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

overiding assignment in module

Hello.
I would to do something like this.

container = []

p1 = point()
l1 = line()

and i would like to override = method of the module so that its puts
all objects into container.
how i can do something like that.
thanks for help,
viktor.

Oct 25 '05 #1
3 1479
Viktor Marohnic wrote:
I would to do something like this.

container = []

p1 = point()
l1 = line()

and i would like to override = method of the module so that its puts
all objects into container.
how i can do something like that.


you cannot, at least not as you've described the problem. assignment is not
an operator in Python; it's a statement that modifies the current namespace.

things you can do include

- use an explicit target object

x.p1 = point()
x.l1 = line()

- execute the script in a controlled fashion, and inspect the resulting namespace:

myscript = """
p1 = point()
l1 = line()
"""

# create a new namespace, and add "built-in" functions to it
namespace = {}
namespace["point"] = point
namespace["line"] = line

# execute the script in this namespace
exec myscript in namespace

for key, item in namespace.iteritems():
...

</F>

Oct 25 '05 #2
On Tue, 25 Oct 2005 04:56:02 -0700, Viktor Marohnic wrote:
Hello.
I would to do something like this.

container = []

p1 = point()
l1 = line()
Choosing names that look like numbers is terrible practice. Don't use l,
l1, O, ll, and so forth, unless you are trying to deliberately make your
code hard to read, hard to understand, and easy to miss bugs.

and i would like to override = method of the module so that its puts
all objects into container.
What do you mean by put all objects into container?

Do you mean:

container = []
container = point()
container = line()

Or do you mean:

container = []
container.append(point())
container.append(line())

Or even:

container = []
container.insert(0, point())
container.insert(0, line())

Or possibly even:

container = []
container.extend(point())
container.extend(line())
how i can do something like that.


Choose a different language.

There is no assignment method in Python.
--
Steven.

Oct 25 '05 #3
Ok thanks a lot. I think i got the point.
I also thought that it could be possible to do something like this
globals().__setitem__ = custom_setter
but __setitem__ is readonly

Oct 25 '05 #4

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

Similar topics

2
by: anon | last post by:
I'm aware that you can assign a value to an attribute in all class instances by assigning to <Class>.<attribute>, however, my case is slightly different and bizarre. In module node: top,...
2
by: Pankh | last post by:
Hi, Is it possible to restrict overiding a function in derived class? To be more clear, I have base class with function foo() and I do not want any derived class to implement foo() again. Always...
2
by: Chad | last post by:
I'm in an intro to VB.net class. I'm haveing trouble with this assignment, if anyone could help me please let me know. thanks! Coding Assignment 7-Chapter 8 OOP-CSCI-171 Intro to VB.NET ...
3
by: Vincent V | last post by:
Hey im Overiding OnInit in my Custom Page class What i want to be able to do is pass in Some Values Ie PageID PageCategory, PageSubCategory How can i pass in some Vairables So my Custom Page class...
2
by: James | last post by:
Hi. I just had success doing something that I thought should fail. Well maybe I did. I'm not sure. In short, I assigned a locally declared object to a module level object and the module...
25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
1
by: Gemmalouise1988 | last post by:
Hi everyone, My most important college assignment to date seems pretty basic on the outside but I'm sure this will interest a few of you. If you see this document:...
24
by: boblatest | last post by:
Hello, I have an if-elif chain in which I'd like to match a string against several regular expressions. Also I'd like to use the match groups within the respective elif... block. The C-like...
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: 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
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
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
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.