SnakeCard on sourceforge
Dear all, The SnakeCard product line is now hosted on sourceforge.net: SCFB - http://sourceforge.net/projects/sctoolkits SC-ID - http://sourceforge.net/projects/sc-id I will keep posting the snapshots on www.snakecard.com as well as SCLOGON and SCWEB until they take shape ;-) Regards, Philippe -- * Philippe C. Martin SnakeCard, LLC www.snakecard.com * -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Help sponsor Pycon
PyCon is now looking for sponsors to help fund the conference; please see http://us.pycon.org/TX2006/HowToSponsor for more information. Sponsors help ensure that PyCon remains a low-cost conference. Several levels of sponsorship are available to match your company's budget. Sponsoring is also a good targeted way to reach a large set of Python users. If you want to advertise something -- a product, a book, a job opening -- to the PyCon community, it costs only $200 to include your marketing material in the tote bag given to all conference attendees. For more details, see http://us.pycon.org/TX2006/HowToSponsor. A.M. Kuchling Chair, PyCon 2006 [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Problem printing in Win98
Hi I'm trying to automatically send a postscript file to be printed to the default printer in a Win98 PC, by means of using the instrucction: win32api.ShellExecute (0, print, file.ps, None, ., 0) but it raises an exception with the message: error: (31, 'ShellExecute', 'A device attached to the system is not functioning.') Curiously, that instruction does works on Win2K/XP, but trying to use this shortcut for easy printing in Win98 provokes such error. I've tried in different machines (all of them running with Win98) and I obtain the same output. Does anybody knows what happens with Win98 printing automation? Any idea? Thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: Where can I find string.translate source?
[EMAIL PROTECTED] writes: Inside the file string.py I couldn't find the source code for translate. Where could it be? Object/stringmodule.c in the python source distribution. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Where can I find string.translate source?
[EMAIL PROTECTED] wrote: The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says A collection of string operations (most are no longer used). Warning: most of the code you see here isn't normally used nowadays. Beginning with Python 1.6, many of these functions are implemented as methods on the standard string object. They used to be implemented by a built-in module called strop, but strop is now obsolete itself. Inside the file string.py I couldn't find the source code for translate. Where could it be? in the string.py module, of course. if you read that comment again, you'll notice that it says many of these functions are implemented as methods on the standard string object and if you search for translate in string.py, you'll also find the source code for the translate function # Character translation through look-up table. def translate(s, table, deletions=): /... docstring snipped .../ if deletions: return s.translate(table, deletions) else: # Add s[:0] so that if s is Unicode and table is an 8-bit string, # table is converted to Unicode. This means that table *cannot* # be a dictionary -- for that feature, use u.translate() directly. return s.translate(table + s[:0]) which calls the translate method to do the work, just as the comment said. to find the method implementation, you have to look at the string object implementation. it's in the Objects directory in the source distribution. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: PATH environment variable
[EMAIL PROTECTED] wrote: Based on a search of other posts in this group, it appears as though os.environ['PATH'] is one way to obtain the PATH environment variable. My questions: 1) is it correct that os.environ['PATH'] contains the PATH environment variable? yes. 2) are there other ways to obtain the PATH environment variable? if so, is one way of obtaining the PATH environment variable preferable to another way? no. using the environ variable is the preferred way to read environment variables. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
Roy Smith wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: That's a tad unfair. Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people to parse long numeric strings. There are plenty of ways to make numeric literals easier to read without resorting to built-in language support. One way is: sixTrillion = 6 * 1000 * 1000 * 1000 * 1000 Or, a more general solution might be to write a little factory function which took a string, stripped out the underscores (or spaces, or commas, or whatever bit of punctuation turned you on), and then converted the remaining digit string to an integer. You could then write: creditCardNumber = myInt (1234 5678 9012 3456 789) Or alternatively, you could write: creditCardNumber = int('1234''5678''9012''3456''789') -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a function access its own name?
B Mahoney wrote: Decorate any function with @aboutme(), which will print the function name each time the function is called. All the 'hello' stuff is in the aboutme() decorator code. There is no code in the decorated functions themselves doing anything to telling us the function name. so you've moved a trivial print statement from the function itself into a decorator, so you can add an extra line before the function instead of inside it. wow. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a function access its own name?
[EMAIL PROTECTED] wrote: Look at the code below: # mystringfunctions.py def cap(s): print s print the name of this function is + ??? cap (hello) Running the code above gives the following output hello the name of this function is ??? I would like the output to be hello the name of this function is cap Is that possible ? def cap(s): print s print the name of this function is + cap yes, I'm serious. if your question had been can a function figure out the name of the function that called it, the answer would have been different. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Where can I find string.translate source?
Thanks Mike and Fredrik. In my Python installation there is no directory called Objects. I use Windows and I downloaded Python from http://www.python.org/download/ As I looked closer I saw that the link # Python 2.4.2 Windows installer (Windows binary -- does not include source) which clearly says that it doesn't include source. So in order to see the source I had to download # Python 2.4.2 source (for Unix or OS X compile) And in that download there is a directory called Objects and there is file called stringobjects.c where one can find the implementation of translate. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem printing in Win98
According to MSDN, err code 31 from ShellExecute is SE_ERR_NOASSOC, meaning there's not an application registered for printing that file type. Roger Maravilloso [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi I'm trying to automatically send a postscript file to be printed to the default printer in a Win98 PC, by means of using the instrucction: win32api.ShellExecute (0, print, file.ps, None, ., 0) but it raises an exception with the message: error: (31, 'ShellExecute', 'A device attached to the system is not functioning.') Curiously, that instruction does works on Win2K/XP, but trying to use this shortcut for easy printing in Win98 provokes such error. I've tried in different machines (all of them running with Win98) and I obtain the same output. Does anybody knows what happens with Win98 printing automation? Any idea? Thanks in advance == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list
enum 0.2: Enumerations in Python
Howdy all, I've uploaded enum 0.2 to the Cheeseshop. The main change is that enumeration values now export their enumtype, index, and key (the things that define each value) as attributes. Thanks to Bengt for making a convincing case in favour of this. So now it's easier to ask an enumeration value about itself: from enum import Enum Weekdays = Enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat') print [str(v) for v in Weekdays] ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'] today = Weekdays.tue print str(today) tue print repr(today) EnumValue(enum.Enum object at 0xb7d1ceec, 2, 'tue') print today.enumtype enum.Enum object at 0xb7d1ceec print today.index 2 print today.key tue -- \ I spilled spot remover on my dog. Now he's gone. -- Steven | `\Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
Steve Holden wrote: Xiao Jianfeng wrote: Steven D'Aprano wrote: On Sun, 20 Nov 2005 11:05:53 +0800, Xiao Jianfeng wrote: I have some other questions: when fh will be closed? When all references to the file are no longer in scope: def handle_file(name): fp = file(name, r) # reference to file now in scope do_stuff(fp) return fp f = handle_file(myfile.txt) # reference to file is now in scope f = None # reference to file is no longer in scope At this point, Python *may* close the file. CPython currently closes the file as soon as all references are out of scope. JPython does not -- it will close the file eventually, but you can't guarantee when. And what shoud I do if I want to explicitly close the file immediately after reading all data I want? That is the best practice. f.close() Let me introduce my problem I came across last night first. I need to read a file(which may be small or very big) and to check line by line to find a specific token, then the data on the next line will be what I want. If I use readlines(), it will be a problem when the file is too big. If I use for line in OPENED_FILE: to read one line each time, how can I get the next line when I find the specific token? And I think reading one line each time is less efficient, am I right? Not necessarily. Try this: f = file(filename.txt) for line in f: if token in line: # or whatever you need to identify it break else: sys.exit(File does not contain token) line = f.next() Then line will be the one you want. Since this will use code written in C to do the processing you will probably be pleasantly surprised by its speed. Only if this isn't fast enough should you consider anything more complicated. Premature optimizations can waste huge amounts of unnecessary programming time. Don't do it. First try measuring a solution that works! Oh yes, thanks. regards Steve First, I must say thanks to all of you. And I'm really sorry that I didn't describe my problem clearly. There are many tokens in the file, every time I find a token, I have to get the data on the next line and do some operation with it. It should be easy for me to find just one token using the above method, but there are more than one. My method was: f_in = open('input_file', 'r') data_all = f_in.readlines() f_in.close() for i in range(len(data_all)): line = data[i] if token in line: # do something with data[i + 1] Since my method needs to read all the file into memeory, I think it may be not efficient when processing very big file. I really appreciate all suggestions! Thanks again. Regrads, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
Xiao Jianfeng wrote: First, I must say thanks to all of you. And I'm really sorry that I didn't describe my problem clearly. There are many tokens in the file, every time I find a token, I have to get the data on the next line and do some operation with it. It should be easy for me to find just one token using the above method, but there are more than one. My method was: f_in = open('input_file', 'r') data_all = f_in.readlines() f_in.close() for i in range(len(data_all)): line = data[i] if token in line: # do something with data[i + 1] Since my method needs to read all the file into memeory, I think it may be not efficient when processing very big file. I really appreciate all suggestions! Thanks again. something like this : for x in fh: if not has_token(x): continue else: process(fh.next()) you can also create an iterator by iter(fh), but I don't think that is necessary using the side effect to your advantage. I was bite before for the iterator's side effect but for your particular apps, it becomes an advantage. -- http://mail.python.org/mailman/listinfo/python-list
wxListBox and others after upgrade to MacOS X 10.4
Hi I have strange problem... Background: I created some application using Linux which was intended to run on Mac OS X. There were few differences between Linux and Mac behavior of wxWidgets but finally after exchange of several screenshots i was able to finish it without even touching mac. BTW It was funny expirience. It was Mac OS 10.2 and everything was installed separetlly (wxPython, pyXML) Now they (my dear users) changed the OS to 10.4 where everything except pyXML is on place and it is working strange - means users can't use it. Problem: controls like buttons and lists are enabled but I can not click on them - it's not reacting. When some list focused on startup I can use it by keys (up and down arrows - to be clear) but mouse events are not handled at all. I spent some time on this problem and looks like I am in deadend. If anybody knows some directions where I can investigate ... would be great. regards -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert a long in a string to a long?
Thank you, for all the good answers. Somehow I overlooked the 'radix' option in the docs. S -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
[EMAIL PROTECTED] wrote: Xiao Jianfeng wrote: First, I must say thanks to all of you. And I'm really sorry that I didn't describe my problem clearly. There are many tokens in the file, every time I find a token, I have to get the data on the next line and do some operation with it. It should be easy for me to find just one token using the above method, but there are more than one. My method was: f_in = open('input_file', 'r') data_all = f_in.readlines() f_in.close() for i in range(len(data_all)): line = data[i] if token in line: # do something with data[i + 1] Since my method needs to read all the file into memeory, I think it may be not efficient when processing very big file. I really appreciate all suggestions! Thanks again. something like this : for x in fh: if not has_token(x): continue else: process(fh.next()) you can also create an iterator by iter(fh), but I don't think that is necessary using the side effect to your advantage. I was bite before for the iterator's side effect but for your particular apps, it becomes an advantage. Thanks all of you! I have compared the two methods, (1). for x in fh: (2). read all the file into memory firstly. I have tested the two methods on two files, one is 80M and the second one is 815M. The first method gained a speedup of about 40% for the first file, and a speedup of about 25% for the second file. Sorry for my bad English, and I hope I haven't made people confused. Regards, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
about dictionary
I have have the following code: a=[3,5,8,0] b={} How I can i assign each item in a as the key in the dictionary b simultaneously? that is, b={3:[],5:[],8:[],0:[]} Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
Xiao Jianfeng wrote: I have compared the two methods, (1). for x in fh: (2). read all the file into memory firstly. I have tested the two methods on two files, one is 80M and the second one is 815M. The first method gained a speedup of about 40% for the first file, and a speedup of about 25% for the second file. Sorry for my bad English, and I hope I haven't made people confused. So is the problem solved ? Putting buffering implementation aside, (1) is the way to go as it runs through content only once. -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
b = dict([(x,dict()) for x in a]) Shi Mu wrote: I have have the following code: a=[3,5,8,0] b={} How I can i assign each item in a as the key in the dictionary b simultaneously? that is, b={3:[],5:[],8:[],0:[]} Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines to be read with readlines()
[EMAIL PROTECTED] wrote: Xiao Jianfeng wrote: I have compared the two methods, (1). for x in fh: (2). read all the file into memory firstly. I have tested the two methods on two files, one is 80M and the second one is 815M. The first method gained a speedup of about 40% for the first file, and a speedup of about 25% for the second file. Sorry for my bad English, and I hope I haven't made people confused. So is the problem solved ? Yes, thank you. Putting buffering implementation aside, (1) is the way to go as it runs through content only once. I think so :-) Regards, xiaojf -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
On 20 Nov 2005 02:59:30 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: b = dict([(x,dict()) for x in a]) Shi Mu wrote: I have have the following code: a=[3,5,8,0] b={} How I can i assign each item in a as the key in the dictionary b simultaneously? that is, b={3:[],5:[],8:[],0:[]} Thanks! Thanks!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: combine doxygen and doc-strings?
Gabriel Zachmann wrote: Is there a way to combine doxygen comments, like this one ## Documentation for a function. # @var a - variable # More details. def func( a ): pass with the doc strings, like this one def func( a ): Documentation for a function. More details. pass ? Obviously, one would like to write the documentaion only once. Best regards, Gabriel. Gabriel, Although it is not documented yet, doxygen understands the following: def func( a ): ! @brief Documentation for a function. @var a This is a variable @return Nothing More details. I found this information in a mailing list (of which I don't know it's name anymore) Good luck, Henk -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
Shi Mu [EMAIL PROTECTED] wrote: I have have the following code: a=[3,5,8,0] b={} How I can i assign each item in a as the key in the dictionary b simultaneously? that is, b={3:[],5:[],8:[],0:[]} Explicit: a = [3, 5, 8, 0] b = {} for key in a: b[key] = [] Quicker: a = [3, 5, 8, 0] b = dict( [(k, []) for k in a] ) What behaviour do you expect when there are repeated values in the list 'a'? -- \ Faith may be defined briefly as an illogical belief in the | `\ occurrence of the improbable. -- Henry L. Mencken | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
Uzytkownik Shi Mu [EMAIL PROTECTED] napisal w wiadomosci news:[EMAIL PROTECTED] I have have the following code: a=[3,5,8,0] b={} How I can i assign each item in a as the key in the dictionary b simultaneously? that is, b={3:[],5:[],8:[],0:[]} Thanks! Other solution: b.fromkeys(a,[]) cheers, Przemek -- http://mail.python.org/mailman/listinfo/python-list
custom xml pretty print
Hi, I have Document. If I print it like this: print doc.toprettyxml( ) I will get this: a b c blablablabla /c /b /a What do I have to do if I want to print it like this: a b cblablablabla/c /b /a Thank you. -- http://mail.python.org/mailman/listinfo/python-list
about polygon
Why I got a black polygon in the following code? How can I make it no-color filled? Thanks! import Tkinter c = Tkinter.Canvas(width=220, height=220) c.pack() c.create_polygon(60,60,100,60,100,100,60,120) c.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: custom xml pretty print
akbar wrote: Hi, I have Document. If I print it like this: print doc.toprettyxml( ) I will get this: a b c blablablabla /c /b /a What do I have to do if I want to print it like this: a b cblablablabla/c /b /a Use a SAX-Handler, parse it yourself and pretty-print your own. You _could_ use DOM, but I don't think its needed here. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
przemek drochomirecki wrote: Uzytkownik Shi Mu [EMAIL PROTECTED] napisal w wiadomosci news:[EMAIL PROTECTED] I have have the following code: a=[3,5,8,0] b={} How I can i assign each item in a as the key in the dictionary b simultaneously? that is, b={3:[],5:[],8:[],0:[]} Thanks! Other solution: b.fromkeys(a,[]) Be warned that all keys share the same value. a = [3, 5, 8, 0] b = dict.fromkeys(a, []) b[3].append(42) b {8: [42], 0: [42], 3: [42], 5: [42]} Probably not what you want... Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
On 11/20/05, Peter Otten [EMAIL PROTECTED] wrote: przemek drochomirecki wrote: Uzytkownik Shi Mu [EMAIL PROTECTED] napisal w wiadomosci news:[EMAIL PROTECTED] I have have the following code: a=[3,5,8,0] b={} How I can i assign each item in a as the key in the dictionary b simultaneously? that is, b={3:[],5:[],8:[],0:[]} Thanks! Other solution: b.fromkeys(a,[]) Be warned that all keys share the same value. a = [3, 5, 8, 0] b = dict.fromkeys(a, []) b[3].append(42) b {8: [42], 0: [42], 3: [42], 5: [42]} Probably not what you want... Peter how to do with it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Web-based client code execution
Stephen Kellett wrote: In message [EMAIL PROTECTED], Steve [EMAIL PROTECTED] writes AJAX works because browsers can execute javascript. I don't know of a browser that can execute python. Basically your stuck with java or javascript because everything else really isn't cross platform. ActiveState do a version of Python that can run in a script tag like JavaScript and VBScript. This requires Windows Scripting Host. They also do a similar thing for Perl, not sure about TCL. See http://groups.google.com/group/comp.lang.python/msg/2d34acee66b40830 Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
Shi Mu wrote: how to do with it? Use Ben Finney's, not Przemek's approach if the values are mutables that you plan to modify. If that's what you are asking. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: about polygon
Hi! Am Sun, 20 Nov 2005 03:55:21 -0800 schrieb Shi Mu: Why I got a black polygon in the following code? How can I make it no-color filled? Use create_line instead: c.create_line(60,60,100,60,100,100,60,120,60,60) Jan -- http://mail.python.org/mailman/listinfo/python-list
Re: about polygon
Shi Mu wrote: Why I got a black polygon in the following code? How can I make it no-color filled? Thanks! import Tkinter c = Tkinter.Canvas(width=220, height=220) c.pack() c.create_polygon(60,60,100,60,100,100,60,120) c.mainloop() You can set the color explicitly (use to denote transparency): c.create_polygon(60,60,100,60,100,100,60,120, fill=, outline=black) I don't know why that isn't the default. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: about polygon
On 11/20/05, Jan Voges [EMAIL PROTECTED] wrote: Hi! Am Sun, 20 Nov 2005 03:55:21 -0800 schrieb Shi Mu: Why I got a black polygon in the following code? How can I make it no-color filled? Use create_line instead: c.create_line(60,60,100,60,100,100,60,120,60,60) Jan If so, what is the difference between create_line and create_polygon? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Why are there no ordered dictionaries?
This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an ordered dictionary class at least in the standard list? Time and again I am missing that feature. Maybe there is something wrong with my programming style, but I rather think it is generally useful. I fully agree with the following posting where somebody complains why so very basic and useful things are not part of the standard library: http://groups.google.com/group/comp.lang.python/msg/e652d2f771a49857 Are there plans to get it into the standard lib sometime? -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: about polygon
Shi Mu wrote: On 11/20/05, Jan Voges [EMAIL PROTECTED] wrote: Hi! Am Sun, 20 Nov 2005 03:55:21 -0800 schrieb Shi Mu: Why I got a black polygon in the following code? How can I make it no-color filled? Use create_line instead: c.create_line(60,60,100,60,100,100,60,120,60,60) Jan If so, what is the difference between create_line and create_polygon? Well, that one is filled and the other not? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to create a button in either pygame or livewires?
Nathan Pinno wrote: Hey all, Is there a way to create a button in either pygame or livewires, that is able to be clicked and when clicked sends a command to restart the program? Maybe something here: http://www.pygame.org/wiki/gui Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: about polygon
Hi Am Sun, 20 Nov 2005 04:45:52 -0800 schrieb Shi Mu: If so, what is the difference between create_line and create_polygon? create_polygon only creates closed polygons. Jan -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
Uzytkownik Peter Otten [EMAIL PROTECTED] napisal w wiadomosci news:[EMAIL PROTECTED] Shi Mu wrote: how to do with it? Use Ben Finney's, not Przemek's approach if the values are mutables that you plan to modify. If that's what you are asking. Peter Maybe he just want to use dictionary as a set. He can use SET container instead. Przemek -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines tobe?read with readlines()
Yes, I have read this part readlines( [sizehint]) Read until EOF using readline() and return a list containing the lines thus read. If the optional sizehint argument is present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (possibly after rounding up to an internal buffer size) are read. Objects implementing a file-like interface may choose to ignore sizehint if it cannot be implemented, or cannot be implemented efficiently. Maybe I'm missing the obvious, but it does not seem to say what happens when the input for readlines is too big. Or does it? How does one tell exactly what the limitation is to the size of the returned list of strings? - Original Message - From: Ben Finney [EMAIL PROTECTED] Newsgroups: comp.lang.python To: python-list@python.org Sent: Saturday, November 19, 2005 6:48 AM Subject: Re: what happens when the file begin read is too big for all lines tobe?read with readlines() Ross Reyes [EMAIL PROTECTED] wrote: Sorry for maybe a too simple a question but I googled and also checked my reference O'Reilly Learning Python book and I did not find a satisfactory answer. The Python documentation is online, and it's good to get familiar with it: URL:http://docs.python.org/ It's even possible to tell Google to search only that site with site:docs.python.org as a search term. When I use readlines, what happens if the number of lines is huge? I have a very big file (4GB) I want to read in, but I'm sure there must be some limitation to readlines and I'd like to know how it is handled by python. The documentation on methods of the 'file' type describes the 'readlines' method, and addresses this concern. URL:http://docs.python.org/lib/bltin-file-objects.html#l2h-244 -- \ If you're not part of the solution, you're part of the | `\ precipitate. -- Steven Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
On 11/20/05, przemek drochomirecki [EMAIL PROTECTED] wrote: Uzytkownik Peter Otten [EMAIL PROTECTED] napisal w wiadomosci news:[EMAIL PROTECTED] Shi Mu wrote: how to do with it? Use Ben Finney's, not Przemek's approach if the values are mutables that you plan to modify. If that's what you are asking. Peter Maybe he just want to use dictionary as a set. He can use SET container instead. Przemek How to use SET? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Christoph Zwerschke [EMAIL PROTECTED] wrote: This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an ordered dictionary class at least in the standard list? What answers have you received that have not been satisfactory? Some possible answers: The native dict is very fast, partly because the implementation doesn't need to ensure any particular ordering. Ordering the keys isn't the normal case, and can be done easily when needed. You asked why not rather than has anyone done this anyway; if you asked the latter of the Python Cookbook, you might find something like this: URL:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 A little old, and pre-dates subclassable native types, but quite serviceable. Time and again I am missing that feature. Maybe there is something wrong with my programming style, but I rather think it is generally useful. In what cases do you find yourself needing a dict that preserves its key order? Can you present a use case that would be improved by an ordered dict? I fully agree with the following posting where somebody complains why so very basic and useful things are not part of the standard library: For my part, I consider it a virtue of Python that the standard library doesn't change rapidly. It allows many competing implementations to be shaken out before everyone starts depending on any one of them. Are there plans to get it into the standard lib sometime? Where to find an answer: URL:http://www.python.org/peps/pep-.html Where to change that answer: URL:http://www.python.org/peps/pep-0001.html -- \ One of the most important things you learn from the internet | `\ is that there is no 'them' out there. It's just an awful lot of | _o__) 'us'. -- Douglas Adams | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Uzytkownik Christoph Zwerschke [EMAIL PROTECTED] napisal w wiadomosci news:[EMAIL PROTECTED] This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an ordered dictionary class at least in the standard list? Time and again I am missing that feature. Maybe there is something wrong with my programming style, but I rather think it is generally useful. I fully agree with the following posting where somebody complains why so very basic and useful things are not part of the standard library: http://groups.google.com/group/comp.lang.python/msg/e652d2f771a49857 Are there plans to get it into the standard lib sometime? -- Christoph i am not sure what is the purpose of having ordered dictionaries built in python, could u provide any examples? i use a contruction: for x in sorted(d.keys()) cheers, przemek -- http://mail.python.org/mailman/listinfo/python-list
Re: about dictionary
Uzytkownik Shi Mu [EMAIL PROTECTED] napisal w wiadomosci news:[EMAIL PROTECTED] On 11/20/05, przemek drochomirecki [EMAIL PROTECTED] wrote: Uzytkownik Peter Otten [EMAIL PROTECTED] napisal w wiadomosci news:[EMAIL PROTECTED] Shi Mu wrote: how to do with it? Use Ben Finney's, not Przemek's approach if the values are mutables that you plan to modify. If that's what you are asking. Peter Maybe he just want to use dictionary as a set. He can use SET container instead. Przemek How to use SET? http://docs.python.org/lib/types-set.html a [3, 5, 8, 8] b = set(a) b set([8, 3, 5]) cheers, przemek -- http://mail.python.org/mailman/listinfo/python-list
about sort and dictionary
Got confused by the following code: a [6, 3, 1] b [4, 3, 1] c {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} c[2].append(b.sort()) c {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} #why c can not append the sorted b?? b.sort() b [1, 3, 4] -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
przemek drochomirecki wrote: i am not sure what is the purpose of having ordered dictionaries built in python, could u provide any examples? i use a contruction: for x in sorted(d.keys()) By ordered dict, one usually wants order that is arbitary which cannot be derived from the content, say insertion order(most ordered dict I saw use this order). I am writing a web applications(simple forms) which has a number of fields. Each field naturally has a name and a number of attributes(formatting etc.), like this : d = {'a':{...}, 'b':{}} This dict would be passed to the Kid template system which would lay it out into a HTML form. For quick and dirty forms, I don't want to code each field individually in the HTML template but just from top to bottom(or left to right for a table) with a for loop. However, I still want to group certain fields together. This is my need of an ordered dict. Or course, I can pass a list along with the dict and loop over the list and retrieve value from the dict, but that would mean another things to pass along. And given the constraint of Kid where everything must be one-liner(expression, no block of code), it makes thing a bit harder. -- http://mail.python.org/mailman/listinfo/python-list
need help in how to make my script read arabic lang
hello , i want to know if yu please how can i use python code in tagging arabic text file my code is as follow : # -*- coding: cp1256 -*-import codecsfrom nltk.tagger import *from nltk.corpus import brownfrom nltk.tokenizer import WhitespaceTokenizerfrom nltk import *from nltk.tokenreader.tagged import TaggedTokenReader # Tokenize ten texts from the Brown Corpustrain_tokens = [] text_str = (open('fataha2.txt').read())#codecs.encode(text_str,'cp1256')reader = TaggedTokenReader(SUBTOKENS='WORDS')text_token = reader.read_token(text_str)print text_token['WORDS'] for l in text_token['WORDS']: train_tokens.append(l)#Initialise and train a unigram taggermytagger = UnigramTagger(SUBTOKENS='WORDS') for xx in train_tokens: cc = reader.read_token(xx['TEXT']) #! print cc.keys() cc['SUBTOKENS']= cc['WORDS'] mytagger.train(cc) #Once a UnigramTagger has been trained, the tag() method can be used to tag new text: text_token = Token(TEXT="ÇáÍãÏ ááå ÑÈ ÇáÚÇáãíä")WhitespaceTokenizer(SUBTOKENS='WORDS').tokenize(text_token)mytagger.tag(text_token)#print 'The first example : Using Unigram Tagger the reseults are : 'printprint text_tokenand i got the following error:Traceback (most recent call last): File "I:/examples/unigramgtag1update1.py", line 13, in ? codecs.encode(text_str,'cp1256') File "C:\Python24\lib\encodings\cp1256.py", line 18, in encode return codecs.charmap_encode(input,errors,encoding_map)UnicodeDecodeError: 'ascii' codec can't decode byte 0xc8 in position 0: ordinal not in range(128)please help Yahoo! FareChase - Search multiple travel sites in one click. -- http://mail.python.org/mailman/listinfo/python-list
about lambda
what does the following code mean? It is said to be used in the calculation of the overlaid area size between two polygons. map(lambda x:b.setdefault(x,[]),a) Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: about sort and dictionary
Shi Mu wrote: Got confused by the following code: a [6, 3, 1] b [4, 3, 1] c {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} c[2].append(b.sort()) c {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} #why c can not append the sorted b?? b.sort() b [1, 3, 4] most built-in function/method don't return the object but None. This I believe is the language creator's preference for everything being explicit. You better do it like this : b.sort() c[2].append(b) Of course, this make things like this not possible : obj.method_a().method_b().method_c() But the language(and the community) in general discourage you to write code like this ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: about sort and dictionary
Shi Mu [EMAIL PROTECTED] writes: #why c can not append the sorted b?? Because sort() doesn't return anything? According to the library reference: 7) The sort() and reverse() methods modify the list in place for economy of space when sorting or reversing a large list. To remind you that they operate by side effect, they don't return the sorted or reversed list. -- Eric Jacoboni, ne il y a 1435934131 secondes -- http://mail.python.org/mailman/listinfo/python-list
Re: about lambda
Shi Mu wrote: what does the following code mean? It is said to be used in the calculation of the overlaid area size between two polygons. map(lambda x:b.setdefault(x,[]),a) The equivalent of : def oh_my_yet_another_function_name_why_not_use_lambda(x): b.setdefault(x,[]) map(oh_my_yet_another_function_name_why_not_use_lambda, a) Or for x in a: b.setdefault(x,[]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
[EMAIL PROTECTED] wrote: I am writing a web applications(simple forms) which has a number of fields. Each field naturally has a name and a number of attributes(formatting etc.), like this : d = {'a':{...}, 'b':{}} This dict would be passed to the Kid template system which would lay it out into a HTML form. For quick and dirty forms, I don't want to code each field individually in the HTML template but just from top to bottom(or left to right for a table) with a for loop. However, I still want to group certain fields together. This is my need of an ordered dict. huh? if you want a list, use a list. d = [('a', {...}), ('b', {})] /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Type-checking unpickled objects
Gordon Airporte wrote: I have this class, and I've been pickling it's objects as a file format for my program, which works great. The problems are a.) how to handle things when the user tries to load a non-pickled file, and b.) when they load a pickled file of the wrong class. a. I can handle with a general exception I guess. I just tried to pickle.load() a .pyc and it failed with a 'KeyError' exception - however that works. It might do that every time, it might not. I hope you're aware of the fact that pickle is not suitable for applications where you cannot trust the source; see e.g. http://www.livejournal.com/users/jcalderone/15864.html (one of the comments show how to place restrictions on what can be loaded from a given pickle) Regarding b., if I type check I simply get the 'instance' type, which doesn't get me all of the way there because I might have an instance of the wrong class. I can't find any sort of __type__ attribute to set in the objects. Perhaps I should use __str__? how about a plain obj = cPickle.load(...) if not isinstance(obj, Class): print expected a Class instance /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: I am writing a web applications(simple forms) which has a number of fields. Each field naturally has a name and a number of attributes(formatting etc.), like this : d = {'a':{...}, 'b':{}} This dict would be passed to the Kid template system which would lay it out into a HTML form. For quick and dirty forms, I don't want to code each field individually in the HTML template but just from top to bottom(or left to right for a table) with a for loop. However, I still want to group certain fields together. This is my need of an ordered dict. huh? if you want a list, use a list. d = [('a', {...}), ('b', {})] Didn't I say that for quick and dirty form(usually first draft), I want a list ? But the same template, it would(may) be further enhanced by graphic designers in which case, I need direct access to the field names, thus the dict property. In this way, I don't have to change the python code just because I change the presentation in the template. -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
Dan Bishop wrote: Roy Smith wrote: creditCardNumber = myInt (1234 5678 9012 3456 789) Or alternatively, you could write: creditCardNumber = int('1234''5678''9012''3456''789') Or creditCardNumber = int(1234 5678 9012 3456 789.replace(' ','')) Or make a little function that does the same job and looks cleaner, if you need this more than once. But why would anyone want to create numeric literals for credit card numbers? -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: PATH environment variable
[EMAIL PROTECTED] wrote: O/S: Win2K Vsn of Python:2.4 Based on a search of other posts in this group, it appears as though os.environ['PATH'] is one way to obtain the PATH environment variable. My questions: 1) is it correct that os.environ['PATH'] contains the PATH environment variable? 2) are there other ways to obtain the PATH environment variable? if so, is one way of obtaining the PATH environment variable preferable to another way? That's the best way because it's portable. If you didn't have os.environ, you might be able to get PATH but reading the output of some subprocess, e.g: import commands path = commands.getoutput('echo $PATH') -- http://mail.python.org/mailman/listinfo/python-list
Re: line order
Ben Bush wrote: I run the following code and the red line and black line show at the same time. is there anyway to show the red line first, then the black line? for example, after I click the 'enter' key? from Tkinter import * tk = Tk() canvas = Canvas(tk, bg=white, bd=0, highlightthickness=0) canvas.pack(fill=BOTH, expand=YES) canvas.create_line(100, 200, 350, 200, arrow=LAST,fill='red') canvas.create_line (100, 0, 100, 200, arrow=FIRST) tk.mainloop() Tkinter uses background tasks to update the screen. Such tasks are called by Tkinter's event processning system, so nothing happens until you hand control over to Tkinter. You can use update or update_idle- tasks to explictly process all pending events/background tasks: canvas.create_line(100, 200, 350, 200, arrow=LAST,fill='red') canvas.update_idletasks() # run all pending background tasks wait_for_enter_key() # e.g. using raw_input() canvas.create_line (100, 0, 100, 200, arrow=FIRST) However, if you add this to a larger Tkinter program, you'll lock up the GUI when you're waiting for the enter key. A better approach is to hand control over to Tkinter, and ask it to draw another item whenever the user presses return: canvas = Canvas(tk, bg=white, bd=0, highlightthickness=0) canvas.pack(fill=BOTH, expand=YES) def draw(event): ... canvas.focus_set() # make sure we have focus canvas.bind(Return, draw) tk.mainloop() the binding means that whenever the user presses the Return key when the Canvas has focus, Tkinter will call the draw callback. you can use a simple counter to keep track of the items: count = 0 def draw(event): global count if count == 0: canvas.create_line(100, 200, 350, 200, arrow=LAST,fill='red') elif count == 1: canvas.create_line(100, 0, 100, 200, arrow=FIRST) count = count + 1 or you can add a simple wrapper def generator_callback(func): gen = func() def callback(event): try: gen.next() except StopIteration: pass return callback and use a generator function to implement the callback: def draw(): canvas.create_line(100, 200, 350, 200, arrow=LAST,fill='red') yield None canvas.create_line(100, 0, 100, 200, arrow=FIRST) # we're done canvas.bind(Return, generator_callback(draw)) hope this helps! /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
Peter Hansen wrote: But why would anyone want to create numeric literals for credit card numbers? May be for space saving ? But storage space being so cheap, this is not a very good reason, but still a reason. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python obfuscation
Alex Martelli wrote: Anton Vredegoor [EMAIL PROTECTED] wrote: ... Suppose I grant all your theories about optimal marketing strategies. I wish I hadn't done that :-) But seriously, I'm having trouble answering in detail all of your points (which doesn't mean I don't value them highly) because my online time is limited by the time period this library is open, and I also want to scavange as much offline reading material as possible while I'm connected. This still doesn't account for the way the market is behaving *now*. It isn't in any way logical or optimal. For example in Holland (where I live) complete governmental departments are dedicated to make life What makes you think that governmental departments are part of the *market*?! Government behavior is controlled by laws that are vastly different from those controlling market behavior; if you're interested, you could study the theory of public choice. I don't think so, so the question can't be answered. It's the same logic that enabled me to say payed webservices can only work well if when in context of replacing obfuscation techniques. From 1+1 == 3 I can derive anything. I know its lame, but my time limitation forces me to go back (or up) one level in order to refute you. snip You seem to tackle the problem of python obfuscation by first proving that it isn't feasible and then giving some kind of solution that will work and give the desired result: webservices. However when I look at That seems to me to be a practicable technical approach, yes. obfuscation techniques I see a desire to profit from giving some person the idea that he or she is superior to someone else because he has a better product. In order to avoid copying we now need obfuscation. The You're discussing the *motivation* for obfuscating, while what I was giving was a possible way of *implementing* similar effects. Yes, that's the point. If you can produce at zero cost then the whole economic theory falters. You enter another continuum where traditional economic values become meaningless. From obfuscation to webservices is a big step in that direction. snip Since redistribution of value, as long as a lot of value is created, can be dealt with by other means, maximizing the creation of value tends to be the goal I prefer -- a policy that quashes part or all of value creation based on redistributive precepts is, by this very fact, going to be something I look askance at (making the pie smaller to try to ensure that what little is left gets sliced according to your political preferences, rather than ensuring the pie is as big as possible as the first order of business, and dealing with the slicing issues as _secondary_ ones). I agree with your sentiment, but in order to maximize value creation we should leave material payments out of the equation when they only slow things down. From your writing I gather you already live in those quarters but you are still using materialistic concepts to describe the world. I don't blame you for it because I wouldn't know myself what would be applicable to a zero cost - maximal gain economy. Anton -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
Mike Meyer [EMAIL PROTECTED] writes: I've seen at least one language (forget which one) that allowed such separators, but only for groups of three. So 123_456 would be valid, but 9_1 would be a syntax error. Ada allows underscores in numeric literals since 1983, without enforcing any grouping. The Ruby language allows also this notation. You may write 1_000_001 or 1000_001 or 10_00_001, etc. (the same for real numbers...). When you have the habit to represent literals like that, all other big numeric literals or workarounds to create grouping seem cryptic. -- Eric Jacoboni, ne il y a 1435938104 secondes -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
You asked why not rather than has anyone done this anyway; if you asked the latter of the Python Cookbook, you might find something like this: URL:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 A little old, and pre-dates subclassable native types, but quite serviceable. Here's a more recent and tested one, by yours truly (and Michael Foord): An Ordered Dictionary http://www.voidspace.org.uk/python/odict.html -- Nicola Larosa - [EMAIL PROTECTED] How wonderful the world would be if his behaviour and attitude was the default among rich people - using his money with a vision to improve the world, instead of getting 8 sportcars and a larger penis. -- barkholt on Slashdot, October 2005, referring to Mark Shuttleworth -- http://mail.python.org/mailman/listinfo/python-list
Re: about lambda
Shi Mu wrote: what does the following code mean? It is said to be used in the calculation of the overlaid area size between two polygons. map(lambda x:b.setdefault(x,[]),a) Thanks! Assuming b is a dict, it is roughly equivalent to the following (except that the variables beginning with _ don't exist): _result = [] for _key in a: if _key not in b: b[_key] = [] _result.append(b[_key]) A more usual way to write this would be: result = [b.setdefault(key, []) for key in a] I added an assignment because I'm assuming that even though you didn't show it the original expression made some use of the resulting list, otherwise it is just wasting time and effort obfuscating something which could be more simply written as: for key in a: if key not in b: b[key] = [] -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
David M. Cooke wrote: Peter Hansen [EMAIL PROTECTED] writes: Steven D'Aprano wrote: Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people to parse long numeric strings. I'm totally unconvinced that this _is_ a real problem, if we define real as being even enough to jiggle my mouse, let alone shattering the planet. What examples does anyone have of where it is necessary to define a large number of large numeric literals? Isn't it the case that other than the odd constants in various programs, defining a large number of such values would be better done by creating a data file and parsing it? One example I can think of is a large number of float constants used for some math routine. In that case they usually be a full 16 or 17 digits. It'd be handy in that case to split into smaller groups to make it easier to match with tables where these constants may come from. Ex: def sinxx(x): computes sin x/x for 0 = x = pi/2 to 2e-9 a2 = -0.1 4 a4 = 0.00833 33315 a6 = -0.00019 84090 a8 = 0.0 27526 a10= -0.0 00239 x2 = x**2 return 1. + x2*(a2 + x2*(a4 + x2*(a6 + x2*(a8 + x2*a10 (or least that's what I like to write). Now, if I were going to higher precision, I'd have more digits of course. Right, this is clearly such a frequent use case it's worth changing the compiler for. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: about lambda
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Shi Mu wrote: what does the following code mean? It is said to be used in the calculation of the overlaid area size between two polygons. map(lambda x:b.setdefault(x,[]),a) The equivalent of : def oh_my_yet_another_function_name_why_not_use_lambda(x): b.setdefault(x,[]) map(oh_my_yet_another_function_name_why_not_use_lambda, a) Or for x in a: b.setdefault(x,[]) Or even: [b.setdefault(x,[]) for x in a] The effect of the code is this: if you have b, a dictionary of values, and a, a list or tuple of indexes to the dictionary, you can generate a list that will contain just the values associated with the indices in the list. If the index is not found in the dictionary, the default value will be used; in this case, that is an empty list. So, for example, if you have b = {'x':1,1:(1,2,3),'arthur':'A string',99:{'j':45,'k':111}} and a looks like this: you produce this: a = (0,1,'x') [[], (1, 2, 3), 1] a = (0,2,3,22) [[], [], [], []] a = ['x','arthur'] [1, 'A string'] ... and so on. -- rzed -- http://mail.python.org/mailman/listinfo/python-list
about dictionary
d is a dictionary. d {0: [[0, 1], [0, 2]], 1: [[0, 1], [1, 2], [1, 3]], 2: [[0, 2], [1, 2], [2, 3]], 3: [[1, 3], [2, 3]]} for the value under each key, if the possible connection is in the dictionary, for example, under key 0. 1 and 2 were found to have a pair in some other places so get [0,1,2] hence, how to design a dictionary, let dicTry= {0: [[0, 1,2], 2: [[0, 1, 2], [1, 2,3]], 2: [[0, 1,2], [1, 2,3], 3: [1,2,3]} Thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
Dan Bishop [EMAIL PROTECTED] wrote: creditCardNumber = int('1234''5678''9012''3456''789') Wow, I didn't know you could do that. That's better than my idea. -- http://mail.python.org/mailman/listinfo/python-list
email separation
HeyI have signed up to receive emails from the python forum and the amount of emails I receive on any day is fairly numerous...Does anyone know if I can somehow separate all mails coming from the python forum from all of my other mail, so I can open it from another folder or something like that under the same address...I have a yahoo account... Yahoo! FareChase - Search multiple travel sites in one click. -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
Steve Holden wrote: David M. Cooke wrote: One example I can think of is a large number of float constants used for some math routine. In that case they usually be a full 16 or 17 digits. It'd be handy in that case to split into smaller groups to make it easier to match with tables where these constants may come from. Ex: def sinxx(x): computes sin x/x for 0 = x = pi/2 to 2e-9 a2 = -0.1 4 a4 = 0.00833 33315 a6 = -0.00019 84090 a8 = 0.0 27526 a10= -0.0 00239 x2 = x**2 return 1. + x2*(a2 + x2*(a4 + x2*(a6 + x2*(a8 + x2*a10 (or least that's what I like to write). Now, if I were going to higher precision, I'd have more digits of course. Right, this is clearly such a frequent use case it's worth changing the compiler for. Yes it is. In that one example he used digit grouping 5 more times than I've used lambda in my life. Remember people use python as a data format as well (see for example JSON). It's a simple harmless change to the parser: ignore underscores or spaces in numeric literals. As others have mentioned, Ruby supports this already, as do Ada, Perl, ML variants, VHDL, boo, nemerle, and others. -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
D H wrote: Steve Holden wrote: David M. Cooke wrote: One example I can think of is a large number of float constants used for some math routine. In that case they usually be a full 16 or 17 digits. It'd be handy in that case to split into smaller groups to make it easier to match with tables where these constants may come from. Ex: def sinxx(x): computes sin x/x for 0 = x = pi/2 to 2e-9 a2 = -0.1 4 a4 = 0.00833 33315 a6 = -0.00019 84090 a8 = 0.0 27526 a10= -0.0 00239 x2 = x**2 return 1. + x2*(a2 + x2*(a4 + x2*(a6 + x2*(a8 + x2*a10 (or least that's what I like to write). Now, if I were going to higher precision, I'd have more digits of course. Right, this is clearly such a frequent use case it's worth changing the compiler for. Yes it is. In that one example he used digit grouping 5 more times than I've used lambda in my life. Remember people use python as a data format as well (see for example JSON). It's a simple harmless change to the parser: ignore underscores or spaces in numeric literals. As others have mentioned, Ruby supports this already, as do Ada, Perl, ML variants, VHDL, boo, nemerle, and others. But that requirement can be served easily with something like this : a2=my_decimal(-0.1 4) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to draw a dash line in the Tkinter?
Ben Bush wrote: How to draw a dash line in the Tkinter? use the dash option. e.g. canvas.create_line(xy, fill=red, dash=(2, 4)) canvas.create_line(xy, fill=red, dash=(6, 5, 2, 4)) (the tuple contains a number of line lengths; lengths at odd positions are drawn, lengths at even positions are gaps. note that not all com- binations are supported on all platforms; if Tkinter cannot find an exact match, it will pick a the closest possible). /F -- http://mail.python.org/mailman/listinfo/python-list
Re: email separation
john boy wrote: Does anyone know if I can somehow separate all mails coming from the python forum from all of my other mail, so I can open it from another folder or something like that under the same address...I have a yahoo account... look under filters on this page: http://help.yahoo.com/help/us/mail/manage/index.html /F -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all linestobe?read with readlines()
Ross Reyes wrote: Maybe I'm missing the obvious, but it does not seem to say what happens when the input for readlines is too big. Or does it? readlines handles memory overflow in exactly the same way as any other operation: by raising a MemoryError exception: http://www.python.org/doc/current/lib/module-exceptions.html#l2h-296 How does one tell exactly what the limitation is to the size of the returned list of strings? you can't. it depends on how much memory you have, what your files look like (shorter lines means more string objects means more overhead), and how your operating system handles large processes. as soon as the operating system says that it cannot allocate more memory to the Python process, Python will abort the operation and raise an exception. if the operating system doesn't complain, neither will Python. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: PATH environment variable
I observed something tangential to this topic, and that is the reason for this reply. I don't understand when os.environ gets updated. The '...captured the first time the os mdule is imported...' verbiage from the following link: http://www.python.org/dev/doc/newstyle/lib/os-procinfo.html provides some information, but it's not clear how to make that fit with the following observations: Sequence of steps...observation 1: 1) open Pythonwin interactive window 2) import os 3) os.environ['PATH'] - this presents the contents of the PATH variable 4) using Windows system properties/environment variables, change contents of PATH variable; apply the changes (after closing, I got back in to verify that the PATH variable was, in fact, changed) 5) in interactive window, reload(os) 6) os.environ['PATH'] - presents same value is in #3 Sequence of steps...observation 2: 1) open Pythonwin interactive window 2) import os 3) os.environ['PATH'] - this presents the contents of the PATH variable 4) using Windows system properties/environment variables, change contents of PATH variable; apply the changes (after closing, I got back in to verify that the PATH variable was, in fact, changed) 5) in interactive window, del os 6) in interactive window, import os 7) os.environ['PATH'] - presents the same value as in #3 I also observed that if I exit the interactive window, and then go back into the interactive window, the os.environ['PATH'] reflects changes to the PATH environment variable that happened while in the interactive window the first time. Do these observations fit with what is stated in section 6.1.1 of the Python Library Reference? -- http://mail.python.org/mailman/listinfo/python-list
Re: PATH environment variable
[EMAIL PROTECTED] wrote: Do these observations fit with what is stated in section 6.1.1 of the Python Library Reference? yes. what part of your observations makes you think that the environment isn't captured (i.e. copied from the process environ- ment) when the os module is imported ? (hint: when you start a new process, it gets a *copy* of the current environment. changes to the original won't affect this copy. all modern operating systems work the same way). /F -- http://mail.python.org/mailman/listinfo/python-list
Re: PATH environment variable
Fredrik Lundh wrote: what part of your observations makes you think that the environment isn't captured (i.e. copied from the process environment) when the os module is imported ? Answer: the part that was informed by a fundamental misunderstanding on my part of how the os module obtains information. Based on Mr. Lundh's 'copied from the process environment' remark and his hint, I would infer the following: 1) In the observations I detailed, the 'process' is the pythonwin application 2) When the pythonwin application is invoked, it obtains a copy of the current environment 3) the import os statement obtains information from the copy of the current environment that was obtained when the pythonwin process began 4) a reload(os) or a combination of del os followed by import os also get information from the copy of the current environment that was obtained when the pythonwin process began My questions: a) are the above inferences (albeit oversimplified) correct? b) when the hint refers to a new process, does the term 'process' refer to the same concept that is described in secion 6.1.5 of the Python Library Reference? -- http://mail.python.org/mailman/listinfo/python-list
Re: query domain registry from python?
On 19 Nov 2005 19:40:58 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:hi, does anyone know of a library that can query domain registry or any site that provide information to such an activity? as i want to build asimple domain name searching program for my own benefit.. thanks alot :D [TW] Try http://www.faqts.com/knowledge_base/view.phtml/aid/4568 -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
[EMAIL PROTECTED] wrote: Peter Hansen wrote: But why would anyone want to create numeric literals for credit card numbers? May be for space saving ? But storage space being so cheap, this is not a very good reason, but still a reason. Space saving where? Why would you have any credit card numbers stored in any application? Even a credit card company isn't going to write code that has the numbers stored as *literals*! There's only one place I can think of right now where you might want that: in automated tests for code that processes credit card numbers. And you definitely do not need to save space in that situation... -Peter -- http://mail.python.org/mailman/listinfo/python-list
Command line
Hoe would I call something on the command line from python, e.g. ls -la? -- http://mail.python.org/mailman/listinfo/python-list
Command line
Hoe would I call something on the command line from python, e.g. ls -la? -- http://mail.python.org/mailman/listinfo/python-list
Re: Command line
What OS are you using. I'm not sure about anything else but on a mac it's: import os os.system(ls -la) -- http://mail.python.org/mailman/listinfo/python-list
need a tutorial in tokens ,different types
hello all could any one suggest me tutorials in different tokenizations and clear describtion of how can i use token type and assign diff attributes to tokens ,also good tutorials in diff data types in python thanks every body enas Yahoo! FareChase - Search multiple travel sites in one click. -- http://mail.python.org/mailman/listinfo/python-list
Re: Command line
amfr wrote: Hoe would I call something on the command line from python, e.g. ls -la? Use the module subprocess - otherwise maybe popen2 or os. Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Underscores in Python numbers
[EMAIL PROTECTED] (David M. Cooke) wrote: One example I can think of is a large number of float constants used for some math routine. In that case they usually be a full 16 or 17 digits. It'd be handy in that case to split into smaller groups to make it easier to match with tables where these constants may come from. Ex: def sinxx(x): computes sin x/x for 0 = x = pi/2 to 2e-9 a2 = -0.1 4 a4 = 0.00833 33315 a6 = -0.00019 84090 a8 = 0.0 27526 a10= -0.0 00239 x2 = x**2 return 1. + x2*(a2 + x2*(a4 + x2*(a6 + x2*(a8 + x2*a10 (or least that's what I like to write). Now, if I were going to higher precision, I'd have more digits of course. You have described, if memory serves, a Taylor series, and those coefficients are 1/3!, 1/5!, 1/7!, etc. What I would do, rather than embedding the numeric constants in the code, is embed the formula and have the machine compute the actual values at import time. At the very least, have them machine generated and saved. You certainly don't want to be typing in long strings of digits like that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Speeding up multiple regex matches
Talin wrote: I've run in to this problem a couple of times. Say I have a piece of text that I want to test against a large number of regular expressions, where a different action is taken based on which regex successfully matched. The naive approach is to loop through each regex, and stop when one succeeds. However, I am finding this to be too slow for my application -- currently 30% of the run time is being taken up in the regex matching. I thought of a couple of approaches, but I am not sure how to make them work: 1) Combine all of the regular expressions into one massive regex, and let the regex state machine do all the discriminating. The problem with this is that it gives you no way to determine which regex was the matching one. use a capturing group for each alternative, and use lastindex to quickly find the match: http://docs.python.org/lib/match-objects.html lastindex The integer index of the last matched capturing group, or None if no group was matched at all. also see: http://effbot.org/zone/xml-scanner.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Delays getting data on sys.stdin.readline() ?
On 11/19/05, Mike Meyer [EMAIL PROTECTED] wrote: Christian Convey [EMAIL PROTECTED] writes: I've got a program that (ideally) perpetually monitors sys.stdin for lines of text. As soon as a line comes in, my program takes some action. The problem is, it seems like a very large amount of data must accumulate on sys.stdin before even my first invocation of readline() returns. This delay prevents my program from being responsive in the way it must be. readline normally returns as soon as it sees a newline. External conditions may cause this to change, or make it impossible. Without knowing those external conditions, the best we can do is guess as to what might be the problem. Has anyone else seen this effect? If so, is there a reasonable workaround? Yes, and maybe. Depends on what's causing the problem. Tell us more about the program, and what sys.stdin is connected to, and the platform you're running on, and someone should be able to provide explicit information. OK, I've fixed it, but I don't understand why the fix works. Let's say I've got two Python programs, I'll call producer and consumer. producer runs for a long time and occasionally while running sends lines of text to stdout. consumer is typically blocked in a call to sys.stdin.readline(). When I run producer on its own, I see its output appear on the console pretty much immediately after calling the print command. But when I pipe producers output to consumers stdin on the Linux command line, consumer stays blocked on its first call to sys.stdin.readline() until the producer program terminates. At that point, consumer seems to immediately get access to all of the stdout produced by producer. I've found I can fix this problem by modifying producer so that immediately after each print command, I call sys.stdout.flush(). When I make this modification, I find that consumer has access to the output of producer immediately after producer issues a print statement. So here's what I don't get: If producer was retaining its output for a while for the sake of efficiency, I would expect to see that effect when I just run producer on the command line. That is, I would expect the console to not show any output from producer until producer terminates. But instead, I see the output immediately. So why, when I pipe the output to consumer, doesn't consumer get access to that data as its produced unless consumer is explicitely calling sys.stdout.flush(). Any thoughts? Thanks, Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
What answers have you received that have not been satisfactory? I googled a little bit and haven't found many answers at all. Some were in the posting I mentioned: Stuff should go into the standard lib only when it is mature and right enough. However, we are already at Python 2.4 and there is still no ordered dictionary, though there is a lot of other specialized stuff. Some possible answers: The native dict is very fast, partly because the implementation doesn't need to ensure any particular ordering. Ok, but that's not an argument against providing ordered dictionaries as well. Ordering the keys isn't the normal case, and can be done easily when needed. That depends. Maybe I do not want the keys to be sorted alphabetically, but according to some criteria which cannot be derived from the keys themselves. You asked why not rather than has anyone done this anyway; if you asked the latter of the Python Cookbook, you might find something like this. Yes, I also found that others have done it more than once, and I know that it's not so difficult to do. There are at least two recipes in the mentioned cookbook and there is odict in pythonutils. The question was why is it not available in the *standard* lib. In what cases do you find yourself needing a dict that preserves its key order? Can you present a use case that would be improved by an ordered dict? There are too many different situations and it would be too much to explain them here, usually in the case mentioned above where the keys are not sorted alphabetically. I often solve them by using two data structures, a list or tuple, plus a dictionary. For instance, the list could contain the names of database fields which shall be output in a certain order, and the dictionary values could contain human readable description of the database fields for headers or something. Instead of maintaining both data structures I feel it would be more natural to use only one ordered dictionary. For my part, I consider it a virtue of Python that the standard library doesn't change rapidly. It allows many competing implementations to be shaken out before everyone starts depending on any one of them. Ok, but this can be used as an argument to not add anything to the standard lib any more. There are already enough competing implementations. Also, the implementation details are not so important, there must be only agreement on the interface and behavior which should not be so difficult in this case. I simply wanted to ask why it is not available in the standard lib, since I simply don't know - has it not been demanded loud enough? - is it really not needed (if you need it it shows you are doing something wrong)? - because nobody presented a satisfying implementation yet? - are there hidden difficulties or controversial issues? -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Web-based client code execution
Paul Watson wrote: I have read some about AJAX. Is there an APAX coming for Python? Not until browsers have embedded Python interpreters. There's been talk about doing this in Mozilla, but I don't think the talk has turned into usable code, yet. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
BaseHTTPServer module
From the BaseHTTPServer module, how do i gget the POST or GET data sent by the client? Is it stired the the file they requested? e.g. objectname.path -- http://mail.python.org/mailman/listinfo/python-list
BaseHTTPServer module
From the BaseHTTPServer module, how do i gget the POST or GET data sent by the client? Is it stired the the file they requested? e.g. objectname.path -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
[EMAIL PROTECTED] schrieb: By ordered dict, one usually wants order that is arbitary which cannot be derived from the content, say insertion order(most ordered dict I saw use this order). I am writing a web applications(simple forms) which has a number of fields. Each field naturally has a name and a number of attributes(formatting etc.), like this : d = {'a':{...}, 'b':{}} Things like that are also my typical use case. The keys usually contain things like database fields or html form fields, the values contain the corresponding description, formatting, data type or data itself etc. The example above is a bit misleading, because using 'a', 'b' as keys can give the impression that you just have to sort() the keys to have what you want. So let's make it more realistic: d = { 'pid': ('Employee ID', 'int'), 'name': ('Employee name', 'varchar'), 'sal': ('Salary', 'float') } Now if I want these things to be presented in this order, I need to run through a separate list ('pid', 'name', 'sal') that holds the order. Ok, you could simply use a list instead of a dictionary: d = ( ('pid', 'Employee ID', 'int'), ('name', 'Employee name', 'varchar'), ('sal', 'Salary', 'float') ) This works as long as you *only* have to go through the list sequentially. But maybe you want to print the name with its description at some other place as well. Now how do you access its description 'Employee name' so easily? -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Command line
amfr wrote: Hoe would I call something on the command line from python, e.g. ls -la? os.system(cmd), or some relative: http://docs.python.org/lib/os-process.html http://docs.python.org/lib/os-newstreams.html#os-newstreams or http://docs.python.org/lib/module-subprocess.html ::: also note that you shouldn't use external commands for trivial things like getting a list of files or getting the size of a file; you can get a list of all files in a directory with files = os.listdir(directory) for file in files: file = os.path.join(directory, file) # full path ... or files = glob.glob(pattern) for file in files: ... and you can get information about a given file with st = os.stat(file) size = st.st_size mtime = st.st_mtime (etc) or size = os.path.getsize(file) mtime = os.path.getmtime(file) (etc) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: func(*params)
David Duerrenmatt wrote: For some reasons, I've to use Python 1.5.2 and am looking for a workaround: In newer Python versions, I can call a function this way: func = some_function func(*params) Then, the list/tuple named params will automatically be expanded and n=len(params) arguments will be submitted. Python 1.5.2 doesn't support this kind of function call. use apply(func, params) or result = apply(func, params) more info: help(apply) Help on built-in function apply in module __builtin__: apply(...) apply(object[, args[, kwargs]]) - value Call a callable object with positional arguments taken from the tuple args, and keyword arguments taken from the optional dictionary kwargs. Note that classes are callable, as are instances with a __call__() method. Deprecated since release 2.3. Instead, use the extended call syntax: function(*args, **keywords). /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
[restored my attribution line so we know who said what] Christoph Zwerschke [EMAIL PROTECTED] wrote: Ben Finney wrote: In what cases do you find yourself needing a dict that preserves its key order? Can you present a use case that would be improved by an ordered dict? There are too many different situations and it would be too much to explain them here, usually in the case mentioned above where the keys are not sorted alphabetically. Without an example, it's hard to know what you want to do and whether an ordered dictionary is the best way to do it. For my part, I consider it a virtue of Python that the standard library doesn't change rapidly. It allows many competing implementations to be shaken out before everyone starts depending on any one of them. Ok, but this can be used as an argument to not add anything to the standard lib any more. I hope not. Rather, it's an argument not to add something to the standard library until it's proven (to the BDFL's criteria) that it's better in than out. There are already enough competing implementations. Have they been sufficiently shaken out to show a clearly superior version? Is any version sufficiently beneficial to write a PEP for its inclusion in the standard library? I simply wanted to ask why it is not available in the standard lib, since I simply don't know - has it not been demanded loud enough? Loud demands don't count for much. PEPs with popular working implementations do. - is it really not needed (if you need it it shows you are doing something wrong)? You dismissed a request for your use cases with handwaving. How can we know? - because nobody presented a satisfying implementation yet? I'm not sure what you mean by satisfying. - are there hidden difficulties or controversial issues? Another possibility: ordered dictionaries are not needed when Python 2.4 has the 'sorted' builtin. -- \ Those who will not reason, are bigots, those who cannot, are | `\ fools, and those who dare not, are slaves. -- Lord George | _o__)Gordon Noel Byron | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Web-based client code execution
David Wahler wrote: Steve wrote: AJAX works because browsers can execute javascript. I don't know of a browser that can execute python. Basically your stuck with java or javascript because everything else really isn't cross platform Don't jump to conclusions... http://dwahler.ky/python/ If you really, really want Python in a browser, it's certainly possible. :) -- David well in firefox 1.07 I seem to be getting Error: unmarshal is not defined Source File: http://dwahler.ky/python/ Line: 133 -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
ownership problem?
Is it correct to say that the typical ownership problem, which frequently arises in C++, does not occur normally in Python? Best regards, Gabriel. -- /---\ | Any intelligent fool can make things bigger, more complex,| | or more violent. It takes a touch of genius - and a lot of courage - | | to move in the opposite direction. (Einstein) | \---/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python weak on the web side?
Tony a écrit : If I'd like to learn Python for web-development, what are the options available? There are too many *good* options for web developpement in Python. Thanks. tony -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python weak on the web side?
On 19/11/05, Michael Goettsche [EMAIL PROTECTED] wrote: On Sunday 20 November 2005 00:24, Tony wrote: If I'd like to learn Python for web-development, what are the options available? A nice framework is CherryPy: http://www.cherrypy.org or Turbogears, which is based on CherryPy: http://www.turbogears.org/ See also Django for CMS type sites. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Christoph Zwerschke wrote: The example above is a bit misleading, because using 'a', 'b' as keys can give the impression that you just have to sort() the keys to have what you want. So let's make it more realistic: d = { 'pid': ('Employee ID', 'int'), 'name': ('Employee name', 'varchar'), 'sal': ('Salary', 'float') } Now if I want these things to be presented in this order, I need to run through a separate list ('pid', 'name', 'sal') that holds the order. Ok, you could simply use a list instead of a dictionary: d = ( ('pid', 'Employee ID', 'int'), ('name', 'Employee name', 'varchar'), ('sal', 'Salary', 'float') ) if you restructure the list somewhat d = ( ('pid', ('Employee ID', 'int')), ('name', ('Employee name', 'varchar')), ('sal', ('Salary', 'float')) ) you can still loop over the list for key, (name, type) in d: print key, name, type # e.g. generate form entry This works as long as you *only* have to go through the list sequentially. But maybe you want to print the name with its description at some other place as well. Now how do you access its description 'Employee name' so easily? but you can easily generate an index when you need it: index = dict(d) name, type = index[pid] print name the index should take less than a microsecond to create, and since it points to the members of the original dict, it doesn't use much memory either... /F -- http://mail.python.org/mailman/listinfo/python-list
Re: ownership problem?
Gabriel Zachmann a écrit : Is it correct to say that the typical ownership problem, which frequently arises in C++, does not occur normally in Python? What is this typical ownership problem ? -- http://mail.python.org/mailman/listinfo/python-list