Message110150
Hi.
I am not a python expert and i was trying to reduce this next code:
data = []
i = 0
for j in range(packetlen+1):
print i, self.channels_in[ channels[i] ]
data.append( self.channels_in[ channels[i] ].pop() )
i += 1
if i >= len(channels):
i=0
into something like this:
data = []
for j in range(packetlen+1), i in channels:
print j, i
data.append( self.channels_in[ i ].pop() )
which is much more readable and short.
But i didnt know if this sintax is really supported (also i didnt found examples on internet), so i just tried.
I runned the script and it didnt complains with errors, BUT i found that the behavior is not what i expected.
I expected j to take value of range() and i to take the values of channels until range() gets empty.
well, the actual behavior is that j takes the value of the complete range() as in
j = range(..)
and the for loop iterates as in
for i in channels:
ALSO i tested this un the python command line and it produces different behaviours:
the same sintax writen as:
for j in range(1,5), i in range(120,500,12):
print j, i
produces
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'i' is not defined
Thats all. I guess that if it produces different results, then there is an error happening here.
If there is a pythonic way to do this:
for j in range(packetlen+1), i in channels:
please tell me.
Cheers.
Diego |
|
Date |
User |
Action |
Args |
2010-07-13 00:11:13 | jacobidiego | set | recipients:
+ jacobidiego |
2010-07-13 00:11:12 | jacobidiego | set | messageid: <1278979872.82.0.311259826309.issue9240@psf.upfronthosting.co.za> |
2010-07-13 00:11:11 | jacobidiego | link | issue9240 messages |
2010-07-13 00:11:08 | jacobidiego | create | |
|