[Tutor] os.rename type error
Lewis Bergman
lbergman@abi.tconline.net
Tue, 15 Oct 2002 10:11:33 -0500
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.
Here is the offending bit of code minus the irrelevant parts:
---------------------------------------------------
conf = "/root/domains.to.scan.conf"
back = "/root/domains.to.scan.conf.old"
import string, getopt, sys, os
def main(conf = conf, back = back, domains = domains):
def read(conf = conf, back = back):
"""Read the conf file in, make a backup, blank the original."""
print conf, back
conf = open(conf, 'r')
temp = conf.readlines()
conf.close()
os.rename(conf, back)
conf = open(conf, 'w')
return conf, temp
-----------------------------------------------------------
When I call the function I get this:
Traceback (most recent call last):
File "./dom2scan.py", line 86, in ?
main()
File "./dom2scan.py", line 56, in main
add(string.lower(args[i]))
File "./dom2scan.py", line 34, in add
conf, temp = read()
File "./dom2scan.py", line 24, in read
os.rename(conf, back)
TypeError: coercing to Unicode: need string or buffer, file found
You can see that I am using strings in both the source and destination
arguemnents for os.rename. Does this mean I have to convert them to Unicode
first? I guess that would be part of the string module. The reference library
didn't say anything about that. The source and destination files are on the
same filesystem on a linux box. The destination does not exist and I am root
anyway.
Any clues would be appreciated.
--
Lewis Bergman
Texas Communications
4309 Maple St.
Abilene, TX 79602-8044
915-695-6962 ext 115