Collection of Checks for Readable and Writable Files.
“Education is the most powerful weapon which you can use to change the world.” ― Nelson Mandela
It can be a bit cumbersome at times to check for read or write permission on a file. The check might succeed but the actual operation could fail. Also, quite a few edge cases need to be covered to get a reasonable answer from such a check. In this article, we cover some issues with regards to checking read and write permission on a file.
Continue reading “Python How to Check if File can be Read or Written”
Easily incorporate strong AES encryption into your programs.
“Believe in your infinite potential. Your only limitations are those you set upon yourself.” ― Roy T. Bennett, The Light in the Heart
Pycrypto is a python module that provides cryptographic services. Pycrypto is somewhat similar to JCE (Java Cryptography Extension) for Java. In our experience JCE is more extensive and complete, and the documentation for JCE is also more complete. That being said, pycrypto is a pretty good module covering many aspects of cryptography.
Continue reading “Using AES for Encryption and Decryption in Python Pycrypto”
Make your life easier with these itertools when dealing with iterables
“A lie gets halfway around the world before the truth has a chance to get its pants on.” ― Anonymous
Python provides the itertools package which provides convenience functions for many common iterator operations. We have covered count(), cycle() and chain() in the first part of this series, and compress(), dropwhile(), and groupby() in the second part. In this article, we present a few examples of ifilter(), islice(), imap() and izip().
Continue reading “Python itertools – ifilter, islice, imap, izip”
More on downloading HTTP URLs using urllib2.
“I like the night. Without the dark, we’d never see the stars.” ― Stephenie Meyer, Twilight
Python provides the well-regarded urllib2 module for opening URLs. Let us investigate some of the capabilities of this module, shall we? Note that most use cases are better served by using the higher level Requests module. However, you should know about the available options.
Continue reading “Python HTTP Client using urllib2”
Learn about all the facilities available with python string formatting
“The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom.” ― Isaac Asimov
String formatting in python is somewhat complicated by the fact that there are a lot of flags and options. Let us learn about them.
Continue reading “Python String Formatting Examples”
Remove items from a List and more.
“Happiness is a perfume you cannot pour on others without getting some on yourself.” ― Ralph Waldo Emerson
In a previous article, we covered some python list methods related to adding items. Let us now continue the review of more list methods.
Continue reading “Python – More List Methods and Recipes”
Check out this refresher on ways to add items to python lists
“Share your knowledge. It is a way to achieve immortality.” ― Dalai Lama XIV
Continue reading “Python List Methods: Adding Items”
Use pipes from multiple threads for bidirectional communication.
“The truth will set you free, but first it will piss you off.” ― Joe Klaas, Twelve Steps to Happiness
Invoking an external process from python and interacting with it can be quite tricky. This is especially true if the interaction is duplex i.e. involving both reading and writing to it. Such an interaction can cause deadlocks since both processes can end up waiting for output from the other. One way to avoid such deadlocks is to separate the reader and writer parts to different threads. We demonstrate such an approach in this article.
Continue reading “How to Avoid Deadlock when Calling External Command from Python”
Use subprocess.Popen for more control over the child process
“The world is a book and those who do not travel read only one page.” ― Augustine of Hippo
In a previous article, we looked at calling an external command in python using subprocess.call(). That method allows you to accomplish several tasks during the invocation:
Continue reading “Run External Command in Python Using Popen”
Learn about the various aspects of the subprocess module.
“I hate quotations. Tell me what you know.” ― Ralph Waldo Emerson, The Essays of Ralph Waldo Emerson
Do you want to run an external command from inside python? Maybe you want to startup a daemon process (no input or output), or perhaps invoke a command and capture its output?
Continue reading “How to Call an External Command in Python”