python - Separating prints within a for loop -


i'm writing script reads subnet in binary form , converts decimal. script needs output decimal result separated periods (i.e. output this: 255.255.255.0).

i'm trying use sep ="." separate print periods, however, not seem work. suspect may because printing individual outputs each time rather 1 full statement joined together. i've attempted end= ".", not option adds additional period end of output.

here snippet of script:

sub1 = "1111 1111.1111 1111.1111 1111.0000 0000" octets = [sub1[0:9], sub1[10:19], sub1[20:29], sub1[30:39]]  conversion in octets:     print(int((conversion).replace(" ",""), 2), sep=".") 

how can make printed output separate periods?

replace spaces once, split string on '.' create list , use .join reconstruct string after converting octets:

sub1 = "1111 1111.1111 1111.1111 1111.0000 0000" octets = sub1.replace(' ', '').split('.')  print('.'.join(map(str, [int(i, 2) in octets]))) # 255.255.255.0 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -