Why is it different from the example on the tutorial?

rxjwg98 at gmail.com rxjwg98 at gmail.com
Sun Jul 6 15:38:41 CEST 2014


On Sunday, July 6, 2014 8:54:42 AM UTC-4, Tim Chase wrote:
> On 2014-07-06 05:13, rxjwg98 at gmail.com wrote:
> 
> > What I get on Python console:
> 
> > 
> 
> > $ python
> 
> > Python 2.7.5 (default, Oct  2 2013, 22:34:09)
> 
> > [GCC 4.8.1] on cygwin
> 
> > Type "help", "copyright", "credits" or "license" for more
> 
> > information.
> 
> > >>> import re
> 
> > >>> p = re.compile('ab*')
> 
> >   File "<stdin>", line 1
> 
> >     p = re.compile('ab*')
> 
> >     ^
> 
> > SyntaxError: invalid syntax
> 
> > >>>
> 
> 
> 
> Are you sure that you copied/pasted that directly from the console
> 
> instead of transcribing it with some mistake?
> 
> 
> 
> I just did the same thing at the console and it worked perfectly
> 
> fine
> 
> 
> 
> $ python
> 
> Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
> 
> [GCC 4.7.2] on linux2
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> import re
> 
> >>> p = re.compile('ab*')
> 
> >>>
> 
> 
> 
> 
> 
> -tkc
Thanks. It did be caused by unclear copy&paste. I shall be careful in future.

When I enter:
>>>counter=100
>>>counter
100

When I get match result:

>>>pattern='abcd'
>>>prog = re.compile(pattern)
>>>string='abcd'
>>>result = prog.match(string)
>>>result
<_sre.SRE_Match object at 0x6ffffeda5e0>

>>>result.group(0)
'abcd'

It looks like 'result' is different from a simple 'counter' variable. I do not
yet find the definition of 'result' object. What do you call 'result' object?
Where can I find it (what topic would be in a tutorial)?

Thanks,





More information about the Python-list mailing list