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


Groups > comp.lang.python > #102030

Re: import locale and print range on same line

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: import locale and print range on same line
Date 2016-01-23 12:36 +0200
Organization A noiseless patient Spider
Message-ID <87zivw37ml.fsf@elektro.pacujo.net> (permalink)
References <2bda88dd-82e3-4e43-b49c-3945a0befdc2@googlegroups.com>

Show all headers | View raw


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

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