[Tutor] Practice python

2016-05-08 Thread monik...@netzero.net

HI:
Can you please recommend a free web class or site that offers lots of coding  
exercises in python, not just the beginning but also intermediate and advanced 
AND provides solutions. I need more practice. All the classes I have taken or 
looked at do not provide enough exercises (with solutions) to retain the info.
Thank you very much
Monika


Scribol.com
20 Female Celebrities Who Are Totally Different in Real Life
http://thirdpartyoffers.netzero.net/TGL3241/572f744288d8074424f2est01duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Way

2016-07-19 Thread monik...@netzero.net
How do you get involved in open source project?
Thank you
Monika

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] The Way
Date: Tue, 19 Jul 2016 00:55:07 +0100

On 18/07/16 22:32, Skapeven Punkboard wrote:
> Hello I have programmed a lot but only basic stuff, I never got further
> from a point in which I had to start looking for information in forums.
> Since the tutorials wherent enogh.  I would like to learn more by trying to
> solve usefull stuff with or for others.  How could I do this and
> participate in the comunity?

You could try an open source project. Get involved with that,
start by fixing bugs or testing or writing documentation.

Or even hang out here and answer some questions. They come at all levels
and as you gain experience you can answer more advanced
topics.

Or do both... :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Affordable Wireless Plans
Set up is easy. Get online in minutes.
Starting at only $9.95 per month! 
www.netzero.net?refcd=nzmem0216
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] python programmin problem

2016-07-20 Thread monik...@netzero.net
Hi:
Can somebody please provide answer to following python programming question? I 
have spent days on it and cannot come up with any code that would make any 
sense for it so I cannot provide you any code. But I would appreciate the 
answer very much, if not in python, then in pseudo code.
Thank you very much
Monika

Here is the problem:
Given a list of integers, return the progress of the test
The progress is defined as the length of the longest run of strictly increasing 
scores "with gaps allowed".
That is the length of the longest group of numbers such that each number in 
that block is strictly larger than the previous number, and the group can be 
formed by choosing some subset of values in the order they appear in the 
original
list. All values are integers.
input [1,7,2,3,5,4,6] returns 5
[1,2,3,5,6] and [1,2,3,4,6] both have length 5 and are longer than any other 
runs
Returning 7 is incorrect for [1,2,3,4,5,6,7] as it changes the ordering of the 
original sequence.
Input [1,2,3,4] the run [1,2,3,4] is the entire test and has lenght 4. returns 4
Input [4, 3, 2, 1] returns 1 each result is a run of 1. so we return 1
Input [1,2,0,4,5] return 5 longest run [1,2,4,5] has lenght 4




Affordable Wireless Plans
Set up is easy. Get online in minutes.
Starting at only $9.95 per month! 
www.netzero.net?refcd=nzmem0216
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python programmin problem

2016-07-20 Thread monik...@netzero.net
IM not able to figure out algorithm to find the runs.
Here is the code I have:

def ProgressCalc(items):
counts = [items[0]]
for i in range(1, len(items)-1):
print "for loop", items[i], items[i + 1]
if counts[- 1] < items[i]:
counts += [items[i]]
print "inside", items[i], items[i - 1], counts

print counts


counts = [items[0]]
for i in range(1, len(items) - 1):
print "for loop", items[i], items[i + 1]
if counts[- 1] <= items[i] and items[i] < items[i + 1]:
counts += [items[i]]
print "inside", items[i], items[i - 1], counts
elif counts[- 1] <= items[i] and items[i] > items[i + 1]:
counts += [items[i]]
i += 2
print counts
ProgressCalc(items)

------ Original Message --
From: Alan Gauld 
To: "monik...@netzero.net" 
Cc: tutor@python.org
Subject: Re: python programmin problem
Date: Thu, 21 Jul 2016 00:11:24 +0100

On 20/07/16 22:11, monik...@netzero.net wrote:
> ... if not in python, then in pseudo code.

The first question to ask is can you do it without a computer?
In other words given

input [1,7,2,3,5,4,6]

Can you first of all produce a list of all valid runs?

[1,2,3,5,6] and [1,2,3,4,6] both have length 5

I also see shorter runs:

[7] and [4,6] for example.

Can you manually create a list of all valid runs?

Once you can do that can you write a program to
generate that as a list of lists in Python?

If so then the answer to your question is a matter of
finding the length of the longest valid run which
should be fairly easy.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



Affordable Wireless Plans
Set up is easy. Get online in minutes.
Starting at only $9.95 per month! 
www.netzero.net?refcd=nzmem0216
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python programmin problem

2016-07-24 Thread monik...@netzero.net
IM sorry I do not understand:

For array A of length N, and for an integer k < N:
-- By k do you mean value of k or position of k in the list?

  L(A, k) is the length of the longest increasing subsequence of the
prefix of A with length k, where that subsequence needs to include the
k'th element too.

What is L?  This L function tries to capture the idea of having a
*partial* solution that involves a portion of the array A.


Why is it helpful?  Because of two crucial things:

1.  If we know L(A, 1), L(A, 2), ... all the way to L(A, N), then
we can just look at the maximum value of those pieces.  That's going
to be a solution to the general problem.
-- By maximum value do you mean I have to sum up the values in the list? Why?


2.  For a subproblem L(A, k), if we know the values for L(A, 1),
L(A, 2), ... , L(A, k-1), then we can compute L(A, k) by looking at
those other subproblems: the result of L(A, k) is related to them.
-- How do we find those subproblems? And then how do you relate them to the 
main problem?

Can you please explain more in details? 
Thank you so much
Monika
-- Original Message --
From: Danny Yoo 
To: Alan Gauld 
Cc: "monik...@netzero.net" , tutor 
Subject: Re: [Tutor] python programmin problem
Date: Sat, 23 Jul 2016 00:13:36 -0700

On Thu, Jul 21, 2016 at 11:30 PM, Alan Gauld via Tutor  wrote:
>
> Forwarding to list. Please use reply-all when responding to tutor messages.
>
> As Danny suggested this is quite a complex problem. I wasn't sure whether
> it was just the programming or the bigger algorithm issue you were stuck on.

[warning: large message ahead.]


This problem is unfortunately not something you can just code by
trying to hack it till it works.  At this level of difficulty, these
kinds of problems are *not* easy: they require some understanding of
fundamentals in algorithms, not Python.  That is, the actual coding of
this is not the hard part.  A direct solution to this problem is a
couple of lines and involves nothing more loops and arrays.  The
difficulty is understanding how to use solutions of sub-problems
toward the general large problem.


I should state this more strongly: trying to hack the solution is not
going to work.  I have to ignore the code presented in this thread
because there's very little to preserve.  The approach of trying to
look at only the very previous element is simply not viable.  The most
direct approach I know to do this is by talking about this in terms of
subproblems.


Here is a sketch of the idea:

Let's put on our magical thinking cap, and say that we'd like to
design a function L(A, m) with the following funny property:

For array A of length N, and for an integer k < N:

  L(A, k) is the length of the longest increasing subsequence of the
prefix of A with length k, where that subsequence needs to include the
k'th element too.

What is L?  This L function tries to capture the idea of having a
*partial* solution that involves a portion of the array A.


Why is it helpful?  Because of two crucial things:

1.  If we know L(A, 1), L(A, 2), ... all the way to L(A, N), then
we can just look at the maximum value of those pieces.  That's going
to be a solution to the general problem.


2.  For a subproblem L(A, k), if we know the values for L(A, 1),
L(A, 2), ... , L(A, k-1), then we can compute L(A, k) by looking at
those other subproblems: the result of L(A, k) is related to them.

How so?

---


As a concrete example, consider a list A = [5, 8, 6, 7].


* What is L(A, 1)?  We want the length of the longest subsequence of
the prefix [5] that includes the 5.  And that's just 1.

   L(A, 1) = 1.

That is, we're starting from scratch: we can't do better than just
pick the 5 as the start of our subsequence.  Since our subsequence
just has [5], that's a subsequence of length 1.


