WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-01-2019, 05:25 PM
fivel_lab fivel_lab is offline
Member
 
Join Date: Mar 2011
Posts: 36
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!
Reply With Quote
  #2  
Old 02-03-2019, 05:39 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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?
Reply With Quote
  #3  
Old 02-04-2019, 10:28 AM
fivel_lab fivel_lab is offline
Member
 
Join Date: Mar 2011
Posts: 36
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.. ?
Reply With Quote
  #4  
Old 02-05-2019, 05:58 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Can you post the code you are using to import the file including any path related commands?
Reply With Quote
  #5  
Old 02-06-2019, 09:55 AM
fivel_lab fivel_lab is offline
Member
 
Join Date: Mar 2011
Posts: 36
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

thanks!
Reply With Quote
  #6  
Old 02-15-2019, 08:47 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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
Reply With Quote
  #7  
Old 02-17-2019, 12:46 PM
fivel_lab fivel_lab is offline
Member
 
Join Date: Mar 2011
Posts: 36
The workaround worked for me too. Thanks for checking on that!
Reply With Quote
  #8  
Old 02-18-2019, 12:15 PM
fivel_lab fivel_lab is offline
Member
 
Join Date: Mar 2011
Posts: 36
oops just kidding.. the workaround code makes autocomplete work(ish) but throws an error on execution

ValueError: Attempted relative import in non-package
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
view_coliision module bbb Vizard 2 08-24-2016 12:46 AM
Could not locate _Vizcore module Bhavesh Vizard 1 06-21-2016 01:48 AM
vizinput module missing whaleeee Vizard 1 02-05-2013 11:30 PM
Exception in module vizjoy fordprefect Vizard 2 12-03-2012 01:41 AM
vhil module vadrian Vizard 2 01-27-2005 11:52 AM


All times are GMT -7. The time now is 09:05 PM.


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