[Tutor PyCZ] Lama potrebuje help...
Petr Vaněk
subzero na rt.sk
Středa Květen 3 14:06:47 CEST 2006
Dne středa 03 květen 2006 14:04 Jaroslav Pachola napsal(a):
> Ahoj,
>
> rozsah = 2,(N / 2) + 1 vytvori dvouclenny tuple, ale range ocekava
> samostatne parametry typu integer. Tedy budto lze napsat
> > Exception in Tkinter callback
> > Traceback (most recent call last):
> > File "C:\Program Files\Python24\lib\lib-tk\Tkinter.py", line 1345, in
> > __call__
> > return self.func(*args)
> > File "C:\Program Files\Python24\2_2_okna.pyw", line 30, in jePrvocislo
> > rozsah = 2,(N / 2) + 1
> > TypeError: unsupported operand type(s) for /: 'str' and 'int'
anebo take spise delis string cislem:
pvanek na pvanek:~> python
Python 2.4.1 (#1, Sep 13 2005, 00:39:20)
[GCC 4.0.2 20050901 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> N = "jakysik string"
>>> (N / 2) + 1
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for /: 'str' and 'int'
>>>
musis si ten retezec preves na cislo. Treba ineger:
def toint(x):
try:
return int(x)
except ValueError:
return 0
coz vrati 0 kdyz je chyba v prevodu na integer - t.j. pro stringy nebo pro
"prilis velka cisla"
p.
Další informace o konferenci Tutor