Class Not Auto-Init On Import

Parthan SR python.technofreak at gmail.com
Sat Apr 21 05:24:34 EDT 2007


On 4/21/07, Robert Rawlins - Think Blue <robert.rawlins at thinkbluemedia.co.uk>
wrote:
>
>  Hello Guys,
>
> From my understanding of what I've read, the 'import' is meant to auto
> Init my class ready for me to access its methods, but it doesn't appear too,
> I'm having to init them myself before I can access them, like this.
>
> import LocationService
>
> Location = LocationService.LocationService()
>
> LocationService.setIP('192.168.1.1')
>
> Why is this the case? Should i not just be able to access the setIP()
> method by doing LocationService.setIP('192.168.1.1') Without having to
> create my own inited reference?
>
Did you try this,

from LocationService import *
LocationService.setIP('192.168.1.1')
# If you have something like LocationService --> LocationService() -->
setIP()

This is similar to using datetime.now() of the datetime module.

>>> import datetime
>>> datetime.now()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'now'
>>> datetime.datetime.now()
datetime.datetime(2007, 4, 21, 14, 49, 4, 506309)

Now for the same,

>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2007, 4, 21, 14, 45, 42, 463064)

Or,

>>> from datetime import *
>>> datetime.now()
datetime.datetime(2007, 4, 21, 14, 46, 27, 767389)

-- 
With Regards


Parthan "Technofreak"

http://technofreakatchennai.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070421/17e987b0/attachment.html>


More information about the Python-list mailing list