LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-22-2002, 03:08 PM   #1
jeg
LQ Newbie
 
Registered: Jul 2002
Distribution: Slackware 8.1
Posts: 2

Rep: Reputation: 0
Python


Hello everyone, this is my first post here and isn't really linux-related, but I figure someone may be able to help anyway (and sooner or later I will most likely need help with linux too).

This is actually not a linux problem, it works fine on Linux but not on Windows.

I am trying to get it to work in Windows also because I'd like to use IDLE but haven't quite got xwindows working correctly yet.

I am writing a Yahtzee game in Python. It is not very good, but it is my first attempt at writing any sort of program longer than a few lines from scratch, so that's to be expected.

Code:
import random
...
class Die:
      def __init__(self, value=0):
            self.value = value

      def __str___(self):
            return str(self.value)

      def __cmp__(self.other):
            if self.value > other.value: return 1
            if self.value < other.value: return -1
            return 0

class DieSet:
      #'DieSet' is the five dice that are used each turn
      def __init__(self):
           self.set = []
           #gives each die a value from 1  to 6
           for die in range(5):
                 newDie = Die()
                  value = int(random.randrange(1, 7))
                  self.set.append(newDie(value))
...
Whenever I do anything with DieSet() (on Windows), it gives me this error:

AttributeError: Die instance has no __call__ method.

However, when I try to do the exact same thing on Linux, it all works fine. Does anyone know why it's giving me that error, or what to do about it? I don't know exactly what the __call__ method is, in the case it really is needed, and haven't found much helpful information on the Internet as of yet. I am using Python 2.2.1 on WindowsXP.

Maybe I should give up on Windows and do it all on Linux, huh?


Thanks in advance for any replies.
-jeg


Last edited by jeg; 07-22-2002 at 03:41 PM.
 
Old 07-23-2002, 12:44 AM   #2
DoubleLetter
Member
 
Registered: Jun 2001
Location: Sharjah, United Arab Emirates
Distribution: Mandrake Linux 10.1
Posts: 132

Rep: Reputation: 15
An error in calling

Hi,

I think this is the error:

You are calling the Die class like this:
'newDie = Die()'

which is fine. Now you have an instance of the Die class in the variable newDie. Fine ?

newDie now holds an INSTANCE of the DIE class. An INSTANCE has methods; you have to access the functions/variables of an INSTANCE like this:
'newDie.value = 23'

or

'newDie.functionName(passedVariable)'

But you are using the INSTANCE itself as a class (!!!) by saying:

'newDie(value)'

It is absolutely incorrect.

from what I understand of your intentions, it should be:

'newDie.value = value'

Was I clear enough ?

Hope that helps !

Cheers,

Ahsan
 
Old 07-26-2002, 08:46 PM   #3
jeg
LQ Newbie
 
Registered: Jul 2002
Distribution: Slackware 8.1
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you! Yes, that did help.

I went back and tried again, both
Code:
value = int(random.randrange(1, 7))
newDie = Die(value)
self.set.append(newDie)
and
Code:
newDie = Die()
newDie.value = int(random.randrange(1, 7))
self.set.append(newDie)
work correctly. (maybe, originally, I tried to put part of each together (?) or something)

It seems obvious now that I know what the problem was, but I guess it never hurts to ask. And, now I'll be sure not to make that mistake again.

Thanks again.
-jeg
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Fedora 2 04-23-2009 07:02 PM
installing python library's (Python Numeric) Four Linux - Newbie 1 10-16-2005 02:31 PM
Python guru's - Is this a python bug? or is it me? bardinjw Programming 2 06-23-2005 08:17 AM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM
install python 2.3 ,necssary to remove python 2.2 ngan_yine Linux - Newbie 7 12-28-2003 04:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration