« first day (2123 days earlier)      last day (2843 days later) » 

4:00 PM
Uses less e-ink on my vegan-friendly ecotop.
 
Yeah it makes sense to me that @coroutine can use yield from but not yield, because the thing you're yielding from is either 1) following the same "don't yield things yourself" contract; or 2) written by someone who knows what they're doing (probably a CPython dev) and yielding a value that the event loop can read.
I suspect that's the kind of statement that, if someone else had written it, would make me think "your mental model of the underlying system is flawed in a way that isn't apparent now, but will lead to a hilarious disaster later, but I don't have the power to convince you of this"
The most expedient thing for me to do here, I suppose, is to stride boldly forward into the pitfall.
 
Here lies Kevin, his last mission: to boldy stride where no man has stridden before.
 
strud?
 
extruded?
 
4:15 PM
snort
 
or is that like... when you don't stride?
 
i think extruding is what happens when you're striding and you strode into a bollard
 
Extruding is when you push down on the lever of the play-doh spaghetti maker. I don't want to be the play-doh in this metaphor.
 
user559633
"Spa'get About It" would be a great name for a cooking show
 
4:17 PM
It's already a character from Tim & Eric. He hops out and scares people, but doesn't cook
 
lol. Nice.
 
I've often thought that a good name for a book / show about unusual Asian cuisine would be "Wok the fut?"
 
user559633
@corvid rip little puppy
 
@corvid Heh. The GF spent about a week just playing that on repeat the first time she saw it.
 
4:27 PM
hey
 
can someone just give help me decide between two different approaches to a problem? I'll be using PyQtGraph to generate a graph.
The x axis will have time in seconds, and the y axis will show the number of events for a given second in x.
The average rate will be 1 event per second. What do you think will be better:

Just have a list with all the y values. OR.
Have a table with the x and y values for every y(x)!=0
 
Neither one sounds objectively bad. I'd probably do it the first way.
 
@Kevin still not quite sure what a coroutine is. Is the degenerate case of a coroutine two generators yielding from each other until they finally produce a result?
 
@RobertGrant Technically, if I understand correctly... a generator is a coroutine
 
4:37 PM
hey guys
i use jython in a project
i think this language have some problems with maximum of nested if statements
 
Fair. I mean the simplest case of using a coroutine for what a generator wouldn't be useful for
 
is it true ?
 
Nope.
 
hmm are you sure ?
 
Not as far as I know. It shouldn't be any different from Python.
 
4:38 PM
I know the CPython parser does have limits for various kinds of things, ex. Number of literals on one line, but they're all up in the hundreds of thousands.
If your program has hundreds of thousands of nested ifs, consider refactoring.
 
@gtzinos on what evidence do you base your assumption that it might?
 
user559633
@gtzinos is the problem maintainability?
 
And what nesting level are you currently finding troublesome?
 
Git Flow question: why do hotfixes branch from master and not the known latest release, given that the known latest release should be in production?
 
That would be equivalent, because the release branch/tag gets merged to master.
 
4:43 PM
@RobertGrant Based on my (possibly flawed) mental model, a regular generator can do anything a coroutine can do, but a lot of the things you'd like to make a generator do, have already been implemented in asyncio, so you save time not reinventing the wheel.
 
You mean shouldn't hotfixes be applied sequentially? I'd agree with you. But don't forget, even a hotfix should be merged back into master, so if you installed the last hotfix properly (merging it into master) there should be no difference, should there?
 
Example: "I want to iterate over two generators together and print the value of whatever one finishes first" is completely possible, but you're going to have to write more boilerplate than if you had just used asyncio.wait
 
@holdenweb since we're talking about git flow, you mean that things should get merged into dev
 
@holdenweb sort of :) I more mean: what's the point of master, if we know the latest release branch? Why don't we stack hotfixes on that instead of onto master (either way obv merging them into develop)
(Master in git flow is what is in production right now)
 
