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


Groups > comp.lang.python > #65590

Re: Python 2.7.6 help with white spaces?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <roy@panix.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'variables': 0.07; 'subject:help': 0.08; 'string': 0.09; 'literal': 0.09; 'means,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'assume': 0.14; '":"': 0.16; 'columns': 0.16; 'integer,': 0.16; 'integer.': 0.16; 'received:166.84': 0.16; 'received:166.84.1': 0.16; 'received:166.84.1.89': 0.16; 'received:mailbackend.panix.com': 0.16; 'received:panix.com': 0.16; 'roy': 0.16; 'seconds.': 0.16; 'specifier': 0.16; 'specifiers': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'variable': 0.18; 'normally': 0.19; 'received:10.0.1': 0.19; 'received:166': 0.19; 'feb': 0.22; '>>>': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'finally,': 0.24; 'format,': 0.24; 'integer': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'needed.': 0.30; 'url:mailman': 0.30; 'decimal': 0.31; 'another': 0.32; 'url:python': 0.33; 'trouble': 0.34; 'subject:with': 0.35; 'minutes,': 0.36; 'url:listinfo': 0.36; 'subject:?': 0.36; 'received:10.0': 0.36; 'similar': 0.36; 'url:org': 0.36; 'seconds': 0.37; 'so,': 0.37; 'two': 0.37; 'received:10': 0.37; 'pm,': 0.38; 'sure': 0.39; 'url:mail': 0.40; 'how': 0.40; 'remove': 0.60; 'header:Message-Id:1': 0.63; 'charset:windows-1252': 0.65; 'minutes': 0.67; 'smith': 0.68; 'article': 0.77; '2014,': 0.84; 'email addr:panix.com': 0.84; 'to:addr:cox.net': 0.84; 'together,': 0.84; 'same,': 0.91; 'scott': 0.93
Subject Re: Python 2.7.6 help with white spaces?
Mime-Version 1.0 (Apple Message framework v1283)
Content-Type text/plain; charset=windows-1252
From Roy Smith <roy@panix.com>
In-Reply-To <699CF5DD-1D51-4712-900D-70B94950305A@cox.net>
Date Thu, 6 Feb 2014 23:26:37 -0500
Content-Transfer-Encoding quoted-printable
References <mailman.6467.1391736132.18130.python-list@python.org> <PDY91n0183bjUJS01DYAz7> <699CF5DD-1D51-4712-900D-70B94950305A@cox.net>
To Scott W Dunning <swdunning@cox.net>
X-Mailer Apple Mail (2.1283)
Cc python-list@python.org
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.6478.1391747206.18130.python-list@python.org> (permalink)
Lines 64
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391747206 news.xs4all.nl 2858 [2001:888:2000:d::a6]:39987
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65590

Show key headers only | View raw


On Feb 6, 2014, at 11:12 PM, Scott W Dunning wrote:

> what exactly is the “%d:%02d”% saying?  

Python uses string format specifiers similar to C's printf()

%d means, "convert an integer to a decimal string"

%2d means the same, plus, "make the result 2 columns wide"

and, finally, %02d means, "and, if it would normally be less than 2 columns, zero-pad it on the left".

So, putting that all together, we've got:

"%d" --> decimal integer
":" --> a literal ":"
"%02d" --> another decimal integer, this time zero-padded to two columns


> 
> 
> 
> On Feb 6, 2014, at 6:25 PM, Roy Smith <roy@panix.com> wrote:
> 
>> In article <mailman.6467.1391736132.18130.python-list@python.org>,
>> Scott W Dunning <swdunning@cox.net> wrote:
>> 
>>> I am having trouble figuring out how to remove spacesŠ.
>>> 
>>> Assume variables exist for minutes and seconds. Each variable is an integer. 
>>> How would you create a string in the format,
>>> 
>>> 3:11
>>> 
>>> with no spaces. where 3 is minutes and 11 is seconds.
>>> 
>>> 
>>> Obviously when IŠ
>>> 
>>> print minutes, ³:², seconds
>>> 
>>> I get 3 : 11
>>> 
>>> how can I get it to print with no spaces?   
>>> 
>>> 3:11
>> 
>> print "%d:%02d" % (minutes, seconds)
>> 
>> The "02" for the seconds specifier makes sure you get exactly two 
>> digits, with a leading zero if needed.
>> -- 
>> https://mail.python.org/mailman/listinfo/python-list
> 


--
Roy Smith
roy@panix.com


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


Thread

Python 2.7.6 help with white spaces? Scott W Dunning <swdunning@cox.net> - 2014-02-06 18:22 -0700
  Re: Python 2.7.6 help with white spaces? Roy Smith <roy@panix.com> - 2014-02-06 20:25 -0500
  Re: Python 2.7.6 help with white spaces? Scott W Dunning <swdunning@cox.net> - 2014-02-06 21:12 -0700
  Re: Python 2.7.6 help with white spaces? Roy Smith <roy@panix.com> - 2014-02-06 23:26 -0500

csiph-web