string/file manipulation simple

J

jeff

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
 
A

Andreas Kuntzagk

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,083
Messages
2,570,589
Members
47,211
Latest member
JaydenBail

Latest Threads

Top