On 24/01/2013 13:29, Krupkina Lesya Olegovna wrote:
Hello!
I’m newcomer to Python and I’m on documentation reading stage and trying some
of examples.
I’m using Win7 x64 OS and Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC
v.1500 64 bit (AMD64)].
I try to understand how string format expres
Krupkina Lesya Olegovna wrote:
> Python outputs decimal as declared as but with more significant digits
> than default value of 6 - if integer part of the decimal is equal to zero.
"%#g"%0.3
> '0.30'
In this context "significant digits" are the first non-zero digit and any
digits (inclu
Hello!
I’m newcomer to Python and I’m on documentation reading stage and trying some
of examples.
I’m using Win7 x64 OS and Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC
v.1500 64 bit (AMD64)].
I try to understand how string format expression (%)works. Everything is almost
clear but except
On Wed, Oct 24, 2012 at 4:11 PM, Mike wrote:
>
> tar: /home/rev/code/beavis/test/24.10.2012: Cannot stat: No such file or
> directory
> tar: 15\:06\:52.tgz: Cannot stat: No such file or directory
You have a space in the filename:
lt = time.localtime(time.time())
return "%02d.%02d.%04d %0
On 24/10/2012 21:11, Mike wrote:
I'm in the process of learning python and migrating away from bash
scripting. I'm in the process of converting my bash scripts that
essentially ssh to another host via shared keys, execute commands
remotely, and exit. To do this I started using paramiko but eventu
I'm in the process of learning python and migrating away from bash
scripting. I'm in the process of converting my bash scripts that
essentially ssh to another host via shared keys, execute commands
remotely, and exit. To do this I started using paramiko but eventually
decided to do it w/ subpro
Wayne Werner wrote:
On Mon, Sep 19, 2011 at 1:11 PM, wrote:
Is there any additional overhead of using the locals() or format(locals())
instead of a tuple? - the format option is a double function call so I would
expect that to be considerably slower
Using the following code and timeit, it a
On Mon, Sep 19, 2011 at 1:11 PM, wrote:
> Is there any additional overhead of using the locals() or format(locals())
> instead of a tuple? - the format option is a double function call so I would
> expect that to be considerably slower
>
Using the following code and timeit, it appears that there
evice
-Original Message-
From: Wayne Werner
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Mon, 19 Sep 2011 12:47:01
To: Pirritano, Matthew
Cc:
Subject: Re: [Tutor] string formatting
___
Tutor maillist - Tutor@python.org
To unsubs
On Mon, Sep 19, 2011 at 10:46 AM, Pirritano, Matthew
wrote:
>
You some variables say:
>
> X = "sky"
> Y = "blue"
>
> Print "the %(x)s is %(y)s" % locals()
>
> the sky is blue
>
> That works! And in cases where I'm replacing over 20 strings it's much
> easier than having to include a tuple at the
714) 568-5648
-Original Message-
From: tutor-bounces+mpirritano=ochca@python.org
[mailto:tutor-bounces+mpirritano=ochca@python.org] On Behalf Of
Steven D'Aprano
Sent: Saturday, September 17, 2011 6:58 PM
To: tutor@python.org
Subject: Re: [Tutor] string formatting
Matthew Pirri
Matthew Pirritano wrote:
But I have very large blocks of text and I thought there was another way
like
X = "sky"
Y = "blue"
"the %(X)s is %(Y)s"
Unless you use the string formatting operator %, strings containing "%"
are just strings. Large or small, the way you do string formatting is
with
On Sun, Sep 18, 2011 at 01:51, Matthew Pirritano <
matthewpirrit...@sbcglobal.net> wrote:
> All,
>
> ** **
>
> I know that I can do this:
>
> ** **
>
> "the %s is %s" % ('sky', 'blue')
>
> ** **
>
> But I have very large blocks of text and I thought there was another way
> like
>
>
On Sat, Sep 17, 2011 at 7:51 PM, Matthew Pirritano <
matthewpirrit...@sbcglobal.net> wrote:
> All,
>
> ** **
>
> I know that I can do this:
>
> ** **
>
> "the %s is %s" % ('sky', 'blue')
>
> ** **
>
> But I have very large blocks of text and I thought there was another way
> like
>
All,
I know that I can do this:
"the %s is %s" % ('sky', 'blue')
But I have very large blocks of text and I thought there was another way
like
X = "sky"
Y = "blue"
"the %(X)s is %(Y)s"
But I've tried this and it is not working. I'm just trying to get it to work
in the inter
wrote
'first={0}, last={1}, middle={2}'.format(*parts)
"first=S, last=M, middle=['P', 'A']"
why do we need the '*' at 'parts'. I know we need it, because
otherwise it
gives an error:
The * tells Python to unpack parts and treat the contents
as individual values. format is looking for 3 v
I see now, that example helps. Basically I use one asterisk to extract a
list or a tuple and double asterisks for a dictionary, but I have to provide
keys in case of a dictionary, like here:
>>> template = '{motto}, {pork} and {food}'
>>> a = dict(motto='spam', pork='ham', food='eggs')
>>> templat
From: tutor-bounces+ramit.prasad=jpmchase@python.org
[mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of
eize...@gmail.com
Sent: Wednesday, June 08, 2011 3:11 PM
To: tutor@python.org
Subject: [Tutor] String formatting question with 's'.format()
I'm work
I'm working through the 'Learn Python' book by Mark Lutz, in this example:
somelist = list('SPAM')
parts = somelist[0], somelist[-1], somelist[1:3]
'first={0}, last={1}, middle={2}'.format(*parts)
"first=S, last=M, middle=['P', 'A']"
why do we need the '*' at 'parts'. I know we need it, becaus
On 31-Mar-11 09:46, bob gailer wrote:
IMHO % formatting is the easiest to use and understand.
I am sorry that it has been slated for removal.
I had the same reaction, but I think it was mostly because of my long
background as a C programmer, since it's essentially the equivalent of
printf() f
IMHO % formatting is the easiest to use and understand.
I am sorry that it has been slated for removal.
--
Bob Gailer
919-636-4239
Chapel Hill NC
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python
Wayne Werner wrote:
On Tue, Mar 29, 2011 at 2:41 PM, Prasad, Ramit wrote:
Is there a difference (or preference) between using the following?
"%s %d" % (var,num)
VERSUS
"{0} {1}".format(var,num)
Practically there's no difference. In reality (and under the hood) there are
more differences, som
On Tue, Mar 29, 2011 at 2:41 PM, Prasad, Ramit wrote:
> Is there a difference (or preference) between using the following?
> "%s %d" % (var,num)
> VERSUS
> "{0} {1}".format(var,num)
>
Practically there's no difference. In reality (and under the hood) there are
more differences, some of which are
For simple strings I use the "%s" % foo version, for more complex stuff I use
the .format() method. I find it easier to control spacing and alignments with
the .format() method, but that's just me.
-Modulok-
On 3/29/11, Blockheads Oi Oi wrote:
> On 29/03/2011 20:41, Prasad, Ramit wrote:
>> Is t
On 29/03/2011 20:41, Prasad, Ramit wrote:
Is there a difference (or preference) between using the following?
"%s %d" % (var,num)
VERSUS
"{0} {1}".format(var,num)
Ramit
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription opti
On Tue, Mar 29, 2011 at 4:21 PM, Corey Richardson wrote:
> On 03/29/2011 03:41 PM, Prasad, Ramit wrote:
> > Is there a difference (or preference) between using the following?
> > "%s %d" % (var,num)
> > VERSUS
> > "{0} {1}".format(var,num)
> >
> >
> > Ramit
>
> If you're using Python 3, use the s
On 03/29/2011 03:41 PM, Prasad, Ramit wrote:
> Is there a difference (or preference) between using the following?
> "%s %d" % (var,num)
> VERSUS
> "{0} {1}".format(var,num)
>
>
> Ramit
If you're using Python 3, use the second one. If you're using Python 2,
you have no option but to use the first
Is there a difference (or preference) between using the following?
"%s %d" % (var,num)
VERSUS
"{0} {1}".format(var,num)
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423
This communication is for infor
"Tony Cappellini" wrote
sys.stdout.write( "\r%-8s ... 0x%08X->0x%08X " % ( descr,
long(startAddr), long(endAddr) )
Why are these displayed with a leading negative sign (between the 0x
and the actual number)- as seen below?
0x-1BFFF400 to 0x-1BFFF000
Because they are negative values and th
I was looking at a this code which uses this code to dsiplay some hex numbers
sys.stdout.write( "\r%-8s ... 0x%08X->0x%08X " % ( descr,
long(startAddr), long(endAddr) )
The hex values are in this range
0x1BFFF400 to 1BFFF000
Why are these displayed with a leading negative sign (between the 0x
a
On Tue, 2006-06-20 at 13:49 -0400, Paul D. Kraus wrote:
> How can i print a float as a currency with commas.
>
> 1222333.4 -> 1,222,333.40
>
> if i '%0.2f'%number
>
> i get
> 1222333.40
import locale
>>> locale.setlocale(locale.LC_ALL,"")
'en_US.UTF-8'
>>> currency_symbol = locale.localeconv()
Paul D. Kraus wrote:
> How can i print a float as a currency with commas.
>
> 1222333.4 -> 1,222,333.40
>
> if i '%0.2f'%number
>
> i get
> 1222333.40
Use locale.format():
In [1]: import locale
In [2]: f=1222333.4
In [6]: locale.setlocale(locale.LC_ALL, "")
Out[6]: 'English_United States.125
How can i print a float as a currency with commas.1222333.4 -> 1,222,333.40if i '%0.2f'%numberi get1222333.40Thanks,Paul
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
> Can I use string formatting in my own functions, or is it stuck with
> builtins?
No, you can use it too.
> It doesn't make much sense for me, but I don't understand the following
> error:
> In [2]: def printd(arg):
> ...: print('>>> %s') % arg
The format operator needs to be with the
> The parenthesization you had earlier forced Python into printing out
> your template before it had an opportunity to plug arg into it. You
> need to do the interpolation first.
Gaaah. Brain freeze.
I was pointing at the wrong code. *grin*
I meant to look at the other statement that you h
On Sat, 15 Apr 2006, Tiago Saboga wrote:
> Can I use string formatting in my own functions, or is it stuck with builtins?
> It doesn't make much sense for me, but I don't understand the following
> error:
>
> In [1]: var = 456
>
> In [2]: def printd(arg):
> ...: print('>>> %s') % arg
> .
Can I use string formatting in my own functions, or is it stuck with builtins?
It doesn't make much sense for me, but I don't understand the following
error:
In [1]: var = 456
In [2]: def printd(arg):
...: print('>>> %s') % arg
...:
In [3]: printd(var)
>>> 456
In [4]: printd('Variab
On 7 Apr 2006, [EMAIL PROTECTED] wrote:
> Sorry I didn't make my question clearer. Bascially I
> want to replace this line:
>
> address="64.41.134.60"/>
>
> With:
>
> address="64.41.134.60"/>
>
> So the regex grouping are that I want to keep
> portNumber= and tcpORudp= and replace the values.
>
Jerome Jabson wrote:
> Hi Kent,
>
> Sorry I didn't make my question clearer. Bascially I
> want to replace this line:
>
> address="64.41.134.60"/>
>
> With:
>
> address="64.41.134.60"/>
>
> So the regex grouping are that I want to keep
> portNumber= and tcpORudp= and replace the values.
> Wh
Hi Kent,
Sorry I didn't make my question clearer. Bascially I
want to replace this line:
With:
So the regex grouping are that I want to keep
portNumber= and tcpORudp= and replace the values.
Which will be varibles in my code.
The question is more on the string formatting in the
replace. Ho
> My problem now is how do I construct the replace
> statement?
> twork = m_sock.sub('\1 %s \2 %s', % port_num % proto,
> twork)
The format operator takes a tuple:
twork = m_sock.sub('\1 %s \2 %s' % (port_num, proto), twork)
So I removed the comma after the string, used a single percent
operat
Jerome Jabson wrote:
> Hello,
>
> I'm trying to replace some strings in a line of text,
> using some regex functions. My question is: If there's
> more then one regex grouping I want to replace in one
> line of a file, how can I use the String Formatting
> operator (%s) in two places?
Hi Jerome,
Hello,
I'm trying to replace some strings in a line of text,
using some regex functions. My question is: If there's
more then one regex grouping I want to replace in one
line of a file, how can I use the String Formatting
operator (%s) in two places?
Here's the line it matches in the file:
Her
Ah, thanks for the explanation. I've never been tripped up by that...
Kent
Pierre Barbier de Reuille wrote:
> Kent Johnson a écrit :
>
>>Pierre Barbier de Reuille wrote:
>>
>
> [...]
>
>>
>>>Well, when using the "%" operator on string always put a tuple or a
>>>dictionnary on the RHS :
>>>
>>>
Kent Johnson a écrit :
> Pierre Barbier de Reuille wrote:
>
[...]
>
>
>>Well, when using the "%" operator on string always put a tuple or a
>>dictionnary on the RHS :
>>
>>print "Connection from %s" % (info,)
>
>
> No, you can put a single item on the right without putting it in a tuple:
> >>
Pierre Barbier de Reuille wrote:
> Jorge Louis De Castro a écrit :
>
>>Hi,
>>
>>I'm slighty confused with python's string formatting operators.
>>
>>Why is it that this prints as a string:
>>
>>channel, info = server.accept()
>>print "Connection from", info
>>
>>And this doesn't?
>>
>>channel, inf
Jorge Louis De Castro a écrit :
> Hi,
>
> I'm slighty confused with python's string formatting operators.
>
> Why is it that this prints as a string:
>
> channel, info = server.accept()
> print "Connection from", info
>
> And this doesn't?
>
> channel, info = server.accept()
> print "Connecti
Hi,
I'm slighty confused with python's string
formatting operators.
Why is it that this prints as
a string:
channel, info = server.accept()
print "Connection from", info
And this doesn't?
channel, info = server.accept()
print "Connection from
%s" % info
Also, anyone knows how do
48 matches
Mail list logo