[Tutor] text editor problems

alan.gauld@bt.com alan.gauld@bt.com
Mon, 22 Jan 2001 13:16:17 -0000

> def save(): 
>   if sname:
>     open sname and write to it
>   elif oname:
>     open oname and write to it
>   else:
>     saveas()

Here you are referencing a global variable sname, oname etc.

> def saveas():
>   sname = asksaveasfile
>   blah blah

Here you are setting a local variable visible only within 
the saveas function. Tus the save function cannot see it.

> Then it gives me the error: No variable named sname exists.

You need to create the sbame variable outside the functions 
and then declare it as global inside saveas.

This is all explained in my tuorial at:


under Namespaces

> I can't figure it out, and I've tried changing it to:
> if oname != "":
> elif sname != "":

As explained above the variables don't exist so you can't 
compare them to anything yet!


Alan G.