Unknown Syntax Error in Code So, I am following a tutorial on CGCookie, and it is using Python code to create an audio visualizer in Blender. Now, I've always been a coding geek, but I don't actually know Python. I've taken a few shots at it but overall, I don't know Python, however, I can read and understand the code because I know basic programming concepts. Now, I'm following this tutorial as closely as I can (the tutorial does not provide code to copy and paste) and I am getting a syntax error. As far as I can tell, there is no syntax error. The line of code (specified by the error message) appears perfect. This line of code is supposed to set the 3D cursor to the active object's origin. Here's the catch: if I run that exact same line of code in the console, it executes just fine.
So here's the error message I get:

File "C:\Me\Blender\Blender Projects\audio visualisation.blend\AudioVisualizer", line 17
bpy.context.scene.cursor_location = bpy.context.active_object.location
   ^
SyntaxError: invalid syntax
location: &lt;unknown location&gt;:-1


It tells me to look in the console for error message, but the console doesn't output anything.
Here's my overall code:


Thanks!

EDIT: Alright. I've tried all the examples and all the procedures that have been suggested by you guys, but it keeps feeding me errors. According to the console, one of the problems it is spitting out is in C:\Program Files\Blender Foundation\Blender\2.74\scripts\modules\bpy\ops.py. This makes me think there is a bug in the API that is causing one of the many errors.
EDIT: Here are the error messages I get for my code.
Original Code:

Error:   File "C:\Gannon\Blender\Blender Projects\audio visualisation.blend\Audi
o Visualizer", line 35
    bpy.ops.graph.sound_bake(filepath="C:\Gannon\Blender\Sounds\Music\Batty McFa
dden.mp3", low=i*step high=i*step+step

                         ^
SyntaxError: invalid syntax



gandalf3's Code and zeffii's Code are essentially the same with alternative formatting which changes the line numbers where the error occurs.

Error: Unsupported audio format

Traceback (most recent call last):
  File "C:\Gannon\Blender\Blender Projects\audio visualisation.blend\Audio Visua
lizer", line 42, in &lt;module&gt;
  File "C:\Gannon\Blender\Blender Projects\audio visualisation.blend\Audio Visua
lizer", line 35, in spiral
  File "C:\Program Files\Blender Foundation\Blender\2.74\scripts\modules\bpy\ops
.py", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Error: Unsupported audio format
You got pretty close TheMinecraftMan757, i've seen many people struggle with that tutorial over the last 3 or 4 years. I think even some of the function calls have been changed. 

as Gandalf points out:


  to scale_apply() on line 24 should be transform_apply(scale=True)


At the time the tutorial was written, the function call was scale_apply(), but it was changed to a more general apply function that can apply not just scale, but rotation and location. You would never have figured that out in a million years without a bit of googling or more familiarity with bpy. 

here's my minimized interpretation of that code.

import bpy

rows = 5
columns = 5

def spiral(X, Y):
    scn = bpy.context.scene  # an alias, lets you use scn shorthand
    x = y = 0
    dx = 0
    dy = -1
    for i in range(max(X, Y)**2):
        if (-X/2 &lt; x &lt;= X/2) and (-Y/2 &lt; y &lt;= Y/2):
            bpy.ops.mesh.primitive_cube_add(location = (x, y, 1))
            obj = bpy.context.active_object

            scn.cursor_location = obj.location
            scn.cursor_location.z -= 1
            bpy.ops.object.origin_set(type="ORIGIN_CURSOR")
            obj.scale = (0.5, 0.5, 7)

            bpy.ops.object.transform_apply(scale=True)
            bpy.ops.anim.keyframe_insert_menu(type='Scaling')

            action = obj.animation_data.action
            action.fcurves[0].lock = True
            action.fcurves[1].lock = True

            bpy.context.area.type = 'GRAPH_EDITOR'

            step = 20000 / (rows * columns)
            fp = r"C:\Gannon\Blender\Sounds\Music\Batty McFadden.mp3"
            bpy.ops.graph.sound_bake(filepath=fp, low=i*step, high=i*step+step)
            action.fcurves[2].lock = True

        if x == y or (x &lt; 0 and x == -y) or (x &gt; 0 and x == 1-y):
            dx, dy = -dy, dx
        x, y = x+dx, y+dy

spiral(rows, columns)


If you don't set the path to a valid one, then you can get errors like

RuntimeError: Error: Unsupported audio format


remarks:


On windows use r'C:\your\file\destination.mp3', the r turns the quoted string that follows it into a raw string literal, this is perfect for filepaths. 
On linux you should really know how to compose a path, but if you're new to it, it might be something like: '/homes/your_user_name/music/some_tune.mp3'
This code can take a long time to bake each graph. Even with a 5*5 grid, it will bake the entire graph 25 times. Here's a version which places a print statement just before it starts baking each iteration, you will need to have the terminal/cmd-prompt open before running the command.




a simple script to test your mp3 filepath, but it is really worth your time to read the python docs about paths

import os

# on windows, string prefix r is used to avoid the need for double backslashes
# filepath = 'C:\\Gannon\\Blender\\Sounds\\Music\\Batty McFadden.mp3'
filepath = r'C:\Gannon\Blender\Sounds\Music\Batty McFadden.mp3'

# on POSIX systems (linux, osx)
# filepath = '/home/zeffii/cookoo_22may_2011.mp3'

found = os.path.exists(filepath)
if found:
    print('yes, this file was found')
else:
    print('nope, the path does not exist')