Welcome to LinuxScrew

A site for Linux lovers worldwide. For newbies, system engineers, administrators, and everybody in between. We cover all things Linux, plus various programming languages, including Python, Javascript, and PHP.

View our featured tutorials and projects in the slider below or scroll down to see all recent articles.

How to Convert a USB Printer to Wireless with a Raspberry Pi
How to Use a Raspberry Pi for Digital Signage
The Worst Things You’ll Probably Google As a Programmer on Linux
How to Build a Raspberry Pi Internet Kiosk
Browsing the Internet on a 1989 Macintosh II with a Web Rendering Proxy
previous arrow
next arrow
Slider

The tr Command in Linux – What It Is and How To Use It

Linux tr Command

The tr (translate) command in Linux reads text from standard input, performs some modification to the text, and then sends it to standard output. This article explains and shows why and how you might use it. tr Command Syntax Here’s the syntax you’ll need to use the command: tr OPTIONS SET1 [SET2] Note that: OPTIONS should be a list of options from the below table The characters in SET1 will be replaced with the characters in the corresponding position in SET2 These are optional – some of the OPTIONS are capable of performing translations, … Read more

How to Use MySQL ‘alias’ to Make Queries Easier to Read

MySQL Alias

This article will explain and demonstrate the use of aliases in MySQL (and MariaDB). MySQL queries can get pretty gnarly – especially if you’re selecting multiple columns from multiple tables. An alias statement is a great tool for simplifying these queries. An alias is just another name for the column or table in question, which you can use to refer to the column or table by. It’s a nickname that can be used to quickly refer to something complex to save time when writing queries. MySQL Column Alias … Read more

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

Square Numbers and Exponents in Python, With Examples

Square Numbers and Exponents in Python

This tutorial will show you how to use exponents (e.g., calculating the square root of a number) in Python, with some code examples. This tutorial covers several ways to calculate exponents in Python 3. Using ** (Power Operator) The ** mathematical operator (known as the power operator) will calculate an exponent, raising the number on the left to the power of the number on the right of the operator: 4**5 # Will evaluate 4*4*4*4*4 and return the integer value 1024 Note that: You will receive a ZeroDivisionError if you try to raise 0 (zero) … Read more

How to Use ‘for’ Loops in Python, With Examples

Python for Loops

This article will show you how to use for loops in Python 3 and provide examples. Loops are one of the fundamentals of programming. So you’ll use them almost constantly. Data in computer software is often stored in arrays (or lists), for example, a record of students enrolled in a course, with each item in a list representing a student. These arrays of data need to be processed – and this is done using loops that step through each item in the array and perform some … Read more

Python lstrip and rstrip Methods – With Examples

Python lstrip and rstrip Methods

This short tutorial will show you how to use lstrip and rstrip to remove whitespace (or any other characters) from the beginning/end of strings in Python. The lstrip and rstrip methods are available on any string type variable in Python 3. Python lstrip String Method The lstrip (Left strip) method will remove leading characters from the string – that is, characters starting from the left of the string. Syntax Here’s the syntax for the lstrip method: string.lstrip(characters) Note that: string can be any string value or variable with a string value characters is an optional parameter for the lstrip method These are the characters that … Read more

How to use the Python zip() Function, With Examples

Python zip

This tutorial will explain how to use the python zip() function to merge or aggregate several iterables (including lists and tuples). First up, the Python zip() function has NOTHING to do with compressing files. It’s got nothing to do with making a .zip file. It’s a totally different thing. So if that’s what you’re looking for, this isn’t it! What are Iterables? In the Python programming language, iterables are data types that can be iterated over item by item. It includes variables called lists, tuples, sets, and dictionaries … Read more

How to Generate Random Numbers and Strings in Python

Python Generate Random Strings Numbers

This article will outline several methods for generating random numbers and strings in the Python programming language. Generating random values is a common and important task when programming almost any kind of application of moderate complexity. Random strings and numbers are used to generate unique identifiers (e.g., for the short URLs in URL shortening services), for identifying unique records in a database, and (most importantly) are frequently used to determine the behavior of gameplay elements in video games (for example, simulating a coin flip, or … Read more

Python: Calculating a Number’s Root (Square/sqrt, Cube), With Examples

Python Calculate Square Root

This article will show you how to calculate the square root, or any root, of numbers in the Python programming language. We previously covered squaring and raising numbers to a power in this article. What is a Root in Mathematics? The root of a number x is the number that must be multiplied by itself a given number of times to equal the number x. For example, the second root of 16 is 4 as 4*4 = 16. It is the second root because 4 must be multiplied by itself twice to reach the required result of 16. The third root of 64 is 4 as 4*4*4 = … Read more

Best Way to Check if a File/Directory is Writable [Python]

Python - Check if File/Directory Writable

This quick tip will show you the best way to check if a file or directory is writable in the Python programming language. Python: The Best Way To Check if a File or Directory is Writable Just try and write to it. That’s it. If you can write to the file, it must be writable Try and write to it, and handle any failure which occurs. try: with open(‘newfile.txt’, ‘w’) as file file.write(‘hello!’) file.close() except IOError as error: # You could also catch Exception instead of IOError to … Read more