473,657 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax error when using 'global' keyword in eval

1 New Member
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 2542
woooee
43 New Member
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
2627
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 letter is 't' (or, in fact, at any time when 't' is at the beginning of a token). This doesn't happen with any other letter (as far as I know), nor if the 'T' is capitalised. My grammar looks like this:
1
426
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 error has occurred.
1
2579
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
3102
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 Year to Month Year) So far i have tried to use the following code: //
0
1555
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 initializing Data property with xml string that matches file exactly. Seems to be problem with binding because if I remove bindings, tree works both ways. I'm binding on server like so... TreeNodeBinding bind = new TreeNodeBinding(); bind.DataMember =...
4
3027
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 debugger unless I add a Global.asax file. When I do that and then try to run the debugger I receive error 403. If I remove the Global.asax file things work fine. The Global.asax file is the one generated by VS 2005 - I don't try to add anything...
2
1880
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 and I want to verify the input password against my database password. PLEASE HELP if (isset($_POST)) $password = @$_POST; if (($login != "") && ($password != "")) { $conn = mysql_connect("localhost", "root", "root"); ...
8
4009
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 guess is what happens when it is accessed through the firewall. However, it works as expected when I use the machine name in place of the IP address. To summarize, the application servers were moved to a new hosting site and one machine is...
7
2856
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: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: (here url)
3
2195
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 Dim rst As DAO.Recordset Dim dbs As DAO.Database Dim rsSQL As DAO.Recordset
0
8397
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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
8732
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
8503
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
8605
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...
0
5632
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
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
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
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.