Square wave harmonics calculator

To create a Square wave wavetable in Pure Data it is possible to use the sinesum command associated to an array. The arguments to provide to this command are: the desired size of the table (a power of two number) and a list of number that define the amplitude of the various harmonics.
To create a square wave we need to use only odd harmonics and their amplitude has to be inversely proportional to the order of the harmonic.

a_k= \frac{1}{k}\text{ if } k \text{ is odd}

a_k=0\text{ if } k \text{ is even}

The following python code create a text file containing the sequence of the harmonics amplitude up to a given order (defined with the MaxOrder variable). Use python to run the script, then open the new text file that has been created, copy the list of number and paste them as argument of the sinesum command in Pure Data.

    #The maximum number of harmonics to be computed in the table
    for i in range(1,MaxOrder+1):
           if i%2==0:
                out_file.write(str(0)+" ")
                #For square wave all the even harmonics are equal to 0
                out_file.write(str(x)+" ")
                #For square wave we use only odd harmonics!

Contact me for help, comments and suggestions.