473,573 Members | 4,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with eval while using PythonCard

Hi

its my first post. I have a problem, I want to user eval() function in
a for loop to set labels to staticText so i done something like this:

dzien=self.comp onents.Calendar .GetDate().GetD ay()
for i in range(1,8):
act=dzien+i -1
eval( 'self.component s.d' + str(i) + '.text = "'+ str(act) + '"')

but there is a problem, the program returned error:

File "/home/lipton/Projekty/kami-organizer/grafik.py", line 27, in __init__
eval( 'self.component s.d' + str(i) + '.text = "'+ str(act) + '"')
File "<string>", line 1
self.components .d1.text = "25"

SyntaxError: invalid syntax

dont know what is wrong, becouse when i copy and paste in to code :
self.components .d1.text = "25"

it work great, but when Im trying to do it using eval() it give me a SyntaxError

Please help.

ps. sorry for my english ;)
May 25 '07 #1
3 1504
On May 25, 3:33 pm, "Michal Lipinski" <michal.lipin.. .@gmail.com>
wrote:
Hi

its my first post. I have a problem, I want to user eval() function in
a for loop to set labels to staticText so i done something like this:

dzien=self.comp onents.Calendar .GetDate().GetD ay()
for i in range(1,8):
act=dzien+i -1
eval( 'self.component s.d' + str(i) + '.text = "'+ str(act) + '"')

but there is a problem, the program returned error:

File "/home/lipton/Projekty/kami-organizer/grafik.py", line 27, in __init__
eval( 'self.component s.d' + str(i) + '.text = "'+ str(act) + '"')
File "<string>", line 1
self.components .d1.text = "25"

SyntaxError: invalid syntax

dont know what is wrong, becouse when i copy and paste in to code :
self.components .d1.text = "25"

it work great, but when Im trying to do it using eval() it give me a SyntaxError

Please help.

ps. sorry for my english ;)

How about something like this:
############
#make object:

class S(object):pass
class X(object):pass
class Y(object):pass

s = S()
s.components = X()
s.components.d1 = Y()
s.components.d1 .text = "hello world"

###########

obj = getattr(s.compo nents, "d" + str(1))
obj.text = "goodybe"
print s.components.d1 .text

May 25 '07 #2
Here's a complete example:

############### ####
#create object 's':

class S(object):pass
class X(object):pass
class Y(object):pass

s = S()
s.components = X()
s.components.d1 = Y()
s.components.d2 = Y()
s.components.d3 = Y()
############### #######

############### #######
set some initial values:
for i in range(1, 4):
obj = getattr(s.compo nents, "d" + str(i))
obj.text = "hello world"
############### ######

############### ######
#change the values:
for i in range(1, 4):
getattr(s.compo nents, "d" + str(i)).text = "goodybe"
############### ######

############### ######
#print out the new values:
for i in range(1, 4):
print getattr(s.compo nents, "d" + str(i)).text
############### ######

May 25 '07 #3
On May 25, 4:43 pm, "Michal Lipinski" <michal.lipin.. .@gmail.com>
wrote:
now it's working just fine. but still I dont know why eval dont work ?

and thx for help

25 May 2007 15:05:03 -0700, 7stud <bbxx789_0...@y ahoo.com>:
Here's a complete example:
############### ####
#create object 's':
class S(object):pass
class X(object):pass
class Y(object):pass
s = S()
s.components = X()
s.components.d1 = Y()
s.components.d2 = Y()
s.components.d3 = Y()
############### #######
############### #######
set some initial values:
for i in range(1, 4):
obj = getattr(s.compo nents, "d" + str(i))
obj.text = "hello world"
############### ######
############### ######
#change the values:
for i in range(1, 4):
getattr(s.compo nents, "d" + str(i)).text = "goodybe"
############### ######
############### ######
#print out the new values:
for i in range(1, 4):
print getattr(s.compo nents, "d" + str(i)).text
############### ######
--
http://mail.python.org/mailman/listinfo/python-list

--
Pozdrawiam

Michał Lipiński

http://lipton.kom.pl
1) Don't use eval()

2) Don't use eval()

3) eval() only works on python "expression s". In python, an
assignment statement is not an expression.

May 25 '07 #4

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

Similar topics

0
1310
by: Ron Stephens | last post by:
Thanks, Tony, we long term newbies need to stick together ;-)) I just updated a few PythonCard versions of three of the modules from askMerlin, and posted them in a link right below the askMerlin100.py command line program. The PythonCard version of election.py in particular is very easy and illustrates what these programs do. You will have...
1
1714
by: Varun Hiremath | last post by:
Hello everybody, I was trying to install pythoncard on my system and I got this error. I am using an unstable version of Debian. Can someone tell me what the error could be. Is it because I am usingUnstable version of Debian I am getting this error or is it because of some other reason. I hope I am mailing this error to the right mailing...
1
2120
by: LenS | last post by:
Under the "Getting Started with Pythoncard" there is a short little example of changing the starter1.py. I have made the 2 changes and when I run the program I get the following error: Traceback error .... result = dialog.alertDialog(self, 'It works!', 'Showing Off') NameError: name 'self' is not defined
24
2358
by: John Henry | last post by:
For serveral years, I have been looking for a way to migrate away from desktop GUI/client-server programming onto the browser based network computing model of programming. Unfortunately, up until recently, browser based programs are very limited - due to the limitation of HTML itself. Eventhough PythonCard hasn't keep up with the latest...
0
7741
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...
0
7661
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...
0
8165
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...
0
6347
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...
0
5252
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...
0
3692
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...
0
3686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1256
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
984
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...

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.