Python Ireland presents October Talks @ Seagrass Restaurant, Dublin (19:00)
Hi All, When: - 14th October 2009, 19:00 Where: -- Seagrass Restaurant, 30 South Richmond Street, Dublin 2--a short walk from Charlemont Luas stop ( map http://bit.ly/U4zNy) What: 19:00-19:30Vishal Vatsa: IPython: The awesome python shell 19:30-20:00Rory Geoghegan: Cocoa and the Python/C API 20:00-20:30Open floor: Lightning Talks Please note that the only caveat for the free venue is that we buy tapas and drink while we are there, I'm sure that's not a problem. I've booked for 20-25 people, hopefully we won't be too cramped in the room, so turn up early if you want a seat. Cheers, /// Vicky P.S.: I've never been to Seagrass, but I have read some good feedback about the function room from the Ruby Ireland event. ~~ ~~ http://irishbornchinese.com ~~ ~~ http://www.python.ie ~~ ~~ -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: cssutils 0.9.6final
what is it -- A Python package to parse and build CSS Cascading Style Sheets. (Not a renderer though!) about this release -- 0.9.6 is a full release. main changes + BUGFIX: Definition of macro for `positivenum` in cssutils profiles actually did allow nagative numbers, fixed (thanks to Jason R. Coombs) license --- cssutils is published under the LGPL version 3 or later, see http://cthedot.de/cssutils/ If you have other licensing needs please let me know. download For download options see http://cthedot.de/cssutils/ cssutils needs Python 2.4 or higher or Jython 2.5 and higher (tested with Python 2.6.3, 2.5.2, 2.4.4 and Jython 2.5.1 on Vista only) Bug reports (via Google code), comments, etc are very much appreciated! Thanks. Christof -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ChiPy October Meeting and Social meetup this Thursday at 7pm
Chicago Python User Group = This month meeting will be a social meet up open house. We will offer a tutor session where small groups will help answer questions or show each other language features. This will be a very casual meeting without a formal presentation. There may be some lighting talks, games, or sprints--whatever we feel like. Nonetheless, this will be a good time to get out of your cubical, garage, basement, coffee shop, bike, office, and hang out with really great group of Python enthusiasts. How often to do you get to ask questions one-on-one with doctors, scientists, hackers, and general pythonic people in an open and friendly setting? See you there... this will be the best meeting ever. Thanks in advance to our new venue hosts: Pumping Station: One When Thursday 7:00pm October 8th 2009 Location * Pumping Station: One * `3354 N. Elston http://maps.google.com/maps?f=qsource=embedhl=engeocode=q=3354+N.+Elston,+Chicago,+ILsll=41.942494,-87.702806sspn=0.007422,0.019312ie=UTF8hq=hnear=3354+N+Elston+Ave,+Chicago,+Illinois+60618ll=41.944106,-87.703514spn=0.033516,0.049953z=14 `_, come in the red door * food plans are currently being made, local options include Chief O'Neill's, Kuma's, Square... * RSVP to johnstoner2 ((at the domain)) gmail ((dot)) com About ChiPy --- ChiPy is a group of Chicago Python Programmers, l33t, and n00bs. Meetings are held monthly at various locations around Chicago. Also, ChiPy is a proud sponsor of many Open Source and Educational efforts in Chicago. Stay tuned to the mailing list for more info. ChiPy website: http://chipy.org ChiPy Mailing List: http://mail.python.org/mailman/listinfo/chicago ChiPy Announcement *ONLY* Mailing List: http://mail.python.org/mailman/listinfo/chipy-announce Python website: http://python.org -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Graphical nodes
Hi everyone Please could someone tell me of any libraries that you could use to make use of graphical nodes in python. Each node would hold data and properties. I am trying to achieve a similar effect, as in the application spoken about below. If you have seen an application called Nuke, by the foundry, you will see what I mean. It uses graphical nodes such as rectangles etc (similar to UML) to link operations on images together with arrows etc. I know that Nuke is made using the Qt toolkit, so maybe someone could tell me what classes were probably used to make this node based interface. Maybe the QGraphicsItem and QGraphicsScene classes? It looks cool so if anyone has any ideas on how to do something like this, it would be great. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: package import dangers
Steven D'Aprano wrote: On Tue, 06 Oct 2009 21:44:35 -0400, Dave Angel wrote: I'm surprised to see you missed this. A module doesn't generally import itself, but it's an easy mistake for a circular dependency to develop among modules. Circular imports are always a difficulty. That has nothing to do with making modules executable as scripts. I was mainly making the point that while self-importing would be rare, circular imports probably crop up fairly often. Circular imports are (nearly always) a design flaw. But until you made me think about it, I would have said that they are safe in CPython as long as all imports are at the top of the file. And as long as the script isn't part of the dependency loop. Thanks for the word always above; in trying to refute it, I thought hard enough to realize you're right. And what's better, realized it before hitting SEND. I would still say that the bugs caused in circular imports are relatively easy to spot, while the ones caused by importing the script can be quite painful to discover, if you aren't practiced at looking for them. And my practice is to keep the two separate, only using a module as a script when testing that module. The only time I've run into the problem of the dual loading of the script was in a simple program I copy-pasted from the wxPython demo code. That demo had a common module (shell) which each individual demo imported. But if you ran that common module as a script, it interactively let you choose which demo to import. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing your scripts, with plenty of re-use
I think the basically you need to write one python script name it __init__.py If you want this script may include functions to reading yours scripts from folder. Put this script in each folder and you use Margie solution . This allow you to use import from each folder . -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining python and sqlite DB into a single, executeable.
tcumming...@gmail.com wrote: The problem, is that I need the python app and the sqlite db file to exist in the same disk file. This way the app to access the data and the data are in the same file. For binaries this is possible with a little hackery. Firstly you need make the app be a zip file. The good news is that zip files store their information at the end while executables store their information at the beginning. This is how self extracting zips work - they are the extractor program followed by the zip data. You can store the sqlite database in the zip portion. Copy it out to a tempfile while running and put it back in when done and saving. The tempfile module will help with temporary files. The zipfile module works quite happily with zip files prepended with extra stuff. To get started make a zip file with dummy contents (for example a readme explaining that mail is stored within). Assuming your app is called mail.exe and the zip file is called mail.zip you just concatenate them. py2exe and several other programs can make an executable out of a Python script for you. However in some cases they use this same 'trick' of an appended zip file to store the python code so you could also just modify that. If your app is a python script and you want to distribute it that way then you can make a zip file of the python script and then you have to run it by setting the PYTHONPATH environment variable to point at the zip file. Note that once you try this you may find the operating system and/or python not being too happy about modifying what they are executing. If you are feeling really adventurous there may even be a way of following the script with the data. This is used in Unix shell scripting but the Unix shell doesn't check the whole file is syntactically correct so you can append any binary junk you want. For Python you could try something like 8 #! python python code python code SOMESPECIALMARKER sqlite file contents 8 You'd have to do some escaping of the contents or maybe just base64 encode it. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Bearophile bearophileh...@lycos.com writes: sorting, and something that's surely not bug-prone. In such situation having a 'key' argument is *better*. Such sort can be stable. Nothing stops comparison sorting from being stable. Since the rest of your post seems premised on the opposite, I hope that clears things up for you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
On Tue, 06 Oct 2009 23:20:13 -0700, Paul Rubin wrote: Bearophile bearophileh...@lycos.com writes: sorting, and something that's surely not bug-prone. In such situation having a 'key' argument is *better*. Such sort can be stable. Nothing stops comparison sorting from being stable. Since the rest of your post seems premised on the opposite, I hope that clears things up for you. I'm sure Paul already knows this, but key-based sorts are comparison sorts. There are two basic types of sorts: comparison based, where the routine has to compare items (usually with the operator), and non-comparison sorts, like bucket sort, pigeon-hole sort and radix sort. These sorts require special knowledge of the items being sorted, and don't need to compare two items. General purpose sorts like Python's sort() do, regardless of whether you pass a key function, a three-way comparison function, or something else. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
how to use WSGI applications with apache
Hi folks, I'm not quite sure where to ask this, but this is my closest guess. I've written a web service based on the newf micro-framework and it uses wsgiref.simple_server. I'm noticing that it's not returning response codes properly (after fixing a bug in newf). Instead, it just closes the TCP connection silently. I am assuming that I need to run it with a more sophisticated server, and I eventually want to run it under apache, but I can't seem to figure out how to do this. Someone once showed me how, and it was a simple line in the apache config. But I can't figure it out how to do again. Any help? -- Obama Nation | My emails do not have attachments; it's a digital signature that your mail program doesn't understand. | http://www.subspacefield.org/~travis/ If you are a spammer, please email j...@subspacefield.org to get blacklisted. pgpJzDE6lo3nC.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi victorsube...@gmail.com wrote: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] print '''Content-Type: text/html ''' db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content To answer your questions, I have no idea what eNom has done to their servers, which is where the other site was hosted (never went live), but am in the process of building on DreamHost, who seems to be a FAR better service than eNom, whom I actually had to report to the BBB and they never fixed or acknowledged very obvious problems. At any rate, the above code gets the browser to print out all the binary garbage that should translate into an image (you can look: http://13gems.com/stxresort/cart/getpic1.py?id=1x=1 ). Any more ideas would be helpful. Going to that URL, my browser now tries to render an HTML page, and I can now see the 'Content-Type: image/jpeg' string being printed into the HTML source. Have you tried removing the 'Content-Type: text/html' header, with the new triple-quoted syntax? -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: bug with itertools.groupby?
On Oct 6, 6:06 pm, Kitlbast vlad.shevche...@gmail.com wrote: grouped acc: 61 grouped acc: 64 grouped acc: 61 am I doing something wrong? sort first, then groupby. -- http://mail.python.org/mailman/listinfo/python-list
Internationalized To:'s and Cc:'s
Hello! How should I correctly construct internationalized base64'ed MIME header? The problem is that 'real name' _should_ be encoded, but the email address - should not. For example, ?utf-8?bla-bla=?= em...@domain should be the correct format, and ?utf-8?bla-bla-bla-bla=?= - incorrect. But email.Header encodes full text including address, and then local mail server append's local domain name as it is not found in encoded header in plain form. I could manually base64 encode real name, append address, put it in header without encoding, but is there any more suitable way doing it? (telling Header to leave address part of header un-encoded). -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest.TestCase and functools.partial don't seem to mix
Joel Smith wrote: Hi List, I want to make some test case classes that can have some data passed in to modify the way they behave. I can't see a straightforward manner to pass data to an __init__() method of a class derived from unittest.TestCase, or to pass data to a test function within that class. Being a C++ guy, I thought If only Python had something equivalent to boost::bind, I'd be fine, and then I discovered functools.partial. I found a post showing how to create classes using partial, and I thought I was good to go. The post I found is here: http://mail.python.org/pipermail/bangpypers/2008-December/000974.html So I adapted that code to see if it worked in the context of unittest. When I run the code, it acts like the parameter I provided with partial isn't even there. Any ideas? #!/usr/bin/python import functools import unittest class GenericWindow: def __init__(self, name, width, height, color='white'): print('Name: %s, width: %d, height: %d, color: %s' % (name, width, height, color)) class TestGenericWindow(unittest.TestCase): def __init__(self, methodName, color): unittest.TestCase.__init__(self, methodName) print('color: %s' % color) self.color = color def testit(): GenericWindow('foo', width=100, height=100, color=self.color) def suite(): s = unittest.Suite() BrownWindowTest = functools.partial(TestGenericWindow, color='brown') BlueWindowTest = functools.partial(TestGenericWindow, color='blue') GreenWindowTest = functools.partial(TestGenericWindow, color='green') s.addTest(unittest.makeSuite(BrownWindowTest)) s.addTest(unittest.makeSuite(BlueWindowTest)) s.addTest(unittest.makeSuite(GreenWindowTest)) return s if __name__ == '__main__': #unittest.main() unittest.main() That code gives the following: Traceback (most recent call last): File ./functools.partial.py, line 32, in module unittest.main() File /usr/lib/python2.6/unittest.py, line 816, in __init__ self.parseArgs(argv) File /usr/lib/python2.6/unittest.py, line 837, in parseArgs self.test = self.testLoader.loadTestsFromModule(self.module) File /usr/lib/python2.6/unittest.py, line 559, in loadTestsFromModule tests.append(self.loadTestsFromTestCase(obj)) File /usr/lib/python2.6/unittest.py, line 550, in loadTestsFromTestCase return self.suiteClass(map(testCaseClass, testCaseNames)) TypeError: __init__() takes exactly 3 arguments (2 given) Thanks for having a look, Joel By default unittest.main() looks for subclasses of unittest.TestCase and generates test cases for every method that starts with test. From that point of view suite() is just an ordinary function and will not even be called. There are a lot more problems with your code that suggest that you should carefully read the unittest documentation, and maybe even have a look at its source code. Here's what became of your code when I tried to make it run: import unittest class GenericWindow: def __init__(self, name, width, height, color='white'): print('Name: %s, width: %d, height: %d, color: %s' % (name, width, height, color)) class TestGenericWindow(unittest.TestCase): def __init__(self, methodName, color): unittest.TestCase.__init__(self, methodName) print('color: %s' % color) self.color = color def testit(self): GenericWindow('foo', width=100, height=100, color=self.color) def suite(): return unittest.TestSuite([ TestGenericWindow(testit, color=brown), TestGenericWindow(testit, color='blue'), TestGenericWindow(testit, color='green'), ]) if __name__ == '__main__': import sys argv = sys.argv[:] argv.insert(1, suite) unittest.main(argv=argv) -- http://mail.python.org/mailman/listinfo/python-list
When ‘super’ is not a good idea (was: 'Once' properties.)
Scott David Daniels scott.dani...@acm.org writes: Scott David Daniels wrote: class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 super(Initialized, class_)._init_class() Mea culpa: Here super is _not_ a good idea, […] Why is ‘super’ not a good idea here? class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 ClassBase._init_class() What makes this implementation better than the one using ‘super’? -- \“I was once walking through the forest alone and a tree fell | `\ right in front of me, and I didn't hear it.” —Steven Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use WSGI applications with apache
if you want to use it with apapache, you need mod_wsgi. If you want a pure python solution, you can use the wsgi server that comes with CherryPy. Personally, I use the wsgi server in CherrPy on my website. My site is not large by any means and the ease of deployment completely erased any benefit I would have gained from apache. On Tue, Oct 6, 2009 at 11:34 PM, travis+ml-pyt...@subspacefield.org wrote: Hi folks, I'm not quite sure where to ask this, but this is my closest guess. I've written a web service based on the newf micro-framework and it uses wsgiref.simple_server. I'm noticing that it's not returning response codes properly (after fixing a bug in newf). Instead, it just closes the TCP connection silently. I am assuming that I need to run it with a more sophisticated server, and I eventually want to run it under apache, but I can't seem to figure out how to do this. Someone once showed me how, and it was a simple line in the apache config. But I can't figure it out how to do again. Any help? -- Obama Nation | My emails do not have attachments; it's a digital signature that your mail program doesn't understand. | http://www.subspacefield.org/~travis/ If you are a spammer, please email j...@subspacefield.org to get blacklisted. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Rules governing a post about a commercial product
Hello, I am hoping to get feedback for a new, commercial platform that targets the python programming language and its users. The product is currently in a closed-beta and will be free for at least a couple months. After reviewing the only rules I could find (http://www.python.org/community/lists/), I wanted to ask one last time to make sure that such a post would be appropriate. Thanks, Ken -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use WSGI applications with apache
travis+ml-pyt...@subspacefield.org writes: Hi folks, I'm not quite sure where to ask this, but this is my closest guess. I've written a web service based on the newf micro-framework and it uses wsgiref.simple_server. I'm noticing that it's not returning response codes properly (after fixing a bug in newf). Instead, it just closes the TCP connection silently. I am assuming that I need to run it with a more sophisticated server, and I eventually want to run it under apache, but I can't seem to figure out how to do this. Someone once showed me how, and it was a simple line in the apache config. But I can't figure it out how to do again. Any help? There are all manner of things that you can configure. First you need to enable mod_wsgi - on as linux box this should be something like: a2enmod wsgi Then you need something like this inside a suitable virtualhost tag in your apache configuration files: WSGIDaemonProcess test threads=1 processes=1 maximum-requests=1 \ python-path=/dir/for/my/script WSGIProcessGroup test WSGIScriptAlias /test /dir/for/my/script/myscript.wsgi Directory /dir/for/my/script Order allow,deny Allow from all /Directory The file myscript.wsgi is a python module within which application names your wsgi application. -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
Thanks everyone for your insight. I'm going to have to agree with the paranoid desire to prevent people importing his module and then using the classes he imports from elsewhere (I'm not ruling out the lead paint theory until I can gather more evidence). It does beg the question for me. Consider the example from his code below from PyQt4 import QtGui class LauncherWidget( QtGui.QWidget ): # A Specialization of QWidget del QtGui Next time python comes across from PyQt4 import QtGui it would have to re-import the class, which seems a waste of cycles that could accumulate. In this situation, the use of __all__ is better. Plus, by using __all__ instead of del you do not have to worry about forgetting to del a class. Ryan -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use WSGI applications with apache
Chris Colbert wrote: if you want to use it with apapache, you need mod_wsgi. Or you can use mod_proxy alone or with mod_rewrite if you want to stick to the builtin webserver of cherrypy. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good idea
Ben Finney wrote: Scott David Daniels scott.dani...@acm.org writes: Scott David Daniels wrote: class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 super(Initialized, class_)._init_class() Mea culpa: Here super is _not_ a good idea, […] Why is ‘super’ not a good idea here? class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 ClassBase._init_class() What makes this implementation better than the one using ‘super’? a possible answer: - explicit implicit I'm not sure this is the correct one though :) JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Python: Text file insert to MySQL
That was great ! Now I am able to insert the values from the file. Somehow I am not able to update a specific field with all the vaues in the file. For eg: Before the update my table contents are: +---+---+ | first | last | +---+---+ | Sara | Jones | | Terry | Burns | | Filiz | Khan | +---+---+ When I do the update using the following code, --- import MySQLdb, csv, sys conn = MySQLdb.connect (host = localhost,user = usr, passwd = pass,db = db) c = conn.cursor() csv_data=csv.reader(file(b.txt)) for row in csv_data: print row c.execute(UPDATE a SET last = %s, row) #c.commit() c.close() - The table contents get updated with the last content of the input file . for eg +---+--+ | first | last | +---+--+ | Sara | c| | Terry | c| | Filiz | c| +---+--+ the contents of the b.txt file: a b c Any kind of help would be greatly appreciated. James On Tue, Oct 6, 2009 at 9:33 PM, Gerhard Häring g...@ghaering.de wrote: Schedule wrote: Hello, I am currenty using MySQL 5.1 community server and trying to import the data of the comma delimited text file into the table using python 2.6 scripts. I have installed Mysqldb 1.2.2. follwoing is my script: [...] 7. c.execute(INSERT INTO a (first, last) VALUES (%s, %s), row) [...] When I execute the statement I get the following error: [...] _mysql_exceptions.ProgrammingError: (1064, You have an error in your SQL syntax; check the manual tha t corresponds to your MySQL server version for the right syntax to use near '%s, %s), row' at line 1) You misplaced the closing quote. wrong: c.execute(INSERT INTO a (first, last) VALUES (%s, %s), row) correct: c.execute(INSERT INTO a (first, last) VALUES (%s, %s), row) -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Question about RADIXCHAR on Win32
Hi all, I have a problem with locale.RADIXCHAR, it seems this constant isn't defined on the Windows platform. Is there a way to use an equivalent of locale.RADIXCHAR ? Thank you Stephane -- Stephane Wirtel - As OpenERP is OpenSource, please feel free to contribute. Developper - Technical Lecturer OpenERP OpenERP - Tiny SPRL Chaussee de Namur, 40 B-1367 Gerompont Tel: +32.81.81.37.00 Web: http://www.tiny.be Web: http://www.openerp.com Planet: http://www.openerp.com/planet/ Blog: http://stephane-wirtel-at-tiny.blogspot.com attachment: stephane.vcf-- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Paul Rubin: Bearophile: sorting, and something that's surely not bug-prone. In such situation having a 'key' argument is *better*. Such sort can be stable. Nothing stops comparison sorting from being stable. Since the rest of your post seems premised on the opposite, I hope that clears things up for you. When I have written that post I was partially unfocused, I am sorry. What I meant is that a general sorting routine, even in D, is better to be first of all flexible. So I think it's better for the D built-in sort to be stable, because such extra invariant allows you to use the sort in more situations. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Python: Text file insert to MySQL
On Wed, Oct 7, 2009 at 1:32 PM, Schedule ssched...@gmail.com wrote: That was great ! Now I am able to insert the values from the file. Somehow I am not able to update a specific field with all the vaues in the file. For eg: [...] c.execute(UPDATE a SET last = %s, row) The database does what you say, not what you mean ;-) SQL commands like SELECT, UPDATE, DELETE work on sets. If you don't qualify the set any further, you always operate on the whole set. To restrict the set, apply a WHERE clause. I. e. Perhaps you should try a SQL tutorial before jumping into SQL + Python. Here's one: http://sqlzoo.net/ -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good idea
Jean-Michel Pichavant jeanmic...@sequans.com wrote: a possible answer: - explicit implicit I'm not sure this is the correct one though :) To me, the explicit reference to the base class violates DRY. It also means you need to manually change all such references should the base class ever change, something that using super() avoids. -- http://mail.python.org/mailman/listinfo/python-list
Re: mktime, how to handle dates before 01-01-1970 ?
Christian Heimes wrote: Ben Finney wrote: If you're committed to changing the epoch anyway, I would recommend using URL:http://en.wikipedia.org/wiki/Astronomical_year_numbering (epoch at 4004 BCE) since it is widely used to unify dates referring to human history. I prefer JDN or MJD (http://en.wikipedia.org/wiki/JDN) for dates long before or after the unix epoch. The conversion from JDN as float to a datetime object is trivial. FWIW, mxDateTime can help you with all of those: import mx.DateTime mx.DateTime.DateTimeFrom('1.1.4004 BCE') mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534a46a2f0 mx.DateTime.DateTimeFrom('1.1.4004 BCE').jdn 258994.5 mx.DateTime.DateTimeFromJDN(258994.5) mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534aeb72f0 mx.DateTime.DateTimeFrom('1.1.4004 BCE').mjd -2141006.0 mx.DateTime.DateTimeFromMJD(-2141006.0) mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534a46a2f0 The supported date range is limited by the number of days that fit into a C long. Should be enough for most use cases :-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 07 2009) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: mktime, how to handle dates before 01-01-1970 ?
M.-A. Lemburg schrieb: Christian Heimes wrote: Ben Finney wrote: If you're committed to changing the epoch anyway, I would recommend using URL:http://en.wikipedia.org/wiki/Astronomical_year_numbering (epoch at 4004 BCE) since it is widely used to unify dates referring to human history. I prefer JDN or MJD (http://en.wikipedia.org/wiki/JDN) for dates long before or after the unix epoch. The conversion from JDN as float to a datetime object is trivial. FWIW, mxDateTime can help you with all of those: import mx.DateTime mx.DateTime.DateTimeFrom('1.1.4004 BCE') mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534a46a2f0 mx.DateTime.DateTimeFrom('1.1.4004 BCE').jdn 258994.5 mx.DateTime.DateTimeFromJDN(258994.5) mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534aeb72f0 mx.DateTime.DateTimeFrom('1.1.4004 BCE').mjd -2141006.0 mx.DateTime.DateTimeFromMJD(-2141006.0) mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534a46a2f0 The supported date range is limited by the number of days that fit into a C long. Should be enough for most use cases :-) Nice ... :) I didn't know that mxDateTime has support for Julian Date. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
On Wed, Oct 7, 2009 at 2:31 AM, Ryan heni...@yahoo.com wrote: Next time python comes across from PyQt4 import QtGui it would have to re-import the class, which seems a waste of cycles that could accumulate. Python only imports modules once. The next time Python comes across that, it looks in sys.modules, sees a copy of PyQt4, and just adds a reference to the class in the existing already-loaded module. All 'del PyQt4' does is deletes a reference to that module from the local namespace. It doesn't actually delete the module or cause it to be destroyed or cleaned up, as there's always at least one additional reference to all modules in the sys.modules dictionary. There's no re-importing. In this situation, the use of __all__ is better. Plus, by using __all__ instead of del you do not have to worry about forgetting to del a class. IMHO, __all__ is almost always better because of its explicitness if you care about the API/modules/classes exposed from this module. del PyQt4 at the end of the file is completely harmless, though. It won't actually affect anything. --S -- http://mail.python.org/mailman/listinfo/python-list
data matrix python
Good morning all! I am trying to build a data matrix, but I am not able either to write to file with a proper structure nor to get the data from the matrix. I want to sort some music by similarity content, and I just have the indexes of the playlist like this: dm = numpy.array(songs) [0 4 2 1 3] [1 2 0 4 3] [2 1 0 4 3] [3 2 1 0 4] [4 0 1 2 3] Now, I want to keep the same format but with the names of the songs, something like this: Sort_dm.append(songlist(dm)) ['100.mp3\n' '10008.mp3' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n' '10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n' '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10008.mp3' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n'] But there is no way either I can access to the data... because there are strings, or save them in matrix format! I could not find anything in the documentation about this! any hint would be very welcome! thank you for your time! Best regards, Bea Mora This message was sent using IMP, the Internet Messaging Program. -- http://mail.python.org/mailman/listinfo/python-list
Python book similar to Enterprise Recipes with Ruby and Rails
Hi Is there a python book that resemble this http://www.amazon.com/Enterprise-Recipes-Ruby-Rails-Schmidt/dp/1934356239/ref=sr_1_1?ie=UTF8s=booksqid=1254914183sr=8-1-spell Also is there a active record version or port of Python ? regards -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Bearophile bearophileh...@lycos.com writes: What I meant is that a general sorting routine, even in D, is better to be first of all flexible. So I think it's better for the D built-in sort to be stable, because such extra invariant allows you to use the sort in more situations. Note that stable sort has additional memory requirements. In situations where you don't need stability, but do need memory-efficient in-place sorting, an unstable sort might well be preferred. This is why libraries such as C++'s STL offer both. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
I took out the line in question (with text/html). Now it prints to screen the url. It did that before. Strange. Any other ideas? TIA, V On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury rami.chowdh...@gmail.comwrote: On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi victorsube...@gmail.com wrote: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] print '''Content-Type: text/html ''' db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content To answer your questions, I have no idea what eNom has done to their servers, which is where the other site was hosted (never went live), but am in the process of building on DreamHost, who seems to be a FAR better service than eNom, whom I actually had to report to the BBB and they never fixed or acknowledged very obvious problems. At any rate, the above code gets the browser to print out all the binary garbage that should translate into an image (you can look: http://13gems.com/stxresort/cart/getpic1.py?id=1x=1 ). Any more ideas would be helpful. Going to that URL, my browser now tries to render an HTML page, and I can now see the 'Content-Type: image/jpeg' string being printed into the HTML source. Have you tried removing the 'Content-Type: text/html' header, with the new triple-quoted syntax? -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good id ea
alex23 wrote: Jean-Michel Pichavant jeanmic...@sequans.com wrote: a possible answer: - explicit implicit I'm not sure this is the correct one though :) To me, the explicit reference to the base class violates DRY. It also means you need to manually change all such references should the base class ever change, something that using super() avoids. I found the correct answer (http://www.artima.com/weblogs/viewpost.jsp?thread=236275) super is perhaps the trickiest Python construct: this series aims to unveil its secrets Having established that super cannot return the mythical superclass, we may ask ourselves what the hell it is returning ;) The truth is that super returns proxy objects.Informally speaking, a proxy is an object with the ability to dispatch to methods of other objects via delegation. Technically, super is a class overriding the __getattribute__ method. Instances of super are proxy objects providing access to the methods in the MRO. Jean-Michel -- http://mail.python.org/mailman/listinfo/python-list
Rules regarding a post about a commercial product
Hello, I am hoping to get feedback for a new, commercial platform that targets the python programming language and its users. The product is currently in a closed-beta and will be free for at least a couple months. After reviewing the only rules I could find (http://www.python.org/community/lists/), I wanted to ask one last time to make sure that such a post would be appropriate. Thanks, Ken -- http://mail.python.org/mailman/listinfo/python-list
AES decrypting in Python
Hi, I am working on a project where I need to decrypt some data that has been encrypted with AES. It looks like M2Crypto is the module of choice for these sorts of things, but I cannot figure out how to do this stuff from the docs. I have the following PHP code that needs to be translated into Python: $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data,MCRYPT_MODE_ECB, $iv),\0); I can't find a method in M2Crypto that gets the initialization vector size. I found the right method in the tests, which appears to be EVP.Cipher. So I would assume, I would need to do something like: EVP.Cipher(alg=aes_256_ecb, key=SomeKey, iv=SomeIV, op=dec, padding=False) I don't really see where I pass the data that needs the decrypting though. Can someone shed some light on this? Thanks, Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Hrvoje Niksic: Note that stable sort has additional memory requirements. In situations where you don't need stability, but do need memory-efficient in-place sorting, an unstable sort might well be preferred. This is why libraries such as C++'s STL offer both. There are stable sorts that need no additional memory. In a largish program written in a general-purpose multi-level language, like D (this is probably true for C++ too), often 80% of the code takes a very little time to run. Such code may need to process few small arrays, or small data sets, or to manage the GUI, etc. So optimizing those parts of the code for performance (both in memory used and CPU cycles used) is stupid. What you want in such large parts of the code is: - to write code quickly - to have code that's short, readable, easy to fix, and most important of all that is the less bug-prone as possible. So what you need in such large parts of the code is something that's very flexible and safe, even if it's not top performance (both in memory and CPU). This is why for example in D there are built-in associative arrays, that have a handy syntax, built-in methods, and they are never O(n^2), even if they are not the most efficient ones where you need max performance, or where you need minimal memory used, or where you need to perform unusual operations. Such built-ins are useful to reduce both code length and bug count, because they are quite safe and easy to use. Stable sorts are a little safer, because they don't scramble your data in certain ways, so they can be used in more situations. This is why having the Timsort in Python is good. When you run profile the D code and you see your program uses too much RAM or wastes too much time in the built-in sort, then you can switch to using special sorts from the std lib. You can even write your own hash or sort for special situations (and you don't have to drop down to use another language for that, you keep using the same, even if you may want to change your programming stile, and use a more C-like style, with no dynamic allocations, some bit twidding, pointers, more structs, 16 bit integers, unsigned integers, unions, compiler intrinsics, even inlined assembly that uses SSE3, etc). In normal code you may want to adopt a more Java-like programming style, or templates, or even using a large library I have written, you may program it almost as a curious Python-like, with lazyness too. This is why I think the built-in sort has to be flexible, because you are supposed to use it most of the times, and most of the times you don't need top performance. Different parts of a program have to be optimized for different things, computer performance, or programmer performance. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: mktime, how to handle dates before 01-01-1970 ?
Christian Heimes wrote: M.-A. Lemburg schrieb: Christian Heimes wrote: Ben Finney wrote: If you're committed to changing the epoch anyway, I would recommend using URL:http://en.wikipedia.org/wiki/Astronomical_year_numbering (epoch at 4004 BCE) since it is widely used to unify dates referring to human history. I prefer JDN or MJD (http://en.wikipedia.org/wiki/JDN) for dates long before or after the unix epoch. The conversion from JDN as float to a datetime object is trivial. FWIW, mxDateTime can help you with all of those: import mx.DateTime mx.DateTime.DateTimeFrom('1.1.4004 BCE') mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534a46a2f0 mx.DateTime.DateTimeFrom('1.1.4004 BCE').jdn 258994.5 mx.DateTime.DateTimeFromJDN(258994.5) mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534aeb72f0 mx.DateTime.DateTimeFrom('1.1.4004 BCE').mjd -2141006.0 mx.DateTime.DateTimeFromMJD(-2141006.0) mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534a46a2f0 The supported date range is limited by the number of days that fit into a C long. Should be enough for most use cases :-) Nice ... :) I didn't know that mxDateTime has support for Julian Date. It also implements the TJD that's sometimes used in the US (the NIST definition of it): mx.DateTime.DateTimeFrom('1.1.4004 BCE').tjd -1006.0 mx.DateTime.DateTimeFrom('1.1.4004 BCE').tjd_myriad 26 mx.DateTime.DateTimeFromTJD(-1006.0, 26) mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b81d4a58558 And has support for the Julian calendar: mx.DateTime.JulianDateTime(1752, 9, 2).Gregorian() mx.DateTime.DateTime object for '1752-09-13 00:00:00.00' at 2b81d4a6eb88 which is sometimes handy for historical dates: http://en.wikipedia.org/wiki/Julian_calendar -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 07 2009) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: unittest.TestCase and functools.partial don't seem to mix
En Tue, 06 Oct 2009 18:01:34 -0300, Joel Smith js-pythonl...@jk1.net escribió: Gabriel Genellina wrote: Note that you don't *have* to use partial in this case, as you're building the suite yourself. Just create the TestCase instances manually: suite = unittest.TestSuite([ TestGenericWindow('testit', 'brown'), TestGenericWindow('testit', 'blue'), TestGenericWindow('testit', 'green') ]) unittest.TextTestRunner().run(suite) Perfect! This is exactly what I needed. For some reason, I didn't understand that I could construct my TestCase objects directly... I thought that I had to allow the unittest framework to construct them for me. This is straightforward, and does exactly what I need. You're not alone :) The unittest design is rather convoluted, probably because it aims to mimic the jUnit design as closely as possible, with all its javaism and unpythonicity. I don't think one could understand how to use the framework just by reading the package documentation; more background info is needed. The Dive into Python book contains a chapter on this topic. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
En Tue, 06 Oct 2009 17:26:19 -0300, Victor Subervi victorsube...@gmail.com escribió: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: That's still wrong. The output should be: - a line containing Content-Type: image/jpeg - a blank line (no more!) - the actual image data A Content-Type of text/html is just *wrong* for an image... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
Gabriel, don't you remember fighting this through with me a year or two ago? It worked just fine back then, but now the same code doesn't work! Go figure! We've tweaked it to this point: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content Your comments are very much appreciated. TIA, V On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina gagsl-...@yahoo.com.arwrote: En Tue, 06 Oct 2009 17:26:19 -0300, Victor Subervi victorsube...@gmail.com escribió: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: That's still wrong. The output should be: - a line containing Content-Type: image/jpeg - a blank line (no more!) - the actual image data A Content-Type of text/html is just *wrong* for an image... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi victorsube...@gmail.com wrote: I took out the line in question (with text/html). Now it prints to screen the url. It did that before. Strange. Any other ideas? TIA, V Looking at the output, it seems the reason for this (for me) is that Firefox can't find the image or any alt text for it, so it's just using the image URL. Are you certain the image data (i.e. the 'content' string) is correct, and being encoded correctly in the output? On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury rami.chowdh...@gmail.comwrote: On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi victorsube...@gmail.com wrote: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] print '''Content-Type: text/html ''' db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content To answer your questions, I have no idea what eNom has done to their servers, which is where the other site was hosted (never went live), but am in the process of building on DreamHost, who seems to be a FAR better service than eNom, whom I actually had to report to the BBB and they never fixed or acknowledged very obvious problems. At any rate, the above code gets the browser to print out all the binary garbage that should translate into an image (you can look: http://13gems.com/stxresort/cart/getpic1.py?id=1x=1 ). Any more ideas would be helpful. Going to that URL, my browser now tries to render an HTML page, and I can now see the 'Content-Type: image/jpeg' string being printed into the HTML source. Have you tried removing the 'Content-Type: text/html' header, with the new triple-quoted syntax? -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: AES decrypting in Python
Mike Driscoll wrote: Hi, I am working on a project where I need to decrypt some data that has been encrypted with AES. It looks like M2Crypto is the module of choice for these sorts of things, but I cannot figure out how to do this stuff from the docs. I have the following PHP code that needs to be translated into Python: $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data,MCRYPT_MODE_ECB, $iv),\0); I can't find a method in M2Crypto that gets the initialization vector size. I found the right method in the tests, which appears to be EVP.Cipher. So I would assume, I would need to do something like: EVP.Cipher(alg=aes_256_ecb, key=SomeKey, iv=SomeIV, op=dec, padding=False) I don't really see where I pass the data that needs the decrypting though. Can someone shed some light on this? If you just need AES, you're probably better of with pycrypto: http://www.amk.ca/python/code/crypto Still, to answer your question: AES uses blocks of 16 bytes (256 bits) each, so the IV-size is always 16 bytes. BTW: I'm not sure what the PHP code is trying to do ... ECB mode doesn't use the IV at all. It's only used for chained modes and there you include the IV in the encrypted data (usually at the beginning), since you need it for decryption. The PHP code apparently generates a random IV block for decryption. This would never work in e.g. CBC mode. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 07 2009) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good idea
Ben Finney wrote: Scott David Daniels wrote: ... class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 super(Initialized, class_)._init_class() Mea culpa: Here super is _not_ a good idea, […] Why is ‘super’ not a good idea here? class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 ClassBase._init_class() What makes this implementation better than the one using ‘super’? Well, it doesn't end with an error message :-) The reason for the error message is that super is built for instance methods, not class methods. You'd need a class method style super to get to the next superclass in the __mro__ with an '_init_class' method. Personally I don't see the need. You could of course do it like this: class MyOtherType(type): def __new__(class_, name, bases, dct): result = type.__new__(class_, name, bases, dct) result()._init_class() return result class OtherClassBase(object): __metaclass__ = MyOtherType def _init_class(self): print 'initializing class' class Initialized(OtherClassBase): def _init_class(self): self.__class__.a, self.__class__.b = 1, 2 super(Initialized, self)._init_class() This code is a problem because the point of this exercise is to do initialization _before_ building an instance (think of building tables used in __init__). Before you decide that super should simply check if the second arg to super is a subclass of the first arg, and operate differently in that case (as my first code naively did), realize there is a problem. I saw the problem in trying the code, and simply tacked in the proper parent call and ran off to work. Think about the fact that classes are now objects as well; a class itself has a class (type or in these classes MyType or MyOtherType) with its own needs for super, and the combination would be a mess. I'm certain you'd get inadvertent switches across the two subtype hierarchies, but that belief may just be my fear of the inevitable testing and debugging issues such an implementation would require. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Rules regarding a post about a commercial product
Ken Elkabany wrote: I am hoping to get feedback for a new, commercial platform that targets the python programming language and its users. The product is currently in a closed-beta and will be free for at least a couple months. After reviewing the only rules I could find (http://www.python.org/community/lists/), I wanted to ask one last time to make sure that such a post would be appropriate. You might want to go for comp.lang.python.announce I am certain you are welcome if you don't spray the area with ads, see, for example, ActiveState's behavior. I trust that if you so start making real money from it, like ActiveState you'll help out the community that is giving you its support. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Rules regarding a post about a commercial product
On 2009-10-07 03:59 AM, Ken Elkabany wrote: Hello, I am hoping to get feedback for a new, commercial platform that targets the python programming language and its users. The product is currently in a closed-beta and will be free for at least a couple months. After reviewing the only rules I could find (http://www.python.org/community/lists/), I wanted to ask one last time to make sure that such a post would be appropriate. Yes, announcements involving relevant commercial products are welcome within limits. For example, one announcement per release is perfectly acceptable. Multiple announcements per release are spam (e.g. Only five more days left for our special promotion!!! Only four more days ...!!!, etc.). I suspect what you have in mind is fine. -- 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: data matrix python
On 2009-10-07 05:46 AM, bbarb...@inescporto.pt wrote: Good morning all! I am trying to build a data matrix, but I am not able either to write to file with a proper structure nor to get the data from the matrix. I want to sort some music by similarity content, and I just have the indexes of the playlist like this: dm = numpy.array(songs) [0 4 2 1 3] [1 2 0 4 3] [2 1 0 4 3] [3 2 1 0 4] [4 0 1 2 3] Now, I want to keep the same format but with the names of the songs, something like this: Sort_dm.append(songlist(dm)) ['100.mp3\n' '10008.mp3' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n' '10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n' '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10008.mp3' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n'] But there is no way either I can access to the data... because there are strings, or save them in matrix format! I could not find anything in the documentation about this! any hint would be very welcome! thank you for your time! You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists However, you will need to show a little more code for us to understand what you are trying to do. Show us the code that you have, show us what results you get (copy-and-paste, please), and tell us what results you expect to get. -- 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: Q: sort's key and cmp parameters
On Tuesday 06 October 2009 02:40:46 pm Paul Rubin wrote: The problem is that if you allow to use the cmp, lot of programmers will use it straight away, not even bothering to know what that strange 'key' argument may be useful for. And they miss the how much handy 'key' is. Given how often we hear consenting adults as justification for any number of gaps in Python error checking, the argument above is singularly unpersuasive. Well, as long as you consider them gaps in need of a justification, of course that argument (and the one about the gaps themselves) will of course seem singularly unpersuasive. But if you see them as a feature (that may sometimes, albeit rarely, missfire), then you would have no problem with /either/ argument. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matemática y Computación, UH. http://profesores.matcom.uh.cu/~kyrie -- http://mail.python.org/mailman/listinfo/python-list
Re: AES decrypting in Python
On Oct 7, 10:04 am, M.-A. Lemburg m...@egenix.com wrote: Mike Driscoll wrote: Hi, I am working on a project where I need to decrypt some data that has been encrypted with AES. It looks like M2Crypto is the module of choice for these sorts of things, but I cannot figure out how to do this stuff from the docs. I have the following PHP code that needs to be translated into Python: $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data,MCRYPT_MODE_ECB, $iv),\0); I can't find a method in M2Crypto that gets the initialization vector size. I found the right method in the tests, which appears to be EVP.Cipher. So I would assume, I would need to do something like: EVP.Cipher(alg=aes_256_ecb, key=SomeKey, iv=SomeIV, op=dec, padding=False) I don't really see where I pass the data that needs the decrypting though. Can someone shed some light on this? If you just need AES, you're probably better of with pycrypto: http://www.amk.ca/python/code/crypto Still, to answer your question: AES uses blocks of 16 bytes (256 bits) each, so the IV-size is always 16 bytes. BTW: I'm not sure what the PHP code is trying to do ... ECB mode doesn't use the IV at all. It's only used for chained modes and there you include the IV in the encrypted data (usually at the beginning), since you need it for decryption. The PHP code apparently generates a random IV block for decryption. This would never work in e.g. CBC mode. -- Marc-Andre Lemburg eGenix.com That's good to know. I had originally started with PyCrypto by following the example here: http://www.codekoala.com/blog/2009/aes-encryption-python-using-pycrypto/ Unfortunately, no matter which base64 decoding method I use, I get a padding error or in the case of b16decode, I get TypeError: Non- base16 digit found. AES decoding is something I've never done before, so I apologize for my greenness. I'll bug the guys on the pycrypto list as well. Thanks, Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run python script in emacs
On 26 sep, 17:54, devilkin devilsp...@gmail.com wrote: I'm just starting learning python, and coding inemacs. I usually splitemacswindow into two, coding in one, and run script in the other, which is not very convenient. anyone can help me with it? is there any tricks likeemacsshort cut? also please recommand someemacsplug-ins for python programming, i'm also beginner inemacs.currently i'm only using python.el. Are any plugins supply code folding and autocomplete? BTW, I'm not a english native speaker, any grammer mistakes, please correct them. :) hello, I was not so long ago in the same situation. I switch to emacs too, why ? probably because the movement is more natural than in vi (used for 12+ years), python-mode automatically starts on the machines I'm using, this is very convenient for *re-indentation* . Python could be difficult to maintain if you don't have a flexible text editor. if you want, i can suggest you some lines for the init file .emacs, in order to keep the text indented with 4 spaces, no tab at all (very important). I also suggest you to have a look on ipython shell, which is a super shell you keep side the text editor. once you discover it, you'll understand. I didn't hear for an autocompletion in emacs. but ipython has a autocompletion. It can sound weird to auto-complete outside your editor, but I like it. you can test little code snippets in ipython, discover the documentation and methods, and try them. I discover this clever advice in http://oreilly.com/catalog/9780596515829/ currently I work with Mac (Aquamacs), and I was recently on Solaris or XP as well. PS: emacs on Mac Terminal with a french keyboard is a bit of a nightmare considering the META key...:-( Aquamacs solves this finally. Olivier -- http://mail.python.org/mailman/listinfo/python-list
ElementTree ; change namespace
Hello the list, I have question about ElementTree module, I didn't find a specific list so I post here. I hope I'm not wrong. I would like to know how to change the namespace URI of all the Element of my XML tree without changing anything else. I want that because I have to compare 2 XML trees, so I walk trought the first tree, and each time I found an element, I delete it (with the Element.remove() function) on the second tree. This way, I can see if there is remaining or lacking elements in my second tree. The problem is that my two trees may not have the same namespace, so the Element.remove() function doesn't work. That's why I want to change the namespace. Also, The Element.remove() documentation says it compares element with their identity ; what is exactly an element identity ? Thank you, Ben -- http://mail.python.org/mailman/listinfo/python-list
best vi / emacs python features
hello, * this is not a troll * which kind of help you have with your favorite editor ? personnally, I find emacs very nice, in the current state of my knowledge, when I need to reindent the code. you know how this is critical in python...:-) I don't use other python-mode features for the moment, maybe you have some advices. I used with success an Xemacs on Solaris, as well as a Aquamacs on Mac. For the vi/vim guys, explain us the best features this editor give you in your py files ! thanks, Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Queue deadlock
Felix wrote: Hello, I keep running into a deadlock in a fairly simple parallel script using Multiprocessing.Queue for sending tasks and receiving results. From the documentation I cannot figure out what is happening and none of the examples seem to cover quite what I am doing. The main code is results = mp.Queue() tasks = mp.JoinableQueue() tasks.put( (0,0) ) procs = [ mp.Process(target=work, args=(tasks, results)) for i in range (nprocs)] for p in procs: p.daemon = True p.start() tasks.join() for i in range(nprocs): tasks.put('STOP') for p in procs: p.join() res=[] while 1: try: res.append(res.get(False)) except Empty: break The function 'work' both consumes tasks adding the results to the output queue and adds new tasks to the input queue based on its result. def work(tasks, results): for task in iter(tasks.get, 'STOP'): res = calc(*task) if res: results.put(res) tasks.put((task[0], res[1])) tasks.put((res[0],task[1])) queue.task_done() This program will hang while the main process joins the workers (after all results are computed, i.e. after tasks.join() ). The workers have finished function 'work', but have not terminated yet. Calling results.cancel_join_thread as a last line in 'work' prevents the deadlocks, as does terminating the workers directly. However I am not sure why that would be needed and if it might not make me loose results. It seems to be the workers cannot finish pusing buffered results into the output queue when calling 'results.join_thread' while terminating, but why is that? I tried calling 'results.close()' before joining the workers in the main process, but it does not make a difference. Is there something I am understanding wrong about the interface? Is there a much better way to do what I am trying to do above? It think it's down to the difference between multithreading and multiprocessing. When multithreading, the threads share the same address space, so items can be passed between the threads directly. However, when multiprocessing, the processes don't share the same address space, so items need to be passed from process to process via a pipe. Unfortunately, the pipe has a limited capacity, so if a process doesn't read from one end then the pipe will eventually fill up and the sender will block. Also, a process won't terminate until it has finished writing to the pipe, and it can't be joined until it has terminated. You can therefore get into a deadlock where: * Process A won't read from the queue until it has joined process B. * The join won't succeed until process B has terminated. * Process B won't terminate until it has finished writing to the queue. * Process B can't finish writing to the queue because it's full. * The queue is full because process A isn't reading from it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
Yes it is. I have had it print to screen already, and there is data in the database. V On Wed, Oct 7, 2009 at 10:03 AM, Rami Chowdhury rami.chowdh...@gmail.comwrote: On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi victorsube...@gmail.com wrote: I took out the line in question (with text/html). Now it prints to screen the url. It did that before. Strange. Any other ideas? TIA, V Looking at the output, it seems the reason for this (for me) is that Firefox can't find the image or any alt text for it, so it's just using the image URL. Are you certain the image data (i.e. the 'content' string) is correct, and being encoded correctly in the output? On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury rami.chowdh...@gmail.com wrote: On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi victorsube...@gmail.com wrote: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] print '''Content-Type: text/html ''' db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content To answer your questions, I have no idea what eNom has done to their servers, which is where the other site was hosted (never went live), but am in the process of building on DreamHost, who seems to be a FAR better service than eNom, whom I actually had to report to the BBB and they never fixed or acknowledged very obvious problems. At any rate, the above code gets the browser to print out all the binary garbage that should translate into an image (you can look: http://13gems.com/stxresort/cart/getpic1.py?id=1x=1 ). Any more ideas would be helpful. Going to that URL, my browser now tries to render an HTML page, and I can now see the 'Content-Type: image/jpeg' string being printed into the HTML source. Have you tried removing the 'Content-Type: text/html' header, with the new triple-quoted syntax? -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
OdarR wrote: hello, * this is not a troll * which kind of help you have with your favorite editor ? personnally, I find emacs very nice, in the current state of my knowledge, when I need to reindent the code. you know how this is critical in python...:-) I don't use other python-mode features for the moment, maybe you have some advices. I used with success an Xemacs on Solaris, as well as a Aquamacs on Mac. For the vi/vim guys, explain us the best features this editor give you in your py files ! thanks, Olivier When opposing vi to emacs, there's is no possibility you get constructive and objective answer, because basically, what can do with one, you can also do it with the other. Being a vi fan, I can just tell you that emacs is for loosers, and no one will dare to challenge this. vi/emacs is like choosing between the Celtics or the Lakers, there is no reason for that, the fun part resides in being totally devoted to your choice :o) For my part I never switched to emacs cause I was tired of getting syntax error with ':w' inserted everywhere in my code. Bad habits are sticky. One feature I have that emacs don't is that I'm able to efficiently edit a file on a remote machine with vim on a terminal (without graphical interface), and I'm using it. Apart from that, both solutions are efficient. I would add that inside a company, it is a good idea to use the same editor as you can share knowledge, macro, plugins and so on. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On Oct 7, 10:44 am, Jean-Michel Pichavant jeanmic...@sequans.com wrote: OdarR wrote: hello, * this is not a troll * which kind of help you have with your favorite editor ? personnally, I find emacs very nice, in the current state of my knowledge, when I need to reindent the code. you know how this is critical in python...:-) I don't use other python-mode features for the moment, maybe you have some advices. I used with success an Xemacs on Solaris, as well as a Aquamacs on Mac. For the vi/vim guys, explain us the best features this editor give you in your py files ! thanks, Olivier Being a vi fan, I can just tell you that emacs is for loosers, and no one will dare to challenge this. I concur 100% with this statement. That said, I like how my install of VIM 'just works' with Python files, doing a good job of coloring and auto indentation. I don't like, however, how an arbitrary colon will trigger auto indentation on the next line. I'm guessing, though, that this is just an issue with my particular syntax file. Garrick -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On 7 oct, 18:44, Jean-Michel Pichavant jeanmic...@sequans.com wrote: Being a vi fan, I can just tell you that emacs is for loosers, and no one will dare to challenge this. vi is very good for newbees, I recommend it. vi/emacs is like choosing between the Celtics or the Lakers, there is no reason for that, the fun part resides in being totally devoted to your choice :o) For my part I never switched to emacs cause I was tired of getting syntax error with ':w' inserted everywhere in my code. Bad habits are sticky. just use the other symetric part of your brain. One feature I have that emacs don't is that I'm able to efficiently edit a file on a remote machine with vim on a terminal (without graphical interface), and I'm using it. Apart from that, both solutions are emacs has the same efficiency on a terminal. or maybe I don't understand your sentence. efficient. I would add that inside a company, it is a good idea to use the same editor as you can share knowledge, macro, plugins and so on. I never used macro with vi or emacs. I shared know-how for vi or emacs. I worked in companies full of talented people, open to new technologies, no issues mixing both editors. and don't speak of UltraEdit yet :) Apart of trolling which is also an activity I like, what are the features vim proposes to Python ? Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 09:38:09 -0700, Victor Subervi victorsube...@gmail.com wrote: Yes it is. I have had it print to screen already, and there is data in the database. V If you're confident that the data is correct and hasn't been corrupted, then I'm afraid I'm out of ideas. Perhaps you could try transmitting it as base64, which might make it more robust in transmission and easier to decode and find errors locally? You'd just need to change the end of your script to read: print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print print content.encode('base64') HTH, Rami On Wed, Oct 7, 2009 at 10:03 AM, Rami Chowdhury rami.chowdh...@gmail.comwrote: On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi victorsube...@gmail.com wrote: I took out the line in question (with text/html). Now it prints to screen the url. It did that before. Strange. Any other ideas? TIA, V Looking at the output, it seems the reason for this (for me) is that Firefox can't find the image or any alt text for it, so it's just using the image URL. Are you certain the image data (i.e. the 'content' string) is correct, and being encoded correctly in the output? On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury rami.chowdh...@gmail.com wrote: On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi victorsube...@gmail.com wrote: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] print '''Content-Type: text/html ''' db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content To answer your questions, I have no idea what eNom has done to their servers, which is where the other site was hosted (never went live), but am in the process of building on DreamHost, who seems to be a FAR better service than eNom, whom I actually had to report to the BBB and they never fixed or acknowledged very obvious problems. At any rate, the above code gets the browser to print out all the binary garbage that should translate into an image (you can look: http://13gems.com/stxresort/cart/getpic1.py?id=1x=1 ). Any more ideas would be helpful. Going to that URL, my browser now tries to render an HTML page, and I can now see the 'Content-Type: image/jpeg' string being printed into the HTML source. Have you tried removing the 'Content-Type: text/html' header, with the new triple-quoted syntax? -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Python 2.6.4rc1
Hello everyone. The source tarballs and Windows installers for Python 2.6.4rc1 are now available: http://www.python.org/download/releases/2.6.4/ Please download them, install them, and try to use them with your projects and environments. Let us know if you encounter any problems with them. Hopefully we can avoid the situation with 2.6.3 having such critical bugs. 2.6.4 final is planned for 18-October. Cheers, -Barry PGP.sig Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
[Hrvoje Niksic] Note that stable sort has additional memory requirements. In situations where you don't need stability, but do need memory-efficient in-place sorting, an unstable sort might well be preferred. This is why libraries such as C++'s STL offer both. FWIW, the additional memory requirements are typically a set of pointers to the objects being sorted, so the memory overhead is typically very small relative to the size of the objects being sorted. IOW, this isn't much of a consideration in most Python apps. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Queue deadlock
On Oct 7, 12:16 pm, MRAB pyt...@mrabarnett.plus.com wrote: Felix wrote: Hello, I keep running into a deadlock in a fairly simple parallel script using Multiprocessing.Queue for sending tasks and receiving results. It seems to be the workers cannot finish pusing buffered results into the output queue when calling 'results.join_thread' while terminating, but why is that? I tried calling 'results.close()' before joining the workers in the main process, but it does not make a difference. Is there something I am understanding wrong about the interface? Is there a much better way to do what I am trying to do above? You can therefore get into a deadlock where: * Process A won't read from the queue until it has joined process B. * The join won't succeed until process B has terminated. * Process B won't terminate until it has finished writing to the queue. * Process B can't finish writing to the queue because it's full. * The queue is full because process A isn't reading from it. I thought about that, but it seemed unlikely since I am not generating too many results (a few thousand small touples of int). Also I tried to deal with it by reading as many results form the queue as were available, then joining the workers, then reading again. This did not work reliably, maybe because the queue would fill up again while I start joining the individual workers. In any case the core of the problem is the following: A bunch of workers push an unknown number of results into a queue. The main process needs to collect all those results. What is the right way to implement that with multiprocessing? I tried joining the workers and then reading everything available, but obviously (see above) that does not seem to work. A dirty trick that works would be reading all results slowly and assuming no more results are comming after the queue is empty, but this is obviously unstable: while 1: try: res.append(results.get(True,LONG_TIMEOUT)) except Empty: break It could be made somewhat better by joining the workers afterwards and reading again, but another deadlock might happen. What I am doing now is having the workers push a DONE flag on the result queue when they end and reading results until all DONE flags have arrived: def work(tasks, results): for task in iter(tasks.get, 'STOP'): res = calc(*task) if res: results.put(res) tasks.put((task[0], res[1])) tasks.put((res[0],task[1])) queue.task_done() results.put('DONE') And in main: res = [] for i in range(opts.nprocs): res += list(iter(results.get,'DONE')) for p in procs: p.join() This seems to work, and as long as workers push data to the results queue in the same order as the puts happen in each process (is this guaranteed?) it should be stable. But is it the best/easiest way to do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
One feature I have that emacs don't is that I'm able to efficiently edit a file on a remote machine with vim on a terminal (without graphical interface), and I'm using it. Apart from that, both solutions are emacs has the same efficiency on a terminal. or maybe I don't understand your sentence. Perhaps this is a reference to the alt/meta/control/buckey/super key-chords that emacs is infamous for using that don't always get reliably transmitted by all terminal-emulation programs and consoles. It was one of my nudging factors towards vi (and later vim), because I occasionally used some terminal software in which alt or shift+control+alt (and other such combinations) weren't detected. Never had that problem with vi/vim. And when all else fails, I can usually fall back to ed in a pinch ;-) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
Well, since the code is automatically generated, it printed this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' Content-Encoding: base64 print print content.encode('base64') which threw this error: [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Traceback (most recent call last): [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /usr/lib64/python2.4/site-packages/mod_python/apache.py, line 299, in HandlerDispatch\n result = object(req) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /usr/lib64/python2.4/site-packages/mod_python/cgihandler.py, line 96, in handler\n imp.load_module(module_name, fd, path, desc) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /var/www/vhosts/ 13gems.com/httpdocs/stxresort/cart/getpic1.py, line 24 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Content-Encoding: base64 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: ^ [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: SyntaxError: invalid syntax Ideas? TIA, V On Wed, Oct 7, 2009 at 12:00 PM, Rami Chowdhury rami.chowdh...@gmail.comwrote: On Wed, 07 Oct 2009 09:38:09 -0700, Victor Subervi victorsube...@gmail.com wrote: Yes it is. I have had it print to screen already, and there is data in the database. V If you're confident that the data is correct and hasn't been corrupted, then I'm afraid I'm out of ideas. Perhaps you could try transmitting it as base64, which might make it more robust in transmission and easier to decode and find errors locally? You'd just need to change the end of your script to read: print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print print content.encode('base64') HTH, Rami On Wed, Oct 7, 2009 at 10:03 AM, Rami Chowdhury rami.chowdh...@gmail.com wrote: On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi victorsube...@gmail.com wrote: I took out the line in question (with text/html). Now it prints to screen the url. It did that before. Strange. Any other ideas? TIA, V Looking at the output, it seems the reason for this (for me) is that Firefox can't find the image or any alt text for it, so it's just using the image URL. Are you certain the image data (i.e. the 'content' string) is correct, and being encoded correctly in the output? On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury rami.chowdh...@gmail.com wrote: On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi victorsube...@gmail.com wrote: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] print '''Content-Type: text/html ''' db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content To answer your questions, I have no idea what eNom has done to their servers, which is where the other site was hosted (never went live), but am in the process of building on DreamHost, who seems to be a FAR better service than eNom, whom I actually had to report to the BBB and they never fixed or acknowledged very obvious problems. At any rate, the above code gets the browser to print out all the binary garbage that should translate into an image (you can look: http://13gems.com/stxresort/cart/getpic1.py?id=1x=1 ). Any more ideas would be helpful. Going to that URL, my browser now tries to render an HTML page, and I can now see the 'Content-Type: image/jpeg' string being printed into the HTML source. Have you tried removing the 'Content-Type: text/html' header, with the new
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi victorsube...@gmail.com wrote: Well, since the code is automatically generated, it printed this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' Content-Encoding: base64 print print content.encode('base64') which threw this error: [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Traceback (most recent call last): [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /usr/lib64/python2.4/site-packages/mod_python/apache.py, line 299, in HandlerDispatch\n result = object(req) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /usr/lib64/python2.4/site-packages/mod_python/cgihandler.py, line 96, in handler\n imp.load_module(module_name, fd, path, desc) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /var/www/vhosts/ 13gems.com/httpdocs/stxresort/cart/getpic1.py, line 24 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Content-Encoding: base64 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: ^ [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: SyntaxError: invalid syntax Ideas? TIA, V I'm sorry, I don't understand how the code is being auto-generated? Is there no way to place the 'Content-Encoding' header inside the triple-quoted string, where it should go? -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
Apart of trolling which is also an activity I like, what are the features vim proposes to Python ? Olivier Many, but none that you won't find with emacs, so when I'm stating it is just a matter of personal preference, I mean it :o) Vi or Emacs is the same question as straight or gay (order matters! :D). No one will come and convince you to use one or the other. Launch both of them, look at the nice and smooth visual of gvim, compare it with the ugly skin of emacs and pick your choice ! Beside from trolling, here are the feature I'm using for python: - syntax highligthts (there are hundreds of different themes, now way you can't find few you like) - auto completion of symbols - code browsing supporting tag files - (almost) smart indentation That's it JM -- http://mail.python.org/mailman/listinfo/python-list
Re: ActivePython 3.1.1.2 vs Python 3.1.1 for OSX?
PyPM is now released! http://groups.google.com/group/comp.lang.python/browse_thread/thread/e9efdedf264a3b8a On Oct 1, 4:42 am, flebber flebber.c...@gmail.com wrote: On Oct 1, 11:28 am, srid sridhar.ra...@gmail.com wrote: On Sep 30, 4:51 pm, Robert Hicks sigz...@gmail.com wrote: I am just curious which I should use. I am going to start learning Python soon. Are they comparable and I just do a eenie meenie minie moe? ActivePython is essentially same as the installers from python.org - but it also comes with additional documentation and tutorials, such as: Python FAQs A snapshot of the Python Enhancement Proposals (PEPs) (For the most recent version, refer to the PEPs on python.org .) Dive Into Python (A tutorial for programmers) Non-Programmers Tutorial For Python http://docs.activestate.com/activepython/3.1/whatsincluded.html Also note that 2.6.x is probably the best bet if you are going to use some 3rd party libraries (after you learn the basics of Python) .. because 3.x does not have many of those libraries ported yet. http://www.activestate.com/activepython/ Further, early next week - a new release of ActivePython-2.6 will be made available that will include, for the first time, a new Python package manager (PyPM) from ActiveState that makes it easier to install packages from pypi.python.org(without having to compile them yourself). This is similar to PPM from ActivePerl. -srid Thats awesome news. -- http://mail.python.org/mailman/listinfo/python-list
Re: AES decrypting in Python
Mike Driscoll wrote: EVP.Cipher(alg=aes_256_ecb, key=SomeKey, iv=SomeIV, op=dec, padding=False) I don't really see where I pass the data that needs the decrypting though. Can someone shed some light on this? Look at test_AES method in http://svn.osafoundation.org/m2crypto/trunk/tests/test_evp.py Basically EVP.Cipher returns the cipher object. You call the update update(data) method on it (you can call this many times if you have lots of data), which returns (possibly partial) result and finally call the final() method to finish, which will return the last piece of the decrypted data. You might also want to take a look at m2secret[1] which is a small library/utility built on top of M2Crypto to encrypt/decrypt stuff. By default it uses AES. [1] http://www.heikkitoivonen.net/m2secret/ -- Heikki Toivonen - http://heikkitoivonen.net -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On 7 oct, 19:29, Tim Chase python.l...@tim.thechases.com wrote: Perhaps this is a reference to the alt/meta/control/buckey/super key-chords that emacs is infamous for using that don't always get reliably transmitted by all terminal-emulation programs and consoles. It was one of my nudging factors towards vi (and later vim), because I occasionally used some terminal software in which alt or shift+control+alt (and other such combinations) weren't detected. Never had that problem with vi/vim. And when all else fails, I can usually fall back to ed in a pinch ;-) -tkc yes, this is true that emacs needs ctrl and meta key. two keys for lots of combinations :-) Like with vi when I began, I need a cheat list of keystrokes for emacs. ctrl is ok. Meta can always be used with ESC. if you really need to stay on a unknown terminal for some weeks, it is not complicated to copy/paste your favorite .emacs file (less than 10 lines is for me sufficient). It's just a matter of organization. Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
Ryan wrote: [] It does beg the question for me. Consider the example from his code below from PyQt4 import QtGui class LauncherWidget( QtGui.QWidget ): # A Specialization of QWidget del QtGui Next time python comes across from PyQt4 import QtGui it would have to re-import the class, which seems a waste of cycles that could accumulate. Errrhm, no. He is not deleting the PyQt4 module from sys.modules; he's only deleting the name QtGui from his own namespace. Next time Python comes across from PyQt4 import QtGui , it finds that the module PyQt4 already exists in sys.modules, so Python does not have to load the module again. All it has to do is bind name QtGui in the importing module to the class with the same name in the PyQt4 module. That does not take many cycles. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
My misunderstanding. Here's the new code: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print print content.encode('base64') Unfortunately, the same result of printing the url. V On Wed, Oct 7, 2009 at 12:56 PM, Rami Chowdhury rami.chowdh...@gmail.comwrote: On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi victorsube...@gmail.com wrote: Well, since the code is automatically generated, it printed this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' Content-Encoding: base64 print print content.encode('base64') which threw this error: [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Traceback (most recent call last): [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /usr/lib64/python2.4/site-packages/mod_python/apache.py, line 299, in HandlerDispatch\n result = object(req) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /usr/lib64/python2.4/site-packages/mod_python/cgihandler.py, line 96, in handler\n imp.load_module(module_name, fd, path, desc) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /var/www/vhosts/ 13gems.com/httpdocs/stxresort/cart/getpic1.py, line 24 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Content-Encoding: base64 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: ^ [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: SyntaxError: invalid syntax Ideas? TIA, V I'm sorry, I don't understand how the code is being auto-generated? Is there no way to place the 'Content-Encoding' header inside the triple-quoted string, where it should go? -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 11:51:13 -0700, Victor Subervi victorsube...@gmail.com wrote: My misunderstanding. Here's the new code: print '''Content-Type: image/jpeg Content-Encoding: base64 ''' Ah, sorry, I wasn't clear -- Content-Encoding is a header, and needs to go with Content-Type, before the newlines. So print '''Content-Type: image/jpeg Content-Encoding: base64 ''' HTH, Rami On Wed, Oct 7, 2009 at 12:56 PM, Rami Chowdhury rami.chowdh...@gmail.comwrote: On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi victorsube...@gmail.com wrote: Well, since the code is automatically generated, it printed this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = select + pic + from products where id=' + str(picid) + '; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' Content-Encoding: base64 print print content.encode('base64') which threw this error: [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Traceback (most recent call last): [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /usr/lib64/python2.4/site-packages/mod_python/apache.py, line 299, in HandlerDispatch\n result = object(req) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /usr/lib64/python2.4/site-packages/mod_python/cgihandler.py, line 96, in handler\n imp.load_module(module_name, fd, path, desc) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File /var/www/vhosts/ 13gems.com/httpdocs/stxresort/cart/getpic1.py, line 24 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Content-Encoding: base64 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: ^ [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: SyntaxError: invalid syntax Ideas? TIA, V I'm sorry, I don't understand how the code is being auto-generated? Is there no way to place the 'Content-Encoding' header inside the triple-quoted string, where it should go? -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Python + webservice
Hello all... I'm new here and a search in tis group but unfortunately i didn't find any kind of solution/code/question etc ... I have to made a python script that communicates with an websevice over the web. I tried out use SoapPy, ZSI, BeautifullSoap and others, but get no success... I have to generate a XML file from a XSD file, and them send it to a webservice as i have said before. There's really no need to generate a XML file from a XSD file bu if it's possible it will be very very good... Has anyone made something like this and can share with me a bit of experience? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi victorsube...@gmail.com escribió: print '''Content-Type: image/jpeg ''' print print content On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina gagsl- p...@yahoo.com.arwrote: That's still wrong. The output should be: - a line containing Content-Type: image/jpeg - a blank line (no more!) ^ - the actual image data -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
I did that. In fact, just to make things easier, I wrote out exactly what is supposed to be rendered, as below: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = select pic1 from products where id='1'; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print print content.encode('base64') I even changed the image/jpeg to text/html to see if the image would print out the binary, and it did, so I'm calling the image correctly, just not rendering the binary as an image. V On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina gagsl-...@yahoo.com.arwrote: En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi victorsube...@gmail.com escribió: print '''Content-Type: image/jpeg ''' print print content On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina gagsl- p...@yahoo.com.arwrote: That's still wrong. The output should be: - a line containing Content-Type: image/jpeg - a blank line (no more!) ^ - the actual image data -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
n00m wrote: numerix's solution was excelled by Steve C's one (8.78s): http://www.spoj.pl/ranks/INOUTEST/lang=PYTH I don't understand nothing. I just got my solution accepted, it ran in 14 seconds though. I have no idea how to shave more seconds off, so I think 7.5 seconds for the fastest solution is really mindboggling. Things that eventually made my solution run within the time limit: - I didn't use int() - I used Psyco Those two resulted in the biggest speed increase. Tweaking with buffered/unbuffered IO was insignificant. Cheers Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
Victor Subervi wrote: [...] print '''Content-Type: image/jpeg Content-Encoding: base64 ''' [...] You have a spurious blank line between those header lines. HTH, -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
RE: How to run python script in emacs
Hitting ctrl-c, twice quickly works for me. -Original Message- From: python-list-bounces+frsells=adventistcare@python.org [mailto:python-list-bounces+frsells=adventistcare@python.org] On Behalf Of OdarR Sent: Wednesday, October 07, 2009 12:02 PM To: python-list@python.org Subject: Re: How to run python script in emacs On 26 sep, 17:54, devilkin devilsp...@gmail.com wrote: I'm just starting learning python, and coding inemacs. I usually splitemacswindow into two, coding in one, and run script in the other, which is not very convenient. anyone can help me with it? is there any tricks likeemacsshort cut? also please recommand someemacsplug-ins for python programming, i'm also beginner inemacs.currently i'm only using python.el. Are any plugins supply code folding and autocomplete? BTW, I'm not a english native speaker, any grammer mistakes, please correct them. :) hello, I was not so long ago in the same situation. I switch to emacs too, why ? probably because the movement is more natural than in vi (used for 12+ years), python-mode automatically starts on the machines I'm using, this is very convenient for *re-indentation* . Python could be difficult to maintain if you don't have a flexible text editor. if you want, i can suggest you some lines for the init file .emacs, in order to keep the text indented with 4 spaces, no tab at all (very important). I also suggest you to have a look on ipython shell, which is a super shell you keep side the text editor. once you discover it, you'll understand. I didn't hear for an autocompletion in emacs. but ipython has a autocompletion. It can sound weird to auto-complete outside your editor, but I like it. you can test little code snippets in ipython, discover the documentation and methods, and try them. I discover this clever advice in http://oreilly.com/catalog/9780596515829/ currently I work with Mac (Aquamacs), and I was recently on Solaris or XP as well. PS: emacs on Mac Terminal with a french keyboard is a bit of a nightmare considering the META key...:-( Aquamacs solves this finally. Olivier -- http://mail.python.org/mailman/listinfo/python-list -- [**CONFIDENTIALITY NOTICE**]: The information contained in this message may be privileged and / or confidential and protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to this message and deleting the material from any computer. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
I tried these combinations: print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print print content.encode('base64') and print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print content.encode('base64') Neither worked :( V On Wed, Oct 7, 2009 at 3:40 PM, Carsten Haese carsten.ha...@gmail.comwrote: Victor Subervi wrote: [...] print '''Content-Type: image/jpeg Content-Encoding: base64 ''' [...] You have a spurious blank line between those header lines. HTH, -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi victorsube...@gmail.com wrote: I did that. In fact, just to make things easier, I wrote out exactly what is supposed to be rendered, as below: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = select pic1 from products where id='1'; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg'''# Only print one line Content-Encoding: base64 ''' print print content.encode('base64') Just to reiterate what Gabriel and Carsten have pointed out, I'd suggest changing the last few lines of the script, as the comments below indicate: print '''Content-Type: image/jpeg''' # One header line print '''Content-Encoding: base64''' # Another header line. Note *no* blank line between them print# Blank line signals the end of the headers print content.encode(base64) # Base64-encoded content comes *after* the blank line If you include extra blank lines after the headers, the browser will misunderstand where the binary image data begins, and so will see a malformed JPEG. If this doesn't work, I suggest changing the content-type header to text/plain and trying to manually decode and check the image data to ensure it's valid. On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina gagsl-...@yahoo.com.arwrote: En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi victorsube...@gmail.com escribió: print '''Content-Type: image/jpeg ''' print print content On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina gagsl- p...@yahoo.com.arwrote: That's still wrong. The output should be: - a line containing Content-Type: image/jpeg - a blank line (no more!) ^ - the actual image data -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
print 'Content-Type: image/jpeg' print 'Content-Encoding: base64' print print content.encode('base64') I did change it to text/plain, but I don't know how I'm supposed to manually decode it. Yes, it printed out a bunch of crap to the screen. I've gotten that far before, and once I read Adobe something, so yes, it's an image. TIA, V On Wed, Oct 7, 2009 at 3:52 PM, Rami Chowdhury rami.chowdh...@gmail.comwrote: On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi victorsube...@gmail.com wrote: I did that. In fact, just to make things easier, I wrote out exactly what is supposed to be rendered, as below: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = select pic1 from products where id='1'; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg'''# Only print one line Content-Encoding: base64 ''' print print content.encode('base64') Just to reiterate what Gabriel and Carsten have pointed out, I'd suggest changing the last few lines of the script, as the comments below indicate: print '''Content-Type: image/jpeg''' # One header line print '''Content-Encoding: base64''' # Another header line. Note *no* blank line between them print# Blank line signals the end of the headers print content.encode(base64) # Base64-encoded content comes *after* the blank line If you include extra blank lines after the headers, the browser will misunderstand where the binary image data begins, and so will see a malformed JPEG. If this doesn't work, I suggest changing the content-type header to text/plain and trying to manually decode and check the image data to ensure it's valid. On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi victorsube...@gmail.com escribió: print '''Content-Type: image/jpeg ''' print print content On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina gagsl- p...@yahoo.com.arwrote: That's still wrong. The output should be: - a line containing Content-Type: image/jpeg - a blank line (no more!) ^ - the actual image data -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining python and sqlite DB into a single, executeable.
Thanks!, but I already thought of your suggestion. I've already gotten the clear impression that the amount of work to implement this is more than the ROI. Having said that, it might work if on exiting the app could re-zip itself. One _big_ problem with zip files or compiled python executables is moving the file from machine to machine. It wouldn't be platform independent anymore. What I like best so far, is to have something like: #!/usr/bin/env python Here lies python, boot code that connects to the sqlite db that pulls from a known sqlite table a blob that is the actual application and executes it. The boot code size must always be less than some size. Convince the python parser not to go here... fillter bytes to the sqlite database offset. sqlite database data End of File. Now the trick is to get the sqlite library to start looking for the sqlite database at, offset. Roger Binns wrote: tcumming...@gmail.com wrote: The problem, is that I need the python app and the sqlite db file to exist in the same disk file. This way the app to access the data and the data are in the same file. For binaries this is possible with a little hackery. Firstly you need make the app be a zip file. The good news is that zip files store their information at the end while executables store their information at the beginning. This is how self extracting zips work - they are the extractor program followed by the zip data. You can store the sqlite database in the zip portion. Copy it out to a tempfile while running and put it back in when done and saving. The tempfile module will help with temporary files. The zipfile module works quite happily with zip files prepended with extra stuff. To get started make a zip file with dummy contents (for example a readme explaining that mail is stored within). Assuming your app is called mail.exe and the zip file is called mail.zip you just concatenate them. py2exe and several other programs can make an executable out of a Python script for you. However in some cases they use this same 'trick' of an appended zip file to store the python code so you could also just modify that. If your app is a python script and you want to distribute it that way then you can make a zip file of the python script and then you have to run it by setting the PYTHONPATH environment variable to point at the zip file. Note that once you try this you may find the operating system and/or python not being too happy about modifying what they are executing. If you are feeling really adventurous there may even be a way of following the script with the data. This is used in Unix shell scripting but the Unix shell doesn't check the whole file is syntactically correct so you can append any binary junk you want. For Python you could try something like 8 #! python python code python code SOMESPECIALMARKER sqlite file contents 8 You'd have to do some escaping of the contents or maybe just base64 encode it. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 14:05:25 -0700, Victor Subervi victorsube...@gmail.com wrote: print 'Content-Type: image/jpeg' print 'Content-Encoding: base64' print print content.encode('base64') I did change it to text/plain, but I don't know how I'm supposed to manually decode it. Yes, it printed out a bunch of crap to the screen. I've gotten that far before, and once I read Adobe something, so yes, it's an image. TIA, V Hopefully the 'crap' you're getting is the base64-encoded representation of your binary image -- you should be able to use Python to decode that, and then use any image viewer to verify that the JPEG is sound. Can you remind us of the URL where that code (with the text/plain content type) is running? On Wed, Oct 7, 2009 at 3:52 PM, Rami Chowdhury rami.chowdh...@gmail.comwrote: On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi victorsube...@gmail.com wrote: I did that. In fact, just to make things easier, I wrote out exactly what is supposed to be rendered, as below: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = select pic1 from products where id='1'; cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg'''# Only print one line Content-Encoding: base64 ''' print print content.encode('base64') Just to reiterate what Gabriel and Carsten have pointed out, I'd suggest changing the last few lines of the script, as the comments below indicate: print '''Content-Type: image/jpeg''' # One header line print '''Content-Encoding: base64''' # Another header line. Note *no* blank line between them print# Blank line signals the end of the headers print content.encode(base64) # Base64-encoded content comes *after* the blank line If you include extra blank lines after the headers, the browser will misunderstand where the binary image data begins, and so will see a malformed JPEG. If this doesn't work, I suggest changing the content-type header to text/plain and trying to manually decode and check the image data to ensure it's valid. On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi victorsube...@gmail.com escribió: print '''Content-Type: image/jpeg ''' print print content On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina gagsl- p...@yahoo.com.arwrote: That's still wrong. The output should be: - a line containing Content-Type: image/jpeg - a blank line (no more!) ^ - the actual image data -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury Never attribute to malice that which can be attributed to stupidity -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: WMI remote call in python script to create process on remote windows computer
ok, cut and pasted, but changed the username/password to protect the innocent. this is from interactive prompt. let me know if i am still not doing the slashes correctly please. i doubt authentication is the issue.; i can get pid information using WQL queries. objCreateProc.Create expects 4 strings (not objects?), right? version info: sys.version '2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)]' import win32com.client computer = servername strUser = servername\\my_account strPassword =shh_secret objSWbemLocator = win32com.client.Dispatch(WbemScripting.SWbemLocator) objSWbemServices = objSWbemLocator.ConnectServer(computer, rroot\cimv2,strUser,strPassword) objCreateProc = objSWbemServices.Get(Win32_Process) ProcessID = u200 objCreateProc.Create(ucmd /c ping 127.0.0.1 c:\\temp\\finall.log,uc:\\temp,u' ',ProcessID ) Traceback (most recent call last): File stdin, line 1, in module TypeError: 'int' object is not callable how can i see the method available? help(objCreateProc) just gives me Help on instance of CDispatch in module win32com.client: Thanks David -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
On Oct 7, 2:31 am, Ryan heni...@yahoo.com wrote: Thanks everyone for your insight. I'm going to have to agree with the paranoid desire to prevent people importing his module and then using the classes he imports from elsewhere (I'm not ruling out the lead paint theory until I can gather more evidence). It's wasted effort. Python isn't really designed to have totally clean namespaces. A base class can be deleted at the end of a module because it's only used while the module is being imported, but lots of other symbols can't. You can't delete any global that's used in a function, that means most imported modules or functions have to remain in the module's namespace, and usually there are a lot more of them than there are deletable base classes. Given that you can't generally have an externally clean namespace, why put forth such effort just to delete one or two names? The right thing to do is to advertise which symbols are external with __all__ (or, as judgment call, to use leading underscore on all internal symbols). There are some tricks you could use to keep __all__ up-to-date, for instance you can use this idiom to automatically add anything defined between two points to __all__ (though it can be subject to name clashing): ## do all your imports here _internals = set(globals()) ## define all your functions/classes/constants here _allnames = set(globals()) __all__ = list(x for x in _allnames-_internals if not x.startswith('_')) del _internals, _allnames # del ok here because this does free memory Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Graphical nodes
Sorry for the toppost, I'm on a mobile, but if I'm understanding you then you might want to try graphine- its a graph theory library with experimental dot language support, which you can use to draw your graphs. Give it a try- graphine.org. On Oct 7, 2009 2:12 AM, Dylan Palmboom dpalmb...@evafoam.co.za wrote: Hi everyone Please could someone tell me of any libraries that you could use to make use of graphical nodes in python. Each node would hold data and properties. I am trying to achieve a similar effect, as in the application spoken about below. If you have seen an application called Nuke, by the foundry, you will see what I mean. It uses graphical nodes such as rectangles etc (similar to UML) to link operations on images together with arrows etc. I know that Nuke is made using the Qt toolkit, so maybe someone could tell me what classes were probably used to make this node based interface. Maybe the QGraphicsItem and QGraphicsScene classes? It looks cool so if anyone has any ideas on how to do something like this, it would be great. Thanks -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining python and sqlite DB into a single, executeable.
[Please do not email me *and* the list - it is highly annoying] Tom Cumming wrote: Thanks!, but I already thought of your suggestion. I've already gotten the clear impression that the amount of work to implement this is more than the ROI. It isn't anywhere near as hard or as much work as you think! Having said that, it might work if on exiting the app could re-zip itself. See the atexit module. One _big_ problem with zip files or compiled python executables is moving the file from machine to machine. It wouldn't be platform independent anymore. You are the one who mentioned executables which generally means platform specific binaries (and in the vast majority of cases that platform is Windows) :-) Being an executable means you don't have to care if Python is already installed. If you want it platform independent then you are stuck with Python text scripts. You can put one in a zip file and use PYTHONPATH or you can use the approach I showed at the bottom of my original message. What I like best so far, is to have something like: You pretty much outlined what I wrote at the bottom of my message. Convince the python parser not to go here... You can't do that. The entire source file has to be valid Python. You can get Python to not take action on parts by making it a multi-line string you do nothing with (ie surround with ) or by prefixing each line with # to make it a comment. I'd recommend a string at the end with base64 encoded contents. This would be very few lines of code to maintain along with tempfile.NamedTemporaryFile and atexit. My estimate is a total of 10-20 lines of code. Now the trick is to get the sqlite library to start looking for the sqlite database at, offset. You cannot use the standard SQLite API to do that. SQLite does have a way of writing custom file access (known as VFS) that could do it and the APSW SQLite Python wrapper provides that functionality. See http://apsw.googlecode.com/svn/publish/vfs.html (Disclaimer: I am the author of APSW). However writing a VFS is *way* more work than something simple to extract data from the end of a script to a temporary file and put the data back at exit. And you'd have to ensure all machines have both Python and APSW installed. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
On Wed, 07 Oct 2009 02:31:00 -0700, Ryan wrote: Thanks everyone for your insight. I'm going to have to agree with the paranoid desire to prevent people importing his module and then using the classes he imports from elsewhere (I'm not ruling out the lead paint theory until I can gather more evidence). It does beg the question for me. No it doesn't, it raises the question. http://en.wikipedia.org/wiki/Begging_the_question Consider the example from his code below from PyQt4 import QtGui class LauncherWidget( QtGui.QWidget ): # A Specialization of QWidget del QtGui Next time python comes across from PyQt4 import QtGui it would have to re-import the class, which seems a waste of cycles that could accumulate. As Hans explained, not quite. When you call from PyQt4 import QtGui, Python loads the module PyQt4, caches the module in sys.modules, and then adds PyQt4.QtGui into the current namespace (your module). When you delete QtGui, that only removes it from your namespace. The module is still in the cache, so the next time you call the import, it's much, much faster. Multiple imports aren't entirely free, but they're much less expensive than you might think. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
How to install 64-bit python on Ubuntu
Hello All, Ubuntu comes pre-installed with Python2.6 but this python installation is a 32 bit installation. I need to use 64-bit Python on Ubuntu - how do I update the current installation to 64-bit installation? Is there any separate package that I need to apt-get? I do the following to know if the current python installation is 32- bit or 64-bit: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. from struct import * calcsize(P) * 8 32 I expect to see the pointer size as 64 there.. If any of you could provide me any info on this matter, it would be a great help Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list
Tkinter -- the best way to make a realtime loop
What's the best way to make a realtime loop in Tkinter? I know in perl you can use repeat and it will call a function every x seconds, in python it seems like after may be the equivalent though it doesn't seem to behave like the perl repeat function. Any ideas? Thanks, Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good idea
Jean-Michel Pichavant jeanmic...@sequans.com wrote: alex23 wrote: To me, the explicit reference to the base class violates DRY. It also means you need to manually change all such references should the base class ever change, something that using super() avoids. I found the correct answer (http://www.artima.com/weblogs/viewpost.jsp?thread=236275) I'm not entirely sure how an opinion + explanation of the underlying mechanics is more or less correct than a development principle... -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
Curious wrote: Ubuntu comes pre-installed with Python2.6 but this python installation is a 32 bit installation. For 64 bit Ubuntu you are mistaken: $ file /usr/bin/python2.6 /usr/bin/python2.6: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped I do the following to know if the current python installation is 32- bit or 64-bit: This is what I do: import ctypes ctypes.sizeof(ctypes.c_void_p) 8 Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
I typically use several editors: /bin/ed, nvi, EDIT.COM, and Vi Improved. These are the advantages that I find these various editors give me: ed -- I can quickly edit files without having to wait on an ncurses app to start up. Although I rarely have access to GNU versions of ed, they use readline which is a big perk when you make a typo. nvi -- smaller and faster then vim, works great over slow ssh links or when editing huge files. I like nvi over the original vi, because most of the limitations of the old-school vi are removed; unlimited undo is the best feature added. EDIT.COM -- much faster then notepad over remote connections, and it understands both DOS and UNIX end of lines; meaning I can skip converting formats, the only downside is it's still a 16-bit program. vim -- My favourite and most used editor. I like it because it can be made fairly compatible with vi, but has superior tag stack handling, and the multiple-window, :ex command line history, and completion features leave their nvi equivalents in the dust. (vi had no completion or command history, and lacked split windows.) Vim also has improved register handling, regular expression support, tab pages for organizing workspaces, a client/server mode, and most importantly can be made to adapt itself (e.g. spaces, tabs, eol's) based on file type without much bother. That makes it much easier to use with Python files then most editors in my tool bag. I am a freak: I do not use nor want syntax highlighting. I don't want my editor to understand mail, irc, or the www either, I want it to edit text efficiently so I can go on with the rest of my life as soon as possible. Given the choice of using a space cadets editor like emacs or something primitive one like ed, I would choose *ed* just to speed things up and save on wrist strain. Before I read a tutorial about vi, I used XEmacs very happily---vi just lines up better with how my brain works. -- It is also general consensus that I am nuts ;) TerryP. -- http://mail.python.org/mailman/listinfo/python-list
Re: AES decrypting in Python
Heikki Toivonen wrote: Mike Driscoll wrote: EVP.Cipher(alg=aes_256_ecb, key=SomeKey, iv=SomeIV, op=dec, padding=False) I don't really see where I pass the data that needs the decrypting though. Can someone shed some light on this? Look at test_AES method in http://svn.osafoundation.org/m2crypto/trunk/tests/test_evp.py Basically EVP.Cipher returns the cipher object. You call the update update(data) method on it (you can call this many times if you have lots of data), which returns (possibly partial) result and finally call the final() method to finish, which will return the last piece of the decrypted data. You might also want to take a look at m2secret[1] which is a small library/utility built on top of M2Crypto to encrypt/decrypt stuff. By default it uses AES. [1] http://www.heikkitoivonen.net/m2secret/ thanks Heikki, finally some encryption / decryption tool that can be used by non-crypto-maniaks. cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
On Oct 7, 4:07 pm, Roger Binns rog...@rogerbinns.com wrote: Curious wrote: Ubuntu comes pre-installed with Python2.6 but this python installation is a 32 bit installation. For 64 bit Ubuntu you are mistaken: $ file /usr/bin/python2.6 /usr/bin/python2.6: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped I do the following to know if the current python installation is 32- bit or 64-bit: This is what I do: import ctypes ctypes.sizeof(ctypes.c_void_p) 8 Roger Thanks very much for you response, Roger! I am sorry but I am not able to follow what you are saying. I am quite new to linux installation world and it's possible that I am missing pretty straightforward info. Did you mean to say that Ubuntu does come pre-installed with 64-bit Python? When I used the same command as you did, I see a 32-bit version there. I am not sure how to get to 64-bit. $ file /usr/bin/python2.6 /usr/bin/python2.6: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. import ctypes ctypes.sizeof(ctypes.c_void_p) 4 I also tried building Python on this machine by setting following configuration option: /configure --enable-universalsdk --with-universal-archs=64-bit But no luck. I am definitely missing something here. Could you please explain how did you get a 64-bit version there? I am using ubuntu 9.0.4. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
Curious schrieb: On Oct 7, 4:07 pm, Roger Binns rog...@rogerbinns.com wrote: Curious wrote: Ubuntu comes pre-installed with Python2.6 but this python installation is a 32 bit installation. For 64 bit Ubuntu you are mistaken: $ file /usr/bin/python2.6 /usr/bin/python2.6: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped I do the following to know if the current python installation is 32- bit or 64-bit: This is what I do: import ctypes ctypes.sizeof(ctypes.c_void_p) 8 Roger Thanks very much for you response, Roger! I am sorry but I am not able to follow what you are saying. I am quite new to linux installation world and it's possible that I am missing pretty straightforward info. Did you mean to say that Ubuntu does come pre-installed with 64-bit Python? When I used the same command as you did, I see a 32-bit version there. I am not sure how to get to 64-bit. I bet your Ubuntu installation is 32bit, too. You need a 64bit installation of Ubuntu in order to run a 64bit version of Python. By default Python is compiled in the same flavor as the OS. What does uname -m show? It should print x86_64 for a 64bit version of Linux. --enable-universalsdk and --with-universal-archs have no function on Linux. They are Mac OS X only options. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
Curious wrote: Did you mean to say that Ubuntu does come pre-installed with 64-bit Python? I am saying that 64 bit Ubuntu comes with 64 bit Python. (32 bit Ubuntu comes with 32 bit Python.) When I used the same command as you did, I see a 32-bit version there. It is most likely that you are running 32 bit Ubuntu (unless you bypassed Ubuntu's packaging and similar stunts). Run 'uname -a' and look near the end. For 64 bit you should see something like this: $ uname -m x86_64 If you see i686 instead of x86_64 you are on 32 bit. $ file /usr/bin/python2.6 /usr/bin/python2.6: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped That is definitely a 32 bit binary. Try some others like /bin/ls and /sbin/init. (A 64 bit kernel can run 32 bit binaries but these core system files should all match the kernel.) I also tried building Python on this machine by setting following configuration option: /configure --enable-universalsdk --with-universal-archs=64-bit That is a road you don't want to go down unless you really know what you are doing and want to bypass the packaging system. As far as I am aware those options only apply to Macs anyway! Could you please explain how did you get a 64-bit version there? When I download Ubuntu I got the 64 bit version. Look at the bottom of the page: http://www.ubuntu.com/getubuntu/download You may find various guides on how to convert a 32 bit installation into a 64 bit one. Do not do any of those (if you do then mention it when asking for help at which point people will tell you not to have done that!) Make a backup and do a *fresh* install. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
On Oct 7, 4:55 pm, Christian Heimes li...@cheimes.de wrote: Curious schrieb: On Oct 7, 4:07 pm, Roger Binns rog...@rogerbinns.com wrote: Curious wrote: Ubuntu comes pre-installed with Python2.6 but this python installation is a 32 bit installation. For 64 bit Ubuntu you are mistaken: $ file /usr/bin/python2.6 /usr/bin/python2.6: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped I do the following to know if the current python installation is 32- bit or 64-bit: This is what I do: import ctypes ctypes.sizeof(ctypes.c_void_p) 8 Roger Thanks very much for you response, Roger! I am sorry but I am not able to follow what you are saying. I am quite new to linux installation world and it's possible that I am missing pretty straightforward info. Did you mean to say that Ubuntu does come pre-installed with 64-bit Python? When I used the same command as you did, I see a 32-bit version there. I am not sure how to get to 64-bit. I bet your Ubuntu installation is 32bit, too. You need a 64bit installation of Ubuntu in order to run a 64bit version of Python. By default Python is compiled in the same flavor as the OS. What does uname -m show? It should print x86_64 for a 64bit version of Linux. --enable-universalsdk and --with-universal-archs have no function on Linux. They are Mac OS X only options. Christian Thanks for your response Christian! You are right, I have got a wrong Ubuntu installation, installed it by mistake instead of 64-bit. After the re-installation, I will post what Python version I find. Thanks all! -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On Oct 7, 10:29 am, Tim Chase python.l...@tim.thechases.com wrote: One feature I have that emacs don't is that I'm able to efficiently edit a file on a remote machine with vim on a terminal (without graphical interface), and I'm using it. Apart from that, both solutions are emacs has the same efficiency on a terminal. or maybe I don't understand your sentence. Perhaps this is a reference to the alt/meta/control/buckey/super key-chords that emacs is infamous for using It's Esc-Meta-Alt-Ctrl-Shift Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
On Oct 7, 5:11 pm, Roger Binns rog...@rogerbinns.com wrote: Curious wrote: Did you mean to say that Ubuntu does come pre-installed with 64-bit Python? I am saying that 64 bit Ubuntu comes with 64 bit Python. (32 bit Ubuntu comes with 32 bit Python.) When I used the same command as you did, I see a 32-bit version there. It is most likely that you are running 32 bit Ubuntu (unless you bypassed Ubuntu's packaging and similar stunts). Run 'uname -a' and look near the end. For 64 bit you should see something like this: $ uname -m x86_64 If you see i686 instead of x86_64 you are on 32 bit. $ file /usr/bin/python2.6 /usr/bin/python2.6: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped That is definitely a 32 bit binary. Try some others like /bin/ls and /sbin/init. (A 64 bit kernel can run 32 bit binaries but these core system files should all match the kernel.) I also tried building Python on this machine by setting following configuration option: /configure --enable-universalsdk --with-universal-archs=64-bit That is a road you don't want to go down unless you really know what you are doing and want to bypass the packaging system. As far as I am aware those options only apply to Macs anyway! Could you please explain how did you get a 64-bit version there? When I download Ubuntu I got the 64 bit version. Look at the bottom of the page: http://www.ubuntu.com/getubuntu/download You may find various guides on how to convert a 32 bit installation into a 64 bit one. Do not do any of those (if you do then mention it when asking for help at which point people will tell you not to have done that!) Make a backup and do a *fresh* install. Roger Thanks Roger. Actually we have one machine at our disposal to try different things out. We installed Linux on it just yesterday and wanted to get Python working so there's nothing important that we fear to loose. We'll probably do the fresh install. Will post on the forum about how it goes and if I get 64-bit Python version. -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
Carl Banks wrote: On Oct 7, 10:29 am, Tim Chase python.l...@tim.thechases.com wrote: Perhaps this is a reference to the alt/meta/control/buckey/super key-chords that emacs is infamous for using It's Esc-Meta-Alt-Ctrl-Shift Sure that's not Winkey+Tab+Fn? :-) -tkc :wq! -- http://mail.python.org/mailman/listinfo/python-list