How to Move/Copy a File or Directory (Folder) with a Progress Bar in Python

In the last article, titled How to Recursively Copy a Folder (Directory) in Python, I covered how to copy a folder recursively from one place to another. As useful as that is, there is still something else that we could add that would make copying a directory much more user friendly! Enter the progress bar […]

Read More

How to Recursively Copy a Folder (Directory) in Python

Ever tried to copy a directory/folder in Python? Ever failed? No matter. Try again! If you haven’t already read it, look at the article How to Copy a File in Python with shutil for an explanation of how to copy files with shutil. Recursively Copying a Directory/Folder of Files in Python In the article that […]

Read More

How to Rename (Move) a File in Python

Renaming (in Python it’s known as moving) a file in Python is really simple, and can be done in very few lines thanks to a handy module called shutil. shutil has a function called move that does precisely what the function name implies. It moves files or directories from one location to another. Here’s a […]

Read More

How to Slice Custom Objects/Classes in Python

For an introduction to slicing, please view the article How to Slice Lists/Arrays and Tuples in Python. Slicing Your Own Python Objects Alright, that’s all cool, now we know how to slice. But how do we slice our own objects? If I implement an object that has a list, or custom data structure, how do […]

Read More

How to See if a String Contains Another String in Python

Ever wanted to see if a string contains a string in Python? Thought it was going to be complicated like C? Think again! Python implements this feature in a very easy to read and easy to implement fashion. There are two ways of doing it, and some will like one way better than the other, […]

Read More

How to Copy a File in Python with shutil

So you want to know how to copy a file in Python? Good! It’s very useful to learn and most complex applications that you may design will need at least some form of copying files. Copying a Single File in Python Alright, let’s get started. This first section will describe how to copy a single […]

Read More

How to Slice Lists/Arrays and Tuples in Python

So you’ve got an list, tuple or array and you want to get specific sets of sub-elements from it, without any long, drawn out for loops? Python has an amazing feature just for that called slicing. Slicing can not only be used for lists, tuples or arrays, but custom data structures as well, with the […]

Read More

How to Get a Sub-string From a String in Python – Slicing Strings

So how do you get a sub-string in Python? Well, Python has a handy dandy feature called “slicing” that can be used for getting sub-strings from strings. But first, we have to go over a couple of things to understand how this works. Slicing Python Objects Strings, in Python, are arrays of characters, except they […]

Read More

How to Use Python’s xrange and range

Python has two handy functions for creating lists, or a range of integers that assist in making for loops. These functions are xrange and range. But you probably already guessed that! The Difference Between xrange and range in Python Before we get started, let’s talk about what makes xrange and range different. For the most […]

Read More

How to Sort a List, Tuple or Object (with sorted) in Python

Sorting a list or tuple is easy in Python! Since a tuple is basically like an array that is not modifiable, we’ll treat it almost the same as a list. Sorting a Python List the Simple Way Okay, so if you only want to sort a list of numbers, Python has a built in function […]

Read More