473,695 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing arguments like -JOB

I am porting a script from Korn Shell to python and want to pass named
parameters like -JOB 123456 -DIR mydir

I can get it to work passing --JOB and --DIR but not -JOB and -DIR

Any ideas?

Current code :

try:
options, xarguments = getopt.getopt(s ys.argv[1:], '', ['JOB=',
'DIR=', 'ERR=', 'GRP=', 'TST=', 'JNM=', 'DAT=',])
except getopt.error:
print 'Error: You tried to use an unknown option'
sys.exit(1)
JOB = ''
for o,a in options[:]:
print 'here2'
print o
print a
if o == '--JOB':
JOB = a
print JOB
Jul 18 '05 #1
2 1570
John Leslie wrote:
I am porting a script from Korn Shell to python and want to pass named
parameters like -JOB 123456 -DIR mydir

I can get it to work passing --JOB and --DIR but not -JOB and -DIR

Any ideas?

Unfortunately (for you), I think you will find most or all of the existing
ways to parse command line options in Python follow the POSIX convention
for arguments, i.e. single letter options are introduced with a single -
and multi-letter options are introduced with --.

My guess is that if you can't change whatever generates the command lines
to conform to this convention you will have to write your own code to do
the processing.

Alternatively you might get by by hacking the command line in your Python
code:

for i, opt in enumerate(sys.a rgv):
if opt in ('-JOB','-DIR', '-ERR', '-GRP', '-TST', '-JNM', '-DAT'):
sys.argv[i] = '-'+opt

... and then use getopt or optparse here ...

It isn't pretty, but so long as those values don't turn up elsewhere in the
command line it ought to work.
Jul 18 '05 #2
Thanks...it worked perfectly.
Brilliant!!

JL
Duncan Booth <du**********@i nvalid.invalid> wrote in message news:<Xn******* *************** *****@127.0.0.1 >...
John Leslie wrote:
I am porting a script from Korn Shell to python and want to pass named
parameters like -JOB 123456 -DIR mydir

I can get it to work passing --JOB and --DIR but not -JOB and -DIR

Any ideas?

Unfortunately (for you), I think you will find most or all of the existing
ways to parse command line options in Python follow the POSIX convention
for arguments, i.e. single letter options are introduced with a single -
and multi-letter options are introduced with --.

My guess is that if you can't change whatever generates the command lines
to conform to this convention you will have to write your own code to do
the processing.

Alternatively you might get by by hacking the command line in your Python
code:

for i, opt in enumerate(sys.a rgv):
if opt in ('-JOB','-DIR', '-ERR', '-GRP', '-TST', '-JNM', '-DAT'):
sys.argv[i] = '-'+opt

... and then use getopt or optparse here ...

It isn't pretty, but so long as those values don't turn up elsewhere in the
command line it ought to work.

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
49575
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. The question is about best practices for passing parameters to an event function. I have, say, the following HTML:
3
14938
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
7
2858
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
39
7646
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down indicate: a) That I don't know enough b) Passing arguments by ref is bad
3
3931
by: Mantorok | last post by:
Hi all I'm pretty new to ASP.Net, is it possible to pass arguments (maybe objects too) to web forms without using a querystring in the URL? Thanks Kev
4
1963
by: Justine | last post by:
Can anyone help? e.g. when you open a vb project property page, in "Configuration Properties" You will see "Command line arguments" in "Start Options". Does anyone knows how to find a way to do arguments passing. Thank you. ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
6
3946
by: Max | last post by:
Last time I tried to explain this on another forum it didn't go too well, so I'll try my best and if you know what I'm talking about then please tell me how to do this. I have a class, inside I have some public functions and private variables. Inside the class I also have a declaration of a new form object. One of the functions of the class takes that form object, shows it with showdialog and the basically passes the control to the form...
7
1965
by: Bonzo | last post by:
>From within a function, I want to pass a/some parameters to another function, AND all arguments, passed into this function. e.g. function firstFunction(){ //this function may have been passed, 0, 1, or n arguments... ... //call another function... var someCalculatedValue = 'someValue';
2
4242
by: william.w.oneill | last post by:
I have an application that takes a few command line parameters. As recommended by others in this group, I'm using a named mutex to ensure that only one instance of the application is running. My question is how to elegantly pass a command line parameter from Instance_B to Instance_A where Instance_A was running prior to Instance_B. For example, the user can launch the program by passing a file name as a command line argument. The program...
0
8567
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7660
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6490
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4340
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1973
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.