Re: how to mysqldb dict cursors

2008-04-25 Thread Vaibhav.bhawsar
Great both methods worked! I dont quite understand this since i imported the
whole module with "import MySQLdb"

Thanks!

On Fri, Apr 25, 2008 at 12:45 AM, Paul McNett <[EMAIL PROTECTED]> wrote:

> Vaibhav.bhawsar wrote:
>
>> I have been trying to get the DictCursor working with mysqldb module but
>> can't seem to. I have pasted the basic connection code and the traceback
>> from pydev. The connection does open with the default cursor class. can't
>> figure this one out. many thanks.
>>
>
> Try one of:
>
> """
> import MySQLdb, MySQLdb.cursors
> conn = MySQLdb.connect(..., cursorclass=MySQLdb.cursors.DictCursor)
> """
>
> -or-
>
> """
> import MySQLdb, MySQLdb.cursors
> conn = MySQLdb.connect(...)
> cur = MySQLdb.cursors.DictCursor(conn)
> """
>
> I'm going off of memory here, though, but I'm at least close.
>
> Paul
>
>


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

Re: Little novice program written in Python

2008-04-25 Thread Peter Otten
Rogério Brito wrote:

> i = 2
> while i <= n:
>      if a[i] != 0:
> print a[i]
>      i += 1

You can spell this as a for-loop:

for p in a:
if p:
print p

It isn't exactly equivalent, but gives the same output as we know that a[0]
and a[1] are also 0.

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

Re: py3k concerns. An example

2008-04-25 Thread Martin v. Löwis
> In my view using a conversion tool on an ongoing basis is
> not an option.  It just adds a dependancy.  What happens when
> the conversion tool is upgraded in a non-backwards-compatible
> way?  Or do we have assurance that it won't be ;)?

The latter: if you include a copy of the converter with your
package, it won't change unless you change it. If you rely
on the copy of the converter that ships with Python 3.0, you
have the assurance that it won't change in a
non-backwards-compatible manner in all of 3.0.y.

Of course, the copies include in later 3.x releases may change, but
you'll have to test for the later 3.x releases, anyway, as
they may show incompatible changes themselves.

> Will changes to the converter
> mean that the users of my
> converted libraries have to start
> using my tools in a different way?

No. If the 2to3 converter is changed to support additional
source patterns to convert, it either won't affect your
code (if you don't use the pattern), or it may convert some
of your code that it didn't previously - then that conversion
may or may not be correct. So as a consequence, your library
may stop working; then you'll have to adjust either your
library, or go back to an older version of the converter.

In no case, however, will the users of the library need to
adjust their code to changing 2to3 output. 2to3 won't change
the library API.

> I have no interest in adding additional dependancies,
> with an additional degree of freedom to break.

Then remove the freedom by fixing a specific 2to3 version
(e.g. by including it).

> So if I want to support both I have to do everything
> twice in the expected case and in the best case test
> everything twice, at the same time, if I want to
> support both versions and keep features in sync.

This I don't understand. Why do you think you have to
do everything twice?

> I still think it's a shame
[...]
> pps: I have to note that it would be nice if the
>   ad-hominem (sp?) invective would drop out of
>   these threads -- it doesn't add a lot, I think.

shame
1 a. a painful emotion caused by consciousness of guilt,
 shortcoming, or impropriety
2 a condition of humiliating disgrace or disrepute

So who do you think should feel guilt? Or should
be disgraced or disreputed?

Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Little novice program written in Python

2008-04-25 Thread Robert Bossy

Peter Otten wrote:

Rogério Brito wrote:

  

i = 2
while i <= n:
 if a[i] != 0:
print a[i]
 i += 1



You can spell this as a for-loop:

for p in a:
if p:
print p

It isn't exactly equivalent, but gives the same output as we know that a[0]
and a[1] are also 0.
  
If the OP insists in not examining a[0] and a[1], this will do exactly 
the same as the while version:


for p in a[2:]:
   if p:
   print p


Cheers,
RB
--
http://mail.python.org/mailman/listinfo/python-list

Re: Little novice program written in Python

2008-04-25 Thread John Machin
On Apr 25, 5:44 pm, Robert Bossy <[EMAIL PROTECTED]> wrote:
> Peter Otten wrote:
> > Rogério Brito wrote:
>
> >> i = 2
> >> while i <= n:
> >>  if a[i] != 0:
> >> print a[i]
> >>  i += 1
>
> > You can spell this as a for-loop:
>
> > for p in a:
> > if p:
> > print p
>
> > It isn't exactly equivalent, but gives the same output as we know that a[0]
> > and a[1] are also 0.
>
> If the OP insists in not examining a[0] and a[1], this will do exactly
> the same as the while version:
>
> for p in a[2:]:
> if p:
> print p
>

... at the cost of almost doubling the amount of memory required.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Little novice program written in Python

2008-04-25 Thread Robert Bossy

John Machin wrote:

On Apr 25, 5:44 pm, Robert Bossy <[EMAIL PROTECTED]> wrote:
  

Peter Otten wrote:


Rogério Brito wrote:
  

i = 2
while i <= n:
 if a[i] != 0:
print a[i]
 i += 1


You can spell this as a for-loop:
  
for p in a:

if p:
print p
  
It isn't exactly equivalent, but gives the same output as we know that a[0]

and a[1] are also 0.
  

If the OP insists in not examining a[0] and a[1], this will do exactly
the same as the while version:

for p in a[2:]:
if p:
print p




... at the cost of almost doubling the amount of memory required.
Indeed. Would it be a sensible proposal that sequence slices should 
return an iterator instead of a list?


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


Re: Little novice program written in Python

2008-04-25 Thread hellt


Rogério Brito:
> Hi, All.
>
> I'm just getting my feet wet on Python and, just for starters, I'm coding some
> elementary number theory algorithms (yes, I know that most of them are already
> implemented as modules, but this is an exercise in learning the language 
> idioms).
>
> As you can see from the code below, my background is in C, without too much
> sophistication.
>
> What I would like is to receive some criticism to my code to make it more
> Python'esque and, possibly, use the resources of the computer in a more
> efficient way (the algorithm implemented below is the Sieve of Eratosthenes):
>

my variant of the sieve

def GetPrimes(N):
arr = []
for i in range(1,N+1):
arr.append(i)
#Set first item to 0, because 1 is not a prime
arr[0]=0
#sieve processing
s=2
while s < math.sqrt(N):
if arr[s-1] != 0:
j = s*s
while j <= N:
arr[j-1] = 0
j += s
s += 1
return [x for x in arr if x != 0]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Little novice program written in Python

2008-04-25 Thread hellt
also, i would recommend you to visit projecteuler.net
you can solve math tasks and then see how others have done the same.

you can fetch very good and pythonic solution there.

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


Re: Little novice program written in Python

2008-04-25 Thread Arnaud Delobelle
hellt <[EMAIL PROTECTED]> writes:

> my variant of the sieve

Since you posted it, you are also looking for advice to improve your
code ;)

> def GetPrimes(N):

> arr = []
> for i in range(1,N+1):
> arr.append(i)
This is the same as:
  arr = range(1, N+1)
!-)

> #Set first item to 0, because 1 is not a prime
> arr[0]=0
> #sieve processing

> s=2
remove this line

> while s < math.sqrt(N):
  for s in xrange(2, int(math.sqrt(N))+1):

> if arr[s-1] != 0:
  if arr[s-1]:

> j = s*s
remove this line

> while j <= N:
  for j in xrange(s*s, N+1, s):

> arr[j-1] = 0

> j += s
remove this line

> s += 1
remove this line

> return [x for x in arr if x != 0]
  return filter(None, arr)


Altogether now:

def getprimes(N):
arr = range(1, N+1)
arr[0] = 0
for s in xrange(2, int(math.sqrt(N))+1):
if arr[s-1]:
for j in xrange(s*s, N+1, s):
arr[j-1] = 0
return filter(None, arr)

It's the same, but it looks a bit less like the litteral translation
of some C code.


Lastly, the lines:

for j in xrange(s*s, N+1, s):
arr[j-1] = 0

from above can be condensed using extended slices:

arr[s*s-1 : N+1 : s] = [0] * (N/s - s + 1)

(If I can count correctly)

Giving the following, slightly shorter and probably faster:

def getprimes(N):
arr = range(1, N+1)
arr[0] = 0
for s in xrange(2, int(math.sqrt(N))+1):
if arr[s-1]:
arr[s*s-1 : N+1 : s] = [0] * (N/s - s + 1)
return filter(None, arr)


If it was me, I would include 0 in the array, giving the slightly simpler:

def getprimes(N):
arr = range(N+1)
arr[1] = 0
for s in xrange(2, int(math.sqrt(N))+1):
if arr[s]:
arr[s*s : N+1 : s] = [0] * (N/s - s + 1)
return filter(None, arr)

(I think)

This all needs to be tested.

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


Re: Little novice program written in Python

2008-04-25 Thread hellt
On 25 апр, 13:29, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> hellt <[EMAIL PROTECTED]> writes:
> > my variant of the sieve
>
> Since you posted it, you are also looking for advice to improve your
> code ;)
>
> > def GetPrimes(N):
> > arr = []
> > for i in range(1,N+1):
> > arr.append(i)
>
> This is the same as:
>   arr = range(1, N+1)
> !-)
>
> > #Set first item to 0, because 1 is not a prime
> > arr[0]=0
> > #sieve processing
> > s=2
>
> remove this line
>
> > while s < math.sqrt(N):
>
>   for s in xrange(2, int(math.sqrt(N))+1):
>
> > if arr[s-1] != 0:
>
>   if arr[s-1]:
>
> > j = s*s
>
> remove this line
>
> > while j <= N:
>
>   for j in xrange(s*s, N+1, s):
>
> > arr[j-1] = 0
> > j += s
>
> remove this line
>
> > s += 1
>
> remove this line
>
> > return [x for x in arr if x != 0]
>
>   return filter(None, arr)
>
> Altogether now:
>
> def getprimes(N):
> arr = range(1, N+1)
> arr[0] = 0
> for s in xrange(2, int(math.sqrt(N))+1):
> if arr[s-1]:
> for j in xrange(s*s, N+1, s):
> arr[j-1] = 0
> return filter(None, arr)
>
> It's the same, but it looks a bit less like the litteral translation
> of some C code.
>
> Lastly, the lines:
>
> for j in xrange(s*s, N+1, s):
> arr[j-1] = 0
>
> from above can be condensed using extended slices:
>
> arr[s*s-1 : N+1 : s] = [0] * (N/s - s + 1)
>
> (If I can count correctly)
>
> Giving the following, slightly shorter and probably faster:
>
> def getprimes(N):
> arr = range(1, N+1)
> arr[0] = 0
> for s in xrange(2, int(math.sqrt(N))+1):
> if arr[s-1]:
> arr[s*s-1 : N+1 : s] = [0] * (N/s - s + 1)
> return filter(None, arr)
>
> If it was me, I would include 0 in the array, giving the slightly simpler:
>
> def getprimes(N):
> arr = range(N+1)
> arr[1] = 0
> for s in xrange(2, int(math.sqrt(N))+1):
> if arr[s]:
> arr[s*s : N+1 : s] = [0] * (N/s - s + 1)
> return filter(None, arr)
>
> (I think)
>
> This all needs to be tested.
>
> --
> Arnaud

nice, but i'm a newbie to python too, so some things for me seems a
liitle complicated)))
--
http://mail.python.org/mailman/listinfo/python-list

Re: Can you recommend a book?

2008-04-25 Thread Brian
On Fri, Apr 25, 2008 at 6:28 AM, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:

> Hello all, I learned Python with the book "Programming Python" by John
> Zelle. But today this book is a little bit old. My Python is some kind
> old. I need a book that will help me brush my style and keep me up to
> date. I would like one with practical examples.
>
> Can you recommend one?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Dive Into Python  is awesome, and best of
all, free.

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

Can you recommend a book?

2008-04-25 Thread [EMAIL PROTECTED]
Hello all, I learned Python with the book "Programming Python" by John
Zelle. But today this book is a little bit old. My Python is some kind
old. I need a book that will help me brush my style and keep me up to
date. I would like one with practical examples.

Can you recommend one?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Little novice program written in Python

2008-04-25 Thread Marc 'BlackJack' Rintsch
On Fri, 25 Apr 2008 10:24:16 +0200, Robert Bossy wrote:

> John Machin wrote:
>> On Apr 25, 5:44 pm, Robert Bossy <[EMAIL PROTECTED]> wrote:
>>   
>>> Peter Otten wrote:
>>> If the OP insists in not examining a[0] and a[1], this will do exactly
>>> the same as the while version:
>>>
>>> for p in a[2:]:
>>> if p:
>>> print p
>>>
>>> 
>>
>> ... at the cost of almost doubling the amount of memory required.
> Indeed. Would it be a sensible proposal that sequence slices should 
> return an iterator instead of a list?

I don't think so as that would break tons of code that relies on the
current behavior.  Take a look at `itertools.islice()` if you want/need
an iterator.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can you recommend a book?

2008-04-25 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
> Hello all, I learned Python with the book "Programming Python" by John
> Zelle. But today this book is a little bit old. My Python is some kind
> old. I need a book that will help me brush my style and keep me up to
> date. I would like one with practical examples.
> 
> Can you recommend one?

http://wiki.python.org/moin/PythonBooks

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


Re: py3k concerns. An example

2008-04-25 Thread Gabriel Genellina
En Thu, 24 Apr 2008 11:10:55 -0300, Paul McGuire <[EMAIL PROTECTED]>  
escribió:



On Apr 21, 9:01 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:


Perhaps you can manage to keep your code compatible with all versions,  
but  
AFAIK the reccomended strategy is to write code compatible with Python  
2.6  
and use the 2to3 tool to generate the 3.0 source. And *not* edit the  
3.0  

code unless one wants to maintain two branches.



Gabriel -

(Thanks for chiming in on this sub-thread, I really enjoy reading your
posts.)


(And I enjoy using your parser! Not that I have to parse text so often,  
but when it comes, the "pythonicity" of pyparsing is a great thing!)



My point is that the recommended strategy MAY work for those who write
end point applications (I consider maintaining 2 branches to be in the
"not working" category), but it does NOT WORK for people who maintain
modules for other people to use, because those people may be on a
range of Python versions that extend beyond 2.6-3.0.  So if I upgrade
my module to 2.6, those running on earlier versions can no longer use
it.  At some point in the future, I'll probably be able to say "no
more support for pre-2.6", but it is a bit early to start saying that
now.

Likewise, I don't want to say "no support for 3.0" - people DO want to
try 3.0 out, and I WANT them to want and be able to use my module too.

Given the recommended strategy, and ruling out dual codebase, whom do
I tell that they can't use the next version of my module?


Ok, code that is "2.6 compatible" doesn't mean that it only runs on 2.6...  
I'm *trying* to write code that is "2to3 friendly" but anyway compatible  
with older Python versions, and it should not require 2.6 to run. That  
means not using "with" as a variable name, for example. (And on the other  
side, also refrain from using some new 2.6 features like class decorators  
and binary literals)
I hope the final version of the 2to3 tool will be a little more robust -  
or at least, that one will always be able to write code in a way that it  
can handle (and I *dont* want to maintain a 2.x and 3.x branches of any  
code either)
Based on my limited experience I'd say that this approach *could* work,  
that is, write the code base for 2.x (x >= 3, in my case) and  
automatically convert to 3.0. That last stage may fail, but -I hope!- not  
so often in the future. As always, YMMV...
Also note that I *don't* write code for other developers (thanks God!),  
just final users (with Python 2.3/4/5)



Again, to me, this is a non-issue because I've been able to create a
cross-version compatible single codebase for pyparsing.  But it was a
bit dicey there for a while, and I think other module developers/
maintainers may not be so lucky.


That's a bit tricky at least. How did you manage to avoid problems with  
(string/unicode) and (bytes/string) in 3.0?



So, I feel that the recommended strategy was devised with a narrow
group of developers in mind, and leaves module developers/maintainers,
who wish to target as broad a set of users as possible, faced with
choosing one of these strategies:
- create (if possible) single cross-version compatible code
- forego support of 3.0 users
- discontinue pre-2.6 support for future versions of their module
- maintain dual codebase


I hope the first alternative will be actually viable, perhaps with help  
from tools like 2to3...


--
Gabriel Genellina

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


Re: Can you recommend a book?

2008-04-25 Thread Malcolm Greene
My two favorites:

- Core Python Programming by Chun
- Learning Python by Lutz

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


problem with unicode

2008-04-25 Thread [EMAIL PROTECTED]
Hi everybody,

I'm using the win32 console and have the following short program
excerpt

# media is a binary string (mysql escaped zipped file)

>> print media
xワユロ[ヨ...
(works)

>> print unicode(media)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)
(ok i guess print assumes you want to print to ascii)

>> print unicode(media).encode('utf-8')
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)
(why does this not work?)

# mapString is a unicode string (i think at least)
>> print "'" + mapString + "'"
' yu_200703_hello\ 831 v1234.9874 '

>>mystr = "%s %s" % (mapString, media)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)

>> mystr = "%s %s" % (mapString.encode('utf-8'), media.encode('utf-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)

I don't know what to do. I just want to concatenate two string where
apparently one is a binary string, the other one is a unicode string
and I always seem to get this error.

Any help is appreciated :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Little novice program written in Python

2008-04-25 Thread hellt
On 25 апр, 15:02, Max M <[EMAIL PROTECTED]> wrote:
> Rogério Brito skrev:
>
> > Hi, All.
>
> > What I would like is to receive some criticism to my code to make it
> > more Python'esque and, possibly, use the resources of the computer in a
> > more efficient way (the algorithm implemented below is the Sieve of
> > Eratosthenes):
>
> I agree with the rest here. Your code generally looks fine.
>
> But on another note, this type of code is not something you often see in
> Python. It is very dense with regard to algorithm.
>
> Most code is not like that so perhaps you should try something more
> "usual" like sending email, fetching webpages etc. to get a feel for the
> language.
>
> --
>
> hilsen/regards Max M, Denmark
>
> http://www.mxm.dk/
> IT's Mad Science

em, i would say, that python (esp. with NumPy+Psyco) is very popular
in numerical processing also.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Little novice program written in Python

2008-04-25 Thread Max M

Rogério Brito skrev:

Hi, All.

What I would like is to receive some criticism to my code to make it 
more Python'esque and, possibly, use the resources of the computer in a 
more efficient way (the algorithm implemented below is the Sieve of 
Eratosthenes):



I agree with the rest here. Your code generally looks fine.

But on another note, this type of code is not something you often see in 
Python. It is very dense with regard to algorithm.


Most code is not like that so perhaps you should try something more 
"usual" like sending email, fetching webpages etc. to get a feel for the 
language.



--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

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


Re: Can you recommend a book?

2008-04-25 Thread hellt
On 25 апр, 15:09, "Malcolm Greene" <[EMAIL PROTECTED]> wrote:
> My two favorites:
>
> - Core Python Programming by Chun
> - Learning Python by Lutz
>
> Malcolm

Learning Python (Lutz) is very good, reading right now.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Problem building python in virtual machine running centos

2008-04-25 Thread Paul Boddie
On 25 Apr, 03:05, Alexandre Gillet <[EMAIL PROTECTED]> wrote:
>
> I am trying to build python-2.4.5 on Centos 5.1, which is a virtual
> machine running with xen.
> I am not able to build python. The compilation crash with the following:
> gcc -pthread -c  -DNDEBUG -g  -O3 -Wall -Wstrict-prototypes -I.
> -I./Include  -DPy_BUILD_CORE -o Objects/unicodeobject.o
> Objects/unicodeobject.c
> In file included from ./Include/Python.h:76,
>  from Objects/unicodeobject.c:39:
> ./Include/object.h:228: internal compiler error: Segmentation fault
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See http://bugzilla.redhat.com/bugzilla> for instructions.
> The bug is not reproducible, so it is likely a hardware or OS problem.
>
> Any suggestion of what am I doing wrong?

You say that the bug is not reproducible, so that means that you can
sometimes compile Python, or does the crash always happen when
compiling some file (not necessarily the one mentioned above)? I think
I've only ever seen a reproducible gcc crash once, and that had
something to do with a C++ source file which I then split into two and
was able to compile as these two separate parts. You might want to
check the gcc version (gcc -v) and to look at bug fixes in any later
versions. Generally, if you get an internal error in gcc, you aren't
doing anything wrong yourself.

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


Re: how to mysqldb dict cursors

2008-04-25 Thread Steve Holden

Vaibhav.bhawsar wrote:
[top-posting amended: see below]
On Fri, Apr 25, 2008 at 12:45 AM, Paul McNett <[EMAIL PROTECTED] 
> wrote:


Vaibhav.bhawsar wrote:

I have been trying to get the DictCursor working with mysqldb
module but can't seem to. I have pasted the basic connection
code and the traceback from pydev. The connection does open with
the default cursor class. can't figure this one out. many thanks.


Try one of:

"""
import MySQLdb, MySQLdb.cursors
conn = MySQLdb.connect(..., cursorclass=MySQLdb.cursors.DictCursor)
"""

-or-

"""
import MySQLdb, MySQLdb.cursors
conn = MySQLdb.connect(...)
cur = MySQLdb.cursors.DictCursor(conn)
"""

I'm going off of memory here, though, but I'm at least close.

> Great both methods worked! I don't quite understand this since i 
imported

> the whole module with "import MySQLdb"
>
> Thanks!
>
The point here is that MySQLdb is a package, not a module. Some packages 
have their top-level __init__.py import the package's sub-modules or 
sub-packages to make them immediately available within the package 
namespace (which is why, for example, you can access os.path.* when you 
have imported os) and others don't.


MySQLdb clearly doesn't need to import the cursors module for its own 
purposes. Perhaps it would be less efficient to always perfrom the 
import, who knows. Well, Andy Dustman does, I suppose, and possibly 
anyone else who reads the code, but I haven't done that myself.


regards
 Steve
--
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Parsing text file with #include and #define directives

2008-04-25 Thread python
Arnaud,

Wow!!! That's beautiful. Thank you very much!

Malcolm



I think it's straightforward enough to be dealt with simply.  Here is
a solution that doesn't handle errors but should work with well-formed
input and handles recursive expansions.

expand(filename) returns an iterator over expanded lines in the file,
inserting lines of included files.

import re

def expand(filename):
defines = {}
def define_repl(matchobj):
return defines[matchobj.group(1)]
define_regexp = re.compile('#(.+?)#')
for line in open(filename):
if line.startswith('#include '):
   recfilename = line.strip().split(None, 1)[1]
   for recline in expand(recfilename):
   yield recline
elif line.startswith('#define '):
   _, name, value = line.strip().split(None, 2)
   defines[name] = value
else:
yield define_regexp.sub(define_repl, line)

It would be easy to modify it to keep track of line numbers and file
names.


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


Re: problem with unicode

2008-04-25 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

> # media is a binary string (mysql escaped zipped file)
> 
 print media
> x???[?...
> (works)

Which encoding, perhaps UTF-8 or ISO8859-1?
 
 print unicode(media)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in
> position 1: ordinal not in range(128)
> (ok i guess print assumes you want to print to ascii)

Not at all -- unicode tries to decode the byte string you gave it,
but doesn't know which encoding to use, so it falls back to ASCII.

You should decode all "incoming" byte strings to unicode objects
using the right encoding -- here I tried yours with UTF-8. This
works best using string's method "decode" which returns a unicode
object.

>>> media="x???[?"
>>> print repr(media.decode("utf-8"))
u'x\u30ef\u30e6\u30ed[\u30e8'

Regards,


Björn

-- 
BOFH excuse #379:

We've picked COBOL as the language of choice.

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


Re: Remove multiple inheritance in Python 3000

2008-04-25 Thread Bjoern Schliessmann
sturlamolden wrote:
> On Apr 22, 1:07 pm, GD <[EMAIL PROTECTED]> wrote:
 
>> Multiple inheritance is bad for design, rarely used and contains
>> many problems for usual users.
>>
>> Every program can be designed only with single inheritance.
> 
> That's how the Java designers were thinking as well: If MI is
> allowed, programmers will suddenly get an irresistible urge to use
> MI to write unmaintainable spaghetti code. So let's disallow MI
> for the sake of common good. 

Argumenting like that, *all* programming languages had to be
outlawed. 8)

Regards,


Björn

-- 
BOFH excuse #391:

We already sent around a notice about that.

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


Re: python-ldap - Operations Error

2008-04-25 Thread Michael Ströder

[EMAIL PROTECTED] wrote:

Thanks for the help guys, it works!  I used the
ldap.set_option(ldap.OPT_REFERRALS, 0) from http://peeved.org/blog/2007/11/20/


Hmm, maybe I should generally switch off referral chasing in python-ldap 
forcing applications to enable it if needed overriding libldap's 
default. I did this already for LDAPObject.protocol_version where 
libldap's default is LDAPv2 and python-ldap sets it to LDAPv3 in 
LDAPObject.__init__(). Although this was an incompatible change no-one 
complained.



immedialtey after import, then did the initialize trace_level=2 and
did the simple_bind_s.  I was able to search and get the results.
That trace_level thing is nice, i'm sure i will be debugging this more
as i move forward :)

Not sure if this is an AD thing or just something i needed to do with
our particular server/config.


Basically the concept of LDAPv3 referrals is broken since there's no 
concept for specifying how to bind to the referral's target without 
a-priori local configuration. See also an old posting to 
news:microsoft.public.windows.server.active_directory related to this:


http://groups.google.com/group/microsoft.public.windows.server.active_directory/msg/d061e0398cc366a5

Ciao, Michael.
--
http://mail.python.org/mailman/listinfo/python-list


multiple pattern regular expression

2008-04-25 Thread micron_make

I am trying to parse a file whose contents are :

parameter=current
max=5A
min=2A

for a single line I used 
for line in file:
print re.search("parameter\s*=\s*(.*)",line).groups()

is there a way to match multiple patterns using regex and return a
dictionary. What I am looking for is (pseudo code)

for line in file:
   re.search("pattern1" OR "pattern2" OR ..,line)

and the result should be {pattern1:match, pattern2:match...}

Also should I be using regex at all here ?

-rohit


-- 
View this message in context: 
http://www.nabble.com/multiple-pattern-regular-expression-tp16895148p16895148.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


ioctl, pass buffer address, howto?

2008-04-25 Thread Neal Becker
I need an ioctl call equivalent to this C code:

my_struct s;
s.p = p; << a pointer to an array of char
s.image_size = image_size;
return (ioctl(fd, xxx, &s));

I'm thinking to use python array for the array of char, but I don't see how
to put it's address into the structure.  Maybe ctypes is the answer?

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


Re: function that accepts any amount of arguments?

2008-04-25 Thread Nick Craig-Wood
Steve Holden <[EMAIL PROTECTED]> wrote:
>  Ken wrote:
> > "Steve Holden" <[EMAIL PROTECTED]> wrote in message 
>  [...]
> >> def mean(*x):
> >> total = 0.0
> >> for v in x:
> >> total += v
> >> return v/len(x)
> >>
> > 
> >  think you want total/len(x) in return statement
> > 
>  Yes indeed, how glad I am I wrote "untested". I clearly wasn't pair 
>  programming when I wrote this post ;-)

Posting to comp.lang.python is pair programming with the entire
internet ;-)


-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: Little novice program written in Python

2008-04-25 Thread Nick Craig-Wood
Rogério Brito <[EMAIL PROTECTED]> wrote:
>  I'm just getting my feet wet on Python and, just for starters, I'm coding 
> some 
>  elementary number theory algorithms (yes, I know that most of them are 
> already 
>  implemented as modules, but this is an exercise in learning the
>  language idioms).

When you are up to speed in python I suggest you check out gmpy for
number theory algorithms.

Eg :-

import gmpy
p = 2
while 1:
print p
p = gmpy.next_prime(p)

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


@@@@ THEY DO DIFFERENT THINGS TO GET HERE@@@@@

2008-04-25 Thread mahalakshmi
HAI !


   EARN MORE MONEY INTERESTED HERE.SEE IN
MY SITE.


THEY DO DIFFERENT THINGS TO
GET HERE


  www.getitlove.blogspot.com

 www.doitbetter5.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiple pattern regular expression

2008-04-25 Thread Arnaud Delobelle
micron_make <[EMAIL PROTECTED]> writes:

> I am trying to parse a file whose contents are :
>
> parameter=current
> max=5A
> min=2A
>
> for a single line I used 
> for line in file:
>   print re.search("parameter\s*=\s*(.*)",line).groups()
>
> is there a way to match multiple patterns using regex and return a
> dictionary. What I am looking for is (pseudo code)
>
> for line in file:
>re.search("pattern1" OR "pattern2" OR ..,line)
>
> and the result should be {pattern1:match, pattern2:match...}
>
> Also should I be using regex at all here ?

If every line of the file is of the form name=value, then regexps are
indeed not needed.  You could do something like that.

params = {}
for line in file:
name, value = line.strip().split('=', 2)
params[name] = value 

(untested)
Then params should be the dictionary you want.

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


Re: problem with unicode

2008-04-25 Thread John Machin
On Apr 25, 9:15 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hi everybody,
>
> I'm using the win32 console and have the following short program
> excerpt
>
> # media is a binary string (mysql escaped zipped file)
>
> >> print media
>
> xワユロ[ヨ ...
> (works)
>
> >> print unicode(media)
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
> 1: ordinal not in range(128)
> (ok i guess print assumes you want to print to ascii)

Guessing is no substitute for reading the manual.

print has nothing to do with your problem; the problem is
unicode(media) -- as you specified no encoding, it uses the default
encoding, which is ascii [unless you have been mucking about, which is
not recommended]. As the 2nd byte is 0x9c, ascii is going nowhere.


>
> >> print unicode(media).encode('utf-8')
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
> 1: ordinal not in range(128)
> (why does this not work?)

Already unicode(media) "doesn't work", so naturally(?)
unicode(media).whatever() won't be better -- whatever won't be called.

>
> # mapString is a unicode string (i think at least)>> print "'" + mapString + 
> "'"
>
> ' yu_200703_hello\ 831 v1234.9874 '
>
> >>mystr = "%s %s" % (mapString, media)
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
> 1: ordinal not in range(128)
>
> >> mystr = "%s %s" % (mapString.encode('utf-8'), media.encode('utf-8'))
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
> 1: ordinal not in range(128)

This is merely repeating the original problem.

>
> I don't know what to do. I just want to concatenate two string where
> apparently one is a binary string, the other one is a unicode string
> and I always seem to get this error.
>
> Any help is appreciated :)

We need a clue or two; do this and let us know what it says:

print type(media), repr(media)
print type(mapString), repr(mapString)
import sys; print sys.stdout.encoding

Also you say that "print media" works. Do you mean that it produces
some meaningful text that you understand? What I see on the screen in
Google Groups is the following 6 characters:
LATIN SMALL LETTER X
KATAKANA LETTER WA
KATAKANA LETTER YU
KATAKANA LETTER RO
LEFT SQUARE BRACKET
KATAKANA LETTER YO
Is that what you see?

What is it that you call "win32 console"?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Little novice program written in Python

2008-04-25 Thread Max M
hellt skrev:

>> Most code is not like that so perhaps you should try something more
>> "usual" like sending email, fetching webpages etc. to get a feel for the
>> language.
>>
> em, i would say, that python (esp. with NumPy+Psyco) is very popular
> in numerical processing also.

I know, and I might be way of, but I would believe that even that would
be more like stringing ready built modules together, calling methods etc.

I have written far denser code that the above example in Python
regularly. But It is like 1%-5% of my code I believe.

Unlike  the c family of languages where there is a lot more algorithms
due to the low level coding. Memory handling, list, dicts etc. qickly
becomes more like math algorithms than in Python.


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

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


Re: Problem building python in virtual machine running centos

2008-04-25 Thread Paul Melis

Paul Boddie wrote:

On 25 Apr, 03:05, Alexandre Gillet <[EMAIL PROTECTED]> wrote:


I am trying to build python-2.4.5 on Centos 5.1, which is a virtual
machine running with xen.
I am not able to build python. The compilation crash with the following:
gcc -pthread -c  -DNDEBUG -g  -O3 -Wall -Wstrict-prototypes -I.
-I./Include  -DPy_BUILD_CORE -o Objects/unicodeobject.o
Objects/unicodeobject.c
In file included from ./Include/Python.h:76,
from Objects/unicodeobject.c:39:
./Include/object.h:228: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See http://bugzilla.redhat.com/bugzilla> for instructions.
The bug is not reproducible, so it is likely a hardware or OS problem.

Any suggestion of what am I doing wrong?



You say that the bug is not reproducible, so that means that you can


"The bug is not reproducible, so it is likely a hardware or OS problem."

This line is printed by GCC itself, not the OP

Paul


sometimes compile Python, or does the crash always happen when
compiling some file (not necessarily the one mentioned above)? I think
I've only ever seen a reproducible gcc crash once, and that had
something to do with a C++ source file which I then split into two and
was able to compile as these two separate parts. You might want to
check the gcc version (gcc -v) and to look at bug fixes in any later
versions. Generally, if you get an internal error in gcc, you aren't
doing anything wrong yourself.

Paul

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


Re: problem with unicode

2008-04-25 Thread John Machin
On Apr 25, 10:01 pm, Bjoern Schliessmann  wrote:
> [EMAIL PROTECTED] wrote:
> > # media is a binary string (mysql escaped zipped file)
>
>  print media
> > x???[? ...
> > (works)
>
> Which encoding, perhaps UTF-8 or ISO8859-1?
>
>  print unicode(media)
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in
> > position 1: ordinal not in range(128)
> > (ok i guess print assumes you want to print to ascii)
>
> Not at all -- unicode tries to decode the byte string you gave it,
> but doesn't know which encoding to use, so it falls back to ASCII.
>
> You should decode all "incoming" byte strings to unicode objects
> using the right encoding -- here I tried yours with UTF-8. This
> works best using string's method "decode" which returns a unicode
> object.
>
> >>> media="x???[?"
> >>> print repr(media.decode("utf-8"))
>
> u'x\u30ef\u30e6\u30ed[\u30e8'
>

But that_unicode_string.encode("utf-8") produces
'x\xe3\x83\xaf\xe3\x83\xa6\xe3\x83\xad[\xe3\x83\xa8'
which does not contain the complained-about byte 0x9c in position 1
(or any other position) -- how can that be?





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


Re: function that accepts any amount of arguments?

2008-04-25 Thread Steve Holden

Nick Craig-Wood wrote:

Steve Holden <[EMAIL PROTECTED]> wrote:

 Ken wrote:
"Steve Holden" <[EMAIL PROTECTED]> wrote in message 

 [...]

def mean(*x):
total = 0.0
for v in x:
total += v
return v/len(x)


 think you want total/len(x) in return statement

 Yes indeed, how glad I am I wrote "untested". I clearly wasn't pair 
 programming when I wrote this post ;-)


Posting to comp.lang.python is pair programming with the entire
internet ;-)



+1 QOTW :)

regards
 Steve
--
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Installation in a local directory

2008-04-25 Thread s.mcdaniel
On Apr 25, 12:37 am, Steve Holden <[EMAIL PROTECTED]> wrote:
> Sean McDaniel wrote:
> > Hi y'all,
>
> > I'm trying to perform a local install of python at work in my user
> > directory. Everything compiles correctly, but I can't seem to tell the
> > configure script the location of the bin and lib directories where I
> > want my stuff. I've think I've passed the correct flags to the
> > 'configure' script.
>
> > make clean
> > ./configure --enable-shared --prefix=/user/mcdaniel/arch32
> > make
>
> > where arch32 contains the the lib and bin directories where I want my
> > python stuff to go.  Unfortunately these directories are not written to;
> > everything ends up in the default location from where I ran 'make'.
> > Moreover, if I add a symbolic link from the python binary (which I can
> > run directly without problems) to the bin directory so that my PATH will
> > recognize the new python, I get an error about loading shared libraries.
>
> > I'm making on a 32 bit new debian system.
>
> > Thank you for your help,
>
> Did you run "make install" yet? It's that step that moves the binaries
> to where they should live. As it says in
>
>http://www.python.org/download/releases/2.5/
>
> """Change to the Python-2.5 directory and run the "./configure", "make",
> "make install" commands to compile and install Python."""
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/

Damnit,

That was exactly the problem. Thank you.

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


Re: wxpython and IEHtmlWindow, Focus Problem.

2008-04-25 Thread Mike Driscoll
On Apr 24, 11:48 pm, Farsheed Ashouri <[EMAIL PROTECTED]> wrote:
> Hi everyone. I create a little browser with wxpython and IEHtmlWindow.
> But I have a little problem here.
> When I press enter in the html page, The focus goes to another panel.
> Why this happens?
> I want to load a html page and it have textares  and user should able
> to press enter inside html page.
>
> This is the code for creating it:
>
> #===Code Begin ==
> class PageOne(wx.Panel):
>     def __init__(self, parent):
>         wx.Panel.__init__(
>             self, parent, -1,
>             style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN|
> wx.NO_FULL_REPAINT_ON_RESIZE
>         )
>
>         self.sizer = wx.BoxSizer(wx.HORIZONTAL)
>         import  wx.lib.iewin    as  iewin
>         a  = iewin.IEHtmlWindow(self, -1 )
>         #a.LoadUrl('file:///E:/Ducuments/EL%20Software%20Project/
> mainSoft/xmlParser/HTML/learn/less2.html')
>         self.sizer.Add(a, 3, wx.EXPAND,1)
>         self.SetSizer(self.sizer)
>         #self.Bind(wx.EVT_TEXT_ENTER , self.OnKeyPress, a)
>         config.CurrentNotebook = a
>
> #===Code End==
>
> Thanks in advance.

I recommend re-posting to the wxPython user's group: 
http://wxpython.org/maillist.php

It may be that you need to set the focus on the html widget and within
the widget, set the focus in one of your text areas. But I don't
really know for sure.

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


PYTHONPATH breaks MySQLdb

2008-04-25 Thread Aljosa Mohorovic
i have a working MySQLdb module (/usr/lib/python2.4/site-packages/
MySQL_python-1.2.2-py2.4-linux-i686.egg), using it without problems.

"clean shell" after login:
python -c "import MySQLdb" reports no errors

if i export PYTHONPATH:
export PYTHONPATH=/var/www/projects/uv_portal/portal

python -c "import MySQLdb" reports no errors as in previous case

if i export PYTHONPATH:
export PYTHONPATH=/var/www/projects/uv_portal/portal/apps

i get this:
python -c "import MySQLdb"
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named MySQLdb

is there any reason why this happens?

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


Re: multiple pattern regular expression

2008-04-25 Thread Robert Bossy

Arnaud Delobelle wrote:

micron_make <[EMAIL PROTECTED]> writes:

  

I am trying to parse a file whose contents are :

parameter=current
max=5A
min=2A

for a single line I used 
for line in file:

print re.search("parameter\s*=\s*(.*)",line).groups()

is there a way to match multiple patterns using regex and return a
dictionary. What I am looking for is (pseudo code)

for line in file:
   re.search("pattern1" OR "pattern2" OR ..,line)

and the result should be {pattern1:match, pattern2:match...}

Also should I be using regex at all here ?



If every line of the file is of the form name=value, then regexps are
indeed not needed.  You could do something like that.

params = {}
for line in file:
name, value = line.strip().split('=', 2)
params[name] = value 


(untested)

I might add before you stumble upon the consequences:
   params[name.rstrip()] = value.lstrip()

Cheers,
RB
--
http://mail.python.org/mailman/listinfo/python-list


Re: Where to get BeautifulSoup--www.crummy.com appears to be down.

2008-04-25 Thread Mike Driscoll
On Apr 24, 1:34 pm, Paul Rubin  wrote:
> Paul Boddie <[EMAIL PROTECTED]> writes:
> > simple Python-only modules, all you'd really need to do to prove the
> > concept is to develop the client-side Windows software (eg. apt-get
> > for Windows) which downloads package lists, verifies signatures, and
> > works out where to put the package contents. ...
>
> I thought the Windows "solution" to this was Authenticode, which is a
> scheme for signing executables against certificates similar to those
> used on SSL web sites.  Of course there's been at least one notorious
> forgery, but typical Linux distro repositories are probably not all
> that secure either.
>
> In the case of a pure Python program like Beautiful Soup, I certainly
> think any installation needing running code should be done by
> distutils included in the Python distro.

I only create binaries using the bdist_wininst or bdist_msi commands
for the extensions. If you think adding a code signature will make the
binaries more acceptable, I'm not against it. Certificates from Comodo
don't cost too much...

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


Re: PYTHONPATH breaks MySQLdb

2008-04-25 Thread Diez B. Roggisch

Aljosa Mohorovic schrieb:

i have a working MySQLdb module (/usr/lib/python2.4/site-packages/
MySQL_python-1.2.2-py2.4-linux-i686.egg), using it without problems.

"clean shell" after login:
python -c "import MySQLdb" reports no errors

if i export PYTHONPATH:
export PYTHONPATH=/var/www/projects/uv_portal/portal

python -c "import MySQLdb" reports no errors as in previous case

if i export PYTHONPATH:
export PYTHONPATH=/var/www/projects/uv_portal/portal/apps

i get this:
python -c "import MySQLdb"
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named MySQLdb

is there any reason why this happens?


Yes. You found a secret that nobody was supposed to know: Python doesn't 
allow portal applications te be written! So it scans the pythonpath for 
a suffix of "portal/apps", and refuses to import anything if it finds it.


Seriously: yes, there must be a reason, but nobody can tell because we 
don't know & see what is beyond the apps-dir that might cause trouble. 
Generally speaking, given that you can properly import MySQLdb without 
any path set, you need to see if there is anything in your path that 
somehow gets imported first and e.g. alters the sys.path.


Try

python -vc 'import MySQLdb'

and if that doesn't make things clearer, use strace.

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


Re: Little novice program written in Python

2008-04-25 Thread Robert Bossy

Marc 'BlackJack' Rintsch wrote:
Indeed. Would it be a sensible proposal that sequence slices should 
return an iterator instead of a list?



I don't think so as that would break tons of code that relies on the
current behavior.  Take a look at `itertools.islice()` if you want/need
an iterator.
A pity, imvho. Though I can live with islice() even if it is not as 
powerful as the [:] notation.


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


Re: problem with unicode

2008-04-25 Thread Matt Nordhoff
[EMAIL PROTECTED] wrote:
> Hi everybody,
> 
> I'm using the win32 console and have the following short program
> excerpt
> 
> # media is a binary string (mysql escaped zipped file)
> 
>>> print media
> xワユロ[ヨ...
> (works)
> 
>>> print unicode(media)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
> 1: ordinal not in range(128)
> (ok i guess print assumes you want to print to ascii)



> I don't know what to do. I just want to concatenate two string where
> apparently one is a binary string, the other one is a unicode string
> and I always seem to get this error.
> 
> Any help is appreciated :)

You should read the Python Unicode documentation, such as:





and maybe a non-Python-specific article:


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

Environment Variables

2008-04-25 Thread Krishna
Environment variable set up is the most confusing part for me all the
time. Please help me with the following questions:

When I install python in a new system, I will go to environment
variables (system variables) and set "path" pointing to C:\Python25
and thats all I do.
I type python from "cmd" window and its converting to python window
for python execution. All fine up to this point.
Now, I want to drag and drop python (.py) files to this window and
execute it. My python files are located in different directories
inside C: and outside C:. When I do that, I get errors and the file is
not found and its not imported. ALso, inside the .py file, if I have a
command to open a different file, it doesnt see that either. How do I
overcome these basic difficulties in python. I wish I can open any
file and work on that using python.


Thanks for your help!
Krishna
--
http://mail.python.org/mailman/listinfo/python-list


Re: Environment Variables

2008-04-25 Thread Mike Driscoll
On Apr 25, 8:07 am, Krishna <[EMAIL PROTECTED]> wrote:
> Environment variable set up is the most confusing part for me all the
> time. Please help me with the following questions:
>
> When I install python in a new system, I will go to environment
> variables (system variables) and set "path" pointing to C:\Python25
> and thats all I do.
> I type python from "cmd" window and its converting to python window
> for python execution. All fine up to this point.
> Now, I want to drag and drop python (.py) files to this window and
> execute it. My python files are located in different directories
> inside C: and outside C:. When I do that, I get errors and the file is
> not found and its not imported. ALso, inside the .py file, if I have a
> command to open a different file, it doesnt see that either. How do I
> overcome these basic difficulties in python. I wish I can open any
> file and work on that using python.
>
> Thanks for your help!
> Krishna

I'm pretty sure you can't do that in a command window. I tried it on
my Windows XP machine and all I get in my instance of IDLE is the path
to the file. It DOES work with PythonWin, which is the ActiveState
version of Python. The only difference is that it include the win32
modules and has a more advanced editor.

You can probably get this to work in other more advanced editors, like
WingIDE or PyDev too.

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


Re: Is 2006 too old for a book on Python?

2008-04-25 Thread Steve Holden

jmDesktop wrote:

Hi, I wanted to buy a book on Python, but am concerned that some of
them are too old.  One I had come to after much research was Core
Python by Wesley Chun.  I looked at many others, but actually saw this
one in the store and liked it.  However, it is from 2006.  I know
there is free documentation and Dive Into Python.  I just liked the
one in question and was hoping for thoughts on the age of it.  I am
using Python 2.5.x and don' t know how different 2.3, 2,4 is from it.


Buy it if you like it (and lots of people do). Less than 1% of the 
language changes between releases. You'll pick the rest up here!


regards
 Steve
--
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Is 2006 too old for a book on Python?

2008-04-25 Thread jmDesktop
Hi, I wanted to buy a book on Python, but am concerned that some of
them are too old.  One I had come to after much research was Core
Python by Wesley Chun.  I looked at many others, but actually saw this
one in the store and liked it.  However, it is from 2006.  I know
there is free documentation and Dive Into Python.  I just liked the
one in question and was hoping for thoughts on the age of it.  I am
using Python 2.5.x and don' t know how different 2.3, 2,4 is from it.

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


Re: Is 2006 too old for a book on Python?

2008-04-25 Thread Matt Nordhoff
jmDesktop wrote:
> Hi, I wanted to buy a book on Python, but am concerned that some of
> them are too old.  One I had come to after much research was Core
> Python by Wesley Chun.  I looked at many others, but actually saw this
> one in the store and liked it.  However, it is from 2006.  I know
> there is free documentation and Dive Into Python.  I just liked the
> one in question and was hoping for thoughts on the age of it.  I am
> using Python 2.5.x and don' t know how different 2.3, 2,4 is from it.
> 
> Thank you.

Python 2.x releases maintain backwards compatibility. There are nice
features that have come since 2.3, but it's not like it's a different
language. You could learn from a slightly old book, then do some
research to find out what you missed. ('with' statement, ternary
operator, smaller things in the stdlib. Maybe generators? What else?)

Now, Python 3 will break backwards compatibility and make more
significant changes than usual, but it will still be basically the same
language, so the same thing applies. And anyway, it won't be very
relevant for a few years.
-- 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Environment Variables

2008-04-25 Thread Steve Holden

Krishna wrote:

Environment variable set up is the most confusing part for me all the
time. Please help me with the following questions:

When I install python in a new system, I will go to environment
variables (system variables) and set "path" pointing to C:\Python25
and thats all I do.
I type python from "cmd" window and its converting to python window
for python execution. All fine up to this point.
Now, I want to drag and drop python (.py) files to this window and
execute it. My python files are located in different directories
inside C: and outside C:. When I do that, I get errors and the file is
not found and its not imported. ALso, inside the .py file, if I have a
command to open a different file, it doesnt see that either. How do I
overcome these basic difficulties in python. I wish I can open any
file and work on that using python.


http://www.python.org/doc/faq/windows/#how-do-i-run-a-python-program-under-windows

regards
 Steve
--
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Environment Variables

2008-04-25 Thread Krishna
On Apr 25, 9:17 am, Mike Driscoll <[EMAIL PROTECTED]> wrote:
> On Apr 25, 8:07 am, Krishna <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Environment variable set up is the most confusing part for me all the
> > time. Please help me with the following questions:
>
> > When I install python in a new system, I will go to environment
> > variables (system variables) and set "path" pointing to C:\Python25
> > and thats all I do.
> > I type python from "cmd" window and its converting to python window
> > for python execution. All fine up to this point.
> > Now, I want to drag and drop python (.py) files to this window and
> > execute it. My python files are located in different directories
> > inside C: and outside C:. When I do that, I get errors and the file is
> > not found and its not imported. ALso, inside the .py file, if I have a
> > command to open a different file, it doesnt see that either. How do I
> > overcome these basic difficulties in python. I wish I can open any
> > file and work on that using python.
>
> > Thanks for your help!
> > Krishna
>
> I'm pretty sure you can't do that in a command window. I tried it on
> my Windows XP machine and all I get in my instance of IDLE is the path
> to the file. It DOES work with PythonWin, which is the ActiveState
> version of Python. The only difference is that it include the win32
> modules and has a more advanced editor.
>
> You can probably get this to work in other more advanced editors, like
> WingIDE or PyDev too.
>
> Mike- Hide quoted text -
>
> - Show quoted text -

So, how do I get the win32 module and what to do with that? Just
install it?

Thanks,
Krishna
--
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Python code from inside php

2008-04-25 Thread Diez B. Roggisch

Nick Stinemates schrieb:
While I certainly prefer to use Python wherever I can, that does not mean 
that there aren't cases where legacy systems or other constraints make this 
impossible. If I have e.g. a type3-based website - "how on earth" should I 
replace that with Python (without wasting a lot of time)?


I don't understand how the 2 are mutually exclusive?

You can have PHP and Python bindings installed on the same Apache
server, unless I'm mistaken?


What about having to set up & maintain (which might not even possible on 
a cheap hoster) two configs for that - just for having a few lines of 
python being run? And how do you go about session-state sharing and so 
forth? After all the scipt might need to be access controlled based on 
login state.


I don't say that there aren't options to run python more direct. I 
argumented against a rather bold statement of Mr. alexelder:


"""
A simple yet dangerous and rather rubbish solution (possibly more of a
hack than a real implementation) could be achieved by using a
technique described above:
"""

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


Re: Can you recommend a book?

2008-04-25 Thread Daniel Folkes
On Apr 25, 6:28 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hello all, I learned Python with the book "Programming Python" by John
> Zelle. But today this book is a little bit old. My Python is some kind
> old. I need a book that will help me brush my style and keep me up to
> date. I would like one with practical examples.
>
> Can you recommend one?

Learning Python followed by Programming Python.

You should be able to find them in a Library too.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Remove multiple inheritance in Python 3000

2008-04-25 Thread sturlamolden
On Apr 25, 2:03 pm, Bjoern Schliessmann  wrote:

> > That's how the Java designers were thinking as well: If MI is
> > allowed, programmers will suddenly get an irresistible urge to use
> > MI to write unmaintainable spaghetti code. So let's disallow MI
> > for the sake of common good.
>
> Argumenting like that, *all* programming languages had to be
> outlawed. 8)

James Gosling, grossed by C++ iostreams, also used this argument to
disallow operator overloading in Java (except for the String class).
That is why Python has NumPy and Java does not.

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


problem with mmap

2008-04-25 Thread Neal Becker
On linux, I don't understand why:

f = open ('/dev/eos', 'rw')
m = mmap.mmap(f.fileno(), 100, prot=mmap.PROT_READ|mmap.PROT_WRITE,
flags=mmap.MAP_SHARED)

gives 'permission denied', but this c++ code works:

#include 
#include 
#include 
#include 
#include 

int main() {
  int fd = open ("/dev/eos", O_RDWR);
  void* m = mmap (NULL, 100, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  std::cout << m << '\n';
}


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


Re: multiple pattern regular expression

2008-04-25 Thread python
How about this?

for line in file:
# ignore lines without = assignment
if '=' in line:
property, value = line.strip().split( '=', 1 )
property = property.strip().lower()
value = value.strip()

# do something with property, value

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


Brand Watches Seiko Men's Premier Alarm Chronograph Watch # SNA209P1 Discount, Swiss, Fake

2008-04-25 Thread blog534
Brand Watches Seiko Men's Premier Alarm Chronograph Watch # SNA209P1
Discount, Swiss, Fake

Browse our Seiko Men's Premier Alarm Chronograph Watch # SNA209P1
Swiss watches, which is sure the watch you are looking for at low
price. There are more high quality designer watch Swiss for selection

Seiko Men's Premier Alarm Chronograph Watch # SNA209P1 Link :
http://www.watches-brand.com/Seiko-wristwatch-7566.html

Brand :  Seiko ( http://www.watches-brand.com/Seiko-Watches.html )

Model :  Seiko Men's Premier Alarm Chronograph Watch # SNA209P1

Description :
Seiko Men's Premier Alarm Chronograph Watch . 100 meters water
resistant. LumiBrite Hands & Markers. Curved Sapphire Crystal. Alarm
hands can indicate the time in a different time zone. Chronograph can
measure up to 60 minutes in 1/5 seconds. Alarm can be set on a 12-hour
basis with two small hands. Hour, minute and small second hands. White
dial. # SNA209 #.


Sale Price :  $ 229.00

Seiko Men's Premier Alarm Chronograph Watch # SNA209P1 Details :


   
Watches-Price Sales Rank: #61722 in Watches

Brand: Seiko
Model: SNA209
Band material: stainless-steel
Case material: stainless-steel
Dial color: White
Movement type: Quartz
Water-resistant to 100 meters




Seiko Men's Premier Alarm Chronograph Watch # SNA209P1 is new brand
Swiss, join thousands of satisfied customers and buy your Seiko with
total satisfaction. A watches-brand.COM 30 Day Money Back Guarantee is
included with every Seiko Fake Series for secure, risk-free online
shopping. watches-brand.COM does not charge sales tax for the Fake
Seiko Men's Premier Alarm Chronograph Watch # SNA209P1.

All of our Fake watches are shipped via EMS to worldwide. Normally it
takes 3days to prepare the fake watch you ordered and 5-10days to
transmit depending on the different destination.We pay for the free
shipping cost for total quantity over 20 pcs. The EMS tracking NO.
will be sent by email when an order is shipped from our warehouse. No
more other charges from watches-brand.com such as the tax. If you have
any other questions please check our other pages or feel free to email
us by [EMAIL PROTECTED]


The Same Fake Seiko Watches Series :

Seiko Men's Premier Automatic (Made in Japan) Watch # SPB003J1 :
http://www.watches-brand.com/Seiko-wristwatch-7567.html

Seiko Men's Premier Automatic (Made in Japan) Watch # SPB005J1 :
http://www.watches-brand.com/Seiko-wristwatch-7568.html

Seiko Men's Premier Automatic All Stainless-Steel Watch with a Black
Dial. Model: SPB001J :
http://www.watches-brand.com/Seiko-wristwatch-7569.html

Seiko Men's Premier Chronograph Watch SDWG45 :
http://www.watches-brand.com/Seiko-wristwatch-7570.html

Seiko Men's Premier Chronograph Watch SDWG47 :
http://www.watches-brand.com/Seiko-wristwatch-7571.html

Seiko Men's Premier Kinetic Auto Relay Watch with Blue Dial. Model:
SNG037 :
http://www.watches-brand.com/Seiko-wristwatch-7572.html

Seiko Men's Premier Kinetic Direct Drive Quartz- Kinetic 100M Water
Resistant Watch # SRG001P1 :
http://www.watches-brand.com/Seiko-wristwatch-7573.html

Seiko Men's Premier Kinetic Direct Drive Quartz- Kinetic 100M Water
Resistant Watch # SRG001P2 :
http://www.watches-brand.com/Seiko-wristwatch-7574.html

Seiko Men's Premier Kinetic Perpetual Calendar Black Dial Watch #
SNP005P1 :
http://www.watches-brand.com/Seiko-wristwatch-7575.html

Seiko Men's Premier Kinetic Perpetual Calendar Silver Dial with Seiko
Original Leather Strap Watch # SNP015P1 :
http://www.watches-brand.com/Seiko-wristwatch-7576.html

Brand Watches Seiko Men's Premier Alarm Chronograph Watch # SNA209P1
Discount, Swiss, Fake
--
http://mail.python.org/mailman/listinfo/python-list


Brand Watches Ebel Women's 1911 Two-Tone Watch #1087221-9365P Discount, Swiss, Fake

2008-04-25 Thread blog534
Brand Watches Ebel Women's 1911 Two-Tone Watch #1087221-9365P
Discount, Swiss, Fake

Browse our Ebel Women's 1911 Two-Tone Watch #1087221-9365P Swiss
watches, which is sure the watch you are looking for at low price.
There are more high quality designer watch Swiss for selection

Ebel Women's 1911 Two-Tone Watch #1087221-9365P Link :
http://www.watches-brand.com/Ebel-wristwatch-3181.html

Brand :  Ebel ( http://www.watches-brand.com/Ebel-Watches.html )

Model :  Ebel Women's 1911 Two-Tone Watch #1087221-9365P

Description :
Ebel Women's 1911 18k and Steel Watch


Sale Price :  $ 209.00

Ebel Women's 1911 Two-Tone Watch #1087221-9365P Details :


   
Brand: Ebel
Model: 1087221-9365P
Band material: steel-and-18k-gold
Bezel material: steel-and-18k-gold
Case material: steel-and-18k-gold
Clasp type: fold-over-clasp
Dial color: white-mother-of-pearl
Dial window material: scratch-resistant-sapphire
Movement type: swiss-quartz
Water-resistant to 330 feet




Ebel Women's 1911 Two-Tone Watch #1087221-9365P is new brand Swiss,
join thousands of satisfied customers and buy your Ebel with total
satisfaction. A watches-brand.COM 30 Day Money Back Guarantee is
included with every Ebel Fake Series for secure, risk-free online
shopping. watches-brand.COM does not charge sales tax for the Fake
Ebel Women's 1911 Two-Tone Watch #1087221-9365P.

All of our Fake watches are shipped via EMS to worldwide. Normally it
takes 3days to prepare the fake watch you ordered and 5-10days to
transmit depending on the different destination.We pay for the free
shipping cost for total quantity over 20 pcs. The EMS tracking NO.
will be sent by email when an order is shipped from our warehouse. No
more other charges from watches-brand.com such as the tax. If you have
any other questions please check our other pages or feel free to email
us by [EMAIL PROTECTED]


The Same Fake Ebel Watches Series :

Ebel 1911 BTR Black Strap Dial Chronograph Mens Watch
9137L73.5335145 :
http://www.watches-brand.com/Ebel-wristwatch-3182.html

Ebel 1911 BTR Stainless Steel Mens Watch 9240L70.6360 :
http://www.watches-brand.com/Ebel-wristwatch-3183.html

Ebel 1911 BTR Stainless Steel Chronograph Mens Watch 9137L72.5360 :
http://www.watches-brand.com/Ebel-wristwatch-3184.html

Ebel Brasilia Mens Black Dial Stainless Steel Automaic Watch
9120M41/52500 / 1215615 :
http://www.watches-brand.com/Ebel-wristwatch-3185.html

Ebel Brasilia Mens Silver Dial Stainless Steel Automaic Watch
9120M41/62500 / 1215614 :
http://www.watches-brand.com/Ebel-wristwatch-3186.html

Ebel Brasilia Men's Brown Strap Silver Dial Stainless Steel Automatic
Watch 9120M41.6235134 / 1215616 :
http://www.watches-brand.com/Ebel-wristwatch-3187.html

Ebel Brasilia Men's Silver Dial Stainless Steel Watch 9255M41/62500 /
1215598 :
http://www.watches-brand.com/Ebel-wristwatch-3188.html

Ebel Sport Classic_Watch Watch 1090141/0225 :
http://www.watches-brand.com/Ebel-wristwatch-3189.html

Ebel Sport Classic Stainless Steel & 18k gold Mens Watch -
1187141/1225 :
http://www.watches-brand.com/Ebel-wristwatch-3190.html

Ebel Sport Classic Stainless Steel & 18k gold Mens Watch -
1188141/0106 :
http://www.watches-brand.com/Ebel-wristwatch-3191.html

Brand Watches Ebel Women's 1911 Two-Tone Watch #1087221-9365P
Discount, Swiss, Fake
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unix Device File Emulation

2008-04-25 Thread blaine
On Apr 24, 3:38 am, "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote:
> On 2008-04-23, blaine <[EMAIL PROTECTED]> wrote:
>
> > On Apr 23, 2:01 pm, "Martin Blume" <[EMAIL PROTECTED]> wrote:
> >> "blaine" schrieb
> >> No,
> >>   while 1:
> >>   r = self.fifodev.readline()
> >>   if r: print r
> >>   else: time.sleep(0.1)
> >> is ok (note the "if r:" clause).
>
> >> Martin
>
> > Beautiful! Thanks Martin!
>
> yes, but you have to follow the usual file handling rules, and close/re-open
> the fifo after detecting EOF. You will be blocked on attempting to re-open
> until there is another writing process.
>
> while 1:
>   fp = open('my_fifo', 'r')
>   while 1:
>  line = fp.readline()
>  if line == '':
> break
>  print line.rstrip()# To prevent printing of \n in line
>   fp.close()
>
> Albert

Oh, good call. Thanks a lot, that really helps.  I felt that the
previous solution was workable, but not perhaps 100% correct.

Thanks Albert!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Environment Variables

2008-04-25 Thread Mike Driscoll
On Apr 25, 8:26 am, Krishna <[EMAIL PROTECTED]> wrote:
> On Apr 25, 9:17 am, Mike Driscoll <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Apr 25, 8:07 am, Krishna <[EMAIL PROTECTED]> wrote:
>
> > > Environment variable set up is the most confusing part for me all the
> > > time. Please help me with the following questions:
>
> > > When I install python in a new system, I will go to environment
> > > variables (system variables) and set "path" pointing to C:\Python25
> > > and thats all I do.
> > > I type python from "cmd" window and its converting to python window
> > > for python execution. All fine up to this point.
> > > Now, I want to drag and drop python (.py) files to this window and
> > > execute it. My python files are located in different directories
> > > inside C: and outside C:. When I do that, I get errors and the file is
> > > not found and its not imported. ALso, inside the .py file, if I have a
> > > command to open a different file, it doesnt see that either. How do I
> > > overcome these basic difficulties in python. I wish I can open any
> > > file and work on that using python.
>
> > > Thanks for your help!
> > > Krishna
>
> > I'm pretty sure you can't do that in a command window. I tried it on
> > my Windows XP machine and all I get in my instance of IDLE is the path
> > to the file. It DOES work with PythonWin, which is the ActiveState
> > version of Python. The only difference is that it include the win32
> > modules and has a more advanced editor.
>
> > You can probably get this to work in other more advanced editors, like
> > WingIDE or PyDev too.
>
> > Mike- Hide quoted text -
>
> > - Show quoted text -
>
> So, how do I get the win32 module and what to do with that? Just
> install it?
>
> Thanks,
> Krishna

ActivePython can be found on the ActiveState website:

http://www.activestate.com/Products/activepython/?_x=1

This will basically just add whatever modules needed if Python is
already installed and it will also install another editor called
pythonwin, which you should be able to find in your start menu.

But be sure to check out that link that Steve gave you. That might
work for you too.

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


Subclassing list the right way?

2008-04-25 Thread Kirk Strauser
I want to subclass list so that each value in it is calculated at call
time.  I had initially thought I could do that by defining my own
__getitem__, but 1) apparently that's deprecated (although I can't
find that; got a link?), and 2) it doesn't work.

