|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > classes causing problems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|