Skip to content

Commit

Permalink
use of alias added to Chapter 8
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdkwast committed Jun 3, 2021
1 parent ff6c5bf commit 28dde6c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions PythonIntroCh8.ipynb
Expand Up @@ -46,7 +46,7 @@
" def printdetails(self):\n",
" print(\"This piano is a/an \" + self.height + \" foot\", end=\" \")\n",
" print(self.type, \"piano, \" + self.age, \"years old and costing\\\n",
" \" + self.price + \" dollars.\")\n",
" \" + self.price + \" dollars.\")\n",
"```\n",
"\n",
"As you see, a module looks pretty much like your normal Python program.\n",
Expand Down Expand Up @@ -112,6 +112,19 @@
"\n",
"This way, you can remove some crypticness, AND have all of the items from a certain module.\n",
"\n",
"A final handy way to import modules is with an alias. Maybe you want to change a name because you've already used the same name for something else in your program, another module you imported uses the same name, or maybe you want to abbreviate a longer name that you use a lot. We can then use the `as` operator. That looks like this:\n",
"\n",
"```Python\n",
"### IMPORT A MODULE WITH AN ALIAS\n",
"# import module\n",
"import moduletest as mt\n",
"\n",
"# use module\n",
"print(mt.age)\n",
"cfcpiano = mt.Piano()\n",
"cfcpiano.printdetails()\n",
"```\n",
"\n",
"## 8.4 Conclusion\n",
"That's it! A very simple lesson, but now you can organise your programs very neatly. In fact, now it is incredibly easy to make programs that can grow in complexity without ending up with one cryptic file that is full of bugs.\n",
"Modules are great for importing code. Next lesson, we learn about file input and output, and the saving of information inside classes, to be retrieved later. Will be great!"
Expand Down Expand Up @@ -141,7 +154,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.6.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 28dde6c

Please sign in to comment.