On Fri, 25 Mar 2022 at 10:44, Avi Gross <avigr...@verizon.net> wrote: > But would it be helpful? Maybe. I am thinking back to decades ago when I > did C and C++ programming and how we used it. It was way more that just: > > #DEFINE TIMEZONE 5 > > The above use is sort of to create a constant. What we often used was ways > to customize the code so different code would be compiled say when testing > or to work one way on machine A with operating system A' versus machines > B and C, perhaps with different needs and abilities. Sometimes all kinds > of features only made it into one version of the other. The compiler saw > different code each time.
Yes, I'm aware of how it was used... but to what extent is that actually necessary in Python? When do you ever need something that you can't do with simple conditional function definition or something of the sort? Textual manipulation lets you create all manner of nightmares. A lot of them are acceptable evils because of the benefits gained, but you'd be hard-pressed to pitch those same benefits to Python programmers, where most of the differences are already handled by (eg) the functions in the os module. > I have also written many things that effectively are read by an early stage > and selected regions are parsed and replaced with code in another language > so that by the time a compiler or interpreter sees it, ... > > So sure, you could write code that reads fileA.py and outputs fileB.py and > only > run fileB through the interpreter. Yes, instead of making versions which have > all > kinds of text written in various languages, you could just have the python > code > read in various files at run time or other techniques. And that's what I meant by having your own preprocessor. I've done various DSLs that way, having something that effectively compiles to Python code. (I've also used Python to write preprocessors for things in other languages, since Python is excellent at text manipulation and even has things like JavaScript lexers available on PyPI.) But the best of these are NOT things that the C preprocessor would be capable of. They can have arbitrarily complex levels of syntactic comprehension, making them far safer to work with. ChrisA -- https://mail.python.org/mailman/listinfo/python-list