1
0
mirror of https://github.com/gsi-upm/sitc synced 2024-11-05 07:31:41 +00:00
sitc/python/1__10_Modules_Packages.ipynb

143 lines
3.3 KiB
Plaintext
Raw Normal View History

2016-02-01 12:05:58 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](http://www.upm.es/sfs/Rectorado/Gabinete%20del%20Rector/Logos/UPM/EscPolitecnica/EscUpmPolit_p.gif \"UPM\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Course Notes for Learning Intelligent Systems"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-02-15 08:01:37 +00:00
"Department of Telematic Engineering Systems, Universidad Politécnica de Madrid, © 2016 Carlos A. Iglesias"
2016-02-01 12:05:58 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Modules and Packages\n",
"\n",
"*Modules* contains definitions and objects that can be reused in other programmes.\n",
"\n",
"*Packages* contain subpackages of modules. They are directories and provide the namespace for modules.\n",
"\n",
"For example, let's have this package sound, a subpackage effects and the modules echo and surround:\n",
"\n",
"<code>\n",
"babel/\n",
" messages/\n",
" \\_\\_init\\_\\_.py\n",
" plurals.py\n",
" catalog.py\n",
"</code>\n",
"\n"
]
},
{
"cell_type": "code",
2016-02-15 08:01:37 +00:00
"execution_count": null,
2016-02-01 12:05:58 +00:00
"metadata": {
"collapsed": false
},
2016-02-15 08:01:37 +00:00
"outputs": [],
2016-02-01 12:05:58 +00:00
"source": [
"# We can import the module plural with import, but we should use the full name\n",
"import babel.messages.plurals\n",
"plurals.get_plural()"
]
},
{
"cell_type": "code",
2016-02-15 08:01:37 +00:00
"execution_count": null,
2016-02-01 12:05:58 +00:00
"metadata": {
"collapsed": false
},
2016-02-15 08:01:37 +00:00
"outputs": [],
2016-02-01 12:05:58 +00:00
"source": [
"import babel.messages.plurals\n",
"babel.messages.plurals.get_plural()"
]
},
{
"cell_type": "code",
2016-02-15 08:01:37 +00:00
"execution_count": null,
2016-02-01 12:05:58 +00:00
"metadata": {
"collapsed": false
},
2016-02-15 08:01:37 +00:00
"outputs": [],
2016-02-01 12:05:58 +00:00
"source": [
"from babel.messages import plurals # with from-import, we can use the short name\n",
"plurals.get_plural()"
]
},
{
"cell_type": "code",
2016-02-15 08:01:37 +00:00
"execution_count": null,
2016-02-01 12:05:58 +00:00
"metadata": {
"collapsed": false
},
2016-02-15 08:01:37 +00:00
"outputs": [],
2016-02-01 12:05:58 +00:00
"source": [
"from babel.messages.plurals import get_plural # now we can use directly get_plural()\n",
"get_plural()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To write a module, it is just needed to include the code in a file ended with \".py\" and the name of the file is the name of the module.\n",
"\n",
"Packages are directories that should have a file \\_\\_.init\\_\\_.py, that can be an empty file or contain initialization code."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Licence"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The notebook is freely licensed under under the [Creative Commons Attribution Share-Alike license](https://creativecommons.org/licenses/by/2.0/). \n",
"\n",
2016-02-15 08:01:37 +00:00
"© 2016 Carlos A. Iglesias, Universidad Politécnica de Madrid."
2016-02-01 12:05:58 +00:00
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}