Probably simple syntax error

Delaney, Timothy (Tim) tdelaney at avaya.com
Mon Jul 2 01:04:02 EDT 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
weighted.
> 	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:
http://docs.python.org/tut/tut.html

especially the sections on lists:
http://docs.python.org/tut/node5.html#SECTION005140000000000000000

and functions:
http://docs.python.org/tut/node6.html#SECTION006600000000000000000

Cheers,

Tim Delaney



More information about the Python-list mailing list