Python: Open file example 1
#!/usr/bin/python
han1 = open("davinder.txt","r")
print "\n\n"
print "If we give print han1 Then output would be", han1, "\n\n"
print "File is open only once"
print "Actual output should be like this so use han1.readline()", han1.readline(),"\n"
print "If you use han1.readline(10) Then it will print next 10 characters as in upper line already pritn upto first \n ", han1.readline(10)
print "If you use again han1.readline(10) then it will print next 10 character untill didnt get next line", han1.readline(10)
print "If you use han1.readline(15) then again print next 15 characters ", han1.readline(15)
print "------------------now start read()--------------------"
print "Now use han1.read()", han1.read()
Output:
[root@mysql Scripts]# ./file1.py
If we give print han1 Then output would be
File is open only once
Actual output should be like this so use han1.readline() [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
If you use han1.readline(10) Then it will print next 10 characters as in upper line already pritn upto first
I am a bes
If you use again han1.readline(10) then it will print next 10 character untill didnt get next line t player
If you use han1.readline(15) then again print next 15 characters I am the best p
------------------now start read()--------------------
Now use han1.read() layer
I am best player
I am an best player
I am a best player
I am a best player
I am a best player
I am a best player
I am a best player
I am a best player
han1 = open("davinder.txt","r")
print "\n\n"
print "If we give print han1 Then output would be", han1, "\n\n"
print "File is open only once"
print "Actual output should be like this so use han1.readline()", han1.readline(),"\n"
print "If you use han1.readline(10) Then it will print next 10 characters as in upper line already pritn upto first \n ", han1.readline(10)
print "If you use again han1.readline(10) then it will print next 10 character untill didnt get next line", han1.readline(10)
print "If you use han1.readline(15) then again print next 15 characters ", han1.readline(15)
print "------------------now start read()--------------------"
print "Now use han1.read()", han1.read()
Output:
[root@mysql Scripts]# ./file1.py
If we give print han1 Then output would be
File is open only once
Actual output should be like this so use han1.readline() [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
If you use han1.readline(10) Then it will print next 10 characters as in upper line already pritn upto first
I am a bes
If you use again han1.readline(10) then it will print next 10 character untill didnt get next line t player
If you use han1.readline(15) then again print next 15 characters I am the best p
------------------now start read()--------------------
Now use han1.read() layer
I am best player
I am an best player
I am a best player
I am a best player
I am a best player
I am a best player
I am a best player
I am a best player
Comments
Post a Comment