Thanks -- a percent escapes itself when using %-formatting.
>
Stephen
>
step...@theboul ets.net wrote:
Hi all. How do I escape the "%" sign in a print statement so that it
prints? Thanks.
The following methods of getting answers to problems can be handy if
it's non-peak hours on the net or your internet connection is
broken/slow :
1. Reasoning: How do you get a literal "'" into an SQL string constant?
How do you get a literal "\" into a Python string constant? How do you
get a literal "$" into some *x shell command lines? Do you detect a
pattern?
2. Inspecting the documentation: in this case, it says:
"""% <tabNo argument is converted, results in a "%" character in the
result. """
If that is not sufficiently clear, can you suggest how it might be
improved?
In message <1159230293.270 822.50390@d34g2 000cwd.googlegr oups.com>, John
Machin wrote:
1. Reasoning: How do you get a literal "'" into an SQL string constant?
How do you get a literal "\" into a Python string constant? How do you
get a literal "$" into some *x shell command lines? Do you detect a
pattern?
None of which applies to escaping of % characters in format strings.
In message <1159230293.270 822.50390@d34g2 000cwd.googlegr oups.com>, John
Machin wrote:
>
>1. Reasoning: How do you get a literal "'" into an SQL string constant?
>How do you get a literal "\" into a Python string constant? How do you
>get a literal "$" into some *x shell command lines? Do you detect a
>pattern?
>
None of which applies to escaping of % characters in format strings.
Its the pattern of escaping here, and yes, it applies: usually, a escaping
character can be literally inserted by doubling it. I'm currently a bit
unsure of the single-quote for sql though, but I'm oscillating between ''
or '''. So - it applies.
In message <1159230293.270 822.50390@d34g2 000cwd.googlegr oups.com>, John
Machin wrote:
>
1. Reasoning: How do you get a literal "'" into an SQL string constant?
How do you get a literal "\" into a Python string constant? How do you
get a literal "$" into some *x shell command lines? Do you detect a
pattern?
>
None of which applies to escaping of % characters in format strings.
What I had in mind was:
where surname = 'O''REILLY'
install_dir = "C:\\Python 25"
....
print "The interest rate is %.2f%% p.a." % (rate * 100.0)
the common pattern being that the problem character is doubled.
In message <1159263309.699 677.301130@m7g2 000cwm.googlegr oups.com>, John
Machin wrote:
Lawrence D'Oliveiro wrote:
>In message <1159230293.270 822.50390@d34g2 000cwd.googlegr oups.com>, John
>Machin wrote:
>>
1. Reasoning: How do you get a literal "'" into an SQL string constant?
How do you get a literal "\" into a Python string constant? How do you
get a literal "$" into some *x shell command lines? Do you detect a
pattern?
>>
>None of which applies to escaping of % characters in format strings.
>
What I had in mind was:
>
where surname = 'O''REILLY'
install_dir = "C:\\Python 25"
...
print "The interest rate is %.2f%% p.a." % (rate * 100.0)
>
the common pattern being that the problem character is doubled.
Which doesn't apply to the "$" character in *nix shell command lines.
In message <1159263309.699 677.301130@m7g2 000cwm.googlegr oups.com>, John
Machin wrote:
>
Lawrence D'Oliveiro wrote:
In message <1159230293.270 822.50390@d34g2 000cwd.googlegr oups.com>, John
Machin wrote:
>
1. Reasoning: How do you get a literal "'" into an SQL string constant?
How do you get a literal "\" into a Python string constant? How do you
get a literal "$" into some *x shell command lines? Do you detect a
pattern?
>
None of which applies to escaping of % characters in format strings.
What I had in mind was:
where surname = 'O''REILLY'
install_dir = "C:\\Python 25"
...
print "The interest rate is %.2f%% p.a." % (rate * 100.0)
the common pattern being that the problem character is doubled.
>
Which doesn't apply to the "$" character in *nix shell command lines.
I'll take your word for it; it's been quite a while :-) *Something* in
the dim dark past worked like that; I thought maybe I was thinking of
m4, but that gets by without doubling.
Your score so far is 1 out of 3; you have two more to go to match your
original assertion "None of which applies...."
I'll take your word for it; it's been quite a while :-) *Something* in
the dim dark past worked like that
>
makefiles?
Bingo! Actually, double bingo!!
>From the docs for GNU Make:
"""
Because dollar signs are used to start make variable references, if you
really want a dollar sign in a target or prerequisite you must write
two of them, `$$' (see How to Use Variables). If you have enabled
secondary expansion (see Secondary Expansion) and you want a literal
dollar sign in the prerequisites lise [sic], you must actually write
four dollar signs (`$$$$').
"""
Comment