Why can I not see the code correctly in Python IDLE.? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Why can I not see the code correctly in Python IDLE.? (/thread-41740.html) |
Why can I not see the code correctly in Python IDLE.? - Trump - Mar-10-2024 I am using Python IDLE 2.7.18.4 on Windows 10. I copied a code from a pdf in my editor and made it as comments. The code look like this in my editor: but when I past the code here (in this forum), I see it correctly as I see some parts of the code are not as comments and thus I got an error: ##import arcpy ##infc = arcpy.GetParameterAsText(0) ## outfc = arcpy.GetParameterAsText(1) ## arcpy.Copy_management(infc, outfc)and I get this error: Traceback (most recent call last): File "D:/ArcPy_Ex/test.py", line 5, in <module> outfc = arcpy.GetParameterAsText(1) NameError: name 'arcpy' is not defined I wonder How I can see the code correctly in the Python IDLE editor? RE: how to fix an error in comments? - deanhystad - Mar-11-2024 You are getting an error because of line 4, not because of anything in the comments. If you want to do this: outfc = arcpy.GetParameterAsText(1)You need to first do this: import arcpyYou should not use Python 2.7, use a current version of python. RE: how to fix an error in comments? - Trump - Mar-11-2024 I posted something here but i want to delete it. Can I delete a post here?how? RE: how to fix an error in comments? - deanhystad - Mar-11-2024 # is the start of a line comment in Python. Everything following # in the line is a comment. Don't depend on syntax highlighting. The error message told you where the error happened. Note the lack of a comment character in outfc = arcpy.GetParameterAsText(1)
RE: how to fix an error in comments? - Trump - Mar-11-2024 (Mar-11-2024, 12:21 AM)deanhystad Wrote: # is the start of a line comment in Python. Everything following # in the line is a comment. Don't depend on syntax highlighting. Thanks for the reply. As I posted later (the image I posted, can it be seen? ), it is seen differently and I woder, now, how I can see the code in the Python IDLE like it is seen here? RE: Why can I not see the code correctly in Python IDLE.? - deanhystad - Mar-11-2024 Access denied on viewing the image. RE: Why can I not see the code correctly in Python IDLE.? - Trump - Mar-14-2024 (Mar-11-2024, 05:16 AM)deanhystad Wrote: Access denied on viewing the image. Sorry about it. This should work, hopefully: RE: Why can I not see the code correctly in Python IDLE.? - deanhystad - Mar-14-2024 How do you run your program? I don't know if the img tags work. Look here for instructions on how to attach a file. https://python-forum.io/misc.php?action=help&hid=35&highlight=image RE: Why can I not see the code correctly in Python IDLE.? - jonesphedra - Apr-04-2024 (Mar-11-2024, 12:21 AM)deanhystad Wrote: # is the start of a line comment in Python. Everything following # in the line is a comment. Don't depend on syntax highlighting. That right. To resolve this problem and see the code correctly in the Python IDLE editor, you need to ensure that the comments are properly formatted with a single '#' symbol at the beginning of each comment line. «spam link removed» |