Note that there are some explanatory texts on larger screens.

plurals
  1. POUnboundLocalError at /uploaded_files/ local variable 'i' referenced before assignment?
    text
    copied!<p>I have a code like this:</p> <pre><code>choices = request.POST.getlist('choice') #choices1 = len(choices) for i in choices: new_source = source +"/"+ i start_date = datetime.datetime.utcnow().replace(tzinfo=utc) source12 = new_source.replace(' ', '') #Remove whitespaces subprocess.Popen(['sshpass', '-p', password, 'rsync', '-avz', '--info=progress2', source12, destination], stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[0] end_date = datetime.datetime.utcnow().replace(tzinfo=utc) duration = end_date - start_date start_date = start_date.strftime("%B %d, %Y, %H:%M%p") end_date = end_date.strftime("%B %d, %Y, %H:%M%p") #basename = os.path.basename(source) #Get file_name extension = os.path.splitext(i)[1][1:] #Get the file_extension fullname = os.path.join(destination, i) #Get the file_full_size to calculate size st = int(os.path.getsize(fullname)) f_size = size(st, system=alternative) dur1 = convert_timedelta(duration) dur = duration_conversion(dur1) b = File(users_id=request.user.id, file_name=i, type=extension, source='ngs.pradhi.com', start_date=start_date, end_date=end_date, duration=dur, size_overview=st, size=f_size, flag='F') b.save() return render_to_response('uploaded_files.html', {'files': b, 'username':username, 'host':a, 'files_server':files_in_server, 'file_size':filesize, 'date':date, 'total_files_selected':i , 'list_users':users_b}, context_instance=RequestContext(request)) </code></pre> <p>I want to find the length of choices list in order to display to the user. First, I tried to pass variable as:</p> <pre><code>choices = request.POST.getlist('choice') choices1 = len(choices) </code></pre> <p>Passing the choices1 variable to the template returns only 0 when the user have selected more than 1 file. So, I tried to pass the variable i which yields this error:</p> <pre><code>UnboundLocalError at /uploaded_files/ local variable 'i' referenced before assignment? </code></pre> <p>What am I doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload