Re: Large number multiplication

2011-07-08 Thread Mark Dickinson
On Jul 7, 9:30 am, Ulrich Eckhardt 
wrote:
> That said, I'm sure that the developers would accept a patch that switches
> to a different algorithm if the numbers get large enough. I believe it
> already doesn't use Karatsuba for small numbers that fit into registers,
> too.

I'm far from sure that such a patch would be accepted. :-)  Indeed,
Tim Peters has been heard to mention that if he were to do it all
again, he probably wouldn't even have implemented Karatsuba [1].
Asymptotically fast integer multiplication is a specialist need that's
already available in 3rd-party Python libraries (gmpy).  IMO, it's not
appropriate to include it in a general-purpose programming language,
and the burden of maintaining such code would outweigh the benefits.

One thing that has been considered in the past is making it possible
to use GMP directly for Python's implementation of long integers;  see
Victor Stinner's efforts in this direction [2].  Licensing concerns,
and the fact that Python's implementation is faster for small
integers, ended up killing this issue.

[1] http://mail.python.org/pipermail/python-dev/2008-November/083355.html
[2] http://bugs.python.org/issue1814

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


Re: Does hashlib support a file mode?

2011-07-08 Thread Steven D'Aprano
Phlip wrote:

>> I worded that poorly. None is (AFAIK) the only instance of NoneType, but
>> I should've clarified the difference.> The is operator does not compare
>> types, it compares instances for identity.
> 
> None is typesafe, because it's strongly typed.

Everything in Python is strongly typed. Why single out None?

Python has strongly-typed objects, dynamically typed variables, and a
philosophy of preferring duck-typing over explicit type checks when
possible.


> However, what's even MORE X-safe (for various values of X) is a method
> that takes LESS for its arguments. That's why I switched from passing
> an object to passing a type, because the more restrictive argument
> type is more typesafe.

It seems to me that you are defeating duck-typing, and needlessly
restricting what the user can pass, for dubious or no benefit. I still
don't understand what problems you think you are avoiding with this tactic.



> However, the MOST X-safe version so far simply passes a string, and
> uses hashlib the way it designs to be used:
> 
> def file_to_hash(path, hash_type):
> hash = hashlib.new(hash_type)
> with open(path, 'rb') as f:
> while True:
> s = f.read(8192)
> if not s:  break
> hash.update(s)
> return hash.hexdigest()


There is no advantage to this that I can see. It limits the caller to using
only hashes in hashlib. If the caller wants to provide her own hashing
algorithm, your function will not support it.

A more reasonable polymorphic version might be:

def file_to_hash(path, hash='md5', blocksize=8192):
# FIXME is md5 a sensible default hash?
if isinstance(hash, str):
# Allow the user to specify the hash by name.
hash = hashlib.new(hash)
else:
# Otherwise hash must be an object that implements the 
# hashlib interface, i.e. a callable that returns an 
# object with appropriate update and hexdigest methods.
hash = hash()
with open(path, 'rb') as f:
while True:
s = f.read(blocksize)
if not s:  break
hash.update(s)
return hash.hexdigest()





-- 
Steven

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


Re: Serial & reset of the device

