Giter VIP home page Giter VIP logo

python-io's Introduction

Python I/O: Conversion of a contacts list in CSV with pickle and JSON

This code was developed as an exercise within the online course Python: trabalhando com I/O [Python: working with I/O] at Alura.

The code implements methods for:

  1. Reading a contacts list from a CSV file (.data/contacts.csv)

    • Each line of the CSV file represents one contact in the format id,name,email
  2. Converting the CSV line into a Python object of the class Contact

    • The class is implemented in contact.py a an object with attributes id, name, and email
  3. Serializing and deserializing the contacts list using pickle

  4. Serializing and deserializing the contacts list using JSON

Repository organization

The repository is organized as follows

./
|-- README.md       : this file
|-- main.py         : main program; run with `python3 main.py`
|-- contact.py      : implements the `Contact` class
|-- contact_utils.py    : implements the methods for handling `Contact` objects
`-- data/           : input and output files
    |-- contacts.csv    : contacts list in CSV format
    `-- contacts.json   : contacts list in JSON format

Running the code

To run the code, simply execute the file main.py with a Python 3 interpreter.

python3 main.py

The code was written for study purposes. All it should do is read the data/contacts.csv file and save its contents back in pickle and JSON formats as data/contacts.p and data/contacts.json. It then proceeds to read the pickle and JSON files and print their contents on the screen.

Warning

Make sure you trust the content of pickle files before opening them. Since they'll restore Python objects, it's fairly easy to insert malicious code into them.


python-io's People

Contributors

af0liveira avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.