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 &

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 2

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 : > > > > --- > &

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 I

fileinput

2019-10-26 Thread Pascal
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

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(): >

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

Re: fileinput module not yielding expected results

2019-09-07 Thread Dan Sommers
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

fileinput module not yielding expected results

2019-09-07 Thread Jason Friedman
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

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-07 Thread Adam Funk
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 -

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-04 Thread Oscar Benjamin
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) >> >

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-04 Thread Serhiy Storchaka
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

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Oscar Benjamin
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

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Laura Creighton
='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 >&

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
;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

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
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

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
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='',

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Terry Reedy
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

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Laura Creighton
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

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread MRAB
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

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Peter Otten
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 >> >>

Re: getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
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

getting fileinput to do errors='ignore' or 'replace'?

2015-12-03 Thread Adam Funk
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

Re: Struggling with os.path.join and fileinput (was 'Path, strings, and lines'

2015-06-15 Thread MRAB
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

Re: Struggling with os.path.join and fileinput (was 'Path, strings, and lines'

2015-06-15 Thread Ian Kelly
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

Struggling with os.path.join and fileinput (was 'Path, strings, and lines'

2015-06-15 Thread Malik Rumi
a directory of files. Here is > >> > my code: > >> > > >> > # -*- coding: utf-8 -*- > >> > import os > >> > import fileinput > >> > > >> > s2 = os.listdir('/home/malikarumi/Projects/P5/shortstories')

Re: EOFError with fileinput

2010-08-17 Thread Alex van der Spek
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

Re: EOFError with fileinput

2010-08-16 Thread Steven D'Aprano
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

Re: EOFError with fileinput

2010-08-16 Thread Alex van der Spek
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

Re: EOFError with fileinput

2010-08-16 Thread Mark Lawrence
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

EOFError with fileinput

2010-08-16 Thread Alex van der Spek
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

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', 

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

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'

FileInput too slow

2010-01-04 Thread wiso
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

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 > &g

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

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+"

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

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

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 overwr

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+, o

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? > > > N

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() et

fileinput

2009-08-11 Thread naaman
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

Re: counting lines using fileinput module

2008-02-13 Thread Robert
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

Re: counting lines using fileinput module

2008-02-13 Thread 7stud
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

Re: counting lines using fileinput module

2008-02-13 Thread Gabriel Genellina
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

counting lines using fileinput module

2008-02-13 Thread Robert
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

Re: use fileinput to read a specific line

2008-01-08 Thread Hrvoje Niksic
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

Re: use fileinput to read a specific line

2008-01-08 Thread Martin Marcher
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

Re: use fileinput to read a specific line

2008-01-08 Thread Fredrik Lundh
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

Re: use fileinput to read a specific line

2008-01-08 Thread Scott David Daniels
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

Re: use fileinput to read a specific line

2008-01-08 Thread Steven D'Aprano
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[

Re: use fileinput to read a specific line

2008-01-08 Thread Fredrik Lundh
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

Re: use fileinput to read a specific line

2008-01-08 Thread Fredrik Lundh
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

Re: use fileinput to read a specific line

2008-01-08 Thread Martin Marcher
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 "

Re: use fileinput to read a specific line

2008-01-07 Thread jo3c
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

Re: use fileinput to read a specific line

2008-01-07 Thread Russ P.
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

Re: use fileinput to read a specific line

2008-01-07 Thread Russ P.
> 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

Re: use fileinput to read a specific line

2008-01-07 Thread Russ P.
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

use fileinput to read a specific line

2008-01-07 Thread jo3c
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

problem occurs with replaced values using fileinput

2006-12-02 Thread Phoe6
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://'

Re: combining the path and fileinput modules SOLVED

2006-11-27 Thread Gabriel Genellina
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

Re: combining the path and fileinput modules SOLVED

2006-11-25 Thread wo_shi_big_stomach
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

Re: combining the path and fileinput modules

2006-11-25 Thread wo_shi_big_stomach
('*')): >> > # >> > # 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

Re: combining the path and fileinput modules

2006-11-24 Thread Gabriel Genellina
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

Re: combining the path and fileinput modules

2006-11-24 Thread wo_shi_big_stomach
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

Re: combining the path and fileinput modules

2006-11-24 Thread Gabriel Genellina
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

Re: combining the path and fileinput modules

2006-11-23 Thread wo_shi_big_stomach
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 " >> #

Re: combining the path and fileinput modules

2006-11-23 Thread Rob Wolfe
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

combining the path and fileinput modules

2006-11-22 Thread wo_shi_big_stomach
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

Re: stdin or optional fileinput

2006-03-15 Thread Peter Otten
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

Re: stdin or optional fileinput

2006-03-15 Thread Fredrik Lundh
"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

Re: stdin or optional fileinput

2006-03-15 Thread Steve Holden
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

Re: stdin or optional fileinput

2006-03-15 Thread the.theorist
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

Re: stdin or optional fileinput

2006-03-15 Thread Steven Bethard
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). >

stdin or optional fileinput

2006-03-15 Thread the.theorist
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