#!/usr/bin/env python
head='auto_userone'
name='Jordy'
sex='male'
hobby='girl'
#*************方法一
def WriteToFileUsePrint():
with open('sample.txt', 'a+') as fd:
print >> fd, "head:"+head+'\n',"name:"+name+'\n',"sex:"+sex+'\n', "hobby:"+hobby+'\n'
fd.close()
#*************方法二
def WriteToFile():
with open('sample.txt', 'a+') as fd:
fd.write("head:"+head+'\n' + "name:"+name+'\n' + "sex:"+sex+'\n' + "hobby:"+hobby+'\n')
fd.close()
if __name__ == '__main__':
WriteToFile()
WriteToFileUsePrint()
python将多个变量输入到文件
最新推荐文章于 2024-08-16 15:02:52 发布