|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Lecture 7 - Sys Module" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "markdown", |
| 12 | + "metadata": {}, |
| 13 | + "source": [ |
| 14 | + "The sys module provides functions and variables used to manipulate different parts of the Python runtime environment.\n", |
| 15 | + "\n", |
| 16 | + "## sys.argv\n", |
| 17 | + "\n", |
| 18 | + "sys.argv returns a list of command line arguments passed to a Python script. The item at index 0 in this list is always the name of the script. The rest of the arguments are stored at the subsequent indices." |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": 2, |
| 24 | + "metadata": {}, |
| 25 | + "outputs": [ |
| 26 | + { |
| 27 | + "name": "stdout", |
| 28 | + "output_type": "stream", |
| 29 | + "text": [ |
| 30 | + "Writing C:\\Users\\majain\\Desktop\\News\\welcome.py\n" |
| 31 | + ] |
| 32 | + } |
| 33 | + ], |
| 34 | + "source": [ |
| 35 | + "%%writefile C:\\Users\\majain\\Desktop\\News\\welcome.py\n", |
| 36 | + "\n", |
| 37 | + "import sys\n", |
| 38 | + "print(\"Hello {}. Welcome to {} tutorial\".format(sys.argv[1], sys.argv[2]))" |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "markdown", |
| 43 | + "metadata": {}, |
| 44 | + "source": [ |
| 45 | + "## sys.exit\n", |
| 46 | + "This causes the script to exit back to either the Python console or the command prompt. This is generally used to safely exit from the program in case of generation of an exception.\n", |
| 47 | + "\n", |
| 48 | + "## sys.maxsize\n", |
| 49 | + "Returns the largest integer a variable can take." |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "markdown", |
| 54 | + "metadata": {}, |
| 55 | + "source": [ |
| 56 | + "## sys.path\n", |
| 57 | + "This is an environment variable that is a search path for all Python modules.\n", |
| 58 | + "\n", |
| 59 | + "## sys.version\n", |
| 60 | + "This attribute displays a string containing the version number of the current Python interpreter." |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "code", |
| 65 | + "execution_count": 2, |
| 66 | + "metadata": {}, |
| 67 | + "outputs": [ |
| 68 | + { |
| 69 | + "data": { |
| 70 | + "text/plain": [ |
| 71 | + "9223372036854775807" |
| 72 | + ] |
| 73 | + }, |
| 74 | + "execution_count": 2, |
| 75 | + "metadata": {}, |
| 76 | + "output_type": "execute_result" |
| 77 | + } |
| 78 | + ], |
| 79 | + "source": [ |
| 80 | + "import sys\n", |
| 81 | + "sys.maxsize" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "code", |
| 86 | + "execution_count": 4, |
| 87 | + "metadata": {}, |
| 88 | + "outputs": [ |
| 89 | + { |
| 90 | + "data": { |
| 91 | + "text/plain": [ |
| 92 | + "['C:\\\\Users\\\\majain\\\\Desktop\\\\DataScience\\\\DataScience by Madhur\\\\01 Python Crash Course',\n", |
| 93 | + " 'C:\\\\Users\\\\majain\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\python37.zip',\n", |
| 94 | + " 'C:\\\\Users\\\\majain\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\DLLs',\n", |
| 95 | + " 'C:\\\\Users\\\\majain\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\lib',\n", |
| 96 | + " 'C:\\\\Users\\\\majain\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3',\n", |
| 97 | + " '',\n", |
| 98 | + " 'C:\\\\Users\\\\majain\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\lib\\\\site-packages',\n", |
| 99 | + " 'C:\\\\Users\\\\majain\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\lib\\\\site-packages\\\\win32',\n", |
| 100 | + " 'C:\\\\Users\\\\majain\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\lib\\\\site-packages\\\\win32\\\\lib',\n", |
| 101 | + " 'C:\\\\Users\\\\majain\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\lib\\\\site-packages\\\\Pythonwin',\n", |
| 102 | + " 'C:\\\\Users\\\\majain\\\\AppData\\\\Local\\\\Continuum\\\\anaconda3\\\\lib\\\\site-packages\\\\IPython\\\\extensions',\n", |
| 103 | + " 'C:\\\\Users\\\\majain\\\\.ipython']" |
| 104 | + ] |
| 105 | + }, |
| 106 | + "execution_count": 4, |
| 107 | + "metadata": {}, |
| 108 | + "output_type": "execute_result" |
| 109 | + } |
| 110 | + ], |
| 111 | + "source": [ |
| 112 | + "sys.path" |
| 113 | + ] |
| 114 | + }, |
| 115 | + { |
| 116 | + "cell_type": "code", |
| 117 | + "execution_count": 5, |
| 118 | + "metadata": {}, |
| 119 | + "outputs": [ |
| 120 | + { |
| 121 | + "data": { |
| 122 | + "text/plain": [ |
| 123 | + "'3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]'" |
| 124 | + ] |
| 125 | + }, |
| 126 | + "execution_count": 5, |
| 127 | + "metadata": {}, |
| 128 | + "output_type": "execute_result" |
| 129 | + } |
| 130 | + ], |
| 131 | + "source": [ |
| 132 | + "sys.version" |
| 133 | + ] |
| 134 | + } |
| 135 | + ], |
| 136 | + "metadata": { |
| 137 | + "kernelspec": { |
| 138 | + "display_name": "Python 3", |
| 139 | + "language": "python", |
| 140 | + "name": "python3" |
| 141 | + }, |
| 142 | + "language_info": { |
| 143 | + "codemirror_mode": { |
| 144 | + "name": "ipython", |
| 145 | + "version": 3 |
| 146 | + }, |
| 147 | + "file_extension": ".py", |
| 148 | + "mimetype": "text/x-python", |
| 149 | + "name": "python", |
| 150 | + "nbconvert_exporter": "python", |
| 151 | + "pygments_lexer": "ipython3", |
| 152 | + "version": "3.7.4" |
| 153 | + } |
| 154 | + }, |
| 155 | + "nbformat": 4, |
| 156 | + "nbformat_minor": 2 |
| 157 | +} |
0 commit comments