flush() function
strip() - removes the given character form both ends.
lstrip() - removes given character from left end.
rstrip() - removes given character from right end.
File Pointer
Binary file operations
pickle
byte stream -> pickle
read -> unpickle from byte stream to the original format
list1 = [1,2,3,"hello",3.5]
Python module pickle
This pickle module provides to two main functions
1)dump(object_to_write,filehandle)
2)load() - can be used read the dumped data from file
1. Inserting/appending a record in a binary file
2. Reading records from a binary file
3. Search a record in a binary file
4. Update a record in a binary file
CSV (Comma Separated Values)
Read CSV file using csv.reader
Read CSV file using readlines()
Read CSV file using Pandas
Read CSV file using csv.DictReader()
import csv
CSV - Comma Separated Values
Each line in a file is known as data/record.
Each record consists of one or more fields, separated by commas (known as
delimiters).
Tabular data is stored as text in a CSV file.
csv.reader
csv1 = csv.reader(file)
empty list
next() - Used to obtain the header
next() - returns the current row and moves to the next row.
r - to read an existing file
w - to create a new file
a - appending
------------
DictReader - Used to read the CSV files in dictionary format
A dictionary - Key value - Key : Value
----------------------------------
What is JSON?
JavaScript Object Notation.
JSON Objects Python Equivalent
Object Dictionary(dict)
Array List(list)
String String(str)
Number int,float
Boolean true True
Boolean false False
Null None
json.dumps() - This function is used to serialize(encode) a Python object into a
JSON formatted string.
json.dump() - This function is used to serialize a Python object and write it to a
JSON file.
json.loads() - This function is used to parse(decode) a JSON formatted string and
convert it
into a Python object.
json.load() - This function is used to read a JSON file and parse its contents
into a Python object
requests - It allows us to send HTTP requests using Python