Probably simple syntax error

Delaney, Timothy (Tim) tdelaney at
Mon Jul 2 07:04:02 CEST 2007

Dustin MacDonald wrote:

> [code]
> randomizing_counter = 0
> # Put the loop counter for the randomizing to zero.
> until_val = 36
> # Set the "until val" to 36. We'll compare them to make sure we're not
> at the end of our wordlist_both.
> while randomizing_counter < until_val:
> 	big_randomized_int = RandRange(0,100)
> 	# Make a random value and store it.
> 	small_randomized_int = big_randomized_int / 100
> 	# Divide that random value and store it in a different variable.
> 	small_randomized_int = Round(small_randomized_int, 2)
> 	# Round that value to 2 decimal places
> 	**weights_array(randomizing_counter) = small_randomized_int
> 	# Assign the first randomized value to our first word to be
> 	randomizing_counter = randomizing_counter + 1
> 	# Up the counter and repeat.
> [/code]
> The starred line is the one getting the error message: "SyntaxError:
> can't assign to function call"

You should always copy and paste the exception you receive (including
the stack trace). Anyway, read the exception *carefully*. It says "can't
assign to function *call*". In the line:

   weights_array(randomizing_counter) = small_randomized_int

"weights_array(randomizing_counter)" is a function call. My guess is
that you think you're trying to modify an element of "weights_array"
(your code doesn't show us what weights_array is, but I'm guessing it's
actually a list), but parentheses are not the syntax for element access
(subscripting) in Python.

You should read the python tutorial:

especially the sections on lists:

and functions:


Tim Delaney

More information about the Python-list mailing list