string/file manipulation simple

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jeff

    string/file manipulation simple

    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
  • Andreas Kuntzagk

    #2
    Re: string/file manipulation simple

    > I was just creating an encryption/ decryption program in python, ive got[color=blue]
    > 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[/color]

    For example like:

    def code_func(c):
    # something clever
    return new_c

    result = "".join(map(cod e_func,my_strin g)) #if code(c) returns a string
    or
    result = "".join([str(item) for item in map(code_func,m y_string)])

    or you could do:

    resultchars=""
    for c in my_string:
    # some computation
    resultchars.app end(result)
    result = "".join(resultc hars)

    (Beware: untested code)

    Andreas

    Comment

    Working...