#๐Ÿ”’ beginner question: how do i run a script in idle?

37 messages ยท Page 1 of 1 (latest)

halcyon orchid
#

reading thinkpython and exercise 2.1 is throwing me for a loop. I tried to write a script in sublime text and exec(2.1.py) in idle, but it gave me a syntax error. i think i just dont understand scripts. Thanks!

frosty lanceBOT
#

@halcyon orchid

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

final pollen
halcyon orchid
final pollen
#

so this is the idle "shell"

#

it's what you call a REPL, it evaluates each line of code separately

#

so following the exercise, you should be typing 5

#

x = 5

#

x + 1

#

and see what happens

halcyon orchid
#

ok. do i need a terminal or cmd prompt or something?

final pollen
#

No, you are meant to write those statements directly into the shell

#

the exercise wants you to see the difference between REPL and a .py file

halcyon orchid
#

i get that

final pollen
#

so did you create a .py file?

halcyon orchid
#

i did

final pollen
#

then to run it from IDLE, you would go File > Open at the top

#

then load that file

halcyon orchid
#

ok

#

heres what happens

#

it opens the .py in a seperate window

final pollen
#

yup, now you can do Run > Run Module at the top

#

and the output will appear in the REPL (the other window)

halcyon orchid
#

ok cool

final pollen
#

you'll probably notice that there is no output

halcyon orchid
#

ya!

#

its = RESTART

final pollen
#

python files won't display output unless you use a print statement

halcyon orchid
#

and then the file location

final pollen
#

REPL however will evaluate each line and output the result immediately

#

REPL stands for "Read/Eval/Print/Loop"

halcyon orchid
#

very cool, thanks

final pollen
halcyon orchid
#

!close

frosty lanceBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.