eugeneyan / eugeneyan-comments

1 stars 1 forks source link

https://eugeneyan.com/writing/uncommon-python/ #60

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Uncommon Uses of Python in Commonly Used Libraries

Some off-the-beaten uses of Python learned from reading libraries.

https://eugeneyan.com/writing/uncommon-python/

kvnkho commented 2 years ago

This content is good! Thanks for writing more advanced content.

xinofekuator commented 2 years ago

That said, is there a reason not to use relative imports? Please comment below!

Regarding relative imports vs absolute imports I find this StackOverflow answer quite useful.

I personally prefer the absolute imports syntax, but it might be just due to been used to it. Rearrange the structure of the packages is not that hard using an IDE to refactor the imports. Regarding the modules inside packages issue, I personally dislike having modules inside packages instead of having them installable with pip. What would be a case where having modules inside a package would be preferred to publish it in pypi (either public or private)?

xinofekuator commented 2 years ago

Thanks a lot of the content, very interesting details that are not widely known. Most of the things were new to me.

The latter states that it’s better to have a simple but slightly incomplete solution than a comprehensive but hard-to-maintain design.

100% agree. As a developer is sometimes hard to remove your own code complexity, I guess that is where working in teams and doing PR reviews gets handy as it is easy to suggest removing not needed complexity in some other's code I think.

vocdex commented 2 years ago

Thanks for the content! I just needed to read this today

siddheshmhatre commented 2 years ago

Thanks for this blog, super informative!

In this section is there a reason why you used relative imports in the models example

from .tree import DecisionTree, RandomForest
from .bandit import Bandit, TSBandit

and not in the app example?

from model_implementation import SimpleModel
from data_implementation import SimpleDataLoader
eugeneyan commented 2 years ago

@siddheshmhatre Good point—updated!

eugeneyan commented 2 years ago

@xinofekuator

What would be a case where having modules inside a package would be preferred to publish it in pypi (either public or private)?

In this case, I'm referring to .py files in packages as modules which may not be reusable by the public and thus not worth the effort to publish to pypi.

kvnkho commented 2 years ago

@eugeneyan I don't know if this is of interest to you, but James Lamb (a maintainer of LightGBM) talked about why we shouldn't publish tests/artifacts/etc. in SciPy here. A bit expected, but going into the numbers helps give insight to the problems end users face.

jkbellew commented 2 years ago

Hey I really enjoyed this content. Keep up the good work. I came for the first paragraph about Using super() in base classes and was able to follow along and understand by playing with the sample code. Keep that up I would have liked to have done the same thing with When to Use a Mixin.

main-Pynerds commented 3 months ago

At least I have understood the difference between @staticmethod, @classmethods and instance methods.