|
|
15鱼币
本帖最后由 vincenzo0823 于 2017-2-21 23:40 编辑
题目是做一个 打开以创建写入内容的函数
- def text_create(name,msg):
- desktop_path = r'C:\Users\Administrator\Desktop'
- full_path = desktop_path + name + '.txt'
- file = open(full_path,'w')
- file.write (msg)
- file.close()
- print ('done')
复制代码
其中
1, def text_create(a,b)报错
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
text_create(a,b)
NameError: name 'a' is not defined
2,def text_create(1,2)报错
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
text_create(1,2)
File "C:\Users\Administrator\Desktop\PYTHON 课后练习\11.py", line 4, in text_create
full_path = str(desktop_path + name + '.txt')
TypeError: Can't convert 'int' object to str implicitly
3,我参数的值是name 为什么下面说找不到name呢?
4,说我不能讲整数 与字符串想家,那应该如何操作才能完成这个内容呢?
那么各位我换个问题,如何创建一个 创建,读取,写入的函数呢?
例如def text_create(name.msg)
这个text_create()调用的时候 name是文件名,msg是内容。 |
|