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


Groups > comp.lang.python > #70678

Re: problem with regex

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: problem with regex
Date 2014-04-28 09:03 -0400
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-8B7422.09035728042014@news.panix.com> (permalink)
References <caeba811-441e-42a0-9b2b-c743205b1f82@googlegroups.com>

Show all headers | View raw


In article <caeba811-441e-42a0-9b2b-c743205b1f82@googlegroups.com>,
 dimmaim@gmail.com wrote:

> i want to find a specific urls from a txt file but i have some issus. First 
> when i take just two lines from the file with copy paste and assign it to a 
> variable like this and it works only with triple quotes
>  
> test='''<long string elided>'''
[...]
> but if a take those lines and save it into a txt file like the original is 
> without the quotes [it doesn't work]

I suspect this has nothing to do with regular expressions, but it's just 
about string management.

The first thing you want to do is verify that the text you are reading 
in from the file is the same as the text you have in triple quotes.  So, 
write a program like this:

test='''<long string elided>'''

datafile=open('a.txt','r')
data_array=''
for line in datafile:
    data_array=data_array+line

print test == data_array

If that prints True, then you've got the same text in both cases (and 
you can go on to looking for other problems).  I suspect it will print 
False, though.  So, now your task is to figure out where those two 
strings differ.  Maybe something like:

for c1, c2 in zip(test, data_array):
    print c1 == c2, repr(c1), repr(c2)

and look for the first place they're not the same.  Hopefully that will 
give you a clue what's going wrong.

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


Thread

problem with regex dimmaim@gmail.com - 2014-04-28 05:52 -0700
  Re: problem with regex Roy Smith <roy@panix.com> - 2014-04-28 09:03 -0400
  Re:problem with regex Dave Angel <davea@davea.name> - 2014-04-28 15:33 -0400

csiph-web