Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Page - 213 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

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

Image of the Page - 213 -

Image of the Page - 213 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 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.
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2016
Language
English
License
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
248
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python