Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Returning a string

Reply
Thread Tools

Returning a string

 
 
Kless
Guest
Posts: n/a
 
      01-03-2009
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/
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      01-03-2009
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
 
Reply With Quote
 
 
 
 
Kless
Guest
Posts: n/a
 
      01-03-2009
On 3 ene, 19:12, "Diez B. Roggisch" <de...@nospam.web.de> 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'
 
Reply With Quote
 
Simon Forman
Guest
Posts: n/a
 
      01-03-2009
On Jan 3, 11:20*am, Kless <jonas....@googlemail.com> wrote:
> On 3 ene, 19:12, "Diez B. Roggisch" <de...@nospam.web.de> 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?
 
Reply With Quote
 
Kless
Guest
Posts: n/a
 
      01-03-2009
On 3 ene, 19:40, Simon Forman <sajmik...@gmail.com> wrote:
> On Jan 3, 11:20*am, Kless <jonas....@googlemail.com> 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?
 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      01-03-2009
Kless schrieb:
> On 3 ene, 19:12, "Diez B. Roggisch" <de...@nospam.web.de> 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

 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      01-03-2009
Kless schrieb:
> On 3 ene, 19:40, Simon Forman <sajmik...@gmail.com> wrote:
>> On Jan 3, 11:20 am, Kless <jonas....@googlemail.com> 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
 
Reply With Quote
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      01-03-2009
On Sat, 03 Jan 2009 11:46:10 -0800, Kless wrote:

> On 3 ene, 19:40, Simon Forman <sajmik...@gmail.com> wrote:
>> On Jan 3, 11:20Â*am, Kless <jonas....@googlemail.com> 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
 
Reply With Quote
 
Kless
Guest
Posts: n/a
 
      01-03-2009
On 3 ene, 19:51, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
> Kless schrieb:
>
>
>
> > On 3 ene, 19:40, Simon Forman <sajmik...@gmail.com> wrote:
> >> On Jan 3, 11:20 am, Kless <jonas....@googlemail.com> 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.
 
Reply With Quote
 
Simon Brunning
Guest
Posts: n/a
 
      01-06-2009
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
returning none when it should be returning a list? randomtalk@gmail.com Python 11 05-02-2006 10:26 AM
Problem returning identity from SQL Server when string contains semicolon Dan ASP .Net 3 11-16-2005 07:31 PM
"Input string was not in a correct format." Error when returning DataViewRow as a form property =?Utf-8?B?Sm9obiBDaG9ybHRvbg==?= ASP .Net 1 04-15-2004 03:31 PM
returning asp server controls as a string anu ASP .Net 0 10-24-2003 08:23 PM
String question: Returning portion of string with words surrounding highlighted search term? Ken Fine ASP General 4 08-14-2003 06:04 AM



Advertisments