Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

CSV formatted string and returns the corresponding JSON format string Python

new here and having issues! Course I'm taking is asking for me to convert a CSV string to JSON formatted string. I created inputs and created a CSV string:

def get_book_info():

title = str(input("enter book title:    ").strip())
isbn = str(input("enter book ISBN:    ").strip())
author = str(input("enter author last name:    ").strip())
publisher = str(input("enter the book publisher:    ").strip())
published = str(input("enter the year published:    "))
price = "%.2f" % float(input("enter price:    "))
price_book = str(price)
output = [title.title(),isbn,author.capitalize(),publisher.title(),published,price_book]
separator = "/"
info = separator.join(output)
return info



def to_csv_format(info):
   title,isbn,author,publisher,published,price_book = info.split("/")
   csv = f"{title},{isbn},{author},{publisher},{published},{price_book}"
   print("The CSV Format String:")
   print(csv)
   return csv

Now, I need to help to create a JSON string using the CSV string. It's also asking me to use find(), string slicing and string concatenation for functionality. I see online help using import csv and import json but the problem is saying I can use find(), slicing and concatenation.

Thanks for your help!!

question from:https://stackoverflow.com/questions/65863210/csv-formatted-string-and-returns-the-corresponding-json-format-string-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...