473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

re module methods: flags(), pattern()

Python re module has methods flags and pattern. How to use these
exactly?

e.g. i tried

print patternObj.flags()

and the error is some "int object is not callable".

newpattern=re.compile(ur'\w+',patternObj.flags())

also bad.

similar error for patternObj.pattern(). (and i suppose the same for
groupindex() )

thanks.

Xah
xa*@xahlee.org
∑ http://xahlee.org/

Jul 19 '05 #1
3 2306
Xah Lee wrote:
Python re module has methods flags and pattern. How to use these
exactly?

e.g. i tried

print patternObj.flags()

and the error is some "int object is not callable".


Where do you read "methods"?

Reinhold
Jul 19 '05 #2
Xah Lee wrote:
Python re module has methods flags and pattern. How to use these
exactly? From the Python 2.3 documentation, section 2.4.2
flags

The flags argument used when the RE object was compiled, or 0 if no
flags were provided.
groupindex

A dictionary mapping any symbolic group names defined by (?P<id>) to
group numbers. The dictionary is empty if no symbolic groups were used
in the pattern.

pattern

The pattern string from which the RE object was compiled.
Comments derived from the docs and error messages:
e.g. i tried

print patternObj.flags()

and the error is some "int object is not callable".
=> flags is an int object

newpattern=re.compile(ur'\w+',patternObj.flags())

also bad.
=> flags is still an int object

similar error for patternObj.pattern().
=> pattern is a string
(and i suppose the same for
groupindex() )
=> groupindex is a dict

thanks.

Xah
xa*@xahlee.org
∑ http://xahlee.org/


The documentation is not that bad that one should not read it at all ;)
If You wrestle with regexps I can recommend an old but still usefull
little wrapper I found eventually on the "Vaults of Parnassus" which is
called reverb.py

Ciao,
Kay

Jul 19 '05 #3

A flag is just an int. From the re doc, you can see
there is a ignorecase flag:

"
I
IGNORECASE
Perform case-insensitive matching; expressions like [A-Z] will
match lowercase letters, too. This is not affected by the current locale.
"

Using the ignorecase flag:
import re
print re.I 2 print re.IGNORECASE 2 r = re.compile("hello", re.IGNORECASE)
print r.pattern 'hello' match = r.search("heLLo")
match.group()
'heLLo'

As the doc says, you can combine several flags with the '|' operator:
r = re.compile("your_regexp", re.SOMEFLAG|re.SOMEOTHERFLAG)
Xah Lee wrote: Python re module has methods flags and pattern. How to use these
exactly?

e.g. i tried

print patternObj.flags()

and the error is some "int object is not callable".

newpattern=re.compile(ur'\w+',patternObj.flags())

also bad.

similar error for patternObj.pattern(). (and i suppose the same for
groupindex() )

thanks.

Xah
xa*@xahlee.org
∑ http://xahlee.org/

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Berteun Damman | last post by:
Hello, First I was trying to get PyOSD, but as soon as I did `import pyosd' Python received a SIGABRT. Then I wrote my own module, which looks like: #include <Python.h> static PyMethodDef...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
16
by: A_PK | last post by:
Hi, I am a VB.net beginner, I do not know what are the major difference between Module vs Class. Could someone guide me when is the best situation to use Module or Class. I have no idea...
0
by: Ron Adam | last post by:
I've made a few more changes to my little collate module. There might be better ways to handle the options, or better choices for the options themselves. I tried to keep it as general as...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
5
by: Mail.To.Nathaniel | last post by:
Hello :) I am new to python and I don't have much expirience in object-oriented technologies neither. The problem is the following: I have to create a simple python template script that will...
1
by: Tomohiro Kusumi | last post by:
Hi, I have a question regarding re module. # By the way I'm not in this list, so I'm sorry but please CC me. I tried following code in Python shell using a regular expression. Why doesn't the...
3
by: Tomohiro Kusumi | last post by:
Diez, Thanks, you're right. Delegated attributes are not in the dir() result. '+' 0 {} Tomohiro Kusumi
6
by: anton | last post by:
Hi, I want to replace all occourences of " by \" in a string. But I want to leave all occourences of \" as they are. The following should happen: this I want " while I dont want this \"
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.