Hardware Reference
In-Depth Information
A CSV file is a comma-separated values file. This is where values are stored in a
simple text file, separated by commas. It is possible to represent a simple table
or database inside a CSV file. Each row or record in the database is represented
by a line in the file, and each field or column is represented by some text on that
line separated by commas. Some CSV files use the first line of the file to store
the headings or field names. All popular spreadsheet and database programs can
import and export data in CSV format.
CSV is a very simple and widely used format. Here is a sample of a CSV file that stores
part of a table from a database with details about Minecraft gamer characters. In this
CSV file, the first row (or line) in the file has the names of the fields, and all other lines
have data separated by commas:
Name,Handle,Speciality
David,w_geek,Coding in Python
Roma,physics_gurl,Designing big buildings
Ryan,mr_teck,Minecraft robots
Craig,rrrrrrrr,TNT expert
This CSV file has one header row, which has three field names called Name , Handle
and Speciality . There are four data rows, each with three fields of data.
When designing complex structures in software, sometimes it is useful to use
other tools to help you. As a software engineer, a spreadsheet is one of the tools
that I regularly find a use for when designing and representing data. Spreadsheets
provide a fantastic way to represent tables of data that can be exported in a CSV
file format, and then loaded into programs. You could try designing a maze in your
favourite spreadsheet program by setting all the columns to be very narrow, and
using formulas to display a white square whenever you put a 0 and a yellow square
whenever you put a 1 . Once you have visualised your maze this way, export it as
maze.csv and run your program and see if you and your friends can solve it!
For your maze data file, you won't need a header row, because each column in the table
represents the same type of data; that is, it stores a number 0 for a space and a number
1 for a wall. You can download this sample maze file from the companion website, but
here it is if you want to type it in:
1. Create a new text file by choosing File New File. Use File Save As and name
the file maze1.csv .
Search WWH ::




Custom Search