472,337 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

trying to find a substring in a string

I'm trying to write what should be a simple script in Python, which
I've never ever used before.

Essentially, I have a text file that has a list of full path file
names to other files, separated by carriage returns.
Contents of first file:
c:\blah.txt
c:\blah1.txt
c:\blah2.txt

The goal is for the user to specify another file, and then search the
specified file for instances of files from the first file.
Contents of user specified file:
file = "c:\blah.txt"
file = "c:\blah1.txt"

My goal is for the program to tell me that it found c:\blah.txt and c:
\blah1.txt.

I've read the contents of the existing file into an array, where each
element is a line from the file. I did the same thing with the user
specified file. I thought it would be a simple nested for loop to find
them, but I'm having no luck finding the strings. The string find
method doesn't do it for me. I've tried regular expressions, but it
never finds a match. I think it doesn't like when I do
re.compile(variableName), but without a debugger I have no way to tell
what's going on at all.

I keep telling myself this should be really simple, but I'm ready to
jump out a window.

Any help would be greatly appreciated. Thanks in advance.
Jun 27 '08 #1
1 1668


ba************@gmail.com wrote:
I'm trying to write what should be a simple script in Python, which
I've never ever used before.

Essentially, I have a text file that has a list of full path file
names to other files, separated by carriage returns.
Contents of first file:
c:\blah.txt
c:\blah1.txt
c:\blah2.txt

The goal is for the user to specify another file, and then search the
specified file for instances of files from the first file.
Contents of user specified file:
file = "c:\blah.txt"
file = "c:\blah1.txt"

My goal is for the program to tell me that it found c:\blah.txt and c:
\blah1.txt.

I've read the contents of the existing file into an array, where each
element is a line from the file.
Put each stripped (to delete \n) line into a set. Then parse out the
filenames and check that they are in the set. Something like

def getname(line): <whatever)

s=set(line.strip() for line in open('allfiles.txt', 'r'))
for line in open('paths.txt'):
if getname(line) not in s:
return '%s not found'%line
else:
return 'all found'

tjr

Jun 27 '08 #2

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

Similar topics

5
by: MyHaz | last post by:
OK i find this a quark in string.find that i think needs some consideration. Normally if a substring is not in the searched_string then...
6
by: JJA | last post by:
I would like some advice on a data and query problem I face. I have a data table with a "raw key" value which is not guaranteed to be valid at its...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information...
2
by: Derek Jones | last post by:
I am currently working on an application for our Business Office to easily search for new budget codes that we have to establish due to an...
29
by: Ajay | last post by:
Hi all,Could anybody tell me the most efficient method to find a substr in a string.
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one...
14
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...?...
2
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I am usign the code below to find the current row and cell. Which works OK. Then hwat I want to do is get the value of each other cell in the row....
4
by: jelle | last post by:
the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0...
4
by: =?Utf-8?B?VG9yZW4gVmFsb25l?= | last post by:
Was editing code, am getting the following errors } expected Type or namespace definition, or end-of-file expected Eyes crossed cannot find code...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
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...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.