HTSQL 2.1-RC1 : A Query Language for the Accidental Programmer

2011-06-23 Thread Clark C. Evans
We'd like to announce the release candidate for
HTSQL 2.1, a high-level query language and web
service gateway for relational databases. HTSQL 
is specifically designed for analytical inquiries 
and targeted to data analysts and web developers.  

HTSQL is implemented as a WSGI component, works
with PostgreSQL, MySQL, SQLite and could be used
to embed ad-hoc reporting features into your
Python application.

Homepage: http://htsql.org
Download: http://pypi.python.org/pypi/HTSQL/
Source: http://bitbucket.org/prometheus/htsql

Since 2.0 release, announced in February, we added many
new language features which increase the query power
of the language.  HTSQL is now able to express quite 
sophisticated business inquiries. 

The 2.2 release of HTSQL later this year will be
focused on usability.  It'll include improved
configuration, a query editor and formatting options.

Also for this release we've cleaned up the homepage
for HTRAF -- a javascript toolkit for constructing
attractive dashboards and interactive reports.  This
toolkit is MIT licensed and implemented as a JQuery
plugin.  For more detail, please visit http://htraf.org.

Let's us know if you have any questions!

Clark C. Evans  Kirill Simonov

***
  HTSQL -- A Query Language for the Accidental Programmer
***

HTSQL (Hyper Text Structured Query Language) is a high-level query
language for relational databases.   The target audience for HTSQL is
the accidental programmer -- one who is not a SQL expert, yet needs a
usable, comprehensive query tool for data access and reporting.  

HTSQL is also a web service which takes a request via HTTP, translates
it into a SQL query, executes the query against a relational database,
and returns the results in a format requested by the user agent (JSON,
CSV, HTML, etc.).

Use of HTSQL with open source databases (PostgreSQL, MySQL, SQLite) is
royalty free under BSD-style conditions.  Use of HTSQL with proprietary
database systems (Oracle, Microsoft SQL) requires a commercial license.
See ``LICENSE`` for details.

For installation instructions, see ``INSTALL``.  For list of new
features in this release, see ``NEWS``.  HTSQL documentation is in the
``doc`` directory. 

http://htsql.org/
The HTSQL homepage

http://htsql.org/doc/introduction.html
Get taste of HTSQL

http://htsql.org/doc/tutorial.html
The HTSQL tutorial

http://bitbucket.org/prometheus/htsql
HTSQL source code

irc://irc.freenode.net#htsql
IRC chat in #htsql on freenode

http://lists.htsql.org/mailman/listinfo/htsql-users
The mailing list for users of HTSQL

HTSQL is copyright by Prometheus Research, LLC.  HTSQL is written by
Clark C. Evans c...@clarkevans.com and Kirill Simonov
x...@resolvent.net.

Generous support for HTSQL was provided by the Simons Foundation.
This material is also based upon work supported by the National
Science Foundation under Grant #0944460.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


PySide 1.0.4 - The winter is coming: Python for Qt released!

2011-06-23 Thread Renato Araujo Oliveira Filho
PySide 1.0.4 - The winter is coming: Python for Qt released!
===

The PySide team is proud to announce our monthly release of PySide project.

Major changes
==

PySide now is 100% compatible with squish[1]

About PySide


PySide is the Nokia-sponsored Python Qt bindings project, providing access to
not only the complete Qt 4.7 framework but also Qt Mobility, as well as to
generator tools for rapidly generating bindings for any C++ libraries.

The PySide project is developed in the open, with all facilities you'd expect
from any modern OSS project such as all code in a git repository [2], an open
Bugzilla [3] for reporting bugs, and an open design process [4]. We welcome
any contribution without requiring a transfer of copyright.

List of bugs fixed
==

882 Can't use QApplication without X
881 pyside-lupdate generates incorrect context when a class contains
another class
879 QDoubleSpinBox: Can't call the parent validate() method from a subclass
877 Fatal Python error on application quit
875 Missing underscore.js in uploaded files
874 QApplication.winEventFilter(msg)  not implemented but in docs
872 Squish GUI Tests work with QT  PyQt but not Pyside.
871 Shiboken should prevent custom code on virtual methods to cause
infinite recursion.
870 QStylePainter.drawControl doesn't draw anything
869 QDateTimeEdit initial time problem
868 Returning color value from styleHint() hangs application
865 Apparent reference counting problem with event filters
863 QAbstractFileEngine::beginEntryList isn't exported to Python
862 Problems when printing objects
860 Problems with slot overloads
858 pyside-rcc produces bigger files than pyrcc4
853 MeeGo packages don't contain PySide.QtOpenGL module
827 Anchor sign for headers to copy links for sections
631 QSocketNotifier: Accept file-like object (with .fileno() method)
in constructor
501 Shiboken generator doesn't use full qualified name (with ::
prefix) on all places.
464 Can't create target lang package and namespace with the same name
424 QDockWidget.setTitleBarWidget does not accept 0
292 Rich comparison overload order issues

Download


The files can be downloaded from PySide download page[2]


References
==

[1] http://www.froglogic.com/
[2] http://qt.gitorious.org/pyside
[3] http://bugs.openbossa.org/
[4] http://www.pyside.org/docs/pseps/psep-0001.html
[5] http://developer.qt.nokia.com/wiki/PySideDownloads


PySide Team
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


ANN: ETS 4.0 released

2011-06-23 Thread Ilan Schnell
Hello,

I am happy to announce the release of ETS 4.0.  This is the
first major release of the Enthought Tool Suite in almost
three years.  This release removes the 'enthought' namespace
from all projects.  For example:

from enthought.traits.api import HasTraits

is now simply::

from traits.api import HasTraits

For backwards compatibility, a proxy package 'etsproxy' has
been added, which should permit existing code to work.  For
convenience this package also contains a refactor tool 'ets3to4'
to convert projects to the new namespace (so that they don't
rely on the 'etsproxy' package).

If you want to download the source code of all ETS projects, you
can download http://www.enthought.com/repo/ets/ALLETS-4.0.0.tar (41MB).
The projects themselves are now hosted on: https://github.com/enthought

We understand that the namespace refactor (which prompted this
major release in the first place) is a big change, and even
though we have tested examples and some of our own code against
this ETS version, we expect there to be little glitches.  We are
therefore already planning a 4.0.1 bug-fix release in about 2-3
weeks.

We are looking forward to your feedback (the development mailing list
is enthought-...@enthought.com), and hope you enjoy ETS 4.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-23 Thread Tim Roberts
Mel mwil...@the-wire.com wrote:

It certainly can be done faster.  I ran it against the factor finder that I 
wrote, and it popped up the answer

mwilson@tecumseth:~$ bin/factors.py 600851475143
71 839 1471 ...

before I could glance at my watch.  factors.py works, as does yours, by 
testing for small factors first, but it divides them out as it goes, so it 
tends to do its work on smallish numbers.  And since the smallest factors 
are taken out as soon as possible, they have to be the prime ones.

That's a great hint, and I'm not sure it would have occurred to me on my
own.  Using your hint, I was able to write a 16-line script that also
produced a result instantaneously.  Very satisfying.

I'm going to save that one...
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.7 and cmd on Windows 7 64 (files lost)

2011-06-23 Thread Michel Claveau - MVP
Hi!

(sorry for my bad english...)

On Win 7 64 bits:
  Command-Line
  CD \Python27
  dir C:\Windows\System32\SoundRecorder.exe:== OK
  Python.exe

 import os
 os.system(dir C:\\Windows\\System32\\SoundRecorder.exe)  

== Do not found the file !!!

and os.system(cmd /k)  then  dir C:\Windows\System32\SoundRecorder.exe  do 
not found
anyway.

But:
  {Ctrl-Z} in Python
  then  dir C:\Windows\System32\SoundRecorder.exe  run OK

Therefore, is the problem only in Python? 


@+
-- 
Michel Claveau 

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


Re: python 3 constant

2011-06-23 Thread Waldek M.
Dnia Wed, 22 Jun 2011 22:17:49 +0100, Noah Hall napisał(a):

 On Wed, Jun 22, 2011 at 7:54 PM, sidRo slacky2...@gmail.com wrote:
 How to declare a constant in python 3?
 
 There aren't true constants in Python, but instead we use a standard
 defined by PEP 8, which states constants are in all caps, for example,
 PI = 3.14, as opposed to pi = 3.14 which could change (according to
 PEP 8, that is)

That said, there are some workarounds for that:
http://code.activestate.com/recipes/65207-constants-in-python/?in=user-97991

Still, I'd reallly like to have constants as a built-in...

Best regards,
Waldek
-- 
http://mail.python.org/mailman/listinfo/python-list


Need help about for loop in python 3.2

2011-06-23 Thread kkiranmca
Hi i am new for this version and could please help me .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help about for loop in python 3.2

2011-06-23 Thread Chris Rebert
On Wed, Jun 22, 2011 at 11:50 PM, kkiranmca kkiran...@gmail.com wrote:
 Hi i am new for this version and could please help me .

You didn't pose an actual question...

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


Re: doing cross platform file work

2011-06-23 Thread Gurpreet Singh
File system paths are a thing you need to take care moving from one OS to other.
Perhaps simplest way to avoid this in windows is install cygwin and enjoy.
Keep your accessible files in directories /var or /home which are common (but 
not in something like /cygdrive/c - Cygwin equilvalent of C:) - as such same 
scripts will work in both places
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 constant

2011-06-23 Thread Ben Finney
Waldek M. wm@localhost.localdomain writes:

 Still, I'd reallly like to have constants as a built-in...

If you mean creating a binding which can't be re-bound: −1.

The ability to re-bind any attribute, even ones which the author thought
should be constant, makes writing unit tests much easier. I don't see
that putative benefits of constant bindings would be anywhere near as
valuable.

-- 
 \   “I love and treasure individuals as I meet them, I loathe and |
  `\ despise the groups they identify with and belong to.” —George |
_o__) Carlin, 2007 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help about for loop in python 3.2

2011-06-23 Thread Ben Finney
kkiranmca kkiran...@gmail.com writes:

 Hi i am new for this version and could please help me .

Welcome!

Don't ask whether you can ask. Just ask.

URL:http://catb.org/~esr/faqs/smart-questions.html

-- 
 \ “I put contact lenses in my dog's eyes. They had little |
  `\   pictures of cats on them. Then I took one out and he ran around |
_o__)  in circles.” —Steven Wright |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7 and cmd on Windows 7 64 (files lost)

2011-06-23 Thread Thorsten Kampe
* Michel Claveau - MVP (Thu, 23 Jun 2011 08:33:20 +0200)
 On Win 7 64 bits:
   Command-Line
   CD \Python27
   dir C:\Windows\System32\SoundRecorder.exe:== OK
   Python.exe
 
  import os
  os.system(dir C:\\Windows\\System32\\SoundRecorder.exe)  
 
 == Do not found the file !!!
 
 and os.system(cmd /k)  then  dir C:\Windows\System32\SoundRecorder.exe  
 do not found
 anyway.

This is because 32-bit processes (Python, 32-bit cmd) cannot see the 64-
bit DLLs in System32.
 
 But:
   {Ctrl-Z} in Python
   then  dir C:\Windows\System32\SoundRecorder.exe  run OK

Now you are running 64-bit Cmd.
 
 Therefore, is the problem only in Python? 

Of course not (see above).

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


Re: Python 2.7 and cmd on Windows 7 64 (files lost)

2011-06-23 Thread Tim Golden

On 23/06/2011 07:33, Michel Claveau - MVP wrote:

Hi!

(sorry for my bad english...)

On Win 7 64 bits:
   Command-Line
   CD \Python27
   dir C:\Windows\System32\SoundRecorder.exe:==  OK
   Python.exe


import os
os.system(dir C:\\Windows\\System32\\SoundRecorder.exe)


==  Do not found the file !!!

and os.system(cmd /k)  then  dir C:\Windows\System32\SoundRecorder.exe  do 
not found
anyway.

But:
   {Ctrl-Z} in Python
   then  dir C:\Windows\System32\SoundRecorder.exe  run OK

Therefore, is the problem only in Python?


Certain commands, including dir and copy are not executables
in their own right, but merely subcommands of cmd.exe. You've
got two options in Python:

  os.system (rcmd /c dir c:\windows)

or:

  subprocess.call ([dir, c:\\windows], shell=True)

which basically does it for you behind the scenes.

I hope that helps..

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


Re: User Authentication

2011-06-23 Thread Tim Golden

On 23/06/2011 06:02, Anurag wrote:

On Jun 22, 7:01 pm, Adam Tauno Williamsawill...@whitemice.org
wrote:

On Wed, 2011-06-22 at 06:34 -0700, Anurag wrote:

Hi All,



I am working on application which needs to do a authentication against
LDAP, if LDAP not installed then local system account (administrator
user in windows and root user in Linux). This should work on both
Windows and Linux.


See python-ldap


I looked into python-ldap, it supports ldap authentication. But I
didn't find anything that support local system account authentication
when no LDAP both in windows and Linux.


If you want local system authentication on Windows, you're going
to need something like this:


http://timgolden.me.uk/python/win32_how_do_i/check-a-users-credentials.html


Ond more thing, somebody suggested me to use PAM. Is it a good choice
and whether it supports both Windows and Linux? Please let me know
which is best to use.


I can't speak for Linux, but I can guarantee that PAM won't
take you anywhere on Windows :)

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


Re: Python 2.7 and cmd on Windows 7 64 (files lost)

2011-06-23 Thread Thorsten Kampe
* Tim Golden (Thu, 23 Jun 2011 08:31:26 +0100)
 
 Certain commands, including dir and copy are not executables
 in their own right, but merely subcommands of cmd.exe.

Right, internal commands.

 You've got two options in Python:
 
os.system (rcmd /c dir c:\windows)

os.system automatically runs a shell (cmd) - see the documentation.
 
Thorsten
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7 and cmd on Windows 7 64 (files lost)

2011-06-23 Thread Tim Golden

On 23/06/2011 09:08, Thorsten Kampe wrote:

* Tim Golden (Thu, 23 Jun 2011 08:31:26 +0100)


Certain commands, including dir and copy are not executables
in their own right, but merely subcommands of cmd.exe.


Right, internal commands.


You've got two options in Python:

os.system (rcmd /c dir c:\windows)


os.system automatically runs a shell (cmd) - see the documentation.


Thanks: should have checked my sources before writing :(

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


Re: those darn exceptions

2011-06-23 Thread Gregory Ewing

Chris Torek wrote:


Oops!  It turns out that os.kill() can raise OverflowError (at
least in this version of Python, not sure what Python 3.x does).


Seems to me that if this happens it indicates a bug in
your code. It only makes sense to pass kill() something
that you know to be the pid of an existing process,
presumably one returned by some other system call.

So if kill() raises OverflowError, you *don't* want
to catch and ignore it. You want to find out about it,
just as much as you want to find out about a TypeError,
so you can track down the cause and fix it.

Generally I think some people worry far too much about
anticipating and catching exceptions. Don't do that,
just let them happen. If you come across a *specific*
exception that it makes sense to catch, then catch
just that particular one. Let *everything* else propagate.

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


Re: those darn exceptions

2011-06-23 Thread Steven D'Aprano
On Thu, 23 Jun 2011 06:16 pm Gregory Ewing wrote:

 Generally I think some people worry far too much about
 anticipating and catching exceptions. Don't do that,
 just let them happen. If you come across a specific
 exception that it makes sense to catch, then catch
 just that particular one. Let everything else propagate.

Good advice.

+1


-- 
Steven

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


Re: Python 2.7 and cmd on Windows 7 64 (files lost)

2011-06-23 Thread Michel Claveau - MVP
Re !

 This is because 32-bit processes (Python, 32-bit cmd) cannot see the 
 64-bit DLLs in System32.

Thanks. 
You are right... but it is not enought.

This command:  echo %PROCESSOR_ARCHITECTURE%
give the statut:
   32:  x86
   64:  AMD64

and  DIR C:\Windows\System32\SoundRecorder.exe  is OK in 64, not in 32.



But if, in 64 mode, I copy SoundRecorder.exe to sr.exe, then I rename
sr.exe to sr.txt, the file (which is not an executable) is not visible 
in 32 mode.
And, if I move (or copy) sr.txt in an USB-drive, the file become visible 
in 32 mode !!!???

Therefore, Windows has a trick for mark the file like visible, or not,
in 32 mode. What trick?


OK, it is not a Python problem. 
Then... thanks again for your explanations.


@-salutations
-- 
Michel Claveau 








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


help me in knowing the syntax for loop and switch statements in python 3.2

2011-06-23 Thread mahantesh varavattekar
Hi,

i am new to python please help to let me know the syntax for python
3.2. with examples.
and how can i use these things for ranges
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-23 Thread Slaunger
As a general note concerning the use of Python on Project Euler, and
the one minute guideline.

For problems 1-100, each problem is easily solved in less than 1
minute processing time *if* the algorithms and math is done right
and with thought.

My project Euler scripts solves the first 100 problems with an average
of 0.91 secs/problem on a 4 y old std business Laptop running 32 bit
Win XP. Of these, one problem takes 18 secs.

For some of the later problems it certainly becomes very difficult to
do all problems within 1 minute if you use Python on an ordinary
processing platform. There you need to resort to a compiled language
like C, C++, or dedicated mathematical software packages, which
implement complex mathematical functions using highly efficient native
libraries.

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


Re: writable iterators?

2011-06-23 Thread Thomas 'PointedEars' Lahn
[Sorry for over-quoting, I am not sure how to trim this properly]

Steven D'Aprano wrote:

 On Thu, 23 Jun 2011 09:30 am Thomas 'PointedEars' Lahn wrote:
 Mel wrote:
 Steven D'Aprano wrote:
 I *guess* that what you mean by writable iterators is that rebinding
 e should change seq in place, i.e. you would expect that seq should now
 equal [42, 42]. Is that what you mean? It's not clear.
 
 Fortunately, that's not how it works, and far from being a
 limitation, it would be *disastrous* if iterables worked that way. I
 can't imagine how many bugs would occur from people reassigning to the
 loop variable, forgetting that it had a side-effect of also reassigning
 to the iterable. Fortunately, Python is not that badly designed.
 
 And for an iterator like
 
 def things():
 yield 1
 yield 11
 yield 4
 yield 9
 
 I don't know what it could even mean.
 
 http://docs.python.org/reference/simple_stmts.html#the-yield-statement
 
 You could have tried to debug.
 
 I think you have missed the point of Mel's comment. He knows what the
 yield statement does. He doesn't know what it would mean to write to an
 iterator like things().
 
 Neither do I.

AIUI the OP is referring to write accesses to the iteration variable
(for want of a better term), not being aware what iterators are.

-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help me in knowing the syntax for loop and switch statements in python 3.2

2011-06-23 Thread Laurent Claessens

Le 23/06/2011 11:48, mahantesh varavattekar a écrit :

Hi,

i am new to python please help to let me know the syntax for python
3.2. with examples.
and how can i use these things for ranges


http://lmgtfy.com/?q=python+syntax+range+example

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


Re: help me in knowing the syntax for loop and switch statements in python 3.2

2011-06-23 Thread Ben Finney
mahantesh varavattekar mvaravatte...@gmail.com writes:

 i am new to python please help to let me know the syntax for python
 3.2. with examples.

Welcome!

Please work your way through the Python tutorial from the beginning
URL:http://docs.python.org/release/3.2/tutorial/. Run each example,
experiment with it to understand before proceeding.

-- 
 \ “I call him Governor Bush because that's the only political |
  `\  office he's ever held legally.” —George Carlin, 2008 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 constant

2011-06-23 Thread Waldek M.
Dnia Thu, 23 Jun 2011 17:22:37 +1000, Ben Finney napisał(a):
 If you mean creating a binding which can't be re-bound: −1.

Perhaps. Or perhaps that could be done in some other fashion;
I admit that I usually stick to more strict languages
and while Python's flexibility is great... I'm really missing
constants.

 The ability to re-bind any attribute, even ones which the author thought
 should be constant, makes writing unit tests much easier. I don't see
 that putative benefits of constant bindings would be anywhere near as
 valuable.

Primo, isn't it usually the author that does the unit testing?
Anyway, correct me if I'm wrong but I always thought that unit tests
should prove the correctness and quality of the code under test,
and not the other way around, which would be sacrifising
code security to make testing easier.

Secundo, one can say that re-binding gives the freedom to change
what one likes; I'd say that I'd also like the freedom to decide what
is mutable and what is not.

Of course, it is just my personal opinion. It might be not pythonic,
I may be wrong, yet - concept of constants is not something new and
if other languages, like C/C++/Java/Perl/ (bash even) have them, 
I can't see the reason not to have them in Python.

Best regards,
Waldek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 constant

2011-06-23 Thread Ben Finney
Waldek M. wm@localhost.localdomain writes:

 Dnia Thu, 23 Jun 2011 17:22:37 +1000, Ben Finney napisał(a):

  The ability to re-bind any attribute, even ones which the author
  thought should be constant, makes writing unit tests much easier. I
  don't see that putative benefits of constant bindings would be
  anywhere near as valuable.

 Primo, isn't it usually the author that does the unit testing?

I don't see how that's relevant. I'm referring to run-time re-binding of
attributes, without the need for changing the code.

 Anyway, correct me if I'm wrong but I always thought that unit tests
 should prove the correctness and quality of the code under test,

Right. Which often involves special set up of the environment in which
that code runs, in order to conduct a proper test.

If the test I need to perform involves demonstrating what the code under
test will do with different values for a name you consider constant,
then I have Python's ability to re-bind that name at run-time.

 Secundo, one can say that re-binding gives the freedom to change what
 one likes; I'd say that I'd also like the freedom to decide what is
 mutable and what is not.

And I, as the user of your code, say that you don't get to dictate how I
use it. I will take the authors's recommendations under advisement, but
I reject any authority to restrict what I can do with it.

Unit tests are just an obvious example. The real lesson here is that the
reciient of the code you write can, and probably will, use it in ways
you never expected. It's not for you to decide which of those uses are
permitted.

 Of course, it is just my personal opinion. It might be not pythonic,

Right. One useful phrase to remember from the founder of the Python
language is that “We're all consenting adults here”.

Indicate through the API and its documentation how you recommend I use
your code; but treat me as an adult capable of making my own decisions
about what risks I accept. Understand that I will be using the code you
wrote in the way I see fit.

-- 
 \ “Don't be afraid of missing opportunities. Behind every failure |
  `\ is an opportunity somebody wishes they had missed.” —Jane |
_o__)  Wagner, via Lily Tomlin |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


PyPad 2.7.1 Update 4 (Python on iPad and iPhone)

2011-06-23 Thread Jon Dowdall

Hi All,

I'm pleased to announce that PyPad (Python environment for iOS) 2.7.1 
Update 4 is now available in the iTunes App Store. New in this version 
is the ability to create custom modules. Modules can be independent or 
can include other user modules to build larger frame works.


Plans for future versions include:
Improved cursor handling in interactive mode.
Access to the interactive command history.
Modules to access iOS specific functionality.
Additional documentation.
Syntax highlighting.
Improved script debugging support.

Regards,

Jon

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


LDAP: How get all users belongs to a group.

2011-06-23 Thread sajuptpm
Hi,
How get all users belongs to a group using python ldap module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Project-wide variable...

2011-06-23 Thread Gnarlodious
Is there a way to declare a project-wide variable and use that in all
downstream modules?

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


Re: Project-wide variable...

2011-06-23 Thread Calvin Spealman
No, but you can define a name in one module and import that into others.

On Thu, Jun 23, 2011 at 9:41 AM, Gnarlodious gnarlodi...@gmail.com wrote:
 Is there a way to declare a project-wide variable and use that in all
 downstream modules?

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




-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project-wide variable...

2011-06-23 Thread Noah Hall
On Thu, Jun 23, 2011 at 2:41 PM, Gnarlodious gnarlodi...@gmail.com wrote:
 Is there a way to declare a project-wide variable and use that in all
 downstream modules?

Well, the standard way you should do it is to use import to import a
certain variable - for example -

a.py -

x = 3


from a import x
x
3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LDAP: How get all users belongs to a group.

2011-06-23 Thread Ken Watford
On Thu, Jun 23, 2011 at 9:14 AM, sajuptpm sajup...@gmail.com wrote:
 Hi,
 How get all users belongs to a group using python ldap module.

Depends on what you mean by users and group, what information you
already have, and what information you want to get. I'll assume you
mean posix accounts and groups, and that you already know how to
connect to the LDAP server.

If you already know the distinguished name of the group, you can get a
list of the member names like so (ignoring error handling):

dn, entry = connection.search_s(group_dn, ldap.SCOPE_BASE)[0]
member_list = entry['memberUid']

That will only get you the usernames. If you need to get the user's
entry (or don't know the group_dn above), then you'll have to do a bit
more searching.

To find a user's entry given their uid:

results = connection.search_s(base_dn, ldap.SCOPE_SUBTREE, (uid=*))
for dn, entry in results:
 if uid in entry['uid']:
 # this is your guy. return, or break, or whatever

The (uid=*) filter just means to only find entries that have user id
fields. If you wanted to be more specific about it, you could limit it
to only posixAccount objects with (objectClass=posixAccount). This
would probably be necessary if you wanted to search for groups (via
(objectClass=posixGroup) ), since those don't have a special field
for their name - they usually just use the cn (common name) field for
that. A slightly more complex filter could be written to avoid the
python loop.

If your groups are not posixGroup objects but instead groupOfNames,
then the appropriate attribute is member rather than memberUid,
and the values there are user DNs instead of uids. In that case, if
you need the uid you'll have to look up those users and pull it out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
On Jun 23, 7:59 am, Noah Hall wrote:
 from a import x

I'm doing that:
import Module.Data as Data

However I end up doing it in every submodule, so it seems a little
redundant. I wish I could load the variable in the parent program and
have it be available in all submodules. Am I missing something?

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


Re: Project-wide variable...

2011-06-23 Thread Peter Otten
Gnarlodious wrote:

 On Jun 23, 7:59 am, Noah Hall wrote:
 from a import x
 
 I'm doing that:
 import Module.Data as Data

from Module import Data

There, you saved three more characters .

 However I end up doing it in every submodule, so it seems a little
 redundant. I wish I could load the variable in the parent program and
 have it be available in all submodules. Am I missing something?

You can modify the builtin namespace:

$ cat module.py
print data
$ cat main.py
import __builtin__
__builtin__.data = 42

import module
$ python main.py
42
$

But I don't think it's a good idea. Remember that explicit is better than 
implicit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project-wide variable...

2011-06-23 Thread Noah Hall
On Thu, Jun 23, 2011 at 3:09 PM, Gnarlodious gnarlodi...@gmail.com wrote:
 On Jun 23, 7:59 am, Noah Hall wrote:
 from a import x

 I'm doing that:
 import Module.Data as Data

Well, that's not quite the same. You're using Module.Data as Data - I
guess you've done this because you've realised that import Module
means you still have to write Module.Data every time. But the correct
way to is state exactly which function or object you want - for
example, from Module import Data. Simple, right? I mean, you almost
had it, but it seems like you've gotten a little confused with various
theories.



 However I end up doing it in every submodule, so it seems a little
 redundant. I wish I could load the variable in the parent program and
 have it be available in all submodules. Am I missing something?

Well, generally, if you've got a variable that you need in all your
sub-modules, the chances are that your code infrastructure needs a bit
of reordering (at least, that's what I find in my case). Without
seeing your code, though, I would find it hard to make a judgement on
what you need. Perhaps reading up on the documentation will help -
http://docs.python.org/tutorial/modules.html#packages

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


Re: writable iterators?

2011-06-23 Thread Ian Kelly
On Wed, Jun 22, 2011 at 3:54 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Fortunately, that's not how it works, and far from being a limitation,
 it would be *disastrous* if iterables worked that way. I can't imagine
 how many bugs would occur from people reassigning to the loop variable,
 forgetting that it had a side-effect of also reassigning to the iterable.
 Fortunately, Python is not that badly designed.

The example syntax is a non-starter, but there's nothing wrong with
the basic idea.  The STL of C++ uses output iterators and a quick
Google search doesn't turn up any harmful-style rants about those.

Of course, there are a couple of major differences between C++
iterators and Python iterators.  FIrst, C++ iterators have an explicit
dereference step, which keeps the iterator variable separate from the
value that it accesses and also provides a possible target for
assignment.  You could say that next(iterator) is the corresponding
dereference step in Python, but it is not accessible in a for loop and
it does not provide an assignment target in any case.

Second, C++ iterators separate out the dereference step from the
iterator advancement step.  In Python, both next(iterator) and
generator.send() are expected to advance the iterator, which would be
problematic for creating an iterator that does both input and output.

I don't think that output iterators would be a disaster in Python,
but I also don't see a clean way to add them to the existing iterator
protocol.

 If you want to change the source iterable, you have to explicitly do so.
 Whether you can or not depends on the source:

 * iterators are lazy sequences, and cannot be changed because there's
 nothing to change (they don't store their values anywhere, but calculate
 them one by one on demand and then immediately forget that value);

No, an iterator is an object that allows traversal over a collection
in a manner independent of the implementation of that collection.  In
many instances, especially in Python and similar languages, the
collection is abstracted to an operation over another collection, or
even to the results of a serial computation where there is no actual
collection in memory.

Iterators are not lazy sequences, because they do not behave like
sequences.  You can't index them, you can't reiterate them, you can't
get their length (and before you point out that there are ways of
doing each of these things -- yes, but none of those ways use
sequence-like syntax).  For true lazy sequences, consider the concept
of streams and promises in the functional languages.

In any case, the desired behavior of an output iterator on a source
iterator is clear enough to me.  If the source iterator is also an
output iterator, then it propagates the write to it.  If the source
iterator is not an output iterator, then it raises a TypeError.

 * mutable sequences like lists can be changed. The standard idiom for
 that is to use enumerate:

 for i, e in enumerate(seq):
    seq[i] = e + 42

Unless the underlying collection is a dict, in which case I need to do:

for k, v in d.items():
d[k] = v + 42

Or a file:

for line in f:
# I'm not even sure whether this actually works.
f.seek(-len(line))
f.write(line.upper())

As I said above, iterators are supposed to provide
implementation-independent traversal over a collection.  For writing,
enumerate fails in this regard.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: User Authentication

2011-06-23 Thread Anurag
My application is a web based application for both windows and Linux.
The web part is developed using Django. So if Python does not support
it then any support for local sytem account authentication in Django?

I am looking for a common library for both Linux and Windows. Any help
will be Gr8

Regards,
Anurag

On Jun 23, 12:52 pm, Tim Golden m...@timgolden.me.uk wrote:
 On 23/06/2011 06:02, Anurag wrote:

  On Jun 22, 7:01 pm, Adam Tauno Williamsawill...@whitemice.org
  wrote:
  On Wed, 2011-06-22 at 06:34 -0700, Anurag wrote:
  Hi All,

  I am working on application which needs to do a authentication against
  LDAP, if LDAP not installed then local system account (administrator
  user in windows and root user in Linux). This should work on both
  Windows and Linux.

  See python-ldap

  I looked into python-ldap, it supports ldap authentication. But I
  didn't find anything that support local system account authentication
  when no LDAP both in windows and Linux.

 If you want local system authentication on Windows, you're going
 to need something like this:

 http://timgolden.me.uk/python/win32_how_do_i/check-a-users-credential...

  Ond more thing, somebody suggested me to use PAM. Is it a good choice
  and whether it supports both Windows and Linux? Please let me know
  which is best to use.

 I can't speak for Linux, but I can guarantee that PAM won't
 take you anywhere on Windows :)

 TJG

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


Re: Project-wide variable...

2011-06-23 Thread bruno.desthuilli...@gmail.com
On Jun 23, 4:42 pm, Peter Otten __pete...@web.de wrote:
(snip)
  However I end up doing it in every submodule, so it seems a little
  redundant. I wish I could load the variable in the parent program and
  have it be available in all submodules. Am I missing something?

 You can modify the builtin namespace:
 But I don't think it's a good idea.

Even posting about it is already a bad idea IMHO. There are good
reasons this isn't documented.

@OP: yes, explicit imports are boring... until you have to debug and
maintain the code, and then you start to LOVE them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 constant

2011-06-23 Thread Chris Angelico
On Thu, Jun 23, 2011 at 9:58 PM, Waldek M. wm@localhost.localdomain wrote:
 Of course, it is just my personal opinion. It might be not pythonic,
 I may be wrong, yet - concept of constants is not something new and
 if other languages, like C/C++/Java/Perl/ (bash even) have them,
 I can't see the reason not to have them in Python.


You can have them in Python. Just run your code through cpp (the C
preprocessor) first. Voila!

It's handy for other things too. Don't like Python's lack of then
and end if?

#define then :
#define end(x)

lst=[1,2,3]
if lst then
  do_stuff
end(if)

You can even make functions that take reference arguments!

#define inc(x) x=x+1

i=3
inc(i)
print(i = ,i)
j=4
inc(i+j)
print(i + j = ,i+j

This is an excellent technique, and I heartily recommend it.

Assuming you're writing an entry for the International Obfuscated
Python Code Contest, that is.

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


Re: writable iterators?

2011-06-23 Thread Neal Becker
Ian Kelly wrote:

 On Wed, Jun 22, 2011 at 3:54 PM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
 Fortunately, that's not how it works, and far from being a limitation,
 it would be *disastrous* if iterables worked that way. I can't imagine
 how many bugs would occur from people reassigning to the loop variable,
 forgetting that it had a side-effect of also reassigning to the iterable.
 Fortunately, Python is not that badly designed.
 
 The example syntax is a non-starter, but there's nothing wrong with
 the basic idea.  The STL of C++ uses output iterators and a quick
 Google search doesn't turn up any harmful-style rants about those.
 
 Of course, there are a couple of major differences between C++
 iterators and Python iterators.  FIrst, C++ iterators have an explicit
 dereference step, which keeps the iterator variable separate from the
 value that it accesses and also provides a possible target for
 assignment.  You could say that next(iterator) is the corresponding
 dereference step in Python, but it is not accessible in a for loop and
 it does not provide an assignment target in any case.
 
 Second, C++ iterators separate out the dereference step from the
 iterator advancement step.  In Python, both next(iterator) and
 generator.send() are expected to advance the iterator, which would be
 problematic for creating an iterator that does both input and output.
 
 I don't think that output iterators would be a disaster in Python,
 but I also don't see a clean way to add them to the existing iterator
 protocol.
 
 If you want to change the source iterable, you have to explicitly do so.
 Whether you can or not depends on the source:

 * iterators are lazy sequences, and cannot be changed because there's
 nothing to change (they don't store their values anywhere, but calculate
 them one by one on demand and then immediately forget that value);
 
 No, an iterator is an object that allows traversal over a collection
 in a manner independent of the implementation of that collection.  In
 many instances, especially in Python and similar languages, the
 collection is abstracted to an operation over another collection, or
 even to the results of a serial computation where there is no actual
 collection in memory.
 
 Iterators are not lazy sequences, because they do not behave like
 sequences.  You can't index them, you can't reiterate them, you can't
 get their length (and before you point out that there are ways of
 doing each of these things -- yes, but none of those ways use
 sequence-like syntax).  For true lazy sequences, consider the concept
 of streams and promises in the functional languages.
 
 In any case, the desired behavior of an output iterator on a source
 iterator is clear enough to me.  If the source iterator is also an
 output iterator, then it propagates the write to it.  If the source
 iterator is not an output iterator, then it raises a TypeError.
 
 * mutable sequences like lists can be changed. The standard idiom for
 that is to use enumerate:

 for i, e in enumerate(seq):
 seq[i] = e + 42
 
 Unless the underlying collection is a dict, in which case I need to do:
 
 for k, v in d.items():
 d[k] = v + 42
 
 Or a file:
 
 for line in f:
 # I'm not even sure whether this actually works.
 f.seek(-len(line))
 f.write(line.upper())
 
 As I said above, iterators are supposed to provide
 implementation-independent traversal over a collection.  For writing,
 enumerate fails in this regard.


While python may not have output iterators, interestingly numpy has just added 
this capability.  It is part of nditer.  So, this may suggest a syntax.

There have been a number of responses to my question that suggest using 
indexing 
(maybe with enumerate).  Once again, this is not suitable for many data 
structures.  c++ and stl teach that iteration is often far more efficient than 
indexing.  Think of a linked-list.  Even for a dense multi-dim array, index 
calculations are much slower than iteration.

I believe the lack of output iterators is a defienciency in the python iterator 
concept.


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


Re: User Authentication

2011-06-23 Thread Tim Golden

On 23/06/2011 16:07, Anurag wrote:

My application is a web based application for both windows and Linux.
The web part is developed using Django. So if Python does not support
it then any support for local sytem account authentication in Django?

I am looking for a common library for both Linux and Windows. Any help
will be Gr8


The two systems are sufficiently different in this kind of area
that any common library will basically consist of code like
this (hand-wavey):

code

import sys

if sys.platform.startswith (win):
  import win32security
  def is_valid_user (username, password):
if win32security.LogonUser ( ... )

elif sys.platform.startswith (linux):
  import pam
  def is_valid_user (username, password):
if pam.validate_user (...)

/code

It's possible someone's put something together already,
but I'm not aware of anything.

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


search through this list's email archives

2011-06-23 Thread Cathy James
Dear All,

I looked through this forum's archives, but I can't find a way to
search for a topic through the archive. Am I missing something?

Thanks as always.
CJ.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search through this list's email archives

2011-06-23 Thread Hans Mulder

On 23/06/11 18:11:32, Cathy James wrote:


I looked through this forum's archives, but I can't find a way to
search for a topic through the archive. Am I missing something?


One way to search the past contributions to this forum is to
go to http://groups.google.com/advanced_search and specify
comp.lang.python in the 'group' field.

This allows you to search for any combination of subject,
content, author, date range, language, etc.

-- HansM


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


[no subject]

2011-06-23 Thread MURTAZA HUSSAIN
murtaza.ned...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search through this list's email archives

2011-06-23 Thread Philip Semanchuk

On Jun 23, 2011, at 12:11 PM, Cathy James wrote:

 Dear All,
 
 I looked through this forum's archives, but I can't find a way to
 search for a topic through the archive. Am I missing something?


http://www.google.com/search?q=site%3Amail.python.org%2Fpipermail%2Fpython-list%2F+++banana
-- 
http://mail.python.org/mailman/listinfo/python-list


performance critical Python features

2011-06-23 Thread Eric Snow
I was thinking about the different features of Python that have an
impact on performance.  Here are the obvious ones I could think of:

Features most impactful on performance:

- function calls
- loops

Features least impactful on performance:

- imports
- function definitions
- class definitions

A key point is that CPython has special-case optimization for
functions (code objects, locals, and eval) and loops (comprehensions,
generators, and iterators).  Also, other libraries are optimized via
C-extensions to be efficient, I expect due to their use in loops.  In
contrast to that, the machinery behind language features like imports
are moving to pure Python.

So, which are the other pieces of Python that really need the heavy
optimization and which are those that don't?  Thanks.

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


Re: Project-wide variable...

2011-06-23 Thread Guillaume Martel-Genest
On Jun 23, 9:41 am, Gnarlodious gnarlodi...@gmail.com wrote:
 Is there a way to declare a project-wide variable and use that in all
 downstream modules?

 -- Gnarlir

What about using an environment variable?
-- 
http://mail.python.org/mailman/listinfo/python-list


Mac OS X 10.6.6 and MacPyhton 2.6 idle doesn't work

2011-06-23 Thread mando
I've installed MacPython 2.6 under mac os x 2.6 and the IDLE doesn't
work.
I post error log. Suggestions?

Thanks a lot.

Luca


23/06/11 19.18.01   Apple80211 framework[211]
ACInterfaceGetPower called
with NULL interface
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
Traceback (most
recent call last):
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]  File
/
Applications/Python 2.6/IDLE.app/Contents/Resources/idlemain.py,
line
30, in module
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
main()
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]  File
/
Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
idlelib/
PyShell.py, line 1382, in main
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
root =
Tk(className=Idle)
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]  File
/
Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-
tk/
Tkinter.py, line 1645, in __init__
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
self._loadtk()
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]  File
/
Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-
tk/
Tkinter.py, line 1659, in _loadtk
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]%
(_tkinter.TK_VERSION, tk_version)
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
RuntimeError:
23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]tk.h
version
(8.4) doesn't match libtk.a version (8.5)
23/06/11 19.18.01   com.apple.launchd.peruser.502[203]
([0x0-0x1f61f6].org.python.IDLE[2470]) Exited with exit code: 1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project-wide variable...

