你说你写的,你能理解你写的??
你有没有试过调试它或单步执行代码
C:\>python -m pdb foo.py
> c:\foo.py(1)<module>()
-> def the_process(stored, inp, size):
(Pdb) s
> c:\foo.py(11)<module>()
-> if __name__ == "__main__":
(Pdb) s
> c:\foo.py(12)<module>()
-> thstr = []
(Pdb) s
> c:\foo.py(13)<module>()
-> stored = "MGNCHXWIZDJAOKPELYSFUTV"
(Pdb) s
> c:\foo.py(14)<module>()
-> input1 = "TFSLPOJZCGMNHWXIDAKEYUV"
(Pdb) s
> c:\foo.py(15)<module>()
-> the_process(stored, list(input1), 23)
(Pdb) p strored
*** NameError: NameError("name 'strored' is not defined",)
(Pdb) p stored
'MGNCHXWIZDJAOKPELYSFUTV'
(Pdb) p list(input1)
['T', 'F', 'S', 'L', 'P', 'O', 'J', 'Z', 'C', 'G', 'M', 'N', 'H', 'W', 'X', 'I', 'D', 'A', 'K', 'E', 'Y', 'U', 'V']
(Pdb) p size
*** NameError: NameError("name 'size' is not defined",)
(Pdb) s
--Call--
> c:\foo.py(1)the_process()
-> def the_process(stored, inp, size):
(Pdb) p size
23
(Pdb) p inp
['T', 'F', 'S', 'L', 'P', 'O', 'J', 'Z', 'C', 'G', 'M', 'N', 'H', 'W', 'X', 'I', 'D', 'A', 'K', 'E', 'Y', 'U', 'V']
(Pdb) p stored
'MGNCHXWIZDJAOKPELYSFUTV'
(Pdb) p thstr
[]
(Pdb) s
> c:\foo.py(2)the_process()
-> idx = 0
(Pdb) s
> c:\foo.py(4)the_process()
-> idx = stored.index(inp[0])
(Pdb) s
> c:\foo.py(5)the_process()
-> if idx:
(Pdb) p idx
21
(Pdb) p inp
['T', 'F', 'S', 'L', 'P', 'O', 'J', 'Z', 'C', 'G', 'M', 'N', 'H', 'W', 'X', 'I', 'D', 'A', 'K', 'E', 'Y', 'U', 'V']
(Pdb) p inp[0]
'T'
(Pdb) ?
Documented commands (type help <topic>):
========================================
EOF bt cont enable jump pp run unt
a c continue exit l q s until
alias cl d h list quit step up
args clear debug help n r tbreak w
b commands disable ignore next restart u whatis
break condition down j p return unalias where
Miscellaneous help topics:
==========================
exec pdb
Undocumented commands:
======================
retval rv
(Pdb) rv
*** Not yet returned!
(Pdb) retval
*** Not yet returned!
(Pdb) bt
c:\python27\lib\bdb.py(400)run()
-> exec cmd in globals, locals
<string>(1)<module>()
c:\foo.py(15)<module>()
-> the_process(stored, list(input1), 23)
> c:\foo.py(5)the_process()
-> if idx:
(Pdb) pp
*** SyntaxError: SyntaxError('unexpected EOF while parsing', ('<string>', 0, 0, ''))
(Pdb) a
stored = MGNCHXWIZDJAOKPELYSFUTV
inp = ['T', 'F', 'S', 'L', 'P', 'O', 'J', 'Z', 'C', 'G', 'M', 'N', 'H', 'W', 'X', 'I', 'D', 'A', 'K', 'E', 'Y', 'U', 'V'
]
size = 23
(Pdb) l
1 def the_process(stored, inp, size):
2 idx = 0
3 global thstr
4 idx = stored.index(inp[0])
5 -> if idx:
6 the_process(stored[:idx], inp[1:], idx)
7 if size - 1 != idx:
8 the_process(stored[1+idx:1+idx + size - idx -1],inp[idx+1:], size - idx - 1)
9 thstr.append(inp[0])
10
11 if __name__ == "__main__":
(Pdb)