473,394 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do you escape % when formatting a string?

Hi,

I'm trying to format a string like so:

string = "You have a 75% chance of success with %s, don't use %s" %(a,
b)

This gives me:
TypeError: not enough arguments for format string

I've tried 75\%, but that doesn't seem to help. What am I missing?

Thanks!
Erik

Apr 2 '07 #1
3 27011
On Apr 2, 10:50 pm, "erikcw" <erikwickst...@gmail.comwrote:
Hi,

I'm trying to format a string like so:

string = "You have a 75% chance of success with %s, don't use %s" %(a,
b)

This gives me:
TypeError: not enough arguments for format string

I've tried 75\%, but that doesn't seem to help. What am I missing?

Thanks!
Erik
Use %%.
>>"%d%%" % 75
"75"
Apr 2 '07 #2
On Apr 2, 10:52 pm, irs...@gmail.com wrote:
On Apr 2, 10:50 pm, "erikcw" <erikwickst...@gmail.comwrote:
Hi,
I'm trying to format a string like so:
string = "You have a 75% chance of success with %s, don't use %s" %(a,
b)
This gives me:
TypeError: not enough arguments for format string
I've tried 75\%, but that doesn't seem to help. What am I missing?
Thanks!
Erik

Use %%.
>"%d%%" % 75

"75"
Oups, I made a typo in the result which should've been "75%"

Apr 2 '07 #3

"erikcw" <er***********@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
| Hi,
|
| I'm trying to format a string like so:
|
| string = "You have a 75% chance of success with %s, don't use %s" %(a,
| b)
|
| This gives me:
| TypeError: not enough arguments for format string
|
| I've tried 75\%, but that doesn't seem to help. What am I missing?

The reference manual?

Apr 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ivo Woltring | last post by:
Dear Pythoneers, I have this app that I want to be able to present in more than 1 language. To do this I use ConfigParser with an ini file. My question: when I 'get()' the message with...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
2
by: | last post by:
Hi All, I am sending an email containing the string data for eg . string subject ="New client"; from my web service. I want that string data to be appearted as bold in the email. I know this...
4
by: Robert Manookian | last post by:
How do you format strings? i.e. In VB6: Format("AB34567", "@@@@@-@@") = "AB345-67" In .Net: ????????
2
by: Lester | last post by:
I need a regexp function which makes a match when the string contains <img...AND the img tag above dows NOT contain a certain path Here is what I have: <img\s.*(src).+> This matches if my...
3
by: preethi303 | last post by:
Hi, I'm using VB 2005 and I have a problem formatting a string when I use the print preview dialog box. I'm using just the vbCrLf character and the Space function to correctly align my data and...
3
by: Dave | last post by:
I'm calling string.Split() producing output string. I need direct access to its enumerator, but would greatly prefer an enumerator strings and not object types (as my parsing is unsafe casting...
5
by: MagnusBL | last post by:
Hi I am just experimenting a little with typecasting and string formatting. Given the small program using MFC and compiled in Visual Studio Express. short int i = 128; char c; CString str;...
4
by: bokisa | last post by:
Hi, I am having a problem with string property in my custom control. If I use \n \r... special chars in this property, they are replaced with escape quotes. Example: if I set next value: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.