Re: New to PSF

2014-12-28 Thread prateek pandey
Yeah, I mean Python Software Foundation. I am a developer and I'm want to contribute. So, Can you please help me in getting started ? Thanks On Sunday, December 28, 2014 4:27:54 AM UTC+5:30, Steven D'Aprano wrote: > prateek pandey wrote: > > > Hey, I'm new to PSF. Can someone please help me in

Re: New to PSF

2014-12-28 Thread prateek pandey
Yeah, I mean Python Software Foundation. I am a developer and I want to contribute. So, Can you please help me in getting started ? Thanks On Sunday, December 28, 2014 4:27:54 AM UTC+5:30, Steven D'Aprano wrote: > prateek pandey wrote: > > > Hey, I'm new to PSF. Can someone please help me in g

Re: New to PSF

2014-12-28 Thread Michiel Overtoom
On Dec 28, 2014, at 09:54, prateek pandey wrote: > Yeah, I mean Python Software Foundation. I am a developer and I want to > contribute. So, Can you please help me in getting started ? https://www.python.org/psf/volunteer/ -- "You can't actually make computers run faster, you can only make t

CSV Error

2014-12-28 Thread JC
Hello, I am trying to read a csv file using DictReader. I am getting error - Traceback (most recent call last): File "", line 1, in r.fieldnames File "/usr/lib/python2.7/csv.py", line 90, in fieldnames self._fieldnames = self.reader.next() ValueError: I/O operation on closed file He

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

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 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 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 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(

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: 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

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 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 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 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 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

Searching through more than one file.

2014-12-28 Thread Seymore4Head
I need to search through a directory of text files for a string. Here is a short program I made in the past to search through a single text file for a line of text. How can I modify the code to search through a directory of files that have different filenames, but the same extension? fname = raw_

Re: Searching through more than one file.

2014-12-28 Thread Mark Lawrence
On 28/12/2014 17:27, Seymore4Head wrote: I need to search through a directory of text files for a string. Here is a short program I made in the past to search through a single text file for a line of text. How can I modify the code to search through a directory of files that have different filen

Re: Searching through more than one file.

2014-12-28 Thread Paul Rubin
Seymore4Head writes: > How can I modify the code to search through a directory of files that > have different filenames, but the same extension? Use the os.listdir function to read the directory. It gives you a list of filenames that you can filter for the extension you want. Per Mark Lawrence,

Re: Searching through more than one file.

2014-12-28 Thread Dave Angel
On 12/28/2014 12:27 PM, Seymore4Head wrote: I need to search through a directory of text files for a string. Here is a short program I made in the past to search through a single text file for a line of text. How can I modify the code to search through a directory of files that have different fi

Re: Searching through more than one file.

2014-12-28 Thread Dave Angel
On 12/28/2014 02:12 PM, Dave Angel wrote: On 12/28/2014 12:27 PM, Seymore4Head wrote: I need to search through a directory of text files for a string. Here is a short program I made in the past to search through a single text file for a line of text. How can I modify the code to search through

Re: Searching through more than one file.

2014-12-28 Thread Paul Rubin
Dave Angel writes: > res = set() > fnames = glob('*.txt') > for line in fileinput.input(fnames): > res.update(line.rstrip().split()) > print sorted(res) Untested: print sorted(set(line.rstrip().split() for line in fileinput(fnames))) -- https://mail.python.org/mailman/listinfo/python-list

Re: Searching through more than one file.

2014-12-28 Thread Terry Reedy
On 12/28/2014 12:27 PM, Seymore4Head wrote: I need to search through a directory of text files for a string. Here is a short program I made in the past to search through a single text file for a line of text. How can I modify the code to search through a directory of files that have different fi

Re: suggestions for VIN parsing

2014-12-28 Thread Vincent Davis
On Fri, Dec 26, 2014 at 12:15 PM, Denis McMahon wrote: > Note, I think the 1981 model year ran KCA - DCA prefixes, not as shown on > the website you quoted. > ​Denis, Regarding the KCA - DCA prefixes, do you have a source as to why you think this? Here is what I have so far with a simple test a

Re: suggestions for VIN parsing

2014-12-28 Thread Rick Johnson
On Sunday, December 28, 2014 5:34:11 PM UTC-6, Vincent Davis wrote: > > [snip: code sample with Unicode spaces! Yes, *UNICODE SPACES*!] Oh my! Might i offer some suggestions to improve the readability of this code? 1. Indexing is syntactically noisy, so if you find yourself fetching the same in

Re: suggestions for VIN parsing

2014-12-28 Thread Rick Johnson
On Monday, December 29, 2014 12:50:39 AM UTC-6, Rick Johnson wrote: [EDIT] > 3. Now you can write some fairly simple logic. > > prog = re.compile("pat1|pat2|pat3...") > def parse_vin(vin): > match = prog.search(vin) > if match: > gname = # Fetch the groupname

Re: Searching through more than one file.

2014-12-28 Thread Rick Johnson
On Sunday, December 28, 2014 11:29:48 AM UTC-6, Seymore4Head wrote: > I need to search through a directory of text files for a string. > Here is a short program I made in the past to search through a single > text file for a line of text. Step1: Search through a single file. # Just a few more bru