赞
踩
'''字符串格式化输出'''
'%.3f'%(10.1111111111)
'{:.3f}'.format(10.3333333333)
'''浮点数四舍五入'''
>>> a = 0.123456789
>>> for i in range(9):
... round(a, i)
import hashlib
res = hashlib.sha256()
i = 0
with open('pycharm-community-2021.1.1.exe', 'rb') as f:
for line in f:
print(line)
res.update(line)
i+=1
print(res.hexdigest())
print(i)
source = input('原始编码:')
print(str(res.hexdigest()) == source)
3.1,
3.2,十进制转为固定长度的二进制
‘{:032b}’.format()
python -i 脚本
https://www.cnblogs.com/dcpeng/p/12251291.html (python virtualenv)
https://www.cnblogs.com/dcpeng/p/12257331.html (pycharm,创建直接用pycharm也可以)
如果你加了参数: --no-site-packages出现了错误virtualenv: error: unrecognized arguments: --no-site-packages,那可以去掉了。因为virtualenv早就默认这个参数了
virtualenv ~
或者使用 --system-site-packages,但会将真实环境所有的库都复制过来
virtualenv --system-site-packages ~
https://www.cnblogs.com/Eva-J/p/8330517.html
如果要在cmd中显示颜色,需要加上
from colorama import init
init(autoreset=True)
from distutils.core import setupfromCython.Buildimport cythonizesetup(ext_modules = cythonize(["zmister.py"]))
pip install pyarmor
pyarmor obfuscate foo.py #使用obfuscate选项对代码进行加密
pyarmor licenses \--expired "2018-12-31" \--bind-disk "100304PBN2081SF3NJ5T" \--bind-mac "70:f1:a1:23:f0:94" \--bind-ipv4 "202.10.2.52" \ r001 #使用licenses 选项生成许可文件
pyarmor obfuscate --with-license licenses/r001/license.lic foo.py #使用--with-license参数指定许可文件
pyarmor pack foo.py #使用pack选项打包脚本
https://mp.weixin.qq.com/s/qsLoVIB1tC8cVRMp2jmSUw
>>>class A(object):
... bar = 1
...
>>> a = A()
>>> getattr(a, 'bar') # 获取属性 bar 值
1
>>> getattr(a, 'bar2') # 属性 bar2 不存在,触发异常
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute 'bar2'
>>> getattr(a, 'bar2', 3) # 属性 bar2 不存在,但设置了默认值
3
>>>
'''方法1'''
>>> a = 1
>>> getattr(sys.modules['__main__'], 'a')
1
'''方法2'''
>>> globals()['a']
1
>>> globals()['cccc']=1
>>> cccc
1
https://blog.csdn.net/leemboy/article/details/83792729
Cython入门教程 : https://www.jianshu.com/p/cfcc2c04a6f5
用Cython加速Python到“起飞”:https://www.jb51.net/article/166720.htm
Python/C API Reference Manual: https://docs.python.org/3/c-api/index.html
# For CUDA 8.0 pip install cupy-cuda80 # For CUDA 9.0 pip install cupy-cuda90 # For CUDA 9.1 pip install cupy-cuda91 # For CUDA 9.2 pip install cupy-cuda92 # For CUDA 10.0 pip install cupy-cuda100 # For CUDA 10.1 pip install cupy-cuda101 # Install CuPy from source pip install cupy
https://www.programcreek.com/python/
将***\python以及***\python\Scripts配置到环境变量中
https://blog.csdn.net/weixin_42151880/article/details/108084264
pycharm中也可以设置
'''方法1'''
def get_key(value):
for k,v in dict.items():
if value == v:
return k
'''方法2:反转字典'''
new_dict = {v:k for k,v in dict.items()}
sorted中的key函数返回元组,会先按照元组第一个元素排序;如果第一个元素相同,按照元组第二个元素排序。
a = [[2,3],[4,1],(2,8),(2,1),(3,4)]
b = sorted(a,key=lambda x: (x[0], -x[1]))
print b
musicBase = {'a': 5, 'b': 4, 'c': -2, 'd': -1, 'e': -1, 'f': 4}
musicSorted = sorted(musicBase.items(), key=lambda x: (x[1], -ord(x[0][-1])), reverse=True)
笔记1-python3中sort函数key如何对两个参数做对比
笔记2-装饰器模板
笔记3-递归
笔记4-抽象类
笔记5-新式类广度优先多继承的继承顺序
笔记6-网络编程
笔记7-类的装饰器(property, classmethod, staticmethod)
笔记8-多进程
笔记9-多线程
笔记10-协程
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。