Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68281 > unrolled thread
| Started by | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| First post | 2014-03-12 14:51 +0100 |
| Last post | 2014-03-12 14:51 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
Re: How do we pass default argument value to create thread object? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2014-03-12 14:51 +0100
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| Date | 2014-03-12 14:51 +0100 |
| Subject | Re: How do we pass default argument value to create thread object? |
| Message-ID | <mailman.8090.1394632343.18130.python-list@python.org> |
----- Original Message -----
> Hi,
> I am using Thread class to create threads.
> <CODE>
> thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"])
> thread.start()
> </CODE>
> This code is throwing compilation error(Ipython).
> In [19]: import threading
> In [20]: def Fun(agr1, arg2, arg3=None):
> ....: pass
> ....:
> In [21]: thread = threading.Thread(target=Fun, args=[arg1, arg2,
> arg3="val" ])
> ------------------------------------------------------------
> File "<ipython console>", line 1
> thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"])
> ^
> SyntaxError: invalid syntax
> How do we pass the value to default arguments while creating thread
> object?
> Regards,
> ~Piyush
> Facebook Twitter
Hi,
try something like
thread = threading.Thread(target=Fun, args=("val1", "val2"), kwargs={"arg3":"val3"})
This will call
Fun("val1", "val2", arg3="val3")
Browse the python tutorial for details on arguments and keyword arguments.
Cheers,
JM
-- IMPORTANT NOTICE:
The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Back to top | Article view | comp.lang.python
csiph-web