Difference between 'import' and 'from ... import'

Andy Todd andy47 at halfcooked.com
Mon Dec 3 17:22:30 EST 2001


Patrick,

"Patrick K. O'Brien" <pobrien at orbtech.com> wrote in
<RFQO7.25511$WC1.2619806 at newsread2.prod.itd.earthlink.net>: 

>I got the following:
>
>C:\Code\Gadfly> python
>Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
>Type "copyright", "credits" or "license" for more information.
>>>> import gadfly
>kjParser.py:16: DeprecationWarning: the regex module is deprecated;
>please use t
>he re module
>  import regex
>C:\PYTHON21\lib\regsub.py:15: DeprecationWarning: the regsub module is
>deprecate
>d; please use re.sub()
>  DeprecationWarning)

That's what I get if I try;

>>> from Gadfly import gadfly

Of course, use of regex instead of re is a whole different kettle of fish 
;-) but if anyone has any patches for the gadfly code that will 'upgrade' 
it I'd be a willing beta tester. Bearing in mind that I can't even import 
the module I'm a little nervous hacking the code myself.

>>>> gadfly
><module 'gadfly' from 'gadfly.pyc'>
>>>> dir(gadfly)
>['GF_Cursor', '__builtins__', '__doc__', '__file__', '__name__',
>'error', 'gadfl
>y', 'sql', 'sqlbind', 'sqlgen', 'verbosity']
>>>>

And then the modules are loaded into the local namespace and everything is 
hunky dory. 

>
>In other words, it worked. All I did was download, unzip, "python
>gfinstall.py", and then what you see above. What didn't work for me was
>what you said worked for you:
>
>C:\Code>python
>Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
>Type "copyright", "credits" or "license" for more information.
>>>> from Gadfly import gadfly
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>ImportError: No module named Gadfly
>>>>
>
>Indeed, on my machine the Gadfly directory does not have an __init__.py
>file, so Gadfly is *not* a package. Does this help at all?

Certainly does, that nailed it. I must have created an __init__.py 
inadvertently by using 'from ... import'. By removing the file I can 
'import gadfly'. Strange error though.

You are a legend. Thanks very much.

Regards,
Andy
-- 
Content free posts a speciality



More information about the Python-list mailing list