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 fo

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 n

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 to

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

2018-08-07 Thread Rafael Knuth
> You forgot the parentheses (), and are returning a reference to the > function instead of calling it and returning its result. Do this: > contents = file_object.read() oh, my bad. Thanks! > Also, consider using snake_case instead of PascalCase for your > function name, since the latter

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 > > print(FilePrinter("C:\\Users\\...\\

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 err

[Tutor] How to write a function which reads files

2018-08-07 Thread Rafael Knuth
Hi there, I got this here: file_path = "C:\\Users\\...\\MyFile.txt" # path shortened for better readability with open(file_path) as file_object: contents = file_object.read() print(contents) It works. Now I want to convert the code above into a function. This is what I wrote: def FileR

Re: [Tutor] how to write a function

2008-03-24 Thread Marc Tompkins
On Mon, Mar 24, 2008 at 6:28 AM, Bartruff, Pamela J. < [EMAIL PROTECTED]> wrote: > Def convert_time(time): > """split hours from minutes" > Time = raw_input("enter a time, in military: ") > At this point, Time is a string, not a number. (At this point, we also have to _assume_ that the user ente

Re: [Tutor] how to write a function

2008-03-24 Thread Bartruff, Pamela J.
Thank you so much. I appreciate the help, I am very new to Python, but I would very much like to learn more... -Original Message- From: bhaaluu [mailto:[EMAIL PROTECTED] Sent: Monday, March 24, 2008 9:17 AM To: Bartruff, Pamela J. Cc: tutor@python.org Subject: Re: [Tutor] how to write a

Re: [Tutor] how to write a function

2008-03-24 Thread bhaaluu
On Mon, Mar 24, 2008 at 8:07 AM, Bartruff, Pamela J. <[EMAIL PROTECTED]> wrote: > > Hello Python users, > > I am very new to Python, how do I program that converts 24 hour time to 12 > hour time? The program should have three functions(input, conversion and > output function) > > Thanks for any he

Re: [Tutor] how to write a function

2008-03-24 Thread Bartruff, Pamela J.
m." -Original Message- From: Kent Johnson [mailto:[EMAIL PROTECTED] Sent: Monday, March 24, 2008 8:07 AM To: Bartruff, Pamela J. Cc: tutor@python.org Subject: Re: [Tutor] how to write a function Bartruff, Pamela J. wrote: > Hello Python users, > > I am very new to Pyth

Re: [Tutor] how to write a function

2008-03-24 Thread Kent Johnson
Bartruff, Pamela J. wrote: > Hello Python users, > > I am very new to Python, how do I program that converts 24 hour time to > 12 hour time? The program should have three functions(input, conversion > and output function) This sounds like a homework assignment. We will help with homework but

[Tutor] how to write a function

2008-03-24 Thread Bartruff, Pamela J.
Hello Python users, I am very new to Python, how do I program that converts 24 hour time to 12 hour time? The program should have three functions(input, conversion and output function) Thanks for any help Pamela Bartruff ___ Tutor maillist -