python-2.6

Calling app from subprocess.call with arguments

Calling app from subprocess.call with arguments Question: I’m a beginner in Python, and I’ve been trying to call a command line app, but it fails: >>> import subprocess as s >>> s.call(“gpio -g read 17”) Traceback (most recent call last): File “<stdin>”, line 1, in <module> File “/usr/lib/python2.6/subprocess.py”, line 470, in call return Popen(*popenargs, **kwargs).wait() …

Total answers: 1

"outsourcing" exception-handling to a decorator

"outsourcing" exception-handling to a decorator Question: Many try/except/finally-clauses not only “uglify” my code, but i find myself often using identical exception-handling for similar tasks. So i was considering reducing redundancy by “outsourcing” them to a … decorator. Because i was sure not to be the 1st one to come to this conclusion, I googled and …

Total answers: 3

Get all object attributes in Python?

Get all object attributes in Python? Question: Is there a way to get all attributes/methods/fields/etc. of an object in Python? vars() is close to what I want, but it doesn’t work unless an object has a __dict__, which isn’t always true (e.g. it’s not true for a list, a dict, etc.). Asked By: user541686 || …

Total answers: 4

Python 2.6 TreeMap/SortedDictionary?

Python 2.6 TreeMap/SortedDictionary? Question: Is there a built-in sorted dictionary implementation in Python 2.6, or are hashtables the only kind? Clarifications: I’m asking about sorted dictionarys, not ordered dictionaries! Asked By: user541686 || Source Answers: I think the answer here is no. There is a Treemap but it isn’t in the python standard library. http://pypi.python.org/pypi/treemap/ …

Total answers: 5

Running a python package

Running a python package Question: Running Python 2.6.1 on OSX, will deploy to CentOS. Would like to have a package to be invoked from a command line like this: python [-m] tst For that, here is the directory structure made: $PYTHONPATH/ tst/ __init__.py # empty __main__.py # below dep.py # below The following is in …

Total answers: 1

How to convert a set to a list in python?

How to convert a set to a list in python? Question: I am trying to convert a set to a list in Python 2.6. I’m using this syntax: first_list = [1,2,3,4] my_set=set(first_list) my_list = list(my_set) However, I get the following stack trace: Traceback (most recent call last): File “<console>”, line 1, in <module> TypeError: ‘set’ …

Total answers: 9

How do you get the current text contents of a QComboBox?

How do you get the current text contents of a QComboBox? Question: Using pyqt4 and python 2.6, I am using a qcombobox to provide a list of options. I am having problems with using the selected option. I have been able to use a signal to trigger a method when the option is selected, but …

Total answers: 4

How to get the current running module path/name

How to get the current running module path/name Question: I’ve searched and this seems to be a simple question without a simple answer. I have the file a/b/c.py which would be called with python -m a.b.c. I would like to obtain the value a.b.c in the module level. USAGE = u”’ Usage: python -m %s …

Total answers: 8

Setup.py: install lxml with Python2.6 on CentOS

Setup.py: install lxml with Python2.6 on CentOS Question: I have installed Python 2.6.6 on CentOS 5.4, [@SC-055 lxml-2.3beta1]$ python Python 2.6.6 (r266:84292, Jan 4 2011, 09:49:55) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> I want to use the lxml module, but build from sources …

Total answers: 4