Skip to content

Commit

Permalink
Merge pull request #251 from kerwincsc/patch-1
Browse files Browse the repository at this point in the history
Update p09_add_directories_to_sys_path.rst
  • Loading branch information
yidao620c committed Dec 6, 2018
2 parents e83f233 + 0bc2bc7 commit be234d6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion source/c10/p09_add_directories_to_sys_path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
sys.path.insert(0, '/some/dir')
sys.path.insert(0, '/other/dir')
虽然这能“工作”,它是在实践中极为脆弱,应尽量避免使用。这种方法的问题是,它将目录名硬编码到了你的源代码。如果你的代码被移到一个新的位置,这会导致维护问题。更好的做法是在不修改源代码的情况下,将path配置到其他地方。如果您使用模块级的变量来精心构造一个适当的绝对路径,有时你可以解决硬编码目录的问题,比如__file__。举个例子:
虽然这能“工作”,但是在实践中极为脆弱,应尽量避免使用。这种方法的问题是,它将目录名硬编码到了你的源代码。如果你的代码被移到一个新的位置,这会导致维护问题。更好的做法是在不修改源代码的情况下,将path配置到其他地方。如果您使用模块级的变量来精心构造一个适当的绝对路径,有时你可以解决硬编码目录的问题,比如__file__。举个例子:
.. code-block:: python
Expand Down

0 comments on commit be234d6

Please sign in to comment.