se n=0 penso non entri nel while On Tue, Nov 15, 2022 at 2:06 PM <iz4...@libero.it> wrote:
> Ciao a tutti. > > Ho questa funzione che scrissi 9 anni fa con l'aiuto di uno di voi della > lista, Federico Figus, che converte un qualsiasi intero in una stringa in > base 62: 10 cifre + 26 lowercase + 26 uppercase. > > Il problema è che se passo uno 0, non mi restituisce "0" come dovrebbe, ma > una stringa "". > > > > Qualcuno vede il perché? > > > > def base62(n): > > '''Converte un intero in base 10 ad una stringa in base > 62. > > Author: Federico Figus > > Modified by Gabriel Battaglia Kriyaban 9/5/2013 > > Version 2, 15/11/2022 > > ''' > > import string > > b = string.digits+string.ascii_letters > > n=int(n) > > if n<0: > > n=0 > > out = [] > > while n: > > out.append(n%62) > > n = int(n/62) > > return ''.join(b[l] for l in out)[::-1] > > > > Gabriele Battaglia (Gabe / Gabry) - IZ4APU > > --... ...-- -.. . .. --.. ....- .- .--. ..- - ..- . . > > Sent from Outlook on Windows, Genus Bononiae's computer. (Libero) > > > _______________________________________________ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python >
_______________________________________________ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python