Environment: python 2.6
path="/this/is/an/example/"
cmd={'Foo': (PATH + 'sh forExample.sh'), 'blah': (PATH + 'sh secExample.sh')}
for app in cmd.keys():
print 'app name', app
it prints as expected Foo
However, when I try to access ‘sh forExample.sh’
for app in cmd.keys():
print 'app name', app
run_apps([app])
where run_apps function looks like this..
def run_apps(apps):
for a in apps:
print a
cmdlist = cmd[a][0]
print cmdlist
It does not give the expected output, but instead gives 's'. I tried varying the value in cmd[a][x], it keeps giving the value of the character which X points to.
Oh and this was the error: /bin/sh: 1: /: Permission denied
I am using Linux, distro: Ubuntu.
any idea what the error is? where I am going on?
The value of
Fooof yourcmddict is'sh forExample.sh'.So
cmd[a][0]will result in the first character of that string.Looking at this line
it seems that you want to have a
tupleas value in your dict. To create a one-value tuple, just append a,and your code should work as expected:Now the value of
cmd[a]is('sh forExample.sh',), and accesing it with[0]will yield'sh forExample.sh'.