AI library
I thought about an AI library for python. This is the possible structure I came up with. Are there any thoughts about it? ailib/ search.py class State: "represents an immutable state of a problem" def __str__(self): pass def __hash__(self): pass class StateSpace: "represents a traversable collection of states" def start(self): "returns a list of initial states" pass def follow(self, state). "returns a list of states that follow after state" pass def search(self, order=none): """returns an iterator over all states according to order order can be a constant (depth, breadth, incdepth) or a heuristic. If none some default search will be used.""" pass def __iter__(self): return self.search() class Heuristic: def follow(self, state): "returns a list of states probably closer to the solution than s pass class Graph(StateSpace): def __init__(self, paths) "paths is a set of tuples (nodeFrom, nodeTo, weight)" pass def a-star(self, nodeFrom, nodeTo): """searches the shortest path (minimal weight) from nodeFrom to nodeTo.""" pass plan.py class State(search.State): "represents a state of the world that can be changed through action. pass class Agent(search.StateSpace): """For any given state an Agent has a set of possible actions that transform the initial state into a subsequent state.""" def perceive(self): "returns the state of the world the agent perceives to be in." pass def actions(self, state): "returns an iterator over actions available in the given state." pass def __iter__(self): return self.actions(self.perceive()) def plan(self, state, currentState=none): """returns a sequence of actions that are supposed to transform the currently perceived state of the world into the desired state.""" if currentState==none: currentState = self.perceive() else: pass logic.py class Symbol: "a Symbol that can be bound to a value or unbound." def bound(self): "returns true if the symbol is bound." def value(self): "if bound returns the value." class Function: "transforms a list of symbols into another symbol." def __init__(self, *symbols): self.symbols = symbols def __call__(self): "returns some symbol." pass class Predicate: "either is or is not valid for a given list of symbols" def __init__(self, *symbols): self.symbols = symbols def __call__(self): "returns true or false" pass class Junctor: """a relation between predicates deriving a truth value from the truth values of the predicates""" def __init__(self, *predicates): self.predicates = predicates def __call__(self): "returns some truth value" pass class Quantifier: "somehow binds symbols." pass class Clause: "A quantified junctor." pass class Axioms: "A list of clauses" def consistent(self): "returns true if the list of axioms is consistent" pass def valid(self, clause, bind=true): """returns true if the clause is consistent with the set of axio If bind is true, any unbound symbol will be bound to a value if pass statistics.py class Entity: "bearer of statistically relevant features." pass class Set: "set of entities. defines usual statistical functions" def __iter__(self): "iterate over all entities." def avg(self, feature): "returns the average of the given feature of all entities." pass # likewise other functions def entropy(self, a, b): "returns the level of randomnes (0..1) between the given feature pass def correlates(self, a, b, e=0.5): return self.entropy(a, b) < e def mine(self):
Re: MySQLdb, lots of columns and newb-ness
Andrew Sackville-West schrieb: > I have an ascii data dump from a POS system that has 131 fields in a > single column in a flat file. I can easily open the file, read in the > data and assemble it into various formats. okay. what I *want* to do > is insert each of these fields into a mysql database that has 132 > columns that correspond to the 131 fields in the ascii file (plus one > for the date). > > I can successfully connect to mysql and do stuff to my tables my > specific problem is how to efficiently put those 132 fields into the > thing. All I have been able to figure out is really ugly stuff like: > build the mysql statement out of various pieces with appropriate > commas and quote included. stuff like (not tested) Haven't tested it, but maybe http://dev.mysql.com/doc/refman/5.0/en/load-data.html is your friend. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fall of Roman Empire
Thomas Ploch schrieb: >> Ben Finney schrieb: >>> "John Machin" <[EMAIL PROTECTED]> writes: >>> Ben Finney wrote: > \ "...one of the main causes of the fall of the Roman Empire was | > `\that, lacking zero, they had no way to indicate successful | > _o__) termination of their C programs." -- Robert Firth | An amusing .sig, but it doesn't address the root cause: As they had no way of testing for the end of a string, in many cases successful termination of their C programs would have been unlikely. >>> Yet historically proven: the 'imperium' process they were running >>> terminated many centuries ago. >>> >>> Or did it fork and exec a different process? >>> > > I rather stay with the metaphysics: > > > #include "metaphysics.h" > > static metaPower God; > > universe *makeUniverse(metaPower God) > { > if (!God) { > printf("Oops, no God available at the moment.Try again later!"); > return NULL; > } > > universe *everything; > > if (!(everything = malloc(sizeof(universe { > God.mood = REALLY_BORED; > printf("God has no time to create a universe."); > return NULL; > } else { > return universe; > } > } > > > :-) > > Sorry, somehow had to do this. Please slap me (i like it, don't worry) > if it's totally stupid > > s totally stupid! You forgot the main function! (not to mention you returned universe instead of everything) static int main(int argc, char **argv) { char *god_name; if (argc) god_name = argv[1]; else god_name = "YHWH"; metaPower God = getGodByName(god_name); universe *everything = makeUniverse(God); while (simulatePhysics(everything)); return 0; } -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] Py++ - 0.8.5
Roman Yakovenko schrieb: > Hello! > > I'm pleased to announce the 0.8.5 release of Py++. I'm just wondering why there is a comp.lang.python.announce newsgroup. Could it be for making announcements or would that be too obvious? -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on regex
Prabhu Gurumurthy schrieb: > to fix this problem, i used negative lookahead with ip pattern: > so the ip pattern now changes to: > \d{1,3}(\.\d{1,3}){3}(?!/\d+) > > now the problem is 10.150.100.0 works fine, 10.100.4.64 subnet gets > matched with ip pattern with the following result: > > 10.100.4.6 > > Is there a workaround for this or what should change in ip regex pattern. > I think what you want is that neither /d+ nor another digit nor a . follows: \d{1,3}(\.\d{1,3}){3}(?!(/\d)|\d|\.) This way 10.0.0.1234 won't be recognized as ip. Neither will 23.12. which could be a problem if an ip is at the end of a sentence, so you might want to omit that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with small program
smartbei schrieb: > Hello, I am a newbie with python, though I am having a lot of fun using > it. Here is one of the excersizes I am trying to complete: > the program is supposed to find the coin combination so that with 10 > coins you can reach a certain amoung, taken as a parameter. Here is the > current program: > > coins = (100,10,5,1,0.5) > anslist = [] > def bar(fin, hist = {100:0,10:0,5:0,1:0,0.5:0}): > s = sum(x*hist[x] for x in hist) > l = sum(hist.values()) > if s < fin and l < 10: > for c in coins: > if (s+c) <= fin: > hist[c] += 1 > bar(fin, hist) > hist[c] -= 1 > elif l==10 and s==fin and not hist in anslist: > #p1 > anslist.append(hist) > > bar(50) > print anslist > > The problem is that if I run it, anslist prints as [{0.5: 0, 1: 0, 10: > 0, 100: 0, 5: 0}], which doesnt even add up to 50. When I check how > many times the program has reached the #p1 by sticking a print there, > it only reaches it once, and it comes out correct. why is it that this > result is replaced by the incorrect final one? > hist is stored in anslist as a pointer only, therfore the hist[c] -= 1 operates on the same dict as is stored in the anslist. Try the following in the python interpreter: a = { 'key' : 1 } l = [a] l[0]['key'] -= 1 a instead use: anslist.append(dict(hist.items)) which will copy the dict. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with PIPE
Dhika Cikul schrieb: > Hello, > > I'm new in Python, i don't know my subject is correct or wrong. I have > problem with my script. I want to change password with passwd password > in python without user submitted anything from keyboard. I get > tutorial that i must use pipe to process this. And this is my code : > > [code] > > 1. > 2. #!/usr/bin/python > 3. > 4. import os > 5. > 6. COMMAND = 'passwd' > 7. PASSWD = 'mypassword' > 8. > 9. # open a pipe to passwd program and > 10. # write the data to the pipe > 11. p = os.popen("%s" % COMMAND, 'w') > 12. p.write(PASSWD) > 13. p.write('\n') > 14. p.write(PASSWD) > 15. p.close() > 16. > [/code] > > > but i got this error : > > [output] >[EMAIL PROTECTED] cp]$ ./password >Changing password for user cp. >Changing password for cp >(current) UNIX password: passwd: Authentication token manipulation error > [/output] > > Anyone can help me how to write to pipe.. i try several method, and > always fail. > > Thank's I guess the passwd program doesn't allow changing passwords from a pipe since it is a potential security hole. -- http://mail.python.org/mailman/listinfo/python-list
Re: DOS, UNIX and tabs
Sebastian 'lunar' Wiesner schrieb: > Ben <[EMAIL PROTECTED]> typed > >> I have a python script on a windows system that runs fine. Both use >> tabs to indent sections of the code. > > Just a tip for you: In python you never use tabs for indentation. The > python style guide [1] recommends four spaces per indentation level. > > [1] http://www.python.org/dev/peps/pep-0008/ > I like using tabs. And the style guide doesn't give a reason why one shouldn't and neither does the thread http://www.python.org/search/hypermail/python-1994q2/0198.html in the archive. So what's the point in typing four spaces for indentation instead of one tab? -- http://mail.python.org/mailman/listinfo/python-list
Re: DOS, UNIX and tabs
Christophe Cavalaria schrieb: > Steven D'Aprano wrote: > You gave the reason in your post : because other people who are using > software that doesn't understand tabs as YOU expect them to have problems > with your code. > > Tabs aren't a problem at all as long as nobody else than you edit your code. Sorry, but that's a silly argument. With the same argument we should stop using python alltogether since the usual MBA will understand nothing but VBA. -- http://mail.python.org/mailman/listinfo/python-list