Nov-20-2019, 12:58 PM
Hi!
I'm attaching the outputs of my little programs at the end of the code, as comments, to see quicker what the program does, and also to include ideas, variations, possible errors, etc. to improve my knowledge, and I have just found something that I find strange.
This program runs fine:
All the best,
I'm attaching the outputs of my little programs at the end of the code, as comments, to see quicker what the program does, and also to include ideas, variations, possible errors, etc. to improve my knowledge, and I have just found something that I find strange.
This program runs fine:
import re string1 = 'Agent Cheesecake was a double agent.' agentNamesRegex = re.compile(r'Agent (\w)\w*') mo0 = agentNamesRegex.sub(r'\0**', string1) print(f"This is string1 '{string1}' with r'\0**' after censorship: {mo0}\n")and produces the following output:
Output:This is string1 'Agent Cheesecake was a double agent.' with r' **' after censorship: ** was a double agent.
>>>
But if I attach the output as comments at the end of the code, and I run the new program with the comments again:import re string1 = 'Agent Cheesecake was a double agent.' agentNamesRegex = re.compile(r'Agent (\w)\w*') mo0 = agentNamesRegex.sub(r'\0**', string1) print(f"This is string1 '{string1}' with r'\0**' after censorship: {mo0}\n") ##Output: ## ##This is string1 'Agent Cheesecake was a double agent.' with r' **' after censorship: ** was a double agent. ## ##>>>it produces the following
Error:Syntax error: source code string cannot contain null bytes.
I thought that the comments couldn't produce errors, as I thought once the signs ## were found, python took everything else as comments, and did nothing about what there was inside those comments. Am I wrong? How can the comments produce an error?All the best,