« first day (1565 days earlier)      last day (3366 days later) » 

12:19 AM
http://stackoverflow.com/questions/28182210/python-list-of-lists/281‌​82341#28182341
 
12:57 AM
Alright all -- quittin' time. Rhubarb
 
 
2 hours later…
3:06 AM
Cbg
 
cbg
 
3:47 AM
wow, 7 upvotes on a day with no new answers. does a little dance
 
4:21 AM
Does this question qualify to be tagged as well?
Anyway, edited it
 
5:08 AM
I've never really bought this. It's always seemed to me that the answer is "because Raymond Hettinger is okay with using weird hacks". — BrenBarn 4 mins ago
lol
 
6:01 AM
@vaultah I was just reading that. That also made me laugh.
 
I know Alex Martelli is something of a legend in the Python world, but his answers can be baffling; this one takes an IMO over-literal approach to a question that explicitly asks about good practice and ends up giving (to be charitable) distinctly unorthodox advice.
 
@ZeroPiraeus WOW. That was a roundabout way of returning somefloat.
 
Does anyone know if this is the defined (and guaranteed) behavior?
class A:

    def __enter__(self):
        print('entered')
        return self

    def __exit__(self, *exc_info):
        print('exited')
        pass


def f():
    with A() as instance:
        instance.attr = 'set'
        print('set')
        return instance

print(f().attr == 'set')
entered
set
exited
True
 
@vaultah Please put that in pastebin, not the chat.
 
6:19 AM
@jakebird451 Normally you'd be right, but the room's quiet enough at the moment that it's not a problem. Also, @vaultah's a regular here and knows the ropes; I'm positive he wouldn't have pasted something like that when the room was busy.
 
@vaultah What are you concerned about with the code? That enter and exit will not be properly called?
 
user559633
yeah vaultah, use a pastebin before we ban you
 
Anyway, sorry for any inconvenience @Zero, @jakebird451
 
@vaultah No, I am sorry as well. I came off as a jerk...
 
Don't worry about it @jakebird451 :-)
 
6:28 AM
If you are worried about the print statements being out of order, you can use sys.stdout.flush() to force the print statement to be printed out to the screen.
 
@vaultah are you wondering whether the return from inside the with block might prevent A.__exit__() being called or something like that?
If so, I think you're fine:
> Finally, if BLOCK contains a break, continue or return statement, the __exit__() method is called with three None arguments just as if BLOCK completed normally. (I.e. these "pseudo-exceptions" are not seen as exceptions by __exit__().)
— https://www.python.org/dev/peps/pep-0343/
 
user559633
@vaultah afaik, the enter/'set/exit behavior is the defined behavior as of python.org/dev/peps/pep-0343 and the true comes by nature of the context manager's own methods. where it's a generator, i'd expect it to treat the return without exiting (the last bit explained much better by zero)
 
user559633
cbg
 
The might be a dumb question, here's the ideone example. I want to know if __exit__ is called immediately and is guaranteed to block the execution
 
6:37 AM
cbg
 
user559633
i don't understand. the __exit__ is called at the end of the context manager instance
 
6:52 AM
Yes, instance is returned, then the __exit__ is called, but will __exit__ be executed before the equality test f().attr == 'reset'? Sorry, can't explain it well enough :(
 
user559633
OH
 
@vaultah You can set a pdb trace and step through it to see how python moves through the code. Python will automatically call the __exit__ function when that block has been left. Both on a return and on an exception. This is done before any further execution.
 
user559633
I assume that the f object is keeping the reference around long enough to do the comparison
 
__exit__ will not deallocate the instance of A. The return method ensures context is maintained until the function has terminated and carried out with passing the value it was returning.
 
7:04 AM
@tristan read that boston got ~23 inches of snow over 24 hours
@tristan that is more than ever in any place in Finland in the era of weather statistics, so can't complain really
 
user559633
@AnttiHaapala yeah, new england (the northeast us) received a non-trivial amount of snow, with some areas flooding quite badly
 
