Just wanted to make you aware of my little recipe on the ASPN Python Cookbook
This is used in the next release of the IssueTrackerProduct for the email notifications.
Just wanted to make you aware of my little recipe on the ASPN Python Cookbook
This is used in the next release of the IssueTrackerProduct for the email notifications.
If you missed the entry about Add links to text with URLs I suggest you read that first. This script has now been improved with bug fixes thanks to David Otton and Flump Cakes.
Download: addhrefs-0.4.tgz
It does not come with a nice installer because I don't think it belongs to the generic Python library anyway. If you want to use it, copy the file addhrefs.py
to somewhere useful.
Truncated! Read the rest by clicking the link below.
"Urwid is a curses-based UI/widget library for Python. It features fluid interface resizing, multiple text layout options, simple markup for attributes, powerful scrolling list boxes and flexible edit boxes."
I've been looking for something like this for a long time. See the screenshots to get an idea of what a curses-based UI is.
Truncated! Read the rest by clicking the link below.
I had the problem today that several files in a directory started with an _
underscore character. (e.g. _red.gif
). Instead of manually renaming each file used the power of shell and python to solve it. (and some help from my collegue of course). Fortunately none of the files had an underscore in the middle of the name so I could keep the command quiet simple:
$ find -iname '_*' \
| xargs python -c \
'import sys;print "\n".join(["mv %s %s"%(x, x.replace("_","")) for x in sys.argv[1:]])'\
| sh -s
Truncated! Read the rest by clicking the link below.
My friend Jacob Lundqvist of Galdrion today showed me a nifty little method I did not know about in Python, namely the inspect
module. It allows you to find out what the name of the method was that called the method "you're in". Allow me to show an example:
import inspect
def foo():
caller_module = inspect.stack()[1][1]
caller_method = inspect.stack()[1][3]
print caller_module, caller_method
return "Something"
def bar():
foo()
if __name__=='__main__':
bar()
Truncated! Read the rest by clicking the link below.
In my latest work stuff I have a custom debugger module that prints the SQL statements used to stdout. To make the debug output more readable I whipped together this quick script that pretty prints SQL statements with hopefully correct case and indentation. It converts something ugly like this:
select * from foo order by bar;
into this:
SELECT
*
FROM
foo
ORDER BY bar;
Truncated! Read the rest by clicking the link below.
I have a degree in mathematics and computer science, but still I don't know why different programming languages evaluate Integer/Integer
differently. On any calculator if you divide one integer with another you get a decimal number (of course not if the numerator is a factor of the denominator).
Python for example returns a integer number:
>>> print 3/10
0
>>> print 3/10.0
0.3
Perl on the other hand returns a decimal number:
print 3/10; print "\n";
print 3/10.0;
...gives...
0.3
0.3
PostgreSQL is like Python:
database=# SELECT 3/10 AS quotient1, 3/10.0 As quotient2;
quotient1 | quotient2
-----------+------------------------
0 | 0.30000000000000000000
And good old MS Excel gives:
=3/10 <=> 0.3
Why is it so?
I'm envisioning a input form which asks initially for a date on a calendar. The next question is duration, or how long from that date. The input for this must be clever. So now I've put together a little script that adds numerically what someone enters in English.
The "problem" is what do you do when you add "1 month" when incrementing the month number is not enough? This program does like this: 2004-08-31
+ 1 month
= 2004-09-30
.
Please have a try of my little program and let me know what you think
I deviced a very simple benchmark through Zope as the web server. Two SQL Select statements that draws from a dummy database table which contains a table with loads of dummy entries with a timestamp field.
Conclusion is that Python's DateTime module is considerably slower than PostgreSQL's builtin date formatting function.
Truncated! Read the rest by clicking the link below.
Last week Fry-IT released CheckoutableTemplates which is a templating module add-on for Zope. It includes a module called slimmer.py
which can compress XHTML, HTML and CSS. The CSS had a flaw in it that I hadn't foreseen. This flaw arises when you use M$ Internet Explorer hacks like this for example:
#centercontent {
margin-left: 259px;
margin-right:249px;
voice-family: "\"}\"";
voice-family: inherit;
margin-left: 271px;
margin-right:251px;
}
Now that bug has been fixed, so I give you: The XHTML, HTML and CSS compressor
It's a little application of slimmer.py
so that the compressing can be tested and so that one can see the effect.