intersection, union, difference, symmetric difference for dictionaries

2014-02-25 Thread mauro
 Dictionaries and sets share a few properties:
- Dictionaries keys are unique as well as sets items
- Dictionaries and sets are both unordered
- Dictionaries and sets are both accessed by key
- Dictionaries and sets are both mutables

So I wonder why operations such us intersection, union, difference, 
symmetric difference that are available for sets and are not available 
for dictionaries without going via key dictviews. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: intersection, union, difference, symmetric difference for dictionaries

2014-02-25 Thread mauro

> 
> {'A': 1} | {'A': 2}
>
> I would propose at least four:
> 
>   {'A': 1}   # choose the LHS 
>   {'A': 2}   # choose the RHS 
>   {'A': (1,2)} # a resulting pair of both 
>   set(['A']) # you did set-ops, so you get a set

The implementation should define if LHS or RHS and user should change the 
order of operands depending on what he wants. 

Your example (as well as a many questions in stackoverflow.com) shows 
that there is some need for these operations, that implemented in C in 
python library will be by far more CPU and memory efficient than 
implemented as you did. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: intersection, union, difference, symmetric difference for dictionaries

2014-02-25 Thread mauro
Il Tue, 25 Feb 2014 22:02:01 +, mauro ha scritto:


>> {'A': 1} | {'A': 2}
>>
>> I would propose at least four:
>> 
>>   {'A': 1}   # choose the LHS {'A': 2}   # choose the RHS {'A': (1,2)}
>>   # a resulting pair of both set(['A']) # you did set-ops, so you get a
>>   set
> 
> The implementation should define if LHS or RHS and user should change
> the order of operands depending on what he wants.
> 
> Your example (as well as a many questions in stackoverflow.com) shows
> that there is some need for these operations, that implemented in C in
> python library will be by far more CPU and memory efficient than
> implemented as you did.

posting error, this entry was supposed to be a reply to Tim Chase's 
comment.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: intersection, union, difference, symmetric difference for dictionaries

2014-02-25 Thread mauro

> 
> {1, 2} & {2, 3} == {2}
> 
In my mind the intersection is evaluated on keys, so the resulting dict 
should be the empty one
> but
> 
> {1:"a", 2:"b", 3:"c"} & {2:"b", 3:"e", 4:"f"} == ???
my output will be
{2:"b", 3:"e"} 
or
{2:"b", 3:"c"} 

depending on the implementation choice.  
> 
> The most obvious result is probably the empty dict {2:"b"}, i. e.
> 
> a & b is defined as dict(a.items() & b.items())
> 
> Frankly, I don't do that a lot. So what's your use-case?
I do not have an use case, but I've seen that many people ask for these 
operations for example in stackoverflow.com

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


Re: Asyncio (or something better) for control of a vacuum system/components.

2014-03-24 Thread mauro
Hav you considered the option of a SCADA solution? There are many 
commercials solutions but also a few open source options such us:
http://openscada.org/
http://pvbrowser.de/pvbrowser/index.php

You may also ask the vacuum system provider, they should be aware of 
SCADA solutions supporting their communication protocols
-- 
https://mail.python.org/mailman/listinfo/python-list


Python class method as an argument of a function in a C extension

2007-09-26 Thread mauro
Hi all,

I am trying to wrap some C code using SWIG (win32, mingw). I am new to
SWIG and to the Python/C API so what I am doing is looking at the
examples and trying to fit them to my needs, but I cannot find any
complete demo example of a C function taking as an argument a Python
function defined by the user.

What I am trying to do is to pass a class method as an argument of a
function defined in a C extension:

# file: runme.py

import myCExtensionModule

class MyClass:
def __init__(self):
self.myCounter = 0
self.myVar = 0
def myMethod(self, myArg):
self.myCounter += 1
return self.myVar + myArg
def runMe(self):
myCExtensionModule.aCFunction(self.myMethod, 10)

x = MyClass()
x.runMe()

# end of runme.py

Can anybody give me an hint (or some link) on how to define
'aCFunction' and how to call 'self.myMethod' in the C source code?

Thank you very much for any kind of help!

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


Re: Python class method as an argument of a function in a C extension

2007-09-26 Thread mauro
On 26 Set, 19:00, Matimus <[EMAIL PROTECTED]> wrote:
> > Can anybody give me an hint (or some link) on how to define
> > 'aCFunction' and how to call 'self.myMethod' in the C source code?
>
> A python function defined in C accepts a pointer to self and a tuple
> of arguments, each of which is also a PyObject. If you pass a function
> or method, it will be included in the tuple of arguments. I don't
> think there is any difference between passing a method and a function.
> You can call that method using functions in the `Object Protocol'
> section of the API, such as PyObject_Call(...).
>
> Here is an example from the Python 
> documentation:http://docs.python.org/ext/callingPython.html
>
> The first part shows how to get a function as an argument. The
> following bits of code show how to actually call that function.The
> example uses PyEval_CallObject, which I can't find documentation to.
> I'm not sure if it even exists (it may be a documentation error). But
> from the example it seems to work exactly the same as
> PyObject_CallObject.
>
> Matt

Thanks a lot!
At last I succeeded in finding an example:
http://mail.python.org/pipermail/python-list/1999-May/003441.html
This uses exactly the PyObject_CallObject, as you suggest.

Mauro

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


PyObject_CallObject: difference between functions and class methods

2007-09-27 Thread mauro
Hi all!

I am trying to call within a C extension a Python function provided as
an argument by the user with: PyObject_Call(). The C extension should
work also if the user supplies a class method, but in this case I am
getting an error. Do I need to explicitly pass 'self' as an argument
to PyObject_Call()? If so, how can I do that?

Now, I am using:

if ((tmp_args = PyTuple_New(1)) == NULL)
PyErr_SetString( PyExc_ReferenceError, "attempt to access a 
null-
pointer" );
PyTuple_SetItem(tmp_args, 0, paramlist);

to create the tuple required by PyObject_Call(), but I have no idea on
how to add a reference to 'self'.

Here is what I would like to obtain:

##
import mymodule

def myfunc(x):
# Do something
return [z]

class MyClass:
def mymethod(self, x):
# Do something
return z
def runme(self):
mymodule.main(myfunc) # This will work
mymodule.main(self.mymethod) # This will not work (Segmentation
fault)

x = MyClass()
x.runme()
##

Thanks in advance.

Mauro

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


Re: Launching command on windows

2007-09-27 Thread mauro
On 27 Set, 15:17, Alexandre Badez <[EMAIL PROTECTED]> wrote:
> Hy,
>
> I'm working on windows and I try to do something like:
>
> import os
> APP = os.path.abspath("C:\\Program Files\\Notepad++\\notepad++.exe")
> FILE1 = os.path.abspath("D:\\Documents and settings\\test1.py")
> FILE2 = os.path.abspath("D:\\Documents and settings\\test2.py")
> command = '"%(app)s" "%(file1)s" "%(file2)s"' % {
> 'app' : APP,
> 'file1' : FILE1,
> 'file2' : FILE2}
> # === FOR 'DEBUG' ===
> print APP
> print FILE1
> print FILE2
> print command
> print repr(command)
> # === END FOR 'DEBUG' ===
> os.system(command)
>
> This code give in output:
> C:\Program Files\Notepad++\notepad++.exe
> D:\Documents and settings\test1.py
> D:\Documents and settings\test2.py
> "C:\Program Files\Notepad++\notepad++.exe" "D:\Documents and settings
> \test1.py" "D:\Documents and settings\test2.py"
> '"C:\\Program Files\\Notepad++\\notepad++.exe" "D:\\Documents and
> settings\\test1.py" "D:\\Documents and settings\\test2.py"'
>
> 'C:\Program' n'est pas reconnu en tant que commande interne
> ou externe, un programme ex,cutable ou un fichier de commandes.
> # <= My windows is a french one
> # This error message could be translated as:
> # 'c:\Program' is not an internal nor external command, an executable
> program nor a command file
>
> But if I copy the command in the output, an paste it in a console, it
> work very well.
> Does any of you know what I can do ?
>
> PS: I think I'm oblige to add " neer every path for spaces in path,
> but if you know an other way, it could be cool :)

If you don't mind using spawnl instead of system, this should work
even with spaces:
os.spawnl(os.P_NOWAITO, command)
I hope it helps.

Mauro

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


setup.py build & SWIG: missing py files (they are outside the build directory)

2007-10-10 Thread mauro
Hi all,
I am trying to make a package distribution containing some extension
module written in C. The problem is that when I run setup.py some
files are generated in the wrong position.
Suppose that this is my setup.py:

from distutils.core import setup, Extension

setup(name='foo',
package_dir  = {"foo" : "src"},
packages=['foo',
'foo.spam',
],
ext_modules=[
Extension("foo.spam._spam",
sources=['src/spam/spam.i',
'src/spam/spam.cc',
],
)
]
)

Here is an example of what I get after running:

python setup.py build -cmingw32 bdist

.\
+build\
+lib.win32-2.4\
+foo\
+spam\
__init__.py
_spam.pyd
__init__.py
foo.py
+src\
+dist\
foo-0.0.win32.zip
setup.py
spam.py

So the problem is that spam.py (generated by SWIG) is not in .\build
\lib.win32-2.4\foo\spam but in the same directory as setup.py!
Of course I can move it manually, but I have to update also
foo-0.0.win32.zip and all this is quite annoying...
Did I miss some option in the setup? Is it possible to run a system
command (copy) after each extension is compiled and linked and the
corresponding .py file is generated?
Thanks in advance!

Mauro

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


Re: cannot create python packages

2007-10-10 Thread mauro
On 10 Ott, 15:01, Konstantinos Pachopoulos <[EMAIL PROTECTED]>
wrote:
> Hi,
> i have the following files:
> current_dir/level1/Called.py
> current_dir/Caller.py
>
> Called.py:
> ---
> class Called:
>def exec1(self):
>  print "Hello"
>
> Caller.py:
> --
> from level1.Called import *
>
> c=Called()
> c.exec1()
>
> However it is impossible for Caller.py to find
> Called.py. I even tried to place the level1 structure
> inside /usr/lib/pythonX.Y/, whithout success however.
> Any ideas?
>
> Thnx
>
>   ___
> Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  
> http://uk.promotions.yahoo.com/forgood/environment.html

I think you need a __init__.py file in level1 directory

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


Re: question about endswith()

2011-03-04 Thread Mauro Caceres
if you could define extension to be a tuple, you could use it this way,
which is a little simpler:

extensions = ('hdf5',) #works
files =
('MOD03.A2010002.1810.005.2010258062733.hdf','MOD03.A2010002.1950.005.2010258063105.hdf','MOD03.A2010002.1950.005.2010258063105.hdf5')
for filename in files:
   if filename.endswith(extensions) :
   print filename

-- 
Mauro Cáceres
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ZODB] Django-hotsauce/ZODB 5.4.0/PyPy nightly sprint!!

2018-06-08 Thread Mauro Amico
seems to me really similar to https://github.com/zopefoundation/ZEO/pull/96
try to upgrade to ZEO 5.1.2

mauro.

Il Ven 8 Giu 2018, 03:29 Etienne Robillard  ha scritto:

> Yo people I'm doing a nightly hacking sprint for django-hotsauce on pypy
> and got some cool bugs I would like to share:
>
> Traceback (most recent call last):
>File "/usr/local/bin/schevo", line 11, in 
>  load_entry_point('libschevo', 'console_scripts', 'schevo')()
>File "/home/erob/src/libschevo/lib/schevo/script/command.py", line
> 32, in __call__
>  return self.main(arg0, args)
>File "/home/erob/src/libschevo/lib/schevo/script/command.py", line
> 74, in main
>  return command()(*args)
>File "/home/erob/src/libschevo/lib/schevo/script/command.py", line
> 32, in __call__
>  return self.main(arg0, args)
>File "/home/erob/src/libschevo/lib/schevo/script/command.py", line
> 74, in main
>  return command()(*args)
>File "/home/erob/src/libschevo/lib/schevo/script/command.py", line
> 32, in __call__
>  return self.main(arg0, args)
>File "/home/erob/src/libschevo/lib/schevo/script/db_evolve.py", line
> 86, in main
>  db = schevo.database.open(url)
>File "/home/erob/src/libschevo/lib/schevo/database.py", line 371, in
> open
>  db = Database(backend)
>File "/home/erob/src/libschevo/lib/schevo/database2.py", line 95, in
> __init__
>  self._update_extent_maps_by_name()
>File "/home/erob/src/libschevo/lib/schevo/database2.py", line 1633,
> in _update_extent_maps_by_name
>  for extent in self._extent_maps_by_id.itervalues():
>File "/usr/local/lib/python2.7/dist-packages/ZODB/Connection.py",
> line 791, in setstate
>  p, serial = self._storage.load(oid)
>File "/usr/local/lib/python2.7/dist-packages/ZODB/mvccadapter.py",
> line 143, in load
>  r = self._storage.loadBefore(oid, self._start)
>File "/home/erob/work/ZEO-5.1.0/src/ZEO/ClientStorage.py", line 520,
> in loadBefore
>  return self._server.load_before(oid, tid)
>File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 783,
> in load_before
>  return self.__call(self.client.load_before_threadsafe, oid, tid)
>File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 748,
> in call
>  return self.wait_for_result(result, self.timeout)
>File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 756,
> in wait_for_result
>  return future.result(timeout)
>File
> "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py",
>
> line 405, in result
>  return self.__get_result()
>File
> "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py",
>
> line 357, in __get_result
>  raise type(self._exception), self._exception, self._traceback
> ZEO.Exceptions.ClientDisconnected: connection lost
> erob@marina:/home/www/isotopesoftware.ca/trunk$
>
>
> Not sure about this first one! :)
>
> The command I'm trying to run is:
>
> % schevo db evolve --app blogengine2 zodb://127.0.0.1:4545 31
>
> The ZODB 5.4.0 server then produce the following traceback:
>
> 2018-06-07T21:14:55 INFO ZEO.asyncio.base Connected server protocol
> --
> 2018-06-07T21:14:55 INFO ZEO.asyncio.server received handshake 'Z5'
> --
> 2018-06-07T21:14:55 ERROR ZEO.asyncio.marshal can't decode message:
> '((ccopy_reg\n_reconstructor\n(czodbpickle\nbinary\nc__b...'
> --
> 2018-06-07T21:14:55 ERROR ZEO.asyncio.server Can't deserialize message
> Traceback (most recent call last):
>File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", line 89,
> in message_received
>  message_id, async, name, args = self.decode(message)
>File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line
> 114, in pickle_server_decode
>  return unpickler.load() # msgid, flags, name, args
>File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line
> 164, in server_find_global
>  raise ImportError("import error %s: %s" % (module, msg))
> ImportError: import error copy_reg:
> --
> 2018-06-07T21:14:55 ERROR ZEO.asyncio.base data_received 4 0 True
> Traceback (most recent call last):
>File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/base.py", line 128,
> in data_received
>  self.message_received(collected)
>File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", line 94,
>

Re: Python versus Perl ?

2005-02-11 Thread Mauro Cicognini

Alex Martelli wrote:

> URK -- _my_ feeling is that we have entirely *too many* options for
> stuff like web application frameworks, GUI toolkits, XML processing,
...
>
>
> Alex

I entirely second that.

More, I'd heartily welcome an authoritative word on which to focus on
for each category... I hate to see scarce resources wasted.

Mauro

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


httplib2 download forbidden

2011-10-05 Thread Mauro Zaccariotto
Hi! does anyone know what's happening here http://code.google.com/p/httplib2/
? I get this:
"403. That’s an error.
Your client does not have permission to get URL /p/httplib2/ from this
server. That’s all we know."
It seems like the httplib2 googlecode project is preventing from
accessing the project web page and downloading httplib2 library
package. I'm in extreme need of using httplib2!
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: httplib2 download forbidden

2011-10-06 Thread Mauro Zaccariotto
On 6 Ott, 09:05, Tim Roberts  wrote:
> Mauro Zaccariotto  wrote:
>
> >Hi! does anyone know what's happening herehttp://code.google.com/p/httplib2/
> >? I get this:
> >"403. That s an error.
> >Your client does not have permission to get URL /p/httplib2/ from this
> >server. That s all we know."
>
> It's working for me.  Do you have some kind of proxy in the way?
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.

No, but today it's working again. O__o
thank you anyway
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Books recommendation

2010-12-07 Thread Mauro Caceres
>
>
> I am also interested to find where I can get Python modules from and how...
> similar tools and sites with cpan and ppm for Perl.
>
>
You should look at http://pypi.python.org/pypi, for modules.
pip (http://pip.openplans.org/) is a tool used to install python modules.

enjoy


-- 
Mauro Cáceres
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Short circuting

2011-01-24 Thread Mauro Caceres
Another option could be something like this:

You can add ids to your regexp, so you can retrive them latter using
groupdict.
Once you have the ids in place, you can join in a new regexp with the "|"
operator which is not greedy, it will stop after the first match.

pattern = (?Pre_section)|?Pre_section|...

Then you can have another structure with the previous id and the actions you
want to perform on them.

actions = {'section': lambda r: r[18:-5],
'name': lambda r: r[6:-1]),
   ...}


Finally you just need to iterate over the result. In this case the
dictionary will have only one pair.

result = pattern.search(line)
if result:
   for key,val in result.groupdict().iteritems():
   actions[key](val)



-- 
Mauro Cáceres
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: returning all matching groups with re.search()

2011-02-07 Thread Mauro Caceres
>>> import re
>>> help(re.findall)
Help on function findall in module re:

findall(pattern, string, flags=0)
Return a list of all non-overlapping matches in the string.

If one or more groups are present in the pattern, return a
list of groups; this will be a list of tuples if the pattern
has more than one group.

Empty matches are included in the result.

>>> re.findall('e','fredbarneybettywilma')
['e', 'e', 'e']

-- 
Mauro Cáceres
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending classes __init__behavior for newbies

2011-02-14 Thread Mauro Caceres
>
>
> Where is the buggy code? Show me how Ship.__init__() can break. Anyone
> can argue, few can offer facts. If you bring an argument that
> Ship.__init__() can break if someone changes the code then that IS NOT
> an valid argument. ANY code can be broken with the addition or
> subtraction of a single char.
>
>
The idea of using super() is that it works with single inheritance and
multiple inheritance.
If after a while your FasterShip extends from Ship and Bird, your
Ship.__init__() will still work BUT it may not be calling the right code. So
using super() is less error prone.

The official documentation also recommends to use super()

http://docs.python.org/library/functions.html#super


-- 
Mauro Cáceres
-- 
http://mail.python.org/mailman/listinfo/python-list


Ping and ARP on both Win and Linux in Python

2008-03-13 Thread Mauro "Baba" Mascia
Hi, this is my question:

I want to know if several switch (about 50) in a big lan are up and then 
know their MAC addresses to do a list that contains host name, ip and mac.
I know only the range of their IP addresses (the host name it's simply 
to know using socket.gethostn.

The first idea it's to ping all ip, parse the response and then execute 
the command "arp -a" and parse the response.
However this way depends on the operating system and the ping response 
depends too from the language.

Another way it's to open the main page of the switch and parse the HTML 
code where i can find the MAC address.
However this way depends on the particular brand's switch.

I know (or better i think) that there is a third way: make ping and arp 
building the packets with socket and so on (but i dont have understand 
in what way do this).

Any suggestion?

(i've already search in google, found many sources but a lot of them 
don't works or don't do what im trying to do...)

Regards,
Mauretto.

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