Python Forum
BeautifulTable print header multi times
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BeautifulTable print header multi times
#2
(Oct-27-2019, 11:54 AM)evilcode1 Wrote:
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"]
its print the table header multi times i need to print it just one time how i can do that ??

Hi!

It's just a thought, but it seems that you have put the table header inside the loop, so every time it reads a line in fp, it would print the header. Have you tried leaving the header line out of the loop and at the same level of indentation as for line in fp?:

def readfile():
    
    with open('/root/domain.txt') as fp:

        table.column_headers =["Website", "Status", "Time"]        
        for line in fp:
            http = "http://" + line.rstrip()
            u = qan.get(http ,verify= False)
            u = (str(u.status_code))
All the best,



I HAVE JUST MADE A DUMMY TEST, WITH SOME MODIFICATIONS OF YOUR CODE TO BE ABLE TO RUN IT ON MY COMPUTER (SO I JUST COMMENTED OUT SOME LINES OR MADE SOME OTHER ADJUSTMENTS, BUT THAT CAN BE EASILY REVERTED AND APPLIED TO YOUR PROGRAM):

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('C:/sites_list_01.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:     
            table.append_row(['http://XXXXXXXXX', '200', str(time.clock()) ])
##            http = "http://" + line.rstrip()
##            u = qan.get(http ,verify= False)
##            u = (str(u.status_code))   
##            print(http + " \t\t\t== > Status : " + u + " \t took : " + str(time.clock()) )
        print(table)
readfile()
where 'C:/sites_list_01.txt' is a dummy text file with just 11 sites that I used to test the program (I have already eliminated it), but the program with these modifications to run on my computer produced the following output (just one header row):

Output:
| Website | Status | Time | |------------------|--------|-------| | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | | http://XXXXXXXXX | 200 | 0.632 | >>>
So I think you could adapt it to your desired output.

All the best,



I think I should also point out that I received a deprecation warning message:

Error:
DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead.
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-27-2019, 12:47 PM

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,731 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