« first day (3334 days earlier)      last day (1618 days later) » 
00:00 - 13:0013:00 - 00:00

12:44 AM
hey guys, i had some fun with a hard git reset and I'm currently looking at a file that was lost with git show but how can I actually copy the content of that command
 
Seb
1:04 AM
@Skyler check out stackoverflow.com/a/1109433/8164958 and the comments to it
 
1:26 AM
cbg
 
 
1 hour later…
2:41 AM
Am I being pendantic when creating a simple urls with urljoin rather than just using +?
 
 
2 hours later…
4:37 AM
How can I check which implementation of python I am using? Example: Pypi, CPython, etc?
In [50]: import platform
In [52]: platform.python_implementation()
Thats it!
 
yes, as the first google search probably showed you. :)
 
The order preserving aspect of dict in Cpython 3.6 onwards - docs.python.org/3/whatsnew/3.6.html#new-dict-implementation - reads "The order-preserving aspect of this new implementation is considered an implementation detail and should not be relied upon". So can we not rely on using this in our application logic to trust that insertion order will be preserved?
 
From 3.7, you can rely on it
In 3.6, you shouldn't.
 
The next Advent of Code puzzle releases in about eight minutes!
 
4:54 AM
That's either going to be the moon against a starry sky or the end of Alderaan...
 
Huh, I was leaning toward a snowman.
 
That was my original thought, but it looks like it might be a bit too big for that... maybe...
Just noticed there were dots inside the circle too. Now I don't know what to think.
 
5:30 AM
Hnm slow aoc day
Made it to leaderboard with a speedhack tasku even though had to fix a problem for wife during coding
 
@variable In 3.6, it was an implementation detail of CPython (the standard Python interpreter), so the order-preserving can be relied on if you're using standard Python 3.6.0 or later (I used a beta version of 3.6 for a little while before 3.6 was officially released, it didn't preserve order).
 
And there are no other python interpreter at 3.6...
 
pypy has a beta it seems
 
Man this is tragic
And it's what I get for not reading the aoc description properly
 
5:41 AM
Hi All,
can you help me in finding the total number of words in <p> using python.
>>>for p_width in bsObj.select('div p'):
    # print(p_width.get_text())
    for pSplit in p_width.split():
        if pSplit not in countPList:
            countPList.append(pSplit)
            countP = countP + 1
        print("Total words in paragraph: ",countP)

This is what I tried along with few other options but nothing seems to work
 
And how does IT not work
 
Messed up my implementation the first time, got timed out, then didn't read the description right, got timed out again. Used the test-cases to get it right, then forgot to change the input before running and got timed out again :)
 
I guess you're using Beautiful Soup, but you need to mention stuff like that when asking questions.
 
Yes, it is beautifulSoup. I tried simple code as well
>>>for p_count in soup.find_all('p'):
print(len(p_count.split()))
 
cbg guys o/
 
5:46 AM
cbg
 
But it counts the number of lines instead of words.
 
Any idea why pydoc is throwing import error for library modules?
 
it hates you probably?
 
Ah too bad then!
 
blah that was a confusing problem to parse
 
5:59 AM
@Dodge can you help with this one..
 
@MunishGupta I was referring to the Advent of Code problem for this evening if my previous statement was confusing. Regarding your problem, you simply want to find the number of words in a string? And len(a_string.split(' ')) is not working for you?
 
Getting an error: TypeError: 'NoneType' object is not callable
 
So whatever you are getting from beautiful soup should be a string, right? Print that to be sure. Then split on space and find the length of the resulting list from the split. If your problem is in getting the string with beautiful soup, then I probably won't be able to troubleshoot that with you.
 
Followed below steps to generate documentation for my code:
1. activated local venv
2. executed command `"python -m pydoc -w my_py_module.py"`
3. On windows, it's throwing No Python documentation found for 'my_py_module.py' and on Ubunutu, it's throwing Import error on random lib modules.
 
I am able to print the entire string from an html page but split() is causing error @Dodge
 
6:12 AM
post a short piece of that string
 
<p>The HTML lang attribute can be used to declare the language of a Web page or
a portion of a Web page. This is meant to assist search engines and browsers. </p>
<p>According to the W3C recommendation you should declare the primary language
for each Web page with the lang attribute inside the &lt;html&gt; tag, like this:</p>
My code is counting the entire<p></p> as one len
 
It's either not a string or the conditional that you are using to increment your counter is not right, assuming that the code you have posted is the code you are using
 
>>>html = requests.get("https://www.w3schools.com/tags/ref_language_codes.asp")
soup = BeautifulSoup(html.text, 'html.parser')

# We get the words within paragraphs
for p_count in soup.find_all('p'):
    print(len(p_count.split()))
this is the entire code....
 
Ah silly mistake! I was providing module name including the extension, however pydoc only requires the module name. Thanks to this Ned guy's answer
 
@MunishGupta :'D I am rotfling here. Idk what the split on soup elements does, but you want to do p_count.text.split().
 
6:24 AM
Generated html looks dirty, guess I didn't work well on documenting code.
 
@MunishGupta the problem is that .foosadfasdfasdfasdfasdf on soup elements will try to return the attribute by that name, if there is no other meaning, or None if there is no such attribute. It is rather stupid indeed...
 
@AnttiHaapala split and then count the number of words.
 
@MunishGupta It works perfectly fine
import requests
from bs4 import BeautifulSoup

html = requests.get("https://www.w3schools.com/tags/ref_language_codes.asp")
soup = BeautifulSoup(html.text, 'html.parser')
for p_count in soup.find_all('p'):
    print(len(p_count.text.split()))
#31
#25
#12
#6
#14
#7
 
6:39 AM
cbg all
 
cbg @toonarmycaptain
 
@Dodge got it. One thing was missing that is (.text). Thank you. Now finally I can move ahead. Appreciate it.
 
Realising that after being offline for most of Thanksgiving, I'm starting AoC behind the pack this year - but I will be trying to keep up!
^ putting this in here in hopes that I'll actually stick to it by publicly announcing ;)
cbg and rbrb @Dodge - I'm for bed. Hope all is well.
 
@MunishGupta No problem, thank Antti becuase 'e is the one who provided the exact syntax you were missing
 
sure than. @AnttiHaapala. thank you for your help. Really appreciate it.
 
6:49 AM
@MunishGupta If you want to count unique words, then it's more efficient to use a set than a list. But in either case, you don't need countP. Just use len on the set (or list). All of Python's container types store their length as an attribute, and you can retrieve that length with the len function.
 
user10984358
today's AoC is kinda of like a stepped down synacor challenge? I never got into that, too high for my level
 
7:14 AM
Can I solve day 1 first? and then move to day 2.
 
you can do them in any order as far as i know
 
Cool! I am new to AoC; so I am checking this blog first: medium.com/@bruntonspall/…
 
@αԋɱҽԃαмєяιcαη It's not a big deal, but when you post a cv-pls request, you should mention the reason why you think the question should be closed.
 
@PM2Ring Alright, next time i will do. thanks for explaining
 
It's weird that the OP edited their code out of the question. I didn't bother looking at the code, but I guess from the comments that the code wasn't very applicable...
 
7:24 AM
he mixed things :S
 
user10984358
If dir(object) gives me a list like so ['file_name', 'file_size','file_created_date','folder_or_not'.......] and when I do object.file_size it will return the size, how can I do this if I want all the attributes that start with file_, I tried iterating for i in dir(object). and if.i.statrswith('file_'): question is how do i do object.i ?
 
user10984358
if its a method i can do methodcaller
 
getattr(object, i)
 
user10984358
no imports needed?
 
nope
 
user10984358
7:28 AM
what is this thing called? I didnt know what to search for :/, tried some crazy keywords
 
user10984358
getting attribtues I guess
 
googling "get attribute by name" would've done it
 
@αԋɱҽԃαмєяιcαη If people disagree with your reason, they can tell you why. :) Actually, it's mostly important for borderline questions: if a question is very bad, that's usually obvious at a glance. It's also good to know if a question is a dupe: if there are gold badge holders active in the room it's a waste for other people to cast close votes on it (although of course they may propose alternative dupe targets).
 
user10984358
I even went to the lengths of using exec lol, thanks!
 
@TheNamesAlc Yikes! There's also a related function in operator, but it doesn't get used much. docs.python.org/3/library/operator.html#operator.attrgetter
 
user10984358
7:38 AM
attrgetter(i)(object) instead of getattr(object,i), the latter seems easier to read, but the former is good for TIL as it complements methodcaller
 
user10984358
if you are using map or something you would use that i guess
 
@TheNamesAlc Exactly. Or itertools.groupby, or sorting a list of objects by 1 or more attributes. All those use cases are parallel to the cases where operator.itemgetter is useful.
 
7:57 AM
operator.itemgetter is way faster than a lambda fucntion.
 
do I smell micro-optimization?
 
@Aran-Fey no.
 
8:11 AM
Does Python unittest self.assertEqual parameters have any order. Example: self.assertEqual(expected, result) vs self.assertEqual(result, expected) ?
 
@variable just check
 
Checked that self.assertEqual(expected, result) is right
Can you point me to documentatiton that suggests this please - I am referring to docs.python.org/3.6/library/unittest.html
 
before you get any deeper into the standard libraries's unittest module, pytest is considered better by most.
e.g., even though it's a third party package that needs to be installed, it enjoys wider usage than something that is bundled within python itself: jetbrains.com/research/python-developers-survey-2018 (ctrl+f for pytest)
 
@AnttiHaapala Assuming you're not using the pure Python implementation. ;) github.com/python/cpython/tree/3.8/Lib/operator.py
@Aran-Fey Conversely, using a lambda (or any function implemented in Python) instead of a stdlib function implemented in C is a code smell, IMHO.
 
8:26 AM
I'd agree if operator.attrgetter('foo') wasn't so long and had no parentheses
 
I have used from operator import itemgetter as ig, but that's probably a bit too short. :)
More commonly, I do ig1 = itemgetter(1), eg if I want to sort & then use groupby.
 
hey guys, is there a good guide on setting up a function to have checkpoints you'd recommend. I'm about to use spark to try and extract a subset of data from ~1TB worth of files and would like to make it so if it crashes I can pick up where I left off
 
@Skyler spark is a totally different beast...
usually you can't recover...
... perhaps you'd want to do it in slices
 
The way my data is structured I kind of get slices
 
what I mean is run 1000 jobs for 1G slices...
 
8:40 AM
Im walking over ~125 bz2 files (250GB compressed) and extracting a much smaller subset of all the row-delimited json in it to a parquet to make the rest of the analysis faster
 
Do you guys think this question is kinda dupe of this question ?
 
for now a simplistic checkpoint system is fine, I do an OS.walk to prep a list of bz2 files to crawl over, so if I had to do a relatively dumb system where I even just restarted at the file I was on that would work, it'd just mean that I need to scrub duplicate rows on the final smaller set.
 
Because I can see the OP is passing module argument not correctly.
 
For now I was half thinking of writing the completed ones to a file and just checking if they exist to figure out where to pick up in the case of a system outage, I just was wondering if a more pythonic way exists I should learn
@AnttiHaapala is what I'm saying making sense or should I rephrase it? basically I just want to be able to pick up where I leave off in this one-time function in the case of crashes
but I'm not familiar with setting up checkpoints outside of a little bit of using tensorflows training checkpoints
 
9:03 AM
@TheLittleNaruto Maybe, but it's puzzling that the OP of the new question says "If i will remove config, it works fine and html gets created but does not work with config file." So I'm not comfortable closing it as a dupe, but I'll link them with a comment.
 
@TheLittleNaruto While the argument seems fishy, I don't think the error is related to it. OP should provide more information, the description is rather obscure and error message is minimal.
 
hey if i send an email over a openvpn connection, there is no need to additionally encrypt the mail using ssl or tls?
 
I'm guessing config.py is just not a valid file and cannot be imported due to errors.
 
9:19 AM
do you guys use two password managers one for private matters and one for work? Or do you use one for both?
 
May 31 '18 at 9:17, by PM 2Ring
I use this for making passwords, which you can read about here. I guess I ought to use something a little more secure, since SHA-1 isn't as secure as it was once thought. Actually, I should tell Tab (aka Xanthir) to get his act together and upgrade it: he's still a regular on the xkcd forums.
 
user10984358
for what its worth I dont use, I just use the default browser one, it also suggests me some random passwords when I create new ones
 
(For that application, SHA-1 is probably adequate, though).
 
9:34 AM
Hi all, trying to make a python program that reads my .txt files into a csv, however when i add to the dict i get a keyerror (from what I believe, this method should create a new entry into the dict but i get key error: 10)
```
import glob, os
import csv

csv_dict = {}

for file in glob.glob("*.txt"):
file_name = file.split('_')
policy = file_name[0]
level = file_name[3]
data = open(g).read().splitlines()
csv_dict[level][policy] = data

with open('my_csv_file.csv', 'wb') as f:
w = csv.DictWriter(f, csv_dict.keys())
w.writeheader()
w.writerow(csv_dict)
```
 
@rshah Sorry, triple backticks don't work in chat. I see 2 problems. What's g ? The main problem is csv_dict[level][policy] = data. I guess you want a dict of dicts. There a couple of ways to achieve that. A defaultdict is probably the simplest.
 
How exactly do you intend to convert a dict of dicts to csv?
 
As for posting code, see sopython.com/wiki/… which is linked in the starboard.
@Aran-Fey That's also a good point. :) A list of dicts would be more usual.
 
@PM2Ring Sorry, g is file
in the for loop
 
Well dicts are ordered now so... :P
 
9:45 AM
This is python 2.7, unfortunately working in mininet VM
 
it's almost 2020.
People really should be moving on. sigh
 
Tell me about it.
 
@rshah Ok. We prefer that you post the actual code that you've been trying to run. Otherwise, we can end up debugging non-existent problems.
 
import glob, os
import csv

csv_dict = {}

for g in glob.glob("*.txt"):
    file_name = g.split('_')
    policy = file_name[0]
    level = file_name[3]
    data = open(g).read().splitlines()
    csv_dict[level][policy] = data

with open('my_csv_file.csv', 'wb') as f:
    w = csv.DictWriter(f, csv_dict.keys())
    w.writeheader()
    w.writerow(csv_dict)
That's the code I am using
The files are formatted like policy_i_chain_j_levels.txt
 
@rshah jesus, 2020 and ppl are still using 2.7
 
9:48 AM
tell them about it
 
@Hakaishin Got that right, go yell at the mininet devs
 
@Hakaishin what timezone are you in? :p
 
I suspect we'll still be seeing 2.7 5 years from now though
 
gmt+1 why?
 
Legacy and all that
 
9:49 AM
ah, i see yeah. i mean plus minus a month, time is relativ right :P
 
Mhm, the inertia and technical debt is a very real barrier. One i've only started to understand lately.
 
Jul 20 '18 at 16:00, by PM 2Ring
In the last couple of weeks I've seen questions from two people (eg https://stackoverflow.com/q/51386698/4014959) working in the Visual Effects industry. These people are forced to use Python 2 because the industry isn't planning to shift to Python 3 until 2020. See the VFX Reference Platform.
 
Breaking news in 2020: "we can't shift to python 3 now, that takes a lot of work!"
9
 
@AndrasDeak lol
 
@AndrasDeak (and Python 4 is probably out soon so we'll worry about it then)? :p
 
9:52 AM
yeah, it's only going to just break again
 
So, less than 18 months ago, I saw questions from 2 different Python devs working in VFX who were writing new libraries (not mere programs) for Python 2.
 
@toonarmycaptain I think you misspelled your name on the AoC wiki page
 
Umm... someone's obsessed with map... stackoverflow.com/questions/59135764/…
 
How to I find getting started pages to this: docs.python.org/3/library/email.html Google just returns me how to send emails. My use case is fairly simple, so I'm pretty sure I can just copy a tutorial snippet, but I can't find one
 
@JonClements so functional
 
9:57 AM
docs.python.org/3/library/email.examples.html found it, would be nice to add it to the left sidebar, instead of having to find it using google
 
@Hakaishin I suspect every builtin module has corresponding examples, which might complicate such a feature
 
@rshah Are i & j words or numbers? Do you want each row of the CSV to correspond to a whole file? How big are these files?
 
@PM2Ring The files are several thousand files long. i and j are numbers, but only j is relevant. The CSV will be levels - 5, 10, 15, etc. up to 50, with each level having columns under it - policy1, policy2, etc.
 
several thousand lines? (you can edit messages in chat for 2 minutes)
 
Yes lines woops!
 
10:07 AM
@rshah are your text files also CSV/structured column data files or just lines of text?
 
Just lines of text, each line is an integer
 
df = pd.DataFrame(data, columns=['Name', 'Phone', 'Email', 'Website'])
df.to_csv('output.csv')
if data is list of lists so why saving the output became slow ? even for just 2 list
 
Because pandas is not a csv reader/writer library.
(among other possible reasons :P)
 
@JonClements I'm always baffled that people insist on using tools they do not understand, for problems they don't understand at all.
 
10:09 AM
but if i unpacked the list of lists ! it's write to output csv in same second ! that's strange for me
 
@MisterMiyagi always baffling but not quite so surprising these days... :)
with open('my_csv_file.csv', 'wb') as fout:
    csvout = csv.writer(fout)
    csvout.writerow(['policy', 'level', 'value'])
    for filename in glob.glob('*.txt'):
        parts = filename.split('_')
        with open(filename) as fin:
            csvout.writerows([parts[0], parts[3], int(line)] for line in fin)
@rshah I think what you're probably after is something like ^^^
 
@αԋɱҽԃαмєяιcαη incidentally something like ^ that would help you too
 
@Hakaishin there is a lot of 2.7 legacy code around, and not enough manpower to migrate it -- especially external dependencies that no one owns anymore. We're probably going to keep running 2.7 for a few years as well.
 
shudder
 
@MisterMiyagi I thought you were in academia
 
10:12 AM
heck... people are still using COBOL systems because it works and what's the point in re-writing it when you don't need to :)
 
@JonClements that would imply that there are no more COBOL devs needed :P
 
@AndrasDeak indeed, but we need lots of servers to do all our science stuff. If I have to pitch "let's hack together some stuff that gets papers published" versus "let's maintain our infrastructure" I can tell you with 95% CL which one gets picked.
and our branch already has significantly more focus on infrastructure than others.
 
I was trying to allude to the infamy of code written by scientists ;)
 
@JonClements Thanks! Now to import this into R ;)
 
@AndrasDeak I have to challenge such rumours. We're much, much worse.
 
10:20 AM
recbg
 
@rshah I'd be surprised if you couldn't use R to do this from the start instead of preprocessing like that in Python :)
 
@JonClements the less R the better...
 
If you can do some work in one language, it's better not to fragment your setup environment to support multiple languages
 
@AnttiHaapala preach
 
Otherwise agreed :P
 
10:25 AM
I dont have R inside the VM, so needed to preprocess a large number of data files into the CSV so I can just upload that
 
@rshah to the choir
 
i see. i ever installed them in 3.7 version on august. and it worked well, no error. today i reinstall my windows and install new python. thanks for your respond sir. God bless your brain — Onta Ss 2 days ago
> God bless your brain
 
hehe
 
I'm stealing that one
 
try:
    df = pd.DataFrame(data, columns=['Name', 'Phone', 'Email', 'Website'])
    df.to_csv('output.csv')
except PermissionError:
    print("Please Close The File")
 
10:32 AM
that's getting worse, not better
Why are you still trying to use pandas to write a list into a csv file?
 
@AndrasDeak you always down my Morale . haha
ok tell me the correct way and i will do ! better than keep asking me why I'm using pandas :@
 
@PM2Ring Okay! I'll add that as comment. Looks like you added already.
 
@αԋɱҽԃαмєяιcαη it's okay to use pandas in general, but "data -> create dataframe -> print csv from data -> discard dataframe" is a good sign that you should be using the builtin csv module instead
 
@MisterMiyagi I think OP would have forgotten about this question; and hence it highly unlikely that he will respond back,. What do you think?
 
I pinged you when Jon posted some code using csv.writer...
 
10:35 AM
@TheLittleNaruto I already did that.
 
@AndrasDeak got it now :P
 
Is it normal that pythons EmailMessage class is bad with Umlauts? Right now I just decided that I will change all umlauts to ae, ue, oe, but this seems very wrong
 
Jun 7 '18 at 14:54, by PM 2Ring
If your only tool is Pandas, then every problem looks like bamboo.
 
@Hakaishin could you elaborate?
 
10:37 AM
:)
 
I like this PM2 quoting himself day... much more exciting than this Cyber Monday rubbish :p
 
b'Subject: Test, Film: 42, =?utf-8?q?F=C3=A4lle=3A?= 3'
Once it hits an umlaut it just jumples it and everything afterwards
 
that library should be fairly good - are you sure it's not the mail system itself doing something odd... have you checked what the specs say (some RFC somewhere)?
 
@Hakaishin UTF-8 in a bytes string isn't very readable to the average human.
 
@TheLittleNaruto yeah, I forgot to check the question's age until after commenting. Perhaps the comment is useful to someone with the same problem, still.
 
10:40 AM
python -m smtpd -c DebuggingServer -n localhost:1025
Im running my test server like this
@PM2Ring so you mean a better smtp server would display it properly? Or is it the windows console who can't do it?
 
No, that's some special kind of encoding. I have vague memories of seeing that before, argh
 
@Hakaishin Well originally SMTP was a pure 7 bit ASCII protocol. But there are ways of dealing with UTF-8. Wikipedia has a short article: en.wikipedia.org/wiki/Unicode_and_email
 
Do you have a really good link to SOLID design principles that you cherish and follow?
 
with open('output.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    writer.writerow(['Name', 'Phone', 'Email', 'Website'])
    writer.writerows(data)
done @AndrasDeak now it's works
 
amazing :P
I'm a bit surprised at newline='' but I've never actually used the csv module
 
10:45 AM
@PM2Ring I assume everything was orginially ascii :P but it's 2020, and I wanna know and what part in the system I have to be mad at and switch out with a newer one which can do utf8
:D
 
Can't you, uh, set some content header that tells to use utf8?
I have no idea how any of this works, but perhaps if encoding doesn't have to be put inside a field it might stay readable?
Hmm, come to think of it, it's weird that you have bytes and mangled data.
(even if it's clearly not just a usual mojibake)
 
@AndrasDeak newline='' is the correct way to open files for csv writing/reading in python 3
@JonClements is still stuck in python2, opening files in rb mode instead ;P
 
Neat, thanks. I take it csv.writer handles the newlines on its own
 
Yup. It's required for correct handling of multi-line values, if I remember right
 
I guess it makes sense. Partial rows and whatnot.
I still don't accept csv with newlines in the values though :P
 
10:49 AM
@Hakaishin That stuff you posted looks like it's using MIME "Encoded-word" en.wikipedia.org/wiki/MIME#Encoded-Word
 
it's just remove the new lines
 
@Aran-Fey hahah... nope... was just going by the OP's line :)
 
try:
    with open('output.csv', 'w+', newline='') as file:
        writer = csv.writer(file)
        writer.writerow(['Name', 'Phone', 'Email', 'Website'])
        writer.writerows(data)
except PermissionError:
    print("Please Close The File")
can i return the operation if the file is closed by the user ?
 
"return the operation"?
 
10:52 AM
I mean, if the user closed the file, so i want the write operation to continue
 
do you mean "resume the operation"?
 
retry the whole operation until it works I guess
 
@αԋɱҽԃαмєяιcαη Probably. Use a loop. And do something like input("Press Enter to continue after closing the file") so your program will wait.
 
Given this CSV file, gist.github.com/ryankshah/84f68893d8ef89e5e0d679d0f5f0b25d, how can I prepend a column that stores integers that increment per row -- I need this for my dataframe to work
 
11:03 AM
@rshah err... isn't that something you could do in R?
 
@rshah you want to enumerate your CSV rows?
I'm decently sure R has this builtin as well
 
@JonClements Whatever I've attempted in R doesnt work! haha
 
also - do you mean incrementing per within each group of policy/level or whatever or across the whole lot?
 
across the whole lot
 
@rshah have you considered asking this in an R channel? This is pretty basic functionality and I'm entirely sure that R handles this out of the box.
 
11:07 AM
given that it's combined from multiple files that may have been globbed in any order... is that even meaningful?
 
this question suggests you have to try hard not to have an index
 
@MisterMiyagi I've figured out the problem.. its not with the numbering, you're right R does this. Thanks :)
 
@Andras ahh... that's more explicit than how I put it :)
 
@AndrasDeak This is the issue, Is there a way of preserving order or would it be better to sort the CSV?
 
11:15 AM
can't decide what's more embarrassing: That they made this error or that their results did depend on it.
 
@rshah You can always sort your files with a well-defined order. Just don't expect glob to do that.
it's always safer if you bind your files to some objective parameter, rather than the order in which you see them
 
There certainly is a way to preserver the order, but why would you want to iterate over the files in the order your filesystem has stored them?
 
user10984358
@JonClements for that question this is even terrible, list(map(lambda x:list(map(add,x[0],repeat(x[1]))),zip(map(range,l2),l1))) though you will have to flatten the end result :p
 
user10984358
I just wanted to refer that question not ping him, idk how to do that without replying
 
@TheNamesAlc map(range, l2) won't cut it, because they need [l2[i] for i in l1] first...
 
11:18 AM
@AndrasDeak All the files start with a policy name, for which there are 4 different ones, and the file name is like policy_x_i_j_etc..
 
user10984358
i ran the code they posted and other than mine being a list of lists it matched, [[0, 1], [1, 2, 3, 4], [2, 3, 4, 5, 6, 7]] ? am i missing something
 
@TheNamesAlc because l1 is just range(3), so indexing with it is a no-op
someone asked OP if that was always the case, got no response
@rshah yes, your original that used x and whatnot as labels made sense to me. That's not relying on any order. Relying on order would be appending your files into a list, and then doing something based on the position of the data in the list.
 
Or, since it's a small dataset, just sorting it into some order in R and then resetting the index or... or... or...
 
user10984358
ahh, didnt see that, also in a similar episode a terrible one liner for calculating the size of a folder, had to snuck in attrgetter after getting to know thatsum(map(attrgetter('st_size'),map(methodcaller('stat'),filter(Path.is_file,folder_path_obj.rglob('*')))))
 
methodcaller is more esoteric than attrgetter I think
 
11:25 AM
I wonder why pathlib objects don't have the equivalent of os.path.getsize()
 
don't they have .stat?
 
user10984358
its a wrapper around os.stat() or os.path.stat()
 
they do... but I'd have thought it's such a common thing... you'd convenience function it
 
user10984358
I was messing with that, type(path_obj.stat) gives <class 'os.stat_result'>
 
using Path.is_file (or Path.anything, really) is extra bad because there's no guarantee that method exists or does what you expect
(because for all you know, the actual implementation might be in PosixPath or WindowsPath)
 
user10984358
11:29 AM
and they still have is_file method defined don't they?
 
As of right now, they do, yes. Tomorrow? Who knows
 
user10984358
fair enough, i resorted to a gen exp after that
 
Still, sum(path.stat().st_size for path in path_obj.rglob('*') if path.is_file) is more readable :)
 
am I the only one reminded of turkeys when I see glob?
 
are you confusing glob with gobble?
 
11:33 AM
close enough for my brain
 
that is the name we given to the noise turkeys make isn't it, "gobbling" or something?
Gobble. The gobble is a loud, rapid gurgling sound made by male turkeys. The gobble is one of the principal vocalizations of the male wild turkey and is used primarily in the spring to let hens know he is in the area.
ahh... yes, it is... good... not going mad then :p
(or more so than usual anyway)
 
@JonClements yup
it's the onomatopoeic word for turkey sounds
 
I'm sure there's far less gobbles in the world after thanksgiving... but there's a respite until xmas I guess :)
 
@AndrasDeak So as I understand this would be rendered correctly on a proper email client? Is there such a test smtp client I can run locally?
 
59 mins ago, by Andras Deak
I have no idea how any of this works, but perhaps if encoding doesn't have to be put inside a field it might stay readable?
so anyone else should feel free to answer ;)
if you weren't on windows I'd suggest using mutt or pine or some other terminal-based email client
 
11:49 AM
@Hakaishin umm... have you got something like outlook/thunderbird installed you can setup to use? That or use smtplib ?
 
@TheNamesAlc assuming they always want + or -, this can actually be fairly short by pushing the operation into range. Still much more obscure than the loops...
 
@JonClements ok my bad. I am using stmlib to send emails, but I only "receive" them using the python built in localhost smtp server which displays the messages in the terminal
 
@MisterMiyagi yup. I didn't want to mention that to OP because their whole approach is flawed and I didn't want to encourage them.
 
@Hakaishin you got a throwaway/gmail account or something you can use?
 
I guess that's the way to go
I'm still not sure how to phrase this, but i would like e.g. outlook to listen to emails received on localhost.
Basically when I do this, I should get an email in outlook, is that possible?
with smtplib.SMTP(smtp_server, port) as smtp_server:
    # smtp_server.login(mail_config["sender_email"], mail_config["email_password"])
    smtp_server.send_message(msg)
 
user10984358
11:54 AM
I saw both of your answers, I am yet to use starmap, conceptually I believe doing things like what OP asked makes you remember how stuff work, they tend to ask questions like that, dont use this but this at interviews, been a victim of those
 
@Hakaishin you need something outlook can "receive" from... smtp just delivers something to somewhere... can you setup a test imap server?
or... failing that... go for a gmail account, setup outlook to receive from that, and then send your tests via smtplib to that account (basically send it to yourself)
 
then can't it receive the mail from my python script? right now smtp_server is just "localhost" and that works with the python smtpd
 
@Hakaishin There's this in the stdlib for doing MIME stuff with emails, but I've never used it myself. docs.python.org/3/library/…
 
@Hakaishin smtp is for delivering... outlook needs either imap/pop3 to get the email
 
12:12 PM
@TheNamesAlc I just don't think that's a way for the OP to learn it. The challenge is doing the logical transformation, for which math and stream languages are more appropriate. Solving it with Python is possible, but it obscures the actual transformation by reversed layers of iterators.
 
What is a good resource to learn about architecting applications, design patterns?
 
such as SOLID you mean?
 
2 hours ago, by variable
Do you have a really good link to SOLID design principles that you cherish and follow?
So yeah
 
Ok problem solved, it's just the debug server which cant do utf8, gmail works
 
It probably can. What it can't/won't is quoted-printable decode
 
12:19 PM
@AndrasDeak not sure what that means
 
ah right, I thought it's that, was to lazy to scroll up :P
 
not touching that one...
 
No not SOLID. I am asking for design patterns, mvc, mvvm, and topics around architecture
 
user10984358
@MisterMiyagi if that is what they expect then what you say is true, say for reversing a list, you can't do seq[::-1] and call it a day, you have to do manually do a loop, I meant from a python specific interview where they are testing you solely on your python dev skill, in which case seq[::-1] is apt
 
user10984358
12:35 PM
@JonClements reminds of the LCS dynamic programming question
 
@JonClements "needs focus"
 
thought I had... but have now
seems like: set(s1).intersection(s2, s3, s4) would work, but doing it recursively... youch
 
12:53 PM
@TheNamesAlc I don't doubt there is some madman out there thinking it's a good interview question. I doubt getting a Python solution to it on SO is proper learning material.
 
00:00 - 13:0013:00 - 00:00

« first day (3334 days earlier)      last day (1618 days later) »