472,378 Members | 1,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

reading from list with paths

Hello,

I would like to read and print files, of which the complete filepaths
are
mentioned in another textfile. In this textfile (list.txt) are for
example the following paths:

/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/
S01C001M1_1LGPseudo_f01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_f01.TextGrid

I know how to open and read one file in my current directory,
but after trying to find this out my self, I give up...

I already got one answer for this question, but it did not work

Thanks a lot

Antar2

Jun 27 '08 #1
5 1459
Le Wednesday 25 June 2008 20:59:38 antar2, vous avez écrit*:
Hello,

I would like to read and print files, of which the complete filepaths
are
mentioned in another textfile. In this textfile (list.txt) are for
example the following paths:

/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/
S01C001M1_1LGPseudo_f01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_f01.TextGrid

I know how to open and read one file in my current directory,
but after trying to find this out my self, I give up...

I already got one answer for this question, but it did not work
What's the problem exactly ? If you already know how to read a file you have
all what you need:

f_list = open('list.txt')
for filename in f_list :
f = open(filename)
print f.read()
f.close()
f_list.close()

If you get an error, please post the full error message with the backtrace.

--
Cédric Lucantis
Jun 27 '08 #2
On 25 juin, 20:59, antar2 <desoth...@yahoo.comwrote:
Hello,
(snip repost of the very same question)
I already got one answer for this question, but it did not work
For which definition of "did not work" ? How is your code ? What did
you expect, and what did you get ? Sorry to ask these questions, but
my crystal ball is currently down for maintainance...

Jun 27 '08 #3
Lie
On Jun 26, 1:59*am, antar2 <desoth...@yahoo.comwrote:
Hello,

I would like to *read and print files, of which the complete filepaths
are
*mentioned in another textfile. In this textfile (list.txt) *are for
*example the following paths:

/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f01.TextGrid
*/data/chorec/chorec-nieuw/s01/S01C001M1/
*S01C001M1_1LGPseudo_f01.TextGrid
*/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_f01.TextGrid

I know how to open and read one file in my current directory,
*but after trying to find this out my self, I give up...
Is this Window's path or Unix-like's path. In Windows, path is
generally like this:
"folder\\data.txt" OR r"folder\data.txt"
because Windows use backslash as its path separator

In Unix-like OS (Unix, Linux, OSX), they use forward slash.

In general, Windows (Explorer) doesn't care whether you used backslash
or forward slash, but I'm not sure if we can use forwardslash in
Python.

I already got one answer for this question, but it did not work
It didn't work... how? Any error message? or what's the content of the
name that should be file object.
>
Thanks a lot

Antar2
Jun 27 '08 #4

antar2 wrote:
Hello,

I would like to read and print files, of which the complete filepaths
are
mentioned in another textfile. In this textfile (list.txt) are for
example the following paths:

/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/
S01C001M1_1LGPseudo_f01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_f01.TextGrid

I know how to open and read one file in my current directory,
but after trying to find this out my self, I give up...

I already got one answer for this question, but it did not work

Thanks a lot

Antar2

--
http://mail.python.org/mailman/listinfo/python-list
---------------------------------
I think what you want is more like:

contents of a file named printthem.py
......
import os

p = open('list.txt')
for vpath in p:
for f in os.listdir(vpath):
print '\n\tContents of:',vpath+'/'+f
f = open(vpath+'/'+f)
print f.read()
f.close()
print '\n\t\t\t\tEND OF FILE\x0C'
p.close()
print "All Done. Is there any paper left?"
......

usage: python printthem.py >/dev/lp0 Unix
python printthem.py prn: Microsoft

On Microsoft use '\\' in place of '/' following each vpath above
The \x0C is Ctrl-L aka: ff or FormFeed
norseman
Jun 27 '08 #5
On Jun 25, 10:00*pm, norseman <norse...@hughes.netwrote:
antar2 wrote:
Hello,
I would like to *read and print files, of which the complete filepaths
are
*mentioned in another textfile. In this textfile (list.txt) *are for
*example the following paths:
/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f01.TextGrid
*/data/chorec/chorec-nieuw/s01/S01C001M1/
*S01C001M1_1LGPseudo_f01.TextGrid
*/data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_f01.TextGrid
I know how to open and read one file in my current directory,
*but after trying to find this out my self, I give up...
I already got one answer for this question, but it did not work
Thanks a lot
Antar2
--
http://mail.python.org/mailman/listinfo/python-list

---------------------------------
I think what you want is more like:

contents of a file named printthem.py
.....
import os

p = open('list.txt')
for vpath in p:
* *for f in os.listdir(vpath):
* * *print '\n\tContents of:',vpath+'/'+f
* * *f = open(vpath+'/'+f)
* * *print f.read()
* * *f.close()
* * *print '\n\t\t\t\tEND OF FILE\x0C'
p.close()
print "All Done. Is there any paper left?"
.....

usage: python printthem.py >/dev/lp0 * * * * Unix
* * * * python printthem.py prn: * * * * * Microsoft

On Microsoft use '\\' in place of '/' following each vpath above
The \x0C is Ctrl-L * aka: ff or FormFeed

norseman
FYI, Python also understands '\f' ('\x0c').

Interestingly, print repr('\a\b\f\n\r\t\v') gives '\x07\x08\x0c\n\r\t
\x0b'. Is that because '\n', '\r' and '\t' occur so often that it was
decided that they should be treated specially?
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jnc | last post by:
Hi, I was wondering if anybody had any pointers on the following: I need to write some code which takes a list of file paths and transforms them into a treeview which shows the directory...
4
by: James Kunicki | last post by:
Hello, I would like to know if anyone as found a way to list a image next to a list box to indicate what type of drive (local or network) and a folder I would like to present in a user...
2
by: Stu | last post by:
Hi, I am writing a windows forms app that needs to list all the virtual servers and their respective log file paths. The IIS6 metabse is nice and easy as it is XML. Is there any way to...
3
by: tigrrgrr42 | last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am currently bringing them from a byte array into a temp file to pop into word and make word do its thing as a com object. ...
1
by: Vesa Leppanen | last post by:
Hi, I am new in python-list and quite new in Python programming as well. I am working mainly with GIS and using Esri's geoprocessing tools. I want to use .ini file to set the parameters,...
2
by: dave6502 | last post by:
Struggling newbe here, some of my #includes work, some dont. Is it possible to list the include path ? (in BASH), I have looked at the environmental variables (loads of them) but cannot find a...
1
by: antar2 | last post by:
Hello, Suppose this is a stupid question, but as a python beginner I encounter a lot of obstacles... so I would be very grateful with some help for following question: I would like to read...
5
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could...
0
by: drewgy | last post by:
Can anyone tell me how to get a list of full UNC paths for all printers on a network? I have tried using WMI but the following code only gives me a list of local printers, and doesn't give me the...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.