Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100789 > unrolled thread
| Started by | Qurrat ul Ainy <qurratul.ainy1@gmail.com> |
|---|---|
| First post | 2015-12-23 17:53 -0800 |
| Last post | 2015-12-23 21:58 -0600 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.lang.python
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
| From | Qurrat ul Ainy <qurratul.ainy1@gmail.com> |
|---|---|
| Date | 2015-12-23 17:53 -0800 |
| Subject | need 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]
| From | Benjamin Kulas <bkulbismuth@gmail.com> |
|---|---|
| Date | 2015-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]
| From | Qurrat ul Ainy <qurratul.ainy1@gmail.com> |
|---|---|
| Date | 2015-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]
| From | Qurrat ul Ainy <qurratul.ainy1@gmail.com> |
|---|---|
| Date | 2015-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]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2015-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]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2015-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]
| From | Andrew Farrell <armorsmith42@gmail.com> |
|---|---|
| Date | 2015-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