Python Forum

Full Version: printing strings on same line..
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import re
with open("svlan.txt") as svlan_file:
     svlan_values = set(svlan_file.read().lower().split())

with open("e320configuration.txt") as conf_file:
    with open("data.txt", "wt") as data_file:
        for line in conf_file:
            if line.lower().strip() not in svlan_values:
                data_file.write(line + "\n")

svlan = open('data.txt','r')
lines = svlan.readlines()
for line in lines:
    if 'gig' in line:
       interface = line
    if 'svlan' in line:
        svlanid = line
        print ("{} {}".format(svlanid,interface))
current output as below
svlan id 95 19
interface gigabitEthernet 2/0/4.9519

svlan id 91 119
interface gigabitEthernet 2/0/5.1011901

svlan id 92 119
interface gigabitEthernet 2/0/5.1011902

svlan id 93 119
interface gigabitEthernet 2/0/5.1011903

expected output
svlan id 95 19 interface gigabitEthernet 2/0/4.9519
svlan id 91 119 interface gigabitEthernet 2/0/5.1011902
when you don't want a line feed, use:
print('some stuff', end='')
Hi age of wisdom,

import re
with open("svlan.txt") as svlan_file:
     svlan_values = set(svlan_file.read().lower().split())

with open("e320configuration.txt") as conf_file:
    with open("data.txt", "wt") as data_file:
        for line in conf_file:
            if line.lower().strip() not in svlan_values:
                data_file.write(line + "\n")

svlan = open('data.txt','r')
lines = svlan.readlines()
for line in lines:
    if 'gig' in line:
       interface = line.split(' ')
    if 'svlan' in line:
       vlan = line.split(' ')
       print "%s %s %s" %(interface[2],vlan[3],vlan[4])
tried different combination, but result is same.
well, it's good once you get advice to a problem you cannot solve on your own, to learn something and implement same solution when you see same problem again
https://python-forum.io/Thread-something...8#pid34638
you need to strip new line '\n' from interface
Don't expect to answer same question for the third time