官术网_书友最值得收藏!

  • The Python Apprentice
  • Robert Smallshire Austin Bingham
  • 140字
  • 2021-07-02 22:16:59

Importing modules into the REPL

Our module can also be imported into the REPL. Let's try that and see what happens. Start the REPL and import your module. When importing a module, you use import <module-name>, omitting the .py extension from the module name. In our case, it looks something like this:

$ python
Python 3.5.0 (default, Nov 3 2015, 13:17:02)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import words
It
was
the
best
of
times
. . .

The code in your module is executed immediately when imported! That's maybe not what you expected, and it's certainly not very useful. To give us more control over when our code is executed, and to allow it to be reused, we'll need to put our code in a function.

主站蜘蛛池模板: 西和县| 肇庆市| 六盘水市| 武鸣县| 冕宁县| 登封市| 迁安市| 霍山县| 靖边县| 绥滨县| 黄冈市| 灵川县| 清水县| 隆林| 无棣县| 若羌县| 台东市| 四子王旗| 凤城市| 商河县| 舟山市| 黄大仙区| 高雄县| 遵义县| 那曲县| 什邡市| 涪陵区| 清水县| 电白县| 临清市| 浮梁县| 丰城市| 宣城市| 杭锦旗| 竹北市| 宝丰县| 红安县| 东乌珠穆沁旗| 漠河县| 邻水| 鸡西市|