Input/Output
Dan Stanzione (TACC) (original author), Steve Lantz, Adam Brazier, Chris Myers
Cornell Center for Advanced Computing
Revisions: 5/2024, 7/2021, 8/2016, 10/2014, 2/2014, 3/2013, 6/2010 (original)
As we have seen, Python's elementary I/O functions are an excellent starting point for those who may be new to programming. It is easy to write code to accept user input from a prompt, for example. But Python also provides powerful I/O capabilities for supporting a wide variety of practical applications.
In this section, we will see how to format variables and text prior to printing them to the screen; how to read data from and write data into files; and even how to preserve entire objects and classes for later re-initialization.
If you are experienced with C/Fortran programming, you should find Python's advanced I/O operations to be flexible and robust (rather like the language itself).
Objectives
After you complete this segment, you should be able to:
- Use I/O functions
- Format variables and text
- Read data from and write data into files
- Preserve entire objects and classes for later re-initialization
Prerequisites
This workshop assumes the reader has no prior exposure to Python. A working knowledge of UNIX/Linux and general programming concepts is assumed. The target audience is scientists and engineers using high performance computing systems who wish to boost their productivity through the use of Python.
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)