473,548 Members | 2,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_f 01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/
S01C001M1_1LGPs eudo_f01.TextGr id
/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 1566
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_f 01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/
S01C001M1_1LGPs eudo_f01.TextGr id
/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...@yaho o.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...@yaho o.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_f 01.TextGrid
*/data/chorec/chorec-nieuw/s01/S01C001M1/
*S01C001M1_1LGP seudo_f01.TextG rid
*/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.t xt" OR r"folder\data.t xt"
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_f 01.TextGrid
/data/chorec/chorec-nieuw/s01/S01C001M1/
S01C001M1_1LGPs eudo_f01.TextGr id
/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(vpat h):
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...@hughe s.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_f 01.TextGrid
*/data/chorec/chorec-nieuw/s01/S01C001M1/
*S01C001M1_1LGP seudo_f01.TextG rid
*/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(vpat h):
* * *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
2055
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 structure of the file paths. Cheers.....Jim
4
1988
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 interface like the OpenFileDialog that has a pulldown(at the top of the dialog) to allow a user to navigate a directory/folder selection.
2
4155
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 reading these details from the IIS5 metabase - which appears to be a binary format? Thanks in advance,
3
4644
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. Is it possible to go straight from a byte array to document in word instead of a temp file? Also is there a way to change the save behaviour to...
1
324
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, especially paths, in my project. PythonWin 2.1. is my version. Why do I get the default back in the case below? Any way around?
2
3778
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 reference. Cheers Dave
1
178
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 files, of which the complete filepaths are mentioned in another textfile. In this textfile (list.txt) are for example the following paths:
5
2150
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 be 1 of these or 100....quantity can change***** </Tabs>
0
1359
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 fully qualified paths. private void GetNetworkPrinters() { try { string strQuery = "SELECT *...
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7803
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6036
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3495
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.