Utilty python script

A forum for general discussion of the Python programming language.

Utilty python script

Postby input » Wed Dec 11, 2013 5:35 pm

Hello,

I am just a beginner in python and I have the following script that not work for me.
What I do to run this script is on the command promt Windows XP this: python more.py System.txt
What I then see is only the sourcecode from the scipt on my screen. And no System.txt

What I am doing wrong.

Code: Select all
#########################################################
# split and interactively page a string or file of text;
#########################################################

import string

def more(text, numlines=15):
    lines = string.split(text, '\n')
    while lines:
        chunk = lines[:numlines]
        lines = lines[numlines:]
        for line in chunk: print line
        if lines and raw_input('More?') not in ['y', 'Y']: break

if __name__ == '__main__':
    import sys                             # when run, not imported
    more(open(sys.argv[1]).read(), 10)     # page contents of file on cmdline
Last edited by Yoriz on Wed Dec 11, 2013 6:04 pm, edited 1 time in total.
Reason: First post lock, Added code tags
input
 
Posts: 1
Joined: Wed Dec 11, 2013 5:29 pm

Re: Utilty python script

Postby Kebap » Wed Dec 11, 2013 9:14 pm

Hello input. Welcome to python and the forums! :mrgreen: Try this in your program and let me know what it outputs:

Code: Select all
print sys.argv
print sys.argv[1]
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 2 guests