Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74008 > unrolled thread
| Started by | rxjwg98@gmail.com |
|---|---|
| First post | 2014-07-06 05:13 -0700 |
| Last post | 2014-07-06 09:01 -0700 |
| Articles | 17 — 9 participants |
Back to article view | Back to comp.lang.python
Why is it different from the example on the tutorial? rxjwg98@gmail.com - 2014-07-06 05:13 -0700
Re: Why is it different from the example on the tutorial? Tim Chase <python.list@tim.thechases.com> - 2014-07-06 07:54 -0500
Re: Why is it different from the example on the tutorial? rxjwg98@gmail.com - 2014-07-06 06:38 -0700
Re: Why is it different from the example on the tutorial? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 07:18 -0700
Re: Why is it different from the example on the tutorial? Roy Smith <roy@panix.com> - 2014-07-06 10:34 -0400
Re: Why is it different from the example on the tutorial? Chris Angelico <rosuav@gmail.com> - 2014-07-07 00:45 +1000
Re: Why is it different from the example on the tutorial? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-06 15:47 +0100
Re: Why is it different from the example on the tutorial? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 08:53 -0700
Re: Why is it different from the example on the tutorial? Roy Smith <roy@panix.com> - 2014-07-06 12:01 -0400
Re: Why is it different from the example on the tutorial? rxjwg98@gmail.com - 2014-07-06 08:03 -0700
Re: Why is it different from the example on the tutorial? Peter Otten <__peter__@web.de> - 2014-07-06 17:46 +0200
Re: Why is it different from the example on the tutorial? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 09:02 -0700
Re: Why is it different from the example on the tutorial? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-06 19:29 +0100
Re: Why is it different from the example on the tutorial? Larry Hudson <orgnut@yahoo.com> - 2014-07-06 13:32 -0700
Re: Why is it different from the example on the tutorial? rxjwg98@gmail.com - 2014-07-06 13:42 -0700
Re: Why is it different from the example on the tutorial? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-06 15:25 +0100
Re: Why is it different from the example on the tutorial? Rustom Mody <rustompmody@gmail.com> - 2014-07-06 09:01 -0700
| From | rxjwg98@gmail.com |
|---|---|
| Date | 2014-07-06 05:13 -0700 |
| Subject | Why is it different from the example on the tutorial? |
| Message-ID | <f949d1c4-98c4-417f-9abc-58fe72b4c0a0@googlegroups.com> |
Hi,
I type the following sample codes on Python, but it echoes differently.
Regular expressions are compiled into pattern objects, which have methods for
various operations such as searching for pattern matches or performing string
substitutions.
>>>
>>> import re
>>> p = re.compile('ab*')
>>> p
<_sre.SRE_Pattern object at 0x...>
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
>>>
Thanks,
[toc] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2014-07-06 07:54 -0500 |
| Message-ID | <mailman.11537.1404651349.18130.python-list@python.org> |
| In reply to | #74008 |
On 2014-07-06 05:13, rxjwg98@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
[toc] | [prev] | [next] | [standalone]
| From | rxjwg98@gmail.com |
|---|---|
| Date | 2014-07-06 06:38 -0700 |
| Message-ID | <c8f935e5-cd8f-4589-a70c-b172a985e22b@googlegroups.com> |
| In reply to | #74009 |
On Sunday, July 6, 2014 8:54:42 AM UTC-4, Tim Chase wrote:
> On 2014-07-06 05:13, rxjwg98@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,
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2014-07-06 07:18 -0700 |
| Message-ID | <21e704ee-648b-423d-8682-11cb310a31a8@googlegroups.com> |
| In reply to | #74014 |
On Sunday, July 6, 2014 8:38:41 AM UTC-5, rxj...@gmail.com wrote:
> When I get match result:
> py>pattern='abcd'
> py>prog = re.compile(pattern)
> py>string='abcd'
> py>result = prog.match(string)
> py>result
> <_sre.SRE_Match object at 0x6ffffeda5e0>
> py>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,
One of the most powerful features of Python,,, for the
noob,,, be documentation strings. With Python you need not
buy expensive books, or venture into seedy and dangerous
alley ways of the inter-webs, no, all you need to do is do
that which any young and inexperienced lad would do when he
finds himself in a troubling situation:
YELL FOR HELP!
The built-in function "help" will answer all your
questions,,, considering you ask the correct questions of
course!,,, but always remember the advice of a wise man and
don't become the "boy who cried wolf" one too many times!
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2014-07-06 10:34 -0400 |
| Message-ID | <roy-3DFFFC.10344406072014@news.panix.com> |
| In reply to | #74015 |
In article <21e704ee-648b-423d-8682-11cb310a31a8@googlegroups.com>, Rick Johnson <rantingrickjohnson@gmail.com> wrote: > On Sunday, July 6, 2014 8:38:41 AM UTC-5, rxj...@gmail.com wrote: > > When I get match result: > > py>pattern='abcd' > > py>prog = re.compile(pattern) > > py>string='abcd' > > py>result = prog.match(string) > > py>result > > <_sre.SRE_Match object at 0x6ffffeda5e0> > > py>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, > > One of the most powerful features of Python,,, for the > noob,,, be documentation strings. I guess I must still be a noob, because I still find them pretty useful! More generically, Python supports "introspection", which means you can ask an object to tell you things about itself. Let's say you've got an object, foo. Here's some useful things you can do to learn more about it: * As Rick points out, you can do help(foo). This is probably the place to start. * You can print dict(foo), which just prints out the attributes the object has. This is really handy when you vaguely remember that a class has some operation, but can't remember the exact name. For example, I use two different database packages, and can never remember which has sort() and which has order_by(). * You can print foo itself, to find out its value, but this can get tricky, since sometimes objects print themselves in confusing ways. Printing repr(foo) will usually get you more detail. * You can print type(foo), to find out exactly what it is (useful when even printing repr() doesn't explain what's going on).
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-07-07 00:45 +1000 |
| Message-ID | <mailman.11541.1404657907.18130.python-list@python.org> |
| In reply to | #74017 |
On Mon, Jul 7, 2014 at 12:34 AM, Roy Smith <roy@panix.com> wrote: > * You can print type(foo), to find out exactly what it is (useful when > even printing repr() doesn't explain what's going on). And very VERY occasionally, print(id(type(foo))) comes in handy, because two types might look the same, but an isinstance check looks (modulo subclassing) at type identity. :) But yes, the info Roy listed is normally what you'll be wanting. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-07-06 15:47 +0100 |
| Message-ID | <mailman.11542.1404658057.18130.python-list@python.org> |
| In reply to | #74017 |
On 06/07/2014 15:34, Roy Smith wrote: > > * You can print foo itself, to find out its value, but this can get > tricky, since sometimes objects print themselves in confusing ways. > Printing repr(foo) will usually get you more detail. > For the OP the pretty print module is usually better than plain old print https://docs.python.org/3/library/pprint.html#module-pprint. I use it like this from pprint import pprint as pp The iPython shell (and presumably others as well) also does a better job of displaying objects than print. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2014-07-06 08:53 -0700 |
| Message-ID | <6fd77d6a-3487-474b-bb96-8da6ab8008f5@googlegroups.com> |
| In reply to | #74017 |
On Sunday, July 6, 2014 9:34:44 AM UTC-5, Roy Smith wrote:
> * You can print dict(foo), which just prints out the attributes the
> object has.
Looks like a typo there.
I think you probably meant to say "dir(foo)"
============================================================
INTERACTIVE SESSION: Python 2.x
============================================================
py> l = range(5)
py> l
[0, 1, 2, 3, 4]
py> dict(l)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
dict(l)
TypeError: cannot convert dictionary update sequence element #0 to a sequence
py> dir(l)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__delslice__', '__doc__', '__eq__', '__format__', '__ge__',
'__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__',
'__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__',
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__',
'__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend',
'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2014-07-06 12:01 -0400 |
| Message-ID | <roy-E5C9E6.12010806072014@news.panix.com> |
| In reply to | #74025 |
In article <6fd77d6a-3487-474b-bb96-8da6ab8008f5@googlegroups.com>, Rick Johnson <rantingrickjohnson@gmail.com> wrote: > On Sunday, July 6, 2014 9:34:44 AM UTC-5, Roy Smith wrote: > > > * You can print dict(foo), which just prints out the attributes the > > object has. > > Looks like a typo there. > > I think you probably meant to say "dir(foo)" This is true. Good catch.
[toc] | [prev] | [next] | [standalone]
| From | rxjwg98@gmail.com |
|---|---|
| Date | 2014-07-06 08:03 -0700 |
| Message-ID | <6928b0db-4f08-4279-aa2e-98f5b70fbc22@googlegroups.com> |
| In reply to | #74015 |
On Sunday, July 6, 2014 10:18:53 AM UTC-4, Rick Johnson wrote: > On Sunday, July 6, 2014 8:38:41 AM UTC-5, rxj...@gmail.com wrote: > > > When I get match result: > > > py>pattern='abcd' > > > py>prog = re.compile(pattern) > > > py>string='abcd' > > > py>result = prog.match(string) > > > py>result > > > <_sre.SRE_Match object at 0x6ffffeda5e0> > > > py>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, > > > > One of the most powerful features of Python,,, for the > > noob,,, be documentation strings. With Python you need not > > buy expensive books, or venture into seedy and dangerous > > alley ways of the inter-webs, no, all you need to do is do > > that which any young and inexperienced lad would do when he > > finds himself in a troubling situation: > > > > YELL FOR HELP! > > > > The built-in function "help" will answer all your > > questions,,, considering you ask the correct questions of > > course!,,, but always remember the advice of a wise man and > > don't become the "boy who cried wolf" one too many times! Thanks. I do not want to waste everyone's time. For a jump start, there are small errors making me frustrating. Your help does help me, confirm the usage etc. After a basic familiarity, I do not want to post more. I use cygwin Python, I type help of an object 'result'. It does show up the help content, but it never quits the help afterwards. It is annoying, and time wasting. (Sorry again, that problem may be about Cygwin, not Python. Excuse me to mention that here. Of course, your help post consumes your time. Thanks again.
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-07-06 17:46 +0200 |
| Message-ID | <mailman.11544.1404661640.18130.python-list@python.org> |
| In reply to | #74021 |
rxjwg98@gmail.com wrote: > I use cygwin Python, > I type help of an object 'result'. It does show up the help content, but > it never quits the help afterwards. It is annoying, and time wasting. To quit help try hitting the 'q' key.
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2014-07-06 09:02 -0700 |
| Message-ID | <ff20fbe1-f8d9-43ce-9ef3-d7ed5c944799@googlegroups.com> |
| In reply to | #74021 |
On Sunday, July 6, 2014 10:03:48 AM UTC-5, rxj...@gmail.com wrote: > Thanks. I do not want to waste everyone's time. Oh NOW you tell us! I could be ranting about flashlights, but here i am wasting time with you again! > For a jump start, there are small errors making me > frustrating. Your help does help me, confirm the usage > etc. How about YOU confirm your OWN usage. I am confident the help function works just fine, can you prove otherwise? We're here to help not to write code for you like slaves. Remember GIGO! > After a basic familiarity, I do not want to post more. I > use cygwin Python, I type help of an object 'result'. It > does show up the help content, but it never quits the help > afterwards. It is annoying, and time wasting. Surely you have a simple Python command line available? Last i heard GvR was giving them away for free! Can you open one and try some interactive musings? If the only tool in your toolbox is a hammer, well, you know the rest...
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-07-06 19:29 +0100 |
| Message-ID | <mailman.11551.1404671355.18130.python-list@python.org> |
| In reply to | #74021 |
On 06/07/2014 16:03, rxjwg98@gmail.com wrote: > > Thanks. I do not want to waste everyone's time. For a jump start, there are > small errors making me frustrating. Your help does help me, confirm the usage > etc. After a basic familiarity, I do not want to post more. I use cygwin Python, > I type help of an object 'result'. It does show up the help content, but it > never quits the help afterwards. It is annoying, and time wasting. (Sorry again, > that problem may be about Cygwin, not Python. Excuse me to mention that here. > Of course, your help post consumes your time. Thanks again. > Don't bother about wasting our time as that's what we're here for :) There is a tutor mailing list that you might feel more comfortable on. See https://mail.python.org/mailman/listinfo/tutor or gmane.comp.python.tutor -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
[toc] | [prev] | [next] | [standalone]
| From | Larry Hudson <orgnut@yahoo.com> |
|---|---|
| Date | 2014-07-06 13:32 -0700 |
| Message-ID | <zomdnUIU6fbSLyTOnZ2dnUVZ_oSdnZ2d@giganews.com> |
| In reply to | #74021 |
On 07/06/2014 08:03 AM, rxjwg98@gmail.com wrote:
<snip>
> Thanks. I do not want to waste everyone's time. For a jump start, there are
> small errors making me frustrating. Your help does help me, confirm the usage
> etc. After a basic familiarity, I do not want to post more. I use cygwin Python,
> I type help of an object 'result'. It does show up the help content, but it
> never quits the help afterwards. It is annoying, and time wasting. (Sorry again,
> that problem may be about Cygwin, not Python. Excuse me to mention that here.
> Of course, your help post consumes your time. Thanks again.
>
I'm curious as to why you're using Cygwin Python. Cygwin is great for using Unix/Linux programs
that are not available in Windows, but there are Windows-native versions of Python available. I
would suggest that you would be better off installing Python directly into Windows instead of
going round-about with Cygwin.
If you do this, I would also suggest that you install Python 3 instead of Python 2, but you may
have to find a different tutorial. Although I suspect that part of your problems are that the
tutorial you're using IS for Python 3 rather than the 2.7 you are using. Really, there aren't a
lot of differences between 2 and 3, but the differences ARE very significant. And 3 is
definitely the better, as well as the future.
(Aside: I do have Cygwin installed on my Windows system, but I have pretty much given up on
using Windows. I find Linux far superior and more comfortable to use, and it gets away from
Big-Brotherish Microsoft. I do use it occasionally, but I think the last time I ran it was at
least two months ago.)
-=- Larry -=-
[toc] | [prev] | [next] | [standalone]
| From | rxjwg98@gmail.com |
|---|---|
| Date | 2014-07-06 13:42 -0700 |
| Message-ID | <b95e6d90-8998-4027-9b6e-06a1de6d4d42@googlegroups.com> |
| In reply to | #74057 |
On Sunday, July 6, 2014 4:32:14 PM UTC-4, Larry Hudson wrote: > On 07/06/2014 08:03 AM, rxjwg98@gmail.com wrote: > > <snip> > > > Thanks. I do not want to waste everyone's time. For a jump start, there are > > > small errors making me frustrating. Your help does help me, confirm the usage > > > etc. After a basic familiarity, I do not want to post more. I use cygwin Python, > > > I type help of an object 'result'. It does show up the help content, but it > > > never quits the help afterwards. It is annoying, and time wasting. (Sorry again, > > > that problem may be about Cygwin, not Python. Excuse me to mention that here. > > > Of course, your help post consumes your time. Thanks again. > > > > > I'm curious as to why you're using Cygwin Python. Cygwin is great for using Unix/Linux programs > > that are not available in Windows, but there are Windows-native versions of Python available. I > > would suggest that you would be better off installing Python directly into Windows instead of > > going round-about with Cygwin. > > > > If you do this, I would also suggest that you install Python 3 instead of Python 2, but you may > > have to find a different tutorial. Although I suspect that part of your problems are that the > > tutorial you're using IS for Python 3 rather than the 2.7 you are using. Really, there aren't a > > lot of differences between 2 and 3, but the differences ARE very significant. And 3 is > > definitely the better, as well as the future. > > > > (Aside: I do have Cygwin installed on my Windows system, but I have pretty much given up on > > using Windows. I find Linux far superior and more comfortable to use, and it gets away from > > Big-Brotherish Microsoft. I do use it occasionally, but I think the last time I ran it was at > > least two months ago.) > > > > -=- Larry -=- Thanks. In fact, I have both Cygwin and Windows version Python, but I incorrectly thought that Cygwin version Python would be closer to Linux than Windows Python. Another thing, I find that Windows Python have a GUI interface. It is good, but it does not have command history as Cygwin has.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-07-06 15:25 +0100 |
| Message-ID | <mailman.11540.1404656725.18130.python-list@python.org> |
| In reply to | #74014 |
On 06/07/2014 14:38, rxjwg98@gmail.com wrote:
> On Sunday, July 6, 2014 8:54:42 AM UTC-4, Tim Chase wrote:
>> On 2014-07-06 05:13, rxjwg98@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,
>
>
>>> help(result)
Help on SRE_Match object:
class SRE_Match(builtins.object)
| The result of re.match() and re.search().
etc
https://docs.python.org/3/library/re.html#module-re
https://docs.python.org/3/library/re.html#match-objects
https://docs.python.org/3/library/re.html#re.match
https://docs.python.org/3/library/re.html#re.search
https://docs.python.org/3/library/re.html#regular-expression-examples
A slight aside, would you please use the mailing list
https://mail.python.org/mailman/listinfo/python-list or read and action
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us
seeing double line spacing and single line paragraphs, thanks.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-07-06 09:01 -0700 |
| Message-ID | <34cc50af-9a3f-4739-bab4-55e4e321cf9a@googlegroups.com> |
| In reply to | #74008 |
On Sunday, July 6, 2014 5:43:55 PM UTC+5:30, rxj...@gmail.com wrote:
> Hi,
> I type the following sample codes on Python, but it echoes differently.
> Regular expressions are compiled into pattern objects, which have methods for
> various operations such as searching for pattern matches or performing string
> substitutions.
> >>> import re
> >>> p = re.compile('ab*')
> >>> p
> 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
1. For *using* regular exps match is fine
For *hacking in the interpreter* I find findall more convenient.
match and findall take the same arguments
2. I wouldn't bother with compile at least at the start
3. Use raw strings for patterns even if it does not seem necessary (below)
$ python
Python 2.7.7 (default, Jun 3 2014, 16:16:56)
[GCC 4.8.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from re import findall
>>> findall(r'ab*', 'abcd')
['ab']
>>> findall(r'ab*', 'abcdab')
['ab', 'ab']
>>> findall(r'ab*', 'abcdabbb')
['ab', 'abbb']
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web