On Wed, 8 Jan 2014 13:51:40 -0800 (PST), sagarnild...@gmail.com wrote:
I am trying to write a program in python which searches for user
specified words in a txt file and copies the selected lines
containing that word into another file.
John Gordon has given you a good start on argument parsing
.
This excludes the word "abc" and search for "exception".
But I don't know how to:
Include multiple search word and exclude words
How to denote them by -e and -s. I have seen the argparse and the getopt
tutorial. But there's no tutorial on this specific topic.
Ple
In
sagarnild...@gmail.com writes:
> But I don't know how to:
> Include multiple search word and exclude words
> How to denote them by -e and -s. I have seen the argparse and the getopt
> tutorial. But there's no tutorial on this specific topic.
This should help you ge
rch for "exception".
But I don't know how to:
Include multiple search word and exclude words
How to denote them by -e and -s. I have seen the argparse and the getopt
tutorial. But there's no tutorial on this specific topic.
Please can somebody help me by modifying my code or wr
gt; File "/home/oracle/wlsuserconfigfiles/./Health_Check_Servers.py", line
> 80, in
> ?
> File "/home/oracle/wlsuserconfigfiles/./Health_Check_Servers.py", line
> 22, in
> main
> NameError: getopt
>
> I thought I was importing the "getopt" as shown belo
ot;/home/oracle/wlsuserconfigfiles/./Health_Check_Servers.py", line 22, in
main
NameError: getopt
I thought I was importing the "getopt" as shown below.
Thanks for you help in advance,
Mustafa
#Conditionally import wlstModule only when script is executed with jython
if __name__ ==
s.
>
> Raphael
> -----
>
> [testGetOpt.py< 1K ]#!/usr/bin/env python
> import sys
> import getopt
>
> try:
> opts, args = getopt.getopt(sys.argv[1:], 'ab')
> except getopt.error:
> print
; is not in the
argument given in getopt.getopt, but it doesn't.
What am I doing wrong ?
Using python 2.6.4 on WindowXP.
Thanks.
Raphael
-
#!/usr/bin/env python
import sys
import getopt
try:
opts, args = getopt.getopt(sys.argv[1:
Hello,
I have some trouble to make getopt.getopt work and the way I want (and
is described in the documentation).
Attached is very small script to reproduce my problem.
If running:
> python testGetOpt.py -a junk1 -b junk2
everything is ok
> python testGetOpt.py -c junk1
ok too: I get the 'In
> Matt Nordhoff wrote:
> > BTW: Checked out optparse? It's bigger and sexier!
If you're doing things with positional arguments, you should consider using
argparse (http://argparse.googlecode.com/svn/tags/r101/doc/index.html). It's
like optparse, but (much) better.
Cheers,
Emm
--
http://mail.
Matt Nordhoff wrote:
> BTW: Checked out optparse? It's bigger and sexier!
Thanks for the tip. Works a treat.
-- Matt
--
http://mail.python.org/mailman/listinfo/python-list
Matthew Lear wrote:
> Hello,
>
> I'm having problems getting getopt to function correctly. Basically, no
> exception is being raised if no argument is passed to the code snippet
> below. I've read the Python documentation and tried example code from
> various s
Hello,
I'm having problems getting getopt to function correctly. Basically, no
exception is being raised if no argument is passed to the code snippet
below. I've read the Python documentation and tried example code from
various sources which should cause an exception, only they don
LoD MoD wrote:
> In this instance the trackback was somewhat unhelpful.There problem was
> here:
>
>file = open(filename, 'r')
>
> should be
>
>file = open(a, 'r')
>
> args should be passed within the getopt riff
We
In this instance the trackback was somewhat unhelpful.There problem was
here:
file = open(filename, 'r')
should be
file = open(a, 'r')
args should be passed within the getopt riff
On Fri, Jul 17, 2009 at 11:08 AM, MRAB wrote:
> LoD MoD wrote:
&
LoD MoD wrote:
I am having trouble extending my option parsing.
Any help is appreciated:
import sys
import getopt
import time
def tail(file):
while 1:
where = file.tell()
line = file.readline()
if not line:
time.sleep(1)
file.seek(where
I am having trouble extending my option parsing.
Any help is appreciated:
import sys
import getopt
import time
def tail(file):
while 1:
where = file.tell()
line = file.readline()
if not line:
time.sleep(1)
file.seek(where
if (key in ("-q", "--testTableName")):
...
> The one that gives me trouble is with the -q option, because it can
> look like: -q "SQL 1 TABLE". It returns back just SQL. How do I get
> it to return the whole thing that is in double quotes?
Hello,
I have been trying to find an example of how to deal with options that have
spaces in them. I am using jython, which is the same I think as python 2.2.3.
I feebly tried to use optparse and argparse with no success (got gettext,
locale, and optparse). The code is as follows:
try
Keep your threadiquette to yourself.
On Wed, Feb 11, 2009 at 1:48 PM, John Machin wrote:
> On Feb 11, 6:16 am, Matthew Sacks wrote:
>> Hi List,
>> I am getting an index out of range error when trying to parse with getopt.
>> Probably something simple. Any sugges
Perhaps you can give me a call privately and I will explain it to you.
Regards,
Matthew
On Wed, Feb 11, 2009 at 1:48 PM, John Machin wrote:
> On Feb 11, 6:16 am, Matthew Sacks wrote:
>> Hi List,
>> I am getting an index out of range error when trying to parse with getopt.
>&g
On Feb 11, 6:16 am, Matthew Sacks wrote:
> Hi List,
> I am getting an index out of range error when trying to parse with getopt.
> Probably something simple. Any suggestions are appreciated
>
> optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=&
an index out of range error when trying to parse with
>>> getopt.
>>> Probably something simple. Any suggestions are appreciated
>>>
>>> optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=',
>>> 'adminServerURL=', &
Steve Holden wrote:
Matthew Sacks wrote:
Hi List,
I am getting an index out of range error when trying to parse with getopt.
Probably something simple. Any suggestions are appreciated
optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=',
'adminServerU
Matthew Sacks wrote:
> Hi List,
> I am getting an index out of range error when trying to parse with getopt.
> Probably something simple. Any suggestions are appreciated
>
> optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=',
> 'admin
Robert Kern writes:
>> is there some way i can force the import based on the the absolute
>> path to the module?
>
> Better would be for you to copy the optparse.py module onto your
> Jython's import path. I'm not particularly familiar with the details
> of Jython, so you will need to consult
specify *all* short options that
you will accept, whether they are no-value or value options; otherwise
you would have to do your own checking for unacceptable options
> This seems to make things a bit more difficult considering unless I
> use the GNU style getopt all arguments are require
I didn't realize that the no-value arguments, -b, -h, etc are required?
This seems to make things a bit more difficult considering unless I
use the GNU style getopt all arguments are required to be passed?
I could be mistaken.
I will have a look at what you have posted here and report my re
On Feb 11, 4:36 pm, Matthew Sacks wrote:
> The documentation leaves lack for want, especially the examples.
You had two problems:
(1) str(passedArgs): The docs make it plain that "args" is a list, not
a str instance: """args is the argument list to be parsed, without the
leading reference to the
On Feb 11, 12:25 pm, John Machin wrote:
> On Feb 11, 12:12 pm, Matthew Sacks wrote:
>
> > if anyone can have a look at this code and offer suggestions i would
> > appreciate it.
> > i am forced to use getopt, so i cant use something good like optparse
>
> > pass
The documentation leaves lack for want, especially the examples.
On Tue, Feb 10, 2009 at 5:25 PM, John Machin wrote:
> On Feb 11, 12:12 pm, Matthew Sacks wrote:
>> if anyone can have a look at this code and offer suggestions i would
>> appreciate it.
>> i am forced to use
On Feb 11, 12:12 pm, Matthew Sacks wrote:
> if anyone can have a look at this code and offer suggestions i would
> appreciate it.
> i am forced to use getopt, so i cant use something good like optparse
>
> passedArgs = sys.argv[1:]
> optlist, args = getopt.get
if anyone can have a look at this code and offer suggestions i would
appreciate it.
i am forced to use getopt, so i cant use something good like optparse
passedArgs = sys.argv[1:]
optlist, args = getopt.getopt(str(passedArgs), ["connectPassword=",
"adminServerURL=", "acti
On 2009-02-10 17:32, Matthew Sacks wrote:
its a debian package. 2.5
importing optparse works with interactive python, but not through the
jython interpreter i an using.
Ah, yes. The current version of Jython is still based off of Python 2.2 whereas
optparse was introduced in Python 2.3.
is
its a debian package. 2.5
importing optparse works with interactive python, but not through the
jython interpreter i an using.
is there some way i can force the import based on the the absolute
path to the module?
On Tue, Feb 10, 2009 at 1:48 PM, Robert Kern wrote:
> On 2009-02-10 15:42, Matthe
On 2009-02-10 15:42, Matthew Sacks wrote:
it seems as if optparse isn't in my standard library.
How did you install your Python? It has been part of the standard library for a
very long time.
is there a way to add a lib like ruby gems?
http://docs.python.org/install/index.html
But optpar
it seems as if optparse isn't in my standard library.
is there a way to add a lib like ruby gems?
On Tue, Feb 10, 2009 at 1:38 PM, Tim Chase
wrote:
> Matthew Sacks wrote:
>>
>> does anyone have any arguments against optparse vs getopt
>
> I've found that the
Matthew Sacks wrote:
does anyone have any arguments against optparse vs getopt
I've found that the optparse module beats getopt on *every*
aspect except in the event that you have experience with the C
getopt libraries *and* just want something that behaves like
those libraries. Opt
On 2009-02-10 15:06, Matthew Sacks wrote:
does anyone have any arguments against optparse vs getopt
As the getopt docs say: "A more convenient, flexible, and powerful alternative
is the optparse module."
I have found all three statements to be true.
But I've found argp
does anyone have any arguments against optparse vs getopt
--
http://mail.python.org/mailman/listinfo/python-list
Hi List,
I am getting an index out of range error when trying to parse with getopt.
Probably something simple. Any suggestions are appreciated
optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=',
'adminServerURL=', 'action=', 'targets=
You could use http://docs.python.org/lib/module-optparse.html
--
http://mail.python.org/mailman/listinfo/python-list
So the return value from getopt.getopt() is a list of tuples, e.g.
>>> import getopt
>>> opts = getopt.getopt('-a 1 -b 2 -a 3'.split(), 'a:b:')[0]; opts
[('-a', '1'), ('-b', '2'), ('-a', '3')]
what
On Sep 29, 7:58 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Carl Banks <[EMAIL PROTECTED]> writes:
> > On Sep 28, 6:19 pm, Ben Finney <[EMAIL PROTECTED]>
> > wrote:
> > > Steven Bethard <[EMAIL PROTECTED]> writes:
> > > > A user shouldn't have to go out of their way to specify regular
> > > > numbe
Carl Banks <[EMAIL PROTECTED]> writes:
> On Sep 28, 6:19 pm, Ben Finney <[EMAIL PROTECTED]>
> wrote:
> > Steven Bethard <[EMAIL PROTECTED]> writes:
> > > A user shouldn't have to go out of their way to specify regular
> > > numbers on the command line, regardless of whether they're
> > > positive
On Sep 28, 6:19 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Steven Bethard <[EMAIL PROTECTED]> writes:
> > A user shouldn't have to go out of their way to specify regular
> > numbers on the command line, regardless of whether they're positive
> > or negative.
>
> A user shouldn't have to go out of
Steven Bethard <[EMAIL PROTECTED]> writes:
> A user shouldn't have to go out of their way to specify regular
> numbers on the command line, regardless of whether they're positive
> or negative.
A user shouldn't have to go out of their way to know whether what they
type on a command line will be t
Casey wrote:
> Ben Finney wrote:
>> I believe they shouldn't because the established interface is that a
>> hyphen always introduced an option unless (for those programs that
>> support it) a '--' option is used, as discussed.
>
> Not "THE" established interface; "AN" established interface. There
921" as a negative integer and not abort the program with some
obscure error about option 921 not being known.
>
> > But I think it is a simple and clever hack and still allows getopt
> > or optparse to function normally.
>
> Except that they *don't* function normall
Ben Finney wrote:
> Casey <[EMAIL PROTECTED]> writes:
>
>> Well, it is a hack and certainly not as clean as having getopt or
>> optparse handle this natively (which I believe they should).
>
> I believe they shouldn't because the established interface is t
Casey <[EMAIL PROTECTED]> writes:
> Well, it is a hack and certainly not as clean as having getopt or
> optparse handle this natively (which I believe they should).
I believe they shouldn't because the established interface is that a
hyphen always introduced an option unless (f
On Sep 27, 7:57 pm, Neal Becker <[EMAIL PROTECTED]> wrote:
> One person's "brilliant" is another's "kludge".
Well, it is a hack and certainly not as clean as having getopt or
optparse handle this natively (which I believe they should). But I
think it is a
Steven Bethard <[EMAIL PROTECTED]> writes:
> In most cases, argparse (http://argparse.python-hosting.com/)
> supports negative numbers right out of the box, with no need to use
> '--':
>
> >>> import argparse
> >>> parser = argparse.ArgumentParser()
> >>> parser.add_argument('-a', typ
Casey wrote:
> On Sep 27, 2:21 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote:
>> If you can access the argument list manually, you could scan it for a
>> negative integer, and then insert a '--' argument before that,
>> if needed, before passing
Casey wrote:
> Is there an easy way to use getopt and still allow negative numbers as
> args?
[snip]
> Alternatively, does optparse handle this?
Peter Otten wrote:
> optparse can handle options with a negative int value; "--" can be used to
> signal that no
On Sep 27, 2:21 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote:
> If you can access the argument list manually, you could scan it for a
> negative integer,
> and then insert a '--' argument before that, if needed, before passing it to
> getopt/optparse.
&
On Sep 27, 2:21 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote:
> If you can access the argument list manually, you could scan it for a
> negative integer, and then insert a '--' argument before that,
> if needed, before passing it to getopt/optparse. Then
On Sep 27, 1:34 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
...
> >>> args
>
> ['-123']
>
> Without the "--" arg you will get an error:
>
> >>> parser.parse_args(["-123"])
>
> Usage: [options]
>
> : error: no such option: -1
> $
>
> Peter
Passing -a-123 works
>>> options, args = parser.parse_args(
If you can access the argument list manually, you could scan it for a negative
integer, and then insert a '--' argument before that, if needed, before passing
it to getopt/optparse. Then you wouldn't have to worry about it on the command
line.
Cheers,
Cliff
On Thu, Sep 27
Casey wrote:
> On Sep 27, 1:34 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
>> optparse can handle options with a negative int value; "--" can be used
>> to signal that no more options will follow:
>
> Thanks, Peter. getopt supports the POSIX "--&quo
On Sep 27, 1:34 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> optparse can handle options with a negative int value; "--" can be used to
> signal that no more options will follow:
Thanks, Peter. getopt supports the POSIX "--" end of options
indicator as well, but
Casey wrote:
> Is there an easy way to use getopt and still allow negative numbers as
> args? I can easily write a workaround (pre-process the tail end of
> the arguments, stripping off any non-options including negative
> numbers into a separate sequence and ignore the (now empt
Is there an easy way to use getopt and still allow negative numbers as
args? I can easily write a workaround (pre-process the tail end of
the arguments, stripping off any non-options including negative
numbers into a separate sequence and ignore the (now empty) args list
returned by getopt, but
Rocky Zhou wrote:
> .dirs .files is just a snapshot of the current directories, which can
> be used to delete-outdated files when restoring. Here I used absolute
> path by using tar's -P parameter. When fs_rstore, it will do this:
> command = "tar -xpz -P -f %s.tgz -T %s" % (archive, self.t_files)
Well, I think I must have more explanation on my script. The script's
usage is like this:
~# fs_backup
Lack of backup identity name
program usage: fs_backup [OPTIONS] $identity
OPTIONS:
-a|--append [t/x[L]:$path, append 1 dir or file to $identity
t/x: include/exclude list, as -T/-X
Rocky Zhou wrote:
> I wonder is there any way to make the wrapper program can wrap options
> && arguments for the the subprocess/command the wrapper will
> execute? by getopt or optparse module?
[snip]
> I need this because I now have finished a fs_backup script written
I wonder is there any way to make the wrapper program can wrap options
&& arguments for the the subprocess/command the wrapper will
execute? by getopt or optparse module?
This is something like the shell script like this:
optwrap=""
while [ $# -gt 0 ]; do
case $1 in
thanks a lot that helped...
Fredrik Lundh wrote:
> "prashant" wrote:
>
> > I am actually using Cygwin to run a python script.
> > I have python 2.5 installed. But when i ran the command mentioned by
> > you... I see that it is looking in the wrong directories... how can i
> > change these look up
"prashant" wrote:
> I am actually using Cygwin to run a python script.
> I have python 2.5 installed. But when i ran the command mentioned by
> you... I see that it is looking in the wrong directories... how can i
> change these look up directories?
is PYTHONHOME perhaps set to the wrong thing?
te:
>
> >I am running a python script which has the line
> >
> > import getopt, sys, os, re, string
> >
> > And i get the error
> >
> > ImportError: No module named getopt
> >
> > Could you please point out a possible solution for
"prashant" wrote:
>I am running a python script which has the line
>
> import getopt, sys, os, re, string
>
> And i get the error
>
> ImportError: No module named getopt
>
> Could you please point out a possible solution for this?
looks like a broken ins
I am running a python script which has the line
import getopt, sys, os, re, string
And i get the error
ImportError: No module named getopt
Could you please point out a possible solution for this?
--
http://mail.python.org/mailman/listinfo/python-list
Daniel> getopt.GetoptError: option --imageDir requires argument
Which is precisely what the getopt module should do.
Daniel> Is there any method in getopt or Python that I could easily
Daniel> check the validity of each command line input parameter?
Getopt already did the
Hello all:
I am using getopt package in Python and found a problem that I can not
figure out an easy to do .
// Correct input
D:\>python AddArrowOnImage.py --imageDir=c:/
// Incorrect input
D:\>python AddArrowOnImage.py --imageDi
Traceback (most recent call last):
File "AddArro
On Mon, 19 Dec 2005, [EMAIL PROTECTED] wrote:
> I want to be able to do something like:
>
> myscript.py * -o outputfile
>
> and then have the shell expand the * as usual, perhaps to hundreds of
> filenames. But as far as I can see, getopt can only get one argument
> wit
ls, the shell will
already have expanded the * and myscript.py will never see the asterisk.
> But as far as I can see, getopt can only get one argument
> with each option.
The getopt module has two main functions you probably want to call.
getopt.getopt expects options like -o arg follow
On Mon, 19 Dec 2005 02:29:41 -0800, [EMAIL PROTECTED] wrote:
> I want to be able to do something like:
>
> myscript.py * -o outputfile
>
> and then have the shell expand the * as usual, perhaps to hundreds of
> filenames. But as far as I can see, getopt can only get one ar
On 19 Dec 2005 02:29:41 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> I want to be able to do something like:
>
> myscript.py * -o outputfile
>
> and then have the shell expand the * as usual, perhaps to hundreds of
> filenames. But as far as I can see, getopt c
I want to be able to do something like:
myscript.py * -o outputfile
and then have the shell expand the * as usual, perhaps to hundreds of
filenames. But as far as I can see, getopt can only get one argument
with each option. In the above case, there isn't even an option string
before the *
On Oct 03, M.N.A.Smadi wrote:
> It is not clear to me if i can define `mandatory' options? That sounds
> strange but let say that the command `requires ' a value for -z or
> --zoo (either or should be find but one and only one of them MUST be
> present). Can i do that with resorting to using if st
It is not clear to me if i can define `mandatory' options? That sounds
strange but let say that the command `requires ' a value for -z or --zoo
(either or should be find but one and only one of them MUST be
present). Can i do that with resorting to using if statements?
thanks
moe smadi
Fredrik
M.N.A.Smadi wrote:
> I have a perl script that I need to port to python. The script takes
> input from the command line. Is there a standard way of processing
> command line arguments based on the -flag preceeding the argument?
Yes.
# pydoc getopt
Help on module getopt:
NAME
"M.N.A.Smadi" wrote:
> I have a perl script that I need to port to python. The script takes
> input from the command line. Is there a standard way of processing
> command line arguments based on the -flag preceeding the argument?
http://docs.python.org/lib/module-getopt.html
http://docs.python.o
hi;
I have a perl script that I need to port to python. The script takes
input from the command line. Is there a standard way of processing
command line arguments based on the -flag preceeding the argument?
thanks
moe smadi
--
http://mail.python.org/mailman/listinfo/python-list
Frans Englich wrote:
On Wednesday 15 December 2004 14:07, Diez B. Roggisch wrote:
In my use of getopt.getopt, I would like to make a certain parameter
mandatory. I know how to specify such that a parameter must have a value
if it's specified, but I also want to make the parameter itself
mandatory(c
On Wednesday 15 December 2004 14:07, Diez B. Roggisch wrote:
> > In my use of getopt.getopt, I would like to make a certain parameter
> > mandatory. I know how to specify such that a parameter must have a value
> > if it's specified, but I also want to make the parameter itself
> > mandatory(combin
In <[EMAIL PROTECTED]>, Frans Englich
wrote:
>> > In my use of getopt.getopt, I would like to make a certain parameter
>> > mandatory.
>>
>> Isn't a *mandatory option* a contradiction? Why don't you turn it into an
>> argument? You already called it argument in the subject of your post.
>
> I p
On Wednesday 15 December 2004 20:12, Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, Frans Englich
>
> wrote:
> > Hello,
> >
> > In my use of getopt.getopt, I would like to make a certain parameter
> > mandatory.
>
> Isn't a *mandatory option* a contradiction? Why don't you turn it into
In <[EMAIL PROTECTED]>, Frans Englich
wrote:
>
> Hello,
>
> In my use of getopt.getopt, I would like to make a certain parameter
> mandatory.
Isn't a *mandatory option* a contradiction? Why don't you turn it into an
argument? You already called it argument in the subject of your post.
Ciao,
> In my use of getopt.getopt, I would like to make a certain parameter
> mandatory. I know how to specify such that a parameter must have a value
> if it's specified, but I also want to make the parameter itself
> mandatory(combined with a mandatory value, the result is that the user
> must specify
sys.exit(common.exitCodes["parameter"])
> Is it possible?
afaik, getopt doesn't have any built-in validation features; Python's got
more than enough of them already...
--
http://mail.python.org/mailman/listinfo/python-list
if opt in ("-V", "--version"):
print "Version:", common.version["Runner"]
sys.exit()
# TODO Can't getopt make an argument mandatory?
if configurationFile == "":
print "Yo
92 matches
Mail list logo