Announce: omniORB 4.1.0 and omniORBpy 3.0
I am pleased to announce that omniORB 4.1.0 and omniORBpy 3.0 are now available. omniORB is a robust, high performance CORBA implementation for C++; omniORBpy is a version for Python. You can download them in source and Windows binary forms from SourceForge here: http://sourceforge.net/project/showfiles.php?group_id=51138package_id=44914release_id=467312 http://sourceforge.net/project/showfiles.php?group_id=51138package_id=48639release_id=467315 These are major new stable releases. The following is a summary of the main new features: - Objects by value support. - Abstract interfaces support. - New simpler and more efficient Any implementation. - IPv6 support. - Flexible endpoint publishing. - New tracing options and more comprehensive logging. - C++ mapping updated to version 1.1. - New-style Python classes can now be used for servants and exception (required for Python 2.5). - Support for local interfaces (partial in Python) - New more scalable socket collection implementation. Many thanks to the people who have contributed to these releases by testing the betas and release candidates, and by contributing features and fixes. Enjoy! Duncan. -- -- Duncan Grisby -- -- [EMAIL PROTECTED] -- -- http://www.grisby.org -- -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: About the 79 character line recommendation
Olivier Langlois a écrit : Hi, There was a coding standard where I worked and the intention behind this requirement was to make the code printer friendly. Printing code source with lines longer than 80 chars greatly hinder readability on paper. Try using size 10 font in place of size 12 when printing. Still readable, print correctly longer lines. [ :-) but I try to keep lines under the 80 columns too :-) ] Greetings, Olivier Langlois http://www.olivierlanglois.net I also think that limiting code to 80 columns often hinders readability. I personally try to limit my code to 100 columns. The end result is pretty nice. However, I'm all for the flat is better than nested philosophy, even when nested is under 100 columns. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Plugin for Web Browser
des exemples de plugins pour IE oui mais qui ne sont pas embarqué dans une page Web je souhaiterai créer qqchose qui ressemble vraiment à Java VM ou Flash J'ai trouvé un début de réponse pour Firefox en télécharger le GeckoSDK mais je n'arrive pas à compiler les exemples pour le moment... merci MC a écrit : Bonjour ! Pour IE, il y a des exemples de plugins, fournis avec PyWin32. Pour FF (comme pour Opera), je ne sais pas. -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Plugin for Web Browser
Hi I was looking for something similar in the past and could not find it. It would be very useful to have Python applets in web pages. What would you use them for? kind regards André On 5 Dec 2006 23:59:29 -0800, Sébastien Ramage [EMAIL PROTECTED] wrote: des exemples de plugins pour IE oui mais qui ne sont pas embarqué dans une page Web je souhaiterai créer qqchose qui ressemble vraiment à Java VM ou Flash J'ai trouvé un début de réponse pour Firefox en télécharger le GeckoSDK mais je n'arrive pas à compiler les exemples pour le moment... merci MC a écrit : Bonjour ! Pour IE, il y a des exemples de plugins, fournis avec PyWin32. Pour FF (comme pour Opera), je ne sais pas. -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list -- Dr. Andre P. Meyerhttp://python.openspace.nl/meyer TNO Defence, Security and Safety http://www.tno.nl/ Delft Cooperation on Intelligent Systems http://www.decis.nl/ Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams -- http://mail.python.org/mailman/listinfo/python-list
How to use MySQL without MySQLdb module
Hi all. I am using a hosting space with python cgi. But this host haven't got MySQLdb installed. Is there any methods to connect to Mysql without MySQLdb. Or any other DB methods with original python release? Thanx -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Plugin for Web Browser
Hi Sebastien Yes, I am a developer, but not C/C++. I have done Java (and many other languages) in the past, but use Python nowadays. So, I am no help for developing the plugin, sorry. I would want to use it though for developing richer Web sites in Python, rather than in JavaScript/Ajax. Having said that: maybe you are also interested in pyjamas (http://pyjamas.pyworks.org/). kind regards André On 12/6/06, Sebastien Ramage [EMAIL PROTECTED] wrote: Hi Thank you for your reply. Yes ! It would be very useful and easy to develop (the applet not the plugin) ! I don't have real project at this time but, I like Python and use it every day. Many time I want to make an applet for game, or webcam remote control but I don't understand and I don't want to learn Java when I know the powerful python. Are you a developper? C++ ? Seb 2006/12/6, Andre Meyer [EMAIL PROTECTED]: Hi I was looking for something similar in the past and could not find it. It would be very useful to have Python applets in web pages. What would you use them for? kind regards André On 5 Dec 2006 23:59:29 -0800, Sébastien Ramage [EMAIL PROTECTED] wrote: des exemples de plugins pour IE oui mais qui ne sont pas embarqué dans une page Web je souhaiterai créer qqchose qui ressemble vraiment à Java VM ou Flash J'ai trouvé un début de réponse pour Firefox en télécharger le GeckoSDK mais je n'arrive pas à compiler les exemples pour le moment... merci MC a écrit : Bonjour ! Pour IE, il y a des exemples de plugins, fournis avec PyWin32. Pour FF (comme pour Opera), je ne sais pas. -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list -- Dr. Andre P. Meyerhttp://python.openspace.nl/meyer TNO Defence, Security and Safety http://www.tno.nl/ Delft Cooperation on Intelligent Systems http://www.decis.nl/ Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams -- Dr. Andre P. Meyerhttp://python.openspace.nl/meyer TNO Defence, Security and Safety http://www.tno.nl/ Delft Cooperation on Intelligent Systems http://www.decis.nl/ Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-platform issue with wxRadioBox
[EMAIL PROTECTED] wrote: I have updated my script to use wx.RadioButton instead, which works perfectly on my mac again, but now the submit button doesn't show up on the pc and I can't click in the netid field on the pc either. any ideas? I modified the __init__() method of class regFrame from your original posting to create a wx.Panel as a child of self and then made all the controls be children of this panel. Your app then seemed to work OK on Windows XP. Using a wx.Panel to hold the content of a frame is a standard wxPython idiom. I find reading the wxPython demo source is a very useful way to learn this sort of thing. HTH, -- CMcP -- http://mail.python.org/mailman/listinfo/python-list
Novice: replacing strings with unicode variables in a list
Hi, Im totally new to Python so please bare with me. Data is entered into my program using the folling code - str = raw_input(command) words = str.split() for word in words: word = unicode(word,'latin-1') word.encode('utf8') This gives an error: File C:\Python25\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x94' in position 0 : character maps to undefined but the following works. str = raw_input(command) words = str.split() for word in words: uni = u uni = unicode(word,'latin-1') uni.encode('utf8') so the problem is that I want replace my list with unicode variables. Or maybe I should create a new list. I also tried this: for word in words[:]: word = u word = unicode(word,'latin-1') word.encode('utf8') print word but got TypeError: decoding Unicode is not supported. What should I be doing? Thanks for your help, Aine. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use MySQL without MySQLdb module
Jia Lu si è divertito a scrivere: Hi all. I am using a hosting space with python cgi. But this host haven't got MySQLdb installed. Are you sure there's no other mysql db interface installed? If the DB is on the very same server, it should be. If it isn't, and you'd like to access an external firewall, you should check whether the firewall of your host really allows outbound connections. If it does, you should look for (or write by yourself) a pure-python db-api implementation of mysqldb. Otherwise, you could connect directly to the port of your mysql database and just write raw sql and pull raw data from it, but this will prevent you from the chance of using more enhanced db tools like sqlalchemy, and it's highly discouraged as well as it's really prone to errors. -- Alan Franzoni [EMAIL PROTECTED] - Togli .xyz dalla mia email per contattarmi. Remove .xyz from my address in order to contact me. - GPG Key Fingerprint (Key ID = FE068F3E): 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E -- http://mail.python.org/mailman/listinfo/python-list
Re: Novice: replacing strings with unicode variables in a list
[EMAIL PROTECTED] wrote: Hi, Im totally new to Python so please bare with me. Data is entered into my program using the folling code - str = raw_input(command) words = str.split() for word in words: word = unicode(word,'latin-1') word.encode('utf8') This gives an error: File C:\Python25\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x94' in position 0 : character maps to undefined but the following works. str = raw_input(command) words = str.split() for word in words: uni = u uni = unicode(word,'latin-1') uni.encode('utf8') This is the exact same code as the one above - there is no type declaration in python, so your uni = u'' statement is bollocks. And I seriously doubt, that the above code and the above error message are related - as you can see, the error is from cp850, a windows codepage. But that isn't in the code above - so there must be something else happening. Please provide the full script, and the desired input - then we might be able to help you. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Does this always go right
Hello Gabriel, For your simple test dictionary, copy and deepcopy behaves identically. If you wish, you should test using values that are containers themselves. thanks, your answer clarifies a lot. Gtx carl -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy vs Deepcopy in multithreaded contexts
Hello, this issue is solved, no help needed. Gtx Carl. - Forwarded by Carl Wolff/IT/NL/Imtech on 06-12-2006 10:51 - Carl Wolff/IT/NL/Imtech wrote on 05-12-2006 22:55:20: Hello question about copy vs deepcopy used in multithreaded context: suppose the following program below: the original dictionary is modified after the thread is started, the thread works on a copied and deepcopied version of the original dictionary. Is the dictionary named originalcopy isolated from changes in original in multithreaded context? The program reports no errors but I want to be really sure about this Thanks Carl. snip original = {} originalcopy = {} originaldeepcopy = {} class checker(threading.Thread): def __init__(self): threading.Thread.__init__(self) pass def run(self): while True: for i in originaldeepcopy: if originalcopy[i] == originaldeepcopy[i]: pass else: print error, originalcopy[i], Not equal to, originaldeepcopy[i] i = 0 while i1000: original[i] = i i = i + 1 originalcopy = copy.copy(original) originaldeepcopy = copy.deepcopy(original) test = checker() test.start() time.sleep(0.5) while True: i = 0 while i1000: original[i] = i*2 i = i + 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Novice: replacing strings with unicode variables in a list
Diez B. Roggisch wrote: Please provide the full script, and the desired input - then we might be able to help you. the full *traceback* would pretty useful, too: http://effbot.org/pyfaq/tutor-i-need-help-im-getting-an-error-in-my-program-what-should-i-do.htm my guess is that the OP left out the print statement that causing the error, and the traceback lines that pointed to that print statement: more test.py uni = up\x95l print uni python test.py Traceback (most recent call last): File test.py, line 2, in module print uni File C:\python25\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x95' in position 1 : character maps to undefined /F -- http://mail.python.org/mailman/listinfo/python-list
Re: What are python closures realy like?
Paddy wrote: I played around a bit. The following is a 'borg' version in that there is only one counter shared between all calls of the outer function: def fun_borg_var(initial_val=0): ...def borg_var_inc(x=1): ...fun_borg_var._n += x a drawback with the function attribute approach compared to a real closure is that the function is no longer a self-contained callable: def fun_borg_var(initial_val=0): def borg_var_inc(x=1): fun_borg_var._n += x return fun_borg_var._n def borg_var_dec(x=1): fun_borg_var._n -= x return fun_borg_var._n try: fun_borg_var._n = fun_borg_var._n except: fun_borg_var._n = initial_val return (borg_var_inc, borg_var_dec) up1, dn1 = fun_borg_var() del fun_borg_var # won't need this any more print up1() # oops! so you might as well use a good old global variable, and initialize it as usual. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Novice: replacing strings with unicode variables in a list
[EMAIL PROTECTED] wrote: Im totally new to Python so please bare with me. That's no problem, really. I don't use a spellchecker, either, and it wouldn't have protected you from that particular typo... Data is entered into my program using the folling code - str = raw_input(command) words = str.split() for word in words: word = unicode(word,'latin-1') word.encode('utf8') This gives an error: File C:\Python25\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x94' in position 0 : character maps to undefined but the following works. str = raw_input(command) words = str.split() for word in words: uni = u uni = unicode(word,'latin-1') uni.encode('utf8') Here you show us the same code twice, as the uni = u assignment has no effect, and a traceback that is probably generated when you try to print uni Here's my guess: The encoding you actually need is cp850, the same that your Python interpreter is trying to use, but in which unichr(0x94) is undefined. In general, you are not free to use a random encoding; rather, you have to use what your console expects. import sys s = raw_input(command) s = unicode(s, sys.stdin.encoding) # trust python to find out the proper # encoding. If that fails use a constant, # probably cp850 words = s.split(): for word in words: print word # trust python, but if it doesn't work out: # word = word.encode(cp850) # print word By the way, strings are immutable (cannot be altered once created), so the following word.encode('utf8') print word is actually spelt word = word.encode(utf8) print word If your data is not read from the console and it contains characters that cannot be printed, unicode.encode() accepts a second parameter to deal with it, see help(u.encode) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Novice: replacing strings with unicode variables in a list
Peter Otten wrote: words = s.split(): Oops, remove bogus colon here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Novice: replacing strings with unicode variables in a list
[EMAIL PROTECTED] wrote: Hi, Im totally new to Python so please bare with me. Data is entered into my program using the folling code - str = raw_input(command) words = str.split() for word in words: word = unicode(word,'latin-1') word.encode('utf8') The above statement produces a string in utf8 and then throws it away. It does not update word. To retain the utf8 string, you would have to do word = word.encode('utf8') and in any case that won't update the original list. *** missing source code line(s) here *** This gives an error: *** missing traceback lines here *** File C:\Python25\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x94' in position 0 : character maps to undefined No, it doesn't. You must have put print word to get the error that you did. *Please* when you are asking a question, copy/paste (1) the exact source code that you ran (2) the exact traceback that you got. but the following works. What do you mean by works? It may not have triggered an error, but on the other hand it doesn't do anything useful. str = raw_input(command) words = str.split() for word in words: uni = u Above line is pointless. Removing it will have no effect uni = unicode(word,'latin-1') uni.encode('utf8') Same problem as above -- utf8 string is produced and then thrown away. so the problem is that I want replace my list with unicode variables. Or maybe I should create a new list. I also tried this: for word in words[:]: word = u word = unicode(word,'latin-1') You got the error on the above statement because you are trying (pointlessly) to decode the value u. Decoding means to convert from some encoding to unicode. word.encode('utf8') Again, utf8 straight down the gurgler. print word This (if executed) will try to print the UNICODE version, and die [as in the 1st example] encoding the unicode in cp950, which is the encoding for your Windows command console. but got TypeError: decoding Unicode is not supported. What should I be doing? (1) Reading the Unicode howto: http://www.amk.ca/python/howto/ (2) Writing some code like this: | strg = \x94 foo bar zot | words = strg.split() | words | ['\x94', 'foo', 'bar', 'zot'] | utf8words = [unicode(word, 'latin1').encode('utf8') for word in words] | utf8words | ['\xc2\x94', 'foo', 'bar', 'zot'] | HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Novice: replacing strings with unicode variables in a list
Fredrik Lundh skrev: Diez B. Roggisch wrote: Please provide the full script, and the desired input - then we might be able to help you. the full *traceback* would pretty useful, too: http://effbot.org/pyfaq/tutor-i-need-help-im-getting-an-error-in-my-program-what-should-i-do.htm my guess is that the OP left out the print statement that causing the error, and the traceback lines that pointed to that print statement: more test.py uni = up\x95l print uni python test.py Traceback (most recent call last): File test.py, line 2, in module print uni File C:\python25\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x95' in position 1 : character maps to undefined /F Thanks for the replies. OK heres the full code I'm using now - compare = uÄis print compare str = raw_input(Enter music:) words = str.split() uniList=[] for word in words: uni=unicode(word,'latin-1') uniList.append(uni) print uniList[0] if(compare!=uniList[0]): print Not the same: + compare + + uniList[0] This gives the following error - Traceback (most recent call last): File stdin, line 1, in module File test.py, line 14, in module print uniList[0] File C:\Python25\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x8e' in position 0 : character maps to undefined How come I can print compare but not uniList[0]? What encoding is being used to store compare? How can I print out the raw bytes stored in compare and uniList[0]? Thanks again for your help, Aine. -- http://mail.python.org/mailman/listinfo/python-list
Re: Novice: replacing strings with unicode variables in a list
[EMAIL PROTECTED] skrev: Fredrik Lundh skrev: Diez B. Roggisch wrote: Please provide the full script, and the desired input - then we might be able to help you. the full *traceback* would pretty useful, too: http://effbot.org/pyfaq/tutor-i-need-help-im-getting-an-error-in-my-program-what-should-i-do.htm my guess is that the OP left out the print statement that causing the error, and the traceback lines that pointed to that print statement: more test.py uni = up\x95l print uni python test.py Traceback (most recent call last): File test.py, line 2, in module print uni File C:\python25\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x95' in position 1 : character maps to undefined /F Thanks for the replies. OK heres the full code I'm using now - compare = uÄis print compare str = raw_input(Enter music:) words = str.split() uniList=[] for word in words: uni=unicode(word,'latin-1') uniList.append(uni) print uniList[0] if(compare!=uniList[0]): print Not the same: + compare + + uniList[0] This gives the following error - Traceback (most recent call last): File stdin, line 1, in module File test.py, line 14, in module print uniList[0] File C:\Python25\lib\encodings\cp850.py, line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x8e' in position 0 : character maps to undefined How come I can print compare but not uniList[0]? What encoding is being used to store compare? How can I print out the raw bytes stored in compare and uniList[0]? Thanks again for your help, Aine. Cool. It works for me now. import sys compare = uÄis print compare str = raw_input(Enter music:) words = str.split() uniList=[] for word in words: uni=unicode(word,sys.stdin.encoding) uniList.append(uni) print uniList[0] if(compare!=uniList[0]): print Not the same: + compare + + uniList[0] -- http://mail.python.org/mailman/listinfo/python-list
Re: how to invoke the shell command and then get the result in python
Fredrik Lundh [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Assuming the script isn't setuid, this would do no more damage than the user could do directly on the command line. except that when the user is typing things into the command line, he *knows* that he's typing things into the command line. Aye! Who is to say that this script won't get re-used innocently in a web application? And in this particular example we were talking about typing regular expressions into the shell, which have many of the same metacharacters as the shell. So even an innocent use of the above can cause problems. Just say no to passing user input (from anywhere at all) via the shell! That (along with SQL injection attacks which are very similar in concept) is one of the most common security attacks for scripting languages like Python when used in a web environment. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
PyMedia - some questions
Hi, Can anyone answer the following questions? Question 1. Can pyMedia create/convert FLV format? I explain in details. As I would like to publish videos for viewing in a browser , I need a good video format. I learned that FLV (Flash(tm) Video) format could be a good choice. Or does anybody suggest a better format??? Question 2 . So, I need to convert a file captured from a video camera into that FLV (Flash(tm) Video) format . Can pyMedia do that or must I use ffmpeg directly like this( to convert from avi to FLV ) ffmpeg -i [sourcefile.avi] -acodec mp3 -ar 22050 -ab 32 -f flv -s 320×240 [destfile.flv] Question 3, This command creates a simple FLV format file, containing the video and audio streams. In addition, FLV files need meta-information such as duration, frames, etc. FLV movie players use this information to calculate progress bar sliders and allow the user to fast-forward or reverse through the video. Can PyMedia add such meta- information? Thank you for help Lad. -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe / Tkinter problem
[EMAIL PROTECTED] wrote: I've got a python GUI working with Tkinter, and I need to package it as an executable file, preferably a single file. Why not use an installer to bundle the python interpreter (with TKinter) and your code in a single executable file? If you don't want to distribute source code then .pyc or .pyo files can be used? An example of (freeware) installer software: http://www.jrsoftware.org/isinfo.php -- http://mail.python.org/mailman/listinfo/python-list
No latin9 in Python?
I noticed that Python does not understand the codec alias names latin7 = iso8859-13, latin9 = iso8859-15 (see http://docs.python.org/lib/standard-encodings.html). Particularly latin9 is pretty popular here in Western Europe since it contains the Euro symbol (contrary to latin1). According to the Wikipedia (http://en.wikipedia.org/wiki/ISO-8859), the latin7 and latin9 aliases seem to be official, at least they are widely used an accepted. In PostgreSQL, LATIN9 is even the name of the charset, and iso8859-15 is the alias name: http://www.postgresql.org/docs/8.2/static/multibyte.html#CHARSET-TABLE Is there anything speaking against adding these as aliases? If no, I would submit a patch. (Also, Python does not support the latin10=iso8859-16 charset. I could try to add that as well.) -- Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: About alternatives to Matlab
On Dec 5, 2006, at 16:35, Mark Morss wrote: very well-written) _Practical OCaml_. However, I also understand that OCaml supports only double-precision implementation of real numbers; that its implementation of arrays is a little clunky compared to Fortran 95 or Numpy (and I suspect not as fast as Fortran's); and that the available libraries, while powerful, are by no means as comprehensive as those available for Python. For example, I am unaware of the existance of an HDF5 interface for OCaml. OCaml is a popular language with computer scientists in France (not surprisingly, given its origins), and I have regular contacts with the computer science research community, so I have been exposed quite a bit to OCaml, to the point of once considering it for numerical work. Not as a replacement for Python, but as a replacement for C or Fortran, i.e. for the heavy-duty parts of my work. What made me abandon this idea are mainly two points: 1) the lack of polymorphism 2) the difficulty of interfacing to C and Fortran code 3) the limited processor support of the native code compiler The lack of polymorphism, particularly in operators, makes OCaml code a pain to write and read in my opinion. Float arithmetic is already bad enough, with +. etc. everywhere. If I add complex and vector types (which could easily be defined in OCaml), I'd have to come up with two more sets of arithmetic operators that make my code less readable. In addition, I'd either have to keep multiple implementations for many algorithms, or pass in all operators and mathematical functions as arguments. Neither solution is acceptable for me. Interfacing to C and Fortran code is important because that's what most libraries are written in. While it is possible in principle with OCaml, it is (or at least was at the time I looked) a pain to interface typical array-handling code, for lack of a compatible data structure on the OCaml side. Native code compilation is obviously important for speed. While many popular processors are supported by ocamlopt, scientific users are notorious for grabbing whatever fast hardware they can lay their hands on. It seems safe to count on the GNU suite being ported rapidly to any new platform. I don't have as much faith in the OCaml developers, though perhaps just out of ignorance. Konrad. -- http://mail.python.org/mailman/listinfo/python-list
Re: What are python closures realy like?
Karl Kofnarson wrote: I wanted to have a function which would, depending on some argument, return other functions all having access to the same variable. An OO approach would do but why not try out closures... I know that everyone will say that Python is a multi-paradigm language and that one should feel free to use whatever technique seems appropriate to solve the problem at hand, but it seems to me that there's been an explosion in nested function usage recently, with lots of code snippets showing them off either in the context of a debugging exercise or as a proposed solution to a problem, and yet in many cases their usage seems frivolous in comparison to plain old object-oriented techniques. I'm not pointing the finger at you here, Karl, since you seem to be experimenting with closures, but why are they suddenly so fashionable? Haven't the features supporting them existed in Python for a few versions now? Don't people want to write classes any more? Intrigued, Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: What are python closures realy like?
Paul Boddie wrote: I know that everyone will say that Python is a multi-paradigm language and that one should feel free to use whatever technique seems appropriate to solve the problem at hand, but it seems to me that there's been an explosion in nested function usage recently, with lots of code snippets showing them off either in the context of a debugging exercise or as a proposed solution to a problem, and yet in many cases their usage seems frivolous in comparison to plain old object-oriented techniques. when doing some heavy optimization, I recently found myself writing: def foobar(arg1, arg2, arg3): def helper(arg): do something with arg1 and argument def foo(): do something with arg1 and arg3 and call helper def bar(): do something with arg1 and arg2 def zoo(): do something with arg2 and arg3 and call helper # oops; how do I return all these? class bag(object): pass bag = bag() bag.foo = foo bag.bar = bar bag.zoo = zoo return bag which, I think, deserves no further comment... /F -- http://mail.python.org/mailman/listinfo/python-list
Re: What are python closures realy like?
def foobar(arg1, arg2, arg3): def helper(arg): do something with arg1 and argument def foo(): do something with arg1 and arg3 and call helper def bar(): do something with arg1 and arg2 def zoo(): do something with arg2 and arg3 and call helper # oops; how do I return all these? class bag(object): pass bag = bag() bag.foo = foo bag.bar = bar bag.zoo = zoo return bag which, I think, deserves no further comment... Could you please explain your reasoning behind why you opted to create the bag, fill it, and then return it? Usually I see something like return foo,bar,zoo and it would be helpful to understand the reasoning behind why one would choose one over the other. Some of the off-the-cuff thoughts in my trying to understand it: -defining a bag, instantiating a bag and filling it takes a few extra cycles for each call of foobar() so the returned tuple should be a hair faster (though perhaps defining a bag class outside the foobar() function might trim some of this?) -returning a tuple requires that any additional methods you might opt to add/return in the future involve adjusting all your code, whereas the bag method allows you to toss extra methods in the bag without adjusting every statement that calls foobar() Are either of these correct? Are there additional reasons I'm missing? Thanks, -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: No latin9 in Python?
Christoph Zwerschke wrote: I noticed that Python does not understand the codec alias names latin7 = iso8859-13, latin9 = iso8859-15 (see http://docs.python.org/lib/standard-encodings.html). Particularly latin9 is pretty popular here in Western Europe since it contains the Euro symbol (contrary to latin1). One learns new things every day, I suppose: I've always referred to it as ISO-8859-15, using whatever combination or absence of _ or - symbols that is deemed appropriate. According to the Wikipedia (http://en.wikipedia.org/wiki/ISO-8859), the latin7 and latin9 aliases seem to be official, at least they are widely used an accepted. In PostgreSQL, LATIN9 is even the name of the charset, and iso8859-15 is the alias name: http://www.postgresql.org/docs/8.2/static/multibyte.html#CHARSET-TABLE My impression of relational databases is that they often have lots of legacy names for things like character encodings. A different perspective may be had by looking at the XML standards where encodings and their naming have received a great deal of attention: http://www.w3.org/TR/REC-xml/#NT-EncodingDecl It may be acceptable even in XML to use latin9 as an encoding name, but since the XML specifications appear to recommend the ISO names, and since XML has quite possibly raised awareness and usage of encoding declarations to previously unknown levels, there may be some benefit in conservatively shadowing XML and the expectations of its users (and of the wider Web page authoring community, amongst others). One would have to look into the rationale of the standards makers to understand why they've made those particular recommendations, however. Is there anything speaking against adding these as aliases? If no, I would submit a patch. (Also, Python does not support the latin10=iso8859-16 charset. I could try to add that as well.) I don't see any disadvantages in having aliases, provided that they're unambiguous, but then I'm far from being any person who is going to be making that particular call. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: What are python closures realy like?
Fredrik Lundh wrote: when doing some heavy optimization, I recently found myself writing: def foobar(arg1, arg2, arg3): def helper(arg): do something with arg1 and argument def foo(): do something with arg1 and arg3 and call helper def bar(): do something with arg1 and arg2 def zoo(): do something with arg2 and arg3 and call helper # oops; how do I return all these? class bag(object): pass bag = bag() bag.foo = foo bag.bar = bar bag.zoo = zoo return bag which, I think, deserves no further comment... Have I missed something deep here, or could you not have written the above as follows...? class foobar(object): def __init__(self, arg1, arg2, arg3): self.arg1, self.arg2, self.arg3 = arg1, arg2, arg3 def helper(self, arg): do something with arg1 and argument def foo(self): do something with arg1 and arg3 and call helper def bar(self): do something with arg1 and arg2 def zoo(self): do something with arg2 and arg3 and call helper There's certainly some boilerplate required (in both forms, though) and you'd have to use self in various places, but the above looks less contorted to me. I'd like to hear your further comment, however, since the principal inconvenience of making a class seems to be in the verbose initialisation and explicit self, the latter of which obviously being a feature that you won't find me complaining about, though. ;-) Paul -- http://mail.python.org/mailman/listinfo/python-list
reloading modules
I'm using python.exe to execute my modules. I have a music.py module which contains my classes and a main.py module which uses these classes. In python.exe, I call import main to execute my program. The problem is that I have to close python and reopen it everytime i change music.py or main.py. What should I be doing. Thanks, Aine. -- http://mail.python.org/mailman/listinfo/python-list
Book recommendations
Can someone recommend a Python book for a newbie and perhaps you have a used one for sale? Thank you. Cordially, west -- http://mail.python.org/mailman/listinfo/python-list
Re: About the 79 character line recommendation
Hello, for me the 80 (or 79) char border when writing code is a fundamental rule. Being at University and having to document each project on paper, it is a must do. i.e. I get code from fellow scolars, that have 160 chars per line, and to get that on paper is disgusting, especially in C/C++. So please, stay true to that. And don't forget those, who actually view source code in a terminal. :-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
len() and PEP 3000
Hi, The function len() is not mentioned in the Python 3000 PEPs. I suggest that at least lists, tupples, sets, dictionaries and strings get a len() method. I think the len function can stay, removing it would break to much code. But adding the method, would bu usefull. Yes, I know, that I can call .__len__() but that is ugly. I have read the FAQ to the len function: http://www.python.org/doc/faq/general/#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list -- Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/ E-Mail: guettli (*) thomas-guettler + de Spam Catcher: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
dict.has_key(x) versus 'x in dict'
Hello, I've always been using the has_key() method to test if a dictionary contains a certain key. Recently I tried the same using 'in', e.g. d = { ... } if k in d: ... and found that it seems to perform a lot better when lots of key-tests are to be performed. I also noticed that has_key() is scheduled to be removed from future (C)Python versions. Does the 'in' way of testing have an optimized implementation compared to has_key()? Is that the reason has_key() is being phased out? Thanks, Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Paul Melis wrote: I've always been using the has_key() method to test if a dictionary contains a certain key. Recently I tried the same using 'in', e.g. d = { ... } if k in d: ... and found that it seems to perform a lot better when lots of key-tests are to be performed. I also noticed that has_key() is scheduled to be removed from future (C)Python versions. Does the 'in' way of testing have an optimized implementation compared to has_key()? no, but full method calls are a lot slower than the under-the-hood C-level call used by the in operator. this is why e.g. string[:len(prefix)] == prefix is often a lot faster than string.startswith(prefix) and why if character in string: string = string.replace(character, replacement) is faster than string = string.replace(character, replacement) if the character isn't there most of the time, despite the fact that the replace method doesn't actually do something if the character isn't found. /F -- http://mail.python.org/mailman/listinfo/python-list
Windows: get owner and group of a file
Hello, with ls -l on windows I get -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile How can I get on windows with a standard python 2.2 (without windows extensions) the information 500 and everyone (owner and group)? Also I cannot use popen('ls -l'). With import stat stat_info = os.lstat(myfile) owner = %-8s % stat_info.st_uid group = %-8s % stat_info.st_gid I get 0 for owner and group. Thanks for your hints, Kai -- http://mail.python.org/mailman/listinfo/python-list
Re: reloading modules
[EMAIL PROTECTED] wrote: I'm using python.exe to execute my modules. I have a music.py module which contains my classes and a main.py module which uses these classes. In python.exe, I call import main to execute my program. The problem is that I have to close python and reopen it everytime i change music.py or main.py. What should I be doing. Thanks, Aine. import main ### Execution Occurs ### # You go off to edit your module reload(main) ### Execution Occurs ### -- http://mail.python.org/mailman/listinfo/python-list
Re: reloading modules
Dustan wrote: [EMAIL PROTECTED] wrote: I'm using python.exe to execute my modules. I have a music.py module which contains my classes and a main.py module which uses these classes. In python.exe, I call import main to execute my program. The problem is that I have to close python and reopen it everytime i change music.py or main.py. What should I be doing. Thanks, Aine. import main ### Execution Occurs ### # You go off to edit your module reload(main) ### Execution Occurs ### I was obviously assuming that your module does something just by importing, which may or may not be the case. Either way, whenever a module may have been edited during a program's lifetime, it can be reloaded using the reload function. -- http://mail.python.org/mailman/listinfo/python-list
RE: Windows: get owner and group of a file
[kai rosenthal] | with ls -l on windows I get | -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile | | How can I get on windows with a standard python 2.2 (without windows | extensions) the information 500 and everyone (owner and group)? | Also I cannot use popen('ls -l'). Wow. Python 2.2. No extensions. Not even popen (). You don't want much, do you? I *think* the answer is that you can't. If you were to loosen up any of your restrictions, you might have a fighting chance of using (in no particular order): 1) popen (ls -l) as you suggest. I assume that the restriction on popen (ls) extends to popen (anything else). 2) win32security from the pywin32 extensions 3) ctypes (builtin from Python 2.5; also available as an extension) TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows: get owner and group of a file
Tim Golden wrote: Wow. Python 2.2. No extensions. Not even popen (). You don't want much, do you? I *think* the answer is that you can't. does the group concept even exist on Windows ? cannot recall I've ever seen ls -l print anything but everyone... /F -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Paul Melis wrote: I've always been using the has_key() method to test if a dictionary contains a certain key. Recently I tried the same using 'in', e.g. d = { ... } if k in d: ... Wouldn't be if k in d.keys() be the exact replacement? Regards, Björn -- BOFH excuse #17: fat electrons in the lines -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows: get owner and group of a file
kai rosenthal wrote: Hello, with ls -l on windows I get -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile How can I get on windows with a standard python 2.2 (without windows extensions) the information 500 and everyone (owner and group)? Also I cannot use popen('ls -l'). Are you by any chance running cygwin? That comes with ls, but windows doesn't. So you need to add the appropriate cygwin binary dirs to you path. But you probably won't want that anyway, as thus your code would only run on a machine with cygwin installed. With import stat stat_info = os.lstat(myfile) owner = %-8s % stat_info.st_uid group = %-8s % stat_info.st_gid I get 0 for owner and group. I'm not sure if stat-calls are fully supported on windows - the windows rights management is considerably different from unixish ones. From the docs: For backward compatibility, the return value of stat() is also accessible as a tuple of at least 10 integers giving the most important (and portable) members of the stat structure, in the order st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime. More items may be added at the end by some implementations. The standard module stat defines functions and constants that are useful for extracting information from a stat structure. (On Windows, some items are filled with dummy values.) Note the last sentence. You should try and look what win32 has to offer. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: len() and PEP 3000
Thomas Guettler wrote: I suggest that at least lists, tupples, sets, dictionaries and strings get a len() method. Why? I think the len function can stay, removing it would break to much code. But adding the method, would bu usefull. Yes, I know, that I can call .__len__() but that is ugly. That's what len() is for. Regards, Björn -- BOFH excuse #281: The co-locator cannot verify the frame-relay gateway to the ISDN server. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyMedia - some questions
I'm not familiar with PyMedia, but this blog entry should be of interest: [Video Blogging using Django and Flash(tm) Video (FLV)] http://blog.go4teams.com/?p=56 It describes a toolchain for publishing AVI files as FLV on the web. ffmpeg is used together with a few other tools, but Python is used to glue it all togheter. - Kjell Magne Fauske Lad wrote: Hi, Can anyone answer the following questions? Question 1. Can pyMedia create/convert FLV format? I explain in details. As I would like to publish videos for viewing in a browser , I need a good video format. I learned that FLV (Flash(tm) Video) format could be a good choice. Or does anybody suggest a better format??? Question 2 . So, I need to convert a file captured from a video camera into that FLV (Flash(tm) Video) format . Can pyMedia do that or must I use ffmpeg directly like this( to convert from avi to FLV ) ffmpeg -i [sourcefile.avi] -acodec mp3 -ar 22050 -ab 32 -f flv -s 320×240 [destfile.flv] Question 3, This command creates a simple FLV format file, containing the video and audio streams. In addition, FLV files need meta-information such as duration, frames, etc. FLV movie players use this information to calculate progress bar sliders and allow the user to fast-forward or reverse through the video. Can PyMedia add such meta- information? Thank you for help Lad. -- http://mail.python.org/mailman/listinfo/python-list
Re: reloading modules
[EMAIL PROTECTED] wrote: I'm using python.exe to execute my modules. I have a music.py module which contains my classes and a main.py module which uses these classes. In python.exe, I call import main to execute my program. The problem is that I have to close python and reopen it everytime i change music.py or main.py. What should I be doing. Thanks, Aine. Instead of calling 'import', use the 'imp' module and call 'find_module' followed by 'load_module'. As the docs explain, one of the differences between this and 'import' is that it loads the module every time, even if it is already imported. HTH Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
Re: SPE (Stani's Python Editor) web site?
Bernard schreef: yes sir should I send them to you? You would do me and other gurus a great favour if you put it on a server somewhere. F John DeRosa a écrit : On 28 Nov 2006 13:16:41 -0800, Bernard [EMAIL PROTECTED] wrote: I can send you the latest tar.gz ( SPE-0.8.3.c-wx2.6.1.0.tar ) file if you want it :) I'm looking for SPE for Python 2.5 and wxPython 2.7.2.0, on Windows. Do you have that? -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Bjoern Schliessmann wrote: Wouldn't be if k in d.keys() be the exact replacement? no. that would convert an O(1) operation to an O(n) operation, which would be rather silly. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Book recommendations
On Dec 6, 7:09 am, west [EMAIL PROTECTED] wrote: Can someone recommend a Python book for a newbie and perhaps you have a used one for sale? Thank you. Beginning Python: From Novice to Professional by Magnus Lie Hetland Core Python Programming (2nd Edition) by Wesley Chun There are plenty of Free online ones as well. HTH Robert -- http://mail.python.org/mailman/listinfo/python-list
RE: Windows: get owner and group of a file
[Fredrik Lundh] | Tim Golden wrote: | | Wow. Python 2.2. No extensions. Not even popen (). You don't | want much, do you? I *think* the answer is that you can't. | | does the group concept even exist on Windows ? cannot recall I've | ever seen ls -l print anything but everyone... | | /F Must admit that I was toying with an excursion into the possible conceptual mappings between the Posix owner/group concept and the Windows security model, but decided that I wasn't too sure at what level the OP was. (And I'm not exactly on firm ground myself). The ls.exe from UnxUtils which I use doesn't even try: it just gives user and group for everything. I've just checked their source and that's exactly what it does. So you might well be right that the user's ls (Cygwin, perhaps?) does no more. I suppose I was reading something like How do I get some kind of group ownership information for this file?. Which could be achieved in some way, if only by picking the first one or the most/least restrictive according to taste and requirements. But my experience is that doing *anything* with the Windows security model, especially with an imperfect understanding of it, is a recipe for frustration. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Bjoern Schliessmann wrote: Paul Melis wrote: I've always been using the has_key() method to test if a dictionary contains a certain key. Recently I tried the same using 'in', e.g. d = { ... } if k in d: ... Wouldn't be if k in d.keys() be the exact replacement? No, 'k in d' is equivalent to 'd.has_key(k)', only with less (constant) overhead for the function call. 'k in d.keys()' on the other hand creates a list of keys which is then searched linearly -- about the worst thing you can do about both speed and memory footprint. Some numbers: $ python2.5 -m timeit -sN = 1; d = dict.fromkeys(range(N)) N in d.keys() 100 loops, best of 3: 0.693 usec per loop $ python2.5 -m timeit -sN = 1000; d = dict.fromkeys(range(N)) N in d.keys() 1 loops, best of 3: 77.2 usec per loop # ouch! $ python2.5 -m timeit -sN = 1; d = dict.fromkeys(range(N)) N in d 1000 loops, best of 3: 0.192 usec per loop ~ $ python2.5 -m timeit -sN = 1000; d = dict.fromkeys(range(N)) N in d 1000 loops, best of 3: 0.192 usec per loop $ python2.5 -m timeit -sN = 1; d = dict.fromkeys(range(N)) d.has_key(N) 100 loops, best of 3: 0.376 usec per loop $ python2.5 -m timeit -sN = 1000; d = dict.fromkeys(range(N)) d.has_key(N) 100 loops, best of 3: 0.385 usec per loop Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows: get owner and group of a file
with ls -l on windows I get -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile Are you by any chance running cygwin? That comes with ls, but windows doesn't. Another alternative might be mounting their Windows-formatted drive from within a *nix-like OS. These permissions are usually set via the /etc/fstab mounting options for the drive. I don't remember what the defaults are, as I have mine set up to take a forced set of uid/gid for users/groups specific to my system. Because at least FAT32 doesn't have this idea of groups (mapping to NTFS is an entirely different ball of wax), you can specify a default mask for everything or specify the directory mask separately from the file mask. man mount will give more details on such goods. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: About the 79 character line recommendation
Olivier Langlois wrote: There was a coding standard where I worked and the intention behind this requirement was to make the code printer friendly. Printing code source with lines longer than 80 chars greatly hinder readability on paper. I don't think I've ever seen Python code printed out other than in books. Indeed, I don't think I've seen anyone print their code in any language in a decade--it's much easier to read online with tags, class browsers, easy access to version history, etc. The 79-column limit is a hard rule most places I've worked, because pretty much all code is going to wind up with someone looking at it on an 80-column terminal at some point. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Plugin for Web Browser
Re ! Je ne sais pas quel est ton objectif, mais il est possible de couplet Python Javascript, de manière à générer/modifier/piloter le contenu HTML de pages Web depuis Python. Je fais ça tous les jours (avec IE) Pour cela je passe par COM. Malheureusement, à cause de la paranoïa sécuritaire ambiante, il y a de plus en plus de contraintes et d'obtacles. Ainsi, s'il n'y a pas (encore) trop de problèmes tant que l'on est en local (avec les .HTA, par exemple), dès que l'on est distant (Intranet, Extranet, Web), il y a maintenant des confirmations à tout bout de champ, des avertissements peu utiles, mais devenus incontournables, des boîte de dialogues intempestives, etc. Donc, si c'est pour utiliser comme interface pour des applis sur le disque (ou le réseau local), OK ; sinon, ça posera des problèmes. C'en est à tel point que je me demande si l'utilisation de frontaux HTML comme GUI est toujours intéressante. Et le problème ne touche pas que Python. Par exemple, j'ai un client qui utilise un logiciel de gestion de l'assurance qualité, utilisant des navigateurs comme interface. Du coup, ils ont des patchs 2 fois par mois, et les utilisateurs ont toujours plus choses à valider... -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Am I stupid or is 'assert' broken in Python 2.5??
I've noticed something odd in Python 2.5, namely that the 2 argument version of 'assert' is broken. Or at least it seems that way to me. Run the following code in your Python interpreter: myString = None assert( myString, 'The string is either empty or set to the None type!' ) assert( myString ) You'll notice that the first assert doesn't do anything, whereas the second assert correctly recognizes that myString does not evaluate to true. That doesn't seem right. Surely Python should have raised an assertion error on the first assert statement, right?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows: get owner and group of a file
Fredrik Lundh [EMAIL PROTECTED] wrote: Tim Golden wrote: Wow. Python 2.2. No extensions. Not even popen (). You don't want much, do you? I *think* the answer is that you can't. does the group concept even exist on Windows ? cannot recall I've ever seen ls -l print anything but everyone... Domain users have a 'primary group'. Actually, contrary to what I said in the previous post I'm not sure that files have the concept. It may just be users and the actual group permissions then get stored on the file. If so and if you assigned any other groups permission on the file you may not be able to distinguish which is the original group for the file and which was added later. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows: get owner and group of a file
kai rosenthal [EMAIL PROTECTED] wrote: Hello, with ls -l on windows I get -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile How can I get on windows with a standard python 2.2 (without windows extensions) the information 500 and everyone (owner and group)? Also I cannot use popen('ls -l'). With import stat stat_info = os.lstat(myfile) owner = %-8s % stat_info.st_uid group = %-8s % stat_info.st_gid I get 0 for owner and group. Thanks for your hints, Kai You can get the owner by doing os.popen('dir /q') and parsing the output, but it is a string not a number (which I guess is why stat/lstat can't return a value). Internally the ownber and primary group are stored as security identifier (SID) values: a SID is a variable length structure. Running the CACLS command on a file will give you the full permission settings for that file. They are a lot more complex than the simple rwx settings from unix. e.g. C:\tempcacls t.py C:\temp\t.py BUILTIN\Administrators:F NT AUTHORITY\SYSTEM:F MYPC\Duncan:F BUILTIN\Users:R C:\tempcacls . C:\temp BUILTIN\Administrators:F BUILTIN\Administrators:(OI)(CI)(IO)F NT AUTHORITY\SYSTEM:F NT AUTHORITY\SYSTEM:(OI)(CI)(IO)F MYPC\Duncan:F CREATOR OWNER:(OI)(CI)(IO)F BUILTIN\Users:R BUILTIN\Users:(OI)(CI)(IO)(special access:) GENERIC_READ GENERIC_EXECUTE BUILTIN\Users:(CI)(special access:) FILE_APPEND_DATA BUILTIN\Users:(CI)(special access:) FILE_WRITE_DATA So far as I know, to get the primary group for a file you will need to call the win32 function GetSecurityInfo asking for the GROUP_SECURITY_INFORMATION. This will give you an appropriate security descriptor. See http://msdn2.microsoft.com/en-us/library/aa379561.aspx -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I stupid or is 'assert' broken in Python 2.5??
On 6 Dec 2006 06:34:49 -0800, antred [EMAIL PROTECTED] wrote: I've noticed something odd in Python 2.5, namely that the 2 argument version of 'assert' is broken. Or at least it seems that way to me. Run the following code in your Python interpreter: myString = None assert( myString, 'The string is either empty or set to the None type!' ) assert( myString ) You'll notice that the first assert doesn't do anything, whereas the second assert correctly recognizes that myString does not evaluate to true. That doesn't seem right. Surely Python should have raised an assertion error on the first assert statement, right?? assert is not a function, it's a keyword. assert x raises an AssertionError if x evaluates to false. (myString, foo) is a two-tuple. two-tuples are never false. (myString) is the same as myString. -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I stupid or is 'assert' broken in Python 2.5??
Never mind, I'm a schmuck!! =0 It should have been assert myString, 'String empty or None!' Sorry, ignore me. =\ -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I stupid or is 'assert' broken in Python 2.5??
antred a écrit : I've noticed something odd in Python 2.5, namely that the 2 argument version of 'assert' is broken. Or at least it seems that way to me. Run the following code in your Python interpreter: myString = None assert( myString, 'The string is either empty or set to the None type!' ) assert( myString ) You'll notice that the first assert doesn't do anything, whereas the second assert correctly recognizes that myString does not evaluate to true. That doesn't seem right. Surely Python should have raised an assertion error on the first assert statement, right?? That behaviour has been present in Python for a long time. Just know that assert is NOT a function, and thus it doesn't require parenthesis ( just the same as print doesn't require them ) Try without them and it'll work. -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I stupid or is 'assert' broken in Python 2.5??
In [EMAIL PROTECTED], antred wrote: Run the following code in your Python interpreter: myString = None assert( myString, 'The string is either empty or set to the None type!' ) assert( myString ) You'll notice that the first assert doesn't do anything, whereas the second assert correctly recognizes that myString does not evaluate to true. That doesn't seem right. Surely Python should have raised an assertion error on the first assert statement, right?? ``assert`` is a statement, not a function. And non-empty tuples are true: assert (False, 'boink') This is equivalent to ``assert True``. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I stupid or is 'assert' broken in Python 2.5??
antred wrote: I've noticed something odd in Python 2.5, namely that the 2 argument version of 'assert' is broken. Or at least it seems that way to me. Run the following code in your Python interpreter: myString = None assert( myString, 'The string is either empty or set to the None type!' ) assert( myString ) You'll notice that the first assert doesn't do anything, whereas the second assert correctly recognizes that myString does not evaluate to true. That doesn't seem right. Surely Python should have raised an assertion error on the first assert statement, right?? No, the parens turn (myString, '...') into a single (non-False) tuple argument to the assert *statement*. assert (None, None) assert None, None Traceback (most recent call last): File stdin, line 1, in ? AssertionError Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: len() and PEP 3000
Bjoern Schliessmann schrieb: Thomas Guettler wrote: I suggest that at least lists, tupples, sets, dictionaries and strings get a len() method. Why? Pro: Because it makes the API more monotonous and more aligned with all other OO languages that exist now and in future. It also helps any written and unwritten IDE providing a method by means of autocompletion. It ends endless debates with Java/C++/C# etc. and newbie Python programmers about this minor issue. Contra: Having both __len__ ( for providing a generic function by duality ) and len in the API is unpleasant. But maybe one can drop all __special__ methods and use a decorator to express duality between methods and functions? class M: @generic def foo(self): print foo foo(M()) # equals M().foo() foo And since we are at it. Why not also dropping __add__, __radd__, __plus__ etc. for: class M: def binary+(self, other): # replaces __add__ ... def r_binary+(self, other): # replaces __radd__ ... def unary+(self, other):# replaces __plus__ ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I stupid or is 'assert' broken in Python 2.5??
antred a écrit : I've noticed something odd in Python 2.5, namely that the 2 argument version of 'assert' is broken. Or at least it seems that way to me. Run the following code in your Python interpreter: myString = None assert( myString, 'The string is either empty or set to the None type!' ) assert( myString ) You'll notice that the first assert doesn't do anything, whereas the second assert correctly recognizes that myString does not evaluate to true. That doesn't seem right. Surely Python should have raised an assertion error on the first assert statement, right?? What you see is correct. Here is a test under Python 2.4: myString = None assert myString, It is empty Traceback (most recent call last): File stdin, line 1, in ? AssertionError: It is empty assert (myString, It is empty) If you use parenthesis to group the condition to test and the error message, then the whole created tuple is used as a condition to test... and this condition is true so assert dont raise any exception. So, just remove your parenthesis and all will go the expected way. A+ Laurent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I stupid or is 'assert' broken in Python 2.5??
Yeah, it hit me seconds after I had posted my message. =0 Why didn't I think of it during the 30 minutes I spent banging my head against the keyboard going nuts over this 'bug' ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Plugin for Web Browser
oui COM je connais et ça fonctionne bien mais ce n'est pas portable d'un navigateur à l'autre et ce n'est pas ce que je cherche à faire. Mon but serait d'avoir un plugin qui permettrait d'embarquer des applets écrient en python dans les pages html à l'image de Java ou Flash, etc Pour le moment j'essaie de générer un plugin pour firefox avec le Gecko SDK fourni par Mozilla (car bizarrement je ne trouve rien coté IE...) mais ce n'est pas gagné vu mon niveau en C++... Je n'arrive pas à compiler l'exemple. As-tu des connaissances en C++ ? avec Visual C++ ? Seb Michel Claveau a écrit : Re ! Je ne sais pas quel est ton objectif, mais il est possible de couplet Python Javascript, de manière à générer/modifier/piloter le contenu HTML de pages Web depuis Python. Je fais ça tous les jours (avec IE) Pour cela je passe par COM. Malheureusement, à cause de la paranoïa sécuritaire ambiante, il y a de plus en plus de contraintes et d'obtacles. Ainsi, s'il n'y a pas (encore) trop de problèmes tant que l'on est en local (avec les .HTA, par exemple), dès que l'on est distant (Intranet, Extranet, Web), il y a maintenant des confirmations à tout bout de champ, des avertissements peu utiles, mais devenus incontournables, des boîte de dialogues intempestives, etc. Donc, si c'est pour utiliser comme interface pour des applis sur le disque (ou le réseau local), OK ; sinon, ça posera des problèmes. C'en est à tel point que je me demande si l'utilisation de frontaux HTML comme GUI est toujours intéressante. Et le problème ne touche pas que Python. Par exemple, j'ai un client qui utilise un logiciel de gestion de l'assurance qualité, utilisant des navigateurs comme interface. Du coup, ils ont des patchs 2 fois par mois, et les utilisateurs ont toujours plus choses à valider... -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
RE: Windows: get owner and group of a file
[Duncan Booth] | You can get the owner by doing os.popen('dir /q') and parsing | the output, but it is a string not a number (which I guess is why | stat/lstat can't return a value). Good one; I'd forgotten about that. However, I don't know if the OP's restriction against popen (ls- l) extends to popen (dir /q) ! TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Fredrik Lundh wrote: [...] this is why e.g. string[:len(prefix)] == prefix is often a lot faster than string.startswith(prefix) This is interesting. In which cases does the former form perform better? [I won't stop using str.startswith anyway :) ] Regards. -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: Book recommendations
On 6 Dec 2006 05:55:44 -0800, Robert Hicks [EMAIL PROTECTED] wrote: On Dec 6, 7:09 am, west [EMAIL PROTECTED] wrote: Can someone recommend a Python book for a newbie and perhaps you have a used one for sale? Thank you. I think a lot depends on your experience with other programming languages. If you are new to Python, but not to programming, I'd definitely go for Python in a nutshell. To the point, loaded with information, and a great resource. And I'd get Python pocket reference, which might be, for long periods, the only thing you need to open. If you do not have a lot of programming experience, you might want to look at How to think like a computer scientist, A byte of Python (both freely available over the net), and then go for Core Python Programming. Beginning Python: From Novice to Professional by Magnus Lie Hetland Core Python Programming (2nd Edition) by Wesley Chun There are plenty of Free online ones as well. HTH Robert -- http://mail.python.org/mailman/listinfo/python-list -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz -- http://mail.python.org/mailman/listinfo/python-list
PyRun_SimpleString no sys.argv[0]
Hello, I'm just starting with Python - would like to embed it in my windows-programm as an script-processor. For tests I use easygui some easy-wrapper for the py-tck-stuff. PyRun_SimpleString(from easygui import *\n); PyRun_SimpleString(import sys\n); PyRun_SimpleString(msgbox()\n); Traceback (most recent call last): File string, line 1, in module File easygui.py, line 148, in msgbox reply = buttonbox(message, title, choices) File easygui.py, line 170, in buttonbox root = Tk() File C:\Python\Python25\Lib\lib-tk\Tkinter.py, line 1631, in __init__ baseName = os.path.basename(sys.argv[0]) AttributeError: 'module' object has no attribute 'argv' May bee makes some sence that the embedded Interpreter has no argv[0], however tk seems not to bee ready for that. I try to define some sys.argv[0] myself after I get out how to do that, maybee someone other has an better idea until than. -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Paul Melis wrote: I've always been using the has_key() method to test if a dictionary contains a certain key. Recently I tried the same using 'in', e.g. I've found using the set type to be the quickest way to do many of these tasks. That leads me to another problem: how to cast / convert sets as something else afterwards What's the best (i.e. Pythonic) way to do this? I need to generate a set (lots of intersections involved), but then I need to display it sorted lstBugsChanged = [ bugId for bugId in setBugsChanged ] lstBugsChanged.sort() -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Andy Dingley wrote: I need to generate a set (lots of intersections involved), but then I need to display it sorted lstBugsChanged = [ bugId for bugId in setBugsChanged ] lstBugsChanged.sort() lstBugsChanged = sorted(setBugsChanged) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Andy Dingley wrote: I need to generate a set (lots of intersections involved), but then I need to display it sorted lstBugsChanged = [ bugId for bugId in setBugsChanged ] lstBugsChanged.sort() In Python 2.4: sorted(setBugsChanged) -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
I wrote: In Python 2.4: lastline.replace(, =) -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
ANN: Albow - A simple widget library for Pygame
ALBOW - A Little Bit of Widgetry for PyGame --- Version 1.0 This is a very basic, no-frills widget set for creating a GUI using PyGame. It was originally developed for my PyWeek 3 competition entry, Sneak. I am documenting and releasing it as a separate package so that others may benefit from it, and so that it will be permissible for use in future PyGame entries. The download includes HTML documentation and an example program demonstrating most of the library's features. http://www.cosc.canterbury.ac.nz/greg.ewing/python/Albow/ -- Gregory Ewing [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Peter Otten wrote: No, 'k in d' is equivalent to 'd.has_key(k)', only with less (constant) overhead for the function call. Ah, thx. Thought the x in d syntax might search in d.values() too. Regards, Björn -- BOFH excuse #12: dry joints on cable plug -- http://mail.python.org/mailman/listinfo/python-list
Re: len() and PEP 3000
Kay Schluehr wrote: Pro: Because it makes the API more monotonous and more aligned with all other OO languages that exist now and in future. It also helps any written and unwritten IDE providing a method by means of autocompletion. It ends endless debates with Java/C++/C# etc. and newbie Python programmers about this minor issue. Contra: It makes the API more aligned with some other OO languages and moves the focus from the python way to the way it's always been done. Regards, Björn -- BOFH excuse #308: CD-ROM server needs recalibration -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Roberto Bonvallet wrote: this is why e.g. string[:len(prefix)] == prefix is often a lot faster than string.startswith(prefix) This is interesting. In which cases does the former form perform better? no time to doublecheck right now, but iirc, last time we benchmarked this, slicing was faster when len(prefix) 300 characters or so. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Bjoern Schliessmann wrote: Peter Otten wrote: No, 'k in d' is equivalent to 'd.has_key(k)', only with less (constant) overhead for the function call. Ah, thx. Thought the x in d syntax might search in d.values() too. I don't think it does Python 2.4.3 (#1, Nov 19 2006, 13:16:36) [GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 Type help, copyright, credits or license for more information. d={1:'a',2:'b'} 1 in d True 'a' in d False Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Book recommendations
Can someone recommend a Python book for a newbie and perhaps you have a used one for sale? Thank you. A Byte of Python is supposed to be good for beginners too. See http://www.byteofpython.info/ Its also a recommended book on the main Python site www.python.org From the preface: This book serves as a guide or tutorial to the Python programming language. It is mainly targeted at newbies (those who are new to computers). It is also useful for experienced programmers who are new to Python. The aim is: If all you know about computers is how to open and save text files, then you should be able to learn Python from this book. If you have previous programming experience, then this book should be useful to get you up to speed on Python. HTH Vasudev ~~~ Vasudev Ram Software consulting and training Dancing Bison Enterprises http://www.dancingbison.com http://jugad.livejournal.com http://dancingbison.blogspot.com ~~~ -- http://mail.python.org/mailman/listinfo/python-list
Best memory analyzer?
Hi! I'm using the BGL bindings, but I think I'm having a giant memory leak. Thing is, I'm not sure if it is the bound C++ variables that are not being trashed, or if the leak is inside my program. What is the best way to debug this? Thanks! Hugo Ferreira -- GPG Fingerprint: B0D7 1249 447D F5BB 22C5 5B9B 078C 2615 504B 7B85 -- http://mail.python.org/mailman/listinfo/python-list
Re: About the 79 character line recommendation
Steve Bergman wrote: So, I was wondering what more accomplished Python programmers thought about this. I *hate* people using more than 79 chars per line! ;) They look horrible in emacs and horrible on print. I never found the need for longer lines. The limit also acts as a deterrent against extra-large one-liners. Finally, notice that you can alwasys aliases if you are a lazy typist: shortcut = LongClassName.LongAttributeName This also saves an attribute access and gives you some additional speed, which may be useful in some cases. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: What are python closures realy like?
Paul Boddie wrote: I'm not pointing the finger at you here, Karl, since you seem to be experimenting with closures, but why are they suddenly so fashionable? Haven't the features supporting them existed in Python for a few versions now? Don't people want to write classes any more? Intrigued, Paul I believe decorators are in large part responsible for that. A callable object does not work as a method unless you define a custom __get__, so in decorator programming it is often easier to use a closure. OTOH closures a not optimal if you want persistency (you cannot pickle a closure) so in that case I use a callable object instead. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a decent HTML parser for Python...
Fredrik Lundh escreveu: Except it appears to be buggy or, at least, not very robust. There are websites for which it falsely terminates early in the parsing. which probably means that the sites are broken. the amount of broken HTML on the net is staggering, as is the amount of code in a typical web browser for dealing with all that crap. for a more tolerant parser, see: http://www.crummy.com/software/BeautifulSoup/ /F +1 for BeautifulSoup. The documentation is quite brief and sometimes confusing, but I've found it the easiest parser I've ever worked with. Stephen -- http://mail.python.org/mailman/listinfo/python-list
extension programing with c
Hi I want to define extention module that connect to berkeley db. I define function for connection to berkeley db with c language in one file and define other function for create extention module that can import from python. function for connection to berkeley db is like this: name=BDB.c - #include db.h void CreateDatabase(char *databasename){ DB *dbp ; int ret; DB_ENV *myEnv; u_int32_t env_flags; char *databasename; ret = db_env_create(myEnv, 0); if (ret != 0) { fprintf(stderr, Error creating env handle: %s\n, db_strerror(ret)); return -1; } env_flags = DB_CREATE |DB_INIT_MPOOL; if((ret = myEnv-open(myEnv,env55, env_flags , 0))!=0){ fprintf(stderr, Error open environment: %s\n, db_strerror(ret)); } db_create(dbp,myEnv,0); dbp-open(dbp,NULL,university,databasename,DB_BTREE,DB_CREATE,0); } --- function for define extention module is like this: name=importBDB.c #include Python.h #include db.h CreateDatabase(char *); static PyObject *insert_data(PyObject *self,PyObject *args) { char *databasename; if (!PyArg_ParseTuple(args, s, databasename)) { return NULL; } CreateDatabase(databasename); Py_RETURN_NONE; } static PyMethodDef data_methods[] = { { data, (PyCFunction)insert_data, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } }; PyMODINIT_FUNC initdata() { Py_InitModule3(data, data_methods, My first extension module.); } -- my compiler is gcc and compiling it with this command: gcc -shared -I/usr/local/include/python2.4 -I/usr/local/BerkeleyDB.4.5/include \ importBDB.c BDB.c \ -L/usr/local/BerkeleyDB.4.5/lib -ldb-4.5 -o insert.so there is an error occurs like this: gcc: importBDB.c: No such file or directory gcc: -L/usr/local/BerkeleyDB.4.5/lib: No such file or directory I know problem for compiler please help me regards saeed __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Roberto Bonvallet wrote: lstBugsChanged = [ bugId for bugId in setBugsChanged ] In Python 2.4: Hmmm. Thanks. Another reason to twist the admin's arm and get them to upgrade the last 2.3.4 boxen sorted(setBugsChanged) Out of interest, whats the Pythonic way to simply cast (sic) the set to a list, assuming I don't need it sorted? The list comprehension? -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a decent HTML parser for Python...
Agreed that the web sites are probably broken. Try running the HTML though HTMLTidy (http://tidy.sourceforge.net/). Doing that has allowed me to parse where I had problem such as yours. I have also had luck with BeautifulSoup, which also includes a tidy function in it. Just Another Victim of the Ambient Morality wrote: Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Okay, I think I found what I'm looking for in HTMLParser in the HTMLParser module. Except it appears to be buggy or, at least, not very robust. There are websites for which it falsely terminates early in the parsing. I have a sneaking feeling the sgml parser will be more robust, if only it had that one feature I am looking for. Can someone help me out here? Thank you... -- http://mail.python.org/mailman/listinfo/python-list
PHP calls python: process vs threads
What I want to do is the following: Web user uploads a word doc, and I need it to move the uploaded word doc, on to another machine and conver it to pdf. Then update the database and allow immediate pdf download. I am thinking of using ftp from machine 1 - machine 2, then convert doc to pdf on machine 2, using process or thread. What is the best way to go about doing this, process or threads or pyro? Pdf is created by calling commands on the command line, through python script. Thank you in advance. John -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Andy Dingley wrote: Out of interest, whats the Pythonic way to simply cast (sic) the set to a list, assuming I don't need it sorted? The list comprehension? mySet = set(myList) myList = list(mySet) -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Andy Dingley wrote: sorted(setBugsChanged) Out of interest, whats the Pythonic way to simply cast (sic) the set to a list, assuming I don't need it sorted? The list comprehension? list(setBugsChanged) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Peter Otten [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Andy Dingley wrote: sorted(setBugsChanged) Out of interest, whats the Pythonic way to simply cast (sic) the set to a list, assuming I don't need it sorted? The list comprehension? list(setBugsChanged) Peter Note that this is not really a cast in the C sense of the word. list(setBugsChanged) constructs and returns a new list containing the elements of setBugsChanges, and leaves setBugsChanged unchanged. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Extension causes segmentation fault -- suggestions on troubleshooting?
Hello, I'm writing a C extension for cygwin python to access a vendor supplied DLL that allows one to set the general purpose IO (gpio) pins of the Silicon Labs' cp2103 USB/serial chip. We communicate to the device using the vendor's virtual com port driver, but the gpio pins allow us access to other functions, like resetting the device and initiating a firmware download. The DLL provides a function, CP210xRT_WriteLatch which sets the gpio pins. It accepts the HANDLE of the open device's com port, a bit mask, and a bit data field to perform its task. Note: I load the DLL dynamically within the extension's init function. Even though the DLL functions are C, apparently the vendor did not use extern C {, as the functions have C++-like decorations (seen via 'nm' on the .lib file) and cygwin's gcc linker generates symbol not found errors when linking to the provided .lib. Dynamically loading the library works. FWIW, the DLL is said to be compiled via VC++ 6.0. Also using the vendor supplied .h file. The extension code, python test program, stackdump output and program run output are included in the attached tgz file for reference. Th extension accepts a file descriptor to an open serial port, uses the cygwin get_osfhandle() function to get the corresponding HANDLE, calls the DLL function, then returns. When run, python core dumps somewhere between the return statement in the extension function and the python program statement following the call to the extension function. The gpio bits are set correctly. If I comment out the call to the DLL function within the extension, no core dump. Obviously, the gpio bits are not set in this case. If I do not open the com port in the python program, but instead call CreateFile/CloseFile within the extension itself and using the HANDLE provided by CreateFile to call the DLL function, the gpio bits are set and no core dump. I could live with this approach if Python could have the com port open when it calls the extension. When I try this, the extension's call to CreateFile to open the com port always fails, presumably because the serial module opens it in some manner that doesn't allow sharing...? Being relatively new to Python, I'm hoping someone can see an obvious mistake, or suggest some strategies to troubleshoot this problem. Thank you for your time, Steve cp210x_rt.tgz Description: application/tgz -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Paul Melis wrote: I don't think it does Thanks for trying, I was too lazy ;) Regards, Björn -- BOFH excuse #52: Smell from unhygienic janitorial staff wrecked the tape heads -- http://mail.python.org/mailman/listinfo/python-list
problem with closures
Hi, I have a problem with closures. I am trying to implement yet another design by contract decorator which would look like the following: pre def contract(f): def newf(*args, **kw): import new precondition = new.function(f.func_code.co_consts[1], f.func_globals,'pre', f.func_defaults, f.func_closure) precondition() result=f(*args, **kw) postcondition=new.function(f.func_code.co_consts[2],globals()) postcondition(result) return result return newf @contract def foo(x,y,g=2,z=1): def pre(): assert x1 and 0y100 def post(result): assert result 0 print 'main' return x+y+z*g print foo(2,5,4,69) pre The problem is that i get the following error message on line 7: TypeError: arg 5 (closure) must be tuple f.func_closure is indeed empty while f.func_code.co_consts[1].co_freevars is logically equal to ('x','y'). Thanks for responding Alain -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
Paul Melis [EMAIL PROTECTED] wrote: Ah, thx. Thought the x in d syntax might search in d.values() too. I don't think it does Python 2.4.3 (#1, Nov 19 2006, 13:16:36) [GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 Type help, copyright, credits or license for more information. d={1:'a',2:'b'} 1 in d True 'a' in d False It is easy enough to to check if you remember that 'in' maps to the __contains__ method: help({}.__contains__) Help on built-in function __contains__: __contains__(...) D.__contains__(k) - True if D has a key k, else False -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonTidy
Thomas Heller wrote this on Tue, Dec 05, 2006 at 07:06:30PM +0100. My reply is below. There is still one major issue. pythonTidy uses open(input-file, rb) to open the Python module to tidy up. That does not work on Windows, at least if the file has (as it should) \r\n newlines. Thank you for challenging my parochial world view. I have posted yet another version of PythonTidy: http://www.lacusveris.com/PythonTidy/PythonTidy-1.5.python This one is omnivorous wrt to newlines. For output, PythonTidy generates \n line endings, this should also be changed on Windows. When OVERRIDE_NEWLINE = None, the first newline encountered on input is the one used throughout the output; otherwise, you can set it to what you want, e.g, OVERRIDE_NEWLINE = '\n'. PythonTidy outputs strings with single quotes, while my own style is to use double quotes (I don't think that pep8 prefers one over the other). Is it possible to customize this? Here is a new global: DOUBLE_QUOTED_STRINGS = True. -- .. Chuck Rhode, Sheboygan, WI, USA .. Weather: http://LacusVeris.com/WX .. 30° — Wind WNW 15 mph — Sky overcast. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get all the variables of a string formating?
On 6 Dec 2006 09:41:36 -0800, GHUM [EMAIL PROTECTED] wrote: imagine: template= Hello %(name)s, how are you %(action)s we can use it to do things like: print template % dict (name=Guido, action=indenting) Is there an easy (i.e.: no regex) way to do get the names of all parameters? get_parameters(template) should return [name, action] Python has to do this somewhere internally. how to access this knowledge? Harald -- http://mail.python.org/mailman/listinfo/python-list I am not aware of anything in the stdlib to do this easily, but its pretty easy to get them. See this example: class format_collector(object): def __init__(self): self.names = [] def __getitem__(self, name): self.names.append(name) return '' collector = format_collector() %(foo)s %(bar)s % collector assert collector.names == ['foo', 'bar'] Of course, wrapping this functionality into a simple function is straightforward and will look better. -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get all the variables of a string formating?
GHUM [EMAIL PROTECTED] wrote: Is there an easy (i.e.: no regex) way to do get the names of all parameters? get_parameters(template) should return [name, action] Python has to do this somewhere internally. how to access this knowledge? How about: class gpHelper: def __init__(self): self.names = set() def __getitem__(self, name): self.names.add(name) return 0 def get_parameters(template): hlp = gpHelper() template % hlp return hlp.names template= Hello %(name)s, how are you %(action)s get_parameters(template) set(['action', 'name']) -- http://mail.python.org/mailman/listinfo/python-list
Getting started with the Python source
I am interested in making some changes and additions to the Python environment (Python and IDLE). I have the source code and can build the source, but what I want to know is what are the main functions or source code for Python and IDLE. Specifically I would like to know what in Python and IDLE would be analogous to void main () in a standard C program. This will help me to work out the structure of the interpreter and the environment. Your help will be greatly appreciated. The changes I wish to make are for investigating the modification of the Python environment for novice programmers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Plugin for Web Browser
Bonsoir ! As-tu des connaissances en C++ ? avec Visual C++ ? Ben, non, je ne pratique pas ces machins. Par contre, je pense qu'il existe une autre démarche, qui consiste à générer, à la volée, en Python, des sortes d'applets java/javascript. Avantages : rien à installer ; milti-navigateurs Inconvénient : ça se programme côté serveur. Voir : Pyjamas (http://pyjamas.pyworks.org/FR/overview/) -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing Barcodes from webapp?
Dennis Lee Bieber wrote: On Tue, 05 Dec 2006 18:19:58 GMT, Dennis Lee Bieber [EMAIL PROTECTED] declaimed the following in comp.lang.python: Aye, just the Postnet scheme... The difficult part was working out the spacing for the dot-matrix printer; the rest was just using the Zipcode digits as an index into byte-strings of MX-80 codes. I've recently downloaded the 4-state spec from USPS... That thing is obscene... At least Postnet could be decoded visually with a simple chart. 4-state distributes bits all over! well the code in reportlab/graphics/barcodes that deals with it should be adaptable if you're interested (only around 300 lines). I have a feeling that the UK/AU 4state codes aren't as exotic, but not having actually implemented them it's hard to say. -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list