Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue w/ "With Open"
#4
(Dec-23-2022, 06:59 AM)vman44 Wrote: Do I have to keep using the %s format, or is there an easier way?
%s is the old way to do string formatting,should not use it anymore.
The way now is to use f-Strings
Post a working code example now have guess,usually so is userinputs a string that have to be split it up.
If want to add comma can be done lke this.
userinputs = 'hello world 123'
userinputs = userinputs.split()
with open('file1.txt', 'a') as writer:
    writer.write(f"{','.join(userinputs)}\n")
If i run two times.
Output:
hello,world,123 hello,world,123
vman44 likes this post
Reply


Messages In This Thread
Issue w/ "With Open" - by vman44 - Dec-23-2022, 06:59 AM
RE: Issue w/ "With Open" - by praveencqr - Dec-23-2022, 07:30 AM
RE: Issue w/ "With Open" - by perfringo - Dec-23-2022, 10:32 AM
RE: Issue w/ "With Open" - by snippsat - Dec-23-2022, 02:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue when using open() in converted exe skakalpes 2 1,745 Feb-02-2022, 02: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