473,569 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python script to windows exe

hi all

i am very much a newbie to python but has some experience of
development.i am trying to write a script which will loop through the
outlook 2003 inbox and save the email data in an simple data.html page
and save all the attachments in a folder name emails.after some
initial struggling i am able to write this script.but now i want to
create the exe file of this script.i have used py2exe for this job and
created the exe. but when i run the exe my program in not behaving as
it supposed to be.its generating some errors.i dont know why this
thing is happening as when i run my script it works fine.can some one
put some light here. i am using python2.5 and is using
py2exe-0.6.6.win32-py2.5.exe of py2exe. My os is windows xp with
service pack2.
thanks and reagrds
sandeep kumar sharma
Jun 27 '08 #1
8 4159
but when i run the exe my program in not behaving as
it supposed to be.its generating some errors.i dont know why this
thing is happening as when i run my script it works fine.can some one
put some light here.
There is nothing special in executables produced by py2exe. I mean
that the debugging strategy is as always. A good start might be in
adding logging\tracing facilities both to script and the executable.
Comparing two trace files could give you some clue.
Jun 27 '08 #2
On May 19, 1:39 pm, "egl...@gmail.c om" <egl...@gmail.c omwrote:
but when i run the exe my program in not behaving as
it supposed to be.its generating some errors.i dont know why this
thing is happening as when i run my script it works fine.can some one
put some light here.

There is nothing special in executables produced by py2exe. I mean
that the debugging strategy is as always. A good start might be in
adding logging\tracing facilities both to script and the executable.
Comparing two trace files could give you some clue.
hi here is my code.i wont get any errors when i run this script.it may
not be the best pycode as i am very much new to python development.

import win32com,win32c om.client
import os,os.path
import codecs
import zipfile

#@Author:::Sand eep Kumar Sharma

#outlook2003 application refrence
outlook_app=0
#outlook ids to access different folders look into msdn for more info.
not a preffered way as i am hardcoding data here
OlDefaultFolder s={'olFolderCal endar':9,'olFol derConflicts':
19,'olFolderCon tacts':10,'olFo lderDeletedItem s':3,'olFolderD rafts':
16,'olFolderInb ox':6,'olFolder Journal':11,'ol FolderJunk':
23,'olFolderLoc alFailures':21, 'olFolderNotes' :12,'olFolderOu tbox':
4,'olFolderSent Mail':5,'olFold erServerFailure s':
22,'olFolderSyn cIssues':20,'ol FolderTasks':
13,'olPublicFol dersAllPublicFo lders':18}
#outlook types to save mailItem look into msdn for more info
#although doesnot work for me :-(
OlSaveAsType={' olTXT': 0,'olRTF':1,'ol Template': 2,'olMSG': 3,'olDoc':
4,'olHTML':5,'o lVCard': 6,'olVCal':7,'o lICal': 8};

#refrence to content in inbox
inbox_obj=0

#function which will initialise outlook and return its reference
def getAppRef():
temp=win32com.c lient.Dispatch( "OutLook.Applic ation")
return temp.GetNamespa ce("MAPI")

#function to return the folders in the outlook
def getOutLookFolde rs(a,b=OlDefaul tFolders['olFolderInbox']):
return a.GetDefaultFol der(b)

#function to get email content
def getMailContent( obj):
txt_file=codecs .open('data.htm l',encoding='ut f-8',mode='w')
for kk in range(len(obj.I tems),1,-1):
#for kk in range(len(obj.I tems-1),0,-1):
#print 'hello'
print 'writting file='+str(kk)
mailItem=obj.It ems[kk]
writeData(mailI tem,txt_file)

#print mailItem.OlSave AsType.olMSG
#saveCopy(mailI tem)
#print "sender="+mailI tem.SenderName+ '
SenderEmailId=' +str(mailItem.S enderEmailAddre ss)+'
Time='+str(mail Item.ReceivedTi me)
#print 'Subject='+mail Item.Subject+' size='+str(mail Item.Size)

txt_file.close( )
'''
file_zip=zipfil e.ZipFile(txt_f ile,"w",zipfile .ZIP_DEFLATED)
file_zip.write( 'data.log')
file_zip.close( )
'''

#function to create a directory
#obviously not a best way :-( but i think can expected this sort of
mistakes from beginners
def createDir():
path=os.path.ab spath("\email")
if(os.path.exis ts(path)):
print "Directory already exists"
else:
os.system("md "+path)

#function to save a copy of email
def writeData(mailI tem,file):
data="<p>"
sender='<h4>Sen derName</
h4>'+checkStrin gType(mailItem. SenderName)
time='<br><h4>T ime</
h4>'+checkStrin gType(str(mailI tem.ReceivedTim e))
attachment='<br ><h5>Attachment s Count</
h5>'+str(len(ma ilItem.Attachme nts))
edata='<h4>Emai l Content</h4>'+checkStrin gType(mailItem. Body)+"</
p><hr/>"
dataToWrite=dat a+sender+time+a ttachment+edata
getAttachmentIn fo(mailItem.Att achments)
file.write(getH TMLString(dataT oWrite))
#checkStringTyp e(dataToWrite)

def getAttachmentIn fo(atmts):
for kk in range(1,len(atm ts)):
atmt=atmts[kk]
#print "File Name="+atmt.Fil eName+'
DisplayName='+a tmt.DisplayName +' PathName='+atmt .PathName+' '
abc=os.path.isd ir(os.getcwd()+ '\email')

if(abc==True):
print 'directory exists'

else:
os.mkdir(os.get cwd()+'\email')

path=os.path.ab spath(os.getcwd ()+'\email')
atmt.SaveAsFile (path+"\\"+atmt .DisplayName)

# function to check whether the character encoding is ascii or smthing
else
def checkStringType (a):

if isinstance(a,st r):
b='not a unicode string'

else:
a.encode('utf-8')
#print 'unicode type'

return a

#function to save the coopy of an email
#:-( but smhow it generate error whenever i make a call to it
def saveCopy(mailIt em):

name="\\"+mailI tem.Subject+"__ "+str(mailItem. ReceivedTime)
print name
#global outlook_app
try:
mailItem.SaveAs (path+name+".tx t",OlSaveAsT ype['olTXT'])
except BaseException:
print BaseException

def getHTMLString(b ):
a='<html><head> <title>Your Email Data log is here</title></
head><body>'+b+ '</body></html>'
return a

#main entrance to the program
def main():
global outlook_app,inb ox_obj
outlook_app=get AppRef()
#print outlook_app.OlS aveAsType.olMSG
print '============== ===='
print dir(outlook_app )
print '============== ===='
inbox_obj=getOu tLookFolders(ou tlook_app)
print dir(inbox_obj)
print (inbox_obj.Item s)
#saveCopy(inbox _obj.Items[1])
getMailContent( inbox_obj)

main()
Jun 27 '08 #3

hi
the py code that i have written is here.when i run this code i wont
get any errors it just works fine for me.but when i created the exe i
start getting an error in my 'getMailContent ' function. The error
description is

TypeError:unsup ported operand type(s) for :- 'instance' and 'int'

i dont know why i am start getting this error when i run it through
the exe.
import win32com,win32c om.client
import os,os.path
import codecs
import zipfile

#@Author:::Sand eep Kumar Sharma

#outlook application refrence
outlook_app=0
#outlook ids to access different folders look into msdn for more info.
not a preffered way as i am hardcoding data here
OlDefaultFolder s={'olFolderCal endar':9,'olFol derConflicts':
19,'olFolderCon tacts':10,'olFo lderDeletedItem s':3,'olFolderD rafts':
16,'olFolderInb ox':6,'olFolder Journal':11,'ol FolderJunk':
23,'olFolderLoc alFailures':21, 'olFolderNotes' :12,'olFolderOu tbox':
4,'olFolderSent Mail':5,'olFold erServerFailure s':
22,'olFolderSyn cIssues':20,'ol FolderTasks':
13,'olPublicFol dersAllPublicFo lders':18}
#outlook types to save mailItem look into msdn for more info
#although doesnot work for me :-(
OlSaveAsType={' olTXT': 0,'olRTF':1,'ol Template': 2,'olMSG': 3,'olDoc':
4,'olHTML':5,'o lVCard': 6,'olVCal':7,'o lICal': 8};

#refrence to content in inbox
inbox_obj=0

#function which will initialise outlook and return its reference
def getAppRef():
temp=win32com.c lient.Dispatch( "OutLook.Applic ation")
return temp.GetNamespa ce("MAPI")

#function to return the folders in the outlook
def getOutLookFolde rs(a,b=OlDefaul tFolders['olFolderInbox']):
return a.GetDefaultFol der(b)

#function to get email content
def getMailContent( obj):
txt_file=codecs .open('data.htm l',encoding='ut f-8',mode='w')
for kk in range(len(obj.I tems),1,-1):
#for kk in range(len(obj.I tems-1),0,-1):
#print 'hello'
print 'writting file='+str(kk)
mailItem=obj.It ems[kk]
writeData(mailI tem,txt_file)

#print mailItem.OlSave AsType.olMSG
#saveCopy(mailI tem)
#print "sender="+mailI tem.SenderName+ '
SenderEmailId=' +str(mailItem.S enderEmailAddre ss)+'
Time='+str(mail Item.ReceivedTi me)
#print 'Subject='+mail Item.Subject+' size='+str(mail Item.Size)

txt_file.close( )
'''
file_zip=zipfil e.ZipFile(txt_f ile,"w",zipfile .ZIP_DEFLATED)
file_zip.write( 'data.log')
file_zip.close( )
'''

#function to create a directory
#obviously not a best way :-( but i think can expected this sort of
mistakes from beginners
def createDir():
path=os.path.ab spath("\email")
if(os.path.exis ts(path)):
print "Directory already exists"
else:
os.system("md "+path)

#function to save a copy of email
def writeData(mailI tem,file):
data="<p>"
sender='<h4>Sen derName</
h4>'+checkStrin gType(mailItem. SenderName)
time='<br><h4>T ime</
h4>'+checkStrin gType(str(mailI tem.ReceivedTim e))
attachment='<br ><h5>Attachment s Count</
h5>'+str(len(ma ilItem.Attachme nts))
edata='<h4>Emai l Content</h4>'+checkStrin gType(mailItem. Body)+"</
p><hr/>"
dataToWrite=dat a+sender+time+a ttachment+edata
getAttachmentIn fo(mailItem.Att achments)
file.write(getH TMLString(dataT oWrite))
#checkStringTyp e(dataToWrite)

def getAttachmentIn fo(atmts):
for kk in range(1,len(atm ts)):
atmt=atmts[kk]
#print "File Name="+atmt.Fil eName+'
DisplayName='+a tmt.DisplayName +' PathName='+atmt .PathName+' '
abc=os.path.isd ir(os.getcwd()+ '\email')

if(abc==True):
print 'directory exists'

else:
os.mkdir(os.get cwd()+'\email')

path=os.path.ab spath(os.getcwd ()+'\email')
atmt.SaveAsFile (path+"\\"+atmt .DisplayName)

# function to check whether the character encoding is ascii or smthing
else
def checkStringType (a):

if isinstance(a,st r):
b='not a unicode string'

else:
a.encode('utf-8')
#print 'unicode type'

return a

#function to save the coopy of an email
#:-( but smhow it generate error whenever i make a call to it
def saveCopy(mailIt em):

name="\\"+mailI tem.Subject+"__ "+str(mailItem. ReceivedTime)
print name
#global outlook_app
try:
mailItem.SaveAs (path+name+".tx t",OlSaveAsT ype['olTXT'])
except BaseException:
print BaseException

def getHTMLString(b ):
a='<html><head> <title>Your Email Data log is here</title></
head><body>'+b+ '</body></html>'
return a

#main entrance to the program
def main():
global outlook_app,inb ox_obj
outlook_app=get AppRef()
#print outlook_app.OlS aveAsType.olMSG
print '============== ===='
print dir(outlook_app )
print '============== ===='
inbox_obj=getOu tLookFolders(ou tlook_app)
print dir(inbox_obj)
print (inbox_obj.Item s)
#saveCopy(inbox _obj.Items[1])
getMailContent( inbox_obj)

main()
my setup file has this code

from distutils.core import setup
import py2exe

setup(console=['outlook.py'])
i have just copied and pasted it from the tutorial available at the
py2exe site and changed the filename with mine filename.
thanks and regards
sandeep kumar sharma
There is nothing special in executables produced by py2exe. I mean
that the debugging strategy is as always. A good start might be in
adding logging\tracing facilities both to script and the executable.
Comparing two trace files could give you some clue.
Jun 27 '08 #4
On May 19, 8:32 am, sandeep <shiningsa...@g mail.comwrote:
hi all

i am very much a newbie to python but has some experience of
development.i am trying to write a script which will loop through the
outlook 2003 inbox and save the email data in an simple data.html page
and save all the attachments in a folder name emails.after some
initial struggling i am able to write this script.but now i want to
create the exe file of this script.i have used py2exe for this job and
created the exe. but when i run the exe my program in not behaving as
it supposed to be.its generating some errors.i dont know why this
thing is happening as when i run my script it works fine.can some one
put some light here. i am using python2.5 and is using
py2exe-0.6.6.win32-py2.5.exe of py2exe. My os is windows xp with
service pack2.

thanks and reagrds
sandeep kumar sharma

You'll need to post the actual errors you get for people to be able to
help. You might find posting to the py2exe mailing list useful.

All the best,
Michael Foord
http://www.ironpythoninaction.com/
Jun 27 '08 #5
En Mon, 19 May 2008 06:59:22 -0300, sandeep <sh**********@g mail.comescribi ó:
the py code that i have written is here.when i run this code i wont
get any errors it just works fine for me.but when i created the exe i
start getting an error in my 'getMailContent ' function. The error
description is

TypeError:unsup ported operand type(s) for :- 'instance' and 'int'

i dont know why i am start getting this error when i run it through
the exe.
By example, your code uses os.getcwd() - so it depends on the current dir. Try running it from a different directory. Don't focus too much on the ".exe" vs ".py" difference: it might not be relevant, the error may reside elsewhere.

Please post the complete exception message *and* traceback. Don't retype it; copy and paste the message from the console. Your message above doesn't appear to be correctly typed, it says `:-` but Python would print `-:` and I don't see any `-` operation in your code that could fail in that way.

Also, don't do this:
try:
mailItem.SaveAs (path+name+".tx t",OlSaveAsT ype['olTXT'])
except BaseException:
print BaseException
because you're completely hiding important information about *what* happened.

--
Gabriel Genellina

Jun 27 '08 #6
On Mon, 19 May 2008 02:59:22 -0700 (PDT), sandeep
<sh**********@g mail.comwrote:
>
hi
the py code that i have written is here.when i run this code i wont
get any errors it just works fine for me.but when i created the exe i
start getting an error in my 'getMailContent ' function. The error
description is

TypeError:unsu pported operand type(s) for :- 'instance' and 'int'
Are you and py2exe using the same version of Python?
(Make something in the exe that displays sys.version...)
>i dont know why i am start getting this error when i run it through
the exe.
import win32com,win32c om.client
import os,os.path
import codecs
import zipfile

#@Author:::San deep Kumar Sharma

#outlook application refrence
outlook_app= 0
#outlook ids to access different folders look into msdn for more info.
not a preffered way as i am hardcoding data here
OlDefaultFolde rs={'olFolderCa lendar':9,'olFo lderConflicts':
19,'olFolderCo ntacts':10,'olF olderDeletedIte ms':3,'olFolder Drafts':
16,'olFolderIn box':6,'olFolde rJournal':11,'o lFolderJunk':
23,'olFolderLo calFailures':21 ,'olFolderNotes ':12,'olFolderO utbox':
4,'olFolderSen tMail':5,'olFol derServerFailur es':
22,'olFolderSy ncIssues':20,'o lFolderTasks':
13,'olPublicFo ldersAllPublicF olders':18}
#outlook types to save mailItem look into msdn for more info
#although doesnot work for me :-(
OlSaveAsType={ 'olTXT': 0,'olRTF':1,'ol Template': 2,'olMSG': 3,'olDoc':
4,'olHTML':5,' olVCard': 6,'olVCal':7,'o lICal': 8};

#refrence to content in inbox
inbox_obj=0

#function which will initialise outlook and return its reference
def getAppRef():
temp=win32com.c lient.Dispatch( "OutLook.Applic ation")
return temp.GetNamespa ce("MAPI")

#function to return the folders in the outlook
def getOutLookFolde rs(a,b=OlDefaul tFolders['olFolderInbox']):
return a.GetDefaultFol der(b)

#function to get email content
def getMailContent( obj):
txt_file=codecs .open('data.htm l',encoding='ut f-8',mode='w')
for kk in range(len(obj.I tems),1,-1):
#for kk in range(len(obj.I tems-1),0,-1):
#print 'hello'
print 'writting file='+str(kk)
mailItem=obj.It ems[kk]
writeData(mailI tem,txt_file)

#print mailItem.OlSave AsType.olMSG
#saveCopy(mailI tem)
#print "sender="+mailI tem.SenderName+ '
SenderEmailId= '+str(mailItem. SenderEmailAddr ess)+'
Time='+str(mai lItem.ReceivedT ime)
#print 'Subject='+mail Item.Subject+' size='+str(mail Item.Size)

txt_file.close( )
'''
file_zip=zipfil e.ZipFile(txt_f ile,"w",zipfile .ZIP_DEFLATED)
file_zip.write( 'data.log')
file_zip.close( )
'''

#function to create a directory
#obviously not a best way :-( but i think can expected this sort of
mistakes from beginners
def createDir():
path=os.path.ab spath("\email")
if(os.path.exis ts(path)):
print "Directory already exists"
else:
os.system("md "+path)

#function to save a copy of email
def writeData(mailI tem,file):
data="<p>"
sender='<h4>Sen derName</
h4>'+checkStri ngType(mailItem .SenderName)
time='<br><h4>T ime</
h4>'+checkStri ngType(str(mail Item.ReceivedTi me))
attachment='<br ><h5>Attachment s Count</
h5>'+str(len(m ailItem.Attachm ents))
edata='<h4>Emai l Content</h4>'+checkStrin gType(mailItem. Body)+"</
p><hr/>"
dataToWrite=dat a+sender+time+a ttachment+edata
getAttachmentIn fo(mailItem.Att achments)
file.write(getH TMLString(dataT oWrite))
#checkStringTyp e(dataToWrite)

def getAttachmentIn fo(atmts):
for kk in range(1,len(atm ts)):
atmt=atmts[kk]
#print "File Name="+atmt.Fil eName+'
DisplayName='+ atmt.DisplayNam e+' PathName='+atmt .PathName+' '
abc=os.path.isd ir(os.getcwd()+ '\email')

if(abc==True):
print 'directory exists'

else:
os.mkdir(os.get cwd()+'\email')

path=os.path.ab spath(os.getcwd ()+'\email')
atmt.SaveAsFile (path+"\\"+atmt .DisplayName)

# function to check whether the character encoding is ascii or smthing
else
def checkStringType (a):

if isinstance(a,st r):
b='not a unicode string'

else:
a.encode('utf-8')
#print 'unicode type'

return a

#function to save the coopy of an email
#:-( but smhow it generate error whenever i make a call to it
def saveCopy(mailIt em):

name="\\"+mailI tem.Subject+"__ "+str(mailItem. ReceivedTime)
print name
#global outlook_app
try:
mailItem.SaveAs (path+name+".tx t",OlSaveAsT ype['olTXT'])
except BaseException:
print BaseException

def getHTMLString(b ):
a='<html><head> <title>Your Email Data log is here</title></
head><body>'+b +'</body></html>'
return a

#main entrance to the program
def main():
global outlook_app,inb ox_obj
outlook_app=get AppRef()
#print outlook_app.OlS aveAsType.olMSG
print '============== ===='
print dir(outlook_app )
print '============== ===='
inbox_obj=getOu tLookFolders(ou tlook_app)
print dir(inbox_obj)
print (inbox_obj.Item s)
#saveCopy(inbox _obj.Items[1])
getMailContent( inbox_obj)

main()
my setup file has this code

from distutils.core import setup
import py2exe

setup(consol e=['outlook.py'])
i have just copied and pasted it from the tutorial available at the
py2exe site and changed the filename with mine filename.
thanks and regards
sandeep kumar sharma
>There is nothing special in executables produced by py2exe. I mean
that the debugging strategy is as always. A good start might be in
adding logging\tracing facilities both to script and the executable.
Comparing two trace files could give you some clue.
David C. Ullrich
Jun 27 '08 #7
hi all

thanks for ur replies. i have a bit closer look at my code and i am
able to fix the problem.now my exe is working fine.the code is bit
more cleaner now as i removed lot of unused function from it and try
to document it also.
import win32com,win32c om.client
import os,os.path
import codecs
import zipfile

#@Author:::Sand eep Kumar Sharma

#outlook application refrence
outlook_app=0
#outlook ids to access different folders look into msdn for more info.
not a preffered way as i am hardcoding data here
OlDefaultFolder s={'olFolderCal endar':9,'olFol derConflicts':
19,'olFolderCon tacts':10,'olFo lderDeletedItem s':3,'olFolderD rafts':
16,'olFolderInb ox':6,'olFolder Journal':11,'ol FolderJunk':
23,'olFolderLoc alFailures':21, 'olFolderNotes' :12,'olFolderOu tbox':
4,'olFolderSent Mail':5,'olFold erServerFailure s':
22,'olFolderSyn cIssues':20,'ol FolderTasks':
13,'olPublicFol dersAllPublicFo lders':18}
#outlook types to save mailItem look into msdn for more info
#although doesnot work for me :-(
OlSaveAsType={' olTXT': 0,'olRTF':1,'ol Template': 2,'olMSG': 3,'olDoc':
4,'olHTML':5,'o lVCard': 6,'olVCal':7,'o lICal': 8};

#refrence to content in inbox
inbox_obj=0

#function which will initialise outlook and return its reference
def getAppRef():
temp=win32com.c lient.Dispatch( "OutLook.Applic ation")
return temp.GetNamespa ce("MAPI")

#function to return the folders in the outlook
def getOutLookFolde rs(a,b=OlDefaul tFolders['olFolderInbox']):
return a.GetDefaultFol der(b)

#function to get email content
def getMailContent( obj):
txt_file=codecs .open('data.htm l',encoding='ut f-8',mode='w')
emailData=""
for kk in range(len(obj.I tems)-1,0,-1):
print 'writting file='+str(kk)
mailItem=obj.It ems[kk]
emailData=email Data+getEmailDa ta(mailItem)
saveAttachments (mailItem.Attac hments)
txt_file.write( getHTMLString(e mailData))
txt_file.close( )

#function which will return the emailItem data as form of String
def getEmailData(ma ilItem):
data="<p>"
sender='<h4>Sen derName</
h4>'+checkStrin gType(mailItem. SenderName)
time='<br><h4>T ime</
h4>'+checkStrin gType(str(mailI tem.ReceivedTim e))
attachment='<br ><h5>Attachment s Count</
h5>'+str(len(ma ilItem.Attachme nts))
edata='<h4>Emai l Content</h4>'+checkStrin gType(mailItem. Body)+"</
p><hr/>"
dataToWrite=dat a+sender+time+a ttachment+edata
return dataToWrite

#function for saving the attachment.we are calling attachments
SaveAsFile to save the attachment.
#SaveAsFile is com method.for more info dig into msdn :-)
def saveAttachments (atmts):
for kk in range(1,len(atm ts)):
atmt=atmts[kk]
abc=os.path.isd ir(os.getcwd()+ '\email')
if(abc==True):
print 'directory exists'
else:
os.mkdir(os.get cwd()+'\email')
path=os.path.ab spath(os.getcwd ()+'\email')
atmt.SaveAsFile (path+"\\"+atmt .DisplayName)

# function to check whether the character encoding is ascii or smthing
else
def checkStringType (a):
if isinstance(a,st r):
b='not a unicode string'
else:
a.encode('utf-8')
#print 'unicode type'
return a

#bit of html stuff so that i can see my output on browsers.
def getHTMLString(e mailData):
a='<html><head> <title>Your Email Data log is here</title></
head><body>'+em ailData+'</body></html>'
return a

#main entrance to the program
def main():
global outlook_app,inb ox_obj
outlook_app=get AppRef()
inbox_obj=getOu tLookFolders(ou tlook_app)
getMailContent( inbox_obj)

main()

once again thanks for your help.

thanks and regards
sandeep kumar sharma
Jun 27 '08 #8
En Tue, 20 May 2008 04:04:13 -0300, sandeep <sh**********@g mail.com>
escribió:
thanks for ur replies. i have a bit closer look at my code and i am
able to fix the problem.now my exe is working fine.the code is bit
more cleaner now as i removed lot of unused function from it and try
to document it also.
Glad to see it worked finally. Just a few comments:
#function which will initialise outlook and return its reference
def getAppRef():
temp=win32com.c lient.Dispatch( "OutLook.Applic ation")
return temp.GetNamespa ce("MAPI")
Instead of a comment, use a docstring
<http://docs.python.org/tut/node6.html#SECT ION006600000000 000000000>

def getAppRef():
"""Initiali se outlook and return its reference."""
...
abc=os.path.isd ir(os.getcwd()+ '\email')
if(abc==True):
print 'directory exists'
else:
os.mkdir(os.get cwd()+'\email')
path=os.path.ab spath(os.getcwd ()+'\email')
atmt.SaveAsFile (path+"\\"+atmt .DisplayName)
Use '\\email' instead, or r'\email'. \ is the escape character, '\temp'
actually isn't what you may think. The rules:
<http://docs.python.org/ref/strings.html>
Anyway, it's much better to use os.path.join to build a path:

email_dir = os.path.abspath (os.path.join(o s.getcwd(), 'email'))
abc = os.path.isdir(e mail_dir)
if abc:
print 'directory exists'
else:
os.mkdir(email_ dir)
atmt.SaveAsFile (os.path.join(e mail_dir, atmt.DisplayNam e))
# function to check whether the character encoding is ascii or smthing
else
def checkStringType (a):
if isinstance(a,st r):
b='not a unicode string'
else:
a.encode('utf-8')
#print 'unicode type'
return a
This function does not perform what the comment says.
The b='...' is useless, and the a.encode(...) line *returns* a string
(which is immediately discarded) - it does not modify `a`, strings in
Python are immutable.

--
Gabriel Genellina

Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14344
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package because of a binary module which has to be compiled with Visual C 6. My scripts start with a '#!/usr/bin/env python' shebang, as God intended. ...
33
2936
by: Darren Dale | last post by:
I love the language. I love the community. My only complaint is that Python for Windows is built with Visual Studio. It is too difficult to build python, or a module, from source. This is what open source is all about, isnt it? I even have a copy of visual studio, and I still cant build modules from source, because my academic copy is...
5
2661
by: Fuzzyman | last post by:
Python 2.4 is built with Microsoft Visiual C++ 7. This means that it uses msvcr7.dll, which *isn't* a standard part of the windows operating system. This means that if you build a windows installer using distutils - it *requires* msvcr7.dll in order to run. This is true even if your package is a pure python package. This means that when...
10
3670
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. Andrew dalke@dalkescientific.com
35
3048
by: Michael Kearns | last post by:
I've been using python to write a simple 'launcher' for one of our Java applications for quite a while now. I recently updated it to use python 2.4, and all seemed well. Today, one of my colleagues noted that on her machine the launcher would complain it was missing a DLL - msvcr71.dll However, there's a very grey area concerning the...
17
3849
by: Paul Rubin | last post by:
Dumb question from a Windows ignoramus: I find myself needing to write a Python app (call it myapp.py) that uses tkinter, which as it happens has to be used under (ugh) Windows. That's Windows XP if it makes any difference. I put a shortcut to myapp.py on the desktop and it shows up as a little green snake icon, which is really cool and...
3
5112
by: diffuser78 | last post by:
I am a newbie in Python and want your help in writing python script. I have to remotely shut the windows px from linux box. I run OpenSSH on windows PC. I remotely connect it from Linux box using ..... ssh Admin@IP_ADDR # connects me fine now without problems (LOCAL) Next, I wrote a script that would log me in and also shut the...
16
3082
by: diffuser78 | last post by:
I want to write a python program and call OS specific commands in it. So basically, instead of typing in on the command line argument I want to have it in a python program and let it do the action. for example. in my program I would want to call the ssh feature like one does on the command line ssh Admin@192.168.2.10 .....etc ...
15
3192
by: kyosohma | last post by:
Hi, I am trying to get a small group of volunteers together to create Windows binaries for any Python extension developer that needs them, much like the package/extension builders who volunteer their time to create Linux RPMs. The main thing I need are people willing to test the binaries to make sure the extension is stable. This would...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.