Re: Autoloader (was Re: CSV Error)

2014-12-28 Thread Chris Angelico
On Mon, Dec 29, 2014 at 3:14 AM, Mark Lawrence wrote: >> Is anyone else interested in the patch? Should I create a tracker >> issue and upload it? > > I'd raise a tracker issue so it's easier to find in the future. http://bugs.python.org/issue23126 ChrisA -- https://mail.python.org/mailman/list

Re: Autoloader (was Re: CSV Error)

2014-12-28 Thread Mark Lawrence
On 28/12/2014 15:38, Chris Angelico wrote: On Mon, Dec 29, 2014 at 1:22 AM, Chris Angelico wrote: I wonder how hard it would be to tinker at the C level and add a __getattr__ style of hook... You know what, it's not that hard. It looks largeish as there are four places where NameError (not co

Re: Autoloader (was Re: CSV Error)

2014-12-28 Thread Chris Angelico
On Mon, Dec 29, 2014 at 2:38 AM, Chris Angelico wrote: > It's just like __getattr__: if it returns something, it's as > if the name pointed to that thing, otherwise it raises NameError. To clarify: The C-level patch has nothing about imports. What it does is add a hook at the point where NameErro

Re: Autoloader (was Re: CSV Error)

2014-12-28 Thread Chris Angelico
On Mon, Dec 29, 2014 at 1:22 AM, Chris Angelico wrote: > I wonder how hard it would be to tinker at the C level and add a > __getattr__ style of hook... You know what, it's not that hard. It looks largeish as there are four places where NameError (not counting UnboundLocalError, which I'm not tou

Re: Autoloader (was Re: CSV Error)

2014-12-28 Thread Chris Angelico
On Mon, Dec 29, 2014 at 1:15 AM, Skip Montanaro wrote: >> We were discussing something along these lines a while ago, and I >> never saw anything truly satisfactory - there's no easy way to handle >> a missing name by returning a value (comparably to __getattr__), you >> have to catch it and then

Re: Autoloader (was Re: CSV Error)

2014-12-28 Thread Skip Montanaro
> We were discussing something along these lines a while ago, and I > never saw anything truly satisfactory - there's no easy way to handle > a missing name by returning a value (comparably to __getattr__), you > have to catch it and then try to re-execute the failing code, which > isn't perfect. H

Autoloader (was Re: CSV Error)

2014-12-28 Thread Chris Angelico
On Mon, Dec 29, 2014 at 12:58 AM, Skip Montanaro wrote: > (Ignore the "autoloading" message. I use an autoloader in interactive > mode which comes in handy when I forget to import a module, as I did > here.) We were discussing something along these lines a while ago, and I never saw anything trul

Re: CSV Error

2014-12-28 Thread Skip Montanaro
Hmmm... Works for me. % python Python 2.7.6+ (2.7:db842f730432, May 9 2014, 23:53:26) [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> with open("coconutBattery.csv", "rb") as f: ... r = csv.DictReader(

Re: CSV Error

2014-12-28 Thread JC
On Sun, 28 Dec 2014 14:41:55 +0200, Jussi Piitulainen wrote: > Skip Montanaro writes: > >> > ValueError: I/O operation on closed file >> > >> > Here is my code in a Python shell - >> > >> > >>> with open('x.csv','rb') as f: >> > ... r = csv.DictReader(f,delimiter=",") >> > >>> r.fieldnames >>

Re: CSV Error

2014-12-28 Thread JC
On Sun, 28 Dec 2014 06:19:58 -0600, Skip Montanaro wrote: >> ValueError: I/O operation on closed file >> >> Here is my code in a Python shell - >> >> >>> with open('x.csv','rb') as f: >> ... r = csv.DictReader(f,delimiter=",") >> >>> r.fieldnames > > The file is only open during the context o

Re: CSV Error

2014-12-28 Thread Jussi Piitulainen
Skip Montanaro writes: > > ValueError: I/O operation on closed file > > > > Here is my code in a Python shell - > > > > >>> with open('x.csv','rb') as f: > > ... r = csv.DictReader(f,delimiter=",") > > >>> r.fieldnames > > The file is only open during the context of the with statement. > Inde

Re: CSV Error

2014-12-28 Thread Skip Montanaro
> ValueError: I/O operation on closed file > > Here is my code in a Python shell - > > >>> with open('x.csv','rb') as f: > ... r = csv.DictReader(f,delimiter=",") > >>> r.fieldnames The file is only open during the context of the with statement. Indent the last line to match the assignment to