chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


Whats the point of the truncate() function for writing to files? filter_list
Author
Message
Whats the point of the truncate() function for writing to files? #1
What's the point of the truncate() function?

For example in this PoC:


PHP Code:
from sys import argv

script
filename argv

print "Okay, we are going to write to the file %r" filename
print "You can print what you like, hit enter to continue, or press Ctrl C to exit(^C)"
raw_input("?")

print 
"Opening the selected file now..."
HPP open(filename'w')

print 
"Truncating the file"
HPP.truncate() [color=#FF1493]#The fuck is truncate() for?[/color]

print "Okay, print what you want into the .txt file"

line1 raw_input("Line 1: ")
line2 raw_input("Line 2: ")
line3 raw_input("Line 3: ")
line4 raw_input("Line 4: ")
line5 raw_input("Line 5: ")
line6 raw_input("Line 6: ")

print 
"Okay, whatever you input above^ will be written to the filename"

HPP.write(line1)
HPP.write("\n")
HPP.write(line2)
HPP.write("\n")
HPP.write(line3)
HPP.write("\n")
HPP.write(line4)
HPP.write("\n")
HPP.write(line5)
HPP.write("\n")
HPP.write(line6)
HPP.write("\n")

print 
"Thank you, and goodbye" 

I can't find anything on the truncate funct. itself. Is it really necessary to use, or is it mandatory to have it? I know I could just delete that line of code, and attempt running it anyway, but I want someones input.
Unleash the lead from my pistol into my head bumpin' crystal

Reply

RE: Whats the point of the truncate() function for writing to files? #2
Taken from the official python documentation:
Code:
file.truncate([size])
Truncate the file’s size. If the optional size argument is present, the file is truncated to (at most) that size. The size defaults to the current position. The current file position is not changed. Note that if a specified size exceeds the file’s current size, the result is platform-dependent: possibilities include that the file may remain unchanged, increase to the specified size as if zero-filled, or increase to the specified size with undefined new content. Availability: Windows, many Unix variants.

This being said, I have never used it nor do I see the need for it to be used in your case.

Reply

RE: Whats the point of the truncate() function for writing to files? #3
This might help you out.
http://stackoverflow.com/questions/45621...-in-python

Reply

RE: Whats the point of the truncate() function for writing to files? #4
(01-07-2014, 12:53 AM)Pens Wrote: Taken from the official python documentation:
Code:
file.truncate([size])
Truncate the file’s size. If the optional size argument is present, the file is truncated to (at most) that size. The size defaults to the current position. The current file position is not changed. Note that if a specified size exceeds the file’s current size, the result is platform-dependent: possibilities include that the file may remain unchanged, increase to the specified size as if zero-filled, or increase to the specified size with undefined new content. Availability: Windows, many Unix variants.

This being said, I have never used it nor do I see the need for it to be used in your case.

Just as I expected if I removed the truncate line it still works, thanks for the response

(01-07-2014, 12:54 AM)Necrosis Wrote: This might help you out.
http://stackoverflow.com/questions/45621...-in-python

Will check it out, thanks for the reply
(This post was last modified: 01-07-2014, 12:57 AM by Alan Turing.)
Unleash the lead from my pistol into my head bumpin' crystal

Reply






Users browsing this thread: 1 Guest(s)