« first day (4583 days earlier)      last day (589 days later) » 

00:01
@PaulMcG I think I recall some distros where third party packages automatically goes to /opt, but I forgot (I did too much distro hopping)
@PaulMcG I liked that too for some stuff I was doing. I remember once doing what some people call "amalgamation", where you basically take a multi modules/header/etc project, and put it all in a single file.
I only ever did that manually for html2text (a python3 fork, since the original one was in 2.X)
it did give some speed improvement (maybe because it didn't have to do the couples of file access it did when accessing modules) so that's something at least
Yeah, I actually toyed with something like that with the pieces of pyparsing, where I dropped in comments like this # 8< ----- (i.e. "cut on the dotted line") to recompose it as a single file if desired. I may revisit if it bothers me enough again.
I feel like it might be nice for large project, because the speed improvement really is eye-opening when you see it once
that's without even compiling it using the cython command or other optimization tricks.
With those "cut here" indicators, then I used another pyparsing file scanner to search for and stitch together all the desired bits.
Evan Hubinger has a cython version of pyparsing 2.4.7, that is about 10X faster than my pure-Python version.
Maybe faster even
I believe he uses it in his coconut language compiler, which compiles to Python.
@PaulMcG didn't know that one :o I guess it has some inspiration from Haskell.
reminds me of some stuff I saw Kevin doing in this room
Well it's been a nice chat with everyone, thanks for the links and kind words - rbrb
00:13
@PaulMcG it might be even faster if it's in pure C (as opposed to cython): jasonstitt.com/c-extension-n-choose-k
take care :)
I feel like pyparsing's performance has more to do with the sheer amount of customization hooks it offers... ?
like, it's creating all these ParseResults and internally lobbing exceptions around iirc
 
1 hour later…
01:50
Yes, there are lots of complex objects being created with short lifetimes, and many function calls (which are performance-killers in Python).
 
3 hours later…
05:05
To those who were there during my bytes compression thing, I need to store images. Should I store it in bytes like this or should I just store the actual image as a file somewhere
05:37
Images are already compressed, so compressing them again won't do much
 
3 hours later…
08:29
Mojo language - superset of Python, adds typing, vectorizing, and parallelizing youtu.be/6GvB5lZJqcE One of the comments captures it pretty well: "Speedups by 1000X means that something that took an hour now takes seconds."
09:29
This regex r'^(\d*(\.)?(\d+)?[eE][-+]?\d+)$' matches all these strings 1.79E+16, 1.2e5, 1e-5, 1.e+1 . But for me full string should not be any of these : 1.79E+16, 1.2e5, 1e-5, 1.e+1. I need a solution using regex itself!
09:44
Cool, you've told us what it shouldn't match. Now tell us what it should match.
10:06
1222.423525, 5572582582955245, 35E+767TYUU, GJKK5659857E+767E+ETYUU --> Any of these should match
10:18
So either it has a . or it ends with E?
user17135505
Good morning, do you know - is it possible to use an alias for inspect.stack()[0][3] which returns a function name?
user17135505
    import inspect

    def function_name():
        return str(inspect.stack()[0][3])

    def foo():
       return function_name()

    def foo2():
        return str(inspect.stack()[0][3])

    assert foo2() == 'foo2'  # works
    assert foo() == 'bar'  # does not work
well, don't check the top of the stack but its parent
user17135505
omg, easy
user17135505
thanks
10:33
it can any string other than scientific notation of any number!
Do you know how to match scientific notation?
I need to solve it using regex. This regex does that! r'^(\d*(\.)?(\d+)?[eE][-+]?\d+)$'
Isn't that the same one you had before?
Looks like it matches all float literals, not just scientific notaiton.
Tested it. It just matches scientific notation numbers
problem here is to find all strings that does contain scientific notation number in it
10:40
As in [s for s in all_strings if re.search(r'^(\d*(\.)?(\d+)?[eE][-+]?\d+)$', s)]?
Is it possible to come up with something like "not matching regex"? I mean negation of regex that I have provided here?
You can combine negative lookahead (as in (?!...)) with an existing pattern to negate it.
Or just negate the re.search match.
So in the above comprehension, us if not re.search(…) instead of if re.search(…).
I tried negative lookahead (as in (?!...)) with an existing pattern to negate it. Could not come up with proper expression.
Tried this - r'^(\d*(\.)?(\d+)?(?![eE])[-+]?\d+)$'. But it did not work for my use case
user17135505
@MisterMiyagi is it possible to get parent of parent?
I must be doing something wrong here
11:38
...why did you put the (?!...) in the middle of the regex? Use (?!^\d*(\.\d*)?[eE][-+]?\d+$)
12:12
No. It is not matching for these - 1222.423525, 5572582582955245, 35E+767TYUU, GJKK5659857E+767E+ETYUU . I mean non scientific notation numbers
user17135505
12:50
    import inspect

    class Printing:
        def printer(self, a, b=None):
            print(f"{self.grandparent()} : {a}")

        def grandparent(self):
            print(inspect.stack()[0][3])  # grandparent
            print(inspect.stack()[1][3])  # printer
            print(inspect.stack()[2][3])  # action
            print(inspect.stack()[3][3])  # main
            return inspect.stack()[2][3]

    class Process:
        def __init__(self):
            pass
        def action(self):
            printer2('first action')
user17135505
With inspect.stack()[2][3], I get the name of function which is action. Going one step above, I get main.
user17135505
Is there any way to get the name of class where action sits, i.e. Process?
Only very convoluted and unreliable ways
user17135505
13:28
Ok, i thought there is some magic method... Cheers
13:53
is it that convoluted? the locals of the associated callstack should have access to a name action, which in turn has at least a __qualname__ you can check
There is in fact no action variable in the locals of any frame on the stack.
Aran-Fey is absolutely right about there only being convoluted and unreliable ways to do this.
really? brb, need to test
14:09
inspect.stack()[0].frame.f_code.co_qualname seems to work well enough.
Huh. Looks like co_qualname is new in 3.11. That makes things somewhat more reliable than they used to be.
Hm, without that there really doesn't seem to be a straightforward way.
You'll still get some weird surprises, such as with C code that doesn't show up in the stack, with class name changes that don't get reflected in co_qualname, or with stuff like @dataclass-generated methods that weren't really defined in the class they were attached to, but it beats what you would have had to go through before.
14:49
@user2357112 I'd have thought it should be there, simply because it's a valid name in that scope, and intuitively frame.f_local + frame.f_globals -> scope
the more you know 🌈
user17135505
15:14
just discovered traceback. Do you use it in anything remotely complex?
user17135505
i had a general except Exception as e: log(e) at the top of script but that is not always telling
user17135505
@MisterMiyagi cheers, added a comment in script to use this once on 3.11+
just discovered a new fact about lambda: stackoverflow.com/questions/47013834/…
@learning_python_self if you want to see a good example, you could look at the built-in trace module: docs.python.org/3/library/trace.html
I remember modifying it once directly (since I wasn't sure how to do it by injection or inheritance) to add support for writing to a file and to stdout at the same time, among other things. It's pretty nice for debugging if your code does not have a while loop
of course, if your output have too many frozen modules in the log, then it might be time for using pdb, gdb or something else...
user17135505
15:30
Because the loop would generate long outcome?
yep
you could stop it and still find use from the cut output, but you know, I guess it's less interesting if you don't capture the full log until the program finish
user17135505
In the last days, I deepened my understanding of exceptions... Seems to me this is what makes development 'responsible'
user17135505
However, I also have a feeling my program is getting much slower with all these outputs
user17135505
Appending each line individually to a log file seems quite costly
of course it's getting slower. Especially if you don't do all those individual write all at once or using larger chunks, you will notice it's getting slower at some point. And even if you use larger chunks/larger write, it will also come a time where it will be slow
16:25
@Aran-Fey so should i store as file or as bytes?
17:20
Store it as bytes how? A file, for example, is a way to store bytes.
Those 2 options aren't mutually exclusive, and the latter is too vague to mean anything
@Arne It's not a valid name in the scope though, because of the way class namespaces work. You could only access it as self.action
 
6 hours later…
23:51
@12944qwerty This doesn't mean anything (see e.g. stackoverflow.com/questions/75078605)

« first day (4583 days earlier)      last day (589 days later) »