YAY! - Just figured out the problem.

Looks like there was no '__init__.py' file in my application root
directory (web2py/applications/mynewapp).

Now that I've put one there; importing works :D

On Mon, Mar 4, 2013 at 4:25 AM, Alec Taylor <[email protected]> wrote:
> Confirmed that the alternate suggested syntax doesn't work (same
> error); and that a blank '__init__.py' file is present in my modules
> directory.
>
> On Mon, Mar 4, 2013 at 4:10 AM, Niphlod <[email protected]> wrote:
>> why don't you use the simplest form
>> from foo_module import Foo
>>
>> ?
>>
>> PS: check that there's an __init__.y in the modules folder. If you want to
>> use appname.modules.foo_module path, you need to check for the __init__.py
>> also in the applications directory.
>>
>>
>> On Sunday, March 3, 2013 6:03:19 PM UTC+1, Alec Taylor wrote:
>>>
>>> My app has default routes; so I can't figure out why I can't import.
>>>
>>> I created the app "mynewapp" as a new simple app; then copied over the
>>> views + default models from the latest welcome app.
>>>
>>> In the modules directory I put "foo_module.py", containing:
>>> #!/usr/bin/env python
>>> # coding: utf8
>>>
>>> class Foo:
>>>     def foo():
>>>         return 'bar'
>>>
>>> ---
>>>
>>> In controllers/mynewapp I put:
>>>
>>> from applications.mynewapp.modules.foo_module  import Foo
>>> # also tried
>>> # from foo_module import Foo
>>>
>>> And received this error
>>>
>>> <type 'exceptions.ImportError'> No module named
>>> mynewapp.modules.foo_module
>>>
>>> ---
>>>
>>> How do I import functions and/or classes from /modules to my controllers?
>>>
>>> Thanks for all suggestions,
>>>
>>> Alec Taylor
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to