#internals-and-peps

1 messages Β· Page 64 of 1

somber halo
#

I've been using rapidjson as a JSON parser lately

pseudo cradle
#

I'd kill to be able to parse jsons instead of binaries, lol

narrow kettle
#

is it a custom format?

radiant fulcrum
#

overall it seems orjson is the fastest out of the json parsers overall

#

followed by ujson

#

tho hyperjson had the most consistent time taken overall

pseudo cradle
#

Jay, if you're asking me, I'm creating parsers to a few different types of binary files that aren't necessarily distinguished via extension

#

So I have multiple files ending in .dat for example that are binary files with different file structures

#

It's "fun"

#

No it's not, it's the least fun part of my project

#

I don't even have the file structure for one of the files

narrow kettle
#

i mean if you know the format before hand it doesnt sound too bad

#

ahh

#

rip

pseudo cradle
#

Yeah....

narrow kettle
#

ive done similar things but for network protocols

pseudo cradle
#

Thankfully my employer knows it's a clusterfuck and isn't holding it against me that I'm struggling with it

narrow kettle
#

find hte person who wrote it and wack them with a hammer

pseudo cradle
#

That's pretty high on my to-do list tbh

#

Webdev is a huge black box for me. From what I hear it doesn't take too much to grasp the basics, but I'm not that motivated to learn it

grave jolt
dim plank
#

ohhh sorry

grave jolt
hollow sky
#

Has anyone used PySpark on Databricks(AWS) in Production? If so, what does your CI/CD pipeline look like for different environments and are there any community tools which can help in CI/CD of PySpark job scripts.

fickle minnow
north root
#

is that adding 1 to counter when __str__ or __repr__ is called?

paper echo
#

@hollow sky i've used it but i have no idea what a proper CI/CD pipeline is like. also this is probably better suited for #tools-and-devops

hollow sky
#

Thanks, will do πŸ™‚ I am new here, so it might take a bit to figure what goes where.

radiant fulcrum
#

well then

fickle minnow
#

is that adding 1 to counter when __str__ or __repr__ is called?
@north root its a __str__

dire wing
#

What ide should i use on i3-5010U 4gb ram?

unkempt rock
quaint lion
#

vim

dire wing
#

Ide not text editor :P

grave jolt
#

I have i5-3230M (which, as I have peeked at some benchmarks, is pretty similar in benchmarks) and 4GB of RAM. Actual performance depends on many factors such as graphics card, RAM speed, disk speed etc.
VSCode with Python+Pyright+some other garbage like coloured parentheses runs just fine. PyCharm can be a tiny bit slow with large projects.

#

"IDE" and "text editor" is not a dichotomy and are pretty vague terms.

quaint lion
#

you can use jedi with vim, vsc with python also uses jedi

grave jolt
#

@dire wing Also, this is not the right channel for this, read the channel description. Ask in #tools-and-devops

terse hill
#

if i had to create a custom hash table (using my own hash function), any resources on what may be a good and simple one to use in an interview for an unknown data set?

raven ridge
#

"general purpose hash function" is the term to Google

terse hill
#

thanks @raven ridge

pseudo cradle
#

But what about the wide world of hashing, how thrilling it is to explore polynomial hashes! πŸ˜„

feral cedar
#

no

pseudo cradle
#

😦

#

Fine, I'll admit, I learned all kinds of complicated hashes but I didn't really have fun doing it

#

It was more just annoying and I love having that all handled in the background in Python 😦

feral cedar
#

πŸ˜ƒ

subtle whale
#

Is python list comprehension parallelized?

#

for example

#

a = [x[0] for x in l]

feral cedar
#

πŸ€”

loud summit
#

!ban 571722029049577472 joined just to post a penis copypasta

fallen slateBOT
#

:incoming_envelope: :ok_hand: applied ban to @balmy mantle permanently.

subtle whale
#

thank you

#

anyways

#

is list comprehension parallelized in python?

#

because it should be, I mean you have independent elements that can be dealt with separately

spark magnet
#

it is not parallelized

peak spoke
#

As in its processing being parallelized for performance?

subtle whale
#

yes

#

it should be. See the simple example I posted right after

#

parallelization can easily make that example faster

spark magnet
#

it's easy to make an example that shouldn't be parallelized, and Python can't tell the difference.

#

better to have the programmer say when it should be parallelized

subtle whale
#

can list comprehensions be parallelized?

peak spoke
#

It can accept any expression which can't be handled in C outside of the GIL, and the overhead of doing it in separate processes is far greater

spark magnet
#

@subtle whale there isn't a simple way to do it. You can use libraries for that.

#

Python in general doesn't run Python code on more than one thread at once.

subtle whale
#

I seem to be hitting a brick wall in terms of speed when it comes to Python.

raven ridge
#

it can't easily be parallelized because the stuff done for each element in the comprehension can be arbitrary Python code, and arbitrary Python code can't be run without the GIL being held, which means it's necessarily serial

subtle whale
#

So I am looking for ways to make my code faster

spark magnet
#

what does your program do?

#

have you tried PyPy?

subtle whale
#

well, it is code I am writing for my master thesis. Long story short: I look at images and predict trajectories of dynamic obstacles. I have to draw a lot and check pixel values too to make sure the predicted trajectory is on the road

#

can pypy be used with opencv and numpy?

spark magnet
#

yes to numpy for sure

teal yacht
#

We can't really give any advice without seeing your code really, but there are caveats to numpy, are you sure you're not falling into these ?

subtle whale
#

caveats?

teal yacht
#

using loops, using np.concat/np.append like you would use list.extend/list.append, making bad slices which copy, etc

subtle whale
#

I will link my code here and ask for advice again. Thank you and also thank you for mentioning PyPy, it seems very interesting and I will give it a try

teal yacht
#

If your code is heavily based on numeric computations, which it appears it is, numba can give you a fair boost of speed for almost free

#

You may need to adapt your code tho

subtle whale
#

numba doesn't work with opencv

teal yacht
#

no but it can be used to accelerate pure python and numpy functions

#

then you can wrap your opencv code around these

subtle whale
#

hmm true, would you recommend cython or numba?

#

I heard almost everyone favor cython over numba

teal yacht
#

numba is definitely easier, but it's really only for numeric computing

#

which seems fine here

#

I'd say try numba and if it doesn't improve much or forces you to modify your code too much (i doubt it but who knows), move to cython

raven ridge
#

multiprocessing really sounds like it should help here

#

if you've got a big data structure that you want to share across many different workers, building that data structure in one process, forking off many workers to do the processing on a shared, copy-on-write version of that data structure, and then sending only the results back to the parent process over a queue should give you much better performance than any parallelism you can add in the Python code, assuming that the processing takes some minimal amount of time to justify the cost of the fork

teal yacht
#

numpy operations are not particularly fit for multiprocessing, they already use simd, same with opencv, I'm really unsure this would bring any speed up

raven ridge
#

maybe a dumb question, but have you tried profiling your code to figure out where it's spending its time, @subtle whale?

teal yacht
#

i wouldn't be surprised if it was consistently worse tbh

raven ridge
#

@teal yacht you're saying you think numpy+opencv+multiprocessing would be worse than numpy+opencv in a single process?

teal yacht
#

that is, ofc again, assuming most of the time is spent doing the numerical computations and not IO or some other non-numpy related ops

#

yes

raven ridge
#

interesting. I don't know numpy or opencv well enough to comment - I'd expect that could possibly be true in some special cases, but wouldn't have expected that to be the general case - but that's outside my wheelhouse.

teal yacht
#

many numpy operations are multi-threaded by default, assuming proper use of them, also not any kind of multi-threading, they use libraries like BLAS, implement SIMD operations etc that basically draw the best out of our CPUs for "pure" math operations

#

I'd expect the cost of building the pool, spawning processes and aggregating the results to be slower, but tbh i've never tried np + multiprocessing

#

semi-related: has anyone had good experience with cupy ? I never tried it but always thought it was interesting, wanted to hear if someone has had success moving from numpy to cupy and had great results

raven ridge
#

on Unix spawning processes is pretty cheap, but you're right that if it means that something that would otherwise use SIMD won't, it'd definitely still be a net loss

#

either way, seems like a really good idea to start with profiling, I'd think - no sense optimizing anything but the place where it's spending the most time, so it's worth checking your understanding of what that is.

subtle whale
#

What is cupy?

#

Cuda related?

teal yacht
#

numpy-like library that uses cuda

subtle whale
#

Sounds relatively new

teal yacht
#

it's "new" as in a few years

subtle whale
#

Also, do you think I should go the C/C++ route if I am not getting the required speedup

#

Is it worth it in fact?

teal yacht
#

naive C/C++ can be slower than python with optimized C/C++ libraries

#

just a disclaimer

spark magnet
#

Try Cython before going all the way to C

subtle whale
#

I did try cython

#

I will try it again after reworking my code a bit

#

I used to write in C/C++ before I switched to python a year ago

raven ridge
#

before making any big decisions, profile, figure out where the time is spent, and then think about how to speed that particular thing up.

#

Cython is awesome, but it's not a silver bullet - applying it to the wrong spot, or not using it properly, will only hurt you.

#

you can probably get the whole thing down to 1 or 2 functions you wrote that are taking up 90% of your time, and once you have that, it'll be a lot easier to ask for help getting those things faster.

#

and once we have specifics to work with it should be really easy to prove whether multiprocessing is the best way to speed it up, or using numpy differently so that it can make better use of SIMD, or what.

feral cedar
#

if you're writing bad code, switching to a faster language won't change anything

boreal umbra
#

What would you do if you want to enumerate over multiple things? So zip and enumerate

#

The only way I can think if is to have itertools.count as the first iterable

feral cedar
#

enumerate(zip()) ?

boreal umbra
#

Does that unpack the tuple you get from zip?

#

!e

my_list = ['a', 'b', 'c']

for a, b, c in enumerate(zip(my_list, my_list)):
    print(a, b, c)
fallen slateBOT
#

@boreal umbra :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 3, in <module>
003 | ValueError: not enough values to unpack (expected 3, got 2)
boreal umbra
#

!e

my_list = ['a', 'b', 'c']

for a, b, c in enumerate(*zip(my_list, my_list)):
    print(a, b, c)
fallen slateBOT
#

@boreal umbra :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 3, in <module>
003 | TypeError: enumerate() takes at most 2 arguments (3 given)
rapid yew
#

!e


for a, (b, c) in enumerate(zip(my_list, my_list)):
    print(a, b, c)```
fallen slateBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

boreal umbra
#

I don't think that that would work but we can see

rapid yew
#

it works, just not my !e

boreal umbra
#

!e

my_list = ['a', 'b', 'c']

for a, (b, c) in enumerate(zip(my_list, my_list)):
    print(a, b, c)
fallen slateBOT
#

@boreal umbra :white_check_mark: Your eval job has completed with return code 0.

001 | 0 a a
002 | 1 b b
003 | 2 c c
boreal umbra
#

interesting

#

thanks!

torpid narwhal
#

I just found out about memoryview. What a cool function. I know about views with numpy arrays, but I didn't know you could do that with Python buffers.

paper echo
#

@torpid narwhal python also has a native array library

#

!d g array

fallen slateBOT
#

This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers. Arrays are sequence types and behave very much like lists, except that the type of objects stored in them is constrained. The type is specified at object creation time by using a type code, which is a single character. The following type codes are defined:

pseudo cradle
#

Isn't it gross?

#

Or like, inferior to numpy?

brave badger
#

array is quite a low-level module, yeah

teal yacht
#

they're not meant for the same stuff tho, array is for simple memory efficient typed arrays, useful for compact storage, numpy is a whole beast that includes arrays and operations optimized for numerical operations

pseudo cradle
#

Do the extra potential operations affect the memory usage of numpy arrays?

teal yacht
#

no, i'd guess it's about the same order of magnitude

#

bad wording, i mean it should be very close

#

but you're not adding a dependency to your code with one

pseudo cradle
#

That's true. I'll probably never use it. Numpy is probably going to be a project requirement for anything I work on.

teal yacht
#

I agree, in the end you're right, I'm curious about the time complexity of append, i don't know the internals of array so i'm unsure if the arrays are fixed or dynamically sized

#

that could be a legitimate use-case against numpy for a lighter alternative to lists

pseudo cradle
#

I want to say they're dynamically sized, but I'm not 100% on that

#

Oh, I mean for numpy

#

I'd be curious about how these are implemented, too

#

I'm leaning towards dynamically sized, though

raven ridge
#

Python's array.array is damn close to std::array, you should appreciate with your C++ referencing username πŸ™‚

#

it's a dynamic array, unlike std::array which is fixed size, but its elements are typical C level types, rather than Python objects.

grave jolt
#

So it doubles on every resize, correct?

pseudo cradle
#

Yeah, it's neat that it has C level types

raven ridge
#

It doesn't have to double, it has to increase by a constant multiple

pseudo cradle
#

^

#

I was about to say, fun fact

raven ridge
#

I'm not sure if it's 2x, but 1.5x is also amortized constant time.

pseudo cradle
#

It just has to be a constant multiple to get amortized constant time

raven ridge
#

Jinx!

pseudo cradle
#

So is that still an array of pointers, or is it a true array?

teal yacht
#

for some reason in python it's not a simple geometric growth

#

(neither for arrays or lists)

#

in cpython*

#

_new_size = (newsize >> 4) + (Py_SIZE(self) < 8 ? 3 : 7) + newsize;

pseudo cradle
#

I mean, it's going to be faster either way because it doesn't have to do type checking

raven ridge
#

So is that still an array of pointers, or is it a true array?
@pseudo cradle a true array.

pseudo cradle
#

I didn't wind up using arrays that often because I kept blowing up my stack with large computations

#

Ooh, nice

#

That's hot

raven ridge
#

when you [] a single item from it, that constructs a Python object.

#

same as numpy.

pseudo cradle
#

Yeah

#

Without numpy I couldn't use Python

#

For my purposes

teal yacht
#

without numpy, there would be none of the current scientific/numerical we have now

pseudo cradle
#

Yeah, everything is built off of numpy

gleaming rover
#

Python's array.array is damn close to std::array, you should appreciate with your C++ referencing username πŸ™‚
@raven ridge so...std::vector?

#

wups I quoted the wrong part

raven ridge
#

yeah, that would have probably been a better analogy πŸ˜„

#

it's tough - list is also close to std::vector, excepting that it's a std::vector<PyObject*>

#

whereas array.array is more like std::vector<int>

gleaming rover
#

yeah it's a little difficult to draw analogies because of the difference in typing

#

between Python and C++

raven ridge
#

yeah.

raven crypt
#

does anyone have a favorite feature of numpy?

pseudo cradle
#

Oooh

#

That's a tough one

#

One of my favorite features is being able to compute functions across any axis I desire or the matrix as a whole

bitter shoal
#

does anyone have a favorite feature of numpy?
@avocadofire#6954
I guess np.where for me.

deft pagoda
#

einsum

paper echo
#

einsum is like regex for vector/matrix math

unkempt rock
#

Im having headache

grave jolt
#

One this that is inconsistent in Python and kind of breaks its duck typing model is the relation of classes, callables and functions.

tribal skiff
#

What’s the best way to input images into a machine learning model

grave jolt
#

!e

class SomeCallable:
    def __call__(self, *args):
        print ("some callable was called", *args)


def f(*args):
    print ("f was called", *args)


class MyClass:
    def g(*args):
        print ("g was called", *args)

    my_f = f

    some_callable = SomeCallable()


x = MyClass()
x.g()
x.my_f()
x.some_callable()
fallen slateBOT
#

@grave jolt :white_check_mark: Your eval job has completed with return code 0.

001 | g was called <__main__.MyClass object at 0x7fb1843780a0>
002 | f was called <__main__.MyClass object at 0x7fb1843780a0>
003 | some callable was called
grave jolt
#

So functions are treated specially and are made into bound methods.

raven ridge
#

yep.

#

I can't argue, that's weird and not super consistent. πŸ™‚

brave badger
#

Has something to do with the __get__ of function objects I believe

raven ridge
#

yeah, it's about the way that functions implement the descriptor protocol.

#

and technically SomeCallable could do it as well.

brave badger
#

From the Descriptor How-To Guide in the documentation

class Function:
    def __get__(self, obj, objtype=None):
        "Simulate func_descr_get() in Objects/funcobject.c"
        if obj is None:
            return self
        return types.MethodType(self, obj)
raven ridge
#

One could make the argument, though, that every callable ought to implement something like that by default.

#

that is, that object.__get__ ought to exist and check if __call__ exists and if so do that.

grave jolt
#

I can't really think of a consistent way to define class methods.

#

I guess that methods are such a common use case that the protocol-based nature is a bit broken

#

Well, one way is to make methodness explicit and make a @method decorator, but that will make most methods have this decorator.

#

So making self an explicit parameter comes with some drawbacks, it seems.

#

!e

def inherit_from(parent):
    def decorator(child):
        def func(*args, **kwargs):
            prepared_object = parent(*args, **kwargs)
            child(prepared_object, *args, **kwargs)
            return prepared_object
        return func
    return decorator
                                
def base(*_, **__):
    return {}

@inherit_from(base)
def animal(this, age, *_, **__):
    this["age"] = age
   
@inherit_from(animal)
def wolf(this, age, howl_length, *_, **__):
    def howl(): print("u" * howl_length)
    this["howl"] = howl

x = base()
print("base() =", x) # {}

cat = animal(17)
print("animal(17) =", cat) # {'age': 17}

dog = wolf(17, 6)
print("wolf(17, 6) =", dog) # {'age': 17, 'howl': <function...>}

dog["howl"]() # uuuuuu
fallen slateBOT
#

@grave jolt :white_check_mark: Your eval job has completed with return code 0.

001 | base() = {}
002 | animal(17) = {'age': 17}
003 | wolf(17, 6) = {'age': 17, 'howl': <function wolf.<locals>.howl at 0x7fc1e078dee0>}
004 | uuuuuu
grave jolt
#

Basically, it uses object-closure duality or something

#

Like one of the million idioms for creating a class in JS

#

Actually... A class is a dependency injection manager for a collection of functions (methods) πŸ‘€

unkempt rock
#

in PyQt5 i have window1 -> opens window2 -> opens window3. if window3 has a problem i want to close window3 and 2 and return to window1. how do i return throw/catch something between QmainWindows?

grave jolt
unkempt rock
#

ok sorry

subtle whale
#

So, I finally overhauled my Python code into this: https://github.com/sarimmehdi/master_thesis/blob/master/real_time.py

And now I am trying to convert it to cython. I am reading online that lists shouldn't be used in cython and we should use arrays instead. Is that true? Because I use lists (and do a lot of list comprehension) and not using lists would mean doing a complete do-over of my code. Also, what about dictionaries?

chrome crescent
#

so does anyone know how would you go about making named pipes but on Windows?

#

cuz apparently os.mkfifo is Availability: Unix.

radiant fulcrum
#

named pipes in windows is a reallllyy big pain in the ass

toxic coral
#

Hi

proven sphinx
#

Im coding both Python and JS how do I integrate them ??vscode

tawny shoal
#

PyCharm Professional or IntelliJ Ultimate works too

#

but yeah VS Code is free

boreal umbra
pseudo cradle
#

It looks like community would be better for me than professional but eh

#

Last time I researched pro was for web dev and full stack while science and scripting could be handled by community

#

Okay I lied there are some scientific tools available that I use a bit but could probably make better use of

valid wren
#

I have an issue on macos (on linux it works fine) where I monkey patch a library that uses the multiprocessing module and on linux, the patched function is called as intended, but on macos, the original function is called in the child processes

#

anybody run into this, know an approach to fix it?

spark magnet
#

that sounds complicated! Why do you need to monkeypatch?

pseudo cradle
#

What does it mean to monkey patch something in this context?

spark magnet
#

i took it to mean, modify the code in a third-party library by changing it at run time

pseudo cradle
#

Hmm

#

Sounds like it might be a pathing issue

boreal umbra
#

I don't think this is really on topic for this channel either.

valid wren
#

What does it mean to...

original_func = module.func
@functools.wraps(original_func)
def mypatch_func():
    shinanigangs...
    return original_func()
    
module.func = mypatch_func
#

ok, sorry for off topic

boreal umbra
#

Maybe it is and I'm not seeing the connection but I would probably use a help channel.

valid wren
#

ok, I didn't grasp the concept, I though those suffixes were project names πŸ˜†

boreal umbra
torpid narwhal
#

What are use cases for using array library? I have never come across a situation where I have used one. A list usually can do what I need.

gentle lodge
#

same here

#

I have the vague sense it's for interoperating with other languages, like maybe C or FORTRAN

#

but that's just a guess

pseudo cradle
#

Basically, when you care about memory usage and operation time

#

You usually don't, so lists are plenty

#

But when you start getting high data throughput or you have some sort of realtime constraints or memory constraints then it's something you should pay more attention to.

torpid narwhal
#

@pseudo cradle thanks

pseudo cradle
#

np

slim island
#

I vaguely remember Arcade apparently uses them instead of numpy arrays in some place or other because they're more efficient

#

I'm curious of some python libraries that do rely on them though - everything I can think of just uses numpy for that stuff

#

the niche where you use array.array seems very small

pseudo cradle
#

I agree personally, but maybe it's for when you're storing data but aren't planning on doing any sort of computation with it

teal yacht
#

it's a nice mix between lists and numpy arrays

#

you get the compact size with the benefits of dynamic arrays

#

but realistically, it's really useful in very few cases

pseudo cradle
#

I'm just having trouble thinking of industries / use cases

#

They're probably there

teal yacht
#

just when you need a compact variant of list

pseudo cradle
#

Maybe in embedded, but at that point I'd just use a different language

raven ridge
#

Micropython is pretty sweet.

pseudo cradle
#

I may explore it some day. We'll see.

gloomy rain
#

I really want to get into programming microcontrollers and more hardware-heavy projects at some point as well. It seems super fun.

narrow kettle
#

theres so many things i want to try/play with, i need more time in my life

pseudo cradle
#

I've worked with Ada, C, and ASM for microcontrollers

#

It's pretty fun but it's a major paradigm shift if you're not used to it

#

Most coders don't ever really have to think about things like firmware or memory

gloomy rain
#

I did a few simple hardware projects at uni, but that's it.

pseudo cradle
#

I've only worked with microcontrollers for hobby or academic use, but may begin some industry work in a few months with it

tired epoch
#

so suppose if i decide to write a interpreter for a language in python. what do i gain from it ?its pretty vague question but im curious what i can learn from it ?

feral cedar
#

you'd learn what it's like to write a language i suppose

brazen jacinth
#

a deeper understanding how interpreted languages operate πŸ€·β€β™‚οΈ

tired epoch
#

hmmm i c i c but anyother benefits ??

undone hare
#

Learning on how parsing work, how lexical analysis work, how stack machines work...

tired epoch
#

ohhh i c i c ty bud

undone hare
#

Taking this back from general Because of the GIL, I wonder what are the practical difference between asyncio and threading, apart from the fact that in asyncio the context switching is done by the python event loop while in threading it is done by the OS

tired epoch
#

i might throw some quick question regarding GIL too. so when u run aysncio, isnt it running in only one thread coz of GIL?

undone hare
#

Asyncio is intended to be run sequencially, it is just a way to be able to execute another piece of code while waiting for an IO operation to complete

tired epoch
#

i get the concurrency part. but is there any way u can bypass GIL and achieve multi threading in python?

undone hare
#

The only way is to launch a new interpreter, this is what multiprocessing does

flat gazelle
#

or to create a thread and run entirely non-python code in it

raven ridge
#

Doesn't have to be entirely non Python code in that thread. The thread can do a mix of Python and non-Python stuff, and drop the GIL while doing the non-Python stuff. That's how numpy works, for example

tired epoch
#

hmmmm but how do u connect the process then ?? for the non python code in the other thread?

#

is there already tool build for it ??

raven ridge
#

You write code in another language in such a way as to allow it to be imported as a Python module. Cython is a tool that simplifies that.

tired epoch
#

oh sweet cpython here i come thnx heaps golygeek

raven ridge
#

Cython, not CPython. Entirely different things.

tired epoch
#

cython here i come.thnx again. i swear i learned so much stuffs about programming after joining this python group lol

next geyser
#

I want to learn python imaging library but i can't find any good sources to do it

slim island
magic python
undone hare
#
dict(sorted(d.items()))```is enough now I think, yeah
pearl river
#

Tuples are compared by first element first, then by second and so on.

limber gull
#

In a sense, yes. Starting with Python 3(.4?) dicts retain order by insertion. So if you create the dictionary with the order you want, it will keep it.

pearl river
#

So that sorts by keys, then by values.

paper echo
#

note that OrderedDicts have nicer properties and APIs still

#

if you really want to enforce/rely on insertion order

pearl river
#

yeah, though it's important to note (at least it was notable to me) that OrderedDicts are for situations where the order is actually important as much as the contents - for example, comparison of OrderedDicts takes order into account, unlike dicts.

paper echo
#

^

#

i think if you're using sorted on a dict then creating a new dict

#

OrderedDict is much better

#

if only to semantically indicate in the code that "this is a dict where order matters"

#

because conceptually a dict is an unordered mapping

magic python
#

hrm - is that not assumed now though?

paper echo
#

i think its still semantically valuable

magic python
#

are you sure you're not just used to thinking about this not being the case from python < 3.6?

#

afaik this is standard now?

paper echo
#

dicts preserve insertion order

magic python
#

yeah

paper echo
#

but 9 times out of 10 you dont care

#

personally i think for the cases where you do care

#

its much clearer to use ordereddict

magic python
#

fair enough, makes sense

#

arm i'm sorting things and it's a bit of a mess πŸ˜„

paper echo
#

i actually thought ordereddict had a .sort method

#

guess i was imagining things

magic python
#

i wish πŸ™ƒ

limber gull
#

There are definitely some niceties on OrderedDict if you are performing lots of reordering operations. If you are just constructing the mapping once, a regular dict is probably all you need.

magic python
#

it'd be nice if pandas could consider empty dicts as NA values.

OrderedDicts are something that I've managed to avoid - probably in part bc of the new standard

limber gull
#

I vaguely recollect being angry at OrderedDicts when doing something with serialization. It might have been way back using tastypie or drf.

paper echo
#

@magic python we just had a discussion here last week about how empty containers should not be considered falsy

#

now you want them to be null?

magic python
#

did we? I don't recall, i use falsy things a fair bit - i just changed the default value so it's not an empty dict now πŸ€”

paper echo
#

you might not have been reading at the time

#

im 50/50 on it, i dont hate it nor do i think its an amazing wow feature

limber gull
#

The strongly typed enthusiasts will eat you alive. πŸ˜…

paper echo
#

i think in general it's reasonable that bool([]) is False, and that if <expr> should implicitly call bool() on the result of the expr

#

re: pandas null-ish definition. @magic python usually i dont want to conflate "empty dict" with "null"

#

and when i do, i either use one or the other consistently

#

e.g. either i replace all empty dicts with None or i replace all None/nan with empty dicts

#

i only mix empty dicts with null values if i want to distinguish between "null" and "has data but it's empty"

#

also how often do you really need a dict inside a series πŸ˜›

#

(j/k i use it all the time)

magic python
#

I was initialising a structure then filling it - but where there are no values i was left with empty dicts :/

#

i was enjoying TDD last week, this week i realise i need to change everything

#

now i hate it

brazen jacinth
#

that's where data cleaning comes in, transform them yourself into NaN?

grave jolt
#

@magic python one important thing is that you don't need to write a direct test for each entity. Suppose you have a function f and a bunch of tests on f. You can add some additional functionality to f (like an optional parameter to pass as strategy, as in sorted), then you can make another test that tests this new functionality. Then you might think that f is doing too many things and decide to refactor it -- split it into two steps, g and h. Don't write tests for g and h. I.e. test the public interface, not the implementation details, because the tests for f will ensure that g and h work

#

if that makes sense

#

The strongly typed enthusiasts will eat you alive.
I am already washing my Monad m => Fork m f

grave jolt
unkempt rock
#

gotcha, sry!

magic python
#

@grave jolt what's the definition of an entity

#

a function?

grave jolt
#

I meant that it is not true that every function, class etc. needs its own dedicated test.

#

Because if that's true, there's very little point in testing. Testing help refactor code and add new features without breaking old ones. And if every change also requires changing the tests, you don't have that guarantee

magic python
#

so if i have f( g( h( x) ) ) i'd just test f

grave jolt
#

If f(x) = g(h(x)) then you can test f, yes. Because if g or h have a defect, that defect should probably break f as well.

#

Except one case. When two defect cancel each other out. But that's pretty rare.

magic python
#

well, it woudn't necessarily be that f(x) == g(h(x)), but i think i get the point

grave jolt
#

well, unless you're in Haskell or something, it's more like f = @aaaaa(g(x + 42); h([a, b, c]); monkeypatch(print with django.model.view.controller))

magic python
#

😦

grave jolt
#

i meant that just composition might be rare, unlike in FP

#

alright, that's a weird way of saying that

magic python
#

i think a lot of my functions are composed actually - which was annoying bc i'd written tests for them all πŸ˜…

#

i guess i can delete them and just leave the top one

grave jolt
#

Yeah, if you have a function that's like

def foo(x):
    return bar(baz(fizz(buzz, x)))

where foo is some kind of a public function and bar and baz are helpers, you only need to test foo.

magic python
#

right - i get the point, I didn't get the point last week

#

though writing tests for everything did make some things kinda handy, maybe not worth it tho

grave jolt
#

And if bar and baz aren't fully covered, then:

  1. you didn't cover some cases
  2. the covered code is inner code that fails only when some invariant fails (if that's important to test, it might make sense to)
  3. some code is dead
#

but you might have a different case, so don't listen to me

flat gazelle
#

tests sort of violate DRY (Do not Repeat Yourself) because then you change something, you also have to update the tests. So too many tests can get annoying, but just the right amount is quite useful

magic python
#

what i've done is annoying as hell

#

i've just commented them all out now

grave jolt
#

RYJE

#

repeat yourself just enough

#

let's make more useless abbreviatures πŸ™‚

magic python
#

yolo

grave jolt
#

LMMUA

flat gazelle
swift gust
#

can I get a job with python without a degree

#

and just projects which I have made

#

to show

teal yacht
#

short answer: yes, but wrong channel

swift gust
#

oops

#

ment to go in channel below

grave jolt
#

I think that's the long answer as well :)

teal yacht
#

iT dEpEnDs

grave jolt
#

that's the real long answer. Alright, drifting to offtopic here

swift gust
#

what if I dont get the job

teal yacht
grave jolt
#

Well, it's not for the mods' pleasure. Keeping stuff on-topic is just better.

#

You know, Single Responsibility Principle πŸ˜„

boreal umbra
#

I want to do n independent function calls in parallel on m CPUs, n > m if it matters. I've done it before with joblib but multiprocessing is stdlib

#

is there any advantage to joblib?

pearl river
#

Joblib can use one of several backends, including multiprocessing.

#

So I'd expect joblib to just provide simpler ways to do it than manually working with multiprocessing/threading.

boreal umbra
#

looks like joblib is already a dependency of one of the requirements

#

of what I'm doing

#

might as well use it, I guess

boreal umbra
#

It appears that I can't use joblib.Parallel because each call relies on a shared object that isn't serializable.

#
    pool = mp.Pool(num_cores)
    for ann in dataset:
        pool.apply(_psudofy_file, args=(ann, output_dir))
    pool.close()

Hopefully this does what I think it does

flat gazelle
#

well, multiprocessing also would not work in this case

#

it also has to move the shared objects into other processes

boreal umbra
#

I have to leave and we're edging off-topic-for-this-channel territory so I'll bring it up somewhere else later if needed

radiant fulcrum
#

@flat gazelle Shared memory Tho that would probably cause so so so many issues

paper echo
#

Is there actually a way to share an arbitrary python object as read-only between processes

#

Something pretty big and complicated and not easily serializable to json or something

flat gazelle
#

pretty much the only things you cannot pickle are things that talk to the OS, which cannot really be read only

paper echo
#

Its pickleable

#

Just huge

#

(This is hypothetical but potentially useful in a few applications i can think of)

torpid narwhal
#

I’ve been impressed with Ray. It uses an in-memory object store to pass data around the different actors.

paper echo
#

Isnt that specifically for dataframes though

#

The main use case in my head is machine learning though

torpid narwhal
#

Ray? No. I think you are thinking about Dask.

#

I’m still confused by your use case.

brazen jacinth
#

perhaps some python wrapper for open mp, if you're in need for distrubted processing

paper echo
#

Make predictions in parallel from a big model without duplicating the model in memory

#

If its not really possible thats fine im just curious

grave jolt
#
          Shared       Unshared
Mutable   AAA!!!!!       ok
Immutable   ok          very nice!!!!
cloud crypt
#

haha

#

nice

brazen jacinth
#

some shared memory segment makes sense for your use

cloud crypt
#

@grave jolt rust did it a bit better than just this I guess

#

well if we are talking about memory here

#

Anyways I was thinking what if Python's compiler was not one-pass so it could support forward references

paper echo
#

@grave jolt yes im looking for shared and immutable

#

"I have 3 gb of float32's and metadata, which i want to share between 16 processes, read-only"

feral cedar
#

wild

flat gazelle
#

you could pack those into a shared memory I think

#

but I never actually looked at how to use that

paper echo
#

Yeah, multiprocessing shared arrays are interesting here

#

Numpy itself also supports memmapping

#

Not sure if you can memmap something read-only from 2 different processes

#

I think you can, eg joblib i think tries to do this

#

But probably using c extension stuff

boreal umbra
#

for logging do you think using modulus substitution is faster than f strings?

cloud crypt
#

f-strings must be faster

boreal umbra
#

I assume that f strings always get evaluated even if the statement doesn't get logged.

cloud crypt
#

oh wait that makes sense

#

haha

peak spoke
#

The time for interpolation on any reasonable string will be negligible

cloud crypt
#
nekit $ python -m timeit -s "import logging; log = logging.getLogger(); test = 42" "log.info('%s', test)"
500000 loops, best of 5: 666 nsec per loop
nekit $ python -m timeit -s "import logging; log = logging.getLogger(); test = 42" "log.info(f'{test}')"
500000 loops, best of 5: 757 nsec per loop``` interesting
#

but I suppose if it does get logged, f-string interpolation will be a faster way

#
nekit $ python -m timeit -s "test = 42" "f'{test}'"
2000000 loops, best of 5: 163 nsec per loop
nekit $ python -m timeit -s "test = 42" "'%s' % test"
1000000 loops, best of 5: 249 nsec per loop``` well I mean it is, obviously
boreal umbra
#

logging statements do modulus substitution their own way, rather than using str.__mod__

cloud crypt
#

oh interesting, let's test that

paper echo
#

They use % internally i think

#

I think i looked at the source once

#

Although dont quote me on that

modern frigate
#

logging uses % internally?

wide shuttle
#

You could say that. It has support for lazily interpolating those strings, which means that the string interpolation only happens when that logging message is actually relevant for something (usually: the logging level is low enough for it to actually be logged).

cloud crypt
#

yeah it seems to

#
    def getMessage(self):
        msg = str(self.msg)
        if self.args:
            msg = msg % self.args
        return msg```
#

yeah also there is a bunch of styles but they seem to be using underlying formatting like .format() or %

paper echo
#

Yep that ^

cloud crypt
#

Python's stdlib is not fully pythonic imo :p

grave jolt
#

You thought that I was totally crazy when I told you about the ,= operator.

#

and I had nothing to do with it!

cloud crypt
#

LOL

grave jolt
#

I'm still laughing πŸ™‚

cloud crypt
#

okay a note about logging

#

_levelToName hurts me

spice pecan
#

There are 10 times it uses it as ,= and one time it uses it as , =

grave jolt
#

there's also... this

    if literal.type == 'STRING':
        s = s.replace('\\\\', '\\')

    return { 'STRING': PatternStr,
             'REGEXP': PatternRE }[literal.type](s, flags)
#

nah, an if is too simple

spice pecan
#

wow

cloud crypt
#

lol

spice pecan
#

I guess it's technically more compact and easier to expand if you get new literal types, but uhh
but why though

cloud crypt
#

you could also cache this dict to not create it all the time

#

like put it globally

grave jolt
#

as a class attribute

#

I guess you can emulate immutable dicts as frozensets of tuples.

cloud crypt
#

please no

grave jolt
#

CPython will store them as constants!!

#

oh, wait, no

#

because it can't store the classes

cloud crypt
#

actually I was looking for a nice bytecode optimizer

#

or like just generally useful bytecode manipulators

#
test_value = 42

@constant("test_value")
def test() -> int:
    return test_value``` and LOAD_GLOBAL will be replaced with LOAD_CONST here, as one of my thoughts
grave jolt
#

hm

#

maybe you could utilize hax somehow?

cloud crypt
#

wait this is AMAZING HAHA

#

never knew about it's so cool HyperNeko

swift imp
#

Is it possible to speed up Pandas by using Cython for specific things?

#

I can't remember teh book because it was available through work, but it basically went over Pandas and talked about it deficiets in certain areas. Spoke about how in some cases using .apply() is actually really freaking slow and advised using custom Cython implementations.

#

I was just wondering if anyone has had experience with that.

grave jolt
paper echo
#

@swift imp I would try numba first

grizzled vigil
#

@paper echo @swift imp Numba is a definitely a lot more simple to use and I would also recommend trying it first, but you are likely not going to get quite as much performance as you could gain from optimal usage of Cython.

#

Whether Cython is worth the added complexity depends on your specific use case and performance requirements.

paper echo
#

Yep thats my experience as well. Im not a good enough C programmer to take full advantage of cython so i use numba for most "mathematical" things that need speed

pseudo cradle
#

What's the difference between numpy and numba?

boreal umbra
#

One of the large computers owned by my uni only has up to python3.6 and I think the administrator is always afraid to install newer versions

paper echo
#

Whereas cython has helped me a lot in other cases where i needed to wrap a C++ library or reduce overhead

boreal umbra
#

if there any reason why he should be afraid to install 3.8 now that it's been out a while?

paper echo
#

Sometimes i get a 50% speedup literally by just cythonizing a function unchanged

pseudo cradle
#

nice

paper echo
#

@pseudo cradle numpy is a vector/matrix/linalg library. Numba is a JIT compiler for python based on LLVM that supports numpy

#

Cython is a Python-like language that compiles to C but with the specific purpose of writing C extensions for CPython

pseudo cradle
#

I've heard Numba been thrown around before but I don't think I've ever used it. I'm never not using numpy, though

#

godlygeek was trying to sell me on the virtues of Cython when I was looking into ctypes

paper echo
#

What was your use case?

pseudo cradle
#

I had an obscure binary file and the parser was in complicated C code. I needed to integrate it with a Python program

unkempt rock
#

What's the point of cython? Is it just speed boost or more?

brave badger
#

It's serves as a superset for the Python language that allows you to write C-style code that can be used mainly for building C extensions

swift imp
#

C is about as close to the metal as you can get unless you want to do assembly or machine language. Cython let's you use it in python

grizzled vigil
#

Or at least, python-like syntax. It has some added constructs and more requirements (particularly if you want to get the most out of it), but it's much easier than programming in C and avoids many of the pitfalls.

swift imp
#

Basically alot of the stuff that makes python great comes at the cost of a lot of overhead. C on the other hand has little overhead but it's alot a more verbose and require many layers of abstraction to do anything super useful

#

Yeah, you don't actually write C

#

I just realize, what I'm saying is sounding like that

pseudo cradle
#

Does cython have dynamic typing still?

#

I wonder if I can use cython and still claim my project is pure python

grizzled vigil
#

You can use dynamic types in Cython, but using static types results in a significantly better performance improvement. Also, Cython IS an implementation of the language Python. When you say "pure python", you're actually referring to CPython, the reference implementation of the language.

#

So, a project that uses Cython instead of (or in addition to) CPython can still be considered 100% Python

pseudo cradle
#

Nice

#

Cool

boreal umbra
#

Posted this in the wrong channel:

len([e for e in gold_ents if e.tag == tag])    # option a
[e.tag == tag for e in gold_ents].count(True)  # option b

Which do people prefer?

teal yacht
#

intent clearer on the first one imo

feral cedar
#

i mean on the second one you know right away you're counting the Trues

pseudo cradle
#

Seems like it's a matter of preference, I like the second one

boreal umbra
#

I switched to the second one because I feel like it's more explicit

paper echo
#

First for sure

#

Wait

#

sum(e.tag == tag for e in gold_ents) could work too

pseudo cradle
#

Hah, looks like it's fairly evenly split

boreal umbra
#

I feel like a builtin that tells you how many times a condition is true for an iterable should be a thing

paper echo
#

Yes, that is sum

sick stump
#

hello

boreal umbra
#

it's one of the more common problems that doesn't seem to have a "one obvious way to do it"

pseudo cradle
#

That seems useful

boreal umbra
#

yeah but if you're using sum you're using the fact that True is 1 and I try to avoid that

rapid yew
#

both of the original 2 eagerly create temporary lists wasting memory

paper echo
#

count_true = sum; count_true(...) πŸ˜‰

#

And yeah i mostly just hate creating lists that get thrown away

boreal umbra
#

tbh I'd almost be tempted to put count_true = sum in my code

paper echo
#

Well to be really correct you'd have to cast everything to bool before summing

rapid yew
#

abusing the fact that bools are ints feels wrong but it is concise and efficient lol

paper echo
#
def count_true(items: Iterable[Any]) -> int:
    return sum(map(bool, items))
rapid yew
#

is treating bools as ints really idiomatic? it's useful here but I've never seen it in the wild, at least intentionally

paper echo
#

It's pretty common among numpy users

#

And R users

rapid yew
#

ah fair, I don't deal with numpy much

#

and I don't like to remember R exists

paper echo
#

Actually yes i would say it's strongly idiomatic

#

To the point where "sum of bools == # true" and "mean of bools == % true" are synonyms in my mind

rapid yew
#

in the domain of numpy maybe but I can pretty confidently say it's pretty obscure to must 'application' python devs

paper echo
#

!e print(isinstance(False, int))

feral cedar
#

oof

fallen slateBOT
#

@paper echo :white_check_mark: Your eval job has completed with return code 0.

True
teal yacht
#

wdym ints and bools should be different, where's the issuepy In [2]: {True: "bruh"}[1] Out[2]: 'bruh'

paper echo
#

I guess it's weird but in a world of weak typing you can justify it as casting and not a subclass thing

teal yacht
#

/s

rapid yew
#

yeah I know it's the case, it's just not really well known or utilized in my experience, and has always felt more leaky or vestigial than intentional

paper echo
#

It's definitely deliberate

#

Like falsy empty containers

rapid yew
#

yeah not implying it's accidental lol, just not super loudly mentioned

pseudo cradle
#

As long as its consistent

#

like all empty containers being falsy

rapid yew
#

falsey empty containers are not actually integers like bools

#

that would be a bit more confusing

feral cedar
#

well yeah, they're containers

pseudo cradle
#

that harkens back to C, doesn't it?

#

With BOOL

#

Where BOOL was just an int

rapid yew
#

yeah that's part of why I have the view of it that I do

#

and how like a big point of tuples has really always been to save refcount mutations

gleaming rover
#

I use sum, but I do find it a little weird

pseudo cradle
#
#option a
for i in range(x)
#option b
i = 0
while i < x
#

option a ig

teal yacht
#

always option a

#

assuming the counter is always incremented by one ofc

boreal umbra
#

@pseudo cradle why would you use b?

feral cedar
#

i mean you can always change the step

gleaming rover
#

honestly I don't know anywhere the latter would be used (not just Python) unless the "counter" was changed by an amount depending on what happened each iteration

feral cedar
#

the only reason to use B is if you want the loop to end before i >= x, and you can use i

#

or if you have a random step ig, that's weird though

#

there was a problem that i had once, where you had to simulate a frog and it jumped random intervals each time

pseudo cradle
#

I have some usecases for B, but my current use case does not fit. I'm just... tired.

#

But I would use option b if I was traversing data with multiple pointers, but this is not that case

rigid cargo
#

does anyone know a good way to get good at python i only really know discord.py

pseudo cradle
#

This isn't the channel for that, but check out this page

#

!resources

fallen slateBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

feral cedar
#

wait, how are you not at least decent if you really know discord.py

spark magnet
#

I asked for opinions on a draft blog post in #unit-testing , but it's a very low-traffic channel... πŸ™‚

halcyon orbit
#

How to kill a child process of a child process without affecting the virtual parent

magic python
#

is there any sort of pattern that's like a zip where one element is a generator?

#

I guess I could just write a for loop πŸ€”

gloomy rain
#

@magic python You can give zip a generator.

spice pecan
#

any iterable should work

magic python
#

oh, yes, i must have done something wrong before πŸ˜„

j = itertools.cycle("ab")
[x * i for x, i in zip(j, range(9))]
#

πŸ‘

feral cedar
#

wait zip a range?

#

use enumerate

#

oh

#

nevermind

paper echo
#

is it bad to re-use typevars?

from typing import Mapping, TypeVar

_T = TypeVar('_T')

def f1(x: _T) -> _T:
    return x

def f2_unrelated_to_f1(x: Mapping[str, _T]) -> _T:
    return {k: v for k, v in x.items() if k.startswith('Q')}

is this ok in general?

modern frigate
#

I dont think reusing typevars is necessarily that bad? but im not really sure

charred wagon
#

I think it's fine

#

I don't think of it as tied to a certain object or function

#

Imagine if you had a more complex typevar, like one that put restrictions on the types. Then I'd consider it to be just a generic thing with defined restrictions that can be used by anything that needs those restrictions, in the same way multiple unrelated things could reuse type aliases

paper echo
#

that makes sense

charred wagon
#

Granted, if you have multiple classes defined nearby which don't have a relationship, then maaaybe having separate typevars for them would be more readable?

#

I don't really think so though

#

I'm not a huge fan of one letter type var names anyway, so in that situation I'd create separate ones to be more descriptive, even if they are identical otherwise

boreal umbra
#

The admin for my uni's big computers apparently said that he will never install a python version past 3.6. My advisor said she's going to change his mind but I'm not sure what his hesitation is.

grave jolt
#

what is his reasoning?

boreal umbra
#

Security, I guess.

brazen jacinth
#

i mean, in the real world - uni or business - the newest version isn't always the best option

boreal umbra
#

I thought he just hadn't gotten around to installing 3.7

#

Though after a while won't older versions become less secure?

brazen jacinth
#

they still recieve security patches

#

(untill the minor version itself is supported)

boreal umbra
#

But not indefinitely, right?

north root
#

nope

#

3.5 is becoming deprecated soon, meaning it'll stop receiving patches

brazen jacinth
#

already? damn

feral cedar
#

they grow up so fast 😒

brazen jacinth
#

oh, basically, 1.5 years of full support, then 3.5 years for security patches

#

security doesn't make sense for reasoning though πŸ€·β€β™‚οΈ

paper echo
#

Fwiw 3.6 is still "usable"

#

F strings are nice i guess but damn 3.7 has been out for a while

slim island
#

3.6 has fstrings. For me the things that I missed from 3.8 to 3.6 were only dataclasses and the walrus

north root
paper echo
#

oh right

#

wait what is 3.6 missing then?

#

importlib.resources i guess but that's been backported

#

can't name variables await lol

#

postponed type annotation evaluation

#

i guess dataclasses are nice but you have attrs anyway

#

i havent yet found a use case for ContextVars

peak spoke
#

for the things that can't get backported reasonably postponed annotations and a lot of async things

paper echo
#

true asyncio was pretty rough in 3.6

#

oh wow module-levelt __getattr__ was new in 3.7 i didnt realize

#

oh and the whole C locale change

#

that alone might be reason enough to not upgrade in a production system tbh

brazen jacinth
#

C locale change?

brazen jacinth
#

if only python handled encoding like rust from the start

paper echo
#

the painful legacy of python 2 strings remains...

#

cool talk

stiff sable
#

back in 2012, it took me about a week to print something in Turkish to console because of the ASCII/utf8 stuff

#

i'm so grateful for python3

paper echo
#

love to hear it πŸ™‚

stiff sable
#

it turned out my Windows login name had a turkish character (non-ASCII) in it, so none of the path stuff was working

brazen jacinth
#

haha, know that too well

#

the beauty is, you can't change it unless you headfirst in the registry

#

that's one of the moments you just say, fuck windows

#

gutwrenchingly annoying moment

stiff sable
#

its more like a fuck python2 moment for me

brazen jacinth
#

a lot of stuff doesn't work if you have a non asci character in your profile name on windows

#

Docker, alot of path stuffs breaks, somethings rely on it internally like android studio, preventing fixes byhand

stiff sable
#

well, i was more or less a regular user before that so i didnt feel the UTF-8 pain until learning python πŸ™‚

#

but yeah, i see your point

#

...and now, in 2020 we broke the unicode stuff again with all those emojis

#

right now i'm trying to find a way to show emojis on wikipedia but i keep getting zero width joiner errors

#

i hate emojis...

flat gazelle
#

emojis don't do anything special, do they? The same modifier mechanism is used for actual text as well afaik

stiff sable
#

i encountered more issues on emojis than regular text

brazen jacinth
#

afaik, nothing special

#

probably more problems with the rendering itself

stiff sable
#

i think some emojis use something like two unicode characters or something\

flat gazelle
#

ye, for example flags are sequences of regional indicators

stiff sable
#

im actually trying to figure it out right now

flat gazelle
#

you have skin tone modifiers as well

stiff sable
#

like the emojis in this tweet

flat gazelle
#

oh damm, twitter straight up replaces emojis with images

stiff sable
#

when I get the text from Twitter API and manipulate it, Wikipedia templates give an error

brazen jacinth
#

yet as an alt, a pure emoji remains

paper echo
#

interesting workaround

#

discord seems to supply its own font for emoji

unkempt rock
#

can someone give example of proper commenting? HAHA

#

Not how-to-comment

#

but general one-liners that get to the point

radiant fulcrum
#

you shouldnt strictly need one line comments if you actually name your shit sensibly and type accordingly :P

teal yacht
#

imo, comments should only be used to explain obscure behaviour when really you can't make your code cleaner without hitting another issue

#

# we need to do this because of that isn't a bad comment imo, explaining what the code itself is doing should be self-explanatory for the most part

radiant fulcrum
#

you also only have that comment for that one line

#

sensible var names are worth 1000% more than comments

teal yacht
#

my rule of thumb is to document code with 3 questions, 1 of which is optional
what ? -> variable names and docstrings
how ? -> the code itsefl
why ? -> this is where comments may be used when that question is worth being answered

fallen slateBOT
#
The Zen of Python (line 17):

If the implementation is easy to explain, it may be a good idea.

#
The Zen of Python (line 18):

Namespaces are one honking great idea -- let's do more of those!

radiant fulcrum
#

nvm

teal yacht
#

you meant 16, but still

radiant fulcrum
#

yeah

#

point made

teal yacht
#

i agree with you, but sometimes it's not applicable

radiant fulcrum
#

i know what you mean

teal yacht
#

I'm wondering what the guy(s) that created this were thinking about being able to explain the implementation or not :p

float Q_rsqrt( float number )
{
    long i;
    float x2, y;
    const float threehalfs = 1.5F;

    x2 = number * 0.5F;
    y  = number;
    i  = * ( long * ) &y;                       // evil floating point bit level hacking
    i  = 0x5f3759df - ( i >> 1 );               // what the fuck? 
    y  = * ( float * ) &i;
    y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
//    y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed

    return y;
}```
neon epoch
#

there are a lot of really really really smart people who wrote a lot of library code

pearl river
#

ah yes, the Doom sqrt thingie πŸ˜›

teal yacht
#

quake*, but yea

neon epoch
#

its like pokemon being made in 16mb and now 15yos cry if they dont have 16gb of ram

brazen jacinth
#

math heavy code, is a devious exception to different types of code when it comes to comments

pliant tusk
#

@teal yacht there are entire papers dedicated to that specific function

#

@pearl river its actually from Quake

teal yacht
#

I know, that doesn't mean it fits the "easy to explain", quite the opposite actually

#

But it's not like they had better options

pliant tusk
#

oh there is no good way to comment code like that

#

because it is probably the result of months of research

unkempt rock
#

You can write a blog post and drop a link πŸ˜›

brazen jacinth
#

in instances like this, a link to a article explaining it doesn't sound bad tbh πŸ€·β€β™‚οΈ

teal yacht
#

Afaik, noone actually knows how they found that

#

Everything is just speculation that was done decades later when the code was released

pliant tusk
unkempt rock
#

The fastest way to the solution: guess it.

pliant tusk
#

it does essentially boil down to that

solar aspen
#

How would someone write an algo aimed at trading stocks/crypto? Really interesting imo.
Like if BTC goes up by 5% then sell

unkempt rock
#

!zen 11

fallen slateBOT
#
The Zen of Python (line 11):

In the face of ambiguity, refuse the temptation to guess.

teal yacht
#
if btc_rates[-1] * 100 / btc_rates[-2] > 105:
  sell()```
solar aspen
#

Interesting

teal yacht
#

(I'm kidding, don't do that)

solar aspen
#

lmao

vast harness
#

z!info

#

!info

unkempt rock
#

#bot-commands

stiff sable
#

have you ever tried to recreate the "wikipedia text version differences" view for comparing long 2 strings/files?

final whale
stiff sable
#

I'm working on exactly this on wikipedia, but I need to preview the changes I'll make and need to compare the original vs modified strings

#

@final whale should I repost there?

radiant fulcrum
#

I remember seeing it a while back but cant find it

#

how do we type hint something but prevent a recursive import issue?

spice pecan
#

using string literals?

radiant fulcrum
#

no there was another way if i remember

spice pecan
#

that or from __future__ import annotations, which postpones the evaluation

radiant fulcrum
#

oh that might be it

spice pecan
#

That's what you'd do for things like

class Thing:
    def named_ctor(args) -> Thing: ...

Not sure about how effective it'll be with circular imports

radiant fulcrum
#

from typing import TYPE_CHECKING might be it aswell`

radiant fulcrum
#

welp my ORM is now strictly typed

#

just gotta start finish the update system

gleaming rover
#

you generally want to combine both

#

the idea of TYPE_CHECKING is that you can put imports that would otherwise be circular in an if TYPE_CHECKING: block

cloud crypt
#

Anyways I was thinking what if Python's compiler was not one-pass so it could support forward references
It could help with circular imports and declaring methods of a class that return that class

#

well, not sure about the circular import part

undone hare
#

Well, multi passes solve a lot of things and allow more optimizations, but that's considerably slower

stuck iris
#

How to print only those elements of a list whose length is 5 in Python ?

pseudo cradle
#
for element in list:
  if len(element) == 5:
    print(element)
unkempt rock
#

is there anyway to get the source code of a repl.run link?

wide shuttle
#

Hello, this channel is for discussing the Python programming language itself, from a higher-level perspective. Thing like advanced language concepts, the implementation, the future of the language, Python Enhancement Proposals (PEPs), and so on.

zealous thorn
#

Does anyone know where i could find a pdf of the book "Advance Computer Programming in Python" by Karkim Pichara and Christian Pieringer???

pseudo cradle
#

Hello, this channel is for discussing the Python programming language itself, from a higher-level perspective. Thing of advanced language concepts, the implementation, the future of the language, Python Enhancement Proposals (PEPs), and so on.
@wide shuttle

flint crystal
#

Hoe can I target MS Word or Notepad with Python? So that I can write on them using Speech Recognition library

gloomy rain
#

@flint crystal This channel is for indepth discussion of the Python language. If you need help, please follow the guide in #β“ο½œhow-to-get-help

flint crystal
#

ok I have my channel open i am gonna wait for replies

unkempt rock
#

y r there so many raids on this server?

ornate violet
#

I don't think that has anything to do with this channel, but all large servers have it.

charred wagon
#

I guess I really don't know what __path__ is and why it's being used over the file's path.

raven ridge
#

Namespace packages.

#

A package can be spread across multiple directories on disk, but only if it's a namespace package.

#

And if a package has an __init__.py, it may or may not be a namespace package, there's no way to know without seeing what the file does

#

!pep 420

fallen slateBOT
#
**PEP 420 - Implicit Namespace Packages**
Status

Final

Python-Version

3.3

Created

19-Apr-2012

Type

Standards Track

raven ridge
#

^ that describes the situation before implicit namespace packages were a thing, which goes into __path__ a bit.

charred wagon
#

Thanks

paper echo
#

implicit namespace packages are pretty nice, i use them at work

#
from bigcorp_datasci.some_really_specific_package import ThingClient
#

it lets us release and maintain lots of little small packages all under the bigcorp_datasci namespace without having to really think about the operational aspects of making that work

orchid lily
#

I have problem with tkinter.

#

who want help me

raven ridge
sand musk
#

does anybody use metaclass meaningfully in python? i’m looking for valid use cases aside from theory and sample usage

unkempt rock
#

Question, what are the chances of programmers teaming up with developers?

#

As in pro type apps, and websites.

north root
#

there are very specific use cases for metaclasses

unkempt rock
#

English please

#

Aka I want to create protype apps and website while learning SQL. But now I’m wondering if I could partner with developers to create apps in my local area

gleaming rover
#

does anybody use metaclass meaningfully in python? i’m looking for valid use cases aside from theory and sample usage
@sand musk hm not really sure if you would consider this meaningful but

#

I use metaclasses to bind class attributes

#

so like an attribute of an instance of a class will vary automatically with the value of an attribute of another instance of another class

#

I’ve also used them for some dependency injection stuff, but that was more for fun

boreal umbra
#

What is dependency injection?

north root
#

@unkempt rock this is not the place to ask that. please see the channel topic. that could probably go in #career-advice or an off-topic channel

gleaming rover
#

What is dependency injection?
@boreal umbra classes ask for things they need instead of making them themselves

#

BASICALLY

signal tide
#

Is that the point of *args, **kwargs or is that something else

gleaming rover
#

not really...? it’s more like a pattern

signal tide
#

Ah ok

gleaming rover
#

okay an example...say you have a recommendation engine.

#

for performance, you want to also have a cache

#

now, your reco engine class could create its own cache...or it could take one in its init method

#

creating its own dependencies vs having them injected in

#

(provided)

#

this has benefits

#

for example if you want to test what happens if the cache randomly drops values you could pass in a mocked object with that behaviour

limpid ridge
#

im tryng to work with some like 7 year old code

#

written in python 2

#

whats the best way to do this in pycharm without fucking up my main python install

#

on ubuntu btw

brave badger
limpid ridge
#

uc

#

*ic

#

thx

unkempt rock
#

Has PEP always mandated that there be two blank lines between functions? I thought it was two lines between module imports and class definitions, then two between class defintions and function definitions... but only one between function definitions otherwise.

spice pecan
#

It's one line between methods and two lines between each class/function definition, has been that way for quite a while if not from the start

unkempt rock
#

I think I might just be used to the one between methods

#

thanks

unkempt rock
#
music_path = Path(MUSIC_PATH)

artists = [
    {
        'path': d,
        'artist': d.stem,
        'albums': [
            {
                'path': a,
                'album': a.stem,
                'songs': [s for s in a.iterdir() if s.name.endswith('mp3')],
                'cover': a / 'cover.jpg'
            } for a in d.iterdir() if a.is_dir()
        ]
    } for d in music_path.iterdir() if d.is_dir()]

list comps ❀️

unkempt rock
#

I had it redone with black

artists = [
    {
        "path": str(directory),
        "artist": directory.stem,
        "albums": [
            {
                "path": str(album),
                "album": album.stem,
                "songs": [
                    str(song) for song in album.iterdir() if song.name.endswith("mp3")
                ],
                "cover": str(album / "cover.jpg"),
            }
            for album in directory.iterdir()
            if album.is_dir()
        ],
    }
    for directory in music_path.iterdir()
    if directory.is_dir()
]

Hrmmm... I'm not sure how I feel about those line breaks between the for and the ifs. Its not even consistently applied. Notice it leaves str(song) for song in album.iterdir() if song.name.endswith("mp3") as one line but thinks much shorter statements should be on their own lines...

Overall I guess it does look better.

wide shuttle
#

The reason is probably that the longer list comprehension is split out over multiple lines and that's when it opts to split all lines

#

Thalbum.iterdir() list comprehension is only broken in the sense that the opening and closing bracket are on seperate lines

brave badger
#

Are recursive functions really that expensive in CPython that it's necessary to put a recursion limit?

cunning sphinx
#

I'm guessing recursion only gets expensive if your arguments for said function gets more and more complex

brave badger
#

Not really familiar with the implementation of the call stack but I'm rather curious as to why I could have an object that nests another instance of the same class and be able to delegate calls just fine e.g.

class Nested:
    def __init__(self, n ,v):
        self.n = n
        self.v = v
    def execute(self):
        print(self.v)
        try:
            self.n.execute()
        except:
            pass

xs = [Nested(None, i) for i in range(5000)]

while len(xs) > 1:
    a = xs.pop()
    b = xs.pop()
    b.n = a
    xs.append(b)

xs[0].execute()
pearl river
#

having some recursion limit is just a good solution to avoid infinite recursion, and the recursion limit can be changed at runtime

brave badger
#

I guess that's true

cloud crypt
#
>>> sys.setrecursionlimit(2**31-1)
``` okay I have two questions, why is that limit have to be a signed integer, and why is it even that large if it will segfault at some point kek
unkempt rock
#

Do you guys use import turtle?

subtle whale
#

I have installed PyPy 3 using snap on Ubuntu 18.04

#

But I am unable to call it from the terminal

#

can someone explain to me how to do that?

undone hare
#

You probably need to add the right path inside the snap to your PATH variable

#

Tbh installing command line tools using snaps sounds like a bad idea

subtle whale
#

how else should I install pypy?

#

this looks like the best way

undone hare
#

You'll end up with a crazily long PATH, and I'm not even sure if the snaps are always mounted in the same directory

#

Using your package manager is preferred

subtle whale
#

I guess a more appropriate question would be this: Has anyone here used PyPy with PyCharm?

pearl river
#

I did. It was as simple as selecting it to be the project's interpreter.

subtle whale
#

I have installed PyPy using snap and now I am trying to create a new virtualenv

#

but I get this weird error which makes no sense

#

can you show me how to you did it?

#

on pycharm

gloomy rain
#

@subtle whale This channel is for indepth discussion of the Python language, not for help. Please check out #β“ο½œhow-to-get-help instead.

subtle whale
#

I thought those channels were for code discussion

#

it's okay to ask questions like these there?

gloomy rain
#

You can ask for help in help channels, yes.

subtle whale
#

ok thank you

pseudo cradle
#

@brave badger Compared to other languages, the recursion limit on Python is pretty conservative. Each recursive call does get stored on the stack so it does take additional memory, but I believe the assumption is that if you have recursion 1000 calls deep that something is wrong. Thankfully in cases where it matters, we can increase the default recursion limit. As someone mentioned though, there is a point where you're just going to segfault.

brave badger
#

Fair answer. Thanks.

pseudo cradle
#

np

orchid karma
#

So it seems to me that the new changes to pip might really encourage the use of venvs even more so.
Also, I'm not entirely sure how this would play out? How would this behavior differ with the pip upgrade?
"If you pip install x and then pip install y, it’s possible that the version of y you get will be different than it would be if you had run pip install x y in a single command."

flat gazelle
#

@cloud crypt I would guess because it is signed integer in C code, and adding the overhead of python integer addition into every call is probably a bad thing. Why it needs the sign idk.

brazen jacinth
#

can you even set a limit on the stack frame depth in other staticly typed languages at runtime?

nimble dome
#

Does opensource project know that copied thier work and violated thier license by selling the software or source

brazen jacinth
#

or heck, even dynamic ones

tropic fulcrum
#

@exotic mortar - also note that sys.setrecursionlimit really is a call stack limit, so if you recurse with A calls B which calls A, you will only recurse recursionlimit/2 times. And even if A calls A, if A has a decorator (like @lru_cache), then each call to A is actually 2 calls on the stack.

#

With some pyparsing parsers (especially those doing arithmetic parsing with many levels of operator precedence), I have to bump the default recursion limit to 3000 or 4000. Setting it to 2**31 is pretty much turning it off, leaving you open to a Python out-of-memory crash instead of a recoverable Python Recursion exception.

paper echo
#

@orchid karma i think the dependency resolution algorithm might find a different result for the latter case compared to the former. i honestly wonder why that is, but i know dependency resolution can be a hard problem algorithmically (beyond just topological sort).

solar onyx
#

Hi
How can I import variable from one function to another function without setting it as a global

pseudo cradle
solar onyx
#

Ok sry

pseudo cradle
#

no worries πŸ™‚

paper echo
#

however, debating the merit of module-global imports definitely is

#

boxed#9332 made a good argument that from X import x should not put x into the top-level namespace of the current module, at least not by default

#

in fact i think that question is on topic here

#

because the solutions are neither trivial nor idiomatic and touch on a lot of python language design details

peak spoke
#

What namespace would x be behind if not the global one? (assuming imports at top)

pseudo cradle
#

At that point I'd just import X

paper echo
#

@peak spoke
a.py ```python
val1 = 123

`b.py` ```python
from a import val1
val2 = 456

the argument is that you should not be able to write from b import val2

#

or at least, that you should not be able to write it without explicitly marking val1 for export from b

#

the idea being that these non-segregated imports clutter up module namespaces

#

one option would be to have __all__ apply to all imports and not just import *

pseudo cradle
#

hmm

paper echo
#

so if you omit __all__ the behavior works as it does now, but if you include __all__ you create a whitelist for all importing, not just for import *

#

maybe @half wolf has other ideas since he's the one that brought it to my attention in the first place

half wolf
#

Yea, what salt said. The problem is that there is just one global namespace they gets clobbered with imports, variables, functions and classes (which are really just variables but anyway). All top level imports become the public API of modules. This is not what anyone means in 99.9% of cases.

#

But changing this now would be a long depreciation period and would introduce performance regressions too (although pretty small).

keen thicket
#

import random
import time
from tkinter import Tk , Button , DISABLED

def show_symbol(x,y):
global first
global previousx , previousy
buttons[x,y]['text'] = button_symbols[x,y]
buttons[x,y].update_idletasks()

if first:
    previousx = x
    previousy = y
    first = False
elif previousx != x or previousy != y:
    if buttons[previousx,previousy]['text'] != buttons[x,y]['text']:
        time.sleep(0.5)
        buttons[previousx,previousy]['text'] = ' '
        buttons[x,y]['text'] = ' '
    else:
        buttons[previousx,previousy]['command'] = DISABLED
        buttons[x,y]['command'] = DISABLED
    first = True

win = Tk()
win.title('Matchmaker')
win.resizable(width=False , height=False)
first = True
previousx = 0
previousy = 0
buttons = { }
button_symbols = { }
symbols = [u'\u2702',u'\u2705',u'\u2708',u'\u2709',u'\u270A',u'\u270B',
u'\u270C',u'\u270F',u'\u2712',u'\u2714',u'\u2716',u'\u2728',
u'\u2702',u'\u2705',u'\u2708',u'\u2709',u'\u270A',u'\u270B',
u'\u270C',u'\u270F',u'\u2712',u'\u2714',u'\u2716',u'\u2728']

random.shuffle(symbols)

for x in range(6):
for y in range(4):
button = Button(command = lambda x=x , y=y: show_symbol(x,y) , width = 10, height = 8)
button.grid(column = x , row = y)
buttons[x,y] = button
button_symbols[x,y] = symbols.pop()

win.mainloop()

#

this is a really fun game i made

#

try it

paper echo
#

@keen thicket that's great πŸ™‚ but this isn't the best place to share your projects

keen thicket
#

ok

paper echo
#

im actually not sure where we should share projects nowadays. you can ask in #community-meta

paper echo
#

in cpython, strings are usually interned, right? e.g.

def f(x):
    s = 'abc'
    return s, x

f(1)
f(2)
f(3)

doesn't create a new string each time?

#

!e ```python
def f():
s = 'abc'
print(id(s))

f()
f()
f()

fallen slateBOT
#

@paper echo :white_check_mark: Your eval job has completed with return code 0.

001 | 140459125360752
002 | 140459125360752
003 | 140459125360752
paper echo
#

!e ```python
from dis import dis
def f():
s = 'abc'
print(dis(f))

fallen slateBOT
#

@paper echo :white_check_mark: Your eval job has completed with return code 0.

001 |   3           0 LOAD_CONST               1 ('abc')
002 |               2 STORE_FAST               0 (s)
003 |               4 LOAD_CONST               0 (None)
004 |               6 RETURN_VALUE
005 | None
paper echo
#

!e ```python
from dis import dis
def f():
s = 'abc'
return s
t = 'def'
def g():
return t
print(dis(f))
print(dis(g))

fallen slateBOT
#

@paper echo :white_check_mark: Your eval job has completed with return code 0.

001 |   3           0 LOAD_CONST               1 ('abc')
002 |               2 STORE_FAST               0 (s)
003 | 
004 |   4           4 LOAD_FAST                0 (s)
005 |               6 RETURN_VALUE
006 | None
007 |   7           0 LOAD_GLOBAL              0 (t)
008 |               2 RETURN_VALUE
009 | None
wheat bough
#

!e
if(item.type == 426){
int health = target.life; //current hp
int healthCap = (int)(target.lifeMax * 0.75f); //75% of max hp
if(health > healthCap){
damage *= 2;
}

fallen slateBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

feral cedar
#

dude did you think you were gonna be able to run Java with a python bot

flat gazelle
#

I think the conclusion that was arrived at is that string with no spaces get interned

spice pecan
#

IIRC strings that qualify as identifiers get interned every time

paper echo
#

!e ```python
def f():
s = 'this string definitely is not a valid identifier'
print(id(s))

f()
f()
f()

fallen slateBOT
#

@paper echo :white_check_mark: Your eval job has completed with return code 0.

001 | 140106400839808
002 | 140106400839808
003 | 140106400839808
spice pecan
#

I assume it's tied to the fact it's a literal

paper echo
#

yeah

#

that's what im asking about though, string literals. i didnt clarify that above

#

makes sense

potent fiber
#

anybody have the algorithm of finding a peak written in python ? (binary research)

feral cedar
#

like, the max value?

modern frigate
#

Dang, AoT compilers/interpreters are pretty awesome

#

I think MyPyc https://github.com/python/mypy/tree/master/mypyc is an aot python interpreter

teal yacht
#

it's a python to C (for cpython extensions, not any kind of C) compiler, analog to Cython

paper echo
#

interesting, i wonder how it differs from nuitka or cython

radiant fulcrum
#

I guess is relies heavily on strict typing to produce any sort of perfomant code

paper echo
#

im surprised its only 4x faster

#

cython typically is a 2x speedup when ive tried it in 1:1 translation with python

#

ive seen 4x from pypy too which doesnt require typing

#

Most type annotations are enforced at runtime (raising TypeError on mismatch)

Classes are compiled into extension classes without __dict__ (much, but not quite, like if they used __slots__)

Monkey patching doesn't work

Instance attributes won't fall back to class attributes if undefined
ahh, strict-mode python

#

Instance attributes won't fall back to class attributes if undefined
i always forget to annotate my class attributes as such

silk pawn
#

out of all the proposals to take away the GIL that bdfl has denied for making single-threaded applications slower, which proposal has the smallest slowdown for single-threaded applications, and what percent is that slowdown?

i was just wondering, because i read somewhere that guido won't allow taking away the GIL because it'll slow down single-threaded applications

#

if you can answer, please ping me with it

unkempt rock
#

I’m 14 and don’t want to work at a place like McDonald’s or something, do you have any idea if any tech companies hire at this age?

pearl river
unkempt rock
#

Okok

magic python
#

are there any metrics to gauge the popularity of a pep?

feral cedar
#

no way a tech company would hire a 14 year old

celest spade
#

guys i am a second year in college and looking for an internship..can you guys give me some advice because so far i have been rejected by 2 companies idk where i am going wrong

#

like im having trouble in getting an interview

unkempt rock
#

I ain’t going to college and living in debt for the rest of my life college is a scam

#

Just invest

#

And learn stuff about it

#

@celest spade

#

It’s ez

celest spade
#

lmao dude i already do stocks πŸ˜† i just want to land an internship, and I am blessed to have parents who pay for college

unkempt rock
#

Dude

#

You should start a huskiness

#

Business

#

I’m gonna start one in 1 year

#

But yeah college is a waste of time

celest spade
#

i want to start a business but i need to think of a proper idea lmao

unkempt rock
#

You will realize college is a scam one day

#

Do clothing

#

Remember

#

SupplyxDemand

#

= $$$$

celest spade
#

that is a big thing lmaoooo

#

big bank bro

#

lmao

unkempt rock
#

We got 75k in the bank

celest spade
#

damnnn lmaooo

#

wait is there like an off topic

#

we can go to

unkempt rock
#

I feel bad for you

celest spade
#

lmao why

unkempt rock
#

Thinking college will get you somewhere

celest spade
#

lmao im enjoying college and i am from an asian family so like they pay for my stuff and they want me to graduate

unkempt rock
#

Most jobs don’t even need college

#

Well I might dip high school

#

I already know what I’m doing in life

feral cedar
#

yeah who needs education

celest spade
#

thats good bro

#

LMAO

unkempt rock
#

Legit

#

They are millionaires who dipped high school

feral cedar
#

survivorship bias is very strong

unkempt rock
#

My parents would pay for my college if I went

#

But I’m not going

feral cedar
unkempt rock
#

Find a successful route and stay on it

#

Teja needed it

gleaming rover
#

there are people who study because they find it interesting, you know

#

also, yeah, off topic.

midnight kraken
#

@unkempt rock Hop on back in here in 4 years and let us know how your decision turned out. Legitimately interested in finding out!

civic temple
#

This is some real advanced discussion

sand musk
#

I use metaclasses to bind class attributes
@gleaming rover thanks but mind sharing some real example? I'm really looking to grasp when is necessary and beneficial to use within python

gleaming rover
#

@gleaming rover thanks but mind sharing some real example? I'm really looking to grasp when is necessary and beneficial to use within python
@sand musk not at my work computer right now so

#

but honestly I think on most cases you can get by without

sand musk
#

i've seen it used for singleton implementation

gleaming rover
#

you could do that, yes

#

or with a class decorator

void lake
#

Can Anyone suggets me a good source for Probabilistic Programming in Machine Learning Domain?

fallen slateBOT
#

Hey @feral cedar!

It looks like you tried to attach file type(s) that we do not allow (.pdf). We currently allow the following file types: .3gp, .3g2, .avi, .bmp, .gif, .h264, .jpg, .jpeg, .mkv, .mov, .mp4, .mpeg, .mpg, .png, .tiff, .wmv, .svg, .psd, .ai, .aep, .xcf, .mp3, .wav, .ogg, .webm, .webp, .m4a.

Feel free to ask in #community-meta if you think this is a mistake.

feral cedar
#

oops

#

probability and statistics for computer science, david forsyth

novel bison
#

Hello

slim island
#

What do people think of the matrix suggestion from the mailing list? It seems to me that it wouldn't be overly useful. Possibly just ending up the same as array.array

violet mural
#

here anyone configured apache xampp server to host flask app?

slim island
violet mural
#

Thanks πŸ™‚

signal tide
#

@slim island idk there seems to be a couple issues with it if you read the thread

#

If anything they might as well integrate numpy in

slim island
#

The main argument for it seems to be that it's a way to use matrices in Python with a friendlier interface for Python programmers than numpy - and I like that, and think it would be good to exist - but it really doesn't take you very far in terms of usecases, and very quickly you'll have to switch to numpy anyway. I think the argument that it makes python more friendly to high school students/teachers is a very good one though

visual shadow
#

I don't like that it essentially tries to fragment the matrix world in python

#

There's already an ugly stepchild of this fragmentation called the array module in python, which 99% of the time lies unused and ignored vs numpy array

#

If there's a link for this proposal somewhere though I'd greatly appreciate it

#

Just to see if my first impressions have any merit or not

slim island
gleaming rover
#

showerthought: why is it import this and not import self?

slim island
#

Honestly, day dreaming about this matrix thing, and I'd just love it if it had slightly more natural indexing than numpy.~~ Being able to do my_matrix[x:x+10][y:y+3] to get a 10x3 slice would be much more intuitive than the numpy way to me at least~~ Probably not the indexing I just did, but something better than numpy's current way which I always misunderstand

visual shadow
#

Hm, there's merit to that, agreed. I personally perhaps have just gotten used to the numpy way of doing it by now, but it was not an easy transition at first.

#

I understand the angle that the mailing list post comes from, primarily trying to ease the burden of simple matrix operations for students

#

The only question is, does that merit creating a stdlib implementation for matrices or not, and I'm not sure there. I'd still lean against

slim island
#

my understanding is that numpy is more intuitive to people coming from R/matlab/other-mathsy backgrounds. And coming from a Python softwarey background, I find it very frustrating to work with - stuff like getting used to new ways of indexing, not using loops anywhere, having to learn a million methods

visual shadow
#

Haha, can't disagree. I essentially picked numpy without any background (wouldn't call myself even proficient in python in that sense) and it definitely was different

#

The trouble is, not using loops and recommendations around that side of things are essentially a necessary evil for performance. If we are not using 2d lists and having a dedicated datatype for matrices, I would presume that part won't change

#

For the indexing aspect though, it's very different from how rest of Python does it. That's always been probably the most jarring thing about it.

slim island
#

yeah, Julia is pretty much the only language I know where loops can still be fast on matrices and stuff

undone hare
#

Technically indexing in python is way faster than resolving a name, since you just use a memory offset instead of going through an hashmap