1
9hills Sep 19, 2013 via Android
这种情况一般是在init.py里from .a import a
或者干脆 from .a import * |
2
supersheep OP @9hills soga,多谢。好像from .a这里的"."不是必须的。不过这样以后每加一个页面就还要再在__init__ 里面加一下,感觉不够傻瓜,现在是写了个方法,一开始的时候parse自己写的一个dict变成tuple传给webpy这样子
|
3
aisk Sep 19, 2013
何必一个类一个文件,楼主用的web.py,一个类应该就是一个页面,难道每个页面的处理代码都非常长,必须拆成一个文件?
|
4
supersheep OP @aisk 也还好,个别页面超过50行了。不过分到页面的话根据模板找文件改起来定位会更快一些,个人喜好啦。
|
5
yakczh Sep 19, 2013
分开文件,多人合作的时候方便些
|
6
9hills Sep 20, 2013 via Android
@supersheep 用import *啊 另外.是有深意的
|
7
supersheep OP @9hills 表示在当前目录么?我试了一下,from . import * 不行,from . import a,b 倒是可以的。
|
8
9hills Sep 20, 2013
|
9
9hills Sep 20, 2013
@supersheep
Imports can be ambiguous in the face of packages; within a package, it's not clear whether import foo refers to a module within the package or some module outside the package. (More precisely, a local module or package can shadow another hanging directly off sys.path.) For the second problem, it is proposed that all import statements be absolute by default (searching sys.path only) with special syntax (leading dots) for accessing package-relative imports. 意思是说如果你用import aaa,就无法分辨是import本目录的aaa还是sys.path中的aaa 所以如果是确定要import package内部,就要加点 |
10
supersheep OP @9hills 好的!非常感谢!我好好看看!
|
11
tkdchen Sep 23, 2013 @supersheep Add `from a import *` into file __init__.py under directory controller/page
Or give the full reference path based on the path of your project, `from controller.page.a import *` Better not use dot in from-import statement Sorry for inputting English, cannot use Chinese while writing this. |
12
tonic Sep 23, 2013
在__init__里, from controller.page.a import a = =
|