number of arguments Error

I am executing a command in a thread for almost 25k times like if threaded is True: thread = Thread(target=threadedCommand, args=(cmd)) thread.start() thread.join() def threadedCommand(command): if command is None: print 'can't execute threaded command' sys.exit(-1) print 'executing - %s'%(command) os.system(command)

参数个数错误

我在一个线程中执行了近25k次的命令 if threaded is True: thread = Thread(target=threadedCommand, args=(cmd)) thread.start() thread.join() def threadedCommand(command): if command is None: print 'can't execute threaded command' sys.exit(-1) print 'executing - %s'%(command) os.system(command) 和命令是一样的 cp file di

Python hash() can't handle long integer?

I defined a class: class A: ''' hash test class >>> a = A(9, 1196833379, 1, 1773396906) >>> hash(a) -340004569 This is weird, 12544897317L expected. ''' def __init__(self, a, b, c, d): self.a = a self.b = b self.c = c self.d = d def __hash__(self): return self.a * self.b + self.c * self.d Why, in the doctest, hash() func

Python hash()不能处理长整数?

我定义了一个类: class A: ''' hash test class >>> a = A(9, 1196833379, 1, 1773396906) >>> hash(a) -340004569 This is weird, 12544897317L expected. ''' def __init__(self, a, b, c, d): self.a = a self.b = b self.c = c self.d = d def __hash__(self): return self.a * self.b + self.c * self.d 为什么在doctest中,hash()函数给

emacs python code completion

Possible Duplicate: Emacs - tab-completion of local Python variables Ok I am getting very confused about this. What I want is code completion for: The current file (even all open buffers) Any module that is imported in the current file Standard libraries (yes I have been spoiled by intelli-sense) What do I need to achieve this? I'm just really confused as there seem to be co

emacs python代码完成

可能重复: Emacs - 本地Python变量的Tab完成 好吧,我对此感到非常困惑。 我想要的是代码完成: 当前文件(甚至是所有打开的缓冲区) 任何在当前文件中导入的模块 标准库 (是的,我被智力感觉宠坏了) 我需要做什么来实现这一目标? 我真的很困惑,因为似乎有无数的代码完成插件,只是不知道我需要/想要哪些。 请不要建议其他编辑/ ide。 我知道很多人开箱即用,但我真的很喜欢emacs。 提前致谢。

python class that acts as mapping for **unpacking

Without subclassing dict, what would a class need to be considered a mapping so that it can be passed to a method with ** from abc import ABCMeta class uobj: __metaclass__ = ABCMeta uobj.register(dict) def f(**k): return k o = uobj() f(**o) # outputs: f() argument after ** must be a mapping, not uobj At least to the point where it throws errors of missing functionality of mapping, so I

作为**解包映射的python类

没有子类化词典,一个类需要被认为是一个映射,以便它可以传递给一个方法** from abc import ABCMeta class uobj: __metaclass__ = ABCMeta uobj.register(dict) def f(**k): return k o = uobj() f(**o) # outputs: f() argument after ** must be a mapping, not uobj 至少它会抛出映射功能缺失的错误,所以我可以开始实施。 我回顾了模拟容器类型,但简单地定义魔术方法没有效果,并且使用ABCMeta来覆盖并注册它

Tuple comparison in Python

According to this : Tuples and lists are compared lexicographically using comparison of corresponding elements. This means that to compare equal, each element must compare equal and the two sequences must be of the same type and have the same length. If not equal, the sequences are ordered the same as their first differing elements. For example, cmp([1,2,x], [1,2,y]) returns the same as cmp

Python中的元组比较

根据这个 : 元组和列表按照字典顺序使用相应元素的比较进行比较。 这意味着为了比较相等,每个元素必须相等并且两个序列必须是相同类型并且具有相同长度。 如果不相等,序列的顺序与它们的第一个不同元素相同。 例如,cmp([1,2,x],[1,2,y])与cmp(x,y)的返回值相同。 如果相应的元素不存在,则首先排序较短的序列(例如,[1,2] <[1,2,3])。 如果我理解正确 (a, b, c) < (d, e, f) 给如果 a < d and

Comparing all elements of two tuples (with all() functionality)

