Re: Reading a file in IDLE 3 on Mac-Lion

2012-09-23 Thread Kevin Walzer
On 9/23/12 8:45 AM, Kevin Walzer wrote: There's nothing to do here; it's an aspect of the native dialog. To clarify: there's nothing to do at the C level, which is where the native dialog is invoked. IDLE can probably be patched to accept other file types, such as "dat." -- Kevin Walzer Cod

Re: Reading a file in IDLE 3 on Mac-Lion

2012-09-23 Thread Kevin Walzer
On 9/23/12 3:33 AM, Ned Deily wrote: This appears to a difference in behavior between Carbon Tk 8.4 and Cocoa Tk 8.5 on OS X. The python.org 32-bit-only installers are built to link with the former and, with 8.4, the Open file dialog box does have the file-type filter menu as Hans describes. Th

Re: Reading a file in IDLE 3 on Mac-Lion

2012-09-23 Thread Ned Deily
In article <505d9cc5$0$6846$e4fe5...@news2.news.xs4all.nl>, Hans Mulder wrote: > On 22/09/12 09:30:57, Franck Ditter wrote: > > In article <505ccdc5$0$6919$e4fe5...@news2.news.xs4all.nl>, > > Hans Mulder wrote: > >> On 21/09/12 16:29:55, Franck Ditter wrote: > >>> I create a text file utf-8 enc

Re: Reading a file in IDLE 3 on Mac-Lion

2012-09-22 Thread Hans Mulder
On 22/09/12 09:30:57, Franck Ditter wrote: > In article <505ccdc5$0$6919$e4fe5...@news2.news.xs4all.nl>, > Hans Mulder wrote: > >> On 21/09/12 16:29:55, Franck Ditter wrote: >>> I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). >>> It runs fine and creates the disk file, visib

Re: Reading a file in IDLE 3 on Mac-Lion

2012-09-22 Thread Franck Ditter
In article <505ccdc5$0$6919$e4fe5...@news2.news.xs4all.nl>, Hans Mulder wrote: > On 21/09/12 16:29:55, Franck Ditter wrote: > > I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). > > It runs fine and creates the disk file, visible with > > TextWrangler or another. > > But I can

Re: Reading a file in IDLE 3 on Mac-Lion

2012-09-21 Thread Hans Mulder
On 21/09/12 16:29:55, Franck Ditter wrote: > I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). > It runs fine and creates the disk file, visible with > TextWrangler or another. > But I can't open it with IDLE (its name is greyed). > IDLE is supposed to read utf-8 files, no ? > Th

Re: Reading a file into a data structure....

2011-10-16 Thread Ian Kelly
On Sat, Oct 15, 2011 at 8:18 PM, MrPink wrote: > I did not understand what a tuple was. > So it was very hard for me to understand what a namedtuple was and > follow the code. > Then I looked up the word at dictionary.com and got this: > http://dictionary.reference.com/browse/tuple > > tuple:  com

Re: Reading a file into a data structure....

2011-10-15 Thread MrPink
I did not understand what a tuple was. So it was very hard for me to understand what a namedtuple was and follow the code. Then I looked up the word at dictionary.com and got this: http://dictionary.reference.com/browse/tuple tuple: computing a row of values in a relational database Now I under

Re: Reading a file into a data structure....

2011-10-15 Thread Troy S
Chris, Thanks for the help. I am using the powerball numbers from this text file downloaded from the site. http://www.powerball.com/powerball/winnums-text.txt The first row is the header/fieldnames and the file starts off like this: Draw Date WB1 WB2 WB3 WB4 WB5 PB PP 10/12/2011 43 10 12 23

Re: Reading a file into a data structure....

2011-10-14 Thread Chris Rebert
On Fri, Oct 14, 2011 at 7:59 PM, MrPink wrote: > This is what I have been able to accomplish: > > def isInt(s): >    try: >        i = int(s) >        return True >    except ValueError: >        return False > > f = open("powerball.txt", "r") > lines = f.readlines() > f.close() > > dDrawings = {}

Re: Reading a file into a data structure....

2011-10-14 Thread Chris Angelico
On Sat, Oct 15, 2011 at 1:59 PM, MrPink wrote: > def isInt(s): >    try: >        i = int(s) >        return True >    except ValueError: >        return False > > f = open("powerball.txt", "r") > lines = f.readlines() > f.close() > > dDrawings = {} > for line in lines: >    if isInt(line[0]): >  

Re: Reading a file into a data structure....

2011-10-14 Thread MrPink
This is what I have been able to accomplish: def isInt(s): try: i = int(s) return True except ValueError: return False f = open("powerball.txt", "r") lines = f.readlines() f.close() dDrawings = {} for line in lines: if isInt(line[0]): t = line.split()

Re: Reading a file into a data structure....

2011-10-13 Thread Jon Clements
On Oct 13, 10:59 pm, MrPink wrote: > This is a continuing to a post I made in > August:http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > I got some free time to work with Python again and have some followup > questions. > > For example, I have a list in a text file like

Re: Reading a file into a data structure....

2011-10-13 Thread Ian Kelly
On Thu, Oct 13, 2011 at 3:59 PM, MrPink wrote: > This is a continuing to a post I made in August: > http://groups.google.com/group/comp.lang.python/browse_thread/thread/b072cfadf998deae/ce6d4d09911e4107?lnk=gst&q=MrPink#ce6d4d09911e4107 > > I got some free time to work with Python again and have s

Re: Reading a file that is changing and getting the new lines

2009-12-03 Thread r0g
Ouray Viney wrote: > Hi: > > Problem: > = > I want to read a ASCII text file that can have data appended to it. I > have hacked some code together that handles the basics, but it falls > short. My code doesn't read in the new lines that could have been > added to the end of the file. No

Re: Reading a file that is changing and getting the new lines

2009-12-01 Thread Dave Angel
Ouray Viney wrote: Hi: Problem: = I want to read a ASCII text file that can have data appended to it. I have hacked some code together that handles the basics, but it falls short. My code doesn't read in the new lines that could have been added to the end of the file. Not python's fau

Re: Reading a file that is changing and getting the new lines

2009-12-01 Thread Sean DiZazzo
On Dec 1, 3:09 pm, Ouray Viney wrote: > Problem: > = > I want to read a ASCII text file that can have data appended to it. > > Example scenario:  As the python script is running a user/application > adds new entries to the end of the test case file, example, adds the > following to the fi

Re: Reading a file

2009-03-05 Thread John Machin
On Mar 6, 1:28 am, MRAB wrote: > Aahz wrote: > > In article , > > Terry Reedy   wrote: > >> for line in open('char.txt'): > >>   if line.find('sweet') != -1 or line.find('blue') != -1: > >>     print(line) > > > For any recent Python, this should be: > > >     if 'sweet' in line or 'blue' in line:

Re: Reading a file

2009-03-05 Thread MRAB
Aahz wrote: In article , Terry Reedy wrote: for line in open('char.txt'): if line.find('sweet') != -1 or line.find('blue') != -1: print(line) For any recent Python, this should be: if 'sweet' in line or 'blue' in line: Although I think that for the OP's use case, it ought to be:

Re: Reading a file

2009-03-04 Thread Aahz
In article , Terry Reedy wrote: > >for line in open('char.txt'): > if line.find('sweet') != -1 or line.find('blue') != -1: > print(line) For any recent Python, this should be: if 'sweet' in line or 'blue' in line: Although I think that for the OP's use case, it ought to be: if l

Re: Reading a file

2009-02-15 Thread zaheer . agadi
On Feb 15, 10:27 am, Steven D'Aprano wrote: > Philipp Pagel wrote: > > zaheer.ag...@gmail.com wrote: > >> Hi > > >> How do i read  a file in Python and search a particular pattern > >> like I have a file char.txt  which has > > >> Mango=sweet > >> Sky=blue > > >> I want to get the strings sweet an

Re: Reading a file

2009-02-14 Thread Steven D'Aprano
Philipp Pagel wrote: > zaheer.ag...@gmail.com wrote: >> Hi > >> How do i read a file in Python and search a particular pattern >> like I have a file char.txt which has > >> Mango=sweet >> Sky=blue > >> I want to get the strings sweet and blue,How to do this..? > > If your entire file consist

Re: Reading a file

2009-02-14 Thread Philipp Pagel
zaheer.ag...@gmail.com wrote: > Hi > How do i read a file in Python and search a particular pattern > like I have a file char.txt which has > Mango=sweet > Sky=blue > I want to get the strings sweet and blue,How to do this..? If your entire file consists of such key=value pairs you may want t

Re: Reading a file

