« first day (2792 days earlier)      last day (2160 days later) » 
01:00 - 17:0017:00 - 00:00

5:00 PM
Hi Guys. What can I do if I am iterating through XML tags, and some tags happen and some do not. Explicitly: Some people have Titles and some not. When I first iterate through the title tag, then people without titles are no longer iterated. What can I do?
 
@roganjosh It would be a little mean if I didn't ;) but you were right. The content did meet up to expectations.
 
                for amkilet in child2:
                        for titel in amkilet.findall("PERSON_TITEL"):
                            for vorname in amkilet.findall("VORNAME"):
                                for nachname in amkilet.findall("NACHNAME"):
 
I see modules with # -*- coding: utf-8 -*- at the top? What benefit does this provide?
 
danke
 
5:04 PM
mostly concerns string literals as I understand
 
is it still relevant in a Python 3 only world (my world)
 
I think so. What if I write a .py file that contains string literals with latin2 encoding?
 
I don't think it's relevant in python 3. Why would you care how your strings are encoded?
 
@piRSquared Is this helpful?
 
Also note that Spyder throws it into a new file by default, so whether or not it has any use, it could be that people just don't delete the auto-generated text
 
5:18 PM
@roganjosh yeah, I have it from a cookiecutter and debating if I should remove it.
thx @Simon that's the same info (basically) that @AndrasDeak shared.
 
@piRSquared I delete it always and yet to see a problem, in Python 3.6
 
good to know
 
That's not a definitive answer either way though sorry :P
 
I suspect utf8 is the default
 
If you mean for the interpreter, yes it is. "By default, Python source files are treated as encoded in UTF-8"
 
5:22 PM
so in principle this is only crucial if you use something else
I've also seen some hacky library (ab)use that encoding. I think it was about backporting f-strings
 
Hi, I think my question is too small to qualify for a real SO question so maybe I can find help here? Highly appreciated :-)
What is the most pythonic way to interleave a list of strings with a fixed string BUT unlike join also after the last element?

``fooString.join(myList) + fooString`` gives an unexpected result for empty lists. I also tried ``zip()`` but it gets quite lengthy with the itertools and the flattening: ``''.join(itertools.chain.from_iterable(zip(myList, itertools.repeat(fooString, len(myList)))))``
 
@PhilLab Welcome! Please see this for formatting code in chat
What do you want to end up with?
 
@AndrasDeak Yes. So if you have non-ASCII chars in your source, and you don't save the file as UTF-8, and it doesn't have a coding directive, odd things can happen.
 
Is there any reason to prefer jupyter-notebook as a shell command over python -m notebook?
 
I probably don't find that encoding header too weird because I'm used to latex where inputenc is an important thing
 
5:26 PM
(aside from tabbed completion and the fact that you know what Python you're launching your module with...)
 
Mostly the former I think. I prefer ipython to python3.6 -m IPython
 
@AndrasDeak ok, got it :-) I am only a beginner in python and what I already know is that a) there are stunningly short solutions for seemingly complex problems b) it is quite hard to find these short solutions if you lack experience. So I was hoping/thinking I overlooked a function which does the job with less amount of code
 
wim
one uses the shebang, one uses the $PATH
 
jupyter-notebook (at least on my system), as I just looked at it hard-codes the python with a shebang (installed from anaconda.)
 
wim
so they are slightly different in meaning and can refer to a different env
 
5:28 PM
@AndrasDeak A cute thing you can do with the coding directive in Python 2 is to set the encoding to rot13. :)
 
@PhilLab yeah, but you didn't explain what you want to happen with what inputs.
 
wim
the shebang is munged at install time
 
I'm not entirely sure what that jupyter-notebook script is actually doing with the re.sub thing
 
wim
this is how people get themselves into crappy situations by doing sudo pip install, btw.
 
from notebook.notebookapp import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
 
wim
5:29 PM
that's not jupyter. that's setuptools.
 
setuptools autowrites that?
 
wim
yes, that's what a generated setuptools entry_points:console_scripts looks like
sounds like I really need to write that packaging canonical :-\
 
@PM2Ring Seriously...?
 
? oh, Q&A?
Yeah, go for it. We need more & better canonical Q&A...
 
@PhilLab The comment from Andras was simply to help you format your code correctly in chat. It's just a bit hard to read without the code being formatted. We're more than happy to try help you solve the actual programming problem.
 
5:32 PM
@wim I've been neck deep in figuring this stuff out. You'd have a bounty waiting for you. Seriously, I'd love to see a good one put up.
 
@piRSquared Sure! Of course, everything after the coding directive has to be rot13'ed for the script to run. And it won't work in Python 3.
 
@roganjosh Yes, I understood but I can't change the message anymore. Maybe I clarify and repost
 
