`
cloudhe
  • 浏览: 107120 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表
Python 和 Ruby 的相同点:       都强调语法简单,都具有更一般的表达方式。     Python 是缩进,Ruby 是类 Basic 的表达。     都大量减少了符号。     都是动态数据类型。     都是有丰富的数据结构。     都具有 C 语言扩展能力,都具有可移植性,比
If you're not willing to read English, here is a translation: http://blog.csdn.net/lanphaday/archive/2008/08/03/2762251.aspx     What the heck does "pythonic" mean?   This was a question asked a few months ago, on, of all places, the EuroPython mailing list, which is mainly used to plan t ...
Let's feel about what "pythonic" is!   >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Re ...
究竟何谓WiMAX? WiMAX全称为World Interoperability for Microwave Access,即全球微波接入互操作性。WiMAX的另一个名字是802.16。 IEEE802.16标准,又称WiMAX,或广带无线接入(Broadband Wireless Access,BWA)标准。它是一项无线城域网(WMAN)技术,是针对 ...
    这个问题是相当有意义的,如果有了比较好的方法,Python 完全可以用来开发商业软件,而不用担心源代码泄露。    前两天我在网上看了看,有很多的人在问这个问题。大部分的人都在用 py2exe,这是个对 Python 程序打包的东东,实际上只是在 Python 程序中找 出依赖的模块,然后发布这个程序。好处在于可以让这个程序脱离 Python 的环境来执行,不用安装 Python 解释器。但实际上并不能保护源代码,因为源 代码其实也包含在其中了。更好的办法是使用 Pyrex。在 http: //www.cosc.canterbury.ac.nz/greg.ewing/python/Pyr ...
    Python 是支持多线程的,并且是 native 的线程。主要是通过 thread 和 threading 这两个模块来实现的。thread是比较底层的模块,threading 是对 thread 做了一些包装的,可以更加方便的被使用。这里需要提一下的是 Python 对线程的支持还不够完善,不能利用多 CPU,但是下个版本的 Python 中已经考虑改进这点,让我们拭目以待。    threading 模块里面主要是对一些线程的操作对象化了,创建了叫 Thread 的 class。一般来说,使用线程有两种模式,一种是创建线程要执行的函数,把这个函数传递进 Thread 对象里,让它来 ...
    在程序中使用配置文件来灵活的配置一些参数是一件很常见的事情,配置文件的解析并不复杂,在 Python 里更是如此,在官方发布的库中就包含有做这件事情的库,那就是 ConfigParser,这里简单的做一些介绍。    ConfigParser 解析的配置文件的格式比较象 ini 的配置文件格式,就是文件中由多个 section 构成,每个 section 下又有多个配置项,比如:  [db] db_host=127.0.0.1 db_port=3306 db_user=root db_pass=password [concurrent] thread=10 processor=20    ...
>>> import shutil >>> dir(shutil) ['Error', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_samefi le', 'abspath', 'copy', 'copy2', 'copyfile', 'copyfileobj', 'copymode', 'copysta t', 'copytree', 'destinsrc', 'move', 'os', 'rmtree', 'stat', 'sys'] >>> shuti ...
import ftplib ftp = ftplib.FTP() ftp.connect("ftp.freebsdchina.org",21) ftp.login("anonymous", "123") ftp.dir() ftp.quit()  下载用这个: ftp.retrbinary('RETR '+filename, open(filename,'wb').write)  上传用这个: ftp.storbinary("STOR "+filename, open(filename, 'rb'))      ...
import string, os, sys dir = '/var' print '----------- no sub dir' files = os.listdir(dir) for f in files: print dir + os.sep + f print '----------- all dir' for root, dirs, files in os.walk(dir): for name in files: print os.path.join(root, name)  前面的 os.listdir 可以列出 dir 里面的所有文件和目 ...
Python 语言是支持用 C 来它写模块的,其实现有的很多模块也是用 C 写的。这里我做个简单的介绍。先决条件:1. 在 linux 上编写时,需要自己编译出 Python的动态连接库。也就是要有 libpython2.5.so 这样的东西。2. 在 windows 上时,则 ...
这两个基本上都是在循环的时候用。 for i in range(0, 100): print i for i in xrange(0, 100): print i   这两个输出的结果都是一样的,实际上有很多不同,range会直接生成一个list对象: >>> a = range(0, 10) >>> type(a) <type 'list'> >>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> a[0] 0   而xrange则不会直接生成一个list, ...
Python 有一个叫 doctest 的模块,很有意思,它可以让你在代码的注释中写入一些特殊的注释,这些注释是测试程序。Python 可以自动对它进行测试。 import doctest def myadd(a, b): ''' >>> myadd(1, 2) 3 >>> myadd(4, 5) 9 ''' return a+b if __name__ == '__main__': doctest.testmod()  输出: D:\>e2.py -v Trying: myad ...
Python2.5 中新增加了集合内容,让我想起了初中数学。看看: >>> b = set() >>> b.add(1) >>> b.add(2) >>> b.add(3) >>> b.add(4) >>> >>> c = set() >>> c.add(4) >>> c.add(5) >>> c.add(6) >>> d = b.difference(c) >>> print d ...
1. This an interesting usage that I don't know how to call it.  See example: def hehe(tt): return 'hehe'+tt() @hehe def test(): return 'test' print test  The output is same as: def hehe(tt): return 'hehe'+tt() def test(): return 'test' test = hehe(test) print test    Ou ...
Global site tag (gtag.js) - Google Analytics