473,799 Members | 3,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing argument to script

hi

if i have a string like this

"ABCE-123456 ABC_DEF_Suggest (abc def ghi).txt"

that needs to be passed to a python script
and i wanted to get the words inside the brackets after i passed this
string. I did a re
something like

thestring = sys.argv[1:]
pat = re.compile(r".* \((.*)\)\.txt$" )
if pat.search(thes tring):
words = pat.search(thes tring).group(1)

but it doesn't return anything for words variable.
When i specifically define the string inside the python script , it
works

thestring = "ABCE-123456 ABC_DEF_Suggest (abc def ghi).txt"

I also tried str(thestring) but also did not work
what is wrong with the argument passing?

thanks

Apr 7 '06 #1
3 2042
> hi

if i have a string like this

"ABCE-123456 ABC_DEF_Suggest (abc def ghi).txt"

that needs to be passed to a python script
and i wanted to get the words inside the brackets after i passed this
string. I did a re
something like

thestring = sys.argv[1:]
pat = re.compile(r".* \((.*)\)\.txt$" )
if pat.search(thes tring):
words = pat.search(thes tring).group(1)

but it doesn't return anything for words variable.
When i specifically define the string inside the python script , it
works

thestring = "ABCE-123456 ABC_DEF_Suggest (abc def ghi).txt"

I also tried str(thestring) but also did not work
what is wrong with the argument passing?


Are you doing this on Linux or Windows?

If you execute your script from the command line on Linux you need to
enclose it in quotation marks otherwise your shell will interfere. So
you need to invoke your program as

python yourscript.py "ABCE-123456 ABC_DEF_Suggest (abc def ghi).txt"

and need to refer to the argument as sys.argv[1:][0], so yourscript.py should be

import sys, re
thestring = sys.argv[1:][0]
pat = re.compile(r".* \((.*)\)\.txt$" )
if pat.search(thes tring):
words = pat.search(thes tring).group(1)
print words

I'm not sure what you need to do on Windows though.
Apr 7 '06 #2
Works for me.

I get "abc def ghi" using your script on Windows XP and ActiveState
Python 2.4.3

rd

Apr 7 '06 #3
Daniel Nogradi <no*****@gmail. com> wrote:
If you execute your script from the command line on Linux you need to
enclose it in quotation marks otherwise your shell will interfere. So
you need to invoke your program as

python yourscript.py "ABCE-123456 ABC_DEF_Suggest (abc def ghi).txt"
Same is true on Windows. It's just that some commands magically convert
filenames with spaces into a single argument if you don't quote them.
(Compare, for instance, cd \Program Files with dir \Program Files .)
and need to refer to the argument as sys.argv[1:][0]


That's an interesting way of spelling sys.argv[1] .

--
\S -- si***@chiark.gr eenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Apr 7 '06 #4

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

Similar topics

8
3969
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer http://sourceforge.net/projects/cpp-perfometer http://alexvn.freeservers.com/s1/perfometer.html
3
14955
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);
11
3103
by: comp.lang.php | last post by:
On one of my sites, I have a TCL CGI script that has a security hole in spite of it having effective server-side validation (the fact that it's CGI IS its security hole). The front end is a PHP script, and I am writing server-side validation onto it, however, it is required to redirect to the TCL CGI script because only a CGI script has the ability to access a group-accessible XML script on the back end. I had to take the whole thing...
6
5584
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not getting. i have had a look on the web and found some examples, but i cant see why my code does not...
5
9858
by: moni | last post by:
Hi.. I am trying to use javascript for google maps display. If I call the javascript function from my aspx file I use: <input type="text" id="addresstext" value="Huntington Avenue, Boston, MA" name="yourName" style="width: 287px" />
2
17306
by: alokvping | last post by:
I have written a perl script in which i have mentioned 4 $ARGV, $ARGV,...etc . While passing an argument to the script i want to pass arguments as strings. Like one argument value should contain n number of characters and strings, eg $ARGV = "This is a script" like wise i want all the arguments to be passed on. Can anyone let me know hows that possible? Or is there any other function to be used for the same?
5
4499
by: kyosohma | last post by:
I have created what amounts to a simple GUI email sending program using Python + wxPython. I have modified the mailto registration in the Windows Registry so that it launches the script when someone clicks on someone's email link in a web page. While this works great if I create a convoluted path command as the registry entry and pass in the email argument to the script, it doesn't work at all if I turn my python file into an exe using...
0
1499
by: mag | last post by:
I have a make file that executes a perl script that takes PERL as an eval. The script executes the eval() function via an arguement to the script like this: target: script $(ARGUMENT) However when I attempt to pass something like this
0
9546
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,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
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
10030
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...
1
7570
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...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.