Re: Merging Objects
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 help(getattr) help(setattr) Regards, Jesus Rivero - (Neurogeek) Cloudthunder wrote: Question: how do I merge two objects? I would like to be able to have an instance of Foo and an instance of Boo and then be able to add them together and create a new object that has the methods and properties of both objects. I am going to be doing a lot of this and I don't want to have to dynamically (or otherwise) create a whole bunch of classes that inherit from both Foo and Boo then create instances of those new children classes. In fact, this wouldn't work for me anyway because I am going to have an instance of Foo which will be used within my algorithm for sometime then later I will want to merge it with a fresh instance of Boo or otherwise give it all the methods and properties of the Boo class. Am I making any sense here? Thanks. - OP P.S. I also noticed that we can no long use the __members__ property to get a tuple of all a class's methods. How can I get the same info from dir()? Dir(), I understand, tells you about all properties and you can't tell it to just list the methods. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFEMWPzdIssYB9vBoMRAnkLAJ4mkUTlB9POlOyE5MeHukAJ5LeawQCghtoQ Dsn33bw0LYFsNS2AYStPLdU= =Dt4g -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Threads and sys.excepthook
Hello guys, I have this problem and i don't know any workarounds yet. Im implementing a DB Connection pool, which initially creates 20 connections and keep them in a dictionary. It also implements a method for allowing external method/classes to get a connection from that pool. he main issue is that, from a testing app, I create a loop like this to test the pool: import thread import sys import seen #this is my module DB = seen.DBManager() def test(name): try : idc,conn = DB.get_conn() print Thread: ,name, -- ,DB, ID: ,idc except : print sys.exc_info()[0] print sys.exc_info()[1] print ERROR IN HERE return for i in xrange(20) : try: name = 'THREAD' + str(i)except: thread.start_new(test, (name,)) #(1) except: print 'An Exception Ocurred' print sys.exc_info()[0] print sys.exc_info()[1] But when i run this code, The code works fine the first 5 times. the rest, all i get is this: SIZE: 20 Thread: THREAD0 -- seen.DBManager object at 0x403ca7ec ID: 0 SIZE: 19 Unhandled exception in thread started by Error in sys.excepthook: Original exception was: Unhandled exception in thread started by Error in sys.excepthook: Original exception was: Unhandled exception in thread started by Error in sys.excepthook: Original exception was: Unhandled exception in thread started by Error in sys.excepthook: Original exception was: And if put a time.sleep(1) after the thread.start_new(test, (name,)) #(1) part, then it does it all perfectly. I dont know what is causing the problem, maybe the threads are spawning too fast? OS issues?? python issues?? Im running Gentoo GNU/Linux and Python2.4 Thanks in advance, Jesús Rivero - (Neurogeek) -- http://mail.python.org/mailman/listinfo/python-list
Re: Where does Python look for libraries?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Python has sys.path If you want to add dirs into your PYTHONPATH add them to sys.path Jesus Rivero - (Neurogeek) ACB wrote: I have been trying to get the gdmodule installed and have run into an issue. When I import gd I get the following error. import gd Traceback (most recent call last): File stdin, line 1, in ? File /usr/local/lib/python2.3/site-packages/gd.py, line 10, in ? import _gd ImportError: /usr/local/lib/libgd.so.2: Undefined symbol libiconv_open But, when I run nm libiconv.so in the directory with the iconv library I get an entry like this 00011fe0 T libiconv_open so I know the functionality is there. So, my question. Does python have a way to add search directories for locating libraries? Thanks. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFEKFHNdIssYB9vBoMRAli3AJ9dFHXpXnrKCWiiSZZhuedKvZnQXgCeLeQF QbRIUt2RC//D+RMrWFsg8lY= =S8Ke -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: pydoc does not like this file
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 hmmm guess -w should be after python and not after pydoc: python -w c:\python24\Lib\pydoc.py .\setup.py And i also guess you are missing a command after setup.py (if you are using py2exe, that must be the command you are looking for.) so try this: $ python -w c:\python24\Lib\pydoc.py .\setup.py py2exe Best Regards, Jesús Rivero - (Neurogeek) Joram Agten wrote: Hello please put me in CC I'm trying pydoc as documentation for my projects but I have the following problem when runnig pydoc on my whole project there is also a file setup.py (from py2exe) but pydoc gives me the following for that file: [D:\programming\trunk\tecap\joag\checkvalue]python c:\python24\Lib\pydoc.py -w .\setup.py problem in .\setup.py - SystemExit: usage: pydoc.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: pydoc.py --help [cmd1 cmd2 ...] or: pydoc.py --help-commands or: pydoc.py cmd --help error: option -w not recognized there are no statements or functions in that file, and also no documentation anybody has any idea? joram -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFEIu09dIssYB9vBoMRAmfOAJ4h9mb5PgD/ZTWdh1VDu6GMvAb5DgCfTpPz 4UgOQcwkH6VhPQpjZI15nW0= =W2ZS -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: nested for loops
It is, but range(2,2) doesn't do anything Jesus Rivero - Neurogeek John Salerno wrote: Can someone tell me why 'n' in this example isn't 2? for n in range(2, 10): for x in range(2, n): print 'x =', x, 'n =', n x = 2 n = 3 -- http://mail.python.org/mailman/listinfo/python-list
Re: html parser , unexpected '' char in declaration
Oopss! You are totally right guys, i did miss the closing '' thinking about maybe errors in the use of ' or . Jesus Tim Roberts wrote: Jesus Rivero - (Neurogeek) [EMAIL PROTECTED] wrote: hmmm, that's kind of different issue then. I can guess, from the error you pasted earlier, that the problem shown is due to the fact Python is interpreting a as an expression and not as a char. review your code or try to figure out the exact input you're receving within the mta. Well, Jesus, you are 0 for 2. Sakcee pointed out what the exact problem was in his original message. The HTML he is being given is ill-formed; the !DOCTYPE directive is not closed. The SGML parser finds a html tag which it thinks is inside the !DOCTYPE, and that's illegal. well probabbly I should explain more. this is part of an email . after the mta delivers the email, it is stored in a local dir. After that the email is being parsed by the parser inside an web based imap client at display time. I dont think I have the choice of rewriting the message!? and I dont want to reject the message alltogether. I can either 1-fix the incoming html by tidying it up or 2- strip only plain text out and dispaly that you have spam, 3 - or ignore that mal-formatted tag and display the rest If this is happening with more than one message, you could check for it rather easily with a regular expression, or even just ''.find, and then either insert a closing '' or delete everything up to the html before parsing it. -- http://mail.python.org/mailman/listinfo/python-list
Re: algorithm, optimization, or other problem?
Hello, If the parameters that are received by functions in order to calculate weights, th's and dot's products , are equal to each other in different cycles (and i bet more than often they will) i suggest you replace those functions with memoizable functions. That also would ease work inside the loop. Take into account other suggestions people have made and review memoization in Python. Regards. Jesus (Neurogeek) Bas wrote: Hi, as the others have already said, move all the invariants out of the loop. It is also not useful to randomly draw a vector out of random array. Some other small things: for i in range(len(x)): do something with x[i] should probably be replaced by for xi in x: do something with xi this saves an array index operation, don't know if this works for a numeric array You use the y**2 twice. A good compiler might notice this, but Python is interpreted... use += instead of + for w, the calculation can be done in place, this might save the creation of a new array/variable I am not sure what you are doing with x, bit it seems that you are transposing it a few times to many. Mightbe you can declare x as the transpose of what you do now, thereby saving the transpose in the loop? so my guess (not tested): x=random((1000,100))# 1000 input vectors, declared differently for xx in x: y=dot(xx,w) y2 = y*y w+=ETA*(y*xx-y2*w); th+= INV_TAU*(y2-th); Hope it helps, Bas -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] (-1)**(1/2)==1?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello! it's Ok. Python gets from 1/2 0 as 0 is the integer part of that division. So, Python is interpreting -1**0 so you get 1 as answer. you should try this (-1)**(1.0/2.0) so 1.0/2.0 is an operation returning 0.5 completely. and you'll get: (-1)**(1.0/2.0) Traceback (most recent call last): File stdin, line 1, in ? ValueError: negative number cannot be raised to a fractional power Regards, Jesús (Neurogeek) Jonathan Barbero wrote: Hello! My name is Jonathan, i´m new with Python. I try this in the command line: (-1)**(1/2) 1 This is wrong, i think it must throw an exception. What do you think? Bye. Jonathan. ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/jrivero%40python.org.ve -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD+eA4dIssYB9vBoMRAuZXAJ4/hc6FrApyDxFScsv8w1kjc+Yi8QCfWzdb Izl2OQUE3iPVeqBnvjErrHA= =y5uC -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: how to break a for loop?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello Gregory! I would also use lists to implement this. They are more practical and you could take advantage of pop() or remove() methods instead of using the Oh-so-Scary del. You could also use a lambda+map or reduce methods to remove all zeros or just do something like this: list_ = [0,0,0,1,0,0,1] print [ elm for elm in list_ if elm != 0 ] [1,1] Regards, Jesus (Neurogeek) Gregory Petrosyan wrote: Hello! It's 1:56 o'clock in St.-Petersburg now, and I am still coding... maybe that's why I encountered stupid problem: I need to remove zeros from the begining of list, but I can't :-(. I use for i,coef in enumerate(coefs): if coef == 0: del coefs[i] else: break but it removes ALL zeros from list. What's up? P.S. I feel SO stupid asking this quastion... ;-) -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD+mVpdIssYB9vBoMRAl4hAJ9RnvgvEo5NsutG9KmD6qOEL7VyFgCfeLit h7FLsbRvHR1z5DSxSPZHFlY= =SY2U -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: html parser , unexpected '' char in declaration
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Sakcee wrote: html = 'html!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN head/head body bgcolor=#ff\r\n Foo foo , blah blah /body/html' html = !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN html head /head body bgcolor=#ff Foo foo , blah blah /body /html Try checking your html code. It looks really messy. ' char is not for multiple line strings. You can try the code above. As a suggestion, you should really focus on learning html basics ;) Regards Jesus (Neurogeek) import htmllib import formatter parser=htmllib.HTMLParser(formatter.NullFormatter()) parser.feed(html) Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.4/sgmllib.py, line 95, in feed self.goahead(0) File /usr/lib/python2.4/sgmllib.py, line 165, in goahead k = self.parse_declaration(i) File /usr/lib/python2.4/markupbase.py, line 132, in parse_declaration self.error( File /usr/lib/python2.4/htmllib.py, line 40, in error raise HTMLParseError(message) htmllib.HTMLParseError: unexpected '' char in declaration the error is generated by unclosed DOCTYPE declaration what is the best way to handle this kind of document. should I use regex to check and strip, or does HTMLParser offers something? , can i override default sgmllib behaviour I have to work with this htmllib because of existing modules . thanks -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD+mZzdIssYB9vBoMRAoWXAJ9KuAnLLXhZVv4t6fDBpu3RW6oxFgCeM/1S iNScofTDdJxLfOkaAR9Ejws= =+LTo -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: html parser , unexpected '' char in declaration
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 hmmm, that's kind of different issue then. I can guess, from the error you pasted earlier, that the problem shown is due to the fact Python is interpreting a as an expression and not as a char. review your code or try to figure out the exact input you're receving within the mta. Regards, Jesus (Neurogeek) Sakcee wrote: thanks for the reply well probabbly I should explain more. this is part of an email . after the mta delivers the email, it is stored in a local dir. After that the email is being parsed by the parser inside an web based imap client at display time. I dont think I have the choice of rewriting the message!? and I dont want to reject the message alltogether. I can either 1-fix the incoming html by tidying it up or 2- strip only plain text out and dispaly that you have spam, 3 - or ignore that mal-formatted tag and display the rest -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD+n5gdIssYB9vBoMRAvIHAJ9H+IQWtaEMa9FBYFvDAQXcIO2SRwCfX3yj BEvNJ6yWht1b+dBc6ohkwYI= =X1JL -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list