简体   繁体   English

在web.py中继承吗?

[英]Inheritance in web.py?

I am currently developing wep.py application. 我目前正在开发wep.py应用程序。 This is my web application which is binded with web.py and wsgi. 这是与web.py和wsgi绑定的我的Web应用程序。

root/main.py 根/ 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()

My application has an abstract class called module in module.py in root directory and its purpose is to be inherited by modules. 我的应用程序在根目录的module.py中有一个抽象类,称为模块,其目的是由模块继承。

root/module.py 根/ module.py

class module:
    def fetchURL(self, url):
        # ...
        return content

The lower level module called "exam" would inherits module 称为“考试”的较低级别的模块将继承该模块

root/exam/ init .py root / exam / init .py

from module import module

class exam(module):
    def getResults(self):
        # error occurs here
        self.fetchURL('math.json')

When I call the parent method, web.py raises an exception 当我调用父方法时,web.py引发异常

WalkerError: ('unexpected node type', 339) WalkerError :(“意外的节点类型”,339)

Environment: Python 2.5 环境:Python 2.5

How can I resolve the problem? 我该如何解决该问题? Thanks 谢谢

// EDIT 03 July 10:22 GMT+0 //编辑03 July 7:10 GMT + 0

The stack trace is as follows 堆栈跟踪如下

 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)

If it is possible I would like to turn off the template functionality as I use python only for JSON output for mobile app. 如果有可能,我想关闭模板功能,因为我仅将python用于移动应用程序的JSON输出。

if you create python module you should add __init__.py in top of your hierarchy: 如果创建python模块,则应在层次结构顶部添加__init__.py

dvedit/
  __init__.py
  clipview.py
  filters/
    __init__.py

it means that in every directory which will be imported via from ... import ... should have __init__.py file. 这意味着在将通过from ... import ...导入的每个目录中,都应具有__init__.py文件。

further info available: http://wiki.cython.org/PackageHierarchy 可用的更多信息: http : //wiki.cython.org/PackageHierarchy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM