473,769 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

when and how do you use Self?

I am new to python,



Could someone explain (in English) how and when to use self?



I have been reading, and haven't found a good example/explanation





Bruce Tieche (br**********@u smtm.sppn.af.mi l)

Nov 3 '05 #1
14 3189
Tieche Bruce A MSgt USMTM/AFD wrote:
I am new to python,

Could someone explain (in English) how and when to use self?

Don't use self. Use other.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Nov 3 '05 #2
As a point of style: the 'other' identifier should only be used in
Zen Metaclass programming as an implicit reference to the calling
object or as a list of references to all other instances of the class.
Context will make it both clear and obvious which use case is
desired.

On 03/11/05, bruno at modulix <on***@xiludom. gro> wrote:
Tieche Bruce A MSgt USMTM/AFD wrote:
I am new to python,

Could someone explain (in English) how and when to use self?

Don't use self. Use other.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'on***@xiludom. gro'.split('@')])"
--
http://mail.python.org/mailman/listinfo/python-list

--
"A little government and a little luck are necessary in life, but only
a fool trusts either of them." -- P. J. O'Rourke
Nov 3 '05 #3
On Thu, 3 Nov 2005 10:48:28 -0500,
Chris Cioffi <ev********@gma il.com> wrote:
As a point of style: the 'other' identifier should only be used in
Zen Metaclass programming as an implicit reference to the calling
object or as a list of references to all other instances of the class.
Context will make it both clear and obvious which use case is desired.


Can I use the 'other' identifier in, e.g., an __add__ method?

Please? ;-)

Regards,
Dan

--
Dan Sommers
<http://www.tombstoneze ro.net/dan/>
Nov 3 '05 #4
Chris Cioffi wrote:
<ot>
as a point of style, top-posting is a Bad Thing(tm)
(fixed)
</ot>

On 03/11/05, bruno at modulix <on***@xiludom. gro> wrote:
Tieche Bruce A MSgt USMTM/AFD wrote:
I am new to python,

Could someone explain (in English) how and when to use self?

Don't use self. Use other.

As a point of style: the 'other' identifier should only be used in
Zen Metaclass programming as an implicit reference to the calling
object or as a list of references to all other instances of the class.
As a point of style, if it refers to a list, it should be 'others' and
not 'other'.

Also, this was supposed to be a joke. I can well understand that my sens
of humour is somewhat disastrous and that this was not a _good_ joke,
but "context should have made both clear and obvious" that it was one.
Context will make it both clear and obvious which use case is
desired.


import this
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'on***@xiludom. gro'.split('@')])"
Nov 3 '05 #5
On Thu, 03 Nov 2005 10:14:23 +0100, bruno at modulix wrote:
Tieche Bruce A MSgt USMTM/AFD wrote:
I am new to python,

Could someone explain (in English) how and when to use self?

Don't use self. Use other.


Are you serious? You don't recommend doing this?

def MyClass:
def __init__(self, x):
self.x = x

???
--
Steven.

Nov 3 '05 #6
Steven D'Aprano wrote:
On Thu, 03 Nov 2005 10:14:23 +0100, bruno at modulix wrote:

Tieche Bruce A MSgt USMTM/AFD wrote:
I am new to python,

Could someone explain (in English) how and when to use self?


Don't use self. Use other.

Are you serious?


Are you seriously wondering if I am serious ?
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Nov 3 '05 #7
bruno at modulix <on***@xiludom. gro> writes:
Don't use self. Use other.

Are you serious?


Are you seriously wondering if I am serious ?


Hmmm... I hope there's no deadlock in this loop...

--
Jorge Godoy <go***@ieee.org >
Nov 3 '05 #8
bruno at modulix wrote:
Steven D'Aprano wrote:
On Thu, 03 Nov 2005 10:14:23 +0100, bruno at modulix wrote:
Tieche Bruce A MSgt USMTM/AFD wrote:
I am new to python,

Could someone explain (in English) how and when to use self?
Don't use self. Use other.

Are you serious?

Are you seriously wondering if I am serious ?


I was also wondering. What's the problem you see with the identifier
"self?"
Nov 3 '05 #9
On Thu, 03 Nov 2005 20:19:03 +0100, bruno at modulix wrote:
Steven D'Aprano wrote:
On Thu, 03 Nov 2005 10:14:23 +0100, bruno at modulix wrote:

Tieche Bruce A MSgt USMTM/AFD wrote:

I am new to python,

Could someone explain (in English) how and when to use self?
Don't use self. Use other.

Are you serious?


Are you seriously wondering if I am serious ?


Well, you are either serious, or you're guilty of giving extremely bad
advice to a newbie who will probably have even less ability to recognise
an in-joke than I do.
--
Steven.

Nov 3 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4718
by: Marc | last post by:
Hi all, I was using Tkinter.IntVar() to store values from a large list of parts that I pulled from a list. This is the code to initialize the instances: def initVariables(self): self.e = IntVar() for part, list in info.masterList.items():
33
1911
by: Xah Lee | last post by:
i've started to read python tutorial recently. http://python.org/doc/2.3.4/tut/tut.html Here are some quick critique: quick example: If the input string is too long, they don't truncate it, but return it unchanged; this will mess up your column lay-out but that's usually better than the alternative, which would be lying about a value. (If you really want truncation you can always add a slice operation, as in
6
3354
by: Coral Snake | last post by:
I am having problems with programming even simple "Hello World" programs from books and tutorials that use Python GUI libraries. Such Programs cause python to throw "Attribute Errors" even when the "attributes" being asked for by the errors exist in the source code. This has happened to me in both the standard python GUI Library Tkinter and in pyGTK here are the codes for the "Hello World Programs involved and their corosponding "Attribute...
0
3812
by: sector119 | last post by:
I use python 2.4.1 and PIL 1.1.5 and when I execute my program I got error: ../code.py Traceback (most recent call last): File "./code.py", line 7, in ? class DrawPlus(ImageDraw.Draw): TypeError: Error when calling the metaclass bases function() argument 1 must be code, not str
15
2596
by: Ralf W. Grosse-Kunstleve | last post by:
****************************************************************************** This posting is also available in HTML format: http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html ****************************************************************************** Hi fellow Python coders, I often find myself writing:: class grouping:
5
1481
by: Russell Warren | last post by:
I just ran across a case which seems like an odd exception to either what I understand as the "normal" variable lookup scheme in an instance/object heirarchy, or to the rules regarding variable usage before creation. Check this out: >>> class foo(object): .... I = 1 .... def __init__(self): .... print self.__dict__ .... self.I += 1
1
1593
by: Peter J. Bismuti | last post by:
How do you access attributes of a class when inheriting from it? Can't you just say: self.attribute? Help?! ........................................................................................................ #!/usr/bin/python from Dialog import Dialog
2
1412
by: cfriedalek | last post by:
Sorry for the vague subject. Not sure what the right terminology is. How can I use an instance's data by reference to the instance name, not the instance attribute? OK the question is probably really poor but hopefully an example will make it clear. <type 'int'> 2 1 3
3
7932
by: dunleav1 | last post by:
In 9.1 and 9.5 (Linux 64 bit) when a buffer pool is set to self- tuning, how are blocks configured in respect to blocked vs non-blocked when self-tuning is set to on? (ie) I have one bufferpool that is 16k that the IBMDEFAULTBP is shared between all tablespaces. The data tablespace has prefetch automatic set to on.
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.