def charcast(s,dt): if s!='' and s !='nan': return "('{0}'::{1})".format(s,rs(dt)) else: return 'NULL'
import pandas as pd import psycopg2 as p2 from astropy.io import fits import re from fitsformatdict import resolve as rs def charcast(s,dt): if s!='' and s !='nan': return "('{0}'::{1})".format(s,rs(dt)) else: return 'NULL' n=fits.open('makarov2.fit') repo=re.compile(r'B-V') mportString=repo.sub('B_V',', '.join(['{0} {1}'.format(n[1].data.names[i],rs(n[1].data.formats[i])) for i in range(len(n[1].data.columns))])) con=p2.connect("dbname='stars' user='******' host='localhost'") cur=con.cursor() #cur.execute("drop table makarov2") #con.commit() cur.execute("create table makarov2 ({0});".format(mportString)) con.commit() for d in n[1].data: imp=[] s=[str(i) for i in d] names=repo.sub('B_V',', '.join(n[1].data.names)) for i in range(len(s)): if s[i]!='' and s[i]!='nan': imp=imp+[s[i]] else: dt=rs(n[1].data.formats[i]) if 'varchar' in dt: imp=imp+[''] else: