Tag: python module

如何重新加载使用`从模块导入*`导入的Python模块

我在这个有用的问答中看到,可以使用reload(whatever_module)或者在Python 3中使用imp.reload(whatever_module) 。 我的问题是,如果我from whatever_module import *中导入了什么呢? 然后,我没有whatever_module来引用当我使用reload() 。 你们会因为把整个模块扔到全局命名空间而嚷嚷吗? 🙂

Python:如何从一个函数进行全局导入

我担心这是一个混乱的方式来解决这个问题,但… 假设我想根据一些条件在Python中进行一些导入。 为此我想写一个函数: def conditional_import_modules(test): if test == 'foo': import onemodule, anothermodule elif test == 'bar': import thirdmodule, and_another_module else: import all_the_other_modules 现在,我怎样才能有import模块全球可用? 例如: conditional_import_modules(test='bar') thirdmodule.myfunction()

如何在Python中logging模块?

而已。 如果你想logging一个函数或一个类,你可以在这个定义之后加一个string。 例如: def foo(): """This function does nothing.""" pass 但是模块呢? 我如何logging一个file.py的function?

如何在Python中获取__main__模块的文件名?

假设我有两个模块: a.py: import b print __name__, __file__ b.py: print __name__, __file__ 我运行“a.py”文件。 这打印: b C:\path\to\code\b.py __main__ C:\path\to\code\a.py 问题 :如何从“b.py”库中获取__main__模块(本例中为“a.py”)的path?

Python:__builtin__和__builtins__有什么区别?

我今天正在编码,发现了一些东西。 如果我打开一个新的解释器会话(空闲),并检查与dir函数定义了什么,我得到这个: $ python >>> dir() ['__builtins__', '__doc__', '__name__', '__package__'] >>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', […]

如何编写一个Python模块?

我一直在为在工作中的简单任务制作Python脚本,从来没有真正打扰他人打包使用。 现在我已经分配了一个REST API的Python包装器。 我完全不知道如何开始,我需要帮助。 我拥有的: (只想尽可能具体)我已经准备好了virtualenv ,它也在github中 ,python的.gitignore文件也在这里,另外还有用于与REST API交互的请求库 。 而已。 这是当前的目录树 . ├── bin │ └── /the usual stuff/ ├── include │ └── /the usual stuff/ ├── lib │ └── python2.7 │ └── /the usual stuff/ ├── local │ └── /the usual stuff/ └── README.md 27 directories, 280 files 我甚至不知道把.py文件放在哪里,如果我做了。 我想做什么: 使一个Python模块安装与“点安装…” 如果可能的话,我需要一个一步一步的编写Python模块的过程。

如何找出我的pythonpath使用python?

如何从Python脚本(或交互式shell)中找出哪些目录在我的系统的PYTHONPATHvariables中列出?

我需要什么来阅读使用Python的Microsoft Access数据库?

我如何访问Python中的Microsoft Access数据库? 用SQL? 我会优先考虑一个适用于Linux的解决scheme,但我也可以适应Windows。 我只需要读取权限。

模块的属性是否与对象可以相同?

与python属性,我可以做到这一点 obj.y 调用一个函数而不是仅仅返回一个值。 有没有办法做到这一点与模块? 我有我想要的情况 module.y 调用一个函数,而不是只返回存储在那里的值。

在代码中安装python模块

我需要从PyPi直接在我的脚本中安装一个软件包。 也许有存在模块或distutils(分布,点)能力,让我只是执行像pypi.install('requests')和请求将被安装到我的virtualenv,我不应该在我的shell中键入pip install requests ?