473,732 Members | 2,227 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 1712
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
8774
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
9447
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...
1
9235
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
9181
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...
1
6735
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 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...
0
4550
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...
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
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.