Re: open(False) in python3

2010-05-12 Thread Jan Kaliszewski
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

Re: how can i know if a python object have a attribute such as 'attr1'?

2010-01-25 Thread Jan Kaliszewski
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

Re: Consume an iterable

2010-01-24 Thread Jan Kaliszewski
145&r2=70296&pathrev=70296 Nice. :) *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: how to list the attributes of a class, not an object?

2010-01-24 Thread Jan Kaliszewski
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())

Re: Consume an iterable

2010-01-24 Thread Jan Kaliszewski
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

PS.

2010-01-24 Thread Jan Kaliszewski
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

Re: how to list the attributes of a class, not an object?

2010-01-24 Thread Jan Kaliszewski
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

Re: Consume an iterable

2010-01-24 Thread Jan Kaliszewski
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

Re: enumerated while loop

2010-01-23 Thread Jan Kaliszewski
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

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jan Kaliszewski
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

Re: Consume an iterable

2010-01-22 Thread Jan Kaliszewski
, 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

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Jan Kaliszewski
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

Re: Symbols as parameters?

2010-01-22 Thread Jan Kaliszewski
s/sollution/solution s/event implemented/even implemented Sorry *j -- http://mail.python.org/mailman/listinfo/python-list

Re: Symbols as parameters?

2010-01-22 Thread Jan Kaliszewski
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

Re: Sorted dictionary

2010-01-21 Thread Jan Kaliszewski
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

Re: Sorted dictionary

2010-01-21 Thread Jan Kaliszewski
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?

Re: Sorted dictionary

2010-01-21 Thread Jan Kaliszewski
code.activestate.com/recipes/576998/). Regards, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Sorted dictionary

2010-01-20 Thread Jan Kaliszewski
.. And I'm curious about your opinions. Regards, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: [Python-Dev] [RELEASED] Python 2.7 alpha 2

2010-01-09 Thread Jan Kaliszewski
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

Re: [Python-Dev] [RELEASED] Python 2.7 alpha 2

2010-01-09 Thread Jan Kaliszewski
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

Re: Transforming a List of elements into a List of lists of elements

2010-01-08 Thread Jan Kaliszewski
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

Re: Transforming a List of elements into a List of lists of elements

2010-01-08 Thread Jan Kaliszewski
, 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

Re: File transfer with python

2010-01-07 Thread Jan Kaliszewski
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

Re: How to execute a script from another script and other script does notdo busy wait.

2010-01-07 Thread Jan Kaliszewski
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

Re: File transfer with python

2010-01-06 Thread Jan Kaliszewski
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

Re: Newbie help- Can multiple instances with multiple names automatically created.

2010-01-04 Thread Jan Kaliszewski
'{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

Re: assert type([]) == type(())

2010-01-02 Thread Jan Kaliszewski
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

Re: mod, modulo and % under 2.4 and 2.5

2009-12-31 Thread Jan Kaliszewski
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

Re: Thread performance on Python 2.6

2009-12-31 Thread Jan Kaliszewski
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

Re: class version of func_globals?

2009-12-30 Thread Jan Kaliszewski
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

Re: possible attribute-oriented class

2009-09-07 Thread Jan Kaliszewski
08-09-2009 o 02:15:10 Steven D'Aprano wrote: On Mon, 7 Sep 2009 09:37:35 am Jan Kaliszewski wrote: 06-09-2009 o 20:20:21 Ethan Furman wrote: > ... I love being able to type > >current_record.full_name == last_record.full_name > > instead of > >

Re: possible attribute-oriented class

2009-09-06 Thread Jan Kaliszewski
scripting (which is still important area of Python usage). -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Q on explicitly calling file.close

2009-09-06 Thread Jan Kaliszewski
finally: f.close() Obviously it doesn't substitute catching with 'except', but I don't see how it could disturb that. Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: possible attribute-oriented class

2009-09-05 Thread Jan Kaliszewski
05-09-2009 Steven D'Aprano wrote: On Fri, 04 Sep 2009 22:37:15 +0200, Jan Kaliszewski wrote: Named tuples (which indeed are really very nice) are read-only, but the approach they represent could (and IMHO should) be extended to some kind of mutable objects. [snip] What sort of exten

Re: possible attribute-oriented class

2009-09-04 Thread Jan Kaliszewski
04-09-2009 Ken Newton wrote: I like this version very much. I'm ready to put this into practice to see how it works in practice. [snip] Not only you (Ken) and me. :-) It appears that the idea is quite old. Nick Coghlan replied at python-id...@python.org: Jan Kaliszewski wrote: What d

Re: possible attribute-oriented class

2009-09-04 Thread Jan Kaliszewski
27;a': 1, 'c': 89, 'b': 2}),\ # 'third': '3rd', 'first': 1} print(struct._as_str(8)) # output: # { # second: 2.0 # sub: # { # a: 1 # c: 89 # b: 2 # } # third: 3rd # first: 1 # } What do you think about it? Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Usage of main()

2009-09-04 Thread Jan Kaliszewski
ic code in functions -- because, as we noted: * in practice it is considerably faster, * it helps you with using functions & class browsers. Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Usage of main()

2009-09-04 Thread Jan Kaliszewski
hanks to using the __main__ idiom (i.e. 'if __name__ == "__main__":' condition). Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: using queue

2009-09-02 Thread Jan Kaliszewski
y the best with a powerful single core; with more cores it becomes being suprisingly inefficient. The culprit is Pythn GIL and the way it [mis]cooperates with OS scheduling. See: http://www.dabeaz.com/python/GIL.pdf Yo *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating slice notation from string

2009-09-02 Thread Jan Kaliszewski
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

Re: Creating slice notation from string

2009-09-02 Thread Jan Kaliszewski
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

Re: Creating slice notation from string

2009-09-02 Thread Jan Kaliszewski
;> # 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

Re: map

2009-09-01 Thread Jan Kaliszewski
st, itertools.repeat('booHoo'))) Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Jan Kaliszewski
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

Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Jan Kaliszewski
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

Re: An assessment of the Unicode standard

2009-08-30 Thread Jan Kaliszewski
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

Re: Overriding iadd for dictionary like objects

2009-08-30 Thread Jan Kaliszewski
PS. Sorry for sending 2 posts -- the latter is the correct one. Cheers, *j -- http://mail.python.org/mailman/listinfo/python-list

Re: copy construtor question

2009-08-29 Thread Jan Kaliszewski
"'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

Re: Need help with Python scoping rules

2009-08-27 Thread Jan Kaliszewski
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.

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Jan Kaliszewski
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

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Jan Kaliszewski
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

Re: Need help with Python scoping rules

2009-08-26 Thread Jan Kaliszewski
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

Re: all possible matchings of elements of two lists

2009-08-26 Thread Jan Kaliszewski
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

Re: Need help with Python scoping rules

2009-08-26 Thread Jan Kaliszewski
ch "recursive" references in Python). -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: break unichr instead of fix ord?

2009-08-25 Thread Jan Kaliszewski
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

Re: Is it a bug?

2009-08-25 Thread Jan Kaliszewski
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 - ...) --

Re: Need help with Python scoping rules

2009-08-25 Thread Jan Kaliszewski
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

Re: Items inheriting attributes from its container?

2009-08-22 Thread Jan Kaliszewski
a[key]) for data in playerdata: self.append(Player(data)) -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Items inheriting attributes from its container?

2009-08-22 Thread Jan Kaliszewski
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

Re: string literal vs string variable

2009-08-22 Thread Jan Kaliszewski
-- they are commonly referred to as 'variables', regarding other languages' terminology). Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: sed/awk/perl: How to replace all spaces each with an underscore that occur before a specific string ?

2009-08-22 Thread Jan Kaliszewski
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

Re: Annoying octal notation

2009-08-22 Thread Jan Kaliszewski
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

