Reputation: 6 Worker
- Active Members
- Active Posts:
- 106 (0.06 per day)
- 16-November 09
- Profile Views:
- Last Active:
- Nov 26 2013 05:06 PM
- OS Preference:
- Who Cares
- Favorite Browser:
- Favorite Processor:
- Favorite Gaming Platform:
- Your Car:
- Dream Kudos:
Posts I've Made
Posted 1 Feb 2013What are you expecting to happen(?).
In the first example you haven't set any positions and Python does its best to output the (empty) attribute pos_vector.
BTW For this second example, your x and y are totally unrelated - I don't know if you were expecting them to be connected in some way.
Gotcha. Fixed with a try/except catch.
def set_posX(self, pos = 0): self.ifBool(pos) self.pos_x = pos def get_posX(self): try: return self.pos_x except AttributeError: self.set_posX() return self.pos_X
I suppose it might be bad coding practice but in most of the cases for my variables, if they haven't been defined, need to be designated along the origin of my coordinate system with null (aherm, "zero") values. Hence [0,0,0] as an output for my examples.
That's why in the first example I was expecting some set of default numbers to at least be returned when load_Pos() was called.
I get the impression that main() should be a nested/inner class of vectors(), but it depends on what you are trying to achieve.
Ehhh... it could work that way (actually that was how it originally was set up...) but my Equations class is already fairly large as it is and uses a lot of different functions that are not necessarily tied in to/with my Loader class; thus the reason they are separate files.
Secondly, I'm trying to get more exposure and understanding on using multiple classes in relation to one another while trying to break my single-file-project habits.
Posted 31 Jan 2013Erm, dunno, as you haven't detailed where this comes from:
Uh sorry, just ignore it; it's effectively the Operator module and class.
Anyhow, tinkered around some more, it works about right but I have another question.
As it now tries to get/set data from one class to another, but the problem is as such that it doesn't seem to perform the proper operations in one class to give any data to the one that's calling it.
for example, if this is what is executed in the shell, it won't result in an error and appear as though everything has gone accordingly but when you try to access the variable/array list for which the data is stored:
>>> x = vectors() >>> x.load_Pos() >>> x.pos_vector [<bound method main.pos_x of <Equations.main object at 0x02AB54F0>>, <bound method main.pos_y of <Equations.main object at 0x02AB54F0>>, <bound method main.pos_z of <Equations.main object at 0x02AB54F0>>]
however, I stilled fiddled with it and got this output as well. Why is that?
>>> x = vectors() >>> y = Equations.main() >>> y.set_posX(0) >>> y.set_posY(0) >>> y.set_posZ(0) >>> position = [y.get_posX(), y.get_posZ(), y.get_posZ()] >>> position [0, 0, 0]
[Edit: ]If it appears in any way to be confusing, I've included the pertinent bits below.
Posted 31 Jan 2013You are importing Operator, which is a module. Operator is not a class or function so you can't call it uses brackets ().
Thanks for the tip, I was pretty sure that was one of the problems involved.
some_fun = functions()
and then you might call the methods set_posX and get_posX on this instance (of the class functions). There is no connection between set/get_posX and your other class, vectors.
So, just off the top of my head, something like this will work then?
class vectors(object): def __init__(self): self.function = Equations.library() def load_Pos(self, pos_x = 0): self.function.set_posX(pos_x) vector = [self.function.get_posX()] self.pos_vector = vector
Posted 28 Jan 2013Python complains correctly. The reason is: when Python runs into a class statement it first builds a dictionary of all the methods. It looks at the arguments and finds a default value self.G. But self refers to an instance to the class which does not yet exist. So Python complains.
The old some_function(bar=None) trick:
class func(object): def __init__(self): self.G = 123 def set_attractor(self, val=None): if val is None: val = self.G self.G_const = val f = func() f.set_attractor() print f.G_const
I see, makes sense...
well problem fixed. Thanks for the help.
Posted 1 Jan 2013
>>> True = False >>> True False
>>> False = True >>> False True >>>
- Member Title:
- D.I.C Head
- Age Unknown
- January 14
- Ft Worth, TX
- Mathematical Theory concerning Algebra/Calculus, Manga (Shirow Masamune & Yukito Kishiro), Science Fiction and/or Fantasy, Astrophyiscs concepts and colonization, Welding and Soldering, Snowboarding, Pyromania, blah, blah, blah... talk to me sometime
- Full Name:
- Years Programming:
- Programming Languages:
- Java, Python, C/C++, BASIC
BloodyInari hasn't added any friends yet.