0% found this document useful (0 votes)
4 views4 pages

Python File Functions: Normal, CSV, JSON

The document outlines various file functions in Python for normal files, CSV files, and JSON files. It provides syntax and examples for functions such as open(), read(), write(), and specific CSV and JSON operations. This serves as a quick reference for handling different file types in Python programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Python File Functions: Normal, CSV, JSON

The document outlines various file functions in Python for normal files, CSV files, and JSON files. It provides syntax and examples for functions such as open(), read(), write(), and specific CSV and JSON operations. This serves as a quick reference for handling different file types in Python programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python File Functions: Normal, CSV, and JSON

📝 Normal File Functions

open()
Syntax:
open(filename, mode)

Example:

f = open('[Link]', 'r')

read()
Syntax:
[Link]()

Example:

data = [Link]()

readline()
Syntax:
[Link]()

Example:

line = [Link]()

readlines()
Syntax:
[Link]()

Example:

lines = [Link]()

write()
Syntax:
[Link](data)

Example:

[Link]('Hello!')
writelines()
Syntax:
[Link](list)

Example:

[Link](['A\n', 'B\n'])

seek()
Syntax:
[Link](position)

Example:

[Link](0)

tell()
Syntax:
[Link]()

Example:

pos = [Link]()

📊 CSV File Functions

[Link]()
Syntax:
[Link](file)

Example:

import csv
with open('[Link]') as f:
reader = [Link](f)

[Link]()
Syntax:
[Link](file)

Example:

reader = [Link](f)

[Link]()
Syntax:
[Link](file)
Example:

writer = [Link](f)
[Link](['Name', 'Age'])

[Link]()
Syntax:
[Link](rows)

Example:

[Link]([['A', 21], ['B', 22]])

[Link]()
Syntax:
[Link](file, fieldnames=[])

Example:

writer = [Link](f, fieldnames=['name', 'age'])

[Link]()
Syntax:
[Link]()

Example:

[Link]()

🧩 JSON File Functions

[Link]()
Syntax:
[Link](file)

Example:

import json
with open('[Link]') as f:
data = [Link](f)

[Link]()
Syntax:
[Link](string)

Example:

data = [Link]('{"name": "A"}')


[Link]()
Syntax:
[Link](obj, file)

Example:

[Link](data, f)

[Link]()
Syntax:
[Link](obj)

Example:

s = [Link]({'name': 'A'})

You might also like