Python Forum
Appending data into a file in tab delimited format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Appending data into a file in tab delimited format
#1
import datetime
from datetime import datetime
n = 5
while n > 0:
id = input("Please enter your ID: ")
file = open("C:\\Users\\abc\\def\\" "%s.txt" % id, "a")
name = input("Please provide your name: ")
Doctor = input("Please provide the name of the doctor you would like to visit: ")
AppointmentDate = input("Please provide the date you want to see the doctor: ")
AppointmentTime = input("Please provide the time you want to see the doctor: ")
EmailID = input("Please provide your email to confirm your appointment: ")
PhoneNum = input("Please provide your phone number to receive confirmation message: ")
file.write(id)

When I run the above code I am able to create file with the ID as its name but it is not appending data
into the text file.
I need to append the data into the text file in tab delimited format.
Each time I want to enter a new line of data it should go to the next line as below
The data should go only into the respective ID file when the user with that ID executes the code.
User with id ABCD will create ABCD file and the below lines should go to his file.
User with id EFGH will create EFGH file and the below lines should go to his file.

Ex: IDABCD JAMES JOLIE 9/9/2019 13:00 [email protected] 9090909090
IDABEE JIMMY JOHNNY 9/9/2019 11:00 [email protected] 9000009090

Assistance is appreciated.
thanks
Reply
#2
Is this what do you need?

a = "absbdbs"
b = "dcfdss"
c = "edfsds"

line = "{}\t{}\t{}\n".format(a, b, c)

with open("foo.log", "a") as f:
    f.write(line)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tab Delimited Strings? johnywhy 7 554 Jan-13-2024, 10:34 PM
Last Post: sgrey
  Export data from PDF as tabular format zinho 5 693 Nov-11-2023, 08:23 AM
Last Post: Pedroski55
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,874 Dec-12-2022, 08:22 PM
Last Post: jh67
  Appending a row of data in an MS Excel file azizrasul 3 1,171 Nov-06-2022, 05:17 PM
Last Post: azizrasul
  Appending data azizrasul 5 3,536 Oct-09-2022, 02:54 AM
Last Post: azizrasul
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 2,654 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Print to a New Line when Appending File DaveG 0 1,217 Mar-30-2022, 04:14 AM
Last Post: DaveG
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,954 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Appending Excel column value as CSV file name sh1704 0 1,295 Feb-06-2022, 10:32 PM
Last Post: sh1704
  Need Help writing data into Excel format ajitnayak87 8 2,503 Feb-04-2022, 03:00 AM
Last Post: Jeff_t

Forum Jump:

User Panel Messages

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