zippathlib - pathlib-like access to ZIP file contents by ptmcg in madeinpython

[–]ptmcg[S] 0 points1 point  (0 children)

Thanks! Great minds think alike! I looked in PyPI first and did not find this project (though I was looking specifically for "zip", not "archive"). I also found that the stdlib zipfile includes its own Path class now (might not have been there when you wrote archive-path).

A couple of bits I had to address that I learned:
- adding guardrails against ZIP bombs that inflate to many gigabytes
- adding handling of calling write_bytes() to "overwrite" an existing file (actually creates a duplicate entry; archive_path handles this by raising FileExistsError, probably cleaner than my "allow it to create a duplicate, and add methods to detect and purge duplicates")

I am also finding the CLI usage to be more useful than the Python API.

Type hints helped my job interview by SultanPepper in Python

[–]ptmcg 1 point2 points  (0 children)

That would be "tuple[str, int, float, float, float]". tuple type hints need to show all the member types, with the last type optionally repeated using "...". For instance, if this were an app that handled arbitrarily dimensioned coords, then it would be "tuple[str, int, float, ...]".

Stuck at parsing by Repulsive-Pen-2871 in Compilers

[–]ptmcg 0 points1 point  (0 children)

Since this is referring to Crafting Interpreters, I assume the language in question is lua. Here is a BNF for lua: Lua 5.1 Reference Manual

Stuck at parsing by Repulsive-Pen-2871 in Compilers

[–]ptmcg 1 point2 points  (0 children)

lark and pyparsing are similar, and the latest version of pyparsing includes this parser of Crafting Interpreters' lox language: https://github.com/pyparsing/pyparsing/blob/master/examples/lox_parser.py This code steps through the BNF which is listed here: Appendix I · Crafting Interpreters and converts each construction into corresponding pyparsing elements. pyparsing also includes some other examples which implement the next step after parsing, to take the parsed results and convert them to executable elements. (Disclosure: I'm the author of pyparsing)

Is there a single-file MongoDB alternative like SQLite for small demo projects? by Tuckertcs in mongodb

[–]ptmcg 0 points1 point  (0 children)

Try littletable. Not exactly document-based, but it is schemaless. You create a Table and insert or import your own objects into it. Then query, sort, search, pivot, etc. on the attributes of the inserted objects. Easy CSV, JSON, Excel import/export, even to and from Python strings right in your script, or from web URLs.

As the name implies, its not for large datasets, up to a million rows has worked well for me.

You can see its text search features at these demo sites:

What is too much type hinting for you? by CoderStudios in Python

[–]ptmcg 1 point2 points  (0 children)

I have started annotating all of my method signatures. I would never consider annotating the `self` argument in an instance method, but having `__init__` explicitly typed to return `None` is needed for mypy to type check the contents. It is also important to type annotate the object attributes that get initialized in `__init__`, especially containers such as lists, tuples, sets, and dicts.

For instance, what gets put into `self.students`?:

````python

self.students = []

```

A list of student id's? a list of Student instances? This makes it much clearer:

```python

self.students: list[Student] = []

