[IronPython] Parsing Stack Traces

2008-02-12 Thread Slide
I have a current script engine I wrote which deals with CodeDom for
JScript.NET scripts and I am currently adding Python capabilities to
it. On the JScript.NET side, I can get the CompilerErrors from the
CompileResults after I've compiled and run the main entry point of the
script. On the Python side, when I run it, I get
SyntaxErrorExceptions, etc that I would like to turn into something
like a CompilerError object. I wrote my own object that is very
similar to CompilerError so that I could abstract this out. Is there a
way to get the line number, column number, etc from the Python engine
so I could fill these items in?

Thanks

-- 
slide-o-blog
http://slide-o-blog.blogspot.com/
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Please help me out its very urgent

2008-02-12 Thread Dino Viehland
Yeah, if it's released in 2006 it looks like it had to be 1.0 (1.1 was released 
in 2007) - so it's not going to have the fix.

I would suggest using ASP.NET Futures if that's possible.  Unfortunately I'm 
not too familiar with the ASP.NET support either and our expert is currently on 
vacation for the next 2 weeks.  I would have thought we would have released a 
version based upon 1.1 at some point.  If we did that it should be possible to 
drop-in 1.1.1 over the 1.1 binaries and have everything work - but that won't 
work between 1.0 and 1.1 because the assembly versions are different (which was 
intentional because there's new public API surface in 1.1).

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Machin
Sent: Tuesday, February 12, 2008 2:50 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Please help me out its very urgent

Dino Viehland wrote:
> Can you try using the library just from the command line and see what
> the result is?  You might want to try running w/ -X:ExceptionDetail to
> see where the exception is actually coming from.
>
>
>
> I tried and was able to open a XLS saved in Office 2003 and earlier
> format w/o any problems using this library so it's hard to know what's
> blowing up in all the code below.

Hi Dino,

I'm the author of xlrd, the library that Praveen is trying to use. I
suspect that the root cause of Praveen's problem is related to this
IronPython bug that I reported ages ago:

http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=3094

This now says status == closed, and release == 2.0 Alpha 5; however it
appears to be fixed in Iron Python 1.1.1. Like you, I have been able to
use xlrd OK from the 1.1.1 ipy interactive prompt. Praveen says he can
do that too. Praveen is however using "IronPython for ASP.NET" which was
evidently released on 11/3/2006 [11 March or 3 November?]. He is *not*
using the "ASP.NET Futures" released in May 2007.

Caveat: ASP, ASP.NET and "IronPython for ASP.NET" are diminishingly
scarce in my knowledge-base :-)

Am I correct in guessing that the IronPython bug is not fixed in the
2006 version of "IronPython for ASP.NET"?

I have suggested the following to Praveen:
"""
Please try this simple test:

1. set up a test module called test1.py, containing:
import sys
print >> sys.stderr, "test 1: being imported"

2. remove all references to xlrd from your aspx.py. Instead, put in:
import test1
print >> sys.stderr, "aspx: module imported OK"

3. run that and see if it prints as expected. If print >> sys.stderr
doesn't work in IP for asp.net, find some other way of doing debug
displays. Do whatever is necessary to get test1 demonstrably importable.

4. copy the final working test1.py to test2.py, and insert a new line at
the top:
# coding: cp1252

5. change your aspx.py to import test2 instead of test1.

If that fails with "Value cannot be null. Parameter name: encoding",
then my guess that my reported bug is not fixed in IP for ASP.NET would
seem to be correct.
We can work around that.
"""

Unfortunately this was abandoned at step 3, because the aspx.py was
missing a line containing "import sys", this caused an error message
"name 'sys' not defined", and the suggested remedy caused some further
problem of an unspecified nature.

> *From:* [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] *On Behalf Of *Praveen Kumar
> *Sent:* Monday, February 11, 2008 9:31 PM
> *To:* users@lists.ironpython.com
> *Subject:* [IronPython] Please help me out its very urgent
>
>
>
> I am new for Ironpython for ASP.net, earlier i was using only Visual
> studio 2005 and struggling with to read excel file without M$ Excel
> object, bt i could nt get any other object which could read excel sheet.
> But suddenly i got one
> Lingfo - Python "xlrd" package for extracting data from Excel files -
> 0.6.1 final
> which can read successfully excel sheet as i desired.but the problem is
> i dont knw hw can i use with IronPython Asp.net(Microsoft IronPython for
> ASP.NET ). i have seperately installed Python2.4..
> i tried with python2.4 its working failrly.while installing xlrd it
> automatically search D:\Python24\, there were no option to configure it
> nad installed  in D:\Python24\Lib\site-packages\.
>
> Then i copy the XLRD package and paste C:\Program Files\Microsoft
> IronPython for ASP.NET\Lib\site-packages\

Not at my suggestion :-)

>
> and wrote the python script ExcelModule.py

Actually it's a kludged version of a recipe from the ASPN Python
Cookbook ...

>
> class readexcel(object):
> def __init__(self,filename):
> """ Returns a readexcel object of the specified filename - this
> may take a little while because the file must be parsed into memory """
> import sys
> sys.path.append('D:\Python24\Lib')
> sys.path.append('D:\Python24\Lib\site-packages')
> from xlrd import *
> print dir(xlrd)

This won't work because "xlrd" is not defined

> re

[IronPython] Import xlrd

2008-02-12 Thread Praveen Kumar
Ok, now i am too much confused, tried with different way as possible. Now my
simple question is--
May i use xlrd module ItonPython for ASP.Net CTP(1.0) if i can then please
tell me the brief information about configuration,library,classetc or i
may use ASP.Net futures then how can i make it possible with this.

-- 
Praveen Kumar
Mahiti Infotech Pvt. Ltd.
# 33-34, Hennur Cross
Hennur Main Road
Bangalore, India - 560043
Mobile:  +91 9343297314
Phone:  +91 80 4148 5080/1  41150580/1
http://www.mahiti.org
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Help with Ops.GetAttr

2008-02-12 Thread Paul Turbett
That did it, thanks!

Dino Viehland wrote:
> You could use Ops.TryGetAttr which doesn't take a context (and flows the 
> default context in for you).
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Turbett
> Sent: Tuesday, February 12, 2008 5:30 AM
> To: users@lists.ironpython.com
> Subject: [IronPython] Help with Ops.GetAttr
>
> Hi,
>
> I'm attempting to get an attribute from python object from C# using a
> method like this:
>
> public object GetAttr(object pyObject, string name)
> {
>ICallerContext context = _pythonEngine.DefaultModule as ICallerContext;
>object value = Ops.GetAttr( context, pyObject,
> SymbolTable.StringToId(name));
>return value;
> }
>
> where _pythonEngine is a PythonEngine object, pyObject is a python
> object and name is the attribute I want to get.
>
> According to other posts I've seen, this should work, but the first line
> sets context to null. How to I get a valid context?
>
> It seems every way I've read about to get the context
> (DefaultContext.Default, GetModuleScope) is private, and therefore
> inaccessible.
>
> I'm using IPY 1.1.1
>
> TIA, Paul
> ___
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> ___
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>   
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Please help me out its very urgent

2008-02-12 Thread John Machin
Dino Viehland wrote:
> Can you try using the library just from the command line and see what 
> the result is?  You might want to try running w/ -X:ExceptionDetail to 
> see where the exception is actually coming from.
> 
>  
> 
> I tried and was able to open a XLS saved in Office 2003 and earlier 
> format w/o any problems using this library so it’s hard to know what’s 
> blowing up in all the code below.

Hi Dino,

I'm the author of xlrd, the library that Praveen is trying to use. I 
suspect that the root cause of Praveen's problem is related to this 
IronPython bug that I reported ages ago:

http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=3094

This now says status == closed, and release == 2.0 Alpha 5; however it 
appears to be fixed in Iron Python 1.1.1. Like you, I have been able to 
use xlrd OK from the 1.1.1 ipy interactive prompt. Praveen says he can 
do that too. Praveen is however using "IronPython for ASP.NET" which was 
evidently released on 11/3/2006 [11 March or 3 November?]. He is *not* 
using the "ASP.NET Futures" released in May 2007.

Caveat: ASP, ASP.NET and "IronPython for ASP.NET" are diminishingly 
scarce in my knowledge-base :-)

Am I correct in guessing that the IronPython bug is not fixed in the 
2006 version of "IronPython for ASP.NET"?

I have suggested the following to Praveen:
"""
Please try this simple test:

1. set up a test module called test1.py, containing:
import sys
print >> sys.stderr, "test 1: being imported"

2. remove all references to xlrd from your aspx.py. Instead, put in:
import test1
print >> sys.stderr, "aspx: module imported OK"

3. run that and see if it prints as expected. If print >> sys.stderr 
doesn't work in IP for asp.net, find some other way of doing debug 
displays. Do whatever is necessary to get test1 demonstrably importable.

4. copy the final working test1.py to test2.py, and insert a new line at 
the top:
# coding: cp1252

5. change your aspx.py to import test2 instead of test1.

If that fails with "Value cannot be null. Parameter name: encoding", 
then my guess that my reported bug is not fixed in IP for ASP.NET would 
seem to be correct.
We can work around that.
"""

Unfortunately this was abandoned at step 3, because the aspx.py was 
missing a line containing "import sys", this caused an error message 
"name 'sys' not defined", and the suggested remedy caused some further 
problem of an unspecified nature.

> *From:* [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] *On Behalf Of *Praveen Kumar
> *Sent:* Monday, February 11, 2008 9:31 PM
> *To:* users@lists.ironpython.com
> *Subject:* [IronPython] Please help me out its very urgent
> 
>  
> 
> I am new for Ironpython for ASP.net, earlier i was using only Visual 
> studio 2005 and struggling with to read excel file without M$ Excel 
> object, bt i could nt get any other object which could read excel sheet. 
> But suddenly i got one
> Lingfo – Python "xlrd" package for extracting data from Excel files – 
> 0.6.1 final
> which can read successfully excel sheet as i desired.but the problem is 
> i dont knw hw can i use with IronPython Asp.net(Microsoft IronPython for 
> ASP.NET ). i have seperately installed Python2.4..
> i tried with python2.4 its working failrly.while installing xlrd it 
> automatically search D:\Python24\, there were no option to configure it 
> nad installed  in D:\Python24\Lib\site-packages\.
> 
> Then i copy the XLRD package and paste C:\Program Files\Microsoft 
> IronPython for ASP.NET\Lib\site-packages\

Not at my suggestion :-)

> 
> and wrote the python script ExcelModule.py

Actually it's a kludged version of a recipe from the ASPN Python 
Cookbook ...

> 
> class readexcel(object):
> def __init__(self,filename):
> """ Returns a readexcel object of the specified filename - this 
> may take a little while because the file must be parsed into memory """
> import sys
> sys.path.append('D:\Python24\Lib')
> sys.path.append('D:\Python24\Lib\site-packages')
> from xlrd import *
> print dir(xlrd)

This won't work because "xlrd" is not defined

> return printed

and this won't work because "printed" is not defined

[big snip]

> 
> and in default.aspx.py 
> 
> import System
> import clr
> from System.Data import *
> from System.Web import *
> from System.Web.UI import *
> #from IronPython.Hosting import PythonEngine
> from clr import *
> import SampleModule
> import sys
> #import SampleModule2
> #import ExcelModule
> #from ExcelModule import readexcel
> from SampleModule import SampleClass
> from SampleModule import readexcel
> if sys.version.startswith("IronPython"):

No longer true:

IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.832
Copyright (c) Microsoft Corporation. All rights reserved.
 >>> import sys; sys.version
'2.4.0 (IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.832)'
 >>>


> # print >> sys.stderr, "...importing encodings"
> import encodings
> sys.path

Re: [IronPython] Please help me out its very urgent

2008-02-12 Thread Dino Viehland
Can you try using the library just from the command line and see what the 
result is?  You might want to try running w/ -X:ExceptionDetail to see where 
the exception is actually coming from.

I tried and was able to open a XLS saved in Office 2003 and earlier format w/o 
any problems using this library so it's hard to know what's blowing up in all 
the code below.

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Praveen Kumar
Sent: Monday, February 11, 2008 9:31 PM
To: users@lists.ironpython.com
Subject: [IronPython] Please help me out its very urgent

I am new for Ironpython for ASP.net, earlier i was using only Visual studio 
2005 and struggling with to read excel file without M$ Excel object, bt i could 
nt get any other object which could read excel sheet. But suddenly i got one
Lingfo - Python "xlrd" package for extracting data from Excel files - 0.6.1 
final
which can read successfully excel sheet as i desired.but the problem is i dont 
knw hw can i use with IronPython Asp.net(Microsoft IronPython for 
ASP.NET). i have seperately installed Python2.4..
i tried with python2.4 its working failrly.while installing xlrd it 
automatically search D:\Python24\, there were no option to configure it nad 
installed  in D:\Python24\Lib\site-packages\.
Then i copy the XLRD package and paste C:\Program Files\Microsoft IronPython 
for ASP.NET\Lib\site-packages\
and wrote the python script ExcelModule.py

class readexcel(object):
def __init__(self,filename):
""" Returns a readexcel object of the specified filename - this may 
take a little while because the file must be parsed into memory """
import sys
sys.path.append('D:\Python24\Lib')
sys.path.append('D:\Python24\Lib\site-packages')
from xlrd import *
print dir(xlrd)
return printed
import os.path
if not os.path.isfile(filename):
raise NameError, "%s is not a valid filename" % filename
self.__filename__ = filename
self.__book__ = xlrd.open_workbook(filename)
self.__sheets__ = {}
self.__sheetnames__ = []
for i in self.__book__.sheet_names():
uniquevars = []
firstrow = 0
sheet = self.__book__.sheet_by_name(i)
for row in range(sheet.nrows):
types,values = sheet.row_types(row),sheet.row_values(row)
nonblank = False
for j in values:
if j != '':
nonblank=True
break
if nonblank:
# Generate a listing of Unique Variable Names for Use as
# Dictionary Keys In Extraction. Duplicate Names will
# be replaced with "F#"
variables = self.__formatrow__(types,values,False)
unknown = 1
while variables:
var = variables.pop(0)
if var in uniquevars or var == '':
var = 'F' + str(unknown)
unknown += 1
uniquevars.append(str(var))
firstrow = row + 1
break
self.__sheetnames__.append(i)
self.__sheets__.setdefault(i,{}).__setitem__('rows',sheet.nrows)
self.__sheets__.setdefault(i,{}).__setitem__('cols',sheet.ncols)
self.__sheets__.setdefault(i,{}).__setitem__('firstrow',firstrow)

self.__sheets__.setdefault(i,{}).__setitem__('variables',uniquevars[:])
def getiter(self, sheetname, returnlist=False, returntupledate=False):
""" Return an generator object which yields the lines of a worksheet;
Default returns a dictionary, specifing returnlist=True causes lists
to be returned.  Calling returntupledate=True causes dates to returned
as tuples of (Year, Month, Day, Hour, Min, Second) instead of as a
string """
if sheetname not in self.__sheets__.keys():
raise NameError, "%s is not present in %s" % (sheetname,\
  self.__filename__)
if returnlist:
return __iterlist__(self, sheetname, returntupledate)
else:
return __iterdict__(self, sheetname, returntupledate)
def worksheets(self):
""" Returns a list of the Worksheets in the Excel File """
return self.__sheetnames__
def nrows(self, worksheet):
""" Return the number of rows in a worksheet """
return self.__sheets__[worksheet]['rows']
def ncols(self, worksheet):
""" Return the number of columns in a worksheet """
return self.__sheets__[worksheet]['cols']
def variables(self,worksheet):
""" Returns a list of Column Names in the file,
assuming a tabular format of course. """
return self.__sheets__[worksheet]['variables']
def __forma

Re: [IronPython] Help with Ops.GetAttr

2008-02-12 Thread Dino Viehland
You could use Ops.TryGetAttr which doesn't take a context (and flows the 
default context in for you).

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Turbett
Sent: Tuesday, February 12, 2008 5:30 AM
To: users@lists.ironpython.com
Subject: [IronPython] Help with Ops.GetAttr

Hi,

I'm attempting to get an attribute from python object from C# using a
method like this:

public object GetAttr(object pyObject, string name)
{
   ICallerContext context = _pythonEngine.DefaultModule as ICallerContext;
   object value = Ops.GetAttr( context, pyObject,
SymbolTable.StringToId(name));
   return value;
}

where _pythonEngine is a PythonEngine object, pyObject is a python
object and name is the attribute I want to get.

According to other posts I've seen, this should work, but the first line
sets context to null. How to I get a valid context?

It seems every way I've read about to get the context
(DefaultContext.Default, GetModuleScope) is private, and therefore
inaccessible.

I'm using IPY 1.1.1

TIA, Paul
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Help with Ops.GetAttr

2008-02-12 Thread Paul Turbett
Hi,

I'm attempting to get an attribute from python object from C# using a 
method like this:

public object GetAttr(object pyObject, string name)
{
   ICallerContext context = _pythonEngine.DefaultModule as ICallerContext;
   object value = Ops.GetAttr( context, pyObject, 
SymbolTable.StringToId(name));
   return value;
}

where _pythonEngine is a PythonEngine object, pyObject is a python 
object and name is the attribute I want to get.

According to other posts I've seen, this should work, but the first line 
sets context to null. How to I get a valid context?

It seems every way I've read about to get the context 
(DefaultContext.Default, GetModuleScope) is private, and therefore 
inaccessible.

I'm using IPY 1.1.1

TIA, Paul
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com