Awesome Python Scripts

Higuys! Today I want to share with you some useful scripts for python.
I am a big fan of scripts, because they facilitate routine work, improve projects, as well as give a visual representation of the use of knowledge in practice

Let’s go!

1. Convert JSON to CSV

import json
if __name__ == '__main__':
    try:
        with open('input.json', 'r') as f:
            data = json.loads(f.read())

        output = ','.join([*data[0]])
        for obj in data:
            output += f'\n{obj["Name"]},{obj["age"]},{obj["birthyear"]}'

        with open('output.csv', 'w') as f:
            f.write(output)
    except Exception as ex:
        print(f'Error: {str(ex)}')

2. Password Generator

import random
import string
total = string.ascii_letters + string.digits + string.punctuation
length = 16
password = "".join(random.sample(total, length))
print(password)

Website

Tags: Python Scripts