* What is L(A, 2)?  We want the length of the longest subsequence of
the prefix [5, 8] that includes the 8.  Why does knowing L(A, 1) help
us?  Because we know L(A, 1) is 1.  What does that mean?  We look at
L(A, 1) to see if maybe we can pick the subsequence that it is
measuring, and augment it.


We know L(A, 1) is the length of the longest sequence that ends up
including the first element of A, so we know that subsequence ends
with a [... 5].  And we can extend that subsequence so it look like
[..., 5, 8].  And we know that such an extension will be of length 2.
Can we do any better?  There are no other subproblems, so no.

That is, L(A, 2) = 2.


* What is L(A, 3)?  We want the length of the longest subsequence of
the prefix [5, 8, 6] that includes the 6.

We look at L(A, 1): can we just extend [..., 5] with a 6?  Yes,
and that gives us 2 as a possible answer for L(A, 3).  Why 2?  Because
L(A, 1) = 1, and if we extend the subsequence measured by L(A, 1), we
make it one element longe

Re: [Tutor] python programmin problem

2016-07-25 Thread monik...@netzero.net
Thank you all for your answers. I do not have a teacher or any body else who 
could guide me. I have taken all python classes offered in my area and many on 
line.
The question is one of questions asked by interviews for a qa position that 
also does some automation with python. Im just trying to learn so that I could 
get a job. Nobody offers manual qa jobs anymore so I am working on updating my 
skills.

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] python programmin problem
Date: Mon, 25 Jul 2016 00:21:10 +0100

On 24/07/16 20:58, Danny Yoo wrote:

> Please: I strongly encourage you to talk with your professor or study
> group: it really does sound like this is the first time you've seen these
> kinds of concepts.  

I agree with Danny, you should talk to your teacher.
I suspect the teacher may have set the problem without appreciating
the full extent of the complexity involved. It certainly doesn't
seem like you are properly equipped to solve it. Maybe he/she can
provide a simpler subset of problem.

Of course this assumes you have a teacher to ask? Your original
post doesn't state where you found the problem, it may be you
just picked it up on a web site or book  and have unwittingly
bitten off more than you are ready to chew just now?

It also depends a bit on whether the intent is to learn about
Python programming or about algorithms. If its the latter then
you might just want to ask on a different (math based) forum.
But if its Python you are interested in then find an easier
problem for now. Otherwise you will lose sight of the Python
problem in trying to solve the math one.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Affordable Wireless Plans
Set up is easy. Get online in minutes.
Starting at only $9.95 per month! 
www.netzero.net?refcd=nzmem0216
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python programmin problem

2016-07-28 Thread monik...@netzero.net
Thank you very much. I will look into your suggestions. I have been looking for 
tutorials but could not find anything at my level of understanding. You said to 
not focus on python but I had a python teacher (a famous python book writer and 
a friend of  Guido) was stressing on doing things in "pythonic" way.
Thank you for the links and I will check/read each one of them.
Monika

-- Original Message --
From: Danny Yoo 
To: "monik...@netzero.net" 
Cc: Alan Gauld , Python Tutor Mailing List 

Subject: Re: [Tutor] python programmin problem
Date: Wed, 27 Jul 2016 21:42:25 -0700

> You will see a problem being explained that you should be *very*
> interested in.  :)  Here's a link just to give you a taste:
>
> https://youtu.be/0yjebrZXJ9A?t=3m
>
>
> I hope that this helps point you in the right direction.  Good luck!


He has some more recent videos from 2012:

 https://youtu.be/Qc2ieXRgR0k?list=PLOtl7M3yp-DV69F32zdK7YJcNXpTunF2b

where he again goes over the familiar example in:

https://youtu.be/o0V9eYF4UI8?t=34m52s
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Affordable Wireless Plans
Set up is easy. Get online in minutes.
Starting at only $9.95 per month! 
www.netzero.net?refcd=nzmem0216
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] __init__

2016-08-29 Thread monik...@netzero.net


Hi:
If __init__ is not defined in a class, will it be called when creating an 
instance?
What in a case if this class inherits from parent with __init__ and without 
__init__?
Thank you
Monika

www.theictm.org (Sponsored by Content.Ad)
1 Fruit That "Destroys" Diabetes
http://thirdpartyoffers.netzero.net/TGL3241/57c4872872749728513dst03duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] super

2016-08-29 Thread monik...@netzero.net
Hi:
Why in super(Child,self).setVal(value) there is Child and self in super? Why 
the repetition? Or should it say Parent instead of Child?
In my understanding it should say Parent2 instead of Child since it refers to 
which parent to take the medthod from. In case of multiple inheritance it 
should state the class from which super will take the setVal method.
Please explain what Im missing here.
Thank you
Monika

class Paren2t():
def setVal(self, value):
self.value = value


class Child(Parent1, Parent2):
def setVal(self, value)
super(Child,self).setVal(value)


legitfeed.com (Sponsored by Content.Ad)
10 Disturbing Things Your Nails Reveal About Your Health
http://thirdpartyoffers.netzero.net/TGL3241/57c4a6dd3b01026dd4006st03duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __init__

2016-08-30 Thread monik...@netzero.net
I cannot really try it. If I have a class without __init__ and the class does 
not inherit from a class that has init there is really no place for me to put 
print statement. IN Java if you do not have a constructor specified java calls 
a default constructor behind the scenes setting up memory. Does python call 
default __init__ if one is not defined? In two python classes that I took both 
teachers gave a different answers.

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] __init__
Date: Mon, 29 Aug 2016 23:10:30 +0100

On 29/08/16 20:03, monik...@netzero.net wrote:

> If __init__ is not defined in a class, will it be called when creating an 
> instance?
> What in a case if this class inherits from parent with __init__ and without 
> __init__?

The easiest way to find out is try it and see what happens!

Just put appropriate print statements in the method.

Alan G

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


oldcatlady.com (Sponsored by Content.Ad)
40 Years Later: How Do 'The Brady Bunch' Look Now?
http://thirdpartyoffers.netzero.net/TGL3241/57c4bcd6864d53cd60b7ast01duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __init__

2016-08-30 Thread monik...@netzero.net
Thank you all for your answers.
The below seems contradicting to me:
" in that case there is no __init__ to call.
The top level class object has an empty __init__() which
does nothing, so it will be called by __new__()"

"It is new() that sets up the memory then calls init(). So init is
only used to initialise the object after it has been
constructed."
"There is always one defined in object but it does nothing.

There is also a default new() in object which is what sets
up the memory etc and then calls init()"

so a class has a default, empty __init__ and __new__. __new__ sets up memory 
and calls __init__. 
In class that has no parent: __init is called by __new__ but really does not do 
anything since it is empty.

Assume you have a child class with no init, but it has empty, default __init__ 
provided by pathon and the same for its parent class. When instantiating child 
class, child class's __new__ calls its ___init__ in child class and then calls 
__init__ in parent class? Why does it not just use the default, provided by 
python __init__ since it found it?

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] __init__
Date: Tue, 30 Aug 2016 10:09:55 +0100

On 29/08/16 23:52, monik...@netzero.net wrote:
> I cannot really try it.

> If I have a class without __init__ and the class does not
 > inherit from a class that has init there is really no place
 > for me to put print statement.

Fair enough but in that case there is no __init__ to call.
The top level class object has an empty __init__() which
does nothing, so it will be called by __new__()

 > IN Java if you do not have a constructor specified java
 > calls a default constructor behind the scenes setting up memory.

Remember that init() is an initialiser, not a constructor.
The constructor is the rarely seen __new__() method. It is
new() that sets up the memory then calls init(). So init is
only used to initialise the object after it has been
constructed.

> Does python call default __init__ if one is not defined?

There is always one defined in object but it does nothing.

There is also a default new() in object which is what sets
up the memory etc and then calls init()

Alan G

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Affordable Wireless Plans
Set up is easy. Get online in minutes.
Starting at only $14.95 per month! 
www.netzero.net?refcd=nzmem0216
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __init__

2016-08-30 Thread monik...@netzero.net
OK so somebodys remark that there is a default __init__ provided was not 
correct. 
What about old style classes? When we have a class that has no parent. and it 
does not inherit from object since it is old class - and this class has no 
__init__, does __new__ call __init__?

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] __init__
Date: Tue, 30 Aug 2016 21:37:44 +0100

On 30/08/16 17:59, monik...@netzero.net wrote:

> Assume you have a child class with no init, but it has empty,
 > default __init__ provided by pathon

It inherits the empty init from object.

>  and the same for its parent class. When instantiating child class,
 > child class's __new__ calls its ___init__ in child class and then
 > calls __init__ in parent class?

Usually there is only one new in object.

When new finishes constructing the empty object
init() gets called. There is no magic it is just a standard
method call that starts at the lowest level child and works
its way up the tree until it finds an init. If all else
fails it reaches the top level object.init()

If any subclass has defined an init it will be called first
and unless it calls super() it will be the last.

> Why does it not just use the default, provided by python
 > __init__ since it found it?

It uses the first init it finds. The last place it looks is
in object which has an empty init method. Python itself does
not provide a default init, it is the empty one in object
that fulfills that function (since every class ultimately
inherits object).

I suspect that's how Java does it too since every Java
class descends from Object. But I've not examined Java
that closely.

As eryksun has intimated there is actually another layer
of magic involved in Python via the metaclass mechanism
which allows us to change the mechanism by which classes
are constructed. but that is way deeper than most
programmers ever need to go! Remember the old adage
  -Keep it Simple!

Alan G

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Health News 24 (Sponsored by Content.Ad)
Don't Use Botox, Use This Instead: Granny Reveals $39 Method
http://thirdpartyoffers.netzero.net/TGL3241/57c5f6096912f7609373fst03duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __init__

2016-08-31 Thread monik...@netzero.net
Somebody in this line of emails mentioned that python provides default __init__ 
if it its not stated in the class by the programmer. And that it is called by 
__new__
Then later on you corrected that.

-- Original Message --
From: Alan Gauld via Tutor 
To: "monik...@netzero.net" 
Cc: tutor@python.org
Subject: Re: [Tutor] __init__
Date: Wed, 31 Aug 2016 00:25:42 +0100




On 30/08/16 22:08, monik...@netzero.net wrote:
> OK so somebodys remark that there is a default __init__ provided was not 
> correct.

It depends on how you interpret default.
In so far as object is the default superclass (in v3)
and it provides an init then there is a default, but
its not part of the language per se but of the standard
object model.
> What about old style classes?

That's a very good question and I don't know the answer.
Hopefully someone else does!

Alan G
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


The ICTM (Sponsored by Content.Ad)
Diabetes Breakthrough That Will Bankrupt Diabetes Industry
http://thirdpartyoffers.netzero.net/TGL3241/57c657c7d3a4157c77d5cst01duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] generator object

2016-08-31 Thread monik...@netzero.net

So generator function returns generator object according to Aaron Maxwell. But 
does this mean that each time yields "returns" it is a generator object? So if 
there are 5 yield "returns" there are 5 generator objects? Or is there always 
only one generator object returned by the generator functions?
Can somebody please explain?
Thank you
Monika
-- Original Message --
From: Alan Gauld via Tutor 
To: "monik...@netzero.net" 
Cc: tutor@python.org
Subject: Re: [Tutor] __init__
Date: Wed, 31 Aug 2016 00:25:42 +0100




On 30/08/16 22:08, monik...@netzero.net wrote:
> OK so somebodys remark that there is a default __init__ provided was not 
> correct.

It depends on how you interpret default.
In so far as object is the default superclass (in v3)
and it provides an init then there is a default, but
its not part of the language per se but of the standard
object model.
> What about old style classes?

That's a very good question and I don't know the answer.
Hopefully someone else does!

Alan G
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Health News 24 (Sponsored by Content.Ad)
Granny Reveals Her Method: Don't Use Botox, Do This Instead
http://thirdpartyoffers.netzero.net/TGL3241/57c65972bb39559723662st04duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] generator object

2016-08-31 Thread monik...@netzero.net
Thank you everybody. This was very helpful
Monika

-- Original Message --
From: Steven D'Aprano 
To: tutor@python.org
Subject: Re: [Tutor] generator object
Date: Wed, 31 Aug 2016 21:24:57 +1000

On Wed, Aug 31, 2016 at 04:12:24AM +0000, monik...@netzero.net wrote:
> 
> So generator function returns generator object according to Aaron 
> Maxwell. But does this mean that each time yields "returns" it is a 
> generator object? So if there are 5 yield "returns" there are 5 
> generator objects? Or is there always only one generator object 
> returned by the generator functions? 
> Can somebody please explain?


The terminology can be confusing, because there are multiple very 
similar terms which are related. But fortunately, we can ask Python 
itself for help!

Let's start by using the inspect module to take a look at an ordinary 
function:

py> import inspect
py> def func():
... return 19
...
py> inspect.isfunction(func)
True
py> inspect.isgenerator(func)
False
py> inspect.isgeneratorfunction(func)
False


So that's pretty straight-forward: a regular function is just a 
function.

What happens if we make something which people often call "a generator"? 
Let's make a function and use yield instead of return:

py> def gen():
... yield 19
...
py> inspect.isfunction(gen)
True
py> inspect.isgenerator(gen)
False
py> inspect.isgeneratorfunction(gen)
True

So there you have it: a function with "yield" inside is still a 
function, but it is also a "generator function". Even though people 
often call it "a generator", it isn't technically a generator. It's a 
generator function.


If we call the generator function, what do we get?

py> it = gen()
py> inspect.isfunction(it)
False
py> inspect.isgenerator(it)
True
py> inspect.isgeneratorfunction(it)
False


So there we have it, all official: calling a generator FUNCTION returns 
a generator.

But in practice, people will use the term "generator" for both generator 
functions like "gen", and the actual generators like "it". Normally the 
distinction isn't important, or it is obvious. When it isn't obvious, 
you can avoid ambiguity by referring to "gen" as the generator function, 
and "it" as the generator object.



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


moneynews.com (Sponsored by Content.Ad)
5 Stocks to Buy Now | Massive Market Correction
http://thirdpartyoffers.netzero.net/TGL3241/57c70d06c606fd062da7st02duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] generator object

2016-08-31 Thread monik...@netzero.net
Aaron Maxwell made a clear distinction between generator function and that it 
returns a generator object. He emphasized that a couple of times.

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] generator object
Date: Wed, 31 Aug 2016 08:56:21 +0100

On 31/08/16 05:12, monik...@netzero.net wrote:
>
> So generator function returns generator object according to Aaron Maxwell.

I don't believe that's correct.

A generator function can return any kind of object including
basic types like numbers, bool etc.In addition, a generator
function yields values which can also be of any type.

It might be valid to say that a generator function *is* a generator
object, but I'll leave that distinction to the language lawyers
to debate.

Alan G

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Health News 24 (Sponsored by Content.Ad)
Don't Use Botox, Use This Instead: Granny Reveals $39 Method
http://thirdpartyoffers.netzero.net/TGL3241/57c706939da2b6930d55st04duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __init__

2016-08-31 Thread monik...@netzero.net
Thank you very much. This was very helpful.

-- Original Message --
From: Steven D'Aprano 
To: tutor@python.org
Subject: Re: [Tutor] __init__
Date: Wed, 31 Aug 2016 22:39:33 +1000

On Wed, Aug 31, 2016 at 04:05:26AM +0000, monik...@netzero.net wrote:

> Somebody in this line of emails mentioned that python provides default 
> __init__ if it its not stated in the class by the programmer. And that 
> it is called by __new__

That may have been me, except I didn't mention __new__.

> Then later on you corrected that.

Instantiation of classes is slightly different in Python 2 and 3. In 
Python 3, there is only one mechanism. When you have a class, and you 
create an instance: 

