In the Starting Python [ http://www.daniweb.com/forums/thread20774.html ] Post,
I configured as specified, but when I take that 1st code example [ print "Hello Monty Python!" ] and save it as a file [ HelloMP1.py ], and open it in the Edit Window, and run it from there, I get the error msg from Python Shell [ There's an error in your progrm: incalid syntax ] .

I can see what's happening: the single line pgm [ print "Hello Monty Python!" ] , which shows in the [ HelloMP1.py ] window, is as programmed. But when I look in the Python Shell , The one liner shows up as [ print "Hello Monty Python! ] without the end [ " ].
The [ " ] gets lost in the in the Run command.
Is this a known problem, or am I doing something wrong?

When I just type [ print "Hello Monty Python! ] , into Python Shell , it runs as it should. No error msgs..

Thanks!

If python says there is a syntax error, it means that you did something wrong. A good idea would be to ask python to tell us what your file really contains, so I suggest that you type this command in the python shell window

>>> open("HelloMP1.py").read()

then please post here the answer from python.

WHen I Run it, I get the following error:
>>> open("\aTest\HelloMP1.py").read()
>>> Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
open("\aTest\HelloMP1.py").read()
IOError: [Errno 22] invalid mode ('r') or filename: '\x07Test\\HelloMP1.py'

I don't know where the [ \x07 Test\\ ] came from.

After an accidental RESTART, I get the following:
>>> ================================ RESTART ================================
>>>
>>> open("HelloMP1.py").read()
' \n'
>>>

What does the ' \n' mean?
Thanks!

You should probably enter your filename as

>>> open("C:\\aTest\\HelloMP1.py").read()

(if the path to your file is C:\aTest\HelloMP1.py , because \ is the character used by python to escape characters in litteral string, so "\a" does not mean backslash followed by a, but the character whith hexadecimal code \x07. If you want to write a backslash followed by a, you can write "\\a" (double every backslash).

(if the path to your file is C:\aTest\HelloMP1.py , because \ is the character used by python to escape characters in litteral string, so "\a" does not mean backslash followed by a, but the character whith hexadecimal code \x07. If you want to write a backslash followed by a, you can write "\\a" (double every backslash).

To avoid this mess, you can make use of the os.path tools:

import os

my_file_path = os.path.join( 'C:\\', 'aTest', 'HelloMP1.py' )
open( my_file_path )
# Etc...

The Python interactive shell is there to quickly test an few lines of Python code. You cannot save or load any code, for that you need to use an editor, or better one of the many IDE programs.

This article has been dead for over six months. Start a new discussion instead.