[Tutor] How can I modify this simple script for argparse?
kwpolska at gmail.com
Sat Oct 13 19:13:22 CEST 2012
On Sat, Oct 13, 2012 at 7:03 PM, Santosh Kumar <sntshkmr60 at gmail.com> wrote:
> Here is a sample script without argparse implementation:
> from sys import argv
> script, filename = argv
> foo = "This line was written by a Python script."
> with open(filename, 'a') as file:
> I find argparse hard. Just give me a startup. How can I make a asgparse version?
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
The documentation may be hard to understand, but the tutorial isn’t:
Anyways, here you go:
parser = argparse.ArgumentParser()
args = parser.parse_args()
foo = "This line was written by a Python script."
with open(args.filename, 'a') as file:
Note that this is the most basic version. Also, I had problems with
running it as a standalone file, but it worked fine in the interactive
stop html mail | always bottom-post
www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
GPG KEY: 5EAAEA16
More information about the Tutor