Concept explainers
Hello how would I get save.py reading and saving my text document. I have code for save.py but it doesn't work. Can someone please help fix it so that it will correctly save onto another text document.
import save
def main():
filename = ''
print('-'*45)
choice = ''
while choice.upper() !='Q':
print()
if filename != '': print('Current file opened:', filename)
print('0) Choose a file to open\t5) Save Song Playlist')
print('Q) Quit')
choice=input('Enter a choice: ')
if choice == '0':
print()
filename = input('Enter file name: ')
rfile =open(filename,'r')
line_list =rfile.read()
for word in line_list:
words_list=word.split(' ')
print(line_list)
print(f"File {filename} opened.")
elif choice == '5':
print()
save.save_playlist(filename)
elif choice.upper() == 'Q':
print("
else:
print('Invalid choice.')
main()
contents of imported save.py
def save_playlist(filename):
words_list = []
line_list -[]
savefilename =input('Enter save file name:')
savefile=open(savefilename,'w')
for index in range(len(line_list)):
line_list[index] =line_list[index].rstrip('\n')
print(line_list)
for word in line_list:
words_list=word.split(' ')
line_list.sort()
for item in line_list:
savefile.write(item + '\n')
savefile.close()
contents of start.txt text document
Alternative
Bastille
Pompeii
3:34
Happier
3:34
Of The Night
3:33
Panic! At The Disco
I Write Sins Not Tragedies
3:06
Nine in the Afternoon
3:11
High Hopes
3:10
Blues
Tab Benoit
Nothing Takes The Place Of You
4:01
For What It's Worth
5:17
Shelter Me
5:05
Joe Bonamassa
I'll Take Care Of You
5:41
The Heart That Never Waits
5:51
Notches
7:04
Robert Cray
Right Next Door (Because of Me)
4:21
Smoking Gun
4:05
This Man
5:06
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images
- For main.CPP file in lines 32 and 33 on visual studio community 2022 it's saying that getline is unidentified why is that and how do i fix it.arrow_forwardpythonarrow_forwardCreate a new file cart.html You must get and set the data on the web page by using document.getElementById( ). Each HTML element on the web page already has an id so it is easy. No need for a loop to go through the list of products, there is only 2 products and the info is hard coded on the web page. You must write the code for function cartTotal().arrow_forward
- this is my code so far but it its not accurate, not sure if i should def function and then for loop? import csv with open ('TopUni.csv', mode='r') as csv_file: csvReader = csv.reader(csv_file) line = [] for line in csvReader: sum(line) print(line)arrow_forwardplease do fast i will give you thumbs uparrow_forwardhelp me rewrite the code without using bufferReader pleasearrow_forward
- Bash shellarrow_forwardLab Tasks – complete these Use the information provided here, in the slideshow and in chapter 12 of our text to do the following exercise. Step 1: On the desktop or wherever you will be saving your java program, use notepador other basic text editor (NOT WORD) to create a .txt file. In this file, type out a list of 10 integers (one on each line or with a space between each). Save. Do this manually. Not with Java. Step 2. Now write a program with the following: 1) In the program creating a File object that connects to the .txt file that you just created. 2) Add code that will check if the file exists and if it doesn’t, it will create it. (Yes, we know it definitely exists but do this part anyway.) 3) Set up a Scanner so that you can read the values from the file and print them to the screen using a loop. You will probably need to use the .hasNext() method. Also, you may want to set up a counter to keep track of how many values there are for future use. (Note that the .length()…arrow_forwardOutput should be 5. Please help me find my error, and create 5 tests below in a seperate file using the corrected code. Thanks. 1. create a strawberryStand object2. create one or more MenuItem objects and add them to the strawberryStand's menu3. create a dictionary of sales for the day that includes sales of at least one item that isn't in the menu4. try calling enter_sales_for_today(), passing that sales dictionary as the argument5. If an InvalidSalesItem is raised, it should be caught with a try/except that prints an explanatory message for the user (otherwise the function should proceed normally). class MenuItem: def __init__(self, name, wholesale_cost, selling_price): self.name = name self.wholesale_cost = wholesale_cost self.selling_price = selling_price def get_name(self): return self.name def get_wholesale_cost(self): return self.wholesale_cost def get_selling_price(self): return self.selling_price class SalesForDay:…arrow_forward
- Which of the following reads an image from a file? Group of answer choices a) imshow b) imread c) image d) readmatrixarrow_forwardIn Python, which of the following opens read_it.txt for writing or reading data text_file variable. a. text_file = open("read_it.txt", "wr") b. text_file = open("read_it.txt", "rw") c. text_file = open("read_it.txt", "aw") d. text_file = open("read_it.txt", "w+") which one is correct?arrow_forwardCould you add lists or dictionaries to my code to manage the data the user entered!? Also, if you can make the code look better, please change it. Thanks!arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education