Indentation on code under button when doing a runQuery

I have been going thru the manual and most likely not looking in the correct location, or maybe its not even possible being as I have not seen it listed in anyones code. I think the correct terminology is called indentation.

Under the way in which I know here is what the code would look like under a button:

fpmi.db.runQuery("select machine,serial,mech1,mech2, runtime, mechpg,shift from prodtrack where shift =1

Now as some of the more experienced people know some of these queries can get lengthy and sometimes you need to scroll your edit window left and right in order to see the whole query or code that has been written. What I am asking is if under the current version if there is a way to make the runQuery look like this:

fpmi.db.runQuery("select machine, serial mech1, mech2 runtime, mechpg shift from prodtrack where shift =1

I guess the best way to describe it is similar to the query you see when you use MS-SQL Studio Manager GUI. When I ever I try to split up the query on multiple lines I get the Lexical error message.

Currently I have one very large query that I have split up as follows but it does not look pretty and there is more than likely a much better way.

q1 = "machine, serial, mech1, mech2" q2 = "runtime, mechpg, shift" fpmi.db.runQuery("select %s,%s from prodtrack where shift = 1"%(q1,q2))

Hope I have made my point clear and have a great day.

You won’t have much luck breaking up your scripting like that since Python uses tab indentation. The expression language is a lot more forgiving there.

There are places where you can often simplify your code. For example, you might use the graphical query builder, you can often use “SELECT *”, etc. I prefer to deal with particularly nasty queries in an SQL frontend or sometimes use external text editors like textpad or UltraEdit.

My personal opinion is that the script editor in FactoryPMI is nice in that it supports line numbers and syntax highlighting. You also have the GUI builders, the playground, and the script modules. The only thing I can come up with on the wish list is text completion. I don’t think you’ll find a Python IDE/editor that supports random text indents like your example. It’s part of the language - that’s like allowing random curly braces in C++.

Hmm, I have been able to break up python script to improve readability all along. For instance:

for i in range(0,10):
	print (i, i+1,i+2,
	i+3,i+4,
	i+5)

And in cases where there aren’t brackets or parentheses to indicate code closure, you can use a back slash to indicate that python should continue on the next line:

for i in range(0,10):
	print 'fgfgf\
nmnmnm'

Am I missing something? Is it IDE specific maybe? I do this in SPE and FPMI.

Yes, the missing part is running a QUERY against a data source. SOme of the queries can get quite lengthy. When you do then in the SQL GUI it does the indents and makes it look nice. Sorry my typing did not come out as lined up as I would like. I guess my basic question comes down to when you are typing in a query does it all have to be on the same line or can it be over multiple lines?

The biggest reason for this is just to make it more simple to read. Lets say you have standard screen resolution 1024 x 768. And lets say when you open up the script editor you can have 50 characters before you need to use the horizontal slider. Now your query consiste of say 100 characters. The next time you have to come in and debug or change anything when you come across this code you would have to use the horizontal slider to see the entire query, where as if you could break the query up over multiple lines when writing in code. Well hopefully you see where I am going with this. It was more of a question about if it is possible to do.

[quote=“Step7”]Hmm, I have been able to break up python script to improve readability all along. For instance:

for i in range(0,10):
	print (i, i+1,i+2,
	i+3,i+4,
	i+5)

And in cases where there aren’t brackets or parentheses to indicate code closure, you can use a back slash to indicate that python should continue on the next line:

for i in range(0,10):
	print 'fgfgf\
nmnmnm'

Am I missing something? Is it IDE specific maybe? I do this in SPE and FPMI.[/quote]

Try typing your query as in my second example (with the ‘’), and it should work. Did you try that?

Thanks, Step7 - I wasn’t thinking of valid ways of cleverly using tabs.

Actually, I learmed this from you. You had an example in some paint component code where you defined a transformation matrix using four lines so the matrix looked “right”, and I have been doing it that way ever since when it made sense. The indent and tabs don’t seem to matter at all, but I still use them to make it more readable.

That’s correct - as long as you’re consistent on the “depth” of indenting. You can’t just randomly make Christmas trees in your code without meaning to :open_mouth: .

As far as I can tell, it doesn’t care about indenting either. I tried some code below that mixes spaces and indents, and nothing seems to break it. You can pretty much format the code anyway you want as long as the first character of a new instruction follows the rules (not that it’s a good idea).

a = [1,2,3,
3,4,
  23, 61, 	56,
1,
7,
        9]
print a

for i in\
range(6,10):
	print
i