« first day (1989 days earlier)      last day (2959 days later) » 

1:04 PM
heresy!
 
I was going to ask why your fonts were so small...
 
By the way anybody know how to sort based on the output of a function with three parameters (two of them are static)
 
@BhargavRao lol:D
 
@BhargavRao great!
 
1:10 PM
needs less braces though
 
more braces is better
 
@Thijser what do you exactly mean?
 
because more is always better
@AndrasDeak I have a list of points and would like to sort them to the angle of a line
I have a function angle(a,b,c) where c is the new point
it returns a floating point
 
is numpy an option?:P
 
it is
 
1:13 PM
cool
 
I think
 
oops wait
 
x and y are constants in this equation
 
hmm
scalar x, scalar y, and list z --> list angle?
 
That seems expensive, this is the deepest loop for a somewhat performance sensative program
 
1:17 PM
but is that your problem?
are points parametrized by z?
 
we have 3 points a b c
I guess that our a and b (constant points, parameters for the sorting that are required for every value) are x and y
c is z the point that varies
right?
 
I'm relatively new to python so I do not know what the --> operator does
(think hours not days)
 
it's entirely anecdotal, nothing to do with syntax
 
alright then it makes sense that I was puzzled by the syntax
 
1:22 PM
def sortfunc(x,y,z):
return -z

a = 3
b = 2
z = [11,12,13]

sorted(z,lambda z,x=a,y=b: sortfunc(x,y,z))
the trick is to use a lambda to expose only a single variable to sorted
this will return the z values sorted according to the output of sortfunc, I hope:D
Inspect this to make sure
 
Thanks I should read up on lambdas in python soon
 
yup:)
useful stuff
 
does this code require numpty?
 
nope
 
Umm... isn't that just sorted(z, key=lambda x, y, z: z, reverse=True) ?
 
1:27 PM
It's just that numpy is my hammer with which I drive every screw and tighten every nut
 
left=sorted(left,lambda z,x=a,y=b: angle(x,y,z))
 
@JonClements that is, but Thijser has an angle(a,b,c) function to sort:)
I just provided an MCVE
@Thijser that's my best guess...
 
TypeError: must use keyword argument for key function
 
but I'm also a noob, so the gurus might give you a better answer
hmm?
python 3 or 2?
 
I think you have more then (checks clock) 22 hours of experience
python3
 
1:28 PM
ah, it works for me in 2
wait a sec
left=sorted(left,key = lambda z,x=a,y=b: angle(x,y,z))
just like the error said
you have to pass the lambda as a keyword argument, called key
 
alright I think that works thanks!
 
@Thijser if left is a list - you might want to consider left.sort() for an inplace sort instead of left = sorted(left...)
 
1:43 PM
@JonClements oh good idea
the fact that the key is a different object made me oblivious of this option:(
 
You can pass key to .sort too
 
I know, thanks:)
I realized after Jon's message
it just didn't occur to me on my own
but as long as I claim to be a noob, I'm safe:P
 
>>> l = ['Andras','Deak','knows','python']
>>> l.sort(key=__import__('operator').itemgetter(2))
>>> l
['Deak', 'Andras', 'knows', 'python']
 
That's just evil @Bhargav :p
 
Lol :D
 
1:48 PM
waffles
waffles for all (except Jon, he gets treats)
 
@AndrasDeak flags message as obsolete :P
 
Coincidently, sorting by the 1st index also gives the same order.
 
Oh, and +1 for Deak Andras ;)
 
I wanted to create ['python', 'knows', 'Deak', 'Andras'] but failed
 
1:51 PM
:(
that would be scary
 
2:14 PM
l = ['Andras','Deak','knows','python']
l.sort(reverse=True)
 
>>> l.sort(key=__import__('operator').itemgetter(2),reverse=True)
>>> l
['python', 'knows', 'Andras', 'Deak']
 
that's not what you wanted to get:P
 
But it looks better ;)
 
does it?
My name is Deák András
 
ummm
>>> sorted(l, key=lambda L, c=iter([2, 4, 1, 0]): next(c))
['python', 'knows', 'Andras', 'Deak']
But then you might as well just do list(itemgetter(2, 4, 1, 0)(l))
 
2:22 PM
str is also an iterable, rite?
Really? I just checked, in my terminal: hasattr("abc", "__iter__") and it came up with False. I'm on Python 2.7, could that be the difference? — Luke Taylor 52 secs ago
Ah, Python 2 problems
 
2:51 PM
is there better way to solve this task : User enters natural number 6<N<100 and program needs to find how many x+y+z = N ( x,y,z are natural too), and the following must be considered x<y<z.The program should output the number of possible combinations.
import time
try:
    konacno = 0
    broj = int(raw_input("Enter number >> "))
    start = time.clock()
    x1=0
    y1=0
    z1=0
    if broj<6 or broj > 99:
        raise ValueError
    for x in range(1,broj+1-y1-z1):
        x1=x
        for y in range(1,broj+1-x1-z1):
 
Forgot to wish - Happy Easter everyone :)
 
@Bhargav ditto :)
 
@MarkoMackic small tip, Post the question and the code in separate messages :)
@JonClements (I am going to buy chocolates now)
 
@BhargavRao thanks i didn't know
 
@MarkoMackic You know you can do that using maths, right?
 
2:59 PM
not really know how
:)
 
I'm searching for a dupe, Have seen that b4 :/
 
duplicate ?
 
Yep, I have seen the exact question as yours before. So that can help you out
 
Ah ok, where to look , on stackoverflow ?
 
My brain doesn't work after a large lunch - you've got a maximum possible of 830,584 in the total search space, you then remove the number where x < y < z can't be met...
 
3:02 PM
i've done it, my program works, but i'm looking for nicer solution :D
 
Okay - what do you get for N=6 ?
 
1 combo
 
errr.....?
 
only 1+2+3 fits
 
oh x+y+z = n
Okay, well, you can re-write your code as: sum(1 for i in range(1, 100) for j in range(1, 100) for k in range(1, 100) if i+j+k == N and i < j < k)
That should do the same thing
 
3:06 PM
single line ;D pretty :) thanks
 
Mind you - it's more bruteforce than yours
 
stackoverflow.com/questions/36248808/… "my code works, but I have edge cases that don't, but I'm not going to bother even mentioned what edge cases those are. Pls fix?"
 
@JonClements Lol, True that.
I still don't understand broj+1-y1-z1 part...
 
@BhargavRao i want to have less loops :)
well yeah
my mistake
 
3:10 PM
i should only put (broj+1)/3 cuz the first number will never be greater than (1/3)*number :)
what're you up to people /
 
Celebrating easter ...
And as to what @JonCle's doing ...
in R Public, Mar 20 at 19:55, by Jon Clements
chase cats and eat scooby snacks?
 
ah yeah i forgot it's easter for you ;)
 
Easter stuff, cleaning the house, being lazy on the laptop because it is sunday
 
I'm watching Aus Vs Ind match
 
I suppose you could reduce the search space slightly, and do less filtering, with something like:
from itertools import product

combos = sum(
    1 for x, y, z in
    product(range(1, 100), range(2, 100), range(3, 100))
    if x < y < z and x + y + z == N
)
But then... ultimately, just make it: sum(1 for x in range(1, 100) for y in range(x + 1, 100) for z in range(y + 1, 100) if x + y + z == N)
That way your x < y < z condition is always met and you only filter on the sum
 
3:33 PM
# Wouldn't this be better?
sum(1 for x in range(1, 100) for y in range(x+1, 100) for z in range(y+1, 100) if x + y + z == n)
 
@Inbar isn't that what I typed?
 
Oh, yeah, I went to write the answer before you typed that.
But then I got delayed and didn't check the chat to see if someone already did that
also you could make it robust. :)
def f(n, bottom=1, top=100):
    return sum(1 for x in range(bottom, top-2) for y in range(x+1, top-1) for z in range(y+1, top) if x + y + z == n)
and slightly better with the range top
 
@InbarRose yup :)
 
@InbarRose we should probably give the OP some more time
sigh
 
bbiab
 
@vaultah That's why it's "on hold" once he edits it can be re-opened.
 
4:37 PM
In theory, yep
 
4:51 PM
Is anyone watching World Cup Cricket 20-20 right now?
 
@thefourtheye is this a cricket reference:
2 hours ago, by Bhargav Rao
I'm watching Aus Vs Ind match
 
@idjaw Oh yes :-)
 
hehe :)
 
@vaultah lol "sorry to distract you from Futurama". I wouldn't have noticed.
Obviously the best time to be watching is while cheating on an important test.
 
:-)
 
5:08 PM
silly question, on the sopython wiki (common questions), does draft mode only make it available to me if I save?
 
Draft mode means it's editable by anyone with the link, but only editors can see the link in the list.
 
great. Thanks. I'll do that first to get input before making it final.
 
argh, actually I need to check the code to remember
 
ok. I'll wait. no rush
thanks for looking in to it
 
ok, I was right, editable by anyone, visible in the list to editors
community is editable by anyone and visible to everyone, and draft overrides community
 
5:13 PM
ok
Just added something here
 
oh of course, it helpfully tells you what the mode means after you create it
 
:)

This comes from a discussion yesterday with Antti about that error and how there was no good canon dupe for it. So, I'm planning on making an SO Q & A for it once the fine details are sorted out in the wiki first.
 
There's really no dupe for "local module name shadows installed name"?
It's a good answer though.
 
I need a close reason “OP has no idea what he’s talking about”
 
"lacks minimal understanding":P
 
5:18 PM
12
Q: How to access a standard-library module in Python when there is a local module with the same name?

EOLHow can a standard-library module (say math) be accessed when a file prog.py is placed in the same directory as a local module with the same name (math.py)? I'm asking this question because I would like to create a package uncertainties that one can use as import uncertainties from uncertaintie...

 
@davidism Thanks for taking a look!

Nice find. I was stubborn with my search as I was actually only looking up by the exception that was raised
 
although that doesn't cover everything, and your answer wouldn't totally make sense there
 
My answer is for exactly that exception that comes up and OP has no idea why it isn't working
I see it come up quite a bit and I tend to always answer it in the comments
and it can just get closed as "cannot be reproduced"
but with a target, we can collect them under one common question
 
"I'm developing this module and its name clashes with a standard-library module". Yes?
 
I'm about to create the question and answer it shorlty. I'm pretty much going to take what I posted in the Wiki to do it
 
5:22 PM
close as "unclear what you're asking":P
 
Okay, already all my hand finger nails are gone.
 
@thefourtheye that's great
 
@thefourtheye 4 in 6
 
I'm waiting for my pup's nail grinder to arrive in the mail soon;)
 
Kohli owns the game.
 
5:25 PM
I wish her nails were all gone too
 
@thefourtheye I'm waiting for 6 by Cap Cool
 
@idjaw I can find a bunch of questions about the problem, but they're not well written or thoroughly answered for the most part. I say go ahead and post.
 
One bounce four :-)
@AndrasDeak bite them when she is asleep? :D
 
If you can come up with a list of duplicates I'll hammer them afterwards.
 
@davidism much appreciated. I'll link here once created
 
5:26 PM
@thefourtheye I wouldn't dare, she's a dachshund;D Very leg-conscious
@idjaw remember to wait 1-2 days before posting your question here...;)
 
@thefourtheye Damn ... I wanted 6; But still!!! \o/
 
add it to the canon as well
 
Okay getting out of my flat to join the celebrations
 
OK. So on Tuesday I'll link my question here
:D
tick-tock
0
A: AttributeError: module 'object' has no attribute 'foobar'

idjawThe reason why this is happening is because your module that you named requests.py is now shadowing the intended requests module you are trying to use. To avoid this, you should rename your module to something else to avoid these situations. Furthermore, chances are you will have generated a re...

and added to the wiki.
do I up-vote and accept my answer? This is so exciting
@AnttiHaapala ^^ because we were talking about it yesterday, thought you'd be interested to know AttributeError question is up.
 
Perhaps you'd replace 'object' with 'module' or something more descriptive
 
5:30 PM
@idjaw mention the path and absolute/relative imports as well
 
-1. Needs more freehand red circles.
 
you're totally going to downvote me aren't you fizzy :P
 
-2 actually! I can downvote Q and A!
 
haha
@vaultah Andras suggested this earlier: "I'm developing this module and its name clashes with a standard-library module"
or should i make the title more accurate to the module I'm using in the question
@davidism should I more or less reference the documentation per this answer
 
@idjaw Nice answer there, But now I feel that the Q must be closed as no longer repro'able :P
 
5:33 PM
You know, that would be hilarious if it got closed by some group of 5 for that very reason
 
I am trying to figure out why I cant set range(i, num)
 
@MahmutKilic please format your code properly.
 
I know it runs just fine when its range(2,num)
 
Alternatively you could pose it to a pastebin and share the link.
 
okay
 
5:35 PM
As it is, we cannot guess what your indentation is.
 
I am trying get prime numbers
 
@idjaw I mean object would be a strange name for a module
 
I am only confused about range part
 
@vaultah I agree...I changed it to be explicit to what I am using
 
why range cannot be range(i, num) besid range(2, num)
 
5:37 PM
@idjaw you need a better title. You can get an import or attribute error depending on how you do the import.
 
Agreed. Trying to think of a good one....having trouble
 
@MahmutKilic what error do you get?
 
@idjaw Why not just 'module' has no attribute 'foo'?
 
@Ffisegydd I dont get prime number whenever i set range(i, num)
 
And you have import module in the code, you try to call foo and you have your file named module.py?
 
5:41 PM
my output is 2
3
5
6
7
8
9...
 
@cricket_007 welcome to the room!
 
@Ffisegydd if I only change range(2,num) it works perfectly
 
@vaultah howdy, I'm only here for a little bit... I need to get out of bed :)
 
@MahmutKilic I'm struggling to understand the logic of your algo.
 
@cricket_007 welcome. Your input is appreciated. So. The title sucks. It should change. I'm having a bit of a block as to what would be a good title
to davidism's point, the exception itself is not ONLY for this reason
 
5:45 PM
@MahmutKilic look at your for loop. You're re-binding i using for i in range(i, num)
That probably isn't what you want.
 
@Ffisegydd I am sorry, The link I paste was for finding prime number. If you look at line 7. I set range(i, num) this gives me wrong output, however when I change that to range(2, num) I get the result I want
 
@cricket_007 Precisely. THe problem comes up quite a bit where OP will have a script name matching the standard module they are trying to import and they get that exception. So when it comes up, we want to dupe it to just help categorize the topics better.
 
@MahmutKilic I'd suggest you give things more explicit names rather than i then you can catch these things easier.
 
@Ffisegydd yes, but I am trying to understand why I cant use i?
 
@davidism thanks for the edit. I have to help my wife with something, feel free to do whatever edits you feel necessary. I'll jump back in when I'm back
 
5:47 PM
@idjaw I'm just thinking if anyone were to search for their error, and they weren't using requests, they wouldn't find (or bother looking at) that post
 
@cricket_007 Yeah. You're right. What do you feel would be a good title to attract users to that question who are experiencing this behaviour?
 
@MahmutKilic you iterate using a while loop, yes?
 
@Ffisegydd yes
 
Well on the second iteration your range will be range(num-1, num) because you've re-bound i
So i == num-1
 
well the title got long, but at least it describes the problem now
 
5:50 PM
Your mistake is using the same variable name for two different things.
durum=True
num=1
start=2
while num < 100:
    num = num + 1
    for i in range(start, num):
        if num % i == 0:
            durum = False
    if durum == True:
        print(num)
    durum = True
 
@davidism great edit
TIL about <!-- break -->
 
Yeah that's useful thing to know for code splits.
 
I use the word break, but anything will work.
 
Well, the error is AttributeError, so thats an important keyword. So is the phrase "module has no attribute" since that describes the problem... As far as filling in the blanks, just something generic
 
@davidism oh. thanks :D
 
5:51 PM
The other useful one is <!-- language: lang-javascript -->
@cricket_007 I'm fairly sure search engines will get it without the final word in the error
and they'll still pick up the more specific example in the body
 
Why don’t accepts also count towards the badge score? :(
 
@davidism I made one small change to the title.
 
@vaultah You can also just use <!-- -->, no need to put something inside ;)
 
You should fill the comment with passive-aggressive insults at the OP.
In this case idjaw.
 
5:55 PM
<!-- poke was here -->
<!-- who reads this is stupid (or not a browser) -->
 
<!-- I bet he's not even really a Lego man -->
 
@Ffisegydd Thank you So much! I was looking for this :)
:)
 
<!-- actually, I don’t have a single clue about the things I’m writing in this answer -->
 
@cricket_007 shame on me, I used the python2 error message
 
That's a paddling.
 
5:57 PM
@poke I put "break" so that the more clueless users don't think I'm just vandalizing the post
 
I typically actually type text between code blocks to describe what I'm showing ...
@davidism nice!
 
Putting "and here's the traceback" is just noise, it's obviously the traceback
 
