Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
translate \ to / ?
#1
i see many examples where / filename separators are used for Windows. but a user of my script on Windows might type in \ as the file separator. should i replace all \ characters with /? what if a file name on Windows has a / in its name much like Linux can have \ in a file name?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
(Oct-01-2019, 12:25 AM)Skaperen Wrote: what if a file name on Windows has a / in its name much like Linux can have \ in a file name?
That is not possible. Look at the reserved (forbidden in file name) chars: https://docs.microsoft.com/en-us/windows...ing-a-file
And if you accept filename as user input you need to validate the input not to include any of these
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
open(fn,'w') should fail with an invalid filename, correct? i would expect open(fn,'r') to fail, somehow, too.

one of the disadvantages of not being a windows user ... i don't end up knowing these things.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
Yes, it will fail. I just don't see the logic to handle some problem chars and not handle others
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
i didn't know / was invalid in Windows. that actually eliminates the issues around portability. all that is needed is replacing every / with \ before it goes to the system. and python apparently takes care of this for me. so i just have paths with / characters. since users could type in \ i just need to replace those with / before letting open() or other python code have it have it.

i should go figure out how to start up a cloud instance with Windows in it then learn how to install Python3 in it.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  googletrans library to translate text language for using data frame is not running gcozba2023 0 1,164 Mar-06-2023, 09:50 AM
Last Post: gcozba2023
  BeautifulSoup - I can't translate html tags that contain <a href=..</a> OR <em></em> Melcu54 10 1,564 Oct-27-2022, 08:58 AM
Last Post: wavic
  How to Translate a python code written in Mac-OS to Windows? alexanderDennisEnviro500 2 2,640 Jul-31-2021, 08:36 AM
Last Post: Gribouillis
  Delimiters - How to skip some html tags from being translate Melcu54 0 1,621 May-26-2021, 06:21 AM
Last Post: Melcu54
  Translate to noob a Name Eroor message bako 2 2,190 Mar-30-2020, 05:58 PM
Last Post: bako
  Translate this line of code please keystone76 2 2,595 Jan-31-2020, 11:15 PM
Last Post: keystone76
  Heating program to translate from Basic to Python tommy2k19 12 5,840 May-21-2019, 08:16 AM
Last Post: tommy2k19
  translate this into python plz abrew132 3 3,865 Apr-12-2017, 10:42 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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