生而为人

程序员的自我修养

0%

List

底层实现是单向链表,所以慎用通过index的遍历方式,因为每次都要从头节点开始查。IndexedSeq可以使用

1
2
3
for (i until nums.lenght) {
println(nums(i))
}

如果需要遍历List,又同时需要获取到index,可以改用迭代或zipWithIndex

1
2
3
4
5
6
7
// 迭代


// zipWithIndex
for ((value, index) <- nums.zipWithIndex) {
...
}

IndexedSeq 的实现主要包括:

Array

[toc]

库

安装库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
pip install requests
pip install spotipy

# 🇨🇳 中国用户必看:解决下载慢/超时报错(换国内镜像源)
# 临时使用一次(推荐,最简单)
pip install 库名 -i https://pypi.tuna.tsinghua.edu.cn/simple

# 如果不想每次都加 -i,可以永久设置(一行命令搞定)
# 设置后,以后直接输入 pip install 库名 就会自动走国内源,网速飞起
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple
腾讯云:https://mirrors.cloud.tencent.com/pypi/simple

# 查看pip配置列表
pip config list

批量安装

1
pip install -r requirements.txt

requirements.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
requests==2.31.0
numpy==1.26.0
pysimplegui==4.60.5.1
spotipy==2.25.2
pylast==5.3.0
musicbrainzngs==0.7.1
python-dotenv==1.0.1
pandas==2.2.3
# 安装 pandas-stubs 后,PyCharm 就能像查字典一样,在你写 df. 或 pd. 时,精准地给出 pandas 特有的方法补全和参数提示,让编码效率和准确性大大提升。
pandas-stubs==2.2.3
mutagen==1.47.0
tqdm==4.66.5

# excel
openpyxl==3.1.5

# 压缩
# pyzipper 是 Python 标准库 zipfile 的增强版,最大的特点是支持 AES 加密的 ZIP 文件
pyzipper==0.4.0
# 支持多种压缩算法(如 LZMA2, BZip2, Deflate 等)和加密方法(如 7zAES),并提供命令行工具,方便直接操作 7z 文件
py7zr==0.21.0
# 支持 RAR3 和 RAR5 格式的归档文件,以及多卷归档和密码保护
rarfile==4.2

# 提供在 CPU 或 GPU 上运行的张量(Tensor)计算,并支持自动微分,用于构建和训练神经网络
torch==2.4.0

# 第三方库
# 这是一个网易云音乐的第三方库
git+https://github.com/zixing131/pyncm.git

查看安装结果

1
pip show python-dotenv

版本问题

win7环境

  1. python <= 3.8
  2. pycharm <= 2019.3

pycharm内置的pip版本过低,会导致安装时出现尝试从源码编译依赖包的问题

而且自带的pip 19.0.3 有一个已知问题,它会阻止你通过常规命令升级 pip 本身

所以需要通过以下命令升级pip,再来安装依赖

1
2
3
4
5
# 强制把 pip 升级到最新版
easy_install -U pip

# 更新其他构建工具
python -m pip install --upgrade setuptools wheel

升级完 pip 后,如果安装其他包时再次遇到“Installing build dependencies”卡住或报错,记得用 --no-build-isolation 参数,让 pip 直接使用你刚刚升级好的 setuptools,而不是再去临时下载构建依赖。

当输出在sleep之后时,无法打印

怀疑原因是因为线程被挂起,无法继续执行,但为什么每个线程都无法被唤醒?需要看下唤醒逻辑

1
2
Thread.sleep(2000);
System.out.println("orderInfo:" + orderInfo);

502错误

有可能是因为有人在进行远程调试

空指针可能情况

基本类型的值为null

(exclude = DataSourceAutoConfiguration.class)

DynamicDataSourceAutoConfiguration

自动化配置的问题

需要排除的配置

[Spring Boot 排除自动配置的 4 种方法,关键时刻很有用!]

  1. @SpringBootApplication
  2. @EnableAutoConfiguration
  3. @SpringCloudApplication
  4. spring.autoconfigure.exclude

Spring Boot自动化配置的利弊及解决之道

排除的类总结
  1. @SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)

注解用法

@RequestBody和@RequestParam注解使用

@Async

  1. 可以指定线程池

不生效原因:

  1. 需要保证调用函数与注解修饰的函数在不同类中,因为不会走代理类。详解 详解2

@Value

注入static变量四种方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import lombok.Getter;

@Component
public class GlobalValue {

@Getter
public static String DATABASE;

@Value("${mysql.db:test}")
public void setDatabase(String db) {
DATABASE = db;
}
// 这里要特别注意:
// 1. @value需要注释set函数上
// 2. 自动生成的getter和setter方法,会带有static的限定符,需要去掉,才可以。
}

@Value
static
https://blog.csdn.net/ZYC88888/article/details/87863038

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘pubApiPush’: Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder ‘group_url’ in value “${group_url}”

group_url: [[查看结果|http://wolf.waimai.dev.sankuai.com/group/hubble/page/dolphinManage]]