Maroder
Maroder

Reputation: 115

Pythonnet trouble with enum containing "None"

Im using pythonnet to work with a C# dll having the following Enum (from doc):

 public enum DownloadOptions {
 None = 0, // Download nothing
 Hardware, // Download hardware only 
 Software // Download software only
 }

Printing "Hardware" and "software" gives me "1" and "2" while printing "None" i get syntax error. It also works fine passing "1" or "2" to the C# function requiring this enum, but "0" is not accepted.

My feeling is that the name "None" is causing trouble here as it is a reserved python keyword.

Any ideas how I can solve this?

Upvotes: 2

Views: 477

Answers (1)

Cong Yang
Cong Yang

Reputation: 94

I just found a solution when I faced the same problem when I use NationalInstruments.VisaNS.dll in python, I have to access the enum None in NationalInstruments.VisaNS.Parity, if use NationalInstruments.VisaNS.Parity.None always get SyntaxError: invalid syntax, so i change search key words to "pythonnet enum None" and found this answer which solve my problem. So compare to

NationalInstruments.VisaNS.Parity.None

use

getattr(NationalInstruments.VisaNS.Parity,'None')

instead.

Upvotes: 2

Related Questions