473,387 Members | 1,420 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,387 software developers and data experts.

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.components.Calendar.GetDate().GetDay()
for i in range(1,8):
act=dzien+i -1
eval( 'self.components.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.components.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 1491
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.components.Calendar.GetDate().GetDay()
for i in range(1,8):
act=dzien+i -1
eval( 'self.components.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.components.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.components, "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.components, "d" + str(i))
obj.text = "hello world"
#####################

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

#####################
#print out the new values:
for i in range(1, 4):
print getattr(s.components, "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...@yahoo.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.components, "d" + str(i))
obj.text = "hello world"
#####################
#####################
#change the values:
for i in range(1, 4):
getattr(s.components, "d" + str(i)).text = "goodybe"
#####################
#####################
#print out the new values:
for i in range(1, 4):
print getattr(s.components, "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 "expressions". 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
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...
1
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...
1
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: ...
24
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.