Am 19.07.2010 13:18, dhruvbird wrote:
> Hello,
> I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
> And would like to compute the cumulative sum of all the integers
> from index zero into another array. So for the array above, I should
> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
> What
Mark Lawrence wrote:
> On 17/07/2010 20:38, Mick Krippendorf wrote:
>>
>> If Java were *really* a multiple dispatch language, it wouldn't be
>> necessary to repeat the accept-code for every subclass. Instead a single
>> accept method in the base class would suffice
Hello,
Am 16.07.2010 09:52, Michele Simionato wrote:
> [os.path.walk vs os.walk]
> There is a big conceptual difference between os.path.walk and os.walk.
> The first works like a framework: you pass a function to it and
> os.path.walk is in charging of calling it when needed. The second works
> li
Karsten Wutzke wrote:
> The visitor pattern uses single-dispatch, that is, it determines
> which method to call be the type of object passed in.
Say, in Python, I have an object o and want to call one of it's methods,
say m. Then which of possibly many methods m to call is determined by
the type
Ralax wrote:
> On Nov 11, 8:58 pm, Chris Rebert wrote:
>> In [2]: def foo(z, a=[]):
>>...: a.append(z)
>>...: return a
>>...:
>>
>> In [3]: foo(1)
>> Out[3]: [1]
>>
>> In [4]: foo(2)
>> Out[4]: [1, 2]
>>
>> In [5]: foo(2)
>> Out[5]: [1, 2, 2]
>>
>> In [6]: foo(3)
>> Out[6]: [1,
Wells wrote:
> I'm not quite understanding why a tuple is hashable but a list is not.
The short answer has already been given. Here is the long answer:
For objects p and q, p==q implies hash(p)==hash(q). It is essential for
dicts and sets that objects used as keys/elements uphold this law, and
al
Thomas wrote:
> Just a curiosity, why does Python do this?
>
[(base, int('1e7', base=base)) for base in range(15,37)]
> [(15, 442), (16, 487), (17, 534), (18, 583), (19, 634), (20, 687),
> (21, 742), (22, 799), (23, 858), (24, 919), (25, 982), (26, 1047),
> (27, 1114), (28, 1183), (29, 1254),
Peng Yu wrote:
> It seems that int() does not convert '1e7'.
It seems it does, though:
>>> int('1e7', base=16)
487
Mick.
--
http://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano wrote:
> On Sun, 01 Nov 2009 21:32:15 +0100, Mick Krippendorf wrote:
>>
>> (Ax)(x is a fire-breathing animal <-> x is a real number equal to
>> sqrt(-1)).
>>
>> And since there are neither such things, it follows that s1 = s2.
>
>
Steven D'Aprano wrote:
> There are an infinite number of empty sets that differ according to their
> construction:
>
> The set of all American Presidents called Boris Nogoodnik.
> The set of all human languages with exactly one noun and one verb.
> The set of all fire-breathing mammals.
> The set
kj wrote:
> How can one check that a Python script is lexically correct?
By using pylint.
Mick.
--
http://mail.python.org/mailman/listinfo/python-list
Jess Austin wrote:
> That's nice, but it means that everyone who imports my class will have
> to import the monkeypatch of frozenset, as well. I'm not sure I want
> that. More ruby than python, ne?
I thought it was only a toy class?
Mick.
--
http://mail.python.org/mailman/listinfo/python-list
Jess Austin schrieb:
> >>> frozenset([1]) == mySet()
> False
>
> frozenset doesn't use mySet.__eq__() because mySet is not a subclass
> of frozenset as it is for set.
You could just overwrite set and frozenset:
class eqmixin(object):
def __eq__(self, other):
print "called %s.__eq__()
Aweks schrieb:
> what do you use?
Either of the following:
-> Vim + Eclim + Rope + pylint + PyDev + Eclipse + cygwin + WindowsXP
-> Vim + Linux
Mick.
--
http://mail.python.org/mailman/listinfo/python-list
Muhammad Alkarouri schrieb:
> I was having a go at a simple implementation of Maybe in Python when I
> stumbled on a case where x.__mul__(y) is defined while x*y is not.
>
> class Maybe(object):
> def __init__(self, obj):
> self.o = obj
> def __repr__(self):
> return 'Maybe
Gabriel Genellina schrieb:
> http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes
Ok. That explains a lot. And your explanation tells the rest. Thank you.
> In short, you have to define the __mul__ method on the type itself or
> any of its bases.
I found this
Gabriel Genellina schrieb:
> __special__ methods are searched in the type, not in the instance
> directly. x*y looks for type(x).__mul__ (among other things)
So I thought too, but:
class meta(type):
def __mul__(*args):
return 123
class boo(object):
__metaclass__ = meta
print boo
Muhammad Alkarouri schrieb:
> Traceback (most recent call last):
> File "", line 1, in
> x*7
> TypeError: unsupported operand type(s) for *: 'Maybe' and 'int'
>
> The farthest I can go in this is that I presume that __mul__ (as
> called by operator *) is supposed to be a bound method while
Paul Rubin wrote:
> Yet another way is to use recursion. I'll leave that as an exercise too.
This time with big numbers:
def trampoline(bouncing, *args, **kwargs):
while bouncing:
result, bouncing, args, kwargs = bouncing(*args, **kwargs)
if result:
return result
Ben Finney schrieb:
> Mick Krippendorf writes:
> The word “anormal” appears to have been made up by you.
> The negation of the word “normal” is “abnormal”, perhaps you meant
> “First Abnormal Form”?
Maybe my English (and my memory) is just not so good. I'm german, and
he
Paul Rubin schrieb:
> Ethan Furman writes:
>> If I knew what First Anormal Form was I (hope!)
>
> It appears to be a made-up term.
I read it somewhere once, I just can't find or even remember the source.
I definitely didn't make it up, though I wish I had.
Mick.
--
http://mail.python.org/mail
Ethan Furman schrieb:
> If I knew what First Anormal Form was [...]
This refers to the Normal Forms one goes through when normalizing
relational databases.
(http://en.wikipedia.org/wiki/Database_normalization#Normal_forms)
The First Anormal Form (FAN) means just lumpin' data together in a comma
s
Ethan Furman schrieb:
> Mick Krippendorf wrote:
>> BTW, the comma-separted-values-in-a-field is officially called the First
>> Anormal Form. There *has to be* some value to it since I've seen it used
>> quite a few times...
>
> Just because you've seen
Steve Holden wrote:
> Many such designs make mistakes like using multiple columns
> (or, even worse, comma-separated values) instead of many-to-many
> relationships.
BTW, the comma-separted-values-in-a-field is officially called the First
Anormal Form. There *has to be* some value to it since I'v
Austin Bingham schrieb:
> I guess we see things differently. I think it's quite natural to want
> a set of unique objects where "unique" is defined as an operation on
> some subset/conflation/etc. of the attributes of the elements.
What you seem to imply is that the hash function imposes some kin
mattia schrieb:
> Any particular difference in using for a simple collection of element ()
> over [] or vice-versa?
Just try this and you'll see:
tup = (1,2,3)
tup.append(4)
or:
tup = (1,2,3)
tup[0] = 4
HTH,
Mick.
--
http://mail.python.org/mailman/listinfo/python-list
vicky schrieb:
> Actually In my system I want to execute some piece of code at the time
> of script exit (expected or unexpected) to ensure the release of all
> the resources. I don't know how to do that :(
You maybe want to use a context manager. Look for 'with statement' and
'contextlib' in your
Carl Banks schrieb:
> Lemme guess.
>
> You tried this at the interactive prompt and concluded it worked in
> general, right?
Yes. Thank you for enlighten me.
> One of these days we're going to have a thread like this where no one
> makes this mistake. Don't know when, but one day it will happen
Hello.
Chris Withers schrieb:
> mname = model.__name__
> fname = mname+'_order'
> value = request.GET.get('order')
> if value:
> request.session[fname]=value
> else:
> value = request.session.get(
> fname,
>
VYAS ASHISH M-NTB837 schrieb:
>
> The function that I want to run is part of a class, not a standalone
> function. There are several class member variables also.
Then try:
class MyClass(object):
...
def run(self):
""" do threaded stuff here """
...
Thread(target=MyClass().r
VYAS ASHISH M-NTB837 schrieb:
> I have an object which has a run() method. But I can call it only once.
> Calling the start() again will give
>
> RuntimeError: thread already started
>
> So what is the way to do this?
>
> I thought of doing a deep copy of the object, as shallow copy will also
>
TerryP schrieb:
> Note: let Commands be a dictionary, such that { "ham" : ...,
> "spam" : ..., "eggs" : ... }.
>
> args = re.split('\s', line)
> cmd = args.pop(0)
>
> if cmd in Commands:
> Commands[cmd](args)
> else:
> raise SyntaxWarning("Syntax error in above program")
>
>
Chris Colbert schrieb:
>
> SIMULATION = False
>
> class SimController(object):
> "do sim stuff here"
>
> class RealController(object):
> " do real stuff here"
>
> class Controller(SuperKlass):
> pass
>
>
> so if SIMULATION == False I want to be able to instance a Controller
> obje
John Nagle schrieb:
> Shaun wrote:
>> I'm trying to create a dictionary with lists as the value for each
>> key.
>
>Try using a tuple, instead of a list, for each key. Tuples
> are immutable, so there's no issue about a key changing while
> being used in a dictionary.
Only if Shaun wanted to
Hi,
Shaun wrote:
> I'm trying to create a dictionary with lists as the value for each
> key. I was looking for the most elegant way of doing it...
from collections import defaultdict
d = defaultdict(list)
d["joe"].append("something")
d["joe"].append("another")
d["jim"].append("slow down, gras
Fahri Basegmez wrote:
> reduce(lambda x, y: x or y, lst)
This doesn't solve the OPs problem since
>>> reduce(lambda x, y: x or y, [False, None])
returns None instead of False.
Mick.
--
http://mail.python.org/mailman/listinfo/python-list
Daniel Bickett wrote:
>
> >>> def boolhunt( items ):
> ... falseExists = False
> ... for item in items:
> ... if item is True:
> ... return True
> ... elif item is False and not falseExists:
> ... falseExists = True
> ... if falseExists:
> ...
Fredrik Lundh wrote:
> Steven Bethard wrote:
>> Raymond Hettinger wrote:
>>>
>>> return max(lst)
>>
>> Very clever! Thanks!
>
> too clever. boolean > None isn't guaranteed by the language
> specification:
>
> http://docs.python.org/ref/comparisons.html
>
> "... objects of different
Steven Bethard wrote:
> I have lists containing values that are all either True, False or
> None, e.g.:
>
> [True, None, None, False]
> [None, False, False, None ]
> [False, True, True, True ]
> etc.
>
> For a given list:
> * If all values are None, the function should r
Joakim Storck wrote:
> [...] the hash values of classes will be used as
> keys in a dictionary that serve as an object pool. [...]
That does seem unwise (as Teal'c would have uttered). The spec says:
hash( object)
Return the hash value of the object (if it has one). Hash values are
in
40 matches
Mail list logo