Skip to content

How can I implement this code? #88572

Jan 17, 2024 · 3 comments · 7 replies
Discussion options

You must be logged in to vote

Hope this helps.....

import json
import os

class JSONFileSystem:
    def __init__(self, file_name='FS.json'):
        self.file_name = file_name
        self.file_system = self.load_file_system()

    def load_file_system(self):
        try:
            with open(self.file_name, 'r') as file:
                return json.load(file)
        except FileNotFoundError:
            return {}

    def save_file_system(self):
        with open(self.file_name, 'w') as file:
            json.dump(self.file_system, file, indent=2)

    def create_file(self, file_name, content):
        self.file_system[file_name] = content
        self.save_file_system()

    def read_file(self, file_name):
        r…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@ghost
Comment options

@FreeQAOnline

This comment was marked as off-topic.

@ghost
Comment options

@ghost
Comment options

@FreeQAOnline

This comment was marked as off-topic.

Comment options

You must be logged in to vote
2 replies
@ghost
Comment options

@ghost
Comment options

Answer selected by FreeQAOnline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Programming Help Programming languages, open source, and software development.
1 participant