
python programming
programming with python
jasonxty
这个作者很懒,什么都没留下…
展开
-
flask怎么生成交互式API文档(swagger)
用 flask_restx https://flask-restx.readthedocs.io/en/latest/index.html原创 2020-06-10 16:36:21 · 1399 阅读 · 0 评论 -
python手写一个Enum
因为目标机器没有enum模块,无法import Enum。但是代码里面用到了开发机器上的Enum。没办法只能手写一个代替一下。# It mainly implements three enum features# 1. Return a enumhand class, has the key/enum class data: Task.DIEID# 2. The enumhand class instance has enum class data according key: Task('D原创 2021-12-26 14:29:32 · 438 阅读 · 0 评论 -
通过swig将C/C++代码暴露给python
入门http://www.swig.org/Doc3.0/Introduction.html#Introduction可以通过include头文件的方式去定义.i文件。这样大大方便了.i文件的书写。实验发现函数可以不用加extern。%module example原创 2021-05-08 13:41:34 · 755 阅读 · 0 评论 -
python的局部变量和全局变量
因为python中变量名是内存对象的引用,C/C++变量名就是内存对象。修改C/C++变量就相当于修改变量对应的内存对象。而修改Python变量就是将变量指向新的内存对象。所以局部、全局变量和C/C++中很不一样。在一个函数内,赋值全局变量前要用global声明它是一个全局变量。否则赋值操作就会新建一个同名的局部变量。当然直接引用赋值过的全局变量没有问题。...原创 2020-08-28 22:59:47 · 202 阅读 · 0 评论 -
python re.compile findall non-grouping
这个findall真是太难理解了。还好网上找到一些参考的资料,以下这个例子还是很不错的。原创 2020-07-28 15:10:20 · 162 阅读 · 0 评论 -
Python code browse
linux下面C语言browse,vim+cscope爽歪歪。python的话,用vscode就可以了。如果不是vscode的话,vim+ctags就可以了。先在你的代码目录里面运行命令“ctags -R”,然后光标移动到一个方法或者函数名称,再按‘ctrl+]’就可以跳转到它的定义。按‘Ctrl+O’就可以返回。...原创 2020-03-04 13:40:32 · 226 阅读 · 1 评论 -
二进制序列类型--bytes, bytearray, memoryview
操作二进制数据的核心内建数据类型是bytes和bytearray。它们由memoryview支持,memoryview使用buffer协议访问内存中其它的二进制对象,却不需要拷贝这些对象。...翻译 2020-03-01 11:08:51 · 3818 阅读 · 0 评论 -
PEP 257 -- Docstring 约定 (翻译)
PEP: 257 Title: Docstring Conventions Author: David Goodger, Guido van Rossum Discussions-To: doc-sig at python.org Status: Active Type: Informational Created: 29-May-...翻译 2020-01-22 15:32:27 · 1548 阅读 · 0 评论 -
VScode Remote-SSH The active editor cannot provide outline information
需要在server上面安装一个extension。原创 2020-01-15 13:43:19 · 3143 阅读 · 0 评论 -
隐藏jupyter notebook的ln
%%HTML<style>div.prompt {display:none}</style>原创 2019-12-17 10:23:18 · 524 阅读 · 0 评论 -
python flask socketio OpenSSL.SSL.Error
This is a problem of urllib3 (1.25).Workaround is to use older version of it:pip install -U "urllib3<1.25"[2019-10-15 10:54:13,137] ERROR in app: Exception on /jscode2session [GET]Traceb...原创 2019-10-15 18:55:40 · 1119 阅读 · 0 评论 -
Python中下划线的意义
Pattern Example Meaning Single Leading Underscore _var Naming convention indicating a name is meant for internal use. Generally not enforced by the Python interpreter (except in wildcard...原创 2019-08-16 14:36:34 · 198 阅读 · 0 评论 -
python 单引号、双引号,3个单引号3个双引号之间的区别
单引号和双引号在Python中我们都知道单引号和双引号都可以用来表示一个字符串,比如 str1 = 'python' str2 = "python"str1和str2是没有任何区别的。我们知道Python以其易用性而著名,所以刚开始看教程学习看到单引号和双引号都可以使用会以为这是Python为了方便程序员,随便用哪个就好,不用担心用错。其实,背后的原因不只是这么简单...转载 2019-05-18 19:26:21 · 776 阅读 · 0 评论 -
with statement
python中的with语句是用来干嘛的?有什么作用?with语句的作用是通过某种方式简化异常处理,也就是所谓的上下文管理器的一种,详情请看PEP-343 用法举例如下: with open('output.txt', 'w') as f: f.write('Hi there!')当你要成对执行两个相关的操作的时候,这样就很方便,以上便是经典例子,with语句会在嵌套的代码翻译 2016-07-26 16:58:35 · 1068 阅读 · 0 评论 -
Should we always favor xrange() over range()
python2.7 >>> print range.__doc__ range(stop) -> list of integers range(start, stop[, step]) -> list of integers Return a list containing an arithmetic progression of integers. range(i, j原创 2016-07-27 10:40:17 · 363 阅读 · 0 评论 -
用virtual environment让库管理变得简单
如果你想工作在多个python项目上,或者想要将项目和其使用的库捆绑在一起,或者你担忧安装的包可能会带来潜在的冲突,你可以通过安装virtual environment,从而使得不同的项目相互独立并且易于管理。当你并不是在虚拟环境下安装一个包,你实际上是全局的安装了这个包。这往往需要管理员身份或者用root身份安装,这时候这个包对于机子上每一个用户,每一个项目来说都是存在的,这在某些情况下可能就会带翻译 2016-07-28 16:59:03 · 565 阅读 · 0 评论 -
正则表达式
??????????????,???????,???????????????,?Ryan Mitchell?Web Scraping with Python, ?????????????????,????????,??????Regular Expressions????????????“??????,??????????????,??,?????????”(?????????????????)?翻译 2016-07-31 14:41:26 · 908 阅读 · 0 评论 -
C程序员一周入门python(一)
由于要开发一个爬虫,调查得知用python比较方便,所以学习一下如雷贯耳的Python参考文献: 《官方文档tutorial.pdf python3.5.4》 《Web Scraping with Python,Ryan Mitchell》背景: 有较好Linux C基础前三天阅读tutorial,并记录以下要点。Python相对C语言有以下特点: - 1、 提供了高效的上层数据结构原创 2017-07-18 16:47:56 · 537 阅读 · 0 评论 -
C程序员一周入门python(二)
本来想先看完书《Web Scraping with Python》再去实践的,后来偷懒,直接到github上找了一个高票项目。然后在分析部分(因为要满足一周的要求。。。)这个项目的基础上,结束python入门。原项目使用MIT许可证,我就放心大胆的用了。项目地址:https://github.com/nladuo/taobao_bra_crawler#!/usr/bin/env python#原创 2017-07-25 10:34:07 · 390 阅读 · 0 评论 -
python2 vs python3
转自https://learntocodewith.me/programming/python/python-2-vs-python-3/转载 2019-05-09 15:05:52 · 265 阅读 · 0 评论 -
python list 交集、并集、差集
#!/usr/bin/env python3# -*- coding: utf-8 -*-' a test module '__author__ = 'Zhang Shuai'a = [1,2,3,4]b = [3,4,5,6]'''求交集'''#方法1c = [i for i in a if i in b]#方法2c = list(set(a).intersecti...转载 2019-05-17 19:14:49 · 248 阅读 · 0 评论 -
python3中用for循环删除列表中元素的坑
转自https://blog.youkuaiyun.com/jimmy_gyn/article/details/79143682for循环语句的对象是可迭代对象,可迭代对象需要实现__iter__或iter方法,并返回一个迭代器,什么是迭代器呢?迭代器只需要实现 __next__或next方法。现在来验证一下列表为什么支持迭代:x = [1,2,3]its = iter(x)# its = x._...转载 2019-05-27 13:51:32 · 1720 阅读 · 0 评论 -
'import module' or 'from module import'
‘import module’和’from module import’,两者的区别其实是主观的。选择一种风格,并且在以后的编码过程中坚持使用它。以下是关于这两种方法的介绍。import module Pros 相对少的维护import语句,不需要再使用额外的imports来应用模块中的其它功能。Cons 每次都用module.foo这样的形式去引用某个功能会显得冗长和重复,冗长可以通过i翻译 2016-07-23 14:54:55 · 312 阅读 · 0 评论