[Tutor] Writing to a file/changing the file name
bob gailer
bgailer at gmail.com
Thu Feb 23 17:57:05 CET 2012
On 2/23/2012 12:04 AM, Michael Lewis wrote:
> Hi everyone,
>
> I have a program where I open a file (recipe.txt), I read that file
> and write it to another file. I am doing some multiplying of numbers
> in between; however, my question is, when I name the file I am writing
> to, the file extension is changed, but the file name is not. What am I
> doing wrong?
Christian gave you the answer (he "fished" for you)
How to "fish" for yourself:
Before posting a question do a walkthru of the program.
This means pretending you are the Python interpreter and your job is to
execute the program step-by-step, writing down the effect of each statement
You will find many answers yourself this way, saving all of us time and
energy.
in the above case take the statement new_file_name = file_name + '2'
and do this:
file_name is "recipe.txt"
file_name + '2' is <here you pretend to be the interpreter and answer
the question what is "recipe.txt" + 2>
If you come up with anything other than "recipe.txt2" then you need to
review how Python works.
Another idea is: when you get an unexpected result there must be a very
good reason for it. Do a little hunting. Each time you solve a problem
for yourself you get stronger.
HTH
--
Bob Gailer
919-636-4239
Chapel Hill NC
More information about the Tutor
mailing list