@RobertGrant redundancy. There's no point in separating release from master when you could just as easily branch a hotfix off the release tag.
 
4:45 PM
if random.randint(1, 10) <= 6 :
 
This sort of thing is what vaguely bothers me about git flow and why I don't use it as written.
 
cant use it ?
 
@gtzinos You have to import random first.
 
(Okay I think I misunderstood, but I'll still write what I was going to :))
 
why not my friend ?
i need to save it to a variable ?
 
4:46 PM
@davidism so git flow says that when the release enters production that release branch is pushed to master and develop, and hotfixes come off master and are pushed to master and develop. Why can't hotfixes just come off the latest release branch?
I might tweet nvie
 
Huh. I'm a bit confused about one thing in flask. Adding a app.errorhandler(404) appears to make the rest of my application work. Otherwise, it always returns a "not found" page
 
@gtzinos Are you replying to me? I don't think I said anything that "why not?" would be a sensical reply to.
 
@gtzinos Are you talking about a pure block of nested ifs, or is there recursion involved? And how deep is the nesting that's giving you trouble?
 
@RobertGrant they can, if that's how you want to visualize it. Branching off of a release branch should be equivalent to branching off its merge point in master.
 
I guess if you branch of release X then do you have to go through a full release process before you can release the hotfix?
 
4:48 PM
not i found this bug
i had 4 nested ifs
the 4 was without else
maybe this was a problem ?
 
Because you're building release X+0.1?
 
No, that shouldn't be a problem at all. It is never mandatory to have an else.
 
@gtzinos whitespace was probably the problem
 
maybe
 
>>> if True:
...     if True:
...             if True:
...                     if True:
...                             print("this code should work just fine")
...
this code should work just fine
 
4:49 PM
i tried it
but nothing
 
user559633
>>> if 1:
...   if 1:
...     if 1:
...       if 1:
...         print(2)
...
2
 
user559633
yeah
 
no problem i found another solution..
if random.randint(1, 10) <= 6 :
any idea why this dont work ?
 
Yeah, it will give you a NameError if you didn't import random. I already told you.
 
More I think about it, the more it seems that it'd be weird to pull hotfixes off a release branch. My brain is just too stupid to tell me why.
 
4:51 PM
Incidentally, it might help if you told us what error you're getting instead of just saying it doesn't work.
 
@gtzinos we're having trouble understanding what you're trying to communicate. Rather than vaguely describing what you see on your screen, please create a minimal, complete, and verifiable example.
garlic until this happens
 
Or, if you're not getting an error, and your code is running but not producing the output you expect it to, you should specify that.
 
at org.python.core.Py.NameError(Unknown Source)
at org.python.core.PyFrame.getglobal(Unknown Source)
at org.python.pycode._pyx27.onEvent$3(__init__.py:60)
at org.python.pycode._pyx27.call_function(__init__.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at org.python.core.PyMethod.__call__(Unknown Source)
at org.python.core.PyObject.__call__(Unknown Source)
better now ?
 
user559633
no
 
Ok, thanks. Looks like it is a name error, so I stand by my recommendation of adding import random.
 
4:52 PM
 
user559633
cute bunny
 
Yeah but I've seen it before. I need to add more to the rotation.
 
@Kevin I was going to post a few, but none of them were on imgur, and I guess you could have licensing issues:(
 
user559633
how can you sue an AI?
 
@tristan many arts PhDs dollars will be spent discussing that very question
Okay I think I got it. If you don't want to create hotfixes off master, and you have release-1.0 branch and need to hotfix, you'd have to branch off release-1.0 and create release-1.0.1, where you make the hotfix, and deploy it and merge to develop. Then for your next hotfix you'd have to branch off release-1.0.1 and create release-1.0.2, and then off that release-1.0.3, etc. I think doing hotfixes off master prevents you from having to daisy-chain release builds.
 
5:03 PM
I'm curious if there's any legal precedent where it was determined that linking to publicly accessible images was illegal.
 
citation needed (I mean that you need to cite creator/source, which can vary and creates some cases, but other than that it is fine in theory)
 
user559633
@Kevin a stretch, but that weev guy going to jail for GET on publicly accessible content
 
And further, whether there is any legal difference to providing a clickable text link to an image, hotlinking an image, or reuploading the image to imgur and hotlinking that.
 
"creates some cases" meaning that there are cases where there is a question about who owns the license based on the rules that were used to post it
also IANAL just to CMA
 
Hey, this looks relevant. en.wikipedia.org/wiki/…
I think I'll just stick to linking to things that are already on imgur.
 
5:10 PM
@Kevin if you guys are fine with random rabbit pics, I can search again. I found some cute ones. Although one of them had a watermark, I guess that's more of a problem
@Kevin ah OK, this is what I figured myself
 
Relatedly, it's amusing to me that 90% of the conversation about rabbit is centered around its most pointless feature.
 
Hey, rabbit teeth are very pointy.
 
(never mind that it's the only feature that works so far)
 
@Kevin How can you say that? :3
 
could put out open call for people to contribute cute animal pics, then it would fall under standard "I posted to SO license" I would assume
 
5:15 PM
I should go to the countryside and shoot some bunnies myself.
 
user559633
 
define "shoot".
 
yeah! analysis results support about 80% of assumptions from my initial proposal. Happy, happy researcher
1 seems false but I like that - helps argue against bias
 
5:26 PM
I always believed in you. Not regarding this thing in particular since I had no idea you were doing it. Just, you know, in general.
All of you have the potential to achieve things that you all have the potential to achieve.
 
considering I have been fighting resistance to analytics in this area - I will take any support
 
Is it legitimate to completely change the title of a question? there is a question "Why is in python float not actually a float?" but it's actually about is tests.
 
Sure. If the title they gave is dumb wrong, fix it up as much as is needed.
 
I'm pretty conservative about name changes. I only edit things like "Python Question [urgent!]"
 
@Elazar I think it's encouraged to edit questions into shape
but if OP edited the original question entirely, after having answers, it might be another issue
 
5:36 PM
The EAFP principle tells us that you should edit the title, and only revert if the OP gets mad at you. And maybe not even then.
It's got to be righteous anger.
 
better ask forgiveness than permission :)
 
Can you get flask without jinja, for single page web applications?
because I just send directly from my static folder using webpack
 
Last night I dreamed that a friend and I visited a leprechaun's cave and found a pedestal containing two identical emeralds. My friend took one, and I left the other alone. Later, it became apparent that he had been cursed by the leprechaun for taking something not belonging to him, and I had been cursed for callously rejecting what was plainly a gift. Lesson: don't go in leprechaun caves.
 
user559633
leprechauns have caves?
 
Well, let's start more generally. Does Ireland have caves?
Clearly Dream Ireland does, but I'm not sure about IRL Ireland.
 
user559633
5:44 PM
Yes, but they call them "caves."
 
It seems reasonable to me that leprechauns could live in caves. They're a geographically diverse species (appearing anywhere that a rainbow can form), so I expect they are highly adaptive in regards to habitation.
 
they're short due to evolutionary adaptation to subterranean conditions
 
user6568562
Or because they didn't eat their beans.
 
When you live in a community of beings that can curse you on sight, it's better to have a smaller outline.
 
@gtzinos you're getting a Java traceback.... you'd really want to see the Python traceback instead.
 
6:01 PM
@Kevin Too bad Ireland doesn't have snakes. Python is way better than Ruby ;)
stackoverflow.com/a/35230823/344286 Kind of interesting to see the downvote bandwagon effect.
 
Is there a way to make this work?

for each in list_of_classes:
print(each.attribute)

AttributeError: 'str' object has no attribute 'unit'
 
Sure.
 
That error doesn't match the code you've shown. What are you trying to do?
 
unit is the attribute
i was trying to print
 
OK, so why were you trying to print the unit attribute of a string?
 
6:07 PM
list_of_classes is a list of classes. I wanted to print the 'unit' attribute for each class in the list
 
The str class (or in this case an instance of it) doesn't have that attribute, so what did you expect?
 
Are you entirely sure that list_of_classes contains classes? Because from the error message, it looks like at least one of them is a string.
 
@JakeStokes can you try to print each, this might be string
 
the list contains strings, which are the names of classes.
 
DSM
So not a list of classes.
 
6:08 PM
a list of class names i guess
 
OK, next time someone vaguely describes a problem and takes five minutes of prodding to provide an mcve, they're getting kicked.
 
Consider making a list of classes instead. [str, list, dict] is just as valid syntax as ['str', 'list', 'dict'].
 
@JakeStokes then you might be have to import that with importlib then you can access attribute
 
@JakeStokes you've been told before that you need to actually ask what you meant to ask.
 
I asked it the best way i know how, as you've probably worked out I'm new to coding
 
6:10 PM
class Fred:
    unit = 23
class Barney:
    unit = 42
list_of_classes = [Fred, Barney]
for item in list_of_classes:
    print(item.unit)
#result:
#23
#42
Job's done!
If you're thinking "Ok, I recognize that it's better to start with a list of classes rather than a list of strings of class names, but the latter is what I've got and I'm stuck with it", then it's a slightly harder problem.
 
Thanks Kevin, that's what I'm trying to achieve but with the classes names saved as strings in the list. Is there a way to do that?
 
Hmm, how best to solve this without eval or globals...
 
lol @ thanks Fred
 
Smells like an xyproblem.info to me
 
@JakeStokes the correct answer is "why are you storing class names as strings?"
 
6:12 PM
Where does this list come from?
 
I wager 3 quatloos on "I get them from input calls"
 
Please do be elaborative-- we get that you're new, but playing 20 questions is annoying, especially for something that is very strange to do in the first place
 
Okay
 
And that would be a pretty reasonable reason, although I wonder why a user would be supplying names of classes :P
 
If the possible classes are limited to a finite number of possible classes that you know ahead of time, you can map the strings to the classes with a dict:
class Fred:
    unit = 23
class Barney:
    unit = 42
d = {"Fred": Fred, "Barney": Barney}
list_of_class_names = ["Fred", "Barney"]
for item in list_of_class_names:
    print(d[item].unit)
#result:
#23
#42
@KevinMGranger Yeah, that would be a double XY problem.
"I'm doing [unusual thing #1] because of [unusual thing #2], of course!"
 
6:15 PM
A wx problem?
Nah, it's input, so no windowing
 
Thanks, I will try your solution.

For the record:
[unusual thing #1] is when I instantiate this particular class, self.name is added to list_of_classes.

[unusual thing #2]
My intention was to use this list to then retrieve an attribute from each class of that type I have created.
 
This might be a strange question of theory, but would it be possible to install an encrypted "VM" on someone's computer that is impossible to access directly, but able to be connected to?
 
In theory, using this: ethereum.org Otherwise, no
 
But self.name is an instance variable, it doesn't describe a class.
 
I think this is a case where eval is the solution.
 
6:17 PM
perhaps this is a bad road to lead a beginner down, but it sounds like they want metaclass like features
 
Perhaps you meant to add self.name as a key pointing to that instance.
{'x': Foo('x'), 'y': Foo('y')}
 
That sounds like something I should be doing instead of this.. I thought if I made a class called Class1 with self.name = Class1 and a list with [Class1] in it, I would be able to use this technique.
 
@JakeStokes go back further, you're still in XY problem land.
907
Q: What is the XY problem?

GnomeWhat is the XY problem? When asking questions, how do I recognize when I'm falling into it? How do I avoid it? Return to FAQ index

 
>>> # Disclaimer: If the answer uses eval, your problem has a problem.
...
>>> class MyClass:
...   pass
...
>>> x = MyClass
>>> y = 'MyClass'
>>> z = eval(y)
>>> x
<class '__main__.MyClass'>
>>> z
<class '__main__.MyClass'>
>>>
 
How about:
list_of_instances = []
class Fred:
    def __init__(self):
        list_of_instances.append(self)
        self.unit = 23
class Barney:
    def __init__(self):
        list_of_instances.append(self)
        self.unit = 42
a = Fred(); b = Fred(); c = Barney()
for item in list_of_instances:
    print(item.unit)
#result:
#23
#23
#42
 
6:20 PM
@QuestionC don't, really, just remove it before they get ideas
it took forever to convince them not to do that last time
 
@Kevin Ah okay, so you've added self to the list instead of self.name like I have. I think you have solved my problem.. and I now understand what the XY Problem is.
 
We need a special contract for the more foot-shooty techniques. Something like "we will teach you the forbidden art, as long as you agree to never ask us about problems that happened because you used the forbidden art"
 
It just needs an intro like the rustonomicon
 
@KevinMGranger That's great.
 
I think that's just having faith in people. Learning (and using) goto didn't forsake me from programming forever.
 
6:25 PM
Well, properly used, goto makes programs cleaner instead of dirtier. eval, on the other hand...
 
Most of the people that come here seeking forbidden arts, are not the type of people that would properly use them.
 
What other arts are forbidden, o ancient one?
 
Here's one that was unearthed last week:
>>> patch = '\x312\x2D7'
>>> import ctypes;ctypes.c_int8.from_address(id(len(patch))+8).value=eval(patch)
>>> 2 + 2
5
 
A couple months ago I had a legitimate "Gotta turn strings into classes variables" problem.
 
I love that one!
 
user6568562
6:27 PM
@KevinMGranger The art of seeming busy. A necessity in this day and age.
 
@Kevin stop that. You're making me feel scared
 
I was not a big fan of the guy whose code I was maintaining fixing, but what was I supposed to do about it? XY doesn't matter when you're only allowed to change Y.
 
Remember, the monster that gets you if you think about it too much, can't get you if you don't think about it too much.
 
Oh that's just a trick, I see
Do you read SCP wiki? That sounds like a series of stories you'd enjoy
Actually, you don't even need to read SCP to enjoy them, just enjoy the writings of QNTM
 
Yep, I've read a good chunk of SCP.
 
6:30 PM
Have you read all of the antimemetics stuff then?
 
Yeah. I like the one thing that nobody can describe and five minutes after they leave the containment area they forget that the thing exists.
And they eventually discover that they can describe what it isn't, and their preliminary descriptions are "it isn't red. It isn't round. It is definitely not safe."
 
No I mean qntm's series. They're stories, not entries
 
I've also read qntm's stuff. Fine Structure was really good. Ra was interesting but I lost track of the conflict after the main character started appearing in three places at once.
 
I remember reading that one. I'm looking at Introductory Antimemetics now.
 
6:48 PM
Hi everyone! I'm having some issues with generator expressions in Python 3.5 at the moment: code like gen = (x**2 for x in range(100000)); print(gen) does take time to execute! I thought it should immediately print <generator object at ...> as generators compute data only when told to do so, do they?
 
user6568562
I believe you did tell it to compute x squared in range 100000
 
The same thing happens in Python 2.7.
 
In principle, any line of code takes time to execute.
 
There's some setup involved in starting a generator.
How much time are we talking?
 
If you're saying it takes time to execute in proportion to the size of the number you feed to range, now that is surprising.
 
6:50 PM
Sure thing, but I didn't request any results, so they should be computed only when requested? It can take several tens of seconds depending on the number I put in range
 
I would expect gen = (x**2 for x in range(100000)) to execute exactly as fast as gen = (x**2 for x in range(1)) and gen = (x**2 for x in range(10000000000000000000))
 
@ForceBru it's "instant" for me on 3.5
 
@Kevin, that's what I'm talking about
 
Just tried >>> gen = (x**2 for x in range(100000000000000000000000000000000000000000000)); print(gen) on my machine and it was effectively instantaneous.
 
Same.
 
6:51 PM
Are you using some kind of non-standard Python environment? A Jupyter notebook or something?
 
I'll bet 3 of whatever fictional currency first-Kevin used that they're on 2
 
Ah, now that I try it on Python 2 I do get a slowdown for larger numbers.
 
Then I've got a possible bug to report to Pythonista (iOS Python IDE) developers...
 
import timeit
print(timeit.timeit('gen = (x**2 for x in range(100000))'))  # 0.5729799962784863
print(timeit.timeit('gen = (x**2 for x in range(10000000000000000000))'))  # 0.7135054669973119
For 3.5.
 
@Kevin, that's because in Python 2.x range returns a list
 
6:54 PM
But I assume that's from it not having the second number interned?
print(timeit.timeit('gen = (x**2 for x in range(1))')) # 0.5094029662102936.
Huh. Now I'm super confused.
 
What the heck, they [Pythonista devs] seem to be patching Python really hard
 
Ok, I think this makes sense. In the generator expression (expr1 for identifier in expr2), expr2 is executed immediately, even if you never ask the generator for a value.
 
ForceBru: in the meantime, use xrange
 
range(a big number) is near-instantaneous on 3.x and O(N) on 2.7, so that's what's causing the time discrepancy.
So cancel that bug report. This will happen in any environment.
 
Ohhhh, that makes sense.
 
6:57 PM
Or did you say it's slow in 3.x... That's a little weird.
 
@Kevin, as I've said, this thing happens in both Python 2.7 & 3.5
BTW, range(a lot) is instantaneous in Python 3.5 as expected, but a generator using it as above is slow as a tortoise
 
import timeit
def _range(x):
    print('Executing')
    return range(2)
print(timeit.timeit('gen = (x**2 for x in _range(1))', globals=globals()))  # 0.5094029662102936
print(timeit.timeit('gen = (x**2 for x in _range(100000))', globals=globals()))  # 0.5729799962784863
print(timeit.timeit('gen = (x**2 for x in _range(10000000000000000000))', globals=globals()))  # 0.7135054669973119
Yup.
 
It might be the IDE's fault, if they're replacing __builtins__.range with something homebrew. But it might not be a bug. It might be intentional. Maybe they want their interactive environment to print [0,1,2,3] when the user enters >>> range(4), and they can't get that behavior if they leave it as-is
 
but... but why
 
So, in Pythonista's Python 3.5: range(1000000000) is fast, but (x**2 for x in range(1000000000)) is slow. WTF?
 
6:59 PM
Whoops I wrote that message before you said that range is fast except inside a generator, which is double weird.
Ok, I changed my mind again. Report it.
 
How slow is slow?
 
Does the repl in Pythonista show you the value of everything you type even if you assign it?
 
Now, I kid you not, everything works fine after I wrote the last message... Again, WTF? :D
 
I spent the last two weeks working on bugs that stopped happening if I looked at them too hard; and fixing code that never should have worked, but in fact did work for half a decade. So I believe you.
 
7:03 PM
They say quantum computing is far off, yet we've got heisenbugs left and right
 
In [1]: N = 1000000000

In [2]: %timeit range(N)
The slowest run took 8.94 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 324 ns per loop

In [3]: %timeit (i**2 for i in range(N))
1000000 loops, best of 3: 872 ns per loop
Dat caching.
 
BTW, a generator expression with collections.Counter is really slow now. Should it be? I mean, are any values actually generated when one instantiates a genexpr? (I believe, they shouldn't be...)
gen = ("{} -> {}\n".format(a, b) for a, b in collections.Counter(random.randint(0, 6) for _ in range(100001)).items())
 
How slow is really slow?
 
Hmm, I observed before that expr2 does execute immediately, but I'm not sure how that works when you have multiple fors.
 
I'd guess that's actually the string formatting.
 
7:07 PM
This single line takes 2 secs to execute given that the one with range is an instant
 
Nothing is instant.
You really need to time your stuff if you're going to be complaining/wondering about speed.
 
Oh, it isn't multiple fors in the one gen expr. It's nested fors. Yeah, I'd expect that Counter expression to execute immediately and run over all 100,001 items right then and there
 
You also need to time things multiple times and check there's no caching.
 
@Ffisegydd, but, I assume, when one creates a genexpr, nothing is really computed inside it, isn't it?
 
It still takes time.
Again, if you want to have a proper conversation about this/look into it properly, you need to time things.
Otherwise it's just verbal masturbation.
 
7:09 PM
No problem, an instant means 4.100799560546875e-05 secs. So, 2 secs is a lot compared to this
 
That's not an instant, that's actually a bit slow.
It's 100* slower than the things I posted above.
Also:
2 mins ago, by Ffisegydd
You also need to time things multiple times and check there's no caching.
 
user559633
And be aware of the timing overhead
 
Also, slow for desktop is relatively fast for mobile.
 
That's being timed on a pretty old iPad. I've said, I'm running this in an iOS 'Pythonista' app
 
DSM
Is it just that ForceBru thinks that nothing inside the genexp parentheses gets executed until next?
 
7:13 PM
No idea
 
@DSM, sorta. They're here to make Python lazy, aren't they?
'they' are genexprs
 
Code still has to be executed though.
 
The initial state is still computed immediately, then execution is paused until the next value is requested.
 
DSM
They do. But it's the evaluation of the genexpr which is lazy, not the construction of the genexp.
 
user559633
twitch.tv/hellogamesofficial no man's sky live stream from the creators
 
7:15 PM
I've got it on preorder waiting to download.
 
user559633
thank you for being the test pilot
 
user559633
Ffisegydd, I believe you were excited for it too?
 
wim
anyone know why is enumerate a type instead of a builtin_function_or_method ?
 
I've got it on preorder too. Just crashed my pc
 
Am I the only one playing on PS4?
 
wim
7:16 PM
reversed as well
 
Looks like it, console peasant.
 
@DSM, sure thing, but when the construction takes two secs, isn't that a lot?
 
@wim possibly because it's implemented in Python, not C.
 
wim
is it?
 
...given that another one with range is constructed very quickly
 
user559633
7:17 PM
Oooh, when did the docs start linking to the source code? That's nice
 
That counter isn't just construction
 
@wim I didn't actually look. :-)
 
wim
that would surprise me too
 
@Ffisegydd, so is it evaluated at construction? If yes, why even call next on it? Doesn't this call make the generator compute stuff?
 
@ForceBru what are we even talking about anymore?
 
7:20 PM
Garlic
 
wim
I bet @user2357112 would know
 
@davidism, about whether some contents of a generator are evaluated at creation, I believe
 
A Counter is not a generator expression. A generator still requires setup. What else is there to say? We keep explaining it in different ways and you keep going in circles.
 
user559633
davidism/fizzy are you going to stream any of it?
 
I might try out the PS4 Twitch integration.
 
user559633
7:21 PM
Please let me know if you do -- I'd tune in.
 
@ForceBru at generator creation time? Or definition time? Cause I'm pretty sure it's only the former, and only the contents up to the first yield expression.
 
@WayneWerner, I'm talking about this code in particular; it takes 2 seconds to run on my iPad, while a `range`-driven genexpr is much faster. `import random, collections, time
s = time.time(); gen = ("{} -> {}\n".format(a, b) for a, b in collections.Counter(random.randint(0, 6) for _ in range(100001)).items()); print(time.time() - s)`
But I think I got it: collections.Counter seems to be a time-waster here
 
Easy, time is moving backwards. time.monotonic() is what you want ;)
 
user559633
why not use dis to see what is "wasting" time
 
oooh, or the line profiler
 
7:28 PM
Or use timeit
 
@tristan Maybe.
 
@ForceBru that's fast because creating a generator doesn't do anything much.
 
user559633
@Ffisegydd same applies for you -- let me know if you stream it. i have a lot of fun with twitch when you're on
 
All you are doing is timing the creation of a single object. The loop isn't run. Time list(gen) next.
 
Shame it's not easier to get to each other, or we could multiplayer up
 
user559633
7:29 PM
I know :/ If there was multiplayer, even with this game seeming to lack actual experiences beyond item collection, I'd pick it up immediately.
 
@Ffisegydd What game is this that you're talking about?
 
Well there is multiplayer, you just need to travel to each other
 
Pokemon go?
 
@MartijnPieters, I know that creating a genexpr should be fast, but it isn't fast enough: scroll up a bit for the code I was talking about.
 
@WayneWerner No Mans Sky
 
user559633
7:31 PM
@Ffisegydd Oh? I was waiting for confirmation that it's actually concurrent playing
 
@ForceBru define 'fast enough'. You are creating a function object to drive the generator, plus a frame object to track the locals and the bytecode progression.
 
@Ffisegydd ahhhh, that one. Cool.
 
@tristan I have seen videos of their head dev saying it is
 
Compared to what? Creating a regular function?
 
The mere creation of this genexpr takes two seconds, so the question is why?
 
7:32 PM
>_<
 
collections.Counter(random.randint(0, 6) for _ in range(100001)) has to execute before you can produce the genexp.
 
user559633
@ForceBru Profile it and teach us.
 
DSM
I had to do some work for a minute. Are we still talking about the fact that the Counter gets executed during genexp construction?
 
Passing a generator expression to an object that consumes it immediately takes time.
 
Yep, apparently.
 
7:32 PM
Because collections.Counter(random.randint(0, 6) for _ in range(100001)) is evaluated as part of the initial state of the outer expression. As we've said multiple times now. That inner generator is saving memory but not time.
 
user559633
@DSM Yes, but why
 
Time that separately.
 
Because we're bad people.
 
no, because I'm being too stupid now 'cuz it's a tiny bit too late here & I'm a tiny bit tired. Now I've understood what was the cause of this, thanks everybody for your help!
 
Just remember to stop asking questions when you're too tired to hear the answers -_-
 
7:45 PM
@wim: You rang?
 
user559633
oh great, another newbie that didn't even bother to pick a name
 
:D
please don't post your new questions here:P
 
user559633
(hi, welcome)
 
wim
yeah, why names enumerate and reversed are instance of types instead of builtin_function_or_method
 
7:51 PM
It's just easier that way. They have to return an object with state and a next method, and the simplest way to efficiently bundle up the necessary state and next implementation is to write a type. You'd do the same in Python if you had to implement that functionality without generators, and trying to do it as a generator from the C side would be crazy awkward.
 
user559633
Is there something intrinsic in a type that makes it easier to keep state and give a next method?
 
def enumerate(iterable):
    i = 0
    for item in iter(iterable):
        yield (i, item)
        i += 1
Seems like that would be the simplest
 
wim
>>> isinstance(enumerate([]), types.GeneratorType)
False
>>> isinstance(enumerate([]), enumerate)
True
 
Ah, now that's interesting
 
user559633
7:57 PM
cbg @RobertGrant
 
@KevinMGranger: A generator would be simplest if you're writing it in Python instead of C, but these things are written in C.
 
wim
so they have two new types because they couldn't be bothered to make them return generators?
 
Hmm, why is it implemented in C? Does it predate generators?
 
Is speed a valid aspect?
 

« first day (2123 days earlier)      last day (2843 days later) »