From owner-freebsd-python@FreeBSD.ORG Tue Aug 24 14:47:53 2004 Return-Path: Delivered-To: freebsd-python@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CB59816A4CE for ; Tue, 24 Aug 2004 14:47:53 +0000 (GMT) Received: from web25408.mail.ukl.yahoo.com (web25408.mail.ukl.yahoo.com [217.12.10.142]) by mx1.FreeBSD.org (Postfix) with SMTP id DAB8743D55 for ; Tue, 24 Aug 2004 14:47:52 +0000 (GMT) (envelope-from max_russell2000@yahoo.co.uk) Message-ID: <20040824105814.36955.qmail@web25408.mail.ukl.yahoo.com> Received: from [194.247.82.75] by web25408.mail.ukl.yahoo.com via HTTP; Tue, 24 Aug 2004 11:58:14 BST Date: Tue, 24 Aug 2004 11:58:14 +0100 (BST) From: =?iso-8859-1?q?Max=20Russell?= To: freebsd-python@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Splitting elements on a line? X-BeenThere: freebsd-python@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: FreeBSD-specific Python issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2004 14:47:53 -0000 Hello- If I have a file made up of lines like this: one two three four five six seven eight nine how can I read the individual items into a lit, so that I do not get each list item consisting of something like: "one two three" Currently I have this: import os, os.path, random filename = ("C:\list.txt") file = open(filename,"r") word_list = file.readlines() file.close() print word_list # output from this program has format ['one two three\n', 'four five six'] # therefore- need to split each item into individual compenents # also- need to remove whitespace and newline character So: Would I perform a split after all of the above? Would I be better performing the split before reading the items into the list? thanks Max ___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com From owner-freebsd-python@FreeBSD.ORG Tue Aug 24 15:44:10 2004 Return-Path: Delivered-To: freebsd-python@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E9F4416A4CE for ; Tue, 24 Aug 2004 15:44:10 +0000 (GMT) Received: from diligence.flag.rootnode.com (adsl-65-67-81-98.dsl.ltrkar.swbell.net [65.67.81.98]) by mx1.FreeBSD.org (Postfix) with ESMTP id 842E943D55 for ; Tue, 24 Aug 2004 15:44:10 +0000 (GMT) (envelope-from joe@osoft.us) Received: from [10.0.1.105] (coherence.flag.rootnode.com [10.0.1.105]) by diligence.flag.rootnode.com (Postfix) with ESMTP id 45F8ED4AE; Tue, 24 Aug 2004 10:44:09 -0500 (CDT) Message-ID: <412B62C8.5030408@osoft.us> Date: Tue, 24 Aug 2004 10:46:16 -0500 From: Joe Koberg User-Agent: Mozilla Thunderbird 0.7.1 (Windows/20040626) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Max Russell References: <20040824105814.36955.qmail@web25408.mail.ukl.yahoo.com> In-Reply-To: <20040824105814.36955.qmail@web25408.mail.ukl.yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-python@freebsd.org Subject: Re: Splitting elements on a line? X-BeenThere: freebsd-python@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: FreeBSD-specific Python issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2004 15:44:11 -0000 Max Russell wrote: >Hello- >If I have a file made up of lines like this: >... > > >filename = ("C:\list.txt") > > Already answered this off list, but I just noticed you aren't even using FreeBSD! hello! Joe Koberg joe at osoft dot us From owner-freebsd-python@FreeBSD.ORG Tue Aug 24 17:22:12 2004 Return-Path: Delivered-To: freebsd-python@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9770D16A4CE for ; Tue, 24 Aug 2004 17:22:12 +0000 (GMT) Received: from web25406.mail.ukl.yahoo.com (web25406.mail.ukl.yahoo.com [217.12.10.140]) by mx1.FreeBSD.org (Postfix) with SMTP id CD49B43D1F for ; Tue, 24 Aug 2004 17:22:11 +0000 (GMT) (envelope-from max_russell2000@yahoo.co.uk) Message-ID: <20040824150409.67240.qmail@web25406.mail.ukl.yahoo.com> Received: from [194.247.82.75] by web25406.mail.ukl.yahoo.com via HTTP; Tue, 24 Aug 2004 16:04:09 BST Date: Tue, 24 Aug 2004 16:04:09 +0100 (BST) From: =?iso-8859-1?q?Max=20Russell?= To: Max Russell , freebsd-python@freebsd.org In-Reply-To: <20040824105814.36955.qmail@web25408.mail.ukl.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: Splitting elements on a line? X-BeenThere: freebsd-python@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: FreeBSD-specific Python issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2004 17:22:12 -0000 P.S: sorry about the whole "c:\" business. Protype is on Windows. Boo Hiss. --- Max Russell wrote: > Hello- > If I have a file made up of lines like this: > > one two three > four five six > seven eight nine > > how can I read the individual items into a lit, so > that I do not get each list item consisting of > something like: > "one two three" > > Currently I have this: > import os, os.path, random > filename = ("C:\list.txt") > file = open(filename,"r") > word_list = file.readlines() > file.close() > print word_list > > # output from this program has format ['one two > three\n', 'four five six'] > # therefore- need to split each item into individual > compenents > # also- need to remove whitespace and newline > character > > So: > > Would I perform a split after all of the above? > > Would I be better performing the split before > reading > the items into the list? > > thanks > Max > > > > > > ___________________________________________________________ALL-NEW > Yahoo! Messenger - all new features - even more fun! > http://uk.messenger.yahoo.com > _______________________________________________ > freebsd-python@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-python > To unsubscribe, send any mail to > "freebsd-python-unsubscribe@freebsd.org" > ___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com