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
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
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)
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
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
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
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
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