0

Hi all.
I'm wondering if it is possible to pass formatted strings to function arguments.

I'm doing something like this:
OUT_TASK = "Task_{id1}, FUNCTION, {id2}, task{id3}_types, None"
t = Task(OUT_TASK.format(id1=i, id2='doNothing', id3=i))

Any clues are much appreciated. Any other means for doing variable arguments are of interest.

Edited by Empireryan

3
Contributors
2
Replies
44
Views
4 Years
Discussion Span
Last Post by snippsat
0

What is the purpose of this?
Anyway, you can parse the input string in TASK.init method.

If you want variable arguments, then you should take a look at the *args, **kwargs function definitions.
See

1

What is the purpose of this?

I wonder about this to.

I'm wondering if it is possible to pass formatted strings to function arguments.

Yes a formatted string is still a string and function can take most datatypes.
I dont see the point of splitting the format option into two part.

def task(arg):
    return arg

#Why not one part,if string is to long escape with \
OUT_TASK = "Task_{id1}, FUNCTION, {id2}, task{id3}_types, None"\
.format(id1=100, id2='doNothing', id3=300)

print task(OUT_TASK)

Can do something like this with *args,but ugly and hard to understand.

def task(*args):
    return args[1]

OUT_TASK = "Task_{id1}, FUNCTION, {id2}, task{id3}_types, None"
print task(OUT_TASK, OUT_TASK.format(id1=100, id2='doNothing', id3=300))

Edited by snippsat

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.