Yes. A 3-length myList and a simple fooString should suffice for an MCVE
 
@PM2Ring boo! no Python3.
 
@AndrasDeak I hope I get the formatting right now. @piRSquared but I like Python3 :-D
Example:

    fooString = ":myGradleTask "
    myList = ["lib", "app", "something"]
    result = .... let there be magic here ...
    assert(result == "lib:myGradleTask app:myGradleTask something:myGradleTask ")
 
5:35 PM
@PhilLab Ah. I'd use zip(myList,itertools.cycle([fooString]))
 
If it gives unexpected results with empty lists, why not just use:
    if myList:
        #do stuff
 
wim
the current state of the packaging world is actually not terrible! but people still do it wrong, because of all the old advice floating around on the internet and the lack of a good modern guide.
 
Oh formatting is just awful in chat
 
@wim come on, stop being a tease and write it :P
 
@wim do you need me to walk you through the motivation? Listen while you convince yourself? Or are just going to do the needful?
 
5:37 PM
@PhilLab or a genexp: ' '.join(elem+fooString for elem in myList)
 
Actually, yes, please do the needful because I was reading around this recently and concerned that the guides were years out of date
 
yeah, I'd probably do the latter
Do you really want to have the traling space?
 
Hi Guys. What can I do if I am iterating through XML tags, and some tags happen and some do not. Explicitly: Some people have Titles and some not. When I first iterate through the title tag, then people without titles are no longer iterated. What can I do?
                for amkilet in child2:
                        for titel in amkilet.findall("PERSON_TITEL"):
                            for vorname in amkilet.findall("VORNAME"):
                                for nachname in amkilet.findall("NACHNAME"):
 
@AndrasDeak No, the trailing space is not needed, the genexp works marvelously. I didn't see that they would fit the use case but they do and it is quite simple. Thank you!
 
no problem
 
5:41 PM
@PhilLab I'd use .join, and do an explicit test to handle the empty list case.
 
@PM2Ring and @roganjosh Also valid, you are right. But the genexp allows me to have a shorter one-liner
 
Well that shouldn't be a goal
You should aim for readability, not the ability to pack everything into one line
Don't get drunk on Python :P
 
@PhilLab On a related note, you can pass a string to .join, e.g., '-'.join('abc'). And there's a hacky trick t
@PhilLab On a related note, you can pass a string to .join, e.g., '-'.join('abc'). And there's a hacky trick using .replace
 
@PM2Ring having connectivity issues? :)
 
s='abc'; s = s.replace('', '-')
 
5:48 PM
What is a canonical exactly?
 
@Simon an authoritative (question and) answer in a subject that comes up a lot
 
@AndrasDeak No, I'm still getting used to this keyboard.
 
ah!
 
I see. Thank you @AndrasDeak
 
often in the form of a self-answered Q&A
rbrb for a while
 
5:50 PM
Rbrb AndrasDeak :)
 
canon: a general law, rule, principle, or criterion by which something is judged.
"the appointment violated the canons of fair play and equal opportunity"
synonyms: principle, rule, law, tenet, precept; More
 
I have no idea why I got that double post when I did that edit, but it has happened on this new phone a couple of times.
 
Can you tag people from your phone?
If I use the web browser, I can't use @ tagging, tested across two android phones
 
wim
@piRSquared I'll do the needfuls, it's just an awkward time because I'm about to go on vacation for a week
gotta make sure nothing catches on fire at work while am out
 
@madik_atma Why are those .findall calls nested? I don't understand why you're even using the 3 inner for loops. People normally have 0 or 1 title, 1 first name, and 1 last name.
@roganjosh In chat I can do @ tagging, with auto-completion, but not in comments.
 
6:02 PM
@roganjosh "Don't get drunk on Python " that pretty much hits the nail on the head :-D
 
@wim I'd actually appreciate a ping in chat once you've done it (I'm aware it's somewhere on the horizon and vacation is paramount priority but I'm registering my interest :) )
@PM2Ring Yeah, it just doesn't work for comments. It's frustrating actually.
 
@PM2Ring what you suggest in this case?
 
Very. Earlier tonight I had to copy a username in as a link and edit it down because I couldn't tell if their name had uppercase I or lowercase l.
 
@PhilLab :) Getting drunk and writing in Python is still fine though. If you can get an IDE with iPython it's really easy to use %timeit to test the speed of code, and you'll be surprised at the proportion of clever-looking one-liners perform awfully against the blatantly obvious approach.
 
@madik_atma Do each of those .findall calls always return a list containing 0 or 1 items?
@PhilLab Yes, it's a little shorter, but I bet it's quite a bit slower, and probably consumes more RAM although that's probably irrelevant unless you list is huge, or you're doing that join operation in a loop.
You can use a conditional to make it a one-liner:
out = sep.join(lst) if lst else ''
with whatever you like in the else part.
 
wim
6:22 PM
in other news, a CPython PR of mine got merged this morning, seems it made it just in the nick of time for 3.7.0 release candidate.
11
 
@PM2Ring its returns <class 'xml.etree.ElementTree.Element'> every loop
 
@PM2Ring sometimes happens to me too on mobile
I've seen it happen once when I clicked twice on the edit icon, so perhaps the other times are when a single click registers as a double. Or you know, invalid anecdotal evidence
 
@PM2Ring even in cases I am pretty sure I got the characters correct, I'm pretty sure they won't get notified anyway
 
@roganjosh that definitely can't be the case
 
@AndrasDeak try it on one of my questions and we'll find out. AndrasDeak should work, yes?
 
6:35 PM
yes, but I'm not sure I've ever commented on your questions
 
No, but you can now
 
left a comment here
 
And you have, you've even answered one of my questions :P
 
oh, how nice of me :D
got a notification
 
hmmm ok
Maybe I've had a go at putting together the username and not got the special characters right (looking at you, coldspeed)
 
6:38 PM
that's much more likely
 
And if you're interested, this is what you answered: stackoverflow.com/questions/40917805/… :)
 
oh, that was a while back, no wonder I don't remember
wow, I do not remember that answer
 
Haha. I was a baby in numpy then. I might have progressed to toddler at this point.
 
@madik_atma Really? I thought the .findall method returns a list of matching elements, but I haven't used that module very much; I don't do much XML parsing.
 
@PM2Ring maybe that what you say can be true, because I am not good in this area. Dont trust me pls. :D
 
6:53 PM
@madik_atma So immediately after for amkilet in child2: you should make those 3 .findall calls (without using more for loops), then extract the data you need from each list using simple indexing. If a list can be empty, like the title list, then you need to test for that, since it's an error to index into an empty list.
 
so... I need to pass IPython an --arg=... from jupyter notebook - preferably through the commandline - any suggestions?
(It's not an argument for a notebook, it's an argument to the kernel that you get documented via python -m IPython --help-all)
 
@madik_atma E.g.., lst = amkilet.findall("PERSON_TITEL"); titel = lst[0].text if lst else ''
 
(see all arguments for the notebook similarly, with python -m notebook --help-all)
 
7:08 PM
@AaronHall what is the question exactly?
I prefer --matplotlib ;)
@wim congratulations! So next time I see weird behaviour in python I'll just blame you :P
 
@AndrasDeak python breaks all the time. "for loop doesn't work in python". "if doesn't work in python" and so forth. I'm surprised it hasn't brought planes down on our heads.
 
No, you're confusing it with pyhton
 
Gah, I always get tripped up by that :/
 
7:25 PM
Or maybe phyton. I think that's the language with if loops.
 
@AndrasDeak I was passing some exec_lines to IPython, now we're using the notebook under the new architecture, which really separates stuff - but I can't figure out how to pass the IPython arguments through from notebook... I know IPython still has a supporting interface, but I'm trying to use Jupyter in the same way, but failing because I can't pass exec_lines directly to Jupyter. I have to figure out how to make it pass the exec_lines for me.
I think I found an answer: github.com/jupyter/help/issues/189
 
OK, so you wanted to mimic passing those command-line args from a module
 
7:45 PM
Grr I've been up-voted by sockpupets again.
 
How do you know?
 
@Simon I've upvoted the other answer to your question
 
So? Do as you wish. I'm not holding grudges :)
 
If that's what you're on about. I honestly don't know what issue you're trying to plug.
 
@piRSquared
Now if I go on that question:
i.stack.imgur.com/5BbcX.png I've also lost two votes I had. Pretty obvious really.
 
7:50 PM
That's not a sock puppet
 
Sorry. If you could please correct my terminology I think it would be better for all.
 
It's possible that I could upvote two of your questions and then succumb to the banality of life and delete my account
 
So you are saying you can up-vote the same question twice?
 
Nothing in your screenshots suggests it's two votes on the same question to me?
 
sock puppeting is not the one single reason for which accounts can be deleted, I presume
 
7:55 PM
If a user deletes/is deleted, their upvotes will be removed across the board
 
Yeah I don't generally go around taking screenshots of all the up-votes I get, but trust me I had three on this question when I asked it.
 
That's not what I'm saying
I could upvote your question now (I won't because I don't understand its relevance as I expressed) and I could have upvoted one of your questions in the past. Then I cave in to SO and delete my account; both upvotes are removed at the same time.
 
