473,799 Members | 3,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1499
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.iteri tems():
...

</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.appen d(point())
container.appen d(line())

Or even:

container = []
container.inser t(0, point())
container.inser t(0, line())

Or possibly even:

container = []
container.exten d(point())
container.exten d(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().__set item__ = 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
1836
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, left, mid, right = range(4) class Node:
2
1356
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 base version of foo() should be called on any derived class object. Can I do that? Thanks.
2
2765
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 1. Create a Windows application that models a carton of eggs: Define a public class and call it cEggCarton to model the egg carton. Declare a module-scope object variable of type cEggCarton. Since we want the object to persist throughout the life...
3
374
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 can see these Imports System.Web Imports System.Web.UI
2
908
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 level object retained the values of the local even after the local went out of scope.
25
2587
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 constants in Python language. There are some workarounds available, for example the const-module. To me, this looks quite cumbersome and very unintuitive. For the interpreter, in the efficiency-wise, I just cannot tell.
1
1344
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: http://stair.stcoll.ac.uk/jowen/btecsd/pconc/docs/IVA1.pdf and take a brief look to see what it's all about, (a fixtures and points system for a school) take a look on page 3, to see the list of students with their names, house and class. Then look on page 2 to see the...
24
1638
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 idiom that I would like to use is this: if (match = my_re1.match(line): # use match elsif (match = my_re2.match(line)):
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10247
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10214
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.