📌 置頂: 請把任何比你弱勢的用路人當作你的至親對待。跟前車保持安全車距 (2秒以上)。

bpo-29901: Improve support of path-like objects in zipapp 分析

In

Tags:



by

bpo-29901 簡介

新知

  • os.PathLike: https://docs.python.org/3/library/os.html#os.PathLike
  • path-like object: https://docs.python.org/3.7/glossary.html#term-path-like-object
  • Lib/zipapp (from version 3.5): https://docs.python.org/3/library/zipapp.html
  • Lib/pathlib (from version 3.4): https://docs.python.org/3/library/pathlib.html

技巧

isinstance 的 classinfo 可以傳入 tuple

from Python 3.6 docs:

isinstance(object, classinfo)
Return true if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof. If object is not an object of the given type, the function always returns false. If classinfo is a tuple of type objects (or recursively, other such tuples), return true if object is an instance of any of the types. If classinfo is not a type or tuple of types and such tuples, a TypeError exception is raised.

ZipFile itself converts the archive name to POSIX format. But I think it is better to do this explicity. Maybe implicit conversion will be deprecated in future.

 


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.