Hallo, patco hat gesagt: // patco wrote:
May be you could be in some help with a script I am trying to do for replacing spaces in a string.
I've tried this:
def space2_(*args): """replaces space with _"""
return reduce(args.replace(' ','_'), args)
You could do:
args = [x.replace(" ","_") for x in args]
This is called "list comprehension" and is very useful.
But if you want to join the elements making up args instead, for example if args is a list coming in through an inlet in [pyext] , you should use join like:
"_".join(args)
Here's the difference of both:
args = ("a", "b", "c d") [x.replace(" ", "_") for x in args]
['a', 'b', 'c_d']
"_".join(args)
'a_b_c d'
Frank Barknecht _ ______footils.org_ __goto10.org__