话说有那位大神看看我这个python程序那里出错了
Tofloor
poster avatar
redapple0204
deepin
2016-10-07 03:18
Author
表示输入选项完就直接出错了
代码如下
import os,urllib.request,re,sys,requests,data
print ('欢迎使用arch安装向导获取器')
resp = requests.get("https://raw.githubusercontent.com/redapple0204/my-boring-python/master/tmp/version-beta")
print('目前最新的测试版本是',resp.text)
resp1 = requests.get("https://raw.githubusercontent.com/redapple0204/my-boring-python/master/tmp/version-stable")
print('目前最新的稳定版本是',resp1.text)
print('请输入您要下载的版本(1为测试版,2为稳定版)')
print('将下载到本程序所在的目录')
shuru = input()
shuru
if (shuru == 1):
         lujing = os.getcwd()
         os.chdir(lujing)
         resp3 = requests.get("https://raw.githubusercontent.com/redapple0204/my-boring-python/master/tmp/version-beta-link")
         data = urllib.request.urlopen(resp3,data).read()
         with open("arch-install-guide.doc", 'wb') as f:
          f.write(data)

if(shuru == 2):
          lujing2 = os.getcwd()
          os.chdir(lujing2)
          resp4 = requests.get("https://raw.githubusercontent.com/redapple0204/my-boring-python/master/tmp/version-stable-link")
          data = urllib.request.urlopen(resp4).read()
          with open("arch-install-guide.doc", 'wb') as f:
             f.write(data)


执行结果如下
redapple@kali ~/Desktop> python3 1.py
欢迎使用arch安装向导获取器
目前最新的测试版本是 codename "happymax" build 004

目前最新的稳定版本是 2.0

请输入您要下载的版本(1为测试版,2为稳定版)
将下载到本程序所在的目录
1
redapple@kali ~/Desktop>


桌面上也并没有这个文件,谁知道怎么回事啊.....
Reply Favorite View the author
All Replies
avatar
MeowSprite
deepin
2016-10-07 04:26
#1
input接收的是字符,不是数字。还有os.getcwd(),os.chdir(lujing),有意义吗?还有最开头的import data?
Reply View the author
avatar
redapple0204
deepin
2016-10-07 04:52
#2
https://bbs.deepin.org/post/44283
input接收的是字符,不是数字。还有os.getcwd(),os.chdir(lujing),有意义吗?还有最开头的import data? ...

import data是下载的必要....
感谢你的建议,现在程序已经能正常运行了~
Reply View the author
avatar
MeowSprite
deepin
2016-10-07 05:06
#3
https://bbs.deepin.org/post/44283
import data是下载的必要....
感谢你的建议,现在程序已经能正常运行了~

哦,自己写的模块吗?主要不要使用这么通用的名字,你下面又使用data变量,建议应该避免这样。
Reply View the author
avatar
redapple0204
deepin
2016-10-07 05:57
#4
https://bbs.deepin.org/post/44283
哦,自己写的模块吗?主要不要使用这么通用的名字,你下面又使用data变量,建议应该避免这样。 ...

1.是的
2.好的,谢谢提醒,下次会注意下
Reply View the author