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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.