« first day (1844 days earlier)      last day (3089 days later) » 
00:00 - 19:0019:00 - 00:00

7:01 PM
So there's convention, then there's a mechanism to override convention in the heading of your modules, then there's Beazley's decorator that pushes information that would normally/statically be in that heading back down into the module.
 
@PM2Ring First I've served media files directly the problem was lack of security, then I wrote a Django function view and checked security before serving media files, on the other hand, Android RetroFit framework which can cache media files on device, is checking security again when loading from cache and this cause delay on loading images
 
Augh, I have achieved a bad state trying to have venv and virtualenv at the same time (venv from a Canopy install, trying to get django running in virtualenv). So bollixed, such irreversible.
 
Anaconda seems to work far better than Canopy from my experience.
Of course some people think you should just stick to pip.
 
Air
@Serjik Okay, but did you try it?
 
I prefer to be pragmatic over dogmatic. New users are easy to get going with Anaconda. Experienced users may prefer to stick to pip.
 
7:18 PM
...now I could have three problems...

Different assumptions among different groups I work with: the sci/numeric/engineering people assume there is one least bad version (of, to oversimplify, interfaces to LAPACK) and are happy with One Install For All Your Real Work. The web developers assume every single project is going to have its own pile of fragile dependencies. And the sysadmin next to me runs practically everything of interest in its own virtual machine, when he can't get them actual separate machines.
 
Observation: sci/num/engineers work with numbers and abstracts. Web devs work with templates. Sysadmins work with computers that have real users.
 
Convert this python code into a tkinter code - unusually polite give-the-code request
 
the person with the least abstract responsibility requires the most separate environments
 
So after giving it thought, I like the name by convention, export to API method. I think the __all__ can have its uses, though. export goes too far afield IMHO
 
@Kevin That's a rare "upvote and vote to close" question.
 
7:22 PM
Even if I was inclined to give teh codes, it's actually fairly nontrivial to turn "falling rock" code into a GUI.
You really need to know the underlying business logic, but only the OP has that.
 
yeah, as a perplexed user, I think the sysadmin has a good point.
 
you guys using containers?
that's probably the best thing for your use-case.
 
Docker is the Next Big Thing I want to learn.
 
I mean, you could write a GUI that's nothing but a label for output, and a text box for input, and a button for submitting... But how is that any better than the command line?
 
@Kevin looks nicer to the user
 
7:24 PM
@AdamSmith Yeah, I really should look at that at some point.
 
A container would probably make all three stakeholders happy.
 
it's nontrivial to implement though
 
I think perhaps more trivial than you might think.
 
I'm tempted to write some kind of stdout-redirecting monstrosity that runs the OP's code as-is, but with a thin GUI veneer.
It would require some coroutine magic, I think.
 
Kevin, you just can't keep chasing every temptation.
 
7:27 PM
Just a little longer and I'll catch that dragon
 
Captain Ahab didn't have more than one Nemo. You gotta focus.
 
I have a one to many relation , say an attribute alphabets is related to an attribute number , such that the given value alphabet has an array of values associated with it , say a->1,4,7,9
b->2,4,5,6
c->1,2,3,4

what would be the most efficient way to store them in a database, is it alphabet->number, such that

a->1
a->4
a->7
a->9

or is it better to store as json encoded alphabet->numbers

a->[1,4,7,9]

I am using mysql database
 
I like the first one better. Makes it easier to write native SQL queries that look at the value arrays' contents.
 
Are you going through all the channels just asking this? I know you just said it in the PHP room.
 
Whoops, I can't count.
 
7:31 PM
It depends on the application, but generally the first approach.
Lets you do things like "Look up every letter mapping to 5" if you need to.
 
so in terms of execution speed which would be better?
 
Guys :\ who here is good at recursive functions? This one is annoying me
 
@Kevin I thought I was diagreeing with you before you edited...
 
:)
 
I'll help you @corvid.

Guys :\ who here is good at recursive functions?
 
7:35 PM
I'll help you, @QuestionC.
 
I write Y combinators for fun, so...
Psychic debugging: you forgot to have a return statement in your recursive case.
 
@JibinMathew Neither is meaningfully slower than the other. The first approach is more database-y though.
 
@AaronHall return recursive help from me
 
You renamed the function in the def line but forgot to rename it in the line where it calls itself.
 
Okay so I have a string like profile.games.$.tag, where $ represents an arbitrary index in an array. I also have an object. I want to find in this object and replace anywhere that matches this string. I'll put a gist real quick.
 
7:38 PM
Passing two -O flags to the Python interpreter can result in malfunctioning programs (if they expect docstrings). So... which popular libs introspect docstrings (aside from maybe pydoc)?
 
@CSᵠ yield from recursive_help(self)
 
@corvid yield from @AdamSmith
 
ack, semicolons!
 
DSM
x.sort(lambda x: x == 0)
 
7:44 PM
@DSM Ooh that's interesting
 
Changed it around a bit
 
DSM
I think the teacher is looking for the purely-indexed based version of NPE's answer (keep a pointer and copy the nonzero values there, then zero-fill the remainder.)
 
neat pro-tip I forgot about: adding \G at the end of mysql queries. Makes it so much nicer to look at
 
channels my inner Dalek EXPLAIN
 
Air
7:58 PM
@PM2Ring Poor Bill must miss his diamond at times like this
 
@Air :) Maybe, but it's not like there aren't plenty of others to help him close rubbish like that.
 
Air
@AdamSmith Would be a great April Fool's joke if a prominent DBMS announced a voice-recognition query execution feature and used a Dalek sound byte there. A clip of someone trying to pronounce Little Bobby Tables' name would also amuse. Who wants to hire me for their tech company April Fools Joke Team?
 
I think I might have it, except for this dumb positional thing character :|
 
I am facing an issue i have number of devices that i connect to a local server, but the issue is that if the local server is restarted then its IP might change , I want all the devices to keep updated with the new IP of the local server, how do i do that
 
Is that a Python question?
 
8:03 PM
More of a networking question , any help would be great
 
Perhaps SuperUser would be better qualified to answer such questions.
 
@JibinMathew you asked the same question in php I see. Please don't just spam your (off-topic) questions to multiple rooms like that. It is extremely rude.
 
@AdamSmith attack any interesting codewars lately?
 
8:18 PM
Aw, I wrote a general-purpose answer for that GUIfication question, but I forgot that I closed it :-(
Oh well. OP, if you find your way into the room, here is teh codes.
 
so sad...lonely codes with no one to has them :(
 
I'll just bust it out for the next "make me a GUI" post :-)
 
"And here's one I made earlier..."
 
It's like a cooking show. "... Cook at 450 degrees for three hours. Luckily, I have one prepared ahead of time"
Pulls perfectly formed program out of the oven. The trick is to marinate with an even coat.
 
The Joy Of Coding. With Kevin Kevinson
can you grow a fro?
 
8:23 PM
Man vs Code With Kevin Kevinson!
 
Relevant:
If a script that was fine before now stops working, that's just it's way of letting you know it misses you and wants to hang out again.
 
oh this is gold.
 
That's a very zen attitude.
 
Best Twitter Account Ever.
 
Well. Now aint that the truth
Many of us think programming is scary, or that you need a degree to do it. That’s not true. It’s about ❤️ and being willing to learn.
 
8:27 PM
I think it's time for me to get a twitter. This and Bored Elon Musk have really changed my views of it.
 
I also like Internet of Shit.
@internetofshit, In your stuff
Obviously the best thing to do is put a chip in it
199 tweets, 22k followers, following 4 users
 
For me, it's usually less heart, more burning spirit. "Pierce the heavens" etc etc.
 
That sounds like some CSI shit.
I mean, anime version tho
"I CAN'T CRACK THIS ALGORITHM, LEND ME YOUR POWER STACKOVERFLOW!"
 
needs more VB GUI
 
Didn't one line it to avoid giving someone an epileptic fit.
 
8:32 PM
that's OK. I clicked and had it. Best epileptic fit. Would do again.
 
@corvid Seems quite tricky. Don't think I can work it out today. Ask again tomorrow.
 
That's great. If you could give me 5 stars on my iTunes epileptic fit podcast page, it really helps us to succeed.
 
deal.
 
Next with on Fizzy Fits, I'll be bringing you the top 20 cat gifs that can induce a fit in your loved ones. See you then!
 
DSM
Being senior enough to have research minions is very convenient.
 
8:34 PM
I am filled with jealousy.
Although technically I'm the only remaining active dev on BigCorp internal product #1234, so if they hire anyone else they'll be my defacto minion.
 
DSM
One of our former interns has become full-time for the next 3/4 year (until he starts med school), and he's smart and productive. Very handy.
@Kevin: what happens if #1234 stops being used for some reason? Do you get transferred?
 
I'm not a very good minion. I argue with our technical lead about what to do as much as actually do stuff.
I've also been known to assign both him and the other devs sprint tasks D:
 
DSM
That's.. not very minionish.
 
@DSM Transferred in the sense that I stay physically where I am, but work on something else, yes.
 
As I said, I'm not a very good minion.
 
8:37 PM
The internal product backlog is long enough that I'll always have something to work on as long as they want me to work on something.
 
DSM
@Fizzy: In your lead's place I'd sabotage your code to protect my position. Always check the hashes. :-)
 
It would take massive societal upheaval to make the whole backlog irrelevant. Actually, that might make it longer. Depends on the kind of upheaval.
 
Quick question regarding pandas. I've got a string column and an int column. I want a third column to be strColumn[:intColumn], but can't seem to get the syntax down. Any ideas?
 
Global thermonuclear war -> more work. World peace and pastoral utopia: less work.
Good thing too, since the pastoral utopia doesn't have electricity.
 
@Kevin The gist problem? I think I might be pretty close to getting it
 
8:41 PM
Well, if you're still pretty close to getting it in 15 hours, I'll help.
It's an interesting problem because the object(s) you're trying to manipulate aren't necessarily at the bottom level of the tree
 
Yeah, therefore recursion is necessary
 
DSM
@BradRice: eh? that makes it look like you want a column with lists or Series as values.
 
I'm thinking a two-step process. The first function finds all the keys that match the wildcard. The second one creates a new version of the tree with the desired changes.
 
DSM
@BradRice: oh, wait. Do you mean you want to turn ["ABC", "DEF", "GHI"] and [1,2,3] into ["A", "DE", "GHI"]?
 
@DSM Yes exactly
Just can't get the syntax right
 
DSM
8:46 PM
Erm. I'm not sure there's a vectorized way to do that. Gimme a sec.
 
I'm working on legacy code from the MS-DOS era, so all the file names are 8bytes. "RPRTRCPT" The most useful filename ever.
 
@Kevin yeah that's what I am doing currently
 
@MorganThrapp almost sounds like a dinosaur....almost. raprotriceritops
 
Ooo, or "UnPdLnfl".
 
now that's just gross Morgan
 
DSM
8:47 PM
The non-vectorized way would be df.apply(lambda x: x["S"][:x["I"]], axis=1) where S is the name of your string column and I the name of your integer column. But let's see if we can get it without iteration..
 
This years hottest Dubstep single: "RTRTRCPT" By MC Thrapp
 
I imagine it sounding like an angrier Bill the Cat.
 
I'm thinking Nyan Cat but every 7 seconds you drop the bass.
 
Hmmm, I do still have a "legal" copy of Ableton on my computer at home.
 
added bonus...have Kevin write up crazy animations that go with the sound. Then Ffisegydd can market the epilepsy. Profit.
 
8:51 PM
On second thoughts actually I'm imagining Nyan Cat mixed with the "BOOOOOOOOMMMMMMBBBBB" sounds from Inception.
 
DSM
@BradRice: unfortunately it doesn't look like I can find an easy way to do it using the .str vectorized accessors, which don't seem to support vector inputs. :-/
(Of course past experience proves that just because I can't think of a way doesn't mean there isn't an obvious one.)
 
@DSM Thank you for the help! If I may, what are the downsides to using the non-vectorized way you posted above?
 
Just spent 20 minutes walking "Fred" through changing his password
shoot me now.
 
DSM
@BradRice: performance is the only one which comes to mind.
 
I see. Well, for the time being, that gets me running again. I'll poke around for an optimized solution later. Thanks again!
 
DSM
8:54 PM
Cheers.
 
stackoverflow.com/q/33508450/3001761 (dupe of the question the "answer" copies comments out of)
 
DSM
"this is a joke"? (from here)
 
flagged and vtc
(v'dtc? vtc'd? What's the right past-tense of that acronym?)
 
Is there a command-line flag to make Python check a script for syntax errors, but not actually run it?
If so, this guy could turn it into a service.
 
IDLE has something like that, not sure if there's a CLI option
 
DSM
9:03 PM
Almost 400k of combined rep wound up interacting with that question (not counting people who looked at it but didn't do anything I could see.)
 
@Kevin found a dupe
 
I think this was @PatrickMaupin's advice the other day, but wrapping your entire code in a if false: works for that
 
Oh, nice.
 
I'd hammer, but I'm out of ammo :o(
Do hammers have ammo? Probably.
 
9:05 PM
already closed as off-topic - tool/library w/e
 
@DSM that's probably an important measure of time wasting...
 
Hammo! Ammo for your hammer
 
@MorganThrapp nailed it (also a pun)
 
Damn, I was hoping for a supermarket-brand canned ham.
 
Not quite a perfect dupe, since he wanted a web site. Just as well that it was closed as a rec req.
 
9:06 PM
@DSM Martijn has that just when he alone answers a question :P
 
@AdamSmith Canned ham scares me.
 
it jiggles
meat shouldn't jiggle
 
Hammo! Ham for people who aren't afraid of the unknown!
 
Hamsterio
 
I don't eat food if it goes "shlorp" as it slides out of its container.
Except cranberry sauce, but that's a holiday exception.
 
9:10 PM
I ate spam once. It tastes like salt and meat water.
 
why do you know what meat water tastes like Morgan.....why
 
I don't want to talk about it... 2012 was a dark year.
 
@Kevin But...refried beans...
 
wringing the liquid out of his steaks just to LIVE.
 
Well, if you know what meat tastes like, and know what water tastes like...
 
9:11 PM
@Ffisegydd That doesn't really shlorp though.
 
I wouldn't eat spam straight, but it's pretty regular in asian food.
 
shlorp usually only occurs if the food retains the shape of the can after it is no longer in the can.
 
Refried beans do that.
 
Gotta get that near-airtight seal as it comes out.
 
@Ffisegydd Not any that I've had.
 
9:12 PM
Well...pigh gergbjqergbqergijidf[jgbnejfbnej...
 
Googling image... I think I've only had refried beans at restaurants, where I don't need to see the uncanny uncanning.
 
Can confirm on the refried beans.
 
Concentrated juice is another one.
 
BAM! You just got Reddit'd son.
 
9:13 PM
@Ffisegydd Huh. I've never had that happen and it's not like I'm buying fancy ones.
 
Yay, for refried beans. Yum.
 
> You can't use examples of things from the documentation as examples of things that aren't in the documentation... – jonrsharpe 34 mins ago
 
Maybe it depends on the climate. Ffisegydd lives in an extra solid zone.
 
I missed this one, earlier.
 
It is true that liquids are banned in the EU.
I tire of chewing on ice for water ;___;
 
9:14 PM
That's why the red cross asks for blood plasma. Because blood liquid isn't allowed.
 
Then how are the Irish part of the EU?
 
They donate blood alcohol.
 
Through The Irish Liquid Exemption Law of 1997. Do they teach you nothing in the US apart from how to sing the pledge of whatever and shoot people stuff?
 
@Ffisegydd And how to remove our refried beans from a can properly.
 
Right. With a firecracker.
 
9:16 PM
With a .45
 
The only sensible way is with a --- right, Fizzy's got it.
 
I find that incendiary devices add a certain mesquite taste that you don't find with ballistic opening techniques.
 
Taste the meat, not the heat
 
You've got to let the tannin settle after blowing your bottle of wine up though, or it's just not good.
 
This is America. I have the freedom to taste either.
 
9:18 PM
No, this is Patrick.
 
Hello? Yes, this is dog.
 
Is mayonnaise an instrument?
 
(This is all a very cabbage conversation)
 
It feels like a Friday conversation, but it's only Tuesday.
 
Are we due a room meeting at some point?
 
9:21 PM
Back to my earlier thoughts on the subject - you can't rely on the underscore prefix for your API unless you alias imports you don't want to export to underscore prefixes... so to create an API with Python, either alias your imports to prefix underscores for convention importing -- or use an __all__
 
Did we do anything after the last one? If we didn't, and something needs to be done, I call shotgun-not-me.
 
Last transcript was apparently from 2015-08-19 15:00, so if it's quarterly, we have until December.
Or, wait. How many months in a year.
 
are room meetings for room-owners only?
 
Carry the one... We have until mid-to-late November.
 
I don't know (or care at this hour) what you're trying to do, but it sounds like you're trying to force Python to do something it's not supposed/designed to do. We're all consenting adults - if people want to go into your API past underscores then they will find a way. Life...finds a way... (if you're not doing what I think you're doing, then ignore this entire message).
 
9:23 PM
Didn't we have a room meeting FAQ at some point? No, room meetings are for anyone that wants to attend.
 
DSM
That code does not make me happy.
 
@Kevin "As such we like to hold these open-house meetings" found in one of the general meeting links
 
@DSM It looks like valid RPS code, right?
 
Hmm, what country has a "U" movie rating?
 
9:25 PM
honestly the comments are what make me unhappy. So many people telling him to post to codereview
 
@Kevin UK does.
 
DSM
U for UK!
 
Closed and cbg!
 
It stands for Universal IIRC and it's basically...well...universal?
 
cbg @TigerhawkT3
 
9:26 PM
Like, kids movies. Literally anyone is allowed to watch them.
 
Approximately like "G" movies in the US, then.
Although the last movie I watched that was G - March of the Penguins - was surprisingly harsh.
Don't make me watch that penguin die, Morgan Freeman. Why would you do this ;_;
 
U, PG, 12A, 15, 18, R18 IIRC.
 
DSM
Urf. OP is a little confused about something, but it's likely he's simplifying the problem too much as well.. move along.
 
@Kevin do you need doesthedogdie.com ?
 
Nah. Ain't no dogs in Antarctica.
 
I clicked...I clicked thinking it would work.
 
Watership Down only has 5? I've never seen it but I expected far more.
That count doesn't seem accurate, since the textual description names 6 methods.
 
@idjaw I bamboozled you!
@Kevin The count is not how many pets died, it's how many viewers have said "Yes pets die."
 
9:30 PM
Got it.
 
Bad UX.
 
well played Adam...well played.
 
@idjaw I posted it without checking if it was a real thing. Then clicked the link hoping it wasn't some sort of NSFW badness that I shouldn't have linked to
 
It's okay, if you link to something and didn't realise it's NSFW then we'll forgive you. Are you guys coming to my party btw? It's lemon themed.
 
Who in the room is the fan of really bad horror/thriller movies?
 
9:34 PM
Me.
 
I have a good one for you that was just ridiculous
 
I enjoy them too.
 
I shall endeavour to find it.
 
Oh man, I've been meaning to watch that. It's the only Kevin Smith movie I haven't seen.
 
9:35 PM
you guys are in for something. I'm convinced drugs were involved in making this.
 
@MorganThrapp I like Kevin Smith, but I'm not sure that's something to be proud of.
 
@idjaw Well, yeah. It's a Kevin Smith movie.
 
sadly no jay or silent bob cameo at all...even though that would have been amazing
 
@AdamSmith I dunno, other than Jersey Girl, I think his filmography is pretty good.
 
mallrats was pretty solid...and clerks
 
9:36 PM
I love Chasing Amy.
 
funny story about Clerks:
I worked for a couple years as a convenience store clerk
my co-worker one evening was a young girl (18? 19 mayyyyybe?) who was overly excited about her first job
 
Clerks 2 was pretty bad, too.
 
giddily she tells me "OMG this is like SO fun. They should, like, make a MOVIE about the kind of hilarious stuff that goes on around here?"
Jaded, I smirk. "Nice. Clerks."
She has no idea what I'm talking about.
Nice girl, but she was about as sharp as a sack of wet mice.
 
I haven't heard that expression before
 
DSM
I'm not sure that expression existed before.
 
DSM
A million monkeys, etc.
 
New pickup line: "you are the monkey to my typewriter"
 
That's Shakespearean.
 
"My heart is the typewriter / upon which will you write a / thousand sonnets you fat ape"
 
that ended in an unexpected way. Applause.
Japan is opening an all you can eat KFC....wtf.
 
Air
9:54 PM
@AdamSmith I like the second answer here
 
haha
 
You're not fighting a battle worth winning.
 
I do these things not because they are easy, but because it's there.
 
9:58 PM
Well, someone is wrong on the Internet, and I do have to fix it.
 
Air
I love that I'm 12 hours into the major update that we told our reporting agencies 4 weeks ago would happen within 3 weeks and I'm just now getting an email from an engineer at one of said agencies like "okay here's what we want"
Spoiler alert: How's it feel to want?
 
That's okay, have you seen the state of affairs for Chip and PIN card processing since the Oct 1st "deadline?"
 
That's nothing! I get content for any given month's newsletter after that month has already started, and then I'm immediately asked why it's not ready yet.
 
If I want to call an attribute using a variable, and I know with certainty that the attribute exists, is there a faster to do it (in terms of processing speed) than using getattr?
 
Air
@AdamSmith I hadn't heard of that deadline but I assume vendors were supposed to switch over to chips? All vendors? Large vendors only? I've used the chip at... uh... Target and one other place, I think
 
10:03 PM
How about accessing it normally, with dot notation? object.var
 
Air
As long as we're complaining, I too have to deal with 8-character object names in a system that was designed in the early '90s :(
 
Wow, I think I'm gonna have to start asking questions on another account, so my rep doesn't goo down — DeliriousMistakes 1 min ago
Nooooo. No no no no no.
 
And are you optimizing for speed because you tested the application, found that it was too slow, profiled your code, and found that getattr() calls were the culprit?
 
@MorganThrapp Hue.
@TigerhawkT3 No, I'm just curious and have a microoptimization addiction.
 
Air
@Augusta suddenly Twitch chat
Is that what Mordekaiser looks like as a 16x16 icon? squints
 
10:06 PM
@Air I haven't been on Twitch in weeks. Are you maybe thinking of a different Augusta? :y
 
How to set python path using a batch file in windows
 
And no, nobody so famous. XD
 
Air
I've just never seen anyone use "hue" outside of Twitch
 
@TigerhawkT3 The problem with that is that the name of the attribute isn't var, it's a string defined by var.
 
Air
It strikes me as a decidedly "Twitch viewers like to make fun of Brazillian mannerisms" thing
 
10:07 PM
"Hue" is the Portuguese spelling for "heh."
 
So the value I need would be returned by getattr(MyObject, var)
 
I'm absolutely making fun of Portuguese mannerisms. I just didn't know it was unique to Twitch. XD
 
Well, create a function with getattr(MyObject, var), create another function with MyObject.var, and then use timeit.
 
I do remember "jajajaja" and "wwww" from RO, although "wwww" is more common and I think "jajajaja" is actually Spanish.
 
10:09 PM
Yes, "ja" is Spanish.
 
Won't MyObject.var just look for an attribute named "var" in MyObject, rather than an attribute with a name defined by var?
 
Air
Ja, das ist "ja" Deutsch (I suspect Google Translate has failed this one)
 
anyone familiar with spark or storm?
 
Rather, if var = 'tgtattr' and MyObject.tgtattr = 'Found it!'; MyObject.var = 'wrong number.', MyObject.var would return 'wrong number.'. Which is not the value I'm looking for.
"Ja" is Deutsch for 'yes', and a laughter sound in Spanish. It's probably other things, too.
 
wwwww is the Japanese version of that
 
10:12 PM
Jawohl.
 
Well, MyObject.var and getattr(MyObject, 'var').
There's a reason why you don't see getattr() much.
 
Air
@Augusta And then there's Jaaaaaaaaaaaaaaaaaaaaaah!
 
I mean, there are people who would probably say it's stupid to be using namespaces this way in the first place, and I wouldn't disagree with them.
 
as for avoiding getattr, could just use a dict instead but without knowing the actual intent I can't really say much
 
Air, you win the day.
 
10:16 PM
My application for all this is that I have a pygame.Rect and, for various reasons, I specify a corner with a string in a config file. So s_getCorner could be "midbottom" or "topleft" or "bottomright" or something like that.
 
@Air Everybody in the U.S. was mandated to switch over to EMV (Chip and Pin) authorizations on Oct 1st. As far as I know, only a handful of processors are even approved to handle those transactions a month later.
 
...which corresponds to a natural attribute property in the Rect class.
 
But yes, Target, Wal*Mart, and other huge national chains are accepting it
and that's about it
 
DSM
@Augusta: do you mean "property" in the Python sense?
 
Our software vendor promised to have a release that would handle EMV by Q4 2015
Insider information puts that date more like Q2 2016
 
10:18 PM
So if I have a Rect myRect = pygame.Rect(22,33,44,56), and I want the center, I could send s_getCorner = 'center'; t_foundCorner = getattr(myRect, s_getCorner) and get 44,61 back.
@DSM Yes, sorry. I'm assuming that it's probably a property of pygame.Rect, since it updates (?) as the Rect's location and size change.
 
DSM
:-/ That probably rules out dictionary-based approaches (which are usually a little faster than going via getattr), unfort.
 
Yeah. -_-
 
In the meantime, software vendor denies all liability if we're sued for non-compliance
 
So, myRect.center wouldn't work?
 
It would, but I'm looking for a point that I define on the fly.
So I can send anything for s_getCorner and get a value back (as long as I specify a legitimate property in a Rect).
 
DSM
10:21 PM
Only thing I can think of if seeing if manually branching is faster than the getattr, and odds are 70/30 against.
 
eval("myRect.{}".format(loc_from_config_file)) # guaranteed to be safe
 
Honestly, considering that getattr is not particularly slow and it only really comes up once, this is kind of a fool's errand. I'm really just interested in learning more about the nuts and bolts of this stuff.
 
DSM
@AdamSmith: I'll bet two hundred quatloos anything via eval is an order of magnitude slower, probably two. :-)
 
If I'm going to do a sketchy thing, I may as well do the most efficient, most elegant sketchy thing.
 
Four hundred quatloos!
 
10:23 PM
My god! That's sixteen hundred monoloos!!
(Or one thousand, six hundred uniloos for you Americans.)
 
DSM
Bloody Yankees and their strange units.
 
C:\Users\adsmith>py -3 -m timeit 'eval("list.{}".format("sort"))'
100000000 loops, best of 3: 0.0122 usec per loop
C:\Users\adsmith>py -3 -m timeit 'getattr(list,"sort")'
100000000 loops, best of 3: 0.0124 usec per loop
 
How about 'list.sort'?
 
C:\Users\adsmith>py -3 -m timeit 'list.sort'
100000000 loops, best of 3: 0.0124 usec per loop
so either I'm doing something stupid, or it doesn't matter.
 
Wait, so getattr is actually just as fast as calling the attribute dir--
right
I remember my original problem now
 
10:27 PM
loooooooooooooool
 
getattr is only substantially slower if the attribute doesn't exist.
HA HA NEVER MIND ME I AM ON DRUGS. =_=
 
Yes, exceptions are slow.
 
@DSM I want my 16,000 deciloos
 
If you find any more of my wild geese, they're yours to keep.
16,000 deciloos is the same as 16 deciLoos, right?
Or is it 16 hectoLoos?
deci:hecto::loo:kiloloo::loo:Loo
-- Which makes it so much easier to remember. --
 
@AdamSmith Weird, I get the same result as you from -m timeit but trying it from inside the interpreter eval is vastly slower
like 100x slower
>>> from timeit import timeit
>>> timeit('getattr(list,"sort")')
0.14120306972382074
>>> timeit('eval("list.{}".format("sort"))')
15.66133726245846
>>> timeit('list.sort')
0.056331366332670996
 
10:39 PM
I've never tried the eval method. I remember getattr being slightly slower, but I'm not sure if it was a third the speed as calling it directly.
I did a bunch of experiments when I was starting out with Python, but I didn't start actually recording the results until later. =_=
 
it's also possible that all of these lookups perform differently on native python classes than on the stdlib C builtins
i.e. timing on list.sort may not be representative
 
true
 
11:41 PM
C:\Users\adsmith>python -m timeit eval('list.{}'.format('sort'))
100000 loops, best of 3: 10.2 usec per loop

C:\Users\adsmith>python -m timeit getattr(list,'sort')
10000000 loops, best of 3: 0.154 usec per loop
I think it's just windows shell quoting weirdness
@tzaman
 
aha
 
C:\Users\adsmith>python -m timeit list.sort
10000000 loops, best of 3: 0.061 usec per loop
 
yeah that reflects the in-interpreter timings much much better
so you need to give DSM back his loos
 
Noooooooo
 
00:00 - 19:0019:00 - 00:00

« first day (1844 days earlier)      last day (3089 days later) »