problem with exec

J

...:::JA:::...

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!
__________________________________________________________________
 
S

Steve Holden

....:::JA:::... said:
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:
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 -------------
 
S

Steven D'Aprano

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.
 
V

vedrandekovic

This is almost certainly because the code contains embedded carriage
returns:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
import os,sys;
^
SyntaxError: invalid syntax


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:
{print "bok kjai ma'}
File "<input>", line 2
{print "bok kjai ma'}
^
SyntaxError: invalid syntax


Thanks!!!!!!!

Regards,Vedran
 
S

Steven D'Aprano

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:

{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.
 
S

Steve Holden

Steven said:
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 -------------
 
V

vedrandekovic

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
 
S

Steven D'Aprano

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.
 
S

Steve Holden

Steven said:
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 -------------
 
G

Gabriel Genellina

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.
 
G

Gabriel Genellina

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.
 
V

vedrandekovic

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top