lobals (i.e. dictionary with
names as keys and objects as values), use:
mod = sys.modules[MyClass.__module__] # (as above)
vars(mod) # or mod.__dict__, though vars(mod) seems to me more elegant
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
31-12-2009 Rodrick Brown wrote:
I started dabbling with threads in python and for some odd reason the
performance seems extremely poor on my 2 core system.
It this a simplified version spawn 2 threads write some data to a file
and time the results vs doing the same sequentially.
Why is the p
01-01-2010 o 02:30:20 W. eWatson wrote:
About a year ago, I wrote a program that used mod() for modulo under
2.5. Apparently, % is also acceptable, but the program works quite well.
I turned the program over to someone who is using 2.4, and apparently
2.4 knows nothing about mod(). Out of
However the following is not an error
for x in []:
assert type(x) == type(())
Trying to iterate over an empty sequence or iterator causes
0 (zero) steps of iteration -- so above assert statement is
never run.
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo
'{0}_with_{1}_juice'.format(booze, juice),
Bottle(booze, juice))
for booze, juice in product(liquors, juices))
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
see:
http://docs.python.org/library/simplehttpserver.html
http://docs.python.org/library/cgihttpserver.html
http://docs.python.org/library/basehttpserver.html
-- as well as:
http://docs.python.org/library/urllib.html
http://docs.python.org/library/urllib2.html
Cheers,
*j
--
Jan Kaliszewski (zuo
Rajat wrote:
I've single CPU machine. I've a feeling that the thread created, which
would run script2, would eat up all of the CPU if I do not use sleep()
in script2.
That way, script1 would still be waiting for script2 to finish.
Single CPU is not a problem for threads (in fact it's even
Valentin de Pablo Fouce wrote:
On 6 ene, 22:42, "Jan Kaliszewski" wrote:
Valentin de Pablo Fouce wrote:
> Ok, I am trying to do a very quick application (is "home based" so is
> not a big deal...). My intention is to transfer files from one
> computer to ano
, 2, 3), (4, 5, None)]
>>> list(itertools.izip_longest(*[iter(s)]*2))
[(1, 2), (3, 4), (5, None)]
See:
http://docs.python.org/library/functions.html#zip
http://docs.python.org/library/functions.html#map
http://docs.python.org/library/itertools.html#itertools.izip_longest
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
PS. Sorry, I wrote:
>>> zip(*[iter(s)]*3) # or simpler: zip(s) :-)
But should be
>>> zip(*[iter(s)]*1) # or simpler: zip(s) :-)
*j
--
http://mail.python.org/mailman/listinfo/python-list
Hello,
I have a question: are class decorator planned to be backported from 3.x?
All the best,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
09-01-2010 o 22:34:28 Jack Diederich wrote:
On Sat, Jan 9, 2010 at 2:53 PM, Jan Kaliszewski
I have a question: are class decorator planned to be backported from
3.x?
Eh? Class decorators have been in the 2.x series since 2.6.
Oops, I overlooked the fact :) Thank you!
*j
--
Jan
.. And I'm curious about your
opinions.
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
code.activestate.com/recipes/576998/).
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
Dnia 21-01-2010 o 08:49:22 Chris Rebert napisał(a):
On Wed, Jan 20, 2010 at 5:50 PM, Steven D'Aprano
wrote:
On Thu, 21 Jan 2010 02:02:02 +0100, Jan Kaliszewski wrote:
http://code.activestate.com/recipes/576998/
What's the advantage of that over sorting the keys as needed?
Dnia 21-01-2010 o 09:27:52 Raymond Hettinger napisał(a):
On Jan 20, 5:02 pm, "Jan Kaliszewski" wrote:
http://code.activestate.com/recipes/576998/
Using an underlying list to track sorted items
means that insertion and deletion take O(n) time.
That could be reduced to O(log
solves (in Pythonic, explicit way) the main
problem: "you could pass invalid strings easily". Typing a two characters
more ('') isn't a big effort.
Please also note that you can apply not only str-based symbols but any
hashable objects (obviously it could be event imp
s/sollution/solution
s/event implemented/even implemented
Sorry
*j
--
http://mail.python.org/mailman/listinfo/python-list
you can search as well as insert with
its functions. But IMHO you shouldn't search for the next starting
*letter*, but for the next *name* in the list (basing on name that was
used recently).
If the list were immutable, no searching would be needed (indexes would
be sufficient), but in real life users can be added and deleted in the
meantime (so index of a particular name changes).
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
, say, the
following code?
def consume(iterator, n):
for _ in islice(iterator, n): pass
Probably the former is faster. But I haven't check it. If you are curious,
use timeit module...
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
PS.
22-01-2010 o 15:44:28 Jan Kaliszewski wrote:
22-01-2010, 14:58:58 Gilles Ganault wrote:
On 22 Jan 2010 13:35:26 GMT, Neil Cerutti wrote:
Resorting is more work than is needed. Just choose a different
starting index each time you display the names, and set up your
lister to wrap
23-01-2010 o 15:49:23 Diez B. Roggisch wrote:
Am 23.01.10 15:44, schrieb Roald de Vries:
Dear all,
I sometimes want to use an infinite while loop with access to the loop
index, like this:
def naturals():
i = 0
while True:
yield i
y += 1
for i in naturals():
print(i)
I assume a function lik
58784389496
100: 1.5890610218
1000: 1.58557391167
None: 2.37005710602
consume3
10: 1.6071870327
100: 1.61109304428
1000: 1.60717701912
None: 1.81885385513
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
urious as to the
attributes of the dict_keys class. but i don't know how to look at
that without first *creating* such an instance, then asking for
"dir(dk)".
Why you bother about creating an instance? Just do it:
list(vars(type({}.keys(
or dir(type({}.keys()))
if dir() sa
24-01-2010, 16:56:42 Jan Kaliszewski wrote:
24-01-2010, 16:28:26 Robert P. J. Day wrote
once again, probably a trivial question but i googled and didn't
get an obvious solution. how to list the attributes of a *class*?
dir(type(an_obj))
or more reliable:
list(vars
486
1000: 12.5794699192
None: 28.5096430779
consume3
10: 2.39173388481
100: 3.43043398857
1000: 14.3361399174
None: 14.8560190201
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
24-01-2010, 17:37:41 Alf P. Steinbach wrote:
DictKeys = type( {}.keys() )
dir( DictKeys )
list( vars( DictKeys ) )
help( DictKeys )
It doesn't help much though because the only method of interrest is
__iter__
Not only. Please, consider:
>>> dictkeys = type({}.keys())
145&r2=70296&pathrev=70296
Nice. :)
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
doesn't work for instances of types with
__slots__ defined (see:
http://docs.python.org/reference/datamodel.html#slots).
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
Terry Reedy dixit (2010-05-12, 14:26):
> On 5/12/2010 1:26 PM, Giampaolo Rodolà wrote:
> >2010/5/12 Gabriel Genellina:
> >>open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
> >>builtin open() + os.fdopen() from 2.x all merged together. It does different
> >>things dependi
Hello Friends,
It's my first post to python-list, so first let me introduce myself...
* my name is Jan Kaliszewski,
* country -- Poland,
* occupation -- composer (studied in F. Chopin Academy of Music @Warsaw)
and programmer (currently in Record System co
27-07-2009 o 22:35:01 David <71da...@libero.it> wrote:
I am writing a command line application, and I need to perform some
cleaning
on exit even if the process is killed.
How can I do that with python?
See: http://docs.python.org/library/signal.html
Cheers,
*j
--
Jan Kaliszewsk
combine these two techniques (i.e. signal handlers call sys.exit(),
then sys.exitfunc/or function registered with atexit does the actual
cleaning actions).
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
else, can you please give me some guidance?
What operating system do you use?
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
s.html#reserved-classes-of-identifiers
* http://docs.python.org/reference/datamodel.html#object.__del__
(in the the red "Warning" frame)
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
results = []
for name in filenames:
results.append(some_function(name))
If filenames were generated according to a particular pattern, you can
mimic that pattern and generate filenames list using
list-comprehension, e.g.:
filenames = ['file{nr}.txt'.format(nr=nr) for nr in rang
Me wrote:
filenames = p'foo', 'bar', baz']
Sorry, should be of course:
filenames = ['foo', 'bar', baz']
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
is the problem?
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
#x27;) # to bytes
b'What makes you think she is a witch?'
>>> b'What makes you think she is a witch?'.decode() # to str
'What makes you think she is a witch?'
>>> b'What makes you think she is a witch?'.decode('utf-8') # to str
'What makes you think she is a witch?'
>>> str(b'What makes you think she is a witch?', 'utf-8') # to str
'What makes you think she is a witch?'
>>> str(b'What makes you think she is a witch?') # but not this way
"b'What makes you think she is a witch?'"
[^ note this]
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
wer readability
imo).
I don't see any real limitation. What's wrong in:
for localVar in container:
block
And ruby's container.each is very similar to Python's iter()
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
Dnia 30-07-2009 o 22:41:57 Masklinn napisał(a):
On 30 Jul 2009, at 22:23 , Jan Kaliszewski wrote:
30-07-2009 o 13:36:49 Masklinn wrote:
On 30 Jul 2009, at 06:04 , alex23 wrote:
On Jul 30, 1:06 pm, r wrote:
2.) the .each method
container.each{|localVar| block}
This method can really
== 'xterm'...
colors = color_codes.COLORS[used_term]
print('Some text, {colors.blue}Something in blue, '
'{colors.red}And now in red.').format(colors=colors)
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
level, and serial. All values except
releaselevel are integers; the release level is 'alpha', 'beta',
'candidate', or 'final'. The version_info value corresponding to
the Python version 2.0 is (2, 0, 0, 'final', 0)."
http://docs.python.org/librar
here.
The last is ok: None != 0.
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
int >>nucleotides, '> foo bar length=76'
print >>nucleotides, seq[-76]
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
sta:
print >>nucleotides, '> foo bar length=76'
print >>nucleotides, seq[-76]
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
ing quite long string')
% (variable1, variable2, variable3))
(Note that multiline-'''-strings are usless in such cases).
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
27;
special character) and not '\\r' (which would mean '\' char + 'r' char).
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
09-08-2009 r wrote:
On Aug 8, 12:43 pm, "Jan Kaliszewski" wrote:
08-08-2009 Steven D'Aprano wrote:
...(snip)
I use it very often, e.g.:
afunction('quite long string %s quite long string '
'quite long string quite long string %s
09-08-2009 o 23:43:14 r wrote:
#-- el bueno --#
"hello i am a very long string that\
does not like newlines so please \
escape me, Thank you!"
You probably ment: """hello i am... [etc.]
Anyway... You're right that generally it's good idea to define
dialog prompts and such stuff separately ra
stance(foo, YourType)".
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
enough arguments for format string
I want to format the string. the list has five elements and the string
has five placeholder but it wont format the string
j must be a tuple -- so either define it as
(u'Tata', u'Oriovac', u'PrimorskoGoranska', u'hrvat
you can use also a list):
h = """SELECT distinct u.id_ulica, o.id_opcina, z.id_zupanija, \
... d.id_drzava, v.id_valuta FROM ulica as u, opcina as o, zupanija as \
... z, drzava as d, valuta as v WHERE u.naziv = '{0}' AND o.naziv = \
... '{1}' AND z.naziv = '{2}' AND d.naziv = '{3}' AND v.naziv = '{4}'\
... """.format(*j)
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
ep=','):
"back_separate('12345678') -> '12,345,678'"
beg = len(text) % grouplen
repeated_iterator = [iter(itertools.islice(text, beg, None))] *
grouplen
strings = itertools.imap(lambda *chars: ''.join(chars),
*repeated_iterator)
return s
15-08-2009 Jan Kaliszewski wrote:
15-08-2009 candide wrote:
Suppose you need to split a string into substrings of a given size
(except
possibly the last substring). I make the hypothesis the first slice is
at the end of the string.
A typical example is provided by formatting a decimal
r short strings (for sure most common case) it's ok: simple and clear.
But for huge ones, it's better not to materialize additional list for the
string -- then pure-iterator-sollutions would be better (like Gabriel's or
mine).
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
7; after more
# than len(Polynome)
# of arguments
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
lse None)
I'd use conditional expression only (rather) in situation when the first
expression-part was 'common' and the other (after else) was 'rare'.
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
__(self, key):
try:
return dict.__getitem__(self, key)
except KeyError:
return self.parent[key]
Did you do it in similar way? (just curiosity) :-)
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
that some other
solution would be better (e.g. inheritance).
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
ed in it).
You can try using sys.stdout.write() instead.
I want to avoid using a def if possible.
But what for? Usualy def is more readable than lambda and it's not worth
to lose readibility just to save a few keystrokes.
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
antically (unless you add a comma -- then you create a tuple, even
without parentheses, but it'a another story...).
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
'foobar'
Because, as I understand Pavel's intent, it has to work dynamically
(e.g. changes in 'a' reflect in behaviour of 'b'), and obviously not
only for such trivial examples like above.
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
equire it (see: http://docs.python.org/3.1/whatsnew/3.0.html ).
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
ors (because of GIL,
see: http://docs.python.org/glossary.html#term-global-interpreter-lock).
'multiprocessing' module is what you need:
http://docs.python.org/library/multiprocessing.html
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
e correct way (and even recommended over s=s+t or s+=t, when
applicable
-- see:
http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange).
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
considered as the 'enclosing' scope.
The only ways to reach Abc's attribute 'message' from that method are:
* 'Abc.message'
* 'self.__class__.message'
* 'self.message' (unless there is an instance attribute 'message' which
overrides the class attribute).
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
19-08-2009 o 02:10:58 Jan Kaliszewski wrote:
The only ways to reach Abc's attribute 'message' from that method are:
* 'Abc.message'
* 'self.__class__.message'
* 'self.message' (unless there is an instance attribute 'message' which
over
o
print ', '.join(arrPlaces)
Output:
C:\moo, C:\supermoo
print ', '.join("'%s'" % item for item in arrPlaces)
Output:
'C:\moo', 'C:\supermoo'
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
19-08-2009 o 10:56:20 <""Michel Claveau -
MVP"> wrote:
(envoyé via news:\\news.wanadoo.fr\comp.lang.python)
Hi!
See the module "sets"
No, see the builtin set type. Module sets is deprecated (removed in Py 3.x)
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
ong lists, when memory becomes expensive):
dict(li[i:i+2] for i in xrange(0, len(li), 2))
Or probably better:
from itertools import islice, izip
dict(izip(islice(li, 0, None, 2), islice(li, 1, None, 2)))
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
) in B...
Hm, maybe something like this:
# result as a dict {: , ...}
dict((element, B.count(element)) for element in A)
If you mean: to count non overlaping occurences of string A in B
-- simply:
B.count(A)
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman
20-08-2009 o 02:05:57 Jan Kaliszewski wrote:
Or probably better:
from itertools import islice, izip
dict(izip(islice(li, 0, None, 2), islice(li, 1, None, 2)))
Or similarly, perhaps more readable:
iterator = iter(li)
dict((iterator.next(), iterator.next()) for i in xrange
)
# prints defaultdict(, {' ': 1, 'e': 1, 'g': 1, 'i': 1,
'o': 1, 'n': 2, 's': 1, 'r': 2, 't': 2})
Yeah, your sollution is better (and more interesting :-)). Thanks!
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
Otten <__pete...@web.de> wrote:
identity = "".join(map(chr, range(256)))
n = len(b) - len(b.translate(identity, a))
Nice, though I'd prefer Simon's sollution:
a = set(a)
n = sum(item in a for item in b)
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.pyt
a = set(a)
n = sum(item in a for item in b)
Why set? Does it matter if I say that items in A are already unique?
Sets are hash-based, so it's (most probably) far more efficient for
sets than for sequences (especially if we say about big/long ones).
Regards,
*j
--
Jan Kalisz
21-08-2009 o 18:09:02 alex23 wrote:
Unfortunately, apply() has been removed as a built-in in 3.x.
You can always implement it yourself :)
def apply(function, args=(), keywords={}):
return function(*args, **keywords)
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman
also inconsistent with *Python* conventions, i.e.:
0x <- hex prefix
0b <- bin prefix
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
22-08-2009 o 20:11:32 bolega wrote:
sed/awk/perl:
How to replace all spaces each with an underscore that occur before a
specific string ?
$ rm -rf /home/bolega ; python -c 'for i in xrange(1000): print "I will
never crosspost senselessly."'
;~]
--
Jan Kalisz
-- they are commonly referred to as 'variables',
regarding other languages' terminology).
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
elf._validate(player=player)
self._recruit(player)
list.append(self, player)
# and similarly:
# * def extend...
# * def insert...
# * def pop...
# * def remove...
...if you really need ordered container (reflecting functions/hierarchy
of players in a team?).
Otherwise, as Stephen noted, you should subclass set rather than list.
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
a[key])
for data in playerdata:
self.append(Player(data))
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
nary
function, not a method. It become a method *when it's called as a method*
(what is possible *after* creating the class => outside the definition).
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
25-08-2009 o 22:51:14 Gleb Belov wrote:
I have two questions:
1) Is it possible and if so, how do I access each individual element?
Are there any indexes and what is the syntax?
It's a 'Read-The-Friendly-Manual' question.
(hint: library reference - Built-in Types - ...)
--
d
loosely) so that it too now fails with characters outside
the BMP.
[snip]
Does not this effectively make unichr() and ord() useless
on Windows for all but a subset of unicode characters?
Are you sure, you couldn't have UCS-4-compiled Python distro
for Windows?? :-O
*j
--
Jan Kaliszewsk
ch "recursive" references in Python).
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
permutations of two lists given and
select any combination and use zip to get the tuples. Repeat this for
all possible combinations.
Any other ideas?
See: module itertools -- there are (OOTB) some combinatoric generators
that may be useful for you.
*j
--
Jan Kaliszewski (zuo)
--
http
def fact(fact, n):
if n < 2:
return 1
else:
return n * fact(fact, n - 1)
fact(fact, 3)
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
return cls
32
33 return cls_wrapper
34
35
36 @verbose_cls(dict)
37 class VerboseDict(dict):
38 pass
39
40
41 @verbose_cls(int)
42 class MyInt(int):
43
44 @verbose_func
45 def __iadd__(self, other):
46 int.__add__(self, other) # can do something more
44 @verbose_func
45 def __iadd__(self, other):
46 int.__add__(self, other) # can do something more interesting
47
48
49 if __name__ == '__main__':
50 d = VerboseDict()
51
52 print("d['a'] = 3")
53 d['a'] = MyInt(3)
54
55 print("d['a'] += 3")
56 d['a'] += MyInt(3)
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
14:17:15 Steven D'Aprano wrote:
The class is a scope, and inside the class scope, you can access local
names. What you can't do is access the class scope from inside nested
functions.
s/from inside nested functions/from inside nested scopes
Besides that detail, I fully agree.
"'shallow' or 'deepcopy'")
...but in such cases as copying existing objects it is usualy better
(though less romantic :-)) to use an ordinary function (e.g. simply
copy.copy() or copy.deepcopy(), as Gabriel has pointed).
Regards,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
PS. Sorry for sending 2 posts -- the latter is the correct one.
Cheers,
*j
--
http://mail.python.org/mailman/listinfo/python-list
nification would mean terrible impoverishment
of our (humans') culture and, as a result, terrible squandering of our
intelectual, emotional, cognitive etc. potential -- especially if such
unification were a result of intentional policy (and not of a slow and
'patient' process of synth
em__, names), hours))',
... )
for t in tests:
... print t
... timeit.repeat(t, setup, number=1000)
... print
...
sum(v * r[k] for k,v in m)
[6.2493009567260742, 6.1892399787902832, 6.2634339332580566]
sum(starmap(mul, ((r[name], hour) for name, hour in m)))
[9.3293819427490234, 10.280816
31-08-2009 o 22:28:56 Jan Kaliszewski wrote:
>>> setup = "from itertools import starmap, imap ; from operator
import mul; import random, string; names = [rndom.choice(string.
ascii_letters) for x in xrange(1)]; hours = [random.randint(
1, 12) for x in xrange(1000)]; m = zi
st, itertools.repeat('booHoo')))
Cheers,
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
;> # Using map.
>>> x[slice(*map(int, s.strip("[]").split(":")))]
[3]
>>> # Using a list comprehension.
>>> x[slice(*[int(i) for i in s.strip("[]").split(":")])]
[3]
Of course, you could also do something like this:
ev
Erratum:
eval(str(x) + s)
-- but it's worse: less secure (e.g. if s could be user-typed) and most
probably much more time-consuming (especially the latter).
There should be *repr* instead of *str*.
*j
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/listinfo/python-list
p("[]").split(":")])]
Traceback (most recent call last):
File "", line 1, in
ValueError: invalid literal for int() with base 10: ''
Similar problem with [2:].
Ideas?
x = [1,4,3,5,4,6,5,7]
s = '[3:6]'
x[slice(*((int(i) if i els
1 - 100 of 109 matches
Mail list logo