Re: 64 bit memory usage

2010-12-08 Thread Ian Kelly

On 12/8/2010 11:42 PM, Dennis Lee Bieber wrote:

The page file can be larger than physical memory because it contains
memory "images" for multiple processes. However, all those "images" have
to map into the physically addressable memory -- so a process is likely
limited to physical memory, but you can have multiple processes adding
up to physical + pagefile in total.


Only those pages that are currently paged in need be mapped to physical 
memory.  The rest are not mapped to anything at all (other than a 
location in the page file) -- once a page is paged out, it need not be 
put back in its original page frame when it is paged in again.


Since a process need not have all its pages in physical memory 
simultaneously, there is no reason to suppose that a single process 
could not consume the entirety of the available virtual memory (minus 
what is used by the operating system) on a 64-bit system (the same 
cannot be said of a 32-bit system, where the total virtual memory 
available may well be larger than the addressable space).


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


Re: completely implicit interpolation based on a frame object

2010-12-08 Thread Edward Peschko
>> Any ideas would be great on this, including pitfalls that people see
>> in implementing it.
>>
> http://docs.python.org/library/string.html#template-strings
>
> regards
>  Steve

Steve,

Thanks for the tip, I did look at templates and decided that they
weren't quite completely what I was looking for, although they could
be part of the solution.

1. they require ${ } around the variables in question that you want to
interpolate. When run through the trace hook, normal code doesn't do
that.
2. they don't provide (AFAICT) a complete interpolation solution.
Suppose I want to define custom interpolations in my tracer, like say,
expanding out lists and dicts, or fleshing out objects using their
stringification method. Does template do this?

Formats may be a bit closer here, but I'm not sure if they are
workable (or usable) with 2.5... which is where I need to work.

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


trace cmd line args

2010-12-08 Thread rusi
I am unable to get trace to not trace system modules.

I tried:
$ python -m trace --listfuncs tt.py --ignore-module 'bdb' > tracefile
$ python -m trace --listfuncs --ignore-dir /usr/lib/python2.6 tt.py >
tracefile
and many other combinations

But anyhow my tracefile contains lines like this:


filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname:

filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: Bdb
filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname:
BdbQuit
filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname:
Breakpoint
filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: Tdb
filename: /usr/lib/python2.6/cmd.py, modulename: cmd, funcname:

filename: /usr/lib/python2.6/cmd.py, modulename: cmd, funcname: Cmd
filename: /usr/lib/python2.6/collections.py, modulename: collections,
funcname: 
filename: /usr/lib/python2.6/collections.py, modulename: collections,
funcname: namedtuple
filename: /usr/lib/python2.6/dis.py, modulename: dis, funcname:

filename: /usr/lib/python2.6/inspect.py, modulename: inspect,
funcname: 
filename: /usr/lib/python2.6/inspect.py, modulename: inspect,
funcname: BlockFinder
filename: /usr/lib/python2.6/inspect.py, modulename: inspect,
funcname: EndOfBlock
filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname:

filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname:
def_op
filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname:
jabs_op
filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname:
jrel_op
filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname:
name_op
filename: /usr/lib/python2.6/pdb.py, modulename: pdb, funcname:

filename: /usr/lib/python2.6/pdb.py, modulename: pdb, funcname: Pdb
filename: /usr/lib/python2.6/pdb.py, modulename: pdb, funcname:
Restart
filename: /usr/lib/python2.6/pprint.py, modulename: pprint, funcname:

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


Re: RCX using python serial help

2010-12-08 Thread Astan Chee
Thanks for that help. I really appriciate it.
My next question is how do I code or what is the checksum? The sum of
opcode and arguments in hex and then mod 256? Does it include the
compliment opcode and arguments as well? Is the checksum compliment
equal to the sum of the opcode (and arguments) compliment?
Thanks again for the clarification

On 12/8/10, MRAB  wrote:
> On 06/12/2010 15:37, Astan Chee wrote:
>> Hi,
>> I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of
>> those old serial IR towers to control the microcontroller. I've had a
>> look around at python's serial documentation as well as the RCX's
>> documentation and I'm trying to write something to control the RCX
>> directly using python. Several examples from of doing this in python
>> include using lnp (i think) and that doesn't quite run well in windows.
>> I've had a look at the C++ code and some protocol documentation here:
>> http://www.generation5.org/content/2001/rob08.asp and converted it to
>> python. I've attached it at the end of the email. So now I've figured
>> out how to check for the battery level and it seems to work (I've tested
>> it on my RCX) but I'm confused with the other documentation (e.g.
>> http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in
>> python or what this all means. I was wondering if anyone can help me
>> complete these? or maybe help me do it step-by-step?
>> Thanks for any help.
> [snip]
> Here's a brief summary of the protocol:
>
> A command or request to the microcontroller is a packet consisting of a
> header, an opcode, arguments, and a checksum.
>
>   The header used in the documentation is 0x55, 0xFF, 0x00.
>
>   The opcode is 1 byte, followed by its one's complement.
>
>   The argument is 0 or more bytes, each followed by its one's complement.
>
>   The checksum is the sum of the opcode and the arguments, modulo 256,
> followed by its one's complement.
>
> A reply from the microcontroller is also a packet consisting of a
> header, an opcode, arguments, and a checksum.
>
>   The header is the same as the original command or request.
>
>   The opcode is the one's complement of the original opcode, followed by
> its one's complement (ie, the original opcode).
>
>   The argument is 0 or more bytes, each followed by its one's complement.
>
>   The checksum is the sum of the opcode and the arguments, modulo 256,
> followed by its one's complement.
>
> The microcontroller will ignore a packet whose opcode is the same as the
> previous one; this is to prevent unintended duplicates due to
> communication errors.
>
> Each opcode has 2 alternatives, one with bit 3 clear and the other with
> bit 3 set (bitwise-ored with 0x08), so if you do want to send a command
> or request with the same opcode as the previous packet you can just use
> the alternative form.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparisons of incompatible types

2010-12-08 Thread John Nagle

On 12/8/2010 7:56 PM, geremy condra wrote:

On Wed, Dec 8, 2010 at 1:01 PM, John Nagle  wrote:

On 12/7/2010 3:59 PM, Mark Wooding wrote:


Exactly one of


   a > b
   a = b
   a < b

  is true, or an type exception must be raised.


   Here's an example where this issue produces invalid results in Python.

>>> NaN = float("nan")
>>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, 
3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0]

>>> sorted(arr)
[0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, 
6.0, nan, 4.0, nan, 6.0, nan]


The sorted numerical values aren't in order. Note the 4.0 near the
end, after the 6.0.  "sort" has failed because it assumes that
a < b and b < c implies a < c. But that's not a valid assumption here.

It's not good to break trichotomy.

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


win32 design pattern: COM localserver?

2010-12-08 Thread kirby.ur...@gmail.com
Greetings gurus.

I'm faced with the challenge of having a single-threaded proprietary
Win32
language wanting to do multiple calls against a Python COM object.

Something like...

loObj = CREATEOBJECT("map_maker")
loObj.report( params, filename)

do while .True.
  yadda yadda
enddo

RETURN

I.e. the client program continues execution while loObj churns away
somewhere doing work in Python, say accessing a MySQL database
and building a map, embedding it in a PDF.

Am I right that the COM object will need to "serve forever" i.e. be
built around some non-terminating loop?  Will the client's call then
spawn a process or thread that continues until finished?

All it has to do is leave a file on disk somewhere, then die.  But
the client can't be kept on the hook until that's all done.

I've had good luck doing an InProcess COM object the generates
a PDF from ReportLab.  But this "stay alive while returning control
to the client" challenge looks like it might be a job for sockets?

Gee I hope not.

Quick links to favorite blog articles will give me a sense of the
ballpark...  Any clues welcome.  Yes, I have the Win32 book from
O'Reilly.

Kirby

PS:  my thanks to Ethan Furman for performing maintenance and
upgrades on his dbf module on PyPI.  The FoxPro gods thank you.
http://pypi.python.org/pypi/dbf/0.88.16

PPS:  some thoughts about IronPython filed here, after trying to
catch up some, sorry about my formatting, here too.
http://mail.python.org/pipermail/edu-sig/2010-December/010138.html

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


Re: Comparisons of incompatible types

2010-12-08 Thread geremy condra
On Wed, Dec 8, 2010 at 1:01 PM, John Nagle  wrote:
> On 12/7/2010 3:59 PM, Mark Wooding wrote:
>>>
>>> Exactly one of
>>> >
>>> >       a>  b
>>> >       a = b
>>> >       a<  b
>>> >
>>> >  is true, or an type exception must be raised.
>>
>> This will get the numerical people screaming.  Non-signalling NaNs are
>> useful, and they don't obey these axioms.
>
>   As a sometime numerical person, I've been screaming at this from
> the other side.   The problem with comparing non-signalling NaNs is that
> eventually, the program has to make a control flow decision, and it
> may not make it correctly.
>
>   I used to do dynamic simulation engines for animation.  I was
> probably the first person to get ragdoll physics to work right,
> back in 1996-1997.  In hard collisions, the program would get
> floating point overflows, and I had to abort the interation, back
> up, cut the time step down, and go forward again, until the time
> step was small enough to allow stable integration.  This was
> under Windows on x86, where it's possible, in a Windows-dependent
> way, to catch signalling NaNs and turn the hardware exception into
> a C++ exception.  If the computation just plowed ahead with
> non-signalling NaNs, with a check at the end, it could go wrong
> and produce bad results, because incorrect branches would be taken
> and the final bogus results might not contain NaNs.
>
>   I personally think that comparing NaN with numbers or other
> NaNs should raise an exception.  There's no valid result for
> such comparisons.

This, in big letters.

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


Re: Comparisons of incompatible types

2010-12-08 Thread Steven D'Aprano
On Wed, 08 Dec 2010 13:01:28 -0800, John Nagle wrote:

> On 12/7/2010 3:59 PM, Mark Wooding wrote:
>>> Exactly one of
>>> >
>>> >   a>  b
>>> >   a = b
>>> >   a<  b
>>> >
>>> >  is true, or an type exception must be raised.
>> This will get the numerical people screaming.  Non-signalling NaNs are
>> useful, and they don't obey these axioms.
> 
> As a sometime numerical person, I've been screaming at this from
> the other side.   The problem with comparing non-signalling NaNs is that
> eventually, the program has to make a control flow decision, and it may
> not make it correctly.

Then use signalling NANs. Nobody is suggesting that quiet NANs should be 
compulsory, or are the solution for all problems. But they're a solution 
for some problems, which is why people use them.

[...]
> I personally think that comparing NaN with numbers or other
> NaNs should raise an exception.  There's no valid result for such
> comparisons.

If NAN and 1 are unordered, then NAN is not less or equal to 1, nor is it 
larger than 1. Hence both NAN <= 1 and NAN >= 1 are false. The problem 
only comes when the caller mistakenly thinks that floats are real 
numbers, and tries to reason about floats like they would reason about 
real numbers.



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


Re: Can't deepcopy bytes-derived class

2010-12-08 Thread Terry Reedy

On 12/8/2010 7:11 PM, Ned Deily wrote:

In article, Terry
Reedy  wrote:

On 12/8/2010 2:42 PM, Dan wrote:

I have a simple type derived from bytes...

class atom(bytes): pass

... that I cannot deepcopy().  The session below demonstrates
how deepcopy() of "bytes" works fine, but deepcopy() of "atom"
does not.

[...]

Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32
bit (Intel)] Type "help", "copyright", "credits" or "license" for
more information.

import copy class atom(bytes):

... pass ...

copy.deepcopy(b'abc')

b'abc'

copy.deepcopy(atom(b'abc'))

Traceback (most recent call last): File "C:\Program Files
(x86)\Wing IDE 3.2\src\debug\tserver \_sandbox.py", line 1,
in # Used internally for debug sandbox under external
interpreter File "C:\Python31\Lib\copy.py", line 173, in
deepcopy y = _reconstruct(x, rv, 1, memo) File
"C:\Python31\Lib\copy.py", line 280, in _reconstruct y =
callable(*args) File "C:\Python31\Lib\copyreg.py", line 88, in
__newobj__ return cls.__new__(cls, *args) builtins.TypeError:
string argument without an encoding


You could trace through copy.py and copyreg.py to see where bytes
and atom get treated differently.

This might be a bug that should be reported on the tracker, but I
do not know. Let see what anyone else says.


FWIW, the example still fails with Python 3.1.3 but seems to work OK
with a recent alpha build of Python 3.2.  What specific change might
have fixed it doesn't come immediately to mind.


According to difflib.unified_diff, the only difference between
Lib/copy.py from 3.1 to 3.2 is 4 lines:
+
+def _deepcopy_method(x, memo): # Copy instance methods
+return type(x)(x.__func__, deepcopy(x.__self__, memo))
+_deepcopy_dispatch[types.MethodType] = _deepcopy_method

(and none in copyreg.py)

These were added in rev76572 as part of
http://bugs.python.org/issue1515

Guido decreed this to be a new feature rather than bugfix, so the change 
went into future 2.7 and 3.2 and not existing 2.6 and 3.1.


Tto verify that these cause the change, comment out in 3.2 or add to 
3.1. I have not read through the issue to understand it or why it would 
affect the OP's code case.


--
Terry Jan Reedy

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


Automating a shell session question

2010-12-08 Thread chad
I manually log into a remote shell and so some stuff. After I do some
stuff, I want the rest of the session to be automated. I've tried
pexpect using the interact() function. However, I don't see any way to
go into non-interactive mode going this route. Ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is py2exe still active ?

2010-12-08 Thread Philip Semanchuk

On Dec 8, 2010, at 5:09 AM, Octavian Rasnita wrote:

> Hi Steve,
> 
> I may put some stupid questions because I am very new to Python, but... I 
> heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) 
> provided on a central archive where we can get them and also report the bugs 
> using a single request/issue tracker?

Hi Octavian,
I didn't see anyone reply to you on the list...

The short answer to your question is "no". PyPI stands for the Python Package 
Index. The key word there is "Index". It's a catalog of packages but many of 
those packages are hosted elsewhere. The places where those packages are hosted 
may or may not have an issue tracker, etc. 

For instance, one the packages that I offer through PyPI (posix_ipc) is hosted 
on my personal Web site. 

Hope this helps
Philip


> - Original Message - 
> From: "Steve Holden" 
> Newsgroups: gmane.comp.python.general
> To: "Octavian Rasnita" 
> Cc: 
> Sent: Wednesday, December 08, 2010 12:56 AM
> Subject: Re: is py2exe still active ?
> 
> 
>> Octavian:
>> 
>> It's great that you want to let people know about bugs. Put yourself in
>> the position of the package maintainer, however. She or he doesn't spend
>> all day working on cxFreeze, and probably doesn't even do a Google
>> search on cxFreeze very often. So they are unlikely to find out about
>> this problem form your well-intentioned note.
>> 
>> It's just possible nobody does care, as I can't find a link to an issue
>> tracker - the best I could advise in this case would be to join the
>> mailing list by visiting
>> 
>> https://lists.sourceforge.net/lists/listinfo/cx-freeze-users
>> 
>> regards
>> Steve
>> 
>> On 12/7/2010 6:49 PM, Octavian Rasnita wrote:
>>> This packager is also nice.
>>> 
>>> If someone cares, I've discovered a small bug in it.
>>> If Python is installed on another drive than C under Windows, the 
>>> cxfreeze.bat file still calls Python on the drive C and it doesn't work 
>>> until it is corrected.
>>> 
>>> Octavian
>>> 
>>> - Original Message - 
>>> From: "Cbast" 
>>> Newsgroups: comp.lang.python
>>> To: 
>>> Sent: Tuesday, December 07, 2010 5:00 PM
>>> Subject: Re: is py2exe still active ?
>>> 
>>> 
>>> On Dec 7, 8:23 am, Anders Persson  wrote:
 Hi!
 When a look att py2exe homepage it is not looking like mutch happen,
 as a beginner i was thinking to start with Python 3, but i like to now
 if py2exe will be for 3 too.
 
 Is any one have any info ?
>>> 
>>> I don't have the answer about py2exe, but I'm using cxFreeze to create
>>> executables with Python 3.1, if it's what you're looking for.
>>> 
>>> http://cx-freeze.sourceforge.net/
>> 
>> 
>> -- 
>> Steve Holden   +1 571 484 6266   +1 800 494 3119
>> PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
>> See Python Video!   http://python.mirocommunity.org/
>> Holden Web LLC http://www.holdenweb.com/
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Can't deepcopy bytes-derived class

2010-12-08 Thread Ned Deily
In article ,
 Terry Reedy  wrote:
> On 12/8/2010 2:42 PM, Dan wrote:
> > I have a simple type derived from bytes...
> >
> > class atom(bytes):
> > pass
> >
> > ... that I cannot deepcopy().  The session below demonstrates how
> > deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not.
[...]
> > Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
> > (Intel)]
> > Type "help", "copyright", "credits" or "license" for more information.
>  import copy
>  class atom(bytes):
> > ... pass
> > ...
>  copy.deepcopy(b'abc')
> > b'abc'
>  copy.deepcopy(atom(b'abc'))
> > Traceback (most recent call last):
> >File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver
> > \_sandbox.py", line 1, in
> >  # Used internally for debug sandbox under external interpreter
> >File "C:\Python31\Lib\copy.py", line 173, in deepcopy
> >  y = _reconstruct(x, rv, 1, memo)
> >File "C:\Python31\Lib\copy.py", line 280, in _reconstruct
> >  y = callable(*args)
> >File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__
> >  return cls.__new__(cls, *args)
> > builtins.TypeError: string argument without an encoding
> 
> You could trace through copy.py and copyreg.py to see where bytes and 
> atom get treated differently.
> 
> This might be a bug that should be reported on the tracker, but I do not 
> know. Let see what anyone else says.

FWIW, the example still fails with Python 3.1.3 but seems to work OK 
with a recent alpha build of Python 3.2.  What specific change might 
have fixed it doesn't come immediately to mind.

-- 
 Ned Deily,
 n...@acm.org

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


Re: Comparisons of incompatible types

2010-12-08 Thread John Nagle

On 12/8/2010 1:47 AM, Steven D'Aprano wrote:

On Wed, 08 Dec 2010 11:58:03 +1100, Ben Finney wrote:


Carl Banks  writes:


On Dec 6, 4:17 pm, Steven D'Aprano  wrote:

Nevertheless, I agree that in hindsight, the ability to sort such
lists is not as important as the consistency of comparisons.


I think that feeling the need to sort non-homogenous lists is
indicative of bad design.


It can also be indicative of code written for a Python that doesn't have
sets.


Or a list that contains unhashable objects.


   If you can't hash it, and it doesn't have some definition of
comparison associated with the object, you probably can't order
it properly, either.

   "<" can't be some random function.  For sorting to work,

a < b and b < c implies a < c

must hold.

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


Re: Can't deepcopy bytes-derived class

2010-12-08 Thread Terry Reedy

On 12/8/2010 2:42 PM, Dan wrote:

I have a simple type derived from bytes...

class atom(bytes):
pass

... that I cannot deepcopy().  The session below demonstrates how
deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not.
What's going wrong?

Thanks,
Dan.


Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
(Intel)]
Type "help", "copyright", "credits" or "license" for more information.

import copy
class atom(bytes):

... pass
...

copy.deepcopy(b'abc')