So i know that comparisons on tuples work lexicographically: Tuples and lists are compared lexicographically using comparison of corresponding elements. This means that to compare equal, each element must compare equal and the two sequences must be of the same type and have the same length. If not equal, the sequences are ordered the same as their first differing elements. For example, cmp(

比较两个元组的所有元素(具有all()功能)

所以我知道元组的比较按字典顺序工作: 元组和列表按照字典顺序使用相应元素的比较进行比较。 这意味着为了比较相等,每个元素必须相等并且两个序列必须是相同类型并且具有相同长度。 如果不相等,序列的顺序与它们的第一个不同元素相同。 例如,cmp([1,2,x],[1,2,y])与cmp(x,y)的返回值相同。 如果相应的元素不存在,则首先排序较短的序列(例如,[1,2] <[1,2,3])。 所以从这个: >>> a = (100,

Possible to return two lists from a list comprehension?

Is it possible to return two lists from a list comprehension? Well, this obviously doesn't work, but something like: rr, tt = [i*10, i*12 for i in xrange(4)] So rr and tt both are lists with the results from i*10 and i*12 respectively. Many thanks >>> rr,tt = zip(*[(i*10, i*12) for i in xrange(4)]) >>> rr (0, 10, 20, 30) >>> tt (0, 12, 24, 36) It is possible f

可以从列表理解返回两个列表?

是否有可能从列表理解返回两个列表? 那么,这显然不起作用,但像这样: rr, tt = [i*10, i*12 for i in xrange(4)] 所以rr和tt都是分别来自i*10和i*12的结果的列表。 非常感谢 >>> rr,tt = zip(*[(i*10, i*12) for i in xrange(4)]) >>> rr (0, 10, 20, 30) >>> tt (0, 12, 24, 36) 如果元素是列表,则列表理解可能返回多个列表。 例如: >>> x, y = [[] for x in range(2)] >&g

Why does x,y = zip(*zip(a,b)) work in Python?

OK I love Python's zip() function. Use it all the time, it's brilliant. Every now and again I want to do the opposite of zip() , think "I used to know how to do that", then google python unzip, then remember that one uses this magical * to unzip a zipped list of tuples. Like this: x = [1,2,3] y = [4,5,6] zipped = zip(x,y) unzipped_x, unzipped_y = zip(*zipped) unzipped_x

为什么x,y = zip(* zip(a,b))在Python中起作用?

好的,我喜欢Python的zip()函数。 一直使用它,它很棒。 我现在想再做一次与zip()相反的操作,认为“我曾经知道如何做到这一点”,然后google python解压缩,然后记住用这个神奇的*来解压缩一个压缩的元组列表。 喜欢这个: x = [1,2,3] y = [4,5,6] zipped = zip(x,y) unzipped_x, unzipped_y = zip(*zipped) unzipped_x Out[30]: (1, 2, 3) unzipped_y Out[31]: (4, 5, 6) 究竟是怎么回事? 这个神奇的星号在做什

Can I use a class instead of a function with map in Python?

According to the doc, the map function "applies function to every item of iterable and returns a list of the results". I've noticed that it also works for classes, eg map(MyClass, get_iterable()) and returns a list of the class instances. Is this correct usage of map ? The docs actually say “Apply function to every item of iterable” where function is a reference to the paramete

我可以在Python中使用类来代替函数吗?

根据文档, map函数“将函数应用于每个可迭代项并返回结果列表”。 我注意到它也适用于类,例如map(MyClass, get_iterable())并返回类实例列表。 这是正确的使用map ? 该文档实际上说“将函数应用于每个可迭代项”,其中函数是对参数名称的引用。 所以是的, map可以用于任何可调用的; 并且所有类型都是可调用的(因为它们将创建该类型的对象)。 map期望可调用。 如果一个对象是可调用的,那也可以工作: class Foo(obje

Getting a map() to return a list in Python 3.x

I'm trying to map a list into hex, and then use the list elsewhere. In python 2.6, this was easy: A: Python 2.6: >>> map(chr, [66, 53, 0, 94]) ['B', '5', 'x00', '^'] However, on Python 3.1, the above returns a map object. B: Python 3.1: >>> map(chr, [66, 53, 0, 94]) <map object at 0x00AF5570> How do I retrieve the mapped list (as in A above) on Python 3.x? A

获取map()以在Python 3.x中返回一个列表

我试图将一个列表映射到十六进制,然后在别处使用列表。 在Python 2.6中,这很简单: 答: Python 2.6: >>> map(chr, [66, 53, 0, 94]) ['B', '5', 'x00', '^'] 但是,在Python 3.1上,上面返回一个地图对象。 B: Python 3.1: >>> map(chr, [66, 53, 0, 94]) <map object at 0x00AF5570> 如何检索Python 3.x中的映射列表(如上面的A所示)? 或者,有没有更好的方法来做到这一点? 我的