Skip to content
Advertisement

Why is idle skipping over f = open(‘filename’ , ‘r’)

I’m writing a program in python and I am having issues getting idle to read my file out. If I use improper syntax it tells me, so it is being read by the compiler but not printing it for the user. Any help would be appreciated. Here is my code.

#! python3.5.2

import sys

if input() == ('im bored'):
    print('What season is it?')
    if input() == ('summer'):
       f = open('callfilesummer.txt', 'r')

Advertisement

Answer

You only put file into variable ‘f’, so you need to read it or work it with someway to show it.

import sys

if input() == ('im bored'):
    print('What season is it?')
    if input() == ('summer'):
       f = open('callfilesummer.txt', 'r')
       print f.read()
       f.close()

You can find more way how to work with files on this http://www.tutorialspoint.com/python/python_files_io.htm

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement