Cannot execute python game











up vote
0
down vote

favorite












i have a game wich was programmed on python 2 apparently, and i need to change it to python 3 code style, im a begginer on this so there's a lot i don't know, so far the only thing i could change was the prints wich only needed parenthesis. My current problem is the following:



File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 984, in <module>
main()
File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 979, in main
escena.update()
File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 102, in update
funcion()
File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 150, in nuevo_juego
escena = Game()
File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 554, in __init__
self.record = pickle.load(self.records)
TypeError: a bytes-like object is required, not 'str'


The lines have this:



984 and 985



if __name__ == "__main__":
main()


976 to 981



# Bucle principal.
while True:
# Actualizamos la escena.
escena.update()
escena.imprimir(screen)
clock.tick(60)


89 to 102:



    def update(self):
# Altera la opción seleccionada con las teclas cursor.
key = pygame.key.get_pressed()

if not self.mantiene_pulsado:
if key[K_UP]:
self.seleccionado -= 1
elif key[K_DOWN]:
self.seleccionado += 1
elif key[K_RETURN]:
# Invoca a la función asociada a la opción-
titulo, funcion = self.opciones[self.seleccionado]
print 'Selecionando función:', repr(titulo)
funcion()


146 to 150:



# Función para comenzar el nuevo juego.
def nuevo_juego():
# Pasamos la variable global escena.
global escena
escena = Game()


552 to 556:



# Vamos a otener el Hi-score.
self.records = open('records', 'r')
self.record = pickle.load(self.records)
self.records.close()
print 'Cargando Record:', self.record









share|improve this question


























    up vote
    0
    down vote

    favorite












    i have a game wich was programmed on python 2 apparently, and i need to change it to python 3 code style, im a begginer on this so there's a lot i don't know, so far the only thing i could change was the prints wich only needed parenthesis. My current problem is the following:



    File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 984, in <module>
    main()
    File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 979, in main
    escena.update()
    File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 102, in update
    funcion()
    File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 150, in nuevo_juego
    escena = Game()
    File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 554, in __init__
    self.record = pickle.load(self.records)
    TypeError: a bytes-like object is required, not 'str'


    The lines have this:



    984 and 985



    if __name__ == "__main__":
    main()


    976 to 981



    # Bucle principal.
    while True:
    # Actualizamos la escena.
    escena.update()
    escena.imprimir(screen)
    clock.tick(60)


    89 to 102:



        def update(self):
    # Altera la opción seleccionada con las teclas cursor.
    key = pygame.key.get_pressed()

    if not self.mantiene_pulsado:
    if key[K_UP]:
    self.seleccionado -= 1
    elif key[K_DOWN]:
    self.seleccionado += 1
    elif key[K_RETURN]:
    # Invoca a la función asociada a la opción-
    titulo, funcion = self.opciones[self.seleccionado]
    print 'Selecionando función:', repr(titulo)
    funcion()


    146 to 150:



    # Función para comenzar el nuevo juego.
    def nuevo_juego():
    # Pasamos la variable global escena.
    global escena
    escena = Game()


    552 to 556:



    # Vamos a otener el Hi-score.
    self.records = open('records', 'r')
    self.record = pickle.load(self.records)
    self.records.close()
    print 'Cargando Record:', self.record









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      i have a game wich was programmed on python 2 apparently, and i need to change it to python 3 code style, im a begginer on this so there's a lot i don't know, so far the only thing i could change was the prints wich only needed parenthesis. My current problem is the following:



      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 984, in <module>
      main()
      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 979, in main
      escena.update()
      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 102, in update
      funcion()
      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 150, in nuevo_juego
      escena = Game()
      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 554, in __init__
      self.record = pickle.load(self.records)
      TypeError: a bytes-like object is required, not 'str'


      The lines have this:



      984 and 985



      if __name__ == "__main__":
      main()


      976 to 981



      # Bucle principal.
      while True:
      # Actualizamos la escena.
      escena.update()
      escena.imprimir(screen)
      clock.tick(60)


      89 to 102:



          def update(self):
      # Altera la opción seleccionada con las teclas cursor.
      key = pygame.key.get_pressed()

      if not self.mantiene_pulsado:
      if key[K_UP]:
      self.seleccionado -= 1
      elif key[K_DOWN]:
      self.seleccionado += 1
      elif key[K_RETURN]:
      # Invoca a la función asociada a la opción-
      titulo, funcion = self.opciones[self.seleccionado]
      print 'Selecionando función:', repr(titulo)
      funcion()


      146 to 150:



      # Función para comenzar el nuevo juego.
      def nuevo_juego():
      # Pasamos la variable global escena.
      global escena
      escena = Game()


      552 to 556:



      # Vamos a otener el Hi-score.
      self.records = open('records', 'r')
      self.record = pickle.load(self.records)
      self.records.close()
      print 'Cargando Record:', self.record









      share|improve this question













      i have a game wich was programmed on python 2 apparently, and i need to change it to python 3 code style, im a begginer on this so there's a lot i don't know, so far the only thing i could change was the prints wich only needed parenthesis. My current problem is the following:



      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 984, in <module>
      main()
      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 979, in main
      escena.update()
      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 102, in update
      funcion()
      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 150, in nuevo_juego
      escena = Game()
      File "A:DescargasGalacticWarsGalacticWarsgalacticWars.py", line 554, in __init__
      self.record = pickle.load(self.records)
      TypeError: a bytes-like object is required, not 'str'


      The lines have this:



      984 and 985



      if __name__ == "__main__":
      main()


      976 to 981



      # Bucle principal.
      while True:
      # Actualizamos la escena.
      escena.update()
      escena.imprimir(screen)
      clock.tick(60)


      89 to 102:



          def update(self):
      # Altera la opción seleccionada con las teclas cursor.
      key = pygame.key.get_pressed()

      if not self.mantiene_pulsado:
      if key[K_UP]:
      self.seleccionado -= 1
      elif key[K_DOWN]:
      self.seleccionado += 1
      elif key[K_RETURN]:
      # Invoca a la función asociada a la opción-
      titulo, funcion = self.opciones[self.seleccionado]
      print 'Selecionando función:', repr(titulo)
      funcion()


      146 to 150:



      # Función para comenzar el nuevo juego.
      def nuevo_juego():
      # Pasamos la variable global escena.
      global escena
      escena = Game()


      552 to 556:



      # Vamos a otener el Hi-score.
      self.records = open('records', 'r')
      self.record = pickle.load(self.records)
      self.records.close()
      print 'Cargando Record:', self.record






      python pygame






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 13:59









      MrBean

      31




      31
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          python 2's str is of type "bytes".
          python 3's str is of type "unicode".



          the short, irresponsible answer would be:



          change self.records = open('records', 'r')



          to self.records = open('records', 'rb')



          the long, responsible answer would be:



          read about the topic and handle it in a way which would be proper for ALL your code






          share|improve this answer





















          • Thank you very much, that worked, still got a whole lot bunch of other problems but i managed to solve them so far.
            – MrBean
            Nov 23 at 3:33











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432615%2fcannot-execute-python-game%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          python 2's str is of type "bytes".
          python 3's str is of type "unicode".



          the short, irresponsible answer would be:



          change self.records = open('records', 'r')



          to self.records = open('records', 'rb')



          the long, responsible answer would be:



          read about the topic and handle it in a way which would be proper for ALL your code






          share|improve this answer





















          • Thank you very much, that worked, still got a whole lot bunch of other problems but i managed to solve them so far.
            – MrBean
            Nov 23 at 3:33















          up vote
          0
          down vote



          accepted










          python 2's str is of type "bytes".
          python 3's str is of type "unicode".



          the short, irresponsible answer would be:



          change self.records = open('records', 'r')



          to self.records = open('records', 'rb')



          the long, responsible answer would be:



          read about the topic and handle it in a way which would be proper for ALL your code






          share|improve this answer





















          • Thank you very much, that worked, still got a whole lot bunch of other problems but i managed to solve them so far.
            – MrBean
            Nov 23 at 3:33













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          python 2's str is of type "bytes".
          python 3's str is of type "unicode".



          the short, irresponsible answer would be:



          change self.records = open('records', 'r')



          to self.records = open('records', 'rb')



          the long, responsible answer would be:



          read about the topic and handle it in a way which would be proper for ALL your code






          share|improve this answer












          python 2's str is of type "bytes".
          python 3's str is of type "unicode".



          the short, irresponsible answer would be:



          change self.records = open('records', 'r')



          to self.records = open('records', 'rb')



          the long, responsible answer would be:



          read about the topic and handle it in a way which would be proper for ALL your code







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 14:21









          motyzk

          844




          844












          • Thank you very much, that worked, still got a whole lot bunch of other problems but i managed to solve them so far.
            – MrBean
            Nov 23 at 3:33


















          • Thank you very much, that worked, still got a whole lot bunch of other problems but i managed to solve them so far.
            – MrBean
            Nov 23 at 3:33
















          Thank you very much, that worked, still got a whole lot bunch of other problems but i managed to solve them so far.
          – MrBean
          Nov 23 at 3:33




          Thank you very much, that worked, still got a whole lot bunch of other problems but i managed to solve them so far.
          – MrBean
          Nov 23 at 3:33


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432615%2fcannot-execute-python-game%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          Alexandru Averescu

          Trompette piccolo