tbexon Posted November 15, 2019 Share Posted November 15, 2019 Hi So I've been writing some basic scripts in python script and an issue I keep on having is the script editor Auto Indenting lines of my code. for instance : if a == 15: symbolType = vs.GetSymName(h) # Get Symbol Name #symbolTypesList.append(DeviceList) # Add it to Global Device Type List recName = vs.GetName(vs.GetRecord(h,1)) # Get the name of the first record attached print(recName) if recName == "Switch": obviously this has the incorrect number of indents, however in the script editor it appears fine: Is there a setting i'm missing somewhere where I can turn this off? Or is there something obvious i'm doing wrong? I've tried copy and pasting the code into IDLE fixing the indentations and then copying it back but it still auto "corrects" it. Thanks Tom Quote Link to comment
Nicolas Goutte Posted November 18, 2019 Share Posted November 18, 2019 (edited) I am not sure what you mean. Assuming that the first code has not been corrupted by this forum, you have your code indented by tabs. So it is 4 spaces width in the VW code editor but much larger displayed in this forum. Indenting with tabs is allowed in Python, even if not recommend. As for how to change it in VW, I do not think it is possible. (The VW code editor has just the basic tools to edit code.) Edited November 18, 2019 by Nicolas Goutte Quote Link to comment
tbexon Posted November 18, 2019 Author Share Posted November 18, 2019 9 minutes ago, Nicolas Goutte said: Assuming the fist code has not been corrupted by this forum, you have your code indented by tabs. So it is 4 spaces width in the VW code editor but much larger displayed in this forum. The first code hasn't been corrupted by the forums, that's exactly what I get if I copy and paste the code in the Screenshot out of the script editor, into either a text editor or IDLE. 10 minutes ago, Nicolas Goutte said: Indenting with tabs is allowed in Python, even if not recommend. What would you use to indent the code instead of Tabs? I've managed to get it working, by going through each line of code deleting all the indents and having to press return from the line above allow it to do it's auto indent thing, and then modify it from there, however it is still a very frustrating way to program, and i'm curious if i'm doing something wrong here or if other people have had this issue? Quote Link to comment
Nicolas Goutte Posted November 18, 2019 Share Posted November 18, 2019 23 minutes ago, tbexon said: The first code hasn't been corrupted by the forums, that's exactly what I get if I copy and paste the code in the Screenshot out of the script editor, into either a text editor or IDLE. What would you use to indent the code instead of Tabs? Python recommends using 4 spaces: https://www.python.org/dev/peps/pep-0008/#indentation However the most important in Python is to avoid mixing spaces and tabs, as mixing is the way to get discrepancies between what the human sees and the Python interpreter understands. (Python is picky on indentation.) 23 minutes ago, tbexon said: I've managed to get it working, by going through each line of code deleting all the indents and having to press return from the line above allow it to do it's auto indent thing, and then modify it from there, however it is still a very frustrating way to program, and i'm curious if i'm doing something wrong here or if other people have had this issue? I have checked quickly (on VW 2020): indenting works for me, if I use tabs or spaces. Of course be careful to set the VW code editor to "Python" *before* you edit any Python code in the windows or you risk mismatches. As you use IDLE, here two tips: - use Run/Check module (Alt-X) to be sure that the indentations are right - Edit/Tabify Region or Edit/Untabify Region. can help you in case you have to correct the indentation. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.