python help

Page 1 of 1

1 Replies - 231 Views - Last Post: 04 August 2014 - 12:15 PM Rate Topic: -----

#1 reptile guy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 17-May 14

python help

Posted 04 August 2014 - 12:00 PM

I have gotten Learning python the hard way, by Zed Shaw. I am having a little trouble with exercise 20. I have done everything correctly, the code runs perfectly. I just don't know what each line does, for example, what does "from sys import argue"
from sys import argv

script, input_file = argv

def print_all(f):
	print f.read()

def rewind(f):
	f.seek(0)

def print_a_line(line_count, f):
	print line_count, f.readline()

current_file = open(input_file)

print "First let's print the whole file:\n"

print_all(current_file)

print "Now let's rewind, kind of like a tape."

rewind(current_file)

print "Let's print three lines:"

current_line = 1
print_a_line(current_line, current_file)

current_line = current_line + 1
print_a_line(current_line, current_file)

current_line = current_line + 1
print_a_line(current_line, current_file)

could someone please try to explain what each line does. Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: python help

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: python help

Posted 04 August 2014 - 12:15 PM

You should take a step back in your book. If you do not know what an import statement does, you are not ready for things like functions. Take it slower and take notes as you go along. When your book tells you what the import means, you should make notes. With that in mind, I'd say you're not ready for the answers to these questions.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1