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 is
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. In fact, with true
multiple dispatch VP
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
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
like a
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), (30,
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
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:
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 of
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.
That assumes that all({}) is defined as true. That is a common
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
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 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(%s)' %
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,
Muhammad Alkarouri schrieb:
Traceback (most recent call last):
File pyshell#83, line 1, in module
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
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
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
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 kind of
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've
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 something, doesn't mean it has value
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
Paul Rubin schrieb:
Ethan Furman et...@stoneleaf.us 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.
--
Ben Finney schrieb:
Mick Krippendorf mad.m...@gmx.de 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
here abnormal
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
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,
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.
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
lead to
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
...
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)
[...] I might take
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
object that inherits
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 use
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, grasshopper)
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 return
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 types always compare
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:
... return
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
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
38 matches
Mail list logo