ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> edu-sig
edu-sig
[Edu-sig] Working interactively with IDE (refreshing script; namespace updating)
by Christopher Smith other posts by this author
Aug 5 2001 7:49PM messages near this date
[Edu-sig] Re: [Pythonmac-SIG] Working interactively with IDE (refreshing script; namespace updating) | [Edu-sig] PythonScript
After reading the "Up All Night with IDLE" thread
http://mail.python.org/pipermail/tutor/2001-January/003082.html
and seeing the post by Patrick regarding "Refreshing a script"
I came up with the following way to work with IDE:

The problem:

	When you are working on a script in a window and you make
	changes to an object (variable, function, etc...) name, 
	the old object still exists.  This means that you will not
	always get an "is not defined" error even though you would if
	you quit and tried to run your script after restarting IDE.

Example:
 
 ORIGINAL

	x=2
	print "x=",x

 MODIFIED

	y=1
	print "y=",x ## <--forgot to change the 2nd x

	# the modified program will print "y= 2" -- even
	# though the x variable is undefined in the script it is 
	# still remembered by Python in this IDE window and
	# that is what you told it (inadvertently) to print.

A solution:

	Work with two scripts, one to load your active work and one
	containing your developing script:

	# tester.py (this just loads and reloads your work)
	import mywork
	reload(mywork)
	mywork.testmywork()


	# mywork.py (this is the one that will contain your work
	def testmywork():
		x=2
		print "x=",x

	When you make changes to "mywork.py" and *save* these changes and
	then run the "tester.py" program as written, you work in "mywork"
	will be reloaded and if you have a modification like shown above,
	you will generate an error since x is not defined.

	When your scipt runs as you want it to, copy the text of "mywork.py",
	delete the first line, and unindent one level and save under a new
	name.

The one-best-solution (IMO):

	IDE would automatically do this sort of thing with a script that is being
	run --not in the interactive window which prompts you with 
	the "> >>" but in the script windows that are created and used to write 
	new scripts.

/c


_______________________________________________
Edu-sig mailing list
Edu-sig@[...].org
http://mail.python.org/mailman/listinfo/edu-sig

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved