CSV stores a small table as text. In the snack list, the first line names the fields, code and icon; each later line supplies one snack’s QR-code value and emoji short code. Python’s DictReader turns those lines into dictionaries, so code can access items by field name rather than by column position. section 11.3.1
Listing 11.1 items.csv: List of snack QR codes and icons
code,icon grapes,:grapes: carrots,:carrot: candy,:candy: lollipop,:lollipop:
This CSV file maps each snack QR code to an icon. The header row becomes dictionary keys, and each following row becomes one item. section 11.3.1
Load the file as lines, then pass them to DictReader. The resulting list contains records such as {'code': 'grapes', 'icon': ':grapes:'}. A selected field is available directly through its key, for example item['code'] or item['icon']. section 11.3.1
Load snack records for a robot
A reusable get_items function opens items.csv, converts emoji short codes on every line, and returns list(DictReader(lines)). The robot can use each code value as a QR-code target while the converted icon is ready for a user interface. section 11.3.2 section 11.3
Use CSV-backed records in this workflow:
- Create a header row for the values the application needs, such as code and icon. section 11.3.1
- Read the file and parse it with DictReader into a list of dictionaries. section 11.3.1
- Convert emoji short codes before returning records when interface icons require Unicode characters. section 11.3.1 section 11.3.2
- Match a selected code against decoded QR data to guide the robot toward the requested snack. section 11.3.2
Keeping the snack catalog in a CSV file separates item data from robot behavior. The motion library reads the catalog, searches for the matching QR code, moves into position, swings its servo arm, and returns to the start after a push. section 11.3.2














