473,915 Members | 3,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with exec

Hello,

After my program read and translate this code:

koristi os,sys;
ispisi 'bok kaj ima';

into the:

import os,sys;
print 'bok kaj ima';

and when it run this code with "exec", I always get error like this, but I
still dont't know what is a problem:

Traceback (most recent call last):
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 188, in
kompajlati
kompajlati_proc es()
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 183, in
kompajlati_proc es
h2=Konzola()
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 158, in __init__
k=kod(ZTextCtrl .GetLabel())
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 83, in kod
exec(str_ngh)
File "<string>", line 1
import os ,sys ;
^
SyntaxError: invalid syntax

PS: How can I change when user write script with my program to he don't need
aspirate the lines of his source code
e.g.
import os,sys
n=90
if n==90:print "OK"
else:print "No"
Regards,

Vedran
_______________ _______________ _______________ _______________ ______ Vedran
veki ICQ#: 264412055 Current ICQ status: + More ways to contact me Get ICQ!
_______________ _______________ _______________ _______________ ______


Jul 21 '07 #1
11 1518
....:::JA:::... wrote:
Hello,

After my program read and translate this code:

koristi os,sys;
ispisi 'bok kaj ima';

into the:

import os,sys;
print 'bok kaj ima';

and when it run this code with "exec", I always get error like this, but I
still dont't know what is a problem:

Traceback (most recent call last):
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 188, in
kompajlati
kompajlati_proc es()
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 183, in
kompajlati_proc es
h2=Konzola()
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 158, in __init__
k=kod(ZTextCtrl .GetLabel())
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 83, in kod
exec(str_ngh)
File "<string>", line 1
import os ,sys ;
^
SyntaxError: invalid syntax
This is almost certainly because the code contains embedded carriage
returns:
>>code = """import os,sys;\nprint 'bok kaj ima';"""
exec code
bok kaj ima
>>code = """import os,sys;\r\nprin t 'bok kaj ima';"""
exec code
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
import os,sys;
^
SyntaxError: invalid syntax
>>>
PS: How can I change when user write script with my program to he don't need
aspirate the lines of his source code
e.g.
import os,sys
n=90
if n==90:print "OK"
else:print "No"

I'm afraid I don't understand this question. If you are talking about
the indentation of the code, if you don't want indentation you will have
to use braces - { and } - to indicate the nesting structure of your program.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Jul 21 '07 #2
On Sat, 21 Jul 2007 16:31:38 -0400, Steve Holden wrote:
I'm afraid I don't understand this question. If you are talking about
the indentation of the code, if you don't want indentation you will have
to use braces - { and } - to indicate the nesting structure of your program.
Oh my, teasing the n00bs like that is not nice. You know Python doesn't
uses braces, it uses BEGIN ... END blocks.
--
Steven.

Jul 22 '07 #3
On 21 srp, 22:31, Steve Holden <st...@holdenwe b.comwrote:
...:::JA:::... wrote:
Hello,
After my program read and translate this code:
koristi os,sys;
ispisi 'bok kaj ima';
into the:
import os,sys;
print 'bok kaj ima';
and when it run this code with "exec", I always get error like this, but I
still dont't know what is a problem:
Traceback (most recent call last):
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 188, in
kompajlati
kompajlati_proc es()
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 183, in
kompajlati_proc es
h2=Konzola()
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 158, in __init__
k=kod(ZTextCtrl .GetLabel())
File "C:\Python24\Li b\site-packages\VL\__i nit__.py", line 83, in kod
exec(str_ngh)
File "<string>", line 1
import os ,sys ;
^
SyntaxError: invalid syntax

This is almost certainly because the code contains embedded carriage
returns:
>>code = """import os,sys;\nprint 'bok kaj ima';"""
>>exec code
bok kaj ima
>>code = """import os,sys;\r\nprin t 'bok kaj ima';"""
>>exec code
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
import os,sys;
^
SyntaxError: invalid syntax
>>>
PS: How can I change when user write script with my program to he don't need
aspirate the lines of his source code
e.g.
import os,sys
n=90
if n==90:print "OK"
else:print "No"

