« first day (2646 days earlier)      last day (2292 days later) » 
00:00 - 22:0022:00 - 00:00

12:12 AM
rbrb
 
Hi! I have an exception class that I'm dynamically setting as a class attribute, but when I raised it the name gets qualified with the module in which the exception class was declared instead of the class it's being set as an attribute of. Does anyone know how to do this correctly?
 
12:27 AM
@Jovito do you mean that if you leave the exception unhandled you want to see FooError: message instead of module_with_exceptions.FooError: message?
 
Instead of module_with_exceptions.FooError: message, I would like to see SomeClass.FooError: message
 
well I know how to hack it, but I don't know what the proper course of action is
 
SomeClass being the class in which FooError is being set as a class attribute
@AndrasDeak how?
 
hmm, does the module containing the class also run the code that raises?
 
yes
 
12:31 AM
I think if you'd import that class and run elsewhere, you'd see the module name you want
@Jovito when you set that error as an attribute you can also set its .__module__ attribute to be __name__, but please promise me to find a proper way to do this :P
 
you mean SomeClass.__name__ right?
 
actually, when you're running that module the __name__ will be "__main__"
I meant regular dunder __name__, but I didn't have direct execution in mind
so yeah, SomeClass.__name__ I guess
which oddly enough should be 'SomeClass' :D
I very much think this is weird and there has to be a better way. So don't blame me when wim comes cracking a flaming whip
 
setting FooError.__module__ to SomeClass.__name__ feels really wrong
 
yes, that's what I'm saying :D
unfortunately I have little experience with exceptions and I have no idea how to do this
 
12:53 AM
I'm trying out Windows 2000 today and this browser and modern OS seems very strange.
 
Did you break into a museum?
 
Nah running it under Virtual Box.
Do you think anyone actually seriously uses one any more
 
 
4 hours later…
5:03 AM
Why does this not work?
    topic = Topic.getTopic(topic_term)
    threads_by_topic = Thread.objects.filter(topic=topic)
    threads = threads_by_topic.filter(Q(title__contains=search_term) | Q(op__content__contains=search_term))
AttributeError: 'Thread' object has no attribute 'filter'
I even tried
threads = threads_by_topic.objects.filter(Q(title__contains=search_term) | Q(op__content__contains=search_term))
 
5:27 AM
hi, What sort of a tuple is this? #python3
 
5:44 AM
Hey @PM just entered - cbg to you and all. Hi there.
how you been
Any SO adventures since we last chatted.
 
Cabbage, @Cam
@deostroll Please do not post images of code, post actual text, and use Ctrl-k or the fixed-font button to preserve indentation.
@Cam_Aust It's been pretty warm here in Sydney. It's overcast today, so it's not too bad, but it's pretty muggy.
 
Yep, up here also, though not doubt cooler. 25 deg outside, wind 17 km/hr. Nice breeze in the door.
Thought I would take a little chill time, visit here. I always learn something.
 
@Cam_Aust I've been doing some ray tracing over the last couple of days. I posted some results here, that you can see in yesterday's transcripts, eg this stereo pair i.stack.imgur.com/aofVY.png
 
Ooh ah stereo .. off I go.
Oh wow that is superb!
What are you using to do that. Love 3D.
 
@deostroll But anyway, that looks like the repr of a class. Those pairs are attribute names and the associated values.
@Cam_Aust I use the ancient but excellent POV-Ray program.
 
5:52 AM
Sorry, will post code next time...
 
OK. Have not used but familiar with the name. Leading for its time.
 
that is actually some sort of a named tuple
 
@deostroll Ok. It certainly could be a namedtuple. And of course the namedtuple constructor is a factory that creates a new class for you.
 
6:13 AM
I spent several minutes looking for a dupe target for this, but could only find questions where the OP shadows the standard module with their own script. I guess doing this sort of double import isn't common, but I'd be surprised if this were the first question about it.
How many other standard modules could this problem occur with? Off the top of my head I can think of datetime, but I assume there are several others.
 
That question looks like a mess
Also, HOW is from whatever import* not a SyntaxError?
import*?
 
6:29 AM
@cᴏʟᴅsᴘᴇᴇᴅ And the OP just edited the original problem out of his code and has a new question. Grrr. I've sent him a comment, but if he doesn't roll back, I'll do it myself.
@cᴏʟᴅsᴘᴇᴇᴅ It's no problem for the parser. And very handy in code golf. :)
 
And look who the answerer is (cc @PM2Ring)
 
@cᴏʟᴅsᴘᴇᴇᴅ Yeah. The guy who I got into a debate with a day or so ago for writing an answer to a trivial list comp question.
 
6:44 AM
@cᴏʟᴅsᴘᴇᴇᴅ I just gave Jacob my standard "don't answer typos" lecture. I'll delete vote in a couple of minutes, I'm curious to see if he'll respond to my comment.
 
Yup, just saw it. Don't think he'll respond though. Doesn't seem like the kind of person who is very receptive to criticism.
 
@cᴏʟᴅsᴘᴇᴇᴅ Yeah, he didn't respond, so I just killed it.
 
Yeah... didn't think so. For the best
 
7:10 AM
rbrb
 
no mcve stackoverflow.com/questions/48237841/… That code couldn't possibly produce that error message.
 
8:22 AM
@MartijnPieters have you tried those^ :D
salmiakki-liquorice milk chocolate
straight from Iceland
 
 
2 hours later…
11:08 AM
early morning weekend cabbage
 
11:19 AM
How can a 20k OP not think that this question is too broad? stackoverflow.com/questions/48238828/…
 
11:42 AM
I thought "this question isn't so bad" until I saw "generation of private and public key in python (should be one line of code)"
 
11:57 AM
@Kotlinboy well what's a Thread and why do you think it has a filter method?
@AnttiHaapala is that also salty?
 
@Kotlinboy It looks like you are using Django Rest Framework. Can you post a minimal, complete example? Use a paste site like pastebin or gist.
I woke up to +65 rep...not a bad start to the weekend.
 
uhhhh, pytest wants me to write the expected value on the left side of the assert statement? Like assert "expected value" == variable
what is this, javascript?
>       assert album.description == "TEST-ALBUM-DESCRIPTION"

Expected :<rest_client.resource.Attribute.Attribute object at 0x7f54eeea5048>
Actual   :TEST-ALBUM-DESCRIPTION
 
Yam the popo, keep it on the right
oh, it uses the order
 
Huh, apparently that output is actually genered by Intellij. Not sure how that works
 
That's weird. pYodatest
@Rawing I would've been surprised if pytest could affect the parser...
 
12:09 PM
wait, what parser?
 
Well my naive impression is that == is evaluated and the resulting bool is "passed" to assert. Python shouldn't see a lhs/rhs order
perhaps instead of parser insert whatever I mean
 
pytest actually rewrites the assert statements; I read that earlier today. Lemme see if I can find that part of the documentation again
 
Ah. Little rascal
 
found it: "Reporting details about a failing assertion is achieved by rewriting assert statements before they are run. Rewritten assert statements put introspection information into the assertion failure message."
from what I've seen so far, pytest is a very magical module.
 
Huh, cool, thanks
 
12:25 PM
@AndrasDeak Thread and Topic are models
 
There's a linked blog post with interesting details pybites.blogspot.hu/2011/07/…
 
topic = Topic.getTopic(topic_term)
gets the topic model instance
Using a function
I basically need to run two filters
 
I didn't know tensorflow had model objects
 
Lol! Django
Sorry
Not restframework. plain django
I'm implementing search for a FOSS reddit clone
from .models import Topic, Thread
from django.db.models import Q
def search_threads(search_term, topic_term=None):
    if topic_term:
        topic = Topic.getTopic(topic_term)
        threads_by_topic = Thread.objects.filter(topic=topic)
        threads = threads_by_topic.objects.filter(Q(title__icontains=search_term) | Q(op__content__icontains=search_term))
    else:
        threads = Thread.objects.filter(Q(title__icontains=search_term) | Q(op__content__icontains=search_term))
    return threads
 
I could guess but I don't actually know any django so I'll let others try to help
 
12:33 PM
@AndrasDeak Interesting read. Sounds like there are plenty of pitfalls when you're rewriting code.
 
