Re: Beginning Question about Python functions, parameters...

2009-11-25 Thread Lie Ryan
astral orange wrote: As for the "class Name():" example above? Even though I haven't seen exactly what purpose 'self' serves In many other programming language, self (or this, or Me) refers the the current class instance. In some languages, you can refer to an instance attribute without an e

Re: Beginning Question about Python functions, parameters...

2009-11-25 Thread Bruno Desthuilliers
astral orange a écrit : On Nov 23, 10:37 pm, r wrote: (snip) This is a horrible example to show noobs. I think the OP could better understand this as a class EVEN though the OP may or may not know what a class *is* yet. class Name(): def __init__(self, first, middle, last):

Re: Beginning Question about Python functions, parameters...

2009-11-24 Thread r
On Nov 24, 9:45 am, astral orange <457r0...@gmail.com> wrote: > > As for the "class Name():" example above? Even though I haven't seen > exactly what purpose 'self' serves > yet I can follow and understand what is going on very easily, that > helps out tremendously. > Very clearly written...Thank y

Re: Beginning Question about Python functions, parameters...

2009-11-24 Thread Terry Reedy
Peter Otten wrote: Terry Reedy wrote: remember exactly what was stored. Maybe a typo. That's a bug in the store() function # as posted def store(data, full_name): names = full_name.split() if len(names) == 2: names.insert(1, '') labels = 'first', 'middle', 'last' for label,

Re: Beginning Question about Python functions, parameters...

2009-11-24 Thread astral orange
On Nov 23, 10:37 pm, r wrote: > On Nov 23, 11:19 am, astral orange <457r0...@gmail.com> wrote: > > > > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it

Re: Beginning Question about Python functions, parameters...

2009-11-24 Thread Peter Otten
Terry Reedy wrote: > astral orange wrote: > >> As far as the program. I did add print statements such as print >> (MyNames) and got back: >> >> {'middle': {}, 'last': {'Smith': ['John Larry Smith']}, 'first': {}} > > Hmmm, as I understood the code, either that should be ... 'last': {} ... > bef

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread r
On Nov 23, 11:19 am, astral orange <457r0...@gmail.com> wrote: > Hi, I am trying to teach myself Python and have a good book to help me > but I am stuck on something and I would like for someone to explain > the following piece of code for me and what it's actually doing. > Certain parts are very c

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread Terry Reedy
astral orange wrote: As far as the program. I did add print statements such as print (MyNames) and got back: {'middle': {}, 'last': {'Smith': ['John Larry Smith']}, 'first': {}} Hmmm, as I understood the code, either that should be ... 'last': {} ... before the first store(), as you seem to b

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread astral orange
On Nov 23, 4:35 pm, Terry Reedy wrote: > astral orange wrote: > > Yes, lines 104-111 is really where my problem lies in understanding > > what is going on here. > > I am beginner so this stuff seems a little unwieldy at the moment. :) > > I *did* invest $40 > > Water under the bridge. Focus on the

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread Terry Reedy
astral orange wrote: Yes, lines 104-111 is really where my problem lies in understanding what is going on here. I am beginner so this stuff seems a little unwieldy at the moment. :) I *did* invest $40 Water under the bridge. Focus on the future... into this book so it' what I have to work wi

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread Stephen Hansen
On Mon, Nov 23, 2009 at 11:14 AM, astral orange <457r0...@gmail.com> wrote: > But back to the example, on line 104 I see there's a call to the > lookup function, passing 3 > parameters ('data', which I think is a nested dictionary, label > (first, middle, last) and name). > > But I am getting lo

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread Stephen Hansen
On Mon, Nov 23, 2009 at 10:26 AM, j wrote: > What I am not totally sure about is when the store function callsthe > lookup function and does "return data[label].get(name)", that line > "trips" me up somethen the lookup function returns that back to > the store function, assigns the data to th

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread astral orange
On Nov 23, 1:17 pm, "Diez B. Roggisch" wrote: > astral orange wrote: > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it's actually doing. > > Certain p

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread MRAB
j wrote: On Nov 23, 12:37 pm, Neo wrote: astral orange schrieb: Hi, I am trying to teach myself Python and have a good book to help me but I am stuck on something and I would like for someone to explain the following piece of code for me and what it's actually doing. Certain parts are very

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread david wright
- Original Message From: j To: python-list@python.org Sent: Mon, November 23, 2009 10:26:42 AM Subject: Re: Beginning Question about Python functions, parameters... On Nov 23, 12:37 pm, Neo wrote: > astral orange schrieb: > > > > > Hi, I am trying to teach myself

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread j
On Nov 23, 12:37 pm, Neo wrote: > astral orange schrieb: > > > > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it's actually doing. > > Certain parts a

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread Diez B. Roggisch
astral orange wrote: > Hi, I am trying to teach myself Python and have a good book to help me > but I am stuck on something and I would like for someone to explain > the following piece of code for me and what it's actually doing. > Certain parts are very clear but once it enters the "def store(da

Re: Beginning Question about Python functions, parameters...

2009-11-23 Thread Neo
astral orange schrieb: > Hi, I am trying to teach myself Python and have a good book to help me > but I am stuck on something and I would like for someone to explain > the following piece of code for me and what it's actually doing. > Certain parts are very clear but once it enters the "def store(d

Beginning Question about Python functions, parameters...

2009-11-23 Thread astral orange
Hi, I am trying to teach myself Python and have a good book to help me but I am stuck on something and I would like for someone to explain the following piece of code for me and what it's actually doing. Certain parts are very clear but once it enters the "def store(data, full_name): " function

Re: Functions, parameters

2007-02-08 Thread Bruno Desthuilliers
Boris Ozegovic a écrit : > Bruno Desthuilliers wrote: > > >>Why don't you just read the source code ? Django is free software, you >>know !-) > > Yes, I know. :) > >>What about something like: > > >>def filter(self, **kw): >> for argname, value in kw.items(): >> fieldname, op = arg

Re: Functions, parameters

2007-02-08 Thread Boris Ozegovic
Paul Rubin wrote: > Since split is applied to argname, it retrieves 'question' and 'startswith'. Exactly. :) And, 'questions' and 'startswith' are two string, and not references at Poll.question, or more precisely, instanceOfPoll.question. I suppose this is what I was looking for: __getattri

Re: Functions, parameters

2007-02-08 Thread Paul Rubin
Boris Ozegovic <[EMAIL PROTECTED]> writes: > > def filter(self, **kw): > >for argname, value in kw.items(): > > fieldname, op = argname.split('__', 1) > > Yes, this is what confused me in the first place: how to separate > arguments. If you call split, and split returns list of String, t

Re: Functions, parameters

2007-02-08 Thread Boris Ozegovic
Bruno Desthuilliers wrote: > Why don't you just read the source code ? Django is free software, you > know !-) Yes, I know. :) > What about something like: > def filter(self, **kw): >for argname, value in kw.items(): > fieldname, op = argname.split('__', 1) Yes, this is what conf

Re: Functions, parameters

2007-02-08 Thread Paul Rubin
Boris Ozegovic <[EMAIL PROTECTED]> writes: > >>> Poll.objects.filter(question__startswith='What') > > This 'question__startswith' is the problem. What is the common idiom for > this type od arguments, so I can Google it? You can refer to function args in Python by name, e.g. define a function

Re: Functions, parameters

2007-02-08 Thread Matimus
>>> Poll.objects.filter(question__startswith='What') That is an example of a keyword argument. You can read about it in the Python Tutorial: http://docs.python.org/tut/node6.html#SECTION00672 -Matt -- http://mail.python.org/mailman/listinfo/python-list

Re: Functions, parameters

2007-02-08 Thread Bruno Desthuilliers
Boris Ozegovic a écrit : > Hi, I'am still learning Python and while reading Django tutorial couldn't > understand this part: > > class Poll(models.Model): > question = models.CharField(maxlength=200) > pub_date = models.DateTimeField('date published') > > > # Django provides a rich d

Functions, parameters

2007-02-08 Thread Boris Ozegovic
Hi, I'am still learning Python and while reading Django tutorial couldn't understand this part: class Poll(models.Model): question = models.CharField(maxlength=200) pub_date = models.DateTimeField('date published') # Django provides a rich database lookup API that's entirely driv