我有一个使用Twilio的python程序,我刚从PKL数据库转移到CSV。我读到访问时间大致相同,但希望让编辑更容易。
问题是Twilio喜欢电话号码的前导“+”(我存储在数据库中),但在Excel中编辑时会删除所有这些前导加号。
在twirio的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
答案 0 :(得分:1)
首先想到文本之前的勾号以保留单元格中公式的解释,这可能很有用(ex: '+33 445 455 333)
。
除了在CSV中,它不受支持。它似乎有效,但在保存为CSV时丢失了。额外报价也不起作用。
作为替代方案,您可以将数据库保存为XLSX而不是CSV
(我希望你不会找到我的答案意见,因为它可能存在其他几个有效的解决方案)