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
Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
I have a weird python question.

I've been having weird internet outages, so I whipped up a little program that pings a given URL once every second, then logs any errors with a timestamp to a file. For the purposes of having a tiny visual to go along with it, I have it print a '.' for successes, and a '!' for failures to the console. This works fine in, say, the VSCode console, but it doesn't update at all when I run it in the windows commandline or powershell through python.

When I had entire sentences for success/failure, it worked fine. If I make it so it logs a newline after every character, it also works fine (but does seem to only update every two characters?). Googling lead me to some weird regedit discussions on stackoverflow, but it didn't result in anything.

For examples:

Not working:
code:
while True:
    time.sleep(1)
    if ping(target) == None:
        logging.warning('Ping to '+target+' failed!')
        print('!', end="")
    else:
        print('.', end="")
Working:

code:
while True:
    time.sleep(1)
    if ping(target) == None:
        logging.warning('Ping to '+target+' failed!')
        print('!')
    else:
        print('.')
Any ideas?

Adbot
ADBOT LOVES YOU

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

QuarkJets posted:

Does it work if you use other characters, such as 'a' and 'b'?

No, doesn't change it.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

cinci zoo sniper posted:

I’d recommend hacking tqdm like so for this use case.

Hey cool, I'll check it out!

For the main problem, mostly I'm just wondering if there's some weird python rule I'm not aware of (or alternately, weird console interaction I'm not aware of).

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

Thermopyle posted:

Yeah, anytime you have weird issues with stuff not updating in the console like you think it should start looking for the flush options.

Foxfire_ posted:

You're writing to stdout and it's line buffered by default. It won't flush to the OS unless a buffer fills up or you write a newline.

use print(whatever, flush=True)

Ah, thanks! That totally fixes it.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
I managed to land my first dev title (half dev, half my current specialty) in a mostly Python group at a big company. I know the first rule of software engineering is 'do what your team does as long as it's not insane' but are there any other tips in terms of like real-world stuff I should consider?

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
Yeah, the way selenium interacts with the browser seems to rely on debugger functions that aren't generally on - you have to launch chrome specifically to allow Selenium to control it, for example. More info on the use case can help because I might be doing something similar.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

uguu posted:

That's a good idea and possible.

I made a program, a script really, which copies text to a folder. I highlight some text, press windows-q, a popup appears and I enter a twoletter code to select the folder.

If I copy text from a browser I'd like it to add the URL automatically. It can kind of detect whether I'm copying from a browser ('firefox' in windowname), but getting the URL is an ordeal.

Edit: an other suggestion was to read the JSON session file. I dismissed it at first because Mozilla moved to a propietary json4lz format. But I found this
https://gist.github.com/Tblue/62ff47bef7f894e92ed5
which should unpack it. I'll try that today.

Edit2: I got it working! I'll throw it up on GitHub in case it's useful to you. Pretty Jacky though.

I wonder if a greasemonkey script might be able to do that. It ain't python though.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
On the topic of unit tests, are there any good books or sites on how to retrofit an existing codebase with unit tests, especially one that's reasonably large (around 8k SLoC) and involves a lot of external calls? I know that generally it's going to boil down to 'chunk it apart and start working on pieces' but it'd be nice if someone had already written some stuff from the perspective that I'm going into.

Most of the stuff I've read highly leans into test driven development, which is a good paradigm, but I'm working on an existing product I didn't start on. We have a backlog item to write some unit tests later, and I'm interested in doing that.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

qsvui posted:

Sounds like Working Effectively with Legacy Code by Michael Feathers might help. It doesn't use Python but I think the advice should be generally applicable.

Book's on my buy list, but I suspect most of it won't be applicable; this codebase is only a year or two old, it's just big enough to be a pain to retrofit testing in.

Edit: Looking around, actually I think this book is actually probably the right answer. Thanks! I picked it up.

Falcon2001 fucked around with this message at 02:36 on Jan 10, 2022

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

D34THROW posted:

It's ridiculous how :neckbeard: I get over a simple half-functional login page in Flask that centers the form on the screen and pins the header to the bottom. If I can get this poo poo on a Heroku instance and spread it around the company I'm gonna be quite happy and make a new name for myself other than "the Excel toucher" and "the NAV geek".

This was me earlier today when I managed to automate the manual generation of some reports for work.

Until about 4 hours later when I discovered a minor discrepancy in a 110mb csv and now I'm having to go back to the datasource all over again.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

former glory posted:

That link is a pro click.

I don't have a compsci background but am a dev, and I think that link is pretty great. I've been watching a lot of stuff around the arguments around OOP and this article does a great job of encapsulating some of my confusion around those arguments.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
I just discovered https://www.attrs.org/, has anyone used this in a shared environment? I'm torn between 'wow this looks amazing' and 'huh, I wonder if this is going to make readability weird for folks that aren't familiar with attrs'.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

QuarkJets posted:

What kind of functionality are you looking for specifically? I'm looking at https://www.attrs.org/en/stable/examples.html and https://www.attrs.org/en/stable/why.html

It sounds like attrs was extremely useful before dataclass was defined, but now it's sort of extraneous unless you need very specific extension features that dataclass doesn't provide. That's edge-case territory, so you may need attrs for a specific project but most of the time you'd be better off just using dataclass.

e: Obligatory link to dataclass in Python docs.
attrs would be very useful if you were forced to use older versions of Python. Please do not use older version of Python

To start, nope, not using older versions of python, we're in late 3.X territory (3.7 I think?) and security won't let us fall behind into the terrible world.

https://hynek.me/articles/import-attrs/ this goes into some of the reason why attrs still exists in a world with dataclasses, which apparently were built from attrs in the first place, but I suppose the other point is that in most cases dataclasses probably does most of what I'd use attrs for and is standard library; I've even used dataclasses on a project recently.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
It's not unreasonable or uncommon in my experience to have a function in a class that outputs a specific datatype for other use (as_dict, as_list, etc). I wouldn't necessarily throw all the formatting logic in there, because I think you risk overcrowding the class, but then again I just did that myself in a reporting project.

In general, probably good to avoid having to double refer to data (maintaining a list of keys and values outside of the relevant class, etc) but I suspect others in here would have better advice.

Also: Nthing the recommendation for typehints. They're an absolute lifesaver for saving you one more run when you forgot something simple like a return/etc, and they're not that hard to include. https://www.pythontutorial.net/python-basics/python-type-hints/ seems like an alright intro, and it makes your IDE a ton more readable.

Falcon2001 fucked around with this message at 19:19 on Feb 7, 2022

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

Dawncloack posted:

I have to backfill information into an SQL database, and I am writing a python script for it.

I depend on some other piece of software to send unix timestamps to (and other info) and then get the info to backfill from it.
This program offers me two options: To get an old date and give me the data from that date or ask for real time information and get this exact moment's data.

I have a problem tho: The real time information has two decimals of precision that the old info does not.

What would be the easiest way to change my system's time a buncha times so that, combined with the other info, I get the better precision ?

Thanks!

edit: I am thinking it might be easier to change the information I feed the program and pretend it's all from right now.

Can you just modify the data you get to or from that program? Because modifying timestamps to add precision (even fake precision) is probably a lot easier than figuring out a way to muck with your system time programmatically, although I'm sure there's a way to do it.

Maybe give some examples of the input/output data?

Falcon2001 fucked around with this message at 03:27 on Feb 13, 2022

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
https://www.freecodecamp.org/news/truthy-and-falsy-values-in-python/ This is probably a pretty decent coverage of 'truthiness' in Python; python allows you to test some things.

If you want to check if the variable is an integer, DefeatistElitist has the right idea.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
Some more details, now that I review your code:

- Input() returns a string, so you'll need to try and cast that to an integer to do division. You probably want to add a try/catch clause to do like
code:
int(user_num)
and see if that fails - if it does, you can have the user try again or just display a friendly error.

Think about the flow there as well. You want to do a few things - Validate that the inputted numbers are integers, then ensure that the second number is not zero, then you can safely divide and return the value. I can be more explicit but I'm assuming you don't just want a response with 'here's the answer'.

Some references.
https://docs.python.org/3/tutorial/inputoutput.html
https://docs.python.org/3/tutorial/errors.html
https://www.programiz.com/python-programming/type-conversion-and-casting

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

abelwingnut posted:

so i'm trying to get python running on my win10 machine. what's the best way? this windows subsystem for linux seems pretty nifty but it also feels like it could be a disaster. as of now, i'm only trying to do web stuff, but could see myself doing more machine learning things.

e: or do i even want to try? i guess i could pretty easily deploy a linux vm on azure and just run everything there. might be the best idea given this machine is also my personal.

Don't get it from the MSStore, for whatever goddamn reason it has some weirdness with PIP and installers and things, just get it from Python.org. Seriously, just get the installer and make sure to click the 'add to path' option and you're gold.

If you're just dicking around, you don't need to worry about pyenv or virtual environments or anything like that, until you get to the point where you're trying to pass code around to other people or package it/etc, and at that point you can always then sit down and do it.

