Re: [Tutor] 'int' object has no attribute 'items'

2016-09-03 Thread Steven D'Aprano
Hi Chidinma, I'm afraid it is very difficult for me to understand your code, because your email program (Yahoo mail perhaps?) has mangled the code and put it all on one single line: On Sat, Sep 03, 2016 at 09:45:17PM +, Chidinma via Tutor wrote: > def calculate_tax(dict_inp):  result = {} 

Re: [Tutor] python memory management

2016-09-03 Thread Alan Gauld via Tutor
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 n

Re: [Tutor] python memory management

2016-09-03 Thread Alan Gauld via Tutor
On 03/09/16 22:16, monik...@netzero.net wrote: > So what does [...] mean? Its Python's way of telling you that you have a self referential data structure. Its just a representational thing but without it Python would end up printing an infinite sequence of values. HTH -- Alan G Author of the Le

Re: [Tutor] python memory management

2016-09-03 Thread zakaria
Is there any practical usage of using reference cycling? On Sat, 2016-09-03 at 14:56 +0100, Alan Gauld via Tutor wrote: > On 03/09/16 04:25, monik...@netzero.net wrote: > > > > > Is this what you mean?  > > a = 5 > > b = a > > a = b > > No, you are confusing variable names with objects. > Here

Re: [Tutor] What's the correct way to define/access methods of a member variable in a class pointing to an object?

2016-09-03 Thread Sharad Singla
@Steven, @Khalil, @Alan Thanks for the inputs/explanations. Appreciate it! Regards Sharad ___ 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-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

[Tutor] 'int' object has no attribute 'items'

2016-09-03 Thread Chidinma via Tutor
Hello,Am trying to solve a problem, but keep getting different errors. Country X calculates tax for its citizens using a graduated scale rate as shown below: - Yearly Income: 0 - 1000Tax Rate: 0% - Yearly Income: 1,001 - 10,000Tax Rate: 10% - Yearly Income: 10,001 - 20,200Tax Rate: 15%

Re: [Tutor] What's the correct way to define/access methods of a member variable in a class pointing to an object?

2016-09-03 Thread Alan Gauld via Tutor
On 03/09/16 18:17, Steven D'Aprano wrote: > One classic example of the Law Of Demeter is: > > "If you want your dog to come to you, don't talk to your dog's legs, > talk to the dog." I love that, I've never seen it before but a great example. > But sometimes the Law Of Demeter should not apply

Re: [Tutor] What's the correct way to define/access methods of a member variable in a class pointing to an object?

2016-09-03 Thread Steven D'Aprano
On Sat, Sep 03, 2016 at 02:51:22PM +0100, Alan Gauld via Tutor wrote: [...] > The first thing to do is point out that what you > are asking about is the Law of Demeter on OOP. > See Wikipedia for a full description. In essence > it says that the user of an object should not > directly access that

Re: [Tutor] python projects

2016-09-03 Thread Steven D'Aprano
On Thu, Sep 01, 2016 at 05:35:33AM +, monik...@netzero.net wrote: > 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 eve

Re: [Tutor] python memory management

2016-09-03 Thread Steven D'Aprano
On Thu, Sep 01, 2016 at 08:21:36PM +, monik...@netzero.net wrote: > 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 prog

Re: [Tutor] python memory management

2016-09-03 Thread Alan Gauld via Tutor
On 03/09/16 04:25, monik...@netzero.net wrote: > Is this what you mean? > a = 5 > b = a > a = b No, you are confusing variable names with objects. Here you only have one object - the number 5. For a cycle you need at least 2 objects and those objects must be able to reference another object. In

Re: [Tutor] What's the correct way to define/access methods of a member variable in a class pointing to an object?

2016-09-03 Thread Alan Gauld via Tutor
On 03/09/16 06:55, Sharad Singla wrote: > What's the correct way to define/access methods of a member variable in a > class pointing to an object? Steven has already given you a long and comprehensive answer based on pragmatic python programming. But since you use the term "correct" I'll give you

Re: [Tutor] python memory management

2016-09-03 Thread Random832
On Fri, Sep 2, 2016, at 23:25, 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 > > I just want to make sure I under

Re: [Tutor] What's the correct way to define/access methods of a member variable in a class pointing to an object?

2016-09-03 Thread khalil zakaria Zemmoura
Hi, Composition is a technique that allows you to express the 'has a' relationship between your object. I'm not a specialist of the OOP but I can see some issues in the model that you expose in your mail. Encapsulation and abstraction are all about designing an API. It allows you to expose simpl

Re: [Tutor] python memory management

2016-09-03 Thread Peter Otten
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 /na

Re: [Tutor] What's the correct way to define/access methods of a member variable in a class pointing to an object?

2016-09-03 Thread Steven D'Aprano
On Sat, Sep 03, 2016 at 11:25:07AM +0530, Sharad Singla wrote: > Hi Pythonistas > > What's the correct way to define/access methods of a member variable in a > class pointing to an object? Python recommends that you start with the simplest thing that will work first, which is direct attribute ac

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 Mes

[Tutor] What's the correct way to define/access methods of a member variable in a class pointing to an object?

2016-09-03 Thread Sharad Singla
Hi Pythonistas What's the correct way to define/access methods of a member variable in a class pointing to an object? For example, I have a class Foo that has a method foo_method: class Foo: def foo_method(self): return 'bar' Now, in another class Bar, I'd like to store an object to