473,651 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IronPython 1.0 - Bugs or Features?

(just wanted to share my experience with IronPython 1.0)

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

IronPython raises "UnboundLocalEr ror: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondi tion):
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'\\.\Phys icalDrive0', '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 2129
In <ed**********@n ewsreader2.netc ologne.de>, Claudio Grondi wrote:
The context:
C:\IronPythonip y.exe
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
vs.
C:\Python24pyth on.exe
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32

IronPython raises "UnboundLocalEr ror: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondi tion):
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:\IronPythonip y.exe
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
vs.
C:\Python24pyth on.exe
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32

IronPython raises "UnboundLocalEr ror: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondi tion):
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'\\.\Phys icalDrive0', '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'\\.\Phys icalDrive0', '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'\\.\Phys icalDrive0', 'rb')
f
<open file '\\.\PhysicalDr ive0', 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:\IronPythonip y.exe
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
vs.
C:\Python24pyth on.exe
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32

IronPython raises "UnboundLocalEr ror: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondi tion):
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'\\.\Phys icalDrive0', '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'\\.\Phys icalDrive0', '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**********@n ewsreader2.netc ologne.de>, Claudio Grondi wrote:

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

IronPython raises "UnboundLocalEr ror: local variable 'strData'
referenced before assignment" error in following case:
<code>
while(someCondi tion):
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 "UnboundLocalEr ror:" 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.dewrot e in message
news:ed******** *@newsreader2.n etcologne.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.dewrot e in message
news:ed******** *@newsreader2.n etcologne.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: DeprecationWarn ing: 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.dewrot e in message
news:ed******** *@newsreader2.n etcologne.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: DeprecationWarn ing: 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.ou t","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
3382
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
2827
by: James | last post by:
http://www.gotdotnet.com/workspaces/workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742
25
2030
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
2509
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 howto shows how to setup IronPython to use with Mono on Linux and how to rebuild IronPython from source. It also discusses various patches to current problems. It also shows that IronPython can run SimpleHTTPServer today, not a trivial...
14
1959
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
1935
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 language features added to handle some quirks with working within the CLR. Although I could be wrong. Thanks -Jake
9
1283
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
5625
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 advance Troels
1
1410
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 the programmer's goal is as to which of the two would be used, but I didn't know if they were really the same language.
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.