Re: signed vs unsigned int

2010-06-02 Thread Stefan Behnel

johnty, 02.06.2010 08:43:

i'm reading bytes from a serial port, and storing it into an array.

each byte represents a signed 8-bit int.

currently, the code i'm looking at converts them to an unsigned int by
doing ord(array[i]). however, what i'd like is to get the _signed_
integer value. whats the easiest way to do this?


See the struct module, it supports various different C types.

Stefan

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


Re: expat parsing error

2010-06-02 Thread kak...@gmail.com
On 2 Ιούν, 03:47, John Machin  wrote:
> On Jun 2, 1:57 am, "kak...@gmail.com"  wrote:
>
>
>
>
>
> > On Jun 1, 11:12 am, "kak...@gmail.com"  wrote:
>
> > > On Jun 1, 11:09 am, John Bokma  wrote:
>
> > > > "kak...@gmail.com"  writes:
> > > > > On Jun 1, 10:34 am, Stefan Behnel  wrote:
> > > > >> kak...@gmail.com, 01.06.2010 16:00:
>
> > > > >> > how can i fix it, how to "ignore" the headers and parse only
> > > > >> > the XML?
>
> > > > >> Consider reading the answers you got in the last thread that you 
> > > > >> opened
> > > > >> with exactly this question.
>
> > > > >> Stefan
>
> > > > > That's exactly, what i did but something seems to not working with the
> > > > > solutions i had, when i changed my implementation from pure Python's
> > > > > sockets to twisted library!
> > > > > That's the reason i have created a new post!
> > > > > Any ideas why this happened?
>
> > > > As I already explained: if you send your headers as well to any XML
> > > > parser it will choke on those, because the headers are /not/ valid /
> > > > well-formed XML. The solution is to remove the headers from your
> > > > data. As I explained before: headers are followed by one empty
> > > > line. Just remove lines up and until including the empty line, and pass
> > > > the data to any XML parser.
>
> > > > --
> > > > John Bokma                                                              
> > > >  j3b
>
> > > > Hacking & Hiking in Mexico -  
> > > > http://johnbokma.com/http://castleamber.com/-Perl&Python Development
>
> > > Thank you so much i'll try it!
> > > Antonis
>
> > Dear John can you provide me a simple working solution?
> > I don't seem to get it
>
> You're not wrong. Trysomething like this:
>
> rubbish1, rubbish2, xml = your_guff.partition('\n\n')

Ok thanks a lot!
Antonis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: signed vs unsigned int

2010-06-02 Thread Steven D'Aprano
On Tue, 01 Jun 2010 23:43:33 -0700, johnty wrote:

> i'm reading bytes from a serial port, and storing it into an array.

An array or a list?


> each byte represents a signed 8-bit int.
> 
> currently, the code i'm looking at converts them to an unsigned int by
> doing ord(array[i]). however, what i'd like is to get the _signed_
> integer value. whats the easiest way to do this?

>>> import array
>>> s = 'Some unsigned bytes \xc3\x80\xc3\xa0\xc3\xa6\xc3\x9f\xc2\xb5'
>>> array.array('b', s)
array('b', [83, 111, 109, 101, 32, 117, 110, 115, 105, 103, 110, 101, 
100, 32, 98, 121, 116, 101, 115, 32, -61, -128, -61, -96, -61, -90, -61, 
-97, -62, -75])


See also the fromstring method of array objects.


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


Re: signed vs unsigned int

2010-06-02 Thread Christian Heimes
> i'm reading bytes from a serial port, and storing it into an array.
> 
> each byte represents a signed 8-bit int.
> 
> currently, the code i'm looking at converts them to an unsigned int by
> doing ord(array[i]). however, what i'd like is to get the _signed_
> integer value. whats the easiest way to do this?

http://docs.python.org/library/struct.html

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


Re: signed vs unsigned int

2010-06-02 Thread johnty
On Jun 2, 12:04 am, Christian Heimes  wrote:
> > i'm reading bytes from a serial port, and storing it into an array.
>
> > each byte represents a signed 8-bit int.
>
> > currently, the code i'm looking at converts them to an unsigned int by
> > doing ord(array[i]). however, what i'd like is to get the _signed_
> > integer value. whats the easiest way to do this?
>
> http://docs.python.org/library/struct.html

the struct docs is exactly what i needed to read. "unpacking" it as a
signed char did the trick. thanks guys!
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Forum

2010-06-02 Thread pyDev
Hello,

I would like to let the community know that there is a new web-based
forum for Python enthusiasts over at PythonForum.org (http://
pythonforum.org). Web-based forums is a preferred method by Python
newcomers to get help in exploring the world of Python and programming
overall. The main goal of PythonForum.org is to popularize Python by
welcoming all newcomers. Recently the forum got "attacked" with
questions by users just starting out with Python. I hope here will be
someone ready to welcome and help newcomers to enter the beautiful
world of Python.


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


Mixing Decimal and float

2010-06-02 Thread B.V.
Hi,

In order to solve some issues due to operations between Decimal and
float, we wanted to implement a class that inherits from both float
and Decimal.

Typically, we wrote:
class Float(Decimal, float):
...

This can not be achieved because of a TypeError exception (with
message "multiple bases have instance lay-out conflict").

With a class that inherits from Decimal, with overridden __add__,
__mul__,  , we succeed to solve operations issues.

But we also need to do:
isinstance(Float('1'), float) == True
isinstance(Float('1'), Decimal) == True
which is, AFAIK, only possible with Float(Decimal, float).

Is there a workaround ?

We are developping with python version 2.5 and 2.6.

Thanks for your help.

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


Re: Python Forum

2010-06-02 Thread Simon Brunning
On 2 June 2010 09:04:56 UTC+1, pyDev  wrote:
> I hope here will be
> someone ready to welcome and help newcomers to enter the beautiful
> world of Python.

Just send them here, or to
. We'll be happy to
help.

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


Re: plac, the easiest command line arguments parser in the world

2010-06-02 Thread Tim Golden

On 02/06/2010 05:37, Michele Simionato wrote:

I would like to announce to the world the first public release of
plac:

   http://pypi.python.org/pypi/plac

Plac is a wrapper over argparse and works in all versions of
Python starting from Python 2.3 up to Python 3.1.


I like it. I'm a constant user of the

  def main (a, b=1, c=2):
# ...

  if __name__ == '__main__':
main (*sys.argv[1:])

pattern, which provides a minimally semi-self-documenting
approach for positional args, but I've always found the existing
offerings just a little too much work to bother with.
I'll give plac a run and see how it behaves.

Thanks

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


Re: Python Forum

2010-06-02 Thread Stefan Behnel

pyDev, 02.06.2010 10:04:

I would like to let the community know that there is a new web-based
forum for Python enthusiasts over at PythonForum.org (http://
pythonforum.org). Web-based forums is a preferred method by Python
newcomers to get help in exploring the world of Python and programming
overall.


It's not how the English speaking community works, though. There are two 
main mailing lists (mirrored as/from newsgroups) around which the larger 
community gathers: python-list (c.l.py) and python-tutor. I doubt (or 
rather put my hope against it) that a forum will attract a critical mass of 
Python cracks to make it attractive to newbees, and I would certainly 
prefer an effort to get them into joining python-tutor instead. There is 
not much to gain from splitting the community.


