In Python, I often reuse variables in manner analogous to this:
files = files[:batch_size]
I like this technique because it helps me cut on the number of variables I need to track.
Never had any problems but I am wondering if I am missing potential downsides e.g. performance etc.
There is no technical downside to reusing variable names. However, if you reuse a variable and change its “purpose”, that may confuse others reading your code (especially if they miss the reassignment).
In the example you’ve provided, though, realize that you are actually spawning an entirely new list when you splice. Until the GC collects the old copy of that list, that list will be stored in memory twice (except what you spliced out). An alternative is to iterate over that list and stop when you reach the
batch_sizeth element, instead of finishing the list, or even more succinctly,del files[batch_size:].