Reputation: 920
is it possible to remove all the formatting from an output
currently i get the values :
((4,), (4,), (88, 59, 21, 38))
displayed in the terminal, however is there a way to strip away the brackets so i only get the values ?
I know it should be simple but cant see to find it on google
Thanks
to get this i am using the command :
print "Header : ", circ_id, command, ip
where where circ_id etc have been derived from earlier on in the application from unpacking a packet for example the ip was derived from :
ip = struct.unpack(byte_string, payload[start:end])
so i guess the question is how in python can you merge various tuples into a single tuple ?
Upvotes: 0
Views: 2269
Reputation: 43523
Use a format string.
In [1]: circ_id, command, ip = (4,), (4,), (88, 59, 21, 38)
In [2]: fs = "Header: {}, {}, {}.{}.{}.{}"
In [3]: print fs.format(circ_id[0], command[0], ip[0], ip[1], ip[2], ip[3])
Header: 4, 4, 88.59.21.38
Upvotes: 0
Reputation: 1232
One more if I the input is string
import re
re.sub('.', lambda m : {'(':'',')':''}.get(m.group(),m.group()),'((4,),(4,),(88,59,21,38))')
Upvotes: 0
Reputation: 7752
>>> new = []
>>> a
((4,), (4,), (88, 59, 21, 38))
>>> for i in a:
... for j in i:
... new.append(j)
...
>>> new
[4, 4, 88, 59, 21, 38]
>>> #If you want result back in tuple
...
>>> tuple(new)
(4, 4, 88, 59, 21, 38)
Upvotes: 2