genetic algorithms package for python ?
Hi all, I am looking for a genetic algorithms package for Python. I have googled the web before posting and found some links. The link of pygene(http://www.freenet.org.nz/python/pygene) cannot be opened. I also tried the recipe on ASPN, but it is too simple for my application, and the ga model in SciPy, which is in testing in the sandbox. Are there any more genetic algorithms packages for Python ? Thanks a lot! xiaojf -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I do this with python ?
Tim N. van der Leeuw wrote: Your question is insufficiently clear for me to answer. Do you want to know how to read from standard-input in a Python program? Do you want to know how to start an external program from Python, and then connect something to that programs standard input? Do you want to know something else? Please specify! Cheers, --Tim Thanks. For example, I can call vim and do something like this in a shell script, #!/bin/sh vim a.file-EOF :some_vim_command :some_vim_command :w :q EOF I want to know how to call vim and to the same thing with python. Regrads, -- http://mail.python.org/mailman/listinfo/python-list
How can I do this with python ?
Dear all, In a shell script, I can run a command which need interactive input like this, #!/bin/sh A_Command-EOF a b c EOF But, how can I do this with python ? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
The difference between import package.module and from package import module(about pymol)
Hello, In pymol I can use from chempy import Atom but import chempy.Atom doesn't work. It says,ImportError: No module named Atom. What is going wrong ? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Has this problem been fiexed ?
Hello, I'm trying to build python2.4.2 on IRIX6.5(cc version MIPSpro Compilers: Version 7.3.1.3m). But the socket module failed to compile. I found this in ./Modules/socketmodule.c, line 193: /* XXX Using _SGIAPI is the wrong thing, 194 but I don't know what the right thing is. */ 195 #undef _SGIAPI /* to avoid warning */ 196 #define _SGIAPI 1 I think maybe somebody have already fixed this problem. Or any hints on how to compile socket module on IRIX? Thanks very much. Regards, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
python2.4.2 test_fpformat and test_locale failed on IRIX6.5
Hello, I am trying to install python2.4.2 on IRIX6.5, but test_fpformat and test_locale failed when I ran smake test. The following is the detailed error message: prompt:\ ./python ./Lib/test/test_fpformat.py test_basic_cases (__main__.FpformatTest) ... ok test_failing_values (__main__.FpformatTest) ... ok test_reasonable_values (__main__.FpformatTest) ... FAIL == FAIL: test_reasonable_values (__main__.FpformatTest) -- Traceback (most recent call last): File ./Lib/test/test_fpformat.py, line 51, in test_reasonable_values self.checkFix(realVal, d) File ./Lib/test/test_fpformat.py, line 28, in checkFix self.assertEquals(result, expected) AssertionError: '-0' != '0' -- Ran 3 tests in 0.005s FAILED (failures=1) Traceback (most recent call last): File ./Lib/test/test_fpformat.py, line 75, in ? test_main() File ./Lib/test/test_fpformat.py, line 71, in test_main run_unittest(FpformatTest) File /user_data2/jfxiao/local/source/python/python-2.4.2/Python-2.4.2/Lib/test/test_support.py, line 290, in run_unittest run_suite(suite, testclass) File /user_data2/jfxiao/local/source/python/python-2.4.2/Python-2.4.2/Lib/test/test_support.py, line 275, in run_suite raise TestFailed(err) test.test_support.TestFailed: Traceback (most recent call last): File ./Lib/test/test_fpformat.py, line 51, in test_reasonable_values self.checkFix(realVal, d) File ./Lib/test/test_fpformat.py, line 28, in checkFix self.assertEquals(result, expected) AssertionError: '-0' != '0' prompt:\ ./python ./Lib/test/test_locale.py '%f' % 1024 =? '1,024.00' ... no '%f' % 1024 == '1024.00' != '1,024.00' '%f' % 102 =? '102.00' ... yes '%f' % -42 =? '-42.00' ... yes '%+f' % -42 =? '-42.00' ... yes '%20.f' % -42 =? ' -42' ... yes '%+10.f' % -4200 =? ' -4,200' ... no '%+10.f' % -4200 == ' -4200' != ' -4,200' '%-10.f' % 4200 =? '4,200 ' ... no '%-10.f' % 4200 == '4200 ' != '4,200 ' Can someone tell me how to fix this ? Thanks in advance. Regrads, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
Steve Holden wrote: Xiao Jianfeng wrote: Steven D'Aprano wrote: On Sun, 20 Nov 2005 11:05:53 +0800, Xiao Jianfeng wrote: I have some other questions: when fh will be closed? When all references to the file are no longer in scope: def handle_file(name): fp = file(name, r) # reference to file now in scope do_stuff(fp) return fp f = handle_file(myfile.txt) # reference to file is now in scope f = None # reference to file is no longer in scope At this point, Python *may* close the file. CPython currently closes the file as soon as all references are out of scope. JPython does not -- it will close the file eventually, but you can't guarantee when. And what shoud I do if I want to explicitly close the file immediately after reading all data I want? That is the best practice. f.close() Let me introduce my problem I came across last night first. I need to read a file(which may be small or very big) and to check line by line to find a specific token, then the data on the next line will be what I want. If I use readlines(), it will be a problem when the file is too big. If I use for line in OPENED_FILE: to read one line each time, how can I get the next line when I find the specific token? And I think reading one line each time is less efficient, am I right? Not necessarily. Try this: f = file(filename.txt) for line in f: if token in line: # or whatever you need to identify it break else: sys.exit(File does not contain token) line = f.next() Then line will be the one you want. Since this will use code written in C to do the processing you will probably be pleasantly surprised by its speed. Only if this isn't fast enough should you consider anything more complicated. Premature optimizations can waste huge amounts of unnecessary programming time. Don't do it. First try measuring a solution that works! Oh yes, thanks. regards Steve First, I must say thanks to all of you. And I'm really sorry that I didn't describe my problem clearly. There are many tokens in the file, every time I find a token, I have to get the data on the next line and do some operation with it. It should be easy for me to find just one token using the above method, but there are more than one. My method was: f_in = open('input_file', 'r') data_all = f_in.readlines() f_in.close() for i in range(len(data_all)): line = data[i] if token in line: # do something with data[i + 1] Since my method needs to read all the file into memeory, I think it may be not efficient when processing very big file. I really appreciate all suggestions! Thanks again. Regrads, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
[EMAIL PROTECTED] wrote: Xiao Jianfeng wrote: First, I must say thanks to all of you. And I'm really sorry that I didn't describe my problem clearly. There are many tokens in the file, every time I find a token, I have to get the data on the next line and do some operation with it. It should be easy for me to find just one token using the above method, but there are more than one. My method was: f_in = open('input_file', 'r') data_all = f_in.readlines() f_in.close() for i in range(len(data_all)): line = data[i] if token in line: # do something with data[i + 1] Since my method needs to read all the file into memeory, I think it may be not efficient when processing very big file. I really appreciate all suggestions! Thanks again. something like this : for x in fh: if not has_token(x): continue else: process(fh.next()) you can also create an iterator by iter(fh), but I don't think that is necessary using the side effect to your advantage. I was bite before for the iterator's side effect but for your particular apps, it becomes an advantage. Thanks all of you! I have compared the two methods, (1). for x in fh: (2). read all the file into memory firstly. I have tested the two methods on two files, one is 80M and the second one is 815M. The first method gained a speedup of about 40% for the first file, and a speedup of about 25% for the second file. Sorry for my bad English, and I hope I haven't made people confused. Regards, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
[EMAIL PROTECTED] wrote: Xiao Jianfeng wrote: I have compared the two methods, (1). for x in fh: (2). read all the file into memory firstly. I have tested the two methods on two files, one is 80M and the second one is 815M. The first method gained a speedup of about 40% for the first file, and a speedup of about 25% for the second file. Sorry for my bad English, and I hope I haven't made people confused. So is the problem solved ? Yes, thank you. Putting buffering implementation aside, (1) is the way to go as it runs through content only once. I think so :-) Regards, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
How to install python2.4.2 on IRIX6.5 ?
Hello, I am trying to install python2.4.2 on a SGI origin3200 machine running IRIX6.5. The native c compiler was used to compile python. ./configure --prefix=/my/path/to/install runs ok, then, smake OPT= runs ok but smake test gets errors, here is the output: 247 tests OK. 2 tests failed: test_fpformat test_locale 41 tests skipped: test_aepack test_al test_applesingle test_bsddb test_bsddb185 test_bsddb3 test_bz2 test_cd test_cl test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp test_codecmaps_kr test_codecmaps_tw test_curses test_dl test_gdbm test_gl test_gzip test_imgfile test_ioctl test_linuxaudiodev test_macfs test_macostools test_nis test_normalization test_ossaudiodev test_pep277 test_plistlib test_scriptpackages test_socket_ssl test_socketserver test_sunaudiodev test_tcl test_timeout test_urllib2net test_urllibnet test_winreg test_winsound test_zipimport test_zlib Ask someone to teach regrtest.py about which tests are expected to get skipped on irix6. *** Error code 1 smake: Error: 1 error I also tried regrtest.py according the above instruction, origin3200% ./Lib/test/regrtest.py -s test_fpformat test_fpformat test test_fpformat failed -- Traceback (most recent call last): File /disk2/jfxiao/local/source/Python-2.4.2/Lib/test/test_fpformat.py, line 51, in test_reasonable_values self.checkFix(realVal, d) File /disk2/jfxiao/local/source/Python-2.4.2/Lib/test/test_fpformat.py, line 28, in checkFix self.assertEquals(result, expected) AssertionError: '-0' != '0' 1 test failed: test_fpformat origin3200% ./Lib/test/regrtest.py -s test_locale test_frozen 1 test OK. - Can somebody tell me what's the problem ? Thanks! Regards, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
[EMAIL PROTECTED] wrote: newer python should use for x in fh:, according to the doc : fh = open(your file) for x in fh: print x which would only read one line at a time. I have some other questions: when fh will be closed? And what shoud I do if I want to explicitly close the file immediately after reading all data I want? Ross Reyes wrote: HI - Sorry for maybe a too simple a question but I googled and also checked my reference O'Reilly Learning Python book and I did not find a satisfactory answer. When I use readlines, what happens if the number of lines is huge?I have a very big file (4GB) I want to read in, but I'm sure there must be some limitation to readlines and I'd like to know how it is handled by python. I am using it like this: slines = infile.readlines() # reads all lines into a list of strings called slines Thanks for anyone who knows the answer to this one. -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
Steven D'Aprano wrote: On Sun, 20 Nov 2005 11:05:53 +0800, Xiao Jianfeng wrote: I have some other questions: when fh will be closed? When all references to the file are no longer in scope: def handle_file(name): fp = file(name, r) # reference to file now in scope do_stuff(fp) return fp f = handle_file(myfile.txt) # reference to file is now in scope f = None # reference to file is no longer in scope At this point, Python *may* close the file. CPython currently closes the file as soon as all references are out of scope. JPython does not -- it will close the file eventually, but you can't guarantee when. And what shoud I do if I want to explicitly close the file immediately after reading all data I want? That is the best practice. f.close() Let me introduce my problem I came across last night first. I need to read a file(which may be small or very big) and to check line by line to find a specific token, then the data on the next line will be what I want. If I use readlines(), it will be a problem when the file is too big. If I use for line in OPENED_FILE: to read one line each time, how can I get the next line when I find the specific token? And I think reading one line each time is less efficient, am I right? Regards, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: add sys to __builtins__
Paul Watson wrote: This sounds pretty interesting. How about a switch to invoke this handling for the one-liner crowd and those who wish to use it? Somehow, I never heard any C programmers suggest that the default processing not include the need for: #include stdio.h I think it is because that we cannot modify the C language, but python is a language that's still evolving. -- http://mail.python.org/mailman/listinfo/python-list
Are there free molecular libraries written in python ?
Hi, Are there any free libraries for the analysis and manipulation of molecular structural models, implemented in the Python programming language ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list