Re: Using 'apply' as a decorator, to define constants

2009-08-22 Thread Jan Kaliszewski
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

Re: #elements of seq A in seq B

2009-08-20 Thread Jan Kaliszewski
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

Re: #elements of seq A in seq B

2009-08-20 Thread Jan Kaliszewski
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

Re: #elements of seq A in seq B

2009-08-20 Thread Jan Kaliszewski
) # 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

Re: Dictionary from a list

2009-08-19 Thread Jan Kaliszewski
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

Re: #elements of seq A in seq B

2009-08-19 Thread Jan Kaliszewski
) 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

Re: Dictionary from a list

2009-08-19 Thread Jan Kaliszewski
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

Re: difference between 2 arrays

2009-08-19 Thread Jan Kaliszewski
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

Re: Raw Strings with Variables

2009-08-18 Thread Jan Kaliszewski
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

Re: Scope and classes

2009-08-18 Thread Jan Kaliszewski
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

Re: Scope and classes

2009-08-18 Thread Jan Kaliszewski
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

Re: How do I convert an iterator over bytes into a str?

2009-08-18 Thread Jan Kaliszewski
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

Re: basic thread question

2009-08-18 Thread Jan Kaliszewski
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

Re: How to create functors?

2009-08-18 Thread Jan Kaliszewski
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

Re: Inheriting dictionary

2009-08-18 Thread Jan Kaliszewski
'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

Re: How to create functors?

2009-08-18 Thread Jan Kaliszewski
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

Re: How to create functors?

2009-08-18 Thread Jan Kaliszewski
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

Re: define class over 2 files

2009-08-18 Thread Jan Kaliszewski
that some other solution would be better (e.g. inheritance). Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheriting dictionary

2009-08-18 Thread Jan Kaliszewski
__(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

Re: Code formatting question: conditional expression

2009-08-18 Thread Jan Kaliszewski
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

Re: Why is "unpacking" of tuples only allowed when there's 1 tupple ?

2009-08-15 Thread Jan Kaliszewski
7; after more # than len(Polynome) # of arguments -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a string into substrings of equal size

2009-08-15 Thread Jan Kaliszewski
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

Re: Splitting a string into substrings of equal size

2009-08-14 Thread Jan Kaliszewski
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

Re: Splitting a string into substrings of equal size

2009-08-14 Thread Jan Kaliszewski
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

Re: i Don't get why it makes trouble

2009-08-13 Thread Jan Kaliszewski
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

Re: i Don't get why it makes trouble

2009-08-13 Thread Jan Kaliszewski
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

Re: With or without leading underscore...

2009-08-10 Thread Jan Kaliszewski
stance(foo, YourType)". Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Bug or feature: double strings as one

2009-08-09 Thread Jan Kaliszewski
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

Re: Bug or feature: double strings as one

2009-08-09 Thread Jan Kaliszewski
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

Re: Need help in configuration for TimedRotatingFileHandler

2009-08-09 Thread Jan Kaliszewski
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

Re: Bug or feature: double strings as one

2009-08-08 Thread Jan Kaliszewski
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

Re: remove last 76 letters from string [sorry, errata]

2009-08-05 Thread Jan Kaliszewski
sta: print >>nucleotides, '> foo bar length=76' print >>nucleotides, seq[-76] Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: remove last 76 letters from string

2009-08-05 Thread Jan Kaliszewski
int >>nucleotides, '> foo bar length=76' print >>nucleotides, seq[-76] Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: boolean OR gotcha

2009-08-04 Thread Jan Kaliszewski
here. The last is ok: None != 0. *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list

Re: Obtaining Python version

2009-08-03 Thread Jan Kaliszewski
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

Re: Printing with colors in a portable way

2009-07-30 Thread Jan Kaliszewski
== '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

Re: Confessions of a Python fanboy

2009-07-30 Thread Jan Kaliszewski
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

Re: Confessions of a Python fanboy

2009-07-30 Thread Jan Kaliszewski
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

  1   2   >