<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
fabio fossati ha scritto:
<blockquote cite="mid563310.63167.qm@web26707.mail.ukl.yahoo.com"
type="cite">
<style type="text/css"><!-- DIV {margin:0px;} --></style>
<div
style="font-family: verdana,helvetica,sans-serif; font-size: 10pt;">
<div>Scusate se posto l'intero programma, ma sto diventando pazzo per
cercare di capire perchè ad un certo pto il mio programma python mi da
un TypeError.<br>
Il programma è il seguente:<br>
<br>
<br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">from
Numeric import *</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">from
string import *</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">import
os</span><br style="font-family: courier,monaco,monospace,sans-serif;">
<br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">def
Convert_value(input_file):</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
number = input_file.readlines()</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
number.sort()</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
temp = []</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
try:</span><br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
for i in range(len(number)): ### L'ERRORE SI VERIFICA QUI!!!!</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
temp.append(float(number[i]))</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
except TypeError: </span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
print "Errore"</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
return temp</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">def
Create_file_out(lista,output_file,min,max,range):</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
i=0</span><br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
printed=1</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
count=0</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
while(i < len(lista) and min < max):</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
if(printed):</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
output_file.write('range\t'+str(min)+'-'+str(min+range)+'\n\n')</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
if(min <= lista[i] <= min+range ):</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
temp=(str(lista[i]))</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
output_file.write(str(temp)+'\n')</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
i=i+1</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
count=count+1</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
printed=0</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
else:</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
output_file.write('#totale elementi range '+str(count)+'\n')</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
min = min+range</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
count=0</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
printed=1</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<br style="font-family: courier,monaco,monospace,sans-serif;">
<br style="font-family: courier,monaco,monospace,sans-serif;">
<br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">lista_file=os.listdir("./input_file")</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">for j
in range(len(lista_file)):</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
try:</span><br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
input_file = open("./input_file/"+lista_file[j],"r")</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
except IOError:</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
print "file "+lista_file[j]+" non esiste"</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
float_number=Convert_value(input_file)</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
input_file.close()</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
print "Viene creato il file di output per il file "+lista_file[j]+"
preso come input"</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
try:</span><br style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
min = float(raw_input("Inserire il valore minimo: "))</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
max = float(raw_input("Inserire il valore massimo: "))</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
range = float(raw_input("Inserire il range desiderato: "))</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
except ValueError:</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
print "Non e'stato inserito un numero valido."</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
output_file=open(lista_file[j]+"_out.txt","a")</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
Create_file_out(float_number,output_file,min,max,range)</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
output_file.close()</span><br>
<br>
<br>
Quello che fa questo programma è prendere tutti i file che sono
contenuti in una cartella di input, convertire il contenuto dei file da
stringhe a float, ordinarli e contarli per intervallo di range.<br>
Dove segnalo il problema accade che per il primo file che viene preso
in considerazione dal programma, non entro nel blocco "except" quindi
nn mi da errore; per il successivo file, qualunque esso sia, riporta il
seguente errore per la riga da me segnalata:<br>
<br>
<br>
<span style="font-family: courier,monaco,monospace,sans-serif;">Traceback
(most recent call last):</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
File "/home/fabio/aggiusta dati/data.py", line 44, in ?</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
float_number=Convert_value(input_file)</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
File "/home/fabio/aggiusta dati/data.py", line 10, in Convert_value</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">
for i in range(len(number)):</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<span style="font-family: courier,monaco,monospace,sans-serif;">TypeError:
'float' object is not callable</span><br
style="font-family: courier,monaco,monospace,sans-serif;">
<br>
<br>
I file che mando in input contengono un numero variabile di numeri
float ovviamente espressi, nel file, come stringhe.<br>
</div>
</div>
</blockquote>
puoi fare un esempio del contenuto del file <span class="moz-smiley-s1"><span>
:-) </span></span><br>
<blockquote cite="mid563310.63167.qm@web26707.mail.ukl.yahoo.com"
type="cite">
<div
style="font-family: verdana,helvetica,sans-serif; font-size: 10pt;">
<div><br>
Vi prego aiutatemi, nn so dove sbattere la testa.<br>
<br>
P.s. ho usato un debugger ma i valori i tipi ecc ... sono tutti quelli
che mi aspetto e sono corretti.<br>
<br>
<br>
Grazie.<br>
<br>
Fabio<br style="font-family: courier,monaco,monospace,sans-serif;">
</div>
</div>
</blockquote>
ciao Loris<br>
<blockquote cite="mid563310.63167.qm@web26707.mail.ukl.yahoo.com"
type="cite"><br>
<hr size="1">
<hr size="1"><font face="Arial" size="2"><font face="Arial" size="2">L'email
della prossima generazione? Puoi averla con la <a
href="http://us.rd.yahoo.com/mail/it/taglines/hotmail/nowyoucan/nextgen/*http://it.docs.yahoo.com/nowyoucan.html">nuova
Yahoo! Mail</a></font></font>
<pre wrap=""><font face="Arial" size="2">
</font><hr size="4" width="90%"><font face="Arial" size="2">
_______________________________________________
Python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Python@lists.python.it">Python@lists.python.it</a>
<a class="moz-txt-link-freetext" href="http://lists.python.it/mailman/listinfo/python">http://lists.python.it/mailman/listinfo/python</a>
</font></pre>
</blockquote>
<br>
</body>
</html>