Re: fileinput

2019-10-29 Thread patatetom
Le mardi 29 octobre 2019 10:34:22 UTC+1, Inada Naoki a écrit : > When you are reading file from stdin, fileinput doesn't open the file. > Python open the stdin. So openhook doesn't affect to stdin. > > You can use stdin.reconfigure() to change encoding and error handler > of the stdin. > > On Tu

Re: fileinput

2019-10-29 Thread Inada Naoki
When you are reading file from stdin, fileinput doesn't open the file. Python open the stdin. So openhook doesn't affect to stdin. You can use stdin.reconfigure() to change encoding and error handler of the stdin. On Tue, Oct 29, 2019 at 6:31 PM wrote: > > Le lundi 28 octobre 2019 11:48:29 UTC+

Re: fileinput

2019-10-29 Thread patatetom
Le lundi 28 octobre 2019 11:48:29 UTC+1, Peter J. Holzer a écrit : > On 2019-10-25 22:12:23 +0200, Pascal wrote: > > for line in fileinput.input(source): > > print(line.strip()) > > > > --- > > > > python3.7.4 myscript.py myfile.log > > Traceback (most recent call last): >

Re: fileinput

2019-10-28 Thread Peter J. Holzer
On 2019-10-25 22:12:23 +0200, Pascal wrote: > for line in fileinput.input(source): > print(line.strip()) > > --- > > python3.7.4 myscript.py myfile.log > Traceback (most recent call last): > ... > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: >

Re: fileinput

2019-10-27 Thread patatetom
Le samedi 26 octobre 2019 17:49:57 UTC+2, Peter Otten a écrit : > Pascal wrote: > > > I have a small python (3.7.4) script that should open a log file and > > display its content but as you can see, an encoding error occurs : > > > > --- > > > > import fileinput > > import sy

Re: fileinput

2019-10-26 Thread Peter Otten
Pascal wrote: > I have a small python (3.7.4) script that should open a log file and > display its content but as you can see, an encoding error occurs : > > --- > > import fileinput > import sys > try: > source = sys.argv[1:] > except IndexError: > source = None > fo

Re: fileinput module not yielding expected results

2019-09-07 Thread Jason Friedman
> > If you're certain that the headers are the same in each file, > then there's no harm and much simplicity in reading them each > time they come up. > > with fileinput ...: > for line in f: > if fileinput.isfirstline(): > headers = extract_headers(line)

Re: fileinput module not yielding expected results

2019-09-07 Thread Barry Scott
> On 7 Sep 2019, at 16:33, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> > wrote: > >with fileinput ...: >for line in f: >if fileinput.isfirstline(): >headers = extract_headers(line) >else: >pass # process a non-header line

Re: fileinput module not yielding expected results

2019-09-07 Thread Dan Sommers
On 9/7/19 11:12 AM, Jason Friedman wrote: $ grep "File number" ~/result | sort | uniq File number: 3 I expected that last grep to yield: File number: 1 File number: 2 File number: 3 File number: 4 File number: 5 File number: 6 As per https://docs.python.org/3/library/fileinput.html#fileinput.

Re: FileInput too slow

2010-01-04 Thread Terry Reedy
On 1/4/2010 5:35 PM, wiso wrote: I'm trying the fileinput module, and I like it, but I don't understand why it's so slow... look: from time import time from fileinput import FileInput file = ['r1_200907.log', 'r1_200908.log', 'r1_200909.log', 'r1_200910.log', 'r1_200911.log'] def f1(): n =

Re: FileInput too slow

2010-01-04 Thread Steven D'Aprano
On Mon, 04 Jan 2010 23:35:02 +0100, wiso wrote: > I'm trying the fileinput module, and I like it, but I don't understand > why it's so slow... Because it is written for convenience, not speed. From the source code: "Performance: this module is unfortunately one of the slower ways of processing

Re: FileInput too slow

2010-01-04 Thread Gabriel Genellina
En Mon, 04 Jan 2010 19:35:02 -0300, wiso escribió: I'm trying the fileinput module, and I like it, but I don't understand why it's so slow... look: from time import time from fileinput import FileInput file = ['r1_200907.log', 'r1_200908.log', 'r1_200909.log', 'r1_200910.log', 'r1_200911

Re: fileinput

2009-08-14 Thread naaman
On Aug 13, 11:41 pm, naaman wrote: > On Aug 13, 7:50 am, Dave Angel wrote: > > > > > naaman wrote: > > > On Aug 12, 1:35 pm, Dave Angel wrote: > > > >> naaman wrote: > > > >>> I'm writing my first Python script and > > >>> I want to use fileinput to open a file in r+ mode. > > >>> Tried fileinpu

Re: fileinput

2009-08-13 Thread naaman
On Aug 13, 7:50 am, Dave Angel wrote: > naaman wrote: > > On Aug 12, 1:35 pm, Dave Angel wrote: > > >> naaman wrote: > > >>> I'm writing my first Python script and > >>> I want to use fileinput to open a file in r+ mode. > >>> Tried fileinput.input(sys.argv[1:],"r+") but that didn't work. > >>> A

Re: fileinput

2009-08-13 Thread naaman
On Aug 13, 1:20 am, "Gabriel Genellina" wrote: > En Wed, 12 Aug 2009 01:27:47 -0300, naaman escribió: > > > I'm writing my first Python script and > > I want to use fileinput to open a file in r+ mode. > > Tried fileinput.input(sys.argv[1:],"r+") but that didn't work. > > ANy ideas? > > Don't use

Re: fileinput

2009-08-13 Thread naaman
On Aug 13, 7:50 am, Dave Angel wrote: > naaman wrote: > > On Aug 12, 1:35 pm, Dave Angel wrote: > > >> naaman wrote: > > >>> I'm writing my first Python script and > >>> I want to use fileinput to open a file in r+ mode. > >>> Tried fileinput.input(sys.argv[1:],"r+") but that didn't work. > >>> A

Re: fileinput

2009-08-13 Thread naaman
On Aug 13, 7:50 am, Dave Angel wrote: > naaman wrote: > > On Aug 12, 1:35 pm, Dave Angel wrote: > > >> naaman wrote: > > >>> I'm writing my first Python script and > >>> I want to use fileinput to open a file in r+ mode. > >>> Tried fileinput.input(sys.argv[1:],"r+") but that didn't work. > >>> A

Re: Re: fileinput

2009-08-13 Thread Dave Angel
naaman wrote: On Aug 12, 1:35 pm, Dave Angel wrote: naaman wrote: I'm writing my first Python script and I want to use fileinput to open a file in r+ mode. Tried fileinput.input(sys.argv[1:],"r+") but that didn't work. ANy ideas? Need to find and overwrite a line in a file sever

Re: fileinput

2009-08-12 Thread Gabriel Genellina
En Wed, 12 Aug 2009 01:27:47 -0300, naaman escribió: I'm writing my first Python script and I want to use fileinput to open a file in r+ mode. Tried fileinput.input(sys.argv[1:],"r+") but that didn't work. ANy ideas? Don't use fileinput, it can't handle r+, only sequencial access. Even if you

Re: fileinput

2009-08-12 Thread naaman
On Aug 12, 1:35 pm, Dave Angel wrote: > naaman wrote: > > I'm writing my first Python script and > > I want to use fileinput to open a file in r+ mode. > > Tried fileinput.input(sys.argv[1:],"r+") but that didn't work. > > ANy ideas? > > > Need to find and overwrite a line in a file several times.

Re: fileinput

2009-08-12 Thread Dave Angel
naaman wrote: I'm writing my first Python script and I want to use fileinput to open a file in r+ mode. Tried fileinput.input(sys.argv[1:],"r+") but that didn't work. ANy ideas? Need to find and overwrite a line in a file several times. I can do it using open and seek() etc. but was wondering if