2011-06-23 Thread Noah Hall
On Thu, Jun 23, 2011 at 6:18 PM, Guillaume Martel-Genest
guillaum...@gmail.com wrote:
 On Jun 23, 9:41 am, Gnarlodious gnarlodi...@gmail.com wrote:
 Is there a way to declare a project-wide variable and use that in all
 downstream modules?

 What about using an environment variable?

Yes, that's fine, but only if the data is suitable for it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
On Jun 23, 8:42 am, Peter Otten wrote:

 from Module import Data

 There, you saved three more characters .
OK I get it, LOL.

 But I don't think it's a good idea. Remember that explicit is better than
 implicit.
Thanks, now I know what that means.

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


Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
On Jun 23, 11:42 am, Noah Hall wrote:

  What about using an environment variable?

 Yes, that's fine, but only if the data is suitable for it.

In this case, the variable is a namespace containing the property of a
folder full of plist files. I access any dictionary item anywhere in
my webapp with a namespace like this:

Data.Plist.SectrumDB.Sectrum.Contents.Character.Type
 Unicode string

There are hundreds of these dictionary items in the namespace, and it
has been a powerful programming tool. I simply wonder if there is a
more elegant way of giving my entire application access to these
variables from the top. Apparently not, from what I gather.

-- Gnarlie
http://Gnarlodious.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project-wide variable...

2011-06-23 Thread Terry Reedy

On 6/23/2011 10:09 AM, Gnarlodious wrote:

On Jun 23, 7:59 am, Noah Hall wrote:

from a import x


I'm doing that:
import Module.Data as Data

However I end up doing it in every submodule, so it seems a little
redundant. I wish I could load the variable in the parent program and
have it be available in all submodules. Am I missing something?


Yes. Make a project ~template.py file that includes the common import.
Mine is something like

#!python3
 '''project_dir/.py -- 2011
Copyright Terry Jan Reedy

'''
from test import ftest,itest


def test_main():


if __name__ == '__main__':
test_main()

--
Terry Jan Reedy

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


Re: writable iterators?

2011-06-23 Thread Chris Torek
(I apologize for the length of this article -- if I had more time,
I could write something shorter...)

In article mailman.296.1308770918.1164.python-l...@python.org
Neal Becker  ndbeck...@gmail.com wrote:
AFAICT, the python iterator concept only supports readable iterators,
not write.  
Is this true?

for example:

for e in sequence:
  do something that reads e
  e = blah # will do nothing

I believe this is not a limitation on the for loop, but a limitation on the 
python iterator concept.  Is this correct?

Yes.

Having read through the subsequent discussion, I think in some ways
you have run into some of the same issues that I did in my originally
somewhat-vague thoughts on exceptions, in that your example is too
close to real Python code and led a number of followers (including
me, originally) astray. :-)

It might be better expressed as, say:

for i in IndirectIter(sequence):
current_value = i.get()
result = compute(current_value)
i.set(result)

which is clearly rather klunky, and also does not fit super-well
into existing iter protocols, but could be implemented for lists
and dictionaries for instance; see below.

A more direct syntax (which I admit is pretty klunky, this is
kind of off the top of my head):

for item in sequence with newvalue:
newvalue = compute(item)

This leaves unresolved the issue of what if you don't set the
variable newvalue, but perhaps the for loop could internally
bind both item *and* newvalue at the top of each iteration,
so that this is essentially:

for item in sequence with newvalue:
newvalue = item # automatically inserted for you
... user code; if it doesn't set newvalue the .set()
(or whatever equivalent) will re-save the original value ...

Or -- and I think this is actually a better idea -- perhaps it
could pre-bind newvalue = None and the automatic iter.set()
invocation would leave None undisturbed.  In which case, the
internal implementation could even use .set() only, rather than
having to call iter.next(), as the primary protocol, with iter.set()
changing the current value and then doing, in essence, return
iter.next().  Of course this is just a micro-optimization that
might only apply to CPython in the first place; I am getting way
ahead of myself here. :-)

(To expand, what I am thinking at the moment is that if one had
this syntax, one would change the iter protocol.  An iterator object
would still provide __iter__ and next callables always.  If it
also provides a set callable -- or setitem or something like
that; the name is clearly flexible at this point -- then this would
make it a writeable iterator that one could use with the new
syntax.  The protocol would become:

for var1 in container [with var2]:
code

which if the with is present would mean: call container.__iter__
to get an iterable as usual, with the usual check that iter.__iter__
is also a callable.  Then, though, check the iterable for the *new*
callable as well.  If not present, you get an error.  If present,
call iter.next() initially and bind var2 to None.  At the bottom
of the loop, to step the loop, call the iter's iter.set() with
var2; bind its return value to var1, and re-bind var2 to None again.
Both iter.next() and iter.set() can raise StopIteration to terminate
the loop.)

This idea needs more thought applied, of course.

Another possible syntax:

for item in container with key:

which translates roughly to bind both key and item to the value
for lists, but bind key to the key and value for the value for
dictionary-ish items.  Then instead of:

for elem in sequence:
...
elem = newvalue

the OP would write, e.g.:

for elem in sequence with index:
...
sequence[index] = newvalue

which of course calls the usual container.__setitem__.  In this
case the new protocol is to have iterators define a function
that returns not just the next value in the sequence, but also
an appropriate key argument to __setitem__.  For lists, this
is just the index; for dictionaries, it is the key; for other
containers, it is whatever they use for their keys.

I actually think I like this second syntax more, as it leaves the
container-modifying step explicitly spelled out in user code.  It
would also eliminate much of the need for enumerate().

 example IndirectIter below 

class IndirectIterError(TypeError):
pass

class _IInner(object):
def __init__(self, outer, iterlist):
self.outer = outer
self.iterlist = iterlist
self.index = -1

def __iter__(self):
return self

def next(self):
self.index += 1
if self.index = len(self.iterlist):
raise StopIteration
return self

def get(self):
return self.outer._get(self.index, self.iterlist)

def set(self, newvalue):
return self.outer._set(self.index, self.iterlist, newvalue)

class IndirectIter(object):
def __init__(self, 

Re: Mac OS X 10.6.6 and MacPyhton 2.6 idle doesn't work

2011-06-23 Thread python
Benjamin,

 You'll have to install Tcl yourself. The 2.6 binaries were
compiled against a newer version than Apple ships.

Does this requirement apply to Python 2.7 or Python 3.2 for the
Mac or is this requirement Python 2.6 specific?

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


Re: Mac OS X 10.6.6 and MacPyhton 2.6 idle doesn't work

2011-06-23 Thread Benjamin Kaplan
On Jun 23, 2011 10:42 AM, mando mandol...@gmail.com wrote:

 I've installed MacPython 2.6 under mac os x 2.6 and the IDLE doesn't
 work.
 I post error log. Suggestions?

 Thanks a lot.

 Luca


You'll have to install Tcl yourself. The 2.6 binaries were compiled against
a newer version than Apple ships.


 23/06/11 19.18.01   Apple80211 framework[211]
 ACInterfaceGetPower called
 with NULL interface
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
 Traceback (most
 recent call last):
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]  File
 /
 Applications/Python 2.6/IDLE.app/Contents/Resources/idlemain.py,
 line
 30, in module
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
 main()
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]  File
 /
 Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
 idlelib/
 PyShell.py, line 1382, in main
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
 root =
 Tk(className=Idle)
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]  File
 /
 Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-
 tk/
 Tkinter.py, line 1645, in __init__
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
 self._loadtk()
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]  File
 /
 Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-
 tk/
 Tkinter.py, line 1659, in _loadtk
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]%
 (_tkinter.TK_VERSION, tk_version)
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]
 RuntimeError:
 23/06/11 19.18.01   [0x0-0x1f61f6].org.python.IDLE[2470]tk.h
 version
 (8.4) doesn't match libtk.a version (8.5)
 23/06/11 19.18.01   com.apple.launchd.peruser.502[203]
 ([0x0-0x1f61f6].org.python.IDLE[2470]) Exited with exit code: 1
 --
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: performance critical Python features

2011-06-23 Thread Chris Angelico
On Fri, Jun 24, 2011 at 2:58 AM, Eric Snow ericsnowcurren...@gmail.com wrote:
 So, which are the other pieces of Python that really need the heavy
 optimization and which are those that don't?  Thanks.


Things that are executed once (imports, class/func definitions) and
things that primarily wait for user input don't need to be optimized.
Things that get executed millions of times a second MAY need to be
optimized.

ChrisA
(The keyword MAY is to be interpreted as per RFC 2119.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: those darn exceptions

2011-06-23 Thread Chris Torek
In article 96gb36fc6...@mid.individual.net,
Gregory Ewing  greg.ew...@canterbury.ac.nz wrote:
Chris Torek wrote:

 Oops!  It turns out that os.kill() can raise OverflowError (at
 least in this version of Python, not sure what Python 3.x does).

Seems to me that if this happens it indicates a bug in
your code. It only makes sense to pass kill() something
that you know to be the pid of an existing process,
presumably one returned by some other system call.

So if kill() raises OverflowError, you *don't* want
to catch and ignore it. You want to find out about it,
just as much as you want to find out about a TypeError,
so you can track down the cause and fix it.

A bunch of you are missing the point here, perhaps because my
original example was not the best, as it were.  (I wrote it
on the fly; the actual code was elsewhere at the time.)

I do, indeed, want to find out about it.  But in this case
what I want to find out is the number I thought was a pid,
was not a pid, and I want to find that out early and catch
the OverflowError() in the function in question.

(The two applications here are a daemon and a daemon-status-checking
program.  The daemon needs to see if another instance of itself is
already running [*].  The status-checking program needs to see if
the daemon is running [*].  Both open a pid file and read the contents.
The contents might be stale or trash.  I can check for trash because
int(some_string) raises ValueError.  I can then check the now-valid
pid via os.kill().  However, it turns out that one form of trash
is a pid that does not fit within sys.maxint.  This was a surprise
that turned up only in testing, and even then, only because I
happened to try a ridiculously large value as one of my test cases.
It *should*, for some value of should :-) , have turned up much
earlier, such as when running pylint.)

([*] The test does not have to be perfect, but it sure would be
nice if it did not result in a Python stack dump. :-) )
-- 
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 constant

2011-06-23 Thread Waldek M.
Dnia Fri, 24 Jun 2011 01:29:38 +1000, Chris Angelico napisał(a):
 You can have them in Python. Just run your code through cpp (the C
 preprocessor) first. Voila!
 
 It's handy for other things too. Don't like Python's lack of then
 and end if?
[...]
Yup, got the sarcasm, that's for sure.
But your point was...?

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


How do you print a string after it's been searched for an RE?

2011-06-23 Thread John Salerno
After I've run the re.search function on a string and no match was
found, how can I access that string? When I try to print it directly,
it's an empty string, I assume because it has been consumed. How do
I prevent this?

It seems to work fine for this 2.x code:

import urllib.request
import re

next_nothing = '12345'
pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?
nothing='
pattern = re.compile(r'[0-9]+')

while True:
page = urllib.request.urlopen(pc_url + next_nothing)
match_obj = pattern.search(page.read().decode())
if match_obj:
next_nothing = match_obj.group()
print(next_nothing)
else:
print(page.read().decode())
break

But when I try it with my own code (3.2), it won't print the text of
the page:

import urllib.request
import re

next_nothing = '12345'
pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?
nothing='
pattern = re.compile(r'[0-9]+')

while True:
page = urllib.request.urlopen(pc_url + next_nothing)
match_obj = pattern.search(page.read().decode())
if match_obj:
next_nothing = match_obj.group()
print(next_nothing)
else:
print(page.read().decode())
break

P.S. I plan to clean up my code, I know it's not great right now. But
my immediate goal is to just figure out why the 2.x code can print
text, but my own code can't print page, which are basically the
same thing, unless something significant has changed with either the
urllib.request module, or the way it's decoded, or something, or is it
just an RE issue?

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


Re: How do you print a string after it's been searched for an RE?

2011-06-23 Thread Ian Kelly
On Thu, Jun 23, 2011 at 1:58 PM, John Salerno johnj...@gmail.com wrote:
 After I've run the re.search function on a string and no match was
 found, how can I access that string? When I try to print it directly,
 it's an empty string, I assume because it has been consumed. How do
 I prevent this?

This has nothing to do with regular expressions. It would appear that
page.read() is letting you read the response body multiple times in
2.x but not in 3.x, probably due to a change in buffering.  Just store
the string in a variable and avoid calling page.read() multiple times.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mac OS X 10.6.6 and MacPyhton 2.6 idle doesn't work

2011-06-23 Thread Ned Deily
In article 1308852410.2257.1466520...@webmail.messagingengine.com,
 pyt...@bdurham.com wrote:
  You'll have to install Tcl yourself. The 2.6 binaries were
 compiled against a newer version than Apple ships.
 
 Does this requirement apply to Python 2.7 or Python 3.2 for the
 Mac or is this requirement Python 2.6 specific?

I don't quite understand what's going on there.  To the OP: when you say 
MacPython 2.6, from where did you install it or did you build it 
yourself?  In OS X 10.6, Apple ships framework versions of both Tcl/Tk 
8.4 and 8.5.  Be aware that the 8.5 version shipped by Apple is known to 
be very problematic with IDLE and Tkinter.  If building youself, install 
the ActiveState Tcl/Tk 8.5 or stick to 8.4.  The most recent python.org 
OS X installer for 2.6 was 2.6.5 
(http://www.python.org/download/releases/2.6.5/) and should work just 
fine with the Apple-supplied Tcl/Tk 8.4 or with ActiveState Tcl/Tk 8.4.   
More info here:

http://www.python.org/download/mac/tcltk/

-- 
 Ned Deily,
 n...@acm.org

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


Re: How do you print a string after it's been searched for an RE?

2011-06-23 Thread John Salerno
On Jun 23, 3:47 pm, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Thu, Jun 23, 2011 at 1:58 PM, John Salerno johnj...@gmail.com wrote:
  After I've run the re.search function on a string and no match was
  found, how can I access that string? When I try to print it directly,
  it's an empty string, I assume because it has been consumed. How do
  I prevent this?

 This has nothing to do with regular expressions. It would appear that
 page.read() is letting you read the response body multiple times in
 2.x but not in 3.x, probably due to a change in buffering.  Just store
 the string in a variable and avoid calling page.read() multiple times.

Thank you. That worked, and as a result I think my code will look
cleaner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you print a string after it's been searched for an RE?

2011-06-23 Thread Thomas L. Shinnick

There is also
  print(match_obj.string)
which gives you a copy of the string searched.  See end of section 
6.2.5. Match Objects


At 02:58 PM 6/23/2011, John Salerno wrote:

After I've run the re.search function on a string and no match was
found, how can I access that string? When I try to print it directly,
it's an empty string, I assume because it has been consumed. How do
I prevent this?

It seems to work fine for this 2.x code:

import urllib.request
import re

next_nothing = '12345'
pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?
nothing='
pattern = re.compile(r'[0-9]+')

while True:
page = urllib.request.urlopen(pc_url + next_nothing)
match_obj = pattern.search(page.read().decode())
if match_obj:
next_nothing = match_obj.group()
print(next_nothing)
else:
print(page.read().decode())
break

But when I try it with my own code (3.2), it won't print the text of
the page:

import urllib.request
import re

next_nothing = '12345'
pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?
nothing='
pattern = re.compile(r'[0-9]+')

while True:
page = urllib.request.urlopen(pc_url + next_nothing)
match_obj = pattern.search(page.read().decode())
if match_obj:
next_nothing = match_obj.group()
print(next_nothing)
else:
print(page.read().decode())
break

P.S. I plan to clean up my code, I know it's not great right now. But
my immediate goal is to just figure out why the 2.x code can print
text, but my own code can't print page, which are basically the
same thing, unless something significant has changed with either the
urllib.request module, or the way it's decoded, or something, or is it
just an RE issue?

Thanks.


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


Re: python 3 constant

2011-06-23 Thread Chris Angelico
2011/6/24 Waldek M. wm@localhost.localdomain:
 Dnia Fri, 24 Jun 2011 01:29:38 +1000, Chris Angelico napisał(a):
 You can have them in Python. Just run your code through cpp (the C
 preprocessor) first. Voila!

 It's handy for other things too. Don't like Python's lack of then
 and end if?
 [...]
 Yup, got the sarcasm, that's for sure.
 But your point was...?

That if you want something, there's usually a way to get it.
Sometimes, giving someone what they want - or showing them how to get
it - makes it obvious to them whether or not they really want it.

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


GOZERBOT 0.9.2 RELEASED

2011-06-23 Thread Bart Thate
Hello new world !

i’m glad to announce the release of version GOZERBOT 0.9.2, a bot that
has been declared dead but has arrived from the pits of hell to serve
our people here well ;] Discovered that SQLAlchemy has been fixed in
such a way that it was easy to resurrect the thing, and release a new
version of it.

It’s not my intention to still maintain GOZERBOT as i prefer users to
switch to JSONBOT but this switch is to be done in such a way that
GOZERBOT users can port their data to JSONBOT in a proper way. Having
GOZERBOT still up and running makes it easier for me to write the
converting software as a GOZERBOT plugin, in which case i have better
access to the data then when i have to access it from the outside.

Ofcourse the conversion plugin is still to be written, but i hope that
current GOZERBOT users can wait a little while before that is in
place ;]

You can get the new version from http://gozerbot.googlecode.com. For
those who want to have a look at the future check http://jsonbot.org

Well thats new from a happy camper that suddenly finds his path ahead.

Grtx,

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


Re: How do you print a string after it's been searched for an RE?

2011-06-23 Thread John Salerno
On Jun 23, 4:47 pm, Thomas L. Shinnick tshin...@prismnet.com
wrote:
 There is also
        print(match_obj.string)
 which gives you a copy of the string searched.  See end of section
 6.2.5. Match Objects

I tried that, but the only time I wanted the string printed was when
there *wasn't* a match, so the match object was a NoneType.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: writable iterators?

2011-06-23 Thread Chris Torek
In article iu00fs1...@news3.newsguy.com I wrote, in part:
Another possible syntax:

for item in container with key:

which translates roughly to bind both key and item to the value
for lists, but bind key to the key and value for the value for
dictionary-ish items.  Then ... the OP would write, e.g.:

for elem in sequence with index:
...
sequence[index] = newvalue

which of course calls the usual container.__setitem__.  In this
case the new protocol is to have iterators define a function
that returns not just the next value in the sequence, but also
an appropriate key argument to __setitem__.  For lists, this
is just the index; for dictionaries, it is the key; for other
containers, it is whatever they use for their keys.

I note I seem to have switched halfway through thinking about
this from value to index for lists, and not written that. :-)

Here's a sample of a simple generator that does the trick for
list, buffer, and dict:

def indexed_seq(seq):

produce a pair
key_or_index value
such that seq[key_or_index] is value initially; you can
write on seq[key_or_index] to set a new value while this
operates.  Note that we don't allow tuple and string here
since they are not writeable.

if isinstance(seq, (list, buffer)):
for i, v in enumerate(seq):
yield i, v
elif isinstance(seq, dict):
for k in seq:
yield k, seq[k]
else:
raise TypeError(don't know how to index %s % type(seq))

which shows that there is no need for a new syntax.  (Turning the
above into an iterator, and handling container classes that have
an __iter__ callable that produces an iterator that defines an
appropriate index-and-value-getter, is left as an exercise. :-) )
-- 
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: doing cross platform file work

2011-06-23 Thread Rhodri James
On Thu, 23 Jun 2011 08:13:18 +0100, Gurpreet Singh  
karamheenkuriy...@gmail.com wrote:


...Cygwin spam.  Twice.

Please don't mail to both comp.lang.python and python-list.  They are  
gatewayed to each other, so we see your messages twice, which makes us  
roughly half as likely to respond to them.


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: doing cross platform file work

2011-06-23 Thread Ryan Kelly
On Wed, 2011-06-22 at 10:44 -0700, Tim Hanson wrote:
 Thanks for your responses to my student question about using OS paths in 
 Python.
 
 For the more general case, I am a Linux user interested in making my scripts 
 platform neutral, which would include Linux, Unix (including Mac), and 
 Windows.  I have looked at the python.org os segment and didn't get an answer.
 
 Is there a library (bonus would be some tutorial material) for making sure my 
 Linux scripts access files and directories on the other platforms 
 transparently?  I don't need the information immediately, but at some point...

You could go all out and use the PyFilesystem module:

   http://packages.python.org/fs/


This provides a unified API not only for accessing files on your local
disk in a platform-agnostic manner, but also for accessing files in a
zip archive, on a remote server, in memory, and from a variety of other
sources.

Even if you only ever intend to access local files, I find the API
provided by PyFilesystem much nicer than using the various modules from
the stdlib.


  Cheers,

 Ryan


-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


compile 32bit application in python for use on 64bit win machine

2011-06-23 Thread miamia
Hello,
I am using 32bit win xp pro and compiling my python scripts as exe
with py2exe. Everything works ok on 32bit windows platforms. But how
can I compile my program for use on 64bit Windows?

On 64bit windows this error occures in event log:
Activation context generation failed for C:\Program Files\app
\app.exe. Dependent Assembly
Microsoft.VC90.CRT,processorArchitecture=x86,publicKeyToken=1fc8b3b9a1e18e3b,type=win32,version=9.0.21022.8
could not be found. Please use sxstrace.exe for detailed diagnosis.

how can I run this program on 64 bit? thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compile 32bit application in python for use on 64bit win machine

2011-06-23 Thread Andrew Berg
On 2011.06.23 06:24 PM, miamia wrote:
 Hello,
 I am using 32bit win xp pro and compiling my python scripts as exe
 with py2exe. Everything works ok on 32bit windows platforms. But how
 can I compile my program for use on 64bit Windows?

 On 64bit windows this error occures in event log:
 Activation context generation failed for C:\Program Files\app
 \app.exe. Dependent Assembly
 Microsoft.VC90.CRT,processorArchitecture=x86,publicKeyToken=1fc8b3b9a1e18e3b,type=win32,version=9.0.21022.8
 could not be found. Please use sxstrace.exe for detailed diagnosis.

 how can I run this program on 64 bit? thanks
Looks like the 64-bit OS you're testing with is missing the 32-bit
Visual C runtime(s). Also, 32-bit programs on a 64-bit install of
Windows belong in \Program Files (x86), not \Program Files. A 32-bit
installer will be directed to the correct directory when trying to
access %ProgramFiles%; a 64-bit installer will not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: performance critical Python features

2011-06-23 Thread Steven D'Aprano
On Fri, 24 Jun 2011 04:00:17 +1000, Chris Angelico wrote:

 On Fri, Jun 24, 2011 at 2:58 AM, Eric Snow ericsnowcurren...@gmail.com
 wrote:
 So, which are the other pieces of Python that really need the heavy
 optimization and which are those that don't?  Thanks.


 Things that are executed once (imports, class/func definitions) and

You can't assume that either of those things are executed once. Consider 
this toy example:

def outer(a, b):
def inner(x):
return (x*a - b)*(x*b - a) - 1
return inner(b**2 - a**2)

results = [outer(a, b) for (a, b) in coordinate_pairs()]

The function definition for inner gets executed repeatedly, inside a 
tight loop.

Fortunately Python does optimize this case. The heavy lifting (parsing 
the source of inner, compiling a code object) is done once, when outer is 
defined, and the only work done at runtime is assembling the pieces into 
a function object, which is fast.

Similarly, imports are so expensive that it makes sense to optimize them. 
A single line like import module requires the following work:

- expensive searches of the file system, looking for a module.py file 
  or a module/__init__.py package, possibly over a slow network or 
  inside zip files;
- once found, parse the file;
- compile it;
- execute it, which could be arbitrarily expensive;
- and which may require any number of new imports.

Again, imports are already optimized in Python: firstly, once a module 
has been imported the first time, the module object is cached in 
sys.modules so that subsequent imports of that same module are much 
faster: it becomes little more than a name lookup in a dict. Only if that 
fails does Python fall back on the expensive import from disk.

Secondly, Python tries to cache the compiled code in a .pyc or .pyo file, 
so that parsing and compiling can be skipped next time you import from 
disk (unless the source code changes, naturally).

And even so, importing is still slow. That's the primary reason why 
Python is not suitable for applications where you need to execute lots of 
tiny scripts really fast: each invocation of the interpreter requires a 
whole lot of imports, which are slow the first time.

(Still, Python's overhead at startup time is nowhere near as expensive as 
that of Java... but Java is faster once started up.)


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


Re: writable iterators?

2011-06-23 Thread Neal Becker
Chris Torek wrote:

 In article iu00fs1...@news3.newsguy.com I wrote, in part:
Another possible syntax:

for item in container with key:

which translates roughly to bind both key and item to the value
for lists, but bind key to the key and value for the value for
dictionary-ish items.  Then ... the OP would write, e.g.:

for elem in sequence with index:
...
sequence[index] = newvalue

which of course calls the usual container.__setitem__.  In this
case the new protocol is to have iterators define a function
that returns not just the next value in the sequence, but also
an appropriate key argument to __setitem__.  For lists, this
is just the index; for dictionaries, it is the key; for other
containers, it is whatever they use for their keys.
 
 I note I seem to have switched halfway through thinking about
 this from value to index for lists, and not written that. :-)
 
 Here's a sample of a simple generator that does the trick for
 list, buffer, and dict:
 
 def indexed_seq(seq):
 
 produce a pair
 key_or_index value
 such that seq[key_or_index] is value initially; you can
 write on seq[key_or_index] to set a new value while this
 operates.  Note that we don't allow tuple and string here
 since they are not writeable.
 
 if isinstance(seq, (list, buffer)):
 for i, v in enumerate(seq):
 yield i, v
 elif isinstance(seq, dict):
 for k in seq:
 yield k, seq[k]
 else:
 raise TypeError(don't know how to index %s % type(seq))
 
 which shows that there is no need for a new syntax.  (Turning the
 above into an iterator, and handling container classes that have
 an __iter__ callable that produces an iterator that defines an
 appropriate index-and-value-getter, is left as an exercise. :-) )

Here is what numpy nditer does:

 for item in np.nditer(u, [], ['readwrite'], order='C'):
... item[...] = 10

Notice that the slice syntax is used to 'dereference' the iterator.  This seems 
like reasonably pythonic syntax, to my eye.

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


Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
On Jun 23, 12:10 pm, Terry Reedy wrote:

 from test import ftest,itest

 def test_main():

 if __name__ == '__main__':
      test_main()

I don't understand this. Can you explain, or refer me to some
documentation?

--  Gnarlie
http://Gnarlodious.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: performance critical Python features

2011-06-23 Thread Chris Angelico
On Fri, Jun 24, 2011 at 10:07 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 On Fri, 24 Jun 2011 04:00:17 +1000, Chris Angelico wrote:

 On Fri, Jun 24, 2011 at 2:58 AM, Eric Snow ericsnowcurren...@gmail.com
 wrote:
 So, which are the other pieces of Python that really need the heavy
 optimization and which are those that don't?  Thanks.


 Things that are executed once (imports, class/func definitions) and

 You can't assume that either of those things are executed once. Consider
 this toy example:

Sure. I was talking in generalities; of course you can do expensive
operations frequently. If you wanted to, you could do this:

radius=5
circum=0
for i in range(10,1000):
c=radius*calculate_pi_to_n_decimals(i)
if ccircum: circum=c

Calculates the highest possible circumference of a circle of that
radius. Does this mean we now have to optimize the pi calculation
algorithm so it can be used in a tight loop? Well, apart from the fact
that this code is moronic, no. All you need to do is cache. (Although
I guess in a way that's an optimization of the algorithm. It's the
same optimization as is done for imports.)

But generally speaking, functions are called more often than they're
defined, especially when we're talking about tight loops. And while
your example could be written without the repeated definition:

def outer(a, b):
   x=b**2 - a**2
   return (x*a - b)*(x*b - a) - 1

results = [outer(a, b) for (a, b) in coordinate_pairs()]

(at least, I think this is the same functionality), if inner() were
recursive, that would be different. But recursive inner functions
aren't nearly as common as write-once-call-many functions.

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


Re: writable iterators?

2011-06-23 Thread Dan Stromberg
On Wed, Jun 22, 2011 at 12:28 PM, Neal Becker ndbeck...@gmail.com wrote:

 AFAICT, the python iterator concept only supports readable iterators, not
 write.
 Is this true?

 for example:

 for e in sequence:
  do something that reads e
  e = blah # will do nothing

 I believe this is not a limitation on the for loop, but a limitation on the
 python iterator concept.  Is this correct?


The Generators, Iterators and Comprehensions 2011 document at the URL below
covers a way of doing this.

http://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project-wide variable...

2011-06-23 Thread Steven D'Aprano
On Thu, 23 Jun 2011 19:01:59 -0700, Gnarlodious wrote:

 On Jun 23, 12:10 pm, Terry Reedy wrote:
 
 from test import ftest,itest

 def test_main():

 if __name__ == '__main__':
      test_main()
 
 I don't understand this. Can you explain, or refer me to some
 documentation?

What part don't you understand?

This is Terry's template. It's not meant to work as-is, he has to fill in 
the details, such as what test_main() actually does.

The if __name__ == '__main__' idiom is a common way of making a Python 
script. When you import a module, Python automatically adds a global to 
it called __name__, and sets it to the name of the module. E.g.:

 import math
 math.__name__
'math'

When you run a module as a script, Python sets the __name__ to '__main__' 
instead. So this is a (slightly hacky) way of distinguishing code that 
runs when the module is imported from code that runs on execution.


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


Re: python 3 constant

2011-06-23 Thread alex23
Waldek M. w...@localhost.localdomain wrote:
 But your point was...?

That it's easier for you to find ways to achieve what you want than it
is require Python to change to accommodate your need.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
Let me restate my question.
Say I have a script Executable.py that calls all other scripts and
controls them:

#!/usr/local/bin/python
from Module import Data
import ModuleTest

ModuleTest.py has this:

print(Data.Plist.Structure)

Running Executable.py gives me this:
NameError: name 'Data' is not defined

1) Can I tell Executable.py to share Data with ModuleTest.py?
or if that can't be done:
2) Can I tell ModuleTest.py to look upstream for Data?

I have used two systems to accomplish this purpose:
1) Import Data into every module as it is loaded, which I am doing
now, and:
2) Load Data at the top and pass it downstream as a variable. This
gets a little cluttered and I quit doing it that way.

So I am looking for an easier way to load Data as an application-wide
variable. If its impossible to do what I want, I can accept that.

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


Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
Idea: It occurs to me that my application class inherits object. Can
I set that to inherit an object that already includes data? So every
subsequent class would start off with data loaded (except for class
Data).

Seems like it should already be invented.

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


Re: Project-wide variable...

2011-06-23 Thread alex23
On Jun 24, 2:01 pm, Gnarlodious gnarlodi...@gmail.com wrote:
 Seems like it should already be invented.

If you're finding you're importing the same data into every single
module, then you're doing something wrong. Creating dependencies
across modules like you're wanting is a recipe for suffering.

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


Re: Using __abstractmethod__ with non-methods

2011-06-23 Thread Eric Snow
Just a follow up on the longer post I made [1]:

Is it bad to set __abstractmethod__ on non-functions in order to
trigger the ABC abstractness checks?

If not, are __isabstractmethod__ on objects and __abstractmethods__ on
classes misleading names?

Like I said before, I don't mean to imply that Python has it wrong.
On the contrary, I typically start by assuming that Python has it
right and then try to figure out what I am missing.  Such is the case
here.

-eric

[1] http://mail.python.org/pipermail/python-list/2011-June/1274555.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Interpreting Left to right?

2011-06-23 Thread Chetan Harjani
x=y=some string
And we know that python interprets from left to right. so why it doesnt
raise a name error here saying name 'y' is not defined?

another example:
(1,2) + 3,
here, python raises a  TypeError can only concatenate tuple(not int) to
tuple but we know (3,) is a tuple as seen by following:
t=3,
type(t)
type 'tuple'
Arent both of this contradicting?

-- 
Chetan H Harjani
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interpreting Left to right?

2011-06-23 Thread Chris Angelico
On Fri, Jun 24, 2011 at 2:32 PM, Chetan Harjani
chetan.harj...@gmail.com wrote:
 x=y=some string
 And we know that python interprets from left to right. so why it doesnt
 raise a name error here saying name 'y' is not defined?

In most languages, the answer is that the = operator associates right
to left, even though most other operators associate left to right.
(That's how C does it, for instance.) But in Python, I believe it's
actually one operator taking several parameters, because = is not an
expression.

In any case, you can safely treat = as an exception to the
left-to-right rule. There are other exceptions too - note the comments
in http://docs.python.org/reference/expressions.html#summary - there's
not many RTL operators in Python, only those that make sense that way.
:)

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


[issue10206] python program starting with unmatched quote spews spaces to stdout

2011-06-23 Thread Petri Lehtinen

Petri Lehtinen pe...@digip.org added the comment:

I'm unable to reproduce this. I checked out the commit 65614:18989ad44636 
(corresponding to r85814, right?), built and ran python -c ', but didn't get 
a space flood on my face. Just a normal SyntaxError.

--
nosy: +petri.lehtinen

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10206
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10206] python program starting with unmatched quote spews spaces to stdout

2011-06-23 Thread Stefan Krah

Stefan Krah stefan-use...@bytereef.org added the comment:

I remember that I could reproduce it at the time. The issue was indeed
fixed in r85904.

--
nosy: +skrah

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10206
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10206] python program starting with unmatched quote spews spaces to stdout

2011-06-23 Thread Petri Lehtinen

Petri Lehtinen pe...@digip.org added the comment:

By checking out the parent of r85904 I now can reproduce this.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10206
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2202] urllib2 fails against IIS 6.0 (No support for MD5-sess auth)

2011-06-23 Thread Chris Withers

Chris Withers ch...@simplistix.co.uk added the comment:

Hmm, I'd argue it's a bug:

  File /usr/lib64/python2.5/urllib2.py, line 972, in get_algorithm_impls
return H, KD
UnboundLocalError: local variable 'H' referenced before assignment

...does not say anything like:

The digest authentication scheme you have requested is not supported

Now, as to whether it's a bug that 'MD5-sess' isn't supported is a tougher 
call. The XXX indicates the intention was certainly for it to be supported...

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2202
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12390] urllib.parse.urlencode encoding lists as strings

2011-06-23 Thread Joesph

Joesph someone...@gmail.com added the comment:

Hrm, yes. 'Tis what I get for working while sick.

--
resolution: invalid - accepted

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12390
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12390] urllib.parse.urlencode encoding lists as strings

2011-06-23 Thread Senthil Kumaran

Senthil Kumaran sent...@uthcode.com added the comment:

Joseph, resolution applies for the bug not the process. tc. :)

--
resolution: accepted - invalid

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12390
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9921] os.path.join('x','') behavior

2011-06-23 Thread Brian Brazil

Brian Brazil brian.bra...@gmail.com added the comment:

David's change sounds good to me.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9921
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10206] python program starting with unmatched quote spews spaces to stdout

2011-06-23 Thread Petri Lehtinen

Petri Lehtinen pe...@digip.org added the comment:

Attached a test case. The patch is against the current default tip.

--
Added file: http://bugs.python.org/file22427/issues10206_test.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10206
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12391] packaging install fails to clean up temp files

2011-06-23 Thread Vinay Sajip

New submission from Vinay Sajip vinay_sa...@yahoo.co.uk:

There are a number of places in packaging.install where temporary directories 
are created, but never cleaned up:

1. In _move_files, if no destination path is passed in, one is created using 
mkdtemp(), but it's not clear where this would be deleted. Moreover, it's never 
called without a path and not part of the public API, so it would make sense to 
always expect a destination to be passed in (and update the docstring to match)

2. install_local_project, in the case of an archive, unpacks it into a 
mkdtemp()'d directory, but never deletes that directory later.

3. install_dists() also calls mkdtemp() if a path is not passed in, but it's 
not clear where this would be deleted. This should be changed to always require 
a path to be passed in. The install_from_infos accepts None as an install path 
and passes that to install_dists, but why are we being so generous? It's not 
asking a lot to be given an explicit path to install to.

Note: the DistInfo class in packaging.pypi.dist also does this kind of thing 
(in the download and unpack methods) - it would seem sensible to make similar 
changes there.

--
assignee: tarek
components: Distutils2, Library (Lib)
messages: 138860
nosy: alexis, eric.araujo, tarek, vinay.sajip
priority: normal
severity: normal
status: open
title: packaging install fails to clean up temp files
type: behavior
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12391
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12386] packaging fails in install_distinfo when writing RESOURCES

2011-06-23 Thread Vinay Sajip

Changes by Vinay Sajip vinay_sa...@yahoo.co.uk:


--
type:  - behavior

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12386
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12363] test_signal.test_without_siginterrupt() sporadic failures on FreeBSD 6.4

2011-06-23 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

All Python 3.x buildbots are green (except FreeBSD 7.2, but it's not related to 
this issue). Let close this issue.

--
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12363
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11223] interruption of locks by signals not guaranteed when locks are implemented using POSIX condition variables; add sys.thread_info

2011-06-23 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset 07655b3dee4f by Victor Stinner in branch '3.2':
Issue #11223: skip test_lock_acquire_interruption() on FreeBSD6
http://hg.python.org/cpython/rev/07655b3dee4f

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11223] interruption of locks by signals not guaranteed when locks are implemented using POSIX condition variables; add sys.thread_info

2011-06-23 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset 3f18a03a2a1e by Victor Stinner in branch 'default':
(null merge 3.2 for issue #11223) python 3.3 has already a better fix
http://hg.python.org/cpython/rev/3f18a03a2a1e

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11223] interruption of locks by signals not guaranteed when locks are implemented using POSIX condition variables; add sys.thread_info

2011-06-23 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset e5183f16c49d by Victor Stinner in branch '3.2':
Issue #11223: skip also test_rlock_acquire_interruption() on FreeBSD6
http://hg.python.org/cpython/rev/e5183f16c49d

New changeset 54fb77e0762c by Victor Stinner in branch 'default':
(null merge 3.2 for issue #11223) python 3.3 has already a better fix
http://hg.python.org/cpython/rev/54fb77e0762c

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11223
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6715] xz compressor support

2011-06-23 Thread jeremybanks

Changes by jeremybanks jer...@jeremybanks.ca:


--
nosy: +jeremybanks

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6715
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2202] urllib2 fails against IIS 6.0 (No support for MD5-sess auth)

2011-06-23 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

Oh, the bad error message is definitely a bug.  The question is whether we can 
also add md5-sess support while fixing it.  Sounds like Senthil thinks no, in 
which case this issue needs to be split into two parts.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2202
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >