Python Crash Course: A Beginner’s Guide to Master the Basics of Python and Data Science. Learn Coding with This Machine Learning Tool. Discover the Endless Possibilities of Computers and Codes. by Wall Eric

Python Crash Course: A Beginner’s Guide to Master the Basics of Python and Data Science. Learn Coding with This Machine Learning Tool. Discover the Endless Possibilities of Computers and Codes. by Wall Eric

Author:Wall, Eric [Wall, Eric]
Language: eng
Format: epub, azw3, pdf
Published: 2020-09-27T16:00:00+00:00


Note that we had instructed the method to read only 10 bytes from the file, and that is why not all the file contents were read.

File Positions

You may use the tell() method to tell the current position in a file. This tells where the next read or write will start from the next time you attempt to do so on the file.

If you need to change this position, you can use the seek(offset[, from]) method. The argument is that offset specifies the number of bytes that should be moved. The argument from specifies the reference position from which bytes should be moved.

If the value of from is 0, then the reference position is the starting point of the file. If you set it to 1, then the current position will be used as a reference position. If it is set to 2, the file’s end will be used as a reference position.

Example

#!/usr/bin/Python3

# Openig the file

p = open("friends.txt", "r+")

str = p.read(10)

print ("The function read the string : ", str)

# Checking the current position

pos = p.tell()

print ("The current position for the file is : ", pos)

# Reposition the pointer to the beginning

pos = p.seek(0, 0)

str = p.read(10)

print ("The read String again is : ", str)

# Close the opened file

p.close()

Run the code from the directory you have stored the file names.txt in. In my case, it returns the following:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(56772)
What's Done in Darkness by Kayla Perrin(26799)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(20660)
De Souza H. Master the Age of Artificial Intelligences. The Basic Guide...2024 by Unknown(20441)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(20438)
The Fifty Shades Trilogy & Grey by E L James(19294)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19256)
Shot Through the Heart by Mercy Celeste(19122)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17290)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(17225)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(17066)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16994)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16610)
The Subtle Art of Not Giving a F*ck by Mark Manson(14604)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14305)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13964)
Scorched Earth by Nick Kyme(12957)
Drei Generationen auf dem Jakobsweg by Stein Pia(11142)
Suna by Ziefle Pia(11064)
Scythe by Neal Shusterman(10550)