1 Replies - 1374 Views - Last Post: 09 November 2009 - 10:21 AM Rate Topic: -----

#1 missoneill  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 02-May 09

Calling python function from outside script

Post icon  Posted 09 November 2009 - 07:44 AM

Hi there,

I'm having a problem calling a function from outside my main python script. The main script creates a set of text file reports. The second python script (email_reports.py) defines the functions used to send out these reports via email. I have imported email_reports into the main script and called the emailing functions. The script executes successfully but data is missing from the resulting emails. Strangely, when I call the emailing functions from within the email_reports.py script, the resulting emails are complete. I don't understand why I'm getting different results from the same function... any insight would be greatly apprectiated.

Here's the code from email_reports.py :

import mailer, time
from time import strftime

today =strftime("%B %d, %Y")
opyear = strftime("%Y")

def EmailYTDRpt(dist):
	 strBody = "					Road Construction Line Summary\n" + 
	 "					Blocks Completed for " + 
	 opyear + " in " + dist + "\n\n\n" + open("T:\\Road_Con\\reports\\" + dist 
	 + "ytd_L.txt", "rb").read() + "\n\n\n" + "			Road Construction Point Features\n" 
	 + "				Blocks Completed in " + opyear + "\n\n\n" + open 
	 ("T:\\Road_Con\\reports\\" + dist + "ytd_P.txt", "rb").read()
	
	 message = mailer.Message()
	 message.From = "from@email.com"
	 message.To = "to@email.com" # email_list
	 message.Subject = dist + " RDCON BLOCKS COMPLETED IN " + opyear + " - " + today
	 message.Body = strBody

	 mailer1 = mailer.Mailer('10.5.2.61')
	 mailer1.send(message)
	 return "Sent"



And here's how I'm calling it from the main script...

import sys, string, os, arcgisscripting, time, shutil, mailer, email_reports
from time import ctime, strptime, strftime

#rest of script here...

email_reports.EmailYTDRpt(dist)



Is This A Good Question/Topic? 0
  • +

Replies To: Calling python function from outside script

#2 missoneill  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 02-May 09

Re: Calling python function from outside script

Posted 09 November 2009 - 10:21 AM

Problem solved!

In the main script, the emailing function was being called while one of the files was still open and was therefore not being read properly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1