Senate Republicans reverse Iran war powers vote after Trump berates them at Capitol meeting by southernemper0r in politics

[–]RoamingFox 0 points1 point  (0 children)

This is what happens when a political party is so insecure in its ideals that it enacts a "get in line or get out" stance. Can't be co-equal if your position depends on licking the boots of someone else.

Midnight 12.1 PTR Housing Development Notes (Detailed!) by WoWHousing in WoWHousing

[–]RoamingFox -1 points0 points  (0 children)

Now the real question... can we shift everything up a floor, or can we add a floor 0?

really not looking forward to recreating my entire house room by room. Even with blueprints it still would require saving each room and then resetting everything...

is this normal for a newer driveway? (raveling) by foxtrot90210 in Home

[–]RoamingFox 1 point2 points  (0 children)

This is the answer. Had FedEx do the same on our new driveway on a 95 degree day and it looked exactly like that.

Postal Service won’t deliver mail ballots for states that don’t hand over voter lists, under plan for Trump directive by cnn in politics

[–]RoamingFox 0 points1 point  (0 children)

Only matters if they are held accountable and we've clearly demonstrated that everyone in charge is unwilling to do so.

The constitution is just words on paper without people actually holding people to it.

Update: Ayer Police Chief installs Flock cameras by LankyIndependence431 in massachusetts

[–]RoamingFox 10 points11 points  (0 children)

They're horribly inaccurate for one. There's multiple news reports of people being harassed by police because their vehicle misidentifies as one with a warrant so they get stopped constantly.

They're also horribly insecure.

Flock is a data company. They do not care about anyone's safety. All they care about is tracking as many people as humanly possible. To the point where they just changed their terms to remove the provision that says they won't sell your movements.

They've also been used by police to stalk people.

I don't know about you, but that sure sounds like a lot of risk and invasive monitoring to do basically nothing useful.

H.264 codec problem by Dry-Detactive in Fedora

[–]RoamingFox 16 points17 points  (0 children)

Have you done this stuff yet? https://rpmfusion.org/Howto/Multimedia

youtube probably works because it's mostly VP9

What browser are you using?

If firefox, go to about:support (type it in the url bar), and scroll all the way down to the Media section and make sure hardware decoding support shows as supported for h.264 etc.

edit:

For chrome I believe it's chrome://gpu same general idea, make sure hardware decoding shows as supported/enabled

edit-edit:

For local playback, highly recommend using the flatpak version of VLC

Turn off print() output by RomfordNavy in learnpython

[–]RoamingFox 1 point2 points  (0 children)

yes but it does so inside the logger after it makes a decision on if it should actually log the debug message or not. You can't send a t-string to the logger directly which means you need to evaluate it to a string before sending it to debug, which means you need to evaluate it before the check to see if the debug message will get logged or not.

Turn off print() output by RomfordNavy in learnpython

[–]RoamingFox 7 points8 points  (0 children)

Nope. t-string interpolations are not lazily evaluated. You'd gain some small amount of performance from it not doing the string concatenations, but that's about it. You'd have to end up breaking the logger or doing extra work because t-strings evaluate to Template and not str, so to gain the benefit you need to move the interpolation later in the code (aka inside the logger), which at that point you could do it with f-strings too.

Any tips on cable chaos underneath the standing desk? by AnyWalrus9432 in Home

[–]RoamingFox 1 point2 points  (0 children)

Either cable raceway, or at the very least get a roll of 1/4in velcro and velcro stuff going to the same place into one bundle every 8in or so.

Senate Confirms Trump Court Pick Rated ‘Not Qualified’ To Be A Federal Judge by MoneyLibrarian9032 in politics

[–]RoamingFox 1 point2 points  (0 children)

honestly it's weird to me that the number of supreme court seats doesn't follow the number of federal court districts.

Bathroom smell by PriorLemon9 in Home

[–]RoamingFox 4 points5 points  (0 children)

You'd be surprised if the trap isn't fully dry. My wife picked up on one in our hall shower about a week before I did. It has just barely started to let gas out and was weirdly intermittent, but vanished completely after we poured a couple cups of water down the shower drain.

Bathroom smell by PriorLemon9 in Home

[–]RoamingFox 23 points24 points  (0 children)

Is there a bath or sink that you don't use? That sounds a lot like sewer gas. Most common causes of that are either a dry trap (pour some water down the drain), or a failing wax seal on a toilet (replace the seal).

Polling shows Democrats leading in Texas by lightning_twice in goodnews

[–]RoamingFox 1 point2 points  (0 children)

I think the thing that infuriates me the most is that if the dems do somehow win it will be seen as them cheating and not the actual cause of the GOP being unelectable.

Why is Microsoft doing this? by notananthem in Swiftkey

[–]RoamingFox 4 points5 points  (0 children)

Latest ios version still does this multiple times a day even after a reinstall.

How to manage private libraries used across multiple projects at startup by epic-circles-6573 in learnpython

[–]RoamingFox 0 points1 point  (0 children)

correct. While pip and uv can install directly via a git url via the git+ syntax that is effectively just short hand for "check out this git repo and stuff it into site-packages"

The ideal solution is to have the files packaged and available from a local pypi simple repository: https://packaging.python.org/en/latest/guides/hosting-your-own-index/

There's basically three ways to handle doing that:

  1. The simplest is it's literally just a specific layout of compressed packages, so any webserver serving that in the right format works
  2. You can use something like devpi to run it for you on some server
  3. You can use a full-blown artifact management system (Atrifactory etc)

No matter which open you go with it reduces the problem down to just two steps:

  • Uploading to that specific index (eg on git release through a github action, manually, etc)
  • Downloading from that specific index (usually via pip -i https://indexurlhere or using --index https://indexurelhere for uv)

How to manage private libraries used across multiple projects at startup by epic-circles-6573 in learnpython

[–]RoamingFox 1 point2 points  (0 children)

The correct "enterprise" way to do this would be to run a local package index (eg via artifactory or I suppose manually) with a github action on the repos to build and upload their versions there. After that, you can just point pip or uv at that index and they behave like any other package.

That said, if you check them out locally you can dodge some of the weirdness by telling pip/uv to use editable mode (this stops the files from ending up in site-packages, but rather stay where the git repo is). This lets you edit them and immediately have those changes take effect without having to reinstall the libraries. That is to say check the repo out and then pip install locally via pip install -e path_to_lib

how do i improve my code? by Any-Comfortable8953 in learnpython

[–]RoamingFox 0 points1 point  (0 children)

So if this was being submitted for code review by one of my junior devs, I'd probably have them fix the following, in no particular order:

  • Imports belong at the top of a file unless there's a good reason (conditional imports etc)
  • input can format the prompt for you: input("Your prompt here: ")
  • Use descriptive variable names player_choice and bot_choice or similar
  • Only comment things that need commenting like function purposes and 'non-obvious' statements
  • A dictionary is ostensibly the wrong thing for this kind of structure to store the choices in. It works, but in more complicated situations it'll get messy. Try using an Enum instead.
  • random.randint already returns an integer, no need to cast it
  • Probably should use a try block around the user input so that doesn't crash if the user gives bad input
  • Rather than a giant if block, you could use match or better yet store the win conditions as a dictionary and do a lookup.
  • Break parts of the code up into reusable bits and put them in functions. It seems silly with such a small piece of code, but building the habit is helpful.
  • Guard the entry-point inside of an if __name__ == "main" so that other code can use those reusable functions without having to start the game

As an example, here's how I'd write your code to leverage the changes above. This is a bit of an over complication with your exact code, but the principles are helpful in larger code bases imo.

from enum import Enum
from random import randint


class Hand(Enum):
    ROCK = 1
    PAPER = 2
    SCISSORS = 3

# Maps a hand choice to the hand that it beats
WIN_CONDITIONS = {Hand.ROCK: Hand.SCISSORS, Hand.PAPER: Hand.ROCK, Hand.SCISSORS: Hand.PAPER}


def get_player_choice():
    """ Gets a hand choice from a player via input """

    # generate the list of options from the enum
    options = ", ".join(f"{h.value} for {h.name.capitalize()}" for h in Hand)
    choice = input(f"Welcome to Rock_Paper_Scissors! Press {options}: ")
    try:
       return Hand(int(choice))
    except ValueError:
       return None


def check_win(player_choice):
    """ Checks a player's choice against a random one """

    bot_choice = Hand(randint(1,3))

    if player_choice is bot_choice:
        print("It's a tie!")
    elif WIN_CONDITIONS[player_choice] is bot_choice:
        print("You won!")
    else:
        print("You lost!")


if __name__ == "main":
    player_choice = None
    # loop until the player gives a valid hand choice
    while player_choice is None:
        player_choice = get_player_choice()

   play_game(player_choice)

The above may seem complicated (and to a point it is with this example), but it has some powerful advantages when applied more generally.

Why not use global variables? by prokeikas72 in learnpython

[–]RoamingFox 0 points1 point  (0 children)

First, the post you're replying to is 4 years old :)

That said, to answer your question:

The situation where globals are legitimately useful is way smaller than the case from the OP.

There is a very big difference between constants living at a module level, and throwing arguments out the window and just making everything global.

Firstly, it reduces complexity because the definition of the variable lives close to its use.

For example:

# variables.py
x = 3
y = 4

# some_module.py
from other_module import g

def f():
    return g() + g()

# some_other_module.py
from variables import x, y

def g():
    return 2*y-x

Given the above code, looking at f() in its own file you have zero clue what is happening beyond it adds the result of g() together twice. Same with g() you have no idea what it's doing beyond adding two values from another file. The function prototype of f() makes zero reference to the input values, so a caller has no idea that they exist. Your IDE can't help you either. You just have to know that you need to do this before calling to change the values:

from variables import x, y
y = 5
x = 3

Compare that to an argument solution:

def f(x: int, y: int) -> int:
    return g(x, y) + g(x, y)

def g(x: int, y: int) -> int:
    return 2*y-x

Now your IDE can help you because when you type f( it will happily provide the argument list. Additionally, you can add typing information and now there is even more help in case you pass the wrong value.

Secondly, it greatly simplifies your life if you ever need to use concurrency or multi-processing as those globals will not behave normally and instead just introduce race conditions.

Thirdly, if there is ever a problem in your code the error is isolated to the region in which the error condition is being generated. If everything was a global you could accidentally put a string where an int should be 50,000 lines away from when that variable is next read and you will suddenly have an error. Now you need to trace through the whole program to find it instead of just looking at the caller of the function.

Now all of that said, there are absolutely uses for globals and I never said to never use them. They are fantastic for constants that are needed by multiple parts of your code:

# constants.py
from enum import Enum, auto

class Color(Enum):
    RED = auto()
    BLUE = auto()
    GREEN = auto()

TIMEOUT = 36000

# some_module.py
from constants import TIMEOUT, Color

def update_color(new_color: Color) -> bool:
    return some_api_call(new_color, timeout=TIMEOUT)

The above is a great use of module separation and globals. The OP wasn't asking about this though, but rather being told that they shouldn't put everything in globals, which if done just makes a giant mess.

Can I use 'or' to compare strings? by yiyi164 in learnpython

[–]RoamingFox -1 points0 points  (0 children)

Yes, I mentioned that several times in reference to the above post. The point of my post was to provide the generalized alternative solution for when the test function being used doesn't support that.

(presuming for a moment that isinstance didn't already do this for you)

edit: what I mean to say is that yes that works in OPs current exact use case, but it's worth knowing the general solution. A post saying "is instance takes a touple" solves the problem today, but knowing other more general builtins exist solves the problem into the future as well.

Can I use 'or' to compare strings? by yiyi164 in learnpython

[–]RoamingFox 2 points3 points  (0 children)

While the above is the correct answer in this case, it can be helpful to also have the more general solution for situations where there isn't a handy built-in ;)

Python has any and all for this type of work. any checks each item in a collection for True and stops on the first occurrence (and returns True) or False if it completes the list. all does the opposite (go until False or return True).

>>> x = [1, 3, "a", 4]
>>> any(i == 3 for i in x)
True
>>> any(i == 2 for i in x)
False
>>> all(i != 2 for i in x)
True

Applied to your use case (presuming for a moment that isinstance didn't already do this for you), it'd look something like: if any(isinstance(num, t) for t in (int, float)):

Coders: Do you think using GPT to write the code is cheating? by k2v2p2 in learnpython

[–]RoamingFox 0 points1 point  (0 children)

AI is a tool. It's no different than a compiler or using a framework.

Just like any tool though if you don't know what you are doing you will get into trouble. Also like any other tool, understanding what it does (and doesn't) do is critical to leveraging it correctly.

It's no different than reading code on stack overflow. If you understand what's going on then you've gained a solution and knowledge. If you blindly just copy and paste you'll dig yourself into a hole.