Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting

Thread Tools Rate Thread Display Modes
Old 12-31-2020, 07:37 AM
garrettwilliams garrettwilliams is offline
Registered User
Join Date: Dec 2020
Posts: 13
Python 3 - importing local modules

Hey all,

I'm trying to make a script I wrote in Python 3 to be more modular - i.e. I want to store some of my functions in a separate file. For instance:

def find_prompt():
    screenrow = crt.Screen.CurrentRow
    x = crt.Screen.Get(screenrow,1,screenrow,30).strip(" ")
The problem is, trying to import this function into my main program it's throwing a 'crt' not defined error. I'm guessing it's because the local interpreter doesn't have a path to that function, even if SecureCRT does. With older scripts I've seen this problem addressed by putting this line of code in the main script before we import the module:

if 'crt' in globals():
    script_dir, script_name = os.path.split(crt.ScriptFullName)
    if script_dir not in sys.path:
        sys.path.insert(0, script_dir)
    script_dir, script_name = os.path.split(os.path.realpath(__file__))
Unfortunately this doesn't seem to work. Is there something simple I'm missing? The Python3 examples I've seen haven't been complex enough to require importing other modules.


Last edited by cboyack; 01-01-2021 at 10:42 AM. Reason: Please use the [CODE] and [/CODE] tags to denote a script
Reply With Quote
Old 01-01-2021, 10:41 AM
cboyack cboyack is offline
VanDyke Technical Support
Join Date: Apr 2020
Location: Albuquerque, NM
Posts: 106
Hi garrettwilliams,

The code which you shared at the bottom of your post is a solution to a completely different problem.

We have put together a set of instructions for importing custom modules referencing the crt object here. While the example on the referenced page is in python 2 (it hasn't yet been tested with python 3), the concept is the same.

In the future, for better readability, please use the [CODE] and [/CODE] tags surrounding any code snippets you include, so that spacing and indentation will be visible.

VanDyke Software
Technical Support
(505) 332-5730

Last edited by jdev; 01-01-2021 at 12:48 PM.
Reply With Quote
Old 01-07-2021, 12:14 PM
garrettwilliams garrettwilliams is offline
Registered User
Join Date: Dec 2020
Posts: 13
Thanks! Extremely helpful.
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
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

All times are GMT -6. The time now is 12:47 PM.