Stefan

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


Re: plac, the easiest command line arguments parser in the world

2010-06-02 Thread Paul Rubin
Tim Golden  writes:
> pattern, which provides a minimally semi-self-documenting
> approach for positional args, but I've always found the existing
> offerings just a little too much work to bother with.
> I'll give plac a run and see how it behaves.

After using optparse a couple of times I got the hang of it.  Maybe its
docs could be organized a bit better, but it does the obvious things
conveniently once you've figured it out a bit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-02 Thread Bruno Desthuilliers

pyDev a écrit :

Hello,

I would like to let the community know that there is a new web-based
forum for Python enthusiasts over at PythonForum.org (http://
pythonforum.org). 


YetAnotherUselessWebForum :(


Web-based forums is a preferred method by Python
newcomers to get help


Oh yeah ? Chapter and verse, please ?

Do the world a favour : replace your whole forum with a static page 
explaining how to join the "official" MLs and/or c.l.py.




in exploring the world of Python and programming
overall. The main goal of PythonForum.org is to popularize Python by
welcoming all newcomers.


Newcomers have always been welcomed here. And yet another forum *where 
the helpful experts won't post nor correct wrong posts* is certainly not 
the best way to "popularize" Python.



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


Re: Vote to Add Python Package "pubsub" to the Python Standard Library

2010-06-02 Thread Ben Finney
Daniel Fetchinson  writes:

> A good example for the first couple of stages of this process is PEP
> 3143 concerning adding a daemon package to the stdlib:
> http://www.python.org/dev/peps/pep-3143/

Thanks for the shout-out for PEP 3143. I can certainly say that the
process Daniel describes was a very healthy one for the development of
the API in that specification. Trimming the fat from the implementation,
and delegating concerns outside the specification, was a major benefit
of going through that public discussion process.

The PEP 3143 reference implementation has a lot of happy users, who are
making use of the API to perform the tasks they need. Once I complete
the extraction of dependencies, I'll be submitting the resulting code
for inclusion in the standard library.

> I haven't found the beginning of the thread discussing this

For the process you outline, the thread where I began soliciting
feedback of the “what's the best way to do this?” kind begins at
http://mail.python.org/pipermail/python-list/2008-September/560437.html>.
Some later threads gave me a better idea what was required and what was
possible.

While making a reference implementation, I drafted a PEP to describe the
interface I wanted the standard library to provide. Once I had it in
good shape, and had a reference implementation ready, I submitted it and
it was registered as PEP 3143.

The first PEP 3143 discussion thread starts at
http://mail.python.org/pipermail/python-ideas/2009-January/002529.html>.
Once I had incorporated a lot of the feedback, I fished again with
http://mail.python.org/pipermail/python-list/2009-March/1197730.html>.

It's annoying that many threads get broken because of poor transmission
of message references. You'll need to browse manually to get more
complete versions of some of the thread.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plac, the easiest command line arguments parser in the world

2010-06-02 Thread Michele Simionato
On Jun 2, 10:43 am, Paul Rubin  wrote:
> Tim Golden  writes:
> > pattern, which provides a minimally semi-self-documenting
> > approach for positional args, but I've always found the existing
> > offerings just a little too much work to bother with.
> > I'll give plac a run and see how it behaves.
>
> After using optparse a couple of times I got the hang of it.  Maybe its
> docs could be organized a bit better, but it does the obvious things
> conveniently once you've figured it out a bit.

Notice that optparse is basically useless in the use case Tim is
considering (positional arguments) since it only manages options.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plac, the easiest command line arguments parser in the world

2010-06-02 Thread Jean-Michel Pichavant

Michele Simionato wrote:

I would like to announce to the world the first public release of
plac:

  http://pypi.python.org/pypi/plac

Plac is a wrapper over argparse and works in all versions of
Python starting from Python 2.3 up to Python 3.1.

With blatant immodesty, plac claims to be the easiest to use command
line arguments parser module in the Python world. Its goal is to
reduce the
learning curve of argparse from hours to minutes. It does so by
removing the need to build a command line arguments parser by hand:
actually it is smart enough to infer the parser from function
annotations.

Here is a simple example (in Python 3) to wet your appetite:

$ cat example.py
def main(arg: "required argument"):
"do something with arg"
print('Got %s' % arg)

if __name__ == '__main__':
import plac; plac.call(main) # passes sys.argv[1:] to main

$ python example.py -h
usage: example.py [-h] arg

do something with arg

positional arguments:
  arg required argument

optional arguments:
  -h, --help  show this help message and exit


$ python example.py
usage: example.py [-h] arg
example.py: error: too few arguments

$  python example.py arg
Got arg

$  python example.py arg1 arg2
usage: example.py [-h] arg
example.py: error: unrecognized arguments: arg2

You can find in the documentation a lot of other simple and not so
simple
examples:

  http://micheles.googlecode.com/hg/plac/doc/plac.html


Enjoy!

 Michele Simionato

P.S. answering an unspoken question: yes, we really needed yet
another
command line arguments parser! ;)
  

Thanks for participating.

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


Re: Drawing Multigraphs

2010-06-02 Thread Richard Brodie

"geremy condra"  wrote in message 
news:mailman.825.1275414239.32709.python-l...@python.org...

> On Tue, Jun 1, 2010 at 9:42 AM, Nima  wrote:
>> Hi there,
>> Is it possible to draw an (undirected) multigraph using a python library?
>> I need to write a program that finds an Eulerian circuit in a graph
>> (which might obviously be a multigraph). As the output of the program,
>> I should draw the graph and print out the solution.
>
> We use Dot in Graphine, and it works well. It's also very easy to
> output to.

NetworkX apparently has dot bindings built-in, although I've not
used it, so I think one should just be able to export to it. 


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


Re: plac, the easiest command line arguments parser in the world

2010-06-02 Thread Stefan Behnel

Paul Rubin, 02.06.2010 10:43:

Tim Golden writes:

pattern, which provides a minimally semi-self-documenting
approach for positional args, but I've always found the existing
offerings just a little too much work to bother with.
I'll give plac a run and see how it behaves.


After using optparse a couple of times I got the hang of it.  Maybe its
docs could be organized a bit better, but it does the obvious things
conveniently once you've figured it out a bit.


Same from here. I managed to talk a Java-drilled collegue of mine into 
writing a Python script for a little command line utility, but he needed a 
way to organise his argument extraction code when the number of arguments 
started to grow beyond two. I told him that there were two ways to do it: 
do it by hand or do it right. He took the right choice and I took him to 
the optparse docs, copied the first example into his code and we adapted it 
a little. He just loved the beauty of it.


Stefan

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


Re: plac, the easiest command line arguments parser in the world

2010-06-02 Thread Michele Simionato
On Jun 2, 11:01 am, Stefan Behnel  wrote:
> I managed to talk a Java-drilled collegue of mine into
> writing a Python script for a little command line utility, but he needed a
> way to organise his argument extraction code when the number of arguments
> started to grow beyond two. I told him that there were two ways to do it:
> do it by hand or do it right. He took the right choice and I took him to
> the optparse docs, copied the first example into his code and we adapted it
> a little. He just loved the beauty of it.

Could you show plac to your friend? I would be curious to know what he
think.
Perhaps he would call out his judgment on optparse ;)

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


Re: Vote to Add Python Package "pubsub" to the Python Standard Library

2010-06-02 Thread Gabriele Lanaro
I definitvely vote for adding such a package to the stdlib (or at least a
symilar publish/subscrive and observer implementation). It's useful in a
wide range of programs.


2010/6/2 Carl Banks 

> On May 26, 4:26 am, Tom  wrote:
> > I vote for adding the Python package "pubsub" to the Python standard
> > library.  It has recently been added to wxpython (replacing the old
> > wx.lib.pubsub package), but it has application to non-gui programs as
> > well.
>
>
> Well, I can definitely see a case for adding something like this to
> the standard library.  If there is a standard publish-subscribe
> implementation, then different third-party packages can use it in a
> consistent way together.  It can open whole paradigms of package
> integration.
>
> However, I'm not sure this particular library is the one to use, and I
> would not be in favor of throwing the first publish-subscribe
> implentation that comes by into the standard library, at least not
> without a whole lot of vetting first.  (They did that with optparse
> and the Python community has been paying for it ever since.)
>
> I think it has a pretty good chance of being accepted, too.  The
> publish-subscribe pattern, if you will, seems to have been implemented
> separately in many places.  The logging module in the standard library
> uses something like this.  Qt's signal/slot mechanism is another
> variation.  I'm sure there's lots more.  I've noticed that pointing
> out lots of independetnly crafted examples in the wild, and especially
> in the standard library, works quite well.
>
>
> Carl Banks
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Forum

2010-06-02 Thread Adam Tauno Williams
On Wed, 2010-06-02 at 10:44 +0200, Bruno Desthuilliers wrote:
> pyDev a écrit :
> > Hello,
> > I would like to let the community know that there is a new web-based
> > forum for Python enthusiasts over at PythonForum.org (http://
> > pythonforum.org). 
> YetAnotherUselessWebForum :(

+1

Yuck; no better way to make new users hate your product than have a web
forum - where they post questions and never get answers... because
the people with the answers are over on the much-easier-to-use mailist
[what an awesome feature:  the questions just show up in my INBOX!
Sweet.].

> > Web-based forums is a preferred method by Python
> > newcomers to get help
> Oh yeah ? Chapter and verse, please 
> Do the world a favour : replace your whole forum with a static page 
> explaining how to join the "official" MLs and/or c.l.py.
> > in exploring the world of Python and programming
> > overall. The main goal of PythonForum.org is to popularize Python by
> > welcoming all newcomers.
> Newcomers have always been welcomed here. And yet another forum *where 
> the helpful experts won't post nor correct wrong posts* is certainly not 
> the best way to "popularize" Python.

+1
-- 
Adam Tauno Williams  LPIC-1, Novell CLA

OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: Mixing Decimal and float

2010-06-02 Thread Mark Dickinson
On Jun 2, 9:24 am, "B.V."  wrote:
> Hi,
>
> In order to solve some issues due to operations between Decimal and
> float, we wanted to implement a class that inherits from both float
> and Decimal.
>
> Typically, we wrote:
>
> class Float(Decimal, float):

Can you explain exactly what issues you want to solve, and how you
want your Float class to behave?  Do I understand correctly that you
want your Float class to be able to represent both floats and
Decimals?

> But we also need to do:
> isinstance(Float('1'), float) == True
> isinstance(Float('1'), Decimal) == True

Can you explain why you need this?

Should isinstance(Float('1.1'), float) and isinstance(Float('1.1'),
Decimal) also both be true, or would only one of those be true?  (And
by the way, what value would Float('1.1') have?  float('1.1') and
Decimal('1.1') are different values.)

I don't think your approach can succeed;  I'd suggest just subclassing
'object' and abandoning the 'isinstance' requirements.  Or perhaps
creating a subclass of Decimal that interacts nicely with floats.  You
might also want to investigate the numbers ABC, though that's new in
Python 2.6.

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


optional optional args vs optional positional options

2010-06-02 Thread Antoine Pitrou
On Wed, 2 Jun 2010 01:49:18 -0700 (PDT)
Michele Simionato  wrote:
> 
> Notice that optparse is basically useless in the use case Tim is
> considering (positional arguments) since it only manages options.

By the way, could you stop naming these "optional arguments", since
positional arguments can be optional as well? It is confusing :)

Thanks

Antoine.


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


Re: optional optional args vs optional positional options

2010-06-02 Thread Tim Golden

On 02/06/2010 11:42, Antoine Pitrou wrote:

On Wed, 2 Jun 2010 01:49:18 -0700 (PDT)
Michele Simionato  wrote:


Notice that optparse is basically useless in the use case Tim is
considering (positional arguments) since it only manages options.


By the way, could you stop naming these "optional arguments", since
positional arguments can be optional as well? It is confusing :)


The great thing with English is that you can use nouns as
adjectives without changing them, so you can say "option arguments"
and "position arguments" quite happily here :)

But then you run into the fact that you're having semantic arguments
about argument semantics :(

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


Re: signed vs unsigned int

2010-06-02 Thread John Machin
On Jun 2, 4:43 pm, johnty  wrote:
> i'm reading bytes from a serial port, and storing it into an array.
>
> each byte represents a signed 8-bit int.
>
> currently, the code i'm looking at converts them to an unsigned int by
> doing ord(array[i]). however, what i'd like is to get the _signed_
> integer value. whats the easiest way to do this?

signed = unsigned if unsigned <= 127 else unsigned - 256
-- 
http://mail.python.org/mailman/listinfo/python-list


Opinion On Best Way...

2010-06-02 Thread Victor Subervi
Hi;
I have a script in which I currently pass a number of variables to another
script through the url in a meta http-equiv tag. This seems both awkward and
hackable. I think it would be best to create a temporary mysql table, insert
them there, and pull them from the following script. The situation is where
a purchaser places an item in my shopping cart. A script is called that
simply pushes the data to the cart script. The reason for this step is to
ensure that when the cart script calls itself (in the form tag) through an
update to either update or delete items, the last cached items aren't
re-added to the shopping cart. What are your thoughts on the best way to
preserve the data from script to script?
TIA.
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixing Decimal and float

2010-06-02 Thread B.V.
On Jun 2, 12:22 pm, Mark Dickinson  wrote:
> On Jun 2, 9:24 am, "B.V."  wrote:
>
> > Hi,
>
> > In order to solve some issues due to operations between Decimal and
> > float, we wanted to implement a class that inherits from both float
> > and Decimal.
>
> > Typically, we wrote:
>
> > class Float(Decimal, float):
>
> Can you explain exactly what issues you want to solve, and how you
> want your Float class to behave?  Do I understand correctly that you
> want your Float class to be able to represent both floats and
> Decimals?

Let me give you the whole story. We work on Tryton, an client/server
application framework written in Python (http://www.tryton.org).
The framework defines several types of fields within its own ORM
(http://doc.tryton.org/1.6/trytond/doc/ref/models/fields.html#ref-
models-fields); among those types, there's a fields.Float type -- not
to be confused with the class Float we are talking about -- (with
underlying python type float) and fields.Numeric (with underlying
python type Decimal).
fields.Numeric(Decimal) where implemented at the beginning of the fork
(Tryton is a fork of OpenERP, formerly known as TinyERP), because the
use of floats in OpenERP leads many problems in module handling
financial data.

The client is written in pygtk. The client connects the server through
a specific (but simple) protocol called pysocket (roughly pickled data
over sockets).
In an application, you may define objects with both Numeric or Float
attributes, and when you need to make them interact, you have to cast.
And everything is fine.

But trying to be open to other languages, the server implements also
an XMLRPC interface (and also a JSONRPC-like interface). That's the
key point: Decimal is python specific. So in an application, you can't
rely on the value received from a client, because depending on the
protocol, the type of the value is different.
So the idea was to create a class that can behave like a Decimal or a
float depending on the context, and set
xmlrpclib.Unmarshaller.dispatch["double"] to a function that return a
Float instance.

A contributor filed an issue on the bug tracker (https://
bugs.tryton.org/roundup/issue1575) and because he's a nice guy (ok
it's a friend of mine), he made a patch proposal (http://
codereview.appspot.com/1387041). The end of the story is in the
comments of the proposal.

>
> > But we also need to do:
> > isinstance(Float('1'), float) == True
> > isinstance(Float('1'), Decimal) == True
>
> Can you explain why you need this?

It's a requirement of the project leader.

>
> Should isinstance(Float('1.1'), float) and isinstance(Float('1.1'),
> Decimal) also both be true, or would only one of those be true?  (And
> by the way, what value would Float('1.1') have?  float('1.1') and
> Decimal('1.1') are different values.)

I think they both should be True, for '1', '1.1', '0', '0.1', ...
For the value, I would say that it depends of the definition of the
field (fields.Float or fields.Numeric).


>
> I don't think your approach can succeed;  I'd suggest just subclassing
> 'object' and abandoning the 'isinstance' requirements.  Or perhaps
> creating a subclass of Decimal that interacts nicely with floats.  You
> might also want to investigate the numbers ABC, though that's new in
> Python 2.6.

First, Float implementation was a subclass of Decimal that works with
floats, and solves many (maybe all) problems. But as you may read in
the comments of the patch proposal, it seems to be not enough.

B.

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


functools.wraps and help()

2010-06-02 Thread Ulrich Eckhardt
Hi!

When I use help() on a function, it displays the arguments of the function,
along with the docstring. However, when wrapping the function using
functools.wraps it only displays the arguments that the (internal) wrapper
function takes, which is typically "*args, **kwargs", which isn't very
useful.

Any suggestions how to fix that? Is that even a bug or a systematic
limitation? In case of the latter, should the documentation for
functools.wraps mention it?

Cheers!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: functools.wraps and help()

2010-06-02 Thread Michele Simionato
On Jun 2, 2:20 pm, Ulrich Eckhardt  wrote:
> Hi!
>
> When I use help() on a function, it displays the arguments of the function,
> along with the docstring. However, when wrapping the function using
> functools.wraps it only displays the arguments that the (internal) wrapper
> function takes, which is typically "*args, **kwargs", which isn't very
> useful.
>
> Any suggestions how to fix that? Is that even a bug or a systematic
> limitation? In case of the latter, should the documentation for
> functools.wraps mention it?

See http://pypi.python.org/pypi/decorator
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optional optional args vs optional positional options

2010-06-02 Thread J. Cliff Dyer
+1  

Options are options, arguments are arguments.  An optional argument is
not an option.  It is an argument that can be left out.



On Wed, 2010-06-02 at 12:42 +0200, Antoine Pitrou wrote:
> On Wed, 2 Jun 2010 01:49:18 -0700 (PDT)
> Michele Simionato  wrote:
> > 
> > Notice that optparse is basically useless in the use case Tim is
> > considering (positional arguments) since it only manages options.
> 
> By the way, could you stop naming these "optional arguments", since
> positional arguments can be optional as well? It is confusing :)
> 
> Thanks
> 
> Antoine.
> 
> 


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


Re: plac, the easiest command line arguments parser in the world

2010-06-02 Thread Michele Simionato
On Jun 2, 6:37 am, Michele Simionato 
wrote:
> With blatant immodesty, plac claims to be the easiest to use command
> line arguments parser module in the Python world

It seems I have to take that claim back. A few hours after the
announce I was pointed out to http://pypi.python.org/pypi/CLIArgs
which, I must concede, is even easier to use than plac. It seems
everybody has written its own command line arguments parser!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixing Decimal and float

2010-06-02 Thread Terry Reedy

On 6/2/2010 8:17 AM, B.V. wrote:


A contributor filed an issue on the bug tracker (https://
bugs.tryton.org/roundup/issue1575) and because he's a nice guy (ok
it's a friend of mine), he made a patch proposal (http://
codereview.appspot.com/1387041). The end of the story is in the
comments of the proposal.


I have no idea how to do what you want. But for future reference, links 
put in running email/newsgroup text as above are not very usable for 
most readers. They are best put on a line *by themselves*. Then they can 
be clicked on in at least some mail/newsgroup readers, or at worst, 
copied and pasted to a browser. Reformatted to be more usable:


A contributor filed an issue on the bug tracker
https://bugs.tryton.org/roundup/issue1575
and because he's a nice guy (ok
it's a friend of mine), he made a patch proposal
http://codereview.appspot.com/1387041
The end of the story is in the comments of the proposal.

Terry Jan Reedy

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


Re: python and filter design: calculating "s" optimal transform

2010-06-02 Thread cassiope
On Jun 1, 2:58 pm, Terry Reedy  wrote:
> On 6/1/2010 2:18 PM, robert somerville wrote:
>
> > Hi;
> > this is an airy question.
>
> > does anybody have some code or ideas on how to calculate the optimal "S"
> > transform of user specified order (wanting the coefficients)  for a
> > published filter response curve, ie.
>
> > f(s) = 1.0/(a1*S^2 + a2*S + a3)
>
> If you do not get an answer here, try the scipy list.

Say what

There are tables of coefficients for Butterworth, Bessel, and other
standard filter forms.
Could you be a little clearer on what you're trying to do?
-- 
http://mail.python.org/mailman/listinfo/python-list


Properly posting links (was Re: Python Forum)

2010-06-02 Thread Terry Reedy

On 6/2/2010 4:04 AM, pyDev wrote:


forum for Python enthusiasts over at PythonForum.org (http://
pythonforum.org). Web-based forums is a preferred method by Python


This is the second time today I have read a post with a useless link 
wrapped over two lines. Email lists and newsgroups (this is both) are 
text, not html based. Put a link on one line by itself, with no 
punctuation. The above, if posted at all, should have been


forum for Python enthusiasts over at PythonForum.org.
http://pythonforum.org
Web-based forums is a preferred method by Python

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


Re: Mixing Decimal and float

2010-06-02 Thread B.V.
On 2 juin, 17:08, Terry Reedy  wrote:
> On 6/2/2010 8:17 AM, B.V. wrote:
>
> > A contributor filed an issue on the bug tracker (https://
> > bugs.tryton.org/roundup/issue1575) and because he's a nice guy (ok
> > it's a friend of mine), he made a patch proposal (http://
> > codereview.appspot.com/1387041). The end of the story is in the
> > comments of the proposal.
>
> I have no idea how to do what you want. But for future reference, links
> put in running email/newsgroup text as above are not very usable for
> most readers. They are best put on a line *by themselves*. Then they can
> be clicked on in at least some mail/newsgroup readers, or at worst,
> copied and pasted to a browser. Reformatted to be more usable:
>
> A contributor filed an issue on the bug 
> trackerhttps://bugs.tryton.org/roundup/issue1575
> and because he's a nice guy (ok
> it's a friend of mine), he made a patch 
> proposalhttp://codereview.appspot.com/1387041
> The end of the story is in the comments of the proposal.
>
> Terry Jan Reedy

Thank you for your remarks, my next posts will in accordance.

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


decorating a memberfunction

2010-06-02 Thread Ulrich Eckhardt
Hi!

I have a class that maintains a network connection, which can be used to
query and trigger Things(tm). Apart from "normal" errors, a broken network
connection and a protocol violation from the peer are something we can't
recover from without creating a new connection, so those errors
should "stick".

The code looks roughly like this:

class Client(object):
def __init__(self, ...):
self._error = None

def _check(fn):
def do_check(self, *args, **kwargs):
# check for sticky error
if self._error:
raise self._error

try:
fn(self, *args, **kwargs)
except NetworkError, e:
self._error = e
raise
except ProtocolError, e:
self._error = e
raise
return do_check

@_check
def frobnicate(self, foo):
# format and send request, read and parse answer

So, any function like frobnicate() that does things is decorated with
_check() so that unrecoverable errors stick. I hope I didn't shorten the
code too much to understand the principle, in particular I'm using
functools.wraps() in order to retain function names and docstrings.


Is this sound? Would you have done it differently? Any other suggestions?
What I'm mostly unsure about is whether the definition of _check() and
do_check() are correct or could be improved.


Thanks!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: decorating a memberfunction

2010-06-02 Thread MRAB

Ulrich Eckhardt wrote:

Hi!

I have a class that maintains a network connection, which can be used to
query and trigger Things(tm). Apart from "normal" errors, a broken network
connection and a protocol violation from the peer are something we can't
recover from without creating a new connection, so those errors
should "stick".

The code looks roughly like this:

class Client(object):
def __init__(self, ...):
self._error = None

def _check(fn):
def do_check(self, *args, **kwargs):
# check for sticky error
if self._error:
raise self._error

try:
fn(self, *args, **kwargs)
except NetworkError, e:
self._error = e
raise
except ProtocolError, e:
self._error = e
raise
return do_check

@_check
def frobnicate(self, foo):
# format and send request, read and parse answer

So, any function like frobnicate() that does things is decorated with
_check() so that unrecoverable errors stick. I hope I didn't shorten the
code too much to understand the principle, in particular I'm using
functools.wraps() in order to retain function names and docstrings.


Is this sound? Would you have done it differently? Any other suggestions?
What I'm mostly unsure about is whether the definition of _check() and
do_check() are correct or could be improved.


You could merge the two excepts:

try:
fn(self, *args, **kwargs)
except (NetworkError, ProtocolError), e:
self._error = e
raise

You could also choose a better name for the decorator, eg
_check_sticky_error. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Simple hack to get $500 to your home.

2010-06-02 Thread money mania
Simple hack to get $500 to your home at http://dailyupdatesonly.tk

Due to high security risks,i have hidden the cheque link in an
image.  in that website on left side below search box, click on image
and enter your name and address where you want to receive your
cheque.please dont tell to anyone.
-- 
http://mail.python.org/mailman/listinfo/python-list


Syntax question

2010-06-02 Thread pmz
Dear Group,

It's really rookie question, but I'm currently helping my wife in some
python-cases, where I'm non-python developer and some of syntax-diffs
make me a bit confused.

Could anyone give some light on line, as following:
"ds = d[:]"  ### where 'd' is an array

Let me guess, is it a declaration of two-dimension array?

Thanks a lot for help and all the best,
Przemek M. Zawada
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax question

2010-06-02 Thread Chris Rebert
On Wed, Jun 2, 2010 at 10:40 AM, pmz  wrote:
> Dear Group,
>
> It's really rookie question, but I'm currently helping my wife in some
> python-cases, where I'm non-python developer and some of syntax-diffs
> make me a bit confused.
>
> Could anyone give some light on line, as following:
> "ds = d[:]"  ### where 'd' is an array
>
> Let me guess, is it a declaration of two-dimension array?

Nope; Python doesn't really have variable declarations.*
That line of code copies the list `d` ( `[]` is the slicing operator,
and the colon indicates the bounds are the entire list; this is a
Python idiom) and assigns the copy to the variable `ds`. Note that the
copying is shallow (i.e. not recursive, only 1 level deep).

*Well, almost: There are `global` and `nonlocal`, but they're only
needed to specify a variable's scope in certain circumstances when you
want to be able to assign to said variable.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax question

2010-06-02 Thread geremy condra
On Wed, Jun 2, 2010 at 10:40 AM, pmz  wrote:
> Dear Group,
>
> It's really rookie question, but I'm currently helping my wife in some
> python-cases, where I'm non-python developer and some of syntax-diffs
> make me a bit confused.
>
> Could anyone give some light on line, as following:
> "ds = d[:]"  ### where 'd' is an array

I'm guessing you mean that d is a list. The square
braces with the colon is python's slicing notation,
so if I say [1,2,3,4][0] I get a 1 back, and if I say
[1,2,3,4][1:4] I get [2,3,4]. Python also allows a
shorthand in slicing, which is that if the first index
is not provided, then it assumes 0, and that if the
second index is not provided, it assumes the end
of the list. Thus, [1,2,3,4][:2] would give me [1,2]
and [1,2,3,4][2:] would give me [3, 4]. Here, neither
has been provided, so the slice simply takes the
items in the list from beginning to end and returns
them- [1,2,3,4][:] gives [1,2,3,4].

The reason someone would want to do this is
because lists are mutable data structures. If you
fire up your terminal you can try the following
example:

>>> a = [1,2,3,4]
>>> b = a
>>> c = [:]
>>> b[0] = 5
>>> b
[5,2,3,4]
>>> # here's the issue
>>> a
[5,2,3,4]
>>> # and the resolution
>>> c
[1,2,3,4]

Hope this helps.

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


Re: Syntax question

2010-06-02 Thread pmz
On 2 Cze, 19:56, geremy condra  wrote:
> On Wed, Jun 2, 2010 at 10:40 AM, pmz  wrote:
> > Dear Group,
>
> > It's really rookie question, but I'm currently helping my wife in some
> > python-cases, where I'm non-python developer and some of syntax-diffs
> > make me a bit confused.
>
> > Could anyone give some light on line, as following:
> > "ds = d[:]"  ### where 'd' is an array
>
> I'm guessing you mean that d is a list. The square
> braces with the colon is python's slicing notation,
> so if I say [1,2,3,4][0] I get a 1 back, and if I say
> [1,2,3,4][1:4] I get [2,3,4]. Python also allows a
> shorthand in slicing, which is that if the first index
> is not provided, then it assumes 0, and that if the
> second index is not provided, it assumes the end
> of the list. Thus, [1,2,3,4][:2] would give me [1,2]
> and [1,2,3,4][2:] would give me [3, 4]. Here, neither
> has been provided, so the slice simply takes the
> items in the list from beginning to end and returns
> them- [1,2,3,4][:] gives [1,2,3,4].
>
> The reason someone would want to do this is
> because lists are mutable data structures. If you
> fire up your terminal you can try the following
> example:
>
> >>> a = [1,2,3,4]
> >>> b = a
> >>> c = [:]
> >>> b[0] = 5
> >>> b
> [5,2,3,4]
> >>> # here's the issue
> >>> a
> [5,2,3,4]
> >>> # and the resolution
> >>> c
>
> [1,2,3,4]
>
> Hope this helps.
>
> Geremy Condra

Thank you for such fast answer! I quite catch, but:
As I see, the d[:] is equal to sentence "get the d array from the
first to the last element"? :)

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


Re: Syntax question

2010-06-02 Thread Matteo Landi
Anyway I suggest you to use a syntax like:

>>>b = list(a)

in order to copy a list, it should be better than slicing.

On Wed, Jun 2, 2010 at 7:56 PM, geremy condra  wrote:
> On Wed, Jun 2, 2010 at 10:40 AM, pmz  wrote:
>> Dear Group,
>>
>> It's really rookie question, but I'm currently helping my wife in some
>> python-cases, where I'm non-python developer and some of syntax-diffs
>> make me a bit confused.
>>
>> Could anyone give some light on line, as following:
>> "ds = d[:]"  ### where 'd' is an array
>
> I'm guessing you mean that d is a list. The square
> braces with the colon is python's slicing notation,
> so if I say [1,2,3,4][0] I get a 1 back, and if I say
> [1,2,3,4][1:4] I get [2,3,4]. Python also allows a
> shorthand in slicing, which is that if the first index
> is not provided, then it assumes 0, and that if the
> second index is not provided, it assumes the end
> of the list. Thus, [1,2,3,4][:2] would give me [1,2]
> and [1,2,3,4][2:] would give me [3, 4]. Here, neither
> has been provided, so the slice simply takes the
> items in the list from beginning to end and returns
> them- [1,2,3,4][:] gives [1,2,3,4].
>
> The reason someone would want to do this is
> because lists are mutable data structures. If you
> fire up your terminal you can try the following
> example:
>
 a = [1,2,3,4]
 b = a
 c = [:]
 b[0] = 5
 b
> [5,2,3,4]
 # here's the issue
 a
> [5,2,3,4]
 # and the resolution
 c
> [1,2,3,4]
>
> Hope this helps.
>
> Geremy Condra
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Matteo Landi
http://www.matteolandi.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax question

2010-06-02 Thread Matteo Landi
Yes it is; d[i:j] is equal to "give me the array from the d[i] to d[j
- 1]", and if you omit i and j then the i and j are respectively
assumed as 0 and len(d) - 1.

On Wed, Jun 2, 2010 at 8:01 PM, pmz  wrote:
> On 2 Cze, 19:56, geremy condra  wrote:
>> On Wed, Jun 2, 2010 at 10:40 AM, pmz  wrote:
>> > Dear Group,
>>
>> > It's really rookie question, but I'm currently helping my wife in some
>> > python-cases, where I'm non-python developer and some of syntax-diffs
>> > make me a bit confused.
>>
>> > Could anyone give some light on line, as following:
>> > "ds = d[:]"  ### where 'd' is an array
>>
>> I'm guessing you mean that d is a list. The square
>> braces with the colon is python's slicing notation,
>> so if I say [1,2,3,4][0] I get a 1 back, and if I say
>> [1,2,3,4][1:4] I get [2,3,4]. Python also allows a
>> shorthand in slicing, which is that if the first index
>> is not provided, then it assumes 0, and that if the
>> second index is not provided, it assumes the end
>> of the list. Thus, [1,2,3,4][:2] would give me [1,2]
>> and [1,2,3,4][2:] would give me [3, 4]. Here, neither
>> has been provided, so the slice simply takes the
>> items in the list from beginning to end and returns
>> them- [1,2,3,4][:] gives [1,2,3,4].
>>
>> The reason someone would want to do this is
>> because lists are mutable data structures. If you
>> fire up your terminal you can try the following
>> example:
>>
>> >>> a = [1,2,3,4]
>> >>> b = a
>> >>> c = [:]
>> >>> b[0] = 5
>> >>> b
>> [5,2,3,4]
>> >>> # here's the issue
>> >>> a
>> [5,2,3,4]
>> >>> # and the resolution
>> >>> c
>>
>> [1,2,3,4]
>>
>> Hope this helps.
>>
>> Geremy Condra
>
> Thank you for such fast answer! I quite catch, but:
> As I see, the d[:] is equal to sentence "get the d array from the
> first to the last element"? :)
>
> P.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Matteo Landi
http://www.matteolandi.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax question

2010-06-02 Thread pmz
On 2 Cze, 20:07, Matteo Landi  wrote:
> Anyway I suggest you to use a syntax like:
>
> >>>b = list(a)
>
> in order to copy a list, it should be better than slicing.
>
>
>
>
>
> On Wed, Jun 2, 2010 at 7:56 PM, geremy condra  wrote:
> > On Wed, Jun 2, 2010 at 10:40 AM, pmz  wrote:
> >> Dear Group,
>
> >> It's really rookie question, but I'm currently helping my wife in some
> >> python-cases, where I'm non-python developer and some of syntax-diffs
> >> make me a bit confused.
>
> >> Could anyone give some light on line, as following:
> >> "ds = d[:]"  ### where 'd' is an array
>
> > I'm guessing you mean that d is a list. The square
> > braces with the colon is python's slicing notation,
> > so if I say [1,2,3,4][0] I get a 1 back, and if I say
> > [1,2,3,4][1:4] I get [2,3,4]. Python also allows a
> > shorthand in slicing, which is that if the first index
> > is not provided, then it assumes 0, and that if the
> > second index is not provided, it assumes the end
> > of the list. Thus, [1,2,3,4][:2] would give me [1,2]
> > and [1,2,3,4][2:] would give me [3, 4]. Here, neither
> > has been provided, so the slice simply takes the
> > items in the list from beginning to end and returns
> > them- [1,2,3,4][:] gives [1,2,3,4].
>
> > The reason someone would want to do this is
> > because lists are mutable data structures. If you
> > fire up your terminal you can try the following
> > example:
>
>  a = [1,2,3,4]
>  b = a
>  c = [:]
>  b[0] = 5
>  b
> > [5,2,3,4]
>  # here's the issue
>  a
> > [5,2,3,4]
>  # and the resolution
>  c
> > [1,2,3,4]
>
> > Hope this helps.
>
> > Geremy Condra
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> --
> Matteo Landihttp://www.matteolandi.net/

In fact, that ain't my syntax, I'd rather use C++ for that project,
because that's my world is not Python, but thank you anyway for help -
I see that Python also has many fans and friends online :) I'll try
help her using your explanations.

THANK you again and all the best,
Przemek M. Zawada

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


See and Enjoy Indian Girls Gallery.

2010-06-02 Thread preety preety
http://www.teluguscope.com/allfiles/galleryfiles/actressfiles/kajole/1.html

http://www.teluguscope.com/allfiles/galleryfiles/actressfiles/aishwaryarai/33.html

http://www.teluguscope.com/allfiles/galleryfiles/actressfiles/mallikasherawat/2.html

http://www.teluguscope.com/allfiles/galleryfiles/actressindexfiles/katrinakaifindex.html

http://www.teluguscope.com/allfiles/galleryfiles/actressindexfiles/ilianaindex.html

http://www.teluguscope.com/allfiles/galleryfiles/actressindexfiles/kajoleindex.html

http://www.teluguscope.com/allfiles/galleryfiles/actressindexfiles/deepikapadukoneindex.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing and accessing server's stdout

2010-06-02 Thread Bryan
Tim Arnold wrote:
> Hi, This is the setup I was asking about.
> I've got users using a python-written command line client. They're
> requesting services from a remote server that fires a LaTeX process. I
> want them to see the stdout from the LaTeX process.

So what you really need is to capture the output of a command, in this
case LaTeX, so you can copy it back to the client. You can do that
with the subprocess module in the Python standard library.

If the command generated so much output so fast that you felt the need
to avoid the extra copy, I suppose you could fork() then hook stdout
directly to socket connected to the client with dup2(), then exec()
the command. But no need for that just to capture LaTeX's output.


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


Re: MySQLDB - server has gone on blob insertion...

2010-06-02 Thread Rami Chowdhury
On Tuesday 01 June 2010 12:46:40 John Nagle wrote:
> durumdara wrote:
> >>> When I tried to start this, I got error:
> >>> _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone
> >>> away')
> 
> Are you by any chance trying to do this on a HostGator account?
> HostGator servers run a program which kills long MySQL transactions
> by executing MySQL "KILL" transactions.
> This is reported to the user as 'MySQL server has gone away'

I don't think HostGator is alone in this -- AFAIK several web hosts (including 
mine) do it too.



Rami Chowdhury
"As an online discussion grows longer, the probability of a comparison involving
Nazis or Hitler approaches one." -- Godwin's Law
408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixing Decimal and float

2010-06-02 Thread I V
On Wed, 02 Jun 2010 05:17:11 -0700, B.V. wrote:
> But trying to be open to other languages, the server implements also an
> XMLRPC interface (and also a JSONRPC-like interface). That's the key
> point: Decimal is python specific. So in an application, you can't rely
> on the value received from a client, because depending on the protocol,
> the type of the value is different. So the idea was to create a class
> that can behave like a Decimal or a float depending on the context, and
> set xmlrpclib.Unmarshaller.dispatch["double"] to a function that return
> a Float instance.

Looking at the Tryton docs, it seems that it already supports field types 
that can't be directly represented in XMLRPC or JSON, like BigInteger or 
Selection. How are these serialized over the non-python RPC mechanisms? 
Could you not do the same for Decimals?
 
> A contributor filed an issue on the bug tracker (https://
> bugs.tryton.org/roundup/issue1575) and because he's a nice guy (ok it's
> a friend of mine), he made a patch proposal (http://
> codereview.appspot.com/1387041). The end of the story is in the comments
> of the proposal.
> 
> 
>> > But we also need to do:
>> > isinstance(Float('1'), float) == True isinstance(Float('1'), Decimal)
>> > == True
>>
>> Can you explain why you need this?
> 
> It's a requirement of the project leader.
> 
> 
>> Should isinstance(Float('1.1'), float) and isinstance(Float('1.1'),
>> Decimal) also both be true, or would only one of those be true?  (And
>> by the way, what value would Float('1.1') have?  float('1.1') and
>> Decimal('1.1') are different values.)
> 
> I think they both should be True, for '1', '1.1', '0', '0.1', ... For
> the value, I would say that it depends of the definition of the field
> (fields.Float or fields.Numeric).
> 
> 
> 
>> I don't think your approach can succeed;  I'd suggest just subclassing
>> 'object' and abandoning the 'isinstance' requirements.  Or perhaps
>> creating a subclass of Decimal that interacts nicely with floats.  You
>> might also want to investigate the numbers ABC, though that's new in
>> Python 2.6.
> 
> First, Float implementation was a subclass of Decimal that works with
> floats, and solves many (maybe all) problems. But as you may read in the
> comments of the patch proposal, it seems to be not enough.
> 
> B.

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


Embedding Python in a C extension

2010-06-02 Thread Paul
I have a problem with embedding Python into a C extension in Windows
Vista. I have implemented a timer routine in C as an extension, which
I can import into Python 2.6.5 and run. Each timer interval, the
extension calls a C CALLBACK function. I want to be able to have this
CALLBACK function call a Python function, so that I can write the
timer handler in Python.

I can write Python functions and call them from a C extension function
with no trouble in all cases EXCEPT when the function that calls the
Python code is the timer's CALLBACK function. That is, if I call
PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or
basically any Python-y function in the CALLBACK function, Python
crashes and I get a window saying "Python has stopped working. Windows
is searching for a solution to the problem."

The Python code runs fine if I call it from a function in the
extension that is not the CALLBACK function. And regular C code runs
in the CALLBACK function properly. It only crashes if I try to run the
Python code from the timer CALLBACK function (or any C function I call
from the CALLBACK function).

Does anybody know how to fix this? Is there a workaround of some sort?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixing Decimal and float

2010-06-02 Thread Nathan Rice
My apologies if someone already mentioned this and I missed it but...

class.__instancecheck__(self, instance) - Return true if instance
should be considered a (direct or indirect) instance of class. If
defined, called to implement isinstance(instance, class).

class.__subclasscheck__(self, subclass) - Return true if subclass
should be considered a (direct or indirect) subclass of class. If
defined, called to implement issubclass(subclass, class).

Nathan

On Wed, Jun 2, 2010 at 4:24 AM, B.V.  wrote:
> Hi,
>
> In order to solve some issues due to operations between Decimal and
> float, we wanted to implement a class that inherits from both float
> and Decimal.
>
> Typically, we wrote:
> class Float(Decimal, float):
> ...
>
> This can not be achieved because of a TypeError exception (with
> message "multiple bases have instance lay-out conflict").
>
> With a class that inherits from Decimal, with overridden __add__,
> __mul__,  , we succeed to solve operations issues.
>
> But we also need to do:
> isinstance(Float('1'), float) == True
> isinstance(Float('1'), Decimal) == True
> which is, AFAIK, only possible with Float(Decimal, float).
>
> Is there a workaround ?
>
> We are developping with python version 2.5 and 2.6.
>
> Thanks for your help.
>
> B.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a pickle to python3

2010-06-02 Thread Paulo da Silva
Em 02-06-2010 04:48, Paulo da Silva escreveu:
> Hi!
> 
> I have a big data structure cpickled into a datafile, by python2.
> I tried to unpickle it using python3 but got the followin message:
> File "/usr/lib64/python3.1/pickle.py", line 1372, in loads
> encoding=encoding, errors=errors).load()
> _pickle.UnpicklingError: invalid load key, 'x'.
> 

...
Please ignore this question. The problem is not the pickle thing but a
compress function I have that has problems related with the new
str/bytes stuff.

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


Re: multiprocessing and accessing server's stdout

2010-06-02 Thread Bryan
I wrote:
> So what you really need is to capture the output of a command, in this
> case LaTeX, so you can copy it back to the client. You can do that
> with the subprocess module in the Python standard library.
>
> If the command generated so much output so fast that you felt the need
> to avoid the extra copy, I suppose you could fork() then hook stdout
> directly to socket connected to the client with dup2(), then exec()
> the command. But no need for that just to capture LaTeX's output.

