« first day (3785 days earlier)      last day (1146 days later) » 

2:16 AM
is there any chance that chat formatting will align itself to post formatting? :-/
 
no
if anything major changes in chat it will probably be a shutdown
 
woah. is it not going over well with SO management?
 
It's just very much on the periphery and the person who wrote its software doesn't work at the company anymore (I think).
most people writing software no longer work at the company, to be fair
 
ok, i see. well, that's less drastic a reason. but with the same unfortunate outcome
 
Comment threads still dump into chat, and moderators use chat on various servers. So it's still seeing some use from the company's point of view.
 
2:22 AM
@AndrasDeak with the kind of changes being talked about on meta (like meta.stackoverflow.com/questions/405302/…) - who's actually going to implement them, then? SO is built on an SO/SE framework, not some bought or outsourced software...so if ppl writing it aren't around...or dropping, that can't be sustained for long, surely
 
There are still a few devs around, like Yaakov Ellis. And to be fair the obsoletion project is not a programming challenge first and foremost, but a UX design challenge.
And it's less "dropping", more "being fired"
 
(yeah, i was aware; but i don't follow meta as much)
 
The company's business model has been "assume we're too big to fail and hope we'll get the next round of funding or be acquired" for a while now, looking at how they manage communities.
 
that's messed up, but not inaccurate
 
but there's enough depressing news these days without ruminating on additional crap like this
 
2:26 AM
(y) <-- thumbs up emoji on another platform/older IMs
 
 
2 hours later…
4:33 AM
i have been using wget to download a file, from today it started giving me ERROR 403: Forbidden then i tried using requests and giving header but still it fails
url = 'https://www1.nseindia.com/content/fo/fo_secban.csv'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
r = requests.get(url,headers=headers)

with open('/tmp/fo_secban.csv', 'wb') as f:
    f.write(r.content)
somehow the website is not allowing me to scrape, but in my chrome browser im able to download the file without any issue
 
4:46 AM
I got to know that my IP Is intentionally blocked why the website :/ huhh
i am able to run the same script from some other network
 
 
3 hours later…
7:46 AM
cbg guys, do I need the "Download debugging symbols" and "Download debug binaries" on Windows? installing using the official python exe
I am going to run on a potato PC so I dont really want to install VS 2017, which is needed if I want to choose the debug binaries option
 
you only need "debugging symbols" and such if you suspect there is an issue with compiled code.
 
with what you said I dont think I will even need that, but I guess it should be a smaller download, I will then just ignore Debug Binaries, melon much
 
8:11 AM
I think all Python tutorial material (docs, blogs, guides, vids) should really put dictionaries earlier in the topic sequence. probably just after lists. they're insanely useful for a multitude of things.
I recall wanting to create "dynamic variables"/"variable variables" in my younger days (gwbasic). dicts/hash maps were not an option of course; and many times may not be the best option (like instead, just a list of values) but when used well, they're so convenient
/me thinks after seeing another "dynamic variables" question
 
8:29 AM
what is a dynamic variable?
 
wanting to create a variable whose name will only be known at runtime
# those questions look like this, though usually much less well-defined
for name, value in [("a", 1), ("b", 2), ("c", 3)]:
    create_variable(name, value)
 
....or which only come in to existence at runtime and whose names and number are possibly unknow-able at coding-time
(* well, technically all variables only come into existence at runtime; but you get what i meant)
i generally make sure to _quote_ "dynamic variables" because it's not actually a thing or very misunderstood.
i don't need to quote `lists` or `variables` coz that's actually a thing(s)
 
9:15 AM
Interesting
 
9:53 AM
Usually I see dynamic variables questions where someone wants to programmatically create something like x0, x1, x2, ..., usually by using exec. because they don't yet make the connection that that is actually what lists are for.
 
aye or dicts if they want their own names too.
 
10:15 AM
Hello :D
Could you recommend a better way for summing up all values here?
something like map or yield?
 
sum(i[1] for i in data)
 
okay cool
the pythonic way
@aneroid A little hard to remember, because I used C# for a long time :)
Thank you
 
or even...
sum(number for cell, number in data)
 
I did not understand the last sentence
 
cell, number will expand each item in the list to those two variables (since each item in the list is a pair of items) aka "tuple unpacking"
 
10:21 AM
When I tried first line I got --> TypeError: 'int' object is not callable
 
because you've assigned sum = 0 already. restart REPL
 
it is working
 
10:57 AM
@kame Note how even the syntax highlighter at pastebin uses a different color for sum than for other variables. That is always a good indication that such a thing already exists.
 
thank you
 
user13727121
oh my gosh it's been hours now and I'm still figuring out how to loop my program back to the beginning using the while loop, the damn thing keeps continuing down instead of going back to the code...
 
@CoreVisional you shouldn't break prematurely, and you should put the right condition into the while header. That's about it.
 
That sounds like a problem you can only have if your while loop has far more code inside of it than it should. Like, several dozens of lines or more
 
user13727121
i have this piece of code where if the user has used up all their guesses, the program will ask if they want to continue or not, if they do, the game will ask for their input again, if they don't, it will exit. The issue is that when they type "yes", they get asked again if they want to retry...
 
@CoreVisional sounds like the opposite of "continuing going down". We can only help debug code we can see. Sounds like more than a few lines so link it to a code paste site if you want us to look at it. Or boil it down to an MCVE and find the bug yourself.
 
11:47 AM
Split your code into a bunch of small functions (max 20 lines) and the problem will solve itself
4
 
is this a good way to show multiprocessing example in python? in my computer it get stuck for large list, my single process merge sort is faster stackoverflow.com/a/53474680/12502959
by large I mean n = 1000
this looked like a good way to tell, "multiprocess has overhead for smaller values" but at larger values it doenst even run
 
Do my eyes deceive me or does that code recursively spawn new processes for every list that's longer than 2?
Even worse, for every list that's longer than 1
 
yeah it should
I was looking for this en.wikipedia.org/wiki/…
 
> This algorithm is the trivial modification of the sequential version and does not parallelize well.
Big surprise!
 
I did read that, I thought for larger lists I could see a speed up even though the processes would be more
 
11:59 AM
Using a larger list only makes things worse. That algorithm turns everything into a short list before it starts doing any work
 
is there a way I cam limit the process spawned here? maybe using ProcessPoolExecutor
ok the wikipedia article tells it achieves linear time instead of log linear, it must be faster right? its just that the implementation I linked is slower?
 
your desire to limit processes and the implementation of the algorithm to literally spawn a process on each split are at odds with each other
 
that makes sense :/, guess I will see some other CPU intensive math task, I know there are transforms but I just thought converting a merge sort I already know would be easier
 
what about just the multiprocessing documentation example?
docs.python.org/3/library/… perhaps boring, but it will show a clear time difference.
 
that is actually not boring, thanks, it is still math :p
 
12:06 PM
If you want to multiprocess a sorting algorithm, it's probably easiest to just split the list into fixed-size chunks (maybe 10k elements each?) and spawn a process for each chunk
 
user13727121
here's the code to my program: dpaste.com/4MW6KDKKF
 
and finally do a n way merge for all the sorted chunks?
 
^ the algorithm fundamentally has to be creating processes sensibly. ofcourse, when you implement it this way, you'll have to probably do 1 more extra step to reconcile all the sorts till that point
exactly.
 
thanks guys, I will see if I can implement this
I will try searching elsewhere as to why the linear version parallel sort runs slower than than the log linear single process sort, maybe find a better implementation if there is one
 
user13727121
forgot to comment that the commented codes at the bottom are supposed to work the same as retrying it. There's no point for me to uncomment it if retrying doesn't work
 
12:11 PM
hm, wait. why is a parallel sort linear? (just curious, i dont know one way or another)
 
I mean the linear in O(n), and parallel in multiprocessing, the wiki article I linked will explain it 10x better than I ever can :D
 
@CoreVisional I'm confused. You said you want to restart when the user has used up all their guesses, but you already implemented that. That's what the if guess_count >= guess_limit: block does. The commented-out code does something else
 
user13727121
Sorry, forgot to include exit() on line 17, will result in an error instead of exiting..
 
user13727121
@Aran-Fey Yes, but if they answer "yes", the program still asks the same thing instead of going back to the beginning.
 
Ah right, because you never reset guess_count to 0
 
12:19 PM
that ^
and calling str on input() is superfluous
 
This is why you split your code into functions. Write a function that lets the player guess 3 times. Then if the player wants to play again, you simply call the function again.
Your code is a big block of logic, and as a result of that, the control flow is a mess. Split your code into smaller pieces, i.e. functions with a clear purpose
 
user13727121
I was going to use functions and call it from there, but I was just curious to see can while loop perform the same as calling it from a function. Did some searches and some of the answers work, implemented that into my program and now it's a mess lol
 
you'll still have both whiles, just in two different places
 
If you care to read it, I wrote a post about how to improve this kind of code. It starts with code like yours and turns it into this. The difference is like night and day
 
I wonder how many people read the start, stop shortly after and use patterns from the first block ;)
 
12:31 PM
Writing that post was pretty enlightening. I made up some purposely bad code to improve, but then revisited it not once, but twice, to make it even worse. Made me realize how far I've come, and how many common beginner mistakes I completely forgot about
 
user13727121
ohh, now it works, just as you said, I forgot to reset it to 0 @Aran-Fey
 
user13727121
@Aran-Fey I'll have a look at it now, there's always a room for improvement
 
@Aran-Fey I think I remember you discussing it here
 
user13727121
holy, those examples are almost the same as the way I code my programs, regardless of the programming languages I use... my gosh
 
12:50 PM
in case anyone is wondering I implemented this pastebin.com/K5M0jWkv seems faster
 
1:04 PM
Hello I'm trying to create a bot that auto click different components on a web page and sum them up up to 10. Anyone knows how to do that kind of stuff?
 
With selenium, probably
 
 
1 hour later…
2:27 PM
@python_user why does this spawn an executor, but not use it?
Keep in mind that Python's multiprocessing has to pickle/unpickle all data passed between processes. It is more efficient the heavier the computation and the smaller the data.
It is likely not ideal for a parallel sort, since the data is exchanged in full and merging requires the entire data in one process anyway.
 
2:42 PM
If you want to demonstrate the concept, creating the random numbers in multiple processes and then using a bucketsort where each bucket is represented by one process might work well.
 
If anyone wants to dabble with some simple CSV files, there are a bunch at github.com/fivethirtyeight/data I've been poking at them with littletable and some are pretty interesting (like this one: github.com/fivethirtyeight/data/tree/master/candy-power-ranking)
 
@MisterMiyagi I'm waiting for someone to make a joke a la "I don't understand a word of that algorithm, because it's german"
I'd do it myself, if, y'know... I didn't speak german
 
oops
 
3:00 PM
@PaulMcG this is amazing :)
 
3:13 PM
Boy, german has a lot more words for "bucket" than I realized. "Amper"? "Küfe"?! "Bütte"??! Never heard any of those in my life
 
Imagine Salad Langague would allow for German dialects... D:
 
Lorbeer
 
Cbg mates, can you guys take a look at my profile here, is it possible to set the flair and the thing below it side to side? Like left and right?
 
Pretty sure it isn't
 
@MisterMiyagi wow :/ I did not even notice that, good thing I posted it here
It worked faster than the parallel merge sort that I saw on SO so I assumed it was working, so it was just a normal merge sort after all
 
3:39 PM
the German version has no pictures :D
 
As my math professor used to say: "Why do you need examples? Just insert numbers into the formula and there you have an example!"
 
I never thought of it that way, but I guess it is as simple as that
 
3:59 PM
Not saying I agree with the guy, mind. :P
 
4:23 PM
@Aran-Fey Okays
 
4:56 PM
there was a time when SO landing page was a search for the newest unanswered [python*] questions. Today, most unanswered questions seem to be just poorly written, un-understandable questions
 
5:12 PM
The price of popularity, I'm afraid ...
 
for close votes, what would be the right reason for this one? https://stackoverflow.com/questions/66372967/what-does-this-means-intquestion-id
PS. this not a [tag:cv-pls], asking what the right reason should be coz it clearly does need to be closed, (or just deleted) but can't think of which reason is appropriate
i went with 'caused by typo' - the typo being the question :-/
 
"Needs details or clarity" seems appropriate.
There wasn't really a problem except the poster didn't read to the end of the documentation. "Premature questioning"?
 
