Returning a string

Discussion in 'Python' started by Kless, Jan 3, 2009.

  1. Kless

    Kless Guest

    Kless, Jan 3, 2009
    #1
    1. Advertising

  2. Kless schrieb:
    > 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
     
    Diez B. Roggisch, Jan 3, 2009
    #2
    1. Advertising

  3. Kless

    Kless Guest

    On 3 ene, 19:12, "Diez B. Roggisch" <> wrote:
    > Kless schrieb:
    >
    > > 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


    Afghanistan
    AF
    Out[19]: u'AF'
    AFG
    Out[19]: u'AFG'
    004
    Out[19]: u'004'
     
    Kless, Jan 3, 2009
    #3
  4. Kless

    Simon Forman Guest

    On Jan 3, 11:20 am, Kless <> wrote:
    > On 3 ene, 19:12, "Diez B. Roggisch" <> wrote:
    >
    > > Kless schrieb:

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

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


    What?
     
    Simon Forman, Jan 3, 2009
    #4
  5. Kless

    Kless Guest

    On 3 ene, 19:40, Simon Forman <> wrote:
    > On Jan 3, 11:20 am, Kless <> wrote:
    >
    > > 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?
     
    Kless, Jan 3, 2009
    #5
  6. Kless schrieb:
    > On 3 ene, 19:12, "Diez B. Roggisch" <> wrote:
    >> Kless schrieb:
    >>
    >>> 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

    >
    > 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:

    >>> unicode("foo")

    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:

    >>> print repr(unicode("foo"))

    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
     
    Diez B. Roggisch, Jan 3, 2009
    #6
  7. Kless schrieb:
    > On 3 ene, 19:40, Simon Forman <> wrote:
    >> On Jan 3, 11:20 am, Kless <> wrote:
    >>
    >>> 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
     
    Diez B. Roggisch, Jan 3, 2009
    #7
  8. On Sat, 03 Jan 2009 11:46:10 -0800, Kless wrote:

    > On 3 ene, 19:40, Simon Forman <> wrote:
    >> On Jan 3, 11:20 am, Kless <> wrote:
    >>
    >> > 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
     
    Marc 'BlackJack' Rintsch, Jan 3, 2009
    #8
  9. Kless

    Kless Guest

    On 3 ene, 19:51, "Diez B. Roggisch" <> wrote:
    > Kless schrieb:
    >
    >
    >
    > > On 3 ene, 19:40, Simon Forman <> wrote:
    > >> On Jan 3, 11:20 am, Kless <> wrote:

    >
    > >>> 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.
     
    Kless, Jan 3, 2009
    #9
  10. 2009/1/3 Kless <>:
    > 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.

    --
    Cheers,
    Simon B.
     
    Simon Brunning, Jan 6, 2009
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anu
    Replies:
    0
    Views:
    311
  2. =?Utf-8?B?Sm9obiBDaG9ybHRvbg==?=
    Replies:
    1
    Views:
    6,083
    =?Utf-8?B?Sm9obiBDaG9ybHRvbg==?=
    Apr 15, 2004
  3. Dan
    Replies:
    3
    Views:
    4,602
  4. Replies:
    11
    Views:
    668
    Christos Georgiou
    May 2, 2006
  5. Ken Fine
    Replies:
    4
    Views:
    203
    Ken Fine
    Aug 14, 2003
Loading...

Share This Page