Jun
Jun
> Python中的字典是使用哈希表[Hash table](https://zh.wikipedia.org/wiki/%E5%93%88%E5%B8%8C%E8%A1%A8)来实现的。 # 0x00 字典的存储方式 Python3.6中的字典对象`PyDictObject`定义在`Include/dictobject.h`: ```c typedef struct _dictkeysobject PyDictKeysObject; typedef struct { PyObject_HEAD /* Number of items in the dictionary */ Py_ssize_t ma_used; /* Dictionary version: globally...
> Python中类型也是个对象 # 0x00 类型对象的类型 在Python中,类型对象的类型是`type`, ```python >>> type(int) >>> type(str) >>> type(list) >>> type(dict) >>> type(type) ``` ``就是`PyType_Type`,类型对象的类型也是对象(`PyTypeObject`),定义在`Objects/typeobject.c`: ```c PyTypeObject PyType_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "type", /* tp_name */...
# 0x00 列表的存储方式 Python中的列表对象对应着`Include/listobject.h`的`PyListObject`: ```c typedef struct { PyObject_VAR_HEAD /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */ PyObject **ob_item; /* ob_item contains space for 'allocated' elements....
交换两个变量的值,大家最常见的写法是这样的: ``` python >>> temp = x >>> x = y >>> y = temp ``` 但其实更 Pythonic 的写法是这样的: ``` python >>> x, y = y, x ``` 大家有没有想过为什么在 Python...
Linux 下的工作都是依靠进程来执行的,控制了进程就相当于控制了 Linux 系统了。这篇博客将通过 Linux 系统的启动登录来探讨进程管理机制,看这种机制如何支撑和左右进程的命运。 ### 什么是进程 先来了解了解什么是进程,程序这个词比较好理解,通常的程序是静态实体,进程是正在运行的程序实体,并且包括这个运行的程序中占据的所有系统资源,比如说CPU(寄存器),IO,内存,网络资源等。进程描述符(PID)是唯一用来标识进程的。 ### 进程的创建 #### fork 和 exec 分别是进程的分身和变身 在运行级别3下启动 Linux,出现命令行界面需要在“login: ”提示符处输入用户名登录,可以另外找一台机子ssh远程连接,查看一下`mingetty`进程的执行情况: ``` # ps -ef|grep mingett[y] root 14450 1 0 14:10 tty1...
 If you are looking to add and remove duplicate input fields, here’s another jQuery example below to do the task for you. This jQuery snippet adds duplicate input fields...
A frequent need when writing a web service is to convert internal representation of resources to and from JSON, which is the transport format used in HTTP requests and responses....
问题如下: ``` error: unknow filesystem grub rescue> ``` rescue 模式下命令集:`set`,`ls`,`insmod`,`root`,`prefix` - set 查看或设置环境变量,这里可以查看和设置启动路径和分区。 - ls 查看设备或文件 - insmod 加载模块 - root 指定用于启动系统的分区,在 rescue 模式下设置 grub 启动分区 - prefix 指定 grub...
问题来自下面这段代码 https://github.com/thesharp/daemonize/blob/master/daemonize.py#L103 ``` python try: process_id = os.fork() except OSError as e: self.logger.error("Unable to fork, errno: {0}".format(e.errno)) sys.exit(1) if process_id != 0: # This is the parent process. Exit without...
问题来源于这样一组数据 ``` python lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] ``` 需要合并列表中的列表,通常来说,最常见的写法是列表推导式 ``` python [item for l in lists for item in l]...