Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 27th, 2003, 05:36 PM
sissy sissy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 29 sissy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #2  
Old July 27th, 2003, 06:53 PM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
Send a message via MSN to SolarBear
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

Reply With Quote
  #3  
Old July 27th, 2003, 07:50 PM
sissy sissy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 29 sissy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old July 28th, 2003, 07:27 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
pipeing stdin

Hey sissy,

When working with pipes you can read them in though stdin (sys.stdin). Take a look at this article for more info.

http://www.linuxjournal.com/article.php?sid=3946

Did you get my reply to your email?

Have fun,
Mark.

Reply With Quote
  #5  
Old July 29th, 2003, 05:14 AM
Wizard2003's Avatar
Wizard2003 Wizard2003 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 206 Wizard2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...)

Reply With Quote
  #6  
Old July 30th, 2003, 01:29 AM
sissy sissy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 29 sissy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #7  
Old July 30th, 2003, 07:25 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > passing file to program

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap