« first day (4108 days earlier)      last day (837 days later) » 

5:07 AM
@roganjosh python -m http.server and ngrok http 8000 is fairly simple too, especially if you need to navigate around to find a few files.
 
5:53 AM
could i ask quick python questions here? or is this more for socializing and just people who code in python sipping coffee talking about rookie mistakes they've made in the past?
 
6:06 AM
both. we've got some room rules, such as no crossposting fresh questions (<48hr) from main, but we allow python questions in general.
 
 
1 hour later…
7:28 AM
I'd choose SSH over FTP any day to transfer files
I remember having to set up an SFTP server, was quite the pain
 
 
2 hours later…
9:47 AM
@roganjosh Couldn't you just load them into Google Sheets?
 
10:08 AM
I bet it's proprietary data
 
10:35 AM
I do currently upload into out company google drive and then open it there, but it's a massive hassle as I pump out a lot of CSVs
 
 
2 hours later…
12:37 PM
I haven't used any of these myself yet, but katacoda has some interesting looking free courses with an engineering slant that might be a bit above the standard of usual free/low cost tutorials. There's some on git, python, tensorflow and k8s etc.
 
I want to access the last element in a list named let's say nums, so I did nums[-1] which should give me the last elment, however the accepted solution to the problem shows it as len(nums) - 1 and it gets approved whereas my way doesn't even get a answer, what am I doing wrong here? FYI Three sum problem.
 
nums[-1] is the usual way of getting the last element. AFAIK this is only possible in Python, so perhaps whoever wrote your quiz wasn't familiar with the technique.
 
@roganjosh cognitiveclass.ai does provide great courses too for free
@Kevin but the final solution that they show is using python, so I don't get what's the difference here
 
Maybe they originally had it in Java, and they thought "I may as well port the code over and offer a Python course too". One-to-one translation is fairly easy but the result is not idiomatic.
(I'm assuming this is some kind of coding challenge site or similar)
 
@Kevin That could be a reason too, sounds naive to me though
@Kevin yeah
 
12:45 PM
"The interwebs says X" is a good reason to consider Y.
 
@MisterMiyagi lol
 
But now the interwebs says '"The interwebs says X" is a good reason to consider Y'
 
JavaScript also supports negative indexing though not with the standard index syntax
 
So accordingly, I should consider the possibility that "The interwebs says X" is not a good reason to consider Y.
End result: I have to think for myself, an act which has a bad track record.
 
The interwebs say Kevin is right X times out of Y
 
12:50 PM
RecursionError
 
@roganjosh JS is crazy, I stay away from it looking at the '11' +/- '1' memes
 
@Kevin Consider Z?
 
If you divide your consideration time by 10 in each layer, then you'll drop below the floating point minimum before the stack overflows
 
It feels like long time no see coming back here and seeing you all folks again.
 
There's nothing crazy about JS. You just have to suspend most of your faculties and it works just fine
 
12:51 PM
Just make sure to have a guard condition like if consideration == 0: return
The majority of JS weirdness comes from its implicit type conversion rules. Python trains us well in the ways of implicit typing, so you should be able to instinctually dodge many JS gotchas
 
This might sound weird, but what exactly are "x gotchas" like JS gotchas or interview gotchas?
 
"gotchas" are basically "traps to watch out for" or "things that can trip you up".
so, x gotchas such as JS gotchas are "things in JS that will surprise you" or "things in JS to watch out for"
 
So I just shared a gotcha here : chat.stackoverflow.com/transcript/message/53829957#53829957 according to this definition
Learn by experiment
 
not quite
gotcha also implies it is something that will trip up "many" people.
so, "common pitfalls to avoid"
 
The mutable default argument in Python is a decent example
 
1:00 PM
aye.
 
Hmm strong argument there
 
the or-gotcha, as ive heard it referred to before, is another great one. (checking a value against two possibilities, a beginner may* write it as x == 5 or 7. This however wont work as expected)
 
I don't think someone would try that though as being too much english language to code translation in literal sense.
 
I see it about once a week on here
 
you'd be surprised :)
its one of "the" most common beginner mistakes i've seen
 
1:04 PM
loll
does writing && count? (been there done that)
 
for a beginner no. for someone coming from a different language, i've seen that too.
 
When I think of gotchas, stackoverflow.com/questions/16424091/… always comes to mind. One of the rare cases where an object ceases to exist even though the process is still using it.
 
Someone tried explaining though : stackoverflow.com/a/15112149/7792580
 
you can judge by the upvotes on the question specifically that it's not all that uncommon.
But yeah, Martijn always has fantastic answers.
 
That person has a mine of medals damn, that guy SO's
 
1:16 PM
He used to hang out in here every day. Good times
 
OP steadfastly refuses to supply a MCVE stackoverflow.com/questions/70710440/…
 
Hi
I have some questions but nobody is answering(dunno why) no downvotes, not closed just no response so can anyone answer that also can I share the question link here
Thanks in advance:)
 
1:33 PM
@DevilIshere assuming it's a Python question I guess it might be okay, though perhaps the SOCVR room might be a better place
very often the close reason is all the explanation there is, as it gets closed when three individual users voted to close and they are not around to explain why
I can see no closed questions on your profile page though
 
@DevilIshere One issue I notice with your newest question is that the code does something completely different than what you want. You have a piece of code with a while True: loop that endlessly checks if a key combination is pressed, and your problem is that the code endlessly prints that a key combination is pressed?
 
@tripleee the question isn't closed, just not getting attention
 
How about you just... y'know... don't do that?
 
oh sorry, misread the problem statement
 
I may be wrong, but the reverse order 'problem' might not be one as in you might press those keys in this particular order
@DevilIshere Should an alt+ctrl shortcut be treated differently than a ctrl+alt?
 
1:51 PM
@AlexandreMarcq but the keyboard module recognizes it as one
 
@AshwinPhadke specifically in Python: sopython.com/wiki/Common_Gotchas_In_Python
 
@Aran-Fey I don't think there is another way also there is a if statement and it only prints it 5 times or so
@tripleee it's not closed not getting attention
@Aran-Fey if while loop can be replaced it may work
 
the general guideline is attract attention by improving the question (and maybe eventually post a bounty, but you don't have enough rep for that, and the question probably isn't clear and well-specified enough to attract a third-party bounty)
 
2:13 PM
I don't think is_pressed is a good way of checking for a lot of different key combinations. I think it would be better to build something on top of the keyboard module's hook system (github.com/boppreh/…), which gives you better information about when a key is pressed or released. And it's just as fast at monitoring 256 keys as it is at monitoring 1 key.
 
Is it ever correct to annotate a parameter as bool? Technically anything with a truth value (so... literally anything) works
 
A while ago I was thinking about how some programs will hide secrets behind key sequences, such as the konami code. I'm curious if there are any notable examples of key sequences being used in a practical and well-documented way. Something like "press and release ctrl, then press and release S, then press and release A, to save the document under a new name"
Vim and emacs have all sorts of weird input paradigms, right? Do they have key sequences?
 
@Aran-Fey something tells me duck and regular typing don't mix
 
@Kevin I'm disappointed nothing happened when I pressed that on the wikipedia article page :P I was hoping for an easter egg js somewhere embedded.
 
2:30 PM
The classic "exit vim" sequence of <esc>:q isn't so much a single three key sequence, as it is three one-key commands that each perform a discrete action necessary to exit
 
@Aran-Fey Such a simple way to give the creators of typing a royal headache. I love it!
 
It's really not a difficult problem to solve now that we have typing.Protocol. Just make a class SupportsBool(Protocol): def __bool__(self): pass
 
Quick search leads me to something called protocols (python.org/dev/peps/pep-0544) maybe this solves the kind of problem you want to annotate.
Aran'd
okay, so i have re-read your question, and i've determined that yes, it's correct to annotate a param as bool
 
It's just... not obvious that using bool is often actually incorrect
 
Godel's Incompleteness Theorem tells us that any axiomatic system must be either inconsistent (i.e. at least one statement is both true and false) or incomplete (i.e. one statement is neither true nor false). Although a great deal of literally anything has a truth value, not all of literally everything does.
 
2:40 PM
And a bit annoying that typing doesn't have a SupportsBool built in
 
if you "want" users to send a bool, and they send something else in that works, then that's not a problem of the annotation. if you however want users to send anything that can behave "as a bool", then i suppose we're back to protocols.
 
Estimated number of oversimplifications and lies in my previous message: 4
Python is likely incomplete, because you cannot assign a name to, say, the beauty of a sunset
 
beauty_of_sunset = np.nan
 
beauty is not a number, but that doesn't mean not a number is beauty
 
By the way, is there a place that has a good explanation for the magic behind 0-argument super()? I have written a subclass of super, and I need the users to understand that the 0-argument form will only work if they do from my_lib import super
 
2:47 PM
@roganjosh If you set up the Python http server in the directory amongst the CSVs, littletable can import CSVs directly from an http URL. Could be an easy way to eyeball the contents before copying over the whole file.
 
@Aran-Fey the PEP should have one.
@Aran-Fey I often need actual bools because I invert them with xor.
@Aran-Fey I doubt that would work. Have you tried it against a numpy array?
 
@MisterMiyagi Sadly, the detail I care about is only unceremoniously mentioned in passing there :(
Would a numpy array be considered an instance of SupportsBool if it's defined as def __bool__(self) -> bool?
Huh. Apparently that makes mypy hang
 
3:11 PM
@Aran-Fey see what pypy does?
 
It's not about me, it's for the users reading my docs. I was hoping I could just link them to an existing explanation, but I ended up writing my own
 
Or replace super in builtins? :P
@Aran-Fey gotcha
@Aran-Fey might as well call it supest
 
3:29 PM
BeautifulSuper, take it or leave it
 
No one going for superduper?
 
3:57 PM
cbg all
 
4:30 PM
@Kevin If you ask me (and you didn't) there are way to many people teaching Python who don't appear to know Python.
 
The old "teacher is one chapter ahead of the students" maneuver. Some bright minds can pull it off. Some.
Common failure mode: teacher is zero to negative fifty chapters ahead of the students
 
@AshwinPhadke It's a corruption of the phrase "got you!" - it's what someone might say when they'd tricked you into making a particular mistake of their choice, and by extension what Python might say when it provides an unexpected (but nonetheless valid) result.
 
I remember helping {younger relative} with some math homework. Something I hadn't used much outside of school, perhaps logarithms. I was basically trying to teach myself from scratch by flipping through the textbook. Not so easy.
I can look at a divide and conquer algorithm and say "that's deffo O(log N)" but I can't reduce 2^(n / e^(log(n) + sqrt(n))) to its simplest form. (not a real problem, do not attempt to solve)
As I muddled through the text book, I dictated my thought process, like "ok, so log(A^B) = A + log(B)... Or, no, should that be times instead of plus???". {relative}'s expression was of the utmost confusion and despair.
 
4:47 PM
It's surprisingly easy to look at someone's math homework and think "uh oh, I can't remember any of this"
While simultaneously it's also easy to forget that there are plenty of things younger people have never even heard about. Just a few weeks ago I had a "Wait, you've never heard of complex numbers?!" moment
 
@Kevin neither :P
 
After a moderate amount of bumbling about, I understood the fundamentals well enough to answer most problems correctly, albeit without grace or speed. I checked {relative}'s work and tried to explain the logical errors in terms of the hodgepodge of definitions I knew. {relative} seemed happier at that point, compared to during the bumbling phase.
All of which is to say, that even a teacher 0 chapters ahead of the student, is preferable to one that's 1 chapter behind
@AndrasDeak I'm not even going to double check, I believe you.
 
It's B*log A, for the record
 
Looks good, I approve
My log literacy goes up considerably if I have Wikipedia open
 
people keep obsessing about logging and complexity so it's important to stay on top of the math
 
5:02 PM
If I can prove that f(N) = f(N/2)+C, then I can say "hmm, feels loggy" and make an educated guess at the final result. It works pretty well.
 
 
2 hours later…
6:52 PM
@Kevin that would be exactly loggy. ln(2 N) = ln N + ln 2.
I think the base of the specific logarithm is exp(ln 2 /C) which is the Cth root of 2 I think
 
7:16 PM
Oh good, I was trying to work it out on paper and came to the same* result, although mine took one million unnecessary lines
(*ballpark)
I'm a little unsatisfied because in the middle I say, "next, assume that f = log..." and then I look real hard for a contradiction, and when I can't find one, I say, "therefore, f = log"
 
@Aran-Fey I hope you immediately followed that up with "Boy, is this your lucky day!"
 
Proof by contradiction is fine and good, but I don't think proof by non-contradiction is quite so robust. For one thing, it doesn't tell you anything about the total number of valid solutions
"Given: x^2 = 1. Next, assume x = -1. This is consistent, so we're done". Congratulations, you found 50% of the answers
 
@holdenweb I don't think they considered themselves very lucky to hear about complex numbers :D
 
What a shame.
 
@Kevin to be fair I only proved that ln works, but it's yet to be proven that all functions that satisfy your requirement are logarithms.
If we understand the requirement as "for all N positive integers" then there are infinitely many solutions. If we understand the requirement as "for all N non-negative integers" there are no solutions for C != 0...
hmm, it might not be possible to have non-logarithmic solutions for a C for which there is a logarithmic one
 
7:34 PM
I suppose f(0) = f(0) + C does rather restrict the valid values of C
 
Or, yeah, there could be. We only know that starting from a given valid N0, the solutions all have the same value in points N0*2^k which still gives some wiggle room.
I also looked at the derivative of the original recurrence relation but didn't know what to do with it
 
The other day I tried to derive e from first principles, and I thought "ok, so it's a function that's its own derivative..." and I ended up with f(x) = 0
 
New IPython has predictive input from code history
Poll: what key combo do you think lets me accept the suggestion?
 
I think I eventually got a bit farther by requiring f(0) = 1, and doing something with Taylor expansion. I may have had some precision problems when I started dividing by big factorials
I'll guess "Enter key" for the poll
 
ctrl + enter
 
7:41 PM
Both good guesses!
but no
I guess when I said "poll" I really meant "riddle"
@Kevin for what it's worth e is usually introduced with a limit, although that isn't easy to compute on paper either
 
escape colon Q
 
right arrow?
 
Clearly speak aloud "Alexa, accept suggestion"
 
It's spoiler
took me long enough to figure out
Anyway, the limit is (1 + 1/n)^n as n tends to infinity. Just plug in n=100 and you get a value that's 0.5% away. But that would be a bit cumbersome to compute on paper.
 
7:57 PM
That's why in olden days everybody elected one guy to compute it, and they put the answer in a big book of good numbers
I suppose if you choose a power of 2 for n, then you can cut down on the required number of multiplications
 
Cabbage
You can write that e limit as an inequality. (1+1/n)^n < e < (1+1/n)^(n+1). So you can get a decent approximation using (1+1/n)^(n+1/2). That's easier to compute if we shift it to (1 + 1 / (m-1/2))^m, and make m a power of 2, so we can do the exponentiation by repeated squaring.
But for pen & paper calculation, using the Taylor series is probably better. Actually, using the series for e^-1 is a little easier. You end up with e^-1 ~= !n/n!, where !n is the subfactorial. So e ~= n!/!n
 
8:12 PM
How to select dataframe rows of a specific column whose values start with "k" or "h" except those belonging to a group in other column?
 
@Huzaifa the first part is df['colname'].str.startswith() and check the docs if you can pass a list or tuple of strings inside, or if you have to use a regex.
Then use a boolean mask to handle "belonging to a group in other column", whatever that means.
 
The classic way to compute large numbers of digits of e is to write it in factorial base notation: e = 2.11111... and convert it to decimal. I have some old Python 2 code (with comments) for it here: math.stackexchange.com/a/1295561/207316
 
if you're in python you can compute (n + 1)**n/n**n for large n, and wait patiently :P
 
@AndrasDeak This means I have 2 columns. One column has animal names, 2nd column has gene names in the dataframe. I want to select only those genes that start with name "k" and "h". This I can do using as you said, df['colname'].str.startswith(). But I don't want those genes who belong to lion. That's what "belonging to a group in other column" means
 
@Huzaifa so create a boolean mask that gives you which rows belong to lion
 
8:18 PM
Okay let me try
 
or which don't belong to lion, for ease of semantics
 
@AndrasDeak You get much faster convergence if you do that 1/2 shift, though. Here's a rough demo:
 
But then you no longer have integer division
Ah, you expanded by 2
Point taken
 
:)
 
Thanks. using this code, I did it.
df_d = df_d.loc[(df_d['gene_name'].str[0].isin(['k', 'h']) & (df_d['Species'] != 'Lion'))]
 
8:32 PM
Why not startswith?
Not sure which is faster, to be honest
But yes, that's the right idea
 
The factorial base algorithm is probably the least painful for hand calculation, since you don't need a huge long division. There is a division in the inner loop, but it's actually a modulus reduction, dividing by the array index, and if your block size is small then the quotient will also be small.
 
This also worked,

df_x = df_d.loc[(df_d['gene_name'].str.startswith(('k', 'h'))) & (df_d['Species'] != 'Lion')]
@AndrasDeak How to check what line of code is faster?
 
@Huzaifa Learn to use the timeit module. docs.python.org/3/library/timeit.html There are lots of examples on SO
 
@PM2Ring Sure, Thanks. I will check it out
 
8:50 PM
Ipython/jupyter have a %timeit magic command
 
Many timeit demos show how to time functions. Here's one I did which times expressions. stackoverflow.com/a/50212230/4014959
 
9:15 PM
I'm googling for sphinx alternatives and one of the results was this thing. Apparently it just extracts comments/docstrings from your code and puts them on the left side of the screen, while the code stays on the right side of the screen. The python documentation ecosystem is truly in a sad state.
 
9:32 PM
still more readable than doxygen :P
What do you have against sphinx, beside its lack of documentation and questionable usage decisions?
 
Rst and its 3-space indents. Lack of customization options. Inconsistent behavior and output/formatting. Spaghetti code (this is relevant because of the lack of customization options).
Plus you need like half a dozen extensions, which introduce their own inconsistencies
 
I don't think I've seen 3-space indents
the rest sound plausible
 
Often you can get away with 4-space indents. Sometimes you need 2-space indents. Rarely 3-space indents, but they do exist
 
hmm, sounds icky
 
Now you're getting it!
 
9:43 PM
Fortunately my code is self-documenting
 
I have legitimately made up my mind to never publish all this code I'm writing to bend sphinx into shape, because I don't want to contribute to its survival. I want it to crash and burn and be replaced by something sane
 
the problem with "be replaced by something sane" is that usually you are the one who ends up having to do that too
wow, language is hard for me today
 
If that was even remotely realistic, it would already be on my to-do list :(
 
not with that attitude!
 
10:05 PM
Ok, I'll add it after "make an easy-to-use, low-boilerplate database"
 
Sqlite3?
 
Too rectangular for my taste
 
Redis?
 
Hmm, gonna need to research that one
 
Redis is better for a cache, really, so maybe Mongodb which will have some stuff in memory but will also help with persistence
 
10:14 PM
I believe both Mongo and Redis require a server? I'm looking for something embedded
 
Sqlite3? :P
 
redis is an in-memory database I think so I'd imagine it can run locally just fine
 
On a serious note, why are you dismissing sqlite3?
 
unless I misunderstand your "embedded" requirement
 
You could launch the other servers on localhost so I guess they could be embedded (I've never tried to bundle it all up)
 
10:18 PM
@roganjosh Tables are a PITA. I don't want to create a table schema for every class in my code. Especially not during the development phase, where I constantly refactor and add and remove attributes. I want a database that has exactly 2 functions: put and query.
 
Hi all,
What is the equivalent of making a soap call to a CGI script and call a function from that cgi script?
Equivalent in python
 
@Aran-Fey i.e. a dict
 
@Aran-Fey what are you winning from these iterations? I'm gonna be the annoying person to argue that thinking about the db structure actually helps you formalise the end result
If you have to keep faffing with the db structure, to the point you can't track it with Alembic, that's the same kind of indicator we keep lecturing people about re: MCVE?
 
@AndrasDeak Sort of, yes. A dict that I can efficiently load from disk, make a small change, save to disk. A dict that I can quickly find specific data in even if it has a million values in it. A dict that I can save to disk even if it contains reference cycles. That kinda stuff.
 
pickle seems to handle dicts with cyclic references ;)
 
10:25 PM
In which case, I think it would be redis. Just set a server on localhost?
 
I heard you could use a global to make sure only one instance is set up :P
 
Global :'(
 
@roganjosh Does it? Pretty sure the database layout will mimic my code layout. Each class gets a corresponding table. I don't think I have to invest any thought into my database, but pretty much all existing databases force me to (or rather, force me to write boilerplate)
 
I'd note that you two might have different views about the use case for that database
 
I'm not super happy about the "launch the db as a subprocess and connect to it" solution, but I'll consider it if Redis seems reasonable
@AndrasDeak Yeah. Most people look at me like I have 3 heads when I say I want a simpler database. But the fact of the matter is that there's a lot of empty space between sqlite3 on one end, and ginormous server-hosted multi-user behemoths on the other end
 
10:32 PM
I'm a bit surprised after some duckduckgoing that nobody seems to ask if they can run redis within the same program. So the answer must be obviously no.
@Aran-Fey are you sure it's not simpler to just cook up something for yourself based on a dict? As I understand the only thing you're missing is querying, but I can't tell how that looks like for your situation.
 
I think it could be done but it's overly complex. It would perhaps be easier to understand where sqlite3 actually falls down for the application. I'm pretty sure you can dump JSON into a column in the short term and figure it out later
 
Man, I remember we already had a related discussion, like... years ago. Crazy that I still haven't made any progress on this
 
reinventing the wheel is avoidable, but it sounds like you have to choose between a unicycle and a concorde when you just need a car to do your shopping
 
Or just use JSON until you figure out the program
 
According to the wiktionary avoidable only means what I want it to mean as a noun. No idea what adjective I'm looking for then.
 
10:36 PM
I'll probably try JSON, yeah. I already tried JSON and it turned out to be too slow, but that was back when I was still a noob
 
Opposite of preferable?
@Aran-Fey how's JSON with cyclic references?
 
Not so great. But if it means I don't have to write my own db, I'll figure out a way to deal with them (:
 
@Aran-Fey it still will be slow, ultimately sqlite3 is very fast and way better than posts will have you believe (even with concurrency)
 
What does JSON have that dict+pickle don't?
Assuming the DB thing is just for debugging locally and not to be unleashed on actual users
 
Even if you hit concurrent writes, you'll get 5 secs on the deadlock for writer access and that's relatively long
 
10:39 PM
Technically it's not a big deal, but pickle usually isn't what you want to use for long-term storage. Given the security problems and all. I'll consider using it, but I'm not a fan
 
I understand even less about your use case than I thought, which wasn't much to begin with
This is not to say that you should explain to me specifically, because I wouldn't be able to help even if I knew more.
 
I have to say, the redis documentation is doing absolutely nothing for me. There's instructions on how to install it and set it up. There's a link to the relevant python module. And there's 3 lines of sample code doing db.set(key, value) and db.get(key). And... that's it?
 

« first day (4108 days earlier)      last day (837 days later) »