« first day (3987 days earlier)      last day (966 days later) » 

1:19 AM
Hey all, wondering if you can point me in the right direction - I have a class that extends a base class. Upon instantiation, I want to check if the subclass has one of the classes implemented from its base but I'm not sure the best way. hasattr(self, '[method]') returns the method from super not the child - so it always appears as its implemented.
 
1:44 AM
^ Made it into a question : stackoverflow.com/questions/69186176/…
 
 
1 hour later…
3:04 AM
Which one of your did this: github.com/borzunov/plusplus ?
 
3:44 AM
Can anyone recommend and reading on unit testing in Python? I'm not working with Django but instead focused on writing an app that communicates with google cloud.
 
@Mikhail this is cool, I assumed one has to hack the parser to add new expressions, but after reading that it is syntactically correct and the byte code hack applied makes this a lot more doable that I thought it would be
that does not mean its still doable by me :D
 
 
2 hours later…
5:50 AM
cabbage!
 
 
7 hours later…
12:40 PM
I bet you could implement ++x for user-defined classes without hacking the Python engine, although it wouldn't be able to tell the difference between ++x and +(+x)
 
How about postincrement?
 
syntax error
 
Syntactically valid code is overrated.
 
1:04 PM
Oops, I thought I had a cool way to make x = +y; z = +x not trigger my custom preincrement behavior, but it doesn't work, and I don't know why I ever thought it would work.
 
Pro-tip: Just store when +x was invoked, and raise an error if ++x is delayed longer than two average bytecode instructions.
 
Hi everyone. Does anyone here have experience working with Convolutional Neural Networks?
 
No, but it's funny, I was intending to read up on them today
 
@DarkRunner can you ask user rb3652 for help? :P
 
Very funny
I'll just check the documentation again.
 
1:11 PM
Feel free to ask your question if you think there's a chance that I'll be able to figure it out during my Wikipedia dive on the topic
 
1:39 PM
guys anybody got any good articles on memory management during python script lifetime? I have run into an issue where the script i am running is consuming to much memory and even though i am manually removing variables and saving data to json files it still seems to use to much and want to leanr how to stop this
 
I don't have any reference. But odds are you're keeping references around, so when you "remove variables" the variables still stick around.
 
I only know like three good articles on any Python topic whatsoever
 
you can check e.g. by setting a weakref on one of the "variables", then "removing the variable", and checking if the weakref gets invalidated
 
There seems to be much more demand than supply when it comes to accessible and professionally written prose on programming theory
 
I'm sure there are dozens of youtube videos around
 
1:45 PM
@AndrasDeak how would i do that? O have been using the del keyword to manually remove variables
fair
 
@Kwsswart yes, that's how you delete names
Deleting a name reduces the corresponding reference count by 1. You need a reference count of 0 for the variable to be deallocated.
 
how could i check for references
 
Do you have to ask me those questions, or can you ask google?
Like "python weakref" or "python check references"
 
fair
will do
sorry mate
 
I'd start with a weakref because that is easier to get right the first time
for starters you should start with x = 1024, add a weakref to that, do del x and check what happens to the weakref
if you see what's going on there, do the same to your real problem and see if the same happens when you del the name
 
1:48 PM
My gut tells me "if you're trying to manually deallocate objects because they're staying alive in your context for too long, maybe you need to use smaller contexts". One way of doing this is to ensure that all of your functions are short. The end of a function essentially dels all local variables it was using.
 
there's probably pandas involved, and it's very easy to end up with stray views that keep each other alive
>>> import weakref
>>> import numpy as np
>>> x = np.arange(10)
>>> y = x[3:5]
>>> xref = weakref.ref(x)
>>> xref()
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> del x
>>> xref()
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Hmm, even del y keeps xref valid, not sure what's going on there. Might be REPL shenanigans.
yeah, it works in a proper script
import weakref
import numpy as np
x = np.arange(10)
y = x[3:5]
xref = weakref.ref(x)
print(xref())  # [0 1 2 3 4 5 6 7 8 9]
del x
print(xref())  # [0 1 2 3 4 5 6 7 8 9]
del y
print(xref())  # None
 
have just run this myself
 
Quite possibly a REPL thing. If nothing else, the variable _ can make things linger a little longer than usual
 
but when running
weakref.getweakrefcount(weak_ref)
returns 0
 
@Kwsswart and what does that tell you?
 
1:54 PM
that there are no references to the weak_ref however when running weakref.getweakrefcount(new_list) throws an error as new_list is no longer defined
 
@Kwsswart so why are you asking python about references to a weakref object?
 
@AndrasDeak just executing xref() stores x into _.
You need to evaluate something else to get rid of the data formerly known as x.
 
@MisterMiyagi yeah, but weirdly even a subsequent _ = 42 didn't fix it. Might be magic underscore that's kept elsewhere.
@MisterMiyagi right, I forgot about that silly detail
 
_ = 42 set the global _, not the builtins._ used by the REPL.
 
