@# 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 17 18 19 20 21 22 23 24



Comments:

<0> does anybody know how I can "save" a function call in a variable?
<0> kind of like partial function application but in python 2.4 or lower, not 2.5
<1> stupid question: how do I test if a name exists?
<1> "if not a: a = 3" but that fails
<2> foo=lambda x: func(1,2,x) comes to mind
<2> Patrick`: hasattr
<0> hmm
<2> Or in the case of a global name, if "a" in globals()
<1> that's kinda fiddly
<1> no, it's a property of self
<1> we test for it existing the first time it might be used
<1> I know there's a simple way to do it
<2> if hasattr(self,"a")
<1> oh, I used exceptions
<1> bad me



<2> Catching AttributeError is another way
<3> TD: The PEP for the partial function application mentioned a reference that explained how to do it in 24. or earlier
<3> (IIRC, I'm not totally sure)
<1> DataBeaver: yeah, s'what I had
<2> I usually try to avoid generating exceptions, except in the case of real errors
<4> Awk looks even more scary
<4> and I want to kill sf
<1> if not hasattr(self, verbosity)
<1> gah, that gives an error
<1> NameError
<3> TD: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549
<3> patric: 'verbosity'
<4> argh
<1> hurrah
<5> yuriks: want to kill sf.net, go with your project for free trac hosting http://www.python-hosting.com/freetrac
<1> wait, quotes? WHY
<4> I hate this, every time I find something cool to do everything goes wrong,
<4> del murphy
<5> Patrick`: hasattr(self, 'verbosity')
<5> Patrick`: quotes because you're asking for a name
<2> Because hasattr wants the name as a string
<3> patrick: because Python doesn't have Lisp symbols yet =) (Or more to the point, without the quotes you'd be asking for a value of the variable, of course :-)
<5> Patrick`: but usually I see extensive usage of hasattr/getattr/setattr as a sign of weakness... ah, bad design :D
<4> __doc__: eh, ok, if I get free hosting does the pyparsin file magically appear on it? >_>
<5> yuriks: eh? :D
<4> GAAAAAAAAA!
<4> IT UP AGAIN!!!!!111ONE
<6> have you considered dropping caffeine yuriks?
<4> meh, I don't drink caffeine =P
<7> you eat it?
<8> must mainline amphetamines
<9> What's the easiest way to take a float and compute the smallest numerator and denominator representing the fraction?
<4> I don't ingest cafeine xD
<6> must be doing speed or something
<4> lol
<6> either way you need to calm down
<3> ceri: it might be harder than you think, since floats aren't really that exact
<4> im nervous cause of these parsing probs
<10> maybe you could take the whole number as the numerator, and the denominator as a power of ten, and factor both, and take out the common factor
<10> s
<8> Ceri1: maybe math.ldexp
<11> frexp
<8> apologies, indeed
<11> hmm, you still have a float
<10> or maybe take the mantissa as the numerator and the denominator is a power of two.. or something along those lines=p
<9> HappyFool/deltab: How would frexp help me get the numerator and denominator?
<11> not suret
<8> Ceri1: hrm. sorry, just a suggestion
<10> actually you probably want to check for repeating decimals
<8> Ceri1: i thought it would let you easily get a form 'x / 2^n', but it looks like not
<2> Converting a float to a rational is rather non-trivial in most cases
<3> ttp://wiki.tcl.tk/752
<2> There's an algorithm for the case where the fraction part is cyclic, but I'm not sure how easy/efficient it's to implement that in a computer program
<3> There's something I found with google ^
<8> it can't be *that* hard -- not referring arbitrary decimals, but IEEE 754 (or whatever) floats
<12> So, I have a string, and I want to call a function with this name. How do I get this function object? Like, I have the string 'print', so I want to call the function print.
<2> Another way is to multiply the fraction by 2^n where n is the number of bits in the mantissa, then find the GCD of those two
<13> Ceri1: Farey numbers: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317
<14> why the hell does activestate no SSL
<8> hrm, there's no math.log2
<2> johnsu01: ***uming we're talking about the global scope, globals()[name]



<14> stupid encryption export regulations in the USA>
<4> robin_: oh yeah
<4> that's stupid
<4> very
<4> a lot
<4> I think it's the stupidiest thing I saw in 5 years
<9> Loge: Thanks, that's what I was looking for.
<12> DataBeaver: Hm, ok. I think these are probably cl*** methods.
<2> In that case getattr(obj,methodname)
<12> DataBeaver: Ok, right. I also have a similar case where I need to do this with keyword arguments.
<12> s/need/want
<2> What do you mean?
<2> getattr gives you a function, you can call it normally.
<12> DataBeaver: so, a function can take arguments like this_one='foo', that_one='bar'. If the argument were a string, I would want to do %s_one='foo' % x.
<12> In other words, I want the name of the keyword argument to be based on the value of a variable.
<2> Put the arguments in a dict and then func(**kwds)
<12> well, yeah, but that's a lot of typing for what is a predictable pattern.
<2> func(**{"%s_one"%x:"foo"})
<12> ah, gotcha.
<12> I think something like that will work.
<15> hi all, are there any packages that can let me sample a (parameterized) poisson distribution?
<12> DataBeaver: Thanks, I'll chew on that for a while.
<15> or any other common distribution
<2> johnsu01: You're welcome
<16> hello, How do I find the path to the python library in a platform independent way?
<16> from a python script
<16> is there a function that returns that path?
<13> nir_ai: look at sys.path
<17> python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
<16> Loge, It will not be there since I am running in an embedded environment that does not even have python installed
<16> Loge, on second thought ignore my reply, its not logical
<16> ignacio, on my system this returns the folder of the site-packages. Is this the expected result?
<13> reikon: if you are still there, just spotted sys.setrecursionlimit() which may workaround your stack overflow probs
<18> If you're recursing more than 50 deep, you're probably choosing the wrong algorithm.
<19> was mpilgrim a guy here?
<8> zeeeeee: i was going to recommend scipy (i see a scipy.stats.poisson), but I can't figure out how to use it. I'm using a slightly dated SVN version and it seems to be broken
<19> what does __doc__ do?
<20> it's very cool the new style of python.org
<8> defcon8: 'def foo(): "docstring here"' -- now foo.__doc__ == 'docstring here'
<19> right
<19> is it like javadoc?
<21> A raw-quoteed string is r'string' right?
<8> i'm don't know what javadoc is. i'm not sure of the precise rules, but i think the first string in a file, cl*** or function is the docstring of that module/cl***/function
<21> I don't need escape characters in a raw-string, right?
<22> if I use pdb.set_trace() inside an except clause of a try block, I can't access the error information with sys.exc_info() (I always get AttributeError no matter the original error). Is there a way to get at this?
<23> ho, i cant use print in map()
<23> :\
<22> HazyNRG: difference between expressions and statements
<22> I think those are the right terms :-/
<10> what about stdout.write or something
<24> Don't you have to quote docs with """ ... """? Or is that just convention?
<8> CSWookie: convention. """ is for multi-line strings, and most docstrings are multiline
<23> yep, i'll use sys.stdout
<21> Please, somone tell me what's wrong with this: http://deadbeefbabe.org/paste/3110
<25> __doc__: ping :)
<21> I've looked at it for fifteen solid minutes, and I still don't see it.
<25> Draconic: use raw strings :)
<21> Tried.
<21> Still didn't work.
<25> Draconic: http://deadbeefbabe.org/paste/3110
<25> Draconic: and use subprocess
<21> The documentation I'm seeing doesn't tell me HOW to use it.
<21> All it says is that it replaces things.
<8> Draconic: afaik raw strings can't end in a \
<21> Yeah, I had to use an escape character to escape the escape character.
<21> Bleh. Whatever.
<21> This should work now.
<26> how do initialize a variable to nothing?
<10> None
<17> ***ign None, rather.
<26> ok, thanks
<26> how does a derived cl*** the parent cl***'s constructor?
<26> *call
<22> if I'm in an except block inside another except block, is there anyway to restore the output of sys.exc_info() back to what it was in the outer except block?


Name:

Comments:

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






Return to #python
or
Go to some related logs:

#openzaurus
ERROR: You need the openssl PHP extension to use SMTP/IMAP TLS!
#math
AL5410 linux
passwd: Critical error - immediate abort
module vfat not found ubuntu
LaunchTuner
source kode php delete checkbox all
xterm does not maximize fluxbox
ubuntu.ong



Home  |  disclaimer  |  contact  |  submit quotes