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!

Recommended Answers

All 7 Replies

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!

>What does the ' \n' mean?
New line, or sometimes RETURN keyboard.

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.

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.