« first day (3287 days earlier)      last day (1883 days later) » 

03:48
I'm trying to learn backtracking by implementing the permutations function. Not getting where I'm doing wrong. Here is my code - pastebin.com/62tpiMUW
Can anyone help me out?
03:59
insert/append isn't the inverse of the slice stuff you're using. You're mutating lists to add items, but building new lists when you want to remove items.
04:11
Thanks, get it :)
04:49
Hi, again facing problem while storing the result, please check the code here: pastebin.com/KL9pAMEG
The program producing the results correctly, but why not store the result?
05:02
I feel so totally excluded...
> Thanks for your vote! Your vote has been recorded and it affects this post’s ranking. Since this post’s score is below 0, your vote will not be displayed.
 
1 hour later…
06:04
@Quark Because your result is a list of chosen. The value of perms is [chosen, chosen, chosen, chosen, chosen, chosen, ...], and chosen is an empty list at the end. Do perms.append(chosen.copy()).
06:19
@Kevin there is a decree on that, straight from the BDF-a-while bugs.python.org/issue38277#msg353270
> The rule I use is: If it doesn't work without parentheses, try adding them.
06:30
which gets a 5/7 eye roll out of me, but I guess it works well enough.
((((((((((s = 'it's not helping'))))))))))
7/7 right there
also, string quotes ^^
@Kevin since 3.7 there is importlib.resources.path so you don't have to juggle __file__ to get to the root of your package.
07:07
cbg
cbg
is there a name for this type of design with a website, where a sidebar with tags lets you gather all similarly tagged content and display that in a result page. The problem is all the keywords I could think of to search have overloaded meanings so you search something like tag sidebar you can guess the number of tutorials im buried in.
i want to try making something similar to that
07:26
recbg
 
1 hour later…
08:54
Good morning everybody
cbg
Just saw your bounty Hough lines
Any suggestions on how to fix it? (note that I'm also open to suggestions without hough lines)
No, I don't know any image recognition
Alright than, any suggestions on how to improve the question? The first few days it got very few views and no votes
08:58
ok, thanks for taking a look anyway
Ah just saw your edit, thanks!
09:28
I see that GitHub packaging now supports Python
did anyone try it already?
what
I checked this morning and it didnt
nice timing, I just registered for the beta
=(
on the stenotype project, the dropdown defaults to python for me
it's not listed on the "learn more" page, though
funny, over there it also picks Python, but has no quickstart instructions as with the other ones. They are probably implementing it just now, I'll take a look if there are already recipes for pushing to gh-registry via gh-actions
09:52
Good morning peole. I started to learn Python but I still have problems with ordinary things like this. I want to print 50 results at once. I know that I can put print (list) 50 times but I need better solution. With this code I get only 1 results. Can someone to teach me what to read for this?




import random

list = ''.join(random.choice('G481RSt0') for x in range (10))

print(list)
*What to read to learn this
Literally any tutorial will teach you about loops
That is loops. OK thank you
10:37
I have some progress but I get all the same results. Not sure what to do to get different

list = ''.join(random.choice('G481RSt0') for x in range (10))
for i in range(50):
print(list)
print()
please adjust the indentation of your code. for inline code, use `-ticks, for multi-line code indent the entire block an additional time.
are you looking for print(*list) perhaps? what "different" output are you expecting anyway?
How about this: Explain in words what the code you wrote is doing. What does the first line do? And what does the loop do?
Obviously my brain is't capable for this. Random get the random from list and loop need to multiple that process.
That description is a bit too high-level to help us. With a bit more detail: The first line creates a random string and stores it in the variable list. The loop prints that variable 50 times. Does that help you see the problem?
realises that list is not a list
10:52
crazy how much we rely on variable names to understand code, isn't it?
yes, names are important. at least they should be.
I was fully in "don't name things after their type" lecture mode when I realised that it wasn't...
11:51
Ugh
They're all just C arrays, amirite
12:08
I am starting to work on a personal project and I just have no idea on how to approach it. Idea is to check if a html page contains an attribute with a simple text. Just like this there would be more than 100 checks to be applied on the same page.

and I have no idea how to approach it, read few tutorials and BeautifulSoup was one option and then HTMLParser. Any suggestions would help on approach.
BeautifulSoup is easier to use
pretty slow and large memory footprint, though (insignificant if you only use it on 1 page, just don't write a multithreaded crawler with BeautifulSoup)
@Aran-Fey that's the problem. My goal is to make it a full fledged applicaton and it can take more than a day to display.
@Aran-Fey for reference this is what I am trying to build. wave.webaim.org
Right. Parse the website with BeautifulSoup and run your tests. You definitely don't want HTMLParser for that.
> Idea is to check if a html page contains an attribute with a simple text.
It would be helpful if you posted an example or two of what kinds of things you are searching for.
12:17
@Aran-Fey I am little worried about execution time with BeautifulSoup.
There might be faster HTML parsers, BS is the only one I've used
You are right. Idea is to see if an html page contains an image. If it does, does it contain an alt tag with a description or not.(This is just 1 condition)
Here I am stuck on how to approach it considering it won't take hours to display the result.
@Aran-Fey Thanks for your input.
@PaulMcG do you have idea on how to approach this.
Well, as the developer of pyparsing, I have the "favorite tool is a hammer" problem. But pyparsing has some advantages over BS - it doesn't actually parse the whole page into an XPath-navigable object, it just looks for text patterns. It has a makeHTMLTags parser creator that will compose mini-parsers for various HTML tags, with awareness of comments, odd quoting styles, comments, etc. And its parsers are much less fragile than corresponding regex approaches.
Here is the pyparsing code to look for <img> tags that have alt properties:
import pyparsing as pp
img_tag = pp.makeHTMLTags("img")[0].addCondition(lambda t: "alt" in t)

sample = """
<img src="smiley.gif" alt="Smiley face" height="42" width="42">
<img src="smiley2_no_alt.gif" height="42" width="42">
<img src=smiley3.gif alt="Another smiley face" height="42" width="42">
"""

for img in img_tag.searchString(sample):
    print(img.src, img.alt)
Will print "smiley.gif" and "smiley3.gif", but not "smiley2_no_alt.gif"
Warning: pyparsing can get slow. Its strengths are in quick development and long-term maintenance. To expand this to look for hundreds of different tag patterns will not be snappy.
12:33
How does that work? It parses the entire DOM in the background but only yields the img elements?
There is no DOM, only strings.
<script>
var foo = `<img src="smiley.gif" alt="Smiley face" height="42" width="42">`;
</script>

<!-- <img src="foo.png" alt="bar"> -->
^ oops
makeHTMLTags generates mini-parsers for the opening and closing tags for the given string. Closing tags are easy, you are just looking for </tag-name>, allowing for extra whitespace. Opening tags are much more difficult. They can have attributes, and attributes values can be quoted with double quotes, single quotes, or even no quotes. And attribute names can have namespaces.
Yes, I usually have to filter out <script> tags and their bodies, and HTML comments.
Comments are easy though, just add img_tag.ignore(pp.htmlComment)
:4759074 and what about the execution time in case of more than 100 conditions on a webpage
I'll respectfully recommend BS again (:
12:38
What is your execution time now?
@PaulMcG Oh BS is taking too long. I could take a loo break in between
Are you sure it is BS, and not your post-parsing code to detect the conditions?
What's the bottleneck, parsing the HTML or running the checks?
Kevin'd!
Paul'd, but my name's Paul too, so it's fine :D
12:42
@PaulMcG @Aran-Fey: Python helpers. Thank you for your answers. At this point I have some clarity
@Aran-Fey I think I knew that at one time
from the AoC leaderboards perhaps
@Aran-Fey and it's parsing HTML that's taking too long
That's a surprise. Maybe a SoupStrainer can help?
I also faintly remember hearing that lxml is a fast parser
wait. Correction.

Right now I am parsing google news homepage. My code is searching for a specific class with any H4 tag and it just take forever.
12:50
@Aran-Fey lxml may have trouble with web pages that have badly-formed HTML. This is a big part of the problem that BS aims to solve.
start = time.time()
url = 'https://news.google.com/?hl=en-US&gl=US&ceid=US:en'
soup = BeautifulSoup(requests.get(url).text, features="html5lib")
list(soup.find_all('h4', class_='ipQwMb'))
print(time.time() - start, 'seconds')
^ runs in 3 seconds
from bs4 import BeautifulSoup
import requests
page = requests.get('https://news.google.com/')
print(page.status_code)
soup = BeautifulSoup(page.content, 'html.parser')
pmc = soup.find('h4').get_text()
print(pmc)


In 7 seconds, it displayed status code and in 35 seconds displayed the text.
That is indeed very slow, and somehow using page.text instead of page.content makes it a lot faster
I made the necessary changes and it worked like magic. Thank you Batman.
Status code: 7 seconds
text: 2 seconds

could you please do me a favour and explain what changed.
13:06
I wish I could
Well, I suppose BS tries to guess the encoding under the hood
@PaulMcG @Aran-Fey: Thank you both of you for helping me out. You saved me a lot of headache.
special thanks to you bro @Aran-Fey. and here's what i found; https://stackoverflow.com/questions/17011357/what-is-the-difference-between-content-and-text
https://stackoverflow.com/questions/40163323/should-i-use-text-or-content-when-parsing-a-requests-response

bye for now.
morning cabbages, all
cbg
13:54
I have an interesting problem: we use airflow to do some work. Part of this "work" is a python script that does stuff. Part of this python code causes a runtime error because the code contains import a.b and b() (which should really have been a.b(). Is there a way to dry-run compile the python code to catch this sort of error before we even try to run it?
I know that any IDE worth its salt would have caught this a long time ago, but I've recently discovered that I can't rely on people to do smart things like use decent tools or test their code
a commit hook/CI with a linter/type checker should do
flake8+mypy+unittests work pretty well to catch the most glaring errors.
would such a linter work even if b() is inside some function def? Or would it only work for top-level?
linters and type checkers work on the entire code.
whether they work for that specific case, you have to try.
fair enough. Many thanks
we've recently added LGTM to all our github hosted projects -- it is pretty good, if a bit overenthusiastic, at catching errors that other tools let slip.
14:04
hey! that's pretty cool. I just looked it up. Thanks
@inspectorG4dget dratted UIs
(gen2) fathead:tmp sholden$ cat /tmp/one.py
import a.b

b()

(gen2) fathead:tmp sholden$ flake8 /tmp/one.py
/tmp/one.py:1:1: F401 'a.b' imported but unused
/tmp/one.py:3:1: F821 undefined name 'b'
/tmp/one.py:4:1: W391 blank line at end of file
@holdenweb thank you so much. Could I ask you to run one more test please? Make one.py look like this:
import a.b

def foo():
    b()
now, what does it say?
I recently started using pre-commit to ensure clean checkins, so now this stuff is all checked and OK's before `I cancommit locally.
(gen2) fathead:tmp sholden$ flake8 /tmp/one.py
/tmp/one.py:1:1: F401 'a.b' imported but unused
/tmp/one.py:3:1: E302 expected 2 blank lines, found 1
/tmp/one.py:4:5: F821 undefined name 'b'
@inspectorG4dget the same, give or take whitespace errors
that's fantastic. Thank you. I'm going to recommend that we implement this in our CI/CD.
14:15
Obviously it can't do static analysis on references created dynamically, but it does catch a ton of stuff you really don't ever wantr to have to think about.
@holdenweb I wholeheartedly agree. The problem is that apparently, I can't depend on everyone else to do their own pre-commit due-diligence
Take their commit bits away!!!!
@holdenweb very true. And if something fails despite this checking, I'll know what to look for, knowing what this can't catch ;]
@holdenweb I wish I had that much power. That's pretty much why I'm pushing to do this in CI/CD. That way, I don't block their commits, but the CI/CD blocks their merges
Or at least protect the master branch, so you can download their branches and fix them up before committing to master. That you should have to do that and not them is perhas an interesting comment on organisational politics. I couldn't possibly say.
But yes, even when it's integrated in every dev's process you still have to keep those checks in the CI (against the day someone - eek - doesn't follow process). But it lets you sleep nights knowing it's less likely atrocities will be committed on the codebase.
Man, if all this stuff had been available when I was young I probably wouldn't have had the sense to use it.
goodness, no! I remember always compiling my C code with -Wpedantic just to make sure I didn't give the TAs an inch to dock marks
how'd you find that? :P
@AndrasDeak I got an upvote there?
@AnttiHaapala done
15:20
I had a "you've already voted to reopen this a century ago"
you forgot to tell the asker to have a long heart-to-heart with the person who gave them that broken string
@AndrasDeak well, I pity zir
you can pity ner and tell ner that it's someone else's fault and xe should fix it
haha now I know what I'd use for my pronouns... 'e, 'im, 'is and link to dead parrot.
there's e/em/es according to Rogers (1890) according to wikipedia
15:24
but this is not e/em/es but 'e/'im/'is
I know :P
^ not among the preferred pronouns.
15:43
@AndrasDeak meh, mem, mes, mehself
Yorkshire: me sen.
ok on a serious note. I answered this question here because I wanted to figure it out without using networkx. However, I also wanted to take a stab at using a stack of iterators. I'm thinking I should have a stack of iterators graph search coded up for AOC when it comes around. I'd appreciate any (useful) criticism of what I've done.
16:16
oooooo
So I've modifed the script to be loadable elsewhere, however I've realised the function i've implemented as part of the module is printing, when likely in other scripts I'm going to want it to just return the data for further handling...
So, I want to do something like "allIPs = getEPGs(ip)" in the main if statement, and then just return the epgs object in the function.... ?
Does that make 'sense' ?
I've just tried it, and calling the script directly works...
yes, have it always return your data, and print it elsewhere
since you need the data all the time and want to print the data some of the time, it stands to reason that the default should be returning the data, and you have to work with that when you do want to print it
errr, wrong script hahaha
@djsmiley2k yup
yeah, but you need a closing parenthesis, and I'd put the return outside the context manager
"context manager" being the if statement?
no, that means the with block
putting a return outside an if should certainly change behaviour
cbg
16:31
hmmm, ok, is there a simple explanation why?
And does it matter that the list epg is created in the with block?
In my head the with statement is responsible for closing the file, so just like with a try/except block I'd put as little in there as necessary. Anything after reading the data into a list doesn't need the file.
So from the print onwards (which I should maybe remove...)
@djsmiley2k if you try to read the data outside the with block you'll fail
@djsmiley2k yup
16:34
oh now reader doesn't exist...?
I think you misread that error message
try rereading what I've said
@djsmiley2k I guess I should've asked "which print?"
i hope that's better as I need to logout from work
nothing changed
17:01
^
wim
wim
@MisterMiyagi ...really? I'm not seeing it
wim
wim
17:25
huh, didn't know bpaste.net . looks nicer than dpaste.
I wonder if the kpaste domain is available...
wim
wim
What features does kpaste offer?
17:44
It has all the good parts of every [a-z]paste site... But because I can't afford a lot of storage, it only stores one document at a time. When you upload something, it erases everyone else's pastes
@wim kevin'd by Kevin but also syntax highlighting for KevinScript
wim
wim
The google search result doesn't inspire my confidence
18:09
My site would be fresh fresh fresh, so that at least is accurate
wim
wim
18:38
any guesses about the sort key on the starboard?
lambda x: random.random()
wim
wim
empirically it seems to be keying on (not is_pinned, n_days_old, -n_stars)
if someone star the pitchfork again I expect it to go to top!
boom
will it go back down if you unstar it?
hmm, so, it is actually something more (not is_pinned, n_days_old, -n_stars, other_mysterious_thing)
age
in time not days?
wim
wim
ohh, like a full time stamp. yeah probably.
wait a moment!
there is a 1d ago below a 2d ago
I think the time since it was last starred is also factored in somehow
18:47
Currently I've starred nothing within the top 10 of the star board. If you need me to star/unstar, let me know
wim
wim
I hate this voting display trial. Wish there was a way to opt-out of the UI experiment
@AnttiHaapala Do you think it would be fair to dupe that to this ?
all answers on the former are inferior/broken. user2357112 fundamental idea will work again but needs some minor tweaking since the input format is slightly different.
19:02
requests doesn't automatically decode gzipped responses?!
if I need to apply sum(i > 5 for i in excel_values) across rows, how may I adjust it? Sum up all instances where value in row is greater than 5.
wim
wim
@Aran-Fey I thought it did - did you set accept headers?
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Charset': 'utf-8;q=0.7,*;q=0.7',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-us,en;q=0.5'
wim
wim
requests.get("https://httpbin.org/gzip").json() works for me
oh, apparently it's not gzip, it's 'Content-Encoding': 'br'
wim
wim
19:11
what the heck is br
wim
wim
sounds like a vegetable
that'll teach me not to blindly copy/paste HTTP headers from SO answers into my code
wim
wim
play with requests.get("https://httpbin.org/brotli") and tweak the headers
I just removed the br and it works. Curiously, removing all 3 still made the server send me brotli instead of plain text
wim
wim
19:25
any windows 10 users here? do you know some working glyphs for this user? if so please edit a link into my answer. --> stackoverflow.com/questions/58420234/…
19:44
@wim ha, that user's name is Diogenes which was recently a topic of discussion here, which was the first time I'd heard of him. He was a hilarious dude
@wim hmm i've upvoted that answer before, if you think so then do hammer, I've got my close and reopen votes with that one already. FWIW I did think about writing a simple token conversion to my answer but didn't have time yet. Mine isn't perfect but I guess it is a case of "there is some input that needs to be converted to Python now", not "this is the format the other party insist on using for arbitrary dictionaries.
@wim let me know when you've divined the sorting rule on the full starboard
Google tells me that Courier New might maybe perhaps be able to display Hiragana and other unicode symbols on Windows. I tried to verify this but I can't remember how to add new fonts to the command prompt properties menu, and superuser.com/questions/5035/… works specifically and only on XP
The current fonts I have available to me are Consolas, Lucida Console, and "Raster Fonts". Consolas gets the most partial credit for being the only one that displays a question mark in a box when I try to print "ぁ"
Lucida Console prints only a box, and Raster Fonts prints only a question mark, and I award zero points for both.
wim
wim
wow, the bar for partial credit is low on windows
at least it gets your imagination going
19:50
I award 2.2e-308 points to Consolas. Don't spend it all in one place.
Google tells me that I can easily display Hiragana if I switch my locale/language/timezone to Japan, but there's a good chance that it will convert all system menus to Japanese, so I'm not going to try that.
How does that even work?
suddenly magical fonts appear?
Quite possibly.
There's like a hundred fonts in my system fonts folder, but there are only three in the command prompt settings menu, so it might just be a matter of making the Hiragana-supporting fonts visible in that menu.
wow
boxes
Courier New definitely has a glyph for ぁ because I can paste it into Notepad++, so at least there's that
can't remember what's the last time I've seen a box in Linux :d
19:58
I thought I was done with boxes ಥ_ಥ
I really look forward to the day when all this shit Just Works.™
It feels like it's been five years away for my entire life
All the nonsense is just such a distraction from the real information processing tasks. When do I get DWIM mode and my jet car?
wim
wim
20:17
@coroutine is deprecated in 3.8 (use async def) bet that gonna bite a lot of people
There should be a fixer shim or similar. Anyone using @coroutine is likely to be in touch with developments, as this has been the plan since the 3.5 to 3.6 transition, IIRC.
2-D time
@Aran-Fey omg failed paste ftw
Hmm this conflicts with my prior understanding that time is a cube
20:33
You'll be happy to know that your life encompasses an area of 25π years²
In fact, it seems you've made the most of your life as you've maximized the area with a given length of 10π years.
I can't help but think you have a pro-circle bias in this matter, piRSquared
hmmm
so did everything work in the beginning (and it was good?)? or, is it going to work in 5 years?
20:56
TBH, I don't know where the beginning is.
wim
wim
what the dupe for comparing a number to string you got from input stackoverflow.com/q/58421576/674039
@piRSquared I note that the arrow is pointing firmly away from "When Everything Works".
@holdenweb >.< you're correct. Interpretation is left as an exercise for the reader.
21:27
cbg
i tinkering aroud and scraping some info with beautiful soup and i had some weirdly formatted data I wanted to pull from some tables
the table is structured as pairs of columns
thanks to the styling i can see an easy way to select the label (which is in shaded columns) vs the values
@Skyler drawn anime girl warning on that link
oh yea, i disabled the styles a while back so i forgot about the banner image
class=profilefor labels and class=desc for the values
(im only pulling from the top two tables (I've scraped the rest already)
but for the inner loop whats the best way to loop over each pair
loop over all td elements pairwise?
yea
luckily it simplifies to just each pair per row since you can just do
for cell in soup.find_all('tr'):
im going to take each label and value and append to a dictionary
I don't see how looping over rows makes anything easier
21:39
Can't you search only within each \table block? Or is that not your issue?
let me rephrase what I said earlier: find all td elements. pair them up. loop over the result.
yea
@AndrasDeak on some of the other tables ive worked with that we done differently I ended up getting a lot of other columns when i converted from bs to pandas
@Skyler is that "yea, sure", or is that "yea, I understand that this is a pro-active suggestion for me to do, and I will try exactly that"?
@Skyler where did "converted to pandas" come from?
@AndrasDeak thats from other tables on this website, so when you asked why i dont just select the tables its cuz i've seen some wonky stuff come out when i select entire tables
I was more asking whether your problem was assigning each td to a given table, or something else
because I'm not sure I understand what you might be asking with "whats the best way to loop over each pair": why not just loop over each pair, as Aran suggested?
21:46
i think as i was typing the solution came to me when i started describing the classes of each cell, since that lets me constrain any weird table formatting
brb
if at least you understand we're all happy
def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)

resp = requests.get('https://fate-go.cirnopedia.org/servant_profile.php?servant=011')
soup = BeautifulSoup(resp.text, features='html5lib')

for stat, value in pairwise(soup.table.find_all('td')):
    print(stat.text.strip(), value.text.strip())
Both of those tables have id="rounded-corner" btw. How incompetent was the person who did that?
@Aran-Fey there are some really weird design choices for the person who made this website, like how he put link tags over the entire table
i think one thing that had been throwing off my other attempts might have been there are some pairs of null pairs that were breaking my test functions
examining the tables closer i see there are zero height rows
22:04
@Aran-Fey I don't want to subject myself to potential brain damage by actually looking at the HTML of that site. ;) Or figuring out how to look at a page's source on my phone. But my guess is that the tables were produced separately by some dumb software that can save tables as HTML, and pasted into a single document by hand.
There's a long history of bad HTML getting created by software that wasn't really designed to create HTML, but had that capability added later. And software that's allegedly intended to create HTML, but the resulting code is not designed to be human-readable, or to be easily pasted into a larger document, it's only supposed to make a simple stand-alone page.
Before HTML5 & modern CSS, people used to do all sorts of crazy things with tables just to achieve desired layout that was vaguely uniform across browsers. There's still a bit of that going on, perpetuated by ancient tutorials, and people who don't know better.
One fun trick was to do bitmap graphics using table cells. It was slow, but it worked. :) But thank goodness for HTML5 Canvas.
wim
wim
22:53
@Aran-Fey your script doesn't seem to be doing it's thing anymore for the glossary, could you take a look?
hmm, I don't get todays xkcd
23:41
@wim around 4% of the expected mass-energy in the universe can be described by that matter we've interacted with so far
another 27% is dark matter, the rest being utterly unknown in property and called dark energy
so if we assumed homogeneity of the universe in these three states then 27% "of the milkfat" is dark matter and the rest dark energy

« first day (3287 days earlier)      last day (1883 days later) »