Python Forum
Writing into 2 text files from the same function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing into 2 text files from the same function
#2
In a certain way the answer may have ever been in the remark; but still wondering if it's thet correct way

import os

Path = str(os.getcwd())
n = 10


#####
def MyFunction(f, g, n):
    
    f.write(f"Square value of {n} is {n**2}\n")
    g.write(f"Cubic value of {n} is {n**3}\n")
    
    

with open(Path + '/file1.txt', 'w') as f1, open(Path + '/file2.txt', 'w') as f2 :
    
    for i in range(1, n):
        print(f"i = {i}")
        MyFunction(f1, f2, i)
Reply


Messages In This Thread
RE: Writing into 2 text files from the same function - by paul18fr - Jul-27-2022, 10:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function parameter not writing to variable Karp 5 1,171 Aug-07-2023, 05:58 PM
Last Post: Karp
  azure TTS from text files to mp3s mutantGOD 2 1,914 Jan-17-2023, 03:20 AM
Last Post: mutantGOD
  Create a function for writing to SQL data to csv mg24 4 1,358 Oct-01-2022, 04:30 AM
Last Post: mg24
  Delete empty text files [SOLVED] AlphaInc 5 1,735 Jul-09-2022, 02:15 PM
Last Post: DeaD_EyE
  select files such as text file RolanRoll 2 1,312 Jun-25-2022, 08:07 PM
Last Post: RolanRoll
  Two text files, want to add a column value zxcv101 8 2,169 Jun-20-2022, 03:06 PM
Last Post: deanhystad
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,646 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  Separate text files and convert into csv marfer 6 3,093 Dec-10-2021, 12:09 PM
Last Post: marfer
  Using .hdf5 files only once they are finished writing pyhill00 7 2,974 Nov-25-2021, 06:01 PM
Last Post: pyhill00
  Sorting and Merging text-files [SOLVED] AlphaInc 10 5,311 Aug-20-2021, 05:42 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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