コード例 #1
0
ファイル: sengfmt2.py プロジェクト: cwins0r/sample-code
def main():
	lines = []
	for line in fileinput.input():
		lines.append(line)
	f = Formatter(lines)
	lines = f.get_lines()

	for l in lines:
		print (l)
コード例 #2
0
def getInput():
    text = []
    filename = None
    with fileinput.input() as f:
        for line in f:
            if (f.filename() != None):
                filename = f.filename()
                break
            else:
                text.append(line)
    if (filename != None):
        f = Formatter(filename=filename)
        t = f.get_lines()
        print_out(t)
    else:
        f = Formatter(inputlines=text)
        t = f.get_lines()
        print_out(t)

    fileinput.close()
コード例 #3
0
def main():
    inputtext =[]
    
    for line in fileinput.input():
        inputtext.append(line[:-1])

   #....if filename not given....#  
    
    f = Formatter(inputlines= inputtext) 
    y = f.get_lines()
    
   #....printing after formatting the input....#
    for line in y:
        print (line)
コード例 #4
0
def main():



	if len(sys.argv) == 1:
		# READ IN FROM STANDARD INPUT
		lines = [line.rstrip() for line in sys.stdin]
		f = Formatter(inputlines = lines)
	else:
		# READ IN FROM TEXT FILE
		inputfile = open(sys.argv[1])
		lines = [line.rstrip() for line in inputfile]
		f = Formatter(inputlines = lines)

	lines = f.get_lines()
	for l in lines:
		print (l)
コード例 #5
0
def main():

    s = """?maxwidth 50
?mrgn 15
Call me Ishmael. Some years ago--never mind how long precisely--having
little or no money in my purse, and nothing particular to interest me on
?mrgn +5
shore, I thought I would sail about a little and see the watery part of
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
?mrgn +5
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
?mrgn +5
the rear of every funeral I meet; and especially whenever my hypos get
such an upper hand of me, that it requires a strong moral principle to
?mrgn +5
prevent me from deliberately stepping into the street, and methodically
knocking people's hats off--then, I account it high time to get to sea
as soon as I can. This is my substitute for pistol and ball. With a
?mrgn +5
philosophical flourish Cato throws himself upon his sword; I quietly
?mrgn +5
take to the ship. There is nothing surprising in this. If they but knew
it, almost all men in their degree, some time or other, cherish very
nearly the same feelings towards the ocean with me.

There now is your insular city of the Manhattoes, belted round by
?mrgn +5
wharves as Indian isles by coral reefs--commerce surrounds it with
her surf. Right and left, the streets take you waterward. Its extreme
downtown is the battery, where that noble mole is washed by waves, and
?mrgn +5
cooled by breezes, which a few hours previous were out of sight of land.
Look at the crowds of water-gazers there."""

    lines = s.splitlines()
    f = Formatter(inputlines=lines)
    lines = f.get_lines()

    for l in lines:
        print(l)
コード例 #6
0
def main():
    canread = False
    try:  # check if can open file
        infile = open(sys.argv[1], 'r')
        canread = True
    except IndexError:  # read from stdin if no file
        infile = sys.stdin
        canread = True
    except IOError:  # file doesn't exist so print error
        print("File Specified Does Not Exist!!")
    if canread:
        with infile:  # read lines in from input
            inlines = infile.readlines()
        # format the lines
        f = Formatter(inlines)
        # get the output from Formatter class
        lines = f.get_lines()
        # print the output from Formatter class
        for line in lines:
            print(line)