Re: Detection of a specific sound

2015-10-27 Thread Chris Angelico
On Mon, Oct 26, 2015 at 1:54 PM, Dennis Lee Bieber
 wrote:
> One difficulty -- there is no standard "smoke alarm" sound... While
> they are using piezo-electric buzzers, the control processor may cycle the
> buzzer in different patterns from maker to maker, or slightly different
> pitches.

Maybe not, but since most smoke alarms have a simple "Test" button, it
should be possible to have the program record a sample of the alarm
it's listening for. That would make detection easier.

I personally have no idea how it would work, but in theory, this
should be equivalent to voice navigation - use the same kind of code
that detects spoken commands, just with a different "language".

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


Re: Error while launching python idle.

2015-10-27 Thread Terry Reedy

On 10/26/2015 7:28 PM, Terry Reedy wrote:

On 10/24/2015 3:00 PM, Vijay kumar wrote:

Hi,

I recently installed python 2.7 on my windows 10 laptop. When i launch
python by clicking the python idle the following error appears


In attached image. You should also type the text so it appears in
responses.


even before i do anything.


Just click OK and continue.  This should really be a warning, not an


I changed the 'error' to a warning and expanded the message a bit, 
including 'select OK and continue'.



error.  You will see it once each session, but only once. The recent
files list will not be saved for when you restart IDLE the next time.



It is up to you to determine why it cannot be written in your home
directory and whether you can change permissions.


Before IDLE tries to write to $Home/.idlerc/recent-files.lst it reads 
it, so it exists.  It does this on startup.  Something or someone other 
than IDLE made it read only.


--
Terry Jan Reedy


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


Re: UNABLE TO GET IDLE TO RUN

2015-10-27 Thread Peter Otten
Terry Reedy wrote:

> On 10/26/2015 9:55 AM, Peter Otten wrote:
> 
>> The "bug" or misfeature is that idle automatically adds the working
>> directory to sys.path.
> 
> I am not sure what you mean by 'working directory' here. 

After

$ cd /foo/bar

the working directory is

/foo/bar

> When one runs a
> program with 'python somepath/file.py', python prepends somepath to
> sys.path.

If /foo/bar contains a string.py (for example) module and you run the 
following sequence

$ cd /foo/bar
$ python3 /usr/bin/idle3

/foo/bar/string.py will shade string.py from the standard library. The 
relevant code in idle is

https://hg.python.org/cpython/file/tip/Lib/idlelib/PyShell.py#l1522

"""
else:
dir = os.getcwd()
if dir not in sys.path:
sys.path.insert(0, dir)
"""

I think this is a misfeature.
 
>> Ideally the editor should see the unaltered path
> 
> I don't know what you mean here.  The editor does not look as sys.path.

idle should see the sys.path as it was before inserting os.getcwd().
 
>> while scripts started from within idle might be allowed to import from
>> the working directory.
> 
> Programs run from the editor are intended to run as much as possible the
> same as if run from a command line.  To do this, IDLE must prepend
> somepath to sys.path the same as python itself does.  As a result, if
> somepath/file.py contains
> 
> import sys
> print(sys.path)
> 
> then when run, sys.path  starts with os.abspath(somepath).

Yes, if inside the shell shown by idle the user types

>>> import string

this should import /foo/bar/string.py rather than the stdlib version.
Different behaviour for "idle the editor" and "idle the shell" is of course 
only possible if both use distinct processes. I don't know idle's 
architecture, so I cannot say if that's already the case or if it would 
require a major rewrite.

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


Re: how to get python socket to use a specific interface

2015-10-27 Thread Robin Becker

On 26/10/2015 22:29, Cameron Simpson wrote:

On 26Oct2015 12:33, Robin Becker  wrote:

.



$ ifconfig
eth0  Link encap:Ethernet  HWaddr 00:...4 GB)
 Interrupt:16

eth0:0Link encap:Ethernet  HWa...


Do you need to bind to the device itself? Using the correct IP address should
normally be sufficient. The system you're talking to won't know anything about
the device, only the address. Try skipping the device binding step.



According to the stackoverflow articles here

http://stackoverflow.com/questions/335607/how-do-i-make-an-outgoing-socket-to-a-specific-network-interface

http://stackoverflow.com/questions/8437726/can-python-select-what-network-adapter-when-opening-a-socket

binding to the local IP seems to be a windows only thing. I have tried just 
binding to the local IP, but my packets were from the default address (the one 
connected to eth0). After reading the 8437726 article again I think I may be on 
the wrong track anyway.




