473,385 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

IronPython 1.0 - Bugs or Features?

(just wanted to share my experience with IronPython 1.0)

The context:
C:\IronPythonipy.exe
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
vs.
C:\Python24python.exe
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32

IronPython raises "UnboundLocalError: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondition):
try:
strData = strSomeValue()
except:
pass
if( type(strData) == str ) : ### <<< HERE THE ERROR
doSomething()
</code>
CPython 2.4.2 doesn't raise an error with same code.

As strData is not set anywhere before in the code it seems, that
IronPython is somehow right, but I am not sure if it is a bug or a feature.

Another problem with IronPython where CPython 2.4.2 runs ok was while I
was trying to do:
f = file(r'\\.\PhysicalDrive0', 'rb')
getting "ValueError: FileStream will not open Win32 devices such as disk
partitions and tape drives. Avoid use of "\\.\" in the path."
Here the same - I am not sure if it is a bug or a feature.

Can someone knowledgeable elaborate on it a bit please?

Claudio Grondi
Sep 6 '06 #1
9 2120
In <ed**********@newsreader2.netcologne.de>, Claudio Grondi wrote:
The context:
C:\IronPythonipy.exe
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
vs.
C:\Python24python.exe
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32

IronPython raises "UnboundLocalError: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondition):
try:
strData = strSomeValue()
except:
pass
if( type(strData) == str ) : ### <<< HERE THE ERROR
doSomething()
</code>
CPython 2.4.2 doesn't raise an error with same code.
Well I get a `NameError` for `someCondition`. Please post a minimal
*working* example that produced the error.

Ciao,
Marc 'BlackJack' Rintsch
Sep 6 '06 #2
Claudio Grondi wrote:
(just wanted to share my experience with IronPython 1.0)

The context:
C:\IronPythonipy.exe
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
vs.
C:\Python24python.exe
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32

IronPython raises "UnboundLocalError: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondition):
try:
strData = strSomeValue()
except:
pass
if( type(strData) == str ) : ### <<< HERE THE ERROR
doSomething()
</code>
CPython 2.4.2 doesn't raise an error with same code.

As strData is not set anywhere before in the code it seems, that
IronPython is somehow right, but I am not sure if it is a bug or a feature.

Another problem with IronPython where CPython 2.4.2 runs ok was while I
was trying to do:
f = file(r'\\.\PhysicalDrive0', 'rb')
getting "ValueError: FileStream will not open Win32 devices such as disk
partitions and tape drives. Avoid use of "\\.\" in the path."
Here the same - I am not sure if it is a bug or a feature.

Can someone knowledgeable elaborate on it a bit please?

Claudio Grondi
Your problem is a blanket exception handler that ignores
the exception. Blanket exceptions are almost always a
bad idea. Blanket exceptions with pass as the only
command in the except: block is ALWAYS a bad idea.

Basically the line strData = strSomeValue() caused an
exception. Since it was inside a try: block, it then
executed what was in the except: block. Since all that
was in the except: block was pass, it just fell through
to the if statement. At that point strData is not
defined because the try block failed and never create
strData object.

It is doing EXACTLY what you told it to do.

-Larry Bates
Sep 6 '06 #3
Claudio Grondi wrote:
>
Another problem with IronPython where CPython 2.4.2 runs ok was while I
was trying to do:
f = file(r'\\.\PhysicalDrive0', 'rb')
getting "ValueError: FileStream will not open Win32 devices such as disk
partitions and tape drives. Avoid use of "\\.\" in the path."
Here the same - I am not sure if it is a bug or a feature.

Can someone knowledgeable elaborate on it a bit please?
I guess it's M$ being overprotective. Certainly it works in CPython as expected,
>>f = file(r'\\.\PhysicalDrive0', 'rb')
f
<open file '\\.\PhysicalDrive0', mode 'rb' at 0x01292650>

I have used similar to get boot sectors etc, but then did you really think Bill
would let us play with our own hardware? Just wait till DRM gets here.
--
Robin Becker

Sep 6 '06 #4
Larry Bates wrote:
Claudio Grondi wrote:
>>(just wanted to share my experience with IronPython 1.0)

The context:
C:\IronPythonipy.exe
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
vs.
C:\Python24python.exe
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32

IronPython raises "UnboundLocalError: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondition):
try:
strData = strSomeValue()
except:
pass
if( type(strData) == str ) : ### <<< HERE THE ERROR
doSomething()
</code>
CPython 2.4.2 doesn't raise an error with same code.

As strData is not set anywhere before in the code it seems, that
IronPython is somehow right, but I am not sure if it is a bug or a feature.

Another problem with IronPython where CPython 2.4.2 runs ok was while I
was trying to do:
f = file(r'\\.\PhysicalDrive0', 'rb')
getting "ValueError: FileStream will not open Win32 devices such as disk
partitions and tape drives. Avoid use of "\\.\" in the path."
Here the same - I am not sure if it is a bug or a feature.

Can someone knowledgeable elaborate on it a bit please?

Claudio Grondi


Your problem is a blanket exception handler that ignores
the exception. Blanket exceptions are almost always a
bad idea. Blanket exceptions with pass as the only
command in the except: block is ALWAYS a bad idea.

Basically the line strData = strSomeValue() caused an
exception. Since it was inside a try: block, it then
executed what was in the except: block. Since all that
was in the except: block was pass, it just fell through
to the if statement. At that point strData is not
defined because the try block failed and never create
strData object.

It is doing EXACTLY what you told it to do.
Sorry for the confusion caused, but you are right.
The actual code was a bit more complex, so I tried to get it down to the
principle, but haven't expected, that
f = file(r'\\.\PhysicalDrive0', 'rb')
buried within strSomeValue() throws an exception as in CPython the code
was running ok.
So the second problem was the cause also for the first one ...
I also erroneously assumed, that the first problem was detected during
parsing ... so, by the way: how can I distinguish an error raised while
parsing the code and an error raised when actually running the code?

Claudio Grondi
Sep 6 '06 #5
Marc 'BlackJack' Rintsch wrote:
In <ed**********@newsreader2.netcologne.de>, Claudio Grondi wrote:

>>The context:
C:\IronPythonipy.exe
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
vs.
C:\Python24python.exe
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32

IronPython raises "UnboundLocalError: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondition):
try:
strData = strSomeValue()
except:
pass
if( type(strData) == str ) : ### <<< HERE THE ERROR
doSomething()
</code>
CPython 2.4.2 doesn't raise an error with same code.


Well I get a `NameError` for `someCondition`. Please post a minimal
*working* example that produced the error.
I can't as after constructing one according to what I have thought was
the cause of it I detected that the error was caused by the exception in
the line
strData = strSomeValue()
(see also my other posting)
I have just misinterpreted the origin of the "UnboundLocalError:" as
raised while parsing and was wondering how it comes, that the parser is
able to detect such things ...
Sorry for the eventually caused confusion.

Claudio Grondi
Sep 6 '06 #6

"Claudio Grondi" <cl************@freenet.dewrote in message
news:ed*********@newsreader2.netcologne.de...
I also erroneously assumed, that the first problem was detected during
parsing ... so, by the way: how can I distinguish an error raised while
parsing the code and an error raised when actually running the code?
Parsing detects and reports syntax errors and maybe something else if you
use non-ascii chars without matching coding cookie. Other errors are
runtime.

tjr

Sep 6 '06 #7
tjreedy wrote:
"Claudio Grondi" <cl************@freenet.dewrote in message
news:ed*********@newsreader2.netcologne.de...
>>I also erroneously assumed, that the first problem was detected during
parsing ... so, by the way: how can I distinguish an error raised while
parsing the code and an error raised when actually running the code?


Parsing detects and reports syntax errors and maybe something else if you
use non-ascii chars without matching coding cookie. Other errors are
runtime.
Let's consider
print '"Data ê"'

In CPython 2.4.2 there is in case of non-ascii character:
sys:1: DeprecationWarning: Non-ASCII character '\xea' in file
C:\IronPython-1.0-BugsOrFeatures.py on line 3, but no encoding
declared; see http://www.python.org/peps/pep-0263.html for details
"Data♀♂ Û"

IronPython does not raise any warning and outputs:
"Data♀♂ ?"

So it seems, that IronPython is not that close to CPython as I have it
expected.
It takes much more time to run this above simple script in IronPython as
in CPython - it feels as IronPython were extremely busy with starting
itself.

Claudio Grondi
Sep 6 '06 #8

Claudio Grondi wrote:
tjreedy wrote:
"Claudio Grondi" <cl************@freenet.dewrote in message
news:ed*********@newsreader2.netcologne.de...
>I also erroneously assumed, that the first problem was detected during
parsing ... so, by the way: how can I distinguish an error raised while
parsing the code and an error raised when actually running the code?

Parsing detects and reports syntax errors and maybe something else if you
use non-ascii chars without matching coding cookie. Other errors are
runtime.
Let's consider
print '"Data ê"'

In CPython 2.4.2 there is in case of non-ascii character:
sys:1: DeprecationWarning: Non-ASCII character '\xea' in file
C:\IronPython-1.0-BugsOrFeatures.py on line 3, but no encoding
declared; see http://www.python.org/peps/pep-0263.html for details
"Data♀♂ Û"

IronPython does not raise any warning and outputs:
"Data♀♂ ?"

So it seems, that IronPython is not that close to CPython as I have it
expected.
It takes much more time to run this above simple script in IronPython as
in CPython - it feels as IronPython were extremely busy with starting
itself.

Claudio Grondi
IronPython is a .NET language, so does that mean that it invokes the
JIT before running actual code? If so, then "simple short scripts"
would take longer with IronPython "busy starting itself" loading .NET
and invoking the JIT. This effect would be less noticable, the longer
the program is. But I'm just guessing; I've not used IronPython.

Sep 6 '06 #9
Super Spinner wrote:
IronPython is a .NET language, so does that mean that it invokes the
JIT before running actual code? If so, then "simple short scripts"
would take longer with IronPython "busy starting itself" loading .NET
and invoking the JIT. This effect would be less noticable, the longer
the program is. But I'm just guessing; I've not used IronPython.
The time of loading IronPython seem to pay out at the end if the script
takes a longer time to run, so you are most probably right. I am a bit
surprised, that the difference is not that big (e.g. at least half the
time) as I have expected from a JIT concept ... :

<code>
# import psyco
# psyco.full()

def arccot(x, unity):
sum = xpower = unity // x
n = 3
sign = -1
while 1:
xpower = xpower // (x*x)
term = xpower // n
if not term:
break
sum += sign * term
sign = -sign
n += 2
return sum

def pi(digits):
print ' start of setting unity value ...',
unity = 10**(digits + 10)
print ' set unity value, starting arccot() ... ',
pi = 4 * (4*arccot(5, unity) - arccot(239, unity))
return pi // 10**10
f = file("pi-decimal-100000digits.out","wb")
f.write(str(pi(100000)))

print """
PC: Pentium 4, 2.8 GHz, Windows XP SP2
writing 100.000 digits of Pi to a file takes using:
CPython 2.4.2 : 2 min 41 s (of CPU time)
CPython+Psyco : 2 min 45 s (of CPU time)
IronPython 1.0 : 1 min 48 s (of CPU time)
"""
</code>

Claudio Grondi
Sep 7 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

82
by: Neuruss | last post by:
IronPython is currently at a pre-alpha stage suitable for experimentation but not for serious development work. http://www.ironpython.com
27
by: James | last post by:
http://www.gotdotnet.com/workspaces/workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742
25
by: Nainto | last post by:
I came across this link today. http://tinyurl.com/9c7ta It seems Microsoft is getting involved with Python. What do you think of it? Is it any good? Anything to worry about? -- Zach
3
by: Sanghyeon Seo | last post by:
I took some time to write this HOWTO: http://sparcs.kaist.ac.kr/~tinuviel/fepy/howto/simplehttpserver-ironpython-mono-howto.html IronPython seems to get much less interest than it deserves. This...
14
by: Dan | last post by:
Just starting to do some windows Client / Server programming. Which would you recommend? I need to create a server to fire events and communicate with clients over a lan. Thanks
27
by: alacrite | last post by:
Anyone know if there is a book for Ironpython in the works? A good knowledge of .NET and Python is enough to get started but just poking around Ironpython homepage it seems like there are some new...
9
by: Luis M. González | last post by:
Check it out: http://www.gotdotnet.com/workspaces/workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742
2
by: Troels Thomsen | last post by:
Hello , When an exeption occurs in a IronPython executet script, and I print the sys.exc , i get something ugly like the example below. How can I get the fileName and line number? Thx in...
1
by: jmDesktop | last post by:
I know that IronPython and CPython are different in that one does not use the .net framework, but are they both really the same Python language. From my basic understanding, it will depend on what...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.