« first day (2195 days earlier)      last day (2978 days later) » 

02:17
sometimes I feel like is list-comprehension golf
 
1 hour later…
03:19
need help with a python issue
and google ain't helping
mister @idjaw
bless me.
user559633
03:48
@qaispak sopython.com/chatroom read the room rules -- if you want help, you'll be expected to follow them.
Sorry about that
I am seeing [] used with some python functions (or lists?) I'm not sure what it means. something like

amount = [function()[0]]
user559633
It's okay -- everyone makes mistakes
what would the [0] mean there?
user559633
It would mean the first indice of the response
pingy pingy pingsalot
I was watching an engaging movie
user559633
03:52
>>> def some_function_returning_list():
...     return [1,2]
...
>>> some_function_returning_list()[0]
1
oh...
user559633
@qaispak do you understand why this works?
that makes sense!
of course.
user559633
okay, cool
user559633
So, then, [some_function_returning_list()[0]] means a list with 1 in it.
03:53
got it. So it's basically just picking up the first index of it
user559633
Yep!
the list would have just one thing.
user559633
Something cute/funny, guess what some_function_returning_list()[True] returns
I'm trying to understand the "egg drop" puzzle problem but the code is in Python and I've never used python before so it's taking a while...
my guess is it would return... just the list?
try it in your interpreter then try it again with [True + True]
user559633
03:55
Nope! It returns 2.
interesting
oh wait...I didn't notice how big the example list was
that was a minor spoiler :P
user559633
@qaispak Try True == 0 in your interpreter
user559633
I don't know the egg drop puzzle
false!
so wouldn't true return 1?
user559633
03:57
:)
user559633
I found that you asked the "egg drop" question on the main site. I'd add more detail, especially the relevant code that you've already written
Oh yeah. That was kind of a theoretical question. I previously wrote the code in Java. A ton of lines but I wasn't getting any help so now I'm looking at my friends code in Python and trying to understand it
It works obviously but I wanna know how.
recursion confuses the hell outta me.
user559633
what about it?
Nothing specific but in a general sense understand how things return from stacks and makes our final solution.
user559633
04:24
@qaispak Would you be satisfied with an explanation of a function that calls another function along as a condition is true?
user559633
04:35
def recur(x, recursion_count=0):
    if x:
        x -= 1
        print( "{tab_depth} return recur({x_variable})".format(x_variable=x, tab_depth="\t" * recursion_count) )
        recursion_count += 1
        recur(x, recursion_count)
    else:
        print("{tab_depth} return None".format(tab_depth="\t" * (recursion_count)))

recur(4)
user559633
that should print some text that explains what's going on when run
Please advise,
1
Q: How to set a specific download location in Mozilla - Marionette web driver?

Surabhil SergyI am having an automation script which worked well before the recent mozilla update. The selenium-python script automates some of my browser actions, and save certain reports (csv) to a defined location. I have been using selenium 2.53.6, which uses the following code : profile = webdriver.fire...

04:51
cbg
@HollyJohnson cbg, potato?
im slave. Potato?
im ok. Trying to fix my mistakes in code, ugh
same we greenbeans have it bad
05:40
Hello evryone,
When doing ZCA-whitenning, do we also whiten the test set as well? or this is only done on training data?
05:54
hmm
should update java...
@idjaw it is
@wim authn, authz
i can update ur java
:)
Does any one know whats the cause for this error? :
cov = np.dot(X.T, X) / X.shape[0]# compute the covariance
ValueError: shapes (28,28,1,50000) and (50000,1,28,28) not aligned: 50000 (dim 3) != 28 (dim 2)
06:12
@HollyJohnson not for long ;)
@Hossein isn't it obvious:
the shapes must be the same!
the covariance works on square matrices, or so...
yours is... well... an irregular hyper-rectangle
Thanks. I am new to python.
thats a 4d array, so basically if I use a for and just individually zca each image it would be fine right?
idk
this is not a python question, this is math question
For N dimensions it is a sum product over the last axis of a and the second-to-last of b:
*damnit works for 2-d matrices
What an apocalyptic view, friend took a photo from New Delhi ...
looks like New Black :P
06:29
@AnttiHaapala Thanks for the clarification, how can I reshape a 28x28x1 array into a 28x28 one?
 numpy.reshape(array, (28, 28))?
@AnttiHaapala Thanks alot :)
07:07
cbg
Cabbage
07:54
Hi, how can I print raw line with whitespace characters?
Cabbage
Cabbage, all
like 'hello\n\r'?
If stuff is hello\n\r it doesn't work
As in print(repr('hello\n\r'), end='')?
@VeeeneX Why do you want the string to end with \n\r? That's not standard in any modern OS. Do you mean hello\r\n?
07:58
@PM2Ring That is just an example
@VeeeneX Does holdenweb's code do what you want?
@PM2Ring Yes
@holdenweb Thanks
@PM2Ring I have a stream from generator and I'm trying to save line ending with whitespace
"===> Logging to r.e.com:5000 as veeenex\r\n===> Cloning...\r\n===> Cloning into '/storage/68G7W'...\r\n==="
08:40
Morning cbg.
Why python has difference in == and is?
is tests if 2 objects have the same identity, e.g. are they the same object
So it's equal to ===?
Sorta, except you can for example in an interactive session have 2 integers with the same value, but different identity. On the other hand in JS they'd still compare equal with ===.
=== in js is same value and type, == will try and coerce types to do the comparison, I believe.
08:48
Perhaps comparing apples and oranges, since python ints are always objects, whereas in JS you have the primitives vs. Objects.
is - rather more about whether it refers to the same object - stackoverflow.com/a/133024/1293222
So all in all, python's is is not quite the same
afaik they are the same, the difference in behavior re: integers is because JS ints are 'value types' while python doesn't really have those
as in === in js is also ref-equality
cbg, Antti!
08:54
@tzaman I think it tries ref equality first, then tries value and type equality if ref fails
yeap, === behaves mostly like is in python, except for primitives.... yet... strings, booleans, numbers etc are primitives, and thus half the things you'd compare would behave differently.
I'm not super versed in JS but iirc
var a = [1, 2, 3]
var b = [1, 2, 3]
a == b # False
a === b # False
Oh fair enough. Glad I'm not a JS programmer
which is funny because in python if you did that
a is b is False, but at least a == b would be True
08:56
Yup
>>> [1,2,3] == [1,2,3]
True
Maybe I just told you how Python does it
Yeah for arrays that (==) fails as they are of the same type, so no conversion, and they are both objects, so strict comparison compares identities.
I knew someone would bring up wat eventually :D
javascript WAT starts at 1:15
confusing
08:57
@VeeeneX in any case, please do not try to understand Python via JavaScript
s/Python/anything/
in Python, == compares the object values by delegating the operation to the __eq__ method - an object can decide whether or not it compares equal to another object.
a is b is true if they refer to the same object.
especially, it is always true that:
a = b  # bind the name a to the same object that b is bound to..
a is b # this is always true after the assignment above.
most of the time you don't want to use is. You use is for checking against None, True, False and so...
I've got what I need:
                line = ""
                for s in response:
                    s = s.decode("utf-8")

                    if repr(line)[-3:-1] == '\\r':
                        self.print_simple(line, end='')
                        line = ""

                    line += s
