2020年5月19日
Details refer to offical document
Virtual environment To create new virtual environment usually in folder venv
python -m venv yourfoldername enter virtual environment source venv/bin/activate exit virtual environment deactivate Pip usage install package pip install packagename list installed packages pip list save installed packages to requirements.txt pip freeze > requirements.txt install packages from requirements.txt pip install -r requirements.txt ……
阅读全文
2020年5月19日
Sequelize data model 在使用 bulkCreate的时候,如果想在返回的数据中包括生成的id, 需要加上option, { returning: true } return CertificationEndUsers.bulkCreate(usersToInsert, { returning: true }); 另外 postgresql中table name包含双引号和不包含的,竟然是不一样的两个table "users" users 比如这是两个table……
阅读全文
2020年5月16日
函数 #!/usr/bin/env python3 # -*- coding: utf-8 -*- # def func, snake case # return value # no args, no return def add_two_number(): print('a') # 1 arg def add_two_number_1(x): return x + 5 # return value # return multiple value def two_number_2(x, y): c = x + y d = x - y return c, d # args def add_number(x, y, *args): print(f'x = {x}') print(f'y = {y}') print(f'args = {args} ') # kwargs # def add_number_1(x, y, *args, **kwargs): print(f'x = {x}') print(f'y = {y}') # f-string f'this is string, {x}' print(f'args = {args} ') print(f'kwargs = {kwargs} ') # wrong # def add_number_2(**kwargs, *args, x, y) # pass # default def add_number_3(x, y, c=10, d = True): print(c) if __name__ == '__main__': # add_two_number() # print(add_two_number_1(6)) # print(two_number_2(10, 5)) # add_number(1,2, 3, 4, 5, 6) # add_number_1(1,2,3,4,5,……
阅读全文
2020年5月16日
条件控制 #!/usr/bin/env python3 # -*- coding: utf-8 -*- if __name__ == '__main__': a = 5 if a > 0: print('a > 0') else: print('a < 0') if a > 0: pass elif a < 5: pass elif a < 10: pass else: pass if a > 0: if a < 5: print(a) else: print('a > 5') 循环控制 #!/usr/bin/env python3 # -*- coding: utf-8 -*- if __name__ == '__main__': # while condition a = 5 while a > 0: # print(a) a = a -1 # for in for i in range(10): print(i) # break the loop print('------------------') for i in range(10): print(i) else: # print('done') # continue the loop print('------------------') for i in range(10): if i == 5: continue print(i) count = 0 while count < 5: print (count, " 小于 5") count……
阅读全文
2020年5月14日
如果启动angular的时候有报 Javascript heap out of memory错误,可以试着修改 node_modules/.bin/ng 加上 --max_old_space_size #!/usr/bin/env node --max_old_space_size=4096 'use strict';……
阅读全文
2020年5月12日
问题提出 golang最近导出csv的时候,如果用excel打开,会有乱码。在网上查到了解决方案,记录一下。 解决方案 f, err := os.Create("data.csv") if err != nil { panic(err) } defer f.Close() f.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM,避免使用Microsoft Excel打开乱码 writer := csv.NewWriter(f) writer.Write([]string{"col 1", "col 2", "col 3"}) writer.Flush()……
阅读全文
2020年5月11日
背景 在做文字检测和文字识别的时候,有时候客户提供的是pdf格式的文件,而不是jpg/png格式,这时候就需要把pdf里面多个页面 保存成图片。 代码库pdf2image 实现 Python 参考readme docker 参考readme golang 参考readme 也可以 直接下载可执行文件直接执行 -> https://github.com/jerrywang1981/pdf2images/blob/master/pdf2image……
阅读全文
2020年5月4日
背景 有时候,我们在python中实现了一个功能,这功能如果用golang重新写呢,会比较麻烦,如果要在golang中调用python中的功能。 方式有很多,主要就是两个程序如果沟通的问题,那方式就各种各样了,可以通过http协议,json/xml等格式,或者tcp, 当然还有个 选择就……
阅读全文
2020年5月2日
对象中通过类或者实例的方法调用方式的不同 如果通过类中取得的方法,需要传入实例 class A(object): def test(self, *args): print(*args) if __name__ == '__main__': a = A() a.test(7, 8, 9) # method from class object m1 = A.test m1(a, 7, 8, 9, 10) # method from instance object m2 = a.test m2(7, 8, 9, 10) 也就是说, 实例方法的第一个参数是实例本身,如果写decorator的时候,要特别注意 比如print_args这个decor……
阅读全文
2020年5月2日
推荐一下自己做的一个docker image, 基于ubuntu,包含 neovim python python 3 nodejs npm golang Plugin 包括 LeaderF coc.nvim other……
阅读全文