Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'exception': 0.03; 'subsequent': 0.04; 'character,': 0.07; 'predefined': 0.07; 'problem?': 0.07; 'suppose': 0.07; 'undefined': 0.07; 'python': 0.09; 'iterate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '"this': 0.13; 'sat,': 0.15; '(assuming': 0.16; 'fine.': 0.16; 'line).': 0.16; 'really?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'splits': 0.16; 'storing': 0.16; 'subject:Discussion': 0.16; 'string': 0.17; 'replacing': 0.17; 'string,': 0.17; 'bit': 0.21; 'file:': 0.22; 'logical': 0.22; 'subject:Code': 0.22; 'split': 0.23; 'header:X-Complaints-To:1': 0.28; 'lines': 0.28; '(since': 0.29; 'character.': 0.29; 'subject:some': 0.29; 'character': 0.29; 'words': 0.29; 'install': 0.29; 'function': 0.30; 'file': 0.32; 'print': 0.32; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'list': 0.35; 'skip:f 40': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'why': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'files': 0.38; 'skip:l 20': 0.38; 'some': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'containing': 0.61; 'email addr:gmail.com': 0.63; 'jul': 0.65; 'say:': 0.84; 'dennis': 0.91; 'choice.': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Discussion on some Code Issues Date: Sat, 07 Jul 2012 16:51:14 -0400 Organization: > Bestiaria Support Staff < References: <3c4e2ef9-bf7e-4fbc-bf12-6780fdc3e5d4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-19-221.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1341694286 news.xs4all.nl 6875 [2001:888:2000:d::a6]:60360 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25032 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/