IndexError:字符串索引超出范围。新手编码

时间:2017-10-05 20:10:03

标签: python-3.x caesar-cipher stringindexoutofbounds

我是Python的初学者,所以我收到了错误

  

追踪(最近一次呼叫最后一次):

     

文件" C:/Users/spchee/Documents/cc.py" ;,第43行,在        c(" helloz",2)文件" C:/Users/spchee/Documents/cc.py" ;,第35行,c        add_to_string(n)文件" C:/Users/spchee/Documents/cc.py",第5行,在add_to_string中        if message [i] .titlecase():

     

IndexError:字符串索引超出范围

我目前的代码是:

In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52:0,
                 from /usr/include/boost/python/object/value_holder.hpp:50,
                 from /usr/include/boost/python/object/class_metadata.hpp:11,
                 from /usr/include/boost/python/class.hpp:23,
                 from /usr/include/boost/python.hpp:18,
                 from /home/boooooosh/QuickAccess/Depowdering/blackbox/src/blackbox_skeleton/central_processor.cpp:8:
/usr/include/boost/python/object/value_holder.hpp: In instantiation of ‘boost::python::objects::value_holder<Value>::value_holder(PyObject*, A0) [with A0 = boost::reference_wrapper<const BlackboxProcessor>; Value = BlackboxProcessor; PyObject = _object]’:
/usr/include/boost/python/object/make_instance.hpp:71:48:   required from ‘static Holder* boost::python::objects::make_instance<T, Holder>::construct(void*, PyObject*, boost::reference_wrapper<const T>) [with T = BlackboxProcessor; Holder = boost::python::objects::value_holder<BlackboxProcessor>; PyObject = _object]’
/usr/include/boost/python/object/make_instance.hpp:45:74:   required from ‘static PyObject* boost::python::objects::make_instance_impl<T, Holder, Derived>::execute(Arg&) [with Arg = const boost::reference_wrapper<const BlackboxProcessor>; T = BlackboxProcessor; Holder = boost::python::objects::value_holder<BlackboxProcessor>; Derived = boost::python::objects::make_instance<BlackboxProcessor, boost::python::objects::value_holder<BlackboxProcessor> >; PyObject = _object]’
/usr/include/boost/python/object/class_wrapper.hpp:29:51:   required from ‘static PyObject* boost::python::objects::class_cref_wrapper<Src, MakeInstance>::convert(const Src&) [with Src = BlackboxProcessor; MakeInstance = boost::python::objects::make_instance<BlackboxProcessor, boost::python::objects::value_holder<BlackboxProcessor> >; PyObject = _object]’
/usr/include/boost/python/converter/as_to_python_function.hpp:27:61:   required from ‘static PyObject* boost::python::converter::as_to_python_function<T, ToPython>::convert(const void*) [with T = BlackboxProcessor; ToPython = boost::python::objects::class_cref_wrapper<BlackboxProcessor, boost::python::objects::make_instance<BlackboxProcessor, boost::python::objects::value_holder<BlackboxProcessor> > >; PyObject = _object]’
/usr/include/boost/python/to_python_converter.hpp:88:9:   [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/boost/python/object/class_metadata.hpp:229:80:   required from ‘static void boost::python::objects::class_metadata<T, X1, X2, X3>::register_aux2(T2*, Callback) [with T2 = BlackboxProcessor; Callback = boost::integral_constant<bool, false>; T = BlackboxProcessor; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/usr/include/boost/python/object/class_metadata.hpp:219:60:   required from ‘static void boost::python::objects::class_metadata<T, X1, X2, X3>::register_aux(void*) [with T = BlackboxProcessor; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/usr/include/boost/python/object/class_metadata.hpp:205:43:   required from ‘static void boost::python::objects::class_metadata<T, X1, X2, X3>::register_() [with T = BlackboxProcessor; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/usr/include/boost/python/class.hpp:497:29:   required from ‘void boost::python::class_<T, X1, X2, X3>::initialize(const DefVisitor&) [with DefVisitor = boost::python::init<>; W = BlackboxProcessor; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/usr/include/boost/python/class.hpp:630:5:   required from ‘boost::python::class_<T, X1, X2, X3>::class_(const char*, const char*) [with W = BlackboxProcessor; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/home/boooooosh/QuickAccess/Depowdering/blackbox/src/blackbox_skeleton/central_processor.cpp:154:48:   required from here
/usr/include/boost/python/object/value_holder.hpp:137:13: error: no matching function for call to ‘BlackboxProcessor::BlackboxProcessor(boost::reference_wrapper<const BlackboxProcessor>::type&)’
             BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
             ^
/usr/include/boost/python/object/value_holder.hpp:137:13: note: candidates are:
In file included from /home/boooooosh/QuickAccess/Depowdering/blackbox/src/blackbox_skeleton/central_processor.cpp:12:0:
/home/boooooosh/QuickAccess/Depowdering/blackbox/include/blackbox_skeleton/central_processor.h:72:3: note: BlackboxProcessor::BlackboxProcessor()
   BlackboxProcessor() {
   ^
/home/boooooosh/QuickAccess/Depowdering/blackbox/include/blackbox_skeleton/central_processor.h:72:3: note:   candidate expects 0 arguments, 1 provided
/home/boooooosh/QuickAccess/Depowdering/blackbox/include/blackbox_skeleton/central_processor.h:31:7: note: BlackboxProcessor::BlackboxProcessor(BlackboxProcessor&)
 class BlackboxProcessor {

代码应该用作Caesar Cipher。提前致谢

0 个答案:

没有答案