1
0
mirror of https://github.com/gsi-upm/sitc synced 2024-12-23 04:08:12 +00:00
sitc/python/1__10_Modules_Packages.ipynb

154 lines
3.7 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": [
2019-03-06 16:46:12 +00:00
"Department of Telematic Engineering Systems, Universidad Politécnica de Madrid, © 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",
2016-02-16 10:39:54 +00:00
"For example, let's have this package babel, a subpackage messages and the modules plurals and catalog:\n",
2016-02-01 12:05:58 +00:00
"\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,
2019-02-28 14:30:33 +00:00
"metadata": {},
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",
2020-02-13 17:10:08 +00:00
"plurals.get_plural()"
2016-02-01 12:05:58 +00:00
]
},
{
"cell_type": "code",
2016-02-15 08:01:37 +00:00
"execution_count": null,
2019-02-28 14:30:33 +00:00
"metadata": {},
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,
2019-02-28 14:30:33 +00:00
"metadata": {},
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,
2019-02-28 14:30:33 +00:00
"metadata": {},
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",
2016-02-16 10:39:54 +00:00
"Packages are directories that should have a file \\_\\_.init\\_\\_.py, that can be an empty file or contain initialization code.\n",
"\n",
"Read [this](https://packaging.python.org/en/latest/) if you want to distribute your modules"
2016-02-01 12:05:58 +00:00
]
},
{
"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",
2019-03-06 16:46:12 +00:00
"© 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",
2019-03-06 16:46:12 +00:00
"version": "3.7.1"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
2016-02-01 12:05:58 +00:00
}
},
"nbformat": 4,
2019-03-06 16:46:12 +00:00
"nbformat_minor": 1
2016-02-01 12:05:58 +00:00
}