Re: [Windows] drag-and-drop onto .py file in modern versions?

2012-04-12 Thread Chris Angelico
On Thu, Apr 12, 2012 at 4:02 PM, Karl Knechtel  wrote:
> Aside: when I double-click a .py file, what determines which Python will run
> it? Is it a matter of which appears first in the PATH, or do I have to set
> something else in the registry? Will a shebang line override the default on
> Windows? If so, how do I write a shebang line for a Windows path - just
> "#!C:/Windows/Python32"?

Apologies - I can't answer your main question, and am just picking up the aside.

The file-type association (which is really a file-extension
association) determines the path to the executable. If that's
specified without a full path, then it'll be the first one in PATH,
but usually the association is given as an absolute filespec. I don't
have a Vista handy, but in XP, bring up any folder, Options|Folder
Options, File Types, and scroll down to PY. (For some obscure reason,
on this particular computer of mine the association is with a Python
that was installed with GNU Lilypond. Weird!) You may need to use the
Advanced button to see the full path.

As to writing a shebang, there's no way to do that directly. But in
theory you could associate .py files with a little script that reads
the first line and figures out which interpreter to invoke it in. For
extra coolness points, write that script in portable Python that can
be run on any of the interpreters you have installed - then you don't
have to care! :)

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


Is it possible develop applications in python for android and which IDE could you recommend me (Eclipse, ...)???

2012-04-12 Thread sisifus
Hello all,

I would like to know if it's possible develop android applications with
python, making the apk package, etc. I don't want program from an android
device only want to make programs for android from my PC.

If it's possible which IDE could you recommend me?

Thanks for your help

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


Sockets accept() in child processes

2012-04-12 Thread Thibaut DIRLIK
Hi,

I'm writing a multiprocess server with Python 3.2 and the multiprocessing
module. Here is my current implementation :

- Main process: select() on a list of server sockets (different ips of the
host, ssl or not, etc)
- Children process : When they get a signal (in fact, a message in a pipe),
they will accept() the server socket

The problem is that after select() returns, I can accept() in the main
process, but in a children process I got a EAGAIN error.
The sockets are non-blocking. It seems that accept() can only be called in
the same process that the one which selected().

This is a problem because I wanted to "decide" which process I should ask
to take the connection
to do some basic load-balacing based on current number of connected client
in each process.

Could someone help me or propose other implementations ?

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


is this foolish?

2012-04-12 Thread Cameron Simpson
I've found myself using a Python gotcha as a feature.

I've got a budding mail filter program which keeps rule state in a
little class instance. Slightly paraphrased:

class RuleState(object):
def __init__(self, M, maildb_path, maildirs={}):
[...]
self.maildirs = maildirs

The maildirs property is a cache of Maildir objects mapped by their
pathname to avoid opening Maildirs every time they're mentioned. I
create a new RuleState every time I file a message, and of course I want
to share the cache between instances.

Normally we look on the Python default parameter value as a gotcha which
causes the unwary to reuse a single object across the board, causing
unwanted persistence of state.

But here I actually think this is a sane way to make an anonymous single
shared state object for the maildirs cache, absent the caller's intent
to use their own.

I can think of a few potential downsides, but on the whole this is going
to do exactly what I want in this case.

Would experienced users please mock me?
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Real Daleks don't climb stairs Real Daleks level the building.
- Adrian Tritschler, ajft@ajft_sun.cs.adfa.oz.au
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is this foolish?

2012-04-12 Thread Chris Angelico
On Thu, Apr 12, 2012 at 7:35 PM, Cameron Simpson  wrote:
> I've found myself using a Python gotcha as a feature.
>
> I've got a budding mail filter program which keeps rule state in a
> little class instance. Slightly paraphrased:
>
>    class RuleState(object):
>        def __init__(self, M, maildb_path, maildirs={}):
>            [...]
>            self.maildirs = maildirs
>
> Would experienced users please mock me?

Well, no mocking; the same technique on a non-method function is a
pretty normal way of maintaining state. But wouldn't it be simpler to
use a class variable?

class RuleState(object):
maildirs = {}
def __init__(self, M, maildb_path):

Then just use self.maildirs everywhere, never assign to it.

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


Re: is this foolish?

2012-04-12 Thread Cameron Simpson
On 12Apr2012 19:43, Chris Angelico  wrote:
| On Thu, Apr 12, 2012 at 7:35 PM, Cameron Simpson  wrote:
| > I've found myself using a Python gotcha as a feature.
| > I've got a budding mail filter program which keeps rule state in a
| > little class instance. Slightly paraphrased:
| >
| >    class RuleState(object):
| >        def __init__(self, M, maildb_path, maildirs={}):
| >            [...]
| >            self.maildirs = maildirs
| >
| > Would experienced users please mock me?
| 
| Well, no mocking; the same technique on a non-method function is a
| pretty normal way of maintaining state.

I hadn't realised it was a common approach.

| But wouldn't it be simpler to use a class variable?

Yes. Yes it would.

| class RuleState(object):
| maildirs = {}
| def __init__(self, M, maildb_path):
| Then just use self.maildirs everywhere, never assign to it.

Thanks. It makes the shared state far more obvious, too.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Life IS pain, highness...  anyone who tries to tell you different is
trying to sell you something.   - Wesley, The_Princess_Bride
-- 
http://mail.python.org/mailman/listinfo/python-list


Error in MD5 checksums of the 2.7.3 release page.

2012-04-12 Thread Jérémy Bethmont
Hello,

There is an error in the MD5 checksums section of the following page:
    http://python.org/download/releases/2.7.3/

Python-3.1.5.tgz, Python-3.1.5.tar.bz2 and Python-3.1.5.tar.xz
are listed instead of:
Python-2.7.3.tgz, Python-2.7.3.tar.bz2 and Python-2.7.3.tar.xz

Best,

--
Jérémy Bethmont
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is this foolish?

2012-04-12 Thread Tim Golden
On 12/04/2012 10:35, Cameron Simpson wrote:
> I've found myself using a Python gotcha as a feature.

Have a look at Peter Inglesby's lightning talk from a
recent London Python Dojo:

  http://inglesp.github.com/2012/03/24/mutable-default-arguments.html

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


Re: is this foolish?

2012-04-12 Thread Karl Knechtel
On Thu, Apr 12, 2012 at 7:15 AM, Tim Golden  wrote:

> On 12/04/2012 10:35, Cameron Simpson wrote:
> > I've found myself using a Python gotcha as a feature.
>
> Have a look at Peter Inglesby's lightning talk from a
> recent London Python Dojo:
>
>  http://inglesp.github.com/2012/03/24/mutable-default-arguments.html
>
>
That's interesting, but you can get the same effect with a function
attribute, if you really don't want to write a class... that way also
protects you against accidentally passing something in to override the
default. (Incidentally: I feel that the "lambda x = x: ..." idiom to avoid
multiple closures sharing state is an ugly hack, for the same reason.)


-- 
~Zahlman {:>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem connecting to SMTP/IMAP server using SSL

2012-04-12 Thread Christian Heimes
Am 12.04.2012 08:56, schrieb Julien Phalip:
> Hi Michael,
> 
> Thanks again for your reply. I've tried using SMTP with TLS. And again
> it works with the VPN turned on but it still won't work with the VPN
> turned off. For some reason I don't understand, it simply won't
> instantiate the SMTP/SMTP_SSL/IMAP4/IMAP4_SSL objects at all and will
> hang forever if the VPN is turned off.

Are you trying to connect to an Exchange server? Several Exchange mobile
clients aren't using IMAP and SMTP but EAS over HTTPS. I have the same
setup at work. The SMTP port is blocked unless I'm at the office or
using VPN.

In your case the connection hangs forever because your office's firewall
drops the network packages instead of sending a reject package. The
client keeps on trying since you haven't configured a timeout.

Christian

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


Re: is this foolish?

2012-04-12 Thread Jean-Michel Pichavant

Cameron Simpson wrote:

I've found myself using a Python gotcha as a feature.

I've got a budding mail filter program which keeps rule state in a
little class instance. Slightly paraphrased:

class RuleState(object):
def __init__(self, M, maildb_path, maildirs={}):
[...]
self.maildirs = maildirs

The maildirs property is a cache of Maildir objects mapped by their
pathname to avoid opening Maildirs every time they're mentioned. I
create a new RuleState every time I file a message, and of course I want
to share the cache between instances.

Normally we look on the Python default parameter value as a gotcha which
causes the unwary to reuse a single object across the board, causing
unwanted persistence of state.

But here I actually think this is a sane way to make an anonymous single
shared state object for the maildirs cache, absent the caller's intent
to use their own.

I can think of a few potential downsides, but on the whole this is going
to do exactly what I want in this case.

Would experienced users please mock me?
  
Instance attributes are not meant to be shared among all instances. 
Assigning a persistant object over instances to an instance attribute is 
perverting your design.
Remember that experienced programmers will automaticcaly trigger a 
warning in their mind when reading your mutable maildirs. They 'll lose 
time to realize that it was intended. Since there is much more standard 
ways to do this (class attribute for instance), you should not use that 
form.


Cleverness is the step mother of obfuscation.

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


Re: is this foolish?

2012-04-12 Thread Andrea Crotti

On 04/12/2012 10:35 AM, Cameron Simpson wrote:

I've found myself using a Python gotcha as a feature.

I've got a budding mail filter program which keeps rule state in a
little class instance. Slightly paraphrased:

 class RuleState(object):
 def __init__(self, M, maildb_path, maildirs={}):
 [...]
 self.maildirs = maildirs

The maildirs property is a cache of Maildir objects mapped by their
pathname to avoid opening Maildirs every time they're mentioned. I
create a new RuleState every time I file a message, and of course I want
to share the cache between instances.

Normally we look on the Python default parameter value as a gotcha which
causes the unwary to reuse a single object across the board, causing
unwanted persistence of state.

But here I actually think this is a sane way to make an anonymous single
shared state object for the maildirs cache, absent the caller's intent
to use their own.

I can think of a few potential downsides, but on the whole this is going
to do exactly what I want in this case.

Would experienced users please mock me?


You could probably just make this caching more explicit using a decorator.
The good thing about that is that you could even change the behaviour of 
your

caching without touching the code that uses it for example.
--
http://mail.python.org/mailman/listinfo/python-list


Coping with risk of decision - modeling of scenarios of parameters of the model in python

2012-04-12 Thread John Oksz

Hello,

I work with energy planning on municipal level.
I have an energy supply deterministic model for municipal customer.

Now I want to coping with uncertainty and risk of decision choosing
one energy supply option for implementing in real.
Some parameters of my deterministic model (energy prices and energy
demands) are uncertainty in future.

I want to coping with uncertainty by using: (1) scenario analysis, (2)
stochastic simulation, and (3) on the end of my research stochastic
optimization.
I want to calculate VaR and CVaR of any modeling decision.

For this parameters (which are uncertainty) I have  historical data
(last 15 years) and I want use this data for forecasting/modeling
scenarios for energy carriers prices (gas, electricity, LPG, coal,
etc.) in future 15 year.

I am looking for methodology of creating scenarios of parameters of
the model (ex-post… ex-ante, ???) for this decision problem.

Can you suggest any paper/book/example about:
- scenario analysis in pyhon
- stochastic simulation in pyhon
- coping with uncertenises and  risk in python (VaR, CVaR)?

Thanks in advance for any help.
John

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


Re: [Windows] drag-and-drop onto .py file in modern versions?

2012-04-12 Thread Mark Lawrence

On 12/04/2012 08:00, Chris Angelico wrote:

On Thu, Apr 12, 2012 at 4:02 PM, Karl Knechtel  wrote:

Aside: when I double-click a .py file, what determines which Python will run
it? Is it a matter of which appears first in the PATH, or do I have to set
something else in the registry? Will a shebang line override the default on
Windows? If so, how do I write a shebang line for a Windows path - just
"#!C:/Windows/Python32"?


Apologies - I can't answer your main question, and am just picking up the aside.

The file-type association (which is really a file-extension
association) determines the path to the executable. If that's
specified without a full path, then it'll be the first one in PATH,
but usually the association is given as an absolute filespec. I don't
have a Vista handy, but in XP, bring up any folder, Options|Folder
Options, File Types, and scroll down to PY. (For some obscure reason,
on this particular computer of mine the association is with a Python
that was installed with GNU Lilypond. Weird!) You may need to use the
Advanced button to see the full path.

As to writing a shebang, there's no way to do that directly. But in
theory you could associate .py files with a little script that reads
the first line and figures out which interpreter to invoke it in. For
extra coolness points, write that script in portable Python that can
be run on any of the interpreters you have installed - then you don't
have to care! :)

Chris Angelico


For the record please see http://www.python.org/dev/peps/pep-0397/ 
"Python launcher for Windows" which discusses shebang lines.


--
Cheers.

Mark Lawrence.

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


Re: is this foolish?

2012-04-12 Thread gene heskett
On Thursday, April 12, 2012 10:40:47 AM Tim Golden did opine:

> On 12/04/2012 10:35, Cameron Simpson wrote:
> > I've found myself using a Python gotcha as a feature.
> 
Tim:  your setup of using the CC: line for every thing with a blank To: 
line is landing your posts in my spam folder.  Do you have a specific 
reason for not using a To: line?

I am not inclined to change my filer rules because that particular rule 
catches a lot of the incoming spam.

> Have a look at Peter Inglesby's lightning talk from a
> recent London Python Dojo:
> 
>   http://inglesp.github.com/2012/03/24/mutable-default-arguments.html
> 
> TJG


Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page: 
He who invents adages for others to peruse
takes along rowboat when going on cruise.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functions which take functions

2012-04-12 Thread Kiuhnm

On 4/11/2012 16:01, Antti J Ylikoski wrote:

On 9.4.2012 21:57, Kiuhnm wrote:

Do you have some real or realistic (but easy and self-contained)
examples when you had to define a (multi-statement) function and pass it
to another function?
Thank you.

Kiuhnm


A function to numerically integrate another function comes as follows:

[...]

Thank you.

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


Re: functions which take functions

2012-04-12 Thread Kiuhnm

On 4/12/2012 8:07, Tim Roberts wrote:

Kiuhnm  wrote:


That won't do. A good example is when you pass a function to re.sub, for
instance.


This is an odd request.


All shall be revealed :)



I often pass functions to functions in order to simulate a C switch
statement, such as in a language translator:

   commands = {
 'add': doAdd,
 'subtract' : doSubtract,
 'multiply' : doMultiply,
 'divide' : doDivide
   }

   nextCommand = parseCommandLine( line )
   invokeCommand( commands[NextCommand] )


I like that very much. Thank you.

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


Zipping a dictionary whose values are lists

2012-04-12 Thread tkpmep
I using Python 3.2 and have a dictionary
>>> d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]}

whose values are lists I would like to zip into a list of tuples. If I 
explicitly write:
>>> list(zip([1,2], [1,2,3], [1,2,3,4])
[(1, 1, 1), (2, 2, 2)]

I get exactly what I want. On the other hand, I have tried

>>>list(zip(d))
[(0,), (1,), (2,)]

>>> list(zip(d.values()))
[([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]

>>> list(zip(d[i] for i in d))
[([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]

>>> list(zip(*d))
Traceback (most recent call last):
  File "", line 1, in 
list(zip(*d))
TypeError: zip argument #1 must support iteration

and nothing quite works. What am I doing wrong?

Sincerely

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


Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Pavel Anossov
zip(*d.values())

On 12 April 2012 20:28,   wrote:
> I using Python 3.2 and have a dictionary
 d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]}
>
> whose values are lists I would like to zip into a list of tuples. If I 
> explicitly write:
 list(zip([1,2], [1,2,3], [1,2,3,4])
> [(1, 1, 1), (2, 2, 2)]
>
> I get exactly what I want. On the other hand, I have tried
>
list(zip(d))
> [(0,), (1,), (2,)]
>
 list(zip(d.values()))
> [([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]
>
 list(zip(d[i] for i in d))
> [([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]
>
 list(zip(*d))
> Traceback (most recent call last):
>  File "", line 1, in 
>    list(zip(*d))
> TypeError: zip argument #1 must support iteration
>
> and nothing quite works. What am I doing wrong?
>
> Sincerely
>
> Thomas Philips
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
С уважением, Аносов Павел
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Kiuhnm

On 4/12/2012 18:28, [email protected] wrote:

I using Python 3.2 and have a dictionary

d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]}


whose values are lists I would like to zip into a list of tuples. If I 
explicitly write:

list(zip([1,2], [1,2,3], [1,2,3,4])

[(1, 1, 1), (2, 2, 2)]

I get exactly what I want. On the other hand, I have tried


list(zip(d))

[(0,), (1,), (2,)]


list(zip(d.values()))

[([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]


Almost. Since d.values() = [[1,2], [1,2,3], [1,2,3,4]], you need to use
list(zip(*d.values()))
which is equivalent to
list(zip([1,2], [1,2,3], [1,2,3,4]))

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


Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Peter Otten
[email protected] wrote:

> I using Python 3.2 and have a dictionary
 d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]}
> 
> whose values are lists I would like to zip into a list of tuples. If I
> explicitly write:
 list(zip([1,2], [1,2,3], [1,2,3,4])
> [(1, 1, 1), (2, 2, 2)]
> 
> I get exactly what I want. On the other hand, I have tried
> 
list(zip(d))
> [(0,), (1,), (2,)]
> 
 list(zip(d.values()))
> [([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]
> 
 list(zip(d[i] for i in d))
> [([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]
> 
 list(zip(*d))
> Traceback (most recent call last):
>   File "", line 1, in 
> list(zip(*d))
> TypeError: zip argument #1 must support iteration
> 
> and nothing quite works. What am I doing wrong?

You have all the building blocks ;)

>>> d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]}
>>> list(zip(*d.values()))
[(1, 1, 1), (2, 2, 2)]

The order of the values is undefined, so you may want to sort the lists by 
key first:

>>> list(zip(*[v for k, v in sorted(d.items())]))
[(1, 1, 1), (2, 2, 2)]

Well, I guess it doesn't really matter for that example...

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


Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Dan Sommers
On Thu, 12 Apr 2012 09:28:03 -0700 (PDT)
[email protected] wrote:

> I using Python 3.2 and have a dictionary
> >>> d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]}
> 
> whose values are lists I would like to zip into a list of tuples. If
> I explicitly write:
> >>> list(zip([1,2], [1,2,3], [1,2,3,4])
> [(1, 1, 1), (2, 2, 2)]
> 
> I get exactly what I want. On the other hand, I have tried
> 
> >>>list(zip(d))
> [(0,), (1,), (2,)]
> 
> >>> list(zip(d.values()))
> [([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]
> 
> >>> list(zip(d[i] for i in d))
> [([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]
> 
> >>> list(zip(*d))
> Traceback (most recent call last):
>   File "", line 1, in 
> list(zip(*d))
> TypeError: zip argument #1 must support iteration
> 
> and nothing quite works. What am I doing wrong?

Try this:

>>> list(zip(*d.values()))

d.values() is a list, but zip wants the individual values as separate
arguments.

HTH,
Dan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible develop applications in python for android and which IDE could you recommend me (Eclipse, ...)???

2012-04-12 Thread Dan Stromberg
http://code.google.com/p/android-scripting/

However, I've not used it, and I'm told it requires a stub for each new
android method exposed to python.  I find it a little regrettable that they
didn't start frp, jython or pypy for jvm instead of cpython, to avoid all
the stubbing.

On Thu, Apr 12, 2012 at 1:21 AM, sisifus wrote:

> Hello all,
>
> I would like to know if it's possible develop android applications with
> python, making the apk package, etc. I don't want program from an android
> device only want to make programs for android from my PC.
>
> If it's possible which IDE could you recommend me?
>
> Thanks for your help
>
> Regards
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sockets accept() in child processes

2012-04-12 Thread Dan Stromberg
I wonder if this'll do what you need:
https://trac.calendarserver.org/browser/CalendarServer/trunk/twext/python/sendfd.py

On Thu, Apr 12, 2012 at 2:31 AM, Thibaut DIRLIK wrote:

> Hi,
>
> I'm writing a multiprocess server with Python 3.2 and the multiprocessing
> module. Here is my current implementation :
>
> - Main process: select() on a list of server sockets (different ips of the
> host, ssl or not, etc)
> - Children process : When they get a signal (in fact, a message in a
> pipe), they will accept() the server socket
>
> The problem is that after select() returns, I can accept() in the main
> process, but in a children process I got a EAGAIN error.
> The sockets are non-blocking. It seems that accept() can only be called in
> the same process that the one which selected().
>
> This is a problem because I wanted to "decide" which process I should ask
> to take the connection
> to do some basic load-balacing based on current number of connected client
> in each process.
>
> Could someone help me or propose other implementations ?
>
> Thank you,
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem connecting to SMTP/IMAP server using SSL

2012-04-12 Thread Dan Stromberg
Are you quite sure that your iPhone isn't using some sort of VPN?

On my Android phone, I need a VPN client to access my work mail, but I
install it once and forget about it; it doesn't require me to enter my
password more than once.

On Fri, Mar 30, 2012 at 10:39 PM, Julien  wrote:

> Hi,
>
> I'm able to connect to an Exchange server via SMTP and IMAP from my
> iPhone using SSL and without using a VPN. So I would expect to be able
> to do the same from my computer using Python.
>
> However, the following hangs and times out on my computer when I'm not
> connected to the VPN:
>
> >>> import imaplib
> >>> imap = imaplib.IMAP4_SSL("my.server.address")
>
> If I am connected to the VPN, then it works fine.
>
> Do you know why it won't work with SSL and without the VPN? Am I
> missing something?
>
> Thanks a lot,
>
> Julien
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functions which take functions

2012-04-12 Thread Jan Kuiken

On 4/9/12 20:57 , Kiuhnm wrote:


Do you have some real or realistic (but easy and self-contained)
examples when you had to define a (multi-statement) function and pass it
to another function?


I don't use it daily but the first argument of list.sort, i.e. the
compare function springs to mind.

Jan Kuiken


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


Re: python module development workflow

2012-04-12 Thread John Nagle

On 4/11/2012 1:04 PM, Miki Tebeka wrote:

Could any expert suggest an authoritative and complete guide for
developing python modules? Thanks!

I'd start with http://docs.python.org/distutils/index.html


Make sure that

python setup.py build
python setup.py install

works.

Don't use the "rotten egg" distribution system.
(http://packages.python.org/distribute/easy_install.html)

John Nagle

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


Re: Problem connecting to SMTP/IMAP server using SSL

2012-04-12 Thread Dan Stromberg
Maybe it's a matter of two different protocols, one requiring a VPN, one
not.

You could perhaps try a sniffer to check that out.  Where to place the
sniffer could be complicated though.

On Fri, Mar 30, 2012 at 10:39 PM, Julien  wrote:

> Hi,
>
> I'm able to connect to an Exchange server via SMTP and IMAP from my
> iPhone using SSL and without using a VPN. So I would expect to be able
> to do the same from my computer using Python.
>
> However, the following hangs and times out on my computer when I'm not
> connected to the VPN:
>
> >>> import imaplib
> >>> imap = imaplib.IMAP4_SSL("my.server.address")
>
> If I am connected to the VPN, then it works fine.
>
> Do you know why it won't work with SSL and without the VPN? Am I
> missing something?
>
> Thanks a lot,
>
> Julien
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Deep merge two dicts?

2012-04-12 Thread Roy Smith
Is there a simple way to deep merge two dicts?  I'm looking for Perl's
Hash::Merge (http://search.cpan.org/~dmuey/Hash-Merge-0.12/Merge.pm)
in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sockets accept() in child processes

2012-04-12 Thread Merwin

Le 12/04/2012 19:10, Dan Stromberg a écrit :


I wonder if this'll do what you need:
https://trac.calendarserver.org/browser/CalendarServer/trunk/twext/python/sendfd.py


The problem is that this is Linux-only solution, and I would like to 
keep a multi-platform compatibility.


There are other ways to do this : use a Lock and do the select() 
directly in the children processes,
but I can't control which process will get the lock, and it's totally 
possible that only 2 processes on 8

will accept connections alternatively.



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


Re: Deep merge two dicts?

2012-04-12 Thread John Nagle

On 4/12/2012 10:41 AM, Roy Smith wrote:

Is there a simple way to deep merge two dicts?  I'm looking for Perl's
Hash::Merge (http://search.cpan.org/~dmuey/Hash-Merge-0.12/Merge.pm)
in Python.


def dmerge(a, b) :
   for k in a :
v = a[k]
if isinstance(v, dict) and k in b:
dmerge(v, b[k])
   a.update(b)



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


multiprocessing and Array problems

2012-04-12 Thread Al Niessner

I am not subscribed to these lists but I do check them occasionally and
will check them more frequently looking for a response.

I am getting a pickling error that I do not understand. It seems the
shared arrays that I create cannot be pickled. Makes the
multiprocessing.Array fairly useless if it cannot be pickled. Hence, I
am guessing that I am doing something wrong and would like some help
spotting it.

This is basically a cut and paste from the examples in the
documentation:

import ctypes
import multiprocessing

def subproc (a, i):
print ("From subprocess " + str(i))
print (a[:])
return

if __name__ == "__main__":
nproc = 3
print ("\nBuilding the array for the second computation.")
b = multiprocessing.Array (ctypes.c_double, nproc*nproc, lock=False)

print ("\nSending the task across to see what happens.")
pool = multiprocessing.Pool(nproc)
for i in range(nproc): pool.apply_async (subproc, kwds={'a':b,
'i':i})
pool.close()
pool.join()
pass

Whether I run it on 2.6, 2.7, or 3.2 I get the same error.

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
self.run()
  File "/usr/lib/python2.6/threading.py", line 484, in run
self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in
_handle_tasks
put(task)
PicklingError: Can't pickle : attribute lookup
multiprocessing.sharedctypes.c_double_Array_9 failed


Anyone want to take a stab as to why this error message is being
generated? Again I have tried python 2.6.7, 2.7.2+, and 3.2.2.

Thanks for any and all help in advance.

-- 
Al Niessner

I have never found the companion that was so companionable as solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it is man's
choice of behavior that makes them malevolent rather than benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers


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


Re: multiprocessing and Array problems

2012-04-12 Thread Al Niessner

Here is an update.

def subproc (i):
print ("From subprocess " + str(i))
print (b[:])
return

if __name__ == "__main__":
nproc = 3
print ("\nBuilding the array for the second computation.")
b = multiprocessing.Array (ctypes.c_double, nproc*nproc, lock=False)

print ("\nSending the task across to see what happens.")
pool = multiprocessing.Pool(nproc)
for i in range(nproc): pool.apply_async (subproc, kwds={'i':i})
pool.close()
pool.join()
pass

Does work. It is not what I need though. I need to be able to pass b as
an argument. The reason is that I create some of these in a loop and
they are not in a global space nor are they know prior to creating the
pool.

On Thu, 2012-04-12 at 11:15 -0700, Al Niessner wrote:
> I am not subscribed to these lists but I do check them occasionally and
> will check them more frequently looking for a response.
> 
> I am getting a pickling error that I do not understand. It seems the
> shared arrays that I create cannot be pickled. Makes the
> multiprocessing.Array fairly useless if it cannot be pickled. Hence, I
> am guessing that I am doing something wrong and would like some help
> spotting it.
> 
> This is basically a cut and paste from the examples in the
> documentation:
> 
> import ctypes
> import multiprocessing
> 
> def subproc (a, i):
> print ("From subprocess " + str(i))
> print (a[:])
> return
> 
> if __name__ == "__main__":
> nproc = 3
> print ("\nBuilding the array for the second computation.")
> b = multiprocessing.Array (ctypes.c_double, nproc*nproc, lock=False)
> 
> print ("\nSending the task across to see what happens.")
> pool = multiprocessing.Pool(nproc)
> for i in range(nproc): pool.apply_async (subproc, kwds={'a':b,
> 'i':i})
> pool.close()
> pool.join()
> pass
> 
> Whether I run it on 2.6, 2.7, or 3.2 I get the same error.
> 
> Exception in thread Thread-1:
> Traceback (most recent call last):
>   File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
> self.run()
>   File "/usr/lib/python2.6/threading.py", line 484, in run
> self.__target(*self.__args, **self.__kwargs)
>   File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in
> _handle_tasks
> put(task)
> PicklingError: Can't pickle  'multiprocessing.sharedctypes.c_double_Array_9'>: attribute lookup
> multiprocessing.sharedctypes.c_double_Array_9 failed
> 
> 
> Anyone want to take a stab as to why this error message is being
> generated? Again I have tried python 2.6.7, 2.7.2+, and 3.2.2.
> 
> Thanks for any and all help in advance.
> 

-- 
Al Niessner

I have never found the companion that was so companionable as solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it is man's
choice of behavior that makes them malevolent rather than benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers


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


Re: Deep merge two dicts?

2012-04-12 Thread Ian Kelly
On Thu, Apr 12, 2012 at 11:59 AM, John Nagle  wrote:
> On 4/12/2012 10:41 AM, Roy Smith wrote:
>>
>> Is there a simple way to deep merge two dicts?  I'm looking for Perl's
>> Hash::Merge (http://search.cpan.org/~dmuey/Hash-Merge-0.12/Merge.pm)
>> in Python.
>
>
> def dmerge(a, b) :
>   for k in a :
>        v = a[k]
>        if isinstance(v, dict) and k in b:
>            dmerge(v, b[k])
>   a.update(b)

That doesn't work.  After b[k] is recursively merged into a[k], the
call "a.update(b)" copies b[k] into a[k], discarding the merged dict.
Try this:

def dmerge(a, b):
for k, v in b.items():
if isinstance(v, dict) and k in a:
dmerge(a[k], v)
else:
a[k] = v

Hash::Merge also does a lot more than this, but I'm not sure exactly
which functionality the OP is looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error in MD5 checksums of the 2.7.3 release page.

2012-04-12 Thread Terry Reedy

On 4/12/2012 6:11 AM, Jérémy Bethmont wrote:


There is an error in the MD5 checksums section of the following page:
 http://python.org/download/releases/2.7.3/

Python-3.1.5.tgz, Python-3.1.5.tar.bz2 and Python-3.1.5.tar.xz
are listed instead of:
Python-2.7.3.tgz, Python-2.7.3.tar.bz2 and Python-2.7.3.tar.xz


verified and forwarded to pydev list for correction.

--
Terry Jan Reedy


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


Re: multiprocessing and Array problems

2012-04-12 Thread MRAB

On 12/04/2012 19:30, Al Niessner wrote:


Here is an update.

def subproc (i):
 print ("From subprocess " + str(i))
 print (b[:])
 return

if __name__ == "__main__":
 nproc = 3
 print ("\nBuilding the array for the second computation.")
 b = multiprocessing.Array (ctypes.c_double, nproc*nproc, lock=False)

 print ("\nSending the task across to see what happens.")
 pool = multiprocessing.Pool(nproc)
 for i in range(nproc): pool.apply_async (subproc, kwds={'i':i})
 pool.close()
 pool.join()
 pass

Does work. It is not what I need though. I need to be able to pass b as
an argument. The reason is that I create some of these in a loop and
they are not in a global space nor are they know prior to creating the
pool.


Doing this works:

processes = []
for i in range(nproc):
processes.append(multiprocessing.Process(target=subproc, 
kwargs={'a':b, 'i':i}))

for p in processes:
p.start()
for p in processes:
p.join()


On Thu, 2012-04-12 at 11:15 -0700, Al Niessner wrote:

 I am not subscribed to these lists but I do check them occasionally and
 will check them more frequently looking for a response.

 I am getting a pickling error that I do not understand. It seems the
 shared arrays that I create cannot be pickled. Makes the
 multiprocessing.Array fairly useless if it cannot be pickled. Hence, I
 am guessing that I am doing something wrong and would like some help
 spotting it.

 This is basically a cut and paste from the examples in the
 documentation:

 import ctypes
 import multiprocessing

 def subproc (a, i):
 print ("From subprocess " + str(i))
 print (a[:])
 return

 if __name__ == "__main__":
 nproc = 3
 print ("\nBuilding the array for the second computation.")
 b = multiprocessing.Array (ctypes.c_double, nproc*nproc, lock=False)

 print ("\nSending the task across to see what happens.")
 pool = multiprocessing.Pool(nproc)
 for i in range(nproc): pool.apply_async (subproc, kwds={'a':b,
 'i':i})
 pool.close()
 pool.join()
 pass

 Whether I run it on 2.6, 2.7, or 3.2 I get the same error.

 Exception in thread Thread-1:
 Traceback (most recent call last):
   File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
 self.run()
   File "/usr/lib/python2.6/threading.py", line 484, in run
 self.__target(*self.__args, **self.__kwargs)
   File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in
 _handle_tasks
 put(task)
 PicklingError: Can't pickle: attribute lookup
 multiprocessing.sharedctypes.c_double_Array_9 failed


 Anyone want to take a stab as to why this error message is being
 generated? Again I have tried python 2.6.7, 2.7.2+, and 3.2.2.

 Thanks for any and all help in advance.





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


Re: Sockets accept() in child processes

2012-04-12 Thread Dan Stromberg
On Thu, Apr 12, 2012 at 10:48 AM, Merwin  wrote:

> Le 12/04/2012 19:10, Dan Stromberg a écrit :
>
>
>> I wonder if this'll do what you need:
>> https://trac.calendarserver.**org/browser/CalendarServer/**
>> trunk/twext/python/sendfd.py
>>
>
> The problem is that this is Linux-only solution, and I would like to keep
> a multi-platform compatibility.
>
I suspect it's actually pretty multiplatform, with one likely exception:
Windows.  But the code itself is from Apple, and I first learned of the
technique in Unix's heyday.


> There are other ways to do this : use a Lock and do the select() directly
> in the children processes,
> but I can't control which process will get the lock, and it's totally
> possible that only 2 processes on 8
> will accept connections alternatively.
>
If you have all your children bind using SO_REUSEADDR, and then have the
parent process pass a "go ahead message" to an available child, you might
get what you desire.  The unavailable child would then pass a "I'm
available again" message back to the parent when ready for another piece of
work.

The children probably should also be able to send a "I'm done with the
socket" message to the parent as well, so the parent doesn't ask two
children to use the socket at the same time.

This is kind of weird, but it seems to satisfy your requirement.

I believe SO_REUSEADDR is even more cross-platform than passing a
filedescriptor.

Better still, don't have the children interact with the main socket; just
let them get a complete message describing a piece of work from the
parent.  This isn't as likely to run into OS idiosyncrasies.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: older woman and young guy

2012-04-12 Thread jimmy970
http://porn-extreme.2304310.n4.nabble.com/
http://porn-extreme.2304310.n4.nabble.com/ 

--
View this message in context: 
http://python.6.n6.nabble.com/AMPUTEE-INCEST-MIDGET-2012-tp4708963p4864079.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does this hang sometimes?

2012-04-12 Thread Jesse Jaggars
Possibly. I wonder what the difference(s) is(are)?

On Sat, Apr 7, 2012 at 5:54 PM, Jason Friedman  wrote:
>> I am just playing around with threading and subprocess and found that
>> the following program will hang up and never terminate every now and
>> again.
>>
>> import threading
>> import subprocess
>> import time
>>
>> def targ():
>>    p = subprocess.Popen(["/bin/sleep", "2"])
>>    while p.poll() is None:
>>        time.sleep(1)
>>
>> t1 = threading.Thread(target=targ)
>> t2 = threading.Thread(target=targ)
>> t1.start()
>> t2.start()
>>
>> t1.join()
>> t2.join()
>>
>>
>> I found this bug, and while it sounds similar it seems that it was
>> closed during python 2.5 (I'm using 2.7.2):
>> http://bugs.python.org/issue1404925
>
> I can confirm hanging on my installation of 2.7.2.  I also ran this
> code 100 times on 3.2.2 without experiencing a hang.  Is version 3.x a
> possibility for you?
-- 
http://mail.python.org/mailman/listinfo/python-list


GNTP not connecting

2012-04-12 Thread milosh zorica
hey folks

seems GNTP doesn't work for me. the growl app itself works cool


import gntp.notifier

gntp.notifier.mini("message")

-

Traceback (most recent call last):
  File "", line 1, in 
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gntp/notifier.py",
line 48, in mini
result = growl.register()
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gntp/notifier.py",
line 128, in register
return self._send('register', register)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gntp/notifier.py",
line 221, in _send
s.connect((self.hostname, self.port))
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py",
line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 61] Connection refused


thanks
m.



-- 
Milosh Zorica

http://www.linkedin.com/in/miloshzorica

phone: +44 20 8144 5294 & +1 206 350 9734
e-mail: [email protected]
skype: milosh.zorica
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GNTP not connecting

2012-04-12 Thread Chris Angelico
On Fri, Apr 13, 2012 at 7:32 AM, milosh zorica  wrote:
>    s.connect((self.hostname, self.port))
> socket.error: [Errno 61] Connection refused

This is saying that the computer at that hostname is running, but no
program is listening on that port. Maybe you have the host/port wrong,
or maybe something needs to be running on that computer.

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


Re: Deep merge two dicts?

2012-04-12 Thread Kiuhnm

On 4/12/2012 19:59, John Nagle wrote:

On 4/12/2012 10:41 AM, Roy Smith wrote:

Is there a simple way to deep merge two dicts? I'm looking for Perl's
Hash::Merge (http://search.cpan.org/~dmuey/Hash-Merge-0.12/Merge.pm)
in Python.


def dmerge(a, b) :
   for k in a :
v = a[k]
if isinstance(v, dict) and k in b:
dmerge(v, b[k])
   a.update(b)


There are a few problems with that code:
1) you don't make sure that b[k] is a dict so
   a={'a':{'b':1}}; b={'a':1}
   make it crash.
2) the last update overwrites nested updates, but this could be the 
intended behavior.

For instance, with the 'a' and 'b' above, the result would be
{'a':1}

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


Re: GNTP not connecting

2012-04-12 Thread Chris Angelico
On Fri, Apr 13, 2012 at 7:44 AM, milosh zorica  wrote:
> yes but what?
>
> everything else works cool and i can connect via socket from python
>
> On Thu, Apr 12, 2012 at 6:38 PM, Chris Angelico  wrote:
>> On Fri, Apr 13, 2012 at 7:32 AM, milosh zorica  
>> wrote:
>>>    s.connect((self.hostname, self.port))
>>> socket.error: [Errno 61] Connection refused
>>
>> This is saying that the computer at that hostname is running, but no
>> program is listening on that port. Maybe you have the host/port wrong,
>> or maybe something needs to be running on that computer.
>>
>> ChrisA
>> --
>> http://mail.python.org/mailman/listinfo/python-list

I'm hoping you meant for that reply to be on-list, and am myself
replying on-list.

You can connect to that (host,port) using Python? In that case, check
that the right host/port is being used by growl - possibly there's a
parameter you need to check. I can't help any further though, as I
have no experience with growl.

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


Re: GNTP not connecting

2012-04-12 Thread milosh zorica
thanks

On Thu, Apr 12, 2012 at 7:30 PM, Chris Angelico  wrote:
> On Fri, Apr 13, 2012 at 7:44 AM, milosh zorica  wrote:
>> yes but what?
>>
>> everything else works cool and i can connect via socket from python
>>
>> On Thu, Apr 12, 2012 at 6:38 PM, Chris Angelico  wrote:
>>> On Fri, Apr 13, 2012 at 7:32 AM, milosh zorica  
>>> wrote:
    s.connect((self.hostname, self.port))
 socket.error: [Errno 61] Connection refused
>>>
>>> This is saying that the computer at that hostname is running, but no
>>> program is listening on that port. Maybe you have the host/port wrong,
>>> or maybe something needs to be running on that computer.
>>>
>>> ChrisA
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>
> I'm hoping you meant for that reply to be on-list, and am myself
> replying on-list.
>
> You can connect to that (host,port) using Python? In that case, check
> that the right host/port is being used by growl - possibly there's a
> parameter you need to check. I can't help any further though, as I
> have no experience with growl.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Milosh Zorica

http://www.linkedin.com/in/miloshzorica

phone: +44 20 8144 5294 & +1 206 350 9734
e-mail: [email protected]
skype: milosh.zorica
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is this foolish?

2012-04-12 Thread Cameron Simpson
On 12Apr2012 10:44, gene heskett  wrote:
| On Thursday, April 12, 2012 10:40:47 AM Tim Golden did opine:
| > On 12/04/2012 10:35, Cameron Simpson wrote:
| > > I've found myself using a Python gotcha as a feature.
| > 
| Tim:  your setup of using the CC: line for every thing with a blank To: 
| line is landing your posts in my spam folder.  Do you have a specific 
| reason for not using a To: line?
| 
| I am not inclined to change my filer rules because that particular rule 
| catches a lot of the incoming spam.

This should probably be offline, but can you outline your rule?
Almost all my rules match on either to or cc happily and I don't know of
a spam pattern that would benefit from treating them differently.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

The laws of thermodynamics state that you can't win, you can't break even,
and you can't even quit the game.  Most human institutions are based on the
belief that you can break one of the three laws -- capitalism assumes you can
win, socialism assumes you can break even, and religion assumes you can quit
the game.
-- 
http://mail.python.org/mailman/listinfo/python-list


remainder of dividing by zero

2012-04-12 Thread Ethan Furman
Okay, so I haven't asked a stupid question in a long time and I'm 
suffering withdrawal symptoms... ;)


5 % 0 = ?

It seems to me that the answer should be 5: no matter how many times we 
add 0 to itself, the remainder of the intermediate step will be 5.


Is there a postulate or by definition answer as to why this should not 
be so?


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


Re: functions which take functions

2012-04-12 Thread Kiuhnm

On 4/12/2012 19:29, Jan Kuiken wrote:

On 4/9/12 20:57 , Kiuhnm wrote:


Do you have some real or realistic (but easy and self-contained)
examples when you had to define a (multi-statement) function and pass it
to another function?


I don't use it daily but the first argument of list.sort, i.e. the
compare function springs to mind.


Yes, I guess there are times when a lambda is not enough and one needs 
to define a real function.

Thanks.

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


Re: remainder of dividing by zero

2012-04-12 Thread Terry Reedy

On 4/12/2012 6:34 PM, Ethan Furman wrote:

Okay, so I haven't asked a stupid question in a long time and I'm
suffering withdrawal symptoms... ;)

5 % 0 = ?

It seems to me that the answer should be 5: no matter how many times we
add 0 to itself, the remainder of the intermediate step will be 5.

Is there a postulate or by definition answer as to why this should not
be so?


0 <= M % N < N
no solution for N == 0

m // n, m % n = divmod(m, n), which is to say, divmod is the fundamental 
recursively defined operation and // and % are each one of the 
components with the other ignored. m % n = divmod(m, n)[1]

and divmod is not defined for n == 0

def divmod(m, n):  # m, n not negative
  q, r = 0, m
  while m >= n:
q, r = q+1, r-n
  return q, r

Of course, given m, n in base n representation, the way you learned to 
do it in school is faster. In binary, it is even easier because each 
digit is 0 or 1 so no guessing needed as with base 10.


--
Terry Jan Reedy

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


Re: remainder of dividing by zero

2012-04-12 Thread MRAB

On 12/04/2012 23:34, Ethan Furman wrote:

Okay, so I haven't asked a stupid question in a long time and I'm
suffering withdrawal symptoms... ;)

5 % 0 = ?

It seems to me that the answer should be 5: no matter how many times we
add 0 to itself, the remainder of the intermediate step will be 5.

Is there a postulate or by definition answer as to why this should not
be so?


If x > 0, 0 <= 5 % x < x.

At the limit of x == 0, you get 0 <= 5 % 0 < 0.

At that point, an exception is probably a good idea! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mouse LED Control in Python

2012-04-12 Thread Shaunda
How can I make a battery powered 
http://www.ledstrips8.com/led-light-bars-c-38.html led strip 12v   with 3
way switches?
My goal is to make a long line of grouped LEDs that is battery powered and
can be turned on or off from 2 different locations. I'm trying to make a
lighting system that doesn't make me have to turn on several individual
lamps as I find them along my path.

I will be making a line with 8  http://www.ledstrips8.com/ waterproof led
strip light  ("lamp" being a cluster of 6 LEDs), but I have no idea as to
how to go about making the line.

How should I set up the circuit to have all of them retain their brightness?

I need a battery that is rechargeable, so I am making one on
cheapbatterypacks.com. What size battery will I need to make (voltage and
mAh) to power this setup?  LEDs are RL5-W18030 at 
http://www.ledstrips8.com/flexible-led-strip-lighting-c-32.html blue led
strip 

I know I need a 3 way switch to turn them on and off with 2 switches, but
I'm not sure how to wire them into the circuit. Any advice?

I don't have a lot of experience with electronics, so some explanations
would be greatly appreciated.

Thanks for you help!

--
View this message in context: 
http://python.6.n6.nabble.com/Mouse-LED-Control-in-Python-tp1035960p4874673.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python module development workflow

2012-04-12 Thread rusi
On Apr 11, 8:38 pm, Peng Yu  wrote:
> On Apr 11, 10:25 am, John Gordon  wrote:
>
> > In <2900f481-fbe9-4da3-a7ca-5485d1ceb...@m13g2000yqc.googlegroups.com> Peng 
> > Yu  writes:
>
> > > It is confusing to me what the best workflow is for python module
> > > development. There is setup.py, egg. Also, pip, easy_install.
>
> > It's unclear what you are asking.
>
> > How to develop your own modules?
>
> > How to package and distribute your own modules once they're finished?
>
> I'm asking these two questions.

You need to ask these two questions separately.

For the first you'll get good answers here if you can be more
specific.

The second is a good question which will not get useful answers
because python's package and distribute system(s) are in a flux.  In
all fairness this is so for most languages which have as bad messes in
this domain. eg Haskell's cabal
http://cdsmith.wordpress.com/2011/01/16/haskells-own-dll-hell/
http://ivanmiljenovic.wordpress.com/2010/03/15/repeat-after-me-cabal-is-not-a-package-manager/
-- 
http://mail.python.org/mailman/listinfo/python-list