« first day (3725 days earlier)      last day (1222 days later) » 

12:16 AM
or possibly someone trying to set up a cache that accidentally keeps querying the endpoint over and over
 
@xcodz-dot If you can isolate the performance to a particular method, then you are likely looking at changing your algorithm to make any significant improvements (though just changing an "in" check from a list to a set or dict can give a marked speed increase).
 
 
4 hours later…
4:32 AM
is there an opposite to this? var = foo if cond else bar something like foo if cond else bar = value
I know this is a syntax error, what I am asking is variable names on the lhs based on a condition
 
5:01 AM
Sounds like a bad idea, but you could just do it with a multiline if statement since they don't create a new scope. You can just do
    if cond:
        foo = value
    else:
        bar = value
 
that is what I have now, just wanted to know if there was a different way
different not necessarily better
 
You can also directly modify globals(), but that's considered bad practice I'm pretty sure.
 
 
3 hours later…
7:53 AM
this closed question looks like it can be fun stackoverflow.com/questions/65463750/…
good way to learn ast
 
 
1 hour later…
9:15 AM
@python_learner you can use assignment expressions to assign variables in an expression context, but if you want to do "variable variables", it's usually better to use a dict instead:
data["foo"] if cond else (data["bar"] := value)
 
9:29 AM
Hi everyone!
 
10:08 AM
@Arne With a dict you can write data["foo" if cond else "bar"] = value.
That seems to focus the conditionality on the target a little better.
But in isolation, such code raises questions like "am I then going to have to use mechanisms like if key in data (or worse when names are optionally set) to determine whether a particular assignment took place?" and I am therefore leery of it.
 
@cs95 re stackoverflow.com/questions/65464695/…: no, you want cheap rep for swag. Good old times.
@Arne does that actually work? I thought it was forbidden. Or was that only attr lookup?
 
10:25 AM
@AndrasDeak Was all that really necessary?
 
Yup
 
So I'm itching to answer a question or two, send me my fine in the mail... In my time here I've closed more than many who've been around longer than I have. My conscience is clear. But I appreciate your advice and will try a bit harder to exert some restraint ;-)
 
10:41 AM
@cs95 if you stay inside I won't see the mess you're making, and that tag's hard to make any worse anyway
 
@AndrasDeak no it doesn't, you're right =/
 
@Arne aww :P
@python_learner make friends with the enter key
Spaghetti is only good on a plate
 
@AndrasDeak "mess" is not the right word to use there, but I understand how you feel
Btw my answers are always public. I invite you to take a look and exercise your voting privilege as you see fit
 
11:04 AM
I have a question about jupyter notebook...
Is there any way to scroll the pop-up help page without using the mouse?
(of course I tried searching, but there's no result. It would be weird if nobody wanted this before) -> startpage.com/do/dsearch?query=jupyter%20scroll%20help%20window
Using help(<symbol>) is possible, but <symbol>? is faster to type.
 
11:15 AM
if you do something like
class A(B):
    def __init__(self):
        super().__init__()
 
Please read through our formatting guide for chat
I can see you're struggling with it. It really is a pain compared to main :/
 
you use super() so as to create the base class in the way you would like, however what happens if you dont init the base class in the derived class?
it is automatically created?
 
Huh? Is jupyter notebook questions okay here?
By the way that question is also okay for main right? (questions about software tools commonly used by programmers)
 
@roganjosh was this meant for me?
 
@Trajan It's optional and not calling is no-op -- stackoverflow.com/a/1385836
 
11:24 AM
@user202729 perfect that what i hoped for
 
(Although it's not what you would normally do with inheritance see the answer right below it -- other languages force the parent to be called)
 
@Trajan yep, just because I could see you taking multiple goes so I thought it might save you some hassle next time :)
 
@Trajan instances are created in __new__. In __init__ they are initialized. If you don't call super's init in B's init then A's attributes set in its init (for instance) will be missing
Put self.foo = 42 in A's __init__ and see if B has that attribute if you don't set it and you omit the super line
There's only ever one instance, and that belongs to A
 
@AndrasDeak dont you mean A and B the other way round here?
 
@Trajan yeah, sorry. It's usually the other way around in examples because you define the parent first
The last message is correct, first two mixed up
 
11:38 AM
class A:
    def __init__(self):
        self.foo = 42

class B(A):
    def __init__(self):
        print(self.foo)
do you mean that?
 
Normally you'd just go alphabetically with naming so A would be the parent class in the example and B the child.
 
@roganjosh fixed, its because im making up this example myself
 
Sure. But any example that's using A and B as class names is (hopefully) just made up :) There's nothing really to "fix", it's just that hypothetical examples would generally run alphabetically and that would always define the parent before the child
 
ok so in this example B() says that self.foo doesnt exist
but i thought it should be there
 
Isn't that what the answers and Andras were telling you, though? You didn't initialise the parent class
21 mins ago, by Andras Deak
@Trajan instances are created in __new__. In __init__ they are initialized. If you don't call super's init in B's init then A's attributes set in its init (for instance) will be missing
And since you've now switched the class names, that comment is correct in its names
 
12:00 PM
i knew i didnt understand this properly
its because the derived class init() function overrides that of the base class
 
No, it's that the parent's __init__ is never run
 
because its being overriden?
 
No, because it isn't called
class A:
    def __init__(self):
        self.foo = 42

class B(A):
    def __init__(self):
        super().__init__()
        self.a = 2
        print(self.foo)

b = B()
Nothing there is overridden. I can still call self.foo and set an attribute in the child class
 
@roganjosh well...
 
Or maybe I'm horrendously wrong now?
 
12:04 PM
In the subclass the new __init__ shadows the one inherited from A
In that sense it's overridden
If B doesn't define a different __init__ it will work, because the inherited one will be called
like how all classes inherit object.__repr__ unless overridden
 
But my example does have a different __init__, it's only a case of name collisions that things get overwritten?
 
@roganjosh well name shadowing is the mechanism of overriding things :)
Not sure about traditional OOP jargon
 
My thinking was that that was the only thing going on in my example
Or, rather, the only way that the two __init__ methods trample each other
 
Shadowing? Yes. I'm just saying it's not unreasonable to call that overriding.
 
Ah, ok. I think we're on the same page :)
 
12:08 PM
yeah
 
class A(B):
    def print_(): print(self.foo)
this didnt work when i changed it, self not found
 
@Trajan you didn't define self
 
I don't suppose this is all bundled into MRO? I guess not, when it's about __init__
 
   class A(B):
        def print_(self): print(self.foo)
 
@roganjosh what do you mean?
 
12:10 PM
that didnt work either
 
@Trajan how did it not work?
 
print_() missing 1 required positional argument: 'self'
 
Does your B define .foo now...? Name's swapped again.
@Trajan instantiate your class
A().print_()
 
MRO would be concerned with just methods and not attributes that are defined at instantiation. But there is no fixed order to which gets precedence:
 
@AndrasDeak that works now
 
12:11 PM
I'm on mobile so can't explain instance method vs class method vs static method
 
class B(A):
    def __init__(self):
        super().__init__()
        self.foo = 2
        print(self.foo)
vs:
class B(A):
    def __init__(self):
        self.foo = 2
        super().__init__()
        print(self.foo)
 
@roganjosh I still don't get the mro part. The latter gives you 42, right?
 
Yeah. I was just musing about whether there was a fixed ordering like there is in MRO. But there isn't, as I just proved to myself
 
Fixed order of what?
 
Attribute lookup
 
12:14 PM
OK :D
 
1:10 PM
Is there any way to use byteplay on python 3.8? I really need it (((
 
 
2 hours later…
user13415013
3:17 PM
Hey friends, I've question.
Although it have been asked, but i want to hear from you guys :)
 
Given a list L of random values, how do I find the maximum sum of values, given that I can use at most R consecutive values at once, discarding the adjacent ones.
For example, given a list L = [13, 12, 11, 9, 16, 17, 100] and R = 3, the sum would be (13 + 12 + 11) + (16 + 17 + 100) = 169, discarding the value 9.
Another example is L = [10, 12, 11, 9, 17, 8, 13] and R = 2. Sum would be (10 + 12) + (9 + 17) + (13) = 61, discarding 11 and 8.
I've been stuck on this for 2 days. I can't seem to find a way to devise a non-greedy algorithm. I'm not asking for a solution, only a hint that can nudge me in the right direction.
 
user13415013
How to get exact location or [place name, nearby movie theater hall name] through python?

When user enters location in input, Like some place,restaurant,cafe name like
search term: [ 12th Street Cinema ]

Expected result ; It would show that movie theater located in that person location [Aurora, NE, United States ] , also nearby places with names.

I had found Google maps. But I dont want to use it because of users privacy concern .

Anybody tell me how can i get it.
 
user13415013
:)
 
@BožoStojković Are you allowed to take less than R values? For example, given L = [13, 12, 11, 9, 16, 17, 100], could you do (12 + 11 + 9) + (17 + 100)?
 
@Aran-Fey Yes. But it has to be maximum
 
3:32 PM
Dang, that makes things a lot more difficult
 
Brute force (recursion) - is the obvious one right?
Then the next thought should be dynamic programming.
 
@Aran-Fey Yeah, I know. It's driving me crazy
 
(aw, I keep typoing obvious to observe)
 
@user202729 The list can be quite large and I'm restrained on execution time
 
@nerd You definitely need some map, obviously. There's OpenStreetMaps, perhaps you can download it?
Wait wait wait, where does this problem come from?
 
3:35 PM
A coding site
 
Is it ongoing?
 
What do you mean?
 
Is it in an ongoing contest?
 
It's a challenge, not a contest.
 
@VictorVosMottor No idea. Either downgrade, or contact the library author (if they are active) or fix it yourself (if it's open source)
Easier said than done.
@BožoStojković Can you post the link?
 
duplicate: pandas groupby sorting on string column - Q&A link in my last comment - categorical data answer solves the problem - stackoverflow.com/questions/65466798/…
 
Okay, N is just 365. And wait, the obvious DP solution is n^2.
Learn DP yourself. It has nothing to do with Python.
 
user13415013
OpenStreetMaps thanks user, :) , would i able to do what i mentioned.
I think i could. I should download it and use it thank you
 
Can anyone answer my question about jupyter notebook by the way? chat.stackoverflow.com/transcript/message/51239548#51239548
 
@user202729 I suppose I would use tabulation?
Wait, how is it n^2?
Given that it's at most R consecutive values, but it could also be 1 to R-1
 
4:05 PM
>>> duh = b'hello there'
>>> print(list(duh))
[104, 101, 108, 108, 111]
Is there any way opposite to the b''? Like to get back the chr form?
I know ''.join(map(chr,list(duh))) could work, other than that any?
 
@CoolCloud no, that would give you a string
>>> bytes(list(duh))
b'hello there'
 
@AndrasDeak So we are talking about two different datatypes.
 
@CoolCloud well what do you think the b at the start means? See type(duh).
Also try doh = 'hello there'; list(doh)
bytes and strings are different enough that the python 2 / 3 divide was worth doing
 
@AndrasDeak This would give a list of strings right?
@AndrasDeak Oh, but how does bytes gets mixed with the ord ?
 
@CoolCloud read the docs on bytes first then ask these
What question remains after that we're happy to answer
 
4:10 PM
Found these.
 
5:04 PM
Hey everyone, did you notice this message by @Vic?
4 hours ago, by Victor VosMottor
Is there any way to use byteplay on python 3.8? I really need it (((
 
@Aran-Fey @user202729 I solved it. Thanks for pointing me in the right direction. I just didn't understand DP properly.
 
@TechExpertWizard yes
 
@Andras Um...
 
2 hours ago, by user202729
@VictorVosMottor No idea. Either downgrade, or contact the library author (if they are active) or fix it yourself (if it's open source)
 
that ^
The answer is "get the author to update the library or update it yourself". Which doesn't sound easy when it's a library that handles bytecode, which is fickle. But all this goes without saying so I didn't say anything.
There was no conversation going on. I'm only mildly bothered by the third-party nagging^[citation needed] about a message. A message with a question that was starred right after it was posted, which was also weird.
 
5:11 PM
@Andras Oh then, anyways, sorry. P.S. That message was starred by me 'cause I wanted someone else to notice it and to help @Vic 'cause we were having a discussion about it.
 
@TechExpertWizard yeah, please don't do that. There's no "fast lane" for asking for help. If the message gets ignored for a long time the asker can gently prod us. But weekends have low traffic.
 
@Andras OK, thanks! Actually, I'm still waiting for @Vic to come into our discussion room since I've got something that I want to discuss with him. But I know people are always busy, myself included :)
 
5:38 PM
@user202729 nominatim is the library built on OSM for this, but it's patchy at best
 
6:07 PM
@AndrasDeak Thanks anyway ;)
 
7:00 PM
Hi everyone. I am a beginner in stack overflow. So I want to know how to ask and how answers to me.
 
user13415013
:) welcome @George
 
user13415013
I've a question guys
 
You've already asked 6 questions and answered many more. I don't know what you mean @George
 
@nerd you also had a question today. So with your history: no.
 
user13415013
:) just little one :) I've not found on stack overflow :)
 
7:05 PM
@nerd :) keep looking :)
 
user13415013
I've found results that i can use from ap https://nominatim.openstreetmap.org/search.php?q=school&polygon_geojson=1&format=json. Although many request are blocked from api.
May be problem solved. Although still not convienced, but works .
 
recbg
 
@nerd I wasn't suggesting that you use the free API. Please don't abuse that. You can host your own stack for nominatim
That's for you to research, before you ask me how it's done
 
user13415013
7:25 PM
:) Thank you , I've found installation page, Although found takes a lot of resources, problem is solved .
 
8:54 PM
@roganjosh and all: Cbg, Happy Christmas 2020
Season of inquiry and experiment:
13
Q: Alcohol safety can you put a bottle of whiskey in the oven

FrankyI was in the mood to give someone a bottle of whiskey, but to customize it, I wanted to decorate it with polymer clay. But to set polymer clay, you have to put it in the oven and so therefore I would have to put it on the bottle of alcohol and then put in the oven. My question is, is it safe to k...

...one comment links to German ZDF TV show called "don't try this at home", and they show the effects of cooking a champagne bottle in a microwave oven. youtube.com/watch?v=2XjwVYkwB_w
 
Ha, I happened to slack that to someone else earlier. "Can I put a sealed container of volatile, flammable fluid in an oven?". I guess it would inject some excitement
 
@roganjosh And I imagine some people are getting creative with ways to light the brandy on your Christmas pudding?
I guess this is Mythbusters-cross-Jackass territory....
 
Afraid, all the alcohol here is to be imbibed. Burning it off; heinous:P
I'm almost tempted to check my t-x-y graphs to see if the fumes would be 100 proof and actually ignite. I'm relatively confident it goes boom, though :P
 
@George Your questions are ok, also they're mostly non-Python. Just the first one you asked obviously you learned that you almost always should post some sort of code attempt of your own, even if it's non-working or pseudocode, or at minimum some sort of outline of what constructs and data structures you will use. You can (and probably should) still edit that question, it's not too late.
@roganjosh Imagine people goofing around on Mars... then again, no atmosphere for combustion really, that excludes most of the fun stuff.
 
9:11 PM
Eh, there's enough fun to be had on Earth, it seems :)
 
Does anyone know a fun not so hard project to do?
 
@Rezaamin See what happens when you put a bottle of whiskey in the oven?
@roganjosh A brandy-powered rocket? Decadence meets silliness.
 
I mean, Brexit gives us a chance to dream big with our new space project! All ideas welcome
 
9:29 PM
@smci I like this one :D
Is there someone familiar with logarithmic regression? I need to find out how some parameters effect a binary result(0,1). I have around 5 Parameters on a dataset with 1000 rows.
 
@grumpyp Yes, what's the issue?
 
@smci I just don´t really know how to get started, whats the best libary I should use? I did some research but found different approaches. Maybe a good source? Thanks!
 
@grumpyp Yes? Do you have a coding issue, or are you just looking for tutorials with sample code? Use sklearn (scikit_learn). There are like a billion tutorials out there, some video, some use jupyter etc. So google "logistic regression sklearn tutorial". Let us know after you find one that worked for you.
 
@smci Alright thanks, gonna check sklearn then. I just wasn´t sure if my dataset fits to some specific libary to get the best results.
 
@grumpyp What different approaches did you find? You mean different packages? or algorithms? It should be pretty standard.
@grumpyp Well what's your dataset? sklearn should be fine, I'm sure there are others but sklearn is what people use. Presumably you found that too.
 
9:38 PM
@smci Some work just with numpy and math then they check the accuracy with sklearn. I just gonna use it, and then I get back to you if I have other questions. Thank you so far!!
@smci Are you familiar with urllib2 / requests? I´m still without an answer on a question stackoverflow.com/questions/65425739/…
 
