Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Zoracle Zed
Jul 10, 2001

QuarkJets posted:

If a User can belong to multiple Groups then the only type annotation that you need is probably `list` anyway - User doesn't need to see any Group code at all

what? you'd still want it as list[Group].

Adbot
ADBOT LOVES YOU

Zoracle Zed
Jul 10, 2001

huhu posted:

I want to import project into demos. However, when I cd into the demos directory and try and run any variation of import statements, I get various errors. I've Googled a bunch and I cannot figure out what's wrong with my import. Or is there a better way to make a demos directory for a package I'm building? One of the stack overflow answers says
code:
If the directories aren't Python packages, you can do this by messing around with sys.path, but you shouldn't.

So I feel like I'm missing something here.

You'll probably want to follow a guide like this. This will allow you to install the project path permanently to the python path. In short:

1. Create a 'src' subfolder in the root folder and move the project folder there
2. Create a pyproject.toml file in the root folder and add the appropriate contents
3. In the root folder, run 'pip install --editable .'

Then 'python demos/demo1.py' should work as expected. (The --editable part means you don't have to reinstall everything everytime you modify the code)

Zoracle Zed
Jul 10, 2001

Falcon2001 posted:

So the question: What's the correct (or at least painless) way to store (and ideally visualize) a 2d cartesian grid where each coordinate can be an arbitrary data type? I'm not looking for code golf style solutions, as I'm using these problems as ways to explore concepts/etc, and so it's more useful to have something that I can dig through and visualize/debug/interact with than a perfect impenetrable one-line solution.

a dict or defaultdict with a tuple of ints as the key type would be my first try

eta: not great for visualization though

Zoracle Zed
Jul 10, 2001

Falcon2001 posted:

Yep, exactly. I'd love to be able to visualize these setups quickly like they do in the explanations (which I've sort of got working with my PIL solution) here's what one of their example explainers looks like:

the ascii grid isn't too bad:
code:
grid = {}
grid[0, 0] = 'O'
grid[-2, 1] = 'B'
grid[0, 3] = 'x'
grid[2, -2] = '#'

for y in range(4, -4, -1):
    row = (grid.get((x, y), '.') for x in range(-4, 4))
    print(''.join(row))

........
........
......#.
........
....O...
..B.....
........
....x...
........
........

Zoracle Zed
Jul 10, 2001
I believe stopping time in this context simply means the number of steps taken. obnoxious itertools solution:

Python code:
from itertools import takewhile, accumulate, count
from random import gauss

walk = takewhile(lambda x: abs(x) < 3, accumulate(gauss(0, 1) for _ in count()))
stopping_time = 1 + sum(1 for _ in walk )

Zoracle Zed fucked around with this message at 19:42 on Nov 11, 2023

Zoracle Zed
Jul 10, 2001
are you responsible for anonymizing PII? stay the hell away imo

Zoracle Zed
Jul 10, 2001
Maybe check out the 'sliding_window' iterator from the itertools recipes, which continues to drive me insane for not being importable but instead requires copy-pasting.

Zoracle Zed
Jul 10, 2001
have you read the building a git clone documentation? I've that used that approach a lot, where the base command has the @pass_context decorator and stashes a custom dataclass in ctx.obj, and then the subcommands have the @pass_obj decorator to recieve the dataclass object directly.

Zoracle Zed
Jul 10, 2001

Falcon2001 posted:

I'll take another look. I thought this method involved having group options which necessitated breaking your cli args up in a weird way ex: (command group --opt-one subcommand --opt-two) but I might have misread it.

yeah you end up with an api like

code:
butt --fart loud --n-turds 3 poo poo --no-flush
where the base 'butt' command doesn't really do anything except collect the common arguments and the subcommand 'poo poo' does the actual work and accepts the specialized args. I think git is the only real-world cli I use that works like but i find it pretty natural, ymmv

Zoracle Zed fucked around with this message at 03:47 on Dec 13, 2023

Zoracle Zed
Jul 10, 2001
Anyone got opinions about API docs generation? I kinda hate sphinx for being insanely over-configurable and writing rst feels like unnecessary friction. Sphinx with numpydoc is managable but I still feel like there's got to be something better.

Zoracle Zed
Jul 10, 2001

Oysters Autobio posted:

FastAPI swagger page generation is pretty cool but it's not like a drop-in or anything to my knowledge (ie you have to build the API with it from the beginning).

I've been exploring python docs stuff and have found that mkdocs and mkdocs material have a big ecosystem of plugins and the like, all built on markdown instead of rst. Might have some API docs gen options.

Thanks for this by the way! I've been playing around with it and like it a lot. Markdown instead of rst is wayyy more ergonomic for me and `mkdocstrings` is the plugin does the automatic API docs generation exactly like I'd want it to, including out of the box support for parsing type annotations from function signatures

Adbot
ADBOT LOVES YOU

Zoracle Zed
Jul 10, 2001

Oysters Autobio posted:

Is there a particular 'style' of python that leans towards tables and similar relational data rather than slinging everything around in key:value pairs, lists etc. I've been finding it hard to get imperative styles to click in my head when I'm so used to how "connected" All the data is within a SQL statement for example. Like is there a way to manage data in python script basically create dimensional tables of data that you need and join em as needed.

Slinging around pandas/polars DataFrames I guess? The polars example here is pretty neat. I think static typing this kind of stuff is still going to be an uphill battle, but I'm not up to date.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply