July 27th, 2003, 06:36 PM
passing file to program
how are well all today... its bloody freezing here at the moment in Sydney
if i have a file on the HD and want to pass it to a python script i use the sys.argv[x] which is fairly straight forward, however im trying to pass a file directly to my script after its been fetched via a pop email retrieve utility.
i figured that sys.argv[x] still would of done that regardless if the file was on the HD or being piped from another program.
im lost now so some help would be much appreciated.
July 27th, 2003, 07:53 PM
Again, I'd suggest you post your script. What are having problems with, exactly ? Is it with Python file I/O ?
Time is the greatest of teachers ; sadly, it kills all of its students.
- Hector Berlioz
July 27th, 2003, 08:50 PM
My apoligies solarbear...
As it standards the code works fine if the email is allready on the HD but like i said if the email is piped directly to the script it fails.
import email, os, sys, smtplib, string
if len(sys.argv) == 1:
print "Usage: %s filename" % os.path.basename(sys.argv)
file = open(sys.argv, 'r')
msg = email.message_from_file(file)
fromaddr = 'MAILER-DAEMON'
toaddrs = msg['from']
subject = 'ERROR'
msgg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (fromaddr, toaddrs, subject))
msgg = msgg + 'testing for now'
server = smtplib.SMTP('localhost')
server.sendmail(fromaddr, toaddrs, msgg)
I have tried many senarios with no success
July 28th, 2003, 08:27 AM
July 29th, 2003, 06:14 AM
It has nothing to do with your question, but for how long do you live in Australia? Stupid question I know ... but a friend is in Sydney at moment ... perhaps you no him (improbably I know...)
July 30th, 2003, 02:29 AM
thanks Mark, i got ya email and have replied twice doesnt seem like your getting them?
Wizard, i have lived in Sydney for all my life 32years in fact
July 30th, 2003, 08:25 AM
Hi sissy, i got one of your replies yesterday, have just replied. You mentioned error trapping, this is really easy with python. if you put out code in one or more try-except blocks you can provide alternatives actions if spacific errors occure.