Mostly Linux & Python syntax notes and hyperlinks.

Tuesday, March 27, 2012

Linux: moving a directory into itself

I didn't know you could do this.

OK, I had a directory with code that I was changing, and I had a bak/ directory in which I was saving current versions.

I had a some files with the string "bak" in them.  I tried to move *bak into bak and lost the entire directory.

Yeah, it was late in the day.

[fire@ice frost]$ mv _* bak
`_some.cmd' -> `bak/_some.cmd'
[fire@ice frost]$ mv say_bak.cmd bak
`say_bak.cmd' -> `bak/say_bak.cmd'
[fire@ice frost]$mv *bak bak
`bak' -> `bak/bak'
`the_world.cmd.bak' -> `bak/the_world.cmd.bak'
mv: cannot move `the_world.cmd.bak' to `bak/the_world.cmd.bak': No such file or directory

Thursday, March 15, 2012

python: ImportError: No module named slythy.toves

Why can't python see my module when it's right there?

I was copying code from one installation to another and thought I had everything.
But, the code ran on one system but not the other.

I finally found the difference: an empty (all comments) file called __init.py__

That is, if in twas/brillig.py you have "from slythy.toves import gyre"
and in twas/slythy/toves.py you define the gyre class,
you need a file called __init.py__ in the twas/slythy/ directory, or you'll get an error like:

    ImportError: No module named slythy.toves
    Python Error: Undefined Python module brillig


There are definite disadvantages to learning python piece-by-piece as you go along.  I was checking environment variables and everything before finally finding out about __init.py__