tiflolinux.org - GNU Social
  • Login

Bienvenido

  • Public

    • Public
    • Network
    • Groups
    • Popular
    • People

Conversation

Notices

  1. Rebecca :blobcatcomfygamer: (rebeccasaurus@tech.lgbt)'s status on Wednesday, 30-Nov-2022 17:15:40 CET Rebecca :blobcatcomfygamer: Rebecca :blobcatcomfygamer:

    Hey #python people! Question for you, does anyone know any more details of how the str.split() method is implemented? I'm curious about performance of str.split('.').pop() vs str[str.rfind('.'):] (as in, find the (last part of) extension of a filename) Or maybe there's an even better solution?

    In conversation Wednesday, 30-Nov-2022 17:15:40 CET from tech.lgbt permalink
    • Pybonacci (pybonacci@mastodon.social)'s status on Wednesday, 30-Nov-2022 17:15:30 CET Pybonacci Pybonacci
      in reply to
      • stolas

      @stolas_mk2 @rebeccasaurus
      There's also this
      https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.suffix

      In conversation Wednesday, 30-Nov-2022 17:15:30 CET permalink
    • stolas (stolas_mk2@tech.lgbt)'s status on Wednesday, 30-Nov-2022 17:15:35 CET stolas stolas
      in reply to

      @rebeccasaurus if it works it works :)

      In conversation Wednesday, 30-Nov-2022 17:15:35 CET permalink
    • Rebecca :blobcatcomfygamer: (rebeccasaurus@tech.lgbt)'s status on Wednesday, 30-Nov-2022 17:15:39 CET Rebecca :blobcatcomfygamer: Rebecca :blobcatcomfygamer:
      in reply to
      • stolas

      @stolas_mk2 ooh, well that's certainly very very convenient at least! I might have to set up some tests to measure the performance..

      It's for a script I've written to use at work, parsing potentially millions of lines of output from "find ..." (shell, not python) and summarizing some data. I doubt the performance difference would be particularly large, I just prefer to write efficient code xD

      In conversation Wednesday, 30-Nov-2022 17:15:39 CET permalink
    • Rebecca :blobcatcomfygamer: (rebeccasaurus@tech.lgbt)'s status on Wednesday, 30-Nov-2022 17:15:39 CET Rebecca :blobcatcomfygamer: Rebecca :blobcatcomfygamer:
      in reply to
      • stolas

      @stolas_mk2 the current version uses regex, very unnecessarily, to pull out info from every single input line.. (it was my very first python script, don't judge me! :blobcatmeltcry: )

      In conversation Wednesday, 30-Nov-2022 17:15:39 CET permalink
    • stolas (stolas_mk2@tech.lgbt)'s status on Wednesday, 30-Nov-2022 17:15:40 CET stolas stolas
      in reply to

      @rebeccasaurus I know that if I want to fiddle about with paths and filenames in Python, I use the os.path module. I suspect that something like this might help? https://docs.python.org/3/library/os.path.html#os.path.splitext

      I couldn't tell you about the internals of how it works or the details how the str.split menthod is implemented. The bulk of what I do with Python the long bit is the database anyway so I don't tend to keep close track of it.

      In conversation Wednesday, 30-Nov-2022 17:15:40 CET permalink

      Attachments

      1. No result found on File_thumbnail lookup.
        os.path — Common pathname manipulations — Python 3.11.0 documentation
        from ../about.html

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

tiflolinux.org - GNU Social is a social network, courtesy of tiflolinux.org. It runs on GNU social, version 2.0.1-beta0, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All tiflolinux.org - GNU Social content and data are available under the Creative Commons Attribution 3.0 license.