Re: Passing information between modules
On 11/21/2022 12:24 AM, dn wrote: My original question probably was intended to be something like: "Today, we can add attributes to a module from the outside. How large is the risk that this will be forbidden one day, so that all code using this will stop working?". This can happen today if, for example, a class is changed to use slots for everything. Between slots and type checking, it can become impossible to add an arbitrary attribute. *You* may be able to avoid this, but if you use someone else's modules or classes it could happen at any time. I might regret the loss of being able to assign an arbitrary attribute wherever I like, but for complex libraries, it is probably a good idea in the long run. -- https://mail.python.org/mailman/listinfo/python-list
Python 3.11.0 installation and Tkinter does not work
Dear list, I want learn python for 4 weeks and have problems, installing Tkinter. If I installed 3.11.0 for my windows 8.1 from python.org and type >>> import _tkinter > Traceback (most recent call last): > File "", line 1, in > ImportError: DLL load failed while importing _tkinter: Das angegebene > Modul wurde nicht gefunden. > So I it is a tkinter Problem and I tried this: > >>> import _tkinter > Traceback (most recent call last): > File "", line 1, in > ImportError: DLL load failed while importing _tkinter: Das angegebene > Modul wurde nicht gefunden. How can I fix this and make it work? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.11.0 installation and Tkinter does not work
On 11/21/2022 1:24 PM, Stefan Ram wrote: [email protected] writes: import _tkinter I don't know why you get this error message. Here, I do not get an error message from that line. However, the normal way to use tkinter, as far as I know, is without the underscore! You can import both tkinter and _tkinter, though I'm not sure why you would do the latter for any normal programming. I think it might be best if you make sure that a recent Visual C++ Redistributable Runtime from Microsoft® is installed before you install Python. That's a worthwhile thought. If you have no such Runtime, I have no idea how to proceed! Maybe uninstall Python, install the Runtime, and then install Python again? python.org says: "Note that Python 3.11.0 cannot be used on Windows 7 or earlier" But maybe there's something about their compilation settings or runtime support versions that doesn't work with the OP's version of Python 8.1. Or, since Python itself seems to be running, maybe the way the tkinter binary was compiled isn't compatible even though Python 3.11 itself is. Maybe this is a bug waiting to be filed... I would try installing a lower version, maybe an older version of Python 3.10, and seeing if that works. If you have chosen any unusual settings during the installation of Python, it might help to try an installation with the suggested settings. I am trying to learn tkinter myself and I am very surprised how well it offers exactly what I am looking for! I hope they never will remove tkinter from the standard distribution! -- https://mail.python.org/mailman/listinfo/python-list
Re: Passing information between modules
> On 21 Nov 2022, at 21:23, [email protected] wrote: > > dn writes: >> Now, at the config stage, take the instructions to define whichever the >> user prefers, and instantiate that class. Then the 'calling-routine' can >> use the instantiated object as an interface to whichever type of output. > > I had many different functions that are supposed to take > a "context" argument. If I would make them all methods of > a class with a "context" field, that would be a huge class > containing methods with many different purposes, which > reminds of the "anti pattern" "God class". Do you haves lots of free standing functions? Are all these functions not part of classes? > >> with Environment() as env: >># processing >> There would be no need to explicitly prevent any 'processing' if the >> set-up doesn't work, because that context manager class will handle it all! > > Yes, but my problem was not so much with setting up the env, > but with passing it to many library functions. Are you writing procedural code or object oriented? Why do you have so many functions outside of a small number of classes? > >> Is this how you implement? > > I'm not sure whether I understand the meaning of this question. You appear not to be doing object oriented design. > > My library had a "console context" (before I started to use > the Python logging facility instead). That console context was > the default for output of progress and error messages. > > A client had the possibility to call functions with a custom > context, and then the function would use this custom context > for progress and error messages. The custom context could > direct those message to a text field in a GUI, for example. > > Instead of passing this custom context to many library > functions, it might be simpler to "pass it to the library > once". This could be done via: > > import library > library.context = my_GUI_context That is not oo design. I get the feeling that you need a better understanding of how to structure a non-trivia library. If you need the context object then you must pass it around. > > , but I wonder whether this "writing into another module" > is really possible in every Python implementation and whether > it will still be supported in the future. I do not see such > a pattern being used with the standard packages and suppose > that there might be a reason for this! > > The same question applies to the more advanced technique of > using "importlib.util.find_spec", "importlib.util.module_from_spec", > and ".__spec__.loader.exec_module" to even support having > different instances of a single module with different globals. > > I can now formulate my question this way: > > Many functions of a library have in their source code calls > like "PRINT( f'Done. Output was written to {filename}.' )". > The library uses "print" as a default for "PRINT", but > should explicitly support clients substituting a custom > implementation to be used for "PRINT". What's the best way > for the client to "pass" his custom implementation to the > library (which is a package or a module)? Each place you have PRINT you need to have context.print calls. You said above that you have, or had, such an object - pass it around and use it. If passing it around is the problem then you need to look at why you code has that problem. Barry > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.11.0 installation and Tkinter does not work
On 11/21/2022 12:59 PM, [email protected] wrote: Dear list, I want learn python for 4 weeks and have problems, installing Tkinter. If I installed 3.11.0 for my windows 8.1 from python.org and type >>> import _tkinter > Traceback (most recent call last): > File "", line 1, in > ImportError: DLL load failed while importing _tkinter: Das angegebene > Modul wurde nicht gefunden. > So I it is a tkinter Problem and I tried this: > >>> import _tkinter > Traceback (most recent call last): > File "", line 1, in > ImportError: DLL load failed while importing _tkinter: Das angegebene > Modul wurde nicht gefunden. How can I fix this and make it work? When installing Python 3.11.0 did you check the box "tcl/tk and IDLE"? (it's an option on the Python Windows installer). I made sure to do that, and then this worked: import tkinter from tkinter import filedialog as fd from tkinter.filedialog import askopenfilename filename = fd.askopenfilename() print(filename) foldername = fd.askdirectory() print(foldername) time.sleep(3) -- https://mail.python.org/mailman/listinfo/python-list
