Aug-13-2018, 05:36 PM
(Aug-13-2018, 04:14 PM)gwilli3 Wrote: The structure of the dictionary is: boarders[brdr_year][brdr_month][brdr_day]{pet_name}
I am a bit confused. So when a client come in and checks in a pet. You want to manually add the pets info: brdr_year, brdr_month, brdr_day and the pets name to a text file? Then, given that text file information you want to generate a dictionary called "boarders" so that you can update some kind of calendar script you have built?
In general, I would suggest not over-complicating the issue with pathlib. Also, are you on a Windows PC or a Linux based distro?
In general, to keep things simple keep the text file in the same directory as the script then:
file = "output.txt" with open(file, 'r') as input: content = input.read() print(content)It is important to keep in mind (deppending on your needs) there are multiple ways of reading in lines:
output for read():
Output:This is the content of the first sentence. This is the content of the second sentence.
This is the content of the second line.
As you can see this gives the entirety of the text files contents as one long string.output for readline():
Output:This is the content of the first sentence. This is the content of the second sentence.
Similar to read() you are returned a string but it goes line by line.output for readlines():
Output:['This is the content of the first sentence. This is the content of the second sentence.\n', 'This is the content of the second line.\n']
Similar to read() in that it gives you the entirety of the text files content; however, now you are returned a list.That being said, when it comes to converting these contents into dictionaries the obvious choice for which to use in my mind would be readlines().