|
D34THROW posted:I cannot for the life of me remember the name of the tool I used which walked your code and created a requirements.txt based on what was actually used. Like...someone running my app doesn't need black or flake8 and poo poo like that. Correct that’s why you can specify those requirements in a requirements_dev.txt file for those who would contribute to your project but not for running in production. I haven’t gotten into poetry yet seems like a lot of overhead that hasn’t been widely adopted yet. What can it do better that I can’t achieve with pyenv and pinned reqs files?
|
# ? Apr 4, 2022 20:27 |
|
|
# ? May 14, 2024 04:19 |
|
Foxfire_ posted:I'm having trouble thinking of something that's actually useful for. Display code would want some application-specific approximation instead of the exact values (humans usually don't want to be told that "0.1" is 3602879701896397 / 36028797018963968 instead of 1/10). And if you were doing arbitrary precision math, you shouldn't have floats to begin with Fractional inches. I just had something happened that has never happened to me before. I'm following the first-fit descending algorithm here and adapting it to fit my needs as follows. The first function calls the second, and it caused an infinite loop or memory leak. I'm trying to determine exactly where. Python code:
D34THROW fucked around with this message at 20:47 on Apr 4, 2022 |
# ? Apr 4, 2022 20:31 |
|
D34THROW posted:The first function calls the second, and it caused an infinite loop or memory leak. I'm trying to determine exactly where. Edit: Looked at the original FFD function. The problem with your code is that the "else:" block is on the inner-most "if". It's supposed to be on the inner-most "for" (the infrequently-used for/else clause). ExcessBLarg! fucked around with this message at 21:17 on Apr 4, 2022 |
# ? Apr 4, 2022 21:07 |
|
D34THROW posted:Fractional inches. For the cut list, a straightforward debugging method is to print out stuff and see where what actually happens splits from what you think happens: code:
The else path on that doesn't make sense to me glancing through, the piece doesn't fit into the freespace, but it's messing with the solution and remaining freespace
|
# ? Apr 4, 2022 21:17 |
|
The March Hare posted:Something like Poetry will keep your requirements in separate files - one will contain packages that are top-level required, and then a lockfile with those packages deps. Also, pipenv or venv or... god there's a bunch of them, huh punk rebel ecks posted:So I finally finished my pokedex project. Definitely learn about virtual environments; generally Python projects each use their own virtual environment to keep projects that need two different incompatible versions of a package kind of isolated from each other. It also helps with making the requirements.txt file like as mentioned before - you don't have to manually pare out anything the project isn't using.
|
# ? Apr 4, 2022 21:24 |
|
Data Graham posted:And while this will do for a quick-n-dirty first pass, ideally you would want to go back and weed out all the things that got installed that aren't strictly "requirements" for your project and that you don't care about pinning. I think of environment handling from two perspectives: 1) the minimum packages required to install and use a package vs 2) a frozen, tested environment. The first should be handled via a setup.cfg or pyproject.toml that specifies as few packages as possible using the loosest version requirements possible. The second should be a conda.yaml or requirements.txt dumped from `conda list` or `pip freeze`. D34THROW posted:I cannot for the life of me remember the name of the tool I used which walked your code and created a requirements.txt based on what was actually used. Like...someone running my app doesn't need black or flake8 and poo poo like that. pipreqs does this, it's pretty cool
|
# ? Apr 5, 2022 05:04 |
|
punk rebel ecks posted:So I finally finished my pokedex project. I didn't review your code because it's in a zip file, sorry
|
# ? Apr 5, 2022 05:15 |
|
QuarkJets posted:I didn't review your code because it's in a zip file, sorry I’ll fix it into the correct format and ask again in two weeks. I’m on a trip right now.
|
# ? Apr 5, 2022 05:40 |
|
I appreciate the help y'all. It generates the cutlists now and the next step is to make it calculate the material required. From there, I have to go back to any classes that involve cut material and modify them to do, say, self.add_to_cutlist("PT 1 X 4 X 8", 37, 2) instead of self.add_to_dict("materials", f'PT 1 X 4 X 8 @ {length}"', 2. Then Sometimes I hate the end of the day because I have something in my head and then forget it 16 hours later when I start up again.
|
# ? Apr 5, 2022 14:45 |
|
D34THROW posted:
May I introduce you to dict.get() to simplify this? https://python-reference.readthedocs.io/en/latest/docs/dict/get.html
|
# ? Apr 5, 2022 20:12 |
|
Slimchandi posted:May I introduce you to dict.get() to simplify this? I use that comprehension so many times and you've just made my life easier, holy poo poo!
|
# ? Apr 5, 2022 20:17 |
|
Is there something like a "semiautomatic automation" framework in Python? I'd like to script something that has to break off at points for manual intervention, resume, and recover from goofiness that can come from that. I figured I could scribble together my own thing with that but the Python community has all kinds of goofy things. I was figuring something like this would be like a re-entrant state machine and I'd be scripting the transitions and what happens with them. The state would be saved off when it exited and reloaded to continue at a spot.
|
# ? Apr 7, 2022 06:17 |
|
I'm at the end of my loving rope here. I'm refactoring my cli.py file into manage.py and I've added the #!usr/bin/env python shebang to the top line of the file, but in order to actually do anything with it at the terminal, I have to type ./manage.py. What I want to be able to do is manage <args> like, say, black or flask or flake8. How are those able to do it? I'm looking at the source on GitHub but I can't figure it out.
|
# ? Apr 7, 2022 17:16 |
|
D34THROW posted:I'm at the end of my loving rope here. You're looking for entry points in setuptools https://setuptools.pypa.io/en/latest/userguide/entry_point.html This is where flake8 configures it https://github.com/PyCQA/flake8/blob/3ce76158a0e18605e9701bd3a2a25716fea411de/setup.cfg#L51
|
# ? Apr 7, 2022 17:26 |
|
Rocko Bonaparte posted:Is there something like a "semiautomatic automation" framework in Python? I'd like to script something that has to break off at points for manual intervention, resume, and recover from goofiness that can come from that. I figured I could scribble together my own thing with that but the Python community has all kinds of goofy things. I’m kinda confused as to what someone would make that wouldn’t just be typing those rules into code? I use AWS step functions to define a state machine that runs lambdas based on business rules. Important bits like max concurrency and error handling are reliable. I do a similar thing with zapier for simple flows. All those are things that require internet connected code to run though.
|
# ? Apr 7, 2022 17:28 |
|
Zephirus posted:You're looking for entry points in setuptools Yeah that looks like it. Do I have to reconfigure my ./manage folder as a module and run setup,py before I can make this work? EDIT: Holy gently caress, I did it. Thank you! Now I think I'm starting to understand packages a little more. But it doesn't ultimately work because it needs access to the app context of my flask app. Back to bash aliases D34THROW fucked around with this message at 18:08 on Apr 7, 2022 |
# ? Apr 7, 2022 17:39 |
|
D34THROW posted:What I want to be able to do is manage <args> like, say, black or flask or flake8.
|
# ? Apr 7, 2022 17:39 |
|
D34THROW posted:Yeah that looks like it. Do I have to reconfigure my ./manage folder as a module and run setup,py before I can make this work? if you don't have it set up with setuptools already then I would follow this advice: ExcessBLarg! posted:You have to copy the file into one of the directories specified by $PATH. Assuming you're on a unix-alike you would rename the manage.py file to manage and set it as executable mv manage.py manage; chmod +x manage You then have to put it in a folder in your PATH environment variable (or add a path to it to your environment). The shebang tells the shell what to call to execute the file (it doesn't look at the file extension). Note this doesn't work on windows outside of WSL.
|
# ? Apr 7, 2022 18:01 |
|
I gave the gently caress up on it because a module can't access the overall app context for Flask. Instead, I'm doing away with manage.py, moving everything into the main .py file I use for Flask, and doing everything with the CLI through that. Which brings me to my next moment looking at myself a year ago learning Python. Instead of doing 19 different parser.add_argument() calls, I'm looping over a dict of dicts that defines the arguments, the functions to call, and the help text. Doing this with a pair of subparsers for tests and db_func, with an additional run argument to actually run the server. I'll post code if anyone's interested in telling me how bad it is. Or I'll shut up if I'm boring y'all. Maybe this all belongs in project.log
|
# ? Apr 8, 2022 17:22 |
|
Question about Python style/best practice - for context, I teach Python to newbies at a bootcamp and I'm trying really hard to get them to do things correctly the first time around instead of them getting jobs and having all their coworkers bitch about how they can't code properly: The following code works, because the attributes for an object are basically just a dictionary you can gently caress around with however you want: code:
|
# ? Apr 12, 2022 17:36 |
|
I'm not an expert enough to speak authoritatively on this in any manner, but I also imagine in that scenario that IDEs would have trouble picking up on the fact that SampleClass has a new_attribute so that might also induce some development difficulties with that specific class.
|
# ? Apr 12, 2022 17:46 |
|
death cob for cutie posted:I'm trying really hard to get them to do things correctly the first time around instead of them getting jobs and having all their coworkers bitch about how they can't code properly I've got some bad news for you about everyone, everywhere
|
# ? Apr 12, 2022 19:01 |
|
oh it's an impossible task because no two people can agree on what is right outside of a vacuum, and everyone thinks everyone else is an idiot, but I should at least try to smooth out the real bad parts
|
# ? Apr 12, 2022 19:55 |
|
I use flake8 and black so I don't have to think about that poo poo. For the most part, flake8 only catches dumb poo poo (like trailing whitespace) and black cleans up poo poo I can't be bothered with, like long comprehensions and statements.
|
# ? Apr 12, 2022 21:22 |
|
death cob for cutie posted:Question about Python style/best practice - for context, I teach Python to newbies at a bootcamp and I'm trying really hard to get them to do things correctly the first time around instead of them getting jobs and having all their coworkers bitch about how they can't code properly: It's bad practice, yes. There's virtually no good reason to do this. Classes should be well defined, and defined once.
|
# ? Apr 12, 2022 22:02 |
|
death cob for cutie posted:From my understanding though, it's a bad idea to just assign attributes to instances of a class willy-nilly, because then there's no guarantee that all instances of a class have the same attributes. Python code:
ExcessBLarg! fucked around with this message at 04:48 on Apr 13, 2022 |
# ? Apr 13, 2022 04:24 |
|
ExcessBLarg! posted:Thought exercise: How is this really any different? This implementation defines a new class and is self-documenting, the other does not and is not. QuarkJets fucked around with this message at 04:53 on Apr 13, 2022 |
# ? Apr 13, 2022 04:44 |
|
QuarkJets posted:This implementation defines a new class and is self-documenting, the other does not and is not. Well said.
|
# ? Apr 13, 2022 07:38 |
|
QuarkJets posted:This implementation defines a new class and is self-documenting, the other does not and is not. I'd argue the biggest issue here is that Python, by having all attributes be public and (easily) assignable outside of the defining context can lead to a situation where an inexperienced programmer might adopt non-idiomatic--but functionally OK--style.
|
# ? Apr 13, 2022 14:15 |
|
CarForumPoster posted:I’m kinda confused as to what someone would make that wouldn’t just be typing those rules into code? As an example, the user at some point has to cherry pick a bunch of commits that cause merge conflicts and resolve them. That process can be non-trivial and span days. I'd like them to be able to resume there. There are a few things like that which can span a few days of interactive work.
|
# ? Apr 13, 2022 20:04 |
|
I am having an absolute bitch of a time with a problem I am going to have a hard time explaining, but here goes. I'm using Flask-Security, but all the examples use a single module to hold everything. What I am trying to do is have user_datastore globally available. To do that, I'm putting as a module-level variable in the app's __init__.py file, which also contains the app factory. I can't set user_datastore at the module level until it's set in the app factory - because I need the db object that isn't created until , but setting a user_datastore variable in create_app doesn't change the module-level init. I need a way to set the __init__.py level variable from within a function and I am out of my loving mind on how to do it. EDIT: Here's the dumb hacky poo poo I'm trying now. Python code:
code:
D34THROW fucked around with this message at 21:05 on Apr 13, 2022 |
# ? Apr 13, 2022 20:26 |
|
I have a best practices question. Preface: I’m working in Django and DRF. I try to keep any complex business logic in services.py and call those functions from my DRF views. DRF serializers are great because they can pass validated data to a function with the following syntax code:
Example code:
I certainly don’t want to pass each value as it’s own arg. I have functions that created 4-5 nested models so the number of args gets large quickly lazerwolf fucked around with this message at 20:38 on Apr 13, 2022 |
# ? Apr 13, 2022 20:33 |
|
D34THROW posted:I am having an absolute bitch of a time with a problem I am going to have a hard time explaining, but here goes. Each module has its own scope. When you import from one module to another, those values are copied to the new scope. Altering that new variable, even via globals(), will not alter the variables that exist in another module's scope. Even if you could do this, you absolutely shouldn't anyway; this kind of design is incredibly frustrating to try and debug when problems occur. I don't know what the examples you're seeing look like, but if they're doing things like this then you should look for new tutorials. Why do you need a global user_datastore variable? Just pass it around to whatever objects need it. Stick it in a class and pass that around instead, if you want
|
# ? Apr 14, 2022 00:32 |
|
lazerwolf posted:I have a best practices question. If you have a bunch of grouped-together data that you're using over and over, then that sounds like a slam dunk case for a dataclass. I don't think "overkill" is the right way to describe this, it's likely going to make your code a lot simpler to read and write once you've defined the object. "I have these 5 values that a bunch of different functions need" is totally dataclass territory
|
# ? Apr 14, 2022 00:40 |
|
Is it best practice to have some python packages installed on the system python for programs that you don't really use in a project but instead use kind of like command line utilities? I mean rather than having them installed from a virtual environment. For example, I have yt-dlp installed for downloading youtube videos, or dte for doing date calculations on the fly. I just have these in my system python and it seems to be working ok so far.
|
# ? Apr 14, 2022 00:44 |
|
QuarkJets posted:If you have a bunch of grouped-together data that you're using over and over, then that sounds like a slam dunk case for a dataclass. I don't think "overkill" is the right way to describe this, it's likely going to make your code a lot simpler to read and write once you've defined the object. "I have these 5 values that a bunch of different functions need" is totally dataclass territory absolutely agreed, because then you can also annotate your functions as accepting objects of that type, and then you can run one of the static type checkers to give you red squiggly lines if you ever screw that up Sleepy Robot posted:Is it best practice to have some python packages installed on the system python for programs that you don't really use in a project but instead use kind of like command line utilities? I mean rather than having them installed from a virtual environment. For example, I have yt-dlp installed for downloading youtube videos, or dte for doing date calculations on the fly. I just have these in my system python and it seems to be working ok so far. I use a ton of python-based utilities at my job, which is being a janitor for computers, and the thing I usually do is have pyenv set a version inside of my "junk drawer" folder that all of my stuff uses. I never install anything to the system python on purpose.
|
# ? Apr 14, 2022 01:39 |
|
12 rats tied together posted:absolutely agreed, because then you can also annotate your functions as accepting objects of that type, and then you can run one of the static type checkers to give you red squiggly lines if you ever screw that up This was my intent. I’d like to ensure the “demographic” dict has a certain form. This might be the only function that would use the dataclass but I want to utilize serializer functionality in non DRF context.
|
# ? Apr 14, 2022 01:57 |
|
lazerwolf posted:This was my intent. I’d like to ensure the “demographic” dict has a certain form. This might be the only function that would use the dataclass but I want to utilize serializer functionality in non DRF context. If a dictionary leaves the scope it was made in, it's a good candidate for sticking in a data class, IMO. I took over some software and we have a couple places where it's just like code:
|
# ? Apr 14, 2022 05:48 |
|
Sleepy Robot posted:Is it best practice to have some python packages installed on the system python for programs that you don't really use in a project but instead use kind of like command line utilities? I mean rather than having them installed from a virtual environment. For example, I have yt-dlp installed for downloading youtube videos, or dte for doing date calculations on the fly. I just have these in my system python and it seems to be working ok so far. Most linux flavors ship with a system python (and make a ton of python packages available via yum or apt) for exactly this reason. Python is pretty handy and has a lot of cool stuff built from it, so it's reasonable to make that stuff available from a standard system location for multiple users to use. So if you have some Python package that you want to make available to your users, especially users who aren't doing their own development, putting it in the system location is a-okay in my opinion. Falcon2001 posted:If a dictionary leaves the scope it was made in, it's a good candidate for sticking in a data class, IMO. I too am flummoxed when I come situations where dicts are being passed around. It's not ideal, even when the dict is documented someplace (and let's face it, the documentation will wind up being full of lies at some point, if not immediately). It works fine enough obviously, you can robustly handle missing keys and whatnot, but it just feels a lot more fragile and harder to maintain.
|
# ? Apr 14, 2022 06:11 |
|
|
# ? May 14, 2024 04:19 |
|
HI! I have a SQLAlchemy question about getting additional data from an association object. The gist is that I have threads and users and I want to get total posts read and last post ID read from an association object given a user ID The context for the issue I'm trying to solve is located at this post in the SQL thread: teen phone cutie posted:Not sure if there's a better thread for this, but I have a performance questions re: a personal project I'm working on: What do you people think is the most performant way to do the "unread count" for threads that Something Awful has? Talking about this thing: And now I've begun implementation So after some reading through the SQLAlchemy docs, I've come to the conclusion that since I need an association table with additional data, what I need is an association object: https://docs.sqlalchemy.org/en/14/orm/basic_relationships.html#association-object So now my models look something like this: Python code:
So far, my GET /threads logic looks like this Python code:
JavaScript code:
JavaScript code:
teen phone cutie fucked around with this message at 07:12 on Apr 14, 2022 |
# ? Apr 14, 2022 06:32 |