« first day (2118 days earlier)      last day (2813 days later) » 

4:00 PM
For me, it depends on how often your array will have less than x items. I try to stick with "Exceptions should be exceptional". So, if it's a normal case that you wouldn't have enough items, I would favor an if, but if 99% of the time you should have enough items, I would go with the exception.
 
Thanks @AndrasDeak I remembered it was not recommended but I couldn't quite remember why
old age is catching up on me, which is bad considering I'm not that old yet
 
re: being invited to chat ... at first glance it does look like a decent SO question, but it's more complex than it first appears. Good style is going to depend to some extent on what you actually intend to do with array[1].
 
Thanks @Way
thanks @WayneWerner
I wil check if condition in my code
 
also, re:cbg
 
If you're validating the 2nd element and your list should have the 2nd element, I would take this approach...
 
4:06 PM
The overriding rule, which all the other rules are really just attempts to illustrate in specific cases, is "which style most clearly expresses my intentions here"?
... because code is read more than it it written :-)
 
try:
    validate(array[1])
except IndexError:
    print('oops, you need more elements')
except MyCustomValidationError:
    print("No, that's not the right value")
else:
    do_the_thing(array[1])
Though typically I'd actually do something like...
try:
    do_the_thing(array[1])
except IndexError:
    print('oops, you need more elements')
except ValueError:
    print('oh dear, that value was the wrong type/value/format/was not a duck when I expected a duck')
 
I think there's a caveat there ... do_the_thing should be the smallest piece of work that you can coherently do, so that you don't inadvertently generate exceptions inside the try clause that you hadn't thought to deal with.
(aside: how did we end up discussing Python in this room? Isn't there a rule against that?)
 
@WayneWerner I am doing same thing, I have to validate for IndexError and ValueError, thanks for the code sample
 
unless the validation is just checking for a value where it should use a default value when one does not exist (then there are other options)
 
@ZeroPiraeus Yesterday was Java ;)
 
4:16 PM
to use try/ catch/ else is prefectly fine right ?
in what case, I can avoid else block ?
instead of else I can write in same line means
    try:
        validate(array[1])
    except IndexError:
        print('oops, you need more elements')
    except MyCustomValidationError:
        print("No, that's not the right value")
do_something_with(array[1])
 
press ctrl+k to format a message as code
 
If you edit your message and click the fixed width font ----->
There you go :)
 
I was trying to add 4 spaces :)
 
Well, if you want to put it in the else: block to indicate that "this is something that I should do after the first step succeeds, but only if there are no exceptions"
 
Assuming do_something_with doesn't care if the array item is valid, then that code's fine.
 
4:20 PM
^ because that
 
If it does care, then you would use the else block.
 
my else block is depend on array[1] value, I have to add else :)
This is first time, I am using chat room, sorry if I made mistake in my previous questions :)
 
If your program absolutely depends on array[1] existing, then you should probably do more in except IndexError besides print a message.
 
It's a warning sign if there's a lot of code in your else block. Typically, whatever's in there should deal with the exceptional circumstance (by bailing out, raising a different exception, setting a default value, etc) and then allow you to move on.
 
@ZeroPiraeus The else block shouldn't see any exceptional circumstances. I'm guessing htat might have been a thinko?
 
4:29 PM
Uh, yeah :-/ Can't edit any more. Thanks for the catch :-)
 
I can't remember the last time I used except-else.
I guess my design philosophy is: when you handle exceptions, either fix everything to the point that the program state is indistinguishable from a state where the exception never happened, or fail quickly and noisily so the user can diagnose the issue. In either case, else is not useful.
 
> fail quickly and noisily
 
Usually that amounts to logging pertinent data and re-raising the exception.
 
Depending on what kind of application you're writing depends how hard you can fail
 
try:
        headers = json.loads(args[2])

        headers_copy = {key.lower(): value.lower()
                        for key, value in headers.items()}

        json.loads(args[3])
    except IndexError:
        pass
    except ValueError as ex:
        LOGGER.exception(ex)
        raise MyCustomeException()
    except AttributeError as ex:
        # If headers is not dict
        LOGGER.exception(ex)
        raise MyCustomeException()
    else:
        # Check `content-type` is `application/json` and `accept` has
this is the code which I wrote after this discussion
 
4:35 PM
i.e. if your user-facing application produces a traceback, you're doin' it wrong ;)
 
Yeah I was just about to say that my philosophy has more merit in some industries than others.
 
no this is REST API, if there is any error, it will log and return 500
 
Extreme example: the airplane autopilot software should probably not terminate itself and return to the shell under any circumstances
 
OK guys, rhubarbing until tomorrow, most likely. hasta la vista
 
