Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python indent question
#1
Hello. I am pretty new to Python and I've found something that is probably pretty simple but eludes me. The problem concerns enclosing existing code in a new loop structure.

I come from a Java background. One of the things I do all the time in Java is build a small section of code for testing and debugging purposes. When I have it clean I do a cut/paste into a loop (if-then,while,for,etc) where it will be called from. The nice thing about my Java IDE is that when I do a cut/paste it automatically corrects the indentation.

I've been developing my Python in Spyder, which does have Source-->Fix Indentation option, but when I cut/paste some sections of code it doesn't "fix" them correctly. My suspicion is that in Java this indentation fix is easier because of the enclosing brackets that clearly delineate the boundaries of the enclosing structure, whereas in Python it seems as though the indentation is the only delineation.

So my question is, is there a way to mark with brackets or some such the beginning and end of a section so that it would be possible to cut/paste code into it and have the editor recognize the edges?

Thanks!
Reply


Messages In This Thread
Python indent question - by iicveji - Oct-20-2017, 04:40 PM
RE: Python indent question - by ichabod801 - Oct-20-2017, 04:50 PM
RE: Python indent question - by iicveji - Oct-21-2017, 03:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  getting unexpected indent errors trying to move cells up jensengt 4 921 Jun-28-2023, 12:05 PM
Last Post: deanhystad
  xml indent SubElements (wrapping) with multiple strings ctrldan 2 1,556 Jun-09-2023, 08:42 PM
Last Post: ctrldan
  IndentationError: unexpected indent dee 3 2,393 May-02-2022, 02:15 AM
Last Post: dee
  Avoid multiple repeat in indent Frankduc 8 2,945 Jan-18-2022, 05:46 PM
Last Post: Frankduc
  IndentationError: unexpected indent jk91 1 2,410 Feb-27-2020, 08:56 PM
Last Post: buran
  could not fix unexpected indent Bayan 1 3,236 Nov-08-2019, 01:45 PM
Last Post: ichabod801
  unable to indent json data dataplumber 4 3,066 Oct-22-2019, 01:55 PM
Last Post: dataplumber
  IndentationError: unexpected indent (Python) segs 8 17,419 Aug-11-2017, 03:13 PM
Last Post: segs

Forum Jump:

User Panel Messages

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