Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-03 Thread Katriel Cohn-Gordon
On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> gc wrote:
>
> > Target lists using comma separation are great, but they don't work
> > very well for this task. What I want is something like
> >
> > a,b,c,d,e = *dict()
>
> a, b, c, d, e = [dict() for i in range(5)]
>

I think this is good code -- if you want five different dicts, then you
should call dict five times. Otherwise Python will magically call your
expression more than once, which isn't very nice. And what if your datatype
constructor has side-effects?

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


Re: making my extensions work together

2011-08-04 Thread Katriel Cohn-Gordon
Wrap your 3rd party library with a Python interface module, and run all
calls from foo and goo through your interface.

On Thu, Aug 4, 2011 at 2:48 PM, Mathew  wrote:

> more info.  I have a large 3rd party library with a function that looks
> like
> this
> void dumbfunc() {
> static int statevar=0;
> ++statevar;
> if (startvar ==3) printf("I have been called 3 times\n");
> }
>
> and I have 2 extensions, foo,py goo.py,created with SWIG, and the both make
> calls to dumbfunc. In creating the extensions, I linked to the 3rd party
> library.
>
> The behavior I want to see is
> >foo.dumbfunc()
> >goo.dumbfunc()
> >goo.dumbfunc()
> I have been called 3 times
>
>
> "Chris Angelico"  wrote in message
> news:mailman.1880.1312441742.1164.python-l...@python.org...
> > On Thu, Aug 4, 2011 at 2:19 AM, Mathew  wrote:
> >> I have 2 extensions and they both access a function in a (static)
> >> library.
> >> The function maintains state information using a static variable.
> >
> > If your extensions are DLLs and they're both linking to the same
> > static library, you should have two independent copies of that library
> > - which would mean they don't interfere with one another. That's why
> > the other extension doesn't see the change, and normally this is the
> > correct and desired behaviour.
> >
> > Having the two be aware of each other is potentially very messy. As
> > Stefan suggested, making one depend on the other would be a lot
> > simpler. Alternatively, there may be ways to have the two extensions
> > share data through Python itself. What are you looking to accomplish?
> >
> > ChrisA
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedded python console and FILE* in python 3.2

2011-08-08 Thread Katriel Cohn-Gordon
Is the `code` module (http://docs.python.org/library/code.html) an
insufficiently exact copy of an interpreter for you?

On Mon, Aug 8, 2011 at 4:17 PM, Francis Labarre
wrote:

>  Hello everyone,
>
> I'm currently trying to port some embedded code from python 2.7 to python
> 3.2.
>
> The current code replicate the basic behavior of the python interpreter in
> an
> MFC application. When a command is entered in our embedded interpreter,
> we write it to a FILE* then transform this FILE* into a Python file with
> the api
> function PyFile_FromFile and assign it to python's stdin. We also assign
> another
> FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne to
> execute
> the statement as the python interpreter normally would. Finally, we
> can easily retrieve
> the result of the execution from the output FILE*.
>
> This is currently the only approach we have found that allows us to
> retrieve the
> result of executing a statement exactly as the interpreter would.
>
> The problem is that the implementation of files has changed in python 3 and
> the function
> PyFile_FromFile has been removed.
>
> Does anyone knows a way to achieve the same thing as this function either
> trough the io module
> or the python/C api? Or could there be a better approach to what we are
> trying to achieve?
>
> Keep in mind that we need to obtain the result of any statement, i.e. :
>
> If the command is "2+2" the result should be "4", if the command is "1/0"
> the result should be
>
> Traceback (most recent call last):
> File "", line 1, in 
> ZeroDivisionError: division by zero
>
>
> Thank you,
>
> F.L.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to solve this problem

2011-08-09 Thread Katriel Cohn-Gordon
Unless you have the router configured to allow connections through to your
local client, you will need the client to connect *outwards*, either to you
or to an intermediate server.

On Tue, Aug 9, 2011 at 12:10 PM, Johny  wrote:

> I have a client that  is a part of a local network.This client has a
> local address( not public).Is there a way how I can connect to this
> client from outside world?
> What software must I install so that I can connect and control that
> client from outside?
>
> Thanks
>
> B
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list