By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

error processing variables

P: n/a
PROBLEM: for some reason, the variables won't work outside the function.
I tried fix it by converting the variables to str and unicode and still no
joy.
The only way it works is by typing each source and
destination file by hand on the shutil.copy2() method.
Or by specifying the functions *inside* the function itself.

Any ideas?

ERROR:
Traceback (most recent call last):
File "data/scripts/wifi.py", line 76, in main
toHPU()
File "data/scripts/wifi.py", line 32, in toHPU
s.copy2(toHPU,wlan)
File "/usr/lib/python2.4/shutil.py", line 92, in copy2
copyfile(src, dst)
File "/usr/lib/python2.4/shutil.py", line 41, in copyfile
if _samefile(src, dst):
File "/usr/lib/python2.4/shutil.py", line 31, in _samefile
return os.path.samefile(src, dst)
File "/usr/lib/python2.4/posixpath.py", line 218, in samefile
s1 = os.stat(f1)
TypeError: coercing to Unicode: need string or buffer, function found
CODE:

import shutil

#variables
s = shutil

toHPU = "/etc/sysconfig/network/toHPU.wifi"
wlan = "/etc/sysconfig/network/ifcfg-wlan-id-00:0e:38:88:ba:6d"
toAnyWifi = "/etc/sysconfig/network/toAny.wifi"
wired = "/etc/sysconfig/network/ifcfg-eth-id-00:0b:db:1b:e3:88"
def toHPU():
s.copy2(toHPU,wlan)
s.copy2(toAnyWifi,wired)

#end

#execute function
toHPU()

---------------
Sep 9 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> import shutil

#variables
s = shutil

toHPU = "/etc/sysconfig/network/toHPU.wifi"
wlan = "/etc/sysconfig/network/ifcfg-wlan-id-00:0e:38:88:ba:6d"
toAnyWifi = "/etc/sysconfig/network/toAny.wifi"
wired = "/etc/sysconfig/network/ifcfg-eth-id-00:0b:db:1b:e3:88"
def toHPU():
s.copy2(toHPU,wlan)
s.copy2(toAnyWifi,wired)

#end

#execute function
toHPU()


Your problem is that the def statement reassignes the name "toHPU" to a
function instead of a string. So when the code runs, you're passing a
function object to s.copy2.

Sep 9 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.