# basic code for downloading a bunch of files at an FTP site using Python's urllib. First I copied the file names from the web site into a text file, from which I extract the names (see below) import urllib import string file = open('WOD1.txt', 'r') # opens a text file with three columns of data I copied from a web page, the middle element is the file name I want to download urls = file.read() # read file into string urls = string.split(urls) # split string into list for i in range(1, len(urls), 3): # iterate through the list, getting the file name file_name = urls[i] # get file name print 'downloading',file_name urllib.urlretrieve('ftp://ftp.nodc.noaa.gov/pub/WOD01/OSD/OBS/'+file_name, 'C:\\temp\\WOD\\'+file_name) # dowlnoad the file using URL (adding file name each time) and save it under the same name in a local directroy ######################################################## #prompt user for filename while 1: try: file_name = raw_input("Type the name of the Fasta file to parse: ") file = open(file_name, 'r') except IOError: print "***ERROR: No such file or directory: \"%s\". Please try again." % file_name else: file.close() break ######################################################## #This code will,let you supply filenames through commandline if __name__ == '__main__': import sys #if no file specified, use current directory #else, use files specified in the command line, e.g. *.gb #*.gb means it will faithfully supply files that end with .gb one by one to make your list of filenames below if len(sys.argv) == 1: filenames = os.listdir(os.curdir) else: filenames = sys.argv[1:] #I hope you understand this, sys.argv is a list and you want everyting from second item to the end of the list #your rest of the code goes here, for example for filename in filenames: #now do something #you can also wrap this code in a try/except/else clause as above #but I'll let you do the minor changes -------- -------- -------- ######################################################## #This code pretty much can store any object, not just strings import pickle file = open('pickl.txt', 'w') dict = {'a':1, 'b':2, 'c':3, 'd':4} pickle.dump(dict, file) file.close() file = open('pickl.txt', 'r+') dict = pickle.load(file) print dict #will output {'a': 1, 'c': 3, 'b': 2, 'd': 4} file.close() ######################################################## #This code to make a database import anydbm db = anydbm.open("database", 'c') db['1'] = 'one' db['2'] = 'two' db['3'] = 'three' db.close() db = anydbm.open('database', 'r') for key in db.keys(): print repr(key), repr(db[key])