xiexiaoy / iTalk

Just record something here
0 stars 0 forks source link

Python Issue #12

Open xiexiaoy opened 7 years ago

xiexiaoy commented 7 years ago

如何找到模块路径

import _socket
_socket.__file__
xiexiaoy commented 6 years ago

奇怪,Tornado没有暴露_handler_connection()方法

xiexiaoy commented 6 years ago

Python线程调度的时机

  1. 指令数用完
  2. 陷入阻塞
xiexiaoy commented 6 years ago

我还纳闷Tornado为什么没有提供on_connection()方法, 原来,它提供了closed()方法。

xiexiaoy commented 6 years ago

Tornado one loop per thread

Tornado Ioloop in thread

Tornado multiple IOLoop in multithreads

xiexiaoy commented 6 years ago

从使用的角度看, coroutine跟threading的用法必须相似。 所以,需要有coroutine的创建销毁、coroutine的同步、coroutine间的通信。

xiexiaoy commented 6 years ago

bytes对象,不可变对象 bytearray对象,可变对象

The difference between bytearray and bytes in Python

xiexiaoy commented 6 years ago

Python 函数内部的静态变量

What is the Python equivalent of static variables inside a function?

xiexiaoy commented 6 years ago

找个sorteddict SortedContainers

xiexiaoy commented 6 years ago

socket.recv()返回什么,以及如何检查对方关闭连接?

当对方关闭连接的时候,socket.recv()返回空字符串而不是返回None。因此

data = sock.recv(bufsize)
if data:
    ...
else:
    handle_close()

而不是

data = sock.recv(bufsize)
if data is not None:
    ...
else:
    handle_close()

注意if something is not Noneif something不等价。

When does socket.recv(recv_size) return? Most elegant way to check if the string is empty in Python?

xiexiaoy commented 6 years ago

ConnectionResetError: [Errno 104] Connection reset by peer

try:
    ...
except OSError:
    ...

捕获OSError竟然漏掉了ConnectionResetError

socket exceptions exceptions OSError

xiexiaoy commented 6 years ago

python -m http.server

what-is-the-python-3-equivalent-of-python-m-simplehttpserver

xiexiaoy commented 6 years ago

善用列表展开式 print(*list)

xiexiaoy commented 6 years ago

Shuffling a list of objects

xiexiaoy commented 6 years ago

How can I convert a Python dictionary to a list of tuples?

xiexiaoy commented 6 years ago

Python remove all whitespace in a string

xiexiaoy commented 6 years ago

What's the difference between eval, exec, and compile in Python?

xiexiaoy commented 6 years ago

In practice, what are the main uses for the new “yield from” syntax in Python 3.3?