From sepatan at sibmail.com Wed Sep 5 07:21:18 2012 From: sepatan at sibmail.com (sepatan at sibmail.com) Date: Wed, 5 Sep 2012 12:21:18 +0700 (NOVT) Subject: [Ironpython-users] How to get the full path (in dotted notation) to an attribute? Message-ID: <48238.83.172.33.173.1346822478.squirrel@www.sibmail.com> Hello. How to get the full path (in dotted notation) to an attribute: class meta (type): def __ getattr__ (cls, t): print cls.__name__, t class a (object): class b (object): class c (object): __metaclass__ = meta a.b.c a.b.c.ff The result: c ff And how to get: a.b.c ff From jdhardy at gmail.com Wed Sep 5 17:27:08 2012 From: jdhardy at gmail.com (Jeff Hardy) Date: Wed, 5 Sep 2012 08:27:08 -0700 Subject: [Ironpython-users] How to get the full path (in dotted notation) to an attribute? In-Reply-To: <48238.83.172.33.173.1346822478.squirrel@www.sibmail.com> References: <48238.83.172.33.173.1346822478.squirrel@www.sibmail.com> Message-ID: On Tue, Sep 4, 2012 at 10:21 PM, wrote: > Hello. > How to get the full path (in dotted notation) to an attribute: > > class meta (type): > def __ getattr__ (cls, t): > print cls.__name__, t > > class a (object): > class b (object): > class c (object): > __metaclass__ = meta > > a.b.c > a.b.c.ff > > The result: > c ff > > And how to get: > a.b.c ff print cls.__module__, cls.__name__, t - Jeff From sepatan at sibmail.com Thu Sep 6 04:01:27 2012 From: sepatan at sibmail.com (sepatan at sibmail.com) Date: Thu, 6 Sep 2012 09:01:27 +0700 (NOVT) Subject: [Ironpython-users] How to get the full path (in dotted notation) to an attribute? In-Reply-To: References: <48238.83.172.33.173.1346822478.squirrel@www.sibmail.com> Message-ID: <43880.83.172.33.173.1346896887.squirrel@www.sibmail.com> So what's the conclusion: __main__ c ff A must: a.b.c ff > > print cls.__module__, cls.__name__, t > > - Jeff > > On Tue, Sep 4, 2012 at 10:21 PM, wrote: >> Hello. >> How to get the full path (in dotted notation) to an attribute: >> >> class meta (type): >> def __ getattr__ (cls, t): >> print cls.__name__, t >> >> class a (object): >> class b (object): >> class c (object): >> __metaclass__ = meta >> >> a.b.c >> a.b.c.ff >> >> The result: >> c ff >> >> And how to get: >> a.b.c ff From no_reply at codeplex.com Fri Sep 14 12:52:09 2012 From: no_reply at codeplex.com (no_reply at codeplex.com) Date: 14 Sep 2012 03:52:09 -0700 Subject: [Ironpython-users] IronPython, Daily Digest 9/13/2012 Message-ID: Hi ironpython, Here's your Daily Digest of new issues for project "IronPython". In today's digest:ISSUES 1. [New issue] rrule.rulestr() ---------------------------------------------- ISSUES 1. [New issue] rrule.rulestr() http://ironpython.codeplex.com/workitem/33114 User gharig has proposed the issue: "I receive an 'write to closed file' exception when executing a sample console vb.net application. I'm trying to use a dateutil rrule.rulestr() function. Works fine until I add the keyword 'UNTIL' to the string. I set the path for pyEngine.GetSearchPaths() to "C:\Python27\Lib" and "C:\Python27\Lib\site-packages\dateutil" The error seems to be thrown in a call to Pythons parser.py class _timelex(object): Thank You George Below is my code, Imports System Imports IronPython.Hosting Imports Microsoft.Scripting.Hosting ' we get access to Action and Func on .Net 2.0 Imports Microsoft.Scripting.Utils Module Module1 Sub Main() Dim x As TestCallIronPython.Program = New TestCallIronPython.Program() x.main2() End Sub End Module Namespace TestCallIronPython Public Class Program Delegate Function ConvertMethod(ByVal inString As String) As String Public Sub main2() Console.WriteLine("Hello World!") Dim options = New Dictionary(Of String, Object)() options("Frames") = True options("FullFrames") = True options("Debug") = True Dim pyEngine As ScriptEngine = Python.CreateEngine(options) Dim pyScope As ScriptScope = pyEngine.CreateScope() pyScope.SetVariable("test", "test me") Dim dir As String = System.IO.Path.GetDirectoryName("C:\Python27\Lib\site-packages\dateutil") Dim paths As System.Collections.Generic.ICollection(Of String) = pyEngine.GetSearchPaths() If Not String.IsNullOrEmpty(dir) Then paths.Add(dir) paths.Add("C:\Python27\Lib") paths.Add("C:\Python27\Lib\site-packages\dateutil") paths.Add("C:\Python27\Lib\site-packages\dateutil\zoneinfo") Else paths.Add(System.Environment.CurrentDirectory) End If pyEngine.SetSearchPaths(paths) Dim code As String = "" + vbCrLf code = code + "import sys" + vbCrLf code = code + "import calendar" + vbCrLf code = code + "import datetime" + vbCrLf code = code + "from dateutil import rrule" + vbCrLf code = code + "from dateutil import parser" + vbCrLf code = code + "" + vbCrLf code = code + "print 'test = ' + test" + vbCrLf code = code + "class MyClass:" + vbCrLf code = code + " def __init__(self):" + vbCrLf code = code + " pass" + vbCrLf code = code + "" + vbCrLf code = code + " def somemethod(self):" + vbCrLf code = code + " print 'in some method'" + vbCrLf code = code + "" + vbCrLf code = code + " def isodd(self, n):" + vbCrLf code = code + " return 1 == n % 2" + vbCrLf code = code + "" + vbCrLf code = code + " def getRule(self, data, y, m, d):" + vbCrLf code = code + " print 'This is data: ',data" + vbCrLf code = code + " start_date = datetime.datetime(y, m, d)" + vbCrLf code = code + " return rrule.rrulestr(data, dtstart=start_date)" + vbCrLf code = code + "" + vbCrLf Dim source As ScriptSource = pyEngine.CreateScriptSourceFromString(code) Dim compiled As CompiledCode = source.Compile() compiled.Execute(pyScope) ' Get the Python Class Dim [MyClass] As Object = pyEngine.Operations.Invoke(pyScope.GetVariable("MyClass")) ' Invoke a method of the class pyEngine.Operations.InvokeMember([MyClass], "somemethod", New Object(-1) {}) ' create a callable function to 'somemethod' Dim SomeMethod2 As Action = pyEngine.Operations.GetMember(Of Action)([MyClass], "somemethod") SomeMethod2() ' create a callable function to 'isodd' Dim IsOdd As Func(Of Integer, Boolean) = pyEngine.Operations.GetMember(Of Func(Of Integer, Boolean))([MyClass], "isodd") Console.WriteLine(IsOdd(1).ToString()) Console.WriteLine(IsOdd(2).ToString()) Dim GetRule As Func(Of String, Int32, Int32, Int32, Object) = pyEngine.Operations.GetMember(Of Func(Of String, Int32, Int32, Int32, Object))([MyClass], "getRule") Dim obj1 As Object obj1 = GetRule("RRULE:FREQ=DAILY;INTERVAL=10;COUNT=42", 2012, 9, 12) Dim obj2 As Object obj2 = GetRule("RRULE:FREQ=DAILY;INTERVAL=10", 2012, 9, 12) Dim obj3 As Object 'FAILURE obj3 = GetRule("RRULE:FREQ=MONTHLY;BYDAY=+2WE;UNTIL=20130101T000000Z", 2012, 9, 12) 'UNTIL=20150921T000000 'FAILURE: Does not like "UNTIL" Console.Write("Press any key to continue . . . ") Console.ReadKey(True) End Sub End Class End Namespace" ---------------------------------------------- ---------------------------------------------- You are receiving this email because you subscribed to notifications on CodePlex. To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sepatan at sibmail.com Mon Sep 17 12:42:17 2012 From: sepatan at sibmail.com (sepatan at sibmail.com) Date: Mon, 17 Sep 2012 17:42:17 +0700 (NOVT) Subject: [Ironpython-users] How to use __ getattr__ to the current module? Message-ID: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> Hello. For example in the text of the module meets the command: ttt(4, x = 7) where and how to define __ getattr__ to handle it? Thank you. From m.schaber at 3s-software.com Mon Sep 17 13:17:54 2012 From: m.schaber at 3s-software.com (Markus Schaber) Date: Mon, 17 Sep 2012 11:17:54 +0000 Subject: [Ironpython-users] WG: Re:Example Sources In-Reply-To: <6f328e58.ecc7.139d3d62b5b.Coremail.meichunyi@126.com> References: <727D8E16AE957149B447FE368139F2B50D86A675@SERVER10> <6f328e58.ecc7.139d3d62b5b.Coremail.meichunyi@126.com> Message-ID: <727D8E16AE957149B447FE368139F2B50D8804D0@SERVER10> Hi, Kelvin and Chris, Do you know whether we have some chinese documentation about softmotion? I'm already researching whether we have some documentation in English.. Best regards Markus Schaber -- ___________________________ We software Automation. 3S-Smart Software Solutions GmbH Markus Schaber | Developer Memminger Str. 151 | 87439 Kempten | Germany | Tel. +49-831-54031-0 | Fax +49-831-54031-50 Email: m.schaber at 3s-software.com | Web: http://www.3s-software.com CoDeSys internet forum: http://forum.3s-software.com Download CoDeSys sample projects: http://www.3s-software.com/index.shtml?sample_projects Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915 -----Urspr?ngliche Nachricht----- Von: meichunyi at 126.com [mailto:meichunyi at 126.com] Gesendet: Montag, 17. September 2012 12:47 An: Markus Schaber Cc: zxq_gd at 126.com Betreff: Re:Example Sources Hi Markus Do you have a "user manual "about softmotion.We need it very much now,if you have one PDF about this ,please send one to me. Thank you. Best wishes! At 2012-09-11 17:02:45,"Markus Schaber" wrote: >Hi, > >Attached are the example sources. > >Best regards > >Markus Schaber >-- > >We software Automation. > >3S-Smart Software Solutions GmbH >Markus Schaber | Developer >Memminger Str. 151 | 87439 Kempten | Germany | Tel. +49-831-54031-0 | >Fax +49-831-54031-50 > >Email: m.schaber at 3s-software.com | Web: http://www.3s-software.com >CoDeSys internet forum: http://forum.3s-software.com Download CoDeSys >sample projects: http://www.3s-software.com/index.shtml?sample_projects > >Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | >Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915 From vernondcole at gmail.com Mon Sep 17 17:11:27 2012 From: vernondcole at gmail.com (Vernon Cole) Date: Mon, 17 Sep 2012 09:11:27 -0600 Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> Message-ID: Dear Sir: Sorry, your question does not seem to make sense. Your example appears to be a simple function call with one keyword argument. To use it, you simply define the optional arguments when you define the function. See the documentation at: http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions __getattr__ is only used within classes to emulate methods which do not actually exist. That does not appear to be what you are wanting. -- Vernon Cole On Mon, Sep 17, 2012 at 4:42 AM, wrote: > Hello. > For example in the text of the module meets the command: > ttt(4, x = 7) > where and how to define __ getattr__ to handle it? > Thank you. > > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sepatan at sibmail.com Mon Sep 17 19:17:55 2012 From: sepatan at sibmail.com (sepatan at sibmail.com) Date: Tue, 18 Sep 2012 00:17:55 +0700 (NOVT) Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> Message-ID: <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> Hello, Vernon Cole. Or you probably do not understand the question, or I did not properly posed the question. I know I can define a function (ttt). And if I'm interested in __ getattr__, so in this case it can not be determined, or its name and parameters are defined at run time. Thank you. > Dear Sir: > Sorry, your question does not seem to make sense. > Your example appears to be a simple function call with one keyword > argument. To use it, you simply define the optional arguments when you > define the function. See the documentation at: > http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions > > __getattr__ is only used within classes to emulate methods which do not > actually exist. That does not appear to be what you are wanting. > -- > Vernon Cole > > On Mon, Sep 17, 2012 at 4:42 AM, wrote: > >> Hello. >> For example in the text of the module meets the command: >> ttt(4, x = 7) >> where and how to define __ getattr__ to handle it? >> Thank you. >> >> _______________________________________________ >> Ironpython-users mailing list >> Ironpython-users at python.org >> http://mail.python.org/mailman/listinfo/ironpython-users >> > From jdhardy at gmail.com Mon Sep 17 22:27:10 2012 From: jdhardy at gmail.com (Jeff Hardy) Date: Mon, 17 Sep 2012 13:27:10 -0700 Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> Message-ID: The short answer is that you can't, in any version of Python. The longer answers can be found at http://stackoverflow.com/questions/2447353/getattr-on-a-module. - Jeff On Mon, Sep 17, 2012 at 10:17 AM, wrote: > Hello, Vernon Cole. > Or you probably do not understand the question, or I did not properly > posed the question. > I know I can define a function (ttt). And if I'm interested in __ > getattr__, so in this case it can not be determined, or its name and > parameters are defined at run time. > Thank you. > >> Dear Sir: >> Sorry, your question does not seem to make sense. >> Your example appears to be a simple function call with one keyword >> argument. To use it, you simply define the optional arguments when you >> define the function. See the documentation at: >> http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions >> >> __getattr__ is only used within classes to emulate methods which do not >> actually exist. That does not appear to be what you are wanting. >> -- >> Vernon Cole >> >> On Mon, Sep 17, 2012 at 4:42 AM, wrote: >> >>> Hello. >>> For example in the text of the module meets the command: >>> ttt(4, x = 7) >>> where and how to define __ getattr__ to handle it? >>> Thank you. >>> >>> _______________________________________________ >>> Ironpython-users mailing list >>> Ironpython-users at python.org >>> http://mail.python.org/mailman/listinfo/ironpython-users >>> >> > > > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users From vernondcole at gmail.com Mon Sep 17 22:50:30 2012 From: vernondcole at gmail.com (Vernon Cole) Date: Mon, 17 Sep 2012 14:50:30 -0600 Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> Message-ID: On Mon, Sep 17, 2012 at 11:17 AM, wrote: > Hello, Vernon Cole. > Or you probably do not understand the question, or I did not properly > posed the question. > I know I can define a function (ttt). And if I'm interested in __ > getattr__, so in this case it can not be determined, or its name and > parameters are defined at run time. > Thank you. > > The name of a function must be defined somewhere, or it cannot be called. It can be defined for arbitrary argument lists. See http://docs.python.org/tutorial/controlflow.html#arbitrary-argument-lists Here is an example... from __future__ import print_function def f(*p, **k): print('Your positional arguments were',repr(p)) print('Your keyword arguments were',repr(k)) print('An empty call...') f() print("A call with f(1,'two',spam=3,eggs='four')...") f(1,'two',spam=3,eggs='four') which gives a result as follows... C:\Users\vernon\x>"c:\program files (x86)\IronPython 2.7\ipy64" x.py An empty call... Your positional arguments were () Your keyword arguments were {} A call with f(1,'two',spam=3,eggs='four')... Your positional arguments were (1, 'two') Your keyword arguments were {'eggs': 'four', 'spam': 3} The __getattr__ method is defined for class "object". In order to use it, you must define a class which overrides the __getattr__ method. In the code below, I define a class with method "f" like the function above, which takes an arbitrary argument list. Then I create an instance of that class called "d". d.__getattr__ returns an instance of d.f() which can then be called with arbitrary arguments. ** NOTE: this is weird code. It probably should never be used in a production environment. ** from __future__ import print_function class DontKnow(object): def f(*p, **k): print('Your positional arguments were',repr(p)) print('Your keyword arguments were',repr(k)) def __getattr__(self,name): print('You tried using',repr(name)) return self.f d = DontKnow() print('An empty call...') d.f() print("A call with f(1,'two',spam=3,eggs='four')...") d.f(1,'two',spam=3,eggs='four') print("A call to d.g") d.g print("A call to d.g(10,20,cheese='chedder')...") d.g(10,20,cheese='chedder') C:\Users\vernon\x>"c:\program files (x86)\IronPython 2.7\ipy64" x.py An empty call... Your positional arguments were (,) Your keyword arguments were {} A call with f(1,'two',spam=3,eggs='four')... Your positional arguments were (, 1, 'two') Your keyword arguments were {'eggs': 'four', 'spam': 3} A call to d.g You tried using 'g' A call to d.g(10,20,cheese='chedder')... You tried using 'g' Your positional arguments were (, 10, 20) Your keyword arguments were {'cheese': 'chedder'} So there you have an arbitrary callable method name with an arbitrary argument list -- but you still need a defined object (like the DontKnow instance "d" above) to hook it to. -- Vernon > Dear Sir: > > Sorry, your question does not seem to make sense. > > Your example appears to be a simple function call with one keyword > > argument. To use it, you simply define the optional arguments when you > > define the function. See the documentation at: > > > http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions > > > > __getattr__ is only used within classes to emulate methods which do not > > actually exist. That does not appear to be what you are wanting. > > -- > > Vernon Cole > > > > On Mon, Sep 17, 2012 at 4:42 AM, wrote: > > > >> Hello. > >> For example in the text of the module meets the command: > >> ttt(4, x = 7) > >> where and how to define __ getattr__ to handle it? > >> Thank you. > >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Mon Sep 17 23:14:13 2012 From: vernondcole at gmail.com (Vernon Cole) Date: Mon, 17 Sep 2012 15:14:13 -0600 Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> Message-ID: Jeff: Why are your answers always so much better than mine? Vernon On Mon, Sep 17, 2012 at 2:27 PM, Jeff Hardy wrote: > The short answer is that you can't, in any version of Python. > > The longer answers can be found at > http://stackoverflow.com/questions/2447353/getattr-on-a-module. > > - Jeff > > On Mon, Sep 17, 2012 at 10:17 AM, wrote: > > Hello, Vernon Cole. > > Or you probably do not understand the question, or I did not properly > > posed the question. > > I know I can define a function (ttt). And if I'm interested in __ > > getattr__, so in this case it can not be determined, or its name and > > parameters are defined at run time. > > Thank you. > > > >> Dear Sir: > >> Sorry, your question does not seem to make sense. > >> Your example appears to be a simple function call with one keyword > >> argument. To use it, you simply define the optional arguments when you > >> define the function. See the documentation at: > >> > http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions > >> > >> __getattr__ is only used within classes to emulate methods which do not > >> actually exist. That does not appear to be what you are wanting. > >> -- > >> Vernon Cole > >> > >> On Mon, Sep 17, 2012 at 4:42 AM, wrote: > >> > >>> Hello. > >>> For example in the text of the module meets the command: > >>> ttt(4, x = 7) > >>> where and how to define __ getattr__ to handle it? > >>> Thank you. > >>> > >>> _______________________________________________ > >>> Ironpython-users mailing list > >>> Ironpython-users at python.org > >>> http://mail.python.org/mailman/listinfo/ironpython-users > >>> > >> > > > > > > _______________________________________________ > > Ironpython-users mailing list > > Ironpython-users at python.org > > http://mail.python.org/mailman/listinfo/ironpython-users > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sepatan at sibmail.com Tue Sep 18 07:11:54 2012 From: sepatan at sibmail.com (sepatan at sibmail.com) Date: Tue, 18 Sep 2012 12:11:54 +0700 (NOVT) Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> Message-ID: <58428.83.172.33.173.1347945114.squirrel@www.sibmail.com> Hello, Jeff Hardy ). 1) It is a good reference. But the methods must be defined in advance (class A). If I write ttt ('i') without defining it in the class A, I get an error. Use __getattr__ in class A does not work. class A(object): def salutation(self, accusative): # code def farewell(self, greeting, accusative): # code ...................... salutation("world") farewell("goodbye", "world") ttt('yy') name 'ttt' is not defined. 2) A good option would be: import sys class Foo(object): def __getattr__(self, t): print 'use __getattr__ - ', t return type(t, (object,), {}) def funct1(self): pass def funct2(self): pass sys.modules[__name__] = Foo() ttt('yy') name 'ttt' is not defined. __getattr__ not work (((. > The short answer is that you can't, in any version of Python. > > The longer answers can be found at > http://stackoverflow.com/questions/2447353/getattr-on-a-module. > > - Jeff > > On Mon, Sep 17, 2012 at 10:17 AM, wrote: >> Hello, Vernon Cole. >> Or you probably do not understand the question, or I did not properly >> posed the question. >> I know I can define a function (ttt). And if I'm interested in __ >> getattr__, so in this case it can not be determined, or its name and >> parameters are defined at run time. >> Thank you. >> >>> Dear Sir: >>> Sorry, your question does not seem to make sense. >>> Your example appears to be a simple function call with one keyword >>> argument. To use it, you simply define the optional arguments when you >>> define the function. See the documentation at: >>> http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions >>> >>> __getattr__ is only used within classes to emulate methods which do >>> not >>> actually exist. That does not appear to be what you are wanting. >>> -- >>> Vernon Cole >>> >>> On Mon, Sep 17, 2012 at 4:42 AM, wrote: >>> >>>> Hello. >>>> For example in the text of the module meets the command: >>>> ttt(4, x = 7) >>>> where and how to define __ getattr__ to handle it? >>>> Thank you. >>>> >>>> _______________________________________________ >>>> Ironpython-users mailing list >>>> Ironpython-users at python.org >>>> http://mail.python.org/mailman/listinfo/ironpython-users >>>> >>> >> >> >> _______________________________________________ >> Ironpython-users mailing list >> Ironpython-users at python.org >> http://mail.python.org/mailman/listinfo/ironpython-users > From vernondcole at gmail.com Tue Sep 18 16:15:25 2012 From: vernondcole at gmail.com (Vernon Cole) Date: Tue, 18 Sep 2012 08:15:25 -0600 Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: <58428.83.172.33.173.1347945114.squirrel@www.sibmail.com> References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> <58428.83.172.33.173.1347945114.squirrel@www.sibmail.com> Message-ID: On Mon, Sep 17, 2012 at 11:11 PM, wrote: > Hello, Jeff Hardy ). > 1) > It is a good reference. But the methods must be defined in advance (class > A). If I write ttt ('i') without defining it in the class A, I get an > error. Use __getattr__ in class A does not work. > > class A(object): > def salutation(self, accusative): > # code > > def farewell(self, greeting, accusative): > # code > ...................... > > salutation("world") > farewell("goodbye", "world") > ttt('yy') > name 'ttt' is not defined. > > Correct. Python is telling you that 'ttt' has no meaning. It does not, cannot, will never, do anything else. This is an error in your program. You must do something -- either a 'def', an assignment, or an include, to define 'ttt' before you use it. __getattr__() is used to catch undefined references from code in a _different_ module, not your own. Why would you go to the trouble of writing code in your own program to fix errors in itself? -- Vernon -------------- next part -------------- An HTML attachment was scrubbed... URL: From sepatan at sibmail.com Tue Sep 18 16:28:25 2012 From: sepatan at sibmail.com (sepatan at sibmail.com) Date: Tue, 18 Sep 2012 21:28:25 +0700 (NOVT) Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> <58428.83.172.33.173.1347945114.squirrel@www.sibmail.com> Message-ID: <1171.83.234.184.84.1347978505.squirrel@www.sibmail.com> Hello, Jeff Hardy ). The fact that the environment in which the plan is written mixed code. Operators Python runtime interpreter Python, operators are redirected to a different language version to another interpreter. It is necessary that when code appears key word in another language, Python captured them (__geattr__). And it needs to be implemented in the current module. I think Python deal with it)). May have many "copies to break"))). > On Mon, Sep 17, 2012 at 11:11 PM, wrote: > >> Hello, Jeff Hardy ). >> 1) >> It is a good reference. But the methods must be defined in advance >> (class >> A). If I write ttt ('i') without defining it in the class A, I get an >> error. Use __getattr__ in class A does not work. >> >> class A(object): >> def salutation(self, accusative): >> # code >> >> def farewell(self, greeting, accusative): >> # code >> ...................... >> >> salutation("world") >> farewell("goodbye", "world") >> ttt('yy') >> name 'ttt' is not defined. >> >> Correct. > Python is telling you that 'ttt' has no meaning. > It does not, cannot, will never, do anything else. > This is an error in your program. > You must do something -- either a 'def', an assignment, or an include, to > define 'ttt' before you use it. > __getattr__() is used to catch undefined references from code in a > _different_ module, not your own. > Why would you go to the trouble of writing code in your own program to fix > errors in itself? > -- > Vernon > From no_reply at codeplex.com Tue Sep 18 19:22:05 2012 From: no_reply at codeplex.com (no_reply at codeplex.com) Date: 18 Sep 2012 10:22:05 -0700 Subject: [Ironpython-users] IronPython, Daily Digest 9/17/2012 Message-ID: Hi ironpython, Here's your Daily Digest of new issues for project "IronPython". In today's digest:ISSUES 1. [New issue] sys.stdout.isatty() always returns True ---------------------------------------------- ISSUES 1. [New issue] sys.stdout.isatty() always returns True http://ironpython.codeplex.com/workitem/33123 User pekkaklarck has proposed the issue: "To reproduce: C:\>ipy -c "import sys; print sys.stdout.isatty()" True C:\>ipy -c "import sys; print sys.stdout.isatty()" > out C:\>type out True" ---------------------------------------------- ---------------------------------------------- You are receiving this email because you subscribed to notifications on CodePlex. To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at microsoft.com Tue Sep 18 20:22:25 2012 From: dinov at microsoft.com (Dino Viehland) Date: Tue, 18 Sep 2012 18:22:25 +0000 Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> Message-ID: Well you can subclass the module type and implement __getattr__, you just need to then publish the module in sys.modules yourself (or provide it via some import loader hook). >>> class C(type(sys)): ... def __getattr__(self, name): ... return 42 ... >>> import sys >>> sys.modules['foo'] = C('foo') >>> import foo >>> foo.blah 42 I haven't read the entire thread, so this might not actually be useful information :) -----Original Message----- From: Ironpython-users [mailto:ironpython-users-bounces+dinov=microsoft.com at python.org] On Behalf Of Jeff Hardy Sent: Monday, September 17, 2012 1:27 PM To: sepatan at sibmail.com Cc: ironpython-users at python.org Subject: Re: [Ironpython-users] How to use __ getattr__ to the current module? The short answer is that you can't, in any version of Python. The longer answers can be found at http://stackoverflow.com/questions/2447353/getattr-on-a-module. - Jeff On Mon, Sep 17, 2012 at 10:17 AM, wrote: > Hello, Vernon Cole. > Or you probably do not understand the question, or I did not properly > posed the question. > I know I can define a function (ttt). And if I'm interested in __ > getattr__, so in this case it can not be determined, or its name and > parameters are defined at run time. > Thank you. > >> Dear Sir: >> Sorry, your question does not seem to make sense. >> Your example appears to be a simple function call with one keyword >> argument. To use it, you simply define the optional arguments when >> you define the function. See the documentation at: >> http://docs.python.org/tutorial/controlflow.html#more-on-defining-fun >> ctions >> >> __getattr__ is only used within classes to emulate methods which do >> not actually exist. That does not appear to be what you are wanting. >> -- >> Vernon Cole >> >> On Mon, Sep 17, 2012 at 4:42 AM, wrote: >> >>> Hello. >>> For example in the text of the module meets the command: >>> ttt(4, x = 7) >>> where and how to define __ getattr__ to handle it? >>> Thank you. >>> >>> _______________________________________________ >>> Ironpython-users mailing list >>> Ironpython-users at python.org >>> http://mail.python.org/mailman/listinfo/ironpython-users >>> >> > > > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users _______________________________________________ Ironpython-users mailing list Ironpython-users at python.org http://mail.python.org/mailman/listinfo/ironpython-users From sepatan at sibmail.com Wed Sep 19 04:31:06 2012 From: sepatan at sibmail.com (sepatan at sibmail.com) Date: Wed, 19 Sep 2012 09:31:06 +0700 (NOVT) Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> Message-ID: <50027.83.172.33.173.1348021866.squirrel@www.sibmail.com> Hello, Dino Viehland ). Thank you for your participation. In your example foo is required. It works: class met(type): def __getattr__(cls, t): def __call__(cls, *args, **kw): class cl(object): __metaclass__=met cl(6,y=7).tt(3,yy=4) (and so on) but cl required. And must be so: tt(3,yy=4) (and so on) -------------------------------------------------- 1)Tried this: import types class cl_mod(types.ModuleType): def __getattr__(self, *args, **kw): sys.modules.setdefault('ppp', cl_mod('ppp')) import ppp #(or from ppp import *) tt(3,yy=4) (and so on) does not work ((. In __getattr__ does not go. 2)and so: class cl_mod(object): def __getattr__(self, *args, **kw): sys.modules[__name__]=cl_mod() tt(3,yy=4) (and so on) does not work ((. In __getattr__ does not go. Until all Waterloo (. But, I think that I will overcome). > Well you can subclass the module type and implement __getattr__, you just > need to then publish the module in sys.modules yourself (or provide it via > some import loader hook). > >>>> class C(type(sys)): > ... def __getattr__(self, name): > ... return 42 > ... >>>> import sys >>>> sys.modules['foo'] = C('foo') >>>> import foo >>>> foo.blah > 42 > > I haven't read the entire thread, so this might not actually be useful > information :) > > -----Original Message----- > From: Ironpython-users > [mailto:ironpython-users-bounces+dinov=microsoft.com at python.org] On Behalf > Of Jeff Hardy > Sent: Monday, September 17, 2012 1:27 PM > To: sepatan at sibmail.com > Cc: ironpython-users at python.org > Subject: Re: [Ironpython-users] How to use __ getattr__ to the current > module? > > The short answer is that you can't, in any version of Python. > > The longer answers can be found at > http://stackoverflow.com/questions/2447353/getattr-on-a-module. > > - Jeff > > On Mon, Sep 17, 2012 at 10:17 AM, wrote: >> Hello, Vernon Cole. >> Or you probably do not understand the question, or I did not properly >> posed the question. >> I know I can define a function (ttt). And if I'm interested in __ >> getattr__, so in this case it can not be determined, or its name and >> parameters are defined at run time. >> Thank you. >> >>> Dear Sir: >>> Sorry, your question does not seem to make sense. >>> Your example appears to be a simple function call with one keyword >>> argument. To use it, you simply define the optional arguments when >>> you define the function. See the documentation at: >>> http://docs.python.org/tutorial/controlflow.html#more-on-defining-fun >>> ctions >>> >>> __getattr__ is only used within classes to emulate methods which do >>> not actually exist. That does not appear to be what you are wanting. >>> -- >>> Vernon Cole >>> >>> On Mon, Sep 17, 2012 at 4:42 AM, wrote: >>> >>>> Hello. >>>> For example in the text of the module meets the command: >>>> ttt(4, x = 7) >>>> where and how to define __ getattr__ to handle it? >>>> Thank you. >>>> >>>> _______________________________________________ >>>> Ironpython-users mailing list >>>> Ironpython-users at python.org >>>> http://mail.python.org/mailman/listinfo/ironpython-users >>>> >>> >> >> >> _______________________________________________ >> Ironpython-users mailing list >> Ironpython-users at python.org >> http://mail.python.org/mailman/listinfo/ironpython-users > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users > > > > > > From niels at netbox.org Wed Sep 19 06:09:10 2012 From: niels at netbox.org (Niels Poppe) Date: Wed, 19 Sep 2012 06:09:10 +0200 Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: <50027.83.172.33.173.1348021866.squirrel@www.sibmail.com> References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> <50027.83.172.33.173.1348021866.squirrel@www.sibmail.com> Message-ID: <47F89BF8-B63E-41EC-AADF-AF76288EB515@netbox.org> # didn?t test any of this in IronPython # this may work and/or help you further # read on about eval, exec and execfile builtins at # http://docs.python.org/library/functions.html?highlight=execfile#execfile class GenericFunction(object): __slots__ = ('__name',) def __init__(self, name): self.__name = name def __call__(self, *args, **kwargs): print "called %s(args=%r, kwargs=%r)" % (self.__name, args, kwargs) class Locals(dict): def __getitem__(self, key): if not key in self: self[key] = GenericFunction(key) return super(Locals, self).__getitem__(key) exec("""tt(3, yy=4)""", globals(), Locals()) # python -i test.py called tt(args=(3,), kwargs={'yy': 4}) From sepatan at sibmail.com Wed Sep 19 07:24:52 2012 From: sepatan at sibmail.com (sepatan at sibmail.com) Date: Wed, 19 Sep 2012 12:24:52 +0700 (NOVT) Subject: [Ironpython-users] How to use __ getattr__ to the current module? In-Reply-To: <47F89BF8-B63E-41EC-AADF-AF76288EB515@netbox.org> References: <57812.83.172.33.173.1347878537.squirrel@www.sibmail.com> <3139.83.234.184.132.1347902275.squirrel@www.sibmail.com> <50027.83.172.33.173.1348021866.squirrel@www.sibmail.com> <47F89BF8-B63E-41EC-AADF-AF76288EB515@netbox.org> Message-ID: <34279.83.172.33.173.1348032292.squirrel@www.sibmail.com> Hello, Niels Poppe. Thank you. This is a good option. Once again, thank you)))). > # didn?t test any of this in IronPython > # this may work and/or help you further > # read on about eval, exec and execfile builtins at > # > http://docs.python.org/library/functions.html?highlight=execfile#execfile > > class GenericFunction(object): > __slots__ = ('__name',) > def __init__(self, name): > self.__name = name > def __call__(self, *args, **kwargs): > print "called %s(args=%r, kwargs=%r)" % (self.__name, args, > kwargs) > > class Locals(dict): > def __getitem__(self, key): > if not key in self: > self[key] = GenericFunction(key) > return super(Locals, self).__getitem__(key) > > exec("""tt(3, yy=4)""", globals(), Locals()) > > > # python -i test.py > called tt(args=(3,), kwargs={'yy': 4}) > > > > From no_reply at codeplex.com Wed Sep 19 18:27:40 2012 From: no_reply at codeplex.com (no_reply at codeplex.com) Date: 19 Sep 2012 09:27:40 -0700 Subject: [Ironpython-users] IronPython, Daily Digest 9/18/2012 Message-ID: Hi ironpython, Here's your Daily Digest of new issues for project "IronPython". In today's digest:ISSUES 1. [New comment] sys.stdout.isatty() always returns True 2. [New comment] sys.stdout.isatty() always returns True ---------------------------------------------- ISSUES 1. [New comment] sys.stdout.isatty() always returns True http://ironpython.codeplex.com/workitem/33123 User jdhardy has commented on the issue: "I don't think, in general, that IronPython can tell them apart, but False is probably safer."----------------- 2. [New comment] sys.stdout.isatty() always returns True http://ironpython.codeplex.com/workitem/33123 User pekkaklarck has commented on the issue: "It seems you cannot do this directly using .NET 4.0 APIs, but the information is available via win32 APIs: http://stackoverflow.com/questions/3453220/how-to-detect-if-console-in-stdin-has-been-redirected .NET 4.5 makes this easier: http://msdn.microsoft.com/en-us/library/system.console.isoutputredirected%28v=VS.110%29.aspx If this problem cannot be easily fixed under these circumstances, I actually prefer True over False as the return value. Well behaving tools that enable fancy console output when sys.stdout.isatty() is True work better currently. Really well behaving tools allow unconditionally turning fancy outputs off and that functionality can be used when redirecting." ---------------------------------------------- ---------------------------------------------- You are receiving this email because you subscribed to notifications on CodePlex. To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at microsoft.com Wed Sep 19 22:40:41 2012 From: dinov at microsoft.com (Dino Viehland) Date: Wed, 19 Sep 2012 20:40:41 +0000 Subject: [Ironpython-users] Python Tools for Visual Studio 1.5 RC Released Message-ID: We're pleased to announce the release of Python Tools for Visual Studio 1.5 RC. Python Tools for Visual Studio (PTVS) is an open-source plug-in for Visual Studio which supports programming with the Python language. PTVS supports a broad range of features including CPython/IronPython, Edit/Intellisense/Debug/Profile, Cloud, HPC, IPython, etc. support. The primary new feature for the 1.5 release is Django including Azure support! The http://www.djangoproject.com is a popular Python webframework/CMS which is used by many reputable companies and high-traffic websites. For Python on Azure support see: https://www.windowsazure.com/en-us/develop/python. In this RC release, the following improvements have been made based on your requests & feedback: * VS2012 support! * A Live Debug REPL - YT: http://www.youtube.com/watch?v=erNx2NLu-t4&hd=1 * Project load time improvements * Kinect 1.5 support * New "New Project from Existing Code!" * Improved intellisense (iterator, PyQt, ...) * Python 3.3 language support * Azure Python Client Lib improvements for Windows, Linux & MacOS There were over 80 fixes/improvements in this release. Unfortunately because of Codeplex's Release Notes character limit (sad), we can't list the summary of bug fixes, so here's a link to the data: http://bit.ly/Ptvs15RcBugs We'd like to thank the following people who took the time to report the issues and feedback for this release (in reverse chronological order): Tmaslach, odwalla, jrade, michiya, timeisparallax, tachiorz, sourbox, tramsay, bahrep, lqbest127, hyh, mrpy, boomer_74, BigFreakinGobot, AngeloBast, ajp, mahpour, cecilphillip, dhabersat. We'd also like to thank Weidong for his wonderful test support during the past few months & welcome Hugues aboard the project! -------------- next part -------------- An HTML attachment was scrubbed... URL: From slide.o.mix at gmail.com Wed Sep 19 22:53:54 2012 From: slide.o.mix at gmail.com (Slide) Date: Wed, 19 Sep 2012 13:53:54 -0700 Subject: [Ironpython-users] Python Tools for Visual Studio 1.5 RC Released In-Reply-To: References: Message-ID: On Wed, Sep 19, 2012 at 1:40 PM, Dino Viehland wrote: > We?re pleased to announce the release of Python Tools for Visual Studio 1.5 > RC. Python Tools for Visual Studio (PTVS) is an open-source plug-in for > Visual Studio which supports programming with the Python language. PTVS > supports a broad range of features including CPython/IronPython, > Edit/Intellisense/Debug/Profile, Cloud, HPC, IPython, etc. support. > > The primary new feature for the 1.5 release is Django including Azure > support! The http://www.djangoproject.com is a popular Python > webframework/CMS which is used by many reputable companies and high-traffic > websites. For Python on Azure support see: > https://www.windowsazure.com/en-us/develop/python. > > In this RC release, the following improvements have been made based on your > requests & feedback: > > ? VS2012 support! > ? A Live Debug REPL - YT: http://www.youtube.com/watch?v=erNx2NLu-t4&hd=1 > ? Project load time improvements > ? Kinect 1.5 support > ? New ?New Project from Existing Code!? > ? Improved intellisense (iterator, PyQt, ?) > ? Python 3.3 language support > ? Azure Python Client Lib improvements for Windows, Linux & MacOS > > > There were over 80 fixes/improvements in this release. Unfortunately because > of Codeplex's Release Notes character limit (sad), we can't list the summary > of bug fixes, so here's a link to the data: > > http://bit.ly/Ptvs15RcBugs > > We?d like to thank the following people who took the time to report the > issues and feedback for this release (in reverse chronological order): > > Tmaslach, odwalla, jrade, michiya, timeisparallax, tachiorz, sourbox, > tramsay, bahrep, lqbest127, hyh, mrpy, boomer_74, BigFreakinGobot, > AngeloBast, ajp, mahpour, cecilphillip, dhabersat. > > > We?d also like to thank Weidong for his wonderful test support during the > past few months & welcome Hugues aboard the project! > > > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users > Great news! Congrats Dino! I may switch to PTVS from PyDev. -- Website: http://earl-of-code.com From jdhardy at gmail.com Wed Sep 19 23:13:58 2012 From: jdhardy at gmail.com (Jeff Hardy) Date: Wed, 19 Sep 2012 14:13:58 -0700 Subject: [Ironpython-users] Python Tools for Visual Studio 1.5 RC Released In-Reply-To: References: Message-ID: On Wed, Sep 19, 2012 at 1:40 PM, Dino Viehland wrote: > We?re pleased to announce the release of Python Tools for Visual Studio 1.5 > RC. Python Tools for Visual Studio (PTVS) is an open-source plug-in for > Visual Studio which supports programming with the Python language. PTVS > supports a broad range of features including CPython/IronPython, > Edit/Intellisense/Debug/Profile, Cloud, HPC, IPython, etc. support. Awesome, I was waiting for VS2012 support so I could switch. Quick question: if I run 'Build' on a pyproj file from within VS, does it run the 'Build' target in the pyproj file? I have some craziness that I'd like to do in that case, so it would be fantastic if that's how it worked (ditto 'Rebuild' and 'Clean'). - Jeff From s.j.dower at gmail.com Thu Sep 20 02:35:27 2012 From: s.j.dower at gmail.com (Steve Dower) Date: Wed, 19 Sep 2012 17:35:27 -0700 Subject: [Ironpython-users] Python Tools for Visual Studio 1.5 RC Released In-Reply-To: References: Message-ID: It doesn't currently, but that will probably be a PTVS 2.0 feature. I'm not sure exactly what's involved yet, but I'd guess that all we have to do is invoke MSBuild. You're welcome to code it up yourself and send it in. That will be the quickest way to get it added (and once you're set up to build, you'll be able to grab all the new things we commit between releases). On Wed, Sep 19, 2012 at 2:13 PM, Jeff Hardy wrote: > On Wed, Sep 19, 2012 at 1:40 PM, Dino Viehland wrote: >> We?re pleased to announce the release of Python Tools for Visual Studio 1.5 >> RC. Python Tools for Visual Studio (PTVS) is an open-source plug-in for >> Visual Studio which supports programming with the Python language. PTVS >> supports a broad range of features including CPython/IronPython, >> Edit/Intellisense/Debug/Profile, Cloud, HPC, IPython, etc. support. > > Awesome, I was waiting for VS2012 support so I could switch. > > Quick question: if I run 'Build' on a pyproj file from within VS, does > it run the 'Build' target in the pyproj file? I have some craziness > that I'd like to do in that case, so it would be fantastic if that's > how it worked (ditto 'Rebuild' and 'Clean'). > > - Jeff > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users From jdhardy at gmail.com Thu Sep 20 05:33:18 2012 From: jdhardy at gmail.com (Jeff Hardy) Date: Wed, 19 Sep 2012 20:33:18 -0700 Subject: [Ironpython-users] Python Tools for Visual Studio 1.5 RC Released In-Reply-To: References: Message-ID: On Wed, Sep 19, 2012 at 5:35 PM, Steve Dower wrote: > It doesn't currently, but that will probably be a PTVS 2.0 feature. > I'm not sure exactly what's involved yet, but I'd guess that all we > have to do is invoke MSBuild. > > You're welcome to code it up yourself and send it in. That will be the > quickest way to get it added (and once you're set up to build, you'll > be able to grab all the new things we commit between releases). I was hoping to avoid that. I've been in the VS project system before ... not my idea of a good time. :) Is there a rough timeline for 2.0 - i.e. more or less than six months? - Jeff From doug.blank at gmail.com Thu Sep 20 06:43:03 2012 From: doug.blank at gmail.com (Doug Blank) Date: Thu, 20 Sep 2012 00:43:03 -0400 Subject: [Ironpython-users] Separating return values from printed values? Message-ID: IronPython users, Interesting question: we have IronPython embedded in a nice little educational GUI, and have the DLR output sent to our text output window where we can control the font color, etc. In teaching CS, it is always hard to try to get across the difference between a "return value" and a "displayed string". For example: >>> 22 22 >>> print(23) 23 >>> function() 22 where 22 is just a value, and 23 is a displayed string (a side-effect for you functional types). These GUIs don't make it easy to see the difference. One thing we've thought about is making a distinction between them with color, such that 22 might be blue, and 23 would be green. Can you think of an easy way to do that with IronPython and the DLR? Anything we could tap into to send evaluations one way, and displayed values another? Thanks for any suggestions, -Doug From rome at Wintellect.com Thu Sep 20 07:37:27 2012 From: rome at Wintellect.com (Keith Rome) Date: Thu, 20 Sep 2012 05:37:27 +0000 Subject: [Ironpython-users] Separating return values from printed values? In-Reply-To: References: Message-ID: <4C554C3A47C5024ABDE00E94DA17BC4D2B13B55C@BY2PRD0711MB417.namprd07.prod.outlook.com> This might give you what you need (hooking in via the runtime output writer, which is where the print function routes to), it seems to work for my quick test: using System; using System.IO; using System.Text; using IronPython.Hosting; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { RunScript("22"); RunScript("print(23)"); Console.ReadKey(); } static void RunScript(string script) { var engine = Python.CreateEngine(); var io = engine.Runtime.IO; io.SetOutput(io.OutputStream, new GreenWriter(io.OutputWriter)); var result = engine.Execute(script); if (result != null) Console.WriteLine(result); } } class GreenWriter : TextWriter { private readonly TextWriter _inner; public GreenWriter(TextWriter inner) { _inner = inner; } public override void Write(string value) { var original = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; _inner.Write(value); Console.ForegroundColor = original; } public override Encoding Encoding { get { return _inner.Encoding; } } } } Keith Rome Senior Consultant and Architect MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS Wintellect | 770.617.4016 | krome at wintellect.com www.wintellect.com -----Original Message----- From: Ironpython-users [mailto:ironpython-users-bounces+rome=wintellect.com at python.org] On Behalf Of Doug Blank Sent: Thursday, September 20, 2012 12:43 AM To: ironpython-users at python.org Subject: [Ironpython-users] Separating return values from printed values? IronPython users, Interesting question: we have IronPython embedded in a nice little educational GUI, and have the DLR output sent to our text output window where we can control the font color, etc. In teaching CS, it is always hard to try to get across the difference between a "return value" and a "displayed string". For example: >>> 22 22 >>> print(23) 23 >>> function() 22 where 22 is just a value, and 23 is a displayed string (a side-effect for you functional types). These GUIs don't make it easy to see the difference. One thing we've thought about is making a distinction between them with color, such that 22 might be blue, and 23 would be green. Can you think of an easy way to do that with IronPython and the DLR? Anything we could tap into to send evaluations one way, and displayed values another? Thanks for any suggestions, -Doug _______________________________________________ Ironpython-users mailing list Ironpython-users at python.org http://mail.python.org/mailman/listinfo/ironpython-users From doug.blank at gmail.com Thu Sep 20 12:44:24 2012 From: doug.blank at gmail.com (Doug Blank) Date: Thu, 20 Sep 2012 06:44:24 -0400 Subject: [Ironpython-users] Separating return values from printed values? In-Reply-To: <4C554C3A47C5024ABDE00E94DA17BC4D2B13B55C@BY2PRD0711MB417.namprd07.prod.outlook.com> References: <4C554C3A47C5024ABDE00E94DA17BC4D2B13B55C@BY2PRD0711MB417.namprd07.prod.outlook.com> Message-ID: On Thu, Sep 20, 2012 at 1:37 AM, Keith Rome wrote: > This might give you what you need (hooking in via the runtime output writer, which is where the print function routes to), it seems to work for my quick test: > > using System; > using System.IO; > using System.Text; > using IronPython.Hosting; > > namespace ConsoleApplication3 > { > class Program > { > static void Main(string[] args) > { > RunScript("22"); > RunScript("print(23)"); > Console.ReadKey(); > } > > static void RunScript(string script) > { > var engine = Python.CreateEngine(); > var io = engine.Runtime.IO; > io.SetOutput(io.OutputStream, new GreenWriter(io.OutputWriter)); > var result = engine.Execute(script); > if (result != null) > Console.WriteLine(result); > } > } > > class GreenWriter : TextWriter > { > private readonly TextWriter _inner; > public GreenWriter(TextWriter inner) > { > _inner = inner; > } > public override void Write(string value) > { > var original = Console.ForegroundColor; > Console.ForegroundColor = ConsoleColor.Green; > _inner.Write(value); > Console.ForegroundColor = original; > } > public override Encoding Encoding > { > get { return _inner.Encoding; } > } > } > } > Thanks for the example! I guess we also have some other issues which may cause use to be unable to use that interface, or maybe our code is overly complicated? We: * use a shared scope, if available so other DLR languages can interoperate (manager.scope below) * compile the code, perhaps with options (for speed and feedback, I guess) * make a distinction between different SourceCodeKinds (for the compiler, I guess) * thus, we don't have a return value; the system automatically prints it (?) * we try/catch each step to give feedback to the student Here is our Execute: sctype = Microsoft.Scripting.SourceCodeKind.InteractiveCode; source = engine.CreateScriptSourceFromString(text, sctype); try { if (compiler_options != null) { source.Compile(compiler_options); } else { source.Compile(); } } catch { sctype = Microsoft.Scripting.SourceCodeKind.Statements; source = engine.CreateScriptSourceFromString(text, sctype); try { if (compiler_options != null) { source.Compile(compiler_options); } else { source.Compile(); } } catch (Exception e) { eo = engine.GetService(); PrintLine(eo.FormatException(e)); return false; } } try { if (manager != null && manager.UseSharedScope) source.Execute(manager.scope); else source.Execute(scope); } catch (Exception e) { if (e.Message.Contains("Thread was being aborted")) { manager.stderr.Print("[Script stopped----------]\n"); } else { eo = engine.GetService(); PrintLine(eo.FormatException(e)); } return false; } if (manager.stderr != null) PrintLine(Tag.Info, "Ok"); Is there a way using this interface, or is our code too much, and we could get by with less? -Doug > Keith Rome > Senior Consultant and Architect > MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS > Wintellect | 770.617.4016 | krome at wintellect.com > www.wintellect.com > > -----Original Message----- > From: Ironpython-users [mailto:ironpython-users-bounces+rome=wintellect.com at python.org] On Behalf Of Doug Blank > Sent: Thursday, September 20, 2012 12:43 AM > To: ironpython-users at python.org > Subject: [Ironpython-users] Separating return values from printed values? > > IronPython users, > > Interesting question: we have IronPython embedded in a nice little educational GUI, and have the DLR output sent to our text output window where we can control the font color, etc. > > In teaching CS, it is always hard to try to get across the difference between a "return value" and a "displayed string". For example: > >>>> 22 > 22 >>>> print(23) > 23 >>>> function() > 22 > > where 22 is just a value, and 23 is a displayed string (a side-effect for you functional types). These GUIs don't make it easy to see the difference. > > One thing we've thought about is making a distinction between them with color, such that 22 might be blue, and 23 would be green. > > Can you think of an easy way to do that with IronPython and the DLR? > Anything we could tap into to send evaluations one way, and displayed values another? > > Thanks for any suggestions, > > -Doug > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users > > From jhcd.jhcd at gmail.com Thu Sep 20 16:48:34 2012 From: jhcd.jhcd at gmail.com (John Dickinson) Date: Thu, 20 Sep 2012 15:48:34 +0100 Subject: [Ironpython-users] struct pack / unpack not thread safe? Message-ID: I have at least two threads that end up calling struct.pack and struct.unpack, and regularly get two exceptions: "SystemError: Object reference not set to an instance of an object." and "SystemError: The LinkedList node does not belong to current LinkedList.". The following code reproduces the problem: import threading import struct import time import traceback import sys class TestThread(threading.Thread): def __init__(self): super(TestThread, self).__init__() self.setDaemon(True) def run(self): while True: try: struct.unpack('!H', '\x4f\x00') struct.pack('H', 20224) time.sleep(0.005) except Exception, e: print(str(e)) traceback.print_exception(*sys.exc_info()) if __name__ == '__main__': thread_1 = TestThread() thread_2 = TestThread() thread_1.start() thread_2.start() while True: print(".") time.sleep(1) (adding more TestThreads makes the error occur more regularly). Running the same code in CPython (2.7) I get no errors (presumably because of the GIL). It seems that struct isn't thread safe - is this a bug? I'm running IronPython "2.7.3 (2.7.0.40) on .NET 4.0.30319.269 (32-bit)" on Windows 7. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jhcd.jhcd at gmail.com Thu Sep 20 16:56:51 2012 From: jhcd.jhcd at gmail.com (John Dickinson) Date: Thu, 20 Sep 2012 15:56:51 +0100 Subject: [Ironpython-users] struct pack / unpack not thread safe? In-Reply-To: References: Message-ID: Sorry, I've just found this: http://ironpython.codeplex.com/workitem/30228so I see that it is a bug. On Thu, Sep 20, 2012 at 3:48 PM, John Dickinson wrote: > I have at least two threads that end up calling struct.pack and > struct.unpack, and regularly get two exceptions: "SystemError: Object > reference not set to an instance of an object." and "SystemError: The > LinkedList node does not belong to current LinkedList.". The following code > reproduces the problem: > > import threading > import struct > import time > import traceback > import sys > > class TestThread(threading.Thread): > > def __init__(self): > super(TestThread, self).__init__() > self.setDaemon(True) > > def run(self): > while True: > try: > struct.unpack('!H', '\x4f\x00') > struct.pack('H', 20224) > time.sleep(0.005) > except Exception, e: > print(str(e)) > traceback.print_exception(*sys.exc_info()) > > if __name__ == '__main__': > > thread_1 = TestThread() > thread_2 = TestThread() > > thread_1.start() > thread_2.start() > > while True: > print(".") > time.sleep(1) > > (adding more TestThreads makes the error occur more regularly). Running > the same code in CPython (2.7) I get no errors (presumably because of the > GIL). It seems that struct isn't thread safe - is this a bug? I'm running > IronPython "2.7.3 (2.7.0.40) on .NET 4.0.30319.269 (32-bit)" on Windows 7. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jhcd.jhcd at gmail.com Thu Sep 20 16:58:58 2012 From: jhcd.jhcd at gmail.com (John Dickinson) Date: Thu, 20 Sep 2012 15:58:58 +0100 Subject: [Ironpython-users] struct pack / unpack not thread safe? In-Reply-To: References: Message-ID: http://ironpython.codeplex.com/workitem/30228 On Thu, Sep 20, 2012 at 3:56 PM, John Dickinson wrote: > Sorry, I've just found this: http://ironpython.codeplex.com/workitem/30228so I see that it is a bug. > > On Thu, Sep 20, 2012 at 3:48 PM, John Dickinson wrote: > >> I have at least two threads that end up calling struct.pack and >> struct.unpack, and regularly get two exceptions: "SystemError: Object >> reference not set to an instance of an object." and "SystemError: The >> LinkedList node does not belong to current LinkedList.". The following code >> reproduces the problem: >> >> import threading >> import struct >> import time >> import traceback >> import sys >> >> class TestThread(threading.Thread): >> >> def __init__(self): >> super(TestThread, self).__init__() >> self.setDaemon(True) >> >> def run(self): >> while True: >> try: >> struct.unpack('!H', '\x4f\x00') >> struct.pack('H', 20224) >> time.sleep(0.005) >> except Exception, e: >> print(str(e)) >> traceback.print_exception(*sys.exc_info()) >> >> if __name__ == '__main__': >> >> thread_1 = TestThread() >> thread_2 = TestThread() >> >> thread_1.start() >> thread_2.start() >> >> while True: >> print(".") >> time.sleep(1) >> >> (adding more TestThreads makes the error occur more regularly). Running >> the same code in CPython (2.7) I get no errors (presumably because of the >> GIL). It seems that struct isn't thread safe - is this a bug? I'm running >> IronPython "2.7.3 (2.7.0.40) on .NET 4.0.30319.269 (32-bit)" on Windows 7. >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no_reply at codeplex.com Thu Sep 20 17:15:05 2012 From: no_reply at codeplex.com (no_reply at codeplex.com) Date: 20 Sep 2012 08:15:05 -0700 Subject: [Ironpython-users] IronPython, Daily Digest 9/19/2012 Message-ID: Hi ironpython, Here's your Daily Digest of new issues for project "IronPython". In today's digest:ISSUES 1. [New issue] boolean type from databinding is not json compatible 2. [New issue] Lower casing non-ASCII characters does not work 3. [New comment] Lower casing non-ASCII characters does not work 4. [New comment] Lower casing non-ASCII characters does not work ---------------------------------------------- ISSUES 1. [New issue] boolean type from databinding is not json compatible http://ironpython.codeplex.com/workitem/33134 User barbar01 has proposed the issue: "You have to cast explicit with bool(a) if a is a boolean set by databinding. json.dumps(a) would create a small written "true","false" which json could not reload."----------------- 2. [New issue] Lower casing non-ASCII characters does not work http://ironpython.codeplex.com/workitem/33133 User pekkaklarck has proposed the issue: "Interestingly upper() works but lower() doesn't. Tested with some Scandinavian letters but not with other scripts. To reproduce: IronPython 2.7.3 (2.7.0.40) on .NET 4.0.30319.269 (32-bit) Type "help", "copyright", "credits" or "license" for more information. >>> a = u'\xe4' # Character '?' >>> A = a.upper() >>> A u'\xc4' # Correctly produces '?' >>> a.islower() True >>> A.islower() False >>> A.lower() u'\xc4' # Wrong! Still '?' >>> A.lower() == a False >>> A.lower() == A True"----------------- 3. [New comment] Lower casing non-ASCII characters does not work http://ironpython.codeplex.com/workitem/33133 User pekkaklarck has commented on the issue: "Very interestingly swapcase() works: >>> a = u'\xe4' >>> A = a.upper() >>> A.swapcase() == a True >>> a.swapcase() == A True This allowed me to create the following workaround function: def lower(string): return ''.join(c if not c.isupper() else c.swapcase() for c in string) "----------------- 4. [New comment] Lower casing non-ASCII characters does not work http://ironpython.codeplex.com/workitem/33133 User pekkaklarck has commented on the issue: "My workaround function was unfortunately slow but could luckily be optimized in common case (including when not running on IronPython). Here's the final code: if sys.platform != 'cli': def lower(string): return string.lower() else: def lower(string): if string.islower(): return string if not _has_non_ascii_chars(string): return string.lower() return ''.join(c if not c.isupper() else c.swapcase() for c in string) def _has_non_ascii_chars(string): for c in string: if c >= u'\x80': return True return False " ---------------------------------------------- ---------------------------------------------- You are receiving this email because you subscribed to notifications on CodePlex. To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rome at Wintellect.com Thu Sep 20 17:48:04 2012 From: rome at Wintellect.com (Keith Rome) Date: Thu, 20 Sep 2012 15:48:04 +0000 Subject: [Ironpython-users] Separating return values from printed values? In-Reply-To: References: <4C554C3A47C5024ABDE00E94DA17BC4D2B13B55C@BY2PRD0711MB417.namprd07.prod.outlook.com> Message-ID: <4C554C3A47C5024ABDE00E94DA17BC4D2B13B8DF@BY2PRD0711MB417.namprd07.prod.outlook.com> That should be fine. My example was the simplest way possible to spin up a script, so I didn't bother with an explicit scope. But that doesn't change anything really. Also if you re-use the same engine many times, you only really need to wire up the custom output writer once - after initial engine creation. You can also make the TextWriter slightly smarter and ensure that it only colorizes text that comes from the print function. There isn't a straightforward way to do that, but you can cheat and check the call stack. As long as your code is full-trust then this shouldn't be an issue. This version might be a little more suitable and complete after seeing your example. I still had to make some assumptions about how your Execute is being handled, but this should at least be fairly close: using System; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using IronPython.Compiler; using IronPython.Hosting; using IronPython.Runtime; using Microsoft.Scripting; using Microsoft.Scripting.Hosting; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { var scripting = new Scripting(); scripting.RunScript("22"); scripting.RunScript("print(23)"); Console.ReadKey(); } } internal class Scripting { private readonly ScriptEngine _engine; private readonly ScriptScope _scope; private readonly CompilerOptions _options; private readonly ConsoleWriter _green; private readonly PythonFile _stderr; private readonly PythonFile _stdin; private readonly PythonFile _stdout; public Scripting() { _engine = Python.CreateEngine(); var io = _engine.Runtime.IO; _green = new ConsoleWriter(io.OutputWriter, ConsoleColor.Green); io.SetOutput(io.OutputStream, _green); _scope = _engine.CreateScope(); _options = new PythonCompilerOptions(ModuleOptions.None); var sys = _engine.GetSysModule(); _stderr = sys.GetVariable("stderr"); _stdin = sys.GetVariable("stdin"); _stdout = sys.GetVariable("stdout"); } public bool RunScript(string text) { var sctype = SourceCodeKind.InteractiveCode; var source = _engine.CreateScriptSourceFromString(text, sctype); try { source.Compile(_options); } catch { sctype = SourceCodeKind.Statements; source = _engine.CreateScriptSourceFromString(text, sctype); try { source.Compile(_options); } catch (Exception e) { var eo = _engine.GetService(); PrintLine(eo.FormatException(e)); return false; } } try { _green.IsEnabled = true; try { source.Execute(_scope); } finally { _green.IsEnabled = false; } } catch (Exception e) { if (e.Message.Contains("Thread was being aborted")) { _stderr.write("[Script stopped----------]\n"); } else { var eo = _engine.GetService(); PrintLine(eo.FormatException(e)); } return false; } if (_stderr != null) PrintLine("Ok"); return true; } void PrintLine(string msg) { _stdout.write(msg + Environment.NewLine); } } class ConsoleWriter : TextWriter { private readonly TextWriter _inner; public bool IsEnabled { get; set; } public ConsoleColor Color { get; set; } public ConsoleWriter(TextWriter inner, ConsoleColor color) { _inner = inner; Color = color; } public override void Write(string value) { var enabled = IsEnabled; if (enabled) { var stack = (new StackTrace()).GetFrames() ?? new StackFrame[0]; var indexed = stack.Select((f, ix) => new {mInfo = f.GetMethod(), ix}); var printFrameQuery = from frame in indexed where frame.mInfo.Name == "Print" && frame.mInfo.DeclaringType == typeof (IronPython.Runtime.Operations.PythonOps) select frame; var printFrame = printFrameQuery.FirstOrDefault(); if (printFrame != null) { var printFrameCallerIx = printFrame.ix + 1; var caller = stack[printFrameCallerIx].GetMethod(); var isHook = caller.DeclaringType == typeof (IronPython.Modules.SysModule) && caller.Name == "displayhookImpl"; // only apply color if this is a message being written by the print() function // but not if print() was called via internal sys displayhook - which should // leave only explicit print() calls enabled = !isHook; } } if (!enabled) { _inner.Write(value); return; } var original = Console.ForegroundColor; Console.ForegroundColor = Color; _inner.Write(value); Console.ForegroundColor = original; } public override Encoding Encoding { get { return _inner.Encoding; } } } } Keith Rome Senior Consultant and Architect MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS Wintellect | 770.617.4016 | krome at wintellect.com www.wintellect.com -----Original Message----- From: Doug Blank [mailto:doug.blank at gmail.com] Sent: Thursday, September 20, 2012 6:44 AM To: Keith Rome Cc: ironpython-users at python.org Subject: Re: [Ironpython-users] Separating return values from printed values? On Thu, Sep 20, 2012 at 1:37 AM, Keith Rome wrote: > This might give you what you need (hooking in via the runtime output writer, which is where the print function routes to), it seems to work for my quick test: > > using System; > using System.IO; > using System.Text; > using IronPython.Hosting; > > namespace ConsoleApplication3 > { > class Program > { > static void Main(string[] args) > { > RunScript("22"); > RunScript("print(23)"); > Console.ReadKey(); > } > > static void RunScript(string script) > { > var engine = Python.CreateEngine(); > var io = engine.Runtime.IO; > io.SetOutput(io.OutputStream, new GreenWriter(io.OutputWriter)); > var result = engine.Execute(script); > if (result != null) > Console.WriteLine(result); > } > } > > class GreenWriter : TextWriter > { > private readonly TextWriter _inner; > public GreenWriter(TextWriter inner) > { > _inner = inner; > } > public override void Write(string value) > { > var original = Console.ForegroundColor; > Console.ForegroundColor = ConsoleColor.Green; > _inner.Write(value); > Console.ForegroundColor = original; > } > public override Encoding Encoding > { > get { return _inner.Encoding; } > } > } > } > Thanks for the example! I guess we also have some other issues which may cause use to be unable to use that interface, or maybe our code is overly complicated? We: * use a shared scope, if available so other DLR languages can interoperate (manager.scope below) * compile the code, perhaps with options (for speed and feedback, I guess) * make a distinction between different SourceCodeKinds (for the compiler, I guess) * thus, we don't have a return value; the system automatically prints it (?) * we try/catch each step to give feedback to the student Here is our Execute: sctype = Microsoft.Scripting.SourceCodeKind.InteractiveCode; source = engine.CreateScriptSourceFromString(text, sctype); try { if (compiler_options != null) { source.Compile(compiler_options); } else { source.Compile(); } } catch { sctype = Microsoft.Scripting.SourceCodeKind.Statements; source = engine.CreateScriptSourceFromString(text, sctype); try { if (compiler_options != null) { source.Compile(compiler_options); } else { source.Compile(); } } catch (Exception e) { eo = engine.GetService(); PrintLine(eo.FormatException(e)); return false; } } try { if (manager != null && manager.UseSharedScope) source.Execute(manager.scope); else source.Execute(scope); } catch (Exception e) { if (e.Message.Contains("Thread was being aborted")) { manager.stderr.Print("[Script stopped----------]\n"); } else { eo = engine.GetService(); PrintLine(eo.FormatException(e)); } return false; } if (manager.stderr != null) PrintLine(Tag.Info, "Ok"); Is there a way using this interface, or is our code too much, and we could get by with less? -Doug > Keith Rome > Senior Consultant and Architect > MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS Wintellect | > 770.617.4016 | krome at wintellect.com www.wintellect.com > > -----Original Message----- > From: Ironpython-users > [mailto:ironpython-users-bounces+rome=wintellect.com at python.org] On > Behalf Of Doug Blank > Sent: Thursday, September 20, 2012 12:43 AM > To: ironpython-users at python.org > Subject: [Ironpython-users] Separating return values from printed values? > > IronPython users, > > Interesting question: we have IronPython embedded in a nice little educational GUI, and have the DLR output sent to our text output window where we can control the font color, etc. > > In teaching CS, it is always hard to try to get across the difference between a "return value" and a "displayed string". For example: > >>>> 22 > 22 >>>> print(23) > 23 >>>> function() > 22 > > where 22 is just a value, and 23 is a displayed string (a side-effect for you functional types). These GUIs don't make it easy to see the difference. > > One thing we've thought about is making a distinction between them with color, such that 22 might be blue, and 23 would be green. > > Can you think of an easy way to do that with IronPython and the DLR? > Anything we could tap into to send evaluations one way, and displayed values another? > > Thanks for any suggestions, > > -Doug > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users > > From doug.blank at gmail.com Thu Sep 20 18:15:04 2012 From: doug.blank at gmail.com (Doug Blank) Date: Thu, 20 Sep 2012 12:15:04 -0400 Subject: [Ironpython-users] Separating return values from printed values? In-Reply-To: <4C554C3A47C5024ABDE00E94DA17BC4D2B13B8DF@BY2PRD0711MB417.namprd07.prod.outlook.com> References: <4C554C3A47C5024ABDE00E94DA17BC4D2B13B55C@BY2PRD0711MB417.namprd07.prod.outlook.com> <4C554C3A47C5024ABDE00E94DA17BC4D2B13B8DF@BY2PRD0711MB417.namprd07.prod.outlook.com> Message-ID: On Thu, Sep 20, 2012 at 11:48 AM, Keith Rome wrote: > That should be fine. My example was the simplest way possible to spin up a script, so I didn't bother with an explicit scope. But that doesn't change anything really. Also if you re-use the same engine many times, you only really need to wire up the custom output writer once - after initial engine creation. > > You can also make the TextWriter slightly smarter and ensure that it only colorizes text that comes from the print function. There isn't a straightforward way to do that, but you can cheat and check the call stack. As long as your code is full-trust then this shouldn't be an issue. > > This version might be a little more suitable and complete after seeing your example. I still had to make some assumptions about how your Execute is being handled, but this should at least be fairly close: > Wow, Keith! That is amazing, and amazing that you wrote this for us! I'll give it a try... looks a little sketching diving into the stack... but this is useful for other uses perhaps also... Whole lotta thanks! -Doug From jdhardy at gmail.com Thu Sep 20 19:13:00 2012 From: jdhardy at gmail.com (Jeff Hardy) Date: Thu, 20 Sep 2012 10:13:00 -0700 Subject: [Ironpython-users] struct pack / unpack not thread safe? In-Reply-To: References: Message-ID: Thanks for bringing this up. Unfortunately the bug database is so deep that some important ones have fallen through the cracks. - Jeff On Thu, Sep 20, 2012 at 7:56 AM, John Dickinson wrote: > Sorry, I've just found this: http://ironpython.codeplex.com/workitem/30228 > so I see that it is a bug. > > > On Thu, Sep 20, 2012 at 3:48 PM, John Dickinson wrote: >> >> I have at least two threads that end up calling struct.pack and >> struct.unpack, and regularly get two exceptions: "SystemError: Object >> reference not set to an instance of an object." and "SystemError: The >> LinkedList node does not belong to current LinkedList.". The following code >> reproduces the problem: >> >> import threading >> import struct >> import time >> import traceback >> import sys >> >> class TestThread(threading.Thread): >> >> def __init__(self): >> super(TestThread, self).__init__() >> self.setDaemon(True) >> >> def run(self): >> while True: >> try: >> struct.unpack('!H', '\x4f\x00') >> struct.pack('H', 20224) >> time.sleep(0.005) >> except Exception, e: >> print(str(e)) >> traceback.print_exception(*sys.exc_info()) >> >> if __name__ == '__main__': >> >> thread_1 = TestThread() >> thread_2 = TestThread() >> >> thread_1.start() >> thread_2.start() >> >> while True: >> print(".") >> time.sleep(1) >> >> (adding more TestThreads makes the error occur more regularly). Running >> the same code in CPython (2.7) I get no errors (presumably because of the >> GIL). It seems that struct isn't thread safe - is this a bug? I'm running >> IronPython "2.7.3 (2.7.0.40) on .NET 4.0.30319.269 (32-bit)" on Windows 7. >> > > > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users > From deniskolodin at gmail.com Fri Sep 21 21:32:06 2012 From: deniskolodin at gmail.com (Denis Kolodin) Date: Fri, 21 Sep 2012 23:32:06 +0400 Subject: [Ironpython-users] How to get char pointer for LPCSTR Message-ID: Hi! Help please! I have to run this code: from ctypes.wintypes import LPCSTR, LPSTR, DWORD dwErrorMessageSize = DWORD(200) lpstrErrorMessage = LPCSTR(b'\000' * dwErrorMessageSize.value) but it fails with error: TypeError: expected char pointer, got bytes This code works well in CPython. How can I run it in IronPython or how to create char pointer? Thank you, Denis Kolodin From no_reply at codeplex.com Sat Sep 22 12:49:41 2012 From: no_reply at codeplex.com (no_reply at codeplex.com) Date: 22 Sep 2012 03:49:41 -0700 Subject: [Ironpython-users] IronPython, Daily Digest 9/21/2012 Message-ID: Hi ironpython, Here's your Daily Digest of new issues for project "IronPython". In today's digest:ISSUES 1. [New comment] compile does not accept AST object 2. [New issue] ctypes.wintypes.LPCSTR doesn't works correctly 3. [New issue] httplib.HTTPSConnection has difficulty parsing certificates ---------------------------------------------- ISSUES 1. [New comment] compile does not accept AST object http://ironpython.codeplex.com/workitem/32526 User jdhardy has commented on the issue: "Fixed in 144a378. Thanks, Pawel."----------------- 2. [New issue] ctypes.wintypes.LPCSTR doesn't works correctly http://ironpython.codeplex.com/workitem/33145 User DenisKolodin has proposed the issue: "This code works in Python: from ctypes.wintypes import LPCSTR lpstr = LPCSTR(b'\000') but doesn't work in IronPython! Fails with error: TypeError: expected char pointer, got bytes"----------------- 3. [New issue] httplib.HTTPSConnection has difficulty parsing certificates http://ironpython.codeplex.com/workitem/33146 User mooch has proposed the issue: "I wrote a small Python script that establishes an HTTPS connection and uploads some data. On CPython this works as expected, but on IronPython it fails with "Error decoding PEM-encoded file."" ---------------------------------------------- ---------------------------------------------- You are receiving this email because you subscribed to notifications on CodePlex. To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no_reply at codeplex.com Wed Sep 26 17:43:27 2012 From: no_reply at codeplex.com (no_reply at codeplex.com) Date: 26 Sep 2012 08:43:27 -0700 Subject: [Ironpython-users] IronPython, Daily Digest 9/25/2012 Message-ID: Hi ironpython, Here's your Daily Digest of new issues for project "IronPython". In today's digest:ISSUES 1. [New issue] introduce support for readline module (raw input) ---------------------------------------------- ISSUES 1. [New issue] introduce support for readline module (raw input) http://ironpython.codeplex.com/workitem/33164 User paweljasinski has proposed the issue: "This is to track changes required to (re) introduce support for readline module. There is a relevant item which probably could be closed: http://ironpython.codeplex.com/workitem/697 Details: On Sun, Jun 24, 2012 at 11:10 AM, Pawel Jasinski wrote: > hi, > > the documentation of raw_input says: > > "If the readline module was loaded, then raw_input() will use it to > provide elaborate line editing and history features." > > Which translates to calling raw_input equivalent inside readline module. > > In case of cpython readline is built-in and there is no public > interface for it. > Readline knows about and has direct access to the internals of python > and swaps the raw_input implementation. > > In case of ironpython it is different. > Readline is an external module. > It used to work by tinkering with console internal state. > This was done in 1.x days, required patching of ironpython code and is > broken now. > > I would like to fix it. > So far I have modified raw_input to check if readliine was loaded and > call internal things of the readline module. > It appears to work but is there a better way? As long as it works without readline, and it's not *too* terrible of a hack, that should be fine. There are a few modules (zipimport comes to mind) that slot into CPython in weird ways, and we might be stuck with them. It might be interesting to use some of the functionality in SuperConsole to implement history w/o readline, but I imagine readline's specific details (C-r, C-e, C-a, etc.) are wired into a lot of people's fingers, and so having the actual readline available is probably a good idea. All the more reason to fix the packaging story for IronPython so that readline can be easily distributed." ---------------------------------------------- ---------------------------------------------- You are receiving this email because you subscribed to notifications on CodePlex. To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pawel.jasinski at gmail.com Thu Sep 27 10:37:05 2012 From: pawel.jasinski at gmail.com (Pawel Jasinski) Date: Thu, 27 Sep 2012 10:37:05 +0200 Subject: [Ironpython-users] utf in source \u00F8 Message-ID: hi, Jeff pointed out that there is something strange with the code I have submitted. It is about main/Languages/IronPython/IronPython/Runtime/PythonModule.cs We have seen quite a few things with args\u00F8 e.g.: public static PythonModule/*!*/ __new__(CodeContext/*!*/ context, PythonType/*!*/ cls, params object[]/*!*/ args\u00F8) { I assumed it had to do with my editor or locale or whatever I did with my repo and it will get converted to crossed o (?) on commit. However today I made a fresh clone with virgin install of git on linux. The \u00F8 is there. The file in question does not have BOM: 0000000 2f 2a 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a Here is exactly what I have done: > git clone https://github.com/IronLanguages/main.git and my settings: core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* remote.origin.url=https://github.com/IronLanguages/main.git branch.master.remote=origin branch.master.merge=refs/heads/master I must be missing something or perhaps it used to be ? and got converted during migration? grep -Irsin '\\u00f8' * | wc -l returns 68 Please, help. --pawel From pawel.jasinski at gmail.com Thu Sep 27 11:09:47 2012 From: pawel.jasinski at gmail.com (Pawel Jasinski) Date: Thu, 27 Sep 2012 11:09:47 +0200 Subject: [Ironpython-users] utf in source \u00F8 In-Reply-To: References: Message-ID: Short update I have looked at 2.6 in codeplex and the \u00f8 is there, so I think it is not my editor or my git settings. http://ironpython.codeplex.com/SourceControl/changeset/view/87420#992096 From no_reply at codeplex.com Thu Sep 27 15:03:15 2012 From: no_reply at codeplex.com (no_reply at codeplex.com) Date: 27 Sep 2012 06:03:15 -0700 Subject: [Ironpython-users] IronPython, Daily Digest 9/26/2012 Message-ID: Hi ironpython, Here's your Daily Digest of new issues for project "IronPython". In today's digest:ISSUES 1. [New issue] match cpython behaviour - types.ModuleType() ---------------------------------------------- ISSUES 1. [New issue] match cpython behaviour - types.ModuleType() http://ironpython.codeplex.com/workitem/33173 User paweljasinski has proposed the issue: "in cpython the following is legal (part of ipython): import types types.ModuleType("a",doc="some doc") in case of ironpython we get: SystemError: Unsupported param dictionary type: IronPython.Runtime.PythonDictionary" ---------------------------------------------- ---------------------------------------------- You are receiving this email because you subscribed to notifications on CodePlex. To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexmasis at gmail.com Thu Sep 27 15:54:36 2012 From: alexmasis at gmail.com (AlexM) Date: Thu, 27 Sep 2012 09:54:36 -0400 Subject: [Ironpython-users] VB.NET DLL Message-ID: Hi guys, Did someone has an example how to access a VB.Net class methods from IronPython? Thanks! alex. -------------- next part -------------- An HTML attachment was scrubbed... URL: From slide.o.mix at gmail.com Thu Sep 27 16:37:12 2012 From: slide.o.mix at gmail.com (Slide) Date: Thu, 27 Sep 2012 07:37:12 -0700 Subject: [Ironpython-users] VB.NET DLL In-Reply-To: References: Message-ID: Should be pretty much the same as using a C# DLL. There are many examples of that on the web. slide On Thu, Sep 27, 2012 at 6:54 AM, AlexM wrote: > Hi guys, > Did someone has an example how to access a VB.Net class methods from > IronPython? > > Thanks! > alex. > > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users > > -- Website: http://earl-of-code.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jdhardy at gmail.com Thu Sep 27 17:28:20 2012 From: jdhardy at gmail.com (Jeff Hardy) Date: Thu, 27 Sep 2012 08:28:20 -0700 Subject: [Ironpython-users] utf in source \u00F8 In-Reply-To: References: Message-ID: Very weird. I have no idea when those would have been introduced, or why. I expected 00F8 to be a non-breaking space or similar, but no, it's an ?. As far as I know, no one from Sweden has ever worked on IronPython. :) That isn't the only file containing it, either. I wonder if, for some reason, those aren't shown in visual studio? I can't see any issue with removing them, but I would like to know how they got there. - Jeff On Thu, Sep 27, 2012 at 2:09 AM, Pawel Jasinski wrote: > Short update > I have looked at 2.6 in codeplex and the \u00f8 is there, so I think > it is not my editor or my git settings. > http://ironpython.codeplex.com/SourceControl/changeset/view/87420#992096 > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users From slide.o.mix at gmail.com Thu Sep 27 17:54:45 2012 From: slide.o.mix at gmail.com (Slide) Date: Thu, 27 Sep 2012 08:54:45 -0700 Subject: [Ironpython-users] utf in source \u00F8 In-Reply-To: References: Message-ID: They are there in https://github.com/IronLanguages/main/blob/562ef478916cbeb820ca04b041c92d2b45dfbbba/Languages/IronPython/IronPython/Runtime/PythonModule.cs and https://github.com/IronLanguages/main/blob/8ddaa9646dff663047d40eb06a4f17913db11e58/Languages/IronPython/IronPython/Runtime/PythonModule.cs which are the only two things in the history on GitHub for that file. On Thu, Sep 27, 2012 at 8:28 AM, Jeff Hardy wrote: > Very weird. I have no idea when those would have been introduced, or > why. I expected 00F8 to be a non-breaking space or similar, but no, > it's an ?. As far as I know, no one from Sweden has ever worked on > IronPython. :) > > That isn't the only file containing it, either. I wonder if, for some > reason, those aren't shown in visual studio? > > I can't see any issue with removing them, but I would like to know how > they got there. > > - Jeff > > On Thu, Sep 27, 2012 at 2:09 AM, Pawel Jasinski > wrote: > > Short update > > I have looked at 2.6 in codeplex and the \u00f8 is there, so I think > > it is not my editor or my git settings. > > http://ironpython.codeplex.com/SourceControl/changeset/view/87420#992096 > > _______________________________________________ > > Ironpython-users mailing list > > Ironpython-users at python.org > > http://mail.python.org/mailman/listinfo/ironpython-users > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users > -- Website: http://earl-of-code.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From davew252 at tx.rr.com Thu Sep 27 18:49:17 2012 From: davew252 at tx.rr.com (Dave Wald) Date: Thu, 27 Sep 2012 11:49:17 -0500 Subject: [Ironpython-users] VB.NET DLL In-Reply-To: References: Message-ID: <5064838D.7000009@tx.rr.com> On 9/27/2012 8:54 AM, AlexM wrote: > Hi guys, > Did someone has an example how to access a VB.Net class methods from > IronPython? > > Thanks! > alex. > > > _______________________________________________ > Ironpython-users mailing list > Ironpython-users at python.org > http://mail.python.org/mailman/listinfo/ironpython-users Here's a link to my IronPython Scratch Pad app. (VB.Net, VisualStudio 10) https://docs.google.com/folder/d/0BwbB7sKzrSFqbHBxMTROQ2IzRDQ/edit Just run the startup.bat => cd C:\IPy27_Projects\IPyScratchPad <= change this or create it start "IPyScratchPad" "C:\IronPython 2.7\ipy.exe" Startup.py <= you may need to change this depending on how you intalled IPy pause Toolbar Buttons 1 thru 5 are active and do some simple demo stuff. Have fun! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at microsoft.com Thu Sep 27 20:50:35 2012 From: dinov at microsoft.com (Dino Viehland) Date: Thu, 27 Sep 2012 18:50:35 +0000 Subject: [Ironpython-users] utf in source \u00F8 In-Reply-To: References: Message-ID: <0bec0125fc3f43fca42be1984eee0ccf@BY2PR03MB596.namprd03.prod.outlook.com> This is a bit of a hack... It's there so that "args" is not accepted as a keyword argument. Because \u00F8 is not a valid identifier in Python there is no possibility that the user can provide this as a keyword argument. We ran into some bug I believe back in the IronPython 1.1 time frame where someone was trying to provide args as a keyword arg and this was a quick and easy fix. A better fix would probably to add some [NoKeywordArgBinding] attribute to the parameter and then update the overload resolver so that we don't allow binding of keyword args for that parameter. And I suspect that will become necessary for Python 3.x support where I think you can have Unicode identifiers (even though this exact identifier is unlikely to be used :) ). > -----Original Message----- > From: Jeff Hardy [mailto:jdhardy at gmail.com] > Sent: Thursday, September 27, 2012 8:28 AM > To: Pawel Jasinski; Dino Viehland > Cc: ironpython-users at python.org > Subject: Re: [Ironpython-users] utf in source \u00F8 > > Very weird. I have no idea when those would have been introduced, or why. > I expected 00F8 to be a non-breaking space or similar, but no, it's an ?. As far > as I know, no one from Sweden has ever worked on IronPython. :) > > That isn't the only file containing it, either. I wonder if, for some reason, > those aren't shown in visual studio? > > I can't see any issue with removing them, but I would like to know how they > got there. > > - Jeff > > On Thu, Sep 27, 2012 at 2:09 AM, Pawel Jasinski > wrote: > > Short update > > I have looked at 2.6 in codeplex and the \u00f8 is there, so I think > > it is not my editor or my git settings. > > > http://ironpython.codeplex.com/SourceControl/changeset/view/87420#992 > 0 > > 96 _______________________________________________ > > Ironpython-users mailing list > > Ironpython-users at python.org > > http://mail.python.org/mailman/listinfo/ironpython-users > > From jdhardy at gmail.com Fri Sep 28 21:19:22 2012 From: jdhardy at gmail.com (Jeff Hardy) Date: Fri, 28 Sep 2012 12:19:22 -0700 Subject: [Ironpython-users] utf in source \u00F8 In-Reply-To: <0bec0125fc3f43fca42be1984eee0ccf@BY2PR03MB596.namprd03.prod.outlook.com> References: <0bec0125fc3f43fca42be1984eee0ccf@BY2PR03MB596.namprd03.prod.outlook.com> Message-ID: On Thu, Sep 27, 2012 at 11:50 AM, Dino Viehland wrote: > This is a bit of a hack... It's there so that "args" is not accepted as a keyword argument. > > Because \u00F8 is not a valid identifier in Python there is no possibility that the user can > provide this as a keyword argument. We ran into some bug I believe back in the IronPython > 1.1 time frame where someone was trying to provide args as a keyword arg and this was a > quick and easy fix. A better fix would probably to add some [NoKeywordArgBinding] attribute > to the parameter and then update the overload resolver so that we don't allow binding of > keyword args for that parameter. And I suspect that will become necessary for Python 3.x > support where I think you can have Unicode identifiers (even though this exact identifier > is unlikely to be used :) ). OK, so they need to stay in for now. It looks like we could get most of them by not binding if [ParamDictionary] or [ParamArray] is present. There are a few other cases where a special one would be needed. Opened http://ironpython.codeplex.com/workitem/33180 to track. Not planning on fixing it before 3.0, though. Thanks, Dino. - Jeff From no_reply at codeplex.com Sat Sep 29 17:53:48 2012 From: no_reply at codeplex.com (no_reply at codeplex.com) Date: 29 Sep 2012 08:53:48 -0700 Subject: [Ironpython-users] IronPython, Daily Digest 9/28/2012 Message-ID: Hi ironpython, Here's your Daily Digest of new issues for project "IronPython". In today's digest:ISSUES 1. [New issue] Stray \u00F8 in source code ---------------------------------------------- ISSUES 1. [New issue] Stray \u00F8 in source code http://ironpython.codeplex.com/workitem/33180 User jdhardy has proposed the issue: "Some parameter names in IronPython have \u00F8 in them. This is a legacy thing, as described bu DinoV: "This is a bit of a hack... It's there so that "args" is not accepted as a keyword argument. Because \u00F8 is not a valid identifier in Python there is no possibility that the user can provide this as a keyword argument. We ran into some bug I believe back in the IronPython 1.1 time frame where someone was trying to provide args as a keyword arg and this was a quick and easy fix. A better fix would probably to add some [NoKeywordArgBinding] attribute to the parameter and then update the overload resolver so that we don't allow binding of keyword args for that parameter. And I suspect that will become necessary for Python 3.x support where I think you can have Unicode identifiers (even though this exact identifier is unlikely to be used :) )." Having the overload resolver ignore ParamDictionaryAttribute and ParamArrayAttribute is a big win (since those would never be called by keyword); adding NoKeywordBindingAttribute would get us the rest of the way." ---------------------------------------------- ---------------------------------------------- You are receiving this email because you subscribed to notifications on CodePlex. To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no_reply at codeplex.com Sun Sep 30 11:44:43 2012 From: no_reply at codeplex.com (no_reply at codeplex.com) Date: 30 Sep 2012 02:44:43 -0700 Subject: [Ironpython-users] IronPython, Daily Digest 9/29/2012 Message-ID: Hi ironpython, Here's your Daily Digest of new issues for project "IronPython". In today's digest:ISSUES 1. [New issue] bool value conversion malfunctions with Iron python libraries ---------------------------------------------- ISSUES 1. [New issue] bool value conversion malfunctions with Iron python libraries http://ironpython.codeplex.com/workitem/33181 User SriharshaVardhan has proposed the issue: "I am finding an issue with iron python libraries while passing a boolean value Say I have python code "booltest.py" like below. if ip_bool is not True and ip_bool is not False : print "invalid ip_bool" And when I call it using Iron Python libraries ScriptEngine engine = Python.CreateEngine(); ScriptScope scope = engine.CreateScope(); scope.SetVariable("ip_bool", false); scope = engine.ExecuteFile("booltest.py", scope); this results in printing 'invalid ip_bool' though its value is set to false Further I updated "booltest.py" to test type and print more info =============================================== print "Before conversion" print "class :" + ip_bool.__class__.__name__ print "value " + str(ip_bool) print "ip_bool is not True # " + str(ip_bool is not True) print "ip_bool is not False # " + str(ip_bool is not False) ip_bool1 = bool(ip_bool) print "\nAfter conversion" print "class :" + ip_bool1.__class__.__name__ print "value " + str(ip_bool1) print "ip_bool is not True # " + str(ip_bool1 is not True) print "ip_bool is not False # " + str(ip_bool1 is not False) =============================================== and it yields ================================ Before conversion class :bool value False ip_bool is not True # True ip_bool is not False # True After conversion class :bool value False ip_bool is not True # True ip_bool is not False # False ================================ Thus passing a bool value from scripting libraries malfunctions" ---------------------------------------------- ---------------------------------------------- You are receiving this email because you subscribed to notifications on CodePlex. To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Peter.Douglas at aeroflex.com Fri Sep 28 10:40:19 2012 From: Peter.Douglas at aeroflex.com (Douglas, Peter) Date: Fri, 28 Sep 2012 04:40:19 -0400 Subject: [Ironpython-users] Iron Python Support for CPython 3.1.5 Message-ID: Hello. Is there a plan or release scheduled to support CPython 3.1.5 in IronPython? Regards Peter Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s). -------------- next part -------------- An HTML attachment was scrubbed... URL: