Python Forum
does not save in other path than opened files before
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
does not save in other path than opened files before
#2
(Jun-23-2023, 03:49 PM)icode Wrote: Thonny (3.3.13) and I do not know
Get a new version of Thonny it's comes with Python 3.10 built in.

Do not use singel \ in Path for Windows,because of escape characters.
Here you clearly see the problem.
>>> f = "C:\anyOtherPathOnMyHDD\outputfile.txt"
>>> f
'C:\x07nyOtherPathOnMyHDD\\outputfile.txt'
So raw string r or just turn around / work fine.
>>> f =  r"C:\anyOtherPathOnMyHDD\outputfile.txt"
>>> f
'C:\\anyOtherPathOnMyHDD\\outputfile.txt'
>>> 
>>> f =  "C:/anyOtherPathOnMyHDD/outputfile.txt"
>>> f
'C:/anyOtherPathOnMyHDD/outputfile.txt'
The basic of open and write files,and use with open then do not need to close file.
with open(r'G:\div_code\hello.txt') as fp:
    result = fp.read()
    print(result)

# Add 123 to hello world
with open(r'G:\div_code\new_hello.txt', 'w') as fp_out:
    add_numb = f'{result} 123'
    fp_out.write(add_numb)
Output:
hello world

hello.txt:
Output:
hello world
new_hello.txt:
Output:
hello world 123
Reply


Messages In This Thread
RE: does not save in other path than opened files before - by snippsat - Jun-23-2023, 04:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 681 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  change directory of save of python files akbarza 3 1,176 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  How to save files in a separate directory Scordomaniac 3 2,783 Mar-16-2022, 10:17 AM
Last Post: Gribouillis
Question How to get html information from a tab of my default browser opened with webbrowser? noahverner1995 2 4,831 Jan-14-2022, 10:02 AM
Last Post: noahverner1995
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,347 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  get all the files in the path in a list? korenron 23 7,797 Jul-19-2021, 07:44 AM
Last Post: korenron
  Rmarkdown opened by python code - errors Rav013 0 2,206 Apr-27-2021, 03:13 PM
Last Post: Rav013
  How to get full path of specified hidden files matching pattern recursively SriRajesh 4 4,151 Jan-18-2020, 07:12 PM
Last Post: SriRajesh
  Downloading And Saving Zip Files To A Particular Path Folder eddywinch82 2 2,694 Jan-06-2020, 07:56 PM
Last Post: eddywinch82
  Details of attachment files in a msg file such as file names save into a python list klllmmm 2 5,910 Nov-12-2019, 05:59 AM
Last Post: klllmmm

Forum Jump:

User Panel Messages

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