Login Register


Python writing & reading text filter_list
Author
Message
Python writing & reading text #1
Hello All,

Just wanted to share this simple snippet of code which allows you to read & write text files in Python, it's really easy and you have no need to import any librarys.

Code:
#!/usr/bin/python f = open('HC.log', 'w') f.write('Hello my name is Lynux!\n') f.write('Welcome to HackCommunity!') f.close() f = open('HC.log', 'r') print f.read()
Donations for Alcohol, Hookers & MJ: 1PzvkR3E3RvEMrcsuFV4AWAzWbum7mtVdZ

Reply

RE: Python writing & reading text #2
Sorry to say it, but this is completely useless. It's info that I consider as "general information" and is therefore not needed to share like that. Besides, you'll literally get more than a million hits on Google.

Another thing, you why not comment on the code you share? Otherwise, how do you expect people to understand that code you're sharing?

It's great that you want to contribute, but please consider what's relevant.

Reply

RE: Python writing & reading text #3
And please center the text left Wink
Code text centered looks very weird.

Reply

RE: Python writing & reading text #4
Added Source tag. Removed Centered Alignment.

@Lynux Please Read this before making a tutorial. I hope you will understand how to write tutorials Smile http://www.hackcommunity.com/Thread-Tuto...-tutorials
[Image: OilyCostlyEwe.gif]

Reply

RE: Python writing & reading text #5
Ok sorry I just thought that someone might find it useful, I'm currently working on a script that will install various tools either automatically or via the users request so I will modify this post with that, at least that will probably be a little better than the above code.
Donations for Alcohol, Hookers & MJ: 1PzvkR3E3RvEMrcsuFV4AWAzWbum7mtVdZ

Reply

RE: Python writing & reading text #6
Maybe a commented version would be useful..

Code:
#!/usr/bin/python # Opening file "HC.log" from current working directory in write mode # More information on file modes here # https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files f = open('HC.log', 'w') # Write a few strings to the end of file f.write('Hello my name is Lynux!\n') f.write('Welcome to HackCommunity!') # Close out out the open file process f.close() # Open file "HC.log" in read mode f = open('HC.log', 'r') # print out the results of the read() method # this should output the contents of the file "HC.log" print f.read()
[Image: iQ3pcQu.png]
BTC Address: 1DCKgDaWcmc9dxBkhe9qrTQtrQpoFUzXdn

Reply







Users browsing this thread: 1 Guest(s)