error processing variables

U

Unknown

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()

---------------
 
I

infidel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top