473,397 Members | 2,028 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,397 software developers and data experts.

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\Lib\site-packages\VL\__init__.py", line 188, in
kompajlati
kompajlati_proces()
File "C:\Python24\Lib\site-packages\VL\__init__.py", line 183, in
kompajlati_proces
h2=Konzola()
File "C:\Python24\Lib\site-packages\VL\__init__.py", line 158, in __init__
k=kod(ZTextCtrl.GetLabel())
File "C:\Python24\Lib\site-packages\VL\__init__.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 1482
....:::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\Lib\site-packages\VL\__init__.py", line 188, in
kompajlati
kompajlati_proces()
File "C:\Python24\Lib\site-packages\VL\__init__.py", line 183, in
kompajlati_proces
h2=Konzola()
File "C:\Python24\Lib\site-packages\VL\__init__.py", line 158, in __init__
k=kod(ZTextCtrl.GetLabel())
File "C:\Python24\Lib\site-packages\VL\__init__.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\nprint '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...@holdenweb.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\Lib\site-packages\VL\__init__.py", line 188, in
kompajlati
kompajlati_proces()
File "C:\Python24\Lib\site-packages\VL\__init__.py", line 183, in
kompajlati_proces
h2=Konzola()
File "C:\Python24\Lib\site-packages\VL\__init__.py", line 158, in __init__
k=kod(ZTextCtrl.GetLabel())
File "C:\Python24\Lib\site-packages\VL\__init__.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\nprint '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,this 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,this 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,this 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(source).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
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(source).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 #11
On 23 srp, 09:19, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Sun, 22 Jul 2007 10:36:59 -0300, <vedrandeko...@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(source).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
Hello,

I know what do you mean and I really need that , but I don't know how
to I do this. Please help me!!!!! It's really important to me


Regards,

Vedran

Jul 23 '07 #12

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

Similar topics

8
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...
4
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...
1
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...
1
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...
3
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...
2
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...
2
by: peleme | last post by:
Hi, Here is a code example to visualize my problem. ---------------------------------------------------------------------------------- import thread import threading from time import sleep ...
5
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
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...
27
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...
0
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...
0
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...

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.