Re: Define a class containing methods for reading a file and then store lines in external variable

2013-08-15 Thread Chris Angelico
On Thu, Aug 15, 2013 at 10:33 AM, Joug Raw wrote: > class FileOpration: > def __init__(self,name): > self.name = name > self.filename = self.name > def readAllline(self): > open(self.name).readlines() > > file1 = FileOpration("myfile.txt") > print file1.filename > a

Define a class containing methods for reading a file and then store lines in external variable

2013-08-15 Thread Joug Raw
Hi, I am really new in python programming and I want to build a class that perform various functions to the content(or lines) of any given file. I want to first include the opening and reading file function into that class, then add other methods. Here is what I wrote for opening file and read

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

Reading a file in IDLE 3 on Mac-Lion

2012-09-21 Thread Franck Ditter
Hello, 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 ? This works on Windows-7. Thanks for the tip,

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

Reading a file into a data structure....

2011-10-13 Thread MrPink
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 some followup questions. For example, I have a list in

Re: Difference between Popen and open() for reading a file

2010-04-30 Thread Aahz
In article , J wrote: > >Say I had a file, foo.txt that I wanted to read from, only one time >and only read. > >So what's the difference between this: > >mylist = Popen(["cat","foo.txt"], stdout=PIPE).communicate()[0].splitlines() > >Is there a reason why you would not use subprocess.Popen for th

Re: Difference between Popen and open() for reading a file

2010-04-22 Thread J
On Thu, Apr 22, 2010 at 15:18, Dave Angel wrote: > The same difference as between handing the paper boy three bucks, versus > flying to London to open an account, making a deposit, going to a branch in > Sydney and asking for a bank check, then flying back home and taking the > paper boy with you

Re: Difference between Popen and open() for reading a file

2010-04-22 Thread Dave Angel
J wrote: I was reading something from a code review a little while ago and saw something that's got my curiosity up... Say I had a file, foo.txt that I wanted to read from, only one time and only read. So what's the difference between this: mylist = Popen(["cat","foo.txt"], stdout=PIPE).comm

Re: Difference between Popen and open() for reading a file

2010-04-22 Thread MRAB
J wrote: I was reading something from a code review a little while ago and saw something that's got my curiosity up... Say I had a file, foo.txt that I wanted to read from, only one time and only read. So what's the difference between this: mylist = Popen(["cat","foo.txt"], stdout=PIPE).commun

Re: Difference between Popen and open() for reading a file

2010-04-22 Thread Chris Rebert
On Thu, Apr 22, 2010 at 11:28 AM, J wrote: > I was reading something from a code review a little while ago and saw > something that's got my curiosity up... > > Say I had a file, foo.txt that I wanted to read from, only one time > and only read. > > So what's the difference between this: > > mylis

Difference between Popen and open() for reading a file

2010-04-22 Thread J
I was reading something from a code review a little while ago and saw something that's got my curiosity up... Say I had a file, foo.txt that I wanted to read from, only one time and only read. So what's the difference between this: mylist = Popen(["cat","foo.txt"], stdout=PIPE).communicate()[0].

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

Reading a file that is changing and getting the new lines

2009-12-01 Thread Ouray Viney
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 fault, more that I don't

Re: Multi thread reading a file

2009-07-05 Thread Lawrence D'Oliveiro
In message <025ff4f1$0$20657$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: > On Sun, 05 Jul 2009 12:12:22 +1200, Lawrence D'Oliveiro wrote: > >> In message >> <1beffd94-cfe6-4cf6-bd48-2ccac8637...@j32g2000yqh.googlegroups.com>, ryles >> wrote: >> >> # Oh... yeah. I really *did* want '

Re: Multi thread reading a file

2009-07-04 Thread Steven D'Aprano
On Sun, 05 Jul 2009 12:12:22 +1200, Lawrence D'Oliveiro wrote: > In message <1beffd94-cfe6-4cf6- > bd48-2ccac8637...@j32g2000yqh.googlegroups.com>, ryles wrote: > > # Oh... yeah. I really *did* want 'is None' and not '== None' which > # iter() will do. Sorry guys! >> >> Please don't let

Re: Multi thread reading a file

2009-07-04 Thread Lawrence D'Oliveiro
In message <1beffd94-cfe6-4cf6- bd48-2ccac8637...@j32g2000yqh.googlegroups.com>, ryles wrote: # Oh... yeah. I really *did* want 'is None' and not '== None' which # iter() will do. Sorry guys! > > Please don't let this happen to you too ;) Strange. others have got told off for using "==

Re: Multi thread reading a file

2009-07-02 Thread ryles
On Jul 2, 11:55 pm, Paul Rubin wrote: > Yeah, it should allow supplying a predicate instead of using == on > a value.  How about (untested): > >    from itertools import * >    ... >    for row in takewhile(lambda x: x is sentinel, >                          starmap(i

Re: Multi thread reading a file

2009-07-02 Thread Paul Rubin
"Gabriel Genellina" writes: > We're talking about the iter() builtin behavior, and that uses == > internally. Oh, I see. Drat. > It could have used an identity test, and that would be better for this > specific case. But then iter(somefile.read, '') wouldn't work. Yeah, it should allow supplyi

Re: Multi thread reading a file

2009-07-02 Thread Gabriel Genellina
En Fri, 03 Jul 2009 00:15:40 -0300, > escribió: ryles writes: >    sentinel = object() I agree, this is cleaner than None. We're still in the same boat, though, regarding iter(). Either it's 'item == None' or 'item == object ()' Use "item is sentinel". We're talking about the iter() bui

Re: Multi thread reading a file

2009-07-02 Thread Paul Rubin
ryles writes: > >    sentinel = object() > > I agree, this is cleaner than None. We're still in the same boat, > though, regarding iter(). Either it's 'item == None' or 'item == object ()' Use "item is sentinel". -- http://mail.python.org/mailman/listinfo/python-list

Re: Multi thread reading a file

2009-07-02 Thread ryles
On Jul 2, 10:20 pm, Paul Rubin wrote: > ryles writes: > > >>> # Oh... yeah. I really *did* want 'is None' and not '== None' > > >>> which iter() will do. Sorry guys! > > > Please don't let this happen to you too ;) > > None is a perfectly good value to put onto a que

Re: Multi thread reading a file

2009-07-02 Thread Paul Rubin
ryles writes: > >>> # Oh... yeah. I really *did* want 'is None' and not '== None' > >>> which iter() will do. Sorry guys! > > Please don't let this happen to you too ;) None is a perfectly good value to put onto a queue. I prefer using a unique sentinel to mark the end of the stream: sentin

Re: Multi thread reading a file

2009-07-02 Thread ryles
On Jul 2, 6:10 am, "Gabriel Genellina" wrote: > En Wed, 01 Jul 2009 12:49:31 -0300, Scott David Daniels   > escribió: > > These loops work well with the two-argument version of iter, > > which is easy to forget, but quite useful to have in your bag > > of tricks: > > >      def convert(in_queue,

Re: Multi thread reading a file

2009-07-02 Thread Gabriel Genellina
En Wed, 01 Jul 2009 12:49:31 -0300, Scott David Daniels escribió: Gabriel Genellina wrote: ... def convert(in_queue, out_queue): while True: row = in_queue.get() if row is None: break # ... convert row out_queue.put(converted_line) These loops work well with the two-argum

Re: Multi thread reading a file

2009-07-01 Thread Stefan Behnel
Mag Gam wrote: > On Wed, Jul 1, 2009 at 12:54 AM, Gabriel Genellina wrote: >> Does the format conversion involve a significant processing time? If not, >> the total time is dominated by the I/O time (reading and writing the file) >> so it's doubtful you gain anything from multiple threads. > > The

Re: Multi thread reading a file

2009-07-01 Thread Mag Gam
LOL! :-) Why not. I think I will take just do it single thread for now and if performance is really that bad I can re investigate. Either way, thanks everyone for your feedback! I think I like python a lot because of the great user community and wiliness to help! On Wed, Jul 1, 2009 at 1:07 AM

Re: Multi thread reading a file

2009-07-01 Thread Mag Gam
Thanks for the response Gabriel. On Wed, Jul 1, 2009 at 12:54 AM, Gabriel Genellina wrote: > En Tue, 30 Jun 2009 22:52:18 -0300, Mag Gam escribió: > >> I am very new to python and I am in the process of loading a very >> large compressed csv file into another format.  I was wondering if I >> ca

Re: Multi thread reading a file

2009-07-01 Thread Lawrence D'Oliveiro
In message , Mag Gam wrote: > I am very new to python and I am in the process of loading a very > large compressed csv file into another format. I was wondering if I > can do this in a multi thread approach. Why bother? -- http://mail.python.org/mailman/listinfo/python-list

Re: Multi thread reading a file

2009-07-01 Thread Scott David Daniels
Gabriel Genellina wrote: ... def convert(in_queue, out_queue): while True: row = in_queue.get() if row is None: break # ... convert row out_queue.put(converted_line) These loops work well with the two-argument version of iter, which is easy to forget, but quite useful to have

Re: Multi thread reading a file

2009-07-01 Thread Stefan Behnel
Gabriel Genellina wrote: > En Tue, 30 Jun 2009 22:52:18 -0300, Mag Gam escribió: > >> I am very new to python and I am in the process of loading a very >> large compressed csv file into another format. I was wondering if I >> can do this in a multi thread approach. > > Does the format conversio

Re: Multi thread reading a file

2009-06-30 Thread Gabriel Genellina
En Tue, 30 Jun 2009 22:52:18 -0300, Mag Gam escribió: I am very new to python and I am in the process of loading a very large compressed csv file into another format. I was wondering if I can do this in a multi thread approach. Does the format conversion involve a significant processing time

Multi thread reading a file

2009-06-30 Thread Mag Gam
Hello All, I am very new to python and I am in the process of loading a very large compressed csv file into another format. I was wondering if I can do this in a multi thread approach. Here is the pseudo code I was thinking about: Let T = Total number of lines in a file, Example 100 (1 mil

Re: Empty string when reading a file

2009-04-05 Thread MRAB
nxri...@googlemail.com wrote: Hi, I'm reading in a file of 250 bytes. At the 55th byte, read() will return an empty string although this isn't the end of the file. This is what I have: for i in range(os.path.getsize("inputFile")): bitsInFile = inputFile.read(1) inputFile.seek(i) byt

Empty string when reading a file

2009-04-05 Thread nxri...@googlemail.com
Hi, I'm reading in a file of 250 bytes. At the 55th byte, read() will return an empty string although this isn't the end of the file. This is what I have: for i in range(os.path.getsize("inputFile")): bitsInFile = inputFile.read(1) inputFile.seek(i) byteFromFile = ord(bitsInFile) Rea

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: Newby Question for reading a file

2009-02-19 Thread Steve Holden
alex23 wrote: > On Feb 20, 5:38 am, Peter Otten <__pete...@web.de> wrote: >> Yes you can get portions of the line by slicing: >> >> for line in open("infile"): >> if line[8:18] != line[18:28]: >> print line, > > You can also name the slices, which makes the code more clear (IMO): >

Re: Newby Question for reading a file

2009-02-19 Thread alex23
On Feb 20, 5:38 am, Peter Otten <__pete...@web.de> wrote: > Yes you can get portions of the line by slicing: > > for line in open("infile"): >     if line[8:18] != line[18:28]: >             print line, You can also name the slices, which makes the code more clear (IMO): endda = slice(8,18) begda

Re: Newby Question for reading a file

2009-02-19 Thread steven.oldner
On Feb 19, 1:44 pm, Curt Hash wrote: > On Thu, Feb 19, 2009 at 12:07 PM, steven.oldner > wrote: > > > On Feb 19, 12:40 pm, Mike Driscoll wrote: > > > On Feb 19, 12:32 pm, "steven.oldner" wrote: > > > > > Simple question but I haven't found an answer.  I program in ABAP, and > > > > in ABAP you

Re: Newby Question for reading a file

2009-02-19 Thread Peter Otten
steven.oldner wrote: > On Feb 19, 12:40 pm, Mike Driscoll wrote: >> On Feb 19, 12:32 pm, "steven.oldner" wrote: >> >> > Simple question but I haven't found an answer.  I program in ABAP, and >> > in ABAP you define the data structure of the file and move the file >> > line into the structure, an

Re: Newby Question for reading a file

2009-02-19 Thread Curt Hash
On Thu, Feb 19, 2009 at 12:07 PM, steven.oldner wrote: > > On Feb 19, 12:40 pm, Mike Driscoll wrote: > > On Feb 19, 12:32 pm, "steven.oldner" wrote: > > > > > Simple question but I haven't found an answer. I program in ABAP, and > > > in ABAP you define the data structure of the file and move t

Re: Newby Question for reading a file

2009-02-19 Thread steven.oldner
On Feb 19, 12:40 pm, Mike Driscoll wrote: > On Feb 19, 12:32 pm, "steven.oldner" wrote: > > > Simple question but I haven't found an answer.  I program in ABAP, and > > in ABAP you define the data structure of the file and move the file > > line into the structure, and then do something to the fi

Re: Newby Question for reading a file

2009-02-19 Thread Mike Driscoll
On Feb 19, 12:32 pm, "steven.oldner" wrote: > Simple question but I haven't found an answer.  I program in ABAP, and > in ABAP you define the data structure of the file and move the file > line into the structure, and then do something to the fields.  That's > my mental reference. > > How do I sep

Newby Question for reading a file

2009-02-19 Thread steven.oldner
Simple question but I haven't found an answer. I program in ABAP, and in ABAP you define the data structure of the file and move the file line into the structure, and then do something to the fields. That's my mental reference. How do I separate or address each field in the file line with PYTHON

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

Reading a file

2009-02-14 Thread zaheer . agadi
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..? Thanks -- http://mail.python.org/mailman/listinfo/python-list

Reading a file

2008-07-24 Thread aditya shukla
Thanks a lot guys , i got it now. Aditya -- http://mail.python.org/mailman/listinfo/python-list

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

Reading a file

2008-07-24 Thread aditya shukla
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() the result that i get is ike this:- 'jd|fj|dnv|jd|0.33|c:windowswin32\nshcbsbs|nscsjsj

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:

Reading a file and resuming reading.

2007-05-25 Thread Karim Ali
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 implicit for loop after a readlines().

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

Reading a file using a UNC - help!

2006-09-26 Thread richard . kessler
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... Little program: #This module checks

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

Reading a file in same directory as code with relative path

2005-11-17 Thread dan . j . weber
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 directory as my code file? Thanks for any help with this. I'm new to