Problems in commands.getoutput(cmd) with sox

Peter Otten __peter__ at web.de
Thu Jul 23 17:20:42 EDT 2009


bbarbero at inescporto.pt wrote:

> Hello to all!
> 
> I am a new researcher, new to Python as well, and I have a problem,
> when I try to get commands from sox in a python script. I am going
> crazy, because this code has been working before.. so I dont really
> know whats going on..
> 
> Ive already seen some solutions that match with what I have. I am
> running this:
> 
> 
> 
>          if os.path.splitext(file_au)[1] == ".au":
>            resampled_file_path = os.path.join(resampled_path, file_au)
>             cmd = "sox " + dir_file + " -r 44100 " + resampled_file_path
>             print cmd
> output = commands.getoutput(cmd)
> print output
> 
> What i do, is just to resample a song from dir_file to
> resampled_file_path. As a result of "cmd" I get:
> 
> ....
> sox /Volumes/HAL/Datasets/Audio/gtzan_genres/rock/rock.00097.au -r
> 44100
> 
/Volumes/bmorab/Audio_Projecto/Data/gtzan_genres/resampled/rock/rock.00097.au
> .....
> 
> If I run this on the command line, it will work perfectly!
> 
> But The program stops at
> 
>   File
> "/Volumes/bmorab/Audio_Projecto/Data/gtzan_genres/resamplingto44.py",
> line 35
>      output = commands.getoutput(cmd)
>      ^
> IndentationError: unexpected indent
> 
> I dont have any idea, whats going on, I am trying lot of things, but I
> can understand where is the error as it has been running perfectly
> before.
> 
> Any suggestions will be more than welcome! Thanks in advance for your
> help!

You are probably mixing tabs and spaces and have set your editor to display 
a tabsize != 8 spaces.

When you change the tabsize to 8 you will see the inconsistent indentation.

In the future you can avoid such problems by configuring your editor to 
replace one tab with four spaces. Recommended reading:

http://www.python.org/dev/peps/pep-0008/

Peter





More information about the Python-list mailing list