For example:

>>> class Foo(list):
... def __getitem__(self, index):
... return 5
...
>>> a = Foo([1, 2, 3, 4, 5])
>>> print a
[1, 2, 3, 4, 5]
>>> print a[2:4]
[3, 4]
>>> print a[3]
5

I first expected that to instead behave like:

>>> print a
[5, 5, 5, 5, 5]
>>> print a[2:4]
[5, 5]

Is there a "right" way to do this?
--
Kirk Strauser
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem building python in virtual machine running centos

2008-04-25 Thread Paul Boddie
On 25 Apr, 14:16, Paul Melis <[EMAIL PROTECTED]> wrote:
>
> "The bug is not reproducible, so it is likely a hardware or OS problem."
>
> This line is printed by GCC itself, not the OP

It's a strange thing for anyone to claim in an error message, though,
especially if it is reproducible. Perhaps some people have special
criteria for reproducibility.

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


why does the following with Queue, q.put('\x02', True) not put it in the queue?

2008-04-25 Thread Gabriel Rossetti

Hello,

I'm having some trouble with the Queue class, for some reason, if I do 
this (ch == ) :


q = Queue.Queue(0)
repr(ch)
q.put(ch, True)
len(q.queue)

where the output is :

'\x02'
0

why isn't the character/string being put it in the queue?

Thank you,
Gabriel
--
http://mail.python.org/mailman/listinfo/python-list


Re: Where to get BeautifulSoup--www.crummy.com appears to be down.

2008-04-25 Thread John Nagle

Paul Rubin wrote:

Paul Boddie <[EMAIL PROTECTED]> writes:

simple Python-only modules, all you'd really need to do to prove the
concept is to develop the client-side Windows software (eg. apt-get
for Windows) which downloads package lists, verifies signatures, and
works out where to put the package contents. ...


I thought the Windows "solution" to this was Authenticode, which is a
scheme for signing executables against certificates similar to those
used on SSL web sites.  Of course there's been at least one notorious
forgery, but typical Linux distro repositories are probably not all
that secure either.

In the case of a pure Python program like Beautiful Soup, I certainly
think any installation needing running code should be done by
distutils included in the Python distro.


   Yes.

   Perl has CPAN, which is reasonably comprehensive and presents modules
in a uniform way.  If you need a common Perl module that's not in the
Perl distro, it's probably in CPAN. "Installing a new module can be as
simple as typing perl -MCPAN -e 'install Chocolate::Belgian'."
So Perl has exactly that.

   Python's Cheese Shop is just a list of links to packages
elsewhere.  There's no uniformity, no standard installation, no
standard uninstallation, and no standard version control.

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


Re: why does the following with Queue, q.put('\x02', True) not put it in the queue?

2008-04-25 Thread sturlamolden
On Apr 25, 4:38 pm, Gabriel Rossetti
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm having some trouble with the Queue class, for some reason, if I do
> this (ch ==  ) :
>
> q = Queue.Queue(0)
> repr(ch)
> q.put(ch, True)
> len(q.queue)

>>> from Queue import Queue
>>> q = Queue(0)
>>> s = '\x02'
>>> q.put(s,True)
>>> len(q.queue)
1



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


Re: Class Inheritance - What am I doing wrong?

2008-04-25 Thread Bruno Desthuilliers

Brian Munroe a écrit :

Ok, so thanks everyone for the helpful hints.  That *was* a typo on my
part (should've been super(B...) not super(A..), but I digress)

I'm building a public API.  Along with the API I have a few custom
types that I'm expecting API users to extend, if they need too.  If I
don't use name mangling, isn't that considered bad practice (read not
defensive programming) to not protect those 'private' fields?


There would be a lot to say about whether defensive programming is a 
good practice or not. At least in the context of hi-level languages with 
exception handling and automatic memory management.


Anyway:
- there's just no way to make anything truly "private" in Python
- the convention is that attributes (including methods - they are 
attributes too) whose name starts with a single leading underscore are 
implementation stuff and should not be messed with. IOW, the contract is 
"mess with them and you're on your own".
- name mangling is only useful when you really need to make sure an 
implementation attribute won't be *accidentally* shadowed. These 
attributes should only be used by methods that are not themselves 
supposed to be overridden or extended by user code. FWIW, I must have 
used them less than half a dozen times in 7+ years (and I wrote more 
than a couple mini-frameworks, with lot of black-juju metaclasses and 
custom descriptors magic in them).


So just use single-leading-underscore for implementation attributes, and 
document what the users are supposed to extend and what they're supposed 
to leave alone.


My 2 cents.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Python code from inside php

2008-04-25 Thread sturlamolden
On Apr 23, 9:13 pm, [EMAIL PROTECTED] wrote:

> A simple yet dangerous and rather rubbish solution (possibly more of a
> hack than a real implementation) could be achieved by using a
> technique described above:
>
>  echo exec('python foo.py');

This will spawn a Python interpreter, and not be particularly
efficient. You could just as well have used CGI.

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


Re: Class Inheritance - What am I doing wrong?

2008-04-25 Thread Brian Munroe
On Apr 24, 10:11 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:

> In python, use attributes starting with a single underscore (such as
> _name).  It tells users that they shouldn't mess with them.  By
> design, python doesn't include mechanisms equivalent to the Java / C++
> 'private'.

Arnaud, Gabriel:

Ok, Ok, I'll trust my users to not abuse my API :)  I didn't realize
that 'private' meant 'private, even to sub-classes' - it is all
becoming clear to me now!

Thanks for the help, and I'm going to re-read 'Python is Not Java'
right about now (I've spent the past few months knee-deep in Java, I
guess I need to cleanse myself)
--
http://mail.python.org/mailman/listinfo/python-list


Re: why does the following with Queue, q.put('\x02', True) not put it in the queue?

2008-04-25 Thread Gabriel Rossetti


Arimaz SA
Av. du 24 Janvier 11
Ateliers de la Ville de Renens, Atelier 5
1020 Renens, Switzerland
www.mydeskfriend.com
Mob: +41-(0)79-539-0069
Tel: +41-(0)21-566-7343



sturlamolden wrote:

On Apr 25, 4:38 pm, Gabriel Rossetti
<[EMAIL PROTECTED]> wrote:
  

Hello,

I'm having some trouble with the Queue class, for some reason, if I do
this (ch ==  ) :

q = Queue.Queue(0)
repr(ch)
q.put(ch, True)
len(q.queue)



  

from Queue import Queue
q = Queue(0)
s = '\x02'
q.put(s,True)
len(q.queue)


1



  
yes, if you do it that way (s = '\x02') it works, but I read the data 
from a file, and I that way it doesn't work

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


Re: Tkinter scrollbar and checkbox

2008-04-25 Thread goldtech
snip...
>
> I use wxPython most of the time, however effbot has a good tutorial on
> scrollbars for Tkinter that I think you might find helpful:
>
> http://effbot.org/zone/tkinter-scrollbar-patterns.htm
>
> Here's another link on the subject:
>
> http://www.pythonware.com/library/tkinter/introduction/scrollbar.htm
>
> HTH
>
> Mike

Indeed, I see it:

http://effbot.org/zone/tkinter-autoscrollbar.htm

Many Thanks.

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


Re: Subclassing list the right way?

2008-04-25 Thread Virgil Dupras
On Apr 25, 4:03 pm, Kirk Strauser <[EMAIL PROTECTED]> wrote:
> I want to subclass list so that each value in it is calculated at call
> time.  I had initially thought I could do that by defining my own
> __getitem__, but 1) apparently that's deprecated (although I can't
> find that; got a link?), and 2) it doesn't work.
>
> For example:
>
> >>> class Foo(list):
>
> ...     def __getitem__(self, index):
> ...             return 5
> ...>>> a = Foo([1, 2, 3, 4, 5])
> >>> print a
> [1, 2, 3, 4, 5]
> >>> print a[2:4]
> [3, 4]
> >>> print a[3]
>
> 5
>
> I first expected that to instead behave like:
>
> >>> print a
> [5, 5, 5, 5, 5]
> >>> print a[2:4]
>
> [5, 5]
>
> Is there a "right" way to do this?
> --
> Kirk Strauser

I'm not totally sure, but I think you have to implement __getslice__
as well, even if it is a deprecated magic function. My guess for this
is that list implements __getslice__ and when you ask for a slice,
Python checks for __getslice__ first, and then, if you don't have it,
calls __getitem__. And since list has it, it's what is called.

As for "print a", you have to override __str__ and __repr__ too.

As a side note, the second argument to __getitem__ is not index, it's
key, because this argument can either be an int index or a slice()
object.
--
http://mail.python.org/mailman/listinfo/python-list


Having problems with wxPython - HELP!!

2008-04-25 Thread Marlin Rowley
I'm desperately spending too much time trying to understand wxPython and it's 
leading me nowhere.

