« first day (4495 days earlier)      last day (436 days later) » 

7:16 AM
Regarding what I asked once about detecting/watching for close file event on Windows, I think I found a way forward, thanks to this and this (as alternative).
main problem though is, based on my own experimentation and the similar conjecture of that answer, it seems like it's easy to lose or miss some events :/
 
 
1 hour later…
8:44 AM
@KarlKnechtel got you, that makes sense.
 
 
2 hours later…
10:49 AM
sigh... here's some garbage with 29k views: stackoverflow.com/questions/38444658
 
@KarlKnechtel I probably told you before, but: unless it's actionable there's really no need to come and bring crap here for everyone's detriment
 
11:16 AM
I mention it because it looks perfectly "actionable" to me in that if it were a new question it could easily be dealt with. as an old question, socvr doesn't care unless it's NATO
I thought the view count was remarkable, in particular. I'm trying to assess the size of the problem where people find bad stuff with a search engine
 
12:10 PM
at Karl: thanks for your previous comment!
new question, i feel like my code is spaghetti. any suggestions for organizing this better?
class MyClass

	classlist = []

	def __init__(self) ...

	def method1(self) ...
		(modifies self index in classlist)


def initialize():
	(constructs a pre-defined amount of MyClass instances and appends them to classlist)
 
@shintuku if you want to show large code block, feel free to use an external link (eg: pastebin, dpaste, etc)
 
my bad! will do this next time
 
the above isn't large, I meant what I said earlier since you used "..." to show that there is content omitted. I thought maybe you wanted to show a larger code block but didn't so it's readable (you probably have other reasons, but that's beside the point)
 
oh i see, perfect, thanks and noted
 
it's not immediately obvious why you think it looks like spaghetti. I guess maybe the naming scheme (method1, initialize) could be seen as peculiar, but it isn't too weird
one thing though is, you should probably place the classlist = [] inside the __init__ and then redefine it differently elsewhere (eg: in one of your method, etc)
 
12:18 PM
i thought that maybe having an external function that acts as a constructor and modifies a class variable might be clunky design, but if its not, great!
for your comment on the classlist: do you mean, to give the classlist as an argument to _init_?
 
@shintuku I meant something like this: stackoverflow.com/a/19292653/12349101 Basically instead of placing it outside __init__, place it inside of it.
then you can modify it inside the class using the other method
 
oh i see, thanks for the comment!
will implement this
ohhh, this is way neater! we initialize a self.classlist by calling an instance method, e.g., instance.initialize(), that only gets called by __init__, and only gets called once during construction
 
yep, that's what I meant
 
thanks, this looks way cleaner
 
12:48 PM
@shintuku Why does the instance have a method that modifies its position in the list (assuming I understood that correctly)? More to the point, why do instances know about the list? What if I wanted to make an instance that isn't in the list? Why shouldn't I be able to do that?
It's only possible to come up with a sensible approach to the problem if we understand why there is a list in the first place.
 
hm, sorry for not giving enough context. the list is a queue and the class instances are things I have to recall. if I fail to recall them, then they're put in the last place of the queue. if I succeed, they're removed from the queue
 
ah, you're implementing some kind of "spaced repetition system" / flashcard tool?
 
right
so if I fail or succeed, i can call instance.fail() or instance.success() to rearrange the queue
 
right, so, I have seen this design issue countless times going back many, many years (to back when I, unfortunately, primarily used c++, at least when talking about code on the internet)
 
very interested in what you have to say
 
12:55 PM
the short version is, you don't actually want the instances to care about the container. Instead, you want the instances to be able to tell you whether they failed, and do the container manipulation outside.
there isn't anything special about the class, that makes it tricky to remove or reorder it from a list. so, code that changes the position of an instance in a list, doesn't need to know anything about the instance, and as such doesn't need to be part of the class interface.
(related: look up what Herb Sutter has to say about designing C++ interfaces.)
we can easily have code outside the class along the lines of
def practice(questions: list[MyClass]):
    while questions:
        q = questions.pop()
        q.show() # display the flashcard to prompt an input
        if q.test(get_response()) == MyClass.WRONG: # find out from the flashcard that the user's answer is wrong
            questions.append(q)
the process of "ask the user a bunch of questions based on a list of flashcards", works the same way no matter what list we're talking about. This lets us construct multiple lists, for example to handle different topics or difficulty levels.
of course I have abstracted out a lot of things here. If you are using a GUI then the entire code structure will likely need to be different in order to be properly event-driven.
 
i see
 
but the point is that the flashcard's actual responsibility is to verify whether the user correctly responded to the prompt
and not to manipulate the list.
 
so each instance would have, e.g., instance.verifycorrectness(input), and return True if the input was correct?
 
we don't need a list to use the flashcards, after all. we could equally well write a program that just reads whatever config file, chooses some random card data, presents one flashcard, and tells the user whether the result was correct.
@shintuku yes, .verifycorrectness is precisely what I call .test in the example.
 
i see i see
i'll attempt an implementation of this
 
1:04 PM
also, thanks for the blog article topic idea. (It would be difficult or impossible to form this into a proper question for a stack exchange site)
 
thanks for the comments, very instructive, i'll be working on this today
 
well, it helps that I saw your previous questions, and had a vague idea that the discussion was headed in this direction ;)
 
@KarlKnechtel i have a question for you, why do you organize the display output so that it is called by an instance, instance of having an external function that takes the instance as argument and displays it?
 
1:21 PM
@NordineLotfi that's not "a large code block"
 
@AndrasDeak--СлаваУкраїні yes, I explained why I said that just under that: chat.stackoverflow.com/transcript/message/55935079#55935079
 
OK, fair enough
@shintuku style note: prefer snake_case as verify_correctness, makes your code much more readable
 
noted, thank you
 
 
2 hours later…
3:49 PM
What does this flag mean and when would i want it? Is it basically just calling flush() on every print or is there more to it?
 
Yes, I think so
 
The note about 3.7 makes it seem like it was rendered superfluous anyway (from my reading of that statement) but I never saw any real change from 3.6 (not knowing it existed as a flag)
 
I've been using it a lot recently, it is very useful for me and it works very well
Superfluous?
 
Well it says that from 3.7 onwards, stdout is unbuffered. So it looks like it's applied by default, meaning you wouldn't need to apply the flag
 
Hmm, I understand now
 
3:54 PM
But I can't really remember ever needing to flush stdout pre 3.7
 
Well, it's very strange, because without using it I can't make it stream unbuffered
Yes, I was using Python > 3.7
 
I suspect its a threading/multiprocessing thing. I'm just curious about its original use
 
Yes, it must be
 
~nvm~
 
Thinking way back I think I did flush on multiple processes but then that raises more questions for me on how the buffer would work, since it kinda implies there (was/is) a single buffer for all processes. The more I learn the less I feel I know about multiprocessing to the point I can spook myself with hypotheticals
 
4:02 PM
@Marco >= 3.7 *
Right
Speaking of multiprocessing I managed to solve the problem I was having
 
@roganjosh this is similar to what's on some Linux tools like sed. This basically force whatever is being held in memory to be forcibly flushed, as in, written (eg: to disk) even if it's size is smaller than the buffer, or even if it didn't finish it's execution yet. A familiar example would be the flush argument for print.
 
is there a shorter way to do
my_dict["key1"]["nested_key5"]["meganested_key2"] = my_function(my_dict["key1"]["nested_key5"]["meganested_key2"])
 
@roganjosh I feel like it was rendered superfluous because this is more of a "general" flag, instead of the fine-grained way of doing it on a per cases basis using, as mentioned above, the flush argument for print
 
@shintuku not if you choose to name only the outer structure.
 
@roganjosh it's hard to find a good use case, I admit. I probably used forced flushing a lot of times in Linux, but that was for a bunch of reasons. All of which being that sometimes, if whatever you're printing/writing is smaller than the buffer where it is held, then you need to forcibly flush, otherwise you leave it up to the buffer or when it finish executing, then the OS/interpreter/etc usually do it on it's own
ah, just noticed I pinged you three separate times, my bad...
 
4:10 PM
It's fine :)
 
at roganjosh: outer structure, i.e., the set of successive keys?
there's no native call for "whatever is being assigned"?
 
No, unlike C++, there is no way to intercept assignment as an operator. When I've needed something like this, I implemented __lshift__ or __ilshift__, so that x << 100 or x <<= 100 would call my special assignment-time code.
 
huh, interesting
thanks for the answer!
 
In python I'd find that really confusing if I'm honest
 
I think I saw a method in a class called __shift__ something once, but didn't check what it did
 
4:23 PM
found out dictionary comprehension exists for what I wanted to do
 
@roganjosh Making me think a bit about how pyparsing's Forwards currently accept the assignment of their contents (using <<= operator). If this looks confusing, maybe I should add an equivalent instance method on Forward.
 
