- Notifications
You must be signed in to change notification settings - Fork750
Closed
Description
Environment
- Pythonnet version: 3.0.3
- Python version: 3.10
- Operating System: Windows 11
- .NET Runtime: 8.0.4
Details
- Describe what you were trying to get done.
I want to read a file that may contain zero width no-break space characters anywhere in the file. If I read a file using C# into Python using Python.NET, these characters get dropped if they are at the start of a line.
- What commands did you run to trigger this issue? If you can provide a
Minimal, Complete, and Verifiable example
this will help us understand the issue.
frompythonnetimportloadload("coreclr")importclrclr.AddReference('System')clr.AddReference('System.Runtime')clr.AddReference('System.IO')importSystemfile_path=r"path\to\zwnbsp_test_data.txt"result=System.IO.File.ReadAllLines(file_path)print(str(result[1][0]))
Native C# code does not seem to have this problem:
C#String[] lines = File.ReadAllLines(@"path\to\zwnbsp_test_data.txt");int firstChar = char.ConvertToUtf32(lines[1], 0);int secondChar = char.ConvertToUtf32(lines[1], 1);Console.WriteLine(firstChar);Console.WriteLine(secondChar);
Some screenshots to help illustrate:
- If there was a crash, please include the traceback here.
No crash