Call for papers: SETP-10, USA, July 2010
It would be highly appreciated if you could share this announcement with your colleagues, students and individuals whose research is in software engineering, software testing, software quality assurance, software design and related areas. Call for papers: SETP-10, USA, July 2010 The 2010 International Conference on Software Engineering Theory and Practice (SETP-10) (website: http://www.PromoteResearch.org ) will be held during 12-14 of July 2010 in Orlando, FL, USA. SETP is an important event in the areas of Software development, maintenance, and other areas of software engineering and related topics. The conference will be held at the same time and location where several other major international conferences will be taking place. The conference will be held as part of 2010 multi-conference (MULTICONF-10). MULTICONF-10 will be held during July 12-14, 2010 in Orlando, Florida, USA. The primary goal of MULTICONF is to promote research and developmental activities in computer science, information technology, control engineering, and related fields. Another goal is to promote the dissemination of research to a multidisciplinary audience and to facilitate communication among researchers, developers, practitioners in different fields. The following conferences are planned to be organized as part of MULTICONF-10. • International Conference on Artificial Intelligence and Pattern Recognition (AIPR-10) •International Conference on Automation, Robotics and Control Systems (ARCS-10) • International Conference on Bioinformatics, Computational Biology, Genomics and Chemoinformatics (BCBGC-10) • International Conference on Computer Communications and Networks (CCN-10) • International Conference on Enterprise Information Systems and Web Technologies (EISWT-10) • International Conference on High Performance Computing Systems (HPCS-10) • International Conference on Information Security and Privacy (ISP-10) • International Conference on Image and Video Processing and Computer Vision (IVPCV-10) • International Conference on Software Engineering Theory and Practice (SETP-10) • International Conference on Theoretical and Mathematical Foundations of Computer Science (TMFCS-10) MULTICONF-10 will be held at Imperial Swan Hotel and Suites. It is a full-service resort that puts you in the middle of the fun! Located 1/2 block south of the famed International Drive, the hotel is just minutes from great entertainment like Walt Disney World® Resort, Universal Studios and Sea World Orlando. Guests can enjoy free scheduled transportation to these theme parks, as well as spacious accommodations, outdoor pools and on-site dining — all situated on 10 tropically landscaped acres. Here, guests can experience a full- service resort with discount hotel pricing in Orlando. We invite draft paper submissions. Please see the website http://www.PromoteResearch.org for more details. Sincerely James Heralds -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
notmm 0.3.4 Happy Lady
Hello, I'm glad to announce the release of notmm v0.3.4, the Python web framework for jobless perfectionists with deadlines! notmm is for those that are getting bored to ride ponies. Snake oil and batteries are of courses included. Documentation is still being a project of its own, though.. Below are the official release notes: notmm-0.3.4 (Happy Lady) In this release, many new improvements and issues have been fixed. - Generic and improved AuthKit support - Added a new Schevo authentication backend for use with AuthKit. - A Non-SQL, ORM construction kit based on Schevo in ``notmm.dbapi.schevo_orm``. - Session cookies management (SessionController) in requests/responses. middlewares. - Custom authentication and authorization support (LoginController). Changes from 0.2.12.2: - Helper apps (wsgiapp and wikiapp) have been refactored a lot. - Helper apps now have their own setup.py script (contrib/setup.py). - New ``RegexURLMap`` class in ``notmm.controllers.routing``. - Backward incompatible with Django 1.0.2. Please update to Django 1.1 or later. - Minor bug fixes and enhancements. Download location 1 (pypi): http://pypi.python.org/pypi/notmm/0.3.4/ Download location 2 (main site): http://gthc.org/distfiles/notmm/notmm-0.3.4.tar.gz Homepage: https://gthc.org/projects/notmm/ Enjoy this release! :) Etienne -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Conditional based on whether or not a module is being used
On Mar 7, 12:34 pm, Steve Holden st...@holdenweb.com wrote: My own impression of theloggingmodule, formed from trying to use its documentation in the past, is that it's somewhat unapproachable, and difficult to use for simple purposes. I am happy to say that now I see the current (3.1) documentation it has improved to the point where I would be happy to try using it again. Thanks for your long-term maintenance of this package. Hi Steve, Thanks for the positive feedback. The initial documentation for the logging package, because it lives in the library section of the overall documentation, was focused more on completeness of coverage for reference usage, rather than a more tutorial-based approach. Thanks to work by Doug Hellmann and others, the documentation has grown, over time, more accessible to Python novices. It's still not perfect, and I hope to be able to improve its clarity in the future, by getting help where possible from people who are better at technical writing than I am. I'm reviewing the documentation at the moment, as it happens, and it still seems hard to be able to put together a structure which is good for everyone. A full treatment, it seems to me, would talk a little about the detail of why things work as they do; but a lot of the time, people are just interested in getting going with the package, and less interested in the whys and wherefores. But for people trying to do more than the basics, that deeper understanding is sometimes necessary. The hard part is satisfying all audiences in one document! Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
pyserial script doesnt execute properly
hello there Iam using python 2.5.4 pyserial 2.4 pywin32-214 on windows 7 i hav a small test script written to query a serial device (arduino) and get back reply appropriately file: test.py import serial print 'hi' ser=serial.Serial(port='\\.\COM2', baudrate=9600) ser.close() ser.open() ser.write('1') ser.readline() ser.readline() ser.close() the device waits for '1' through its serial interface and print two lines if it gets '1' Some Data found and Header received the script works on IDLE well when given one line at a time but when given in command line as python test.py it prints hi and wait forever can anyone help? thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: Conditional based on whether or not a module is being used
On Mar 6, 11:13 pm, Pete Emerson pemer...@gmail.com wrote: 1) In debug mode, send what would have gone to syslog to STDOUT or STDERR 2) In non-debug mode, use /dev/log or localhost:514 depending on what is set 3) Allow for multiple levels ofloggingbeyond INFO, WARNING, CRIT ... essentially allow multiple levels of INFO depending on how much detail is desired. A high level of messaging when programs are running poorly is desired, but when programs are running smoothly, I don't need to send as much to syslog. By debug mode, do you mean the value of the __debug__ variable, or something else (e.g. a flag in your application)? You could certainly do something like (in your logging initialization code): if __debug__: handler = logging.StreamHandler() else: #use domain socket, UDP, etc. handler = logging.handlers.SocketHandler(...) logger.addHandler(handler) where logger is the root logger or some other high-level logger in your application. By the way, are you aware that accessing syslog via openlog etc. may not thread-safe, at least in some environments? Search the Web for syslog openlog thread for more info. You can certainly add additional levels to logging (see addLevelName), but I'm not sure that's what you really need. Generally, I find that when there are problems to be debugged, I get more benefits from using the logger hierarchy: I keep the level at logging.DEBUG but just log different things to different loggers. Just as a fr'instance, if I were logging the parsing of HTTP requests, I might use loggers named 'request', 'request.headers', 'request.headers.cookies', 'request.body', 'request.body.multipart' etc. When everything is working well, I have the verbosity of these loggers turned low by e.g. setting the level for the 'request' logger to WARNING or higher; when I want to debug header processing in more detail I might set the level of the 'request.headers' logger to DEBUG, which would output events from request header processing (but not the body), or just turn up the 'request.headers.cookies' level to look in more detail at what's happening during processing Cookie: headers. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ?
Hi, Today, I've show this static web site generating tools write in ruby : * http://webgen.rubyforge.org/index.html * http://nanoc.stoneship.org/about/ * http://webby.rubyforge.org/tutorial/ I like this tools, I'm wonder if there are similar tools in Python ? I know Sphinx, but this tools is oriented documentation. Thanks for your information, Stephane -- Stéphane Klein steph...@harobed.org Blog : http://harobed.org Jabber : stephane.kl...@jabber.fr -- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial script doesnt execute properly
Hi, kishore wrote: hello there Iam using python 2.5.4 pyserial 2.4 pywin32-214 on windows 7 i hav a small test script written to query a serial device (arduino) and get back reply appropriately file: test.py import serial print 'hi' ser=serial.Serial(port='\\.\COM2', baudrate=9600) ser.close() ser.open() ser.write('1') ser.readline() ser.readline() ser.close() the device waits for '1' through its serial interface and print two lines if it gets '1' Some Data found and Header received the script works on IDLE well when given one line at a time but when given in command line as python test.py it prints hi and wait forever Unfortunately I don't remember exacty, but try following: close IDLE and try then to start the script from the command line. I remember having had a problem with idle, that it did not always close the UART port (especially, when an error (e.g. syntax) occured before the close statement) bye N -- http://mail.python.org/mailman/listinfo/python-list
Re: remove element with ElementTree
On Mar 9, 11:35 am, tdan df.tr...@gmail.com wrote: I have been using ElementTree to write an app, and would like to simply remove an element. But in ElementTree, you must know both the parent and the child element to do this. There is no getparent() function, so I am stuck if I only have an element. see http://effbot.org/zone/element.htm#accessing-parents -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ?
On Mar 9, 8:57 am, KLEIN Stéphane steph...@harobed.org wrote: Hi, Today, I've show this static web site generating tools write in ruby : *http://webgen.rubyforge.org/index.html *http://nanoc.stoneship.org/about/ *http://webby.rubyforge.org/tutorial/ I like this tools, I'm wonder if there are similar tools in Python ? I know Sphinx, but this tools is oriented documentation. Thanks for your information, Stephane I'm only aware of Hyde (http://ringce.com/hyde) Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Duplicate keys in dict?
On Mar 7, 6:23 pm, vsoler vicente.so...@gmail.com wrote: Hello, My code snippet reads data from excel ranges. First row and first column are column headers and row headers respectively. After reding the range I build a dict. What is the best approach for this problem? Can anybody help? Have you tried xlread ? (http://www.python-excel.org/) Best, -- Yinon -- http://mail.python.org/mailman/listinfo/python-list
Re: related lists mean value (golfed)
Am 09.03.2010 13:02, schrieb Peter Otten: [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Peter ... pwned. Should be the fastest and shortest way to do it. I tried to do something like this, but my brain hurt while trying to visualize list comprehension evaluation orders ;) Regards, Michael -- http://mail.python.org/mailman/listinfo/python-list
Opportunity to author Python books- Packt Publishing.
Hi All, I am writing to you for Packt Publishing, the publishers computer related books. We are planning to extend our catalogue of cookbooks and are currently inviting Python fanatics interested in writing a cookbook. So, if you love Python and are interested in writing a cookbook, please contact us with your book ideas at aut...@packtpub.com. Even if you do not have a book idea and are simply interested in authoring a cookbook, we are keen to hear from you. More details about the opportunity are available at: http://authors.packtpub.com/content/python-fanatics-invited-write-packt Thanks Kshipra Singh Author Relationship Manager Packt Publishing www.PacktPub.com Skype: kshiprasingh15 Twitter: http://twitter.com/kshipras Interested in becoming an author? Visit http://authors.packtpub.com for all the information you need about writing for Packt. -- http://mail.python.org/mailman/listinfo/python-list
a newbie's question
Hi all, I'm a newbie of python programming language. I have used c/c++ for 5 years, and one year experience in Lua programming language. Can any one give me some advice on learning python. Think you for any help!! best regards!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: (updated) Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime
We've decided to build a re-usable *general purpose* PY2EXE runtime that can be shared by a number of scripts vs. distributing a monolithic EXE for each of our scripts. A list of the Python 2.6.4 compatible modules/packages we decided to include (and exclude) in our runtime follows my signature. Any suggestions on additions or deletions appreciated. Thanks, Malcolm 3rd party modules/packages: - jsonpickle - wmi --- forgot this one in my original post - win32api - winshell We've included all modules from the Python standard library EXCEPT the following: http://www.python.org/doc/2.6.4/modindex.html - aifc - audioop - bsddb - Carbon - dbhash - distutils - dumbdbm - netrc - plistlib - robotparser - ScrolledText - shelve - sunau - tabnanny - Tix - Tkinter - turtle - whichdb -- http://mail.python.org/mailman/listinfo/python-list
Re: Opportunity to author Python books- Packt Publishing.
On Mar 8, 2010, at 6:25 AM, Kshipra Singh wrote: I would be delighted to write a cookbook on the stuff I use every day: python for administering cloud servers. Thanks, S aka/Steve Steiner aka/ssteinerX Hi All, I am writing to you for Packt Publishing, the publishers computer related books. We are planning to extend our catalogue of cookbooks and are currently inviting Python fanatics interested in writing a cookbook. So, if you love Python and are interested in writing a cookbook, please contact us with your book ideas ataut...@packtpub.com. Even if you do not have a book idea and are simply interested in authoring a cookbook, we are keen to hear from you. More details about the opportunity are available at: http://authors.packtpub.com/content/python-fanatics-invited-write-packt Thanks Kshipra Singh Author Relationship Manager Packt Publishing www.PacktPub.com Skype: kshiprasingh15 Twitter: http://twitter.com/kshipras Interested in becoming an author? Visit http://authors.packtpub.com for all the information you need about writing for Packt. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Calculating very large exponents in python
On Mar 8, 10:39 pm, casevh cas...@gmail.com wrote: [also replying to Geremy since the OP's message doesn't appear...] On Mar 8, 11:05 am, geremy condra debat...@gmail.com wrote: On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad miracles...@hotmail.com wrote: Thanks Geremy, That has been an absolute bump... GOD i cant sit on my chair, it has worked even on 512 bit number and with no time.. superb i would say. lastly, i am using the code below to calculate Largest Prime factor of a number: print ('''===''' ''' CALCULATE HIGHEST PRIME FACTOR ''' '''===''') #!/usr/bin/env python def highest_prime_factor(n): if isprime(n): return n for x in xrange(2,n ** 0.5 + 1): if not n % x: return highest_prime_factor(n/x) def isprime(n): for x in xrange(2,n ** 0.5 + 1): if not n % x: return False return True if __name__ == __main__: import time start = time.time() print highest_prime_factor(1238162376372637826) print time.time() - start the code works with a bit of delay on the number : 1238162376372637826 but extending it to (109026109913291424366305511581086089650628117463925776754560048454991130443047109026109913291424366305511581086089650628117463925776754560048454991130443047) makes python go crazy. Is there any way just like above, i can have it calculated it in no time. thanks for the support. If you're just looking for the largest prime factor I would suggest using a fermat factorization attack. In the example you gave, it returns nearly immediately. Geremy Condra- Hide quoted text - - Show quoted text - For a Python-based solution, you might want to look at pyecm (http:// sourceforge.net/projects/pyecm/) On a system with gmpy installed also, pyecm found the following factors: 101, 521, 3121, 9901, 36479, 300623, 53397071018461, 1900381976777332243781 There still is a 98 digit unfactored composite: 60252507174568243758911151187828438446814447653986842279796823262165159406500174226172705680274911 Factoring this remaining composite using ECM may not be practical. casevh- Hide quoted text - - Show quoted text - After a few hours, the remaining factors are 6060517860310398033985611921721 and 9941808367425935774306988776021629111399536914790551022447994642391 casevh -- http://mail.python.org/mailman/listinfo/python-list
Re: imported var not being updated
John Posner a écrit : On 3/8/2010 11:55 PM, Gary Herron wrote: snip The form of import you are using from helpers import mostRecent makes a *new* binding to the value in the module that's doing the import. snip What you can do, is not make a separate binding, but reach into the helpers module to get the value there. Like this: import helpers print helpers.mostRecent Gary, are you asserting that in these separate situations: one.py: from helpers import mostRecent x = mostRecent two.py: import helpers x = helpers.mostRecent ... the name x will be bound to different objects? Nope. What he's saying is that one.x and two.x are two different names - each living in it's own namespace - that happen to be bound to the same object. Now rebiding one.x to a different object will _of course_ have no impact on the object two.x is bound to. That's exactly the same as: one = dict() two = dict() # one['x'] and two['x'] refer to the same object one['x'] = two['x'] = [foo, bar] print one['x'], two['x'], one['x'] is two['x'] # mutating one['x'], visible in two['x'] # (of course since it's the same object) one['x'].append(baaz) print one['x'], two['x'], one['x'] is two['x'] # now rebind one['x'] one['x'] = 42 # obvious result: one['x'] and two['x'] now refer to 2 different objects print one['x'], two['x'], one['x'] is two['x'] If in doubt about namespaces, think dicts. Namespaces are like dicts - and are often nothing else that a plain old dict FWIW. HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: imported var not being updated
On 3/8/2010 11:55 PM, Gary Herron wrote: snip The form of import you are using from helpers import mostRecent makes a *new* binding to the value in the module that's doing the import. snip What you can do, is not make a separate binding, but reach into the helpers module to get the value there. Like this: import helpers print helpers.mostRecent Gary, are you asserting that in these separate situations: one.py: from helpers import mostRecent x = mostRecent two.py: import helpers x = helpers.mostRecent ... the name x will be bound to different objects? Tx, John -- http://mail.python.org/mailman/listinfo/python-list
Re: NoSQL Movement?
mk a écrit : Bruno Desthuilliers wrote: Well, Zope is backed by an object database rather than a relational one. And it ended up being a *major* PITA on all Zope projects I've worked on... Care to write a few sentences on nature of problems with zodb? I was flirting with the thought of using it on some project. Would require more than a few sentences. But mostly, it's about the very nature of the Zodb : it's a giant graph of Python objects. So : 1/ your data are _very_ tightly dependant on the language and applicative code 2/ you have to hand-write each and every graph traversal 3/ accessing a given object usually loads quite a few others in memory I once thought the Zodb was cool. -- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial script doesnt execute properly
On Mar 9, 2:19 pm, News123 news...@free.fr wrote: Hi, kishore wrote: hello there Iam using python 2.5.4 pyserial 2.4 pywin32-214 on windows 7 i hav a small test script written to query a serial device (arduino) and get back reply appropriately file: test.py import serial print 'hi' ser=serial.Serial(port='\\.\COM2', baudrate=9600) ser.close() ser.open() ser.write('1') ser.readline() ser.readline() ser.close() the device waits for '1' through its serial interface and print two lines if it gets '1' Some Data found and Header received the script works on IDLE well when given one line at a time but when given in command line as python test.py it prints hi and wait forever Unfortunately I don't remember exacty, but try following: close IDLE and try then to start the script from the command line. I remember having had a problem with idle, that it did not always close the UART port (especially, when an error (e.g. syntax) occured before the close statement) bye N Thanks for your response i tried closing idle and the following code prints port opened Write failed code: import serial import time ser=serial.Serial(port='\\.\COM2', baudrate=9600) if ser: print 'port opened' ser.open() if ser.write('1'): print 'Write success' else: print 'write failed' time.sleep(1) a=ser.readline() time.sleep(1) b=ser.readline() print b ser.close() I believe this might be a serial port access error. how to solve this? Any suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial script doesnt execute properly
On Mar 9, 8:01 pm, kishore kishorei...@gmail.com wrote: On Mar 9, 2:19 pm, News123 news...@free.fr wrote: Hi, kishore wrote: hello there Iam using python 2.5.4 pyserial 2.4 pywin32-214 on windows 7 i hav a small test script written to query a serial device (arduino) and get back reply appropriately file: test.py import serial print 'hi' ser=serial.Serial(port='\\.\COM2', baudrate=9600) ser.close() ser.open() ser.write('1') ser.readline() ser.readline() ser.close() the device waits for '1' through its serial interface and print two lines if it gets '1' Some Data found and Header received the script works on IDLE well when given one line at a time but when given in command line as python test.py it prints hi and wait forever Unfortunately I don't remember exacty, but try following: close IDLE and try then to start the script from the command line. I remember having had a problem with idle, that it did not always close the UART port (especially, when an error (e.g. syntax) occured before the close statement) bye N Thanks for your response i tried closing idle and the following code prints port opened Write failed code: import serial import time ser=serial.Serial(port='\\.\COM2', baudrate=9600) if ser: print 'port opened' ser.open() if ser.write('1'): print 'Write success' else: print 'write failed' time.sleep(1) a=ser.readline() time.sleep(1) b=ser.readline() print b ser.close() I believe this might be a serial port access error. how to solve this? Any suggestions? have found one more person with same problem but no solution http://mail.python.org/pipermail/python-win32/2009-January/008613.html -- http://mail.python.org/mailman/listinfo/python-list
Re: imported var not being updated
On Tue, Mar 9, 2010 at 9:18 AM, John Posner jjpos...@optimum.net wrote: On 3/8/2010 11:55 PM, Gary Herron wrote: snip The form of import you are using from helpers import mostRecent makes a *new* binding to the value in the module that's doing the import. snip What you can do, is not make a separate binding, but reach into the helpers module to get the value there. Like this: import helpers print helpers.mostRecent Gary, are you asserting that in these separate situations: one.py: from helpers import mostRecent x = mostRecent two.py: import helpers x = helpers.mostRecent ... the name x will be bound to different objects? Tx, John No. the name x will be bound to the same object. It's the other way that gives a problem from helpers import mostRecent works like import helpers mostRecent = helpers.mostRecent del helpers so when you do mostRecent = x it rebinds mostRecent in the current scope but doesn't affect helpers.mostRecent, the name in the helpers module. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there in Python some static web site generating tools like?webgen, nanoc or webby in Ruby ?
KLEIN Stéphane steph...@harobed.org wrote: Hi, Today, I've show this static web site generating tools write in ruby : * http://webgen.rubyforge.org/index.html * http://nanoc.stoneship.org/about/ * http://webby.rubyforge.org/tutorial/ I like this tools, I'm wonder if there are similar tools in Python ? rst2web -- --- | Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__garabik @ kassiopeia.juls.savba.sk | --- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! -- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial script doesnt execute properly
On Mar 9, 8:01 pm, kishore kishorei...@gmail.com wrote: On Mar 9, 2:19 pm, News123 news...@free.fr wrote: Hi, kishore wrote: hello there Iam using python 2.5.4 pyserial 2.4 pywin32-214 on windows 7 i hav a small test script written to query a serial device (arduino) and get back reply appropriately file: test.py import serial print 'hi' ser=serial.Serial(port='\\.\COM2', baudrate=9600) ser.close() ser.open() ser.write('1') ser.readline() ser.readline() ser.close() the device waits for '1' through its serial interface and print two lines if it gets '1' Some Data found and Header received the script works on IDLE well when given one line at a time but when given in command line as python test.py it prints hi and wait forever Unfortunately I don't remember exacty, but try following: close IDLE and try then to start the script from the command line. I remember having had a problem with idle, that it did not always close the UART port (especially, when an error (e.g. syntax) occured before the close statement) bye N Thanks for your response i tried closing idle and the following code prints port opened Write failed code: import serial import time ser=serial.Serial(port='\\.\COM2', baudrate=9600) if ser: print 'port opened' ser.open() if ser.write('1'): print 'Write success' else: print 'write failed' time.sleep(1) a=ser.readline() time.sleep(1) b=ser.readline() print b ser.close() I believe this might be a serial port access error. how to solve this? Any suggestions? have found one more person with same problem but no solution http://mail.python.org/pipermail/python-win32/2009-January/008613.html -- http://mail.python.org/mailman/listinfo/python-list
Re: NoSQL Movement?
On Mar 8, 11:14 am, Duncan Booth duncan.bo...@invalid.invalid wrote: Xah Lee xah...@gmail.com wrote: For example, consider, if you are within world's top 100th user of database in terms of database size, such as Google, then it may be that the off-the-shelf tools may be limiting. But how many users really have such massive size of data? You've totally missed the point. It isn't the size of the data you have today that matters, it's the size of data you could have in several years' time. so, you saying, in several years, we'd all become the world's top 100 database users in terms of size, like Google? Xah ∑ http://xahlee.org/ ☄ -- http://mail.python.org/mailman/listinfo/python-list
Re: related lists mean value
Am 08.03.2010 23:34, schrieb dimitri pater - serpia: Hi, I have two related lists: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] what I need is a list representing the mean value of 'a', 'b' and 'c' while maintaining the number of items (len): w = [1.5, 1.5, 8, 4, 4, 4] This kinda looks like you used the wrong data structure. Maybe you should have used a dict, like: {'a': [1, 2], 'c': [5, 0, 7], 'b': [8]} ? I have looked at iter(tools) and next(), but that did not help me. I'm a bit stuck here, so your help is appreciated! As said, I'd have used a dict in the first place, so lets transform this straight forward into one: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] # initialize dict d={} for idx in set(y): d[idx]=[] #collect values for i, idx in enumerate(y): d[idx].append(x[i]) print(d is now a dict of lists: %s % d) #calculate average for key, values in d.items(): d[key]=sum(values)/len(values) print(d is now a dict of averages: %s % d) # build the final list w = [ d[key] for key in y ] print(w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n % (x, y, w)) Output is: d is now a dict of lists: {'a': [1, 2], 'c': [5, 0, 7], 'b': [8]} d is now a dict of averages: {'a': 1.5, 'c': 4.0, 'b': 8.0} w is now the list of averages, corresponding with y: x: [1, 2, 8, 5, 0, 7] y: ['a', 'a', 'b', 'c', 'c', 'c'] w: [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Could have used a defaultdict to avoid dict initialisation, though. Or write a custom class: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] class A: def __init__(self): self.store={} def add(self, key, number): if key in self.store: self.store[key].append(number) else: self.store[key] = [number] a=A() # collect data for idx, val in zip(y,x): a.add(idx, val) # build the final list: w = [ sum(a.store[key])/len(a.store[key]) for key in y ] print(w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n % (x, y, w)) Produces same output, of course. Note that those solutions are both not very efficient, but who cares ;) thanks! No Problem, Michael -- http://mail.python.org/mailman/listinfo/python-list
Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime
We've decided to build a re-usable *general purpose* PY2EXE runtime that can be shared by a number of scripts vs. distributing a monolithic EXE for each of our scripts. A list of the Python 2.6.4 compatible modules/packages we decided to include (and exclude) in our runtime follows my signature. Any suggestions on additions or deletions appreciated. Thanks, Malcolm 3rd party modules/packages: - jsonpickle - win32api - winshell We've included all modules from the Python standard library EXCEPT the following: http://www.python.org/doc/2.6.4/modindex.html - aifc - audioop - bsddb - Carbon - dbhash - distutils - dumbdbm - netrc - plistlib - robotparser - ScrolledText - shelve - sunau - tabnanny - Tix - Tkinter - turtle - whichdb -- http://mail.python.org/mailman/listinfo/python-list
Re: odd error
Alex Hall wrote: Now, though, when I press ctrl-shift-c (keystroke 11), nothing happens. Control-C sends a special signal to the console, like Control-Break. Pressing any other keystroke after that will crash the program with some sort of Python internal com server exception that I have never seen before. Neither do I, in particular since you don't share that rare gem with us. ;) Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
RE: How to detect C Function block using python
In the source code of PythoidC ( http://pythoidc.googlecode.com ), I wrote a Parser for C header files with Python regular expression, not only functions but also structs macros. May be of some help. Hey All, I'm new in this community. I am writing a static analyzer for validating C Code using python and for that I'm looking for a python module/API that will detect Function block of a given C-File. I know simple function can be detected using push { and poping it if character } is found. This solution is actually done already, I want a robust API that can do more then that like detecting Function name parameters its return types etc. Thanks! Faheem-- http://mail.python.org/mailman/listinfo/python-list
Re: a newbie's question
On 9 March 2010 13:51, Lan Qing efi...@gmail.com wrote: Hi all, I'm a newbie of python programming language. Welcome! I have used c/c++ for 5 years, and one year experience in Lua programming language. Can any one give me some advice on learning python. Think you for any help!! You'll find some useful starting points here - http://wiki.python.org/moin/BeginnersGuide/Programmers. -- Cheers, Simon B. -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ?
I'm only aware of Hyde (http://ringce.com/hyde) There are also jekyll and cyrax: http://github.com/mojombo/jekyll/ http://pypi.python.org/pypi/cyrax/0.1.5 I haven't tried any of them, but it looks like cyrax is in active development and its design was inspired in both jekyll and hyde. Best regards, Javier -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question: python versions differ per user?
On Mar 8, 8:15 pm, BobAalsma bob.aal...@aalsmacons.nl wrote: I'm on Mac OS X 10.5.8 and downloaded 2.6.4 Mac Installer Disk Image as/in(?) the sys admin user. For this user Pyhton 2.6.4 is now the current version. I want to use Python outside the sys asdmin user. However, all other users still use Python 2.5.1 (Apple delivered). The sys admin user looks in /Library/Frameworks/Python.framework/ Versions/2.6/lib/... The other users look in /System/Library/Frameworks/ Python.framework/Version/2.5/lib/... I could not find any questions on this matter, so am I the only one? Did I do something wrong? I assumed the paths for all users would be modified - too easy? OK, sorry, found out. -- http://mail.python.org/mailman/listinfo/python-list
Re: related lists mean value
On Mar 8, 6:39 pm, John Posner jjpos...@optimum.net wrote: On 3/8/2010 5:34 PM, dimitri pater - serpia wrote: Hi, I have two related lists: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] what I need is a list representing the mean value of 'a', 'b' and 'c' while maintaining the number of items (len): w = [1.5, 1.5, 8, 4, 4, 4] I have looked at iter(tools) and next(), but that did not help me. I'm a bit stuck here, so your help is appreciated! Nobody expects object-orientation (or the Spanish Inquisition): Heh. Yep, I avoided OO for this. Seems like a functional problem. My solution is functional on the outside, imperative on the inside. You could add recursion here, but I don't think it would be as straightforward. def num_dups_at_head(lst): assert len(lst) 0 val = lst[0] i = 1 while i len(lst) and lst[i] == val: i += 1 return i def smooth(x, y): result = [] while x: cnt = num_dups_at_head(y) avg = sum(x[:cnt]) * 1.0 / cnt result += [avg] * cnt x = x[cnt:] y = y[cnt:] return result #- from collections import defaultdict class Tally: def __init__(self, id=None): self.id = id self.total = 0 self.count = 0 x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c'] # gather data tally_dict = defaultdict(Tally) for i in range(len(x)): obj = tally_dict[y[i]] obj.id = y[i] obj.total += x[i] obj.count += 1 # process data result_list = [] for key in sorted(tally_dict): obj = tally_dict[key] mean = 1.0 * obj.total / obj.count result_list.extend([mean] * obj.count) print result_list #- -- http://mail.python.org/mailman/listinfo/python-list
Re: related lists mean value (golfed)
OK, I golfed it :D Go ahead and kill me ;) x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] def f(a,b,v={}): try: v[a].append(b) except: v[a]=[b] def g(a): return sum(v[a])/len(v[a]) return g w = [g(i) for g,i in [(f(i,v),i) for i,v in zip(y,x)]] print(w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n % (x, y, w)) Output: w is now the list of averages, corresponding with y: x: [1, 2, 8, 5, 0, 7] y: ['a', 'a', 'b', 'c', 'c', 'c'] w: [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Regards, Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: related lists mean value (golfed)
Michael Rudolf wrote: OK, I golfed it :D Go ahead and kill me ;) x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] def f(a,b,v={}): try: v[a].append(b) except: v[a]=[b] def g(a): return sum(v[a])/len(v[a]) return g w = [g(i) for g,i in [(f(i,v),i) for i,v in zip(y,x)]] print(w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n % (x, y, w)) Output: w is now the list of averages, corresponding with y: x: [1, 2, 8, 5, 0, 7] y: ['a', 'a', 'b', 'c', 'c', 'c'] w: [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: related lists mean value (golfed)
Michael Rudolf wrote: Am 09.03.2010 13:02, schrieb Peter Otten: [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Peter ... pwned. Should be the fastest and shortest way to do it. It may be short, but it is not particularly efficient. A dict-based approach is probably the fastest. If y is guaranteed to be sorted itertools.groupby() may also be worth a try. $ cat tmp_average_compare.py from __future__ import division from collections import defaultdict try: from itertools import izip as zip except ImportError: pass x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] def f(x=x, y=y): p = defaultdict(int) q = defaultdict(int) for a, b in zip(x, y): p[b] += a q[b] += 1 return [p[b]/q[b] for b in y] def g(x=x, y=y): return [sum(a for a,b in zip(x,y)if b==c)/y.count(c)for c in y] if __name__ == __main__: print(f()) print(g()) assert f() == g() $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'f()' 10 loops, best of 3: 11.4 usec per loop $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'g()' 1 loops, best of 3: 22.8 usec per loop Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: odd error
I know ctrl-c kills a process in the shell, but these are global hotkeys and all others work fine. You made me discover something, though: the error only happens if ctrl-shift-c is pressed when in the shell from where the program was run; when pressed anywhere else, the keystroke does nothing at all. Is there something I am missing about these keystroke dictionaries? It seems like they do not work unless the keycodes are in numerical order and are not separated by more than one number. Currently, my dictionary consists of the numbers 1-0 on the top of the keyboard, but adding any other keycode, like the 99 in my original message, will cause that keystroke to do absolutely nothing. Thanks to your response, I suspect the problem is something to do with the keypress being captured by the shell. Still, not being able to use anything except numbers is very annoying!! Why would this be happening? On 3/9/10, Ulrich Eckhardt eckha...@satorlaser.com wrote: Alex Hall wrote: Now, though, when I press ctrl-shift-c (keystroke 11), nothing happens. Control-C sends a special signal to the console, like Control-Break. Pressing any other keystroke after that will crash the program with some sort of Python internal com server exception that I have never seen before. Neither do I, in particular since you don't share that rare gem with us. ;) Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap -- http://mail.python.org/mailman/listinfo/python-list
Re: related lists mean value
On Mar 8, 2:34 pm, dimitri pater - serpia dimitri.pa...@gmail.com wrote: Hi, I have two related lists: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] what I need is a list representing the mean value of 'a', 'b' and 'c' while maintaining the number of items (len): w = [1.5, 1.5, 8, 4, 4, 4] What results are you expecting if you have multiple runs of 'a' in a longer list? -- http://mail.python.org/mailman/listinfo/python-list
Re: odd error
On 09/03/2010 13:55, Alex Hall wrote: Hi all, In the same program I wrote about yesterday, I have a dictionary of keystrokes which are captured. I just tried adding a new one, bringing the total to 11. Here are entries 10 and 11; 10 has been working fine for months. 10 : (57, win32con.MOD_CONTROL), 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) Now, though, when I press ctrl-shift-c (keystroke 11) Ctrl-C (with or without any other modifier) has a special meaning which overrides any hotkeys. You may be able to do something by adding a break handler through SetConsoleCtrlHandler (exposed in win32api). But it would obviously be a special case outside your normal control flow. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: imported var not being updated
John Posner wrote: On 3/8/2010 11:55 PM, Gary Herron wrote: snip The form of import you are using from helpers import mostRecent makes a *new* binding to the value in the module that's doing the import. snip What you can do, is not make a separate binding, but reach into the helpers module to get the value there. Like this: import helpers print helpers.mostRecent Gary, are you asserting that in these separate situations: one.py: from helpers import mostRecent x = mostRecent two.py: import helpers x = helpers.mostRecent ... the name x will be bound to different objects? Tx, John Hi John, No they are bound to the same object ... to start with. But if, as the OP indicated, something in the helpers module changes that module's binding of 'mostRecent', then the only helpers.mostRecent in your two.py will notice that change. The variable 'x' in both samples and the 'mostRecent' value in one.py will remain unchanged. That's true for mutable *and* immutable values -- however, mutable values admit a further consideration: Since all 'x's and 'mostRecent's refer to the same value, any mutation is noticed in all cases. But, *any* assignment ( with = or of the form *from helpers import mostRecent* ) breaks the reference to the shared value. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: odd error
On 09/03/2010 16:34, Tim Golden wrote: On 09/03/2010 13:55, Alex Hall wrote: Hi all, In the same program I wrote about yesterday, I have a dictionary of keystrokes which are captured. I just tried adding a new one, bringing the total to 11. Here are entries 10 and 11; 10 has been working fine for months. 10 : (57, win32con.MOD_CONTROL), 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) Now, though, when I press ctrl-shift-c (keystroke 11) Ctrl-C (with or without any other modifier) has a special meaning which overrides any hotkeys. You may be able to do something by adding a break handler through SetConsoleCtrlHandler (exposed in win32api). But it would obviously be a special case outside your normal control flow. ... or you could use SetConsoleMode to disable input processing. But that would only work (I think) in one console, not at a global level. TJG -- http://mail.python.org/mailman/listinfo/python-list
1794 - Best, Cheapest Web-Hosting, Domain at $1.99!
World's Cheapest Rate Hosting, 99.9% Uptime US Based Dedicated Server, Fast Customer Service Register Domain only at $1.99 per Year 3 Month Hosting Free with 1 year Package -- http://mail.python.org/mailman/listinfo/python-list
Re: related lists mean value
On Mar 9, 7:21 am, Steve Howell showel...@yahoo.com wrote: def num_dups_at_head(lst): assert len(lst) 0 val = lst[0] i = 1 while i len(lst) and lst[i] == val: i += 1 return i def smooth(x, y): result = [] while x: cnt = num_dups_at_head(y) avg = sum(x[:cnt]) * 1.0 / cnt result += [avg] * cnt x = x[cnt:] # expensive? y = y[cnt:] # expensive? return result BTW I recognize that my solution would be inefficient for long lists, unless the underlying list implementation had copy-on-write. I'm wondering what the easiest fix would be. I tried a quick shot at islice(), but the lack of len() thwarted me. -- http://mail.python.org/mailman/listinfo/python-list
Re: odd error
Okay, I changed the keycode from 99 (c) to 107 (k), and the errors have disappeared. However, now the function that should be called is not. As I said in a previous message, I have always had trouble with this sort of keystroke dictionary. It seems like, if a keycode is out of order or not one more than the number before it, the function to which it is tied will not get called. I am using the message looping mode from Tim Golden's website, and it works beautifully until I try to put an out-of-sequence keycode into the keystrokes dictionary. The dictionary contains numbers 0-9 (48-57) and all is well, but when I put in this 107 code then the function tied to 107 is not called, yet the ones tied to 48-57 still work normally. Why would the sequence matter, or does it not and I am doing something else wrong? Here is a sample of my dictionary: keys.append({ 1 : (48, win32con.MOD_CONTROL), 2 : (49, win32con.MOD_CONTROL), 3 : (50, win32con.MOD_CONTROL), 4 : (51, win32con.MOD_CONTROL), 5 : (52, win32con.MOD_CONTROL), 6 : (53, win32con.MOD_CONTROL), 7 : (54, win32con.MOD_CONTROL), 8 : (55, win32con.MOD_CONTROL), 9 : (56, win32con.MOD_CONTROL), 10 : (57, win32con.MOD_CONTROL), 11 : (107, win32con.MOD_CONTROL | win32con.MOD_SHIFT) #never calls its #function, and note that it is not in the sequence of the other ten }) and here is a list of functions tied to it: funcs.append({ 1 : exitProgram, 2 : arm.sayLoad1, 3 : arm.sayLoad2, 4 : arm.sayLoad3, 5 : arm.sayLoad4, 6 : arm.sayProcAvg, 7 : arm.sayUsedRam, 8 : arm.sayDisk1Info, 9 : arm.sayDisk2Info, 10 : nextMode, 11: clipboard.toClipboard }) If I were to tie clipboard.toClipboard to any of keys 1-10 (0-9, or 48-57) then it would work fine; it is when the 107 shows up that the function is not called, and this is a huge limitation for the rest of the program since I am stuck with just the ten numbers available on the keyboard. Any suggestions would be great! On 3/9/10, Tim Golden m...@timgolden.me.uk wrote: On 09/03/2010 13:55, Alex Hall wrote: Hi all, In the same program I wrote about yesterday, I have a dictionary of keystrokes which are captured. I just tried adding a new one, bringing the total to 11. Here are entries 10 and 11; 10 has been working fine for months. 10 : (57, win32con.MOD_CONTROL), 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) Now, though, when I press ctrl-shift-c (keystroke 11) Ctrl-C (with or without any other modifier) has a special meaning which overrides any hotkeys. You may be able to do something by adding a break handler through SetConsoleCtrlHandler (exposed in win32api). But it would obviously be a special case outside your normal control flow. TJG -- http://mail.python.org/mailman/listinfo/python-list -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap -- http://mail.python.org/mailman/listinfo/python-list
Re: imported var not being updated
On 3/9/2010 9:48 AM, Bruno Desthuilliers wrote: John Posner a écrit : On 3/8/2010 11:55 PM, Gary Herron wrote: snip The form of import you are using from helpers import mostRecent makes a *new* binding to the value in the module that's doing the import. snip What you can do, is not make a separate binding, but reach into the helpers module to get the value there. Like this: import helpers print helpers.mostRecent Gary, are you asserting that in these separate situations: one.py: from helpers import mostRecent x = mostRecent two.py: import helpers x = helpers.mostRecent ... the name x will be bound to different objects? Nope. What he's saying is that one.x and two.x are two different names - each living in it's own namespace - that happen to be bound to the same object. Now rebiding one.x to a different object will _of course_ have no impact on the object two.x is bound to. Sure -- my bad, Python 101. In this case, the module *helpers* is the equivalent of a container object, one of whose attributes *mostRecent* gets bound to a series of immutable string objects. That's exactly the same as: one = dict() two = dict() # one['x'] and two['x'] refer to the same object one['x'] = two['x'] = [foo, bar] print one['x'], two['x'], one['x'] is two['x'] # mutating one['x'], visible in two['x'] # (of course since it's the same object) one['x'].append(baaz) print one['x'], two['x'], one['x'] is two['x'] # now rebind one['x'] one['x'] = 42 # obvious result: one['x'] and two['x'] now refer to 2 different objects print one['x'], two['x'], one['x'] is two['x'] If in doubt about namespaces, think dicts. Namespaces are like dicts - and are often nothing else that a plain old dict FWIW. No doubts here, I hope. I even tend to see namespaces where, strictly speaking, they don't exist. As I said at the end of a recent (and flame-ridden) thread [1]: --- * A dict is a collection of user-devised names, each of which is assigned to an object. * A list/tuple is an interpreter-maintained collection of integer names (0, 1, 2, ...), each of which is assigned to an object. --- So in my world, in mylist[cnt+1], the expression *cnt+1* is equivalent to the integer name 4 (if cnt==3, that is), so that mylist[cnt+1] = obj.subobj.attr ... is just a NAME2 = NAME1 kind of assignment statement, binding an additional name to an object that already has a name. Tx, John [1] http://mail.python.org/pipermail/python-list/2010-February/1236318.html -- http://mail.python.org/mailman/listinfo/python-list
String is ASCII or UTF-8?
Hours of Googling has not helped me resolve a seemingly simple question - Given a string s, how can I tell whether it's ascii (and thus 1 byte per character) or UTF-8 (and two bytes per character)? This is python 2.4.3, so I don't have getsizeof available to me. -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
* C. Benson Manica: Hours of Googling has not helped me resolve a seemingly simple question - Given a string s, how can I tell whether it's ascii (and thus 1 byte per character) or UTF-8 (and two bytes per character)? This is python 2.4.3, so I don't have getsizeof available to me. Generally, if you need 100% certainty then you can't tell the encoding from a sequence of byte values. However, if you know that it's EITHER ascii or utf-8 then the presence of any value above 127 (or, for signed byte values, any negative values), tells you that it can't be ascii, hence, must be utf-8. And since utf-8 is an extension of ascii nothing is lost by assuming ascii in the other case. So, problem solved. If the string represents the contents of a file then you may also look for an UTF-8 represention of the Unicode BOM (Byte Order Mark) at the beginning. If found then it indicates utf-8 for almost-sure and more expensive searching can be avoided. It's just three bytes to check. Cheers hth., - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
On 09/03/2010 16:54, C. Benson Manica wrote: Hours of Googling has not helped me resolve a seemingly simple question - Given a string s, how can I tell whether it's ascii (and thus 1 byte per character) or UTF-8 (and two bytes per character)? This is python 2.4.3, so I don't have getsizeof available to me. You can't. You can apply one or more heuristics, depending on exactly what your requirement is. But any valid ASCII text is also valid UTF8-encoded text since UTF-8 isn't two bytes per char but a variable number of bytes per char. Obviously, you can test whether all the bytes are less than 128 which suggests that the text is legal ASCII. But then it's also legal UTF8. Or you can just attempt to decode and catch the exception: try: unicode (text, ascii) except UnicodeDecodeError: print Not ASCII TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
On 09-03-2010 18:02, Alf P. Steinbach wrote: * C. Benson Manica: Hours of Googling has not helped me resolve a seemingly simple question - Given a string s, how can I tell whether it's ascii (and thus 1 byte per character) or UTF-8 (and two bytes per character)? This is python 2.4.3, so I don't have getsizeof available to me. Generally, if you need 100% certainty then you can't tell the encoding from a sequence of byte values. However, if you know that it's EITHER ascii or utf-8 then the presence of any value above 127 (or, for signed byte values, any negative values), tells you that it can't be ascii, AFAIK it's completely impossible. UTF-8 characters have 1 to 4 bytes / byte. I can create ASCII strings containing byte values between 127 and 255. cheers, Stef hence, must be utf-8. And since utf-8 is an extension of ascii nothing is lost by assuming ascii in the other case. So, problem solved. If the string represents the contents of a file then you may also look for an UTF-8 represention of the Unicode BOM (Byte Order Mark) at the beginning. If found then it indicates utf-8 for almost-sure and more expensive searching can be avoided. It's just three bytes to check. Cheers hth., - Alf -- http://mail.python.org/mailman/listinfo/python-list
Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ?
Hi, Today, I've show this static web site generating tools writed in ruby : * http://webgen.rubyforge.org/index.html * http://nanoc.stoneship.org/about/ * http://webby.rubyforge.org/tutorial/ I like this tools, I'm wonder if there are similar tools in Python ? I know Sphinx, but this tools is oriented documentation. Thanks for your information, Stephane -- http://mail.python.org/mailman/listinfo/python-list
Re: What to do if anything bites.
News123 wrote: Google Adsense wrote: What to do if anything bites. Check our bites treatment at http://... Pythons don't bite First, if you have to respond to spam please omit the URL that the spammer is trying to bring to Google's attention as well as direct readers. Secondly, do you realise you are posting from an address that has been suspended due to inactivity? Otherwise you would have received this message privately. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: scipy sparse matrix question
On 2010-03-09 00:14 AM, Victor Eijkhout wrote: I can't find any detailed information about scipy.sparse. The place to ask would be on scipy-user: http://www.scipy.org/Mailing_Lists My specific question: what does for x in A give me when A is a sparse matrix? It seems to yield all nonzero locations, No, it gives you rows, just like a dense 2D array. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: libc Sleep api performs a busy waiting
Joe Fox schrieb: Hi, actually i have simplified my scenario a lot here , In my actual case , i have to call a C-api which blocks on c select , in a separate thread. my thread is getting struck in that api , and thus blocking all the other threads. Can you point to something which will help me call this blocking C-api call without my thread getting struck. ctypes. Releases the GIL before calling C api functions. -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.stdout vs. sys.stderr
On Jan 11, 2010, at 1:47 PM Nobody nob...@nowhere.com wrote: On Mon, 11 Jan 2010 10:09:36 +0100, Martin v. Loewis wrote: In Python 3.1 is there any difference in the buffering behavior of the initial sys.stdout and sys.stderr streams? No. Were they different at some earlier point in Python's evolution? That depends on the operating system. These used to be whatever the C library set up as stdout and stderr. Typically, they were buffered in the same way. On Unix, stdout will be line buffered if it is associated with a tty and fully buffered otherwise, while stderr is always unbuffered. On Windows, stdout and stderr are unbuffered if they refer to a character device, fully buffered otherwise (Windows doesn't have line buffering; setvbuf(_IOLBF) is equivalent to setvbuf(_IOFBF)). ANSI C says: As initially opened, the standard error stream is not fully buffered; the standard input and standard output streams are fully buffered if and only if the stream can be determined not to refer to an interactive device. I don't want to get into a quibble fight here, but I need to reraise this issue. [I teach and write and want to make sure I get this right. I already have an incorrect paragraph about this in my Bioinformatics Programming Using Python book.] The key question here is line buffering vs full buffering. In Unix (at least in an OS X Terminal), the following code prints a number every two seconds in Python 2: for n in range(5): . . . print sys.stderr, n, # final , to not send newline . . . time.sleep(2) However, in Python 3, similar code does not print the numbers until the whole thing finishes (again, running from the terminal). for n in range(5): . . . print(n, file=sys.stderr, end='') . . . time.sleep(2) So it appears that in a Unix terminal window, Python 2 does not line- buffer stderr whereas Python 3 does. That's what tripped me up. While developing and debugging code, I often print periods on a line as some loop progresses (sometimes every Nth time around, for some reasonable N) just to know the pace of execution and that the program is still doing something. In doing that recently in Python 3 I discovered that I either had to leave out the end='' or do sys.stderr.flush() after every print, which amounts to the same thing. This was a big surprise, after many, many years of C, C++, Java, and Python programming -- I have always thought of stderr as completely unbuffered in languages that have it. Doesn't mean some languages line- buffer stderr on some platforms, just pointing out an assumption I've lived with for a very long time that tripped me up writing a note about using stderr in Python 3 without actually demonstrating the code and therefore not catching my error.-- http://mail.python.org/mailman/listinfo/python-list
Re: remove element with ElementTree
Justin Ezequiel, 09.03.2010 10:34: On Mar 9, 11:35 am, tdandf.tr...@gmail.com wrote: I have been using ElementTree to write an app, and would like to simply remove an element. But in ElementTree, you must know both the parent and the child element to do this. There is no getparent() function, so I am stuck if I only have an element. see http://effbot.org/zone/element.htm#accessing-parents Also note that there is an independent ElementTree implementation called lxml.etree, which has parent pointers. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: How to determine if threads are active in an application?
En Fri, 26 Feb 2010 19:10:30 -0300, pyt...@bdurham.com escribió: Is there technique to determine if threads are active in a Python application? The only technique I can think of is to check sys.modules for thread and threading. But this will only show whether these modules were imported - not whether there are actually background threads running. I've just read your post. Look at threading.activeCount() - this returns only those threads created using the threading module. If that's not enough, you'll have to use some OS-specific functions. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: remove element with ElementTree
tdan, 09.03.2010 04:35: I have been using ElementTree to write an app, and would like to simply remove an element. But in ElementTree, you must know both the parent and the child element to do this. There is no getparent() function, so I am stuck if I only have an element. I am iterating over a table and getting alltd tags, checking their text, and conditionally deleting them: def RemoveElementWithText( topEl, subEl, text ): Note that all-camel-case names are rather unusual for function names and rather used for class names. See PEP 8 for a style guide. for el in topEl.getiterator( subEl ): if el.text = text: break else: el = None return el RemoveElementWithText( table, 'td', 'sometext' ) My table is like so: table thead... tbodytrtd... Is there any way to do this in ElementTree? I think the easiest is to iterate not over the elements themselves, but over their parents, and then to remove all children of the specified tag in each step. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
On Mar 9, 12:07 pm, Tim Golden m...@timgolden.me.uk wrote: You can't. You can apply one or more heuristics, depending on exactly what your requirement is. But any valid ASCII text is also valid UTF8-encoded text since UTF-8 isn't two bytes per char but a variable number of bytes per char. Hm, well that's very unfortunate. I'm using a database library which seems to assume that all strings passed to it are ASCII, and I'm attempting to use it on two different systems - one where all strings are ASCII, and one where they seem to be UTF-8. The strings come from the same place, i.e. they're exclusively normal ASCII characters. What I would want is to check once for whether the strings passed to function foo() are ASCII or UTF-8, and if they are to assume that all strings need to be decoded. So that's not possible? -- http://mail.python.org/mailman/listinfo/python-list
Re: scipy sparse matrix question
On 3/9/2010 1:14 AM, Victor Eijkhout wrote: I can't find any detailed information about scipy.sparse. Scipy questions are best asked on the scipy list, which I suspect you can also access via news.gmane.org. My specific question: what does for x in A give me when A is a sparse matrix? Try it and see what you get. -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
C. Benson Manica cbman...@gmail.com wrote in message news:98375575-1071-46af-8ebc-f3c817b47...@q23g2000yqd.googlegroups.com... The strings come from the same place, i.e. they're exclusively normal ASCII characters. In this case then converting them to/from UTF-8 is a no-op, so it makes no difference at all. -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
On Mar 9, 12:24 pm, Richard Brodie r.bro...@rl.ac.uk wrote: C. Benson Manica cbman...@gmail.com wrote in messagenews:98375575-1071-46af-8ebc-f3c817b47...@q23g2000yqd.googlegroups.com... The strings come from the same place, i.e. they're exclusively normal ASCII characters. In this case then converting them to/from UTF-8 is a no-op, so it makes no difference at all. Except to the database library, which seems perfectly happy to send an 8-character UTF-8 string to the database as 16 raw characters... -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ?
I like this tools, I'm wonder if there are similar tools in Python ? Blogofile is a static file blog engine/compiler, inspired by Jekyll. http://blogofile.com/ http://github.com/EnigmaCurry/blogofile -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
On 2010-03-09 11:12 AM, Stef Mientki wrote: On 09-03-2010 18:02, Alf P. Steinbach wrote: * C. Benson Manica: Hours of Googling has not helped me resolve a seemingly simple question - Given a string s, how can I tell whether it's ascii (and thus 1 byte per character) or UTF-8 (and two bytes per character)? This is python 2.4.3, so I don't have getsizeof available to me. Generally, if you need 100% certainty then you can't tell the encoding from a sequence of byte values. However, if you know that it's EITHER ascii or utf-8 then the presence of any value above 127 (or, for signed byte values, any negative values), tells you that it can't be ascii, AFAIK it's completely impossible. UTF-8 characters have 1 to 4 bytes / byte. I can create ASCII strings containing byte values between 127 and 255. No, you can't. ASCII strings only have characters in the range 0..127. You could create Latin-1 (or any number of the 8-bit encodings out there) strings with characters 0..255, yes, but not ASCII. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
On 3/9/2010 11:54 AM, C. Benson Manica wrote: Hours of Googling has not helped me resolve a seemingly simple question - Given a string s, how can I tell whether it's ascii (and thus 1 byte per character) or UTF-8 (and two bytes per character)? Utf-8 is an encoding that uses 1 to 4 bytes per character. So it is not clear what you are asking. Alf answered one of the possible questions. This is python 2.4.3, so I don't have getsizeof available to me. -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
Op 2010-03-09 18:31, C. Benson Manica schreef: On Mar 9, 12:24 pm, Richard Brodie r.bro...@rl.ac.uk wrote: C. Benson Manica cbman...@gmail.com wrote in messagenews:98375575-1071-46af-8ebc-f3c817b47...@q23g2000yqd.googlegroups.com... The strings come from the same place, i.e. they're exclusively normal ASCII characters. In this case then converting them to/from UTF-8 is a no-op, so it makes no difference at all. Except to the database library, which seems perfectly happy to send an 8-character UTF-8 string to the database as 16 raw characters... In that case I think you mean UTF-16 or UCS-2 instead of UTF-8. UTF-16 uses 2 or more bytes per character, UCS-2 always uses 2 bytes per character. UTF-8 uses 1 or more bytes per character. If your texts are in a Western language, the second byte will be zero in most characters; you could check for that (but note that the second byte might be the first one in the byte stream, depending on the byte ordering). HTH, Roel -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: related lists mean value (golfed)
Peter Otten wrote: Michael Rudolf wrote: Am 09.03.2010 13:02, schrieb Peter Otten: [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Peter ... pwned. Should be the fastest and shortest way to do it. It may be short, but it is not particularly efficient. A dict-based approach is probably the fastest. If y is guaranteed to be sorted itertools.groupby() may also be worth a try. $ cat tmp_average_compare.py from __future__ import division from collections import defaultdict try: from itertools import izip as zip except ImportError: pass x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] def f(x=x, y=y): p = defaultdict(int) q = defaultdict(int) for a, b in zip(x, y): p[b] += a q[b] += 1 return [p[b]/q[b] for b in y] def g(x=x, y=y): return [sum(a for a,b in zip(x,y)if b==c)/y.count(c)for c in y] if __name__ == __main__: print(f()) print(g()) assert f() == g() $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'f()' 10 loops, best of 3: 11.4 usec per loop $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'g()' 1 loops, best of 3: 22.8 usec per loop Peter I converged to the same solution but had an extra reduction step in case there were a lot of repeats in the input. I think it is a good compromise between efficiency, readability and succinctness. x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] from collections import defaultdict totdct = defaultdict(int) cntdct = defaultdict(int) for name, num in zip(y,x): totdct[name] += num cntdct[name] += 1 avgdct = {name : totdct[name]/cnts for name, cnts in cntdct.items()} w = [avgdct[name] for name in y] -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ?
KLEIN Stéphane, 09.03.2010 09:30: Today, I've show this static web site generating tools writed in ruby : * http://webgen.rubyforge.org/index.html * http://nanoc.stoneship.org/about/ * http://webby.rubyforge.org/tutorial/ I like this tools, I'm wonder if there are similar tools in Python ? Here's a still incomplete but not so short list of web frameworks in Python: http://wiki.python.org/moin/WebFrameworks You might be interested in the templating frameworks if all you want is generate static pages. Stefan -- http://mail.python.org/mailman/listinfo/python-list
ICNAAM 2010 Mini-Symposium on Computational Bioimaging and Visualization
Dear Colleague, Within the ICNAAM 2010 - 8th International Conference of Numerical Analysis and Applied Mathematics (http://www.icnaam.org), to be held in Rhodes, Greece, on 19-25 September 2010, we are organizing the Mini- Symposium on “Computational Bioimaging and Visualization”. Due to your research activities in the related fields, we would like to invite you to submit an invited extended abstract to our mini- symposium. Your contribution is mostly welcomed, and we would be honoured if you could accept this invitation. TOPICS OF INTEREST (not restricted to): - Image Processing and Analysis for Computational Bioimaging and Visualization; - Biomedical Signal and Image Acquisition and Processing; - Data Processing, Modeling and Analysis; - Scientific Visualization; - Enhanced Visualization; - Human Computer Interaction; - Simulation and Animation; - Virtual Reality; - Computer Aided Diagnosis, Surgery, Therapy, Treatment and Telemedicine Systems; - Software Development for Computational Bioimaging and Visualization; - Grid Computing in Computational Bioimaging and Visualization; - Applications of Computational Bioimaging and Visualization. IMPORTANT DATES: Deadline for Submission of Extended Abstract: July 22, 2010; Notification of acceptance: July 29, 2010; Deadline for Submission of the source files of the camera ready extended abstracts to American Institute of Physics (AIP Conference Proceedings): August 1, 2010. SUBMISSION INSTRUCTIONS: Extended abstracts will be published in a Special Volume of the AIP Conference Proceedings. Please, see the Instructions for Authors at: http://www.icnaam.org/abstract.htm, and select the Mini-Symposium on “Computational Bioimaging and Visualization” when submitting your contribution. With kind regards, João Manuel R. S. Tavares, University of Porto, Portugal, tava...@fe.up.pt Renato Natal Jorge, University of Porto, Portugal, rna...@fe.up.pt (Organizers of the Mini-Symposium on “Computational Bioimaging and Visualization”) -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyrhon2.5 to 2.4 conversion
Thanks a lot everybody for your help, it worked now :) On Feb 28, 4:12 am, MRAB pyt...@mrabarnett.plus.com wrote: tarek...@gmail.com wrote: Hi, I am currently using oauth2.py library, and it works fine on one of my PC's (python2.5), but later on when I tried to use it with python2.4 the following line (line 332 inhttp://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) showed a syntax error items = [(k, v if type(v) != ListType else sorted(v)) for k,v in sorted(self.items()) if k != 'oauth_signature'] So it there a way to convert this line to a python2.4 compliant syntax. I think the clearest is: items = [] for k, v in sorted(self.items()): if k != 'oauth_signature': if type(v) == ListType: v = sorted(v) items.append((k, v)) -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
I can create ASCII strings containing byte values between 127 and 255. No, you can't - or what you create wouldn't be an ASCII string, by definition of ASCII. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: scipy sparse matrix question
Terry Reedy tjre...@udel.edu wrote: My specific question: what does for x in A give me when A is a sparse matrix? Try it and see what you get. Ah, how do I see what I get? If I print it it looks plausible, but I don't know how to pull it apart. It doesn't seem to be an array. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu -- http://mail.python.org/mailman/listinfo/python-list
Re: How to detect C Function block using python
En Tue, 09 Mar 2010 04:51:57 -0300, Faheem faheem_...@yahoo.com escribió: I'm new in this community. I am writing a static analyzer for validating C Code using python and for that I'm looking for a python module/API that will detect Function block of a given C-File. I know simple function can be detected using push { and poping it if character } is found. This solution is actually done already, I want a robust API that can do more then that like detecting Function name parameters its return types etc. Take a look at ctypeslib [1]; it uses gccxml [2] to parse .h header files and generate equivalent Python declarations. [1] http://svn.python.org/view/ctypes/trunk/ctypeslib/ [2] http://www.gccxml.org/ -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: scipy sparse matrix question
On 2010-03-09 14:52 PM, Victor Eijkhout wrote: Terry Reedytjre...@udel.edu wrote: My specific question: what does for x in A give me when A is a sparse matrix? Try it and see what you get. Ah, how do I see what I get? If I print it it looks plausible, but I don't know how to pull it apart. It doesn't seem to be an array. In [5]: I = sparse.csr_matrix(np.eye(4)) In [6]: list(I) Out[6]: [1x4 sparse matrix of type 'type 'numpy.float64'' with 1 stored elements in Compressed Sparse Row format, 1x4 sparse matrix of type 'type 'numpy.float64'' with 1 stored elements in Compressed Sparse Row format, 1x4 sparse matrix of type 'type 'numpy.float64'' with 1 stored elements in Compressed Sparse Row format, 1x4 sparse matrix of type 'type 'numpy.float64'' with 1 stored elements in Compressed Sparse Row format] What is unclear about that? They are obviously 1x4 sparse matrices, i.e. the rows of the matrix. Use the .indices and .data attributes to get the indices of the nonzero values and the corresponding values. Details may differ depending on the format of sparse matrix. Some aren't even iterable. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Down casting Python objects
So I have `x', a instance of class `Foo'. I also have class `Bar', a class extending `Foo' with a couple of methods. I'd like to down cast x as efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect things to work OK in all major versions of CPython? -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
On 09-03-2010 18:36, Robert Kern wrote: On 2010-03-09 11:12 AM, Stef Mientki wrote: On 09-03-2010 18:02, Alf P. Steinbach wrote: * C. Benson Manica: Hours of Googling has not helped me resolve a seemingly simple question - Given a string s, how can I tell whether it's ascii (and thus 1 byte per character) or UTF-8 (and two bytes per character)? This is python 2.4.3, so I don't have getsizeof available to me. Generally, if you need 100% certainty then you can't tell the encoding from a sequence of byte values. However, if you know that it's EITHER ascii or utf-8 then the presence of any value above 127 (or, for signed byte values, any negative values), tells you that it can't be ascii, AFAIK it's completely impossible. UTF-8 characters have 1 to 4 bytes / byte. I can create ASCII strings containing byte values between 127 and 255. No, you can't. ASCII strings only have characters in the range 0..127. You could create Latin-1 (or any number of the 8-bit encodings out there) strings with characters 0..255, yes, but not ASCII. Probably, and according to wikipedia you're right. I think I've to get rid of my old books, Borland turbo Pascal 4 (1987) has an ASCII table of 256 characters, while the small letters say 7-bit ;-) cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
CSV DictReader loops when used with MySQLdb
I'm going crazy. Using python 2.5.2 on 64 bit Linux. I have a class which reads CSV files using the CSV DictReader. If I print the rows, everything works perfectly. If I insert the rows into a MySQL table using MySQLdb, the DictReader loops back and begins re-reading from the beginning of the file when it reaches EOF. Here's the code: class CsvLoader: load data from a CSV file into a corresponding MySQL table def __init__(self, fname, schema, db, useCleanReader = False): self.schema = schema self.db = db if useCleanReader: self.reader = csv.DictReader(CleanReader(fname), delimiter=',', quotechar='') else: self.reader = csv.DictReader(open(fname), delimiter=',', quotechar='') def loadMysql(self): for row in self.reader: self.db.insertGeneric(self.schema.tableName(), row) def printRows(self): for row in self.reader: print \n, row and here is the insertGeneric method: def insertGeneric(self, table, record): execute a generic INSERT, given a dict as input fieldList = [] valueList = [] for k in record.keys(): fieldList.append(k) valueList.append(record[k]) fields = , .join(fieldList) m = ['%s'] valueMarkers = , .join(m * len(valueList)) # create a string like: %s, %s, %s... sql = 'insert into %s (%s) values (%s)' % (table, fields, valueMarkers) cursor = self.conn.cursor() print +++ insert: %s = %s % (sql, valueList) cursor.execute(sql, valueList) cursor.close() useCleanReader is False CsvLoader.printRows() works fine. CsvLoader.loadMySql() keeps looping through the CSV file. Ideas? -- Art Z. -- Art Zemon, President Hen's Teeth Network http://www.hens-teeth.net/ Phone: (866)HENS-NET or (636)447-3030 ext. 200 Twitter: AZemon http://twitter.com/AZemon -- http://mail.python.org/mailman/listinfo/python-list
Named loops for breaking
Hey, I did a little searching and couldn't really find much recent on this. The only thing I found was this: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a696624c92b91181/5b7479fdc3362b83?lnk=gstq=break+named+loop#5b7479fdc3362b83 Basically I'm wondering if there are any plans to implemented named loops in Python, so I can tell a break command to break out of a specific loop in the case of nested loops. Currently I'm using boolean flag variables, but I find that very clumsy. I know this idea of breaking out of specific loops from javascript; I guess java does it too. It just seems a very Pythonian idea to me: clear, promotes code legibility, seems obvious. -- http://mail.python.org/mailman/listinfo/python-list
How to dynamic insert more conditional statements into a function
Hi I am a newbie for Python Here is a question, say I have a list L, function foo is: def foo(L): if L[0] 0: return True if later I want another function goo which returns True when L[0] and L[1] are both 0, i.e., def goo(L): if L[0] 0 and L[1] 0: return True Can anybody tell me how can I write the function goo based upon the function foo? Thanks! I know if it is implementable, I should use decorator. But I just cannot figure out how. -- http://mail.python.org/mailman/listinfo/python-list
find text location (in pixels) using python (pyPdf)
Has anyone ever tried to find the pixel (or point) location of text in a PDF using Python? I've been using the pyPdf libraries for other things, and it seems to me that if I can find the bounding box for text, I should be able to calculate the location. What I want to do is take a PDF of one of our vendor invoices and blur everything in it except the block that's related to a single customer. So if I have an invoice that looks like: Alfred Annoying 123 Elm St Somewhere, NJ $100 Barbie Bonehead 456 Pine St Elsewhere, NJ $125 Charlie Clueless 789 Beech St. Everywhere, NJ $150 I want to show Barbie just her section of the invoice (with the header intact, so that she can tell it's a real invoice) but with Alfred and Charlie's information blurred out. I was going to convert the PDF to a JPG or PNG and do the blurring with ImageMagick/PythonMagick. But that requires me to know the pixel location of the regions that I want blurred and left alone. I'm also open to other ideas if I'm going about this the hard way -- http://mail.python.org/mailman/listinfo/python-list
Re: Updates about Tk
On Feb 27, 5:29 pm, rantingrick rantingr...@gmail.com wrote: Great post Kevin! The only thing i would like to add are my two favorite references for learning Tkinter. They are not geared around the new ttk stuff, but still 95% relevant to any Tkinter-ing http://effbot.org/tkinterbook/ http://infohost.nmt.edu/tcc/help/pubs/tkinter/ You might also want to check out: http://www.tkdocs.com/ Which covers the ttk widgets too (and, for multi-language people, it also handles how to do it from four languages). Donal. -- http://mail.python.org/mailman/listinfo/python-list
Re: Named loops for breaking
Daniel Klein bri...@gmail.com writes: Basically I'm wondering if there are any plans to implemented named loops in Python, so I can tell a break command to break out of a specific loop in the case of nested loops. Currently I'm using boolean flag variables, but I find that very clumsy. The usual way to do this in Python is with an exception, perhaps a specially named one if that makes your code clearer: class Whatever(Exception): pass ... try: for x in thingie: for y in x.whatsis(): if lose(y): raise Whatever ... except Whatever: pass This situation doesn't come up all that often and you should probably ask yourself if you really need those nested loops. You might also be able to put the nested loop structure into a function that you can then exit with a return statement. -- http://mail.python.org/mailman/listinfo/python-list
Re: String is ASCII or UTF-8?
On 3/9/2010 1:36 PM Stef Mientki said... On 09-03-2010 18:36, Robert Kern wrote: snip No, you can't. ASCII strings only have characters in the range 0..127. You could create Latin-1 (or any number of the 8-bit encodings out there) strings with characters 0..255, yes, but not ASCII. Probably, and according to wikipedia you're right. I too looked at wikipedia, and it seems historically incomplete to me. In particular, I looked for 'high order ascii', which, when I was working with Basic Four in the '70's, is what they used. Essentially, the high order bit was set for all characters to make 8A a line feed, etc. Still the same 0..127 characters, but not really an extended ascii which is where wikipedia forwards you to. I remember having to strap the eighth bit high when I reused the older line printers to get them to work. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: How to dynamic insert more conditional statements into a function
On 3/9/2010 1:48 PM Shane said... Hi I am a newbie for Python Here is a question, say I have a list L, function foo is: def foo(L): if L[0] 0: return True if later I want another function goo which returns True when L[0] and L[1] are both 0, i.e., def goo(L): if L[0] 0 and L[1] 0: return True Here's one way... def foo(L,deep=0): return L[0] and not deep or foo(L[1:],deep-1) Subject to clean up. Emile -- http://mail.python.org/mailman/listinfo/python-list
Can't build hashlib
The md5 module is used in build xulrunner and Firefox from source. When I do run the install its says md5 no such module. I compiled Python 2.6.4 after installing openssl and BerkleyDB, yet I get this error when compilying Python: Failed to find the necessary bits to build these modules: _tkinter bsddb185 dl imageopsunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _hashlib _ssl -- http://mail.python.org/mailman/listinfo/python-list
Re: equivalent of Ruby's Pathname?
I just saw this thread on the Python-URL. On Feb 14, 12:39 pm, a...@pythoncraft.com (Aahz) wrote: Sean DiZazzo =A0half.ital...@gmail.com wrote: Why did Path() get rejected? Is it the idea itself, or just the approach that was used? What are the complaints? You should search for the discussiona around it. I read the discussion, and there was definitely some going back and forth on whether it should be sub-classed from string, but the conversation just seemed to stop abruptly with no decision one way of the other. Maybe I missed a thread. It has a habit of being discussed and dropped repeatedly. The main issue is that Guido doesn't see an OO approach as necessarily better than the existing functions, so it has a high bar for acceptance. One issue is that some people see a need to separate filesystem- independent functionality (joining paths and extracting components) from filesystem-dependent functionality (listing directories, removing files, etc). ``path.py`` and PEP 355 were rejected mainly because of this. There was support for a small filesystem-independent class that could be put into the stdlib, and some modest moving/renaming of the filesystem functions (which are scattered across os, os.path, shutil, glob, etc). We were hoping to get this done for Python 3 but didn't make it. I wrote a ``Unipath`` package that tried to be a compromise between what everybody wanted, with a FS-independent class and a FS- dependent subclass, but could not get any feedback on it. Somebody else was going to write a PEP for the renamings, but I never saw it. Since then, path.py has been included in a couple packages and seems to have the most widespread use. I gave up on the stdlib and reconfigured Unipath as a pure 3rd-party library. (The FS-independent AbstractPath class is still there if anybody wants to use it for a PEP.) The other people who made their own implementations seemed to be happy with theirs, and that was that. The string vs non-string argument has pretty much been decided in favor of strings (i.e., a string subclass). Not ``a.txt.open()`` but ``open(Path(a.txt))``. Too many standard and 3rd-party modules expect string paths: you'd have to convert your path to a string every time you pass it as an argument. The main problem with string paths is that .join() means something else, but that's usually solved by using a different method name: joinpath, child, /, etc. Other proposals have been a tuple subclass, so that ``Path(a/b/c.txt) [-1] == Path(c.txt)``, and a library that can do non-native paths (Windows style on Unix systems and vice-versa). These don't seem to be in vogue anymore. What has become more common is virtual paths; i.e., the same interface for filesystems, FTP, zip files, etc. That was discussed during the last go-around but there were no implementations. Now there are a few projects active on this, such as http://groups.google.com/group/stdpyfs . This is probably the future of any path object, so it would make sense to define a path now that can work with all these backends. --Mike -- http://mail.python.org/mailman/listinfo/python-list
file seek is slow
I ran a comparison that timed 1e6 file seeks. The tests were run with Python 2.6.4 and Microsoft Visual C 6.0 on Windows XP with an Intel 3GHz single processor with hyperthreading. Results: C: 0.812 seconds Python: 1.458 seconds. difference = 0.646 seconds. If the file.seek is removed the Python loop takes 2ms so the loop overhead is minimal. Without pysco the loop overhead is 4.6ms and Python takes 1.866. Any ideas what is causing the slow down over the 'C' version. In general I have been trying to take a video application written in C+ + and make it work in Python. There seem to be delays in the handoff to Windows System code that make the Python version just a touch slower in some areas, but these slowdowns are critically effecting the work. File seek is not a deal breaker here, it is just the latest thing I have noticed and the simplest to demonstrate. Python version: import time def main(): # write temp file SIZE = 1000 f1 = file('video.txt', 'wb') f1.write('+' * SIZE) f1.close() f1 = file('video.txt', 'rb') t0 = time.clock() for i in xrange(100): f1.seek(0) delta = time.clock() - t0 print %.3f % delta f1.close() if __name__ == '__main__': import psyco psyco.full() main() // 'C' version #include stdio.h #include time.h #define SIZE 1000 static void main(int argc, char *argv[]) { FILE *f1; int i; int t0; float delta; char buffer[SIZE]; // write temp file memset(buffer, (int)'+', SIZE); f1 = fopen(video.txt, wb); fwrite(buffer, SIZE, 1, f1); fclose(f1); f1 = fopen(video.txt, rb); t0 = clock(); for (i=0; i 100; i++) { fseek(f1, 0, SEEK_SET); } delta = (float)(clock() - t0) / CLOCKS_PER_SEC; printf(%.3f\n, delta); fclose(f1); } -- http://mail.python.org/mailman/listinfo/python-list
Re: equivalent of Ruby's Pathname?
On 02/09/10 14:00, Phlip wrote: cut Ah, now we get down to the root of the problem. Because Python is so stuck on the one best way to do it mentality, language bigotry prevented the Committee from picking from among several equally valid but non-best options. And after 20 years of growth, Python still has no Pathname class. What a mature community! C-: cut Well even if this statement would be true, I personally think that not proclaiming something a 'standard' if you are sure that you are not sure about it, is a virtue. -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: Reverse engineering CRC?
Dave Angel wrote: If you assume it's done in a single pass, and you know which byte is the end of the buffer, I'd think you could learn a lot by just tweaking that last byte. I'm sure I would, but unfortunately I can't control the last byte. The bytes that I can influence are some distance back from the end of the data. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: file seek is slow
This is a pretty tight loop: for i in xrange(100): f1.seek(0) But there is still a lot going on, some of which you can lift out of the loop. The easiest I can think of is the lookup of the 'seek' attribute on the f1 object. Try this: f1_seek = f1.seek for i in xrange(100): f1_seek(0) How does that help your timing? -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Knight's tour Warndorff's algorithm problem
Hi all I'm having some troubles with writing Knight's tour (http://en.wikipedia.org/wiki/Knight%27s_tour) solution in Python 3. I'm using Warnsdorff's algorithm (http://en.wikipedia.org/wiki/Knight% 27s_tour#Algorithm) and I'm wondering why it doesn't work with boards of certain sizes. I've written a solution and I like it but it does not work correctly for 15x15, 26x26, 27x27 and 32x32 boards (don't know why; checked from 5x5 to 40x40). So I'd be really glad if you tell me whether I am too stupid for Python or for Discrete Math? In other words, did I implemented Warnsdorff's algorithm in Python 3 correctly or maybe all my troubles are because I haven't read tutorial with enough patience? P.S. Warnsdorff's algorithm says that it's not really important which square to choose between those which have equal amount of ways out. In spite of that I tried to changed my program and added '=' to condition at line 78. Results were quite surprising: now it works for 5x5, 6x6, ... 34x34 but not for 35x35! #!/usr/bin/env python3 class ChessBoardSquare: Class for chess board square. status = 0# 0 - unvisited, 1 - visited ways_out = 0 # Count of possible moves from this square. x = 0 # Square's x coordinate, from left to right. y = 0 # Square's y coordinate, from top to bottom. def __init__(self, y, x): (self.y, self.x) = (y, x) class ChessBoard: size = 8 # Board square width and height. cell = [] # Embedded list of board cells. move = 0 # Current move number. x = 0 # x coordinate of square to move to. y = 0 # y coordinate of square to move to. def __init__(self): import sys # Reading board size. if len(sys.argv) = 2: self.size = int(sys.argv[1]) # Reading first square to move to. if len(sys.argv) = 4: self.y = int(sys.argv[2]) self.x = int(sys.argv[3]) # Creating board squares. for i in range(self.size): self.cell.append([]) for j in range(self.size): self.cell[i].append(ChessBoardSquare(i, j)) # Counting ways out for every square on a board. for i in range(self.size): for j in range(self.size): self.cell[i][j].ways_out = len(self.getCellNeighbours(i, j)) def makeMove(self): This function makes another move. # Printint current move number. self.move += 1 print(self.move, ':', sep = '') # We have visited just another square. self.cell[self.y][self.x].status = 1 # Now we should define where to move next and # re-calculate possible moves from neighbours of # current square. neighbours = self.getCellNeighbours(self.y, self.x) next = 0 for neighbour in neighbours: neighbour.ways_out -= 1 if next == 0: next = neighbour continue if next.ways_out neighbour.ways_out: next = neighbour if (next != 0): (self.y, self.x) = (next.y, next.x) # And finally printing result of this move. self.printField() #input() def printField(self): This function prints field to standart output. for i in range(self.size): for j in range(self.size): print(self.cell[i][j].status, end = '') #print('(', self.cell[j][j].status, ')', sep = '', end = ' ') print() def getCellNeighbours(self, y, x): This function returns those cells which are accessible from current square. # Coordinates of possible neighbours. applicants = [[y - 1, x - 2], [y - 1, x + 2], [y + 1, x - 2], [y + 1, x + 2], [y - 2, x - 1], [y - 2, x + 1], [y + 2, x - 1], [y + 2, x + 1]] result = [] for applicant in applicants: # It's fail if out of index. if applicant[0] 0 or applicant[0] = self.size: continue if applicant[1] 0 or applicant[1] = self.size: continue # If it is unvisited then everythin's alright and we append it to the result list. if self.cell[applicant[0]][applicant[1]].status == 0: result.append(self.cell[applicant[0]][applicant[1]]) return result if __name__ == '__main__': field = ChessBoard() while (field.cell[field.y][field.x].ways_out != 0): field.makeMove() field.makeMove() -- http://mail.python.org/mailman/listinfo/python-list
Re: Named loops for breaking
Daniel Klein bri...@gmail.com wrote: Basically I'm wondering if there are any plans to implemented named loops in Python, so I can tell a break command to break out of a specific loop in the case of nested loops. You should be able to do this with the goto module: http://entrian.com/goto/ But please note that I'm not seriously advocating its use :) -- http://mail.python.org/mailman/listinfo/python-list
Re: odd error
Alex Hall mehg...@gmail.com wrote: Why would the sequence matter, or does it not and I am doing something else wrong? Here is a sample of my dictionary: Showing us the code that handles the dictionary lookup + function calling would probably help us a lot more here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Six Minutes and fourty two seconds
Tobiah wrote: Now that I use python, this is the amount of time per day that I spend adding forgotten semicolons while debugging other languages. What compels you to write Python code without semicolons? Frederic Try the C language without semicolons and braces http://pythoidc.googlecode.com-- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial script doesnt execute properly
Hi Kishore, Have you tried ser=serial.Serial(port='COM2', baudrate=9600) instead of port='\\.\COM2'? Also, I'd suggest you temporarily define some other parameters that now you're leaving to default values. From the documentation of pyserial: readline(size=None, eol='\n') You're sure that your Arduino device is sending a '\n' right after the '1', aren't you? Or is it two consecutive '1'? And another idea: If this is your first experience with PySerial, I suggest you first use some free software as counterpart to your Arduino device in order to confirm the microcontroller is sending exactly what you think it is sending. In other words, is it sending to your Python program '11' or '1\n1\n'? Also to confirm other details such as parity bits, baud, etc. Cheers, Andy -- http://mail.python.org/mailman/listinfo/python-list
Re: Reverse engineering CRC?
On Mar 7, 7:09 pm, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Given some known data/crc pairs, how feasible is it to figure out the polynomial being used to generate the crc? In the case I'm looking at, it appears that the crc size may be at least 24 bits, so just trying all possible polynomials probably isn't doable. An article I found hints at the possibility of using GCDs to make the search more efficient, but doesn't go into any details. Anyone know of any literature about this? If it helps, I have the ability to generate test cases with known message contents to some extent, although I don't have complete control over the contents. Also it's a manual process, so generating large numbers of them automatically isn't an option. Hi Greg. I would at least flip one bit at a time on the first byte of your data to see if the transformation is bitwise. -- http://mail.python.org/mailman/listinfo/python-list
Knight's tour Warndorff's algorithm problem
El 9 mar, 22:57, Robin Rytich escribió: I'm having some troubles with writing Knight's tour (http://en.wikipedia.org/wiki/Knight%27s_tour) solution in Python 3. I'm using Warnsdorff's algorithm (http://en.wikipedia.org/wiki/Knight% 27s_tour#Algorithm) and I'm wondering why it doesn't work with boards of certain sizes. I've written a solution and I like it but it does not work correctly for 15x15, 26x26, 27x27 and 32x32 boards (don't know why; checked from 5x5 to 40x40). Warnsdorff's algorithm is heuristic; it works most of the time, but in some cases leads to a dead end and you have to backtrack and try another alternative. The starting square is important; if you start at 1,1 (instead of 0,0) your program finds a solution for all those problematic board sizes. So I'd be really glad if you tell me whether I am too stupid for Python or for Discrete Math? In other words, did I implemented Warnsdorff's algorithm in Python 3 correctly or maybe all my troubles are because I haven't read tutorial with enough patience? Your implementation looks fine to me. Some comments on the code itself: class ChessBoard: size = 8 # Board square width and height. cell = [] # Embedded list of board cells. This sets a class attribute (as opposed to normal, instance attributes) which is shared by all ChessBoard instances (this really should be covered in the FAQ!). You really want an instance attribute here: do `self.cell = []` in __init__ def __init__(self): import sys # Reading board size. if len(sys.argv) = 2: self.size = int(sys.argv[1]) I would process command line arguments when the script starts, and supply size/x/y as parameters to the ChessBoard constructor. In other words, the caller must provide those parameters, it's not ChessBoard responsability to hunt for them. if (next != 0): (self.y, self.x) = (next.y, next.x) All those six () are unnecessary. Also, `next` might refer to integer 0 or a ChessBoardSquare instance. That's perfectly legal in Python, but *I* prefer to assign objects of the same type when using the same variable name. In this case, 0 is used only as a marker, any other non-ChessBoardSquare instance would do, and I'd substitute None instead. (This is more than a stylistic whim: some JIT compiler may benefit from knowing the object type won't change) def printField(self): This function prints field to standart output. for i in range(self.size): for j in range(self.size): print(self.cell[i][j].status, end = '') print() Instead of artificially iterate over the *indices* to finally reach the objects, you may directly iterate over the board squares: for row in self.cell: for square in row: print(square.status, end = '') print() Later: applicants = [[y - 1, x - 2], [y - 1, x + 2], [y + 1, x - 2], [y + 1, x + 2], [y - 2, x - 1], [y - 2, x + 1], [y + 2, x - 1], [y + 2, x + 1]] result = [] for applicant in applicants: if applicant[0] 0 or applicant[0] = self.size: continue if applicant[1] 0 or applicant[1] = self.size: continue if self.cell[applicant[0]][applicant[1]].status == 0: result.append(self.cell[applicant[0]][applicant[1]]) It would be better to use meaningful names instead of applicant[0], applicant[1] -- let me re-use y,x. We can write a more concise condition: result = [] for y,x in applicants: if not 0 = y self.size: continue if not 0 = x self.size: continue if self.cell[y][x].status == 0: result.append(self.cell[y][x]) Now, lets combine all those conditions into a single one: result = [] for y,x in applicants: if 0 = y self.size and 0 = x self.size and self.cell[y][x].status == 0: result.append(self.cell[y][x]) Finally, a code pattern like the above can always be rewritten as a list comprehension: result = [self.cell[y][x] for y,x in applicants if 0 = y self.size and 0 = x self.size and self.cell[y][x].status == 0 ] Apart from these points, your program looks fine to me. You even added function docstrings! (ok, they might be more informative, but at least they exist!) -- Gabriel Genellina --
pexpect and logging integration
Hi all, has anyone managed to integrate pexpect and logging? I.e., I'd like to be able to pick up the dialog, commands sent and responses received, in my logging. I know about the pexpect logfile, and I can log things to stdout or stderr, but I really need to log using the python logging library. Any thoughts appreciated /Lars -- http://mail.python.org/mailman/listinfo/python-list
Re: Named loops for breaking
En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein bri...@gmail.com escribió: Basically I'm wondering if there are any plans to implemented named loops in Python, so I can tell a break command to break out of a specific loop in the case of nested loops. See PEP3136 [1] and its rejection note [2] I think you may find some more discussion in the python-ideas list. Currently I'm using boolean flag variables, but I find that very clumsy. I know this idea of breaking out of specific loops from javascript; I guess java does it too. It just seems a very Pythonian idea to me: clear, promotes code legibility, seems obvious. Although I've occasionally missed the feature myself, I agree with Guido's arguments against it. You have several alternatives: refactor the loop into an auxiliary function, use a specific exception, add boolean flags, or repeat the test at the outer levels. (I usually choose the first). [1] http://www.python.org/dev/peps/pep-3136/ [2] http://mail.python.org/pipermail/python-3000/2007-July/008663.html -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: How to dynamic insert more conditional statements into a function
En Tue, 09 Mar 2010 18:48:42 -0300, Shane sheng...@gmail.com escribió: Hi I am a newbie for Python Here is a question, say I have a list L, function foo is: def foo(L): if L[0] 0: return True if later I want another function goo which returns True when L[0] and L[1] are both 0, i.e., def goo(L): if L[0] 0 and L[1] 0: return True Can anybody tell me how can I write the function goo based upon the function foo? Thanks! I know if it is implementable, I should use decorator. But I just cannot figure out how. To implement goo based on foo: def goo(L): if foo(L) and L[1]0: return True I don't see how to use a decorator here - maybe your example became too simple to be useful. A more realistic use case? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: datelib pythonification
DATE_TYPE = type(date.today()) def dates_diff(self, *targs): nargs = len(targs) if nargs == 0: return self.enddate - self.startdate if nargs == 1: arg = targs[0] if not isinstance(arg, (list, tuple)) or len(arg) != 2: raise Exception( single arg must be list or tuple of length 2) start, end = arg elif nargs == 2: start, end = targs else: raise Exception(expected 0,1, or 2 args; found %d % nargs) if isinstance(start, DATE_TYPE) and isinstance(end, DATE_TYPE): return end - start raise Exception(both values must be of type DATE_TYPE) HTH, John This is awesome. Thank you for your contribution. I wasn't sure anyone was gonna reply; just saw your reply, pardon my delay. I will make the changes you suggested to other functions that apply in the lib as well(mimic that style of coding). Make it so it raises exceptions instead of failing over quietly(fallback to the __init__ passed args in other words). Is There any other functions or methods that you would recommend be added to the lib? Any and all other suggestions are welcome. I love python and you guys are practically helping me expand on my knowledge in this realm :) I haven't touched it in a little bit so after I mess with it again I'll be able to add more this thread/lib or whatever. Thanks Again, -Alex Goretoy -- http://mail.python.org/mailman/listinfo/python-list