Cheers,
Cameron Simpson 



--
Robin Becker

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


Re: UNABLE TO GET IDLE TO RUN

2015-10-27 Thread Terry Reedy

On 10/27/2015 4:15 AM, Peter Otten wrote:

Terry Reedy wrote:



When one runs a
program with 'python somepath/file.py', python prepends somepath to
sys.path.


If /foo/bar contains a string.py (for example) module and you run the
following sequence

$ cd /foo/bar
$ python3 /usr/bin/idle3


I am curious what 'import sys; sys.path' prints in interactive mode, for 
both 'python3' and the above, of whichever *nix you are running.



/foo/bar/string.py will shade string.py from the standard library.


Please reread what I wrote.  IDLE is imitating Python.  This shading the 
same behavior as if you just typed $ python3.  From 
https://docs.python.org/3/library/sys.html#sys.path


"sys.path

A list of strings that specifies the search path for modules. 
Initialized from the environment variable PYTHONPATH, plus an 
installation-dependent default.


As initialized upon program startup, the first item of this list, 
path[0], is the directory containing the script that was used to invoke 
the Python interpreter. If the script directory is not available (e.g. 
if the interpreter is invoked interactively or if the script is read 
from standard input), path[0] is the empty string, which directs Python 
to search modules in the current directory first. Notice that the script 
directory is inserted before the entries inserted as a result of PYTHONPATH.

"

Modules in the current directory shade stdlib modules of the same name. 
 This is a feature for people who want this behavior.  It is a problem 
for people who are caught by it.  The most common example here is 
beginners who write their own random.py, for instance, and then another 
file with 'import random', expecting to get the stdlib module.  This has 
nothing to do with IDLE.  If you do not like this behavior, criticize 
python, not IDLE.


"A program is free to modify this list for its own purposes."

IDLE's purpose is to imitate what python does, in both interactive and 
batch modes.  There are bugs relative to this (and I just opened 
https://bugs.python.org/issue25488), but the bug is not 'imitating 
python' but the failure to do so.  If you find a non-trivial divergence 
in how code is executed that I am not aware of, I would like to know.



The relevant code in idle is

https://hg.python.org/cpython/file/tip/Lib/idlelib/PyShell.py#l1522



"""
 else:
 dir = os.getcwd()
 if dir not in sys.path:
 sys.path.insert(0, dir)
"""


Nope, not in IDLE's normal mode, in which user code is executed in a 
separate process.  The above is for sys.process in the idle process.  I 
suspect it is a holdover from when Idle ran user code in its own process 
(which is still does when -n is given on the command line).


In the previous line, before 'else', the directory of all files given as 
args to be edited is added to sys.path.  I suspect that this is to 
enable completions in single process mode, which is deprecated.



I think this is a misfeature.


Why do you think it a misfeature for IDLE to execute code the way Python 
does?


--
Terry Jan Reedy

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


How to make this simple code look better

2015-10-27 Thread Ganesh Pal
from myPopen import run

def configure_network():
"""
Prepare network for test
"""
try:
cmd = ("netadm enable -p ncp DefaultFixed")
out, err, ret = run(cmd, timeout=60)
if ret != "":
logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
return False
cmd = ("ipadm create-ip net3")
out, err, ret = run(cmd, timeout=60)
if ret != "":
logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
return False
cmd = ("ipadm create-addr -a 192.168.84.3/24 net3")
out, err, ret = run(cmd, timeout=60)
if ret != "":
logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
return False
cmd = (" route -p add default 192.168.84.1")
out, err, ret = run(cmd, timeout=60)
if ret != "":
logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
return False
except Exception, e:
logging.exception("Failed to run %s got %s" % (cmd, e))
return False
logging.info("Configuring network .Done !!!")
return True


Q1.How to make this code look better (in terms of quality)
Q2. Iam using the except clause, just to maintain the syntax,  will
any exception be caught in this case.
Q3. Any other observations made

Thanks,  Iam on Python 2.7 and freebsd.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Version 3.5 required which was not found in the registry

2015-10-27 Thread luyijie
python-list:
 when i install  
 pop "Python Version 3.5 required which was not found in the registry"
 I do not know how to do...


  Best regards


武汉天喻信息产业股份有限公司 
终端技术研发部 卢义杰
手机 13437109862
地址 武汉市东湖开发区庙山小区华工大学科技园创新基地18号楼B座5楼
邮编:430223
--
Disclaimer:
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to which they are addressed. If 
you have received this email in error please notify WHTY. If you are not the 
named addressee you should not disseminate, distribute or copy this e-mail. 
Please note that any views or opinions presented in this email are solely those 
of the author and do not necessarily represent those of WHTY. Finally, the 
recipient should check this email and any attachments for the presence of 
viruses. WHTY accepts no liability for any damage caused by any virus 
transmitted by this email
-- 
https://mail.python.org/mailman/listinfo/python-list


Fw: Python 3.5.0 (32-bit) won't install to Windows XP

2015-10-27 Thread Richard Hinerfeld via Python-list


--- On Fri, 10/23/15, Richard Hinerfeld  wrote:

> From: Richard Hinerfeld 
> Subject: Python 3.5.0 (32-bit) won't install to Windows XP
> To: "[email protected]" 
> Date: Friday, October 23, 2015, 9:10 PM
> I am
> sending you the log with all the errors.
> 

Python 3.5.0 (32-bit)_20151023210511.log
Description: Binary data
-- 
https://mail.python.org/mailman/listinfo/python-list


Building a python extension on Windows

2015-10-27 Thread Ken Brooks
I checked out a copy of svn.python.org/projects/stackless/trunk because it 
seems to have a good sample project (PC/example_nt) for building a Python 
extension on Windows. That directory has a Microsoft Visual C++ solution file 
which can be updated to my Visual C++ version (8, of 2005).

First I tried cd-ing to that directory, as they recommend, and saying "python 
setup.py install". The result? A very common complaint, "Unable to find 
vcvarsall.bat". A search using Windows would suggest that that file doesn't 
exist anywhere on my system.

So I followed the VC++ build instructions, and copied the example_nt directory 
up one level in the tree before building it. But when I actually try to build 
the solution it wants to look in the PCBuild directory for python27.lib, which 
isn't there. Nor can I find that library anywhere else.

What gives? Is this project somehow hopelessly out of date? And more to the 
point, can someone direct me to a nice, fresh example project that will build a 
little Python extension on Windows?

Thanks,

Ken

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


Re: Fw: Python 3.5.0 (32-bit) won't install to Windows XP

2015-10-27 Thread Laura Creighton
Python.org is not supporting XP for 3.5 and beyond.
You need to upgrade your OS, or stick with 3.4

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


Re: Python Version 3.5 required which was not found in the registry

2015-10-27 Thread Michiel Overtoom

> On 27 Oct 2015, at 02:18, luyijie  wrote:
> 
>  when i install  
>  pop "Python Version 3.5 required which was not found in the registry"
>  I do not know how to do...

Wat version of Windows are you using?

Greetings,

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


Re: Detection of a specific sound

2015-10-27 Thread Chris Angelico
On Tue, Oct 27, 2015 at 11:06 PM, Dennis Lee Bieber
 wrote:
> It would almost be faster to attach a thin, high-impedance (since one
> doesn't want to weaken the actual sounder) wire to the Piezo buzzer, and
> poll for activity.  No false positive from an alarm clock or microwave
> chirping.

Or wire up a second smoke alarm (those things honestly aren't all that
expensive) with the noisemaker replaced by something that signals your
application. Actually, it's probably already been done -
internet-enabled smoke alarms...

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


Re: Python Version 3.5 required which was not found in the registry

2015-10-27 Thread MRAB

On 2015-10-27 01:18, luyijie wrote:

python-list:
  when i install 
  pop "Python Version 3.5 required which was not found in the registry"
  I do not know how to do...


Have you installed Python 3.5?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Detection of a specific sound

2015-10-27 Thread John O'Hagan
On Sun, 25 Oct 2015 17:17:28 -0700
Montana Burr  wrote:

> I'm looking for a library that will allow Python to listen for the
> shriek of a smoke alarm. Once it detects this shriek, it is to notify
> someone. Ideally, specificity can be adjusted for the user's
> environment. 

I've used python to detect and record ambient sound by launching
the simple command-line program sox (in its guise as "rec") as a python
subprocess. I hope someone corrects me, but the few python audio
libraries seemed to me to be overkill in terms of coding required and
underkill in terms of features. With sox, it's easy to set things like
length of recording and a triggering threshold etc.. The latter is good
for your use-case because you can set it high enough to only start
recording when something is loud enough to be an alarm. 

Once you have your recording, as others have pointed out, what you do to
detect an alarm sound in it will depend on what alarms sound like where
you live. 

> I'm thinking of recording a smoke alarm and having the program try to
> find the recorded sound in the stream from the microphone.

That kind of matching is IMO unlikely to work. The human ear (or
rather the brain's auditory processing) is very good at picking out the
same general sound in different contexts. Getting software to do this is
hard.

I had a quick look at the acoustid module, which uses Shazam-style
acoustic fingerprinting. It has a method for measuring the similarity
of different recordings, but my little trials weren't promising. A test
recording of my ringtone measured as identical to itself (so far so
good), but only about 25% identical to another recording of the same
ringtone. A recording of me randomly whistling also measured about 25%
similar to the ringtones. 

If your smoke alarms are anything like mine, they have a fixed pitch,
volume and pulse, simple machine-friendly properties that are unlikely
to happen by accident. You could try the aubio module (not a typo,
that's aubio with a "b"). I've never used it and it's python 2 only,
but it has pitch, onset time and "beat" detection. You might be able to
use it to measure those properties from a sample recording, and then
check your monitored recordings to see if they have roughly the same
measurements.

Regards

John

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


Re: How to make this simple code look better

2015-10-27 Thread MRAB

On 2015-10-27 11:54, Ganesh Pal wrote:

from myPopen import run

def configure_network():
 """
 Prepare network for test
 """
 try:
 cmd = ("netadm enable -p ncp DefaultFixed")
 out, err, ret = run(cmd, timeout=60)
 if ret != "":
 logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
 return False
 cmd = ("ipadm create-ip net3")
 out, err, ret = run(cmd, timeout=60)
 if ret != "":
 logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
 return False
 cmd = ("ipadm create-addr -a 192.168.84.3/24 net3")
 out, err, ret = run(cmd, timeout=60)
 if ret != "":
 logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
 return False
 cmd = (" route -p add default 192.168.84.1")
 out, err, ret = run(cmd, timeout=60)
 if ret != "":
 logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
 return False
 except Exception, e:
 logging.exception("Failed to run %s got %s" % (cmd, e))
 return False
 logging.info("Configuring network .Done !!!")
 return True


Q1.How to make this code look better (in terms of quality)
Q2. Iam using the except clause, just to maintain the syntax,  will
any exception be caught in this case.
Q3. Any other observations made

Thanks,  Iam on Python 2.7 and freebsd.


According to the format strings, 'ret' is a number. If that's the case,
it's not a string, so ret != "" will always be true.

Why are you wrapping the command string literals in (...)? That's not
necessary.

You're doing the same thing with each of the command strings, so why
not put them into a list and then iterate over them? It'll save a lot
of duplication.

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


Re: How to make this simple code look better

2015-10-27 Thread Tim Chase
On 2015-10-27 17:24, Ganesh Pal wrote:
> from myPopen import run
> 
> def configure_network():
> """
> Prepare network for test
> """
> try:
> cmd = ("netadm enable -p ncp DefaultFixed")
> out, err, ret = run(cmd, timeout=60)
> if ret != "":
> logging.error("Can't run %s got %s (%d)!" % (cmd, err,
> ret)) return False
> cmd = ("ipadm create-ip net3")
> out, err, ret = run(cmd, timeout=60)
> if ret != "":
> logging.error("Can't run %s got %s (%d)!" % (cmd, err,
> ret)) return False
> cmd = ("ipadm create-addr -a 192.168.84.3/24 net3")
> out, err, ret = run(cmd, timeout=60)
> if ret != "":
> logging.error("Can't run %s got %s (%d)!" % (cmd, err,
> ret)) return False
> cmd = (" route -p add default 192.168.84.1")
> out, err, ret = run(cmd, timeout=60)
> if ret != "":
> logging.error("Can't run %s got %s (%d)!" % (cmd, err,
> ret)) return False
> except Exception, e:
> logging.exception("Failed to run %s got %s" % (cmd, e))
> return False
> logging.info("Configuring network .Done !!!")
> return True
> 
> 
> Q1.How to make this code look better (in terms of quality)

I'd be tempted

1) to put it in a loop
2) just test the "ret" string directly instead of comparing it to
   the empty string
3) to do your exception testing on each command rather than wrapping
   the entire loop

  for cmd in [
  "netadm enable -p ncp DefaultFixed",
  "ipadm create-ip net3",
  "ipadm create-addr -a 192.168.84.3/24 net3",
  "route -p add default 192.168.84.1",
  ]:
try:
  out, err, ret = run(cmd, timeout=60)
  if ret:
logging.exception("Can't run %s got %s (d)!", cmd, err, ret)
return False
except Exception, e:
  logging.exception("Failed to run %s", cmd)
  return False
  logging.info("Configuring network done.")
  return True

It reduces the redundant code and also brings all of the commands
together in one place to see the expected steps.

> Q2. Iam using the except clause, just to maintain the syntax,  will
> any exception be caught in this case.

All regular exceptions will be caught.  I think certain errors (rather
than exceptions) may still behave properly.

-tkc



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


Paramiko SSHClient.connect() problem

2015-10-27 Thread Skip Montanaro
I'm trying to use paramiko (for the first time) to connect to both the
localhost and a remote host as I read along in Jesse Noller's blog post
.
That host is listed in ~/.ssh/known_hosts three different ways: unqualified
hostname, fully qualified hostname, partially qualified hostname, and IP
address. In all cases, it raises an SSHException. Here's an attempt to
connect to localhost:

>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> conn = ssh.connect("127.0.0.1")
SSHException Server '127.0.0.1' not found in known_hosts
[||1] [paramiko/client.py|connect|288]
[paramiko/client.py|missing_host_key|570]

I'm using paramiko 1.15.2 on an OpenSuSE 12.2 system. It's true that
"127.0.0.1" doesn't appear in known_hosts, but the remote host I care about
does, and it gets the same result:

>>> ssh = paramiko.SSHClient()
>>> conn = ssh.connect("firefly")
SSHException Server 'firefly' not found in known_hosts
[||1] [paramiko/client.py|connect|288]
[paramiko/client.py|missing_host_key|570]

Finally, there is also a "localhost" record in known_hosts. Connecting to
that fails with a different exception:

>>> ssh = paramiko.SSHClient()
>>> conn = ssh.connect("localhost")
error getsockaddrarg: bad family
[||1] [paramiko/client.py|connect|251]
[paramiko/util.py|retry_on_signal|270] [paramiko/client.py||251]
[/opt/TWWfsw/python27/lib/python2.7/socket.py|meth|224]

I use host key authentication, not password authentication.

Any pointers appreciated.

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


Re: How to make this simple code look better

2015-10-27 Thread Ganesh Pal
> According to the format strings, 'ret' is a number. If that's the case,
> it's not a string, so ret != "" will always be true.
>
> Why are you wrapping the command string literals in (...)? That's not
> necessary.
>
> You're doing the same thing with each of the command strings, so why
> not put them into a list and then iterate over them? It'll save a lot
> of duplication.
>
> --

Thanks for pointing the ret !=""  error . It should be ret!=0 , yes
let me put into the string and try to iterate.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Paramiko SSHClient.connect() problem

2015-10-27 Thread Skip Montanaro
On Tue, Oct 27, 2015 at 8:23 AM, Skip Montanaro 
wrote:

> >>> ssh = paramiko.SSHClient()
> >>> conn = ssh.connect("firefly")
> SSHException Server 'firefly' not found in known_hosts
> [||1] [paramiko/client.py|connect|288]
> [paramiko/client.py|missing_host_key|570]
>

I figured out that I needed to call

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

I guess that has the side effect of actually reading my known_hosts file?

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


Re: How to make this simple code look better

2015-10-27 Thread Ganesh Pal
On Tue, Oct 27, 2015 at 5:38 PM, Tim Chase
 wrote:

> It reduces the redundant code and also brings all of the commands
> together in one place to see the expected steps.

Thanks your suggested code looks nice , I easily knocked off half the
lines of my code :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Paramiko SSHClient.connect() problem

2015-10-27 Thread Chris Angelico
On Wed, Oct 28, 2015 at 12:23 AM, Skip Montanaro
 wrote:
> Finally, there is also a "localhost" record in known_hosts. Connecting to
> that fails with a different exception:
>
 ssh = paramiko.SSHClient()
 conn = ssh.connect("localhost")
> error getsockaddrarg: bad family
> [||1] [paramiko/client.py|connect|251]
> [paramiko/util.py|retry_on_signal|270] [paramiko/client.py||251]
> [/opt/TWWfsw/python27/lib/python2.7/socket.py|meth|224]
>
> I use host key authentication, not password authentication.
>
> Any pointers appreciated.

The "bad family" error suggests that there's a mismatch between IPv4
and IPv6. It's common for /etc/hosts to contain two references to
localhost, one as 127.0.0.1 and another as ::1 (IPv4 and IPv6
respectively), and if ssh.connect() is picking the wrong one, it'll
have trouble. If you hack your hosts file to have only one localhost,
does the problem disappear?

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


Re: Building a python extension on Windows

2015-10-27 Thread Chris Angelico
On Tue, Oct 27, 2015 at 3:17 PM, Ken Brooks  wrote:
> I checked out a copy of svn.python.org/projects/stackless/trunk because it
> seems to have a good sample project (PC/example_nt) for building a Python
> extension on Windows. That directory has a Microsoft Visual C++ solution
> file which can be updated to my Visual C++ version (8, of 2005).

Building Python extensions on Windows depends heavily on the exact
versions of the MS C compiler and CPython you use. Specifically, to
use your extension with the standard python.org downloadable Python,
you *must* use the same compiler that was used to build it. You
mentioned that it went looking for python27.lib, which implies that
you're using Python 2.7. That uses (and thus requires) a version of
the MS compiler that is no longer supported in the normal way, but you
can get it here:

http://www.microsoft.com/en-au/download/details.aspx?id=44266

Unless you have a good reason for using 2.7, I would strongly
recommend grabbing Python 3.5 instead. Starting with 3.5, the Windows
builds of CPython are using a new "universal library" that will allow
future compilers to be much more compatible with current versions, so
you'll have an easier time of it down the track. Check out Steve
Dower's blog on the subject:

http://stevedower.id.au/blog/building-for-python-3-5-part-two/

If that doesn't help, you might do well to join the python-win32
mailing list, where you'll find a lot of people who know about the
specific details and difficulties of building Windows extensions.

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


RE: Building a python extension on Windows

2015-10-27 Thread Christopher Wilcox
If you are building c extensions on windows with 2.7 you need to get the 
matching compiler from http://aka.ms/vcpython27. You should also make sure you 
are running the latest setup tools. If you are using 2.7.10 you should have 
them already. Finally, I suggest using ‘pip install .’ instead of ‘python 
setup.py install’. You can get setup.py install to work on your machine with 
some configuration, but pip install will just work.

So, in summary, run the following from the PC directory:
pip install setuptools –upgrade
pip install .

-Chris


From: Ken Brooks
Sent: Tuesday, October 27, 2015 5:09
To: [email protected]
Cc: Ken Brooks
Subject: Building a python extension on Windows


I checked out a copy of svn.python.org/projects/stackless/trunk because it 
seems to have a good sample project (PC/example_nt) for building a Python 
extension on Windows. That directory has a Microsoft Visual C++ solution file 
which can be updated to my Visual C++ version (8, of 2005).
First I tried cd-ing to that directory, as they recommend, and saying "python 
setup.py install". The result? A very common complaint, "Unable to find 
vcvarsall.bat". A search using Windows would suggest that that file doesn't 
exist anywhere on my system.
So I followed the VC++ build instructions, and copied the example_nt directory 
up one level in the tree before building it. But when I actually try to build 
the solution it wants to look in the PCBuild directory for python27.lib, which 
isn't there. Nor can I find that library anywhere else.
What gives? Is this project somehow hopelessly out of date? And more to the 
point, can someone direct me to a nice, fresh example project that will build a 
little Python extension on Windows?
Thanks,
Ken
 


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


Re: Paramiko SSHClient.connect() problem

2015-10-27 Thread Skip Montanaro
On Tue, Oct 27, 2015 at 1:40 PM, Chris Angelico  wrote:

> If you hack your hosts file to have only one localhost,
> does the problem disappear?
>

Yes, that appears to solve the problem. Thanks. I hadn't even thought there
would be IPv4/IPv6 distinctions here.

Interestingly enough, the box does seem to support IPv6:

% ssh ::1
Warning: Permanently added '::1' (ECDSA) to the list of known hosts.
Last login: Tue Oct 27 07:31:10 2015 from 10.100.0.191
...

Would I have been able to solve the problem in my paramiko calls by
suitable changes to ssh.connect()? I don't see anything obvious, though
perhaps I could give a non-default "sock" argument?

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


Windows 10 pip2.7.exe uninstall fails

2015-10-27 Thread Mark Lawrence

Let's install something.

C:\>Python27\Scripts\pip2.7.exe install tox
Collecting tox
  Using cached tox-2.1.1-py2.py3-none-any.whl
Collecting virtualenv>=1.11.2 (from tox)
  Using cached virtualenv-13.1.2-py2.py3-none-any.whl
Collecting py>=1.4.17 (from tox)
  Using cached py-1.4.30-py2.py3-none-any.whl
Collecting pluggy<0.4.0,>=0.3.0 (from tox)
  Using cached pluggy-0.3.1-py2.py3-none-any.whl
Installing collected packages: virtualenv, py, pluggy, tox
Successfully installed pluggy-0.3.1 py-1.4.30 tox-2.1.1 virtualenv-13.1.2

Let's get rid of it.

C:\>Python27\Scripts\pip2.7.exe uninstall tox

A message box is displayed:-

"This app can't run on your PC
To find a version for your PC, check with the software publisher".

Close the message box and:-

"Access is denied."

Searching hasn't thrown up a single reference to uninstall errors like 
this, any ideas?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Building a python extension on Windows

2015-10-27 Thread Zachary Ware
On Mon, Oct 26, 2015 at 11:17 PM, Ken Brooks  wrote:
> I checked out a copy of svn.python.org/projects/stackless/trunk

Sorry I don't have the time at the moment for a more complete answer,
but I will point out that that is not the right repository for
anything anymore.  For one thing, it's very outdated (see
http://svn.python.org/view/stackless/, 'trunk' was last modified 5
years ago!); we migrated from Subversion to Mercurial
(https://hg.python.org/) 4 years ago.  For another, that's the
repository for Stackless Python, which is not what you want (unless
you do actually want Stackless Python :).  In that case, Stackless
development has moved to BitBucket:
https://bitbucket.org/stackless-dev/stackless); Stackless is a fork of
CPython.

The upshot is, the repository you most likely want is at
https://hg.python.org/cpython.

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


Re: Building a python extension on Windows

2015-10-27 Thread Jeff Archer
Ken,
I have been successful with building Python on Windows by
downloading Python-3.5.0.tgz.  Expand it and follow the instructions in
Python-3.5.0\PCBuild\readme.txt.  Basically, run get_externals.bat, then
use build.bat.  I have not however been successful building with VS2015
IDE.  Can't remember the specific issues off-hand but since I was
successful using the batch files, I didn't worry about it.
With this build of Python I have gotten rudimentary extensions working with
Boost.Python and straight C code.  Had to build Boost against this build of
Python to make that work.

jeff

*From: *Ken Brooks
> *Sent: *Tuesday, October 27, 2015 5:09
> *To: *[email protected]
> *Cc: *Ken Brooks
> *Subject: *Building a python extension on Windows
>
>
>
>
>
> I checked out a copy of svn.python.org/projects/stackless/trunk because
> it seems to have a good sample project (PC/example_nt) for building a
> Python extension on Windows. That directory has a Microsoft Visual C++
> solution file which can be updated to my Visual C++ version (8, of 2005).
>
> First I tried cd-ing to that directory, as they recommend, and saying
> "python setup.py install". The result? A very common complaint, "Unable to
> find vcvarsall.bat". A search using Windows would suggest that that file
> doesn't exist anywhere on my system.
>
> So I followed the VC++ build instructions, and copied the example_nt
> directory up one level in the tree before building it. But when I actually
> try to build the solution it wants to look in the PCBuild directory for
> python27.lib, which isn't there. Nor can I find that library anywhere else.
>
> What gives? Is this project somehow hopelessly out of date? And more to
> the point, can someone direct me to a nice, fresh example project that will
> build a little Python extension on Windows?
>
> Thanks,
>
> Ken
>
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Paramiko SSHClient.connect() problem

2015-10-27 Thread Chris Angelico
On Wed, Oct 28, 2015 at 6:56 AM, Skip Montanaro
 wrote:
> On Tue, Oct 27, 2015 at 1:40 PM, Chris Angelico  wrote:
>>
>> If you hack your hosts file to have only one localhost,
>> does the problem disappear?
>
>
> Yes, that appears to solve the problem. Thanks. I hadn't even thought there
> would be IPv4/IPv6 distinctions here.
>
> Interestingly enough, the box does seem to support IPv6:
>
> % ssh ::1
> Warning: Permanently added '::1' (ECDSA) to the list of known hosts.
> Last login: Tue Oct 27 07:31:10 2015 from 10.100.0.191
> ...
>
> Would I have been able to solve the problem in my paramiko calls by suitable
> changes to ssh.connect()? I don't see anything obvious, though perhaps I
> could give a non-default "sock" argument?

I've no idea. At this point, it's sounding like a paramiko issue -
possibly even a bug, I don't know. Something to explore, at least.

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


Re: how to get python socket to use a specific interface

2015-10-27 Thread Cameron Simpson

On 27Oct2015 10:00, Robin Becker  wrote:

On 26/10/2015 22:29, Cameron Simpson wrote:

On 26Oct2015 12:33, Robin Becker  wrote:

.



$ ifconfig
eth0  Link encap:Ethernet  HWaddr 00:...4 GB)
Interrupt:16

