1 numpy写入数据:
将numpy中的数组写入txt中:
numpy.savetxt("result.txt", numpy_data);
保存list数据
file=open('data.txt','w')
file.write(str(list_data));
file.close()
2 表示指数:
fs = 100e+5
3 类似三元操作符
4 获取执行文件的python文件的绝对目录
参考:
import os
cwd = os.path.dirname(os.path.realpath('__file__'))
cwd
输出
'C:\\Users\\ZJ\\aaa'
需要注意__file__可能需要加入‘’()
3 文件导入
python目录中的__init__.py文件详解_python在目录下创建init-CSDN博客https://blog.csdn.net/Victor2code/article/details/106361045
一个文件夹下有很多文件,则需要在这个文件夹下添加一个__init__.py文件,这主要是因为python不支持from folder import *
在python脚本被执行,python导入其他包或模块时,python会根据sys.path列表里的路径寻找这些包或模块。如果没找到的话,程序就会报错,所以可以在代码中加入
print(sys.path)
来判断当前模块的搜索路径,然后进行代码的调试
4 打成wheel包
pip install --upgrade build
python -m build
5
5 日志输出
root_logger = logging.getLogger()
for h in root_logger.handlers:
root_logger.removeHandler(h)
logging.basicConfig(format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s',
level=logging.DEBUG,
filename='/home/test.log',
filemode='w')
6 import相关
参考深度好文