首页
学习
活动
专区
圈层
工具
发布
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    在 Bash 中获取 Python 模块变量列

    在 Bash 中获取 Python 模块的变量列表可以通过使用 python -c 来运行 Python 代码并输出变量名列表。...1、问题背景在编写 Bash 补全脚本时,需要获取已安装 Python 模块中与模式匹配的所有变量。为了避免解析注释等内容,希望仅使用 Python 相关功能。...设你有一个 Python 模块(文件)mymodule.py,内容如下:# mymodule.pyx = 10y = 20z = 30​def my_function(): pass要在 Bash 中获取该模块中的所有变量...使用 dir() 获取模块中的所有名称。使用 inspect 模块过滤出变量(排除函数、类、模块等)。...inspect.ismodule(value) and not inspect.isclass(value)]print(' '.join(variables))"说明vars(mymodule).items():获取模块的所有属性

    11.9K10
    领券