I am having python 2.4 on linux machine. I am using exec funcation as:

objconfigfile=open(path, 'r')
for line in objconfigfile.readlines()
if line == None:

It is throwing exception as:
invalid syntax for "exec(line)"

Please let me know the issue, do we have exec function in python 2.4?

Kindly update

Recommended Answers

All 5 Replies

There is an error on this line, no colon
for line in objconfigfile.readlines()

I would suggest that you print every line because
if line == None:
will probably never be true, but you will have to print it and see. Also, exec(line) expects "line" to be a valid python statement.

commented: good comment +8


sorry there is : specified for the loop.
Its basically reading from configuration file having following text:

Previous_Days_Raw_Zip_Files_Delete_Applog =.0000002
Previous_Days_Raw_Zip_Files_Delete_Eventlog =.00000002
Directory_Path_Applog =
Zipped_File_Format = "%Y-%m-%d"
Zip_Files_Deletion_Flag_Applog = "Y"
Zip_Files_Deletion_Flag_Eventlog = "N"
Log_File_Path = "C:\\Logs\\"
Log_File_Path1 = "//MIS/E://One97DWH//MIS_Phase2//Indial//Release//Python//Logs"

So there is no blank line in this text.
Please let me know the possible cause of issue.

I found a copy of 'movable Python24' on one of my flash drives, and this works ...

# excute a code string
s = 'print "Hello!" '

"""my result -->

In answer to your question, Python24 has the function exec().

What can be issue with my program and file ?

What can be issue with my program and file ?

Like our friend woooee stated, the lines in your file are not valid Python executable statements!

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.