Re: question about file handling with "with"

2012-03-29 Thread Nobody
On Wed, 28 Mar 2012 11:31:21 +0200, Jabba Laci wrote: > Is the following function correct? Is the input file closed in order? > > def read_data_file(self): > with open(self.data_file) as f: > return json.loads(f.read()) Yes. The whole point of being able to use a file as a context m

Re: Difference between json.load() and json.loads() [From: RE: question about file handling with "with"]

2012-03-28 Thread Nadir Sampaoli
2012/3/28 ian douglas > > The functions with an s take string parameters. The others take file > streams. > > foo = '{"age": 38}' > my_json = json.loads(foo) > I see, it makes perfectly sense now. Thanks for clearing it up. -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference between json.load() and json.loads() [From: RE: question about file handling with "with"]

2012-03-28 Thread ian douglas
On Mar 28, 2012 6:54 AM, "Nadir Sampaoli" wrote: > > Hello everyone (my first message in the mailing list), > >> >> > Is the following function correct? >> Yes, though I'd use json.load(f) instead of json.loads(). > > > The docs aren't very clear (at least for me) about the difference between json

Difference between json.load() and json.loads() [From: RE: question about file handling with "with"]

2012-03-28 Thread Nadir Sampaoli
Hello everyone (my first message in the mailing list), > > Is the following function correct? > Yes, though I'd use json.load(f) instead of json.loads(). > The docs aren't very clear (at least for me) about the difference between json.load()

Re: question about file handling with "with"

2012-03-28 Thread Peter Otten
Jabba Laci wrote: > Is the following function correct? Yes, though I'd use json.load(f) instead of json.loads(). > Is the input file closed in order? > > def read_data_file(self): > with open(self.data_file) as f: > return json.loads(f.read()) The file will be closed when the wit

question about file handling with "with"

2012-03-28 Thread Jabba Laci
Hi, Is the following function correct? Is the input file closed in order? def read_data_file(self): with open(self.data_file) as f: return json.loads(f.read()) Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list