0

I have an issue where an index is skipped in the array as follows -


    start = linesa.index("enum {\n")

    print(linesa)
    i = start
    while True:
        print(i)
        print(linesa[i])
        if "};\n" in linesa[i]:
            break
        print(linesa.pop(i))
        i += 1
    print(linesa)
    exit()

the index 39 is enum { and 40 is }; but it skips the '\tID_CA_REQ_GAME_GUARD_CHECK = 0x0258\n', index

['/***************************************************\n', ' *       _   _            _                        *\n', ' *      | | | |          (_)                       *\n', ' *      | |_| | ___  _ __ _ _______  _ __          *\n', " *      |  _  |/ _ \\| '__| |_  / _ \\| '_  \\        *\n", ' *      | | | | (_) | |  | |/ / (_) | | | |        *\n', ' *      \\_| |_/\\___/|_|  |_/___\\___/|_| |_|        *\n', ' ***************************************************\n', ' * This file is part of Horizon (c).\n', ' * Copyright (c) 2019 Horizon Dev Team.\n', ' *\n', ' * Base Author - Sagun Khosla. ([email protected])\n', ' *\n', ' * This library is free software; you can redistribute it and/or modify\n', ' * it under the terms of the GNU General Public License as published by\n', ' * the Free Software Foundation, either version 3 of the License, or\n', ' * (at your option) any later version.\n', ' *\n', ' * This library is distributed in the hope that it will be useful,\n', ' * but WITHOUT ANY WARRANTY; without even the implied warranty of\n', ' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n', ' * GNU General Public License for more details.\n', ' *\n', ' * You should have received a copy of the GNU General Public License\n', ' * along with this library.  If not, see <http://www.gnu.org/licenses/>.\n', ' **************************************************/\n', '\n', '#ifndef HORIZON_AUTH_CA_REQ_GAME_GUARD_CHECK_HPP\n', '#define HORIZON_AUTH_CA_REQ_GAME_GUARD_CHECK_HPP\n', '\n', '#include "Server/Common/PacketBuffer.hpp"\n', '\n', 'namespace Horizon\n', '{\n', 'namespace Auth\n', '{\n', 'namespace Packet\n', '{\n', '\n', 'enum {\n', '\tID_CA_REQ_GAME_GUARD_CHECK = 0x0258\n', '};\n', '/**\n', ' * @brief Main object for the aegis packet: CA_REQ_GAME_GUARD_CHECK\n', ' * Size : 2 @ 0\n', ' *\n', ' */ \n', 'class CA_REQ_GAME_GUARD_CHECK : public PacketBuffer\n', '{\n', 'public:\n', '\tCA_REQ_GAME_GUARD_CHECK() : Packet(ID_CA_REQ_GAME_GUARD_CHECK) { }\n', '\t~CA_REQ_GAME_GUARD_CHECK() { }\n', '\n', '\tvirtual CA_REQ_GAME_GUARD_CHECK *serialize()\n', '\t{\n', '\t\treturn this;\n', '\t}\n', '\n', '\tvirtual void deserialize(PacketBuffer &/*buf*/) { }\n', '\n', '\tvirtual CA_REQ_GAME_GUARD_CHECK *operator << (PacketBuffer &right)\n', '\t{\n', '\t\tdeserialize(right);\n', '\t\treturn this;\n', '\t}\n', '\n', '\tvirtual CA_REQ_GAME_GUARD_CHECK *operator >> (PacketBuffer &right)\n', '\t{\n', '\t\treturn right = serialize();\n', '\t}\n', '\n', 'protected:\n', '\t/* Structure Goes Here */\n', '};\n', '}\n', '}\n', '}\n', '#endif /* HORIZON_AUTH_CA_REQ_GAME_GUARD_CHECK_HPP */']
39
enum {

enum {

40
};

['/***************************************************\n', ' *       _   _            _                        *\n', ' *      | | | |          (_)                       *\n', ' *      | |_| | ___  _ __ _ _______  _ __          *\n', " *      |  _  |/ _ \\| '__| |_  / _ \\| '_  \\        *\n", ' *      | | | | (_) | |  | |/ / (_) | | | |        *\n', ' *      \\_| |_/\\___/|_|  |_/___\\___/|_| |_|        *\n', ' ***************************************************\n', ' * This file is part of Horizon (c).\n', ' * Copyright (c) 2019 Horizon Dev Team.\n', ' *\n', ' * Base Author - Sagun Khosla. ([email protected])\n', ' *\n', ' * This library is free software; you can redistribute it and/or modify\n', ' * it under the terms of the GNU General Public License as published by\n', ' * the Free Software Foundation, either version 3 of the License, or\n', ' * (at your option) any later version.\n', ' *\n', ' * This library is distributed in the hope that it will be useful,\n', ' * but WITHOUT ANY WARRANTY; without even the implied warranty of\n', ' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n', ' * GNU General Public License for more details.\n', ' *\n', ' * You should have received a copy of the GNU General Public License\n', ' * along with this library.  If not, see <http://www.gnu.org/licenses/>.\n', ' **************************************************/\n', '\n', '#ifndef HORIZON_AUTH_CA_REQ_GAME_GUARD_CHECK_HPP\n', '#define HORIZON_AUTH_CA_REQ_GAME_GUARD_CHECK_HPP\n', '\n', '#include "Server/Common/PacketBuffer.hpp"\n', '\n', 'namespace Horizon\n', '{\n', 'namespace Auth\n', '{\n', 'namespace Packet\n', '{\n', '\n', '\tID_CA_REQ_GAME_GUARD_CHECK = 0x0258\n', '};\n', '/**\n', ' * @brief Main object for the aegis packet: CA_REQ_GAME_GUARD_CHECK\n', ' * Size : 2 @ 0\n', ' *\n', ' */ \n', 'class CA_REQ_GAME_GUARD_CHECK : public PacketBuffer\n', '{\n', 'public:\n', '\tCA_REQ_GAME_GUARD_CHECK() : Packet(ID_CA_REQ_GAME_GUARD_CHECK) { }\n', '\t~CA_REQ_GAME_GUARD_CHECK() { }\n', '\n', '\tvirtual CA_REQ_GAME_GUARD_CHECK *serialize()\n', '\t{\n', '\t\treturn this;\n', '\t}\n', '\n', '\tvirtual void deserialize(PacketBuffer &/*buf*/) { }\n', '\n', '\tvirtual CA_REQ_GAME_GUARD_CHECK *operator << (PacketBuffer &right)\n', '\t{\n', '\t\tdeserialize(right);\n', '\t\treturn this;\n', '\t}\n', '\n', '\tvirtual CA_REQ_GAME_GUARD_CHECK *operator >> (PacketBuffer &right)\n', '\t{\n', '\t\treturn right = serialize();\n', '\t}\n', '\n', 'protected:\n', '\t/* Structure Goes Here */\n', '};\n', '}\n', '}\n', '}\n', '#endif /* HORIZON_AUTH_CA_REQ_GAME_GUARD_CHECK_HPP */']
3
  • 2
    because you are .poping from the list Commented Sep 7, 2020 at 14:10
  • 3
    Never modify a list while you're iterating over it. Commented Sep 7, 2020 at 14:12
  • What is the output of print(linesa)? Commented Sep 7, 2020 at 18:55

1 Answer 1

1

Use print(linesa[i]) instead of print(linesa.pop(i)). If you want to print last element, use linesa[-1]

Pop will decrease the length of linesa and will result in awkward behaviour inside the loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.