This is a constant value. This value must be replaced with the file path from your own system in the example below. Open the file in read-only mode. Print the content of the given file using the read function. Apply seek method to the given file by passing some random number as an argument. It returns the file content from that index position.
Print the content of the given file using the read function after applying seek method. Close the given file using the close function. The Exit of the Program. Below is the implementation: Make a single variable to store the path of the file. In this case, we're reading the contents of the file.
Apply seek method to the given file by passing some random number as an argument to it and print it. It returns the new position. Leave a Comment Cancel reply You must be logged in to post a comment.
I just thought that B might start reading the file from the beginning. How do I check if that's the case? Should I worry about stupid things like this? And I would use the absolute seek--it's simpler to get right, and to read; it doesn't waste an extra possible syscall for a tell; it doesn't have the race condition if the file changes between the calls If you're worried about performance, it's not just more useful, but also easier, to test performance than to try to guess how it works and then try to guess what the performance impact would be.
Just create a big file, and try both versions within a timeit. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 2 months ago. Active 7 years, 7 months ago. Viewed 5k times. Is there any difference between these two? A: seek back by difference from current position fp.
As a general rule: is your code too slow? Have you narrowed the slowness down to a bottleneck in this area? If yes, worry about optimizing it. Yes, it's slow. Now I did not narrowed down, but I thought it could be "blatant" difference if I start reading a huge file from the beginning every time if I encounter a bad line. Yep, so this was a reasonable question. It just didn't turn out to be the issue.
0コメント