473,387 Members | 1,536 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,387 software developers and data experts.

Re: Question regarding re module

Diez,

Thanks, you're right.
Delegated attributes are not in the dir() result.
>>getattr(reg, "pattern")
'[0-9]+'
>>getattr(reg, "flags")
0
>>getattr(reg, "groupindex")
{}

Tomohiro Kusumi
Tomohiro Kusumi schrieb:
>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 result of dir(reg) have 'pattern', 'flags', and
'groupindex' although they exist as members of _sre.SRE_Pattern
instance ?

It sort of irritates me, because whenever I write Python code
using a module which I'm not used to using, I often try Python
shell with TAB complete to find out the member of module/instance.
It could be that the result overloads the __getattr__-method to delegate
calls to some object. Thus it's not part of the outer instance.

Diez


Jun 27 '08 #1
3 945
On Jun 5, 7:11*am, Tomohiro Kusumi <kusumi.tomoh...@jp.fujitsu.com>
wrote:
>
It could be that the result overloads the __getattr__-method to delegate
calls to some object. Thus it's not part of the outer instance.
Didn't I read that Py3 will support a __dir__ method so that classes
*could* report such pseudo-attributes in response to dir?

-- Paul
Jun 27 '08 #2
Paul McGuire wrote:
On Jun 5, 7:11 am, Tomohiro Kusumi <kusumi.tomoh...@jp.fujitsu.com>
wrote:
>>It could be that the result overloads the __getattr__-method to delegate
calls to some object. Thus it's not part of the outer instance.

Didn't I read that Py3 will support a __dir__ method so that classes
*could* report such pseudo-attributes in response to dir?
It's already there in 2.6:

.... class X (object):
.... def __init__ (self, a, b):
.... self.a = a
.... self.b = b
.... def __dir__ (self):
.... return ['a', 'b', 'c']
....
>>dir (X (1, 2))
['a', 'b', 'c']
>>>
TJG
Jun 27 '08 #3
It could be that the result overloads the __getattr__-method to delegate
calls to some object. Thus it's not part of the outer instance.

Didn't I read that Py3 will support a __dir__ method so that classes
*could* report such pseudo-attributes in response to dir?

-- Paul

I don't believe that it possibly could:

class foo(object):

def __getattr__(self, what):
if what[0] == 't':
return True

f = foo()

print f.toby
** Posted from http://www.teranews.com **
Jun 27 '08 #4

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

Similar topics

3
by: praba kar | last post by:
Dear All, In Php we can do all the mailing operations like sending a text as a message, adding attachment to a mail, adding additional headers and so on using Mail_mime class. I want to know...
0
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils...
3
by: Samuel | last post by:
I wrote a very simple httpmodule and tried to compile it with no success. This is my code: ============== Imports System Imports System.Web Imports Microsoft.VisualBasic NameSpace...
8
by: Paminu | last post by:
I am trying to split my program in different parts. I have a file called mainfile.c that contains the main() function, some global variables and a few other functions. I then have a file...
4
by: fh1996 | last post by:
csc /target:module MyMod.cs What's meaning of "NETMODULE"? Is /target:module always going to generate xxx.netmodule? Does C# compiler only generate the following 3 types of files: .EXE, .DLL...
10
by: sam_cit | last post by:
Hi Everyone, I had a doubt regarding extern decleration, i tried this is one source file, extern int sample; extern int sample; int main() {
1
by: Jim Flanagan | last post by:
Hello - I am in need of more help regarding an approach to accomplishing the following: We have a need to change the Volume serial numbers of a bunch of preprogrammed IDE Solid State Drive...
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...
25
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.