« first day (1820 days earlier)      last day (3132 days later) » 

12:14 AM
@AdamSmith You are absolutely correct. I figured from the OP request they wanted to have bob and sally as required params and optionally provide additional ones
@AdamSmith So, what you are saying is that the ideal approach based on what OP is trying to do is to simply suggest using def foo(*args, **kwargs), or simply def foo(**kwargs)
 
 
1 hour later…
1:23 AM
hey
 
 
1 hour later…
2:47 AM
cbg
So i work help desk for a small retail chain. I just got a call to after hours that a POS terminal had fallen asleep, and (knowing that they aren't to touch the power button without Tech Support on the line) the store staff had taken apart the plastic clam shell and switched off the power supply instead.
sigh
 
3:17 AM
What, they can't power cycle a POS?
@AdamSmith Why not?
 
51
A: python list comprehensions; compressing a list of lists?

Ants AasmaYou can have nested iterations in a single list comprehension: [filename for path in dirs for filename in os.listdir(path)]

This is a very confusing line of code to me
Can someone explain it? Maybe somewhere you could put parentheses in it that'd mean the same thing?
 
[filename for path in dirs #:
              for filename in os.listdir(path)]
Does that help?
 
Yeah, I think it does
so it's similar to a loop like...

for path in dirs:
for filename in os.listdir(path):
# do something with filename
(pardon my formatting) is that about right
 
l = []
for path in dirs:
    for filename in os.listdir(path):
        l.append(filename)
 
I think I've got it...let me see if I can work that into my code. Thanks!
Got it! Thanks again. I kept tripping up over the last-first-middle nature of it.
 
3:34 AM
Glad to help.
 
 
2 hours later…
wim
5:59 AM
>>> False == False in [False]
True
(fun with comparison operator chaining)
 
6:12 AM
@AaronHall Because the type of people you hire to be a convenience store clerk for minimum wage think the way to resolve a computer going to sleep is to turn it off at the power supply.
(evidenced by the fact that that's exactly what happened)
so we don't let them make any decisions whatsoever with the hardware
 
@wim That is actually evaluated as False == False and False in [False]
 
 
1 hour later…
7:22 AM
Mornin'
 
7:36 AM
Hey up sunshine
 
Heya
 
 
1 hour later…
9:10 AM
Hey!
I want to check if a string of words has contains a pair of words.
The pair of words are contained in a list of tuples
 
string of words looks like what?
 
list of tuples containing pairs: [('people', 'said'), ('hello', 'stampede'), ('buy', 'police'), ('people', 'pilgrims')]
 
that didn't answer my question.
 
string of words is basically tokenization of sentence.
 
and you've tried what?
 
9:13 AM
(Pdb) print(words)
['Witnesses', 'to', 'a', 'stampede', 'that', 'left', 'more', 'than', '700', 'people', 'dead', 'at', 'the', 'hajj', 'in', 'Saudi', 'Arabia', 'on', 'Thursday', 'blamed', 'Saudi', 'authorities', 'and', 'said', 'they', 'were', 'afraid', 'to', 'continue', 'the', 'rituals', '.']
Two loops one over the words in sentence and one tuples in list works but it seems unpythonic to me
is there a easier way to do this
 
unpythonic
What's the definition of Pythonic?
 
>>> pairs = [('people', 'said'), ('hello', 'stampede'), ('buy', 'police'), ('people', 'pilgrims')]
>>> words = ['Witnesses', 'to', 'a', 'stampede', 'that', 'left', 'more', 'than', '700', 'people', 'dead', 'at', 'the', 'hajj', 'in', 'Saudi', 'Arabia', 'on', 'Thursday', 'blamed', 'Saudi', 'authorities', 'and', 'said', 'they', 'were', 'afraid', 'to', 'continue', 'the', 'rituals', '.']
>>> words = set(words)
>>> [words.issuperset(tup) for tup in pairs]
[True, False, False, False]
 
Awesome does this work in python 2 as well?
I tried (Pdb) print(words)
['Witnesses', 'to', 'a', 'stampede', 'that', 'left', 'more', 'than', '700', 'people', 'dead', 'at', 'the', 'hajj', 'in', 'Saudi', 'Arabia', 'on', 'Thursday', 'blamed', 'Saudi', 'authorities', 'and', 'said', 'they', 'were', 'afraid', 'to', 'continue', 'the', 'rituals', '.']
(Pdb) [words.issuperset(tup) for tup in cs_words]
*** AttributeError: 'list' object has no attribute 'issuperset'
 
@AbhishekBhatia in Aaron's example, words is a set. Only sets have the method issuperset
The only corner case I can think of is if your tuple is ("word", "word") and you needed to check that your list contains "word" TWICE.
or a very very short list of words might cost more time to create a set and do two O(1) lookups than it does to do two O(n) lookups
so you could do [all((w in words for w in tup)) for tup in cs_words]
though that doesn't fix the counting problem. That would require conversion to a collections.Counter and is a bigger pain.
import collections
c_words = Counter(words)
[all((c_words.get(word) < count for word,count in Counter(tup).items())) for tup in cs_words]
which off the cuff looks like it adds a TON of overhead for a very small corner case.
probably much faster to test for it and special case it
anyway, it's 2:30am. I gotta get to bed. Rhubarb
 
9:47 AM
@Ffisegydd just played the first couple of intro levels of HotS; pretty fun. Similar to Dota, but with a much better intro level.
 
10:29 AM
@Robert yeah definitely. I assume you did the tutorial with Raynor and co then? It's a lot of fun.
Dota has one map only I think, HotS has 8-9
Large variety of characters too.
 
11:12 AM
cbg!
 
11:29 AM
cabbage
 
hey hey how goes it
 
cabbage @PM2Ring @idjaw @Ffisegydd @RobertGrant and others

anyone having other news about the documentation project other than: https://meta.stackoverflow.com/questions/new/documentation?show=all&sort=recentlyactive
 
Hi, Xavier. Sorry, I haven't been following the progress of the documentation project - I have mixed feelings about it.
 
I'm very new to the community, so I am not familiar. Also, I clicked that link and it went to a page not found
 
@idjaw it's about
2457
Q: Warlords of Documentation: A Proposed Expansion of Stack Overflow

Kevin MontroseIt’s been 7 years and 10,000,000+ Questions since Stack Overflow was launched. The amount of good that has been done for the field - all the developers helped, all the person-hours saved, all the beginners who grew into professionals - is hard to overstate. I cannot express how proud I am of what...

 
11:38 AM
Thanks @XavierCombelle reading now.
This seems like a huge endeavor
was an interesting read
 
Very huge. Especially if you want to keep the docs up to date. I suspect it will be impossible to get uniformity of quality across the whole documentation base.
 
Initial thoughts on this, it seems like it's an entire SO site on its own...like you would have to have SO and SOdocs co-exist
you can't expect a mod to handle both SO and SOdocs
 
Yep. It would be a semi-separate entity.
Unlike SO, it won't be a comprehensive resource, since the documentation project doesn't want to document things that already have adequate docs. And I suspect that could have the very undesirable effect of smaller projects slacking-off in their docs creation duties, since they know that SO-Docs will eventually pick up the slack.
 
11:54 AM
plus there are probably a lot of thoughts across several communities on documentation itself that they would not want to participate, leaving many holes when searching docs
you would end up going back to SO anyway
You know what would be interesting? If a question from someone under a certain amount of rep had their question analyzed upon submitting and detected for possible duplicates it would return a list of answers saying "hey we found these...we are putting your question on hold until you can confirm these answers really did not help".
unless something like this is happening? I asked a question a very long time ago and deleted it..so don't remember
 
12:16 PM
Cbg everyone. I was wondering if anyone has played around with a raspberry pi in here? :p
 
I've never posted a question on SO - I get my questions answered by Googling them. :) The system already offers the OP a list of possible dupes before they submit. And I guess that kinda works, but the downside is that we get to see lots of question from OPs that don't understand why their question matches one of the offered dupes, or are too lazy to solve their problem with the offered dupes & expect us to provide them with a custom solution.
 
Exactly! I feel like maybe that should be worked on...make it harder to ask a question that REALLY is a duplicate.
Or would that lead to frustration on using the site, and result in less usage?
 
They already link to relevant questions when someone makes the post, so it wouldn't be that hard
 
@idjaw Yeah. We don't want to scare off the poor clueless newbs. But to be fair, it often does take some expertise to understand why a particular dupe is relevant to your problem.
Still, I think it's crazy that you can ask a question without being a logged-in registered user.
 
wait, what?
seriously?
 
12:26 PM
I'm afraid so.
 
I'm pretty sure the user insert random ints are the unregistered users, for the most part
 
@Programmer Yep. So when you answer there questions, don't expect an upvote from them anytime soon. :) OTOH, it's not that unusual to see an unreg'd user's name change to a proper user name while their question's active.
 
Is that what user###### is? unregistered user?
!! AN OPENSTACK QUESTION!! I KNOW THIS!! (sorry I love openstack) stackoverflow.com/questions/33053927/…
 
wim
some guys are just like that
 
Generally people adopt a more normal name once they register, but they don't have to.
 
12:32 PM
wow...176K rep....that's so punk! screw the system! :P
 
wim
there's a very helpful guy in the python tag too
(s)he knows a lot about numpy
 
I've never dabbled with numpy...I see it a lot
 
DSM
Morning cabbage for all.
 
I'm trying to come up with an idea on how to setup a raspberry pi, that my parents would find interesting/useful. I was thinking while idle it could pull from new images to a certain imgur category and then they can use it as like a media/file storage server. Anyone got better ideas?
 
And there are pages of people just called user or User stackoverflow.com/users?page=1&search=user
 
wim
12:34 PM
numpy is awesome
i actually got into python via numpy
 
DSM
I got into Python because I had a data analysis tool written in C and as it grew more complicated it became impossible to manage. Several thousand lines of unmaintainable C became a couple hundred of Python, and I was hooked.
 
I got in to Python because I was tasked with converting an old perl provisioning system
 
I just learned python in college lol
 
wim
in school we learned Eiffel ..
ever heard of Eiffel in a commercial software environment? me neither ..
 
wow...yeah I totally had to look up Eiffel
I did computer hardware engineering, so I didn't have many software courses. I had the standard c++ course. I actually didn't realize I wanted to be a software dev until I graduated university with a hardware degree :P
 
1:36 PM
are we talking about how one got in contact with python?
Honestly I was feeling quite.. "python is not my type of language, the whitespace indentation is nothing for me, etc" prior to learning it. The reason I started reading about the language? I'm not teaching an introductory course to programming, and the language (not decided by me); python.
contrary to be initial belief python is a very good language for students who have never written a single line of code in their life, though the simplicity of the language comes with a lot of confusion when accidentally diving into things that are not meant to be explored by novice developers
 
@PM2Ring the problem is as far as I know there is very few adequate docs (major point is lacking of examples)
 
@XavierCombelle Sure, but is SO-Docs a good solution to that problem. I don't mind the idea of enhancing / complementing existing docs with examples, but I'm not comfortable with the idea of Stack Exchange becoming a patchy docs repository.
 
Hmm.. given that this question has a very limited answer-span, and that none of them are as detailed as the answers on this newer question ; do you think it is more suitable to close the old as a duplicate of the new - than the opposite?
I'm not sure how you guys in handles this, but that is how we handle such duplicates in ; and it is also recommended by meta-threads such as this one
 
1:53 PM
I haven't looked at the questions yet, but yes, we also like to do that in the python tag, when it's appropriate.
 
4
Q: Accessing attributes on literals work on all types, but not `int`; why?

Filip Roséen - refpI have read that everything in python is an object, and as such I started to experiment with different types and invoking __str__ on them — at first I was feeling really excited, but then I got confused. >>> "hello world".__str__ () 'hello world' >>> [].__str__ () '[]' >>> 3.14.__str__ () '3.14' >>>

22
Q: accessing a python int literals methods

CADBOTSince everything is an object in python, even literals, we are typically allowed to call methods directly on a literal. ex: 'hello'.upper() In theory, it seems like the same thing should be allowed for int literals ex: 4.bit_length() However, this doesn't work, and I'm not sure why. Any ...

@PM2Ring I would have posted my answer to the older one, but for some reason I couldn't find it when I was writing my self-answered Q&A (probably because I didn't search for the right thing, the title of the new question was edited when I realized my mistake)
 
@PM2Ring the problem with current doc is that the bar for editing it is pretty high. For example did you already edited official python docs ? (even if it's quite good) moreover, standard python docs are limited to standard lib, which so don't necessarily will
 
@FilipRoséen-refp In this particular case I think it'd be better to post your new answer to the older page. True, your new answer is much more comprehensive. OTOH, Ned's is brief and to the point, so it may be adequate for many readers.
Also, Ned is a highly respected member of the Python & SO communities, and has put a lot of work into various tutorials, both in written and in video form (eg nedbatchelder.com/text/names.html). So it would be nice for his answer to continue to be on the main page for this question.
 
@FilipRoséen-refp in my opinion, you should post your answer on the old question now you found it, because your question don't add too much to the old one
and of course close the new one as dup
 
@XavierCombelle Fair point. However SO-Docs won't be replicating docs that are already of a high standard. So the core Python docs won't be on it, but docs for 3rd-party Python docs will be if they don't already have good docs. And to me, that's a bit messy
 
2:03 PM
@PM2Ring but that would mean that one should value the author higher than the answers, which goes against the focus on answers - so I don't think that is the way to go. I might start a meta-discussion on this particular case
 
@PM2Ring I'm not sure that the standard of python docs are so high sometimes I feel like they are lacking of example (even if they are precise)
 
@FilipRoséen-refp Yes, answers should be valued more highly than authors. However, some authors produce vast quantities of high-quality answers, and it's nice to give such authors the respect that they deserve. By all means, raise it on Meta SO. Pity Martijn or Jon aren't here at the moment: you could ask them about merging.
 
wim
I had this discussion once already because I duped an older question to a newer one
there was a guy, who is now a mod, that didn't like that and thought it should go the other way and he was being a bit of a douchebag about it
 
@XavierCombelle Oh, I agree. I'm a big believer in example code. And as I said above, I don't mind the idea of complementing existing docs with example code: to me that seems a more appropriate thing for SO to do than to take on the task of maintaining documentation.
 
wim
so now I'm much more careful about closing dupes to newer questions, especially to ones that I've answered myself
 
2:16 PM
@wim always a pleasure to see you as well :p
 
wim
lol
 
there's @JonClements! Looking at the conversation above, what do you reckon is the best approach to solve the issue?
 
@wim I can understand people getting upset about it, especially if the old page has a high hit rate and lots of votes. I'm sure some of those old popular pages can be nice little rep-earners... :)
 
maybe @JonClements's opinion has already been expressed between the lines (given what @wim wrote above, I didn't see that until now)
 
Umm... not sure - let's open the Qs and have a look
 
2:19 PM
BTW, @FilipRoséen-refp: I mentioned one of your recent answer in here the other day: I (mostly) liked the code & explanation, but I wasn't so impressed with your somewhat unusual use of whitespace. :) See chat.stackoverflow.com/transcript/message/26168006#26168006
 
@PM2Ring yeah, I am a bit weird - old habits are hard to get rid of. I take the "competent Python programmer" as a very nice compliment since I have not been writing python for too long. In other words, thanks!
You are not the first to react to my unusual use of whitespace, so maybe I should listen to the community and get rid of such when writing posts on stackoverflow :P
 
I've merged the older question into the newer
 
wim
A questionable decision Jon
 
Hey all!
 
wim
the top voted answer is now mentioning the method bit_length which seems out of nowhere in the context of the question
 
2:26 PM
I will edit it to make it work
 
Fairly straight-forward to make the Q generic about int methods, but keeping inline with __str__ as an example...
 
wim
think you're making a mess and extra work for yourselves
 
fixed the other answers to refer to __str__ instead of bit_length, all should be good now
 
cbg
 
@FilipRoséen-refp Oh, good. :) I do understand about it being hard to move on from old old habits - I've used all sorts of conventions over the years, including a few languages that made certain kinds of alignment mandatory. But in Python, putting a space between the function name and the parentheses is very unusual. Using space for alignment isn't so bad, but IMO it should only be done in special circumstances, not for general coding situations (eg aligning imports).
 
2:29 PM
@BhargavRao CBG as in "Chill Black Guy"?
 
cbg as in Salad
 
@BhargavRao too bad..
 
wim
agree with PM on the weird whitespace by the way. it looks like shit
read pep8
 
@wim Well, merging is almost always a messy business, so it's understandable that mods are rather reluctant to do it. OTOH, when one or more of the posters concerned are available to assist in the process it does make it a little easier.
 
2:31 PM
I trying to build a corpus of documents related to earthquakes. I want to download all news articles related to that event. My problem is that using google search(stackoverflow.com/questions/15550655/…) gives bias with respect what is revelant now. Instead I want all articles irrespective of time or relevance.
 
@PM2Ring I'm a C++ guy, but the abuse of whitespace could be a leftover from my perl-days where sub-references are called as $sub->(@args) and regular ones as &sub (@args) - I like a little bit of spacing between the function to call and the arguments, mostly because you can also write sub@args if you'd like
even though my perl-days came far later than when I started writing C++, so I have no idea
 
@FilipRoséen-refp I was just more curious about how long it took to actually space stuff out like that... :)
 
@JonClements I'm a fast typist, and I do it as I type so I have no idea how I am to answer that question :P
 
Doesn't it ever happen that you end up including a module with a longer name then end up thinking "oh damn it - I've gotta go through and re-align everything AGAIN now..."
 
I find it easier to read white whitespace, if you stare at a few hundred/thousand lines of code per day having things in neat columns sure aids the nuddle
 
wim
2:34 PM
when I look at neat columns like that I just think the guy who wrote this code has OCD
 
@JonClements I'm a vim-poweruser, so fixing the alignment is a piece of pie - you could also use something as ClangFormat (not sure if there's an equivalent tool for python though)
 
wim
and what if another guy has to include another import , and he isn't a vim-poweruser
 
@wim of course I comply with the coding-standards of whatever project I'm working with someone on
 
@wim he's going to have a lot of space bar pressing to do :p
 
wim
or he just autopep8 you pypi.python.org/pypi/autopep8
 
2:42 PM
Cabbage!
 
user559633
Hello friends, Jon
 
@Jon Can you give me a tldr what happened with that int method question? Why did you merge the old answers into the new one?
 
Better to have a single canonical question, with the sign post being highly viewed but with the target easier to read/understand
 
@wim :) Or is a relic of Ancient Times, when that sort of thing was encouraged. And that was partly a holdover of the days of punch cards, when you had to align your code to various fixed width columns. Eg it was common in assembly code to have the first field for a label, the next field for the opcode mnemonic, the next field for the operands. That was followed by an automatic comments field, with the final 8 columns of the 80 columns card used for optional card sequence numbers.
 