eth0:0Link encap:Ethernet  HWa...


Do you need to bind to the device itself? Using the correct IP address should
normally be sufficient. The system you're talking to won't know anything about
the device, only the address. Try skipping the device binding step.


According to the stackoverflow articles here

http://stackoverflow.com/questions/335607/how-do-i-make-an-outgoing-socket-to-a-specific-network-interface

http://stackoverflow.com/questions/8437726/can-python-select-what-network-adapter-when-opening-a-socket

binding to the local IP seems to be a windows only thing.


No, it is a pretty standard BSD socket layer thing. (Windows got its original 
TCP stack from there too). I just tested a Linux RHEL6 host binding to a 
specific address just now using telnet:


 /usr/bin/telnet -b x.x.x.193 x.x.x.174 22

where the .193 is not the primary address - it is an additional local address.  
The connection was correctly received by the target as from the alias address, 
not the base address:


 Oct 28 10:28:18 HOSTNAME sshd[7531]: Connection from x.x.x.193 port 61621

An strace says:

 socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3 bind(3, {sa_family=AF_INET, 
sin_port=htons(0), sin_addr=inet_addr("203.166.218.193")}, 16) = 0

 setsockopt(3, SOL_IP, IP_TOS, [16], 4)  = 0

 connect(3, {sa_family=AF_INET, sin_port=htons(22), 
sin_addr=inet_addr("203.166.218.174")}, 16) = 0

so you can see it just binds the source address and goes. No device names 
involved.


I have tried just binding to the local IP, but my packets were from the 
default address (the one connected to eth0). After reading the 8437726 article 
again I think I may be on the wrong track anyway.


Please show me the exact code you're using. This really should work without 
annoying "device" binding.


The counter examples in the articules you cite are for particularly weird 
circumstances, such as where the routing table cannot correctly deduce the 
interface (distinct attached networks with the _same_ network numbering - 
ghastly). They don't say "binding to the local IP seems to be a windows only 
thing" that I can see.


Please post your failing code. I suspect you're missing something.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to make this simple code look better

2015-10-27 Thread Ben Finney
Dennis Lee Bieber  writes:

>   Actually, if 0 is success, and you are testing for a failure, it
> should probably just be
>
>   if ret:
>   #do error

That obscures the intent; there is nothing about “is ‘ret’ false?” that
tells me what the meaning of that test is.

It happens to be the case that “success” is a false-y value, but that's
not clear from reading a simple “if ret” test.

Instead, I advise making it clear *why* we're checking zero in
particular: because in this case zero means success. That's not obvious,
and should be explicit.

EXIT_CODE_SUCCESS = 0

# …

(stdout_content, stderr_content) = proc.communicate()
if proc.returncode != EXIT_CODE_SUCCESS:
handle_the_failure(proc)

-- 
 \  “The process by which banks create money is so simple that the |
  `\ mind is repelled.” —John Kenneth Galbraith, _Money: Whence It |
_o__)   Came, Where It Went_, 1975 |
Ben Finney

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


Re: How to log the output from the multiple telnet sessions to separate log file

2015-10-27 Thread dieter
[email protected] writes:
> ...
>  I created the my own class MyLogger and passing log file name to it. I'm 
> seeing no log is being written to passed log file instead everything is 
> written to the logfilename [actually logfilename is variable with file name] 
> I'm trying to create MyLogger object for each telnet session. and use that 
> object.
>
> MyLogger is beeing called inside the Telnetsession class. those are present 
> in PmTelnet3.py file.
>
>
> class MyLogger():
>   import logging
>   def __init__(self,logfilename):
>   #create logger with 'spam_application'
>   self.logger = self.logging.getLogger('TelnetSession')

This will always give you the same logger object.

I recommend to carefully read the "logging" related documentation
to understand its architecture. In your context, the logger
hierarchy and the concept of "logging handler" are of great importance.

> ...
>   self.logging.basicConfig(filename = logfilename,
>   level = 
> self.logging.INFO ,
>   format= 
> '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
>   datefmt='%m-%d 
> %H:%M',
>   filemode='w')
This will configure the so called "root" logger - the object at
the root of the logger hierarchy. Loggers lower down in the hiearrchy
will "inherit" from loggers higher up, unless they override things.

Therefore, you will usually have a single "basicConfig" call, which
globally (independent of the individual telnet sessions) configures
common aspects. In the individual telnet sessions, you would
use session specific loggers (below the "root" logger) which would
inherit the common configuration and override session specific things
(e.g. the log file via a specific handler).

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