Python Forum
how write variable in files and retreive it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how write variable in files and retreive it
#2
Please use python and output tags when posting code and results. I put them in for you this time. Here are instructions for doing it yourself next time.

The standard way to write to a file is:

with open('data.txt', 'w') as data_file:
    data_file.write(some_string)
The data can be retrieved with

with open('data.txt') as data_file:
    some_string = data_file.read()
You can also read the lines of a file in as a list (data_file.readlines()) or iterate over the lines in a file (for line in data_file:).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: how write variable in files and retreive it - by ichabod801 - Jan-28-2019, 04:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write a part of powershell command as a variable? ilknurg 2 2,002 Jul-26-2022, 11:31 AM
Last Post: ilknurg
  How do I read the HTML files in a directory and write the content into a CSV file? glittergirl 1 3,463 Sep-23-2019, 11:01 AM
Last Post: Larz60+
  Python Script Spawned by Cron or Systemd doesn't write files..? johnnyrobot 2 3,651 May-24-2019, 07:04 PM
Last Post: Larz60+
  Delete Lines that Contain Words - Loop through files in a folder - Write to new files dj99 3 4,704 May-18-2019, 06:34 AM
Last Post: heiner55
  How to I define a variable between strings in telnetlib write? Fez 2 4,344 May-02-2019, 06:53 PM
Last Post: Fez
  Read and write data to CSV files kartik 1 2,569 Mar-12-2019, 06:16 AM
Last Post: Yoriz
  write each line of a text file into separate text files and save with different names Shameendra 3 3,680 Feb-20-2019, 09:07 AM
Last Post: buran
  How to open and write into several files kazimahmet 3 3,826 May-07-2018, 02:08 PM
Last Post: wavic
  Write Variable String To CSV Cell digitalmatic7 1 7,566 Nov-24-2017, 07:10 AM
Last Post: Prince_Bhatia
  Replacing variable in a split string and write new file python MyCode 1 4,419 Oct-30-2017, 05:20 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020