#internals-and-peps
1 messages · Page 81 of 1
Lol
What are your thoughts on sticking all imports needed only for typing under the if TYPE_CHECKING condition after postponed evaluation of annotations rolls around?
I've worked with a few libs now where only some utils were needed but imports of types for typing loaded in the whole package
@peak spoke wouldn't that only give you a runtime benefit if you never use those modules during that interpreter session for anything other than typing?
Yes, but overall it could reduce the spread of what's imported. The worst example of this I encountered was with sphinx where it was only necessary for compatibility with their format but the import of the utik function for that loaded the whole package through annotation imports
I wouldn't mind if there's a significant difference in runtime performances
The separation of the import groups may also be useful
i was reading about metaclasses, and i saw a super().__init__ being called on type on the metaclass __init__
but doing some tests, it works normally without using super init
there's any advantage to call the type constructor on a metaclass constructor?
what works normally?
class Meta(type):
def __init__(cls, name, bases, dict):
"""There's no apparent issues not using this super __init__ here"""
super().__init__(name, bases, dict)
well, if that's all there is --- there's no point in the __init__ --- usually to justify it you need something else going on --- a common use is registering a class
but you can use __init_subclass__ for that now
!e
subclasses = {}
class MyMeta(type):
def __init__(cls, name, bases, dict):
subclasses[name] = cls
super().__init__(name, bases, dict)
class MyBase(metaclass=MyMeta):
pass
class MySubclass(MyBase):
pass
print(subclasses)
@deft pagoda :white_check_mark: Your eval job has completed with return code 0.
{'MyBase': <class '__main__.MyBase'>, 'MySubclass': <class '__main__.MySubclass'>}
something like this
👍
>>> tokenize._all_string_prefixes() {'', 'Rf', 'Rb', 'Br', 'u', 'br', 'rf', 'RB', 'B', 'U', 'BR', 'rb', 'Fr', 'rB', 'rF', 'RF', 'F', 'fR', 'b', 'FR', 'f', 'R', 'fr', 'r', 'bR'}```
@rustic stag what does this mean?
It means that Discord was showing me an old message! There was a discussion of mixed-case string prefixes. It turns out it was from about 30 hours ago, but Discord said it was new. So I was showing how to find all of the valid string prefixes. Sorry it was so out of date.
No worries, it's still relevant 🙂
@rustic stag I wasn't asking as a moderation action, I just wanted to know 
@boreal umbra no problem!
I'd say that depends on what you're doing in those try/finally blocks. Maybe use context managers, if it's a resource you're opening/closing? Or if it's a function that throws an exception when something can't be found (like str.index), you could write a wrapper that returns None instead.
If the control flow logic depends on exceptions being thrown, you might not be able to reduce it at all
Oh, and you could always extract those deeper finally blocks into their own functions, that could help too
@rotund atlas okay, I spent some time working on it
I think I kind of have a solution
but it's also not really on topic for this channel
how about you open a help channel? #❓|how-to-get-help
sure
@rotund atlas and ping me
exit stack from contextlib
@rotund atlas See #❓|how-to-get-help. We have our own help channel system, it's not provided by Discord.
Is there a reason why qualified imports avoid circular dependencies within modules? e.g.
# engine.py
from . import environment as ev
# environment.py
from . import engine as en
```vs.
```python
# engine.py
from .environment import Environment
# environment.py
from .engine import Engine
Because if you do import module, it's fine if the module hasn't fully loaded yet.
so if you do
# a.py
import b
# b.py
import a
and run a.py, the first line of b.py will bind the module object to the name a, but that is like a pointer or something
But from module import name requires module to be fully loaded, because any line in it can redefine name
Hmm
that's not exactly right: @brave badger, it's a question of what is available when. If you have:
# a.py
x = 1
import b
# b.py
from a import x
print(x)
everything will work totally fine. That's because modules are executed from top to bottom: when a is imported a module object is created for it, then the code in it starts executing: the x attribute of that module is set to 1, and then b is imported. When b runs it looks up the module object for a, finds it, looks up the x attribute of it, finds it, and everything works fine.
If you instead do:
# a.py
import b
x = 1
# b.py
from a import x
print(x)
then things won't work. When a is imported a module object is created for it, then the code in it starts executing: it executes import b before the x attribute has been set on it, and when b runs it looks up the module object for a, finds it, looks up the x attribute of it, and fails because that attribute doesn't exist - it isn't defined until after b has been imported, which can't happen because b requires it.
And if you instead do:
# a.py
import b
x = 1
# b.py
import a
print(a.x)
you'll get the exact same error even though you're not using a from import, because it still needs to access a.x at import time, and a.x still hasn't been defined when b is imported.
But if you do:
# a.py
import b
x = 1
b.print_x()
# b.py
import a
def print_x():
print(a.x)
then everything works fine: when a runs it creates a module, then it imports b, and b looks up the module a and finds the (empty) module and saves a reference to it, and defines a new function (whose globals aren't yet resolved, so at this point a.x doesn't need to exist; it won't be an error until print_x() is called). Then, the import b finishes, a gets around to executing x=1 (setting the a.x attribute), and then it calls b.print_x(). Back in b, that now looks up the a.x attribute, and since it has now been set everything works fine.
Right, thanks @raven ridge. Qualified imports worked best for me considering that I'm using postponed annotations and the fact that most of my calling code exists within functions and methods.
Yeah, importing the module instead of the attribute you need is definitely helpful for working around cycles, it's just helpful to know why that works.
so anyone here understands binary
i got an exam in 5 mins
ik this is python but i didnt know where to go for such question
@unkempt rock That is not relevant to this channel at all
huh i didnt send anything
In case you're not aware we keep logs so please don't try and troll. I wouldn't have pinged otherwise.
@stoic raptor this channel is for discussion. Please use it as intended
@stoic raptor The developer role is the base role, basically. If you have any other questions about how things work here, feel free to ask in #community-meta.
Ok
@clear rapids
Hey @rotund patrol!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
Hey @rotund patrol!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
@rotund patrol ?
:thonk:
okay so im confused, i can print an f string, i can declare a variable to be equal to an f string, i can then return that variable from a function and it gets interpolated out properly when i later print the return of said function, but i can't directly return an f string from a function - it gives me a syntaxerror.
what's the delta between an f string and a variable equal to an f string that is causing the problem?
what does your code look like?
i mean i can give you a very basic example of what i'm talking about - this is just somethign i had never experienced myself until someone in the general channel asked for help, and debugging it was confusing
the commented out lines include: using a variable and then returning that variable (works), returning a f string (what the person originally had, and i don't have a good sense of why it doesn't work), and then returning a concatenation of strings (also works)
I have to give a presentation on hiding redundancy, complexity anyone can help me please
@wicked holly first off you dont need to do str(self.age) inside an fstring
>>> def s(a):
... return f'{a}'
...
>>> s(1)
'1'
>>> ``` also it works for me
@pliant tusk ugh okay the 'real problem' was i was pointing to a python2 interpreter in my shebang, nevermind me
@buoyant timber I suggest grabbing a help channel #❓|how-to-get-help 🙂
oh ok, im new to this discord, thanks for letting me know
thats an interesting system though
I'm learning advanced algorithms & data structures in school right now and I'm a bit confused on if devs actually create their own algorithm libaries or just use stdlib?
I see python has sorted() but I can't find any documentation on it's source code/how it's implemented/it's running time/etc...Is it normal to make my own merge sort and my own bottom-up cut rod dynamic programming algo?
unless you have extremely good reasons not to, use stdlib
you might want to learn some about python profiling
But there's like 15 different sorting algorithms and stdlib just has one from what I can tell and like I said I can't even find info on what kind of sort it is.
well for that specifically: https://stackoverflow.com/questions/10948920/what-algorithm-does-pythons-sorted-use
And if I want to do sort the countless other ways since there's no such thing as 1 perfect sorting algorithm?
i mean there are people who have done implementations of other algorithms (example: https://github.com/Sayan-Paul/Sort-Library-in-Python/blob/master/sortlib.py)
but from what you're describing, it sounds like what would be most useful would be to mess around with some python profiling tools, so you can have some reference points for comparing two implementations or two different algorithms?
timsort will probably be better than whatever you can come up with in python, since it's in C
it's a combination of insertion sort, and merge sort
...ya but sometimes you'd want to use selection sort since it's better than insertion sort and merge sort for low n or nearly sorted arrays...I don't need a profiler, i know how these algorithms work. You don't just use 1 sorting algorithm for everything, that's ridiculous
no you don't lmfao
sure
you're not an engineer then, just a code monkey
my bad dude
lmfao i forgot all the bootcamp kiddies think they're engineers now
I suggest you read the implementation of timsort
shell sort, quicksort, heapsort
and then you've got things like union-find for the percolation problem that can be implemented all sorts of ways
ya i just looked up timsort, it's not usable for every situation at all
timsort works well on real world data, I suggest you give https://github.com/python/cpython/blob/master/Objects/listsort.txt a read for why it was chosen as the default sort and remained for almost 20 years
You'd rarely want to use anything other than the standard sort in python.
i suggest you read an algorithms textbook on why you can't use 1 sort for everything and why that makes you not qualified to work in the field
There is also a heap implementation in the standard library, for when you need it.
my bad, you are clearly smarter, and a real engineer
no you're just a code monkey that thinks he's an engineer because he read a book on python
but don't actually know CS
I'm sorry I offended you
try to beat the built-in sort with something you make though
maybe you'll learn something
im sure its good for sorting your hentai tho
I don't see timsort on there
I guess it's really just too slow to compare
which is worse than quicksort in real life situations
wonder why its called quicksort?
its quick
you probably didn't learn that in your webshit bootcamp tho
you should contribute to cpython, change the implementation
you might be the next guido
Now look at the current requirements for supporting sorting on an object, and tell me if you can have the same little requirements with quicksort
why not to use c++ or c?
@hazy oak if you know something that another user doesn't, feel free to explain what that is, but the tone you're taking here is pretty condescending and not appropriate for our community.
They left, but quadsort is also faster than quicksort hehe
oh, perfect
lol
Actually, I once benchmarked that a pure python radix sort did a better job than timsort starting with some input size 🤔
but that's true for random data
isn't part of the point of timsort that it's O(n) if the list is already sorted?
yeah because it's smarter than a normal merge sort
is log-linear the best possible runtime for very not-sorted data?
it obviously can't be linear
(right?)
O(n logn) is optimal for a comparison sort
isn't log-linear what nlogn is?
yeah
but there's also bucket sort, which can be better
but it doesn't apply to all data
the guy just seemed like a kid having a meltdown
@wicked holly probably, but they're gone now, so let's talk about Python 😄
he didn't seem to be able of doing basic google searches or profiling on his own, but lashed out at everyone
@last mural tony thot. You can scroll up to read it but let's not waste more time discussing it.
lol
:P
when people get hyper bent out of shape about performance vis python it just sort of makes me roll my eyes... like just wait until you learn about the interpretation lock...
but do they seriously use python in algorithms courses nowadays? we were still using c as of 10 years ago.
@wicked holly I think Python is a good language for learning A&DS because you can focus on how the problem is being solved and not on the implementation details of the language.
mit uses python
what a world
a lot of places use Java I think
my uni uses Java for most classes
most of the programming-specific courses i took were through the engineering department, which were separate from the CS department
i need a bit of cpp help, not sure if i can get any here
the other server which is specifically for cpp isn't active
oops wrong channel
if it's C++11 or older i can probably help you in pms
ok i added friend, i think i changed some settings due to some aggressive spamming i was getting on another server
so I brought it up last week, I remember why I used __new__, I was customizing behavior around int:
https://docs.python.org/3.8/reference/datamodel.html?highlight=metaclass#basic-customization
Is there any problem in keeping a reference to an exception that has a traceback?
It'll keep references to the frame, keeping local etc. alive but the gc should clean them up when it runs if it isn't disabled
hm OK. I see asyncio's Future keeps reference to the exception set by set_exception(). I need to keep a reference because I want to raise it later.
just remember to del after you're done using it
@sacred yew what does that do?
@boreal umbra reduces the refcount
https://stackoverflow.com/a/6798042
does anyone know why __call__ is being invoked for the new class instance versus __init__/__new__? I don't really understand metaclasses yet.
@desert peak you create an instance of a class by calling it: obj = MyClass()
Yes, but doesn't that invoke __init__/__new__? Wouldn't __call__ be invoked by doing MyClass()()?
though i have to tell you, I am opposed to these kinds of singletons.
i'm not sure why it isn't __init__
oh, because you don't want a new object, so you override __call__ to prevent it from constructing an object.
it's better to just skip all this though
@spark magnet my use-case: I'm trying to create an app-wide aiohttp.ClientSession object that will refresh credentials from a vault on bad response from an API I'm integrating to.
why not just have a function that returns the object to use?
so I'm creating a singleton session that will use FastAPI's dependency injection
why is SomeClass() better than some_class() ? It's easier to write the function.
because all I'm doing is implementing __call__ on a class
which is how class-based callables work for fastapi's DI
mostly for the benefit of singletons since I only want one session and I want it to hook into the http lifecycle to refresh credentials on bad responses from my API
while also being easier to test
right, the function could handle the singleton-ness of it
but wouldn't I have to rely on global and a module member with that approach?
yes. instead you have a global hidden inside a metaclass somewhere.
it's not so different, except we can understand the function.
that's true, different approaches to the same goal
Singleton._instances is a global
with a less-hackable way for my coworkers to mutate it though 🙂
if your coworkers would fiddle with the global, you have a social issue, not a technical one 🙂
it seems like Java people wrote a book about patterns, and now everyone thinks Singletons are good and important.
I wish python had more immutable structures
yes, lots of people do.
but Singleton won't protect you from the real risk, which is someone mutating the one object.
(in fact, it increases the risk by lying about object construction)
obj = SomeClass() # is this my object, or shared? ¯\_(ツ)_/¯
just remember to
delafter you're done using it
@sacred yew Well I am takingFutureas reference, I don't see where they manually clear the reference
singletons are only to be used as sentinels or related things in places imo
otherwise they’re used for globally manipulating on stuff which is prone to data races
My main concern is how they are made. There's no reason in Python to write a misleading class to do it.
I always avoid globals and shared state stuff. The bigger the project the messier it gets and more prone to side effects
my use-case is very defined here, I'm sharing an aiohttp session and need to refresh credentials from a vault on API failure
I’m a big fan of always passing in what the function needs
@desert peak yes, that's a great reason to control object creation. You just don't need metaclasses to do it.
I never heard of meta classes and stuff like that until I started touching django projects. It drives me nuts
calling a Class() or a function() should be transparent, no?
What happened to good old oop
metaclasses are pretty fundamental to oop.. lol
In what way
definitely not
here's a good list of metaclass use-cases:
https://stackoverflow.com/questions/392160/what-are-some-concrete-use-cases-for-metaclasses
i don't know if I've ever written a metaclass
frameworks are a pretty major way metaclasses are utilized
They’re not legible in any way
I see frameworks like to use metaclasses because it makes them more usable
hmm, i have written them.
Declarative programming is another thing I see popping up in this thread
if you have a need to affect the behavior of bunch of classes when the class is defined, a metaclass is a way to do it.
(but lying Singletons are still bad 🙂 )
it looks like metaclasses are the reason __new__ exists
from typing import Optional, Type, TypeVar
S = TypeVar("S", bound="Singleton")
class SingletonMeta(type):
def __repr__(cls) -> str:
return f"<singleton class {cls.__name__}>"
class Singleton(metaclass=SingletonMeta):
INSTANCE: Optional[S] = None
def __new__(cls: Type[S], *args, **kwargs) -> S:
if cls.INSTANCE is None:
cls.INSTANCE = super().__new__(cls)
return cls.INSTANCE
def __repr__(self) -> str:
return f"<singleton {self.__class__.__name__}>"``` that's my way to write them
@cloud crypt that's bad
That looks disgusting
why is
I kind of like it 😆
@cloud crypt because your class is lying, and there's no need.
define lying
Declarative programming is another thing I see popping up in this thread
@desert peak Yeah, django'sModeluses a metaclass that allows them to be written in a declarative manner
"I wrote code that looked like I was making a new object, but I got an existing object instead"
mmmm, by that extension, do you think __call__ is bad, too?
I just showed a way to do that if you do it
@cloud crypt why not just use a function to manage the object creation?
I just showed a way to do that if you do it
"if you want to do a bad thing, here's how to do it:.."
I mean, this is kind of python's fault for calling 3 magic methods on object instantiation
@spark magnet my use-case: I'm trying to create an app-wide aiohttp.ClientSession object that will refresh credentials from a vault on bad response from an API I'm integrating to.
this is java's fault for making people think everything has to be handled in a class
Are you trying to rescue the behavior on a failed request? @desert peak
@desert peak you can avoid all the magic methods. write a function.
@elder lodge well, the credentials can expire at any time; they rotate daily
If you get a bad response from the api I don’t think the solution is to refresh credentials in the same request and try again
it's bad UX to have a request fail randomly due to authorization when it can be fixed
@elder lodge cant the object be passed as parameter to others that needs it?
Why don’t you have something that tells you about the expiration of your token?
I think singleton is used because people don't want to pass the references
it's bad UX to have an object construction not construct an object.
so they make it a global object
Aren’t singletons global?
the tools available to me don't provide that information @elder lodge
@tacit hawk I understand the convenience of the global. I'm just suggesting a simpler and clearer way to do it.
@elder lodge if you create a singleton class, that's not guaranteed. None is global, I guess.
I have this information about my environment: credentials rotate every 24 hrs (+/-2hr), the API I retrieve the credentials from is rate limited, and during rotation gives me a rotation-in-progress message
I think an object that hides the credential rotation is a good idea
@boreal umbra None, (), True and False are all singletons.
and certain chars/strings, no?
I hadn't heard about the empty tuple being a singleton but it makes sense given that True and False are aliases for 1 and 0.
but most of that is just an optimization, code would work the same even if they weren't.
@spark magnet I haven't thought of that avenue. Might be worth writing a decorator that caches credentials and automatically rotates underneath the rate limit
I hate decorators too
@desert peak i thought i was saying that your object was a good idea
@elder lodge why
not exactly aliases, bool is a subclass of int, with true and false just having the same numeric value as 1 and 0
I hate decorators and I hate metaclasses
@elder lodge we got that. but why?
or is it
I'm clearly a failure. One moment.
I hate anything that hides implementation and makes code illegible for other developers
!e print(True is 1)
@boreal umbra :white_check_mark: Your eval job has completed with return code 0.
001 | <string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
002 | False
Guess not.
it's bad UX to have an object construction not construct an object.
@spark magnet well I think the singletons would carrySingletonin the name, but without any hint that's really bad
Yea I know what abstractions are
okay you hate metaclasses, sure
I guess you're off writing asm by hand then
have you ever used enum?
@tacit hawk there's no reason to write lying Singleton classes
I thought true and false referred to the same object as the 1 and 0 allocated when the interpreter starts. I'm not sure what I thought the bool class was doing.
I hate anything that hides implementation and makes code illegible for other developers
@elder lodge Don't functions hide implementation?
!e
print(help(bool))
You are not allowed to use that command here. Please use the #bot-commands channel instead.
It's more than that, @cloud crypt I'm pretty sure it subclasses int
it does
it does
I hate anything that hides implementation and makes code illegible for other developers
@elder lodge generally people don't want to know the implementation. The documentation is enough.
@spark magnet yes but I guess what I’m saying is , from a readability standpoint you look at a function and then it’s dressed with decorators that can mutate things and you have to dig into them and i don’t like that
and I was talking about altered behavior on bools
again
@elder lodge but that's like say, "my functions call other functions, so i have to know what those functions do"
Is anyone here experienced with writing integration tests?
just trust the tool or don't use them
decorators are legit one of my favorite features of Python
@opal flame that would be a good question for #unit-testing
I agree, decorators are really nice
I especially like the way different frameworks have utilized them
@boreal umbra thanks
because they can change behavior without changing the code
@spark magnet sure I get that. I just don’t find them readable at all. Especially when you have multiple decorators. It’s a nice convenient feature but many languages don’t have them and are fine
from enum import Flag
class Color(Flag):
BLACK = 0
RED = 1
GREEN = 2
BLUE = 4
YELLOW = RED | GREEN
CYAN = GREEN | BLUE
PURPLE = RED | BLUE
WHITE = RED | GREEN | BLUE``` ever thought what happens behind that
my understanding, from listening to raymon hettingers keynote about being a core dev, is that the enum module is a massive overuse of pythons features
many languages are far more verbose as a result
I thought you could only pipe enums after the class has been defined
the enum module is disgusting and they should've implemented enums as a native language feature
but it's not part of the language
you can't always distinguish between the language and the stdlib
you mean builtin? well it's just a minor detail
@smoky turret yeah it definitely hella is, https://github.com/nekitdev/enums.py I have written a reimplementation of that and I really feel weird about it
enums are such a fundamental part of programming that they should've had their own grammar imo. I would love algebraic types
I didn’t like _sunders_ and related so I rewrote it for myself
https://packaging.python.org/tutorials/packaging-projects/#creating-setup-py
They're missing from setuptools import find_packages here aren't they? Or am i missing something 🤔
I don't really use enums so I'm not sure what they're missing
they are not really missing anything
I only added ability to have control over members, some other funny metaprogramming features and stuff
what really sucks is MRO
https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html
what they could have been /sigh
because types kinda steal your methods
@desert peak i thought that was being replaced by pyproject.toml
@desert peak that is a much different concept of enums — but yeah, definitely
@desert peak cool thanks - it seems the link i sent was wrong still tho?
https://github.com/nekitdev/enums.py#method-resolution-order can someone tell if this is a stupid or fine idea to have
also - most of the projects i see seem to use setup.py, so I'm not sure i follow what's wrong with it
You are missing that they imported the module, not from the module.
ah ofc, that was stupid, didn't read setuptools. there at all for some reason
i really don’t see a need for enums like Rust in Python
anything i should look at re the cfg comment tho? I don't really get it
in Rust, it’s basically essential
with the pattern matching PEP, they would be very nice to have
in Python, not so much
@magic python It's a way to "declare" your options instead of writing them "imperatively"
look up declarative v. imperative programming
less implementation details needed for declarative
you just tell the program what state it should be in
and let the framework handle the rest
sure, ggplot vs mpl etc
i'm familiar with the concept, just that i generally seem to see setup.py
you still use setup.py with setup.cfg
you just leave an empty setup()
for backwards compatibility
maybe i'll get it later then, i don't do much packaging, doesn't seem like a big deal atm tho
I do a ton of packaging and I hate everything about how Python handles it
the pypa example of setup.cfg is pretty minimal too
it's all in .py not cfg, so eh, not very clear
When the need arises, however, Python provides a capability that not all object-oriented languages support: you can get under the hood and define custom metaclasses. The use of custom metaclasses is somewhat controversial, as suggested by the following quote from Tim Peters, the Python guru who authored the Zen of Python:
“Metaclasses are deeper magic than 99% of users should ever worry about. If you wonder whether you need them, you don’t (the people who actually need them know with certainty that they need them, and don’t need an explanation about why).”
— Tim Peters
oh that sample project is garbage
ok good ha
https://github.com/mburszley/bandwidth-monitor/tree/dev
here's a thing I'm working on @magic python
A wrapper for https://www.speedtest.net/ to get time-series data on local bandwidth availability. - mburszley/bandwidth-monitor
to get time-series data on local bandwidth availability
lol, co-worker and i were looking for exactly this earlier
I saw it on reddit and wrote a scheduler and such around it - I was planning on making an API to generate the plots, but haven't had time lately
I went down the rabbithole of getting CI/CD implemented and exploring using tabs in python over spaces and yapf and and and...
rabbithole of getting CI/CD implemented
been trying to do that with R and renv... makes you think python envs are managed well
my plan is to host it on pip eventually when I get another window of time
well, CI/CD isn't difficult, actually. It's the pipeline tool decision that I was struggling with making decisions on like linting and auto formatting, etc.
only think I've used cfg for is flake8 - toml is used for pylint / pytest errors etc, and that's about it ( no packaging )
pytest supports pyproject now? that's new. it also supports the cfg file
yea
I tried using Poetry for this but was dissatisfied with the way it was handling packaging
for distribution
i cba to learn anything fancy i don't think, i just want to package things, which is why using setup.py seemed "standard"
but if it's shifted/ing to cfg maybe i'll do that
I think people use setup.py because there's so much documentation and examples on that, but setup.cfg is a much nicer experience. I'm not sure how much support pyproject.toml has in the broader ecosystem since it's such a "newer" PEP, but it'll catch on eventually
personally I think pip and its ecosystem need to be torn down and started fresh
because there's so much documentation and examples on that
yeah exactly this, there's a load
i've only used R and python, so pythons seems nice I guess
try using almost anything else. nuget, cargo, yarn, all much nicer experiences
python's is a problem because you can have broken environments as a default
yes
i use pip-tools compile for that
because python can only load one version of a package
things like poetry try to solve that problem which is why it sees adoption
what's pip-tools missing that poetry gives
pip-tools only pins dependencies, it doesn't resolve them. poetry resolves all your dependencies against each other so you never have conflicting versions (this assumes some level of dependency pinning in your dependencies, however)
yeah i'd go with the docs over me ha
usually i have something like pandas in requirements.in and pip compile will create requirements.txt with the version info and stuff in there
yeah, compile just pins your dependencies
I think that it does deps as i seem to recall pandas-profiling holding the pandas version back as it was dependent on pandas <=0.28 or something like that... i'm not too sure tho
it doesn't do any resolving of its own
ah ok cheers, good to know
pip has a resolver, but it doesn't resolve against all packages in an environment like poetry will do
it only exists to resolve versions against pypi
poetry also generates lockfiles, so you always get the same version of dependencies and it doesn't have to re-run resolution on install
requirements.txt is a lock file? or not
nope, requirements is just that - dependencies for your app
unless you pin exact versions for every dependency, you can end up with different versions between installs
ok, interesting... i had it in my head that poetry was some fancy new thing that might be gone soon for some reason.... perhaps i should consider it if it's used more
unless you pin exact versions for every dependency
that is what pip-tools compile seems to do afaict
idk why poetry does virtualenvs too, that seems annoying
https://python-poetry.org/
you can check it out for yourself if you'd like to see
Python dependency management and packaging made easy.
you can also configure virtualenvs to be created in your project if you don't like the centralized venv approach:
$ poetry config virtualenvs.in-project true
i do use ~/.virtualenvs but i have stuff that i'm used to I guess so it goes from changing from pip-tools -> poetry for dep management to changing other things as well
how does django do this:
b = Blog.objects.get(name="Cheddar Talk")
how does objects have a database connection automatically?
a global someplace
def get_blog_by_id(session: Session, blog_id: int) -> Blog:
return session.query(Blog).filter(Blog.id == blog_id).one()
is the above less preferred because it's verbose compared to
Blog.objects.get(id=blog_id)
@elder lodge it would be inconvenient to have to pass a session explicitly everywhere you needed it, including into templates.
@elder lodge avoiding globals is a good instinct. but sometimes a well-placed global makes things a lot easier.
Why does this happen?
missing a closing bracket )
My bad
also, not the right channel for this
Can I add you as a friend?
uhh, Im not looking to be someones goto for debugging
@unkempt rock when you see that much repetition, that's a sign there's a better way to do what you're doing
Such AS.
and also, this isn't a help channel. check out #❓|how-to-get-help
Isnt clearly listed.
huh? it's the third category in the list of channels
a dictionary is probably your best bet for this
you should take a help channel, there are a few things wrong with your program
anyone know if django.db is available as an external non-django package in some form? there are a lot of niceties it has--would be nice to be able to use something like that for non-django projects
@elder lodge it's not available separately
Django ORM is its own thing for use in its framework. Checkout SQLAlchemy for a non-Django alternative @elder lodge
It's not available separately, but it is totally possible for you to use Django just for its ORM bits. You'll need to run django.setup() at one point in your program before starting to use the models and the like (and you'll need to set up settings) but it's Just Python ™️
@main folio doesn't it usually go the other way around?
nope
using python for a backend is garbage code
sorry cython not python
cython with a c
python is event worse for a backend thou
but seriously how do you embed cython in c++
is there a cython chat
python is event worse for a backend thou
@main folio what is so terrible about python for a backend?
Any statement in a program can change the value of a global variable. If you find that the wrong value is being stored in a global variable, you have to track down every statement that accesses it to determine where the bad value is coming from. In a program with thousands of lines of code, this can be difficult.
@spark magnet speed
@torpid pollen are you pasting text from somewhere else?
also what he said
@main folio what does your program do?
stockdata
is it doing a lot of calcuation?
numpy could help
yes that's why you use c extensions
raw c is the best
but c is not "better"
it is
we don't need to debate this
dev time >>> run time
3000 iq hours
wut
THE PRODUCT MUST EMBODY PERFECTION
ok he's trolling
for the entire codebase
some
since that's what your argument is for using all c
@torpid pollen are you pasting text from somewhere else?
@spark magnet no
so write raw asm for an entire codebase because it's "better"
asembly isnt much faster then c
c isn't much faster than python with c extensions
alot of the time c runs as fast as assembly
python on the other hand is at best like 50 times slower then assembly
@fickle atlas, its way faster trust me
unless you're talking about cython
cython is amazing
You pinged the wrong person
what language is numpy written in
@main folio we get it, we're not trying to change your mind
c isn't much faster than python with c extensions
@sacred yew
it s way faster
I have concluded that you are incapable of reading a graph
want speed for numeric calculations use fortran
we really don't have to continue this pissing match
Ive read the graph
c++ had less time
thats all that matters
c would've probably done it better
c is faster then c++
you know that right? @sacred yew
seriously go to off-topic if you want to troll or something
@main folio really, let's stop
you're cluttering the chat with non-sense
I'll stop
anyone have luck deploying packages to pypi w/ poetry?
never deployed anything there, so this is my first foray
optimized cython is faster
Stop it and leave.
I'm trying to help
@main folio no you aren't. be nice.
stop being rude, please
@main folio this channel is specifically for discussing the Python language itself. It seems like you aren't really interested in doing that.
cython is an extention of the language of python
yes, but no one was asking how to make things faster.
it's more of a superset of Python. However it seems like you're not really listening to what the other members here are saying.
If you want to do numerical calculations faster, but still do it in Python, you can use numpy and pandas. If that's not enough, you can write the whole thing in C. That's about all there is to say about that.
cython is an area I know
@main folio when someone asks about cython, we will be glad to have your expertise.
@main folio I'd appreciate it if you take a different approach going forward. Comments like "build the best product possible event if it kills you in the proccess" and "THE PRODUCT MUST EMBODY PERFECTION" show that you're more interested in playing around than engaging with people here.
help me install matplotlib this module
@white prism this is a channel for discussion of the language. try #❓|how-to-get-help or #python-discussion? thanks!
that's off-topic
@white prism this is a channel for discussion of the language. try #❓|how-to-get-help or #python-discussion? thanks!
@gleaming rover I don't have permission to write to p-generator how do I get it?
sorry, didn't understand that
matplotlib is usually include
@main folio it's included if you install Anaconda, but not otherwise.
matplotlib is not in the stdlib, it has to be installed.
I was about to say pip3 install matplotlib
sounds like they're being removed in short order
why is curl | sh or curl | python - such a popular install method?
!ban 760221432466243604 user impersonation
:incoming_envelope: :ok_hand: applied ban to @unique notch permanently.
why is
curl | shorcurl | python -such a popular install method?
@desert peak it works
right, I'm curious why they don't get into sys pkg mgrs or pip
pkg mgrs mean getting packaged for a bunch of OS's, pip means your users have to have pip working
at least do wget, then open a text editor to check, then do python3
oh you mean, curl | SUDO python3 - got it
I was installing oh-my-zsh and poetry on my WSL2 instance and they both go the curl | sh route which is why I was expressing my dismay above
it is, but not the recommended installation route
bruh why is the manual inspection one below the self pwn ones
right
?
https://pypi.org/project/bandwidth-monitor/
I did a thing! Just felt like sharing my first published package after much procrastinating
A wrapper for speedtest.net to get time-series data on local bandwidth availability.
Anyone here knows selneium?
@quasi urchin Not the channel for that
claim a help channel if you're after help #❓|how-to-get-help
Is there a way to host python server with open port for free?
There is variation in answer of integration with comparing using scipy.integrate. can anyone help!? How is it so?
Hey @unkempt rock and @meager idol, thuis isn't an help channel, see #❓|how-to-get-help
why doesnt it work```python
def saveText(event=None):
global fileName
if not fileName :
inputName = asksaveasfile(mode='w', title="Save the file", defaultextension=".txt", filetypes = (("Python","*.py"),("Text File","*.txt"),("all files","*.*")))
else:
inputName = fileName
if inputName:
fileName = inputName
content = textField.get(1.0, END)
with open(fileName, "a") as theFile:
theFile.write(content)
root.title('{}'.format(os.path.basename(fileName)))
its not writing into the file
@random bison Akarys just said that this is not a help channel. To get help, see #❓|how-to-get-help
ok
Can anyone suggest me which path to follow for gsoc 2021
And contributing in python open source
@amber nimbus #❓|how-to-get-help
how do I make an if-statement to check if something is in a file name? Like:
if 'data' in file.name:
that should work if file.name is a string
Sounds like a question you should ask in a help channel
This channel is to discuss the Python programming language itself, from a higher-level perspective
See #❓|how-to-get-help for information on how to open your own channel
the other people were also redirected to a help channel..
anyone have experience passing async ctx mgrs around?
I think I'm seeing a double-free happening
@desert peak You should ask in #async-and-concurrency, I suppose
wasn't aware there was a channel for that
I have a PyTest question. Is it possible to parameterize a test with different fixtures? as in pytest.mark.paramaterize('fixture', [(fixture_a, ), (fixture_b,)]) ?
Hey @faint compass and @tepid ermine, see #❓|how-to-get-help, this isn't an help channel
@tepid ermine Akrays directed you to #❓|how-to-get-help. Please read that for instructions as to how to open a help channel, since this one is strictly for discussion. Going forward, please also don't write long, low-content messages like "plzzzzzzzz" where there are many Zs that wrap around numerous times. Thanks!
!mute 755050058193567744 1h Please stop spamming. When this mute ends, you can open a help channel and ask for help with what you're doing.
:incoming_envelope: :ok_hand: applied mute to @tepid ermine until 2020-10-30 19:41 (59 minutes and 58 seconds).
Hi i want to know can i push change with branch name “local-branch” in local to branch name “remote-branch” in remote repo?
@barren quest try asking in #tools-and-devops. This channel is strictly for Python talk.
Are requests faster if i pass the allow_redirects=False parameter in python? Like if i make a GET request to google.com for example and it redirects me to google.de does it do another GET request to google.de which it would'nt if I pass the allow_redirects=False parameter?
@hollow rose if you don't allow redirects, you won't get the data you want.
it will be faster, but you won't get your data, will you?
@hollow rose have you tried it without the redirects?
yes, it will make another get request.
oh, then you aren't trying to get data
so it will redirect me without the param to false right
it will take longer than with allow_redirects=False
yes, it will.
appreciate it! 🙂
@unkempt rock Not Python, unfortunately
this channel is specifically for talking about Python though
@unkempt rock no problem; be sure to check out the channel description for any channel before you comment in it for the first time.
@unborn osprey this is for language discussion; try #algos-and-data-structs
kk sorry
np!
?
@crude glen if I understand the screenshot correctly, it looks like your bot does something that Discord feels is a waste of their resources. However that would be a better topic for #discord-bots
Anyone have any favorite libraries for parsing extended, complex bitfields?
I tried ‘struct’ out but it appears to deal primarily in values that align nicely with byte boundaries
In my case I have some unsigned ints stored in 7 bits, or 10 bits, etc
is there anyone that would be able to take a look a this for me
I am not getting an output; i think i am missing some type of a function but i am not entirely sure
I can in a moment
Thank you
presumably your “hello world” prints adequately, right?
@cedar kiln this isn't a help channel; see #❓|how-to-get-help
if i remove everything below ## this is the second part and run it it will print the helloworld statment
with that second part that is what is messing it up
feel free to ping me directly its no sweat if folks dont want the discussion here
bet thank you
Tho I’d still love to get folks’ thoughts on bitfield parsing 🙂
In JavaScript I always just do it manually but I thought I’d see if I can be cuter in Python...
There any way to put up some pop up or any kind of disclaimer that this channel in particular is not for help? we seem to get people asking for help in here like every hour
Well, “advanced discussion” certainly seems to imply discussion re: python with advanced developers or something.
naming and off by ones...
Though fairchild above lost interest in my helping him once I refused to simply correct the script... 😑
we've tried many many variations on the name, this one seems to work the best so far
metaclass hell
python-meta-discussion
We discussed a lot of different names, and I actually suggested having "no-help" just to see how the rest of the staff would feel about that. However we want all our channels to be welcoming.
If you have any suggestions, let us know on #community-meta
You got it
advanced-usage-no-help
naw, alternative constructors are nice
Like most of my classes these days have one.
what are these classes of?
I use a function overloading package
it's a good tool to remove redundant constructors with different names for different types
@crisp zinc function overloading isn't well supported by python because signatures aren't typed
Is there a reason youre finding them useful in particular?
It’s always kind of hard to say whats appropriate in the absence of context
That is not the same thing @gritty pebble
It doesn't allow for multiple implementations
All implementations need to be explicitly called from the final function which is kinda dirty
The http module doesn't have status code 418 before 3.9?
No
Oh no I'll have to upgrade
hi
oi, thats a very important response code
its up there in the standards with rfc2549
?
?
Assuming those ? are you asking about the response code thing.
418 I'm a teapot
It's from some April Fools
???
#advanced-http-discussion but 418 was actually described as having a serious purpose: "it identifies many of the ways in which HTTP has been extended inappropriately", the protocol is actually fairly interesting if you get around the whole coffee analogy https://tools.ietf.org/html/rfc2324
what is that....
@signal tide the RFC serves a serious purpose, not the 418 status code, to be clear.
yes - an April fools joke intended as satire about the HTTP standardization process.
it really is ironic isn't it
i'll just leave this here
@tasks.loop(seconds=0.01)
async def SocketRocket(self, request_man: RequestManager):
ok there's a coin flip discord bot (assuming its written in python)
prolly use a random to generate a number >0.5 tails, <0.5 heads
random uses a mersenne twister PRNG feeding the timestamp
How do you possibly predict the next values
@flat gazelle did a quick search in the channels looks like you know about seeds and PRNG could you possibly help thanks
@unkempt rock This is not a help channel, see the channel description. See #❓|how-to-get-help if you want to get help with a question.
I mean, the point of a rng is that you can't predict the values
you can store the state of the random generator, then generate the next few numbers just to peek, then restore the state of the random generator.
I guess the person was asking about details of rng implementation
Mersenne twister can be broken afaik
But with random()<0.5, it's not at all worthwhile to try to crack
624 iterations is enough to predict all subsequent values, but only if you have access to all of the bits
https://pl.m.wikipedia.org/wiki/Mersenne_Twister#Zastosowannie (in polish but you can click on citation 2 for an English link)
oh, if you don't have access to the code, it's not possible.
anyway, this is off-topic here.
Quick question, CPython only allocates/frees memory from the OS in big blocks right?
thats generally less about Cpython and more about the OS
windows i think allocates in nKB chunks
it's absolutely about CPython, actually.
@visual harness I believe that question would be implementation-specific for which operating system's syscalls are being used.
is the Cpython is the "main" python interpeter?
@radiant fulcrum would you know by any chance of how to work with cmd sessions with os module?
nop
hi guys im panda i wanted some help in python im just a beginner soo please bare with me
hey guys can u please help me with this its a program to count the uppercase lowercase and alphabet and digit in a string
@next cliff hello, this is not the correct channel to ask for help in. Please read #❓|how-to-get-help and use a help channel.
@next cliff lakmatiol is right that this isn't the right channel, but if you open a help channel I'll come find you
i am sorry
Quick question, CPython only allocates/frees memory from the OS in big blocks right?
@visual harness yes. https://docs.python.org/3/c-api/memory.html
is the Cpython is the "main" python interpeter?
@unkempt rock it's the most common one, yes.
Most OSes prefer memory requests in bigger chunks then having process a ton amount of memory requests for tiny amount
That's a relief
@spiral willow that's true, but not exactly relevant. See the link I pasted: CPython has its own memory arenas, above and beyond whatever the OS might do. So the answer is unequivocally "yes", regardless of OS.
@unkempt rock it's the most common one, yes.
@raven ridge Is there a difference beetween other ones ( Afaik there is rust one )
I don't know of any rust one, but perhaps there is one.
what is the difference
I know of CPython, pypy, IronPython, Jython, MicroPython, CircuitPython...
what is pypy?
and ironpython
and jython?
and mcropython
and ciruit one?
I dont one anyone I only know Cpython and use it
pypy - a Python interpreter written in Python with a JIT
ironpython - a Python interpreter that runs in the .net clr
jython - A Python interpreter that runs in the Java JVM
micropython - A minimal Python interpreter designed to run on microcontrollers
circuitpython - a fork of micropython designed to be easier to teach, and to have greater uniformity across different microcontrollers
written in python!?
lel
and yes
why there is lots of things like this
I would say "An developer say: Don't repeat yourself." to guido
because they work better than CPython in different niches, and because people find them fun to build.
install it from your package manager, or download it from https://www.pypy.org/
why guido didnt made a compiler too?
@unkempt rock You mean, why does CPython not have a JIT?
JIT?
just-in-time compiler. It translates bytecode to machine code at runtime.
I mean why guido didnt made a compiler for Python to compile Python but made lots of unnecessary interpreters
Because python was never intended to be a compiled language
Guido didn't make any of those interpreters.
He made CPython; other people made all the others.
If Cpython had a JIT though that would be pretty cool
soo
why people didnt made a compiler too
He made CPython; other people made all the others.
^^
pypy has a Just In Time compiler, like I said.
Cython (as opposed to CPython) can compile Python code to C code that can be compiled as a CPython extension module... That's the closest thing I can think of to what you're asking about.
If Cpython had a JIT though that would be pretty cool
@amber nexus There was some talk about CPython getting a JIT in 3.12 or 3.13 in last week's core dev sprints, from what I've heard. It may come one day.
Yeah I heard it was a possibility
that may just be aspirational, but it's definitely on the table.
I wonder how significant the speed boost would be with a JIT
I would expect something along the lines of PyPy for pure Python code but is it too much to expect?
Nothing wrong in hoping, although if that was the case, I'd be really happy
Cython (as opposed to CPython) can compile Python code to C code that can be compiled as a CPython extension module... That's the closest thing I can think of to what you're asking about.
@raven ridge how can I install / use it
btw guys
how python import keyword works?
where can I find o n l y import's source code
@raven ridge how can I install / use it
@unkempt rock https://cython.readthedocs.io/en/latest/src/tutorial/embedding.html
how python import keyword works?
@unkempt rock it imports a file in the current name space
where can I find o n l y import's source code
@unkempt rock surprisingly, there are many files for this single keyword
@unkempt rock https://cython.readthedocs.io/en/latest/src/tutorial/embedding.html
@raven ridge ty 🙏
@unkempt rock surprisingly, there are many files for this single keyword
@true hollow source code != ONE File
it can be lots of files
it's not even one language.
@raven ridge Cpython
most of the code is in https://github.com/python/cpython/blob/dff1ad509051f7e07e77d1e3ec83314d53fb1118/Python/import.c though
it's in the:
- grammar file
- token file
- Python/import.c (core)
- the parser, ast and tokenizer
- evaluator
oke ty
still the import.c is quite complex tho
aa wait
I'm not sure why you'd want to play with the import keyword
arfgh
right. .pyc files are bytecode, not machine code.
when you execute them the evaluator is directly called
from sys import argv
file = open(argv[1])
for line in file:
if line[:5] == "print":
print([5:])
file.close()
haha interpreter
Python can do things that cannot be done in languages that compile to machine code at build time, and then just run that machine code at runtime.
It's impossible to have a feature like exec without running an interpreter at runtime.
or eval for that matter.
cpython is just a complex case
@true hollow I red lua source code too
its complex too
Well yeah, all major languages are going to be complex
the first version of an interpreter is gonna be pretty simple. The longer they live, the more features are added, and the more complex they get.
and yeah a guy said me fork lua its easy to customize
I mean you can just edit the language so yeah
You have to actually understand what you're doing when customising it so as to not break anything but if you have that knowledge then sure
So you're trying to change a language, it make it more like another language
That just sounds like quite the rabbit hole that's going to waste a lot of time for little payoff
:P
Its for myself actually
importis not good
^^
I need a keyword like #include in c on python
Well goodluck with that
?
I wont make something
I dont know how to :P
import sucks
I even cant import another file in another directory
like
Yes you can
I need a keyword like
#includein c on python
@unkempt rock you could literally just run your Python code through a C preprocessor, potentially - though you'd need to avoid#comments that might be recognized as preprocessor commands.
What's your point?
I cant include includeMe.py from main.py like import "../bar/spam/includeMe.py
You can
You can import it but not like that, no
@unkempt rock you could literally just run your Python code through a C preprocessor, potentially - though you'd need to avoid
#comments that might be recognized as preprocessor commands.
@raven ridge I mean#includefunctionilaty
so do I.
if you ran your code through a C Preprocessor, it'd do the including.
that's not a good idea - but it's possible.
The ability to import code from any old python file literally already exists
how?
It's just you wouldn't do it using import alone
There are multiple ways you can do it
The C preprocessor is a separate phase of compilation that isn't really part of the C compiler, and can be done independently of compiling C code - and there are other languages that are built to use the C preprocessor. Not many, but some.
if it's in a package, you can from ..bar.spam import include_me FWIW
What.
#include "../bar/spam/includeMe.h"
sure. but it does something completely and entirely different, too, so 🤷
import importlib.util
spec = importlib.util.spec_from_file_location("module.name", "/path/to/file.py")
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
foo.MyClass()
I found this on https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path
and its impossible in interpreters
it will break everything if you are interpretering it from other file
I always put my program's files to /opt
are you trying to get something that behaves like C's #include? Literally pasting in code from another file into a single module?
so exec(open("/path/to/file.py").read()) ?
it pastes the whole code to main.py
AssemPy loop:
def loop():
# loop code...
loop()
but why
idk lel
exec(open(...).read()) is a much closer Python analog to C's #include than import is.
hi
hi
how do you scrape a website that has no homepage ?
o.O
hello
hello
@subtle lion This is not a help channel, see #❓|how-to-get-help and claim a help channel if you want to get help.
yeah i know had one opened earlier for about an hour. think its a way to advanced question.
sakai in the main general might have had an idea. so ill try it later.
It's not questions that you find advanced, it's more of a discussion channel. Help channels are fit for questions of any level.
ah ye then i missunderstood. 🙂
python might be good at aloot of stuff but finding a needle in a haystack might be too difficult yet 🙂 thats more or less the lesson i learned today 🙂
Is there any place where it's easy to find discussion about a given PEP? There are some PEPs that were proposed that I find interesting that just sort of never happened - and I'd love to hear the original reasons for/against them
Usually the pep themselves have a link to the mailing discussions in the foot notes
@unkempt rock do you really want to implement #include
aka the shittiest "import" system in existence

Are you sure that copying and pasting code from the specified source file into the target file is a better import system than the one implemented in Python?
@unkempt rock
If you really think so... As it was mentioned before, you can use the C preprocessor.
c is awful
its literally header copy-paste
python import may be bad
but c #includes is even worse
doesn't cpp have modules now?
and #include is supposed to work with header files
but if you're copy pasting the source code
that makes it so much more inefficient
$ echo "}" > o
$ echo "{" > c
$ echo "
#include <stdio.h>
int main
()
#include \"c\"
printf(\"Hello World\");
#include \"o\"
">main.c
$ gcc -L. -o main main.c
$ ./main
Hello World
personally I think that something like JS imports would be better
yeah, not too fond of python imports
they make sense once you understand them, but even then they are a bit unwieldy.
import { name, draw, reportArea, reportPerimeter } from './modules/square.js';
so much nicer than python
don't need to mess with relative imports
that break half the time
that doesn't really leave room for things like import hooks, so I am not really in favour of just straight up files. Not sure how to improve it tbh.
hm thats a good point
what happens if CPython runs out of memory while allocating an exception object?
in order to handle it sanely it would have to
allocate another exception object 
It will drop the topmost stack objects anyway, so it will have some place to create it
ohh nice
hi guys am new to Django can you recommend me a book that cover Django pretty good
im learning c
but coming from a python/high level background c is really complicated
i mean im really good with python, i kind of know how c works but it still is complicated even for a "expert python programmer"
any tips on how to break that wall??
Recognize that it's a lower level of abstraction compared to python, so it will be a bit awkward at first. Honestly, my best tip is, ask yourself "how does it actually work" whenever you think of some python code.
That may help you prime yourself to thinking in C terms.
are there any examples of open source web projects using celery?
Is there a generic typehint suitable for keyfunc argument return values, or is it normal to just leave that as Any?
you mean like a HKT?
That was a red flag from me.
@night viper I suppose HKT could be used for this, I'm just surprised there isn't a type like Comparable or Orderable for having __eq__ and __le__ or such defined like Hashable for __hash__
Probably I could define my own with ABCMeta tho
yeah like a concept or typeclass. It would be cool but I guess the ship has sailed on the object model for how mixing work. all objects can have eq and le. And tbh typing in Python is documentation only since you don't get any of the std benefits. if you plan to type so much then a compiled language might be nice
I'm using typehints just to smooth out development
Some of the dependency injection stuff I do would be a struggle to build even in the most modern typed languages I've looked at
Anyway, I really don't care about whether a keyfunc returns an int or a tuple or a str, so long as it can be compared to itself, which is the general expectation for keyfuncs anyways. Since they're a python idiom I was surprised to see they're not captured by a type hint prebuilt
hello there
:incoming_envelope: :ok_hand: applied mute to @vast frigate until 2020-11-02 18:39 (9 minutes and 59 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).
Does anyone knows how to import a library and create a function in the same line ? Is it possible in python 3.6 ?
something like import math; def f(x): return math.exp(x)
Can't find anything
that would work, though I don't really see why you'd want that
It's syntax error. I'm trying to make my code in one line
I guess you could use __import__('module'), look into #esoteric-python for that kind of stuff
@gilded imp
def f(x): return __import__('math').exp(x)
I'm uncertain you could call yourself an expert python programmer and call learning C "really complicated"
I mean, you have to consider memory semantics and new syntax, but it's still just programming.
c honestly isn't that complicated
the only "extra" things it has is manual memory managment
@gilded imp why did you want it all in one line?
Im trying the past 3 days to solve a 2kyu kata in codewars. Im 4 and i want to rank up. So its a one line kata
I've done with the solution, I now have to short enough my code
Of course the function is more complicated than the other above.
are there more reasonable katas you can do instead? This is just obscure trivia.
There are a lot but I just liked that. It contains math-geometry and I study maths so I chose that.
@worthy widget Hi. This is not a help channel, this is a discussion channel. See #❓|how-to-get-help.
alright
Not much at this time
Which book is best for python(beginner)?
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
I think "automate the boring stuff" is most often recommended to beginners, but it's not the one I used. This channel is for advanced discussion about the language so stick to #python-discussion for other topics.
Nvm, I mixed up isinstance with issubclass
Hahaha...
Anyhow, do you guys have any tips for mapping __init__ parameters to UI elements? I'm using PyQt5 and I'm trying to initialize classes from GUI.
Get the signature from the class?
Hello I would like to build a webapp server to host Python applications similar to the Mathworks webapp server: https://www.mathworks.com/products/matlab-web-app-server.html
What infrastructures and what tools do I need?