2011-07-08 Thread Tim Roberts
yorick  wrote:
>
>I'm trying to access a hardware board of my company through a serial
>connection using a Python script and the pyserial module.
>
>I use Python 2.7.1 with Ubuntu 11.04 (pyserial is the package python-
>serial with version 2.5.2, http://pyserial.sourceforge.net/pyserial_api.html).
>
>The board to which I'm trying to connect works correctly with serial
>as some other guys did some TCL scripts to manage it.
>My problem is that every time I open a new connection, the device is
>reset. I'd like to not have the device reset.

I'm not sure what that means.  The RS-232 standard does not have the
concept of "reset".  What is it that triggers a device reset?
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python for science experiments

2011-07-08 Thread Ajith Kumar
Hello,
  Just posting a link of a project using Python  for
doing science experiments.

with regards

ajith


-- 
Dr. Ajith Kumar B.P.
Scientist SG
Inter-University Accelerator Centre
Aruna Asaf Ali Marg
New Delhi 110067
www.iuac.res.in
Ph: (off) 91 11 26893955 (Ext.230)
  (res)91 11 26897867
  (mob) 91 9868150852
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EVIL!

2011-07-08 Thread Andrew Berg
On 2011.07.07 12:29 PM, rantingrick wrote:
> So you prefer to close a gazillion windows one by one? If so, why not
> just code the GUI correctly from the start; by creating separate
> transactions? Thereby reducing the number of windows a user must
> juggle? FYI: You know the user complexity of a GUI increases
> exponentially by the number of windows present.
:-D

Are you paid to troll? I must say, your technique of presenting
semi-logical, but completely wrong arguments is admirable. Truly the
work of a professional.
-- 
http://mail.python.org/mailman/listinfo/python-list


Finding duplicated photo

2011-07-08 Thread TheSaint
Hello,

I came across the problem that Gwenview moves the photo from the camera 
memory by renaming them, but later I forgot which where moved.
Then I tought about a small script in python, but I stumbled upon my 
ignorance on the way to do that.

PIL can find similar pictures. I was thinking to reduce the foto into gray 
scale and resize them to same size, what algorithm should take place?
Is PIL able to compare 2 images?
 
-- 
goto /dev/null
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding duplicated photo

2011-07-08 Thread Billy Mays

On 07/08/2011 07:29 AM, TheSaint wrote:

Hello,

I came across the problem that Gwenview moves the photo from the camera
memory by renaming them, but later I forgot which where moved.
Then I tought about a small script in python, but I stumbled upon my
ignorance on the way to do that.

PIL can find similar pictures. I was thinking to reduce the foto into gray
scale and resize them to same size, what algorithm should take place?
Is PIL able to compare 2 images?



I recently wrote a program after reading an article ( 
http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html 
) using the DCT method he proposes.  It worked surprisingly well even 
with just the 64bit hash it produces.


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


Re: Serial & reset of the device

2011-07-08 Thread Tim Chase

On 07/08/2011 02:45 AM, Tim Roberts wrote:

yorick  wrote:

I'm trying to access a hardware board of my company through a serial
connection using a Python script and the pyserial module.

The board to which I'm trying to connect works correctly with serial
as some other guys did some TCL scripts to manage it.
My problem is that every time I open a new connection, the device is
reset. I'd like to not have the device reset.


I'm not sure what that means.  The RS-232 standard does not have the
concept of "reset".  What is it that triggers a device reset?


While not a "reset" per-se, it might be triggered by the RTS/CTS, 
DSR/DTR, or carrier-detect pins depending on the configuration. 
Without the code and with minimal pySerial experience, I don't 
know whether opening a serial-port in pySerial automatically 
lights up one of those aux. lines and unsignals it when the 
connection is closed.  If the device expects a "power on" signal 
on one of those pins, I'd start by looking to see if pySerial's 
.close() drops the signal on those pins and if it offers a way to 
keep the signal high while releasing the port.  Otherwise, you 
may have to open once, do all your work and only close the port 
when you're done (and the device can be reset)


-tkc


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


Re: Does hashlib support a file mode?

2011-07-08 Thread Phlip
On Jul 8, 12:42 am, Steven D'Aprano  wrote:
> Phlip wrote:
> >> I worded that poorly. None is (AFAIK) the only instance of NoneType, but
> >> I should've clarified the difference.> The is operator does not compare
> >> types, it compares instances for identity.
>
> > None is typesafe, because it's strongly typed.
>
> Everything in Python is strongly typed. Why single out None?

You do understand these cheap shots are bad for conversations, right?

I didn't single out None. When did you stop raping your mother?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serial & reset of the device

2011-07-08 Thread Grant Edwards
On 2011-07-08, Tim Chase  wrote:
> On 07/08/2011 02:45 AM, Tim Roberts wrote:
>> yorick  wrote:
>>> I'm trying to access a hardware board of my company through a serial
>>> connection using a Python script and the pyserial module.
>>>
>>> The board to which I'm trying to connect works correctly with serial
>>> as some other guys did some TCL scripts to manage it. My problem is
>>> that every time I open a new connection, the device is reset. I'd
>>> like to not have the device reset.
>>
>> I'm not sure what that means.  The RS-232 standard does not have the
>> concept of "reset".  What is it that triggers a device reset?
>
> While not a "reset" per-se, it might be triggered by the RTS/CTS, 
> DSR/DTR, or carrier-detect pins depending on the configuration.
> Without the code and with minimal pySerial experience, I don't 
> know whether opening a serial-port in pySerial automatically 
> lights up one of those aux. lines and unsignals it when the 
> connection is closed.

On Unix, the serial port device driver generally turns DTR and RTS off
when a port is closed and turns them on when it's opened.  I don't
know what Windows does.  A quick glance through the pyserial sources
shows that it turns on DTR and RTS when a port is opened, and does
nothing with them when a port is closed.

If you need RTS/DTR to stay in a known state, then open the port, set
them to the state you want them, and keep the port open.

-- 
Grant Edwards   grant.b.edwardsYow! Remember, in 2039,
  at   MOUSSE & PASTA will
  gmail.combe available ONLY by
   prescription!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding duplicated photo

2011-07-08 Thread TheSaint
Billy Mays wrote:

> It worked surprisingly well even
> with just the 64bit hash it produces.
> 
I'd say that comparing 2 images reduced upto 32x32 bit seems too little to 
find if one of the 2 portrait has a smile referred to the other.
I think it's about that mine and your suggestion are similar, but I'd like 
to scale pictures not less than 256x256 pixel.
Also to take a wider case which the comparison involve a rotated image.

-- 
goto /dev/null
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding duplicated photo

2011-07-08 Thread Billy Mays

On 07/08/2011 10:14 AM, TheSaint wrote:

Billy Mays wrote:


It worked surprisingly well even
with just the 64bit hash it produces.


I'd say that comparing 2 images reduced upto 32x32 bit seems too little to
find if one of the 2 portrait has a smile referred to the other.
I think it's about that mine and your suggestion are similar, but I'd like
to scale pictures not less than 256x256 pixel.
Also to take a wider case which the comparison involve a rotated image.



Originally I thought the same thing.  It turns out that doing a DCT on 
an image typically moves the more important data to the top left corner 
of the output.  This means that most of the other data in the output an 
be thrown away since most of it doesn't significantly affect the image. 
 The 32x32 is an arbitrary size, you can make it any square block that 
you want.


Rotation is harder to find.  You can always take a brute force approach 
by simply rotating the image a couple of times and try running the 
algorithm on each of the rotated pics.  Image matching is a difficult 
problem.


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


Re: making socket.getaddrinfo use cached dns

2011-07-08 Thread high bandwidth
my /etc/resolv.conf says:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by
> resolvconf(8)
> # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
> nameserver 127.0.0.1
> search Dynex
>

But getaddrinfo still takes a lot of time for repeated queries. After
installing BIND9 and starting it, getaddrinfo is almost instantaneous for
repeated queries.

Thanks!


*Chris Angelico* rosuav at gmail.com

wrote:

On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth http://mail.python.org/mailman/listinfo/python-list>>
wrote:
>* I use cached dns lookups with pdnsd on my ubuntu machine to speed up web*>* 
>access as regular lookups can take 15-30 seconds. However, python's*>* 
>mechanize and urllib etc use socket.getaddrinfo, which seems not to be 
>using*>* dns cacheing or taking a long time because of ipv6 lookups. In either 
>case,*>* I subsequent access to the same site to be fast and not require 
>lengthy*>* calls to getaddrinfo. How can I get python to correctly use cached 
>dns*>* lookups and ipv4 only (at least in those cases where it is 
>appropriate).*
One solution would be to do your own DNS lookups and then pass urllib
an IP address. Is pdnsd set up to be your computer's primary resolver?
(Is /etc/resolv.conf pointing to localhost?) If not, that might help.
I've generally done my DNS caching using BIND, so I can't help with
pdnsd specifically.

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


Re: Python-list Digest, Vol 94, Issue 52

2011-07-08 Thread Mapere Ali
Hi,

I need help with a python script to monitor my wireless router
internet usage using a Mac address and then backup the report files on
the server. i would also like to create login access on the website to
have users checkout their bandwidth usage...Please help anyone
I'm a newbie in Python..

Regards
mapere

I'v
On 7/8/11, python-list-requ...@python.org
 wrote:
> Send Python-list mailing list submissions to
>   python-list@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/python-list
> or, via email, send a message with subject or body 'help' to
>   python-list-requ...@python.org
>
> You can reach the person managing the list at
>   python-list-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-list digest..."
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 94, Issue 52

2011-07-08 Thread Thomas Jollans
On 07/08/2011 04:45 PM, Mapere Ali wrote:
> Hi,
> 
> I need help with a python script to monitor my wireless router
> internet usage using a Mac address and then backup the report files on
> the server. i would also like to create login access on the website to
> have users checkout their bandwidth usage...Please help anyone
> I'm a newbie in Python..

Try doing it yourself. Give it your best shot, one step at a time.

Depending on how new you are to Python, you might want to go through a
tutorial before embarking on your own project.

The Python documentation (this will be very useful) is here:
http://doc.python.org/

When you get stuck, come back here, show us what you've done and what
the problem is, and we can help you with your (specific) problem.

Also, if you ask questions here, you'll want to be able to respond to
individual answers, so please subscribe to the actual list, not the digest.

Have fun
Thomas

> 
> Regards
> mapere
> 
> I'v
> On 7/8/11, python-list-requ...@python.org
>  wrote:
>> Send Python-list mailing list submissions to
>>  python-list@python.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>  http://mail.python.org/mailman/listinfo/python-list
>> or, via email, send a message with subject or body 'help' to
>>  python-list-requ...@python.org
>>
>> You can reach the person managing the list at
>>  python-list-ow...@python.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Python-list digest..."
>>

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


Re: Finding duplicated photo

2011-07-08 Thread Thomas Jollans
On 07/08/2011 01:29 PM, TheSaint wrote:
> Hello,
> 
> I came across the problem that Gwenview moves the photo from the camera 
> memory by renaming them, but later I forgot which where moved.
> Then I tought about a small script in python, but I stumbled upon my 
> ignorance on the way to do that.
> 
> PIL can find similar pictures. I was thinking to reduce the foto into gray 
> scale and resize them to same size, what algorithm should take place?
> Is PIL able to compare 2 images?
>  

If Gwenview simply moves/renames the images, is it not enough to compare
the actual files, byte by byte?

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


Re: Finding duplicated photo

2011-07-08 Thread Dan Stromberg
On Fri, Jul 8, 2011 at 8:16 AM, Thomas Jollans  wrote:

> On 07/08/2011 01:29 PM, TheSaint wrote:
> > Hello,
> >
> > I came across the problem that Gwenview moves the photo from the camera
> > memory by renaming them, but later I forgot which where moved.
> > Then I tought about a small script in python, but I stumbled upon my
> > ignorance on the way to do that.
> >
> > PIL can find similar pictures. I was thinking to reduce the foto into
> gray
> > scale and resize them to same size, what algorithm should take place?
> > Is PIL able to compare 2 images?
> >
>
> If Gwenview simply moves/renames the images, is it not enough to compare
> the actual files, byte by byte?
>

This'll detect duplicates pretty fast; it often doesn't even need to read a
whole file once, while not sacrificing accuracy:

http://stromberg.dnsalias.org/~dstromberg/equivalence-classes.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding duplicated photo

2011-07-08 Thread Dave Angel

On 01/-10/-28163 02:59 PM, TheSaint wrote:

Hello,

I came across the problem that Gwenview moves the photo from the camera
memory by renaming them, but later I forgot which where moved.
Then I tought about a small script in python, but I stumbled upon my
ignorance on the way to do that.

PIL can find similar pictures. I was thinking to reduce the foto into gray
scale and resize them to same size, what algorithm should take place?
Is PIL able to compare 2 images?

If your real problem is identifying a renamed file amongst thousands of 
others, why not just compare the metadata?  it'll be much faster.


For example, if you only have one camera, the timestamp stored in the 
EXIF data would be pretty close,  Some cameras also store their "shutter 
release number" in the metadata, which would be even better.


One concern is whether Glenview or any other of your utilities discard 
the metadata.  That would be a big mistake.


Also, if Gwenview has no other features you're counting on, perhaps you 
should write your own "move the files from camera to computer" utility.  
that's what I did, and it renames and reorganises the files as it does, 
according to my conventions, not someone else's.  One reason for the 
renaming is that my cameras only use 4 digit numbers, and these recycle 
every 1 images.


DaveA



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


ANN: ActivePython 2.7.2.5 is now available

2011-07-08 Thread Sridhar Ratnakumar
ActiveState is pleased to announce ActivePython 2.7.2.5, a complete, 
ready-to-install binary distribution of Python 2.7.

  http://www.activestate.com/activepython/downloads


What's New in ActivePython-2.7.2.5
==

New Features & Upgrades
---

- Upgrade to Python 2.7.2 (`release notes
  `__)
- Security upgrade to openssl-0.9.8r
- [Windows] Upgrade to PyWin32 CVS snapshot as of 2011-01-16
- Upgrade to pythonselect 1.3 which supports Windows
- Upgrade to PyPM 1.3.4:

  - [Windows] `Bug #89474 `_:
automatically expand %APPDATA%\Python\Scripts
  - Bug #90382: --no-ignore option to fail immediately for missing packages


- Upgraded the following packages:

  - Distribute-0.6.19
  - pip-1.0.1
  - virtualenv-1.6.1

Noteworthy Changes & Bug Fixes
--

- PyPM:

  - Upgrade to six 1.0.0
  - Bug #89540: `uninstall` command now properly removes symlinks
  - Bug #89648: shebang fixer skips symlinks 
  - Include SQLAlchemy in the private area (pypm/external/{2,3}/sqlalchemy)


What is ActivePython?
=

ActivePython is ActiveState's binary distribution of Python. Builds for 
Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX 
builds, and access to older versions are available in ActivePython Business, 
Enterprise and OEM editions:

  http://www.activestate.com/python

ActivePython includes the Python core and the many core extensions: zlib and 
bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) 
database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for 
Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for 
low-level library access, and others. The Windows distribution ships with 
PyWin32 -- a suite of Windows tools developed by Mark Hammond, including 
bindings to the Win32 API and Windows COM.

ActivePython also includes a binary package manager for Python (PyPM) that can 
be used to install packages much easily. For example:

  C:\>pypm install numpy
  [...]

  C:\>python
  >>> import numpy.linalg
  >>>

See this page for full details:

  http://docs.activestate.com/activepython/2.7/whatsincluded.html

As well, ActivePython ships with a wealth of documentation for both new and 
experienced Python programmers. In addition to the core Python docs, 
ActivePython includes the "What's New in Python" series, "Dive into Python", 
the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs).

An online version of the docs can be found here:

  http://docs.activestate.com/activepython/2.7/

We would welcome any and all feedback to:

  activepython-feedb...@activestate.com

Please file bugs against ActivePython at:

  http://bugs.activestate.com/enter_bug.cgi?product=ActivePython

Supported Platforms
===

ActivePython is available for the following platforms:

- Windows (x86 and x64)
- Mac OS X (x86 and x86_64; 10.5+)
- Linux (x86 and x86_64)

- Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only)
- Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only)
- HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only)
- HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only)
- AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only)

More information about the Business Edition can be found here:

  http://www.activestate.com/business-edition

Custom builds are available in the Enterprise Edition:

  http://www.activestate.com/enterprise-edition

Thanks, and enjoy!

The Python Team

--
Sridhar Ratnakumar
sridharr at activestate.com
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: ActivePython 2.6.7.20 is now available

2011-07-08 Thread Sridhar Ratnakumar
ActiveState is pleased to announce ActivePython 2.6.7.20, a complete, 
ready-to-install binary distribution of Python 2.6.

  http://www.activestate.com/activepython/downloads


What's New in ActivePythonEE-2.6.7.20
=

New Features & Upgrades
---

