8 ms·
Python Cheatsheet
- deleted 3y ago[deleted]
- zabzonk 3y agowho exactly is this aimed at? why would they not use the python on-line documentation?
- samwillis 3y agoDiscoverability, a document like this makes it much easier to find features and tools you were unaware of. The Python documentation is awesome, but it doesn't provide a 30k ft overview of the language and standard library, especially when the standard lib is so comprehensive.
- Given_47 3y agoExactly. Analogous to curling cheat.sh or simply using the tldr pages as opposed to sifting thru the entirety of a man page for a quick command
- zabzonk 3y agoi really don't see how - i have never had had any difficulty searching for features in the standard library documentation.
- bloopernova 3y agoYour experience is not the same as everyone else's.
- analog31 3y ago"Unofficial" documentation can serve needs that are neglected by the official docs, even if only by offering a different point of view. I can't speak to Python specifically, but to make an analogy, a microcontroller that I'm working with right now is documented by a 3500 page manual that requires a fair amount of expertise just to know what to look for. But a seasoned embedded dev might be just fine with that, and annoyed by anything simpler. On the other hand, I can make headway by using the Arduino API and boatloads of online documentation in the form of blogs, tutorials, StackOverflow, etc. Likewise, nobody knows how to write technical documentation that's readable by everybody. In the case of Python, the official docs are typically the last place where I'd look for stuff, given the quality of documents such as this cheat sheet. There's still a need for authoritative "developer" documentation, but not for me. The diversity of Python developers, from hobbyists to pro's, justifies a similar diversity of documentation.
- zabzonk 3y ago> In the case of Python, the official docs are typically the last place where I'd look for stuff, given the quality of documents such as this cheat sheet. you say "I can't speak to Python specifically", but i can assure you that the official docs are far superior to this cheat sheet.
- 7373737373 3y agoYour opinion is not the same as everyone else's.
- Barrin92 3y agopersonally I find online docs too bothersome. Over the years I've made an entire folder of cheatsheet org-mode files and when I work I can just hit a hotkey and grep them. Also writing and updating them actually helps memorize things
- qnleigh 3y agoI can't read the entire python documentation in an hour. And having never taken a programming class or worked alongside a professional software engineer, I only know what it's occurred to me to look for. Python has lots of tools that I didn't know I needed. Probably the same us true for most people, and the only difference is what level of "cheatsheet" is appropriate. I'm embarrassed to say I learned what generators are from this. 7 lines of code; totally unambiguous explanation. I don't even use iterators all that often, so I'm not surprised that I've never googled something that lead me to them.
- majkinetor 3y agoI like pages like this. Exactly the level of detail I need when I want to use python once in a while. Thanks.
- mey 3y agoThat is a lot of data for a single page IMO. You already have a TOC, several library sections might be pages unto themselves. You might also cross link topics into their relevant python docs for deeper references. I know I always need to dig deeper into CSV/argparse for specific things when working with those systems. Edit: awesome content
- dazzaji 3y agoThis comment got me thinking “What do you notice that is incorrect or important but missing from this page?” I discovered two things: 1) I’m too shallow in Python to identify any such issues and 2) while GPT-4 and Sage struggled with that precise question, in about 3 seconds I got what appears to be a really useful critique from Claude 2 100k. I’ll share that in case anybody is interested: ___ Here are a few things I noticed that could be improved on the Python cheatsheet page: - The dictionary section is missing explanation of dict comprehensions. Dict comprehensions are an important and useful feature for constructing dictionaries in a concise way. - In the section on modules, it would be good to mention virtual environments. Virtual environments are an important tool for Python dependency and package management. - The examples in the Pandas section are useful, but more explanation or details could be provided on some of the core DataFrame operations like merging/joining, groupby, aggregations, etc. - In the sections on concurrency and parallelism, async/await could be explained and demonstrated. Asyncio is commonly used for asynchronous programming in Python. - The cheatsheet focuses mainly on built-in modules and functionality. It could be useful to also cover some widely used 3rd party libraries like NumPy, SciPy, Matplotlib, TensorFlow, etc. - Sections on testing and debugging could be added - things like unittest, pytest, logging, debugging tools. Testing and debugging are key skills for Python developers. - The cheatsheet is very text heavy. More visuals, diagrams, or tables could help make it more scannable and easier to navigate. Overall it covers a lot of ground, but filling in some of those gaps would make it more comprehensive and useful as a reference. The content is excellent, just some ways it could be expanded on.
- hoistbypetard 3y agoEh. I think that critique misses more than it hits. > The dictionary section is missing explanation of dict comprehensions. Dict comprehensions are an important and useful feature for constructing dictionaries in a concise way. Those are in the inline section, with the other comprehensions: https://gto76.github.io/python-cheatsheet/#inline https://gto76.github.io/python-cheatsheet/#inline > In the sections on concurrency and parallelism, async/await could be explained and demonstrated. Asyncio is commonly used for asynchronous programming in Python. Those are in the coroutines section: https://gto76.github.io/python-cheatsheet/#coroutines https://gto76.github.io/python-cheatsheet/#coroutines > The cheatsheet focuses mainly on built-in modules and functionality. It could be useful to also cover some widely used 3rd party libraries like NumPy, SciPy, Matplotlib, TensorFlow, etc. NumPy: https://gto76.github.io/python-cheatsheet/#numpy https://gto76.github.io/python-cheatsheet/#numpy Matplotlib: https://gto76.github.io/python-cheatsheet/#plot https://gto76.github.io/python-cheatsheet/#plot (It doesn't cover SciPy, Tensorflow. That said, I've been writing python for 23+ years, and can count on two fingers how many times I've needed either of those.) ---- Some parts of the critique are correct, if not especially useful IMO. I'd say most of the parts of the critique that are correct seem to misunderstand the purpose of the cheatsheet. The best points the model generated, IMO, were the ones related to pandas and virtual environments.
- teddyh 3y agoMy initial comments: • Does not cover the “raise from” syntax¹. • Does not cover Structural Pattern Matching (the “match” and “case” keywords)². (EDIT: The FAQ states that it covers Python 3.8, and this feature was added in Python 3.10.) • In my basic script template I have this, to show warnings by default: if not sys.warnoptions: import warnings warnings.simplefilter("default") • My basic script template also uses the “-bbI” switches to python on the shebang line. 1. <https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement https://docs.python.org/3/reference/simple_stmts.html#the-ra...> 2. <https://docs.python.org/3/reference/compound_stmts.html#the-match-statement https://docs.python.org/3/reference/compound_stmts.html#the-...>
- linuxftw 3y agoThis content has been deprecated by chatgpt. In fact, this could have been generated by chatgpt.
- zombiemama 3y agoI tried that already, here is the result: https://gist.github.com/gto76/145776c5eace059b09ca1d6ca771a123 https://gist.github.com/gto76/145776c5eace059b09ca1d6ca771a1...
- linuxftw 3y agoNice! Looks reasonably comparable at a glance for the collections section.
- zombiemama 3y agoSure, but I strongly suspect that it was a part of the corpus (it's been online for ~5 years now).
- linuxftw 3y agoI asked it to generate something similar for golang with a snippet of the list section, and the results look pretty similar. So I don't think it's relying too heavily on a direct example.
- zombiemama 3y agoI think you're right, I already asked it for some libraries that are not included in the original (fuck my life :) https://gist.github.com/gto76/9ed16511a046d9746d38c55a14ec09a9 https://gist.github.com/gto76/9ed16511a046d9746d38c55a14ec09...
- linuxftw 3y agoReally solid chat prompt idea, for sure!
- bvan 3y agoThank you.
- rtpg 3y agoI highly highly highly recommend using something like Zeal for documentation viewing. It's so much faster to type in something and read docs than to google, no matter how fast your internet is. Though it's more limited to knowing what object you're looking for already (The first person to mention ChatGPT gets bopped. I do not need to use an LLM to look up module documentation)
- xarope 3y agothis reminds me of the perlrefs I used to download and printout; despite having years of perl coding, I'd often forget which combinations of @#$%^&* (ok I'm just randomly typing now!) I'd have to use.
- asicsp 3y agoPrevious discussion: https://news.ycombinator.com/item?id=29679788 https://news.ycombinator.com/item?id=29679788 (243 points | Dec 25, 2021 | 57 comments) See also: * Python Crash Course cheatsheet: https://ehmatthes.github.io/pcc_3e/cheat_sheets/ https://ehmatthes.github.io/pcc_3e/cheat_sheets/ * Scientific Python cheatsheet: https://ipgp.github.io/scientific_python_cheat_sheet/ https://ipgp.github.io/scientific_python_cheat_sheet/ * Common beginner errors: https://pythonforbiologists.com/29-common-beginner-errors-on-one-page.html https://pythonforbiologists.com/29-common-beginner-errors-on... * Python regular expression cheatsheet: https://learnbyexample.github.io/python-regex-cheatsheet/ https://learnbyexample.github.io/python-regex-cheatsheet/ — my blog post, includes examples as well
- roydivision 3y agoThis is great, thanks Jure. For whatever reason I find it difficult to read documentation, I work much better with code examples, they speak to me much more clearly than a text explanation.
- Glawen 3y agoOfficial python documentation is awful to read, I always give up reading and look somewhere else. This page is great, I love it :)
- kzrdude 3y agoI think the online documentation for Python stdlib is quite good. What I don't understand is why more of it is not available in help() from Python itself. For all the docstring features in Python, the stdlib somehow just has second rate documentation in module and function docstrings! Compare with numpy and scipy, where the docstrings are comprehensive (there's a correspondance between online and embedded docs.)
- 1letterunixname 3y agoDifficult to read and lacks a page layout for printing. It should've used font and style variations for placeholders rather than nonstandard and annoying characters like < >.
- Rygian 3y agoI really like those names, 'splat operator' and 'splatty-splat operator.' > Inside Function Call > Splat expands a collection into positional arguments, while splatty-splat expands a dictionary into keyword arguments. args = (1, 2) kwargs = {'x': 3, 'y': 4, 'z': 5} func(*args, **kwargs)
- gpderetta 3y agoHN ate your stars and for a few seconds I was confused that I forgot how python works.
- Timon3 3y agoThis is a good overview, thank you for sharing! One nitpick - the "duck type" section doesn't seem to mention Protocols, which is the "official" name you'll find in the Python documentation.
- sireat 3y agoFantastic amount of information in a single page. . However there are two things I do not like: 1. Use of <identifier> notation for almost everything. It might be technically sound, but it brings to mind reading Backus-Naur form specs. For cheat sheets my_int, my_iterator etc format is more pleasant for eyes. 2. Examples from various external libraries are of questionable real life utility, they are a nice showcase of what is possible, but are really too terse at times - looking at you popcorn audio example. Official docs for libraries such as Plotly or Pandas are much more pleasant. Then again Copilot is even faster for looking up a tricky matplotlib incantation... Thus the cheat sheet should have been split in two parts, one would cover Python and possibly standard library. Second part would cover the popular libraries.
- kzrdude 3y agoColor or underline would be a good marker for the variables. Even better than having a prefix "my_" for the visual noise factor.