[Tutor] mutable strings? [and global stuff]

alan.gauld@bt.com alan.gauld@bt.com
Mon, 26 Mar 2001 12:12:15 +0100


> semi-useful in the process.  I'm trying to write a 
> little script to use for interactively renaming files, 
> want to be able to navigate through my file system, 
> and I need some type of changeable string, so I can 
> keep track of where I am.   

I wonder if you are confusing variables and references/names?

You need a name that can point to several different strings.
You don't need to change the strings themselves you need to 
change which string the name points at.
eg

foo = "myfile.mp3"
# do some messing here
foo = "newfile.mp3"
# do more messing
foo = foo[:-3]+"txt" # change foo to store newfile.txt

Is that what you mean?
In the last line I didn't change the string "newfile.mp3"
but I did create a new string based on the original.

Does that meet your needs? Do you really need to change the original string?
Thats very unusual...

Alan G.