double-underscore

How is __mro__ different from other double underscore names?

♀尐吖头ヾ 提交于 2019-12-13 13:26:03
问题 I stumbled upon this behavior for double underscore name that I don't understand: class A: pass class B: pass class C(A,B): __id__ = 'c' c = C() print(C.__mro__) # print the method resolution order of class C #print(c.__mro__) # AttributeError: 'C' object has no attribute '__mro__' print(C.__id__) # print 'c' print(c.__id__) # print 'c' I know about the name mangling for __name , which doesn't apply for __name__ (more for overloading operator methods). __id__ behaves just like a regular class

Import __module__ python: why the underscores?

喜欢而已 提交于 2019-12-10 16:01:21
问题 I am new to Python, and have started working on code written by others. In the source of packages downloaded from Pypi I have noticed the use of import __module__ to use functions and classes defined in the src folder of packages. Is this common practice? I actually can't really understand this kind of syntax, could you explain it to me or send me to some reference? 回答1: It's a python convention for some builtin objects. From PEP8: __double_leading_and_trailing_underscore__ : "magic" objects

Filtering out choiceless polls in the Django tutorial causes polls in the index to duplicate

被刻印的时光 ゝ 提交于 2019-12-06 17:27:57
I've edited the code from the tutorial for the index view to look like this: class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_poll_list' def get_queryset(self): """ Return the last five published polls (not including those set to be published in the future, or those without choices). """ return Poll.objects.filter( pub_date__lte=timezone.now(), choice__choice_text__isnull=False ).order_by('-pub_date')[:5] But now my index looks like this: What're you up to? What're you up to? What're you up to? Whats up? Whats up? How has this happened? And

What does underscoring methods connote?

旧城冷巷雨未停 提交于 2019-12-06 02:47:13
问题 I am relatively new to the Python language and encountered this in doing the following: help(list) Here is what I encountered: __add__(...) | x.__add__(y) <==> x+y | | __contains__(...) | x.__contains__(y) <==> y in x | | __delitem__(...) | x.__delitem__(y) <==> del x[y] Regarding these, what are the underscores for? Because they aren't used (to my knowledge) when you use a method normally, I'm struggling to understand why they'd take the time to write them out with underscores in the

Ruby variable name with double underscores

久未见 提交于 2019-11-30 13:46:54
Sometimes I see variable names with double underscore in the beginning and the end. For example: Article.__elasticsearch__ Is there some naming convention related to double underscores in Ruby variable names? An initial underscore or double underscore basically indicates "special/avoid overwrite" --meaning it's meant to reduce the likelihood that someone else might define a method/attribute of the same name. The most common occurrence is __send__ . From Ruby Forum The author of the ElasticSearch gem made the wrong call IMO. At the end of the thread, Avdi Grimm, who is well-known in the Ruby

Underscore in php function

吃可爱长大的小学妹 提交于 2019-11-29 09:34:20
问题 What does it mean when a PHP function name begins with an underscore? for example: __construct() I know what the construct means but I've seen other places where the function begins with an underscore, or a double underscore and I'm just not sure of the significance. 回答1: It means that PHP calls it implicitly. It's called a 'Magic Method' Also, it's two underscores, not one. Learn more here: PHP Magic Methods 回答2: In PHP, functions start with two underscores usually have special meanings.

Using '__progname' instead of argv[0]

老子叫甜甜 提交于 2019-11-28 11:57:26
In the C / Unix environment I work in, I see some developers using __progname instead of argv[0] for usage messages. Is there some advantage to this? What's the difference between __progname and argv[0] . Is it portable? __progname isn't standard and therefore not portable, prefer argv[0] . I suppose __progname could lookup a string resource to get the name which isn't dependent on the filename you ran it as. But argv[0] will give you the name they actually ran it as which I would find more useful. Using __progname allows you to alter the contents of the argv[] array while still maintaining

What is this double underscore in Cocoa

孤街醉人 提交于 2019-11-27 21:40:02
The single underscore in Objective-C is apparently reserved for Apple's "internal" use (and was available for use with private instance variables prior to Apple's claim). But why would they use a double -underscore in their SQLiteBooks example for the iPhone? See this snippet taken from MasterViewController.m: + (EditingViewController *)editingViewController { // Instantiate the editing view controller if necessary. if (__editingViewController == nil) { __editingViewController = [[EditingViewController alloc] initWithNibName:@"EditingView" bundle:nil]; } return __editingViewController; } There

Double Underscore in PHP?

本小妞迷上赌 提交于 2019-11-27 04:56:58
What does the double underscores in these lines of PHP code mean? $WPLD_Trans['Yes']=__('Yes',$WPLD_Domain); $WPLD_Trans['No']=__('No',$WPLD_Domain); Looks like you're using Wordpress - wp-includes/l10n.php defines __ as a function that translates a string (similar to gettext and its alias, _ but with an optional parameter for explicitly specifying a domain). Strictly speaking, it means nothing in PHP as it is not a pre-defined function. However, in many frameworks, like CakePHP, and other libraries the double underscore is a function used for translating strings based on the user's language

What is this double underscore in Cocoa

99封情书 提交于 2019-11-26 23:05:06
问题 The single underscore in Objective-C is apparently reserved for Apple's "internal" use (and was available for use with private instance variables prior to Apple's claim). But why would they use a double -underscore in their SQLiteBooks example for the iPhone? See this snippet taken from MasterViewController.m: + (EditingViewController *)editingViewController { // Instantiate the editing view controller if necessary. if (__editingViewController == nil) { __editingViewController = [