Language:
switch to room list switch to menu My folders
Go to page: First ... 12 13 14 15 [16] 17 18 19 20 ... Last
[#] Sun Dec 28 2008 18:33:59 EST from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

this is not a python question as much as an object oriented question.
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'
like
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.

[#] Sun Dec 28 2008 18:34:37 EST from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Notice everybody how I restrained myself from saying anything bad about python.

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.

[#] Sun Dec 28 2008 20:54:24 EST from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

[#] Sun Dec 28 2008 22:37:57 EST from observer @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

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:

class mystuff:
 def average(self,a,b,c):
  result=a+b+c
  result=result/3
  return result
print "main part of program"
stuff=mystuff()
print stuff.average(9,18,27)



[#] Mon Dec 29 2008 08:22:06 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

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. 



[#] Mon Dec 29 2008 13:05:37 EST from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

according to one of the answers apparently they do support static stuff in classes.

[#] Mon Dec 29 2008 15:39:52 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

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. 



[#] Mon Dec 29 2008 15:46:46 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

dothebart wrote:

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).



[#] Mon Dec 29 2008 16:47:38 EST from dothebart @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

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.



[#] Mon Dec 29 2008 19:22:26 EST from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I just came accross a really weird javaism.

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.

[#] Mon Dec 29 2008 19:31:32 EST from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I stand corrected, in eclipse, there's the compiler, then there's the Compiler.

[#] Mon Dec 29 2008 19:48:14 EST from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


Ah, gotcha. It prevalidated but then it wouldn't compile.

Right?

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.)

[#] Mon Dec 29 2008 20:18:12 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Yeah, dothebart, I'm not really suggesting anyone drop everything and leap over to bazaar, but I've found it an interesting open source alternative.  I'm keeping my eye on it.

[#] Wed Dec 31 2008 16:47:21 EST from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

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?

[#] Wed Dec 31 2008 17:04:22 EST from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


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...

[#] Thu Jan 01 2009 13:27:01 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


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.

[#] Thu Jan 01 2009 16:01:21 EST from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

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.

[#] Thu Jan 01 2009 16:03:30 EST from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

parallelism has been my favorite programming model since I was a little kid.
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

[#] Thu Jan 01 2009 16:57:20 EST from IGnatius T Foobar @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

And yet you hate multithreaded programs.

[#] Thu Jan 01 2009 21:47:21 EST from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

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.



Go to page: First ... 12 13 14 15 [16] 17 18 19 20 ... Last