用python实现一些功能

1、若两个.py文件同在一个文件夹下,则一个.py文件可以调用另一个.py文件中的函数:from .py文件名 import 函数名。
2、Python读取json文件中的数据
import json
with open("./config.json") as json_file:
config=json.load(json_file)
print(config[“max_depth”])
3、拼接路径:
from os.path import join
Join(“a”,”b”),无论a后面有没有/,都没关系,有则不加,没有自动加
4、创建文件夹,在当前路径下创建aa文件夹
from os import makedirs
makedirs("./aa")
5、程序运行时,接收命令行输入

2.py
a=input()
print(a)

python3 2.py 回车
输入3 回车
屏幕显示3 ,即输入的3被传给变量a

猜你喜欢

转载自blog.csdn.net/weixin_44594953/article/details/122913826