Is it possible to call a class but without a new instance created?

Jim Lee jlee54 at gmail.com
Tue Jun 19 03:44:52 EDT 2018



On 06/18/2018 09:22 PM, Jach Fong wrote:
> Ben Finney at 2018/6/19 PM 10:20 wrote:
>> Jach Fong <jfong at ms4.hinet.net> writes:
>>
>>> Although it passed the first examination, I have no idea if it can
>>> work correctly in the real application:-)
>>
>> Neither do I. What is the real-world problem you are trying to solve?
>> Why do you think this (and not some more idiomatic Python feature) is
>> needed for solving that problem?
>>
> No, I don't have any specific application in mind. This idea was just
> triggered by a sentence in a Docstring in file font.py.
>
> class Font:
>     """Represents a named font.
>     Constructor options are:
>     ...
>     exists -- does a named font by this name already exist?
>        Creates a new named font if False, points to the existing font 
> if True.
>     ...
>     """
>
> But honestly I still don't know how it "points to the existing font":-(
>
>
If the font exists, the Font object calls this:
     tk.call("font", "configure", self.name, *font)
Otherwise, it calls this:
     tk.call("font", "create", self.name, *font)

The font caching is all handled by Tk, not Python.  The Font object is 
just a wrapper around calls to Tk.

-Jim




More information about the Python-list mailing list