Home » Programming

How to Import a CSV File to PostgreSQL

PostgreSQL Import CSV File

This tutorial will show you how to import data from a CSV file into a PostgreSQL database table. What is a CSV File A CSV (Comma Separated Values) file is a text file that contains tabulated information. The rows in this data each take up a line in the text file, while the values in each column on each row are separated by a comma – hence, comma-separated. CSV files are versatile. Because the data within is stored as plain text, they can be opened … Read more

Home » Programming

How to Export and Back Up PostgreSQL Databases

PostgreSQL Backup Import Export

This tutorial will show you how to export, import, and back up your PostgreSQL clusters and databases. You should regularly back up. It’s one of the most important things you can do as a sysadmin, developer, and even a hobbyist. Losing your data is detrimental to business, and your projects. Losing your family photos sucks too. This article demonstrates the various way to import and export PostgreSQL data so that it can be backed up. This process should be done regularly (or automated!), and performed … Read more

Home » Programming

Printing Text in Python Without a Newline

Python print without newline

This short tutorial will show you how to print text in Python, without a new line appearing. The Newline Character in Python In Python, newlines are represented by a \ (backslash) followed by n: \n You Can Add New Lines to Printed Strings The \n won’t be shown to the user – a new line will be inserted instead (unless an escape character is added). So, when the below code is executed: print(“Linux\nScrew”) It will appear as: Linux Screw Print Statements Add a Newline By Default By default, a newline … Read more

Home » Programming

How to Run an SQL File in MySQL (or MariaDB) on Linux/Ubuntu

How to Run a SQL File in MySQL/MariaDB on Linux/Ubuntu

Here is an article outlining several methods for running SQL files in MySQL on Linux/Ubuntu. Whether you’re installing a package, following a tutorial, or restoring a backup – it’s useful to be able to execute an SQL script from a file and have it do all of the work for you, rather than having to type it all out. Most GUI database managers have a simple import option prominently displayed in the menu bar – so here’s how to do it from the command line … Read more

Home » Programming

How to Read CSV Files in Python, With Examples

Python read from csv file

This article will show you how to read CSV (Comma Separated Values) files in the Python programming language, with examples. What is CSV (Comma Separated Values) CSV (Comma Separated Values) is a format for storing and transmitting data, usually in a text file, in which the individual values are separated by a comma (,). Each row in a CSV file represents an individual record containing multiple comma separated values. A CSV file looks like this: name,age,favourite colour Fred,54,green Mary,31,pink Steve,12,orange Above, the CSV describes three people, with information … Read more

Home » Programming

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 » Programming

JavaScript for Loops – How to Use Them [Examples]

How to use for loops in JavaScript

This article will show you how to use the simplest JavaScript loop – the for loop, and provide code examples. JavaScript for Loops JavaScript’s for loops are used to execute a block of code repeatedly until a condition is met. The initial variables, condition that must be met, and the expression which progresses the loop are all defined within the loop expression. for loop Syntax JavaScript for loops follow the following syntax: for (INITIALIZATION; CONDITION; FINAL_EXPRESSION) { //Code to be executed in the loop } Note that: INITIALIZATION sets the variable which is used to control … Read more

Home » Programming

How to Sort a Dictionary by Value in Python [Examples]

Python sort dictionary by value

This article will show you how to sort a dictionary by the values it contains in the Python programming language. Code examples are included. What is a Dictionary? A dictionary is one of Pythons built in variable types for storing data. Dictionaries are similar to associative arrays or hash tables in other languages. A dictionary contains a collection of values or objects. Unlike lists and arrays, rather than their values being stored at a specific index (the ordered position in the sequence of stored values), values in a dictionary … Read more

Home » Programming

How to Use Nested For Loops in JavaScript, with Examples

JavaScript nested for loops

This article will quickly explain nested for loops in JavaScript, how they are used with multidimensional arrays, and show some examples. For Loops We’ve already covered for loops – check out our article here. To sum up the article, for loops repeat a block of code for a given number of iterations: for (let i = 0; i <= 3; i++) { console.log(i); // Will output the numbers 0-3 to the console } Above, a for loop is defined that defines an initial variable i that is used to control the loop, sets a … Read more

Home » Programming

How to use the Python sum() Function to Add/Sum Numbers

Python sum

The Python sum() function takes a list of numbers, and sums them up (totals/adds them all together). Here’s how to use it, with examples. Summing/Totalling/Adding Numbers The concept of summing numbers is simple – take the numbers you wish to get the total of, and add them all together. 1 + 2 + 3 = 6 It’s basic arithmetic that you’ll use daily when writing computer software in any language. Summing Numbers in Python The sum() function in Python sums numbers. It’s a built-in function, which can be used anywhere … Read more