Skip to content

Tag: python

Unable to fake terminal input with termios.TIOCSTI

Most of the code samples I’ve seen are trying to read from stdin without local echo. To do this they modify the “local modes” flag to remove the setting to “Echo input characters”. I thought I could just modify the “input modes” flag to TIOCSTI which is for “Ins…

How to pass variables in parent to subprocess in python?

I am trying to have a parent python script sent variables to a child script to help me speed-up and automate video analysis. I am now using the subprocess.Popen() call to start-up 6 instances of a child script but cannot find a way to pass variables and modules already called for in the parent to the child. F…

Python3 exec, why returns None?

When the code below this text, and returns the result None why? Result: Module code exx.py: Answer The problem of course is not only that print returns None, it is that exec returns None, always. If you’d need the return value, you’d use eval: after which you’d notice that print still return…

Plotting correlation heatmaps with Seaborn FacetGrid

I am trying to create a single image with heatmaps representing the correlation of features of data points for each label separately. With seaborn I can create a heatmap for a single class like so An I get this which makes sense: But then I try to make a list of all the labels like so: And sadly I get

Naturally sorting Pandas DataFrame

I have a pandas DataFrame with indices I want to sort naturally. Natsort doesn’t seem to work. Sorting the indices prior to building the DataFrame doesn’t seem to help because the manipulations I do to the DataFrame seem to mess up the sorting in the process. Any thoughts on how I can resort the i…

Shuffle DataFrame rows

I have the following DataFrame: The DataFrame is read from a CSV file. All rows which have Type 1 are on top, followed by the rows with Type 2, followed by the rows with Type 3, etc. I would like to shuffle the order of the DataFrame’s rows so that all Type’s are mixed. A possible result could be:…

how to deactivate virtualenv from a bash script

I’m a novice in shell scripting, but I want to make a bash script for activate/deactivate a virtual enviroment using virtualenv. Then I want to use this script like a service in Ubuntu copying it inside /etc/init.d folder. In my script, I have a variable like this: VENV=/opt/odoo/odoo_server/venv_oddo/b…

First occurrence of a number in python list

I have a long list which consist of two fixed possible numbers (0 and 1). e.g: I don’t know which number occurs first in the list but I am sure that if 0 is occurring first in the list then it will occur consecutively followed by 1, same case for 1. I am performing some kind of action on the