Re: [Tutor] __init__

2016-09-06 Thread Steven D'Aprano
On Mon, Sep 05, 2016 at 12:24:50PM +, Albert-Jan Roskam wrote: > => Aha, thank you, I did not know that. So for Python-3-only code, > the idiom is "class SomeClass:", and for Python2/3 code "class > SomeClass(object)". I prefer to explicitly inherit from object regardless of which versi

Re: [Tutor] __init__

2016-09-05 Thread Albert-Jan Roskam
From: Tutor on behalf of Steven D'Aprano Sent: Thursday, September 1, 2016 1:24 AM To: tutor@python.org Subject: Re: [Tutor] __init__   On Wed, Aug 31, 2016 at 06:35:44PM +, Albert-Jan Roskam wrote: > > >In Python 3, old-style classes are gone. Even in Python 2, they'

Re: [Tutor] __init__

2016-08-31 Thread Steven D'Aprano
On Wed, Aug 31, 2016 at 06:35:44PM +, Albert-Jan Roskam wrote: > > >In Python 3, old-style classes are gone. Even in Python 2, they're > >discouraged. > > This suggests that old-style classes are still used, even in Python 3, > doesn't it? > > albertjan@debian:~$ python3.5 > Python 3.5.0 (

Re: [Tutor] __init__

2016-08-31 Thread monik...@netzero.net
Thank you very much. This was very helpful. -- Original Message -- From: Steven D'Aprano To: tutor@python.org Subject: Re: [Tutor] __init__ Date: Wed, 31 Aug 2016 22:39:33 +1000 On Wed, Aug 31, 2016 at 04:05:26AM +, monik...@netzero.net wrote: > Somebody in this

Re: [Tutor] __init__

2016-08-31 Thread Albert-Jan Roskam
>In Python 3, old-style classes are gone. Even in Python 2, they're >discouraged. This suggests that old-style classes are still used, even in Python 3, doesn't it? albertjan@debian:~$ python3.5 Python 3.5.0 (default, Apr 13 2016, 20:39:27) [GCC 4.9.2] on linux Type "help", "copyright", "cred

Re: [Tutor] __init__

2016-08-31 Thread Steven D'Aprano
On Tue, Aug 30, 2016 at 09:08:13PM +, monik...@netzero.net wrote: > OK so somebodys remark that there is a default __init__ provided was not > correct. It is correct. The default __init__ is provided by object, the root of the class hierarchy. > What about old style classes? When we have a

Re: [Tutor] __init__

2016-08-31 Thread Steven D'Aprano
On Wed, Aug 31, 2016 at 04:05:26AM +, monik...@netzero.net wrote: > Somebody in this line of emails mentioned that python provides default > __init__ if it its not stated in the class by the programmer. And that > it is called by __new__ That may have been me, except I didn't mention __new_

Re: [Tutor] __init__

2016-08-31 Thread monik...@netzero.net
o.net" Cc: tutor@python.org Subject: Re: [Tutor] __init__ Date: Wed, 31 Aug 2016 00:25:42 +0100 On 30/08/16 22:08, monik...@netzero.net wrote: > OK so somebodys remark that there is a default __init__ provided was not > correct. It depends on how you interpret default. In so far

Re: [Tutor] __init__

2016-08-30 Thread Alan Gauld via Tutor
On 30/08/16 22:08, monik...@netzero.net wrote: OK so somebodys remark that there is a default __init__ provided was not correct. It depends on how you interpret default. In so far as object is the default superclass (in v3) and it provides an init then there is a default, but its not part of

Re: [Tutor] __init__

2016-08-30 Thread monik...@netzero.net
Message -- From: Alan Gauld via Tutor To: tutor@python.org Subject: Re: [Tutor] __init__ Date: Tue, 30 Aug 2016 21:37:44 +0100 On 30/08/16 17:59, monik...@netzero.net wrote: > Assume you have a child class with no init, but it has empty, > default __init__ provided by pathon It in

Re: [Tutor] __init__

2016-08-30 Thread Alan Gauld via Tutor
On 30/08/16 17:59, monik...@netzero.net wrote: Assume you have a child class with no init, but it has empty, > default __init__ provided by pathon It inherits the empty init from object. and the same for its parent class. When instantiating child class, > child class's __new__ calls its __

Re: [Tutor] __init__

2016-08-30 Thread Alan Gauld via Tutor
On 30/08/16 12:50, eryksun wrote: On Tue, Aug 30, 2016 at 9:09 AM, Alan Gauld via Tutor wrote: new() that sets up the memory then calls init(). So init is only used to initialise the object after it has been constructed. __new__ and __init__ are called by the metaclass __call__ method. __init

Re: [Tutor] __init__

2016-08-30 Thread monik...@netzero.net
tantiating child class, child class's __new__ calls its ___init__ in child class and then calls __init__ in parent class? Why does it not just use the default, provided by python __init__ since it found it? -- Original Message -- From: Alan Gauld via Tutor To: tutor@pytho

Re: [Tutor] __init__

2016-08-30 Thread eryk sun
On Tue, Aug 30, 2016 at 9:09 AM, Alan Gauld via Tutor wrote: > new() that sets up the memory then calls init(). So init is > only used to initialise the object after it has been > constructed. __new__ and __init__ are called by the metaclass __call__ method. __init_ is called if __new__ returns a

Re: [Tutor] __init__

2016-08-30 Thread Alan Gauld via Tutor
On 29/08/16 23:52, monik...@netzero.net wrote: I cannot really try it. If I have a class without __init__ and the class does not > inherit from a class that has init there is really no place > for me to put print statement. Fair enough but in that case there is no __init__ to call. The top l

Re: [Tutor] __init__

2016-08-30 Thread monik...@netzero.net
. Does python call default __init__ if one is not defined? In two python classes that I took both teachers gave a different answers. -- Original Message -- From: Alan Gauld via Tutor To: tutor@python.org Subject: Re: [Tutor] __init__ Date: Mon, 29 Aug 2016 23:10:30 +0100 On 29/08

Re: [Tutor] __init__

2016-08-29 Thread Steven D'Aprano
On Mon, Aug 29, 2016 at 07:03:31PM +, monik...@netzero.net wrote: > > > Hi: > If __init__ is not defined in a class, will it be called when creating an > instance? Yes, because the default __init__ does nothing. So if you don't need an __init__, just don't bother to write it! Try experimen

Re: [Tutor] __init__

2016-08-29 Thread Joel Goldstick
On Mon, Aug 29, 2016 at 3:03 PM, monik...@netzero.net wrote: > > > Hi: > If __init__ is not defined in a class, will it be called when creating an > instance? > What in a case if this class inherits from parent with __init__ and without > __init__? > Thank you > Monika >

Re: [Tutor] __init__

2016-08-29 Thread Alan Gauld via Tutor
On 29/08/16 20:03, monik...@netzero.net wrote: If __init__ is not defined in a class, will it be called when creating an instance? What in a case if this class inherits from parent with __init__ and without __init__? The easiest way to find out is try it and see what happens! Just put appro

Re: [Tutor] __init__ argument

2013-03-15 Thread Steven D'Aprano
On 16/03/13 09:46, Joshua Wilkerson wrote: The program keeps telling me that the __init__ in Rock takes two arguments and only one is given. Ideas? Yes. You need to look at the arguments required when you construct a Rock() instance, and compare it to the arguments actually given. [snip ir

Re: [Tutor] __init__ argument

2013-03-15 Thread Dave Angel
On 03/15/2013 06:46 PM, Joshua Wilkerson wrote: The program keeps telling me that the __init__ in Rock takes two arguments and only one is given. Ideas? The point of the game is to dodge falling rocks. Two more appear every time one reaches the bottom of the screen. # Avalanche, a dodging game

Re: [Tutor] __init__ doesn't seem to be running

2013-03-15 Thread Dave Angel
(By top-posting, you lost all the context. Next time, post your responses AFTER the part you're quoting. And don't just quote it all, only the part that's relevant.) On 03/15/2013 06:25 PM, Cameron Macleod wrote: I added the "self." to both the references to tasks and then I added the print

Re: [Tutor] __init__ doesn't seem to be running

2013-03-15 Thread Hugo Arts
On Fri, Mar 15, 2013 at 10:25 PM, Cameron Macleod < cmacleod...@googlemail.com> wrote: > I added the "self." to both the references to tasks and then I added the > print statement to the __init__ function and I got the dreaded NameError of > death: > > > Traceback (most recent call last): > File

Re: [Tutor] __init__ doesn't seem to be running

2013-03-15 Thread Cameron Macleod
I added the "self." to both the references to tasks and then I added the print statement to the __init__ function and I got the dreaded NameError of death: Traceback (most recent call last): File "C:\Python33\todo.py", line 6, in class todo: File "C:\Python33\todo.py", line 31, in todo

Re: [Tutor] __init__ doesn't seem to be running

2013-03-15 Thread Hugo Arts
On Fri, Mar 15, 2013 at 9:21 PM, Cameron Macleod wrote: > Hello everyone, I'm using Python 3.3 and am trying to write a simple to-do > list program. I have a class which runs pretty much everything called todo > and the __init__ method doesn't seem to be running. > > class todo(): > def __ini

Re: [Tutor] __init__.py question

2011-06-02 Thread Marilyn Davis
Thank you for your careful explanation, Steven. I guess there's nothing more for me to know. While I think it is a mistake to put directories in your package directory structure that aren't part of the package, that seems to be all it's about. Well, I guess I don't feel quite so stupid. Thank y

Re: [Tutor] __init__.py question

2011-06-01 Thread Steven D'Aprano
Marilyn Davis wrote: [...] There's something I'm missing because I think you simply can't call something string.py unless you are willing to give up the library string.py. No, you're right about that. Python's search path is "first match wins". Whether it's a package or a module, it will match

Re: [Tutor] __init__.py question

2011-06-01 Thread Alexandre Conrad
2011/6/1 Marilyn Davis : > Maybe I'm getting what you say, Alexandre and Ramit. > > When you import logging, it imports string, but it won't if you have a > string of your own already imported. > > So, when logging depends on string, it'll get mine and crash. > > But __init__.py helps what in this

Re: [Tutor] __init__.py question

2011-06-01 Thread Marilyn Davis
Maybe I'm getting what you say, Alexandre and Ramit. When you import logging, it imports string, but it won't if you have a string of your own already imported. So, when logging depends on string, it'll get mine and crash. But __init__.py helps what in this scenario? The only scenario it helps,

Re: [Tutor] __init__.py question

2011-06-01 Thread Alexandre Conrad
As a side note, remember that imported modules are cached under sys.modules. If you import something, it will be looked up in sys.modules and use the one in memory if it exists. If it doesn't exist, it will iterate over sys.path and look for your module/package. If it doesn't find it, you will get

Re: [Tutor] __init__.py question

2011-06-01 Thread Alexandre Conrad
2011/5/31 Marilyn Davis : > I don't really understand why __init__.py is necessary -- except that it > makes the packaging scheme work. > > The Python Manual by Guido van Rossum and Fred L. Drake says: > > ... this is done to prevent directories with a common name, such as > string, from unintentio

Re: [Tutor] __init__.py question

2011-06-01 Thread Prasad, Ramit
I wonder if this is so that it can ignore directories on sys.path. I assume that the path passed to python can be quite verbose depending on the OS's handling of path and environment variables. This is also a way to have Python ignore Python scripts in directories on the path that are not meant

Re: [Tutor] __init__.py question

2011-06-01 Thread Marilyn Davis
Thank you Válas Péter. I still don't get it, or how __init__.py alters the scenario you describe. I know that sometimes I'm really dense so please be patient with me. If I have a string.py in my local directory, it will be imported when I "import string" because the search path, sys.path, (which

Re: [Tutor] __init__.py question

2011-06-01 Thread Válas Péter
I think it means that you may have a subdirectory named "string" in your actual directory where you store e.g. your string-related scripts, and you have a Python package named "string" _somewhere_else_, but in the module search path. The subdirectory of the actual directory will have priority bacau

Re: [Tutor] __init__() - is it required?

2011-01-10 Thread Corey Richardson
On 01/09/2011 04:27 PM, Steven D'Aprano wrote: > Corey Richardson wrote: >> Do all classes need an __init__() method? I have classes that look much >> like this one starts out: >> >> class GenerateXML(object): >> """Defines methods to be inherited for StaticXML and AnimationXML""" >> def __

Re: [Tutor] __init__() - is it required?

2011-01-10 Thread Alan Gauld
"bob gailer" wrote No, init() is only for initialising the object instance. If you have no local instance spwecific initialisation you can leave it to the inherited init() aor have no init() at all. Well I'd like to expand that a bit. There are cases where I create a class attribute and upd

Re: [Tutor] __init__() - is it required?

2011-01-09 Thread bob gailer
On 1/9/2011 4:42 PM, Alan Gauld wrote: "Corey Richardson" wrote Do all classes need an __init__() method? I have classes that look much like this one starts out: No, init() is only for initialising the object instance. If you have no local instance spwecific initialisation you can leave it

Re: [Tutor] __init__() - is it required?

2011-01-09 Thread Alan Gauld
"Corey Richardson" wrote Do all classes need an __init__() method? I have classes that look much like this one starts out: No, init() is only for initialising the object instance. If you have no local instance spwecific initialisation you can leave it to the inherited init() aor have no ini

Re: [Tutor] __init__() - is it required?

2011-01-09 Thread Steven D'Aprano
Corey Richardson wrote: Do all classes need an __init__() method? I have classes that look much like this one starts out: class GenerateXML(object): """Defines methods to be inherited for StaticXML and AnimationXML""" def __init__(self): pass I would rather not do that. Code wit

Re: [Tutor] __init__ arguments storage

2008-09-21 Thread Kent Johnson
Here is another writeup on __new__() and __init__(); http://www.voidspace.org.uk/python/weblog/arch_d7_2008_09_20.shtml#e1014 Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] __init__ arguments storage

2008-09-20 Thread Rob Kirkpatrick
Thanks Kent! That really makes it clear now. The bug I ran into was a while back and I've since ignored it to the point of forgetting how to invoke it, but I remember the stack trace said something about "variable received multiple arguments". I wanted to check the arguments to see if the same v

Re: [Tutor] __init__ arguments storage

2008-09-20 Thread Kent Johnson
On Sat, Sep 20, 2008 at 1:32 PM, Rob Kirkpatrick <[EMAIL PROTECTED]> wrote: > Hi All, > > In between an object's creation and call to __init__, where are the __init__ > arguments stored? Is there a class dictionary that init uses to initialize > the instance? I tried printing Class.__init__, but

Re: [Tutor] __init__ arguments storage

2008-09-20 Thread Alan Gauld
"Rob Kirkpatrick" <[EMAIL PROTECTED]> wrote In between an object's creation and call to __init__, where are the __init__ arguments stored? Is there a class dictionary that init uses to initialize the instance? I tried printing Class.__init__, but they aren't in there. I haven't checked Py

Re: [Tutor] __init__, default values and dict's

2008-08-14 Thread ALAN GAULD
> def __init__(self, d=None): > if not d: > > I would use > if d is None: > so the user can explicitly pass e.g. an empty dict. Good catch. I agree. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] __init__, default values and dict's

2008-08-14 Thread Kent Johnson
On Thu, Aug 14, 2008 at 1:32 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > For the second try > > def __init__(self, d=None): > if not d: I would use if d is None: so the user can explicitly pass e.g. an empty dict. Kent ___ Tutor maillist - Tutor@p

Re: [Tutor] __init__, default values and dict's

2008-08-14 Thread Alan Gauld
"Bart Cramer" <[EMAIL PROTECTED]> wrote Does anybody know why this is the case? And what would be the most convenient solution to enforce the dynamic creation of the dictionary? Kent answered the first bit. For the second try def __init__(self, d=None): if not d: d = {} self.d

Re: [Tutor] __init__, default values and dict's

2008-08-14 Thread Kent Johnson
On Thu, Aug 14, 2008 at 6:05 AM, Bart Cramer <[EMAIL PROTECTED]> wrote: > Dear tutors, > > I have the following code snippet: > > class N (object) : > >def __init__ (self, d={}) : >self.d = d > > I assumed that on each call of the __init__ without a dictionary > provided, a

Re: [Tutor] __init__.py for running a file from commandline?

2006-12-07 Thread Marcus Goldfish
On 11/27/06, Michael P. Reilly <[EMAIL PROTECTED]> wrote: When you type something from the command-line, you are at the whims of the WinXP command shell. You have to follow its rules, not Python's. It would need to have "python" in %PATH%, and then it would need to have to run "python C:\path\

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-27 Thread Michael P. Reilly
Marcus, When you type something from the command-line, you are at the whims of the WinXP command shell. You have to follow its rules, not Python's. It would need to have "python" in %PATH%, and then it would need to have to run "python C:\path\to\pyroot\utils\commands\mygrep.py". The arguments

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-27 Thread Kent Johnson
Marcus Goldfish wrote: > > > On 11/11/06, *Kent Johnson* <[EMAIL PROTECTED] > > wrote: > > Marcus Goldfish wrote: > > Hoping someone can help with this... > > > > I have a logical python namespace using a directory tree and > __init__.py > >

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-27 Thread Marcus Goldfish
On 11/11/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Marcus Goldfish wrote: > Hoping someone can help with this... > > I have a logical python namespace using a directory tree and __init__.py > files. For example, PYTHONPATH points to ~pyroot, and I have the following: > > ~pyroot/ > ~pyroot/ut

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-11 Thread Kent Johnson
Marcus Goldfish wrote: > Hoping someone can help with this... > > I have a logical python namespace using a directory tree and __init__.py > files. For example, PYTHONPATH points to ~pyroot, and I have the following: > > ~pyroot/ > ~pyroot/utils/ > ~pyroot/utils/commands/mygrep.py > > Which ma

Re: [Tutor] __init__.py for running a file from commandline?

2006-11-10 Thread Luke Paireepinart
Marcus Goldfish wrote: > Hoping someone can help with this... > > I have a logical python namespace using a directory tree and > __init__.py files. For example, PYTHONPATH points to ~pyroot, and I > have the following: > > ~pyroot/ > ~pyroot/utils/ > ~pyroot/utils/commands/mygrep.py > > Which ma

Re: [Tutor] __init__.py

2005-05-23 Thread Alan G
HI Joseph, > I've seen many (python) "plugins" (some located in site-packages [windows > here]) with the name __init__.py. init.py is the file that controls the behaviour of python packages - that is collections of modules used as a single entity. Read the python docs for the fine detail, but e

Re: [Tutor] __init__.py

2005-05-22 Thread Lee Cullens
Joseph, I'm relatively new to Python, but I might be able to help with your question. First, think of the convention "self" (or sometimes "me" in other languages) as a reference to a specific instance derived from a class. When you reference an inherited class method of an instance, the

Re: [Tutor] __init__.py

2005-05-22 Thread Joseph Quigley
>__init__.py will be executed when a package is imported. Oh. So it will (for instance) compile .py to .pyc after the installation is finished. Nice. Thanks, JQ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/

Re: [Tutor] __init__.py

2005-05-22 Thread Shidai Liu
On 5/23/05, Joseph Quigley <[EMAIL PROTECTED]> wrote: I've seen many (python) "plugins" (some located in site-packages [windowshere]) with the name __init__.py.What's their use?class foo:def __init__:print "this starts first" def foo1():print "this co