×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    1

    from number to string

    hallo everybody,

    I am trying to create a string file that is like:

    a_01
    a_02
    a_03
    .
    .
    a_10

    Is it possible to convert a nuber to a string? Is it possible in python?

    thanks

    GS

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: from number to string

    Quote Originally Posted by GuidoS_1981 View Post
    hallo everybody,

    I am trying to create a string file that is like:

    a_01
    a_02
    a_03
    .
    .
    a_10

    Is it possible to convert a nuber to a string? Is it possible in python?

    thanks

    GS
    I'm not sure I understand what you mean, but it is done with the str function

    x=46
    str(x) will return the string '46'

  3. #3
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,795

    Re: from number to string

    Quote Originally Posted by GuidoS_1981 View Post
    hallo everybody,

    I am trying to create a string file that is like:

    a_01
    a_02
    a_03
    .
    .
    a_10

    Is it possible to convert a nuber to a string? Is it possible in python?

    thanks

    GS
    Your question is more into core Python rather than Py60.
    I think you are a newbie to python.
    Go through the docs for better understanding
    http://docs.python.org/tut/

    Best Regards
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    125

    Re: from number to string

    Quote Originally Posted by GuidoS_1981 View Post
    I am trying to create a string file that is like:

    a_01
    a_02
    a_03
    .
    .
    a_10
    Try...

    Code:
    f = open('outfile', 'w')
    for i in range(1, 11):
        f.write('a_%02d\n' % i)
    f.close()
    Quote Originally Posted by GuidoS_1981 View Post
    Is it possible to convert a nuber to a string?
    In addition to the 'str' function, you can use a printf-style format specifier as used in the above code. Examples...

    Code:
    '%d'   % 1 -> '1'
    '%2d'  % 1 -> ' 1'
    '%3d'  % 1 -> '  1'
    '%02d' % 1 -> '01'
    '%03d' % 1 -> '001'

Similar Threads

  1. Replies: 2
    Last Post: 2007-04-20, 03:38
  2. WML & WMLSCript problem ????
    By gemini_shooter in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-14, 06:02
  3. WML & WMLSCript problem ????
    By gemini_shooter in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-14, 06:01
  4. Personal
    By JSmith77 in forum PersonalJava
    Replies: 4
    Last Post: 2003-07-30, 12:52
  5. D211 new linux driver 1.04 not working !!
    By franz_meyer in forum Multimodecards
    Replies: 1
    Last Post: 2002-12-12, 08:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×