
Sure, based on the provided content, here are the details you requested: Python File Input Training
Learn about file input in Python, including working with lists, arrays, setting up your environment, and essential commands for file manipulation and string operations.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Introduction to File Input CSEG Python Training, Week 7
Lists and Arrays Arrays Lists Must import (numpy, array) Built-in Allow indexing, slicing, and iterating Defined using square brackets Defined by a call to a function in the imported package Ordered Mutable One Element operations dimension One or more dimensions Elements don't have to be unique Can have heterogeneous element types Array operations Homogeneous element types
Setup Get sample code git clone https://gitlab.com/CSU-CIRA/python_training_resources/text_csv_files.git Get sample text and CSV files (same data, different formats) and put it in your cloned directory curl -O/wget/put link in browser ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_trend_gl.txt ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_trend_gl.csv Optional: open one of the files using your preferred text/CSV tool to see what we're dealing with Header/footer Comments Field header Missing data Create and activate your environment cd text_csv_files conda env create -f environment.yml conda activate text_csv_files
Command Quick Reference File Input open(filename, mode) Mode allows you to set read (default), write, append, and create action, along with specifying whether you are handling a text (default) or binary file Returns a file object that can be used with .read(), .readline(), and .readlines() .close() Can also handle closing implicitly by using with open Looping range(stop), range(start, stop, step) Default start is zero, default step is one, and stop is non-inclusive String Manipulation .split(separator) Any type/amount of whitespace is the default separator if none is specified .strip(characters) Any type/amount of leading and trailing whitespace is removed by default if no characters are specified .startswith(characters) Looks at the beginning of a string by default, but can key off a certain starting and ending character position within the string List Building .append(item/list) Variable Inspection type(variable)