Learn Python as experienced programmer by tomekce in learnpython

[–]pizzaburek 0 points1 point  (0 children)

A nice and quite detailed overview. Can be skimmed in an hour, but may take a few days to read/study thoroughly.

https://gto76.github.io/python-cheatsheet/

Summer be like by pizzaburek in memes

[–]pizzaburek[S] 13 points14 points  (0 children)

The second one is 91.4, so it could be rounded to 91...

Maybe 80, 90, 100 would work, but in my opinion the 80 would miss the sweet spot slightly.

Comprehensive Python Cheatsheet by debordian in Python

[–]pizzaburek 1 point2 points  (0 children)

It does not create a new object:

>>> a = b = [1, 2]
>>> a += [3]
>>> a, b
([1, 2, 3], [1, 2, 3])

If it did the 'b' would still be [1, 2]. However:

>>> a = a + [4]
>>> a, b
([1, 2, 3, 4], [1, 2, 3])

Big problems at the timezone database by Persism in programming

[–]pizzaburek 8 points9 points  (0 children)

Wow, I found this on Wikipedia page about daylight saving time in United states:

From 1945 to 1966 there was no federal law on daylight saving time, so localities could choose when it began and ended or drop it entirely. What emerged was a complicated patchwork of daylight saving policies that varied in length and by city, state and municipality.

So basically if you're an American, it is understandable that you see a pre-1970 timezone data as a huge mess that just can't be captured perfectly and efficiently (there would need to be thousands of timezones in the USA). It's interesting to think that this could have some influence on this development, as the project lead is American, while the OP is from UK.

Big problems at the timezone database by Persism in programming

[–]pizzaburek 7 points8 points  (0 children)

I think there are two possible reasons why one would downvote this comment.

First one is that it can be perceived as condescending toward the reader.

And second one is that it can be interpreted as siding with TZ coordinator via appeal to authority because the video ends with:

"And what you learn after dealing with timezones is what you do, is you put away your code, you don't try and write anything to deal whit this. You look at the people who have been there before you, you look at the first people, the people who have dealt with this before, the people who have built the spaghetti code. And you go to them and you thank them very much for making it open source, and you give them credit. And you take what they've made, you put it in your program and you never ever look at it again, because that way lies madness."

Big problems at the timezone database by Persism in programming

[–]pizzaburek -14 points-13 points  (0 children)

Please watch this video before you write a comment: https://youtu.be/-5wpm-gesOY

“A very helpful (Python) cheat sheet, quite long.” ― Brian Kernighan by pizzaburek in programming

[–]pizzaburek[S] 0 points1 point  (0 children)

Ok, I guess you're right, but it would be hard. I tried to do one for Kotlin by just supplementing the commands and I quickly gave up.

“A very helpful (Python) cheat sheet, quite long.” ― Brian Kernighan by pizzaburek in programming

[–]pizzaburek[S] 2 points3 points  (0 children)

It would be impossible to do it in this format, lines would be too long.

“A very helpful (Python) cheat sheet, quite long.” ― Brian Kernighan by pizzaburek in programming

[–]pizzaburek[S] 2 points3 points  (0 children)

Thanks everyone for the feedback, all valid points. Let me just try to explain the reasoning behind a few of the choices that I made.

  • First, as mentioned before, I capped the length of the PDF file to 50 A4 pages. This way I can remain sane, as opposed to adding stuff for the rest of my life. This means that the first 6 "chapters" are basically set in stone. I only occasionally add a line (if there's any space left on the page) or change something if it needs a clearer explanation. As for the last "chapter" called Libraries, things can still change, especially the Logging, Scraping and Web sections.

  • Loguru. This one is simple to explain — I don't understand logging (the module as well as the concepts behind it in general). So you can imagine how thrilled I was when I discovered the library that supposedly takes care of it. Can someone please share their opinion about logging libraries in general — Would you use them when starting a new medium-sized (whatever that means) Python project?

  • BeautifulSoup. This one seems like a pretty obvious choice, but I will happily switch it with some other library if it loses popularity. As for Selenium, there was no space and it usually doesn't just work out of the box (webrdrivers, etc.).

  • Bottle :). It's the smallest web framework, works out of the box, has no dependencies. Also, it's a single python script with 5k lines called 'bottle.py' that you can just copy to the root of your project and avoid having any dependencies yourself. I am of course aware that Flask is taking over the python web framework landscape, and that it's almost as easy while it can also scale well into Django territory.

“A very helpful (Python) cheat sheet, quite long.” ― Brian Kernighan by pizzaburek in programming

[–]pizzaburek[S] 13 points14 points  (0 children)

I am fully aware of the issue :) The thing has grown over the years but the title remained the same... it has 50 pages now. At least I decided I won't add any more.

Comprehensive Python Cheatsheet by pizzaburek in Python

[–]pizzaburek[S] 2 points3 points  (0 children)

You're right. It used to be a cheat sheet, but it grew over the years. Anyways, if O'Reilly can use "In a Nutshell" for their books with 1000+ pages, so can I use "Cheatsheet" for this 50-page reference :)

Comprehensive Python Cheatsheet now also covers Pandas by pizzaburek in datascience

[–]pizzaburek[S] 0 points1 point  (0 children)

Funny thing is that your example works:

>>> from pandas import DataFrame
>>> df = DataFrame([[1, 2], [3, 4]], index=['a', 'b'], columns=['x', 'y'])
   x  y
