1. No Profile Picture
    inexperienced and useless
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Stevenage, uk
    Rep Power

    Unhappy classes causing problems

    I'm pretty new to progranmming and I'm trying my first use of classes in Python. The thing is that they don't seem to work.
    Here's how I defined it:

    class search (self, value):
    def sub_search (self, value):
    self.value = value
    #rest of function here

    then when I called it:

    if structureorsmiles == SMILES:

    SMI and struc_smi are both defined,
    I don't get any errors generated, it just doesn't do anything, almost like the call of the class doesn't work. If anyone can see an obvious fault, please help

  2. #2
  3. No Profile Picture
    Python Prophet
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Amersfoort, The Netherlands
    Rep Power
    What are you trying to do? In the code you post nothing is printed to the screen, so it's right nothing gets printed.

    Anyway, there's something wrong with your class definition:

    class search(self, value):

    Anything you put between these parentheses are the classes you want to inherit from. I don't think that's what you want here, You probably want something like this:
    class Search:
        def __init__(self, Value):
            self.Value = Value
        def SubSearch(self):
            # Function goes here.
    SearchIt = Search(Value) # The value you want to search.
    if structureorsmiles == SMILES:
        SearchIt.SubSearch(self, SMI)
        SearchIt.SubSearch(self, struc_smi)
    You know, you should really try reading a good beginners book on CS and Python. I'd recommend this one:

    How to think like a computer scientist: Learning with Python

    Also, try putting your code within [ code][ /code] blocks(omit the spaces).
    Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems. - Jamie Zawinski, in comp.lang.emacs

IMN logo majestic logo threadwatch logo seochat tools logo