silly REPL
(but noted, thanks)
 
1:57 PM
Disclaimer: Knowing too much about Python memory management may have negative effects on your outlook on life, the universe, and everything. Consult your doctor before ingesting knowledge of Python memory management. Don't drink and memory manage.
 
I heard that drinking can help with not managing memory
 
Science has proven a correlation between excessive drinking and core dumps.
Or so I heard...
 
When it comes to memory management, I think an ounce of prevention is worth a pound of cure. When you first assign to a variable, have a clear idea of its purpose, and how long it needs to live to fulfill that purpose. When you create objects, understand what values it is dependent on, and what objects it may be keeping references to. This includes both objects you create directly, and objects created by functions that you're calling.
 
@Kevin if I wanted to think about lifetimes I'd be using Rust
 
i care about lifetimes. in my universe everything lasts forever.
 
2:02 PM
@AndrasDeak Well hey, there's a thought. If memory management is really important, then using a language with more explicit memory tools may be a sensible choice.
 
2:13 PM
On a more practical note, I've found memory-profiler to work reasonably well to debug "leaks".
 
 
2 hours later…
4:20 PM
Hi All, I am using openpyxl on Windows machine that runs very important spreadsheets and runs all time. I am logging into the machine using a different profile. Can I be sure that using openpyxl, which will open and close Excel spreadsheet, does not interfere with spreadsheets running on the other different profile
 
Does the program modify the excel file or only read it?
 
doesn't the very act of opening a spreadsheet in windows lock it for use?
hm, i suppose im not sure how that interaction works when opening via a library
 
4:36 PM
Modifies the excel file
Remember you can log into Windows using different profiles
Profile 1 - Runs important Workbooks, runs 24 hours day
Profile 2 - my simple python program, that runs macro and save file
 
So what do you want to happen if the program tries to modify the file while someone has it open?
 
Question: Are Excel instances separate? Reason, e.g. if program fails, will affect Excel of Profile 1
Completely different file
 
If you start multiple Excel processes then they're independent, yes
 
Just worried if program, abends, it will kill Excel of other profile
Aaah thanks
 
But if you have a file opened and excel crashes, then excel won't release its lock on that file. Meaning that next time you open it, you will be told that someone else currently has it open. In that case, you will have to manually delete the lock file
 
4:41 PM
if the two profiles are not interacting with the same excel file, you dont have an issue.
 
Great, thats the answer I was looking for
Just posted question as well online, Thanks for the quick response.
 
@ParitoshSingh That's an interpretation of the question I wasn't prepared for :/
 
@Aran-Fey just smile and wave, smile and wave. :P
 
Can I use this place to ask questions?
 
you can, make sure you take a quick glance at the room rules as well to see what's appropriate or allowed
 
5:01 PM
@AstralWolf you can find our rules at sopython.com/chatroom
 
input = ["aaiabbc"]
# precondition -> variable length, user defined

sequences = ["aa","bb","ab","cc","bc"]
# n number of sequences

exp-output = ["aa","ab","bc"]
# i is ommitted (invalid, un-present sequence)
# traversal from the beginning
# note "bb" though apparently present is ommitted
need some help in approach
citing personal reasons i would like to avoid "re" involvement
 
@PIngu my first recommendation is to give a clear problem statement rather than a bunch of comments you only understand if you already know the problem
I could guess, but I shouldn't have to
 
@AndrasDeak okay,
 
If my guess would be correct, this problem is trivial to do inefficiently in python.
but yes, that 'note "bb"' note is completely unclear to me
 
5:17 PM
I need help with running Xonsh
Xonsh run both python and shell commands in interactive mode normally
But running script files which end with .xsh doesn't work for me.
 
Have you already checked if that's supposed to be supported out of the box?
 
like running it with CMD?
 
presumably you'd run .xsh with Xonsh, right?
 
I used to run it with Xonsh
and now running it with CMD doesn't show any error
but doesn't show the expected output as well.
 
5:35 PM
@AstralWolf edit and ctrl+k for code formatting, see also our formatting guide to chat
 
#Could you guys tell me which pseudocode is correct

#Definiton A

def func():
    inside func2's block scope
    inside func2's block scope

    def func2(): inside func2's block scope
        inside func2's block scope
        inside func2's block scope

#or Definition B

def func():
    not inside func2's block scope
    not inside func2's block scope

    def func2(): not inside func2's block scope
        inside func2's block scope
        inside func2's block scope
 
@AndrasDeak this is the error I get when I run a script called Untitled.xsh,

c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\runpy.py:125: RuntimeWarning: 'xonsh.main' found in sys.modules after import of package 'xonsh', but prior to execution of 'xonsh.main'; this may result in unpredictable behaviour
warn(RuntimeWarning(msg))
c:\program files (x86)\microsoft visual studio\shared\python37_64\python.exe: loader for xonsh.__amalgam__ cannot handle xonsh.main
 
@AstralWolf Honestly, I have no idea what a "block scope" is
 
@Aran Treat it as a "function scope" then, or just "scope"
 
Whatever that means, there's no way the first one is correct, where there's code outside func2 that should belong to func2 in some way
 
5:50 PM
For the first one, I considered it plausible because code inside func2 can access local variables defined in func without qualifying them first, right (without the dot prefix)
 
That's still unclear to me. Does a "scope" encompass all variables the function can see, or those it can write to, or <insert a bajillion other interpretations here>
 
dot prefix?
 
Thats what I was trying to figure out, because it seems that most resources use Definitoin B when they use the word "scope", but take a look at this answer: https://softwareengineering.stackexchange.com/questions/273302/what-is-the-relationship-between-scope-and-namespaces-in-python

it seems to argue for the Definition A of "scope"
 
i think you probably should be using the phrase "local scope" if you want to refer to local scope. and that will then mean definition B is correct
 
Good ol' terminology rabbit hole. I'm not going down that one again
 
5:53 PM
Even in python file .py after importing xonsh
the command echo is reported to be not defined in Pylance
 
@ParitoshSingh yeah i agree
From the answer, "A scope defines which namespaces will be looked in and in what order." (I assume when a name is looked up). Wouldn't this be considered part of the "name resolution" process rather than a scope?
 
i think Aran is wise here.
 
Business as usual ;D
 
Alright, I'll leave it and there then. I also have another more esoteric question
https://stackoverflow.com/questions/4698493/can-i-add-custom-methods-attributes-to-built-in-python-types/4698550#comment122301899_4698550

I was reading this answer about adding custom methods to built-in types, it seems that it is possible by subclassing the type, and then overloading or adding the methods you want. However, as the answer states, objects created via literal syntax still implement the normal dunder methods. Is there any reason this is so? For example
class int(int):
    """Changes plus operation to minus"""
    def __init__(self,x):
        self.x = x
    def __add__(self, y):
        return self.x - y

print(int(3) + int(5)) #Outputs -2
print(3 + 5) #Still outputs 8
You can literally define an int class that returns a custom string by overloading the __new__ method, so I am wondering why Python objects written in the second line fail to implement the new methods
 
>>> import dis
>>> dis.dis('[1]')
  1           0 LOAD_CONST               0 (1)
              2 BUILD_LIST               1
              4 RETURN_VALUE
>>> dis.dis('list(1)')
  1           0 LOAD_NAME                0 (list)
              2 LOAD_CONST               0 (1)
              4 CALL_FUNCTION            1
              6 RETURN_VALUE
literals don't bother instantiating the python types
 
6:04 PM
basically, python builtins go to the magical land of C. the invocation of literals can bypass the entire python object modeling stage
 
integer literals specifically are probably stored as CONSTs during the compilation phase
 
@AstralWolf Well, python doesn't know how to create instances of your int class. How is python supposed to know what value(s) to pass into your class's constructor? What should happen if your __init__ doesn't take any arguments?
 
time for an AST transformer that changes LOAD_CONSTs to type calls :P
 
The devs could go and define what happens in each and every case, but why should they? Overriding builtins is a terrible idea to begin with
 
Exciting news in an email from Atlassian/Confluence (cc @MisterMiyagi). You can now apparently use emojis to "jazz up your page"! It's the change I've been waiting for
 
6:10 PM
@roganjosh 🤩 🕺 👍 🥳 🎶!
 
@AndrasDeak @Andras This is the bytecode right? Do you mind briefly explaining the key things going on here? I have never analysed a dis output before
Ohhh, okay, I think I get it, invoking something via a literal bypasses any opportunity to check whether the class name has been modified or not
 
I'm not much of an expert, mind you. But what matters is that in the first case the interpreter first loads the literal 1, then it builds the list directly at the bytecode level, then returns that list. In the second case it loads the list name (whatever that is), then calls it with the argument 1, then returns the result. If you shadow list with your own type it will only be called in the latter case.
 
@AstralWolf The Short description of the scoping rules? Q&A might be useful. The official Naming and Binding spec is also reasonably readable.
 
@AndrasDeak thank you
alright miste, i'll get to work on them
 
@AndrasDeak oh, and that second one usually gives a TypeError when executed :P
 
 
2 hours later…
7:59 PM
cabbage
 
 
2 hours later…
9:39 PM
How to change the default interpreter
I use xonsh
Each time I want to run both .py and .xsh files using Xonsh
wihout invoking xonsh at the beginning of the command line like
xonsh script.py
 
right click -> properties -> open with -> xonsh
 
I mean in the editor
not in the file explorer
 
...which one?
 
VS code
 
hmm, no idea
 
9:45 PM
@Aran-Fey I'm sorry, in the Terminal not editor
I tend to sleep
and I'm tired sorry for the confusion.
I want to run my script I type in the command line of VS code
xonsh Untitled-1.py
but I want somehow xonsh be implicit
 

« first day (3987 days earlier)      last day (966 days later) »