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


Groups > comp.lang.python > #72412

Re: How to read a directory path from a txt file

Newsgroups comp.lang.python
Date 2014-06-02 07:28 -0700
References <a3298f5d-dcf9-4dd7-bae8-b655e8224114@googlegroups.com>
Message-ID <234b1dbc-97be-4fd8-84e2-f44d9ec57edc@googlegroups.com> (permalink)
Subject Re: How to read a directory path from a txt file
From Rustom Mody <rustompmody@gmail.com>

Show all headers | View raw


On Monday, June 2, 2014 7:48:25 PM UTC+5:30, Samuel Kamau wrote:
> I have created a txt file with various paths to directories. The paths look like this
> 
> /home/wachkama/Desktop/api/genshi
> 
> /home/wachkama/Desktop/www/portal/schedule
> 
> /home/wachkama/Desktop/show/help.genshi
> 
> 
> 
> How do i read this paths in python ?

for x in open("filenames.txt"):
   print x

Assuming your filenames are in a file called filenames.txt in current directory

Also in practice:
1. You probably want print x.strip()
2. You dont want a print but whatever is the code you want

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


Thread

How to read a directory path from a txt file Samuel Kamau <wachkama@gmail.com> - 2014-06-02 07:18 -0700
  Re: How to read a directory path from a txt file Rustom Mody <rustompmody@gmail.com> - 2014-06-02 07:28 -0700
  Re: How to read a directory path from a txt file Chris Angelico <rosuav@gmail.com> - 2014-06-03 00:29 +1000
  Re: How to read a directory path from a txt file Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-06-02 15:44 +0100
  Re: How to read a directory path from a txt file Samuel Kamau <wachkama@gmail.com> - 2014-06-02 08:13 -0700
    Re: How to read a directory path from a txt file Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-02 16:24 +0000
      Re: How to read a directory path from a txt file Samuel Kamau <wachkama@gmail.com> - 2014-06-02 10:18 -0700

csiph-web