Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68282

Re: How do we pass default argument value to create thread object?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <zachary.ware@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'syntax': 0.04; 'arguments': 0.09; 'subject:create': 0.09; 'subject:How': 0.10; 'def': 0.12; 'thread': 0.14; '2],': 0.16; 'arg2,': 0.16; 'argument:': 0.16; 'subject:default': 0.16; 'subject:object': 0.16; 'subject:pass': 0.16; 'syntaxerror:': 0.16; 'threads.': 0.16; 'url:thread': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'wed,': 0.18; 'import': 0.22; 'cc:addr:gmail.com': 0.22; 'to:name:python-list@python.org': 0.22; 'creating': 0.23; 'compilation': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '"",': 0.31; 'info.': 0.31; 'file': 0.32; 'class': 0.32; 'url:python': 0.33; 'received:google.com': 0.35; 'subject:?': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'url:library': 0.38; 'to:addr:python-list': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'skip:- 60': 0.39; 'how': 0.40; 'hope': 0.61; 'url:3': 0.61; 'more': 0.64; 'mar': 0.68; 'invalid': 0.68; 'default': 0.69; 'url:4': 0.69
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=0sfRKCMtKJdkJHRTl0PgBGmwIgN/kgDeFFoT/ny3RHc=; b=hfKPr4saKI9RzeULr7M6WZ5bWobcNHHNZZ8O/KbQodpnNG8jJw0Z8XX47zTziGaFzE r75N7jPULf+8XgBq36HE0xH+0u0cw6uaXWNKuUhKUH6ihGpAyPviNyIvNfqCf59QL0lB vw886oV2UIhzg3mJA2JVplR256CcobEMI1xTLR0wUVKddxmRMIlGYkIj/NL7PHXmrJnW CgHkYjbBPCm9tlzieKmZmTcGr1vYDTpEdGYBqBolTyjySmydJVKVmCorRE+FGOIiXKMn NsvFwlpGV1EOdLWs9vMVz6CJeli41ZdHmmV8zAbxaEWq637zrRqqUVrJiwDRFzOmoEAK m3hA==
X-Received by 10.50.141.199 with SMTP id rq7mr4051762igb.11.1394633657519; Wed, 12 Mar 2014 07:14:17 -0700 (PDT)
MIME-Version 1.0
Sender zachary.ware@gmail.com
In-Reply-To <CAJV9OM_9tg5y5cC_zrzSZ4RVF8VvxqOxE-uhzyKusWPeeC1sxg@mail.gmail.com>
References <CAJV9OM_9tg5y5cC_zrzSZ4RVF8VvxqOxE-uhzyKusWPeeC1sxg@mail.gmail.com>
From Zachary Ware <zachary.ware+pylist@gmail.com>
Date Wed, 12 Mar 2014 09:12:39 -0500
X-Google-Sender-Auth 9rsdM88OjAaLC6ALBmltLDPgi-8
Subject Re: How do we pass default argument value to create thread object?
To "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8091.1394633665.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1394633665 news.xs4all.nl 2936 [2001:888:2000:d::a6]:33334
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:68282

Show key headers only | View raw


On Wed, Mar 12, 2014 at 8:09 AM, Piyush Verma <114piyush@gmail.com> wrote:
> 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?

Use the 'kwargs' argument:

   thread = threading.Thread(target=Fun, args=[1, 2], kwargs={'arg3': "val"})

See http://docs.python.org/3.4/library/threading#threading.Thread for more info.

Hope this helps,
-- 
Zach

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How do we pass default argument value to create thread object? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-03-12 09:12 -0500

csiph-web