newbie how do I interpret this?

B

bobueland

Here's a small session
import re
p=re.compile('[a-z]+')
m=p.match('abb1a')
dir(m)
['__copy__', '__deepcopy__', 'end', 'expand', 'group', 'groupdict',
'groups', 'span', 'start']Help on built-in function groups:

groups(...)

My question is. How do I interpret the hiven help info
groups(...)

alt1. Tough luck. There's no help. People are to busy to write
reference manuals.
alt 2. There are no parameters. The only possibility is m.groups()
alt3. Something else

Thanks Bob
 
F

Fredrik Lundh

Help on built-in function groups:

groups(...)


My question is. How do I interpret the hiven help info
groups(...)

alt1. Tough luck. There's no help. People are to busy to write
reference manuals.

they're busy writing reference manuals, you mean:

http://docs.python.org/lib/match-objects.html
alt 2. There are no parameters. The only possibility is m.groups()

in this case, that happens to be the most common way to use
the method.
alt3. Something else

the words "built-in function" means that the function is im-
plemented in C, and is therefore outside the reach of Python's
introspection mechanisms. In this case, there don't seem to
be any custom docstring associated with this method, so the
above is all help() can tell you at the moment. This may of
course change in future releases.

</F>
 
M

Mike Meyer

Here's a small session
import re
p=re.compile('[a-z]+')
m=p.match('abb1a')
dir(m)
['__copy__', '__deepcopy__', 'end', 'expand', 'group', 'groupdict',
'groups', 'span', 'start']Help on built-in function groups:

groups(...)

My question is. How do I interpret the hiven help info
groups(...)

alt1. Tough luck. There's no help. People are to busy to write
reference manuals.
alt 2. There are no parameters. The only possibility is m.groups()
alt3. Something else

alt 3, specifically: No doc string, time to check the reference manual.

<URL: http://docs.python.org/lib/match-objects.html > says:

groups( [default])
Return a tuple containing all the subgroups of the match, from
1 up to however many groups are in the pattern. The default
argument is used for groups that did not participate in the
match; it defaults to None. (Incompatibility note: in the
original Python 1.5 release, if the tuple was one element
long, a string would be returned instead. In later versions
(from 1.5.1 on), a singleton tuple is returned in such cases.)

Since you don't have any groups in your re, groups is always going to
return (). You probably want group().

<mike
 
B

bobueland

Thanks for the reply

I didn't realise the meaning of ""built-in function". Also I thought
that help( ) mirrored the info in reference manual, which it obviously
does not. Thanks again for a good answer and the link.
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top