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


Groups > comp.lang.python > #102067

Re: import locale and print range on same line

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Terry Reedy <tjreedy@udel.edu>
Newsgroups comp.lang.python
Subject Re: import locale and print range on same line
Date Sat, 23 Jan 2016 21:45:29 -0500
Lines 59
Message-ID <mailman.193.1453603541.15297.python-list@python.org> (permalink)
References <2bda88dd-82e3-4e43-b49c-3945a0befdc2@googlegroups.com> <56a37b1e$0$1612$c3e8da3$5496439d@news.astraweb.com> <mailman.176.1453555148.15297.python-list@python.org> <56a383fa$0$1593$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmqw_C_ju784fPcgOq5zgggOaFR_mwqupzLZd8kN-DOjBw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de WsIeF//vGG/ZhQPa+9QpgAmN2jQbtRUbkRzQiBW9q4PQ==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'continuation': 0.07; '[1,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:same': 0.09; 'unexpected': 0.09; 'python': 0.10; 'jan': 0.11; "'hello": 0.16; '2016': 0.16; '24,': 0.16; 'preprocess': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'shells': 0.16; 'subject:import': 0.16; 'syntaxerror:': 0.16; 'tried:': 0.16; 'wrote:': 0.16; 'string': 0.17; '>>>': 0.20; 'windows': 0.20; 'so.': 0.22; '"",': 0.22; 'keyboard': 0.22; 'am,': 0.23; 'sat,': 0.23; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'chris': 0.26; 'not.': 0.27; 'skip:( 20': 0.28; 'character': 0.29; 'print': 0.30; 'that.': 0.30; 'code': 0.30; 'everyone': 0.31; 'knows': 0.32; 'maybe': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'file': 0.34; 'propose': 0.35; 'received:71': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'does': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'your': 0.60; 'email addr:gmail.com': 0.62; 'world': 0.64; '>>>>>': 0.66; 'prompt': 0.79; 'received:fios.verizon.net': 0.91; 'why?': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host pool-71-185-227-36.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1
In-Reply-To <CAPTjJmqw_C_ju784fPcgOq5zgggOaFR_mwqupzLZd8kN-DOjBw@mail.gmail.com>
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:102067

Show key headers only | View raw


On 1/23/2016 8:58 AM, Chris Angelico wrote:
> On Sun, Jan 24, 2016 at 12:45 AM, Steven D'Aprano <steve@pearwood.info> wrote:
>> On Sun, 24 Jan 2016 12:19 am, Chris Angelico wrote:
>>
>>> On Sun, Jan 24, 2016 at 12:07 AM, Steven D'Aprano <steve@pearwood.info>
>>> wrote:
>>>> On Sat, 23 Jan 2016 09:02 pm, raiwil@gmail.com wrote:
>>>>
>>>>> However I need to put the code on one single line.
>>>>
>>>> Why? Is the Enter key on your keyboard broken?
>>>
>>> Maybe it's for a python -c invocation.
>>
>>
>> [steve@ando ~]$ python -c "for i in range(5):
>>>      print 'hello world'
>>> "
>> hello world
>> hello world
>> hello world
>> hello world
>> hello world
>> [steve@ando ~]$
>
> Well, not everyone's shells are as awesome as bash...

Like Windows command prompt is not.  I tried:

C:\Users\Terry>python -c "for i in range(5):\n\tprint('hello world')"
   File "<string>", line 1
     for i in range(5):\n  print('hello world')
                                              ^
SyntaxError: unexpected character after line continuation character

-c does not preprocess the code string before executing.  I may propose 
that it do so.  However, Python is still pretty awesome.

C:\Users\Terry>python -c "exec('''for i in range(5):\n  print('hello 
world')''')"
hello world
hello world
hello world
hello world
hello world

> and not everyone knows you can do that.

One can even combine -i (interactive) with -c (code).

C:\Users\Terry> python -i -c "exec('''a=[]\nfor i in 
(1,2,3):\n\ta.append(i)''')"
 >>> a
[1, 2, 3]
 >>>

-- 
Terry Jan Reedy

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