« first day (3155 days earlier)      last day (1792 days later) » 

wim
12:09 AM
@AndrasDeak PEP-8 actually says to put in a return None
Note: I'm not advocating to put a useless explicit return. I'm advocating to ignore pep8 :P
 
frick da police
 
12:27 AM
dam
 
1:10 AM
@wim I understand it now after @roganjosh explained it to me. Hence why I said I didn't understand it. Soliciting and explanation for future usage.
 
2:00 AM
cbg :P
 
 
2 hours later…
4:13 AM
posting this one last time for the benefit of people who haven't seen it yet (given up on the hope that it gets starred)
Jun 1 at 4:53, by cs95
20k+ rep and nothing better to do? We want you! 1. Click this link 2. Start deleting.
please use discretion and keep an eye out for stuff that should not be removed.
 
you mean cast delete votes?
many of these are not at -3 and so not eligible for delete voting yet
@cs95 ^
 
the ones older than 5 days are. Alternatively, sort by votes and start from the bottom of the scrap heap
 
oh yes that is revolting
 
keep your eyes peeled for reversal candidates, those are worth keeping
 
5:21 AM
hi
 
hello
 
 
1 hour later…
6:53 AM
lol, found a bug again in CPython code when writing an answer: bugs.python.org/issue37170
 
stackoverflow.com/questions/56472379/… Possible dupe but unsure what's the dupe target
 
7:12 AM
closed already
 
@AnttiHaapala I see that vstinner disagrees that it's a bug. But the docs he linked seem to agree with you.
 
@PM2Ring I am ever so more sure that vstinner doesn't undrestand a thing about C
 
it seems like he read it quickly, and saw just the -1
and he was like, oh, that's fine
 
@wim I thought I misremembered again, but no, I think it says to return None when there are other non-None returns:
> Be consistent in return statements. Either all return statements in a function should return an expression, or none of them should.
In a function with a single return it can be omitted from how I read that and what follows
 
well, but also: if the value is used then you should be explict because it is better than implicit
ok wtf victor then closed it already.
 
7:18 AM
@AnttiHaapala I don't think he got that the problem is the type, not the value
@AnttiHaapala is there ever a path where a None return value is meant to be used?
 
@MisterMiyagi well, of course the problem is the value
 
I can only remember using it as a poor man's void
 
well, not usually... if your function would ever return only None then it usually wouldn't be used.
 
@AnttiHaapala but the -1 is correct, the value is wrong due to using the wrong type... or am I missing something?
 
@MisterMiyagi no you're not missing anything.
 
7:21 AM
Well, (unsigned long long) -1 is a different value to (unsigned long) -1, to wit, 2^64-1 vs 2^32-1
 
it is moments like these when I remember why I prefer the dynamic-type-speak :/
 
funnily enough the function doesn't seem to be used much, most of the usages are covered.
 
@AndrasDeak That's fair enough. If a function has multiple return statements, and some of them return stuff apart from None, then the other return paths should be return None. A bare return, or using the implied return None is probably not a good idea. OTOH, the compiler is pretty dumb about adding those implied return None lines.
 
A bare return is same as return None right?
 
Right.
 
7:28 AM
so not returning anything, a bare return and a return None, three ways of returning None
 
I dreamt that it was the penultimate day of the semester and I accidentally learned from a student that we forgot to organise a mid-term resit, and there was no time left to rectify that. Weirdest "forgot to prepare for an exam" dream ever.
 
is it proper to actually reopen a bug on the bpo:?
 
@PM2Ring I always understood this to mean "all paths should return something meaningful"
 
So is this code PEP-8 proof?
In [17]: def f(a):
    ...:     if a == 1:
    ...:         return
    ...:     elif a == 2:
    ...:         return None
    ...:     else:
    ...:         pass
 
gah, nope.
 
7:30 AM
that is just bogus
 
I don't think so, since the last one doesn't return anything
 
Just do def f(a): return None
none of your paths return anything other than None
 
so returning None is not returning anything?
 
@AndrasDeak ObXKCD m.xkcd.com/557
 
@DeveshKumarSingh not returning anything is returning None
 
