diff --git a/CSV_to_JSON/README.md b/CSV_to_JSON/README.md index 4b195bf..7d1bd1c 100644 --- a/CSV_to_JSON/README.md +++ b/CSV_to_JSON/README.md @@ -6,14 +6,14 @@ Make sure you have python 3 or higher, that's it. ## Files before
-![before](https://github.com/TechBoyy6/Python-scripts-collection/blob/master/CSV_to_JSON/img/before.jpg)
+![before](https://github.com/fnplus/Python-scripts-collection/blob/master/CSV_to_JSON/img/before.jpg?raw=true)
## CLI interface -![image](https://github.com/TechBoyy6/Python-scripts-collection/blob/master/CSV_to_JSON/img/CLI.jpg) +![image](https://github.com/fnplus/Python-scripts-collection/blob/master/CSV_to_JSON/img/CLI.jpg?raw=true) ## Files After
-![after](https://github.com/TechBoyy6/Python-scripts-collection/blob/master/CSV_to_JSON/img/after.jpg) +![after](https://github.com/fnplus/Python-scripts-collection/blob/master/CSV_to_JSON/img/after.jpg?raw=true) ## Contact diff --git a/CSV_to_JSON/csv_to_json.py b/CSV_to_JSON/csv_to_json.py index 69cb35e..207d98a 100644 --- a/CSV_to_JSON/csv_to_json.py +++ b/CSV_to_JSON/csv_to_json.py @@ -1,29 +1,20 @@ import csv import json -file_name = input("Provide the CSV filename without extension>> ") +file_name = input("Provide the CSV filename : ") +if not file_name.strip().endswith(".csv"): + file_name += ".csv" -with open(file_name + '.csv') as f: +with open(file_name) as f: + reader = csv.reader(f, delimiter=",") - reader = csv.reader(f, delimiter=',') - - titles = [] - temp_data = {} - - for heading in reader: - titles = heading - break - - i = 1 + titles = next(reader) + temp_data = [] for row in reader: - current_row = "row{}".format(i) - temp_data['{}'.format(current_row)] = {} - for col in range(len(titles)): - temp_data[current_row][titles[col]] = row[col] - i += 1 + temp_data.append({col: val for col, val in zip(titles, row)}) -with open(file_name + '.json', 'w') as f_j: +with open(file_name.strip()[:-4] + ".json", "w") as f_j: json.dump(temp_data, f_j, indent=4) print("File converted successfully :)\n") \ No newline at end of file diff --git a/FindIPAddress/FindIPAddress.py b/FindIPAddress/FindIPAddress.py index 4171f9c..552cd1d 100644 --- a/FindIPAddress/FindIPAddress.py +++ b/FindIPAddress/FindIPAddress.py @@ -1,5 +1,7 @@ import socket -hostname = socket.gethostname() -IPAddr = socket.gethostbyname(hostname) -print("Your Computer Name is:" + hostname) -print("\nYour Computer IP Address is:" + IPAddr) \ No newline at end of file + +HostName = socket.gethostname() +IPAddr = socket.gethostbyname(HostName) + +print(f"Your Computer Name is: {HostName}\n") +print(f"Your Computer IP Address is: {IPAddr}") \ No newline at end of file