python - Inheritance in IronPython and circular references -


i have question circular references in ironpython. let's have class hierarchy. in 1 file have parent class:

from child import child  class parent(object):     def getchild(self):         return child() 

in file have child class:

from parent import parent  class child(parent):     def dosomething(self):         return 0 

i have kind of circular references here. so, when try execute code this:

from parent import *  parent = parent() child = parent.getchild() 

i've got error: can avoid circular reference in kind of way?

as say, have circular import problem.

the normal way of solving have 2 classes in same file. python not enforce kind of link between file , class, can have many classes in single file , can called whatever like. (in fact, giving file exact same name class contains un-pythonic; apart else, files should have lower_case_with_underscore names, whereas classes camelcase.)

however, if reason can't that, can break circular import doing inside method:

class parent(object):     def getchild(self):         child import child         return child() 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -