Tip about Python Script

Help bring our custom Ages to life! Share tips and tricks, as well as code samples with other developers.

Tip about Python Script

Postby andylegate » Wed Jan 30, 2008 4:49 am

Just wanted to add this. I was going to put in on the Wiki, but then stopped and though, where? We don't have a tutorial on Python, and I'm NOT qualified to write one for it! :D

However, I helped discover something that can trip you up, and wanted to warn others:

When you are reading the forum, and someone has provided scripting for Python on here like in the code box below, it is best to NOT use the "Select All" feature to copy and paste it into your editing program. For some reason, programs like PlasmaShop, when you do with, will automatically indent all the lines!

This will result in syntax error, or other problems.

example:
Code: Select all
######################################
#                                    #
#  Dynamic Book Template by D'Lanor  #
#                                    #
######################################
from Plasma import *
from PlasmaTypes import *
from PlasmaNetConstants import *
import xLinkingBookDefs
import __Campbravo__PageDefs
actClickableObject = ptAttribActivator(1, 'Act: Clickable Object')
ObjectMsg = ptAttribString(2, 'Object String')
AgeStartedIn = None
ourBook = None
bkLinks = []


Instead, MANUALLY select the code using your mouse and keyboard, then copy and paste it into your program. The auto indent will not happen then.

I don't know why this is, nor others. But it did cause me a lot of hair pulling. You would think we'd notice it right away, but it was actually over looked for a while.

Hope this helped.
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

Re: Tip about Python Script

Postby Robert The Rebuilder » Wed Jan 30, 2008 10:11 am

Andy:

I'm using PlasmaShop 2.2.2. When I click on the "SELECT ALL", hit Ctrl-C to copy, then paste into an open Python file in PlasmaShop, I don't get the indent that you see - no matter where my insertion point is in the Python file.

Perhaps it is a configuration issue? For example, do you have an editor specified for Python code? And what are the settings on the Editor tab of your Options dialog? [You could paste a screenshot of the dialog instead of typing up all the flag settings.]
Can we rebuild it? Yes, we can - here's how.

MOULagain KI# 1299

Myst Movie coming soon - spread the word!
User avatar
Robert The Rebuilder
 
Posts: 1383
Joined: Sat Sep 29, 2007 7:24 am
Location: Virginia, US

Re: Tip about Python Script

Postby andylegate » Wed Jan 30, 2008 10:31 am

No external editor is selected.

I went to the options and the edit tab.

I saw a check mark in the Auto Indent and though "Hey! There we go!" but that didn't change anything (I think that's for when you're writing script, when you hit enter, it will auto indent if you need it on the next line).

Anyway, real quick, as I'm going to be gone for the next hour and half running errands (don't have time for a screen shot, I type 120 wpm, faster)

all the following have check marks

Code Folding
Line Numbers
Selection Margin

Insert Tabs as Spaces
Auto Indent

Indention Guides
Long Line marker

Tab Width = 4
Long Lines = 80
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

Re: Tip about Python Script

Postby Trylon » Wed Jan 30, 2008 11:00 am

Another tip:

Never ever use tab-characters in python code.
Only use spaces!

If you don't it will probably mess up the indentation sooner or later.
One day I ran through the cleft for the fiftieth time, and found that uru held no peace for me anymore.
User avatar
Trylon
 
Posts: 1446
Joined: Fri Sep 28, 2007 11:08 pm
Location: Gone from Uru

Re: Tip about Python Script

Postby D'Lanor » Wed Jan 30, 2008 12:29 pm

I never use tabs and the forum still messes up my Python code using SELECT ALL. What happens I think is that SELECT ALL also selects the indentation of the code box it is in. This is a common problem with copy / pasting from browsers.

btw, I use UltraEdit which is the best text editor around so it does not add anything that isn't there.
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Tip about Python Script

Postby Chacal » Wed Jan 30, 2008 1:30 pm

UltraEdit is hard to beat. I couldn't live without it.
Chacal


"The weak can never forgive. Forgiveness is an attribute of the strong."
-- Mahatma Gandhi
User avatar
Chacal
 
Posts: 2508
Joined: Tue Nov 06, 2007 2:45 pm
Location: Quebec, Canada

Re: Tip about Python Script

Postby Robert The Rebuilder » Wed Jan 30, 2008 1:40 pm

Andy and D'Lanor: what browser are you using? I'm using IE v7, and I don't get the indent when I "SELECT ALL".
Can we rebuild it? Yes, we can - here's how.

MOULagain KI# 1299

Myst Movie coming soon - spread the word!
User avatar
Robert The Rebuilder
 
Posts: 1383
Joined: Sat Sep 29, 2007 7:24 am
Location: Virginia, US

Re: Tip about Python Script

Postby andylegate » Wed Jan 30, 2008 2:48 pm

Mozilla Firefox is what I'm using.......

Let me try something.....

Code: Select all
# emacs-mode: -*- python-*-
from Plasma import *
from PlasmaTypes import *
from PlasmaNetConstants import *
from xPsnlVaultSDL import *
import math
import time


and

Code: Select all
# emacs-mode: -*- python-*-
from Plasma import *
from PlasmaTypes import *
from PlasmaNetConstants import *
from xPsnlVaultSDL import *
import math
import time
"I'm still trying to find the plKey for Crud!"
Image
Blender Age Creation Tutorials
3DS Max Age Creation Tutorials
User avatar
andylegate
 
Posts: 2348
Joined: Mon Oct 01, 2007 7:47 am

Re: Tip about Python Script

Postby D'Lanor » Wed Jan 30, 2008 3:34 pm

I am also using a Mozilla based browser. Not Firefox but Netscape (yeah, call me nostalgic).
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Tip about Python Script

Postby Trylon » Wed Jan 30, 2008 3:35 pm

Firefox gives me an indent as well, Andy...

When I switch to IE7, it doesn't indent...
One day I ran through the cleft for the fiftieth time, and found that uru held no peace for me anymore.
User avatar
Trylon
 
Posts: 1446
Joined: Fri Sep 28, 2007 11:08 pm
Location: Gone from Uru

Next

Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests