Hi,

Forgive me if this is a silly question as I am newbie to python. I have to pass a string that contains a few spaces to a python script. How can I get it to read as one argument?

Thanks...

Recommended Answers

All 4 Replies

Hi,

Forgive me if this is a silly question as I am newbie to python. I have to pass a string that contains a few spaces to a python script. How can I get it to read as one argument?

Thanks...

If you are executing your script from the command line, you should include the string in quotes

python myscript.py "this is the argument with spaces"

This problem has nothing to do with python. It has to do with the way the terminal reads command lines on your platform.

Thanks for the quick response Gribouillis. The problem is I am running the python script against WebSphere wsadmin.sh being all called from another unix script and I tried using single and double quotes with no luck.
I ended up saving the string to a temp file from unix and reading the file in python script.

If there is a better solution, I would appreciate some guidance.

Can you post values of parameters before call and error message and your current solution, don't forget code tags.

def myfunc(a,b,c,d):
    print a
    print b
    print c
    print d

a=('here','is' ,'some', 'strings')

b= " ".join(a)

print b

## one list to many parameters
myfunc(*a)

Thanks for the quick response Gribouillis. The problem is I am running the python script against WebSphere wsadmin.sh being all called from another unix script and I tried using single and double quotes with no luck.
I ended up saving the string to a temp file from unix and reading the file in python script.

If there is a better solution, I would appreciate some guidance.

There is probably a better solution, but I think you should post the lines of code where the python script is invoked. Is it shell code ? python code ? Is the string argument a constant string or a variable string, etc..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.