Is there a module that allows me to find errors that occur due to copy
by reference? I am looking for something like the following:
>>import mydebug mydebug.check copybyreference = True a=2 b=[a] a=4
Traceback (most recent call last):
File "<stdin>", line 1, in ?
CopyByReference Error: Variable b refers to variable a, so please do not
change variable a.
Does such a module exist?
Would it be possible to code such a module?
Would it be possible to add the functionality to array-copying in
numpy?
What would be the extra cost in terms of memory and CPU power?
I realize that this module would disable some useful features of the
language. On the other hand it could be helpful for new python users.
Niels 16 1181
On 9 dic, 02:22, "Niels L Ellegaard" <niels.ellega.. .@gmail.comwrot e:
Is there a module that allows me to find errors that occur due to copy
by reference?
What do you mean by "copy by reference"?
I am looking for something like the following:
>import mydebug mydebug.checkc opybyreference = True a=2 b=[a] a=4
Traceback (most recent call last):
File "<stdin>", line 1, in ?
CopyByReference Error: Variable b refers to variable a, so please do not
change variable a.
(I won't be pedantic to say that Python has no "variables" ). What's
wrong with that code? You are *not* changing "variable a", you are
binding the integer 4 to the name "a". That name used previously to be
bound to another integer, 2 - what's wrong with it? Anyway it has no
effect on the list referred by the name "b", still holds b==[2]
What do you want? Forbid the re-use of names? So once you say a=2, you
can't modify it? That could be done, yes, a "write-once-read-many"
namespace. But I don't see the usefullness.
Does such a module exist?
No
Would it be possible to code such a module?
I don't know what do you want to do exactly, but I feel it's not
useful.
Would it be possible to add the functionality to array-copying in
numpy?
No idea.
What would be the extra cost in terms of memory and CPU power?
No idea yet.
I realize that this module would disable some useful features of the
language.
Not only "some useful features", most programs would not even work!
On the other hand it could be helpful for new python users.
I think you got in trouble with something and you're trying to avoid it
again - but perhaps this is not the right way. Could you provide some
example?
--
Gabriel Genellina
Gabriel Genellina wrote:
I think you got in trouble with something and you're trying to avoid it
again - but perhaps this is not the right way. Could you provide some
example?
I have been using scipy for some time now, but in the beginning I made
a few mistakes with copying by reference. The following example is
exagerated
for clarity, but the principle is the same:
import os
output=[]
firstlines =[0,0]
for filename in os.listdir('.') :
try:
firstlines[0] = open(filename," r").readline s()[0]
firstlines[1] = open(filename," r").readline s()[1]
output.append(( filename,firstl ines))
except:continue
print output
Now some of my fortran-using friends would like to use python to
analyze their data files. I wanted them to avoid making the same
mistakes as I did so I thought it would be good if they could get some
nanny-like warnings saying: "Watch out young man. If do this, then
python will behave differently from fortran and matlab". That could
teach them to do things the right way.
I am not an expert on all this, but I guessed that it would be possible
to make a set of constraints that could catch a fair deal of simple
errors such as the one above, but still allow for quite a bit of
programming.
Niels
In <11************ **********@n67g 2000cwd.googleg roups.com>, Niels L
Ellegaard wrote:
I have been using scipy for some time now, but in the beginning I made
a few mistakes with copying by reference.
But "copying by reference" is the way Python works. Python never copies
objects unless you explicitly ask for it. So what you want is a warning
for *every* assignment.
Ciao,
Marc 'BlackJack' Rintsch
Marc 'BlackJack' Rintsch wrote:
In <11************ **********@n67g 2000cwd.googleg roups.com>, Niels L
Ellegaard wrote:
I have been using scipy for some time now, but in the beginning I made
a few mistakes with copying by reference.
But "copying by reference" is the way Python works. Python never copies
objects unless you explicitly ask for it. So what you want is a warning
for *every* assignment.
Maybe I am on the wrong track here, but just to clarify myself:
I wanted a each object to know whether or not it was being referred to
by a living object, and I wanted to warn the user whenever he tried to
change an object that was being refered to by a living object. As far
as I can see the garbage collector module would allow to do some of
this, but one would still have to edit the assignment operators of each
of the standard data structures: http://docs.python.org/lib/module-gc.html
Anyway you are probably right that the end result would be a somewhat
crippled version of python
Niels
Niels L Ellegaard wrote:
I wanted a each object to know whether or not it was being referred to
by a living object, and I wanted to warn the user whenever he tried to
change an object that was being refered to by a living object. As far
as I can see the garbage collector module would allow to do som
*all* objects in Python are referred to by "living" objects; those that
don't are garbage, and are automatically destroyed sooner or later.
(maybe you've missed that namespaces are objects too?)
</F>
On Sat, 09 Dec 2006 05:58:22 -0800, Niels L Ellegaard wrote:
I wanted a each object to know whether or not it was being referred to
by a living object, and I wanted to warn the user whenever he tried to
change an object that was being refered to by a living object. As far
as I can see the garbage collector module would allow to do some of
this, but one would still have to edit the assignment operators of each
of the standard data structures:
I think what you want is a namespace that requires each object to have
exactly one reference - the namespace. Of course, additional references
will be created during evaluation of expressions. So the best you can do
is provide a function that checks reference counts for a namespace when
called, and warns about objects with multiple references. If that could
be called for every statement (i.e. not during expression evaluation -
something like C language "sequence points"), it would probably catch the
type of error you are looking for. Checking such a thing efficiently would
require deep changes to the interpreter.
The better approach is to revel in the ease with which data can be
referenced rather than copied. I'm not sure it's worth turning python
into fortran - even for selected namespaces.
--
Stuart D. Gathman <st****@bmsi.co m>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
I think what you want is a namespace that requires each object to have
exactly one reference - the namespace. Of course, additional references
will be created during evaluation of expressions. So the best you can do
It's not enough. It won't catch the case where a list holds many
references to the same object - the example provided by the OP.
--
Gabriel Genellina
On 9 dic, 09:08, "Niels L Ellegaard" <niels.ellega.. .@gmail.comwrot e:
Now some of my fortran-using friends would like to use python to
analyze their data files. I wanted them to avoid making the same
mistakes as I did so I thought it would be good if they could get some
nanny-like warnings saying: "Watch out young man. If do this, then
python will behave differently from fortran and matlab". That could
teach them to do things the right way.
Best bet is to learn to use python the right way. It's not so hard...
I am not an expert on all this, but I guessed that it would be possible
to make a set of constraints that could catch a fair deal of simple
errors such as the one above, but still allow for quite a bit of
programming.
The problem is, it's an error only becasuse it's not the *intent* of
the programmer - but it's legal Python code, and useful. It's hard for
the computer to guess the intent of the programmer -yet!...-
--
Gabriel Genellina
Niels L Ellegaard wrote:
I wanted to warn the user whenever he tried to
change an object that was being refered to by a living object.
To see how fundamentally misguided this idea is,
consider that, under your proposal, the following
program would produce a warning:
a = 1
The reason being that the assignment is modifying
the dictionary holding the namespace of the main
module, which is referred to by the main module
itself. So you are "changing an object that is
being referred to by a living object".
--
Greg This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Johann Blake |
last post by:
I can hardly believe I'm the first one to report this, but having gone
through the newsgroup, it appears that way.
I would like to open a solution in the VS.NET IDE that consists of
multiple DLLs and a test application (an .EXE). The .EXE is my startup
application. All the DLLs are shared components. This means that they
contain a key and are stored in the GAC.
When I go to run the test application in the IDE, it will not execute...
|
by: Alexei |
last post by:
Hello,
The following doesn't compile due to absence of the copy constructor in class FileStream:
FileInfo ^ fi = ...;
FileStream fs = fi->OpenRead();
The compiler is Beta 2. Is this supported? Planned to be supported?
|
by: RadekP |
last post by:
Hi Gurus ..
I would really appreciate some insights for the problem that bugs me for
quite some time. I keep my custom controls in their own shared
(private/public key signed) assembly. I need to have it shared. Usually I
work with a Web application project that has a reference to my shared,
custom controls assembly. Web project is a "Startup Project". I need to be
able to set a breakpoint in my Custom Controls (shared) project. VS.NET...
|
by: Brian Bischof |
last post by:
I'm having troubles getting the debugging process to work consistenly for
external classes. I got it to work once and then I turned it off. But now I
can't get re-enabled. Here is what I'm doing. If someone could tell me what
I'm missing that would be great.
1. Create an external class and call it Test.dll.
2. Create a test Asp.net app called App.sln.
3. For App.sln I set a reference to Test.dll.
4. Compile App.sln and run it. The web...
|
by: Brian Bischof |
last post by:
I'm having troubles getting the debugging process to work consistenly for
external classes. I got it to work once and then I turned it off. But now I
can't get re-enabled. Here is what I'm doing. If someone could tell me what
I'm missing that would be great.
1. Create an external class and call it Test.dll.
2. Create a test Asp.net app called App.sln.
3. For App.sln I set a reference to Test.dll.
4. Compile App.sln and run it. The web...
| |
by: Ken Allen |
last post by:
The MSDN documentation on remote debugging is a bit sparse, to say the
least, and there is almost no information available on the 'best' way to
configure this. I should note that my development system is Windows XP
Pro and the test machine is Windows 2003, both running the latest
upgrades; Visual Studio 2005 is installed on the development system and
the .Net 2.0 framework is installed on the test system. The two systems
do not have the...
|
by: Ethan Strauss |
last post by:
Hi,
I have a C#.net Web application which calls a web service
(http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/eutils.wsdl). It has run
just fine for months. Recently I started getting "System.Net.WebException:
The underlying connection was closed" errors. I started the application up in
debugging mode and it ran fine. After fiddling with things for awhile I now
find that it works while I am running in debug mode, but does not when I am...
|
by: puzzlecracker |
last post by:
From my understanding, if you declare any sort of constructors,
(excluding copy ctor), the default will not be included by default. Is
this correct?
class Foo{
public:
Foo(int); // no Foo() is included, i believe.
};
|
by: kenobewan |
last post by:
Congratulations! You are one of the few who realise that over 80% of errors are simple and easy to fix. It is important to realise this as it can save a lot of time. Time that could be wasted making unnecessary changes, that in turn can cause further problems.
Programming is a humbling experience. An experience that causes one to reflect on human error. One major cause of these errors is syntax, syntax, syntax. We tend not to notice when we...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |