diff --git a/docs/_quarto.yml b/docs/_quarto.yml
index 6c6bd00..3536f9e 100644
--- a/docs/_quarto.yml
+++ b/docs/_quarto.yml
@@ -223,6 +223,11 @@ book:
- notes/python-modules/datetime.qmd
#- notes/python-modules/getpass.ipynb
+ - part: "The Programming Environment"
+ #href: notes/python-modules/index.qmd
+ chapters:
+ - notes/python-lang/file-operations.qmd
+
- part: "Custom Functions In-Depth"
chapters:
- notes/python-lang/control-flow/function-docs.qmd
@@ -249,7 +254,7 @@ book:
#body-footer: "© Copyright 2024, Your Name Here"
page-footer:
- center: "© Copyright 2024, Michael J Rossetti"
+ center: "© Copyright 2024 - 2025, Michael J Rossetti"
#bibliography: references.bib
diff --git a/docs/index.qmd b/docs/index.qmd
index 7f88fb3..2d22507 100644
--- a/docs/index.qmd
+++ b/docs/index.qmd
@@ -5,7 +5,7 @@
![](/images/python-banner.jpeg){fig-align="center" fig-alt="Intro to Software Development in Python (banner image)"}
-->
-Welcome to the \"Intro to Software Development in Python\" book (2024 edition, online)!
+Welcome to the \"Intro to Software Development in Python\" book (2024 edition, online)!
Whether you are a professional seeking to enhance technical skills, or a student aspiring to enter the field, this book should serve as a valuable resource.
@@ -13,3 +13,15 @@ Whether you are a professional seeking to enhance technical skills, or a student
The notes and exercises in this book are aimed to help you achieve a working knowledge of Python, and gain confidence in using Python to solve problems and create software applications.
We hope this book inspires you to harness the power of Python, helps you develop marketable technology skills, and opens up new avenues for innovation and efficiency in your work.
+
+
+
diff --git a/docs/notes/api-integrations/sending-email.qmd b/docs/notes/api-integrations/sending-email.qmd
new file mode 100644
index 0000000..e0be9ae
--- /dev/null
+++ b/docs/notes/api-integrations/sending-email.qmd
@@ -0,0 +1 @@
+# Sending Email in Python
diff --git a/docs/notes/dev-tools/google-colab/pip.ipynb b/docs/notes/dev-tools/google-colab/pip.ipynb
index 6863d1a..6cfc73f 100644
--- a/docs/notes/dev-tools/google-colab/pip.ipynb
+++ b/docs/notes/dev-tools/google-colab/pip.ipynb
@@ -1,435 +1,357 @@
{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "4HrdczX535YR"
- },
- "source": [
- "# Package Management with Pip\n",
- "\n",
- "As mentioned, Python has a rich ecosystem of third-party open source libraries called **packages**, that can provide us with super-charged capabilities to make our lives easier.\n",
- "\n",
- "If we want to use one of these packages, we must first install it. After installation, we can import its functionality and use it in our program.\n",
- "\n",
- "In Google Colab, many of the most popular Python packages come pre-installed, so there is no need to install them again.\n",
- "\n",
- "But it is very common to want to use other packages in the Python ecosystem as well, including any packages we might find shared on [GitHub](https://github.com/), or hosted more officially on the Python Package Index ([PyPI](https://pypi.org/)), which is a centralized repository for all official Python packages.\n",
- "\n",
- "To manage the Python package installation process, we use Python's sidekick, a command-line tool called [Pip](https://packaging.python.org/en/latest/tutorials/installing-packages/#use-pip-for-installing).\n",
- "\n",
- ":::{.callout-note}\n",
- "In Google Colab, when we use terminal commands (such as `pip` commands), we prefix them with an exclamation point (!), to differentiate them from Python code.\n",
- ":::\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "cvTclgbripz2",
- "outputId": "86bc5c06-f240-41bc-8e20-7f68028e7fd2"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "pip 23.1.2 from /usr/local/lib/python3.10/dist-packages/pip (python 3.10)\n"
- ]
- }
- ],
- "source": [
- "!pip --version"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "gexwh9AWiYQv",
- "outputId": "a81c3b26-370b-4646-9e2a-889e2fe64ee8"
- },
- "outputs": [],
- "source": [
- "#!pip --help"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "E-22L_vn38NL"
- },
- "source": [
- "## Listing Installed Packages\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "8RSTJhSX38tb"
- },
- "source": [
- "We use a `pip list` command to list all packages installed in the current environment (which in this case is the Google Colab environment).\n",
- "\n",
- "\n",
- "\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "cQ7cILTF32br",
- "outputId": "7035b5bd-2d96-4b79-a531-510243c1df1e"
- },
- "outputs": [],
- "source": [
- "!pip list"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "![List of packages pre-installed in Google Colab](../../../images/pip-list.gif)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "R0lxu5aG3__3"
- },
- "source": [
- "\n",
- "Wow, we see there are dozens of packages already installed.\n",
- "\n",
- "If you are looking for a specific package, you can search for it within the displayed output by piping a `grep` command to search for the package you want (e.g. `pandas`):\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "HiAz2eiX4Fms",
- "outputId": "e3af9190-9dd1-4ffb-f0c8-ee80decc0d62"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "geopandas 0.13.2\n",
- "pandas 2.0.3\n",
- "pandas-datareader 0.10.0\n",
- "pandas-gbq 0.19.2\n",
- "pandas-stubs 2.0.3.230814\n",
- "sklearn-pandas 2.2.0\n"
- ]
- }
- ],
- "source": [
- "!pip list | grep pandas"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "WabV9KTG4AkF"
- },
- "source": [
- "\n",
- "## Installing Packages\n",
- "\n",
- "\n",
- "We use a `pip install` command to install a package, supplying the name of the package we want to install.\n",
- "\n",
- "For example, if we wanted to install the `pandas` package, we would use a command `pip install pandas` (although we see this is already installed in Colab):\n",
- "\n",
- "\n",
- "\n",
- "\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 17,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "mRitHDeYkhHI",
- "outputId": "b19f1df4-8bb6-48e8-fae9-1626a6d593bd"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (2.0.3)\n",
- "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas) (2.8.2)\n",
- "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas) (2023.4)\n",
- "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas) (2024.1)\n",
- "Requirement already satisfied: numpy>=1.21.0 in /usr/local/lib/python3.10/dist-packages (from pandas) (1.25.2)\n",
- "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)\n"
- ]
- }
- ],
- "source": [
- "!pip install pandas"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "XHvj3EWUlBcY"
- },
- "source": [
- "Let's try installing a package for real, such as the [`yahooquery` package](https://pypi.org/project/yahooquery/), which provides access to financial data:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {
- "id": "qIwhcfa94K9u"
- },
- "outputs": [],
- "source": [
- "%%capture\n",
- "!pip install yahooquery"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- ":::{.callout-tip title=\"Pro Tip\"}\n",
- "If we optionally add a \"[capture magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html#cellmagic-capture)\" (`%%capture`) at the top of a cell, it will suppress outputs during the installation process. \n",
- ":::"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "9-4MXi-kkgMc"
- },
- "source": [
- "When we install packages, Pip will download the source code from the PyPI into the current development environment.\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "6bE8TkczmaUd",
- "outputId": "5a0fe522-c237-41b4-b4dd-f437d009a2db"
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "yahooquery 2.3.7\n"
- ]
- }
- ],
- "source": [
- "!pip list | grep yahooquery"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "gszBHVoqmYGS"
- },
- "source": [
- "## Using Installed Packages"
- ]
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "4HrdczX535YR"
+ },
+ "source": [
+ "# Package Management with Pip\n",
+ "\n",
+ "As mentioned, Python has a rich ecosystem of third-party open source libraries called **packages**, that can provide us with super-charged capabilities to make our lives easier.\n",
+ "\n",
+ "If we want to use one of these packages, we must first install it. After installation, we can import its functionality and use it in our program.\n",
+ "\n",
+ "In Google Colab, many of the most popular Python packages come pre-installed, so there is no need to install them again.\n",
+ "\n",
+ "But it is very common to want to use other packages in the Python ecosystem as well, including any packages we might find shared on [GitHub](https://github.com/), or hosted more officially on the Python Package Index ([PyPI](https://pypi.org/)), which is a centralized repository for all official Python packages.\n",
+ "\n",
+ "To manage the Python package installation process, we use Python's sidekick, a command-line tool called [Pip](https://packaging.python.org/en/latest/tutorials/installing-packages/#use-pip-for-installing).\n",
+ "\n",
+ ":::{.callout-note}\n",
+ "In Google Colab, when we use terminal commands (such as `pip` commands), we prefix them with an exclamation point (!), to differentiate them from Python code.\n",
+ ":::\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
+ "id": "cvTclgbripz2",
+ "outputId": "86bc5c06-f240-41bc-8e20-7f68028e7fd2"
+ },
+ "outputs": [
{
- "cell_type": "markdown",
- "metadata": {
- "id": "RA-zY9LFi53n"
- },
- "source": [
- "After installing a package, we now have access to import its functionality and use it. Generally this involves reading the package documentation to see what capabilities it provides. For example, after consulting the [`yahooquery` package documentation](https://yahooquery.dpguthrie.com/), it says we can get started like this:"
- ]
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "pip 23.1.2 from /usr/local/lib/python3.10/dist-packages/pip (python 3.10)\n"
+ ]
+ }
+ ],
+ "source": [
+ "!pip --version"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
- {
- "cell_type": "code",
- "execution_count": 20,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "Ct5SLN0IjFUt",
- "outputId": "ec33d362-5b4f-4ccb-fdaf-74da987df491"
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'aapl': {'maxAge': 1,\n",
- " 'priceHint': 2,\n",
- " 'previousClose': 208.14,\n",
- " 'open': 209.08,\n",
- " 'dayLow': 208.61,\n",
- " 'dayHigh': 210.77,\n",
- " 'regularMarketPreviousClose': 208.14,\n",
- " 'regularMarketOpen': 209.08,\n",
- " 'regularMarketDayLow': 208.61,\n",
- " 'regularMarketDayHigh': 210.77,\n",
- " 'dividendRate': 1.0,\n",
- " 'dividendYield': 0.0047999998,\n",
- " 'exDividendDate': '2024-05-10 00:00:00',\n",
- " 'payoutRatio': 0.14930001,\n",
- " 'fiveYearAvgDividendYield': 0.71,\n",
- " 'beta': 1.25,\n",
- " 'trailingPE': 32.734837,\n",
- " 'forwardPE': 28.912773,\n",
- " 'volume': 4248669,\n",
- " 'regularMarketVolume': 4248669,\n",
- " 'averageVolume': 68294093,\n",
- " 'averageVolume10days': 122265030,\n",
- " 'averageDailyVolume10Day': 122265030,\n",
- " 'bid': 210.52,\n",
- " 'ask': 210.4,\n",
- " 'bidSize': 300,\n",
- " 'askSize': 400,\n",
- " 'marketCap': 3227597930496,\n",
- " 'fiftyTwoWeekLow': 164.08,\n",
- " 'fiftyTwoWeekHigh': 220.2,\n",
- " 'priceToSalesTrailing12Months': 8.457556,\n",
- " 'fiftyDayAverage': 187.4738,\n",
- " 'twoHundredDayAverage': 183.01765,\n",
- " 'trailingAnnualDividendRate': 0.96,\n",
- " 'trailingAnnualDividendYield': 0.00461228,\n",
- " 'currency': 'USD',\n",
- " 'fromCurrency': None,\n",
- " 'toCurrency': None,\n",
- " 'lastMarket': None,\n",
- " 'coinMarketCapLink': None,\n",
- " 'algorithm': None,\n",
- " 'tradeable': False}}"
- ]
- },
- "execution_count": 20,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# https://yahooquery.dpguthrie.com/\n",
- "# https://pypi.org/project/yahooquery/\n",
- "\n",
- "from yahooquery import Ticker\n",
- "\n",
- "t = Ticker('aapl')\n",
- "t.summary_detail"
- ]
+ "id": "gexwh9AWiYQv",
+ "outputId": "a81c3b26-370b-4646-9e2a-889e2fe64ee8"
+ },
+ "outputs": [],
+ "source": [
+ "#!pip --help"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "E-22L_vn38NL"
+ },
+ "source": [
+ "## Listing Installed Packages\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "8RSTJhSX38tb"
+ },
+ "source": [
+ "We use a `pip list` command to list all packages installed in the current environment (which in this case is the Google Colab environment).\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "37Aae367mgW8"
- },
- "source": [
- "It is crucially important to read the package documentation to familiarize yourself with the package's functionality. After further consulting the `yahooquery` package documentation, we find additional capabilities:"
- ]
+ "id": "cQ7cILTF32br",
+ "outputId": "7035b5bd-2d96-4b79-a531-510243c1df1e"
+ },
+ "outputs": [],
+ "source": [
+ "!pip list"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "![List of packages pre-installed in Google Colab](../../../images/pip-list.gif)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "R0lxu5aG3__3"
+ },
+ "source": [
+ "\n",
+ "Wow, we see there are dozens of packages already installed.\n",
+ "\n",
+ "If you are looking for a specific package, you can search for it within the displayed output by piping a `grep` command to search for the package you want (e.g. `pandas`):\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
+ "id": "HiAz2eiX4Fms",
+ "outputId": "e3af9190-9dd1-4ffb-f0c8-ee80decc0d62"
+ },
+ "outputs": [
{
- "cell_type": "code",
- "execution_count": 21,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "80TvLJUJl8vc",
- "outputId": "77ca7ddf-1b73-41cd-82a4-3ff43ee02864"
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'aapl': {'address1': 'One Apple Park Way',\n",
- " 'city': 'Cupertino',\n",
- " 'state': 'CA',\n",
- " 'zip': '95014',\n",
- " 'country': 'United States',\n",
- " 'phone': '408 996 1010',\n",
- " 'website': 'https://www.apple.com',\n",
- " 'industry': 'Consumer Electronics',\n",
- " 'industryKey': 'consumer-electronics',\n",
- " 'industryDisp': 'Consumer Electronics',\n",
- " 'sector': 'Technology',\n",
- " 'sectorKey': 'technology',\n",
- " 'sectorDisp': 'Technology',\n",
- " 'longBusinessSummary': 'Apple Inc. designs, manufactures, and markets smartphones, personal computers, tablets, wearables, and accessories worldwide. The company offers iPhone, a line of smartphones; Mac, a line of personal computers; iPad, a line of multi-purpose tablets; and wearables, home, and accessories comprising AirPods, Apple TV, Apple Watch, Beats products, and HomePod. It also provides AppleCare support and cloud services; and operates various platforms, including the App Store that allow customers to discover and download applications and digital content, such as books, music, video, games, and podcasts. In addition, the company offers various services, such as Apple Arcade, a game subscription service; Apple Fitness+, a personalized fitness service; Apple Music, which offers users a curated listening experience with on-demand radio stations; Apple News+, a subscription news and magazine service; Apple TV+, which offers exclusive original content; Apple Card, a co-branded credit card; and Apple Pay, a cashless payment service, as well as licenses its intellectual property. The company serves consumers, and small and mid-sized businesses; and the education, enterprise, and government markets. It distributes third-party applications for its products through the App Store. The company also sells its products through its retail and online stores, and direct sales force; and third-party cellular network carriers, wholesalers, retailers, and resellers. Apple Inc. was founded in 1976 and is headquartered in Cupertino, California.',\n",
- " 'fullTimeEmployees': 150000,\n",
- " 'companyOfficers': [],\n",
- " 'irWebsite': 'http://investor.apple.com/',\n",
- " 'maxAge': 86400}}"
- ]
- },
- "execution_count": 21,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# https://yahooquery.dpguthrie.com/guide/ticker/intro/\n",
- "\n",
- "t.summary_profile"
- ]
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "geopandas 0.13.2\n",
+ "pandas 2.0.3\n",
+ "pandas-datareader 0.10.0\n",
+ "pandas-gbq 0.19.2\n",
+ "pandas-stubs 2.0.3.230814\n",
+ "sklearn-pandas 2.2.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "!pip list | grep pandas"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "WabV9KTG4AkF"
+ },
+ "source": [
+ "\n",
+ "## Installing Packages\n",
+ "\n",
+ "\n",
+ "We use a `pip install` command to install a package, supplying the name of the package we want to install.\n",
+ "\n",
+ "For example, if we wanted to install the `pandas` package, we would use a command `pip install pandas` (although we see this is already installed in Colab):\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
+ "id": "mRitHDeYkhHI",
+ "outputId": "b19f1df4-8bb6-48e8-fae9-1626a6d593bd"
+ },
+ "outputs": [
{
- "cell_type": "markdown",
- "metadata": {
- "id": "MGkCm4XFnwaf"
- },
- "source": [
- "We can continue to explore the documentation to learn about additional functionality."
- ]
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (2.0.3)\n",
+ "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas) (2.8.2)\n",
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas) (2023.4)\n",
+ "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas) (2024.1)\n",
+ "Requirement already satisfied: numpy>=1.21.0 in /usr/local/lib/python3.10/dist-packages (from pandas) (1.25.2)\n",
+ "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)\n"
+ ]
+ }
+ ],
+ "source": [
+ "!pip install pandas"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "XHvj3EWUlBcY"
+ },
+ "source": [
+ "Let's try installing a package for real, such as the [`yahooquery` package](https://pypi.org/project/yahooquery/), which provides access to financial data:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "id": "qIwhcfa94K9u"
+ },
+ "outputs": [],
+ "source": [
+ "%%capture\n",
+ "!pip install yahooquery"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ ":::{.callout-tip title=\"Pro Tip\"}\n",
+ "If we optionally add a \"[capture magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html#cellmagic-capture)\" (`%%capture`) at the top of a cell, it will suppress outputs during the installation process. \n",
+ ":::"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "9-4MXi-kkgMc"
+ },
+ "source": [
+ "When we install packages, Pip will download the source code from the PyPI into the current development environment.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
+ "id": "6bE8TkczmaUd",
+ "outputId": "5a0fe522-c237-41b4-b4dd-f437d009a2db"
+ },
+ "outputs": [
{
- "cell_type": "markdown",
- "metadata": {
- "id": "n-P7zjirlnOt"
- },
- "source": [
- "By installing and using packages, we are harnessing the power of the open source Python ecosystem."
- ]
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "yahooquery 2.3.7\n"
+ ]
}
- ],
- "metadata": {
+ ],
+ "source": [
+ "!pip list | grep yahooquery"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "gszBHVoqmYGS"
+ },
+ "source": [
+ "## Using Installed Packages"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "RA-zY9LFi53n"
+ },
+ "source": [
+ "After installing a package, we now have access to import its functionality and use it. Generally this involves reading the package documentation to see what capabilities it provides. \n",
+ "\n",
+ "For example, after consulting the [`yahooquery` package](https://yahooquery.dpguthrie.com/) documentation, it says we can get started like this:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
"colab": {
- "provenance": [],
- "toc_visible": true
- },
- "kernelspec": {
- "display_name": "Python 3",
- "name": "python3"
+ "base_uri": "https://localhost:8080/"
},
- "language_info": {
- "name": "python"
+ "id": "80TvLJUJl8vc",
+ "outputId": "77ca7ddf-1b73-41cd-82a4-3ff43ee02864"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'aapl': {'address1': 'One Apple Park Way',\n",
+ " 'city': 'Cupertino',\n",
+ " 'state': 'CA',\n",
+ " 'zip': '95014',\n",
+ " 'country': 'United States',\n",
+ " 'phone': '408 996 1010',\n",
+ " 'website': 'https://www.apple.com',\n",
+ " 'industry': 'Consumer Electronics',\n",
+ " 'industryKey': 'consumer-electronics',\n",
+ " 'industryDisp': 'Consumer Electronics',\n",
+ " 'sector': 'Technology',\n",
+ " 'sectorKey': 'technology',\n",
+ " 'sectorDisp': 'Technology',\n",
+ " 'longBusinessSummary': 'Apple Inc. designs, manufactures, and markets smartphones, personal computers, tablets, wearables, and accessories worldwide. The company offers iPhone, a line of smartphones; Mac, a line of personal computers; iPad, a line of multi-purpose tablets; and wearables, home, and accessories comprising AirPods, Apple TV, Apple Watch, Beats products, and HomePod. It also provides AppleCare support and cloud services; and operates various platforms, including the App Store that allow customers to discover and download applications and digital content, such as books, music, video, games, and podcasts. In addition, the company offers various services, such as Apple Arcade, a game subscription service; Apple Fitness+, a personalized fitness service; Apple Music, which offers users a curated listening experience with on-demand radio stations; Apple News+, a subscription news and magazine service; Apple TV+, which offers exclusive original content; Apple Card, a co-branded credit card; and Apple Pay, a cashless payment service, as well as licenses its intellectual property. The company serves consumers, and small and mid-sized businesses; and the education, enterprise, and government markets. It distributes third-party applications for its products through the App Store. The company also sells its products through its retail and online stores, and direct sales force; and third-party cellular network carriers, wholesalers, retailers, and resellers. Apple Inc. was founded in 1976 and is headquartered in Cupertino, California.',\n",
+ " 'fullTimeEmployees': 150000,\n",
+ " 'companyOfficers': [],\n",
+ " 'irWebsite': 'http://investor.apple.com/',\n",
+ " 'maxAge': 86400}}"
+ ]
+ },
+ "execution_count": 21,
+ "metadata": {},
+ "output_type": "execute_result"
}
+ ],
+ "source": [
+ "# https://yahooquery.dpguthrie.com/guide/ticker/intro/\n",
+ "from yahooquery import Ticker\n",
+ "\n",
+ "ticker = Ticker(\"AAPL\")\n",
+ "ticker.summary_profile"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "MGkCm4XFnwaf"
+ },
+ "source": [
+ "We can continue to explore the documentation to learn about additional functionality."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "n-P7zjirlnOt"
+ },
+ "source": [
+ "By installing and using packages, we are harnessing the power of the open source Python ecosystem."
+ ]
+ }
+ ],
+ "metadata": {
+ "colab": {
+ "provenance": [],
+ "toc_visible": true
+ },
+ "kernelspec": {
+ "display_name": "Python 3",
+ "name": "python3"
},
- "nbformat": 4,
- "nbformat_minor": 0
+ "language_info": {
+ "name": "python"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
}
diff --git a/docs/notes/python-lang/file-operations.qmd b/docs/notes/python-lang/file-operations.qmd
new file mode 100644
index 0000000..f527fc7
--- /dev/null
+++ b/docs/notes/python-lang/file-operations.qmd
@@ -0,0 +1,68 @@
+# Text File Operations
+
+Python applications have access to their surrounding environment, including any files that may exist there.
+
+In this chapter we will practice reading and writing text files, using the [`open` function](https://docs.python.org/3/library/functions.html#open).
+
+For these example, let's consider the following textual message, which in this case is a multiline string:
+
+```{python}
+message = """
+Hello World!
+
+This is a message.
+"""
+
+print(type(message))
+print(message)
+```
+
+
+## Writing Files
+
+We can use the `open` function in "writing" mode (`"w"`) to write text contents to file:
+
+```{python}
+filepath = "my_message.txt"
+
+# "w" means "open the file for writing":
+with open(filepath, "w") as file:
+ file.write(message)
+```
+
+Let's break this down. As the first parameter we first specify the name (or the full path) of the file we want to reference.
+
+Then as the second parameter specifies the "mode", or the way in which we intend to open the file (i.e. reading or writing).
+
+FYI: the `with` statement creates a **context manager** that allows us to open the file without explicitly closing it. The file will be closed when the indentation level resets back to the left margin.
+
+FYI: here, `file` is an alias variable referencing the file object (technically a `TextIOWrapper` datatype). You can choose any variable name you like instead, just reference that same variable name inside the scope of the context manager when reading with the file's `read` method, or writing with the file's `write` method.
+
+## Reading Files
+
+To verify the contents got written to file, let's read the same file.
+
+Here we are use the `open` function in "reader" mode (`"r"`) to read the contents of the text file:
+
+```{python}
+# "r" means "open the file for reading":
+with open(filepath, "r") as file:
+ contents = file.read()
+ print(contents)
+```
+
+## Removing Files
+
+We can use the `os` module to detect, and delete files:
+
+```{python}
+import os
+
+print(os.path.exists(filepath))
+```
+
+```{python}
+os.remove(filepath)
+
+print(os.path.exists(filepath))
+```