Re: Annoying octal notation
On Sat, 22 Aug 2009 22:19:01 -0500, Derek Martin wrote: On Sat, Aug 22, 2009 at 02:55:51AM +, Steven D'Aprano wrote: I can see how 012 can be confusing to new programmers, but at least it's legible, and the great thing about humans is that they can be taught (usually). And the great thing is that now you get to teach yourself to stop writing octal numbers implicitly and be write them explicitly with a leading 0o instead :) Sorry, I don't write them implicitly. A leading zero explicitly states that the numeric constant that follows is octal. That is incorrect. Decimal numbers implicitly use base 10, because there's nothing in the literal 12340 (say) to indicate the base is ten, rather than 16 or 9 or 23. Although implicit is usually bad, when it's as common and expected as decimal notation, it's acceptable. Hex decimals explicitly use base 16, because the leading 0x is defined to mean base 16. 0x is otherwise not a legal decimal number, or hex number for that matter. (It would be legal in base 34 or greater, but that's rare enough that we can ignore this.) For the bases we care about, a leading 0x can't have any other meaning -- there's no ambiguity, so we can treat it as a synonym for base 16. (Explicitness isn't a binary state, and it would be even more explicit if the base was stated in full, as in e.g. Ada where 16#FF# = decimal 255.) However, octal numbers are defined implicitly: 012 is a legal base 10 number, or base 3, or base 9, or base 16. There's nothing about a leading zero that says base 8 apart from familiarity. We can see the difference between leading 0x and leading 0 if you repeat it: repeating an explicit 0x, as in 0x0xFF, is a syntax error, while repeating an implicit 0 silently does nothing different: 0x0xFF File stdin, line 1 0x0xFF ^ SyntaxError: invalid syntax 0077 63 It is so in 6 out of 7 computer languages I have more than a passing familiarity with (the 7th being scheme, which is a thing unto itself), including Python. It's that way on Bourne-compatible and POSIX-compatible Unix shells (though it requires a leading backslash before the leading zero there). I'm quite certain it can not be the case on only those 6 languages that I happen to be familiar with... No, of course not. There are a bunch of languages, pretty much all heavily influenced by C, which treat integer literals with leading 0s as oct: C++, Javascript, Python 2.x, Ruby, Perl, Java. As so often is the case, C's design mistakes become common practice. Sigh. However, there are many, many languages that don't, or otherwise do things differently to C. Even some modern C-derived languages reject the convention: C# doesn't have octal literals at all. As far as I can tell, Objective-C and Cocoa requires you to explicitly enable support for octal literals before you use them. In D, at least some people want to follow Python's lead and either drop support for oct literals completely, or require a 0o prefix: http://d.puremagic.com/issues/show_bug.cgi?id=2656 E makes a leading 0 a syntax error. As far as other, non-C languages go, leading 0 = octal seems to be rare or non-existent: Basic and VB use a leading O for octal. FORTRAN 90 uses a leading O (uppercase o) for octal, and surrounds the literal in quotation marks: O12 would be ten in octal. 012 would be decimal 12. As far as I can tell, COBOL also ignores leading zeroes. Forth interprets literals according to the current value of BASE (which defaults to 10). There's no special syntax for it.To enter ten in octal, you might say: 8 BASE ! 12 or if your system provides it: OCT 12 Standard Pascal ignores leading 0s in integers, and doesn't support octal at all. A leading $ is used for hex. At least one non-standard Pascal uses leading zero for octal. Haskell requires an explicit 0o: http://www.haskell.org/onlinereport/lexemes.html#lexemes-numeric So does OCaml. Ada uses decimal unless you explicitly give the base: http://archive.adaic.com/standards/83lrm/html/lrm-02-04.html Leading zeroes are insignificant in bc: [st...@sylar ~]$ bc bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 012 + 011 23 Leading zeroes are also insignificant in Hewlett-Packard RPN language (e.g. HP-48GX calculators), Hypertalk and languages derived from it. I'm not sure, but it looks to me like Boo doesn't support octal literals, although it supports hex with 0x and binary with 0b. Algol uses an explicit base: 8r12 to indicate octal 10. Common Lisp and Scheme use a #o prefix. As far as *languages* go, 0-based octal literals are in the tiny minority. As far as *programmers* go, it may be in a plurality, perhaps even a small minority, but remember there are still millions of VB programmers out there who are just as unfamiliar with C conventions. While it may be true that people commonly
Re: Blank Line at Program Exit
On Thursday 20 August 2009 07:31:14 Steven Woody wrote: Hi, Any python program, even that does absolutely nothing in the code, will cause a blank line printed out when the program exit. What's the reason? not for me: h...@linuxbox:~/Sasol/lib cat blank.py h...@linuxbox:~/Sasol/lib python blank.py h...@linuxbox:~/Sasol/lib - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: your favorite debugging tool?
On Saturday 22 August 2009 16:49:22 Aahz wrote: In article mailman.227.1250951162.2854.python-l...@python.org, Esmail ebo...@hotmail.com wrote: What is your favorite tool to help you debug your code? I've been getting along with 'print' statements but that is getting old and somewhat cumbersome. Despite the fact that I've been using Python for more than a decade, print is still my mainstay (or possibly logging to a file). Same here, although I have not been abusing python for as long as Aahz has been using it. I find that python pretty much does more or less what I expect it to, and where it does not, a print quickly gets me to RTFM when I have been rolling along under intuition. And the final arbiter is of course the interactive prompt. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: your favorite debugging tool?
On 2009-08-22 07:25 AM, Esmail wrote: Hi all, What is your favorite tool to help you debug your code? I've been getting along with 'print' statements but that is getting old and somewhat cumbersome. I'm primarily interested in utilities for Linux (but if you have recommendations for Windows, I'll take them too :) I use emacs as my primary development environment, FWIW. Someone mentioned winpdb .. anyone have experience/comments on this? Others? I am frequently in the IPython interactive prompt for testing out stuff and even as the main way of running my code. It has a nice feature that when you get a traceback, you can open up pdb post-mortem. In [8]: def f(x): ...: y = 1 / x ...: return y ...: In [9]: f(1) Out[9]: 1 In [10]: f(0) --- ZeroDivisionError Traceback (most recent call last) /Users/rkern/ipython console in module() /Users/rkern/ipython console in f(x) ZeroDivisionError: integer division or modulo by zero In [11]: %debug ipython console(2)f() ipdb print x 0 I have a little function that I've been using recently to print out the function I am currently in along with the arguments: def whereami(): Print the current function call. import kerntrace;kerntrace.whereami() import inspect frame = inspect.currentframe(1) args, varargs, varkw, f_locals = inspect.getargvalues(frame) if args[:1] == ['self']: del args[0] print '%s%s' % (frame.f_code.co_name, inspect.formatargvalues(args, varargs, varkw, f_locals)) I think pdb is okay, but I am looking forward to pydbgr's completion. http://code.google.com/p/pydbgr/ -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
conditional for-statement
Hi, i was wondering if there is a syntax alike: for i in range(10) if i 5: print i equivalent to for i in (for i in range(10) if i5): print i sebastien -- http://mail.python.org/mailman/listinfo/python-list
Re: conditional for-statement
seb sdementen at gmail.com writes: Hi, i was wondering if there is a syntax alike: for i in range(10) if i 5: print i for i in range(10): if i 5: print i -- http://mail.python.org/mailman/listinfo/python-list
Re: your favorite debugging tool?
On Aug 22, 4:25 pm, Esmail ebo...@hotmail.com wrote: Hi all, What is your favorite tool to help you debug your code? I've been getting along with 'print' statements but that is getting old and somewhat cumbersome. I'm primarily interested in utilities for Linux (but if you have recommendations for Windows, I'll take them too :) I use emacs as my primary development environment, FWIW. Someone mentioned winpdb .. anyone have experience/comments on this? Others? Thanks, Esmail Although like the others I mostly use print statements, in a few occasions I have found useful to resort to a full-blown debugger. Of the ones I have used, the one provided by eclipse+pydev is the one I liked most. The one in pywin32 IDE is basic but can be useful. With emacs, one should be able to use pydb, but I never used that, although emacs is my most used programming environment on most platforms. About print cumbersomeness, I agree. As I posted elsewhere, I'd like a 'trace mechanism' with the following characteristics: 1. Can be enabled/disabled easily, and when it is dsabled it has no runtime costs ( i.e. disabled 'trace' statements do not generate any code) 2. Can be enabled/disabled on a class/function/method base (e.g. enable only the trace in a method ), to only get the trace output from the code you are debugging 3. Make it easy to report the context (i.e. generate messages which starts with 'class.method:', without hanving to hardcode class name and method name). I know about the 'trace' and 'logging' modules, but neither seem to satisfy the above requirements. Probably using python introspection and metaprogramming features it is possible to do somethinmg that covers at least 2 and 3. Not sure about one (using if __debug__ you can reduce the runtime cost when compiling in optimized mode, but probably not nullify it). Ciao - FB -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
On Sat, 22 Aug 2009 14:54:41 -0700 (PDT), James Harris wrote: They look good - which is important. The trouble (for me) is that I want the notation for a new programming language and already use these characters. I have underscore as an optional separator for groups of digits - 123000 and 123_000 mean the same. The semicolon terminates a statement. Based on your second idea, though, maybe a colon could be used instead as in 2:1011, 8:7621, 16:c26b I don't (yet) use it as a range operator. I could also use a hash sign as although I allow hash to begin comments it cannot be preceded by anything other than whitespace so these would be usable 2#1011, 8#7621, 16#c26b I have no idea why Ada which uses the # also apparently uses it to end a number 2#1011#, 8#7621#, 16#c26b# If you are going Unicode, you could use the mathematical notation, which is 1011sub2/sub, 7621sub8/sub, c26bsub16/sub (subscript specification of the base). Yes, it might be difficult to type (:-)), and would require some look-ahead in the parser. One of the advantages of Ada notation, is that a numeric literal always starts with decimal digit. That makes things simple for a descent recursive parser. I guess this choice was intentional, back in 1983 a complex parser would eat too much resources... -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de -- http://mail.python.org/mailman/listinfo/python-list
Re: conditional for-statement
On Aug 23, 10:09 am, seb sdemen...@gmail.com wrote: Hi, i was wondering if there is a syntax alike: for i in range(10) if i 5: print i equivalent to for i in (for i in range(10) if i5): print i sebastien AFAIK, no syntax fo that. But the standard syntax is not too different: for i in range(0): if i 5 : print i Or you can use itertools.ifilter: for i in itertools.ifilter( lambda x: x 5, range(10) ): print i Or, if you define a function corresponding to the loop body, you could do something like: map( print, (i for i in range(10) if i 5 )) # only works if print is a function Ciao FB -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying octal notation
MRAB: '_': what if in the future we want to allow them in numbers for clarity? Hettinger says it's hard (= requires too many changes) to do that and Python programs don't have big integer constants often enough, so probably that improvement will not see the light. In the meantime in a Python program of mine I have put a small bug, writing 100 instead of 1000. Now in Python I write 10*1000*1000, because I try to learn from my bugs. In D I enjoy writing 10_000_000. --- Steven D'Aprano: In D, at least some people want to follow Python's lead and either drop support for oct literals completely, or require a 0o prefix:http://d.puremagic.com/issues/show_bug.cgi?id=2656 Yes, people in the D community are trying to improve things, but it's a slow and painful process, and often it goes nowhere. There's lot of politics. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE file saving problem
On Fri, 21 Aug 2009 14:48:56 -0700 (PDT), r rt8...@gmail.com wrote: On Aug 21, 4:10 pm, MRAB pyt...@mrabarnett.plus.com wrote: Yes, and much more needs improvement! I have made many changes already and i am polishing an IDLE 3000 for the good people of Pythonia, stay tuned more to come There is a small little detail that nags me when I use IDLE: When the cursor is somewhere in the white space at the beginning of the lines and I use Ctrl-rightArrow [ctrl]-[-] to go to the first word in the line then IDLE skips the position with the first non-whitespace letter and places the cursor after the first word in the line. This is not consistent because moving backwards works. [ctrl]-[-] Similar things happen at the end of a line. I suggest that these movements should consider 'before the first' and 'after the last' text in the line as stop positions. I think other editors do that, at least MS Visual Studio. (The [pos1] alternating between first column and first text in line does not help much.) Harald -- http://mail.python.org/mailman/listinfo/python-list
Re: conditional for-statement
Il Sun, 23 Aug 2009 01:09:04 -0700 (PDT), seb ha scritto: Hi, i was wondering if there is a syntax alike: for i in range(10) if i 5: print i You can write for i in filter(lambda i: i 5, range(10)): print i but for i in range(10): if i 5: print i it' better readable, and for i in range(6,10): print i it's event better. -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
In comp.lang.python James Harris james.harri...@googlemail.com wrote: On 22 Aug, 10:27, David 71da...@libero.it wrote: ... What about 2_1011, 8_7621, 16_c26h or 2;1011, 8;7621, 16;c26h ? They look good - which is important. The trouble (for me) is that I want the notation for a new programming language and already use these characters. I have underscore as an optional separator for groups of digits - 123000 and 123_000 mean the same. Why not just use the space? 123 000 looks better than 123_000, and is not syntactically ambiguous (at least in python). And as it already works for string literals, it could be applied to numbers, too… -- --- | Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__garabik @ kassiopeia.juls.savba.sk | --- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! -- http://mail.python.org/mailman/listinfo/python-list
Re: logging SMTPhandler Error
On Aug 23, 12:48 am, a...@pythoncraft.com (Aahz) wrote: It's also not too difficult to do the moral equivalent with dnspython and find the MX host for the domain you're trying to send e-mail to; that usually does not require an encrypted connection. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ I support family values -- Addams family values --www.nancybuttons.com Thanks :-). I'm not sure that I understand exactly what needs to be done, but I'll read the documentation and see what I can come up with. Bev in TX -- http://mail.python.org/mailman/listinfo/python-list
Is Python what I need?
Hi all I'm interested in developing computer based, interactive programs for students in a special school who have an aversion to pen and paper. I've searched the net to find ready made software that will meet my needs but it is either written to a level much higher than these students can cope with or priced beyond our school budget. I came across a blog of someone singing the praises of Python. My question is therefore aimed at those that know what they are talking about (ie users in this group). Is Python the language I need to learn to develop these programs? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python what I need?
On Sun, Aug 23, 2009 at 9:26 PM, newbie sp.b...@gmail.com wrote: Hi all I'm interested in developing computer based, interactive programs for students in a special school who have an aversion to pen and paper. What sort of interactive program? Would it be educational, for example? I've searched the net to find ready made software that will meet my needs but it is either written to a level much higher than these students can cope with or priced beyond our school budget. Could you give us the details of which software you've encountered that were either too expensive or did not meet your needs? I came across a blog of someone singing the praises of Python. My question is therefore aimed at those that know what they are talking about (ie users in this group). Is Python the language I need to learn to develop these programs? Any language can do the job. What a program does depends on the design, and specification. Different languages simply have different behaviours, and perhaps platform dependence and requirements. So, in some way, yes, Python can do what you need, but you need to tell us in exact details what you were really looking for. Good luck, Xav -- http://mail.python.org/mailman/listinfo/python-list
Re: your favorite debugging tool?
Il Sat, 22 Aug 2009 10:25:37 -0400, Esmail ha scritto: I use emacs as my primary development environment, FWIW. Someone mentioned winpdb .. anyone have experience/comments on this? Others? I use Winpdb on Windows and I feel quite comfortable. The interface is not so clever as more advanced (and expensive, winpdb is free) debuggers but there is all yuo need for deep-source debugging. It is especially suited for multi threaded programs and GUI debugging, where command line debugging is a pain. It supports remote debugging over encrypted connection also. regards David -- http://mail.python.org/mailman/listinfo/python-list
Combining python and perl
Hi, According to http://www.python.org/doc/essays/comparisons.html, it says Python and Perl come from a similar background (Unix scripting, which both have long outgrown), and sport many similar features, but have a different philosophy. Perl emphasizes support for common application- oriented tasks, e.g. by having built-in regular expressions, file scanning and report generating features. Python emphasizes support for common programming methodologies such as data structure design and object-oriented programming, and encourages programmers to write readable (and thus maintainable) code by providing an elegant but not overly cryptic notation. As a consequence, Python comes close to Perl but rarely beats it in its original application domain; however Python has an applicability well beyond Perl's niche. My question is that how to combine both python and perl to take advantages of both their strong aspects. Of course, I want to primarily use python---that is why I send this message to this group. I see a module 'perlmodule'. But I would like to know whether there are other tips besides using 'perlmodule' to take perl's advantage in python. Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining python and perl
On Sun, 2009-08-23 at 05:37 -0700, Peng Yu wrote: Hi, According to http://www.python.org/doc/essays/comparisons.html, it says Python and Perl come from a similar background (Unix scripting, which both have long outgrown), and sport many similar features, but have a different philosophy. Perl emphasizes support for common application- oriented tasks, e.g. by having built-in regular expressions, file scanning and report generating features. Python emphasizes support for common programming methodologies such as data structure design and object-oriented programming, and encourages programmers to write readable (and thus maintainable) code by providing an elegant but not overly cryptic notation. As a consequence, Python comes close to Perl but rarely beats it in its original application domain; however Python has an applicability well beyond Perl's niche. My question is that how to combine both python and perl to take advantages of both their strong aspects. Of course, I want to primarily use python---that is why I send this message to this group. I'm not sure why you'd want to combine them. You can pretty much do the same things with both language, it's just that one may emphasize one thing or make it easier for the user than the other. For example, regular expressions in Perl. It's built into the language, but that doesn't mean Python doesn't have regular expressions, just that Python is less centered around them. If you want to use regular expressions with Python just import re. -a -- http://mail.python.org/mailman/listinfo/python-list
Re: Blank Line at Program Exit
On Sat, Aug 22, 2009 at 11:25 PM, Nitebirdz nitebi...@sacredchaos.comwrote: On Thu, Aug 20, 2009 at 01:31:14PM +0800, Steven Woody wrote: Hi, Any python program, even that does absolutely nothing in the code, will cause a blank line printed out when the program exit. What's the reason? Thanks. Chances are it is related to whichever operating system and/or shell you are using. For instance, this is taken from a system running Ubuntu Linux 8.04: - laptop:$ cat hello.py #!/usr/bin/env python print Hello, there! laptop:$ ./hello.py Hello, there! laptop:$ cat nothing.py #!/usr/bin/env python laptop:$ ./nothing.py laptop:$ - As you can see, no blank line was printed out. -- http://mail.python.org/mailman/listinfo/python-list Hi, I am using cywin on XP. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com) -- http://mail.python.org/mailman/listinfo/python-list
How to distribute an application
Hi, My application contains a main python source file as well as a set of modules (also .py files). Now, I am considering distribute my application to others. But the distutils seems made for distributing packages not for main applications. Am I right? Thanks. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
On Aug 23, 6:35 am, n...@cam.ac.uk wrote: I am interested in surveying people who want to interoperate between Fortran and Python to find out what they would like to be able to do more conveniently, especially with regard to types not supported for C interoperability by the current Fortran standard. snip Python is still on my to do list, but I know I'll be interested in the following: 1) Do you want to use character strings of arbitrary length? Yes 2) Do you want to use Python classes with list members, where the length of the list is not necessarily fixed for all instances of the class? Or, equivalently, Fortran derived types containing allocatable or pointer arrays? Yes 2) Do you want to use Fortran derived types or Python classes that contain type-bound procedures (including finalizers)? Please answer yes whether or nor you would like to call those type-bound procedures from the other language. Don't know yet 4) Do you want to call functions where the called language allocates or deallocates arrays/lists/strings for use by the calling language? Note that this is specifically Fortran-Python and Python-Fortran. Yes agt -- Freedom - no pane, all gaiGN! Code Art Now http://codeartnow.com Email: a...@codeartnow.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary from a list
In article baa0d11c-c999-4eee-9cf5-90ad667f5...@b25g2000prb.googlegroups.com, EK eka...@gmail.com wrote: On Aug 20, 2:10=A0pm, Peter Otten __pete...@web.de wrote: from itertools import izip it =3D iter([1,2,3,4,5,6]) dict(izip(it, it)) {1: 2, 3: 4, 5: 6} dict(zip(*[iter(l)]*2)) No, that's not a good solution. For starters, it's less readable than Peter's version. More importantly, it has poor memory use because it needs to construct both the intermediate tuple and the zip() list. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ I support family values -- Addams family values --www.nancybuttons.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying octal notation
Dennis Lee Bieber wlfr...@ix.netcom.com writes: About the only place one commonly sees leading zeros on decimal numbers, in my experience, is zero-filled COBOL data decks (and since classic COBOL stores in BCD anyway... binary (usage is computational/comp-1) was a later add-on to the data specification model as I recall...) A more common case is dates. I've seen people trip over this writing things like xxx = [ date(2009, 10, 12), date(2009, 12, 26), date(2010, 02, 09), ] -M- -- http://mail.python.org/mailman/listinfo/python-list
Re: logging SMTPhandler Error
In article 60de8d40-61f4-4ffd-bcef-749bf0667...@k19g2000yqn.googlegroups.com, Bev in TX countryon...@yahoo.com wrote: On Aug 23, 12:48=A0am, a...@pythoncraft.com (Aahz) wrote: It's also not too difficult to do the moral equivalent with dnspython and find the MX host for the domain you're trying to send e-mail to; that usually does not require an encrypted connection. Thanks :-). I'm not sure that I understand exactly what needs to be done, but I'll read the documentation and see what I can come up with. Slightly expanded: most mail servers accept connections from any other mail server for addresses that are hosted by them. The MX address for a domain tells you what mail server hosts that address. By connecting directly to the MX, your script is essentially acting as a mail server itself. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ I support family values -- Addams family values --www.nancybuttons.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
garabik-news-2005...@kassiopeia.juls.savba.sk writes: Why not just use the space? 123 000 looks better than 123_000, and is not syntactically ambiguous (at least in python). And as it already works for string literals, it could be applied to numbers, too… +1 to all this. I think this discussion was had many months ago, but can't recall how it ended back then. -- \ “Only the educated are free.” —Epictetus, _Discourses_ | `\ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
n...@cam.ac.uk wrote: I am interested in surveying people who want to interoperate between Fortran and Python to find out what they would like to be able to do more conveniently, especially with regard to types not supported for C interoperability by the current Fortran standard. Any suggestions as to other ways that I could survey such people (Usenet is no longer as ubiquitous as it used to be) would be welcomed. You might want to ask also on the Cython, NumPy and SciPy mailing lists. NumPy and SciPy have a rather large audience of scientific developers, and Cython has a running sub-project on providing better Fortran integration (which might be of interest to you anyway). Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
I had an objection to using spaces in numeric literals last time around and it still stands, and it still stands in the new one. What happens if you use a literal like 0x10f 304? Is 304 treated as decimal or hexadecimal? It's not clear how you would begin to combine it The way string concatenation works, it takes two independent string literals, and combines them. If you specify r'\n' 'abc\n', the first half is treated independently as a raw string, and the second half is treated as a normal string. The result is '\\nabc\n'. With numeric literals, this behavior doesn't even make sense. How do you concatenate hex 10f with decimal 304? I suppose you could multiply 0x10f by 1000, and add them, but this probably wouldn't fit any practical usecase. Alternatively, you could raise an exception, and require the user to use numeric literals of the same type, like 0x10f 0x304, but then you lose any readability benefit you might have gained by dropping the _ to begin with. If, on the other hand, you want to combine the tokens before processing their independent meanings, which makes the most intuitive sense, well, in that case we're no longer talking about an operation analogous to string contcatenation. We're talking about integers no longer being simple tokens that can be assigned a value. I'm not familiar with the code that makes all this happen in C Python (or any other implementation for that matter), but it seems like it extends the complexity of the parser unnecessarily. I'm concerned that the benefit in readability will be outweighed by the burden it places on the parser, and the cognitive burden on the programmer of knowing what to expect when using non-decimal numeric literals. For that reason, I'm a -1 on using a space in numeric literals, but +1 on using some other separator, and an _, in spite of its slight awkwardness in typing, seems like a good idea. If someone with a solid understanding of the python parser could chime in that this wouldn't cause as much friction as I think, and explain a clean, elegant implementation for this, many of my concerns would be alleviated, and I would change my -1 to a -0. Cheers, Cliff On Mon, 2009-08-24 at 00:01 +1000, Ben Finney wrote: garabik-news-2005...@kassiopeia.juls.savba.sk writes: Why not just use the space? 123 000 looks better than 123_000, and is not syntactically ambiguous (at least in python). And as it already works for string literals, it could be applied to numbers, too… +1 to all this. I think this discussion was had many months ago, but can't recall how it ended back then. -- \ “Only the educated are free.” —Epictetus, _Discourses_ | `\ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile
Hi I've got my backup script which opens tarfile for add chosen file to it. But while setting it up, i've got Traceback: here's the url: --http://paste.ubuntu.com/258081/-- I have searched among google's result but didn't found anything useful. Only found info that it may be the backslashes fault in path, but i have written proper the path. Here's link to my script paste: http://paste.ubuntu.com/258087/ Is its the '|\U' literal fault in path '|C:\\Users\\Ryniek's WinSe7en\\MyNewGGBackup(2009-08-23 14:59:02).tar.bz2|' ? Sorry if i'm annoying but i'm still learning. | -- http://mail.python.org/mailman/listinfo/python-list
Trying To Catch Invalid User Input
Hi; I have the following: style = raw_input('What style is this? (1 = short, 2 = long): ') flag = 0 while flag == 0: if (style != 1) or (style != 2): style = raw_input('There was a mistake. What style is this? (1 = short, 2 = long): ') else: flag = 1 I would think this would catch errors and permit valid values, but it doesn't. If I enter an erroneous value the first time, and the second time a good value, it doesn't break the loop. Why? TIA, Victor -- http://mail.python.org/mailman/listinfo/python-list
Most active coroutine library project?
I've been taking a look at the multitude of coroutine libraries available for Python, but from the looks of the projects they all seem to be rather quiet. I'd like to pick one up to use on a current project but can't deduce which is the most popular/has the largest community. Libraries I looked at include: cogen, weightless, eventlet and circuits (which isn't exactly coroutine-based but it's event-driven model was intriguing). Firstly, are there any others I've missed? And what would the consensus be on the which has the most active community behind it? -- http://mail.python.org/mailman/listinfo/python-list
can python make web applications?
can python make powerfull database web applications that can replace desktop database applications? e.g: entrprise accounting programs,enterprise human resource management programs ...etc -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
On 23 Aug, 12:35, n...@cam.ac.uk wrote: I am interested in surveying people who want to interoperate between Fortran and Python to find out what they would like to be able to do more conveniently, especially with regard to types not supported for C interoperability by the current Fortran standard. Any suggestions as to other ways that I could survey such people (Usenet is no longer as ubiquitous as it used to be) would be welcomed. I think you will find that 99.9% of Python and Fortran programmers are scientists and engineers that also use NumPy and f2py. Go to scipy.org and ask your question on the numpy mailing list. Regards, Sturla Molden -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python what I need?
newbie wrote: I'm interested in developing computer based, interactive programs for students in a special school who have an aversion to pen and paper. I've searched the net to find ready made software that will meet my needs but it is either written to a level much higher than these students can cope with or priced beyond our school budget. I came across a blog of someone singing the praises of Python. My question is therefore aimed at those that know what they are talking about (ie users in this group). Is Python the language I need to learn to develop these programs? From the distance it looks like these children need a good teacher rather than a bad (or just starting) programmer. They need goals they can understand and share, not yet another tool. But it's interactive? Yeah, three canned answers instead of just one... That said, Python is a good language for the casual developer. You can whack together something pretty quickly. It may not be perfect, but you don't waste time on administrative overhead either. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying To Catch Invalid User Input
Victor Subervi wrote: Hi; I have the following: style = raw_input('What style is this? (1 = short, 2 = long): ') flag = 0 while flag == 0: if (style != 1) or (style != 2): style = raw_input('There was a mistake. What style is this? (1 = short, 2 = long): ') else: flag = 1 I would think this would catch errors and permit valid values, but it doesn't. If I enter an erroneous value the first time, and the second time a good value, it doesn't break the loop. Why? This is wrong: (style != 1) or (style != 2) For example, if style is 1 (which should be a valid value): (style != 1) or (style != 2) = (1 != 1) or (1 != 2) = Falseor True = True What you mean is: (style != 1) and (style != 2) -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying To Catch Invalid User Input
Victor Subervi wrote: Hi; I have the following: style = raw_input('What style is this? (1 = short, 2 = long): ') flag = 0 while flag == 0: if (style != 1) or (style != 2): style = raw_input('There was a mistake. What style is this? (1 = short, 2 = long): ') else: flag = 1 I would think this would catch errors and permit valid values, but it doesn't. If I enter an erroneous value the first time, and the second time a good value, it doesn't break the loop. Why? TIA, Victor First, raw_input will not return an integer, but rather characters, so the value of style will never be 1 or 2, but rather '1', or '2'. But even if you make your comparisons against '1' and '2', this will not work since you've also made a simple logic error. The conditional if (style != '1') or (style != '2'): will always be True no matter what value style has. For instance if style is '1', then the conditional evaluates like (False) or (True) which evaluates to True. You want one of the following: if (style != '1') and (style != '2'): or if not (style == '1' or style == '2'): or if style == '1' or style == '2': flag = 1 ... or if style in ['1','2']: flag = 1 ... or better yet dispense with flag altogether while style not in ['1','2']: style = raw_input('There was a mistake ... Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python what I need?
On Sun, 23 Aug 2009, newbie wrote: Hi all I'm interested in developing computer based, interactive programs for students in a special school who have an aversion to pen and paper. I've searched the net to find ready made software that will meet my needs but it is either written to a level much higher than these students can cope with or priced beyond our school budget. I came across a blog of someone singing the praises of Python. My question is therefore aimed at those that know what they are talking about (ie users in this group). Is Python the language I need to learn to develop these programs? Perhaps, maybe, yes. Python has simple syntax and it can be grasped quite fast. It is also quite easy IMHO to go from easy interactive, calculator-like stuff to bigger things. It also has quite big library of specialized functions, to be used in bigger programs. So if this is what you are looking for, it seems you are in the right place. You may also have a look at Squeak. It is an implementation of Smalltalk language. As far as I can tell, it is targeted for kid users or young students, who are interested in programming. http://en.wikipedia.org/wiki/Smalltalk http://www.squeak.org/ http://en.wikipedia.org/wiki/Squeak Or, I mean, Smalltalk is a general purpose language, just as Python. It is not a kid language. Squeak, however, seems to be a bit easier for new users. After tinkering with it a little, I think it has few batteries not only included (like Python has) but connected to few toys as well. This makes it more playable than Python after unpacking the box. Wrt languages, their goodness or differences between them - I am pretty much sure a number of people will start pointing them out to you. But I don't think this is really that much important. All languages are more or less similar because they serve the same purpose. Just try and do not use (Visual) Basic :-) and you should be ok. Well, maybe this is just me, but I consider VB to be a dead-end. Besides, if this is going to be let's show them how interesting it is, you should stay away from languages more complicated, like Java. Those who are going to learn Java, will learn it anyway. Knowing something different and cool first should not kill them. Quite the contrary, it can be an eye opener. Regards Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did rm -rif on the programmer's home** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
garabik-news-2005...@kassiopeia.juls.savba.sk wrote in message news:h6r4fb$18...@aioe.org... In comp.lang.python James Harris james.harri...@googlemail.com wrote: On 22 Aug, 10:27, David 71da...@libero.it wrote: ... What about 2_1011, 8_7621, 16_c26h or 2;1011, 8;7621, 16;c26h ? They look good - which is important. The trouble (for me) is that I want the notation for a new programming language and already use these characters. I have underscore as an optional separator for groups of digits - 123000 and 123_000 mean the same. Why not just use the space? 123 000 looks better than 123_000, and is not syntactically ambiguous (at least in python). If the purpose is to allow _ to introduce a non-base ten literal, using this to enter a hexadecimal number might result in: 16_1234 ABCD I'd say that that was ambiguous (depending on whether a name can follow a number; if you have a operator called ABCD, then that would be a problem). Unless each block of digits used it's own base: 16_1234 16_ABCD And as it already works for string literals, it could be applied to numbers, too… String literals are conveniently surround by quotes, so they're a bit easier to recognise. -- Bart -- http://mail.python.org/mailman/listinfo/python-list
Re: generate keyboard/mouse event under windows
Ray wrote: On Aug 19, 2:07 pm, yaka gu.yakahug...@gmail.com wrote: Read this and see if it helps: http://kvance.livejournal.com/985732.html is there a way to generate a 'true' keyboard event? (works like user pressed a key on keyboard) not send the 'send keyboard event to application' ? If there is such a spot, it is a major security weakness. You'd be able to automate password attacks. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying To Catch Invalid User Input
On Sun, 2009-08-23 at 16:36 +0100, MRAB wrote: Victor Subervi wrote: Hi; I have the following: style = raw_input('What style is this? (1 = short, 2 = long): ') flag = 0 while flag == 0: if (style != 1) or (style != 2): style = raw_input('There was a mistake. What style is this? (1 = short, 2 = long): ') else: flag = 1 I would think this would catch errors and permit valid values, but it doesn't. If I enter an erroneous value the first time, and the second time a good value, it doesn't break the loop. Why? This is wrong: (style != 1) or (style != 2) For example, if style is 1 (which should be a valid value): (style != 1) or (style != 2) = (1 != 1) or (1 != 2) = Falseor True = True What you mean is: (style != 1) and (style != 2) Or (perhaps) better: VALID_STYLES = {1: 'short', 2: 'long'} style = None while style not in VALID_STYLES: style = raw_input('What style is this? %s: ' % str(VALID_STYLES).replace(':', ' =')) # also, raw_input() returns a string try: style = int(style) except ValueError: pass -- http://mail.python.org/mailman/listinfo/python-list
Python-URL! - weekly Python news and links (Aug 23)
QOTW: ... [O]nce you accept that text is best handled in Unicode, there's little sense in making an exception for the limited subset that happens to be representable in ASCII. - Ben Finney http://groups.google.com/group/comp.lang.python/msg/accc8c2ae9d7ed15 Python 3.1.1 released: http://groups.google.com/group/comp.lang.python/t/f34c4b07a61f4414/ Parallelization in Python 2.6: http://groups.google.com/group/comp.lang.python/t/c8169c393e58a5d5/ 012=3D=3D10, a relic from ancient times, is finally gone: http://groups.google.com/group/comp.lang.python/t/3bc42fffb012635b/ How to ensure a method is actually implemented in a derived class: http://groups.google.com/group/comp.lang.python/t/42d0ec54b7683f23/ Is this community sexist? (Also, etymology of the word guy Guy ~ Guido) http://groups.google.com/group/comp.lang.python/t/7a190c24d8025bb4/ A for loop using range() is inefficient, but other Python variants are able to optimize it: http://groups.google.com/group/comp.lang.python/t/27df793be6f5675/ The scope of names inside a class statement: http://groups.google.com/group/comp.lang.python/t/4a244346dc9a5f15/ Counting how many times items from a set appear on a given list: http://groups.google.com/group/comp.lang.python/t/fb0580cefff96682/ Construct a dictionary from a list [key,value,key,value,...] (many recipes!): http://groups.google.com/group/comp.lang.python/t/e16e180b5f61f748/ And more recipes: format a number with thousand separators: http://groups.google.com/group/comp.lang.python/t/2eb729797f162a6e/ Code style: how to write a long conditional expression: http://groups.google.com/group/comp.lang.python/t/6876917a4d579d59/ On the concept of functor and how it may be applied to Python: http://groups.google.com/group/comp.lang.python/t/8fbc7ad2ec11841c/ Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish the efforts of Python enthusiasts: http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the Planet sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes podcasts ... to help people learn Python ... Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.orggroup=gmane.comp.python.develsort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=pythonShowStatus=all The old
Re: [Diversity] Language note
In article mailman.4473.1249755333.8015.python-l...@python.org, Rami Chowdhury rami.chowdh...@gmail.com wrote: Most indian languages have a different grammer (compared to English). So i'm curious to see how that would be implemented in a parser +1 -- I'd be interested in seeing this too, although we have drifted OT here and perhaps this conversation would be better had on Python- list. The closest I've seen to a language being able to support different grammatical structures is Perligata (http:// www.csse.monash.edu.au/~damian/papers/HTML/Perligata.html), does Python have anything similar? . . . Yes and no. There's considerably more to say on the subject than my own patience permits for now. Highlights, though: I regard it as a big deal whether a language permits Unicode in spelling variable names (Python 3 does, despite URL: http://mail.python.org/pipermail/idle-dev/2000-April/000133.html , and presumably you know the situation in Perl); languages like Lisp, Forth, and Tcl have minimal syntax, and rich traditions of construction of problem-specific little languages, so it's common in them to see, for example, object orientation modeled with a variety of lexical orders; and my own favorite little-language work in Python has generally modeled VSO human languages. -- http://mail.python.org/mailman/listinfo/python-list
Re: conditional for-statement
Hi, i was wondering if there is a syntax alike: for i in range(10) if i 5: print i You can write for i in filter(lambda i: i 5, range(10)): print i but for i in range(10): if i 5: print i it' better readable, and for i in range(6,10): print i it's event better. How about using a generator expression instead of a list? for i in (x for x in range(10) if x 5): print i -John -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying To Catch Invalid User Input
Really slick! Thanks! V On Sun, Aug 23, 2009 at 11:08 AM, Albert Hopkins mar...@letterboxes.orgwrote: On Sun, 2009-08-23 at 16:36 +0100, MRAB wrote: Victor Subervi wrote: Hi; I have the following: style = raw_input('What style is this? (1 = short, 2 = long): ') flag = 0 while flag == 0: if (style != 1) or (style != 2): style = raw_input('There was a mistake. What style is this? (1 = short, 2 = long): ') else: flag = 1 I would think this would catch errors and permit valid values, but it doesn't. If I enter an erroneous value the first time, and the second time a good value, it doesn't break the loop. Why? This is wrong: (style != 1) or (style != 2) For example, if style is 1 (which should be a valid value): (style != 1) or (style != 2) = (1 != 1) or (1 != 2) = Falseor True = True What you mean is: (style != 1) and (style != 2) Or (perhaps) better: VALID_STYLES = {1: 'short', 2: 'long'} style = None while style not in VALID_STYLES: style = raw_input('What style is this? %s: ' % str(VALID_STYLES).replace(':', ' =')) # also, raw_input() returns a string try: style = int(style) except ValueError: pass -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: can python make web applications?
On Aug 23, 8:12 pm, Deep_Feelings doctore...@gmail.com wrote: can python make powerfull database web applications that can replace desktop database applications? e.g: entrprise accounting programs,enterprise human resource management programs ...etc Very much so. The web frameworks, Django TurboGears are quite powerful and can be used to do what you just now mentioned. Check out Django - esp if the application is database centric. It has very good documentation and a free online book - djangobook. -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyxser-1.2r --- Python-Object to XML serialization module
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 Hello, I'm pleased to announce pyxser-1.2r, a Python-Object to XML serializer and deserializer. This module package it's completely written in C and licensed under LGPLv3. The tested Python versions are 2.5.X and 2.7.X. * home page: http://coder.cl/software/pyxser * hosted at: http://sourceforge.net/projects/pyxser/ * pypi entry: http://pypi.python.org/pypi?:action=displayname=pyxserversion=1.2r The current ChangeLog is as follows: - -8--8--8--8- 1.2r (2009.08.23): Daniel Molina Wegener d...@coder.cl * Added encoded serialization of Unicode strings by using the user defined encoding as is passed to the serialization functions as enc parameter * Refactored some functions to allow more ordered code. - -8--8--8--8- As you see, now Unicode strings are serialized as encoded byte string by using the encoding that the user pass as enc parameter to the serialization function. This means that Unicode strings are serialized in a human readable form, regarding a better interoperability with other platforms. Best regards... - -- .O. | Daniel Molina Wegener | FreeBSD Linux ..O | dmw [at] coder [dot] cl | Open Standards OOO | http://coder.cl/ | FOSS Developer -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (FreeBSD) iQIcBAEBCgAGBQJKkW/VAAoJEHxqfq6Y4O5N36oP/3iV+D9YUgLStFoZiJvb5b7x +UyrfyWpg6oxqeH4oOUVmyrWYlIaM3IStOtCayYEIrRJeg7FfHM8rvUV89FhDgVy xb/4R9UyqSOqcev/edmXvhbUKfOjUDu/kaKNjK4HiI3Ewh6BBjxbythZSQ/BcvGc OzAsZU9bACbuTuiYLumoum/KjRg/13Tzc8R+xhugJ7fjqH94kWGmUN8l8E/DU7O1 IULm4da4y4mPzhdyIxIGzncOGEZmQLLcv7jYcMVBvkuXe8Ar0WlGQ6YjyvQMLVlz KBn5JiNC1/gzImQXXDfT2u454gyH86i7BRtOCk0RbUmTVFsQ32wjnF0u4bngrtm7 3dD0WVIWV/n/27UZtYte3YlVoHzYu+M6TsX9vwhxvg4SHvg74XigXuXgD8vWQxGE FP6YENbHOND3oSNJIRO9368irvCbYrcpndtYBLyyDlfwdN5YTAME+Z5eEGvl4j4P D7aPryOKCzklxv33qtA1si6f//4JPqdKHGXnl8ysPC7QWh6u+ImmYFYj2kAu7l/N PfUvf8hfQqWOz53W4AuFGg5u+L29TIMUUvxc4r446SFdLUZEaHueJ5GQ0G8uNF/B QoWUnwynLlasyeo+JTcrG9NBgm85QfT3jDd+z4Zba9yWCqojymOpVCQ5duKifMb3 x9fc1ulI44AGNAv+UhnB =4C1g -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
[Followup-To: header set to comp.lang.fortran.] On 2009-08-23, n...@cam.ac.uk n...@cam.ac.uk wrote: I am interested in surveying people who want to interoperate between Fortran and Python to find out what they would like to be able to do more conveniently, especially with regard to types not supported for C interoperability by the current Fortran standard. Any suggestions as to other ways that I could survey such people (Usenet is no longer as ubiquitous as it used to be) would be welcomed. My Email address is real, so direct messages will be received. Specifically, I should like to know the answers to the following questions: 1) Do you want to use character strings of arbitrary length? As in, a signed C int (that most Fortran implementations use to keep track of string lengths) may not be sufficient? No, I'm not particularly interested in that. 2) Do you want to use Python classes with list members, where the length of the list is not necessarily fixed for all instances of the class? Or, equivalently, Fortran derived types containing allocatable or pointer arrays? Yes. 2) Do you want to use Fortran derived types or Python classes that contain type-bound procedures (including finalizers)? Please answer yes whether or nor you would like to call those type-bound procedures from the other language. In python I use it all the time, haven't used any F2003 OOP features yet. 4) Do you want to call functions where the called language allocates or deallocates arrays/lists/strings for use by the calling language? Note that this is specifically Fortran-Python and Python-Fortran. Yes. Generally speaking, f2py today is not that bad, though it's getting long in the tooth. There is a project called fwrap that aims to create an improved python/Fortran bridge: http://conference.scipy.org/static/wiki/smith_fwrap.pdf This project uses ISO_C_BINDING, and I think that this is the correct approach rather than trying to keep up with whatever ABI's all those Fortran compilers use. So from the Fortran side of the fence, I suppose the path forward would be to improve on the C binding functionality (this would also of course benefit other language bindings than just python). Whether TR 29113 is the right path forward or not I have no strong opinion on. Specifically what's needed is some way to portably access the array descriptor data, and maybe also how to access the OOP functionality in a standardized way. The experience with C++ ABI's suggests that this might not be as straightforward as it sounds. -- JB -- http://mail.python.org/mailman/listinfo/python-list
Re: Most active coroutine library project?
Phillip B Oldham phillip.old...@gmail.com writes: I've been taking a look at the multitude of coroutine libraries available for Python, but from the looks of the projects they all seem to be rather quiet. I'd like to pick one up to use on a current project but can't deduce which is the most popular/has the largest community. Libraries I looked at include: cogen, weightless, eventlet and circuits (which isn't exactly coroutine-based but it's event-driven model was intriguing). Firstly, are there any others I've missed? There's greenlets http://pypi.python.org/pypi/greenlet which I think is also fairly described as quiet. -M- -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying octal notation
On 21 Aug, 00:59, James Harris james.harri...@googlemail.com wrote: ... Is there some magic to make the 2.x CPython interpreter to ignore the annoying octal notation? I'd really like 012 to be 12 and not 10. This is (IMHO) a sad hangover from C (which took it from B ... This seemed worth writing up so I've taken the snipped comments and posted them at http://sundry.wikispaces.com/octal-zero-prefix The idea is that the page can be pointed to any time the issue comes up again. I've also fleshed the comments out a bit. James -- http://mail.python.org/mailman/listinfo/python-list
Re: Polling a net address
In article 99ddf4e1-d327-4fb1-aee4-aa881de3b...@d23g2000vbm.googlegroups.com, Iain i...@kandaba.com wrote: I'm writing a system tray application for windows, and the app needs to poll a remote site at a pre-defined interval, and then process any data returned. The GUI needs to remain responsive as this goes on, so the polling needs to be done in the background. I've been looking into Twisted as a way of achieving this, but can't seem to get anything to loop successfully. Does anyone have any pointers that they might be able to give me? You might prefer trying out threads instead; there's a simple Tkinter example in http://www.pythoncraft.com/OSCON2001/index.html -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ I support family values -- Addams family values --www.nancybuttons.com -- http://mail.python.org/mailman/listinfo/python-list
Re: can python make web applications?
Deep_Feelings wrote: can python make powerfull database web applications that can replace desktop database applications? e.g: entrprise accounting programs,enterprise human resource management programs ...etc In addition to the recommendations by other people, I'd like to recommend the very easy to learn and use web2py. (www.web2py.com). -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
In article slrnh92tp8.qcl@vipunen.hut.fi, JB f...@bar.invalid wrote: [Followup-To: header set to comp.lang.fortran.] Sorry - set back again, because you don't provide an Email address, and there's a significant issue. Thanks for the response. 1) Do you want to use character strings of arbitrary length? As in, a signed C int (that most Fortran implementations use to keep track of string lengths) may not be sufficient? No, I'm not particularly interested in that. No, I mean things like 'Kilroy was here'. Currently, Fortran's C interoperability supports only strings of length 1, and you have to kludge them up as arrays. That doesn't work very well, especially for things like function results. Generally speaking, f2py today is not that bad, though it's getting long in the tooth. There is a project called fwrap that aims to create an improved python/Fortran bridge: Thanks. I will look at that. This project uses ISO_C_BINDING, and I think that this is the correct approach rather than trying to keep up with whatever ABI's all those Fortran compilers use. So from the Fortran side of the fence, I suppose the path forward would be to improve on the C binding functionality (this would also of course benefit other language bindings than just python). Whether TR 29113 is the right path forward or not I have no strong opinion on. Specifically what's needed is some way to portably access the array descriptor data, and maybe also how to access the OOP functionality in a standardized way. The experience with C++ ABI's suggests that this might not be as straightforward as it sounds. That is precisely what I am investigating. TR 29113 falls a LONG way before it gets to any of the OOP data - indeed, you can't even pass OOP derived types as pure data (without even the functionality) in its model. Nor most of what else Python would expect. Regards, Nick Maclaren. -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions on XML
My problem is with IDLE on Windows. When I try to type Bangla directly into the IDLE window I only get '?' characters, and repr() fails with a UnicodeDecodeError. I expect, though, that that's because of my specific installation / Windows issues, as it works fine on Fedora 10... I do not get any problem in processing Hindi or Bangla or any Indian language in Python it is perfectly fine. I have no problems either -- my issues are with IDLE, and only on Windows. Rami Chowdhury Strangers are just friends who haven't had enough gin. -- Howdle's Saying 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) On Saturday 22 August 2009 13:27:02 SUBHABRATA BANERJEE wrote: Should I help you? If you answered my questions I am differing from your view I do not get any problem in processing Hindi or Bangla or any Indian language in Python it is perfectly fine. Best Regards, Subhabrata. On Sat, Aug 22, 2009 at 9:48 AM, Rami Chowdhury rami.chowdh...@gmail.comwrote: I am using primarily UTF-8 based strings, like Hindi or Bengali. Can I use Python to help me in this regard? I can say from experience that Python on Windows (at least, Python 2.5 on 32-bit Vista) works perfectly well with UTF-8 files containing Bangla. I have had trouble with working with the data in IDLE, however, which seems to prefer ASCII by default. - Rami Chowdhury Never assume malice when stupidity will suffice. -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) On Aug 21, 2009, at 19:15 , joy99 wrote: Dear Group, I like to convert some simple strings of natural language to XML. May I use Python to do this? If any one can help me, on this. I am using primarily UTF-8 based strings, like Hindi or Bengali. Can I use Python to help me in this regard? How can I learn good XML aspects of Python. If any one can kindly name me a book or URL. I am using Python2.6 on Windows XP with IDLE as GUI. Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Need cleanup advice for multiline string
Simon Brunning wrote: 2009/8/11 Robert Dailey: On Aug 11, 3:40 pm, Bearophile wrote: There are gals too here. It's a figure of speech. And besides, why would I want programming advice from a woman? lol. Thanks for the help. Give the attitudes still prevalent in our industry (cf http://tinyurl.com/c5nqju and many more), I'm sorry to say that I don't think this is funny. Me neither. I used to reply with comments like you just missed more than half of the world's population to people who started their postings with hi guys!, and I stopped doing that as a) it became too tiring, especially on a potentially-for-newbees group like c.l.py, and b) to many people it actually *is* a figure of speech. But reading statements like the above really makes me feel that it's best to comment even on simple things like hi guys!. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Need cleanup advice for multiline string
Jean-Michel Pichavant wrote: Grant Edwards wrote: On 2009-08-18, Simon Forman sajmik...@gmail.com wrote: Sexism, racism, homophobia, religious intolerance, etc., all stem from a fundamental forgetfulness of our Unity in God (as I would put it) and this is perhaps the single greatest cause of human misery. You mean the single greatest cause of human misery isn't Microsoft Windows? No, emacs is responsible ! Hail to Vi ! Heck, where's Godwin's law when you need it? Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Need cleanup advice for multiline string
Mensanator wrote: asking how many Jews you can fit into a Volswagen. None, because it's already full. (or voll as those who design Volkswagens would put it...) Stefan -- http://mail.python.org/mailman/listinfo/python-list
Is python faster than java?
I'm building a large application, kind of fancy python but I'm concerned about speed. Cheers Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining python and perl
On Aug 23, 8:00 am, Albert Hopkins mar...@letterboxes.org wrote: On Sun, 2009-08-23 at 05:37 -0700, Peng Yu wrote: Hi, According tohttp://www.python.org/doc/essays/comparisons.html, it says Python and Perl come from a similar background (Unix scripting, which both have long outgrown), and sport many similar features, but have a different philosophy. Perl emphasizes support for common application- oriented tasks, e.g. by having built-in regular expressions, file scanning and report generating features. Python emphasizes support for common programming methodologies such as data structure design and object-oriented programming, and encourages programmers to write readable (and thus maintainable) code by providing an elegant but not overly cryptic notation. As a consequence, Python comes close to Perl but rarely beats it in its original application domain; however Python has an applicability well beyond Perl's niche. My question is that how to combine both python and perl to take advantages of both their strong aspects. Of course, I want to primarily use python---that is why I send this message to this group. I'm not sure why you'd want to combine them. You can pretty much do the same things with both language, it's just that one may emphasize one thing or make it easier for the user than the other. For example, regular expressions in Perl. It's built into the language, but that doesn't mean Python doesn't have regular expressions, just that Python is less centered around them. If you want to use regular expressions with Python just import re. I understand that the sames things can be done with both language. But I do think that certain applications can be done faster (in term of the coding debugging time, I don't care runtime here) with one language than with another. Therefore, for any give problem, it is meaningful to decide, based on the time to write and debug the code, which part should be programmed with perl and which part should be programed with python. However, when I split the code in perl and python, the problem of the integration is introduced, which incur additional coding and maintenance cost. I am sure that somebody must has already encounter the similar situation like I described above. I am wondering whether there are any advices on how to take advantages of both languages to speed up the code development time and reduce maintenance cost. Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python faster than java?
On 8/23/2009 12:47 PM Raimond Garcia said... I'm building a large application, What kind of application? kind of fancy python but I'm concerned about speed. Speed of what? Development? User interaction? Responsiveness to queries? Mostly, you should worry about speed later. Writing it in python is probably faster than java. Then optimize the slow bits once you've identified where its needed. Emile -- http://mail.python.org/mailman/listinfo/python-list
web frameworks that support Python 3
I use Chinese and therefore Unicode very heavily, and so Python 3 is an unavoidable choice for me. But I'm frustrated by the fact that Django, Pylons, and TurboGears do not support Python 3 yet and (according to their development websites) will not for a very long time to come. So I am asking for recommendations for web frameworks that support Python 3. I am running Ubuntu 9.04 (Jaunty). Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile
Ryniek90 wrote: I've got my backup script which opens tarfile for add chosen file to it. But while setting it up, i've got Traceback: here's the url: --http://paste.ubuntu.com/258081/-- I have searched among google's result but didn't found anything useful. Only found info that it may be the backslashes fault in path, but i have written proper the path. Here's link to my script paste: http://paste.ubuntu.com/258087/ Is its the '|\U' literal fault in path '|C:\\Users\\Ryniek's WinSe7en\\MyNewGGBackup(2009-08-23 14:59:02).tar.bz2|' ? Sorry if i'm annoying but i'm still learning. It's probably a misleading error from the OS; I would guess the problem is that the filename contains colons, which I believe is a no-no on Windows. You want to make sure to always escape your backslashes (or use raw strings), too, or that's going to bite you sometime later (but it's not your main problem here). -- Erik Max Francis m...@alcyone.com http://www.alcyone.com/max/ San Jose, CA, USA 37 18 N 121 57 W AIM/Y!M/Skype erikmaxfrancis Every human being is a problem in search of a solution. -- Ashley Montague -- http://mail.python.org/mailman/listinfo/python-list
Re: web frameworks that support Python 3
On Sun, 2009-08-23 at 13:13 -0700, David Prager Branner wrote: I use Chinese and therefore Unicode very heavily, and so Python 3 is an unavoidable choice for me. But I'm frustrated by the fact that Django, Pylons, and TurboGears do not support Python 3 yet and (according to their development websites) will not for a very long time to come. So I am asking for recommendations for web frameworks that support Python 3. I am running Ubuntu 9.04 (Jaunty). Python 2.x has Unicode. In fact Django and the like use unicode heavily. What's different about Python 3 is that there is only unicode strings, whereas Python 2 has a string type and a unicode type. So it's not true that Python 3 is an unavoidable choice for using unicode. -- http://mail.python.org/mailman/listinfo/python-list
Re: web frameworks that support Python 3
At Sunday 23 August 2009 22:13:16 you wrote: I use Chinese and therefore Unicode very heavily, and so Python 3 is an unavoidable choice for me. Python 2.x supports Unicode just as well as Python 3. Every common web framework works perfectly with unicode. In any case, there is bottle [1], which provides a *very minimal* framework for WSGI web development. Don't expect too much, it is really small, and doesn't do much more than routing and minimal templating. However, it is the only Python-3-compatible web framework I know of. [1] http://bottle.paws.de/page/start -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) signature.asc Description: This is a digitally signed message part. -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining python and perl
On Sun, 2009-08-23 at 12:54 -0700, Peng Yu wrote: I understand that the sames things can be done with both language. But I do think that certain applications can be done faster (in term of the coding debugging time, I don't care runtime here) with one language than with another. Yes, and usually that application is written in that language *or* the other. Therefore, for any give problem, it is meaningful to decide, based on the time to write and debug the code, which part should be programmed with perl and which part should be programed with python. However, when I split the code in perl and python, the problem of the integration is introduced, which incur additional coding and maintenance cost. Couldn't agree more. I am sure that somebody must has already encounter the similar situation like I described above. I am wondering whether there are any advices on how to take advantages of both languages to speed up the code development time and reduce maintenance cost. Perhaps you need to give more specific criteria. I've worked on a few projects where different languages are used, but in different domains. For example, the client may be written in Python but the server written in Java or PHP. Or different subsystems written in different languages. For example, the workflow engine may be written in Python but the batch processor written in C. However in these cases, for the most part, the systems themselves are monolingual though they communicate with each other using well-defined, common interfaces (e.g. TCP/IP, XMLRPC, HL7, etc.). If, however, you are thinking of writing a sub-system in multiple languages (ala permodule, for example), you are in for a world of hurt. Not only will the code be difficult to maintain yourself, it will be difficult for others to maintain/understand it. Most people don't say things like Well I'm going to write all the 'object' stuff in Python but all the string processing in Perl. What usually motivates people to write systems in multiple languages are: * Availability of third-party libraries in a certain language. * Combining separate systems written in different languages. * Developer's capabilities in one language or the other * External dependencies (e.g. need to to have a plugin system for people to program in Python). * Performance. * Other types of glue (e.g. installation scripts need to be written in Perl, test system is Java based so CI scripts need to be in Java). permodule is nice for simple or one-off kind of stuff (or for any of the above reasons). But any reasonably-sized application using something like that throughout is going to be a maintenance nightmare. -- http://mail.python.org/mailman/listinfo/python-list
Re: conditional for-statement
On Aug 23, 6:18 pm, John Posner jjpos...@optimum.net wrote: Hi, i was wondering if there is a syntax alike: for i in range(10) if i 5: print i You can write for i in filter(lambda i: i 5, range(10)): print i but for i in range(10): if i 5: print i it' better readable, and for i in range(6,10): print i it's event better. How about using a generator expression instead of a list? for i in (x for x in range(10) if x 5): print i -John Indeed, but we could have the same syntax than for generators but directly in the for statement as in for variable in generator if condition: body Is there a special reason for not doing so ? A rejected PEP ? -- http://mail.python.org/mailman/listinfo/python-list
Re: web frameworks that support Python 3
David Prager Branner wrote: I use Chinese and therefore Unicode very heavily, and so Python 3 is an unavoidable choice for me. As others noted before, this statement is not true by itself. But I'm frustrated by the fact that Django, Pylons, and TurboGears do not support Python 3 yet and (according to their development websites) will not for a very long time to come. http://wiki.python.org/moin/PortingDjangoTo3k Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: can python make web applications?
A lot check this fantastic open source application, http://www.openerp.com, all done is python. On 8/23/09, Stefaan Himpe stefaan.hi...@gmail.com wrote: Deep_Feelings wrote: can python make powerfull database web applications that can replace desktop database applications? e.g: entrprise accounting programs,enterprise human resource management programs ...etc In addition to the recommendations by other people, I'd like to recommend the very easy to learn and use web2py. (www.web2py.com). -- http://mail.python.org/mailman/listinfo/python-list -- Sent from my mobile device -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python faster than java?
Makes sense. +1 Cheers Peter On Sun, Aug 23, 2009 at 9:59 PM, Emile van Sebille em...@fenx.com wrote: On 8/23/2009 12:47 PM Raimond Garcia said... I'm building a large application, What kind of application? kind of fancy python but I'm concerned about speed. Speed of what? Development? User interaction? Responsiveness to queries? Mostly, you should worry about speed later. Writing it in python is probably faster than java. Then optimize the slow bits once you've identified where its needed. Emile -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: conditional for-statement
On Aug 23, 10:36 pm, seb sdemen...@gmail.com wrote: On Aug 23, 6:18 pm, John Posner jjpos...@optimum.net wrote: Hi, i was wondering if there is a syntax alike: for i in range(10) if i 5: print i You can write for i in filter(lambda i: i 5, range(10)): print i but for i in range(10): if i 5: print i it' better readable, and for i in range(6,10): print i it's event better. How about using a generator expression instead of a list? for i in (x for x in range(10) if x 5): print i -John Indeed, but we could have the same syntax than for generators but directly in the for statement as in for variable in generator if condition: body Is there a special reason for not doing so ? A rejected PEP ?- Hide quoted text - - Show quoted text - I just found the same thread on the python ideas group at http://mail.python.org/pipermail/python-ideas/2009-April/004278.html sorry for reposting -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
On 23 Aug, 04:38, c...@tiac.net (Richard Harter) wrote: On Sat, 22 Aug 2009 14:54:41 -0700 (PDT), James Harris james.harri...@googlemail.com wrote: On 22 Aug, 10:27, David 71da...@libero.it wrote: ... (snipped a discussion on languages and other systems interpreting numbers with a leading zero as octal) Either hexadecimal should have been 0h or octal should have been 0t :=3D) I have seen the use of Q/q instead in order to make it clearer. I still prefer Smalltalk's 16rFF and 8r377. Two interesting options. In a project I have on I have also considered using 0q as indicating octal. I maybe saw it used once somewhere else but I have no idea where. 0t was a second choice and 0c third choice (the other letters of oct). 0o should NOT be used for obvious reasons. So you are saying that Smalltalk has base in decimalrnumber where r is presumably for radix? That's maybe best of all. It preserves the syntactic requirement of starting a number with a digit and seems to have greatest flexibility. Not sure how good it looks but it's certainly not bad. I opine that a letter is better; special characters are a valuable piece of real estate. Very very true. However for floating point you need at least three letters because a floating point number has three parts: the fixed point point, the exponent base, and the exponent. Now we can represent the radices of the individual parts with the 'r'scheme, e.g., 2r101001, but we need separate letters to designate the exponent base and the exponent. B and E are the obvious choices, though we want to be careful about a confusion with 'b' in hex. For example, using 'R', 3R20.1B2E16Rac Ooh err! is 20.1 in trinary (6 1/3) times 2**172 (hex ac). I grant that this example looks a bit gobbledegookish, You think? :-) but normal usage would be much simpler. The notation doesn't handle balanced trinary; however I opine that balanced trinary requires special notation. When the programmer needs to construct such values how about allowing him or her to specify something like (20.1 in base 3) times 2 to the power of 0xac Leaving out how to specify (20.1 in base 3) for now this could be (20.1 in base 3) * 2 ** 0xac The compiler could convert this to a constant. James -- http://mail.python.org/mailman/listinfo/python-list
Re: conditional for-statement
On Sun, Aug 23, 2009 at 1:36 PM, sebsdemen...@gmail.com wrote: On Aug 23, 6:18 pm, John Posner jjpos...@optimum.net wrote: Hi, i was wondering if there is a syntax alike: for i in range(10) if i 5: print i You can write for i in filter(lambda i: i 5, range(10)): print i but for i in range(10): if i 5: print i it' better readable, and for i in range(6,10): print i it's event better. How about using a generator expression instead of a list? for i in (x for x in range(10) if x 5): print i -John Indeed, but we could have the same syntax than for generators but directly in the for statement as in for variable in generator if condition: body Is there a special reason for not doing so ? A rejected PEP ? It's not been added since it's completely unnecessary (see the several alternatives already presented by others). There have been a few other mailinglist threads on adding essentially the same syntax. None have proved fruitful. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
On 23 Aug, 00:16, Mel mwil...@the-wire.com wrote: James Harris wrote: I have no idea why Ada which uses the # also apparently uses it to end a number 2#1011#, 8#7621#, 16#c26b# Interesting. They do it because of this example from http://archive.adaic.com/standards/83rat/html/ratl-02-01.html#2.1: Thanks for providing an explanation. 2#1#E8 -- an integer literal of value 256 where the E prefixes a power-of-2 exponent, and can't be taken as a digit of the radix. That is to say 16#1#E2 would also equal 256, since it's 1*16**2 . Here's another suggested number literal format. First, keep the familar 0x and 0b of C and others and to add 0t for octal. (T is the third letter of octal as X is the third letter of hex.) The numbers above would be 0b1011, 0t7621, 0xc26b Second, allow an arbitrary number base by putting base and number in quotes after a zero as in 02:1011, 08:7621, 016:c26b This would work for arbitrary bases and allows an exponent to be tagged on the end. It only depends on zero followed by a quote mark not being used elsewhere. Finally, although it uses a colon it doesn't take it away from being used elsewhere in the language. Another option: 0.(2:1011), 0.(8:7621), 0.(16:c26b) where the three characters 0.( begin the sequence. Comments? Improvements? James -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
On 23 Aug, 21:55, James Harris james.harri...@googlemail.com wrote: ... However for floating point you need at least three letters because a floating point number has three parts: the fixed point point, the exponent base, and the exponent. Now we can represent the radices of the individual parts with the 'r'scheme, e.g., 2r101001, but we need separate letters to designate the exponent base and the exponent. B and E are the obvious choices, though we want to be careful about a confusion with 'b' in hex. For example, using 'R', 3R20.1B2E16Rac Ooh err! is 20.1 in trinary (6 1/3) times 2**172 (hex ac). I grant that this example looks a bit gobbledegookish, You think? :-) but normal usage would be much simpler. The notation doesn't handle balanced trinary; however I opine that balanced trinary requires special notation. When the programmer needs to construct such values how about allowing him or her to specify something like (20.1 in base 3) times 2 to the power of 0xac Leaving out how to specify (20.1 in base 3) for now this could be (20.1 in base 3) * 2 ** 0xac Using the suggestion from another post would convert this to 0.(3:20.1) * 2 ** 0xac The compiler could convert this to a constant. -- http://mail.python.org/mailman/listinfo/python-list
__import__(x) VS __import__(x, {}, {}, [''])
I am trying to understand the difference between __import__(x) and __import__(x, {}, {}, ['']). The documentations wording was a bit weird for me to understand: The standard implementation does not use its locals argument at all, and uses its globals only to determine the package context of the import statement. Does that mean it passes in the globals by default, or does the above statement stand true only if globals() is passed in? -- http://mail.python.org/mailman/listinfo/python-list
What is the recommended library for xml parsing?
Is there a good build in library or should I use a third party one? Cheers, Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: conditional for-statement
seb wrote: On Aug 23, 6:18 pm, John Posner jjpos...@optimum.net wrote: [ ... ] How about using a generator expression instead of a list? for i in (x for x in range(10) if x 5): print i -John Indeed, but we could have the same syntax than for generators but directly in the for statement as in for variable in generator if condition: body Is there a special reason for not doing so ? A rejected PEP ? Well, the Zen of Python does say There should be one-- and preferably only one --obvious way to do it. Beyond that, I refer you to Gerald M. Weinberg's _The Psychology of Computer Programming_, specifically chapters 11 and 12, about Programming Languages, and their design. The proposal creates an case where one particular pair of syntactic constructs can be mooshed together. OK for them, but everything else becomes an exception; what about while a==c if b != d: why not if b != d while a==c: or for a in range(7) if os.name == 'posix': It winds up burdening the programmers with remembering which constructs are and which are not mooshable. Weinberg gave an example: FORTRAN had some stringent rules for what expressions were and were not allowed as array subscripts. The result was that many programmers couldn't remember all the rules, and often avoided using legal forms, having forgotten they were legal. Maybe the line was already crossed when list comprehensions came into being, still, the damage is localized in a particular context: building a list. It isn't out creating wild options in the program control flow at large. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
James Harris wrote: On 23 Aug, 00:16, Mel mwil...@the-wire.com wrote: James Harris wrote: I have no idea why Ada which uses the # also apparently uses it to end a number 2#1011#, 8#7621#, 16#c26b# Interesting. They do it because of this example from http://archive.adaic.com/standards/83rat/html/ratl-02-01.html#2.1: Thanks for providing an explanation. 2#1#E8-- an integer literal of value 256 where the E prefixes a power-of-2 exponent, and can't be taken as a digit of the radix. That is to say 16#1#E2 would also equal 256, since it's 1*16**2 . Here's another suggested number literal format. First, keep the familar 0x and 0b of C and others and to add 0t for octal. (T is the third letter of octal as X is the third letter of hex.) The numbers above would be 0b1011, 0t7621, 0xc26b Second, allow an arbitrary number base by putting base and number in quotes after a zero as in 02:1011, 08:7621, 016:c26b Why not just put the base first, followed by the value in quotes: 21011, 87621, 16c26b This would work for arbitrary bases and allows an exponent to be tagged on the end. It only depends on zero followed by a quote mark not being used elsewhere. Finally, although it uses a colon it doesn't take it away from being used elsewhere in the language. Another option: 0.(2:1011), 0.(8:7621), 0.(16:c26b) where the three characters 0.( begin the sequence. Comments? Improvements? -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
James Harris wrote:... Another option: 0.(2:1011), 0.(8:7621), 0.(16:c26b) where the three characters 0.( begin the sequence. Comments? Improvements? I did a little interpreter where non-base 10 numbers (up to base 36) were: .7.100 == 64 (octal) .9.100 == 100 (decimal) .F.100 == 256 (hexadecimal) .1.100 == 4 (binary) .3.100 == 9 (trinary) .Z.100 == 46656 (base 36) Advantages: Tokenizer can recognize chunks easily. Not visually too confusing, No issue of what base the base indicator is expressed in. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: logging SMTPhandler Error
In article mailman.290.1251065005.2854.python-l...@python.org, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On 23 Aug 2009 06:14:00 -0700, a...@pythoncraft.com (Aahz) declaimed the following in gmane.comp.python.general: Slightly expanded: most mail servers accept connections from any other mail server for addresses that are hosted by them. The MX address for a domain tells you what mail server hosts that address. By connecting directly to the MX, your script is essentially acting as a mail server itself. But is not possible if one's ISP blocks pass-through SMTP connections. Correct, but the OP said that zir ISP did not have a mailserver; AFAIK all ISPs that block SMTP have their own mailserver that you can point at instead. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ I support family values -- Addams family values --www.nancybuttons.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended library for xml parsing?
On Sun, Aug 23, 2009 at 3:07 PM, Raimond Garciavoodoorai2...@gmail.com wrote: Is there a good build in library or should I use a third party one? xml.etree.ElementTree: http://docs.python.org/library/xml.etree.elementtree.html Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
Scott David Daniels scott.dani...@acm.org wrote in message news:kn2dnszr5b0bwazxnz2dnuvz_s-dn...@pdx.net... James Harris wrote:... Another option: 0.(2:1011), 0.(8:7621), 0.(16:c26b) where the three characters 0.( begin the sequence. Comments? Improvements? I did a little interpreter where non-base 10 numbers (up to base 36) were: .7.100 == 64 (octal) .9.100 == 100 (decimal) .F.100 == 256 (hexadecimal) .1.100 == 4 (binary) .3.100 == 9 (trinary) .Z.100 == 46656 (base 36) Advantages: Tokenizer can recognize chunks easily. Not visually too confusing, No issue of what base the base indicator is expressed in. It can be assumed however that .9. isn't in binary? That's a neat idea. But an even simpler scheme might be: .octal.100 .decimal.100 .hex.100 .binary.100 .trinary.100 until it gets to this anyway: .thiryseximal.100 -- Bartc -- http://mail.python.org/mailman/listinfo/python-list
Re: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile
Erik Max Francis max at alcyone.com writes: Ryniek90 wrote: Is its the '|\U' literal fault in path '|C:\\Users\\Ryniek's WinSe7en\\MyNewGGBackup(2009-08-23 14:59:02).tar.bz2|' ? What is the '|\U' literal fault ??? It's probably a misleading error from the OS; I would guess the problem is that the filename contains colons, which I believe is a no-no on Windows. The colons are the problem. The error message is not from the OS; it is concocted by Python (see fileobject.c) as what appears to be the best possible text given vague error reporting by Windows. I don't understand probably a misleading error [message] -- invalid mode (actual value) or filename - invalid something-obviously-not-invalid or filename - invalid filename -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
On 23 Aug, 20:42, n...@cam.ac.uk wrote: That is precisely what I am investigating. TR 29113 falls a LONG way before it gets to any of the OOP data - indeed, you can't even pass OOP derived types as pure data (without even the functionality) in its model. Nor most of what else Python would expect. I am note sure what you mean. This has the same ABI: typedef struct { int m, n; float r; } myctype; use iso_c_binding type, bind(c) :: myftype integer(c_int) :: m, n real(c_float) :: s end type You thus can pass derived types between C and Fortran. -- http://mail.python.org/mailman/listinfo/python-list
Newbie: list comprehension troubles..
Hi, I'm trying to replace this... # this works but there must be a more pythonic way, right? tlist = [] for obj in self.objs: t = obj.intersect(ray) if (t != None): tlist.append((obj,t)) with a list comprehension- can it be done? What I need to do is iterate over a list of graphics primitives and call their intersect method. If the returned t value is not None then I want to store the obj refernence and its t value in a list of tuples for further processing. I've tried stuff like ... tlist = [(obj,t) for obj,t in (self.objs, obj.intersect(ray)) if (t != None)] tlist = [(obj,t) for obj in self.objs for t in obj.intersect (ray) ] print ,len(tlist), tlist but they don't work. Any help greatly appreciated. matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: list comprehension troubles..
On Sun, Aug 23, 2009 at 4:27 PM, mmmatta...@gmail.com wrote: Hi, I'm trying to replace this... # this works but there must be a more pythonic way, right? tlist = [] for obj in self.objs: t = obj.intersect(ray) if (t != None): tlist.append((obj,t)) with a list comprehension- can it be done? Yes: tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in self.objs) if pair[1] is not None] Should it be done? Probably not. It's less readable and less efficient. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
On 24 Aug, 00:02, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: That's a C language problem -- since a string in C is just an array of character. The last FORTRAN dialect (and implementation) I used passed strings On 24 Aug, 00:02, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: values -- FORTRAN strings were typically static, the called function could not reallocate to fit in longer data and update the descriptor to match) It is possible to pass an arbitrary length. You have to convert a pointer from C to Fortran: subroutine foobar(cstr) bind(c, name='foobar') use, intrinsic :: iso_c_binding type(c_ptr) :: cstr character(*), pointer :: fstr call c_f_pointer(cptr, fptr) If you need the length, call strlen from libc. I think the OP has misunderstood how the Fortran 2003 C bindings work. They don't convert C pointers to Fortran strings or Fortran arryas. They convert C pointers to Fortran pointers. Sturla -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: list comprehension troubles..
Chris Rebert wrote: On Sun, Aug 23, 2009 at 4:27 PM, mmmatta...@gmail.com wrote: Hi, I'm trying to replace this... # this works but there must be a more pythonic way, right? 'Pythonic' is readable, if nothing else tlist = [] for obj in self.objs: t = obj.intersect(ray) if (t != None): tlist.append((obj,t)) This, to me, is more readable than the lc replacement. with a list comprehension- can it be done? Yes: tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in self.objs) if pair[1] is not None] Should it be done? Probably not. It's less readable and less efficient. I agree. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
On 24 Aug, 01:59, sturlamolden sturlamol...@yahoo.no wrote: subroutine foobar(cstr) bind(c, name='foobar') use, intrinsic :: iso_c_binding type(c_ptr) :: cstr character(*), pointer :: fstr call c_f_pointer(cptr, fptr) Which means that you can write a wrapper in Fortran callable from C, that calls a Fortran routine you want to expose: subroutine wrap_foobar(cstr) bind(c, name='foobar') use, intrinsic :: iso_c_binding type(c_ptr) :: cstr character(*), pointer :: fstr call c_f_pointer(cptr, fptr) call foobar(fstr) end subroutine subroutine foobar(fstr) character(*) :: fstr ! whatever end subroutine This by the way is how wrap exposes Fortran functions to Cython. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: list comprehension troubles..
Chris Rebert c...@rebertia.com writes: tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in self.objs) if pair[1] is not None] Should it be done? Probably not. [Compared to a ‘for’ suite with an ‘if’ suite, it's] less readable and less efficient. I disagree on the “less efficient”, unless you've measured it. The Python compiler and machine make list comprehensions and generator expressions turn into quite efficient code. I also disagree on “less readable”, if you show the structure and choose meaningful names (I can only guess at the meaning from the OP's code):: tribbles = [ (obj, tribble) for (obj, tribble) in ( (obj, obj.intersect(ray)) for obj in self.objs) if tribble is not None] -- \ “I must say that I find television very educational. The minute | `\ somebody turns it on, I go to the library and read a book.” | _o__)—Groucho Marx | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Protecting against callbacks queuing up?
Hello I'm using Python for S60 1.9.7 on my Nokia phone. I've made a program that gets input from an accelerometer sensor, and then calculates some stuff and displays the result. The sensor framework API does a callback to a function defined by me, every time new data is available. The problem is, that sometimes, the calculations may take longer than others, but if the callback is called before the first calculation is done, it seems like it's queuing up all the callbacks, and execute them sequentially, afterwards. What I need, is to simply ignore the callback, if the previous call hasn't finished it's operations before it's called again. I thought that this code would do the trick, but it obviously doesn't help at all, and i can't understand why... def doCallback(self): if self.process_busy==False: self.process_busy=True self.data_callback() self.process_busy=False doCallback is defined as a callback function for the accelerometer instance, and data_callback does some calculations and show them on the display of the phone. What to do? Thanks... -- http://mail.python.org/mailman/listinfo/python-list
Re: Need cleanup advice for multiline string
On Sun, 23 Aug 2009 20:52:16 +0200, Stefan Behnel wrote: Simon Brunning wrote: 2009/8/11 Robert Dailey: On Aug 11, 3:40 pm, Bearophile wrote: There are gals too here. It's a figure of speech. And besides, why would I want programming advice from a woman? lol. Thanks for the help. Give the attitudes still prevalent in our industry (cf http://tinyurl.com/c5nqju and many more), I'm sorry to say that I don't think this is funny. Me neither. I used to reply with comments like you just missed more than half of the world's population to people who started their postings with hi guys!, If you start your post with Hi guys, you've missed more than EIGHTY percent of the world's population, namely the 5.5 to 6 billion people who speak no English. To say nothing of the 99.9% of the world's population who couldn't help you with your query, even if they spoke English, and even if they were on the Internet. In that case, missing out on the small percentage of English-speaking women who don't know that guys has become sexless probably doesn't matter. (I'm amused and somewhat perplexed that somebody with the non-English name of Stefan, writing from a .de email address, seems to be assuming that (1) everybody is on the Internet, and (2) everybody on the Internet speaks English. Awareness of sexism is a good thing, but so is awareness of cultural chauvinism.) and I stopped doing that as a) it became too tiring, especially on a potentially-for-newbees group like c.l.py, and b) to many people it actually *is* a figure of speech. But reading statements like the above really makes me feel that it's best to comment even on simple things like hi guys!. Or you could enter the 21 century and understand that guys has become a generic term for people of any sex. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Protecting against callbacks queuing up?
Esben von Buchwald wrote: Hello I'm using Python for S60 1.9.7 on my Nokia phone. I've made a program that gets input from an accelerometer sensor, and then calculates some stuff and displays the result. The sensor framework API does a callback to a function defined by me, every time new data is available. The problem is, that sometimes, the calculations may take longer than others, but if the callback is called before the first calculation is done, it seems like it's queuing up all the callbacks, and execute them sequentially, afterwards. What I need, is to simply ignore the callback, if the previous call hasn't finished it's operations before it's called again. I thought that this code would do the trick, but it obviously doesn't help at all, and i can't understand why... def doCallback(self): if self.process_busy==False: self.process_busy=True self.data_callback() self.process_busy=False doCallback is defined as a callback function for the accelerometer instance, and data_callback does some calculations and show them on the display of the phone. If it is, in fact, queuing the callbacks then that means that it's just recording that the callback needs to be called, but doesn't actually do it while a previous one is in effect, ie it'll wait for the current call to return before doing the next one. What to do? Thanks... If you want to try multithreading you could make the callback just trigger the actual action in another thread. The other thread could wait for an event, perform the calculation, then clear any pending events before waiting again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
On 24 Aug, 02:26, nos...@see.signature (Richard Maine) wrote: You missed the word OOP, which seemed like the whole point. Not that the particular word is used in the Fortran standard, but it isn't hard to guess that he means a derived type that uses some of the OOP features. Inheritance, polymorphism, and type-bound procedure (aka methods in some other languages) come to mind. But C is not OOP. The ISO C bindings in Fortran are not ISO C++ bindings. This is for a reason: C++ does not have a standard ABI like ISO C. -- http://mail.python.org/mailman/listinfo/python-list
Re: install package in a particular python version
On Thu, 20 Aug 2009 20:53:18 -0700 (PDT), Steve1234 sflen...@comcast.net wrote: Benjamin suggested: sudo python2.5 setup.py install and it works. This makes sense, thanks. I downloaded pythonpkgmgr from source and installed it. I got the error that reguired wx package was missing. I couldn't find this package for Linux or source. That's wxpython. You'll need to look at http://www.wxpython.org/download.php#binaries David -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: list comprehension troubles..
On Sun, Aug 23, 2009 at 5:09 PM, Ben Finneyben+pyt...@benfinney.id.au wrote: Chris Rebert c...@rebertia.com writes: tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in self.objs) if pair[1] is not None] Should it be done? Probably not. [Compared to a ‘for’ suite with an ‘if’ suite, it's] less readable and less efficient. I disagree on the “less efficient”, unless you've measured it. The Python compiler and machine make list comprehensions and generator expressions turn into quite efficient code. Well, I hadn't benchmarked it originally, but since you bring it up: class Foo(object): def __init__(self, n): self.n = n def intersect(self, ray): return ray + self.n objs = [Foo(n) for n in range(300)] ray = 42 def listcomp(objs, ray): tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in objs) if pair[1] is not None] def naive(objs, ray): tlist = [] for obj in objs: t = obj.intersect(ray) if t is not None: tlist.append((obj,t)) ch...@morpheus Desktop $ python Python 2.6.2 (r262:71600, May 14 2009, 16:34:51) [GCC 4.0.1 (Apple Inc. build 5484)] on darwin ch...@morpheus Desktop $ python -m timeit -n 1 -s 'from tmp import naive, ray, objs' 'naive(objs, ray)' 1 loops, best of 3: 227 usec per loop ch...@morpheus Desktop $ python -m timeit -n 1 -s 'from tmp import listcomp, ray, objs' 'listcomp(objs, ray)' 1 loops, best of 3: 254 usec per loop The numbers for each test stayed within a few usec of each other over a few runs. I thus conclude that the list comprehension method is indeed slower (which makes sense looking at the 2 algorithms). I also disagree on “less readable”, if you show the structure and choose meaningful names (I can only guess at the meaning from the OP's code):: tribbles = [ (obj, tribble) for (obj, tribble) in ( (obj, obj.intersect(ray)) for obj in self.objs) if tribble is not None] I do concede it becomes somewhat more readable if split over multiple lines: pairs = ((obj, obj.intersect(ray)) for obj in self.objs) tlist = [pair for pair in pairs if pair[1] is not None] Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
sturlamolden sturlamol...@yahoo.no wrote: On 24 Aug, 02:26, nos...@see.signature (Richard Maine) wrote: You missed the word OOP, which seemed like the whole point. Not that the particular word is used in the Fortran standard, but it isn't hard to guess that he means a derived type that uses some of the OOP features. Inheritance, polymorphism, and type-bound procedure (aka methods in some other languages) come to mind. But C is not OOP. The ISO C bindings in Fortran are not ISO C++ bindings. This is for a reason: C++ does not have a standard ABI like ISO C. That seems irrelevant to the question originally asked, which was Do you want to use Fortran derived types or Python classes that contain type-bound procedures (including finalizers)? Yes, it is no surprise that the C interop stuff fails to address this, since it isn't in C. Something different/extra would be needed, which is exactly what Nick said. I'm going to jump out of the middle of this now. The only reason I jumped in was to point out the gap in communication, where Nick said that the TR doesn't handle OOP derived types and you replied that it does so do derived types, omitting the OOP part, which was clearly (to me) Nick's whole point. However, I don't seem to be facilitating the communication, as the replies just seem to be wandering farther afield, or maybe it is around in a circle. I think you just explained that the ISO C bindings in Fortran don't handle what Nick is asking about... but that somehow this makes it puzzling that Nick also says that they don't handle it. Well, I'll leave it to Nick and you, I guess. I'm lost. -- Richard Maine| Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric literals in other than base 10 - was Annoying octal notation
bartc ba...@freeuk.com wrote: Scott David Daniels scott.dani...@acm.org wrote in message news:kn2dnszr5b0bwazxnz2dnuvz_s-dn...@pdx.net... James Harris wrote:... Another option: It can be assumed however that .9. isn't in binary? That's a neat idea. But an even simpler scheme might be: .octal.100 .decimal.100 .hex.100 .binary.100 .trinary.100 until it gets to this anyway: .thiryseximal.100 At some point, abandoning direct support for literals and just having a function that can handle different bases starts to make a lot of sense to me: int('100', 8) 64 int('100', 10) 100 int('100', 16) 256 int('100', 2) 4 int('100', 3) 9 int('100', 36) 1296 max -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the recommended library for xml parsing?
+1 ::results:: Cheers, Peter Petrelli On Mon, Aug 24, 2009 at 12:59 AM, Chris Rebert c...@rebertia.com wrote: On Sun, Aug 23, 2009 at 3:07 PM, Raimond Garciavoodoorai2...@gmail.com wrote: Is there a good build in library or should I use a third party one? xml.etree.ElementTree: http://docs.python.org/library/xml.etree.elementtree.html Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Fortran interoperability
On 24 Aug, 01:59, sturlamolden sturlamol...@yahoo.no wrote: subroutine foobar(cstr) bind(c, name='foobar') use, intrinsic :: iso_c_binding type(c_ptr) :: cstr character(*), pointer :: fstr call c_f_pointer(cptr, fptr) Actually, this does not work, as it is illegal to create a pointer to a character(*). However, we can create a pointer to a huge string (say 2 GB or whatever maximum the system allows), and slice that down to a substring using strlen to obtain the length. So here is how to pass a variable-length string from C to Fortran, tested with gcc and gfortran 4.1.1. In foobar.f03: subroutine wrap_foobar(cstr) bind(c, name='foobar') ! a wrapper for foobar we expose to C use, intrinsic :: iso_c_binding interface function strlen(cstr) bind(c, name='strlen') use, intrinsic :: iso_c_binding integer(c_int) :: strlen type(c_ptr), value :: cstr end function strlen end interface type(c_ptr), value :: cstr character(2147483647), pointer :: p_fstr integer :: n n = strlen(cstr) call c_f_pointer(cstr, p_fstr) call foobar(p_fstr(1:n)) end subroutine subroutine foobar(fstr) ! this is the Fortran function we want to call from C ! it takes a variable length string as argument and print its length character(*) :: fstr write (*,*) len(fstr) end subroutine In main.c: extern void foobar(char *); int main(int argc, char *argv[]) { foobar(argv[1]); return 0; } stu...@sturla-pc /d/fortrantest $ gfortran -c foobar.f03 stu...@sturla-pc /d/fortrantest $ gcc -c main.c stu...@sturla-pc /d/fortrantest $ gcc -o test.exe main.o foobar.o -lgfortran stu...@sturla-pc /d/fortrantest $ ./test 1234 4 stu...@sturla-pc /d/fortrantest $ ./test 0123456789 10 So it works... Regards, Sturla Molden -- http://mail.python.org/mailman/listinfo/python-list
Re: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile
John Machin wrote: Erik Max Francis max at alcyone.com writes: Ryniek90 wrote: Is its the '|\U' literal fault in path '|C:\\Users\\Ryniek's WinSe7en\\MyNewGGBackup(2009-08-23 14:59:02).tar.bz2|' ? What is the '|\U' literal fault ??? It's probably a misleading error from the OS; I would guess the problem is that the filename contains colons, which I believe is a no-no on Windows. The colons are the problem. The error message is not from the OS; it is concocted by Python (see fileobject.c) as what appears to be the best possible text given vague error reporting by Windows. I don't understand probably a misleading error [message] -- invalid mode (actual value) or filename - invalid something-obviously-not-invalid or filename - invalid filename I also suspect the pipe symbol. I don't know if it's an invalid character to Windows, but it's certainly a bad idea. The '|' character means something special to the shell. DaveA -- http://mail.python.org/mailman/listinfo/python-list