« first day (1638 days earlier)      last day (3314 days later) » 

12:21 AM
question: considering a meta question on whether one should delete their answer when an update to the OP's question invalidates their answer?
I found a wiki entry somewhat about this but, to me, it doesn't seem to address the specific case I meantioned
should I ask or just consider it a minor variation of the wiki and forget it
I've had this happen to me once (didn't delete) and just saw where someone else deleted their answer after he was advised to in a comment but to me the answer was related enough that it could provide value to someone searching for the same issue...and made me think of this question
 
1:09 AM
@JGreenwell I think those situations are usually just treated on a case by case basis. A lot depends on how long OP had the original question up before the massive edit, whether their new question is a clarification of what they were attempting to ask before and it happens to invalidate your answer, etc.
 
@DonkeyKong eh, I think I'm just going to do some research on it when I get the chance (get me a chance to look at analysis on/with SO) and then look back at it and see whether it is worth a meta post
 
@JGreenwell Fair enough. My guess, if you post it on Meta and don't get duped, is that your response will be something like- If they completely defaced the post to an unrelated question, that is bad, that is their fault. If they clarified what they meant, and in the process of doing so invalidated someone else's answer, it is up to the answer-er of that question to decide whether their answer still provides any value.
@JGreenwell ... cont Should they feel it doesn't and delete it, and you then feel that their answer still to some degree addresses the question, you can always add your own answer, or make a community-wiki answer.
 
1:44 AM
@DonkeyKong yeah, at this point I'm curious on how often this happens and if a wiki answer (or addition to the wiki entry I referenced earlier) would be helpful. Mostly at this point its a way for me to get some more experience with some analytic work which is just helpful for my own education (and maybe I find some interesting statistics to share if nothing else)
anyway rbrb, and enjoy your night
 
@JGreenwell You too :)
 
 
1 hour later…
3:06 AM
s = str(n)
l = len(s)
for n in (n for n in range(1, l + 1) if l % n == 0):
ints = map(int, map(lambda x: ''.join(x), zip(*[iter(s)]*n)))
if sum(ints) == 100:
Can someone please simplify this code for me so that I can understand it
lines 3 and 4, I have no idea what's going on
 
3:19 AM
workflow question. I'm forking and pulling a remote git repo. I made a pretty large change and am not ready to merge it back into the main branch yet, but would like to submit a pull request to the upstream repo for the substantial work I've done so we can all work on it in the separate branch. Is there a way to submit a pull request to a new upstream branch?
@Roger I'm pretty number theory makes that code do nothing at all (in base 10). Is it actually for n in (n for n in range(1, l+1) if n % l == 0) ?
 
How do you post codes here?
 
@Roger ask a question? :)
actually that's not true. [n for n in range(1, len(str(n))+1) if len(str(n)) % n == 0] is exactly [1], as far as I can tell.
 
def f(n):
s = str(n)
l = len(s)
for n in (n for n in range(1, l + 1) if l % n == 0):
ints = map(int, map(lambda x: ''.join(x), zip(*[iter(s)]*n)))
if sum(ints) == 100:
return True
return False
that's the whole code, I don't know how to post it here with the indentation
 
ctrl+k before you post it.
and I'm pretty sure that function is equivalent to:
def f(*args):
    return False
:)
 
nah
it's true for f(5050) and f(25252525) and a few more
 
3:30 AM
really?
 
yea
 
oh I'm getting confused by the silly single-character variable names
n is not n.
 
3:45 AM
@Roger here's a less terrible version of that code
 
RE: my earlier message I guess I'm asking: what's the best way to pull request a feature branch into upstream, without forcing it to merge with master?
cbg @AnttiHaapala
 
fetch...
pull means: fetch and merge into current branch
that's what it means
well, if you'd go see any git manual ...
Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.
 
Either I'm having an airheaded moment, or I haven't explained it well.
I've forked an upstream remote, done git checkout -b feature_branch, made several commits, and want to push it BACK to an (as-yet) non-existent branch of upstream
 
ah
now I read it correctly :P
above you asked for pull request
 
3:55 AM
Well I don't have push access to upstream
so any merge I do has to be a PR
 
then why do you say "push" above
every single sentence you add just makes me more confused
 
