[Tutor] function for loaning a book
William Ray Wing
wrw at mac.com
Wed Nov 27 11:40:50 EST 2019
> On Nov 27, 2019, at 11:30 AM, samhar zghaier <samharzghaier at gmail.com> wrote:
>
> Ok
> The code doesn't move the file to the loan list
> here is what my text file looks like:
> book of y, sma
> book of d, adam
> book of f, blag
> book of b, sam
>
Ah, OK, now liberally salt your code with print statements and watch what is happening.
>
> On Wed, 27 Nov 2019 at 17:20, William Ray Wing <wrw at mac.com <mailto:wrw at mac.com>> wrote:
>
>
>> On Nov 27, 2019, at 11:06 AM, Sam <samharzghaier at gmail.com <mailto:samharzghaier at gmail.com>> wrote:
>>
>> There is no error, it’s just that it doesn’t work
>>
>
> Please elaborate “doesn’t work.” Does it not run? Does it run and not produce the expected result? Since we don’t have your data files, we can’t see what is happening.
>
>
>> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>>
>> From: William Ray Wing <mailto:wrw at mac.com>
>> Sent: Wednesday, 27 November 2019 17:04
>> To: samhar zghaier <mailto:samharzghaier at gmail.com>
>> Cc: William R. Wing <mailto:wrw at mac.com>; Tutor <mailto:tutor at python.org>
>> Subject: Re: [Tutor] function for loaning a book
>>
>>
>>
>> > On Nov 27, 2019, at 8:56 AM, samhar zghaier <samharzghaier at gmail.com <mailto:samharzghaier at gmail.com>> wrote:
>> >
>> > Hello
>> > I creatred a function to read each of my text files and read them into the
>> > program, im now trying to delete a certain item from one of the two lists i
>> > created and add it to the other one
>> > currently i am not able to add a certain element to the loan list
>>
>> Please copy and paste the entire error message traceback and show us what happens.
>>
>>
>> > This is the code i have currently written
>> >
>> > file_name = "text.txt"
>> > loan_file = "loan.txt"
>> >
>> > class Book():
>> > def __init__(self, title, writer):
>> > self.title = title
>> > self.writer = writer
>> > def get_book_list():
>> > book_list = []
>> > with open(file_name, "r") as file:
>> > lines = file.readlines()
>> > for line in lines:
>> > line = line.split(",")
>> > book_list.append(Book(line[0].strip(), line[1].strip()))
>> > return book_list
>> >
>> > def get_loan_list():
>> > loan_list = []
>> > with open(loan_file, "r") as file:
>> > lines = file.readlines()
>> > for line in lines:
>> > line = line.split(",")
>> > loan_list.append(Book(line[0].strip(), line[1].strip()))
>> > return loan_list
>> >
>> > def loan_book():
>> > book_title = input("What is the name of the book")
>> > info = book_list
>> > for line in info:
>> > if line.title == book_title:
>> > loan_list.append(line)
>> >
>> >
>> > def main():
>> > loan_list = get_loan_list()
>> > book_list = get_book_list()
>> > loan_book()
>> > main()
>> >
>> >
>> > Help please
>> > _______________________________________________
>> > Tutor maillist - Tutor at python.org <mailto:Tutor at python.org>
>> > To unsubscribe or change subscription options:
>> > https://mail.python.org/mailman/listinfo/tutor <https://mail.python.org/mailman/listinfo/tutor>
More information about the Tutor
mailing list