Hello.
cmd won't recognize python at all I've checked several times , and I don't understand what's wrong Sent from Mail for Windows 10 -- https://mail.python.org/mailman/listinfo/python-list
Re: Learning Python 2.4
I'd recommend starting with http://learnpythonthehardway.org/book/ by Zed Shaw or Beginning Python Using Python 2.6 and Python 3.1 by James Payne I'd say learning Python 2.6 would be better than 2.4, since it's really old. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I customize builtin module search path to prefix/lib to prefix/lib64?
In addition to that, .pth cannot prepend search path. All thing it can do is appending to it. In my case, I have to put lib64 before lib/. On 9/26/08, js [EMAIL PROTECTED] wrote: For 64bit python, there's no need to look at lib/lib-dynload because libraries for 64bit should be in lib64/lib-dynload. Having module search path which point to libraries the python can not understand is, IMHO, wrong. On Fri, Sep 26, 2008 at 3:03 AM, Mike Driscoll [EMAIL PROTECTED] wrote: On Sep 25, 10:41 am, js [EMAIL PROTECTED] wrote: Hi list, Is it possible to change module search path (PYTHONPATH) built-in to Python interpreter? I thought I can change it with configure --libdir but it didn't work for me. I also tried patching around python source tree replacing lib to lib64 but it didn't work either. Adjusting sys.path directly or using environ should do the trick but I'd rather want to make it the default path for my python Thanks, Why not just add a custom path file (*.pth)? EasyInstall, wx, PyWin32 and others do it. Of course there's always sys.path.append as well. Mike -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
How can I customize builtin module search path to prefix/lib to prefix/lib64?
Hi list, Is it possible to change module search path (PYTHONPATH) built-in to Python interpreter? I thought I can change it with configure --libdir but it didn't work for me. I also tried patching around python source tree replacing lib to lib64 but it didn't work either. Adjusting sys.path directly or using environ should do the trick but I'd rather want to make it the default path for my python Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I customize builtin module search path to prefix/lib to prefix/lib64?
For 64bit python, there's no need to look at lib/lib-dynload because libraries for 64bit should be in lib64/lib-dynload. Having module search path which point to libraries the python can not understand is, IMHO, wrong. On Fri, Sep 26, 2008 at 3:03 AM, Mike Driscoll [EMAIL PROTECTED] wrote: On Sep 25, 10:41 am, js [EMAIL PROTECTED] wrote: Hi list, Is it possible to change module search path (PYTHONPATH) built-in to Python interpreter? I thought I can change it with configure --libdir but it didn't work for me. I also tried patching around python source tree replacing lib to lib64 but it didn't work either. Adjusting sys.path directly or using environ should do the trick but I'd rather want to make it the default path for my python Thanks, Why not just add a custom path file (*.pth)? EasyInstall, wx, PyWin32 and others do it. Of course there's always sys.path.append as well. Mike -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I convert a PyObject to string in C++?
PyString_AsString returns a c string. Just feed it to std::string http://docs.python.org/api/stringObjects.html#l2h-472 On Tue, Sep 23, 2008 at 11:32 AM, [EMAIL PROTECTED] wrote: I have a PyObject, say 'Hello World' , a string, How do I convert it to a string in C++? Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Quality of Standard Modules
I read an interview with Guido at http://www.techworld.com.au/article/255835/a-z_programming_languages_python and that's very interesting. In that article, he said there are also a lot of modules that aren't particularly well thought-out, or serve only a very small specialized audience, or don't work well with other modules. I'm curious what modules he's refering and other Pythonistas feel it's not pythonic. Can you share some of your thought? -- http://mail.python.org/mailman/listinfo/python-list
Py_BuildValue for char **?
Hi, I'm writing a wrapper module of C API. To make a C struct data avaiable to Python, I need to map C struct into a PyObject. I'm thinking that I use a tuple or dict to represent the struct but a problem is one of the members of the struct is char **, which is not supported by Py_BuildValue. Is there any idiomatic way of mapping char ** to Python? Any suggestions, pointers would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: The best way to package a Python module?
Thanks everyone for details. I'll try stealing some of the good bits of python-central of debian for my purpose. On Mon, Jun 16, 2008 at 10:43 AM, Ben Finney [EMAIL PROTECTED] wrote: Jean-Paul Calderone [EMAIL PROTECTED] writes: What has changed is that the tools in common use for Debian packaging of Python libraries have taken on the role of generating those per-version copies at install time. [EMAIL PROTECTED]:~$ ls -l /usr/lib/python2.{4,5}/site-packages/sqlite/main.py lrwxrwxrwx 1 root root 63 2007-12-27 15:29 /usr/lib/python2.4/site-packages/sqlite/main.py - /usr/share/pycentral/python-sqlite/site-packages/sqlite/main.py lrwxrwxrwx 1 root root 63 2007-12-27 15:29 /usr/lib/python2.5/site-packages/sqlite/main.py - /usr/share/pycentral/python-sqlite/site-packages/sqlite/main.py [EMAIL PROTECTED]:~$ That doesn't seem to agree with your statement. Am I missing something? You are missing an inspection of the contents of the actual package file. The package file itself contains only a single copy of the Python module (at /usr/share/pycentral/site-packages/sqlite/main.py). What you see there on your filesystem was created at install time; the installation tool figures out, at install time, which Python versions need to be supported on this particular system, and creates those symlinks. Thus, the change that's occurred is that the user doesn't need to choose between Python SQLite library for Python 2.4 and Python SQLite library for Python 2.5. There is no longer a separation at the package level by Python version, so the user merely needs to choose (given your example) the single Python SQLite library, and the install process takes care of setting it up for all supported versions of Python on the system. -- \ [Freedom of speech] isn't something somebody else gives you. | `\ That's something you give to yourself. —_Hocus Pocus_, | _o__)Kurt Vonnegut | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
The best way to package a Python module?
Hi list, I'm trying to build a package for python modules. When I just wanted to have a package for Python2.5, this is an easy task, but in most cases, it's not enough. Sometimes I need python2.4, 2.5, 2.6 or 3.0 etc. The problem is coming from the fact that python installs its modules into version-independent place as follow. $prefix/lib/python2.4/site-package/ $prefix/lib/python2.5/site-package/ For this, I have to create a package for each version. Let's say if I need a module called spam and installed spam with python2.5. The files would be installed in $prefix/lib/python2.5/site-package/. It only usable from python2.5. When I need it for python2.4, I have to prepare the same package for python2.4, the only difference is the place it installed. This is the problem I'm having now. How can I avoid this redundant work? Any advice, suggestions would be greatly appreciated. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: The best way to package a Python module?
By package, I meant APT, Ports for BSD, MacPorts, etc. On Mon, Jun 16, 2008 at 1:16 AM, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On Mon, 16 Jun 2008 01:01:47 +0900, js [EMAIL PROTECTED] wrote: Hi list, I'm trying to build a package for python modules. When I just wanted to have a package for Python2.5, this is an easy task, but in most cases, it's not enough. Sometimes I need python2.4, 2.5, 2.6 or 3.0 etc. The problem is coming from the fact that python installs its modules into version-independent place as follow. $prefix/lib/python2.4/site-package/ $prefix/lib/python2.5/site-package/ For this, I have to create a package for each version. Let's say if I need a module called spam and installed spam with python2.5. The files would be installed in $prefix/lib/python2.5/site-package/. It only usable from python2.5. When I need it for python2.4, I have to prepare the same package for python2.4, the only difference is the place it installed. This is the problem I'm having now. How can I avoid this redundant work? Any advice, suggestions would be greatly appreciated. Thanks! What do you mean, package? If you use distutils, then none of the questions you asked make very much sense. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: TextWrapper keepking line breaks?
Hi Arnaud, Great. Thanks for your help! On Tue, Mar 11, 2008 at 10:27 AM, Arnaud Delobelle [EMAIL PROTECTED] wrote: On Mar 10, 11:31 pm, js [EMAIL PROTECTED] wrote: Hi list, Can I make TextWrapper keep line breaks in the text? For example, s = spam\nham print wrap(s) spam ham As far as I can tell, there seems no way to do this, but before writing my own solution, I want to know whether the solution already exists or not. Thanks. Don't know but you could write: import textwrap def wraplines(text): ... return '\n'.join(textwrap.fill(line) for line in text.split('\n')) ... s = spam\nham print wraplines(s) spam ham HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
TextWrapper keepking line breaks?
Hi list, Can I make TextWrapper keep line breaks in the text? For example, s = spam\nham print wrap(s) spam ham As far as I can tell, there seems no way to do this, but before writing my own solution, I want to know whether the solution already exists or not. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Beautiful Code in Python?
Hi, Have you ever seen Beautiful Python code? Zope? Django? Python standard lib? or else? Please tell me what code you think it's stunning. -- http://mail.python.org/mailman/listinfo/python-list
Re: Book Recomendations
I wonder why nobody mension Python Cookbook yet. http://www.oreilly.com/catalog/pythoncook2/ Web version: http://aspn.activestate.com/ASPN/Cookbook/Python/ and Python Standard Library http://www.oreilly.com/catalog/pythonsl/ http://effbot.org/zone/librarybook-index.htm On Sun, Mar 2, 2008 at 4:09 PM, Paddy [EMAIL PROTECTED] wrote: On Mar 2, 12:56 am, Ira Solomon [EMAIL PROTECTED] wrote: I am an experienced programmer (40 years). I've done Algol (if you've heard of that you must be old too), PL/1, VB,VBA, a little C, and a few other odd languages (e.g. Taskmate). I'm interested in learning Python and have downloaded a slew of books. Too many. I'd like a recommendation as to which books are considered to be the cream of the crop. I know there are tutorials on the web, but, again, I don't know the quality. I would appreciate recommendations on those as well. Thanks Ira Hi Ira, Get Python installed on your machine - I would suggest the latest 2.5 release then either start up idle (or pythonwin if you have that on windows), or just type python at a command line prompt to get you to pythons shell. The Python shell together with the official tutorial is a great way to learn Python. If you start to flag, then their are a few videos of pre-teen kids learning Python here: http://showmedo.com/videos/python?topic=beginner_programming If they can learn it ;-) Welcome to Python, have fun! - Paddy. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Official IRC channel for Python?
I saw bad guys on IRC a few days ago, but it was not a problem because Ignore user function in IRC client makes his/her messages invisible. BTW,who's the maintainer of the channel? On 27 Feb 2008 11:34:54 -0800, Paul Rubin http://phr.cx@nospam.invalid wrote: Guilherme Polo [EMAIL PROTECTED] writes: I can join #perl, #php, #ruby, #mysql, #postgres without registration. What advantage does it have? and the advantage really worth? The direct benefit is a probability of having less spam, and things like that. I don't remember ever seeing irc spam on freenode. I see it once in a while on undernet. This is a non-problem. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Official IRC channel for Python?
You can't join #python on freenode without identifying with nickserv first. Why is that? I can join #perl, #php, #ruby, #mysql, #postgres without registration. What advantage does it have? and the advantage really worth? If #python were the developer's room, I'd say it's reasonable, but that's not the case here. -- http://mail.python.org/mailman/listinfo/python-list
Official IRC channel for Python?
Howdy, I was wondering if there's official IRC channel for Python. I tried #python irc.freenode.net and irc.openproject.net with no luck. Could you please give me some suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: Official IRC channel for Python?
Really? maybe I'm been blocked from it... thanks. On 23 Feb 2008 20:37:42 -0800, Paul Rubin http://phr.cx@nospam.invalid wrote: js [EMAIL PROTECTED] writes: I tried #python irc.freenode.net That has always worked for me. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Official IRC channel for Python?
No. Actually, i'm very new to IRC. On Sun, Feb 24, 2008 at 2:55 PM, Steve Holden [EMAIL PROTECTED] wrote: js wrote: Really? maybe I'm been blocked from it... thanks. Currently 479 users. Have you been blocked from many channels? regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there any Generic RSS/ATOM generator in Python?
Trivial? More than XML::Atom::Feed? http://search.cpan.org/~miyagawa/XML-Atom-0.28/lib/XML/Atom/Feed.pm On 2/14/08, Torsten Bronger [EMAIL PROTECTED] wrote: Hallöchen! Terran Melconian writes: On 2008-02-11, js [EMAIL PROTECTED] wrote: Is there any de-fact standard RSS/ATOM generator? (especially, I'd like to create Atom's) Do I have to do it myself from scratch? I looked into similar issues about six months ago. My conclusion was that generally XML generation libraries (unlike parsers) don't get written, because there's little enough to them that it isn't seen as worth doing, and that accepted practice is to just do it yourself. Maybe I understand you wrongly but there *is* a general XML generator with ElementTree. I wouldn't generate XML directly but using ElementTree to generate Atom. I did it myself three months ago and it was really trivial. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [EMAIL PROTECTED] (See http://ime.webhop.org for further contact info.) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there any Generic RSS/ATOM generator in Python?
Great... I guess I should have learned more about ElementTree. In anyway, Thanks all. You all convinced me, really. On 2/14/08, Stefan Behnel [EMAIL PROTECTED] wrote: Torsten Bronger wrote: js writes: Trivial? More than XML::Atom::Feed? http://search.cpan.org/~miyagawa/XML-Atom-0.28/lib/XML/Atom/Feed.pm Excerpt from my code: root = ElementTree.Element(feed, xmlns=http://www.w3.org/2005/Atom;) ElementTree.SubElement(root, id).text = self.id ElementTree.SubElement(root, title).text = self.title ElementTree.SubElement(root, updated).text = format_time(self.updated) Look at the bottom of this page for an RSS example using the E factory: http://effbot.org/zone/element-builder.htm I find it much more readable than the above code, especially if you use the version that comes with lxml.objectify, which has better support for namespaces and data types: http://codespeak.net/lxml/objectify.html#tree-generation-with-the-e-factory Stefan -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Is there any Generic RSS/ATOM generator in Python?
Hi, I'm looking for RSS/ATOM generator I can use in Python. I searched on pypi and the other places but I couldn't find any options on this. (I found many parsers, though) Is there any de-fact standard RSS/ATOM generator? (especially, I'd like to create Atom's) Do I have to do it myself from scratch? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
TheSchwartz in Python?
Hi, I'm looking for a job queue manager in Python, like TheSchwartz.[1]. I found there's TheSchawrtz server, RPC server powered by Gearman, to which Python/Ruby can connect [2], but setting up two languages env is a little cumbersome to me. Is there any alternative to that in Python? The requirement is * Store job queue in disk, not memory * Easy to set up * 100% Python Any pointers would be appliciated. Thanks. [1] http://search.cpan.org/~bradfitz/TheSchwartz-1.04/lib/TheSchwartz.pm [2] http://brad.livejournal.com/2332359.html -- http://mail.python.org/mailman/listinfo/python-list
Re: TheSchwartz in Python?
Cool, but sched saves job in memory... cron can't be an option. It's just a scheduler not a job queue. On Feb 7, 2008 1:36 AM, Larry Bates [EMAIL PROTECTED] wrote: js wrote: Hi, I'm looking for a job queue manager in Python, like TheSchwartz.[1]. I found there's TheSchawrtz server, RPC server powered by Gearman, to which Python/Ruby can connect [2], but setting up two languages env is a little cumbersome to me. Is there any alternative to that in Python? The requirement is * Store job queue in disk, not memory * Easy to set up * 100% Python Any pointers would be appliciated. Thanks. [1] http://search.cpan.org/~bradfitz/TheSchwartz-1.04/lib/TheSchwartz.pm [2] http://brad.livejournal.com/2332359.html Are you sure CRON won't do the job for you. If not, then you may want to at least take a look at Python's sched module (if you haven't already). -Larry -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Why the HELL has nobody answered my question !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
And why the HELL people prefer answering this kind of question to normal ones? (Including me...) On Jan 31, 2008 9:40 AM, Blubaugh, David A. [EMAIL PROTECTED] wrote: I do not understand why no one has answered the following question: Has anybody worked with Gene Expression Programming David Blubaugh -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, January 30, 2008 6:10 PM To: python-list@python.org Subject: Python-list Digest, Vol 52, Issue 437 Send Python-list mailing list submissions to python-list@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Python-list digest... This e-mail transmission contains information that is confidential and may be privileged. It is intended only for the addressee(s) named above. If you receive this e-mail in error, please do not read, copy or disseminate it in any manner. If you are not the intended recipient, any disclosure, copying, distribution or use of the contents of this information is prohibited. Please reply to the message immediately by informing the sender that the message was misdirected. After replying, please erase it from your computer system. Your assistance in correcting this error is appreciated. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib supports javascript
AFAIK, nothing. How abount letting a browser do it? By using pamie [1] or selenium, you can drive a browser from python. [1] http://pamie.sourceforge.net/ On Feb 2, 2008 11:07 AM, J. Peng [EMAIL PROTECTED] wrote: hello, Which useragent lib supports javascript? I know something about these libs: urllib,urllib2,cookielib,httplib But I'm not sure which one of them can support javascript scripts. Thanks! -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for web software in Python.
http://wiki.python.org/moin/WebApplications?highlight=%28%28PythonWikiEngines%29%29 Hope this helps On 9/18/07, Kevin Ar18 [EMAIL PROTECTED] wrote: Are any of the following pieces of web software available in Python (under a non-copyleft license like BSD or MIT or Python license)? Mailing list - with web accessable archive and list maintenance. Source control Wiki System Again, only non-copyleft licenses like MIT, BSD, or public domain. Or would I be better off with PHP? BTW, does anyone know where that project is that was working on a forum made with Python? _ More photos; more messages; more whatever – Get MORE with Windows Live™ Hotmail(r). NOW with 5GB storage. http://imagine-windowslive.com/hotmail/?locale=en-usocid=TXT_TAGHM_migration_HM_mini_5G_0907 -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: A short question about non-ascii characters in list
Thank you for your quick reply. It's intentional. __str__ of a list uses the __repr__ of its elements. This helps reduce confusion (e.g., between ['a', 'b, c'] and ['a, b', 'c']). That's make sence, but it's also true that sometimes we want to see the contents of a list in pretty format. So for now I need to write and use crappy mylist like this. class mylist(list): def __str__(self): return '[' + ', '.join(self) + ']' l = mylist([uäöü, uäöü, uäöü]) print unicode(l) very ugly, but just works. -- http://mail.python.org/mailman/listinfo/python-list
A short question about non-ascii characters in list
print uäöü äöü print [uäöü] [u'\xe4\xf6\xfc'] Python seems to treat non-ASCII chars in a list differently from the one in the outside of a list. I think this behavior is so inconvenient and actually makes debugging work harder. Is this an intentional? Is there any doc discussing about this? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to join array of integers?
print ''.join([str(i) for i in [1,2,3]]) On 9/15/07, Summercool [EMAIL PROTECTED] wrote: i think in Ruby, if you have an array (or list) of integers foo = [1, 2, 3] you can use foo.join(,) to join them into a string 1,2,3 in Python... is the method to use ,.join() ? but then it must take a list of strings... not integers... any fast method? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get headers in urllib2 response
How about using httplib? http://docs.python.org/lib/httplib-examples.html HTTPResponse has getheaders() method, too. On 9/15/07, Johny [EMAIL PROTECTED] wrote: Can anyone provide an example how to find out the return code and header from an urllib2 request? For example response = urllib2.urlopen('http://www.google.com').read().strip() provides data but I do not know if the return code was 200 or different. Thanks -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RFC-3986 or 2396 implementation in Python?
Hi list. Is there any module that is compatible with RFC-3986 or 2396, which is like Perl's URI module(http://search.cpan.org/~gaas/URI-1.35/URI.pm)? I like to normalize lots of URIs I've got in my database to make them all unique ones. Thank you in advance. -- http://mail.python.org/mailman/listinfo/python-list
Encryption recommendation
Can someone help me find the proper way to do AES encryption/decryption using Python? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
How do you htmlentities in Python
Hi list. If I'm not mistaken, in python, there's no standard library to convert html entities, like amp; or gt; into their applicable characters. htmlentitydefs provides maps that helps this conversion, but it's not a function so you have to write your own function make use of htmlentitydefs, probably using regex or something. To me this seemed odd because python is known as 'Batteries Included' language. So my questions are 1. Why doesn't python have/need entity encoding/decoding? 2. Is there any idiom to do entity encode/decode in python? Thank you in advance... -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you htmlentities in Python
Thanks you Matimus. That's exactly what I'm looking for! Easy, clean and customizable. I love python :) On 6/5/07, Matimus [EMAIL PROTECTED] wrote: On Jun 4, 6:31 am, js [EMAIL PROTECTED] wrote: Hi list. If I'm not mistaken, in python, there's no standard library to convert html entities, like amp; or gt; into their applicable characters. htmlentitydefs provides maps that helps this conversion, but it's not a function so you have to write your own function make use of htmlentitydefs, probably using regex or something. To me this seemed odd because python is known as 'Batteries Included' language. So my questions are 1. Why doesn't python have/need entity encoding/decoding? 2. Is there any idiom to do entity encode/decode in python? Thank you in advance. I think this is the standard idiom: import xml.sax.saxutils as saxutils saxutils.escape() 'amp;' saxutils.unescape(gt;) '' saxutils.unescape(A bunch of text with entities: amp; gt; lt;) 'A bunch of text with entities: ' Notice there is an optional parameter (a dict) that can be used to define additional entities as well. Matt -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: howto check does module 'asdf' exist? (is available for import)
Why not just use try? Trying to import a module is a python idiom. http://www.diveintopython.org/file_handling/index.html On 21 May 2007 06:17:16 -0700, dmitrey [EMAIL PROTECTED] wrote: howto check does module 'asdf' exist (is available for import) or no? (without try/cache of course) Thx in advance, D. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Closing socket file descriptors
Hello, Yang. You're not supposed to use os.open there. See the doc at http://docs.python.org/lib/os-fd-ops.html Is there any reason you want to use os.close? On 20 May 2007 04:26:12 GMT, Yang [EMAIL PROTECTED] wrote: Hi, I'm experiencing a problem when trying to close the file descriptor for a socket, creating another socket, and then closing the file descriptor for that second socket. I can't tell if my issue is about Python or POSIX. In the following, the first time through, everything works. On the second connection, though, the same file descriptor as the first connection may be re-used, but for some reason, trying to do os.read/close on that file descriptor will cause an error. Thanks in advance for any help on why this problem is occurring and/or how to resolve it (preferrably, I can continue to use file descriptors instead of resorting to socket.recv/socket.close). def handle( s ): print id(s), s print os.read( s.fileno(), 4096 ) # s.recv(4096) os.close( s.fileno() ) # s.close() svr = socket.socket() svr.bind( ( 'localhost', 8003 ) ) svr.listen( 1 ) while True: print 'accepting' s,_ = svr.accept() handle( s ) # Traceback (most recent call last): # File ./normal_server_close_error.py, line 25, in module # handle( s ) # File ./normal_server_close_error.py, line 13, in handle # print os.read( s.fileno(), 4096 ) # s.recv(4096) # OSError: [Errno 9] Bad file descriptor -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Closing socket file descriptors
Hi Yang. Hi, thanks for your answer. Should I just use that object's close() method? Is it safe to assume that objects that have fileno() also have close()? (Statically typed interfaces would come in handy now.) I'm writing a simple asynchronous I/O framework (for learning purposes - I'm aware of the myriad such frameworks for Python), and I'm writing a wrapper around objects that can be passed into select.select(). Since select() requires objects that have fileno's, that's the only requirement I place on the wrapped object's interface, and thus why I've been using FD-based operations: I'm not sure whether objects which have fileno always have close, but I think it's always safe to use the object's close method. How about keeping the wrapped object's interface consistent in your framework? It'd make your work moch easier. -- http://mail.python.org/mailman/listinfo/python-list
Re: Popen and wget, problems
Hi Jesse. cmd_set = ['wget', '-nv', '-O dir/cpan.txt', 'http://search.span.org'] [snip] proc = Popen(cmd_set, stdout=PIPE, stderr=PIPE) wget will treat this as $ wget -nv '-O dir/cpan.txt' http://search.cpan.org; And will emit the following error because there's no pathname ' dir/cpan.txt'. (Note the pathname has a trailing space.) dir/cpan.txt: No such file or directory Replace '-O dir/cpan.txt with '-Odir/cpan.txt' or '-O', 'dir/cpan.txt' and it should work. Hope this helps -- http://mail.python.org/mailman/listinfo/python-list
file.read() returns an emtpy even if its currenet position is not at the end
Hi list. I'm writing a tail -f like program in python and I found file.read() doesn't work as I think it should. Here's the code illustrating my problem. ### #!/usr/bin/env python import os, sys filename = test.out f = open(filename, w+) f.write(Hello) f.flush() f.seek(0, 2) statinfo = os.stat(filename) print file size: %d % statinfo.st_size print position : %d % f.tell() line = f.read() print line : [%s] % line # Writing the same file using another fd f2 = open(filename, a+) f2.write(World) f2.flush() f2.close() statinfo = os.stat(filename) print file size: %d % statinfo.st_size print position : %d % f.tell() line = f.read() # read() returns emtpy!! readlines?() works ok ### Running the above, I got the following. ### file size: 5 position : 5 line : [] file size: 10 position : 5 ### So my question is why the second f.read() returns an emtpy? From tell() and its st_size I'm sure that file descriptor is not at the EOF and read()'s doc says An empty string is returned when EOF is encountered immediately. Using readline() or readlines() instead of read() works great though. I'm using Python 2.4.3 on OS X. Probably I'm missing something but I could't figure out. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: file.read() returns an emtpy even if its currenet position is not at the end
Thank you for reply. I've just found the bug report on this. http://sourceforge.net/tracker/index.php?func=detailaid=1523853group_id=5470atid=105470 Nobody seems to be working on this, though. On 22 Apr 2007 14:41:29 -0700, Alberto Valverde [EMAIL PROTECTED] wrote: On Apr 22, 6:51 pm, js [EMAIL PROTECTED] wrote: Hi list. I'm writing a tail -f like program in python and I found file.read() doesn't work as I think it should. Here's the code illustrating my problem. ### #!/usr/bin/env python import os, sys filename = test.out f = open(filename, w+) f.write(Hello) f.flush() f.seek(0, 2) statinfo = os.stat(filename) print file size: %d % statinfo.st_size print position : %d % f.tell() line = f.read() print line : [%s] % line # Writing the same file using another fd f2 = open(filename, a+) f2.write(World) f2.flush() f2.close() statinfo = os.stat(filename) print file size: %d % statinfo.st_size print position : %d % f.tell() line = f.read() # read() returns emtpy!! readlines?() works ok ### Running the above, I got the following. ### file size: 5 position : 5 line : [] file size: 10 position : 5 ### So my question is why the second f.read() returns an emtpy?From tell() and its st_size I'm sure that file descriptor is not at the EOF and read()'s doc says An empty string is returned when EOF is encountered immediately. Using readline() or readlines() instead of read() works great though. I'm using Python 2.4.3 on OS X. Probably I'm missing something but I could't figure out. Thanks in advance. I've hit into the same issue recently when implementing more or less the same thing and found that doing f.seek(f.tell()) on the file object when empty strings start to come out allows you to continue read()ing after hitting EOF if the file grows again. I finally dropped the hack and used readline instead since it made me a little bit uneasy though... Alberto -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing Python 2.4.4 on OSX
The only way you can do is rermove python2.4.4's files manually. I suggest you to use MacPorts or Fink. With MacPort, you can uninstall python2.4 by doing $ port uninstall python24 And Installation is $ port install python25 On 24 Mar 2007 10:30:28 -0700, Robert Hicks [EMAIL PROTECTED] wrote: I want to upgrade to 2.5 but I don't see any unistall instructions anywhere. Robert -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
print a ... z, A ... Z, \n' in Python
HI guys, How do you write Perl's print a ... z, A ... Z, \n' in Python In Python? A way I came up with is the following, but I'm sure this is ugly. ''.join(chr(c) for c in (range(ord('a'), ord('z')+1) + range(ord('A'), ord('Z')+1))) or crange = lambda c1, c2: [ chr(c) for c in range(ord(c1), ord(c2)+1) ] ''.join(chr(c) for c in crange('a', 'z') + crange('A', 'Z')) I want to feel The Zen of Python :) -- http://mail.python.org/mailman/listinfo/python-list
Re: print a ... z, A ... Z, \n' in Python
But note that you return the last item of the range too, and that goes against the semantic of the usual Python range/xrange, so you may want to call this function with another name. That makes sense. 100% agree with you. Maybe there are better ways to solve this problem. Maybe a way to generate (closed?) char ranges can be added to the Python standard lib. Maybe we don't want char range If string constants would be rich enough. -- http://mail.python.org/mailman/listinfo/python-list
Re: print a ... z, A ... Z, \n' in Python
I forgot to cc pythonlist... # Thanks for you quick reply. I didn't know any string constants. From Python Library reference, 4.1.1 String constants: letters The concatenation of the strings lowercase and uppercase described below. The specific value is locale-dependent, and will be updated when locale.setlocale() is called. Great... -- http://mail.python.org/mailman/listinfo/python-list
Re: print a ... z, A ... Z, \n' in Python
Maybe we don't want char range If string constants would be rich enough. But as soon as we want a string that doesn't correspond to any pre-defined constants, we're hosed. For example, there isn't a constant that would correspond to this Perl-ism: print l ... w, e ... j, L ... W, E ... J, \n; Yes, I'm certain that l ... w, e ..j will never be a constant because that doesn't mean a thing so nobody want them :) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find out if another process is using a file
How about using lock? Let writing process locks the files before writing, and unlock after the job's done. I think it'd work file in most environment. On 1/19/07, Tom Wright [EMAIL PROTECTED] wrote: I'm writing a program which reads a series of data files as they are dumped into a directory by another process. At the moment, it gets sporadic bugs when it tries to read files which are only partially written. I'm looking for a function which will tell me if a file is opened in write-mode by another process - if it is, my program will ignore it for now and come back to it later. This needs to work on linux and windows. Mac OS would be a bonus too. An os-independent solution would be good, but I could write os-specific options and have it pick the appropriate one. Is there any way of doing this? I've drawn a blank with google so far. A nasty hack would be to use the file modification time, and wait until that's a few seconds in the past, but is there a nice solution? -- I'm at CAMbridge, not SPAMbridge -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Can I beat perl at grep-like processing speed?
Just my curiosity. Can python beats perl at speed of grep-like processing? $ wget http://www.gutenberg.org/files/7999/7999-h.zip $ unzip 7999-h.zip $ cd 7999-h $ cat *.htm bigfile $ du -h bigfile du -h bigfile 8.2Mbigfile -- grep.pl -- #!/usr/local/bin/perl open(F, 'bigfile') or die; while(F) { s/[\n\r]+$//; print $_\n if m/destroy/oi; } -- END -- -- grep.py -- #!/usr/bin/env python import re r = re.compile(r'destroy', re.IGNORECASE) for s in file('bigfile'): if r.search(s): print s.rstrip(\r\n) -- END -- $ time perl grep.pl pl.out; time python grep.py py.out real0m0.168s user0m0.149s sys 0m0.015s real0m0.450s user0m0.374s sys 0m0.068s # I used python2.5 and perl 5.8.6 -- http://mail.python.org/mailman/listinfo/python-list
Re: regular expression
I'm a great fan of regexp because it has great power and flexibility. if you don't like it I suggest you to read Mastering Regular Expressions. http://www.oreilly.com/catalog/regex3/ Yes, sometimes it might be hard to understand bites you but if you use it correctly, it works great. On 18 Dec 2006 20:25:32 -0800, Asper Faner [EMAIL PROTECTED] wrote: I seem to always have hard time understaing how this regular expression works, especially how on earth do people bring it up as part of computer programming language. Natural language processing seems not enough to explain by the way. Why no eliminate it ? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: prefix search on a large file
I did the test the way you suggested. It took not so long to realize stupid mistakes I made. Thank you. The following is the result of test with timeit(number=1) using fresh copy of the list for every iteration 0.331462860107 0.19401717186 0.186257839203 0.0762069225311 I tried my recursive-function to fix up my big-messed-list. It stops immediately because of 'RuntimeError: maximum recursion limit exceeded' I hope this trial-and-errors getting me good place... anyway, thank you. On 10/13/06, Peter Otten [EMAIL PROTECTED] wrote: js wrote: By eliminating list cloning, my function got much faster than before. I really appreciate you, John. def prefixdel_recursively2(alist): if len(alist) 2: return alist first = alist.pop(0) unneeded = [no for no, line in enumerate(alist) if line.startswith(first)] adjust=0 for i in unneeded: del alist[i+adjust] adjust -= 1 return [first] + prefixdel_recursively(alist) process stime prefixdel_stupidly : 11.9247150421 prefixdel_recursively : 14.6975700855 prefixdel_recursively2 : 0.408113956451 prefixdel_by_john: 7.60227012634 Those are suspicious results. Time it again with number=1, or a fresh copy of the data for every iteration. I also have my doubts whether sorting by length is a good idea. To take it to the extreme: what if your data file contains an empty line? Peter -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Where can I find good python code?
Hi, I've learned basics of Python and want to go to the next step. So I'm looking for good python examples I steal good techniques from. I found Python distribution itself contains some examples in Demo directory. I spent some time to read them and I think they're good but seemed not so practical to me. Any recommendations? -- http://mail.python.org/mailman/listinfo/python-list
prefix search on a large file
Hello, list. I have a list of sentence in text files that I use to filter-out some data. I managed the list so badly that now it's become literally a mess. Let's say the list has a sentence below 1. Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. 2. Python has been an important part of Google 3. important part of Google As you see sentence 2 is a subset of sentence 1 so I don't need to have sentence 1 on the list. (For some reason, it's no problem to have sentence 3. Only sentence that has the same prefix part is the one I want to remove) So I decided to clean up the list. I tried to do this simple brute-force manner, like --- sorted_list = sorted(file('thelist'), key=len) for line in sorted_list[:] unneeded = [ line2 for line2 in sorted_list[:] if line2.startswith(line) ] sorted_list = list(set(sorted_list) - (unneeded)) --- This is so slow and not so helpful because the list is so big(more than 100M bytes and has about 3 million lines) and I have more than 100 lists. I'm not familiar with algorithms/data structure and large-scale data processing, so any advice, suggestions and recommendations will be appreciated. Thank you in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: python's newbie question
http://mail.python.org/pipermail/python-list/2004-May/221591.html HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: prefix search on a large file
Thank you for the quick reply. Here're the exact code I executed. (including your code) #!/usr/bin/env python from pprint import pprint as pp data = [ 'foo bar baz', 'foo bar', 'foo', 'food', 'food', # duplicate 'xyzzy', 'plugh', 'xyzzy and plugh are magic', '', ] data_sorted_by_len = sorted(data, key=len) data_sorted_by_asc = sorted(data) print OP trial 1 input; pp(data) def prefixdel_stupidly(alist): for line in alist[:]: unneeded = [no for no, line2 in enumerate(alist[1:]) if line2.startswith(line) and line != line2] adjust=1 for i in unneeded: del alist[i+adjust] adjust -= 1 return alist def prefixdel_recursively(alist): if len(alist) 2: return alist unneeded = [no for no, line in enumerate(alist[1:]) if line.startswith(alist[0])] adjust=1 for i in unneeded: del alist[i+adjust] adjust -= 1 return [alist[0]] + prefixdel_recursively(alist[1:]) def prefixdel_by_john(alist): olist = [] for i in xrange(len(alist)-1, 0, -1): if alist[i].startswith(alist[i-1]): continue olist.append(alist[i]) olist.append(alist[0]) return olist if __name__ == '__main__': from timeit import Timer print sorted(prefixdel_stupidly(data_sorted_by_len[:])) print sorted(prefixdel_recursively(data_sorted_by_len[:])) print sorted(prefixdel_by_john(data_sorted_by_asc[:])) t = Timer(prefixdel_stupidly(data_sorted_by_len), from __main__ import prefixdel_stupidly, data_sorted_by_len) print t.timeit(number=10) t = Timer(prefixdel_recursively(data_sorted_by_len), from __main__ import prefixdel_recursively, data_sorted_by_len) print t.timeit(number=10) t = Timer(prefixdel_by_john(data_sorted_by_asc), from __main__ import prefixdel_by_john, data_sorted_by_asc) print t.timeit(number=10) The output is the following: $ python2.5 myprefixdel.py OP trial 1 input ['foo bar baz', 'foo bar', 'foo', 'food', 'food', 'xyzzy', 'plugh', 'xyzzy and plugh are magic', ''] ['foo', 'plugh', 'xyzzy', ''] ['foo', 'plugh', 'xyzzy', ''] ['foo', 'food', 'plugh', 'xyzzy', ''] 1.17837095261 1.21182584763 0.737352132797 Your code is much faster than ones I wrote but the result is a little bit different.('food' shoud be removed because 'foo' is in the list) As you pointed out, list[:] must be a big evil but without duplicating the list, the problem become much harder to solve to me. Any practical solution, anyone? -- http://mail.python.org/mailman/listinfo/python-list
Re: prefix search on a large file
By eliminating list cloning, my function got much faster than before. I really appreciate you, John. def prefixdel_recursively2(alist): if len(alist) 2: return alist first = alist.pop(0) unneeded = [no for no, line in enumerate(alist) if line.startswith(first)] adjust=0 for i in unneeded: del alist[i+adjust] adjust -= 1 return [first] + prefixdel_recursively(alist) process stime prefixdel_stupidly : 11.9247150421 prefixdel_recursively : 14.6975700855 prefixdel_recursively2 : 0.408113956451 prefixdel_by_john: 7.60227012634 -- http://mail.python.org/mailman/listinfo/python-list
Sort by domain name?
Hi list, I have a list of URL and I want to sort that list by the domain name. Here, domain name doesn't contain subdomain, or should I say, domain's part of 'www', mail, news and en should be excluded. For example, if the list was the following http://mail.google.com http://reader.google.com http://mail.yahoo.co.uk http://google.com http://mail.yahoo.com the sort's output would be http://google.com http://mail.google.com http://reader.google.com http://mail.yahoo.co.uk http://mail.yahoo.com As you can see above, I don't want to Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort by domain name?
Thanks for your quick reply. yeah, it's a hard task and unfortunately even google doesn't help me much. All I want to do is to sort out a list of url by companyname, like oreilly, ask, skype, amazon, google and so on, to find out how many company's url the list contain. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort by domain name?
Gentle reminder: is this homework? And you can expect better responses if you show youve bootstrapped yourself on the problem to some extent. Sure thing. First I tried to solve this by using a list of domain found at http://www.neuhaus.com/domaincheck/domain_list.htm I converted this to a list (in python) and tried like below look for url that endswith(domain in domains) if found: capture the left side of the domain part(tld) and save all url to a dictionary that key is the captured string to me this seems to work but stuck because this solution seems no good. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort by domain name?
On 2 Oct 2006 08:56:09 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: js: All I want to do is to sort out a list of url by companyname, like oreilly, ask, skype, amazon, google and so on, to find out how many company's url the list contain. Then if you can define a good enough list of such company names, you can just do a search of such names inside each url. Maybe you can use string method, or a RE, or create a big string with all the company names and perform a longest common subsequence search using the stdlib function. well, I think list is so large that that's impossible to create such a good company-list. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sort by domain name?
How about sorting the strings as they are reversed? urls = \ http://mail.google.com http://reader.google.com http://mail.yahoo.co.uk http://google.com http://mail.yahoo.com.split(\n) sortedList = [ su[1] for su in sorted([ (u[::-1],u) for u in urls ]) ] for url in sortedList: print url snip Close to what you are looking for, might be good enough? Great... I couldn't thought that way. Thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list