haizei 发表于 2019-9-24 16:51:09

import urllib.request


with open('D:\\Python_Project\\2019.9.24\\urls.txt','r',encoding='utf-8') as f:
    website_list = f.readlines()
    length = len(website_list)
    #print(website_list)
    #print(length)
    for i in range(1,length+1):
      F = open('D:\\Python_Project\\2019.9.24\\url_%d.txt' %i,'w',encoding='utf-8')
      response = urllib.request.urlopen(website_list)
      html = response.read()
      html = html.decode('utf-8')
      F.write(html)
      F.close()

huazai33 发表于 2019-9-25 13:57:13

thank you for sharing

anfree 发表于 2019-9-29 11:17:15

努力學習中~

dearuser 发表于 2019-10-5 11:13:03

f.truncate()

——f.truncate(f.tell())

小鱼咸鱼 发表于 2019-10-7 15:13:18

感谢老师的资料,让我,有种恍然大明白的感觉

MMMz 发表于 2019-10-9 16:08:58

1

memo1989 发表于 2019-10-11 09:19:54

支持一波。

好好学习88 发表于 2019-10-22 17:19:25

坚决支持!!!!!!!!!!!!

kliang 发表于 2019-10-25 19:26:11

看答案

TheOne000 发表于 2019-10-25 20:14:02

课后题:
测试题:
0.B 应该和转义字符有关;
>>> f = open('E:\\Python\\小甲鱼\\2/test0.txt')
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
    f = open('E:\\Python\\小甲鱼\\2/test0.txt')
FileNotFoundError: No such file or directory: 'E:\\Python\\小甲鱼\\2/test0.txt'
>>> f = open('E:\\Python\\小甲鱼\\2/test0.txt','w')
>>> f = open('E:\\Python\\小甲鱼\\2\test1.txt','w')
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
    f = open('E:\\Python\\小甲鱼\\2\test1.txt','w')
OSError: Invalid argument: 'E:\\Python\\小甲鱼\\2\test1.txt'
>>> f = open('E:\\Python\\小甲鱼\\2//test2.txt','w')

1.可读
2.二进制,可执行
3.这个不太清楚
4.
5.
>>> for each in f:
        print(each)

       
尔康:肿么了,我们昨天不是已经把话说明白了吗?又出什么事了?脸色怎么这么苍白?为什么不看着哥?

紫薇:你骗我?

尔康:我又怎么了?

紫薇:紫薇。你跟我说你和紫薇没有过去,可是在回廊下看雪看月亮谈了整整一晚,难道这不算是过去吗?你可以爱柳青柳红,可以爱小燕子,可以爱紫薇,可以爱五阿哥,就不可以爱我吗?


6.
>>> f.read(10)
'尔康:肿么了,我们昨'

7。tell()
8.我测试完没出错啊。
>>> f.seek(45,0)
45

grey1001 发表于 2019-10-28 11:27:48

where is the record.txt file(the lesson 29)?

exin2 发表于 2019-11-1 21:10:46

为什么Mac打不开桌面文件老是提醒错误

yoyo19980720 发表于 2019-11-5 11:27:30

kankankankan

liangyan888 发表于 2019-11-10 16:17:12

做完作业再看更有收获。

Timer__18 发表于 2019-11-13 13:44:16

感谢小甲鱼!!!

海月清辉 发表于 2019-11-26 01:02:16

seek里,现在用法已变,from是默认了

盛远港 发表于 2019-11-26 21:24:49

学习

foreverqaz 发表于 2020-1-3 20:28:28

打卡

srxh17 发表于 2020-1-22 14:18:18

{:10_249:}{:10_269:}{:10_269:}

云云云诶 发表于 2020-1-27 12:07:06

已完成代码
页: 3 4 5 6 7 8 9 10 11 12 [13] 14 15 16 17 18
查看完整版本: 文件的打开模式和文件对象方法