#๐Ÿ”’ Little Code Review

7 messages ยท Page 1 of 1 (latest)

small steeple
#

Can anyone gave me a Code Review ?

import json
from colorama import Fore, Style

jsonFile = 'color.json'

def saveColorsInConfig(filename):
    colors = {
        "Red": {"name": "Red", "code": Fore.RED},
        "Yellow": {"name": "Yellow", "code": Fore.YELLOW},
        "Blue": {"name": "Blue", "code": Fore.BLUE},
        "Green": {"name": "Green", "code": Fore.GREEN},
        "Reset": {"name": "Reset", "code": Style.RESET_ALL},
        "Black": {"name": "Black", "code": Fore.BLACK}
    } 
    
    with open(filename, 'w') as file:
        json.dump(colors, file, indent=4)
        
        
def LoadColorsFromConfig(filename):
    with open(filename, 'r') as file:
        colors = json.load(file)
    return colors

def main():
    testo = []
    saveColorsInConfig(jsonFile)
    
    color = LoadColorsFromConfig(jsonFile)
    
    Red = color["Red"]["code"]
    Yellow = color["Yellow"]["code"]
    Blue = color["Blue"]["code"]
    Green = color["Green"]["code"]
    Reset = color["Reset"]["code"]
    Black = color["Black"]["code"]

    while True:
        test = input(f"{Green}Write a Option{Black}:{Reset} ")
        
        if test.lower() == "done":
            print(f"{Fore.RED}Lists is Finished and {Blue}{len(testo)} {Red}Options are In the List {Reset}")
            
            for i, testa in enumerate(testo):
                print(f"{Blue}{i}{Black}: {Yellow}{testa}")
                
            break
                
        else:
            testo.append(test)

if __name__ == "__main__":
    main()
wintry jettyBOT
#

@small steeple

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

willow rivet
#

colors is not a function of saveColorsInConfig so you should extract that from the function.

primal light
dreamy meteor
wintry jettyBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.