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

news/2024/7/24 3:51:19 标签: python, java, 前端
python"># 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)


http://www.niftyadmin.cn/n/5279149.html

相关文章

【Mysql basic commands/query: how to update the message/record data of each row】

mysql common commands I) desc, insert and update I) desc, insert and update desc describe, insert into subject values(null,“Geometry Politics”, 99); mysql> select * from subject; ------------------------------------------------- | subject_id | subj…

vue获取图片的blob传给django后端

在Vue.js中,你可以通过组合使用JavaScript的fetch API来获取图片的Blob数据,并通过HTTP请求将其发送到Django后端。以下是一个基本的示例,这个过程通常分为两个步骤:首先是在Vue组件中获取Blob数据并发送到后端,其次是…

firewalld防火墙开启后无法启动docker的问题

1、错误场景和现象 linux开启或重启防火墙后,创建docker自定义网络时 docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 frayernet报错:[rootVM-16-5-centos home]# docker network create --driver bridge --su…

C# 设置文本框只能输入数字和小数点

private void input_weight_KeyPress(object sender, KeyPressEventArgs e) { //数字、小数点 if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar ! 8 && (int)e.KeyChar ! 46) e.Handled true; //…

protoc go 编译失败记录

报错问题&#xff1a; 原因&#xff1a; 是因为protobuf的安装出了问题&#xff0c;我是手动复制的protoc文件。因此没有include相关的文件。 它依赖的文件和go的模块依赖不是一个东西&#xff0c;是要在/usr/local/bin/protoc 的上一层的include下面的。也就是/usr/local/in…

什么是索引下推?

什么是索引下推 索引下推(Index Condition Pushdown&#xff0c;简称ICP)&#xff0c;是MySQL5.6版本的新特性&#xff0c;用于优化数据查询。 不使用索引条件下推优化时存储引擎通过索引检索到数据&#xff0c;然后返回给MySQL服务器&#xff0c;服务器然后判断数据是否符合条…

阻焊层,预计将以4.5%左右的复合年增长率增长

阻焊层&#xff0c;也称为阻焊剂&#xff0c;是施加在印刷电路板 (PCB) 上的保护层&#xff0c;用于保护铜迹线在焊接过程中免受氧化、污染和损坏。近年来&#xff0c;由于消费电子、汽车、航空航天和电信等各种应用对 PCB 的需求不断增加&#xff0c;阻焊层市场一直在显着增长…

Ubuntu 常用命令之 cal 命令用法介绍

&#x1f4d1;Linux/Ubuntu 常用命令归类整理 cal命令在Ubuntu系统下用于显示日历。它可以显示任何特定月份或整个年份的日历。 cal命令的参数如下 -1&#xff1a;只显示当前月份的日历。-3&#xff1a;显示前一个月、当前月和下一个月的日历。-s&#xff1a;指定日历的开始…