« first day (1971 days earlier)      last day (2987 days later) » 

DSM
9:02 PM
@eleanora: unfortunately not, I usually use mpl in non-interactive mode.
 
Is this actually a good practice? stackoverflow.com/a/4264655
 
@HEADLESS_0NE If you not using the loop variable? Sure.
 
Looks okay to me
 
okay cool
 
I don't love for loops where you don't actually use the loop var and I try to refactor them away, but it's not inherently bad.
 
9:05 PM
What would you suggest instead?
 
It depends.
In that specific case? Probably print("Hello, World!\n"*50).
Though that's much less memory efficient. It all depends on what you're trying to do.
 
Okay, here's my use case. A user has a list of credit cards. I want to generate x number of randomized credit card objects and append them to my user's credit_cards list
 
I'd probably suggest a list comprehension/generator expression
 
Yup, that would be what I would do.
 
agreed
 
9:08 PM
[CreditCard() for _ in range(x)]
 
ah that's sexy
Alright, doing that.
 
The linked answer would be so much cooler if it said "If you use Python <3"
 
In general, if it's possible to use a list comprehension, I'm going to use one.
 
I've been a bit worried for using things like [plt.close(k) for k in range(10)], somehow it felt bad to use a list comprehension which doesn't actually construct something
 
But sometimes I see people using list comps as a for loop one-liner - maybe in code golf this has some virtue, but doing this [x.mutator_that_returns_None() for x in list_of_xes] feels abusive to me.
 
9:11 PM
I'm glad it's not bad practice:)
oops, just my use case:D
 
I MEAN YOU ANDRAS!!!
:)
 
ah I see, Morgan's example constructs an object for each element
at least my sense of wrong was right:P
 
Yes, HEADLESS_ONE wanted a list of CreditCards, so a list comp is appropriate
 
of course, that's cool
I probably wouldn't put this into an actual program, only interactively in ipython
 
I could just be being anal about it too, maybe some of the others could weigh in
 
9:13 PM
@PaulMcGuire I've definitely done that in golf, but I'd never do it in production.
 
@PaulMcGuire no, I feel the sentiment
 
@PaulMcGuire Actually it's a bit more involved than that.
        for _ in range(cc_count):
                cc = CreditCard().generate_credit_card()
                self.add_credit_card(cc)
Dammit, I always forget how to place code in the chat
 
@HEADLESS_0NE click "fixed font" button for multiline messages
 
Ctrl + K. It only works if the whole message is code though.
 
Make it a separate post, and click "fixed font"
 
9:14 PM
might have to go back a few characters to make it appear
 
@HEADLESS_0NE See, for that I would do this:
 
But really? ClassName().generate_instance_of_class()?
 
while len(self.credit_cards) <= cc_count:
    self.add_credit_card(CreditCard().generate_credit_card())
 
__init__?
 
Randomized data in generate
using faker + paypal test cc numbers
 
9:16 PM
Usually, just Class() will suffice, and this will call the __init__ method to initialize the new object
 
I suppose you can make generate_credit_card a class method?
 
But yeah, stub out CreditCard's __init__ for testing.
 
yes.
 
Instead of Class().generate().
 
And i for one wouldn't put this in a member function :P. Rather a public which takes as param the object to add credit cards to.
 
9:16 PM
You guys, I was just about to say "classmethod"..
 
@HEADLESS_0NE The ^K shortcut also works in chat
 
@paul23 What, add_credit_card(wallet, card)?
 
Thanks @Carpetsmoker
 
I'd much rather have that as a member function of wallet.
 
Something like that
 
9:17 PM
wallet.add(card)
 
@PaulMcGuire Yeah, exactly.
 
wallet.add(photo)
 
Well that's if you already created the credit card.
 
etc.
wallet.add(CC.generate_random_card_for_testing() for _ in range(x))
 
See, this is why I'm here. Thanks for the advice guys haha
 
9:18 PM
Oh oh are we talking about testing? Like unit testing testing?
 
@PaulMcGuire doesn't that add a tuple/list?
 
@idjaw test automation for web and backend
 
Depend on how you implement add()
 
generate_credit_card(wallet, **card_args):
    wallet.add_card(CreditCard().generate_credit_card(**card_args))
 
@PaulMcGuire but add will be called once
with the iterable
 
9:19 PM
that's how I would do it.
 
right?
 
If it is tolerant of single items or lists or generators, then all is ok
 
I'm trying to learn, is why I'm asking:)
to make sure I understand exactly what's going on
 
But maybe should be:
 
It'll be called with a generator object.
 
9:20 PM
@MorganThrapp cool, thanks
 
wallet.add_many_things(CC.generate_etc...)
 
@PaulMcGuire This is quite hard a requirement. Especially when you use "strings" as input.
 
how so?
 
Yeah, I would do two separate wallet.add_item() and wallet.add_items().
 
wait
 
9:22 PM
@AndrasDeak It was! Using a list comp as a one line for loop when you don't actually use the resulting list is evil, and should only be used for stuff like code golf.
 
Well depends on the circumstances, but often you use EAFBL, but say you can have strings/lists-of-strings as arguments, with the list-of-strings just having to add all strings in the list, you would do something like:
 
@PM2Ring will do, thank you:)
I mean won't do:D
 
I knew what you meant. :)
 
try:
    for i in input:
        self.blah(i)
except AttributeError:
    self.blah(input)
 
yeah, I'm just a bit pedantic:P
 
9:24 PM
This works for integer/list-of-integer (or any object mostly)
 
EAFBL: Easier to Ask Forgiveness Before you Leap ??? An interesting mixture of paradigms. :)
5
 
However wiith strings/list-of-strings it won't raise an error to fallback on the single addition method. Instead it considered "string" to be an iterable - thus it adds each character.
 
@AndrasDeak That's generally a virtue in a programmer.
 
@PM2Ring XD oops
 
can't you check the type if you know what's legal input? or is it not foolproof enough?
 
9:25 PM
@MorganThrapp - if the concept of a Wallet was such that having one contain nested lists didn't make sense, then I think that passing an iterable to add() should be legit for adding all the items in the iterable.
@paul23 - oh yes, is the string arg supposed to be one item or many chars?
If I did want to have my wallet contain a nested list, say a list of photos in a little photo holder in the wallet, then I could wallet.add(PhotoHolder(list_of_photos))
 
@PaulMcGuire Well it just makes things hard when you try to add generics - what if the object you try to add in the future implements __items__ or something?
 
?? you mean __getitem__? __items__ is a new one for me, is that in Py3?
If you were going to design a single method to accept single items or iterables, then you would need to make that call up front, whether a string is a single item or a sequence of chars. If you wanted to treat it as a single item, then you would probably do an isinstance(arg, str) or isinstance(arg,basestring) to expressly handle it as a single item and not iterate over it.
But it can be done
rbrb for a bit...
 
@PaulMcGuire That's true.
 
@PaulMcGuire Indeed, __getitem__() it is. (or __iter__() or next()) - I always mix up names.
 
Here's a nice ref: A Guide to Python's Magic Methods These methods are sometimes called dunder methods.
 
9:41 PM
@PM2Ring thanks for the link - going to read that, too.
 
@PaulMcGuire Wow - haven't seen you around in ages :)
 
Makes me actually wonder - can you make __call__ a classmethod? - and how to make THAT work compared to calling the initializer?
 
DSM
@JonClements: ahem, he's been around more lately than you have. :-)
 
@DSM wouldn't surprise me - it's still an accurate statement though :)
 
two typos in a row. ick
not a good flask day.
 
Given that most days are bad, that actually means this is just an average day. ;_;
 
=/
 
Time to trade in my Phantom 2.
Subject tracking, obstacle avoidance, 28 minute battery
 
nice, drones! - I'm waiting for this project to get off the ground again: playsheep.de/drone
 
9:56 PM
> maximum control range of 3.1mi (5km)
 
@davidism protection against predatory drones?
 
@davidism Drones become much more fun when they get hands-free and follow your programmed actions (subject tracking is one of those things).
 
@PM2Ring of course
 
late afternoon music sharing. Neil Young time.
 
10:21 PM
Rhubarb
 
bye
 
rbrb
 
@JonClements - hey! Yes, I haven't been around for a while, started coming by again a week or so ago
 
@PaulMcGuire cool - good to see you around again :)
 
10:31 PM
Oww :-(
 
if we're going to post crap questions, can we at least stop oneboxing them?
and really, stop posting them too
 
Okay; sorry. Just thought it was funny :-)
 
cbg
 
10:45 PM
This is funny. A friend of mine just tweeted this little js oddity
new Date('2016-03-09')
Tue Mar 08 2016 19:00:00 GMT-0500 (EST)
new Date('3/9/2016')
Wed Mar 09 2016 00:00:00 GMT-0500 (EST)
wonder what's going on there...
 
new Date('2016-03-09')
23:46:50.558 Date 2016-03-09T00:00:00.000Z
Sounds like a timezone thing?
I think new Date() assumes UTC, but since he's in EST it's a day earlier?
 
That is actually from my console
because I wanted to try it out
look at the statements, the two Date() calls are the same date
 
It looks like Date guesses at UTC vs local time based on the string format. :P
 
very strange
 
not like
 
10:48 PM
strange is why anyone would use 3/9/2016:P
 
23:48:17.606 new Date('3/9/2016')
23:48:17.608 Date 2016-03-08T23:00:00.000Z
hmm
I have the reverse
 
whoah, I can run js in my browser!
I've never actually tried it:P
I get @Carpetsmoker's output
including 23:00Z...
 
what browser are you guys using?
I'm on Chrome
 
can zip() (and izip()) take a generator (as opposed to a list of tuples)?
 
firefox 38.0 on ubuntu 14.04
 
10:50 PM
wow
this is getting fun
 
DSM
@paul23: sure.
 
I'm in CET (UTC+1, daylight saving)
 
DSM
I get Invalid Date for 2016-03-09 in rhino, and output matching idjaw's in chrome.
 
> Given a date string of "March 7, 2014", parse() assumes a local time zone, but given an ISO format such as "2014-03-07" it will assume a time zone of UTC (ES5 and ECMAScript 2015). Therefore Date objects produced using those strings may represent different moments in time depending on the version of ECMAScript supported
> Because of the variances in parsing of date strings, it is recommended to always manually parse strings as results are inconsistent, especially across different ECMAScript implementations
 
But why 23:00??:D
probably related to this
 
10:54 PM
But why male models?
 
"The String may be interpreted as a local time, a UTC time, or a time in some other time zone, depending on the contents of the String. "
 
@tzaman very apt quote there
 
Oh, too late :-(
 
how do you know I'm not a male model?
 
given that you didn't read the whole thing before asking about the thing, you could very well be
 
10:55 PM
:D
I assumed there isn't a time zone where it's 23:00 five minutes ago, and right now
cause it's still 2016-03-08T23:00:00.000Z
snap snap snap *storms out fabulously*
oh, you mean it gives the UTC midnight converted to the same time zone, right?:P
wait, @Carpetsmoker, are you also in UTC+1?
 
tl;dr: Don't pass random date-ish strings to date parsing programs that you don't understand or are ill-defined.
 
midnight in UTC+1 is 23:00 zulu
 
CET, yes
 
@davidism a lesson in RTFMing....it was right there. :) thanks
 
so it's definitely local time, converted to UTC
in retrospect, now I understand that this is exactly the first sentence of what @davidism quoted
still, it just wasn't clear to me:(
*goes back to computing entropy instead*
 
DSM
11:05 PM
Rhubarb for all!
 
brb @DSM
new trello feature. I'll give it a shot, see if it sticks with me:

http://blog.trello.com/trello-chrome-extension/?utm_source=newsletter&utm_medium=email&utm_campaign=MarNewsletter
 
11:18 PM
Anybody know how to use the format mini-spec language to say reformat a string 'en_US' to 'en-us' ?
 

« first day (1971 days earlier)      last day (2987 days later) »