Skip to content

Commit 17d9539

Browse files
committed
Translate faq/design.html#why-doesn-t-python-have-a-with-statement-for-attribute-assignments
1 parent 86eecf1 commit 17d9539

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

faq/design.po

+28-2
Original file line numberDiff line numberDiff line change
@@ -1129,18 +1129,22 @@ msgstr ""
11291129

11301130
#: ../../faq/design.rst:653
11311131
msgid "Why doesn't Python have a \"with\" statement for attribute assignments?"
1132-
msgstr ""
1132+
msgstr "為何 Python 沒有屬性賦值的 with 陳述式?"
11331133

11341134
#: ../../faq/design.rst:655
11351135
msgid ""
11361136
"Python has a 'with' statement that wraps the execution of a block, calling "
11371137
"code on the entrance and exit from the block. Some languages have a "
11381138
"construct that looks like this::"
11391139
msgstr ""
1140+
"Python 的 with 陳述式包裝了一區塊程式的執行,在進入和離開該區塊時執行程式碼。"
1141+
"一些語言會有像如下的結構:\n"
1142+
"\n"
1143+
"::"
11401144

11411145
#: ../../faq/design.rst:663
11421146
msgid "In Python, such a construct would be ambiguous."
1143-
msgstr ""
1147+
msgstr "但在 Python,這種結構是模糊的。"
11441148

11451149
#: ../../faq/design.rst:665
11461150
msgid ""
@@ -1149,6 +1153,9 @@ msgid ""
11491153
"assigned to. This is the main point of static typing -- the compiler "
11501154
"*always* knows the scope of every variable at compile time."
11511155
msgstr ""
1156+
"在其他語言裡,像是 Object Pascal、Delphi 和 C++,使用的是靜態型別,所以我們可"
1157+
"以清楚地知道是哪一個成員被指派值。這是靜態型別的重點 — 在編譯的時候,編譯器永"
1158+
"遠都知道每個變數的範圍 (scope)。"
11521159

11531160
#: ../../faq/design.rst:670
11541161
msgid ""
@@ -1158,10 +1165,16 @@ msgid ""
11581165
"simple reading, what attribute is being referenced: a local one, a global "
11591166
"one, or a member attribute?"
11601167
msgstr ""
1168+
"Python 使用的是動態型別。所以我們不可能提前知道在執行時哪個屬性會被使用到。成"
1169+
"員屬性可能在執行時從物件中被新增或移除。這使得如果簡單來看的話,我們無法得知"
1170+
"以下哪個屬性會被使用:區域的、全域的、或是成員屬性?"
11611171

11621172
#: ../../faq/design.rst:676
11631173
msgid "For instance, take the following incomplete snippet::"
11641174
msgstr ""
1175+
"以下列不完整的程式碼為例:\n"
1176+
"\n"
1177+
"::"
11651178

11661179
#: ../../faq/design.rst:682
11671180
msgid ""
@@ -1171,24 +1184,37 @@ msgid ""
11711184
"variable named \"x\", will it be used inside the with block? As you see, "
11721185
"the dynamic nature of Python makes such choices much harder."
11731186
msgstr ""
1187+
"這段程式碼假設「a」有一個叫做「x」的成員屬性。然後,Python 裡並沒有任何跡象告"
1188+
"訴直譯器這件事。在假設「a」是一個整數的話,那會發生什麼事?如果有一個全域變數"
1189+
"稱為「x」,那在這個 with 區塊會被使用嗎?如你所見,Python 動態的天性使得這種"
1190+
"選擇更加困難。"
11741191

11751192
#: ../../faq/design.rst:688
11761193
msgid ""
11771194
"The primary benefit of \"with\" and similar language features (reduction of "
11781195
"code volume) can, however, easily be achieved in Python by assignment. "
11791196
"Instead of::"
11801197
msgstr ""
1198+
"然而,with 陳述式或類似的語言特性(減少程式碼量)的主要好處可以透過賦值來達"
1199+
"成,而非如下:\n"
1200+
"\n"
1201+
"::"
11811202

11821203
#: ../../faq/design.rst:695
11831204
msgid "write this::"
11841205
msgstr ""
1206+
"應該寫成這樣:\n"
1207+
"\n"
1208+
"::"
11851209

11861210
#: ../../faq/design.rst:702
11871211
msgid ""
11881212
"This also has the side-effect of increasing execution speed because name "
11891213
"bindings are resolved at run-time in Python, and the second version only "
11901214
"needs to perform the resolution once."
11911215
msgstr ""
1216+
"這也有提升執行速度的副作用,因為 Python 的名稱綁定解析會在執行的時候發生,而"
1217+
"第二版只需要執行解析一次即可。"
11921218

11931219
#: ../../faq/design.rst:708
11941220
msgid "Why don't generators support the with statement?"

0 commit comments

Comments
 (0)