« first day (4073 days earlier)      last day (882 days later) » 

8:35 AM
hey guys, I have three different functions which would print a few results, I would ideally want to have these sent over an email, how can I collect these print statements so I can send them as mail once all 3 functions are done?
I have referred some code for the smtp part from stackoverflow, the problem is I am not sure how I can collect the print
I can't just return these messages as values because the actual functions themselves return values that I later use
 
It's a hack, but you can use contextlib.redirect_stdout
 
so I add this before every print I want to get?
 
Cbg all, how's everyone ?
 
No, just wrap the whole program in it
 
I have a couple logs there, won't they get captured too?
 
8:43 AM
Yeah
 
most prints happen at a same place, so I guess adding them at places is doable
thanks man
 
In that case you have no choice but to rewrite the whole mess
 
how bad is it to return a tuple with one of the elements being a list of these messages?
Tuple[List[str], int, int, int] that is how it would look like
 
Hard to say without knowing the context
 
it is a mess, I had no idea I had to mail these later on, when you meant re write, how can I rewrite this? I would still need to collect these right?
 
8:50 AM
If you want to mail them, then naturally you must collect them first, yes. What you need to change is that the functions must help you with collecting the stuff you need, instead of just printing it
 
I can have a class and pass that instance to every function which can just add the messages to the instance? this way I don't have to return anything
would that work?
 
Yes
 
thanks I will just go with this then, now I have to edit all the prints :D
 
9:29 AM
I just realized I accidentally formatted my EFI system partition instead of my USB stick... oops...
 
Is this a smart way to make code work with multiple versions of libs?
from packaging import version
from django import __version__ as django_version
if version.parse(django_version).major > 3:
    from django.utils.translation import gettext_lazy as _
else:
    from django.utils.translation import ugettext_lazy as _
I feel like yes, but maybe somebody else has more experience with supporting multiple versions and could give me some advice on pitfalls
 
I'd rather do if hasattr(django.utils.translation, 'gettext_lazy'): than figure out the exact version where it was implemented
 
makes sense
I guess then I could just as well try to import and catch the exception?
 
True
 
If there's a clear version dependency, I prefer having it explicitly in the code. Makes it harder to accidentally silence dependency issues.
 
9:37 AM
@MisterMiyagi that's what I thought too, thus my first approach, It was deprecated in 4 so bigger than 3 seems fine
 
FWIW, I would use version >= minimum_version instead of version > (minimum_version - 1).
 
true
I'm making now an own file, from where all the other imports are gonna happen
 
 
3 hours later…
12:46 PM
woah updating from django 1 to 4 took me about an hour, I'd say that's a really good job on their part to keep everything so stable
ok nvm, it compiles, the tests don't pass yet :P
 
1:20 PM
hello can anyone point me how to start with open source
What it means to be open source contributor
 
1:32 PM
@jeea are there any libraries that you're using a lot and whose codebase you're familiar with
There isn't a set way to get involved. Most libraries will be really appreciative of pull requests for issues, as long as you've taken the time to understand the inner working of the code. Lots of libraries will also put a "good first issue" tag on issues that they think people will be able to start with
 
1:59 PM
Thinking about the topic from the other end, I wonder what I can do to make my projects friendly to new users.
Surely there's a lot of overlap with general advice on maintainability. Make code that people can read, document things, write tests. But perhaps some of these are more useful to experts. If I was fresh out of CS 101, I probably wouldn't know how to run a test suite, for example
(I still don't know how, but that's besides the matter)
 
some projects do some kind of "on ramp" documentation for contributors, that always is helpful, even if it may not instantly enable a complete beginner to get going. Unfortunately, you just have to expect "some" level of familiarity with programming when writing your docs.
The other roganjosh already mentioned, labelling easy pickings as "good first issue"
for the on ramp documentation, this was where i first saw it: spyder contributing
Unfortunately, it still felt intimidating when i first saw it...and im honestly not sure how to address that aspect. I feel like the devs really did a great job trying to make it easy to start
 
I think it's useful to set expectations. For some of the internal tooling I'm building, people are starting to devote their "initiative time" (we get 3 hours a week) to helping support it. I was actually quite happy with the way that people handled "just be aware that it's likely that I'm going to throw PRs back at you in the beginning. I hope that won't frustrate you"
 
Mm, thats a good shout too, though that may not help someone who's afraid to send the very first PR out itself.
 
If anything, they seemed more motivated by that because they're looking to develop better practices, so then they have a decent frame of reference - "this library is part of a full stack and I know that pushback is really just to try help me think about the problems a bit more and refine my code"
 
this conversation is making me wonder whether* some kind of interactive contributing demo would help..and whether such a thing already exists.
 
2:10 PM
I had a moderately challenging time making PRs for CPython and Notepad++, a year or two ago. The source changes themselves were simple; "CS 102" level difficulty at best. Getting my code onto their branch was what took up 90% of my time.
 
@ParitoshSingh we're trying hard to figure out how to do this internally
 
yeah, theres a lot of tooling "around" the actual code that one needs to essentially be familiar with to really get going. git itself for example, is so vital to the process
 
At the moment I haven't managed to figure out a decent approach, nor has anyone else, though we have software engineering workgroups every week that just got set up. But talking to 75 people about the principle of decorators (which has become the de facto example) doesn't help people identify where they might be useful in code. But then, that's too granular
 
but may not be at the forefront of someone who has just done studies in school
 
The ideal would be for someone to do some live refactoring (or something like that) but it's asking for people to throw their code under the bus. Personally, I don't mind doing that with my god-awful customer code where we've rushed, but then people kinda need to know the context of the problem. And there wouldn't be many other volunteers
 
2:15 PM
It sounds like your team is on the right track though, and may very well crack this solution.
 
CPython's PR process is pretty well documented at devguide.python.org, but the quick reference is over a page long, and the not-so-quick reference has a hundred bullet points
 
I was imagining something really really basic, like a kind of code base that resets to a certain state with some bug or some typo
and people make PRs on it, where the bugfix itself is documented. all they need to do is walk through the actual steps, but the steps include running tests and stuff
This may not apply to your internal use case btw, but was just wondering what it would take to make contributing feel less intimidating for new programmers in general*
 
My suggestion, which didn't get the reception I'd hoped, was that we start a toy project trading with training cash and it's understood by everyone that the reviews of PRs will be thorough. That detaches it from any customer work we have, gamifies our output a bit, and sets expectations
Plus, would be relatively full-stack if we slapped some webapp on the front. I might try again
 
My seasoned developer brain lobe understands why each step in CPython's process is important and good, but my inner child looks at the size of the scroll bar and says "oof"
 
That suggestion sounds very good, though the issue is see is that it's taking actual developer work and putting it into the toy project.
 
2:19 PM
You have to balance it against the appetite of the DS team here, though. There are multiple people asking for help in the software engineering side, and we've had a few failed initiatives. It's not really wasted effort in that context. Or, shove a real £100 in the pot and bet small. Split the profits
 
That may be why it may not go well with everyone. it's essentially developer effort being sent into a project that they know is not going to be used, just to learn how PRs work, which may be perceived as a smaller reward for the effort needed
 
It's not just about PRs, but the review of the code itself
 
ah! gotcha
got it, different goals then
 
Sorry, that's my bad for not being very clear. I'm trying to hit multiple objectives at the same time
 
no all good, I see where you're coming from now. If the goal is to teach the whole review process, this could work
I will say, something that seems to be great for this, discord bots
i wonder if you could morph that into something that can be done at work. how about a teams bot (if you use teams) or something along those lines?
The single biggest upside of that, is that there's immediate feedback with whatever you did. And the concept of sending commands in a chat and having it do "something" seems easy enough to grasp for anyone no matter what background
 
2:25 PM
What's the goal of the bot? Is it something we could keep iterating on?
 
@ParitoshSingh Even just a video showing the process from start to finish, would probably be useful for a good portion of interested viewers
 
exactly, the goal is just "useful commands". so you essentially pick some commands you wish to have
the simple ones, like saying a joke, getting the weather, polling your meetings, that kind of stuff. really, you can make it as simple or complex as need be
and that makes it so flexible for different users
@Kevin True! I feel like this surely "must" exist somewhere.
 
The viewer fresh out of CS 101 watches the video and says "oh, so that's how I open a cmd prompt". The Kevin watches the video and says "oh, so that's where they put the "change branches" dropdown on Github"
 
And then we just slap the PR scrutiny process on top of that, I guess.
 
exactly ^
because the actual task is so trivial, the entire focus shifts to the things you actually want people to learn.
some boiler plate for turning commands into actions at best, that can be abstracted away if need be
 
2:28 PM
cabbage!
 
I might float that idea; thanks. We need to come up with something because some of our code is heart-breaking when I wander our github, and the people writing it are also the ones turning up to these sessions wanting to learn how to improve
 
cbg
 
(not suggesting that I'm somehow the person to teach everyone how to fix it. But between a few of us, we have a lot of bases covered)
 
@jeea I would say it means participating in an open source project. The most common activity is probably writing code to fix a bug or add a new feature. But it can also be writing documentation and examples or responding to tickets from users or lots of other things.
 
I don't know if the clion warning: The file is too complex to perform the data-flow analysis is a compliment or a bad thing :D
 
2:40 PM
"where you go, I cannot follow ;_;"
 
Hello! I came here from SOpython website, is this where i can ask questions? this looks like official stackexchange website
 
Yes, question-asking is often done here
 
You can also ask more complicated programming questions here
 
This is indeed an official stack exchange website. All of us are regular users, so we're not spokespersons, or anything
Unless someone with a blue name and a diamond wanders in, maybe
 
Cool! I am a researcher who are migrating from matlab to python due to python being open source and i can strcture my programs better etc. I am having some syntaxial issues however, and this one i can't seem to be able to solve with google.

In matlab i can write A(A<2) where A is a vector of numbers, and this would give me a vector with 0 and 1 where the condition inside is true. Is there a neat way to do the exact same in python?
 
2:45 PM
check out numpy and pandas
 
I am using numpy but I've searched online and I can't figure out WHAT inside numpy that would achieve this to me.
 
I hear DataFrames are good at this kind of thing
If you'd like to stick to built-in types only, you could use lists and list comprehensions:
>>> a = [4, 8, 15, 16, 23, 42]
>>> a = [item >= 16 for item in a]
>>> a
[False, False, False, True, True, True]
And you can get [0,0,0,1,1,1] instead if you alter the condition to int(item >= 16). But I think booleans are more idiomatic here
 
oh wow that is exactly what i need
Thanks a lot!
 
No problem :-)
 
2:50 PM
builtin ways of doing this will be much harder and complicated in the long run btw
numpy and pandas does a lot of this for you
 
Just by saying "I am a researcher" I suspect that numpy/pandas will be useful to you at some point
 
I really need to become familiar to numpy and pandas
 
Sciency types love big grids of numbers and the many ways of moving those grids around
 
Yeah I am using large grids of numbers hehe I am using numpy for a lot of stuff
but currently i am trying to migrate my algorithms to python adn to get them running, then i can clean them up
 
Sensible
 
2:56 PM
Yeah, I've accepted that "doing them right" will not happen on the first iteration and i am just wasting my own time trying to write the perfect implementation from the start
once it is working i can polish it :)
 
Welcome to programming 101 :D
 
Thanks :D I actually attended one year of cs degree back in 2013, but when i was without physics i realised that was the program for me, so i switched then and never looked back. Nice though to have both worlds in my current research
 
There is value in writing a prototype that is slow and ugly and weird, even if you plan to throw it out and start over.
 
Yeah 100%. And i am structuring my algorithm and implementation as classes and objects now, so it'll be more easily modifiable than for example a huge matlab script written top to bottom
Is there a way then to use the vector [True False False .... etc] with anothjer vector to return only the trues as in matlab A(truth_vector) = (vector with only the true values) ?
 
@Kevin The way to look at reality. I find it somehow very odd, that basically all of reality can be broken down into linalg. The first time I had this realized it creeped me out for about 2 weeks and gave the whole world a kind of grey color. It felt somehow depressing to think that the whole human experience could be described as matrix calculations. But it passed and looking back I don't even know why I found this thought depressing
 
3:04 PM
hi, just jumping into the convo. what datatype is this actually?
 
vector of complex numbers.
 
what python datatype is this
 
and i want to use some conditions to sort out only a few of them
 
Personally I'm a little troubled that the world can't be broken down into linalg more. Darn quantum physics!
 
@Kevin oh wonders of quantum :)
 
3:05 PM
zp_raw is the vector with complex numbers, in matlab i wrote

zp_ind = zp_raw > 0;
zp = min(zp_raw(zp_ind)); to get the smallst value that made it > 0
 
so in python, vector isnt a datatype. there's lists, and theres numpy arrays. If you havent been using numpy array yet, i'd strongly suggest using that.
 
Perhaps you want:
>>> a = [-4, 8, -15, 16, -23, 42]
>>> only_positives = [item for item in a if item > 0]
>>> min(only_positives)
8
 
i'd say that offering list comps to them may be very detrimental to them here.
let me get to my computer, one min
well... i guess it depends. will you only be working with 1 dimension?
import numpy as np

a = [-4, 8, -15, 16, -23, 42]
arr = np.array(a)

zp_ind = arr > 0

zp = arr[zp_ind].min() # to get the smallst value that made it > 0

zp
Out[7]: 8
something like this would be the numpy equivalent. In python, the arrays use square brackets to access things. and while min exists as a pure python function, the .min method would be better when you already have arrays. you'll usually have the corresponding method for whatever you use
 
@ParitoshSingh I largely agree. But I don't know numpy, and I do know lists, so ¯\_(ツ)_/¯
Leave me alone in a room with a help seeker and a cabinet full of footguns, and the outcome is already predetermined
 
To be honest, it may not be as bad as i made it sound, I was just a bit cautious about not opening a can of worms for them if they actually needed numpy
Also, we need to get you onboard the numpy hype train Kevin! One more shotgun in your arsenal
 
3:15 PM
There was some discussion about that a page or two up. Summary: since they're a researcher in a physics-related field, they probably will need numpy in the long run. My list-based proposals are optimized for getting something working without too much cognitive overload.
 
The issue with that is that starting from list comps doesn't just keep you at square zero for learning numpy, it actively brings you to where you will need to invest a bit more effort to shift your mindset.
something below square zero, so to speak
 
Yeah :-)
 
numpy essentially thrives in vectorization, which i presume matlab users should feel at home with (i think).
 
I give querents only as many footguns as they can bear
Physicists already know the art of problem solving, so putting them at square negative one just brings them to even footing with beginners from the general population ;-)
 
It is indeed arrays i am working with, and it seems the syntax in the example from paritosh singh resembles matlab more
 
3:27 PM
@Kevin touche! :D
Off topic, but question about recommendation letters. When an academic writes a recommendation letter for an alumni, should they include what the student is doing currently, or just only mention the student's college life. context: student did college, then job for 5 years, now going for higher studies.
 
My uninformed opinion would be, just mention the college life
Ideally, the academic knew the alumni when they were in college, and they worked together at that time. The letter would focus on the qualities that the academic witnessed first-hand. If the academic hasn't worked with the alumni since then, it's not particularly useful for them to say "oh, and I heard they're working at XYZ and Associates now. I bet they're doing well"
I suppose things can get more complicated when the relationship is not so by-the-book. Maybe the academic is actually co-workers with the alumni at XYZ and Associates, and never actually knew them in college. Maybe they have no professional relationship, they just hit it off at the bar last year, and exchange work stories over a pint every week.
 
3:51 PM
arghh... I think my internet connection thinks it's Tigger... bouncy bouncy...
 
4:27 PM
Thanks Kevin!
Internet... its always there until you need it most
 
Cbg-eve
quick question : let's say I have a script with 3 functions
 
functions like show_me_the_fruits, show_me_the_tv_shows and show_me_the_closest_mcdonalds
 
@MisterMiyagi Well logging is quite a hard thing to make secure I would imagine
 
each of the functions needs variables to run, variables that can be different from each of the function. I'm trying to put them with some arguments, using optparse or else but I'm quite confused on how to do it.
 
optparse?
wasnt that old? argparse superceded it?
 
4:59 PM
I don't think I've followed any of your recent questions @AndyK
In future, please give an MCVE. These theoretical questions are quite draining
 
@roganjosh that's ok, there are some people who gladly helped.
@roganjosh I've put some questions on SO, so that should do what you are expecting.
 
When? I can see some from 2015. I should be clearer; the fact that you're getting help doesn't mean that it's not taxing on the time of the people that are helping you. I'm asking you to be clearer in general.
 
@roganjosh sorry I don't mean to be ... mean nor blunt, but as we are not face to face, your comment seems quite rude.
 
What is rude about my comment?
 
@roganjosh it is Friday evening. I will be as nice as possible. Put that in your room's rules.
 
5:06 PM
No. I would prefer that you answered my question about a perfectly objective statement
 
@roganjosh For me, it is objective. I do see your point of view though, that my question can be more meaty but when you are not sure where you are going, you are asking questions. But if the room is only for certain type of questions e.g ones with MCVE, then it should be clear on the rules. ;)
 
How can we make it any clearer, then, in your opinion? We have a set of rules and most people don't even bother reading them, let alone giving an MCVE
 
woof
 
@JonClements meoow
 
oh there's a cat... must chase the cat... brb
@AndyK what would you suggest?
 
5:15 PM
@AndyK The fact that we let a few questions get answered without an MCVE can be considered a "leniancy" or a "relaxation". We could become completely stringent about it if you actually preferred, but i dont think that leads to a particularly healthy conversation in general. I'd suggest re-reading roganjosh's messages with a more open mindset, and dont try to see it as a personal attack or attempt to be rude.
its not rude to ask for an mcve. it's rude to expect help without one and dismiss the concerns of a room owner for your own convenience.
 
i'd go so far as to say that your statements were uncalled for. i mean, come on, you aren't new here, right?
 
@JonClements I don't know tbh. I hear Roganjosh's point of view, although I disagree. I'm not asking for code per se, even if sometimes I do (I recon that). However, if you don't want to answer or cannot answer, don't. Not sure if being stricter would help but that's my point of view.
 
It's not about the answers needing code. it's about the question being phrased with some code to go along with it, to make the question clearer.
It can be as simple as "here, let me show you with an example what i mean to ask. <example follows>" that's pretty much it.
That "shouldnt" be seen as an attack.
 
It also doesn't help that you apparently haven't done a lot of research about the subject, because if you had, you should know that optparse has been deprecated for a long time (since python 3.2). That's immediately a red flag.
 
5:20 PM
@ParitoshSingh I like your answer. it gives more context. I do agree that asking for an MCVE is not a unheard of and I've been here long enough to know the rules ;) Just probably that a Friday evening makes more ... jumpy than usual ... My bad for this one.
@Aran-Fey that one is fair.
 
@roganjosh yeah I did some searching on the internet, I forked and did a pull request but I think the repository i forked was quite old
 
Cheers, appreciate it.
 
@roganjosh apologies.
 
@AndyK no need to apologise. I liked Paritosh's explanation of what's happened here. Please keep it in mind with future questions; I certainly wasn't trying to be anything other than objective.
 
also how to check what different versions of python I have currently installed, I think overtime I have installed many different pythons like anaconda and different versions here and there its a complete mess
 
5:23 PM
@roganjosh will do 👍
 
Thank you :)
 
@AndyK some things happen - don't worry too much about 'em. Just try and be nice about your frustrations when communicating here is all :)
 
@jeea that's what anaconda does to your machine. You know what they say about it? Say no to anaconda
 
@JonClements indeed. I try my best to to keep a quite demeanor but sometimes, the day is taking a toll but that's not an excuse and indeed, the piece of code is giving me a bit of headache but that's another story
 
Also about the mvce story. You can ask your question here without code, but it has to be somewhat high level and interesting Some old deprecated library and some nitty detail isn't gonna jiggle many whistles or what ever the phrase is that I'm looking for
 
5:30 PM
"jiggly many whistles" probably isn't it. It's tickled me, though :P
 
@Hakaishin Yes! I mean, "No"! I mean, Yes Sir, No Anaconda!
 
@AndyK we all have our "off days"... don't worry about it
 
Nooo.... grrr editing an old messages just deletes what you previously started typing
annoying
I just discovered two opposing design principles one is to parse inputs at the beginning and then pass around "clean" data types. The other is to do lines of codes as close as possible to where they are gonna be used. Which left me now in an interesting situation I have function foo, bar and zee. Now foo takes a str which is a datetime, but only zee uses it in the middle of the function. So at first I parsed it to datetime in foo, then thought wait I parse it there where I need it in zee,
but then I realized what if I need it in bar, I will just see the param datetime and will expect it to be a datetime not a str, so I think I'm for the first philosophy, I wonder if the google c++ style guide has something about this tradeoff scenario, because principle 2 I have from them principle 1 I'm not sure where I got it from
hacks :D
 
"Now foo takes a str which is a datetime" excuse me?
 
I have to agree, not parsing everything at the beginning is just gonna result in a mess
 
5:37 PM
if something's unparsable, the sooner the better though
 
@JonClements cheers mate.
 
have a nice weekend folks :)
 
ditto
 
 
3 hours later…
8:35 PM
0
A: Problems to display the Form in the Template using CreateView

nigel222You also need to render {{form.fieldname.errors}} for each {{form.fieldname}}. The error will be telling you why the form is not valid, but you cannot see them! You can test it if there is extra html you want to generate only if there are errors. {% if form.fieldname.errors %} <br> {{form.fieldna...

 

« first day (4073 days earlier)      last day (882 days later) »