@wim My first thought (echoed when I googled to see if there were any caveats) was to question if that's really a good thing? For open source in general, for the 'community'...a lot of code that might otherwise be private is at present public because of Github's charging for it to not be so.
Will I be too impolite if I comment 'READ the basic tutorial of Python first.' in the following question: stackoverflow.com/questions/54340461/… _( :з」∠)_
I wouldn't mind doing Android stuff, mostly for personal use. But only if I can do it in Python, since I have no desire to learn Java. I had a brief look at the BeeWare docs about a year ago, and it looked intriguing, but I'd hate to invest the time & energy into learning BeeWare stuff if it's not rock-solid, or if it's slow. For simple stuff, I can just write JavaScript & run it in a browser.
@wim I think it's ok for the intended audience: people who are competent coders, coming from a C-like language. But there's certainly room for improvement, and more examples
But I certainly don't think it's suitable for raw beginners with no prior programming experience.
Hi, i am reading a file with polar coordinates and converting it to (Long, Lat). I want to loop over (range, azimuth) and save to csv only if a certain variable is above a certain limit. Can anyone guide me?
You are iterating using "range" on "range_data" instead of directly iterating on the elements of whatever data you have. 1, are you sure you want to do that? Most problems generally get resolved by iterating directly through a list. if yes, then 2, the error message indicates your value/values are not ints. check what "range_data" has. @user2153702
try and figure out how to express what you need in code first. (ps. only consider a certain value is essentially an if statement). You may actually want to spend some time going through some tutorials and getting comfortable with the language syntax
@davidism: yes, I think asking people new to Flask to start with packaging too is premature.
Publishing to Heroku or just checking out a repository on a server is pretty common. Packaging adds overhead without clear benefits (you can make your source read-only in other ways too).
@AnttiHaapala: so packaging might make deployment to a WSGI server that doesn't share the working directory a little easier. Does adding a path to PYTHONPATH cost more than teaching about packaging?
I know packaging has its advantages but it is further along in the lifecycle of a project, not at the very start.
I want to select N columns per unique value in certain column of a pandas dataframe. I am currently thinking of something like this bpaste.net/show/e19c144de0c7, but I feel there must be a better way. Any clues?
@AnttiHaapala I'm trying to get rid of zip_safe=False
I think the biggest impediment is the Jinja env
But like, it's everywhere. The other Pallets projects have it set, even though there's nothing stopping them from being imported from a zip.
@MartijnPieters thanks. I think my original reason was that way too many people were doing sys.path.insert or plopping a bunch of modules without a package, and then running into weird import errors.
Also flask run originally wasn't as good, now it can understand packages without them being installed.
But I should probably move the install page back to the patterns section rather than the tutorial. Maybe same with the test / coverage section.
Yeah, it comes down to informing users how to set up their template loader, or coming up with a loader that works in both scenarios.
The problem is if we go down the "works in every scenario" case, I guarantee some PyInstaller-like tool will break it in a different way than zipimport.
Yeah. Ideally something closed-form with a number of terms that doesn't scale proportionally to n
I'm trying to find a symbolic solution to a problem that I encountered yesterday:
This is a one-player game. The goal of the game is to have N points. You start with zero points. You take a turn by rolling a six-sided die. On a 1, you gain 1 point. On a 6, you lose all points. On a 2, 3, 4, or 5, nothing happens.
On average, how many turns will it take you to reach N points?
I only know the limit of the infinite geometric series by heart. sum_{k=0}^inf b^k = 1/(1-b) (assuming |b|<1), so then sum_{k=0}^n b^k = sum_{k=0}^inf b^k - b^(n+1) * sum_{k=0}^inf b^k = 1/(1-b) - b^(n+1)/(1-b) = (1 - b^(n+1))/(1-b).
Now I've got 12 * (2**N - 1) after doing a lot of math which I skipped writing down. Since it's only wrong by a factor of two, I think I've got a functional approach, stymied only by my atrocious algebra skills
quick question about TDD: when you guys are writing your functional/unit tests, do you think of everything that could possibly go wrong and try to test for that, then write code implementing your functionality?
or do you just do the most straight-forward testing first
so, for example, if i'm testing an "edit profile" page, i can think of a buuunch of different scenarios (user's not logged in, user logged in, sent wrong type of request, etc.)
should i not worry about these scenarios (yet) and write the straightforward test + code first?
As someone who has never done TDD but thinks it's a neat idea, I would also like to know the answer to this.
In principle "everything that could possibly go wrong" should be a category with a finite number of elements, so it should be possible to compose a big list of possible disasters, and write a test for each one of them.
My answer to that (I sometimes do TDD), is "whatever floats your boat". Ideally, your steps / tests should be incremental & not too extensive in the first go, else you'll be left with many tests & little code trying to get things by the deadline.
Perhaps try the basic tests first, then write functionality, test, if they pass, add extensive tests, repeat.
I'm no authority, but that's the approach I usually like for real-world (time limited) projects
In design-first-test-later development, it is said that the ideal is to test every code path. If accessing the page without logging in first causes code to execute that isn't executed in any other scenario, then it should be tested. Perhaps this ideal is also true for TDD.
@AmagicalFishy Ideally (given TDD), you'd write tests for and then add basic functionality for "edit page". Next step would be to add the "wrong type of request" tests, but if the view is dependent on user login, then the user logged in or not scenarios must be included in the very first tests.
How you test all code paths when you have not written any code yet, seems a bit chicken-and-egg. But I guess if you have a clear mental picture of the design before you start writing tests or code, then you can make an educated guess
Keeping it minimal is key when adding functionality. Don't write code for which you don't have a test for. IMO that's what TDD says. So, keep the tests & code incremental, even for a single view (if complex).
Inspecting elements of the series, I'm getting negative numbers, which doesn't match what I think should be happening, alas
Ok, I wrote down all* the math this time and I got the answer I wanted: pastebin.com/NXFnyvHg
(*except for the math that Andras gave me)
"It appears that f(n-q, n) = A[q] + B[q] * f(0,n)" is a bit hand wavey, but I'm not inclined to do an exhaustive proof because that would be exhausting
Hmm, sum for k from [1,i] of (1/2)**k doesn't quite work for i=0, does it.
That may just be a typo.
No, it gives me the numbers I want. I guess it's logically sound as long as the sum of an empty interval is defined to be zero.
Hard mode: now find the formula for the expected length of the game, except you gain a point with probability P, and lose all points with probability Q
I guess you'd change the cur != n case to P* (1 + f(cur+1,n)) + Q*(1+f(0,n)) + (1 - P - Q)*(1+f(cur,n)) and work from there. The steps are conceptually similar, just uglier.
Variant problem: same setup as the base problem, but rolling a six only causes you to lose a single point, unless doing so would give you a negative score.
@AndrasDeak what about this example on the numpy site
>>> a = np.arange(6).reshape(2,3)
>>> a
array([[0, 1, 2],
[3, 4, 5]])
>>> np.argmax(a, axis=0)
array([1, 1, 1])
I feel like there's a story behind the warning at picamera.readthedocs.io/en/release-1.13/…, and the title of the story is "Dave Jones and the neverending stream of troubleshooting emails from beginners"
yeah, i think i heard of an accidental numpy patch bug that affected a few systems for a while, that had the sum -1 work wrongly for very specific users.
Questioning assumptions is one of the most critical things about programming though for sure. More often that not, when we are trying to debug our code for example, ive seen a lot of people just refuse to believe that they made a mistake in some portion.
And then they tell me "this should work. why isnt this working?"
@erotavlas So when you see an example, don't just read it. Copy it to your IDE or editor & run it, then modify the values and run it again & see what changes. Keep playing with it until it sinks in. That way you're much more likely to understand what's going on, and more likely to remember it.
{Intern} showed me a sql query in our project that seemed unusually inefficient, and we couldn't figure out why it was written that way until we questioned the assumption that the original author was a fool and a charlatan. It turns out, I wrote it, and I had a very good reason, the specifics of which will not fit within this margin.
That's the way I learn stuff. I've been coding for almost 50 years, but whenever I learn new material I still try to play around with it, because it's so easy to misunderstand stuff if you just read it & don't test it.
OTOH, just experimenting with stuff can be helpful, but random experimentation without guidance from the docs or a tutorial can lead to faulty assumptions too.
Yep. The finite geometric series formula always works, unless the ratio is 1. It even works for complex numbers. And a good thing too, otherwise power series would be pretty useless. ;)
@PM2Ring So true. I've only really understood how git branching worked when I tried it out on a dummy repo and I was watching my work literally disappearing before my eyes, and reappearing to the sound of the git checkout.
Several hours ago I had to post some stern comments on a terrible answer in Astronomy after that question was used as a dupe target to close a new question that has a great answer. Fortunately, a mod has re-opened it.
@vaultah Oh, I didn't notice that, since it's hard to see on the phone. But now that I've zoomed in on the full-size version on the profile page, I see what you mean. Yes, I think that's report-worthy, but I can't remember how to do that. I guess a custom flag on any of their posts.
@Kevin Yep, plasma, but it gets pretty dense down in the core, like 130 times the density of water for our Sun, IIRC. And of course that will expand back to normal gaseous density once you remove the pressure. I guess it's easiest to just work with the star's mass, and average over the different elements in the star.
Even though it's mostly hydrogen & helium, there's still a heap of other elements. Eg the Sun has more than a 1000 Earth masses worth of iron that it inherited from the cloud that provided the ingredients of the solar system.
@ParitoshSingh It's spread through the whole Sun, due to convective mixing, and you can see evidence for every element in the Sun's spectrum. I think there's a higher concentration of heavier stuff in the core, but I'd have to check what the real astrophysicists say about that. Obviously, it's not possible to observe directly, but we can get indirect evidence from how heavy elements interfere with the fusion reactions.
Interesting. i thought for some reason that stars would not have heavy metals because afaik they only form on supernovas...but then i derped and didnt consider that further stars would be formed from the remains of a supernova explosion
Certainly I'd expect gravity to draw heavier elements closer towards the core, but since gravity's not the only force at play I'm unwilling to make a generalization
I wonder if a general relativity adjustment needs to be made for the density calculation. Meaning, do we inaccurately calculate density of stuff when it is in gravitationally warped space? I've never thought through this so I might be mixing stuff up.
@ParitoshSingh The stuff that forms stellar systems is mostly hydrogen & helium (3 parts H to 1 part He, by mass); the other stuff is around 1 to 2%.
But that other stuff is quite important, so the very earliest stars that didn't have those extra ingredients were quite different. They were much larger & hence died rather quickly. We think. There are none of them left in the modern universe, and although we look back in time when we look deep into space it's not easy to see individual stars many billions of light-years away, until they go supernova.
@Kevin If a star is big enough to get to the stage that it produces iron then it will collapse. See en.m.wikipedia.org/wiki/Supernova#Core_collapse In fact, that whole page is excellent, despite a few internal inconsistencies.
I came to a similar conclusion, having just skimmed across half a dozen articles that mention iron in a stellar context, and which invariably go on to mention how stars with that kind of composition explode pretty much immediately afterwards
Points to Iron Star for being about something that won't exist for 10^1500 years, and also using the phrase "forest of forbidden FeII lines"
So "non-supernovas can form iron" should be interpreted to mean "a star that hasn't yet become a supernova, but definitely will very soon, can form iron"
One of the most important elements for star formation is carbon. When a gas cloud starts collapsing, it heats up, which tends to counteract the collapse. But if the cloud contains a little carbon it can radiate infrared in frequencies that hydrogen & helium are transparent to, so some of the heat can escape.
@Kevin Yep. Actually, it forms radioactive nickel-56, but that quickly decays to regular iron-56, via cobalt, generating lots of heat & neutrinos in the process.
Carbon's also important in the life of stars too. As well as the usual p-p chain that turns hydrogen into helium, there's the CNO cycle that primarily operates in stars hotter than our Sun. It's a kind of catalytic process that turns carbon into nitrogen, which then goes to oxygen, which then breaks down to helium & carbon, so the cycle can repeat. It's kinda cute that the 4 most important elements of organic life, CHON, are also important in the stellar "life" cycle.
Carbon is initially produced by a thing called the triple alpha process, where 3 heliums (alpha particles) fuse to carbon. But almost all of the CNO in our bodies comes from that CNO cycle.
Reminds me of an article I read that asked "how come smaller numbers tend to have a greater number of cool properties than larger ones? Why does 2 get to be the first even number and the first prime and the minimum number of points required to determine a line? Save some for the rest of us"