Re: Does underscore has any special built-in meaningin Python ?
In article 062813eb-7eec-4504-b32c-abadf02c3...@12g2000pri.googlegroups.com, dandi kain dandi.k...@gmail.com wrote: What is the functionality of __ or _ , leading or trailing an object , class ot function ? Is it just a naming convention to note special functions and objects , or it really mean someting to Python ? One more thing: if you have global module names with a single leading underscore (e.g. _foo), they will not be loaded when you use from module import * However, import * is strongly discouraged for the most part. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important. --Henry Spencer -- http://mail.python.org/mailman/listinfo/python-list
Re: Does underscore has any special built-in meaningin Python ?
a...@pythoncraft.com (Aahz) writes: One more thing: if you have global module names with a single leading underscore (e.g. _foo), they will not be loaded when you use from module import * However, import * is strongly discouraged for the most part. Dude, that's exactly the “underscore has an effect on import but as a beginner don't worry about it” that I avoided drawing attention to. The explanation was just fine without that. But no, you have to find a way to *contribute*, don't you? Things were different before all these new-fangled changes, I say. Get off my lawn. -- \ “I love and treasure individuals as I meet them, I loathe and | `\ despise the groups they identify with and belong to.” —George | _o__) Carlin, 2007 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Does underscore has any special built-in meaningin Python ?
Ben Finney a écrit : dandi kain dandi.k...@gmail.com writes: What is the functionality of __ or _ , leading or trailing an object , class ot function ? OP Please note that in Python, classes and functions are objects too. But anyway, these underscores are part of *identifiers*, not objects themselves !-) /OP foo Ordinary name, part of public interface _foo Ordinary name, part of internal-only interface __fooOrdinary name, but will be mangled (this style used rarely) __foo__ Name which is used in a special way by Python And FWIW: foo_ When you want to use a reserved name for identifier (ie: 'class_' , 'or_', 'and_' etc) -- http://mail.python.org/mailman/listinfo/python-list
Does underscore has any special built-in meaningin Python ?
Hello everybody, I have just started learning Python.I heard its simple so I pick a presentation [1] and tried to work on it.But when it comes to underscores leading and trailing an object I dont understand any.I look through the python manual also but that was not helping .I searched some forums and I still dont have a clear picture. What is the functionality of __ or _ , leading or trailing an object , class ot function ? Is it just a naming convention to note special functions and objects , or it really mean someting to Python ? Thanks ahead , [1] http://www.aleax.it/goo_py4prog.pdf -- http://mail.python.org/mailman/listinfo/python-list
Re: Does underscore has any special built-in meaningin Python ?
On Wed, Jul 29, 2009 at 1:59 PM, dandi kain dandi.k...@gmail.com wrote: Hello everybody, I have just started learning Python.I heard its simple so I pick a presentation [1] and tried to work on it.But when it comes to underscores leading and trailing an object I dont understand any.I look through the python manual also but that was not helping .I searched some forums and I still dont have a clear picture. What is the functionality of __ or _ , leading or trailing an object , class ot function ? Is it just a naming convention to note special functions and objects , or it really mean someting to Python ? It's just a convention for the most part. A single leading underscore is used for private attributes. Two leading underscores will affect the code- it mangles the variable name so that you don't have to worry about the value being overwritten by a subclass. For instance class Foo(object) : def __init__(self) : self.__bar = '' foo = Foo() will store the attribute as foo._Foo__bar. Also, the magic methods- the ones that are used for operations and built-in stuff, all have two leading and two trailing underscores. These are things like __add__ (+), __eq__ (=), __cmp__ (old way for comparisons), __len__ (len), __str__ (str), and so on. Thanks ahead , [1] http://www.aleax.it/goo_py4prog.pdf -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Does underscore has any special built-in meaningin Python ?
29-07-2009 Benjamin Kaplan benjamin.kap...@case.edu wrote: On Wed, Jul 29, 2009 at 1:59 PM, dandi kain dandi.k...@gmail.com wrote: [snip What is the functionality of __ or _ , leading or trailing an object , class ot function ? Is it just a naming convention to note special functions and objects , or it really mean someting to Python ? It's just a convention for the most part. A single leading underscore is used for private attributes. Two leading underscores will affect the code- Single leading underscore in some situations also affect the code... See: * http://docs.python.org/reference/lexical_analysis.html#reserved-classes-of-identifiers * http://docs.python.org/reference/datamodel.html#object.__del__ (in the the red Warning frame) -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list
Re: Does underscore has any special built-in meaningin Python ?
Benjamin Kaplan wrote: On Wed, Jul 29, 2009 at 1:59 PM, dandi kain dandi.k...@gmail.com wrote: Hello everybody, I have just started learning Python.I heard its simple so I pick a presentation [1] and tried to work on it.But when it comes to underscores leading and trailing an object I dont understand any.I look through the python manual also but that was not helping .I searched some forums and I still dont have a clear picture. What is the functionality of __ or _ , leading or trailing an object , class ot function ? Is it just a naming convention to note special functions and objects , or it really mean someting to Python ? It's just a convention for the most part. A single leading underscore is used for private attributes. Two leading underscores will affect the code- it mangles the variable name so that you don't have to worry about the value being overwritten by a subclass. For instance class Foo(object) : def __init__(self) : self.__bar = '' foo = Foo() will store the attribute as foo._Foo__bar. Also, the magic methods- the ones that are used for operations and built-in stuff, all have two leading and two trailing underscores. These are things like __add__ (+), __eq__ (=), __cmp__ (old way for comparisons), __len__ (len), __str__ (str), and so on. For this last, see http://docs.python.org/dev/py3k/reference/datamodel.html#special-method-names -- http://mail.python.org/mailman/listinfo/python-list
Re: Does underscore has any special built-in meaningin Python ?
On Jul 30, 3:59 am, dandi kain dandi.k...@gmail.com wrote: What is the functionality of __ or _ , leading or trailing an object , class ot function ? Is it just a naming convention to note special functions and objects , or it really mean someting to Python ? I think everyone else has covered what you need to know, but there's still one remaining pseudo-convention you might see in Python code, and that's using _ as a label to indicate that you don't care about the value it holds. Overly simplistic example: data_set = [('gold','junk'),('gold','junk'),...] for keep, _ in data_set: ... It's a convenient way of not having to come up with a label for something you're not going to use, although arguably you get the same effect with names like 'dummy', 'ignore' etc. Not everyone agrees with this usage but you _will_ see it in use in other people's code, so it helps to have a heads up. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does underscore has any special built-in meaningin Python ?
dandi kain dandi.k...@gmail.com writes: What is the functionality of __ or _ , leading or trailing an object , class ot function ? There is no change in functionality. It has some slight effects on import, but as a beginner you shouldn't need to worry about that. Is it just a naming convention to note special functions and objects , or it really mean someting to Python ? Both. It's a strongly-adhered-to naming convention, as an indicator to the reader how that name should be used. foo Ordinary name, part of public interface _foo Ordinary name, part of internal-only interface __fooOrdinary name, but will be mangled (this style used rarely) __foo__ Name which is used in a special way by Python There's no change in the objects themselves; the underscores rather indicate how those names are expected to be accessed. -- \ “Pinky, are you pondering what I'm pondering?” “I think so, | `\ Brain, but Tuesday Weld isn't a complete sentence.” —_Pinky and | _o__) The Brain_ | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list