|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
原打算在每次数据下载时都新建一个文件来存储数据,结果运行后报错说包装后save_file里的chengdu这个名字没被定义,啊,捉急啊,哪里错了呢
- import urllib.request
- import time,sys
- def save_file(chengdu,count):
- file_name='chengdu'+str(count)+'.txt'
- f=open(file_name,'x')
- f.write(data)
- f.close()
- count=0
- while True:
- s=time.ctime()
- length=len(s)
- sys.stdout.write(s)
- sys.stdout.write('\b'*length)
- url =" 等等等"#不写成这样就发不了啊,url对网站有攻击行为啥的
- data = urllib.request.urlopen(url).read()
- data = data.decode('UTF-8')
- sys.stdout.write(data)
-
- save_file(chengdu,count)
- count+=1
- f.close()
复制代码
报错内容:
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\Python practise\成都空气污染数据下载.py", line 21, in <module>
save_file(chengdu,count)
NameError: name 'chengdu' is not defined
|
|