@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16



Comments:

<0> have a nice day
<1> and even then why is that a speed issue in any way for this code?
<1> optimizaiton without profiling is just plain stupid
<2> Yango: I'm more than happy to show you how to do what you want to achieve, provided you're okay with having it redesigned more sanely.
<1> since humans almost ALWAYS get optimizations wrong
<3> Jerub, I'm always happy to learn. But I have some weird restrictions that may not suit you
<1> what are the weird restrictions?
<3> The weird restriction is that I cannot call methods with arguments, which is the cause I need to generate methods which imply the argument in the name
<2> why can you not call methods with arguments?
<3> and that way not having to code each method by hand
<3> because it's in a templating engine which doesn't support arguments to functions
<2> what templating engine?
<3> django's
<2> internally developed?
<2> right. okay.



<1> it seems you could just use __getattr__ to make it work then
<4> so I have a list of tuples like: [(120, 2), (122, 4), (127, 3)]
<2> Yango: how are you calling a function dynamically from within the template? is the template automatically generated?
<4> those are (index, length) tuples. any recommendations on how to collapse those into the smallest set of contiguous ranges?
<3> object.func, no
<4> so the example would end up as: [(120, 6), (127, 3)]
<2> alus: a for loop
<4> yeah...
<4> nothing clever?
<4> I really want interval type set() again
<4> maybe I'll just bite the bullet and write it
<3> Jerub, could you also explain why modifying __dict__ or __cl***__ is such ****ty practice?
<3> such a
<2> Yango: because this can be quite easily done with a __getattr__
<2> viz:
<1> so why just override __getattr___ to return a callable object when the name you want is handed in?
<3> kosh that looks like a good idea...
<1> it is simple, extensible, you don't have hundreds of actual methods etc
<3> def __getatt__(self,attr): if attr in self.names.keys(): return self.method(attr)
<5> How can i check if a file exists?
<2> http://rafb.net/paste/results/G54qYK56.html
<2> then you can do, orderlookup.order_5 from inside the template.
<3> and that works for all other methods not in name?
<3> I mean will , in your example, orderlookup.foo still work if there was a foo too?
<2> yeah, to be honest, I don't remember.
<2> you'd have to look it up.
<2> and test it.
<2> you're using unit-tests, right?
<3> okay. thanks. I see why this is a better solution, but I don't see why the other is the worst possible thing ever in the universe
<2> Yango: a) eval, b) adding attributes to an object, c) instancemethod, d) all on the same line.
<1> eval an exec should pretty much never be used
<2> adding attributes to an object *dynamically*
<3> Jerub, and a solution with lambda's and setattr instead of the eval? (that eval wasn't intended to stay, in any case)
<2> Yango: just as bad.
<3> Jerub, excuse my stubbornness, but _why_?
<6> Because you can't guarantee that they'll be there at invocation time.
<1> Yango: you are also adding a huge ammount of stuff to the object for no gain?
<1> Yango: if the same problem can be solved with a simple dynamic lookup why would you etc up so much more memory to add a bunch of methods dynamically/
<1> Yango: if you had say 10000 items how much memory are those 10000 functions going to eat compared to the __getattr__ way of doing it?
<3> kosh, as I said, I totally get why the getattr is a lot better, but I still can't see the other thing as such a bad thing, even though ignacio's contribution shed a little light on that
<1> Yango: every attribute you attach to an object takes memory
<1> Yango: if you attach a bunch of items that should be calculated dynamically you have just increased your memory footprint for NOTHING
<1> Yango: you have made the problem more complex then it needs to be and more resource intensive for no gain
<1> simpler and cleaner code is also far less likely to break
<1> and to maintain later
<3> okay :)
<1> it reminds me of some sql code I have seen recently, it was about 5K loc for the query, it could be simlified to about 50 without any change in behavior
<1> however the person did a whole bunch of simple queries and did all kinds of complex joining logic manually
<3> weird, defining __getattr__ forces you to define __repr__
<7> not really, no; you'll just have to raise AttributeError in your __getattr__, for '__repr__', or return a suitable function.
<8> When simplifying context free grammars, namely removing unit productions, if a variable links back to itself in a unit production, what do I do? Like C -> Dc | bB | C
<2> parker`: that's an interesting one, that would simplfy to C -> Dc bB
<2> er
<2> C -> Dc | bB
<2> don't you mean, C -> A C | B C
<8> ? No.
<8> If I did, there wouldn't be unit productions, and I wouldn't have to simplify it :)
<8> it's context free so it's all legal
<2> parker`: what's the specific example?
<8> what do you mean? You want the entire problem?
<8> or the specific example of removing unit productions?



<8> well say you have:
<8> S -> Aa
<8> er sorry scratch that
<8> S -> Aa | B, A -> A | bb, A-> a | bc | B
<8> the final one is too long lol
<8> nevermind
<8> I'll just... play around with it I guess
<2> I don't see why A->A|bb would make sense.
<8> why wouldn't it?
<8> I mean, it doesn't make much sense, but it's legal
<8> but I kind of see your point, I guess I can just drop the C
<8> and not lose anything
<2> yeah
<8> I get it now
<8> thanks :) I thought you were questioning the original problem or something
<8> my bad
<8> cool, you happen to know anything about ambiguous grammars?
<8> I mean, can I take any normal grammar and make it ambiguous?
<8> it seems like adding a few productions for S could do it
<2> parker`: yeah.
<2> parker`: I feel like I'm the only person who didn't hate the compilers course at uni.
<8> lol man I'm not even in the compiler course yet
<8> this is theory of computing
<8> and I hate Scratch, because no matter how much he tells me not to use "lol" I think I'll just keep doing it...
<8> old habits.
<2> Scratch is my bot. just fyi and all.
<8> haha
<8> well, by "hate" I meant "love" and by "keep doing it" I meant "stop doing it".
<8> lol ;)
<2> there it goes again.
<2> learning to say, 'heh' is the road to recovery.
<8> yeah, that one was on purpose, for ironic effect
<2> anyway, yes, ambiguous grammars.
<8> so any grammar can be made ambiguous?
<8> well, any CFG
<8> and what's the point of purposely making a grammar ambiguous? does it ever help or is it always bad?
<8> my book notes that ambiguity is usually removed when necessary, but are there ever any beneficial facets of it?
<9> lol
<9> (sorry just trying)
<10> Jerub: what uni did/do you go to?
<10> I am taking compilers at uni (univeristy of northern iowa) right now
<8> jessie: any idea about my Q?
<8> ambiguity in languages
<8> or grammars rather
<11> its late and my mind is kinda slow atm
<10> not everything can be made ambiguous
<10> was that the question or do I need to read further up
<8> [02:36] <8> my book notes that ambiguity is usually removed when necessary, but are there ever any beneficial facets of it?
<11> if im in an if statement i prompt the user for something, if they give me sumthing. i want to get out of that if statement and go into another one
<11> how would i do this
<11> like... "if sys.argv[1]" then raw_input = "which files" then if they give "*" then go to another if statement to select all files
<11> i have all the code, just not how to switch out of it
<8> ? get out of an if statement?
<8> if statements usually don't hold you
<8> show some code, pastebin
<11> ok
<10> I can't think of any benefits to ambiguity...lemme google a bit and see
<12> maybe it's necessary for certain types of flexibility?
<12> well not if you take out the specific ambiguous instances i guess
<11> nvm
<11> i got it
<8> hehe alright man
<13> anyone here tried using the CGIHTTPServer module to run a web server?
<11> 2:48 AM
<14> anyone made an autopackage for a python app before?
<11> my mind is slowing down... lol
<11> ha ha ha
<10> it is nice to be able to do the same thing multiple ways, and most programming languages are ambiguous (anything useful is), but I can't think of a benefit that is as a result of the ambiguity
<8> ah
<8> I think I understand
<10> however removing ambiguity isn't trivial, so maybe a benefit is that it is easier?
<8> it's 3... I have a 9am... ugh... later guys, time to get those 5 hours
<8> hehe true
<10> night


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #python
or
Go to some related logs:

#php
openwrt dhcp lease-time
ddfire
rdfleming
gmplayer unable to find simple control pcm
ubuntu usplash rng not detected
#math
sources.list tikiwiki sarge
let i++ bash
Gnome keyboard preferences not working



Home  |  disclaimer  |  contact  |  submit quotes