July 28th, 2004, 05:24 PM
Array definition problem
I have a problem in the function below, the problem is that the compilation gives a syntaxis error.
dat = array(dat) ########## the syntax error cames in this line.
Last edited by netytan; July 29th, 2004 at 04:02 AM.
Reason: Added Code tags
July 28th, 2004, 06:16 PM
1) please put the code in [ CODE]... [/ CODE] tags (without the spaces), so that it does not lose its indentation.
2) What is the error message? Does it just say 'syntax error' or does it give any other information?
3) have you checked the indentation is correct, and does not mix tabs and spaces? This is one of the commonest causes of syntax errors for newbies.
4) Where does 'array' come from? If you are using the array module then you need to do from array import array somewhere at the start of the program. You also need to specify the array type.
5) Are you sure it is a syntax error and not a runtime error? Your code does not make sense, since dat starts off as a list and the first time round the loop you change it to an array. The second time round the loop it will fail since you cannot initialise an array object with another array.
Dave - The Developers' Coach
July 29th, 2004, 04:08 AM
An array in Python is called a list(), so if you want to create an array from another data type i.e. a string you would do this.
You have a major indent error after your function definition. So i would think that is where the SyntaxError is coming from rather than the line you marked.
["s", "t", "r", "i", "n", "g"]
Which, if you havn't defined or imported the array() class/function elsewhere in your program, should raise a NameError.
Hope this helps,