- 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.
推薦閱讀
- Dynamics 365 Application Development
- Java Web基礎與實例教程(第2版·微課版)
- Django:Web Development with Python
- Mastering OpenCV 4
- Oracle Exadata專家手冊
- PySpark Cookbook
- 微信小程序全棧開發技術與實戰(微課版)
- C#開發案例精粹
- C專家編程
- TypeScript 2.x By Example
- Web編程基礎:HTML5、CSS3、JavaScript(第2版)
- Python物理建模初學者指南(第2版)
- Microsoft HoloLens By Example
- RESTful Web API Design with Node.js
- 絕密原型檔案:看看專業產品經理的原型是什么樣