In Python, how do I create aliases? I want to rename “elif” as “elseif”
In C, one can use #define
to make a developer's life easier. In C, it is possible to do this: #define el else
. This would allow a developer to write either else
or el
depending on their preferences, and the compiler would replace all the "el"s with "else" during pre-compilation..
Is there anything similar in python? Is there something in python that will allow me to create aliases for my own convenience?
python if-statement alias aliases
add a comment |
In C, one can use #define
to make a developer's life easier. In C, it is possible to do this: #define el else
. This would allow a developer to write either else
or el
depending on their preferences, and the compiler would replace all the "el"s with "else" during pre-compilation..
Is there anything similar in python? Is there something in python that will allow me to create aliases for my own convenience?
python if-statement alias aliases
1
Not from what I know of.
– shahkalpesh
Dec 31 '18 at 12:29
3
Remember that even your example is strictly speaking not C code but pre-processor instructions. Python does not have a pre-processor and does not allow to rename keywords. Even if it would be possible it would violate many of the code principles Python is built around.
– Klaus D.
Dec 31 '18 at 12:32
@KlausD., Can you give a few examples of the "code principals" around which Python is built, and how my idea would break them?
– Ryan Jensen
Dec 31 '18 at 14:09
python.org/dev/peps/pep-0020
– Klaus D.
Dec 31 '18 at 14:24
@KlausD. If I were to rename "elif" to "ef" and rename "else" to "el", that would make more control keywords 2 characters long (if, ef, el). It would improve the beauty and readability of the code. That goal is in alignment with the first line of the poem you referenced.
– Ryan Jensen
Dec 31 '18 at 15:51
add a comment |
In C, one can use #define
to make a developer's life easier. In C, it is possible to do this: #define el else
. This would allow a developer to write either else
or el
depending on their preferences, and the compiler would replace all the "el"s with "else" during pre-compilation..
Is there anything similar in python? Is there something in python that will allow me to create aliases for my own convenience?
python if-statement alias aliases
In C, one can use #define
to make a developer's life easier. In C, it is possible to do this: #define el else
. This would allow a developer to write either else
or el
depending on their preferences, and the compiler would replace all the "el"s with "else" during pre-compilation..
Is there anything similar in python? Is there something in python that will allow me to create aliases for my own convenience?
python if-statement alias aliases
python if-statement alias aliases
asked Dec 31 '18 at 12:28
Ryan JensenRyan Jensen
1353
1353
1
Not from what I know of.
– shahkalpesh
Dec 31 '18 at 12:29
3
Remember that even your example is strictly speaking not C code but pre-processor instructions. Python does not have a pre-processor and does not allow to rename keywords. Even if it would be possible it would violate many of the code principles Python is built around.
– Klaus D.
Dec 31 '18 at 12:32
@KlausD., Can you give a few examples of the "code principals" around which Python is built, and how my idea would break them?
– Ryan Jensen
Dec 31 '18 at 14:09
python.org/dev/peps/pep-0020
– Klaus D.
Dec 31 '18 at 14:24
@KlausD. If I were to rename "elif" to "ef" and rename "else" to "el", that would make more control keywords 2 characters long (if, ef, el). It would improve the beauty and readability of the code. That goal is in alignment with the first line of the poem you referenced.
– Ryan Jensen
Dec 31 '18 at 15:51
add a comment |
1
Not from what I know of.
– shahkalpesh
Dec 31 '18 at 12:29
3
Remember that even your example is strictly speaking not C code but pre-processor instructions. Python does not have a pre-processor and does not allow to rename keywords. Even if it would be possible it would violate many of the code principles Python is built around.
– Klaus D.
Dec 31 '18 at 12:32
@KlausD., Can you give a few examples of the "code principals" around which Python is built, and how my idea would break them?
– Ryan Jensen
Dec 31 '18 at 14:09
python.org/dev/peps/pep-0020
– Klaus D.
Dec 31 '18 at 14:24
@KlausD. If I were to rename "elif" to "ef" and rename "else" to "el", that would make more control keywords 2 characters long (if, ef, el). It would improve the beauty and readability of the code. That goal is in alignment with the first line of the poem you referenced.
– Ryan Jensen
Dec 31 '18 at 15:51
1
1
Not from what I know of.
– shahkalpesh
Dec 31 '18 at 12:29
Not from what I know of.
– shahkalpesh
Dec 31 '18 at 12:29
3
3
Remember that even your example is strictly speaking not C code but pre-processor instructions. Python does not have a pre-processor and does not allow to rename keywords. Even if it would be possible it would violate many of the code principles Python is built around.
– Klaus D.
Dec 31 '18 at 12:32
Remember that even your example is strictly speaking not C code but pre-processor instructions. Python does not have a pre-processor and does not allow to rename keywords. Even if it would be possible it would violate many of the code principles Python is built around.
– Klaus D.
Dec 31 '18 at 12:32
@KlausD., Can you give a few examples of the "code principals" around which Python is built, and how my idea would break them?
– Ryan Jensen
Dec 31 '18 at 14:09
@KlausD., Can you give a few examples of the "code principals" around which Python is built, and how my idea would break them?
– Ryan Jensen
Dec 31 '18 at 14:09
python.org/dev/peps/pep-0020
– Klaus D.
Dec 31 '18 at 14:24
python.org/dev/peps/pep-0020
– Klaus D.
Dec 31 '18 at 14:24
@KlausD. If I were to rename "elif" to "ef" and rename "else" to "el", that would make more control keywords 2 characters long (if, ef, el). It would improve the beauty and readability of the code. That goal is in alignment with the first line of the poem you referenced.
– Ryan Jensen
Dec 31 '18 at 15:51
@KlausD. If I were to rename "elif" to "ef" and rename "else" to "el", that would make more control keywords 2 characters long (if, ef, el). It would improve the beauty and readability of the code. That goal is in alignment with the first line of the poem you referenced.
– Ryan Jensen
Dec 31 '18 at 15:51
add a comment |
2 Answers
2
active
oldest
votes
Python is a very permissive language but there are some reserved keywords.
Here is a description how you can simulate c preprocessor.
Just for fun in version 2.x
you may even swap True
and False
. Check here.
add a comment |
What you are referring to is preprocessing the source code. In C (and some other languages), you can do simple find and replace operations on the source code, treating the source code as simple text.
Python does not ship with anything like that. However, you can create variables that refer to globals. For instance, you could create a variable j
that is the same as os.path.join
like this:
import os
j = os.path.join
print(j("one", "two")) # same as print(os.path.join("one", "two"))
Are there any errors in my answer? Why the downvote?
– Flimm
Dec 31 '18 at 15:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987528%2fin-python-how-do-i-create-aliases-i-want-to-rename-elif-as-elseif%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Python is a very permissive language but there are some reserved keywords.
Here is a description how you can simulate c preprocessor.
Just for fun in version 2.x
you may even swap True
and False
. Check here.
add a comment |
Python is a very permissive language but there are some reserved keywords.
Here is a description how you can simulate c preprocessor.
Just for fun in version 2.x
you may even swap True
and False
. Check here.
add a comment |
Python is a very permissive language but there are some reserved keywords.
Here is a description how you can simulate c preprocessor.
Just for fun in version 2.x
you may even swap True
and False
. Check here.
Python is a very permissive language but there are some reserved keywords.
Here is a description how you can simulate c preprocessor.
Just for fun in version 2.x
you may even swap True
and False
. Check here.
answered Dec 31 '18 at 12:41
Jónás BalázsJónás Balázs
348312
348312
add a comment |
add a comment |
What you are referring to is preprocessing the source code. In C (and some other languages), you can do simple find and replace operations on the source code, treating the source code as simple text.
Python does not ship with anything like that. However, you can create variables that refer to globals. For instance, you could create a variable j
that is the same as os.path.join
like this:
import os
j = os.path.join
print(j("one", "two")) # same as print(os.path.join("one", "two"))
Are there any errors in my answer? Why the downvote?
– Flimm
Dec 31 '18 at 15:41
add a comment |
What you are referring to is preprocessing the source code. In C (and some other languages), you can do simple find and replace operations on the source code, treating the source code as simple text.
Python does not ship with anything like that. However, you can create variables that refer to globals. For instance, you could create a variable j
that is the same as os.path.join
like this:
import os
j = os.path.join
print(j("one", "two")) # same as print(os.path.join("one", "two"))
Are there any errors in my answer? Why the downvote?
– Flimm
Dec 31 '18 at 15:41
add a comment |
What you are referring to is preprocessing the source code. In C (and some other languages), you can do simple find and replace operations on the source code, treating the source code as simple text.
Python does not ship with anything like that. However, you can create variables that refer to globals. For instance, you could create a variable j
that is the same as os.path.join
like this:
import os
j = os.path.join
print(j("one", "two")) # same as print(os.path.join("one", "two"))
What you are referring to is preprocessing the source code. In C (and some other languages), you can do simple find and replace operations on the source code, treating the source code as simple text.
Python does not ship with anything like that. However, you can create variables that refer to globals. For instance, you could create a variable j
that is the same as os.path.join
like this:
import os
j = os.path.join
print(j("one", "two")) # same as print(os.path.join("one", "two"))
answered Dec 31 '18 at 12:33
FlimmFlimm
52.5k23136158
52.5k23136158
Are there any errors in my answer? Why the downvote?
– Flimm
Dec 31 '18 at 15:41
add a comment |
Are there any errors in my answer? Why the downvote?
– Flimm
Dec 31 '18 at 15:41
Are there any errors in my answer? Why the downvote?
– Flimm
Dec 31 '18 at 15:41
Are there any errors in my answer? Why the downvote?
– Flimm
Dec 31 '18 at 15:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987528%2fin-python-how-do-i-create-aliases-i-want-to-rename-elif-as-elseif%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Not from what I know of.
– shahkalpesh
Dec 31 '18 at 12:29
3
Remember that even your example is strictly speaking not C code but pre-processor instructions. Python does not have a pre-processor and does not allow to rename keywords. Even if it would be possible it would violate many of the code principles Python is built around.
– Klaus D.
Dec 31 '18 at 12:32
@KlausD., Can you give a few examples of the "code principals" around which Python is built, and how my idea would break them?
– Ryan Jensen
Dec 31 '18 at 14:09
python.org/dev/peps/pep-0020
– Klaus D.
Dec 31 '18 at 14:24
@KlausD. If I were to rename "elif" to "ef" and rename "else" to "el", that would make more control keywords 2 characters long (if, ef, el). It would improve the beauty and readability of the code. That goal is in alignment with the first line of the poem you referenced.
– Ryan Jensen
Dec 31 '18 at 15:51