Upon further reading, I see that the subprocess module makes the
direct-hookup method easy, at least on 'nix systems. Just tell
subprocess.Popen to use the client-connected socket as the
subprocess's stdout.

The question here turns out to make more sense than I had though upon
reading the first post. The server runs a command at the client's
request, and we want to deliver the output of that command back to the
client. A brilliantly efficient method is to direct the command's
stdout to the client's connection.

Below is a demo server that sends the host's words file to any client
that connects. It assumes Unix.


--Bryan Olson


#!/usr/bin/python

from thread import start_new_thread
from subprocess import Popen


def demo(sock):
subp = Popen(['cat', '/usr/share/dict/words'], stdout=sock)
subp.wait()
sock.close()

if __name__ == '__main__':
listener_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listener_sock.bind(('', 54321))
listener_sock.listen(5)
while True:
sock, remote_address = listener_sock.accept()
start_new_thread(demo, (sock,))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixing Decimal and float

2010-06-02 Thread Steven D'Aprano
On Wed, 02 Jun 2010 17:17:11 -0400, Nathan Rice wrote:

> My apologies if someone already mentioned this and I missed it but...
> 
> class.__instancecheck__(self, instance) - Return true if instance should
> be considered a (direct or indirect) instance of class. If defined,
> called to implement isinstance(instance, class).
> 
> class.__subclasscheck__(self, subclass) - Return true if subclass should
> be considered a (direct or indirect) subclass of class. If defined,
> called to implement issubclass(subclass, class).

The original poster needs to support Python 2.5 and 2.6, but 
__instancecheck__ and __subclasscheck__ are only supported in 2.6 or 
higher, so this doesn't help.



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


Re: Properly posting links

2010-06-02 Thread Ben Finney
Terry Reedy  writes:

> On 6/2/2010 4:04 AM, pyDev wrote:
>
> > forum for Python enthusiasts over at PythonForum.org (http://
> > pythonforum.org). Web-based forums is a preferred method by Python
>
> This is the second time today I have read a post with a useless link
> wrapped over two lines. Email lists and newsgroups (this is both) are
> text, not html based. Put a link on one line by itself, with no
> punctuation.

Or better, follow appendix “E. Recommendations for Delimiting URI in
Context” of RFC 2396 http://www.ietf.org/rfc/rfc2396.txt>. This
allows the text to flow more naturally than breaking every URL onto a
separate line, while still delimiting URLs within the text in a standard
manner that most text processing tools will recognise.

-- 
 \ “We can't depend for the long run on distinguishing one |
  `\ bitstream from another in order to figure out which rules |
_o__)   apply.” —Eben Moglen, _Anarchism Triumphant_, 1999 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixing Decimal and float

2010-06-02 Thread Chris Rebert
On Wed, Jun 2, 2010 at 4:11 PM, Steven D'Aprano
 wrote:
> On Wed, 02 Jun 2010 17:17:11 -0400, Nathan Rice wrote:
>> My apologies if someone already mentioned this and I missed it but...
>>
>> class.__instancecheck__(self, instance) - Return true if instance should
>> be considered a (direct or indirect) instance of class. If defined,
>> called to implement isinstance(instance, class).
>>
>> class.__subclasscheck__(self, subclass) - Return true if subclass should
>> be considered a (direct or indirect) subclass of class. If defined,
>> called to implement issubclass(subclass, class).
>
> The original poster needs to support Python 2.5 and 2.6, but
> __instancecheck__ and __subclasscheck__ are only supported in 2.6 or
> higher, so this doesn't help.

Even in 2.6+, good luck trying to define new methods on class `type`
(the metaclass of float and Decimal).

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python in a C extension

2010-06-02 Thread MRAB

p...@mail.python.org wrote:

I have a problem with embedding Python into a C extension in Windows
Vista. I have implemented a timer routine in C as an extension, which
I can import into Python 2.6.5 and run. Each timer interval, the
extension calls a C CALLBACK function. I want to be able to have this
CALLBACK function call a Python function, so that I can write the
timer handler in Python.

I can write Python functions and call them from a C extension function
with no trouble in all cases EXCEPT when the function that calls the
Python code is the timer's CALLBACK function. That is, if I call
PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or
basically any Python-y function in the CALLBACK function, Python
crashes and I get a window saying "Python has stopped working. Windows
is searching for a solution to the problem."

The Python code runs fine if I call it from a function in the
extension that is not the CALLBACK function. And regular C code runs
in the CALLBACK function properly. It only crashes if I try to run the
Python code from the timer CALLBACK function (or any C function I call
from the CALLBACK function).

Does anybody know how to fix this? Is there a workaround of some sort?


Here's a quote from the Python docs at:

http://docs.python.org/c-api/init.html

"""The Python interpreter is not fully thread safe. In order to support
multi-threaded Python programs, there's a global lock, called the global
interpreter lock or GIL, that must be held by the current thread before
it can safely access Python objects. Without the lock, even the simplest
operations could cause problems in a multi-threaded program: for
example, when two threads simultaneously increment the reference count
of the same object, the reference count could end up being incremented
only once instead of twice."""

That's probably what's happening to you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: plac, the easiest command line arguments parser in the world

2010-06-02 Thread alex23
Michele Simionato  wrote:
> It seems I have to take that claim back. A few hours after the
> announce I was pointed out tohttp://pypi.python.org/pypi/CLIArgs
> which, I must concede, is even easier to use than plac. It seems
> everybody has written its own command line arguments parser!

I think I still find opterator[1] to be simpler and clearer. No magic
global variables, no spooky behaviour with the main function, just a
decorator and docstring.

1: http://github.com/buchuki/opterator
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python in a C extension

2010-06-02 Thread Carl Banks
On Jun 2, 1:46 pm, Paul Grunau wrote:
> I have a problem with embedding Python into a C extension in Windows
> Vista. I have implemented a timer routine in C as an extension, which
> I can import into Python 2.6.5 and run. Each timer interval, the
> extension calls a C CALLBACK function. I want to be able to have this
> CALLBACK function call a Python function, so that I can write the
> timer handler in Python.
>
> I can write Python functions and call them from a C extension function
> with no trouble in all cases EXCEPT when the function that calls the
> Python code is the timer's CALLBACK function. That is, if I call
> PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or
> basically any Python-y function in the CALLBACK function, Python
> crashes and I get a window saying "Python has stopped working. Windows
> is searching for a solution to the problem."
>
> The Python code runs fine if I call it from a function in the
> extension that is not the CALLBACK function. And regular C code runs
> in the CALLBACK function properly. It only crashes if I try to run the
> Python code from the timer CALLBACK function (or any C function I call
> from the CALLBACK function).
>
> Does anybody know how to fix this? Is there a workaround of some sort?

See PEP 311.  When an external/uncertain thread calls into Python, it
has to be sure a Python thread state exists for that thread, and that
the thread holds the global interpreter lock.  This is done by
surrounding all Python code with the following calls:

PyGILState_STATE state = PyGILState_Ensure();

and

PyGILState_Release(state);

Normally, code in extension modules can rely on the current thread
having the global lock at all entry points, so it doesn't have worry
about the thread state.  But a callback from a timer can't assume
that.


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