re.search('10000|10001', line)<br><br><div class="gmail_quote">On 2 October 2011 10:50, dudes dudes <span dir="ltr"><<a href="mailto:akam123@hotmail.co.uk">akam123@hotmail.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div dir="ltr">
John,<br>I'm using DrPython as an editor on slackware running on V-box.
With some strange reason when I try to copy and paste it to my windows,
doesn't allow me to that. And for that reason I only "typed" very small
parts of the code and during that I have missed " " around r and
possibly some other syntaxes. . Now With DrPython, if you try to save
your change, it won't let you to save it if you syntax issues or parts I
missing ( such as missing " " around r). <br><div class="im"><br>> <br>> If you try your code one step at a time, you'll find that even<br>> your open line has a bug (missing quotes around r):<br>
> <a href="http://docs.python.org/library/functions.html#open" target="_blank">http://docs.python.org/library/functions.html#open</a><br><br></div>You mean missing Syntax !<br> <br>I
don't understand why all of the sudden everyone think I'm wasting their
time !! I just have a deadline for a piece of work that is sue to 1 PM
Europe time <br><br>thanks John for your links <br>ak<br><br><div>> Date: Sun, 2 Oct 2011 10:33:38 +0100<br>> From: <a href="mailto:stuart@sjsears.com" target="_blank">stuart@sjsears.com</a><br>> To: <a href="mailto:gllug@gllug.org.uk" target="_blank">gllug@gllug.org.uk</a><div class="im">
<br>> Subject: Re: [Gllug] matching strings in python<br>> <br></div><div><div></div><div class="h5">> On 02/10/11 09:36, dudes dudes wrote:<br>> > Hello,<br>> > <br>> > Can someone kindly point me my mistake here in this code. I'm trying to<br>
> > search a file for 10000 OR 10001 (in python).<br>> > <br>> > import re;<br>> > <br>> > this= open("file", r)<br>> > for line in this:<br>> > if re.match('(10000)' | '(10001)', line)<br>
> > print line<br>> <br>> RTFM :)<br>> <br>> <a href="http://docs.python.org/library/re.html#matching-vs-searching" target="_blank">http://docs.python.org/library/re.html#matching-vs-searching</a><br>
> <br>> specifically:<br>> where are these numbers on each line? Are they at the start? if not,<br>> re.match won't find them without a preceding wildcard.<br>> <br>> Also, there's no need for the 'this=...' bit, unless you actually feel<br>
> you need the variable.<br>> <br>> Something like the following<br>> <br>> for line in open('filename'):<br>> if re.search('1000[01]', line):<br>> print line<br>> <br>
> is more likely to succeed<br>
> <br>> <br>> > /*It doesn't give me any errors. However; doesn't find the 10000 OR 10001 */<br>> As Tet says, that's difficult to credit, unless you have selectively<br>> copied and pasted random bits of your code into this email and changed<br>
> the quoting. Or just attempted to write it in email from memory.<br>> <br>> At the very least:<br>> <br>> * the 'r' on your open(...) line is not quoted.<br>> <br>> * The re.match line itself will throw at least one syntax error - all<br>
> characters in your pattern should be inside one set of quotes.<br>> <br>> * The second if statement is missing a colon.<br>> <br>> This example was fairly trivial, but if you are asking for help with<br>
> code like this, it would help if you actually post working excerpts from<br>
> it. Or excerpts that throw the errors you are asking about.<br>> <br>> Regards,<br>> <br>> Stuart<br>> -- <br>> Stuart Sears RHCA etc.<br>> "It's today!" said Piglet.<br>> "My favourite day," said Pooh.<br>
> --<br>> Gllug mailing list - <a href="mailto:Gllug@gllug.org.uk" target="_blank">Gllug@gllug.org.uk</a><br>> <a href="http://lists.gllug.org.uk/mailman/listinfo/gllug" target="_blank">http://lists.gllug.org.uk/mailman/listinfo/gllug</a><br>
</div></div></div> </div></div>
<br>--<br>
Gllug mailing list - <a href="mailto:Gllug@gllug.org.uk">Gllug@gllug.org.uk</a><br>
<a href="http://lists.gllug.org.uk/mailman/listinfo/gllug" target="_blank">http://lists.gllug.org.uk/mailman/listinfo/gllug</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Vaidas Jablonskis<br><br>