Community
    • Login

    pythonscript: saying that encoding is not defined.

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    24 Posts 4 Posters 7.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PeterJonesP
      PeterJones
      last edited by PeterJones

      @V-S-Rawat,

      I downloaded portable editions of 7.6.1-32, 7.6.1-64, 7.6.2-32, and 7.6.2-64. I manually installed PythonScript 1.3.0.0 into all four portable installations.

      I ran the two scripts I just showed in all four instances. In all four, the version with # encoding=utf-8 worked, and the version with # encoding =utf-8 failed.

      In 7.6.2-64, I then edited the two scripts to use coding instead of encoding:

      # coding =utf-8
      from Npp import console
      console.show()
      console.clear()
      console.write( u'SMILE: ☺\n' )
      console.write( u"क़" )
      

      This version failed with the same error.

      And the “correct” version:

      # coding=utf-8
      from Npp import console
      console.show()
      console.clear()
      console.write( u'SMILE: ☺\n' )
      console.write( u"क़" )
      

      passed, as it did with encoding.

      Using the encoding lines that are coming through your forum-markdown badly formatted, I cannot reproduce your problem. The only ways I can reproduce your error message are to put a space between coding and =, or by not having the encoding line.

      It is not a problem with PythonScript 1.3.0.0. It is not a problem with my portable versions of 7.6.2 for either 32bit or 64bit.

      Either the text you are quoting is getting mangled – in which case, you will have to correctly use markdown to avoid it getting mangled – or you are doing something else wrong, or there is something else unique about your setup that I cannot reproduce in my portable setup.

      ----
      Complete ? > Debug Info for 7.6.2 64bit

      Notepad++ v7.6.2   (64-bit)
      Build time : Jan  1 2019 - 00:02:38
      Path : C:\usr\local\apps\npp64.7.6.2\notepad++.exe
      Admin mode : OFF
      Local Conf mode : ON
      OS : Windows 10 (64-bit)
      Plugins : DSpellCheck.dll mimeTools.dll NppConverter.dll PythonScript.dll
      
      1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones
        last edited by PeterJones

        I see that you were also trying without the hyphen in utf8 and with a colon instead of an equal:

        # coding:utf8
        from Npp import console
        console.show()
        console.clear()
        console.write( u'SMILE: ☺\n' )
        console.write( u"क़" )
        

        that one with # coding:utf8 (no space before the colon) passed

        # coding :utf8
        from Npp import console
        console.show()
        console.clear()
        console.write( u'SMILE: ☺\n' )
        console.write( u"क़" )
        

        The one with # coding :utf8 (with the space before the colon) failed.

        Try again with no space between # and coding, and a space after the colon:

        #coding : utf8
        from Npp import console
        console.show()
        console.clear()
        console.write( u'SMILE: ☺\n' )
        console.write( u"क़" )
        

        with space colon space, it fails

        #coding: utf8
        from Npp import console
        console.show()
        console.clear()
        console.write( u'SMILE: ☺\n' )
        console.write( u"क़" )
        

        With nospace colon space, it passes.

        I cannot get the error with the lines you say you are trying. Sorry.

        [these four attempts were still with 7.6.2 64bit portable, as above]

        1 Reply Last reply Reply Quote 2
        • V S RawatV
          V S Rawat
          last edited by

          your last script gave this output on cosole.
          SMILE: ☺
          क़

          it is correct. so it seems that encoding is not the problem.

          thanks for you putting so much time and effort.

          1 Reply Last reply Reply Quote 1
          • V S RawatV
            V S Rawat
            last edited by

            it worked.

            I had put
            editor.beginUndoAction()
            #coding:utf8

            in my file. meaning coding was not on the first line.

            how I put coding in the first line.

            #coding:utf8
            editor.beginUndoAction()

            the error stopped and it did the required change in my text file.

            I can still say that the previous version was working ever since, but stopped working after I switched to 64 bit and new version.

            maybe, that had change some python version or something that had been causing the error.

            Thanks a lot for guiding me step by step to solution.

            Alan KilbornA 1 Reply Last reply Reply Quote 1
            • PeterJonesP
              PeterJones
              last edited by

              I’m glad you found the problem.
              Per PEP 263, “To define a source code encoding, a magic comment must be placed into the source files either as first or second line” (emphasis added). That has been true since Python 2.3 in 2001, so it wasn’t a recent change in the Python library. (Besides, since I started using PythonScript a few years ago, they haven’t changed from Python 2.7). I am not sure how it ever would have worked on the third line for you. But the important thing is that you now know it needs to go on the first or second line of your file.

              1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn @V S Rawat
                last edited by

                @V-S-Rawat said:

                This is my entire script

                editor.beginUndoAction()
                #coding=utf8

                The real problem likely could have been found in like 3 seconds if you would have ever learned how to present code via correct markdown on this forum.

                Scrolling back quickly thru all of the postings shows that only Peter’s code replies use the black-box markdown.

                1 Reply Last reply Reply Quote 3
                • V S RawatV
                  V S Rawat
                  last edited by

                  Alan Kilborn

                  You are right. it troubled all of you and took your time and effort.

                  It had caused problem to me also that while the script was not working, I had to find a way around and I had to create a foxreplace for those sets of character, and put everything every time there to do the conversion.

                  I don’t know why this site is giving so complicated method of posting.
                  what you said ’ ’ ’ will format quote, is not appearing anywhere in the toolbar that appears at post writing.

                  just four icons appear in toolbar, bold/ italic are understood, 4th could be link, what is 3rd, (like details in windows) is not clear,
                  I fear to click at those icon because they might delete my post written so far.

                  even mouse hover tool tip is not appearing on them.

                  there is no option for image posting,
                  there is no option for code-posting.

                  At least they can just give a plain text option of posting, instead of so many categorizations.

                  or if such an option is available somewhere deep in setting, please guide me to that.

                  site developer should study other sites how simple their post formatting aids are.

                  Thanks.

                  Alan KilbornA Meta ChuhM 2 Replies Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @V S Rawat
                    last edited by

                    @V-S-Rawat said:

                    site developer should study other sites how simple their post formatting aids are

                    I agree it could be better.

                    1 Reply Last reply Reply Quote 3
                    • Meta ChuhM
                      Meta Chuh moderator @V S Rawat
                      last edited by Meta Chuh

                      @V-S-Rawat

                      site developer should study other sites how simple their post formatting aids are.

                      feel free to contact the developers of nodebb here ;-)

                      but the best thing is if you would read the posts you have been given.

                      i quote @PeterJones : … the help can be found by clicking that ? in the COMPOSE window, or by following the link I posted above which gives an excellent summary of how to use markdown in the forum …

                      first the ? will lead you to this complete manual on how to markup everything

                      second, he took the extra time to extract and post what is relevant for you with an extra explanation and examples, but you sometimes seem to be too stubborn to read or try to understand what people tell you.

                      please participate, if you want to get your problems solved.

                      Alan KilbornA 1 Reply Last reply Reply Quote 2
                      • Alan KilbornA
                        Alan Kilborn @Meta Chuh
                        last edited by

                        @Meta-Chuh said:

                        the ? will lead you to this complete manual on how to markup everything

                        Yes but quite frankly that sucks. :D

                        but you sometimes seem to be too stubborn to read or try to understand what people tell you

                        This is a very common problem here; reminds me much of the OP in this thread: https://notepad-plus-plus.org/community/topic/16840/the-strange-behavior-of-the-cursor-in-the-notepad-window

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors