0

When i create and write in a text file using the python code below, it executes successfully. However, when i open the text file, it does not show anything written in it!

newl=[]
    print ""
    while 1:
        tks=raw_input("# ")
        if tks=="/":
            text=''.join(newl)
            print text
            filen=open('c:/Users/Admin/Desktop/snickcode.txt', 'w')
            filen.write(str(text))
            filen.close
            print "#saved to desktop, please rename the file before reuse"
            print "{non}"
            print ""
            break
        else:
            gig=(str(tks))
            newl.append(gig)
            print newl
2
  • 1
    You already have print text before the file is written. Does it display anything? Also, if nothing is written to the file, how can you say "it executes successfully"? Sounds like it's broken to me! Commented Mar 26, 2014 at 6:49
  • You only write to the file if the input is '/'. And you are just writing an empty string. If your input is different it will only append to the list but will not write to the file. Commented Mar 26, 2014 at 6:56

1 Answer 1

1

I assume / is the first input you tried. Because this

text=''.join(newl)
...
filen.write(str(text))

is what you write you the file and

newl=[]

doesn't contain any items at that point, the contents of the file remain 'empty'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.