« first day (3107 days earlier)      last day (1841 days later) » 
00:00 - 16:0016:00 - 23:00

4:00 PM
Hmmm, profiler tells me np.linalg.norm is the slowest part of the program
 
there are a few alternatives but they might all be slower
 
meh, looks like I need to write a gpu custom op
 
np.sqrt((v**2).sum()), np.sqrt(v.dot(v))
@Hakaishin yeah, that's probably a good option
for squared norm v.dot(v) could probably be faster
then again for a collection of vectors that would not work like that...
 
how can one access index in a for loop like this?
for d in lst:
print(d) # index??????
One thing I have come up with is this
for index, d in enumerate(lst):
print(index, d)
but im not sure if that's the best way..
 
enumerate is the correct way, yes.
 
4:09 PM
Yeah but I would like to have the norm not the squared norm. But I guess the longest part is the sqrt. Is there a way to tell np to only calculate it to a small precision? I don't need much precision 2-3 decimals
 
thanks @Kevin
 
@Hakaishin use a different dtype with fewer bits, but that's not always a good idea, and might not even be faster because hardware is weird
 
really liking this lang
 
.astype(np.float32) for single precision, start from an array of that type
And are you sure you need the norm? Can't you recast your problem to work with squared norms?
 
good point.
 
4:12 PM
im not sure why it didn't format the code I posted above (inserted 4 spaces)
maybe I have done something else..
 
A message is either all block code or not block code, can't mix both
 
Refer to sopython.com/wiki/… for information on chat formatting
 
oh I see... I did read that.
 
Perhaps I should move the "you can’t mix plaintext and code in a multi-line message." passage higher up because a lot of people seem to have trouble seeing it and/or retaining it
It's really hard to do UX testing on this because it's hard to ask "did you have difficulty locating this piece of information?" without making it sound like "what are you, blind?"
 
we might also emphasize the sandbox as a primary route for testing rather than shyly mentioning it as an aside
 
4:23 PM
I don't mind if the average user spends five seconds looking at the page before they get bored and close the window. I'm not here to wag my finger at the inattentive, I'm here to optimize the amount of information I can convey in five seconds
 
I'm here to wag my finger
 
user11285244
I want to get a lot of e-mail address from job_offer_site, but almost all of them block. How to get?
 
What do you plan to do with those emails?
 
user11285244
scrape to make mail deliver function. for job
 
it's almost as if they don't want you to get all those email addresses
 
4:35 PM
What kind of mail will you be delivering to those addresses?
 
user11285244
No, I just want many address for sales
 
Oh, for spam. Why didn't you say so?
 
user11285244
ha , what do you mean
 
@AndrasDeak rude :P
 
4:40 PM
@AtsushiSakata You seem to be asking "I want to scrape a webpage that doesn't want me to scrape it, in order to obtain a lot of email addresses I can use for sales". That sounds like blatant spamming and unethical, maybe even illegal. You might understand our reluctance to help you.
 
Yep, this is suspicious to the highest degree
 
and Kevin is very optimistic by nature
 
user11285244
so, is that possible to get mail address from web site? but many tools which is not free get a lot of email address. How they get
 
Nope, it's impossible, sorry.
 
@AtsushiSakata until you stop sounding like a spammer please go away.
 
user11285244
4:46 PM
no, I just asking
 
and I'm answering
 
user11285244
Yes, Idid not say I am spamming
 
You didn't, but we figured it out anyway.
 
user11285244
Ok, I did not use mail address to spam. I just want to know how many scraping tools get mail address ? Many API does not offer these things, how do they get?
 
Atsushi Sakata people, especially the ones in this chat, don't like that kind of thing. I suggest you drop it and not bring it up in the future.
 
user11285244
5:03 PM
@skyline33 what is the mean?
 
what ?
 
Perhaps skyline33 thinks it's impolite to refuse to answer your spamming question, and to also check your question history to see if you have any posts worth closing.
 
@Kevin by saying rude to Andras you mean? that was actually earlier convo about the formatting code
 
Oh. Conventionally a ping is understood to be a reply to the user's most recent message. If you want to reply to an older message, then it is more clear to reply to that message in particular, using the "reply to this message" link available under the dropdown menu that appears on the left of the message when you hover over it.
 
I see, didn't know that way actually.
Lesson learnt I guess
 
user11285244
5:11 PM
I also understand.
 
wim
5:42 PM
Is there any reasonable way to get outdated accepted answers deleted? The --no-install argument is deprecated in 2014 and removed in 2015. The pinned accepted answer is now basically just a waste of time for any readers .. it's worse than useless
 
You could try delvoting (won't work, needs negative score, not going to happen), or raising a custom mod flag describing the situation (won't work, they don't decide in technical matters). The only thing might work is if you convince the answerer that it should be deleted and they request deletions with a custom mod flag. Even then it might be a gamble, but I don't see any other way.
 
Create two tags, "pip-8.1.1-and-below", "pip-8.1.2-and-above". Retag this question and create a new question with the other tag. Then request that all the appropriate answers get migrated
 
Cabbage
Anyone knows how to convert this line Parameter(torch.from_numpy(_adj).float()) into tensorflow? is it same as tf.get_variable ?
 
@wim you should at least note that deprecation on top of the answer no to mislead modern users
some people will undoubtedly think that old versions must be supported as well, it should just be obvious when an answer is legacy
@wim actually, the asker was active 18 hours ago. You should just gently prod them to change the accept, problem solved.
perhaps I should do that instead, hold on
 
Yesterday I got a reply to a post I made in 2015. The comment asked me to make a revision. I did so. This at least proves that this works some of the time.
Mind you, I made the revision in the hopes that I would get an upvote for doing so. "hey can you please revert your accept" is less incentivized.
 
5:57 PM
It seems that the accepted answer to this old question of yours has been deprecated for a few years, see also the top-voted non-accepted answer. If I may suggest, please consider changing the accept so that the newer, top-voted answer is accepted, so new readers will see the relevant answer on top. Thanks :) — Andras Deak 10 secs ago
I'll also edit a warning on top the accepted answer
 
is <blink> an option? That would be a good eye catcher
 
No, alas. I'll abuse quote syntax though :P
 
If I am doing site-requested triage and I flag a question, will the mod see that question as it was when I flagged it or as it is in real time. Say I flag as spam because it looks like pure nonsense, but perhaps the user simply had some terrible formatting error and accidentally posted the question then immediately corrects the issues, will the mod see a nicely formatted normal question or do they have a way to see what I saw?
 
Pure nonsense is not spam!
if a post gets edited within 5 minutes and there are no comments, there's no history of the edit, and the mod will only see the new version
 
6:12 PM
Ok that is important information.
 
it's called a "grace period"
And "pure nonsense" as in "cat walked on keyboard" is either "very low quality" or "not an answer".
Oh, we're talking about questions.
there's no VLQ flag for questions, hmm...
 
Requires editing is my only safe option if the thing does not "look ok". I don't want to waste mod time with flags that I have been encouraged by the site to create
 
No, "requires editing" means "someone other than OP can edit it into shape"
 
You have told me this before, I guess I've gotten it right more often than not
Ah cool, I'll read that
 
what I usually have in mind is the LQPQ
I've done 5 triage reviews overall, so I'm not very familiar with the concept there
 
wim
6:20 PM
@AndrasDeak looks good thanks
I wish there was a better process for dealing with outdated stuff and bad accepts
 
man gpus are awesome :) What took before 2-3 minutes and in some cases 5-10 now takes 2-4s
 
7:03 PM
And do you get the same result? :P
 
"Well, the results are completely incorrect. But they were incorrect before, too, so it's still a win"
Curse this out-of-date Tkinter documentation
This is the second answer I've made this week that boils down to "tkinter.PhotoImage and PIL.ImageTk.PhotoImage have different interfaces"
I want to write in my answer "only tkinter.PhotoImage requires you to base64encode the image's bytes before you pass it as data" but when I pass unencoded bytes to it, it works anyway.
Technically effbot.org/tkinterbook/photoimage.htm never says that it will refuse non-b64encoded bytes. In much the same way that the rules of basketball do not say that a dog cannot play
 
what is the difference of these
#this
if x.find("string") >= 0:
# or this
if "string" in x:
and logically which to use or it doesn't matter?
 
no semantic difference, but if "string" in x: is more readable
assuming x is a string, anyway
 
7:20 PM
I see.. x will always be string, so will just use the latter.
 
If there's more than one way to do something, pick the one that looks more like English
Optimization guru PM2Ring has appeared as a miniature angel on my shoulder and he says that using in is also a millionth of a second faster because the code doesn't have to do attribute lookup to find the str.find method
He also says that since he's a figment of my imagination, the real human PM2Ring should not be held accountable for the veracity of this statement
 
one of these days there'll be an argument about micro-optimizations between PM2 and wim
(unless there already was and I missed it)
 
Optimization theory is a fertile field for arguments. Hardware-dependent benchmarks! Peephole optimizations that don't exist in all environments! Arguments about how arguing wastes orders of magnitude more time than you'd ever save by implementing optimizations!
They should take a Python 3.X build and encase the whole computer in an acrylic cube, and store it next to the International Kilogram.
Then we can at least have a little objectivity when we argue about The Standard Python
 
@Kevin we also these days have the luxury of not to be restricted to just a couple kilobytes of ram and make sure "every tiny bit counts"
 
Just leaving my objects lying around until the garbage collector gets to them is the height of decadence
 
7:34 PM
We can have a "oh well... just throw another 8gb ram at it" or... "screw it, I'll just add another processor"... and they'd probably be both cheaper options than optimising the code
 
user7437554
Hello guys, just want to make a short question...
 
user7437554
for line in smifile:
  mol=Chem.MolFromSmiles(line)
  hmol=Chem.AddHs(mol)
  hmol_list.append(hmol)
 
user7437554
If you see the last three lines, each output is input in the next line
 
We can throw more hardware at it, although this lax attitude is why every website is 20 MB
 
user7437554
Is there a better practice to use or is that ok?
 
7:35 PM
You could do:
for line in smifile:
  hmol_list.append(Chem.AddHs(Chem.MolFromSmiles(line)))
 
user7437554
right, but is that the best way or is it better to split it up?
 
There is no objective rule about when it is appropriate to create a variable even if you are only going to use it once on the next line. Use your personal discretion to decide what's readable and maintainable.
 
user7437554
fine, there is no difference in the required time to carry on the process?
 
Nope.
 
My personal standard is something like "use names if you can come up with a good descriptive name that communicates the intent of the value. If you can't, then it probably doesn't deserve a name"
 
user7437554
7:40 PM
Thanks both :)
 
By that logic, the majority of all functions, classes and modules I've created weren't worthy of a name :/
 
user7437554
Indeed
 
user7437554
(joke)
 
cbg
Does str.format() call str() on its parameters by default?
 
#contrived example. I prefer this:
for line in my_file:
    price = zort(frob(line)).partition("|")[0]

#over this:
for line in my_file:
    frobbed_line = frob(line)
    zorted_frobbed_line = zort(frobbed_line)
    partitioned_zorted_frobbed_line = zorted_frobbed_line.partition("|")
    price = partitioned_zorted_frobbed_line[0]
 
7:44 PM
@Code-Apprentice Yes, but you can override that with !r to call repr instead
>>> '{}'.format('a')
'a'
>>> '{!r}'.format('a')
"'a'"
 
sometimes i don't get what they mean by, 'your code isn't pythonic'
 
@Aran-Fey tnx for the info. I have a situation where a coworker is manually calling str() on the args and my first inclination is that this is unnecessary. Just wanted to confirm.
@skyline33 "pythonic" just means "conventions that are generally accepted by the python community"
 
And then there's also the 3rd twin that nobody cares about:
>>> '{!a}'.format('a')
"'a'"
 
If I'm reading docs.python.org/3/library/string.html#format-string-syntax correctly, .format calls the __format__ method of each argument. I suspect that most built-in types will call str() within their __format__ definitions, but this is not guaranteed.
 
7:47 PM
Regardless you definitely do not need to call str() manually
 
Dang, Kevin's right and I'm wrong:
>>> class Foo:
...  __repr__ = lambda _: 'repr'
...  __str__ = lambda _: 'str'
...  __ascii__ = lambda _: 'ascii'
...  __format__ = lambda _, fmt: 'format'
...
>>> '{}'.format(Foo())
'format'
 
docs.python.org/3/reference/datamodel.html#object.__format__ suggests that the basic implementation of object.__format__ calls str(), so that's what all classes will do unless they override that behavior
 
`import ctypes
import keyboard
from tkinter import *

#my_window = Tk()

def useros():
user32 = ctypes.WinDLL('user32', use_last_error=True)
curr_window = user32.GetForegroundWindow()
thread_id = user32.GetWindowThreadProcessId(curr_window, 0)

klid = user32.GetKeyboardLayout(thread_id)
lid = klid & (2**16 - 1)
lid_hex = hex(lid)
return lid_hex
lhx = useros()

while True:
if keyboard.is_pressed('alt+shift'):
lhx = useros()
if lhx == '0x409': #currently we are in English-Mode and changing
my_window = Tk()
My first code block!!!!!
 
So close :> backticks don't work in multiline messages. See sopython.com/wiki/… for more info
 
This potent piece of software displays a colored window for a sec when a language changes
 
7:51 PM
while True:
if keyboard.is_pressed('alt+shift'):
 
ufff
there's got to be a better way to code that
 
hahha if there is i must find it
 
I think keyboard.add_hotkey might make for a cleaner design, but IIRC that runs the callback in a separate thread, which may or may not cause Tkinter to flip out
 
7:53 PM
Tkinter is not good with threads
 
yeah, making changes to the GUI from a thread is a no-no
 
Ohhh
well i m taking down notes now
first script took me 8 hrs
 
It might be OK here if you create the window and manipulate it in the same thread. I don't think Tkinter cares about whether it's in a child thread or the main thread; it only cares that it's in exactly one thread.
 
without tkinter?
 
The maximally paranoid approach is to assume that Tkinter has to be in the main thread, and use queues or other message passing schemes to get the callback threads to make GUI update requests to the main thread
 
7:55 PM
root.after(0, callback_func), usually
 
@ExoticBirdsMerchant If you're asking "are you saying 'It might be OK here if you create the window and manipulate it in the same thread [If you don't use tkinter to create the window]'?", that is not what I'm saying. I'm saying that it might be OK even if you use Tkinter.
 
aha i ll try to upgrade this code
 
Hmm, recursive psychic requirement guessing gives me a headache
 
@ExoticBirdsMerchant You also have 5 lines of nearly identical code in your 3 if statements. You should turn that into a function.
 
what would u use
 
7:57 PM
Tkinter.
 
the else if s
@kevin i use the right tool now with the right way
i need to create a second function too Aran-Fey is right
 
Probably something like
def make_colored_window(color):
    my_window = Tk()
    my_window.title('GR')
    my_window.configure(background = color)
    my_window.after(350, my_window.destroy)
    my_window.mainloop()

#rest of code goes here

lhx = useros()
if lhx == '0x409': #currently we are in English-Mode and changing
    make_colored_window("orange")
elif lhx == '0x407':#currently we are in German-Mode and changing
    make_colored_window("blue")
elif lhx == '0x408':#currently we are in Greek-Mode and changing
    make_colored_window("red")
You could even use a dict and have no ifs at all.
 
so a funktion for the window which is used in the if elifs
 
def make_colored_window(color):
    my_window = Tk()
    my_window.title('GR')
    my_window.configure(background = color)
    my_window.after(350, my_window.destroy)
    my_window.mainloop()

d = {'0x409': "orange", '0x407': "blue", '0x408': "red"}

while True:
    if keyboard.is_pressed('alt+shift'):
        lhx = useros()
        if lhx in d:
            make_colored_window(d[lhx])
 
how nice ill use your code to improve the script
well it looks so smaller now ... ill run it
 
8:02 PM
Oops, some apostrophes keep sneaking into my code blocks
 
i am intergrating the useros functions importing modules
so u made a func with the gui
another with the layouts
wooooooowwwww u guys are good
you wrote that so fast hah guess it is experience
i finished the python documentation though
 
@ExoticBirdsMerchant yup, got a lot of help here, it is nice to be in.
 
i am using python for 2 months now on spare time after work
 
im using it for 2 weeks now.. I did also use py2 sometime ago but not to this extent.
 
8:14 PM
def foo(a, b):
    global prev_func
    prev_func = lambda: foo(a, b)
    print(a, b)

foo(x, y)
prev_func()
Is there a shorthand for lambda: foo(a, b) here?
 
Nope
 
@QuestionC prev_func = foo?
oh, nvm...you want a function that takes no args
this seems strange, though since you will assign to prev_func every time you call it.
 
The idea is that there's also a def bar: which assigns to prev_func every time it's called
The real idea is that I got an object that I would like to know how to regenerate itself so I pass it a lambda referring to the factory method that created it.
 
@QuestionC so you are saying that your MCVE isn't actually complete?
 
It's technically an X,Y problem but I don't want to get judged for doing X.
 
8:27 PM
no prob...so the direct answer to your question is no, there isn't a shorter way to do your lambda
 
8:50 PM
hello guyes
if i want to put the cursor of turtle to the middle of the window
is there any specific code for it
 
Can we change the value in a dictionary? e.g; I want to increase the value inside a loop.
 
yes
 
Do you know how to access a value?
 
i wrote it like this
from turtle import *

speed(100)
forward(100)
right(90)
forward(100)
right(90)
forward(100)
right(90)
forward(100)
right(90)
back(100)
right(90)
forward(100)
right(90)
back(100)
right(90)
forward(100)
right(90)
back(200)
right(90)
forward(100)
right(90)
back(100)
forward(100)
left(90)
forward(100)
left(90)
forward(100)
right(90)
back(100)
left(90)
forward(100)
 
8:58 PM
@Braanajjar that seems like a lot of steps and none of them scream "middle of the screen" to me. Are those steps really necessary?
 
if there is any method to make the code shorter
 
@AndrasDeak Yeah, like dict[key]
 
@taritgoswami OK, so how do you think you'd have to change that value?
@Braanajjar there most certainly is but I don't know turtle at all, sorry
 
@AndrasDeak dict[key]+=1 ?
 
@taritgoswami that would be a reasonable guess. Why not try it?
 
8:59 PM
dict[key] = "string" ?
 
but do you know a code to put the cursor in the middle
 
@skyline33 No
 
thank you anyway
 
@AndrasDeak it works
 
@taritgoswami awesome ;)
 
9:02 PM
thanks
 
Dicts are mutable, you can change any value to anything. Augmented assignments such as += work naturally.
@Braanajjar looking at the docs, setx(0) might work
same for sety
 
tarit that's how I change dict values.. doesn't necessarily mean it has to be string if you think so..
 
there's probably a single call that centers the turtle
setpos or setposition seem suspicious
 
no it didnt work
 
OK, I can't help beyond reading the docs for you
 
9:05 PM
or you know
it actully worked
 
no way
 
thank you
 
hehe
 
no problem
 
another question
how to cancel the process of drawing
 
9:06 PM
I'm not sure what you're asking but the likely answer is "raise the turtle pen" docs.python.org/3/library/turtle.html#turtle.penup
 
i want to have the drawing ready without the cursor to draw it
 
OK, that I don't understand at all. It might make sense if one knows turtle, but it doesn't make sense to me. Sorry.
 
ok,sorry for annoying you
and thanks
goodbye
 
bye :(
 
You didn't annoy me, I just honestly can't help
In other news, from the turtle docs:
> It tries to keep the merits of the old turtle module and to be (nearly) 100% compatible with it.
 
9:10 PM
"You didn't annoy me" hey hey it's gonna rain today ...
 
"tries [...] to be (nearly) 100% compatible"
 
nothing worse than putting up improved code you think will work but taking an hour to further fix it..
done for today
 
@skyline33 you should seriously consider writing bug-free code...
 
Is that OK?
that i posted it here
 
9:16 PM
In moderation yes. Although there was one user who complained about anime soundtracks being linked here, on account of NSFW video suggestions being raised in the preview.
Oh, I remember, the complaint was about having one-boxed videos. So next time you post something like that, make it a link that doesn't one-box, i.e. don't put the link in a separate message.
 
Its NSFW because its eye catchy the anime
aha okie
try the song it goes places
:P
 
I'm fine, thanks
 
I guess you need 1980s nostalgia to like it
 
well it has an atmosphere of mystery and yup maybe little 80s aesthetik .. not like Bazooka Joe, or Frankie goes to Holywood more on the scifi side
 
This is from that Ryan Gosling movie
The one with all the cars
 
9:31 PM
Transformers
 
Oh laurel, it's in the soundtrack name... Drive
 
9:45 PM
Hi guys, having a bit of a pickle. I am trying to translate some code from me to Python, but I am not doing Python for long. Anyway, I know I need to use c_void_p from ctypes, but I am not sure how to get the size of a ctype float to calculate the offset I need.
This is my C++ Code I want to translate: ` GLuint stride = sizeof(Vertex);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride, (void*)0); // Vertices
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, stride, (void*)(3 * sizeof(float))); // Texture`
 
What exactly do you mean by "translate to python"? Are you actually trying to interface python with some other language?
 
I am porting an older game of mine to python
using PyOpenGL
my pickle is the offset, the last parameter in glVertexAttribPointer. I am not sure how to do this in Python with ctypes
Or in other words: I need a pointer in the size of 3 c-type floats
 
I know neither library you're using so merely rubber ducking here: have you found the examples?
 
Yeah, most links are dead or are using outdated OpenGL or the vbo class, which is considered experimental, so not really a good use
Why is OpenGL so hard in Python?
 
9:54 PM
I find it easier in C++, but that is just me
 
float_size = sizeof(c_float) # looks relevant
@BadSnowflake it's possible that it's true. OpenGL is a low-level thing and python is high-level, when two of these meet it's never easy. I've worked with vtk which is between openGL and python in a sense, and already that's a huge pain to use from python. Still beats using anything else for proper data visualization.
 
Thanks @AndrasDeak. Finally got this part:
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, ctypes.c_void_p(0)) # issue here
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, ctypes.c_void_p(ctypes.sizeof(c_float)*3))
At least I hope so :P
 
Do you really need to pass c_void_p objects as the last argument? The examples I looked at seemed to pass number literals. Or is that the version discrepancy you mentioned?
hmm, I guess yeah: def glVertexAttribPointer( index , size , type , normalized , stride , pointer)
 
Those are attribute pointers. It tells OpenGL how your vbo is made up. I have a vbo that has 3 floats for position, then 2 floats for uvs
 
9:59 PM
so the first attribute pointer is null, the second 3*sizeof(float) away from the start of the array
 
I was asking about 0 vs c_void_p(0) etc., but as I said I'm not familiar with any of this so I'll take your word for it
if I wrote python bindings for a low-level library I'd make the API native-python-specific...
 
OpenGL is a bit tricky, since its only a definition and has no API in form of a library
 
I'm talking about PyOpenGL
it should be able to hide the machinery under its hood so that you as a user of PyOpenGL never have to figure out the size of a float
I might be missing something
 
OpenGL accepts a range of datatypes, from int to floats to doubles, which do not even exist in python as far as I am aware
but yeah, would be nice to have a python specific api there
 
Yeah, we don't have (c-)floats, only doubles (at least in native python), and ints are arbitrary-precision ints.
 
10:32 PM
I want to add an element in a set if it's not there, I wrote this code:
if(!(ar[i] in uSet)):
            uSet.add(ar[i])
But, it's raising a syntax error, where I have used the !(not), I meant to say, if ar[i] is not present in the set uSet
Can anyone tell me how I can change this?
 
yes, use the version of logical negation that is valid python
Note that it might not be slower to just try and add the item to the set. Sets only contain items once, so you can't end up with duplicates.
 
Ooh, I forgot it, just used that and it works
 
also note that python has the "not in" operator for convenience
 
@AndrasDeak Thanks, I will note it down :)
 
to be honest I don't know whether checking first is better
 
00:00 - 16:0016:00 - 23:00

« first day (3107 days earlier)      last day (1841 days later) »