WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   autocomplete for custom module? (https://forum.worldviz.com/showthread.php?t=6224)

fivel_lab 02-01-2019 06:25 PM

autocomplete for custom module?
 
OK, so simple question but can't seem to find much help on the subject: is there a way to use the IDE's autocomplete for a custom module? The lab has a bunch of very commonly used utility functions and we have new people writing scripts every academic year. Would be very handy to be able to have autocomplete to facilitate training!

Jeff 02-03-2019 06:39 AM

After importing the module into your script, the autocomplete should display the function names. Is the module in the same folder as the script or a different location?

fivel_lab 02-04-2019 11:28 AM

Thanks! So, after your comment I confirmed that it works if the module is in the current directory of the script I'm working on. Very cool!

But, as you suspected, I have it setup as a package in a different directory (including __init__.py). I have added the path to the enclosing folder with sys.path.insert, but it still doesn't work.. ?

Jeff 02-05-2019 06:58 AM

Can you post the code you are using to import the file including any path related commands?

fivel_lab 02-06-2019 10:55 AM

Sure!

Directory structure is set up like this:

Code:

FIVEL/                      top-level enclosing folder
          fvl/                        package
              __init__.py                    package initalization
              likertScaleObj.py                  example package module(s)
          VRproject/                        project directory
              F18/
                    F18.py                    last semester's version of the exp
              S19/
                  S19.py                    current semester's version

the code in S19.py ::::
Code:

import sys
import os
import os.path as path

sys.path.insert(0, path.dirname(path.dirname(path.dirname(__file__))))

#confirm path info with print statements
print path.dirname(__file__)
print path.dirname(path.dirname(__file__))
print path.dirname(path.dirname(path.dirname(__file__)))
print sys.path
print os.listdir(path.dirname(path.dirname(path.dirname(__file__))))

import fvl #no error

but.. after that no magic autocomplete :confused:

thanks!

Jeff 02-15-2019 09:47 PM

It does not look like the autocomplete is set to work with paths added on the fly using the sys.path.insert command. It may work by adding to the PYTHONPATH environment variable.

If the module is in a directory above you could use the following code to import the module. I just tested and this worked for me with the autocomplete:

Code:

# import module in directory above
from .. import my_module

# import module two directories above
from ... import my_module


fivel_lab 02-17-2019 01:46 PM

The workaround worked for me too. Thanks for checking on that!

fivel_lab 02-18-2019 01:15 PM

oops just kidding.. the workaround code makes autocomplete work(ish) but throws an error on execution

ValueError: Attempted relative import in non-package


All times are GMT -7. The time now is 02:50 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC