34 |
34 |
35 In this tutorial, we will see how to run python scripts from command |
35 In this tutorial, we will see how to run python scripts from command |
36 line, importing modules, importing scipy and pylab modules. And also |
36 line, importing modules, importing scipy and pylab modules. And also |
37 see the Python standard library. |
37 see the Python standard library. |
38 |
38 |
|
39 .. #[Punch: the sentence seems discontinuous.] |
|
40 |
39 {{{ switch to next slide on executing python scripts from command line }}} |
41 {{{ switch to next slide on executing python scripts from command line }}} |
40 |
42 |
41 Let us create a simple python script to print hello world. Open your |
43 Let us create a simple python script to print hello world. Open your |
42 text editor and type the following, |
44 text editor and type the following, |
43 |
45 |
119 Now let us run the script again, |
121 Now let us run the script again, |
120 :: |
122 :: |
121 |
123 |
122 python four_plot.py |
124 python four_plot.py |
123 |
125 |
124 Now it gave another error plot not defined, let us edit the file again |
126 Now it gave another error -- plot not defined, let us edit the file |
125 and add the line below the line we just added, |
127 again and add the line below the line we just added, |
126 |
128 |
127 {{{ switch to next slide, fix ``plot`` problem }}} |
129 {{{ switch to next slide, fix ``plot`` problem }}} |
128 |
130 |
129 {{{ add the line as second line in four_plot.py and save }}} |
131 {{{ add the line as second line in four_plot.py and save }}} |
130 :: |
132 :: |
152 :: |
154 :: |
153 |
155 |
154 from scipy import * |
156 from scipy import * |
155 |
157 |
156 So in practice it is always good to use function names instead of |
158 So in practice it is always good to use function names instead of |
157 asterisk or star. As if we use asterisk to import from a particular |
159 asterisk or star. If we use asterisk to import from a particular |
158 module then it will replace any existing functions with the same name |
160 module then it will replace any existing functions with the same name |
159 in our name-space. |
161 in our name-space. |
160 |
162 |
161 {{{ switch to next slide, Instead of ``*`` }}} |
163 {{{ switch to next slide, Instead of ``*`` }}} |
162 |
164 |
206 |
208 |
207 python sine.py |
209 python sine.py |
208 |
210 |
209 {{{ switch to next slide, What is a module? }}} |
211 {{{ switch to next slide, What is a module? }}} |
210 |
212 |
211 So till now we have been learning about importing modules, now what is |
213 Until now we have been learning about importing modules, now what is a |
212 a module? |
214 module? |
213 |
215 |
214 A module is simply a file containing Python definitions and |
216 A module is simply a file containing Python definitions and |
215 statements. Definitions from a module can be imported into other |
217 statements. Definitions from a module can be imported into other |
216 modules or into the main module. |
218 modules or into the main module. |
217 |
219 |
218 {{{ switch to next slide, Python standard library }}} |
220 {{{ switch to next slide, Python standard library }}} |
219 |
221 |
220 Python has a very rich standard library of modules |
222 Python has a very rich standard library of modules. It is very |
221 |
223 extensive, offering a wide range of facilities. Some of the standard |
222 Python's standard library is very extensive, offering a wide range of |
224 modules are, |
223 facilities. Some of the standard modules are, |
|
224 |
225 |
225 for Math: math, random |
226 for Math: math, random |
226 for Internet access: urllib2, smtplib |
227 for Internet access: urllib2, smtplib |
227 for System, Command line arguments: sys |
228 for System, Command line arguments: sys |
228 for Operating system interface: os |
229 for Operating system interface: os |