0

I want to put some python script's into resources to not implement it in code like this:

Code = "if pos.IsConstruction: \r\n pos.Mirror()" // Code is string

So I made .resx file named _PythonScripts and put that code into .py file. I was trying to read this like that example, but IDE is talking me that this is binary file.

Code = Resources._PythonScripts.clear

I can add that this is working on .sql files but on .py not. Can You give me tip how Can I read this?

3
  • You could refer to the file itself in a .resx as a path, use the path to open the file in your code and parse the code inside the .py file. I've never done something like that but it should be possible, you should look for something like a Python Parser for C# because there is no need to reinvent the wheel. Commented Sep 12, 2019 at 8:48
  • How did you add the file? The extension of the original file doesn't matter - it's either a text file or not. The IDE doesn't have anything to do with how the code runs either. Do you get a compilation error? What exactly? Commented Sep 12, 2019 at 9:23
  • Cannot implicitly convert type 'byte[]' to 'string'. This is a .txt file with ranamed .txt to .py to easier write python scripts in VisualStudio Commented Sep 12, 2019 at 9:40

2 Answers 2

1

Assuming your file is called hello.py, do

string hello = File.ReadAllText("hello.py")

see File.ReadAllText Method

Sign up to request clarification or add additional context in comments.

2 Comments

Thank You, but it gives the same result. Cannot implicitly convert type 'byte[]' to 'string'
@TheNa2rat no, File.ReadAllText returns a string, not byte[], check the example at learn.microsoft.com/en-us/dotnet/api/…
0

Since python scripts are just text files, save a copy of the .py file as a .txt file and then import it into the resources file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.