Sep-22-2022, 10:46 PM
(This post was last modified: Sep-23-2022, 03:54 PM by isaac_python.)
Hello,
I'm trying to get my output from Amazon Workspaces to print to a file. I can get the data from workspaces, but I have not been able to write the data to the CSV file. I have been looking around the web, and all the answers I can find are the simplest possible answers, and only print the code from within Python itself. I can find no real-world examples that adequately address my problem. Any assistance is appreciated, Thank you.
This is my code:
import boto3
client = boto3.client('workspaces')
folder = input('directoryId> ')
workspaces = client.describe_workspaces()['Workspaces']
directoryIds = [workspaces['DirectoryId']for workspaces in workspaces]
directoryIds.sort()
for DirectoryIds in folder:
print(workspaces)
##----------------CSV Writer Code----------------##
import csv
with open('workspacesdata.csv', 'w', newline='') as csvfile:
datawriter = csv.writer(csvfile,dialect='excel')
fieldnames=['WorkspaceId', 'DirectoryId', 'UserName', 'IpAddress','State', 'BundleId', 'SubnetId','ComputerName','VolumeEncryptionKey' , 'WorkspaceProperties','RunningMode']
datawriter = csv.DictWriter(csvfile, fieldnames=fieldnames)
datawriter.writeheader()
##----------------CSV Reader Code----------------##
import os
os.system('start excel.exe workspacesdata.csv')
I'm trying to get my output from Amazon Workspaces to print to a file. I can get the data from workspaces, but I have not been able to write the data to the CSV file. I have been looking around the web, and all the answers I can find are the simplest possible answers, and only print the code from within Python itself. I can find no real-world examples that adequately address my problem. Any assistance is appreciated, Thank you.
This is my code:
import boto3
client = boto3.client('workspaces')
folder = input('directoryId> ')
workspaces = client.describe_workspaces()['Workspaces']
directoryIds = [workspaces['DirectoryId']for workspaces in workspaces]
directoryIds.sort()
for DirectoryIds in folder:
print(workspaces)
##----------------CSV Writer Code----------------##
import csv
with open('workspacesdata.csv', 'w', newline='') as csvfile:
datawriter = csv.writer(csvfile,dialect='excel')
fieldnames=['WorkspaceId', 'DirectoryId', 'UserName', 'IpAddress','State', 'BundleId', 'SubnetId','ComputerName','VolumeEncryptionKey' , 'WorkspaceProperties','RunningMode']
datawriter = csv.DictWriter(csvfile, fieldnames=fieldnames)
datawriter.writeheader()
##----------------CSV Reader Code----------------##
import os
os.system('start excel.exe workspacesdata.csv')