-
-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backslash in windows path definition - need a forward slash #454
Comments
I think |
Thx, but this makes not the difference.
the linked example creates also |
@ReimarBauer What is the output you were expecting? |
|
On Window you wil get backslashes because Don't forget that when you repr a string with backslashes, Python will escape them, so it will display as two backslashes... |
ahh, ok that's a good hint. We can close this here. I need only to be very consequent in my joining of dirs. Mixing backslash and forward slash makes the trouble.
|
Seems I get in that problem
because fs.path.join uses also on windows a forward slash.
|
You need to be very careful to separate "pyfilesystem paths" (which will always use |
@willmcgugan @dargueta ISTR that other people have also run into this "confusion" before - perhaps the docs need clarifying about this? Maybe by using an example or two to illustrate the concepts? |
@lurch Yeah probably. Maybe a callout in the concepts page would help, and some additional text at the top of the reference. @ReimarBauer Just to re-iterate, use |
I agree I must be careful. On this abstraction I don't want to use or want a dependency on os.path.join. I want be able to exchange pyfilesystem2 urls which uses forward slashes. This should be interpreted on the operation system how it is needed. At a join where a collission on OS level like |
No it shouldn't, the whole point of PyFilesystem paths is that they always use
As mentioned above, you shouldn't be trying to "join" a system (OS) path with a PyFilesystem path. I think the fundamental way to look at it is:
EDIT:
Perhaps https://docs.pyfilesystem.org/en/latest/openers.html is what you're looking for? |
I have now more or less solved it how you suggested. The tests should be close to the usecases. Hmm, may be a TempFS Url would be interesting. Not thought on that before. |
from fs.tempfs import TempFS A TempFS is always a osfs filesystem. May be it could be interesting to request the url representation. Than the OS dependant part can be done by the OS and the user can if he wants continue with the url. |
Any OS-dependent part should always be done with a syspath, please don't try to bodge an FS-URL into working with OS functions 😉 But of course it's fine to "serialise" a TempFS path to a FS-URL, and to then later recreate an OSFS from that same FS-URL (but be careful of the Note also that an FS-URL may look similar to a "regular" URL, but the two aren't interchangeable, there are subtle differences (there was a big discussion here ages ago about how |
The way PyFilesystem works does make sense, once you get used to it 😄 |
On writing a config py script like this example I have to replace "\" by "/"
The string to be written looks good
|
If I understand correctly, don’t you just need to double up the backslashes so they don’t escape the quote? |
Yep, you can either do: ROOT_DIR = 'C:\\Users\\LOCAU\\Temp\\23\\tmpps037so4mss6575af3296\\' (standard double-backslash escape) or you can do: ROOT_DIR = r'C:\Users\LOCAU\Temp\23\tmpps037so4mss6575af3296' (slash isn't necessary at the end of the path, but you want a See https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals for more info. As an example of why the >>> ROOT_DIR = 'some\\nice\\long\\path'
>>> print(ROOT_DIR)
some\nice\long\path
>>> ROOT_DIR = 'some\nice\long\path'
>>> print(ROOT_DIR)
some
ice\long\path
>>> ROOT_DIR = r'some\nice\long\path'
>>> print(ROOT_DIR)
some\nice\long\path ( |
If I would manually write that string I would prefer like in the example this version, without the \ at the end.
The string I have gets into the config_file by a f'string substitution from
This has always an ending slash on windows the \.
This is resulting into a My current solution is to replace \ to /. Maybe just the last os.seperator can be a / in any case, or can be requested. |
Oh that's strange. Is that deliberate behaviour @willmcgugan ?
Probably better to just remove the last character if it's a >>> ROOT_DIR = 'C:\\Users\\LOCAU\\Temp\\23\\tmpps037so4mss6575af3296\\'
>>> print(ROOT_DIR)
C:\Users\LOCAU\Temp\23\tmpps037so4mss6575af3296\
>>> if ROOT_DIR.endswith('\\'):
... ROOT_DIR = ROOT_DIR[:-1]
...
>>> print(ROOT_DIR)
C:\Users\LOCAU\Temp\23\tmpps037so4mss6575af3296 |
Hi
I ran in a problem of \ used in pathes. This was in the past different. Also the documentations shows:
This is broadly similar to the standard os.path module but works with paths in the canonical format expected by all FS objects (that is, separated by forward slashes and with an optional leading slash).
The text was updated successfully, but these errors were encountered: