Skip to content

Compatibility issue between argparse and pythonnet packages #404

Closed
@sg08013

Description

@sg08013

Environment

  • Pythonnet version: 2.3.0.dev1 (built from master on 23/02/2017)
  • Python version: 2.7.13 64bit
  • Operating System: Windows 7 64bit

Details

  • I tested the pythonnet version from yesterday, 23/02/2017, as we are interested in the bug fix for the method overload issue Method overload object type #377. I noticed that we are now running into compatibility issues with the package argparse.

The package argparse now only works correctly, if the parsing of the command line arguments is done BEFORE the import statement of pythonnet (import clr).

If I revert my pythonnet version to pythonnet==2.2.2, then the problem disappears.

The following minimal test code illustrates the problem:

file: test.py
import argparse
# import clr # can't put it here, args.arg1 will be None

parser = argparse.ArgumentParser()
parser.add_argument('--arg1', '-a', help='argument 1', dest='arg1')
args = parser.parse_args()

import clr   
print('Argument 1 = ')
print(args.arg1)

Then I start the script from command line as

python test.py --arg1 "Hello World"

If I run the code with the "import clr" statement after the call to parser.parse_args() then I get the desired output: 
Argument 1 =
hello world

However, if I put the "import clr" at the beginning of the file, I get the output:
Argument 1 =
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions