Re: A Single Instance of an Object?

2024-03-11 Thread Peter J. Holzer via Python-list
elf.cache[key] = value > return value > > Now it is easier to unit test, and the cache is not global. However, I > cannot instantiate Lookup inside the while- or for- loops in main(), > because the cache should be only one. I need to ensure there is only > one instance of

Re: A Single Instance of an Object?

2024-03-11 Thread Chris Angelico via Python-list
On Tue, 12 Mar 2024 at 08:04, Ivan "Rambius" Ivanov wrote: > > A Singleton is just a global variable. Why do this? Did someone tell > > you "global variables are bad, don't use them"? > > I have bad experience with global variables because it is hard to > track what and when modifies them. I don't

Re: A Single Instance of an Object?

2024-03-11 Thread Ivan "Rambius" Ivanov via Python-list
(key) method > > clumsy, because I have to clean it after each unit test. I refactored > > it as: > > > > class Lookup: > > def __init__(self): > > self.cache = {} > > > > Change "cache" to be a class-attribute (it is currentl

Re: A Single Instance of an Object?

2024-03-11 Thread Ivan "Rambius" Ivanov via Python-list
On Mon, Mar 11, 2024 at 5:01 PM Chris Angelico via Python-list wrote: > > On Tue, 12 Mar 2024 at 07:54, Ivan "Rambius" Ivanov via Python-list > wrote: > > I am refactoring some code and I would like to get rid of a global > > variable. Here is the outline: > > > > ... > > > > I have never done th

Re: A Single Instance of an Object?

2024-03-11 Thread dn via Python-list
be a class-attribute (it is currently an instance. Then, code AFTER the definition of Lookup can refer to Lookup.cache, regardless of instantiation, and code within Lookup can refer to self.cache as-is... -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list

Re: A Single Instance of an Object?

2024-03-11 Thread Chris Angelico via Python-list
On Tue, 12 Mar 2024 at 07:54, Ivan "Rambius" Ivanov via Python-list wrote: > I am refactoring some code and I would like to get rid of a global > variable. Here is the outline: > > ... > > I have never done that in Python because I deliberately avoided such > complicated situations up to now. I kn

A Single Instance of an Object?

2024-03-11 Thread Ivan "Rambius" Ivanov via Python-list
logger.error("cmd returned error") self.cache[key] = value return value Now it is easier to unit test, and the cache is not global. However, I cannot instantiate Lookup inside the while- or for- loops in main(), because the cache should be only one. I need to ensure there

how to connect linux aws ec2 instance to windows local machine at my home using paramiko

2023-11-27 Thread Kashish Naqvi via Python-list
I have a north viriginia ec2 linux instance and a windows machine at my home, how do I connec tthem? import paramiko import time def run_scripts(): # Set your local machine's SSH details local_machine_ip = ' ' username = 'justk' private_key_path = &#x

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dom Grigonis via Python-list
Thank you. > On 16 Nov 2023, at 21:30, Dieter Maurer wrote: > > Dom Grigonis wrote at 2023-11-16 21:11 +0200: >> ... >>> On 16 Nov 2023, at 21:00, Dieter Maurer wrote: >>> ... >>> Methods are not bound during instance creation, they are bound during &g

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dieter Maurer via Python-list
Dom Grigonis wrote at 2023-11-16 21:11 +0200: > ... >> On 16 Nov 2023, at 21:00, Dieter Maurer wrote: >> ... >> Methods are not bound during instance creation, they are bound during >> access. > >Good to know. What is the criteria for binding then? Does i

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dom Grigonis via Python-list
eal as there would be too much >> overhead. >> >> I think what I am looking for is custom method binding. > > Methods are not bound during instance creation, they are bound during > access. Good to know. What is the criteria for binding then? Does it check if its

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dieter Maurer via Python-list
r is custom method binding. Methods are not bound during instance creation, they are bound during access. You can use descriptors to implement "custom method binding". Descriptors are defined on the class (and do not behave as descriptors when defined on instances). Thus, y

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dieter Maurer via Python-list
class method. > >I was wandering if there is an equivalent functionality of attribute to >receive `instance` argument on instance creation. As PEP 487 describes, `__set_name__` essentially targets descriptors. It is there to inform a descriptor about the name it is used for in a class (and

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dom Grigonis via Python-list
` argument. >> >> Thus, allowing simulation of bound class method. >> >> I was wandering if there is an equivalent functionality of attribute to >> receive `instance` argument on instance creation. > > As PEP 487 describes, `__set_name__` essentially targets descriptor

__set_name__ equivalent for instance

2023-11-15 Thread Dom Grigonis via Python-list
of attribute to receive `instance` argument on instance creation. Regards, DG -- https://mail.python.org/mailman/listinfo/python-list

Re: How to replace an instance method?

2022-09-21 Thread Diego Souza
mple and Stupid (KISS) -- Diego Souza Wespa Intelligent Systems Rio de Janeiro - Brasil On Mon, Sep 19, 2022 at 1:00 PM wrote: > > > From: "Weatherby,Gerard" > Date: Mon, 19 Sep 2022 13:06:42 + > Subject: Re: How to replace an instance method? > Just subclass and over

Re: How to replace an instance method?

2022-09-19 Thread Eryk Sun
On 9/19/22, 2qdxy4rzwzuui...@potatochowder.com <2qdxy4rzwzuui...@potatochowder.com> wrote: > On 2022-09-18 at 09:11:28 +, > Stefan Ram wrote: > >> r...@zedat.fu-berlin.de (Stefan Ram) writes (abbreviated): >> >types.MethodType( function, instance ) >> &g

Re: How to replace an instance method?

2022-09-19 Thread 2QdxY4RzWzUUiLuE
On 2022-09-18 at 09:11:28 +, Stefan Ram wrote: > r...@zedat.fu-berlin.de (Stefan Ram) writes (abbreviated): > >types.MethodType( function, instance ) > >functools.partial( function, instance ) > >new_method.__get__( instance ) > > I wonder which of these th

Re: How to replace an instance method?

2022-09-19 Thread Eryk Sun
On 9/18/22, Stefan Ram wrote: > r...@zedat.fu-berlin.de (Stefan Ram) writes (abbreviated): >>types.MethodType( function, instance ) >>functools.partial( function, instance ) >>new_method.__get__( instance ) > > I wonder which of these three possibilities expresses >

Re: How to replace an instance method?

2022-09-19 Thread Weatherby,Gerard
m 17.09.2022 um 00:35 schrieb Dan Stromberg: On Fri, Sep 16, 2022 at 2:06 PM Ralf M. mailto:ral...@t-online.de>> wrote: I would like to replace a method of an instance, but don't know how to do it properly. You appear to have a good answer, but... are you sure this is a good idea? It&#

Re: How to replace an instance method?

2022-09-18 Thread Lars Liedtke
ivacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 16.09.22 um 22:55 schrieb Ralf M.: I would like to replace a method of an instance, but don't know how to do it properly. My first naive idea was inst = SomeClass() def new_method(self, param):

Re: How to replace an instance method?

2022-09-17 Thread Eryk Sun
x27;s accessed as a method of an instance of the class. In the class, that's just a function object; it's exactly a function, not merely fundamentally the same thing as one. It's only when accessed as an attribute of an instance of the type that the function's descriptor __get_

Re: How to replace an instance method?

2022-09-17 Thread Chris Angelico
On Sun, 18 Sept 2022 at 10:29, wrote: > > > From your description, Chris, it sounds like the functional programming > technique often called currying. A factory function is created where one (or > more) parameters are sort of frozen in so the user never sees or cares about > them, and a modified o

RE: How to replace an instance method?

2022-09-17 Thread avi.e.gross
ase, the function now knows what object it is attached to as this. -Original Message- From: Python-list On Behalf Of Chris Angelico Sent: Saturday, September 17, 2022 8:21 PM To: python-list@python.org Subject: Re: How to replace an instance method? On Sun, 18 Sept 2022 at 09:37, Eryk

Re: How to replace an instance method?

2022-09-17 Thread Chris Angelico
ptor. Thus if a method object is set > as an attribute of a type, the method does not rebind as a new method > when accessed as an attribute of an instance of the type. An unbound method in Python 2 was distinctly different from a function, but in Python 3, they really truly are the same thing.

Re: How to replace an instance method?

2022-09-17 Thread Eryk Sun
underlying function (i.e. the method's __func__), such as inspecting the __name__ and __code__. A fundamental difference is that, unlike a function, a method is not a descriptor. Thus if a method object is set as an attribute of a type, the method does not rebind as a new method when

Re: How to replace an instance method?

2022-09-17 Thread Chris Angelico
On Sun, 18 Sept 2022 at 07:20, Ralf M. wrote: > > Am 16.09.2022 um 23:34 schrieb Eryk Sun: > > On 9/16/22, Ralf M. wrote: > >> I would like to replace a method of an instance, but don't know how to > >> do it properly. > > > > A function is a descr

Re: How to replace an instance method?

2022-09-17 Thread Ralf M.
Am 17.09.2022 um 00:35 schrieb Dan Stromberg: On Fri, Sep 16, 2022 at 2:06 PM Ralf M. <mailto:ral...@t-online.de>> wrote: I would like to replace a method of an instance, but don't know how to do it properly. You appear to have a good answer, but...  are you sure

Re: How to replace an instance method?

2022-09-17 Thread Ralf M.
Am 16.09.2022 um 23:34 schrieb Eryk Sun: On 9/16/22, Ralf M. wrote: I would like to replace a method of an instance, but don't know how to do it properly. A function is a descriptor that binds to any object as a method. For example: >>> f = lambda self, x: self + x

Re: How to replace an instance method?

2022-09-16 Thread Thomas Passin
Here is an example of probably the easiest way to add an instance method: class Demo: def sqr(self, x): return x*x # Function to turn into a instance method def cube(self, x): return x*x*x d = Demo() print(d.sqr(2)) d.cube = cube.__get__(d) print(d.cube(3)) As for when

Re: How to replace an instance method?

2022-09-16 Thread Dan Stromberg
On Fri, Sep 16, 2022 at 2:06 PM Ralf M. wrote: > I would like to replace a method of an instance, but don't know how to > do it properly. > You appear to have a good answer, but... are you sure this is a good idea? It'll probably be confusing to future maintainers of thi

Re: How to replace an instance method?

2022-09-16 Thread Eryk Sun
On 9/16/22, Ralf M. wrote: > I would like to replace a method of an instance, but don't know how to > do it properly. A function is a descriptor that binds to any object as a method. For example: >>> f = lambda self, x: self + x >>> o = 42 >&g

Re: How to replace an instance method?

2022-09-16 Thread Chris Angelico
On Sat, 17 Sept 2022 at 07:07, Ralf M. wrote: > > I would like to replace a method of an instance, but don't know how to > do it properly. > > My first naive idea was > > inst = SomeClass() > def new_method(self, param): > # do something > return

How to replace an instance method?

2022-09-16 Thread Ralf M.
I would like to replace a method of an instance, but don't know how to do it properly. My first naive idea was inst = SomeClass() def new_method(self, param): # do something return whatever inst.method = new_method however that doesn't work: self isn't passed as first p

Re: terminate called after throwing an instance of 'boost::python::error_already_set

2022-05-28 Thread Barry
> On 27 May 2022, at 21:17, Larry Martell wrote: > > I have a script that has literally been running for 10 years. > Suddenly, for some runs it crashes with the error: > > terminate called after throwing an instance of > 'boost::python::error_already_set This is

Re: terminate called after throwing an instance of 'boost::python::error_already_set

2022-05-27 Thread dn
; Suddenly, for some runs it crashes with the error: > > > > terminate called after throwing an instance of > 'boost::python::error_already_set > > > > No stack trace. Anyone have any thoughts on what could cause this > > and/or how

Re: terminate called after throwing an instance of 'boost::python::error_already_set

2022-05-27 Thread Larry Martell
On Fri, May 27, 2022 at 5:51 PM dn wrote: > On 28/05/2022 08.14, Larry Martell wrote: > > I have a script that has literally been running for 10 years. > > Suddenly, for some runs it crashes with the error: > > > > terminate called after throwing an i

Re: terminate called after throwing an instance of 'boost::python::error_already_set

2022-05-27 Thread dn
On 28/05/2022 08.14, Larry Martell wrote: > I have a script that has literally been running for 10 years. > Suddenly, for some runs it crashes with the error: > > terminate called after throwing an instance of > 'boost::python::error_already_set > > No stack trace. A

terminate called after throwing an instance of 'boost::python::error_already_set

2022-05-27 Thread Larry Martell
I have a script that has literally been running for 10 years. Suddenly, for some runs it crashes with the error: terminate called after throwing an instance of 'boost::python::error_already_set No stack trace. Anyone have any thoughts on what could cause this and/or how I can track it

Re: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-10 Thread Lars Liedtke
server {    listen [::]:80;    listen 80;    server_name api.familie-liedtke.net;    location / {    return 301 https://$host$request_uri;    }    include /usr/local/etc/nginx/include/letsencrypt.conf; } server {    listen 443 ssl http2;    listen [::]:443 ssl http2;    server_name api.f

Re: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-10 Thread Lars Liedtke
I think this is more a thing of apporach. Nginx is quite simple to install and a config doing nothing else than redirecting https to https and proxying requests to a service (whichever tat is, in your case gunicorn) can become a nobrainer. That is what it became for me. Additionally the config

RE: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-08 Thread Kirill Ratkin
req/res on Gunicorn instance) b) Scalability (proxy can spread traffic on several Gunicorn instances) c) Maintenance (you can gracefully shutdown/restart Gunicorn instances one by one) d) Security (For example SSL certificate is configured in proxy only. There are another useful features which

Re: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-08 Thread Skip Montanaro
Thanks all. I was hoping to get away without something more sophisticated like NGINX. This is just a piddly little archive of an old mailing list running on a single-core Ubuntu VM somewhere on the East Coast. Speed is not a real requirement. Load balancing seemed like overkill to me. Still, I gues

Re: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-08 Thread Albert-Jan Roskam
I always use NGINX for this. Run Flask/Gunicorn on localhost:5000 and have NGINX rewrite https requests to localhost requests. In nginx.conf I automatically redirect every http request to https. Static files are served by NGINX, not by Gunicorn, which is faster. NGINX also allows you

Re: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-07 Thread Kushal Kumaran
On Fri, Jan 07 2022 at 12:51:48 PM, Skip Montanaro wrote: > Hopefully some Pythonistas are also Gunicornistas. I've had little success > finding help with a small dilemma in the docs or in other more specific > sources. > > I'm testing out a new, small website. It is just Gunicorn+Flask. I'd like

Gunicorn - HTTP and HTTPS in the same instance?

2022-01-07 Thread Skip Montanaro
Hopefully some Pythonistas are also Gunicornistas. I've had little success finding help with a small dilemma in the docs or in other more specific sources. I'm testing out a new, small website. It is just Gunicorn+Flask. I'd like to both listen for HTTP and HTTPS connections. Accordingly, in my co

typing instance variable

2021-05-13 Thread David Kolovratník
t): File "myclass.py", line 1, in class MyClass: ValueError: 'foo' in __slots__ conflicts with class variable This is where the way of type declaration of instance variable comes from: https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html class MyClass: # You can optiona

Re: pyodbc -> MS-SQL Server Named Instance ?

2019-07-02 Thread Frank Millman
On 2019-07-02 3:41 PM, Adam Tauno Williams wrote: On Tue, 2019-07-02 at 07:36 +0200, Frank Millman wrote: On 2019-07-01 10:13 PM, Adam Tauno Williams wrote: I am trying to connect to a Named Instance on an MS-SQL server using pyODBC. This is what I use -  conn = pyodbc.connect

Re: pyodbc -> MS-SQL Server Named Instance ?

2019-07-02 Thread Adam Tauno Williams
On Tue, 2019-07-02 at 11:00 -0400, Adam Tauno Williams wrote: > On Tue, 2019-07-02 at 09:41 -0400, Adam Tauno Williams wrote: > > On Tue, 2019-07-02 at 07:36 +0200, Frank Millman wrote: > > > On 2019-07-01 10:13 PM, Adam Tauno Williams wrote: > > > > I am trying to

Re: pyodbc -> MS-SQL Server Named Instance ?

2019-07-02 Thread Adam Tauno Williams
On Tue, 2019-07-02 at 09:41 -0400, Adam Tauno Williams wrote: > On Tue, 2019-07-02 at 07:36 +0200, Frank Millman wrote: > > On 2019-07-01 10:13 PM, Adam Tauno Williams wrote: > > > I am trying to connect to a Named Instance on an MS-SQL server > > > using pyODBC. I

Re: pyodbc -> MS-SQL Server Named Instance ?

2019-07-02 Thread Malcolm Greene
You may need to update your ODBC driver from version 13 to 17.x. Malcolm -- https://mail.python.org/mailman/listinfo/python-list

Re: pyodbc -> MS-SQL Server Named Instance ?

2019-07-02 Thread Adam Tauno Williams
On Tue, 2019-07-02 at 07:36 +0200, Frank Millman wrote: > On 2019-07-01 10:13 PM, Adam Tauno Williams wrote: > > I am trying to connect to a Named Instance on an MS-SQL server > > using pyODBC. > This is what I use - > >  conn = pyodbc.connect( >

Re: pyodbc -> MS-SQL Server Named Instance ?

2019-07-01 Thread Frank Millman
On 2019-07-01 10:13 PM, Adam Tauno Williams wrote: I am trying to connect to a Named Instance on an MS-SQL server using pyODBC. The ODBC driver works, as I can connection without issue to a non- named-instance SQL-Server used by another application. What is the DSN (connection) string magick

pyodbc -> MS-SQL Server Named Instance ?

2019-07-01 Thread Adam Tauno Williams
I am trying to connect to a Named Instance on an MS-SQL server using pyODBC. The ODBC driver works, as I can connection without issue to a non- named-instance SQL-Server used by another application. What is the DSN (connection) string magick to connect to a named instance? I can connect from my

Re: Instance vs Class variable oddity

2019-05-18 Thread jfong
Chris Angelico於 2019年5月18日星期六 UTC+8下午3時09分37秒寫道: > On Sat, May 18, 2019 at 1:51 PM wrote: > > > > Correct me if I am wrong, please. > > > > I always think that the LEGB rule (e.g. the namespace to look up for) was > > applied at compile-time, only the binding was resolved "dynamically" at > > ru

Re: Instance vs Class variable oddity

2019-05-18 Thread Chris Angelico
On Sat, May 18, 2019 at 1:51 PM wrote: > > Correct me if I am wrong, please. > > I always think that the LEGB rule (e.g. the namespace to look up for) was > applied at compile-time, only the binding was resolved "dynamically" at > run-time. For example: > > def foo(): > print(x) > > foo() wi

Re: Instance vs Class variable oddity

2019-05-17 Thread dieter
s. > > I have never run across this issue because I would never use the same name as > an instance attribute and a class attribute. I use this regularly. Think of the "class attribute" as providing a default for a potential "instance attribute" of the same na

Re: Instance vs Class variable oddity

2019-05-17 Thread jfong
ariable, or a global variable. It's more likely a class instance attribute, and it's resolved by applying MRO rule dynamically. --Jach -- https://mail.python.org/mailman/listinfo/python-list

Re: Instance vs Class variable oddity

2019-05-17 Thread Ethan Furman
On 05/17/2019 11:37 AM, Irv Kalb wrote: self.x = self.x + 1 I have never run across this issue because I would never use the same name as an instance attribute and a class attribute. So you treat your class attributes as if they were static? -- ~Ethan~ -- https://mail.python.org/mailman

Re: Instance vs Class variable oddity

2019-05-17 Thread Chris Angelico
lf.x can refer to different variables. I > actually teach Python, and this would be a very difficult thing to explain to > students. > > I have never run across this issue because I would never use the same name as > an instance attribute and a class attribute. (I also know that "

Re: Instance vs Class variable oddity

2019-05-17 Thread Irv Kalb
> On May 15, 2019, at 5:41 PM, Ben Finney wrote: > > Irv Kalb writes: > >> I just saw some code that confused me. The confusion has to do with >> class variables and instance variables. > > (Perhaps unrelated, but here's another confusion you may be suff

Re: Instance vs Class variable oddity

2019-05-15 Thread Ben Finney
Irv Kalb writes: > I just saw some code that confused me. The confusion has to do with > class variables and instance variables. (Perhaps unrelated, but here's another confusion you may be suffering from: There's no such thing as a “class variable” or “instance variabl

Re: Instance vs Class variable oddity

2019-05-15 Thread Irv Kalb
> On May 15, 2019, at 11:02 AM, Rob Gaddi > wrote: > > On 5/15/19 10:52 AM, Irv Kalb wrote: >> I just saw some code that confused me. The confusion has to do with class >> variables and instance variables. In order to understand it better, I built >> this ver

Re: Instance vs Class variable oddity

2019-05-15 Thread Rob Gaddi
On 5/15/19 10:52 AM, Irv Kalb wrote: I just saw some code that confused me. The confusion has to do with class variables and instance variables. In order to understand it better, I built this very small example: class Test: x = 0 def __init__(self, id): self.id = id

Instance vs Class variable oddity

2019-05-15 Thread Irv Kalb
I just saw some code that confused me. The confusion has to do with class variables and instance variables. In order to understand it better, I built this very small example: class Test: x = 0 def __init__(self, id): self.id = id self.show() def show(self

Re: Questions on Instance methods

2019-04-22 Thread dieter
Arup Rakshit writes: > ... > As you saw from documentation link, those are just words kind of spec. > Which source you recommend to read which explains these concepts more with > example codes. I cannot help you much with this -- I am much turned towards spec[ification] like documentation and ha

Re: Questions on Instance methods

2019-04-21 Thread eryk sun
On 4/21/19, Arup Rakshit wrote: > > I am reading https://docs.python.org/3/reference/index.html now, and it > seems like saying what Python can do, but not going deep to explain it > to a new comers most of the time. The guide to Python descriptors may help. https://docs.python.org/3/howto/descr

Re: Questions on Instance methods

2019-04-21 Thread Arup Rakshit
p Rakshit writes: > >>> When an instance method object is created by retrieving a class method >>> object from a class or instance, its __self__ attribute is the class >>> itself, and its __func__ attribute is the function object underlying the >>> class

Re: Questions on Instance methods

2019-04-19 Thread dieter
Arup Rakshit writes: >>When an instance method object is created by retrieving a class method >> object from a class or instance, its __self__ attribute is the class itself, >> and its __func__ attribute is the function object underlying the class >> method. >

Questions on Instance methods

2019-04-19 Thread Arup Rakshit
>When an instance method object is created by retrieving a class method > object from a class or instance, its __self__ attribute is the class itself, > and its __func__ attribute is the function object underlying the class method. Here I have 2 questions: 1. How do you create an

Re: Reasoning of calling a method on class object instead of class instance object

2019-03-19 Thread Peter Otten
edShippingContainer._c_to_f(self.celsius) > If I call `_c_to_f`, `_f_to_c` methods on `self` instead of > `RefrigeratedShippingContainer` class object, still it works. So what is > the reason behind of this calling on the class object, instead class > instance object? I don't know,

Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Michael Torrie
On 03/18/2019 07:09 PM, Ben Finney wrote: > Arup Rakshit writes: > > Michael Torrie writes: > >> On 03/18/2019 05:55 PM, Ben Finney wrote: If I call `_c_to_f`, `_f_to_c` methods on `self` instead of `RefrigeratedShippingContainer` class object, still it works. >>> >>> That's right, an

Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Ben Finney
Arup Rakshit writes: Michael Torrie writes: > On 03/18/2019 05:55 PM, Ben Finney wrote: > >> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of > >> `RefrigeratedShippingContainer` class object, still it works. > > > > That's right, and is indeed the point of making a static method on

Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Michael Torrie
On 03/18/2019 05:55 PM, Ben Finney wrote: >> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of >> `RefrigeratedShippingContainer` class object, still it works. > > That's right, and is indeed the point of making a static method on a > class. I'm confused. The methods that refer to Refi

Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Ben Finney
d function] can be called either on the class (such as `C.f()`) or on an instance (such as `C().f()`). The instance is ignored except for its class. > So what is the reason behind of this calling on the class object, > instead class instance object? Whichever makes the most sense in th

Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Arup Rakshit
t(self, value): self.celsius = RefrigeratedShippingContainer._f_to_c(value) If I call `_c_to_f`, `_f_to_c` methods on `self` instead of `RefrigeratedShippingContainer` class object, still it works. So what is the reason behind of this calling on the class object, instead class instance

Re: Instance of 'dict' has no 'replace' member

2019-02-01 Thread Dan Sommers
On 2/1/19 7:15 AM, sinless...@gmail.com wrote: Hello guys can you help me to solve problem when i compile proram got error like this "Instance of 'dict' has no 'replace' member[no member](67;14)". Python dicts don't have a replace method. It looks like you&

Instance of 'dict' has no 'replace' member

2019-02-01 Thread sinless199
Hello guys can you help me to solve problem when i compile proram got error like this "Instance of 'dict' has no 'replace' member[no member](67;14)". here you can see my code. url = "http://mapa.um.warszawa.pl/mapviewer/foi"; querystring = {"req

Re: Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-27 Thread Peter J. Holzer
On 2018-12-17 21:57:22 +1100, Paul Baker wrote: > class C: > def __init__(self): > self.__dict__['a'] = 1 > > @property > def a(self): > return 2 > > o = C() > print(o.a) # Prints 2 What version of Python is this? I get a different res

Re: Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-27 Thread Peter J. Holzer
On 2018-12-27 14:17:34 +0100, Peter J. Holzer wrote: > On 2018-12-17 21:57:22 +1100, Paul Baker wrote: > > class C: > > def __init__(self): > > self.__dict__['a'] = 1 > > > > @property > > def a(self): > > return 2 > > > > o = C() > > pr

Re: Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-18 Thread Ian Kelly
On Mon, Dec 17, 2018, 12:09 PM Paul Baker When Python looks up an attribute on an object (i.e. when it executes > `o.a`), it uses an interesting priority order [1]. It looks for: > > 1. A class attribute that is a data-descriptor (most commonly a property) > 2. An instance attribu

Re: Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-18 Thread dieter
Paul Baker writes: > When Python looks up an attribute on an object (i.e. when it executes > `o.a`), it uses an interesting priority order [1]. It looks for: > > 1. A class attribute that is a data-descriptor (most commonly a property) > 2. An instance attribute > 3. Any oth

Why do data descriptors (e.g. properties) take priority over instance attributes?

2018-12-17 Thread Paul Baker
When Python looks up an attribute on an object (i.e. when it executes `o.a`), it uses an interesting priority order [1]. It looks for: 1. A class attribute that is a data-descriptor (most commonly a property) 2. An instance attribute 3. Any other class attribute We can confirm this using the

Re: How to test for type or instance of dict_values?

2018-12-11 Thread fabian . becker87
Very late to the party, but I just encountered a very similar problem and found a solution: ``` import collections obj = {"foo": "bar"} isinstance(obj.values(), collections.abc.ValuesView) # => True ``` Hope that helps someone out there :) On Thursday, November 17, 2016 at 9:09:23 AM UTC-8, Te

Re: Injecting methods into instance / class

2018-12-03 Thread Peter Otten
duncan smith wrote: > On 02/12/2018 18:36, Peter Otten wrote: >> class CommonMethods: >> __add__ = add > Ah, I could just bind them within the class, > > mean = mean > max = max etc. > > but I'd somehow convinced myself that didn't work. As the names are the > same I'd probably sti

Re: Injecting methods into instance / class

2018-12-02 Thread duncan smith
On 02/12/2018 18:36, Peter Otten wrote: > duncan smith wrote: > >> Hello, >> I have a lot of functions that take an instance of a particular >> class as the first argument. I want to create corresponding methods in >> the class. I have tried the following, wh

Re: Injecting methods into instance / class

2018-12-02 Thread Thomas Jollans
On 02/12/2018 18:56, duncan smith wrote: > Hello, > I have a lot of functions that take an instance of a particular > class as the first argument. I want to create corresponding methods in > the class. I have tried the following, which (when called from __init__) > creat

Re: Injecting methods into instance / class

2018-12-02 Thread duncan smith
On 02/12/2018 18:26, Stefan Ram wrote: > duncan smith writes: >> I have tried to find examples of injecting methods into classes without > > Wouldn't the normal approach be to just define a > class with your functions as instance methods? > > main.py >

Re: Injecting methods into instance / class

2018-12-02 Thread Peter Otten
duncan smith wrote: > Hello, > I have a lot of functions that take an instance of a particular > class as the first argument. I want to create corresponding methods in > the class. I have tried the following, which (when called from __init__) > creates the relevant methods

Re: Injecting methods into instance / class

2018-12-02 Thread Morten W. Petersen
Hi Duncan. On Sun, Dec 2, 2018 at 7:02 PM duncan smith wrote: > Hello, > I have a lot of functions that take an instance of a particular > class as the first argument. I want to create corresponding methods in > the class. I have tried the following, which (when called f

Injecting methods into instance / class

2018-12-02 Thread duncan smith
Hello, I have a lot of functions that take an instance of a particular class as the first argument. I want to create corresponding methods in the class. I have tried the following, which (when called from __init__) creates the relevant methods in an instance (Python 3.6). def init_methods

Re: Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Ibrahim Dalal
e(A.foo) # > > a.foo() # TypeError: foo() takes no arguments (1 given) > > A.foo() # TypeError: unbound method foo() must be called > > with A instance as first argument (got nothing instead) > > > > There is a way in Python 2 as well, and I'm

Re: Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Bob van der Poel
iven) > A.foo() # TypeError: unbound method foo() must be called > with A instance as first argument (got nothing instead) > > > Clearly, foo is an instance method. I know one should use @staticmethod for > declaring a method static. The question here is, given the abo

Re: Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Terry Reedy
foo() must be called with A instance as first argument (got nothing instead) Clearly, foo is an instance method. It is either a buggy instance method, missing the required first parameter, *or* a buggy static method, missing the decorator, making it appear to the interpreter as an instance metho

Re: Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Thomas Jollans
() # TypeError: unbound method foo() must be called > with A instance as first argument (got nothing instead) > > > Clearly, foo is an instance method. I know one should use @staticmethod for > declaring a method static. The question here is, given the above code, is > th

Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Ibrahim Dalal
class A: def foo(): print 'Hello, world!' a = A()print A.foo # print a.foo # >print type(A.foo) # a.foo() # TypeError: foo() takes no arguments (1 given) A.foo() # TypeError: unbound method foo() must be called with A instance as first

Re: Cross platform mutex to prevent script running more than instance?

2018-09-06 Thread eryk sun
On Tue, Sep 4, 2018 at 5:47 PM, Cameron Simpson wrote: > > The downside with mkdir, and also with pd files really, is that a program or > OS abort can leave them lying around. Being persistent objects, some kind of > cleanup is needed. While the OP needs a cross-platform solution, if it's just Wi

Re: Cross platform mutex to prevent script running more than instance?

2018-09-05 Thread Cameron Simpson
On 03Sep2018 07:45, Malcolm Greene wrote: >Use case: Want to prevent 2+ instances of a script from running ... >ideally in a cross platform manner. I've been researching this topic and >am surprised how complicated this capability appears to be and how the >diverse the solution set is. I've seen s

Re: Cross platform mutex to prevent script running more than instance?

2018-09-05 Thread Thomas Jollans
On 09/04/2018 05:35 AM, Cameron Simpson wrote: > On 03Sep2018 07:45, Malcolm Greene wrote: >> Use case: Want to prevent 2+ instances of a script from running ... >> ideally in a cross platform manner. I've been researching this topic and >> am surprised how complicated this capability appears to b

Re: Cross platform mutex to prevent script running more than instance?

2018-09-05 Thread CFK
What about using flock()? I don't know if it works on Windows, but it works really well for Unix/Linux systems. I typically create a log file in a known location using any atomic method that doesn't replace/overwrite a file, and flock() it for the duration of the script. Thanks, Cem Karan On Mon

  1   2   3   4   5   6   7   8   9   10   >