473,782 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Missing member

I have some troubles with a member variable that seems to be missing
in a class. In short, heres what I do; class A is the parent class, B
inherits from A and C inherits from B (hope I used the right words
there). Now, I create an instance of C, which calls A's __init__ which
in turn creates all the member variables. Then I call C.move() (a
function defined in A), but then, one of the variables seems to have
become 'NoneType'.

The code can be found here (Ive taken away unnecessery stuff):
http://pastebin.com/875394

The exact error is (which occur on line 15 in the pasted code):
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

Any comments are welcome. :)

Feb 4 '07 #1
4 2452
On Feb 5, 9:45 am, "Mizipzor" <mizip...@gmail .comwrote:
I have some troubles with a member variable that seems to be missing
in a class. In short, heres what I do; class A is the parent class, B
inherits from A and C inherits from B (hope I used the right words
there). Now, I create an instance of C, which calls A's __init__ which
in turn creates all the member variables. Then I call C.move() (a
function defined in A), but then, one of the variables seems to have
become 'NoneType'.

The code can be found here (Ive taken away unnecessery stuff):http://pastebin.com/875394

The exact error is (which occur on line 15 in the pasted code):
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'
Line 15 is:
self.pos += (self._directio n * self.stats.spee d)
So obviously(???) self._direction is None

What does line 8 do: self._direction = vector() ???

I'd suggest adding line 8.1:

assert self._direction is not None
Any comments are welcome. :)
I doubt that you really mean that, so I have refrained from
commenting :-)

Cheers,
John

Feb 4 '07 #2
On Feb 4, 4:45 pm, "Mizipzor" <mizip...@gmail .comwrote:
I have some troubles with a member variable that seems to be missing
in a class. In short, heres what I do; class A is the parent class, B
inherits from A and C inherits from B (hope I used the right words
there). Now, I create an instance of C, which calls A's __init__ which
in turn creates all the member variables. Then I call C.move() (a
function defined in A), but then, one of the variables seems to have
become 'NoneType'.

The code can be found here (Ive taken away unnecessery stuff):http://pastebin.com/875394

The exact error is (which occur on line 15 in the pasted code):
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

Any comments are welcome. :)
Here's a suggestion: use new-style classes. Have _BaseEntity inherit
from object, allows you to use super for invoking methods on super
classes. Instead of:
class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
_BaseEntity.__i nit__(self, type, x, y)

You enter:
class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
super(Entity,se lf).__init__(ty pe, x, y)

This makes it easier to update your inheritance hierarchy later. New-
style classes have other benefits too.

As for your NoneType problem, try adding "print self._direction " to
the end of _BaseElement.__ init__.

-- Paul

Feb 5 '07 #3
"Paul McGuire" typed:
Here's a suggestion: use new-style classes. Have _BaseEntity inherit
from object, allows you to use super for invoking methods on super
classes. Instead of:
class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
_BaseEntity.__i nit__(self, type, x, y)

You enter:
class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
super(Entity,se lf).__init__(ty pe, x, y)

This makes it easier to update your inheritance hierarchy later. New-
style classes have other benefits too.
I am still a beginner to Python, but reading that made me think on
impluse, "What happens in case of one class inheriting from two or more
different classes?"

Having written a small test case and testing it, I find that
super().__init_ _() calls the __init__() of the first of the class in
the list of classes from which the calling class inherits. For example:

class C(A, B):
def __init__(self):
super(C, self).__init__( )

calls A's __init__ explicity when an instance of C is instantiated. I
might be missing something. I didn't know that.

--
Ayaz Ahmed Khan

A witty saying proves nothing, but saying something pointless gets
people's attention.

Feb 5 '07 #4
Mizipzor a écrit :
I have some troubles with a member variable that seems to be missing
in a class. In short, heres what I do; class A is the parent class, B
inherits from A and C inherits from B (hope I used the right words
there). Now, I create an instance of C, which calls A's __init__ which
in turn creates all the member variables. Then I call C.move() (a
function defined in A), but then, one of the variables seems to have
become 'NoneType'.

The code can be found here (Ive taken away unnecessery stuff):
http://pastebin.com/875394

The exact error is (which occur on line 15 in the pasted code):
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'
Alas, there's a dependency on an unknown class or function vector (which
I presume lives in the eponym module), so we just can guess that the
call to vector() at line 8 returned None. IOW, the problem is elsewhere...
Any comments are welcome. :)
You ask for it, you get it:

import pygame, math
from pygame.locals import *
=bad style
import tilemap, dataManager
from vector import *
=idem

class _BaseEntity:

=class _BaseEntity(obj ect):

