Nov-16-2017, 01:31 PM
Thanks Metulburr for reply. I already tried Generating *.pyc file and making it bytecoded. My problem is that I am using *.py file in my C# code. As long as i specify file as *.py code works fine but as soon as i define it as *.pyc it gives me this error.
Is there any way in C# to convert .pyc back to .py within code itself?
Error:An exception of type 'System.ArgumentException' occurred in Microsoft.Scripting.dll but was not handled in user code
System.ArgumentException was unhandled by user code
HResult=-2147024809
Message=File extension '.pyc' is not associated with any language.
Source=Microsoft.Scripting
StackTrace:
at Microsoft.Scripting.Hosting.ScriptRuntime.UseFile(String path)
at WpfApp.MainWindow.func() in C:\Users\documents\visual studio 2015\Projects\WpfApp\WpfApp\MainWindow.xaml.cs:line 42
at WpfApp.MainWindow..ctor() in C:\Users\documents\visual studio 2015\Projects\WpfApp\WpfApp\MainWindow.xaml.cs:line 31
InnerException:
My C# code is like thisusing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using IronPython.Hosting; using Microsoft.Scripting.Hosting; namespace WpfApp { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); func(); } public void func() { var ipy = Python.CreateRuntime(); dynamic test = ipy.UseFile("pythonFunctions.pyc"); lblText.Content=test.calcu(1,2,3,4,5); } } }It gives me error at line 37. I tried importing dll as reference too but that also didn't work.
Is there any way in C# to convert .pyc back to .py within code itself?