|
12 rats tied together posted:the context manager is pretty easy and is a great python feature, you basically just define __enter__ and __exit__ methods There's a simpler syntax since (I think) 3.5, using the @contextmanager decorator: Python code:
|
# ? Aug 2, 2021 22:29 |
|
|
# ? May 15, 2024 02:54 |
|
D34THROW posted:Already kicking myself. I've got 4 kids and sometimes I want to randomly pick one for something, or randomize the order they do things. I typically use a d4 for this...but I just thought "hey, I'm learning Python, why not build an app for it"? Android development on Windows looks like fun! I thought Android was all Java?
|
# ? Aug 3, 2021 07:20 |
|
QuarkJets posted:I thought Android was all Java? There are wrappers that, if I understand correctly, translate python to java bytecode for Android purposes. There's also Kotlin and another language or two supported.
|
# ? Aug 3, 2021 13:30 |
|
I'm procrastinating by sketching out an elective python course for late BSc/early MSc CS students who already have a bunch of programming experience in general and have done some basic python stuff. This would not be a course on programming in general, on specific 3rd party libraries, on DS/ML etc, but more of a "here's a bunch of more python stuff that might be useful". I've drafted the following learning objectives, and would welcome any feedback on stuff I've completely missed. Note that there's some basic stuff (e.g. sets) to cover gaps in their introductory programming courses: quote:# Part 1: On good python
|
# ? Aug 3, 2021 14:25 |
|
Loezi posted:I'm procrastinating by sketching out an elective python course for late BSc/early MSc CS students who already have a bunch of programming experience in general and have done some basic python stuff. This would not be a course on programming in general, on specific 3rd party libraries, on DS/ML etc, but more of a "here's a bunch of more python stuff that might be useful". This looks like the python course I wish I could take.
|
# ? Aug 3, 2021 14:34 |
|
DoctorTristan posted:There's a simpler syntax since (I think) 3.5, using the @contextmanager decorator: Its *almost* at the point where they'll cut the nonsense and just implement the drat anonymous blocks from Ruby, like they should have done a decade and a half ago. I love python, but I'm perpetually annoyed at the contortions GvR put python through to avoid having to implement anonymous function. I get the proliferation of poo poo DSLs that ruby suffered was probably a hard "hell no"", but honestly, it just feels like the one area where python is a decade behind the competition. Hell even loving pascal (http://docwiki.appmethod.com/appmethod/1.13/topics/en/Anonymous_Methods_in_Object_Pascal) has them, and that things a *dinosaur*. (a dinosaur I still have a soft spot for, as my original programming language)
|
# ? Aug 3, 2021 16:29 |
|
edit: deleted, I didnt read your comment properly lol. My bad.
|
# ? Aug 3, 2021 16:33 |
duck monster posted:Hell even loving pascal (http://docwiki.appmethod.com/appmethod/1.13/topics/en/Anonymous_Methods_in_Object_Pascal) has them, and that things a *dinosaur*. My high school AP computer science class was in Pascal, back in like 1997.
|
|
# ? Aug 4, 2021 02:05 |
a foolish pianist posted:My high school AP computer science class was in Pascal, back in like 199 And it was considered pretty archaic then
|
|
# ? Aug 4, 2021 02:14 |
|
Loezi posted:I'm procrastinating by sketching out an elective python course for late BSc/early MSc CS students who already have a bunch of programming experience in general and have done some basic python stuff. This would not be a course on programming in general, on specific 3rd party libraries, on DS/ML etc, but more of a "here's a bunch of more python stuff that might be useful". That looks like a pretty good outline and also one that I wish I'd gone through before I started having to use Python. I think basically everything in that list is covered by Fluent Python (2nd Ed.), which I found an excellent read (though I don't think it's quite finished yet, but if you have institutional access to O'Reilly online it's a great resource). The very first section is "The Python Data Model" and goes over the Python data model - particularly magic/dunder methods - in a much more digestible way than the official docs, so that approach might be worth considering. quote:- You have heard of contravariance, covariance and invariance, and have a basic understanding of how these concepts relate to python generics ... I have not ... or if I did, it was ~16 years ago and I've forgotten... quote:- You know of and can use basic python data structures such `set`, `defaultdict`, `Counter`, `deque` and `OrderedDict` Out of curiosity, are you planning to tell them anything about OrderedDict besides that dicts are ordered by default and so it's being deprecated in 3.10? Also, for what it's worth (not much), I checked the codebase I'm working on and found no usages of deque in Python code, though there were some std::deque usages in C++ code.
|
# ? Aug 4, 2021 03:04 |
|
duck monster posted:Its *almost* at the point where they'll cut the nonsense and just implement the drat anonymous blocks from Ruby, like they should have done a decade and a half ago. To be honest I prefer the explicit __enter__ and __exit__ definitions to the decorator that converts a try/catch into something that can be context managed, but I have a probably unreasonable hate of try/catch in general. When I write python at work, it's usually for / around people who are not python developers, so I try to stick to code patterns that are either single line comprehensions that I can explain with a comment, or "c# without curly braces". It would be cool to work somewhere I can assume that everyone knows what a decorator is. eXXon posted:Also, for what it's worth (not much), I checked the codebase I'm working on and found no usages of deque in Python code, though there were some std::deque usages in C++ code. It seems like in general a queue is not particularly useful without an event loop, and most python courses I've seen never really get that far.
|
# ? Aug 4, 2021 05:51 |
|
Soylent Pudding posted:This looks like the python course I wish I could take. eXXon posted:That looks like a pretty good outline and also one that I wish I'd gone through before I started having to use Python. Thanks! eXXon posted:I think basically everything in that list is covered by Fluent Python (2nd Ed.), which I found an excellent read (though I don't think it's quite finished yet, but if you have institutional access to O'Reilly online it's a great resource). The very first section is "The Python Data Model" and goes over the Python data model - particularly magic/dunder methods - in a much more digestible way than the official docs, so that approach might be worth considering. This is a good suggestion! I don't seem to have access to this, but I'll talk to the library folks. eXXon posted:... I have not ... or if I did, it was ~16 years ago and I've forgotten... Basic idea, as far as I've understood it: You have "Type" and "Subtype", and it's clear that you can call a function expecting a Type argument with a Subtype argument. But are you allowed to call a function expecting a Container[Type] with a Container[Subtype]? Intuition might say "yes", but what if the functions adds a new Type object to the Container? To simplify a bit, covariance basically means "yes", contravariance means "no, but the other way around is okay" and invariance (the python default) means "only the exact type I specified is allowed". PEP484 has a section on this but it's not something you'd necessarily ever run across. eXXon posted:Out of curiosity, are you planning to tell them anything about OrderedDict besides that dicts are ordered by default and so it's being deprecated in 3.10? Also, for what it's worth (not much), I checked the codebase I'm working on and found no usages of deque in Python code, though there were some std::deque usages in C++ code. Completely forgot about the ordered dictionaries thing. I think I'll need to cover my bases and talk a bit about this whole mess. 12 rats tied together posted:It seems like in general a queue is not particularly useful without an event loop, and most python courses I've seen never really get that far. I mostly wanted to talk about deque to 1) contrast the performance of dequeue.appendleft(v) and list.insert(0, v) and 2) highlight the existence of many data structures they might not have thought of.
|
# ? Aug 4, 2021 08:54 |
|
I am both a hobbyist and a standards nut. Therefore, rewiring my brain to write PEP8-compliant code is a massive dick. Namely, I'm so used to using camelCase for variable names and PascalCase for function names that going to lowercase_with_underscores is loving killing me. Never mind the trailing newline on files, making sure I'm not leaving extra whitespace at the end of lines, and the most wonderful part...staying within 72 characters for comments and 100 characters for code. That's really fun when I'm 5 indents deep for the function alone, then doing something with a long string that's broken into 18 lines because the actual string doesn't start until column 76 and PEP8 wants the continuation to be at or past the original indentation.
|
# ? Aug 5, 2021 18:46 |
|
thats certainly a noble goal but do note that pep8 stresses consistency (and knowing when to be inconsistent) over any of its individual recommendations. you can camelCase if you want to and you'll be pep8 compliant so long as you are consistently camelCase i set all my poo poo to 2 spaces instead of 4 e: Loezi posted:I mostly wanted to talk about deque to 1) contrast the performance of dequeue.appendleft(v) and list.insert(0, v) and 2) highlight the existence of many data structures they might not have thought of. 12 rats tied together fucked around with this message at 19:00 on Aug 5, 2021 |
# ? Aug 5, 2021 18:58 |
|
D34THROW posted:I am both a hobbyist and a standards nut. Therefore, rewiring my brain to write PEP8-compliant code is a massive dick. Namely, I'm so used to using camelCase for variable names and PascalCase for function names that going to lowercase_with_underscores is loving killing me. Never mind the trailing newline on files, making sure I'm not leaving extra whitespace at the end of lines, and the most wonderful part...staying within 72 characters for comments and 100 characters for code. That's really fun when I'm 5 indents deep for the function alone, then doing something with a long string that's broken into 18 lines because the actual string doesn't start until column 76 and PEP8 wants the continuation to be at or past the original indentation. Use black.
|
# ? Aug 5, 2021 19:04 |
|
D34THROW posted:I am both a hobbyist and a standards nut. Therefore, rewiring my brain to write PEP8-compliant code is a massive dick. Namely, I'm so used to using camelCase for variable names and PascalCase for function names that going to lowercase_with_underscores is loving killing me. Never mind the trailing newline on files, making sure I'm not leaving extra whitespace at the end of lines, and the most wonderful part...staying within 72 characters for comments and 100 characters for code. That's really fun when I'm 5 indents deep for the function alone, then doing something with a long string that's broken into 18 lines because the actual string doesn't start until column 76 and PEP8 wants the continuation to be at or past the original indentation. You're worried about things that disappear if you use PyCharm and set it up the way you want. I'd assume VScode would be true as well. I've literally never once thought about how many characters to stay within for comments. If I make a long one I see a yellow squiggly, right click, refactor. necrotic posted:Use black. 12 rats tied together posted:thats certainly a noble goal but do note that pep8 stresses consistency (and knowing when to be inconsistent) over any of its individual recommendations. you can camelCase if you want to and you'll be pep8 compliant so long as you are consistently camelCase At least a few people who hire python peeps in this thread, me included, have said that camelCase var names for python coders is a red flag for bad code. Not a reason to not hire someone, but it will stick out like a sore thumb.
|
# ? Aug 5, 2021 20:27 |
|
necrotic posted:Use black. this
|
# ? Aug 5, 2021 20:33 |
|
CarForumPoster posted:At least a few people who hire python peeps in this thread, me included, have said that camelCase var names for python coders is a red flag for bad code. Not a reason to not hire someone, but it will stick out like a sore thumb. Agree, I wouldn't have mentioned it if OP didn't indicate that they are primarily a hobbyist. Submitting python code as part of a python tech interview to a python software shop with camelCase is not a great way to communicate "I will be pleasant to work with and productive in your ecosystem". necrotic posted:Use black.
|
# ? Aug 5, 2021 20:37 |
|
12 rats tied together posted:i set all my poo poo to 2 spaces instead of 4
|
# ? Aug 5, 2021 21:50 |
|
there was one thing ruby got right, and it was spacing
|
# ? Aug 5, 2021 22:04 |
|
CarForumPoster posted:You're worried about things that disappear if you use PyCharm and set it up the way you want. I'd assume VScode would be true as well. I've literally never once thought about how many characters to stay within for comments. If I make a long one I see a yellow squiggly, right click, refactor. I have VSCode set up with appropriate rulers but i had no idea refactoring code fixes long comments. Awesome! Use black...what the hell does that mean EDIT: Well, that smiley has changed since last I used it. vvv I'll check it out! D34THROW fucked around with this message at 22:45 on Aug 5, 2021 |
# ? Aug 5, 2021 22:20 |
|
D34THROW posted:I have VSCode set up with appropriate rulers but i had no idea refactoring code fixes long comments. Awesome! https://black.readthedocs.io/en/stable/
|
# ? Aug 5, 2021 22:22 |
|
Yeah, I should have originally linked it. Phone posting makes me lazy
|
# ? Aug 5, 2021 23:09 |
|
D34THROW posted:I have VSCode set up with appropriate rulers but i had no idea refactoring code fixes long comments. Awesome! If you use PyCharm (use PyCharm if you don't use Pycharm) there's a plugin to let you obsessively press a hotkey and have all of your disgusting formatting fixed. Takes all of five minutes to set up, doesn't really need configuration.
|
# ? Aug 6, 2021 00:36 |
|
I've tried pycharm, its sluggish as hell on my 2010 Win7 work laptop and hogs way too much memory to run alongside Outlook, Excel, and our ERP. VSCode is much more work friendly I've found.
|
# ? Aug 6, 2021 01:00 |
PyCharm has all the IntelliJ bloat and some weird Java-smelly keybindings and search behaviors (just try searching for text in a Terminal window, what the gently caress is going on) but once I've gotten used to all its conveniences I recently opened up Xcode assuming it would have all the same features and nnnnnnnope. Just a wasteland
|
|
# ? Aug 6, 2021 02:47 |
|
D34THROW posted:my 2010 Win7 work laptop youre kidding right? throw some coffee on that poo poo and get a new laptop.
|
# ? Aug 6, 2021 02:56 |
Finding you've got crazy long strings wrapping madly on the end of 20 indents isn't the python complaint you think it is, time to learn to structure code better.
|
|
# ? Aug 6, 2021 08:13 |
And being five indents deep in any logic is a good time to step back and think about refactoring
|
|
# ? Aug 6, 2021 11:50 |
|
quote:hobbyist I'm entirely self-taught and I tend to program how I think and modularize when I can. My proudest Python achievement at the moment is a mini-suite of tools I'm using for a CLI app - TextMenu(), ActionMenu(), and EndMenu(). TextMenu() takes a list of strings, uses them to generate a menu, validates input, and returns the input to the caller. ActionMenu() does the same thing, except with tuples instead of strings - [0] contains the menu item and [1] contains the command to eval() on selection. EndMenu() extends ActionMenu() in a way, asking if the user wants to resume, go back to the main menu, or exit. It takes the resume function name as an argument. On the plus side, I'm learning how to document as I go and my docstrings and comments are improving. I really like docstrings and how VSCode integrates them so well.
|
# ? Aug 6, 2021 15:09 |
|
Docstrings, well-documented Python code, and PyCharm is like a dream. I love it all.
|
# ? Aug 6, 2021 15:30 |
|
n-thing using a python formatter like black. Makes your life much easier and your code quality better. If you use some sort of VCS (you should be) you can also look into pre-commit to set up your repo to execute black flake8 and other formatters on commit
|
# ? Aug 6, 2021 15:45 |
|
lazerwolf posted:n-thing using a python formatter like black. Makes your life much easier and your code quality better. If you use some sort of VCS (you should be) you can also look into pre-commit to set up your repo to execute black flake8 and other formatters on commit I use GitHub integrated with VSCode - I can initialize the repository straight from there. Mainly it's because I'm paranoid about data loss, I commit every night, but I'm trying to get on a better system on a per-feature basis. Black looks amazing. Auto-formatting your code so you don't...really have to worry about the minutiae anymore? Abso-friggin-lutely. EDIT: I just ran Black on a venv and this happened. I guess Python's core isn't very PEP8. code:
D34THROW fucked around with this message at 18:07 on Aug 6, 2021 |
# ? Aug 6, 2021 17:06 |
|
lazerwolf posted:n-thing using a python formatter like black. Makes your life much easier and your code quality better. If you use some sort of VCS (you should be) you can also look into pre-commit to set up your repo to execute black flake8 and other formatters on commit Is there a reason to run black and flake8? I haven't used black but thought people tended to use one or the other
|
# ? Aug 7, 2021 03:13 |
|
QuarkJets posted:Is there a reason to run black and flake8? I haven't used black but thought people tended to use one or the other Yeah black is just a configurable automatic formatter. Flake8 doesn’t reformat your code but catches other errors like unused imports etc.
|
# ? Aug 7, 2021 05:09 |
|
I use isort followed by black followed by flake8 as my pre-commit hook and it's great.
|
# ? Aug 7, 2021 09:32 |
|
Loezi posted:I use isort followed by black followed by flake8 as my pre-commit hook and it's great. Cheers. I never knew about isort
|
# ? Aug 7, 2021 14:29 |
|
D34THROW posted:EDIT: I just ran Black on a venv and this happened. I guess Python's core isn't very PEP8. To be fair, black is even more opinionated than PEP8! I tried using black (and others) with pre-commit, but all of them add 2-3 minutes to the commit time (possibly because I'm using GitHub Desktop); any tricks to speed it up?
|
# ? Aug 7, 2021 17:02 |
|
dorkanoid posted:To be fair, black is even more opinionated than PEP8! Depending on which IDE you use, you can usually get black and isort plug-ins to format on save so your files should just pass through pre commit faster. Also I guess it depends on how many files in your repo and how many pre commit hooks you’re executing. Maybe look into GitHub actions to run a code quality verification on push
|
# ? Aug 7, 2021 17:41 |
|
|
# ? May 15, 2024 02:54 |
|
dorkanoid posted:To be fair, black is even more opinionated than PEP8! Are you accidentally running against every file in the repo maybe, instead of just the committed files?
|
# ? Aug 7, 2021 18:00 |