User Tools

Site Tools


other:python:starting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
other:python:starting [2019/04/26 11:57] – Improved the quick start section jypeterother:python:starting [2019/04/26 14:18] – Removed sections that were moved to the quick-start jypeter
Line 268: Line 268:
 Note: Anaconda provides and uses ''conda'' for its installation. Since UV-CDAT is now also installed and maintained with ''conda'', you can read the [[other:uvcdat:conda_notes|Installing and maintaining UV-CDAT with conda]] page for more information, even if you are not going to use UV-CDAT Note: Anaconda provides and uses ''conda'' for its installation. Since UV-CDAT is now also installed and maintained with ''conda'', you can read the [[other:uvcdat:conda_notes|Installing and maintaining UV-CDAT with conda]] page for more information, even if you are not going to use UV-CDAT
  
-===== Launching Python ===== +===== ipython =====
- +
-Once you have initialized the [[#some_python_distributions|python distribution]] you want to use, follow the instructions below to //start the interpreter from a shell// (on a Windows computer, you will have to start python from the //Start// menu or by clicking a shortcut on your desktop). +
- +
-Remember that on Linux/Mac you can check which python you are using by typing ''which python''+
- +
-==== Useful keyboard shortcuts ==== +
- +
-^  Key  ^  Effect +
-|  **CTRL-D**  |  Exit the interpreter +
-|  **↑ and ↓**  |  Go to previous/next line(s) +
-|  **CTRL-A**  |  Go to the beginning of the line  | +
-|  **CTRL-E**  |  Go to the end of the line  | +
-|  **CTRL-K**  |  Erase from the cursor to the end of the line  | +
-|  **CTRL-U**  |  Erase from the beginning of the line to the cursor +
-|  **TAB** x 2  |  Do some TAB-completion (context dependent)\\ e.g. ''a = np.cum**TABTAB**'' +
-|  **CTRL-C**  |  Interrupt a running script +
-|  **CTRL-Z**  |  Suspend the interpreter and go back to the shell\\ **Do not forget** to go back to the interpreter with ''fg''\\ or to kill it (with ''jobs'' and ''kill %NN''+
- +
-==== Stand-alone script ==== +
- +
-A python script is just like any other shell script. You don't have to explicitly call the python interpreter, if the interpreter is specified in a ''#!'' [[https://en.wikipedia.org/wiki/Shebang_%28Unix%29|shebang comment]] on the first line of the script with, and the script has its execution bit set (''chmod +x my_script.py'').  +
- +
-<code> +
-jypeter@asterix1 - ...jypeter - 54 >cat basic_script.py +
-#!/usr/bin/env python +
- +
-import sys +
- +
-script_name = sys.argv[0] +
- +
-print('Hello world, I am the ' + script_name + ' script'+
- +
-# The end +
- +
-jypeter@asterix1 - ...jypeter - 55 >chmod +x basic_script.py +
- +
-ypeter@asterix1 - ...jypeter - 56 ># Type here what is required to initialize the distribution you want +
- +
-jypeter@asterix1 - ...jypeter - 57 >./basic_script.py +
-Hello world, I am the ./basic_script.py script +
-</code> +
- +
-==== Standard interpreter ==== +
- +
-  * ''python'': start the interpreter +
-  * ''python script.py'': execute //script.py// and **exit** +
-  * ''python -i script'': execute //script.py// and **stay in the interpreter** (''-i'' = //**I**nteractive//+
- +
-Type ''man python'' if you want to see what other command line options are available+
  
 ==== ipython interpreter ==== ==== ipython interpreter ====
other/python/starting.txt · Last modified: 2024/09/13 16:20 by jypeter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki