Nov-21-2019, 01:33 PM
(This post was last modified: Nov-21-2019, 01:33 PM by newbieAuggie2019.)
(Nov-21-2019, 10:35 AM)snippsat Wrote: The error happens before comments part.Thank you!
According to my multiple tries in IDLE, before adding the comments, it doesn't seem so. This program runs fine in IDLE:
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 in IDLE:
Output:This is string1 'Agent Cheesecake was a double agent.' with r' **' after censorship: ** was a double agent.
>>>
It is ONLY when I add that output as comments to the program in IDLE, and then I try to run the program with the comments, when the error message of null bytes is thrown back at me. Probably I'm not very good at explaining myself. I don't need/want to modify the program as it runs fine till I add the output as comments. THE ONLY THING THAT I WOULD LIKE TO KNOW IS WHY THE COMMENTS THROW BACK AN ERROR MESSAGE WHILE SUPPOSEDLY PYTHON DOESN'T READ INSIDE THE COMMENTS PRECEDED BY ##.Just to clarify a bit further, the original program to see differences in substitutions is:
import re string1 = 'Agent Cheesecake was a double agent.' agentNamesRegex = re.compile(r'Agent (\w)\w*') mo0 = agentNamesRegex.sub(r'\0**', string1) mo1 = agentNamesRegex.sub(r'\1**', string1) print(f"This is string1 '{string1}' with r'\0**' after censorship: {mo0}\n") print(f"This is string1 '{string1}' with r'\1**' after censorship: {mo1}\n")which also runs fine in IDLE, producing the following output:
Output:This is string1 'Agent Cheesecake was a double agent.' with r' **' after censorship: ** was a double agent.
This is string1 'Agent Cheesecake was a double agent.' with r' **' after censorship: C** was a double agent.
>>>
And it also runs fine till I add the output as comments to the program in IDLE (but before that, it runs fine). I only simplify the program to make the question of why those comments are read in IDLE and throw back an error message. I hope to have explained myself better now, sorry for not transmitting my doubt clearer before.All the best,
newbieAuggie2019
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs