Fix Python – How to make a python, command-line program autocomplete arbitrary things NOT interpreter

I am aware of how to setup autocompletion of python objects in the python interpreter (on unix).

Google shows many hits for explanations on how to do this.
Unfortunately, there are so many references to that it is difficult to find what I need to do, which is slightly different.

I need to know how to enable, tab/auto completion of arbitrary it….

Fix Python – how to check which version of nltk, scikit learn installed?

In shell script I am checking whether this packages are installed or not, if not installed then install it. So withing shell script:
import nltk
echo nltk.__version__

but it stops shell script at import line
in linux terminal tried to see in this manner:
which nltk

which gives nothing thought it is installed.
Is there any other way to verify thi….

Fix Python – Two versions of python on linux. how to make 2.7 the default

I’ve got two versions of python on my linuxbox:
$python
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

$ /usr/local/bin/python2.7
Python 2.7.3 (default, Oct 8 2013, 15:53:09)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on ….

Fix Python – Cannot kill Python script with Ctrl-C

I am testing Python threading with the following script:
import threading

class FirstThread (threading.Thread):
def run (self):
while True:
print ‘first’

class SecondThread (threading.Thread):
def run (self):
while True:
print ‘second’

FirstThread().start()
SecondThread().start()

This is running ….

Fix Python – Getting MAC Address

I need a cross platform method of determining the MAC address of a computer at run time. For windows the ‘wmi’ module can be used and the only method under Linux I could find was to run ifconfig and run a regex across its output. I don’t like using a package that only works on one OS, and parsing the output of another program doesn’t seem very e….

Fix Python – Call Python script from bash with argument

I know that I can run a python script from my bash script using the following:
python python_script.py

But what about if I wanted to pass a variable / argument to my python script from my bash script. How can I do that?
Basically bash will work out a filename and then python will upload it, but I need to send the filename from bash to python when….

Fix Python – linux tee is not working with python?

I made a python script which communicates with a web server using an infinite loop.
I want to log every communication data to a file and also monitor them from terminal at same time. so I used tee command like this.
python client.py | tee logfile

however, I got nothing from terminal nor logfile.
the python script is working fine.
what is happenin….

Fix Python – Why does multiprocessing use only a single core after I import numpy?

I am not sure whether this counts more as an OS issue, but I thought I would ask here in case anyone has some insight from the Python end of things.
I’ve been trying to parallelise a CPU-heavy for loop using joblib, but I find that instead of each worker process being assigned to a different core, I end up with all of them being assigned to the sa….

Fix Python – Running a Python script from PHP

I’m trying to run a Python script from PHP using the following command:
exec(‘/usr/bin/python2.7 /srv/http/assets/py/switch.py arg1 arg2’);
However, PHP simply doesn’t produce any output. Error reporting is set to E_ALL and display_errors is on.
Here’s what I’ve tried:

I used python2, /usr/bin/python2 and python2.7 instead of /usr/bin/python2.7
I….