On Tue, Sep 6, 2011 at 3:18 PM, Laszlo Nagy <gand...@shopzeus.com> wrote:
> On 2011-09-06 15:42, Kayode Odeyemi wrote: > >> I was able to get this solved by calling class like this: >> >> >>> from core.fleet import Fleet >> >>> f = Fleet() >> >> Thanks to a thread from the list titled "TypeError: 'module' object is not >> callable" >> > Or you can also do this: > > import core.fleet # import module core.fleet under the name core.fleet > f = core.fleet.Fleet() > > Please note that the import statement imports the module with the given > name. > > So for example > > import x.y.z > > will import the name "x.y.z". Anything that is in module "z" will be > available through its module, that is "x.y.z". > Whenever you use "import <name>", you have to access module contents > through "<name>". > > You can change the name: > > import core.fleet as c # import module core.fleet under the name c > f = c.Fleet() > > That is, import [package-name] .[class-name] If using from, that can take the form of [package-name].[pymodule] import [pymodule] or [class-name] I just got to understand it. Thanks. This explanation really simplifies it further. Can I do: from [pymodule] import [class-name], assuming the pymodule as a class instance? -- Odeyemi 'Kayode O. http://www.sinati.com. t: @charyorde
-- http://mail.python.org/mailman/listinfo/python-list