Re: problem with special characters in filename
Try this: import shutil,os file1 = open('a.dat','r') #opens file for reading for line in file1: print line ##old_name = line[0:len(line)-1] #gets rid of "\n" suffix ##print old_name line.strip() #gets rid of "\n" suffix print line os.rename('b.dat',line) #renames file file1.close() From: "fizzo...@gmail.com" To: python-list@python.org Sent: Friday, January 23, 2009 2:43:24 PM Subject: problem with special characters in filename using: Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Hello I have two files (let's assume they are all in the same directory): 1) "a.dat" containing the single line "Sébastien.dat" 2) "Sébastien.dat" containing arbitraty data I want to: open "a.dat" read in the single line ("Sébastien.dat") copy the file described by the single line ("Sébastien.dat") to another location with name "b.dat" This is what I have started with: import shutil file = open('a.dat','r') #opens file for reading for line in file: print line old_name = line[0:len(line)-1] #gets rid of "\n" suffix print old_name shutil.copy(old_name, 'b.dat') #copies file However I get the following error: IOError: [Errno 2] No such file or directory: 'S\xc3\xa9bastien.dat' I'm sure this has something to do with encoding and decoding UTF-8 and Unicode or something like that, but everything I've tried has yet to produce any favourable results. Thanks Dino -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Need script to download file from a server using python script
Hi, I am fairly new to python and i am looking for a python script to download file(latest build) from the server. But, the build name changes daily. For Ex: today the build URL will be "http://mybuilds/myapp_1234.exe"; and tomorrow it will be "http://myserver/mybuilds/myapp_3456.exe";. So i need a script which downloads the latest build without any knowledge of build number. Can anyone help me? Advance thanks, This is my start: ### import os,sys,httplib,time, Server="myserver" Build2Download=mybuilds/myapp_3456.exe installer=myapp_3456.exe print "Downloading Installer... from the site:%s"%Server connection=httplib.HTTPConnection(Server) connection.request("GET",Build2Download) resp = connection.getresponse() if resp.status != 200: print "Error getting installer. GET response : %d %s" % (resp.status, resp.reason) sys.exit(-1) try: open(Installer, 'wb').write(resp.read()) time.sleep(15) except: pass ### The build number keeps changing. So how can i use wildchars(?) or something else to handle change in the build no.? Advance Thanks, Murali. -- http://mail.python.org/mailman/listinfo/python-list