I'm trying to make a script that will create a window, and then immediately 
fill this window with a background color.  I also want to be able to fill this 
window with a background color anytime I need to, therefore I put it in a 
function called "InitBuffer()".  

Problem 1:  Python doesn't clear the window with "Grey" (my background color) 
when it is initially created.  Why?  
Problem 2: OnPaint() seems to always get called for whatever reason.  Fine.  
But I only want it to refresh the contents of the window.  So, if I draw to the 
Client window a series of rectangles, the ONLY thing I want OnPaint() to do is 
refresh what has already been draw to the screen.  The ONLY time it should 
clear the screen is when I call InitBuffer().  How do I do this?


Here's my code:

# Mental Ray Thread
class runMentalRayThread(threading.Thread):
def __init__(self,sFile,renderWindow):
threading.Thread.__init__(self)
self.filename = sFile
self.threadID = os.getpid()
self.renderBuffer = renderWindow

# poll the file using yet another thread.  When that returns,
# capture the mental ray stream and render to the canvas.
def run(self):
self.portInfo = queryMentalRay(self.filename) 
self.renderBuffer.InitBuffer()  
scanMR(self.portInfo[0], self.portInfo[1], self)

# Render Window
class RenderWindow(wx.Window):
def __init__(self,parent,ID,pos,size):
wx.Window.__init__(self,parent,ID,pos,size)
self.renderThread = runMentalRayThread(filename,self)
self.SetBackgroundColour("Grey")
self.Bind(wx.EVT_IDLE, self.OnIdle)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.InitBuffer()
 
# Our initial buffer must be set and background cleared.   
def InitBuffer(self):
print 'InitBuffer() called...'
self.ClearBackground()
   
# Idle function.  Wait for a render
def OnIdle(self,event):
if not self.renderThread.isAlive():
print 'Starting thread to poll Mental Ray...'
self.renderThread = runMentalRayThread(filename,self)
self.renderThread.start()
   
# Refreshes the window. 
def OnPaint(self,event):
print 'OnPaint() called...'
dc = wx.PaintDC(self)


# Closing the render window, we need to 
# kill the thread attached to Mental Ray. 
def OnClose(self,event):
if self.renderThread.isAlive():
# kill the thread
os.popen("kill -9 "+str(self.renderThread.threadID))

_
Spell a grand slam in this game where word skill meets World Series. Get in the 
game.
http://club.live.com/word_slugger.aspx?icid=word_slugger_wlhm_admod_april08--
http://mail.python.org/mailman/listinfo/python-list

Re: why does the following with Queue, q.put('\x02', True) not put it in the queue?

2008-04-25 Thread Jerry Hill
On Fri, Apr 25, 2008 at 11:11 AM, Gabriel Rossetti
<[EMAIL PROTECTED]> wrote:
>  yes, if you do it that way (s = '\x02') it works, but I read the data from
> a file, and I that way it doesn't work

It does work (using Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45)
[MSC v.1310 32 bit (Intel)] on win32)

import Queue
f = open('temp', 'w')
f.write('\x02')
f.close()

f = open('temp', 'r')
ch = f.read(1)
f.close()

print repr(ch)
q = Queue.Queue(0)
q.put(ch, True)
print len(q.queue)

prints the following:
'\x02'
1

Perhaps you could put together an example that actually shows the
behavior you're seeing.  I'm not super familiar with Queue.Queue
internals, but should you be accessing the undocumented q.queue (the
internal deque of the Queue instance) directly?  Shouldn't you be
using the documented q.qsize() interface instead?

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


Subclassing datetime.date does not seem to work

2008-04-25 Thread Rick King




I would like to subclass datetime.date so that I can write:

d = date2('12312008')

I tried:

from datetime import date
class date2(date):
    def __init__( self, strng ):
    mm,dd,yy = int(strng[:2]), int(strng[2:4]), int(strng[4:])
    date.__init__(self,yy,mm,dd)

But then this statement:
d = date2('12312008')

Causes:
TypeError: function takes exactly 3 arguments (1 given)

Is there something basically wrong with subclassing date?
-Rick King


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

Brand Watches Seiko Men's Watches Premier SNA745P - AA Discount, Swiss, Fake

2008-04-25 Thread watches0560
Brand Watches Seiko Men's Watches Premier SNA745P - AA Discount,
Swiss, Fake

Browse our Seiko Men's Watches Premier SNA745P - AA Swiss watches,
which is sure the watch you are looking for at low price. There are
more high quality designer watch Swiss for selection

Seiko Men's Watches Premier SNA745P - AA Link :
http://www.watches-brand.com/Seiko-wristwatch-7594.html

Brand :  Seiko ( http://www.watches-brand.com/Seiko-Watches.html )

Model :  Seiko Men's Watches Premier SNA745P - AA

Description :
Seiko watches - indispensable for today's lifestyle. Seiko watches
- an important accessory for today's lifestyle.


Sale Price :  $ 245.00

Seiko Men's Watches Premier SNA745P - AA Details :


   
Brand: Seiko
Band material: Black Leather Strap
Case material: Stainless Steel
Dial color: Black
Movement type: Quartz
Water-resistant to 100 meters




Seiko Men's Watches Premier SNA745P - AA is new brand Swiss, join
thousands of satisfied customers and buy your Seiko with total
satisfaction. A watches-brand.COM 30 Day Money Back Guarantee is
included with every Seiko Fake Series for secure, risk-free online
shopping. watches-brand.COM does not charge sales tax for the Fake
Seiko Men's Watches Premier SNA745P - AA.

All of our Fake watches are shipped via EMS to worldwide. Normally it
takes 3days to prepare the fake watch you ordered and 5-10days to
transmit depending on the different destination.We pay for the free
shipping cost for total quantity over 20 pcs. The EMS tracking NO.
will be sent by email when an order is shipped from our warehouse. No
more other charges from watches-brand.com such as the tax. If you have
any other questions please check our other pages or feel free to email
us by [EMAIL PROTECTED]


The Same Fake Seiko Watches Series :

Seiko Men's Watches Premier SNL039 - 5 :
http://www.watches-brand.com/Seiko-wristwatch-7595.html

Seiko Men's Watches Premier SNL041 - 5 :
http://www.watches-brand.com/Seiko-wristwatch-7596.html

Seiko Men's Watches Premier SNL041P - AA :
http://www.watches-brand.com/Seiko-wristwatch-7597.html

Seiko Men's Watches Premier SNL041P2 - AA :
http://www.watches-brand.com/Seiko-wristwatch-7598.html

Seiko Men's Watches Premier SNL042P - AA :
http://www.watches-brand.com/Seiko-wristwatch-7599.html

Seiko Men's Watches Premier SNL044P - AA :
http://www.watches-brand.com/Seiko-wristwatch-7600.html

Seiko Men's Watches Premier SNP001P - AA :
http://www.watches-brand.com/Seiko-wristwatch-7601.html

Seiko Men's Watches Premier SNP003P - AA :
http://www.watches-brand.com/Seiko-wristwatch-7602.html

Seiko Men's Watches Premier SNP004P - AA :
http://www.watches-brand.com/Seiko-wristwatch-7603.html

Seiko Men's Watches Premier SNP005P - AA :
http://www.watches-brand.com/Seiko-wristwatch-7604.html

Brand Watches Seiko Men's Watches Premier SNA745P - AA Discount,
Swiss, Fake
--
http://mail.python.org/mailman/listinfo/python-list


Brand Watches Ebel Classic Brown Leather Strap Date Mens Watch 9120F51.6235134 Discount, Swiss, Fake

2008-04-25 Thread watches0560
Brand Watches Ebel Classic Brown Leather Strap Date Mens Watch
9120F51.6235134 Discount, Swiss, Fake

Browse our Ebel Classic Brown Leather Strap Date Mens Watch
9120F51.6235134 Swiss watches, which is sure the watch you are looking
for at low price. There are more high quality designer watch Swiss for
selection

Ebel Classic Brown Leather Strap Date Mens Watch 9120F51.6235134
Link : http://www.watches-brand.com/Ebel-wristwatch-3195.html

Brand :  Ebel ( http://www.watches-brand.com/Ebel-Watches.html )

Model :  Ebel Classic Brown Leather Strap Date Mens Watch
9120F51.6235134

Description :
Stainless Steel Case & Bezel, Silver Dial, Brown Crocodile Leather
Strap, Date Display, Roman Numeral Hour Markers, Self Winding
Automatic Movement, Scratch Resistant Sapphire Crystal, Deployment
Buckle, Water Resistant up to 165FT


Sale Price :  $ 245.00

Ebel Classic Brown Leather Strap Date Mens Watch 9120F51.6235134
Details :


   
Brand: Ebel
Model: 9120F51.6235134
Band material: Leather
Bezel material: stainless-steel
Case material: stainless-steel
Clasp type: deployment-buckle
Dial color: silver
Dial window material: scratch-resistant-sapphire
Movement type: Swiss Automatic Movement
Water-resistant to 165 feet




Ebel Classic Brown Leather Strap Date Mens Watch 9120F51.6235134 is
new brand Swiss, join thousands of satisfied customers and buy your
Ebel with total satisfaction. A watches-brand.COM 30 Day Money Back
Guarantee is included with every Ebel Fake Series for secure, risk-
free online shopping. watches-brand.COM does not charge sales tax for
the Fake Ebel Classic Brown Leather Strap Date Mens Watch
9120F51.6235134.

All of our Fake watches are shipped via EMS to worldwide. Normally it
takes 3days to prepare the fake watch you ordered and 5-10days to
transmit depending on the different destination.We pay for the free
shipping cost for total quantity over 20 pcs. The EMS tracking NO.
will be sent by email when an order is shipped from our warehouse. No
more other charges from watches-brand.com such as the tax. If you have
any other questions please check our other pages or feel free to email
us by [EMAIL PROTECTED]


The Same Fake Ebel Watches Series :

Ebel Classic Two-Tone Black Leather Strap Mens Watch
1255F41.0235136 :
http://www.watches-brand.com/Ebel-wristwatch-3196.html

Ebel Classic Wave Mens Watch 9187151/20125 :
http://www.watches-brand.com/Ebel-wristwatch-3197.html

Ebel Men's Type E Stainless Steel Black Dial Watch, Model -
9187C41/5716 :
http://www.watches-brand.com/Ebel-wristwatch-3198.html

Ebel Men's Type E Stainless Steel Rubber Band Watch, Model -
9187C41/06C35606 :
http://www.watches-brand.com/Ebel-wristwatch-3199.html

Ebel Men's E Type Watch #9187C41-3716 :
http://www.watches-brand.com/Ebel-wristwatch-3200.html

Ebel Men's E Type Watch #9187C51-5716 :
http://www.watches-brand.com/Ebel-wristwatch-3201.html

Ebel Men's E Type Automatic Watch #9330C41-0716 :
http://www.watches-brand.com/Ebel-wristwatch-3202.html

Ebel Men's E Type Watch #9187C41-0716 :
http://www.watches-brand.com/Ebel-wristwatch-3203.html

Ebel Men's E Type Watch #9187C41-56C35606 :
http://www.watches-brand.com/Ebel-wristwatch-3204.html

Ebel Men's E Type Watch #9187C51-06C35606 :
http://www.watches-brand.com/Ebel-wristwatch-3205.html

Brand Watches Ebel Classic Brown Leather Strap Date Mens Watch
9120F51.6235134 Discount, Swiss, Fake
--
http://mail.python.org/mailman/listinfo/python-list


Re: module error in Vista -- works as administrator

2008-04-25 Thread sawilla
The access writes to easy-install.pth for regular users is read and
execute.

The output of sys.path for regular users is:
['', 'C:\\Program Files\\Python25\\lib\\site-packages\
\setuptools-0.6c8-py2.5.eg
g', 'C:\\Program Files\\Python25\\python25.zip', 'C:\\Program Files\
\Python25\\D
LLs', 'C:\\Program Files\\Python25\\lib', 'C:\\Program Files\\Python25\
\lib\\pla
t-win', 'C:\\Program Files\\Python25\\lib\\lib-tk', 'C:\\Program Files\
\Python25
', 'C:\\Program Files\\Python25\\lib\\site-packages']

The output of sys.path for the admin user is:
['', 'C:\\Program Files\\Python25\\lib\\site-packages\
\setuptools-0.6c8-py2.5.eg
g', 'C:\\Program Files\\Python25\\lib\\site-packages\\networkx-0.36-
py2.5.egg',
'C:\\Program Files\\Python25\\lib\\site-packages\\numpy-1.0.4-py2.5-
win32.egg',
'C:\\Program Files\\Python25\\lib\\site-packages\\scipy-0.6.0-py2.5-
win32.egg',
'C:\\Program Files\\Python25\\lib\\site-packages\\matplotlib-0.91.2-
py2.5-win32.
egg', 'C:\\Program Files\\Python25\\lib\\site-packages\\dot2tex-2.7.0-
py2.5.egg'
, 'C:\\Program Files\\Python25\\lib\\site-packages\\pydot-1.0.2-
py2.5.egg', 'C:\
\Program Files\\Python25\\lib\\site-packages\\pyparsing-1.4.11-py2.5-
win32.egg',
 'C:\\Program Files\\Python25\\python25.zip', 'C:\\Program Files\
\Python25\\DLLs
', 'C:\\Program Files\\Python25\\lib', 'C:\\Program Files\\Python25\
\lib\\plat-w
in', 'C:\\Program Files\\Python25\\lib\\lib-tk', 'C:\\Program Files\
\Python25',
'C:\\Program Files\\Python25\\lib\\site-packages']

The contents of easy-install.pth are:
import sys; sys.__plen = len(sys.path)
./setuptools-0.6c8-py2.5.egg
./networkx-0.36-py2.5.egg
./numpy-1.0.4-py2.5-win32.egg
./scipy-0.6.0-py2.5-win32.egg
./matplotlib-0.91.2-py2.5-win32.egg
./dot2tex-2.7.0-py2.5.egg
./pydot-1.0.2-py2.5.egg
./pyparsing-1.4.11-py2.5-win32.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:];
p=getattr(sys,
'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)

The location where numpy is found:
>>> print os.path.abspath(numpy.__file__)
C:\Program Files\Python25\lib\site-packages\numpy-1.0.4-py2.5-win32.egg
\numpy\__
init__.pyc

So I believe I need to have the easy-install.pth file executed
automatically for regular users but I don't know how to do this.

Reg




On Apr 21, 7:29 pm, John Machin <[EMAIL PROTECTED]> wrote:
> sawillawrote:
> > On Apr 21, 5:42 pm, John Machin <[EMAIL PROTECTED]> wrote:
> >> Log on as administrator, start python in command window and do this:
>
> >> import sys
> >> sys.path # shows where python is looking for importables
> >> import numpy
> >> import os.path
> >> print os.path.abspath(numpy.__file__) # shows where it found numpy
>
> >> Log on as ordinary user, start python in command window and do this:
>
> >> import sys
> >> sys.path
> >> # check how this is different from the admin's sys.path
>
> >> If you can't see what to do after that, come back here with the output
> >> from those steps.
>
> >> HTH,
> >> John
>
> > That was a great help, thank you. I now see what is causing the
> > problem but I don't know how to fix it. I used easy_install to install
> > several packages. When I run Python from an administrator command
> > window all of the directories in C:\Program Files\Python25\Lib\site-
> > packages\easy-install.pth are added to the sys.path. When I run it as
> > a regular user, those directories are not added to the sys.path and so
> > Python can't find the modules.
>
> > I know how to manually add those directories to Python's search path
> > but then I'll need to update the path every time I install something.
> > How do I get Python to automatically load the easy-install.pth file
> > for the regular user account?
>
> > Reg
>
> """
> If you can't see what to do after that, come back here with the output
> from those steps.
> """
> in particular what is in sys.path for the non-admin user.
> Also what are the access rights to the easy-install.pth file?- Hide quoted 
> text -
>
> - Show quoted text -

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


Fun with relative imports and py3k

2008-04-25 Thread Kay Schluehr
Since their introduction in Python 2.5 I only reviewed the new
"relative import" notation briefly by reading the "What's new in
Python 2.5" article. Now I wanted checkout if I get comfortable with
them.

Opening the tutorial I found following notice ( 6.4.2 ):

"Note that both explicit and implicit relative imports are based on
the name of the current module.
Since the name of the main module is always "__main__", modules
intended for use as the main module
of a Python application should always use absolute imports."

The distinction between modules and scripts was new to me. One of the
primary features I always appreciated in Python was that modules had a
dual purpose: they were components and they were programs. One could
use them in isolation or as a part of a package something I always
missed when I programmed in languages with the tyranny of a single
main.

However 'implicit relative imports' work as usual and Py3K just
changes the priority of search - one might simply ignore the
'explicit' variant and care for unambiguous names.

Now things are not so easy in life and when you are confronted with
other peoples software you have to know at least the rules of the
game.

Digging a little deeper I found the following section in "What's new
in Python 2.6"

'Python’s -m switch allows running a module as a script.
When you ran a module that was located inside a package, relative
imports didn’t work correctly.'

Hmm... they worked as specified or at least as documented. I admit I'm
confused but I suspect I'm not the only one. Now everything is fine.
You just run each and every module with the -m option "as a script"
because there is a chance that somewhere is a relative import ( e.g.
local to a function ) and suddenly the module fails to import stuff
due to a modality in the import behavior.

Let's see how it works in practice.

This here my very first attempt to start Pythons 2to3 refactoring tool
written by the master himself. I looked at it and he used relative
imports.

C:\Python30\Lib\lib2to3>C:\Python30\python -m refactor.py
Traceback (most recent call last):
  File "C:\Python30\lib\runpy.py", line 103, in _run_module_as_main
loader, code, fname = _get_module_details(mod_name)
  File "C:\Python30\lib\runpy.py", line 78, in _get_module_details
loader = get_loader(mod_name)
  File "C:\Python30\lib\pkgutil.py", line 456, in get_loader
return find_loader(fullname)
  File "C:\Python30\lib\pkgutil.py", line 466, in find_loader
for importer in iter_importers(fullname):
  File "C:\Python30\lib\pkgutil.py", line 422, in iter_importers
__import__(pkg)
  File "C:\Python30\lib\lib2to3\refactor.py", line 23, in 
from .pgen2 import driver
ValueError: Attempted relative import in non-package


Not working. I'm perfectly sure I don't understand the error message
but what's worse is that runpy.py fails which
was just created ( in Python 2.6 ) to fix the issue with the
apparently broken relative imports that is o.k. according to the
introductory material that is dedicated to newbies.

I'm trying to fix this naively by turning the explicit into implicit
relative (or absolute?) imports and see what happens.

refactor.py

...

# Local imports
from pgen2 import driver
from pgen2 import tokenize

import pytree
import patcomp
import fixes
import pygram



C:\Python30\Lib\lib2to3>C:\Python30\python -m refactor.py
Traceback (most recent call last):
  File "C:\Python30\lib\runpy.py", line 103, in _run_module_as_main
loader, code, fname = _get_module_details(mod_name)
  File "C:\Python30\lib\runpy.py", line 78, in _get_module_details
loader = get_loader(mod_name)
  File "C:\Python30\lib\pkgutil.py", line 456, in get_loader
return find_loader(fullname)
  File "C:\Python30\lib\pkgutil.py", line 466, in find_loader
for importer in iter_importers(fullname):
  File "C:\Python30\lib\pkgutil.py", line 422, in iter_importers
__import__(pkg)
  File "refactor.py", line 27, in 
import patcomp
  File "C:\Python30\lib\lib2to3\patcomp.py", line 17, in 
from .pgen2 import driver
ValueError: Attempted relative import in non-package

This time patcomp fails with its relative imports despite the fact
that it is not imported as a "script" but as a module inside the
lib2to3 package and it is not __main__ but refactor.py is.

I give up. I always thought migration from Python 2.X to Python 3.0
was an issue not the conversion tool ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: py3k concerns. An example

2008-04-25 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:



> > I still think it's a shame
> [...]
> > pps: I have to note that it would be nice if the
> >   ad-hominem (sp?) invective would drop out of
> >   these threads -- it doesn't add a lot, I think.
> 
> shame
> 1 a. a painful emotion caused by consciousness of guilt,
>  shortcoming, or impropriety
> 2 a condition of humiliating disgrace or disrepute

- [in sing.] a regrettable or unfortunate situation or action:  `it is a 
shame that they are not better known'

If English isn't your 1st language, you deserve a lot of credit for your 
mastery of it, but you need a better dictionary.

   Donn Cave, [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list

Re: Explicit variable declaration

2008-04-25 Thread Filip Gruszczyński
>  In Python the standard patten for "declaring" variables is just to assign to
>  them as they are needed.  If you want the effect of a declaration as you
>  would do in C, you can just define the variable and initialize it to 0 or
>  None.  (Or {} for a new dictionary, or [] for a new list.)

Yep, I get it and I absolutely love this about Python. What I don't
actually love is situation, where I misspell and instead of setting
one variable, other is created. This is why I would like to declare
variables first and say, that these are the only ones, that can be set
in certain function (the same with fields in a class).

I am finishing a small tool, that allows to create such declarations
in similar manner to Smalltalk declarations. I hope I can post a link
to it soon.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list

Re: module error in Vista -- works as administrator

2008-04-25 Thread sawilla
I've discovered the cause of the problem. At some point previously,
Windows Vista had created a copy of the site-packages directory in a
virtual store for the user account. The easy-install.pth file in the
virtual store did not contain the same path information as the easy-
install.pth that the administrator account sees. I deleted the user's
Python25 directory in the virtual store and now the user's sys.path
contains all of the necessary paths.

Reg

On Apr 25, 12:04 pm, sawilla <[EMAIL PROTECTED]> wrote:
> The access writes to easy-install.pth for regular users is read and
> execute.
>
> The output of sys.path for regular users is:
> ['', 'C:\\Program Files\\Python25\\lib\\site-packages\
> \setuptools-0.6c8-py2.5.eg
> g', 'C:\\Program Files\\Python25\\python25.zip', 'C:\\Program Files\
> \Python25\\D
> LLs', 'C:\\Program Files\\Python25\\lib', 'C:\\Program Files\\Python25\
> \lib\\pla
> t-win', 'C:\\Program Files\\Python25\\lib\\lib-tk', 'C:\\Program Files\
> \Python25
> ', 'C:\\Program Files\\Python25\\lib\\site-packages']
>
> The output of sys.path for the admin user is:
> ['', 'C:\\Program Files\\Python25\\lib\\site-packages\
> \setuptools-0.6c8-py2.5.eg
> g', 'C:\\Program Files\\Python25\\lib\\site-packages\\networkx-0.36-
> py2.5.egg',
> 'C:\\Program Files\\Python25\\lib\\site-packages\\numpy-1.0.4-py2.5-
> win32.egg',
> 'C:\\Program Files\\Python25\\lib\\site-packages\\scipy-0.6.0-py2.5-
> win32.egg',
> 'C:\\Program Files\\Python25\\lib\\site-packages\\matplotlib-0.91.2-
> py2.5-win32.
> egg', 'C:\\Program Files\\Python25\\lib\\site-packages\\dot2tex-2.7.0-
> py2.5.egg'
> , 'C:\\Program Files\\Python25\\lib\\site-packages\\pydot-1.0.2-
> py2.5.egg', 'C:\
> \Program Files\\Python25\\lib\\site-packages\\pyparsing-1.4.11-py2.5-
> win32.egg',
>  'C:\\Program Files\\Python25\\python25.zip', 'C:\\Program Files\
> \Python25\\DLLs
> ', 'C:\\Program Files\\Python25\\lib', 'C:\\Program Files\\Python25\
> \lib\\plat-w
> in', 'C:\\Program Files\\Python25\\lib\\lib-tk', 'C:\\Program Files\
> \Python25',
> 'C:\\Program Files\\Python25\\lib\\site-packages']
>
> The contents of easy-install.pth are:
> import sys; sys.__plen = len(sys.path)
> ./setuptools-0.6c8-py2.5.egg
> ./networkx-0.36-py2.5.egg
> ./numpy-1.0.4-py2.5-win32.egg
> ./scipy-0.6.0-py2.5-win32.egg
> ./matplotlib-0.91.2-py2.5-win32.egg
> ./dot2tex-2.7.0-py2.5.egg
> ./pydot-1.0.2-py2.5.egg
> ./pyparsing-1.4.11-py2.5-win32.egg
> import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:];
> p=getattr(sys,
> '__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)
>
> The location where numpy is found:>>> print os.path.abspath(numpy.__file__)
>
> C:\Program Files\Python25\lib\site-packages\numpy-1.0.4-py2.5-win32.egg
> \numpy\__
> init__.pyc
>
> So I believe I need to have the easy-install.pth file executed
> automatically for regular users but I don't know how to do this.
>
> Reg
>
> On Apr 21, 7:29 pm, John Machin <[EMAIL PROTECTED]> wrote:
>
>
>
> > sawillawrote:
> > > On Apr 21, 5:42 pm, John Machin <[EMAIL PROTECTED]> wrote:
> > >> Log on as administrator, start python in command window and do this:
>
> > >> import sys
> > >> sys.path # shows where python is looking for importables
> > >> import numpy
> > >> import os.path
> > >> print os.path.abspath(numpy.__file__) # shows where it found numpy
>
> > >> Log on as ordinary user, start python in command window and do this:
>
> > >> import sys
> > >> sys.path
> > >> # check how this is different from the admin's sys.path
>
> > >> If you can't see what to do after that, come back here with the output
> > >> from those steps.
>
> > >> HTH,
> > >> John
>
> > > That was a great help, thank you. I now see what is causing the
> > > problem but I don't know how to fix it. I used easy_install to install
> > > several packages. When I run Python from an administrator command
> > > window all of the directories in C:\Program Files\Python25\Lib\site-
> > > packages\easy-install.pth are added to the sys.path. When I run it as
> > > a regular user, those directories are not added to the sys.path and so
> > > Python can't find the modules.
>
> > > I know how to manually add those directories to Python's search path
> > > but then I'll need to update the path every time I install something.
> > > How do I get Python to automatically load the easy-install.pth file
> > > for the regular user account?
>
> > > Reg
>
> > """
> > If you can't see what to do after that, come back here with the output
> > from those steps.
> > """
> > in particular what is in sys.path for the non-admin user.
> > Also what are the access rights to the easy-install.pth file?- Hide quoted 
> > text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

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


Re: convert xhtml back to html

2008-04-25 Thread Jim Washington

Stefan Behnel wrote:

bryan rasmussen top-posted:
  

On Thu, Apr 24, 2008 at 9:55 PM, Stefan Behnel <[EMAIL PROTECTED]> wrote:


from lxml import etree

tree = etree.parse("thefile.xhtml")
tree.write("thefile.html", method="html")

 http://codespeak.net/lxml
  

wow, that's pretty nice there.

 Just to know: what's the performance like on XML instances of 1 GB?



That's a pretty big file, although you didn't mention what kind of XML
language you want to handle and what you want to do with it.

lxml is pretty conservative in terms of memory:

http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/

But the exact numbers depend on your data. lxml holds the XML tree in memory,
which is a lot bigger than the serialised data. So, for example, if you have
2GB of RAM and want to parse a serialised 1GB XML file full of little
one-element integers into an in-memory tree, get prepared for lunch. With a
lot of long text string content instead, it might still fit.

However, lxml also has a couple of step-by-step and stream parsing APIs:

http://codespeak.net/lxml/parsing.html#the-target-parser-interface
http://codespeak.net/lxml/parsing.html#the-feed-parser-interface
http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk
  
If you are operating with huge XML files (say, larger than available 
RAM) repeatedly, an XML database may also be a good option.


My current favorite in this realm is Sedna (free, Apache 2.0 license).  
Among other features, it has facilities for indexing within documents 
and collections (faster queries) and transactional sub-document updates 
(safely modify parts of a document without rewriting the entire 
document).  I have been working on a python interface to it recently 
(zif.sedna, in pypi).


Regarding RAM consumption, a Sedna database uses approximately 100 MB of 
RAM by default, and that does not change much, no matter how much (or 
how little) data is actually stored. 

For a quick idea of Sedna's capabilities, the Sedna folks have put up an 
on-line demo serving and xquerying an extract from Wikipedia (in the 
range of 20 GB of data) using a Sedna server, at 
http://wikidb.dyndns.org/ .  Along with the on-line demo, they provide 
instructions for deploying the technology locally. 


- Jim Washington

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


Re: Subclassing list the right way?

2008-04-25 Thread Matimus
On Apr 25, 7:03 am, Kirk Strauser <[EMAIL PROTECTED]> wrote:
> I want to subclass list so that each value in it is calculated at call
> time.  I had initially thought I could do that by defining my own
> __getitem__, but 1) apparently that's deprecated (although I can't
> find that; got a link?), and 2) it doesn't work.
>
> For example:
>
> >>> class Foo(list):
>
> ... def __getitem__(self, index):
> ... return 5
> ...>>> a = Foo([1, 2, 3, 4, 5])
> >>> print a
> [1, 2, 3, 4, 5]
> >>> print a[2:4]
> [3, 4]
> >>> print a[3]
>
> 5
>
> I first expected that to instead behave like:
>
> >>> print a
> [5, 5, 5, 5, 5]
> >>> print a[2:4]
>
> [5, 5]
>
> Is there a "right" way to do this?
> --
> Kirk Strauser

The built in types are very optimized. You can't make any assumptions
about how overriding methods on them will affect other method calls.

>From the docs:

__getitem__( self, key)

Called to implement evaluation of self[key]. For sequence types, the
accepted keys should be integers and slice objects. Note that the
special interpretation of negative indexes (if the class wishes to
emulate a sequence type) is up to the __getitem__() method. If key is
of an inappropriate type, TypeError may be raised; if of a value
outside the set of indexes for the sequence (after any special
interpretation of negative values), IndexError should be raised. For
mapping types, if key is missing (not in the container), KeyError
should be raised. Note: for loops expect that an IndexError will be
raised for illegal indexes to allow proper detection of the end of the
sequence.

What that basicly says is that it affects what is returned by a[x].

>>> class Foo(list):

... def __getitem__(self, index):
... return 5
...
>>> a = Foo([1, 2, 3, 4, 5])
>>> print a # a.__str__ called
[1, 2, 3, 4, 5]
>>> print a[2:4] # a.__getslice__ called
[3, 4]
>>> print a[3] # a.__getitem__ called
5

The _right_ way? Well, it depends on what you really want to do. If
you really want to calculate the value at call time but have it behave
exactly as a list in every way, then you will have to override pretty
much any method that deals with the values normally stored in the list
object. That means any method that either returns values stored in the
object, accepts as a parameter values stored in the object or uses the
values stored in the object in any way.

Methods that return values stored in the object:
__getitem__
__getslice__

pop

Methods that accept as a parameter values stored in the object:
__contains__
count
remove
index

Methods that use values stored in the object in some way:
__add__
__eq__
__ge__
__gt__
__iadd__
__imul__
__le__
__lt__
__mul__
__ne__
__reduce__
__reduce_ex__? I'm not sure about this one, I think it is for pickling
__repr__
__reversed__
__rmul__
__str__
__iter__
sort
reverse

I know that Py3.0 is going to implement Abstract Base Classes. I don't
know if that is going to clean up this behavior or not. So, you can
either write a lot of code or restrict the way you use lists to a
limited amount of functionality. There is a third option, which is to
calculate the values when storing. This might be a little easier, but
if you want to ensure that values returned by all methods are the same
type as your class you are back to overriding a lot of methods.

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


Re: how to mysqldb dict cursors

2008-04-25 Thread Vaibhav.bhawsar
Hmm that explains it! Thank you.
v

On Fri, Apr 25, 2008 at 7:38 AM, Steve Holden <[EMAIL PROTECTED]> wrote:

> Vaibhav.bhawsar wrote:
> [top-posting amended: see below]
>
>> On Fri, Apr 25, 2008 at 12:45 AM, Paul McNett <[EMAIL PROTECTED] > [EMAIL PROTECTED]>> wrote:
>>
>>Vaibhav.bhawsar wrote:
>>
>>I have been trying to get the DictCursor working with mysqldb
>>module but can't seem to. I have pasted the basic connection
>>code and the traceback from pydev. The connection does open with
>>the default cursor class. can't figure this one out. many thanks.
>>
>>
>>Try one of:
>>
>>"""
>>import MySQLdb, MySQLdb.cursors
>>conn = MySQLdb.connect(..., cursorclass=MySQLdb.cursors.DictCursor)
>>"""
>>
>>-or-
>>
>>"""
>>import MySQLdb, MySQLdb.cursors
>>conn = MySQLdb.connect(...)
>>cur = MySQLdb.cursors.DictCursor(conn)
>>"""
>>
>>I'm going off of memory here, though, but I'm at least close.
>>
>>  > Great both methods worked! I don't quite understand this since i
> imported
> > the whole module with "import MySQLdb"
> >
> > Thanks!
> >
> The point here is that MySQLdb is a package, not a module. Some packages
> have their top-level __init__.py import the package's sub-modules or
> sub-packages to make them immediately available within the package namespace
> (which is why, for example, you can access os.path.* when you have imported
> os) and others don't.
>
> MySQLdb clearly doesn't need to import the cursors module for its own
> purposes. Perhaps it would be less efficient to always perfrom the import,
> who knows. Well, Andy Dustman does, I suppose, and possibly anyone else who
> reads the code, but I haven't done that myself.
>
> regards
>  Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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

Re: Calling Python code from inside php

2008-04-25 Thread alexelder
On Apr 25, 4:02 pm, sturlamolden <[EMAIL PROTECTED]> wrote:
> On Apr 23, 9:13 pm, [EMAIL PROTECTED] wrote:
>
> > A simple yet dangerous and rather rubbish solution (possibly more of a
> > hack than a real implementation) could be achieved by using a
> > technique described above:
>
> >  > echo exec('python foo.py');
>
> This will spawn a Python interpreter, and not be particularly
> efficient. You could just as well have used CGI.

Thanks for pointing that out. I thought the warning before hand
could've suggested that this implementation wasn't the best. I'll be
more explicit in the future.
--
http://mail.python.org/mailman/listinfo/python-list


Re: convert xhtml back to html

2008-04-25 Thread Tim Arnold
"bryan rasmussen" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> I'll second the recommendation to use xsl-t, set the output to html.
>
>
> The code for an XSL-T to do it would be basically:
> http://www.w3.org/1999/XSL/Transform"; 
> version="1.0">
> 
>
> 
>
> you would probably want to do other stuff than just  copy it out but
> that's another case.
>
> Also, from my recollection the solution in CHM to make XHTML br
> elements behave correctly was  as opposed to , at any rate
> I've done projects generating CHM and my output markup was well formed
> XML at all occasions.
>
> Cheers,
> Bryan Rasmussen

Thanks Bryan, Walter, John, Marc, and Stefan. I finally went with the xslt 
transform which works very well and is simple.  regexps would work, but they 
just scare me somehow. Brian, my tags were formatted as  but the help 
compiler would issue warnings on each one resulting in log files with 
thousands of warnings. It did finish the compile though, but it made 
understanding the logs too painful.

Stefan, I *really* look forward to being able to use lxml when I move to RH 
linux next month. I've been using hp10.20 and never could get the requisite 
libraries to compile. Once I make that move, maybe I won't have as many 
markup related questions here!

thanks again to all for the great suggestions.
--Tim Arnold




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


Newbie question about import

2008-04-25 Thread Luca
Hi all. I'm trying to do something with python import but isn't working for me.

Using python 2,5 I've a program structured like this:

* a main module called (for example) "mommy" with an __init__.py and a
file called "mommy.py"
* a __version__ var defined inside the main __init__.py

>From the mommy.py file I need to import the __version__ var, but I'm
really not able to do this! I fear this is a very stupid task to do...
my problem is that the file is called like the module.

Anyone can point me to the solution?

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


Re: Problem building python in virtual machine running centos

2008-04-25 Thread Alexandre Gillet
Thanks for your answers. I did solve my problem.
I upgraded my glibc libraries and it seems to solve the problem.
I was able to build python-2.4.5 using gcc 4.1.2 (glibc-2.5-18.el5_1.1)

Alex

On Thu, 2008-04-24 at 18:05 -0700, Alexandre Gillet wrote:
> Hi,
> 
> I am trying to build python-2.4.5 on Centos 5.1, which is a virtual
> machine running with xen.
> I am not able to build python. The compilation crash with the following:
> gcc -pthread -c  -DNDEBUG -g  -O3 -Wall -Wstrict-prototypes -I.
> -I./Include  -DPy_BUILD_CORE -o Objects/unicodeobject.o
> Objects/unicodeobject.c
> In file included from ./Include/Python.h:76,
>  from Objects/unicodeobject.c:39:
> ./Include/object.h:228: internal compiler error: Segmentation fault
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See http://bugzilla.redhat.com/bugzilla> for instructions.
> The bug is not reproducible, so it is likely a hardware or OS problem.
> 
> 
> Any suggestion of what am I doing wrong?
> 
> Thanks
> Alex
> 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about import

2008-04-25 Thread Larry Bates

Luca wrote:

Hi all. I'm trying to do something with python import but isn't working for me.

Using python 2,5 I've a program structured like this:

* a main module called (for example) "mommy" with an __init__.py and a
file called "mommy.py"
* a __version__ var defined inside the main __init__.py


From the mommy.py file I need to import the __version__ var, but I'm

really not able to do this! I fear this is a very stupid task to do...
my problem is that the file is called like the module.

Anyone can point me to the solution?



In the future please show us what you "actually" did with full tracebacks if 
there were any so we know what you actually tried.


I do something like this by doing:

from version import version__

It doesn't have to be a module (e.g. doesn't need __init__.py) to make that 
work.

Hope this helps.

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


Re: Newbie question about import

2008-04-25 Thread Kay Schluehr
On 25 Apr., 20:03, Luca <[EMAIL PROTECTED]> wrote:
> Hi all. I'm trying to do something with python import but isn't working for 
> me.
>
> Using python 2,5 I've a program structured like this:
>
> * a main module called (for example) "mommy" with an __init__.py and a
> file called "mommy.py"
> * a __version__ var defined inside the main __init__.py
>
> >From the mommy.py file I need to import the __version__ var, but I'm
>
> really not able to do this! I fear this is a very stupid task to do...
> my problem is that the file is called like the module.
>
> Anyone can point me to the solution?
>
> --
> -- luca

You have to import the package containing mummy and __init__ from the
pythonpath ( which can be examined using the sys module and the
sys.path attribute ). Then access __version__ as an attribute:

mypack/   # package indicated by __init__.py
   mummy.py
   __init__.py


mummy.py

import mypack  # o.k. if accessible from pythonpath
mypack.__version__
--
http://mail.python.org/mailman/listinfo/python-list


Why is None <= 0

2008-04-25 Thread Gregor Horvath

Hi,

>>> None <= 0
True

Why?
Is there a logical reason?

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


Re: print some text

2008-04-25 Thread Gabriel Ibanez

Hi !

Other idea (old style school):

def printing():
  f=open("lpt1", "w")
  f.write("\nSomething to print\f")
  f.close()

Cheers..

- Ibanez -

- Original Message - 
From: <[EMAIL PROTECTED]>

Newsgroups: comp.lang.python
To: 
Sent: Wednesday, April 23, 2008 10:27 PM
Subject: Re: print some text


On Apr 23, 2:05 pm, barronmo <[EMAIL PROTECTED]> wrote:

I'm a beginner searching for an easy way to print the contents of a
text control. So far I've come up with the following(difficulties):

1) using wxPython
-convert to HTML and then print (I don't know anything about
HTML)
-use wx.Printout (Seems complicated; may be beyond my abilities)

2) create a text file and then print it out (can create but can only
print with the win32api.ShellExecute method so this solution doesn't
help me on my Linus laptop)

3) use ReportLab to create .pdf and then print that out (again, can
create but can't print in Linux)

Thanks for any help.

Mike


Write out an HTML file, write back if you need a quick one, then print
that with a browser.
--
http://mail.python.org/mailman/listinfo/python-list

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


Re: Why is None <= 0

2008-04-25 Thread Martin v. Löwis

 None <= 0
> True
> 
> Why?
> Is there a logical reason?

None is smaller than anything. The choice of
making it so is arbitrary, however, Python 2.x
tries to impose a total order on all objects (with varying
success), therefore, it is necessary to take arbitrary
choices.

(FWIW, in 2.x, x>=4?, it's None < numbers < anything else;
numbers are ordered by value, everything else is ordered
by type name, then by address, unless comparison functions
are implemented).

Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is None <= 0

2008-04-25 Thread D'Arcy J.M. Cain
On Fri, 25 Apr 2008 20:27:15 +0200
Gregor Horvath <[EMAIL PROTECTED]> wrote:
>  >>> None <= 0
> True
> 
> Why?

Why not?

> Is there a logical reason?

Everything in Python can compare to everything else.  It is up to the
programmer to make sure that they are comparing reasonable things.

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is None <= 0

2008-04-25 Thread Paul McNett

Gregor Horvath wrote:

 >>> None <= 0
True


More accurately:


None < 0

True


Why?
Is there a logical reason?


None is "less than" everything except for itself:

>>> None < 'a'
True
>>> None < False
True
>>> None == None
True

In my humble opinion, I think that comparisons involving None should 
return None, but I trust that the designers came up with this for very 
good reasons. As far as I know I've never been bitten by it.


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


Re: Why is None <= 0

2008-04-25 Thread Gregor Horvath

D'Arcy J.M. Cain schrieb:

On Fri, 25 Apr 2008 20:27:15 +0200
Gregor Horvath <[EMAIL PROTECTED]> wrote:

 >>> None <= 0
True

Why?


Why not?


Because, from http://www.python.org/dev/peps/pep-0020/ :

Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.

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


Re: Why is None <= 0

2008-04-25 Thread D'Arcy J.M. Cain
On Fri, 25 Apr 2008 11:54:23 -0700
Paul McNett <[EMAIL PROTECTED]> wrote:
> In my humble opinion, I think that comparisons involving None should 
> return None...

Like relational databases.

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is None <= 0

2008-04-25 Thread Grant Edwards
On 2008-04-25, Gregor Horvath <[EMAIL PROTECTED]> wrote:
> Hi,
>
> >>> None <= 0
> True
>
> Why?

Comparing objects of differing types produces an undefined
result.  Next time you do it, it might return False. (Well,
it's not really going to, but it's allowed to.)

> Is there a logical reason?

For what?  There's no reason it returns true rather than false.
The more interesting question is why doesn't it raise an
exception.  

-- 
Grant Edwards   grante Yow! These PRESERVES should
  at   be FORCE-FED to PENTAGON
   visi.comOFFICIALS!!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is None <= 0

2008-04-25 Thread Gary Herron

Gregor Horvath wrote:

Hi,

>>> None <= 0
True

Why?
Is there a logical reason?

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


In early Python, the decision was made that the comparison of *any* two 
objects was legal and would return a consistent result.  So objects of 
different types will compare according to an ordering on their types (an 
implementation dependent, unspecified, but consistent ordering), and 
objects of the same type will be compared according to rules that make 
sense for that type.


Other implementations have the right to compare an integer and None 
differently, but on a specific implementation, the result will not change.


Python 3 will raise an exception on such comparisons.

Gary Herron

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


  1   2   >