def __init__(self, type, x, y):
self._direction = vector()
self.pos = vector(x,y)
self.stats = dataManager.get EntityStats(typ e)
self.hp = self.stats.maxH p # todo: make all atttributes local

def move(self):
""" moves the entity in its direction according to its speed """
self.pos += (self._directio n * self.stats.spee d)

def setDirection(se lf, point, y = None):
""" sets the direction to point, and normalises it
if y is specifed, "point" is expected to be x,
otherwise, "point" is expected to be a vector class """
# make a vector
if not y == None:
= if y is not None:
point = vector(point, y)
self._direction = point.normalise ()
#def lookAt(self, point, y = None):
# """ changes the angle so the entity "looks" at the specified
coords
# if y is specifed, "point" is expected to be x,
# otherwise, "point" is expected to be a vector class """
# # make a vector
# if not y == None:
# point = vector(point, y)

=code duplication, should be factored out

# vec = vector(point.x - self.posx, point.y - self.posy)
# vec.normalise()
#
# angle = math.degrees(ma th.asin(vec.y))
# print angle

def draw(self, targetSurface):
""" blits the entire stats.image onto the targetSurface at the
ent's coords """
targetSurface.b lit(self.stats. image, (self.pos.x,sel f.pos.y))

class Entity(_BaseEnt ity):
def __init__(self, type, x = 0, y = 0):
_BaseEntity.__i nit__(self, type, x, y)

=You don't need to override the __init__ method if it's just to call
the superclass's __init__ with the same args...

(snip)
Feb 6 '07 #5

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

Similar topics

1
21396
by: Junior | last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could not be found (are you missing a using directive or an assembly reference?)" message in two particular lines, and I've tried everything... Could anyone please paste this and tell me what I'm doing wrong ? I use SerialPort.zip, which can be downloaded at http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=b06e30f9-1301-4cc6-ac14-dfe325097c69 ...
4
2460
by: Conrad Weyns | last post by:
vc7.1 has no problem with the following snippet: template <typename T> class TTest { std::list<T*>::iterator m_It; }; but metrowerks codewarrior 9.2 kicks my butt and online Comeau confirms: 1. MW:
2
10926
by: kalpana.sinduria | last post by:
Hi all, how to remove the following complle error. When I compiling the code I get the following errors: Compiling... CDrtEachDefFeat.cpp d:\ include\common\cdrtintegfeat.h(39) : error C2143: syntax error : missing ';' before '*'
4
1539
by: Peter Olcott | last post by:
Yesterday I found that an invocation of a member function that lacked the required "()" pararenthesis did not generate an error message. This was an invocation of a member function that is part of a library so I do not have access to the source code. The compiler was MSVC++ 6.0. I can't think of any scenario that would prevent a compiler error message from being generated. Can some one please explain how this could have occurred?
2
1213
by: Caladin | last post by:
I'm sure once someone answers this I'll feel really dumb. I'm a c++ programmer playing with c# an here's my conundrum I declare a class in the for public class Form1 : System.Windows.Forms.For class Class
0
1433
by: Harald Hoyer | last post by:
My application has an exe and some DLLs. During debugging only debug information of the current binary is available. For example: ============DLL: -----------------------------------------Header: class CKnownLocal; class CKnownGlobal { CKnownLocal &Member; ...
14
1837
by: tshad | last post by:
I am trying to set up a reusable library (business component) that I can use in a bunch of my pages. I built the file and it almost compiles, but I am not sure what I am missing. The vbc command and results are: ************************************************************************ C:\Inetpub\wwwroot\Development>vbc /t:library emailClass.vb
1
4288
by: BobPaul | last post by:
I'm following code out of a howto book and this is really bugging me. This header file was created by VStudio 6.0 when I did a "Right Click: Add Member Function" CLine is a class I wrote (per the book's instructions) and Line.h in included in Day10Doc.cpp Here is the contents of Day10Doc.h #if !defined(AFX_DAY10DOC_H__16736853_CB29_49E7_A8ED_C912CAE666EC__INCLUDED_) #define AFX_DAY10DOC_H__16736853_CB29_49E7_A8ED_C912CAE666EC__INCLUDED_ ...
0
4226
by: RickVidallon | last post by:
Missing or Truncated Body Text in Email Application - 2 Strange Examples... There is no earthly reason why this is happening! EXAMPLES HERE: http://65.36.227.70/actmailer/ We have a scheduled task which runs every 5mins and sends pending email campaign. The script has been written in VB.NET and following is the code which
0
9643
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
9480
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
10313
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
10081
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
9946
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
7494
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
5378
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
4044
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
3643
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.