I'm afraid I don't understand this question. If you are talking about
the indentation of the code, if you don't want indentation you will have
to use braces - { and } - to indicate the nesting structure of your program.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
Hello,

Thanks for everything previously, but just to I ask about code
indentation,thi s with { and } doesn't
employed, here is my example how can I solve this about code
indentation:
>>n=90
if n==90:
{print "bok kjai ma'}
File "<input>", line 2
{print "bok kjai ma'}
^
SyntaxError: invalid syntax
Thanks!!!!!!!

Regards,Vedran

Jul 22 '07 #4
On Sun, 22 Jul 2007 03:23:30 -0700, vedrandekovic wrote:
Thanks for everything previously, but just to I ask about code
indentation,thi s with { and } doesn't
employed, here is my example how can I solve this about code
indentation:
>>>n=90
if n==90:
{print "bok kjai ma'}
File "<input>", line 2
{print "bok kjai ma'}
^
SyntaxError: invalid syntax

Steve Holden was playing silly games. You can't use { } for indentation.
You have to use indentation.

--
Steven.

Jul 22 '07 #5
Steven D'Aprano wrote:
On Sun, 22 Jul 2007 03:23:30 -0700, vedrandekovic wrote:
>Thanks for everything previously, but just to I ask about code
indentation,th is with { and } doesn't
employed, here is my example how can I solve this about code
indentation:
>>>>n=90
if n==90:
{print "bok kjai ma'}
File "<input>", line 2
{print "bok kjai ma'}
^
SyntaxError: invalid syntax


Steve Holden was playing silly games. You can't use { } for indentation.
You have to use indentation.
I wasn't playing silly games at all, and I did prefix that part ofmy
answer with "I'm afraid I don't understand this question". The OP is
writing a program to "translate" a Python-like language that uses
non-English keywords into Python. Since the application is transforming
its input, it could transform braces into indentation. Of course
*Python* doesn't use braces, but the question was how to write
"pseudo-Python" without using indentation to indicate grouping.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Jul 22 '07 #6
I wasn't playing silly games at all, and I did prefix that part ofmy
answer with "I'm afraid I don't understand this question". The OP is
writing a program to "translate" a Python-like language that uses
non-English keywords into Python. Since the application is transforming
its input, it could transform braces into indentation. Of course *Python*
doesn't use braces, but the question was how to write "pseudo-Python"
without using indentation to indicate grouping.

regards
Steve

Hi,

This previously is exactly what I need can you help me somehow about
this
code
indentation, on any way you know.Plese help I will really appreciate
this!!!!!!!!!!! !!!

Regards,

Vedran
Jul 22 '07 #7
On Sun, 22 Jul 2007 09:12:21 -0400, Steve Holden wrote:

>Steve Holden was playing silly games. You can't use { } for indentation.
You have to use indentation.
I wasn't playing silly games at all, and I did prefix that part ofmy
answer with "I'm afraid I don't understand this question". The OP is
writing a program to "translate" a Python-like language that uses
non-English keywords into Python. Since the application is transforming
its input, it could transform braces into indentation. Of course
*Python* doesn't use braces, but the question was how to write
"pseudo-Python" without using indentation to indicate grouping.
Then I have misunderstood you, and I apologize.

--
Steven.

Jul 22 '07 #8
Steven D'Aprano wrote:
On Sun, 22 Jul 2007 09:12:21 -0400, Steve Holden wrote:

>>Steve Holden was playing silly games. You can't use { } for indentation.
You have to use indentation.
I wasn't playing silly games at all, and I did prefix that part ofmy
answer with "I'm afraid I don't understand this question". The OP is
writing a program to "translate" a Python-like language that uses
non-English keywords into Python. Since the application is transforming
its input, it could transform braces into indentation. Of course
*Python* doesn't use braces, but the question was how to write
"pseudo-Python" without using indentation to indicate grouping.

Then I have misunderstood you, and I apologize.
Thanks. I was hoping that was the case.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Jul 22 '07 #9
En Sun, 22 Jul 2007 10:36:59 -0300, <ve***********@ v-programs.com>
escribió:
>Since the application is transforming
its input, it could transform braces into indentation. Of course
*Python*
doesn't use braces, but the question was how to write "pseudo-Python"
without using indentation to indicate grouping.
This previously is exactly what I need can you help me somehow about
this
code
indentation, on any way you know.Plese help I will really appreciate
this!!!!!!!!!!! !!!
If you are using the tokenize module as suggested some time ago, try to
analyze the token sequence you get using { } (or perhaps begin/end pairs
in your own language, that are easier to distinguish from a dictionary
display) and the sequence you get from the "real" python code. Then write
a script to transform one into another:

from tokenize import generate_tokens
from token import tok_name
from cStringIO import StringIO

def analyze(source) :
g = generate_tokens (StringIO(sourc e).readline)
for toknum, tokval, _, _, _ in g:
print tok_name[toknum], repr(tokval)

I think you basically will have to ignore INDENT, DEDENT, and replace
NAME+"begin" with INDENT, NAME+"end" with DEDENT.

--
Gabriel Genellina

Jul 23 '07 #10

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

Similar topics

8
2201
by: Filip Dreger | last post by:
Each function has a func_code property that is suposed to contain the pure bytecode of the function. All the context (including reference to relevant namespaces) is stored in different fields of the function object. Since 'exec' is able to execute any string or bytecode in the current scope, it would seem possible to execute code of any function in any namespace. But no matter how I tried, I could not do it. There must be something I am...
4
13823
by: Oracle 9Ri2 AS 2.1 IA 64 | last post by:
Hello, I am working with Oracle 9Ri2 version on Linux AS 2.1 for IA64. I have a problem when i try to lanch the following program : EXEC SQL PREPARE MyStmt FROM SELECT CHAMP1 FROM TAB1 WHERE CHAMP2="4" AND CHAMP3 = "C" FOR UPDATE;
1
11794
by: Steve Thorpe | last post by:
Hi. I have two sql servers and have ran exec sp_addlinkedserver 'ACSPSM', N'SQL Server' to link one to the other and also vise versa. Each server has two users permissioned. My problem is when ever I try to do something that does a remote write I get the follow error message Microsoft OLE DB Provider for SQL Server error '80040e14'
1
1548
by: Matik | last post by:
Hello to all, Maybe first small introduction: - SQLServer 2000 SP3, - XP Pro EN, - ActiveX, - SP in database It should working like this. There is a instanse of an object working, which recieves "telegramms"
3
10643
by: Cesco | last post by:
Hallo to everybody. I have a DTS in SQL Server 2000 and I need to execute it from stored procedure. I know that there are various method fot does this but they doesn't work. The first method that I try to use is with the stored procedure "xp_cmdshell". If I write in DOS prompt dtsrun /F c:\DTS1.dts the DTS1 will execute well
2
3220
by: Vaap | last post by:
I did lot of googling to see if I can solve the SQL server not found problem while trying to run ASP.Net community starter kit from an XP machine to Windows 2003 server hosting SQL server 2000 database. Tried all possible combinations but it still fails. I have Windows 2003 server having SQL Server 2000 installed with SP2. The installation went Ok on a XP professional machine and I was able to create database and user logins etc on...
2
1342
by: peleme | last post by:
Hi, Here is a code example to visualize my problem. ---------------------------------------------------------------------------------- import thread import threading from time import sleep def a():
5
2443
by: TPJ | last post by:
I have the following code: ----------------------------------- def f(): def g(): a = 'a' # marked line 1 exec 'a = "b"' in globals(), locals() print "g: a =", a
2
4680
by: chets | last post by:
Hi All, I am facing problem in executing one dynamic query in PRO *C program on linux. I want to update table mytable by data MADURAI for a column mycolumn1 where primary key is myPK.I want to use EXECUTE IMMEDIATE with context.But it is not working. Following is my piece of code. Please help. Thanks in advance. int main() {
27
5169
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set contents ]; close $fileID
1
11064
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
10541
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
9730
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...
1
8099
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7253
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
6143
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4777
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
4343
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3367
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.