we thank Norway for taking the hit for us :d
 
@vaultah IIRC what happens is that the instance is not returned right away, consider `__exit__` to be equivalent to a `finally` block which is always executed "on the way out" even if there is a `return` statement in try block. So, Python gets the `__exit__` method from the stack and calls it and if there was an exception and based on the return value of `__exit__` further actions are taken. In the end `RETURN_VALUE` is called again.
https://docs.python.org/2/library/dis.html#opcode-SETUP_WITH
 
@Ashwini oh, thanks
 
user559633
7:21 AM
loving this insomnia. too tired to code, too awake to sleep
 
Hi Guy! Halleluah! Started learning python about 10 days ago, just figured out how to write lambdas and do map-filter-reduce. OMG, I feel like my life has changed, for the better! Still a n00b tho...Any good resources to practice functional programming in python ?
 
resists linking to the C-word
 
@Anupam too bad the functional programming is a second-class citizen in the python world :D
@Anupam you can teach yourself all of itertools
 
I heard that. Word on the street is - Haskell is the way to go to really get into funprogramming
 
Yeah or Clojure is nice
 
7:27 AM
ty
 
I just yesterday answered a problem with composed functional style, and it is slower than the generator expression because python optimizes generator expression so extensively
 
@RobertGrant I was wondering what the C-word was ... Lot's of dirty things popped in my head :P
 
user559633
heh
 
7:28 AM
@Anupam that is to say, if there is "map(x, l)" then in python (x(i) for i in l) is most probably faster
same for filter, (i in l if x(i)) faster than filter(x, l)
and especially if you combine them
but I find the generator expressions harder to read
 
yeah, i read that in a SO post somewhere earlier today.
someone was showing off how to sum a list using reduce and said that it was faster than sum()
 
I was like trying to finetune it to the perfection, but no.
hmm? sum ought to be faster
 
yep. some other guy promptly came along and corrected him
 
4.40526103973
0.901048898697
tosum = list(range(10000000))
print(timeit(lambda: reduce(add, tosum), number=10))
print(timeit(lambda: sum(tosum), number=10))
also: operator module
 
lol "second class citizen" is a bit of understatement then
 
7:36 AM
8
Q: Differences between functools.partial and a similar lambda?

prpl.mnky.dshwshrIn Python, suppose I have a function f that I want to pass around with some secondary arguments (assume for simplicity that it's just the first argument that remains variable). What are the differences between doing it these two ways (if any)? # Assume secondary_args and secondary_kwargs have b...

this too, the lambda is always slower in this case because it looks the variable names from the containing scope if global every single time
whereas functools.partial binds them tightly
I wish there was a function.bind() akin to javascript but no
@Anupam btw see this to see what python is about: stackoverflow.com/questions/16801322/…
 
that was a sweet solution. itertools is the way to go then!
are lambdas used in real world python applications then ?
 
not that much
:(
I would like more of them but
I mean, I do not often use map or filter anymore since they are slower anw and I find python lambda syntax annoying
make_branch_regex(map(lambda x: remove_extra(fnmatch.translate(x)), value)) I had written this recently it seems
make_branch_regex(remove_extra(fnmatch.translate(x)) for x in value) would be more pythonic, slightly shorter and faster.
 
user559633
7:52 AM
you can use lambdas, but part of writing pythonic code is "don't write lines of code that make people want to hurt you"
 
right, glad i had my enthusiasm curbed for funprogramming in python then.
 
:D
no, this is functional programming too, but with different syntax
 
@tristan ha. come at me bro!
 
just that the original functional style and lambdas are a bit slower compared to the specialized forms (and the pythonic style's often shorter)
@Anupam for the lambda: I use it whenever I need a single line function or closure
but it is not that often.
 
cbg(all)
 
7:59 AM
this is is so cool, getting out of the java mould. i now realize that have a long way to learning the pythonic way. but i am really liking the pythonic way so far...
 
cbg
 
user559633
helloc @PeterVaro :)
 
i have a SecurityError problem in my JS code because of the Same Origin Policy. I know exactly why that is, however after one day of searching to bypass this error only on the client side gave me jo result, so now I have to setup a minimal proxy server which will redirect the HTTP for me -- now my question is: how the heck would I do that in Flask?
@tristan -- well it is CPython by default, so helloc you;
 
@Anupam Yeah, Python code tends to be a lot sleeker than the Java equivalent. After you've been doing Python for a while Java will seem overly verbose & positively littered with braces. :)
 
@AnttiHaapala it's funny how you mentioned the make_branch_regex. Personally, I would have preferred the lambda solution, not realizing that python, sort of discourages it, by offering faster ways of doing it. I think that the lambda solution would be more readable while glancing through the tonnes of code.
 
user559633
8:04 AM
@PeterVaro flask + flask cors is a pretty quick way to handle this
 
in java 8 the lambda is everywhere
the map lambda is not really obvious unless you know what map and lambda are
but
remove_extra(fnmatch.translate(x)) for x in value
this says: calculate remove_extra(fnmatch.translate(x)) for each x in value...
 
@tristan that looks interesting, thanks ;)
 
of course we are adults here, and we know what map is :D
@PeterVaro cors only
 
@tristan that looks awesome
 
user559633
No worries :)
 
8:09 AM
@AnttiHaapala ?
 
no proxy
cors to kill old ies
 
user559633
you can probably just copy paste the syntax from this github.com/tristanfisher/surfboard/blob/master/api/api.py (oh, the syntax is plainly in there)
 
@AnttiHaapala of CORS
 
the greatest advantage of cors of cors is that old IEs don't like it
 
@tristan the question is: is that developer reliable? :P
 
8:11 AM
@AnttiHaapala I heard if you don't pay for your hosting, then you can lose even more users! :)
 
user559633
@PeterVaro ha, not sure on the flask-cors. for the example code: hell no, that guy sucks at computers
 
:):):)
 
user559633
what's the minimum version of IE that people with some of their teeth and money to spend on goods or services use?
 
As posted that's not a very good quality question anyway.
Neither bb has any lifetime since no instances of A are created.
 
user559633
there's this, which might even be a CV-pls as it asks for offsite/tutorial
 
8:20 AM
cbg boys! :D
 
user559633
cbg
 
so, whats up?
 
AttributeError: 'module' object has no attribute 'packaging'
 
user559633
can't sleep, writing wtforms widgets
 
this shit again
@MartijnPieters have you seen that?
 
8:21 AM
@AnttiHaapala way too often.
 
user559633
do you guys want to come along on CV-ing stackoverflow.com/questions/4484167/… ?
 
What is module here? Is it masking another module?
 
it is easy-install path corruption or something
 
user559633
what's easy-install? :)
 
what is the attribute packaging?
 
8:22 AM
@tristan the predecessor to pip
oh wait, you were being sarcastic XD
 
user559633
haha yeah
 
@MartijnPieters this is distribute/vssetuptools/vswhatever/vsmyvenv/vssystemsitepackages/vs me, basically the whole world against me
 
@tristan Yeah, voted.
The answer isn't that great either.
 
user559633
@GamesBrainiac i actually grabbed the namespace for easy_install in pip to prevent people from getting super confused
 
@AnttiHaapala right, I've not seen that then.
 
user559633
8:23 AM
cheers @MartijnPieters, agreed
 
@MartijnPieters basically, easy-isntall.pth decides I need /usr/lib/python3/dist-packages there at completely wrong point
 
@tristan wow.
 
@PM2Ring That is true. ;) . @AnttiHaapala cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html see strategy. In stark contrast to python lambdas in Java are optimized and as fast. Did not profile and check for tho. (Was searching for the doc )
 
@Anupam notice that the sorting paradigm for python was changed
because functions are slow, python does not support a straight comparison function anymore.
 
user559633
whoa, how did i miss that cmp is gone? wtyam
 
8:26 AM
instead there is the key= which calculates the sorting key O(n) times
because 99.9 % of time the sorting key is very simple
 
yes.
 
and the 0.05 % of time the comparison function is not stable
0.05 % of time then you get the hit.
 
user559633
 
@Anupam now this is 1 place where one often uses lambda
but again often not necessary
say you want lowercase strings
then you say key=str.lower, like in java one woudl say String::toLowerCase
 
@tristan You've used that before, haven't you :P
 
8:30 AM
but if you want lowercase with spaces removed, then
 
user559633
@GamesBrainiac i might have
 
key=lambda v: v.replace(' ', '').lower()
there is no other "better/pythonic" pattern for that
 
@AnttiHaapala Ahh, I see what you did there. You didn't codify it, thats why I was confused.
 
?
lazy here
 
@AnttiHaapala I was like "that shouldn't work, he didn't specify a replacement" :P
 
8:33 AM
@MartijnPieters This comment you made saved my day. Thanks!!! — George Florea 44 secs ago
Really?
 
There are 4 close votes on that ... Should I do it?
To cv or not to cv
 
user559633
 
Done
Thank you, code is the best documentation :-) — Ante Dec 19 '10 at 20:39
 
Yeah, how did that answer get 55 upvotes? It's three links!
 
user559633
it's also off topic
 
8:42 AM
do not flag it :D
I got 2 declined flags yesterday
and thus cannot flag anything anymore
other was link only answer
just delete the whole question :D
easier that way
 
The only good link-only answer is the one for recursion.
5
 
@RobertGrant Thats a good one.
 
I got declined because of the linkedin oauth credentials in 1 question and then
now flagbanned for a week
 
Post it in meta and ask why the yam?
 
no
bc ppl will start arguing that it is a good answer
 
user559633
8:52 AM
it's really not though. one of the flag reasons is linking without content
 
re-cbg
 
cbg
 
@Ffisegydd cbg
 
user559633
alright, back in 5 or so hours, time to get sleep. rbrb
 
rbrb
 
8:57 AM
Good night, sweet prince.
 
@cel done
 
wow.
@Ffisegydd You've been busy.
 
You broke my run ;-;
 
9:07 AM
ahahahahahahahaha
 
One day I'm going to get to 10 straight
I heard if you get to 13 straight requests you gain Wizard powers and they make you an SE developer.
 
Enough and they say, "CV, please?"
 
slowly clap while nodding with grudging respect
 
That's not just nice. That's SO nice.
 
Stop.
 
9:19 AM
I know. Too much awesome.
 
Morning cabbage all
 
@IntrepidBrit cbg
 
How's everyone's mornings going thus far?
 
@IntrepidBrit Brooooo! :D
Whats up?
 
@RobertGrant Yeah...too much "awesome".
@IntrepidBrit Sup
 
9:22 AM
@GamesBrainiac Currently suffering from DOMS. Trying to get back into shape, ready to clamber all over hydroelectric dams again if need be
Currently, my body hates me xD
Yourself?
 
DOMS?
 
Delayed onset muscle soreness
 
@IntrepidBrit Doing pretty well. Fighting with microsoft word.
 
Oh, okay
 
Cabbages
 
9:24 AM
Cbg dude.
 
@GamesBrainiac What on earth for?
 
Book writing. Can't do it in RST or MD.
 
You'd better not be copying Ghoulag
 
Does anyone know if the answer to this git question only applies to the current git branch or to the whole git repo, answerer did not specify.

http://stackoverflow.com/a/21991379/2911408
 
cbg(vader)
 
9:25 AM
@Vader it will remove the file from your current branch.
 
It's a pity the book industry doesn't TeX anymore
 
Meaning if you add a file to .gitignore, you then have to go through every single branch and remove it, or somehow merge them (with some form of black magic or something).
@IntrepidBrit I love TeX.
 
@Ffisegydd well in this case, this branch is all I want. I accidently added all my master stuff to my branch
 
So you're going to add all your master stuff to .gitignore?
That seems weird.
 
well I have a branch
but it has the master stuff in it, which it shouldn't
 
9:28 AM
I initially hated Tex, but then the University provided us with their template for creating documents, and I fell in love. No more dicking around with WYSIWYG editors trying to make it look right. Aaah. I wish I could use TeX for all my documentation...
 
so I need to get rid of the master stuff in my repo
 
@IntrepidBrit rst is pretty powerful too, give it a shot sometime.
Its got everything from interpreted roles to directives.
 
@Vader well git rm it and then actually rm it.
Then you don't need to worry about it being in the folder, so you don't need to add it to .gitignore.
 
I will when I'm working in a team of other softies. But rst will suffer from the same problems I have now with TeX. The other people (electronics/sales/etc) who have to contribute will look at it like it's some sort of evil blood magic
 
well my master is in / and the branch is in /test
so everytime I do git add --all in master it adds /test
 
9:32 AM
@Vader this sounds messed up. A git branch should be in the same location as every other branch.
 
... then don't do git add --all?
 
So I have master in /fizzy and then I branch it into dev to do some dev work, but the work is still in /fizzy
 
@IntrepidBrit Yes, that is the obvious solution but adding 10 files individually every time is teadious
@Ffisegydd so all stuff from one repo should be in the same folder?
 
I mean a branch can have extra/different subfolders say, but generally yeah it should be in the same place.
 
9:34 AM
hmm
but still the problem persists. How do I make it easy to keep branches from overlapping (keeping track of the same files)
 
2 messages moved to Trash can
Hello to you too @brisk! Please see the chatroom rules here sopython.com/chatroom
 
@Vader What do you mean?
 
@IntrepidBrit well I don't want master to track files in my test branch but if they are all in the same directory everytime git will want to stage those files
 
Yes, it'll want to stage them for your test branch. It shouldn't stage them to master until you checkout master and try to add/commit them to master
Unless you haven't properly checked out your test branch
 
git checkout test that's the one right?
 
9:40 AM
yep
 
so common workflow is to stay on your branch until you re ready to merge into master?
how do I prevent branches from trying to track what master is already tracking (is this the right workflow?)
 
I think your perception of how git is supposed to work is flawed.
When you're on test it's as if master doesn't exist.
You can have files that are in both, or files that are in just one, or files that are in both but different content.
 
@Ffisegydd well that how I think it should be but that's not the case.
 
@Vader Generally, yes.
@Vader Why are you trying to prevent it? Those changes should only exist in the test branch
 
Let's say I write a Python package called foo. I have just released 0.1 which is master. I then decide that I want to support Python 4 as well as Python 3, so I make a new branch called dev. I then modify all my code to support Python 4. I may have to add new files, or modify existing files, or maybe even delete files. I then say "Okay! I am happy with it!" and so I then merge dev into master.
While I'm working on dev, master is completely unchanged. I could effectively re-write the entire script, refactor everything, and master wouldn't know/care.
Once I've merged the two together, I can delete the dev branch, because it has the same content as the master branch.
 
9:46 AM
ahh :d
btw... on related note, in pycon.fi I had an argument with Ezio Melotti of coredev fame...
 
So if I am on branch tracking files that are also in master, I am not really tracking those files, just the branches own version of it?
 
In theory, I could be working on master simultaneously with Fizzy, but be working on bug fixes for the Python3 code - pushing/branching/merging more regularly than Fizzy would be - and it wouldn't affect his code
 
Yes :D
 
... Ezio said that "You should use git branches to have python 2 and python 3 version of your library, it is so effortless, or possibly a separate one for every possible python version"
I was like ".... ...... ..... ....!!!!!!" :D
 
Aaaah, I think this is all coming down to the definition of "tracking"
@AnttiHaapala Could be worse. He could be advocating the use of CVS haha
 
9:48 AM
ah ofc he didnt say "git" since all core devs use Hg and like it
anyway basically the point was that instead of doing polyglot code, everyone just should maintain 10 separate versions of their single library bc... "it's just so easy" :D
@Vader master is a branch
git tracks content, not files! it just tracks "source code lines" or "binary blobs" and where these lines seem to be residing at a given moment
 
I am just trying to figure out what the common git thing to do this'
when I switch back to my master branch all my /test files disappear from the directory
is that supposed to happen?
 
yes, since they exist in your other branch and not in master branch
 
Also how come when I switch from master to test it doesn't hide master stuff?
 
so git knows they are source files, and something it can safely "make dfisapper"
because those files werent tracked
 
but they were
I always did add -all before a commit
 
10:03 AM
@Vader Maybe you need to do a quick git refresher course; I found Ry’s Git Tutorial helpful when I was first learning git. Going back to basics may seem a little tedious, OTOH, it may help you get the git way of thinking & teach you stuff you neglected the first time through.
 
see git status
always use git status
@Vader also better to learn to use git add
and a lot
you know if you have git added a file, and then remove it by accident, you can recover the version of the time of git add
 
I did this to show me in test which files were tracked, it listed all of the same ones master was tracking
 
see git status (preferably get some color there)
 
git ls-tree -r master --name-only
 
yes but do git status to see what is there
 
10:05 AM
@PM2Ring This is me "learning git" I am not done learning it, so I can't refresh just yet. Link looks good, will check outfor sure
@AnttiHaapala kinda already deleted the repo, wasn't important anyway. Only meant for learning git
 
@Vader No worries. In that case, I'm sure you'll enjoy working through that tutorial.
 
So, is there any easy way you guys add stuff to the staging area? A magic silver bullet perhaps?
or always git add this, git add that
 
always git add, but I use zsh shell with mods
 
pfft
 
with tab it only autocompletes files that could be added ...
 
10:09 AM
I only have git bash
 
who tells you you can only have it
dunno if it works as well
 
I really like the github client, and fall back to git bash for stuff the client can't do
 
so git add <tab> only lists those files that are dirty
 
@AnttiHaapala dirty how?
 
not in index and are modified
 
10:10 AM
they weren't this way last commit?
 
cbg
so close... 1 more vote for a reversal.
 
what reversal??
did someone delete zalgo?
 
@AnttiHaapala someone always tries.
Brad Larson has got a whopping 15 reversal badges. O_0
 
10:26 AM
nice
 
Voted
 
10:41 AM
 
3rd hammer thrown
 
I suspect, actually, that the dupe is not what the OP wanted. But it's such a vague question that it's difficult to be sure.
 
@Jerry I used an actual dupe hammer.
@Ffisegydd better to dupe than to close as 'unclear'.
at least they got some help.
 
That dupe converts the current time to ms since epoch, but I suspect that the OP wants the ms of the current second. But yeah, better to dupe.
 
10:46 AM
isn't dupe what everyone voted?
also, that hammer was the thor hammer lol
 
Yeah. I voted dupe too.
 
@Jerry yeah, but when you refer to the hammer, that's the gold tag badge dupe hammer.
Gold tag badges can hammer a question shut with a single vote.
 
oh, I didn't know that one
 
I'm tempted to run a print of t-shirts with the Zalgo answer on it..
 
We have Toffee Hammers :D
 
10:47 AM
that hammer refers to gold close
 
@IntrepidBrit include the link.
 
@IntrepidBrit Do it. I'll have one.
 
but I got to insta close a few questions myself
just didn't refer to them as hammer
 
@MartijnPieters Good idea.
@Ffisegydd I'll look into it, see how much it'd cost. I think when you get it in like batches of 10, the price per print isn't extortionate
 
I think per the licence you'd have to include the link (legally speaking)
 
10:55 AM
Since after a second of googling, that popped up
 
Hi @All
 
Guten morgen.
We should make an sopython t-shirt...
 

« first day (1565 days earlier)      last day (3366 days later) »