@AndrasDeak Yeah, I think I need to find kernel.json from a Python shell (I don't have a jupyter executable) now...
So now I need to get the results of jupyter kernelspec list without having jupyter...
 
@Simon In other words, those upvotes that are being removed could be collected over any period of time from the same user. They just happen to be removed all at once :)
 
wim
>>> class Employee(NamedTuple):
...     name: str
...     id: int
...
>>> issubclass(Employee, NamedTuple)
False
fun - didn't noticed that until now (from here)
 
8:03 PM
FWIW, one of our regulars once lost a couple of hundred points in one hit. He was not impressed.
 
Yes but the score of the first theoretical up-vote will show as 1 for each post. In my case it shows as 3 (with one down-vote). If you had deleted your account then the up-votes from both posts would disappear. So the score for this question would go back down to 2 (and so would the other post). In my case it dropped down to +1/-1 so I lost two votes. @roganjosh
If you deleted you account the rep would go down for each post, and for the score to go down by 2 on the first post and the other post would lose the rep. In which case I would lose 15 rep not 10
 
foo. We don't have jupyter-kernelspec
 
@wim Hmmm. Not good. But I've only ever used namedtuple
 
The other possibility was that another user removed his up-vote at the same moment as the other account was deleted (I find that somehow unlikely). @roganjosh
Particularly as the question is 7hours old
 
... one user account cannot vote twice on the same question, so any explanation that depends on that is false.
 
8:08 PM
Yamming auto-correct. :(
 
which might support the original sock puppet idea.
 
^ phew. Yes impossible unless they have two accounts.
 
@Simon if you have an army of followers, can you subtly hint that my answers are awesome too?
But I don't actually understand the return on someone upvoting a random user's answer
 
That workaround was ugly, but I made it work.
 
inflation. the goal is to inject more points in the economy.
 
8:11 PM
@roganjosh Sure. As soon as I get around to finding a way to contact them :p
 
@FélixGagnon-Grenier oh god. In 5 years, 500 upvotes (I don't have that on anything) will be worthless?!
 
brace yourselves
 
@roganjosh Couldn't elaborate could you?
 
@Simon I don't think that I have random people following my activity and upvoting my answers (to apparently inflate the upvote economy) so if you have them, please direct them my way :)
 
Shh; I will, but don't let my secret be known.
 
8:20 PM
@roganjosh Camouflage. If a sock only upvotes one person's stuff, it looks pretty obvious. But anyway, I think we've had enough of this topic for the time being.
 
Agreed
 
has anyone heard of fully convolutional networks for semantic segmentation?
 
8:38 PM
I assume you know this article?
 
wim
@PM2Ring it's like that meme, yo dawg, we heard you like metaclasses so we put a metaclass in your metaclass so you can break OOP with your OOP ...
 
right right, i am aware of that article and FCNs in general.
I use them often, but I want to know if anyone has ever combined results from multiple neural networks.
Let's say I have two separate networks, each of them segments the same image but different objects.
How are the results of the two networks commonly combined? I want to do something more sophisticated than simply combining them.
 
@wim wow. They literally let any nonsense through if you call it a "meme"
 
8:58 PM
@Simon Yeah, that's annoying
 
I wish there was a sql equivalent to python's black
 
9:28 PM
pet peeve #12334654766345: people who add upper case "PYTHON" to their question titles
 
@coldspeed perhaps you should find bigger problems.
 
yes, the first 1233465476634 problems are bigger :P
 
When just viewing new questions, I thought that PYTHON was appended by the system to questions tagged as such
 
10:03 PM
???
 
10:24 PM
@coldspeed You can edit it out. ;) I'm amazed more low-rep users don't clean those up: it's 6 chars, so it's over the minimal edit limit. That sounds like an easy way to earn 2 points to me.
 
10:42 PM
Potentially too superficial for an edit suggestion
 
Fair point. OTOH, such posts often have other stuff worth fixing.
 
Yup
 
Mind you, PYTHON in a title is less annoying than [SOLVED] added onto the title after it's answered.
I managed to write an Astronomy answer on my phone. Although I came close to throwing it at the wall, fighting auto-correct. It keeps turning "its" into "it's".
 
I never trusted that
 
@PM2Ring can you turn off autocomplete?
 
11:05 PM
@AaronHall Probably. It's a pretty good auto-completion most of the time. It's just the "invisible" corrections that you don't pick up straight away that are annoying. And it's still learning - I've only had this phone for a week.
 
11:27 PM
Anyone ever use traitlets? I'm thinking it could have used a better name, like "app options" or something like that...
 
11:43 PM
Code not working. I think it is time to call it a day. Rhubarb all
 
11:58 PM
well, neither is mine, but that's because I haven't finished it yet. I'll leave it for the Monday me to handle
 
01:00 - 17:0017:00 - 00:00

« first day (2792 days earlier)      last day (2160 days later) »