首页 > python,如何把变量类型打印到文件?

python,如何把变量类型打印到文件?

这样貌似不行

    fileHandle = open('test.txt', 'a')
    fileHandle.write(str(type(abc)))
    fileHandle.close()

你的变量abc是不是没定义?我试了一下可以打印 代码是这样的

 a  = str(type('abc'))
 myfile = open('test.txt', 'w')
 myfile.write(a)
 myfile.close()

# define abc
abc = 123

with open('test.txt', 'a') as f:
    f.write(str(type(abc)))
【热门文章】
【热门文章】