Archive for March 4th, 2011
new output format in Python
Posted March 4, 2011
on:- In: 电脑
- Leave a Comment
print “***********************************************”
print “total: {0}”.format(total)
print “{0:<10s} {1:>10s} {2:>20s}”.format(‘version’, ‘count’, ‘percentage’)
versions = sorted(counts.keys())
for k in versions:
print “{0:<10s} {1:>10d} {2:>20.1%}”.format(k, counts[k], counts[k]/float(total))
how to force a division in Python
Posted March 4, 2011
on:- In: 电脑
- Leave a Comment
1. a/float(b)
2. from __future__ import division
c = a/b
3. python 3.x, / is division while // is the old integer division
subprocess pipe and wait deadlock
Posted March 4, 2011
on:- In: 电脑
- Leave a Comment
p = subprocess.Popen([executable, args], stdout=subprocess.PIPE)
p.wait()
this will deadlock if executable outputs fill up the in-memory buffer and thus stops until someone reads from that buffer
in essence, don’t wait on a process that can output something. use p.communicate() for this purpose