[Tutor] Error help
I've been getting this error over and over and was wondering if someone could help me fix it. [image: Inline image 1] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __init__
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. IN Java if you do not have a constructor specified java calls a default constructor behind the scenes setting up memory. 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/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 appropriate print statements in the method. Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor oldcatlady.com (Sponsored by Content.Ad) 40 Years Later: How Do 'The Brady Bunch' Look Now? http://thirdpartyoffers.netzero.net/TGL3241/57c4bcd6864d53cd60b7ast01duc ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error help
On 30/08/16 03:22, Matthew Lehmberg wrote: I've been getting this error over and over and was wondering if someone could help me fix it. [image: Inline image 1] This is a text mailing list so attachments dont get through. Plese repost with your error message cut n paste into the message. Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __init__
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 level class object has an empty __init__() which does nothing, so it will be called by __new__() > IN Java if you do not have a constructor specified java > calls a default constructor behind the scenes setting up memory. Remember that init() is an initialiser, not a constructor. The constructor is the rarely seen __new__() method. It is new() that sets up the memory then calls init(). So init is only used to initialise the object after it has been constructed. Does python call default __init__ if one is not defined? There is always one defined in object but it does nothing. There is also a default new() in object which is what sets up the memory etc and then calls init() Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __init__
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 an instance of the class. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __init__
Thank you all for your answers. The below seems contradicting to me: " in that case there is no __init__ to call. The top level class object has an empty __init__() which does nothing, so it will be called by __new__()" "It is new() that sets up the memory then calls init(). So init is only used to initialise the object after it has been constructed." "There is always one defined in object but it does nothing. There is also a default new() in object which is what sets up the memory etc and then calls init()" so a class has a default, empty __init__ and __new__. __new__ sets up memory and calls __init__. In class that has no parent: __init is called by __new__ but really does not do anything since it is empty. Assume you have a child class with no init, but it has empty, default __init__ provided by pathon and the same for its parent class. When instantiating 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@python.org Subject: Re: [Tutor] __init__ Date: Tue, 30 Aug 2016 10:09:55 +0100 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 level class object has an empty __init__() which does nothing, so it will be called by __new__() > IN Java if you do not have a constructor specified java > calls a default constructor behind the scenes setting up memory. Remember that init() is an initialiser, not a constructor. The constructor is the rarely seen __new__() method. It is new() that sets up the memory then calls init(). So init is only used to initialise the object after it has been constructed. > Does python call default __init__ if one is not defined? There is always one defined in object but it does nothing. There is also a default new() in object which is what sets up the memory etc and then calls init() Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Affordable Wireless Plans Set up is easy. Get online in minutes. Starting at only $14.95 per month! www.netzero.net?refcd=nzmem0216 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] ImportError: cannot import name
Hello, I use python 3.5.1 and try to import sompy and get the following error: File "C:\Anaconda3\lib\site-packages\sompy-1.0-py3.5.egg\sompy\__init__.py", line 30, in from sompy import SOMFactory ImportError: cannot import name 'SOMFactory' What could cause such an error? Thanks in advance for any suggestions. Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __init__
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_ is called if __new__ returns an instance of the class. Quite so, but I didn't want to bend brains too much by mentioning metaclasses! They are confusing enough for experienced programmers let alone the typical tutor subscriber! Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ImportError: cannot import name
On 30/08/16 10:25, fa306...@skynet.be wrote: Hello, I use python 3.5.1 and try to import sompy and get the following error: File "C:\Anaconda3\lib\site-packages\sompy-1.0-py3.5.egg\sompy\__init__.py", line 30, in from sompy import SOMFactory ImportError: cannot import name 'SOMFactory' What could cause such an error? Thanks in advance for any suggestions. The most likely cause is that the module sompy does not contain the name SOMFactory (check the spelling...). Try >>> import sompy >>> dir(sompy) To check the available names Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __init__
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 ___init__ in child class and then > calls __init__ in parent class? Usually there is only one new in object. When new finishes constructing the empty object init() gets called. There is no magic it is just a standard method call that starts at the lowest level child and works its way up the tree until it finds an init. If all else fails it reaches the top level object.init() If any subclass has defined an init it will be called first and unless it calls super() it will be the last. Why does it not just use the default, provided by python > __init__ since it found it? It uses the first init it finds. The last place it looks is in object which has an empty init method. Python itself does not provide a default init, it is the empty one in object that fulfills that function (since every class ultimately inherits object). I suspect that's how Java does it too since every Java class descends from Object. But I've not examined Java that closely. As eryksun has intimated there is actually another layer of magic involved in Python via the metaclass mechanism which allows us to change the mechanism by which classes are constructed. but that is way deeper than most programmers ever need to go! Remember the old adage -Keep it Simple! Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __init__
OK so somebodys remark that there is a default __init__ provided was not correct. What about old style classes? When we have a class that has no parent. and it does not inherit from object since it is old class - and this class has no __init__, does __new__ call __init__? -- Original 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 inherits the empty init from object. > and the same for its parent class. When instantiating child class, > child class's __new__ calls its ___init__ in child class and then > calls __init__ in parent class? Usually there is only one new in object. When new finishes constructing the empty object init() gets called. There is no magic it is just a standard method call that starts at the lowest level child and works its way up the tree until it finds an init. If all else fails it reaches the top level object.init() If any subclass has defined an init it will be called first and unless it calls super() it will be the last. > Why does it not just use the default, provided by python > __init__ since it found it? It uses the first init it finds. The last place it looks is in object which has an empty init method. Python itself does not provide a default init, it is the empty one in object that fulfills that function (since every class ultimately inherits object). I suspect that's how Java does it too since every Java class descends from Object. But I've not examined Java that closely. As eryksun has intimated there is actually another layer of magic involved in Python via the metaclass mechanism which allows us to change the mechanism by which classes are constructed. but that is way deeper than most programmers ever need to go! Remember the old adage -Keep it Simple! Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Health News 24 (Sponsored by Content.Ad) Don't Use Botox, Use This Instead: Granny Reveals $39 Method http://thirdpartyoffers.netzero.net/TGL3241/57c5f6096912f7609373fst03duc ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __init__
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 the language per se but of the standard object model. What about old style classes? That's a very good question and I don't know the answer. Hopefully someone else does! Alan G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ImportError: cannot import name
On Tue, Aug 30, 2016 at 11:25:44AM +0200, fa306...@skynet.be wrote: > Hello, > I use python 3.5.1 and try to import sompy and get the following error: > > File "C:\Anaconda3\lib\site-packages\sompy-1.0-py3.5.egg\sompy\__init__.py", > line 30, in from sompy import SOMFactory > > ImportError: cannot import name 'SOMFactory' > > What could cause such an error? Thanks in advance for any suggestions. Lots of things. (1) Check the spelling. Python is case-sensitive, so SOMFactory is not the same as SomFactory or SOMfactory or somfactory. (2) Do you have your own file called "sompy.py" somewhere? If so, that will block access to the real one. (3) Are you sure that sompy supports Python 3.5? (4) Are you sure that SOMFactory actually exists? I don't see it in any of the five notebooks here: https://github.com/sevamoo/SOMPY although maybe I've missed something. It might help if you can copy and paste the FULL traceback showing exactly what line of code failed and the precise sequence of calls. Please COPY and PASTE (don't retype from memory, or summarise, and especially don't take a screenshot) the entire traceback, starting with the line Traceback (most recent call last): all the way to the end. Then we will have a better idea of what is going on. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ImportError: cannot import name
On Wed, Aug 31, 2016 at 10:25:17AM +1000, Steven D'Aprano wrote: > (4) Are you sure that SOMFactory actually exists? I don't see it in any > of the five notebooks here: > > https://github.com/sevamoo/SOMPY > > although maybe I've missed something. I may have... there's a sixth notepad here: http://nbviewer.jupyter.org/gist/sevamoo/ec0eb28229304f4575085397138ba5b1 and it refers to SOMFactory. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor