#1
|
|||
|
|||
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!
|
#2
|
|||
|
|||
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?
|
#3
|
|||
|
|||
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.. ? |
#4
|
|||
|
|||
Can you post the code you are using to import the file including any path related commands?
|
#5
|
|||
|
|||
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 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 thanks! |
#6
|
|||
|
|||
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 |
#7
|
|||
|
|||
The workaround worked for me too. Thanks for checking on that!
|
#8
|
|||
|
|||
oops just kidding.. the workaround code makes autocomplete work(ish) but throws an error on execution
ValueError: Attempted relative import in non-package |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
view_coliision module | bbb | Vizard | 2 | 08-24-2016 01:46 AM |
Could not locate _Vizcore module | Bhavesh | Vizard | 1 | 06-21-2016 02:48 AM |
vizinput module missing | whaleeee | Vizard | 1 | 02-06-2013 12:30 AM |
Exception in module vizjoy | fordprefect | Vizard | 2 | 12-03-2012 02:41 AM |
vhil module | vadrian | Vizard | 2 | 01-27-2005 12:52 PM |