0

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

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by vegaseat
Featured Replies
  • 1

    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. Read More

1

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 by woooee: n/a

Comments
good comment
0

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.

0

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().

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.