@# 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



Comments:

<0> can't you still do 'foo=cl***method(foo)' after you've defined foo? or did cl***method change in 2.4 too ?
<1> noahslater, right below the method definition, write: cl***method(mymethod)
<2> self.__cl***__ will give you a reference to the cl*** of the reference in self.
<1> or maybe the way HappyFool wrote it o_O
<3> Traceback (most recent call last):
<3> File "<stdin>", line 1, in ?
<3> TypeError: unbound method add() must be called with Foo instance as first argument (got nothing instead)
<1> Ah, it is exactly as HappyFool wrote it.
<1> MyCl***().mymethod() instead of MyCl***.mymethod(), perhaps?
<3> Whats the diff there?
<2> The cl*** method still has to be called from an instance.
<3> Oh dear... that's what I want to avoid
<2> Then p*** it the cl*** as the first argument.
<1> maybe you want a staticmethod or a plain module-level function.
<1> Or that :-)
<3> No, that wont work either:



<3> Traceback (most recent call last):
<3> File "<stdin>", line 1, in ?
<3> TypeError: unbound method add() must be called with Foo instance as first argument (got cl***obj instance instead)
<1> oh right
<0> noahslater: what must this function actually do?
<4> TFK: iteration stayed in build. basically this is what I have now:http://pastebin.com/585168
<4> TFK: sorry for the rather long paste ...
<0> hrm. my cl***method's work if i do kl***.clsmethod(stuff)
<3> I have a cl***obj which maintains a list of extension modules. Before anything uses the cl*** within the system I want to be able to call a method on the cl***obj that extends it's functionality before anything instansiates it. The method will alter it's private list of extensions.
<4> TFK: from the client point of view, it only needs to run yet another init func, which is a downside, but it was quikcer then starting to add another cl*** with iterators or change the exsiting code.
<4> TFK: in essance, it feels like the iterator approach
<0> noahslater: this works on my Python 2.4.2: http://rafb.net/paste/results/WyMkSZ12.html
<4> TFK: only I don't use for, and left the while .next stuff
<3> Do you see? I want to alter the cl*** definition in a controlled manner before anything gets the chance to instansiate it...
<3> Looking now..
<1> I'm way out of my league with that code, I'm afraid.
<4> TFK: nahh, I'm sure not, I'm just a newb in py/pygtk trust me :)
<3> HappyFool: Thank you so much - that works for me too
<0> noahslater: cool beans
<5> hi. how can I inspect a method and find if any decorators are set on it?
<0> elvelind: do you think it's even possible? (i'm definitely no expert ;)
<5> HappyFool, It might not be :)
<6> elvelind: you cannot, unless the decorator gives you a way to do so.
<5> Yhg1s, okay. good to know
<7> Is there a way to display colored text in Python console output under Win XP?
<8> I'm interested to know that too
<7> an advanced type of shell perhaps? a Win XP clone of Unix shells?
<9> elephantus: you can try ANSI escape sequences, but don't work on all terminals
<9> example, print "\033[32mgreen\033[0m"
<3> How do you get a function to remember variables the next time it is called?
<10> hey, im trying to save a file into ~/.mygame/save.xml (with ~/ being my home directory in bash)
<10> how do i return the current home directory in python?
<11> You get the value of the HOME environment variable.
<11> os.getenv('HOME') I believe.
<6> os.path.expanduser()
<6> noahslater: by storing them outside a function. a cl*** is what's usually used
<3> But I want to do this is a module function...
<10> hari`: thanks, that works a treat
<6> noahslater: too bad. can't be done.
<3> And it cant see the module variables
<6> it can, it just can't ***ign to them.
<3> Well, I need to do it
<10> hari`: so if this was a windows box would that be somewhere in c:\documents and settings\ ?
<3> PHP has "static"
<6> you need the 'global' declaration for that to happen.
<6> PHP isn't Python.
<3> I know... but I would like the same functionality - its v useful
<6> use a cl***. you can do 'module.method = someinstance.method' if you want a short way of calling a specific method.
<6> see, for instance, the random module; it does the same thing.
<3> no, that doesn't make any sense in my case
<11> MrRio, win32 users often don't have a HOME set. There's some stupid win32* modules to get access to things like GetUserDirectory() or something like that.
<6> how does it not make sense?
<3> Because conceptualy it is illogical to use a cl*** for this purpose...
<3> It's symanticaly messy
<11> 'semantically'
<3> Yeah, I know
<11> ;)
<6> noahslater: I guess you'll have to stick to PHP then.
<3> Yhg1s: No need to be like that is there
<6> noahslater: well, you don't like the solutions I've given you, which are the only ones you have.



<6> there really isn't really another solution :)
<3> Yhg1s: I appreciate your input, I just thought you were being a little terse
<6> I thought the same of you.
<10> hari`: I see.. ill just forget about them i reckon
<3> Yhg1s: Fair play... :)
<6> FWIW, toying with globals is the closest thing to static in PHP and C, and it's considered extremely bad style.
<3> Yeah, I know - that why I was avoiding it..
<3> Could I not use closures somehow towards my ends?
<6> the cl*** solution is almost always the best way, even when it doesn't seem, to you, that cl***es are semantically correct.
<12> noahslater: You could try modifying the function's func_dict
<6> you could, but not in any significant way; the easiest way would be to use a cl*** to make the closures.
<3> Wow... never even heard of the "func_dict"
<6> you can set function attributes.
<6> it's the same as using globals.
<3> Yhg1s: Haha... funny
<6> (it is, infact, using a global.)
<3> Yhg1s: :)
<10> anyone here package python apps/games for debian-like distros?
<3> Yhg1s: Are you saying that it is bad style to modify the functions func_dict?
<13> i'm using pyrex to create a python module (uses an external c header file for structure definitions). the module in question is called database and contains data about contacts and events. i'd like to split the module in database.contacts and database.events - currently i have functions that start with Contact for contacts and Event for events (database.ContactGetCount -> database.contacts.GetCount()). can i do that from my pyrex module ?
<6> noahslater: not particularly more than using globals directly, or using another global storage.
<12> noahslater: Yhg1s way is easier to understand - what you want to do is what cl***es are for
<3> Yhg1s: So, one more question - how come the variable declared before the function def is out of scope?
<12> noahslater: I just giving another solution
<12> I'm
<14> has anyone read the o'reilly twisted book? i was hoping it would have more in the way of tutorial... like, telling me what i need to know to write my own protocols/servers/clients/etc, and helping me wrap my head around the ideas of deferreds, reactors, and so forth.... but looking at the table of contents, it seems to mostly be a cookbook for how to use existing modules to do stuff like web, ssh, mail, and netnews... none of which i real
<14> ly care about
<15> hello
<15> how can I delete a slice from a string?
<16> mcmillen: try asking in #twisted.
<16> with the slice notation and a re-***ignment.
<15> sysfault I tried that but I got an error
<0> strings are immutable; you can do newstring=oldstr[:n] + oldstr[m:]
<15> HappyFool yeh thats right. So if I need to go about removing a variable chunk of text from a string (but with fixed indices) how should I do that?
<3> wchun: oh no... my client is autoignoring you - can you try to post again
<0> i don't quite understand what you want to do -- a variable chunk with fixed indices ?
<13> rabar: just like HappyFool told you in his earlier post: "newstring=oldstr[:n] + oldstr[m:]" where m > n and m - n is the part you want to leave out
<15> HappyFool forget what I just said... say I have a string test="abcTreeCatDogBatTrunkbcaTreeTeaTrunk" I just want to "delete" the data between the Trees and Trunks
<15> Eblis is that the most efficient way?
<17> hey
<17> how must modify eval for example eval(a=5) to get a=5 defined as global variable?
<0> rabar: b=test.find('Tree')+len('Tree'); c=test.find('Trunk'); test.find[:b]+test.find[c:]
<6> noahslater: unless you use nested functions and a _very_ old Python, they shouldn't be out of scope.
<6> Airwulf: you can't do that with eval; use exec instead. Do realize you are executing arbitrary Python code (in both cases), and it's not very secure.
<17> and what is secure solution?
<18> i have a simple threaded program that sends packets as quickly as it can
<18> http://rafb.net/paste/results/T7UKqp90.html
<18> why does it eat up 50% CPU?
<18> what am i doing stupidly?
<15> HappyFool, that last line... is that how it should read?
<0> rabar: i think so
<0> rabar: err
<0> rabar: maybe 'print ....'
<0> bother
<0> rabar: sorry
<0> b=test.find('Tree')+len('Tree'); c=test.find('Trunk'); print test[:b]+test[c:]
<15> Ah, okay thanks HappyFool
<17> Yhg1s: Can I access the global namespace directly? Is it a dict?
<19> Airwulf: globals()
<17> luc***: and globals()["a"]=5 is a useful way to set a global variable?
<13> globals() is read only i think
<6> nope
<0> 'global a; a=5' works quite handily ;)
<17> I thought to do something like exec("global %s; %s=%s"%(key,key,value). But Yhg1s told me it isn't secure
<0> eek
<20> there are so many python books out there. which one should I get, in order to get a good feel for all libs, and how to use python in all situations? I already know the language, but want to get more used to it in practical situations.
<20> any recommendations?
<17> hakanw: Python Cookbook is nice to learn some gimmicks
<0> Airwulf: i think the security depends on who provides key and value (e.g., is it from a cgi script?). what app are you trying to write?
<17> wxwidgets app. I read a config file with ConfigParser and will set global variables like Cfg_<section>_<otpion>=<value>
<0> and how do these options affect your program? Your functions/cl***es read them?
<17> Yes they are used in functions/cl***es
<13> why not do globals()[key] = value ?


Name:

Comments:

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






Return to #python
or
Go to some related logs:

#python
xmule permission denied
sis 760gx ubuntu
#web
point eip to nop sled
xcdroast CDR_SECURITY gentoo
#osdev
processor turian performance
#osdev
dwl g510 peek driver



Home  |  disclaimer  |  contact  |  submit quotes