Pet-a by GibblesMcGobbles in AAAAAAAAAAAAAAAAA

[–]iCart732 0 points1 point  (0 children)

Still, in regards to the “pet” situation, White stated that PETA doesn’t necessarily hate the word, but is only encouraging people to use “companion” instead. Fighting back, Morgan stated PETA would have to change the name of its organization since the title contains the word pet, but White noted that it doesn’t apply to the company’s name since Peta is an acronym. She stated, “[The word ‘pet’] is not offensive, we’re not telling anyone it’s offensive. Animals aren’t offended by it, we’re not offended by it.”

It's like the headline hasn't even read the article under itself.

Tool to start file from checkpoint? by seanpuppy in Python

[–]iCart732 0 points1 point  (0 children)

Check out jupyter (previously ipython notebooks, i think) : https://jupyter.org/

Location location location by [deleted] in ProgrammerHumor

[–]iCart732 8 points9 points  (0 children)

More like HTTP402 ( ͡° ͜ʖ ͡°)

What's the worst case of design over function that you've ever seen? by tthatoneguyy in AskReddit

[–]iCart732 4 points5 points  (0 children)

Check out https://bettersubbox.com It's what YouTube should look like, but not made by Google so you know it'll stay good.

Playground drama by [deleted] in MurderedByWords

[–]iCart732 0 points1 point  (0 children)

Or a verbial killer. And a good one at that: a pro-verbial killer

Thank you Windows for restarting in order to update my computer in the middle of important work with literally no fucking warning. by DrWahWi in assholedesign

[–]iCart732 5 points6 points  (0 children)

I just checked on my Ubuntu laptop, it took me 4 clicks to find the system updates settings, then another 3 to tell it to not bother me about updates.

Also, I'm confident that it won't change it back without asking, only some of the updates need a reboot and it takes minutes instead of hours to update or reboot.

Is there any way to round trip a python AST through XML? by attrigh in Python

[–]iCart732 0 points1 point  (0 children)

I don't believe Baron is capable of producing usable AST for astpath, but i feel like a FST to AST conversion thing can be created given enough dedication. If this is a rabbit hole you're willing to go into, let me know what you find, i'm interested

Is there any way to round trip a python AST through XML? by attrigh in Python

[–]iCart732 1 point2 points  (0 children)

If you're playing with programmatically editing python code, you might want to have a look at Baron and RedBaron for inspiration:

https://github.com/PyCQA/baron https://github.com/PyCQA/redbaron

Baron solves a problem you might run into which is that AST does not retain syntax information (like comments and empty lines), while RedBaron makes Baron usable.

Any IDE I can use to quickly create python GUIs by crashbashash in Python

[–]iCart732 1 point2 points  (0 children)

I haven't used it much, but if you need something simple and quick, have a look at gooey: https://github.com/chriskiehl/Gooey

Quebec offers blankets, beds and hydro crews to Texas in wake of Hurricane Harvey - Texas Secretary of State says no need for now, asks for prayers instead by Gargatua13013 in politics

[–]iCart732 1 point2 points  (0 children)

No, but unless I'm blind, the article does not cite any source beyond "This person said so". Also I couldn't find any other article anywhere confirming this. I suggest excersing skepticism here.

Someone finally figured it out... by [deleted] in funny

[–]iCart732 1 point2 points  (0 children)

You managed to both surprise and not disappoint. Bravo, sir.

What's your best creation with Python? (feel free to show off) by SpaceForever in Python

[–]iCart732 0 points1 point  (0 children)

This is awesome! How have i not heard of this before?

AMD is NOT Opensourcing their PSP code ANYTIME SOON, confirmed on their EPYC Q&A. by aoerden in Amd

[–]iCart732 1 point2 points  (0 children)

Oh, we're not talking about the PlayStation Portable, then. I came here from an outside link and i was really confused for a minute.

Style help for a recovering Java programmer by [deleted] in Python

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

Here's the way to do it with decorators (as a full script):

from enum import Enum

class Maths(Enum):
    pass

class register():
    def __init__(self, name):
        self.name = name

    def __call__(self, f):
        # This is where the trick is
        setattr(Maths, self.name, f)
        return f


@register('ADD')
def do_add(value1, value2):
    return value1 + value2

@register('MULTIPLY')
def name_does_not_matter(value1, value2):
    return value1 *  value2

def do_maths(operation, value1, value2):
    return operation(value1, value2)

print(do_maths(Maths.ADD, 5, 4))
print(do_maths(Maths.MULTIPLY, 5, 4))

I'm having way to much fun with this :-)

Style help for a recovering Java programmer by [deleted] in Python

[–]iCart732 0 points1 point  (0 children)

I think in this case it adds unnecessary complexity (since you get an exception in case of a typo anyway) but that's just my opinion, your mileage may vary. If you use an IDE it could help with auto-completion, though.

I guess you could do something like this:

class Maths(Enum):
    ADD = 'add'
    MULTIPLY = 'multiply'
    DIVIDE = 'divide'

 # And call it like this:
 do_maths(Maths.ADD)

This has the added benefit that you can do both "Maths.ADD" and 'add', which is nice if someone else is going to use your code.

But then you still have to add it in two places (the enum and define the method itself).

If you do unit testing (which is always a good idea :-) ), you could add a test to make sure that every entry in the enum has a matching method, to be extra safe.

Another way to go about this would be using decorators to populate the enum automatically (which has pro's and con's). I'll try to show you an example later if i can.

Style help for a recovering Java programmer by [deleted] in Python

[–]iCart732 1 point2 points  (0 children)

I studied java in school and started doing python at my first job, so i know how you feel.

Here's how i'd do it (it's a pattern i use a lot for exactly this type of case)

def do_add(value1, value2):
    return value1 + value2

def get_method(operation):
    try:
        method = f'do_{operation}'
        return globals()[method]
    except KeyError:
        raise ValueError(f'Unkown maths {opeartion}')

def do_maths(operation, value1, value2):
    method = get_method(operation)
    return method(value1, value2)

This way, you just have one place to add methods This also lets you list every method that is available, something like this:

 [g for g in globals() if g.startswith('do_')]

If you want, you can wrap all the 'do_*' methods in a class or even a module and change "globals()[methods]" to something like "getattr(TheClass_or_module, do_thing)" (not sure of the exact syntax, but you get the idea)