0

I have a tcl script tclname.tcl calling a python script (helloWorld3.py ) and passing an array

tclname.tcl :

set names(1) Jane
set names(2) Tom
set names(3) Elisabeth
set names(4) Robert
set names(5) Julia
set names(6) Victoria
set output [exec /home/Python-2.7.6/./python /home/mbenabu/vtf/tests/helloWorld3.py $names]

getting error: FATAL: can't read "names": variable is array

is it possible to pass an array from tcl to python?

Thanks,

2
  • 1
    It's a Tcl list that maps to a Python array. Commented Feb 23, 2015 at 1:26
  • What input is the python program expecting? A list of words in sys.argv? Commented Feb 23, 2015 at 11:50

1 Answer 1

0

You can't get a value from an array. You can, however, get a list of keys ("names") and values by using array get:

set names(1) Jane
set names(2) Tom
set names(3) Elisabeth
set names(4) Robert
set names(5) Julia
set names(6) Victoria
array get names
# => 4 Robert 5 Julia 1 Jane 6 Victoria 2 Tom 3 Elisabeth

The order of the name-value pairs usually isn't equal to the order the values were set in.

Documentation: array

Sign up to request clarification or add additional context in comments.

7 Comments

I called the tcl procedure like: [exec /home/Python-2.7.6/./python /home/mbenabu/vtf/tests/helloWorld3.py [array get names]]
now, in my python script helloWorld3.py I'm calling a different tcl procedure with this list: tcl.eval('GetRedhatRelease {%s} array' % sys.argv[1]) but GetRedhatRelease is expecting an array not a list.
how can i overcome this issue?
@mba: I'm not sure what tcl.eval can do, but if it can run a script and not just a command, maybe you can construct the names array inside that script instead of passing the key-value list into the python script?
Yes, But i dont want to tuch the GetRedhatRelease script.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.