[英]Inheritance in web.py?
我目前正在开发wep.py应用程序。 这是与web.py和wsgi绑定的我的Web应用程序。
根/ main.py
import web
import sys
import imp
import os
sys.path.append(os.path.dirname(__file__))
#from module import module
from exam import exam
urls = (
'/exam', 'exam'
)
application = web.application(urls, globals(), autoreload = True).wsgifunc()
我的应用程序在根目录的module.py中有一个抽象类,称为模块,其目的是由模块继承。
根/ module.py
class module:
def fetchURL(self, url):
# ...
return content
称为“考试”的较低级别的模块将继承该模块
root / exam / init .py
from module import module
class exam(module):
def getResults(self):
# error occurs here
self.fetchURL('math.json')
当我调用父方法时,web.py引发异常
WalkerError :(“意外的节点类型”,339)
环境:Python 2.5
我该如何解决该问题? 谢谢
//编辑03 July 7:10 GMT + 0
堆栈跟踪如下
mod_wsgi (pid=1028): Exception occurred processing WSGI script 'D:/py/labs_library/index.py'.
Traceback (most recent call last):
File "D:\csvn\Python25\lib\site-packages\web\application.py", line 277, in wsgi
result = self.handle_with_processors()
File "D:\csvn\Python25\lib\site-packages\web\application.py", line 247, in handle_with_processors
return process(self.processors)
File "D:\csvn\Python25\lib\site-packages\web\application.py", line 244, in process
raise self.internalerror()
File "D:\csvn\Python25\lib\site-packages\web\application.py", line 467, in internalerror
return debugerror.debugerror()
File "D:\csvn\Python25\lib\site-packages\web\debugerror.py", line 305, in debugerror
return web._InternalError(djangoerror())
File "D:\csvn\Python25\lib\site-packages\web\debugerror.py", line 290, in djangoerror
djangoerror_r = Template(djangoerror_t, filename=__file__, filter=websafe)
File "D:\csvn\Python25\lib\site-packages\web\template.py", line 845, in __init__
code = self.compile_template(text, filename)
File "D:\csvn\Python25\lib\site-packages\web\template.py", line 924, in compile_template
ast = compiler.parse(code)
File "D:\csvn\Python25\lib\compiler\transformer.py", line 51, in parse
return Transformer().parsesuite(buf)
File "D:\csvn\Python25\lib\compiler\transformer.py", line 128, in parsesuite
return self.transform(parser.suite(text))
File "D:\csvn\Python25\lib\compiler\transformer.py", line 124, in transform
return self.compile_node(tree)
File "D:\csvn\Python25\lib\compiler\transformer.py", line 167, in compile_node
raise WalkerError, ('unexpected node type', n)
WalkerError: ('unexpected node type', 339)
如果有可能,我想关闭模板功能,因为我仅将python用于移动应用程序的JSON输出。
如果创建python模块,则应在层次结构顶部添加__init__.py
:
dvedit/
__init__.py
clipview.py
filters/
__init__.py
这意味着在将通过from ... import ...
导入的每个目录中,都应具有__init__.py
文件。
可用的更多信息: http : //wiki.cython.org/PackageHierarchy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.