pet peeve: no matter what I do, blogspot.com always turns into blogspot.hu
 
12:52 PM
@Kotlinboy Please use a paste site like pastebin or gist and give a link here. That way you can more easily include a minimal models.py file as well.
@AndrasDeak you should just move to another country. Problem solved!
 
or use a vpn :P
 
that's too easy
 
@AndrasDeak I know that feeling. Browser language: english. Windows language: english. website: german
 
yup
rewriting google links before sharing has been automatic for a while, but blogpost comes up too rarely
 
threads = Thread.objects.filter(Q(title__icontains=search_term) | Q(op__content__icontains=search_term))
is working
However chaining filters is not working
 
1:25 PM
re-cbg
 
cbg
 
@Kotlinboy I haven't looked at your pastebin, but you should probably be using the or operator, not bitwise OR. The or operator short-cicuits, so the 2nd expression won't be evaluated if the 1st is True-ish.
 
that's probably some django magic to combine filters
 
Oh, ok. If so, I'm not impressed.
 
I presume it follows the tradition of file permission bit magic
 
1:34 PM
Fair enough. In that case, @Kotlinboy please ignore my earlier message. :)
 
doesn't or automatically use bool? Whereas a custom bitwise op can do complicated (and non-boolean) things via __or__
 
Turns out some functions in my code make my PC unresponsive. That's a first. Not sure how to debug this.
 
can you see if it's a cpu or a memory thing?
 
Both cpu usage and memory usage skyrocket, but I guess it's the memory
 
yup
are you on windows?
 
1:45 PM
Not sure how I managed to screw up so bad. This debugging session will likely end with a serious facepalm
I'm on linux right now
 
you can use ulimit -Sv <bytes of memory to restrict the process to> to turn that thrashing into a MemoryError
and I'd try using pdb (pudb)
and you just need to find the combination of infinite loop + .append ;)
 
@AndrasDeak Well, you can intercept bool too, via the __bool__ magic method:
class Test:
    def __init__(self, val):
        self.val = val
    def __repr__(self):
        return f'Test({self.val!r})'
    def __bool__(self):
        rc = bool(self.val)
        print(f'BOOL {self.val!r}')
        return rc

a, b, c = [Test(u) for u in ('', 'abc', 'def')]
print(a or b or c)
#output
BOOL ''
BOOL 'abc'
Test('abc')
 
but bool is not binary, is it?
and at the end of the day it has to return True or False
so you can't, say, instantiate a new object based on Aobj or Bobj
well, you can, but it will contain either Aobj or Bobj rather than a mixture
 
@AndrasDeak bool returns True or False. You could do weird things in __bool__, but I admit it would be ugly because to do anything useful you'd be creating side-effects. Messing with __bool__ doesn't give you a way to make and or or result in a different object.
 
yes, that was my point
 
1:58 PM
Fair enough. So I guess Django is being sensible in overriding the bitwise & and |.
 
I think so, yes
 
To change the subject, I wrote a slightly weird recursive function a few hours ago, while investigating this SE.math question. It's a recursive function with a float arg involving square root. lim x->1 f(x) = 1, so the recursion has to keep taking square roots to get to the base case. Fortunately, iterated sqrt converges to 1 fairly quickly. :)
 
looks a bit like homework
 
I need some insight in the thinking process of the modeling process. I have a User and a User has a profile. However a User also has a message inbox and an online status. I consider those two features as a relationship and field on the User model not the UserProfile model. Am I on the correct path?
 
@AndrasDeak I don't think so, since it's such an intractable function. SE.math is pretty tolerant of homework questions, although they do expect to see some attempt by the OP.
 
2:12 PM
The second sentence of the two-sentence question triggered my alarm :)
 
I guess it could be homework, if the student is just expected to investigate it using numerical methods (like I did) but I don't have a clue how you'd even go about proving convergence.
Here's a nice SE.math question I answered a little while ago. The OP has made a decent attempt, and although it is homework-ish, I assume that he's a self-learner, as his user name proclaims. But his Google skills don't appear to be very strong, since he ought to have stumbled across the Chinese remainder theorem by now if he's studying congruences.
 
@AndrasDeak somewhat :D
I've yet to try them :d
 
then I'd pass :P
 
such a nice bag, I don't want to open
 
:D
Is that a puffin in the top left corner?
I've literally only seen pictures and videos of them on the ground, I was genuinely surprised to see one in the air. And I know they can fly.
 
2:26 PM
@AndrasDeak or a porg? :D
 
@AnttiHaapala I don't think I'd like salmiakki with chocolate, although I don't mind non-ammoniacal licorice with chocolate.
 
I'm not sure I've ever had anise-flavoured chocolate
 
I like chilli with chocolate, but I hate mint with chocolate. And I don't like milk chocolate that much. Ever since I was a kid, I've always preferred dark chocolate.
 
after eight <3
 
2:58 PM
I re-rendered that GIF anim with more frames, so it's less jittery now.
 
3:28 PM
For any given class, function or a variable, I see __getattribute__, __setattr__ & __delattr__ defined by default. Is this valid for any x, where isinstance(x, object) == True?
 
Yes, those functions are defined in the object class
It could be an implementation detail though. I'm not sure if the language spec states that object always defines those 3 methods
 
func.__getattribute is actually func.__dict__['__getattribute__'] which does not exist. How does it access object.__dict__['__getattribute__']?
Is it because function type is subclass of object type?
 
Yes. __getattribute__ doesn't exist in the function's dict, it exists in object.__dict__. It's an inherited method, so it doesn't show up in the __dict__.
 
Can't I access class function(object): & class object():code thru meta programming?
 
probably not, no. I think those classes aren't written in python.
 
3:39 PM
ok thank you
 
4:00 PM
How to find the own attributes of any object? >>> object. HIT TAB gives it's own attributes as there is no base class, How to find own attributes of >>> type. HIT TAB shows the same base class attributes?
 
vars(type).keys()
 
This will pick keys from type.__dict__ which gives it's own attributes
 
Wasn't that what you wanted? :s
 
4:17 PM
Is this purely a place where you get your coding questions answered?
 
no, it's a chat room :)
it's just somewhat dead on weekends, that's all
 
oh cool how's your day going
 
"coding questions get answered" on main if anywhere
 
i expect people go out and have fun on the weekends
 
and then there's people like me who stay home and crash their PC with a stupid bug
 
4:23 PM
What'd you do?
 
I'm not really sure. Some sort of infinite recursion with a memory leak I think
I fixed the recursion, but I suspect the memory leak is still in there somewhere
 
That sounds bad. Hope you figure it out.
I'm trying to tailor my dataset for a ML model. Kinda like walking into a room at night with the lights off.
I know where I want to go, but not sure if this is the best route or it leads me there.
 
@Rawing with python?
Is it still crashing? Did you try ulimit?
 
Uh, I guess calling it a memory leak was inaccurate. It's probably one of the functions in the recursion loop allocating some memory that never gets released because the recursion never stops
But no, it's not crashing anymore. I think it was a combination of two bugs, and I fixed one of them.
 
Great :)
You could try running in p(u)db and setting a breakpoint for an appropriate depth of nesting, to see if anything's off in the namespace
 
4:44 PM
To be honest, I don't think I want to bother learning yet another new technology (pdb) this week. I'll go with the good ol' "I'm sure it'll fix itself as I finish the project" solution
 
OK. I'm in love with gdb --tui for fortran/c so I'm biased
I strongly suggest taking a look when you have too much time, it can be real useful :) But pdb is a bit cumbersome so third-party pudb improves a lot on the experience
 
"PuDB allows you to debug code right where you write and test it–in a terminal." ಠ_ಠ
I don't even
 
Well I'm sure there's a debugger in pycharm if that's your thing :D
my main point was a debugger, but I default to a terminal
 
Well, you're right, I really should try debugging with a debugger sometime. print statements only get you so far
 
MATLAB's IDE lets you click to create breakpoints etc, I figured that's an IDE thing
Interactively looking at the namespace
In wty situations that can save lives
(When you don't even know what to print)
 
5:01 PM
Yeah, I've used it a few times in my java assignment. It came in pretty handy. Never used a debugger for python though.
rbrb, going to take a shower to ponder design decisions
 
Rbrb
 
5:29 PM
To follow DRY principle, I used class based decorator for debugging on every method access in that class. But to further follow DRY principle to avoid adding decorator to every class, I used meta class.
Is meta class mainly used to follow DRY principle in coding?
 
morning cabbage
@Rawing PyCharm/IntelliJ is great for debugging python code
 
DSM
5:47 PM
It's definitely off-topic, but this question makes me smile-- I admire the spirit.
 
Hello cabbage
Hello, I have been using sqlite for python, and I have it in my online website.
Could anybody of you try the register form, to let me check if it was saved to the database? Invent an email and username and password. For password put 12345678. It actually just saves it to the database.
I want to check if it works.
Thank-you. And apart from that, any feedback would be useful, referring to the styling of the navigator bar. The register form in my website is: nasom.svcdev.com/register
BTW the website is in Flask
hey you tried it!
Thanks.
Your username was 'user123', email 'user123@email.com', password '12345678' Who entered it?
Any feedback?
 
 
1 hour later…
7:41 PM
Is there a function for floor(log2(x)) for measuring the number of bits? I recall having come across such a function in numpy.
 
DSM
Python ints have a .bit_length() method. I'm not sure what you mean by "number of bits", though, because you'll need 5 bits to represent 16, but your formula floor(log2(16)) would only give 4, so maybe you have an unusual definition in mind.
 
Yeah, I mean floor(log2(16)), not the number of bits including sign.
 
DSM
Is this some new kind of binary I'm not familiar with? 10000_2 = 16, not 1000_2.
 
Oh sorry you're right.
 
7:57 PM
I'm attempting to connect to a webpage with this script: dpaste.com/29G3RXS but it's returning an AttributeError: module 'urllib' has no attribute 'error'. Can anyone suggest anything to get this working?
 
DSM
Import urllib.error.
Actually, I guess you'll need to import urllib.request as well.
 
Thanks it working now. Now for my next question why import both?
 
DSM
Aren't you using both?
 
Yes but why does import urllib not cover both
 
8:02 PM
cabbage
 
DSM
Packages are often written to allow the user to decide what portions of it should be imported. scipy, for example, would take quite a long time to import if you always needed to import the whole thing.
 
So your saying that urllib is a folder?
 
have you read what he linked?
 
Yes more than once
 
OK then
He's saying that urllib is a package with submodules, and the top-level __init__.py doesn't import all the submodules, so importing just urllib only imports part of the package. I mean, if I understand correctly.
 
8:09 PM
I see yes that makes sense.
 
you could try putting together a toy package with this structure to see if you can reproduce it
 
better still I'll take a look at init.py if I can find it.
 
one package, two submodules, import only the one in the __init__.py of the package, import the package, see what you end up with
@Simon see if urllib.__file__ is defined
 
Oh yeah sweet thanks.
Right here is the entire contents of init.py: " "
 
yup
apparantly it's not even a package with subpackages, just a single package
 
8:14 PM
*apparently
 
indeed
 
No your spelling.
but yes your right it is.
 
that's one of the things I can reliably spell
 
DSM
"you're right", and you're also missing some commas and capitals, if we're in a language-correcting mood.
 
I think he was joking there
see also "no your spelling"
 
DSM
8:17 PM
Maybe, but if so his joke travelled back in time and gave us "So your saying that". ;-)
 
Interesting module then. Designed so you have to import more than urllib in order any error catching to work.
 
DSM
Not specific to errors, though. urllib itself doesn't export anything in the main namespace, IIRC.
 
@DSM ooooh :D
@DSM yup
empty __init__.py, trivial namespace for urllib on import
this is not the typical approach
 
agreed
 
8:28 PM
@DSM @AndrasDeak I really can't see why they did that. Apart to force users to import specific parts of the package
 
well it could also be weird if you had to do this:
import urlllib
my_err = urllib.error.URLError
might as well from urllib.error import URLError
 
Yeah but there not giving anyone the option of that.
 
if all functionality is grouped under submodules, you might as well import the submodules you need
I'm not saying this is the only way to go, but I don't find it all that insane
 