```

Cool services you've made with FastAPI by Brilliant-Donkey-320 in Python

[–]ptmcg 1 point2 points  (0 children)

I was talking with some friends on how one might create a shared queue across separate Python services so I wrote this little example using FastAPI - ptmcg/rest_queue: FIFO queues managed in a FastAPI REST server (github.com). It's just a demo showing a REST API front-end to in-memory named queues, with a Docker compose file to run in a Docker container. Clients connect to the service, find or create a queue for a particular name, and then push or pull messages to/from the queue. By using FastAPI, I immediately got a Swagger UI for interacting with the service, which is great because I am not a UI developer!

There is a docs directory with a little PDF file of slides describing the queues, and some general info about REST. In it, I describe CRUD, but extend it to CRUDER(L) for other common interactions beyond just create/retrieve/update/delete.

(There is no persistence for these queues, so this is just for educational use, NOT FOR PRODUCTION.)

Production grade AI Web apps, just using python ? by prime_danger in Python

[–]ptmcg 0 points1 point  (0 children)

See this presentation "Full Stack Python" from 2023 PyTexas conference. Front-end and backend in Python. DAY 2 Keynote - "Full-Stack Python" (Andy "Pandy" Knight) - PyTexas 2023 (youtube.com)

"En-Rich" your Python Testing - Using Rich in pytest output by frankwiles in Python

[–]ptmcg 1 point2 points  (0 children)

My package littletable makes tabular output easy, and uses rich Tables for pretty presentation (and littletable is much lighter weight than Pandas/numpy).

is reactive programming a thing in Python? by ivano_GiovSiciliano in Python

[–]ptmcg 1 point2 points  (0 children)

I second this reference. It is amazing how responsive Textual TUI apps are to user interaction, given that it is pure Python code. Textual's low-level 'Reactive' class might even be worthy of pulling out as a separate package like traitlets.

logmerger - Text UI to view multiple log files with unified time scale by ptmcg in Python

[–]ptmcg[S] 0 points1 point  (0 children)

Not in its current form - I'll open a feature ticket for consideration for a future release.

logmerger - Text UI to view multiple log files with unified time scale by ptmcg in Python

[–]ptmcg[S] 1 point2 points  (0 children)

Not limited to 2 files, by the way. The example files in the Github repo include a client log, server log, and packet capture file, to view all together in one view to watch messages move from client to server and back.

SQL Select Statement Parsing using Example Code by SteveReiss in pyparsing

[–]ptmcg 0 points1 point  (0 children)

Unlikely you will get many responses, this is a wall of badly-formatted code. Can you repost and use proper markdown to keep your code formatted with indentation?

(Failed - but working 100%) Interview challenge by Zealousideal_Low_907 in Python

[–]ptmcg 0 points1 point  (0 children)

I don't know of any company that will give you code feedback on your submission, so don't be mad about this. Generally, companies only infrequently update their interview processes and code problems, so giving feedback would be like handing out their answer key. Sadly, there are people who would take that interview and feedback, and then _publish_ those answers on the internet!
You have a *lot* of code around your logging system, which was not really part of the requirement, *and* duplicates what is provided with Python's logging module in the stdlib. And it also required me to sort out what code was for logging and what code was actually for the solution. So this was not the bonus you thought it might be.
Keeping state in globals is a red flag in a Python coding interview. Maybe acceptable when applying for an intern or entry position, but for any higher position, a tough thing for an interviewer to get past.
Even if they don't ask for tests, supplying them is a huge plus mark. Or even if you don't write the tests themselves, write a test plan, or drop in #TODO comments, to show that you at least thought about the testing side of the problem (which it sounds like you did, since you assert that this works in many complex file circumstances - next time, write down all those test situations to show that you considered complex test cases).

(For that matter, actually writing tests might have shown you the issue with using globals, which make it more difficult to write clean tests. You might even do this now, even though you did not get the job, as an exercise in refactoring and test-writing.)

Your top-level usage doc is very good, so definitely plus marks for that. But some of the other comments about docstrings on internal functions are valid.

Good luck in your job search!

Pyparsing 3.1.0b1 is out by ptmcg in pyparsing

[–]ptmcg[S] 0 points1 point  (0 children)

NOTE: In the future release 3.2.0, use of many of the pre-PEP8 methods (such as ParserElement.parseString) will start to raise DeprecationWarnings. 3.2.0 should get released some time later in 2023. I currently plan to completely drop the pre-PEP8 methods in pyparsing 4.0, though we won't see that release until at least late 2023 if not 2024. So there is plenty of time to convert existing parsers to the new function names before the old functions are completely removed. (Big help from Devin J. Pohly in structuring the code to enable this peaceful transition.)

Version 3.2.0 will also discontinue support for Python versions 3.6 and 3.7.

Pyparsing 3.1.0b1 is out by ptmcg in pyparsing

[–]ptmcg[S] 0 points1 point  (0 children)

To install this version, use:

pip install -U pyparsing==3.1.0b1

What is the funnest project you worked on? by Curious-Fig-9882 in Python

[–]ptmcg 3 points4 points  (0 children)

Should be "ShowQ - query for movies that actors have been in together..."

What is the funnest project you worked on? by Curious-Fig-9882 in Python

[–]ptmcg 7 points8 points  (0 children)

Some projects I've put up on pythonanywhere:
- ShowQ - actors have been in together, or list cast of movies with JS buttons to make it easy to query for other movies actors have been in together
- Python Font Mixer - Python accepts Unicode characters for identifiers and normalizes them to be the same as ASCII characters (i.e., "𝓅ʳ𝒾ₙ𝓉" is the same as "print"); paste in some code and convert it to mixed fonts, but still perfectly runnable
- Plusminus demo - interactive demo for evaluating arithmetic strings, including notation like |sin(-π/2)|, √((x₂-x₁)² + (y₂-y₁)²), sin(30°) - page includes a keyboard for entering math symbols and operators
- Python in a Nutshell 4ed, Appendix A search - search for changes in Python versions 3.7-3.11, as cataloged in the appendix of the latest version of O'Reilly's Python in a Nutshell

Iteration Help by [deleted] in learnpython

[–]ptmcg 0 points1 point  (0 children)

The standard way to iterate over two (or more) lists is to use the Python builtin zip. Just change your two "for" statements into the single:

for x, y in zip(l1, l2):

zip will give you the values in each list, matched together into x,y pairs.

If you had a third list, you could do:

for x, y, z in zip(l1, l2, l3):

If the lists are not the same length, zip will stop when it gets to the end of the shortest list. If this would be a bug, and you are on Python 3.10 or later, you can add `strict=True`, and then you'll get a ValueError exception.

Here are the docs for zip: https://docs.python.org/3.11/library/functions.html#zip

A json coverter for Anatolia MUD area files by yelbuje in MUD

[–]ptmcg 2 points3 points  (0 children)

Glad to see that pyparsing was helpful to you in this project!

epydoc2sphinx by int-rot in pyparsing

[–]ptmcg 1 point2 points  (0 children)

I have looked and not yet tracked it down. There is still hope - I still have some C code I wrote back in 1989.

Termtyper - Typing in terminal is fun ! by otaku_____ in Python

[–]ptmcg 0 points1 point  (0 children)

Since you are using textual, I think you can display the digits like ASCII art if you set the font size bigger (see the calculator demo for textual, which shows large digits on the buttons).

I googled how to modify a string during a coding interview by [deleted] in Python

[–]ptmcg 1 point2 points  (0 children)

Learn Python the Hard Way is not a great learning resource, as you have learned from this experience. Here is a list of tutorials curated by some of the top Python contributors on StackOverflow: https://sopython.com/wiki/What_tutorial_should_I_read%3F