7:32 AM
@DeveshKumarSingh the pep discusses return vs return None, though implied return should be similar
 
aah okay, it says to use return None instead of not writing a return statement, be explicit
 
@PM2Ring well this could've happened a few weeks ago ;)
 
@DeveshKumarSingh That's what PEP-8 says not to do. But try this: get rid of that else: pass, and then pass your function to dis.dis and see what it prints.
 
@MisterMiyagi how about
 
pro tip: use type hinting to rid yourself of ever returning None. One person can type an Optional[Optional[Optional[T]]] only so often before going mad...
 
7:36 AM
class FUBAR:
     def __eq__(self, other):
           raise TypeError('NANANANA')
 
@PM2Ring okay f(1) and f(2) has the exact same bytecode, is that what's expected?
 
Function calls don't have bytecode, functions do
 
@AnttiHaapala AFAIK that violates the rules for writing a proper __eq__
metaprogramming was not fun lately
 
okay, i saw three explicit LOAD_CONST 0 (None) in dis.dis(func)
 
SQLAlchemy uses a similar thing
 
7:39 AM
so the bytecode added 3 explicit return None for that function
In [28]: dis.dis(f)
  2           0 LOAD_FAST                0 (a)
              2 LOAD_CONST               1 (1)
              4 COMPARE_OP               2 (==)
              6 POP_JUMP_IF_FALSE       12

  3           8 LOAD_CONST               0 (None)
             10 RETURN_VALUE

  4     >>   12 LOAD_FAST                0 (a)
             14 LOAD_CONST               2 (2)
             16 COMPARE_OP               2 (==)
             18 POP_JUMP_IF_FALSE       24

  5          20 LOAD_CONST               0 (None)
In [22]: def f(a):
    ...:     if a == 1:
    ...:         return
    ...:     elif a == 2:
    ...:         return None
 
@DeveshKumarSingh Yes. Here's a simpler example.
def f(a):
    if a:
        return a
    else:
        return None
 
okay 2 return None, one of the explicit, and one for implicit return None
so what do I learn here?
 
misread the f
 
@DeveshKumarSingh That the compiler is too dumb to realise that it doesn't need to add that final return None
 
@DeveshKumarSingh that automatically optimising Python is really hard and generally not worth it
 
8:00 AM
generally the cpython compiler is so notoriously bad that when they finally add some trivial optimizations it will easily void all these "optimizations"
 
the pypy bytecode compiler also adds the useless return None
 
@MisterMiyagi it is not "useless"
the correct optimization would be to do
LOAD_FAST a
LOAD_CONST 2
COMPARE_OP 2
LOAD_CONST 0
RETURN_VALUE
 
I mean for the fs with an else clause
@PM2Ring like this @AnttiHaapala
 
8:23 AM
cbg
 
8:34 AM
cbg
 
cbg
 
hmm. why is this returning true?
class whatever():
    pass

id(whatever()) == id(whatever()) #True. why?
 
coincidence. The first whatever() instance is garbage collected before the 2nd one is created, and they end up getting the same ID. The 2 objects' life times don't overlap.
 
8:45 AM
perfect, ty
 
@ParitoshSingh duplicate sopython.com/canon/76/…
 
@Arne Dupes it.
 
@U9-Forward thanks
 
:-)
My Hammer
 
@Arne a recursive function is a function that calls itself. Not what I'm after thanks. — Nick P 1 min ago
 
8:48 AM
@AnttiHaapala ah ty.
 
finally, that glaring hole in my cs education got closed
wait, he edited it D= now I look like a fool
 
@Arne reopened
 
it's tough to visualize that things can be garbage collected inbetween the execution of the single line. i presume my mistake was thinking that the single line in code had any relation to a single operation in terms of bytecode.
for context though, this is actually a question that was just asked here i need to learn how to make cv pls messages
 
@ParitoshSingh Done
 
8:59 AM
Isn't it great when documentation straight up lies to you?
 
but is that a good thing or a bad? the id ending up being the same
 
> Raises: IOError – If the file cannot be found, or the image cannot be opened and identified.
OSError: cannot identify image file
:/
 
rip
@DeveshKumarSingh its "irrelevant" at that point.
 
@DeveshKumarSingh it's good, lower memory footprint for python. and ids aren't meant to be reliable since you don't get to control your objects lifetime
 
9:02 AM
didn't someone write in chat here not too long ago that it might have been a good idea if id() wasn't a builtin and instead in the inspect module, or something like that?
I'd agree on that
 
so it holds true for different classes too
In [38]: class whatever:
    ...:     pass
    ...:

In [39]: class whenever:
    ...:     pass
    ...:

In [40]: id(whatever()) == id(whenever())
Out[40]: True
 
hm. i don't see why id reuse implies lower memory footprint.
that memory location is still freed and ready for use
 
makes sense since both objects are allocated memory from the same location
 
what am i missing?
 
@ParitoshSingh did i use the wrong word?
 
9:04 AM
@Aran-Fey I take it it's not an alias?
 
well, i am not sure. memory footprint i presume meant how much memory you're using during execution. is that off?
 
@AndrasDeak nope
>>> OSError.mro()
[<class 'OSError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>]
>>> IOError.mro()
[<class 'OSError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>]
 
@ParitoshSingh freed and ready to use -> which it does on the same line
 
IOError is an OSError, but not vice versa
 
IOError is not OSError?
 
9:05 AM
oh.
 
@AndrasDeak well, say the id was still freed, but the 2nd object was allocated a different location in memory, youre still only using so called 1 memory slot at a time.
 
Yeah, I'm dumb. My bad.
*scraps half-finished bug report*
 
:D
@ParitoshSingh and fragmented trash could pile up faster, I imagine
 
okay, that definitely sounds logical.
 
@Arne yup
 
9:10 AM
@Arne Yep, the badger.
Python is very good at recycling dead objects. Also, it does its own memory management, so when it does need to create a new object, it does it using memory from its own memory stores, called arenas. It only rarely needs to call the OS's memory allocation or free functions.
Dec 6 '16 at 11:58, by PM 2Ring
@MohammadYusufGhazi Note that when a Python object dies its memory gets returned to Python's memory allocator, it doesn't get released back to the OS. The Python allocator does return memory to the OS when it decides it's appropriate, though. If you want to know the gory details, take a look at Memory Management
 
@PM2Ring back referencing a 2.5 yr old message, awesome :) Did you remember what you said? Or you just searched it :)
 
Python has a pymalloc allocator optimized for small objects (smaller or equal to 512 bytes) with a short lifetime. It uses memory mappings called “arenas” with a fixed size of 256 KiB. It falls back to PyMem_RawMalloc() andPyMem_RawRealloc() for allocations larger than 512 bytes.
@DeveshKumarSingh I did a search for arena, said by me. ;)
 
got it :)
 
9:27 AM
In Ancient Python, the interpreter would allocate new memory blocks for the arenas when it needed to, but it would only free arena memory when the interpreter exited. So deleted objects would be returned to the arenas, but not to the OS. I call that "Hotel California memory management". ;) Modern Python is more well-behaved.
 
what's an arena? Does that stand for something in python
 
9:41 AM
rbrb
 
@PM2Ring oh wow, TIL, thanks!
 
10:01 AM
TIL?
 
Hi there
imagenet_data ='dogImages/train'
train_data_loader = torch.utils.data.DataLoader(imagenet_data,
                                          batch_size=4,
                                          shuffle=True,
                                          num_workers=nThreads)
I have this DataLoader
I would like to get only one image from the loader
I tried:
x= iter(train_data_loader).next()
print(x)
 
@DeveshKumarSingh Today I Learned
 
but I don't get the image as an arry .. I only get:
['i']
or other characters
but not an array
 
try a for loop?
 
but I want only one image?
 
10:05 AM
also does your code follow the example here? pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader
 
is that... python 2?
 
also check the type of train_data_loader, is it what you expect
 
no python 3.7
 
but iterators don't have a .next() method in python 3?
 
hm but why I don't get any error hehe
in notebook kernel is written: Python 3, and locally I've installed 3.7
 
10:08 AM
I guess the DataLoader returns a custom iterator that does have a next for whatever reason
 
you need to do next(iter(train_data_loader)) then
 
@PM2Ring I have a model in Django

class Category(models.Model):
#bydefault every model has one column-id which is primary key column
parentId=models.ForeignKey('self',on_delete=models.CASCADE,null=True)
name = models.CharField(max_length = 200, db_index = True)
slug = models.SlugField(max_length = 200, db_index = True, unique = True)

What problem I am facing is that if I crate the category from the shell then it is allowing me. I crated one like this:

Category.objects.create(name='Vehicles',slug='vehicles').save()
 
maybe look here
 
@DeveshKumarSingh I have gone through this but I want to know the reason that even though we are using null=True for the parentId, why it is throwing the error in admin page it shold set the value as null.
 
there is a bug ticket and a commit in one of the answers, did you look there
also what's your django version
 
10:20 AM
@DeveshKumarSingh django v 2.1.5 and where it the bug ticket
 
Hi guys I am trying to install a module named fasttext through Linux
I tried through anaconda first but its not being detected
So I tried using pip
Here is the error I am getting:
ERROR: Complete output from command /home/rssld/.pyenv/versions/anaconda3-5.2.0/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-h899w6fi/fasttext/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-gjijwb6t/install-record.txt --single-version-externally-managed --compile:
    ERROR: running install
    running build
Can someone guide me on what to do ?
 
@DeveshKumarSingh Ok I have gone through this link what what it is saying that for CharField django saves empty string in db instead of null and it is resolved. but what I am asking is that if it is null = True then why at admin I am getting the errorr: This field is required
 
@RaphX are you on ubuntu?
 
Yeah @Arne
 
10:29 AM
which version?
 
ubuntu 16.04 LTS@Arne
 
ok I'll try to reproduce
 
@chiragsoni Sorry, I don't know Django.
 
No @DeveshKumarSingh
 
10:35 AM
or is it this one
 
@DeveshKumarSingh I got the answer from here: stackoverflow.com/questions/2493341/…
 
@DeveshKumarSingh pypi.org/project/fasttext refers to the first one at pyk
 
@DeveshKumarSingh anyway thanks for the reply
 
@chiragsoni cool you figured it out yourself !
@Arne aah then there are some prereqs needed before pip install freetext it seems
 
it's fasttext @DeveshKumarSingh
 
10:39 AM
@RaphX That's very large! Next time, please use something like dpaste, pastebin, etc, if you have a large block of code or a large error message. A dozen or so lines is ok to paste here directly, but longer stuff should be linked from a paste service.
 
Ok @PM2Ring
 
@RaphX then i suggest going through their readme and seeing if any prereqs are needed before you pip install fasttext
 
I installed cython,, its still showing the same error
 
can any body explain getlist() in django working?
 
btw according to the readme: github.com/pyk/fastText.py#update there is an update library for fasttext perhaps try that
 
10:44 AM
@RaphX the docs say Python version 2.7 or >=3.4, you're using python3.5
then again, the other docs only say 2.6 and up.. so I guess I'm still going to try
 
Could smbd explain me why this answer minused twice? stackoverflow.com/a/56475620/10824407
 
@DeveshKumarSingh Hammered
 
@OlvinRoght only the downvoter can explain why they downvoted, but they are under no obligation to provide an explanation
 
for once, it is pretty much unreadable mess of list comprehension
 
10:55 AM
but the question is a mess too
but yeah, lack of explanatory text could be one hypothesis as to why several people decided to downvote only your answer
another would be that we should not answer questions which are convoluted and/or probable duplicates but then the other answers should have been downvoted too if that was the principle at play here
 
@RaphX Alright, I finally got it to build. python version doesn't seem too important, and it ended up just being the usual python-dev build dependencies. At least in my case.
 
So what should I do?@Arne
 
all other answers are downvoted as well
 
maybe I looked at the wrong time then
but they are -1/+1, this one is -2/+2
 
@OlvinRoght No, pari should not change the question at this late stage. It's not fair.
 
11:01 AM
@PM2Ring, I've understood that, okay
 
yes, I already CV'd to close it
also a very simple double for loop is enough for it
list1 = [['2.6x3.65'], [], ['2', '2.9x1.7', '2.5x1.3']]
res = []
for l in list1:
    li = []
    for i in l:
        li.extend(i.split('x'))
    res.append(li)

print(res)
 
@RaphX try this
apt install gcc g++ python3-dev
python3 -m venv env
source env/bin/activate
(env) pip install cython wheel
(env) pip install fasttext
 
Am I supposed to put something in place of 'env'?@Arne
 
nah, that should work exactly as I wrote it.
 
you can call it something else if you like, it's just the name of a directory which will be created in the current directory
then of course you have to use the correct directory in the source command which follows it, too
you can do all of this in /tmp for a start if you want to experiment
 
11:04 AM
oh, and don't type the (env) part, I only added that to illustrate that the virtualenv should be activated for those commands
 
@OlvinRoght not a downvoter, but mixing list comprehensions with map and sum is very convoluted
 
I am getting this error:
zsh: parse error near `pip'
(anaconda3-5.2.0)
 
an answer that has this code snipped [sum([list(map(float, i.split('x'))) but barely any explanation is not exactly good
 
@RaphX looks like you typed in the (env) after all? don't
1 min ago, by Arne
oh, and don't type the (env) part, I only added that to illustrate that the virtualenv should be activated for those commands
 
sorry overlooked that :P
still an error :
 
11:10 AM
(please use dpaste this time)
 
Its just one line
 
@MisterMiyagi, what is the problem with map in list comprehension?
 
zsh: command not found: apt
 
@OlvinRoght list comprehensions already express map and filter
these two are equivalent:
 
@RaphX try sudo apt-get install gcc g++ python3-dev
 
11:12 AM
[expr(a) for a in thingy if cond(a)]
map(expr, filter(cond, thingy))
 
list(map(float, list1)) equals to [float(i) for i in list1]
 
perhaps apt is not available for zsh but for some other shell
 
when apt-get install is not available, sometimes yum is the alternative
however, i do not know linux at all to say more than that
 
43 mins ago, by RaphX
ubuntu 16.04 LTS@Arne
it's apt-get, I'm just more comfortable with just apt and sometimes forget when exactly it was added
 
11:14 AM
@OlvinRoght exactly, instead of using one paradigm you mix two
 
@MisterMiyagi, edited with listr comprehension. When I wrote the answer I've just thought that it will be less code.
 
actually less code should not replace readability of the answer, any answer on SO is also for future readers to understand
 
you can also drop the useless sum, it is only needed because you added another useless []
[[float(e) for i in l for e in i.split('x')] for l in list1]
generally, sum is associated with adding numbers, which is misleading since your lists also contain numbers
that is still a three-level list comprehension, but at least it is one paradigm only and does not include unneeded additional levels
at the end of the day, most of these questions come from people that have problems with *flat* lists already
if you want them to actually understand your answer, keep complexity low and opt for readability over terseness
 
wax on, wax off.
 
cbg
 
11:23 AM
cbg
 
Yes, yes, agter I've replaced map with list comp I can do this.
 
zsh: command not found: apt
 
Before I've used map and apply this "hack" with sum with empty list
 
@Arne
 
@OlvinRoght All of MisterMiyagi's advice to you is good. But that doesn't mean your code was so bad that it deserved 2 downvotes. However, at least 2 people thought the style of your code was sufficiently poor to be worth downvoting it. Readability is very important in any language, but especially in Python. It's possible to write very clear code in Python, but it's also possible to write inscrutable messes if you try to be too clever. ;)
 
11:26 AM
@RaphX yes, you need to type sudo apt-get instead
 
@MisterMiyagi, thanks for all advices. I've finally edited to last version :)
 
Jan 17 '16 at 12:25, by PM 2Ring
Remember Kernighan's maxim: "Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" — The Elements of Programming Style , 2nd edition, chapter 2.
 
@RaphX fwiw, you can replicate my build with this Dockerfile, and use that as an inspiration / command lookup
 
or sudo apt-get update && sudo apt-get install -y python3.5 gcc g++ python3-dev python3-pip && pip3 install cython && pip3 install fasttext
 
sudo apt -get gcc g++ python3-dev
[sudo] password for rssld:
sudo: apt: command not found
(anaconda3-5.2.0)
 
11:32 AM
why the space?
apt-get
 
also, apt-get install gcc g++ python3-dev
 
Haha, this needs to stop. @RaphX please stop.
 
when you can't even copy-paste instructions it's a good sign that you should take a break and do something else
 
Actually I tried without spaces
 
11:37 AM
@RaphX Please try harder. And read how not to be a help vampire. You are seriously depleting patience of the users here, which is a non-renewable resource.
(you're in bad luck because you're not the only one with the same issue these days, so a shortage of patience is expected)
 
I guess I got it
It seems sudo yum install is working although I know its for Fedora/Debian
 
Pandas folk, here was a link on reddit to a pandas cheat sheet (well, if you count 8 pages as a "sheet") from the people at Enthought: reddit.com/r/Python/comments/bxbcdm/…
 
I got this result from the first line of your code @Arne
Loaded plugins: fastestmirror, priorities, security, versionlock
Setting up Install Process
Loading mirror speeds from cached hostfile
 * dev-dsk-main: dev-desktop-repos-dub.amazon.com
 * dev-dsk-updates: dev-desktop-repos-dub.amazon.com
Package gcc-4.4.6-3.45.amzn1.x86_64 already installed and latest version
No package g++ available.
No package python3-dev available.
Nothing to do
(anaconda3-5.2.0)
That means I don't need to download that thing right?
 
That's not Arne's first line of code, you're doing it wrong. Please stop with this problem here.
you can try asking on chat.stackexchange in a relevant room about how to install packages on ubuntu
 
11:58 AM
Someone in the forum thread of the latest xkcd comic just mentioned this brilliant piece of software: github.com/tessalt/echo-chamber-js/blob/master/readme.md
 
laurel, that is wickedly genius
 
chaotic good
 
until someone inspects and finds the github link :)
 
Yesterday I got three upvotes for an answer I wrote that turned out to be completely wrong :>
 
StackOverflow in a nutshell
 
12:06 PM
At least I figured it out and edited in the correct answer. I wonder how often I write answers that are wrong and I don't discover my mistake.
 
In other xkcd news, pittsburghjoe, the negative quantum spacetime guy, had his final fling: forums.xkcd.com/viewtopic.php?f=18&t=126714 Notice the subtle diplomacy employed by moderator gmalivuk.
 
haha
 
Succinct.
 
Almost missed it
 
why waste time say lot word when few word do trick
Update: yesterday I wrote two answers that turned out to be wrong.
 
12:17 PM
Smart of you to cluster them, now you can gather up all the shame in one sitting and dispose of it for good
 
Extra shame points awarded because I got pinged by a person saying "hey you forgot corner case XYZ" and me thinking "pfft no way bro, my work is flawless" and ignoring him for twelve hours
 
you were pre-occupied in another segment of the multiverse
 
It must be the upcoming solstice, or something. ;) I've seen a few dubious answers on Physics.SE, and a couple of totally wrong ones. One of those got self-deleted after I pointed out the factual error his answer was based on. Oh, and we've been visited by the self-appointed father of antigravity, but he's pretty mild compared to pittsburghjoe.
 
antigravity is dangerous business, you could easily just get zapped away from Earth, or splattered all over the Western wall or the ceiling
 
@PM2Ring how the f* do people manage such mindless blabbering without their brain melting?
 
12:27 PM
I can't even comprehend what was the conspiracy theory which was mentioned by Kevin in the first place
 
@MisterMiyagi What evidence do you have that his brain has not, in fact, melted? :D
 
12:51 PM
This reminds me of Netflix's documentary on the Flat Earth Conspiracy community. Everyone they interview is absolutely convinced they're right, sometimes in the face of contradictory evidence (some of which they collected themselves)
Only like 25% of them are obviously complete lunatics. I feel like this says something about the average human's capacity for compartmentalization and cognitive dissonance
In particular I remember a prominent flat earth podcaster saying something like "It's pretty likely that NASA is all lizard people", and in the very next scene, saying "I can't believe some of my listeners believe I'm a lizard person, you can't just make assertions like that with no proof"
 

« first day (3155 days earlier)      last day (1792 days later) »