Home » Search results for 'python attribute'

Python setAttr() – What it Does and How to Use It [Examples]

Python use setattr() to set object attributes

The setattr() function is used to set the value of an attribute of an object. Here is how it is used, with examples. Python Objects and Classes Python is an object oriented programming language. Object oriented means that rather than code being written as a list of instructions, accumulating data and passing the results to the following lines of code (known as procedural programming), data and functionality is contained within the objects it describes. Each object is a self-contained representation of something, that can be modified, and passed between functions … Read more

Home » Search results for 'python attribute'

Python hasattr() – What it Does and How to Use It [Examples]

Python use hasattr() to check object properties

The hasattr() function is used to check whether an object has a given named attribute. Here is how it is used, with examples. Python Objects and Classes Python is an object oriented programming language. Object oriented means that rather than code being written as a list of instructions, accumulating data and passing the results to the following lines of code (known as procedural programming), data and functionality is contained within the objects it describes. Each object is a self-contained representation of something, that can be modified, and passed between functions … Read more

Home » Search results for 'python attribute'

Python getattr() – What it Does and How to Use It [Examples]

Python use getattr() to get object attributes

The getattr() function is used to get the value of an attribute of an object. Here is how it is used, with examples. Python Objects and Classes Python is an object oriented programming language. Object oriented means that rather than code being written as a list of instructions, accumulating data and passing the results to the following lines of code (known as procedural programming), data and functionality is contained within the objects it describes. Each object is a self-contained representation of something, that can be modified, and passed between functions … Read more

Home » Search results for 'python attribute'

Running External Programs in Python with subprocess [Examples]

Python subprocess

This article will show you how to use the Python subprocess module to run external programs and scripts from Python. It is often necessary to call external applications from Python. Usually these are command-line applications which you can use to perform tasks outside of the Python environment, like manipulating files, or interacting with third party services. For example, you might call the wget command to retrieve a remote file. Any application which is accessible on the command line is available to subprocess, and can be executed from within Python. You … Read more

Home » Search results for 'python attribute'

The Python ‘os’ Library – What it is and How it’s Used

Python os Library

This article will give a short overview of the Python os (Operating System) module – and show some examples of how it is used. What is the Python ‘os’ Library/Module? The Python os library contains helpful tools and functions for interacting with the underlying Operating System being used to execute the running Python code. It can be used to query information about the system environment – including operating system, disk space, memory information, and which path Python is being executed from. The information available will differ depending on which operating system Python is … Read more

Home » Search results for 'python attribute'

What are Python Docstrings and How Are They Used?

Python Docstring

This tutorial will explain what docstrings are in the Python programming language and how they can be used. What is a Docstring in Python? A docstring is a string literal that is used to document your code. A string literal is a sequence of characters 0 or more characters in length, which is to be treated as a single entity – i.e., it’s a string variable of any length. A docstring appears after the definition of a module, class, method, or function and should explain the purpose of the object it … Read more

Home » Search results for 'python attribute'

How to Merge Dictionaries in Python, With Examples

Python Merge Dictionaries

This article will show you the simplest ways to merge two or more dictionaries in the Python programming language. Note that the code examples in this article are written for Python version 3 – and will not work with Python version 2! What is a Dictionary in Python? We’ve covered what dictionaries are in our article here. As there are a couple of ways to merge multiple dictionaries in Python, we’ve put together this article separately to make sure we’ve got everything covered! Merging/Joining Using Dictionary Union … Read more

Home » Search results for 'python attribute'

Enums in Python – What They Are, How to Use Them

Python Enum

This article will teach you what an Enum is, and how they are used in the Python programming language. What is an Enum? An Enum (Enumerated Type) is a data structure containing multiple values. Each value is assigned to an identifier – and can be accessed by that identifier. Enums contain pre-defined constants that aren’t expected to change (they’ll be the same when the application is written and when it is run so that you can always refer to the data in the enum by the same identifier and get … Read more

Home » Search results for 'python attribute'

Command Line Arguments in Python Scripts, With Examples

Python Command Line Arguments

This article will show you simple methods to pass command line arguments to your Python scripts, with some examples. Passing arguments to your script makes it easy to build multi-use scripts that can work on different inputs. This is much easier than re-editing your code every time you want to change the inputs it will be working on. I’ve previously covered building a full command-line application in Python, which accepts command-line options and bundles the application into a distributable package with no external dependencies – … Read more

Home » Search results for 'python attribute'

Python List ‘sort()’ Method – Sorting Lists in Python Easily

Sorting Lists in Python Easily

In Python, there’s an easy way to sort lists: using the sort() method. This tutorial explains how to use sort(), with examples. We’ve covered the following in Python: Removing list items Checking if items are in lists Finding items in lists Now it’s time to find out how to sort a list. Syntax for the sort() Method list.sort(reverse=True|False, key=sortFunction) Note that: ‘reverse’ should be a True/False boolean value and is optional reverse=True will sort the list descending The default is reverse=False True/False values case sensitive in Python! … Read more