Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28643
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: Setting up a class |
| Date | 2012-09-06 17:23 -0400 |
| Organization | > Bestiaria Support Staff < |
| References | <a451e907-5167-4e3e-a7f2-d63ffa0f2821@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.330.1346966626.27098.python-list@python.org> (permalink) |
On Thu, 6 Sep 2012 05:00:32 -0700 (PDT), shaun
<shaun.wiseman91@gmail.com> declaimed the following in
gmane.comp.python.general:
>
> But I'm having major problems since I am new to python I keep trying to do it as I would do it in Java but classes seem to be very different. I was wondering could someone answer a few questions?
>
First mistake... IGNORE anything you know about Java classes.
(Including the one-class-per-file).
> 1) Is there anything I should know about passing in variables from another script to the class?
Normally you don't pass variables to the "class" -- you create an
INSTANCE of the class (and may pass some parameters to the __init__()
method.
>
> 2) When I'm passing variables back to the script they seem to come back blank as if I haven't done it correctly (I declare the empty variable at the top of the class, I use the information I get from the database to fill it and I send it back) Is there anything I'm not doing right with this.
>
Python doesn't have "declarations" (other than "global" and related
in newer versions).
Normally one "return"s data from a method call. Otherwise one access
instance attributes using instance.attribute notation.
> 3)When I want to use a method from a class in another class method it never seems to work for me, I have a feeling this is to do with "self" but im not too sure??
>
"self" is the instance whose method is being called.
If you are trying to use a class for something that has no
instances, forget it, just package everything up as module and import
the module.
> Any help would be appreciated.
Read the language reference manual, and the Python tutorial...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Setting up a class shaun <shaun.wiseman91@gmail.com> - 2012-09-06 05:00 -0700
Re: Setting up a class Joel Goldstick <joel.goldstick@gmail.com> - 2012-09-06 08:16 -0400
Re: Setting up a class MRAB <python@mrabarnett.plus.com> - 2012-09-06 13:20 +0100
Re: Setting up a class "Colin J. Williams" <cjw@ncf.ca> - 2012-09-06 09:41 -0400
Re: Setting up a class Dave Angel <d@davea.name> - 2012-09-06 09:41 -0400
Re: Setting up a class Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-06 17:23 -0400
csiph-web