Repository: r1chardj0n3s/parse

Issue:
Allow using a Parser as a formatter
I think it would nice and elegant if the same object could be used both as a formatter and a parser. This can be achieved by adding a `format` method:
```python
>>> p = compile("It's {}, I love it!")
>>> p.parse("It's spam, I love it!")
<Result ('spam',) {}>
>>> p.format('spam')    # <----  This is the new suggested method
"It's spam, I love it!"
```

Granted, one could simply hold on to the original string and use that, but I think it's useful if we only needed the Parser object for both of these. For example, if you pass the Parser as an argument to a function, currently you need to pass the format string as well, otherwise you have to access the internal `_format` field.
At the very least, we should have a `get_format` method to retrieve the internal `_format` field.

Another reason is that if we are using two different objects for formatting and for parsing, it increases the chance that someone creates a bug by changing one of the objects and forgetting to change the other one.

Discussion:

Patch:
diff --git a/parse.py b/parse.py
index 474dd68..2e6c2c2 100644
--- a/parse.py
+++ b/parse.py
@@ -482,6 +482,10 @@ class Parser(object):
     def fixed_fields(self):
         return self._fixed_fields.copy()
 
+    @property
+    def format(self):
+        return self._format
+
     def parse(self, string, evaluate_result=True):
         """Match my format to the string exactly.
 


Test patch:
diff --git a/tests/test_parse.py b/tests/test_parse.py
index dcb4a12..69d35dd 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -739,3 +739,10 @@ def test_strftime_strptime_roundtrip():
     s = dt.strftime(fmt)
     [res] = parse.parse("{:" + fmt + "}", s)
     assert res == dt
+
+
+def test_parser_format():
+    parser = parse.compile("hello {}")
+    assert parser.format.format("world") == "hello world"
+    with pytest.raises(AttributeError):
+        parser.format = "hi {}"