📙
Python Programming
  • Python Programming
  • Installation and Setup
  • Part 1: Basics
    • Variables
      • Primitive Data Types
      • Secondary Data Types
    • Control Flow and Loop
    • Functions
    • Error Handling
    • Decorators
    • Constructor
    • Built-in Functions and Modules
    • Pythonic Code
    • Miscellaneous Functionalities
    • Understanding Checkpoint I
    • Python Problem Practice I
      • Solutions
  • Part 2: Level Up
    • Real Life Application I
    • Real Life Application II
    • OOP Concepts
    • Creating Library
    • Real Life Application III
  • Processing Related
    • Parallel Processing
    • Oreilly - High Performance Python
    • Memory Management
      • Memory Leak
      • String
      • Array
      • Dictionary
    • Ubuntu CPU and RAM
    • Time and Space Complexity
  • Data Structure
    • Data Structure Overview
    • Array
    • Stack
    • Queue
    • LinkedList
    • Hash-table and Hash-map
    • Recursion
    • Binary Tree
    • Heap Data Structure
    • Graphs
      • Python Graph Visualisation
    • Dynamic Programming
    • Problem Solving Techniques
    • Additional topics
Powered by GitBook
On this page
  • Writing into a File
  • Writing a .txt File
  • Writing to a JSON File
  • Reading a File
  • Reading a JSON File

Was this helpful?

  1. Part 1: Basics

Miscellaneous Functionalities

Writing into a File

Writing a .txt File

# saving a text file
with open("file_name.txt", "w") as output:
    output.write(str(content))
   

Writing to a JSON File

# saving a json file 
import json
with open('file_name.json', 'w') as f:
    json.dump(content, f)

Reading a File

Reading a JSON File

import json
  
# Opening JSON file
f = open('file_name.json',)
  
# returns JSON object as a dictionary
data = json.load(f)
PreviousPythonic CodeNextUnderstanding Checkpoint I

Last updated 4 years ago

Was this helpful?