Don't understand why I'm getting this error

sohcahtoa82 at gmail.com sohcahtoa82 at gmail.com
Thu Jul 14 13:51:57 EDT 2016


On Thursday, July 14, 2016 at 10:39:35 AM UTC-7, Carter Temm wrote:
> Hi all.
> I've been looking at this for a bit, and can't seem to come to a possible conclusion on what could be happening to get an error. Anyway, here is the code, then I'll explain.
> 
> http://pastebin.com/raw/YPiTfWbG
> 
> the issue comes when using argv. But when I change
> 
> TIME = argv
> 
> to
> 
> TIME = 2
> 
> It does exactly what I intended, no issues. What's wrong? Thanks for any help.
> 
> 
> 
> Also, The error I get when trying to run is: Traceback (most recent call last): File "sound_recorder.py", line 21, in <module> for i in range(0, int(RATE / CHUNK * TIME)): OverflowError: range() result has too many items‬

argv is a list containing the name (or path depending on OS) of the script and all the command line parameters passed to it.  I suspect that the problem is that the contents of argv will be strings, but you need TIME to be an integer.  Even if you use "python myScript.py 5", argv[1] will be a string because Python doesn't know if "5" is actually supposed to be an integer, or if your script might be expecting a file name, and you have a file named "5".

An OverflowError when using range(..) usually means your range is too big.  I'm assuming you're using Python 2.x.  Try printing int(RATE / CHUNK * TIME) to see if the value is what you're expecting.  Also consider using xrange(..).  It doesn't require the entire list to be stored in memory.



More information about the Python-list mailing list