python获取当前用户home目录和username

2023-12-22 10:40:57
# coding:utf-8

import getpass
import datetime
import os
user_name=getpass.getuser()
print(user_name)
# 获取当前用户的home目录
current_user_home=os.path.expanduser("~")
print("当前用户的home目录:"+current_user_home)

insert_data="hello-"+str(datetime.date.today())+user_name
print(insert_data)

whole_path=current_user_home+'/aaa.txt'
print(whole_path)
with open(whole_path, "w") as file:
    file.write(insert_data)

文章来源:https://blog.csdn.net/someInNeed/article/details/135146454
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。