Python Forum
Why can I not see the code correctly in Python IDLE.?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why can I not see the code correctly in Python IDLE.?
#1
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:
[Image: view?usp=sharing]
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?
Reply
#2
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 arcpy
You should not use Python 2.7, use a current version of python.
Reply
#3
I posted something here but i want to delete it. Can I delete a post here?how?
Reply
#4
# 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.
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
Note the lack of a comment character in outfc = arcpy.GetParameterAsText(1)
Reply
#5
(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.

The error message told you where the error happened.
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
Note the lack of a comment character in outfc = arcpy.GetParameterAsText(1)

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?
Reply
#6
Access denied on viewing the image.
Reply
#7
(Mar-11-2024, 05:16 AM)deanhystad Wrote: Access denied on viewing the image.

Sorry about it. This should work, hopefully:
[Image: KNL6Pjp]
Reply
#8
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=...ight=image
Reply
#9
(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.

The error message told you where the error happened.
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
Note the lack of a comment character in outfc = arcpy.GetParameterAsText(1)

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»
Gribouillis write Apr-04-2024, 08:31 AM:
Spam link removed, please read this
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  hi need help to make this code work correctly atulkul1985 5 801 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  Launch Python IDLE Shell from terminal Pavel_47 5 1,264 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Python Idle won't start totalmachine 9 3,546 Oct-16-2022, 05:57 PM
Last Post: totalmachine
  Why is IDLE not opening on a MacOS Montery 12.6 and using Python 3.10.7? Merlin385 7 1,724 Oct-08-2022, 08:36 PM
Last Post: Merlin385
  Serializing Python data Correctly (JSON) JgKSuperstar 4 2,124 Nov-04-2021, 07:31 PM
Last Post: JgKSuperstar
  MAC Python IDLE issue shadow12 4 2,570 Oct-29-2021, 12:22 AM
Last Post: shadow12
  Python MYSQL connection does not work after 1h idle zazas321 9 6,854 Oct-07-2021, 12:02 PM
Last Post: ndc85430
  Customize Python Keywords for IDLE alanvers 0 2,005 Apr-03-2021, 10:56 AM
Last Post: alanvers
  Sublime Text + Anaconda not indenting Python code correctly Maxximiliann 0 2,006 Jun-13-2020, 06:09 PM
Last Post: Maxximiliann
  vs code interpreter vs IDLE feature tsmspace 4 4,232 Apr-01-2020, 10:45 PM
Last Post: kiliman13

Forum Jump:

User Panel Messages

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