Skip to main content
Question

How to access an array from python startup script in the rest of the workbench


what i'm trying to do is take an array of strings from a python startup script and access it from the rest of the workbench (specifically an sql executor and emailer). what i have so far is made a global variable like so:

global users_to_fix
users_to_fix = []

then i append strings into that array.

and here are my tranformers:

0684Q00000ArDpuQAF.png

here is the PythonCaller:

0684Q00000ArDpzQAF.png

i have gotten this solution from https://knowledge.safe.com/questions/58082/passing-parameters-from-a-python-script-tool-to-a.html

i am getting the following error:

Python Exception <TypeError>: Failure to convert list unicode values to native UTF-8 values.
Error encountered while calling function `getUsersToFix'
f_8(PythonFactory)PythonFactory failed to process feature

i'm thinking there must be a better way to do this. because i'm not actually dealing with features, i'm dealing with a list of usernames of our AGOL database.

5 replies

geosander
Forum|alt.badge.img+7
  • May 17, 2018

Hi,

You can't set a list attribute like that.

Have a look at this example.

Sander


  • Author
  • May 17, 2018
geosander wrote:

Hi,

You can't set a list attribute like that.

Have a look at this example.

Sander

thank you. i tried that solution and now i'm getting "Python Exception : Could not convert attribute value to a supported attribute type."

 

 


geosander
Forum|alt.badge.img+7
  • May 17, 2018
geosander wrote:

Hi,

You can't set a list attribute like that.

Have a look at this example.

Sander

Hmm, seems that there's an item in your users_to_fix list that has an unsupported type. Are you sure that they are all strings? If yes, it might be a character encoding issue. Are you using Python 2.7 or 3.x?

 

Also read this.

 

 

Some other things: the "Attributes to expose" field of the PythonCaller should be set to "users_to_fix{}". But that's not the issue here.

 


geosander
Forum|alt.badge.img+7
  • May 17, 2018
geosander wrote:

Hi, 

You can't set a list attribute like that. 

Have a look at this example

Sander 

And just to make sure you've got the code 100% right:

 

def getUsersToFix(feature):
	global users_to_fix
	num_items = len(users_to_fix)
	for i in range(num_items):
		name = "users_to_fix{{{}}}".format(i)
		value = users_to_fix[i] 
		feature.setAttribute(name, value)
Optionally, you can add...

 

		print type(value)
... just before the feature.setAttribute() line. This will print all the type names somewhere in your log (usually all the way at the end of the translation). Check if they're all unicode or str (assuming you're using Python 2.7).

  • Author
  • May 17, 2018
geosander wrote:
Hmm, seems that there's an item in your users_to_fix list that has an unsupported type. Are you sure that they are all strings? If yes, it might be a character encoding issue. Are you using Python 2.7 or 3.x?

 

Also read this.

 

 

Some other things: the "Attributes to expose" field of the PythonCaller should be set to "users_to_fix{}". But that's not the issue here.

 

i fixed it! you were correct; there were some values which were not strings. thank you!

 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings