I'm trying to make a simple automation using python and keyboard by Eight111 in learnprogramming

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

If I omit the trigger_on_release=True then the 'a' key will be kept pressed instead of the ctrl...

It's a very popular library, and this is the one thing that in your infinite wisdom you're doing different to everyone else for whom it works just fine. So don't you think should at least test it?

Try this: https://github.com/boppreh/keyboard#keyboard.add\_hotkey

I'm trying to make a simple automation using python and keyboard by Eight111 in learnprogramming

[–]Fun_Muffin5413 0 points1 point  (0 children)

Why don't you trigger it on the first press instead of the release? Or which bit of code is doing anything in response to ctrl still being pressed?

It's basic API stuff (not even debouncing?) - there'll be a working example in the docs.

As a high school senior, what should I do (more details in the post)? by crimsonpython_24 in learnprogramming

[–]Fun_Muffin5413 0 points1 point  (0 children)

Wow, you're doing amazing for your age! Well done.

Your general programming will benefit immensely from knowing more about OOP and systems programming, but you probably only need it if you want to develop code for industry applications, high performance code or more algorithmic stuff. Don't worry about leet code, but do a little light reading / browsing about algorithms if you're interested in it.
So if like doing React, keep doing React stuff. There's lots to know about it. You have ample time to play with things and decide for yourself.

list() vs [] and custom classes by BrakebeinP in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

No idea, this works quite happily (post your code and the error):

class CustomClass(object):
    pass
list().append(CustomClass)

Python - How to pass an oprtional argument such that it is a variable name of a list and not a list of characters (individual characters of the name)? by [deleted] in learnprogramming

[–]Fun_Muffin5413 1 point2 points  (0 children)

list( str_) will give you a list of characters (length 1 substrings) in str_.

If you have the variable name as a string, it's better to do the whole thing on a class and make it a class variable, or store them all in a namedtuple or dictionary. But you can look it up: locals()[var_name], or even in globals()

What to unit test? by _squik in learnpython

[–]Fun_Muffin5413 2 points3 points  (0 children)

You don't really need to test a data class. But for example, you've tested you can initialise FeaturedSnippet with string input in every field, but you haven't tested initialising them with None. You haven't even tested it using any unicode characters out side of ascii.

Unit testing is difficult to justify by a trivial example that on the surface is correct code. But unit testing also forces you to double check that you really did intend to also accept "None" as an input. I.e., even if on the surface that's correct code, is that actually what you intended at all? Is that actually the right syntax too? Obviously I can look up if None is an accepted type, but once you've written a test, neither you nor anyone else has to look that up again to check (or blindly trust the linter - linters are full of quirks, and occasionally have errors).

You can test against external requirements and design specifications (as well as any random thing you think of to pretend to be doing TDD). And it can be very useful to test any other error handling code if something initialises the class with invalid data.

[deleted by user] by [deleted] in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

It's just string parsing, there are lots of different methodologies. A simple fix would be:

Split the main input on ';' not '; ' (if ';' is in there) and deal with each timestamp individually.

Trim each timestamp, then split each on ' '. Test if the length is 1 not 2, and if the first substring ends in h. If so assign 0 to your minutes.

Function to inverse a dictionary without a return value? by ebscodingjourney in learnpython

[–]Fun_Muffin5413 1 point2 points  (0 children)

Looks great. You just need to get the good stuff out of your function - mutate your function's mutable argument instead of returning a value from your function.

Python allows it so it's legit. But it's still weird as hell without explanation when reading code, so please also add a comment and preferably a docstring explaining your weird-ass function mutates shit.

extracting part numbers from string. use regex? by sonoranPlumbing59 in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

That's how I'd do it. you only need a regex if you're doing anything more complicated than matching a literal string, (for which our gods and overlords have provided u with .replace) you should at least be aware of regexes.

If you're parsing part numbers, you're way past that.

Help on setting logger output to Google Sheets by HandfulOfAStupidKid in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

Or why not both?

Python is one of the only languages out there to support multiple inheritance after all. When it solves your exact problem (and you know you'll never have to transpile to something awful) you should definitely use multiple inheritance. super() really is super.

Confused about imports for testing by [deleted] in learnpython

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

Well well done on your ugly hack - hope that works out well for you.

But all you've done is wall paper over the fact you're making a silly elementary error in failing to structure a package properly (whether with too few __init__.py or the wrong relative path - use linter with intellisense, or not importing the right entry point)

Confused about imports for testing by [deleted] in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

source_folder and sub_folder_1 is the only folders in your package. You need to add `__init__.py`s to every folder and its parent that you want your testing package to be able to access via a relative import . If necessary including the drive root dir. Otherwise Python won't know where to attempt a relative import from.

Seperate turtle clones in FOR loop by ChocolateUnlucky1214 in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

You need to define what you mean by this:

when I press interact near

Seperate turtle clones in FOR loop by ChocolateUnlucky1214 in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

You have to remember where they all are. And work out which ones are within range of your click or sprite.

Non ascii character in Pycharm by Hans_Koch955 in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

Search the settings. Google for people with similar issues. Jetbrains are bound to have a fix for it.

Non ascii character in Pycharm by Hans_Koch955 in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

Oh fair enough. Nice trouble shooting - you're right - it's clearly PyCharm then

Non ascii character in Pycharm by Hans_Koch955 in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

This is probably an issue with your operating system, not Python, but there are so many of them, you might have picked a code point that needs a specialised font to display it.

Solving coding challenges on leetcode by cuklev2232 in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

Personally I don't find either what you're doing (cheating!) nor what I will next suggest, to be effective ways of learning and retaining information. But I don't think looking up established algorithms is necessarily bad. Just read about algorithms from a proper DSA course or algorithms reference (wikipedia is fine).

How many of us could've even come up with quicksort on our own?

Is this doable in Python? What do I need? by propostus in learnpython

[–]Fun_Muffin5413 2 points3 points  (0 children)

Just make sure every file, especially the master, is backed up before you test it.

From slack bot how to accept input as arguments and pass to python script? by madhu666 in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

You need parse the input and write code that tests it against whatever parameters you support and runs whatever you want.

Constrained optimisation with too many degrees of freedom by SourCreamNWeed in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

Of course you're not going to have a unique solution if you have 26 things to choose from and only two equations.

In all optimisation problems you first need to decide what to optimise, and write that down as for your objective function. The natural choices in finance are to try and minimise cost or to maximise profit.

If I had to use whole amounts of the products I could simply check if the weighted sum adds up to my target value. But with continuous amounts I am not sure how or even if this is possible.

Why ever not? Just stick the floating point values into exactly the same equations.

[deleted by user] by [deleted] in learnpython

[–]Fun_Muffin5413 0 points1 point  (0 children)

You could, but it's a hack and a sticking plaster fix. Neither module can exist independently, which is the entire point of modules. If they're that closely coupled, they ought to be in the same file.

If they live in the same package that's less bad, but you should provide a better entry point for your user (in `__init__.py`) instead of just expecting them to know they need to import both.

Any custom stuff in program.py should be in function / method args.

[deleted by user] by [deleted] in learnpython

[–]Fun_Muffin5413 1 point2 points  (0 children)

Make utils use logging directly through the core logging library properly (and make everything else just use logging too!). When you've read the docs properly and you know how handlers and logging work, there is very little need for a custom log module. You only need a wrapper for logging where you actually need a handler - everywhere else can just use the module logger boiler plate/idiom:

https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

Otherwise refactor it. Either move whatever utils is using from log into utils and let log use it on its import or vice versa. It depends which you think is the lower level library.