# --------------------Most Useful #1-------------------------------
# Better Example Function Would be Like a WMI Query and List Results
# Pass a Computer Name and then the Function Gathers the Information
def computer(Name):
import wmi
# Replace with your remote computer's details
computer_name = Name
# Connect to the remote computer's WMI
c = wmi.WMI(computer=Name)
print('\n',"------------ WMI Class OS Information ---------")
for os in c.Win32_OperatingSystem():
print(f"Caption: {os.Caption}")
print(f"Version: {os.Version}")
print(f"BuildNumber: {os.BuildNumber}")
print(f"BuildNumber: {os.Manufacturer}")
#--- Call Function
computer('LocalHost')
# Define a function with a default parameter
def my_function(dog='ScoobyDoo'):
# Construct a message about the dog
my_dog_var = dog + ' is a great dog to have.'
print('\nDoggie Function:', my_dog_var)
# Call the function with the default value
my_function()
# Call the function with a specific argument
my_function(dog='Scrappy')
#---Basic Function Call with Math Operators---
# --- Variable
Scotty=10
def my_secfunction(Scott):
global Scotty
Scotty+=Scott
#---Call Function
my_secfunction(55)
#---Print Results
print('\n',"sec Fucntion:",Scotty)
Functions
#---Variable ---
x = 20
#---def (definition) declares a function---
def my_function():
global x #---Define as Global Variable
x+=25
#---Call the Function
my_function()
print(x)
# ---------------Most Useful #2----------------------------
#---Calculations and Passing Values to Function---
def math_routine(x,y,z):
return(x+y)**z
#---Call Function
calculated_var=math_routine(2,4,6)
print('\nCalculated Value',calculated_var)
# ---------------- Most Useful #3 ---------------------------
# Importing a module from another directory
# Add the path to the directory containing the module
import sys
sys.path.append('C:/PYTHON/modules')
# Import the custom math module
import math_module
# Call the function from the module and pass values
calc_var = math_module.addition(2, 2, 2)
# Print the results
print('\nFrom Module:', calc_var)