Re: inplace text filter - without writing file

2016-10-02 Thread MRAB

On 2016-10-02 06:33, Sayth Renshaw wrote:

On Sunday, 2 October 2016 16:19:14 UTC+11, Sayth Renshaw  wrote:

On Sunday, 2 October 2016 12:14:43 UTC+11, MRAB  wrote:
> On 2016-10-02 01:21, Sayth Renshaw wrote:
> > Hi
> >
> > I have a fileobject which was fine however now I want to delete a line from 
the file object before yielding.
> >
> > def return_files(file_list):
> > for filename in sorted(file_list):
>
> When joining paths together, it's better to use 'os.path.join'.
>
> > with open(dir_path + filename) as fd:
> >  for fileItem in fd:
> >  yield fileItem
> >
> > Ned gave an answer over here http://stackoverflow.com/a/6985814/461887
> >
> > for i, line in enumerate(input_file):
> > if i == 0 or not line.startswith('#'):
> > output.write(line)
> >
> > which I would change because it is the first line and I want to rid 

Re: inplace text filter - without writing file

2016-10-02 Thread breamoreboy
On Sunday, October 2, 2016 at 6:19:14 AM UTC+1, Sayth Renshaw wrote:
> 
> I just can't quite get it.
> 
> def return_files(file_list):
> for filename in sorted(file_list):
> file = os.path.join(dir_path, filename)
> print(file)
> with open(file) as fd:
> print(fd)
> for fileItem in fd:
> print(fileItem)
> for line in fileItem:
> print(line[0])
> if 

Re: inplace text filter - without writing file

2016-10-01 Thread Sayth Renshaw
On Sunday, 2 October 2016 16:19:14 UTC+11, Sayth Renshaw  wrote:
> On Sunday, 2 October 2016 12:14:43 UTC+11, MRAB  wrote:
> > On 2016-10-02 01:21, Sayth Renshaw wrote:
> > > Hi
> > >
> > > I have a fileobject which was fine however now I want to delete a line 
> > > from the file object before yielding.
> > >
> > > def return_files(file_list):
> > > for filename in sorted(file_list):
> > 
> > When joining paths together, it's better to use 'os.path.join'.
> > 
> > > with open(dir_path + filename) as fd:
> > >  for fileItem in fd:
> > >  yield fileItem
> > >
> > > Ned gave an answer over here http://stackoverflow.com/a/6985814/461887
> > >
> > > for i, line in enumerate(input_file):
> > > if i == 0 or not line.startswith('#'):
> > > output.write(line)
> > >
> > > which I would change because it is the first line and I want to rid 

Re: inplace text filter - without writing file

2016-10-01 Thread Sayth Renshaw
On Sunday, 2 October 2016 12:14:43 UTC+11, MRAB  wrote:
> On 2016-10-02 01:21, Sayth Renshaw wrote:
> > Hi
> >
> > I have a fileobject which was fine however now I want to delete a line from 
> > the file object before yielding.
> >
> > def return_files(file_list):
> > for filename in sorted(file_list):
> 
> When joining paths together, it's better to use 'os.path.join'.
> 
> > with open(dir_path + filename) as fd:
> >  for fileItem in fd:
> >  yield fileItem
> >
> > Ned gave an answer over here http://stackoverflow.com/a/6985814/461887
> >
> > for i, line in enumerate(input_file):
> > if i == 0 or not line.startswith('#'):
> > output.write(line)
> >
> > which I would change because it is the first line and I want to rid 

Re: inplace text filter - without writing file

2016-10-01 Thread Sayth Renshaw
Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: inplace text filter - without writing file

2016-10-01 Thread MRAB

On 2016-10-02 01:21, Sayth Renshaw wrote:

Hi

I have a fileobject which was fine however now I want to delete a line from the 
file object before yielding.

def return_files(file_list):
for filename in sorted(file_list):


When joining paths together, it's better to use 'os.path.join'.


with open(dir_path + filename) as fd:
 for fileItem in fd:
 yield fileItem

Ned gave an answer over here http://stackoverflow.com/a/6985814/461887

for i, line in enumerate(input_file):
if i == 0 or not line.startswith('#'):
output.write(line)

which I would change because it is the first line and I want to rid 

inplace text filter - without writing file

2016-10-01 Thread Sayth Renshaw
Hi

I have a fileobject which was fine however now I want to delete a line from the 
file object before yielding.

def return_files(file_list):
for filename in sorted(file_list):
with open(dir_path + filename) as fd:
 for fileItem in fd:
 yield fileItem

Ned gave an answer over here http://stackoverflow.com/a/6985814/461887

for i, line in enumerate(input_file):
if i == 0 or not line.startswith('#'):
output.write(line)

which I would change because it is the first line and I want to rid