« first day (4478 days earlier)      last day (471 days later) » 

4:43 AM
duplicate stackoverflow.com/questions/34129348 per my comment (wasn't tagged as Python before)
 
 
2 hours later…
6:19 AM
I did a lot of work tonight, documented here: meta.stackoverflow.com/a/422750/523612
 
 
2 hours later…
8:00 AM
what on earth is this old nonsense stackoverflow.com/questions/50100767
(not reproducible or needs debugging details I guess. the setup is a complete wtf)
 
8:27 AM
[tag:cv-pls] duplicate https://stackoverflow.com/questions/56361133
I am also trying to clean up a bunch of unrecognized dupes via https://stackoverflow.com/search?q=pip._internal
 
 
1 hour later…
@KarlKnechtel Do you know an alternative dupe target for "this runs only on Python2"? I've seen both kinds of issues (writing custom code Python 2 style, and trying to use Python 2 code) and the question seems to fall into the latter category.
 
Interesting post on mastodon, using "..." in place of True for an infinite while loop.
while ...:
    print("infinite looooop")
 
I'm guessing it's similar to when while 1: is used.
 
Since bool(...) is True, this is just like while True:
 
All it does is confuse people
 
9:47 AM
... is not used often, so it throws people off when they see it.
 
if I see it and notice it actually work, I would just either think of it being similar to while 1 or, being a weird version that work on non-true basis, but that one would be just a personal hypothesis
 
I added support for ... in pyparsing: Word(alphas)[...] is equivalent to ZeroOrMore(Word(alphas)), and Word(alphas) + ... + Word(nums) is equivalent to Word(alphas) + SkipTo(Word(nums)) + Word(nums) (I especially like the DRYness of the second one).
 
Typing also adopted ... heavily for omitting things that have a clear meaning but don't need repeating.
 
10:11 AM
Morning cbg all of those of you that are morning inclined
 
cbg
 
 
3 hours later…
12:43 PM
[offtop] Are git hooks saved in repository e.g. when pushed to github?
 
1:10 PM
nvm, they aren't
 
and for good reason. Imagine if I snuck a cheeky sudo rm-rf / into a post-receive hook?
 
Weeeell, yeah but at the same time seems like something that could be avoided with a bit of redesign
 
Or, leave it as is :)
 
And require everyone to manually install hooks themselves
 
Yes - everyone's hook requirements are going to be very different. Why make sweeping assumptions and make something a horrific security vulnerability when it's easy enough to remedy in your org?
 
1:47 PM
"Context managers are sort of a wrapper around code." Is that an accurate description?
 
not really
imho
I guess it's not a false statement, but also don't feel like it explains what they actually are for
 
2:02 PM
@Riya that would describe decorators too, which serve a completely different purpose
it might be more valuable to describe both of them rather in terms of what you're trying to achieve when using them
context managers: create a resource for a block of code, usually by doing some creation on entry, and some destruction/freeing on exit of said block
decorators: wrap a function or class, and run arbitrary code instead. usually, the original class or function will still expected to be executed, but not necessarily
those were my personal ad-hoc descriptions btw, nothing even close to authorative
 
 
1 hour later…
3:35 PM
Hello. Is it a bad idea to package JavaScript files using setuptools and installing them with pip instead of using npm?
 
How do you install JS files with pip?
 
I package them and install them like any other packages.
 
That's not an entirely helpful answer but ok
 
Well, I would say it's a bad idea because server-side JS is still abhorrent to me. But I feel that opinion is not useful to you right now :)
 
Just talking about client side js files which will be used by Flask blueprints.
 
3:44 PM
That's not "installed". They are resources for your app, so of course you distribute them with your package
 
I know. But some of those js files are optional and I want to distribute them separately.
And I know I can install them just by putting them inside a folder but I am concerned about versioning and dependencies.
 
@Dante Worried about what specifically? Surely your template code is heavily tied to the versions of javascript anyway. So you absolutely do want them in your repo. If you want something optional, my gut feeling would be to play around with git submodules.
 
Well, the only thing I can say is that I package an entire Java server with my library as an executable JAR and the reason I ended up doing that was because versioning became absolute hell without it. I know that every version of the python library I release comes complete with a perfectly compatible version of the Java server
 
(Bah, I didn't mean to delete that message)
 
Although I did configure the Java server to throw a 418 in the hard-to-catch instances that it could tell there was a mismatch, prior to bundling it. And I felt mildly better about the whole situation from that
In any case, that's way more extreme than a flask app, where JS is pretty mundane
 
3:54 PM
@OldTinfoil Its a plugin based app. So plugins (js files) can have their own version and dependencies.
 
I feel like you're just drip-feeding us information and you already know what you want to do. It's quite frustrating, actually
 
Sorry I didn't mean to. I just wanted to make the question simple.
 
Sounds like you're on the edge of writing your own package management system right now.
 
LOL. I wanted to do that at first but it is not easy.
 
You could try to do something loop with wheels, so that when you run pip install my-js-plugin-x, it knows what other packages it requires at what versions. But you wouldn't catch me doing that
So past some high level hand-waving, I'm useless to you and should wait for someone more knowledgeable about such things
 
4:03 PM
Thanks anyway :-)
 
But yeah, sounds like you're cruising for some sanity damage.
 
Already happened :D
 
4:21 PM
What's pylint's problem with unnecessary else statements after a return? I happen to like unnecessary else statements after a return
 
I use pylance
 
late morning cabbages, folks
 
4:46 PM
cbg!
 
cbg
I have 2 files a imports b, now how would I go about "returning" to a? I can't just call return on the top level
 
I don't think I understand how you're using return in this case. All top-level names (function names, variables, etc) within b will be made available from within a as a result of the import. What is it that you would like to "return" to a from b?
 
5:27 PM
@Hakaishin that's not how import or return works. Maybe we can help more if you show some example code and describe in more detail about what you are trying to do.
 
@inspectorG4dget I see, so there is no way to prevent that?
I mean in the meantime I found a workaround or even better to say a solution. My initial idea which is asked here would have been a work around
and as it seem impossible
 
5:45 PM
The best way to "return" something from b into a is to call a b function from with a (after the import) and capture that function's return value
 
@PaulMcG I suppose it's ok, but liable to make some newbies think it's some magic power of Ellipsis. But I guess it's not as bad as the "long arrow" operator in C-like languages. stackoverflow.com/q/1642028/4014959
 
6:17 PM
@inspectorG4dget It's about djangos defaults.py file, so it's a bit of a special situation. But I got it solved :) Basically the problem was that I need the db for the config to populate djangos defaults. Then again on a fresh install I need django to run the migrations, but to run django I already need the db conf. But I just added a parameter when loading the conf to skip the db and only take the defaults from a file. This can be used once to run django to run the migrations and then the config
can be read from the db like normal
Alright guys, I'm off to Bali for 5 weeks remote working <3. If anybody is also there hit me up :P
 
 
1 hour later…
7:32 PM
@PM2Ring started doing C more seriously recently, but didn't know there was a long arrow operator (already knew about the arrow (the shorter one) operator though...
 
I got a partial answer (pseudocode), but since I barely know any Python, if someone wants to give a more complete answer I will click accept on that!
3
Q: Print chemical formula from list of atoms in Python?

Nike DattaniLets consider the following code which uses the Mole object: import pyscf mol = pyscf.M( atom = ''' O H 1 0.9576257 H 1 0.9576257 2 104.51 ''' ) Is there an easy way to print the chemical formula: H2O? In the above-linked documentation page, I couldn't find a...

 
7:52 PM
I know how to turn the string "HHO" into "H2O", but I don't know anything about pyscf
 
maybe sharing your pseudocode could enable people to try and make something that would work?
 
There's no code, I just know how to do it.
 
@NordineLotfi was this comment directed at Kevin or me?
>>> mol.elements
['O', 'H', 'H']

>>> for atom in mol.elements:
... print(atom)
...
O
H
H
@Kevin are you able to reproduce the mol.elements array that I just typed out above? If so, then you don't need PySCF. The code/pseudocode given to me in the answer so far, actually gives me an error at elements{atom}. It says "invalid syntax".
 
Probably he meant to write elements[atom]. It would probably still give an error, though.
I'll write a little prototype that works on ['O', 'H', 'H'] .
 
@Nike my bad, should have pinged you. Yes this was directed at you :)
 
8:01 PM
Thanks so much Kevin!
 
"When the formula contains no carbon, all the elements, including hydrogen, are listed alphabetically"... Bit more complicated than I first thought
 
@NordineLotfi The pseudocode is in the answer to my post, but my initial comment here might not have made that as clear as necessary. Sorry about that! Do you see the pseudocode now?
 
yep, can see it now
 
Nordine: great!
Kevin: Getting the "pseudocode" to work even without the alphabetical sorting, would at least help me get in the right direction. I've been trying to work on it myself.
With square brackets, I do still get an error:
>>> elements['H'] += 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'H'
If I initialize elements['H'] = 0, then it works.
 
Can you lice with the Hill representation? I understand that answering this will punt you in the right direction, but will it be enough for your final requirements?
Lice? Live. Silly phone
 
8:07 PM
@roganjosh yea absolutely!
The person that wrote the answer, is the lead author (and original creator) of AVOGADRO and OpenBabel, so if those programs use the Hill representation, I think getting something that knows all the rules of the IUPAC conventions would be challenging! I don't see why it should be too challenging since students learn the IUPAC conventions in class, so we should be able to program a computer to know them, but I'm happy with the Hill representation.
In fact I'm okay with the atoms not being sorted at all for now. Alphabetical is fine for now.
 
The first part would probably be a counter
 
Prototype written, now I'm looking up cool molecules to test it on
What's a good molecule that doesn't have C in it... Hmm
 
Try artemisinin. That was my baby for several years
Oh but it has carbon in it. Hmmm
 
@roganjosh you had malaria for several years?
 
Thankfully no, but I was involved in purifying it. Your question has catapulted me back to my previous life before programming :)
Not purifying malaria. That would be supervillain material
 
8:15 PM
I had to do two separate for loops:
>>> for atom in mol.elements:
...    elements[atom] = 0
...
>>> elements
{'O': 0, 'H': 0}
>>> for atom in mol.elements:
...    elements[atom] += 1
...
>>> elements
{'O': 1, 'H': 2}
 
I've chosen Iron(III) sulfate, for secret reasons
 
The counter I suggested wouldn't need to be initialised with zero counts. But Kevin probably has something that works
 
I, too, elected to use counter
 
I would suggest not to approach this with a "I'll only learn what I need" kind of mindset. If you're going to be programming, you should properly sit down and work through a tutorial. That's far more productive than doing little experiments like elements(i) and elements{i}
 
@Aran-Fey thanks for the advice. May I ask, on what is it based?
 
8:27 PM
I posted an answer. The secret reason that I chose Iron(III) sulfate was to demonstrate that the algorithm won't always give the "most beautiful" representation. Wikipedia describes Iron(III) sulfate as "Fe₂(SO₄)₃". My approach makes no effort to divide out common factors or include parentheses.
 
@Nike Experience, sort of. It's common to see beginners who have absolutely no clue what they're doing - I've literally answered questions with "Write a loop then" before. I've also seen lots of data scientists who basically just cobble together code while hardly understanding what they're doing
 
I, too, would like everybody that's going to be programming to make a concerted effort to learn programming. But I like programming, so maybe I'm biased.
 
I know a lot of scientists usually prefer to do what needs to be done and not concentrate too much on the programming part, but, at some point, you'll notice you'll get things done much faster and more thoroughly the earlier you start knowing more about the tools you're working with.
 
Somewhere on the other side of the world, AntiKevin recommends learning the minimum amount to get your thing working. This ensures you can quickly return to fun things, such as rock climbing and writing poetry.
 
the docs on pyscf are also abysmal, so this doesn't really help either.
@Nike I did an example here. It output O1H2. I'm guessing this is the output you wanted or? Just wanted a confirmation in case this is what you want
 
8:38 PM
What usually happens is that you'll spend more time on it than you thought you would. You aren't going to spend 3 days writing python and then never program again in your life. And even if you are only going to spend 3 days on it... a structured approach to learning is still better than pulling out your hair for 3 days in a row
 
AntiKevin is very good at estimating exactly how much time he'll spend coding. He's somehow immune to Hofstadter's law.
 
@NordineLotfi This code is excellent, and even more compact than Kevin's. Why don't you write an answer? Perhaps you were waiting for confirmation from me?
Kevin's gives the result in a neater and more aesthetically pleasing format though. H2O looks better than O1H2.
 
yeah, I wanted to know if it was the output you wanted. I do prefer Kevin's answer, because it shows he has more knowledge than I have currently on atoms and formulas (note the description where I state I don't know what I'm doing :P)
I'll post it shortly
 
@NordineLotfi I like Kevin's format better, but I like the compactness of your code. I think you should write an answer and let the voters decide! Also, some parts of your code might be used by someone else who improves it.
 
My chemistry knowledge consists of very fuzzy recollections from high school, plus twenty minutes of Wikipedia from today
I maintain the illusion that I know what I'm doing by fighting the urge to write "... I think." at the end of every declarative sentence
 
8:46 PM
@Kevin I'm also very good at estimating that, as long as that time is 0!
 
