Python论坛  - 讨论区

标题:[python-chinese] 请教:wxpython中使用XRC的优缺

2006年11月03日 星期五 09:45

马踏飞燕 honeyday.mj在gmail.com
星期五 十一月 3 09:45:47 HKT 2006

2006/10/31, limodou <limodou在gmail.com>:
> On 10/31/06, jiang hongbo <larkdream在gmail.com> wrote:
> >    呵呵,我现在用的就是wxglade,不过好像不支持绝对定位,有时候不方便。那位知道有所见所得的支持绝对定位的工具吗?
> >   我想请教limodou的可不是XML的自动补全哦,事实上具体说是两个问题:
> >   1.在python中变量名可以指派不同的类型,也就是说变量名所指向的类型在运行时是可变的,那么在编辑器中是如何得到变量名所指派的类型来进行补全的呢?
>
> UliPad目前可以判断变量的类型,但是在相对简单的情况下,如:
>
> a = "string"
>
> 这样ulipad是可以判断的。但是如果一会你赋了一个字符串,一会又是整数,可能还是有问题。这种处理比较麻烦,需要自已实现类似的语法分析,ulipad的主模块中module/PyParse.py中。次模块主要是处理源文件与动态分析的,在acp/python/import_utils.py中,比较麻烦
>

类型判断方面建议参考WingIDE的方法,就是用一个断言语句。
assert isinstance(myvariable, CMyClass)
这样的。
这样的话,在下面的代码中IDE就知道myvariable是CMyClass的实例了,接下来就有补全等功能了。
下面是原话:

You can get more out of Wing's auto-completer, Source Assistant,
goto-definition features, and Source Browser by declaring the class of
instance values in those cases where Wing cannot infer them from your
code.

This is done by inserting isinstance statements.  For example:

assert isinstance(myvariable, CMyClass)

This tells Wing that myvariable can be an instance of class CMyClass
(possibly among other things if you write code that allows multiple
types for a variable).

In cases where doing this introduces a circular import, you can use a
conditional to allow Wing's static analyser to process the code
without causing problems when it is executed:

if 0:
  import othermodule
  assert isinstance(myvariable, othermodule.COtherClass)

In most code, a few such assertions go a long way.  The more Wing
knows about your code, the faster you will be able to edit and
navigate it.

For C/C++ extension modules, where Wing can obtain only limited
information, additional interface information can be provided in
special Python interface files.  For example for an extension module
imported as mymodule, the file mymodule.pi can be created to contain
Python skeleton code that matches the functions, attributes, classes,
and methods defined by the extension module.

Python interface files can often be auto-generated from header or
interface description files.  Examples of *.pi files used by Wing to
provide completion for builtins can be seen in
resources/builtin-pi-files in your Wing IDE installation.

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号