Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25035

Re: Discussion on some Code Issues

From subhabangalore@gmail.com
Newsgroups comp.lang.python
Subject Re: Discussion on some Code Issues
Date 2012-07-07 22:42 -0700
Organization http://groups.google.com
Message-ID <09adb3cf-f3f2-4acc-b561-a36dcf15ecc7@googlegroups.com> (permalink)
References <a4f0e2a9-cc3b-4081-beb9-82f229e95ba1@googlegroups.com> <3c4e2ef9-bf7e-4fbc-bf12-6780fdc3e5d4@googlegroups.com> <mailman.1901.1341694286.4697.python-list@python.org>

Show all headers | View raw


On Sunday, July 8, 2012 2:21:14 AM UTC+5:30, Dennis Lee Bieber wrote:
> On Sat, 7 Jul 2012 12:54:16 -0700 (PDT), subhabangalore@gmail.com
> declaimed the following in gmane.comp.python.general:
> 
> > But I am bit intrigued with another question,
> > 
> > suppose I say:
> >   file_open=open("/python32/doc1.txt","r")
> >   file=a1.read().lower()
> >   for line in file:
> >        line_word=line.split()
> > 
> > This works fine. But if I print it would be printed continuously.
> 
> 	"This works fine" -- Really?
> 
> 1)	Why are you storing data files in the install directory of your
> Python interpreter?
> 
> 2)	"a1" is undefined -- you should get an exception on that line which
> makes the following irrelevant; replacing "a1" with "file_open" leads
> to...
> 
> 3)	"file" is a) a predefined function in Python, which you have just
> shadowed and b) a poor name for a string containing the contents of a
> file
> 
> 4) 	"for line in file", since "file" is a string, will iterate over EACH
> CHARACTER, meaning (since there is nothing to split) that "line_word" is
> also just a single character.
> 
> 	for line in file.split("\n"):
> 
> will split the STRING into logical lines (assuming a new-line character
> splits the lines) and permit the subsequent split to pull out wordS
> ("line_word" is misleading, as to will contain a LIST of words from the
> line).
> 
> > I like to store in some variable,so that I may print line of my choice and manipulate them at my choice.
> > Is there any way out to this problem?
> > 
> > 
> > Regards,
> > Subhabrata Banerjee
> -- 
> 	Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Thanks for pointing out the mistakes. Your points are right. So I am trying to revise it,

file_open=open("/python32/doc1.txt","r")
for line in file_open:
         line_word=line.split()
         print (line_word)

To store them the best way is to assign a blank list and append but is there any alternate
method for huge data it becomes tough as the list becomes huge if any way variables may be assigned.

Regards,
Subhabrata Banerjee.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-04 16:21 -0700
  Re: Discussion on some Code Issues Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-05 00:02 +0000
  Re: Discussion on some Code Issues Rick Johnson <rantingrickjohnson@gmail.com> - 2012-07-04 17:08 -0700
  Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-04 20:25 -0700
    Re: Discussion on some Code Issues Peter Otten <__peter__@web.de> - 2012-07-05 09:30 +0200
      Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-05 07:33 -0700
      Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-05 07:33 -0700
        Re: Discussion on some Code Issues Peter Otten <__peter__@web.de> - 2012-07-06 09:35 +0200
  Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-07 12:54 -0700
    Re: Discussion on some Code Issues Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-07 16:51 -0400
      Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-07 22:42 -0700
        Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-08 18:03 +1000
          Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-08 10:05 -0700
            Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-09 03:17 +1000
              Re: Discussion on some Code Issues Roy Smith <roy@panix.com> - 2012-07-08 14:17 -0400
                Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-09 07:54 +1000
                Re: Discussion on some Code Issues Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-09 00:57 +0000
                Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-09 18:41 +1000
                Re: Discussion on some Code Issues Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-09 12:24 +0000
                Re: Discussion on some Code Issues Chris Angelico <rosuav@gmail.com> - 2012-07-10 00:47 +1000
                Re: Discussion on some Code Issues Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-09 12:49 -0400
              Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-16 07:17 -0700
              Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-16 07:17 -0700
            Re: Discussion on some Code Issues MRAB <python@mrabarnett.plus.com> - 2012-07-08 19:27 +0100
          Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-08 10:05 -0700
        Re: Discussion on some Code Issues Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-08 15:07 -0400
      Re: Discussion on some Code Issues subhabangalore@gmail.com - 2012-07-07 22:42 -0700

csiph-web