473,404 Members | 2,137 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,404 software developers and data experts.

Tapping into the access of an int instance

Hi,

Does anyone know how to interrupt the lookup of an integer value? I
know I need to subclass int, since builtin types can't be altered
directly...

Below is how far I've come... What I want is to tap into the access of
instance i's value 1...
>>class Int(int):
def __init__(self, *a, **k):
super(Int, self).__init__(self, *a, **k)

>>i = Int(1)
i
1

Regards,
Tor Erik
Sep 20 '07 #1
5 1008
On Sep 20, 1:21 pm, "Tor Erik Sønvisen" <toreri...@gmail.comwrote:
Hi,

Does anyone know how to interrupt the lookup of an integer value? I
know I need to subclass int, since builtin types can't be altered
directly...

Below is how far I've come... What I want is to tap into the access of
instance i's value 1...
>class Int(int):

def __init__(self, *a, **k):
super(Int, self).__init__(self, *a, **k)
>i = Int(1)
i

1

Regards,
Tor Erik
While I'm not *totally* sure what you are asking, you can access the
first parameter you passed in __init__ via args[0].

Sep 20 '07 #2
"Tor Erik Sønvisen" <to*******@gmail.comwrites:
Does anyone know how to interrupt the lookup of an integer value?
AFAIK, int values *aren't* "looked up", in my understanding of that
term.

Can you explain what events you want to intercept?
Below is how far I've come... What I want is to tap into the access
of instance i's value 1...
In many senses "instance i" *is* "value 1".

What "access" do you want to intercept? Can you show some code
examples of things that you would expect to trigger this "access"?
Also, some similar events involving the instance that would *not*
trigger the same thing.

--
\ "The generation of random numbers is too important to be left |
`\ to chance." -- Robert R. Coveyou |
_o__) |
Ben Finney
Sep 20 '07 #3
Tor Erik Sønvisen wrote:
Hi,

Does anyone know how to interrupt the lookup of an integer value? I
know I need to subclass int, since builtin types can't be altered
directly...

Below is how far I've come... What I want is to tap into the access of
instance i's value 1...
>>>class Int(int):
def __init__(self, *a, **k):
super(Int, self).__init__(self, *a, **k)

>>>i = Int(1)
i
1

Regards,
Tor Erik
Perhaps you could elaborate on what you want to do with that value once
you "tap" it.
Sep 21 '07 #4
Tor Erik Sønvisen wrote:
Does anyone know how to interrupt the lookup of an integer value? I
know I need to subclass int, since builtin types can't be altered
directly...

Below is how far I've come... What I want is to tap into the access of
instance i's value 1...
>>>class Int(int):
def __init__(self, *a, **k):
super(Int, self).__init__(self, *a, **k)

>>>i = Int(1)
i
1
You may be looking for __new__() which is invoked before an object is
created. This is particular useful for immutables like int.
>>lookup = {}
class Int(int):
.... def __new__(cls, value, *more):
.... if not more:
.... try:
.... return lookup[value]
.... except KeyError:
.... pass
.... return int.__new__(cls, value, *more)
....
>>lookup["answer"] = Int(42)
Int("answer")
42
>>type(_)
<class '__main__.Int'>

Peter
Sep 21 '07 #5
>>>>ch************@gmail.com (CM) wrote:
>CMOn Sep 20, 1:21 pm, "Tor Erik Sønvisen" <toreri...@gmail.comwrote:
>>Hi,

Does anyone know how to interrupt the lookup of an integer value? I
know I need to subclass int, since builtin types can't be altered
directly...

Below is how far I've come... What I want is to tap into the access of
instance i's value 1...

class Int(int):

def __init__(self, *a, **k):
super(Int, self).__init__(self, *a, **k)

i = Int(1)
i

1

Regards,
Tor Erik
>CMWhile I'm not *totally* sure what you are asking, you can access the
CMfirst parameter you passed in __init__ via args[0].
What args do you mean?
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Oct 2 '07 #6

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

Similar topics

166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
1
by: Alex | last post by:
Acc97 on a subform I have a series of Combo box's which because of my inability to think ahead! I have had to use a field on the last one which I did not intend to use, and bound to it....
15
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I met with a strange issue that derived class function can not access base class's protected member. Do you know why? Here is the error message and code. error C2248:...
0
by: Ahmedhussain | last post by:
Hi everyone, I am totally new to IIS. I somehow configured IIS and now whenever I try to add a website, on testing it gives me the error of authorization, i.e. "Cannot verify access to path :...
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.