Python Forum
Can the comments produce errors in python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can the comments produce errors in python?
#9
(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
Reply


Messages In This Thread
RE: Can the comments produce errors in python? - by newbieAuggie2019 - Nov-21-2019, 01:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Algorithm for extracting comments from Python source code Pavel1982 6 746 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  Produce One file Per PurchaseOrder jland47 1 415 Jan-26-2024, 11:38 AM
Last Post: Larz60+
  When does Python detect Errors? stamp1t 1 513 Oct-21-2023, 05:53 PM
Last Post: deanhystad
  How do I add comments from a text-file to an array of folders? clausneergaard 2 1,880 Feb-08-2023, 07:45 PM
Last Post: Larz60+
  Inserting line feeds and comments into a beautifulsoup string arbiel 1 1,254 Jul-20-2022, 09:05 AM
Last Post: arbiel
  Using multiprocessing to produce objects for i in range lucasrohr 6 1,767 Feb-02-2022, 03:53 PM
Last Post: lucasrohr
  Delete multiple comments with a single API call (facebook) Ascalon 0 2,379 Dec-04-2021, 08:33 PM
Last Post: Ascalon
  Rmarkdown opened by python code - errors Rav013 0 2,156 Apr-27-2021, 03:13 PM
Last Post: Rav013
  How to make a bot in pycharm for youtube for automatically adding python comments kodek2222 1 2,161 Jan-21-2021, 12:47 PM
Last Post: Aspire2Inspire
  Python Request Errors PythonNoob1998 7 4,275 Jan-07-2021, 05:18 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020