The interactive module of Python and C # pythonnet

Source: Internet
Author: User

Today summarizes the Python and C # Interactive module pythonnet, in fact, Microsoft also has the corresponding interpreter, is IronPython, but after all IronPython still have a lot of things not inherited from the python side, so sometimes use is not so cool. But fortunately, the powerful community always surprises us, and Pythonnet is one of the things that surprises me, and it's a smooth way to interact with C #. But the information on the Internet is still too little, but eventually it is toss out. Here's the code.

#Coding=utf-8#The CLR is the public runtime environment, which is the core of the interaction with C #ImportCLRImportSYS#This module is best imported when importing the CLR, so you can use the AddReference methodImportSystemsys.path.append (R'D:\dll')#load the C#dll file pathCLR. Findassembly ('ClassLibrary5.dll')#load the C#dll file fromClasslibrary5.aaaaaImport*#Import Namespacesa= CLR. AddReference ('ClassLibrary5')#instantiate a C # class library so that it can be called, such as the source location of this class libraryC1=bbbbb ()Printa.locationc1.a ()PrintDir (System)

Code comments are quite clear, there are a few points to note, when loading the C#dll file, you must use the

Clr. The findassembly method instead of the Clr.addreference method, and when importing CLR modules, it is best to import the system module, as explained in the reason note, and finally note that the C # namespace must be imported as a module. The above is the approximate usage of pythonnet. Other uses will need to be studied in the future use of the process!

Interactive module for Python and C # pythonnet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.