473,809 Members | 2,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Syntax error in ".py" file and globals variable values notavailable.

Timothy Grant a écrit :
On Thu, Aug 28, 2008 at 1:40 AM, Alexis Boutillier
<al************ ***@arteris.com wrote:
>Timothy Grant a écrit :
>>On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier
<al********** *****@arteris.c omwrote:
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
Methodolog y 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
Al************* **@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
Al************* **@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
Al************* **@arteris.net
Aug 29 '08 #1
0 1869

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

Similar topics

4
3127
by: ulysses | last post by:
Hi, I use PyQt 3.8 non-commercial version in win32. I get a big question. I Can't show PY variable in QT filedialog as initially parameter. Code sample is following: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fileName="test.avi" def saveSomething(aString):
3
3998
by: | last post by:
Hi everybody, I'm sure there's a way to do this, but I can't find it. How can I execute another .py file from my first .py file without using an exec* command? They're both in the same directory, and it would be nice to have some run("another.py") type statement as opposed to a big exec with absolute pathnames and garbage like that. It works the way I have it, but it just seems like a bad way in general to do it. I'm runnning Python...
5
5291
by: F. GEIGER | last post by:
Dear all, never thought that this could happen to me: I accidently deleted a ..py-file before I could back it up :-( However, the .pyc file is still there. Can I restore the .py file from the .pyc file somehow? Many thanks in advance Franz GEIGER
4
1827
by: martijn | last post by:
H! I'm trying to find a python function to use like this: -- maincode.py Include "apythonscript_function.py" -- end
1
2297
by: Beryl Small | last post by:
I have a web application in Visual Studio.Net 2003. On the click event of a button on my .aspx page, I use the following FileCopy SourceFile, DestinationFil the Sourcefile is on a mapped drive (s:\) on the server it returns the error "File not found" even though the file is there. The same code in the same place works fine if the file is on the c:\ drive. Same code also works fine with the mapped server drive in .NET if a put it in a...
6
2050
by: nibiery | last post by:
I am just getting started with Python, and I think I may be thinking about it wrong. I'd like to be able to work interactively with some code that I've got in a file. The only interpreted language I have much experience with is Tcl/Tk, and in that I would use "source file.tcl" in the console to load my source. Is there a similar command in python? I know I can run my file as a script, but since I'm just experimenting with how the language...
5
2360
by: Jason Jiang | last post by:
Hi, How to get the name of the running .py file like the macro _FILE_ in C? Thanks. Jason
2
2221
by: ward.david | last post by:
I am using py2exe to generate an executable so that I can deliver my scripts as a EXE. I have a couple of file that are needed by the program that I do not want to include in the EXE because they are used for program configuration (similar to the way an INI file is used.) These file may change per installation, so I may need to edit them. Having them wrapped up in the EXE just won't work for my needs. I've used the 'exclude' option to...
5
2168
by: ron.longo | last post by:
Is there any way that I can find the path of the main .py file of my application? For example, I have an application with some resources which are in a subdirectory: myPythonApp.py /resources image1
1
4710
by: cesco | last post by:
Hi, I need to instantiate an object (my_object) whose methods I have to use in two files (file1.py and file2.py) which are in the same directory. Is it possible to instantiate such object in the __init__.py file and then directly use it in file1.py and file2.py? If not, as I seem to experience, what is the best practice to follow in this case? (I thought __init__.py was somehow useful for that). Many thanks
0
9602
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
10639
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
10376
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...
1
10383
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7661
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
5550
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
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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.