473,490 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

% sign in python?

What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)
Jul 17 '08 #1
9 6831
korean_dave wrote:
What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)
It's the string formatting operator:
http://docs.python.org/lib/typesseq-strings.html
Btw, a good place to start searching would be:
http://docs.python.org/lib/lib.html
especially:
http://docs.python.org/lib/genindex.html

Cheers
RB
Jul 17 '08 #2
The percent sign is a placeholder.

For example, if
level = 1
msg = 'look'

Then
'[[Log level %d: %s]]' % ( level, msg )
becomes
'[[Log level 1: look]]'

%d means insert an integer
%s means insert a string

You can also use dictionaries.
d = {'string1': 'hey', 'string2': 'you'}
Then
'%(string1)s %(string2)s' % d
becomes 'hey you'
On Thu, Jul 17, 2008 at 10:33 AM, korean_dave <da*********@gmail.comwrote:
What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)
--
http://mail.python.org/mailman/listinfo/python-list
Jul 17 '08 #3


korean_dave wrote:
What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)
Having seen a number of comments like this over the years (about the
difficulty of searching for symbol meanings), I just started, last
night, a symbol index listing nearly all Python syntax uses of
non-alpha-or-digit ascii symbols. When I finish and upload it
somewhere, I will post an announcement with the link.

tjr

Jul 17 '08 #4
Terry Reedy wrote:
>

korean_dave wrote:
>What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)

Having seen a number of comments like this over the years (about the
difficulty of searching for symbol meanings), I just started, last
night, a symbol index listing nearly all Python syntax uses of
non-alpha-or-digit ascii symbols. When I finish and upload it
somewhere, I will post an announcement with the link.

tjr

--
http://mail.python.org/mailman/listinfo/python-list
I thought, in this contexted, it was mapping operator.
sph
Jul 17 '08 #5
On Jul 17, 3:42*pm, Terry Reedy <tjre...@udel.eduwrote:
korean_dave wrote:
What does this operator do? Specifically in this context
test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)

Having seen a number of comments like this over the years (about the
difficulty of searching for symbol meanings), I just started, last
night, a symbol index listing nearly all Python syntax uses of
non-alpha-or-digit ascii symbols. *When I finish and upload it
somewhere, I will post an announcement with the link.

tjr
That sounds great Terry! I look forward to seeing this.

~Jordan
Jul 17 '08 #6
Steven Howe <ho*********@gmail.comwrote:
>Terry Reedy wrote:
>>
korean_dave wrote:
>>What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

I thought, in this contexted, it was mapping operator.
What??

Python does not have a "mapping operator". It has a "map" function, but no
equivalent operator.

% is either the string formatting operator (when the left-hand operand is a
string) or the modulo operator (when the left-hand operand is a number).
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '08 #7


Tim Roberts wrote:
Steven Howe <ho*********@gmail.comwrote:
>Terry Reedy wrote:
>>korean_dave wrote:
What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
I thought, in this contexted, it was mapping operator.
You miss clipped. I never wrote that. Please be careful, especially
about attributing mis-information.
What??

Python does not have a "mapping operator". It has a "map" function, but no
equivalent operator.

% is either the string formatting operator (when the left-hand operand is a
string) or the modulo operator (when the left-hand operand is a number).
Which I learned 10 years ago. What I did write was a pre-announcement
of a Python symbol glossary, which I just finished a first draft of.
And now to bed ;-)

Jul 18 '08 #8
Terry Reedy wrote:
>

korean_dave wrote:
>What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)

Having seen a number of comments like this over the years (about the
difficulty of searching for symbol meanings), I just started, last
night, a symbol index listing nearly all Python syntax uses of
non-alpha-or-digit ascii symbols. When I finish and upload it
somewhere, I will post an announcement with the link.

tjr
This will be excellent, Terry.

For the present case, perhaps we should also point out that in
python 3.0:

" Note

The formatting operations described here are obsolete and may go away in
future versions of Python. Use the new String Formatting in new code."

(Taken from the provisional documentation at:

http://docs.python.org/dev/3.0/libra...ing-formatting
)
Jul 18 '08 #9
Terry Reedy <tj*****@udel.eduwrote:
>
Tim Roberts wrote:
>Steven Howe <ho*********@gmail.comwrote:
>>Terry Reedy wrote:
korean_dave wrote:
What does this operator do? Specifically in this context
>
test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

I thought, in this contexted, it was mapping operator.

You miss clipped. I never wrote that. Please be careful, especially
about attributing mis-information.
If you count the signs, you'll see that I correctly attributed the
question to korean_dave, and the answer to Steve Howe. Steve's reply
contained your name, but there was no text from you in my post.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 21 '08 #10

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

Similar topics

3
4118
by: sarmin | last post by:
Hi Pythoners... It seems to me the Asterisk (*) sign in python means many things... if a python code line looks like this: def__init__(self, func, *param): bla bla bla... and then u have...
29
22108
by: Mark Hahn | last post by:
We are considering switching to the dollar sign ($) for self, instead of the period ( . ) we are using now in Prothon. Ruby uses the at-sign (@) for self, but our new usage of self also includes...
34
4060
by: Blake T. Garretson | last post by:
I want to save some sensitive data (passwords, PIN numbers, etc.) to disk in a secure manner in one of my programs. What is the easiest/best way to accomplish strong file encryption in Python? ...
217
8933
by: gyromagnetic | last post by:
The following url points to an article written by Damian Conway entitled "Ten Essential Development Practices": http://www.perl.com/pub/a/2005/07/14/bestpractices.html Althought the article has...
10
3263
by: jantod | last post by:
I think there might be something wrong with the implementation of modulus. Negative float values close to 0.0 break the identity "0 <= abs(a % b) < abs(b)". print 0.0 % 2.0 # => 0.0 print...
0
1426
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 407 open ( +3) / 3393 closed (+17) / 3800 total (+20) Bugs : 888 open (+28) / 6145 closed (+14) / 7033 total (+42) RFE : 232 open...
0
2021
by: yrogirg | last post by:
Actually, I need utf-8 to utf-8 encoding which would change the text to another keyboard layout (e.g. from english to russian ghbdtn -> ÐÒÉ×ÅÔ) and would not affect other symbols. I`m totally...
3
7889
by: Marcin Jurczuk | last post by:
Hello, I'm fighting with Certificate Authority functionality with python I stuck on following problem: How to sign CSR using CA key and write resulted certificate. You can do it using following...
0
7142
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
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7352
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...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.