471,337 Members | 1,071 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 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 1417
....:::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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Filip Dreger | last post: by
4 posts views Thread by Oracle 9Ri2 AS 2.1 IA 64 | last post: by
1 post views Thread by Steve Thorpe | last post: by
2 posts views Thread by peleme | last post: by
5 posts views Thread by TPJ | last post: by

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.