473,734 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Very weird behavior that's driving me crazy

Hello,
I am experiencing a weird behavior that is driving me crazy. I have module
called Sensors containing, among other things:

class Manager:
def getStatus(self) :
print "getStatus(self =%s)" % self
return {"a": "b", "c": "d"}

and then I have another module called SensorSingleton that emulates the
hard-to-code-on-python singleton in this way:

manager = Manager()
print "manager=%s " % manager
def getStatus():
print "getStatus( )"
return manager.getStat us()

and then in some other module, I import SensorSingleton and I do, among
other things:

print SensorSingleton .getStatus()

and the output is more or less like this. First, the manager:

manager: <Sensor.Manag er object at 0xb7b9efec>

ok, then

Manager.getStat us(self=<Sensor .Manager object at 0xb77cde8c>) =>
{"a": "b", "c": "d"}
None

None is the return of SensorSingleton .getStatus(), now, my questions are:

- Shouldn't the manager be the same in the first print and the second, that
is, the id is different, shouldn't it be the same ?
- What happened with all the output of SensorSingleton .getStatus() ? there's
no trace of it (but there's output of the method it calls).
- Why doesn't the SensorSingleton .getStatus() return the return value of
manager.getStat us(), it's a very straight forward call to it and return it.

Thank you.
--
Pupeno <pu****@pupeno. com(http://pupeno.com)
Aug 16 '06 #1
5 1713
In <44************ ***********@new sspool4.arcor-online.net>, Pupeno wrote:
- Shouldn't the manager be the same in the first print and the second, that
is, the id is different, shouldn't it be the same ?
- What happened with all the output of SensorSingleton .getStatus() ? there's
no trace of it (but there's output of the method it calls).
- Why doesn't the SensorSingleton .getStatus() return the return value of
manager.getStat us(), it's a very straight forward call to it and return it.
How have you tested this? Is there any chance it was an interactive
session and you forgot to reload the module after making changes to it?

Ciao,
Marc 'BlackJack' Rintsch
Aug 16 '06 #2
Pupeno wrote:
Hello,
I am experiencing a weird behavior that is driving me crazy. I have module
called Sensors containing, among other things:

class Manager:
def getStatus(self) :
print "getStatus(self =%s)" % self
return {"a": "b", "c": "d"}

and then I have another module called SensorSingleton that emulates the
hard-to-code-on-python singleton in this way:

manager = Manager()
print "manager=%s " % manager
def getStatus():
print "getStatus( )"
return manager.getStat us()

and then in some other module, I import SensorSingleton and I do, among
other things:

print SensorSingleton .getStatus()

and the output is more or less like this. First, the manager:

manager: <Sensor.Manag er object at 0xb7b9efec>

ok, then

Manager.getStat us(self=<Sensor .Manager object at 0xb77cde8c>) =>
{"a": "b", "c": "d"}
None

None is the return of SensorSingleton .getStatus(), now, my questions are:

- Shouldn't the manager be the same in the first print and the second, that
is, the id is different, shouldn't it be the same ?
- What happened with all the output of SensorSingleton .getStatus() ? there's
no trace of it (but there's output of the method it calls).
- Why doesn't the SensorSingleton .getStatus() return the return value of
manager.getStat us(), it's a very straight forward call to it and return it.

Thank you.
--
Pupeno <pu****@pupeno. com(http://pupeno.com)
The code you posted doesn't match the output you posted. Try coding
the smallest version of what you're trying to do and post its output.

Peace,
~Simon

Aug 16 '06 #3
Nevermind, it was fixed. Thanks.

Pupeno wrote:
Hello,
I am experiencing a weird behavior that is driving me crazy. I have module
called Sensors containing, among other things:

class Manager:
def getStatus(self) :
print "getStatus(self =%s)" % self
return {"a": "b", "c": "d"}

and then I have another module called SensorSingleton that emulates the
hard-to-code-on-python singleton in this way:

manager = Manager()
print "manager=%s " % manager
def getStatus():
print "getStatus( )"
return manager.getStat us()

and then in some other module, I import SensorSingleton and I do, among
other things:

print SensorSingleton .getStatus()

and the output is more or less like this. First, the manager:

manager: <Sensor.Manag er object at 0xb7b9efec>

ok, then

Manager.getStat us(self=<Sensor .Manager object at 0xb77cde8c>) =>
{"a": "b", "c": "d"}
None

None is the return of SensorSingleton .getStatus(), now, my questions are:

- Shouldn't the manager be the same in the first print and the second,
that is, the id is different, shouldn't it be the same ?
- What happened with all the output of SensorSingleton .getStatus() ?
there's no trace of it (but there's output of the method it calls).
- Why doesn't the SensorSingleton .getStatus() return the return value of
manager.getStat us(), it's a very straight forward call to it and return
it.

Thank you.
--
Pupeno <pu****@pupeno. com(http://pupeno.com)
Aug 16 '06 #4

Pupeno wrote:
Hello,
I am experiencing a weird behavior that is driving me crazy. I have module
called Sensors containing, among other things:

class Manager:
def getStatus(self) :
print "getStatus(self =%s)" % self
return {"a": "b", "c": "d"}

and then I have another module called SensorSingleton that emulates the
hard-to-code-on-python singleton in this way:

manager = Manager()
print "manager=%s " % manager
def getStatus():
print "getStatus( )"
return manager.getStat us()

and then in some other module, I import SensorSingleton and I do, among
other things:

print SensorSingleton .getStatus()

and the output is more or less like this. First, the manager:

manager: <Sensor.Manag er object at 0xb7b9efec>
### Uh-oh. The code should print "manager=", not "manager:"
>
ok, then

Manager.getStat us(self=<Sensor .Manager object at 0xb77cde8c>) =>
### Uh-oh. The code should print "getStatus(self =blahblahblah" i.e.
without "Manager." in the front.
{"a": "b", "c": "d"}
None

None is the return of SensorSingleton .getStatus(),
### What evidence do you have for that statement?

now, my questions are:
>
- Shouldn't the manager be the same in the first print and the second, that
is, the id is different, shouldn't it be the same ?
### Yes.
- What happened with all the output of SensorSingleton .getStatus() ? there's
no trace of it (but there's output of the method it calls).
### All what output? The only expected output is "getStatus( )"
- Why doesn't the SensorSingleton .getStatus() return the return value of
manager.getStat us(), it's a very straight forward call to it and return it.
If you want help, forget the "more or less" caper -- it's useless. It's
obvious from the above that the output that you describe can *not* have
come from the code fragments that you showed.Cut your 3 modules down to
the bare minimum that still shows the bug. Include copies of those plus
the exact (copy/paste) results of running the test at the OS
command-line (I.e. not in an IDE). Do make sure that none of your
modules are being shadowed or are outdated -- have all 3 in your
current working directory, and delete all .pyc files before running the
test.

What version of Python are you running? 2.3? Which platform?

Below's what I tried -- it's essentially the same as your code, with a
bit more output and with lower-case module names and I didn't bother
with a 2-line calling module. It works as expected.

HTH,
John

C:\junk>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright" , "credits" or "license" for more information.
|>>import singleton
[singleton] manager=<sensor s.Manager instance at 0x00AF43A0>
|>>singleton.ge tStatus()
[singleton] entered getStatus()
[sensors]getStatus(self <sensors.Manage r instance at 0x00AF43A0>)
[singleton] stuff = {'a': 'b', 'c': 'd'}
{'a': 'b', 'c': 'd'}
|>>^Z

C:\junk>type sensors.py
class Manager:
def getStatus(self) :
print "[sensors]getStatus(self %s)" % self
return {"a": "b", "c": "d"}

C:\junk>type singleton.py
from sensors import Manager
manager = Manager()
print "[singleton] manager=%s" % manager
def getStatus():
print "[singleton] entered getStatus()"
stuff = manager.getStat us()
print "[singleton] stuff =", stuff
return stuff
8<---

Aug 16 '06 #5
Pupeno a écrit :
(snip)
>
and then I have another module called SensorSingleton that emulates the
hard-to-code-on-python singleton (snip)
What do you mean "hard to code on python singleton" ?
Aug 27 '06 #6

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

Similar topics

1
4081
by: Robertb | last post by:
I'm driving myself crazy trying to figure this one out. So much so that I think I'm within walking distance now! The program is written and compiled in Visual Basic 6 with SP5. The OS is Windows XP Professional. The other day, it worked just fne. Today it doesn't. I had this same problem a few weeks ago, but it mysteriously went away. Well, now it's back. What did I change? I have no idea. Lot's of stuff, I suppose. I don't...
4
2533
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys() sorted_feature_vector.sort() #feature_vector.keys()=sorted_feature_vector
1
2104
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the content of an untyped DataSet. This is to be done in the "DropDown" Event (since the dataset is empty at program start). If I go with this:
0
1154
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the content of an untyped DataSet. This is to be done in the "DropDown" Event (since the dataset is empty at program start). If I go with this:
6
2535
by: Calvin Lai | last post by:
Hi all, I have the following code which should work. However, an exception ( InvalidOperationException) was thrown which doesn't make sense to me. line 1: foreach (string name in _fieldMaps.Keys) line 2: _fieldMaps = 1; where _fieldMaps is a hashtable containing (string, int) pairs internally.
0
1190
by: Jeremy | last post by:
I have written my own URL rewriter, and it was working fine until i moved the re-writing code from App_BeginRequest to App_AuthorizeRequest. Now I get a 404 (file not found) error whenever the request doesn't have a query string. If I add a query string, it works fine. The really weird thing is that when I turn tracing on, the 404 goes away! This is driving me crazy. Here are some sample URLs: (tracing enabled = False) Rewritten...
0
1308
by: Shapper | last post by:
Hello, I have this code in Global.asax: Sub Session_Start(Sender As Object, E As EventArgs) Dim cookie As HttpCookie = Request.Cookies("MyCookie") If Not cookie Is Nothing Then Response.Write(" * Cookie Exists * ") If Not cookie.Values("culture") Is Nothing
1
1447
by: Sa¹o Zagoranski | last post by:
Hi... This is driving me crazy and I really hope I can get an answer... Take a look at the piece of code below (I'm using .net 2.0): try { double pointTime = XDate.DateTimeToXLDate(point.time); double pointValue = Convert.ToDouble(point.value); list.Add(pointTime, pointValue);
5
1386
by: Todd | last post by:
OK...I have a form that has two text boxes. These two fields are being filled from a file import, which works fine. I am then passing these values into a custom class with both values typed as DOUBLE (IE: double.parse(mytextbox1.text) ). When I subtract these two values, I'm get an erroneous .00000000000002 being added to the result of the subtraction!! The form fills the instance of the class...
0
8946
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, 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...
0
8776
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
9310
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...
0
9182
tracyyun
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...
0
8186
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, 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...
0
6031
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.