4:36 PM
rbrb @holdenweb
 
Ehh, you just need to make sure the copilot is handy with pdb ;-)
 
@Lafada I'm not sure that I would enjoy coming across that bit of code... I think there are quite a few improvements you could make there...
as a slight aside/background, is this a cgi script?
i.e. I'm wondering why you have this args array
 
except: pass is one of those things where you have to be really confident that you know what you're doing, if you're going to use it
 
I am using bottlepy
@Kevin only statement for IndexError is args[1] and args[2]
headers.items raise AttributeError is args[1] is not valid dict
ValueError if for not a valid json
 
Does bottlepy not provide json methods?
Looks like if you're using anything after 0.10, it does
and given it's on 0.12.9, you probably should be
 
4:42 PM
it has JSON methods and those methods expect a dict
which is probably a part of the problem
 
I got body argument as string which should be valid json
{
    "test": "test",
    "args": [
        "url",
        "method",
        "headers", # This should be valid header to call the url
        "body" # This should be valid json when call with `POST` or `PUT`
    ]
}
this is the payload
 
Do you not have request.json available?
Huh. Are there really no SO questions/answers that actually detail how to make a Python package?
 
4:58 PM
129
Q: How to write a Python module?

yowmamasitaI've been making Python scripts for simple tasks at work and never really bothered packaging them for others to use. Now I have been assigned to make a Python wrapper for a REST API. I have absolutely no idea on how to start and I need help. What I have: (Just want to be specific as possible) I...

2nd answer has more detail on packages
 
@JGreenwell I don't see setup.py mentioned anywhere there :P (which is mostly what I'm complaining about, heh)
 
oh, well there is one about that but it just copies the Distutils Turtorial from python.org wiki
could link if you want but again could just link to original :P ;)
263
Q: What is setup.py?

Software EnthusiasticCan anyone please explain, what is setup.py and how can it be configured or used?

but the answers there aren't that great so I see what you mean
 
Yeah. I mean... I guess they link to the docs, which are fine... I just wanted to close this as a dupe
but... none of the potential targets actually answer the question beside link-only answers :P
 
I figured you wanted a dupe target, might be time to answer it and then link them to it as dupes?
 
5:05 PM
(well, they may offer more than just links, but there's no clear-cut canonical "this is a simple way you can make a python package")
 
except yeah, I see not that great a question either
where's that kid who said he had no questions? Time for him to ask ;)
 
Maybe it's time to ask and answer the question :D
 
@WayneWerner request.json will give you args as array, I need to validate each item of array
 
That's... interesting. So you mean someone is posting
{
    "test": "test",
    "args": [
        "url",
        "method",
        "headers", # This should be valid header to call the url
        "body" # This should be valid json when call with `POST` or `PUT`
    ]
}
 
yes
means, my API call another API and return the data
to call that API, it need url, method, headers and body
 
I need to validate headers and body if there, then it should be json
 
Your architecture sounds really strange. If you're powerless to change it, well, good luck! Otherwise... I think there are better things to do
cause right now it looks like you're trying to make an HTTP request via a JSON call to an HTTP endpoint
which is insane
Either a) pass the HTTP request through, or b) pass the JSON request through
Doing something that's effectively http(json(http())) is just making things more complicated
 
it looks to me like your trying to get each section (element) of a JSON scheme instead of just trying json.load() and seeing if you get a value error based on the whole thing
 
I cant change the arch, need to provide validation in that arc :(
 
json.load('json or whatever') will pass a value error if something is not json - that is the standard way to check
 
5:18 PM
You can provide validation without doing crazy things
 
:)
I have to call API within my API call only, how I get data ?
like in args I suggest them to send valid json data
 
wait, what?
 
but they ask to go with string data only
 
so check the string
json.load() works with strings
 
DSM
Early afternoon cabbage for all.
 
5:21 PM
hey DSM
 
yes, that is what I am checkin in my code sample
 
....so what are you actually trying to validate?
 
Hey, DSM.
 
stackoverflow.com/q/38749095 dupe listed in comment
 
just got a headhunting email: "Greetings <name>, we would like you for <unkown> position" - I should apply
 
5:23 PM
@JGreenwell I have to validate args has value for headers or not, if it has value for headers then its valid json or not, args has value for body or not, if it has value for body then its valid json or not
This message from stackoverflow career ?
I applied trough career in may company
 
no, just random people
 
@JGreenwell how about emails that praise your accomplishments; we see your contributions to Open Source software, your Stack Overflow work, blah, blah, blah then offer a position with technology that totally misses the "dislikes" section in my published CV?
Great job on doing your research. Trash.
 
