473,394 Members | 1,699 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.

Newb question: underscore

What is this doing?

print >fd, _(__doc__)
I'm guessing line-splitting __doc__ into a list, but what's that
leading underscore do?

Thanks!
Jun 27 '08 #1
9 1100
Skye <sp****@gmail.comwrites:
What is this doing?

print >fd, _(__doc__)
Without any context, it's impossible to know.
I'm guessing line-splitting __doc__ into a list, but what's that
leading underscore do?
Look at the rest of the module to see where that name comes from;
perhaps an assignment, or an 'import foo as _'.

My guess would be someone has used the common convention of naming the
"get the corresponding localised version of this string from the
application's gettext database" function as '_' for convenience.

That's only a guess though; you should believe the code you have in
front of you, not my guesses.

--
\ "Pinky, are you pondering what I'm pondering?" "Well, I think |
`\ so, Brain, but 'apply North Pole' to what?" -- _Pinky and The |
_o__) Brain_ |
Ben Finney
Jun 27 '08 #2
Skye wrote:
What is this doing?

print >fd, _(__doc__)
I'm guessing line-splitting __doc__ into a list, but what's that
leading underscore do?
It's calling a function with a single argument, like sqrt(x), except the
function is named _ and the argument is named __doc__. The underscores
have no special significance here, but they do make the code hard to read.

The first part of the statement directs the print to send the output to
a file, named fd, which was presumably opened earlier ... but I don't
think that was part of your question.

Gary Herron
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #3
Ohh, it's a function _() call. Now it makes sense.

Of course Python would be consistent... I was expecting trickery!

It's actually from the Mailman source, def _(s) is a string function
for i18n

Thanks,
Skye

Jun 27 '08 #4
My guess would be someone has used the common convention of naming the
"get the corresponding localised version of this string from the
application's gettext database" function as '_' for convenience.
Funny that this comes up.

I just noticed this in some code I was looking at the other day. A
number of statements in the form:

print _(something)

My question is: Why would anyone decide to obfuscate something as easy
to read as Python??? At first I thought that they were making a function
out of print (which makes some sense), but I don't think that is the
case. I tried (not very hard) to trace back the code to figure out where
_() is being assigned, but gave up. Oh, this is in the gdesklets package
if anyone is interested.
**** Listen to my CD at http://www.mellowood.ca/music/cedars ****
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bo*@mellowood.ca
WWW: http://www.mellowood.ca

Jun 27 '08 #5
Skye wrote:
What is this doing?

print >fd, _(__doc__)
I'm guessing line-splitting __doc__ into a list, but what's that
leading underscore do?

Thanks!
I think it is standard practice to use the underscore for unicode converts.
Jun 27 '08 #6
bvdp <bo*@mellowood.cawrites:
My question is: Why would anyone decide to obfuscate something as easy
to read as Python???
They didn't decide to obfuscate; they decided to follow a
strongly-expected convention for the name of that function by existing
users of the 'gettext' functionality, in contexts that predate the
appearance of that functionality in Python.

--
\ Hercules Grytpype-Thynne: "Well, Neddie, I'm going to be |
`\ frank." Ned Seagoon: "Right, I'll be Tom." Count Moriarty: |
_o__) "I'll be Gladys." *slap* -- The Goon Show, _World War I_ |
Ben Finney
Jun 27 '08 #7
My question is: Why would anyone decide to obfuscate something as easy
to read as Python???

They didn't decide to obfuscate; they decided to follow a
strongly-expected convention for the name of that function by existing
users of the 'gettext' functionality, in contexts that predate the
appearance of that functionality in Python.
Well _ can also mean the previous output statement that wasn't null,
so it has OTHER uses...
Jun 27 '08 #8
co*********@gmail.com a écrit :
>>My question is: Why would anyone decide to obfuscate something as easy
to read as Python???
They didn't decide to obfuscate; they decided to follow a
strongly-expected convention for the name of that function by existing
users of the 'gettext' functionality, in contexts that predate the
appearance of that functionality in Python.

Well _ can also mean the previous output statement that wasn't null,
In the shell only IIRC.

Jun 27 '08 #9
John Fabiani a écrit :
Skye wrote:
>What is this doing?

print >fd, _(__doc__)
I'm guessing line-splitting __doc__ into a list, but what's that
leading underscore do?

Thanks!
I think it is standard practice to use the underscore for unicode converts.
Actually, it's for i18n, not for encoding.
Jun 27 '08 #10

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

Similar topics

0
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
7
by: csx | last post by:
Hi everyone! two quick questions relating to arrays. Q1, Is it possible to re-assign array elements? int array = {{2,4}, {4,5}}; array = {2,3}
5
by: Walter Tross | last post by:
Somebody with a very regulatory mind in this newsgroup has written that it's better not to use a leading underscore for class member names, because names with a leading underscore are used...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
4
by: Pete Horm | last post by:
Hi everyone, I have a question about using this variable. I am new to programming and I had a book that was a couple of years old regarding php programming. None of the examples were working...
6
by: aurelien.chanudet | last post by:
Hi all, Can someone tell me about the difference between these two statements ? char *string = _("foo"); char *string = "foo"; Thanks, Aurelien
29
by: jaysherby | last post by:
I'm new at Python and I need a little advice. Part of the script I'm trying to write needs to be aware of all the files of a certain extension in the script's path and all sub-directories. Can...
2
by: Steven W. Orr | last post by:
On Friday, Feb 23rd 2007 at 11:12 -0500, quoth Steven W. Orr: =>I understand that two leading underscores in a class attribute make the =>attribute private. But I often see things that are coded...
14
by: Alexander Dong Back Kim | last post by:
Dear all, I used to use C++ programming language at all time but moved to C# and Java. Few days ago, I restarted studying about C++ with a very beginner's mind. I wrote a simple class and gcc...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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.