加载中
python-正则特别例子

s='This$#is% Matrix# %!' print(s) # 把左右都被\w夹住的非\w替换为空格 # ?<=判断左边满足条件 # ?= 判断右边满足条件 print(re.sub(r'(?<=\w)([^\w]+)(?=\w)',' ',s)) #......

2023/04/22 09:49
70
python-读取多行输入

input: 4 3 2 1 2 1 2 1 2 1 2 3 4 3 4 3 4 #读取一个数组 n, m = map(int, input().split()) # taking number of rows and column array = numpy.array([input().strip().split() for _ in ...

2023/04/21 18:44
97
Python - Pandas导入csv

将CSV文件转换为dataframe 版本一 当做字符串导入为df 移除末尾两列 转换NaN为None方便导入数据库 def prepare_df(filepath): data = pd.read_csv (filepath, dtype=str) df_source = pd.Da...

2021/11/27 23:00
172
Python - 使用subprocess调用脚本

有套老系统,网站界面发起操作,调用服务器的脚本跑任务。 使用python重构,需要用到subprocess。subprocess.run是高阶函数,subprocess.popen是底层函数。 一般来说,脚本放在指定目录,需要...

2021/10/08 15:09
238
Flask - 环境变量和应用配置

dotenv可以从根据文件配置环境变量,然后flask再根据环境变量进行应用配置。 项目目录: ./ ├── Dockerfile ├── Pipfile ├── Pipfile.lock ├── README.md ├── app │ ├── ...

2021/09/16 17:33
629
Python - Flask设置CORS

使用flask-cors from flask_cors import CORS cors = CORS(app, resource={r"/api/.*": {"origins:":"*"}}) 注意点:api后面是点号加星号,不要只写一个星号。 另外,如果使用JSON作为前后端...

2021/09/16 15:41
281
Python - Flask 保存JSON数据到文件

用户数据格式: { "user":[ {"name":"allen","id":"001"}, {"name":"bond","id":"002"}, {"name":"cindy","id":"003"}, {"name":"donnie","id":"004"}, } Flask处理: import ast import js...

2021/09/02 16:26
1K
百度智能云 - 文字识别入门应用

起源 今天想把春节时折腾OCR引擎-Tesseract时产出的脚本整理一下,以便发布到网络方便大家参考。看了一下,觉得没什么必要,因为我自己都很难看懂了。跟住看到一些应用百度文字识别免费接口的...

Python技巧之拉姆达(Lambda)函数

Python中的‘lambda’关键字提供了一个便捷的途径去声明短小并匿名的函数。 # The lambda keyword in Python provides a # shortcut for declaring small and # anonymous functions: >>> ad...

2020/03/11 17:24
796
Python技巧之运行时访问类名和函数名

你可以在运行时获取字符对象名,技巧是使用下划线包裹的属性: # You can get the name of # an object's class as a # string: >>> class MyClass: pass >>> obj = MyClass() >>> obj.__cla...

2020/03/11 16:50
180
Python技巧之使用内置函数issubclass()获取类继承关系

你可以通过内置函数“issubclass()”检查类的继承关系: # You can check for class # inheritance relationships # with the "issubclass()" built-in: >>> class BaseClass: pass >>> class...

2020/03/11 16:45
168
Python技巧之使用统一码作为变量名

Python3允许使用unicode统一码作为变量名,但是只允许类字母的字符,不能使用emoji。 # Python 3 allows unicode # variable names: >>> π = math.pi >>> class Spin̈alTap: pass >>> Spi...

2020/03/11 16:41
350
Python技巧之超棒的内建函数:globals()和locals()

globals()返回一个字典,其包含当前上下文所有的全局变量。 locals()干的是一样的活,但返回的 # "globals()" returns a dict # with all global variables # in the current scope: >>> glo...

2020/03/11 16:10
146
Python技巧之循环体中的条件分支

Python的‘for’和‘while’循环支持‘else’分句,分句仅在循环体没有触发‘break’语句并终止时执行。 # Python's `for` and `while` loops # support an `else` clause that executes # ...

2020/03/09 18:23
130
Python技巧之检查列表所有元素是否相等

方法有三: 将列表构造为集合,再判断长度 用一个元素与所有元素比较 比较列表第一个元素的个数和列表长度 # Pythonic ways of checking if all # items in a list are equal: >>> lst = ['...

2020/03/09 18:09
2.7K

没有更多内容

加载失败,请刷新页面

返回顶部
顶部