Finally got my new computer properly configured and can start doing productive work. Oops, the bug I'm supposed to be fixing can only be reproduced on the machines belonging to my boss and the head of QA, and they're in an all-day meeting.
 
The fact that I am currently hacking a lot of Java is neither here nor there ;-)
 
DSM
Free afternoon! #hooray
 
5:31 PM
Python is still involved in a major way :-P
 
Said meeting may or may not have "how can we improve the rate of progress on [Kevin's project]?" on the agenda
 
@MartijnPieters as it should be :)
 
sky rockets in flight....afternoon delight...aaaaaaaaafternoon delight.
♪♪♪♪
 
@DSM Yeah but I'm on edge because they could return at any moment.
It's like the part in a horror movie where the protagonist is juuuust about to close their medicine cabinet with a mirror on the front.
 
Is there a way to change what a literal digit character points to? Something like codegolf.stackexchange.com/a/28818/38770 but for Python.
Eg, I want to somehow do 4 = 5. (It's for golf, don't worry).
 
5:41 PM
@MartijnPieters I recently got one for a junior SQL dev. Recruiters are so impressive.
 
I don't mind it being some weird and hacky thing with ctypes or something.
import ctypes;ctypes.c_int8.from_address(id(len(patch))+8).value=eval(patch) Herp de derp, it's on that answer.
 
@MartijnPieters I don’t get why recruiters ignore the obvious places they need to look when SO careers makes it so super easy for them…
I got a job offer recently for pure JS dev because that’s the very first item that appears on my CV in the top 10% list.
 
I occasionally get one that does have a clue.
Usually they work for the big A listing companies. Amazon, Uber, Microsoft.
 
Yeah, I got one recently who wrote like a human, just for a random job in York
Other than getting the location wrong he seemed very competent
 
Well researched, clearly did their homework, won't bother to contact you unless they know they might have a shot.
 
5:45 PM
@RobertGrant I like those that write like humans
 
@RobertGrant well, the Uber recruiter didn't mention a location, which was rather devious, since they don't have a UK engineering office.
 
@Martijn Yeah, those are rare, but I love it when they show that they actually bothered to read what I wrote.
@MartijnPieters Maybe they were looking for a driver? :D
 
@poke they definitely did their homework. Down to knowing how long I've been with FB.
 
“Judging by your SO contributions, I see that you’re really bored. Do you want to drive for us?”
 
@poke :-D
 
5:49 PM
@poke "Judging from your SO contributions, you don't work a full day. Not quite sure why we're writing to you, but you don't get the job."
 
hah
 
They should be providing you either JSON, or just plain ol' POST data, right?
Or do they want to post something different?
 
"Method GetWidgets not found", says the C# runtime error. public List<Widget> GetWidgets(BasicUser user, int? maxresults=null){, says Widget.cs. "???", says me.
C'mon, C#. I thought static typing was supposed to make sure this kind of thing only happens at build time.
 
@Ffisegydd :D
 
6:07 PM
@WayneWerner check with my architech, in payload they have one more parameter on which bases they will check, to call another API or not, If you dont want to call another API then there is no need of ARGS
but if you need to call another API, then args need all details to call like ,url. method, headers, and body
 
that's awful
they can't, you know, do something sane? :P
 
Cant do in that :(, they design like that only
yes they cant, but I have limited power too :)
one more thing, what is your suggession, if you want to make some decision on another API call in your REST application ?
same stituaation they are facing here,
@WayneWerner I check your code
@route('/json', method='POST')
def fun():
    print(request.json)
    r = requests.post('http://localhost:8890/otherapi', json=request.json)
    print(r)
    return 'Ok'
in this r = requests.post(request.json['args'][0], json=request.json['args'][2])
this is the case in my code :(
 
Have you guys ever applied for a company, then they took so long to get back to you that you literally forgot you ever applied?
 
I got response from one company after 2 month :)
but they replied in Career portal only, so I got track of that when I applied
 
I got one from google a few minutes ago. The last email was seven months ago
 
6:17 PM
then you google beat my time
 
@corvid Google seems to go through recruiters like someone with the flu goes through tissues
 
@MartijnPieters Yep, if you're in Cambridge and you do any sort of software, chances are a recruiter from google has talked to you at some point
 
I've yet to be contacted by the same Google recruiter twice in a row, and they all appear to be new at the job.
 
@Lafada Yeah that's gnarly. I'm going to post something here in a second
 
Perhaps every new Google employee's first assignment is to recruit one other new employee. That way, they don't need a dedicated HR team to do it.
 