b'abc'

copy.deepcopy(atom(b'abc'))

Traceback (most recent call last):
   File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver
\_sandbox.py", line 1, in
 # Used internally for debug sandbox under external interpreter
   File "C:\Python31\Lib\copy.py", line 173, in deepcopy
 y = _reconstruct(x, rv, 1, memo)
   File "C:\Python31\Lib\copy.py", line 280, in _reconstruct
 y = callable(*args)
   File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__
 return cls.__new__(cls, *args)
builtins.TypeError: string argument without an encoding


You could trace through copy.py and copyreg.py to see where bytes and 
atom get treated differently.


This might be a bug that should be reported on the tracker, but I do not 
know. Let see what anyone else says.


--
Terry Jan Reedy

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


Re: Comparisons of incompatible types

2010-12-08 Thread John Nagle

On 12/7/2010 3:59 PM, Mark Wooding wrote:

Exactly one of
>
>a>  b
>a = b
>a<  b
>
>  is true, or an type exception must be raised.

This will get the numerical people screaming.  Non-signalling NaNs are
useful, and they don't obey these axioms.


   As a sometime numerical person, I've been screaming at this from
the other side.   The problem with comparing non-signalling NaNs is that
eventually, the program has to make a control flow decision, and it
may not make it correctly.

   I used to do dynamic simulation engines for animation.  I was
probably the first person to get ragdoll physics to work right,
back in 1996-1997.  In hard collisions, the program would get
floating point overflows, and I had to abort the interation, back
up, cut the time step down, and go forward again, until the time
step was small enough to allow stable integration.  This was
under Windows on x86, where it's possible, in a Windows-dependent
way, to catch signalling NaNs and turn the hardware exception into
a C++ exception.  If the computation just plowed ahead with
non-signalling NaNs, with a check at the end, it could go wrong
and produce bad results, because incorrect branches would be taken
and the final bogus results might not contain NaNs.

   I personally think that comparing NaN with numbers or other
NaNs should raise an exception.  There's no valid result for
such comparisons.

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


Re: Comparison with False - something I don't understand

2010-12-08 Thread Mark Wooding
"OKB (not okblacke)"  writes:

>   This is an interesting setup, but I'm not sure I see why you need 
> it.  If you know that, in a particular context, you want toy(x, 0) to 
> result in 42 instead of ZeroDivisionError, 

... and that's the point.  You don't know whether you'll need it at the
call site.  Something further up has decided that, in its context, 42
shall be the magic value returned.  In some other context, there
shouldn't be a magic value, and the exception should terminate the
program.

My toy example was just that: a minimal example showing the machinery in
action.  The value of separating out exception handling like this is
only apparent if there's a fair amount of code in between the policy
(`return 42') and the site where the exception is signalled.

Small examples of powerful abstractions aren't very convincing: a small
example trivially doesn't require powerful abstraction.  Sorry.

-- [mdw]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparison with False - something I don't understand

2010-12-08 Thread OKB (not okblacke)
Mark Wooding wrote:
> Any code called from within the `with handler' context will (unless
> overridden) cause a call `toy(x, 0)' to return 42.  Even if the `with
> handler' block calls other functions and so on.  Note also that the
> expression of this is dynamically further from where the error is
> signalled than the resume point (which is within the same function).
> You can't do this with `try' ... `except'.  Which was, of course, the
> point.

This is an interesting setup, but I'm not sure I see why you need 
it.  If you know that, in a particular context, you want toy(x, 0) to 
result in 42 instead of ZeroDivisionError, why not just define

safeToy(x, y):
try:
retVal = toy(x, y)
except ZeroDivisionError:
retVal = 42
return retVal

. . . and then call safeToy instead of toy in those contexts?

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replacing globals in exec by custom class

2010-12-08 Thread Terry Reedy

On 12/8/2010 8:01 AM, Jonathan S wrote:


class Global(dict):
 def __init__(self):
 pass
 def __getitem__(self, key):
 import __builtin__
 if key == 'xx':
 return 'xx'

 if hasattr(__builtin__, key):
 return getattr(__builtin__, key)

 else key in self.__dict__:
 return self.__dict__[key]


syntax error


 def __setitem__(self, key, value):
 self.__dict__[key] = value

 def __str__(self):
 return '  ' + unicode(self.__dict__)


code="""
print globals()
print xx  # Does work, prints 'xx'

def q():
 print globals().__getitem__('xx') # Does work, prints 'xx'
 print globals()['xx']  # Does work, prints 'xx'
 print xx # Does not work, cannot find xx
q()
"""
g = Global()

exec(compile(code, 'my code', 'exec'), g, g)
}}}


When asking such questions, paste both the actual code that compiled and 
ran and the actual traceback you got in response.


--
Terry Jan Reedy

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


Can't deepcopy bytes-derived class

2010-12-08 Thread Dan
I have a simple type derived from bytes...

class atom(bytes):
   pass

... that I cannot deepcopy().  The session below demonstrates how
deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not.
What's going wrong?

Thanks,
Dan.


Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
(Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> import copy
>>> class atom(bytes):
... pass
...
>>> copy.deepcopy(b'abc')
b'abc'
>>> copy.deepcopy(atom(b'abc'))
Traceback (most recent call last):
  File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver
\_sandbox.py", line 1, in 
# Used internally for debug sandbox under external interpreter
  File "C:\Python31\Lib\copy.py", line 173, in deepcopy
y = _reconstruct(x, rv, 1, memo)
  File "C:\Python31\Lib\copy.py", line 280, in _reconstruct
y = callable(*args)
  File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__
return cls.__new__(cls, *args)
builtins.TypeError: string argument without an encoding
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: email discovering code

2010-12-08 Thread Sudheer Satyanarayana

On 12/08/2010 11:53 PM, Tracubik wrote:

Hi all,
i remember i've found somewhere (i think here but i'm not sure) a
signature of a user with a strange python code that, if runned on
terminal, reveal the email of the contact

Can anyone help me finding it?

thanks
Nico
   

import base64
encoded = base64.b64encode('m...@email.address')
print base64.b64decode(encoded)


--
With warm regards,
Sudheer. S
Personal home page - http://sudheer.net | Tech Chorus - 
http://techchorus.net

Web and IT services - http://binaryvibes.co.in
--
http://mail.python.org/mailman/listinfo/python-list


Re: del operator and global namespace

2010-12-08 Thread Dan Stromberg
Please try adding "global x" to the beginning of f().

On Wed, Dec 8, 2010 at 10:06 AM, alust  wrote:
> Hello,
>
> Can somebody explain this strange (to me) effect please.
>
> In this program it is impossible to access a global variable within a
> function:
>
> $ cat /tmp/test.py
> x='xxx'
> def f():
>     print x
>     del x
>
> f()
>
> $ python /tmp/test.py
> Traceback (most recent call last):
>   File "/tmp/test.py", line 6, in 
>     f()
>   File "/tmp/test.py", line 3, in f
>     print x
> UnboundLocalError: local variable 'x' referenced before assignment
>
> But if we comment the del operator the program will work:
>
> $ cat /tmp/test.py
> x='xxx'
> def f():
>     print x
>     #del x
>
> f()
>
> $ python /tmp/test.py
> xxx
>
> So why in this example the print operator is influenced by del
> operator
> that should be executed after it?
>
> --
> Thanks, Alexei
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP8 compliance and exception messages ?

2010-12-08 Thread Gerald Britton
I'm a bit late to the discussion, but remembering that raise takes an
expression, I can break it up like this:

>>> raise (
... Exception (
... "Long "
... "exception "
... "text."
... )
... )
Traceback (most recent call last):
  File "", line 3, in 
Exception: Long exception text

Then, you can indent the individual lines any way you like.
-- 
Gerald Britton
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: del operator and global namespace

2010-12-08 Thread MRAB

On 08/12/2010 18:06, alust wrote:

Hello,

Can somebody explain this strange (to me) effect please.

In this program it is impossible to access a global variable within a
function:

$ cat /tmp/test.py
x='xxx'
def f():
  print x
  del x

f()

$ python /tmp/test.py
Traceback (most recent call last):
File "/tmp/test.py", line 6, in
  f()
File "/tmp/test.py", line 3, in f
  print x
UnboundLocalError: local variable 'x' referenced before assignment

But if we comment the del operator the program will work:

$ cat /tmp/test.py
x='xxx'
def f():
  print x
  #del x

f()

$ python /tmp/test.py
xxx

So why in this example the print operator is influenced by del
operator
that should be executed after it?


The Python source code is compiled to bytecodes which are then
interpreted. It's during the compilation stage that it determines
whether a name is local. If you bind to a name:

x = 0

or del a name:

del x

anywhere in the function, it takes that name to be local.

When it actually interprets the bytecode at the print statement it
tries to reference the name, but nothing has been bound to it yet, so
it raises an exception.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python creates "locked" temp dir

2010-12-08 Thread Christian Heimes
Am 08.12.2010 10:31, schrieb Alex Willmer:
> 2. When you say "I am unable to access". Do you mean another script/
> process is unable to access? If so, that is the point of mkdtemp() -
> to make a temporary directory that _only_ the creating process can
> access. If you want to share it then tempfile is not the right module
> for you.

There isn't a way to limit access to a single process. mkdtemp creates
the directory with mode 0700 and thus limits it to the (effective) user
of the current process. Any process of the same user is able to access
the directory.

Christian

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


Re: class browser

2010-12-08 Thread Adam Tauno Williams
On Wed, 2010-12-08 at 13:18 +0530, Rustom Mody wrote:
> If I have a medium to large python code base to browse/study, what are
> the class browsers available?

Monodevelop has good Python support which includes a working Python
class browser for Python projects & solutions.


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


email discovering code

2010-12-08 Thread Tracubik
Hi all,
i remember i've found somewhere (i think here but i'm not sure) a 
signature of a user with a strange python code that, if runned on 
terminal, reveal the email of the contact

Can anyone help me finding it?

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


Re: Python creates "locked" temp dir

2010-12-08 Thread Christian Heimes
Am 08.12.2010 19:05, schrieb astar:
> Hi,
> 
> I recently got caught on tempfiles with respect  to
> urllib.urlretrieve, which can create a tmpfile.  Ah, but the file
> simply could not be found on the file system, even as root.  But
> within the program that created the tmpfile, you could do useful
> things with the tmpfile.  So the discussion in this thread is useful
> to me in understanding the rules.  But having been given a clue by
> someone else, I never did find any python library documentation that
> was at all informative, even to the level of discourse in this
> thread.

By default the tempfile module creates anonymous temporary files. The
files are created with O_CREAT | O_EXCL and unlinked ASAP. As a result
the temporary file no longer has a filename on the file system, just an
open file descriptor in the current process. If you need a file with a
name, use the NamedTemporaryFile feature of the tempfile module.

Christian

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


del operator and global namespace

2010-12-08 Thread alust
Hello,

Can somebody explain this strange (to me) effect please.

In this program it is impossible to access a global variable within a
function:

$ cat /tmp/test.py
x='xxx'
def f():
 print x
 del x

f()

$ python /tmp/test.py
Traceback (most recent call last):
   File "/tmp/test.py", line 6, in 
 f()
   File "/tmp/test.py", line 3, in f
 print x
UnboundLocalError: local variable 'x' referenced before assignment

But if we comment the del operator the program will work:

$ cat /tmp/test.py
x='xxx'
def f():
 print x
 #del x

f()

$ python /tmp/test.py
xxx

So why in this example the print operator is influenced by del
operator
that should be executed after it?

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


Re: Python creates "locked" temp dir

2010-12-08 Thread astar
Hi,

I recently got caught on tempfiles with respect  to
urllib.urlretrieve, which can create a tmpfile.  Ah, but the file
simply could not be found on the file system, even as root.  But
within the program that created the tmpfile, you could do useful
things with the tmpfile.  So the discussion in this thread is useful
to me in understanding the rules.  But having been given a clue by
someone else, I never did find any python library documentation that
was at all informative, even to the level of discourse in this
thread.

But here is a relevant question:  I wonder if a child process is the
*same* process as the parent for these purposes?

Thanks.

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


Re: Replacing globals in exec by custom class

2010-12-08 Thread DevPlayer
Shouldn't
return 'xx'
be
return self['xx'


I don't know why precisely you're using a class as a global namespace,
not that I personally find fault with it. But here are some other
things you can do.

Idea one:
==
class NS(object): """place to put junk"""

ns = NS()

ns.global_var1 = "SPAM and eggs"
ns.global_var2 = "use as you like just prefix with ns."
del ns.global_var  # because I'm fickle
dir(ns)

Idea two:
==
Instead of a class as a global namespace, use a module

ns.py
--
"""My global namespace"""
# do not import anything or make
# classes or run functions here, just a place to have varibles

ns_var = "var defined in ns.py"

ignore = ['__builtins__', '__class__', '__delattr__', '__dict__',
'__doc__', '__file__', '__format__', '__getattribute__', '__hash__',
'__init__', '__name__', '__new__', '__package__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__']

main.py

import ns
import mod1
import mod2
import mod3

ns.main_var = "this is main var"

ns.mod3_var = mod3.mod3_var
ns.mod3_somefunc_var = mod3.somefunc.somefunc_var

mod3.show( "ns.ns_var", ns.ns_var)
mod3.show( "ns.main_var", ns.main_var)
mod3.show( "ns.mod1_var", ns.mod1_var)
mod3.show( "ns.mod2_var", ns.mod2_var)
mod3.show( "ns.somefunc_var", ns.somefunc_var)
mod3.show( "ns.mod3_var", ns.mod3_var)
mod3.show( "ns.mod3_somefunc_var", ns.mod3_somefunc_var)
mod3.show( "dir(ns)", dir(ns))
mod3.list_globals()


mod1.py
---
import ns

# good usage; var not in mod1 global namespace and value is not copied
# from one namespace to another but just put in it.

ns.mod1_var = "this is text in mod1"

# therefore by doing this your code in mod1 is likely to use
# ns.mod1_var and not just mod1_var -is- not ns.mod1_var


mod2.py
---
import ns

ns.mod2_var = "text in mod2"


def somefunc():
# good app globals
ns.somefunc_var = "make a var not in the global namespace of the
mod2"
ns.renamed_var = "rename this"

somefunc()



mod3.py
---
# mod3_var is misleading; because you might use it but mod3.mod3_var
# would not be the same value as the ns.mod3_var
mod3_var = "not assigned to ns from in mod3.py but from main.py"


def somefunc():
# bad globals
somefunc.somefunc_var = "make a var not in the global namespace of
the mod3"
somefunc.renamed_var = "rename this"

somefunc()  # instinate somefunc_var

def show(astring, avalue):
print astring
print '   ', str(avalue)

def list_globals():
print 'ns variable list'
import ns
print '   [',
for item in dir(ns):
if not item in ns.ignore:
print "'" + item.strip() + "', ",
print ']'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replacing globals in exec by custom class

2010-12-08 Thread DevPlayer
Shouldn't
return 'xx'
be
return self['xx']
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replacing globals in exec by custom class

2010-12-08 Thread DevPlayer
Couple of things:

I don't think this is what you want:

   def __getitem__(self, key):
import __builtin__
if key == 'xx':
return 'xx'
I won't return a KeyError for any string you give g[]
It will return 'xx' only if you supply key='xx' and ignore every other
key=???
With the above code you can do g['yyy'] and you would get None

For your example code to work, line 14 in your example needs to be:
elif key in self.__dict__: # (change else to elif)

for your dict (or globalscl) to act like other dicts() add
an else:
raise KeyError( 'Key not found: %s' % (key,))

__dict__ of a dict I believe is not the namespace of dict. I thought
dict[key] and dict.__dict__[key] where not the same place

__dict__ of dict in Python 2.5 and prior was rumored to be buggy and
unused. Don't know about Python 2.6 +

I thought __getitem__() did not look in __dict__ of dict().

If I copy your code into a module globalcl.py
and comment out "print xx" in the string,
and in PyCrust I "import globalcl"
I too get the results and errors you claim.

If I then do:

>>>globalcl.g.keys()
I get: ['__builtins__']

>>>globalcl.g['__builtins__']
I get: nothing (or None)

>>>globalcl.g['__builtin__']
I get: nothing (or None)

# -
# interesting part

>>>globalcl.g['xx']
I get: 'xx'

>>>if 'xx' in globalcl.g:
...print True
...else:
...print False

I get: False
# -

>>>globalcl.g.__builtins__
AttributeError: 'Global' object has no attribute  __builtins__'

>>>globalcl.g.__builtins__
AttributeError: 'Global' object has no attribute '__builtin__'

>>>globalcl.g.__dict__
{'q': }



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


Re: Calling FORTAN dll functions from Python

2010-12-08 Thread Katie T
On Tue, Dec 7, 2010 at 11:11 AM, Alex van der Spek  wrote:

> Does anyone know how to call functions from FORTRAN dlls in Python? Is it
> even possible? I browsed the documentation for Python 2.6.1 and the Python/C
> API comes close to what I would like to do but it is strictly limited to C.
>
> Unfortunately the passing of arguments in C and FORTRAN is very different,
> not to mention the differences with strings where FORTRAN expects a hidden
> length argument. It could call the FORTRAN dll from C and call the C
> functions from Python but is that my only option?
>
> For reference: I am using Python 2.6.1 FORTRAN powerstation 4.0. It is not
> an option to translate the FORTRAN code to C (using f2c) as the source code
> is the official ASME version of calculating steam tables.
>
>
I've done it before by creating C wrapper function and it was relatively
painless, using C wrappers means that it's much easier to integrate into
other languages as well if you need to do more integration down the line.

Katie
-- 
CoderStack
http://www.coderstack.co.uk
The Software Developer Job Board
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wanted: slow regexes

2010-12-08 Thread MRAB

On 08/12/2010 12:42, Alexander Gattin wrote:

Hello,

On Mon, Dec 06, 2010 at 04:08:16AM +, MRAB wrote:

I'm looking for examples of regexes which are
slow (especially those which seem never to
finish) but whose results are known.


does it have anything to do with
http://swtch.com/~rsc/regexp/regexp1.html?


The new regex still uses backtracking.

Interestingly, that webpage says that:

("a" x 10) =~ /^(ab?)*$/

caused Perl to segfault. I tried it and it didn't segfault, but it
didn't match either, although:

("a" x 1) =~ /^(ab?)*$/

did match.

Neither the re nor regex modules had any problem with it!
--
http://mail.python.org/mailman/listinfo/python-list


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread nn
On Dec 7, 10:52 am, gst  wrote:
> Hi,
>
> I met a situation where I was passing an object created in/with an
> upper level module class to a lower level module class' instance in
> one of its __init__ argument and saving a ref of the upper object in
> that lower level class' new instance.
>
> But in my IDE I want the completion to also work from within the lower
> level module when it's refering to the object passed from the upper
> level:
>
> Well, I'm sure I'm not very clear in my terms (and probably a bit long
> in the sentence) so here it is in code:
>
> files:
> module1.py
> subpackage/module2.py
>
> file module1.py:
>
> from subpackage.module2 import class2
>
> class class1(object):
>
>     def __new__(cls, _self=None, *args, **kwargs):
>         if _self:  ## we've been passed an instance already
> initialyzed
>                      ## so directly return it instead of creating a
> new object.
>             return _self
>         return object.__new__(cls)
>
>     def __init__(self, _self=None, *args, **kwargs):
>         if _self:  ## we've been passed an instance already
> initialyzed
>                      ## so directly returns
>             ## assert(self is _self) ?
>             return
>         self.object2 = class2(object1=self, "blip", "blop")
>         # others init
>
> file module2.py:
>
> class class2(object):
>
>     def __init__(self, object1, *args, **kwargs):
>
>         from ..module1 import class1
>
>         self.object1 = class1(_self=object1)    ## instead of:
> self.object1 = object1
>
>     ## others functions and/or init..
>     ## where  now I've completion working on self.object1 :
>     ## if I add(or remove) fields/methods in module1 (and save) then
>     ## I have them available(or disappeared) in the completion when
> executed from this submodule.
>     ## This ofcourse permits to save me of remembering all of the
> class1 attributes/methods when I'm working with self.object1 from
> within one of class2 methods.
>
> What do you think of this ?
>
> I guess there can be others ways of doing this..  ?
>
> Thanks,
>
> Regards,
>
> Greg.
>
> note: I'm using Eclipse 3.5.2 with pydev so (I don't really know how
> others IDE can handle this case) .

You might want to test with Wing IDE http://wingware.com/
using the 10 day trial version to see if that works just for kicks.
I've heard it has the best autocomplete of all IDEs out there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread Jean-Michel Pichavant



quoting eclipse page:

"Pydev [...] uses advanced type inference techniques to provide features
such code completion and code analysis"

I don't know exactly what's hidden behind this marketing stuff. Did you
try to document your method with a markup language supported by Eclipse
(if there is any)?



pydev completion apparently is restricted (as far as i see) to some
very specific cases (basically it works when you import a module at
top of another one and that you instantiate objects from the imported
module within the init methods of the classes of the module which is
importing the other one (but so "circular" references created on some
objects from the first module (the one imported) in the second one
won't have the completion working for them (that's what I see)).
  


To understand what is possible and what is not, you simply need to think 
like a completion feature.


case 1:
self.object = MyClass()

self.object is a MyClass instance, easy stuff I need to parse MyClass 
and get the list of attributes/method


case 2:

self.object = object1

There may be simply no way to know the type/class of object1, object1 
could be even of an inconsistent type, sometimes None, int, MyClass, who 
knows ?
Your trick worked because you found a way to write self.object = 
MyClass(object1) and getting barely the same effect than self.object = 
object1.


I'm still thinking that's it's a bad idea. In any case your IDE can 
still be fooled by the dynamic  of python (like pylint is)


How to write python code then ? Well I guess most people either knows 
all the attributes by heart, have the documentation, or a split screen 
to the class definition, possibly folded using advanced text editor 
feature. You need to forget about code completion with any dynamic 
language. I also sometimes use an ipython shell to instanciate objects 
and inspect their attributes.


JM

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


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread gst
On 8 déc, 16:20, gst  wrote:

> even with the "assert(self is _self)" in the "if _self:" condition in
> the new and/or  init methods of the class1 ?

damn : in the init method only of course..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread gst
On 8 déc, 16:20, gst  wrote:
> On 8 déc, 15:51, Jean-Michel Pichavant  wrote:
>
> Hi,
>
> > gst wrote:
> > > nb: so this "hack" is only relevant during dev ; once the project
> > > would be finished the "hack" could be removed (i.e : in class2 init I
> > > would directly do : self.object1 = object1)
>
> > Expect some bugs then on the 'release' version.
>
> even with the "assert(self is _self)" in the "if _self:" condition in
> the new and/or  init methods of the class1 ?

note: I don't know if that matters but I'm using __slots__ in this
class1 ..

greg.

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


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread gst
On 8 déc, 15:51, Jean-Michel Pichavant  wrote:

Hi,


> gst wrote:
> > nb: so this "hack" is only relevant during dev ; once the project
> > would be finished the "hack" could be removed (i.e : in class2 init I
> > would directly do : self.object1 = object1)
>
> Expect some bugs then on the 'release' version.

even with the "assert(self is _self)" in the "if _self:" condition in
the new and/or  init methods of the class1 ?


> I'm not sure I understood everything you mentioned in your OP, however
> writing python code on class creation to make Eclipse completion 'work'
> is ... a very bad idea IMO.
> Just don't do it.

yes I'm trying to find better ways for having completion works out of
the box in this case.. (that would be a high help to my opinion).


> quoting eclipse page:
>
> "Pydev [...] uses advanced type inference techniques to provide features
> such code completion and code analysis"
>
> I don't know exactly what's hidden behind this marketing stuff. Did you
> try to document your method with a markup language supported by Eclipse
> (if there is any)?

pydev completion apparently is restricted (as far as i see) to some
very specific cases (basically it works when you import a module at
top of another one and that you instantiate objects from the imported
module within the init methods of the classes of the module which is
importing the other one (but so "circular" references created on some
objects from the first module (the one imported) in the second one
won't have the completion working for them (that's what I see)).


> class class2(object):
>     def __init__(self, object1, *args, **kwargs):
>     """blablabla
>
>     @param object1: a L{class1} reference
>     """
>     self.object1 = object1
>
> The docstring would be the only way for an IDE to infer a argument type.
> Note that I used the epydoc markup language because it's the only one I
> know but it's unlikely supported by Eclipse. You better try
> reStructuredText.
>
> JM

well, I'm not very used to docstrings in fact but it's effectively a
way to achieve this ; well certainly better than doing this kind of
"ugly" hack so.
I'll have a try at that.

Thanks for your reply,

regards,

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


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread Jean-Michel Pichavant

gst wrote:

greg.

nb: so this "hack" is only relevant during dev ; once the project
would be finished the "hack" could be removed (i.e : in class2 init I
would directly do : self.object1 = object1)
  


Expect some bugs then on the 'release' version.
I'm not sure I understood everything you mentioned in your OP, however 
writing python code on class creation to make Eclipse completion 'work' 
is ... a very bad idea IMO.

Just don't do it.

quoting eclipse page:

"Pydev [...] uses advanced type inference techniques to provide features 
such code completion and code analysis"


I don't know exactly what's hidden behind this marketing stuff. Did you 
try to document your method with a markup language supported by Eclipse 
(if there is any)?


class class2(object):
   def __init__(self, object1, *args, **kwargs):
   """blablabla

   @param object1: a L{class1} reference
   """
   self.object1 = object1

The docstring would be the only way for an IDE to infer a argument type.
Note that I used the epydoc markup language because it's the only one I 
know but it's unlikely supported by Eclipse. You better try 
reStructuredText.


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


64 bit memory usage

2010-12-08 Thread Rob Randall
I am trying to understand how much memory is available to a 64 bit python
process running under Windows XP 64 bit.

When I run tests just creating a series of large dictionaries containing
string keys and float values I do not seem to be able to grow the process
beyond the amount of RAM present.

For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at
around 2GB.

On another machine with 16GB RAM and 24GB pagefile the process stalls at
16GB.

In other tests where a C++ program loads and runs the python DLL, if C++
based operations are performed the memory usage will grow to 40GB, but if
python is used to grab the memory it can still only grow to 16GB. With this
program if the memory usage is grown to over 16GB on the C++ side,
attempting to grab any from python crashes the process.

I was under the impression that python could grab as much memory as other
programs.

Can anyone tell me what is happening or where I may be going wrong?

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


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread gst
On 8 déc, 14:09, Steve Holden  wrote:
>
> If you'd told us which IDE you were using we might have offered better
> advice, but you seem to want to keep that a secret ("my IDE" tells us
> nothing).
>

sorry it was totally bottom of my first message :

> note: I'm using Eclipse 3.5.2 with pydev so (I don't really know how
others IDE can handle this case) .

now I realyze that my question has not a lot to do with python
language itself and I should resubmit that probably on pydev forums/..

but as I told I wanted to have some advises on the "good" (or not) use
of this "way of doing" with python itself.  You already explained me
it's not the best so far.. and I agree although during (my) dev it
helps ;) (but I do this only with very few classes that have lot of
attributes/methods ofcourse).

regards,

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


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread Steve Holden
On 12/8/2010 1:01 PM, gst wrote:
> As I told I try to have some kind of "ultimate" autocompletion, always
> working for this kind of case (I know exactly that a certain member of
> a certain class' instance will always have the same type but my IDE
> doesn't seem to guess/know it.. ; I guess the best answer would be :
> bad IDE, change IDE but I'm guessing that others IDE can't do a lot
> better in this case.
> 
If you'd told us which IDE you were using we might have offered better
advice, but you seem to want to keep that a secret ("my IDE" tells us
nothing).

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: Python creates "locked" temp dir

2010-12-08 Thread utabintarbo
Thanks for the reply.

The relevant function (in a module) is as follows:

def createWorkDir(pathdir="k:\\"):
import tempfile, os

if os.name == 'posix':
pathdir = os.path.join(config.get('paths', 'MOUNTPOINT'),
'subdir1')
else:
pathdir = os.path.normpath(r"\\windowsmount\subdir1")
if not os.path.exists(os.path.join(pathdir,'tmp','program')):
os.makedirs(os.path.join(pathdir,'tmp','program'))
return os.path.normpath(tempfile.mkdtemp("", "",
os.path.join(pathdir,'tmp','program')))

The calling program calls the function as such:
updateWorkDir = createWorkDir()

I then attempt to copy a file (using shutil.move) into updateWorkDir
and get an:

IOError: [Errno 13] Permission denied: '/MOUNTPOINT/subdir1/tmp/
program/y-Z0h3/file.ext'

I also tried to create a similar dir under 'tmp' using os.mkdir and
while the dir was not locked such that only the owner could do
anything in it, it was not writeable by anything other than the owner,
even when mode 0777 was specified explicitly.

Thanks for the help.



On Dec 8, 4:31 am, Alex Willmer  wrote:
> On Dec 7, 9:03 pm, utabintarbo  wrote:
>
> > I am using tempfile.mkdtemp() to create a working directory on a
> > remote *nix system through a Samba share. When I use this on a Windows
> > box, it works, and I have full access to the created dir. When used on
> > a Linux box (through the same Samba share), the created directory
> > shows as "locked", and I am unable to access. Obviously, I need
> > access. Any clues?
>
> You haven't provided enough details to go on.
> 1. Please post the actual code, and the trace back (if any).
> 2. When you say "I am unable to access". Do you mean another script/
> process is unable to access? If so, that is the point of mkdtemp() -
> to make a temporary directory that _only_ the creating process can
> access. If you want to share it then tempfile is not the right module
> for you.
>
> Regards, Alex

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


Replacing globals in exec by custom class

2010-12-08 Thread Jonathan S
Hi all,

I wonder if anyone can explain some weird behaviour in Python.
What I'm trying to do is to execute a string of python code through
the 'exec' statement. I pass an instance of my Global class, which
acts like a dict. By overriding the __getitem__ method, the Global
should pretend that a global variable, named 'xx' does exist.

This does work for the outermost scope in the executed code, but
inside the nested function, 'q', the Global instance seems never to be
accessed, 'xx' is not found, while the globals() built-in still
returns the custom Global instance.

According to python's executing model [1], the interpreter is supposed
to look into globals(), if a variable has not been assigned in the
inner scope. What am I missing here?

[1] http://docs.python.org/reference/executionmodel.html


{{{
class Global(dict):
def __init__(self):
pass
def __getitem__(self, key):
import __builtin__
if key == 'xx':
return 'xx'

if hasattr(__builtin__, key):
return getattr(__builtin__, key)

else key in self.__dict__:
return self.__dict__[key]

def __setitem__(self, key, value):
self.__dict__[key] = value

def __str__(self):
return '  ' + unicode(self.__dict__)


code="""
print globals()
print xx  # Does work, prints 'xx'

def q():
print globals().__getitem__('xx') # Does work, prints 'xx'
print globals()['xx']  # Does work, prints 'xx'
print xx # Does not work, cannot find xx
q()
"""
g = Global()

exec(compile(code, 'my code', 'exec'), g, g)
}}}




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


Re: Wanted: slow regexes

2010-12-08 Thread Alexander Gattin
Hello,

On Mon, Dec 06, 2010 at 04:08:16AM +, MRAB wrote:
> I'm looking for examples of regexes which are
> slow (especially those which seem never to
> finish) but whose results are known.

does it have anything to do with
http://swtch.com/~rsc/regexp/regexp1.html?

-- 
With best regards,
xrgtn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparisons of incompatible types

2010-12-08 Thread Tim Chase

On 12/08/2010 03:47 AM, Steven D'Aprano wrote:

Or a list that needs to be presented to a human reader in some arbitrary
but consistent order.

Or a doctest that needs to show the keys in a dict:

 >>>  d = myfunction()
 >>>  sorted(d.keys())
 ['ham', 'spam', 42, None]


[snip]


Agreed, but in hindsight I think it would be better if there was a
separate lexicographic sort function, that guaranteed to sort anything
(including such unorderable values as complex numbers!), without relying
on the vagaries of the standard comparison operators.


wouldn't that be something like

  sorted(mixedstuff, key=str)

or if all you need is a stable order regardless of what that 
order is, one could even get away with:


  sorted(mixedstuff, key=id)

-tkc




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


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread gst
On 8 déc, 11:45, Steven D'Aprano  wrote:
> On Tue, 07 Dec 2010 07:52:06 -0800, gst wrote:
> > Hi,
>
> > But in my IDE I want the completion to also work from within the lower
> > level module when it's refering to the object passed from the upper
> > level:
>
> "The completion"? What do you mean?

Hi,

I mean the autocompletion feature of my IDE :

when I type "object."  then on the "." it shows me possible members/
methods of the 'object'. depending on what my IDE can guess about the
object possible type(s) ;  in the worst case it can't guess nothing
about it and that's my point below..


> > Well, I'm sure I'm not very clear in my terms (and probably a bit long
> > in the sentence) so here it is in code:
>
> I'm afraid I have to agree with your, your description is not clear to me.

I hope I'm now ;)

> Unfortunately, neither is your code, because I don't understand *why* you
> do the things you do.

damn. ok let's go..


> > file module1.py:
>
> > from subpackage.module2 import class2
>
> Is it relevant that class2 comes from another module?

yes.  hmmm or maybe not completely.. I think it only highly depends on
what the IDE can guess on an object type used inside some methods
depending on the files hierarchy..


> Would your concept work if class1 and class2 were defined in the same file?

I guess yes also.


> > class class1(object):
>
> >     def __new__(cls, _self=None, *args, **kwargs):
> >         if _self:  ## we've been passed an instance already
> > initialyzed
> >                      ## so directly return it instead of creating a
> > new object.
> >             return _self
> >         return object.__new__(cls)
>
> Depending on your application, this may be an unsafe assumption. If the
> caller says class1("spam"), your class will return "spam". This may or
> may not be what you want.

I'm always passing the good object type when I do this.


> >     def __init__(self, _self=None, *args, **kwargs):
> >         if _self:  ## we've been passed an instance already
> > initialyzed
> >                      ## so directly returns
> >             ## assert(self is _self) ?
> >             return
> >         self.object2 = class2(object1=self, "blip", "blop") # others
> >         init
>
> Okay, this seems like a fairly straightforward case of adding an
> attribute to your instance that includes a reference to itself. No big
> deal... there's nothing wrong with this, although you are creating a
> reference cycle, which is somewhat of a (mild) code-smell.

that is a worry effectively.  (hmm when you say it's a case of adding
an attribute that includes a ref to itself it's not really that (or i
badly understand) : it's adding an attribute to a lower level class
instance that contains a ref to an upper level class instance (which
also contains a ref to the lower level class' instance and that's the
cycle (and that's a bit my worry))

> > file module2.py:
>
> > class class2(object):
>
> >     def __init__(self, object1, *args, **kwargs):
>
> >         from ..module1 import class1
>
> Now you have a circular import, and that's a pretty major code smell.
> That's dangerous. Try to avoid it. Perhaps the easiest way to avoid it is
> to place class1 and class2 in the same module, and stop writing Java :)

damn if this looks like Java it's really not my will ;  I've not made
Java anymore for probably 10 years !

I'll try by putting class1 and  class2 in same module (or at same
directory level first) and see if that can do it..

>
> >         self.object1 = class1(_self=object1)    ## instead of:
> > self.object1 = object1
>
> >     ## others functions and/or init..
> >     ## where  now I've completion working on self.object1 : ## if I
> >     add(or remove) fields/methods in module1 (and save) then ## I have
> >     them available(or disappeared) in the completion when
> > executed from this submodule.
> >     ## This ofcourse permits to save me of remembering all of the
> > class1 attributes/methods when I'm working with self.object1 from within
> > one of class2 methods.
>
> I'm afraid I don't understand what you mean here in these comments. What
> do you mean, "save me of (from?) remembering all the class1 attributes/
> methods..." -- how does it save you from knowing the methods? Whether you
> write this:
>
> instance = class1()
> instance.method()
>
> or this:
>
> instance = class1()
> another_instance = class2(instance)
> another_instance.object1.method()
>
> you still need to know the name "method".
>
> It seems to me that this scheme is unnecessarily complex, convoluted and
> confusing, for very little gain. Perhaps you could try explaining what
> you hope to accomplish, giving examples?

Effectively I recognise that this seems like a bit silly/odd .. but as
it's working I wanted some advises so ;)

As I told I try to have some kind of "ultimate" autocompletion, always
working for this kind of case (I know exactly that a certain member of
a certain class' instance will always have the same type but my

Re: Case Sensitive Section names configparser

2010-12-08 Thread Jon Clements
On Dec 8, 10:32 am, RedBaron  wrote:
> Is there any way by which configParser's get() function can be made
> case insensitive?

I would probably subclass dict to create a string specific, case
insensitive version, and supply it as the dict_type. See
http://docs.python.org/library/configparser.html#ConfigParser.RawConfigParser

That way your values would remain cased correctly, but lookups would
be insensitive.

hth

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


Re: class browser

2010-12-08 Thread Jean-Michel Pichavant

Rustom Mody wrote:
If I have a medium to large python code base to browse/study, what are 
the class browsers available?

vim + ctags is one of them.

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


Re: Case Sensitive Section names configparser

2010-12-08 Thread Francesco Bochicchio
On 8 Dic, 11:32, RedBaron  wrote:
> Is there any way by which configParser's get() function can be made
> case insensitive?

If you don't care about the case of the config parameter values, you
could pre-convert the input to
configParser all in UPPER or lower letter with a file-like object like
this (NOT TESTED):

class AllUpperFile(object):
def __init__(self, fname): self.fp = file(fname)
def readline(self): return self.fp.readline().upper()

and the use configParser.readfp method to feed the file-like object to
the config parser

 myConfigparser.readfp( AllUpperFile("myconnfigfile.cfg")

HTH

Ciao

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


Re: use of __new__ to permit "dynamic" completion within (any?) IDE ?

2010-12-08 Thread Steven D'Aprano
On Tue, 07 Dec 2010 07:52:06 -0800, gst wrote:

> Hi,
> 
> I met a situation where I was passing an object created in/with an upper
> level module class to a lower level module class' instance in one of its
> __init__ argument and saving a ref of the upper object in that lower
> level class' new instance.
> 
> But in my IDE I want the completion to also work from within the lower
> level module when it's refering to the object passed from the upper
> level:

"The completion"? What do you mean?


> Well, I'm sure I'm not very clear in my terms (and probably a bit long
> in the sentence) so here it is in code:

I'm afraid I have to agree with your, your description is not clear to me.

Unfortunately, neither is your code, because I don't understand *why* you 
do the things you do.


> files:
> module1.py
> subpackage/module2.py
> 
> 
> file module1.py:
> 
> from subpackage.module2 import class2

Is it relevant that class2 comes from another module? Would your concept 
work if class1 and class2 were defined in the same file?

By the way, it's conventional (but not compulsory) to name classes with 
an initial capital letter, and instances in all lowercase.



> class class1(object):
> 
> def __new__(cls, _self=None, *args, **kwargs):
> if _self:  ## we've been passed an instance already
> initialyzed
>  ## so directly return it instead of creating a
> new object.
> return _self
> return object.__new__(cls)

Depending on your application, this may be an unsafe assumption. If the 
caller says class1("spam"), your class will return "spam". This may or 
may not be what you want.


> def __init__(self, _self=None, *args, **kwargs):
> if _self:  ## we've been passed an instance already
> initialyzed
>  ## so directly returns
> ## assert(self is _self) ?
> return
> self.object2 = class2(object1=self, "blip", "blop") # others
> init

Okay, this seems like a fairly straightforward case of adding an 
attribute to your instance that includes a reference to itself. No big 
deal... there's nothing wrong with this, although you are creating a 
reference cycle, which is somewhat of a (mild) code-smell.

 
> file module2.py:
> 
> class class2(object):
> 
> def __init__(self, object1, *args, **kwargs):
> 
> from ..module1 import class1

Now you have a circular import, and that's a pretty major code smell. 
That's dangerous. Try to avoid it. Perhaps the easiest way to avoid it is 
to place class1 and class2 in the same module, and stop writing Java :)


> self.object1 = class1(_self=object1)## instead of:
> self.object1 = object1
> 
> ## others functions and/or init..
> ## where  now I've completion working on self.object1 : ## if I
> add(or remove) fields/methods in module1 (and save) then ## I have
> them available(or disappeared) in the completion when
> executed from this submodule.
> ## This ofcourse permits to save me of remembering all of the
> class1 attributes/methods when I'm working with self.object1 from within
> one of class2 methods.

I'm afraid I don't understand what you mean here in these comments. What 
do you mean, "save me of (from?) remembering all the class1 attributes/
methods..." -- how does it save you from knowing the methods? Whether you 
write this:

instance = class1()
instance.method()

or this:

instance = class1()
another_instance = class2(instance)
another_instance.object1.method()

you still need to know the name "method".

It seems to me that this scheme is unnecessarily complex, convoluted and 
confusing, for very little gain. Perhaps you could try explaining what 
you hope to accomplish, giving examples?


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


Re: is py2exe still active ?

2010-12-08 Thread Jonathan Hartley
On Dec 8, 10:09 am, "Octavian Rasnita"  wrote:
> Hi Steve,
>
> I may put some stupid questions because I am very new to Python, but... I 
> heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) 
> provided on a central archive where we can get them and also report the bugs 
> using a single request/issue tracker?
>
> Octavian
>
>
>
> - Original Message -
> From: "Steve Holden" 
>
> Newsgroups: gmane.comp.python.general
> To: "Octavian Rasnita" 
> Cc: 
> Sent: Wednesday, December 08, 2010 12:56 AM
> Subject: Re: is py2exe still active ?
>
> > Octavian:
>
> > It's great that you want to let people know about bugs. Put yourself in
> > the position of the package maintainer, however. She or he doesn't spend
> > all day working on cxFreeze, and probably doesn't even do a Google
> > search on cxFreeze very often. So they are unlikely to find out about
> > this problem form your well-intentioned note.
>
> > It's just possible nobody does care, as I can't find a link to an issue
> > tracker - the best I could advise in this case would be to join the
> > mailing list by visiting
>
> >  https://lists.sourceforge.net/lists/listinfo/cx-freeze-users
>
> > regards
> > Steve
>
> > On 12/7/2010 6:49 PM, Octavian Rasnita wrote:
> >> This packager is also nice.
>
> >> If someone cares, I've discovered a small bug in it.
> >> If Python is installed on another drive than C under Windows, the 
> >> cxfreeze.bat file still calls Python on the drive C and it doesn't work 
> >> until it is corrected.
>
> >> Octavian
>
> >> - Original Message -
> >> From: "Cbast" 
> >> Newsgroups: comp.lang.python
> >> To: 
> >> Sent: Tuesday, December 07, 2010 5:00 PM
> >> Subject: Re: is py2exe still active ?
>
> >> On Dec 7, 8:23 am, Anders Persson  wrote:
> >>> Hi!
> >>> When a look att py2exe homepage it is not looking like mutch happen,
> >>> as a beginner i was thinking to start with Python 3, but i like to now
> >>> if py2exe will be for 3 too.
>
> >>> Is any one have any info ?
>
> >> I don't have the answer about py2exe, but I'm using cxFreeze to create
> >> executables with Python 3.1, if it's what you're looking for.
>
> >>http://cx-freeze.sourceforge.net/
>
> > --
> > Steve Holden           +1 571 484 6266   +1 800 494 3119
> > PyCon 2011 Atlanta March 9-17      http://us.pycon.org/
> > See Python Video!      http://python.mirocommunity.org/
> > Holden Web LLC                http://www.holdenweb.com/

Hey,

Yes, they are all Python packages or applications, and yes, PyPI aka
The Cheese Shop is a single repository for them. However, they do not
share mailing lists or issue trackers. Each project maintains its own
bug tracking, etc.

Best regards,

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


Re: is py2exe still active ?

2010-12-08 Thread Jonathan Hartley
On Dec 8, 10:09 am, "Octavian Rasnita"  wrote:
> Hi Steve,
>
> I may put some stupid questions because I am very new to Python, but... I 
> heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) 
> provided on a central archive where we can get them and also report the bugs 
> using a single request/issue tracker?
>
> Octavian
>
>
>
> - Original Message -
> From: "Steve Holden" 
>
> Newsgroups: gmane.comp.python.general
> To: "Octavian Rasnita" 
> Cc: 
> Sent: Wednesday, December 08, 2010 12:56 AM
> Subject: Re: is py2exe still active ?
>
> > Octavian:
>
> > It's great that you want to let people know about bugs. Put yourself in
> > the position of the package maintainer, however. She or he doesn't spend
> > all day working on cxFreeze, and probably doesn't even do a Google
> > search on cxFreeze very often. So they are unlikely to find out about
> > this problem form your well-intentioned note.
>
> > It's just possible nobody does care, as I can't find a link to an issue
> > tracker - the best I could advise in this case would be to join the
> > mailing list by visiting
>
> >  https://lists.sourceforge.net/lists/listinfo/cx-freeze-users
>
> > regards
> > Steve
>
> > On 12/7/2010 6:49 PM, Octavian Rasnita wrote:
> >> This packager is also nice.
>
> >> If someone cares, I've discovered a small bug in it.
> >> If Python is installed on another drive than C under Windows, the 
> >> cxfreeze.bat file still calls Python on the drive C and it doesn't work 
> >> until it is corrected.
>
> >> Octavian
>
> >> - Original Message -
> >> From: "Cbast" 
> >> Newsgroups: comp.lang.python
> >> To: 
> >> Sent: Tuesday, December 07, 2010 5:00 PM
> >> Subject: Re: is py2exe still active ?
>
> >> On Dec 7, 8:23 am, Anders Persson  wrote:
> >>> Hi!
> >>> When a look att py2exe homepage it is not looking like mutch happen,
> >>> as a beginner i was thinking to start with Python 3, but i like to now
> >>> if py2exe will be for 3 too.
>
> >>> Is any one have any info ?
>
> >> I don't have the answer about py2exe, but I'm using cxFreeze to create
> >> executables with Python 3.1, if it's what you're looking for.
>
> >>http://cx-freeze.sourceforge.net/
>
> > --
> > Steve Holden           +1 571 484 6266   +1 800 494 3119
> > PyCon 2011 Atlanta March 9-17      http://us.pycon.org/
> > See Python Video!      http://python.mirocommunity.org/
> > Holden Web LLC                http://www.holdenweb.com/

Hey,

Yes, they are all Python packages or applications, and yes, PyPI aka
The Cheese Shop is a single repository for them. However, they do not
share mailing lists or issue trackers. Each project maintains its own
bug tracking, etc.

Best regards,

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


Re: Calling FORTAN dll functions from Python

2010-12-08 Thread Carl Banks
On Dec 7, 3:11 am, "Alex van der Spek"  wrote:
> Does anyone know how to call functions from FORTRAN dlls in Python? Is it
> even possible? I browsed the documentation for Python 2.6.1 and the Python/C
> API comes close to what I would like to do but it is strictly limited to C.
>
> Unfortunately the passing of arguments in C and FORTRAN is very different,
> not to mention the differences with strings where FORTRAN expects a hidden
> length argument. It could call the FORTRAN dll from C and call the C
> functions from Python but is that my only option?

I'd recommend f2py, which is part of the numpy package.


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


Case Sensitive Section names configparser

2010-12-08 Thread RedBaron
Is there any way by which configParser's get() function can be made
case insensitive?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparisons of incompatible types

2010-12-08 Thread Steven D'Aprano
On Tue, 07 Dec 2010 15:08:23 -0800, John Nagle wrote:

> If you're thinking hard about this, I recommend viewing Alexander
> Stepanov's talk at Stanford last month:
> 
> http://www.stanford.edu/class/ee380/Abstracts/101103.html
> 
> He makes the point that, for generic programs to work right, the basic
> operations must have certain well-defined semantics.  Then the same
> algorithms will work right across a wide variety of objects.

But they already work right across a wide variety of objects, so long as 
you limit yourself to the subset of objects where the basic operations 
have the same semantics.

I think that insisting that all operators must always have the same 
semantics is as impractical and unnecessary as insisting that all 
functions and methods with the same name must always have the same 
semantics. We wouldn't expect 

pencil.draw
six_shooter.draw
game.draw

to all have the same semantics, or

math.sin
priest.sin

despite the inconvenience it makes to duck-typing. Why should we expect 
more from operators than we expect from named functions, when there are 
so many more named functions and so few useful symbols for operators?

To my mind, it is foolish for us to expect x*y to always have the same 
semantics when even mathematicians don't expect that. In pure 
mathematics, x*y != y*x for any of the following:

matrices
quaternions
octonions

and probably many others I don't know about.


> This is consistent with Python's "duck typing", but inconsistent
> with the current semantics of some operators.
> 
> For example, "+" as concatenation makes "+" non-commutative.

No, it only makes + non-commutative for those types where + is non-
commutative.


> In other words,
> 
>   a + b
> 
> is not always equal to
> 
>   b + a
> 
> which is not good.

I don't see why. It seems to me that it's only a bad thing if you hope to 
reason about the meaning of a+b without knowing what a and b actually are.

Personally, I don't consider that a particularly useful trait.


> Important properties to have across all types:
> 
>   a + b == b + a
> 
> Exactly one of
> 
>   a > b
>   a = b
>   a < b
> 
> is true, or an type exception must be raised.

As Mark Wooding has already pointed out, that would make numeric 
programmers mad, as it eliminates NANs, which are far more important to 
them. And me.

It also would make it impossible to use > and < to talk about rankings in 
natural hierarchies, such as (say) pecking orders. Using > to mean "out-
ranks", you might have a pecking order among five hens like this:

A > B > C > D > E

but

D > B

Not all comparisons are equivalence relations, and it would be a crying 
shame to lose the ability to use > and < to discuss (e.g.) non-transitive 
comparisons.



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


Re: group 0 in the re module

2010-12-08 Thread J. Gerlach
Am 08.12.2010 03:23, schrieb Yingjie Lan:
> Hi, 
> 
> According to the doc, group(0) is the entire match.
> 
 m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist") 
 m.group(0) # The entire match 'Isaac Newton' 
> 
> But if you do this:
 import re
 re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234')
> '\x00 to 757-234'
> 
> where I expected
> '757234 to 757-234'
> 
> Then I found that in python re '\0' is considered an octal number.
> So, is there anyway to refer to the entire match by an escaped
> notation?
> 
> Thanks,
> 
> Yingjie
> 
the documentation of the re module says:

>  \g uses the corresponding group number; \g<2> is
>  therefore equivalent to \2, but isn’t ambiguous in a replacement such
>  as \g<2>0. \20 would be interpreted as a reference to group 20, not a
>  reference to group 2 followed by the literal character '0'. The
>  backreference \g<0> substitutes in the entire substring matched by
>  the RE.

.. so you're looking for r"\g<0> to \1-\2"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is py2exe still active ?

2010-12-08 Thread Octavian Rasnita
Hi Steve,

I may put some stupid questions because I am very new to Python, but... I heard 
about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a 
central archive where we can get them and also report the bugs using a single 
request/issue tracker?

Octavian

- Original Message - 
From: "Steve Holden" 
Newsgroups: gmane.comp.python.general
To: "Octavian Rasnita" 
Cc: 
Sent: Wednesday, December 08, 2010 12:56 AM
Subject: Re: is py2exe still active ?


> Octavian:
> 
> It's great that you want to let people know about bugs. Put yourself in
> the position of the package maintainer, however. She or he doesn't spend
> all day working on cxFreeze, and probably doesn't even do a Google
> search on cxFreeze very often. So they are unlikely to find out about
> this problem form your well-intentioned note.
> 
> It's just possible nobody does care, as I can't find a link to an issue
> tracker - the best I could advise in this case would be to join the
> mailing list by visiting
> 
>  https://lists.sourceforge.net/lists/listinfo/cx-freeze-users
> 
> regards
> Steve
> 
> On 12/7/2010 6:49 PM, Octavian Rasnita wrote:
>> This packager is also nice.
>> 
>> If someone cares, I've discovered a small bug in it.
>> If Python is installed on another drive than C under Windows, the 
>> cxfreeze.bat file still calls Python on the drive C and it doesn't work 
>> until it is corrected.
>> 
>> Octavian
>> 
>> - Original Message - 
>> From: "Cbast" 
>> Newsgroups: comp.lang.python
>> To: 
>> Sent: Tuesday, December 07, 2010 5:00 PM
>> Subject: Re: is py2exe still active ?
>> 
>> 
>> On Dec 7, 8:23 am, Anders Persson  wrote:
>>> Hi!
>>> When a look att py2exe homepage it is not looking like mutch happen,
>>> as a beginner i was thinking to start with Python 3, but i like to now
>>> if py2exe will be for 3 too.
>>>
>>> Is any one have any info ?
>> 
>> I don't have the answer about py2exe, but I'm using cxFreeze to create
>> executables with Python 3.1, if it's what you're looking for.
>> 
>> http://cx-freeze.sourceforge.net/
> 
> 
> -- 
> Steve Holden   +1 571 484 6266   +1 800 494 3119
> PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
> See Python Video!   http://python.mirocommunity.org/
> Holden Web LLC http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perceived inconsistency in py3k documentation

2010-12-08 Thread Steven D'Aprano
On Wed, 08 Dec 2010 00:47:37 +0100, Steve Holden wrote:

> On 12/6/2010 8:00 PM, Antoine Pitrou wrote:
>> On Sun, 05 Dec 2010 14:47:38 -0500
>> Terry Reedy  wrote:
>>> On 12/5/2010 3:31 AM, Greg wrote:
>>>
>>> For future reference,
>>>
 1) At http://docs.python.org/py3k/reference/datamodel.html: 2) At
 http://docs.python.org/py3k/library/stdtypes.html:
>>>
>>> do not work because of the trailing :s, at least not with FireFox.
>> 
>> Work fine here. The problem isn't Firefox, it is your e-mail or news
>> client.
>> 
>> Antoine.
>> 
>> 
> In my case also the links don't work, because my newsreader
> (Thunderbird) makes the assumption that the colons are part of the URLs.
> This behavior is common enough that people need to be aware of it.

It seems to me that colons are legal inside URIs and don't need to be 
escaped. If that is the case, then Thunderbird is correct to treat the 
colon as part of the URL, and whatever client Antoine is using is wrong 
to exclude it.

See this thread here for a discussion which concluded that colons are 
legal and don't need to be escaped:

http://markmail.org/message/juowogoeiff44qc4


Personally, I never let any character except whitespace or < > delimiters 
touch a URL. I never know how applications will interpret it.



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


Re: Comparisons of incompatible types

2010-12-08 Thread Steven D'Aprano
On Wed, 08 Dec 2010 11:58:03 +1100, Ben Finney wrote:

> Carl Banks  writes:
> 
>> On Dec 6, 4:17 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info> wrote:
>> > Nevertheless, I agree that in hindsight, the ability to sort such
>> > lists is not as important as the consistency of comparisons.
>>
>> I think that feeling the need to sort non-homogenous lists is
>> indictative of bad design.
> 
> It can also be indicative of code written for a Python that doesn't have
> sets.

Or a list that contains unhashable objects.

Or a list that needs to be presented to a human reader in some arbitrary 
but consistent order.

Or a doctest that needs to show the keys in a dict:

>>> d = myfunction()
>>> sorted(d.keys())
['ham', 'spam', 42, None]

(although that case is probably the weakest of the three). 



> So there's no design error in wanting heterogenerous sequences to sort;
> it can be quite Pythonic (until the advent of the ‘set’ type).

Agreed, but in hindsight I think it would be better if there was a 
separate lexicographic sort function, that guaranteed to sort anything 
(including such unorderable values as complex numbers!), without relying 
on the vagaries of the standard comparison operators. 

Or at least anything printable, in which case sorted() with a key 
function of lambda obj: (repr(type(obj)), repr(obj)) might work, I 
suppose...

Then at least we could limit our arguments to how this hypothetical 
lexicographic sort function was broken, instead of how all comparison 
operators are broken :)



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


Re: Python creates "locked" temp dir

2010-12-08 Thread Alex Willmer
On Dec 7, 9:03 pm, utabintarbo  wrote:
> I am using tempfile.mkdtemp() to create a working directory on a
> remote *nix system through a Samba share. When I use this on a Windows
> box, it works, and I have full access to the created dir. When used on
> a Linux box (through the same Samba share), the created directory
> shows as "locked", and I am unable to access. Obviously, I need
> access. Any clues?

You haven't provided enough details to go on.
1. Please post the actual code, and the trace back (if any).
2. When you say "I am unable to access". Do you mean another script/
process is unable to access? If so, that is the point of mkdtemp() -
to make a temporary directory that _only_ the creating process can
access. If you want to share it then tempfile is not the right module
for you.

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


class browser

2010-12-08 Thread Rustom Mody
If I have a medium to large python code base to browse/study, what are the
class browsers available?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling FORTAN dll functions from Python

2010-12-08 Thread Daniel da Silva
I don't know much about fortran+python, but I work with someone who does,
and he absolutely loves this tool:
http://cens.ioc.ee/projects/f2py2e/

Daniel

On Tue, Dec 7, 2010 at 10:19 PM, Dennis Lee Bieber wrote:

> On Tue, 07 Dec 2010 12:52:54 +0100, Stefan Behnel 
> declaimed the following in gmane.comp.python.general:
>
> > Alex van der Spek, 07.12.2010 12:11:
> > > Does anyone know how to call functions from FORTRAN dlls in Python? Is
> > > it even possible?
> >
> > Sure, have a look at fwrap and Cython.
> >
> > Stefan
>
> Possibly ctypes too...
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list