Display Function Code Body?
Hail Python pals! I played with the R (http://r-project.cran.org) last night to do some statistics and it has an interactive session too, and I found a feature that is quite useful. I found by actually typing a function name, the R gives you a code body output. > f1 = function(x){x*x} > f1 function(x){x*x} # more examples (you can try some) > sd function (x, na.rm = FALSE) { if (is.matrix(x)) apply(x, 2, sd, na.rm = na.rm) else if (is.vector(x)) sqrt(var(x, na.rm = na.rm)) else if (is.data.frame(x)) sapply(x, sd, na.rm = na.rm) else sqrt(var(as.vector(x), na.rm = na.rm)) } # While our python gives an output which is more pro but less informational. >>> def f1(x):return x*x >>> f1 What I would like to do is to write a function like disp(), when typed, it can give you the code infomation. >>> disp(f1) def f1(x): return x*x # or any shallow function code from a file >>> import calendar; disp(calendar.isleap) def isleap(year): """Return 1 for leap years, 0 for non-leap years.""" return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) # surely the compiled function code cannot be displayed >>> disp(blabla) : internal/compiled function Can someone please point out how this can be achieved nicely. I've tried some text searching approach, too dirty I must say. Oh! Thank you ... Haibao Tang -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] 20050126 find replace strings in file
OK. But please don't die throwing that string, or this post will lose its educational purpose as it was meant to be. -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] combinatorics fun
I am no longer resisting. As time goes, the nausea when I first saw Mr. Lee's smelly "technical posts" is starting to fade. The discussion group should have a high tolerance towards polymorphic people these days. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance Issues of MySQL with Python
There are no performance overhead except when you are dragging a huge chunk of information out of the database, in that case, python is converting the data to its tuple data type which adds one more processing. I found this when I didn't have the priviledge to do "mysql> SELECT * FROM TBL INTO OUTFILE;", I used python MySQLdb first, which I later found sufficiently slower enough than using >>>system("echo 'USE db; SELECT * FROM TBL;' |mysql >outfile") But this is the minor case. -- http://mail.python.org/mailman/listinfo/python-list
Re: Complementary language?
At home I almost use python exclusively, the other two languages I can be productive is C# and C++, I chose C# because I am a Windows programmer (don't throw tomato at me, I am no troll..) and I choose C++ because the algorithm was implemented in this dialect in school. -- http://mail.python.org/mailman/listinfo/python-list
Jython & IronPython Under Active Development?
This question may be a bit weird but I really want to know if these two hybrid projects are still active. -- http://mail.python.org/mailman/listinfo/python-list
A simple question string.replace
I have a two-column data file like this 1.12.3 2.211.1 4.31.1 ... Is it possible to substitue all '1.1' to some value else without using re. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
How to parse a name out of a web page?
with high accuracy... My temporary plan is to first recognized consecutive two or three initial-capitalized words, but certainly we need to do more than that? Anyone has suggestions? Thanks first. -- http://mail.python.org/mailman/listinfo/python-list