0

I am a beginner, and I am trying to run my first script in the windows command line. When I try to open the file I get the following error:

>>> script1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'script1' is not defined

I have the file saved in the lib folder where python is installed. I was hoping someone here could assist me or tell me what I might be doing incorrectly.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Hummdis
1

You need to run the file from the Windows command line, not the Python command line.

You should also be able to select "Run" from within the Python IDE in Windows.

For example:

C:\Users\user1\Python Files> python script1

It may also be easier for you to just run it from the PythonWin. There's a "Run" feature that runs the script for you.

All I know if that you can't just type the name into the Python command line and it works. You'll need to import the file to do that:

import script1

Or use:

from script1 import *

Whichever is easiest and I think the PythonWin GUI would be easiest for you.

Edited by Hummdis: Added code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.