[pygtk] ANNOUNCE: PyGObject 2.15.3
I am pleased to announce version 2.15.3 of the Python bindings for GObject. The new release is available from ftp.gnome.org as and its mirrors as soon as its synced correctly: http://download.gnome.org/sources/pygobject/2.15/ What's new since PyGObject 2.15.2? - Beginning of porting to Python 3.0. glib gobject modules ported. (Johan) - Wrap g_app_info_* functions (Gian) - Wrap gio.FileAttributeInfo (Gian) - Wrap g_vfs_get_supported_uri_schemes (Johan, #545846) - Wrap g_file_info_get_modification_time (Johan, #545861) - Wrap gio.Volume.mount/eject (Johan) - Wrap gio.File.move (Johan) - Wrap gio.query_writable_namespaces (Gian, #545920) - Separate glib gobject documentation - Wrap GFile.append_to_async (Gian, #545959) - Wrap GFile.create_async (Gian, #546020) - Change return value from 'gboolean' to 'int' and changed semantics to Pythonic (Paul, #544946) - Wrap GFile.replace_async and query_info_async (Gian, #546046) - GIcon and implementations improvements (Paul, #546135) - Improve __repr__ and richcompare for gio classes (Paul) - Missing Py_INCREFs for some file async methods (Jonathan Matthew, #546734) - File.copy progress_callback does not work (Paul, #546591) - add File.replace_contents, replace_contents_async, replace_contents_finish. (Jonathan Matthew, #547067) - Add GFile.query_default_handler (Gian) - fix docstring line length (Jonathan Matthew, #547134) - improve runtime type wrapper creation (Paul, #547104) - make gio.File more Pythonic (Paul, #546120) - No TypeError raised when type is None (Paul, #540376) - wrap a few memory stream methods (Paul, #547354) - wrap gio.DataInputStream.read_line and ...read_until (Paul, #547484) - wrap four important asynchronous methods in gio.Drive and gio.Mount (Paul, #547495) - gio.InputStream.read() looks broken (Paul, #547494) - wrap g_content_types_get_registered() (Paul, #547088) - cannot create new threads when pygtk is used (Paul, #547633) - an unitialized variable in PyGLib (Paul, #549351) - Constructor of gtk.TreeView raises TypeError when model is None (Paul, #549191) - Fix memory problems reported by valgrind due to invalid tp_basicsize in PyGPropsDescr_Type. (Gustavo, #549945) Blurb: GObject is a object system library used by GTK+ and GStreamer. PyGObject provides a convenient wrapper for the GObject library for use in Python programs, and takes care of many of the boring details such as managing memory and type casting. When combined with PyGTK, PyORBit and gnome-python, it can be used to write full featured Gnome applications. Like the GObject library itself PyGObject is licensed under the GNU LGPL, so is suitable for use in both free software and proprietary applications. It is already in use in many applications ranging from small single purpose scripts up to large full featured applications. PyGObject requires glib = 2.14.0 and Python = 2.3.5 to build. GIO bindings require glib = 2.16.0. Johan -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Roundup Issue Tracker version 1.4.6 released
I'm proud to release version 1.4.6 of Roundup. 1.4.6 is a bugfix release: - Fix bug introduced in 1.4.5 in RDBMS full-text indexing - Make URL matching code less matchy If you're upgrading from an older version of Roundup you *must* follow the Software Upgrade guidelines given in the maintenance documentation. Roundup requires python 2.3 or later for correct operation. To give Roundup a try, just download (see below), unpack and run:: roundup-demo Release info and download page: http://cheeseshop.python.org/pypi/roundup Source and documentation is available at the website: http://roundup.sourceforge.net/ Mailing lists - the place to ask questions: http://sourceforge.net/mail/?group_id=31577 About Roundup = Roundup is a simple-to-use and -install issue-tracking system with command-line, web and e-mail interfaces. It is based on the winning design from Ka-Ping Yee in the Software Carpentry Track design competition. Note: Ping is not responsible for this project. The contact for this project is [EMAIL PROTECTED] Roundup manages a number of issues (with flexible properties such as description, priority, and so on) and provides the ability to: (a) submit new issues, (b) find and edit existing issues, and (c) discuss issues with other participants. The system will facilitate communication among the participants by managing discussions and notifying interested parties when issues are edited. One of the major design goals for Roundup that it be simple to get going. Roundup is therefore usable out of the box with any python 2.3+ installation. It doesn't even need to be installed to be operational, though a disutils-based install script is provided. It comes with two issue tracker templates (a classic bug/feature tracker and a minimal skeleton) and four database back-ends (anydbm, sqlite, mysql and postgresql). -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Python 3.0b2 cannot map '\u12b'
Tim Roberts wrote: josh logan [EMAIL PROTECTED] wrote: I am using Python 3.0b2. I have an XML file that has the unicode character '\u012b' in it, which, when parsed, causes a UnicodeEncodeError: 'charmap' codec can't encode character '\u012b' in position 26: character maps to undefined This happens even when I assign this character to a reference in the interpreter: Python 3.0b2 (r30b2:65106, Jul 18 2008, 18:44:17) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. s = '\u012b' s Traceback (most recent call last): File stdin, line 1, in module File C:\Python30\lib\io.py, line 1428, in write b = encoder.encode(s) File C:\Python30\lib\encodings\cp437.py, line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u012b' in position 1: character maps to undefined Is this a known issue, or am I doing something wrong? Both. U+012B is the Latin lower-case i with macron (i with a bar instead of a dot). That character does not exist in the 8-bit character set CP437, which you are trying to use. If you choose an 8-bit character set that includes i-with-macron, then it will work. UTF-8 would be a good choice. It's in ISO-8859-10. I doubt the OP 'chose' cp437. Why does Python using cp437 even when the default encoding is utf-8? On WinXP sys.getdefaultencoding() 'utf-8' s='\u012b' s Traceback (most recent call last): File stdin, line 1, in module File C:\Program Files\Python30\lib\io.py, line 1428, in write b = encoder.encode(s) File C:\Program Files\Python30\lib\encodings\cp437.py, line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u012b' in position 1: character maps to undefined To put it another way, how can one 'choose' utf-8 for display to screen? Using IDLE, display works fine. IDLE 3.0b2 s='\u012b' s 'ī' # i macron import sys sys.getdefaultencoding() 'utf-8' I ran across this is a different context and mentioned it on the bug tracker, but the Windows interpreter seems broken here. I will send this in UTF-8 so the i-macron will hopefully show up. tjr -- http://mail.python.org/mailman/listinfo/python-list
Processes in Linux from Python
To get a number of the http processes running on my Linux( Debia box) I use ps -ef | grep [h]ttpd | wc -l But If I want to use to get a number of the http processes from my Python program I must use a popen command e.g. popen2.popen3('ps -ef | grep [h]ttpd | wc -l') that is I must call an external command from Python. But it creates a zombie. So my question is: Is it possible to get a number of the http processes running on Linux directly from Python ? Thanks for help. L. -- http://mail.python.org/mailman/listinfo/python-list
Re: Processes in Linux from Python
Johny schrieb: To get a number of the http processes running on my Linux( Debia box) I use ps -ef | grep [h]ttpd | wc -l But If I want to use to get a number of the http processes from my Python program I must use a popen command e.g. popen2.popen3('ps -ef | grep [h]ttpd | wc -l') that is I must call an external command from Python. The shell does the exact same thing. And by the way: i think you miss a grep -v grep after the first grep - otherwise you count the grep itself. But it creates a zombie. Try using the subprocess module. It should not require you to call wait yourself. So my question is: Is it possible to get a number of the http processes running on Linux directly from Python ? Not really, or at least not with less effort without duplicating system tools functionality. Diez -- http://mail.python.org/mailman/listinfo/python-list
Using NLTK in Java
I am trying to convert a python module (that contains the use of NLTK.Corpus) by jythonc. It is not able to include nltk dependencies within the java class it creates. So when i use this class in java, it fails to recognize nltk. Can anyone please let me know how should i use nltk in python/jython modules so i can use in Java. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using NLTK in Java
[EMAIL PROTECTED] schrieb: I am trying to convert a python module (that contains the use of NLTK.Corpus) by jythonc. It is not able to include nltk dependencies within the java class it creates. So when i use this class in java, it fails to recognize nltk. Can anyone please let me know how should i use nltk in python/jython modules so i can use in Java. If there are any binary dependencies, you are out of luck. It won't work. You would need to write a RPC-Server then, with technologies such as XMLRPC or CORBA. Diez -- http://mail.python.org/mailman/listinfo/python-list
Inquiry regarding the name of subprocess.Popen class
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the object itself is a subprocess, not a popen. It seems that it would be more accurate to just name the class Subprocess, can anyone explain why this is not the case? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
file-Grid-file
Hi all, I imported a comma seperated data to PyGridTableBase which is a abstract Grid, I parse and display the information. After update i want to save it back to the comma seperated file, eith the same filename. any suggestions how to do that ? do you know any reference to this subject ? YM -- http://mail.python.org/mailman/listinfo/python-list
Re: Command lime code
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Okay, I'll take I wild guess: By command lime code you did not refer to the algorithmic domination of citrus fruit, but rather to that window with the tiny blinking cursor and loads of text in white on black. Also by 'chdir' you probably mean the MS DOS equivalent to UNIX 'cd' (which AFAIK also works on MS DOS). So Googling for MS DOS Commands might be a good idea and yield, amongst others, this result: http://en.wikipedia.org/wiki/List_of_DOS_commands On Aug 29, 2008, at 6:20 PM, [EMAIL PROTECTED] wrote: I am new to python. I did find a page which listed some code - IE chdir type code but can not find it again. Can you supply an address? -- http://mail.python.org/mailman/listinfo/python-list -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) iD8DBQFIu5wCcZ70OCIgLecRArTEAJ42+XoaVOgOnk+o/f3shWSp0Cq3CQCfRstB 8bKzY9FBeZmGzKyzAg7xEwk= =3xLN -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: (in memory) database
Roel Schroeven schreef: Cameron Laird schreef: I now suspect that my 2.5 packaging has something to do with 64-bit builds; all my 32-bit Ubuntu servers have Python 2.5.2, while the 64-bit ones are at Python 2.5. Strange: my 64-bit Ubuntu 8.04 has Python 2.5.2, with working sqlite: (mine is a desktop, not a server; I don't know if that should make any difference). -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
how to find position of dictionary values
hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? thanks you. -- http://mail.python.org/mailman/listinfo/python-list
Unable to clear Entry subwidget of Tix Combo Box
Hi, In my combo box taken from Tix, how can I clear the entry subwidget? My case is like this: I have a check button which when made un-ticked should clear the entry from combo box (i. anything selected in combo box previously) I used the following commands: subEntry = self.cbAnalysisLibVersion.subwidget(entry) subEntry.delete(0,END) But this is not working. Please help. Thanks and regards, Rajat -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
lookfor = 'dfsdf' for item, value in kev.items(): if lookfor in value: print item print value.index(lookfor) break # assuming you only want one result You can also skip the 'if' verification in which case you need to catch ValueError exception in case there is no such entry in the current list. Hope it helps. lee wrote: hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? thanks you. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Know if a object member is a method
Hi all. I think this is a newbie question... what is the best method to know if a property of an object is a function? I'm thinking something as if type(obj.methodName)==??? Can someone help me? -- -- luca -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
On Sep 1, 1:21 pm, Alexandru Palade [EMAIL PROTECTED] wrote: lookfor = 'dfsdf' for item, value in kev.items(): if lookfor in value: print item print value.index(lookfor) break # assuming you only want one result You can also skip the 'if' verification in which case you need to catch ValueError exception in case there is no such entry in the current list. Hope it helps. lee wrote: hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? thanks you. -- http://mail.python.org/mailman/listinfo/python-list hi, thank u your solution is exactly wat i wanted :) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
lee a écrit : hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? It's quite simple (hint : read the FineManual(tm) for dict.items() and list.index()), but 1/totally inefficient and 2/not garanteed to yield a single value (what if 'dfsdf' happens to be also the 4th item of the list bound to key 'address' ?). May I suggest you rethink your data structure instead ? What you have here is obviously a collection of 'phno/email/name/address'records. These records shouldn't be split across different objects. Assuming 'phno' is a unique identifier for each record, a better data structure would be: records = { 'dgsd' : {'email': 'dg', 'name' : 'ds', 'address' : 'sdg'}, 'gsdg' : {'email': 'sgsd', 'name':'ds', 'address' : 'dsgsdg'}, # etc } This way, the lookup is as simple and efficient as possible. My 2 cents -- http://mail.python.org/mailman/listinfo/python-list
Re: The Importance of Terminology's Quality
From: [EMAIL PROTECTED] (Rob Warnock) In the LGP-30, they used hex addresses, sort of[1], but the opcodes (all 16 of them) had single-letter mnemonics chosen so that the low 4 bits of the character codes *were* the correct nibble for the opcode! ;-} That's a fascinating design constraint! It would be an interesting puzzle to find the most efficient design whereby: - The single-character mnemonics are as easy to memorize as possible; - The instructions produce as efficient code as possible; - The mnemonics really do accurately express what the instruction does; - Minimize total number of instructions needed, maybe fewer than 16; - With the low-order-four-bits rule of course. - See also the avoid-ambiguous-sound criterion later below. By the way, do you remember exactly all the 16 opcodes, or have a Web reference available? [Or you could type in the actual hex digits, since the low 4 bits of *their* character codes were also their corresponding binary nibble values... but that would have been wrong.] Moreso because some of the sounds would be ambiguous, which I recognized when I first started to use the IBM hexadecimal standard. See below. The LGP-30 character code was defined before the industry had yet standardized on a common hex [sic, hexadecimal, base 16 not base 6!!!] character set, Before IBM had decided to use hexadecimal in their abend coredumps from their System/360 and by their 800-pound-gorilla status they got everyone else to use that ABCDEF system. they used 0123456789fgjkqw. That doesn't make sense. The low-order four bits of those letters aren't consecutive ascending values from 9+1 to 9+6. Did you make a typo, or did you explain something wrong? (map 'list #'char-code 0123456789fgjkqw) = (48 49 50 51 52 53 54 55 56 57 102 103 106 107 113 119) (loop for n in * collect (rem n 16)) = (0 1 2 3 4 5 6 7 8 9 6 7 10 11 1 7) Now if you used this sequence of letters instead: (map 'list #'char-code 0123456789jklmno) = (48 49 50 51 52 53 54 55 56 57 106 107 108 109 110 111) (loop for n in * collect (rem n 16)) = (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) Unfortunately o looks like 0, and l looks like 1. Anyway, what I hated about IBM's hexadecimal notation was: - A0 would be pronounced Ay-tee, which sounds too much like Eighty. - 1A would be pronounced Ay-teen, which sounds too much like Eighteen. - On the lineprinters where we get our abend listings, the capital D and digit 0 (which didn't have any diagonal slash) looked almost identical when the ribbon was going bad, as it always was. - Likewise B and 8 looked nearly identical. - Likewise E and F often looked nearly identical of lower part of E was hitting bad part of ribbon. Now for single-character mnemonics for four bits of instruction opcode, to avoid any two characters that look too similar: 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z We obviously have no choice for KLMNO, so because of look-alike we can't use 0 or D or Q, so we have to use P instead of 0, so our choices look like: 1 2 3 4 5 6 7 8 9 A B C E F G H I J K L M N O P R S T U V W X Y Z If we have an opcode that sets a register to 1, or clears register#1, we might use mnemonic 1 for that instruction, but otherwise we must avoid using digits, use letters only. 1 A B C E F G H I J K L M N O P R S T U V W X Y Z We can't use both U and V, and we can't use both E and F, and we can't use both 1 and I, but we're stuck using both M and N, sigh. At this point I can't decide which branches of the search to discard and which to fix, so I'll stop analysing this puzzle. (With lower-case characters different combinations were mutually exclusive, such as l and 1, but I was doing upper case here.) If punctuation is allowed, then + - * / = would make dandy mnemonic opcodes for the obvious instructions. If characters that look like arrows can be used for push and pop, then we have V for push and ^ for pop. If characters that look like arrows can be used for moving left/right in RAM, or shifting bits in a register, then we have for left and for right. I wonder if solving this puzzle will yield yet another esoteric programming language? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
On Sep 1, 1:45 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: lee a écrit : hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? It's quite simple (hint : read the FineManual(tm) for dict.items() and list.index()), but 1/totally inefficient and 2/not garanteed to yield a single value (what if 'dfsdf' happens to be also the 4th item of the list bound to key 'address' ?). May I suggest you rethink your data structure instead ? What you have here is obviously a collection of 'phno/email/name/address'records. These records shouldn't be split across different objects. Assuming 'phno' is a unique identifier for each record, a better data structure would be: records = { 'dgsd' : {'email': 'dg', 'name' : 'ds', 'address' : 'sdg'}, 'gsdg' : {'email': 'sgsd', 'name':'ds', 'address' : 'dsgsdg'}, # etc } This way, the lookup is as simple and efficient as possible. My 2 cents hi, i agree with u, my data strusture is not efficient. but all the records,viz...name,phno, email,address are all generated at runtime , when the user enters them. so how can i design my datastructure in that case? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
On Sep 1, 1:45 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: lee a écrit : hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? It's quite simple (hint : read the FineManual(tm) for dict.items() and list.index()), but 1/totally inefficient and 2/not garanteed to yield a single value (what if 'dfsdf' happens to be also the 4th item of the list bound to key 'address' ?). May I suggest you rethink your data structure instead ? What you have here is obviously a collection of 'phno/email/name/address'records. These records shouldn't be split across different objects. Assuming 'phno' is a unique identifier for each record, a better data structure would be: records = { 'dgsd' : {'email': 'dg', 'name' : 'ds', 'address' : 'sdg'}, 'gsdg' : {'email': 'sgsd', 'name':'ds', 'address' : 'dsgsdg'}, # etc } This way, the lookup is as simple and efficient as possible. My 2 cents hi, i agree with u, my data strusture is not efficient. but all the records,viz...name,phno, email,address are all generated at runtime , when the user enters them. so how can i design my datastructure in that case? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
On Sep 1, 1:45 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: lee a écrit : hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? It's quite simple (hint : read the FineManual(tm) for dict.items() and list.index()), but 1/totally inefficient and 2/not garanteed to yield a single value (what if 'dfsdf' happens to be also the 4th item of the list bound to key 'address' ?). May I suggest you rethink your data structure instead ? What you have here is obviously a collection of 'phno/email/name/address'records. These records shouldn't be split across different objects. Assuming 'phno' is a unique identifier for each record, a better data structure would be: records = { 'dgsd' : {'email': 'dg', 'name' : 'ds', 'address' : 'sdg'}, 'gsdg' : {'email': 'sgsd', 'name':'ds', 'address' : 'dsgsdg'}, # etc } This way, the lookup is as simple and efficient as possible. My 2 cents hi, i agree with u, my data strusture is not efficient. but all the records,viz...name,phno, email,address are all generated at runtime , when the user enters them. so how can i design my datastructure in that case? -- http://mail.python.org/mailman/listinfo/python-list
Re: Know if a object member is a method
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Luca, use type(something).__name__ , e.g. def x(): pass class C: pass c = C() type(x).__name__ == 'function' True type(C).__name__ == 'classobj' True type(c).__name__ == 'instance' True On Sep 1, 2008, at 10:43 AM, Luca wrote: Hi all. I think this is a newbie question... what is the best method to know if a property of an object is a function? I'm thinking something as if type(obj.methodName)==??? Can someone help me? -- -- luca -- http://mail.python.org/mailman/listinfo/python-list -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) iD8DBQFIu606cZ70OCIgLecRAhE6AJ4r0GuHlWxXbLaYuolqpJStYPD+ggCgidKg qtgl+nbaKgH5AoelTu5WeJU= =W4eG -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
On Sep 1, 1:45 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: lee a écrit : hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? It's quite simple (hint : read the FineManual(tm) for dict.items() and list.index()), but 1/totally inefficient and 2/not garanteed to yield a single value (what if 'dfsdf' happens to be also the 4th item of the list bound to key 'address' ?). May I suggest you rethink your data structure instead ? What you have here is obviously a collection of 'phno/email/name/address'records. These records shouldn't be split across different objects. Assuming 'phno' is a unique identifier for each record, a better data structure would be: records = { 'dgsd' : {'email': 'dg', 'name' : 'ds', 'address' : 'sdg'}, 'gsdg' : {'email': 'sgsd', 'name':'ds', 'address' : 'dsgsdg'}, # etc } This way, the lookup is as simple and efficient as possible. My 2 cents hi, i agree with u, my data strusture is not efficient. but all the records,viz...name,phno, email,address are all generated at runtime , when the user enters them. so how can i design my datastructure in that case? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
lee a écrit : hi, thank u your solution is exactly wat i wanted :) I'm afraid it's not what you actually *need*, cf my other post. -- http://mail.python.org/mailman/listinfo/python-list
Re: Know if a object member is a method
On Mon, 01 Sep 2008 10:43:25 +0200, Luca wrote: Hi all. I think this is a newbie question... what is the best method to know if a property of an object is a function? I'm thinking something as if type(obj.methodName)==??? Can someone help me? That's not quite as easy as you might think. In my testing, calling type(obj.methodName) can give any of the following: type 'instancemethod' type 'function' type 'builtin_function_or_method' There may be others as well. Possibly all you really need is to check if the attribute is callable without caring what type of method or function it is: callable(obj.methodName) True In my opinion, that's the best way. If you are sure that the method won't have side-effects or bugs: try: ... obj.method() ... except: ... print Not a method ... (But how can you be sure?) If you insist on an explicit test, try this: import new type(obj.methodName) == new.instancemethod or alternatively: isinstance(obj.methodName, new.instancemethod) True -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Know if a object member is a method
On Mon, 01 Sep 2008 10:52:10 +0200, Manuel Ebert wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Luca, use type(something).__name__ , e.g. def x(): pass class C: pass c = C() type(x).__name__ == 'function' True type(C).__name__ == 'classobj' True type(c).__name__ == 'instance' True That's relatively fragile, since such names aren't reserved in any way. It's easy to fool a name comparison check with an accidental name collision: class function(object): # not a reserved name ... pass ... x = function() type(x).__name__ 'function' x() # must be a function then... Traceback (most recent call last): File stdin, line 1, in module TypeError: 'function' object is not callable But not so easy to fool a type check: type(x) == new.function False Of course that's not bullet-proof either. I leave it as an exercise to discover how you might break that piece of code. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
lee wrote: On Sep 1, 1:45 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: lee a écrit : hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? It's quite simple (hint : read the FineManual(tm) for dict.items() and list.index()), but 1/totally inefficient and 2/not garanteed to yield a single value (what if 'dfsdf' happens to be also the 4th item of the list bound to key 'address' ?). May I suggest you rethink your data structure instead ? What you have here is obviously a collection of 'phno/email/name/address'records. These records shouldn't be split across different objects. Assuming 'phno' is a unique identifier for each record, a better data structure would be: records = { 'dgsd' : {'email': 'dg', 'name' : 'ds', 'address' : 'sdg'}, 'gsdg' : {'email': 'sgsd', 'name':'ds', 'address' : 'dsgsdg'}, # etc } This way, the lookup is as simple and efficient as possible. My 2 cents hi, i agree with u, my data strusture is not efficient. but all the records,viz...name,phno, email,address are all generated at runtime , when the user enters them. so how can i design my datastructure in that case? Are u short on keystrokes? You are not textmessaging here... Regarding the actual question: there is no difference in building your or the other structure. It's only a question of which key you use first. Instead of first looking up the type of the record (phno or some such), do that with the name of the user. If no record exists, create one. Then populate the record with the user's values. Like this: user = dsdf phonenumber = 123 record = records.setdefault(user, {}) record[phno] = phonenumber Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Know if a object member is a method
On Mon, Sep 1, 2008 at 11:35 AM, Steven D'Aprano [EMAIL PROTECTED] wrote: That's relatively fragile, since such names aren't reserved in any way. It's easy to fool a name comparison check with an accidental name collision: class function(object): # not a reserved name ... pass ... x = function() type(x).__name__ 'function' x() # must be a function then... Traceback (most recent call last): File stdin, line 1, in module TypeError: 'function' object is not callable But not so easy to fool a type check: type(x) == new.function False Of course that's not bullet-proof either. I leave it as an exercise to discover how you might break that piece of code. Ok, so... What is the best way to do this? The most pythonic? -- -- luca -- http://mail.python.org/mailman/listinfo/python-list
list + dictionary searching
Hello All, I am very new to python. Any help will be highly appreciated. Thanks I have a list of dictionaries: a = [{'username': u'John Wang', 'user_utilization': 1.0, 'month': 9, 'user_id': 4, 'year': 2008}, {'username': u'John Wang', 'user_utilization': 1.0, 'month': 10, 'user_id': 4, 'year': 2008}, {'username': u' ', 'user_utilization': 1.0, 'month': 9, 'user_id': 1, 'year': 2008}] I would like to : search dictionaries within this list create a new list with dictionaries which gives 1 dictionary for every user with month_year as a key and utilization for that month as a value Please give your thoughts Thanks, Manoj -- http://mail.python.org/mailman/listinfo/python-list
Re: Processes in Linux from Python
Johny wrote: Is it possible to get a number of the http processes running on Linux directly from Python ? The Python core has no direct API for the job. However you can use the virtual /proc/ file system for the job. Or check out my enumprocess package. http://pypi.python.org/pypi?:action=displayname=enumprocessversion=0.1 It's far from perfect but it should do the job on Linux. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Using NLTK in Java
On 1 Sep, 11:55, Diez B. Roggisch [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] schrieb: I am trying to convert a python module (that contains the use of NLTK.Corpus) by jythonc. It is not able to include nltk dependencies within the java class it creates. So when i use this class in java, it fails to recognize nltk. Can anyone please let me know how should i use nltk in python/jython modules so i can use in Java. If there are any binary dependencies, you are out of luck. It won't work. You would need to write a RPC-Server then, with technologies such as XMLRPC or CORBA. Diez So does that mean that Jython does not support nltk uptil now. I ask this because when I try to import nltk in Jython (which is assumed to replace Python), i get the same error. Its just nltk that I am not able to use. The rest of the jython functions and libraries work fine within Java. -- http://mail.python.org/mailman/listinfo/python-list
Re: Processes in Linux from Python
On Sun, 31 Aug 2008 23:25:56 -0700 (PDT), Johny wrote: To get a number of the http processes running on my Linux( Debia box) I use ps -ef | grep [h]ttpd | wc -l ... So my question is: Is it possible to get a number of the http processes running on Linux directly from Python ? Yes, it is. There is a number of third party packages that provide such functionality, including PSI: http://www.psychofx.com/psi/ I never actually liked them, because they are parsing /proc directory by themselves. Thus I wrote my own tool that is a wrapper around procps library (libproc* in your /lib, probably). Your system tools like ps, w or top are using this library. My wrapping library is available at: http://code.google.com/p/procpy/ In your case you could use it like this: import procpy pp = procpy.Proc() for pid in pp.pids: ...if pp.procs[pid]['cmd'] == 'apache2': ... print pp.procs[pid]['tid'] ... 5204 5205 5206 5208 it prints the PIDs of all the apache2 processes on my system. Procpy is fine for my own needs, but if I were about to write a code that is intended to be portable, I'd use PSI. It also is more mature. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list
Re: list + dictionary searching
Manoj a écrit : Hello All, I am very new to python. Any help will be highly appreciated. Thanks I have a list of dictionaries: a = [{'username': u'John Wang', 'user_utilization': 1.0, 'month': 9, 'user_id': 4, 'year': 2008}, {'username': u'John Wang', 'user_utilization': 1.0, 'month': 10, 'user_id': 4, 'year': 2008}, {'username': u' ', 'user_utilization': 1.0, 'month': 9, 'user_id': 1, 'year': 2008}] I would like to : search dictionaries within this list Care to elaborate ??? create a new list with dictionaries which gives 1 dictionary for every user with month_year as a key and utilization for that month as a value assuming the user_id/month/year combination is unique: from collections import defaultdict users = defaultdict(dict) for record in a: month_year = %(month)s_%(year)s % record users[record['user_id']][month_year] = record['user_utilization'] print users.values() HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: (in memory) database
mark a écrit : Hi there, I need to extract data from text files (~4 GB) on this data some operations are performed like avg, max, min, group etc. The result is formated and written in some other text files (some KB). I currently think about database tools might be suitable for this. I would just write the import from the text files and ... the tool does the rest. The only problem I can imagine is that this would not be fast enough. Is this an a priori, or did you actually benchmark and found out it would not fit your requirements ? But I would give it a shoot. Unfortunately I have only some knowledge of SQLite which is not an option here. Some additional requirements I can think of are: - Python (I want to hone my programming skills too) - Python-only (no C-lib) for simplicity (installation, portability). Therefore SQLite is not an option - must be fast These two requirements can conflict for some values of fast. - I like SQL (select a, b from ...) this would be nice (row[..] + ... is a little hard getting used to) So far I found PyDBLite, PyTables, Buzhug but they are difficult to compare for a beginner. Never used any of them - I have sqlite, mysql and pgsql installed on all my machines -, so I can't help here. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
On Sep 1, 2:37 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: lee wrote: On Sep 1, 1:45 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: lee a écrit : hi, i have a dictionary as follows : kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg', 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'], 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']} if user is enters the 3rd item of key phno, ie dfsdf in my dict, how can i find it is the third item in the internal list of phno of that dictionary? It's quite simple (hint : read the FineManual(tm) for dict.items() and list.index()), but 1/totally inefficient and 2/not garanteed to yield a single value (what if 'dfsdf' happens to be also the 4th item of the list bound to key 'address' ?). May I suggest you rethink your data structure instead ? What you have here is obviously a collection of 'phno/email/name/address'records. These records shouldn't be split across different objects. Assuming 'phno' is a unique identifier for each record, a better data structure would be: records = { 'dgsd' : {'email': 'dg', 'name' : 'ds', 'address' : 'sdg'}, 'gsdg' : {'email': 'sgsd', 'name':'ds', 'address' : 'dsgsdg'}, # etc } This way, the lookup is as simple and efficient as possible. My 2 cents hi, i agree with u, my data strusture is not efficient. but all the records,viz...name,phno, email,address are all generated at runtime , when the user enters them. so how can i design my datastructure in that case? Are u short on keystrokes? You are not textmessaging here... Regarding the actual question: there is no difference in building your or the other structure. It's only a question of which key you use first. Instead of first looking up the type of the record (phno or some such), do that with the name of the user. If no record exists, create one. Then populate the record with the user's values. Like this: user = dsdf phonenumber = 123 record = records.setdefault(user, {}) record[phno] = phonenumber Diez i am soory for that keystrokes. can anyone tell me how can i change the value of key. suppose i have a dictionary kev = {'kabir': ['[EMAIL PROTECTED]', '1234', 'missuri'], 'shri': ['[EMAIL PROTECTED]', '23423', 'india'], 'marsa': ['[EMAIL PROTECTED]', '2345', 'brazil'], 'sandeep': ['[EMAIL PROTECTED]', '007', 'canada']} how can i change the key to something like 'sabir' and how can i change the values of kabir? -- http://mail.python.org/mailman/listinfo/python-list
Re: list + dictionary searching
On Mon, 1 Sep 2008 03:14:22 -0700 (PDT), Manoj wrote: I would like to : search dictionaries within this list create a new list with dictionaries which gives 1 dictionary for every user with month_year as a key and utilization for that month as a value Please give your thoughts Reading about for loop seems like a good idea. You can easily create a set of functions that gives you direct access to the information you need. http://docs.python.org/tut/node6.html#SECTION00620 http://docs.python.org/tut/node7.html#SECTION00750 Give it a try. Try to design some functions that let you view and add new lists/dictionaries to your variables. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list
Re: The Importance of Terminology's Quality
Robert Maas, [EMAIL PROTECTED] wrote: +--- | From: [EMAIL PROTECTED] (Rob Warnock) | In the LGP-30, they used hex addresses, sort of[1], but the | opcodes (all 16 of them) had single-letter mnemonics chosen so that | the low 4 bits of the character codes *were* the correct nibble for | the opcode! ;-} ... | By the way, do you remember exactly all the 16 opcodes, or have a | Web reference available? +--- There are quite a few out there; here's one: http://www.users.nwark.com/~rcmahq/jclark/lgp30.htm Some notes on the opcodes: - Bring (B) would be called Load in current parlance. - Extract (E) would be called And in current parlance. - Unconditional Transfer (U) would be called Jump or Branch. - Hold (H) would be called Store; Clear (C) would be called Store-and-Clear (the DCA instruction of the DEC PDP-8). - There are two Multiply ops, M N, depending on whether the upper or lower bits (respectively) of the product are returned. - Store Address (Y) stores an address in the AC into the address field of the destination [yes, modifying the code in-place!! -- it was mostly used for indexing through arrays], whereas the Return Address (R) stores the current instruction address + 2 into the address field of the destination. The subroutine calling sequence is thus an R/U pair: R foo_last U foo where the FOO subroutine might be written as: foo: ... ... foo_last: U foo_last ; overwritten +--- | The LGP-30 character code was defined before the industry had | yet standardized on a common hex [sic, hexadecimal, base 16 | not base 6!!!] character set, ... | they used 0123456789fgjkqw. | | That doesn't make sense. The low-order four bits of those letters | aren't consecutive ascending values from 9+1 to 9+6. Did you make a | typo, or did you explain something wrong? +--- No, what I wrote is correct. The low 4 bits of 0123456789fgjkqw *are* 0 through 16 (or 0123456789abcdef in current hex)... IN THE *LGP-30 FLEXOWRITER* CHARACTER CODE, *not* in ASCII or EBCDIC or Baudot or any other standard code. Well, actually, it's a little more complex than that. The LGP-30 used a 6-bit keyboard code on the Flexowriter (and the paper tape reader punch), but the machine could be put into either 6-bit or 4-bit input mode. In the latter, only the first four bits of each code got shifted into the accumulator. So I suppose you could say those were the *upper* 4 bits of each character, though when read into the accumulator in 4-bit input mode they truly *were* the lower 4 bits. (Sorry for the confusion. It was an interesting machine.) +--- | (map 'list #'char-code 0123456789fgjkqw) | = (48 49 50 51 52 53 54 55 56 57 102 103 106 107 113 119) +--- That's ASCII. The LGP-30 did not use ASCII. The LGP-30 used Flexowriter keyboard code, see: http://ed-thelen.org/comp-hist/lgp-30-man-f002.gif -Rob p.s. The full programming manual for the LGP-30 can be found here: http://ed-thelen.org/comp-hist/lgp-30-man.html but good luck reading its archaic style. ;-} - Rob Warnock [EMAIL PROTECTED] 627 26th Avenue URL:http://rpw3.org/ San Mateo, CA 94403 (650)572-2607 -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
On Mon, 1 Sep 2008 03:51:13 -0700 (PDT), lee wrote: i am soory for that keystrokes. can anyone tell me how can i change the value of key. suppose i have a dictionary kev = {'kabir': ['[EMAIL PROTECTED]', '1234', 'missuri'], 'shri': ['[EMAIL PROTECTED]', '23423', 'india'], 'marsa': ['[EMAIL PROTECTED]', '2345', 'brazil'], 'sandeep': ['[EMAIL PROTECTED]', '007', 'canada']} how can i change the key to something like 'sabir' and kev['sabir'] = kev['kabir'] del kev['kabir'] how can i change the values of kabir? kev['sabir'][0] = '[EMAIL PROTECTED]' *untested* -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list
Retrieving http headers from HTTPConnection object
Hi, when using httplib for http requests, like for example: conn = httplib.HTTPConnection(www.python.org) conn.request(GET, /index.html) Is it possible to retrieve the complete http request in string form : GET /index.html HTTP/1.1 Host: www.python.org User-Agent: ... Accept: ... Accept-Language: Accept-Encoding: Accept-Charset: Keep-Alive: Connection: I mean does the HTTPConnection object have a property that stores this ? or is it retrievable by some other form? Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving http headers from HTTPConnection object
On Mon, Sep 1, 2008 at 1:06 PM, jorma kala [EMAIL PROTECTED] wrote: Hi, when using httplib for http requests, like for example: conn = httplib.HTTPConnection(www.python.org) conn.request(GET, /index.html) Is it possible to retrieve the complete http request in string form : GET /index.html HTTP/1.1 Host: www.python.org User-Agent: ... Accept: ... Accept-Language: Accept-Encoding: Accept-Charset: Keep-Alive: Connection: I mean does the HTTPConnection object have a property that stores this ? or is it retrievable by some other form? Thanks a lot. -- Looking at the code of HTTPConnection, all that goes through the _output message (including, therefore, the putheaders) are appended to the self._buffer list. Regards Marco -- Marco Bizzarri http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Best way for add new path when embedding python into C
Hi list, I have a little question about whats' the best way for add - no replace - new path into python c embedding environment for this situation. I'm using PyObject_CallObject(pfunc, pArgs); for call one function of some module loaded with PyImport_Import function. PyImport_Import function search this module into system path list object. I read some examples about Py_GetPath and PySys_SetPath and i think some examples are wrong or can be misinterpreted. Py_GetPath make only a basic path, some sitautions are considred for make this path, for example read environment varialbes. PySys_SetPath overwrite all path list object. When Py_Initialitze it's called sys path object is generated with Py_GetPath content and a other directories added by site.py file pre processor. The best way for add new path before call PyImport_Import is adding new string item into sys path object ? Bye and thks to all -- Pau Freixes Linux GNU/User -- http://mail.python.org/mailman/listinfo/python-list
Re: Using NLTK in Java
[EMAIL PROTECTED] wrote: On 1 Sep, 11:55, Diez B. Roggisch [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] schrieb: I am trying to convert a python module (that contains the use of NLTK.Corpus) by jythonc. It is not able to include nltk dependencies within the java class it creates. So when i use this class in java, it fails to recognize nltk. Can anyone please let me know how should i use nltk in python/jython modules so i can use in Java. If there are any binary dependencies, you are out of luck. It won't work. You would need to write a RPC-Server then, with technologies such as XMLRPC or CORBA. Diez So does that mean that Jython does not support nltk uptil now. I ask this because when I try to import nltk in Jython (which is assumed to replace Python), i get the same error. Its just nltk that I am not able to use. The rest of the jython functions and libraries work fine within Java. I don't know for sure - how about you post the error-message? Otherwise we can't assess the problem. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
On Sep 1, 3:59 pm, Wojtek Walczak [EMAIL PROTECTED] wrote: On Mon, 1 Sep 2008 03:51:13 -0700 (PDT), lee wrote: i am soory for that keystrokes. can anyone tell me how can i change the value of key. suppose i have a dictionary kev = {'kabir': ['[EMAIL PROTECTED]', '1234', 'missuri'], 'shri': ['[EMAIL PROTECTED]', '23423', 'india'], 'marsa': ['[EMAIL PROTECTED]', '2345', 'brazil'], 'sandeep': ['[EMAIL PROTECTED]', '007', 'canada']} how can i change the key to something like 'sabir' and kev['sabir'] = kev['kabir'] del kev['kabir'] how can i change the values of kabir? kev['sabir'][0] = '[EMAIL PROTECTED]' *untested* -- Regards, Wojtek Walczak,http://tosh.pl/gminick/ thanks wojtek, it worked :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way for add new path when embedding python into C
Pau Freixes wrote: The best way for add new path before call PyImport_Import is adding new string item into sys path object ? The same way you'd add a path in Python: PyObject *sys_path; PyObject *path; sys_path = PySys_GetObject(path); if (sys_path == NULL) return NULL; path = PyString_FromString(/your/path) if (path == NULL) return NULL; if (PyList_Append(sys_path, path) 0) return NULL Py_RETURN_NONE; Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
lee a écrit : On Sep 1, 2:37 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: lee wrote: (snip) i agree with u, my data strusture is not efficient. but all the records,viz...name,phno, email,address are all generated at runtime , when the user enters them. so how can i design my datastructure in that case? ot Are u short on keystrokes? You are not textmessaging here... i am soory for that keystrokes Is your cap key broken ?-) /ot (snip) . can anyone tell me how can i change the value of key. suppose i have a dictionary kev = {'kabir': ['[EMAIL PROTECTED]', '1234', 'missuri'], 'shri': ['[EMAIL PROTECTED]', '23423', 'india'], 'marsa': ['[EMAIL PROTECTED]', '2345', 'brazil'], 'sandeep': ['[EMAIL PROTECTED]', '007', 'canada']} how can i change the key to something like 'sabir' and how can i change the values of kabir? I don't mean to be harsh, but did you read the FineManual(tm) ? All this is very basic (no pun) stuff, mostly documented, and easy to try out using the interactive interpreter. This ng is very newbie-friendly, but this doesn't mean you can hope to get by without doing the minimal effort of going thru the tutorial and trying a couple things by yourself before asking. Hope you'll understand the above remark intends to be an helpful advice... -- http://mail.python.org/mailman/listinfo/python-list
Re: Know if a object member is a method
On Mon, 01 Sep 2008 11:45:36 +0200, Luca wrote: But not so easy to fool a type check: type(x) == new.function False Of course that's not bullet-proof either. I leave it as an exercise to discover how you might break that piece of code. Ok, so... What is the best way to do this? The most pythonic? The most pythonic might be not checking at all but simply *call* the object and deal with possible failures. What's your use case? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Know if a object member is a method
Luca wrote: On Mon, Sep 1, 2008 at 11:35 AM, Steven D'Aprano [EMAIL PROTECTED] wrote: ... But not so easy to fool a type check: type(x) == new.function False Of course that's not bullet-proof either. I leave it as an exercise to discover how you might break that piece of code. Ok, so... What is the best way to do this? The most pythonic? The question would be - why do you want this? Is it just curiosity or can we find a better solution to the overall problem, once understood? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Know if a object member is a method
On Mon, 01 Sep 2008 11:45:36 +0200, Luca asked about recognizing methods: What is the best way to do this? The most pythonic? That depends on why you are doing it, and what you want to do with the information once you've found it. If you are experimenting in the interactive interpreter, the easiest way is simply call the method and see what happens: obj.methodName() # call the method If it succeeds, then it is some sort of callable, a method or a function or something more unusual. If you fear side-effects, then use: callable(obj.methodName) Alternatively, you can read the docs: help(obj) help(obj.methodName) If your aim is to write something like a debugger, profiler, or some other application that needs to inspect arbitrary objects and work out what they do, then you probably should be using: isinstance(obj.methodName, new.instancemethod) But remember that not all callable attributes are instancemethods! There is no one right way of doing this. Hope this helps. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0b2 cannot map '\u12b'
On Mon, 01 Sep 2008 02:27:54 -0400, Terry Reedy wrote: I doubt the OP 'chose' cp437. Why does Python using cp437 even when the default encoding is utf-8? On WinXP sys.getdefaultencoding() 'utf-8' s='\u012b' s Traceback (most recent call last): File stdin, line 1, in module File C:\Program Files\Python30\lib\io.py, line 1428, in write b = encoder.encode(s) File C:\Program Files\Python30\lib\encodings\cp437.py, line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u012b' in position 1: character maps to undefined Most likely because Python figured out that the terminal expects cp437. What does `sys.stdout.encoding` say? To put it another way, how can one 'choose' utf-8 for display to screen? If the terminal expects cp437 then displaying utf-8 might give some problems. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
about computer tips inonline click here
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
click here more tips in online about software
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
get paid on free offers
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
click heremore dollar
http://www.moneymaking4.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Know if a object member is a method
On Mon, Sep 1, 2008 at 2:18 PM, Steven D'Aprano [EMAIL PROTECTED] wrote: If your aim is to write something like a debugger, profiler, or some other application that needs to inspect arbitrary objects and work out what they do, then you probably should be using: isinstance(obj.methodName, new.instancemethod) But remember that not all callable attributes are instancemethods! There is no one right way of doing this. Hope this helps. Yes, this helps a lot. In facts I need to do something like a language parser. Thanks all. -- -- luca -- http://mail.python.org/mailman/listinfo/python-list
Re: Know if a object member is a method
Luca wrote: Yes, this helps a lot. In facts I need to do something like a language parser. a *parser* that works on object structures created by executing a Python program? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: __stack_chk_fail_local
thanks for the help, maybe the solution will be useful: in various Linux distributions are starting to ship with a version of the GNU C compiler which incorporates an extension which implements protection for stack-smashing. In that case the Makefile has to modified with CFLAGS = -fno-stack-protector gianluca Marco Bizzarri wrote: On Sat, Aug 30, 2008 at 3:03 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Thanks! I've resolved the problem with libraries but... I've still error with this message: ImportError: ./_python_grass6.so: undefined symbol: __stack_chk_fail_local exuse me, I'm not a guru. Gianluca I'm not a guru either, Gianluca ;) I made a little search on Google; the first link is the following: http://ubuntuforums.org/showthread.php?t=352642 can you apply the suggestion? I think you should give a little more context on your problem, also, because I think it has to do with your setup (not that you setup something in the wrong way: just to have context). Regards Marco -- http://mail.python.org/mailman/listinfo/python-list
How to print first(national) char from unicode string encoded in utf-8?
Hi, I have a problem with unicode string in Pylons templates(Mako). I will print first char from my string encoded in UTF-8 and urllib.quote(), for example string 'Łukasz': ${urllib.unquote(c.user.firstName).encode('latin-1')[0:1]} and I received this information: type 'exceptions.UnicodeDecodeError': 'utf8' codec can't decode byte 0xc5 in position 0: unexpected end of data When I change from [0:1] to [0:2] everything is ok. I think it is because of unicode and encoding utf-8(2 bytes). How to resolve this problem? Best regards -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0b2 cannot map '\u12b'
On Sep 1, 8:19 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Mon, 01 Sep 2008 02:27:54 -0400, Terry Reedy wrote: I doubt the OP 'chose' cp437. Why does Python using cp437 even when the default encoding is utf-8? On WinXP sys.getdefaultencoding() 'utf-8' s='\u012b' s Traceback (most recent call last): File stdin, line 1, in module File C:\Program Files\Python30\lib\io.py, line 1428, in write b = encoder.encode(s) File C:\Program Files\Python30\lib\encodings\cp437.py, line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u012b' in position 1: character maps to undefined Most likely because Python figured out that the terminal expects cp437. What does `sys.stdout.encoding` say? To put it another way, how can one 'choose' utf-8 for display to screen? If the terminal expects cp437 then displaying utf-8 might give some problems. Ciao, Marc 'BlackJack' Rintsch So, it is not a problem with the program, but a problem when I print it out. sys.stdout.encoding does say cp437. Now, when I don't print anything out, the program hangs. I will try this again and let the board know the results. Thanks for all of your insight. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print first(national) char from unicode string encoded in utf-8?
2008/9/1 [EMAIL PROTECTED]: Hi, I have a problem with unicode string in Pylons templates(Mako). I will print first char from my string encoded in UTF-8 and urllib.quote(), for example string 'Łukasz': ${urllib.unquote(c.user.firstName).encode('latin-1')[0:1]} and I received this information: type 'exceptions.UnicodeDecodeError': 'utf8' codec can't decode byte 0xc5 in position 0: unexpected end of data When I change from [0:1] to [0:2] everything is ok. I think it is because of unicode and encoding utf-8(2 bytes). How to resolve this problem? Best regards -- http://mail.python.org/mailman/listinfo/python-list First: you're talking about utf8 encoding, but you've written latin1 encoding. Even though I do not know Mako templates, there should be no problem in your snippet of code, if encoding is latin1, at least for what I can understand. Do not assume utf8 is a two byte encoding; utf8 is a variable length encoding. Indeed, 'a' encoded as utf8 is 'a' (one byte) 'à' encode as utf8 is '\xc3\xa0' (two bytes). Can you explain what you're trying to accomplish (rather than how you're tryin to accomplish it) ? Regards Marco -- Marco Bizzarri http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Multiple window handling
Hi!! I'm trying to program an application which have multiple windows and is capable of executing method defined inside class of one another, i tries a simpel frame work here and am creating Toplevel inside method as the new window to be genereated, and again want another window to be loaded when the widget inside toplevel is executed as necessary..but am feeling lost to either create a class for such new window or write function again.. also, when running clearentry() it is not working...have i missed something here.. Programming with multiple window is main task for me..so how it can be done??? the code i tried is here, from Tkinter import * import sys import os class toplevel1(Tk): def __init__(self,parent): Tk.__init__(self,parent) self.parent=parent self.initialize() def initialize(self): label=Label(self, text=Toplevel Practice).pack(side=TOP) button1=Button(self,text=Child 1,command=self.openchild1).pack(side=LEFT) button2=Button(self,text=Child 2,command=self.openchild2).pack(side=LEFT) self.resizable(width=NO,height=YES) self.geometry('300x300') def openchild1(self): c1 = Toplevel(self,bg=#aabbcc,height=300,width=300,borderwidth=1) c1.title(Child One) c1.resizable(width=NO,height=NO) F = Frame(c1,height=40,width=300) F.pack(side=TOP,fill=X,expand=1) llb=Label(F,text=Enter command..) llb.pack(side=LEFT,padx=1) ent = Entry(F,width=50) ent.pack(side=LEFT,padx=2,expand=1) bCl = Button(F,text=Clear Text,command=self.clearentry) bCl.pack(side=LEFT,padx=2, pady=0) bQt = Button(F,text=Quit, command=F.quit) bQt.pack(side=RIGHT,padx=1, pady=0) F1=Frame(c1,relief=SUNKEN,height=330,width=300) txt=Text(F1) scr=Scrollbar(F1,orient=VERTICAL,command=txt.yview,bg=green,width=20) txt.insert(END,inside txt...) txt.config(yscrollcommand=scr.set) F1.pack(side=TOP,fill=X,expand=1) txt.pack(side=LEFT,fill=BOTH,padx=1) scr.pack(side=RIGHT,fill=Y) F2=Frame(c1,height=30,width=300,relief=RAISED) F2.pack(side=BOTTOM,fill=X,expand=1) llb1=Label(F2,text= Low Down statusbar) llb1.pack(side=LEFT) def clearentry(self): self.ent.delete(0,END) def openchild2(self): c2 = Toplevel(self,bg=red,height=200,width=200,borderwidth=1) c2.geometry('200x200') c2.resizable(width=NO,height=NO) c2.title(Child Two) Label(c2, text=This is a regular toplevel window.).pack(side=TOP) if __name__==__main__: obj=toplevel1(None) obj.title('Main Window') obj.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Using an existing instance as parent
Hi, I was trying to find a way to set, upon __init__() the parent of a class to an existing instance. Here is a minimal example of what I'm trying to do: class A(object): def __init__(self, x): self.x = x class B(A): def __init__(self, *args): if not isinstance(args[0], A): super(B, self).__init__(args[0]) else: self = args[0] self.y = args[1] b = B(4, 6) print 'b:', b.x, b.y, type(b) a = A(7) c = B(a, 3) # Means: please set c parent's using instance a print 'c:', c.x, c.y, type(c) This does not work as can be tested. The reason I'm in search for a solution in this area is that in our project, A is not copy-able (it is written using a boost.python binding to a C++ object that does not allow copying) - so I can't simply call, inside B's __init__(), a copy constructor for A. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Eleganz way to get rid of \n
Hello, I'm quite often using this construct: for l in open(file, r): do something here, l contains the \n or \r\n on windows at the end. I get rid of it this way: for l in open(file, r): while l[-1] in \r\n: l = l[:-1] I find this a little bit clumsy, but it works fine. Has someone a better solution ? Thanks Hans -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print first(national) char from unicode string encoded in utf-8?
On 1 Wrz, 15:10, Marco Bizzarri [EMAIL PROTECTED] wrote: 2008/9/1 [EMAIL PROTECTED]: Hi, I have a problem with unicode string in Pylons templates(Mako). I will print first char from my string encoded in UTF-8 and urllib.quote(), for example string 'Łukasz': ${urllib.unquote(c.user.firstName).encode('latin-1')[0:1]} and I received this information: type 'exceptions.UnicodeDecodeError': 'utf8' codec can't decode byte 0xc5 in position 0: unexpected end of data When I change from [0:1] to [0:2] everything is ok. I think it is because of unicode and encoding utf-8(2 bytes). How to resolve this problem? Best regards -- http://mail.python.org/mailman/listinfo/python-list First: you're talking about utf8 encoding, but you've written latin1 encoding. Even though I do not know Mako templates, there should be no problem in your snippet of code, if encoding is latin1, at least for what I can understand. Do not assume utf8 is a two byte encoding; utf8 is a variable length encoding. Indeed, 'a' encoded as utf8 is 'a' (one byte) 'à' encode as utf8 is '\xc3\xa0' (two bytes). Can you explain what you're trying to accomplish (rather than how you're tryin to accomplish it) ? Regards Marco -- Marco Bizzarrihttp://notenotturne.blogspot.com/http://iliveinpisa.blogspot.com/ When I do ${urllib.unquote(c.user.firstName)} without encoding to latin-1 I got different chars than I will get: no Łukasz but Åukasz -- http://mail.python.org/mailman/listinfo/python-list
CSV reader and unique ids
Hi All, I'm trying to use the CSV module to read in some data and then use a hashable method (as there are millions of records) to find unique ids and push these out to another file, can anyone advise? Below is the code so far fin = open(CSV_INPUT, rb) fout = open(CSV_OUTPUT, wb) reader = csv.reader(fin, delimiter=chr(254)) writer = csv.writer(fout) headerList = reader.next() UID = {} #For help #print headerList # ['Time', 'User-ID', 'IP'] try: for row in reader[1]: UID[row] = 1 else: List= UID.keys() writer.writerows(List) fin.close() fout.close() Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print first(national) char from unicode string encoded in utf-8?
On Mon, Sep 1, 2008 at 3:25 PM, [EMAIL PROTECTED] wrote: When I do ${urllib.unquote(c.user.firstName)} without encoding to latin-1 I got different chars than I will get: no Łukasz but Å ukasz -- http://mail.python.org/mailman/listinfo/python-list That's crazy. string.encode('latin1') gives you a latin1 encoded string; latin1 is a single byte encoding, therefore taking the first byte should be no problem. Have you tried: urlib.unquote(c.user.firstName)[0].encode('latin1') or urlib.unquote(c.user.firstName)[0].encode('utf8') I'm assuming here that the urlib.unquote(c.user.firstName) returns an encodable string (which I'm absolutely not sure), but if it does, this should take the first 'character'. Regards Marco -- Marco Bizzarri http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Eleganz way to get rid of \n
On Sep 1, 9:25 am, Hans Müller [EMAIL PROTECTED] wrote: Hello, I'm quite often using this construct: for l in open(file, r): do something here, l contains the \n or \r\n on windows at the end. I get rid of it this way: for l in open(file, r): while l[-1] in \r\n: l = l[:-1] I find this a little bit clumsy, but it works fine. Has someone a better solution ? Thanks Hans Can you do this: f = open(fname) for x in f: line = x.rstrip('\r\n') -- http://mail.python.org/mailman/listinfo/python-list
Re: Eleganz way to get rid of \n
On Mon, 01 Sep 2008 15:25:03 +0200, Hans M�ller wrote: I'm quite often using this construct: for l in open(file, r): do something Has someone a better solution ? The most general would be to use rstrip() without arguments: a=some string\r\n a.rstrip() 'some string' but be careful, because it will also cut whitespaces: a=some string\t \r\n a.rstrip() 'some string' so maybe you could do this: a.rstrip('\n').rstrip('\r') 'some string\t ' HTH. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list
Re: SAXReaderNotAvailble: No parsers found
On Aug 30, 8:59 pm, josh logan [EMAIL PROTECTED] wrote: Vincent Yau [EMAIL PROTECTED] writes: I am trying to use Python SAX API to parse XML files. I do see expat.py somewhere underneath my Python 2.1.1 installation (on Solaris). But I got this error when invoking the xml.sax.make_parser() call. Any tip/help much appreciated. You should install Expat before building Python. Best, you edit Modules/Setup to build pyexpat explicitly. Regards, Martin Fast-forward to 2008 I installed Python 3.0b2 on a Windows Vista laptop (after having previously installed Python 2.5), and I am getting this same error: Traceback (most recent call last): File Programming\Python\monkeys.py, line 24, in module test_parse(sys.argv[1]) File Programming\Python\monkeys.py, line 21, in test_parse xml.sax.parse(f, handler) File C:\Python30\lib\xml\sax\__init__.py, line 30, in parse parser = make_parser() File C:\Python30\lib\xml\sax\__init__.py, line 90, in make_parser raise SAXReaderNotAvailable(No parsers found, None) xml.sax._exceptions.SAXReaderNotAvailable: No parsers found I see a pyexpat.lib in the C:\Python30\libs folder. I also see a pyexpat.pyd in the C:\Python30\DLLs folder. It works in Python 2.5. I installed Python 3.0b2 as admin. Does anyone know what is wrong and how to fix it? Does anyone have an answer for this? I uninstalled both Python 2.5 and Python 3.0b2 and then re-installed 3.0b2, thinking that the installer was confusing 2.5 and 3.0b2 on Windows Vista. Still have the same issue. I had to use my XP machine, since the Vista installation seems broken for Python 3.0b2. How do I fix this? How do I get Python to notice the pyexpat.lib in the C:\Python30\DLLs folder in Vista? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Eleganz way to get rid of \n
On Sep 1, 9:41 am, Wojtek Walczak [EMAIL PROTECTED] wrote: On Mon, 01 Sep 2008 15:25:03 +0200, Hans Müller wrote: I'm quite often using this construct: for l in open(file, r): do something Has someone a better solution ? The most general would be to use rstrip() without arguments: a=some string\r\n a.rstrip() 'some string' but be careful, because it will also cut whitespaces: a=some string\t \r\n a.rstrip() 'some string' so maybe you could do this: a.rstrip('\n').rstrip('\r') 'some string\t ' HTH. -- Regards, Wojtek Walczak,http://tosh.pl/gminick/ You can send both '\n' and '\r' in one rstrip call. No need for 2 separate calls. -- http://mail.python.org/mailman/listinfo/python-list
Re: logging - how to use in a library?
On Aug 29, 11:02 pm, Thomas Heller [EMAIL PROTECTED] wrote: BTW: Let me say that the more I useloggingthe more I like it.loggingis a fantastic package! Thank you, I can say the same for ctypes and py2exe :-) Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
On 2008-09-01, W. eWatson [EMAIL PROTECTED] wrote: That's the question in Subject. For example, the difference between 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in years between, say, 1990 and 2050. In other words not some really strange period of time well outside our current era of history. Does the standard library's datetime module not do what you want? http://docs.python.org/lib/module-datetime.html -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Command lime code
On 2008-08-29, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I am new to python. OK. I did find a page which listed some code - IE chdir type code but can not find it again. I have absolutely no clue what you mean. Can you supply an address? Sure, in fact, I can supply two! http://www.python.org/ http://www.google.com/ -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Eleganz way to get rid of \n
Hans Müller a écrit : Hello, I'm quite often using this construct: for l in open(file, r): do something here, l contains the \n or \r\n on windows at the end. I get rid of it this way: for l in open(file, r): while l[-1] in \r\n: l = l[:-1] I find this a little bit clumsy, indeed. but it works fine. Has someone a better solution ? help(str.rstrip) -- http://mail.python.org/mailman/listinfo/python-list
Re: Eleganz way to get rid of \n
Hans Müller wrote: I'm quite often using this construct: for l in open(file, r): do something here, l contains the \n or \r\n on windows at the end. nope -- if you open a file in text mode (without the b), the I/O layer will translate \r\n to \n on Windows. if you want even more robust behaviour, use the U flag (for universal newlines); that'll handle old-style Mac files too. (as others have pointed out, a plain rstrip() is usually the best choice anyway. giving meaning to trailing whitespace in text files is usually a really lousy idea). /F -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
Grant Edwards wrote: On 2008-09-01, W. eWatson [EMAIL PROTECTED] wrote: That's the question in Subject. For example, the difference between 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in years between, say, 1990 and 2050. In other words not some really strange period of time well outside our current era of history. Does the standard library's datetime module not do what you want? http://docs.python.org/lib/module-datetime.html Yes, it would seem so. This works fine. date1 = datetime.date(2007, 2, 27) date2 = datetime.date(2007, 3, 3) print date1: , date1 print date2: , date2 diff = date2 - date1 print diff: , diff result: date1: 2007-02-27 date2: 2007-03-03 diff: 4 days, 0:00:00 I was pondering this in pyfdate, but perhaps missed it or it was not obvious to me in the tutorial for some reason. There are few places where it's not quite complete. pyfdate has some rules for dealing with length of month oddities that started me thinking it would have difficulty with situations like the above. However, it would seem any general implementation of time and date should be capable of making similar calculations without difficulty. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet Web Page: www.speckledwithstars.net/ -- http://mail.python.org/mailman/listinfo/python-list
python extension dynamic linking
Hi, I am writing Python extension in C++, in this extension I am using methods from another Python extension. On Linux I am currently linking my extension with used Python extension -- what is quite ugly. gcc ... -lgdi where gdi is a link to C++ extension imported by 'module' I would like to avoid direct linking here. import module # export some symbol used in my_module import my_module I realized that on Mac it is possible to dynamically link C++ extension using -bundle -undefined dynamic_lookup I wonder how to solve this problem on Linux or MS Window. Thanks for any pointers... Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Using an existing instance as parent
André a écrit : Hi, I was trying to find a way to set, upon __init__() the parent of a class to an existing instance. ??? Sorry but I just can't make any sense of this. Here is a minimal example of what I'm trying to do: class A(object): def __init__(self, x): self.x = x class B(A): def __init__(self, *args): if not isinstance(args[0], A): super(B, self).__init__(args[0]) else: self = args[0] Rebinding an argument only affect the current namespace. self.y = args[1] b = B(4, 6) print 'b:', b.x, b.y, type(b) a = A(7) c = B(a, 3) # Means: please set c parent's using instance a print 'c:', c.x, c.y, type(c) This does not work as can be tested. The reason I'm in search for a solution in this area is that in our project, A is not copy-able (it is written using a boost.python binding to a C++ object that does not allow copying) - so I can't simply call, inside B's __init__(), a copy constructor for A. Ok, I think I get the point... When an A instance is passed as first arg, you'd like to use this instance's state to call super(B).__init__ ? If so, here's a possible solution (QD, to be corrected according to real use case, etc): import copy class B(A): def __init__(self, *args): if isinstance(args[0], A): x = copy.copy(args[0].x) # if it's a mutable and you want a copy else: x = args[0] super(B, self).__init__(x) self.y = args[1] Be sure to carefully read copy's doc. -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
On 2008-09-01, W. eWatson [EMAIL PROTECTED] wrote: Grant Edwards wrote: On 2008-09-01, W. eWatson [EMAIL PROTECTED] wrote: That's the question in Subject. For example, the difference between 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in years between, say, 1990 and 2050. In other words not some really strange period of time well outside our current era of history. Does the standard library's datetime module not do what you want? http://docs.python.org/lib/module-datetime.html Yes, it would seem so. This works fine. It would probably be worth your while to read through one of introductory Python books or just browse through the Python tutorial: http://docs.python.org/tut/ I was pondering this in pyfdate, but perhaps missed it or it was not obvious to me in the tutorial for some reason. Sorry, can't help you there -- I've never heard of pyfdate. The timedate module that comes with Python has always done what I needed to do with dates/times. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Buffer objects
Greetings, I need a little help with buffer objects. Many Python objects export the buffer interface, or can be persuaded to create a buffer object with a buffer() call. First question, the buffer() function appears very quick. Does it just wrap the internal pointer and then exit? Second question, the buffer interface does include support for multiple segments of memory. All the buffers I have examined are only a single segment, is this a rarely used functionality? Third question, having got my buffer interface I want to get the actual pointer out so that I can call foreign functions with ctypes with the pointer as a function argument and add offsets to it, so I would like it as a plain int. What is the recommended method of accessing the raw pointer from the buffer object? It must be me but I have found the whole buffer thing difficult to understand from the docs, it appears only useful to C coders, but I use the buffer interface (GetData()) of wx.Image objects a lot in my work. TomH celephicus(AT)gmail(DOT)com -- http://mail.python.org/mailman/listinfo/python-list
Printing list of dates starting today
Hello everyone, please, I need your help. I'm new to python, so I don't know if this will seem like a stupid question to some of you ... I have a need to write to a file (or just print on screen, that part doesn't matter at this point) a list of dates, starting today. For example: 02.09.2008. tue 03.09.2008. wed et cetera Is there some intristic function in python which can help me with this or do I have to do the calendar calculation by hand ? Would appreciate all the help I can get. Regards Luka Djigas -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing list of dates starting today
Luka Djigas wrote: please, I need your help. I'm new to python, so I don't know if this will seem like a stupid question to some of you ... I have a need to write to a file (or just print on screen, that part doesn't matter at this point) a list of dates, starting today. For example: 02.09.2008. tue 03.09.2008. wed et cetera Is there some intristic function in python which can help me with this or do I have to do the calendar calculation by hand ? import datetime # see: http://docs.python.org/lib/module-datetime.html d = datetime.date.today() str(d) '2008-09-01' d.strftime(%d.%m.%Y. %a) '01.09.2008. Mon' # see http://docs.python.org/lib/module-time.html#l2h-2826 d.strftime(%d.%m.%Y. %a).lower() '01.09.2008. mon' for i in range(10): ... print d.strftime(%d.%m.%Y. %a).lower() ... d += datetime.timedelta(days=1) ... 01.09.2008. mon 02.09.2008. tue 03.09.2008. wed 04.09.2008. thu 05.09.2008. fri 06.09.2008. sat 07.09.2008. sun 08.09.2008. mon 09.09.2008. tue 10.09.2008. wed /F -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
Grant Edwards wrote: On 2008-09-01, W. eWatson [EMAIL PROTECTED] wrote: Grant Edwards wrote: On 2008-09-01, W. eWatson [EMAIL PROTECTED] wrote: That's the question in Subject. For example, the difference between 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in years between, say, 1990 and 2050. In other words not some really strange period of time well outside our current era of history. Does the standard library's datetime module not do what you want? http://docs.python.org/lib/module-datetime.html Yes, it would seem so. This works fine. It would probably be worth your while to read through one of introductory Python books or just browse through the Python tutorial: http://docs.python.org/tut/ Oddly, Leaning Python has no mention of datetime (not date or time), at least, that I could find. I'm considering the Nutshell book, 2nd ed., as a better reference (and cross reference) to various topics. I was pondering this in pyfdate, but perhaps missed it or it was not obvious to me in the tutorial for some reason. Sorry, can't help you there -- I've never heard of pyfdate. The timedate module that comes with Python has always done what I needed to do with dates/times. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet Web Page: www.speckledwithstars.net/ -- http://mail.python.org/mailman/listinfo/python-list
FHA Refinance Loan
On October 1, 2008, new FHA Refinance Loan Guidelines will go into effect as part of The Housing and Economic Recovery Act of 2008. This new FHA Mortgage program is designed to help thousands of homeowners who are at risk of foreclosure in their curent conventional or sub- prime home loans. The details of The “HOPE for Homeowners Act of 2008� are as follows: 1. Eligible Borrowers Only owner-occupants who are unable to afford their mortgage payments are eligible for the program. No investors or investor properties will qualify. Homeowners must certify, under penalty of law, that they have not intentionally defaulted on their loan to qualify for the program and must have a mortgage debt-to-income ratio greater than 31% as of March 1, 2008. Lenders must document and verify borrowers’ income with the IRS. 2. Home Equity Appreciation Sharing In order to avoid a windfall to the borrower created by the new 90% loan-to-value FHA-insured mortgage, the borrower must share the newly- created equity and future appreciation equally with FHA. This obligation will continue until the borrower sells the home or refinances the FHA-insured mortgage. Moreover, the homeowner’s access to the newly created equity will be phased-in over a 5 year period. The borrower agrees to repay the following share of any home equity appreciation with the FHA when the home is sold or refinanced again; A. 100% of any equity earned is paid to the government FHA if the home sells or the borrower refinances within 1 year. B. 90% of any equity earned is paid to the FHA if the home sells or the borrower refinances within 2 years. C. 80% of any positive equity earned is paid to the FHA if the home sells or the borrower refinances within 3 years. D. 70% of any positive equity earned is paid to the FHA if the home sells or the borrower refinances within 4 years. E. 60% of any positive equity earned is paid to the FHA if the home sells or the borrower refinances within 5 years. F. 50% of any positive equity earned is paid to the FHA if the home sells or the borrower refinances after 5 years. Note: The FHA requires a 3% Exit Fee of the Mortgage Principal Balance when the borrower sells or refinances the home again. 3. Other Requirements Existing Subordinate Liens Before participating in this program, all subordinate liens (such as second loans, home equity loans, etc.) must be extinguished. This will have to be done through negotiation with the first lien holder. Mortgage Insurance and Other Fees The Up Front FHA Mortgage Insurance Premium that is required on all FHA Refinance Loans will change as part The Housing and Economic Recovery Act of 2008. The Monthly MI Rates have also been updated. The following FHA MI rates will begin on October 1, 2008 and will be effective for 12 months; FHA Up Front MIP - Required on all FHA Loans (Can be financed into loan amount). 1.75% - Normal FHA 203(b) Refinance 1.5% - FHA Streamlined Refinance 3.0% - FHASecure (Refinance for high risk borrowers who are already delinquent on current mortgage) Monthly MI �� Multiply the loan amount by the figure below and then divide by 12. The result is your Monthly Mortgage Insurance. 30 Year Note 0.55% - Refinance greater than 90% of the home’s LTV. 0.50% - Refinance less than or equal to 90% of the home’s LTV. 15 Year Note 0.25% - Refinance greater than 90% of the home’s LTV. Monthly MI is not required on an 15 Year FHA Refinance Loan with an LTV of 90% or less. The FHA Refinance Loan Process Each new loan will be originated and underwritten on a case-by-case basis. To get approved, your income statements, bank accounts, credit scores and work history will be examined. A new appraisal must be performed on your home to determine its current value. If doesnt have positive equity, then you must contact your current lender and negotiate with them to reduce (write down) your current mortgage to 90% of its current appraised value. If your current lender agrees to the write down, then you will be able to proceed with the FHA refinance. www.my-quickloans.com -- http://mail.python.org/mailman/listinfo/python-list
Problem with Twisted
Hello. I have something like that: from twisted.words.protocols.jabber import xmlstream from twisted.internet import protocol from twisted.words.xish import domish, utility from twisted.internet import reactor from twisted.python import log import sys, hashlib log.startLogging(sys.stdout) def magicHash(password, sid): magic1 = 0x50305735 magic2 = 0x12345671 sum = 7 for s in range(len(password)): z = ord(password[s]); if (z == ' '): continue if (z == '\t'): continue magic1 = magic1 ^ magic1 0x3f) + sum) * z) + (magic1 8)) magic2 = magic2 + ((magic2 8) ^ magic1) sum += z magic1 = magic1 0x7fff magic2 = magic2 0x7fff return ('%08x%08x'%(magic1, magic2)) def ping(xmlstream): print 'ping' xmlstream.send(' \t ') reactor.callLater(40, ping, xmlstream) class TlenAuthInitializer(object): def __init__(self, xs): print Wykonywanie TlenAuthInitializer self.xmlstream = xs def initialize(self): print Wykonywanie TlenAuthInitializer - initialize iq = xmlstream.IQ(self.xmlstream, set) print '1' iq['id'] = self.xmlstream.sid print '2' q = iq.addElement('query', 'jabber:iq:auth') print '3' q.addElement('username', content = self.xmlstream.authenticator.jid) print '4' q.addElement('digest', content = hashlib.sha1(magicHash(self.xmlstream.authenticator.password, self.xmlstream.sid)).hexdigest()) print '4' q.addElement('resource', content = 't') print '6' q.addElement('host', content = 'tlen.pl') print q.toXml(prefixes=self.prefixes, closeElement=0) print '7' d = iq.send('q') print '8' d.addCallback(self._authreply) print '9' d.addErrBack(self._authfail) print '10' def _authreply(self, el): print Wykonywanie TlenAuthInitializer - _authreply print el.toXml() reactor.callLater(40, ping, self.xmlstream) def _authfail(self, el): print Wykonywanie TlenAuthInitializer - _authfail print el.toXml() class TlenAuthenticator(xmlstream.ConnectAuthenticator): def __init__(self, jid, password, host): print Wykonywanie TlenAuthenticator xmlstream.ConnectAuthenticator.__init__(self, host) self.jid = jid self.password = password def associateWithStream(self, xs): print Wykonywanie TlenAuthenticator - associateWithStream xs.version = (0, 0) xmlstream.ConnectAuthenticator.associateWithStream(self, xs) inits = [(TlenAuthInitializer, True)] for initClass, required in inits: init = initClass(xs) init.required = required xs.initializers.append(init) class TlenStream(xmlstream.XmlStream): def sendHeader(self): print Wykonywanie TlenStream - sendHeader rootElem = domish.Element((None, 's')) rootElem['v'] = '9' rootElem['t'] = '06000224' self.rootElem = rootElem self.send(rootElem.toXml(prefixes=self.prefixes, closeElement=0)) self._headerSent = True print 'XMLed rootElem from sendHeader '+rootElem.toXml(prefixes=self.prefixes, closeElement=0) def sendFooter(self): print Wykonywanie TlenStream - sendFooter self.send('/s') def onDocumentStart(self, rootelem): print Wykonywanie TlenStream - onDocumentStart xmlstream.XmlStream.onDocumentStart(self, rootelem) print 'rootelem from onDocumentStart '+rootelem.toXml() if rootelem.hasAttribute(i): self.sid = rootelem[i] self.authenticator.streamStarted(rootelem) class TlenStreamFactory(xmlstream.XmlStreamFactory): def __init__(self, authenticator): print Wykonywanie TlenStreamFactory xmlstream.XmlStreamFactory.__init__(self, authenticator) self.authenticator = authenticator def buildProtocol(self, _): print Wykonywanie TlenStreamFactory - buildProtocol self.resetDelay() # Create the stream and register all the bootstrap observers xs = TlenStream(self.authenticator) xs.factory = self for event, fn in self.bootstraps: xs.addObserver(event, fn) return xs def lg(el): print 'all',el def err(el):
Re: Writing to ms excel
http://docs.python.org/lib/module-csv.html -- http://mail.python.org/mailman/listinfo/python-list
Re: CSV reader and unique ids
Mike P wrote: I'm trying to use the CSV module to read in some data and then use a hashable method (as there are millions of records) to find unique ids and push these out to another file, You could either zip with a counter or use the uuid module, depending on just how unique you want your ids to be. code import os, sys import csv import itertools import uuid stuff = the quick brown fox jumps over the lazy dog.split () f = open (output.csv, wb) writer = csv.writer (f) # # Style 1 - numeric counter # writer.writerows (zip (itertools.count (), stuff)) # # Style 2 - uuid # writer.writerows ((uuid.uuid1 (), s) for s in stuff) f.close () os.startfile (output.csv) /code TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing list of dates starting today
On 2008-09-01, Luka Djigas [EMAIL PROTECTED] wrote: please, I need your help. I'm new to python, so I don't know if this will seem like a stupid question to some of you ... There are several ways to do it. Have a look at the documentation of modules time and datetime. For this exact problem time is the most straighforward one. I have a need to write to a file (or just print on screen, that part doesn't matter at this point) a list of dates, starting today. For example: 02.09.2008. tue 03.09.2008. wed 0 [EMAIL PROTECTED]:~ $ /usr/bin/python Python 2.5.2 (r252:60911, Jul 31 2008, 17:31:22) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type help, copyright, credits or license for more information. import time DAY = 60 * 60 * 24 today = time.time() for i in (0, 1, 2, 3): ... t = time.gmtime(time.time() + i * DAY) ... print time.strftime('%d.%m.%Y, %a', t) ... 01.09.2008, Mon 02.09.2008, Tue 03.09.2008, Wed 04.09.2008, Thu -- Ari Makela late autumn - [EMAIL PROTECTED] a single chair waiting http://arska.org/hauva/ for someone yet to come -- Arima Akito -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
On 2008-09-01, W. eWatson [EMAIL PROTECTED] wrote: Oddly, Leaning Python has no mention of datetime (not date or time), at least, that I could find. I'm considering the Nutshell book, 2nd ed., as a better reference (and cross reference) to various topics. datetime is pretty new standard library module. I'm quite sure that it wasn't around when the latest edition of Learning Python was written. -- Ari Makela late autumn - [EMAIL PROTECTED] a single chair waiting http://arska.org/hauva/ for someone yet to come -- Arima Akito -- http://mail.python.org/mailman/listinfo/python-list
Make money using free affiliate programs
Making money with affiliate programs is a better way, please see this web-site: http://www.abicana.com/affiliatenetworks.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Some problems with classes
Chris Rebert a écrit : On Sun, Aug 31, 2008 at 6:39 PM, ssecorp [EMAIL PROTECTED] wrote: Why/how is it possible to add variables like this? I don't understand this mechanism: http://docs.python.org/tut/node11.html#SECTION001133 Under the covers, Python objects are implemented using dictionaries, Not necessarily. so adding an attribute just adds a new key-value pair to the object's internal dictionary (which, incidentally, you can access as someobj.__dict__). Idem. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0b2 cannot map '\u12b'
Marc 'BlackJack' Rintsch wrote: On Mon, 01 Sep 2008 02:27:54 -0400, Terry Reedy wrote: I doubt the OP 'chose' cp437. Why does Python using cp437 even when the default encoding is utf-8? On WinXP sys.getdefaultencoding() 'utf-8' s='\u012b' s Traceback (most recent call last): File stdin, line 1, in module File C:\Program Files\Python30\lib\io.py, line 1428, in write b = encoder.encode(s) File C:\Program Files\Python30\lib\encodings\cp437.py, line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u012b' in position 1: character maps to undefined Most likely because Python figured out that the terminal expects cp437. What does `sys.stdout.encoding` say? The interpreter in the command prompt window says CP437. The IDLE Window says 'cp1252', and it handles the character fine. Given that Windows OS can handle the character, why is Python/Command Prompt limiting output? Characters the IDLE window cannot display (like surrogate pairs) it displays as boxes. But if I cut '[][]' (4 chars) and paste into Firefox, I get 3 chars. '[]' where [] has some digits instead of being empty. It is really confusing when every window on 'unicode-based' Windows handles a different subset. Is this the fault of Windows or of Python and IDLE (those two being more limited that FireFox)? To put it another way, how can one 'choose' utf-8 for display to screen? If the terminal expects cp437 then displaying utf-8 might give some problems. My screen displays whatever Windows tells the graphics card to tell the screen to display. In OpenOffice, I can select a unicode font that displays at least everything in the BasicMultilingualPlane (BMP). Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Getting an objetcs dict?
I did nce(I think). class X X.__dict__() and ngot a dict of its variables. Now i get errors doing this. what am i doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
TkMessageBox - Using sys.exit() is a a great pain. Looking for other similar commands.
Hi, I'm using a TkMessageBox for handling some errors and displaying them through the message boxes. My code is as below: if selectedVer == strNoArchivedResults: tkMessageBox._show(Error, \ type='ok', icon='error', \ message=Cannot perform Results Comparison as no results are currently archived for this library) sys.exit() This message box is displayed when the above comdition is met: Using sys.exit() is a great pain since this closes my parent GUI ( the main GUI). Please suggest some other way around. Thanks and regards, Rajat -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting an objetcs dict?
On Mon, 1 Sep 2008 11:31:42 -0700 (PDT), ssecorp wrote: I did nce(I think). class X X.__dict__() and ngot a dict of its variables. Now i get errors doing this. what am i doing wrong? You're not asking smart questions: http://www.catb.org/~esr/faqs/smart-questions.html HINT: the attribute you're accessing is not a callable. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Command lime code
Manuel Ebert wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Okay, I'll take I wild guess: By command lime code you did not refer to the algorithmic domination of citrus fruit, but rather to that window with the tiny blinking cursor and loads of text in white on black. Also by 'chdir' you probably mean the MS DOS equivalent to UNIX 'cd' (which AFAIK also works on MS DOS). So Googling for MS DOS Commands might be a good idea and yield, amongst others, this result: The os module also has an os-independent chdir() function. -- http://mail.python.org/mailman/listinfo/python-list
Benchmark differences between 32 and 64 bit Python?
Anyone have any benchmarks on the difference in performance between 32 and 64 bit versions of Python for specific categories of operation, eg. math, file, string, etc. operations? My question is OS neutral so feel free to share your experience with either Windows or Linux OS's. Thank you, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find position of dictionary values
Alexandru Palade wrote: lookfor = 'dfsdf' for item, value in kev.items(): if lookfor in value: print item print value.index(lookfor) break # assuming you only want one result slight variation: lookfor = 'dfsdf' for item, value in kev.items(): for i, val in enumerate(value): if val == lookfor: print item, i break # assuming you only want one result else: print lookfor, 'not found' This is what for-else is meant for. If you want 0 to many lookfor occurences, lookfor = 'dfsdf' hits = [] for item, value in kev.items(): for i, val in enumerate(value): if val == lookfor: hits.append((item, i)) print hits One-liner fanatics would, of course, rewrite this as hits = [(item, i) for item, value in kev.items() for i, val in enumerate(value) if val == lookfor] Terry Jan Reedy tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: The Importance of Terminology's Quality
From: George Neuner [EMAIL PROTECTED] A friend of mine had an early 8080 micros that was programmed through the front panel using knife switches When you say knife switches, do you mean the kind that are shaped like flat paddles? I think that would be the IMSAI, which came after the ALTAIR. Those flat paddle-shaped switched would presumably be much more comfortable on the fingers than the standard metal toggle switches on the ALTAIR. I had an ALTAIR, which made front-panel programming rather painful on the fingers. ... toggle in the binary address, latch it, toggle in the binary data, latch it, repeat ad nauseam. For manually loading software in sequential locations, you have to enter the binary address only once. After that, you press the EXAMINE-NEXT toggle to increment the address by one. That reduced the effort by nearly a factor of 3. Instead of toggling a 16-bit address and EXAMINE and 8-bit datum and STORE each time, you toggle just EXAMINE-NEXT and 8-bit datum and STORE for each consecutive memory location after the first. Note the address and data toggles are bistable, stay in whatever position you left them in, whereas the three control toggles (EXAMIME EXAMINE-NEXT STORE) are spring loaded, making momentary contact when you force them then spring back to inactive when you release them. It had no storage device initially ... to use it you had to input your program by hand every time you turned it on. Almost but not quite true. With static RAM, most of the data can survive power-downs of hours or even days. I had 28k bytes of static RAM on my ALTAIR, so if I needed to start it up after it had been shut down I'd toggle in the starting address by hand, EXAMINE that, compare what shows with what's on my printed listing, and if it matches just EXAMINE-NEXT to compare the next. In the few cases I saw a bit or two flipped, I'd re-enter that one byte of data. I had to do that only for my BOOT1 loader, which was hand-loaded from front panel and took text input in 3n+1 form from Beehive 3A terminal connected to serial port, maybe also for BOOT2 loader which had been loaded in 3n+1 form and took input in hexadecimal form, and maybe also for BOOT3 loader which had been loaded in hexadecimail form from Beehive and automatically downloaded the next bootstrap loader from modem. If only a few bytes (of BOOT2 or BOOT3) had been damaged by days of power down, comparing binary against listing to verify it's 99% correct, and then manually patching just one or two bytes, would be faster and safer than manually entering 3n+1 or hexadecimal from keyboard. But once BOOT3 was loaded, I always downloaded all the rest of the software from the PDP-10 over the modem. I did a little bit of programming on it, but I tired of it quickly. Did your friend's machine have two serial ports, one for local terminal and one for modem, and did you have access to a remote PDP-10 or other mainframe for running a cross-assembler? Or did you have some other computer locally available, where you could use that other computer both to store your library of code and to perform automated file transfer from archive on other computer to where it's needed on IMSAI? As did my friend - once he got the tape storage working (a new prom) Yeah, I never had the money to buy that, and with the PDP-10 available for both cross-assembling and archiving/downloading, I didn't need it. Machine coding is not relevant anymore - it's completely infeasible to input all but the smallest program. That's not totally true. For some educational purposes, like *really* understanding pointers (not the kind in C so much as the kind that are inherent in all pointer-linked data structures such as linked lists and binary search trees etc.), it helps to have some hands-on experience writing and executing machine-language code, in a sense actually seeing a register first point to the first byte of a CONS cell then by indexing with offset pointing *through* the *second* pointer of that CONS cell to whatever the CDR points to. Then mission impossible when your instructor tells you to see if there's a way to reverse that process, whereby you are given the register pointing to whatever the CDR points to, and you are supposed to find the address of the original CONS cell. Instant enlightenment, no lecture/sermon needed! -- http://mail.python.org/mailman/listinfo/python-list
Py 2.6 changes
I have just re-read the list of changes in Python 2.6, it's huge, there are tons of changes and improvements, I'm really impressed: http://docs.python.org/dev/whatsnew/2.6.html I'll need many days to learn all those changes! I can see it fixes several of the missing things/problems I have found in Python in the past, like the lack of information regarding the floating point it uses, etc. I have seen that many (smart) updates are from Hettinger. You can see a language gets better when you can remove often-used commodity functions/classes from your own 'bag of tricks' :-) (Like the permutations() function, etc). Python now must be compiled with C89 compilers (after 19 years!). This means that the Python source tree has dropped its own implementations of memmove and strerror, which are in the C89 standard library. I presume it's better for me to not hold my breath while I wait CPython to be written in C99 :-) Now math has factorial: http://docs.python.org/dev/library/math.html#math.factorial Seen how reduce() is removed from Python 3 (I know it's in itertools), and seeing that for me to write a productory() function was the first usage I have had for reduce, years ago, I think the math module can gain a productory() function too. For Python 2.7/3.1 I'd now like to write a PEP regarding the underscores into the number literals, like: 0b_0101_, 268_435_456 etc. I use such underscores all the time in the D language, and I think they can be a tiny but significant improvement for Python (and underscore is much better than just a space, because the underscore helps the person that reads the code to understand that's a single number). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0b2 cannot map '\u12b'
On Mon, 01 Sep 2008 14:25:01 -0400, Terry Reedy wrote: Marc 'BlackJack' Rintsch wrote: On Mon, 01 Sep 2008 02:27:54 -0400, Terry Reedy wrote: Most likely because Python figured out that the terminal expects cp437. What does `sys.stdout.encoding` say? The interpreter in the command prompt window says CP437. The IDLE Window says 'cp1252', and it handles the character fine. Given that Windows OS can handle the character, why is Python/Command Prompt limiting output? The windows command prompt expects cp437 because that's what old DOS programs print to it. Characters the IDLE window cannot display (like surrogate pairs) it displays as boxes. But if I cut '[][]' (4 chars) and paste into Firefox, I get 3 chars. '[]' where [] has some digits instead of being empty. It is really confusing when every window on 'unicode-based' Windows handles a different subset. That's because it is not 'unicode-based'. Communication between those programs has to be done with bytes, so the sender has to encode unicode characters in the encoding the receiver expects. Is this the fault of Windows or of Python and IDLE (those two being more limited that FireFox)? It's nobodies fault. That's simply how the encoding stuff works. To put it another way, how can one 'choose' utf-8 for display to screen? If the terminal expects cp437 then displaying utf-8 might give some problems. My screen displays whatever Windows tells the graphics card to tell the screen to display. But the terminal gets bytes and expects them to be cp437 encoded characters and not utf-8. So you can't send whatever unicode character you want, at least not without changing the encoding of the terminal. In OpenOffice, I can select a unicode font that displays at least everything in the BasicMultilingualPlane (BMP). But OOo works with unicode internally, so there's no communication with outside programs involved here. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list