![c9b148ffda23d8aff62540a717dd4f52.png](https://i-blog.csdnimg.cn/blog_migrate/f4279e221f1ac17c4beee9fd9b0bfd0d.jpeg)
我们知道,在计算机中,各种数据,各种程序通常是以文件的形式有组织地存放在磁盘、磁带等存储介质上的。文件是我们使用计算机必须使用的工具。在python中文件也很多,想要得到一个程序,就要向文件输入内容。write中文翻译为书写,在python中,就是用write函数写入文件。本文将向大家介绍python中是如何用wreite函数写入文件和设置文件字体大小的。
1、用write函数写入文件
poem = "This is a poem"
dirs = '/Users/joseph/work/python/'
filename = 'poem.txt'
path = dirs + filename
f = open(path, 'w')
f.write(poem)
f.close()
2、设置字体大小
实例:将字体大小更改为16(默认值为8)
import turtle as t
t.write('中国', font=("Arial", 16))
以上就是write函数写入文件和设置字体的过程,字体大小可根据自己的需求来设置字体大小,希望能对你的学习有所帮助哦~
原文至:python中如何用write函数写入文件?-Python学习网