« first day (1993 days earlier)      last day (2938 days later) » 

4:00 PM
@VasanthPrabakar define "open"
 
I want to open one of the link by it's position
 
@VasanthPrabakar You haven't provided NEARLY enough information. You really need to read mcve.
 
I tried but it doesn't works. It opens IE browser multiple times.. and I had to stop python running program
 
@VasanthPrabakar it sounds like you haven't read a tutorial. We require users here to have a basic understanding of Python. What tutorial should I read?
 
I'm guessing "open" here means "automatically start up a web browser and navigate to the url in the link, (or possibly opening a new tab in an already-running web browser instance, if such an instance exists)"
I guess you could use Popen for that? I haven't tried.
 
4:01 PM
Open could also mean "Get the html source from the link"
Though I agree I'd imagine your scenario first.
 
DSM
webbrowser.open(some_url) seems to work for me well enough.
 
My scenario is more difficult because of the "one at a time" stipulation. If you only want the second link to open when the user closes the first link, that's quite tricky to detect.
Unless... I wonder if you could use subprocess to detect when the web browser process terminates? But then you'd have to dispose of the "opening a new tab in an already running instance" feature.
 
what does that new mean? @davidism
 
@VasanthPrabakar try reading
 
4:03 PM
@VasanthPrabakar click the link and read it.
 
"new = 2"
 
DSM
Today's turning out to be a rough day.
 
yep, not having any of it
 
I've got gin at home. You're having a party. We'll survive.
Antti doesn't have an appendix anymore but he's still going strong.
 
4:04 PM
:D
 
@Ffisegydd Nobody reads those anyway ;)
 
Happy Birthday to @MartijnPieters!
18
 
I'd rather take back my appendix if I could get rid of this cough
 
Fun fact: Finnish people store their anger and cynicism in their appendix, meaning that Antti is now a reasonable and well-rounded person.
8
 
adds Fizzy to bucket list of people he needs to drink with
 
4:05 PM
Unfortunatly, I don't have enough Python expirience to understand this link problem :(
 
Dear python devs, please implement constants for the new keyword argument of webbrowser.open. open(link, new=2) is less comprehensible than open(link, new=webbrowser.OPEN_NEW_TAB_IF_POSSIBLE)
 
so I ran a dir(my_function_name) and I saw that __init__ is one of the things printed out. Does that mean in a decorator I can add a custom init to the function?
 
I'm pretty sure that's a thing you can do, yeah.
 
What do you mean by printed out?
 
to my terminal
 
4:07 PM
I'm not sure how __init__ is used by functions though.
 
def someFunc():
print dir(someFunc)
 
its not used in classes?
 
@Rooster no you can't, since your function was initialized already.
 
@Rooster type(my_function_name) gives you <class 'function'>. So yes, functions are objects of a certain type. That means they have an initializer that runs when you create a function.
 
4:07 PM
They're obviously objects but I don't think __init__ is called on every function call, I think it's already been - Kevin'd by Antti and Poke.
 
class Fred:
    def __init__(self):
        print "regular init"
def injected_init(self):
    print "injected init"
Fred.__init__ = injected_init
Fred()
#result: "injected init"
Whoops I think I misread the question.
 
but when you call a function its already initialized without the init
 
@Kevin That’s the other way around
def xy (): pass
 
You can overload the __init__ of user-defined classes, but that isn't what you asked, was it.
 
eh, I want to do that but opposite, actually without the class def @Kevin
 
4:08 PM
^ this calls Function.__init__
 
@DanielEngel no, calling a function is calling an already initialized object, a function object
 
also you cannot subclass from function:
>>> class bar(type(lambda:1)): pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
    type 'function' is not an acceptable base type
 
well, Im already adding params to the function in the decorator
except I want to validate the params
 
@Rooster the __init__ is there because all python classes have __init__ (that I know of)
 
but I dont see the decorator code running when I execute the function :/
 
4:10 PM
not all of them
 
@Rooster Maybe you should tell us what you are trying to accomplish, and then we can tell you why function objects having __init__ methods has nothing to do with that.
 
@Rooster you've lost me. What are you actually trying to do, and what does it have to do with __init__?
 
DSM
This seems like an XY problem. If you want to validate the parameters, validate them. No need for this __init__ stuff.
 
but this is a weird problem
eh, its complicated, sorry. Let me go fool around a bit so as to better articulate what I'm trying to do.
 
yes, next time do that first
 
4:10 PM
the CPython type object will have a reference to __init__ and __new__, I believe.
 
but I can say this, I want to validate args and kwargs via a decorator
 
so do that, you don't need dir or __init__
 
and __init__ would be object.__init__ if not something else
 
ya, sorry, I randomly just noticed it and thought things would be so much easier if I could use it :/
 
def decorator(f):
    @functools.wraps(f)
    def decorated(*args, **kwargs):
        # validate
        return f(*args, **kwargs)
    return decorated
 
4:12 PM
then doing a doubley nested thing in the decorator / use functools.wrap
right
 
there's the args, there's the kwargs, validate them
 
you can define a function inside a function???? I didn't know that
 
except it doesn't look like the decorator code is executing when the function runs
closure?
 
@Rooster what are you talking about?
 
@Rooster That may be because decorator code typically runs right after you create the function, not when you call the function.
def foo(f):
    print "I'm decorating something."
    return f
print "about to define frob."
@foo
def frob():
    print "frob is being executed."
print "frob has been defined."
print "frob is about to be executed."
frob()
print "frob has been executed."

#output:
#about to define frob.
#I'm decorating something.
#frob has been defined.
#frob is about to be executed.
#frob is being executed.
#frob has been executed.
 
4:13 PM
Probably a strange regex question. Can you have nested capture groups?
 
@Rooster The decorator returns a new function that replaces your decorated function. That new function validates, and then it calls the original function.
 
If you're expecting "I'm decorating something" to go between "frob is about to be executed" and "frob has been executed", then your mental model is off somewhere
 
@corvid yeah, pretty sure
 
right, so it looks like when the function is defined, the decorator code executes. but then when the actual function is called it does not
 
@Rooster Read my last comment again.
 
4:14 PM
so how can validation occur if at the time of execution the args and kwargs cant be accessed yet
 
@Rooster try reading
 
Okay it seems to work... I have a very strange replacement statement here
 
@davidism Today is really a hard day.
 
@Rooster check this as well. Explains how to use a decorator to validate certain method arguments.
 
DSM
> 'This must be Thursday,' said Arthur to himself, sinking low over his beer. 'I never could get the hang of Thursdays.'
 
4:17 PM
@DanielEngel nested functions have been in python forever, but the kind that davidism uses there is also a closure, which didn't work in python before 2.2ish
 
:29674621 agreed.
 
so as I read the example Kevin posted, its not possible to validate kwargs and args on an individual basis relative to the function being called?
 
im just lost in this function inside function
 
nested functions are easy once you understand that space-time is curved
 
@Rooster why not?
 
4:17 PM
@Rooster try reading
 
Getting decorator logic to execute when the regular function executes typically requires you to create a nested function. So basically, see davidism's example from two pages ago.
 
right, I read the example, the decorator code is only executed once, at the time of the function definition
 
kevin@ lol
 
@Rooster Again, read my comment.
 
@Rooster and then the decorated function replaces the original function and runs ever time.
 
4:19 PM
I will just continue to stick to classes instead of indeppended functions
 
@Rooster please read about how decorators work. TBH if you never used decorators, they are tricky to understand at first. So it is really well worth your time to do the necessary reading to understand what is going on when you decorate a method.
 
def foo(f):
    print "I'm decorating something."
    def f_(*args, **kwargs):
        print "I am the nested function."
        f(*args, **kwargs)
    return f_
print "about to define frob."
@foo
def frob():
    print "frob is being executed."
print "frob has been defined."
print "frob is about to be executed."
frob()
print "frob has been executed."

#output:
#about to define frob.
#I'm decorating something.
#frob has been defined.
#frob is about to be executed.
#I am the nested function.
#frob is being executed.
Tadaa, "I am the nested function" prints every time you call frob.
 
@DanielEngel Should I call someone? (*badum-ts*)
 
cbg
 
4:21 PM
@Kevin Can I just say that I’m offended by your Python 2 use?
 
I still don't totally grok decorators. I get how they work in theory, but I don't try to understand them.
 
eh, maybe my decorator with nested functions is just written wrong
same @Morgan'Venti'Thrappuccino
 
DSM
Argument validation is about the easiest possible example, though, because you don't have to close over any variables. You just add a line of code and then call the original function.
 
waittttt
maybe its not
 
@poke You absolutely may.
 
4:22 PM
so I have a bunch of print statements in the decorator
 
@my_decorator
def my_function

def my_function
my_function = my_decorator(my_function)
 
and the nested part of the decorator
 
@Kevin Good.
 
A more practical application:
 
those should only execute the first time right
 
4:22 PM
def require_only_ints(f):
    def f_(*args, **kwargs):
        for arg in args:
            if not isinstance(arg, int):
                raise Exception("Expected only integers!!!")
        return f(*args, **kwargs)
    return f_

@require_only_ints
def frob(a,b):
    return a*b

print frob(1,2)
print frob(-99, 23)
print frob(42, "Hello world")

#result:
#2
#-2277
#Traceback (most recent call last):
#...
#Exception: Expected only integers!!!
 
not in the newly created funciton?
 
@davidism Wait, is that seriously all it is? Wow. Okay, that makes a lot more sense now.
 
yes
 
@Rooster depends on your understanding of “in the decorator”…
@Morgan'Venti'Thrappuccino Haha :D
 
user2743227
can anyone help me with calculating gradients for a linear equation? i'm trying to write a logistic classifier... but I don't understand it =/
 
4:24 PM
@poke I have a bad habit of making things out to be much more complex than they actually are.
 
I recently linked this in an answer of mine. The following uses two decorators to explain what is going on, beautifully explained by Sir Martijn: here
 
I don't understand what is the problem we are trying to solve here
 
user2743227
I posted a question yesterday but doesn't seem like anyone knew the answer
 
@Kevin's approach breaks as soon as someone calls by kwargs
 
theyre trying to make me not stupid
 
4:24 PM
@DanielEngel I’m not sure anyone does.
 
or at best not ignorant to python syntax
 
@user1375469 Are you looking for linear interpolation? That's what I use to draw gradients when I'm rendering images.
 
user2743227
no, i'm trying to do gradient descent
 
user2743227
like so: stackoverflow.com/questions/17784587/…, but for matrixes
 
@user1375469 you've written an algorithm that you do not understand?
 
4:26 PM
ahhh fml
 
and here is a decorator that handles args and kwargs
 
@user1375469 perhaps you should look into *scikit.learn
 
I'll just go play around in a terminal until I understand
 
@Rooster reaaaaaaaaaaaaaad :)
 
user2743227
I can't write an algorithm for gradients.
 
user2743227
4:27 PM
no, it's more like. I can't wrap my head around the concept of gradients
 
can you post your code here?
 
I really think my issue is Im trying to refactor something weird to do something weirder
 
user2743227
14
Q: gradient descent using python and numpy

Madan Ramdef gradient(X_norm,y,theta,alpha,m,n,num_it): temp=np.array(np.zeros_like(theta,float)) for i in range(0,num_it): h=np.dot(X_norm,theta) #temp[j]=theta[j]-(alpha/m)*( np.sum( (h-y)*X_norm[:,j][np.newaxis,:] ) ) temp[0]=theta[0]-(alpha/m)*(np.sum(h-y)) te...

 
ii wish what I was trying was as simple as the examples yall are posting
 
@Rooster I wish you would post what you're actually trying to do
 
4:28 PM
Then you aren't doing a good job at explaining what it is you are actually trying to do. Because based on what we all deciphered, you are trying to validate args and kwargs using a decorator.
 
DSM
@Rooster: this plan of asking questions which are either (1) unrelated to your real problem like __init__, or (2) so different that nothing we say helps, isn't working well.
.. and for the second time in ten minutes three people say the same thing within seconds. We think too much alike..
 
moderators are going to be getting informed all day it seems
@JonClements sorry puppy, just one of those days
 
DSM
It's not that we're being crazy, right? Our guests really are just a little off today?
 
takes out the scooby snakes and a bowl of milk
 
3 hours ago, by Kevin
I've been online for five minutes today and I've already voted to close two questions. It's shaping up to be a grumpy day.
Prophecy fulfilled.
 
4:29 PM
yeah, not just you DSM. I noticed it too.
 
@davidism Umm... that's the 4th mod flag I've seen :p
 
@DSM really I think it started last night, but I decided to re-watch Gargantia instead of dealing with it.
 
I like the "reopen queue".
it is the fastest queue of them all: "no..." "f*scking no..."
and I do not even need to think of a reason :D
 
Now reading about gradients... Oh, it's like 3d slope.
 
ND slope
 
4:32 PM
Ok...is this a Thursday thing? Is there something happening today we are not aware of? Because wow
 
do you delete questions or they do that themselves
 
@MarkoMackic Both.
 
Is it the Twilight Zone up in here or something
 
well i asked that, because i didn't even start to read, and the post was deleted
lol
 
@idjaw I have a little bit of pity for OP there because modulus is slightly hard to google if you don't know the word "modulus"
But only slightly.
 
4:34 PM
lol this is really basic question :)
 
@Kevin I don't know. Print True if divisible by 5 seems to be a winner in the Google-web
 
A lot of people also don't know that the modulus operator is even a thing
 
man needs to take some math class on modulus
yeah
that's what i meant
but that's surely not the man from University
 
But you could technically synthesize the mod function yourself using floor division I guess: def mod(a,b): return a - (a/b)*b
 
eh, sorry, I guess I'm really just venting my frustrations about python being different from what I already know. Thinking about it, I am being really pedantic
 
4:35 PM
Pedantry is my favorite sport.
 
DSM
Pedantry isn't actually a sport, you know.
 
:-P
 
pedantry....pe...pantry...OK lunch time.
 
is pedantery when you do something carefully and correct ? like not messy ?
 
@Rooster You are also asking for help while being very vague about what you’re doing. We have been talking to you for a while now, and yet we can’t tell what your problem is. If you want us to help you, you should show us what you’re doing (link to your code), and then we may be able to tell you what you’re doing wrong and what you are misunderstanding.
 
> Pedantry. noun. Excessive concern with minor details and rules.
 
@Kevin i knew ,it's simmilarly said in our lang :) i like it, but i never was pedant :D
 
is there a python equivalent of jsfiddle I can make?
 
I had an online Python interpreter bookmarked on my old computer... But it's gone now :-(
 
@Rooster I searched for "python jsfiddle" and got results
 
user2743227
4:39 PM
@AnttiHaapala i'm trying to write the algorithm myself. using the library would be cheating =/
 
@Rooster do you ask us does it exist, or how you'd make it
 
fair point
 
so by definition programming can be called a sport ?
lol
 
If you're being pedantic, sure.
 
in that case i won't call it a sport , i don't understand paying attention to look details in code(when writing it) , if it works you can put it through auto formatter?
 
4:47 PM
auto formatting can only do so much
 
i don't get you , you mean it can't format it correctly ? or what ?
 
@user1375469, ok, I read the wiki article and it seems fairly straightforward... you've got the equation F(x) and the equation ∇F(x). You iteratively do new_x = old_x - Y * ∇F(old_x) until the x value converges to your satisfaction.
The hardest part appears to be choosing the correct value of Y to guarantee convergence. The page links to this, which looks relevant...
Line Search as well.
 
ok, so heres a fiddle that demonstrates what Im trying to do. (i realize I said validate args, kwargs, which is my ultimate goal, but first I just need to understand the decorator stuff). So I think if I get one question answered about it, my confusion will be cleared up. Why arent the print statements in the validator function firing at all, or on every call to test? repl.it/CBGy/1
 
@Rooster: validator = fn - why?
 
5:02 PM
Yeah, that seems wrong. You define validator, then immediately overwrite it with something else. print "************doing validation*********" is never going to execute that way.
I also don't really get what the .params stuff is for.
 
i guess the example I originally found did something like that, except it was copying func_name
well , its probably unrelated to the problem, but it needs to stay in there for other things
the params stuff I mean
 
If you just delete that stuff, then your print stuff appears.
 
what's the overall problem?
 
If you think that assignment is unrelated to your problem, you need to correct your mental model of how assignment works in Python.
 
PEP8 question that I can't really find an answer in the PEP8 doc (python.org/dev/peps/pep-0008/#function-names). How would you name a function that's meant to return a boolean?
Hea! cbg :)
 
5:08 PM
Generally I do is_.
 
Oh, you're saying the params stuff is probably unrelated.
 
I usually go with something descriptive like def is_blue(thing): or def can_be_frobbed(widget): etc
 
@HEADLESS_0NE I usually do something like (for example) def is_divisible()
 
@HEADLESS_0NE That's not typically something you find in the style guide. That's more general design stuff. I typically name it like I'm asking a question
is_, does_, has_
 
@Kevin How often do you frob widgets?
 
5:09 PM
The drawback being, you can't easily distinguish between a name for a function-that-returns-boolean, and a regular old boolean.
 
hmmmm, thanks for helping with the progress
 
@MarcusS Not since the restraining order
 
Okay, so for instance, I want to write a function that just checks if some binary (i.e. validator) is present, so... something like does_validator_exist() would be okay?
 
why not?
 
why not @HEADLESS_0NE ?
@idjaw we understood :D
 
5:10 PM
Eh, just wanted to have a second opinion. :D Thanks guys
 
I might lean towards is_validator_present just to preserve symmetry with the english description you used to explain what the function does
 
@Kevin yea, that actually sound better
 
def might_there_possibly_be_a_validator_perchance():
 
Although either way it's a little awkward having to write is_validator_present(my_validator)... I might do is_present(my_validator) but only if that doesn't introduce ambiguity elsewhere
Like, if a reader sees the name is_present and without actually looking at the function definition can deduce from context that it takes a validator as its sole argument.
 
Depending on how your code is structured, the module name might also be a disambiguator.
 
5:13 PM
def im_terribly_sorry_sir_but_i_insist_that_i_must_validate_this_data(data):
  validate_data(data)
  return "Thank you, have a good day sir"
 
Yeah, or if you can make it a method. my_validator.is_present() is a cromulent approach.
 
well, I'll have to check for two executable binaries, see if they are there. If not, download them.

so I guess having something like `is_executable_present(dir, name)` might be good?
 
And if you make it a property, then it removes the "function or bool?" ambiguity
 
It's just a helper function to a script, not a complicated program. :)
 
It's fine I suppose although it doesn't seem to offer much over just using os.path.isfile(os.path.join(dir, name))
 
5:16 PM
@Kevin just for clarity. Abstracting implementation details for someone reading the main script
 
@HEADLESS_0NE you can also use the comments
 
@MarkoMackic Madness! :P
 
yeah :D
i really don't get a point of abstracting things, that makes people more lazy and less intelligent
 
Please break each of those words into their fundamental concepts. No abstractions allowed!
 
do you want them in binary ? :D
lol
 
5:23 PM
yes.... serious face
 
nope , I'm to lazy to google ascii to binary
 
01101101011000010110010001100101001000000111100101101111011101010010000001101100‌​011011110110111101101011
 
yeah, that's invalid , you tricked me
...
 
That would be pretty easy, no?
Take each word from Marko's sentence. For each word, look up the dictionary definitions. For each word in the definition, look up their respective definitions. Until every definition merges to the same base word. Return each word looked up into a single non-sense binary string. Do a little dance and move on with your life.
 
>>> s = "01101101011000010110010001100101001000000111100101101111011101010010000001101100011011110110111101101011"
>>> "".join(chr(int(s[i:i+8],2)) for i in range(0,len(s),8))
'made you look'
For the lazy.
 
5:28 PM
I was even lazier. I just googled it. Shame.
 
quick. Destroy the harddrive. They are on their way
no time to explain. Just throw it in the microwave and run
 
About time!
 
Hmm, random UI question for you guys, a poll of sorts:
 
hard drives are cool, once i've accidently formated hard drive, and i found some free software for restoration, from hd with capacity 50 GB it found 300GB of data :)
 
5:34 PM
Let's say you're using your phone and you're on a screen that displays items in a list (labeled by name). The far right of each item has a pencil icon and a red X. You'd probably expect that clicking either of these does something different. Would it also be confusing to realize that clicking the name/row itself does something?
 
@MarcusS Yes.
 
I don't realize design, draw it in paint :p
or gimpp if you're on linux
"D
 
/ x Field
 
No, but only because I've written enough CRUD apps to know that if an edit button and a delete button are present, there must also be a read button nearby.
 
@MarcusS I would expect that clicking the row/name would give me info, the pencil would let me edit, and the x would delete/close.
 
5:36 PM
Depends on the list. If it's a title of something I'd expect it to expand out (think of accordion menus)
 
@Kevin My app is basically CRUD city all over the place
 
Although there's an argument to retain symmetry by making the read button an actual icon, like its siblings. So, an eye or something.
 
Click on / to edit, x to delete the field
 
Never mind
@MarcusS as it's a phone you have to make sure that dragging to scroll doesn't get annoying though.
 
But there's a counterargument that if "read" is the most common operation, it should have the largest clickable area, especially on mobile where it's easy to fat-finger and miss a 32px icon.
 
5:38 PM
That's one argument for having a dedicated "expand" button
 
Basically what I am making is a fitness app
 
In which case you want to break symmetry and make the entire label clickable
 
Make their thumbs fit by making the UI awful!
 
And there's a page where you can add/remove/change/log data for whatever metric you want
So for example, maybe in this list you want to record data for bodyweight
 
If it's a fitness app, then the target audience literally has fat fingers, so it's even more of a concern :-P
 
5:38 PM
To be honest this sounds like "Hold down to "right click"" functionality to me.
 
But the weird part is that there are different CRUD applications present
You could modify the descriptor itself, or modify the underlying data you've logged for it
 
So I was thinking that clicking the edit button brings up another dialog asking what it is you want to edit exactly
 
what about this ?
 
@Kevin Believe it or not, spacing the icons is a concern I had as well XD
 
5:40 PM
Jesus @MarkoMackic use a wireframe app or something. lol
 
I like my paint drawings, they are artistic
:D
 
No. No they are not.
 
Yea, a true expression of your inner-self.
 
What can i do, I don't have precise mouse (It must be it)
 
@MarkoMackic draw.io
 
5:43 PM
well the paint has those flowchart elements too, just i was too lazy to use them
anyone made keylogger ?
 
Yeah. Sort of.
 
You can find some Python keyloggers on Github. Example: github.com/ajinabraham/Xenotix-Python-Keylogger/blob/master/…
 
I wrote global_hotkeys.py so I could execute code in response to a keystroke even when the program doesn't have keyboard focus.
Capturing every keystroke probably requires a different approach.
GetKeyboardState instead of GetKeyState would save you 255 function calls, for one thing
 
I know to search on github, just was interested if anyone here did something like it :)
 
Am I the only one who would end up setting this up upside-down just so it looks more like a spider?
 
5:55 PM
I wonder how badly that would affect your overall signal.
 
hahaha
I didn't realize the internet already started making fun of this
 
I'm not inclined to make the world more spiderlike than it already is.
 
oh man this is great
 
5:57 PM
Anyone for cup of coffee ? bbl
 
My recent cup gave me palpitations....so I'm done for the day
 
WTH does a built-in game accelerator do in a router?
 
The same thing gold-tipped connectors do in Monster Cables, I expect.
 
accelerates games.....really Morgan?
 

« first day (1993 days earlier)      last day (2938 days later) »