Public Group

# Help me, i can't understand well :)

This topic is 1431 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

Please ,Help me i can't understand the code well

i can't understand everything

from sys import argv

script, input_file = argv

def print_all(f):

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

def print_a_line(line_count, f):

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)

Edited by koka282

##### Share on other sites

I'm not the best person to answer the question, but I don't even know what you're asking.

-Did you see this group of code, and don't know what it means?

-Are you writing something, and this is not working?

##### Share on other sites

I'm learning from (python the hard way)

Exercise 20: Functions and files

Edited by koka282

##### Share on other sites

i wrote it the topic & i continue trying to to understand it i was going to see at night my understanding was right or not but now i i think i understand i take long time to understand but i think that's not problem right ?&i will try to write the code with myself it will be hard but i will write it :)

##### Share on other sites

Yep. You should take it slow. There is no hurry.

i wrote it the topic & i continue trying to to understand it i was going to see at night my understanding was right or not but now i i think i understand i take long time to understand but i think that's not problem right ?&i will try to write the code with myself it will be hard but i will write it

Best way to be sure, that you understand a piece of code, is to modify it, so it does something different. If it does what you thought it would do, you can assume that you understand that particular piece of code.

##### Share on other sites

i do something like what you say Lysy

i think i understand now but i will try to write it with myself it will be hard

functions and files working together

Thank you :)

seek()

##### Share on other sites

Your question is still very vague. Do you understand what seek is supposed to do? Do you understand the purpose of rewind, and why it is implemented as it was?

##### Share on other sites
def rewind(f):
f.seek(0) 

can you explain ??

if i didn't type it i can print the file again why !?

it close the file or what

current_line = 1
print_a_line(current_line, usingfil)

current_line = current_line + 1
print_a_line(current_line, usingfil)

current_line = current_line + 1
print_a_line(current_line, usingfil)


if current line = 2

it print the second line how ???!!!!!!!

Edited by koka282

1. 1
Rutin
23
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631757
• Total Posts
3002150
×