<FreeKB>
Home
About
Walkthroughs
Linux Commands
Sign In
FreeKB - Python (Scripting) articles
Python (Scripting) articles
Arrays
Getting Started with Arrays
Append values to the end of an array
Blank out an array
Combine or merge arrays
Convert array to string
Convert sting to array
Count the elements in an array
Remove duplicate values from an array
base64
Base64 encoding and decoding
Classes
Calling classes from another Python script
Getting Starting with Classes
Command line options
Command line options flags arguments
Commands
Configure the "python" command to invoke the "python3" command
python --version command
Date and Time
date and time
def (function)
Getting Started with functions
Calling functions from another Python script
Pass values into a function
Return value in a function
email
Send an email
exit
Stop Halt or Exit
Files and Directories
Create Write or Append to a file (open)
Determine if a file or directory exists
mkdir
Read a file (open)
FTP
Connect to an FTP Server
Hashes
Getting Started with Hashes
hash has_key
hostname
hostname (socket)
if elif else statement
if elif else statements
Install
Install pycharm on Linux
Install Python on Linux CentOS
JSON
Determine if JSON key contains a value
Determine if JSON key contains an empty array
Determine if JSON key exists
Loop through JSON array
Parse dictionary using json.dumps
Parse dictionary using json.loads
Parse JSON file using json.load
Parse JSON using json.tool
Log
Logging to a log file
Loops
Break out of a loop
Loop over a dictionary
Looping over a sequence of integers using range
Looping over a variable using split or splitlines
Looping over an array
match
Find matching expression using find
Find matching expression using re.match
Math
Addition and Increment (+)
Division (/)
Subtraction and Decrement
Modules
Creating your own modules
import module
sys.path
Native operating system commands
Native operating system commands
os
Users Home Directory
os.access
Determine if an file or directory is readable writable (os.access)
os.path
Determine if an object is a file or directory (os.path.isfile isdir)
dirname basename and present working directory (pwd)
Return and print script name
whoami
Printing output
Printing text to the console (print)
Replace
Escape backslash
Replace and re.sub
REST API (curl)
GET request
PATCH request
POST request
Sleep
Pause using Sleep
SSH
SSH using paramiko
strip
Remove whitespace using strip, lstrip and rstrip
Troubleshooting
Resolve "AttributeError: 'dict' object has no attribute 'loads'"
Resolve "TypeError: cannot concatenate 'str' and 'bool' objects"
Resolve "TypeError: cannot concatenate 'str' and 'list' objects"
Resolve "TypeError: string indices must be integers"
try except else
try except else finally
Upper Lower Case
Upper Lower Case using upper lower
Variables
Append to a variable
Defining variables
Version
python --version command
Virtual Environment
Activate a virtual environment
Create a virtual environment (venv virtualenv)
Installing packages in a virtual environment