Jun-23-2018, 03:17 PM
a little script to print a horizontal rule with optional tab markers of an optional character (default '#') and an optional interval (default 8).
hr.py:
hr.py:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from __future__ import print_function import fcntl,os,struct,termios from os import environ as e from sys import argv try: h,w = struct.unpack('4H',fcntl.ioctl(1,termios.TIOCGWINSZ,struct.pack('4H',0,0,0,0)))[:2] except: try: fd = os.open('/dev/tty',os.O_WRONLY) h,w = struct.unpack('4H',fcntl.ioctl(fd,termios.TIOCGWINSZ,struct.pack('4H',0,0,0,0)))[:2] os.close(fd) except: h,w = 1,80 b='-' if 'b' in e: b=e['b'] r=[b]*w if 'i' in e: try: i=int(e['i']) except: i=8 if 't' in e: t=e['t'] if not t: t='#' for n in range(0,w,i): r[n]=t if len(argv)>2: a=' '.join(argv[2:]) for n in range(min(w,len(a))): r[n]=a[n] print(''.join(r))then this happens:
Output:lt1/forums /home/forums 4> t='#' python3 hr.py
Traceback (most recent call last):
File "hr.py", line 27, in <module>
for n in range(0,w,i):
NameError: name 'i' is not defined
lt1/forums /home/forums 5>
either line 21 or line 23 should define variable "i" in local name space, before control reaches line 27, right? or am i missing something? how can the flow of control avoid both line 21 and line 23?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.