如何在SecureCRT的python脚本中引入自己编写的模块

注:同样可以用来处理importError问题。

1. 重构python解释器(仅限8.0.0版本)

    可以用本地的python 2.7环境来取代SecureCRT本身的解释器

感谢这位博主的两篇博文。

  1.  SecureCRT调用python脚本ImportError https://blog.csdn.net/MrRight17/article/details/82527407
  2.  SecureCRT脚本环境类(python)https://blog.csdn.net/MrRight17/article/details/82874479

但是之后的版本之中,改为了vpython.zip 和 vpython.dll就不适用了。 (这里是笔者水平不行。。是在不会)

2. 简单的解决办法,引入模块路径

     参考论坛: https://forums.vandyke.com/printthread.php?t=10331 (使用chrome打开会自动机翻成中文,不如不翻译。。。)

To load a module in a Python script started in SecureCRT you must place the module in a valid path. Valid paths are defined in the sys.path list. If you don't want to use the paths in the list, you can modify sys.path.

Here is an example of how one can modify sys.path to look for the module in the same location as the script:

Code:


import sys
import os
(strScriptPath, strScriptName) = os.path.split(__file__)
# Inject the path to the script into sys.path for use when looking for modules
# to import.

if strScriptPath in sys.path:
    # If the path exists, don't inject.  Unless SecureCRT is closed, we don't
    # need to inject the path of the running script because sys.path is static.

    crt.Dialog.MessageBox("Already There")
else:
    # Inject the path of the running script if it is not in sys.path
    sys.path.insert(0, strScriptPath)

In my tests, I had to use .py rather than .fy for the module name extension.

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值