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


Groups > comp.lang.python > #85214

Re: meaning of: line, =

Path csiph.com!usenet.pasdenom.info!news.franciliens.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.028
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'line:': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; '1:08': 0.16; 'ast': 0.16; 'comma': 0.16; 'command:': 0.16; 'expecting': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "function's": 0.16; 'iterable': 0.16; 'unpack': 0.16; 'why,': 0.16; 'wrote:': 0.18; 'slightly': 0.19; 'thu,': 0.19; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'work.': 0.31; 'yields': 0.31; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'returning': 0.36; 'url:org': 0.36; 'here:': 0.62; 'dont': 0.67; 'line,': 0.68; 'unusual': 0.74; 'saw': 0.77; '2015': 0.84; 'compare:': 0.84; 'same,': 0.91; 'thing,': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=5nQbjD7r+m+YJivNDWlB7ZbhytZ1fhSxzuiCguG2lZA=; b=dPwW+oi7FIhTMjJfv9rJ5rlYa/6O6WwRG1U/ZvqaJ2pnBhnOqUlifkSednsiSzzFaZ H9EqG8/RIXk6OKBhj0V15lv0VzFv+HUlgDZXY8cjdkvd61ZYBd0gnzWftHMD1DQLQJlu t1qpKV8u/p3/aTLxERqEsfp5bHPF7YEMmQwaC52p4mqeGuH1ut6hv91a6rD7dUbuOKRI uEXz9ugYCThigkQludcaIEWuB153I0fjr+gp4JRPJtKqbfP53lTyJRnY8Dbivf+HFovJ 4Rbn0opfJS/amJy5F9GX5RxJcMrBaoWAm+Cb8d6/d+RrFtsxFK6sYX6E2ZPX9+daUUWZ IwRQ==
MIME-Version 1.0
X-Received by 10.107.158.146 with SMTP id h140mr34609929ioe.27.1423059892980; Wed, 04 Feb 2015 06:24:52 -0800 (PST)
In-Reply-To <54d227ef$0$3292$426a74cc@news.free.fr>
References <54d227ef$0$3292$426a74cc@news.free.fr>
Date Thu, 5 Feb 2015 01:24:52 +1100
Subject Re: meaning of: line, =
From Chris Angelico <rosuav@gmail.com>
Cc "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.18462.1423059895.18130.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1423059895 news.xs4all.nl 2877 [2001:888:2000:d::a6]:36219
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:85214

Show key headers only | View raw


On Thu, Feb 5, 2015 at 1:08 AM, ast <nomail@invalid.com> wrote:
> I dont understand why there is a comma just after line in the following
> command:
>
> line, = plt.plot(x, np.sin(x), '--', linewidth=2)
>
>
> I never saw that before
>
> Found here:
> http://matplotlib.org/examples/lines_bars_and_markers/line_demo_dash_control.html
>

That's a slightly unusual form of unpacking. Compare:

def get_values():
    return 5, 7, 2

x, y, z = get_values()

This is like "x = 5; y = 7; z = 2", because it unpacks the function's
return value into those three targets.

What you have is exactly the same, except that it has only one target.
So it's expecting plt.plot() to return an iterable with exactly one
thing in it, and it'll unpack it and put that thing into line:

def get_packaged_value():
    return [42]

x, = get_packaged_value()

This is equivalent to "x = 42". I don't know matplotlib, so I don't
know what it's returning or why, but as long as it's iterable and
yields exactly one thing, this will work.

ChrisA

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


Thread

meaning of:  line, = "ast" <nomail@invalid.com> - 2015-02-04 15:08 +0100
  Re: meaning of: line, = leo kirotawa <kirotawa@gmail.com> - 2015-02-04 12:22 -0200
  Re: meaning of: line, = Chris Angelico <rosuav@gmail.com> - 2015-02-05 01:24 +1100
  Re: meaning of:  line, = "ast" <nomail@invalid.com> - 2015-02-05 09:28 +0100

csiph-web