the official way of printing unicode strings

2008-12-13 Thread Piotr Sobolewski
Hello, in Python (contrary to Perl, for instance) there is one way to do common tasks. Could somebody explain me what is the official python way of printing unicode strings? I tried to do this such way: s = u"Stanisław Lem" print u.encode('utf-8') This works, but is very cumbersome. Then I tried

Re: the official way of printing unicode strings

2008-12-14 Thread Piotr Sobolewski
Marc 'BlackJack' Rintsch wrote: > I'd make that first line: > sys.stdout = codecs.getwriter('utf-8')(sys.stdout) > > Why is it even more cumbersome to execute that line *once* instead > encoding at every ``print`` statement? Oh, maybe it's not cumbersome, but a little bit strange - but sure, I c

I want to release the GIL

2008-10-20 Thread Piotr Sobolewski
Hello, I have such program: import time import thread def f():     global lock     while True:         lock.acquire()         print thread.get_ident()         time.sleep(1)         lock.release() lock=thread.allocate_lock() thread.start_new_thread(f,()) thread.start_new_thread(f,()) time.sleep(60)

Re: I want to release the GIL

2008-10-21 Thread Piotr Sobolewski
Thanks for answers. But what about my main question? Is it possible to release GIL without sleeping? I know that in this example situation I can achieve my goals without that - I can just move sleep outside of locked block. But I just want to know it for future - can I just do something like thread

variable scope in list comprehensions

2008-04-03 Thread Piotr Sobolewski
Hello, there is something I don't understand about list comprehensions. I understand how does this work: print [[y for x in range(8)] for y in range(8)] However I don't understand why this one works: print [[y for y in range(8)] for y in range(8)] In this second example I have one loop nested i

Re: variable scope in list comprehensions

2008-04-04 Thread Piotr Sobolewski
Duncan Booth wrote: > For the OP, in some languages (e.g. C) 'for' loops typically calculate > the value of the loop control variable based on some expression > involving the previous value. Python isn't like that. In Python the data > used to compute the next value is stored internally: you canno

how can I use a callable object as a method

2008-09-18 Thread Piotr Sobolewski
Hello, I would like to use a callable object as a method of a class. So, when I have such normal class: class f: version = 17 def a(self): return self.version f1 = f() print f1.a() I want to change it to something like that: class add: def __call__(self

Re: how can I use a callable object as a method

2008-09-23 Thread Piotr Sobolewski
Hrvoje Niksic wrote: >> However, the second version does not work. I think I understand >> why. That's because "a" inside f1 is not a function (but an object). > > An object that defines __call__ is perfectly usable as a function. > Your problem is that it doesn't know how to convert itself to a