Splitting device addresses into parts

Bruno Desthuilliers onurb at xiludom.gro
Tue Sep 26 18:49:48 CEST 2006


Fabian Steiner wrote:
> I often have to deal with strings like "PCI:2:3.0" or "PCI:3.4:0" and
> need the single numbers as tuple (2, 3, 0) or (3, 4, 0). Is there any
> simple way to achieve this? So far I am using regular expressions but I
> would like to avoid them ...

devices = ["PCI:2:3.0", "PCI:3.4:0"]
for d in device:
  nums = tuple(map(int, d.split(':')[1:]))
  print "for ", d, " : ", nums


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list