diff options
author | Fred Drake <fdrake@acm.org> | 2001-12-12 06:20:34 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-12-12 06:20:34 (GMT) |
commit | 1e7dfd374578bb322fba69a227519fed8ec60f3d (patch) | |
tree | 83eef8957fb81dcd357c6ecde47d715296b5c4f8 /Lib | |
parent | 8d0645cb84c3a8babce4b9b44c389e175e293b2a (diff) | |
download | cpython-1e7dfd374578bb322fba69a227519fed8ec60f3d.zip cpython-1e7dfd374578bb322fba69a227519fed8ec60f3d.tar.gz cpython-1e7dfd374578bb322fba69a227519fed8ec60f3d.tar.bz2 |
Wrapped a long line.
Converted to use "".startswith() to avoid slicing (& temp string creation).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/getopt.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/getopt.py b/Lib/getopt.py index 82cf04d..f1dc7ac 100644 --- a/Lib/getopt.py +++ b/Lib/getopt.py @@ -68,7 +68,7 @@ def getopt(args, shortopts, longopts = []): if args[0] == '--': args = args[1:] break - if args[0][:2] == '--': + if args[0].startswith('--'): opts, args = do_longs(opts, args[0][2:], longopts, args[1:]) else: opts, args = do_shorts(opts, args[0][1:], shortopts, args[1:]) @@ -124,7 +124,8 @@ def do_shorts(opts, optstring, shortopts, args): if short_has_arg(opt, shortopts): if optstring == '': if not args: - raise GetoptError('option -%s requires argument' % opt, opt) + raise GetoptError('option -%s requires argument' % opt, + opt) optstring, args = args[0], args[1:] optarg, optstring = optstring, '' else: @@ -135,7 +136,7 @@ def do_shorts(opts, optstring, shortopts, args): def short_has_arg(opt, shortopts): for i in range(len(shortopts)): if opt == shortopts[i] != ':': - return shortopts[i+1:i+2] == ':' + return shortopts.startswith(':', i+1) raise GetoptError('option -%s not recognized' % opt, opt) if __name__ == '__main__': |