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


Groups > comp.lang.python > #102032

Re: import locale and print range on same line

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Vlastimil Brom <vlastimil.brom@gmail.com>
Newsgroups comp.lang.python
Subject Re: import locale and print range on same line
Date Sat, 23 Jan 2016 12:12:41 +0100
Lines 40
Message-ID <mailman.175.1453547570.15297.python-list@python.org> (permalink)
References <2bda88dd-82e3-4e43-b49c-3945a0befdc2@googlegroups.com> <87zivw37ml.fsf@elektro.pacujo.net>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de Pv4HJBUNq7Nuu0k3J2nFVwT2UvLudCA8lFr72O4RRcdQ==
Return-Path <vlastimil.brom@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'skip:[ 20': 0.03; 'error:': 0.05; 'indicating': 0.05; 'locale': 0.07; 'ignoring': 0.09; 'subject:same': 0.09; 'syntax': 0.13; '1))': 0.16; 'circumvent': 0.16; 'definition.': 0.16; 'python),': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:import': 0.16; 'syntaxerror:': 0.16; 'skip:l 30': 0.18; "python's": 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; '(which': 0.26; 'separate': 0.27; 'message-id:@mail.gmail.com': 0.27; 'separated': 0.29; 'url:mailman': 0.30; 'code': 0.30; 'e.g.': 0.30; "can't": 0.32; 'statement': 0.32; 'url:python': 0.33; '"")': 0.33; 'url:listinfo': 0.34; 'list': 0.34; 'gives': 0.35; 'received:google.com': 0.35; 'next': 0.35; 'url:org': 0.36; 'created': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'skip:p 20': 0.38; 'someone': 0.38; 'hi,': 0.38; 'why': 0.39; 'rather': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'some': 0.40; 'url:3': 0.60; "'for'": 0.84; 'to:name:python': 0.84; 'url:reference': 0.91
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:to :content-type; bh=3s60ScCStfRH+VwA7loJbdwpV4yjdRLTURygfM4YS10=; b=JB8UZR82USX/UDl46hxRKQ7HldMoxc7g4Vg98KW3p3bkC2BDzb/8nEUWOf4OP4vQO7 VqsOEzlUz+2RRgK24UhnmpvuyYkKXIIQ0Vi2mEtMNx9n5OHz6Dh11WdTV9hKtgLjRqGD BWZV4KiAoKW+T999PfLiagGKCkPCW5TrzfZTfqfq990CuQwbiIJMJHzPPzOCzMeKonjN ltVfgCy0lygpkINA6aLNNM6AxEpsD1hhVYrnJuY/zXkVBfVDhYW+9zK3krax6d/JDrN4 XpVzJm85KS3wFIcQTvsfxu6cwtJG7Bn7PjfnvAyACMNBEJbwf2x5xxoCvazqrzd9T36g dcCw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=3s60ScCStfRH+VwA7loJbdwpV4yjdRLTURygfM4YS10=; b=gChmMURwrw6Ij7vTIN6uZFKm9qCelv5So43JicVGPwcfh0W08i8hW0qCSYHtVZ5n8U BEN4QU6Jn/5lCwWgthJQpQMUkeJY7bzEhNfiewKcE8mSe4/fhpGyCf/XRpoKK5BHaEMn gRvqZ4PT31FFibX6mKk6J7cBOxjOqQDJSoWhdRQy7bmSLWNrF/nxcfrManxJgkbu1+Hh noKylhCoNLPnVc4mKE8GQ/9x6AwFtUEIc+UAIi0V+qsGFqxrYF8NUAfjMygLfLl+ilyt dKDglMEtLi2F8MGpUV46abC5nzl9ThdxBueZ7dLPXxyVIj2fOFpf6Fy3jsWnJNxXSPck qkzA==
X-Gm-Message-State AG10YORYgHDrxOIR2y9oIwEGTYWG9ny9/wag7CTgxHS2tKm6n6+BIEApdJdYkcgpsFb9dACKlxx6psrI3f55gA==
X-Received by 10.25.155.81 with SMTP id d78mr2459412lfe.77.1453547562004; Sat, 23 Jan 2016 03:12:42 -0800 (PST)
In-Reply-To <87zivw37ml.fsf@elektro.pacujo.net>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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>
Xref csiph.com comp.lang.python:102032

Show key headers only | View raw


2016-01-23 11:36 GMT+01:00 Marko Rauhamaa <marko@pacujo.net>:
> raiwil@gmail.com:
>
>> Can someone tell me why next code doesn't work?
>>
>> import locale; locale.setlocale(locale.LC_ALL, ""); for i in
>> range(1,20,4): print(locale.format("%2f", i, 1))
>>
>> It gives an error: SyntaxError: invalid syntax --> indicating 'for'
>>
>> However I need to put the code on one single line.
>> When I separate them like below it works fine.
>>
>> import locale
>> locale.setlocale(locale.LC_ALL, "")
>> for i in range(1,20,4):
>>    print(locale.format("%2f", i, 1))
>
> The answer is in Python's syntax definition. Not everything is allowed
> on a single line.
>
> See <URL: https://docs.python.org/3/reference/grammar.html>
>
> Only small_stmt's can be separated by semicolons.
>
> A for statement is a compound_stmt, which is not a small_stmt.
>
>
> Marko
> --
> https://mail.python.org/mailman/listinfo/python-list

Hi,
if you realy can't use multiple lines (which is rather essencial for
python), you can circumvent this in some cases, e.g. using list
comprehension and ignoring the created list itself:
import locale; locale.setlocale(locale.LC_ALL, "");
[print(locale.format("%2f", i, 1)) for i in range(1,20,4)]

vbr

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


Thread

import locale and print range on same line raiwil@gmail.com - 2016-01-23 02:02 -0800
  Re: import locale and print range on same line Marko Rauhamaa <marko@pacujo.net> - 2016-01-23 12:36 +0200
    Re: import locale and print range on same line Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-01-23 12:12 +0100
      Re: import locale and print range on same line Ramo <raiwil@gmail.com> - 2016-01-23 03:57 -0800
  Re: import locale and print range on same line Steven D'Aprano <steve@pearwood.info> - 2016-01-24 00:07 +1100
    Re: import locale and print range on same line Chris Angelico <rosuav@gmail.com> - 2016-01-24 00:19 +1100
      Re: import locale and print range on same line Steven D'Aprano <steve@pearwood.info> - 2016-01-24 00:45 +1100
        Re: import locale and print range on same line Chris Angelico <rosuav@gmail.com> - 2016-01-24 00:58 +1100
          Re: import locale and print range on same line Ramo <raiwil@gmail.com> - 2016-01-23 06:03 -0800
            Re: import locale and print range on same line Chris Angelico <rosuav@gmail.com> - 2016-01-24 01:53 +1100
        Re: import locale and print range on same line Terry Reedy <tjreedy@udel.edu> - 2016-01-23 21:45 -0500
        Re: import locale and print range on same line Chris Angelico <rosuav@gmail.com> - 2016-01-24 13:51 +1100
        Re: import locale and print range on same line eryk sun <eryksun@gmail.com> - 2016-01-24 02:00 -0600

csiph-web