because I'm mixing my terminology LOL
 
sorry
 
are you talking about github
 
3:56 AM
Well github is the remote of choice, yes.
 
or are you talking about git request-pull that is text only
Generate a request asking your upstream project to pull changes into their tree. The request, printed to the standard output, summarizes the changes and indicates from where they can be pulled.
I am not sure if this works like this in github
 
Either way I don't see an option to create a PR to a new (to upstream) branch
a quick google shows that it can't be done without having push access to upstream in order to create the branch. That seems dumb.
I feel like that would be a fairly common use case. Fork a repo, add a feature branch, and PR to upstream without merging the branch
(rbrb, getting my daughter to bed)
 
github is borken
with git it is possible to do such a pull request
see this, perfectly allows you to specify any remote branch, so might as well be a new one
 
@AdamSmith GitHub's workflow is that you need to press the fork button to create your own remote, and push it it there.
Their UI lets you send PRs between forks of the same repo.
(Pardon if I'm misunderstanding the question.)
 
@JeremyBanks but it only allows you to create a PR to an existing upstream branch
@AnttiHaapala from "If you pushed your change to a branch whose name is different from the one you have locally" (emphasis mine) I think it's talking about YOUR remote branch, not your UPSTREAM's remote branch
 
4:12 AM
@AdamSmith Ahh, that's true. I guess that isn't something that they think needs to be done in their encouraged workflow, but I can see why it could be useful for projects operated in certain ways.
I think people generally just upload their dev branches to their own remote, and expect others to pull from there if they'd like to work off of it, before it gets pulled into the official one.
 
4:31 AM
Cbg
 
5:19 AM
@AdamSmith just make a pr and comment that you want it to be a new branch :D
I am not sure about that either, if it is possible to change the target...
@AdamSmith the document I linked is about GIT
you asked about GIT... well, github is not git.
whether you can push somewhere or not is orthogonal to whether that something is upstream or not and both of them are orthogonal to whether or not it is your repository.
so you have a 3-dimensional space there :D
 
cbg Jon
 
5:37 AM
@Antti wat? I thought we had to be in 37 dimensional space to even exist? :p
 
5:47 AM
@AnttiHaapala I was referring to git in my reply :P
 
6:05 AM
Grr, didn't get 30 points thanks to the rep cap
 
6:36 AM
hmmhm
 
Hey guys
 
Haha
 
okie :P
needed to move the message back to kick him
while there is a room in this room for off-topic discussions, I do not think anyone wants to be forced to read his monologues...
 
hmm
my hammer didn't work!
 
The tag was added after the question was posted
 
I know
 
7:06 AM
@Antti feel free to add anything to the trello board
 
7:46 AM
@JonClements sorry had breakfast :D
@JonClements done
 
8:50 AM
Hey guys, I'm doing a python tutorial and I've been stuck on this exercise for ages postimg.org/image/4t4dxy6hl Can someone please give me some hints as to how you would go about doing this
 
547
Q: How do you split a list into evenly sized chunks in Python?

jespernI have a list of arbitrary length, and I need to split it up into equal size chunks and operate on it. There are some obvious ways to do this, like keeping a counter and two lists, and when the second list fills up, add it to the first list and empty the second list for the next round of data, bu...

@Roger your hint ^
 
Thanks
 
Convert your integer to string, split the resulting string into chunks of sizes from range(1, len(string) + 1)
 
9:10 AM
So, once again, we find ourselves in an election.
 
The codes used are a little advanced for me. Most of them have functions the tutorial is yet to have introduced
Is there a simpler way to split the string into chunks
 
I'd say that stackoverflow.com/a/1751478/2301450 is the simplest of all
 
[l[i:i + n] for i in range(0, len(l), n)]
l[i:i + n]
I don't understand that part ^
 
667
Q: Explain Python's slice notation

SimonDo you have a good explanation (with references) on Python's slice notation? To me, this notation needs a bit of picking up. It looks extremely powerful, but I haven't quite got my head around it and am looking for a good guide.

 
ohhhhhhhhhhhh that's slicing
 
9:22 AM
@Roger solved yet?
 
nah, still trying
 
@Roger actually you need to see if the i completely subdivides the number
it is a bit like
95
Q: How can I tell if a string repeats itself in Python?

JohnI'm looking for a way to test whether or not a given string repeats itself for the entire string or not. Examples: [ '0045662100456621004566210045662100456621', # '00456621' '0072992700729927007299270072992700729927', # '00729927' '001443001443001443001443001...

this one (though not at all)
@Roger there is 1 thing that is not clear from the exercise
is 8809 ok that there are "2 two-digit numbers" 88 and 09
 
not sure to be honest
the part where testing both 1+2+3+4 and 12+34 is required for is_square_sum(1234) is what I can't seem to figure out how to do
 
Hello! What tools do you use for testing python code?
 
@QueueOverflow it depends - simple scripts I use doctest, anything more complex usually py.test
 
9:30 AM
You guys should seriously start using behave or lettuce. Will save you a lot of time when you don't understand why your tests are failing.
 
@Roger so if you have a 6 digit number, it could be divided into 1, 2 and 3 digit numbers
 
yes that's right @AnttiHaapala
 
@Roger for general case: loop in range(1, length // 2 + 1)
then test if that length divides the length of the number
 
@jonrsharpe Thanks, I will look at py.test. Do you use Nose or other frameworks with doctest?
 
@Roger the key is "any"
 
9:32 AM
Cbg :)
 
@QueueOverflow no, if it's complex enough for that I don't use doctest
 
@Roger solved
 
@AnttiHaapala what do you mean by "then test if that length divides the length of the number"
 
@jonrsharpe I has understood you. Thanks.
 
@Roger so you'd go all the possible values of i
if n % i != 0, then you cannot divide n digits into k numbers of length of i
and you discard that i
 
9:36 AM
@khajvah Consider the option that Malik is just happy to be back online! Or that his eye surgery worked out well after the eye-patches have been removed. — sehe 47 mins ago
Hehe
 
you can do this 2 ways: either think of the numbers as strings, or numbers as numbers... either one works. in the first way you'd do splicing, in the second one you'd divide and calculate remainders with 10**i
 
sorry lol, im still lost. Only been doing python for 2 weeks now
 
@Roger describe me the algorithm in English :D
 
huh?
 
Most of the times people prefer simpler/easy to read solutions than Pythonic ones :(
 
9:44 AM
I mean how'd you want to write it in python
 
def is_square_sum(num):
    string = str(num)
    for digits in range(1, len(string)//2 + 1):
 
yes, that's a start :D
 
@AnttiHaapala You got a hawk eye. I couldn't spot that mistake though I looked at that code for five minutes :'(
 
digits there is i now you'd need to use another for and slice to split the string into
@thefourtheye I looked for a mistake :D
 
You are too good man, take it :D
 
9:48 AM
@thefourtheye you could make your answer better by noting that maybe it'd be faster if the dictionary values would be sets to begin with ;)
 
You are right. OP mentions that and files are the set of files that contain
 
also, do not use tuple assignment, that's ugly :d
I would never use it in a case where the , goes to a second line :)
 
Oh sure. I ll edit that as well.
 
for digits in string[0:len(string)//2 +1]:
@AnttiHaapala , is this how the 2nd loop should look like?
oh wait, no that's impossible
 
for j in range(0, len(string), i):
 
10:04 AM
Should i flag for migration in MSO? stackoverflow.com/review/triage/7651010
 
@thefourtheye mhmh
@thefourtheye actually, if the word is not found,
you want to return an empty set
so you'd use get(word, frozenset())
 
But I have if word in d check, right?
 
yes and it is possibly wrong
 
Antti how you get soo good at python
 
if this contains all the words and files :D
 
10:07 AM
if I return an empty set, intersection will be empty
 
yes
so: give me all of files that have 'banana', 'apple' AND 'asdfasdfioajsfgkewrutjwekrng,mxvnbsx,fmbnsdjfgsdlkfcxvm,nsdf,mgsndfgkjsdfhgsdlk‌​fn cv,m'
 
Ah, I see what you are saying now.
 
what should the result be?
possibly ;)
@Roger 15 yrs
 
:O awesome
 
Lets say if only banana is there and apple is not there in the dictionary, then the result should be empty. That's what you are saying, right?
 
10:08 AM
I have been paid for 10 years for getting better in python
@thefourtheye exactly
if that is the whole match there
 
Cool, editing the answer now.
 
and if you had asked that in comments etc...
then the other would not have had that accept :D
 
Hmmm, my bad :( I should understand the question completely
 
Folks, I've made a little anagram finder, do you think, you can make it better? gist.github.com/anonymous/49a8967c17c8361008cf
i.e. more pythonic?
 
@thefourtheye it is not being said in the quesiton
that is why you sohuld ask in the comments :d
 
10:14 AM
Yup, updated the answer now. I am going to leave a comment to the OP now.
 
@GamesBrainiac use defaultdict(list)
(of course)
@GamesBrainiac hmm why ordereddict, does it matter?
 
@AnttiHaapala the result must be ordered in the same way the world list came in
yup ;)
 
cbg
 
I was thinking of making DefaultOrderedDict but then stopped myself :P
 
hash_dict.setdefault(c, []).append(word)
 
10:16 AM
@AnttiHaapala But yea, you're right on the money, default dict would be much simpler.
 
@AnttiHaapala: Indentation Error in that edit to stackoverflow.com/questions/29576337/…
 
        c = hash_word(word)

        if c not in hash_dict:
            hash_dict[c] = []

        hash_dict[c].append(word)
can be written as
hash_dict.setdefault(hash_word(word), []).append(word)
 
@thefourtheye but that would add multiple values to the mix
@thefourtheye You're right. I should've thought of setdefault :P
 
Try if it works fine :)
 
it seems to be working fine
 
10:19 AM
Also
hash_word = lambda w: "".join(sorted(list(w)))
doesn't need the list I guess
 
@GamesBrainiac
from collections import OrderedDict

class OrderedDefaultDict(OrderedDict):
    def __init__(self, factory, *a, **kw):
        self._factory = factory
        super().__init__(*a, **kw)

    def __missing__(self, key):
        value = self[key] = self._factory()
        return value
:P
yeah, and it does not indeed need to be a list
so just ''.join(sorted(w))
with hash_dict being OrderedDefaultDict(list), you can do:
hash_dict[c].append(word) right away
 
Yea, but setdefault already does that for me.
No need to create class that takes in a factory as well.
 
@GamesBrainiac @thefourtheye Java 8 is more powerful than python here...
 
It has OrderedDefaultDict?
 
no
Map has computeIfAbsent
 
10:22 AM
@thefourtheye Thats a keeper!
 
that takes a lambda function :P
 
@AnttiHaapala now thats useful
 
Antti, I repeat: you screwed up the indentation in the edit you made to stackoverflow.com/questions/29576337/…
 
@AnttiHaapala Ah, I wonder why Python didn't choose to do that.
 
@PM2Ring didn't see that
 
10:24 AM
@thefourtheye I've changed my mind on JS. ES6 is looking rather good.
 
@thefourtheye because guido hates, utterly loathes functional programming
wanted to kill lambda too
 
@GamesBrainiac Yup, I am slowing learning it and loving it :D
 
But ES5 should die a quick death man. I absolutely hate it. No friggin generators!
 
@GamesBrainiac there are shims and compilers to ES5
who cares
 
@AnttiHaapala I think he started learning pure FP 6 or 7 years back. I may be wrong
 
10:25 AM
"lambda should die" was on the agenda for python 3 at least,
 
@AnttiHaapala Thats why I use typescript for most things, but with ES6 no more transpiling.
 
I'm not a big fan of FP, but lambda doesn't imply FP, IMHO. Lambdas can be very handy for non-FP things like GUI callbacks.
@AnttiHaapala Does he hate FP, period? Or does he just want to discourage people doing it in Python because it conflicts with "There should be one-- and preferably only one --obvious way to do it."
 
@PM2Ring has said that "recursion is not a way to do things, that's why the python has low limits"...
and said that "reduce I hated the most" of the ~unholy triangle
any is a good idea, so is all, reduce can be put into functools, I do not care too much about having an import but
dropping altogether, hey c'mon
 
@AnttiHaapala I'm still stuck and I think I'm just gonna give up. Can you please show me how to do such a question? or just a start after the looping
 
@AnttiHaapala Yeah, I've read that before. I suppose I see his point about reduce, but I don't fully agree. OTOH, I guess it can impede code readability, especially if you use reduce with a non-trivial function argument.
As for recursion, it'd be nice if Python had tail-call optimization. OTOH, I fully endorse discouraging people from using recursion when simple looping is adequate - IMHO, recursion should be reserved for things like tree traversal which are a PITA to do non-recursively.
 
10:45 AM
@Roger
        the_sum = sum(int(s[j:j + i]) ** 2 for j in range(0, length, i))
        if the_sum == number:
            return True
@PM2Ring TCO means that a simple loop would do
but the problem is that python recursion is limited by C recursion limits
 
Isn't this question more suitable for MSO? stackoverflow.com/questions/29576511/…
 
maybe or maybe not...
 
@AnttiHaapala Yes, I realize that TCO converts tail call recursion into a simple loop. AFAIK, C has no recursion limits, per se, but it does impact on your stack (when not optimized away. I suppose that implementing TCO in a dynamic interpreted language like Python could be a little trickier than implementing it in a compiled language, but to be honest I haven't thought deeply on this particular topic.
 
Hey up
 
cbg :)
 
10:54 AM
Re-cbg
 
When trying to look at a webpage with python code in it, it only shows me stuff like "{% for s in sections %}" and not the actual html code. Why?
 
@Ffisegydd ...
 
I'm using MAMP which is suppose to include Python
 
I looked at and I was horrified
@simpe PHP not Python
 
@AnttiHaapala whistles innocently
 
10:59 AM
@simpe Templates are not Python code; the template engine may be coded in Python and support a lot of Python(-like) constructs, but a template is not itself Python code.
The idea is that templates are used for presentation only, really. Leave business logic to Python code, then pass the data to the template to render HTML.
 
How much logic should be in templates is often a highly debated topic.
Some engines support very little (Django), some moderate amounts (Jinja) and some (Mako) can pretty much replace psp :P
 
Sup @Games. You ready for your talk?
 
Never seen PHP like this before.. I assumed it was python as the content is stored in .py files.
 
@Ffisegydd No, got my Canadian Visa application rejected. Visa office's exact words, "We think you might not come back"
 
F**ks sake. Sorry mate.
 
11:03 AM
Yea, total bummer.
 
@MartijnPieters python questions are awful now
 
@AnttiHaapala I just don't answer them anymore.
 
@Games is there anything else you could do with the prepared talk at least? Maybe find a meetup locally. Would be a shame to waste the prep.
 
I want rep
I am worrying about the future of python
@GamesBrainiac ORLY?
 
@Ffisegydd I got the response from the Singapore HC quite early, so I didn't even have time to prepare my talk anymore :P
@AnttiHaapala Yea. Just pycharm these days.
 
11:05 AM
@GamesBrainiac Singapore HC?
 
@GamesBrainiac they denied your visa...
 
@Ffisegydd They don't issue Canadian Visas in Bangladesh anymore, so if you want a Visa, you go to an agent, they send your Visa to Singapore, where it is processed and then sent back to you.
 
Oh I see.
 
@AnttiHaapala They did. They asked me a lot of weird questions too, "Are you associated with any terrorist organizations, have you ever incited violence, have you killed someone, have you been in jail"
 
that sound like teh suck
 
11:08 AM
I nearly laughed at one point XD
 
canada sounds a lot like murica already
 
They're kicking out recent foreign university grads too, not allowing them to apply to citizenship
Dunno why they've become so hostile all of a sudden.
 
lol
in finland we have free tuition and the problem is that the graduates won't stay
 
because, if they're good, why would they suffer from cold if they're from tropical countries
they stay only if they have social reasons, spouses or SOs and so...
loool
nokia is selling its maps division
 
11:11 AM
thanks so much Antti
 
they paid 5 billion for it
and then they sold the mobile phones for 5 billion for microsoft, now I guess they're selling maps for 5 bucks :D
 
cbg @Games!
 
@JonClements Heya!
Ready to duke it out in the elections?
 
@RobertGrant How ya been?
 
11:14 AM
Good thanks, wife's 30th went well yesterday :)
Going to do a bit more Pyramid now
 
@RobertGrant Thats pretty awesome! What did you get her?
 
Mostly, I'm buying breakfast at a fancy place for 40 people next week :)
 
Just clothes, vouchers, nice makeup, that sort of thing
 
hahahahaha
You're a pretty awesome guy Rob! :P
 
11:16 AM
@AnttiHaapala I dv'ed that stopwatch OP for not fixing their question after repeated requests. I was tempted to dv when I first saw it because I hate questions that begin with "So". :) I wouldn't really dv a question just for that, but I almost did the other day when I saw one beginning with "so" (with no capitalization), so it looked like a sentence with the beginning chopped off.
 
Haha thanks
@AnttiHaapala I'm going to try deform again now
 
@RobertGrant try without it at first :D
if you can
 
I did, and it's annoying :)
 
for a simple form
haha :d
 
Yeah I did a complete list/create/update "manually".
Actually what I might do before deform is combine the create and update stuff into one thing
does that
 
11:21 AM
@PM2Ring: removing so and other noise is easy enough. Is there a decent question left after removing that? If not, downvote for that reason.
 
cbg
what is OP?
 
@MartijnPieters yeah, usually it is that the so is the tip of the ijsberg that soon follows.
 
@tilaprimera Original Poster.
The author of the question.
38
A: What is an OP when referring to Stack Exchange?

Martijn PietersOP stands for Original Poster. It is used to refer to the person asking the question, or sometimes, the author of the answer being commented on.

 
melons @MartijnPieters
 
@MartijnPieters It wasn't a great question, just typical newbie confusion. FWIW, here's the question. It had a minor indentation problem which the OP didn't fix, and they also refused to clarify in the question itself what their desired output was, although they eventually mentioned the desired output in a comment to Klaus D's answer.
I don't have a lot of time for OP's who won't fix their question (or even respond adequately to requests in comments) when it's clearly explained what they need to do.
 
11:26 AM
@PM2Ring That's all good reasons to downvote. :-)
And also to vote to close.
post is closed now.
 
Thanks
 
0
Q: Can Python host a websocket and interact with a serial port without blocking?

Bertus KrugerI am busy developing a Python system that uses web-sockets to send/received data from a serial port. For this to work I need to react to data from the serial port as it is received. Problem is to detect incoming data the serial port needs to queried continuously looking for incoming data. Most l...

how about this?
how to answer this question? "Can."
 
How on Earth is this valid Python? stackoverflow.com/a/29577343/4014959
@AnttiHaapala "I have looked at how NodeJS interact with serial ports and it seems much nicer. " That almost deserves a link to youtube.com/watch?v=bzkRVzciAZg :)
 
hmm I haven't heard that video
I was going to say "I haven't seen that video" :D
 
11:43 AM
My SQLAlchemy model has a string and a float in it, and when I made a new instance of it to pass to a template, it sets the string and float to None. Makes sense.
 
@PM2Ring That's someone answering generic regex questions rather than tailor it to Python specifically.
 
But when I set the string to '' and the float to 0.0, the string works, but the float still says None.
 
And doing it badly.
 
Any ideas why the float wouldn't change?
Other than a simple typographical error
(Sorry)
 
@RobertGrant that does not make sesnse, though mybets are on the simple typographical error
 
11:47 AM
@MartijnPieters Yes. FWIW, René originally said that the g was for greedy, hence my comment, but has since edited their answer.
 
@PM2Ring I think they referred to the + in the expression.
The g there is a distraction.
 
René's + is fine, but the OP has + inside a [^ ] set.
 
Maybe you might know how to help? @AlexGolubenko — marriedjane875 13 hours ago
How would you flag that comment? I'm thinking either "not constructive", or custom "It is inappropriate to ping individual users for hlep"
 
@WayneConrad the user isn't pinged unless they actually interacted with that post.
It is just noise at this point.
 
Ah. I didn't know that. I had a HV ping me that way once, but it was on one of my answers.
 
11:55 AM
Hard to pick a flag in that case; I just picked too chatty.
 
That sounds as good as anything. Thanks.
 

« first day (1638 days earlier)      last day (3314 days later) »