Fix Python – Importing a long list of constants to a Python file

In Python, is there an analogue of the C preprocessor statement such as?:
#define MY_CONSTANT 50
Also, I have a large list of constants I’d like to import to several classes. Is there an analogue of declaring the constants as a long sequence of statements like the above in a .py file and importing it to another .py file?
Edit.
The file Constants.p….

Fix Python – Python: reload component Y imported with ‘from X import Y’?

In Python, once I have imported a module X in an interpreter session using import X, and the module changes on the outside, I can reload the module with reload(X). The changes then become available in my interpreter session.
I am wondering if this also possible when I import a component Y from module X using from X import Y.
The statement reload Y….

Fix Python – Python Nose Import Error

I can’t seem to get the nose testing framework to recognize modules beneath my test script in the file structure. I’ve set up the simplest example that demonstrates the problem. I’ll explain it below.
Here’s the the package file structure:
./__init__.py
./foo.py
./tests
./__init__.py
./test_foo.py

foo.py contains:
def dumb_true():
retu….

Fix Python – how to “reimport” module to python then code be changed after import

I have a foo.py
def foo():
print “test”

In IPython I use:
In [6]: import foo
In [7]: foo.foo()
test

Then I changed the foo() to:
def foo():
print “test changed”

In IPython, the result for invoking is still test:
In [10]: import foo
In [11]: foo.foo()
test

Then I use:
In [15]: del foo
In [16]: import foo
In [17]: foo.foo()
test

I….

Fix Python – Python: Best way to add to sys.path relative to the current running script

I have a directory full of scripts (let’s say project/bin). I also have a library located in project/lib and want the scripts to automatically load it. This is what I normally use at the top of each script:
#!/usr/bin/python
from os.path import dirname, realpath, sep, pardir
import sys
sys.path.append(dirname(realpath(__file__)) + sep + pardir + s….

Fix Python – ImportError: libSM.so.6: cannot open shared object file: No such file or directory

When trying to import OpenCV, using import cv2 I get the following error:
/usr/local/lib/python2.7/dist-packages/cv2/__init__.py in ()
7
8 # make IDE’s (PyCharm) autocompletion happy
—-> 9 from .cv2 import *
10
11 # wildcard import above does not import “private” variables like __version__

ImportError: libSM.so.6….