python-module

How do I get ibm_db or PyDB2 python modules to work with DB2 in Mac OS X 10.7 Lion?

♀尐吖头ヾ 提交于 2019-12-06 10:38:43
问题 I used this question/answer to install DB2 in Lion: How do I install IBM DB2 Express-C on Mac OS X 10.7 Lion? After configuring my databases, I am able to use db2 from the command line to execute queries, but the python modules ibm_db and PyDB2 both fail to import with the following error: >>> import ibm_db Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: dlopen(/Library/Python/2.7/site-packages/ibm_db-1.0.4-py2.7-macosx-10.7-intel.egg/ibm_db.so, 2): Symbol

Automatically call common initialization code without creating __init__.py file

♀尐吖头ヾ 提交于 2019-12-06 05:26:15
问题 I have two directories in my project: project/ src/ scripts/ "src" contains my polished code, and "scripts" contains one-off Python scripts. I would like all the scripts to have "../src" added to their sys.path, so that they can access the modules under the "src" tree. One way to do this is to write a scripts/__init__.py file, with the contents: scripts/__init__.py: import sys sys.path.append("../src") This works, but has the unwanted side-effect of putting all of my scripts in a package

Is there anything like Python export?

纵饮孤独 提交于 2019-12-06 00:03:57
问题 We use all the time python's import mechanism to import modules and variables and other stuff..but, is there anything that works as export? like: we import stuff from a module: from abc import * so can we export like?: to xyz export * or export a,b,c to program.py I know this question isn't a typical type of question to be asked here..but just in curiosity..I checked over the python console and there is nothing that exists as 'export'..maybe it exists with some different name..? 回答1: First,

Python import modules, folder structures

假如想象 提交于 2019-12-05 21:31:15
问题 I have been looking for a way to solve this. I have a python project, and this is the folder structure I want: /project/main.py /project/src/models.py /project/test/tests.py I want to be able to run the tests by executing the tests.py in terminal. tests.py imports modules in /project/src/ for testing. First I solved this by adding sys.path.insert(0, '..') in tests.py. But then the paths used in models.py for opening text files had to be relative to the tests.py , etc. Which means the program

What's the best practice for incorporating third-party libraries in a python program?

人走茶凉 提交于 2019-12-05 21:03:44
Good afternoon. I am writing a small to medium-sized python program for my job. The task requires me to use the Excel libraries xlwt and xlrd , as well as a library for querying Oracle databases, called cx_Oracle . I am developing the project through a version control system, namely CVS. I was wondering what is the standard way to organize third-party libraries around a python project. Should the libraries xlwt, xlrd, and cx_Oracle be stored in a directory such as /usr/local/lib/python, which presumably has its place in the PYTHONPATH? Or should the third-party libraries instead be included in

paramiko python module hangs at stdout.read()

左心房为你撑大大i 提交于 2019-12-05 01:40:00
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 comes to stdout.read() , it hangs... sometimes it prints the output after long time. Can you please

Relative import of package __init__.py

早过忘川 提交于 2019-12-05 01:22:13
Suppose I have a package containing two submodules and also a substantial amount of code in __init__.py itself: pkg/__init__.py pkg/foo.py pkg/bar.py and, to make planned future refactorings easier, I want components of the package to exclusively use relative imports to refer to each other. In particular, import pkg should never appear. From foo.py I can do from __future__ import absolute_import from . import bar to get access to the bar.py module, and vice versa. The question is, what do I write to import __init__.py in this manner? I want exactly the same effect as import pkg as local_name ,

What is the difference between `sys.meta_path` and `sys.path_hooks` importer objects?

泪湿孤枕 提交于 2019-12-05 00:53:12
问题 Using importlib , what is the difference between "Meta Path Finder" (found by traversing over sys.meta_path) and Path Entry Finder" (found by traversing over sys.path_hooks)? The first type is called upon begin of an import, but when is the second type used? Do both return a spec object? I want to implement a customized import, where a module can be imported from sources other than *.py or *.pyc, e.g. from a stream. How can this be done? 回答1: sys.path_hooks returns a finder factory. Path

python calling a module that uses argparser

Deadly 提交于 2019-12-05 00:41:38
This is probably a silly question, but I have a python script that current takes in a bunch of arguements using argparser and I would like to load this script as a module in another python script, which is fine. But I am not sure how to call the module as no function is defined; can I still call it the same way I do if I was just invoking it from cmd? Here is the child script: import argparse as ap from subprocess import Popen, PIPE parser = ap.ArgumentParser( description='Gathers parameters.') parser.add_argument('-f', metavar='--file', type=ap.FileType('r'), action='store', dest='file',

How to split a Python module into multiple files?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 00:38:11
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? 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 modA1 import A1 from modA2 import A2 Even if A "processes" A1s and A2s you should be fine because thanks to