Archive for December, 2006

FTP Ignorance

Wednesday, December 13th, 2006

I spent over an hour trying to run the sample code below. This comes from the sample code from ftputil (The best FTP library for Python by the way.)

# download some files from the login directory
import ftputil
host = ftputil.FTPHost('ftp://ftp.kernel.org/')
names = host.listdir(host.curdir)
for name in names:
    if host.path.isfile(name):
        host.download(name, name, 'b')        # remote, local, binary mode

And I just kept getting this error!

raise FTPOSError(ftp_error)
FTPOSError: (11001, 'getaddrinfo failed')
Debugging info: ftputil 2.1.1, Python 2.4.2 (win32)

Anyway the simple mistake ended up being that I needed to use ftp.kernel.org/ and not ftp://ftp.kernel.org/. So that’s the answer if you’re ever stuck, omit the ftp:// prefix.

How to Remove Hyperlinks in Open Office

Tuesday, December 12th, 2006

Click image for an animated gif showing how to do this.
Removing hyperlinks in Open Office

Found answer here.

Using Dirac Bra-ket Notation in Open Office

Tuesday, December 12th, 2006

If you want to use Dirac’s Bra-ket notation in Open Office’s formula editor, just cheat and insert a line and angle bracket as needed since Open Office doesn’t have any official support for it.

Thus
left langle bra mline right none
gives you <bra|
and
left none mline ket right rangle
gives you |ket>

This google group post had the answer.

By the way, to get to the formula editor in open office go to the insert menu, then select the object submenu, then select formula.

HTML Tags – Does acronym or abbr Show Longer Title?

Wednesday, December 6th, 2006

I’m curious how the acronym and abbr tags compare in how much text of the title they show when one hovers the mouse over them. So I figured I’d post them here and find out.

When you hove your mouse over the elements below the title should say:
It’s not often that I get to write a post and answer a question by writing said post. How unusual this event is.

Acronym Tag
TTT

Abbr Tag
TTT

and just for comparison let’s try the a tag:
A Tag
TTT

Well my result in Firefox 1.5.0.8 is that all three show the same amount of text:
It’s not often that I get to write a post and answer a question by writing said post. Ho..

What results do you I.E. users get on mousing over these?

I was just interested in finding a quick way to make a “tooltips” equivalent appear on a webpage. I guess if I want longer text I’d have to make some kind of javascript box show up on the mouse-over event or whatever …

[tags]acronym, abbr, acrynom, anchor, title, tooltip, mouseover[/tags]

Python – How to Lock a File in Windows

Friday, December 1st, 2006

If you have a situation where multiple programs could be writing to the same file at the same time, file locking it is a simple way to keep things safe and coordinated. I’ve found the portalocker code/module to be the best way to achieve this in Windows. Below is some sample code for using this module, but be sure to notice the trick in line 5, or you’ll be moderately confused for three months and think the code is working when it’s not (more on that after the sample.).

Sample Usage:

import portalocker
#access the file you want to lock
token=file('token.txt','r+') #use r+ for some reason ...
#Lock the file
portalocker.lock(token,portalocker.LOCK_EX|portalocker.LOCK_NB)
#Brag about it, or perhaps use the file ...
print 'I have this file! No one can use it!'
time.sleep(10)
#Relinquish
token.close()
print 'Ok, you can use it now'

Notice that weird looking “portalocker.LOCK_EX|portalocker.LOCK_NB” on line 5? That’s what made it work for me. I don’t know how or why but finally got this idea from a google code search on portalocker.

If anyone knows why “portalocker.LOCK_EX|portalocker.LOCK_NB” works while only “LOCK_EX” works but just makes other programs hang at opening token.txt, and “LOCK_NB” and “LOCK_SH” don’t work at all, then you’ll get a $5 dollar gift card for Answer My Searches (assuming I ever sold merchandise on this site which I can’t fathom, oh and it expires in 6 months! .. but I’d still appreciate the answer :-)

Update:
Jody, from Gaithersburg, Maryland writes in that LOCK_EX is for blocking access and LOCK_EX|portalocker.LOCK_NB is for not blocking which I suppose means causing another program to raise an error when accessing a locked file as shown in this link. Enjoy the gift card, Jody!

[tags]portalocker, lock files, lock, flock, LOCK_NB, LOCK_SH, LOCK_EX[/tags]