[Geany-Users] Can't import local module. Solved perhaps
Paul Marlin
wurfsendungen at xxxxx
Sat Dec 14 19:40:44 UTC 2019
On 12/13/19 3:02 PM, Matthew Brush wrote:
> I'm not sure exactly what you're going for, but often you will have
> your main script in the top level, and then put common/library code in
> a package directory, with an (often empty) `__init__.py` file.
> Something like this:
>
> - py
> - main.py
> - common
> - __init__.py
> - fun.py
>
> If you lay it out like this, it "Just Works" out of the box with
> Geany's execute command for `main.py`, without messing with any path
> variables or anything.
>
> If you want to leave it where `main.py` is in a directory that is a
> sibling of your common/library package, you will probably have to mess
> with paths and/or use some kind of relative imports.
>
> I don't think your problem is with Geany as much as with trying to
> understand Python's quite complicated import
> mechanisms/rules/conventions.
Amen
>
> Hope that helps.
>
> Regards,
> Matthew Brush
============================================
What I'm looking for is a way to structure multiple python applications
that all make use of user defined functions (VFP jargon perhaps) stored
in a python script (this is how I did it with multiple PHP apps).
I followed your suggestion and took the liberty of adding a second
script, main1.py. *Both worked* even without __init__.py. *
*
- py
- main.py
- main1.py
- common
- fun.py
But my problem is that main.py and main1.py really represent separate
applications each with multiple files. The only way I know of
organizing apps is to place their files in their own directory. So I
tried
- py
- app1
- main1.py
- app2
- main2.py
- common
- fun.py
Even though this seems to be the same structure as I started with, both
main1.py and main2.py worked. So it appears Geany is now accepting
/home/paul/py as being in the PYTHONPATH. Since common is downstream of
that, it works.
Thank you.
PS: I'm sure this belongs in a separate thread; but I got cocky and
tried an alarm clock program that I had written involving a tkinter
GUI. It worked fine in Idle; but all I got from Geany was a terminal
window telling me the exit code was 0. Using the ancient dicotomy of
system vs. applcation programing, wouldn't it be fair to say all
application programs are GUI?
Paul
> _______________________________________________
> Users mailing list
> Users at lists.geany.org
> https://lists.geany.org/cgi-bin/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/users/attachments/20191214/5b115b31/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: py.png
Type: image/png
Size: 17725 bytes
Desc: not available
URL: <https://lists.geany.org/pipermail/users/attachments/20191214/5b115b31/attachment-0001.png>
More information about the Users
mailing list