Qile Liang's blog

归档 · 全部

首页

关于

归档

Write a singleton in python by import module

What is singleton?Singleton is a creational design pattern that lets you ensure that a class has only one instance, while providing a global access point to this instance. How to implement singleton using module?In python it is easy to implement singleton using module. Init a instance is all you need. class xxx: # implement your class # only one instance ..

更多

How to redirect output of print to log in python

How “print” work in python?In python print point to sys.stdout.write. In other words, when calling print, python will call sys.stdout.write(obj+’\n’) . Let me give an example to prof that. First I define a function named fun1 which write parameter to a file test.txt. Then make sys.stdout.write point to fun1. And try to print something. import sys def fun1..

更多

Can I call class variables without cls?

Can I call class attributes without cls in Python ?When we have a class variable but we find that we need call it in a non-class-method. Can we do operation like that? The answer is : Yes and no. Why the answer is yes?For any class attributes , we can use “self” to call them. After the first time we to do so, we will create an instance attributes implicitl..

更多

golang xxx is relative, but relative import paths are not supported in module mode

Golang package managementGo has its own package management system named “go modules”. It was introduced in Go 1.11as an official solution for golang’s package management. With go modules mode, we no longer need to place our code in $GOPATH directory. Go initIn golang modules mode, we cant import our package in our project directly ( like what we do in pyt..

更多
loading..

electron require is not defined

本篇文章是用于解决最新版本electron在浏览器侧文件如何引入nodejs下的包的问题。主要基于The ultimate Electron guide 编写。 Chromium 和 Node 如何交互?Electron 应用程序是一个npm项目,它包含electron框架作为依赖项。npm 项目的主要入口点是 Electron 应用程序的入口点,我们可以在其中选择性地包含我们想要的任何 Node API,以及创建并呈现UI的前端浏览器。 Chromium and ElectronChromium 从它的主进程开始。从主进程中,可以生成**渲染器进程(renderer)**。渲染器进程与[browser]窗口同义。主进程持有对渲染器进程的引用,并可以根据需要创建/删除渲染器进程。在大多数 Electro..

更多
loading..

coredns插件原理与corefile原理

什么是coredns?coredns是谷歌开发并开源的一款dns解析服务器。其使用golang开发,提供了插件跨平台等特性。 coredns插件注册插件coredns框架会在初始化时对插件进行注册,注册过后的插件可以被配置和调用。这里用 log 插件举例说明, 在 init() 内注册 log 的 setup 装载方法, 然后使用 AddPlugin 注册一个 plugin.Plugin 方法. 其目的就是要实现中间件那种调用链。其调用遵循一个调用链的倒叙。代码位置: plugin/log/setup.go // 注册 log 插件, 把 log 的 setup 装载方法注册进去. func init() { plugin.Register("log", setup) } func setup(c *..

更多