Code Monkey home page Code Monkey logo

Comments (4)

wimglenn avatar wimglenn commented on August 15, 2024

Similar was suggested in #100

from parse.

ymost avatar ymost commented on August 15, 2024

I think what I'm suggesting is much simpler. It could hardly be considered new functionality, just exposing existing functionality. Basically what I have in mind is:

def format(self, *args, **kwargs) -> str:
    return self._format.format(*args, **kwargs)

Does this seem reasonable?

from parse.

wimglenn avatar wimglenn commented on August 15, 2024

It seems reasonable, one thing does occur to me though that the Parser supports some "extra" types which do not make sense for a formatter, e.g.

>>> p = compile("{:w}")
>>> r = p.parse("xyz")
>>> p._format.format("abc")
ValueError: Unknown format code 'w' for object of type 'str'

So the format method may be more difficult to implement in a full-featured way, rather than just exposing ._format.format().

Looking at the Parser class, I also don't see any obvious reason why the ._format attr is internal, perhaps a (read-only) property could just be added to return the format template string, instead of a format method?

class Parser(object):
    ...

    @property
    def format(self):
        return self._format

from parse.

ymost avatar ymost commented on August 15, 2024

Wow, I didn't know about the extra types. I guess parse() is not exactly the opposite of format()...
Anyway a read-only property seems good!

from parse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.