0

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 ?

user2061913
  • 910
  • 2
  • 14
  • 34
  • 5
    It would help if you told us what you were doing to _get_ that output. – Jack Aidley Jun 03 '14 at 20:13
  • 1
    You can flatten the array and then print the flattened array, which will have fewer brackets: http://stackoverflow.com/questions/10632111/how-to-flatten-a-hetrogenous-list-of-list-into-a-single-list-in-python/10632267 – Anderson Green Jun 03 '14 at 20:13
  • You are getting the result in form of a tuple. https://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences Try playing with the tuples. – ρss Jun 03 '14 at 20:18

3 Answers3

2
>>> 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)
pynovice
  • 7,424
  • 25
  • 69
  • 109
0

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))')
LonelySoul
  • 1,212
  • 5
  • 18
  • 45
0

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
Roland Smith
  • 42,427
  • 3
  • 64
  • 94