Archive for the ‘python’ Category

Save python os.system output (stdout) in variable [SOLVED]

If you try something like this in python: a = os.system("find / -name myfile.ext") print a   # the output for find will be printed, but ‘a’ will store the exit code of the find command So, how do you save the output of os.system to a variable? Use the subprocess module and proceed like: [...]

CDS-Invenio: List DELETED RECORDS from collection name – python script

Some time ago I posted some cds invenio mysql useful queries. Some people wrote some days ago asking wether I could put this into a function. Here you are List all deleted records which belong(ed) to collection ‘colname’ (tested with Invenio 0.99.x) def listDeletedFromCollname(colname, coltag=’980__c’): from invenio.dbquery import run_sql query = """ SELECT distinct bibrec_bib98x.id_bibrec [...]

Python: autocomplete names with tab key [solved]

I learned a python trick that saved me a lot of time when using the interpreter. Just wanted to share it with you. >>> import rlcompleter, readline >>> readline.parse_and_bind("tab:complete") With the above lines you’ll have a unix-like autocomplete for functions. For instance, if you type >>> import os >>> os. And then you press “TAB” [...]

Know mod_python running version [SOLVED]

A friend of mine asked yesterday: how do I get the mod_python version that my site is running? Answer is quite easy! >>> import mod_python >>> print mod_python.version 3.3.1

Python & Oracle [SOLVED] ImportError: libclntsh.so.11.1: wrong ELF class: ELFCLASS32

If you are getting a message like this: >>> import cx_Oracle Traceback (most recent call last): File "<stdin>", line 1, in ? ImportError: libclntsh.so.11.1: wrong ELF class: ELFCLASS32 It means you are having issues with ELF (Executable and Linkable Format) How to solve em? First, locate the path to libclntsh.so.11.1 (usually in /usr): [root@zaguan importaFHdesdeRoble]# [...]

Eliminar tildes con python [SOLUCIONADO]

Es muy probable que si programas en python te encuentres, alguna vez, con una situación en la que debes eliminar las tildes de algún texto. Esto se puede hacer fácilmente utilizando el módulo unicodedata. He creado la funcion elimina_tildes tal que asi: 1 2 3 4 5 6 7 import unicodedata def elimina_tildes(s): return ”.join((c [...]

[Errno 13] Permission denied: ‘/root/.python-eggs’ [SOLVED]

A few days ago I had to install MySQLdb. The installation is quite simple: # tar -xzvf MySQL-python-1.2.2.tar.gz # cd MySQL-python-1.2.2 # python setup.py build # python setup.py install But then I checked a page which had to use this python module (MySQLdb) and… oops, it did not work: Can’t extract file(s) to egg cache [...]

Utilizando ECLIPSE para programar python en entorno git

A modo de chuleta, una vez más, os pongo los pasos necesarios para trabajar con Eclipse, EGit y PyDev. 1. Instalar Eclipse Classic. 2. Iniciar Eclipse, y deberías ver una pantalla similar a: 3. Instalar PyDev desde Eclipse. Para ello, en la pantalla anterior, pulsa sobre la flecha de la derecha. Aparecerá una pantalla de [...]

Python: how do I check the variable type? [solved]

This is a usual question in python forums. How (the hell!) do I check my variable’s type? I am NOT a python-pro, but I have to deal with this language very often, as CDS Invenio is coded using python. Well, I was changing a function and wanted to check the type of a variable… First [...]

CDS-Invenio: [notice] mod_python: (Re)importing module ‘mod_python.publisher’

Yesterday I looked at /var/log/httpd/error_log and observed a [notice] mod_python: (Re)importing module ‘mod_python.publisher’ was filling apache error_log file. Tibor (from CDS Support Team) told me this was a harmless notice I could safely ignore. I wanted to get rid of it because it fills logs, so I decided to upgrade my mod_python to last version [...]

Paypal donate

Please help me keep this blog up by donating.

Por favor, ayúdame a continuar con el blog donando.