Skip to content

Conversation

rsokl
Copy link
Owner

@rsokl rsokl commented Jul 3, 2018

@davidmascharka finally done with this. Ugh. Torturous.

@rsokl rsokl requested a review from davidmascharka July 3, 2018 18:35
Copy link
Collaborator

@davidmascharka davidmascharka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this must have been brutal to write. Looks good! Just a few changes recommended below.

"\n",
"Despite our regular use of the `import` statement, we have thus far swept its details under the rug. Here, we will finally pay our due diligence and discuss Python's import system, which entails understanding the way that code can be organized into modules and packages. Modules are individual `.py` files from which we can import functions and objects, and packages are collections of such modules. Detailing this packaging system will not only provide us with insight into the organization of the standard library and other collections of Python code, but it will permit us to create our own packages of code.\n",
"\n",
"To conclude this section, we will demonstrate the process of installing a Python package to your system; supposing that you have written your own Python package, installing it enables you to import it anywhere on your system. A brief overview will be provided of the two most popular venues for hosting Python packages to the world at large: the Python Package Index (PyPI) and Anaconda.org.\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to your system" should be "on your system"

to -> on

"source": [
"## Modules\n",
"\n",
"A Python module refers to a single `.py` file that contains function definitions and variable-assignment statements. Importing a module will execute these statements, rendering the resulting objects available via the imported module. \n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put module in quote marks?

A Python 'module' refers to...

"\n",
"A Python module refers to a single `.py` file that contains function definitions and variable-assignment statements. Importing a module will execute these statements, rendering the resulting objects available via the imported module. \n",
"\n",
"Let's create our own module and import it into an interactive Python session. Open a Jupyter notebook or IPython console in a known directory on your computer. Now, with an [IDE](http://www.pythonlikeyoumeanit.com/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.html#Integrated-Development-Environments) or simple text editor (not software like Microsoft Word!) create text file named `my_module.py` in the same directory as you Python session. The contents of `my_module.py` should be:\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"create a text file"

the return of Caveman Ryan

"purpose of your module.\n",
"\"\"\"\n",
"\n",
"print(\"I am being executed!\")\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

horrific!

(really hope Sanjeev still reads these 🤣)

">>> import my_module\n",
"I am being executed!\n",
"\n",
"# produced is a object that is an instance of the module-type\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds awkward...but I don't have a better alternative right now

Trying to think of what I would say about #includeing something...

"\n",
"### PYTHONPATH and Site-Packages\n",
"\n",
"Thus far in our reading of Python packages we have had to take care that all of the modules and packages that we have written reside in the same directory as our interactive Python session. How is it that we are able to import NumPy in any session or module, without any knowledge of where that package is located? This is because we have installed NumPy, which means that the package has been placed in our \"Python path\", which is indicated as PYTHONPATH.\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would italicize "installed" here:

"This is because we have installed NumPy, which..."

"\n",
"Thus far in our reading of Python packages we have had to take care that all of the modules and packages that we have written reside in the same directory as our interactive Python session. How is it that we are able to import NumPy in any session or module, without any knowledge of where that package is located? This is because we have installed NumPy, which means that the package has been placed in our \"Python path\", which is indicated as PYTHONPATH.\n",
"\n",
"The PYTHONPATH specifies the directories that the Python interpreter will look to when importing modules. You can check your PYTHONPATH in `sys.path`:\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"will look in" instead, maybe

"\n",
"Thus far in our reading of Python packages we have had to take care that all of the modules and packages that we have written reside in the same directory as our interactive Python session. How is it that we are able to import NumPy in any session or module, without any knowledge of where that package is located? This is because we have installed NumPy, which means that the package has been placed in our \"Python path\", which is indicated as PYTHONPATH.\n",
"\n",
"The PYTHONPATH specifies the directories that the Python interpreter will look to when importing modules. You can check your PYTHONPATH in `sys.path`:\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can check your PYTHONPATH using sys.path

"source": [
"If you read through the additional materials linked above, you will see that there are many more fields of optional information that can be provided in this setup script, such as the author name, any installation requirements that the package has, and more.\n",
"\n",
"Armed with this script, we are ready to install our package locally on our machine! In you terminal, navigate to the directory containing this setup script and your package that it being installed. Run\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your terminal

"\n",
"Both managers will install packages to your site-packages directory.\n",
"\n",
"There are substantial benefits for using `conda` rather than to install packages. First and foremost, `conda` has a powerful \"environment solver\", which tracks the inter-dependencies of Python packages. Thus it will attempt to install, upgrade, and downgrade packages as needed to accommodate your installations. Additionally, the default list of packages available via `conda` are curated and maintained by Continuum Analytics, the creators of Anaconda. To elucidate one of the benefits of this, installing NumPy via `pip` will deliver the vanilla version of NumPy to you, `conda` will install an [mkl-optimized version of NumPy](https://software.intel.com/en-us/articles/numpyscipy-with-intel-mkl), which can execute routines substantially faster. Finally, `conda` also serves as [an environment manager](https://conda.io/docs/user-guide/tasks/manage-environments.html), which allows you to maintain multiple, non-conflicting environments that can house different configurations of installed Python packages and even different versions of Python itself.\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...advantages to using conda rather than pip to install packages."

"...installing NumPy via pip will deliver the vanilla version of NumPy to you**;** conda will install..." <-- semicolon

I'll keep my thoughts on conda to myself...

@rsokl rsokl merged commit 3b0dfab into master Jul 4, 2018
@rsokl rsokl deleted the py_package branch July 4, 2018 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants