From educationandmore at gmail.com Tue Aug 13 09:56:06 2024 From: educationandmore at gmail.com (Markis Gardner) Date: Tue, 13 Aug 2024 09:56:06 -0400 Subject: [Tutor] Question Message-ID: This is my first time - so I hope I am doing this correctly. A long time ago, back when VB 6 was still popular (boy I loved that language, but hated what they did to it in VB.NET. WIshed they still had it) and Yahoo messenger was still around. I wrote a SUPER SIMPLE ABBREVIATED form of messenger able to chat with other people. Is it possible to do it as a standalone program with Python? If yes, can you give me suggestions on what to read (please don't send me the code solution)? If no, what is the best that can be done with JUST python? Thank you! Markis -- I am a certified Education consultant with *both *PIER and ICEF. http://connect.pierapps.com/widgets/agencies/42472 Check out one of my inventions.. Laser Deflector! Laser Deflector (lasermirrorgame.com) From alan.gauld at yahoo.co.uk Tue Aug 13 11:00:21 2024 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 13 Aug 2024 16:00:21 +0100 Subject: [Tutor] Question In-Reply-To: References: Message-ID: On 13/08/2024 14:56, Markis Gardner wrote: > ABBREVIATED form of messenger able to chat with other people. > > Is it possible to do it as a standalone program with Python? It depends what you mean by standalone. If you are happy to run it under the Python interpreter then yes thats straightforward. If you want to create an exe file that you can distribute then there are tools that can bundle up a python program + interpreter into a self executing bundle. > If yes, can you give me suggestions on what to read (please don't send me > the code solution)? I'm not sure what your level of experience is. But the official Python tutorial would be a good start for an ex VB6 programmer. And for the networking stuff there are varios online tutorials and HowTos around. A good paper book is "Python Network Programming" on Apress. I don't know enough about Yahoo Messenger protocols etc to offer any more specific advice. But python has pretty good networking support so you should be able to do something. There may even be a module specifically for Yahoo, try searching the PyPi repository. In fact, a quick Google threw this up: https://pypi.org/project/pyahoolib/ Claims to support the Yahoo Messenger protocol... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From PythonList at DancesWithMice.info Tue Aug 13 17:06:48 2024 From: PythonList at DancesWithMice.info (dn) Date: Wed, 14 Aug 2024 09:06:48 +1200 Subject: [Tutor] Question In-Reply-To: References: Message-ID: <159099be-a6cc-45f2-a6ca-90c10e6e6144@DancesWithMice.info> On 14/08/24 03:00, Alan Gauld via Tutor wrote: > On 13/08/2024 14:56, Markis Gardner wrote: > >> ABBREVIATED form of messenger able to chat with other people. >> >> Is it possible to do it as a standalone program with Python? > > It depends what you mean by standalone. If you are happy to run it under > the Python interpreter then yes thats straightforward. If you want to > create an exe file that you can distribute then there are tools that can > bundle up a python program + interpreter into a self executing bundle. > >> If yes, can you give me suggestions on what to read (please don't send me >> the code solution)? > > I'm not sure what your level of experience is. But the official Python > tutorial would be a good start for an ex VB6 programmer. And for the > networking stuff there are varios online tutorials and HowTos around. > A good paper book is "Python Network Programming" on Apress. > > I don't know enough about Yahoo Messenger protocols etc to offer > any more specific advice. But python has pretty good networking > support so you should be able to do something. There may even be a > module specifically for Yahoo, try searching the PyPi repository. > In fact, a quick Google threw this up: > > https://pypi.org/project/pyahoolib/ > > Claims to support the Yahoo Messenger protocol... Like @Alan, I haven't played with the Yahoo Messenger code. Enjoyed the learning-intention of this question (cf a give-me-the-answer attitude)! Was put-off by the description of the above code-library. Since Yahoo's prime, the world has moved-on. There are disadvantages to large, centralised systems - yesterday someone would have lost his/her job (or head) over the Trump-Musk love-fest foul-up on eX-twitter, and mentioning "CrowdStrike" will still cause many-a blood-pressure to rise. Accordingly, other ideas have arisen such as the ActivityPub protocol, Pub-Sub ideas, and similar. Having mentioned Twitter earlier and on-topic with messaging, an alternative implementation is Mastodon (not that I'm a frequent user of same). You may like to take a look at its mechanisms, perhaps starting with "How to implement a basic ActivityPub server" (https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/) which is language-agnostic (so, discussing mechanisms and data-transfer rather than coding detail) and leads-on with further reading. Regardless of the course you choose, please let us know how you get-on, and feel free to ask further questions... PS I've thought (but that's as far as I've progressed) about developing a Python presentation on programming with APIs, using Mastodon as an (interest-raising) 'target'. -- Regards, =dn From avi.e.gross at gmail.com Tue Aug 13 20:30:53 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Tue, 13 Aug 2024 20:30:53 -0400 Subject: [Tutor] Question In-Reply-To: References: Message-ID: <00af01daede1$38bee4f0$aa3caed0$@gmail.com> Markis, Any fairly simple algorithm generally can be rewritten in Python BUT many such programs rely on external functionality that may not trivially be available. Did your program use Visual Basic libraries or external libraries written in C or Fortran and so on to do some of the work? It may be you can find such functionality in the Python universe too, but that can be a consideration. As others have mentioned, it depends on what you mean by standalone. Pretty much any Python program can be a standalone if it is invoked from some command file that calls python as an interpreter and hands it a file to execute. Your distribution would supply the appropriate such file and document calling it, as one option. Other options to make a sort of bundled executable could be done but may not be necessary if the right version of python is already installed. -----Original Message----- From: Tutor On Behalf Of Markis Gardner Sent: Tuesday, August 13, 2024 9:56 AM To: tutor at python.org Subject: [Tutor] Question This is my first time - so I hope I am doing this correctly. A long time ago, back when VB 6 was still popular (boy I loved that language, but hated what they did to it in VB.NET. WIshed they still had it) and Yahoo messenger was still around. I wrote a SUPER SIMPLE ABBREVIATED form of messenger able to chat with other people. Is it possible to do it as a standalone program with Python? If yes, can you give me suggestions on what to read (please don't send me the code solution)? If no, what is the best that can be done with JUST python? Thank you! Markis -- I am a certified Education consultant with *both *PIER and ICEF. http://connect.pierapps.com/widgets/agencies/42472 Check out one of my inventions.. Laser Deflector! Laser Deflector (lasermirrorgame.com) _______________________________________________ Tutor maillist - Tutor at python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor From alan.gauld at yahoo.co.uk Sun Aug 18 10:18:01 2024 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 18 Aug 2024 15:18:01 +0100 Subject: [Tutor] Any Jupyter users? Message-ID: I have a friend doing a CS degree and running into problems with a Python "program" in her data science course. I said I'd take a look although data analysis is not my forte. When I got there I was presented with a Jupyter/Anaconda environment and the program seemed to be effectively a long interactive session (which Jupyter can save and rerun) about 200+ lines. Most of which is simply calling into library functions from the anaconda stack plus a half dozen libraries installed by pip at the top of the session. The error (a valueError) when I got to it is raised deep inside one of the imported libraries and the traceback does not go all the way to the top (only 3 or 4 levels) so it's not clear where the student's code is calling the library (although I suspect it will be the line in Jupyter above the error trace... But that is not calling any of the functions listed in the traceback. I don't use Anaconda or Jupyter so I'm not sure what debugging facilities are available. Is there a way to generate a complete traceback? Are there ways to find out where a function is defined (which module?). I did a simple text search but it didn't find the highest function listed so I assume it's inside a module somewhere, but where? Are there any tracing facilities like the ability to step through/into a function? Also can you save a Jupyter session as a runnable python file (ie with all the output stuff removed or commented out)? That way we might get a more complete error trace from the vanilla interpreter. Or load it into a smart IDE like Visual Code that can jump up and down the stack. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From mats at wichmann.us Sun Aug 18 10:33:45 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 18 Aug 2024 08:33:45 -0600 Subject: [Tutor] Any Jupyter users? In-Reply-To: References: Message-ID: On 8/18/24 08:18, Alan Gauld via Tutor wrote: > I don't use Anaconda or Jupyter so I'm not sure what debugging > facilities are available. Is there a way to generate a complete > traceback? Are there ways to find out where a function is defined > (which module?). I did a simple text search but it didn't find the > highest function listed so I assume it's inside a module somewhere, > but where? Are there any tracing facilities like the ability to step > through/into a function? there's an ipdb you can install to be able to debug, similar the Python stdlib pdb.'Bout as much as I know. Seems Jupyter provides something more sophisticated but this is just a quick web search, no knowledge (this iPython notebook stuff has never really made sense to me, and I end up deleting the support packages when they install automatically in VS Code, for example. So I'm a pretty bad resource (grin)). https://jupyterlab.readthedocs.io/en/stable/user/debugger.html > > Also can you save a Jupyter session as a runnable python file > (ie with all the output stuff removed or commented out)? That way we > might get a more complete error trace from the vanilla interpreter. > Or load it into a smart IDE like Visual Code that can jump up and > down the stack. > From sjeik_appie at hotmail.com Fri Aug 23 11:53:46 2024 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 23 Aug 2024 17:53:46 +0200 Subject: [Tutor] Dataclass question Message-ID: Hi, I'm using dataclasses and one of the fields is has a bytes type. It could be the contents of a .zip or .csv. I don't want to see so much clutter in the logs or on the screen, so I'm looking for a neat way to omit most of the info from the dataclass object's representation. Using the code below, field "y" is not shown at all, which is not really what I want (but it's nice and clean). Field "z" is more like it, but it requires more code. Is there a better way? Maybe with pydantic? from dataclasses import field, dataclass class AbbreviatedBytes(bytes): def __repr__(self, width=2): r = super().__repr__() return r if len(self) < width else f"{r[:width + 1]} [...]'" @dataclass class Test: x : bytes = b"" y : bytes = field(default=b"", repr=False) z : bytes = b"" def __post_init__(self): self.z = AbbreviatedBytes(self.z) print(Test(b"aaaa", b"bbbb", b"cccc")) # output: Test(x=b'aaaa', z=b'c [...]') Best wishes, Albert-Jan From sjeik_appie at hotmail.com Fri Aug 23 12:04:22 2024 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 23 Aug 2024 18:04:22 +0200 Subject: [Tutor] Dataclass question In-Reply-To: Message-ID: Hmm, maybe ditch the AbbrevitatedBytes class and then: def __post_init__(self): self.z.__repr__ = lambda self, n=10: repr(self) if len(self) < n else repr(self)[:n] + " [...]" On Aug 23, 2024 17:53, Albert-Jan Roskam wrote: Hi, I'm using dataclasses and one of the fields is has a bytes type. It could be the contents of a .zip or .csv. I don't want to see so much clutter in the logs or on the screen, so I'm looking for a neat way to omit most of the info from the dataclass object's representation. Using the code below, field "y" is not shown at all, which is not really what I want (but it's nice and clean). Field "z" is more like it, but it requires more code. Is there a better way? Maybe with pydantic? from dataclasses import field, dataclass class AbbreviatedBytes(bytes): def __repr__(self, width=2): r = super().__repr__() return r if len(self) < width else f"{r[:width + 1]} [...]'" @dataclass class Test: x : bytes = b"" y : bytes = field(default=b"", repr=False) z : bytes = b"" def __post_init__(self): self.z = AbbreviatedBytes(self.z) print(Test(b"aaaa", b"bbbb", b"cccc")) # output: Test(x=b'aaaa', z=b'c [...]') Best wishes, Albert-Jan _______________________________________________ Tutor maillist - Tutor at python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor From mats at wichmann.us Fri Aug 23 12:41:18 2024 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 23 Aug 2024 10:41:18 -0600 Subject: [Tutor] Dataclass question In-Reply-To: References: Message-ID: On 8/23/24 09:53, Albert-Jan Roskam wrote: > Hi, > I'm using dataclasses and one of the fields is has a bytes type. It could > be the contents of a .zip or .csv. I don't want to see so much clutter in > the logs or on the screen, so I'm looking for a neat way to omit most of > the info from the dataclass object's representation. Using the code below, > field "y" is not shown at all, which is not really what I want (but it's > nice and clean). Field "z" is more like it, but it requires more code. Is > there a better way? Maybe with pydantic? > from dataclasses import field, dataclass > class AbbreviatedBytes(bytes): > def __repr__(self, width=2): > r = super().__repr__() > return r if len(self) < width else f"{r[:width + 1]} [...]'" > @dataclass > class Test: > x : bytes = b"" > y : bytes = field(default=b"", repr=False) > z : bytes = b"" > def __post_init__(self): > self.z = AbbreviatedBytes(self.z) > print(Test(b"aaaa", b"bbbb", b"cccc")) # output: Test(x=b'aaaa', z=b'c > [...]') > Best wishes, > Albert-Jan This doesn't seem to have much to do with dataclasses. You're after a string shortener to use in whatever repr method... are you just asking about what convention to follow? Or for implementation? Many shorteners (including the stdlib textwrap.shorten) drop chars from the end and use a default placeholder of [...] (like your samples) but take an optional placeholder argument. (textwrap would be no use to you as it doesn't take bytes and only breaks on word boundaries - it's just an illustration). The unittest module also has a shortener it uses, which is a little more general - it chops chars out from in between a prefix and suffix (you can give the length of each) and inserts a counter of how much was chopped in between, so you can get an output like: prefixtext[13 characters]suffixtext Frequently the placeholder for removed stuff is included in computing the output size so if it's > SIZE and placeholder is 4 wide, you chop it so the retained text is SIZE-4, and then append/insert the placeholder. just some ideas to think about. You're just prettyfying stuff for yourself, wouldn't worry about the "requires more code" aspect. From sjeik_appie at hotmail.com Fri Aug 23 15:15:04 2024 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 23 Aug 2024 21:15:04 +0200 Subject: [Tutor] Dataclass question In-Reply-To: Message-ID: On Aug 23, 2024 18:41, Mats Wichmann wrote: The unittest module also has a shortener it uses, which is a little more general - it chops chars out from in between a prefix and suffix (you can give the length of each) and inserts a counter of how much was chopped in between, so you can get an output like ==== Aah, thanks! I never thought about unittest. This looks useful: https://github.com/python/cpython/blob/bf1b5d323bdb6b1609c6f4b31dcaed621e5d0e2f/Lib/unittest/util.py#L45. Best wishes, Albert-Jan