Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7684 > unrolled thread
| Started by | TheSaint <nobody@nowhere.net.no> |
|---|---|
| First post | 2011-06-15 19:57 +0800 |
| Last post | 2011-06-16 08:02 -0500 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
Function within class and in modules TheSaint <nobody@nowhere.net.no> - 2011-06-15 19:57 +0800
Re: Function within class and in modules Roy Smith <roy@panix.com> - 2011-06-15 08:18 -0400
Re: Function within class and in modules Zach Dziura <zcdziura@gmail.com> - 2011-06-15 06:57 -0700
Re: Function within class and in modules TheSaint <nobody@nowhere.net.no> - 2011-06-16 20:33 +0800
Re: Function within class and in modules Andrew Berg <bahamutzero8825@gmail.com> - 2011-06-16 08:02 -0500
| From | TheSaint <nobody@nowhere.net.no> |
|---|---|
| Date | 2011-06-15 19:57 +0800 |
| Subject | Function within class and in modules |
| Message-ID | <ita6nj$4j4$1@speranza.aioe.org> |
Hello sorry, I'm bit curious to understand what could be the difference to pack up a class for some number of functions in it and a simple module which I just import and use the similar functions? The only perspective that I think of is that class might instantiate a function several time. For my use I don't have multithread and mostly programs are sequencial. -- goto /dev/null
[toc] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2011-06-15 08:18 -0400 |
| Message-ID | <roy-189429.08185815062011@news.panix.com> |
| In reply to | #7684 |
In article <ita6nj$4j4$1@speranza.aioe.org>, TheSaint <nobody@nowhere.net.no> wrote: > Hello > sorry, I'm bit curious to understand what could be the difference to pack up > a class for some number of functions in it and a simple module which I just > import and use the similar functions? If all you have is a bunch of functions, just sticking them in a module is fine. The reason you would want to package them up as a class would be if there's some state that needs to be saved. Don't think of a class as a collection of methods, think of it as a hunk of data, and some methods which operate on that data. Looking at it another way, if you write a class and discover that none of the methods ever make any use of self, then what you probably really wanted to do was create a module to hold all those methods as top-level functions.
[toc] | [prev] | [next] | [standalone]
| From | Zach Dziura <zcdziura@gmail.com> |
|---|---|
| Date | 2011-06-15 06:57 -0700 |
| Message-ID | <29d03ead-fce0-4d6e-b0d0-692cbb19712f@dn9g2000vbb.googlegroups.com> |
| In reply to | #7684 |
> On Jun 15, 7:57 am, TheSaint <nob...@nowhere.net.no> wrote: > Hello > sorry, I'm bit curious to understand what could be the difference to pack up > a class for some number of functions in it and a simple module which I just > import and use the similar functions? > The only perspective that I think of is that class might instantiate a > function several time. For my use I don't have multithread and mostly > programs are sequencial. I had a hard time with this at first when I started using Python. I personally come from a background of using Java in an educational environment, so I'm pretty familiar with it. Going from a "pure" Object-Oriented language, where everything MUST be bundled into a class, and an Object is less of "a bit of data" and more of "a data structure that actually DOES something", was a little difficult. Just repeat this to yourself: Python ISN'T Java. Repeat it until the words start sounding funny to you. Then continue for another 10 minutes. It'll sink in. Anyhow... In Python, classes aren't necessarily treated as "things that do stuff" (though they can DEFINITELY act in that way!). Python classes are made to hold data. If you have something that you need to save for later, put it in a class and call it a day. If you only have a bunch of functions that are meant to process something, just put them into a module. You'll save yourself some time, you won't have to instantiate a class in order to call the functions, and you'll be happier overall. (I know was happy from being freed from the Pure OO model that Java shoves down your throat!)
[toc] | [prev] | [next] | [standalone]
| From | TheSaint <nobody@nowhere.net.no> |
|---|---|
| Date | 2011-06-16 20:33 +0800 |
| Message-ID | <itct6r$8un$1@speranza.aioe.org> |
| In reply to | #7699 |
Zach Dziura wrote: > Just repeat this to yourself: Python ISN'T Java I never had to do anything in Java. But mostly something in Sumatra :D I'm getting the point that I'll need class very seldom. Only to understand some more the use of self, whether I'll use a class. -- goto /dev/null
[toc] | [prev] | [next] | [standalone]
| From | Andrew Berg <bahamutzero8825@gmail.com> |
|---|---|
| Date | 2011-06-16 08:02 -0500 |
| Message-ID | <mailman.14.1308229382.1164.python-list@python.org> |
| In reply to | #7699 |
On 2011.06.15 08:57 AM, Zach Dziura wrote:
> Just repeat this to yourself: Python ISN'T Java.
class MainClass:
def public static void main(*args):
print('Am I doin' it right?')
:P
Or something like that. I've forgotten almost everything I learned about
Java.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web