Jump to content

Script Editor Auto Indent


tbexon

Recommended Posts

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:

2039456784_vectorscriptexample.thumb.png.9486e1614fa7cedaa1005b0e2ef7b251.png

 

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


 

 

 

Link to comment

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 by Nicolas Goutte
Link to comment
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?

 

Link to comment
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.

 

 

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...