Home Python print result to variable with correct formatting
Reply: 1

Python print result to variable with correct formatting

Jschlooz
1#
Jschlooz Published in 2017-11-13 22:09:36Z

I have a script that uses raw_input to enter a IPv4 IP address in CIDR format.

#<--BEGIN IPv4 CIDR FORMATTING -->
# Get address string and CIDR string from command line
sys.argv = raw_input("Type IPv4 address in CIDR format ")
(addrString, cidrString) = sys.argv.split('/')

The functions defined in the script converts the user inputted CIDR (1.1.1.1/16) to normal IPv4 format.

Print result with code: print addrString, ".".join(map(str, mask)) outputs to screen as 1.1.1.1 255.255.0.0 which is correct. But when I assign addrString, ".".join(map(str, mask)) to a variable, like var2 = addrString, ".".join(map(str, mask)) it's shown as ('1.1.1.1', '255.255.0.0')

How can i strip the unneeded signs like

(

and

'

and

,

when assigning to a variable?

Shadow
2#
Shadow Reply to 2017-11-13 22:15:21Z

You're printing a tuple. That's what tuples look like when printed. It sounds like you just want the two values together as a string, so you could do something like;

display_value = " ".join(var2)
print var2
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300352 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO