Command Line Arguments in Python

Overview With Python being such a popular programming language, as well as having support for most operating systems, it’s become widely used to create command line tools for many purposes. These tools can range from simple CLI apps to those that are more complex, like AWS’ awscli tool. Complex tools like this are typically controlled by the user via command line arguments, which allows the user to use specific commands, set options, and more. For example, these options could tell […]

Read more

How to Copy a File in Python

Introduction When it comes to using Python to copy files, there are two main ways: using the shutil module or the os module. All of the os methods we show here are methods that allow us to execute shell commands from our Python code, which we’ll use to execute the copy command (Windows) or the cp command (Unix). You’ll notice that many of these methods, in both the shutil module and the os module, have very similar functionality (which shouldn’t […]

Read more

Reading Files with Python

To work with stored data, file handling belongs to the core knowledge of every professional Python programmer. Right from its earliest release, both reading and writing data to files are built-in Python features. In comparison to other programming languages like C or Java it is pretty simple and only requires a few lines of code. Furthermore, no extra module has to be loaded to do that properly. Basics of Files in Python The common methods to operate with files are […]

Read more

Reading and Writing Lists to a File in Python

As serialized data structures, Python programmers intensively use arrays, lists, and dictionaries. Storing these data structures persistently requires either a file or a database to work with. This article describes how to write a list to file, and how to read that list back into memory. To write data in a file, and to read data from a file, the Python programming language offers the standard methods write() and read() for dealing with a single line, as well as writelines() […]

Read more
1 2