[Gllug] matching strings in python

dudes dudes akam123 at hotmail.co.uk
Sun Oct 2 10:08:06 UTC 2011




> 
> RTFM :)

TFM has been Read b4 starting the project :P

> http://docs.python.org/library/re.html#matching-vs-searching
> 
> specifically:
> where are these numbers on each line? Are they at the start? if not,
> re.match won't find them without a preceding wildcard.

yes there are one each line and at the start of each 
 
> Also, there's no need for the 'this=...' bit, unless you actually feel
> you need the variable.

yes I need "this" as variable even though it has a different variable name in the source code.
  
> Something like the following
> 
> for line in open('filename'):
>     if re.search('1000[01]', line):
>         print line

 
> is more likely to succeed

YES True, but there are 10.000 different digit numbers, but I only need to find  10 numbers .. such as 10000, 10001, 1286, 3412, 3512, 456, 653,,,etc and they are different. Therefore I need to retrieve one out of these 10 numbers ! 
> 
> > /*It doesn't give me any errors. However; doesn't find the 10000 OR 10001 */
> As Tet says, that's difficult to credit, unless you have selectively
> copied and pasted random bits of your code into this email and changed
> the quoting. Or just attempted to write it in email from memory.

copy and paste doesn't work due to my platform environment settings ! I have typed some part and yes I missed some syntax !
> At the very least:
> 
> * the 'r' on your open(...) line is not quoted
> * The re.match line itself will throw at least one syntax error - all
> characters in your pattern should be inside one set of quotes.

yes True but using DrPython as an editor  won't let you to save the code if you have syntax issues.

> * The second if statement is missing a colon.
> 
> This example was fairly trivial, but if you are asking for help with
> code like this, it would help if you actually post working excerpts from
> it. Or excerpts that throw the errors you are asking about.

agree and thank you :)

> Regards,
> 
> Stuart
> -- 
> Stuart Sears RHCA etc.
> "It's today!" said Piglet.
> "My favourite day," said Pooh.
> --
> Gllug mailing list  -  Gllug at gllug.org.uk
> http://lists.gllug.org.uk/mailman/listinfo/gllug
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20111002/f05f007b/attachment.html>
-------------- next part --------------
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list