Hi all,
what do you see looking at format string syntax
https://docs.python.org/3/library/string.html#formatstrings ?
In particular, at something like this:
{h[1].red.jumbo-header:Hello, World!}
Yes, this is syntactically correct statement and if we tweak Formatter
methods, we can generate
On Sunday, 22 July 2018 10:24:55 UTC+5:30, Cameron Simpson wrote:
> On 21Jul2018 21:33, Sharan Basappa wrote:
> >I get a lot confused while using print functions in Python.
> >
> >For example, I get the same results for the following code:
> >
> >str = "one two three"
>
> Pleasetry not to name v
On 22/07/18 06:54, Cameron Simpson wrote:
> On 21Jul2018 21:33, Sharan Basappa wrote:
>> I get a lot confused while using print functions in Python.
>>
>> For example, I get the same results for the following code:
>>
>> str = "one two three"
>
> Pleasetry not to name variables after builtin clas
On 21Jul2018 21:33, Sharan Basappa wrote:
I get a lot confused while using print functions in Python.
For example, I get the same results for the following code:
str = "one two three"
Pleasetry not to name variables after builtin classes ("str" is the name of
Python's string class).
prin
On Sun, Jul 22, 2018 at 2:53 PM, Abdur-Rahmaan Janhangeer
wrote:
> *Folks,I get a lot confused while using print functions in Python.For
> example, I get the same results for the following code:str = "one two
> three"print strprint "%s" %(str)So, what is the need to use the second
> method which I
*Folks,I get a lot confused while using print functions in Python.For
example, I get the same results for the following code:str = "one two
three"print strprint "%s" %(str)So, what is the need to use the second
method which I see being used in many programs I am referring to*
well
1) that is more
Folks,
I get a lot confused while using print functions in Python.
For example, I get the same results for the following code:
str = "one two three"
print str
print "%s" %(str)
So, what is the need to use the second method which I see being used in many
programs I am referring to
--
https:/
On Thu, Mar 29, 2018 at 1:54 AM, Dan Stromberg wrote:
> On Wed, Mar 28, 2018 at 7:30 AM, Ganesh Pal wrote:
>>>
>>> Or maybe they're not giving the same result. I'm a little confused here.
>>>
>>
>>
>> My Bad and Apologies , I should be fined for pasting wrong question.
>>
>> Actually I wanted t
On Wed, Mar 28, 2018 at 7:30 AM, Ganesh Pal wrote:
>>
>> Or maybe they're not giving the same result. I'm a little confused here.
>>
>
>
> My Bad and Apologies , I should be fined for pasting wrong question.
>
> Actually I wanted to know if its ok to use just empty {} with .format()
> or use {
"Ganesh Pal" wrote in message
news:CACT3xuUmOzR=5G9=zaf3fp2lytbgjv74vsyjfsvsifo77lf...@mail.gmail.com...
Actually I wanted to know if its ok to use just empty {} with .format()
or use {} with values i.e {0} {1} both will give the same results anyway
The benefit of using empty {} is that yo
>
> Or maybe they're not giving the same result. I'm a little confused here.
>
My Bad and Apologies , I should be fined for pasting wrong question.
Actually I wanted to know if its ok to use just empty {} with .format()
or use {} with values i.e {0} {1} both will give the same results anyway
On 03/26/2018 09:37 AM, Ganesh Pal wrote:
> Hi Team,
>
> Just a quick suggestion, on string formatting with .format() which of the
> below is better , given both give the same result .
No they don't. Look more closely at the output.
>>>> attempts = 1
>>
>
>
> Or maybe they're not giving the same result. I'm a little confused here.
>
>
Thanks Chris, for the reply they appear to give the same result .
--
https://mail.python.org/mailman/listinfo/python-list
在 2018年3月26日星期一 UTC+8下午11:37:46,Ganesh Pal写道:
> Hi Team,
>
> Just a quick suggestion, on string formatting with .format() which of the
> below is better , given both give the same result .
>
> >>> attempts = 1
> >>> msg2 = "Hello"
> >>
On Tue, Mar 27, 2018 at 2:37 AM, Ganesh Pal wrote:
> Hi Team,
>
> Just a quick suggestion, on string formatting with .format() which of the
> below is better , given both give the same result .
>
>>>> attempts = 1
>>>> msg2 = "Hello"
>>>
Hi Team,
Just a quick suggestion, on string formatting with .format() which of the
below is better , given both give the same result .
>>> attempts = 1
>>> msg2 = "Hello"
>>> print "Retry attempt:{0} for error:{1}".format(attempts,msg2)
Retry
Was "Accessing parent objects."
On 03/25/2018 12:26 PM, Jugurtha Hadjar wrote:
>> print("I am {0.__class__.__name__} foo".format(self))
>
> I prefer keyword arguments, but if I used it that way I'd do:
>
> print("I am {0} foo".format(self.__class__.__name__))
These are contrived examples. In r
Ian Kelly wrote:
> On Sat, Dec 10, 2016 at 11:40 PM, Veek M wrote:
>> Well take a look at this:
>> ###
>> #!/usr/bin/python
>>
>> class Foo(int):
>> def __init__(self, value):
>> self.value = value
>>
>> def __str__(self):
>> print '
On Sat, Dec 10, 2016 at 11:40 PM, Veek M wrote:
> Well take a look at this:
> ###
> #!/usr/bin/python
>
> class Foo(int):
> def __init__(self, value):
> self.value = value
>
> def __str__(self):
> print '__str__'
> return str(
Steve D'Aprano wrote:
> On Sat, 10 Dec 2016 06:06 pm, Veek M wrote:
>
>> When we do:
>>
>> print '%s %d' % ('hello', 10)
>>
>> what special method is being invoked internally within the string-
>> format-specifier?
>
> %d requires the argument to be an int, or able to be converted to int
> usi
On Sat, 10 Dec 2016 06:06 pm, Veek M wrote:
> When we do:
>
> print '%s %d' % ('hello', 10)
>
> what special method is being invoked internally within the string-
> format-specifier?
%d requires the argument to be an int, or able to be converted to int using
the __int__ special method.
py> cl
When we do:
print '%s %d' % ('hello', 10)
what special method is being invoked internally within the string-
format-specifier?
format() invokes format__
print invokes __str__
I'm basically trying to make sense of:
raise TypeError('urkle urkle %s' % list(dictionary))
<=> raise TypeError('urkle
gging/__init__.py", line 828, in format
return fmt.format(record)
File "/usr/lib/python3.4/logging/__init__.py", line 565, in format
record.message = record.getMessage()
File "/usr/lib/python3.4/logging/__init__.py", line 328, in getMessage
msg = msg
Message()
File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 330, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
[snip]
File
"C:\Users\dweng\PycharmProjects\lumar_ingestion\ingestion_workflow_modules\import_to_d
return fmt.format(record)
File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 567, in format
record.message = record.getMessage()
File "C:\Continuum\Anaconda3\lib\logging\__init__.py", line 330, in getMessage
msg = msg % self.args
TypeError: not all argume
On Wed, Feb 17, 2016 at 7:32 PM, Chris Angelico wrote:
> The print statement/function happily accepts multiple arguments, and
> will join them according to a set of predefined rules. The logging
> functions don't have those rules, so they take one message and some
> optional parameters. Try this,
On Thu, Feb 18, 2016 at 12:58 AM, Ganesh Pal wrote:
> Iam on python 2.6 and Linux , I had replaced print out, err ret with
> logging.info(out, err ,ret) in the below code . I am getting
>
> "TypeError: not all arguments converted during string formatting"
> error an
logging.info(out, err ,ret) in the below code . I am getting
>
> "TypeError: not all arguments converted during string formatting"
> error any quick suggestion
>
>
> try:
> out, err, ret = run(cmd, timeout=60)
> # New line add
Hi Team,
Iam on python 2.6 and Linux , I had replaced print out, err ret with
logging.info(out, err ,ret) in the below code . I am getting
"TypeError: not all arguments converted during string formatting"
error any quick suggestion
try:
out, err, ret = run(cmd,
On 09/06/2015 13:15, Skip Montanaro wrote:
One thing which seems obvious now is that since format() delegates to
the individual types for formatting, much of the documentation of this
stuff must now be delegated to the individual types. However, I can't
find anything about the formatting syntax
On Tue, Jun 9, 2015 at 7:29 AM, wrote:
> Where have you looked? Have you read
> https://docs.python.org/3/library/string.html#formatspec ?
Yes, but I missed the None section. I looked closely at 'g', but
didn't see anything like "this is the default". I will admit I was a
bit frustrated to see t
On Tue, Jun 9, 2015, at 08:15, Skip Montanaro wrote:
> Skip> Why don't floats support "{:.Ns}"? (I know I can use "{!s}".)
>
> random832> Why would they? The old style didn't support %.Ns either.
>
> Well, the old style does, though it appears the N is ignored:
>
> >>> "%5s" % -0.00666762259822
Skip> Why don't floats support "{:.Ns}"? (I know I can use "{!s}".)
random832> Why would they? The old style didn't support %.Ns either.
Well, the old style does, though it appears the N is ignored:
>>> "%5s" % -0.00666762259822
'-0.00666762259822'
It doesn't raise an exception though.
(This i
On 08/06/2015 21:05, Steven K Knight wrote:
June 8 2015 3:11 PM, "Skip Montanaro" mailto:%22Skip%20Montanaro%22%20>> wrote:
I have so far ignored the new string formatting (you know, the stuff
with all the braces, dots and brackets that make Python strings look
lik
On Mon, Jun 8, 2015, at 16:32, Skip Montanaro wrote:
> This is counterintuitive:
>
> >>> "{:.3}".format(-0.00666762259822)
> '-0.00667'
> >>> "{:.3f}".format(-0.00666762259822)
> '-0.007'
> >>> "%.3f" % -0.00666762259822
> '-0.007'
> >>> "{:.3s}".format(-0.00666762259822)
> ValueError Unknown form
On 08.06.15 23:32, Skip Montanaro wrote:
This is counterintuitive:
>>> "{:.3}".format(-0.00666762259822)
'-0.00667'
>>> "{:.3f}".format(-0.00666762259822)
'-0.007'
>>> "%.3f" % -0.00666762259822
'-0.007'
>>> "{:.3s}".format(-0.00666762259822)
ValueError Unknown format code 's' for object of
It just means significant digits in the general format, which alternates
between 10-exponent notation and plain decimal notation.
https://docs.python.org/3.4/library/string.html#format-specification-mini-language
>>> '{:.3}'.format(0.356785)
'3.57e-05'
>>> '{:.3}'.format(0.0035678
This is counterintuitive:
>>> "{:.3}".format(-0.00666762259822)
'-0.00667'
>>> "{:.3f}".format(-0.00666762259822)
'-0.007'
>>> "%.3f" % -0.00666762259822
'-0.007'
>>> "{:.3s}".format(-0.00666762259822)
ValueError Unknown format code 's' for object of type 'float'
Why does the first form display f
June 8 2015 3:11 PM, "Skip Montanaro" wrote:
I have so far ignored the new string formatting (you know, the stuff
with all the braces, dots and brackets that make Python strings look like Perl
code ). I am still only using Python 2.7, but have recently started forcing
mys
On Mon, Jun 8, 2015 at 3:05 PM, Steven K Knight wrote:
> I think http://pyformat.info/ is what you're looking for.
Perfect, thanks!
S
--
https://mail.python.org/mailman/listinfo/python-list
I have so far ignored the new string formatting (you know, the stuff with
all the braces, dots and brackets that make Python strings look like Perl
code ). I am still only using Python 2.7, but have recently started
forcing myself to use the print() function. I figure maybe I should also
start to
or.execute(sql,(gender,main_link,cat,item_content,price,seller))
This looks very much like your previous mistake
(1) Don't put quotes around the placeholders. They are probably interpreted
as string literals.
(2) The last placeholder is missing the %
> error:
>
>
> quer
""
may be you miss a "%" sign?
> query = query % db.literal(args)
> TypeError: not all arguments converted during string formatting
cheers:
a.
--
https://mail.python.org/mailman/listinfo/python-list
| varchar(20) | YES | | NULL |
|
| created_on | timestamp| NO | | CURRENT_TIMESTAMP |
|
+--+--+--+-+---++
8 rows in set (0.00 sec)
+++
error:
query = query % db.literal(args)
TypeError: not all arguments converted during string formatting
--
https://mail.python.org/mailman/listinfo/python-list
On 11/26/2013 05:01 PM, Victor Hooi wrote:
> Hi,
>
> I'm trying to use Python's new style string formatting with a dict
> and string together.
>
> For example, I have the following dict and string variable:
>
> my_dict = { 'cat': 'ernie',
On Tue, Nov 26, 2013 at 4:01 PM, Victor Hooi wrote:
> Hi,
>
> I'm trying to use Python's new style string formatting with a dict and
> string together.
>
> For example, I have the following dict and string variable:
>
> my_dict = { 'cat': '
On Tue, 26 Nov 2013 16:01:48 -0800, Victor Hooi wrote:
> '{0['cat']} {1} {0['dog']}'.format(my_dict, foo) ...
> SyntaxError: invalid syntax
It's a syntax error because you are using the same quotes. You have:
'{0['cat']} {1} {0['dog']}'
which is parsed as:
STR '{0['
NAME cat
STR '
Hi,
I'm trying to use Python's new style string formatting with a dict and string
together.
For example, I have the following dict and string variable:
my_dict = { 'cat': 'ernie', 'dog': 'spot' }
foo = 'lorem ipsum'
If I w
On 14 Jul., 17:31, Billy Mays wrote:
> On 07/14/2011 11:00 AM, Christian wrote:
>
>
>
>
>
>
>
>
>
> > Hi,
>
> > I get some problem when i like to set the table name dynamic.
> > I'm appreciate for any help.
>
> > Christian
>
> > ### works
> > newcur.execute ( """ INSERT INTO events (id1,id2
On 07/14/2011 11:00 AM, Christian wrote:
Hi,
I get some problem when i like to set the table name dynamic.
I'm appreciate for any help.
Christian
### works
newcur.execute ( """ INSERT INTO events (id1,id2) VALUES (%s,%s);
""" , (rs[1],rs[2]))
### works not
newcur.execute ( """ INSE
On Fri, Jul 15, 2011 at 1:00 AM, Christian wrote:
> Hi,
>
> I get some problem when i like to set the table name dynamic.
> I'm appreciate for any help.
>
> ### works but is not really perfect: None from rs list result in
> "None" instead of NULL.
> newcur.execute ( """ INSERT INTO %s_events (id
Hi,
I get some problem when i like to set the table name dynamic.
I'm appreciate for any help.
Christian
### works
newcur.execute ( """ INSERT INTO events (id1,id2) VALUES (%s,%s);
""" , (rs[1],rs[2]))
### works not
newcur.execute ( """ INSERT INTO %s_events (id1,id2) VALUES (%s,
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160
On 2011.07.10 09:33 AM, Roy Smith wrote:
> The canonical way to do that would be something like
>
> fields = [demux_filter, field_filter, fpsin_filter, i2pfilter,
> dn_filter, fpsout_filter, trim_filter, info_filter]
> avs.write(''.join(fields)
Roy Smith wrote:
> The canonical way to do that would be something like
>
> fields = [demux_filter,
> field_filter,
> fpsin_filter,
> i2pfilter,
> dn_filter,
> fpsout_filter,
> trim_filter,
> info_filter]
> avs.write(''.join(fi
In article ,
Andrew Berg wrote:
> How should I go about switching from concatenation to string formatting
> for this?
>
> avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter +
> dn_filter + fpsout_filter + trim_filter + info_filter)
>
> I can think of a few w
Andrew Berg wrote:
> How should I go about switching from concatenation to string formatting
> for this?
>
> avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter +
> dn_filter + fpsout_filter + trim_filter + info_filter)
>
> I can think of a few ways, but no
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160
On 2011.07.10 04:47 AM, Vinay Sajip wrote:
> You don't need logutils, just the BraceMessage class - which is
> shown in the blog post (around 10 lines). Feel free to use it with
> copy and paste :-)
I didn't realize that was the actual class when
Andrew Berg gmail.com> writes:
> On 2011.07.10 02:23 AM, Vinay Sajip wrote:
> > There are examples in the blog post I linked to earlier:
> It seems that would require logutils. I'm trying to keep dependencies to
> a minimum in my project, but I'll take a look at logutils and see if
> there's anyt
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160
On 2011.07.10 02:23 AM, Vinay Sajip wrote:
> There are examples in the blog post I linked to earlier:
It seems that would require logutils. I'm trying to keep dependencies to
a minimum in my project, but I'll take a look at logutils and see if
the
Andrew Berg gmail.com> writes:
> How would I do that with the newer formatting? I've tried:
There are examples in the blog post I linked to earlier:
http://plumberjack.blogspot.com/2010/10/supporting-alternative-formatting.html
Regards,
Vinay Sajip
--
http://mail.python.org/mailman/listinf
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160
How should I go about switching from concatenation to string formatting
for this?
avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter +
dn_filter + fpsout_filter + trim_filter + info_filter)
I can think of a few ways, but none of
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160
On 2011.07.10 12:55 AM, Dennis Lee Bieber wrote:
> Maybe it's been removed, but from the help file for my installation
help(file) returns a NameError in 3.2. It shows up as a built-in
function in the 2.7 docs, but not in the py3k docs. It's not me
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160
On 2011.07.09 11:04 PM, Andrew Berg wrote:
>
> Is barf built-in as well?
>
That came off more hostile than I wanted, so I'll rephrase it:
I doubt it has anything to do with built-ins, since it fails on a
variable name that obviously does not re
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160
On 2011.07.09 09:54 PM, Dennis Lee Bieber wrote:
> "file" is a built-in (related to "open").
Also:
> Traceback (most recent call last): File
> "C:\Users\Bahamut\workspace\Disillusion\disillusion.py", line 178, in
> save_preset() File
> "C:\Users\
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160
On 2011.07.09 09:54 PM, Dennis Lee Bieber wrote:
> "file" is a built-in (related to "open").
It is? What is it?
>>> type(file)
Traceback (most recent call last):
File "", line 1, in
NameError: name 'file' is not defined
I don't see it in
On 2011.07.09 06:06 AM, Vinay Sajip wrote:
> In a logging context at least, using the form like
>
> logger.debug("formatting message with %s", "arguments")
>
> rather than
>
> logger.debug("formatting message with %s" % "arguments")
How would I do that with the newer formatting? I've tried:
> logge
Andrew Berg gmail.com> writes:
> Other than the case where a variable isn't a string (format() converts
> variables to strings, automatically, right?) and when a variable is used
> a bunch of times, concatenation is fine, but somehow, it seems wrong.
> Sorry if this seems a bit silly, but I'm a n
On Sat, Jul 9, 2011 at 12:16 AM, Chris Angelico wrote:
> Has the same optimization been implemented for Unicode? The page
> doesn't mention Python 3 at all, and I would guess that the realloc
> optimization would work fine for both types of string.
Seems to be implemented for strs in 3.2, but not
On Sat, Jul 9, 2011 at 3:30 PM, Steven D'Aprano
wrote:
> It also doesn't generalise: only appends are optimized, not prepends.
>
> If you're interested in learning about the optimization:
>
> http://utcc.utoronto.ca/~cks/space/blog/python/ExaminingStringConcatOpt
>From that page:
"Also, this is o
On Fri, Jul 8, 2011 at 11:30 PM, Steven D'Aprano
wrote:
> Billy Mays wrote:
>
>> If it means anything, I think concatenation is faster.
>
> You are measuring the speed of an implementation-specific optimization.
> You'll likely get *very* different results with Jython or IronPython, or
> old versi
Billy Mays wrote:
> If it means anything, I think concatenation is faster.
You are measuring the speed of an implementation-specific optimization.
You'll likely get *very* different results with Jython or IronPython, or
old versions of CPython, or even if you use instance attributes instead of
lo
Andrew Berg wrote:
> Is it bad practice to use this
>> logger.error(self.preset_file + ' could not be stored - ' +
>> sys.exc_info()[1])
> Instead of this?
>> logger.error('{file} could not be stored -
>> {error}'.format(file=self.preset_file, error=sys.exc_info()[1]))
>
>
> Other than the case
* John Gordon (Fri, 8 Jul 2011 20:23:52 + (UTC))
> I prefer this usage:
>
> logger.error('%s could not be stored - %s' % \
> (self.preset_file, sys.exc_info()[1]))
The syntax for formatting logging messages according to the
documentation is:
Logger.error(msg, *args)
NOT
Logger.erro
the idea of intentionally having multiple ways to
do something, all with roughly equal merit.
On 2011.07.08 04:38 PM, Ian Kelly wrote:
> Also, string formatting (especially using the new syntax like you are)
> is much clearer because there's less noise (the quotes all over the
>
Ben Finney writes:
> logger.error(
> '{0} could not be stored - {1}'.format(
> (self.preset_file, sys.exc_info()[1]))
>
> I usually prefer to use named placeholders instead of positional, but
> this duplicates your original.
Ah, I see that the OP *did* use named placeholders.
On Fri, Jul 8, 2011 at 3:50 PM, Ben Finney wrote:
> * The ‘%’ string formatting operator is superseded in current Python
> versions by the more flexible ‘format’ method of string objects.
>
AFAIK, % formatting is the only kind of formatting that works portably
across all of CPythons
Andrew Berg writes:
> Is it bad practice to use this
> > logger.error(self.preset_file + ' could not be stored - ' +
> > sys.exc_info()[1])
This is not necessarily bad practice, but there are not many points in
its favour. It's inflexible and makes the eventual formatting harder to
discern.
> I
racketing syntax, since the function
parens are still open.
* The ‘%’ string formatting operator is superseded in current Python
versions by the more flexible ‘format’ method of string objects.
So:
logger.error(
'{0} could not be stored - {1}'.format(
(self.preset
On Fri, Jul 8, 2011 at 3:23 PM, Benjamin Kaplan
wrote:
> String formatting is the One Right Way here. It's fine to use string
> concatenation for a few things, but the operation is O(n^2) because each
> concat occurs one at a time: Python allocates space for a string the size of
ong.
> Sorry if this seems a bit silly, but I'm a novice when it comes to
> design. Plus, there's not really supposed to be "more than one way to do
> it" in Python.
>
String formatting is the One Right Way here. It's fine to use string
concatenation for a few
On 07/08/2011 04:18 PM, Andrew Berg wrote:
Is it bad practice to use this
logger.error(self.preset_file + ' could not be stored - ' +
sys.exc_info()[1])
Instead of this?
logger.error('{file} could not be stored -
{error}'.format(file=self.preset_file, error=sys.exc_info()[1]))
Other than th
In Andrew Berg
writes:
> Is it bad practice to use this
> > logger.error(self.preset_file + ' could not be stored - ' +
> > sys.exc_info()[1])
> Instead of this?
> > logger.error('{file} could not be stored -
> > {error}'.format(file=self.preset_file, error=sys.exc_info()[1]))
> Other than the
Is it bad practice to use this
> logger.error(self.preset_file + ' could not be stored - ' +
> sys.exc_info()[1])
Instead of this?
> logger.error('{file} could not be stored -
> {error}'.format(file=self.preset_file, error=sys.exc_info()[1]))
Other than the case where a variable isn't a string (f
On 06/21/2011 05:19 PM, Terry Reedy wrote:
On 6/21/2011 7:33 AM, Tim Chase wrote:
http://docs.python.org/library/stdtypes.html#str.format>
Is there a good link to a thread-archive on when/why/how .format(...)
became "preferred to the % formatting"?
That is a controversial statement.
I'm no
On 6/21/2011 7:33 AM, Tim Chase wrote:
On 06/20/2011 09:17 PM, Terry Reedy wrote:
On 6/20/2011 8:46 PM, Tim Chase wrote:
On 06/20/2011 05:19 PM, Ben Finney wrote:
“This method of string formatting is the new standard in
Python 3.0, and should be preferred to the % formatting
described in
On 06/20/2011 09:17 PM, Terry Reedy wrote:
On 6/20/2011 8:46 PM, Tim Chase wrote:
On 06/20/2011 05:19 PM, Ben Finney wrote:
“This method of string formatting is the new standard in
Python 3.0, and should be preferred to the % formatting
described in String Formatting Operations in new code
On 6/20/2011 8:46 PM, Tim Chase wrote:
On 06/20/2011 05:19 PM, Ben Finney wrote:
“This method of string formatting is the new standard in
Python 3.0, and should be preferred to the % formatting
described in String Formatting Operations in new code.”
http://docs.python.org/library/stdtypes.html
On 06/20/2011 05:19 PM, Ben Finney wrote:
“This method of string formatting is the new standard in
Python 3.0, and should be preferred to the % formatting
described in String Formatting Operations in new code.”
http://docs.python.org/library/stdtypes.html#str.format>
Is there a good link t
Steven D'Aprano writes:
> On Tue, 07 Jun 2011 10:11:01 +1000, Ben Finney wrote:
>
> > I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can
> > also take the namespace of an object. I only need to remember one
> > “give me the namespace” function for formatting.
[…]
>
> It's a code
On Tue, 07 Jun 2011 10:11:01 +1000, Ben Finney wrote:
> Chris Rebert writes:
>
>> print "{solo} was captured by {jabba}".format(**locals()) # RIGHT
>
> I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can also
> take the namespace of an object. I only need to remember one “give m
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney wrote:
> Chris Rebert writes:
>
>> print "{solo} was captured by {jabba}".format(**locals()) # RIGHT
>
> I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can also
> take the namespace of an object. I only need to remember one “give me
> th
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney wrote:
>> You must use prefix-** in the call to unpack the mapping as keyword
>> arguments. Note that using locals() like this isn't best-practice.
>
> Who says so, and do you find their argument convincing? Do you have a
> reference for that so we can se
Chris Rebert writes:
> print "{solo} was captured by {jabba}".format(**locals()) # RIGHT
I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can also
take the namespace of an object. I only need to remember one “give me
the namespace” function for formatting.
> You must use prefix-*
Prasad, Ramit wrote:
print "{} was captured by {}".format(solo, jabba)
Is this Python2.7 specific?
Python 2.6.x :
print "{} was captured by {}".format('t1', 't2')
ValueError: zero length field name in format
Apparently it is 2.7 and greater -- my apologies for not specifying that.
~Ethan~
> print "{} was captured by {}".format(solo, jabba)
Is this Python2.7 specific?
Python 2.6.x :
>>>print "{} was captured by {}".format('t1', 't2')
ValueError: zero length field name in format
Ramit
This communication is for informational purposes only. It is not
intended as an offer or soli
On Mon, Jun 6, 2011 at 10:15 AM, Jabba Laci wrote:
> Hi,
>
> I'd like to simplify the following string formatting:
>
> solo = 'Han Solo'
> jabba = 'Jabba the Hutt'
> print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
>
Steve Crook wrote:
On Mon, 6 Jun 2011 12:15:35 -0400, Jabba Laci wrote in
Message-Id: :
solo = 'Han Solo'
jabba = 'Jabba the Hutt'
print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
# Han Solo was captured by Jabba the Hutt
How about:-
print "%s was captured by %s" % (solo
On Mon, 6 Jun 2011 12:15:35 -0400, Jabba Laci wrote in
Message-Id: :
> solo = 'Han Solo'
> jabba = 'Jabba the Hutt'
> print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
> # Han Solo was captured by Jabba the Hutt
How about:-
print "%s was captured by %s" % (solo, jabba)
--
ht
On Mon, Jun 6, 2011 at 9:15 AM, Jabba Laci wrote:
> Hi,
>
> I'd like to simplify the following string formatting:
>
> solo = 'Han Solo'
> jabba = 'Jabba the Hutt'
> print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
>
Hi,
I'd like to simplify the following string formatting:
solo = 'Han Solo'
jabba = 'Jabba the Hutt'
print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
# Han Solo was captured by Jabba the Hutt
What I don't like here is this: "so
1 - 100 of 455 matches
Mail list logo