In Python, how do I create aliases? I want to rename “elif” as “elseif”












-3















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?










share|improve this question


















  • 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
















-3















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?










share|improve this question


















  • 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














-3












-3








-3








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












2 Answers
2






active

oldest

votes


















1














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.






share|improve this answer































    -1














    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"))





    share|improve this answer
























    • Are there any errors in my answer? Why the downvote?

      – Flimm
      Dec 31 '18 at 15:41











    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer




























      1














      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.






      share|improve this answer


























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '18 at 12:41









        Jónás BalázsJónás Balázs

        348312




        348312

























            -1














            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"))





            share|improve this answer
























            • Are there any errors in my answer? Why the downvote?

              – Flimm
              Dec 31 '18 at 15:41
















            -1














            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"))





            share|improve this answer
























            • Are there any errors in my answer? Why the downvote?

              – Flimm
              Dec 31 '18 at 15:41














            -1












            -1








            -1







            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"))





            share|improve this answer













            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"))






            share|improve this answer












            share|improve this answer



            share|improve this answer










            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



















            • 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


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas