By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,494 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,494 IT Pros & Developers. It's quick & easy.

How "return" no return ?

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Ximo wrote:
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?
Jul 19 '05 #2

P: n/a
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:
2+2 4 int a

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

"Joseph Garvin" <k0*****@kzoo.edu> escribió en el mensaje
news:ma**************************************@pyth on.org... Ximo wrote:
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?

Jul 19 '05 #3

P: n/a
[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.

--
François Pinard http://pinard.progiciels-bpi.ca
Jul 19 '05 #4

P: n/a
"Ximo" wrote:
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:
2+2 4 int a

Then I'm finding that de function which execute "int a" return me nothing,
and no
int a None
what Python version are you using? here's what a normal Python
interpreter is supposed to do with your example:
2+2 4 int a File "<stdin>", line 1
int a
^
SyntaxError: invalid syntax


</F>

Jul 19 '05 #5

P: n/a
I am doing my own interpreter with the Python languaje.

Do you understand me?

"Fredrik Lundh" <fr*****@pythonware.com> escribió en el mensaje
news:ma**************************************@pyth on.org...
"Ximo" wrote:
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:
>>> 2+2

4
>>> int a
>>>


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

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


</F>

Jul 19 '05 #6

P: n/a
On 5/12/05, Ximo <el*****@yahoo.es> wrote:
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

"Fredrik Lundh" <fr*****@pythonware.com> escribió en el mensaje
news:ma**************************************@pyth on.org...
"Ximo" wrote:
I am doing a interpret of lines and it show me a prompt, and I want ifI
write a declaration as "int a" my progrtam return de prompt and nothing
more, for exemple:

>>> 2+2
4
>>> int a
>>>

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

>>> int a
None
>>>


what Python version are you using? here's what a normal Python
interpreter is supposed to do with your example:
> 2+2

4
> int a

File "<stdin>", line 1
int a
^
SyntaxError: invalid syntax
>


</F>



--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #7

P: n/a
Ximo wrote:
I am doing my own interpreter with the Python languaje.

Do you understand me?

"Fredrik Lundh" <fr*****@pythonware.com> escribió en el mensaje
news:ma**************************************@pyth on.org...
"Ximo" wrote:

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:


You may be looking for the flags argument to the compile function:
exec compile("int(3)","<console>","single") 3 exec compile("int(3)","<console>","exec")

help(compile) 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

Jul 19 '05 #8

P: n/a
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.

Jul 19 '05 #9

P: n/a
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
a = 3 # because it's an assignment statement
def f(): return # because it's a 'def' statement
None # because the result of the expression is 'None'
f() # because the result of the expression is 'None'
Your example int a

is 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)

iD8DBQFChKUbJd01MZaTXX0RAunPAJ0b3XM2Lo5fzLdVKvu9MF sc25vwrACfRM3c
QiLX2q0+qeof4uHJa2Kq6K4=
=rkiZ
-----END PGP SIGNATURE-----

Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.