| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2759 人关注过本帖
标题:Python 怎么打开文件
只看楼主 加入收藏
q18024155574
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2014-11-27
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:9 
Python 怎么打开文件
>>> context = "'hello worldhello china'"
>>> f = open('hello.txt','w')
>>> f.write(context)
>>> f.close()
为什么我打开不了,新人求不喷
搜索更多相关主题的帖子: hello china 
2014-11-27 16:47
静夜思
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:济南的冬天
等 级:管理员
威 望:11
帖 子:8902
专家分:2567
注 册:2004-3-25
收藏
得分:0 
确定文件是否存在,另外,错误提示是什么?

畅所欲言
2014-11-27 16:54
q18024155574
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2014-11-27
收藏
得分:0 
回复 2 楼 静夜思
>>> context = "'hello world hello china'"
>>> f= = file('hello.txt','w')
SyntaxError: invalid syntax
>>> f = file('hello.txt','w')
>>> f.write(context)
>>> f.close
<built-in method close of file object at 0x0000000002846420>
>>>
没有错误提示吧,可是我不知道怎么用python对文本内容进行编写啊,难道不能用phthon(GIU)进行编写,要用脚本?
2014-11-27 17:00
静夜思
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:济南的冬天
等 级:管理员
威 望:11
帖 子:8902
专家分:2567
注 册:2004-3-25
收藏
得分:0 
f.close后面要带括号

畅所欲言
2014-11-27 17:01
q18024155574
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2014-11-27
收藏
得分:0 
回复 4 楼 静夜思
Type "copyright", "credits" or "license()" for more information.
>>> context = "'hello world hello china'"
>>> f= = file('hello.txt','w')
SyntaxError: invalid syntax
>>> f = file('hello.txt','w')
>>> f.write(context)
>>> f.close
<built-in method close of file object at 0x0000000002846420>
>>> f.close()
>>>
那然后呢
2014-11-27 17:03
q18024155574
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2014-11-27
收藏
得分:0 
回复 4 楼 静夜思
我确实是没有创建文档的,不是没创建文档的话会自动生成一个吗
还有假如是自动生成文档,那文档自动保存在哪呢
2014-11-27 17:05
静夜思
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:济南的冬天
等 级:管理员
威 望:11
帖 子:8902
专家分:2567
注 册:2004-3-25
收藏
得分:20 
没出错,证明程序正常,hello world hello china已经被成功写进hello.txt

畅所欲言
2014-11-27 17:05
q18024155574
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2014-11-27
收藏
得分:0 
回复 7 楼 静夜思
可是我没找到hello.txt
在哪看的啊
2014-11-27 17:08
静夜思
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:济南的冬天
等 级:管理员
威 望:11
帖 子:8902
专家分:2567
注 册:2004-3-25
收藏
得分:0 
退出python的交互式环境 exit()
然后所在的目录下应该就能找到hello.txt

畅所欲言
2014-11-27 17:11
q18024155574
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2014-11-27
收藏
得分:0 
回复 9 楼 静夜思
找到了,万谢
2014-11-27 17:23
快速回复:Python 怎么打开文件
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017443 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved