Hi, I'm new to Python and having difficulty opening my .py file (ex1.py).

In the command prompt I cd to the folder containing the file and when I try to open it nothing happens. The prompt just gives me a new line. It looks like this...

1. I open the prompt
2. "cd" to "c:\users\me\practicepython" (where my py file is located)
3. I then type ex1.py (the file contains "hello world")
4. I have also tried typing "python ex1.py"
5. The prompt does nothing, just returns with the commandline "c:\users\me\practicepython"

I can open Python by typing "python", I can edit the py file (ex1.py) but for some reason it will not execute within the prompt. Python is added to my Path as well. I am at a loss for what to do, any help would be much appreciated. Thanks !

Recommended Answers

All 9 Replies

Try forcing the path to ex1.py: python .\ex1.py to see what happens. Be aware that I'm not a Windows user.

Try forcing the path to ex1.py: python .\ex1.py to see what happens. Be aware that I'm not a Windows user.

Unfortunately it gave me the same result. It just returned the same command line. It does stop for one second like it is doing something, but then returns the same line.

Try to write your code files and run them from the IDE that comes with the Python installation (called IDLE). The IDE will connect the working directory (where your code file is located) with Python.exe

See http://www.daniweb.com/forums/thread20774.html

Try to write your code files and run them from the IDE that comes with the Python installation (called IDLE). The IDE will connect the working directory (where your code file is located) with Python.exe

See http://www.daniweb.com/forums/thread20774.html

Tried to run it in IDLE, it will open my file in the editor but when I try to run it(f5) it just gives me

>>> ================================ RESTART ================================
>>>
>>>

I have tried a couple different .py files but it just gives me the same thing. One liners I right in IDLE come back okay, if that helps at all.

What does your code look like?

What @bumsfeld said. This does start to sound like an infinite recursion or some other programming error, though I would expect IDLE to give you some kind of diagnostic.

It is just a couple lines...

1 "Hello World!"
2 "Hello Again"

I used gedit. Though it occurs whether I use gedit / IDLE editor.

First a meta post:

  • Notice the (CODE) button in the toolbar. When you are posting code, either press the button, then paste between the two tags, or paste, then highlight and press the button. This creates line numbers, code coloring, and preserves indentation: All good things
  • And, while I'm in meta mode: Once you, the OP (Original Poster) are satisfied that the thread is solved, you should hunt down the 'mark thread solved' link at the bottom of the thread and use it. This is only possible for the OP, and is also a good thing: It helps keep DaniWeb working as well as possible.

Next, to the meat of the problem
You need to actually print something, or nothing will show up:

print("Hello once")
print("Hello twice")

should do the trick. (In the interpreter, or IDLE, just mentioning a value causes its string representation to be printed. But in a script, if you want it printed, you have to say so)

First a meta post:

  • Notice the (CODE) button in the toolbar. When you are posting code, either press the button, then paste between the two tags, or paste, then highlight and press the button. This creates line numbers, code coloring, and preserves indentation: All good things
  • And, while I'm in meta mode: Once you, the OP (Original Poster) are satisfied that the thread is solved, you should hunt down the 'mark thread solved' link at the bottom of the thread and use it. This is only possible for the OP, and is also a good thing: It helps keep DaniWeb working as well as possible.

Next, to the meat of the problem
You need to actually print something, or nothing will show up:
print("Hello once")
print("Hello twice")
should do the trick. (In the interpreter, or IDLE, just mentioning a value causes its string representation to be printed. But in a script, if you want it printed, you have to say so)

Wow, thank you griswolf. Complete oversight on my part. Thanks for the tips as well.

Obviously I am completely new to this world so I appreciate both you and bumsfeld's replies.

Cheers !

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.