-
yield 的简单解释 - [python]
2008-06-17
yield就相当于往一个list中塞东西而已(初步这么感觉),只不过写法很奇怪罢了。呵呵
>>> def kk(x):
... yield x
... yield x+7
... yield x*2
...
>>> b = kk(14)
&g... -
1.1 A Simple Example - [python]
2008-03-07
1.1 A Simple Example Extending and Embedding the Python Interpreter Previous: 1. Extending Python with Up: 1. Extending Python with Next: 1.2 Intermezzo: Errors and
1.1 A Simple Example ... -
How to define process in python - [python]
2008-02-29
when we run python script, such as a.py, we always see the process (eg: ps -A) is "python", not "a.py", how to solve it:
#!/usr/bin/env python
procname = 'Hello'
import os, sys
if not os.environ.has_key('N... -
python 中如何替换隐含字符 - [python]
2008-02-15
比如这么一句:^A Why miss out?^B^R^P
那些^A, ^B这些什么隐含字符其实是我parse网页后留下的,现在想把这些隐含字符给替换替换掉(或者削掉)
以前用perl是可以这样的:
$str =~ s/[\cA-\cI\cK\cL\cN-\cZ]//gi;
于是就得到Why miss out?了
现在得用python完成这一替换,尝试了一下:re.compile(r"[\cA-\c... -
python tip: 删除非空目录 - [python]
2008-02-05
def RemoveNonNullDirectory (top):
"""
Remove non-null directory
"""
while 1:
... -
python switch - [python]
2008-01-08
# This class provides the functionality we want. You only need to look at
# this if you want to know how this works. It only needs to be defined
# once, no need to muck around with its internals.
class switch(object):
def __init... -
Python Tips : 判断两个文件是否相同 - [python]
2008-01-07
python中提供了很便捷的方法来判断两个文件的内容是否相同,只要两行代码:
import filecmp
filecmp.cmp(r'e:\1.txt',r'e:\2.txt')
如果两个文件相同,会输出True,否则会输出false。 -
Unicode strings to ASCII in python - [python]
2007-12-28
This has been a problem for a long time for me. Whenever someone enters a title in my CMS the id of the document is derived from the title. Spaces are replaced with '- and &' is replaced with and etc. The final thing I wanted to do was to make s... -
python fp函数 - [python]
2007-12-19
出于适当的需要,有几种通常在功能性语言和Lisp中出现的功能加入到了Python。通过lambda关键字,可以创建很小的匿名函数。这里有一个函数返回它的两个参数的和:“lambda a, b: a+b”。 Lambda 形式可以用于任何需要的函数对象。出于语法限制,它们只能有一个单独的表达式。语义上讲,它们只是普通函数定义中的一个语法技巧。类似于嵌套函数定义,lambda形式可以从包含范围内引用变量:
语法: lambda argument1, ar... -
Python函数参数中的*,** - [python]
2007-12-19
问题:
Python的函数定义中有两种特殊的情况,即出现*,**的形式。
如:def myfun1(username, *keys)或def myfun2(username, **keys)等。
解释:
* 用来传递任意个无名字参数,这些参数会一个Tuple的形式访问。
**用来处理传递任... -
3.9 File Objects - [python]
2007-12-18
3.9 File Objects File objects are implemented using C's stdio package and can be created with the built-in constructor file() described in section 2.1, ``Built-in Functions.''3.6 File objects are also returned by some other bu... -
python 正则表达式 tips - [python]
2007-12-18
###########################################################
特殊字符:
###########################################################
"." 匹配除 "\n" 之外的任何单个字符。要匹配包括 '\n' 在内的任何字符,请使用象 '[.\n]' 的模式。
"^"... -
3.6.1 String Method - [python]
2007-12-18
3.6.1 String Methods These are the string methods which both 8-bit strings and Unicode objects support:
8 -bit字符串和unicode对象支持这些字符串方法
capitalize( ) Return a copy of the string with only its fi... -
4.1.1 String constants - [python]
2007-12-18
原文:http://docs.python.org/lib/node39.html
4.1.1 String constants
The constants defined in this module are:
该模块包含这些常量:
ascii_letters The concatenation of the ascii_lowerc... -
python 得到shell命令的结果 - [python]
2007-12-12
import os
str = os.popen("dir").read()
a = str.split("\n")
for b in a:
print b -
怎样在python中判断一个文件是否存在 - [python]
2007-12-12
import os
path = 'c:\windows'
e = os.path.exists(path)
print e # True
那如果是要判断文件而不是目录呢?
os.p... -
Python如何操控内存buffer? - [python]
2007-12-09
和C字符串不同,Python字符串不能改写。按字符串索引赋值会产生错误。
>>> word[0] = 'x'
Traceback (most recent call last):
File "", line 1, in ?
TypeError: object doesn't support item assignment
>>> word[:1]...
共1页 1








