943,548 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 768
  • Python RSS
Sep 14th, 2009
0

exec function in python 2.4

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajivgupta1107 is offline Offline
6 posts
since Aug 2009
Sep 14th, 2009
1

Re: exec function in python 2.4

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.
Last edited by woooee; Sep 14th, 2009 at 4:35 pm.
Reputation Points: 741
Solved Threads: 691
Nearly a Posting Maven
woooee is offline Offline
2,302 posts
since Dec 2006
Sep 14th, 2009
0

Re: exec function in python 2.4

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=['1003\\10.1.44.200\\Event_Log\\','1006\\10.4.192.21\\Event_Log\\']
Directory_Path_Applog =['1003\\10.1.44.200\\App_Log\\','1006\\10.4.192.21\\App_Log\\']
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajivgupta1107 is offline Offline
6 posts
since Aug 2009
Sep 14th, 2009
0

Re: exec function in python 2.4

I found a copy of 'movable Python24' on one of my flash drives, and this works ...
python Syntax (Toggle Plain Text)
  1. # excute a code string
  2. s = 'print "Hello!" '
  3. exec(s)
  4.  
  5. """my result -->
  6. Hello!
  7. """
In answer to your question, Python24 has the function exec().
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 14th, 2009
0

Re: exec function in python 2.4

What can be issue with my program and file ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajivgupta1107 is offline Offline
6 posts
since Aug 2009
Sep 14th, 2009
0

Re: exec function in python 2.4

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!
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: List of QWidgets with PyQt4
Next Thread in Python Forum Timeline: Confusing strings





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC