Python Forum
my first file won't create itself
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my first file won't create itself
#1
name =input("what is your name?")
sipCard =int(input("What is your sip card"))
twoforone =int(input("How many of the two for one deals would you like?"))
            
#monthly record
with open ("MonthlyRecord.txt")as f:
    f.write (name)
    f.write (sipCard)
    f.write (twoforone)
    f.close()

    f = open("MonthlyRecord.txt", "r")
    print(f.read())
Output:
what is your name?mehri What is your sip card123 How many of the two for one deals would you like?3
Error:
Traceback (most recent call last): File "C:/Users/StaR/AppData/Local/Programs/Python/Python311/file.py", line 6, in <module> with open ("MonthlyRecord.txt")as f: FileNotFoundError: [Errno 2] No such file or directory: 'MonthlyRecord.txt'
snippsat write Nov-27-2022, 12:33 AM:
Fixed code tag in your post,look at BBCode on how to use.

Attached Files

.py   file.py (Size: 410 bytes / Downloads: 94)
Reply
#2
To make changes so it work,and some improvent.
Some points need w parameter when shall wtite to file.
when use with open don't need to close the file as it automatically done.
name = 'Tom'
sipCard = 5
twoforone = 3

#monthly record
with open("MonthlyRecord.txt", 'w') as fp_out:
    fp_out.write(f'{name}\n{sipCard}\n{twoforone}')

with open("MonthlyRecord.txt", "r") as fp:
    print(fp.read())
Output:
Tom 5 3
Reply
#3
Thank you so much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create Choices from .ods file columns cspower 3 602 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,889 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  Use PM4PY and create working file thomaskissas33 0 664 Nov-14-2023, 06:53 AM
Last Post: thomaskissas33
  Create csv file with 4 columns for process mining thomaskissas33 3 754 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  create exe file for linux? korenron 2 976 Mar-22-2023, 01:42 PM
Last Post: korenron
  Create multiple/single csv file for each sql records mg24 6 1,398 Sep-29-2022, 08:06 AM
Last Post: buran
Sad pandas writer create "corrupted" file freko75 1 2,818 Jun-14-2022, 09:57 PM
Last Post: snippsat
  create new log file on logging? korenron 6 2,285 Mar-22-2022, 07:14 AM
Last Post: korenron
  Create zip file from the BLOB column in ORACLE DB nnsatpute 2 1,939 Dec-31-2021, 11:00 AM
Last Post: ibreeden
  Create a 2-channel numpy file from two cvs file containing a 9x9 matrix silvialecc 1 1,643 Oct-26-2021, 07:59 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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