python script to windows exe
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue May 20 18:50:06 EDT 2008
En Tue, 20 May 2008 04:04:13 -0300, sandeep <shiningsandy at gmail.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.client.Dispatch("OutLook.Application")
> return temp.GetNamespace("MAPI")
Instead of a comment, use a docstring
<http://docs.python.org/tut/node6.html#SECTION006600000000000000000>
def getAppRef():
"""Initialise outlook and return its reference."""
...
> abc=os.path.isdir(os.getcwd()+'\email')
> if(abc==True):
> print 'directory exists'
> else:
> os.mkdir(os.getcwd()+'\email')
> path=os.path.abspath(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(os.getcwd(), 'email'))
abc = os.path.isdir(email_dir)
if abc:
print 'directory exists'
else:
os.mkdir(email_dir)
atmt.SaveAsFile(os.path.join(email_dir, atmt.DisplayName))
> # function to check whether the character encoding is ascii or smthing
> else
> def checkStringType(a):
> if isinstance(a,str):
> 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
More information about the Python-list
mailing list