you could also just add a comment or a docstring explaining how it works (if that isn't done already)
 
Pyparsing is pretty heavy on operator overloading: pyparsing-docs.readthedocs.io/en/latest/…
 
I mean, you were the originator or a major dependency in our ecosystem that has stood the test of time, so maybe it's me that needs to adapt. It just wouldn't be so clear to me that this had been overriden on first read
To be more concrete on my position, it would be easier to suggest:
a = my_dict["key1"]["nested_key5"]["meganested_key2"]
a = my_function(a)
But I didn't mean to suggest that pyparsing needs any clarification. I don't know enough about the library for a start!
 
but this doesn't mutate the dictionary :(
 
4:34 PM
Have I done a boo boo with my mental python? I need to fire up my laptop
I have indeed. I will retire in shame for a bit. Apologies for the bad advice
 
np i do the same always
 
Eh, no, this one is bad for me. I've been away from programming for a week and already totally screwed up my mental programming.
 
No problem, you are a human
In fact, even ChatGPT makes frequent mistakes
 
.... comparing me to ChatGPT is like twisting the knife! :P
 
No, I'm commenting on the phrase that humans make mistakes, but actually even ChatGPT, which is a good (well, it's relative) robot, makes mistakes.
 
4:53 PM
@roganjosh @shintuku could go one level up with subdict = my_dict['key1']['nested_key5']; key = 'meganested_key2'; subdict[key] = my_function(subdict[key])
sorry for the pings
 
No worries. They are my "shame, shame, shame" bell tolls :D that must be one of my biggest brain farts for years
I did earlier overhear a conversation about how we'd solve our energy crisis by putting mirrors on the moon to harvest the kinetic energy of the sun. That makes me feel better, though
 
Does it make you feel better that you're so much better than ChatGPT on a lot of subjects?
 
5:31 PM
Does any one here know how to resize my PyTorch tensor properly? I have a tensor with the size of [1, 3, 64, 64] and I want to change its size to [1, 4, 64, 64]. If possible, I want the new created layer to be the same as the previous, like `newtensor[0][3] = oldtensor[0][2]. Thanks!
Sorry I forgot to mention, the tensor has requires_grad=True
 
5:50 PM
@Marco what was the solution? Just curious
 
I don't know in detail (I probably won't even be able to figure this out in detail), but definitely related to version mismatch with at least one software/package. Probably related to the version of CUDA and/or Pytorch and/or Python that were causing incompatibility with the GPU I was using.
Thanks for asking.
Sorry, this is the description of the problem clarification. This culminated in me creating a new environment installing brand new versions of the various packages I needed to use, including PyTorch and Python.
@Marco PyTorch *
various packages or softwares *
 
6:09 PM
got you
 
6:23 PM
Nice
Weird thing about it: I didn't received any output erros
 
i have a list of 2 element lists (lists that have 2 elements each)
what can I do to iterate over it in the same way as we iterate over enumerate?
i.e., over:
for i,e in enumerate(lst):
 
@Marco didn't receive*
 
6:40 PM
is the following the nicest way?
for i,e in [tuple(i) for i in list_to_tuple]:
sucks that I have to tuple it first
 
@shintuku you don't
for i,e in list_of_lists:
Like I said, duck typing. All sequences work.
 
ah, you're right! but it's giving me a too many values to unpack exception
but it works
 
If you tuple it first, it's already an iteratable. Otherwise it wouldn't work
 
@shintuku so not all items have length 2
 
nevermind, it wasn't working because there's an element of the list that had 3 elements
right, nice catch
thanks for the help
 
7:30 PM
while True:
    if input == choice1:
        ...
        break
    elif input == choice2:
        ...
        break
    elif input == choice3:
        ...
        break
it the above bad design? it attempts to ensure a valid input is given, otherwise it asks again
 
else: continue and break after the block?
and if the ... is not there then if input in choices can help
And don't call it input :P
 
am trying to parse your comments
oops, yeah input seems like a type
what do you mean by else: continue and break after the block?
 
while True:
    if cond1: foo()
    elif cond2: bar()
    else: continue
    break
On mobile, add the PEP8
Or just move the verification logic into a function
 
ah that is way nicer! thank you
 
 
2 hours later…
9:32 PM
"[(23.12.hello."
I'm trying to get the correct RegEx to return "23.12."
so far I have "\d*\..*\.", but this also includes 'hello', i.e., it returns '23.12.hello.'
any suggestions?
 
@shintuku my suggestion would be to either work through a tutorial, or do some focussed learning aimed at (now) regex.
the volume with which your basic questions are pouring in doesn't seem too maintainable
 
my bad, thanks for the comment
 
If you want to match two groups of digits, look for two groups of digits. You only have one \d in there.
 
ah! that was it
thanks!
 
10:36 PM
Hello, is there any good way to prevent AVG to scan pyinstaller executables?
This is only happen at the first time.
 
@ChrisP uninstalling AVG? ;)
 
@ChrisP Configure it to not scan in the directory where they are.
 
10:58 PM
This mini program is to installed in 30 different machines that i am owner.
So uninstalling avg it's not a solution
* i am not owner.
 
stackoverflow.com/questions/75355961 do we have duplicates for this?
 

« first day (4495 days earlier)      last day (436 days later) »