473,406 Members | 2,273 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,406 software developers and data experts.

Syntax error when using 'global' keyword in eval

So, recently I've been experimenting with a telnet server, and a 5250 terminal emutator and I thought of making a field system, for easier graphical (well, not quite) displaying.

This basically lets you set the value of a X and Y position on the screen and it automatically updating it, and I needed to make the field_[X & Y coordinates] variables global in order to use them in all the functions. The screen size variables work fine, but since it has many diffirent field_* variables which have diffirent names, I had to use eval, but this throws a syntax error.

The code and error message is located below:

Expand|Select|Wrap|Line Numbers
  1. from os import system
  2.  
  3. def set_screen_size(x,y):
  4.     global screen_x
  5.     global screen_y
  6.     screen_x = str(x)
  7.     screen_y = str(y)
  8.     system('mode con cols=' + screen_x + ' lines=' + screen_y)
  9.  
  10. def set_field(x,y,val):
  11.     global screen_x
  12.     global screen_y
  13.     x = str(x)
  14.     y = str(y)
  15.     val = val[0:1]
  16.     if(x > screen_x or x < 0 or y > screen_y or x < 0):
  17.         on_error('Field outside screen given. set_field('+x+','+y+','+val+')')
  18.     eval('global field_' + x + y)
  19.     eval('field_' + x + y + ' = ' + val)
  20.     update_screen()
  21.  
  22. def update_screen():
  23.     global screen_x
  24.     global screen_y
  25.     for x in screen_x:
  26.         line = ""
  27.         for y in screen_y:
  28.             eval('global field_' + x + y)
  29.             eval('val = field_' + x + y)
  30.             line = line + val
  31.         print line
  32.  
Traceback:
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "G:\FieldScreen\fieldscreen.py", line 34, in <module>
  3.     set_field(0,0,"H")
  4.   File "G:\FieldScreen\fieldscreen.py", line 18, in set_field
  5.     eval('global field_' + x + y)
  6.   File "<string>", line 1
  7.     global field_00
  8.          ^
  9. SyntaxError: invalid syntax
  10.  
May 14 '10 #1
1 2537
woooee
43
Start with this
Expand|Select|Wrap|Line Numbers
  1. if(x > screen_x or x < 0 or y > screen_y or x < 0):
  2. if(x > screen_x or x < 0 or y > screen_y or y < 0): <===== 
May 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Andrew James | last post by:
Gentlemen, I'm running into a problem whilst testing the parsing of a language I've created with TPG . It seems that for some reason, TPG balks when I try to parse an expression whose first...
1
by: Dermot O'Loughlin | last post by:
Can anyone help me with this? I get the following error when using the odbc adapter wizard in VS.Net 2003: --------------------------- Wizard Form --------------------------- An unexpected...
1
by: FaYYaZ | last post by:
Hi All I am getting error "Syntax error " when trying to define a class Like Class myClass Public height Public ID Private t_width
3
by: KevLow | last post by:
Hi, Hope some kind soul can help me out here.. I'm trying to programmatically modify the column headings of a crosstab query such that it can be dynamic based on user specified period (Month...
0
by: Charlie | last post by:
Hi: I get a TreeNode binding error when using Data property of XmlDataSource control. When I switch to TextFile property and point to xml file on hard drive, problem goes anyway. I'm...
4
by: Al Santino | last post by:
Hello, I've created a simple C# web services project using Visual Studio 2005. My service compiles and runs correctly when called by remote clients. I'm able to step through the service in the...
2
by: sharmilah | last post by:
I have the following code in my script and it's giving a syntax error at line *** when using the password function. My password in the mysql database is encrypted using the password function itself...
8
by: msnews.microsoft.com | last post by:
Our IT team relocated our application servers yesterday. They had to take one machine out of the cluster because it would prompt users for credentials if accessed using the IP address, which I...
7
by: svsenthilkumar | last post by:
Hai, I got an javascript error when using ajax in mozilla browser, anyone help me why the error is coming, meaning for this error and how can i rectify this error. Error: " nsresult:...
3
by: James Watson | last post by:
'Microsoft VB 6.3, Access 2002 'Syntax error in the INSERT INTO Statement when the query runs 'How can I make this work? Private Sub Command52_Click() On Error GoTo Err_Command52_Click ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.