Comments (12)
But then how do you specify an argument that contains strings?
Original comment by [email protected]
on 16 Sep 2009 at 8:33
from argparse.
s/strings/spaces
Original comment by [email protected]
on 16 Sep 2009 at 8:34
from argparse.
Ok. In that case it will not work. Is it stablished that strings are specified
between " " ?
If that is the case, I think I can write a more complex parser that handles
that as well...
Original comment by [email protected]
on 17 Sep 2009 at 6:45
from argparse.
I'm not really 100% sure what the standard here is. See issue16 where the
feature was
proposed.
Java implements this feature slightly differently:
http://java.sun.com/javase/6/docs/technotes/tools/windows/javac.html#commandline
argfile
There aren't really clear specs there, but after playing around with javac for
a bit,
I think the Java rules are:
* Arguments are split up by whitespace
* Except that you can quote things with ""
But adopting that behavior for argparse would be backwards incompatible with the
current behavior. So we'd have to go through a deprecation cycle before
changing it.
I'd definitely like to see feedback from zhirsch, who created the original
feature
request before moving forward on this issue.
Original comment by [email protected]
on 17 Sep 2009 at 7:34
- Added labels: Type-Enhancement
- Removed labels: Type-Defect
from argparse.
I think quoting strings is the way to go.
What I do not like of the current implementation is that if you happen to not
have a perfect formated file with
parameters, such as having a space at the beginning or the end of the file, you
get all kind of weird errors...
In any case, making possible to specify strings in the argument file without
quotes is not really consistent with
the command line interface, since you cannot use unquoted strings without
getting errors...
Original comment by [email protected]
on 17 Sep 2009 at 7:43
from argparse.
The argument against quotes is that it's only your shell that's allowing quotes
-- if
you worked directly within Python, you wouldn't put quotes around anything.
That said, I'm open to changing things given:
* we get some feedback from others saying that they think this is the right
thing to
do, and
* we go through the usual deprecation process, which means:
* argparse 1.1:
* introduce quoting mechanism
* issue DeprecationWarning for lines with spaces but no quotes
* argparse 1.2:
* turn warning into error - spaces only allowed with quotes
* argparse 1.3:
* start treating all whitespace as separators - i.e. call .split()
Original comment by [email protected]
on 17 Sep 2009 at 9:11
from argparse.
How about adding an (optional) argument that takes a callable that gets passed
each
line from an argument file? Then the parsing would use the return value of
that
function call as the actual line. The default would be the current behavior
(taking
each line literally).
I've found the need for such a feature myself, for skipping blank lines and
lines
that start with a # (comments).
I've attached a patch that implements this.
Original comment by [email protected]
on 18 Sep 2009 at 5:04
Attachments:
from argparse.
Seems like for the skipping comments you really want to override the entire file
reading and parsing process
Maybe we should add a ``fromfile_read_args`` keyword argument, defaulting to::
def read_args(path):
return open(path).read().splitlines()
And then for the particular use case above you could override it with::
def read_lines(path):
for line in open(path):
if not line.startswith("#"):
for item in line.split():
yield item
Original comment by [email protected]
on 18 Sep 2009 at 7:10
from argparse.
Yea, that works. An alternative would be to make it a "public" method of the
ArgumentParser class and have to subclass in order to override it (which would
reduce
the number of keyword arguments to the constructor).
Original comment by [email protected]
on 19 Sep 2009 at 4:19
from argparse.
Yeah, I thought about that too. Either one would probably be okay.
Original comment by [email protected]
on 19 Sep 2009 at 6:06
from argparse.
Here's a patch that adds a method to the ArgumentParser class that can be
overridden in
a subclass.
Original comment by [email protected]
on 28 Dec 2009 at 9:02
Attachments:
from argparse.
Thanks for the excellent patch. Committed with minor modifications in r80.
Original comment by [email protected]
on 7 Jan 2010 at 5:30
- Changed state: Fixed
from argparse.
Related Issues (20)
- Poll: why are you using argparse from pypi (or from here) these days? HOT 3
- How to filepath location as command line argument HOT 1
- What does the comments "We have to allow for ..." means? HOT 3
- parsing only a subset and leave all other checks undone HOT 3
- The description of optional arguments which takes values is not same as the (true/false) based ones since it's name is appearing twice. HOT 1
- argparse 1.2 incompatible with Python 3.1 HOT 10
- When -h is used, default values that fail should not matter HOT 2
- positional arguments before options cause all options to be in REMAINDER HOT 1
- Argparse is not testable with nosetest HOT 1
- `choices=[...]` overrides `nargs='*'` HOT 1
- Serious issues with nested mutex groups in help output HOT 2
- Bug with negative numbers in scientific notation HOT 1
- pypi version does not handle empty arguments when fromfile_prefix_chars set (python issue 12353) HOT 1
- .add_mutually_exclusive_group() only works when child of parser but not when a child of argument group HOT 1
- Argparse 1.4.0 doesn't have a wheel on PyPI: causes get-pip.py failures. HOT 2
- Is " if option_string.startswith(option_prefix): " a special design in _get_option_tuples()? HOT 3
- Issue with argument_group and required add_mutually_exclusive_group HOT 2
- AssertionError: assert ' '.join(pos_parts) == pos_usage HOT 3
- argparse WBN if default values displayed in -h message HOT 1
- argparse ArgumentParser(allow_abbrev=True) not documented on web HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from argparse.