@davidism I wonder if that’s really explaining enough for clueless users though..
 
Never had any complaints. Most probably don't even notice, since I pretty much rewrite posts when I edit them.
 
Now we need to monitor that question to reopen it if someone decides to close it. Or put some warning like
Please note that this is intended as a canonical answer to a common question ... please don't close as duplicate unless you're sure the other question has a better, more complete answer. — Zero Piraeus Sep 4 '14 at 22:29
 
6:01 PM
I'll post it, to keep it separate to the poster/editor.
Done.
 
Might as well ask a mod to clean up the comment section
 
If you lot would like to vote the comment to ensure it stays nearish the top, wouldn't go amiss.
 
fun way to spend Easter holidays: suspected appendicitis
 
D:
 
:C
 
6:03 PM
of course everyone is on the vacation in hospital as well
including tomorrow
 
@Ffisegydd now to start hammering
 
6:18 PM
@AnttiHaapala hope you're OK =/
@davidism thank you for taking the time to help edit things. Really appreciate it.
 
There's other ways that error can happen, and sometimes it will show up apparently in other code, because a different local name is shadowing. Need to figure out how to work that into the answer.
Huh, that's interesting. If you make a file called sys.py or os.py, the right one still gets imported correctly. Probably something the interpreter imports before the path is modified.
 
interesting. I'm currently re-reading this
to catch anything I might have forgotten
 
At some other point we have to go and hammer all the "urllib is different in Python 3" posts as well. They keep popping up as related to this one.
 
oh yeah, that was a massive change
 
We should just close Python 2 as a duplicate of Python 3.
 
6:33 PM
There's a ridiculous amount of things you can customize for the import process, and I've never seen a good example of needing most of that.
The only examples I've seen are more clever "never actually do this" things. Importing JSON files to get parsed structures, pip installing packages if they don't exist.
 
@idjaw I was being snarky about that silly question one of you posted earlier:P
since the only obvious way to do it is "name it differently, silly"
but I see that it's what you're saying too
so what about that "absolute import" stuff in the question linked earlier?
is it unavailable/hacky?
 
@davidism To promote best practices, we should probably avoid the whole import hackery
and just stick with our guns :)
"don't do this, silly....just have a better name"
 
"and don't import *"
 
I got one downvote on the question....I'm just going to blame Fizzy. Just because. :D
 
I would've left the canonical comment right after posting, to make it clearly visible
 
6:42 PM
it would be great to get all those comments deleted
 
-1 won't be the end of the world
 
@cricket_007 When you get a chance, can you delete your comments on the question? Thanks!
 
at least there's no CV as of yet:D
 
I want to bubble fizzy's comment to the top
 
@idjaw just flag your question and ask for them to be deleted
 
6:43 PM
oh ok
 
probably mention they should leave Fizzy's
 
is it OK to have those posts deleted?
isn't it a bit iffy?
 
rbrb
 
bye
 
well you're already the top google hit for the query I was using earlier to find duplicates
probably because of the "shadows name" phrase
 
6:45 PM
Everything is coming up Milhouse!
 
what the?:D
google's scary
 
OK I'm being yelled out to leave the house
 
stackoverflow.com/questions/36250353/… unclear question and answer is worse
 
Family time
 
it'll pass, take care;)
 
6:46 PM
@idjaw I have a window opened, that's outside enough for me
 
@idjaw your real life will be waiting here for you
 
That's what I told my wife
she didn't find it funny
 
@Ffisegydd Agreed. Let's get rid of it fast before the answer dumpers catch on
 
6:48 PM
alright. rbrb from my laptop. Cheers all. And thanks to all of you for your input on this. That was awesome.
cheers
 
o7
 
:D
o?
^ itchy head
 
@idjaw You seriously take your notebook outside with you so you can continue chatting when your wife asks you for family time outside?
 
6:53 PM
Sounds like he has his priorities sorted.
 
Sounds super dangerous to me.
 
@poke not at all. I was in my living room. The kids were napping and we promised my parents we would visit once they woke up. My wife had them at the door quickly. I just didn't realize she ninja-prepared them without me knowing
 
@idjaw you seem to get "ninja'd" quite often Captain :p
 
How did he reply to you though, do you ask? Well now he's on his notebook while driving to his parents.
 
So… where are you now?
haha
 

« first day (1989 days earlier)      last day (2959 days later) »