Re: web frameworks that support Python 3

2009-08-23 Thread Graham Dumpleton
On Aug 24, 6:34 am, Sebastian Wiesner  wrote:
> 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

There is one big flaw with your claim. That is the there is no WSGI
specification for Python 3.0 as yet. Anything that claims to work with
WSGI and Python 3.0 is just a big guess as far as how WSGI for Python
3.0 may work.

I would therefore be a bit cautious with your claim.

Graham

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python what I need?

2009-08-23 Thread c
> I'm interested in developing computer based, interactive programs

That is so open-ended it could mean anything.  If you give a much
more specified idea of what you are imagining creating, people could
be helpful.

> for students in a special school who have an aversion to pen and paper.


Aversion?  Why?  Is it that they have such bad penmanship that
writing
is too frustrating?  I've taught such students in college, and
suspect
(but do not know) that what would be good is to get them young and
really put in the remedial time to train their penmanship up to
sustained
legibility and speed.  Eventually society might go 100% electronic;
for now, being able to write notes on paper is very helpful, and
paper
is still such a great technology aside from renewable concerns, but
they can be greatly improved.  (I even suspect rigorous and successful
penmanship training might pay off in "general intelligence" gains)


> 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?

I agree with Dave A that writing a useful program is often far harder
than a beginner might imagine.  That said, much would depend on what
you would need the program to do.  Python, in my limited experience
as a hobbyist, strikes me as fairly easy to get started with in
programming, and yet can do a great deal, too.  So, as I said, more
details about the intended program would help people guide your
choice.

Che
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: basic thread question

2009-08-23 Thread John Nagle

Jan Kaliszewski wrote:

18-08-2009 o 22:10:15 Derek Martin  wrote:


I have some simple threaded code...  If I run this
with an arg of 1 (start one thread), it pegs one cpu, as I would
expect.  If I run it with an arg of 2 (start 2 threads), it uses both
CPUs, but utilization of both is less than 50%.  Can anyone explain
why?

I do not pretend it's impeccable code, and I'm not looking for a
critiqe of the code per se, excepting the case where what I've written
is actually *wrong*. I hacked this together in a couple of minutes,
with the intent of pegging my CPUs.  Performance with two threads is
actually *worse* than with one, which is highly unintuitive.  I can
accomplish my goal very easily with bash, but I still want to
understand what's going on here...

The OS is Linux 2.6.24, on a Ubuntu base.  Here's the code:


Python threads can't benefit from multiple processors (because of GIL,
see: http://docs.python.org/glossary.html#term-global-interpreter-lock).


This is a CPython implementation restriction.  It's not inherent in
the language.

Multiple threads make overall performance worse because Python's
approach to thread locking produces a large number of context switches.
The interpreter unlocks the "Global Interpreter Lock" every N interpreter
cycles and on any system call that can block, which, if there is a
thread waiting, causes a context switch.

Multiple Python processes can run concurrently, but each process
has a copy of the entire Python system, so the memory and cache footprints are
far larger than for multiple threads.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need cleanup advice for multiline string

2009-08-23 Thread Mensanator
On Aug 23, 2:25�pm, Stefan Behnel  wrote:
> Mensanator wrote:
> > asking how many Jews you can fit into a Volswagen.
>
> None, because it's already full.

A spelling error does not make it any less offensive.

>
> (or "voll" as those who design Volkswagens would put it...)
>
> Stefan

-- 
http://mail.python.org/mailman/listinfo/python-list


sgmllib.py

2009-08-23 Thread elsa
Hi all,

I'm new to both this forum and Python, and I've got a bit stuck trying
to learn how to parse HTML here is my problem

I'm using a textbook that uses sgmllib.py for all its examples. I'm
aware that sgmllib is not in the current release, however I want to
get it to work, as I have python 2.5, and the text book uses it.

So, the first example says to type something like (to test the
sgmllib):

python sgmllib.py "path/to/my/file.html"   example (1)

this doesn't work for me. I think I have figured out the problem  -
the error says

"/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/
Python.app/Contents/MacOS/Python: can't open file 'sgmllib.py': [Errno
2] No such file or directory"

the problem is that this path is wrong. My sgmllib.py is in:

"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/sgmllib.py"

if I substitute this path for sgmllib.py in example (1), everything
works fine. However, I don't want to do all that typing everytime I
want to use sgmllib.py. So, I thought maybe the problem was with
PYTHONPATH. I executed the following command:

export PYTHONPATH=/System/Library/Frameworks/Python.framework/Versions/
2.5/li/python2.5:$PYTHONPATH

this seemed to work - no errors raised. However, when I retyped
example (1), I got the same original error.

Any assistance would be much appreciated. I'm working on max os x
leopard.

Thanks,

elsa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Most "active" coroutine library project?

2009-08-23 Thread Doron Tal
On Sun, Aug 23, 2009 at 6:02 PM, Phillip B Oldham
wrote:

> 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
>

If you seek also event-driven libraries:
Twisted - http://twistedmatrix.com/trac/

--doron
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __import__(x) VS __import__(x, {}, {}, [''])

2009-08-23 Thread Phil
"If you call it without a value for 'globals', it uses the current
value of globals()."

Thanks, this is what I was trying to ask. I typed my question up way
too fast before dinner. You've been great help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Literal concatenation, strings vs. numbers (was: Numeric literals in other than base 10 - was Annoying octal notation)

2009-08-23 Thread Ben Finney
greg  writes:

> J. Cliff Dyer wrote:
>
> > What happens if you use a literal like 0x10f 304?
>
> To me the obvious thing to do is concatenate them textually and then
> treat the whole thing as a single numeric literal. Anything else
> wouldn't be sane, IMO.

Yet, as was pointed out, that behaviour would be inconsistent with the
concatenation of string literals::

>>> "abc" r'def' u"ghi" 'jkl'
u'abcdefghijkl'

So, different representations of literals are parsed as separate
literals, then concatenated. To have the behaviour you describe, the
case needs to be made separately that digit concatenation should not be
consistent with the established string literal parsing behaviour.

-- 
 \“What if the Hokey Pokey IS what it's all about?” —anonymous |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __import__(x) VS __import__(x, {}, {}, [''])

2009-08-23 Thread greg

Phil wrote:

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?

Not sure what you mean by "it" in that question.

This is talking about the built-in implementation of
the __import__ function, and what it does with the
'globals' and 'locals' arguments that get passed to
it (by whatever means).

If you call it without a value for 'globals', it uses
the current value of globals().

The bytecode generated for the 'import' statement
always calls it with the current globals() and locals().

If you pass an empty dict for 'globals', I think the
effect will be to cause the module name to always be
interpreted as a top-level module (i.e. no relative
import). But I'm not sure.

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread Ben Finney
Max Erickson  writes:

> 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

Hah! You don't get me that easily, nobody would make something so simple
and obvious.

Right, guys?

-- 
 \   “When a well-packaged web of lies has been sold to the masses |
  `\over generations, the truth will seem utterly preposterous and |
_o__)its speaker a raving lunatic.” —Dresden James |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python faster than java?

2009-08-23 Thread sturlamolden
On 23 Aug, 21:59, Emile van Sebille  wrote:

> Speed of what? Development? User interaction? Responsiveness to queries?


My personal view on the 'Is Python faster than Java' question:

- Coding? Yes, if you program 'pythonic'.

- String handling? Often.

- I/O and networking? Often.

- Iteration? No.

- Function calls and recursion? No.

- Arithmetics with elemental types? No.

- Numerics? Yes, if you use NumPy.

Is never interesting which language generates the most efficient code.
If that were the case, we would be writing everything in assembly. If
the code is fast enough, it is fast enough. Fast enough is sufficient.

If some part of the code turn out to be too slow, we have two options:
Either we use faster hardware, which is often the cheapest solution.
Or we can alternatively try to move that part to something less high-
level (Cython, C, C++, Fortran, assembly). Unlike Java, Python
integrates easily with C.

Also beware that Python is not Java: There is an old saying that you
can write FORTRAN in any language. You can also write Java in Python.
It will be just as slow to program as Java, and it will run a lot
slower than Java. Most of the complaints about 'Python being slow'
stems from people writing Java in Python.







-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile

2009-08-23 Thread John Machin
Dave Angel  ieee.org> writes:

 
> John Machin wrote:
> > Erik Max Francis  alcyone.com> writes:
  
> 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.

The "pipe" character is not a valid character in a Windows file.
Despite the OP's message wrapping the filename in "pipes",
there are no pipes in the filename in the traceback to
which he posted a link.  Wrapping the filename in "pipes"
and the cryptic reference to "the '|\U' literal fault"
appear to be side-issue bogglements.

 >>> open('boggle|txt', 'wb')
 Traceback (most recent call last):
   File "", line 1, in 
 IOError: [Errno 22] invalid mode ('wb') or filename: 'boggle|txt'
 >>> open('|boggle.txt|', 'wb')
 Traceback (most recent call last):
   File "", line 1, in 
 IOError: [Errno 22] invalid mode ('wb') or filename: '|boggle.txt|'


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python what I need?

2009-08-23 Thread Dave Angel

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?

  
I think I'm a bit confused as to just what you're intending, and what 
your background is.  So if this response doesn't fit, please don't be 
offended.


I'm guessing you don't want these special students to do any 
programming, but instead you just want to find/develop inexpensive 
applications for their use.  You have some specific ideas, but haven't 
found anything already available within your budget.


I'm also guessing that you're a total beginner at programming.  If so, I 
claim that most programs are much, much harder to write than you can 
imagine.  Python is one of the easiest languages to learn and to write 
things in, but even so, most  GUI programs take hundreds of hours to 
develop.  And I've been doing it for forty years, in about 30 languages.


DaveA

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python/Fortran interoperability

2009-08-23 Thread Richard Maine
sturlamolden  wrote:

> Does anyone use OOP in Fortran anyway?

Presumably not many people yet because...

> And Fortran 2003 compilers are not ubiquitous.

I'd not only agree, I'd say that was quite a bit understated. Last time
I checked, the number of Fortran 2003 compilers available on the most
widely used platforms was zero, which is quite a bit short of
ubiquitous. No I don't have an IBM workstation handy; or a Cray. Nor do
most people.

I did try playing with the Fortran OOP stuff quite a few years ago, when
NAG first added some of the OOP features to their f95 compiler. But
alas, although they added some of the OOP features, there were critical
parts that were not included. Play with it a little is all I could do. I
couldn't write any serious code, or even "play" very extensively. (Lack
of allocatable scalars was a show stopper; it seems so simple and isn't
even normally identified as an OOP feature per se, but you need it to do
much with OOP in F2003).

I'm told that NAG's 5.2 finally has the needed stuff, but it has been an
awful long time in coming... and still isn't yet here for anything but
Linux (I'm told "soon"). Some other compilers are also getting there.
But there is just no way that most people have spent much time
developing with compilers that adequately supported the f2003 OOP
features.

(I'd cite my formal comment on f2008, and maybe David Muxworthy's recent
article as well, but we've already been down that path.)

-- 
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: What is the recommended library for xml parsing?

2009-08-23 Thread bot
voodoorai2000 on gmail.com has asked me for the current status of our 
votation.. so here you go:

+1 => 1 vote
-1 => 0 votes

Time Line:
--
(2009-08-24 01:25:11) Raimond Garcia: +1

Visit the fancy votation page:
* http://letsdecide.us/4130bc4e0051016cb377d3436f4e8e683ed820ed
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread greg

J. Cliff Dyer wrote:


What happens if you use a literal like 0x10f 304?


To me the obvious thing to do is concatenate them
textually and then treat the whole thing as a single
numeric literal. Anything else wouldn't be sane, IMO.

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python/Fortran interoperability

2009-08-23 Thread sturlamolden
On 24 Aug, 02:57, nos...@see.signature (Richard Maine) wrote:

> 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.

You are right, I missed th OOP part.

It might be interesting in teh future to say inherit a Python class
from a Fortran 2003 derived type. I have no idea how to do this (I
don't know Fortran 2003 that well). But possibly one could do some
magic with the ISO C bindings, exposing the Fortran 2003 derived type
as a C etxtension class to Python.

Does anyone use OOP in Fortran anyway? I sure do not. And Fortran 2003
compilers are not ubiquitous. Fortran compilers tend to support a
subset for Fortran 2003, usually ISO C bindings but not OOP.


Sturla


























-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile

2009-08-23 Thread Dave Angel

John Machin wrote:

Erik Max Francis  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


Re: Python/Fortran interoperability

2009-08-23 Thread sturlamolden
On 24 Aug, 01:59, sturlamolden  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: What is the recommended library for xml parsing?

2009-08-23 Thread Raimond Garcia
+1

::results::

Cheers,

Peter Petrelli



On Mon, Aug 24, 2009 at 12:59 AM, Chris Rebert  wrote:

> On Sun, Aug 23, 2009 at 3:07 PM, Raimond Garcia
> 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

2009-08-23 Thread Max Erickson
"bartc"  wrote:

> 
> "Scott David Daniels"  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: Python/Fortran interoperability

2009-08-23 Thread Richard Maine
sturlamolden  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: Newbie: list comprehension troubles..

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 5:09 PM, Ben Finney wrote:
> Chris Rebert  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: install package in a particular python version

2009-08-23 Thread David Lyon
On Thu, 20 Aug 2009 20:53:18 -0700 (PDT), Steve1234 
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: Python/Fortran interoperability

2009-08-23 Thread sturlamolden
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: Protecting against callbacks queuing up?

2009-08-23 Thread MRAB

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: Need cleanup advice for multiline string

2009-08-23 Thread Steven D'Aprano
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
>>  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


Protecting against callbacks queuing up?

2009-08-23 Thread Esben von Buchwald

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: Newbie: list comprehension troubles..

2009-08-23 Thread Ben Finney
Chris Rebert  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


Re: Python/Fortran interoperability

2009-08-23 Thread sturlamolden
On 24 Aug, 01:59, sturlamolden  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..

2009-08-23 Thread Terry Reedy

Chris Rebert wrote:

On Sun, Aug 23, 2009 at 4:27 PM, mm 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

2009-08-23 Thread sturlamolden
On 24 Aug, 00:02, Dennis Lee Bieber  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  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..

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 4:27 PM, mm 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


Newbie: list comprehension troubles..

2009-08-23 Thread mm
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: Python/Fortran interoperability

2009-08-23 Thread sturlamolden
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


Re: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile

2009-08-23 Thread John Machin
Erik Max Francis  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: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread bartc


"Scott David Daniels"  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: What is the recommended library for xml parsing?

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 3:07 PM, Raimond Garcia 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: logging SMTPhandler Error

2009-08-23 Thread Aahz
In article ,
Dennis Lee Bieber   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: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread Scott David Daniels

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: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread MRAB

James Harris wrote:

On 23 Aug, 00:16, Mel  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
:


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

  0"2:1011", 0"8:7621", 0"16:c26b"


Why not just put the base first, followed by the value in quotes:

2"1011", 8"7621", 16"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?


--
http://mail.python.org/mailman/listinfo/python-list


Re: conditional for-statement

2009-08-23 Thread Mel
seb wrote:

> On Aug 23, 6:18 pm, John Posner  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


What is the recommended library for xml parsing?

2009-08-23 Thread Raimond Garcia
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


__import__(x) VS __import__(x, {}, {}, [''])

2009-08-23 Thread Phil
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


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread James Harris
On 23 Aug, 21:55, James Harris  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


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread James Harris
On 23 Aug, 00:16, Mel  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
> :

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

  0"2:1011", 0"8:7621", 0"16: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: conditional for-statement

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 1:36 PM, seb wrote:
> On Aug 23, 6:18 pm, John Posner  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: conditional for-statement

2009-08-23 Thread seb
On Aug 23, 10:36 pm, seb  wrote:
> On Aug 23, 6:18 pm, John Posner  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

2009-08-23 Thread James Harris
On 23 Aug, 04:38, c...@tiac.net (Richard Harter) wrote:
> On Sat, 22 Aug 2009 14:54:41 -0700 (PDT), James Harris
>
>
>
>
>
>  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 r 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: Is python faster than java?

2009-08-23 Thread Raimond Garcia
Makes sense.
+1

Cheers

Peter

On Sun, Aug 23, 2009 at 9:59 PM, Emile van Sebille  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: can python make web applications?

2009-08-23 Thread Goke Aruna
A lot check this fantastic open source application,
http://www.openerp.com, all done is python.

On 8/23/09, Stefaan Himpe  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: web frameworks that support Python 3

2009-08-23 Thread Stefan Behnel
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: conditional for-statement

2009-08-23 Thread seb
On Aug 23, 6:18 pm, John Posner  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: Combining python and perl

2009-08-23 Thread Albert Hopkins
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: web frameworks that support Python 3

2009-08-23 Thread Sebastian Wiesner
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: web frameworks that support Python 3

2009-08-23 Thread Albert Hopkins
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: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile

2009-08-23 Thread Erik Max Francis

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


web frameworks that support Python 3

2009-08-23 Thread David Prager Branner
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: Is python faster than java?

2009-08-23 Thread Emile van Sebille

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


Re: Combining python and perl

2009-08-23 Thread Peng Yu
On Aug 23, 8:00 am, Albert Hopkins  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


Is python faster than java?

2009-08-23 Thread Raimond Garcia
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: Need cleanup advice for multiline string

2009-08-23 Thread Stefan Behnel
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


Re: Need cleanup advice for multiline string

2009-08-23 Thread Stefan Behnel
Jean-Michel Pichavant wrote:
> Grant Edwards wrote:
>> On 2009-08-18, Simon Forman  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

2009-08-23 Thread Stefan Behnel
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
>  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: Questions on XML

2009-08-23 Thread Rami Chowdhury
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 
wrote:
> > 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: Python/Fortran interoperability

2009-08-23 Thread nmm1
In article , JB   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: can python make web applications?

2009-08-23 Thread Stefaan Himpe

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: Polling a net address

2009-08-23 Thread Aahz
In article <99ddf4e1-d327-4fb1-aee4-aa881de3b...@d23g2000vbm.googlegroups.com>,
Iain   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: Annoying octal notation

2009-08-23 Thread James Harris
On 21 Aug, 00:59, James Harris  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: Most "active" coroutine library project?

2009-08-23 Thread Matthew Woodcraft
Phillip B Oldham  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: Python/Fortran interoperability

2009-08-23 Thread JB
["Followup-To:" header set to comp.lang.fortran.]
On 2009-08-23, 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


[ANN] pyxser-1.2r --- Python-Object to XML serialization module

2009-08-23 Thread Daniel Molina Wegener
-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=display&name=pyxser&version=1.2r

The current ChangeLog is as follows:

- -8<--8<--8<--8<-
1.2r (2009.08.23):

        Daniel Molina Wegener 
        * 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: can python make web applications?

2009-08-23 Thread koranthala
On Aug 23, 8:12 pm, 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

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


Re: Trying To Catch Invalid User Input

2009-08-23 Thread Victor Subervi
Really slick! Thanks!
V

On Sun, Aug 23, 2009 at 11:08 AM, Albert Hopkins wrote:

> 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: conditional for-statement

2009-08-23 Thread John Posner



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: [Diversity] Language note

2009-08-23 Thread Cameron Laird
In article ,
Rami Chowdhury   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 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


Python-URL! - weekly Python news and links (Aug 23)

2009-08-23 Thread Gabriel Genellina
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.org&group=gmane.comp.python.devel&sort=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=python&Show

Re: Trying To Catch Invalid User Input

2009-08-23 Thread Albert Hopkins
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


Re: generate keyboard/mouse event under windows

2009-08-23 Thread Scott David Daniels

Ray wrote:

On Aug 19, 2:07 pm, yaka  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: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread bartc


 wrote in message 
news:h6r4fb$18...@aioe.org...

In comp.lang.python James Harris  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: Is Python what I need?

2009-08-23 Thread Tomasz Rola
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: Trying To Catch Invalid User Input

2009-08-23 Thread Gary Herron

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: Trying To Catch Invalid User Input

2009-08-23 Thread MRAB

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: Is Python what I need?

2009-08-23 Thread Peter Otten
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: Python/Fortran interoperability

2009-08-23 Thread sturlamolden
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


can python make web applications?

2009-08-23 Thread Deep_Feelings
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


Most "active" coroutine library project?

2009-08-23 Thread Phillip B Oldham
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


Trying To Catch Invalid User Input

2009-08-23 Thread Victor Subervi
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


IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile

2009-08-23 Thread Ryniek90

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


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread J. Cliff Dyer
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


Re: Python/Fortran interoperability

2009-08-23 Thread Stefan Behnel
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

2009-08-23 Thread Ben Finney
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: logging SMTPhandler Error

2009-08-23 Thread Aahz
In article <60de8d40-61f4-4ffd-bcef-749bf0667...@k19g2000yqn.googlegroups.com>,
Bev in TX   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: Annoying octal notation

2009-08-23 Thread Matthew Woodcraft
Dennis Lee Bieber  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: Dictionary from a list

2009-08-23 Thread Aahz
In article ,
EK   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: Python/Fortran interoperability

2009-08-23 Thread viper-2
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.  

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


How to distribute an application

2009-08-23 Thread Steven Woody
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: Blank Line at Program Exit

2009-08-23 Thread Steven Woody
On Sat, Aug 22, 2009 at 11:25 PM, Nitebirdz wrote:

> 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


Re: Combining python and perl

2009-08-23 Thread Albert Hopkins
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


Combining python and perl

2009-08-23 Thread Peng Yu
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


  1   2   >