April 1st, 2005, 01:51 PM
Preceding a path with a / means the root directory on *nix systems, I'm not sure how Windows handles this but it's probably not a good idea to use it. Instead you should remove the / and ./ characters from your filenames entirely.
Originally Posted by pylon
This means that the line file=open("/element/"+ename+".txt",'w') will become file=open("element/"+ename+".txt",'w').
Note: that it isn't a good idea to use the names of Pythons built-in functions for your own variables.
__init__ is the method that is called when you create an instance of an object, so it allows you to set default values for instance variables. Basically this is used to set up or "initialize" the instance .
April 1st, 2005, 10:40 PM
Better would be to pass parameters in when Element() is created:
def __init__(self, symbol, name, weight):
self.symbol = symbol
self.name = name
self.weight = weight
pb = Element("pb", "lead", 60) # or whatever the weight is ;-)
symbol = raw_input("Enter the symbol:")
name = ...
weight = ...
elem = Element(symbol, name, weight)
April 2nd, 2005, 08:55 PM
Thankyou very much, you don't understand how much that explained to me righ there!!!
THankyou thankyou thankyou!!!!
You'll get a rep. bonus from me now!!
April 2nd, 2005, 09:30 PM
Very interesting thread guys. Nice overview of OOP too. Thanks