Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Syntax error in ".py" file and globals variable values not available.

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


alexis.boutillier at arteris

Aug 27, 2008, 2:49 AM

Post #1 of 6 (75 views)
Permalink
Syntax error in ".py" file and globals variable values not available.

Hi,

I have a strange behaviour of python with pdb and import statement.
Here is the example code :

file my1.py:
import my2

file my2.py:
a=5
toto

I intentionnaly put a syntax error in file my2.py.

If I run "python -i my2.py" and run pdb I got :
NameError: name 'toto' is not defined
>>> import pdb
>>> pdb.pm()
-> toto
>>> print a
5

If I run "python -i my1.py" and run pdb I got :
NameError: name 'toto' is not defined
>>> import pdb
>>> pdb.pm()
-> toto
>>> print a
None

Why can't I get access to variable a in pdb when the process generating
the error came from an import statement ?

With python 2.3.5, it works fine and in the two cases I get the correct
value of 5 for variable "a".
with python 2.43,2.5.1,2.5.2, it doesn't work and I get "None" value for
variable a.

Somebody can explain me this behaviour ?


Thanks.
--
Boutillier Alexis
Methodology engineer

Arteris SA
The Network-on-Chip Company TM
www.arteris.net

6 par Ariane Immeuble Mercure
78284 Guyancourt Cedex
France
Office: (+33) 1 61 37 38 71
Fax: (+33) 1 61 37 38 41
Alexis.Boutillier[at]arteris.net
--
http://mail.python.org/mailman/listinfo/python-list


timothy.grant at gmail

Aug 27, 2008, 9:24 AM

Post #2 of 6 (70 views)
Permalink
Re: Syntax error in ".py" file and globals variable values not available. [In reply to]

On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier
<alexis.boutillier[at]arteris.com> wrote:
> Hi,
>
> I have a strange behaviour of python with pdb and import statement.
> Here is the example code :
>
> file my1.py:
> import my2
>
> file my2.py:
> a=5
> toto
>
> I intentionnaly put a syntax error in file my2.py.
>
> If I run "python -i my2.py" and run pdb I got :
> NameError: name 'toto' is not defined
>>>> import pdb
>>>> pdb.pm()
> -> toto
>>>> print a
> 5
>
> If I run "python -i my1.py" and run pdb I got :
> NameError: name 'toto' is not defined
>>>> import pdb
>>>> pdb.pm()
> -> toto
>>>> print a
> None
>
> Why can't I get access to variable a in pdb when the process generating the
> error came from an import statement ?
>
> With python 2.3.5, it works fine and in the two cases I get the correct
> value of 5 for variable "a".
> with python 2.43,2.5.1,2.5.2, it doesn't work and I get "None" value for
> variable a.
>
> Somebody can explain me this behaviour ?
>
>
> Thanks.
> --
> Boutillier Alexis
> Methodology engineer
>
> Arteris SA
> The Network-on-Chip Company TM
> www.arteris.net
>
> 6 par Ariane Immeuble Mercure
> 78284 Guyancourt Cedex
> France
> Office: (+33) 1 61 37 38 71
> Fax: (+33) 1 61 37 38 41
> Alexis.Boutillier[at]arteris.net
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Because of the syntax error the module wasn't loaded.

What kind of behaviour would you expect on code that has been flagged
as not executable?

--
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


alexis.boutillier at arteris

Aug 28, 2008, 1:40 AM

Post #3 of 6 (63 views)
Permalink
Re: Syntax error in ".py" file and globals variable values not available. [In reply to]

Timothy Grant a écrit :
> On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier
> <alexis.boutillier[at]arteris.com> wrote:
>> Hi,
>>
>> I have a strange behaviour of python with pdb and import statement.
>> Here is the example code :
>>
>> file my1.py:
>> import my2
>>
>> file my2.py:
>> a=5
>> toto
>>
>> I intentionnaly put a syntax error in file my2.py.
>>
>> If I run "python -i my2.py" and run pdb I got :
>> NameError: name 'toto' is not defined
>>>>> import pdb
>>>>> pdb.pm()
>> -> toto
>>>>> print a
>> 5
>>
>> If I run "python -i my1.py" and run pdb I got :
>> NameError: name 'toto' is not defined
>>>>> import pdb
>>>>> pdb.pm()
>> -> toto
>>>>> print a
>> None
>>
>> Why can't I get access to variable a in pdb when the process generating the
>> error came from an import statement ?
>>
>> With python 2.3.5, it works fine and in the two cases I get the correct
>> value of 5 for variable "a".
>> with python 2.43,2.5.1,2.5.2, it doesn't work and I get "None" value for
>> variable a.
>>
>> Somebody can explain me this behaviour ?
>>
>>
>> Thanks.
>> --
>> Boutillier Alexis
>> Methodology engineer
>>
>> Arteris SA
>> The Network-on-Chip Company TM
>> www.arteris.net
>>
>> 6 par Ariane Immeuble Mercure
>> 78284 Guyancourt Cedex
>> France
>> Office: (+33) 1 61 37 38 71
>> Fax: (+33) 1 61 37 38 41
>> Alexis.Boutillier[at]arteris.net
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
> Because of the syntax error the module wasn't loaded.
>
> What kind of behaviour would you expect on code that has been flagged
> as not executable?
>
I got the same behaviour with :
file my2.py:
a=5
raise SystemError,""

In pdb, I can't have the value of attribute a.
So this is not linked to the fact that it is a SyntaxError or a SystemError.

I expect to be able to have the value of all attributes that have been
used before the error occured.
This is problematic because in a more complicated code, you can't have
the value of the attribute that was used before the error occured.
Python know that this attribute exist, it only don't have its value.
other attribute affected are : __name__,__doc__,__file__.

--
Boutillier Alexis
Methodology engineer

Arteris SA
The Network-on-Chip Company TM
www.arteris.net

6 par Ariane Immeuble Mercure
78284 Guyancourt Cedex
France
Office: (+33) 1 61 37 38 71
Fax: (+33) 1 61 37 38 41
Alexis.Boutillier[at]arteris.net
--
http://mail.python.org/mailman/listinfo/python-list


timothy.grant at gmail

Aug 28, 2008, 1:23 PM

Post #4 of 6 (60 views)
Permalink
Re: Syntax error in ".py" file and globals variable values not available. [In reply to]

On Thu, Aug 28, 2008 at 1:40 AM, Alexis Boutillier
<alexis.boutillier[at]arteris.com> wrote:
> Timothy Grant a écrit :
>>
>> On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier
>> <alexis.boutillier[at]arteris.com> wrote:
>>>
>>> Hi,
>>>
>>> I have a strange behaviour of python with pdb and import statement.
>>> Here is the example code :
>>>
>>> file my1.py:
>>> import my2
>>>
>>> file my2.py:
>>> a=5
>>> toto
>>>
>>> I intentionnaly put a syntax error in file my2.py.
>>>
>>> If I run "python -i my2.py" and run pdb I got :
>>> NameError: name 'toto' is not defined
>>>>>>
>>>>>> import pdb
>>>>>> pdb.pm()
>>>
>>> -> toto
>>>>>>
>>>>>> print a
>>>
>>> 5
>>>
>>> If I run "python -i my1.py" and run pdb I got :
>>> NameError: name 'toto' is not defined
>>>>>>
>>>>>> import pdb
>>>>>> pdb.pm()
>>>
>>> -> toto
>>>>>>
>>>>>> print a
>>>
>>> None
>>>
>>> Why can't I get access to variable a in pdb when the process generating
>>> the
>>> error came from an import statement ?
>>>
>>> With python 2.3.5, it works fine and in the two cases I get the correct
>>> value of 5 for variable "a".
>>> with python 2.43,2.5.1,2.5.2, it doesn't work and I get "None" value for
>>> variable a.
>>>
>>> Somebody can explain me this behaviour ?
>>>
>>>
>>> Thanks.
>>> --
>>> Boutillier Alexis
>>> Methodology engineer
>>>
>>> Arteris SA
>>> The Network-on-Chip Company TM
>>> www.arteris.net
>>>
>>> 6 par Ariane Immeuble Mercure
>>> 78284 Guyancourt Cedex
>>> France
>>> Office: (+33) 1 61 37 38 71
>>> Fax: (+33) 1 61 37 38 41
>>> Alexis.Boutillier[at]arteris.net
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>>
>> Because of the syntax error the module wasn't loaded.
>>
>> What kind of behaviour would you expect on code that has been flagged
>> as not executable?
>>
> I got the same behaviour with :
> file my2.py:
> a=5
> raise SystemError,""
>
> In pdb, I can't have the value of attribute a.
> So this is not linked to the fact that it is a SyntaxError or a SystemError.
>
> I expect to be able to have the value of all attributes that have been used
> before the error occured.
> This is problematic because in a more complicated code, you can't have the
> value of the attribute that was used before the error occured.
> Python know that this attribute exist, it only don't have its value. other
> attribute affected are : __name__,__doc__,__file__.
>
> --
> Boutillier Alexis
> Methodology engineer
>
> Arteris SA
> The Network-on-Chip Company TM
> www.arteris.net
>
> 6 par Ariane Immeuble Mercure
> 78284 Guyancourt Cedex
> France
> Office: (+33) 1 61 37 38 71
> Fax: (+33) 1 61 37 38 41
> Alexis.Boutillier[at]arteris.net
> --
> http://mail.python.org/mailman/listinfo/python-list
>

So if you were writing C code and the file failed to compile you would
still expect to have a working executable that just worked up until
the point of the syntax error?

I'm not sure why you just don't fix the syntax error and move on.


--
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


alexis.boutillier at arteris

Aug 29, 2008, 12:48 AM

Post #5 of 6 (56 views)
Permalink
Re: Syntax error in ".py" file and globals variable values not available. [In reply to]

Timothy Grant a écrit :
> On Thu, Aug 28, 2008 at 1:40 AM, Alexis Boutillier
> <alexis.boutillier[at]arteris.com> wrote:
>> Timothy Grant a écrit :
>>> On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier
>>> <alexis.boutillier[at]arteris.com> wrote:
>>>> Hi,
>>>>
>>>> I have a strange behaviour of python with pdb and import statement.
>>>> Here is the example code :
>>>>
>>>> file my1.py:
>>>> import my2
>>>>
>>>> file my2.py:
>>>> a=5
>>>> toto
>>>>
>>>> I intentionnaly put a syntax error in file my2.py.
>>>>
>>>> If I run "python -i my2.py" and run pdb I got :
>>>> NameError: name 'toto' is not defined
>>>>>>> import pdb
>>>>>>> pdb.pm()
>>>> -> toto
>>>>>>> print a
>>>> 5
>>>>
>>>> If I run "python -i my1.py" and run pdb I got :
>>>> NameError: name 'toto' is not defined
>>>>>>> import pdb
>>>>>>> pdb.pm()
>>>> -> toto
>>>>>>> print a
>>>> None
>>>>
>>>> Why can't I get access to variable a in pdb when the process generating
>>>> the
>>>> error came from an import statement ?
>>>>
>>>> With python 2.3.5, it works fine and in the two cases I get the correct
>>>> value of 5 for variable "a".
>>>> with python 2.43,2.5.1,2.5.2, it doesn't work and I get "None" value for
>>>> variable a.
>>>>
>>>> Somebody can explain me this behaviour ?
>>>>
>>>>
>>>> Thanks.
>>>> --
>>>> Boutillier Alexis
>>>> Methodology engineer
>>>>
>>>> Arteris SA
>>>> The Network-on-Chip Company TM
>>>> www.arteris.net
>>>>
>>>> 6 par Ariane Immeuble Mercure
>>>> 78284 Guyancourt Cedex
>>>> France
>>>> Office: (+33) 1 61 37 38 71
>>>> Fax: (+33) 1 61 37 38 41
>>>> Alexis.Boutillier[at]arteris.net
>>>> --
>>>> http://mail.python.org/mailman/listinfo/python-list
>>>>
>>>
>>> Because of the syntax error the module wasn't loaded.
>>>
>>> What kind of behaviour would you expect on code that has been flagged
>>> as not executable?
>>>
>> I got the same behaviour with :
>> file my2.py:
>> a=5
>> raise SystemError,""
>>
>> In pdb, I can't have the value of attribute a.
>> So this is not linked to the fact that it is a SyntaxError or a SystemError.
>>
>> I expect to be able to have the value of all attributes that have been used
>> before the error occured.
>> This is problematic because in a more complicated code, you can't have the
>> value of the attribute that was used before the error occured.
>> Python know that this attribute exist, it only don't have its value. other
>> attribute affected are : __name__,__doc__,__file__.
>>
>> --
>> Boutillier Alexis
>> Methodology engineer
>>
>> Arteris SA
>> The Network-on-Chip Company TM
>> www.arteris.net
>>
>> 6 par Ariane Immeuble Mercure
>> 78284 Guyancourt Cedex
>> France
>> Office: (+33) 1 61 37 38 71
>> Fax: (+33) 1 61 37 38 41
>> Alexis.Boutillier[at]arteris.net
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
> So if you were writing C code and the file failed to compile you would
> still expect to have a working executable that just worked up until
> the point of the syntax error?
>
> I'm not sure why you just don't fix the syntax error and move on.
>
>

As you can see in my last response, this problem is not linked to the
type of error, If I "raise" a SystemError instead of creating a
SyntaxError I still can't access variable defined before the error.


--
Boutillier Alexis
Methodology engineer

Arteris SA
The Network-on-Chip Company TM
www.arteris.net

6 par Ariane Immeuble Mercure
78284 Guyancourt Cedex
France
Office: (+33) 1 61 37 38 71
Fax: (+33) 1 61 37 38 41
Alexis.Boutillier[at]arteris.net
--
http://mail.python.org/mailman/listinfo/python-list


timothy.grant at gmail

Aug 29, 2008, 1:22 PM

Post #6 of 6 (52 views)
Permalink
Re: Syntax error in ".py" file and globals variable values not available. [In reply to]

On Fri, Aug 29, 2008 at 12:48 AM, Alexis Boutillier
<alexis.boutillier[at]arteris.com> wrote:
> Timothy Grant a écrit :
>>
>> On Thu, Aug 28, 2008 at 1:40 AM, Alexis Boutillier
>> <alexis.boutillier[at]arteris.com> wrote:
>>>
>>> Timothy Grant a écrit :
>>>>
>>>> On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier
>>>> <alexis.boutillier[at]arteris.com> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I have a strange behaviour of python with pdb and import statement.
>>>>> Here is the example code :
>>>>>
>>>>> file my1.py:
>>>>> import my2
>>>>>
>>>>> file my2.py:
>>>>> a=5
>>>>> toto
>>>>>
>>>>> I intentionnaly put a syntax error in file my2.py.
>>>>>
>>>>> If I run "python -i my2.py" and run pdb I got :
>>>>> NameError: name 'toto' is not defined
>>>>>>>>
>>>>>>>> import pdb
>>>>>>>> pdb.pm()
>>>>>
>>>>> -> toto
>>>>>>>>
>>>>>>>> print a
>>>>>
>>>>> 5
>>>>>
>>>>> If I run "python -i my1.py" and run pdb I got :
>>>>> NameError: name 'toto' is not defined
>>>>>>>>
>>>>>>>> import pdb
>>>>>>>> pdb.pm()
>>>>>
>>>>> -> toto
>>>>>>>>
>>>>>>>> print a
>>>>>
>>>>> None
>>>>>
>>>>> Why can't I get access to variable a in pdb when the process generating
>>>>> the
>>>>> error came from an import statement ?
>>>>>
>>>>> With python 2.3.5, it works fine and in the two cases I get the correct
>>>>> value of 5 for variable "a".
>>>>> with python 2.43,2.5.1,2.5.2, it doesn't work and I get "None" value
>>>>> for
>>>>> variable a.
>>>>>
>>>>> Somebody can explain me this behaviour ?
>>>>>
>>>>>
>>>>> Thanks.
>>>>> --
>>>>> Boutillier Alexis
>>>>> Methodology engineer
>>>>>
>>>>> Arteris SA
>>>>> The Network-on-Chip Company TM
>>>>> www.arteris.net
>>>>>
>>>>> 6 par Ariane Immeuble Mercure
>>>>> 78284 Guyancourt Cedex
>>>>> France
>>>>> Office: (+33) 1 61 37 38 71
>>>>> Fax: (+33) 1 61 37 38 41
>>>>> Alexis.Boutillier[at]arteris.net
>>>>> --
>>>>> http://mail.python.org/mailman/listinfo/python-list
>>>>>
>>>>
>>>> Because of the syntax error the module wasn't loaded.
>>>>
>>>> What kind of behaviour would you expect on code that has been flagged
>>>> as not executable?
>>>>
>>> I got the same behaviour with :
>>> file my2.py:
>>> a=5
>>> raise SystemError,""
>>>
>>> In pdb, I can't have the value of attribute a.
>>> So this is not linked to the fact that it is a SyntaxError or a
>>> SystemError.
>>>
>>> I expect to be able to have the value of all attributes that have been
>>> used
>>> before the error occured.
>>> This is problematic because in a more complicated code, you can't have
>>> the
>>> value of the attribute that was used before the error occured.
>>> Python know that this attribute exist, it only don't have its value.
>>> other
>>> attribute affected are : __name__,__doc__,__file__.
>>>
>>> --
>>> Boutillier Alexis
>>> Methodology engineer
>>>
>>> Arteris SA
>>> The Network-on-Chip Company TM
>>> www.arteris.net
>>>
>>> 6 par Ariane Immeuble Mercure
>>> 78284 Guyancourt Cedex
>>> France
>>> Office: (+33) 1 61 37 38 71
>>> Fax: (+33) 1 61 37 38 41
>>> Alexis.Boutillier[at]arteris.net
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>> So if you were writing C code and the file failed to compile you would
>> still expect to have a working executable that just worked up until
>> the point of the syntax error?
>>
>> I'm not sure why you just don't fix the syntax error and move on.
>>
>>
>
> As you can see in my last response, this problem is not linked to the type
> of error, If I "raise" a SystemError instead of creating a SyntaxError I
> still can't access variable defined before the error.
>
>
> --
> Boutillier Alexis
> Methodology engineer
>
> Arteris SA
> The Network-on-Chip Company TM
> www.arteris.net
>
> 6 par Ariane Immeuble Mercure
> 78284 Guyancourt Cedex
> France
> Office: (+33) 1 61 37 38 71
> Fax: (+33) 1 61 37 38 41
> Alexis.Boutillier[at]arteris.net
> --
> http://mail.python.org/mailman/listinfo/python-list
>

http://docs.python.org/ref/import.html

--
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.