Reputation: 19
I am making a small program that gets basic information of your system this works and outputs the information in a console but I would like it so that the output creates a folder in the C drive and creates a txt file in that folder containing all the information.
When I run the program it creates the folder and txt file but contains "None"
def run_all_checks():
montior_cpu_times()
monitor_cpu_util()
monitor_cpu_cores()
monitor_cpu_freq()
monitor_RAM_Usage()
monitor_disk()
monitor_disk_usage()
monitor_network()
if not os.path.exists('C:\System Information Dump'):
os.makedirs('C:\System Information Dump')
save_path = 'C:\System Information Dump'
file_name = "System Info Dump.txt"
completeName = os.path.join(save_path, file_name)
print(completeName)
file1 = open(completeName, "a")
file1.write (str(run_all_checks()))
file1.close()
#def file1():
#return run_all_checks()
#info = file1()
#file = open("System Info Dump.txt","a")
#file.write(str(info))
#file.close()
#file1()
The commented code is just an example of what I have tried as well but didnt work.
Upvotes: 0
Views: 128
Reputation: 36
Your run_all_checks doesn't return anything. If you are not sure how long the function list is. You can keep a list of functions and iterate over it and return its value or even just directly write the value onto the file. Something like this:
def run_all_checks():
return "testing"
def montior_cpu_times():
return "FUNC 1"
def montior_cpu_util():
return "FUNC 2"
def runtest2():
return "FUNC3"
funcs = [montior_cpu_times(), montior_cpu_util(), runtest2(), run_all_checks()]
for func in funcs:
print(func)
Upvotes: 2
Reputation: 492
The problem is that run_all_checks()
doesn't return anything. So that's why the text file is empty.
For example, try:
def run_all_checks():
montior_cpu_times()
monitor_cpu_util()
monitor_cpu_cores()
monitor_cpu_freq()
monitor_RAM_Usage()
monitor_disk()
monitor_disk_usage()
monitor_network()
return "Checks ran successfully!"
Upvotes: 0