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
&
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 2
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):
>
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:
>
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 :
> >
> > ---
> &
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 I
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
for line in fileinput.input(source
>
> 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():
>
> 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:
>
es.
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_heade
import csv
import fileinput
import sys
print("Version: " + str(sys.version_info))
print("Files: " + str(sys.argv[1:]))
with fileinput.input(sys.argv[1:]) as f:
for line in f:
print(f"File number: {fileinput.fileno()}")
print(f"Is first li
On 2015-12-04, Oscar Benjamin wrote:
> Or you can use fileinput which is designed to be exactly this kind of
> context manager and to be used in this way. Although fileinput is slightly
> awkward in defaulting to reading stdin.
That default is what I specifically like about fileinput -
On 4 Dec 2015 08:36, "Serhiy Storchaka" wrote:
>
> On 04.12.15 00:26, Oscar Benjamin wrote:
>>
>> On 3 Dec 2015 16:50, "Terry Reedy" wrote:
>>>
>>> fileinput is an ancient module that predates iterators (and generators)
>>
>
On 04.12.15 00:26, Oscar Benjamin wrote:
On 3 Dec 2015 16:50, "Terry Reedy" wrote:
fileinput is an ancient module that predates iterators (and generators)
and context managers. Since by 2.7 open files are both context managers and
line iterators, you can easily write your own multi
o_stuff(line)
>>>
>>> which the documentation describes as "a hook which opens each file
>>> with codecs.open(), using the given encoding to read the file", but
>>> I'd like codecs.open() to also have the errors='ignore' or
>>> err
='ignore' or
>>>errors='replace' effect. Is it possible to do this?
>>>
>>>Thanks.
>>
>> This should be both easy to add, and useful, and I happen to know that
>> fileinput is being hacked on by Serhiy Storchaka right now, who agrees
>&
;a hook which opens each file
>>with codecs.open(), using the given encoding to read the file", but
>>I'd like codecs.open() to also have the errors='ignore' or
>>errors='replace' effect. Is it possible to do this?
>>
>>Thanks.
>
> This
On 2015-12-03, Terry Reedy wrote:
> fileinput is an ancient module that predates iterators (and generators)
> and context managers. Since by 2.7 open files are both context managers
> and line iterators, you can easily write your own multi-file line
> iteration that does exactly w
On 2015-12-03, Peter Otten wrote:
> def my_hook_encoded(encoding, errors=None):
> import io
> def openhook(filename, mode):
> mode = mode.replace('U', '').replace('b', '') or 'r'
> return io.open(
> filename, mode,
> encoding=encoding, newline='',
ke codecs.open() to also have the errors='ignore' or
errors='replace' effect. Is it possible to do this?
I forgot to mention: this is for Python 2.7.3 & 2.7.10 (on different
machines).
fileinput is an ancient module that predates iterators (and generators)
and context manag
the file", but
>I'd like codecs.open() to also have the errors='ignore' or
>errors='replace' effect. Is it possible to do this?
>
>Thanks.
This should be both easy to add, and useful, and I happen to know that
fileinput is being hacked on by Serhiy Storc
On 2015-12-03 15:12, Adam Funk wrote:
I'm having trouble with some input files that are almost all proper
UTF-8 but with a couple of troublesome characters mixed in, which I'd
like to ignore instead of throwing ValueError. I've found the
openhook for the encoding
for line in fileinput.input(opt
Adam Funk wrote:
> On 2015-12-03, Adam Funk wrote:
>
>> I'm having trouble with some input files that are almost all proper
>> UTF-8 but with a couple of troublesome characters mixed in, which I'd
>> like to ignore instead of throwing ValueError. I've found the
>> openhook for the encoding
>>
>>
On 2015-12-03, Adam Funk wrote:
> I'm having trouble with some input files that are almost all proper
> UTF-8 but with a couple of troublesome characters mixed in, which I'd
> like to ignore instead of throwing ValueError. I've found the
> openhook for the encoding
>
> for line in fileinput.input
I'm having trouble with some input files that are almost all proper
UTF-8 but with a couple of troublesome characters mixed in, which I'd
like to ignore instead of throwing ValueError. I've found the
openhook for the encoding
for line in fileinput.input(options.files,
openhook=fileinput.hook_enc
a list of strings in a directory of files. Here is my
code:
>> >
>> > # -*- coding: utf-8 -*-
>> > import os
>> > import fileinput
>> >
>> > s2 = os.listdir('/home/malikarumi/Projects/P5/shortstories')
>>
>> Note that the
join. Anyway, I
> thought you had some good ideas so I worked with them but as I say I keep
> getting stuck at one particular point. Here is the current version of my code:
>
> # -*- coding: utf-8 -*-
> import os
> import fileinput
>
> path1 = os.path.join('Projec
a directory of files. Here is
> >> > my code:
> >> >
> >> > # -*- coding: utf-8 -*-
> >> > import os
> >> > import fileinput
> >> >
> >> > s2 = os.listdir('/home/malikarumi/Projects/P5/shortstories')
Thanks all! I understand better now. I had no idea that EOFError was an
exception. I was looking for a function to tell me when the end of a
sequential file is reached as in all of the 4 programming languages that I
do know this is a requirement.
Will modify my program accordingly.
Alex van d
idea what you mean. But if that is what you're
doing, then you're doing it completely wrong! Exceptions aren't flags
that get set globally by magic. You have completely misunderstood
Python's programming model.
In this case, the point of using fileinput is so you don't
e
news:4c696751$0$22940$e4fe5...@news.xs4all.nl...
Using the fileinput module to process lists of files:
for line in fileinput.input(logs):
Unfortunately, EOFError does not seem to indicate the end-of-file
condition correctly when using fileinput.
How would you find the EOF file for all th
On 16/08/2010 17:29, Alex van der Spek wrote:
Using the fileinput module to process lists of files:
for line in fileinput.input(logs):
Unfortunately, EOFError does not seem to indicate the end-of-file
condition correctly when using fileinput.
How would you find the EOF file for all the
Using the fileinput module to process lists of files:
for line in fileinput.input(logs):
Unfortunately, EOFError does not seem to indicate the end-of-file condition
correctly when using fileinput.
How would you find the EOF file for all the files in the file list 'logs'?
Thank
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',
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
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'
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_200
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
> &g
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.
> >>&
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+"
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.
> >>&
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.
> >>&
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 overwr
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+, o
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?
>
> > N
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() et
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 wo
On Feb 13, 8:31 pm, 7stud <[EMAIL PROTECTED]> wrote:
> On Feb 13, 6:47 pm, Robert <[EMAIL PROTECTED]> wrote:
>
>
>
> > I would like to count lines in a file using the fileinput module and I
&g
On Feb 13, 6:47 pm, Robert <[EMAIL PROTECTED]> wrote:
> I would like to count lines in a file using the fileinput module and I
> am getting an unusual output.
> ---
> ---
> #!/usr/bin/python
> impo
En Wed, 13 Feb 2008 23:47:11 -0200, Robert <[EMAIL PROTECTED]>
escribió:
> I would like to count lines in a file using the fileinput module and I
> am getting an unusual output.
> --
> #!/usr/b
I would like to count lines in a file using the fileinput module and I
am getting an unusual output.
--
#!/usr/bin/python
import fileinput
# cycle through files
for line in fileinput.input():
if (fileinput.isfirstline
Fredrik Lundh <[EMAIL PROTECTED]> writes:
> From what I can tell, Java's GC automatically closes file streams,
> so Jython will behave pretty much like CPython in most cases.
The finalizer does close the reclaimed streams, but since it is
triggered by GC, you have to wait for GC to occur for the
Fredrik Lundh wrote:
> Martin Marcher wrote:
>
>>> i need to read line 4 from a header file
>>
>> http://docs.python.org/lib/module-linecache.html
>
> I guess you missed the "using linecache will crash my computer due to
> memory loading, because i am working on 2000 files each is 8mb" part.
o
Steven D'Aprano wrote:
> Python guarantees[1] that files will be closed, but doesn't specify when
> they will be closed. I understand that Jython doesn't automatically close
> files until the program terminates, so even if you could rely on the ref
> counter to close the files in CPython, it wo
Russ P. wrote:
> On Jan 7, 9:41 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>> Given that the OP is talking 2000 files to be processed, I think I'd
>> recommend explicit open() and close() calls to avoid having lots of I/O
>> structures floating around...
>>
[effectively]
>> for fid in
On Mon, 07 Jan 2008 22:16:56 -0800, Russ P. wrote:
> One second thought, I wonder if the reference counting mechanism would
> be "smart" enough to automatically close the previous file on each
> iteration of the outer loop. If so, the files don't need to be
> explicitly closed.
Python guarantees[
jo3c wrote:
> hi everybody
> im a newbie in python
> i need to read line 4 from a header file
> using linecache will crash my computer due to memory loading, because
> i am working on 2000 files each is 8mb
>
> fileinput don't load the file into memory first
> how
Martin Marcher wrote:
>> i need to read line 4 from a header file
>
> http://docs.python.org/lib/module-linecache.html
I guess you missed the "using linecache will crash my computer due to
memory loading, because i am working on 2000 files each is 8mb" part.
--
http://mail.python.org/mailma
jo3c wrote:
> i need to read line 4 from a header file
http://docs.python.org/lib/module-linecache.html
~/2delete $ cat data.txt
L1
L2
L3
L4
~/2delete $ python
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "
On Jan 8, 2:08 pm, "Russ P." <[EMAIL PROTECTED]> wrote:
> > Given that the OP is talking 2000 files to be processed, I think I'd
> > recommend explicit open() and close() calls to avoid having lots of I/O
> > structures floating around...
>
> Good point. I didn't think of that. It could als
On Jan 7, 9:41 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Mon, 7 Jan 2008 20:10:58 -0800 (PST), "Russ P."
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
> > for file0 in files:
>
> > lnum = 0 # line number
>
> > for line in file(file0):
> > lnum += 1
> Given that the OP is talking 2000 files to be processed, I think I'd
> recommend explicit open() and close() calls to avoid having lots of I/O
> structures floating around...
Good point. I didn't think of that. It could also be done as follows:
for fileN in files:
lnum = 0 # line
On Jan 7, 7:15 pm, jo3c <[EMAIL PROTECTED]> wrote:
> hi everybody
> im a newbie in python
> i need to read line 4 from a header file
> using linecache will crash my computer due to memory loading, because
> i am working on 2000 files each is 8mb
>
> fileinput don't
hi everybody
im a newbie in python
i need to read line 4 from a header file
using linecache will crash my computer due to memory loading, because
i am working on 2000 files each is 8mb
fileinput don't load the file into memory first
how do i use fileinput module to read a specific line f
Hi All,
I am able to use urlib2 through proxy. I give proxy credentials and use
# Set the Proxy Address
proxy_ip = "10.0.1.1:80"
proxy_user = 'senthil_or'
proxy_password_orig='password'
proxy_password = urllib.quote(proxy_password_orig,"")
# Setup the Proxy with urllib2
proxy_url = 'http://'
At Sunday 26/11/2006 01:29, wo_shi_big_stomach wrote:
for line in fileinput.input(g, inplace=1, backup='.bak'):
# just print 2nd and subsequent lines
if not fileinput.isfirstline():
print line.rstrip('\n')
# check first line only
elif fileinput.isfirstline
tion.
>
>
>> dir = path('/home/wsbs/Maildir')
>> #for f in dir.walkfiles('*'):
>> for f in filter(os.path.isfile, dir.walkfiles('*')):
>
> If I understand the documentation of fileinput, you shouldn't even
> need this
('*')):
>> > #
>> > # test:
>> > # print f
>>
>> Thanks, this way f will print the full pathname/filename. But f already
>> does that using Jason Orendorff's path module:
>>
>> dir = path('/home/wsbs/Maild
Thanks, this way f will print the full pathname/filename. But f already
does that using Jason Orendorff's path module:
dir = path('/home/wsbs/Maildir')
for f in dir.walkfiles('*'):
print f
The filter is used to exclude directories. fileinput can't handle di
t.input().
Either the path or the os.path methods cause this line:
for line in fileinput.input(f, inplace=1, backup='.bak'):
to throw this error:
File "./p2.py", line 23, in ?
for line in fileinput.input(f, inplace=1, backup='.bak'):
At this point I believe the
At Thursday 23/11/2006 12:21, wo_shi_big_stomach wrote:
>> dir = path(/home/wsbs/Maildir)
>> for f in dir.walkfiles('*'):
>> #
>> # test:
>> # print f
>
> Are you absolutely sure that f list doesn't contain
> any path to directory, not file?
> Add this:
>
> f = filter(os.p
t;>
>> Here's the script:
>>
>> # start of program
>>
>> # p.pl - fix broken SMTP headers in email files
>> #
>> # recurses from dir and searches all subdirs
>> # for each file, evaluates whether 1st line starts with "From "
>> #
am
>
> # p.pl - fix broken SMTP headers in email files
> #
> # recurses from dir and searches all subdirs
> # for each file, evaluates whether 1st line starts with "From "
> # for each match, program deletes line
>
> import fileinput
> import os
> import re
urses from dir and searches all subdirs
# for each file, evaluates whether 1st line starts with "From "
# for each match, program deletes line
import fileinput
import os
import re
import string
import sys
from path import path
# recurse dirs
dir = path(/home/wsbs/Maildir)
for f i
the.theorist wrote:
> I'll keep both those in mind for future programs.
> my current fix has been
>
> if not args:
> args = [ sys.stdin ]
> else:
> map( open, args )
>
> and then a modification to the main loop, as you proposed.
>
> I thought that one day I might run into a problem open
"the.theorist" wrote:
> I used this bit of code to detect wether i want stdinput or not.
>
> if len(args)==0:
> args = [ sys.stdin ]
>
> Now in my main loop I've written:
>
> for file in args:
> for line in open( file ):
> #do stuff
>
> The probelm occurs when I pass no arguments a
the.theorist wrote:
> Steven Bethard wrote:
>
>>the.theorist wrote:
>>
>>>I was writing a small script the other day with the following CLI
>>>prog [options] [file]*
>>>
>>>I've used getopt to parse out the possible options, so we'll ignore
>>>that part, and assume for the rest of the discussion t
Steven Bethard wrote:
> the.theorist wrote:
> > I was writing a small script the other day with the following CLI
> > prog [options] [file]*
> >
> > I've used getopt to parse out the possible options, so we'll ignore
> > that part, and assume for the rest of the discussion that args is a
> > list
the.theorist wrote:
> I was writing a small script the other day with the following CLI
> prog [options] [file]*
>
> I've used getopt to parse out the possible options, so we'll ignore
> that part, and assume for the rest of the discussion that args is a
> list of file names (if any provided).
>
I was writing a small script the other day with the following CLI
prog [options] [file]*
I've used getopt to parse out the possible options, so we'll ignore
that part, and assume for the rest of the discussion that args is a
list of file names (if any provided).
I used this bit of code to detect
80 matches
Mail list logo