Вы находитесь на странице: 1из 2

CSV- stands for comma separated values file.

This allows data to be saved in a table structured


format. CSVs look similar to a spreadsheet but with a .csv extension (they often take the form of a text
file containing information separated by commas). CSV files can be used with any spreadsheet
program but They differ from other spreadsheet file types because you can only have a single sheet in
a file, they cannot save cell, column, or row styling, and cannot save formulas.
For example, if you had a table similar to the one below, that data would look like the CSV data below
the table.
Spreadsheet Table:
Data 1
Example 1
Example 1

Data 2
Example 2
Example 2

Data 3
Example 3
Example 3

CSV Table:
import csv
import sys

# imports the csv module


# imports the sys module

f = open(sys.argv[1], 'rb') # opens the csv file


try:
reader = csv.reader(f) # creates the reader object
for row in reader: # iterates the rows of the file in
orders
print row # prints each row
finally:
f.close()
# closing

Data 1, Data 2, Data 3


Example 1, Example 2, Example
3
Example 1, Example 2, Example
Each row is a new line, and each column is separated with a comma.
Example of CSV in python
The CSV module allows you to read and write data in a CSV format. It allows programmers to write
data in the format preferred by Excel and read data from a file which was generated by Excel without
knowing the precise details of the CSV format used by Excel. Programmers can also describe the
CSV formats understood by other applications or define their own special-purpose CSV formats.

JSON-stands for JavaScript Object Notation. It is a way to store information in an organized access
manner. It gives us a readable collection of data that we can access in a logical manner.
JSON Data:

{
"Red":"#f00",
"Green":"#0f0",

JSON has the benefit of having implementations in many languages


(especially JavaScript), making it suitable for inter-application
communication. JSON is probably most widely used for communicating
between the web server and client in an AJAX application, but is not
limited to that problem domain.

"Blue":"#00f",
"Cyan":"#0ff",
"Magenta":"#f0f",
"Yellow":"#ff0",
"Black":"#000"
}
Sarah
Dunne

Take the following string containing JSON data:


json_string = '{"first_name": "Guido", "last_name":"Rossum"}'
It can be parsed ( to analyse (a string or text) ) like this:
import json

parsed_json = json.loads(json_string)
And can now be used as a normal dictionary:
print(parsed_json['first_name'])"Guido"

Sarah Dunne

Вам также может понравиться