设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【Python 第32课】 写文件

[复制链接]

0

主题

0

好友

46

积分

新手上路

Rank: 1

11#
发表于 2015-12-9 12:57:15 |只看该作者
#题1
f = file("data.txt")
a1=f.read()
out2=open("output2.txt","w")
out2.write(a1)
out2.close()

#题2
f=raw_input()
out=open("output3.txt","w")
out.write(f)
out.close()

好开心第一次能写出点东西
回复

使用道具 举报

1

主题

1

好友

152

积分

注册会员

Rank: 2

12#
发表于 2015-12-19 14:54:57 |只看该作者
1.
f=open('data.txt')
data=f.read()
print(data)
out=open('output.txt', 'w')
out.write(data)
f.close()
out.close()
回复

使用道具 举报

1

主题

1

好友

152

积分

注册会员

Rank: 2

13#
发表于 2015-12-19 14:59:28 |只看该作者
2.
data=input()
out=open('output.txt','w')
out.write(data)
out.close()
回复

使用道具 举报

0

主题

1

好友

273

积分

中级会员

Rank: 3Rank: 3

14#
发表于 2016-1-2 17:10:39 |只看该作者
第一题
  1. f=file('data.txt')
  2. data=f.read()
  3. out=open('output.txt','a')
  4. out.write(data)
  5. f.close
  6. out.close
复制代码
回复

使用道具 举报

0

主题

1

好友

273

积分

中级会员

Rank: 3Rank: 3

15#
发表于 2016-1-2 17:20:13 |只看该作者
第二题
  1. data=raw_input()
  2. eg=file('excercise.txt','w')
  3. eg.write(data)
  4. eg.close()
复制代码
回复

使用道具 举报

0

主题

0

好友

34

积分

新手上路

Rank: 1

16#
发表于 2016-4-7 17:04:10 |只看该作者
总是提示 IOError: File not open for reading,求解
QQ截图20160407170329.png
回复

使用道具 举报

174

主题

45

好友

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

17#
发表于 2016-4-7 17:32:31 |只看该作者
对不起我是保镖 发表于 2016-4-7 17:04
总是提示 IOError: File not open for reading,求解

w是写入模式
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

0

主题

0

好友

121

积分

注册会员

Rank: 2

18#
发表于 2016-5-5 15:39:55 |只看该作者
Crossin老师,新写的文件必须关闭之后,再打开才能print吗?有没有其他快捷的方式呢?
1.png
回复

使用道具 举报

0

主题

0

好友

121

积分

注册会员

Rank: 2

19#
发表于 2016-5-5 15:49:38 |只看该作者
7.png
回复

使用道具 举报

0

主题

0

好友

20

积分

新手上路

Rank: 1

20#
发表于 2016-5-31 11:41:55 |只看该作者
本帖最后由 FPOS 于 2016-5-31 11:51 编辑
  1. f=file('text1.txt')
  2. date=f.read()
  3. print 'copy over'
  4. f.close()
  5. print 'closed text1'
  6. e=file('text2.txt','w')
  7. e.write(date)
  8. print 'writed in text2'
  9. e.close()
  10. print 'closed text2\n请检查文件'
复制代码
月底终于忙完了,其实还是懒。
  1. f1=raw_input()
  2. f2=file('text2.txt','w')
  3. f2.write(f1)
  4. f2.close()
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-17 16:40 , Processed in 0.030312 second(s), 23 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部