« first day (3278 days earlier)      last day (1895 days later) » 
01:00 - 17:0017:00 - 00:00

17:05
@JohnnyApplesauce Why can't you copy that script and modify the copy so it doesn't create the unwanted file? Do you have any control of the name of the unwanted file?
wim
wim
@PM2Ring it's bad because of the confusion between iterable and iterator. your edits cleaned it up cosmetically, but didn't address the fundamental confusion at all
You would never define a class like this because of range. And there is already something called Counter in collections, which is something entirely different.
"you're not supposed to change it" -- This is quite hard to actually enforce for Python programs, if the steady stream of "how do I keep people from meddling with my scripts?" questions over the years is any indication
@wim The OP asks about iterators, not iterables. But yes, a good answer could explain what iterables and iterators are. BTW, @MisterMiyagi made those edits, not me.
wim
wim
I guess my main problem is the Counter(low, high) really looks like it should be an iterable or container, not a one-shot iterator. I'm not aware of any precedent for SomeClass(...) to return an iterator, much more useful info for n00bs would be for SomeClass.__iter__ to return an iterator.
@wim The name is bad, but that post is so old that it predates collections.Counter. IIRC, it was introduced in 2.7, but there's an official Counter recipe available for 2.5.
Yes, I'd expect Counter(low, high) to have similar behaviour to range or xrange
wim
wim
17:16
wow, didn't realise collections.Counter was so new (2.7)
so the answer was not as bad then in 2008, but it hasn't aged well... :)
guess the output
counter = Counter(3,9)

for i in counter:
    for j in counter:
        print(i, j)
I have a guess, let me see
oh, I need the definition first :D
yes, got it!
wim
wim
👏
This makes me think that for a sequence I only need __len__ and __getitem__ as minimal. And indeed __contains__ and __iter__ are generated from those. What am I missing for isinstance(seq, collections.abc.Sequence) to be True? If I define a generator __iter__ on a class it will recognize it as a subclass of collections.abc.Iterable.
Why?
wim
wim
17:30
you only have one package
may as well just put the name
also dependencies specified as zipfiles on github is pretty gross too
having to hard-code the package name into my setup.py seems like a pointless source of errors. Don't see the problem with auto-detecting it
wim
wim
the package name is a different thing from the distribution name, though
for example, I think pip may even munge your distribution name to secure-serialization instead of secure_serialization
you would likely not want the distribution name to automatically change if you added another top-level package that happened to come alphabetically before "s", or renamed the top-level package for whatever reason
also why do you have a master branch and a release branch?
@AndrasDeak For a sequence, you only need __getitem__, btw
I don't think I'll ever have 2 modules in the same project
master is my dev branch, release is where tested releases go
wim
wim
that's what tags are for, not branches...
release from master!
and don't push anything to master unless it passed tests
17:37
can you download a zip archive for a tag?
alright, I'll look into tags then
wim
wim
and if you are python3-only add the Requires-Python metadata to prevent pip2 from installing you
and if you're a single-top-level-package project only supporting python 3 you should probably use pyproject.toml along with a more modern packaging tool than setuptools
e.g. flit will unique out the __author__, __version__, and long description automatically so you don't need to do those regex hacks
can pip install directly from github if there's no setup.py?
wim
wim
I haven't checked this recently but I think a recent enough pip can?
Just a moment, I have a setup.py-less project somewhere that you can try with ...
pip install git+https://github.com/wimglenn/pytest-raisin <-- works for me 👍
(disclaimer: I'm not sure what version of pip that started working properly on, but it was pretty recent)
17:48
Alright, I'll take a look at flit later. Thanks
wim
wim
what is "in scope" for breaking your code, btw? just an arbitrary code exec during deserialization?
@PaulMcG thanks. So it's just that collections.abc.Sequence won't guess?
@wim Doesn't have to be quite as bad as arbitrary code execution - basically it can be anything that allows an attacker to trick you into doing something you didn't intend doing. Say, deserializing a Dragon instead of a CutePuppy. Or deserializing a CutePuppy whose set_name() method is shadowed by exec. Stuff like that
wim
wim
@AndrasDeak I don't reckon those abc have ever worked properly. What are you LBYL anyway?
Why does en.wikipedia.org/wiki/… say that θ ∈ [0, π]? Doesn't 0 through pi only cover half of a circle?
Or, hmm, it makes sense for one of the values to cover only half a circle, and the other one to revolve completely around...
But, like a USB that won't fit, I've tried switching the variables three times in my code and the output is still weird
wim
wim
18:00
@AndrasDeak e.g. old-style getitem iterators aren't seen as iterable either. The only reliable way to check if something is iterable is to call iter on it (EAFP)
@wim purely academic curiosity
brushed up on the iterator protocol thanks to the Counter thing, and sequences were right next to it
wim
wim
here's a sprinkling of strong opinions chat.stackoverflow.com/…
thanks, I knew it has come up before
Guess I'll just try all 3! possibilities until one works
ah, abc in general
18:03
Raymond H has a YouTube video out there touting the beauty of this - "just implement __getitem__ and voila you have a sequence!"
Ah, part of my problem is that the article is using Z as the vertical axis, as indicated by en.wikipedia.org/wiki/Spherical_coordinate_system#/media/…. That at least explains why even my simpler experiments were rotated ninety degrees.
In the absence of __len__, I think len() successively calls __getitem__ until it gets IndexError.
wim
wim
nope
prejudice against 1-based sequences
wim
wim
it will just crash with a TypeError
18:05
and yeah, that ^
Hrmm, willing to admit my mistakes, but my recent experience led me down this path for a reason. Checking....
that raised half an hour ago
(I know because I accidentally tried implementing a non-existing __length__ first)
wim
wim
you're probably thinking of old-skool protocol. instances of a class which only defines __getitem__ will correctly return an iterator if you call iter on one of them.
The Python docs try to keep this secret, because they want people to use the new-skool iterator protocol (i.e. define __iter__)
@PaulMcG not quite either...
This may have been Py2 old-style-classes thinking. Ooof, I thought I had shaken all that stuff loose
18:13
@PaulMcG not even the iter one was as straightforward... stackoverflow.com/questions/52357560/…
Ah, my issue this past summer was that adding __getitem__ to a class implicitly made it iterable, not that it gave it a virtual __len__ method.
Implicit iterability -> explicit irritability
@Kevin It's annoying, because the article uses 2 conventions, the physics ISO convention, where theta is the polar angle, ranging from 0 to pi, and the maths convention, which swaps phi & theta relative to the ISO convention. Here's the ISO diagram: upload.wikimedia.org/wikipedia/commons/thumb/4/4f/…
After rearranging terms for the Nth time, I'm getting output that looks correctish
Stupid yamming transparent diagram...
wim
wim
probably not worth adding answer there, but it is also possible to opt-out of iterator
18:17
10% of my points appear to be spinning in the wrong direction but that might be the wagon wheel effect
@Kevin Oh, good.
@wim __iter__ = None?
wim
wim
>>> class B:
...     def __getitem__(self, item):
...         return [0,1,2][item]
...     __iter__ = None
...
>>> [*B()]
TypeError: 'B' object is not iterable
@AnttiHaapala you guessed it
Yeah,. __len__ will be used in the absence of a __bool__ (Py 2 _nonzero__) method. I don't believe container types must implement __len__, though it's strongly encouraged.
any recommendations regarding flit vs. poetry? (Or other candidates I haven't heard of?)
18:23
In my experience with 3d math, going from "wrong" to "correctish" is 90% of the work, and from "correctish" to "correct" is another 90%
wim
wim
@Aran-Fey they are for different purposes
@wim I get TypeError: 'NoneType' object is not callable
@Aran-Fey I like poetry, and it can easily cope with a project/project/src project structure, so I'm happy. Flit appears to be lighter-weight and less flexible, but good at what it handles. (Disclaimer: that is received opinion, I haven't used flit).
wim
wim
for your serializer thing, you will prefer flit, since you are not running an app or service, so you have no need for managing a deployment
it is "less flexible" if you don't like its choices. it is "more opinionated" if you do like its choices.
@Aran-Fey Use pipenv, it is the preferred tool ducks
18:26
class IsItASequence:
    def __init__(self, num_items):
        self._internal = list(range(num_items))

    def __getitem__(self, n):
        return self._internal[n]

    __iter__ = None

z = IsItASequence(3)
for i in z:
    print (i)
@Kevin What about the third 90%?
wim
wim
(imo a Python packaging tool is the one piece of software which absolutely should be opinionated)
@holdenweb make it understandable to yourself bout 2 hours later
alright, got it
wim
wim
because of no strong opinions forced by setuptools or distutils, we have a question like this every 5 minutes stackoverflow.com/q/58275110/674039
18:27
@wim Why do I not get `IsItASequence object is not iterable'?
@PaulMcG python 2?
it is so perverse to run ubuntu in windows
but it works.
import sys
sys.version_info
sys.version_info(major=3, minor=6, micro=8, releaselevel='final', serial=0)
wim
wim
@PaulMcG I'm not sure. You should...?
I did
@PaulMcG because this is not the program you're running
wim
wim
please read [MCVE] ;)
18:30
% python2 blah.py
Traceback (most recent call last):
  File "blah.py", line 11, in <module>
    for i in z:
TypeError: 'NoneType' object is not callable
:D
% python3 blah.py
Traceback (most recent call last):
  File "blah.py", line 11, in <module>
    for i in z:
TypeError: 'IsItASequence' object is not iterable
and that's 3.6.7
wim
wim
suspected layer 8 error
Sorry - my console was 3.6.8, but adding import sys; print(sys.version_info) to my script gives 3.5.2.
wim
wim
I would still expect a TypeERror in 3.5
the new iterator protocol was a py3k thing, wasn't it...?
Both are TypeErrors, but my question is about the error message being different
wim
wim
ah ok
maybe that more contextual error message was added in a minor point release
I thought you were trying to say the iteration actually worked, which would be strange
18:35
@PaulMcG Also, consider yourself slapped for doing print (i). ;) There should not be a space between the function name and the open parenthesis. Especially with print, because that looks like a Py2 print statement that's printing a tuple.
Oh, if only that were the only reason for me to be slapped...
wim
wim
list(range(... is a paddlin' too
And now there it is, in the archive for all eternity
I wouldn't mind a dollar for every piece of Python example code that puts a space after print...
Oh come on, I just needed a quick list contents - I originally had [0] * num_items but I couldn't tell the difference between z[0] and z[1]
18:40
I think wim's point is that there's no need to convert the range object to a list - range supports __getitem__, too
@wim Even before that, IIRC. 2.4? They were deffo in 2.6.
wim
wim
yeah and you also lose some nice features like O(1) slicing, reversed, membership...
18:55
Well, despite this relentless piling-on, @wim's tip of assigning __iter__ = None will be a big help to me. Now I'm going home...
*makes a cup of tea for @PaulMcG*
I use list(range(...)) in like 90% of my example code
It's great that range objects have lots of cool features, but if my code is designed to operate on a list, I'm going to give it a list
wim
wim
@PaulMcG happy to be of assistance, your earlier tip to set __cause__ = None on an exception (and consequently __suppress_context__) was also a big help for me!
(inb4 "good code adheres to interfaces, not types")
wim
wim
it meant I could go from a 3 modules package, with a compat.py and a conditional import statement, down to just a simple single .py file distribution
py2 can't go away soon enough :(
19:11
Ah, the 10% of my points rotating the wrong way aren't because of the wagon wheel effect, it's because my data is bad
wim
wim
19:41
TIL they don't send the 100k swag anymore
I wonder who was the final person to get it
@wim what about submodules? find_packages lists them, are there consequences to not including them?
@wim sounds like they might resume the custom. You know, panem et circenses
wim
wim
19:58
@Arne you mean subpackages?
yeah, ['secure_serialization', 'secure_serialization.generic_proto', 'secure_serialization.proto1']
does someone know how can i reshape a array using numpy reshape? I mean, in the tutorial i'm following the guy used this code: X = np.array(X).reshape(-1, img_size, img_size, 1), but it's not working because he was using a old version of numpy i think. I tried to reshape it in some different ways but none works. The last thing i tried was: X = np.array(X).reshape(img_size, img_size) but i get this error: ValueError: cannot reshape array of size 80000000 into shape (100,100)
wim
wim
@Arne yep, you need to include them in setuptools
TBH I'm not sure what flit or poetry do here, I don't really use subpackages
@boss the error sounds reasonable enough. Why do you think you can reshape an array of size 80000000 into shape (100, 100)?
and why are you saying that .reshape(-1, img_size, img_size, 1) is "not working"?
To take a step back: do you understand what reshape does?
wim
wim
looks as though flit (which dogfoods itself) just collects them recursively, since I don't see flit.vcs mentioned anywhere in the installer: github.com/takluyver/flit/blob/1.3/pyproject.toml#L10
which makes sense as the default behaviour, I mean why would you ever want to exclude a subpackage or have to specify them all explicitly?
20:21
@AndrasDeak Not at all. but if i can't resize it, then why the guy in the tutorial does? He is using a dataset with 24K images, and i'm using a dataset with 8K images, his array would be even more bigger then mine
First you should understand what it does and then try to judge what makes sense ;)
Reshape does literally that: takes the elements and pours them into a new shape. The number of elements cannot change during this operation.
An array of shape (100, 100) has 10000 elements, so only arrays of size 10000 can be reshaped to (100, 100). And the size is the product of the individual shapes in an array, of course. Is this reasonable?
You're also using -1 as part of your reshape at one point and then dropping that when you report on the error
@roganjosh sssh, let's get back to that later
heads-up: for two weeks you might get popups telling you that negative votes won't be displayed (to askers, judging by the asker's explanation of the phenomenon) meta.stackoverflow.com/questions/390178/…
That's an interesting angle to take
I wonder why it needed to come with the popup at all. No participant would have known?
wim
wim
20:36
lol
This is the opposite direction I want the site to go -- I think people's reputation should be able to go negative just like posts — Michael Mrozek Nov 19 '10 at 21:09
@roganjosh because they're testing how it affects voting interaction
I'm not even sure the "won't be displayed" is true
I'm guessing the actual mechanism is being communicated vaguely. I read it as everyone except the OP would see the downvote below 0
It would seem like it. But Shog is intentionally being vague lest he taints the data. He'll explain what's up in two weeks.
As long as rep and quality control are unaffected (i.e. everyone except the asker sees the real score) I don't mind. Though I think a lot of serial yam askers won't see the question ban coming with a bunch of closed 0-score questions.
Yeah, the "several of your recent questions have not been well-received" will certainly be confusing to that kind of poster
Well, <shrug> I guess a close and no upvotes is enough to constitute "not well received"
21:17
The problem earlier that I was asking about was that I have to grade 30 students' Python scripts, and the assignment teaches them to read a file made for the assignment (which is in my student script directory) and to write a derivative one
It would declutter the directory if I could dispose of the my own, and I don't want to change the student code lest I accidentally make the code not work and have to check 30 times (that's in the Oh case, not the Theta) whether their code didn't work because of me or they sent a non-working script.
Then you just need to delete the file after running the student's code. Why the need for a time delay?
wim
wim
21:44
write a little runner which would copy the module to a temporary directory, os.chdir and execfile, then nuke the whole tree in teardown
maybe even exec with a specific user made for the runner in case some students try to create files under homedir
or do the whole thing in a container if you have any students wearing a black hat
22:35
@roganjosh What's wrong with "Several of your recent questions violate SO rules and if you keep violating rules this you may be suspended/banned"? Sounds like the right calibre of ammunition.
@JohnnyApplesauce Depends if your system has (Unix-like) group and user permissions to prevent students viewing each others' files. Alternative I suppose is you could generate 30 unique filenames and email each user. Or just append their student ID or some two-digit class ID: file-xyz.txt. You don't need cryptographically-random strings, but FYI
@roganjosh I guess a more constructive variant is "Several of your recent questions violate SO rules. Please reread the rules [link] fully. If you keep violating rules you may be suspended/banned"
@smci not necessarily misattribution. Bosses give talks with students'/coworkers' slides all the time, which can easily be OK as long as the order of authors on the cover reflects the work (like in a paper)
which I see is what the answerers are saying
@AndrasDeak It's misattribution when the poster's name is not displayed, let alone prominently (i.e on the title page, with equal billing to all coauthors, not just line 13 of acknowledgments on page 39). The question was unclear, and since the OP (apparently) won't be attending the conf, which of us would trust that advisor to attribute it fully and correctly? I wouldn't, I doubt you would. Some days, Academia.SE reads like a cross-cultural complaint basket about how rampant academic fraud is.
> P.s. she never gave anybody a credit (She did this before with my senior)
OK, missed that part ^
@AndrasDeak It doesn't hurt to read the question before commenting, sir :P . We're clearly talking about a serial perpetrator of academic fraud.
All: is it ok to add Random string generation with upper case letters and digits to sopython.com/canon ? (Note that unless otherwise specified, we should interpret 'random' as 'everyday random', not 'cryptographically random', random-seed cannot be discovered for deniability. etc.)
Q2: is How to randomly select an item from a list? sufficiently different? The title says 'list'but the code example only shows single character letters, in fact list(string.ascii_lowercase[0:5]) ? Is this/not a dupe?
Q3: the SO canon currently contains How to generate random numbers that are different? [duplicate], as in 'distinct', or 'without resampling'. But it was closed back in 2012 as a dupe of Pick N items at random from sequence of unknown length
23:01
@smci well I read 90%, that has to count for something
wim
wim
LOL
@smci and of course, as I said, name on the front cover, first-billed
wim
wim
ignacio never writes long answers like that
look at his initial revision stackoverflow.com/posts/2257449/revisions
600k rep says you don't have to
wim
wim
everything of substance is from e-satis
2380 upvotes for a cheap one-liner!
23:15
@AndrasDeak Err but the killer question is, assuming OP doesn't go to the conf, how could they get a binding promise from a sleazebag advisor like that to actually do what they promised? (and where is their recourse assuming advisor breaks the promise?) I doubt it, given that advisor has a history of doing exactly this. So if OP already has their degree awarded (unclear, not stated) and graint paid out, they could tell advisor to get lost.
Q3b: so I retitled the dupe target to Pick N distinct items at random from sequence of unknown length, in only one iteration, but it still feels like a bad non-generalizable question, an an XY question for asking "How to determine/estimate upper-bound of iterator length (without iterating)?" Hence should not be a general dupe target. Your suggestions?
23:48
And I found this question, which is barely a question Random is barely random at all?, and really just asks "How long before repetitions, when sampling with Python random.randint()?", aka "What is the Birthday Paradox in random number generation?" This isn't even specifically a Python question. So: Reword? Close-as-dupe (if so of what?)? Leave as-is?
simple typo; the code was fine, the user just forgot to clear axes between plots R equivalent python code gives different output
01:00 - 17:0017:00 - 00:00

« first day (3278 days earlier)      last day (1895 days later) »