- Upgrade to Python 2.6.7 (`release notes
  `__)
- Upgrade to pythonselect 1.3 which supports Windows
- Upgrade to PyPM 1.3.4:

  - [Windows] `Bug #89474 `_:
automatically expand %APPDATA%\Python\Scripts
  - Bug #90382: --no-ignore option to fail immediately for missing packages
  
- Upgraded the following packages:

  - Distribute-0.6.19
  - pip-1.0.1
  - virtualenv-1.6.1

Noteworthy Changes & Bug Fixes
--

- PyPM:

  - Upgrade to six 1.0.0
  - Bug #89540: `uninstall` command now properly removes symlinks
  - Bug #89648: shebang fixer skips symlinks 


What is ActivePython?
=

ActivePython is ActiveState's binary distribution of Python. Builds for 
Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX 
builds, and access to older versions are available in ActivePython Business, 
Enterprise and OEM editions:

  http://www.activestate.com/python

ActivePython includes the Python core and the many core extensions: zlib and 
bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) 
database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for 
Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for 
low-level library access, and others. The Windows distribution ships with 
PyWin32 -- a suite of Windows tools developed by Mark Hammond, including 
bindings to the Win32 API and Windows COM.

ActivePython also includes a binary package manager for Python (PyPM) that can 
be used to install packages much easily. For example:

  C:\>pypm install numpy
  [...]

  C:\>python
  >>> import numpy.linalg
  >>>

See this page for full details:

  http://docs.activestate.com/activepython/2.6/whatsincluded.html

As well, ActivePython ships with a wealth of documentation for both new and 
experienced Python programmers. In addition to the core Python docs, 
ActivePython includes the "What's New in Python" series, "Dive into Python", 
the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs).

An online version of the docs can be found here:

  http://docs.activestate.com/activepython/2.6/

We would welcome any and all feedback to:

  activepython-feedb...@activestate.com

Please file bugs against ActivePython at:

  http://bugs.activestate.com/enter_bug.cgi?product=ActivePython

Supported Platforms
===

ActivePython is available for the following platforms:

- Windows (x86 and x64)
- Mac OS X (x86 and x86_64; 10.5+)
- Linux (x86 and x86_64)

- Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only)
- Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only)
- HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only)
- HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only)
- AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only)

More information about the Business Edition can be found here:

  http://www.activestate.com/business-edition

Custom builds are available in the Enterprise Edition:

  http://www.activestate.com/enterprise-edition

Thanks, and enjoy!

The Python Team

--
Sridhar Ratnakumar
sridharr at activestate.com
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: ActivePython 2.5.6.10 is now available

2011-07-08 Thread Sridhar Ratnakumar
ActiveState is pleased to announce ActivePython 2.5.6.10, a complete, 
ready-to-install binary distribution of Python 2.5.

  http://www.activestate.com/activepython/downloads


What's New in ActivePython-2.5.6.10
===

New Features & Upgrades
---

- Upgrade to Python 2.5.6 (`release notes
  `__)
- Upgrade to Tcl/Tk 8.5.9 (`changes `_)
- [Windows] Installer upgrade: automatically uninstall previous versions - Bug 
#87783
- [Linux] Include Tcl/Tk development files (`#40`_)
- [Windows] Upgrade to PyWin32 CVS snapshot as of 2011-01-16
- Security upgrade to openssl-0.9.8r

Noteworthy Changes & Bug Fixes
--

- [MacOSX] Fix uninstall on Snow Leopard (10.6)
- Bug #87600: create a `idleX.Y` script on unix
- [Windows] Renamed "python25.exe" to "python2.5.exe" (Unix like)
- [Windows] Include "python2.exe"


What is ActivePython?
=

ActivePython is ActiveState's binary distribution of Python. Builds for 
Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX 
builds, and access to older versions are available in ActivePython Business, 
Enterprise and OEM editions:

  http://www.activestate.com/python

ActivePython includes the Python core and the many core extensions: zlib and 
bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) 
database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for 
Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for 
low-level library access, and others. The Windows distribution ships with 
PyWin32 -- a suite of Windows tools developed by Mark Hammond, including 
bindings to the Win32 API and Windows COM.

ActivePython also includes a binary package manager for Python (PyPM) that can 
be used to install packages much easily. For example:

  C:\>pypm install numpy
  [...]

  C:\>python
  >>> import numpy.linalg
  >>>

See this page for full details:

  http://docs.activestate.com/activepython/2.5/whatsincluded.html

As well, ActivePython ships with a wealth of documentation for both new and 
experienced Python programmers. In addition to the core Python docs, 
ActivePython includes the "What's New in Python" series, "Dive into Python", 
the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs).

An online version of the docs can be found here:

  http://docs.activestate.com/activepython/2.5/

We would welcome any and all feedback to:

  activepython-feedb...@activestate.com

Please file bugs against ActivePython at:

  http://bugs.activestate.com/enter_bug.cgi?product=ActivePython

Supported Platforms
===

ActivePython is available for the following platforms:

- Windows (x86 and x64)
- Mac OS X (x86 and x86_64; 10.5+)
- Linux (x86 and x86_64)

- Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only)
- Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only)
- HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only)
- HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only)
- AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only)

More information about the Business Edition can be found here:

  http://www.activestate.com/business-edition

Custom builds are available in the Enterprise Edition:

  http://www.activestate.com/enterprise-edition

Thanks, and enjoy!

The Python Team

--
Sridhar Ratnakumar
sridharr at activestate.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EVIL!

2011-07-08 Thread rantingrick
On Jul 7, 8:25 pm, Steven D'Aprano  wrote:
> rantingrick wrote:
> > On Jul 7, 12:34 am, Gregory Ewing  wrote:
> >> The important thing is that it's okay for an app to stay
> >> alive until its *last* top level window is closed.
>
> I partially disagree with Greg on this. This is not the only model: on the
> Apple Mac, or any system with a similar GUI design, the application can
> survive having the last window closed. There are other application types
> that don't need any window at all.

Yeah they call those "command line" programs.

> So while it is common for closing the
> last window to exit the application, it is not a necessary requirement.

If a "root-window-hierarchy" type GUI needs to close any or all
windows (or allow the user to do so) it can do this quite well. It's
called logic (in programming circles). But the GUI by default exposes
an interface to the user:

 * Close all windows by clicking the X of the ROOT window.
 * Close any window by clicking the X of THAT window.

However, if (as you argue) you need the program to continue AFTER the
root is closed well then, i have wonderful news for you... THAT CAN BE
DONE!. You just create some logic to handle it. This is very simple
ideas Steven. I am talking about CS 101 here. Do you need a tutor?

> >> There
> >> doesn't have to be a special "main" window that kills the
> >> whole app when you close it.
>
> > So you prefer to close a gazillion windows one by one?
>
> Nonsense. Greg says nothing of the sort.
>
> Avoiding the anti-pattern "close a gazillion windows one by one" is why you
> have an application-wide Quit or Exit command, as opposed to a Close
> command which applies only to the current window.

CRIKEY! That's what the ROOT window does you blankity-blank! Are you
just arguing for the sake of arguing? Just because Apple removed the
root-window's "window-management user-interface" (psst: that's the
three buttons at the top of the root window (Minimize|Maximize|Close))
and nailed them on the desktop does not change anything. You are
comparing a half dozen eggs and six eggs and then claiming them to be
somehow different. There is no comparison!

If i remove the steering wheel from a car and hook up some "remote-
controlled" gearbox to the front wheel linkage how does that
modification change anything about how the CAR itself interfaces with
the road? I just simply moved around some of the interface elements
from a user point of view. Someone is still driving the car; albeit
from a remote location. They can go left, they can go right. And you
claim that this "remote-window management user-interface" has some
magical benefit over the "window-management user-interface". There is
no benefit that is applicable to this argument. The only benefit in my
version is driver safety, however safety is non applicable to this
thread. And i would argue that as the safety of a driver increases the
safety of the general public decreases due to the driver being "once
removed" from the danger zone. Not that "safety" is applicable either.

> > If so, why not
> > just code the GUI correctly from the start; by creating separate
> > transactions? Thereby reducing the number of windows a user must
> > juggle? FYI: You know the user complexity of a GUI increases
> > exponentially by the number of windows present.
>
> Don't assume that there is a one-to-one relationship between transactions
> (documents?) and windows. The relationship is actually many-to-many:
> windows can contain tabbed or notepad interfaces, or can be split into
> multiple panes, or both. Panes and tabs can be split into independent
> windows, or rejoined into one main window.

Of course, and that is exactly why i suggested using a tabbed widget
to an earlier confused GUI designer.

> E.g. I can have six Firefox windows open, each one with many different
> websites open in separate tabs. I have Close Tab, Close Window and Exit
> Firefox commands.

Yes. Firefox itself is the "root" window. Each tab is a transaction.
What is your point? Proving yourself incorrect?

> In Konquorer, not only can I have multiple windows and multiple tabs, but I
> can split each tab into two or more panes, and display two views of the
> same document in the same tab, or two different documents in the one tab.
> This is especially useful when using it as a file manager.

Yes and what has that got to do with "root window hierarchies"?
Nothing! Do you even know which side your arguing for anymore? If you
are trying to support my argument you are doing a good job of it.
Thanks. Keep up the good work.

> In older versions of Word (and possibly current, although I haven't tested
> it) you can open files multiple times. Each time opens in a new window,
> representing a new view of the one file. Edits in one window update all the
> others. This can be useful for, e.g. making edits to page 3 while
> simultaneously viewing page 303. An alternate UI for to split the one
> window into two panes, and scroll them independently. So a

Re: The end to all language wars and the great unity API to come!

2011-07-08 Thread sal migondis
On Jul 6, 7:45 am, Steven D'Aprano  wrote:
> sal migondis wrote:

> > How could a belief be wrong?

> I believe...

Shifting from 'belief' to 'believe', the latter having a considerably
wider semantic scope.

After that, anything goes.. naturally.

> you are a small glass of beer. Are you *actually* a small glass of
> beer in reality? If so, my belief is right. If you are a human being, then
> my belief is wrong.

Are you a lawyer..?

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


Re: The end to all language wars and the great unity API to come!

2011-07-08 Thread Ian Kelly
On Fri, Jul 8, 2011 at 1:05 PM, sal migondis  wrote:
>> I believe...
>
> Shifting from 'belief' to 'believe', the latter having a considerably
> wider semantic scope.

Wider how?  Would you care to give an example of something that is
believed but is not a belief?
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: psutil 0.3.0 released

2011-07-08 Thread Giampaolo Rodolà
Hi folks,
I'm pleased to announce the 0.3.0 release of psutil:
http://code.google.com/p/psutil

=== Major enhancements ===

* disk usage
* mounted disk partitions
* system per-cpu percentage utilization and times
* per-process terminal
* physical and virtual memory usage including percentage

=== New features by example ===

>>> import psutil
>>>
>>> for x in range(3):
... psutil.cpu_percent(percpu=True)
...
[4.0, 34.2]
[7.0, 8.5]
[1.2, 9.0]
>>>
>>> psutil.phymem_usage()
usage(total=4153868288, used=2854199296, free=1299668992, percent=34.6)
>>> psutil.virtmem_usage()
usage(total=2097147904, used=4096, free=2097143808, percent=0.0)
>>>
>>> psutil.get_partitions()
[partition(device='/dev/sda3', mountpoint='/', fstype='ext4'),
 partition(device='/dev/sda7', mountpoint='/home', fstype='ext4')]
>>>
>>> psutil.disk_usage('/')
usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)
>>>
>>>
>>> psutil.Process(os.getpid()).terminal
'/dev/pts/0'
>>>


Also, a new examples directory showing some examples usages:
http://code.google.com/p/psutil/source/browse/#svn%2Ftrunk%2Fexamples

For a complete list of features and bug fixes see:
http://psutil.googlecode.com/svn/trunk/HISTORY


=== Links ===

* Home page: http://code.google.com/p/psutil
* Source tarball: http://psutil.googlecode.com/files/psutil-0.3.0.tar.gz
* Api Reference: http://code.google.com/p/psutil/wiki/Documentation


Please try out this new release and let me know if you experience any
problem by filing issues on the bug tracker.
Thanks in advance.


--- Giampaolo Rodola'

http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/
-- 
http://mail.python.org/mailman/listinfo/python-list


String concatenation vs. string formatting

2011-07-08 Thread Andrew Berg
Is it bad practice to use this
> logger.error(self.preset_file + ' could not be stored - ' +
> sys.exc_info()[1])
Instead of this?
> logger.error('{file} could not be stored -
> {error}'.format(file=self.preset_file, error=sys.exc_info()[1]))


Other than the case where a variable isn't a string (format() converts
variables to strings, automatically, right?) and when a variable is used
a bunch of times, concatenation is fine, but somehow, it seems wrong.
Sorry if this seems a bit silly, but I'm a novice when it comes to
design. Plus, there's not really supposed to be "more than one way to do
it" in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-08 Thread John Gordon
In  Andrew Berg 
 writes:

> Is it bad practice to use this
> > logger.error(self.preset_file + ' could not be stored - ' +
> > sys.exc_info()[1])
> Instead of this?
> > logger.error('{file} could not be stored -
> > {error}'.format(file=self.preset_file, error=sys.exc_info()[1]))

> Other than the case where a variable isn't a string (format() converts
> variables to strings, automatically, right?) and when a variable is used
> a bunch of times, concatenation is fine, but somehow, it seems wrong.
> Sorry if this seems a bit silly, but I'm a novice when it comes to
> design. Plus, there's not really supposed to be "more than one way to do
> it" in Python.

