Python Forum
BeautifulTable print header multi times
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BeautifulTable print header multi times
#11
(Oct-29-2019, 11:38 AM)buran Wrote: the line you refer is already outside the loop (line 15 in your latests code)
(Oct-29-2019, 11:23 AM)buran Wrote: line 23 must be outside the loop.
that is print(table)

# 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)
readfile()
Output:
Traceback (most recent call last): File "/root/Desktop/checkurl.py", line 24, in <module> readfile() File "/root/Desktop/checkurl.py", line 20, in readfile u = qan.get(http ,verify= False) File "/usr/local/lib/python2.7/dist-packages/requests-2.7.0-py2.7.egg/requests/api.py", line 69, in get return request('get', url, params=params, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-2.7.0-py2.7.egg/requests/api.py", line 50, in request response = session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-2.7.0-py2.7.egg/requests/sessions.py", line 465, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-2.7.0-py2.7.egg/requests/sessions.py", line 573, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-2.7.0-py2.7.egg/requests/adapters.py", line 415, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))
Reply
#12
this is problem with your connection, nothing to do with where the print function is
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to print string multiple times on new line ace19887 7 5,781 Sep-30-2020, 02:53 PM
Last Post: buran
  How to print string multiple times separated by delimiter Mekala 1 1,914 May-23-2020, 09:21 AM
Last Post: Yoriz
  Print 'X' a number of times Than999 1 2,662 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