8:57 PM
@0x263A what have you posted that your msg been deleted ?
 
9:10 PM
@Nike added an update to my answer: mattermodeling.stackexchange.com/a/10260/6574 I think it now give the correct output, at least for H2O. Don't know about other inputs.
 
user20812299
1
Q: Duplication of the numbers of a list, with append, at each click on the checkbox. How can i avoid duplication?

Takao貴男This function is invoked by a checkbox. In the function there is append, which takes values in a query sql and adds them into the dictionary. The problem is that when i uncheck and also when i check the checkbox again, the values are added back into the dictionary, because append inserts them aga...

 
user20812299
Can anyone help me with this question please?
 
9:27 PM
@NordineLotfi in my language, I got your solution with a more compact code:
 
@roganjosh ah, was getting a bit worried over here
 
@Nike Nice :D what's the name of that language? I don't think I recognize the syntax. Also, check the other "EDIT" part of my answer. I don't know if this can work on other inputs, but this works with your example input at least (the one in your question).
ah, I'm guessing this is matlab?
 
@NordineLotfi how did you guess that?!
 
the num2str and disp showed matlab as result when I looked around on SO and google.
 
@NordineLotfi nice!
Interesting that you'd check SO before Google?!
 
9:36 PM
I mean, while SO's search is pretty bad, using it can sometimes yield good results. Otherwise, using search engine like Google and searching on SO or others works better.
 
I'd have searched num2str on Google.
disp was not really needed. This is what it looks like without disp and with disp:
 
@Nike yeah, but wanted to make sure. There are more interesting code examples on SO than on google, where the syntax is easier to tell. I also thought that there might be false-positive since other languages might also contain something called num2str.
I also don't know matlab compared to shell/python, so that probably interfered with my thinking process too
 
@NordineLotfi has the compactness of my above code tempted you to examine MATLAB?
 
@Nike well, I did think of looking into it more. I never found a good use-case for that to happen
 
@NordineLotfi yea the compactness alone isn't enough to convince people to learn an entirely new language.
 
10:25 PM
2 messages moved to MetaPython
@NordineLotfi beside the good use case you'll also need a thick wallet. Or Octave.
people tend to go from MATLAB to Python these days, not the other way around
 
How long, Andras. Are you okay?
 
@AndrasDeak--СлаваУкраїні You're right. I did notice this was also the usual trend that people followed, and probably for good reasons too
 
You're welcome.
 
but if you do have MATLAB code, googling "matlab <function name>" usually gives you the official docs as first result which is great (the official docs, that is)
 
10:32 PM
I see, that does sound appealing :o
 
How's matlab as a language? Weird? Ok? Good for what it was designed to do?
 
the last one, very much
 
Haha
From the little I know I would say that too.
 
MATLAB stands for "matrix laboratory", and it's great for handling double-valued arrays
 
Double as in the data type?
 
10:34 PM
especially matrices; syntax gets clunky for multidimensionals, and it doesn't do 1d arrays
@Aran-Fey yup
 
Argh
 
I figured "double arrays" would be ambiguous but apparently the replacement term wasn't much better :P
 
No 1d arrays sounds like a weird design decision
 
One you go outside that niche things get icky. Strings, ew. Inhomogeneous containers (cells), meh. OOP, yikes (although I don't know much about this part and lost track of the others in 2012).
 
@AndrasDeak--СлаваУкраїні in terms of not doing 1d arrays, if you consider vectors 1d arrays, then it does them very well :)
 
10:36 PM
@Aran-Fey MATLAB started out as a thin wrapper for LAPACK and BLAS and LINPACK etc. fortran routines. The kind that makes users homicidal. Think zgemv.
 
And the syntax is pretty weird in my opinion. But it seems that many find it easy.
 
Syntax is basically fortran 90 plus some syntax sugar for matmul and transpose, which is fine. But a lot more rigid than that of Python.
@AndrasDeak--СлаваУкраїні point being that 1. matrices were the main use case, and 2. anything is a step up from there
 
Yeah, it's fair.
 
And yes, you have (1, n) and (n, 1) shaped arrays. But you can't have proper 1d arrays, and sometimes operations surprise you in whether they give you a column vector or a row vector.
 
@AndrasDeak--СлаваУкраїні despite strings being "ew", my MATLAB code to get the same result that Nordine got in Python above, was simpler. At least it didn't require the extra IF statement.
 
Seeing disp brought back memories of my old programmable calculator. Good times, although I have no idea how I had the patience to program pong on that thing
One more language I can add to my resume
 
@AndrasDeak--СлаваУкраїні why do you say the syntax is basically Fortran 90 rather than FORTRAN 77 or FORTRAN 66 or FORTRAN IV?
 
because as far as I know it's fortran 90 that introduced slice notation for arrays
 
Okay
 
In my opinion Python would be very close to perfection if it released the GIL (mainly due to the slow code execution problem I'm having, although the problem must be in the infrastructure or environment of the machine where I'm deploying the code), I've already read a little about Python reason for not having the release, but I wanted to see a TL;DR type response.
 
11:12 PM
@Marco See PEP-703 peps.python.org/pep-0703 potentially available in 3.12
 
Wowww
I don't believe this. :D
Thank you very much for posting this news.
 
11:28 PM
If the GIL is removed, I wonder what people's reactions will be. There's probably a significant number of people who underestimate the benefits of the GIL
 
Can you describe some important benefits of the GIL, please?
 
Well, it seems I missed a lot of "fun"
I already told you @Marco about the ways that code might escape the GIL. Did you bother to read up on that?
 
I remember, uh, but my code is not composed only of those parts that release the GIL.
 
I mean, do you need direct answers to every problem or can you think to yourself "huh, that's interesting. Maybe I'll read around it"?
 
Well, it depends on the kind of code that you write. But in essence, it has a similar benefit as asyncio - you can rely on the fact that certain operations, like appending a value to a list, can't be interrupted by other threads. Without the GIL, who knows what happens if another thread removes an element from the list while you're appending one? You might get a segfault or something
 
11:33 PM
Roganjosh, as I said before your second question, my code is not just made up of the parts that manage to release the GIL. :(
 
Granted, that's unlikely to happen. But that only makes it harder to debug. If your program randomly crashes, good luck figuring out why
 
@Marco That wasn't my point. I've told you about BLAS/etc etc, I've mentioned multiple ways code can be compiled... are you researching any of this stuff yourself or do you just come back to us to answer things for you?
 
Nice example, Aran. Then you are probably 100% against removing the GIL.
 
Good lord
I thought I was gonna get peace from the company slack but this is....
 
@Marco Making it optional sounds like a reasonable middle ground. I don't care about performance, so I'll just leave it turned on
 
11:44 PM
Roganjosh, I don't know why you're mad at me, but maybe your day just wasn't good, mine wasn't either, but I forgive you. The fact that I, for example, have the possibility of solving the problem by converting, for example, to Cython, all the rest of my code that does not release the GIL does not prevent me from returning to comment on my problem here (mostly vaguely), mainly because it's not trivial to convert a bunch of code to Cython.
I basically commented that I really wish Python didn't have the GIL, I think it's not wrong for me to express my opinion. Also I mentioned that there is a possibility that the problem involves something related to the machine itself that I am deploying my code. Ah, news that should be relevant to the subject, I managed to free up the use of more cores on this machine, but even so I can't finish executing my code.
Ok, Aran, great exposure.
 
I didn't have a good day, no. And I never suggested that you rewrote something in Cython. Wishing that Python didn't have the GIL is a massive topic and "mostly vaguely" is somewhat apt here. I have been trying to help you and I don't know what else to say unless you do your research
 
chat.stackoverflow.com/transcript/message/55857624#55857624: And no, at the moment I'm doing several tests to try to find out why in this environment I can't finish executing the code, I'm not researching Cython, nor trying to parallelize the code. Does not make sense. Especially because I can run it efficiently and smoothly on another machine, but I need to use this new machine because it is an HPC, and I need to perform longer tasks on it.
And I didn't come to ask for answers, but I could, but no one is obliged to answer anything for me, I know that very well.
Well, you mentioned about ways the code can be compiled, for example, include Cython in that. But OK.
But what research do you want me to do, Roganjosh?
 
@Marco I didn't suggest that you needed to compile your code with cython at all
The packages_/_libraries_/_whatever we call them might need to be compiled on installation
I'm not gonna try fix the markdown in time. The libraries you import are using C/C++ code, not you
 
11:59 PM
"I've told you about BLAS/etc etc": ok, I had already arrived that NumPy uses this, remember?

Well, about compiling, I think you are referring to PyTorch, which can compile part of the library in C/C++, ok. No, I didn't check that. But it doesn't make sense for me to optimize the program even more, since my goal is not to optimize more, but to at least have the same execution performance on the previous machine where I ran the code without problems.
 

« first day (4478 days earlier)      last day (471 days later) »