ubuntu - How do I print the content of a .txt file in Python? -


i'm new programming (obviously) , advanced computer stuff in general. i've have basic computer knowledge, decided wanted learn more. i'm teaching myself (through videos , ebooks) how program.

anyways, i'm working on piece of code open file, print out contents on screen, ask if want edit/delete/etc contents, it, , re-print out results , ask confirmation save.

i'm stuck @ printing contents of file. don't know command use this. i've tried typing in several commands here latest i've tried , no code isn't complete:

from sys import argv  script, filename = argv print "who you?" name = raw_input()  print "what file looking today?" file = raw_input()  print (file)  print "ok then, here's file wanted."   print "would delete contents? yes or no?" 

i'm trying write these practice codes include as i've learned far. i'm working on ubuntu 13.04 , python 2.7.4 if makes difference. far :)

opening file in python reading easy:

f = open('example.txt', 'r') 

to in file, use read()

file_contents = f.read() 

and print contents, do:

print (file_contents) 

don't forget close file when you're done.

f.close() 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -