[Tutor] help making my ftp script more pythony
Sean 'Shaleh' Perry
shalehperry@attbi.com
Sun, 20 Jan 2002 22:36:41 -0800 (PST)
>
> def CallBak(DirString):
> Path = DirString[56:]
> # print Path
> PathList.append(Path)
> return
>
an empty return has no point
>#Connect to host
> try:
> ftp = ftplib.FTP('ftpav.cai.com')
> except ftplib.all_errors, e:
> print e
>
you do not actually handle any of these exceptions, you just print. I more
typical python app would likely wrap this whole block in a single exception,
perhaps withing a loop
>
> if os.path.isfile(TempPath+"\\"+FileName):
> try:
> os.remove(TempPath+"\\"+FileName) #it's a file, delete it
> except:
> #probably failed because it is not a normal file
> win32api.SetFileAttributes(TempPath+"\\"+FileName,
> win32con.FILE_ATTRIBUTE_NORMAL)
> os.remove(TempPath+"\\"+FileName) #it's a file, delete it
>
use os.path.join(), makes the code a lot clearer.
filename = os.path.join(TempPath, Filename)