Re: [Tutor] How to write a function which reads files

2018-08-08 Thread boB Stepp
On Wed, Aug 8, 2018 at 8:30 PM boB Stepp wrote: > > On Tue, Aug 7, 2018 at 9:13 AM Rafael Knuth wrote: Curses! Sorry, Chris! This should be: > > Chris Warrick wrote: > > > Also, consider using snake_case instead of PascalCase for your > > > function name, since the latter is typically used

Re: [Tutor] How to write a function which reads files

2018-08-08 Thread boB Stepp
On Tue, Aug 7, 2018 at 9:13 AM Rafael Knuth wrote: > Alan Gauld wrote: > > Also, consider using snake_case instead of PascalCase for your > > function name, since the latter is typically used for classes, and > > perhaps call it read_file to better describe it? > > thanks, I wasn't aware of the

Re: [Tutor] How to write a function which reads files

2018-08-07 Thread Mats Wichmann
Question is already answered, just wanted to add a mini-note. def FileReader(file_path):with open(file_path) as file_object: contents = file_object.readreturn contents you /can/ return the read method here, which is what this typo does. And the caller of the function can use it

Re: [Tutor] How to write a function which reads files

2018-08-07 Thread Alan Gauld via Tutor
On 07/08/18 13:46, Rafael Knuth wrote: > Now I want to convert the code above into a function. > This is what I wrote: > > def FileReader(file_path): > with open(file_path) as file_object: > contents = file_object.read > return contents > >

Re: [Tutor] How to write a function which reads files

2018-08-07 Thread Chris Warrick
On Tue, 7 Aug 2018 at 15:07, Rafael Knuth wrote: > def FileReader(file_path): > with open(file_path) as file_object: > contents = file_object.read > return contents > > print(FilePrinter("C:\\Users\\...\\MyFile.txt")) # path shortened for > better readability > > I got this