Python Forum
BeautifulTable print header multi times
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BeautifulTable print header multi times
#4
Hi again!

My understanding, seeing your first post, is that your code runs properly, but it prints the header row every time it reads for line in fp because you made the program to print the headers inside the loop for every line read in fp with this part of your code:

def readfile():
     
    with open('/root/domain.txt') as fp:
         
        for line in fp:
            http = "http://" + line.rstrip()
            u = qan.get(http ,verify= False)
            u = (str(u.status_code))
            table.column_headers =["Website", "Status", "Time"]
            table.column_alignments['Website'] = BeautifulTable.ALIGN_LEFT
            table.set_style(BeautifulTable.STYLE_MARKDOWN)
             
            table.append_row([http, u, str(time.clock()) ])
I think that if the image you posted corresponds to that first program, then you should try to leave out of the loop, just the part establishing the unchangeable characteristics to set the table.

If the program that you posted on your first post was running fine, and the only thing not wanted was that the header line was printed more than once, then I would suggest you try this one:

# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import requests as qan
import time 
from beautifultable import BeautifulTable
import warnings
 
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
table = BeautifulTable()
 
def readfile():     
    with open('/root/domain.txt') as fp:
        table.column_headers =["Website", "Status", "Time"]         
        table.column_alignments['Website'] = BeautifulTable.ALIGN_LEFT
        table.set_style(BeautifulTable.STYLE_MARKDOWN)         
        for line in fp:
            http = "http://" + line.rstrip()
            u = qan.get(http ,verify= False)
            u = (str(u.status_code))             
            table.append_row([http, u, str(time.clock()) ])             
            print(table)
All the best,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Messages In This Thread
RE: BeautifulTable print header multi times - by newbieAuggie2019 - Oct-29-2019, 11:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to print string multiple times on new line ace19887 7 6,008 Sep-30-2020, 02:53 PM
Last Post: buran
  How to print string multiple times separated by delimiter Mekala 1 2,018 May-23-2020, 09:21 AM
Last Post: Yoriz
  Print 'X' a number of times Than999 1 2,732 Jan-18-2020, 06:41 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020