yeah, lol that needs to be a reason. or maybe even an RTFM for questions easily answered by existing official documentation
@holdenweb i feel like that would give the OP the impression we want to know more about how they didn't read the docs. it's not missing context, and for someone who knows django (or can google), the info being asked is clear; as is the answer
perhaps - for users with 50k points or something, they should be able to use external links for the "duplicate of" reason. so it would basically be "RTFM"
(j/k i know that would break the existing dupe linkage code; or would it?)
 
5:39 PM
@aneroid The OP is clearly aware of their error. Close it and move on?
 
@holdenweb i've already cast my close vote and moved on
(i went with typo)
 
🤷‍♂️
 
It's not a great question, but a good answer creates good content for Stack Overflow. If the asker feels dumb for not fully reading the docs, that's their problem. If someone feels like it's worth their time to answer, it's a free writing prompt...
 
That's an unorthodox view of close mechanics. If it's close worthy it should be closed even if it has a brilliant answer.
 
Does somebody remember a really good article about time keeping? It was something like a brief history of timekeeping, it was from a physicist and looked at the last few thousands years and also at the modern era of computers and time keeping. It was really good but I can't find it
The website looked like simple html very minimalistic style
Similar to this, but with less pictures and longer and more related to computers: nrich.maths.org/6070
 
6:02 PM
About this:
in Python Ouroboros - The Rotating Knives, 16 hours ago, by Andras Deak
first_truthy = next((lst for lst in list_of_lists if any(lst)), None)
if first_truthy is None:
    print('Never broke')  # no longer makes sense
The if i1, if i2, if i3... where actually various different if statements.
So we can't just loop through them testing the same statement.
 
is there some simple way to convert numbers to 32/64 bit floats? I am trying to check for precision errors.
So far, I have the rather ugly def as_f32(num: float): return struct.unpack('f', struct.pack('f', num))[0]
 
@AndrasDeak "closeworthy" implies you can find the right close reason listed. If none of them seem to apply, well, although historically you don't need to apply logic to get a question closed, it's better if you do... To me, a great question demonstrates the asker did his homework to some extent. Here the asker demonstrated the opposite. But say they did quote the docs that answer the question, and then says he still doesn't understand, the question doesn't fundamentally change.
 
Is there a more pythonic way of doing this? I'm basically referring to the slant the will just keep growing. Thanks.
 
@AnnZen A loop over pairs of (lst1, bar), (lst2, foo), ... seems appropriate.
Usually, if the question is "how to do X n-times" then the answer is "use a loop"
 
6:12 PM
Hm, let's say a loop over pairs of (lst1, lambda item: item in bar), (lst2, lambda item: item + 4 in foo), ... instead.
 
@AnnZen please stop asking very vague questions if you're not willing to stick around to clarify and respond to replies
@AaronHall yes, closeworthy does imply that it can be closed appropriately :P
 
@AnnZen you've posted that here before, I think. If you want a better response, be clearer about what you're trying to do with the code. We can't tell you how to make it better because we don't see it doing much of anything.
The control flow cannot be further simplified without discarding some of the utility of the control flow.
 
@AaronHall it's slightly different. But same vagueness.
(Just to preempt "I didn't post this before")
 
6:28 PM
@MisterMiyagi Thanks. But the order is important.
@AndrasDeak I am willing, and will.
respond to replies
 
I don't see anything wrong with MisterMiyagi's suggestion. What do you mean the order is important? Then loop over the pairs in the correct order. Where's the problem?
 
@Aran-Fey but how? The conditions are all different...
 
pairs = (
    (lst1, lambda e: e in bar),
    (lst2, lambda e: e + 4 in foo),
)

for lst, condition in pairs:
    for item in lst:
        if condition(item):
            return

print('Never broke')
 
@AnnZen Pardon? A loop is ordered.
 
says the async guy
 
6:44 PM
i think the formatted version makes it clearer: but if i may try to explain the solution/approach provided:
@AnnZen they are suggesting that you create tuple pairs of `(list, condition)` for each list and its specific condition (so 4 pairs). if the condition is a lambda, then it can be "called" like a function with each item of the list. that's the part: `if condition(item)` under the loops
 
@aneroid So for each condition, use a lambda?
 
yes
 
Interesting...
 
Guys, I am trying to compute the laplacian using np.fft can I share with you guys my code?
 
@Rafael_Cristo hello, please read our rules and see
 
6:48 PM
@MisterMiyagi but would it be ordered the same as in my example?
 
I did that.
 
@Rafael_Cristo then you know the answer :)
if it's not the same thing as stackoverflow.com/questions/66340452/… then you're good to go
 
I did a questions recently answered but I still have some doubts remaining...
 
@AnnZen yes, it would be ordered because the outermost loop is for lst, condition in pairs: so each pair is processed in order - and the condition being checked is the one for that list (until the loop for that list "finishes"), then it's the next (list, condition) pair
 
@AndrasDeak it is not the same
but relates to.
 
6:52 PM
So basically, the consensus is that using lambdas makes it more pythonic than the example I gave, right?
 
@AnnZen no, consensus is that one of the interpretations of your question looks better that way despite the lambdas
 
Using Python idioms that make the code clearer is more Pythonic. Do lambdas make the code clearer to you? Then use them. Asking us to make things more Pythonic is not particularly interesting because we don't know why you don't think it's Pythonic to begin with.
 
@AndrasDeak What do you mean by "looks better"?
 
I mean it looks less worse.
 
@AnnZen it's one way to not have the nesting go on infinitely deeply slanted right. no matter how many lists and conditions you have*, it will only be 2 loops and an if condition
* = if the condition used for each list is only checking one item of that list at a time, and not previous-list-last-item & current-list-current-item checks together
 
6:58 PM
@aneroid Thanks! I'm assuming that using lambdas is the only solution.
Please notify me if there are more. Thanks everybody!
 
@AnnZen there are differences between them still because your original version can access i1, i2, etc. in the deeper nested blocks but the version suggested can't. so unless you can share the full code or how its used, that's the best solution for now. and if you don't need to access "old list items" in the deeper blocks, the version suggested should work fine
 
@Rafael_Cristo make sure to follow our room rules: sopython.com/chatroom
> If your code is longer than about 12 lines, use an external paste tool such as dpaste.com.
 
@davidism OK. So in this case How can I see my question will be answered. I am asking because I don't have access to this room.
 
try reading what I wrote again, I didn't say "post in the room you don't have access to"
 
It won't be answered in that room, @Rafael_Cristo. That's where we move questions that don't meet our room rules (that's in the room description). Please read the room rules and post longer snippets of code off-site (e.g. dpaste or gist and link it here)
 
7:10 PM
...or post it as a question ? (am I missing something wrt why it shouldn't be a mainsite question?)
@Aran-Fey and that needed a labeled break ala rejected pep 3136 python.org/dev/peps/pep-3136 (the return means it would have to be in a function called separetely; which is fine but labeled break woulda been nicer)
 
@aneroid ew no
The gods didn't give us loops for us to go back to goto
 
@AndrasDeak or a series of 'break-else-continue-break' like in this answer: stackoverflow.com/a/3150107/1431750
not goto-labels , more like break N where N is the number of levels to break out of, default being 0
 
return is fine, honestly
 
i'd just go with stupid flags break_outer = True or break_three = True. inelegant but understood by anyone who reads it
@aneroid which is so counterintuitive that I had to read it thrice to confirm that it does infact break inner/outer separately (wrt the answer I linked)
 
7:30 PM
Okay, I have this scenario:
# More code
for i1 in lst1:
    if i1.upper() in bar:
        skip_to_print()
    # More code
for i2 in lst2:
    if i2 // 2 in foo:
        skip_to_print()
    # More code
for i3 in lst3:
    if i3:
        skip_to_print()
    # More code
for i4 in lst4:
    if i4 not in lst1:
        skip_to_print()
    # More code
print("End")
# More code
To make it actually work, I'll need to do:
# More code
for i1 in lst1:
    if i1.upper() in bar:
        break
    # More code
else:
    for i2 in lst2:
        if i2 // 2 in foo:
            break
        # More code
    else:
        for i3 in lst3:
            if i3:
                break
            # More code
        else:
            for i4 in lst4:
                if i4 not in lst1:
                    break
                # More code
print("End")
# More code
Do you think the structure (a.k.a. the slide) needs improvement, or is it already optimal?
 
Can you extract each for loop into a separate function?
 
Not really, there are shared variables in almost each loop.
 
Okay, then I'd go about it like this:
1) Try to refactor that ungodly mess
2) Try again
3) Give it another shot
4) One more attempt
5) Still here? Go with something like this, I guess:
for i1 in lst1:
    if i1 in bar:
        skip_to_print = True
        break

if not skip_to_print:
    for i2 in lst2:
        if i2 + 4 in foo:
            skip_to_print = True
            break
 
@Aran-Fey I thought of this (and even used it), but I want to confirm, is it really an improvement?
 
Pretty much anything that doesn't make your indentation skyrocket is an improvement
 
7:43 PM
I mean, that would add defining a variable each time.
@Aran-Fey Really?
Good to know :)
 
it's just one variable skip_to_print to add in each block. like the break_flags flags i mentioned needing, in place of labeled breaks - these flags, while inelegant, can be understood by anyone who reads it
 
Ah.
@aneroid And the additional if statement to each block.
 
true. but slightly longer code is better than deeply nested code; imho. and you don't need to worry about the 80-char or 120-char width of your code
 
Good point.
So the consensus is that deep nesting needs to be fixed, even if that means sacrificing efficiency, right?
 
Readability beats efficiency by a factor of float('inf')
(Unless it doesn't. But usually it does)
 
7:52 PM
i was going to provide a much worse but very functional solution... still gonna post; for the sheer horror to trying to write overly purist code
 
@Aran-Fey :O
Rhubarb
Been ages since my last salad phrase :)
 
ok, i apologise in advance...
wait, l'll put that on pastebin
it's the same idea as @Aran-Fey's in this post: https://chat.stackoverflow.com/transcript/message/51670989#51670989
I've turned the pairs into triplets of `(list, more_code_function, condition)` and added local functions for `more_code_functions` which have a list of nonlocal variables which gives them access to the outer scope vars which would have been present in the deep-nested version
if the variables are being used in read-only context, then like global var_name, it can be skipped; since the inner function would have access to the outer scope
 
8:09 PM
That's not as bad as I expected, but... yeah, still pretty bad
 
entirely functional, no flag values. i did apologise first :-)
@AnnZen just to show the option, see - pastebin.com/Gc1azMa8; but in your code, use the version Aran-Fey provided
in theory, triplets could be passed in as a parameter; then do some inspection/monkey patching magic to attach each lst_func to looper's local scope - and then you've got a reusable recipe. to make it worse - add a pre_check_func() for each lst. heck, maybe even a pre_return_func()/post_check_True() function for a round quintuplets
 
FWIW, it might be worth questioning why this problem needs solving in the first place.
Doing four+ completely different actions on four+ completely different things doesn't immediately seem like one function.
 
8:24 PM
I think you mistook his meaning
 
oh, then yes, i did. sprouts
 
@aneroid I'm asking "why this" – hopefully the answer is not just "because this" :P
 
Also worth asking: "why us". Not just now, but in general.
 
@MisterMiyagi I shudder to think that my answer was going to be: "to avoid slantiness"
but if each of those "more code" parts actually had many shared variables, then no way to avoid either the problem or the least-worse solution
otoh #XYproblem
 
9:00 PM
@MisterMiyagi This:
1 hour ago, by Ann Zen
Do you think the structure (a.k.a. the slide) needs improvement, or is it already optimal?
So my question was initially if the slide needs to be solved or not.
 
I don't think that's what MisterMiyagi meant. Why does your problem necessitate that flow in the first place?
That's what Aran-Fey suggested in their checklist at point number 1 - this could do with a refactor. Is the question really going to be answered by improving the approach you've chosen or rethinking the approach?
 
I'm pretty sure it's the former.
I've put a lot of thought into the approach.
 
 
1 hour later…
10:30 PM
@aneroid Just close-voted it, with "Other - covered in documentation"
 
@PaulMcG that's not a valid close reason
 
Sorry, I guess I misread the consensus from earlier. Shall I reopen?
 
I didn't even open the question, so I don't know :P
but stricty speaking RTFM is a downvote reason, not a close reason
of course there has to be a line somewhere between something non-trivial yet documented and "how do I add an item to a list?"
 

« first day (3785 days earlier)      last day (1146 days later) »