Posts: 4,647
Threads: 1,494
Joined: Sep 2016
is there any case where a line of code that begins with a decimal number expressed as a run of digit characters can be valid Python code in Python3? if i have some logic that removes such numbers (only) from the start of each line, would such logic corrupt or damage the Python code it is processing?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,790
Threads: 76
Joined: Jan 2018
May-07-2024, 05:52 AM
(This post was last modified: May-07-2024, 05:52 AM by Gribouillis.)
(May-07-2024, 05:40 AM)Skaperen Wrote: is there any case where a line of code that begins with a decimal number expressed as a run of digit characters can be valid Python code in Python3?
These lines are valid python code if that's what you mean
232444
7663 + 12333
87633 >> x
Does your preprocessor remove these lines?
>>> class A:
... def __rrshift__(self, n):
... print('Hello', n)
...
>>> a = A()
>>> 1876 >> a
Hello 1876
« We can solve any problem by introducing an extra level of indirection »
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
it looks like i need to use a scheme with something other than just a number, such as maybe a number followed by something such as ":". i want to be sure this containment scheme cannot ever look like valid Python code. for example, an alternate test would be to test if the whole line is valid Python, to decide to remove the number (if valid, leave the line(s) unchanged). what i need is a string scheme such that decimal digits plus something at the start of a line always makes the line distinguishable from valid Python code so it can be decided that the scheme has been prepended to the line.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,790
Threads: 76
Joined: Jan 2018
May-08-2024, 06:25 AM
(This post was last modified: May-08-2024, 06:25 AM by Gribouillis.)
(May-07-2024, 10:17 PM)Skaperen Wrote: what i need is a string scheme such that decimal digits plus something at the start of a line always makes the line distinguishable from valid Python code
It won't be that easy, consider these examples using line continuation or multiline strings
>>> x = \
... 23
>>>
>>> if x == \
... 23:
... print('hello')
...
hello
>>> """What a great number
... 23:
... the best number ever!
... """
'What a great number\n23:\nthe best number ever!\n'
Why do you want to do this? It would be easier if
every line had such a number. That would remove ambiguity.
« We can solve any problem by introducing an extra level of indirection »
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
yeah, the multi-line literal will be a huge problem if i don't thoroughly parse all the Python code (including the multi-line literal and/or continuation). the original goal was mixing the Python code into something else. that thought came about from seeing the output of "cat -n". i'll have to totally re-think that concept.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.