python-module

Python pdb on python script run as package

孤者浪人 提交于 2019-12-23 07:55:21
问题 I have a python program that I usually run as a part of a package: python -m mymod.client in order to deal with relative imports inside "mymod/client.py." How do I run this with pdb - the python debugger. The following does not work: python -m pdb mymod.client It yields the error: Error: mymod.client does not exist EDIT #1 (to address possible duplicity of question) My question isn't really about running two modules simultaneously python, rather it is about how to use pdb on a python script

What does Cython do with imports?

混江龙づ霸主 提交于 2019-12-23 07:47:11
问题 I want to create a Python extension and I really like the idea of using Cython. Mainly to gain more knowledge about it and to take advantage of speed gains, if any. I have read quite a bit of Cython documentation but I am not a computer scientist (yet) and do not have an in depth knowledge to understand the low-level basics, hence the reason for my following questions: I was just wondering, what happens if I use an externally imported (for example, an ORM or SQL library or any other 3rd party

Python Module Imports - Explicit vs Implicit Relative Imports

若如初见. 提交于 2019-12-22 03:17:11
问题 Last night, when working on my mac, I set up some module imports in my __init__.py 's from MongoProvider import MongoProvider from Settings import Settings etc. I'm unsure of what version of Python is on that machine. I'll edit the question later with that info once I have it. Today, working on a different machine, which is Windows and using Python 3.3.3, my module imports were breaking. By adding an explicit relative import (adding a leading dot), I was able to fix the issue. from

How to install Python module on Ubuntu

爱⌒轻易说出口 提交于 2019-12-22 01:50:37
问题 I just wrote a function on Python. Then, I wanted to make it module and install on my Ubuntu 11.04. Here is what I did. Created setup.py along with function.py file. Built distribution file using $Python2.7 setup.py sdist Then installed it $Python2.7 setup.py install All was going fine. But, later I wanted to use the module importing it on my code. I got import error: ImportError: No module named '-------' PS. I searched over google and didn't find particular answer. Detailed answer will be

How to split a Python module into multiple files?

泪湿孤枕 提交于 2019-12-22 01:34:45
问题 I have a single Python module which contains 3 classes: A, A1 and A2. A1 and A2 derive from A. A contains functions which operate on A1 and A2. This all works fine when it's in one .py file. But that file has grown quite long and I would like to split A1 and A2 off into their own files. How can I split this file despite a circular dependency? 回答1: modA.py: class A(...): ... modA1.py: import modA class A1(modA.A): ... modA2.py: import modA class A2(modA.A): ... modfull: from modA import A from

How to use sys.path_hooks for customized loading of modules?

夙愿已清 提交于 2019-12-21 17:58:07
问题 I hope the following question is not too long. But otherwise I cannot explain by problem and what I want: Learned from How to use importlib to import modules from arbitrary sources? (my question of yesterday) I have written a specfic loader for a new file type (.xxx). (In fact the xxx is an encrypted version of a pyc to protect code from being stolen). I would like just to add an import hook for the new file type "xxx" without affecting the other types (.py, .pyc, .pyd) in any way. Now, the

Python import modules in another file

十年热恋 提交于 2019-12-21 17:54:57
问题 I'm currently re-factoring a project (formerly big one file) into several seperate python files, each of which runs a specific part of my application. Eg, GUIthread.py runs the GUI, Computethread.py does some maths, etc etc. Each thread includes the use of functions from imported modules like math , time , numpy , etc etc. I already have a file globalClasses.py containing class definitions for my datatypes etc, which each .py file imports at the start, as per recomendation here: http://effbot

Is there a way to run a python script that is inside a zip file from bash?

二次信任 提交于 2019-12-21 12:22:24
问题 I know there is a way to import modules which are in a zip file with python. I created kind of custom python package library in a zip file. I would like to put as well my "task" script in this package, those are using the library. Then, with bash, I would like to call the desired script in the zip file without extracting the zip. The goal is to have only one zip to move in a specified folder when I want to run my scripts. 回答1: I finally found a way to do this. If I create a zip file, I must

Mapping module imports in Python for easy refactoring

≡放荡痞女 提交于 2019-12-20 17:59:23
问题 I have a bunch of Python modules I want to clean up, reorganize and refactor (there's some duplicate code, some unused code ...), and I'm wondering if there's a tool to make a map of which module uses which other module. Ideally, I'd like a map like this: main.py -> task_runner.py -> task_utils.py -> deserialization.py -> file_utils.py -> server.py -> (deserialization.py) -> db_access.py checkup_script.py re_test.py main_bkp0.py unit_tests.py ... so that I could tell which files I can start

Obtaining module name: x.__module__ vs x.__class__.__module__

本秂侑毒 提交于 2019-12-19 19:52:47
问题 I want to obtain the module from which a Python object is from. Both x.__module__ and x.__class__.__module__ seem to work. Are these completely redundant? Is there any reason to prefer one over another? 回答1: If x is a class then x.__module__ and x.__class__.__module__ will give you different things: # (Python 3 sample; use 'class Example(object): pass' for Python 2) >>> class Example: pass >>> Example.__module__ '__main__' >>> Example.__class__.__module__ 'builtins' For an instance which