FreeKB - Python (Scripting) articles
Python (Scripting) articles

ArraysGetting Started with ArraysAppend values to the end of an arrayBlank out an arrayCombine or merge arraysConvert array to stringConvert sting to arrayCount the elements in an arrayRemove duplicate values from an arraybase64Base64 encoding and decodingClassesCalling classes from another Python scriptGetting Starting with ClassesCommand line optionsCommand line options flags argumentsCommandsConfigure the "python" command to invoke the "python3" commandpython --version commandDate and Timedate and timedef (function)Getting Started with functionsCalling functions from another Python scriptPass values into a functionReturn value in a functionemailSend an emailexitStop Halt or ExitFiles and DirectoriesCreate Write or Append to a file (open)Determine if a file or directory existsmkdirRead a file (open)FTPConnect to an FTP ServerHashesGetting Started with Hasheshash has_keyhostnamehostname (socket)if elif else statementif elif else statementsInstallInstall pycharm on LinuxInstall Python on Linux CentOSJSONDetermine if JSON key contains a valueDetermine if JSON key contains an empty arrayDetermine if JSON key existsLoop through JSON arrayParse dictionary using json.dumpsParse dictionary using json.loadsParse JSON file using json.loadParse JSON using json.toolLogLogging to a log fileLoopsBreak out of a loopLoop over a dictionaryLooping over a sequence of integers using rangeLooping over a variable using split or splitlinesLooping over an arraymatchFind matching expression using findFind matching expression using re.matchMathAddition and Increment (+)Division (/)Subtraction and DecrementModulesCreating your own modulesimport modulesys.pathNative operating system commandsNative operating system commandsosUsers Home Directoryos.accessDetermine if an file or directory is readable writable (os.access)os.pathDetermine if an object is a file or directory (os.path.isfile isdir)dirname basename and present working directory (pwd)Return and print script namewhoamiPrinting outputPrinting text to the console (print)ReplaceEscape backslashReplace and re.subREST API (curl)GET requestPATCH requestPOST requestSleepPause using SleepSSHSSH using paramikostripRemove whitespace using strip, lstrip and rstripTroubleshootingResolve "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 elsetry except else finallyUpper Lower CaseUpper Lower Case using upper lowerVariablesAppend to a variableDefining variablesVersionpython --version commandVirtual EnvironmentActivate a virtual environmentCreate a virtual environment (venv virtualenv)Installing packages in a virtual environment