Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Seite - 213 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 213 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Bild der Seite - 213 -

Bild der Seite - 213 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text der Seite - 213 -

A.3 HowtoWriteandRunaPythonProgram 213 A.3.4 UsingaPlainTextEditorandaTerminalWindow 1. Create a folder where your Python programs can be located, say with name mytestunderyourhomefolder. This ismostconvenientlydone in the terminal window since you need to use this window anyway to run the program. The commandforcreatinganewfolder ismkdir mytest. 2. Move to thenewfolder:cd mytest. 3. Start theeditorofyourchoice. 4. Write a program in the editor, e.g., just the line print ’Hello!’. Save the programunder thenamemyprog1.py in themytest folder. 5. Move to the terminalwindowandwritepython myprog1.py. You should see thewordHello!beingprinted in thewindow. A.3.5 Spyder Spyder is a graphical application for developing and running Python programs, available on all major platforms. Spyder comes with Anaconda and some other pre-built environments for scientific computingwithPython. OnUbuntu it is con- veniently installedbysudo apt-get install spyder. The left part of the Spyder window contains a plain text editor. Click in this window andwrite print ’Hello!’ and return. ChooseRun from theRun pull- downmenu, and observe the outputHello! in the lower rightwindowwhere the output fromprograms isvisible. Youmaycontinuewithmoreadvancedstatements involvinggraphics: import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 4, 101) y = np.exp(-x)*np.sin(np.pi*x) plt.plot(x,y) plt.title(’First test of Spyder’) plt.savefig(’tmp.png’) plt.show() ChoosingRun – Run now leads to a separate windowwith a plot of the function e x sin. x/. FigureA.1showshowtheSpyderapplicationmay look like. The plot file we generate in the above program, tmp.png, is by default found in the Spyder folder listed in the default text in the top of the program. You can choose Run – Configure ... to change this folder as desired. The program you write is written to a file .temp.py in the same default folder, but any name and foldercanbespecified in the standardFile – Saveas... menu. Aconvenient featureofSpyder is that theupper rightwindowcontinuouslydis- playsdocumentationof thestatementsyouwrite in theeditor to the left.
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2016
Sprache
englisch
Lizenz
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
248
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python