发布时间:2022-05-19 08:49:51 人气:431 作者:多测师
我们知道,在计算机中,各种数据,各种程序通常是以文件的形式有组织地存放在磁盘、磁带等存储介质上的。文件是我们使用计算机必须使用的工具。在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))
以上内容为大家介绍了python中如何用write函数写入文件?,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注多测师。https://www.e70w.com/xwzx/