string/file manipulation simple

Discussion in 'Python' started by jeff, Aug 1, 2003.

  1. jeff

    jeff Guest

    Hey,

    first of all sorry if this has double posted my mail progie did some
    funny stuff

    I was just creating an encryption/ decryption program in python, ive
    got no problem with the algothims or anything like that. my only
    difficulty is how to i take a file and read in each charecter and then
    preform and operation to it and then output it to another file,
    basically i just wanna know how to take a string and then perform
    actions to each charecter

    cheers

    greg
    jeff, Aug 1, 2003
    #1
    1. Advertising

  2. > I was just creating an encryption/ decryption program in python, ive got
    > no problem with the algothims or anything like that. my only difficulty is
    > how to i take a file and read in each charecter and then preform and
    > operation to it and then output it to another file, basically i just wanna
    > know how to take a string and then perform actions to each charecter


    For example like:

    def code_func(c):
    # something clever
    return new_c

    result = "".join(map(code_func,my_string)) #if code(c) returns a string
    or
    result = "".join([str(item) for item in map(code_func,my_string)])

    or you could do:

    resultchars=""
    for c in my_string:
    # some computation
    resultchars.append(result)
    result = "".join(resultchars)

    (Beware: untested code)

    Andreas
    Andreas Kuntzagk, Aug 1, 2003
    #2
    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. Rex
    Replies:
    2
    Views:
    294
  2. Armel Asselin
    Replies:
    6
    Views:
    1,073
    Armel Asselin
    Nov 16, 2006
  3. Sengly
    Replies:
    4
    Views:
    290
    John Machin
    Jun 8, 2008
  4. AlienBaby

    Simple image manipulation question

    AlienBaby, Jan 19, 2009, in forum: Python
    Replies:
    1
    Views:
    282
  5. Goran Petrovic

    NEEH HELP...simple string manipulation

    Goran Petrovic, Jul 23, 2003, in forum: Javascript
    Replies:
    2
    Views:
    86
    Lasse Reichstein Nielsen
    Jul 23, 2003
Loading...

Share This Page