Linked Questions
40 questions linked to/from How can I selectively escape percent (%) in Python strings?
52
votes
6
answers
168k
views
ValueError: unsupported format character while forming strings [duplicate]
This works:
print "Hello World%s" %"!"
But this doesn't
print "Hello%20World%s" %"!"
the error is ValueError: unsupported format character 'W' (0x57) at index 8
I am using Python 2.7.
Why would I ...
41
votes
6
answers
127k
views
How do I print a '%' sign using string formatting? [duplicate]
I've made a little script to calculator percent; however, I wish to actually include the % within the message printed...
Tried this at the start - didn't work...
oFile.write("Percentage: %s%"...
19
votes
8
answers
26k
views
python, format string [duplicate]
I am trying to build a format string with lazy argument, eg I need smth like:
"%s \%s %s" % ('foo', 'bar') # "foo %s bar"
how can i do this?
10
votes
1
answer
57k
views
What is %% for in Python? [duplicate]
I'm trying to understand the following Python quine:
s = 's = %r\nprint(s%%s)'
print(s%s)
In particular, I'm having trouble finding any info about that %% part.
Anyone know what that does exactly, in ...
4
votes
4
answers
2k
views
How to include % in string formats in Python 2.7? [duplicate]
I am trying to append % in a string using string formats.
I am trying to get the below output:
a : [" name like '%FTa0213' "]
Try 1 :
a = [ ]
b = {'by_name':"FTa0213"}
a.append(" name like "%" %s'...
2
votes
4
answers
13k
views
Python string percent sign escape [duplicate]
I am experimenting some string outputs and I came across something that throws an error when printing
x = "ll=%s%2C%20%s" % ("lat", "lng")
The syntax above throws an error:
ValueError: unsupported ...
2
votes
2
answers
13k
views
Python string formatting special characters [duplicate]
How do you make the following code work?
example = "%%(test)%" % {'test':'name',}
print example
Where the desired output is "%name%"
Thanks
6
votes
3
answers
14k
views
Unsupported format character? [duplicate]
I am trying to print a line with a with a float formatter to 2 decimal points like this:
print "You have a discount of 20% and the final cost of the item is'%.2f' dollars." % price
But when I do ...
-2
votes
1
answer
13k
views
What is the string format "%g%%" mean in python 3? [duplicate]
According to python 3 document, the string formating "%%" means "a perncet sign".
Following code is an example:
"%g%%" % 10.34 == "10.34%"
I am not sure what does this "%g" mean here, I suspect it ...
-2
votes
2
answers
4k
views
What does '%%' mean in python? [duplicate]
I came across a problem when I was learning python.
print('test%d, %.2f%%' % (1,1.4))
however, it has an error.
ValueError: incomplete format
But if I execute like this:
print('test%d, %.2f%%' % (1,...
5
votes
1
answer
2k
views
Partial String Formatting in Python Logging Formatters [duplicate]
I'm looking for a way to perform partial string formatting in Python logging formatters.
When trying to define a formatter the following way:
formatter = logging.Formatter('[num-%d] %(levelname)s %(...
3
votes
2
answers
346
views
Python Using (%s) in a string that slo contains a (%)? [duplicate]
I have a string that contains a % that I ALSO want to use %s to replace a section of that string with a variable. Something like
name = 'john'
string = 'hello %s! You owe 10%.' % (name)
But when I ...
0
votes
2
answers
142
views
Anomaly in print statement in python [duplicate]
Suppose I have a print statement in python as given :
print "components required to explain 50% variance : %d" % (count)
This statement gives a ValuError, but if I have this print statement :
print "...
Jarvis's user avatar
- 8,602
0
votes
4
answers
297
views
python string formatting [duplicate]
I want to execute a git command, in shell it is as below:
$ git log v2.6.38..v2.6.38-rc8 --pretty=format:%s%n%n
the --pretty=format:%s%n%n is to say only show the commit subject message, and every ...
mike's user avatar
- 1,147
-2
votes
1
answer
90
views
How do I print '%' in a string that has '%s' in it? [duplicate]
I would like the output to be this
I'm using '%s' to print this out: hello!
My code:
print "I'm using %s to print this out: %s" % "hello!"
This returns an error.