6:19 PM
@MartijnPieters first (and last?) Google recruiter that I was contacted by, when I finally got round to responding to them a week or two later, the email address had been destroyed
 
@Kevin but then, what happens when every human is recruited by google?
 
not just redirected... like their mailbox no longer existed
 
@corvid "The last non-google employee on Earth sat alone in a room. There was a knock on the door"
 
@WayneWerner yes! I had that too!
I'm pretty sure Google uses contractors for their recruiting work.
 
@corvid that happens with like 50% of the colleges I apply to
do companies which list "No physical location" make other people nervous or am I just weird?
well, weirder?
 
6:26 PM
Depends. Does this make you nervous?
 
It would make me nervous for sure
 
well, I'm not a sloth
 
oh...ok.
 
oh, sorry. Did I destroy your mental image of me as Slothman?
 
That would make kristen bell freak out, I'm sure
That's what an HTTP request looks like - one is form encoded, the other is JSON
so if I understand it properly, they're POSTing (or GETting, I suppose) an HTTP request embedded in an HTTP request
Rather than just posting the data
 
6:41 PM
@JGreenwell haha...I had to look up what that would look like. Was not disappointed
 
your being extra nice today Wayne....granted if they are doing that it is just insane
yes!
 
the checkered vest makes it greater
 
OMg Civ 6. :D Hope it's better than the last one.
 
waiting for your review
proceed with your playing
 
needs a bowtie
then it would be perfect
 
6:42 PM
 
That is fantastic
 
nerdcop episode needs one with that slothman <- @tristan
 
bowties are cool
 
@Lafada I just added an example comment on that gist of what I would expect them to be posting
 
@WayneWerner let me check
 
6:45 PM
I can't really think of any reason why you would want to do anything differently. Like, if you know the URL and the method and the data, why aren't you making the request? And for sure, why in the heck are you sending that request via an HTTP server rather than via a proxy server if that's something that you have to do
 
wow
it just never gets better
 
I'm actually lol'ing
I want to create that topic so hard
 
I almost feel like that user accidentally made their way to SOD and actually wanted to ask a question
 
@WayneWerner as I mention, I dont have control on that, what architech want to do is, make call from our API, for that we need data
@WayneWerner from your example, how to validate the body and headers ?
thats what I am trying to solve in my code
 
I actually wondered if someone here made that request but realized we'd all proudly use our own names
 
6:47 PM
@Lafada You don't. They're validated because you got a request. Your program should know about calling the other API
 
@WayneWerner other API's are not fix
 
Wayne is feeling really nice
 
@WayneWerner for some they are calling ElasticSearch for other case they call RabbitMQ etcs
 
@Lafada If they're not fixed, then what can your service even do?
@JGreenwell I don't want anyone else to suffer. There are many design decisions I've had to live with because someone was making really strange choices :P
 
@WayneWerner I agree with you, this is transge choice, but I dont have option :(
 
6:52 PM
Such as embedding microsoft word inside an Eclipse widget so it could be used for building documents. Instead of an HTTP form ;)
 
isn't that one of those milestone thingies that everyone is always talking about
I've actually done that one
 
@Lafada But what is your API supposed to even do? Can you explain that? Can whoever told you to build it explain it?
 
@WayneWerner this API store data to DB and send API call to other service, if other service return 'COMPLETE` status, it will udpate in local DB
this is the case
but Other API is not fix ?
 
Javadoc to Word comparable (compatible?) shiver
non-standard Javadoc, of course
 
@Lafada So how do the callers know what to call?
How are they going to change what API they're calling?
or the data that they're passing in?
 
6:56 PM
@WayneWerner caller is intarnal only, so he has endpoints for the internal api
 
@PM2Ring Great track. That Gibson SG is the guitar I dream to have one day. I absolutely love that sound.
 
It will add that
 
Does anyone else have an issue with github commits not showing on their page? My little tile graph is woefully out of date :( /minorproblems
 
heh...tried to link help out that OP (from Doc topic request) and realized I have no idea how to ask a question on SO
 
The problem here is that your program doesn't have a well-defined responsibility. Is it responsible for calling an API or is it responsible for logging data? It sounds like right now you have it trying to do half of both.

Either your API should provide logging services, and all of the API calling should be left up to your callers, *OR* you should provide API services and the callers should just be passing you data. If you provide logging of the data, that's also fine, but your callers shouldn't be passing you any non-data information
 
7:00 PM
except from my phone cause I hit the + button all the time on accident
 
@Withnail using the right email address on your commits, right? ;)
 
It sounds like it's time for some garlic.
 
Indeed.
Alas :(
 
nah, that time was an hour ago - Wayne was just being really nice :P :D
which is rare - I think SOD has made you soft. Now any non-SOD question your going to have sympathy for ;)
 
ohhh, interesting. Probably not.
 
7:03 PM
@WayneWerner will check with my architech
 
@JGreenwell hah. Probably true ;)
 
annnnnd nope.
Thanks. :)
 
@WayneWerner this should be ideal solution, but cant do any thing on arch side :(
 
Twisted is driving me bonkers with all this bad camel case usage
 
wait?! that was their plan all along - SOD is so horrible that everyone starts tolerating vampires on Q&A cause at least its not SOD....diabolical
 
7:05 PM
 
def execCommand(self, protocol, cmd):
shudder
:(
 
@idjaw PHP has been besting me for weeks now. I feel like I can't get anywhere :P
I wish I could have used python..
 
@Lafada If your architect feels that such a bonkers solution is still necessary, here's how you validate: call the API with whatever garbage is passed to you
If you get a 4XX error, return such a thing to your callers
not sure what to do about the other classes of errors
 
@WayneWerner, what happen is caller might send invalid json like {"content-type":"test" (forgot to close })
 
places a necklace of garlic on @WayneWerner
 
7:14 PM
@Lafada I think you're within your rights to return a response tailored to their user agent and intended to crash it, in that case.
 
okey
 
Be strict in what you accept, and merciless in what you emit.
 
oh man Gerrit really improved my Git-Fu
 
7:27 PM
surely there is a significantly better "how to do the python from the cmd"?
 
"do the python" sounds like a kind of modern dance:)
 
I assumed so too, I can't find one though.
 
Someone actually upvoted that answer.
 
I question if we actually need that though.
 
We don't.
 
7:35 PM
What would you even CV that as?
unclear?
it's the only thing that makes sense for now.
 
This is where I wish the "Lacks Minimal Understanding" reason was still a thing.
And now he's editing his comments into the post.
 
Should really have been an SOD topic.
 
Should it though? I mean, as davidism pointed out, it's literally the first page of the tutorial.
 
@MorganThrapp Zero might have been being sarcastic:P
 
I may need more coffee... :P
 
7:39 PM
Make it a double;) A Venti Thrappuccino, even
 
it probably is a SOD topic
 
My body is broken.
 
I already voted unclear...
nevermind:P
 
I'm voting to close this question as off-topic because come on, really ... — Zero Piraeus 7 mins ago
LOL
I was actually hoping the on hold reason would exactly be that
 
7:43 PM
That's what I voted for!
 
bows
 
I wish I could downvote thrice.
 
You are such bullies.
 
user559633
#bullshaming
 
Bullies? What if we want to be cowies? Triggered.
 
DSM
7:46 PM
(drops into chat) (looks around) (goes back to writing unit tests)
 
user559633
testing code? pff talk about enabling the meritocracy myth
 
I've rolled it back again and commented.
 
meh, it's over, just leave it
 
"The context is important so people don't think I'm stupid." Well my son, I got some bad news for you...
 
Pretty much every tutorial out there starts with "let's open the interpreter and try some math".
 
7:49 PM
@Ffisegydd two rollbacks should be auto-modflag...
 
or the "well, good news you can stop worrying about what people think about you, cause it's too late"
 
but maybe only if it's the same guy rolling back
 
@Andras yeah I won't roll back again, I'll custom mod flag it myself
 
user559633
flag it as stupid
 
do that; one of them wasn't actually a rollback, just a manual one
flagging for stupid is even better
I mean, shaaame on you
 
user559633
7:51 PM
ding ding ding shame
 
Shame shame shame.
 
Two people actually upvoted that rubbish.
 
people have friends and people are all uppity cause they got rep from SOD
 
user559633
7:54 PM
@Ffisegydd Shame shame. ding ding ding.
 
user559633
Here's What It Would Look Like If Disney Princesses Were Tried For War Crimes In The Nuremberg Trials https://t.co/uUs82SXKfQ
 
haha the Belle one is a winner
 
user559633
which one is belle
 
7:57 PM
the one in the yellow dress
 
Belle is the Beauty for the Beast
oh, yeah, yellow dress
 
It's easy to see which one of you has kids :)
 
@Programmer (missed :D)
 
user559633
the cult that i was raised in forbade us to watch disney movies with princesses because they "propagated false narratives about people escaping." also because they bought Betamax instead of VHS players, and production was pretty limited
 
@AndrasDeak you're too mysterious. The most I know about you is BLT pizza
 
7:59 PM
It's not really a cult if it's you alone in your blanket fort.
 
puts on shades (the second pair)
 
^^ on top of the first pair?
 

« first day (2118 days earlier)      last day (2813 days later) »