Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

shapes = [{'type': 'circle', 'x': 300, 'y': 300, 'radius': 100, 'color': 'cyan'},
{'type': 'circle', 'x': 300, 'y': 300, 'radius': 10, 'color': 'white'},
{'type': 'rectangle', 'x1': 500, 'y1': 500, 'x2': 550, 'y2': 580, 'color': 'green'},
{'type': 'line', 'x': 0, 'y': 0, 'a': 100, 'b': 300, 'color': "black", 'width': 7},
{'type': 'point', 'x': 200, 'y': 50, 'color': 'black'},
{'type': 'point', 'x': 205, 'y': 50, 'color': 'black'},
{'type': 'point', 'x': 210, 'y': 50, 'color': 'black'},
{'type': 'triangle', 'x': 500, 'y': 100, 'a': 600, 'b': 100, 'c': 550, 'd': 200, 'color': 'yellow'},
{'type': 'oval', 'x': 100, 'y': 100, 'a': 400, 'b': 400, 'color': 'red'},
{'type': 'text', 'x': 500, 'y': 50, 'message': 'hello world!', 'color': 'blue'}
]

I'd like to take this list and write it to a new txt file. Ignoring the ':' , {}, and words within quotation marks. so the txt file created would look like this: 


circle, 300,300, 100, cyan
circle, 300,300, 10, white
rectangle, 500,500, 550,580, green
line, 0,0, 100,300, black, 7
point, 200,50,black
point, 205,50,black
point, 210,50,black
triangle, 500,100, 600,100, 550,200, yellow
image, 150,500, cedar_rapids.ppm
oval, 100,100, 400,200, red
text, 500,50, hello world!, blue

what i have so far is:

s_shapes = ['{}\n'.format(i) for i in shapes]
textFileName = input("Save as: ")
with open(textFileName, "w") as fp:
fp.writelines(s_shapes)
fp.close()

it prints my list in the txt file, but doesnt get rid of the words in quotations, the :  or the {}. 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education