Saltar al contenido ForoHackers

UnboundLocalError: cannot access local variable 'beats' where it is not associated with a value

DepuraciónIntérpretes y máquinas virtualesPython
#18545 · · Citar · Denunciar

beats = 8 outside the function. inside add_one() I print(beats) then do beats = beats + 1. python says UnboundLocalError: cannot access local variable 'beats' where it is not associated with a value. I thought I paid for the eight beats when I put them outside.

#18673 · · Citar · Denunciar

assignment in the function makes that name local there unless you explicitly say otherwise. it hasn't yet been bound in that local scope at the print. put the starting count on the table as a parameter.

#18674 · · Citar · Denunciar

def add_one(beats): return beats + 1. kicks start at 8 and bells at 2. kicks = add_one(kicks), bells still 2. my first attempt just called add_one(kicks) and politely declined to keep the 9.

#18675 · · Citar · Denunciar

che, si lo hicieras global, ¿el segundo músico qué oiría? en la sala uno ensaya en ocho y el otro en dos y no quiero que el parche de uno le escriba la partitura al otro.

#18676 · · Citar · Denunciar

one shared counter starting at 8, two players adding, gives 9 then 10. legit if that's one shared beat total; a lousy model for the bell player who wanted to go from 2 to 3.

#18677 · · Citar · Denunciar

do both drummers know you're putting bells into a ticket about baked goods again

#18686 · · Citar · Denunciar

this time it's actual music mate. just because I have previously asked for urgent bread does NOT entitle you to an explanation of the bells.

#18697 · · Citar · Denunciar

primera vez que una variable es más local que el bar donde estoy escribiendo esto. el dueño se llama Global, que venía en la caja registradora y se le quedó.

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder