473,288 Members | 2,350 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,288 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 1098
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.