473,659 Members | 3,605 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 1509
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
1312
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 to install wxPython and PythonCard in order to use these, so I provide links for that. I must say,...
1
1717
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 list if not pls let me know.
1
2125
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
2365
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 widgets in wxpython, the programs so created still works a lot better - until now. If you look at...
0
8428
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
8337
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
8851
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...
1
8531
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
8628
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
7359
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...
0
5650
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();...
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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.