@cᴏʟᴅsᴘᴇᴇᴅ Hey coldspeed, I'm using Numpy to pad the left and top portions of any array with zeros. I have got it working this way:
a = np.array([[1, 1,1], [2, 2,2], [3, 3,3], [4,4,4], [5,5,5]])
print(a.shape)
top =np.zeros(a.shape[1])
y = np.insert(a, 0, top).reshape(a.shape[0] +1, a.shape[1])
left = np.zeros(y.shape[0])
y = np.insert(y, 0, left, axis =1)
print(y)

Anything I should do to make it more efficient or maybe more readable?
 
why not allocate a larger matrix and overwrite the bottom right?
 
8:37 PM
@AndrasDeak What do you mean?
 
IIRC there's a pad function in numpy that does just this
 
In [7]: m,n = a.shape
   ...: y = np.zeros((m+1,n+1),dtype=a.dtype)
   ...: y[1:,1:] = a
   ...:

In [8]: y
Out[8]:
array([[0, 0, 0, 0],
       [0, 1, 1, 1],
       [0, 2, 2, 2],
       [0, 3, 3, 3],
       [0, 4, 4, 4],
       [0, 5, 5, 5]])
yup, np.pad, although I keep not using that because it does too many things :D
 
DSM
Aww, cs beat me. :-(
In [21]: np.pad(a, [(1,0), (1,0)], 'constant')
Out[21]:
array([[0, 0, 0, 0],
       [0, 1, 1, 1],
       [0, 2, 2, 2],
       [0, 3, 3, 3],
       [0, 4, 4, 4],
       [0, 5, 5, 5]])
 
In [39]: np.pad(a, ((1, 0), (1, 0)), 'constant')
Out[39]:
array([[0, 0, 0, 0],
       [0, 1, 1, 1],
       [0, 2, 2, 2],
       [0, 3, 3, 3],
       [0, 4, 4, 4],
       [0, 5, 5, 5]])
Psh, ninja'd by 2 people
 
mutual ninjation?
 
DSM
8:39 PM
Well, coldspeed said it first, so I think he wins.
 
FWIW pad is better
 
DSM
It's powerful but can be confusing.
 
Well played, Mr Data Science Man
 
this is one of the tasks which I solve faster the hard way than it would take me to read through pad's docstring
 
@AndrasDeak Thanks going to test it out.
@cᴏʟᴅsᴘᴇᴇᴅ Ah didn't know. I'm trying to getting better at writing these type of functions from scratch, if i need to implement something from scratch in the future.
 
8:42 PM
@AndrasDeak I'm not disagreeing with the "not insane" part I'm saying it's unreasonable not to give much of a choice
 
How would it give you a choice?
 
Put some text in init.py :)
 
@AndrasDeak Thank you. Looks good.
 
@Simon Okay?
 
?
 
@Moondra no worries, though reinventing the wheel is rarely necessary
 
DSM
"What is error all about? and why?" Deep, man.
 
I was attempting to build a chat system between two computers until now. I think I'll give it a break now.
 
@AndrasDeak Yea, you are right, but I'm trying to implement computer vision algorithms from scratch to get a deep understanding of algorithms, and also improve numpy skills, so I can implement custom algorithms in the future.
 
Part of using a library well is to know and use the tools therein
 
8:51 PM
Part of using a library well is also having gone through the struggle of implementing its functionality yourself only to discover the library after doing all that hard work for nothing
 
Yup. But at the end of the day you should commit the pre-existing version
Unless you do it better
@DSM second comment has a great point. Must be some horrible encapsulation reflex. Let's hope it's not homework
 
DSM
Fortunately I've decided not to worry about it. :-)
Saturday rhubarb for all!
 
Bah, the more I look at it the worse it gets. Closed the tab...
Rhubarb
 
@DSM Rhubarb. :)
 
9:44 PM
cbg
 
cbg
Could you test my register form? (made with flask)
It is here: nasom.svcdev.com/register. If there is any error, please tell me. Thank-you.
 
00:00 - 22:0022:00 - 00:00

« first day (2646 days earlier)      last day (2292 days later) »