自动导入PEP [英] Automatic import PEP

查看:62
本文介绍了自动导入PEP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






我写了''autoimp''模块[1],允许你导入懒人模块:


来自autoimp import *(导入所有模块周围的懒惰包装器对象;懒惰

模块将变为正常模块时属性

首先使用getattr()访问。

来自autoimp import A,B(导入特定的懒惰模块包装器对象)。


autoimp的要点是通过包含from autoimp import *来使用交互式Python提示

更高效在PYTHONSTARTUP文件中。

因此可以使用:


>> urllib2.urlopen(''http://www.google.com'')。read()
Image.open(''test.bmp'')
pylab.plot( [1,2],[3,4])
scipy.linalg.eig([[1,2],[3,4]])
...



完全可以使用交互式提示而不使用import

语句。在实践中,我发现在所有延迟模块的初始导入中,有很少的时间开销和/或
和内存(假设所有的Python

模块路径都在本地磁盘,而不是网络上的。)


我还发现了autoimp用于编写普通的Python应用程序;一个人可以使用来自autoimp import *的
在Python源文件的顶部,因此所有可用于该源文件的
Python模块,这导致编写程序的效率提高了我必须仔细考虑全局变量以避免名称冲突错误。


现在因为这个功能很有用,我想写一个PEP来添加

" lazy import" Python解释器的功能。


具体来说:


懒惰导入*

懒惰导入A,B,C


这将涉及引入一个新的关键字,例如lazily。


PEP应包含内置Python的扩展__import __(__ lazilyimport__?)

和imp和zipimport模块,以便新的懒惰导入功能可以由动态完全利用。 Python代码。


与autoimp密切相关模块是Philip Eby的导入模块[2]。导入

模块可以懒惰地导入单个模块以及许多其他功能,

因此Philip可能希望参与其中,并且导入的功能可以如果需要

,请在PEP中使用。


意见?


[1]。 http://cheeseshop.python.org/pypi/autoimp/1.0。 2

[2]。 http://peak.telecommunity.com/DevCenter/Importing

__________________________________________________

你是雅虎吗??

厌倦了垃圾邮件?雅虎邮件具有最好的垃圾邮件保护
http://mail.yahoo.com

解决方案

嗨!


>>我还找到了autoimp在编写普通Python时很有用...



+1


-

@ -salutations


Michel Claveau


意见?


很棒:)


Connelly Barnes启发我们:


我写了' 'autoimp''模块[1],它允许你导入懒惰模块:


autoimp的要点是使用交互式Python

通过加入from autoimp import *来提高工作效率在

PYTHONSTARTUP文件中。



听起来很棒。


我还找到了autoimp用于编写普通的Python

应用程序;一个人可以使用from autoimp import *在一个

Python源文件的顶部,因此所有Python模块都可用于

源文件



这听起来像是我的新bug的来源。除此之外,您对该程序使用的所有模块都没有

概述。这也是

阻止使用pylint和朋友自动检查。


Sybren

-

Sybren St ?? vel

St ?? vel IT - http:/ /www.stuvel.eu/



Hi,

I wrote the ''autoimp'' module [1], which allows you to import lazy modules:

from autoimp import * (Import lazy wrapper objects around all modules; "lazy
modules" will turn into normal modules when an attribute
is first accessed with getattr()).
from autoimp import A, B (Import specific lazy module wrapper objects).

The main point of autoimp is to make usage of the interactive Python prompt
more productive by including "from autoimp import *" in the PYTHONSTARTUP file.
Thus one can use:

>>urllib2.urlopen(''http://www.google.com'').read()
Image.open(''test.bmp'')
pylab.plot([1,2],[3,4])
scipy.linalg.eig([[1,2],[3,4]])
...

One can thenceforward use the interactive prompt without using the "import"
statement at all. In practice, I have found that there is little overhead in time
and memory for the initial import of all lazy modules (assuming all of the Python
module paths are on the local disk, and not on a network).

I have also found "autoimp" useful in writing normal Python applications; one can
use "from autoimp import *" at the top of a Python source file and thus have all
Python modules available to that source file, which results in increased
efficiency of writing the program with the downside that one has to think more
carefully about global variables to avoid name conflict bugs.

Now because this feature is useful, I thought of writing a PEP to add the
"lazy import" functionality to the Python interpreter.

Specifically:

lazily import *
lazily import A, B, C

This would involve the introduction of a new keyword, such as "lazily".

The PEP should include extensions to the builtin Python __import__ (__lazilyimport__ ?)
and the imp and zipimport modules so that the new "lazy import" feature can be
fully utilized by "dynamic" Python code.

Closely related to the "autoimp" module is Philip Eby''s Importing module [2]. The Importing
module has the ability to lazily import a single module as well as a number of other features,
so Philip may wish to be involved, and features from Importing may be used in the PEP if
desired.

Opinions?

[1]. http://cheeseshop.python.org/pypi/autoimp/1.0.2
[2]. http://peak.telecommunity.com/DevCenter/Importing
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

解决方案

Hi!

>>I have also found "autoimp" useful in writing normal Python...

+1

--
@-salutations

Michel Claveau


Opinions?

Great :)


Connelly Barnes enlightened us with:

I wrote the ''autoimp'' module [1], which allows you to import lazy modules:

The main point of autoimp is to make usage of the interactive Python
prompt more productive by including "from autoimp import *" in the
PYTHONSTARTUP file.

Sounds like a great idea.

I have also found "autoimp" useful in writing normal Python
applications; one can use "from autoimp import *" at the top of a
Python source file and thus have all Python modules available to
that source file

That sounds like a source of new bugs to me. Besides that, you have no
overview at all of which modules are used by the program. It also
prevents automated checking of that using pylint and friends.

Sybren
--
Sybren St??vel
St??vel IT - http://www.stuvel.eu/


这篇关于自动导入PEP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