Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Python Programming for Arduino
  • Toc
  • feedback
Python Programming for Arduino

Python Programming for Arduino

By : Pratik Desai
4.6 (22)
close
Python Programming for Arduino

Python Programming for Arduino

4.6 (22)
By: Pratik Desai

Overview of this book

This is the book for you if you are a student, hobbyist, developer, or designer with little or no programming and hardware prototyping experience, and you want to develop IoT applications. If you are a software developer or a hardware designer and want to create connected devices applications, then this book will help you get started.
Table of Contents (13 chapters)
close
12
Index

Using CSV files to store data


Now you know methods to open, manipulate, and close files using Python. In the previous examples, we used the Python interpreter and string data to get familiar with these methods. But when it comes to saving a large number of numerical values from sensor data, the comma separated values (CSV) file format is one of the most widely used file formats other than text. As the name states, values are separated and stored using commas or other delimiters such as a space or tab. Python has a built-in module to deal with CSV files.

To begin with, use the following code snippet to create a Python file and run your first CSV program:

import csv
data = [[1, 2, 3], ['a', 'b', 'c'], ['Python', 'Arduino', 'Programming']]

with open('example.csv', 'w') as f:
  w = csv.writer(f)
  for row in data:
    w.writerow(row)

You can also open the csvWriter.py file from this chapter's code folder, which contains the same code. After executing the code, you will be able to find a file named...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete