Re: Question on difference between LambdaType and FunctionType

2018-11-25 Thread Iwo Herka
> Why are lambda functions not instrumented? Because, if I didn't forget about anything, assignment in lambdas is invalid. That is, lambda self. self.x = 1 or lambda self: (self.x = 1) will throw SyntaxError. Therefore, I don't have to worry that someone will attempt to mutate the

Re: Question on difference between LambdaType and FunctionType

2018-11-25 Thread Chris Angelico
On Mon, Nov 26, 2018 at 7:45 AM Iwo Herka wrote: > > Everything works fine, except that I have to cover the following: > > foo = lambda self: None > > class Foo: > __init__ = foo > > Since I'm treating FunctionType and LambdaType differently (I don't have > to instrument lambdas,

Re: Question on difference between LambdaType and FunctionType

2018-11-25 Thread Iwo Herka
Chris Angelico wrote: > [...] why do you care about the difference? What is it in your code that > cares about whether a function was created with "def" or with "lambda"? In answer to my previous question on the list, (https://mail.python.org/pipermail/python-list/2018-November/738151.html),

Re: Question on difference between LambdaType and FunctionType

2018-11-25 Thread Chris Angelico
On Mon, Nov 26, 2018 at 6:54 AM Iwo Herka wrote: > > > That said, though: if you want to distinguish a lambda function from a > > def function, you can do so with reasonable reliability using the > > function's name: > > That's what I'm using currently, thank you for the suggestion. >

Re: Question on difference between LambdaType and FunctionType

2018-11-25 Thread Iwo Herka
> That said, though: if you want to distinguish a lambda function from a > def function, you can do so with reasonable reliability using the > function's name: That's what I'm using currently, thank you for the suggestion. Nonetheless, it feels hacky - that's why I tried to use LambdaType and, to

Re: Question on difference between LambdaType and FunctionType

2018-11-25 Thread Chris Angelico
On Mon, Nov 26, 2018 at 6:06 AM Iwo Herka wrote: > > Hello, > > Can someone please provide a use-case for having LambdaType > separate to FunctionType? Clarification: This is talking about the 'types' module. > Since they are equal > (LambdaType == FunctionType) it seems a bit superfluous to

Re: Question about implementing immutability

2018-11-22 Thread Iwo Herka
czw., 22 lis 2018 o 11:14 Thomas Jollans napisał(a): > [..] this allows other classes' __init__s to set attributes. Fair point. > I might try setting a self._fixed flag at the end of init and do a check > > if getattr(self, '_fixed', False): > raise TypeError(f"'{type(self)}' is immutable")

Re: Question about implementing immutability

2018-11-22 Thread Thomas Jollans
On 2018-11-21 17:45, Iwo Herka wrote: > Hello, > > Let's say I want to implement immutability for user-defined class. > More precisely, a class that can be modified only in its (or its > super-class') __init__ method. My initial idea was to do it the > following fashion: > > def

Re: Question about implementing immutability

2018-11-22 Thread Iwo Herka
czw., 22 lis 2018 o 10:53 Thomas Jollans napisał(a): > If you're tempted to go down that route and can require Python 3.7, use > dataclasses! I'm aware of them, thanks. :) Dataclasses are great for certain use-cases; I was just wondering how hard would it be to implement something approximating

Re: Question about implementing immutability

2018-11-22 Thread Thomas Jollans
On 2018-11-21 21:36, Calvin Spealman wrote: > If you want to create your own immutable class, maybe inherit from a > namedtuple? If you're tempted to go down that route and can require Python 3.7, use dataclasses! > > On Wed, Nov 21, 2018 at 11:45 AM Iwo Herka wrote: > >> Hello, >> >> Let's

Re: Question about implementing immutability

2018-11-22 Thread Iwo Herka
Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: > If an instance of your class contains a list, and you change one > of the elements of that list, then the instance's __setattr__ > never comes into play: I think that's within the bounds of what is understood as "immutable" in Python.

Re: Question about implementing immutability

2018-11-21 Thread dieter
Iwo Herka writes: > Let's say I want to implement immutability for user-defined class. > More precisely, a class that can be modified only in its (or its > super-class') __init__ method. My initial idea was to do it the > following fashion: > > def __setattr__(self, *args, **kwargs): >

Re: question on the 'calendar' function

2018-11-21 Thread Calvin Spealman
Sorry, but, that is largely what programming is. On Wed, Nov 21, 2018 at 4:09 PM o1bigtenor wrote: > On Wed, Nov 21, 2018 at 2:47 PM Calvin Spealman > wrote: > > > > Python and the standard library are all tools, but you still need to use > those tools to accomplish something. > > > > This is

Re: question on the 'calendar' function

2018-11-21 Thread o1bigtenor
On Wed, Nov 21, 2018 at 2:47 PM Calvin Spealman wrote: > > Python and the standard library are all tools, but you still need to use > those tools to accomplish something. > This is am understanding. What I'm doing is making tools to make tools to make tools to make tools to make decisions and

Re: question on the 'calendar' function

2018-11-21 Thread Calvin Spealman
Python and the standard library are all tools, but you still need to *use* those tools to accomplish something. On Wed, Nov 21, 2018 at 12:01 PM o1bigtenor wrote: > On Wed, Nov 21, 2018 at 8:09 AM Calvin Spealman > wrote: > > > > You really have the pieces you need here. You can print a whole

Re: Question about implementing immutability

2018-11-21 Thread Calvin Spealman
If you want to create your own immutable class, maybe inherit from a namedtuple? On Wed, Nov 21, 2018 at 11:45 AM Iwo Herka wrote: > Hello, > > Let's say I want to implement immutability for user-defined class. > More precisely, a class that can be modified only in its (or its > super-class')

Re: Question about implementing immutability

2018-11-21 Thread Dan Sommers
On 11/21/18 11:45 AM, Iwo Herka wrote: Hello, Let's say I want to implement immutability for user-defined class. More precisely, a class that can be modified only in its (or its super-class') __init__ method. My initial idea was to do it the following fashion: def __setattr__(self, *args,

Re: question on the 'calendar' function

2018-11-21 Thread mm0fmf
On 21/11/2018 12:27, o1bigtenor wrote: [Stuff clipped] What I need is to be able to have more than one calendar year options and this function seems to be limited to work with a maximum of only one year at a time. If I not reading the documentation correctly - - - please advise. (Thanking

Re: question on the 'calendar' function

2018-11-21 Thread o1bigtenor
On Wed, Nov 21, 2018 at 8:09 AM Calvin Spealman wrote: > > You really have the pieces you need here. You can print a whole year's > calendar with calendar.formatyear() or a single month with > calendar.monthcalendar(). If you need multiple years, call the first more > than once with each year

Re: question on the 'calendar' function

2018-11-21 Thread Calvin Spealman
You really have the pieces you need here. You can print a whole year's calendar with calendar.formatyear() or a single month with calendar.monthcalendar(). If you need multiple years, call the first more than once with each year you need to print. If you need partial years, print the individual

Re: question on the 'calendar' function

2018-11-21 Thread o1bigtenor
On Wed, Nov 21, 2018 at 2:37 AM wrote: > > On Tuesday, November 20, 2018 at 7:53:06 PM UTC+1, o1bigtenor wrote: > > On Tue, Nov 20, 2018 at 11:50 AM Schachner, Joseph > > wrote: > > > > > > It's possible I don't understand the question. The calendar functions > > > are NOT limited to this year

Re: question on the 'calendar' function

2018-11-21 Thread marco . nawijn
On Tuesday, November 20, 2018 at 7:53:06 PM UTC+1, o1bigtenor wrote: > On Tue, Nov 20, 2018 at 11:50 AM Schachner, Joseph > wrote: > > > > It's possible I don't understand the question. The calendar functions are > > NOT limited to this year or any limited range. > > > > Example: > > import

Re: question on the 'calendar' function

2018-11-20 Thread Ben Finney
o1bigtenor writes: > On Tue, Nov 20, 2018 at 12:09 PM Ben Finney > wrote: > > o1bigtenor writes: > > > It could be useful to see the longer time spans as weeks rather > > > than as days but seeing the larger time frames only as months > > > would enable the planning that I need to do. > > > >

Re: question on the 'calendar' function

2018-11-20 Thread o1bigtenor
On Tue, Nov 20, 2018 at 12:09 PM Ben Finney wrote: > > o1bigtenor writes: > > > I am in the process of learning my first computer programming language > > (unless g-code counts and then it is my second - - - grin). It > > definitely is a big world out there. > > Welcome, and congratulations on

Re: question on the 'calendar' function

2018-11-20 Thread o1bigtenor
On Tue, Nov 20, 2018 at 11:50 AM Schachner, Joseph wrote: > > It's possible I don't understand the question. The calendar functions are > NOT limited to this year or any limited range. > > Example: > import calendar > print( calendar.monthcalendar(2022, 12) ) > > Prints lists of dates in each

Re: question on the 'calendar' function

2018-11-20 Thread Ben Finney
o1bigtenor writes: > I am in the process of learning my first computer programming language > (unless g-code counts and then it is my second - - - grin). It > definitely is a big world out there. Welcome, and congratulations on starting with Python! > The calendar function has a lot of

RE: question on the 'calendar' function

2018-11-20 Thread Schachner, Joseph
It's possible I don't understand the question. The calendar functions are NOT limited to this year or any limited range. Example: import calendar print( calendar.monthcalendar(2022, 12) ) Prints lists of dates in each week of December 2022. It prints: [[0, 0, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9,

Re: Question about the definition of the value of an object

2018-11-19 Thread Iwo Herka
> Attempting to define value here would be at best a massive > distraction from the concepts the documentation is trying > to get across. > There is one very simple definition of "value" which is entirely > accurate, but probably not helpful, and that is: An object's > value is whatever it is

Re: Question about the definition of the value of an object

2018-11-19 Thread Chris Angelico
On Tue, Nov 20, 2018 at 3:08 AM Iwo Herka wrote: > > Hello everyone, > > I've been looking for something in the documentation > (https://docs.python.org/3.8/reference/datamodel.html) recently > and I've noticed something weird. Documentation states that every > object has a value, but doesn’t

Re: Question about the definition of the value of an object

2018-11-19 Thread Terry Reedy
On 11/19/2018 9:08 AM, Iwo Herka wrote: Hello everyone, I've been looking for something in the documentation (https://docs.python.org/3.8/reference/datamodel.html) recently and I've noticed something weird. Documentation states that every object has a value, but doesn’t provide any definition

Re: Question about the definition of the value of an object

2018-11-19 Thread Rhodri James
On 19/11/2018 14:08, Iwo Herka wrote: I've been looking for something in the documentation (https://docs.python.org/3.8/reference/datamodel.html) recently and I've noticed something weird. Documentation states that every object has a value, but doesn’t provide any definition whatsoever of what

Re: Question about Multi-processing

2018-10-02 Thread Chris Angelico
On Wed, Oct 3, 2018 at 2:13 AM Anthony Flury via Python-list wrote: > I continued to read the documentation and came to this quote : > > /Functionality within this package requires that the > //|__main__|//module be importable by the children. This is covered > in //Programming

Re: Question about floating point

2018-09-01 Thread Paul Moore
On Sat, 1 Sep 2018 at 12:31, Frank Millman wrote: > > "Frank Millman" wrote in message news:pm3l2m$kv4$1...@blaine.gmane.org... > > > > I know about this gotcha - > > > > >>> x = 1.1 + 2.2 > > >>> x > > 3.3003 > > > [...] > > I have enjoyed the discussion, and I have learnt a lot

Re: Question about floating point

2018-09-01 Thread Steven D'Aprano
On Sat, 01 Sep 2018 13:27:59 +0200, Frank Millman wrote: from decimal import Decimal as D f"{D('1.1')+D('2.2'):.60f}" > '3.3000' '{:.60f}'.format(D('1.1') + D('2.2')) >

Re: Question about floating point

2018-09-01 Thread Frank Millman
"Frank Millman" wrote in message news:... "Frank Millman" wrote in message news:pm3l2m$kv4$1...@blaine.gmane.org... I know about this gotcha - >>> x = 1.1 + 2.2 >>> x 3.3003 [...] I have enjoyed the discussion, and I have learnt a lot about floating point. Thanks to all. I

Re: Question about floating point

2018-08-31 Thread Steven D'Aprano
On Fri, 31 Aug 2018 18:45:16 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> The right way is to >> set the rounding mode at the start of your application, and then let >> the Decimal type round each calculation that needs rounding. > > It's not clear what you mean by "rounding mode"

Re: Question about floating point

2018-08-31 Thread Gregory Ewing
Steven D'Aprano wrote: The right way is to set the rounding mode at the start of your application, and then let the Decimal type round each calculation that needs rounding. It's not clear what you mean by "rounding mode" here. If you mean whether it's up/down/even/whatever, then yes, you can

Re: Question about floating point

2018-08-30 Thread Steven D'Aprano
On Thu, 30 Aug 2018 19:22:29 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> Why in the name of all that's holy would anyone want to manually round >> each and every intermediate calculation when they could use the Decimal >> module and have it do it automatically? > > I agree that

Re: Question about floating point

2018-08-30 Thread Gregory Ewing
Steven D'Aprano wrote: Why in the name of all that's holy would anyone want to manually round each and every intermediate calculation when they could use the Decimal module and have it do it automatically? I agree that Decimal is the safest and probably easiest way to go, but saying that it

Re: Question about floating point

2018-08-29 Thread Steven D'Aprano
On Wed, 29 Aug 2018 11:31:29 +1200, Gregory Ewing wrote: > Frank Millman wrote: >> I have been trying to explain why >> they should use the decimal module. They have had a counter-argument >> from someone else who says they should just use the rounding technique >> in my third example above. > >

Re: Question about floating point

2018-08-29 Thread Steven D'Aprano
On Tue, 28 Aug 2018 16:47:25 +0200, Frank Millman wrote: > The reason for my query is this. I am assisting someone with an > application involving monetary values. I have been trying to explain why > they should use the decimal module. They have had a counter-argument > from someone else who says

Re: Question about floating point

2018-08-29 Thread Oscar Benjamin
On Tue, 28 Aug 2018 at 15:50, Frank Millman wrote: > > "Frank Millman" wrote in message news:pm3l2m$kv4$1...@blaine.gmane.org... > > > > I know about this gotcha - > > > > >>> x = 1.1 + 2.2 > > >>> x > > 3.3003 > > > [...] > > > > >>> y = 3.3 > > >>> y > > 3.3 > > > [...] > > > > >>>

Re: Question about floating point

2018-08-28 Thread Gregory Ewing
Frank Millman wrote: I have been trying to explain why they should use the decimal module. They have had a counter-argument from someone else who says they should just use the rounding technique in my third example above. It's possible to get away with this by judicious use of rounding.

Re: Question about floating point

2018-08-28 Thread Rob Gaddi
On 08/28/2018 07:11 AM, Frank Millman wrote: Hi all I know about this gotcha - x = 1.1 + 2.2 x 3.3003 According to the docs, the reason is that "numbers like 1.1 and 2.2 do not have exact representations in binary floating point." So when I do this - y = 3.3 y 3.3 what

Re: Question about floating point

2018-08-28 Thread MRAB
On 2018-08-28 15:11, Frank Millman wrote: Hi all I know about this gotcha - x = 1.1 + 2.2 x 3.3003 According to the docs, the reason is that "numbers like 1.1 and 2.2 do not have exact representations in binary floating point." So when I do this - y = 3.3 y 3.3 what exactly

Re: Question about floating point

2018-08-28 Thread Chris Angelico
On Wed, Aug 29, 2018 at 12:47 AM, Frank Millman wrote: > They were interesting, but actually did not answer the question that I > forgot to ask! > > The reason for my query is this. I am assisting someone with an application > involving monetary values. I have been trying to explain why they

Re: Question about floating point

2018-08-28 Thread Frank Millman
"Frank Millman" wrote in message news:pm3l2m$kv4$1...@blaine.gmane.org... I know about this gotcha - >>> x = 1.1 + 2.2 >>> x 3.3003 [...] >>> y = 3.3 >>> y 3.3 [...] >>> z = (1.1 + 2.2) * 10 / 10 >>> z 3.3 Thanks to Chris and Stephen for the replies. They were

Re: Question about floating point

2018-08-28 Thread Grant Edwards
On 2018-08-28, Frank Millman wrote: x = 1.1 + 2.2 x > 3.3003 > > According to the docs, the reason is that "numbers like 1.1 and 2.2 do not > have exact representations in binary floating point." Right. > So when I do this - > y = 3.3 y > 3.3 > > what exactly

Re: Question about floating point

2018-08-28 Thread Stephen Tucker
Hi Frank, One difference is that, in order to carry out the instructions embodied in the first example, the computer has to perform arithmetic. And it adds the binary approximation of 1.1 (which is very slightly wrong) to the binary approximation of 2.2 (which, again, is very slightly wrong). It

Re: Question about floating point

2018-08-28 Thread Chris Angelico
On Wed, Aug 29, 2018 at 12:11 AM, Frank Millman wrote: > Hi all > > I know about this gotcha - > x = 1.1 + 2.2 x > > 3.3003 > > According to the docs, the reason is that "numbers like 1.1 and 2.2 do not > have exact representations in binary floating point." > > So when I do

Re: Question : Input after all prompts in python

2018-06-12 Thread mohan4h
On Tuesday, June 12, 2018 at 7:37:25 PM UTC+8, Bart wrote: > On 11/06/2018 12:16, Steven D'Aprano wrote: > > On Mon, 11 Jun 2018 01:44:19 -0700, mohan4h wrote: > > > >> Everyone, > >> > >> I am very new to python. I am trying to achieve the below in it, but i > >> am unable to find suitable

Re: Question : Input after all prompts in python

2018-06-12 Thread Bart
On 11/06/2018 12:16, Steven D'Aprano wrote: On Mon, 11 Jun 2018 01:44:19 -0700, mohan4h wrote: Everyone, I am very new to python. I am trying to achieve the below in it, but i am unable to find suitable documentation to guide me on the same. I want to prompt 3 questions together and then get

Re: Question : Input after all prompts in python

2018-06-11 Thread Steven D'Aprano
On Mon, 11 Jun 2018 07:19:15 -0700, mohan4h wrote: > print(u"\u001b[{}A".format(n), flush=True, end="") > ^ > SyntaxError :invalid syntax My crystal ball tell me you are using Python 2. Is that right? -- Steven D'Aprano "Ever since I

Re: Question : Input after all prompts in python

2018-06-11 Thread Wolfgang Maier
On 06/11/2018 04:19 PM, moha...@gmail.com wrote: BTW i tried the code above, but i encountered a syntax error. print(u"\u001b[{}A".format(n), flush=True, end="") ^ SyntaxError :invalid syntax That's probably because you have been running

Re: Question : Input after all prompts in python

2018-06-11 Thread mohan4h
On Monday, June 11, 2018 at 9:13:04 PM UTC+8, Karsten Hilbert wrote: > On Mon, Jun 11, 2018 at 02:52:53PM +0200, Peter Otten wrote: > > > If the above hack works in the OP's environment it's certainly as easy as > > it > > can get; he just has to copy the up() and right() functions, and maybe

Re: Question : Input after all prompts in python

2018-06-11 Thread Karsten Hilbert
On Mon, Jun 11, 2018 at 02:52:53PM +0200, Peter Otten wrote: > If the above hack works in the OP's environment it's certainly as easy as it > can get; he just has to copy the up() and right() functions, and maybe adapt > the arguments. > > The learning curve for tkinter or curses is steep by

Re: Question : Input after all prompts in python

2018-06-11 Thread Peter Otten
Karsten Hilbert wrote: > On Mon, Jun 11, 2018 at 02:14:26PM +0200, Peter Otten wrote: > >> >> print("1. Enter your name :") >> >> print("2. Enter your age :") >> >> print("3. Enter your gender :") >> >> name = input("") >> >> age = input("") >> >> gender = input("") >> > >> > That doesn't solve

Re: Question : Input after all prompts in python

2018-06-11 Thread Karsten Hilbert
On Mon, Jun 11, 2018 at 02:14:26PM +0200, Peter Otten wrote: > >> print("1. Enter your name :") > >> print("2. Enter your age :") > >> print("3. Enter your gender :") > >> name = input("") > >> age = input("") > >> gender = input("") > > > > That doesn't solve the "next to" part in > > > > get

Re: Question : Input after all prompts in python

2018-06-11 Thread Peter Otten
Karsten Hilbert wrote: > On Mon, Jun 11, 2018 at 11:16:39AM +, Steven D'Aprano wrote: > >> > I want to prompt 3 questions together and then get input for the first >> > question next to question as below. >> > >> > 1. Enter your name : _ >> > 2. Enter your age : >> > 3. Enter your gender :

Re: Question : Input after all prompts in python

2018-06-11 Thread Karsten Hilbert
On Mon, Jun 11, 2018 at 11:16:39AM +, Steven D'Aprano wrote: > > I want to prompt 3 questions together and then get input for the first > > question next to question as below. > > > > 1. Enter your name : _ > > 2. Enter your age : > > 3. Enter your gender : > > > > After showing the below

Re: Question : Input after all prompts in python

2018-06-11 Thread Steven D'Aprano
On Mon, 11 Jun 2018 01:44:19 -0700, mohan4h wrote: > Everyone, > > I am very new to python. I am trying to achieve the below in it, but i > am unable to find suitable documentation to guide me on the same. > > I want to prompt 3 questions together and then get input for the first > question

Re: Question : Input after all prompts in python

2018-06-11 Thread Karsten Hilbert
On Mon, Jun 11, 2018 at 01:44:19AM -0700, moha...@gmail.com wrote: > I am very new to python. I am trying to achieve the below in it, but i am > unable to find suitable documentation to guide me on the same. > > I want to prompt 3 questions together and then get input for the first > question

Re: Question about Decimal and rounding

2018-04-27 Thread Frank Millman
"Thomas Jollans" wrote in message news:19223891-2006-d496-bdfe-32776834e...@tjol.eu... On 27/04/18 10:21, Frank Millman wrote: > I have an object which represents a Decimal type. > > It can receive input from various sources. It has to round the value to > a particular scale factor before

Re: Question about Decimal and rounding

2018-04-27 Thread Thomas Jollans
On 27/04/18 10:21, Frank Millman wrote: > Hi all > > I have an object which represents a Decimal type. > > It can receive input from various sources. It has to round the value to > a particular scale factor before storing it. The scale factor can vary, > so it has to be looked up every time,

Re: Question regarding objects in __call__() methods

2018-03-26 Thread Arshpreet Singh
On Monday, 26 March 2018 11:32:51 UTC+5:30, dieter wrote: > Fürther inspection utilities: "dir", "vars" and the "inspect" module. > Read the documentation to find out what they do. Thanks, Dieter, That is really helpful! -- https://mail.python.org/mailman/listinfo/python-list

Re: Question regarding objects in __call__() methods

2018-03-26 Thread dieter
Arshpreet Singh writes: > ... > As debugging the code I got at line 10. I am sending a request to particular > API and returning a request_object . further deep down it generates the > "response_object" as from my requirements that should be JSON object but I am > only

Re: Question about modules documentation

2017-09-15 Thread Tobiah
>> 'next sentence' is the operative piece. I think that if the bit >> about placement was moved to the end of the paragraph the whole >> thing would be more readable and I wouldn't have stumbled on it. > > If it had meant "the imported module's names" or indeed "the imported > modules' names",

Re: Question about modules documentation

2017-09-15 Thread Rhodri James
On 15/09/17 18:05, Tobiah wrote: On 09/15/2017 09:25 AM, Stefan Ram wrote:> Tobiah writes: Modules can import other modules. It is customary but not required to place all import statements at the beginning of a module (or script, for that matter). The

Re: Question about modules documentation

2017-09-15 Thread Tobiah
On 09/15/2017 09:25 AM, Stefan Ram wrote:> Tobiah writes: >> Modules can import other modules. It is customary but not >> required to place all import statements at the beginning >> of a module (or script, for that matter). The imported >> module names are

Re: Question about modules documentation

2017-09-15 Thread Tobiah
Re-reading I guess the plural refers to the multiple modules referenced in the first sentence. It was probably written that way before someone inserted the bit about the customary placement, which greatly clouds the connection. On 09/15/2017 09:03 AM, Tobiah wrote: > In this doc: > >

Re: Question about modules documentation

2017-09-15 Thread Chris Angelico
On Sat, Sep 16, 2017 at 2:03 AM, Tobiah wrote: > It seems that if the statement read: > > the imported module's name (singular) is placed in the > importing module's global symbol table. > > That it would be more accurate. That implies that you only import one

Re: Question About When Objects Are Destroyed (continued)

2017-08-07 Thread Grant Edwards
On 2017-08-05, Tim Daneliuk wrote: > On 08/05/2017 03:21 PM, Chris Angelico wrote: >> so the object's lifetime shouldn't matter to you. > > I disagree with this most strongly. That's only true when the > machine resources being consumed by your Python object are small in >

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 05:36 PM, Ned Batchelder wrote: > On 8/5/17 5:41 PM, Tim Daneliuk wrote: >> On 08/05/2017 11:16 AM, Ned Batchelder wrote: >>> It uses >>> reference counting, so most objects are reclaimed immediately when their >>> reference count goes to zero, such as at the end of local scopes. >>

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 05:36 PM, Ned Batchelder wrote: > On 8/5/17 5:41 PM, Tim Daneliuk wrote: >> On 08/05/2017 11:16 AM, Ned Batchelder wrote: >>> It uses >>> reference counting, so most objects are reclaimed immediately when their >>> reference count goes to zero, such as at the end of local scopes. >>

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 05:58 PM, Chris Angelico wrote: > On Sun, Aug 6, 2017 at 7:32 AM, Tim Daneliuk wrote: >> On 08/05/2017 03:21 PM, Chris Angelico wrote: >>> After a 'with' block, >>> the object *still exists*, but it has been "exited" in some way >>> (usually by closing/releasing

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 05:58 PM, Chris Angelico wrote: > On Sun, Aug 6, 2017 at 7:32 AM, Tim Daneliuk wrote: >> On 08/05/2017 03:21 PM, Chris Angelico wrote: >>> After a 'with' block, >>> the object *still exists*, but it has been "exited" in some way >>> (usually by closing/releasing

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Chris Angelico
On Sun, Aug 6, 2017 at 7:32 AM, Tim Daneliuk wrote: > On 08/05/2017 03:21 PM, Chris Angelico wrote: >> After a 'with' block, >> the object *still exists*, but it has been "exited" in some way >> (usually by closing/releasing an underlying resource). > > The containing object

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Ned Batchelder
On 8/5/17 5:41 PM, Tim Daneliuk wrote: > On 08/05/2017 11:16 AM, Ned Batchelder wrote: >> It uses >> reference counting, so most objects are reclaimed immediately when their >> reference count goes to zero, such as at the end of local scopes. > Given this code: > > class SomeObject: > . >

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread MRAB
On 2017-08-05 22:41, Tim Daneliuk wrote: On 08/05/2017 11:16 AM, Ned Batchelder wrote: It uses reference counting, so most objects are reclaimed immediately when their reference count goes to zero, such as at the end of local scopes. Given this code: class SomeObject: . for foo

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Marko Rauhamaa
Tim Daneliuk : > Are you saying that each time a,b,c are reassigned to new instances of > SomeObject the old instance counts go to 0 and are immediately - as in > synchronously, right now, on the spot - removed from memory? That depends on the implementation of Python.

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 11:16 AM, Ned Batchelder wrote: > It uses > reference counting, so most objects are reclaimed immediately when their > reference count goes to zero, such as at the end of local scopes. Given this code: class SomeObject: . for foo in somelist: a = SomeObject(foo) b

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 03:21 PM, Chris Angelico wrote: > After a 'with' block, > the object *still exists*, but it has been "exited" in some way > (usually by closing/releasing an underlying resource). The containing object exists, but the things that the closing logic explicitly released do not. In some

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Chris Angelico
On Sun, Aug 6, 2017 at 1:23 AM, Tim Daneliuk wrote: > On 08/04/2017 07:00 PM, Chris Angelico wrote: >> Again, don't stress about exactly when objects get >> disposed of; it doesn't matter. > > > Respectfully, I disagree strongly. Objects get build on the heap and > persist

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Ned Batchelder
On 8/5/17 11:23 AM, Tim Daneliuk wrote: > On 08/04/2017 07:00 PM, Chris Angelico wrote: >> Again, don't stress about exactly when objects get >> disposed of; it doesn't matter. > > Respectfully, I disagree strongly. Objects get build on the heap and > persist even when they go out of scope until

Re: Question About When Objects Are Destroyed

2017-08-05 Thread Ned Batchelder
On 8/4/17 7:42 PM, Jon Forrest wrote: > On 8/4/2017 4:34 PM, gst wrote: >> 'two' is a so called constant or literal value .. (of that >> function). >> >> Why not attach it, as a const value/object, to the function itself ? >> So that a new string object has not to be created each time the >>

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Marko Rauhamaa
Tim Daneliuk : > On 08/04/2017 07:00 PM, Chris Angelico wrote: >> Again, don't stress about exactly when objects get disposed of; it >> doesn't matter. > > Respectfully, I disagree strongly. Objects get build on the heap and > persist even when they go out of scope until such

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/04/2017 07:00 PM, Chris Angelico wrote: > Again, don't stress about exactly when objects get > disposed of; it doesn't matter. Respectfully, I disagree strongly. Objects get build on the heap and persist even when they go out of scope until such time garbage collection takes place. This

Re: Question About When Objects Are Destroyed

2017-08-04 Thread Terry Reedy
On 8/4/2017 7:11 PM, Jon Forrest wrote: Consider the following Python shell session (Python 3.6.2, Win64): >>> def givemetwo(): ... x = 'two' ... print(id(x)) ... >>> givemetwo() 1578505988392 So far fine. My understanding of object existence made me think that the object

Re: Question About When Objects Are Destroyed

2017-08-04 Thread Steve D'Aprano
On Sat, 5 Aug 2017 09:11 am, Jon Forrest wrote: > Consider the following Python shell session (Python 3.6.2, Win64): > > >>> def givemetwo(): > ... x = 'two' > ... print(id(x)) > ... > >>> givemetwo() > 1578505988392 > > So far fine. My understanding of object existence made

Re: Question About When Objects Are Destroyed (continued)

2017-08-04 Thread Chris Angelico
On Sat, Aug 5, 2017 at 9:47 AM, Jon Forrest wrote: > Perhaps the reason the variable isn't destroyed is > shown by the following (again, in the same session): > import sys sys.getrefcount(1578505988392) > 3 > > So, maybe it's not destroyed because there are still >

Re: Question About When Objects Are Destroyed

2017-08-04 Thread Chris Angelico
On Sat, Aug 5, 2017 at 9:42 AM, Jon Forrest wrote: > On 8/4/2017 4:34 PM, gst wrote: >> >> 'two' is a so called constant or literal value .. (of that >> function). >> >> Why not attach it, as a const value/object, to the function itself ? >> So that a new string object has not

Re: Question About When Objects Are Destroyed

2017-08-04 Thread Jon Forrest
On 8/4/2017 4:34 PM, gst wrote: 'two' is a so called constant or literal value .. (of that function). Why not attach it, as a const value/object, to the function itself ? So that a new string object has not to be created each time the function is called. Because anyway strings are immutable. So

Re: Question

2017-07-31 Thread oliver
On Mon, Jul 31, 2017, 17:33 Sonja Williams via Python-list, < python-list@python.org> wrote: > > > > > Good Day, > > I have decided to learn more about programming so I picked up the book > Beginning Programming by Matt Telles. After following the directions > verbatim and going to the Python

Re: Question

2017-07-31 Thread Chris Angelico
On Tue, Aug 1, 2017 at 7:11 AM, Sonja Williams via Python-list wrote: > > > > > Good Day, > > I have decided to learn more about programming so I picked up the book > Beginning Programming by Matt Telles. After following the directions > verbatim and going to the Python

Re: Question about propagating universal_newlines through subprocess.Popen to io.TextIOWrapper

2017-06-26 Thread Bill Deegan
On Mon, Jun 26, 2017 at 2:22 PM, eryk sun wrote: > On Mon, Jun 26, 2017 at 8:59 PM, Bill Deegan > wrote: > > > > Ideally (for my use case) it would be something which propagated > > universal_newlines to io.TextIOWrapper().. rather than discards it.

Re: Question about propagating universal_newlines through subprocess.Popen to io.TextIOWrapper

2017-06-26 Thread eryk sun
On Mon, Jun 26, 2017 at 8:59 PM, Bill Deegan wrote: > > Ideally (for my use case) it would be something which propagated > universal_newlines to io.TextIOWrapper().. rather than discards it. > In my case I want the stdout to be encoded utf-8, but I do not want \r's >

Re: Question about propagating universal_newlines through subprocess.Popen to io.TextIOWrapper

2017-06-26 Thread Bill Deegan
On Mon, Jun 26, 2017 at 12:44 PM, eryk sun wrote: > On Mon, Jun 26, 2017 at 5:23 PM, Bill Deegan > wrote: > > > > That universal_newlines value is discarded due to: > > > > text_mode = encoding or errors or universal_newlines > > > > ... > > > > if

Re: Question about propagating universal_newlines through subprocess.Popen to io.TextIOWrapper

2017-06-26 Thread eryk sun
On Mon, Jun 26, 2017 at 5:23 PM, Bill Deegan wrote: > > That universal_newlines value is discarded due to: > > text_mode = encoding or errors or universal_newlines > > ... > > if text_mode: > self.stdout = io.TextIOWrapper(self.stdout, >

Re: Question about abstract base classes and abstract properties -- Python 2.7

2017-01-10 Thread Steven D'Aprano
On Wednesday 11 January 2017 12:26, Gerald Britton wrote: > I was rereading the 2.7 docs about abstract base classes the other day. I > found this line in the usage section of the abc.abstractproperty function: > > "This defines a read-only property; you can also define a read-write > abstract

Re: Question about abstract base classes and abstract properties -- Python 2.7

2017-01-10 Thread Gerald Britton
I was rereading the 2.7 docs about abstract base classes the other day. I found this line in the usage section of the abc.abstractproperty function: "This defines a read-only property; you can also define a read-write abstract property using the ‘long’ form of property declaration:" along with

<    1   2   3   4   5   6   7   8   9   10   >