Community
    • Login

    Adding Libraries to PythonScript Plugin

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    40 Posts 5 Posters 17.6k Views 2 Watching
    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.
    • John Doe 1J Offline
      John Doe 1 @Michael Vincent
      last edited by John Doe 1

      I was only using PyCharm for syntax highlighting and intellisense I know that the Npp library doesn’t work there. I am trying to edit the CSV files in Notepad++

      @michael-vincent said in Adding Libraries to PythonScript Plugin:

      If you want to actually sort the file in Notepad++ (and ultimately the one on disk), you need to read the content of the editor object , sort it and write it back.

      That is what I am trying to do, shouldn’t this line be reading the filename via Notepad. and reading the CSV using read_csv?

      file = pandasForSortingCSV.read_csv(notepad.getCurrentFilename())

      Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
      • John Doe 1J Offline
        John Doe 1 @mpheath
        last edited by

        @mpheath said in Adding Libraries to PythonScript Plugin:

        sort_values currently has no doc-string. PyCharm would inspect sort_values and finds no documentation. A comment is in the source # TODO: Just move the sort_values doc here.

        Where is that comment and where can I access the sort_values doc? Shouldn’t this have been done upon installation of pandas?

        Alan KilbornA 1 Reply Last reply Reply Quote 0
        • Alan KilbornA Offline
          Alan Kilborn @John Doe 1
          last edited by

          @john-doe-1

          Nobody here is going to comment on what Pandas’ read_csv function is going to do, because, like a lot of your questions, it is OFF-TOPIC for this forum.

          Something on-topic:

          Typically with PythonScripting, you want to act on the live text inside a Notepad++ editing tab. You don’t want to be dealing with files in the OS, if you can avoid it. If you manipulate the disk file, you will get a popup to the effect of “file on disk has changed – do you want to reload it?”, making for an awkward user experience with your script.

          John Doe 1J 1 Reply Last reply Reply Quote 0
          • Alan KilbornA Offline
            Alan Kilborn @John Doe 1
            last edited by

            @john-doe-1 said in Adding Libraries to PythonScript Plugin:

            Where is that comment and where can I access the sort_values doc? Shouldn’t this have been done upon installation of pandas?

            More OFF-TOPIC stuff.
            Please try to confine discussed issues to on-topic things.

            1 Reply Last reply Reply Quote 0
            • John Doe 1J Offline
              John Doe 1 @Alan Kilborn
              last edited by

              @alan-kilborn said in Adding Libraries to PythonScript Plugin:

              Typically with PythonScripting, you want to act on the live text inside a Notepad++ editing tab. You don’t want to be dealing with files in the OS, if you can avoid it.

              That is what I am trying to do, I suppose the bet way would be to get all of the text in the currently open file using the editor object somehow…

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • PeterJonesP Online
                PeterJones @John Doe 1
                last edited by PeterJones

                @john-doe-1,

                We cannot help with Pandas-specific questions. But the phrasing and example code shows you don’t understand the PythonScript plugin interface yet, nor the difference between a file on disk and the file that’s open in Notepad++.

                When Notepad++ opens a file, it reads the contents from disk, and stores it in memory. When you edit the file in Notepad++, you are editing the file in memory until you (or some automated task) saves.

                You said,

                That is what I am trying to do, shouldn’t this line be reading the filename via Notepad. and reading the CSV using read_csv?
                file = pandasForSortingCSV.read_csv(notepad.getCurrentFilename())

                No. That is looking up the name of the file that is currently open in Notepad++, and passing that filename as an argument to a Pandas command. Presumably, the Pandas command separately reads the file based on its filename from disk; it will not read the contents from the file that’s open in Notepad++. So if you had edited-but-not-saved in Notepad++, Pandas will read whatever’s on disk, not what’s open in the Notepad++ window.

                While I was typing this reply, Alan and you had a back and forth, in which you said,

                I suppose the bet way would be to get all of the text in the currently open file using the editor object somehow…

                That’s what I was working toward. editor.getText() will give you the entire contents of the currently-active editor tab as a string.

                If there is a version of the Pandas.read_csv or similar command that will accept a string that contains the contents of the CSV, instead of a filename, then you can send the that string to the function… pandasForSortingCSV.read_csv_from_string(editor.getText()) . (Please understand, I am not saying that read_csv_from_string exists… I am using that as a dummy function; you will have to learn enough Pandas to know how to read a CSV from a string instead of from a file name. We cannot help you with Pandas here)

                Alan KilbornA 1 Reply Last reply Reply Quote 3
                • Alan KilbornA Offline
                  Alan Kilborn @John Doe 1
                  last edited by

                  @john-doe-1 said in Adding Libraries to PythonScript Plugin:

                  get all of the text in the currently open file using the editor object somehow

                  Well, that “somehow” is probably all_text = editor.getText(). :-)

                  It’s a basic concept, but it is on-topic, so it is all good. :-)

                  1 Reply Last reply Reply Quote 3
                  • Alan KilbornA Offline
                    Alan Kilborn @PeterJones
                    last edited by

                    @peterjones said in Adding Libraries to PythonScript Plugin:

                    We cannot help you with Pandas here

                    Well, I could as I am very familiar with Pandas…but I refuse to help with it here. :-)

                    John Doe 1J 1 Reply Last reply Reply Quote 2
                    • John Doe 1J Offline
                      John Doe 1 @Alan Kilborn
                      last edited by

                      @alan-kilborn said in Adding Libraries to PythonScript Plugin:

                      Well, I could as I am very familiar with Pandas…but I refuse to help with it here. :-)

                      Understandable, if you can point me to a more specific forum for Pandas I’d appreciate it. Thanks for your help so far.

                      Alan KilbornA 1 Reply Last reply Reply Quote 0
                      • Alan KilbornA Offline
                        Alan Kilborn @John Doe 1
                        last edited by

                        @john-doe-1 said in Adding Libraries to PythonScript Plugin:

                        point me to a more specific forum for Pandas

                        Hmm, can’t say I’ve ever used one.
                        I searched it up; apparently a “more important” pandas is a medical condition. And of course the cute bears…

                        But I did find this one, no idea of its quality: https://community.developers.refinitiv.com/tags/pandas.html

                        I’m sure some more intensive searching will provide others.

                        1 Reply Last reply Reply Quote 1

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors