IDLE import subprocess SyntaxError but not in Python3 in Terminal with Mac OSX





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















The following code fragment from the IDLE Python 3.7.1 Shell window on MacOS 10.11.6 causes a syntax error.

What is the solution?

The same code run in Terminal Python 2.7.10 or Python3 does not cause an error.



Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> import subprocess
from time import strftime
import time
SyntaxError: multiple statements found while compiling a single statement
>>>









share|improve this question


















  • 1





    Why are you importing time twice? It seems like that is the reason there is an error.

    – Karl
    Nov 16 '18 at 17:13













  • You cannot execute multiple statements like that in IDLE. IPython (like in Spyder) however can do this

    – user8408080
    Nov 16 '18 at 19:13


















0















The following code fragment from the IDLE Python 3.7.1 Shell window on MacOS 10.11.6 causes a syntax error.

What is the solution?

The same code run in Terminal Python 2.7.10 or Python3 does not cause an error.



Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> import subprocess
from time import strftime
import time
SyntaxError: multiple statements found while compiling a single statement
>>>









share|improve this question


















  • 1





    Why are you importing time twice? It seems like that is the reason there is an error.

    – Karl
    Nov 16 '18 at 17:13













  • You cannot execute multiple statements like that in IDLE. IPython (like in Spyder) however can do this

    – user8408080
    Nov 16 '18 at 19:13














0












0








0








The following code fragment from the IDLE Python 3.7.1 Shell window on MacOS 10.11.6 causes a syntax error.

What is the solution?

The same code run in Terminal Python 2.7.10 or Python3 does not cause an error.



Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> import subprocess
from time import strftime
import time
SyntaxError: multiple statements found while compiling a single statement
>>>









share|improve this question














The following code fragment from the IDLE Python 3.7.1 Shell window on MacOS 10.11.6 causes a syntax error.

What is the solution?

The same code run in Terminal Python 2.7.10 or Python3 does not cause an error.



Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> import subprocess
from time import strftime
import time
SyntaxError: multiple statements found while compiling a single statement
>>>






python subprocess syntax-error python-idle






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 16:57









macmac

1




1








  • 1





    Why are you importing time twice? It seems like that is the reason there is an error.

    – Karl
    Nov 16 '18 at 17:13













  • You cannot execute multiple statements like that in IDLE. IPython (like in Spyder) however can do this

    – user8408080
    Nov 16 '18 at 19:13














  • 1





    Why are you importing time twice? It seems like that is the reason there is an error.

    – Karl
    Nov 16 '18 at 17:13













  • You cannot execute multiple statements like that in IDLE. IPython (like in Spyder) however can do this

    – user8408080
    Nov 16 '18 at 19:13








1




1





Why are you importing time twice? It seems like that is the reason there is an error.

– Karl
Nov 16 '18 at 17:13







Why are you importing time twice? It seems like that is the reason there is an error.

– Karl
Nov 16 '18 at 17:13















You cannot execute multiple statements like that in IDLE. IPython (like in Spyder) however can do this

– user8408080
Nov 16 '18 at 19:13





You cannot execute multiple statements like that in IDLE. IPython (like in Spyder) however can do this

– user8408080
Nov 16 '18 at 19:13












1 Answer
1






active

oldest

votes


















0














The answer, as is often the case, is in the exception message. You should enter one and only one statement in response to IDLE's statement prompt. A couple of weeks ago, I edited the IDLE doc to make this clearer.




With IDLE’s Shell, one enters, edits, and recalls complete statements.
Most consoles and terminals only work with a single physical line at a
time.



When one pastes code into Shell, it is not compiled and possibly
executed until one hits Return. One may edit pasted code first. If one
pastes more that one statement into Shell, the result will be a
SyntaxError when multiple statements are compiled as if they were one.




If, in response to the prompt >>>, you type import subprocess and hit return, IDLE sends the statement to Python in the user process to execute the import. IDLE then presents a new >>> prompt. You entered three statements without triggering execution. The only way I know to do that is by pasting all three at once. (If you found another way, I would like to know ;-).



To run multiple statements at once, edit or paste into a file and run it. I keep a tem.py file that I use for this. I usually open it with Files => Recent files.






share|improve this answer


























    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%2f53342287%2fidle-import-subprocess-syntaxerror-but-not-in-python3-in-terminal-with-mac-osx%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The answer, as is often the case, is in the exception message. You should enter one and only one statement in response to IDLE's statement prompt. A couple of weeks ago, I edited the IDLE doc to make this clearer.




    With IDLE’s Shell, one enters, edits, and recalls complete statements.
    Most consoles and terminals only work with a single physical line at a
    time.



    When one pastes code into Shell, it is not compiled and possibly
    executed until one hits Return. One may edit pasted code first. If one
    pastes more that one statement into Shell, the result will be a
    SyntaxError when multiple statements are compiled as if they were one.




    If, in response to the prompt >>>, you type import subprocess and hit return, IDLE sends the statement to Python in the user process to execute the import. IDLE then presents a new >>> prompt. You entered three statements without triggering execution. The only way I know to do that is by pasting all three at once. (If you found another way, I would like to know ;-).



    To run multiple statements at once, edit or paste into a file and run it. I keep a tem.py file that I use for this. I usually open it with Files => Recent files.






    share|improve this answer






























      0














      The answer, as is often the case, is in the exception message. You should enter one and only one statement in response to IDLE's statement prompt. A couple of weeks ago, I edited the IDLE doc to make this clearer.




      With IDLE’s Shell, one enters, edits, and recalls complete statements.
      Most consoles and terminals only work with a single physical line at a
      time.



      When one pastes code into Shell, it is not compiled and possibly
      executed until one hits Return. One may edit pasted code first. If one
      pastes more that one statement into Shell, the result will be a
      SyntaxError when multiple statements are compiled as if they were one.




      If, in response to the prompt >>>, you type import subprocess and hit return, IDLE sends the statement to Python in the user process to execute the import. IDLE then presents a new >>> prompt. You entered three statements without triggering execution. The only way I know to do that is by pasting all three at once. (If you found another way, I would like to know ;-).



      To run multiple statements at once, edit or paste into a file and run it. I keep a tem.py file that I use for this. I usually open it with Files => Recent files.






      share|improve this answer




























        0












        0








        0







        The answer, as is often the case, is in the exception message. You should enter one and only one statement in response to IDLE's statement prompt. A couple of weeks ago, I edited the IDLE doc to make this clearer.




        With IDLE’s Shell, one enters, edits, and recalls complete statements.
        Most consoles and terminals only work with a single physical line at a
        time.



        When one pastes code into Shell, it is not compiled and possibly
        executed until one hits Return. One may edit pasted code first. If one
        pastes more that one statement into Shell, the result will be a
        SyntaxError when multiple statements are compiled as if they were one.




        If, in response to the prompt >>>, you type import subprocess and hit return, IDLE sends the statement to Python in the user process to execute the import. IDLE then presents a new >>> prompt. You entered three statements without triggering execution. The only way I know to do that is by pasting all three at once. (If you found another way, I would like to know ;-).



        To run multiple statements at once, edit or paste into a file and run it. I keep a tem.py file that I use for this. I usually open it with Files => Recent files.






        share|improve this answer















        The answer, as is often the case, is in the exception message. You should enter one and only one statement in response to IDLE's statement prompt. A couple of weeks ago, I edited the IDLE doc to make this clearer.




        With IDLE’s Shell, one enters, edits, and recalls complete statements.
        Most consoles and terminals only work with a single physical line at a
        time.



        When one pastes code into Shell, it is not compiled and possibly
        executed until one hits Return. One may edit pasted code first. If one
        pastes more that one statement into Shell, the result will be a
        SyntaxError when multiple statements are compiled as if they were one.




        If, in response to the prompt >>>, you type import subprocess and hit return, IDLE sends the statement to Python in the user process to execute the import. IDLE then presents a new >>> prompt. You entered three statements without triggering execution. The only way I know to do that is by pasting all three at once. (If you found another way, I would like to know ;-).



        To run multiple statements at once, edit or paste into a file and run it. I keep a tem.py file that I use for this. I usually open it with Files => Recent files.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '18 at 19:06

























        answered Nov 16 '18 at 18:53









        Terry Jan ReedyTerry Jan Reedy

        12.3k12140




        12.3k12140
































            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%2f53342287%2fidle-import-subprocess-syntaxerror-but-not-in-python3-in-terminal-with-mac-osx%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

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values