AttributeError: 'module' object has no attribute 'urlopen' (Python 2.7)
AttributeError: 'module' object has no attribute 'urlopen' (Python 2.7)
我正在为我的学校编写一个程序,我正在为每位教师在文本文件中托管每日 SBWAT(学生将能够)。这是我的代码,SchoolNet.py
import Tkinter
import urllib
print urllib.__file__
def showsbwat(teacher):
sbwat = urllib.openurl("192.168.1.203/" + teacher + ".txt")
print sbwat
def showshecdule():
mainwindow.withdraw()
schedulewindow.deiconify()
firstperiodbutton = Tkinter.Button(schedulewindow, text = periodlist[0], command = lambda: showsbwat(periodlist[0]))
firstperiodbutton.pack()
global sbwatlabel
sbwatlabel = Tkinter.Label(schedulewindow, text = "")
sbwatlabel.pack()
def login():
try:
schedulefile = open(usernamevar.get() + ".txt", "r")
global periodlist
periodlist = schedulefile.readlines()
print periodlist
mainwindow.deiconify()
loginwindow.withdraw()
except:
usernamevar.set("Invalid ID")
loginwindow = Tkinter.Tk()
loginwindow.wm_title('Login to SchoolNet')
mainwindow = Tkinter.Tk()
mainwindow.wm_title('SchoolNet')
schedulewindow = Tkinter.Tk()
schedulewindow.wm_title('SchoolNet Schedule')
mainwindow.withdraw()
schedulewindow.withdraw()
loginwindow.deiconify()
schedulebut = Tkinter.Button(mainwindow, text = 'Schedule', command=showshecdule)
schedulebut.pack()
usernamevar = Tkinter.StringVar()
usernameentry = Tkinter.Entry(loginwindow, textvariable=usernamevar)
usernameentry.pack()
loginbut = Tkinter.Button(loginwindow, text="Login", command=login)
loginbut.pack()
Tkinter.mainloop()
但是,当我 运行 它时,我不断收到此错误:
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1486, in __call__
return self.func(*args)
File "SchoolNet.py", line 12, in <lambda>
firstperiodbutton = Tkinter.Button(schedulewindow, text = periodlist[0], com
mand = lambda: showsbwat(periodlist[0]))
File "SchoolNet.py", line 6, in showsbwat
sbwat = urllib.openurl("192.168.1.203/" + teacher + ".txt")
AttributeError: 'module' object has no attribute 'openurl'
我已经用 urllib 和 urllib2 试过了,但我得到了同样的错误。 None 目录中的其他文件的名称与任何 python 模块的名称相同。我究竟做错了什么?
我正在使用 Python 2.7
是urlopen
不是openurl
:
urllib.urlopen()
从 urllib.request 导入假期
URL = "www.webpage-address"
页=假期(URL)
文字=page.read()
我正在为我的学校编写一个程序,我正在为每位教师在文本文件中托管每日 SBWAT(学生将能够)。这是我的代码,SchoolNet.py
import Tkinter
import urllib
print urllib.__file__
def showsbwat(teacher):
sbwat = urllib.openurl("192.168.1.203/" + teacher + ".txt")
print sbwat
def showshecdule():
mainwindow.withdraw()
schedulewindow.deiconify()
firstperiodbutton = Tkinter.Button(schedulewindow, text = periodlist[0], command = lambda: showsbwat(periodlist[0]))
firstperiodbutton.pack()
global sbwatlabel
sbwatlabel = Tkinter.Label(schedulewindow, text = "")
sbwatlabel.pack()
def login():
try:
schedulefile = open(usernamevar.get() + ".txt", "r")
global periodlist
periodlist = schedulefile.readlines()
print periodlist
mainwindow.deiconify()
loginwindow.withdraw()
except:
usernamevar.set("Invalid ID")
loginwindow = Tkinter.Tk()
loginwindow.wm_title('Login to SchoolNet')
mainwindow = Tkinter.Tk()
mainwindow.wm_title('SchoolNet')
schedulewindow = Tkinter.Tk()
schedulewindow.wm_title('SchoolNet Schedule')
mainwindow.withdraw()
schedulewindow.withdraw()
loginwindow.deiconify()
schedulebut = Tkinter.Button(mainwindow, text = 'Schedule', command=showshecdule)
schedulebut.pack()
usernamevar = Tkinter.StringVar()
usernameentry = Tkinter.Entry(loginwindow, textvariable=usernamevar)
usernameentry.pack()
loginbut = Tkinter.Button(loginwindow, text="Login", command=login)
loginbut.pack()
Tkinter.mainloop()
但是,当我 运行 它时,我不断收到此错误:
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1486, in __call__
return self.func(*args)
File "SchoolNet.py", line 12, in <lambda>
firstperiodbutton = Tkinter.Button(schedulewindow, text = periodlist[0], com
mand = lambda: showsbwat(periodlist[0]))
File "SchoolNet.py", line 6, in showsbwat
sbwat = urllib.openurl("192.168.1.203/" + teacher + ".txt")
AttributeError: 'module' object has no attribute 'openurl'
我已经用 urllib 和 urllib2 试过了,但我得到了同样的错误。 None 目录中的其他文件的名称与任何 python 模块的名称相同。我究竟做错了什么? 我正在使用 Python 2.7
是urlopen
不是openurl
:
urllib.urlopen()
从 urllib.request 导入假期
URL = "www.webpage-address"
页=假期(URL)
文字=page.read()