Difference method vs attribut = function
Hi, a class can have methods, and it can have attributes, which can hold a function. Both is well known, of course. My question: Is there any difference? The code snipped shows that both do what they should do. But __dict__ includes just the method, while dir detects the method and the attribute holding a function. My be that is the only difference? class MyClass: def __init__(self): functionAttribute = None def method(self): print("I'm a method") def function(): print("I'm a function passed to an attribute") mc = MyClass() mc.functionAttribute = function mc.method() mc.functionAttribute() print('Dict: ', mc.__dict__)# shows functionAttribute but not method print('Dir: ', dir(mc))# shows both functionAttribute and method By the way: in my usecase I want to pass different functions to different instances of MyClass. It is in the context of a database app where I build Getters for database data and pass one Getter per instance. Thanks for hints Ulrich -- Ulrich Goebel -- https://mail.python.org/mailman/listinfo/python-list
Best Practice Virtual Environment
Hi, I learned to use virtual environments where ever possible, and I learned to pip install the required packages there. That works quite nice at home. Now I come to deploy a Python script on a debian linux server, making it usable for a couple of users there. Debian (or even Python3 itself) doesn't allow to pip install required packages system wide, so I have to use virtual environments even there. But is it right, that I have to do that for every single user? Can someone give me a hint to find an howto for that? Best regards Ulrich -- Ulrich Goebel -- https://mail.python.org/mailman/listinfo/python-list
TkInter Scrolled Listbox class?
Hi, I would like to build a class ScrolledListbox, which can be packed somewhere in ttk.Frames. What I did is to build not really a scrolled Listbox but a Frame containing a Listbox and a Scrollbar: class FrameScrolledListbox(ttk.Frame): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # # build Listbox and Scrollbar self.Listbox = tk.Listbox(self) self.Scrollbar = ttk.Scrollbar(self) # # configure these two self.Listbox.config(yscrollcommand=self.Scrollbar.set) self.Scrollbar.config(command=self.Listbox.yview) # # pack them in Frame self.Listbox.pack(side=tk.LEFT, fill=tk.BOTH) self.Scrollbar.pack(side=tk.RIGHT, fill=tk.BOTH) That works, so instances of FrameScrolledListbox can be packed and the tk.Listbox itself is accessible via an attribute: frmScrolledListbox = FrameScrolledListbox(main) frmScrolledListbox.Listbox.config(...) But it would be a bit nicer to get a class like class ScrolledListbox(tk.Listbox): ... So it would be used that way: scrolledListbox = ScrolledListbox(main) scrolledListbox.config(...) Is that possible? The problem which I can't handle is to handle the Frame which seems to be needed to place the Scrollbar somewhere. Best regards Ulrich -- Ulrich Goebel -- https://mail.python.org/mailman/listinfo/python-list
Python 3.8 or later on Debian?
Hi, Debian Linux seems to love Python 3.7 - that is shown by apt-get list, and it's installed on my Debian Server. But I need at least Python 3.8 Is there a repository which I can give to apt to get Python 3.8 or later? Or do I really have to install and compile these versions manually? I'm not a friend of things so deep in the system... Greetings Ulrich -- Ulrich Goebel -- https://mail.python.org/mailman/listinfo/python-list