with open(logfilename1, ‘a’) as logfile: uname = platform.uname() cpufreq =…
- User
with open(log_filename1, ‘a’) as log_file: uname = platform.uname() cpufreq = psutil.cpu_freq()
log_file.write(f’======= Computer ====== \nOS Name: {0} \n’.format(os_name)) log_file.write(‘OS Version: {0} \n’.format(os_version)) log_file.write(‘CPU: {0} \n’.format(proc_info.Name)) log_file.write(‘RAM: {0} GB \n’.format(system_ram)) log_file.write(‘Graphics Card: {0} \n’.format(gpu_info.Name))
log_file.write(‘======= System Information =======\n’) log_file.write(f"System: {uname.system}\n") log_file.write(f"Node Name: {uname.node}\n") log_file.write(f"Release: {uname.release}\n") log_file.write(f"Version: {uname.version}\n") log_file.write(f"Machine: {uname.machine}\n") log_file.write(f"Processor: {uname.processor}\n")
log_file.write(‘======= CPU Information =======\n’)
log_file.write(“Physical cores: \n”.format(psutil.cpu_count(logical=False))) log_file.write(“Total cores: \n”.format(psutil.cpu_count(logical=True))) log_file.write(f"Max Frequency: {cpufreq.max:.2f}Mhz \n") log_file.write(f"Min Frequency: {cpufreq.min:.2f}Mhz \n") log_file.write(f"Current Frequency: {cpufreq.current:.2f}Mhz \n") log_file.write(f"Total CPU Usage: {psutil.cpu_percent()}% \n")
в этом коде он выдает все верно кроме строчек: log_file.write(“Physical cores: \n”.format(psutil.cpu_count(logical=False))) log_file.write(“Total cores: \n”.format(psutil.cpu_count(logical=True))) log_file.write(f"Machine: {uname.machine}\n") log_file.write(f"Processor: {uname.processor}\n") исправь пажалуйста
- Assistant
Sure! Here's the corrected code:
import os import platform import psutil log_filename1 = "log_file.txt" with open(log_filename1, 'a') as log_file: uname = platform.uname() cpufreq = psutil.cpu_freq() log_file.write("======= Computer ======\n") log_file.write("OS Name: {}\n".format(os.name)) log_file.write("OS Version: {}\n".format(platform.version())) log_file.write("CPU: {}\n".format(platform.processor())) log_file.write("RAM: {} GB\n".format(psutil.virtual_memory().total / (1024**3))) log_file.write("Graphics Card: {}\n".format("Unknown")) # Replace "Unknown" with actual GPU info log_file.write("======= System Information =======\n") log_file.write("System: {}\n".format(uname.system)) log_file.write("Node Name: {}\n".format(uname.node)) log_file.write("Release: {}\n".format(uname.release)) log_file.write("Version: {}\n".format(uname.version)) log_file.write("Machine: {}\n".format(uname.machine)) log_file.write("Processor: {}\n".format(uname.processor)) log_file.write("======= CPU Information =======\n") log_file.write("Physical cores: {}\n".format(psutil.cpu_count(logical=False))) log_file.write("Total cores: {}\n".format(psutil.cpu_count(logical=True))) log_file.write("Max Frequency: {:.2f}Mhz\n".format(cpufreq.max)) log_file.write("Min Frequency: {:.2f}Mhz\n".format(cpufreq.min)) log_file.write("Current Frequency: {:.2f}Mhz\n".format(cpufreq.current)) log_file.write("Total CPU Usage: {}%\n".format(psutil.cpu_percent())) - User
как получить IP при запуске программы python
- Assistant
You can obtain the IP address of a device by using the
socketmodule in Python. Here's an example of how you can get the IP address when your Python program starts:import socket def get_ip_address(): hostname = socket.gethostname() ip_address = socket.gethostbyname(hostname) return ip_address # Get the IP address when the program starts ip_address = get_ip_address() print("IP Address:", ip_address)This code uses the
gethostname()function to get the hostname of the device and then uses thegethostbyname()function to obtain the corresponding IP address. Theget_ip_address()function returns the IP address, and you can store it in a variable or use it as needed within your program.Please note that this method will give you the IP address of the device on which the program is running. If you have multiple network interfaces or are behind a network address translation (NAT) router, the IP address obtained may not be the same as the external IP address visible from the internet.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.