Re: Finding non ascii characters in a set of files

2007-02-24 Thread Toby A Inkster
bg_ie wrote: > What I'd like to do is scan a directory and list all the > files in it that contain a non ascii character. Not quite sure what your intention is. If you're planning a one-time scan of a directory for non-ASCII characters in files, so that you can manually fix those files up, then t

Re: Finding non ascii characters in a set of files

2007-02-23 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > I'm updating my program to Python 2.5, but I keep running into > encoding problems. I have no ecodings defined at the start of any of > my scripts. What I'd like to do is scan a directory and list all the > files in it that contain a non ascii character. How would I go ab

Re: Finding non ascii characters in a set of files

2007-02-23 Thread Tim Arnold
"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > In <[EMAIL PROTECTED]>, Tim Arnold wrote: > >> Here's what I do (I need to know the line number). >> >> import os,sys,codecs >> def checkfile(filename): >> f = codecs.open(filename,encoding='ascii') >> >>

Re: Finding non ascii characters in a set of files

2007-02-23 Thread Martin v. Löwis
Tim Arnold schrieb: > That looks much cleaner. I didn't know the 'num' from the enumerate would > persist so the except block could report it. It's indeed guaranteed that the for loop index variables will keep the value they had when the loop stopped (either through regular termination, break, or

Re: Finding non ascii characters in a set of files

2007-02-23 Thread Tim Arnold
"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > In <[EMAIL PROTECTED]>, Tim Arnold wrote: > > Untested: > > import os, sys, codecs > > def checkfile(filename): >f = codecs.open(filename,encoding='ascii') > >try: >for num, line in enu

Re: Finding non ascii characters in a set of files

2007-02-23 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Tim Arnold wrote: > Here's what I do (I need to know the line number). > > import os,sys,codecs > def checkfile(filename): > f = codecs.open(filename,encoding='ascii') > > lines = open(filename).readlines() > print 'Total lines: %d' % len(lines) > for i in

Re: Finding non ascii characters in a set of files

2007-02-23 Thread Tim Arnold
"Peter Bengtsson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Feb 23, 2:38 pm, [EMAIL PROTECTED] wrote: >> Hi, >> >> I'm updating my program to Python 2.5, but I keep running into >> encoding problems. I have no ecodings defined at the start of any of >> my scripts. What I'd l

Re: Finding non ascii characters in a set of files

2007-02-23 Thread John Machin
On Feb 24, 2:44 am, Larry Bates <[EMAIL PROTECTED]> wrote: > Peter Bengtsson wrote: > > On Feb 23, 2:38 pm, [EMAIL PROTECTED] wrote: > >> Hi, > > >> I'm updating my program to Python 2.5, but I keep running into > >> encoding problems. I have no ecodings defined at the start of any of > >> my scrip

Re: Finding non ascii characters in a set of files

2007-02-23 Thread John Machin
On Feb 24, 2:35 am, "John Machin" <[EMAIL PROTECTED]> wrote: > On Feb 24, 2:12 am, "Peter Bengtsson" <[EMAIL PROTECTED]> wrote: > > > On Feb 23, 2:38 pm, [EMAIL PROTECTED] wrote: > > > > Hi, > > > > I'm updating my program to Python 2.5, but I keep running into > > > encoding problems. I have no ec

Re: Finding non ascii characters in a set of files

2007-02-23 Thread Larry Bates
Peter Bengtsson wrote: > On Feb 23, 2:38 pm, [EMAIL PROTECTED] wrote: >> Hi, >> >> I'm updating my program to Python 2.5, but I keep running into >> encoding problems. I have no ecodings defined at the start of any of >> my scripts. What I'd like to do is scan a directory and list all the >> files

Re: Finding non ascii characters in a set of files

2007-02-23 Thread John Machin
On Feb 24, 2:12 am, "Peter Bengtsson" <[EMAIL PROTECTED]> wrote: > On Feb 23, 2:38 pm, [EMAIL PROTECTED] wrote: > > > Hi, > > > I'm updating my program to Python 2.5, but I keep running into > > encoding problems. I have no ecodings defined at the start of any of > > my scripts. What I'd like to do

Re: Finding non ascii characters in a set of files

2007-02-23 Thread Peter Bengtsson
On Feb 23, 2:38 pm, [EMAIL PROTECTED] wrote: > Hi, > > I'm updating my program to Python 2.5, but I keep running into > encoding problems. I have no ecodings defined at the start of any of > my scripts. What I'd like to do is scan a directory and list all the > files in it that contain a non ascii

Finding non ascii characters in a set of files

2007-02-23 Thread bg_ie
Hi, I'm updating my program to Python 2.5, but I keep running into encoding problems. I have no ecodings defined at the start of any of my scripts. What I'd like to do is scan a directory and list all the files in it that contain a non ascii character. How would I go about doing this? Thanks, Ba