cbg ladies and gentlemen
@VeeeneX ah nvm,
really you will literally get \r?
not carriage return character
09:03
@AnttiHaapala That's what they want. See earlier posts.
omg
sounds like WXYZ problem already
XY problem
Yeah, sounds like there might be some convoluted thinking going on
Someday it will be opensource
@VeeeneX Can you tell us why you want the literal \r\n in that file ?
09:08
@PM2Ring It's not a file
It's http stream from docker-py
@PM2Ring note that that wouldn't work for literal \r\n either :P
it cuts 3rd and 2nd last characters...
this is stupid, why doesn't Python have negative zero
a fun bug in a python library... medium.com/@florian_7764/…
>>> 'abcdef'[-3:-1]
'de'
>>> 'abcdef'[-3:-0]
''
>>> 'abcdef'[-3:None]
'def'
@FlorianMargaine bad code like that everywhere
@VeeeneX HTTP streams will contain real line feed and return characters, even though the interpreter will display their representations.
@FlorianMargaine that doesn't sound right though
09:21
@AnttiHaapala Because there is no representation of -0 in twos' complement notation
Unlike ones-compliment notation
@AnttiHaapala ?
but that slicing is w0rng
@FlorianMargaine EPIPE is not generated in that case
I know you know, but couldn't resist answering your question literally
   EPIPE  fd is connected to a pipe or socket whose reading end is closed.  When this happens the writing process will also receive a SIGPIPE signal.  (Thus, the write return value is seen  only
          if the program catches, blocks or ignores this signal.)
@holdenweb grr :D
@FlorianMargaine sounds really wrong...
the read end must have disconnected...
if the buffer is written full, it just blocks
what if it's non-blocking?
@AnttiHaapala You could do this, but I guess it is a bit clunky:
for i in range(-3, 1):
    print(i, 'abcdef'[-3:i or None])
#output
-3
-2 d
-1 de
0 def
ah, it's EAGAIN
hm
how did that lead to the EPIPE we were seeing?
ah, the thrown exception was probably closing the read pipe, one way or another?
and the next write would throw EPIPE
yes, but why would it be nonblocking?
09:27
(seeing a EAGAIN is really not weird in gevent code...)
@AnttiHaapala kazoo sets it like that
not by default
ah...
one thing you can't do in gevent-aware code is blocking
and the behaviour is dependent on if HAS_FNCTL:
...
09:30
heh :)
probably a race on the read end? is there really only one reading?
the write end would throw EAGAIN when the pipe is full...
@AnttiHaapala yes, which would raise a ConnectionClosed
but no EPIPE
EPIPE would need the reader fd to be closed.
Finally!
               line = ""
                for s in response:
                    s = s.decode("utf-8")

                    if repr(line)[1:5] == '===>' and repr(line)[-5:-1] == '\\r\\n':
                        self.print_simple(line, end='')
                        line = ""

                    line += s
09:32
@FlorianMargaine it is writing 0s only?
abusing a pipe for a semaphore
@AnttiHaapala as far as I can see, yes
latest version uses a socket for that
but same idea
lol...
"!#¤"#!¤
probably because there is no cross-platform semaphores or sth.
yeah :/
gevent does have semaphore though, so we ended up using that
unfortunately, we actually can't up the semaphore count to 64k (or whatever the pipe buffer size is), because kazoo does some writes in the hub instead of a gevent callback, where you can't lock
so the semaphore count has to be "low enough"
(it does the requests in a callback, but when it batches them, only the first is in a callback, the rest are executed in the hub)
another fun bug is this one: github.com/python-zk/kazoo/pull/407
I was adding an iptables rule to drop the packets to zk, and it kept looping forever instead of crashing :(
Is it okay if I ask a question here if I am not getting any answer from posting on site?
Cabbage
09:43
@JasminShah Please read the room rules in the sidebar; in short - 1. yes, if the question hasn't been answered for a couple of days; and 2. don't ask to ask, just ask the question.
cbg @Bhargav
I'm totally new to JSON, want to convert JSON into a tree image. See my question here: http://stackoverflow.com/questions/40118113/how-to-convert-json-data-into-a-tree-image
Someone suggested to use https://plot.ly/python/tree-plots/, but I really don't know how to use it. Can anyone help?
So you did not read the rules.
Just read, will come back after 2 days. Melon!
Melons ;)
10:11
lol
nice
my thumb became wobbly
> var that = this;
--Javascript
user6568562
10:47
@mgilson This is very insightful, thank you
re-cbg.
@VeeeneX aarrgghh.
if repr(line)[1:5] == '===>' and repr(line)[-5:-1] == '\\r\\n' is a terrible test.
I suspect you would be better to try if line[1:5] == '===>' and line.endswith('\r\n')
Your code might work, because repr produces a canonical representation of a string, but it makes a lot more sense (and is faster) to test the string contents directly.
Sorry, that should have been if line.startswith('===>') and line.endswith('\r\n') - I forgot that using repr you had to take account of the inserted quote character
silently curses dyslexia and lack of typing skills
11:22
hi guys, cbg!
i have a doubt. I have a list containing items in the form - [('a','a1'),('b','b1'),...]. I want to remove the list items for which the 2nd element eg. a1 etc. are empty strings. I tried to do it using filter -
for i in range(0, len(sflf_list)):
            sflf_list = list(filter(None, sflf_list(i(1))))
But it says - 'TypeError: 'int' object is not callable'. What is the mistake?
cbg
@ChahatUpreti i is an integer from the range generator, not a tuple from the list.
i[1] gives - 'TypeError: 'int' object is not subscriptable'
no need for a for loop if you use filter. All you need is sflf_list = list(filter(lambda x: x[1], sflf_list))
@vaultah, sflf_list[i][1] gives IndexError: string index out of range. and what is wrong??
removes every tuple which has a falsy value in the second element
11:32
@Sevanteri, thanks that worked. what was the error in my loop?
well for starters, you were overwriting sflf_list in the loop. :P
remind me to think before writing anything :D
why don't you use a list comprehension instead? [x for x in sflf_list if x[1]]
ya, i guess that would be neater. just haven't gotten out of the habit of thinking in termsof for loops !!
11:55
@khajvah var self = this;, happier? ;-)
love it
:D
I'm tempted to CV this as a typo. Any thoughts?
12:10
@PM2Ring man, I need to answer more questions like that for the easy upvotes!
Whilst in principle I agree that something like this is very much needed, this template covers only a narrow subset of questions suitable for Stack Overflow - debugging questions that to my mind are not even the most interesting or useful. How would you fill in this template for a question that asks how to solve a particular problem for which you don't yet have any code (for example, you can't find a suitable library or API call)? Or what about a 'best practice' question? — Ian Goldby 4 hours ago
sigh. some people really don't get the scope of Stack Overflow
I think it should be closed - I very much doubt any rational search by someone facing the same problem could retrieve this question ...
@enderland You've got to be quick when questions like that come up. Foolishly, I tend to look for suitable dupes while others are FGITWing. :)
it has nothing to do with the exception, which is all the keywords, I threw a CV on there
This one looks interesting, except I'm not sure I understand the question. :) stackoverflow.com/questions/40130559/…
@AnttiHaapala get more digits is my new life goal
12:19
@holdenweb Did you see the post about the project leader from hell that I linked the other day?
@PM2Ring I'm pretty sure that's a troll post, but meh :\
@enderland I guess it could be; the OP claims they are a consultant.
morning everyone
adding to a set doesn't require copying the set, right?
Right.
12:27
I should look up the implementation of a set, I guess I assume it's basically a wrapped hash table
It would be weird if you weren't allowed to call add without calling copy first
@enderland It's definitely worthwhile to take a look at the CPython source for set & dict (they're quite similar).
Or are you saying, does adding to a set require the backend to copy the set in a way not visible to the programmer, much like how [1] + [2] and "foo" + "bar" create new lists and strings respectively? No, there shouldn't be any overhead like that
I just wrote an answer talking about sets, though I've rarely used them
@Kevin yeah
Although those examples are a bit apples-and-oranges because .add mutates and + doesn't.
12:31
I assumed no if it's a hash table but you never know when those details are totally abstracted away
I was gonna answer the question but it was put on hold... Tomato
@enderland Set & dict use a dynamic hash table, so as the number of items grows it's periodically necessary to build a new hash table. But that happens at C speed.
Do you guys think it will be a performance hit to animate all movement on a given page? I like animations a lot
user6568562
@PM2Ring Could you give an example to illustrate this [ : ?
:33577885 import sys

s = set([])

sizes = set([])
for i in range(100):
    s.add(i)
    sizes.add(sys.getsizeof(s))

print (sizes)
prints:
set([232, 744, 8424, 2280])
huh, direct reply-to breaks the indentation but fixed-font breaks direct replyto
12:43
@randomhopeful It's not something that's easy to illustrate in Python, but here's a relevant question by Wim: Modifying a dict during iteration. Bear in mind that this is an implementation detail, Python doesn't have to behave like this, but CPython (currently) does.
KPython will never have to rebuild new hash tables because there will be a hard limit of 20 elements per set. Adding additional ones will cause a kernel panic. "if you need more than 20 elements, you're probably approaching the problem wrong anyway", says the developer.
(It's me. I'm the developer. Stop using sets.)
You can call sys.setsetsizelimit but the community will shun you.
user6568562
@enderland ; @PM2Ring Thank you ! It is too advanced for my basic grasp, but I bookmarked them for later revisit [ :
@PM2Ring :-O Fortunately I only have to deal with the founder from hell, and do still get to appoint my own development staff
13:08
@Kevin I presume there's a maximum to that as well, but you can call sys.setsetsizelimitlimit to increase it?
Yes, and that also has a limit, which you can increase with sys.setsetsetsetsizelimitlimitlimit. There are in fact an infinite number of these functions, although you can only actually use the first twenty of them.
You can use more if you use sys.setsetsetsizelimitinfiniteregresslimit though
Why not go the whole hog: sys.setsetsetsetsizelimitlimitlimit.__call__.__call__.__call__(something)?
Now you're thinking with KPython.
13:21
@Kevin I'm hoping that that attribute's maximum is also 20. You can just make it less than 20.
Oh crap you already did that
And better
Yes, the maximum size is 20, but the developer did a lousy job implementing it so you can still work around it by doing sys.setsetsizelimit(0x20)
>>> dir(c)
['...', '__doc__', '__module__']
user559633
@holdenweb Why is he/she the founder from hell?
user559633
(asking so i can fix my own behaviors or know what to avoid doing that's frustrating)
Satan was the first entrepreneur. "F this, I'm going to found my own afterlife! With blackjack! And hookers!"
13:50
I haven't use yield from very much (it doesn't exist in Python 2.6). Stylistically, is yield from (n, n+2) ok, or should I just do yield n; yield n+2?
I didn't even know you could do the first one.
Somehow I assumed that yield from only works on generators. Tuples aren't generators, so I guess I'm wrong.
yield from is very nice in recursive generator functions. Eg, you can do yield from my_recursive_func(some_args) inside my_recursive_func
But yeah, it works on anything that you can iterate over.
Yes, I agree. But when I use it, my_recursive_func is a generator function, so it nicely fit in my broken mental model.
Now that I know it's valid syntax, yield from (n, n+2) does not bother me stylistically.
So is the difference that if you did yield my_recusive_func() that that function call would not be invoked using the event loop?
If you did yield, then the generator object would get yielded, rather than each individual item that the generator wants to yield
13:58
Sorry, I asked that question inside a context I wasn't talking about
Perhaps I should write some code
>>> def f(x):
...     yield x
...     if x >  0: yield from f(x-1)
...
>>> def g(x):
...     yield x
...     if x > 0: yield g(x-1)
...
>>> list(f(3))
[3, 2, 1, 0]
>>> list(g(3))
[3, <generator object g at 0x011E3090>]

« first day (2195 days earlier)      last day (2978 days later) »