Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
June 28, 2024
To save the Python screen output to a text file, you can redirect the standard output to a file. Here’s the modified version of your code with explanations.
This code will save the printed output to the specified text file (`output.txt`). You can change the `output_file_path` variable to your preferred file path.
import json import exec.fullog as e inp = e.getdata() # inp now is a dict() which has items, keys, and values. # Query output_file_path = 'output.txt' # Set the desired file path # Redirecting standard output to a file with open(output_file_path, 'w') as f: original_stdout = sys.stdout # Save a reference to the original standard output sys.stdout = f # Redirect standard output to the file print('Data collected on:', inp['header']['timestamp'].date()) print('\n CLASS 1 INFO\n') for item in inp['Demographics']: if item['name'] in ['Carly', 'Jane']: print(item['name'], 'Height:', item['ht'], 'Age:', item['years']) for item in inp['Activity']: if item['name'] in ['Cycle', 'Run', 'Swim']: print(item['name'], 'Athlete:', item['athl_name'], 'Age:', item['years']) sys.stdout = original_stdout # Reset standard output to the original value