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


Groups > comp.lang.python > #72411 > unrolled thread

How to read a directory path from a txt file

Started bySamuel Kamau <wachkama@gmail.com>
First post2014-06-02 07:18 -0700
Last post2014-06-02 10:18 -0700
Articles 7 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  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

#72411 — How to read a directory path from a txt file

FromSamuel Kamau <wachkama@gmail.com>
Date2014-06-02 07:18 -0700
SubjectHow to read a directory path from a txt file
Message-ID<a3298f5d-dcf9-4dd7-bae8-b655e8224114@googlegroups.com>
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 ?

[toc] | [next] | [standalone]


#72412

FromRustom Mody <rustompmody@gmail.com>
Date2014-06-02 07:28 -0700
Message-ID<234b1dbc-97be-4fd8-84e2-f44d9ec57edc@googlegroups.com>
In reply to#72411
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

[toc] | [prev] | [next] | [standalone]


#72413

FromChris Angelico <rosuav@gmail.com>
Date2014-06-03 00:29 +1000
Message-ID<mailman.10559.1401719388.18130.python-list@python.org>
In reply to#72411
On Tue, Jun 3, 2014 at 12:18 AM, Samuel Kamau <wachkama@gmail.com> 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 ?

This sounds like homework. You'll need to go back to the problem
you've been given, figure out what you're actually trying to
accomplish, and then break that down into several pieces. We're happy
to help you learn, but we will not just do the assignment for you, as
that's counter-productive for all of us.

If it *isn't* homework, please explain in much more detail what it is
you're trying to do here.

ChrisA

[toc] | [prev] | [next] | [standalone]


#72414

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-06-02 15:44 +0100
Message-ID<mailman.10560.1401720230.18130.python-list@python.org>
In reply to#72411
On 02/06/2014 15:18, 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 ?
>

https://docs.python.org/3/library/functions.html#open
https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#72416

FromSamuel Kamau <wachkama@gmail.com>
Date2014-06-02 08:13 -0700
Message-ID<3a3c89ee-aa7a-4be7-a868-348bc5a0f75e@googlegroups.com>
In reply to#72411
On Monday, June 2, 2014 10:18:25 AM UTC-4, 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 ?

I have permission issues with my web server. So I have written part of my script to read and write the current paths in the web servers with its username and group name into a txt file. I want my script to replace the new permissions on my web server with the permissions written on my txt file. So The last part of my script is the tricky part. How to read the txt file and go to all the paths and rewrite the permissions as per what is on the txt file.

[toc] | [prev] | [next] | [standalone]


#72424

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-06-02 16:24 +0000
Message-ID<lmi8gr$2eg$2@dont-email.me>
In reply to#72416
On Mon, 02 Jun 2014 08:13:23 -0700, Samuel Kamau wrote:

> I have permission issues with my web server.

Hacks to fix permissions problems are dangerous. There is probably a 
better way to fix this issue.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#72429

FromSamuel Kamau <wachkama@gmail.com>
Date2014-06-02 10:18 -0700
Message-ID<ada7a2ce-5a02-437b-8036-7d082433106e@googlegroups.com>
In reply to#72424
On Monday, June 2, 2014 12:24:59 PM UTC-4, Denis McMahon wrote:
> On Mon, 02 Jun 2014 08:13:23 -0700, Samuel Kamau wrote:
> 
> 
> 
> > I have permission issues with my web server.
> 
> 
> 
> Hacks to fix permissions problems are dangerous. There is probably a 
> 
> better way to fix this issue.
> 
> 
> 
> -- 
> 
> Denis McMahon, denismfmcmahon@gmail.com

The issue is that i use jenkins to deploy my files to the web server. Jenkins takes possession of all files as username and group name. This over right the right permissions on the web server. I want the script to be restoring the right privileges after jenkins deploys a new build.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web