The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by iri]

Hello, I've got a problem with a sentence of a program that worked perfectly
and now doesn't. The sentence is this:

namenul=name[:-4]+'N.IN' #name=FICH.IN2 and I want namenul be FICHN.IN
fnul=open(namenul,'w')

This fnul is an output file in which it will be written some information I
need (I use, fnul.write(infomation to be written) ) but now, I can´t get that
information because this file is not created, simply appears on the screen.
I tried some other extensions such as:

namenul=name[:-4]+'NIN' --> it works
namenul=name[:-4]+'N'+'.IN' --> it doesn't work

I think that there's some kind of problem with that "."!! (But before there
wasn't... And I haven´t changed anything!)

Can anyone help me?
Thank you very much.
import-bot (20211) [Avatar] Offline
#2
Re: Can anyone help me with something that worked perfectly.. now doesn't?!
[Originally posted by daryl d harms]

Hi Irantzu,

Your code appears that it should work, i.e.:
>>> name="FICH.IN2"
>>> namenul=name[:-4]+'N.IN'
>>> namenul
'FICHN.IN'
>>> fnul = open(namenul,'w')
>>> fnul.write("write to file"smilie
>>> fnul.close()

The only things I can think that you might want to check:
(1) is whether the file FICH.IN already exists in the current working
directory and if so if the process your program has permission to access it.

or
(2) whether you have opened this file to write in some other part of the
program and not yet closed it by the time this piece of code runs.

Daryl