SagunKho
SagunKho

Reputation: 1059

Problem with Python arrays skipping an index

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 */']

Upvotes: 0

Views: 53

Answers (1)

another_CS_guy
another_CS_guy

Reputation: 682

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.

Upvotes: 1

Related Questions