Concatenation feels ugly/clunky to me.

I prefer this usage:

  logger.error('%s could not be stored - %s' % \
(self.preset_file, sys.exc_info()[1]))

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: String concatenation vs. string formatting

2011-07-08 Thread Billy Mays

On 07/08/2011 04:18 PM, Andrew Berg wrote:

Is it bad practice to use this

logger.error(self.preset_file + ' could not be stored - ' +
sys.exc_info()[1])

Instead of this?

logger.error('{file} could not be stored -
{error}'.format(file=self.preset_file, error=sys.exc_info()[1]))



Other than the case where a variable isn't a string (format() converts
variables to strings, automatically, right?) and when a variable is used
a bunch of times, concatenation is fine, but somehow, it seems wrong.
Sorry if this seems a bit silly, but I'm a novice when it comes to
design. Plus, there's not really supposed to be "more than one way to do
it" in Python.

If it means anything, I think concatenation is faster.

__TIMES__
a() -  0.09s
b() -  0.09s
c() - 54.80s
d() -  5.50s

Code is below:

def a(v):
out = ""
for i in xrange(100):
out += v
return len(out)

def b(v):
out = ""
for i in xrange(10):
out += v+v+v+v+v+v+v+v+v+v
return len(out)

def c(v):
out = ""
for i in xrange(100):
out = "%s%s" % (out, v)
return len(out)

def d(v):
out = ""
for i in xrange(10):
out = "%s%s%s%s%s%s%s%s%s%s%s" % (out,v,v,v,v,v,v,v,v,v,v)
return len(out)

print "a", a('xx')
print "b", b('xx')
print "c", c('xx')
print "d", d('xx')

import  profile

profile.run("a('xx')")
profile.run("b('xx')")
profile.run("c('xx')")
profile.run("d('xx')")
--
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-08 Thread Benjamin Kaplan
On Fri, Jul 8, 2011 at 1:18 PM, Andrew Berg wrote:

> Is it bad practice to use this
> > logger.error(self.preset_file + ' could not be stored - ' +
> > sys.exc_info()[1])
> Instead of this?
> > logger.error('{file} could not be stored -
> > {error}'.format(file=self.preset_file, error=sys.exc_info()[1]))
>
>
> Other than the case where a variable isn't a string (format() converts
> variables to strings, automatically, right?) and when a variable is used
> a bunch of times, concatenation is fine, but somehow, it seems wrong.
> Sorry if this seems a bit silly, but I'm a novice when it comes to
> design. Plus, there's not really supposed to be "more than one way to do
> it" in Python.
>

String formatting is the One Right Way here. It's fine to use string
concatenation for a few things, but the operation is O(n^2) because each
concat occurs one at a time: Python allocates space for a string the size of
the first 2 things, copies the contents over. Then allocate a string the
size of that string plus the third string and copy the contents over. It can
get pretty slow if you're building a really big string With string
formatting, Python creates a single string large enough to copy all the
formatting arguements in and then copies the contents over once.

Also, string formatting (especially using the new syntax like you are) is
much clearer because there's less noise (the quotes all over the place and
the plusses) and it's better for dealing with internationalization if you
need to do that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-08 Thread Ian Kelly
On Fri, Jul 8, 2011 at 3:23 PM, Benjamin Kaplan
 wrote:
> String formatting is the One Right Way here. It's fine to use string
> concatenation for a few things, but the operation is O(n^2) because each
> concat occurs one at a time: Python allocates space for a string the size of
> the first 2 things, copies the contents over. Then allocate a string the
> size of that string plus the third string and copy the contents over. It can
> get pretty slow if you're building a really big string With string
> formatting, Python creates a single string large enough to copy all the
> formatting arguements in and then copies the contents over once.

This argument doesn't really fly, because a string formatting
operation is typically used as an alternative for a constant number of
concatenations, not O(n) concatenations.  As such, either approach
would be O(n) for a single instance.

In the case that you do need to do O(n) concatenations, it is usually
best to use a StringIO object, or to build a list and then call
str.join.

> Also, string formatting (especially using the new syntax like you are) is
> much clearer because there's less noise (the quotes all over the place and
> the plusses) and it's better for dealing with internationalization if you
> need to do that.

This is the real reason to prefer string formatting over
concatenation.  It's also much less clutter to be able to use the %s
placeholder rather than having to call str() on everything.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-08 Thread Ben Finney
John Gordon  writes:

> I prefer this usage:
>
>   logger.error('%s could not be stored - %s' % \
> (self.preset_file, sys.exc_info()[1]))

That can be improved by learning two things:

* The backslash-linebreak is ugly and fragile, and almost never needed,
  since Python knows to continue a statement if any bracketing syntax
  (parens, brackets, braces, triple quotes, etc.) is still open.

  So you can continue a statement over multiple lines by introducing
  some bracketing syntax at an appropriate place. In this case, you
  don't even need to add any bracketing syntax, since the function
  parens are still open.

* The ‘%’ string formatting operator is superseded in current Python
  versions by the more flexible ‘format’ method of string objects.

So:

logger.error(
'{0} could not be stored - {1}'.format(
(self.preset_file, sys.exc_info()[1]))

I usually prefer to use named placeholders instead of positional, but
this duplicates your original.

-- 
 \   “We have clumsy, sputtering, inefficient brains…. It is a |
  `\ *struggle* to be rational and objective, and failures are not |
_o__) evidence for an alternative reality.” —Paul Z. Myers, 2010-10-14 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-08 Thread Ben Finney
Andrew Berg  writes:

> Is it bad practice to use this
> > logger.error(self.preset_file + ' could not be stored - ' +
> > sys.exc_info()[1])

This is not necessarily bad practice, but there are not many points in
its favour. It's inflexible and makes the eventual formatting harder to
discern.

> Instead of this?
> > logger.error('{file} could not be stored -
> > {error}'.format(file=self.preset_file, error=sys.exc_info()[1]))

With the caveat that the formatting of that line should be using PEP 8
indentation for clarity:

logger.error(
'{file} could not be stored - {error}'.format(
file=self.preset_file, error=sys.exc_info()[1]))

> Other than the case where a variable isn't a string (format() converts
> variables to strings, automatically, right?)

If you don't specify a conversion in the placeholder, it will default to
‘str’, yes.

> and when a variable is used a bunch of times, concatenation is fine,

I don't see any argument for concatenation there; using a variable a
bunch of times works just fine with the ‘format’ method.

> but somehow, it seems wrong. Sorry if this seems a bit silly, but I'm
> a novice when it comes to design. Plus, there's not really supposed to
> be "more than one way to do it" in Python.

There is often more than one way to do it. The Zen of Python is explicit
that there should be one obvious way to do it (and preferably only one).

The “OOW” in “TOOWTDI” is not “only one way”, but “one obvious way”.

The presence of multiple ways to format strings (the ‘%’ operator, the
‘format’ method) is for backward compatibility with code written before
the current recommended ‘format’ method.

Backward compatibility is a common reason for more than one way to do it
in Python. It's just preferable that all but one of them should be
non-obvious :-)

-- 
 \“The whole area of [treating source code as intellectual |
  `\property] is almost assuring a customer that you are not going |
_o__)   to do any innovation in the future.” —Gary Barnett |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-08 Thread Dan Stromberg
On Fri, Jul 8, 2011 at 3:50 PM, Ben Finney wrote:

> * The ‘%’ string formatting operator is superseded in current Python
>  versions by the more flexible ‘format’ method of string objects.
>

AFAIK, % formatting is the only kind of formatting that works portably
across all of CPythons 2.5, 2.6, 2.7, 3.0,  3.1, 3.2; Pypy and Jython.

So I'm still writing new code using %.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-08 Thread Ben Finney
Ben Finney  writes:

> logger.error(
> '{0} could not be stored - {1}'.format(
> (self.preset_file, sys.exc_info()[1]))
>
> I usually prefer to use named placeholders instead of positional, but
> this duplicates your original.

Ah, I see that the OP *did* use named placeholders. So, even better:

logger.error(
'{file} could not be stored - {error}'.format(
file=self.preset_file, error=sys.exc_info()[1]))

-- 
 \  “Those who write software only for pay should go hurt some |
  `\ other field.” —Erik Naggum, in _gnu.misc.discuss_ |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-08 Thread Andrew Berg
On 2011.07.08 05:59 PM, Ben Finney wrote:
> With the caveat that the formatting of that line should be using PEP 8
> indentation for clarity:
PEP 8 isn't bad, but I don't agree with everything in it. Certain lines
look good in chunks, some don't, at least to me. It's quite likely I'm
going to be writing 98%, if not more, of this project's code, so what
looks good to me matters more than a standard (as long as the code
works). Obviously, if I need to work in a team, then things change.
> > and when a variable is used a bunch of times, concatenation is fine,
I prefaced that sentence with "Other than the case", as in "except for
the following case(s)".
> There is often more than one way to do it. The Zen of Python is explicit
> that there should be one obvious way to do it (and preferably only one).
I meant in contrast to the idea of intentionally having multiple ways to
do something, all with roughly equal merit.



On 2011.07.08 04:38 PM, Ian Kelly wrote:
> Also, string formatting (especially using the new syntax like you are)
> is much clearer because there's less noise (the quotes all over the
> place and the plusses)
I don't find it that much clearer unless there are a lot of chunks.
> and it's better for dealing with internationalization if you need to
> do that.
I hadn't thought of that. That's probably the best reason to use string
formatting.


Thanks, everyone.
-- 
http://mail.python.org/mailman/listinfo/python-list


CI and BDD with Python

2011-07-08 Thread mark curphey
Moving to Python from Ruby, first time poster. 

Anyone any opinions (non-religious) on investing time in Lettuce 
(www.lettuce.it) or Freshen (https://github.com/rlisagor/freshen#readme) for 
their BDD ?

And for CI having been using Hudson for a while, any real advantages in a 
Python / Django world for adopting something native like Trac and one of the CI 
plugins like Bitten?

Cheers!

Mark

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


meaning of numpy.fft coefficients

2011-07-08 Thread Joey
the list generated by numpy is of form [ a+bi, c+di, ...]

could anybody tell me the meaning of the coefficients a and b? I am
very confused about fourier transform!

information provided by numpy reference says Ak = Sum  of a[m] *
exp{-2*pi * i * m * k / n} for m from 0 to n-1

Which part is a and which part is b and what is the meaning of each
part?

Thx in adv.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: meaning of numpy.fft coefficients

2011-07-08 Thread Corey Richardson
Excerpts from Joey's message of Fri Jul 08 20:14:29 -0400 2011:
> the list generated by numpy is of form [ a+bi, c+di, ...]
> 
> could anybody tell me the meaning of the coefficients a and b? I am
> very confused about fourier transform!
> 

a+bi is a typical complex number. a is the real part, b is the imaginary.
Python uses j,

>>> 4+5j
(4+5j)

http://en.wikipedia.org/wiki/Complex_number
http://docs.python.org/library/stdtypes.html#typesnumeric
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-08 Thread Thorsten Kampe
* John Gordon (Fri, 8 Jul 2011 20:23:52 + (UTC))
> I prefer this usage:
> 
>   logger.error('%s could not be stored - %s' % \
> (self.preset_file, sys.exc_info()[1]))

The syntax for formatting logging messages according to the 
documentation is:

Logger.error(msg, *args) 

NOT

Logger.error(msg % (*args)) 

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


Re: CI and BDD with Python

2011-07-08 Thread Stefan Behnel

mark curphey, 09.07.2011 01:41:

And for CI having been using Hudson for a while, any real advantages in a 
Python / Django world for adopting something native like Trac and one of the CI 
plugins like Bitten?


I warmly recommend Jenkins (i.e. Hudson) for anything CI. It gives you tons 
of plugins and configuration options together with full information 
awareness about your build status and dependencies through a nice web 
interface.


The only reason to go native here is that it may become simpler to set up 
Python build and test jobs. But given that it's usually just a couple of 
shell commands that you write once, you'd miss more from the interface than 
what you gain from a quicker job setup.


Stefan

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


Re: Implicit initialization is EVIL!

2011-07-08 Thread Steven D'Aprano
rantingrick wrote:

> On Jul 7, 8:25 pm, Steven D'Aprano  +comp.lang.pyt...@pearwood.info> wrote:
>> rantingrick wrote:
>> > On Jul 7, 12:34 am, Gregory Ewing  wrote:
>> >> The important thing is that it's okay for an app to stay
>> >> alive until its *last* top level window is closed.
>>
>> I partially disagree with Greg on this. This is not the only model: on
>> the Apple Mac, or any system with a similar GUI design, the application
>> can survive having the last window closed. There are other application
>> types that don't need any window at all.
> 
> Yeah they call those "command line" programs.

Only idiots who don't understand that Graphical User Interface does not
equal Window.

I'm done with this conversation. Welcome to Killfile City, population
rantingrick.

See you in a few months. Try to have grown up by then.




-- 
Steven

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


Re: Does hashlib support a file mode?

2011-07-08 Thread Steven D'Aprano
Phlip wrote:

> On Jul 8, 12:42 am, Steven D'Aprano  +comp.lang.pyt...@pearwood.info> wrote:
>> Phlip wrote:
>> >> I worded that poorly. None is (AFAIK) the only instance of NoneType,
>> >> but I should've clarified the difference.> The is operator does not
>> >> compare types, it compares instances for identity.
>>
>> > None is typesafe, because it's strongly typed.
>>
>> Everything in Python is strongly typed. Why single out None?
> 
> You do understand these cheap shots are bad for conversations, right?
> 
> I didn't single out None. 

Phlip, I'm not an idiot, please don't pee on my leg and tell me it's
raining. In the very sentence you quote above, you clearly and obviously
single out None:

"None is typesafe, because it's strongly typed."

Yes, None is strongly typed -- like everything else in Python. I don't
understand what point you are trying to make. Earlier you claimed that
identity testing for None is type-unsafe (or at least *less* type-safe,
whatever that means):

"Note the fix also avoids comparing to None, which, as usual, is also icky
and less typesafe!"

then you say None is type-safe -- if there is a coherent message in your
posts, it is too cryptic for me.


> When did you stop raping your mother? 

What makes you think I've stopped?



-- 
Steven

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


Re: String concatenation vs. string formatting

2011-07-08 Thread Steven D'Aprano
Andrew Berg wrote:

> Is it bad practice to use this
>> logger.error(self.preset_file + ' could not be stored - ' +
>> sys.exc_info()[1])
> Instead of this?
>> logger.error('{file} could not be stored -
>> {error}'.format(file=self.preset_file, error=sys.exc_info()[1]))
> 
> 
> Other than the case where a variable isn't a string (format() converts
> variables to strings, automatically, right?) 

Not exactly, but more or less. format() has type codes, just like % string
interpolation:


>>> '{0:d}'.format(1)
'1'
>>> '{0:d}'.format(None)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: Unknown format code 'd' for object of type 'str'

>>> '%d' % 1
'1'
>>> '%d' % None
Traceback (most recent call last):
  File "", line 1, in 
TypeError: %d format: a number is required, not NoneType

If you don't give a type code, format converts any object to string (if
possible).


> and when a variable is used 
> a bunch of times, concatenation is fine, but somehow, it seems wrong.

I don't like long chains of string concatenation, but short chains seem okay
to me. One or two plus signs seems fine to my eyes, three at the most. Any
more than that, I'd look at replacing it with % interpolation, the
str.join() idiom, the string.Template class, or str.format. 

That's five ways of building strings.

Of course, *repeated* string concatenation risks being slow -- not just a
little slow, but potentially MASSIVELY slow, hundreds or thousands of times
slower that alternatives. Fortunately recent versions of CPython tend to
avoid this (which makes it all the more mysterious when the slow-down does
strike), but other Pythons like Jython and IronPython may not. So it's best
to limit string concatenation to one or two strings.

And finally, if you're concatenating string literals, you can use implicit
concatenation (*six* ways):

>>> s = ("hello "
...  "world"
...  "!")
>>> s
'hello world!'


> Sorry if this seems a bit silly, but I'm a novice when it comes to
> design. Plus, there's not really supposed to be "more than one way to do
> it" in Python.

On the contrary -- there are many different examples of "more than one way
to do it". The claim that Python has "only one way" to do things comes from
the Perl community, and is wrong.

It is true that Python doesn't deliberately add multiple ways of doing
things just for the sake of being different, or because they're cool,
although of course that's a subjective judgement. (Some people think that
functional programming idioms such as map and filter fall into that
category, wrongly in my opinion.) In any case, it's clear that Python
supports many ways of doing "the same thing", not all of which are exactly
equivalent:

# e.g. copy a list
blist = list(alist)
blist = alist[:]
blist[:] = alist  # assumes blist already exists
blist = copy.copy(alist)
blist = copy.deepcopy(alist)
blist = []; blist.extend(alist)
blist = [x for x in alist]  # don't do this


Hardly "only one way" :)



-- 
Steven

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


Re: String concatenation vs. string formatting

2011-07-08 Thread Steven D'Aprano
Billy Mays wrote:

> If it means anything, I think concatenation is faster.

You are measuring the speed of an implementation-specific optimization.
You'll likely get *very* different results with Jython or IronPython, or
old versions of CPython, or even if you use instance attributes instead of
local variables.

It also doesn't generalise: only appends are optimized, not prepends.

Worse, the optimization can be defeated by accidents of your operating
system's memory management, so code that runs snappily and fast on one
machine will run SLLLOOWWWLY on another.

This is not a hypothetical risk. People have been burned by this in real
life:

http://www.gossamer-threads.com/lists/python/dev/771948

If you're interested in learning about the optimization:

http://utcc.utoronto.ca/~cks/space/blog/python/ExaminingStringConcatOpt




-- 
Steven

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


Re: String concatenation vs. string formatting

2011-07-08 Thread Ian Kelly
On Fri, Jul 8, 2011 at 11:30 PM, Steven D'Aprano
 wrote:
> Billy Mays wrote:
>
>> If it means anything, I think concatenation is faster.
>
> You are measuring the speed of an implementation-specific optimization.
> You'll likely get *very* different results with Jython or IronPython, or
> old versions of CPython, or even if you use instance attributes instead of
> local variables.
>
> It also doesn't generalise: only appends are optimized, not prepends.

Indeed:

$ python -m timeit -s "v = 'x' * 10; out = ''" "out = out + v"
100 loops, best of 3: 6.59 usec per loop

$ python -m timeit -s "v = 'x' * 10; out = ''" "out = v + out"
10 loops, best of 3: 268 usec per loop

Good to know.  I had no idea such an optimization existed.

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


Re: String concatenation vs. string formatting

2011-07-08 Thread Chris Angelico
On Sat, Jul 9, 2011 at 3:30 PM, Steven D'Aprano
 wrote:
> It also doesn't generalise: only appends are optimized, not prepends.
>
> If you're interested in learning about the optimization:
>
> http://utcc.utoronto.ca/~cks/space/blog/python/ExaminingStringConcatOpt

>From that page:
"Also, this is only for plain (byte) strings, not for Unicode strings;
as of Python 2.4.2, Unicode string concatenation remains
un-optimized."

Has the same optimization been implemented for Unicode? The page
doesn't mention Python 3 at all, and I would guess that the realloc
optimization would work fine for both types of string.

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


Re: String concatenation vs. string formatting

2011-07-08 Thread Ian Kelly
On Sat, Jul 9, 2011 at 12:16 AM, Chris Angelico  wrote:
> Has the same optimization been implemented for Unicode? The page
> doesn't mention Python 3 at all, and I would guess that the realloc
> optimization would work fine for both types of string.

Seems to be implemented for strs in 3.2, but not unicode in 2.7.
-- 
http://mail.python.org/mailman/listinfo/python-list