instance = MyClass(args)

the following happens:

instance = MyClass.__new__(args)
instance.__init__(args)


That is a simplified description, the actual details are a bit more 
complicated, but if you think of it like the above, you will be okay 
except for the most unusual situations.

Does this mean that all classes must define __new__ and __init__? No! If 
you don't define them, your class will inherit them from the root of the 
class hierarchy, "object". object has those methods built-in:

py> object.__new__

py> object.__init__


and if you don't override one or both, you get the superclass method and 
its default behaviour. object.__new__ actually creates the instance, and 
object.__init__ takes no arguments and does nothing.

In Python 3, writing:

class MyClass(object):

or just

class MyClass:

has the same effect. Both cases inherit from object.


Things are a bit more complicated in Python 2. If you inherit from 
object, or from some other type that inherits from object (such as int, 
float, list, dict etc) then it behaves just like Python 3. But if you 
don't inherit from object, if you write:

class MyClass:

with no parent classes listed, you get the legacy Python 1 behaviour, 
so-called "old-style" or "classic" classes.

You probably don't want to use classic classes. All sorts of things 
don't work with them, such as super, property, classmethod, 
staticmethod, and __slots__. Avoid classic classes unless you know what 
you are doing.

In a classic class, there is no __new__ method. Only __init__ is called. 
If you don't write an __init__ method, Python performs a default 
initialisation, but there's no method involved. The interpreter has the 
behaviour hard-coded, unless you override it.

So for both Python 3 "new-style" classes, and Python 2 "old-style" 
classes, writing __init__ in optional. If you don't write it, you get 
the default behaviour.




-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Health News 24 (Sponsored by Content.Ad)
Don't Use Botox, Use This Instead: Granny Reveals $39 Method
http://thirdpartyoffers.netzero.net/TGL3241/57c71b3ecf4711b3e1670st02duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] python projects

2016-09-01 Thread monik...@netzero.net
Hi:
I have been taking python classes for overa year now and studying and studying 
it all days long. However, I still cannot get a job as a python automation qa 
(despite of many years of experience in qa) because everybody is looking for a 
senior python developers for automation qa jobs. Entry level positions are 
rare. Is there a website where I could maybe do some python projects for 
somebody, for free or for low pay? Pretty soon I will have to take a survival 
job since my savings are ending and when that happens I will not have much time 
to practice python and all my hard work will go to waste.
Thank you very much
Monika

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] generator object
Date: Thu, 1 Sep 2016 00:23:53 +0100

On 31/08/16 23:24, Alan Gauld via Tutor wrote:

> Then I tried
> ...
> x = list(2)

Should be


list(gen(2))

I hope that was obvious...
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Health News 24 (Sponsored by Content.Ad)
Don't Use Botox, Use This Instead: Granny Reveals $39 Method
http://thirdpartyoffers.netzero.net/TGL3241/57c7be4cdccca3e4c38a6st04duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] python memory management

2016-09-01 Thread monik...@netzero.net
Hi:
Can somebody please explain how memory is managed by python? What kind of 
memory it uses? What structures use what kind of memory?
If many people work on the same project and have many instances of the same 
object how do they ensure that all instances are killed before the programs 
exit? Apparently if one of the programmer leaves a reference to object it might 
not be automatically deleted by python on exit. What is the command to do this?

Could somebody please explain how this works, especially on projects involving 
multiple programmers?
Thank you very much
Monika



DrAnkurWalia (Sponsored by Content.Ad)
Breaking: Delhi Girls Are Getting 5 Shades Fairer (Do This)
http://thirdpartyoffers.netzero.net/TGL3241/57c8379d62edd379d57b6st04duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python memory management

2016-09-01 Thread monik...@netzero.net
Thank you for your explanation. It is very clear and confirms what I thought I 
knew. However, I had a job interview and the interview said it was a mistake 
that I did not say that in cases when there are  multiple programmers, there 
might be some objects/references left and not deallocated from the memory by 
python. He asked me how this should be handles. 
So I told him that python has its automatic garbage collection which keeps 
track of all objects and references and deletes them as appropriate (similar 
what you state). I added that programmers can keep track of occurrences of 
object and make sure that it goes down to 0. And if it does not then use del to 
delete. However, he did not like my answer. So Im trying to learn from my 
mistakes and learn if an object or reference are still at the end of the 
program how they should be deleted. I had problem understanding him too well 
since he was calling from overseas (there was interference) and I could not 
understand his accent well. But I need to learn this for future interviews. 
Your posting states that this is not a problem but according to the interviewer 
it is. (I do not mean to be un-nice to you, sorry) So how this situation should 
be handled?
Thank you
Monika

-- Original Message --
From: Steven D'Aprano 
To: tutor@python.org
Subject: Re: [Tutor] python memory management
Date: Fri, 2 Sep 2016 04:10:02 +1000

On Thu, Sep 01, 2016 at 02:12:11PM +0000, monik...@netzero.net wrote:
> Hi:
> Can somebody please explain how memory is managed by python? What kind 
> of memory it uses? What structures use what kind of memory?
> If many people work on the same project and have many instances of the 
> same object how do they ensure that all instances are killed before 
> the programs exit? Apparently if one of the programmer leaves a 
> reference to object it might not be automatically deleted by python on 
> exit. What is the command to do this?
> 
> Could somebody please explain how this works, especially on projects 
> involving multiple programmers?


In general, you (almost) never need to care about memory management, 
Python will do it for you.

The number of programmers writing the code doesn't matter. What matters 
is how many times the program is running *at the same time*. Each time 
it runs, your computer's operating system (Windows, Linux, Mac OS X) 
will start what is called "a process", running the Python interpreter. 
When the process exits at the end, the OS will reclaim all the memory 
used and make it available for the next process.

While the program is running, the OS has to allocate memory between many 
different processes. On my computer, right now, I have over 200 
processes running. Most of them are handled by the OS, but the others 
include my email program, my web browser, a few text editors, my desktop 
manager, and many others. The OS manages the memory allocation.

As far as Python is concerned, it manages its own memory from what the 
OS gives it. When you assign a value:

name = "Inigo Montoya"

the Python interpreter allocates a chunk of memory in the memory heap to 
hold the string. It then tracks whether or not the string is being used. 
So long as the string is being used by your program, or *could possibly* 
be used, Python will hold onto that string, forever.

But as soon as it sees that it can no longer be used, it will free the 
memory and reuse it.

This process is called "garbage collection". You can google for more 
information, or ask here. Different Python interpreters use different 
garbage collectors:

IronPython uses the .Net garbage collector;

Jython uses the Java garbage collector;

PyPy has a few different ones that you can choose from;

and the CPython (that's the standard Python you are probably running) 
interpreter has two, a simple "reference counter" GC that works very 
fast but not very thoroughly, and a more thorough GC that picks up 
anything the reference counter can't handle.

(Mostly reference cycles: if one object has a reference to another, and 
that second object also has a reference to the first, that's a cycle. 
The reference counter can't deal with that, but the second GC can.)


Let's track the life-span of a chunk of memory. Suppose you write the 
following code in a module:


name = "Inigo Montoya"
print(name)
name = "The Dread Pirate Roberts"


The second assignment frees up the string "Inigo Montoya", as no part of 
your program can possibly access the old value any more, since it has 
been replaced by the new value. So the garbage collector frees that 
chunk of memory and makes it available for something else. This happens 
automatically, and virtually instantly.

You never need to care about allocating or deallocating memory. The 
interpreter has its own memory manager to do that, with a garbage 
collector to deall

Re: [Tutor] python memory management

2016-09-03 Thread monik...@netzero.net

By:
"reference cycles: if one object has a reference to another, and 
that second object also has a reference to the first, that's a cycle."

Is this what you mean? 
a = 5
b = a
a = b

I just want to make sure I understand.
Thank you very much for your explanation. 
Monika

-- Original Message --
From: Steven D'Aprano 
To: tutor@python.org
Subject: Re: [Tutor] python memory management
Date: Fri, 2 Sep 2016 04:10:02 +1000

On Thu, Sep 01, 2016 at 02:12:11PM +, monik...@netzero.net wrote:
> Hi:
> Can somebody please explain how memory is managed by python? What kind 
> of memory it uses? What structures use what kind of memory?
> If many people work on the same project and have many instances of the 
> same object how do they ensure that all instances are killed before 
> the programs exit? Apparently if one of the programmer leaves a 
> reference to object it might not be automatically deleted by python on 
> exit. What is the command to do this?
> 
> Could somebody please explain how this works, especially on projects 
> involving multiple programmers?


In general, you (almost) never need to care about memory management, 
Python will do it for you.

The number of programmers writing the code doesn't matter. What matters 
is how many times the program is running *at the same time*. Each time 
it runs, your computer's operating system (Windows, Linux, Mac OS X) 
will start what is called "a process", running the Python interpreter. 
When the process exits at the end, the OS will reclaim all the memory 
used and make it available for the next process.

While the program is running, the OS has to allocate memory between many 
different processes. On my computer, right now, I have over 200 
processes running. Most of them are handled by the OS, but the others 
include my email program, my web browser, a few text editors, my desktop 
manager, and many others. The OS manages the memory allocation.

As far as Python is concerned, it manages its own memory from what the 
OS gives it. When you assign a value:

name = "Inigo Montoya"

the Python interpreter allocates a chunk of memory in the memory heap to 
hold the string. It then tracks whether or not the string is being used. 
So long as the string is being used by your program, or *could possibly* 
be used, Python will hold onto that string, forever.

But as soon as it sees that it can no longer be used, it will free the 
memory and reuse it.

This process is called "garbage collection". You can google for more 
information, or ask here. Different Python interpreters use different 
garbage collectors:

IronPython uses the .Net garbage collector;

Jython uses the Java garbage collector;

PyPy has a few different ones that you can choose from;

and the CPython (that's the standard Python you are probably running) 
interpreter has two, a simple "reference counter" GC that works very 
fast but not very thoroughly, and a more thorough GC that picks up 
anything the reference counter can't handle.

(Mostly reference cycles: if one object has a reference to another, and 
that second object also has a reference to the first, that's a cycle. 
The reference counter can't deal with that, but the second GC can.)


Let's track the life-span of a chunk of memory. Suppose you write the 
following code in a module:


name = "Inigo Montoya"
print(name)
name = "The Dread Pirate Roberts"


The second assignment frees up the string "Inigo Montoya", as no part of 
your program can possibly access the old value any more, since it has 
been replaced by the new value. So the garbage collector frees that 
chunk of memory and makes it available for something else. This happens 
automatically, and virtually instantly.

You never need to care about allocating or deallocating memory. The 
interpreter has its own memory manager to do that, with a garbage 
collector to deallocate memory.

So, when do you need to care about memory?

- If you are writing a C extension, you have to manage your own memory.

- If you're using the ctypes module, you have access to the C code of 
  the interpreter, so you have to care about managing your own memory.

- If you're creating massively huge strings or lists, you might have to 
  worry about running out of memory.

For example, I once locked up my computer by foolishly creating a HUGE 
list:

# Don't try this at home!
L = list(range(100**100))


That would need to find enough memory for a list with one hundred 
trillion trillion trillion trillion trillion trillion trillion trillion 
trillion trillion trillion trillion trillion trillion trillion trillion 
trillion trillion trillion trillion trillion trillion entries. Each 
entry will take at least four bytes, so the total is ... well, it's a 
lot. Much more than my poor computer has.

On Windo

Re: [Tutor] python memory management

2016-09-03 Thread monik...@netzero.net
So what does [...] mean?

-- Original Message --
From: Peter Otten <__pete...@web.de>
To: tutor@python.org
Subject: Re: [Tutor] python memory management
Date: Sat, 03 Sep 2016 14:26:12 +0200

monik...@netzero.net wrote:

> 
> By:
> "reference cycles: if one object has a reference to another, and
> that second object also has a reference to the first, that's a cycle."
> 
> Is this what you mean?
> a = 5
> b = a
> a = b

No. int instances are immutable. The assignments above bind both /names/ a 
and b to the same instance of int -- 5. The last statement a = b is 
redundant as a is already bound to 5.

For a reference cycle you need something in an object x to refer to another 
y and vice versa. x and y here are not Python names, but the actual objects.

An example using lists:

>>> a = ["a"]
>>> b = ["b"]

Let's append b to a:
>>> a.append(b)
>>> a[1]
['b']
>>> a[1][1]
Traceback (most recent call last):
  File "", line 1, in 
IndexError: list index out of range

We don't have a cycle yet, so Python eventually complains.
Now let's complete the cycle by appending b to a.

>>> b.append(a)
>>> a[1][1]
['a', ['b', [...]]]
>>> a[1][1][1][1][1]
['b', ['a', [...]]]

We can keep accessing x[1] forever, and if Python weren't smart enough to 
detect the cycle instead of producing the [...] it would continue building 
the string representation for the nested lists until all available memory 
was consumed or the stack overflowed.

Another example with a custom class:

>>> class C:
...def __init__(self, name): self.name = name
...def __repr__(self): return self.name
... 
>>> a = C("a")
>>> b = C("b")
>>> a
a
>>> b
b
>>> a.b = b
>>> b.a = a
>>> a.b.a.b.a.b.a.b.a.b.a
a

A cycle may of course consist of more than two objects:

>>> a = C("a")
>>> b = C("b")
>>> c = C("c")
>>> a.b = b
>>> b.c = c
>>> c.a = a
>>> c.a.b.c
c
>>> c.a.b.c.a.b.c.a.b.c
c

The minimal cycle consists of an object referencing itself:

>>> a = C("a")
>>> a.a = a
>>> a.a.a.a.a.a.a
a


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


howlifeworks.com (Sponsored by Content.Ad)
Why Women Are Flocking to This Incredible New Shopping Site
http://thirdpartyoffers.netzero.net/TGL3241/57cb3e00e29ee3e000c94st01duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python memory management

2016-09-04 Thread monik...@netzero.net
Thank you all for your explanations. I really enjoy learning about things like 
that.
Monika

-- Original Message --
From: Alan Gauld via Tutor 
To: zakaria , tutor@python.org
Subject: Re: [Tutor] python memory management
Date: Sun, 4 Sep 2016 01:22:27 +0100

On 03/09/16 23:20, zakaria wrote:
> Is there any practical usage of using reference cycling?

There are a (very) few cases where data structures require the
creation of cyclic references. One example I've used is in
managing comms networks where nodes are multiply and/or
cyclically linked and you need to build those linkages into
your data model. In those cases you need to manage the
cleanup yourself.

But most cyclic references occur by accident, the programmer
probably didn't intend them to exist but it just so happened that
one object points to another which happens to point at another
which in turn points at the first. The cycle can span many objects.
Think of a directory tree where a deeply nested node has a link
pointing back at a root level node. But the root also indirectly
points at that low level node by means of the tree structure...

As a specific example, It often happens in GUIs where widgets
hold references to other widgets higher in the widget
parent/child tree.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Unlock Visions (Sponsored by Content.Ad)
1 Odd Method 'Restores' Your 20/20 Vision. Try This
http://thirdpartyoffers.netzero.net/TGL3241/57cb93756ab9c13757ae2st02duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] cannot find html file, in the same dir as python file

2016-09-05 Thread monik...@netzero.net
Hi:
Im trying to learn Selenium with python. I have a html file button.html in the 
same directory as python file. I have the htnl file on my PC since my html file 
is much simpler for me to learn from than regular html files on the web. The 
blow code works with web html files but cannot find my button.html file on my 
PC. Why?

chromedriver = "resources/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
self.driver = webdriver.Chrome(chromedriver)
base_url = 'button.html'
self.driver.get(base_url)

FileNotFoundError: [WinError 2] The system cannot find the file specified
Even though this is in Selenium this is a python question. I think.
Thank you very much
Monika

Daily News (Sponsored by Content.Ad)
How Does This Delhi Student Makes Up to Rs 15000 Per Day?
http://thirdpartyoffers.netzero.net/TGL3241/57cddcf17f4b25cf11e5fst02duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cannot find html file, in the same dir as python file

2016-09-06 Thread monik...@netzero.net
I put 

print( os.getcwd() )

into my script, and got 

C:\Users\Monika\Documents\PythonWeb\class3code\class3code

So I put into my script:

base_url = 
'C:\Users\Monika\Documents\PythonWeb\class3code\class3code\button.html' instead 
of base_url = 'button.html'
and ran it andI got a popup message in python:


(unicode error) 'unicodesscape' codec can't decode bytes in position 2-3; 
truncated  \Uescape



- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] cannot find html file, in the same dir as python file
Date: Tue, 6 Sep 2016 01:25:27 +0100

On 05/09/16 21:59, monik...@netzero.net wrote:

> chromedriver = "resources/chromedriver"
> os.environ["webdriver.chrome.driver"] = chromedriver
> self.driver = webdriver.Chrome(chromedriver)
> base_url = 'button.html'
> self.driver.get(base_url)
> 
> FileNotFoundError: [WinError 2] The system cannot find the file specified
> Even though this is in Selenium this is a python question. I think.

Have you tried giving it the full path?

Have you tried asking Python where it is looking, eg

print( os.getcwd() )

Just in case Python is not running where you think
it is - I can't remember how windows decides... and
its better not to guess anyway.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


howlifeworks.com (Sponsored by Content.Ad)
How to Read Your Child's Deleted Texts - Get Your Free Trial
http://thirdpartyoffers.netzero.net/TGL3241/57ce27cfe928e27cf1ef7st04duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cannot find html file, in the same dir as python file

2016-09-06 Thread monik...@netzero.net
The r trick did it. Yay! 
Thank you
Monika

-- Original Message --
From: Alan Gauld 
To: "monik...@netzero.net" 
Cc: tutor@python.org
Subject: Re: [Tutor] cannot find html file, in the same dir as python file
Date: Tue, 6 Sep 2016 08:43:03 +0100

On 06/09/16 03:18, monik...@netzero.net wrote:
> I put 
>
> print( os.getcwd() )
>
> into my script, and got 
>
> C:\Users\Monika\Documents\PythonWeb\class3code\class3code

Is that the directory you expected? Is it where your html file lives?

> So I put into my script:
>
> base_url = 
> 'C:\Users\Monika\Documents\PythonWeb\class3code\class3code\button.html' 
> instead of base_url = 'button.html'
> and ran it andI got a popup message in python:
>
> (unicode error) 'unicodesscape' codec can't decode bytes in position 2-3; 
> truncated  \Uescape

Because you are using a single backslash Python sees the \U as a Unicode
indicator. Either change the backslashes to forward slashes or put an 'r'
in front of the string to make it raw:

base_url = r'C:\Users\Monika\Documents\.'


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


moneynews.com (Sponsored by Content.Ad)
5 Stocks to Buy Now | Massive Market Correction
http://thirdpartyoffers.netzero.net/TGL3241/57cee48f50a49648f16dfst01duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] @property for old style classes vs new style classes

2016-09-15 Thread monik...@netzero.net

Hi:
Im studying @property, @var.setter and @var.deleter.
I understand how they work in new style classes. Even though I do not use old 
style classes it would be interesting to understand what is going on behind the 
scenes. I can try to make assumptions but I do not want to because they might 
be incorrect. 
Could somebody please explain what is going on for old style classes for the 
below code:
class GetSet():

def __init__(self, value):
self.attrval = value

@property
def var(self):
print "getting the var attribute"
return self.attrval
@var.setter 
def var(self,value):
print "setting the var attribute"
self.attrval = value

@var.deleter
def var(self):
print "deleting the var attribute"
self.attrval = None

me = GetSet(5)
me.var = 1000
print me.var
del me.var
print me.var

Output:
1000
getting the var attribute
5
>>>


Same code but with new style classes (this one I understand):
class GetSet(object):

def __init__(self, value):
self.attrval = value

@property
def var(self):
print ("getting the var attribute")
return self.attrval
@var.setter
def var(self,value):
print ("setting the var attribute")
self.attrval = value

@var.deleter
def var(self):
print ("deleting the var attribute")
self.attrval = None

me = GetSet(5)
me.var = 1000
print (me.var)
del me.var
print (me.var)

Output:
setting the var attribute
getting the var attribute
1000
deleting the var attribute
getting the var attribute
None

Thank you very much
Monika

Unlock Visions (Sponsored by Content.Ad)
1 Odd Method 'Restores' Your 20/20 Vision. Try This
http://thirdpartyoffers.netzero.net/TGL3241/57da2673b610726731820st03duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] @property for old style classes vs new style classes

2016-09-15 Thread monik...@netzero.net
Thank you both for your explanations but they were too difficult for me to 
understand.
What is descriptor protocol? Can you please explain? 
I checked for var in both instance and class __dict__ but it was only in class, 
not in the instance. I checked for it after I instantiated me, before deletion. 
So now the post explaining it to me does not make a full sense.
So it seem to me that the class on udemy did not explain very well how this 
@property works (they talked only about new classes). Now after reading the 
posts several times I feel I understand less how it works. 
Could somebody please explain how @property works in new classes? What is going 
on behind the scenes? And then how in comparison with old classes? I will 
reread the posts again and maybe I will understand it better. Please explain in 
simple English. :)
Thank you very much
Monika
-- Original Message --
From: Steven D'Aprano 
To: tutor@python.org
Subject: Re: [Tutor] @property for old style classes vs new style classes
Date: Fri, 16 Sep 2016 02:57:12 +1000

On Thu, Sep 15, 2016 at 04:40:22AM +0000, monik...@netzero.net wrote:

> Could somebody please explain what is going on for old style classes for the 
> below code:

The important part is that the descriptor protocol doesn't get used for 
old style classes. If that statement means something to you, that's 
great, otherwise please ask. So in an old-style class:


> class GetSet():
> 
> def __init__(self, value):
> self.attrval = value
> 
> @property
> def var(self):
> print "getting the var attribute"
> return self.attrval
> @var.setter 
> def var(self,value):
> print "setting the var attribute"
> self.attrval = value

At this point, you have a class GetSet, with a class attribute:

GetSet.var

which is a property object. Now let's make an instance:

> me = GetSet(5)
> me.var = 1000

At this point, the instance now has an instance attribute:

me.var

which is the int 1000. So there are now TWO attributes called "me", 
living in different scopes:

me.__dict__['var'] = 1000  # in the instance

GetSet.__dict__['var'] = property object


Remember that attribute look-ups normally look in the instance __dict__ 
before the class __dict__.


> print me.var
> del me.var
> print me.var

The first print looks for 'var' in the instance, finds it, and prints 
1000. Then the del command looks for 'var' in the instance, finds it, 
and deletes it. Then finally the second print looks for 'var' in the 
instance, *doesn't* find it there (because it has been deleted), so it 
looks in the class, and finds GetSet.__dict__['var'] which is a property 
object.

At this point, things get a bit mysterious. According to the 
documentation, Python ought to print something like:



since the descriptor protocol doesn't run for old-style classes. But 
apparently it does *partly* run, because the property object's __get__ 
method is invoked, which calls the getter method that you defined.


> Output:
> 1000
> getting the var attribute
> 5


So there is a part mystery here. As far as I can tell, the documentation 
suggests that the output should be:

1000


rather than what you got.




-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Do This Before Bed Tonight to Burn Belly Flab All Night Long
Flat Belly Overnight
http://thirdpartyoffers.netzero.net/TGL3241/57db10cd7d30310cd7bb9st01duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] @property for old style classes vs new style classes

2016-09-15 Thread monik...@netzero.net
For both old and new classes I have var only in GetSet class, but not in 
instance me. Why?
print me.__dict__
print GetSet.__dict__

{'attrval': 5}

{'__weakref__': , '__doc__': None, 
'__module__': '__main__', '__init__': , 
'__dict__': , 'var': }
>>> 

Thank you very much
Monika

-- Original Message --
From: Steven D'Aprano 
To: tutor@python.org
Subject: Re: [Tutor] @property for old style classes vs new style classes
Date: Fri, 16 Sep 2016 02:57:12 +1000

On Thu, Sep 15, 2016 at 04:40:22AM +, monik...@netzero.net wrote:

> Could somebody please explain what is going on for old style classes for the 
> below code:

The important part is that the descriptor protocol doesn't get used for 
old style classes. If that statement means something to you, that's 
great, otherwise please ask. So in an old-style class:


> class GetSet():
> 
> def __init__(self, value):
> self.attrval = value
> 
> @property
> def var(self):
> print "getting the var attribute"
> return self.attrval
> @var.setter 
> def var(self,value):
> print "setting the var attribute"
> self.attrval = value

At this point, you have a class GetSet, with a class attribute:

GetSet.var

which is a property object. Now let's make an instance:

> me = GetSet(5)
> me.var = 1000

At this point, the instance now has an instance attribute:

me.var

which is the int 1000. So there are now TWO attributes called "me", 
living in different scopes:

me.__dict__['var'] = 1000  # in the instance

GetSet.__dict__['var'] = property object


Remember that attribute look-ups normally look in the instance __dict__ 
before the class __dict__.


> print me.var
> del me.var
> print me.var

The first print looks for 'var' in the instance, finds it, and prints 
1000. Then the del command looks for 'var' in the instance, finds it, 
and deletes it. Then finally the second print looks for 'var' in the 
instance, *doesn't* find it there (because it has been deleted), so it 
looks in the class, and finds GetSet.__dict__['var'] which is a property 
object.

At this point, things get a bit mysterious. According to the 
documentation, Python ought to print something like:



since the descriptor protocol doesn't run for old-style classes. But 
apparently it does *partly* run, because the property object's __get__ 
method is invoked, which calls the getter method that you defined.


> Output:
> 1000
> getting the var attribute
> 5


So there is a part mystery here. As far as I can tell, the documentation 
suggests that the output should be:

1000


rather than what you got.




-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Do This Before Bed Tonight to Burn Belly Flab All Night Long
Flat Belly Overnight
http://thirdpartyoffers.netzero.net/TGL3241/57db0db4a9dedb31f3bst04duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] @property for old style classes vs new style classes

2016-09-15 Thread monik...@netzero.net
I figured out why you have var in instance __dict__. 
It was after you added it. But why var is in class __dict__?
Does @property make it a class attribute?
Thank you
Monika

-- Original Message --
From: Steven D'Aprano 
To: tutor@python.org
Subject: Re: [Tutor] @property for old style classes vs new style classes
Date: Fri, 16 Sep 2016 02:57:12 +1000

On Thu, Sep 15, 2016 at 04:40:22AM +0000, monik...@netzero.net wrote:

> Could somebody please explain what is going on for old style classes for the 
> below code:

The important part is that the descriptor protocol doesn't get used for 
old style classes. If that statement means something to you, that's 
great, otherwise please ask. So in an old-style class:


> class GetSet():
> 
> def __init__(self, value):
> self.attrval = value
> 
> @property
> def var(self):
> print "getting the var attribute"
> return self.attrval
> @var.setter 
> def var(self,value):
> print "setting the var attribute"
> self.attrval = value

At this point, you have a class GetSet, with a class attribute:

GetSet.var

which is a property object. Now let's make an instance:

> me = GetSet(5)
> me.var = 1000

At this point, the instance now has an instance attribute:

me.var

which is the int 1000. So there are now TWO attributes called "me", 
living in different scopes:

me.__dict__['var'] = 1000  # in the instance

GetSet.__dict__['var'] = property object


Remember that attribute look-ups normally look in the instance __dict__ 
before the class __dict__.


> print me.var
> del me.var
> print me.var

The first print looks for 'var' in the instance, finds it, and prints 
1000. Then the del command looks for 'var' in the instance, finds it, 
and deletes it. Then finally the second print looks for 'var' in the 
instance, *doesn't* find it there (because it has been deleted), so it 
looks in the class, and finds GetSet.__dict__['var'] which is a property 
object.

At this point, things get a bit mysterious. According to the 
documentation, Python ought to print something like:



since the descriptor protocol doesn't run for old-style classes. But 
apparently it does *partly* run, because the property object's __get__ 
method is invoked, which calls the getter method that you defined.


> Output:
> 1000
> getting the var attribute
> 5


So there is a part mystery here. As far as I can tell, the documentation 
suggests that the output should be:

1000


rather than what you got.




-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


15 Actors Who Are Gay - No. 12 Will Shock Women
trendytribune.com
http://thirdpartyoffers.netzero.net/TGL3241/57db177b8815a177b1d3dst03duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] maximum recursion error

2016-09-16 Thread monik...@netzero.net

Hi:
Below is code where mistakenly self.var is named the same as function var 
instead of a different name. I know that this is not correct but I was 
experimenting to see what happens.
class GetSet():

def __init__(self, value):
#self.attrval = value
self.var = value

@property
def var(self):
print "getting the var attribute. "
#return self.attrval
return self.var
@var.setter 
def var(self,value):
print "setting the var attribute"
#self.attrval = value
self.var = value

@var.deleter
def var(self):
print "deleting the var attribute. "
#self.attrval = None
self.var = None

When I run the code with below I get " maximum recursion depth exceeded while 
calling a Python object" which is what I expected.
me = GetSet(5)
me.var = 1000
print me.var   - I do not get "max recursion error" here. Why?
del me.var
print me.var   - Here I get "max recursion error"

What I do not understand is why I do not get the same error when runing below:

me = GetSet(5)
me.var = 1000
print me.var

Why do I get the error after I do del but not without del? Why do I get the 
error after doing print me.var for the second time but not for the first time? 
In my understanding I should get the recursion error after the first print 
me.var.
Why do I have to del and print again me.var to get the "max recursion error"?
Thank you very much
Monika




Do This Before Bed Tonight to Burn Belly Flab All Night Long
Flat Belly Overnight
http://thirdpartyoffers.netzero.net/TGL3241/57db5afb836b65afb35f7st04duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] __getitem__

2016-11-23 Thread monik...@netzero.net
Hi:
Can you please explain __getitem__? My understanding is that it brings back 
dictionary's value. Is this correct? If so which value does it bring? Does it 
look up this value by using a key? Where is this key specified in  " 
numbers.__getitem__"   ?

The below supposedly brings back dictionary's keys list  sorted by values. But 
how does it do it?

numbers = {'first': 1, 'second': 2, 'third': 3, 'Fourth': 4}
sorted(numbers, key=numbers.__getitem__)

Thank you very much
Monika



3 Signs You May Have a Fatty Liver [Watch]
livecellresearch.com
http://thirdpartyoffers.netzero.net/TGL3241/583532f442b7c32f440b1st04duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] __getitem__ another problem

2016-11-23 Thread monik...@netzero.net
Hi:
Can you please explain what is going on below? I do not understand how 
numbermap.__getitem__ brings back month's key.
Does numbermap.__getitem__ bring back numbermap key or value? If key then it is 
not consistent with my understanding of problem in my previous email.  So month 
is sorted by numbermap values or keys?


month = dict(one='January',
 two='February',
 three='March',
 four='April',
 five='May')
numbermap = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}
sorted(month, key=numbermap.__getitem__)
['one', 'two', 'three', 'four', 'five']
This is from:
http://pythoncentral.io/how-to-sort-python-dictionaries-by-key-or-value/

Which Haircuts Look Exceptional on Older Women?
starsgossip.com
http://thirdpartyoffers.netzero.net/TGL3241/583536c537dff36c4036dst01duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __getitem__

2016-11-23 Thread monik...@netzero.net
Hi:
Thank you very much for your explanation. Just to confirm when using 
__getitem__ sort will go thru every key in dict and get its value and then sort 
according to it. Correct?

Also, you wrote:

">>> sorted(numbers, key = lambda ky: numbers[ky])  "

ky is input to lambda. Where does lambda get ky? what is ky value?
Thank you very much
Monika

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] __getitem__
Date: Wed, 23 Nov 2016 10:05:50 +

On 23/11/16 06:09, monik...@netzero.net wrote:

> Can you please explain __getitem__? 

__getitem__ is the operator overload for indexing.
It is like the __add__() method which overloads the + operator.
So if you imple,ent __add__() in your class you can add two instances
together using + and Python calls your __add__() method behind the scenes.
In the same way when you index a collection object (with []) Python
calls the __getitem__ method behind the scenes. So for a dictionary
you can access the values of the dictionary by indexing it with a key:

d = {1:2,3:4}
n = d[1]   # calls d.__getitem__(1) resulting in n = 2

> My understanding is that it brings back dictionary's value. 
> Is this correct?

It brings back the value of the provided key.

> If so which value does it bring? 
> Does it look up this value by using a key?

Yes.

> Where is this key specified in  " numbers.__getitem__"   ?

Either by using indexing like numbers[somekey] or by
someone explicitly calling numbers.__getitem__(aKey)

In your example below sorted accesses the values
using the supplied function (which can be any arbitrary
function that accepts an argument and returns a value.)
By providing __getitem__ as the input function sorted
effectively uses the dictionary values.

> The below supposedly brings back dictionary's keys list  sorted by values. 
> But how does it do it?

By making the sort key the value of each dictionary key in turn

> numbers = {'first': 1, 'second': 2, 'third': 3, 'Fourth': 4}
> sorted(numbers, key=numbers.__getitem__)

If you try it at the prompt:

>>> numbers = {'first': 1, 'second': 2, 'third': 3, 'Fourth': 4}
>>> sorted(numbers, key=numbers.__getitem__)
['first', 'second', 'third', 'Fourth']

You see it works. Now try without getitem:

>>> sorted(numbers)
['Fourth', 'first', 'second', 'third']

This is sorted by the keys. Now lets use a different
sort method to get the values:

def getValue(aKey): return numbers[aKey]

This uses the more familiar indexing technique
to retrieve the value for a given key. We can
now use this function with sorted to get the
original result:

>>> sorted(numbers, key = getValue)
['first', 'second', 'third', 'Fourth']


And we can miss out the separate function definition
by using a lambda:

>>> sorted(numbers, key = lambda ky: numbers[ky])
['first', 'second', 'third', 'Fourth']
>>>

But the authors of your example have used __getitem__
directly because it's already available...(and the indexing
technique calls __getitem__ indirectly anyway).

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Affordable Wireless Plans
Set up is easy. Get online in minutes.
Starting at only $14.95 per month! 
www.netzero.net?refcd=nzmem0216
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __getitem__

2016-11-23 Thread monik...@netzero.net

Hi:
I have two questions in regards to below code:
1. largest is a list, not a list of lists. 
[('deit', 4), ('acer', 3), ('aceilmr', 2), ('arst', 2)]
so why when I do largest[0] I get the whole list again, not just the first item 
from the list. To get the first item I have to do largest[0][0].

2. largest = [sorted(analist, key=lambda analist: analist[1], reverse=True)]
brings back the same result as:
largest = [sorted(analist, key=lambda d: d[1], reverse=True)]
and the same result as:
largest = [sorted(analist, key=lambda x: x[1], reverse=True)]
The result is:
[('deit', 4), ('acer', 3), ('aceilmr', 2), ('arst', 2)]

I really do not understand why and how this works. Could you please explain?
in lambda x: x[1] I pass x to lambda and it does calculation of x[1] but where 
does it get the x, what is the value of x? 
why lambda x: x[1] brings the same result as lambda d: d[1] and lambda analist: 
analist[1]

#question. have a list of words. check for anagrams
#count how many anagrams there are.
#do it thru dictionary
#then get anagaram list which has the biggest amount of words
words = ["miracle", "claimer", "care", "race", "arts", "rats", "acre","diet", 
"edit", "tide", "tied"]
def anagram(words):
d = {}
for word in words:
wordl = list(word)
print "word as list:  " , wordl
wordlsorted = sorted(wordl)
print "word lsit sorted:  " , wordlsorted
wordsorted = ''.join(wordlsorted)
print "word sorted as string:   ", wordsorted
d[wordsorted] = d.get(wordsorted, []) + [word]

print d
analist = [(key , len(value)) for key, value in d.items()]
print analist
print "largest:  ", [sorted(analist, key=lambda analist: analist[1], 
reverse=True)][0]
largest = [sorted(analist, key=lambda analist: analist[1], reverse=True)]
print type(largest)
print largest[0][0]

anagram(words)

Thank you very much in advance for explaining this.
Monika

Eat This Junk Food To "Reverse" Dementia
Nutrition and Healing
http://thirdpartyoffers.netzero.net/TGL3241/58358b1017902b0f1d93st02duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __getitem__ another problem

2016-11-23 Thread monik...@netzero.net
So numbermap.__getitem__ brings back 1, then 2,then 3, then 4. 
Then it looks up 1 ,2, 3, 4 in month but there is no  key with value 1, 2, or 
or in 4. 
What am I missing?
Thank you very much
Monika

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] __getitem__ another problem
Date: Wed, 23 Nov 2016 10:09:46 +

On 23/11/16 06:26, monik...@netzero.net wrote:

> I do not understand how numbermap.__getitem__ brings back month's key.

numbermap returns the integer corresponding to the key.
That number is then used by sorted as the basis for
sorting month. So for the first entry sorted receives
the value 1, for the second it gets 2. and so on.
It then prints the keys corresponding to those
values.

> month = dict(one='January',
>  two='February',
>  three='March',
>  four='April',
>  five='May')
> numbermap = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}
> sorted(month, key=numbermap.__getitem__)
> ['one', 'two', 'three', 'four', 'five']

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


7-Time Lotto Winner Reveals The Truth How To Win Any Lottery
MNT
http://thirdpartyoffers.netzero.net/TGL3241/58358cba68d69cba49c6st04duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __getitem__

2016-11-24 Thread monik...@netzero.net
Hi:
Thank you very much for ALL your postings. They help a lot and now things make 
sense.
Thank you
Monika

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] __getitem__
Date: Wed, 23 Nov 2016 22:25:08 +

On 23/11/16 12:25, monik...@netzero.net wrote:

> I have two questions in regards to below code:
> 1. largest is a list, not a list of lists. 
> [('deit', 4), ('acer', 3), ('aceilmr', 2), ('arst', 2)]
> so why when I do largest[0] I get the whole list again, 

I don't know you will need to show us some real code.
Ideally input at the >>> prompt.

> 2. largest = [sorted(analist, key=lambda analist: analist[1], reverse=True)]
> brings back the same result as:
> largest = [sorted(analist, key=lambda d: d[1], reverse=True)]
> and the same result as:
> largest = [sorted(analist, key=lambda x: x[1], reverse=True)]

Yes because it doesn't matter what you call the parameter of the lambda,
it's like any other function:

def add2(x): return x+2

def add2(y): return y+2

def add2(z): return z+2

All of these functions are identical they always do the same
regardless of what you call the parameter. Remember a lambda
is just a shortcut for a function

key = lambda d: d[1]

is identical to

def key(d): return d[1]

and

key = lambda analist: analist[1]

is identical to

def key(analist): return analist[1]

Just like the add2() examples it doesn't matter what
name you use for the parameter.

> ...but where does it get the x, what is the value of x? 

See my other post about how sorted() works.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


3 Signs You May Have a Fatty Liver [Watch]
livecellresearch.com
http://thirdpartyoffers.netzero.net/TGL3241/58363984eaf793984277ast02duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor