Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98034
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Puzzled |
| Date | 2015-11-01 11:13 +0100 |
| Organization | None |
| Message-ID | <mailman.13.1446372848.4463.python-list@python.org> (permalink) |
| References | <4CFEDC132D44AC49BA0E91FBEB947119084A742852@DCBL123VX.root.sutterhealth.org> |
Robinson, Wendy wrote:
> Hi there,
> I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic
> programs successfully.
> This morning I rebooted my computer and can't get a single one to work.
> The interpreter seems to be fine and the environment variables look
> correct. But every py file I try to run at the >>> prompt gives me a
> NameError.
>
> I tried running the Repair installation, but that did not help.
>
> Any suggestions?
If you want to run a python script you have to invoke it on the commandline,
not inside the interactive interpreter, i. e. if you have a script
myscript.py containing the line
print("Hello world!")
Wrong:
C:\> python3
>>> myscript.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'myscript' is not defined
Here python looks for a variable "myscript" which of course isn't defined.
(If it were the next step would be to look for an attribute "py" and you'd
probably get an AttributeError)
Right:
C:\> python3 myscript.py
Hello world!
Here python runs the script and exits.
If you have a function defined in a module that you want to use from the
interactive interpreter you have to import the module. Assuming mymodule.py
contains the function
def say_hello():
print("Hello world!")
C:\> python3
>>> import mymodule
>>> mymodule.say_hello()
Hello world!
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Puzzled Peter Otten <__peter__@web.de> - 2015-11-01 11:13 +0100
csiph-web