and cannot be deduced from the documentation.
--
components: Interpreter Core
messages: 70822
nosy: blop
severity: normal
status: open
title: string formatting quirk using %.%
type: behavior
___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org
Guido van Rossum [EMAIL PROTECTED] added the comment:
It's straightforward if you consider the implementation of the
requirement that %% renders a single percent sign: the second % is
parsed just like any other formatting code (i, d, f, etc.) and the stuff
between the first % and the formatting
nadav [EMAIL PROTECTED] added the comment:
The main problem with this is that the following code does not make any
sense:
%(a)% % dict(a=3)
It has no semantic meaning (take the dictionary paramater a, and do nothing
with it).
It must be a user bug (except in very wierd cases).
I agree that
Georg Brandl [EMAIL PROTECTED] added the comment:
I'd rather see it this way: It is a programming error if a format string
contains a reference to a nonexisting dictionary key, no matter what
formatting specifier is used. The implementation is quite consistent here.
--
nosy:
New submission from Artur Zaprzała [EMAIL PROTECTED]:
Description of 'g' and 'G' conversion types of string formatting
operator at http://www.python.org/doc/2.5.2/lib/typesseq-strings.html is:
Floating point format. Uses exponential format if exponent is greater
than -4 or less than precision
Georg Brandl [EMAIL PROTECTED] added the comment:
Thanks, fixed in r62774.
--
resolution: - fixed
status: open - closed
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2773
__
Artur Zaprzała [EMAIL PROTECTED] added the comment:
The fix is wrong. not less == greater than or equal to
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2773
__
___
Georg Brandl [EMAIL PROTECTED] added the comment:
Argh, fixed in r62775.
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2773
__
___
Python-bugs-list mailing list
Unsubscribe:
Eric Smith [EMAIL PROTECTED] added the comment:
On the python-3000 list we decided not to add new features to %
formatting, since it will be deprecated in favor of str.format.
--
resolution: - wont fix
status: open - closed
__
Tracker [EMAIL PROTECTED]
Eric Smith [EMAIL PROTECTED] added the comment:
I should have noted that the PEP was modified to remove %b and %#b
formatting.
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2416
__
import locale
locale.setlocale(locale.LC_ALL, '')
'en_US.UTF-8'
locale.format('%.2f', 1021212.12, True)
'1,021,212.12'
On Wed, Apr 9, 2008 at 1:04 PM, Kelie [EMAIL PROTECTED] wrote:
Hello,
Is there something in Python built-in function or library that will
convert a number 1205466.654 to
Hello,
Is there something in Python built-in function or library that will convert
a number 1205466.654 to $1,205,466.65? To add the $ sign and set the
decimal place is not a problem, but I don't know how to add the thousands
delimiter.
Thanks,
--
Kelie
UliPad http://code.google.com/p/ulipad/
On Wed, Apr 9, 2008 at 1:04 PM, Kelie [EMAIL PROTECTED] wrote:
Is there something in Python built-in function or library that will convert
a number 1205466.654 to $1,205,466.65? To add the $ sign and set the
decimal place is not a problem, but I don't know how to add the thousands
delimiter.
Thank you Jerry!
--
Kelie
UliPad http://code.google.com/p/ulipad/ is my Python editor.
--
http://mail.python.org/mailman/listinfo/python-list
New submission from Eric Smith [EMAIL PROTECTED]:
PEP 3127 Integer Literal Support and Syntax says that % string
formatting should support %b. This needs to be added to both 2.6 and
3.0. It needs to support the forms %b and %#b.
--
assignee: eric.smith
components: Interpreter Core
Is there an easy way to make string-formatting smart enough to
gracefully handle iterators/generators? E.g.
transform = lambda s: s.upper()
pair = ('hello', 'world')
print %s, %s % pair # works
print %s, %s % map(transform, pair) # fails
with a
TypeError: not enough arguments
On Feb 27, 5:23 pm, Tim Chase [EMAIL PROTECTED] wrote:
Is there an easy way to make string-formatting smart enough to
gracefully handle iterators/generators? E.g.
transform = lambda s: s.upper()
pair = ('hello', 'world')
print %s, %s % pair # works
print %s, %s % map(transform
On Wed, 27 Feb 2008 10:23:49 -0600
Tim Chase [EMAIL PROTECTED] wrote:
I can force it by wrapping the results of my generator in a call
to tuple() or list()
I think you are wrong about list(). Since map() returns a list already
it doesn't change anything.
print %s, %s %
On Feb 27, 4:23 pm, Tim Chase [EMAIL PROTECTED] wrote:
Is there an easy way to make string-formatting smart enough to
gracefully handle iterators/generators? E.g.
transform = lambda s: s.upper()
pair = ('hello', 'world')
print %s, %s % pair # works
print %s, %s % map(transform
D'Arcy J.M. Cain wrote:
I find I hit it mostly with calls to map() where I want to apply
some transform (as above) to all the items in a list of
parameters such as
%s=%s%s=%s % map(urllib.quote, params)
Isn't map() deprecated? The above can be done with;
%s=%s%s=%s %
En Wed, 27 Feb 2008 14:23:49 -0200, Tim Chase
[EMAIL PROTECTED] escribi�:
Is there an easy way to make string-formatting smart enough to
gracefully handle iterators/generators? E.g.
transform = lambda s: s.upper()
pair = ('hello', 'world')
print %s, %s % pair # works
print
Is there an easy way to make string-formatting smart enough to
gracefully handle iterators/generators? E.g.
transform = lambda s: s.upper()
pair = ('hello', 'world')
print %s, %s % pair # works
print %s, %s % map(transform, pair) # fails
with a
TypeError: not enough
On Feb 27, 5:25 pm, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote:
On Wed, 27 Feb 2008 10:23:49 -0600
Tim Chase [EMAIL PROTECTED] wrote:
%s=%s%s=%s % map(urllib.quote, params)
Isn't map() deprecated? The above can be done with;
%s=%s%s=%s % tuple([urllib.quote(x) for x in params])
I
D'Arcy J.M. Cain [EMAIL PROTECTED] writes:
The above can be done with;
%s=%s%s=%s % tuple([urllib.quote(x) for x in params])
Or, better::
%s=%s%s=%s % tuple(urllib.quote(x) for x in params)
passing a generator, instead of a list created from a generator, to
the tuple constructor.
Note that your problem has nothing to do with map itself.
String interpolation using % requires either many individual
arguments, or a single *tuple* argument. A list is printed
as itself.
Just as an exercise to understand this better, I've been trying
to figure out what allows for this
On Wed, 27 Feb 2008 13:06:27 -0800 (PST)
Arnaud Delobelle [EMAIL PROTECTED] wrote:
On Feb 27, 5:25 pm, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote:
Isn't map() deprecated? The above can be done with;
I don't think that map() is deprecated. In python 3.0 it is still
present, only it returns an
On Wed, 27 Feb 2008 14:41:32 -0600, Tim Chase wrote:
Is there an easy way to make string-formatting smart enough to
gracefully handle iterators/generators? E.g.
transform = lambda s: s.upper()
pair = ('hello', 'world')
print %s, %s % pair # works
print %s, %s % map(transform
Steven D'Aprano [EMAIL PROTECTED] writes:
map() isn't deprecated, not even for Python 3 where it remains a built-
in. However it will return an iterator instead of a list, making it
(presumably) a more convenient way to spell itertools.imap().
That's the first I heard of that change. I guess
En Wed, 27 Feb 2008 23:18:14 -0200, Steven D'Aprano
[EMAIL PROTECTED] escribió:
I think there is a good case for % taking an iterator. Here's an
artificial example:
def spam():
while True: yield spam
spam = spam()
%s eggs tomato and %s % spam
%s %s bacon tomato %s and eggs % spam
En Wed, 27 Feb 2008 20:40:04 -0200, Tim Chase
[EMAIL PROTECTED] escribió:
Note that your problem has nothing to do with map itself.
String interpolation using % requires either many individual
arguments, or a single *tuple* argument. A list is printed
as itself.
Just as an exercise to
On Thu, 28 Feb 2008 00:03:02 -0200, Gabriel Genellina wrote:
En Wed, 27 Feb 2008 23:18:14 -0200, Steven D'Aprano
[EMAIL PROTECTED] escribió:
I think there is a good case for % taking an iterator. Here's an
artificial example:
def spam():
while True: yield spam
spam = spam()
%s
Hi all,
I am trying to write a simple program that will accept an integral
time input in the HHMMSS format and output a HH:MM:SS form. My
code is as follows:
import string
def FormatTime(time):
'''Converts an HHMMSS string to HH:MM:SS format.'''
timeString =
[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hi all,
I am trying to write a simple program that will accept an integral
time input in the HHMMSS format and output a HH:MM:SS form. My
code is as follows:
import string
def FormatTime(time):
On 1月27日, 上午1时02分, [EMAIL PROTECTED] wrote:
Hi all,
I am trying to write a simple program that will accept an integral
time input in the HHMMSS format and output a HH:MM:SS form. My
code is as follows:
import string
def FormatTime(time):
'''Converts an HHMMSS
[EMAIL PROTECTED] wrote:
Hi all,
I am trying to write a simple program that will accept an integral
time input in the HHMMSS format and output a HH:MM:SS form. My
code is as follows:
import string
def FormatTime(time):
'''Converts an HHMMSS string to HH:MM:SS
I apologize for the lack of details in my last post. This time
formatting program is a piece of a larger program I am trying to write
to de-clutter GPS transmission. I have a GPS receiver that transmits
its readings via bluetooth. I've been able to use pySerial and store
X number of bytes, then
On Jan 27, 7:15 am, [EMAIL PROTECTED] wrote:
I apologize for the lack of details in my last post.
There is nothing to apologise for. Unlike some, you gave enough
information, without prompting, to get answers to your questions.
Don't go to the other extreme :-)
This time
formatting program
In article
[EMAIL PROTECTED],
John Machin [EMAIL PROTECTED] wrote:
snip
div operator? The integer division operator is //
Yes, sorry, that's what I meant.
--
Odysseus
--
http://mail.python.org/mailman/listinfo/python-list
In article
[EMAIL PROTECTED],
John Machin [EMAIL PROTECTED] wrote:
snip
You obviously haven't tried float(n / m), or you wouldn't be asking.
True, it was a very silly idea.
Most legible and slowest first:
1. float(n) / float(m)
2. n / float(m)
3. 1.0 * n / m
Recommendation: go with
In article
[EMAIL PROTECTED],
Roberto Bonvallet [EMAIL PROTECTED] wrote:
Put this at the beginning of your program:
from __future__ import division
This forces all divisions to yield floating points values:
Thanks for the tip. May I assume the div operator will still behave as
On Jan 13, 8:43 pm, Odysseus [EMAIL PROTECTED] wrote:
In article
[EMAIL PROTECTED],
Roberto Bonvallet [EMAIL PROTECTED] wrote:
Put this at the beginning of your program:
from __future__ import division
This forces all divisions to yield floating points values:
Thanks for the
In article [EMAIL PROTECTED],
Gary Herron [EMAIL PROTECTED] wrote:
Odysseus wrote:
snip
print '%2u %6u %4.2f' % \
(i, wordcounts[i], 100.0 * wordcounts[i] / wordcounts[0])
Using 4.2 is the problem. The first digit (your 4) give the total
number of characters to use for the
Odysseus wrote:
Hello, group: I've just begun some introductory tutorials in Python.
Taking off from the word play exercise at
http://www.greenteapress.com/thinkpython/html/book010.html#toc96
I've written a mini-program to tabulate the number of characters in each
word in a file. Once
Hello, group: I've just begun some introductory tutorials in Python.
Taking off from the word play exercise at
http://www.greenteapress.com/thinkpython/html/book010.html#toc96
I've written a mini-program to tabulate the number of characters in each
word in a file. Once the data have been
Odysseus wrote:
Hello, group: I've just begun some introductory tutorials in Python.
Taking off from the word play exercise at
http://www.greenteapress.com/thinkpython/html/book010.html#toc96
I've written a mini-program to tabulate the number of characters in each
word in a file. Once the
On Jan 13, 3:15 pm, Odysseus [EMAIL PROTECTED] wrote:
[snip]
P.S. Is there a preferable technique for forcing floating-point division
of two integers to that used above, multiplying by 100.0 first? What
about if I just wanted a ratio: is float(n / m) better than 1.0 * n /
m?
Odysseus
You
On Jan 12, 10:15 pm, Odysseus [EMAIL PROTECTED] wrote:
P.S. Is there a preferable technique for forcing floating-point division
of two integers to that used above, multiplying by 100.0 first?
Put this at the beginning of your program:
from __future__ import division
This forces all
Neal Becker a écrit :
I have a list of strings (sys.argv actually). I want to print them as a
space-delimited string (actually, the same way they went into the command
line, so I can cut and paste)
So if I run my program like:
./my_prog a b c d
I want it to print:
'./my_prog' 'a' 'b'
I have a list of strings (sys.argv actually). I want to print them as a
space-delimited string (actually, the same way they went into the command
line, so I can cut and paste)
So if I run my program like:
./my_prog a b c d
I want it to print:
'./my_prog' 'a' 'b' 'c' 'd'
Just print sys.argv
Neal Becker wrote:
I have a list of strings (sys.argv actually). I want to print them as a
space-delimited string (actually, the same way they went into the command
line, so I can cut and paste)
So if I run my program like:
./my_prog a b c d
I want it to print:
'./my_prog' 'a' 'b' 'c'
On 2007-12-14, Neal Becker [EMAIL PROTECTED] wrote:
I have a list of strings (sys.argv actually). I want to print them as a
space-delimited string (actually, the same way they went into the command
line, so I can cut and paste)
So if I run my program like:
./my_prog a b c d
I want it to
dictionary-key/value syntax), you can do something like:
number = lambda x: dict((str(i+1), v) for (i,v) in enumerate(x))
%(2)s and %(1)s % number([A, B])
Whoa - that'll take me a little while to figure out, but it looks intriguing!
It basically just returns a dictionary that maps your
Hi,
I'm sure I one read somewhere that there is a simple way to set the order
of replacements withing a string *without* using a dictionary.
What I mean is:
s = %s and %s % ( A, B )
print s
A and B
Now, is there something quick like:
s = %s/2 and %s/1 % ( A, B )
print s
B and A
?
I know
Donn Ingle wrote:
Now, is there something quick like:
s = %s/2 and %s/1 % ( A, B )
print s
B and A
?
GNU glibc printf accepts a format string:
printf (%2$s and %1$s, A, B);
to produce what you want -- but not Python, AFAIK.
Mel.
--
but not Python, AFAIK
Damn!
\d
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 2, 1:35 pm, Donn Ingle [EMAIL PROTECTED] wrote:
Hi,
I'm sure I one read somewhere that there is a simple way to set the order
of replacements withing a string *without* using a dictionary.
What I mean is: s = %s and %s % ( A, B )
print s
A and B
Now, is there something quick
try to import printf using ctypes
On Dec 2, 2007 7:49 PM, MRAB [EMAIL PROTECTED] wrote:
On Dec 2, 1:35 pm, Donn Ingle [EMAIL PROTECTED] wrote:
Hi,
I'm sure I one read somewhere that there is a simple way to set the
order
of replacements withing a string *without* using a dictionary.
I'm sure I one read somewhere that there is a simple way to set the order
of replacements withing a string *without* using a dictionary.
What I mean is:
s = %s and %s % ( A, B )
print s
A and B
Now, is there something quick like:
s = %s/2 and %s/1 % ( A, B )
print s
B and A
?
dictionary-key/value syntax), you can do something like:
number = lambda x: dict((str(i+1), v) for (i,v) in enumerate(x))
%(2)s and %(1)s % number([A, B])
Whoa - that'll take me a little while to figure out, but it looks intriguing!
Tah.
\d
--
New submission from Talin:
This patch contains documentation updates for the Python Library Reference
pertaining to PEP 3101 Advanced String Formatting.
--
components: Documentation
files: docupdates.diff
messages: 55526
nosy: talin
severity: normal
status: open
title: Documentation
Georg Brandl added the comment:
Thanks! Committed as part of rev. 57829.
--
assignee: - georg.brandl
nosy: +georg.brandl
resolution: - accepted
status: open - closed
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1068
Eric V. Smith added the comment:
Closed, code was checked in revision 57444.
--
versions: +Python 3.0 -Python 2.6
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1009
__
Eric V. Smith added the comment:
I tried to close it, without success. Possible tracker issue, I'll
investigate.
It should be closed!
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1009
__
Changes by Eric V. Smith:
--
versions: +Python 2.6
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1009
__
___
Python-bugs-list mailing list
Unsubscribe:
inconsisntency using string formatting
Initial Comment:
Sirs:
Using python to generate a text file for transfer of data between systems, I
seem to be getting inconsistent rounding results using a text formatting string
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32
: rounding inconsisntency using string formatting
Initial Comment:
Sirs:
Using python to generate a text file for transfer of data between systems, I
seem to be getting inconsistent rounding results using a text formatting string
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel
: rounding inconsisntency using string formatting
Initial Comment:
Sirs:
Using python to generate a text file for transfer of data between systems, I
seem to be getting inconsistent rounding results using a text formatting string
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel
Thanks guys!
I've used the HTML and the unicodedata suggestions, each on a
different report. These worked nicely!
Andy
--
http://mail.python.org/mailman/listinfo/python-list
Hi guys,
I'm writing a piece of software for some Thai friend. At the end it
is supposed to print on paper some report with tables of text and
numbers. When I test it in English, the columns are aligned nicely,
but when he tests it with Thai data, the columns are all crooked.
The problem here
En Wed, 27 Jun 2007 04:20:52 -0300, Andy [EMAIL PROTECTED] escribió:
I'm writing a piece of software for some Thai friend. At the end it
is supposed to print on paper some report with tables of text and
numbers. When I test it in English, the columns are aligned nicely,
but when he tests it
On Jun 27, 12:20 am, Andy [EMAIL PROTECTED] wrote:
Hi guys,
I'm writing a piece of software for some Thai friend. At the end it
is supposed to print on paper some report with tables of text and
numbers. When I test it in English, the columns are aligned nicely,
but when he tests it with
On Jun 27, 3:10 am, Leo Kislov [EMAIL PROTECTED] wrote:
On Jun 27, 12:20 am, Andy [EMAIL PROTECTED] wrote:
Hi guys,
I'm writing a piece of software for some Thai friend. At the end it
is supposed to print on paper some report with tables of text and
numbers. When I test it in English,
Hello alltogether,
is it possible to format stings with fixed width of let's say 7 character. T
need a floating point with 3 chars before dot, padded with ' ' and 3 chars
after
dot, padded with '0'.
Followingh is my approach
f = 21.1
s = %.03f % f
s
'21.100'
But there are missing ' '.
Hello alltogether,
is it possible to format stings with fixed width of let's say 7 character. T
need a floating point with 3 chars before dot, padded with ' ' and 3 chars
after
dot, padded with '0'.
Followingh is my approach
f = 21.1
s = %.03f % f
s
'21.100'
But there are missing ' '.
Alexander Eisenhuth wrote:
Hello alltogether,
is it possible to format stings with fixed width of let's say 7 character. T
need a floating point with 3 chars before dot, padded with ' ' and 3 chars
after
dot, padded with '0'.
Followingh is my approach
f = 21.1
s = %.03f % f
s
On 16 Mar, 13:20, Alexander Eisenhuth [EMAIL PROTECTED]
wrote:
Hello alltogether,
is it possible to format stings with fixed width of let's say 7 character. T
need a floating point with 3 chars before dot, padded with ' ' and 3 chars
after
dot, padded with '0'.
Followingh is my approach
Steve Holden wrote:
Alexander Eisenhuth wrote:
Hello alltogether,
is it possible to format stings with fixed width of let's say 7 character. T
need a floating point with 3 chars before dot, padded with ' ' and 3 chars
after
dot, padded with '0'.
Followingh is my approach
f = 21.1
Thanks for your fast reply. I'm fine with your %7.03f solution. (negatives
are
not significant)
Alexander Eisenhuth schrieb:
Hello alltogether,
is it possible to format stings with fixed width of let's say 7
character. T need a floating point with 3 chars before dot, padded with
' '
Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
decimal.Decimal class, but repeatedly instantiating Decimals is inefficient
for my
Darren Dale wrote:
Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
decimal.Decimal class, but repeatedly instantiating Decimals
Steve Holden wrote:
Darren Dale wrote:
Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
decimal.Decimal class, but repeatedly
On 2007-03-14, Steve Holden [EMAIL PROTECTED] wrote:
Darren Dale wrote:
Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
Steve Holden [EMAIL PROTECTED] writes:
Darren Dale wrote:
Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
decimal.Decimal
On Mar 14, 1:14 pm, Darren Dale [EMAIL PROTECTED] wrote:
Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
decimal.Decimal class,
[EMAIL PROTECTED] wrote:
On Mar 14, 1:14 pm, Darren Dale [EMAIL PROTECTED] wrote:
Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with
Fredrik Lundh [EMAIL PROTECTED] wrote:
lots of stuff to for me to download and read up
In the meantime, I have produced this evil hack, that takes advantage of the
difference in pixel widths between the space, and either the fullstop or the
single quote...
It will only work if you have quite
Hendrik van Rooyen wrote:
Is there a way to format this so it will line up with *any* font ?
I would prefer not to give up and use a fixed width font - it looks so
teletypish...
sounds like contradicting requirements to me.
instead of trying to force the listbox to behave like a
Fredrik Lundh [EMAIL PROTECTED] wrote:
instead of trying to force the listbox to behave like a multicolumn
widget, maybe you could switch to another widget? some alternatives include
a Text widget (you have to roll your own selection logic)
I _really_ don't feel strong enough for
Hendrik van Rooyen [EMAIL PROTECTED] wrote:
Fredrik Lundh [EMAIL PROTECTED] wrote:
instead of trying to force the listbox to behave like a multicolumn
widget, maybe you could switch to another widget? some alternatives include
a Text widget (you have to roll your own selection
I am populating a listbox from a directory that looks like this:
variable_dict = {funny_long_or_short_variable_name_as_key: (2,45),..
the tuple represents a card, line pair.
medf is a font object and a forward reference here.
I write:
for x in variable_dict:
txt = x
while
Peter Otten wrote:
Dustan wrote:
Is there any builtin function or module with a function similar to my
made-up, not-written deformat function as follows? I can't imagine it
would be too easy to write, but possible...
template = 'I am %s, and he %s last %s.'
values = ('coding',
My template outside of the '%s' characters contains only commas and
spaces, and within, neither commas nor spaces. Given that information,
is there any reason it might not work properly?
Given this new (key) information along with the assumption that
you're doing straight string replacement
Tim Chase wrote:
My template outside of the '%s' characters contains only commas and
spaces, and within, neither commas nor spaces. Given that information,
is there any reason it might not work properly?
Given this new (key) information along with the assumption that
you're doing
Dustan wrote:
Tim Chase wrote:
My template outside of the '%s' characters contains only commas and
spaces, and within, neither commas nor spaces. Given that information,
is there any reason it might not work properly?
Given this new (key) information along with the assumption that
Dustan wrote:
Dustan wrote:
Tim Chase wrote:
My template outside of the '%s' characters contains only commas and
spaces, and within, neither commas nor spaces. Given that information,
is there any reason it might not work properly?
Given this new (key) information along with
On 14 Oct 2006 05:35:02 -0700,
Dustan [EMAIL PROTECTED] wrote:
Is there any builtin function or module with a function similar to my
made-up, not-written deformat function as follows? I can't imagine it
would be too easy to write, but possible...
[ snip ]
Any input? I've looked through the
template = '%s, %s, %s'
values = ('Tom', 'Dick', 'Harry')
formatted = template % values
import re
unformat_string = template.replace('%s', '([^, ]+)')
unformatter = re.compile(unformat_string)
extracted_values = unformatter.search(formatted).groups()
using '[^, ]+' to mean
Only you know what anomalies will be found in your data-sets. If
you know/assert that
-the only stuff in the formatting string is one set of characters
-that stuff in the replacement-values can never include any of
your format-string characters
-that you're not using funky
Is there any builtin function or module with a function similar to my
made-up, not-written deformat function as follows? I can't imagine it
would be too easy to write, but possible...
template = 'I am %s, and he %s last %s.'
values = ('coding', coded', 'week')
formatted = template % values
template = 'I am %s, and he %s last %s.'
values = ('coding', coded', 'week')
formatted = template % values
formatted
'I am coding, and he coded last week.'
deformat(formatted, template)
('coding', 'coded', 'week')
expanded (for better visual):
deformat('I am coding, and he coded last
801 - 900 of 978 matches
Mail list logo