Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100789 > unrolled thread

need some basic help

Started byQurrat ul Ainy <qurratul.ainy1@gmail.com>
First post2015-12-23 17:53 -0800
Last post2015-12-23 21:58 -0600
Articles 7 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  need some basic help Qurrat ul Ainy <qurratul.ainy1@gmail.com> - 2015-12-23 17:53 -0800
    Re: need some basic help Benjamin Kulas <bkulbismuth@gmail.com> - 2015-12-23 20:24 -0800
      Re: need some basic help Qurrat ul Ainy <qurratul.ainy1@gmail.com> - 2015-12-24 11:33 -0800
        Re: need some basic help Qurrat ul Ainy <qurratul.ainy1@gmail.com> - 2015-12-24 11:38 -0800
        Re: need some basic help Terry Reedy <tjreedy@udel.edu> - 2015-12-24 17:14 -0500
    Re: need some basic help Steven D'Aprano <steve@pearwood.info> - 2015-12-24 22:58 +1100
    Re: need some basic help Andrew Farrell <armorsmith42@gmail.com> - 2015-12-23 21:58 -0600

#100789 — need some basic help

FromQurrat ul Ainy <qurratul.ainy1@gmail.com>
Date2015-12-23 17:53 -0800
Subjectneed some basic help
Message-ID<90cc0071-7c78-4974-88ad-60ff89649c95@googlegroups.com>
Hello,

Can someone please explain this code below. I am new at Python .
Thanks 


def receive_messages(self, msgs, time):
      for msg in msgs:
         msg.set_recv_time(time)
      self.msgs_received.extend(msgs)

[toc] | [next] | [standalone]


#100791

FromBenjamin Kulas <bkulbismuth@gmail.com>
Date2015-12-23 20:24 -0800
Message-ID<1dc1e09d-f1cc-4cf6-8535-f61ac2af9c43@googlegroups.com>
In reply to#100789
On Wednesday, December 23, 2015 at 7:53:43 PM UTC-6, Qurrat ul Ainy wrote:
> Hello,
> 
> Can someone please explain this code below. I am new at Python .
> Thanks 
> 
> 
> def receive_messages(self, msgs, time):
>       for msg in msgs:
>          msg.set_recv_time(time)
>       self.msgs_received.extend(msgs)

What exactly are you confused about? This looks like it is part of a class; can you post the entire class definition? Also, what is the purpose of the program that contains this snippet?

[toc] | [prev] | [next] | [standalone]


#100825

FromQurrat ul Ainy <qurratul.ainy1@gmail.com>
Date2015-12-24 11:33 -0800
Message-ID<b4eaa827-0e57-458c-8ee0-99508ead1cf7@googlegroups.com>
In reply to#100791
what is snippet ??



On Thursday, December 24, 2015 at 5:25:18 AM UTC+1, Benjamin Kulas wrote:
> On Wednesday, December 23, 2015 at 7:53:43 PM UTC-6, Qurrat ul Ainy wrote:
> > Hello,
> > 
> > Can someone please explain this code below. I am new at Python .
> > Thanks 
> > 
> > 
> > def receive_messages(self, msgs, time):
> >       for msg in msgs:
> >          msg.set_recv_time(time)
> >       self.msgs_received.extend(msgs)
> 
> What exactly are you confused about? This looks like it is part of a class; can you post the entire class definition? Also, what is the purpose of the program that contains this snippet?

[toc] | [prev] | [next] | [standalone]


#100827

FromQurrat ul Ainy <qurratul.ainy1@gmail.com>
Date2015-12-24 11:38 -0800
Message-ID<6364f688-2022-49d9-a1ce-ed7663936745@googlegroups.com>
In reply to#100825
On Thursday, December 24, 2015 at 8:33:59 PM UTC+1, Qurrat ul Ainy wrote:
> what is snippet ??
> 
> 
> 
> On Thursday, December 24, 2015 at 5:25:18 AM UTC+1, Benjamin Kulas wrote:
> > On Wednesday, December 23, 2015 at 7:53:43 PM UTC-6, Qurrat ul Ainy wrote:
> > > Hello,
> > > 
> > > Can someone please explain this code below. I am new at Python .
> > > Thanks 
> > > 
> > > 
> > > def receive_messages(self, msgs, time):
> > >       for msg in msgs:
> > >          msg.set_recv_time(time)
> > >       self.msgs_received.extend(msgs)
> > 
> > What exactly are you confused about? This looks like it is part of a class; can you post the entire class definition? Also, what is the purpose of the program that contains this snippet?

Thank you steven foe the detail explanation i got it now. 
and thank you Andrew for recommendation I really need that 

[toc] | [prev] | [next] | [standalone]


#100836

FromTerry Reedy <tjreedy@udel.edu>
Date2015-12-24 17:14 -0500
Message-ID<mailman.131.1450995300.2237.python-list@python.org>
In reply to#100825
On 12/24/2015 2:33 PM, Qurrat ul Ainy wrote:
> what is snippet ??

Search 'snippet definition' on the web with your browser.
It comes from 'snip', so something 'snipped'.


-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#100795

FromSteven D'Aprano <steve@pearwood.info>
Date2015-12-24 22:58 +1100
Message-ID<567bddfa$0$1617$c3e8da3$5496439d@news.astraweb.com>
In reply to#100789
On Thu, 24 Dec 2015 12:53 pm, Qurrat ul Ainy wrote:

> Hello,
> 
> Can someone please explain this code below. I am new at Python .
> Thanks
> 
> 
> def receive_messages(self, msgs, time):
>       for msg in msgs:
>          msg.set_recv_time(time)
>       self.msgs_received.extend(msgs)


This is a method belonging to a class. We don't know what the class is,
because you haven't shown it, so let's just call it "MyClass".

The method takes two arguments (msgs and time) plus a special
argument, "self", which represents the instance where the method is called.
So at some point, you must say:

    instance = MyClass()

Do you understand object oriented programming? Have you programmed in any
other languages?

My *guess* is that the "msgs" argument is probably a list of messages:

    the_messages = [first_message, second_message, third_message]

and the "time" argument is possibly a number (time in seconds?):

    some_time = 125


Then you call the method:

    instance.receive_messages(the_messages, some_time)


When you call the receive_messages method, the following happens:

- each of the messages are taken in turn, one at a time, and a method on
that message is called:

    for msg in msgs:
        msg.set_recv_time(time)

    Translation:
    for each message first_message, second_message, ...
        call method "set_recv_time" with argument some_time

- then the original instance calls one of its own messages, probably to
store those messages:

    self.msgs_received.extend(msgs)




I can't be more detailed, as I don't know how much programming experience
you have, or what the class that this method came from does.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#100801

FromAndrew Farrell <armorsmith42@gmail.com>
Date2015-12-23 21:58 -0600
Message-ID<mailman.104.1450965772.2237.python-list@python.org>
In reply to#100789
This code snippet is a method on a class. What is a method? This chapter of
the book Think Python
<http://www.greenteapress.com/thinkpython/html/thinkpython018.html> does a
good job of explaining it.
Without understanding this foundation, it isn't possible to really answer
your question, so definitely read at least that chapter.
Think Python was the book I first learned from and if you are new to
python, I recommend it among the other python tutorials to consider.

In this case, this method takes two things:
0) The object that it is a method of (by python convention, this is called
"self")
1) a collection of message objects (probably a list, maybe a tuple,
probably not a set)
2) a time
It then, goes through all of them and tells each one "you were received at
some particular time." by calling a method on each of the message objects.
The object that it is a method of seems to have a list of messages it has
received. So, this method sticks the collection of new message objects onto
the list of already-received messages.

On Wed, Dec 23, 2015 at 7:53 PM, Qurrat ul Ainy <qurratul.ainy1@gmail.com>
wrote:

> Hello,
>
> Can someone please explain this code below. I am new at Python .
> Thanks
>
>
> def receive_messages(self, msgs, time):
>       for msg in msgs:
>          msg.set_recv_time(time)
>       self.msgs_received.extend(msgs)
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web