[Tutor] how to find the maximum length substring with equal 'a' and 'b' ?

2014-04-06 Thread Arup Rakshit
Suppose, if I have the string 'aababbb', I want to get the output as 'aababb'. I want the output in time complexity O(N) and space complexity O(1). when input string is 'abababa', output should be same as input. ___ Tutor maillist - Tutor@python.org T

[Tutor] Question about the object.__del__(self) method

2019-04-22 Thread Arup Rakshit
del__ says: > `del x` doesn’t directly call `x.__del__()` — the former decrements the > reference count for `x` by one, and the latter is only called when `x`’s > reference count reaches zero. Also what the reference count here means? I know that x can hold only one reference at a t

Re: [Tutor] Question about the object.__del__(self) method

2019-04-22 Thread Arup Rakshit
On 22/04/19 3:35 PM, Alan Gauld via Tutor wrote: On 22/04/2019 10:18, Arup Rakshit wrote: Consider the below in simple class: class RandomKlass: def __init__(self, x): self.x = x def __del__(self): print("Deleted…") Now when I delete the object cr

[Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Arup Rakshit
CustomList(list=[1, 2, 3, 4, 5, 6])     print(list[1:3])     print(list[3])     print("===\n")     list = MyCustomListV1(list=[1, 2, 3, 4, 5, 6])     print(list[1:3])     print(list[3]) If run it, I get the output: [2, 3] 4 === [2, 3] 4 -- T

Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Arup Rakshit
ent than in the body of __init__ method? Can you elaborate this? -- Thanks, Arup Rakshit ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

[Tutor] What protocol to follow when need to pick either one from __getattr__ and __getattribute__ ?

2019-04-23 Thread Arup Rakshit
ate this to educate me please? doc said: > This method should either return the (computed) attribute value or raise an AttributeError exception. Another question: My question is that: Can I raise a domain error like OperationNotPermitted when raising i

Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Arup Rakshit
On 23/04/19 10:08 PM, Steven D'Aprano wrote: On Tue, Apr 23, 2019 at 08:27:15PM +0530, Arup Rakshit wrote: You probably want:     def __init__(self, list=None): if list is None:     list = [] self.list = list That is really a new thing to me. I didn&#

[Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-24 Thread Arup Rakshit
are other reasons of this setup? import fine_grained_module fine_grained_module.foo = "foo” # Setting foo… repr(fine_grained_module) # 'Verbose fine_grained_module' Thanks, Arup Rakshit a...@zeit.io ___ Tutor maillist - Tutor@

Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-25 Thread Arup Rakshit
On 25/04/19 3:52 AM, Alan Gauld via Tutor wrote: On 24/04/2019 12:22, Arup Rakshit wrote: In the simple code like what are the advantages we get from? I'm not really sure what you are asking about? Ok. My question is that when people add such a class to the module? What is the goal/inte

Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-25 Thread Arup Rakshit
On 25/04/19 1:21 PM, Steven D'Aprano wrote: On Thu, Apr 25, 2019 at 11:30:28AM +0530, Arup Rakshit wrote: On 25/04/19 3:52 AM, Alan Gauld via Tutor wrote: On 24/04/2019 12:22, Arup Rakshit wrote: In the simple code like what are the advantages we get from? I'm not really sure wh

[Tutor] module import from a packager works inconsistent between REPL and command line

2019-04-25 Thread Arup Rakshit
izzapy import menu Traceback (most recent call last): File "", line 1, in File "/Users/aruprakshit/python_playground/pizza-shop/pizzapy/menu.py", line 2, in from pizza import Pizza ModuleNotFoundError: No module named 'pizza' >>> What is the reaso

Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-26 Thread Arup Rakshit
On 26/04/19 11:10 AM, Steven D'Aprano wrote: On Thu, Apr 25, 2019 at 02:52:07PM +0530, Arup Rakshit wrote: Here it is: *3.3.2.1. Customizing module attribute access* (https://docs.python.org/3/reference/datamodel.html#customizing-module-attribute-access) Oh! That's brand new in 3.7,

Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-26 Thread Arup Rakshit
On 26/04/19 8:58 PM, Alan Gauld via Tutor wrote: On 26/04/2019 13:48, Arup Rakshit wrote: BTW, one thing I would like to know about this list is that, everytime I send an email I see it the in list after 2 hours approx. Is this for me or everybody? I am just curious. Just for you! ...And

Re: [Tutor] module import from a packager works inconsistent between REPL and command line

2019-04-26 Thread Arup Rakshit
On 26/04/19 10:58 AM, Steven D'Aprano wrote: On Thu, Apr 25, 2019 at 05:40:18PM +0530, Arup Rakshit wrote: I have a small app like this: Please simplify your code to the minimum needed to demonstrate the problem you are asking about. This bit is excellent: pizza-shop$ tree . . └── pi

[Tutor] Use case of attaching list of strings as spec to the Mock.mock_add_spec() method?

2019-04-28 Thread Arup Rakshit
case. So if anyone can explain this, I will be very helpful. Thanks, Arup Rakshit a...@zeit.io ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

[Tutor] self.name is calling the __set__ method of another class

2019-04-29 Thread Arup Rakshit
ooks like some magic is going on under the hood. Can anyone please explain this how self.name and self.email assignment is called the __set__ from NonBlank? What is the name of this concept? Thanks, Arup Rakshit a...@zeit.io ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] self.name is calling the __set__ method of another class

2019-04-29 Thread Arup Rakshit
On 29/04/19 11:40 PM, Steven D'Aprano wrote: On Mon, Apr 29, 2019 at 11:25:51PM +0530, Arup Rakshit wrote: Now I am not getting how the __set__() method from NonBlank is being called inside the __init__() method. Looks like some magic is going on under the hood. Can anyone please explain

Re: [Tutor] self.name is calling the __set__ method of another class

2019-05-02 Thread Arup Rakshit
re I think I hit the wall everytime. Python doesn't work the way I am thinking it, and I am far behind of this. -- Thanks, Arup Rakshit ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] self.name is calling the __set__ method of another class

2019-05-02 Thread Arup Rakshit
On 30/04/19 5:11 AM, Steven D'Aprano wrote: On Tue, Apr 30, 2019 at 12:47:02AM +0530, Arup Rakshit wrote: I really didn't write that code by myself. The day I'll you will not see me here everyday :) . I was watching a PyCon video https://youtu.be/81S01c9zytE?t=8172 where the a

[Tutor] Local variable look up outside the function and method

2019-05-12 Thread Arup Rakshit
how these search happens in 2 contexts. Thanks, Arup Rakshit a...@zeit.io ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

[Tutor] How arguments to the super() function works?

2019-05-18 Thread Arup Rakshit
self.permissions = 0 Here, why super(Role, self).__init__(**kwargs) is used instead of super().__init__(**kwargs) ? What that Role and self argument is instructing the super() ? Thanks, Arup Rakshit a...@zeit.io ___ Tutor maillist - T

Re: [Tutor] How arguments to the super() function works?

2019-05-18 Thread Arup Rakshit
> On 19-May-2019, at 4:46 AM, Mark Lawrence wrote: > > On 18/05/2019 17:21, Arup Rakshit wrote: >> I am writing an Flask app following a book, where a piece of python concept >> I am not getting how it works. Code is: >> class Role(db.Model): >>

[Tutor] Python type annotation question

2019-06-24 Thread Arup Rakshit
n object at 0x10e078128> >>> p = Person(11) >>> p.dob 11 Although I marked dob as date type, why am I able to assign it an int? So my question how does type annotation helps, when should we use them and what advantages it brings? Thanks, Arup Rakshit a...@zeit.io ___