liveBook · Manning

Readline

As explained in Julia as a Second Language

readline is a Julia function that reads one line of text from an input stream.

readline reads one line of text from an input stream. The stream may be a file, the keyboard through stdin, or another Julia I/O object. section 5.0 section 17.1

Read a file one line at a time

Open a CSV file, then call readline(io) repeatedly. The first calls return lines such as "name,size,price" and "hawaiian,S,10.5". Combine readline with eof to stop at the end.

Read keyboard input

Calling readline(stdin) waits for a line typed into the terminal and returns it as text. Store the result, then print or process it. section 5.3.2

A practical line-reading workflow is:

  • Split each returned line when it contains delimited fields. section 17.1
  • Parse numeric or Boolean fields because readline returns text rather than typed values. section 5.3.2
  • Close the I/O object after processing to avoid leaking operating-system resources. section 17.1

How Julia as a Second Language covers it

How deep it goes
Demonstrates line-by-line loops and stream types, while deferring more sophisticated CSV-reading techniques.
Examples
Uses pizza-sales.csv, keyboard input, and rocket-engines.csv to demonstrate line-oriented reading.
What it assumes
Assumes basic Julia functions and strings while introducing streams, stdin, file opening, end-of-file checks, and text conversion.
What you can do after
Apply it via Julia I/O objects to read files or keyboard lines and feed the resulting text into parsing workflows.
How it connects
Connects readline with open, stdin, eof, split, parse, IOStream, and IOBuffer.

Also explained in

Compare how 4 books explain readline →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.