python
iteye_15479
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python中list类型相减
两个list()类型相减就是比如a=[1,2,3,4,5]b=[2,3,4]a-b需要得到[1,5]但是python list不支持减法只能使用py的投机取巧了~ 呵呵我们来用set()如下<code l=python>print list(set(a)-set(b))[1,5] #结果...原创 2009-10-16 09:00:58 · 2704 阅读 · 0 评论 -
Twisted中的DeferredList
在这个blog上学习twisted。[url]http://blog.163.com/gzjck_gshock/blog/static/77206203201291461538770/[/url]里面的一个关于DeferredList的例子一开始对语法不太理解,copy并run了一遍就理解了,把代码贴在这里留作以后借鉴。connecttest.py:[code="p...原创 2013-02-21 17:08:39 · 356 阅读 · 0 评论 -
lost on Py_DECREF/INCREF when handling PyList_Append in Python C extension
The main hint is in the docs, if it says 'Steals a reference' than the function basically takes ownership, if it says 'New Reference' than it did an INCREF for you, if nothing is said it probably does...原创 2015-11-03 21:41:16 · 331 阅读 · 0 评论 -
How can I convert a character to a integer in Python, and viceversa?
Use chr() and ord():>>> chr(97)'a'>>> ord('a')97原创 2015-10-27 14:38:04 · 300 阅读 · 0 评论 -
python中的import
什么时候你应该使用 from module import? 如果你要经常访问模块的属性和方法,且不想一遍又一遍地敲入模块名,使用 from module import。 如果你想要有选择地导入某些属性和方法,而不想要其它的,使用 from module import。 如果模块包含的属性和方法与你的某个模块同名,你必须使用 import module 来避免名字冲突。 ...原创 2009-10-12 17:00:06 · 106 阅读 · 0 评论 -
python中的and-or技巧
>>> a = "first">>> b = "second">>> 1 and a or b 'first'>>> 0 and a or b 'second' 这个语法看起来类似于 C 语言中的 bool ? a : b 表达式。整个表达式从左到右进行演算,所以先进行原创 2009-09-29 09:27:02 · 193 阅读 · 0 评论 -
python中使用可选参数和命名参数
Python 允许函数参数有缺省值;如果调用函数时不使用参数,参数将获得它的缺省值。此外,通过使用命名参数还可以以任意顺序指定参数。SQL Server Transact/SQL 中的存储过程也可以做到这些;如果你是脚本高手,你可以略过这部分。 info 函数就是这样一个例子,它有两个可选参数。 def info(object, spacing=10, collapse=1...原创 2009-09-28 11:35:35 · 1062 阅读 · 0 评论 -
python中的连续赋值
连续值赋值>>> range(7) [0, 1, 2, 3, 4, 5, 6]>>> (MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = r...原创 2009-09-28 10:10:25 · 850 阅读 · 0 评论 -
python中的boolean
在 2.2.1 版本之前,Python 没有单独的布尔数据类型。为了弥补这个缺陷,Python 在布尔环境 (如 if 语句) 中几乎接受所有东西,遵循下面的规则:0 为 false; 其它所有数值皆为 true。 空串 ("") 为 false; 其它所有字符串皆为 true。 空 list ([]) 为 false; 其它所有 list 皆为 true。 ...原创 2009-09-28 09:55:34 · 699 阅读 · 0 评论 -
Python 和其他编程语言数据类型的比较
摘自《Dive into Python》。静态类型语言 一种在编译期间就确定数据类型的语言。大多数静态类型语言是通过要求在使用任一变量之前声明其数据类型来保证这一点的。Java 和 C 是静态类型语言。 动态类型语言 一种在运行期间才去确定数据类型的语言,与静态类型相反。VBScript 和 Python 是动态类型的,因为它们确定一个变量的类型是在您第一次给它赋值的时候。 强...原创 2009-09-27 14:43:53 · 239 阅读 · 0 评论 -
python中删除非空目录
import shutil shutil.rmtree(dir)2009-08-25 21:08:46 · 340 阅读 · 0 评论 -
python subprocess
Module: subprocessPurpose: Spawn and communicate with additional processes.Python Version: New in 2.4An updated version of this article can be found on the main PyMOTW site.Description:The subprocess ...原创 2009-08-13 11:30:03 · 129 阅读 · 0 评论 -
python中使用随机数
随机整数:>>> import random>>> random.randint(0,99)21随机选取0到100间的偶数:>>> import random>>> random.randrange(0, 101, 2)42随机浮点数:>>> import rand原创 2009-08-05 09:35:01 · 443 阅读 · 0 评论 -
Example of Using getopt in Python
import getopt, sysdef main(): try: opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="]) except getopt.GetoptError: # print help information and exit:...2009-07-24 12:31:05 · 108 阅读 · 0 评论 -
python脚本参数处理的一个技巧
import sys width = int(sys.argv[1]) height = int(sys.argv[2]) count = int(sys.argv[3]) length = int(sys.argv[4]) base = sys.argv[5] t...2009-07-23 23:20:22 · 122 阅读 · 0 评论 -
Turn to Python from Perl: example of SSH in multi-threads
I need to execute commands on several remote servers at the same time via ssh. Writing shell script to send commands to servers with code below is quite simple but has trouble to know when all...2009-07-21 16:39:46 · 132 阅读 · 0 评论 -
Date/Time处理函数总结 [To Do]
几种我所用到的用来处理日期,时间的函数总结。[u][b]Perl[/b][/u]1. localtime[code="perl"] # 0 1 2 3 4 5 6 7 8 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);[/code]I...原创 2013-04-12 10:46:39 · 353 阅读 · 0 评论
分享