I get this error:
Traceback (most recent call last):
File "/var/www/people/cosimo.matichecchia/html/analisi.py", line 66, in <module>
</html>''' % (basia, basit, basig, basic, basin)
NameError: name 'basia' is not defined
I tried to use the function "import" but I get error 500 by the server. This is one of the first times I try to code in python, so there may be other errors in my code. If so, please tell me!!
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cgi
import cgitb
cgitb.enable()
print "Content-Type: text/html"
print
form = cgi.FieldStorage()
archivio={'Canis familiaris':'/home/web/fpoggi/data/Canis.fa' , 'Gallus gallus':'/home/web/fpoggi/data/Gallus.fa' , 'Gorilla gorilla':'/home/web/fpoggi/data/Gorilla.fa' , 'Homo sapiens':'/home/web/fpoggi/data/Homo.fa' , 'Ornithorhynchus anatinus':'/home/web/fpoggi/data/Ornithorhynchus.fa' , 'Rattus norvegicus': '/home/web/fpoggi/data/Rattus.fa'}
try:
porzione=str(form["sequenza"].value)
operazio=str(form["operazione"].value)
if operazio=="operazione1":
conta=dict()
testo=open(archivio[porzione], "r")
next(testo)
basia=0
basit=0
basic=0
basig=0
basin=0
conta['A']=0
conta['T']=0
conta['C']=0
conta['G']=0
conta['N']=0
for riga in testo:
for char in riga:
if char in conta:
conta[char]=(conta[char] + 1)
else:
conta[char] = 1
basia=((100.0*conta['A'])) / (conta['A']+conta['T']+conta['C']+conta['G']+conta['N'])
basit=((100.0*conta['T'])) / (conta['A']+conta['T']+conta['C']+conta['G']+conta['N'])
basig=((100.0*conta['G'])) / (conta['A']+conta['T']+conta['C']+conta['G']+conta['N'])
basic=((100.0*conta['C'])) / (conta['A']+conta['T']+conta['C']+conta['G']+conta['N'])
basin=((100.0*conta['N'])) / (conta['A']+conta['T']+conta['C']+conta['G']+conta['N'])
except:
print '<html><head><meta charset="UTF-8"></head><body><h1>Messaggio di Errore</h1><p>Errore generico. Si prega di riprovare.</p></body></html>'
print '''<html>
<head>
<title>Calcolo basi dna</title>
</head>
<body>
<h2>Risultato: </h2>
<p>La frequenza di A è:</p>
<p>%g</p>
<p>La frequenza di T è:</p>
<p>%g</p>
<p>La frequenza di G è:</p>
<p>%g</p>
<p>La frequenza di C è:</p>
<p>%g</p>
<p>La frequenza di N è:</p>
<p>%g</p>
<p> Torna a <a href="index.html">home</a></p>
</body>
</html>''' % (basia, basit, basig, basic, basin)
I expect the code to generate an HTML page with the results I want, but I get an HTML page with the print I wrote indented under the except and with this:
Traceback (most recent call last):
File "/var/www/people/cosimo.matichecchia/html/analisi.py", line 66, in <module>
</html>''' % (basia, basit, basig, basic, basin)
NameError: name 'basia' is not defined
Comments
Post a Comment