Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12835 > unrolled thread
| Started by | Laszlo Nagy <gandalf@shopzeus.com> |
|---|---|
| First post | 2011-09-06 16:18 +0200 |
| Last post | 2011-09-06 17:12 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Python marks an instance of my class undefined Laszlo Nagy <gandalf@shopzeus.com> - 2011-09-06 16:18 +0200
Re: Python marks an instance of my class undefined Hans Mulder <hansmu@xs4all.nl> - 2011-09-06 17:12 +0200
| From | Laszlo Nagy <gandalf@shopzeus.com> |
|---|---|
| Date | 2011-09-06 16:18 +0200 |
| Subject | Re: Python marks an instance of my class undefined |
| Message-ID | <mailman.802.1315318727.27778.python-list@python.org> |
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()
[toc] | [next] | [standalone]
| From | Hans Mulder <hansmu@xs4all.nl> |
|---|---|
| Date | 2011-09-06 17:12 +0200 |
| Message-ID | <4e66387b$0$2499$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #12835 |
On 6/09/11 16:18:32, Laszlo Nagy 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() An import statement always imports a module, but Python also has the from...import statement to import one item from a module: from core.fleet import Fleet f = Fleet() The convention is to use the name "Fleet" (with an initial capital) for the class and "fleet" (all lower case) for the module. This makes it easier to not confuse the class and the module. Hope this helps, -- HansM
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web