- #1
BiGyElLoWhAt
Gold Member
- 1,623
- 131
I'm revisiting python, because recently our physics department decided to adopt it as our computational language, and I missed the class. I've also been given the impression that it's a very good language for algorithms and what-not.
According to https://docs.python.org/3/tutorial/introduction.html
This seems so useless!
I'm really wanting to try to screw around with some simple AI, via writing a program that rewrites itself with new variables generated via input (for later reference).
I'm anticipating the need to alter strings based on new input. Any work arounds? I went through the string methods library and couldn't find anything I thought would be of use:
https://docs.python.org/3/library/stdtypes.html#string-methods
Perhaps a way to generate a new string, copy the contents over, delete the old, copy them back to a string with the same name as the original but with the necessary alterations.
Would I be better off just going with something along the lines of string_2 = string_1[:5] + 'new information' +string[5:]
?
Also, I haven't figured out exactly how I'm going to implement a lot of these things, so if you have other idea's, feel free to toss them my way
For right now the goal is to come up with a program that takes an input as a series of tokens, parses them into a 'command' object (or array, I don't know if python actually has objects), then executes the command which "alters" the program itself.
Thanks!
According to https://docs.python.org/3/tutorial/introduction.html
Python strings cannot be changed — they are https://www.physicsforums.com/glossary.html#term-immutable . Therefore, assigning to an indexed position in the string results in an error:
This seems so useless!
I'm really wanting to try to screw around with some simple AI, via writing a program that rewrites itself with new variables generated via input (for later reference).
I'm anticipating the need to alter strings based on new input. Any work arounds? I went through the string methods library and couldn't find anything I thought would be of use:
https://docs.python.org/3/library/stdtypes.html#string-methods
Perhaps a way to generate a new string, copy the contents over, delete the old, copy them back to a string with the same name as the original but with the necessary alterations.
Would I be better off just going with something along the lines of string_2 = string_1[:5] + 'new information' +string[5:]
?
Also, I haven't figured out exactly how I'm going to implement a lot of these things, so if you have other idea's, feel free to toss them my way
For right now the goal is to come up with a program that takes an input as a series of tokens, parses them into a 'command' object (or array, I don't know if python actually has objects), then executes the command which "alters" the program itself.
Thanks!
Last edited by a moderator: