kearney

自学还没成才的python猿

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
1 def create_text(filename):    
2     path = '/Users/admin/Desktop/' #需自定义路径    
3     file_path = path + filename + '.txt'
4     file = open(file_path,'w')
5     file.close()
6     
7 create_text('hello') # 调用函数

 注意第2行代码,表示的是在桌面新建hello.txt文件。建议写完整路径

>>> 
Traceback (most recent call last):
  File "E:\素材\03 python\导出属性字段.py", line 9, in <module>
    create_text('hello') # 调用函数
  File "E:\素材\03 python\导出属性字段.py", line 7, in create_text
    file = open(file_path,'w')
IOError: [Errno 2] No such file or directory: '/Users/JN-PC/Desktop/hello.txt'
>>> 

 

path = 'C:/Users/admin/Desktop/'

 

posted on 2017-03-27 18:34  Gino森  阅读(11903)  评论(0编辑  收藏  举报