Hack Forums
[Python] Sublime3 unexpected indent trickle affect - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Sublime3 unexpected indent trickle affect (/showthread.php?tid=5444378)



Sublime3 unexpected indent trickle affect - datguy.dev - Oct 25, 2016

Greetings,
I was curious if you guys had any tips about a Sublime setup when it comes to Python? Sometimes when I go run my code I get an unexpected indent error. It happens ... so I go check statements, tabs, and spaces.


The issue is when I 'fix' one line of code, the spaces or whatever, it affects the next line. I fix that next line, and it happens to the next line! It is quite frustrating. It doesn't matter if I start corrections from the top or below. I can select the text and see the spaces and tabs. They change as I make the corrections to other lines.


* - chefragoo7 - Oct 25, 2016

No tips about Sublime setup, but launching the script by:
Code
python -tt script.py

should solve the problem.


* - SpacePupper - Oct 25, 2016

Are you mixing tabs and spaces? Python can generally handle either, but not both.


* - bytez - Oct 26, 2016

Hi, i had this problem also, but i found the easiest trick for it.

In Sublime click, View->Indentation->Convert indentations to Tabs


* - datguy.dev - Oct 26, 2016

(Oct 25, 2016 10:05 PM)SpacePupper Wrote:  Are you mixing tabs and spaces? Python can generally handle either, but not both.

Not directly. I strictly use tabs, but somehow spaces get in there.

(Oct 26, 2016 04:59 AM)bytez Wrote:  Hi, i had this problem also, but i found the easiest trick for it.

In Sublime click, View->Indentation->Convert indentations to Tabs

Thanks. I think that'll help a bit. But I think it maybe more that my tab size was 4. I have to manually restructure about 10 scripts and thousands of lines of code just to fix the spacing. Find a replace doesn't fully do the job.


* - bytez - Oct 26, 2016

(Oct 26, 2016 11:34 AM)datguy.dev Wrote:  Not directly. I strictly use tabs, but somehow spaces get in there.


Thanks. I think that'll help a bit. But I think it maybe more that my tab size was 4. I have to manually restructure about 10 scripts and thousands of lines of code just to fix the spacing. Find a replace doesn't fully do the job.

I had the problem cause i copy pasted my script from pycharm, and the fix works all the time, it converts every line so i dont have to do it manually :)

How come you have to do manually when it does it auto? :D


* - datguy.dev - Oct 26, 2016

(Oct 26, 2016 01:18 PM)bytez Wrote:  I had the problem cause i copy pasted my script from pycharm, and the fix works all the time, it converts every line so i dont have to do it manually :)

How come you have to do manually when it does it auto? :D

The automatic indentation function you stated previously isn't correctly fixing all the indents. It'll randomly leave 4 spaces, in other areas in doesn't. It breaks statements, nested statements, and thus the flow of a script. So I have to do a logic check as well. meh. . . It is better than nothing.


* - bytez - Oct 26, 2016

(Oct 26, 2016 01:29 PM)datguy.dev Wrote:  The automatic indentation function you stated previously isn't correctly fixing all the indents. It'll randomly leave 4 spaces, in other areas in doesn't. It breaks statements, nested statements, and thus the flow of a script. So I have to do a logic check as well. meh. . . It is better than nothing.

Oh wierd, it works alright for me, but i dont have like 500 lines programs :D


* - datguy.dev - Oct 26, 2016

(Oct 26, 2016 02:07 PM)bytez Wrote:  Oh wierd, it works alright for me, but i dont have like 500 lines programs :D

Honestly, it is just messing up because of the current spacing issues in scripts. This is a good learning experience for me to setup before starting. Thanks for the suggestion. It saved me quite some time. 👍