A python script to convert JSON data to CSV file

This script will convert your JSON data to a CSV file. It takes .json a file as input and provides .csv the file as output.

Installation

pip install json

Script

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)}')

Thank you for reading this tutorial. Don’t forget to clap 👏 and follow me to read more articles like this in the future.

--

--

A guide on creating and reading QR codes in Python with a working example.

An example is to create and read QR codes using python.

generate.py

import pyqrcode
import png
from PIL import Image
s = "https://python.plainenglish.io/" # url to open after scanning qr code
url = pyqrcode.create(s) # creating qr code
img = "python-in-plain-english.png" # name of image
url.png(img, scale=10) # saving image as png
im=Image.open(img) # opening image
im.show()

read.py

from pyzbar.pyzbar import decode
from PIL import Image
d = decode(Image.open("path-to-qr-code.png"))
# print(d)
print(d[0].data.decode())

Thank you for reading this tutorial. Don’t forget to clap 👏 and follow me to read more articles like this in the future.

--

--

A tutorial on web scraping in Python using BeautifulSoup

An example is to get a webpage title using python and BeautifulSoup.

import os
import requests
from bs4 import BeautifulSoup
url = "https://www.google.com/"
reponse = requests.get(url)
if reponse.ok:
soup = BeautifulSoup(reponse.text, "lxml")
title = str(soup.find("title"))
title = title.replace("<title>", "")
title = title.replace("</title>", "")
print("The title is : " + str(title))
os.system("pause")

Thank you for reading this tutorial. Don’t forget to clap 👏 and follow me to read more articles like this in the future.

--

--

Harendra Verma

Harendra Verma

I have expertise with Python, Javascript, Angular, Node JS, Laravel. @harendraverma21