Hi guy's im new to python so please excuse the ignorance pretty well 99% of my coding is powershell/DSC and then more falls to DevOps for IAC terraform, ARM/bicep, yaml and json... just hoping someone can point me to proper documentation or just give me some helpful advice
My current issue is as im so used to powershell being able to reference or store an item from array or just depict it from ingress or egress with the inline $_. or $.name
Is there a way i can do it easily with python the same way for variables and parts of array$s = {bob,12,north,frank}$s.[1] <12>
here is a quick example - not a great one as its a service but gives what im getting at....# Get a specific service - in this case, the "Windows Update" service$service = Get-Service -Name wuauserv# Display basic information about the service using dot notationWrite-Host "Service Name: $($service.Name)"Write-Host "Display Name: $($service.DisplayName)"Write-Host "Status: $($service.Status)"Write-Host "Start Type: $($service.StartType)"Write-Host "Dependent Services: $($service.DependentServices.Count)"# Check if the service is stopped and start it if it isif ($service.Status -eq 'Stopped') { Write-Host "Service is stopped. Attempting to start..." # Start the service using a method $service.Start() # Refresh service status $service.Refresh() Write-Host "New Status: $($service.Status)"}**verse python utilising powershell util**import psutilimport subprocessdef get_service(name): # Get the list of all services and find the specified one for service in psutil.win_service_iter(): if service.name() == name: return service return Nonedef start_service(name): # Start the service using subprocess subprocess.run(['sc', 'start', name], capture_output=True)def stop_service(name): # Stop the service using subprocess subprocess.run(['sc', 'stop', name], capture_output=True)# Main codeservice_name = 'wuauserv'service = get_service(service_name)if service: print(f"Service Name: {service.name()}") print(f"Display Name: {service.display_name()}") print(f"Status: {service.status()}") print(f"Description: {service.description()}")**Second python dot notation example**import os# Define the directory you want to exploredirectory = os.getcwd() # Gets the current working directory# List all files and directories in the specified directoryentries = os.listdir(directory)print(f"Entries in {directory}:")for entry in entries: # Create full path full_path = os.path.join(directory, entry) # Check if it's a file or directory if os.path.isfile(full_path): # Get size using os.path.getsize size = os.path.getsize(full_path) print(f"File: {entry}, Size: {size} bytes") elif os.path.isdir(full_path): print(f"Directory: {entry}")