Monday 15 June 2015

python - Print dashes across full width of screen -



python - Print dashes across full width of screen -

this question has reply here:

how console window width in python 12 answers

i'm looking print dash "-" until end of user's screen.

basically programme print line of text , line of dashes beneath , line of text. done user can distinguish between first , sec line.

something this:

first line of text -------------------------------------------------------------------------------------- sec line of text

is there way me using standard python 2.6 libraries. cannot utilize additional libraries such texttable or newer version of python.

2.6? okay, quite old. should work: (taken how console window width in python)

def getterminalsize(): import os env = os.environ def ioctl_gwinsz(fd): try: import fcntl, termios, struct, os cr = struct.unpack('hh', fcntl.ioctl(fd, termios.tiocgwinsz, '1234')) except: homecoming homecoming cr cr = ioctl_gwinsz(0) or ioctl_gwinsz(1) or ioctl_gwinsz(2) if not cr: try: fd = os.open(os.ctermid(), os.o_rdonly) cr = ioctl_gwinsz(fd) os.close(fd) except: pass if not cr: cr = (env.get('lines', 25), env.get('columns', 80)) ### utilize get(key[, default]) instead of try/catch #try: # cr = (env['lines'], env['columns']) #except: # cr = (25, 80) homecoming int(cr[1]), int(cr[0]) (width, height) = getterminalsize() print "-" * width

python python-2.6

No comments:

Post a Comment