WSL2 is rad, but it's also not really a problem for Python; Python and Linux go hand in hand because a lot of linux distros come with Python so it's sort of a 'known value' in the environment, but it works just fine on Windows.

VSCode has great support for Python btw, and does integrate into pyenv and other things when you get to that point.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

QuarkJets posted:

That's a bad reason

God I cannot count the number of times I've just been blinking at something I know I wrote a week ago. I've started making it a habit to improve docstrings even if I'm not heavily modifying the function.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

QuarkJets posted:

Yeah this PEP has pretty good guidelines

https://www.python.org/dev/peps/pep-0257/

One thing I love about Python is how consistently people seem to adhere and agree to PEP8 and other style guide stuff. Like I dunno, I never noticed this when working on C#, although it's possible I was just new enough to not know it.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

QuarkJets posted:

Yeah comments should actually be pretty uncommon imo, the names of functions and variables should make clear what is happening.

Also, don't use the names of builtins for variable names: id and type are verboten. The IDE you use should identify this

In the hierarchy of best practices, over-commenting is still a lesser evil than a lot of other options though.

I do generally agree though with most of those being superfluous. timestamp is pretty clear (or created_time if you want to be more explicit), and I would only add comments on anything that's weird enough that you can't easily represent it with a nicely specific variable name.

Edit: Also, I think that function/method docstrings are way more useful in terms of documentation than individual variable comments.

Falcon2001 fucked around with this message at 23:25 on Mar 9, 2022

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

teen phone cutie posted:

huh interesting. even more interesting that the sqlalchemy docs don't even mention this:

https://docs.sqlalchemy.org/en/14/orm/mapping_columns.html

So if you want your column name to be "id," this is preferred?

Python code:
user_id = Column('id', Integer, primary_key=True)

Yeah, in general you want to avoid reusing any already used variable names from the standard library. IDEs should warn you about this if you're using one, so naming something list, id, type, etc should all give a warning because you're overwriting it. In theory you can do it, but it can cause weird behavior or straight up bigger problems so it's a good idea to avoid it whenever possible. It's kind of wild that they just don't mention it in their docs, but welp.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

Protocol7 posted:

It's probably fine on a class, if not a bit of a code smell - PyCharm correctly flags a global variable shadowing the builtin, but doesn't care at all in a class.

I think the idea being that you'd always access it as object.id instead of just plain id.

Oh, hey that's a good point actually, I hadn't considered that.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

Sleepy Robot posted:

I'm trying to piece together a script to automatically adjust screen brightness settings based on a user's location. So far I have it working with hardcoded lat/long values, but I'd like the user to input a city / state and it accurately determines the intended location (lat/long is required for sunset module) or at least offers a set of possible matching cities before converting to coordinates. Is there an API or package that can do this? I'm thinking Google Maps could probably handle it but maybe there's a better approach.

https://openweathermap.org/price looks like it has a free tier, which depending on how much calls you're making should be fine.

Ninja Edit: https://openweathermap.org/api/geocoding-api it has a geocoding api, it's not just for weather.

Ninja Edit 2: https://geopy.readthedocs.io/en/stable/ It looks like there's a python library for interacting with geocoding apis too, which might save you a little work.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

12 rats tied together posted:

If you have unique ids that would scream set difference to me, which is what you said yeah

edit: there's of course like 2 dozen other things that are wrong with it, but, i guess one of the nice things about python is that you can fall back to list index nonsense if you didnt bother to read any of the documentation

Agreed on set difference - sets are great for when you're trying to do unique IDs of things, and you can use them pretty lazily to just dedupe a list. (as long as comparison/etc is possible between the list objects, etc etc. There are edge cases.)

code:
de_duped_list = list(set(list_of_stuff_with_duplicates))
So really you can probably do that code with this, assuming I didn't miss some use case there.

code:
set_one = set(GeneList)
set_two = set(GeneList2)
return list(set_one.Difference(set_two))

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
So I have a bit of a best practices question. In the event that you have a function that mutates a data structure like a list/etc, is it best practice to return the mutated version, or to just make it clear in the docstring that the function mutates the object? For the sake of argument, let's assume that this isn't a library or other externally facing function and is pretty tightly bound business logic specific to a situation, where you're separating code out into functions to improve readability/etc.

code:
big_dict = retrieve_data()
remove_butts(big_dict)
vs
code:
big_dict = retrieve_data()
big_dict = remove_butts(big_dict)

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
Thanks for the feedback! I think the biggest takeaway is that it should be clear, and I properly type hint all my functions/etc, so it's clear that this doesn't return anything (-> None), which means I think I'm going in the right direction.

I also agree with the nicest option being the 'make it a class and then have a method that does the thing to itself'. This is a four year old codebase that I just came into, so there's a few different places we're just passing dictionaries around instead of using dataclasses/etc. Some of those I'll be trying to clean up as I go along and generally docstring or otherwise fix up some of the older bits of this program.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

Armitag3 posted:

Apparently this works
Python code:
guid = "1234-123123-12123-1234"
print(f"{{{guid}}}")
# > {1234-123123-12123-1234}
lol

https://peps.python.org/pep-0498/#specification it's in the spec, yeah. I think I had to use this recently.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
Speaking of pickling:

We have a (currently) single threaded job that runs regularly and operates as a pipeline where it starts by gathering data from multiple sources, and then merges and transforms those into a composite file we use for the rest of whatever job is running.

I'm looking into ways to make this more flexible, so I'm debating setting up separate jobs and setting up a 'cache' by pickling the composite at the end of merge and then storing it for reuse, and then regenerating it whenever the stored data is more than 30 minutes old. This would cut about 60-75 seconds off of each of our jobs (minus the whole unpickling process).

Is pickle a reasonable tool for this use case or should I be considering something else? The data is not easily serializable to json since it's fairly complex and includes a lot of custom data types.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

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:
requests: dict
and I'm like WHAT THE gently caress IS IN HERE. I'm gonna go through and fix that poo poo up at some point, because it drives me crazy to have to figure out where we make this drat thing like eight steps away from where I'm working with it again.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

QuarkJets posted:

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.

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.

We were doing a cache stored as json and handled as a dict, and I just finished refactoring in an abstraction layer and got to delete so much weird code that was all around handling these weird fragile dictionaries, and bonus, it's gonna make it much easier to switch that over to a proper storage system like DynamoDB.

Falcon2001 fucked around with this message at 07:30 on Apr 14, 2022

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

Falcon2001 posted:

dataclass talk

Actually, I should expand on this in case anyone is newer and reading this, like I was not that long ago.

So it is extra code and extra work to define data storage classes, so there is a tradeoff here. But what I'm poking at here is the idea that a lot of times you use a dictionary because it's convenient, because putting things into a dict and taking them out is a reasonably easy operation. Especially with certain external operations it's easy to just go 'oh yeah, json turns to dict, I'll just keep it.' and that's not always a terrible idea. If the json schema is well defined, it's probably fine; you'll just need to look up the schema later. But the bigger problem is when you start making your own dictionaries to hold data.

However, the tradeoff is that new development turns into a constant fight of 'wait what the gently caress is in here. What are the keys? Let me run a debugger. OH okay that's what I want.', which isn't the case if you define a class, because your IDE is going to tell you the attributes of the class readily, and even if you don't use an IDE, you're one hop away from just looking up the code yourself.

(This part is like CS101 but putting it out there as an example) The other upside to using your own classes for data structures is that it gives you all the OOP benefits of classes so it can be as lightweight or heavy as you want it to be. For example, I want to cutover from a json flat-file for storing our cached data to DynamoDB or another lightweight database soon, and by adding an abstraction layer to this, I was able to ensure that the rest of my code is not going to need significant overhauls in the future, since instead of dictionary style syntax, we're using more general syntax, and some helper methods. Whenever we cutover to a new storage system I can just update the new cache_types I defined and keep all my changes pretty confined.

That all said, there are some downsides, namely that it is more code to write, but like most coding, it's one of those tradeoffs between today vs tomorrow.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

QuarkJets posted:

Sure, I agree with all of that.

But your previous post was kind of against the core premise; there's a lot of room between "use one dataclass that holds everything that any function might need" and "don't use dataclasses". Also, the specific post where a dataclass was recommended contained clearly modeled data (animal demographics), and the recommendation was to just wrap that data in a dataclass and not the misc. other function arguments. That's a good usecase.

I personally use/recommend dataclass arguments sparingly; only when it makes sense to group together arguments, and only when you're going to need to reuse those same arguments in multiple places. Then a dataclass is handy. But like any other class, you shouldn't create one without a reason.

FWIW as the recent dataclass lover, I agree with all this, because mostly the idea is 'if you're going to be passing around data from place to place as a clear set of data, you might want to schematize it'. I'm mostly arguing against dictionaries, not against overuse of classes/etc. If you're just passing info from one place to another, then yeah, just pass them as arguments.

For example, the 'responses' dictionary I was complaining about is data from a specific process - it's not going to change regularly (or if it does, it's going to gently caress up our schema enough for a code change anyway), and we basically pass it along a pipeline into multiple places. By the time I'm into the fifth step, there's no easy way for me to go find where the heck it's built anymore without walking back the code a bunch.

ExcessBLarg! posted:

It's a common trap to have an Everything class that contains attributes for everything and gets passed around to every function to pick the parts they care about.

Yeah also this would definitely be bad and I agree with you...except how much worse would it be if it was a dictionary instead.

Falcon2001 fucked around with this message at 04:56 on Apr 15, 2022

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

punk rebel ecks posted:

So I'm back from my traveling.

I managed to do what you all said and upload the code correctly on Github and make a pip freeze file for the requirements. That said the pip freeze resulted in pretty much every package I have installed in VSC listed in the file rather than what's simply required for the program. Not sure if I should delete the unnecessary stuff.

Anywhere he is the link to my project:

https://github.com/gunraidan/pokedex


Do you think I am ready to apply for any type of software development jobs yet?

To add onto what others have said:

- Absolutely use a linter of some kind, like Flake8. This will significantly increase your code's readability and uniformity and help reinforce good coding habits. This also isn't a 'newbie crutch' thing either, all the professionals I know use Flake8 as well as auto-formatters like Black or autopep8 to ensure that you're sticking to consistent results.

- Breaking apart things into modules is not only good for readability, but also good for writing code. There's a lot of various styles or opinions on this, but In general, split your code out into modules based on what they do - you'll often see a types.py file in some smaller projects where you group general data types, or bigger classes can have their own files. You can overdo this, but I mostly go by 'feel'; when a file has gotten so big that it starts to feel clunky, it's a good sign that I need to look at refactoring some stuff out into it's own class.

- Also, I know that you've gotten some pretty significant critique here, but I do want to say that having anything on GitHub is pretty good, and being able to point to a finished project and say 'hey I made a thing, and it works!' is something to feel pretty good about. That said, having a project that addresses the critiques that everyone's brought up is an even better starting point.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
Depending on where they are/etc, he could also look for smaller shops that are hiring positions that do coding AND other stuff too, like sysadmin roles or whatever. As long as there's some coding, could be good experience. Although I'm sort of unfamiliar wiht how that tht space looks these days.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
Also, a BS degree is still useful even if it's the same field, because it shows a certain baseline level of 'I can accomplish something concrete." and talks about general knowledge as well.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

SirPablo posted:

List comprehensions are awesome but they can get really wonky to read sometimes. It might be easier just to write your code then go back through and find where you are doing any "for x in range ()" type loops. Those are prime candidates for list comprehension.

I think list comprehensions are one of those very easy to gently caress up 'clever coding' things, but they're also much clearer sometimes, so you have to weigh the balance. Once you get into nesting them it's often much clearer to use a nested If statement instead or something.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

lazerwolf posted:

I will preface this by saying I don’t have experience with dash (I’m not sure about the quality of their docs), but I would try the official documentation.

An often overlooked skill in a developer is their ability to read the documentation.

Generally the official documentation has a good tutorial to follow.

At the very least, starting with the official documentation is a good way to make sure you're referring to a good source of truth; if you have questions from that, you also end up in a much better place to start googling from once you know the terminology used in that particular project/etc.

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

worms butthole guy posted:

I have a question about what the best "stack" would be to do this stupidly simple task.

I want to write a little program that reads from an API and then shows that data, refreshing itself every few minutes. The catch is during this refresh period, I want to play a video. I guess it's basically a digital sign, but I want to make it by hand.

I figured since i'm not doing anything super advanced i'd just use Flask for the backend to retrieve the data, but being "new" to Python (but not programming; I usually program in PHP), what should I use for the front end to accomplish this? I know React and Vue and can use those but those seem maybe a bit excessive.

Anyways I appreciate the help. Thank you!

Depending on how much you want to try a new tech, I've been seeing HTMX a lot lately as a JS-less (but built in JS) library that seems to be a nice lightweight alternative to vue/react/etc. I haven't tried it myself though, and I'm curious how other view it, but the videos/etc seem pretty promising.

edit: here's a video example that seems to at least be somewhat near what you're looking at :
https://www.youtube.com/watch?v=kNXVFB5eQfo&t=1079s

Falcon2001 fucked around with this message at 23:40 on May 2, 2022

Adbot
ADBOT LOVES YOU

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
I've used that same concept with dealing with templates without kinja for simple email forms at work; we just load the template and then .format() it. But everywhere else is fstrings.

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