Forums
Python standard library
11 posts
• Page 1 of 2 • 1, 2
Python standard library
When I coding the cobra and want to use a Python standard library, is there the way?
- arisawa
- Posts: 51
Re: Python standard library
Not currently. Someday Cobra will support Microsoft's Dynamic Language Runtime (DLR), using it for dynamic dispatch. Then you should be able to use pure Python libraries through IronPython. But we don't have that right now.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Python standard library
By the way, was there a particular library or libraries that you wanted to use from Python? Just curious.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Python standard library
sorry, off topic
Does not Cobra follow it by built-in function of Python?
Does Cobra have pound-bang line? the example?
because I learn Cobra, Python and C# in side by side, I meet with such a confusion and questions well.
Does not Cobra follow it by built-in function of Python?
Does Cobra have pound-bang line? the example?
because I learn Cobra, Python and C# in side by side, I meet with such a confusion and questions well.
- arisawa
- Posts: 51
Re: Python standard library
These questions are fine.arisawa wrote:sorry, off topic
Cobra uses the .NET/Mono libraries. So if you want to find the built-in functions for something you can search Google for "C# read directories" or whatever you like. Eventually, we'll have a cross platform library that runs on both .NET and JVM, but that won't be for awhile.arisawa wrote:Does not Cobra follow it by built-in function of Python?
It's supposed to, but I just tried "#!/usr/bin/cobra" on my Mac and it failed for reasons that I researched before. Basically, unix is not very flexible in allowing the pound-bang command to be another script which is what "/usr/bin/cobra" is. I was able to do this though:arisawa wrote:Does Cobra have pound-bang line? the example?
#!/bin/bash cobra
class X
def main
print 'Hello.'
#!/bin/bash /usr/bin/cobra
...
No problem.arisawa wrote:because I learn Cobra, Python and C# in side by side, I meet with such a confusion and questions well.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Python standard library
Just for fun, here's a sample Cobra program calling into IronPython
I called this program CallingIronPython.cobra. I used IronPython 1.1.0 (the API changed with IronPython 2.0) and had IronPython.dll and IronMath.dll in the same directory as the cobra file. Ran Cobra with the command line: cobra -r:IronPython.dll CallingIronPython
A good resource (especially if you want to work with IronPython 2.0) is http://www.voidspace.org.uk/ironpython/embedding.shtml
Hope that helps.
- Code: Select all
use IronPython.Hosting
use IronPython.Runtime.Types
use IronPython.Runtime.Operations
class Program
def main is shared
""" Test docstring """
engine = PythonEngine()
code = 'print "This is IronPython"'
engine.execute(code)
I called this program CallingIronPython.cobra. I used IronPython 1.1.0 (the API changed with IronPython 2.0) and had IronPython.dll and IronMath.dll in the same directory as the cobra file. Ran Cobra with the command line: cobra -r:IronPython.dll CallingIronPython
A good resource (especially if you want to work with IronPython 2.0) is http://www.voidspace.org.uk/ironpython/embedding.shtml
Hope that helps.
- eric.sellon
- Posts: 24
Re: Python standard library
That's great. Would make a nice wiki page. hint, hint.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Python standard library
Chuck wrote:Would make a nice wiki page. hint, hint.
Done. Made a Cobra Cookbook on the wiki and added this recipe -> http://cobra-language.com/trac/cobra/wiki/CallingIronPythonRecipe
- eric.sellon
- Posts: 24
Re: Python standard library
Wow! It is a helpful idea.
I wrote a sample to try:
In the tried feeling
Python code seems to run if it does in this way:
but, still rocky.
I wrote a sample to try:
use System.Windows.Forms
use IronPython.Hosting
class Calc inherits Form
var tb as TextBox
var pe as PythonEngine = PythonEngine()
var s as Str = Str()
cue init
base.init
.text = 'SimpleCalc'
flp = FlowLayoutPanel(parent=this, dock=DockStyle.Fill, flowDirection=FlowDirection.TopDown)
.tb = TextBox(parent=flp)
b = Button(text='done', parent=flp)
listen b.click, ref .handleClick
.pe.globals.add('TextBox', .tb)
.pe.globals.add('Str', .s)
def handleClick(sender, args as EventArgs)
.pe.execute('TextBox.Text =' + 'Str.Pack('+.tb.text+')')
class Str
def pack(n as int) as String
return n.toString
class Program
def main is shared
Application.run(Calc())
In the tried feeling
Python code seems to run if it does in this way:
engine = PythonEngine()
file = 'test.py'
engine.executeFile(file)
but, still rocky.
- arisawa
- Posts: 51
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 9 guests