[Python-ideas] Jump to function as an an alternative to call function
Chris Angelico
rosuav at gmail.com
Wed Aug 15 19:09:58 EDT 2018
On Thu, Aug 16, 2018 at 8:53 AM, Jacob Solinsky <jacobsolinsky at gmail.com> wrote:
> What I had hoped to do was use a preamble code block to collect all of the
> most common queries called by the mutate function in the local namespace,
> for example
>
> C = 'bpgkdtszSZjCmnywh'
> M = 'mn'
>
>
> class Morpheme:
> #stuff
>
> def preamble(self):
>
> ps = self.precedingmorpheme.form
> ss = self.succeedingmorpheme.form
> ssc = re.match(f'^[{C}]', self.succedingmorpheme.form) #Whether or not
> the following morpheme is consonant initial
> ssm = re.match(f'[{M}]$', self.precedingmorpheme.form) #Whether or not
> the preceding morpheme is nasal final
>
> these local variables are used quite often in the mutate methods, of which
> there are several dozen, so storing them by default saves a lot of typing.
>
Ahh, I see what you mean. I was thinking the other way - a single
mutate function that has a part in there saying "now run the code
block for this particular subclass".
What would be really nice would be something like:
from preamble() import *
I'm fairly sure that (per se) isn't going to fly, but it would be
interesting as a concept. Would need a new spelling.
The quirky part of my brain is trying to figure if class namespace can
be abused for this.
ChrisA
More information about the Python-ideas
mailing list