@grumpyp Not much, but you should move to using urllib3 now. As it happens I came here today to ask my own urllib3 issue.
 
10:18 PM
@smci and same to you - hopefully a better 2021 for us all as well.
 
In response to grumpyp, do you guys use Python 3 urllib, or urllib3?
 
my impression is that the golden standard is requests
I almost never do web stuff, but when I do, it's requests. :P
 
Yes, requests + which of the urllibs?
 
Doesn't requests replace the urllibs?
 
People still seem to use both together, AFAIK.
 
10:32 PM
from my understanding... urllib3 is a 3rd party module that requests wraps around
if you only had to stick to native libraries, then in 2.x you'd use urllib2 or in Python 3.x, you'd use urllib.request
 
@smci not that I'm aware of, but that might not be a good yard stick
I'd use requests for anything I need that can be done with synchronous requests
 
I think there's been discussions that 3rd party things such as requests or dateutil should be part of the standard library, but, that just wouldn't work because of speed of updates, backwards compatibility stuff, introducing additional dependencies etc...
 
I'm gonna have to test this soon, incidentally. I'm gonna be battering my own API and I'm not sure I'll get away with async calls. I should probably test whether requests adds overhead to urllib
 
In my last job, I wrote REST client code using just requests. For simple calls I could use urllib from the stdlib, but I only did this on rare occasions when I was writing code to distribute to people when I wanted to minimize dependencies.
I've also been reading about FastAPI lately, but I think that is server-side only (alternative to Flask).
 
@roganjosh how resilient is your api meant to be? There's already things you can use to battle test a system with stuff that was meant for that purpose but can also be used to do a DoS attack etc...
@PaulMcG congrats on new job btw... hope it goes well!
 
10:47 PM
There's no way around it. I need to shift 300k calls as fast as they can be answered.
I'm connecting multiple different technologies so I'm a bit limited in how much I can influence the response effort. I'm coupling them up with HTTP
 
@roganjosh what's the infrastructure setup? Have you got a MQ with scalable worker processes or... ?
 
For the POC I haven't got a load balancer. For production, I will have several instances running
 
POC's are fun... :)
I'm going back to watching films now - but if you get stuck/want some pointers (even if they're not ultimately useful :p) - you know where to find me
 
@JonClements Thanks, Jon - First day is a week from tomorrow
 
Indeed Jon. I hope you've had a good Xmas too?
I may hassle you for puppy powah, but now is not the time :)
 
10:52 PM
@roganjosh it was okay thanks - quieter than normal but oh well... such was to be expected
@roganjosh you could try my uncle scooby - but he's not really the most verbose of canines come to think of it... :p
 
:P
Did you at least get a bit of down time to relax?
 
@roganjosh: 'Skyfall' isn't a proper Bond film, the post-Fleming plots are weak.
 
yup... might even have had 4 days in a row!
@smci I enjoyed the song though :p
 
Pow! :)
 
rbrb for now folks
 
10:56 PM
Take care mate
 
@smci Oh... I totally enjoyed rewatching "The Night Manager" - if you haven't seen that and into that kind of thing... absolutely recommended
 
@JonClements I've been reading tons of positive recommendations... maybe would prefer to read the book first
 
@smci but stuff explodes n things. Like, that scene where he puts some whiskey in the oven to blow up the baddies
 
RIP le Carré too...
 
@smci It's as far as I recall not massively close to the book - so as a series, it's probably best to watch and enjoy rather than compare to the book - otherwise, you lose the watching experience because you're constantly comparing
anyway rbrb
 
11:21 PM
hey everyone, I'm trying to scrape a webpage using BeautifulSoup but there's a weird table element that has the following structure: <td><span>some span text</span>some td text</td>
so when I do a find("td").get_text() I would get back the string "some span textsome td text"
how can I only retrieve "some td text" using BeautifulSoup?
 
@JansthcirlU You mean, nested tags? If you can't get it working right, you might have to kludge to substring/subtract "some span text" from the combined text.
 
yeah there's a span in the cell which causes me to get that text as well
unfortunately some of the td elements follow a different structure so I can't always predict how I have to trim the resulting string
 

« first day (3725 days earlier)      last day (1222 days later) »