python-module

Need help understanding module import errors

北城以北 提交于 2019-12-10 20:33:59
问题 I'm trying to use the sendgrid Python API as a module in web2py. After testing it successfully from the command line, I dropped it into my modules folder, but as soon as I try to import sendgrid into my controller file, I get: File "applications/test/modules/sendgrid/__init__.py", line 4, in <module> del sendgrid, message NameError: name 'sendgrid' is not defined Looking at the __init__.py file, I noticed they're doing * imports on the module level, which I've seen cause problems before, but

Python Module for Session Management

孤街醉人 提交于 2019-12-10 14:51:27
问题 Is there any equivalent module for session management like Perl's CGI::Session or Apache::Session ? (I know most python web frameworks have their own implementations, but I am looking for a stand alone module that could be used with any python application.) 回答1: I think you can use Beaker's which is a popular library for this. documentation 回答2: Werkzeug is a WSGI library that is somewhat equivalent to Perl's CGI module in the Python world (almost nobody uses CGI in Python), and it has basic

Dot-slash not recognized in command prompt - Trying to install Python module

只愿长相守 提交于 2019-12-10 13:27:23
问题 I am trying to install a Python module in command prompt. The directions state to run "./configure" to install the module and then run a make command. However, whenever I do that, I receive the error '.' is not recognized as an internal or external command, operable program or batch file. I am still relatively new to using Command Prompt and Python, so this could be a very novice issue. From what I've read from other questions, it seems that command prompt should automatically recognize the .

paramiko python module hangs at stdout.read()

二次信任 提交于 2019-12-10 02:14:14
问题 I am using the below code: import paramiko def runSshCmd(hostname, username, password, cmd, timeout=None): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(hostname, username=username, password=password, allow_agent=False, look_for_keys=False, timeout=timeout) stdin, stdout, stderr = client.exec_command(cmd) stdin.flush() data = stdout.read() print (data) client.close() runSshCmd("10.128.12.32", "root", "C0mput3Gr!d", "ts_menu") when it

Python internals - How do objects know about global variables?

安稳与你 提交于 2019-12-09 20:00:45
问题 I recently discovered some interesting behavior that left me wondering about how an object knows about which global variables exist. For example, suppose I have a file "test.py": globalVar = 1 toDelete = 2 class Test(object): classVar = 3 def runTest1(self): print globalVar print toDelete print missingVar def runTest2(self): print self.classVar print toCreate print missingVar Then in an interactive shell I do this: >>> import test >>> tester = test.Test() >>> tester.runTest1() 1 2 Traceback

Sphinx document module properties

*爱你&永不变心* 提交于 2019-12-09 15:08:06
问题 I have a module that should have a @property , I solved this by setting a class as the module. I got the idea from this answer: Lazy module variables--can it be done? I wanted this to be repeatable and easy to use so I made a metaclass for it. This works like a charm. The problem is that when using Sphinx to generate documentation properties don't get documented. Everything else is documented as expected. I have no idea how to fix this, maybe this is a problem with Sphinx? The module: import

How to import two versions of the same python module at the same time?

☆樱花仙子☆ 提交于 2019-12-09 13:09:32
问题 Suppose I have two versions of a python package, say "lib". One is in folder ~/version1/lib and the other is in ~/version2/lib . I'm trying to load both packages in one session by doing this: sys.path.insert(0, '~/version1') import lib as a sys.path.insert(0, '~/version2') import lib as b But it doesn't work, because of cache, b will be the same as a . Is there anyway to do it? Maybe use hook in sys.meta_path ? I didn't figure it out. Or is there anyway to delete cache of imported modules?

Connecting to Sql Server with Python 3 in Windows

纵饮孤独 提交于 2019-12-09 01:02:05
问题 Can someone please point me in the right direction of how I can connect to MS SQL Server with Python? What I want to do is read a text file, extract some values and then insert the values from the text file into a table in my Sql Server database. I am using Python 3.1.3, and it seems some of the modules I have come across in research online are not included in the library. Am I missing something? Is there a good 3rd party module I should know about. Any help would be greatly appreciated.I am

How to use __init__.py in (sub-)modules to define namespaces?

橙三吉。 提交于 2019-12-09 00:04:59
问题 my question is about writing Python (3.x) packages and (sub-)modules and the correct usage of __init__.py files to declare namespaces. I used to code in C++, so I like to use a lot of separate files to organize projects. For example, (imo) if a module contains several classes, each of these should be in a separate file. As I am inexperienced developing in Python, it is hard to formulate my thoughts in a simple question. So let's consider the following small python package as an example.

Python ImportError loading module within subfolder

白昼怎懂夜的黑 提交于 2019-12-08 19:57:28
I have the following structure abc/ __init__.py settings.py tests/ __init__.py test.py in test.py , I am getting an ImportError for #test.py import abc.settings You have two ways. Firstly, by setting the path variable import os import sys sys.path.insert(0, <Complete path of abc>) Or by using relative imports. The variable sys.path is a list of strings that determines the interpreter’s search path for modules. It is initialized to a default path taken from the environment variable PYTHONPATH , or from a built-in default if PYTHONPATH is not set. You can modify it using standard list operations