[Tutor] os.rename type error

Jeff Shannon jeff@ccvcorp.com
Tue, 15 Oct 2002 09:43:18 -0700


Lewis Bergman wrote:

> I know this should be readily apparent due to the fact that python tells me
> what is wrong. I just can't seem to figure out why.
> [....]
>         def read(conf = conf, back = back):
>                 """Read the conf file in, make a backup, blank the original."""
>                 print conf, back
>                 conf = open(conf, 'r')

Here's your problem.  You have a string conf, which you use to open the file... and
then store the open file in conf as well.  When you later give conf to os.rename(),
you're passing it the open file, not the string containing the filename.  Use a
different name for you open file variable, and all should be well.

Jeff Shannon
Technician/Programmer
Credit International