Skip to content
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

Issue with path in windows #10

Open
lguerard opened this issue May 3, 2023 · 7 comments
Open

Issue with path in windows #10

lguerard opened this issue May 3, 2023 · 7 comments

Comments

@lguerard
Copy link
Contributor

lguerard commented May 3, 2023

The parse_path functions sometimes creates issues on windows when parsing a direct path copied.

  • Using the script parameter for file "U:\VAMP\guerard\LS7\new copy\SmalltileandZ - Copy.czi" returns 'path':'U:\\VAMP\\guerard\\LS7\\new copy\\'
  • Directly using parse_path("U:\VAMP\guerard\LS7\new copy\SmalltileandZ - Copy.czi") gives 'path': 'U:\\VAMP\\guerard\\LS7\new copy\\' which then later can cause issues
@lguerard
Copy link
Contributor Author

lguerard commented May 3, 2023

Adding path = path.lower().replace("\n",r"\\n") at the beggining of the script fixes it, but it doesn't feel like the proper way to do it... Let me know if you have any ideas @ehrenfeu

@lguerard
Copy link
Contributor Author

lguerard commented May 9, 2023

Same thing is happening with \t

@ehrenfeu
Copy link
Member

ehrenfeu commented Aug 9, 2024

Sorry, I need to see the two results side by side:

           "U:\VAMP\guerard\LS7\new copy\SmalltileandZ - Copy.czi"
parse_path("U:\VAMP\guerard\LS7\new copy\SmalltileandZ - Copy.czi"
'path':'U:\\VAMP\\guerard\\LS7\\new copy\\'
'path': 'U:\\VAMP\\guerard\\LS7\new copy\\'

Now I'm confused. Could you point out or explain differently what the issue is exactly? The only thing I'm seeing is the space after the colon in the second section, but I guess that's just a copy-paste thing, no?

@imagejan
Copy link

imagejan commented Aug 9, 2024

  • Directly using parse_path("U:\VAMP\guerard\LS7\new copy\SmalltileandZ - Copy.czi") gives 'path': 'U:\\VAMP\\guerard\\LS7\new copy\\' which then later can cause issues

Does it help calling parse_path with a raw string (r in front of the quotes)?

parse_path(r"U:\VAMP\guerard\LS7\new copy\SmalltileandZ - Copy.czi")

Otherwise Python interprets \t and \n as tab and newline, respectively...

@ehrenfeu
Copy link
Member

ehrenfeu commented Aug 9, 2024

Ah, I see the \n in the second path now...

@imagejan is probably right, calling it like this should work - the question is then rather if we can enforce this from within the function (as in, avoiding the string to be interpreted wrongly), or if that's already too late.

➡️ I'll need to look into this!

@rohangirishrao
Copy link

I guess replacing the \n back to "proper" alphabet at the top of the method should work, right? Converting to a raw string inside the function would be too late.
path = path.replace("\n", "\\n").replace("\t", "\\t") ?

@ehrenfeu
Copy link
Member

ehrenfeu commented Aug 13, 2024

@lguerard could you create an additional test for this (preferred), or modify the existing one here:

def test_parse_path_windows():
path = r'C:\foo\bar'
parsed = parse_path(path)
assert parsed['orig'] == path
assert parsed['full'] == r'C:/foo/bar'
assert parsed['fname'] == 'bar'
assert parsed['dname'] == 'foo'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants