0

I am trying to pull words and integers from a text file and have them all print on the same line using if statements. Would I need to continue with the for loop to achieve the outputs to be printed on the same line?

I am trying to get it print frame #, type:0x0800

with open('wireShark.txt', 'rt') as file_content:
for line in file_content:
    if 'Frame' in line:
        i=line.find(':') 
        idnum = line[0:i] 
        print(idnum)

    if 'Type' in line:
        i=line.find(':')
        idnum4 = line[4:9]
        print (idnum4)

    if '0x0800' in line:
        i=line.find(')')
        idnum5 = line[16:i]
        print (idnum5)
martineau
  • 119,623
  • 25
  • 170
  • 301
Orion262
  • 3
  • 2

1 Answers1

0

As many people are noticing, you don't need to print with a new line.

with open('wireShark.txt', 'rt') as file_content:
for line in file_content:
    if 'Frame' in line:
        i=line.find(':') 
        idnum = line[0:i] 
        print(idnum, end="")

    if 'Type' in line:
        i=line.find(':')
        idnum4 = line[4:9]
        print (idnum4, end="")

    if '0x0800' in line:
        i=line.find(')')
        idnum5 = line[16:i]
        print (idnum5, end="")

The end="" just tells Python: Hey, don't print a newline.

PythonPikachu8
  • 359
  • 2
  • 11