Making a class defines what mystuff is. But you have to actually create an instance (thus instantiating) of type mystuff so you can operate on it.
alas, I don't know python, so I can't tell you what the syntax is, but it probably involves the word 'new'
instanceofmystuff = new mystuff()
print instanceofmystuff.average(9, 18, 27)
There is probably also a way to define mystuff as a static class or at least the average function as a static function which would mean among other things you wouldn't have to instantiate it first, and your syntax would work.
But that's a C and java thing, I'm only guessing they probably have it in python too.
Also, there's a place called stackoverflow.com that just loves questions like yours.
In fact, I think I'm going to post it myself.
There ya go, lots of answers.
Thanks. http://homepage.mac.com/s_lott/books/nonprog/htmlchunks/ch42.html#objects.class.deff was helpful. In case anybody cares, the working code is:
print "main part of program"
I don't think you have static functions in Python, but you can create functions within a module, which would act kind of like a static function.
That is, your .py file could define a function, which would require you include the .py module before using it. That's about as close to static as it gets with Python, as memory serves. Been a long time since I worked with Python.
It's been far too long since I last messed with Python. I think I remember that now, although I cannot recall how you're supposed to set something like that up, or how you'd call such a function.
I'm not digging into GIT because of the numbers of merges we do here is very limited, and at $work a missing Tortoise frontend is the knockout fact why GIT won't get adopted there. ...so starting a git effort there would be a total waste of time.
And I respond:
Have you considered using bazaar instead? It's git-like in its capabilities, and I think there's a tortoise-like front end (although for Windows this front end is very weak right now... with some work in Python, it could probably be brought up to speed).
no, I didn't. and... I might have noded once in a while that I can't live without braces, So me raising the flag for a python solution... next to zero, well, probably a java solution would fit inbetween.
I've got other battles to waste my breath on. Subversion works well, merging back between branches might be one of its weak points, Neither am I the one to distribute workload nor to decide to switch 30 people over to s.th. else.
Probably once pain gets worse on others, I might throw in a suggestion, but belief in patch and friends is weak over here, so I might also risk to be burnt on the stake for forbidden thoughts and rituals.
So, unless s.th. changes dramaticaly SVN is the tool of choice.
I have a class x, that has a public class y defined in it.
New function says
y inst = new y();
this fails because there's no access to x from which I can create y. okay, I get that.
So I do this:
x xinst = new x();
y inst = new y();
and it compiles. I changed nothing. Nowhere did I tell java to get y from the x I made but it seems it decided to take care of that by itself.
Very not cool, unless I'm missing something.
Ah, gotcha. It prevalidated but then it wouldn't compile.
Perhaps this will illuminate the issue further. When you define a class within another class, the inner class can be either static or non-static. A static inner class is essentially the same as a regular outer class except it exists within the namespace (NOT the lexical scope) of the outer class. However, an instance of a non-static inner class contains a hidden reference to an instance of the outer class, and the source code for the inner class is allowed to refer to member fields of the outer class by name, without any further qualification. (Thus necessitating the hidden reference.)
This concept is extended further, for anonymous inner classes, which are allowed to refer to automatic variables defined on the stack of the routine that is creating the anonymous inner class, as long as those variables are declared final. (Because they are passed by value to the inner class as parameters to an implicit constructor.)
non-static. A static inner class is essentially the same as a regular
outer class except it exists within the namespace (NOT the lexical
scope) of the outer class. However, an instance of a non-static inner
class contains a hidden reference to an instance of the outer class,
and the source code for the inner class is allowed to refer to member
fields of the outer class by name, without any further qualification.
I knew most of that, but not the bit about anonymous inner classes. Not a big fan on anonymous classes. Just makes things less readable, and doesn't buy you anything at compile time, right?
Well, in terms of source-level public/private checks and so on, there is nothing that you can do with an anonymous inner class that you can't do with a named one. But it adds a certain amount of convenience, mostly for quick event handler classes that just receive callbacks and only contain a couple of lines of code.
Things get a bit funny at the bytecode level, where the access permission model is a bit faked and overloaded to deal with inner classes, but no big deal there...
I am growing to *love* asynchronous programming.
Sending something off to get a web page while I work on something else, calling some other function when you've got it... stuff like that... man it's powerful stuff.
And I think, at least in C++, it's made easier with boost::asio. I'm growing to really like that library, as I get more accustomed to it.
mostly for quick event handler classes that just receive callbacks and
only contain a couple of lines of code.
okay, that's a good example, and now that you've mentioned it, I realize I've actually done that.
One of the coolest programs I ever wrote ended up as a demo on some colletion CD of apple II programs, I wrote a text window manager, and a voluntary timesharing kind of thing and wrote a few appplications for it. I had a simple terminal, a bouncing ball, a file viewer and something else, and they all ran at the same time and the window manager did the window visibility thing, it was really cool.
Went nowhere, but it was neat to watch
Well, the joy of working asynchronously is that you aren't working in a multi-threaded environment (necessarily), but it *feels* multithreaded.
It's like it's multithreaded without any of the hassles of being multithreaded.
It's really what Apple tried to ram down everyone's throat with their 'co-operative' multi-threading model that blew up in their face. They simply didn't do it right, I guess.