bbias - need to make a few calls - appear to be missing some servers...
 
2:45 PM
@JonClements But wouldn’t the more appropriate way to solve that to simply edit the existing old question to be of better quality? Like this, combined with the self-answer, this looks like a double-rep farm.
I also think that calling __str__() is a terrible example for this problem. It just asks for answers like “Just call str(123) instead”. The original bit_length() usage was a lot more practical.
 
user559633
Oh interesting, SO is pushing their careers stuff by encouraging noting your title/current employer in your profile
 
@tristan Not just careers: that's a prelude to Teams
 
user559633
Oh yeah, this madness.
 
user559633
We should name ourselves like an old style gaming clan
 
user559633
3:03 PM
Quora, meta-github, and trying to get those recruiter dollars
 
rhubarb time
 
user559633
take care
 
rbrb PM
 
Okay guys I need an idea for a Python library called jazzhands.
Like a true genius I have the name, but not the idea.
 
user559633
I love that the Teams page comment sections is SO employees being shitty and snarky about criticism
 
user559633
3:06 PM
Negative feedback??!?! On my site?!????
 
@Ffisegydd jazz hands as a service
 
@poke I certainly not agree, especially not since the question was given to be by a real human being, phrasing it as the question is written. Saying "just call `str(123) instead" does not answer the question which is why the behavior is as described
@poke if it really looks/feels like a "double rep-farm" (whatever that is) the question can easily be locked to prevent rep-gain from it, or simply be made to be owned by the community.
 