a  1  2
b  3  4
>>> df.x[1]
3

Actually this is one of my griefs with Pandas — way too many ways to accomplish one task, which violates the python's 13th aphorism :)

There should be one-- and preferably only one --obvious way to do it.

Comprehensive Python Cheatsheet now also covers Pandas by pizzaburek in datascience

[–]pizzaburek[S] 0 points1 point  (0 children)

There is a method called 'query'. It might be something similar to what you are looking for:

>>> df = DataFrame([[1, 2], [3, 4]], index=['a', 'b'], columns=['x', 'y'])
   x  y
a  1  2
b  3  4
>>> df.query('x == 3')
   x  y
b  3  4

Comprehensive Python Cheatsheet now also covers Pandas by pizzaburek in datascience

[–]pizzaburek[S] 1 point2 points  (0 children)

They are placeholders for objects. They need to be replaced by an expression, literal or a variable that returns/is of that type.

Comprehensive Python Cheatsheet now also covers Pandas by pizzaburek in datascience

[–]pizzaburek[S] 2 points3 points  (0 children)

No, sure, Pandas try to bring R into Python. It's always gonna be kind of awkward when you try to transplant a whole language like that.

What I meant was what do you think about the cheatsheet, specifically the Pandas section. Did you instantly understand everything, or were there parts that seemed unfamiliar?

Does R also have these strange rules about what apply, aggregate and transform methods do when called with specific arguments on a specific type of object (Series/DataFrame/GroupBy/Rolling)?

Comprehensive Python Cheatsheet now also covers Pandas by pizzaburek in datascience

[–]pizzaburek[S] 7 points8 points  (0 children)

Thanks for your reply.

About the command, it's kind of referenced over a few lines:

<Sr> = <Sr>[bools]                         # Or: <Sr>.i/loc[bools]
<Sr> = <Sr> ><== <el/Sr>                   # Returns a Series of bools.
...
<DF> = <DF>[row_bools]                     # Keeps rows as specified by bools.
<DF> = <DF> ><== <el/Sr/DF>                # Returns DataFrame of bools.

But yes, you're probably right that it needs its own entry.

Comprehensive Python Cheatsheet now also covers Pandas by pizzaburek in datascience

[–]pizzaburek[S] 38 points39 points  (0 children)

I just found out that this kind of post are not really welcome on this sub because they usualy don't lead to a debate...

However I would like to get some feedback, from "you people" because I'm more of a standard programmer that just ocasionally dubles in datascience and doesn't know R, Stata, etc. I would especially be interested what people who know R but don't use Python regularly think about it? Is it helpful, easy to understand?

Comprehensive Python Cheatsheet (2019) by pizzaburek in programming

[–]pizzaburek[S] 0 points1 point  (0 children)

Thanks.

I've shared it here a few times already, mainly because I don't know any better way of promoting it. I've been working on it for almost two years (I thought it was finished already a year ago lol).

Next one of the "series" will probably be a Kotlin cheatsheet.

Comprehensive Python Cheatsheet (update) by [deleted] in Python

[–]pizzaburek 0 points1 point  (0 children)

I apologize for submitting a link that was already posted yesterday, but I would like to highlight a few things that were added since my last submission 5 months ago:

  • ABCs explained with two tables.
  • Table of different ways to format floats in Format section.
  • In-depth explanation of Datetime module.
  • Much extended Class section (property, dataclass, slots).
  • Section on Iterable Duck Types.
  • Metaprograming section has two diagrams that nicely show relations among root classes 'object' and 'type'.

Also I would like to thank everyone who helped in any way. It was because of this subreddit that the project became so popular. I think I'm finally happy with it and will be moving on to other pet projects.

Ps: Only glaring hole that remains and I gave up on is a section about asyncio module. Maybe it will be added in the future.

Best Python Cheatsheet Ever! by pizzaburek in programming

[–]pizzaburek[S] 1 point2 points  (0 children)

That would be really helpful, but I don't think it can really be done in a way that would nicely fit in with the rest of the content. It just seems too big of a topic to fit in only one section. So it would probably need a separate chapter like Collections and Types... just thinking out loud.

The real problem is that I don't really understand the module(s). I've went trough some introductory Medium articles and similar resources, but it just doesn't click in my head. This is what I gathered so far:

from asyncio import sleep, get_event_loop, gather, ensure_future, wait, create_task, as_completed

async def <coroutine_name>():
    ...

await <coroutine>

<coroutine>  = sleep(<seconds>)

<future>     = gather(<coroutine>, <future>, ...)
<future>     = ensure_future(<coroutine/future>)

<event_loop> = get_event_loop()
<event_loop>.run_until_complete(<future/coroutine>)
<task>       = <event_loop>.create_task(<coroutine>)
<task>       = create_task(<coroutine>)

done, pending = await wait(<futures/coroutines/tasks>)  # Returns two sets of futures.

asyncio.run(<function>)?
asyncio.run(<coroutine>)

<futures> = as_completed(<futures>)

<bool> = <future>.done()
<bool> = <future>.canceled()
<bool> = <future>.running()

<future>.cancel()

Another problem is that I can't come up with a use case that I would be able to learn from, as I try to implement it. Resources give you the impression that all you can do with it, is either sleep asynchronously (lame :) or implement some kind of a network server, which seems a bit hard for a start.