Python's file.read()
function won't read anything. It always returns ''
no matter what's inside the file. What can it be? I know it must be something straightforward, but I can't figure it out.
UPD: I tried with 'r' and 'w+' modes.
UPD: The code was:
>>> file = open('helloworld', 'w+')
>>> file.read()
''
Solution: It just came to me that, although a file is available for reading in 'w+' mode, Python truncates it after opening. 'r' (or 'r+') mode should be used instead. Thanks everyone.