上一周在电脑上安装Python 和Pycharm软件,在抖音上学习。抖音博主RIck小白课堂,有一些Python入门的课程,进行学习。
有一节课程,关于文件中写字符的函数小程序,原程序如下:
def textCreate(name,msg):
desktopPath ='C:/Users/EDY/Desktop/'
fullPath = desktopPath + name +'.txt'
file = open(fullPath,'w')
file.write(msg) file.close()
print('done‘)
textCreate( name: 'hello', msg: 'hello wortd')
无法调试通过,各位大侠,请有时间指导一二。
通过查找资料和系统问题反馈和提示,讲程序修订如下:
import typing
def textCreate(name,msg):
desktopPath ='C://Users//GJH2257//'
fullPath = desktopPath + name +'.txt'
file:typing.textIO = open(fullPath, 'w')
print(fullPath)
file.write(msg)
file.close()
print('done')
textCreate( 'hello', 'hello world')
调试成功,并能生成hello.txt文件,并能写入文字。十分开心。
另外,cfg库文件,一直无法安装成功,请高人指点指点,不甚感谢!