200526-python int list转String

在python中,可以直接通过','.join的方式来连接一个list,但是如果list中的元素不是string,会报错

1
2
3
4
5
6
>>> a = [1,2,3]
>>> ','.join(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected str instance, int found
>>>

针对非string元素的列表的转换时,可以考虑借助表达式语言来处理,如下

1
2
3
4
>>> a = [1,2,3]
>>> ','.join([str(x) for x in a])
'1,2,3'
>>>

190524-Python之pip导出与安装项目依赖包

使用pip进行python的包管理,记录下常见的两个,安装与导出项目依赖包

1
2
3
4
5
6
7
8
# 安装依赖
pip install pymysql

# 导出依赖
pip freeze 1> requirements.txt

# 安装项目所有依赖
pip install -r requirements.txt
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×

的hash值

1
2
3
4
>>> hash('hello world')
-2288959098694490958
>>> hash(123)
123
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×