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

    Join Date
    Aug 2001
    Location
    Stevenage, uk
    Posts
    10
    Rep Power
    0

    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
    searchit=search

    then when I called it:

    if structureorsmiles == SMILES:
    searchit.sub_search(SMI)
    else:
    searchit.sub_search(struc_smi)

    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

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

    Join Date
    Jun 2001
    Location
    Amersfoort, The Netherlands
    Posts
    45
    Rep Power
    14
    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:
    Code:
    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)
    else:
        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