Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Jason Friedman Newsgroups: comp.lang.python Subject: Re: reading from a txt file Date: Thu, 26 Nov 2015 14:04:34 -0700 Lines: 11 Message-ID: References: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de G9pBtjJPu9B+Meb8aGq4tgl84oZ7MpwC2cTuMEwrqgNQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'subject:file': 0.07; 'advance': 0.10; 'received:74.125.82.44': 0.15; 'file.\xc2\xa0': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:txt': 0.16; 'file.': 0.22; 'header:In-Reply-To:1': 0.24; 'wondering': 0.25; 'message-id:@mail.gmail.com': 0.27; 'specifically': 0.28; 'strings,': 0.29; "i'm": 0.30; 'to:name:python-list': 0.30; 'file': 0.34; 'received:google.com': 0.35; 'text': 0.35; '8bit%:4': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'hey,': 0.75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=+AXccbUm7coRAkptrd8bAl+35gkBgeJn5MqeYNx7P0w=; b=uxC/NDUnKiB/rWRHuvdLReBbI03psEjgCaQ/qM+He2AlDXsv7SB88XjzjFlZ9EkRxZ rJSUT8Oo7QnkMiUomRlhuPuvqolGLyDMgvqqtBGlcG/3TLotqyP0MmiHezW5mu5qJMvN px5TZXn/I2QOuyQYJwCearWVE1cl5YMmmxG00GGhTrqiFtCIk+rjJ9kBUM6HUKHBIAph AtYPPZi4rfP+tjsCSqH+Ce3BiOb216Ni+g9bGNOjY7GwyrloCkmNHlr3MFuxXY+cBiKE qvMt5dNrLNCElE24sgfXm8oKiou5znS8InW0RCr7w/coXYsCMJaYO0LIrpfiuX8YpCaw DlQQ== X-Received: by 10.194.235.230 with SMTP id up6mr59904496wjc.178.1448571874837; Thu, 26 Nov 2015 13:04:34 -0800 (PST) In-Reply-To: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99597 > > Hey, I'm wondering how to read individual strings in a text file. I can > read a text file by lines with .readlines() , > but I need to read specifically by strings, not including spaces. Thanks > in advance > How about: for a_string in open("/path/to/file").read().split(): print(a_string)