Connect to a Redis cluster with Python

To connect to a Redis server with Python, one can use python3-redis module. First verify that python3-redis module is installed. I’m showing the package name in Fedora 39, if you use a different distro, then check for the relevant package name. $ rpm -q python3-redis python3-redis-4.3.3-1.el9.noarch Here is the sample code to connect to a non-cluster Redis server: import redis # Connect to Redis r = redis.Redis(host='10.97.147.175', port=6379) # Set a key-value pair r....

April 3, 2024 · 1 min · 191 words · kenno

How to extract a zip archive with Python on Windows

Have you ever been asked or wonder how to learning a programming language? If not, then you can skip this blog post. :-) At work, a coworker said to me “I want to learn a programming language. Where do I start or how do I even start it?” I was asked this question because I had explicitly expressed my interest to my teams that I like programming a lot, though programming is not being used my professional career at the moment....

September 26, 2023 · 3 min · 466 words · kenno

Install Ansible on Freebsd

This post briefly explains how to install Ansible on a FreeBSD host. I’m going to install Ansible in a virtual environment using Python 3. (If you still use Python 2, it’s time to start migrating to Python 3 now.) $ sudo pkg install python36 $ mkdir ~/dev/python3-venv $ python3 -m venv ~/dev/python3-venv/ansible Next, activate the Python venv (ansible), and start installing Ansible using pip: $ source ~/dev/python3-venv/ansible $ pip install ansible You may or may not need to update pip module as I did....

February 21, 2019 · 1 min · 138 words · kenno

Installing Pip with Python 3.5 on FreeBSD

Here is a quick note serves as a self-reminder on how to get pip working or installed on FreeBSD 10.3. First, ensure that Python 3 package is installed. Python 3 is provided by python35 package. # pkg install python35 However, there is no package for pip, at least at the time of this writing, on FreeBSD. To have it installed, run the following command: # python3.5 -m ensurepip We should as well update pip to new version:...

May 6, 2016 · 1 min · 84 words · kenno

Python: How to convert a list to a string

There must already exist a gazillion articles about how to do this; but one more won’t hurt, right? Suppose you have a list, called alist, as the following: In [2]: alist Out[2]: ['apple', 'banana', 'pear'] To create a string from “alist” with a comma separator, we can do this: In [3]: ','.join(alist) Out[3]: 'apple,banana,pear' Basically, you can place a desired separator in the ',' or omit it totally. Reference: http://www.decalage.info/en/python/print_list

August 2, 2014 · 1 min · 70 words · kenno

Install Python 3 on CentOS 6

The latest release of Python 3 is 3.3.2, and there’s no package available on CentOS repo via yum. The following steps explains how to manually get Python 3 onto a CentOS system: Install development tools # yum groupinstall "Development Tools" # yum install zlib-devel bzip2-devel openssl-devel \ ncurses-devel sqlite-devel readline-devel tk-devel Download and install Python $ wget http://python.org/ftp/python/3.3.2/Python-3.3.2.tar.bz2 $ tar xjf Python-3.3.2.tar.bz2 $ cd Python-3.3.2 $ ./configure --prefix=/opt/python3 $ make $ make install</pre> Test...

September 4, 2013 · 1 min · 81 words · kenno

Python MySQLdb package for Debian

I try to use MySQLdb module with my Python code for the first time. This is what I see: import MySQLdb Traceback (most recent call last): File "", line 1, in ImportError: No module named MySQLdb your code here For Debian, the package for MySQLdb module is python-mysqldb. # apt-get install python-mysqldb Now, let’s verify if MySQLdb module has been correctly installed: >>> import MySQLdb >>> No more import error message, which means you can start using MySQldb module now....

November 9, 2008 · 1 min · 80 words · kenno