April 5, 2008

Packages are a way of structuring Python's module namespace by using ``dotted module names''.

Note that when using from package import item, the item can be either a submodule (or subpackage) of the package, or some other name defined in the package, like a function, class or variable. The import statement first tests whether the item is defined in the package; if not, it assumes it is a module and attempts to load it. If it fails to find it, an ImportError exception is raised.

Some Notice:

Now what happens when the user writes from sound.effects import *? Ideally, one would hope that this somehow goes out to the filesystem, finds which submodules are present in the package, and imports them all. Unfortunately, this operation does not work very well on Windows platforms, where the filesystem does not always have accurate information about the case of a filename! On these platforms, there is no guaranteed way to know whether a file ECHO.PY should be imported as a module echo, Echo or ECHO. (For example, Windows 95 has the annoying practice of showing all file names with a capitalized first letter.) The DOS 8+3 filename restriction adds another interesting problem for long module names.

Packages support one more special attribute, __path__. This is initialized to be a list containing the name of the directory holding the package's __init__.py before the code in that file is executed. This variable can be modified; doing so affects future searches for modules and subpackages contained in the package.

While this feature is not often needed, it can be used to extend the set of modules found in a package.



Technorati :

有一根27厘米的细木杆,在第3厘米、7厘米、11厘米、17厘米、23厘米这五个位置上各有一只蚂蚁。 木杆很细,不能同时通过一只蚂蚁。开始 时,蚂蚁的头朝左还是朝右是任意的,它们只会朝前走或调头,但不会后退。当任意两只蚂蚁碰头时,两只蚂蚁会同时调头朝反方向走。假设蚂蚁们每秒钟可以走一厘米的距离。 编写程序,求所有蚂蚁都离开木杆的最小时间和最大时间。

----------------------------------------------------


***  最笨的方法当然是把蚂蚁看成一个一个的去遍历左右; // 还真有人这么写

***  然后好一点的方法是递归:

类似这种:http://blog.csdn.net/andylin02/archive/2007/07/27/1711701.aspx
就不贴代码了

***  最简单的方法当时是“禅”啦

Python代码:
def f(x):return 27-x
a=[3,7,11,17,23] 
b=map(f,a)
print 'max:',max(max(a),max(b))
print 'min:',max(min(a[x],b[x]) for x in range(0,5))


那你看,万生在人海穿梭,相遇又回头:如果把这个过程想象成我继续走,他继续走;
我穿着他的躯壳,他穿着我的躯壳,那岂不等同于我们没有相识

所以
要算最长的的时间 就是初始状况下 蚂蚁离距离它最远的那个边的最大值。
要算最少的时间 就是所有蚂蚁中最后一只走出来的时间,就是每个蚂蚁都朝着离自己近的一个端点爬,然后这些时间中最大的一个。
上面是一段简单的草稿代码 就么的注释了。

缘分那。。缘分。。

《WxPython in Action》中译文:
http://www.pythontik.com/blog/default.asp?tag=wxPython

翻译的哥们的耐心真厉害!

大赞一下。。