The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
passing file to program
Discuss passing file to program in the Python Programming forum on Dev Shed. passing file to program Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 27th, 2003, 05:36 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 29
Time spent in forums: 2 h 48 m 25 sec
Reputation Power: 0
|
|
|
passing file to program
Hi folks,
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.
many thanks...
|

July 27th, 2003, 06:53 PM
|
 |
onCsdfeu
|
|
Join Date: Jul 2003
Location: Canada
Posts: 100
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
|
|
|
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, 07:50 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 29
Time spent in forums: 2 h 48 m 25 sec
Reputation Power: 0
|
|
My apoligies solarbear...
Code:
#!/usr/bin/env python
import email, os, sys, smtplib, string
if len(sys.argv) == 1:
print "Usage: %s filename" % os.path.basename(sys.argv[0])
sys.exit(1)
file = open(sys.argv[1], 'r')
msg = email.message_from_file(file)
file.close()
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.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msgg)
server.quit()
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.
I have tried many senarios with no success
thanks
|

July 28th, 2003, 07:27 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
pipeing stdin
|

July 29th, 2003, 05:14 AM
|
 |
Contributing User
|
|
Join Date: Jul 2003
Posts: 206
Time spent in forums: 19 h 29 m 24 sec
Reputation Power: 10
|
|
|
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, 01:29 AM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 29
Time spent in forums: 2 h 48 m 25 sec
Reputation Power: 0
|
|
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, 07:25 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
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.
Mark.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|