« first day (2442 days earlier)      last day (2499 days later) » 
00:00 - 18:0018:00 - 00:00

6:02 PM
Actually "I just happened to be standing in this spot and the meat packing district sprung up around me" isn't a terrible justification for having a druid live in a city, if you happen to be a race that outlives civilizations
"I don't really pay it much mind, I expect this to all be trees again soon enough"
 
the city sprung up around a mystical tree that the druid protects
 
and he's too much of a woosie and didn't slaughter all those stupid humans who built the city
 
I was definitely thinking of that bit from The Dark Tower with the rose in the vacant lot that turns out to be highly plot relevant
 
perhaps he lives next to the equivalent of central park
large city complete with forest, parts of which are best not visited
he can stick close to the woods and only sneak out when he needs something from the plebs
 
Waterdeep has a big park but it's infested with undead apparently
 
6:16 PM
Hmm...Lorien-like tree housing is not an option, right?
the undead would be great to keep unsolicited visitors away
 
I assume level six adventurers don't really consider zombies a threat but that's when you're all kitted out and rested, not when you nip out to the outhouse at 3 AM in your pajamas and something grabs your ankle
 
@idjaw my friend told me that 'Mr Steer' has really good burgers, can you vouch for that statement? Or is it over hyped?
 
6:35 PM
I wanna play DnD with room6 :(
 
room6 is a collaborative storytelling exercise whose participants answer programming questions during downtime.
 
I've never played DnD with multiple DMs.... What happens when one DM is in disagreement with another ?
 
They make their own room.
 
Going off to different sides of the story while still maintaining the common objective, nice... now that's real story telling. I'm assuming you may only follow one DM unless you can clone yourself
 
is it correct for me to say that len([1 for _ in gen]) is better than sum(1 for _ in gen) when we want to count the length of a non infinite generator ? I ran some timeit test and it seems like len wins out based on time, but I'm not sure how to test for memory
 
can we write some JS/otherMagic to create a little widget that automatically prepends a question with [tag:cv-pls] and posts it to sochat?
 
I'll do it for $5
 
@MooingRawr in general len([1 for _ in gen]) is worse than sum(1 for _ in gen)
sum(1 for _ in gen) doesn't create a list in memory
 
well, if that gen is huge, you're going to run into issues with memory allocation. Then again, 1 is interned and singleton, so I'd imagine the memory footprint to be tiny. Still, the list will need to allocate space, so you /will/ run into memory issues there
 
6:56 PM
My expectation is that list comps win for shorter generators but as the size increases they slowly get swamped by increasingly expensive memory allocation
 
@KevinMGranger I might actually take you up on that. copy/pasting with [tag:cv-pls] is getting annoying
 
I was joking, it's something I could make eventually. Probably not this weekend though
 
Meanwhile sum(1 for _ in gen) chugs along at a reasonable O(N) for as long as necessary, experiencing no slowdown, save perhaps for a blip when it switches from int to long int
 
^ sum(...) O(n) time and O(1) space. len(...) O(n) time and O(n) space
 
🍓
 
7:01 PM
@vaultah oh wait.... i was using timeit wrong.... >< Nvm.... I remember reading on here that sum(gen) was better than len([gen]) but my test showed otherwise, turns out my test was wrong.
 
out of curiosity, how do you use timeit wrong?
 
import timeit
print(timeit.timeit('len([1 for _ in range(1000)])'))
print(timeit.timeit('sum(1 for _ in range(1000)'))
Doesn't do what I thought it does.... serves me right for not looking up the docs for timeit.
 
Anyone here like Eric Andre?
 
I. Don't. Care. About. Baseball.
 
I caught ten minutes of his show once and I didn't really get it
 
7:06 PM
Hi, Im a pretty new programmer and have always wrote classes all in one file. Im trying to learn how to split one of my existing projects into a package but am having trouble understanding the logic of how its formatted. The program i have is an app that has a menu gui screen and then leads to a new screen that has a game. What do i put in init.py and when do i open the app class
 
It starts to make sense about ten minutes and one second in
 
lol ^%
Any interview Eric Andre is in, is just crazy, he can't be tamed
Theres this guy named nardwuar who interviews really famous people and deep dives on them with info from their childhood
He breaks down the barriers of these people and its really interesting to see how they react to the information
 
I've tried making one of my projects into a package once and at the end of the process I had just as much understanding as when I started
 
@Kevin haha yeah I mean I was told not to open my app class in init but then idk how it gets opened
 
7:11 PM
you're confusing two things here
 
You're supposed to somehow indicate which of your .py files is the "main" one. I guess that information goes in... setup.py?
 
splitting your project into multiple files, and turning it into a module
 
Oh yeah if you just want to have a program that uses multiple files, and don't want to have "a package", that's easy
 
you have a file that, when executed, starts your program. You'll always need that, regardless of whether your code is all in one file or not
and then if you also want your project to be importable, then you'll need to make an __init__.py file as well
 
Oh ok, so what is a package then compared to just split?
I always thought a package was just a program which classes split into different files
 
7:16 PM
If you just have a bunch of files in a folder, python doesn't see that as a module, so it can't be imported. But if you add an __init__.py in that folder, that tells python "hey, this folder is a module" and then it can be imported
 
That makes sense, yeah i dont need this to be imported.. thank you @Rawing
 
we really need a canon for how to split up your project to multiple files :\
I remember looking up this topic, found this : python-guide-pt-br.readthedocs.io/en/latest/writing/structure never read it though... Honestly I forgot about it until now..
 
step 1: split code into multiple files
step 2: add imports, and realize you have a cyclic import somewhere
step 3: ????
step 4: give up on trying to solve your problem properly, and employ ugly hacks like lazy imports instead
at least that's how it usually goes for me
 
My company just slams all the projects into one solution (c#) :D
 
@MooingRawr Good idea. However, reading the intro in the docs on modules and packages is probably a good starting point.
 
7:22 PM
Right on :D I find Python has one of the better docs. I really REALLY hate reading Microsoft's c# docs >.>
 
I rarely have cyclic import problems, thanks in part to Python's dynamic typing. widget.py does not need to import sprocket.py even if Widget.frobnicate(sprocket) typically takes a Sprocket instance.
If I only ever call frobnicate from main.py, then only main.py needs to import sprocket.
 
that's funny because snakes are known to not have the sharpest vision
 
O M G! That has to be the best thing since sliced bread
 
there are also userscripts that buff up cv-plses sent to chatrooms, giving you votes, age etc.
 
test = test1 = list(randint(1,3) for x in range(10000))

Is it possible to make these variables not point to the same list, without copying from the first variable to the second?
like:
test = list(randint(1,3) for x in range(10000))
test1 = test[:]
 
Don't think you can manage that on one line without some serious trickery
 
That's pretty much how it's done - what is the problem?
Code golfing?
 
&gt; not point to the same list &gt; without copying ??? I give up
 
also, you seem to be asking "can I copy a list without copying a list" ...
 
7:37 PM
Perhaps the question is "can I copy the list without doing [:] specifically?"
 
I don't know I just thought that there might have been a way.
 
you should also make sure that you don't want to generate 2 independent lists of 10k length instead :P
 
There's always copy.copy I guess
 
you could- kevin'd sigh...
 
But I guess it doesn't get better than this right?
test = list(randint(1,3) for x in range(10000))
test1 = test[:]
 
7:39 PM
That's about as short and concise as you can make it yeah
 
I think that's fine
but if anybody else will read your code (which includes "you 6 months from now") you should use more meaningful variable names (assuming these are not just dummy variable names for the MCVE)
except...
how about using a listcomp instead of list(genexp)?
 
DSM
I tend to use .copy() these days more than [:], but apart from that, it seems fine. You could one-line it if you wanted to in a few ways but they'd all be much less clear.
 
yeah, don't tell him those :P
 
Regular brain: `seq[:]`
Enlightened brain: `copy.copy(seq)`
Galaxy brain: writing pure functional code with no side effects so it doesn't matter if two lists are referentially equal or not because you aren't going to mutate either one
 
test,test1 = map(list, itertools.tee(random.randint(1,10) for _ in range(100)))
 
7:43 PM
nice fresh memes
 
DSM
@PaulMcGuire: hmmph, I had a,b = map(list, tee(randint(1,3) for x in range(10000)))
 
What is the "tee" for/doing?
 
isn't copy() slightly slower than [:] ?
 
Sorry, did I miss your post?
 
7:44 PM
nvm
 
test, test1 = (lambda x: x, x[:])([randint(1,3) for x in range(10000)]) #don't actually use this please
 
DSM
No, I was just complaining that was one of the ways I didn't want to post because it was unclear. :-) Also: a,b = map(list, [randint(1,3) for x in range(10000)]*2).
@Kevin: no need for the copy module, copy's a method of list now.
 
Oh, rad.
I think I knew that, deep down.
 
I wasn't aware tee works with iterators... interesting
 
itertools is magic
 
7:49 PM
Man I really need to get into the habit of writing valid tests. Maybe I should write tests for my tests :D
copy is not slower than [:] .... :\ I just had an invalid test ...
also could we not use list() instead of copy() and [:] ?
 
DSM
Yep.
 
I guess copy module exist cause deep copy is useful and you might as well have a shallow copy as well..
 
In [33]: *a, = b = [randint(1,3) for x in range(10)]

In [34]: a is b, a == b
Out[34]: (False, True)
5
 
DSM
Plus you might want to copy something that doesn't have a copy method. Tuples, for example.
 
Unpacking assignment FTW
 
7:54 PM
Why copy a tuple? Multiple refs to the same tuple are safe
 
DSM
@vaultah: WHAT
 
@vaultah Nice.
 
DSM
@PaulMcGuire: true, but I can imagine wanting a copy function which is more content-agnostic.
 
@vaultah - Dang!
 
DSM
I'm looking at that and I still can't believe it works.
 
7:57 PM
 
I have a question on snapchats new snap map
Since snapchats feature is based off of the amount of snaps occurring at x location (sort of like a heat map, the brighter the color, the more events happening in that location), so as a user, you can see what's going on in that location.
 
HA! Tricked you into staring that
 
Couldn't someone write a program to where a snap is taken every 30 seconds in said x location so the map could 'heat up' and other users could view that location to see what's going on? If this is possible, couldn't advertisers exploit this feature and sell their products or services to whatever users click on the map?
 
@faceless I'm happy to say I have no idea what you're talking about
 
hahaha *just millennial things
 
7:59 PM
you monsters
 
I only use snapchat because of my girlfriend
for tha nudes
giggity
 
@inspectorG4dget ops = [operator.add, operator.sub] could be a tuple, since you don't need to modify it. OTOH, I think that your code is overly complex. A simple int to hold the direction is probably cleaner & easier to understand.
 
I was bored, so I slightly complexified it
@vaultah but how is that even syntactically correct?
 
why should it not be?
 
huh so unpacking and repacking also works as a copy.... but that make sense I suppose
 
8:04 PM
>>> a = range(3)
>>> a
range(0, 3)
>>> *a, = range(3)
>>> a
[0, 1, 2]
at least it makes sense to me syntactically, and in hindsight it makes sense that a copy is created
 
@vaultah that's impressive if you thought/remember that, hats off to you sir
 
*a, = range(3) can be rewritten as (*a,) = range(3). Since there's only one thing in that tuple, that translates to *a = range(3), which makes sense
 
I just thought that *a, would make a tuple not a list since a, makes a tuple
 
so then does *a, = b = range(...) translate to (*a,) = b = range(...)?
 
>>> *a = range(3)
  File "<stdin>", line 1
SyntaxError: starred assignment target must be in a list or tuple
:P
I read *a, = range(...) as "unpack the iterable on the right side on assignment, but come to think of it consume it all in a sequence called a"
 
8:08 PM
But then thinking about it some more the * should turn it into a list....
Oh, it's a Python 3.x syntax... doesn't work for 2.x
 
woooooooooooow. I just got it
 
> Assignment of an object to a target list, optionally enclosed in parentheses or square brackets, is recursively defined as follows.
If the target list is a comma-separated list of targets, or a single target in square brackets: The object must be an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets.

If the target list contains one target prefixed with an asterisk, called a “starred” target: The object must be an iterable with at least as many items as there are targets in the target
I'm not sure that actually sheds much light on the subject
but source
 
@MooingRawr hah, I was just passively thinking about Sebastian's message when the idea came up, so it didn't happen instantly
 
@vaultah I would count that as instantly.... it was still on the spot... welp the reward of mind blowing fact goes to you this week.
 
8:30 PM
@MooingRawr I like P. J. Plauger's philosophy: the test code tests the main program, and the main program tests the test code.
 
@PM2Ring wise words to live by
 
8:59 PM
since it's Friday, what are some interesting python behaviors that look weird at first glance (not unlike *a, =b = [...] from before)?
 
I like transposing a list of lists with *zip(*:
z = [[1,2,6],[3,4,7]]
print(*zip(*z))
(1, 3) (2, 4) (6, 7)
 
9:16 PM
a = a[0] = [[]]
 
I like chunking stuff with zip, but this trick only works if your sequence has a whole number of chunks: a partial final chunk gets lost. You can get around that by using itertools.zip_longest to provide a fill value.
>>> list(zip(*[iter(range(15))]*3))
[(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11), (12, 13, 14)]
Totally unrelated, Python's floor division rounds towards negative infinity rather than zero, so, eg -42//5 is -9. That means you can use it for ceiling division: -(-42//5) is 9.
 
Andras I just tried running your code which resulted in some weird output: [...]
What does it mean? I can't insert items into that list for some reason.
 
it's a list that contains itself
basically a = [[]]; a[0] = a
 
That is so weird
 
python chooses to print that as [...] instead of producing infinite output
 
9:31 PM
Could it somehow be useful?
 
Speaking of which ... is a valid expression, you can use it as a placeholder in place of pass
 
Good question. I can't think of any situation where that'd be useful
 
if cond:
    do_something()
else:
    ... # um, figure it out later
You could use self-referencing list to test recursion limit error handling?
 
That's neat!
# a perfectly valid function
def func(foo=..., bar=...):
    return foo if ... else bar
 
Wow I didn't know that was possible, that's awesome.
 
9:43 PM
Also, I still don't understand why rubbish like print(-----++++---++-+-+2) is valid
You'd think one unary operator would be enough
 
@SebastianNielsen It lets you store a graph in a list, even if the graph contains loops. Although I'm not sure if that counts as being useful. ;) It's probably easier to write a Node class and give it some appropriate attributes and methods. But anyway...
>>> a[:]=['a',a,b];b[:]=['b',b,a]
>>> a
['a', [...], ['b', [...], [...]]]
>>> b
['b', [...], ['a', [...], [...]]]
>>> a[1] is a, b[1] is b
(True, True)
 
Wow, that is so confusing.
 
So we have a graph containing 2 nodes, a & b. Each node points to itself as well as to the other node.
 
Ahh I see
That is very impressive, programming is getting more and more interesting.
 
if you program like that, your code reviews will also be "interesting"
 
9:54 PM
Stuff like that isn't easy to read, and it's not easy to see what eg, a[2][2][1] is. A decent Node class with named attributes and useful methods for displaying the node data, its neighbours, and for traversing the graph in various ways is far more usable than trying to do it with lists. OTOH, lists are fairly cheap in their RAM use, so in some situations you might want to use such recursive lists rather than a more sane datatype.
 
wim
>>> def foo(*, kwarg='keyword only'):
...     print(kwarg)
...
>>> from multiprocessing import Pool
>>> pool = Pool()
>>> pool.starmap(foo, [[]])
keyword only
[None]
how do you do this
>>> pool.starmap(foo, [[], [kwarg='nondefault']])
  File "<ipython-input-20-d0aa061bcf35>", line 1
    pool.starmap(foo, [[], [kwarg='nondefault']])
                                 ^
SyntaxError: invalid syntax
without the syntax error , obvs
there must be a better way than writing a dumb wrapper function ..
 
What are some use cases for the assert condition?
does it always stop a program when assert False
 
getting a weird error about calling freeze_support() when I run that... first attempt at multiprocessing: not very successful
it might be worth a shot to pass a list of dicts to starmap though: pool.starmap(foo, [{'kwarg': 'whatever'}])
 
@faceless assert, does as the name, it asserts if the condition is True, if it isn't True. It will raise an error - stop the program.
Could be useful in a lot of cases.
 
then would you only use an assert when debugging?
 
10:05 PM
No not at all.
 
wim
@Rawing I doubt it Python can't distinguishing from wanting to pass through a dict as a dict (positionally) and a dict to be unpacked
 
yea, it'll probably be unpacked wrong. Doesn't hurt to try though.
 
@SebastianNielsen can you use a real world example?
 
To test if the status is 200 - when scraping websites using requests
 
You usually use assert to make sure you or another programming isn't doing something stupid, but it wouldn't make sense to throw an exception
 
wim
10:09 PM
@SebastianNielsen don't use assert for that
unless it's in a unit test
 
def func(arg):
    assert isinstance(arg, list), "You're supposed to pass a list here, dumbass"
 
wim
because that's not what assert is for
@Rawing don't use assert for that either
 
wim
assert is not for validating input
 
10:10 PM
if x < 1:
    ....
elif x>=1:
    ...
else:
    assert False # should never be reached
 
I would never write that, since there is no possible way the program ever would hit that state.
if x is a string, it would throw an error before even getting to the else statement.
 
wim
@SebastianNielsen and that's exactly what you should use asserts for
 
That just seems like a waste of lines of code.
 
wim
no
 
DSM
@SebastianNielsen: elapsed time to a counterexample -- about ten seconds.
In [3]: if x < 1:
   ...:     print("less than 1")
   ...: elif x>=1:
   ...:     print("greater than 1")
   ...: else:
   ...:     assert False # should never be reached
   ...:
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-3-709fcbd7ff6c> in <module>()
      4     print("greater than 1")
      5 else:
----> 6     assert False # should never be reached
      7

AssertionError:
 
wim
10:12 PM
they are a protection against your own assumptions being wrong
 
yea the type checking example certainly wasn't very good, but there are situations where an assert is an acceptable alternative to throwing a TypeError
 
wim
>>> float('nan') < 1
False
>>> float('nan') >= 1
False
 
DSM
@wim: hey, no spoilers. ;-)
IMHO asserts are there to detect programmer errors, not user errors. So using them to validate types is usually a misstep.
 
wim
here is a valid use of assert
 
I'll keep that in mind
 
wim
10:14 PM
things = [0, 1, 2]
thing = random.choice(things)
if thing == 0:
    # do stuff
else:
    assert thing in {1, 2}
    # do other stuff
 
But then I suppose faceless was right, that assert mainly is used for debugging. Since it's used to detect programming errors.
 
wim
they are for defensive programming:
- detecting errors in your own assumptions, and failing early
- protecting code from terrible accidents should it be refactored by yourself or other developers later on
e.g. future me goes and adds something else in the things collection, and my code below it had never taken into account that possibility
better to blow up with AssertionError than to cause data corruption or some other nasal demons
 
You are totally right, thanks for the explanation. :)
 
Any flask people here?
 
@wim answers here suggest that there isn't one
 
11:04 PM
There are nasal demons to worry about now?
 
wim
yeah I saw that .. almost 2 yrs old tho
 
@Jasch1 welcome to the room! Might I suggest you read the rules first?
 
how many hours a day do you guys program?
I want to learn progamming in 21 days
 
I guarantee you'll have a lot left to learn after those 21 days
 
NOt according to the link i posted
 
11:15 PM
I started reading "learn perl 5 in 21 days" when I was ~14. It took me more than 21 days and I never finished it.
 
if any book or other resource tells you there won't be much left to learn after 21 days, I'd seriously consider burning it
 
Aw did you read the link above @Rawing?
 
nope. I'm not sure what a .webp file is, how to open it, or whether I want to have it on my PC at all
 
but...quoracdn.net sounds so honest
 
It's a picture that uses the same compression as webm videos, or something like that
 
11:22 PM
firefox doesn't open it out of the box so I'm not sold
 
Yeah it's chrome-only for now I think
 
There, thats what it was
 
well in that case 21 days is more than enough I suppose
 
I like some of the comments on the imgur page
> After 21 days: if stupid write crappy replaceable code. If mediocre shitty servicable code. If clever write truly horrible impenetrable code
 
11:56 PM
Midsummer cbg
 
since we were talking about weird language constructs earlier: stackoverflow.com/a/14617232/2188562 (python 2 only)
 
00:00 - 18:0018:00 - 00:00

« first day (2442 days earlier)      last day (2499 days later) »