@@ -519,6 +519,8 @@ msgid ""
519519" types have their own free list; these free lists would have to be moved to "
520520"the interpreter state. And so on."
521521msgstr ""
522+ "也有建议说 GIL "
523+ "应该是解释器状态锁,而不是完全的全局锁;解释器不应该共享对象。不幸的是,这也不可能发生。由于目前许多对象的实现都有全局的状态,因此这是一个艰巨的工作。举例来说,小整型数和短字符串会缓存起来,这些缓存将不得不移动到解释器状态中。其他对象类型都有自己的自由变量列表,这些自由变量列表也必须移动到解释器状态中。等等。"
522524
523525#: ../../faq/library.rst:452
524526msgid ""
@@ -527,20 +529,21 @@ msgid ""
527529"extensions are being written at a faster rate than you can convert them to "
528530"store all their global state in the interpreter state."
529531msgstr ""
532+ "我甚至怀疑这些工作是否可能在优先的时间内完成,因为同样的问题在第三方拓展中也会存在。第三方拓展编写的速度可比你将它们转换为把全局状态存入解释器状态中的速度快得多。"
530533
531534#: ../../faq/library.rst:457
532535msgid ""
533536"And finally, once you have multiple interpreters not sharing any state, what"
534537" have you gained over running each interpreter in a separate process?"
535- msgstr ""
538+ msgstr "最后,假设多个解释器不共享任何状态,那么这样做比每个进程一个解释器好在哪里呢? "
536539
537540#: ../../faq/library.rst:462
538541msgid "Input and Output"
539- msgstr ""
542+ msgstr "输入输出 "
540543
541544#: ../../faq/library.rst:465
542545msgid "How do I delete a file? (And other file questions...)"
543- msgstr ""
546+ msgstr "怎样删除文件?(以及其他文件相关的问题……) "
544547
545548#: ../../faq/library.rst:467
546549msgid ""
@@ -549,6 +552,8 @@ msgid ""
549552":func:`~os.unlink` is simply the name of the Unix system call for this "
550553"function."
551554msgstr ""
555+ "使用 ``os.remove(filename)`` 或 ``os.unlink(filename)``。查看 :mod:`os` "
556+ "模块以获取更多文档。这两个函数是一样的,:func:`~os.unlink` 是这个函数在 Unix 系统调用中的名字。"
552557
553558#: ../../faq/library.rst:471
554559msgid ""
@@ -558,10 +563,13 @@ msgid ""
558563"directories as long as they're empty; if you want to delete an entire "
559564"directory tree and its contents, use :func:`shutil.rmtree`."
560565msgstr ""
566+ "如果要删除目录,应该使用 :func:`os.rmdir`;使用 :func:`os.mkdir` 创建目录。``os.makedirs(path)``"
567+ " 会创建 ``path`` 中任何不存在的目录。``os.removedirs(path)`` "
568+ "则会删除其中的目录,只要它们都是空的;如果你想删除整个目录以及其中的内容,可以使用 :func:`shutil.rmtree`。"
561569
562570#: ../../faq/library.rst:477
563571msgid "To rename a file, use ``os.rename(old_path, new_path)``."
564- msgstr ""
572+ msgstr "重命名文件可以使用 ``os.rename(old_path, new_path)``。 "
565573
566574#: ../../faq/library.rst:479
567575msgid ""
@@ -570,53 +578,63 @@ msgid ""
570578"There's also ``os.ftruncate(fd, offset)`` for files opened with "
571579":func:`os.open`, where *fd* is the file descriptor (a small integer)."
572580msgstr ""
581+ "如果需要截断文件,使用 ``f = open(filename, \" rb+\" )`` 打开文件,然后使用 "
582+ "``f.truncate(offset)``;offset 默认是当前的搜索位置。也可以对使用 :func:`os.open` 打开的文件使用 "
583+ "``os.ftruncate(fd, offset)``,其中 *fd* 是文件描述符(一个小的整型数)。"
573584
574585#: ../../faq/library.rst:484
575586msgid ""
576587"The :mod:`shutil` module also contains a number of functions to work on "
577588"files including :func:`~shutil.copyfile`, :func:`~shutil.copytree`, and "
578589":func:`~shutil.rmtree`."
579590msgstr ""
591+ ":mod:`shutil` 模块也包含了一些处理文件的函数,包括 "
592+ ":func:`~shutil.copyfile`,:func:`~shutil.copytree` 和 :func:`~shutil.rmtree`。"
580593
581594#: ../../faq/library.rst:490
582595msgid "How do I copy a file?"
583- msgstr ""
596+ msgstr "怎样复制文件? "
584597
585598#: ../../faq/library.rst:492
586599msgid ""
587600"The :mod:`shutil` module contains a :func:`~shutil.copyfile` function. Note"
588601" that on MacOS 9 it doesn't copy the resource fork and Finder info."
589602msgstr ""
603+ ":mod:`shutil` 模块有一个 :func:`~shutil.copyfile` 函数。注意在 MacOS 9 中不会复制 resource "
604+ "fork 和 Finder info。"
590605
591606#: ../../faq/library.rst:497
592607msgid "How do I read (or write) binary data?"
593- msgstr ""
608+ msgstr "怎样读取(或写入)二进制数据? "
594609
595610#: ../../faq/library.rst:499
596611msgid ""
597612"To read or write complex binary data formats, it's best to use the "
598613":mod:`struct` module. It allows you to take a string containing binary data"
599614" (usually numbers) and convert it to Python objects; and vice versa."
600615msgstr ""
616+ "要读写复杂的二进制数据格式,最好使用 :mod:`struct` 模块。该模块可以读取包含二进制数据(通常是数字)的字符串并转换为 Python "
617+ "对象,反之亦然。"
601618
602619#: ../../faq/library.rst:503
603620msgid ""
604621"For example, the following code reads two 2-byte integers and one 4-byte "
605622"integer in big-endian format from a file::"
606- msgstr ""
623+ msgstr "举例来说,下面的代码会从文件中以大端序格式读取一个 2 字节的整型和一个 4 字节的整型: "
607624
608625#: ../../faq/library.rst:512
609626msgid ""
610627"The '>' in the format string forces big-endian data; the letter 'h' reads "
611628"one \" short integer\" (2 bytes), and 'l' reads one \" long integer\" (4 "
612629"bytes) from the string."
613630msgstr ""
631+ "格式字符串中的 ‘>’ 强制以大端序读取数据;字母 ‘h’ 从字符串中读取一个“短整型”(2 字节),字母 ‘l’ 读取一个“长整型”(4 字节)。"
614632
615633#: ../../faq/library.rst:516
616634msgid ""
617635"For data that is more regular (e.g. a homogeneous list of ints or floats), "
618636"you can also use the :mod:`array` module."
619- msgstr ""
637+ msgstr "对于更常规的数据(例如整型或浮点类型的列表),你也可以使用 :mod:`array` 模块。 "
620638
621639#: ../../faq/library.rst:521
622640msgid ""
@@ -625,10 +643,13 @@ msgid ""
625643"instead (the default), the file will be open in text mode and ``f.read()`` "
626644"will return :class:`str` objects rather than :class:`bytes` objects."
627645msgstr ""
646+ "要读写二进制数据的话,需要强制以二进制模式打开文件(这里为 :func:`open` 函数传入 ``\" rb\" ``)。如果(默认)传入 "
647+ "``\" r\" `` 的话,文件会以文本模式打开,``f.read()`` 会返回 :class:`str` 对象,而不是 :class:`bytes` "
648+ "对象。"
628649
629650#: ../../faq/library.rst:529
630651msgid "I can't seem to use os.read() on a pipe created with os.popen(); why?"
631- msgstr ""
652+ msgstr "似乎 os.popen() 创建的管道不能使用 os.read(),这是为什么? "
632653
633654#: ../../faq/library.rst:531
634655msgid ""
@@ -638,36 +659,39 @@ msgid ""
638659"function. Thus, to read *n* bytes from a pipe *p* created with "
639660":func:`os.popen`, you need to use ``p.read(n)``."
640661msgstr ""
662+ ":func:`os.read` 是一个底层函数,它接收的是文件描述符 —— 用小整型数表示的打开的文件。:func:`os.popen` "
663+ "创建的是一个高级文件对象,和内建的 :func:`open` 方法返回的类型一样。因此,如果要从 :func:`os.popen` 创建的管道 *p* "
664+ "中读取 *n* 个字节的话,你应该使用 ``p.read(n)``。"
641665
642666#: ../../faq/library.rst:618
643667msgid "How do I access the serial (RS232) port?"
644- msgstr ""
668+ msgstr "怎样访问(RS232)串口? "
645669
646670#: ../../faq/library.rst:620
647671msgid "For Win32, POSIX (Linux, BSD, etc.), Jython:"
648- msgstr ""
672+ msgstr "对于 Win32,POSIX(Linux,BSD 等),Jython: "
649673
650674#: ../../faq/library.rst:622
651675msgid "http://pyserial.sourceforge.net"
652- msgstr ""
676+ msgstr "http://pyserial.sourceforge.net "
653677
654678#: ../../faq/library.rst:624
655679msgid "For Unix, see a Usenet post by Mitch Chapman:"
656- msgstr ""
680+ msgstr "对于 Unix,查看 Mitch Chapman 发布的帖子: "
657681
658682#: ../../faq/library.rst:626
659683msgid "https://groups.google.com/[email protected] " 660- msgstr ""
684+ msgstr "https://groups.google.com/[email protected] " 661685
662686#: ../../faq/library.rst:630
663687msgid "Why doesn't closing sys.stdout (stdin, stderr) really close it?"
664- msgstr ""
688+ msgstr "为什么关闭 sys.stdout(stdin,stderr)并不会真正关掉它? "
665689
666690#: ../../faq/library.rst:632
667691msgid ""
668692"Python :term:`file objects <file object>` are a high-level layer of "
669693"abstraction on low-level C file descriptors."
670- msgstr ""
694+ msgstr "Python :term:`文件对象 <file object>` 是一个对底层 C 文件描述符的高层抽象。 "
671695
672696#: ../../faq/library.rst:635
673697msgid ""
@@ -677,6 +701,8 @@ msgid ""
677701"descriptor. This also happens automatically in ``f``'s destructor, when "
678702"``f`` becomes garbage."
679703msgstr ""
704+ "对于在 Python 中通过内建的 :func:`open` 函数创建的多数文件对象来说,``f.close()`` 从 Python "
705+ "的角度将其标记为已关闭,并且会关闭底层的 C 文件描述符。在 ``f`` 被垃圾回收的时候,析构函数中也会自动处理。"
680706
681707#: ../../faq/library.rst:641
682708msgid ""
0 commit comments