Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98034 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2015-11-01 11:13 +0100 |
| Last post | 2015-11-01 11:13 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Puzzled Peter Otten <__peter__@web.de> - 2015-11-01 11:13 +0100
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2015-11-01 11:13 +0100 |
| Subject | Re: Puzzled |
| Message-ID | <mailman.13.1446372848.4463.python-list@python.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 top | Article view | comp.lang.python
csiph-web