Returning a string

D

Diez B. Roggisch

Kless said:
How is possible that I can print a variable, but when I use *return
var* it returns an empty string

http://paste.pocoo.org/show/97588/

I don't see anything that indicates that the returned object is the
empty string. Simply because there is no code testing for that. And of
course you don't show any debugging output, which doesn't help either.

Diez
 
K

Kless

I don't see anything that indicates that the returned object is the
empty string. Simply because there is no code testing for that. And of
course you don't show any debugging output, which doesn't help either.

Diez

Afghanistan
AF
Out[19]: u'AF'
AFG
Out[19]: u'AFG'
004
Out[19]: u'004'
 
K

Kless

Afghanistan
AF
Out[19]: u'AF'
AFG
Out[19]: u'AFG'
004
Out[19]: u'004'

What?

That's the output got from ipython. As you can see, it prints
'Afghanistan' but it can not returns it. In change, the another
strings are returned.

Could it be because it isn't returning the value from the
recursivecall?
 
D

Diez B. Roggisch

Kless said:
I don't see anything that indicates that the returned object is the
empty string. Simply because there is no code testing for that. And of
course you don't show any debugging output, which doesn't help either.

Diez

Afghanistan
AF
Out[19]: u'AF'
AFG
Out[19]: u'AFG'
004
Out[19]: u'004'

What is that? IPython? And I don't see no empty string here. *What* I
see is the way python's interactive prompt puts out strings, like this:
u'foo'

Do you mean by any chance that you don't understand why print prints
foo, but the prompt shows u"foo"? That is because the prompt invokes

repr(o)

to print out an object:
u'foo'

Which means that the output includes quotes and the "u"-prefix in case
of an unicode object to help the user to see what the current object
looks like.

Diez
 
D

Diez B. Roggisch

Kless said:
Afghanistan
AF
Out[19]: u'AF'
AFG
Out[19]: u'AFG'
004
Out[19]: u'004'
What?

That's the output got from ipython. As you can see, it prints
'Afghanistan' but it can not returns it. In change, the another
strings are returned.

Could it be because it isn't returning the value from the
recursivecall?

Yep, I guess that's the problem. You need to do

if cell_tag:
return clean_tags(cell_tag)


Diez
 
M

Marc 'BlackJack' Rintsch

Afghanistan
AF
Out[19]: u'AF'
AFG
Out[19]: u'AFG'
004
Out[19]: u'004'

What?

That's the output got from ipython. As you can see, it prints
'Afghanistan' but it can not returns it. In change, the another strings
are returned.

Maybe you should show the *input* too…

Ciao,
Marc 'BlackJack' Rintsch
 
K

Kless

Kless schrieb:


Afghanistan
AF
Out[19]: u'AF'
AFG
Out[19]: u'AFG'
004
Out[19]: u'004'
What?
That's the output got from ipython. As you can see, it prints
'Afghanistan' but it can not returns it. In change, the another
strings are returned.
Could it be because it isn't returning the value from the
recursivecall?

Yep, I guess that's the problem. You need to do

if cell_tag:
    return clean_tags(cell_tag)

Diez

Thank you very much. It works now.
 
S

Simon Brunning

2009/1/3 Kless said:
How is possible that I can print a variable, but when I use *return
var* it returns an empty string

What makes you think it's returning an empty string? You aren't doing
anything with the return value in line 26 of your example.
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top