Scientific Programming with Python
Create your first package
1. Create the following files and directories
|
|
2. Add the following to setup.py
|
|
3. Now, from the top level micro
directory, install the package using pip
:
$pip install -e .
4. Try to import the micro package from Python:
In [1]: import micro
5. You should always also have a README.md
and LICENSE.md
:
LICENSE.md
: Explains if/how this software may be used by others. See for examples
https://choosealicense.com/ or https://opensource.guide/legal/.README.md
: Explains what this sofware does, how to install/use it, etc.,
6. Finally, upload to GitHub
- init a git for
micro
in your own computer. - create a new repository in your GitHub and upload the whole
micro
into it. - running the following code to install
micro
package from the GitHub:pip install git+https://github.com/username/micro
Python-testing
Function description
so we could see the description when type help(strflip)
|
|
assert(strflip(‘ab’) == ‘ba’)
assert(strflip(‘mario’) == ‘oiram’)
from strflip import strflip
assert(strflip(‘’) == ‘’)
def test_empty_string():
assert(strflip(‘’) == ‘’)
```
if we want to see the output from these test functions, we could:
pytest -s
Performance
using %timeit
or %prun
in IPYTHON to see the performance of a function.