I'm trying to write scripts for PSPad in Python. Unfortunately, I found that
globals variables of several scripts clash each with other. Probably because all
scripts executed in the same global namespace.

How to reproduce:

Create 2 python scripts in \Program Files\PSPad
Editor\Script\Python.AXScript.2\

file a.py with content:
========================================================
module_name = "a.py"
module_desc = "Description of a"
module_ver = "1"
pspad = globals()['global']

def Init():
    pspad.addMenuItem('About a.py', '', 'about')

def about():
    pspad.echo(
        ("a.py\n"
        "Description: %s\n"
        "Version: %s\n") % (module_desc, module_ver))
========================================================

file b.py with content:

========================================================
module_name = "b.py"
module_desc = "Description of b"
module_ver = "2"
pspad = globals()['global']

def Init():
    pspad.addMenuItem('About b.py', '', 'about')

def about():
    pspad.echo(
        ("b.py\n"
        "Description: %s\n"
        "Version: %s\n") % (module_desc, module_ver))
========================================================

Now save files and compile scripts.
In the Script menu there should be 2 menu items: "About a.py" and "About b.py".

Run "About a.py" and got output:

---------------------------
Info
---------------------------
b.py
Description: Description of b
Version: 2

---------------------------
OK   
---------------------------


As you can see actually executed function about() from b.py and with all global
variables from b.py.

For me it's serious enough bug to not writing scripts in Python for PSPad at
all. Because I don't think that creating unique names for different plugins is
good idea. It's exact antithesi of main Python idea of having separate
namespaces for different programs. Unfortunately PSPad breaks namespaces idea.
It's not appropriate. It's means that only one python script could be used on
any given machine.

-- 
<http://forum.pspad.com/read.php?4,43403,43403>
PSPad freeware editor http://www.pspad.com

Odpovedet emailem