Updated my Careers.SO to include BigCorp
 
@FilipRoséen-refp I know the problem, but my point is that the original question was better. You acted in good faith, I know that, but that doesn’t mean that I have to agree with how the merge was done now.
 
user559633
3:09 PM
I updated my profile to play with their textboxes
 
I'm gonna go with evil Corp
 
user559633
I get that reference
 
@poke the older question could have been edited to become better phrased, more specifically to include examples of when .bit_length did work directly on other literals (such as floating-point)
 
hey @MartijnPieters I did some advertising for you reddit.com/r/Python/comments/3o7uj3/…
 
user559633
socket.sendall() returns None on success. Happy morning troubleshooting.
 
3:12 PM
@tristan and throw exception on failure ?
 
user559633
@XavierCombelle Yes sir, that is accurate. Throws exception, no way to determine how many bytes were sent from Python
 
really tristan ?
 
user559633
Which part? Sorry, I assumed gender from the name
 
@tristan looks like this part is poorly design
 
user559633
3:15 PM
I had this "fun" little thing where I was checking if _socket.sendall() and sending the return to an accumulator to give metrics (e.g. rx_bytes: XXX tx_bytes: XXX)
 
@tristan I'm a sir by the way tristan
 
user559633
@XavierCombelle :) just being careful in case i unintentionally offended
 
@tristan I so that in such a case you have to use socket.send and not socket.sendall
 
user559633
Yep, I switched over to that
 
@XavierCombelle thanks!
@XavierCombelle: not sure if I'd be the right choice though; starting a new job on Monday, so my availability is limited to UK evenings and weekends.
 
3:34 PM
All the best for the new job, @Martijn :)
 
user559633
3:58 PM
 
@tristan man, tristan, you really need to shave!
 
user559633
@MartijnPieters Haha, that's actually accurate.
 
user559633
My neckbeard has merged with my unkempt neck hair and has turned into a low-grade mane
 
Has it connected with the chest hair yet?
 
user559633
@idjaw No comment
 
4:03 PM
The only reason I shaved was for a wedding. I'm on week 2 now.
 
Real programmers don't shave
:D
 
Amen to that
 
DSM
If we don't shave, how do we handle our unibrows? .. asking for a friend.
3
 
if not (a programmer):
    then shave
:D
 
4:17 PM
@DSM (don't know how to link images here) in1.ccio.co/YI/12/Md/274860383477643195yXRq8Hjdc.jpg
 
Just paste the image in a new message. It'll onebox
 
@idjaw just paste in a message, or use the upload button and paste the URL in there (picking the from the web option).
 
YES! Thanks guys
 
user559633
@DSM I've found that it magically disappears. Just fall asleep next to your spouse/partner/keeper/abductor and it will be gone in the morning
 
goo luck for your job @MartijnPieters
 
4:50 PM
cbg
@MartijnPieters new job, who's the lucky company :D
 
rbrb
 
@AnttiHaapala see my profile :-P (new feature on Stack: add your current position to your profile)
Starting as Tech Lead at Facebook.
 
5:06 PM
so what would you be working on
 
Dunno yet.
 
wish they'd let you give some love to the api libs :D but I guess a futile dream :D
 
First a bootcamp, then I get to pick.
In other words, ask me again in about 6 or 7 weeks.
 
hehe :D
 
anyone had done sqlalchemy tree with just self-referential fk using CTEs
maybe this works
 
@MartijnPieters graphQL is an interesting technology from facebook. I wonder how much it can be applied by other companies. For example when I use twitter api, there is a lot of junk returned.
 
6:05 PM
Shouldn't var curText = htmlText.slice(0,2); return the first 3 characters of the htmlText string?
I'm trying to figure this out in Javascript & htmlText is created via var htmlText = $("#chat").html(); using jQuery
 
@RPiAwesomeness you ask for javascript ?
 
@XavierCombelle Yeah, is that off-topic in here?
 
Why Python room?
 
I wasn't sure since it seems to be the SO room
Didn't see any other rooms related to JS when I searched the sight
 
DSM
6:07 PM
Your search-fu is, frankly, not great.
 
Apparently not :P
My bad, sorry guys
 
no problem, the link I posted should take you there
 
@RPiAwesomeness "slice extracts up to but not including end." developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
 
@XavierCombelle Yeah, I've figured that out. RN it's not giving me anything :P
Anyways, TY @idjaw for the link
 
@RPiAwesomeness cheers
 
oh Netscape...you brought magic to my world back in the day. :P
 
So if I have an HTML element object, should its __str__ return the html?
I think maybe yes.
 
6:51 PM
so like obj.href ?
 
no, str(obj)
or format(obj)
 
yes
 
or '{}'.format(obj)
 
I would expect that if I did that I would expect the output as '<a href = "blah">'
 
7:07 PM
hey guys, quick q about beautifulsoup
is there any way to find the text BETWEEN two html tags? I'm trying to find the text between a h3 and h2
or is it hacky in that i'll need to use regex?
 
DSM
So from '<h3>a</h3>b<h2>c</h2>' you want b?
 
Yep! Is that possible?
 
are you looking for something like this: stackoverflow.com/questions/16835449/…
 
DSM
I'd probably find all h3s and then check to see if the next (next) element was h2. If so, take the text after h3.
 
@idjaw I saw that question as well, I think it varies between <p> </p>
and no tags, which is the frustrating thing
@DSM Ah, so just the hacky way?
 
DSM
7:14 PM
That doesn't seem that hacky to me, and doesn't involve any regex. But someone who uses bs4 more might have a better solution.
 
7:27 PM
@OneRaynyDay the @DSM solution looks not bad at all except that it will not work as soon as between h3 and h2 there is some tag (that you did not specify in your question)
 
Yeah that was the immediate edge case I saw.
 
DSM
Huh. I automatically interpreted the question as only applying to cases where there were no intervening tags, because otherwise you might not know which text to return.
 
Indeedilydoodee.
OP not provided full details. 100 lines.
 
DSM
.. eh? Do you smell burning toast?
 
I was suggesting that the OP will have to do 100 lines as penance. Like in an old school class room.
 
DSM
7:42 PM
That makes sense, he admittedly grudgingly.
 
Right, I meant that there might be tags in between
Sorry about the confusion guys - I'll explain it a bit further
So let's say <h3></h3>...<p>..<ul></ul>...</p><h2></h2>...<h2></h2>...
I'm trying to get everything between /h3> and <h2
so this part: ...<p>..<ul></ul>...</p>
 
DSM
So by "the text between a h3 and h2" you really just mean the section of the raw document between those two tags?
 
yep!
 
8:05 PM
I think that requires a bit of regex hmmm
 
What if you have h3, h3, h2, h2? What should be returned?
 
the area between the last h3 and the first h2
But in this case, there will only be 1 h3 always.
I tried using this as the regex(it worked on regex101.com but not in python for some reason) : print(subSoup.find_all(re.compile("/<\/h2>[^;]*<h3>/")))
 
You may need to choose appropriate flags.
 
@Ffisegydd do you mean like the /.../g for global, with possible flags gmixsu, etc? I didn't include anything and it still gave me the correct output here: regex101.com/r/kK9rG7/2
 
I did mean those yes.
 
8:14 PM
But I didn't include them and it still worked on the website?
 
Well I didn't know that when I suggested it :p
 
@Ffisegydd ah yeah I gotcha, but yeah it has some discrepancies that I'm totally unaware about
between website's version and actual python regex... ergh
 
to work you should use print(subSoup.find_all(re.compile(r"</h2>[^;]*<h3>"))) but using a regex for parsing html is for sure a bad idea
 
Nope, still didn't work :P, but yeah I'm aware, but I can't seem to find the content between 2 tags any other way
 
@OneRaynyDay your regex is gready, most of the times you want ungready matching in this kind of cases. So add ? after [^;]*
 
8:24 PM
@HamZa still nope :'(
 
I know it doesn't work but still an improvement
also define "doens't work"
 
@HamZa It returns [] when I apply the regex, the print just gives me "[]", and I see your point about the greedy part
 
Does print(subSoup.find_all(re.compile("</h2>[^;]*?<h3>"))) work?
 
@HamZa Oh, you mean <\/h2> right? for escape char
 
@OneRaynyDay no escaping
since we aren't using any delimiter
 
8:27 PM
@HamZa No there are no results still... Here, let me show you what i get if I just do print(subSoup.find_all(re.compile("")))
 
@OneRaynyDay lol. Try re.compile("<h3>") for starters
(with the print find_all stuff ofc)
 
@HamZa wait omg, find_all gives me an array.
 
@HamZa okay, so I fixed it(made it into a string instead of array of strings)
thank you though! :)
 
@OneRaynyDay nice!
 
8:48 PM
@HamZa thank you! :)
 
welcome
 
8:59 PM
@XavierCombelle Provided Twitter wants to give you that power.
Given that Twitter is moving towards putting paywalls around the information they hold..
 
user559633
Speaking of which 'Twitter Expected to Begin Layoffs and Stop Headquarters Expansion'
 
user559633
Hooray!
 
user559633
I wish they'd layoff everyone and also stop existing.
 
user559633
9:16 PM
Something I didn't know -- time.sleep(0) yields to other threads. found via the scheduler documentation
 
user559633
I assumed that time.sleep would still be busy waiting
 
10:09 PM
Hi! Can someone please help me with this:
http://fpaste.org/277794/14445145/
 
10:41 PM
Yep, that sleep is important.
I had to change some threaded stuff that would be used by a lot of people, so I had to verify I wasn't going to bork stuff up by doing it that way.
I figured it out by reading the source.
And empirical tests.
It's not well documented, I think.
 
user559633
11:02 PM
@AaronHall Yeah, not entirely sure what documentation page I'd expect it in either
 
time.sleep ?
 
user559633
It's nowhere in threading, time would be okay, but it's used for much more than just avoiding busylock
 
"Suspend execution of the calling thread for the given number of seconds." is where it should be elaborated on.
 
user559633
Yeah, fair
 
user559633
Slippery slope to explaining general concepts, but threading could use one of the Python 'how-to' docs that goes into it
 
11:18 PM
good evening all
 
11:36 PM
cbg all
 
hey
 

« first day (1820 days earlier)      last day (3132 days later) »