Hi,

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:
continue
exec(line)


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

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.

Edited 7 Years Ago by woooee: n/a

Comments
good comment

Hi,

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_Eventlog=
Directory_Path_Applog =
Common_Path_Indial="//MIS/E://One97DWH//MIS_Phase2//Indial//Release//ETTL//Input_Files//"
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!" '
exec(s)

"""my result -->
Hello!
"""

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

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!

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