2009-02-14 Thread Terry Reedy
zaheer.ag...@gmail.com wrote: Hi How do i read a file in Python and search a particular pattern like I have a file char.txt which has Mango=sweet Sky=blue I want to get the strings sweet and blue,How to do this..? for line in open('char.txt'): if line.find('sweet') != -1 or line.find('bl

Re: Reading a file

2008-07-24 Thread Gary Herron
aditya shukla wrote: I have a text file whose contents are like this:- jd|fj|dnv|jd|0.33|c:\\windows\\win32 shcbsbs|nscsjsj|0.93|hsbcjsnc I am trying to read the file like this:- >>> x = open("c:\\a.txt","r") Better to use "rb" (for binary read) rather than "r" mode. >>> x.read() Now, te

Re: Reading a file

2008-07-24 Thread Fredrik Lundh
aditya shukla wrote: I have a text file whose contents are like this:- jd|fj|dnv|jd|0.33|c:\\windows\\win32 shcbsbs|nscsjsj|0.93|hsbcjsnc I am trying to read the file like this:- >>> x = open("c:\\a.txt","r") >>> x.read() eh, wouldn't it be easier if you actually read the replies to your

Re: Reading a file and resuming reading.

2007-05-26 Thread Hendrik van Rooyen
"Karim Ali" wrote: > Hi, > > Simple question. Is it possible in python to write code of the type: > > - > while not eof <- really want the EOF and not just an empty line! readline() reads to the next newline - an empty line *is* EOF - a blank line has at least a

Re: Reading a file and resuming reading.

2007-05-25 Thread Karim Ali
Hrvoje Niksic <[EMAIL PROTECTED]> wrote: >If you open the file in binary mode, you can easily keep track of the >position in file: > >bytepos = 0 >with file(filename) as f: > for line in f: > ... process line ... > bytepos += len(line) > >If you need to restart the operation, simply seek

Re: Reading a file and resuming reading.

2007-05-25 Thread Hrvoje Niksic
"Karim Ali" <[EMAIL PROTECTED]> writes: > - > while not eof <- really want the EOF and not just an empty line! > readline by line > end while; > - for line in open_file: ... It will stop on EOF, not on empty line. > But also, in cas

Re: Reading a file and resuming reading.

2007-05-25 Thread Laszlo Nagy
Karim Ali wrote: > Hi, > > Simple question. Is it possible in python to write code of the type: > > - > while not eof <- really want the EOF and not just an empty line! > readline by line > end while; > - > > What I am using now is the im

Re: Reading a file and resuming reading.

2007-05-25 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Karim Ali wrote: > Simple question. Is it possible in python to write code of the type: > > - > while not eof <- really want the EOF and not just an empty line! > readline by line > end while; > - while True:

Re: Reading a file using a UNC - help!

2006-09-26 Thread richard . kessler
Thanks very much all for respondingI got it working. As you indicated, I just had mixed up my escapes (//) with my \n. When I got the correct amount of backslashes and removed the linefeeds it worked great. Thanks again. -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading a file using a UNC - help!

2006-09-26 Thread johnzenger
You should use os.path.exists to test if a file exists. Your exception-catching structure is not necessary. Also, if the file you are reading from contains proper Windows filenames, it is not necessary to replace \ with \\ and so forth. The \ acts as an escape character only when it is in Python

Re: Reading a file using a UNC - help!

2006-09-26 Thread Robert Kern
[EMAIL PROTECTED] wrote: > I have the simplest need...to read a file full of file names(unc) and > then check to see if each of these files exists. I tried with the > following program, but always get file not found, even when it is > there. If I type in the file name as a literal it works... > >

Re: Reading a file in same directory as code with relative path

2005-11-18 Thread [EMAIL PROTECTED]
Answer to a similar question: http://groups.google.com/group/comp.lang.python/msg/c01f292d7926f393?hl=en&; If you want a way that will work regardless if your module is run interactively, imported, or just run by itself, this is a solution that will always work: :: \wherever\wherever\ (the d

Re: Reading a file in same directory as code with relative path

2005-11-17 Thread Bengt Richter
On 17 Nov 2005 17:29:55 -0800, [EMAIL PROTECTED] wrote: >I'm trying to read an XML file in the same directory as my python code, >using minidom: > >document = xml.dom.minidom.parse("data.xml") > >How can I read in the file "data.xml" without knowing it's full >path--just that it's in the same dire