def importing(): exchange = 'sz' f = open('/home/appleface/ashare/%s.txt'%exchange,'r') for i in f.readlines(): print str(i.strip()) s = ASharesCode.new() try: s.code = str(i.strip()) s.exchange = exchange s.save() except Exception,e: print i logging.error('%s\n',str(e),exc_info=True)