473,573 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1106
Skye <sp****@gmail.c omwrites:
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.c a
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*********@gma il.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
2120
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 construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No...
7
11761
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
3125
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 internally by compilers (well, not so internally, since they appear in header files). I personally use the leading underscore (followed by a lower case...
3
6437
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 COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too...
4
1605
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 correctly, until I discovered that my new version of PHP 4.4 disabled global variables. I figured out how to make the following php script work...
6
340
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
2623
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 someone set me on the right path to what modules and calls to use to do that? You'd think that it would be a fairly simple proposition, but I can't...
2
1168
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 up with one =>underscore. Unless I'm missing something, there's a idiom going on here. => =>Why do people sometimes use one leading underscore? ...
14
2106
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 couldn't compile the class. Any hints that I'm missing? Header File: #ifndef __Calc_h__
0
7793
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8222
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7800
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8092
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2230
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 we have to send another system
0
1049
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.