Jump to content
  • Advertisement
Sign in to follow this  
koka282

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

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

i can't understand everything

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)
Edited by koka282

Share this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
Share on other sites

I'm learning from (python the hard way)

Exercise 20: Functions and files

Edited by koka282

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

i do something like what you say Lysy smile.png

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

functions and files working together biggrin.png

Thank you :)

Share this post


Link to post
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 this post


Link to post
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 

need explain please smile.png

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!