Final Introduction to Python of 2008
As the year draws to a close, Holden Web is pleased to remind readers that its final public Introduction to Python class of this year will be held from 9-11 December at our education center close to Washington, DC. There are several hotels conveniently located within walking distance, and we provide breakfast snacks on lunch each day. You can purchase places on-line at http://holdenweb.com/py/training/ by credit card or using PayPal. Thanks to all students who have already attended this class. We look forward to meeting you again as our range of course offerings increases. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Your Million Dollar Python Project at the Toronto Python User's Group on Tuesday
We'll be having our regular Toronto Python User's Group (PyGTA) at our regular location, Linux Caffe, at our regular time, 7pm on the Third Tuesday of the month. This month's topic is: If you had up to 1 million dollars to spend on a Python project, what would you spend it on? What features would you like to see? What changes do you feel need to be made? Would you spend the money on advertising, optimization, libraries, frameworks, concurrency, alternative implementations, or infrastructure? What keeps you from using Python everywhere, and what could you do to fix that? Would you spend the money on making a killer commercial project? Would you hire programmers, put out code bounties, or just donate money to projects? Linux Caffe is located at the corner of Grace and Harbord, one block South of Christie station, details on the web-site at http://www.pygta.org. Have fun, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Remote control of firefox (mozilla) from a python program
Scott wrote: I have a requirement to control a firefox web browser from an external python program. The python program running under linux from a command shell needs to first find all open firefox web browser windows read the URL currently displayed in each web browser and if the URL matches a particular regular expression it needs to get/set form fields displayed in the web browser. Basically I need something like Windows COM and Internet Explorer where you can use COM to get/set form elements in the web page as well as post the web page. Does xpcom provide this? Is there some other method? Mozilla has an xpcom interface but I am not sure it is available to a python program running in a different process as my scenario describes. At some point I will need this python program to run under Mac OS X but for now I need something running under Linux. I think you need a tool like Funittest, it is a functional test tool based on Selenium Remote Control: http://www.openplans.org/projects/funittest/project-home -- Riccardo Lemmi -- http://mail.python.org/mailman/listinfo/python-list
Re: Project layout / Import files from different subdirectories
Markus Mayer schrieb: Hi folks. I'm new to python and have a slight problem importing - or maybe understanding - modules. I'm writing a GUI application using Qt4 and wanted to separate the business from the view logic. So I have my folder structure as following: project/ main.py important.py project/ gui/ __init__.py mainwindow.py anotherwindow.py Now I can import mainwindow etc. from main and important, but how do I do it the other way round? By placing a __init__.py into project, and then import project.main import project.gui.mainwindow Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: [Newbie] Strange output from list
On Mon, 10 Nov 2008 20:02:39 -0600, Andrew [EMAIL PROTECTED] wrote: sql = 'SELECT id FROM master' rows=list(cursor.execute(sql)) for id in rows: sql = 'SELECT COUNT(code) FROM companies WHERE code=%s' % id[0] result = list(cursor.execute(sql)) print Code=%s, number=%s % (id[0],result[0][0]) Notice the extra [0] index on the result In English: Item zero of the tuple that is item zero of result Thanks, it worked. But why does id[0] return the value of the first (and only) column as I expected it, while I need to use result[0] [0] to access the first column? -- http://mail.python.org/mailman/listinfo/python-list
Re: pysqlite install error on hp ux (ld: Can't find library for -lpython2.5)
* Geon. (Mon, 10 Nov 2008 18:00:56 -0800 (PST)) On 11?10?, ??1?31?, ??? [EMAIL PROTECTED] wrote: On Nov 10, 10:29 am, Geon. [EMAIL PROTECTED] wrote: when i install pysqlite i meet bellow error. ( use easy_install and source code building same problem ) ld: Can't find library for -lpython2.5 what mean this message? and what i do? my system is hp-ux 11i v3. and python2.5 is installed. ld command also avaliable. please help for me~ Hi, as far as I know. 1. you can use module sqlite3 instead. 2. you can use these commands on ubuntu: sudo apt-get install libsqlite3-dev sudo easy_install -Z pysqlite is possible apt-get on hp unix? i think apt-get is only available ubuntu linux system.. No, on all Debian based distributions. Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 and sqlite
* [EMAIL PROTECTED] (Mon, 10 Nov 2008 15:33:22 -0800 (PST)) On a (sun) webserver that I use, there is python 2.5.1 installed. I'd like to use sqlite3 with this, however sqlite3 is not installed on the webserver. Python comes with SQLite support. It's not necessary to have SQLite installed for that. If I were able to compile sqlite using a sun machine (I normally use linux machines) and place this in my lunix home account would I be able to use python and sqlite? Just go ahead and import sqlite3 Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Re: IBM integer and double formats
On Nov 10, 11:49 pm, John Machin [EMAIL PROTECTED] wrote: Call me crazy if you like, but I'd name that function IEEEtoIBM. But it's topsy-turvy day! Didn't you get the memo? Oh, all right. IEEEtoIBM it is. That's a hexadecimal representation in lowercase with no leading zeroes ... variable length and lowercase doesn't seem very IBM to me. True. Replace %x with %016X for fixed-length uppercase. Or as you say, bytes output is probably more natural. I was guessing that the OP wants to write the converted float out to an ASCII file, in hex. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: [Newbie] Strange output from list
On Tue, Nov 11, 2008 at 12:56 AM, Gilles Ganault [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 20:02:39 -0600, Andrew [EMAIL PROTECTED] wrote: sql = 'SELECT id FROM master' rows=list(cursor.execute(sql)) for id in rows: sql = 'SELECT COUNT(code) FROM companies WHERE code=%s' % id[0] result = list(cursor.execute(sql)) print Code=%s, number=%s % (id[0],result[0][0]) Using liberal term rewriting, consider the following rough equivalencies in the code: id[0] == rows[INDEX_HERE][0] == list(cursor.execute(sql))[INDEX_HERE][0] result[0][0] == list(cursor.execute(sql))[0][0] Note that in both cases, the list is sliced twice; the for-loop just conceals the `[INDEX_HERE]` implicit slicing that is caused by iterating over the list. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com Notice the extra [0] index on the result In English: Item zero of the tuple that is item zero of result Thanks, it worked. But why does id[0] return the value of the first (and only) column as I expected it, while I need to use result[0] [0] to access the first column? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Project layout / Import files from different subdirectories
Diez B. Roggisch schrieb: By placing a __init__.py into project, and then import project.main import project.gui.mainwindow Diez Ouch. Thanks. Markus -- PGP/GPG key 0x2EB39BF9 -- http://mail.python.org/mailman/listinfo/python-list
Re: Final Python Class of 2008
Steve Holden wrote: As the year draws to a close, Holden Web is pleased to remind readers that its final public Introduction to Python class of this year will be held from 9-11 December at our education center close to Washington, DC. There are several hotels conveniently located within walking distance, and we provide breakfast snacks on lunch each day. You can purchase places on-line at http://holdenweb.com/py/training/ by credit card or using PayPal. Thanks to all students who have already attended this class. We look forward to meeting you again as our range of course offerings increases. Since this is 2008, please understand that the former title was a typo and we weren't advertising classes 12 months in advance ... regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Air Force1 and Air Jordan shoes PAYPAL wholesale
Air Force1 and Air Jordan shoes PAYPAL wholesale www.z-a-z-a.com air force1 shoes. air force1 high shoes. air force1 light shoes . we are professional produce air force1 and jordan shoes supplier ,carry PAYPAL.main air force1-25th AF1-high AF1-low .air jordan 1-14,air jordan 23,air force 1jordan 5,air force1jordan12,air jordan1jordan23 and so on .We are sure you will make your business very easily under our help.If you need any help, please do not hesitate to contact with us at any time. -- http://mail.python.org/mailman/listinfo/python-list
Re: My first Python program -- a lexer
John Machin schrieb: You are getting closer. A better analogy is that using a dict is like transporting passengers along an autobahn in an aeroplane or helicopter that never leaves the ground. It is not a bad idea to transport passengers in an airplane, but then the airplane should not follow an autobahn, but use the shortest way -- at an appropriate altitude. Translated back to Python dicts, this would mean that using a dict for my purposes is a good idea, but that I do not make use of its full capabilities -- in other words, I should rewrite my code -- still using dict but in a better way. Or do you mean that for 10 kilometers of autobahn, an airplane would be overkill? Maybe I am a bit biased by my PHP background, but { name: regex, ... } looks simpler to me than [ ( name, regex ), ... ], because the former is not a nested structure, while the latter would be a 2D-array in PHP. Suppose I use the dict and I want to access the regex associatetd with the token named tokenname (that is, no iteration, but a single access). I could simple write tokendict[tokenname]. But with the list of tuples, I can't think of an equally easy way to do that. But then, as a beginner, I might be underestimating Python. Greetings, Thomas -- Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison! (Coluche) -- http://mail.python.org/mailman/listinfo/python-list
Re: Sync paramstyle between sqlite and mysql
On Nov 10, 11:00 am, Daniel [EMAIL PROTECTED] wrote: Hello, I'm developing an application that accesses both a MySQL and an SQLite database. I would like to have named parameters in my SQL and have found the following: For MySQL my named parameters need to look like this: %(paramname)s For SQLite my named parameters need to look like this: :paramname I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that there are five paramstyles, though it wasn't clear if I should expect these to be implemented in all DBAPI2 compliant modules. I have found that I can set the paramstyle, but it doesn't seem to apply: import sqlite3 as dbapi2 dbapi2.paramstyle 'qmark' dbapi2.paramstyle = 'format' dbapi2.paramstyle 'pyformat' My sqlite access still requires the 'named' format and not 'pyformat'. Can someone tell me if it's possible to configure a connection or cursor to use a particular paramstyle? Thanks. If no one has any input, can someone tell me where I should post? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 - is this true?
On Nov 11, 8:02 am, M.-A. Lemburg [EMAIL PROTECTED] wrote: On 2008-11-11 02:10, Steven D'Aprano wrote: On Mon, 10 Nov 2008 12:51:51 +, Duncan Grisby wrote: I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being able to sort lists where some of the members are None. To some extent, it also sorts lists of other mixed types. It will be very hard to migrate this aspect of it to Python 3. No, it is very hard to sort *arbitrary* objects consistently. If it appears to work in Python 2.x that's because you've been lucky to never need to sort objects that cause it to break. If you read Duncan's email, he isn't talking about arbitrary objects at all. He's just referring to being able to sort lists that contain None elements. That's far from arbitrary and does work consistently in Python 2.x - simply because None is a singleton which is special cased in Python: None compares smaller to any other object in Python. I'm not sure why this special case was dropped in Python 3.0. None is generally used to be a place holder for a n/a-value and as such will pop up in lists on a regular basis. I think the special case for None should be readded to Python 3.0. On python-ideas I proposed adding two new builtin singletons instead, Smallest and Largest, since the behavior of None wrt comparisons was never officially part of the language. George -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 - is this true?
M.-A. Lemburg wrote: On 2008-11-11 02:10, Steven D'Aprano wrote: On Mon, 10 Nov 2008 12:51:51 +, Duncan Grisby wrote: I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being able to sort lists where some of the members are None. To some extent, it also sorts lists of other mixed types. It will be very hard to migrate this aspect of it to Python 3. No, it is very hard to sort *arbitrary* objects consistently. If it appears to work in Python 2.x that's because you've been lucky to never need to sort objects that cause it to break. If you read Duncan's email, he isn't talking about arbitrary objects at all. He's just referring to being able to sort lists that contain None elements. That's far from arbitrary and does work consistently in Python 2.x - simply because None is a singleton which is special cased in Python: None compares smaller to any other object in Python. I'm not sure why this special case was dropped in Python 3.0. None is generally used to be a place holder for a n/a-value and as such will pop up in lists on a regular basis. I think the special case for None should be readded to Python 3.0. I agree here, it seems strange that cmp(None,None) is exceptional. Clearly the is relation applies to None so does ==. Do we not have a sorting order for sets with one element? My maths is now shot, but I seem to remember there are automatic orders for such simple sets. -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: My first Python program -- a lexer
Thomas Mlynarczyk wrote: John Machin schrieb: You are getting closer. A better analogy is that using a dict is like transporting passengers along an autobahn in an aeroplane or helicopter that never leaves the ground. It is not a bad idea to transport passengers in an airplane, but then the airplane should not follow an autobahn, but use the shortest way -- at an appropriate altitude. Translated back to Python dicts, this would mean that using a dict for my purposes is a good idea, but that I do not make use of its full capabilities -- in other words, I should rewrite my code -- still using dict but in a better way. Or do you mean that for 10 kilometers of autobahn, an airplane would be overkill? The latter. Maybe I am a bit biased by my PHP background, but { name: regex, ... } looks simpler to me than [ ( name, regex ), ... ], because the former is not a nested structure, while the latter would be a 2D-array in PHP. But it's a question of the properties of the objects. Because lists are ordered it's appropriate to use them when you want to iterate over them and no random access is required. If you need random access by key and no particular ordering is required for the iteration then you should use a dict. Forget simplicity until you know how the different objects are implemented under the hood. A good first rule is that simple, readable Python will usually be efficient. As far as execution efficiency goes I'd be very surprised if the dict solution was faster, but even if it were I would still prefer the list-based solution because it's more appropriate to the problem. Premature optimization is the root of all evil ... Suppose I use the dict and I want to access the regex associatetd with the token named tokenname (that is, no iteration, but a single access). I could simple write tokendict[tokenname]. But with the list of tuples, I can't think of an equally easy way to do that. But then, as a beginner, I might be underestimating Python. But when do you want to do that? There's no point inventing use cases - they should be demonstrated needs. The only time your original code needs to use the token name to retrieve the value is for your compile() method, but assuming the passed-in tokens was of the form [(name, pattern), ...] you could just as easily throw the method away and in __init__() write self.tokens = [(name, re.compile(pat)) for name, pat in tokens] Or simply pass compiled token patterns in in the first place when they are necessary ... then the caller has the option of not bothering to optimize in the first place! The advantage of the list-based approach is that it at least allows of the possibility that you can observe the relative frequencies of the tokens' appearance in real code, and then optimize the ordering to give best (mean) performance (by putting the commonest token first) should tokenization become a program hotspot. With a dict you have no such opportunity, because the ordering is determined by the implementation and not by your data structure. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Close access to the base class public methods
Hi! Could you imagine any way to block access to the base class public methods? Here is an example: class B: def public_method(): pass class A(B): def public_a_method(): pass def a = A() Is there any way to block the call a.public_method() without any changes to B class? Thank you! -- http://mail.python.org/mailman/listinfo/python-list
Re: Where to locate existing standard encodings in python
Hi Philip, Thanks for your answer: The fact, that a module 'encodings' exists was new to me. encodings.aliases.aliases has however one problem. It helps to locate all encoding aliases, but it won't find entries for which no aliases exist: So I can find koi8_r and its aliases [ [k,v] for k,v in encodings.aliases.aliases.iteritems() \ if v.find('koi') -1 ] [['cskoi8r', 'koi8_r']] However I wouuldn't find the greek code page 'cp737' as it exists without an alias [ [k,v] for k,v in encodings.aliases.aliases.iteritems() \ if v.find('737') -1 ] [] What gives me a list of quite some encodings on my host is the shell command ls /usr/lib/python2.5/encodings | sed -n 's/\.py$//p' | sort (soma false hits, bit this is fine for me purposes) I don't know if really all encodings are represented with a .py file and if all encodigns have to be in this directory, but it's a start. Using shell commands is not that pythonic: I could try to rewrite this in python by 1.) determine from which directory encodings was imported and then using the glob module to list all .py files located there. thanks again and bye N Philip Semanchuk wrote: On Nov 11, 2008, at 9:10 AM, News123 wrote: Hi Philip, Your answer touches exaclty one point, which I was slightly afraid of: - The list is not exhaustive - python versions might have implemented different codecs. This is why I wondered whether there's any way of querying python for a list of codecs it supports. Try this: Python 2.5.1 (r251:54863, Nov 17 2007, 21:19:53) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type help, copyright, credits or license for more information. import encodings.aliases encodings.aliases.aliases aliases in the encodings.aliases module is a dict mapping alias names (the dict keys) to encodings (the dict values). Thus, this will give you the list of supported encodings: set(encodings.aliases.aliases.values()) The encodings module isn't in the documentation (?!?); I found it when looking through the Python source code. For that reason I can't say more about how it works. You may want to experiment to see if encodings added via codecs.register() show up in the encodings.aliases.aliases dict. Have fun Philip Philip Semanchuk wrote: On Nov 9, 2008, at 7:00 PM, News123 wrote: Hi, I was googling quite some time before finding the answer to my question: 'what are the names for the encodings supported by python?' I found the answer at http://python.active-venture.com/lib/node127.html Now my question: Can I find the same info in the standard python doc or query python with a certain command to print out all existing codings? Look under the heading Standard Encodings: http://docs.python.org/library/codecs.html Note that both the page you found (which appears to be a copy of the Python documentation) and the reference I provide say, Neither the list of aliases nor the list of languages is meant to be exhaustive. I guess one reason for this is that different Python implementations could choose to offer codecs for additional encodings. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Close access to the base class public methods
RinKaMeAri wrote: Hi! Could you imagine any way to block access to the base class public methods? Here is an example: class B: def public_method(): pass class A(B): def public_a_method(): pass def a = A() Is there any way to block the call a.public_method() without any changes to B class? Thank you! The simplest way would be to override B.public_method within A by defining A.public_method to raise a NotImplementedError or similar exception. Though of course this then begs the question of why A would need to subclass B in the first place, but I assume there would be methods you *did* want to implement. Perhaps more background would yield a better solution. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Where to locate existing standard encodings in python
On Nov 11, 2008, at 1:08 PM, News123 wrote: Hi Philip, Thanks for your answer: The fact, that a module 'encodings' exists was new to me. We both learned something new today. =) encodings.aliases.aliases has however one problem. It helps to locate all encoding aliases, but it won't find entries for which no aliases exist: Ooops, I hadn't thought about that. What gives me a list of quite some encodings on my host is the shell command ls /usr/lib/python2.5/encodings | sed -n 's/\.py$//p' | sort (soma false hits, bit this is fine for me purposes) I don't know if really all encodings are represented with a .py file and if all encodigns have to be in this directory, but it's a start. Using shell commands is not that pythonic: I could try to rewrite this in python by 1.) determine from which directory encodings was imported and then using the glob module to list all .py files located there. Yes, I'd thought about this but I agree with you that it seems unpythonic and fragile. Unfortunately I can't think of anything better at this point. Good luck Philip Philip Semanchuk wrote: On Nov 11, 2008, at 9:10 AM, News123 wrote: Hi Philip, Your answer touches exaclty one point, which I was slightly afraid of: - The list is not exhaustive - python versions might have implemented different codecs. This is why I wondered whether there's any way of querying python for a list of codecs it supports. Try this: Python 2.5.1 (r251:54863, Nov 17 2007, 21:19:53) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type help, copyright, credits or license for more information. import encodings.aliases encodings.aliases.aliases aliases in the encodings.aliases module is a dict mapping alias names (the dict keys) to encodings (the dict values). Thus, this will give you the list of supported encodings: set(encodings.aliases.aliases.values()) The encodings module isn't in the documentation (?!?); I found it when looking through the Python source code. For that reason I can't say more about how it works. You may want to experiment to see if encodings added via codecs.register() show up in the encodings.aliases.aliases dict. Have fun Philip Philip Semanchuk wrote: On Nov 9, 2008, at 7:00 PM, News123 wrote: Hi, I was googling quite some time before finding the answer to my question: 'what are the names for the encodings supported by python?' I found the answer at http://python.active-venture.com/lib/node127.html Now my question: Can I find the same info in the standard python doc or query python with a certain command to print out all existing codings? Look under the heading Standard Encodings: http://docs.python.org/library/codecs.html Note that both the page you found (which appears to be a copy of the Python documentation) and the reference I provide say, Neither the list of aliases nor the list of languages is meant to be exhaustive. I guess one reason for this is that different Python implementations could choose to offer codecs for additional encodings. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
subprocess communication, exec()
If I run 'python -i subprocessclient.py' I expect to see the nice level of it go up 2, and the nice level of the subprocess go up 1. But all I see is the nice level of the client change. What am I doing wrong? subprocessserver.py: #!/usr/bin/python2.5 import os import sys while True: next_line = sys.stdin.readline() if not next_line: break exec(next_line) #sys.stdout.write(output) #sys.stdout.write(next_line) #sys.stdout.flush() subprocessclient.py: #!/usr/bin/python2.5 import subprocess, os server = subprocess.Popen(('python2.5', 'subprocessserver.py'), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) os.nice(2) server.stdin.write('''os.nice(1)''') Thanks. -Chuckk -- http://www.badmuthahubbard.com -- http://mail.python.org/mailman/listinfo/python-list
Re: disable ctrl-P in idle?
On Nov 10, 4:53 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Nov 10, 3:27 pm, timw.google [EMAIL PROTECTED] wrote: On Nov 10, 2:57 pm, Robert Singer [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 20:56:46 +0100, Robert Singer [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 10:40:28 -0800 (PST), timw.google [EMAIL PROTECTED] wrote: Is there a way to disable ctrl-P (print window) in IDLE? I'm editing some python code in IDLE and I keep hitting this by mistake from my years of emacs editing. Thanks in advance. Try autohotkey and map it to something else. Like, nothing :-) Internally, I don't think so, it's part of CUI. -- Bob ... continue: Or, you can just continue using emacs. I'm using vim, and can't think of a single reason why I should change it for idle. -- Bob Thanks. I on a XP box now, and it's a pain to get things installed here. That's why I'm not using emacs. When I'm on Linux, I use emacs. It's not worth the trouble to install something else for just this. It is not more difficult to install emacs on XP. What makes you think that? It's not that it's technically difficult. It's just a hassle to involve the help desk. -- http://mail.python.org/mailman/listinfo/python-list
Re: disable ctrl-P in idle?
On Nov 10, 10:35 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Nov 10, 4:49 pm, RichardT [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 10:40:28 -0800 (PST), timw.google [EMAIL PROTECTED] wrote: Is there a way to disable ctrl-P (print window) in IDLE? I'm editing some python code in IDLE and I keep hitting this by mistake from my years of emacs editing. Thanks in advance. In Idle, select 'Configure IDLE..' from the options menu. In the Options dialog, select the Keys tab. Scroll down to the 'print-window' entry and select it. Click the Get New Keys For Selection button. Select the new key combination e.g. Shift+Ctrl+p and click OK button. If you have not enter any custom keys before, you will get a prompt for a Custom Key Set Name - enter a name and click OK. For the archive, since our hero prefers not to receive credit. Ctrl+P should no longer send the window to the printer. On my system (python 2.5.1 on XP) it now moves the cursor up a line for some reason (deafult binding for the widget?) Cursor up is the default emacs binding for Ctrl+P so this will probably please the original poster (and me too!) Wonderful! I remapped ctrl-N too while I was at it. Thanks (and no help desk involvement either!) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 - is this true?
Duncan Grisby wrote: Yes, very hard. There is a difference between 'very hard' (to get 'right') and 'to slow' (for a particular application). I accept the latter. There are only ever simple types in the lists -- strings, integers, Nones, very occasionally floats, and lists of those things. The sort is always predictable with those types. Just because you can contrive situations to demonstrate unpredictable sorts doesn't mean that all sorts with mixed types are unpredictable. The 2.5 manual (and I sure before that) *intentially* defines the default cross-type comparisons as unreliable. (This unusual definition of comparison was used to simplify the definition of operations like sorting and the in and not in operators. In the future, the comparison rules for objects of different types are likely to change.) They have changed in the past and now they change again (yes, a little more drastically this time, but as expected for some years). The sorting is in a performance-critical part of the system, so the overhead of evaluating a key function is not insignificant. A key function that returns objects that contrive to emulate the functionality of a comparison function is definitely not appropriate. That area of the system already builds the lists using C++ for speed, so if we ever migrate to Python 3 it will probably be easier to do the whole thing in C++ rather than jump through hoops to make the Python sort work efficiently enough. Assuming the premises, agreed. No hurry, but you can even pull timsort() out of the source, if you otherwise like its large-list behavior, and hardcode the comparison function. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 - is this true?
M.-A. Lemburg wrote: I think the special case for None should be readded to Python 3.0. Quick summary of thread that MAL started on Python-3000-dev list: Once upon a time, 0 None was true. When rich comparisons were added, None 0 (and *most* other things) become true as an intentionally undocumented implementation detail. The None rule only applies for sure when None controls the comparison: ob None is true or undefined if type(ob) says so. Guido's pronouncement: In short, I'll have None of it. summarizing We're not going to add the feature back that None compares smaller than everything. It's a slippery slope that ends with all operations involving None returning None -- I've seen a proposal made in all earnestness requesting that None+42 == None, None() == None, and so on. This Nonesense was wisely rejected; a whole slew of early-error-catching would have gone out of the window. It's the same with making None smaller than everything else. For numbers, you can already use -inf; for other types, you'll have to invent your own Smallest if you need it. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: f2py usage problem
[EMAIL PROTECTED] wrote: Hi Python gurus, I have installed numpy and interested in testing f2py module using the first example in the documentation. Hi, You will want to ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists First I tried: C:\testpython C:\Program Files\Python25\Scripts\f2py.py -c fib1.f ... running build_ext No module named msvccompiler in numpy.distutils; trying from distutils error: Python was built with Visual Studio 2003; extensions must be built with a compiler than can generate compatible binaries. Visual Studio 2003 was not found on this system. If you have Cygwin installed, you can try compiling with MingW32, by passing -c mingw32 to setup.py. Then I installed mingw32 and tried to pass -c mingw32 to setup.py as below, but got another error: C:\testspython C:\Program Files\Python25\Lib\site-packages \numpy-1.0.4.0002-py2.5-win32.egg\numpy\f2py\setup.py -c mingw32 That's not the setup.py it is talking about. f2py is used both as a program and a library inside your own distutils setup.py scripts. Internally, the f2py program uses distutils to build the extension module. The error message you see comes from distutils, so it is (confusingly, in this case) assuming you are calling distutils from a setup.py script. The corresponding f2py program option would be --compiler=mingw32 . See f2py -h for all of the command line options. -- 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: Project layout / Import files from different subdirectories
It works when the program you are executing is in the current working directory, because Python always puts the directory containing the program you are executing (not the current working directory) on the path. Aha, that makes sense. I also found with a quick test that importing a module from the current dir works because '' is part of sys.path. I'm again amazed how beautifull it is all put together :) Cheers, Almar -- http://mail.python.org/mailman/listinfo/python-list
Printing a status line from a python script
Hi All, I am working on a python script for my colleague that will walk a directory and search in the different files for a specific string. These pieces I am able to do. What my colleague wants is that when she runs the script the filename is replaced by the current file that is being processed. So instead of seeing a series of files being listed down the page, she only wants to see the file currently being processed. I am not sure if this is even possible. Any thoughts would be greatly appreciated. Thanks. Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: plot for sale
On Nov 7, 2008, at 7:27 , [EMAIL PROTECTED] wrote: A plot in the new economic zone of the city Plots can be done using a library called matplotlib, and its free as far as I know. I'm not sure if the licensing prohibits selling the plots, but you'd need to post on that list for more details. bb -- Brian Blais [EMAIL PROTECTED] http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Re: Close access to the base class public methods
On Nov 11, 9:12 pm, Steve Holden [EMAIL PROTECTED] wrote: RinKaMeAri wrote: Hi! Could you imagine any way to block access to the base class public methods? Here is an example: class B: def public_method(): pass class A(B): def public_a_method(): pass def a = A() Is there any way to block the call a.public_method() without any changes to B class? Thank you! The simplest way would be to override B.public_method within A by defining A.public_method to raise a NotImplementedError or similar exception. Though of course this then begs the question of why A would need to subclass B in the first place, but I assume there would be methods you *did* want to implement. Perhaps more background would yield a better solution. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Thanks, Steve! will do what you have proposed. It is just the stub example. Have been writing some tests for class hierarchy and found the case when user can call the base method with the derived instance and have problems :-) IMO, it is the class design bug. Tried to play with __all__, setattr, getattr, but didn't find any solution. BTW, what do you mean to subclass B in the *first place*? -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing a status line from a python script
Chris Seymour wrote: Hi All, I am working on a python script for my colleague that will walk a directory and search in the different files for a specific string. These pieces I am able to do. What my colleague wants is that when she runs the script the filename is replaced by the current file that is being processed. So instead of seeing a series of files being listed down the page, she only wants to see the file currently being processed. I am not sure if this is even possible. Any thoughts would be greatly appreciated. Try printing each filename with sys.write(\r%s\r%s % ( *80, filename) It's crappy, but it might just work (you may need to change the 80 to some other numeric value). regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug in PIL 1.1.6
Markus Mayer: Any idea where I should send this (and/or more) information to? You can send your note and and image to effbot. You can also put an image online somewhere and give here the link (a small image, to avoid saturating your server, etc) so people can test it. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing a status line from a python script
On Tue, Nov 11, 2008 at 11:02 AM, Chris Seymour [EMAIL PROTECTED] wrote: Hi All, I am working on a python script for my colleague that will walk a directory and search in the different files for a specific string. These pieces I am able to do. What my colleague wants is that when she runs the script the filename is replaced by the current file that is being processed. So instead of seeing a series of files being listed down the page, she only wants to see the file currently being processed. I am not sure if this is even possible. Any thoughts would be greatly appreciated. Have you tried using carriage returns (\r)? chris ~ $ python Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type help, copyright, credits or license for more information. for i in range(10): ... print '\r'+str(i), 9 Note how each line gets overwritten by the next so that we only see the final number output (9). But really, I don't see a good reason to do this. So what, the output takes up some extra lines on the terminal? Big whoop. Your colleague can either pipe the script to `less` or a file if it really bothers them. And that way you get a list of all files processed, which can often come in handy in my experience. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com Thanks. Chris -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Project layout / Import files from different subdirectories
Almar Klein wrote: If your main file is in the root of the project, you can just use absolute imports. So you can use gui.anotherwindow or project.important from all files. I'm not sure this is good practice though... I was first under the impression that you can always import modules that are in your current working dir. But this seems to not always work... It works when the program you are executing is in the current working directory, because Python always puts the directory containing the program you are executing (not the current working directory) on the path. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Snippets management
On Nov 10, 3:14 pm, Stef Mientki [EMAIL PROTECTED] wrote: expora wrote: On Nov 6, 12:38 pm, Stef Mientki [EMAIL PROTECTED] wrote: Edwin wrote: Hi there, I've been looking for a snippet manager and found PySnippet but it requires PyGTK. Do you know any other option that doesn't need much? I'm sort of new to python and user interfaces seem a bit far for me right now, that's why I thought having to install PyGTK was unnecessary. Would you recommend installing it anyway? I'm on a Mac, maybe some users of Steve's Unix flavour know about a snippets software piece? I'm looking for free/open source alternatives. Thank you! P.S.: I'm also new to usenet ;) and hope my english is not that bad. -- http://mail.python.org/mailman/listinfo/python-list I developed one in wxPython, you can see some of the features here. http://mientki.ruhosting.nl/data_www/pylab_works/pw_code_editor.html Although it's part of a larger part it can be used standalone, but then it requires two actions copy and paste. Started from a python application you can do copy+paste with just one action. It has integrated a full blown scintilla editor, with syntax highlighting, code completion, and syntax checker. If there's interest, I can distribute the files as a separate package. cheers, Stef Mientki Wicked! I'm going to check it out Stef. Is the source available? It's all about learning for me right now. source can now be found here: http://pylab-works.googlecode.com/files/Test_Scintilla_Templates.zip cheers, Stef How great! Thanks for sharing mate! Downloading... Cheers, E. -- http://mail.python.org/mailman/listinfo/python-list
Re: Final Python Class of 2009
Steve, have you been in Guido's time machine again? Steve No, honest (hides hands behind back). Well then what's that red stuff on your face that looks like strawberry jam? Could it be the special grease we store next to the keys to the time machine? Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Python 2.5.3: call for patches
I would like to apply fixes for some CVE's which are addressed in 2.5 but not yet in 2.4. this would include CVE-2007-4965 CVE-2008-1679 CVE-2008-1721 CVE-2008-2315 CVE-2008-3144 CVE-2008-1887 CVE-2008-4864 Can you identify the revisions that would need backporting? I could only find (trunk revisions) CVE-2007-4965: r65880 CVE-2008-1721: r62235, issue2586 CVE-2008-3144: issue2588, issue2589, r63734, r63728. CVE-2008-1887: issue2587, r62261, r62271 CVE-2008-4864: r66689 So what about CVE-2008-1679: claimed to be issue1179 in the CVE, but that says it fixes CVE-2007-4965 only? CVE-2008-2315 In principle, this is fine with me, so go ahead. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess communication, exec()
On Nov 11, 1:23 pm, Chuckk Hubbard [EMAIL PROTECTED] wrote: If I run 'python -i subprocessclient.py' I expect to see the nice level of it go up 2, and the nice level of the subprocess go up 1. But all I see is the nice level of the client change. What am I doing wrong? subprocessserver.py: #!/usr/bin/python2.5 import os import sys while True: next_line = sys.stdin.readline() if not next_line: break exec(next_line) #sys.stdout.write(output) #sys.stdout.write(next_line) #sys.stdout.flush() subprocessclient.py: #!/usr/bin/python2.5 import subprocess, os server = subprocess.Popen(('python2.5', 'subprocessserver.py'), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) os.nice(2) server.stdin.write('''os.nice(1)''') Thanks. -Chuckk --http://www.badmuthahubbard.com Looks like you're dropping an error by redirecting the child process' standard error into a pipe. First off, remove the stderr=subprocess.PIPE from subprocessclient.py. When you do so, you'll start seeing an error message whenever your code runs: [EMAIL PROTECTED] ~]$ python client.py None [EMAIL PROTECTED] ~]$ Traceback (most recent call last): File stdin, line 1, in module NameError: name 'os' is not defined That doesn't make a lot of sense at first, until you consider the following: [EMAIL PROTECTED] ~]$ echo 'os.nice(1)' | python Traceback (most recent call last): File stdin, line 1, in module NameError: name 'os' is not defined The Python interpreter is trying to execute the data you write to the stdin of the child process. Changing the Popen line to use the string form rather than the sequence form remedies the problem, as does changing 'string=True' to 'string=False.' The reason? Because when you set shell=True, additional arguments in args sequence are passed as additional arguments to the shell itself, not to the command. From subprocess.py: if isinstance(args, types.StringTypes): args = [args] else: args = list(args) if shell: args = [/bin/sh, -c] + args So, in your attempt, you're effectively doing the following: /bin/sh -c python2.5 server.py When you want: /bin/sh -c python2.5 server.py HTH, Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: Close access to the base class public methods
RinKaMeAri wrote: On Nov 11, 9:12 pm, Steve Holden [EMAIL PROTECTED] wrote: RinKaMeAri wrote: Hi! Could you imagine any way to block access to the base class public methods? Here is an example: class B: def public_method(): pass class A(B): def public_a_method(): pass def a = A() Is there any way to block the call a.public_method() without any changes to B class? Thank you! The simplest way would be to override B.public_method within A by defining A.public_method to raise a NotImplementedError or similar exception. Though of course this then begs the question of why A would need to subclass B in the first place, but I assume there would be methods you *did* want to implement. Perhaps more background would yield a better solution. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Thanks, Steve! will do what you have proposed. It is just the stub example. Have been writing some tests for class hierarchy and found the case when user can call the base method with the derived instance and have problems :-) IMO, it is the class design bug. Tried to play with __all__, setattr, getattr, but didn't find any solution. BTW, what do you mean to subclass B in the *first place*? It's just an expression. As in I built A as a subclass of B, but since I overrode all B's methods in A there was no point making it a subclass in the first place. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Close access to the base class public methods
On Tue, Nov 11, 2008 at 11:16 AM, RinKaMeAri [EMAIL PROTECTED] wrote: On Nov 11, 9:12 pm, Steve Holden [EMAIL PROTECTED] wrote: RinKaMeAri wrote: Hi! Could you imagine any way to block access to the base class public methods? Here is an example: class B: def public_method(): pass class A(B): def public_a_method(): pass def a = A() Is there any way to block the call a.public_method() without any changes to B class? Thank you! The simplest way would be to override B.public_method within A by defining A.public_method to raise a NotImplementedError or similar exception. Though of course this then begs the question of why A would need to subclass B in the first place, but I assume there would be methods you *did* want to implement. snip BTW, what do you mean to subclass B in the *first place*? Because you're inheriting from A and yet you don't want to inherit a certain part of A, in this case public_method(), it's usually a sign something is wrong with your class hierarchy; otherwise, you could just inherit from something else which would have just the part of A you want to inherit; it's a so-called code smell, specifically Refused Bequest I believe. See this link into Fowler's Refactoring for more info on Refused Bequest and the other code smells: http://books.google.com/books?id=1MsETFPD3I0Cpg=PA87lpg=PA87dq=refused+bequestsource=blots=pKN4o0QJc7sig=rYT4lfWxhKijvNHpLYqk8DY5Epwhl=ensa=Xoi=book_resultresnum=3ct=result Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Simple question about Python lists
I'm learning Python (while coming from MATLAB). One question I have is that if I have a list with say 8 elements, and I want just a few of them how do I select them out. In MATLAB, if I just want the first, fifth and eighth element I might do something like this: b = a([1 5 8]); I can't seem to figure out a similar Python construct for selecting specific indices. Any suggestions? Thanks, Eric -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question about Python lists
On Tue, 11 Nov 2008 11:47:53 -0800, Eric wrote: I'm learning Python (while coming from MATLAB). One question I have is that if I have a list with say 8 elements, and I want just a few of them how do I select them out. In MATLAB, if I just want the first, fifth and eighth element I might do something like this: b = a([1 5 8]); I can't seem to figure out a similar Python construct for selecting specific indices. Any suggestions? b = [a[i] for i in [1, 5, 8]] Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 and sqlite
Sqlite3 is an optional part of Python. It has no dependencies on SQLite. That's not true. To build the _sqlite3 module, you need the SQLite3 sources or binaries, in addition to the Python sources. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing a status line from a python script
Thanks guys for the ideas. Appreciate the help. Cheers. Chris -- http://mail.python.org/mailman/listinfo/python-list
Parsing: request for pointers
Hi everyone, I would like to implement a parser for a mini-language and would appreciate some pointers. The type of text I would like to parse is an extension of: http://www.websequencediagrams.com/examples.html For those that don't want to go to the link, consider the following, *very* simplified, example: === programmer Guido programmer Fredrik Lundh as effbot programmer Alex Martelli as martellibot programmer Tim Peters as timbot note left of effbot: cutting sense of humor note over martellibot: Offers detailed note, explaining a problem, accompanied by culinary diversion to the delight of the reader note over timbot: programmer clever as fox timbot - Guido: I give you doctest Guido -- timbot: Have you checked my time machine? === From this, I would like to be able to extract (programmer, Guido) (programmer as, Fredrik Lundh, effbot) ... (note left of, effbot, cutting sense of humor) (note over, martellibot, Offers...) (note over, timbot, 'programmer clever as fox') Some observations: 1. I want to use indentation to identify blocks. (the site I referred to uses end note which I don't want) 2. keywords (such as programmer, note over) can appear in text, and should not then be misidentified 3. I was thinking of using http://effbot.org/zone/simple-top-down-parsing.htm as a guide; however, it is not clear to me how it could be adapted to handle observations 1 and 2. (If it easily could, just a few pointers would be enough, and I'll start from there...) 4. I want to do this only using modules in the standard Python library, as I want to use this to learn about the basics of parsing. So, please don't *simply* suggest to use a third-party module, such as [1] plex, [2] yapps, [3] pyparsing The learning journey is more important for me than just having a canned solution to my (current) parsing problem. Cheers, André [1] http://www.cosc.canterbury.ac.nz/greg.ewing/python/Plex/ [2] http://theory.stanford.edu/~amitp/yapps/ [3] http://pyparsing.wikispaces.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 and sqlite
* Martin v. Löwis (Tue, 11 Nov 2008 20:54:37 +0100) Sqlite3 is an optional part of Python. It has no dependencies on SQLite. That's not true. To build the _sqlite3 module, you need the SQLite3 sources or binaries, in addition to the Python sources. That's not what I meant: the question is, do you need SQLite /after/ you've built from source or if you install the Python binary. Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] sqlite 0.8.3
* sandro (Tue, 11 Nov 2008 11:42:00 GMT) ANNOUNCE: sqlkit 0.8.3 November, 10 2008 I'm happy to announce release 0.8.3 of sqlkit package for python - the first public release. Are you aware that you announced sqlite 0.8.3 in the subject??!! Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Sync paramstyle between sqlite and mysql
* Jerry Hill (Tue, 11 Nov 2008 11:24:50 -0500) On Mon, Nov 10, 2008 at 1:00 PM, Daniel [EMAIL PROTECTED] wrote: I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that there are five paramstyles, though it wasn't clear if I should expect these to be implemented in all DBAPI2 compliant modules. I have found that I can set the paramstyle, but it doesn't seem to apply: As far as I understand it, paramstyle is informational, not a setting that you can change. You have no choice but to use the paramstyle that the provider of the dbapi-compliant module has chosen to use. Right. Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question about Python lists
On Tue, Nov 11, 2008 at 5:47 PM, Eric [EMAIL PROTECTED] wrote: I'm learning Python (while coming from MATLAB). One question I have is that if I have a list with say 8 elements, and I want just a few of them how do I select them out. In MATLAB, if I just want the first, fifth and eighth element I might do something like this: b = a([1 5 8]); I can't seem to figure out a similar Python construct for selecting specific indices. Any suggestions? MATLAB works with 1-based index, while Python is 0-based, so accessing the index number 8 wouldn't be valid with 8 elements here in Python. Now, to solve your problem you could either use the already suggested answer above mine or depending on what you what else you wanna do, you will feel more comfortable using numpy. Supposing you have a array with 8 elements: x = numpy.arange(8) To pull out the first, fifth and eighth elements you would do: x[numpy.array([0, 4, 7])] It is so no natural as it was in MATLAB, but well, it was a different language. Thanks, Eric -- http://mail.python.org/mailman/listinfo/python-list -- -- Guilherme H. Polo Goncalves -- http://mail.python.org/mailman/listinfo/python-list
sys.stdout, urllib and unicode... I don't understand.
Hello fellow pythonists, I'm a relatively new python developer, and I try to adjust my understanding about how things works to python, but I have hit a block, that I cannot understand. I needed to output unicode datas back from a web service, and could not get back unicode/multibyte text before applying an hack that I don't understand (thank you google) I have realized an wxPython simple application, that takes the input of a user, send it to a web service, and get back translations in several languages. The service itself is fully UTF-8. The source string is first encoded to latin1 after a passage into unicode.normalize(), as urllib.quote() cannot work on unicode srcText=unicodedata.normalize('NFKD',srcText).encode('latin1','ignore') After that, an urllib request is sent with this encoded string to the web service con=urllib2.Request(self.url, headers={'User-Agent':'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11'}, origin_req_host='http://translate.google.com') req=urllib2.urlopen(con) First problem, how to determine the encoding of the return ? If I inspect a request from firefox, I see that the server return header specify UTF-8 But if I use this code: ret=U'' for line in req: ret=ret+string.replace(line.strip(),'\n',chr(10)) I end up with an UnicodeDecodeError. I tried various line.decode(), line.normalize and such, but could not make this error disapear. I, until now, avoided that problem as the service always seems to return 1 line, but I am wondering. Second problem, if I try an print line into the loop, I too get the same error. I though that unicode() would force python to consider the given text as unicode, not to try to convert it to unicode. Here again, trying several normalize/decode combination did not helped at all. Then, looking for help through google, I have found this post: http://mail.python.org/pipermail/python-list/2007-October/462977.html and I gave it a try. What I did, though, was not to override sys.stdout, but to declare a new writer stream as a property of my main class: self.out=OutStreamEncoder(sys.stdout, 'utf-8') But what is strange, is that since I did that, even without using this self.out writer, the unicode translation are working as I was expecting them to. Except on the for loop, where a concatenation still triggers the UnicodeDecodeErro exception. I know the explicit is better than implicit python motto, and I really like it. But here, I don't understand what is going on. Does the fact that defining that writer object does a initialization of the standard sys.stdout object ? Does it is related to an internal usage of it, maybe in urllib ? I tried to find more on the subject, but felt short. Can someone explain to me what is happening ? The full script source can be found at http://www.webalis.com/translator/translator.pyw -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 and sqlite
On Tue, Nov 11, 2008 at 6:04 PM, Thorsten Kampe [EMAIL PROTECTED] wrote: * Martin v. Löwis (Tue, 11 Nov 2008 20:54:37 +0100) Sqlite3 is an optional part of Python. It has no dependencies on SQLite. That's not true. To build the _sqlite3 module, you need the SQLite3 sources or binaries, in addition to the Python sources. That's not what I meant: the question is, do you need SQLite /after/ you've built from source or if you install the Python binary. Is that some form of tricky question ? The binary package either comes with the sqlite lib, or in the case of linux distributions, the package requires the installation of sqlite lib. If you try removing the sqlite lib package (in Linux), the package manager will tell you that python depends on it. Thorsten -- http://mail.python.org/mailman/listinfo/python-list -- -- Guilherme H. Polo Goncalves -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 - is this true?
The sorting is in a performance-critical part of the system, so the overhead of evaluating a key function is not insignificant. Can you easily produce an example? It doesn't have to be real data, but should have the structure (typewise) of the real data. I would like to perform some measurements. For example, I could imagine that l = [] for i in range(1000): x = random.randint(0,100) if x 4: l.append(None) else: l.append(x) might adequately model your problem. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Has anyone tried calling zip.py in feedback.py and print out an innerHTML to provide a download link?
Hello, there. Has anyone tried calling zip.py in feedback.py and print out an innerHTML to provide a download link? I find difficult to make it work. Sincerely, David #** # Description: #Zips the contents of a folder. # Parameters: # 0 - Input folder. # 1 - Output zip file. It is assumed that the user added the .zip # extension. #** # Import modules and create the geoprocessor # import sys, zipfile, arcgisscripting, os, traceback gp = arcgisscripting.create() # Function for zipping files. If keep is true, the folder, along with # all its contents, will be written to the zip file. If false, only # the contents of the input folder will be written to the zip file - # the input folder name will not appear in the zip file. # def zipws(path, zip, keep): path = os.path.normpath(path) # os.walk visits every subdirectory, returning a 3-tuple # of directory name, subdirectories in it, and filenames # in it. # for (dirpath, dirnames, filenames) in os.walk(path): # Iterate over every filename # for file in filenames: # Ignore .lock files # if not file.endswith('.lock'): gp.AddMessage(Adding %s... % os.path.join(path, dirpath, file)) try: if keep: zip.write(os.path.join(dirpath, file), os.path.join(os.path.basename(path), os.path.join(dirpath, file)[len(path)+len(os.sep):])) else: zip.write(os.path.join(dirpath, file), os.path.join(dirpath[len(path):], file)) except Exception, e: gp.AddWarning(Error adding %s: %s % (file, e)) return None if __name__ == '__main__': try: # Get the tool parameter values # infolder = gp.GetParameterAsText(0) outfile = gp.GetParameterAsText(1) # Create the zip file for writing compressed data. In some rare # instances, the ZIP_DEFLATED constant may be unavailable and # the ZIP_STORED constant is used instead. When ZIP_STORED is # used, the zip file does not contain compressed data, resulting # in large zip files. # try: zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED) zipws(infolder, zip, True) zip.close() except RuntimeError: # Delete zip file if exists # if os.path.exists(outfile): os.unlink(outfile) zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_STORED) zipws(infolder, zip, True) zip.close() gp.AddWarning(Unable to compress zip file contents.) gp.AddMessage(Zip file created successfully) except: # Return any python specific errors as well as any errors from the geoprocessor # tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = PYTHON ERRORS:\nTraceback Info:\n + tbinfo + \nError Info:\n + str(sys.exc_type)+ : + str(sys.exc_value) + \n gp.AddError(pymsg) msgs = GP ERRORS:\n + gp.GetMessages(2) + \n gp.AddError(msgs) -- http://mail.python.org/mailman/listinfo/python-list
Re: Project layout / Import files from different subdirectories
Steve Holden schrieb: If you want shorter names in your main code, of course, you can use import project.main as main import project.gui.mainwindow as window or somethihg similar. regards Steve Yeah, I was going with the from x import y scheme by now, didn't know as was available as well. Perfect, that makes it a bit easier. Thanks! Markus -- PGP/GPG key 0x2EB39BF9 -- http://mail.python.org/mailman/listinfo/python-list
Re: etymology of list comprehension?
In article [EMAIL PROTECTED], Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] writes: Ah, thanks... and does comprehension have any special computer science meaning? It is from mathematical set theory. If you write something like { p | [some logical expression indicating that p is prime] } then that denotes a set (the set of all prime numbers). That every such formula names a set is called the axiom of comprehension. The above notation is sometimes called set-builder notation. Frege's original system of logic (late 19th century), now called naive set theory had unrestricted comprehension which meant you could say anything at all where the logical expression went. This made the system inconsistent, because of Russell's paradox (c is the class of all classes that are not members of themselves. So is c a member of itself?). Axiomatic set theory has a restricted axiom of comprehension that requires the logical expression to be a first order formula with a certain syntax, to avoid such paradoxes. Not that it matters, but the fix is not by using a first-order formula with a certain syntax. The comprehension itself is not {p | p satisfies some condition}, it's {p in S | p satisfies some condition}, where S is some set. You're not allowed to ask for _everything_ satisfying a certain condition, just for the elements of some given set satisfying the condition. The paradox doesn't come from being allowed to say anything at all. If you write (*) c = {x | ~(x e x)} (where ~ means not and a e b means a is an element of b) you get Russell's paradox: if c is an element of c then it follows that c is not an element of c, while if c is not an element of c then it follows that c is an element of c. The problem is not with the formula ~(x e x); given a set S, there's no problem with the set {x in S | ~(x e x)}, for example. restricted versus unrestricted does not refer to some restriction on that formula - the restriction in restricted comprehension is the x in S part - we're restricting things to elements of a given set S. Writing informally people often omit the in S part when the S in clear from the context. For example, your original {p | p is prime} should officially be {p in N | p is prime}, where N is the set of natural numbers - the first form is often written because the in N is implicit in prime. Anyway, list comprehensions in programming languages got their name because of their resemblance to set-builder notation that invoked the axiom of comprehension. -- David C. Ullrich -- http://mail.python.org/mailman/listinfo/python-list
Re: [Newbie] Strange output from list
Chris Rebert wrote: On Tue, Nov 11, 2008 at 12:56 AM, Gilles Ganault [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 20:02:39 -0600, Andrew [EMAIL PROTECTED] wrote: sql = 'SELECT id FROM master' rows=list(cursor.execute(sql)) for id in rows: sql = 'SELECT COUNT(code) FROM companies WHERE code=%s' % id[0] result = list(cursor.execute(sql)) print Code=%s, number=%s % (id[0],result[0][0]) Using liberal term rewriting, consider the following rough equivalencies in the code: id[0] == rows[INDEX_HERE][0] == list(cursor.execute(sql))[INDEX_HERE][0] result[0][0] == list(cursor.execute(sql))[0][0] Note that in both cases, the list is sliced twice; the for-loop just conceals the `[INDEX_HERE]` implicit slicing that is caused by iterating over the list. You might also want to consider saving some time by using a SQL solution (assuming SQLite supports it, which it should) (untested): cursor.execute( SELECT master.id, count(companies.code) FROM master JOIN companies ON master.id = companies.code GROUP BY companies.code) for id, count in cursor.fetchall(): print Code=%s, number=%s % (id, count) I'd like to think it makes the Python a bit more readable too ... regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 and sqlite
* Thorsten Kampe (Tue, 11 Nov 2008 10:45:28 +0100) * (Mon, 10 Nov 2008 18:48:28 -0500) Can you ask them if sqlite3 is installed? and if not... to install it? Why would he have to install SQLite?! You could include in your discussions well sqlite3 is part of python if it isn't, you haven't installed python properly Sqlite3 is an optional part of Python. It has no dependencies on SQLite. It seems it's not that simple. On a Gentoo host the SQLite package provided the necessary library. On a openSUSE host it was libsqlite. From my understanding SQLite (the headers) is only needed for building python with SQLite support (or pysqlite) from scratch. Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 and sqlite
That's not what I meant: the question is, do you need SQLite /after/ you've built from source or if you install the Python binary. Depends on how you built SQLite on your system. If it was a static library, you won't need it - if it is a shared library, you certainly need the shared library at run-time. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question about Python lists
Guilherme Polo wrote: On Tue, Nov 11, 2008 at 5:47 PM, Eric [EMAIL PROTECTED] wrote: I'm learning Python (while coming from MATLAB). One question I have is that if I have a list with say 8 elements, and I want just a few of them how do I select them out. In MATLAB, if I just want the first, fifth and eighth element I might do something like this: b = a([1 5 8]); I can't seem to figure out a similar Python construct for selecting specific indices. Any suggestions? MATLAB works with 1-based index, while Python is 0-based, so accessing the index number 8 wouldn't be valid with 8 elements here in Python. Now, to solve your problem you could either use the already suggested answer above mine or depending on what you what else you wanna do, you will feel more comfortable using numpy. Supposing you have a array with 8 elements: x = numpy.arange(8) To pull out the first, fifth and eighth elements you would do: x[numpy.array([0, 4, 7])] Actually, x[[0,4,7]] will work just as well. -- 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: Simple question about Python lists
On Nov 11, 1:51 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Tue, 11 Nov 2008 11:47:53 -0800, Eric wrote: I'm learning Python (while coming from MATLAB). One question I have is that if I have a list with say 8 elements, and I want just a few of them how do I select them out. In MATLAB, if I just want the first, fifth and eighth element I might do something like this: b = a([1 5 8]); I can't seem to figure out a similar Python construct for selecting specific indices. Any suggestions? b = [a[i] for i in [1, 5, 8]] Ciao, Marc 'BlackJack' Rintsch Thanks! It makes sense, but in this case MATLAB seems easier and no less readable. That said, I know better than for a newbie like me to question syntax issues. Regards, Eric -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 and sqlite
* Martin v. Löwis (Tue, 11 Nov 2008 21:40:44 +0100) That's not what I meant: the question is, do you need SQLite /after/ you've built from source or if you install the Python binary. Depends on how you built SQLite on your system. If it was a static library, you won't need it - if it is a shared library, you certainly need the shared library at run-time. Aah, thanks. Makes sense a lot. There were quite a few people here in the last few days who asked how to build or use Python (or pysqlite) when SQLite is not installed (and they can't because it's not their system). I always said that it's not necessary to have SQLite installed for /running/ Python. Seems that I was 65% right. Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Re: concurrency program design stackless python tasklet or python thread?
In article [EMAIL PROTECTED], davy zhang [EMAIL PROTECTED] wrote: first here is my basic idea is every actor holds their own msg queue, the process function will handle the message as soon as the dispatcher object put the message in. Sounds like a standard design. This idea naturally leads me to place every actor in a separate thread waiting for msg but the rumor has it, stackless python with tasklet and channel can do much more better in concurrency program, so I dive my head into it. but I found the tasklet is really a lined-up sequence , that means if a tasklet blocked or do some time consuming calculation, the other tasklets can not get the cpu slice so we must design very carefully to avoid the big job for single task I am just confused why the stackless python is said to be good at concurrency program model or just I get a wrong idea to practice? Well, you have to be a bit careful, but Stackless is definitely one good approach to handling your design. For example, EVE Online is an MMORPG written in Python with a similar design. That said, I personally have trouble wrapping my brain around Stackless, so I'd probably choose a different technique. -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ It is easier to optimize correct code than to correct optimized code. --Bill Harlan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 - is this true?
On 2008-11-11 02:10, Steven D'Aprano wrote: On Mon, 10 Nov 2008 12:51:51 +, Duncan Grisby wrote: I have an object database written in Python. It, like Python, is dynamically typed. It heavily relies on being able to sort lists where some of the members are None. To some extent, it also sorts lists of other mixed types. It will be very hard to migrate this aspect of it to Python 3. No, it is very hard to sort *arbitrary* objects consistently. If it appears to work in Python 2.x that's because you've been lucky to never need to sort objects that cause it to break. If you read Duncan's email, he isn't talking about arbitrary objects at all. He's just referring to being able to sort lists that contain None elements. That's far from arbitrary and does work consistently in Python 2.x - simply because None is a singleton which is special cased in Python: None compares smaller to any other object in Python. I'm not sure why this special case was dropped in Python 3.0. None is generally used to be a place holder for a n/a-value and as such will pop up in lists on a regular basis. I think the special case for None should be readded to Python 3.0. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 11 2008) 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 mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX 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://mail.python.org/mailman/listinfo/python-list
Are there any FOSS Python Single-Sign-on Servers?
Are there any FOSS Python Single-Sign-on Servers? We're looking to centralise the sign-on for our numerous internal webapps (across multiple servers, languages, and domains) to speed user management and application development. I've searched around but can only seem to find OpenID servers, which will probably be too open for our needs. Coding one up would possibly take more time than we have, and we'd prefer something maintained externally to cut dev costs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple question about Python lists
Eric wrote: On Nov 11, 1:51 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Tue, 11 Nov 2008 11:47:53 -0800, Eric wrote: I'm learning Python (while coming from MATLAB). One question I have is that if I have a list with say 8 elements, and I want just a few of them how do I select them out. In MATLAB, if I just want the first, fifth and eighth element I might do something like this: b = a([1 5 8]); I can't seem to figure out a similar Python construct for selecting specific indices. Any suggestions? b = [a[i] for i in [1, 5, 8]] Ciao, Marc 'BlackJack' Rintsch Thanks! It makes sense, but in this case MATLAB seems easier and no less readable. That said, I know better than for a newbie like me to question syntax issues. In my experience, I never do this with lists so there's no optimized syntax for it. I do use it very often with numpy arrays, and that does have optimized syntax. -- 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: subprocess communication, exec()
On Tue, Nov 11, 2008 at 9:39 PM, Jeff McNeil [EMAIL PROTECTED] wrote: On Nov 11, 1:23 pm, Chuckk Hubbard [EMAIL PROTECTED] wrote: If I run 'python -i subprocessclient.py' I expect to see the nice level of it go up 2, and the nice level of the subprocess go up 1. But all I see is the nice level of the client change. What am I doing wrong? subprocessserver.py: #!/usr/bin/python2.5 import os import sys while True: next_line = sys.stdin.readline() if not next_line: break exec(next_line) #sys.stdout.write(output) #sys.stdout.write(next_line) #sys.stdout.flush() subprocessclient.py: #!/usr/bin/python2.5 import subprocess, os server = subprocess.Popen(('python2.5', 'subprocessserver.py'), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) os.nice(2) server.stdin.write('''os.nice(1)''') Thanks. -Chuckk --http://www.badmuthahubbard.com Looks like you're dropping an error by redirecting the child process' standard error into a pipe. First off, remove the stderr=subprocess.PIPE from subprocessclient.py. When you do so, you'll start seeing an error message whenever your code runs: [EMAIL PROTECTED] ~]$ python client.py None [EMAIL PROTECTED] ~]$ Traceback (most recent call last): File stdin, line 1, in module NameError: name 'os' is not defined That doesn't make a lot of sense at first, until you consider the following: [EMAIL PROTECTED] ~]$ echo 'os.nice(1)' | python Traceback (most recent call last): File stdin, line 1, in module NameError: name 'os' is not defined The Python interpreter is trying to execute the data you write to the stdin of the child process. Changing the Popen line to use the string form rather than the sequence form remedies the problem, as does changing 'string=True' to 'string=False.' The reason? Because when you set shell=True, additional arguments in args sequence are passed as additional arguments to the shell itself, not to the command. From subprocess.py: if isinstance(args, types.StringTypes): args = [args] else: args = list(args) if shell: args = [/bin/sh, -c] + args So, in your attempt, you're effectively doing the following: /bin/sh -c python2.5 server.py When you want: /bin/sh -c python2.5 server.py HTH, Jeff That helps immensely, Jeff, thank you for explaining all that. I took out 'shell=True' and it works, and I took out the stdout and stderr arguments to debug. I am finally able to perform every step in my plan: start a child process of python running a script that imports the Csound API; raise the nice level of the parent process; compile and run a Csound orchestra remotely; and send it notes from the parent process. Thanks for your help. -Chuckk -- http://www.badmuthahubbard.com -- http://mail.python.org/mailman/listinfo/python-list
Re: module cwiid and threading: how to use cwiid.Wiimote without blocking
The only solution, that I found was recompiling the libcwiid wrapper, such that it allows threading (the patch existed already on the libcwiid Trac data base, though it's not part of an official release) bye N News123 wrote: Hi, I'm using the module cwiid to conncet to a wiimote. import cwiid wiimote = cwiid.Wiimote() This function is blocking: It waits until it could sucessfully connect to a device or until 20 seconds passed without sucessful connection. As I wanted to do some things even if the wii-mote is not connected I though about creating a thread, which tries connecting until it is sucessfully connected and let the application do something else meanwhile. Unfortunately it seems, that the call to cwiid.Wiimote() blocks all threads. Probably the call to Wiimote() doesn't release the GIL. So my question: Is there anybody knowing if there's any trick in python or in libcwiid to avoid this 'complete block' The only idea, that I have is to do the polling in a second process. I'm just not sure though how I could pass the sucessfully connected device to the parent process without creating pipes or thanks for any ideas and bye N P.S. Attached a test script and its output: #[code] import os,sys,time,threading,cwiid class wii_thread(threading.Thread): def run(self): wm = None while not wm: try: print try to connect wm=cwiid.Wiimote() except: print Didn't find wiimote will retry time.sleep(0.5) print setup wiimote,poll and queue wii events time.sleep(1000) if __name__ == '__main__': wii_thrd = wii_thread() wii_thrd.start() while True: print 'do something' time.sleep(1) #[code end] # the output ## do something try to connect No wiimotes found Didn't find wiimote will retry do something try to connect setup wiimote,poll and queue wii events do something do something do something Traceback (most recent call last): File ./threadprob.py, line 22, in module time.sleep(1) KeyboardInterrupt -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Python 2.5.3: call for patches
Martin v. Löwis schrieb: Within a few weeks, we will release Python 2.5.3. This will be the last bug fix release of Python 2.5, afterwards, future releases of 2.5 will only include security fixes, and no binaries (for Windows or OSX) will be provided anymore (from python.org). In principle, the release will include all changes that are already on the release25-maint branch in subversion [1]. If you think that specific changes should be considered, please create an issue in the bug tracker [2], and label it with the 2.5.3 version. Backports of changes that are already released in Python 2.6 but may apply to 2.5 are of particular interest. I would like to apply fixes for some CVE's which are addressed in 2.5 but not yet in 2.4. this would include CVE-2007-4965 CVE-2008-1679 CVE-2008-1721 CVE-2008-2315 CVE-2008-3144 CVE-2008-1887 CVE-2008-4864 Matthias -- http://mail.python.org/mailman/listinfo/python-list
Re: wildcard match with list.index()
Thanks, I just have to choose which one to use :) -- http://mail.python.org/mailman/listinfo/python-list
SHA1withRSA in python
Hi all, in java there are several libraries for sha1withrsa, there is something similar in python? thanks Nicola -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 - is this true?
Terry Reedy wrote: M.-A. Lemburg wrote: I think the special case for None should be readded to Python 3.0. Quick summary of thread that MAL started on Python-3000-dev list: Once upon a time, 0 None was true. When rich comparisons were added, None 0 (and *most* other things) become true as an intentionally undocumented implementation detail. The None rule only applies for sure when None controls the comparison: ob None is true or undefined if type(ob) says so. Guido's pronouncement: In short, I'll have None of it. summarizing We're not going to add the feature back that None compares smaller than everything. It's a slippery slope that ends with all operations involving None returning None -- I've seen a proposal made in all earnestness requesting that None+42 == None, None() == None, and so on. This Nonesense was wisely rejected; a whole slew of early-error-catching would have gone out of the window. It's the same with making None smaller than everything else. For numbers, you can already use -inf; for other types, you'll have to invent your own Smallest if you need it. tjr This still doesn't explain why None should not be comparable to itself. -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there any FOSS Python Single-Sign-on Servers?
Phillip B Oldham schrieb: Are there any FOSS Python Single-Sign-on Servers? [snip] I've searched around but can only seem to find OpenID servers, which will probably be too open for our needs. So if it is not OpenID, which protocol are you going to implement? cheers Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 and sqlite
* (Mon, 10 Nov 2008 18:48:28 -0500) Quoting [EMAIL PROTECTED] [EMAIL PROTECTED]: On a (sun) webserver that I use, there is python 2.5.1 installed. I'd like to use sqlite3 with this, however sqlite3 is not installed on the webserver. If I were able to compile sqlite using a sun machine (I normally use linux machines) and place this in my lunix home account would I be able to use python and sqlite? Any thoughts? I know its a bit of a stretch ... Can you ask them if sqlite3 is installed? and if not... to install it? Why would he have to install SQLite?! You could include in your discussions well sqlite3 is part of python if it isn't, you haven't installed python properly Sqlite3 is an optional part of Python. It has no dependencies on SQLite. Thorsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Final Python Class of 2009
Steven D'Aprano wrote: On Mon, 10 Nov 2008 22:14:16 -0500, Steve Holden wrote: Subject: Final Python Class of 2009 Steve, have you been in Guido's time machine again? :-) No, honest (hides hands behind back). regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Project layout / Import files from different subdirectories
On Tue, Nov 11, 2008 at 7:08 AM, Markus Mayer [EMAIL PROTECTED] wrote: Steve Holden schrieb: If you want shorter names in your main code, of course, you can use import project.main as main import project.gui.mainwindow as window or somethihg similar. regards Steve Are explicit relative imports applicable here? Could he do a from .. import project.main as main without adding another __init__.py? Or do I have my head screwed on funny? -- http://mail.python.org/mailman/listinfo/python-list
Re: Project layout / Import files from different subdirectories
If your main file is in the root of the project, you can just use absolute imports. So you can use gui.anotherwindow or project.important from all files. I'm not sure this is good practice though... I was first under the impression that you can always import modules that are in your current working dir. But this seems to not always work... Almar 2008/11/11 Jeremiah Dodds [EMAIL PROTECTED]: On Tue, Nov 11, 2008 at 7:08 AM, Markus Mayer [EMAIL PROTECTED] wrote: Steve Holden schrieb: If you want shorter names in your main code, of course, you can use import project.main as main import project.gui.mainwindow as window or somethihg similar. regards Steve Are explicit relative imports applicable here? Could he do a from .. import project.main as main without adding another __init__.py? Or do I have my head screwed on funny? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: IBM integer and double formats
On Nov 11, 12:07 pm, Mark Dickinson [EMAIL PROTECTED] wrote: All character data are stored in ASCII, regardless of the operating system. But character data is not the same thing as numeric data. Okay--- you win again, John. Sheesh. [...] Apologies for annoying you. Mark -- http://mail.python.org/mailman/listinfo/python-list
[ANN] sqlite 0.8.3
ANNOUNCE: sqlkit 0.8.3 November, 10 2008 I'm happy to announce release 0.8.3 of sqlkit package for python - the first public release. http://sqlkit.argolinux.org/ The package --- SQLkit PyGtk package provides Mask and Table widgets to edit database data. It's meant as a base for database desktop applications. The application --- It also provides 'sqledit' a PyGTK application based on sqlkit that can be used from command line to browse and edit data. The package has 2 very rich demo suites for sql widgets (the main one in sqlkit/demo/sql/demo.py) and for layout creation Main features of sqlkit: * editor of databases in 2 modes: table mask * based on sqlalchemy: can cope with many different databases * very powerfull filtering capabilities: - each field can be used to filter records - filter may span relationship - date filtering possible also on relative basis (good for saved queries) * completion on all text field and foreign keys * very easy way to draw a layout for mask views * completely effortless editing of relationships * very easy way to set defaults * possibility to display totals of numeric fields * any possible sql constraint can be attached to a Mask or a Table. It can be expressed a s a normal sqlalchemy query or with django-like syntax * sqledit: python script to edit db Sqlkit is based on: --- * python (= 2.4) * PyGtk * Sqlalchemy (= 0.5) * glade * dateutils Dowload more: --- * http://docs.argolinux.org/sqlkit/sqlkit/download.html * hg clone http://hg.argolinux.org/py/sqlkit * google group: http://groups.google.it/group/sqlkit/ * License: GNU GPL -- http://mail.python.org/mailman/listinfo/python-list
Bug in PIL 1.1.6
Hi again. I seem to have stumbled over a bug in PIL 1.1.6's ImageQt module. It has problems with _some_ GIFs, which appear sheared after the conversion. Seems to be a scanline length problem or something. ImageQt(Image.open(specific_gif_file)) displayed using a PyQt4 painter. Any idea where I should send this (and/or more) information to? Best regards, Markus -- PGP/GPG key 0x2EB39BF9 -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange output from list
On Nov 11, 10:47 pm, Steve Holden [EMAIL PROTECTED] wrote: Chris Rebert wrote: On Tue, Nov 11, 2008 at 12:56 AM, Gilles Ganault [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 20:02:39 -0600, Andrew [EMAIL PROTECTED] wrote: sql = 'SELECT id FROM master' rows=list(cursor.execute(sql)) for id in rows: sql = 'SELECT COUNT(code) FROM companies WHERE code=%s' % id[0] result = list(cursor.execute(sql)) print Code=%s, number=%s % (id[0],result[0][0]) Using liberal term rewriting, consider the following rough equivalencies in the code: id[0] == rows[INDEX_HERE][0] == list(cursor.execute(sql))[INDEX_HERE][0] result[0][0] == list(cursor.execute(sql))[0][0] Note that in both cases, the list is sliced twice; the for-loop just conceals the `[INDEX_HERE]` implicit slicing that is caused by iterating over the list. You might also want to consider saving some time by using a SQL solution (assuming SQLite supports it, which it should) (untested): cursor.execute( SELECT master.id, count(companies.code) FROM master JOIN companies ON master.id = companies.code GROUP BY companies.code) Shouldn't it be GROUP BY master.id? I would have thought that SQL would be sad about a non-aggregate (master.id) that's in the SELECT list but not also in the GROUP BY list. for id, count in cursor.fetchall(): print Code=%s, number=%s % (id, count) I'd like to think it makes the Python a bit more readable too ... Agreed. result[0][0] is an abomination. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sync paramstyle between sqlite and mysql
On Mon, Nov 10, 2008 at 1:00 PM, Daniel [EMAIL PROTECTED] wrote: I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that there are five paramstyles, though it wasn't clear if I should expect these to be implemented in all DBAPI2 compliant modules. I have found that I can set the paramstyle, but it doesn't seem to apply: As far as I understand it, paramstyle is informational, not a setting that you can change. You have no choice but to use the paramstyle that the provider of the dbapi-compliant module has chosen to use. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
f2py usage problem
Hi Python gurus, I have installed numpy and interested in testing f2py module using the first example in the documentation. First I tried: C:\testpython C:\Program Files\Python25\Scripts\f2py.py -c fib1.f running build running config_cc unifing config_cc, config, build_clib, build_ext, build commands -- compiler options running config_fc unifing config_fc, config, build_clib, build_ext, build commands -- fcompiler options running build_src building extension untitled sources f2py options: [] f2py: c:\docume~1\e6462\locals~1\temp\tmpzcktrq \src.win32-2.5\untitledmodule.c creating c:\docume~1\e6462\locals~1\temp\tmpzcktrq creating c:\docume~1\e6462\locals~1\temp\tmpzcktrq\src.win32-2.5 Reading fortran codes... Reading file 'fib1.f' (format:fix,strict) Post-processing... Block: untitled Block: fib Post-processing (stage 2)... Building modules... Building module untitled... Constructing wrapper function fib... fib(a,[n]) Wrote C/API module untitled to file c: \docume~1\e6462\locals~1\temp\tmpzcktrq\src.win32-2.5/ untitledmodule.c adding 'c:\docume~1\e6462\locals~1\temp\tmpzcktrq \src.win32-2.5\fortranobject.c' to sources. adding 'c:\docume~1\e6462\locals~1\temp\tmpzcktrq\src.win32-2.5' to include_dirs. copying C:\Progra~1\python25\lib\site-packages\numpy-1.0.4.0002-py2.5- win32.egg\ numpy\f2py\src\fortranobject.c - c:\docume~1\e6462\locals~1\temp \tmpzcktrq\src.win32-2.5 copying C:\Progra~1\python25\lib\site-packages\numpy-1.0.4.0002-py2.5- win32.egg\ numpy\f2py\src\fortranobject.h - c:\docume~1\e6462\locals~1\temp \tmpzcktrq\src.win32-2.5 running build_ext No module named msvccompiler in numpy.distutils; trying from distutils error: Python was built with Visual Studio 2003; extensions must be built with a compiler than can generate compatible binaries. Visual Studio 2003 was not found on this system. If you have Cygwin installed, you can try compiling with MingW32, by passing -c mingw32 to setup.py. Then I installed mingw32 and tried to pass -c mingw32 to setup.py as below, but got another error: C:\testspython C:\Program Files\Python25\Lib\site-packages \numpy-1.0.4.0002-py2.5-win32.egg\numpy\f2py\setup.py -c mingw32 Warning: Assuming default configuration (C:\Program Files\Python25\Lib \site-pack ages\numpy-1.0.4.0002-py2.5-win32.egg\numpy\f2py\lib\parser/ {setup_parser,setup}.py was not found) Appending f2py.lib.parser configuration to f2py.lib Ignoring attempt to set 'name' (from 'f2py.lib' to 'f2py.lib.parser') Warning: Assuming default configuration (C:\Program Files\Python25\Lib \site-packages\numpy-1.0.4.0002-py2.5-win32.egg\numpy\f2py\lib\extgen/ {setup_extgen,setup}.py was not found) Appending f2py.lib.extgen configuration to f2py.lib Ignoring attempt to set 'name' (from 'f2py.lib' to 'f2py.lib.extgen') Appending f2py.lib configuration to f2py Ignoring attempt to set 'name' (from 'f2py' to 'f2py.lib') F2PY Version 2_4422 Traceback (most recent call last): File C:\Program Files\Python25\Lib\site-packages\numpy-1.0.4.0002- py2.5-win32.egg\numpy\f2py\setup.py, line 130, in module **config) TypeError: setup() got multiple values for keyword argument 'version' Version (as printed out to be 2_4422) doesn't look like to be multiple value as the message says... I have tried different machine with different python version installation (2.5, 2.4) and also searched the forum without finding my answer. Is there anybody out there so kind as to help me with this? Thanks... /Ben -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there any FOSS Python Single-Sign-on Servers?
On Nov 11, 9:24 pm, paul [EMAIL PROTECTED] wrote: Phillip B Oldham schrieb: Are there any FOSS Python Single-Sign-on Servers? [snip] I've searched around but can only seem to find OpenID servers, which will probably be too open for our needs. So if it is not OpenID, which protocol are you going to implement? In theory, we could use an OpenID server: our staff could register with something like MyOpenID, register with each of our individual webapps, and then gain access with a single sign-on. However, its not really getting round the problem we have: we need to give our staff access to all of our apps in one go, give them one place to sign on, and have the ability to disable their account at short notice. Doing this with openid would mean we have *no* access to the user account and therefore would still have the overhead of having to disable accounts with each webapp we provide. It also opens-up a security threat in that anyone could register to our internal apps with an OpenID account. Which is bad. Essentially, we need a SSO server with which we would register our *webapps* and then create user account, specifying which webapps that user has access to, and at what level. Essentially something like OpenSSO but python-based. -- http://mail.python.org/mailman/listinfo/python-list
Wing IDE 3.1.5 released
Hi, Wingware has released version 3.1.5 of Wing IDE, a bugfix release for all three product levels of Wing IDE. *Release Highlights* This release includes the following: * Avoid auto-starting batch searches when a new project is opened * Several vi mode fixes * Added debug 'watch' item to editor context menu * Recognize type of 'x' in 'from x import y' * Allow debugger to start even if replacing sys.stdin fails * Store list of test files in shared project file (*.wpr) * About 16 other bug fixes: see the change log for details: http://wingware.com/pub/wingide/3.1.5/CHANGELOG.txt *Downloads* Wing IDE Professional and Wing IDE Personal are commercial software and require a license to run. A free trial license can be obtained directly from the product when launched. Wing IDE Pro 3.1.5http://wingware.com/downloads/wingide/3.1 Wing IDE Personal 3.1.5 http://wingware.com/downloads/wingide-personal/3.1 Wing IDE 101 3.1.5http://wingware.com/downloads/wingide-101/3.1 *About Wing IDE* Wing IDE is an integrated development environment for the Python programming language. It provides powerful debugging, editing, code intelligence, testing, and search capabilities that reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching entry level programming courses with Python. System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE 3.1 supports Python versions 2.0.x through 2.5.x. *New Features in Wing 3.1* This release adds the following features not found in Wing 3.0.x: * Support for zip archives * Support for pkg_resources name spaces and eggs * Support for doctest and nose style unit tests (*) * Scan for sys.path changes such as those used in buildout * How-To and support for Google App Engine * Inline context appropriate templates/snippets integrated with autocompleter (*) * Word list driven auto-completion in non-Python files (**) * Quick navigation to files and symbols by typing a fragment (**) * Improved support for Stackless Python * Preference to strip trailing white space on save * Display gi_running and gi_frame for generators * Improved code analysis for Python 2.5 * Other minor features and bug fixes not found in Wing 3.0.x (*)'d items are available in Wing IDE Professional only. (**)'d items are available in Wing IDE Personal or Professional only. Please see the change log for a detailed list of changes: http://wingware.com/pub/wingide/3.1.5/CHANGELOG.txt *Purchasing and Upgrading* Wing 3.1 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Any 2.x license sold after May 2nd 2006 is free to upgrade; others cost 1/2 the normal price to upgrade. Upgrade a 2.x license: https://wingware.com/store/upgrade Purchase a 3.x license:https://wingware.com/store/purchase -- The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange output from list
Steve Holden wrote in news:mailman.3804.1226412496.3487.python- [EMAIL PROTECTED] in comp.lang.python: Shouldn't it be GROUP BY master.id? I would have thought that SQL would be sad about a non-aggregate (master.id) that's in the SELECT list but not also in the GROUP BY list. Well, I did say untested. But in SQL Server, for example, any field argument to COUNT() must be an aggregated column. So it may depend on the SQL implementation. I should really have said You must mean an SQL Server other than the Microsofts one, as: select count( aid ) as count from table_1 group by aid count --- 8 8 8 8 8 8 8 8 (8 row(s) affected) and: select count( aid ) as count from table_1 count --- 64 (1 row(s) affected) Like it should. Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug in PIL 1.1.6
[EMAIL PROTECTED] schrieb: Markus Mayer: Any idea where I should send this (and/or more) information to? You can send your note and and image to effbot. You can also put an image online somewhere and give here the link (a small image, to avoid saturating your server, etc) so people can test it. Okay, for the tip, here we go: http://www.defx.de/usenet/imgqtbug/index.html I included a small test case that shows this behavior. Regards, Markus -- PGP/GPG key 0x2EB39BF9 -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug in PIL 1.1.6
Steve Holden schrieb: [EMAIL PROTECTED] wrote: From http://www.pythonware.com/products/pil/ You can join the Image SIG via python.org's subscription page, or by sending a mail to [EMAIL PROTECTED] Put subscribe in the message body to automatically subscribe to the list, or help to get additional information. Hum, I was hoping I could avoid that. :/ (The list, of course) Markus -- PGP/GPG key 0x2EB39BF9 -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding the instance reference of an object [long and probably boring]
greg wrote: Arnaud Delobelle wrote: But in the course of conversation I might refer to Napoleon, meaning Napoleon Bonaparte (1769 - 1821) or Napoleon III (1808 - 1873). That's more like referring to the name 'Napoleon' in two different namespaces. The original binding still exists, you're just switching contexts. My point was to get away from a model for Python which was built on its likely implementation and to hint that we can build one using the naive concept of 'name for a thing' instead. I don't believe it's possible to build any complete and correct model of Python behaviour without including some concept equivalent to a reference. You can talk about names written on PostIt notes and such like, but that only gets you a short way. It doesn't easily handle names in different namespaces, or references that exist without simple names, e.g. list and tuple items. Trying to repair these deficiencies only leads to increasingly bizarre and contrived mental pictures. +1 On the other hand, if you explicitly include the concept of a reference from the beginning, everything is quite clear and consistent. Yes. References do explain things very well, since the model is in exact agreement with the reality of the implementation. In other words, the model should be as simple as possible but no simpler. Leaving out references makes it too simple. Another point I'd like to make is that there is nothing inherently low-level about the concept of a reference. It doesn't have to be implemented as a memory address or any other particular machine-level thing. It's possible to talk about Python object references in a completely implementation-independent way. Indeed one might make use of some object store, and references would still be useful even if they weren't memory addresses. Also, just because you don't explicitly refer to them and manipulate them at the language level doesn't mean they don't exist. To think otherwise is like thinking that air doesn't exist just because you can't see it. There are plenty of experiments which clearly indicate its existence. Likewise, there are plenty of experiments that you can perform with any Python interpreter that reveal the existence of references, or something equivalent to them. Good stuff. I have come to the conclusion that this thread is mostly best left alone, since the remaining participants appear to have agreed on Python's semantics and now continue to argue about what name should be used to describe them. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug in PIL 1.1.6
[EMAIL PROTECTED] wrote: Markus Mayer: Any idea where I should send this (and/or more) information to? You can send your note and and image to effbot. You can also put an image online somewhere and give here the link (a small image, to avoid saturating your server, etc) so people can test it. From http://www.pythonware.com/products/pil/ You can join the Image SIG via python.org's subscription page, or by sending a mail to [EMAIL PROTECTED] Put subscribe in the message body to automatically subscribe to the list, or help to get additional information. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.stdout, urllib and unicode... I don't understand.
Thierry wrote: Hello fellow pythonists, I'm a relatively new python developer, and I try to adjust my understanding about how things works to python, but I have hit a block, that I cannot understand. I needed to output unicode datas back from a web service, and could not get back unicode/multibyte text before applying an hack that I don't understand (thank you google) I have realized an wxPython simple application, that takes the input of a user, send it to a web service, and get back translations in several languages. The service itself is fully UTF-8. The source string is first encoded to latin1 after a passage into unicode.normalize(), as urllib.quote() cannot work on unicode srcText=unicodedata.normalize('NFKD',srcText).encode('latin1','ignore') urllib.quote() operates on byte streams. If your web service is UTF-8 it would make sense to use UTF-8 as input encoding not latin1, wouldn't it? unicodeinput.encode(utf-8) After that, an urllib request is sent with this encoded string to the web service con=urllib2.Request(self.url, headers={'User-Agent':'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11'}, origin_req_host='http://translate.google.com') req=urllib2.urlopen(con) First problem, how to determine the encoding of the return ? It is sent as part of the headers. e.g. content-type: text/html; charset=utf-8 If I inspect a request from firefox, I see that the server return header specify UTF-8 But if I use this code: ret=U'' for line in req: ret=ret+string.replace(line.strip(),'\n',chr(10)) I end up with an UnicodeDecodeError. I tried various line.decode(), line.normalize and such, but could not make this error disapear. I, until now, avoided that problem as the service always seems to return 1 line, but I am wondering. web server answer is encoded byte stream too (usually utf-8 but you can check the headers) so line.decoce(utf-8) should give you unicode to operate on (always do string operations on canonized form) Second problem, if I try an print line into the loop, I too get the same error. I though that unicode() would force python to consider the given text as unicode, not to try to convert it to unicode. But it is what it does. Basically unicode() is a constructor for unicode objects. Here again, trying several normalize/decode combination did not helped at all. Its not too complicated, you just need to keep unicode and byte strings separate and draw a clean line between the two. (the line is decode() and encode() ) Then, looking for help through google, I have found this post: http://mail.python.org/pipermail/python-list/2007-October/462977.html and I gave it a try. What I did, though, was not to override sys.stdout, but to declare a new writer stream as a property of my main class: self.out=OutStreamEncoder(sys.stdout, 'utf-8') This is fancy but not needed if you take care like above. HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange output from list
John Machin wrote: On Nov 11, 10:47 pm, Steve Holden [EMAIL PROTECTED] wrote: Chris Rebert wrote: On Tue, Nov 11, 2008 at 12:56 AM, Gilles Ganault [EMAIL PROTECTED] wrote: On Mon, 10 Nov 2008 20:02:39 -0600, Andrew [EMAIL PROTECTED] wrote: sql = 'SELECT id FROM master' rows=list(cursor.execute(sql)) for id in rows: sql = 'SELECT COUNT(code) FROM companies WHERE code=%s' % id[0] result = list(cursor.execute(sql)) print Code=%s, number=%s % (id[0],result[0][0]) Using liberal term rewriting, consider the following rough equivalencies in the code: id[0] == rows[INDEX_HERE][0] == list(cursor.execute(sql))[INDEX_HERE][0] result[0][0] == list(cursor.execute(sql))[0][0] Note that in both cases, the list is sliced twice; the for-loop just conceals the `[INDEX_HERE]` implicit slicing that is caused by iterating over the list. You might also want to consider saving some time by using a SQL solution (assuming SQLite supports it, which it should) (untested): cursor.execute( SELECT master.id, count(companies.code) FROM master JOIN companies ON master.id = companies.code GROUP BY companies.code) Shouldn't it be GROUP BY master.id? I would have thought that SQL would be sad about a non-aggregate (master.id) that's in the SELECT list but not also in the GROUP BY list. Well, I did say untested. But in SQL Server, for example, any field argument to COUNT() must be an aggregated column. So it may depend on the SQL implementation. I should really have said GROUP BY master.id, companies.code which is the kind of stupidity SQL's brainless implementations force one to resort to. for id, count in cursor.fetchall(): print Code=%s, number=%s % (id, count) I'd like to think it makes the Python a bit more readable too ... Agreed. result[0][0] is an abomination. Though one I am sure we have all used at times. The original code wasn't too bad for a beginner. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: IBM integer and double formats
On Nov 11, 11:36 am, John Machin [EMAIL PROTECTED] wrote: wants to write the converted float out to an ASCII file, in hex. Sheesh. It's an *IBM mainframe* file. It would need to be in EBCDIC, not ASCII. But why guess? He said he wanted to write it out in SAS XPORT format. Which is stored in ASCII, no? From the link you gave earlier, 3rd line of the introduction: All character data are stored in ASCII, regardless of the operating system. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug in PIL 1.1.6
Markus Mayer schrieb: Okay, for the* tip, here we go: *2nd tip that is. I need some sleep. -- PGP/GPG key 0x2EB39BF9 -- http://mail.python.org/mailman/listinfo/python-list
Re: Project layout / Import files from different subdirectories
On Tue, Nov 11, 2008 at 8:46 AM, Markus Mayer [EMAIL PROTECTED] wrote: Hi folks. I'm new to python and have a slight problem importing - or maybe understanding - modules. I'm writing a GUI application using Qt4 and wanted to separate the business from the view logic. So I have my folder structure as following: project/ main.py important.py project/ gui/ __init__.py mainwindow.py anotherwindow.py Now I can import mainwindow etc. from main and important, but how do I do it the other way round? Also, is there maybe a better project layout? I couldn't find anything useful on it asking Dr. Google. Since a couple of days, I use this construct and it seems to work quite well, http://mientki.ruhosting.nl/data_www/pylab_works/pw_importing.html cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: sorting list of complex numbers
Steve Holden [EMAIL PROTECTED] wrote: Only half the number, of course. The advantage of the key function is that each element requires only one call out to a Python function, and the comparisons then take place using a C-coded comparison function. You don't need any Python-coded function at all. The operator module is your friend: key=operator.attrgetter('real', 'imag') will create the required tuples for sorting. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden God is real, but Jesus is an integer. ! bellman @ lysator.liu.se ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list
Re: IBM integer and double formats
On Nov 11, 8:15 pm, Mark Dickinson [EMAIL PROTECTED] wrote: On Nov 10, 11:49 pm, John Machin [EMAIL PROTECTED] wrote: Call me crazy if you like, but I'd name that function IEEEtoIBM. But it's topsy-turvy day! Didn't you get the memo? Oh, all right. IEEEtoIBM it is. That's a hexadecimal representation in lowercase with no leading zeroes ... variable length and lowercase doesn't seem very IBM to me. True. Replace %x with %016X for fixed-length uppercase. Or as you say, bytes output is probably more natural. I was guessing that the OP wants to write the converted float out to an ASCII file, in hex. Sheesh. It's an *IBM mainframe* file. It would need to be in EBCDIC, not ASCII. But why guess? He said he wanted to write it out in SAS XPORT format. -- http://mail.python.org/mailman/listinfo/python-list
Re: Where to locate existing standard encodings in python
Hi Philip, Your answer touches exaclty one point, which I was slightly afraid of: - The list is not exhaustive - python versions might have implemented different codecs. This is why I wondered whether there's any way of querying python for a list of codecs it supports. thanks again for your and the other answers bye N Philip Semanchuk wrote: On Nov 9, 2008, at 7:00 PM, News123 wrote: Hi, I was googling quite some time before finding the answer to my question: 'what are the names for the encodings supported by python?' I found the answer at http://python.active-venture.com/lib/node127.html Now my question: Can I find the same info in the standard python doc or query python with a certain command to print out all existing codings? Look under the heading Standard Encodings: http://docs.python.org/library/codecs.html Note that both the page you found (which appears to be a copy of the Python documentation) and the reference I provide say, Neither the list of aliases nor the list of languages is meant to be exhaustive. I guess one reason for this is that different Python implementations could choose to offer codecs for additional encodings. -- http://mail.python.org/mailman/listinfo/python-list
Re: concurrency program design stackless python tasklet or python thread?
Hi there, On Tue, Nov 11, 2008 at 5:57 AM, davy zhang [EMAIL PROTECTED] wrote: first here is my basic idea is every actor holds their own msg queue, the process function will handle the message as soon as the dispatcher object put the message in. Using stackless, every tasklet can have a channel which it uses to communicate with other tasklets. The tasklet is blocked until there's something on the channel to receive. This idea naturally leads me to place every actor in a separate thread waiting for msg You can have actors with many separate tasklets waiting for messages, still being relatively lightweight, meaning you can run thousands of tasklets without serious lack of performance. but I found the tasklet is really a lined-up sequence , that means if a tasklet blocked or do some time consuming calculation, the other tasklets can not get the cpu slice This is cooperative scheduling, which you can choose not to use with Stackless (instead, use preemptive scheduling). If you determine that one particular task is taking too much cpu, you can declaratively call stackless.schedule() and put that task back to the scheduler queue and allow other tasks to have a go. so we must design very carefully to avoid the big job for single task That's right - with cooperative scheduling careful design is the key. I am just confused why the stackless python is said to be good at concurrency program model or just I get a wrong idea to practice? Stackless is an extremely lightweight way into concurrent programming. I have personally used it in few projects and i quite like how lightweight it is and how easy it is to write concurrent programs. On the plus side, Stackless developers have plenty of examples and common idioms of how Stackless should be used, which I highly recommend you to check out. You might find a solution to your problem right there amongst the examples. Check it all out on http://www.stackless.com -- a lex 13 x http://www.a13x.info -- http://mail.python.org/mailman/listinfo/python-list
Re: Final Python Class of 2009
[EMAIL PROTECTED] wrote: Steve, have you been in Guido's time machine again? Steve No, honest (hides hands behind back). Well then what's that red stuff on your face that looks like strawberry jam? Could it be the special grease we store next to the keys to the time machine? [no answer] -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list