« first day (4486 days earlier)      last day (448 days later) » 

5:18 AM
duckduckgo.com/… Why is this kind of thing so hard to search for???
(Do we actually have anything like a canonical for that?)
 
 
3 hours later…
8:02 AM
Unfortunate typo of the day: threading.Threat(
 
Even a broken Freud is correct twice a day!
I think they call this foreshadowing.
 
Good morning, I created a class that relies on method chaining.
        import lib
        pw = {..}
        class A:
            a = lib.lib_function(**pw)
            b = a.lib_function2()
            def __init__(self, x=None):
                self.x = x
            def do(self):
                return self.b.lib_function3(self.x)
            def action1(self, y):
                return A(y+y).do()
            def action2(self, y):
                return A(2*y).do().lib_function4()
            def action3(self, y):  # general purpose, in case no
                return A(y)
There is 1 aspect that does not feel right: saving password as global and initializing library via class variables. A much cleaner way would be to pass to instance.
        import lib
        pw = {..}
        class A:
            def __init__(self, x=None, pw=None):
                self.x = x
                if pw:
                    self.a = lib.lib_function(**pw)
                    self.b = self.a.lib_function2()
 
Where does the password actually come from in the real application?
User input? Some config? Is it static?
 
I would like this to be a kind of library for other to use, so I assume it would be cleaner to create a new class for credentials and read the object in A.__init__?
 
8:19 AM
@trincot (doesn't seem to be present right now, but I think is a regular?) I think I misunderstood the central problem in stackoverflow.com/questions/75254007, but this question is still clearly NMF and you should know better than to provide an answer.
 
    class Connect:
        def __init__(self, **pw):
            self.a = lib.lib_function(**pw)
            self.b = self.a.lib_function2()

    c = Connect({..})

    class A:
        def __init__(self, c=None, x=None):
            self.x = x
            if c:
                self.a = c.a
                self.b = c.b
 
@aeiou It's not clear to me why there is a "password", or why it's necessary for calling the lib_function. When you call it a "password", are you trying to convey that it should be kept private somehow? (in that case, shouldn't it be read from a secrets file or something?) Or do you just mean that it's config data?
Also, what will be done with the results from the lib_function and lib_function2 calls? Is there a particular reason we're keeping track fo that?
 
@KarlKnechtel Yes, user specific secrets. The idea is user solves passing of secrets independently.
 
Should lib_function be called again each time an instance is created? Or just once? if once, then what are the restrictions on when that happens?
 
lib_function is connection to database. It is called just once. I am not attempting (shall I?) to solve more tries?
 
8:25 AM
so multiple instances of A should share a database connection?
 
lib_function connects to db, lib_function2 creates a cursor, do points to cursor and do is invoked to do actions
@KarlKnechtel This is not intended. The reason for separating in 2 classes is to make it somehow cleaner.
If something, it would rather be separate instances of connection and associated A. The class A just conveys some actions in database and library functions.
 
9:06 AM
Question: I'm wondering how Python's sysconfig.get\_platform() and/or distutils.util.get\_platform() work under the hood. On mac when I run these, I get "macosx-10.9-x86_64". I'm not quite sure I understand where this information comes from. When I go to my CLI and type uname then I get back "Darwin". I also see "Darwin" when I use platform.system(). If I were to re-create this in Bash without Python, where is Python pulling this information from?

>>> import os
>>> os.name
'posix'
>>> import platform
I'm working on a Mac script, and wondering if I can generate the "macosx-10.9-x86_64" string without Python.
Bash script*
 
Technically, MacOS "is" Darwin just like Ubuntu "is" Linux.
 
Looks like it's based on the output of uname, but post-processed somehow. See the source code
 
sw_vers looks promising
$ sw_vers
ProductName:		macOS
ProductVersion:		13.1
BuildVersion:		22C65
Python itself parses /System/Library/CoreServices/SystemVersion.plist
 
9:25 AM
That's some good information, thanks. Grabbing the ProductVersion from the SystemVersion.plist agrees with my Operating System version: 12.4
I'm not 100% sure why Python tells me 'macosx-10.9-x86_64'. I'm wondering if that's a cache or something of my operating system version when python was installed or something
Ah, I see where the 10.9 comes from now.
https://bugs.python.org/msg157509
So it's
>>> import sysconfig
>>> print(sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET'))
10.9
Thanks MisterMiyagi, that info regarding sw_vers and SystemVersion.plist looks much better for my use case.
 
10:06 AM
I feel i'm doing something bad in git, but is there an easier way to do the following sequence:
git checkout <somebranch>
git merge <branchIwasIn>
git push
git checkout <brachIwasIn>
 
10:35 AM
@paul23 just fyi, there is also a git room
 
It's scary that the answer isn't an immediate "yes, of course", especially considering that in most cases you should probably run more than just those 4 commands (pytest, coverage, sphinx, ...). This part of the development workflow is such a disaster
 
If you need it often... define a shell function.
 
hello! i have a couple of classes and functions, and I'd like a command line interface where i could create instances of my classes and call functions in real time by manually typing it out
is there any readily available library or option i can use to obtain this?
 
@Aran-Fey those 4 commands are the "final step" after you tested the current branch and want to push into main/whatever.
 
@paul23 Erm, why don't you test after merging? That changes the codebase after all.
@shintuku Something like my_program.py SomeClass("Foo", 12).quxnicate(7)?
 
10:46 AM
@MisterMiyagi oh in the current specific case I "merge" into a "production" branch which is just something the build server reads to update the live code.
 
@MisterMiyagi rather, I first run the program. say I have a class called Object, so in this command line-like interface, i would type, first_object = Object(), second_object = Object()
 
exec(input())?
 
so, I'm creating instances in real time. and if I have functions related to these, i can type out, example_function(first_object, second_object), in real time, not necessarily beforehands inside my_program.py
 
@shintuku How does that differ from the REPL?
 
is using celery, shared_task is dumb idea in django sync restful api calls ?
 
10:49 AM
@paul23 Which is thus also exactly what you should be testing, no? At least it works that way in MiyagiCorp. Things that get deployed should always be runnable.
 
@MisterMiyagi i'll look up what that is, thanks for the tip!
 
It's now 11:49 and I wish Python had an if+with combo again.
That means my personal counter is now at... squints many many lots.
 
@MisterMiyagi that was exactly it, thanks for the help!
 
@MisterMiyagi but the testing also happens on the production server before the server replaces the containers anyways.
 
@paul23 And are you the only one using the production branch from the server?
If not then now your team has a broken central version halting work for everyone.
 
10:55 AM
The "central" version is "main" - I'm currently the only one who is pushing to production. Though that does indeed need some rethinking.
 
 
3 hours later…
1:28 PM
Interesting. While looking at stackoverflow.com/q/75258586/953482, I used 7zip to explore the contents of "pip.exe" in my Python/Scripts folder. It contains a small .py script that imports and calls pip._internal.cli.main.main().
I'm surprised that 7Zip can extract anything from an exe file. Unclear to me whether the exe file is a zip file cleverly disguised as an exe file, or if it's a regular old exe and 7Zip can do this kind of thing for any regular old exe.
 
My understanding is it's mostly a zip file (not sure which compression algorithm they use, if any) wrapped with a thin exe that calls components in the zip. That's pretty much how PyInstaller works.
 
I think it doesn't use any compression. If I open pip.exe in Notepad++, after the first 700 lines of human-unreadable noise, I can see the plaintext contents of the small .py script.
There's also a bit of xml earlier on, but that counts as "human-unreadable noise" :-p
Interesting that my Python path, "C:\Python311\python.exe", is hardcoded into the file. I guess it must be generated on the fly whenever I update pip.
 
1:45 PM
when I played around with pex the resulting zipapps looked very similar. I think it was usually just a zipped folder of dependencies, and then the line of code that called the entrypoint was prepended to the archive
when I opened that file with an editor and deleted the line, it was recognized as a zip again
 
"The zipfile specification allows for arbitrary data to be prepended to a zipfile". Today I learned.
"If your archive program can’t handle this, it is a bug in your archive program." These are the words of a man who has had to explain this many times in the past
 
2:25 PM
@Kevin it probably scans the file for a 7zip or supported format header. I think I saw that once on Linux, but didn't know this was done on Windows too
@Kevin yeah, that's a self-extractable installer. Anaconda use this a lot too (their Linux installer used to and probably still is just a bash script that untar itself)
 
7zip can extract C:/windows/notepad.exe as well. I suspect notepad doesn't depend on zip.
 
I can smell the possible security vulnerabilities from here
 
3:11 PM
@Kevin FWIW, on linux it's just a python script. it's marked executable, has no .py extension, and is given a shebang with the absolute path to the corresponding python (at least in virtualenvs)
oh, judging by that script, also it looks like pip._internal.main got moved again, to pip._internal.cli.main
it's almost as if the answer I wrote the other day was correct
(rather, gave correct advice, by, you know, reading the documentation)
 
3:53 PM
hi @KarlKnechtel, only wanted to update you that I will study your reply over the weekend. It provides a lot of food for thought and testing. Thank you.
 
 
1 hour later…
5:19 PM
I just realized haven't seen Andras around lately is he not coming in this room anymore?
 
Not often
 
I did try to backread but didn't find anything but just curious anyway not like i've been around for while
 
5:54 PM
@shintuku Take a look at the -i command-line option. docs.python.org/3/using/cmdline.html#cmdoption-i
 
6:50 PM
How much bigger would a exe file made with python be than a exe from c or another direct compile language?
 
Depends
For example, consider a compiler written in Python, that compiles C code into an executable; and a compiler written in C, that compiles C code into an executable. If you run both compilers on the same C code, I would expect the resulting exe files to be the same size.
Now consider an executable that was created by running PyInstaller on a Python file that contains print("Hello, World!"). And consider an executable created by running a C compiler on int main(){printf("Hello, World!"); return 0;}. I would expect the executable made by PyInstaller to be much larger than the one made by the C compiler.
Another way of looking at it: it depends on whether you're asking about an exe made from Python, or made by Python
 
7:11 PM
What's the difference?
 
I bet a determined fella could make a pretty small python program that writes this.
 
Send it on codegolf
 
 
3 hours later…
10:07 PM
@12944qwerty A C compiler translates C source code into machine code, which the CPU can run directly. A program that makes an .exe from a Python program works quite differently.
It simply bundles up the Python source (including any necessary modules) and a Python interpreter into an executable archive. So when you run that .exe, it basically extracts the interpreter, launches it, and feeds it the Python script. Thus the .exe is relatively large, and it runs at normal Python speed, not machine code speed.
 
10:21 PM
@NordineLotfi Definitely. Back in the day of floppy disks & dial-up bulletin boards, some "genius" added the ability to make self-extracting archives to their archiver / compressor. The plan was to make it easier for people to be able to extract stuff. There were a bunch of competing incompatible archivers, with different versions. Admittedly, it could be annoying to get some cool program in archive form & then realise you didn't have a decompressor / extractor for it.
However, self-extracting archives are obviously larger, which is a big deal when you're using 2400 baud modems and floppy disks that hold less than a megabyte.
And then self-extracting archives started appearing that were infected with malware. That tended to make many people rather suspicious of all self-exracting files. ;)
But some people really liked the convenience. And a few years later we got things like CD-ROMs that auto-run when you insert them...
 

« first day (4486 days earlier)      last day (448 days later) »