[Tutor] Re: Tutor digest, Vol 1 #87 - 7 msgs
Daniel Gau
b4705021@im.ntu.edu.tw
Tue, 27 Jul 1999 16:08:22 +0800 (CST)
On Tue, 27 Jul 1999 tutor-admin@python.org wrote:
>
> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the web, visit
> http://www.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-request@python.org
> You can reach the person managing the list at
> tutor-admin@python.org
>
> When replying, please edit your Subject line so it is more specific than
> "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
> 1. RE: (no subject) (alan.gauld@bt.com)
> 2. Getting current path (Chris Frost)
> 3. Re: Inheritance and *args and **kw (Art Siegel)
> 4. Re: Getting current path (Chris Frost)
> 5. Inheritance and *args (Art Siegel)
> 6. Re: Inheritance and *args (Steve Spicklemire)
> 7. Re: Inheritance and *args (Joseph J. Strout)
>
> --__--__--
>
> Message: 1
> From: alan.gauld@bt.com
> To: andyquake@hotmail.com, tutor@python.org
> Subject: RE: [Tutor] (no subject)
> Date: Mon, 26 Jul 1999 11:27:16 +0100
>
> > can you please send me a tutorial that defines all the
> > terms...like strings
> > and stuff cause i don't know what all these terms mean and it's very
> > confusing to me.
>
> Take a look at the 2 'Python for non programmer' tutorials under
> documentation at the python web site.
>
> http://www.python.org/doc/Intros.html
>
> If that's still not enough then look at my (in progress)
> 'Programming for beginners' tutorial which uses Pytthon,
> Tcl and BASIC. It goes into more detail on the terminology
> than either of the other 2.
>
> Specifically the Data page might help you.
>
> http://members.xoom.com/alan_gauld/tutor/tutindex.htm
>
> Alan G.
>
> --__--__--
>
> Message: 2
> Date: Mon, 26 Jul 1999 09:34:13 -0500
> From: Chris Frost <chris@frostnet.advicom.net>
> To: tutor@python.org
> protocol="application/pgp-signature"
> Subject: [Tutor] Getting current path
>
>
> --2/5bycvrmDh4d1IB
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: quoted-printable
>
> How can you find the current directory you are presently in? I'd like to
> output to whatever directory a program is called from, and then load it
> back reason being.
>
> thanks!
> --=20
> Chris Frost | <http://www.frostnet.advicom.net/chris/>
> -------------+------------------------------------------
> Public PGP Key:
> Email chris@frostnet.advicom.net with the subject "retrieve pgp key"
> or visit <http://www.frostnet.advicom.net/chris/about/pgp_key.phtml>
>
> --2/5bycvrmDh4d1IB
> Content-Type: application/pgp-signature
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGPfreeware 5.0i for non-commercial use
> MessageID: cmhcn2QRojoxlxcbk6WVRDievvZrxSss
>
> iQA/AwUBN5xj0+EzIlbKpewXEQIHTgCg/fP7/rWyr6lmRusIJygNNscv6X0An1e1
> 9KntB39xm+PKk3Ar2N5ilNIG
> =+GIx
> -----END PGP SIGNATURE-----
>
> --2/5bycvrmDh4d1IB--
>
> --__--__--
>
> Message: 3
> From: "Art Siegel" <ajs@ix.netcom.com>
> To: "Python Tutor" <tutor@python.org>
> Date: Mon, 26 Jul 1999 11:02:32 -0400
> charset="iso-8859-1"
> Subject: [Tutor] Re: Inheritance and *args and **kw
>
> I create a class with only *args constructors which are handled in the
> class' def __init__.
>
> I inherit from the class and try to add **kw args in the sub-classes def
> __init__.
>
> But in creating an instance of the the sub-class the kw dictionary is now an
> element of a tuple passed as a single argument, rather than a tuple of *args
> and a dictionary of *kw.
>
> I think the above is probably inconherent. If anybody can see what I am
> driving at, help is appreciated.
>
> I will try to follow up with a snippet to clarify my issue
>
>
>
>
>
> --__--__--
>
> Message: 4
> Date: Mon, 26 Jul 1999 10:10:29 -0500
> From: Chris Frost <chris@frostnet.advicom.net>
> To: Emile van Sebille <emile@FenX.com>
> Cc: tutor@python.org
> Subject: Re: [Tutor] Getting current path
> protocol="application/pgp-signature"
>
>
> --LQksG6bCIzRHxTLp
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: quoted-printable
>
> On Mon, Jul 26, 1999 at 08:01:30AM -0700, Emile van Sebille wrote:
> > Hi Chris,
> >=20
> > >>> import os
> > >>> os.getcwd()
> > 'D:\\Program Files\\Python\\Tools\\idle'
> >=20
> > HTH
> Yes, thanks!
>
> How could I tell if the user simply entered a filename, or if they gave
> the entire path (assuming unix if that helps)?
>
> thanks again,
> --=20
> Chris Frost | <http://www.frostnet.advicom.net/chris/>
> -------------+------------------------------------------
> Public PGP Key:
> Email chris@frostnet.advicom.net with the subject "retrieve pgp key"
> or visit <http://www.frostnet.advicom.net/chris/about/pgp_key.phtml>
>
> --LQksG6bCIzRHxTLp
> Content-Type: application/pgp-signature
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGPfreeware 5.0i for non-commercial use
> MessageID: EAj7Vkdi3hAwVZx4b2UkfWbAJ2PH4gFX
>
> iQA/AwUBN5xsVOEzIlbKpewXEQLNYQCfZpiylyjpDG7quQQd6fr9/ftTL70AoJ0C
> HnSe0hL6RqLTz/j0hlN/Y2fg
> =puey
> -----END PGP SIGNATURE-----
>
> --LQksG6bCIzRHxTLp--
>
> --__--__--
>
> Message: 5
> From: "Art Siegel" <ajs@ix.netcom.com>
> To: "Python Tutor" <tutor@python.org>
> Date: Mon, 26 Jul 1999 12:16:18 -0400
> boundary="----=_NextPart_000_000A_01BED760.AA2D99A0"
> Subject: [Tutor] Inheritance and *args
>
> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_000A_01BED760.AA2D99A0
> Content-Type: text/plain;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> class Position:
> def __init__(self, *args):
> if args:
> self.x=3Dargs[0]
> self.y=3Dargs[1]
> self.z=3Dargs[2]
> print self.x,self.y,self.z
>
> class Point(Position):
> def __init__(self,*args):
> Position.__init__(self,args)
>
> Point(1,2,3)
>
> Result:
>
> Traceback (innermost last):
> ...
> self.y=3Dargs[1]
> IndexError: tuple index out of range
>
> Apparently because the arguments to Point(1,2,3) is read in as a single =
> element tuple, whose single element is the 3 element tuple (1,2,3).
>
> Whereas Position(1,2,3) is processed as a three element tuple, with =
> elements 1,2,3.
>
> Is there a straightforward approach to accomplish above inheritance??
>
>
> ------=_NextPart_000_000A_01BED760.AA2D99A0
> Content-Type: text/html;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
> <HTML>
> <HEAD>
>
> <META content=3Dtext/html;charset=3Diso-8859-1 =
> http-equiv=3DContent-Type>
> <META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
> </HEAD>
> <BODY bgColor=3D#ffffff>
> <DIV><FONT color=3D#000000 size=3D2>class Position:<BR> def =
> __init__(self,=20
> *args):<BR> if args:<BR> =
> self.x=3Dargs[0]<BR> =20
> self.y=3Dargs[1]<BR> self.z=3Dargs[2]<BR> print=20
> self.x,self.y,self.z</FONT></DIV>
> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV>
> <DIV><FONT color=3D#000000 size=3D2>class Point(Position):<BR> def=20
> __init__(self,*args):<BR> =
> Position.__init__(self,args)<BR></FONT></DIV>
> <DIV><FONT color=3D#000000 size=3D2>Point(1,2,3)</FONT></DIV>
> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV>
> <DIV><FONT color=3D#000000 size=3D2>Result:</FONT></DIV>
> <DIV><FONT color=3D#000000 size=3D2><BR>Traceback (innermost =
> last):</FONT></DIV>
> <DIV><FONT color=3D#000000 size=3D2> =20
> ...<BR> self.y=3Dargs[1]<BR>IndexError: tuple index =
> out of=20
> range<BR></FONT></DIV>
> <DIV><FONT color=3D#000000 size=3D2>Apparently because the arguments to =
> Point(1,2,3)=20
> is read in as a single element tuple, whose single element is the 3 =
> element=20
> tuple (1,2,3).</FONT></DIV>
> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV>
> <DIV><FONT size=3D2>Whereas Position(1,2,3) is processed as a three =
> element tuple,=20
> with elements 1,2,3.</FONT></DIV>
> <DIV><FONT size=3D2></FONT> </DIV>
> <DIV><FONT size=3D2>Is there a straightforward approach to accomplish =
> above=20
> inheritance??</FONT></DIV>
> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV></BODY></HTML>
>
> ------=_NextPart_000_000A_01BED760.AA2D99A0--
>
>
> --__--__--
>
> Message: 6
> Date: Mon, 26 Jul 1999 12:22:05 -0500 (EST)
> From: Steve Spicklemire <steve@acer.spvi.com>
> To: ajs@ix.netcom.com
> CC: tutor@python.org
> (ajs@ix.netcom.com)
> Subject: Re: [Tutor] Inheritance and *args
>
>
> Art,
>
> Try this:
>
> ----------------------------------------------------------------------
>
> class Position:
> def __init__(self, *args):
> if args:
> self.x=args[0]
> self.y=args[1]
> self.z=args[2]
> print self.x,self.y,self.z
>
> class Point(Position):
> def __init__(self,*args):
> apply(Position.__init__,([self] + list(args)))
>
> Point(1,2,3)
>
> ----------------------------------------------------------------------
>
> -steve
>
> --__--__--
>
> Message: 7
> Date: Mon, 26 Jul 1999 10:24:13 -0700
> To: "Art Siegel" <ajs@ix.netcom.com>, "Python Tutor" <tutor@python.org>
> From: "Joseph J. Strout" <joe@strout.net>
> Subject: Re: [Tutor] Inheritance and *args
>
> --============_-1279112630==_ma============
> Content-Type: text/plain; charset="us-ascii"
>
> At 9:16 AM -0700 07/26/99, Art Siegel wrote:
>
> > self.y=args[1]
> >IndexError: tuple index out of range
> >Apparently because the arguments to Point(1,2,3) is read in as a single
> >element tuple, whose single element is the 3 element tuple (1,2,3).
>
> Yep.
>
> >Whereas Position(1,2,3) is processed as a three element tuple, with
> >elements 1,2,3.
>
> Yep again.
>
> >Is there a straightforward approach to accomplish above inheritance??
>
> Yep^3. Well, reasonably straightforward -- slightly complicated by having
> an additional parameter ('self'):
>
> apply(Position.__init__, (self,) + args)
>
> In cases where you have a list or tuple of arguments, but you need to pass
> them to a function as separate arguments rather than a single object, you
> use 'apply'.
>
> Cheers,
> -- Joe
> ,------------------------------------------------------------------.
> | Joseph J. Strout Biocomputing -- The Salk Institute |
> | joe@strout.net http://www.strout.net |
> `------------------------------------------------------------------'
> --============_-1279112630==_ma============
> Content-Type: text/enriched; charset="us-ascii"
>
> At 9:16 AM -0700 07/26/99, Art Siegel wrote:
>
>
> <excerpt> self.y=args[1]
>
> IndexError: tuple index out of range
>
> Apparently because the arguments to Point(1,2,3) is read in as a single
> element tuple, whose single element is the 3 element tuple (1,2,3).
>
> </excerpt>
>
> Yep.
>
>
> <excerpt>Whereas Position(1,2,3) is processed as a three element tuple,
> with elements 1,2,3.
>
> </excerpt>
>
> Yep again.
>
>
> <excerpt>Is there a straightforward approach to accomplish above
> inheritance??
>
> </excerpt>
>
> Yep^3. Well, reasonably straightforward -- slightly complicated by
> having an additional parameter ('self'):
>
>
> apply(Position.__init__, (self,) + args)
>
>
> In cases where you have a list or tuple of arguments, but you need to
> pass them to a function as separate arguments rather than a single
> object, you use 'apply'.
>
>
> Cheers,
>
> -- Joe
>
> ,------------------------------------------------------------------.
>
> | Joseph J. Strout Biocomputing -- The Salk Institute |
>
> | joe@strout.net http://www.strout.net |
>
> `------------------------------------------------------------------'
>
> --============_-1279112630==_ma============--
>
>
>
> --__--__--
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest
>
-------------------------------------------------------------------
-- Daniel Gau<plateau@www.linux.org.tw> --
-- webmaster of Linux Notes --
-- http://www.linux.org.tw/~plateau/linux_notes/index.htm --
-- webmaster of TwLUG --
-- http://www.linux.org.tw --
-- ICQ 30932232 --
-------------------------------------------------------------------