How "return" no return ?

J

Joseph Garvin

Ximo said:
Hello, I want that the return sentence don't return anything, how can I do
it?. If i do only return it returns None, and pass don't run too.

Can anyone help me?, thanks.
XIMO
Returning None is the same as returning nothing. What exactly are you
trying to do?
 
X

Ximo

Hello, I want that the return sentence don't return anything, how can I do
it?. If i do only return it returns None, and pass don't run too.

Can anyone help me?, thanks.
XIMO
 
X

Ximo

I am doing a interpret of lines and it show me a prompt, and I want if I
write a declaration as "int a" my progrtam return de prompt and nothing
more, for exemple:

Then I'm finding that de function which execute "int a" return me nothing,
and no
 
?

=?iso-8859-1?Q?Fran=E7ois?= Pinard

[Ximo]
I want that the return sentence don't return anything, how can I do
it?

`return' always return something (if we except the case of generators).
Used without arguments, it returns None, as you discovered already.
If a function "falls through" its end, None is implicitely returned.

A function always have a value. I do not understand the need of "not
returning anything". What do you mean? What is the real need?
[...] pass don't run too.

`pass' surely runs. However, `pass' is not a `return' statement.
 
F

Fredrik Lundh

Ximo said:
I am doing a interpret of lines and it show me a prompt, and I want if I
write a declaration as "int a" my progrtam return de prompt and nothing
more, for exemple:


Then I'm finding that de function which execute "int a" return me nothing,
and no

what Python version are you using? here's what a normal Python
interpreter is supposed to do with your example:
File "<stdin>", line 1
int a
^
SyntaxError: invalid syntax
</F>
 
B

Bill Mill

I am doing my own interpreter with the Python languaje.

Do you understand me?

Well, to be frank, no. However, Frederik's point still stands; in the
python langage, "int a" is syntactically invalid. If you're writing
your own interpreter, it should still be syntactically invalid.

Could you perhaps repeat your question with an example of what
behavior is surprising you?

Peace
Bill Mill
bill.mill at gmail.com
 
M

Michael Spencer

Ximo said:
I am doing my own interpreter with the Python languaje.

Do you understand me?

You may be looking for the flags argument to the compile function:
Help on built-in function compile in module __builtin__:

compile(...)
compile(source, filename, mode[, flags[, dont_inherit]]) -> code object

Compile the source string (a Python module, statement or expression)
into a code object that can be executed by the exec statement or eval().
The filename will be used for run-time error messages.
The mode must be 'exec' to compile a module, 'single' to compile a
single (interactive) statement, or 'eval' to compile an expression.
The flags argument, if present, controls which future statements influence
the compilation of the code.
The dont_inherit argument, if non-zero, stops the compilation inheriting
the effects of any future statements in effect in the code calling
compile; if absent or zero these statements do influence the compilation,
in addition to any features explicitly specified.
Michael
 
K

kaerbuhez

Ximo a écrit :
I am doing my own interpreter with the Python languaje.

Do you understand me?

I will do my best : I guess that you are about to write your own non
python interpreter (I mean, it will interpret some language that is not
Python) and your interpreter sadly writes "None" when there is none to
write.
Is that correct ?
If yes, I suggest that you replace somewhere in your code:
print result
by
if result is not None: print result

I know that this is not the question but if it is right that your
interpreter is not a python interpreter and that you build a console on
top of it (I know many assumptions, ...), I would like to kindly suggest
you to use something else that the Python prompt (">>>") - at least on
this NG - I am afraid that _this_ didn't help anybody to understand what
you meant.

If by pure coincidence, this helped you, it would unexpectingly enlight
my day ... and please don't tell me that my english is perfect, I know
it perfectly well.
 
J

Jeff Epler

At the interactive prompt, a result is printed when both these things
are true:
* The entered code is an expression, not any other kind of statement
* The result of the expression is not 'None'
If an expression occurs, information about it will be printed instead.

So the interpreter won't print a result for
Your exampleis not Python, but if it was it would probably be a non-expression
statement, and thus never print a result in the interpreter.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFChKUbJd01MZaTXX0RAunPAJ0b3XM2Lo5fzLdVKvu9MFsc25vwrACfRM3c
QiLX2q0+qeof4uHJa2Kq6K4=
=rkiZ
-----END PGP SIGNATURE-----
 

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,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top