我有一個使用Twilio的Python程序,我剛從PKL數據庫移動到CSV。我讀到訪問時間大致相同,但想要更容易編輯。通過Excel保存CSV中的前導「+」
問題是Twilio喜歡電話號碼(我將其存儲在數據庫中)的前導「+」,但在Excel中編輯時會刪除所有這些前導加號。
處理Twilio的python電話號碼存儲的最佳方式是什麼?
def save_pkl(pkl, name):
with open(os.path.join(__location__,name + '.pkl'), 'wb') as f:
pickle.dump(pkl, f, 0) #replace 0 with pickle.HIGHEST_PROTOCOL
def load_pkl(name):
with open(os.path.join(__location__,name + '.pkl'), 'rb') as f:
return pickle.load(f)
def save_csv(obj, name):
f=open(os.path.join(__location__,name+'.csv'),"wb")
writer=csv.writer(f)
if name=="customer":
writer.writerow(("Name","MobileNumber","Email","Joined"))
for number in obj:
writer.writerow((obj[number]["name"],number,obj[number]["email"],obj[number]["joined"]))
else:
writer.writerow(("Name","MobileNumber","Email"))
for number in obj:
writer.writerow((obj[number]["name"],number,obj[number]["email"]))
f.close()
def load_csv(name):
db={}
f=open(os.path.join(__location__,name+'.csv'),"rb")
headers = next(f).strip().split(",")
freader = csv.reader(f)
for entry in freader:
name = entry[0]
mobilenumber = entry[1]
email = entry[2]
db[mobilenumber]={"name" : name, "email" : email}
if "Joined" in headers:
joined = entry[3]
db[mobilenumber]["joined"] = joined
f.close()
return db
你能提供你的代碼嗎? – xli
@xli我只是添加了我的pkl和csv加載/保存代碼 – atclaus