求助webpy这个错误是怎么回事啊?
import weburls = (
'/', 'index'
)
class index:
def GET(self):
print "Hello, world!"
if __name__ == "__main__":
web.run(urls, globals())
运行python web.py,为什么运行时候总是显示错误:
web.run(urls, globals())
AttributeError: 'module' object has no attribute 'run' 文件名改一下 回复 2# anonymous0502
真的可以了,好神奇,多谢,这是为什么呢,web是什么关键字吗
导入的是你写的这个模块文件吧
http://blog.csdn.net/kernelspirit/article/details/3381666
细节上有些东西我也还没明白,又试了下发现跟我以前的理解又有点不一样,我也得再看看:lol 回复 4# anonymous0502
多谢多谢,但是暂时还是不太懂,慢慢研究吧
就这个问题我也来提问一下::lol
我以前认为当自己写了个python脚本,文件名跟标准模块同名时,脚本中import该模块名时是导入的这个脚本本身。
以前自己也做过这样的操作,把文件名改成别的名字就可以了。
看了写别人的博文好像也是这么个意思啊
比如这个:
http://weiweiabc109.blog.163.com/blog/static/2835722011111643052261/
但是刚才自己试了下又发现这样的现象:import time
import sys
#print sys.modules
#print sys.path
def aa(v1):
print(v1)
return 1
time.sleep(2)
if __name__ == '__main__':
time.sleep(2)
上面的脚本保存成time.py却能运行,看看表面性质不是跟楼主的代码挺类似的吗,为什么这样可以运行呢? 回复 5# learningpython
互相学习:mrgreen:
本帖最后由 anonymous0502 于 2012-07-10 14:07 编辑
>>> import time
>>> time.__file__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
>>> import re
>>> re.__file__
'c:\\python32\\lib\\re.py'
time和re这两个有什么特别的地方?为什么一个有__file__属性一个没有?
又把下面这几句保存成re.py也能运行啊import re
def aa(v1):
print(v1)
return 1
if __name__ == '__main__':
r=re.compile(r'^\s*')
这种问题是怎么回事?有没有高手帮忙解答一下啊,多谢:mrgreen: 我的问题有没有人愿意瞄几眼:lol
页:
[1]