Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99597
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Jason Friedman <jsf80238@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: reading from a txt file |
| Date | Thu, 26 Nov 2015 14:04:34 -0700 |
| Lines | 11 |
| Message-ID | <mailman.153.1448571876.20593.python-list@python.org> (permalink) |
| 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 | <jsf80238@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:99597 |
Show key headers only | View raw
>
> 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)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
reading from a txt file vincentypedro@gmail.com - 2015-11-26 12:34 -0800
Re: reading from a txt file Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-26 20:50 +0000
Re: reading from a txt file Jason Friedman <jsf80238@gmail.com> - 2015-11-26 14:04 -0700
Re: reading from a txt file Gary Herron <gherron@digipen.edu> - 2015-11-26 13:01 -0800
Re: reading from a txt file Pedro Vincenty <vincentypedro@gmail.com> - 2015-11-26 17:24 -0800
Re: reading from a txt file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-26 21:44 -0500
csiph-web