I am new to Python, so forgive me if I am asking a wrong question. I have a .xls that I would like to ftp and save it as a Python object. Currently, I am taking an awkward approach where [Step 1] I first ftp the file and save it as .txt (I know .xls->.txt is a bad idea!), and then [Step 2] open and save that .txt file in Python shell. That is,
## Import the necessary module from ftplib import FTP ftp = FTP('webftp.vancouver.ca') ftp.login() ftp.cwd('OpenData/xls') filename = 'new_food_vendor_locations.xls' ftp.retrbinary('RETR %s' % filename, open('myLovelyNewFile.txt', 'w').write) ftp.quit()
This allows me to create a new file 'myLovelyNewFile.txt' in my current directly. In my Python shell, I have:
myLovelyPython = open('myLovelyNewFile.txt','r') for line in myLovelyPython.readlines(): print line myLovelyPython.close()
Although Python can run all these command lines, the printed lines do not have correct inputs due to the forceful conversion from xls to txt. Furthermore, I would like to save the ftp-ed object directly as some python object (rather than first saving it as .txt outside Python). Is there easy solution to this problem?