python-module

Mock an entire module in python

…衆ロ難τιáo~ 提交于 2019-12-19 16:53:32
问题 I have an application that imports a module from PyPI. I want to write unittests for that application's source code, but I do not want to use the module from PyPI in those tests. I want to mock it entirely (the testing machine will not contain that PyPI module, so any import will fail). Currently, each time I try to load the class I want to test in the unittests, I immediately get an import error. so I thought about maybe using try: except ImportError: and catch that import error, then use

Python packages: relative imports

为君一笑 提交于 2019-12-19 08:28:02
问题 I'm working on a Python application consisting of a core and multiple independent modules using the core. I'm having difficulty setting up relative imports of packages. app |- __init__.py |- core |- __init__.py |- corefile.py |- module1 |- __init__.py |- main.py The __init__.py files are empty. I'm running Python 2.7.1. main.py from .core import * Running python main.py results in ValueError: Attempted relative import in non-package . Similar questions: Ultimate answer to relative python

Using scipy.stats.stats in django after deployment

删除回忆录丶 提交于 2019-12-19 08:12:48
问题 I am in the process of creating an django-powered (1.3) interface to a package that relies heavily in scipy.stats.stats (scipy version 0.9.0), called ovl . During early development phases, using djangos own development-server, this was no problem. After deployment using apache debian/2.2.9 and mod_wsgi 3.3, this causes a serious problem. Whatever view I'm trying to load in the browser, it starts loading, and keeps doing that for a good 5 minutes (until time-out) and a 500 page appears. Just

Is it possible to end a python module import with something like a return?

允我心安 提交于 2019-12-19 02:39:15
问题 I would like to know if there is a way of writing the below module code without having to add another indentation level the whole module code. # module code if not condition: # rest of the module code (big) I am looking for something like this: # module code if condition: # here I need something like a `return` # rest of the module code (big) Note, I do not want to throw an Exception, the import should pass normally. 回答1: I don't know of any solution to that, but I guess you could put all

Error Loading MySQLdb Module and “pip install MySQLdb”

余生长醉 提交于 2019-12-18 15:12:32
问题 I'm trying start up a Django project. I get this error on trying to run the manage.py: (venv)dyn-160-39-161-214:proj Bren$ python manage.py Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/Bren/Desktop/fss/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line utility.execute() File "/Users/Bren/Desktop/fss/venv/lib/python2.7/site-packages/django/core/management/_

Python: replacing a function within a class of a module

自作多情 提交于 2019-12-18 13:27:38
问题 I'm trying to replace a function defined within a class in order to modify its function (as in inner workings) without changing the actual code. I've never done this before, hence, having some problems while replacing it. Changing the code will have me accessing the package within my python library which is not much of an option. For example if the module was called testMOD class testMOD(object): def testFunc(self, variable): var = variable self.something = var + 12 Then I would import

Why do I need __init__.py at every level? [duplicate]

雨燕双飞 提交于 2019-12-18 13:12:43
问题 This question already has answers here : What is __init__.py for? (11 answers) Closed 2 years ago . Given that I have the following directory structure with . being the current working directory . \---foo \---bar \---__init__.py \---baz.py When I run python -c "import foo.bar.baz" I get Traceback (most recent call last): File "<string>", line 1 ImportError: No module named foo.bar.baz If I echo "" > foo/__init__.py , the above command works. Am I doing something wrong or do I misunderstand

Importing everything ( * ) dynamically from a module

江枫思渺然 提交于 2019-12-18 12:49:10
问题 I have a Python module that I want to dynamically import given only a string of the module name. Normally I use importlib or __import__ and this works quite well given that I know which objects I want to import from the module, but is there a way to do the equivalent of import * dynamically. Or is there a better approach? I know in general its bad practice to use import * but the modules I'm trying to import are automatically generated on the fly and I have no way of knowing the exact module

Intellij/Pycharm can't debug Python modules

こ雲淡風輕ζ 提交于 2019-12-18 12:15:29
问题 I use PyCharm / IntelliJ community editions from a wile to write and debug Python scripts, but now I'm trying to debug a Python module , and PyCharm does a wrong command line instruction parsing, causing an execution error, or maybe I'm making a bad configuration. This is my run/debug configuration: And this is executed when I run the module (no problems here): /usr/bin/python3.4 -m histraw But when I debug, this is the output in the IntelliJ console: /usr/bin/python3.4 -m /opt/apps/pycharm

A plethora of Python OSC modules - which one to use?

房东的猫 提交于 2019-12-18 10:36:14
问题 Open Sound Control (OSC) is a protocol for communication among computers, sound synthesizers, and other multimedia devices that is optimized for modern networking technology. It is particularly common to use OSC with MAX/MSP -- which in fact is what I am doing, using OSC with Python to talk to another subsystem in MAX. There are a bunch of python modules that support OSC. Great. And they all claim to be simple, useful, and perfect. At the risk of verging into subjective territory, what use