On Tue, 17 Sep 2019 16:51:04 -0400 Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote:
> On 9/17/19 2:59 PM, Manfred Lotz wrote: > > > def regex_from_filepat(fpat): > > rfpat = fpat.replace('.', '\\.') \ > > .replace('%', '.') \ > > .replace('*', '.*') > > > > return '^' + rfpat + '$' > > > > As I don't want to have the replace() functions in one line my > > question is if it is ok to spread the statement over various lines > > as shown above, or if there is a better way? > > Is that way okay? Sure. Are there other ways? Sure. > > To isolate each replace() function on its own line, and to eliminate > the clutter of the backslashes, consider this: > > rfpat = (fpat > .replace('.', '\\.') > .replace('%', '.') > .replace('*', '.*') > ) > > "Better" is going to depend on your initial reason for not wanting all > those function calls on one line. What is that reason? Well, I don't want those functions on a single line because having them multiline the code looks clearer. I asked here because I don't like the backslashes. Wrapping them in () looks like a good solution. -- https://mail.python.org/mailman/listinfo/python-list