« first day (3095 days earlier)      last day (2078 days later) » 

00:55
@AaronHall I've started following your suggestion and quoting the question at the top of answers. Let's see how much of a difference it makes.
@coldspeed Good - you recall my reasoning?
@AaronHall it doesn't make your answer worse but will most likely make it better... is what I remember :P
What I think you meant by this was that it helps you structure your answer better, and also gets others' attention.
@coldspeed other answers tend to go off on tangents (due to rambling or going off of other answers) such that readers reading your answer don't recall the actual question being asked. Restating the question reminds them of the actual reason people are writing answers, making your answer look good. It also helps me focus my material to directly respond to what's being asked.
I have also started restating questions in real life to be sure I understand the question. Some people don't like it, but I feel it helps me focus.
 
1 hour later…
02:29
cbg
Is there a one-liner I can use to import only os.path.isfile?
03:04
>>> from os.path import isfile
But what about using pathlib.Path?
Much cleaner interface than the mush of os.path methods, plus '/' operator
 
2 hours later…
04:47
cbg
 
1 hour later…
06:13
@PaulMcG When using pathlib.Path, I get AttributeError: 'str' object has no attribute 'stat'. What is the right way to do it?
@PaulMcG Don't worry, I just figured it out:
from pathlib import Path
Path("file.txt").is_file()
06:46
cabbage, I need a couple asparagusses
So, Python's doctest is returning "TypeError: 'bool' object is not callable" when testing this function inside a class:
    def autosave(self, option=None):
        """
        Configure autosaving.

        :type option: boolean
        :param option: The state to set autosave to. If not provided, it will return the current value.

        :rtype: boolean
        :return: The new autosave state or the current one.

        >>> data = ReadSettings("settings-test.json")
        >>> data.autosave()
        True
        >>> data.autosave(False)
        False
        >>> data.autosave()
        False
        """
        if option is None:
07:11
@Programmer If you're talking about /* comments */, AFAIK the first language to use that style was C. Wikipedia lists several other languages that support that comment syntax en.wikipedia.org/wiki/…
07:21
morning
@RichieBendall When self.autosave = option is executed, you replace the self.autosave method with the option object, which is a boolean.
Methods are simply callable attributes, and they live in the same namespace as the other attributes of an object, so you have to take care that your method names don't clash with the names of other attributes of the class.
@motaa Greetings.
07:43
@coldspeed I just fixed a minor typo on stackoverflow.com/a/55554709/4014959 but that first table looks pretty bad. At least, it does on my phone.
08:15
@PM2Ring Ah, thank you... and as for the table, I wanted to display an ASCII table in code because it looks more aesthetically appealing... :P But maybe I could convert it to am image. I actually did that for a table in this answer
@Aran-Fey done
@PM2Ring Thanks!
@coldspeed Ok. Maybe it's a font issue, but in this browser the and chars aren't aligned correctly.
@RichieBendall No worries. Also, once you fix the attribute name issue, you can simplify the code a little by inverting the test. If you set the (renamed) autosave attribute if option is not None you only need a single return statement.
08:30
Oh ok
hi
can someone help with this - its killing me
Well, maybe I could take a screenshot of the ASCII table and get the best of both worlds
@coldspeed It's a shame that we can't use MathJax on all Stack Exchange sites, but I guess it's not often useful on SO, and it can slow down page loading.
@walksignison ask your question before it kills you? (assuming you've read the room rules for waiting 2 full days before posting a recent question)
He's already dead I think
08:35
lol
oh, nvm
forgot the asterisks...
(sorry for multiple pings)
@walksignison Sorry, that question's an hour old, and it's the weekend, so things are a bit slow.
You can ask about it here in a couple of days, as stated in our room rules.
ok got it
I don't know asyncio, but I'm pretty sure 5 separate code blocks doesn't count as a MCVE
08:38
@walksignison Thanks for your understanding.
thank you and sorry about posting too soon
@walksignison No worries. Your question looks ok, but it will be easier for people to help you if you give them a MCVE they can run.
09:13
ok done
10:11
local name rebinding dupe see also comments stackoverflow.com/questions/55545804/…, one suboptimal target: stackoverflow.com/questions/15035923/…
Any better targets are appreciated, also for the canon
@AndrasDeak I'm happy to hammer it, but since I don't know Pandas, I can't suggest better targets. Should I add both the targets you suggest in the comments?
Well it's not really pandas. My original suggestion is probably moot because they have df = df.assign(...) in the function, the problem is that they expect the input parameter to change in the global scope
My original dupe suggestion says to rebind the return value of df.append
So it's really "why does foo = bar inside def baz(foo) not change the original value?"
@AndrasDeak Oh, ok.
You could keep the original target for completeness, but that's not the crux of it
If it were pandas I wouldn't worry about the canon :)
Hammered, and the 1st target got added automatically.
10:21
OK, thanks :)
oh hey that dupe target belongs to me (well, one of them, at least)
Hardly surprising
Hardly surprising that my answers can serve as useful dupe targets? I'll take that as a complement ;)
yeah OK
11:01
cbg
11:12
cbg
Hi,
I have a multindex DF:

	foo1			foo2
	col1	col2	col3	col1	col2	col3
0
1
2
3
4
How can I choose every col1?
@JasminParent looks like SO already has it answered, here and here
personally i've never used multiindex df, looks like a horrible thing to do. May also want to look at your use case and see if you can't represent your information without a multiindex perhaps?
thank you
I think I would save great amounts of time by putting everything in the same df and avoid loops if I can figure out indexing
i see, thats fair
11:31
@ParitoshSingh seems intuitive enough to me. Think multiple currencies each with buy/sell/mean values, for instance. You could be interested in "all the buys".
Got it
main.loc[:, (slice(None), 'col1')]
I suppose i was a bit harsh in my first assessment. I didn't think of the speed of indexing. Its essentially like representing a list (or better, dict) of dictionaries, each dict having the same keys, just horizontally instead of vertically.
and it looks like it does utilize the indexing properly, so i think its fair enough to say theres valid uses for it
At first I was using a dict of df and that required nested loops wich took forever, now its instant
thats nice. though im surprised dict used nested loops. Makes me think it wasn't used as well as it could have perhaps?
the inner level access shouldnt require any loops, since you have the "col1" name in hand already.
yea there was something about it Im not quite remembering
11:40
it says what you have, or main.xs('col1', level=1, axis=1)
11:51
Yup that works too
hey guys, if you are have a for loop the time complexity is O(n). Is there a way to get this faster?
Yes, O(n) with a smaller prefactor
or smaller n :P
what about O(n log n)?
1. what about it? 2. that's "slower" than O(n)
lol
oops
what about O(log n)
11:54
1. what about it? 2. that's "faster" than O(n)
can you get a for loop to O(log n)
if so, how? use a hash table?
you cannot talk about orders in isolation with the work being done
Fortunately your question is very vague so I can give a very vague answer. A loop over n items will typically be O(n) because if your loop has 2x more iterations then you do 2x the work
Your question doesn't make a whole lot of sense. It's kind of like asking "If have this employee who takes 5 hours to do his job. Can I make him do his job in 3 hours?". The answer is, obviously, "I don't know". We don't know what the employee's job is, we don't know how much time the employee wastes on coffee breaks, and we don't know if it's possible to do the job in 3 hours.
if, for example, the work is "do some calculation on every value in a loop", then naturally, you just have to use all values
So, orders are inherently tied to the work that is to be done
11:57
I had a programming question
which I solved using a for loop
and then the question was how could you make this faster? and i thought there was a way to compress for loop in time using some data structure/algo
for n in range(1, N+1):
    if math.log2(n) % 1:
        continue
    # work here
O(log N) loop, roughly ^
oh ok, i thought there was some substitution for the for loop which was faster
maybe i remember wrong
maybe it was an O(n^2) algo reduced to O(n log n) using another data structure?
if my understanding of orders is correct, that roughly /practically needs to be emphasized more, i dont think "purity" wise thats O(log n). the conditional has to be checked N times, right?
@ParitoshSingh yup, but if there's anything nontrivial in the loop body then the O(N) overhead is negligible
12:02
hence "roughly"
"amortized O(log N)" might be true, not sure
@Permian the point is that 1. this isn't something we can answer without knowing the entire algorithm, and 2. it's not about the loop. What you might have in mind is something like replacing a list with a set or a dict, in which case membership testing goes from O(N) to amortized O(1). If you have this test inside a loop that might make the difference between O(N^2) and O(N).
similarly, sorting a list and doing binary search on it might give you O(N log N) when other approaches are O(N^2)
But as you see it's not about "how can I rewrite my loop". You have to step back and look at your problem from a distance. And if you ask for help, try making it informative.
^ and in many cases, the "loop" itself doesn't go away, but the logic changes so as to achieve a speedup. (very common in n to log n conversions)
rbrb
@AndrasDeak ok thanks
is there anywhere online where you can find a cookbook of say the most common 20 algo speed up techniques?
i still cant quite grasp this algo and data structure stuff
12:20
For my thing of earlier:

df.loc[:, (slice(None), 'col1')]

or

df.xs('col1', level=1, axis=1)

How can I select all col1,... coln but without say col2?
That's probably tricker. Try dropping only col2.
ok
How would you write that?
no idea, I don't use pandas
took me 3 minutes to google
and the result is not terribly surprising
that works

df.loc[:, (slice(None), 'col1')].drop(['foo2'], axis=1)
or something
@JasminParent that will drop a top-level column but you were asking about dropping an inner column
12:33
Yes my question was wrong
Should have been:

How can I select all col1 for all foo1,... foon but without foo2
Still wondering what could be the correct conditional way
Conditional how? You want "every column except one", that's exactly what df.drop does.
Now I drop 'foo2' but why cant I select all but foo2 in the first place, something to use instead of slice(None)
you can
In [70]: df
Out[70]:
        one                           two                         three
          a         b         c         a         b         c         a         b         c
0  0.023669 -0.856832 -0.779266  0.763048 -0.406337 -0.370318  0.983759  0.757866 -0.219006
1  0.800848 -0.211682 -1.027736  0.553380  0.429333 -0.835842  0.966920 -0.731482 -0.053430
2  1.620663 -0.204222 -0.162625  0.420700 -0.670913  0.150236  0.756593 -1.362302  0.322070
3 -0.036540 -0.668942  0.270120 -0.214179 -1.011296 -0.280570  0.386431 -0.830124  0.658574
12:46
Yup thanks
You used matlab or something similar before?
 
1 hour later…
13:56
crap, I've got a dead pixel :(
I have one too
I've head one for a very long time...this is new :( Oh well, 6-year-old laptop, could be in much worse shape.
I also have dust at the bottom of the screen (between the matrix and the protection layer) :D
14:31
Yo
15:23
@AndrasDeak s/head/had/ ugh
It's ok Andras, I can't spell either
 
1 hour later…
Wis
Wis
16:49
can somebody on Windows tell me what's the output of this 4 line script on Windows?
```
import sys
print(sys.executable)
print(sys.path)
print(sys.exec_prefix)
```
C:\Python37\python3.exe
['D:\\Users\\Aran-Fey\\Desktop\\temp {e}', 'D:\\Users\\Aran-Fey\\Desktop\\temp {e}\\python.exe\\Lib', 'D:\\Users\\Aran-Fey\\Desktop\\temp {e}\\python.exe\\DLLs', 'D:\\Users\\Aran-Fey\\Desktop\\folder\\coding\\python', 'C:\\Python37\\python37.zip', 'C:\\Python37\\DLLs', 'C:\\Python37\\lib', 'C:\\Python37', 'C:\\Users\\Aran-Fey\\AppData\\Roaming\\Python\\Python37\\site-packages', 'C:\\Python37\\lib\\site-packages']
C:\Python37
Wis
Wis
thanks!
Huh, those temp {e}\\python.exe\\Lib things don't make a whole lot of sense... pretty sure there's no python.exe there...
especially not a directory by that name...
I think python on Windows can import from exe files
16:53
huh
Or maybe that was zip files? I forget
zip files certainly
(maybe)
Hello!
Wis
Wis
so a cross-platform regex to check if the process is a python interpreter is something like sys.exec_prefix + os.sep + "|python(.+)?(.exe)?"
16:56
ha, I was hoping it would be something like this :P
Wis
Wis
I should just rent a digitalocean windows server for testing, they bill by the minute right?
I want to take input a line like 2 3 in Python. Using l=int(input()) and r=int(input()) in different lines not helps, can anyone tell me how I can take inputs?
l, r = map(int, input().split(' '))
take the input first. split the string. convert each item in split to int*
Thanks :)
17:00
brain doesnt want to work atm
Hi i am following a tutorial about saving some docs from a html page using the rllib.request.urlretrieve . Can understand the filename retrieve and change command though.
Searched online for some documentation -> "./"+actual_link[actual_link.find("/turnstile_")+1:] <- unfortunately -> no luck so far
Full line is this urllib.request.urlretrieve(download_link, "./"+actual_link[actual_link.find("/turnstile_")+1:]) . Any idea what is done here ? :/
without having seen much into what you've done, may i suggest using requests library instead if it can serve your purposes?
much more user friendly, its a higher level interface to requests. Great for simple tasks related to data from webpages, or sending requests
I do use the requests library in a part before that, in order to get actually the the html text
r = requests.get(overview_url)
soup = BeautifulSoup(r.text, 'html.parser')
a = soup.findAll("a")[36]
can the saving of the files also be accomplished with just the requests library?
i'd have imagined so, yes. If you can reach the data with a url, requests should be able to do the same. The main thing however, is whether those files are accessible on a url or not.
17:22
@JohnDoe before you try posting anything with non-trivial indentation please make sure to read our multiline code formatting guide
@AndrasDeak Sorry about that..Will indent in the future!
you didn't have to, I'm preventing a future unformatted block of code ;)
easier to give a heads-up early than to try getting a broken message fixed
Can I make a lame joke?
Who am I kidding, we like bad jokes
    pun
# "pun" indented
*crickets chirping*
:D:D:D
i had to spend a lot of effort to understand that one. D:
whatever brain-cells were still functioning are now spent.
17:34
Well..spent I would say ;)
It probably would've worked better with some context
oh nah, it was pretty good
@ParitoshSingh btw. : I found this one stackoverflow : stackoverflow.com/a/14114741/5393648
Basically : requests doesnt offer a simple way to download.
Or am I missing something?
ah, interesting.
i mean, its a really old message
well that is correct...2 years
17:36
but i dont know a lot about requests in and out. Just suggesting an exploration before commiting
I'll search a bit further ;)
perhaps this blog post? looks like it shouldnt be too bad
will check, thank you!
It also seems like the size of the file creates issues to consider too
this briefly mentions it.
theres a stream parameter in the library now, which probably didnt exist when that SO answer was written
that should allow arbitrarily big files to be downloaded too
I've been reading old scifi from the 40s & 50s by Fredric Brown. A few hours ago, I read a story that featured Hell crater on the Moon. It's named after the Hungarian astronomer and Jesuit priest, Max Hell. With a name like that, I bet he had a great sense of humour. :)
17:44
Hmm, apparently "hell" does actually mean "hell" in hungarian. (In german it means "bright".)
nope, hell is a non-existent word here
*shakes fist at that online translator whose name I already forgot*
So how do people get money nowadays?
I want money and not have to work, please suggest
roganjosh knows how. something about pyramids. :P
Are you luckier than 13,983,816 other random people? If so, play the lotto
18:02
Speaking of luck -- I would probably lose even if there were no other people
That SigBovik thing that Arne posted the other day (that has the article about paint spatters being decoded into Perl programs) has as an article about monetizing open source software. Eg, release a Freemium version of a compiler or interpreter where developers have the option of paying a small fee to get error messages that are actually readable by humans. ;)
"Born under a bad sign
Been down since I began to crawl
If it wasn't for bad luck, you know I wouldn't have no luck at all" - William Bell.
18:20
@ParitoshSingh Thanks, that actually worked! Will no try to transfer this method to my other case :)
cheers, glad to help :)
 
2 hours later…
20:00
also gonna need delvotes thanks to a 200k+ user...
left a comment
I don't think he cares
worth a shot
 
2 hours later…
22:19
Hello World
or just Hello hehe
amazing song it helps me concentrate my mind: youtube.com/watch?v=apHmsOed7m8
 
1 hour later…
23:29
@Aran-Fey closed, but delvoting not possible yet.

« first day (3095 days earlier)      last day (2078 days later) »