ANN: Celery 1.0 released

2010-02-11 Thread Ask Solem
===
 Celery 1.0 has been released!
===

We're happy to announce the release of Celery 1.0.

What is it?
===

Celery is a task queue/job queue based on distributed message passing.
It is focused on real-time operation, but supports scheduling as well.

The execution units, called tasks, are executed concurrently on one or
more worker servers. Tasks can execute asynchronously (in the background)
or synchronously (wait until ready).

Celery is already used in production to process millions of tasks a day.

Celery was originally created for use with Django, but is now usable
from any Python project. It can
also operate with other languages via webhooks.

The recommended message broker is RabbitMQ (http://rabbitmq.org), but support
for Redis and databases is also available.

For more information please visit http://celeryproject.org


Features


See http://ask.github.com/celery/getting-started/introduction.html#features

Stable API
==

From this version on the public API is considered stable. This means there 
won't
be any backwards incompatible changes in new minor versions. Changes to the
API will be deprecated; so, for example, if we decided to remove a function
that existed in Celery 1.0:

* Celery 1.2 will contain a backwards-compatible replica of the function which
  will raise a PendingDeprecationWarning.
  This warning is silent by default; you need to explicitly turn on display
  of these warnings.
* Celery 1.4 will contain the backwards-compatible replica, but the warning
  will be promoted to a full-fledged DeprecationWarning. This warning
  is loud by default, and will likely be quite annoying.
* Celery 1.6 will remove the feature outright.

See the Celery Deprecation Timeline for a list of pending removals:
http://ask.github.com/celery/internals/deprecation.html

What's new?
===

* Task decorators

Write tasks as regular functions and decorate them.
There are both task(), and periodic_task() decorators.

* Tasks are automatically registered

Registering the tasks manually was getting tedious, so now you don't have
to anymore. You can still do it manually if you need to, just
disable Task.autoregister. The concept of abstract task classes
has also been introduced, this is like django models, where only the
subclasses of an abstract task is registered.

* Events

If enabled, the worker will send events, telling you what tasks it
executes, their results, and how long it took to execute them. It also
sends out heartbeats, so listeners are able to detect nonfunctional
workers. This is the basis for the new real-time web monitor we're working 
on
(celerymon: http://github.com/ask/celerymon/).

* Rate limiting

Global and per task rate limits. 10 tasks a second? or one an hour? You
decide. It's using the token bucket algorithm, which is
commonly used for network traffic shaping. It accounts for bursts of
activity, so your workers won't be bored by having nothing to do.


* New periodic task service.

Periodic tasks are no longer dispatched by celeryd, but instead by a
separate service called *celerybeat*. This is an optimized, centralized
service dedicated to your periodic tasks, which means you don't have to
worry about deadlocks or race conditions any more. But that does mean you
have to make sure only one instance of this service is running at any one
time.

  **TIP:** If you're only running a single celeryd server, you can embed
  celerybeat inside it. Just add the --beat argument.


* Broadcast commands

If you change your mind and don't want to run a task after all, you
now have the option to revoke it.

Also, you can rate limit tasks or even shut down the worker remotely.

It doesn't have many commands yet, but we're waiting for broadcast
commands to reach its full potential, so please share your ideas
if you have any.

* Multiple queues

The worker is able to receive tasks on multiple queues at once.
This opens up a lot of new possibilities when combined with the impressive
routing support in AMQP.

* Platform agnostic message format.

  The message format has been standardized and is now using the ISO-8601 format
  for dates instead of Python datetime objects. This means you can write task
  consumers in other languages than Python (eceleryd anyone?)

* Timely

  Periodic tasks are now scheduled on the clock, i.e. timedelta(hours=1)
  means every hour at :00 minutes, not every hour from the server starts.
  To revert to the previous behavior you have the option to enable
  PeriodicTask.relative.

* ... and a lot more!

To read about these and other changes in detail, please refer to
the change log: http://celeryproject.org/docs/changelog.html
This document contains crucial information for those
upgrading from a previous version of Celery, so be sure to read the entire
change set 

[ANN] pyxser-1.4.2r --- Python Object to XML serializer/deserializer

2010-02-11 Thread Daniel Molina Wegener
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Hello Python Community.

I'm pleased to announce pyxser-1.4.2r, a python extension which
contains functions to serialize and deserialize Python Objects
into XML. It is a model based serializer. Here is the ChangeLog
entry for this release:

- ---8---
1.4.2r (2010.02.10):

Daniel Molina Wegener dmw at coder dot cl
* pyxser_collections.c: Added constraint checks for NULL
pointers removing nested statements.
* pyxser.c: Removed nested statements.
* pyxser_tools.c: Added constratints checks for NULL pointers,
removed nested statements and added strict checking for lists
since it was crashing with an ambigous list definition that
can not be handled by PyList_Check().
* test-utf8.py: Added tests to determine if it continue
crashing with module serialization.

Thanks to pyxser users for their feedback.
- ---8---

This release contains some bug fixes, mainly related to type
checking and type handling. I hope this small extension will
help you on your programming tasks.

The project is hosted at:
http://sourceforge.net/projects/pyxser/

The web page for the project is located at:
http://coder.cl/products/pyxser/

PyPi entry is:
http://pypi.python.org/pypi?:action=displayname=pyxserversion=1.4.2r

For a sample article on how to integrate
pyxser with ZSI WebServices:
http://coder.cl/2009/10/18/pyxser-and-zsi-webservices/

Thanks and best regards,
- -- 
Daniel Molina Wegener dmw [at] coder [dot] cl
Software Architect, System Programmer  Web Developer
Phone: +1 (510) 629-4267 | Blog: http://coder.cl/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iQIcBAEBCgAGBQJLcwqwAAoJEHxqfq6Y4O5NP2YQAKwiMq7xdutSpEcrXPsD2dxI
VQUhzoaJ+Z+N0Vu6nKLM8yOXGkCSD8iuKgV3ZimH3gHhYs/VTvfkNwkfJuck76Vg
y3CvJ69rVezYI2ELcsWP0+srxffyy0NHgYEKlKU3Dz06PhNnGx2PMfeG7j5ZGKyz
92J+PMoO6FSlRAmEmGrnjtWaCeNLmlJ2rdSvQ7iSIV8mTwULHB2QubvNs62x+8v5
Mj8XM4HVVEqOI2aF3KuAhYdHj6Exz3O5clnzT6niYl/ukWErSZ6JUJoF9IKcBPVJ
LYMCIPvad6llr2FcIatve7MwdmFx/FVNkpd7oZuvLEiQYqxsuT9fv2L/1Ne1IRSM
KRLW5/oqekirIURJgFmn6rw0D9Hj5eQXfXTTCHT+RTUaWgMKXFiVkSCHpOeX5M14
i4pp1+xUhje/R+Y05FmdcBivahdc+4UiaQsWODIj/kUbfa455aLrVomdLzXQavg/
9nY/N5sd0wqdW2vyJrgvap1lAhzP+ktFk/UTetUavvz9bz0tHRB9aTNDS53dfck5
yVX/ZumRdtf4wtwTu/t6gkWD7N0K0Bmy1EB3JNz6KCBvjL8QDB8W/kW+os85QFoz
9NxedRoJNn5nVyos879+ClnHqXVTtkmeJOuLFuh2+9pnfc/KSAvCDXZKPZZNHKYx
WdTJKm400Hi9J/pIOzx/
=bv4P
-END PGP SIGNATURE-

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

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


Announcing IronPython 2.6.1 RC1

2010-02-11 Thread David DiCato
Hello Python Community,

We're pleased to announce the release of IronPython 2.6.1 RC1. This version of 
IronPython makes great strides in stability and compatibility, including a 
considerable number of targeted bugfixes. Because this is our largest servicing 
release to date, and due to our decision against incrementing the assembly 
version numbers, it is important that we get everything right. To this end, we 
present our first-ever RC for a minor dot release. Of course, your feedback is 
imperative to the quality of this release, so we'd love to hear from you!

IronPython 2.6.1 comes in two flavors - one that runs on top of .NET 4.0 RC, 
and one that runs on any other framework starting with .NET 2.0 SP1.  They can 
be downloaded here:

-  IronPython 2.6.1 RC1 for .NET 2.0 SP1: 
http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=40144

-  IronPython 2.6.1 RC1 for .NET 4.0 RC: 
http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=40146

Note: The .NET Framework 4.0 RC is required for the latter release and can be 
downloaded at 
http://www.microsoft.com/downloads/details.aspx?FamilyID=a9ef9a95-58d2-4e51-a4b7-bea3cc6962cbdisplaylang=en

IronPython 2.6.1 RC1 includes fixes for well over 50 bugs, large and small. 
Ctypes has had a number of significant updates, including union support, 
variant_bool, and wintypes. Another focus has been on sys.settrace, making 
debugging more reliable. For example, sys.settrace now returns the correct 
frame, supports tracing through modules, and no longer interferes with import 
os. Other notable fixes include thread-safe importing, and the missing error 
code in _winreg exception.

In addition, we've made a substantial improvement in import time. Not only does 
this reduce startup time, but can speed up the importing of large, 
definition-heavy modules by up to 50%.

As you might imagine, the .NET 4.0 flavor of IronPython 2.6.1 RC1 has a few of 
its own changes designed for better interoperability with the framework. These 
include fixing some errors with Func and better runtime isolation when 
similarly-named assemblies in different locations are loaded in multiple 
engines. In addition, both the .NET 2.0 and .NET 4.0 builds support the new 
.NET 4.0 IStructuralEquatable and IStructuralComparable interfaces and maps 
them to the  appropriate operations (__eq__, __hash__, __gt__, etc.). In the 
case of .NET 4.0, this replaces IValueEquality as the gold standard for 
defining equality in an interop-friendly manner. In the .NET 2.0 build, these 
interfaces are copied so that their use can be phased in while retaining 
IValueEquality for backwards compatibility.

Special thanks to Albert Szilvasy, cendalc, clovery, egonw_, essey, fabiofz, 
igalse, jazzcat, jlunder, laughingboy, marten_range, László de Almásy, lbaker, 
Lukas Cenovsky, pl6306, roinet, sanxiyn, Thomas Heller, vernondcole, and 
Wolfram for reporting issues. Happy Scripting!

- The IronPython Team

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

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


Announce: Linux Desktop Testing Project (LDTP) 2.0.3 released

2010-02-11 Thread Nagappan Alagappan
Hello,

About LDTP:

Linux Desktop Testing Project is aimed at producing high quality test
automation framework (using GNOME / Python) and cutting-edge tools that can
be used to test Linux Desktop and improve it. It uses the Accessibility
libraries to poke through the application's user interface. We strive to
help in building a quality desktop.

Changes in this release:

Return always unicode string in gettextvalue, required to fix automated test
script in VMware Workstation
Fix ooldtp compatibility with LDTPv1 as reported by Mago [1] team
Patch by James Tatum for getallstates compatible with hasstate function
Fix bug b.g.o#608413
Fix Firefox preference accessing bug, reported by Aaron Yuan 
yuanchong1...@gmail.com

Download source:
http://download.freedesktop.org/ldtp/2.x/2.0.x/ldtp-2.0.3.tar.gz

Download RPM from
http://download.opensuse.org/repositories/home:/anagappan:/ldtp2:/rpm/
Will schedule deb build in openSUSE build service tomorrow

Documentation references:

For detailed information on LDTP framework and latest updates visit
http://ldtp.freedesktop.org

For information on various APIs in LDTP including those added for this
release can be got from http://ldtp.freedesktop.org/user-doc/index.html

Report bugs - http://ldtp.freedesktop.org/wiki/Bugs

To subscribe to LDTP mailing lists, visit
http://ldtp.freedesktop.org/wiki/Mailing_20list

IRC Channel - #ldtp on irc.freenode.net

Thanks
Nagappan

[1] - http://mago.ubuntu.com

-- 
Linux Desktop (GUI Application) Testing Project -
http://ldtp.freedesktop.org
http://nagappanal.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Modifying Class Object

2010-02-11 Thread Alf P. Steinbach

* I V:

On Thu, 11 Feb 2010 07:37:35 +0100, Alf P. Steinbach wrote:

* Steven D'Aprano:

s = [1]
t = s # Binds the name t to the object bound to the name s.
t[0] = 2  # Changes the object bound to the name t print(s)  #
Checks the object via the original name.

Notice that your version describes what happens according to some
implementation, below the level of the Python virtual machine.

Consider just the

   assert( t is not s )

   t = s

Does this change anything at all in the computer's memory?

If it doesn't, then it has no effect whatsoever.

But since it does have an effect, a memory change has been effected.


I don't think your disagreeing with Steven here - by talking about the 
computers memory, it's clear that you are talking about the details of 
an implementation of python, not the semantics of python itself. Unless, 
of course, you are under the misapprehension that the computer's memory 
is relevant to the python language, rather than the particular 
implementation. Python itself has nothing to do with computers or 
memory; these are mere implementation details.


You know, the programming language that doesn't need computers: Python.

:-)



Cheers,

- Alf (not sure how to read your posting, but it's funny anyhow)
--
http://mail.python.org/mailman/listinfo/python-list


Re: I've built Python, but can't figure out how to package it for windows

2010-02-11 Thread Tim Golden

On 11/02/2010 05:24, Mark Jones wrote:
[... problems building from tools/msi ...]

I sympathise. I went through similar hoops last year, merely to
be able to do it. I think I'm right in saying that very few
people are bothered enough to package their own MSI on windows
because the (probably very few) developers who have a need to
run bleeding-edge Python, eg to test out patches or whatever,
can simply run from checkout\pcbuild\python_d.exe or whatever.
And everyone else simply runs the MSI provided on python.org.

I'm fairly sure I'm right in saying that it's Martin von L
who builds the MSIs for python.org and if I haven't done it
before I'd like to offer him a vote of thanks for having done
and for continuing to do this. The tools/msi is used by him
to do those builds and does make certain assumptions. One,
in particular, is that you have an *existing* copy of some
recent Python running somewhere. (I use python25, I think).
Altho' it might be nice to be able to bootstrap, in practice
it isn't a problem.

For interest's sake I offer my make-snapshots area which I
use to build trunk or branches for Python 2.x / 3.x when I
have the change:

  http://svn.tjg.org.uk/make-snapshots

Feel free to look at least to see what I'm doing. I think I
didn't bother with Tix (I don't use Tkinter) so thanks for
providing some input on that; I may well go back and retrofit.

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


Re: Executing Commands From Windows Service

2010-02-11 Thread Tim Golden

On 10/02/2010 22:55, T wrote:

Great suggestions once again - I did verify that it was at least
running the plink.exe binary when under LocalSystem by having the
service run plink.exe  C:\plinkoutput.txt - this worked fine.  And,
as I mentioned, it's now working just fine when running under a
regular admin account.  So, I think that's going to be my solution to
avoid any further issues.  My best guess at this point (as you
mentioned), is that plink.exe is doing _something_ network-related
that LocalSystem doesn't have the privileges to do - what exactly it
is, I have no idea.  I may play around with it some more later, but
running the service under an admin account should be a perfectly
acceptable solution.

Also, I will be writing other Python apps that the service will be
executing - so it goes without saying that I'll be including a log to
file option :)  Thanks again for all your guys' help!


I'm not sure if this has been said already, but a reasonably common
approach to services is to create a user specifically for the
service and grant it exactly the privs / perms it needs (once you
work out what they are). You then assign it a generated password,
eg a GUID which you don't even try to remember: simply cut-and-paste
it in. Then create the service to run under that user.

That way you don't have the service running under
some local Administrator account with the associated risk
of its being subverted and gaining more control than you
want. Nor do you have it running as a real user whose
password might change for any reason, leaving you with
a service which won't start up.

I don't remember at this moment whether such a user's profile
is automatically loaded in the process when the service starts
or whether you have to do the LoadUserProfile thing.

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


Re: ANN: obfuscate

2010-02-11 Thread Christian Heimes
Gregory Ewing wrote:
 Actually I gather it had a lot to do with the fact that
 the Germans made some blunders in the way they used the
 Enigma that seriously compromised its security. There
 was reportedly a branch of the German forces that used
 their Enigmas differently, avoiding those mistakes, and
 the British never managed to crack any of their messages.

IIRC some versions of the Enigma weren't cracked because they used a
different setup and different daily keys.

The predecessor of the Enigma was cracked by Polish scientists years
before WW2 started. Some flaws in the instructions and a known plain
text attack made the crack of the Enigma practical. It took the British
scientists merely hours rather than days or weeks to decipher the daily
key with some smart tricks. For example they started fake attacks on
ships or cities just to have the names in some encrypted reports.
-- 
http://mail.python.org/mailman/listinfo/python-list


how to improve this cycle (extracting data from structured array)?

2010-02-11 Thread Alexzive
Hello guys,

I am just wondering if there is a quick way to improve this algorithm
[N is a structured array which hold info about the nodes n of a finite
element mesh, and n is about 300.000). I need to extract info from N
and put it in to a 3*n matrix NN which I reshape then with numpy. I
think to append is quite unefficient:

***
N = odb.rootAssembly.instances['PART-1-1'].nodes


NN=[]

B=[0,0,0]
 #auxsiliar vector
for i in range(len(N)):

B[0] = N[i].label

B[1] = N[i].coordinates[0]

B[2] = N[i].coordinates[1]

NN = append(NN,B)


NN=NN.reshape(-1,3)


Many Thanks in advance!
Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to improve this cycle (extracting data from structured array)?

2010-02-11 Thread Tim Chase

Alexzive wrote:

I am just wondering if there is a quick way to improve this algorithm
[N is a structured array which hold info about the nodes n of a finite
element mesh, and n is about 300.000). I need to extract info from N
and put it in to a 3*n matrix NN which I reshape then with numpy. I
think to append is quite unefficient:

***
N = odb.rootAssembly.instances['PART-1-1'].nodes

NN=[]

B=[0,0,0]
 #auxsiliar vector
for i in range(len(N)):
B[0] = N[i].label
B[1] = N[i].coordinates[0]
B[2] = N[i].coordinates[1]
NN = append(NN,B)


Usually this would be written with a list-comprehension, 
something like


  nn = [(x.label, x.coordinates[0], x.coordinates[1])
for x in N]

or if you really need lists-of-lists instead of lists-of-tuples:

  nn = [[x.label, x.coordinates[0], x.coordinates[1]]
for x in N]

-tkc


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


Bizarre arithmetic results

2010-02-11 Thread Terrence Cole
Can someone explain to me what python is doing here?

Python 3.1.1 (r311:74480, Feb  3 2010, 13:36:47) 
[GCC 4.3.4] on linux2
Type help, copyright, credits or license for more information.
 -0.1 ** 0.1
-0.7943282347242815
 a = -0.1; b = 0.1
 a ** b
(0.7554510437117542+0.2454609236416552j)
 -abs(a ** b)
-0.7943282347242815

Why does the literal version return the signed magnitude and the
variable version return a complex?

Cheers,
Terrence

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


Re: Re: sqlite3 bug?

2010-02-11 Thread wayne . dads . bell

Thank you

It just highlights that when your tired things can easily be missed and
maybe you should leave things until the morning to view things with
fresh eyes =)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-11 Thread Arnaud Delobelle
Alf P. Steinbach al...@start.no writes:
[...]
 That's bullshit.
[...]
 not any that you know about.
[...]
 yet another ad hominem attack
[...]
 It also reflects rather badly on you.
[...]
 - Alf

Alf, 

The above was extracted from the last post from you but I could have
picked almost any of your recent endeavours.  I've come to the
conclusion that you're not a cute furry alien with a long nose.  You're
a big bad troll!

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


Re: ANN: obfuscate

2010-02-11 Thread Gregory Ewing

Daniel Fetchinson wrote:


It also turned out that everybody mostly writes his/her
own obfuscation routine.


Hey, it gives you the additional advantage of obfuscation
by obscurity!

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


Re: ANN: obfuscate

2010-02-11 Thread Paul Rubin
Gregory Ewing greg.ew...@canterbury.ac.nz writes:
 Actually I gather it had a lot to do with the fact that the Germans
 made some blunders in the way they used the Enigma that seriously
 compromised its security. There was reportedly a branch of the German
 forces that used their Enigmas differently, avoiding those mistakes,
 and the British never managed to crack any of their messages.

I think you are thinking of the Kriegsmarine (naval) Enigma.  Yes they
were more careful with procedures, but the machine was also harder to
crack because it had four rotors instead of three.  IIRC, the Brits were
eventually (1942?) able to capture one by shooting up a German submarine
and boarding it to get the machine while the sub was sinking; a British
sailor wasn't able to get out in time and drowned during that operation.
Getting the rotor settings off the captured unit (they may have had to
do it more than once) was enough to get a foothold into the code.  My
memory is hazy on this by now so I may have some parts wrong, but David
Kahn's book Seizing the Enigma tells the story (I read it many years
ago).  A fictionalized version appears in Neil Stephenson's novel
Cryptonomicon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Unicode strings

2010-02-11 Thread aabelyakov
Excellent! But what about the unicode
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bizarre arithmetic results

2010-02-11 Thread Andre Engels
On Thu, Feb 11, 2010 at 1:44 AM, Terrence Cole
list-s...@trainedmonkeystudios.org wrote:
 Can someone explain to me what python is doing here?

 Python 3.1.1 (r311:74480, Feb  3 2010, 13:36:47)
 [GCC 4.3.4] on linux2
 Type help, copyright, credits or license for more information.
 -0.1 ** 0.1
 -0.7943282347242815
 a = -0.1; b = 0.1
 a ** b
 (0.7554510437117542+0.2454609236416552j)
 -abs(a ** b)
 -0.7943282347242815

 Why does the literal version return the signed magnitude and the
 variable version return a complex?

It's an issue of precedence of operators:

-0.1 ** 0.1

is interpreted as

-(0.1 ** 0.1)

and not as

(-0.1) ** 0.1






-- 
André Engels, andreeng...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bizarre arithmetic results

2010-02-11 Thread Mark Dickinson
On Feb 11, 12:44 am, Terrence Cole list-
s...@trainedmonkeystudios.org wrote:
 Can someone explain to me what python is doing here?

  -0.1 ** 0.1
 -0.7943282347242815

Here you're computing -(0.1 ** 0.1).  The exponentiation operator
binds more strongly than the negation operator.

  a = -0.1; b = 0.1
  a ** b
 (0.7554510437117542+0.2454609236416552j)

Here you're computing (-0.1) ** 0.1.

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


Re: Bizarre arithmetic results

2010-02-11 Thread Peter Otten
Terrence Cole wrote:

 Can someone explain to me what python is doing here?
 
 Python 3.1.1 (r311:74480, Feb  3 2010, 13:36:47)
 [GCC 4.3.4] on linux2
 Type help, copyright, credits or license for more information.
 -0.1 ** 0.1
 -0.7943282347242815
 a = -0.1; b = 0.1
 a ** b
 (0.7554510437117542+0.2454609236416552j)
 -abs(a ** b)
 -0.7943282347242815
 
 Why does the literal version return the signed magnitude and the
 variable version return a complex?

Operator precedence.

 -0.1**0.1
-0.7943282347242815
 (-0.1)**0.1
(0.7554510437117542+0.2454609236416552j)

Quoting http://docs.python.org/3.1/reference/expressions.html:


The power operator binds more tightly than unary operators on its left; it 
binds less tightly than unary operators on its right.


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


Re: Bizarre arithmetic results

2010-02-11 Thread Shashwat Anand
Do you really believe that -0.1 ** 0.1 is a valid computational problem ?
Can you raise a negative number to a fractional power ?
Output on my console (python 2.6)

 -.1 ** .1
-0.79432823472428149
 a,b = -.1,.1
 a**b
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: negative number cannot be raised to a fractional power
 -abs(a**b)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: negative number cannot be raised to a fractional power

There is a little issue here that ' -.1 ** .1' should give you error
message. That is it.


On Thu, Feb 11, 2010 at 6:14 AM, Terrence Cole 
list-s...@trainedmonkeystudios.org wrote:

 Can someone explain to me what python is doing here?

 Python 3.1.1 (r311:74480, Feb  3 2010, 13:36:47)
 [GCC 4.3.4] on linux2
 Type help, copyright, credits or license for more information.
  -0.1 ** 0.1
 -0.7943282347242815
  a = -0.1; b = 0.1
  a ** b
 (0.7554510437117542+0.2454609236416552j)
  -abs(a ** b)
 -0.7943282347242815

 Why does the literal version return the signed magnitude and the
 variable version return a complex?

 Cheers,
 Terrence

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

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


Re: Bizarre arithmetic results

2010-02-11 Thread Christian Heimes
Terrence Cole wrote:
 -0.1 ** 0.1
 -0.7943282347242815
 a = -0.1; b = 0.1
 a ** b
 (0.7554510437117542+0.2454609236416552j)
 -abs(a ** b)
 -0.7943282347242815
 
 Why does the literal version return the signed magnitude and the
 variable version return a complex?

The binary power operator has a higher precedence than the unary
negative operator. -0.1 ** 0.1 is equal to -(0.1**0.1)

Christian

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


Re: Bizarre arithmetic results

2010-02-11 Thread Shashwat Anand
Just realized my flaw

 .1**.1
0.79432823472428149
 (-.1)**(.1)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: negative number cannot be raised to a fractional power

- a ** b = - (a ** b) and not (-a) ** b, Thats why -.1**.1 giving you
-0.79432823472428149 since .1 ** .1 = 0.79432823472428149 and minus sign is
appended prior to it.

On Thu, Feb 11, 2010 at 6:01 PM, Shashwat Anand anand.shash...@gmail.comwrote:

 Do you really believe that -0.1 ** 0.1 is a valid computational problem ?
 Can you raise a negative number to a fractional power ?
 Output on my console (python 2.6)

  -.1 ** .1
 -0.79432823472428149
  a,b = -.1,.1
  a**b
 Traceback (most recent call last):
   File stdin, line 1, in module
 ValueError: negative number cannot be raised to a fractional power
  -abs(a**b)
 Traceback (most recent call last):
   File stdin, line 1, in module
 ValueError: negative number cannot be raised to a fractional power

 There is a little issue here that ' -.1 ** .1' should give you error
 message. That is it.



 On Thu, Feb 11, 2010 at 6:14 AM, Terrence Cole 
 list-s...@trainedmonkeystudios.org wrote:

 Can someone explain to me what python is doing here?

 Python 3.1.1 (r311:74480, Feb  3 2010, 13:36:47)
 [GCC 4.3.4] on linux2
 Type help, copyright, credits or license for more information.
  -0.1 ** 0.1
 -0.7943282347242815
  a = -0.1; b = 0.1
  a ** b
 (0.7554510437117542+0.2454609236416552j)
  -abs(a ** b)
 -0.7943282347242815

 Why does the literal version return the signed magnitude and the
 variable version return a complex?

 Cheers,
 Terrence

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



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


Re: Bizarre arithmetic results

2010-02-11 Thread Jussi Piitulainen
Terrence Cole writes:

 Can someone explain to me what python is doing here?
 
 Python 3.1.1 (r311:74480, Feb  3 2010, 13:36:47) 
 [GCC 4.3.4] on linux2
 Type help, copyright, credits or license for more information.
  -0.1 ** 0.1
 -0.7943282347242815
  a = -0.1; b = 0.1
  a ** b
 (0.7554510437117542+0.2454609236416552j)
  -abs(a ** b)
 -0.7943282347242815
 
 Why does the literal version return the signed magnitude and the
 variable version return a complex?

The minus sign is not part of the literal syntax. Python takes the
expression as -(0.1 ** 0.1), the binary operator binding tighter than
the unary.

Try (-0.1) ** 0.1, and try a = 0.1, then -a ** 0.1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bizarre arithmetic results

2010-02-11 Thread Tim Chase

Terrence Cole wrote:

Can someone explain to me what python is doing here?

Python 3.1.1 (r311:74480, Feb  3 2010, 13:36:47) 
[GCC 4.3.4] on linux2

Type help, copyright, credits or license for more information.

-0.1 ** 0.1

-0.7943282347242815

a = -0.1; b = 0.1
a ** b

(0.7554510437117542+0.2454609236416552j)

-abs(a ** b)

-0.7943282347242815

Why does the literal version return the signed magnitude and the
variable version return a complex?


I think this recently showed up on the list and the answer 
involved the order of operations and precedence of - vs. **. 
 To check, try


   (-0.1) ** 0.1
   -(0.1 ** 0.1)

The first one is what the assignment-to-variables gains you, but 
I think ** has a higher precedence than the unary-- so it 
gets performed first.


I don't have Py3 on my machine here, and 2.5 rejects the first form:

Python 2.5.4 (r254:67916, Nov 19 2009, 19:46:21) [GCC 4.3.4] on 
linux2
Type help, copyright, credits or license for more 
information.

 -(0.1**0.1)
-0.79432823472428149
 (-0.1)**0.1
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: negative number cannot be raised to a fractional power

But perhaps Py3 changes evaluation, returning an complex number.

-tkc



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


Re: Bizarre arithmetic results

2010-02-11 Thread Daniel Fetchinson
On 2/11/10, Terrence Cole list-s...@trainedmonkeystudios.org wrote:
 Can someone explain to me what python is doing here?

 Python 3.1.1 (r311:74480, Feb  3 2010, 13:36:47)
 [GCC 4.3.4] on linux2
 Type help, copyright, credits or license for more information.
 -0.1 ** 0.1
 -0.7943282347242815
 a = -0.1; b = 0.1
 a ** b
 (0.7554510437117542+0.2454609236416552j)
 -abs(a ** b)
 -0.7943282347242815

 Why does the literal version return the signed magnitude and the
 variable version return a complex?

Try this and think about operator precedence:

Python 3.1.1 (r311:74480, Dec 13 2009, 16:50:25)
[GCC 4.4.2 20091027 (Red Hat 4.4.2-7)] on linux2
Type help, copyright, credits or license for more information.
 (-0.1)**0.1
(0.7554510437117542+0.2454609236416552j)


I.e. -0.1**0.1 is not the same as (-0.1)**0.1, because it's first
0.1**0.1 and then a minus sign.

HTH,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-11 Thread Martin P. Hellwig

On 02/07/10 19:02, T wrote:

I have a script, which runs as a Windows service under the LocalSystem
account, that I wish to have execute some commands.  Specifically, the
program will call plink.exe to create a reverse SSH tunnel.  Right now
I'm using subprocess.Popen to do so.  When I run it interactively via
an admin account, all is well.  However, when I'm running it via
service, no luck.  I'm assuming this is to do with the fact that it's
trying to run under the LocalSystem account, which is failing.  What
would be the best way around this?  Thanks!


All being said about LS account not having the appropriate rights to 
access the necessary devices/files.


Could it be so simple that the network is plain simply not available at 
all? For wireless connections I believe the connection/authentication by 
default is made in user space. I would save the output of an ipconfig 
run as the LS account to a file and see what is happening.

Perhaps followed by a ping.

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


Re: SimpleXMLRPCServer and client address

2010-02-11 Thread Jean-Michel Pichavant

Stephen Hansen wrote:
On Wed, Feb 10, 2010 at 5:36 PM, Jean-Michel Pichavant 
jeanmic...@sequans.com mailto:jeanmic...@sequans.com wrote:


I don't know exactly what you are trying to do, but if your server
requires informations from the client, it would be better to ask
explicitly the client for those informations.
For instance, if a method requires te client IP address, then the
IP address is definitely a parameter of the method.


I can't answer the OP, as I don't know the answer to his specific 
question-- but er, asking a client to provide one's IP address is not 
really a very workable solution. There's no way to really determine 
your own IP address in a reliable way.


All the usual methods (e.g., 
socket.gethostbyname(socket.gethostname())) can fail and/or be wrong 
in some not terribly uncommon situations. The only reliable way to get 
such a piece of information is to connect to a server, and ask that 
server what address you were connecting to them as. Even then, that IP 
may not be the same as an IP you use to connect to say, a different 
server (on a different network)


--S

You're probably right.
But my point covered only the fact that if a method needs something it 
should ask it explicitly throught parameters, not taking the opportunity 
to guess it since it happens that it's a xmlrpc server and that the 
information could be deduced from the client IP address.


My feeling is that the OP needed something else than the client IP 
address, and was trying at the server side to map client IPs with the 
data he effectively needs. I could be wrong though.


JM




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


exception in Tkinter on Ubtunu...

2010-02-11 Thread Lumbee
...hey guys, I posted this over on the Ubuntu forums with no luck. I'm
running Ubuntu 9.10 and python 2.5. In Idle when I type in a function
I get this error...

 Exception in Tkinter callback
Traceback (most recent call last):
  File /usr/lib/python2.5/lib-tk/Tkinter.py, line 1417, in __call__
return self.func(*args)
  File /usr/lib/python2.5/idlelib/MultiCall.py, line 151, in handler
r = l[i](event)
  File /usr/lib/python2.5/idlelib/CallTips.py, line 55, in
try_open_calltip_event
self.open_calltip(False)
  File /usr/lib/python2.5/idlelib/CallTips.py, line 79, in
open_calltip
self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1])
  File /usr/lib/python2.5/idlelib/CallTipWindow.py, line 66, in
showtip
self.position_window()
  File /usr/lib/python2.5/idlelib/CallTipWindow.py, line 35, in
position_window
self.parencol))
  File /usr/lib/python2.5/lib-tk/Tkinter.py, line 2860, in bbox
self.tk.call((self._w, 'bbox') + args)) or None
  File /usr/lib/python2.5/lib-tk/Tkinter.py, line 1033, in _getints
return tuple(map(getint, self.tk.splitlist(string)))
ValueError: invalid literal for int() with base 10: '(167,'
testNestEggFixed(

...I've tried reinstalling, and am not sure where to go from here. I
also get a 2nd small windows about 2X2 with 'idle' in the title, and
nothing in the box, and I cannot use the mouse if I open a Python
program from Idle. Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Your beloved python features

2010-02-11 Thread jhermann
$ python -c import this
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bizarre arithmetic results

2010-02-11 Thread Duncan Booth
Tim Chase python.l...@tim.thechases.com wrote:

 But perhaps Py3 changes evaluation, returning an complex number.

Yes, the change is documented at 
http://docs.python.org/3.1/reference/expressions.html#the-power-operator

If it is in any of the What's new in Python x.xx documents or in a PEP 
somewhere I haven't spotted it.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


base32hex support in python?

2010-02-11 Thread Vishal Shetye
Hi,
One of the modules that I am currently working on requires base32hex encoding 
as defined by RFC 4648, section 7.
I checked base64 module which has base32encode/decode functionality but not 
with extended hex alphabet.
Is there a module, currently available, that provides this?

As far as I see, it looks fairly simple to add support for base32hex. It 
differs from the base32 encoding only in the alphabet used. I am willing to 
provide a patch.
Just to note, map01 argument won't be applicable to base32hexdecode as this 
encoding uses both 0 (zero) and O (oh) in its alphabet.

Looking at the section 13 of RFC 4648, I think, adding base32hex support would 
make it conform to RFC 4648.

-
Vishal

DISCLAIMER
==
This e-mail may contain privileged and confidential information which is the 
property of Persistent Systems Ltd. It is intended only for the use of the 
individual or entity to which it is addressed. If you are not the intended 
recipient, you are not authorized to read, retain, copy, print, distribute or 
use this message. If you have received this communication in error, please 
notify the sender and delete all copies of this message. Persistent Systems 
Ltd. does not accept any liability for virus infected mails.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to improve this cycle (extracting data from structured array)?

2010-02-11 Thread Alexzive
On Feb 11, 1:08 pm, Tim Chase python.l...@tim.thechases.com wrote:
 Alexzive wrote:
  I am just wondering if there is a quick way to improve this algorithm
  [N is a structured array which hold info about the nodes n of a finite
  element mesh, and n is about 300.000). I need to extract info from N
  and put it in to a 3*n matrix NN which I reshape then with numpy. I
  think to append is quite unefficient:

  ***
  N = odb.rootAssembly.instances['PART-1-1'].nodes

  NN=[]

  B=[0,0,0]
   #auxsiliar vector
  for i in range(len(N)):
      B[0] = N[i].label
      B[1] = N[i].coordinates[0]
      B[2] = N[i].coordinates[1]
      NN = append(NN,B)

 Usually this would be written with a list-comprehension,
 something like

    nn = [(x.label, x.coordinates[0], x.coordinates[1])
          for x in N]

 or if you really need lists-of-lists instead of lists-of-tuples:

    nn = [[x.label, x.coordinates[0], x.coordinates[1]]
          for x in N]

 -tkc

yeah, much better thanks!
Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bizarre arithmetic results

2010-02-11 Thread Mark Dickinson
On Feb 11, 1:38 pm, Duncan Booth duncan.bo...@invalid.invalid wrote:
 Tim Chase python.l...@tim.thechases.com wrote:
  But perhaps Py3 changes evaluation, returning an complex number.

 Yes, the change is documented 
 athttp://docs.python.org/3.1/reference/expressions.html#the-power-operator

 If it is in any of the What's new in Python x.xx documents or in a PEP
 somewhere I haven't spotted it.

Not in the 'what's new' documents, as far as I can tell, but this
change was introduced as part of implementing PEP 3141.

http://www.python.org/dev/peps/pep-3141/

Here's an extract from the PEP, describing the 'Complex' abstract base
class:


class Complex(Number):
Complex defines the operations that work on the builtin complex
type.

In short, those are: conversion to complex, bool(), .real, .imag,
+, -, *, /, **, abs(), .conjugate(), ==, and !=.

If it is given heterogenous arguments, and doesn't have special
knowledge about them, it should fall back to the builtin complex
type as described below.


snip lots of other abstractmethods here

@abstractmethod
def __pow__(self, exponent):
a**b; should promote to float or complex when necessary.
raise NotImplementedError


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


python crash on windows but not on linux

2010-02-11 Thread hjebbers
To all,
I am running an EDI translator, and doing stress tests.
When processing a test with a (relatively) big EDI file(s) on
windowsXP  I get a crash:
'sorry for the inconvenience' etc  (so no clues about what is
causing the problem)

This happens with python 2.4, 2.5, 2.6
It does not happen in the same setuptests on linux. (while the linux
machine has only half of the RAM of the windows machine).
I am quite sure it is not some external module; there's no GUI (apart
from 'print'), no network connections.
Actually, the crash is not predictablethe crash occurs most of the
time...but at different points.

So basically I am wondering how to proceed.
Is it related to a memory problem? (which does not occur on Linux)

any pointer is very welcome,

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


Re: method names nounVerb or verbNoun

2010-02-11 Thread cjw

On 05-Feb-10 14:53 PM, Wanderer wrote:

Which is the more accepted way to compose method names nounVerb or
verbNoun?

For example voltageGet or getVoltage? getVoltage sounds more normal,
but voltageGet is more like voltage.Get. I seem to mix them and I
should probably pick one way and stick with it.

Thanks
I prefer verbNoun.  Let's remember that PEP 8 is a guide, not a set of 
rules.


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


Re: Bizarre arithmetic results

2010-02-11 Thread Robert Kern

On 2010-02-11 06:31 AM, Shashwat Anand wrote:

Do you really believe that -0.1 ** 0.1 is a valid computational problem
? Can you raise a negative number to a fractional power ?
Output on my console (python 2.6)

  -.1 ** .1
-0.79432823472428149
  a,b = -.1,.1
  a**b
Traceback (most recent call last):
   File stdin, line 1, in module
ValueError: negative number cannot be raised to a fractional power
  -abs(a**b)
Traceback (most recent call last):
   File stdin, line 1, in module
ValueError: negative number cannot be raised to a fractional power

There is a little issue here that ' -.1 ** .1' should give you error
message. That is it.


No, fractional powers of negative numbers are perfectly valid mathematically. 
The result is a complex number. In Python 3 (what the OP is using), this has 
been implemented, but not in Python 2.6.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Modifying Class Object

2010-02-11 Thread Steve Holden
Alf P. Steinbach wrote:
 * Steve Holden:
[...]
 In this particular part of the thread I am attempting, unsuccessfully,
 to convince you that a change in *your* behavior would lead to less
 hostility directed towards the way you present your ideas.

 You apparently feel it is quite acceptable to tell people to learn to
 read,
 
 I have not used that expression.
 
 However I have suggest and emphasized that it might help to *read*
 whatever one quotes, when the quoted material (such as one paragraph)
 has not been read.
 
 Telling someone to learn to read is a Steve Holden'sk way to imply
 that the person is an ignoramus who hasn't bothered to learn to read.
 Telling a person to read something that's obviously not been read is
 quite another matter. So, you are misrepresenting  --  again  --  and in
 a quite revealing way, sorry.
 
Pardon me? You used it on December 16 in a response to Mensanator in
message hgbri8$e1...@news.eternal-september.org

M : How about devoting a section on downloading the source files
M : and compiling it on a Mac?

AS: Learn to read.

AS: At the top of every second page it tells you that this is an
AS: introduction based on Windows.

I am sure you will have some glib response as to why this wasn't rude at
all. Allow me to correct you - it was, and rudeness is not welcomed on
comp.lang.python. That doesn't mean it doesn't happen (why, I have even
been known to be rude myself - we are none of us perfect, after all).

I have already given ample evidence that when I am wrong I will admit
it. You, contrariwise, maintain that you will admit when you are wrong
(I believe 40% of the time was the figure you used) but I fail to
remember any single incident when you made such an admission.

 and calling their assertions bullshit,
 
 Yes, in this group, but only for personal attacks.
 
 Such as yours.
 
 I think I've shown extreme restraint in the face of bullying from you
 and some followers, and calling the insinuations bullshit is quite mild.

I don't have followers. Assertions I make are my own, and stand alone
without the need of support. Calling them bullshit is indeed quite
mild, but doesn't invalidate them. You can only do that by engaging, but
instead you hysterically shout ad hominem whenever anyone makes a
personal remark.
 
 but when we try to point
 out aspects of your behavior that are either undesirable or unacceptable
 we are indulging in ad hominem attacks.
 
 That is an untrue and extremely misleading description of what you've
 been doing.
 
I'll let that be judged on the record. You have consistently refused to
accept, despite assertions from several individuals (presumably those
you choose to characterize as my followers, thereby allowing you to
write them off without seriously considering what they say - at least
that is how it looks from the outside) that criticism of your behavior
is not, in fact, an ad hominem attack but an attempt to engage you in
debate and have you modify that behavior.

So, for the final time: remarks about personal characteristics only
constitute ad hominem attacks ONLY when they are made for the purpose of
invalidating other (typically, in this group, technical) arguments.

If we met in person at a conference (God help us both) and you sat in an
open space session picking your nose, would you deem it an ad hominem
attack if I told you to stop? It sounds like it, even though I would
tell you to stop not so that others would respect your technical
arguments any less, but because by departing from the accepted standards
of behavior you would offend others.
 
 In your terms, your accusing me of bullying behavior is an ad hominem
 attack on me, so I won't bother to respond further.
 
 You're complaining about the person you're hitting saying clearly what
 you did.
 
 If some truthful words about bullying can get you straight I'm for it.
 
 Even if it means getting down to your level (and yes, I did).
 
Nope, I'm not complaining at all. That's your tactic: look, Steve is
hitting me. You are entitled to write what you like on this newsgroup,
but you have to accept that it will have consequences. I am simply
pointing out that what's sauce for the goose is sauce for the gander.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: Modifying Class Object

2010-02-11 Thread Steve Holden
Alf P. Steinbach wrote:
 * Steven D'Aprano:
[...]
 accusing them of lying for having an opinion that differs from yours,
 
 That is untrue.
 
Well, that says it all really.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Any way to turn off exception handling? (debugging)

2010-02-11 Thread mk

Hello everyone,

I'm getting an exception (on socket) handled in a program I'm trying to 
debug. I have trouble locating where exactly that happens.


In such situation turning exception handling off could be useful, bc 
unhandled exception stack trace is precisely what I'm trying to obtain.


Anybody knows of such possibility?

Regards,
mk

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


Re: method names nounVerb or verbNoun

2010-02-11 Thread Martin P. Hellwig

On 02/05/10 19:53, Wanderer wrote:

Which is the more accepted way to compose method names nounVerb or
verbNoun?

For example voltageGet or getVoltage? getVoltage sounds more normal,
but voltageGet is more like voltage.Get. I seem to mix them and I
should probably pick one way and stick with it.

Thanks


For me personally I do the following:
spam_get/spam_set; might be preferred if you have more spam_* functions 
(i.e. spam_del, spam_eat, etc.)


set_spam/get_spam; is I think reasonable if you have also a *_ham 
function (i.e. set_ham, get_ham).


Funny thing for me is that when I have both spam_*  *_ham naming, I 
usually rethink my approach and split it out to separate classes/modules.


Please note that this is at the moment a personal, uneducated, never 
really thought about it, preference. Meaning it is very likely that with 
some more insight there is a good chance that I find my approach in 
retrospect flawed.


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


Re: Bizarre arithmetic results

2010-02-11 Thread Jussi Piitulainen
Robert Kern writes:
 On 2010-02-11 06:31 AM, Shashwat Anand wrote:
  There is a little issue here that ' -.1 ** .1' should give you
  error message. That is it.
 
 No, fractional powers of negative numbers are perfectly valid
 mathematically. The result is a complex number. In Python 3 (what
 the OP is using), this has been implemented, but not in Python 2.6.

Perhaps it should raise a MisleadingSpacingError at compile time. The
error message could recommend - .1**.1, or better -(.1 ** .1).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread Steve Holden
mk wrote:
 Hello everyone,
 
 I'm getting an exception (on socket) handled in a program I'm trying to
 debug. I have trouble locating where exactly that happens.
 
 In such situation turning exception handling off could be useful, bc
 unhandled exception stack trace is precisely what I'm trying to obtain.
 
 Anybody knows of such possibility?
 
 Regards,
 mk
 
If the exception is currently being trapped by a handler in your code
you could just insert a raise statement at the start of that handler.
This will re-raise the same exception, which will presumably not be
caught a second time?

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-11 Thread mk

kj wrote:

I have read a *ton* of stuff on Unicode.  It doesn't even seem all
that hard.  Or so I think.  Then I start writing code, and WHAM:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal 
not in range(128)

(There, see?  My Unicodephobia just went up a notch.)

Here's the thing: I don't even know how to *begin* debugging errors
like this.  This is where I could use some help.


 a=u'\u0104'

 type(a)
type 'unicode'

 nu=a.encode('utf-8')

 type(nu)
type 'str'


See what I mean? You encode INTO string, and decode OUT OF string.

To make matters more complicated, str.encode() internally DECODES from 
string into unicode:


 nu
'\xc4\x84'

 type(nu)
type 'str'
 nu.encode()
Traceback (most recent call last):
  File stdin, line 1, in module
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: 
ordinal not in range(128)


There's logic to this, although it makes my brain want to explode. :-)

Regards,
mk


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


Re: Dreaming of new generation IDE

2010-02-11 Thread Bruno Desthuilliers

catonano a écrit :
(snip)

Today, I tried to understand the twisted.web.client code and I found 3
methods I couldn't find by who were called.

I asked on the mailing list and they suggested me where they were
called and that the tool for such thing is grep.

So, you grep, you get a list of files, you open each one of them and
keep scrolling


May I suggest reading grep's FineManual ? with proper options, you'll 
get not only the file, but also the exact lines (and lineno) where the 
expression appears.



If it's this, then it's not experimental at all, it's been done
already and been put apart.

Crap won :-(


Ever read worst is better ?-)

Now, image-based systems like Smalltalk do have their share of quirks 
and drawbacks too.


Also, Smalltalk's toolbox can only be used by and for Smalltalk. A bit 
autistic, he ?


I'm doing mostly web development nowadays. That means that I'm 
constantly switching between server-side code (mostly Python or PHP but 
 can be almost any other language), shell scripts, SQL, html + whatever 
templating language is used by this project, javascript and css. And of 
course quite a few configuration file formats...


So well, as far as I'm concerned, not having to learn 42+ different 
toolboxes is a big plus (having to remember 42+ different languages is 
already hard enough) - I can use a same code editor (Emacs) and standard 
unix/linux text-handling tools on all my codebase.


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


Re: Terminating threaded programs

2010-02-11 Thread Aahz
In article mailman.1961.1265383809.28905.python-l...@python.org,
mk  mrk...@gmail.com wrote:

I have a problem with a threaded program: it frequently hangs on sys.exit.

The problem is that my program uses threads which in turn use paramiko 
library, which itself is threaded.

I try to gracefully close the threads (below), but it doesn't always 
work, if paramiko calls happen to be at stage of negotiating ssh 
connection or smth similar.

The only workable solution I have is a program sending itself SIGKILL, 
which makes it terminated by OS (I think so).

You can also use os._exit().
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

At Resolver we've found it useful to short-circuit any doubt and just
refer to comments in code as 'lies'. :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread mk

Steve Holden wrote:

I'm getting an exception (on socket) handled in a program I'm trying to
debug. I have trouble locating where exactly that happens.



If the exception is currently being trapped by a handler in your code


It's not my code.


you could just insert a raise statement at the start of that handler.
This will re-raise the same exception, which will presumably not be
caught a second time?


I don't know where the handler is, that is precisely a problem. I'm 
trying to locate that handler.


Regards,
mk

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread Simon Brunning
On 11 February 2010 16:17, mk mrk...@gmail.com wrote:
 I'm getting an exception (on socket) handled in a program I'm trying to
 debug. I have trouble locating where exactly that happens.

 In such situation turning exception handling off could be useful, bc
 unhandled exception stack trace is precisely what I'm trying to obtain.

 Anybody knows of such possibility?

Not as far as I know. Besides, the chances are that if you were to be
able to turn off exception handling altogether your code wouldn't make
it as far as the code you are interested in anyway.

Is there some way you could monkey patch the exception class to add
some logging in there or something?

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread mk

Simon Brunning wrote:

Not as far as I know. Besides, the chances are that if you were to be
able to turn off exception handling altogether your code wouldn't make
it as far as the code you are interested in anyway.


Sure, but I could deal with that, jerry-rigging the code as exceptions 
go by, finally reaching the exception I care about.


With all the problems, this would still be much better than nothing. As 
thing are, the only way to do this is guessing and turning particular 
try / except blocks off.


(a really nifty solution would be turning exceptions on or off per 
module / file basis).


IIRC Lua and/or C++ do have this ability, why not Python?

I smell material for a PEP.


Is there some way you could monkey patch the exception class to add
some logging in there or something?


Sure I can, but how do I get out of Python the info *what called 
particular class/instance*? That is, how do I know who's the caller?


Regards,
mk

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


Re: Dreaming of new generation IDE

2010-02-11 Thread Francis Carr
 I can't believe the code editing situation today is in a such sorry
 state.
I can't believe an old coder is feeling so sorry for himself.


 Today, I tried to understand the twisted.web.client code and I found 3
 methods I couldn't find by who were called.

 I asked on the mailing list and they suggested me where they were
 called and that the tool for such thing is grep.

 So, you grep, you get a list of files, you open each one of them and
 keep scrolling and switching from one file to another... endlessly.
 Maybe I'm getting old, but I tend to get lost in the process.

Maybe the relevant lesson to be taken from Smalltalk is *not*
  put it all in one image
but instead
  write code to solve problems, e.g., reading code


I suggest defining a few shell functions to *automate* the search, for
example in zsh

function allf () {
  # Recursively find files with suffix matching comma-separated list
in $1.
  # For example, allf cpp,hpp finds all *.cpp and *.hpp.
  find . -type f | grep -E \.(${1//,/|})$
}

function src () {
  # Similar to allf, then search for a regex among the results.
  find . -type f -print0 | grep -zE \.(${1//,/|})$ | xargs -0 grep -
lE $2
}

function srcl () {
  # Similar to src (see above),
  # then search for a pattern among the results,
  # and pass matching files to less.
  src $1 $2 | xargs less -p $2
}


Smalltalk's images are cool.  But they are such a huge hammer, and
they impose so many additional requirements!  The costs outweigh the
cool.

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


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-11 Thread kj


In mailman.2379.1265906673.28905.python-l...@python.org mk mrk...@gmail.com 
writes:

To make matters more complicated, str.encode() internally DECODES from 
string into unicode:

  nu
'\xc4\x84'
 
  type(nu)
type 'str'
  nu.encode()
Traceback (most recent call last):
   File stdin, line 1, in module
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: 
ordinal not in range(128)

There's logic to this, although it makes my brain want to explode. :-)


Thanks for pointing this one out!  It could have easily pushed my
Unicodephobia into the incurable zone...

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread Stephen Hansen
On Thu, Feb 11, 2010 at 9:32 AM, mk mrk...@gmail.com wrote:

 Simon Brunning wrote:

 Not as far as I know. Besides, the chances are that if you were to be
 able to turn off exception handling altogether your code wouldn't make
 it as far as the code you are interested in anyway.


 Sure, but I could deal with that, jerry-rigging the code as exceptions go
 by, finally reaching the exception I care about.

 With all the problems, this would still be much better than nothing. As
 thing are, the only way to do this is guessing and turning particular try /
 except blocks off.

 (a really nifty solution would be turning exceptions on or off per module /
 file basis).

 IIRC Lua and/or C++ do have this ability, why not Python?

 I smell material for a PEP.


Um, Lua has nothing even vaguely like Python's exceptions. It has errors,
and you can catch them only by doing a protected call. Otherwise they halt
the entire interpreter.

Python exceptions are pervasive. I don't think you fully understand HOW
pervasive they are-- turning off exceptions would utterly break a -vast-
amount of Python code. Exceptions are not errors: exceptions are the
uncommon, the exceptional, case. If one could somehow turn off exceptions,
you can't even do a for loop: every for loop would become infinite--
exceptions are how Python signals the end of an iterator. Think about that,
*every* for loop in Python suddenly breaks.

They're also used in countless other areas which are simply not errors.


  Is there some way you could monkey patch the exception class to add
 some logging in there or something?


 Sure I can, but how do I get out of Python the info *what called particular
 class/instance*? That is, how do I know who's the caller?


Um... run your code in a debugger.

That's what debugger's are -for-.

pdb is a simple one. Various IDE's have more advanced ones.

I think you're better served showing us what, I'm getting an exception (on
socket) handled... actually means, what is actually happening with real
code and output, and getting pointers on where to look, then trying to
gather material to support an honestly impossible change :)

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


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-11 Thread MRAB

mk wrote:

kj wrote:

I have read a *ton* of stuff on Unicode.  It doesn't even seem all
that hard.  Or so I think.  Then I start writing code, and WHAM:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 
0: ordinal not in range(128)


(There, see?  My Unicodephobia just went up a notch.)

Here's the thing: I don't even know how to *begin* debugging errors
like this.  This is where I could use some help.


  a=u'\u0104'
 
  type(a)
type 'unicode'
 
  nu=a.encode('utf-8')
 
  type(nu)
type 'str'


See what I mean? You encode INTO string, and decode OUT OF string.


Traditionally strings were string of byte-sized characters. Because they
were byte-sided they could also be used to contain binary data.

Then along came Unicode.

When working with Unicode in Python 2, you should use the 'unicode' type
for text (Unicode strings) and limit the 'str' type to binary data
(bytestrings, ie bytes) only.

In Python 3 they've been renamed to 'str' for Unicode _strings_ and
'bytes' for binary data (bytes!).

To make matters more complicated, str.encode() internally DECODES from 
string into unicode:


  nu
'\xc4\x84'
 
  type(nu)
type 'str'
  nu.encode()
Traceback (most recent call last):
  File stdin, line 1, in module
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: 
ordinal not in range(128)


There's logic to this, although it makes my brain want to explode. :-)


Strictly speaking, only Unicode can be encoded.

What Python 2 is doing here is trying to be helpful: if it's already a
bytestring then decode it first to Unicode and then re-encode it to a
bytestring.

Unfortunately, the default encoding is ASCII, and the bytestring isn't
valid ASCII. Python 2 is being 'helpful' in a bad way!
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: obfuscate

2010-02-11 Thread MRAB

Christian Heimes wrote:

Gregory Ewing wrote:

Actually I gather it had a lot to do with the fact that the Germans
made some blunders in the way they used the Enigma that seriously
compromised its security. There was reportedly a branch of the
German forces that used their Enigmas differently, avoiding those
mistakes, and the British never managed to crack any of their
messages.


IIRC some versions of the Enigma weren't cracked because they used a 
different setup and different daily keys.


The predecessor of the Enigma was cracked by Polish scientists years 
before WW2 started. Some flaws in the instructions and a known plain 
text attack made the crack of the Enigma practical. It took the

British scientists merely hours rather than days or weeks to decipher
the daily key with some smart tricks. For example they started fake
attacks on ships or cities just to have the names in some encrypted
reports.


In some cases the British had decoded the messages before the intended
recipient!

The Americans decoded Japanese messages about an planned attack on an
island, but didn't know which one because of the fake names, so they
instructed their bases to report certain problems in a way that the
Japanese could decode.

Midway reported a shortage of water, the Japanese decoded it and sent a
message about it, the Americans decoded their message and discovered
that island's fake name, and thus found out that Midway was the intended
target of the attack.

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread mk


the uncommon, the exceptional, case. If one could somehow turn off 
exceptions, you can't even do a for loop: every for loop would become 
infinite-- exceptions are how Python signals the end of an iterator. 
Think about that, *every* for loop in Python suddenly breaks. 


Ouch.


Sure I can, but how do I get out of Python the info *what called
particular class/instance*? That is, how do I know who's the caller?


Um... run your code in a debugger.


..except the code in question is multithreaded and pdb is no good for 
that, and last time I checked, yappi was broken.




That's what debugger's are -for-.

pdb is a simple one. Various IDE's have more advanced ones.


I tried using pdb on paramiko and my own threaded code, lost some hair 
in the process, and gave up. It's good for tracing the main thread, 
basically, not for threading.Threads.


I think you're better served showing us what, I'm getting an exception 
(on socket) handled... actually means, what is actually happening with 
real code and output, and getting pointers on where to look, then trying 
to gather material to support an honestly impossible change :)


I'm using a threaded library paramiko (probably by now half of this 
group is sick of hearing me saying this again). 2 of (rather broken) 
hosts (Solaris, Linux) are really, really slow when responding over SSH, 
like a minute for a key exchange. In paramiko, timeout doesn't work bc 
the timeout specified there is timeout for a socket and not for SSH.


When calling transport.socket.close() via threading.Timer like this:

def printandclose(self):
print \ntrying to close transport.sock
self.trans.sock.close()
self.flag = True


self.flag = False
timer = threading.Timer(4, self.printandclose)
timer.start()
self.trans.start_client()
timer.cancel()

... I'm getting this on the console:

ERROR (9, 'Bad file descriptor')

According to a guy who is very knowledgable on the library (thanks for 
all the help, James) this is result of catching socket.error somewhere 
in paramiko code, like except socket.error.


I need to find that place. On top of lack of proper handling of 
timeouts, this is important bc when calling paramiko SSHClient.connect() 
(which in turn uses the same machinery as transport.start_client IIRC) 
paramiko uses close to 100% of CPU when negotiating with such broken or 
unresponsive hosts.


For my reasons, I need to get this fixed.

Regards,
mk


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


Re: ANN: obfuscate

2010-02-11 Thread Matthew Barnett

Paul Rubin wrote:

Gregory Ewing greg.ew...@canterbury.ac.nz writes:

Actually I gather it had a lot to do with the fact that the Germans
made some blunders in the way they used the Enigma that seriously
compromised its security. There was reportedly a branch of the German
forces that used their Enigmas differently, avoiding those mistakes,
and the British never managed to crack any of their messages.


I think you are thinking of the Kriegsmarine (naval) Enigma.  Yes they
were more careful with procedures, but the machine was also harder to
crack because it had four rotors instead of three.  IIRC, the Brits were
eventually (1942?) able to capture one by shooting up a German submarine
and boarding it to get the machine while the sub was sinking; a British
sailor wasn't able to get out in time and drowned during that operation.
Getting the rotor settings off the captured unit (they may have had to
do it more than once) was enough to get a foothold into the code.  My
memory is hazy on this by now so I may have some parts wrong, but David
Kahn's book Seizing the Enigma tells the story (I read it many years
ago).  A fictionalized version appears in Neil Stephenson's novel
Cryptonomicon.


U-559? I think that's the one where Hollywood made a film about it, but
portraying it as a purely American action. That didn't go down too well
in the UK!
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: obfuscate

2010-02-11 Thread MRAB

Paul Rubin wrote:

Gregory Ewing greg.ew...@canterbury.ac.nz writes:

Actually I gather it had a lot to do with the fact that the Germans
made some blunders in the way they used the Enigma that seriously
compromised its security. There was reportedly a branch of the German
forces that used their Enigmas differently, avoiding those mistakes,
and the British never managed to crack any of their messages.


I think you are thinking of the Kriegsmarine (naval) Enigma.  Yes they
were more careful with procedures, but the machine was also harder to
crack because it had four rotors instead of three.  IIRC, the Brits were
eventually (1942?) able to capture one by shooting up a German submarine
and boarding it to get the machine while the sub was sinking; a British
sailor wasn't able to get out in time and drowned during that operation.
Getting the rotor settings off the captured unit (they may have had to
do it more than once) was enough to get a foothold into the code.  My
memory is hazy on this by now so I may have some parts wrong, but David
Kahn's book Seizing the Enigma tells the story (I read it many years
ago).  A fictionalized version appears in Neil Stephenson's novel
Cryptonomicon.


U-559? I think that's the one where Hollywood made a film about it, but
portraying it as a purely American action. That didn't go down too well
in the UK!

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread Paul Rubin
mk mrk...@gmail.com writes:
 Um... run your code in a debugger.

 ..except the code in question is multithreaded and pdb is no good for
 that, and last time I checked, yappi was broken.

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread mk

Stephen Hansen wrote:
the uncommon, the exceptional, case. If one could somehow turn off 
exceptions, you can't even do a for loop: every for loop would become 
infinite-- exceptions are how Python signals the end of an iterator. 
Think about that, *every* for loop in Python suddenly breaks. 


Hmm what if one could turn off exception handling for particular 
exception classes?


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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread Peter Otten
mk wrote:

 
 the uncommon, the exceptional, case. If one could somehow turn off
 exceptions, you can't even do a for loop: every for loop would become
 infinite-- exceptions are how Python signals the end of an iterator.
 Think about that, *every* for loop in Python suddenly breaks.
 
 Ouch.
 
 Sure I can, but how do I get out of Python the info *what called
 particular class/instance*? That is, how do I know who's the caller?
 
 
 Um... run your code in a debugger.
 
 ..except the code in question is multithreaded and pdb is no good for
 that, and last time I checked, yappi was broken.
 
 
 That's what debugger's are -for-.
 
 pdb is a simple one. Various IDE's have more advanced ones.
 
 I tried using pdb on paramiko and my own threaded code, lost some hair
 in the process, and gave up. It's good for tracing the main thread,
 basically, not for threading.Threads.
 
 I think you're better served showing us what, I'm getting an exception
 (on socket) handled... actually means, what is actually happening with
 real code and output, and getting pointers on where to look, then trying
 to gather material to support an honestly impossible change :)
 
 I'm using a threaded library paramiko (probably by now half of this
 group is sick of hearing me saying this again). 2 of (rather broken)
 hosts (Solaris, Linux) are really, really slow when responding over SSH,
 like a minute for a key exchange. In paramiko, timeout doesn't work bc
 the timeout specified there is timeout for a socket and not for SSH.
 
 When calling transport.socket.close() via threading.Timer like this:
 
 def printandclose(self):
  print \ntrying to close transport.sock
  self.trans.sock.close()
  self.flag = True
 
 
 self.flag = False
 timer = threading.Timer(4, self.printandclose)
 timer.start()
 self.trans.start_client()
 timer.cancel()
 
 ... I'm getting this on the console:
 
 ERROR (9, 'Bad file descriptor')
 
 According to a guy who is very knowledgable on the library (thanks for
 all the help, James) this is result of catching socket.error somewhere
 in paramiko code, like except socket.error.
 
 I need to find that place. On top of lack of proper handling of
 timeouts, this is important bc when calling paramiko SSHClient.connect()
 (which in turn uses the same machinery as transport.start_client IIRC)
 paramiko uses close to 100% of CPU when negotiating with such broken or
 unresponsive hosts.
 
 For my reasons, I need to get this fixed.

You could try to shadow the exception class with None:

 ZeroDivisionError = None
 try:
... 1/0
... except ZeroDivisionError:
... print caught
...
Traceback (most recent call last):
  File stdin, line 2, in module
ZeroDivisionError: integer division or modulo by zero

Applying that technique on a module containing

try: 
   ...
except socket.error: 
   ...

#untested
import socket

class SocketWrapper:
def __getattr__(self, name):
return getattr(socket, name)
error = None

import module_using_socket
module_using_socket.socket = SocketWrapper()

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread Steve Holden
mk wrote:
 Stephen Hansen wrote:
 the uncommon, the exceptional, case. If one could somehow turn off
 exceptions, you can't even do a for loop: every for loop would become
 infinite-- exceptions are how Python signals the end of an iterator.
 Think about that, *every* for loop in Python suddenly breaks. 
 
 Hmm what if one could turn off exception handling for particular
 exception classes?
 
An extension of the warnings mechanism might be the easiest way to play
with an implementation ...

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: ANN: obfuscate

2010-02-11 Thread Mark Lawrence

Christian Heimes wrote:

Gregory Ewing wrote:

Actually I gather it had a lot to do with the fact that
the Germans made some blunders in the way they used the
Enigma that seriously compromised its security. There
was reportedly a branch of the German forces that used
their Enigmas differently, avoiding those mistakes, and
the British never managed to crack any of their messages.


IIRC some versions of the Enigma weren't cracked because they used a
different setup and different daily keys.

The predecessor of the Enigma was cracked by Polish scientists years
before WW2 started. Some flaws in the instructions and a known plain
text attack made the crack of the Enigma practical. It took the British
scientists merely hours rather than days or weeks to decipher the daily
key with some smart tricks. For example they started fake attacks on
ships or cities just to have the names in some encrypted reports.


I believe that all of Enigma was eventually cracked cos of two major flaws.
1) A letter could never be sent as itself.
2) The Luftwaffe were very poor when compared to the Wehrmacht or 
Kriegsmarine about security so they were a major leak of data regarding 
the other organisations.
3) The users instead of using random three letter combinations kept 
using the same ones.  HIT LER and BER LIN were popular, but the most 
famous one at Bletchley Park was the name of the guy's girlfriend.


Further, the far more powerful Geheimscreiber was also cracked at 
Bletchley by using Colossus.  Sorry some years since I read the book 
about this so can't remember the title or author.


Regards.

Mark Lawrence.

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


Re: Terminating threaded programs

2010-02-11 Thread sstein...@gmail.com

On Feb 11, 2010, at 11:43 AM, Aahz wrote:

 In article mailman.1961.1265383809.28905.python-l...@python.org,
 mk  mrk...@gmail.com wrote:
 
 I have a problem with a threaded program: it frequently hangs on sys.exit.
 
 The problem is that my program uses threads which in turn use paramiko 
 library, which itself is threaded.
 
 I try to gracefully close the threads (below), but it doesn't always 
 work, if paramiko calls happen to be at stage of negotiating ssh 
 connection or smth similar.
 
 The only workable solution I have is a program sending itself SIGKILL, 
 which makes it terminated by OS (I think so).
 
 You can also use os._exit().

This just came up on the Twisted IRC channel last night and came to the same 
conclusion.  Python's going to wait for threads to terminate and if they're not 
going to, neither is Python.  os._exit() came up as the 'last resort' way out 
of the app.

S

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread mk

Paul Rubin wrote:

mk mrk...@gmail.com writes:

Um... run your code in a debugger.

..except the code in question is multithreaded and pdb is no good for
that, and last time I checked, yappi was broken.


Try winpdb.org.


This is a treasure! In minutes I've had this attached to remote process 
and debugging threads.


Muchos gracias Paul!

Regards,
mk


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


python and http POST

2010-02-11 Thread galileo228
Hey All,

Been teaching myself Python for a few weeks, and am trying to write a
program that will go to a url, enter a string in one of the search
fields, submit the search, and return the contents of the search
result.

I'm using httplib2.

My two particular questions:

1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}),
how do I know what the particular key should be? In other words, how
do I tell python which form on the web page I'm visiting I'd like to
fill in? Do I simply go to the webpage itself and look at the html
source? But if that's the case, which tag tells me the name of the
key?

2) Even once python fills in the form properly, how can I tell it to
'submit' the search?

Thanks all!

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread mk

Peter Otten wrote:

try: 
   ...
except socket.error: 
   ...


#untested
import socket

class SocketWrapper:
def __getattr__(self, name):
return getattr(socket, name)
error = None

import module_using_socket
module_using_socket.socket = SocketWrapper()


Very interesting solution. Thanks!

Regards,
mk




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


Re: python crash on windows but not on linux

2010-02-11 Thread hjebbers
On Feb 11, 7:01 pm, Peter Otten __pete...@web.de wrote:
 hjebbers wrote:
  On Feb 11, 5:45 pm, M3RT mgul...@gmail.com wrote:
  The problem may be related to how you treat the EDI file or lets say
  DATA. Also your coding style is important. Can you provide more info?

  Yes, a whole lot more; but I do not want to bother you with that now.
  I was just wondering if it is possible that the same setup gives a
  CRASH! on windows and just works on linux.
  (where is the bug?)

 In the platform-specific code ;)

 Even on alt.haruspicy they cannot do much without a liver now and then...

if it is in the platform-specific code should I make this into a
bugreport?
(because the crash does not appear at the same place in my code (when
doing the same test-run) it will be quite hard to point down)

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


Re: python crash on windows but not on linux

2010-02-11 Thread hjebbers
On Feb 11, 7:01 pm, Peter Otten __pete...@web.de wrote:
 hjebbers wrote:
  On Feb 11, 5:45 pm, M3RT mgul...@gmail.com wrote:
  The problem may be related to how you treat the EDI file or lets say
  DATA. Also your coding style is important. Can you provide more info?

  Yes, a whole lot more; but I do not want to bother you with that now.
  I was just wondering if it is possible that the same setup gives a
  CRASH! on windows and just works on linux.
  (where is the bug?)

 In the platform-specific code ;)

 Even on alt.haruspicy they cannot do much without a liver now and then...

if it is in the platform-specific code should I make this into a
bugreport?
(because the crash does not appear at the same place in my code (when
doing the same test-run) it will be quite hard to point down)

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


MODULE FOR I, P FRAME

2010-02-11 Thread DANNY
Hello!

I am currently developing a simple video player in python, and my
problem is that i can't find a module which has a function that can
determine if frame(image) is I or P coded (MPEG coding). I have been
using PIL but I couldnt find anything that could help me with that
problem.

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


Re: python crash on windows but not on linux

2010-02-11 Thread Jerry Hill
On Thu, Feb 11, 2010 at 9:32 AM, hjebbers hjebb...@gmail.com wrote:
 To all,
 I am running an EDI translator, and doing stress tests.
 When processing a test with a (relatively) big EDI file(s) on
 windowsXP  I get a crash:
    'sorry for the inconvenience' etc  (so no clues about what is
 causing the problem)


You need to give us more information if we're going to be able to
help.  At the very least, you'll need to copy  paste the actual error
message.  It would be even better if you could show us some of your
code, and better yet if you could give us a small bit of code that is
self contained and reproduces the problem you're experiencing.

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


Re: python crash on windows but not on linux

2010-02-11 Thread hjebbers
On Feb 11, 7:01 pm, Peter Otten __pete...@web.de wrote:
 hjebbers wrote:
  On Feb 11, 5:45 pm, M3RT mgul...@gmail.com wrote:
  The problem may be related to how you treat the EDI file or lets say
  DATA. Also your coding style is important. Can you provide more info?

  Yes, a whole lot more; but I do not want to bother you with that now.
  I was just wondering if it is possible that the same setup gives a
  CRASH! on windows and just works on linux.
  (where is the bug?)

 In the platform-specific code ;)

 Even on alt.haruspicy they cannot do much without a liver now and then...

if it is in the platform-specific code should I make this into a
bugreport?
(because the crash does not appear at the same place in my code (when
doing the same test-run) it will be quite hard to point down)

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


PExpect Cross-Platform Alternative

2010-02-11 Thread Nathan Farrar
Hello Community,

Recently I've been automating lots of network operations tasks via simple
python scripts.  Originally, I utilized paramiko but found that the module
had issues working with cisco equipment.  I switched to pexpect and things
have worked wonderfully since (I've been running this scripts in a Linux
environment).  However, I was just tasked to get these scripts running in a
windows environment and to my dismay very quickly realized that pexpect is
not cross platform compatible.

Am I stuck, or are there solutions out there?

Cheers!
Nathan

-- 
The men the American people admire most extravagantly are the most daring
liars; the men they detest most violently are those who try to tell them the
truth. -- H. L. Mencken
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-11 Thread Alf P. Steinbach

* Steve Holden:

Alf P. Steinbach wrote:

* Steven D'Aprano:

[...]

accusing them of lying for having an opinion that differs from yours,

That is untrue.


Well, that says it all really.


You seem to insinuate that I'm saying that Steven is lying, and/or that Steven 
is lying.


From context and your earlier similar behavior, I presume the former only.

Anyway that's a *very* dirty insinuation.

And ...

It seems you *do not understand* the difference between an incorrect statement 
and a lie.


Which is very telling, I'm sorry.

And you have yet again concentrated on a personal attack via insinuation etc., 
diversion, which also is very telling, sorry.



Cheers,

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


Re: python and http POST

2010-02-11 Thread Ken Seehart
Use tamperdata to view and modify HTTP/HTTPS headers and post 
parameters... 


https://addons.mozilla.org/en-US/firefox/addon/966

Enjoy,
Ken

galileo228 wrote:

Hey All,

Been teaching myself Python for a few weeks, and am trying to write a
program that will go to a url, enter a string in one of the search
fields, submit the search, and return the contents of the search
result.

I'm using httplib2.

My two particular questions:

1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}),
how do I know what the particular key should be? In other words, how
do I tell python which form on the web page I'm visiting I'd like to
fill in? Do I simply go to the webpage itself and look at the html
source? But if that's the case, which tag tells me the name of the
key?

2) Even once python fills in the form properly, how can I tell it to
'submit' the search?

Thanks all!

Matt
  


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


Re: PExpect Cross-Platform Alternative

2010-02-11 Thread Steve Holden
Nathan Farrar wrote:
 Hello Community,
 
 Recently I've been automating lots of network operations tasks via
 simple python scripts.  Originally, I utilized paramiko but found that
 the module had issues working with cisco equipment.  I switched to
 pexpect and things have worked wonderfully since (I've been running this
 scripts in a Linux environment).  However, I was just tasked to get
 these scripts running in a windows environment and to my dismay very
 quickly realized that pexpect is not cross platform compatible.
 
 Am I stuck, or are there solutions out there?
 
It works pretty well under Cygwin (which also improves your Windows
scripting environment no end). Any chance you would be allowed to
install that?

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: Modifying Class Object

2010-02-11 Thread Alf P. Steinbach

* Steve Holden:

Alf P. Steinbach wrote:

* Steve Holden:

[...]

In this particular part of the thread I am attempting, unsuccessfully,
to convince you that a change in *your* behavior would lead to less
hostility directed towards the way you present your ideas.

You apparently feel it is quite acceptable to tell people to learn to
read,

I have not used that expression.

However I have suggest and emphasized that it might help to *read*
whatever one quotes, when the quoted material (such as one paragraph)
has not been read.

Telling someone to learn to read is a Steve Holden'sk way to imply
that the person is an ignoramus who hasn't bothered to learn to read.
Telling a person to read something that's obviously not been read is
quite another matter. So, you are misrepresenting  --  again  --  and in
a quite revealing way, sorry.


Pardon me? You used it on December 16 in a response to Mensanator in
message hgbri8$e1...@news.eternal-september.org

M : How about devoting a section on downloading the source files
M : and compiling it on a Mac?

AS: Learn to read.

AS: At the top of every second page it tells you that this is an
AS: introduction based on Windows.

I am sure you will have some glib response as to why this wasn't rude at
all. Allow me to correct you - it was, and rudeness is not welcomed on
comp.lang.python. That doesn't mean it doesn't happen (why, I have even
been known to be rude myself - we are none of us perfect, after all).

I have already given ample evidence that when I am wrong I will admit
it. You, contrariwise, maintain that you will admit when you are wrong
(I believe 40% of the time was the figure you used)


No, 40% of contested cases. But that was sort of a white lie. I'm not that often 
wrong, and anyway it doesn't apply to me in [comp.lang.python] so far. It only 
applies to groups where only things that might be incorrect are challenged.




but I fail to
remember any single incident when you made such an admission.


Your memory seems to be very very bad, since I've stated I've been wrong also in 
direct debates with you.


But one person who /does/ have severe trouble admitting that he's wrong, going 
to the extreme of ad hominem attacks and using terms such as wring to avoid 
saying it (it's quite amazing, almost unbelievable) is Steve Holden.


Anyway, I was wrong about not having used that phrase learn to read.

I'm not sure if I ever apologized directly to Mensanator for that, and now it's 
history, but what I do know I did was to follow up on that comment of his, 
making changes, and to acknowledge him for that in the [ack.txt] listing.


Any reader might draw conclusions from that, e.g. what I positively did or what 
I possibly forgot to do  --  we're not perfect beings any of us.



[Steve Holden rambling with personal characterizations  circular logic snipped]


Cheers  hth.,

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


Re: Terminating threaded programs

2010-02-11 Thread mk

Stephen Hansen wrote:
I use threads all the time (well, for certain types of workloads) and 
have never seen this.


Are your threads daemon threads? The only time I've seen sys.exit() not 
close out my program is when I'm launching non-daemon threads on accident.


The snag is that my program is using calls to another threaded library 
(paramiko) which does lots of stuff with sockets and communication 
(SSH). Paramiko in turn calls Crypto which has compiled C extensions. I 
really don't know what's going on in there, just guessing that this 
might trigger this behavior.


Now, I do get some slightly random errors on close due to threads doing 
stuff or returning from doing stuff while the shutdown procedure is 
going on, but I don't really care, cuz, well, I'm shutting everything 
down and nothing worth knowing is going on in the rest of the program.


Same as me, except I get lots of exceptions in threads if I shut down 
with sys.exit. SIGTERM somehow gets around this problem.


I'll try os._exit.

Regards,
mk

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


Re: Terminating threaded programs

2010-02-11 Thread mk

Aahz wrote:


You can also use os._exit().


Thanks!


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


Re: Terminating threaded programs

2010-02-11 Thread mk

Aahz wrote:


You can also use os._exit().


Yes! It works cleanly! Thanks a million!

OTOH, if I use sys.exit(), it's just hanging there.

Regards,
mk

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


Re: Is a merge interval function available?

2010-02-11 Thread Jonathan Gardner
On Feb 10, 3:23 pm, Peng Yu pengyu...@gmail.com wrote:
 I'm wondering there is already a function in python library that can
 merge intervals. For example, if I have the following intervals ('['
 and ']' means closed interval as 
 inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...)

 [1, 3]
 [2, 9]
 [10,13]
 [11,12]

 I want to get the following merged intervals.

 [1,9]
 [10,13]

 Could somebody let me know if there is a function in the python
 library?

I vaguely recall a similar question a long time ago. Peng, is this a
homework assignment?

Perhaps we should add a standard module called homework. It can have
functions for all the different homework assignments we see on
c.l.python. We can simply point people to this module and then can
include the code in their answers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is a merge interval function available?

2010-02-11 Thread Alf P. Steinbach

* Jonathan Gardner:

On Feb 10, 3:23 pm, Peng Yu pengyu...@gmail.com wrote:

I'm wondering there is already a function in python library that can
merge intervals. For example, if I have the following intervals ('['
and ']' means closed interval as 
inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...)

[1, 3]
[2, 9]
[10,13]
[11,12]

I want to get the following merged intervals.

[1,9]
[10,13]

Could somebody let me know if there is a function in the python
library?


I vaguely recall a similar question a long time ago. Peng, is this a
homework assignment?

Perhaps we should add a standard module called homework. It can have
functions for all the different homework assignments we see on
c.l.python. We can simply point people to this module and then can
include the code in their answers.


If it's possible, there was/is this guy over in clc.c++ who responded/responds 
to homework questions with the most advanced, convoluted and, except for 
misleading names, technically correct solutions.



Cheers,

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


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-11 Thread mk

MRAB wrote:


When working with Unicode in Python 2, you should use the 'unicode' type
for text (Unicode strings) and limit the 'str' type to binary data
(bytestrings, ie bytes) only.


Well OK, always use u'something', that's simple -- but isn't str what I 
get from files and sockets and the like?



In Python 3 they've been renamed to 'str' for Unicode _strings_ and
'bytes' for binary data (bytes!).


Neat, except that the process of porting most projects and external 
libraries to P3 seems to be, how should I put it, standing still? Or am 
I wrong? But that's the impression I get?


Take web frameworks for example. Does any of them have serious plans and 
work in place to port to P3?



Strictly speaking, only Unicode can be encoded.


How so? Can't bytestrings containing characters of, say, koi8r encoding 
be encoded?



What Python 2 is doing here is trying to be helpful: if it's already a
bytestring then decode it first to Unicode and then re-encode it to a
bytestring.


It's really cumbersome sometimes, even if two libraries are written by 
one author: for instance, Mako and SQLAlchemy are written by the same 
guy. They are both top-of-the line in my humble opinion, but when you 
connect them you get things like this:


1. you query SQLAlchemy object, that happens to have string fields in 
relational DB.


2. Corresponding Python attributes of those objects then have type str, 
not unicode.


3. then I pass those objects to Mako for HTML rendering.

Typically, it works: but if and only if a character in there does not 
happen to be out of ASCII range. If it does, you get UnicodeDecodeError 
on an unsuspecting user.


Sure, I wrote myself a helper that iterates over keyword dictionary to 
make sure to convert all str to unicode and only then passes the 
dictionary to render_unicode. It's an overhead, though. It would be 
nicer to have it all unicode from db and then just pass it for rendering 
and having it working. (unless there's something in filters that I 
missed, but there's encoding of templates, tags, but I didn't find 
anything on automatic conversion of objects passed to method rendering 
template)


But maybe I'm whining.



Unfortunately, the default encoding is ASCII, and the bytestring isn't
valid ASCII. Python 2 is being 'helpful' in a bad way!


And the default encoding is coded in such way so it cannot be changed in 
sitecustomize (without code modification, that is).


Regards,
mk

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


calculating a string equation

2010-02-11 Thread Astan Chee

Hi,
I have some variables in my script that looks like this:
vars = {'var_a':'10','var_b':'4'}
eqat = (var_a/2.0) = var_b
result = (var_a+var_b)/7
What I'm trying to do is to plug in var_a and var_b's values from vars 
into eqat and see if eqat returns true or false as well as getting the 
value of result if these variables were plugged in. How do I do this?
I'm also expecting eqat and result to contain various python 
mathematical operators like **, and compounded ()'s.
I'm not sure how to convert the equation; if I have to make a bunch of 
if-statements or if there is a python function that already does 
something like this.

Thanks for any help.
Cheers
Astan

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


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-11 Thread Robert Kern

On 2010-02-11 15:43 PM, mk wrote:

MRAB wrote:



Strictly speaking, only Unicode can be encoded.


How so? Can't bytestrings containing characters of, say, koi8r encoding
be encoded?


I think he means that only unicode objects can be encoded using the .encode() 
method, as clarified by his next sentence:



What Python 2 is doing here is trying to be helpful: if it's already a
bytestring then decode it first to Unicode and then re-encode it to a
bytestring.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: calculating a string equation

2010-02-11 Thread Arnaud Delobelle
Astan Chee astan.c...@al.com.au writes:

 Hi,
 I have some variables in my script that looks like this:
 vars = {'var_a':'10','var_b':'4'}
 eqat = (var_a/2.0) = var_b
 result = (var_a+var_b)/7
 What I'm trying to do is to plug in var_a and var_b's values from vars
 into eqat and see if eqat returns true or false as well as getting the
 value of result if these variables were plugged in. How do I do
 this?
 I'm also expecting eqat and result to contain various python
 mathematical operators like **, and compounded ()'s.
 I'm not sure how to convert the equation; if I have to make a bunch of
 if-statements or if there is a python function that already does
 something like this.

Yes: eval()

 vars = {'var_a':10 ,'var_b':4}
 eqat = (var_a/2.0) = var_b
 result = (var_a+var_b)/7
 eval(eqat, vars)
False
 eval(result, vars)
2

(Note that I have slightly modified your vars dictionary)
See a recent thread about the dangers of eval().

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


Re: Modifying Class Object

2010-02-11 Thread Terry Reedy

On 2/11/2010 1:37 AM, Alf P. Steinbach wrote:


Consider just the
assert( t is not s )
t = s

Does this change anything at all in the computer's memory?


By 'computer', do you mean 'anything that computes' (including humans) 
or specifically 'electronic computer'?



But since it does have an effect, a memory change has been effected.


Agreed, in whatever 'memory' the 'computer' is using.


You describe that memory change as that t has been bound to the same
object as s.


I prefer to use the word 'associated': namespaces are a many-to-one 
association between names and objects.



By which you mean that henceforth, until the next assignment to t, t
*refers* to the same object as s.


T and s are both associated with the same object.


That explanation in terms of refers is necessary.


I disagree


No beginner knows what it means that a name is bound to something means, 
until it's been
explained.


I agree, which is why I am trying to avoid 'bound', etc, in favor of 
'associated'. One problem of 'bind' is that it sometimes raises the 
question of which is bound to which. 'Associated' avoids that.



The explanation is necessarily in terms of refers to.


I have given an alternative, even if you still prefer yours.


When something A refers to something B, then by definition A is a
*reference* to B.


I presume you agree that the name 'Alf P. Steinbach' refers to you. Do 
you then consider it to be a 'reference' to you? In either case, the 
Python definition uses 'refers to' in the same way that names refer to 
people, and did even before names were used in electro-mechanical 
computer programming.


Steven D'Aprano:

My version describes what happens at the level of high-level Python
code, which is the defined semantics of the language. It makes no
assumptions about the implementation, completely unlike yours which is
entirely implementation-
specific. My description is equally valid whether Python is being
executed by the CPython virtual machine on an Intel-compatible
processor, or hand-simulated with pencil and paper, or something
completely different. Yours is not.


About 13 years ago, I noticed that electronically executable Python was 
very similar to some of the designed-for-human-reading algoritm 
languages (pseudocode) that were not. I then coined the oxymoron 
'executable pseudocode' for Python. I see the difference between the 
descriptions as reflecting the difference between Python, the executable 
algorithm language and Python, the machine programming language.


 I describe the high-level language, you describe one implementation.
 Neither view is *wrong*, per se, but one describes the semantics of
 the language while the other describes the implementation.

I think anyone writing books using Python should at least understand the 
abstract view even if he prefers to write from the more concrete view.


Terry Jan Reedy

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


Re: Modifying Class Object

2010-02-11 Thread Alf P. Steinbach

* Terry Reedy:

On 2/11/2010 1:37 AM, Alf P. Steinbach wrote:


Consider just the
assert( t is not s )
t = s

Does this change anything at all in the computer's memory?


By 'computer', do you mean 'anything that computes' (including humans) 
or specifically 'electronic computer'?


In this context I mean the virtual machine that a Python language assumes.

Doesn't matter if it's electronic or a pen-and-pencil simulation.



But since it does have an effect, a memory change has been effected.


Agreed, in whatever 'memory' the 'computer' is using.


You describe that memory change as that t has been bound to the same
object as s.


I prefer to use the word 'associated': namespaces are a many-to-one 
association between names and objects.



By which you mean that henceforth, until the next assignment to t, t
*refers* to the same object as s.


T and s are both associated with the same object.


That explanation in terms of refers is necessary.


I disagree

No beginner knows what it means that a name is bound to something 
means, until it's been

explained.


I agree, which is why I am trying to avoid 'bound', etc, in favor of 
'associated'. One problem of 'bind' is that it sometimes raises the 
question of which is bound to which. 'Associated' avoids that.



The explanation is necessarily in terms of refers to.


I have given an alternative, even if you still prefer yours.


Associated is just less precise than refers.

Associated is two-way.

Anyway it's just a term, and if you define it to mean a one-way reference, then 
nothing substantial is changed except more room for misunderstanding.




When something A refers to something B, then by definition A is a
*reference* to B.


I presume you agree that the name 'Alf P. Steinbach' refers to you. Do 
you then consider it to be a 'reference' to you?


Yes, and that's irrelevant, because you can't change a name. It's a slightly 
different meaning. But a name edit field with my name in it most probably refers 
to me.



In either case, the 
Python definition uses 'refers to' in the same way that names refer to 
people, and did even before names were used in electro-mechanical 
computer programming.


That's so subtle a distinction that it appears meaningless to me.

It says refers to but doesn't mean refers to?




 Steven D'Aprano:

My version describes what happens at the level of high-level Python
code, which is the defined semantics of the language. It makes no
assumptions about the implementation, completely unlike yours which is
entirely implementation-
specific. My description is equally valid whether Python is being
executed by the CPython virtual machine on an Intel-compatible
processor, or hand-simulated with pencil and paper, or something
completely different. Yours is not.


About 13 years ago, I noticed that electronically executable Python was 
very similar to some of the designed-for-human-reading algoritm 
languages (pseudocode) that were not. I then coined the oxymoron 
'executable pseudocode' for Python. I see the difference between the 
descriptions as reflecting the difference between Python, the executable 
algorithm language and Python, the machine programming language.


  I describe the high-level language, you describe one implementation.
  Neither view is *wrong*, per se, but one describes the semantics of
  the language while the other describes the implementation.

I think anyone writing books using Python should at least understand the 
abstract view even if he prefers to write from the more concrete view.


It seems to me that you lack an understanding of the abstract here, going into 
imagined and not concretely discussed differences between refers to and 
refers to.


Until or if (but I think it unlikely) you can explain clearly what that 
difference between refers to and refers to is, it's just wordplay.



Cheers  hth.,

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


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-11 Thread Steve Holden
mk wrote:
 MRAB wrote:
 
 When working with Unicode in Python 2, you should use the 'unicode' type
 for text (Unicode strings) and limit the 'str' type to binary data
 (bytestrings, ie bytes) only.
 
 Well OK, always use u'something', that's simple -- but isn't str what I
 get from files and sockets and the like?
 
Yes, which is why you need to know what encoding was used to create it.

 In Python 3 they've been renamed to 'str' for Unicode _strings_ and
 'bytes' for binary data (bytes!).
 
 Neat, except that the process of porting most projects and external
 libraries to P3 seems to be, how should I put it, standing still? Or am
 I wrong? But that's the impression I get?
 
No, it's probably not going as quickly as you would like, but it's
certainly not standing still. Some of these libraries are substantial
works, and there were changes to the C API that take quite a bit of work
to adapt existing code to.

 Take web frameworks for example. Does any of them have serious plans and
 work in place to port to P3?
 
There have already been demonstrations of partially-working Python 3
Django. I can't speak to the rest.

 Strictly speaking, only Unicode can be encoded.
 
 How so? Can't bytestrings containing characters of, say, koi8r encoding
 be encoded?
 
It's just terminology. If a bytestring contains koi8r characters then
(as you unconsciously recognized by your use of the word encoding) it
already *has* been encoded.

 What Python 2 is doing here is trying to be helpful: if it's already a
 bytestring then decode it first to Unicode and then re-encode it to a
 bytestring.
 
 It's really cumbersome sometimes, even if two libraries are written by
 one author: for instance, Mako and SQLAlchemy are written by the same
 guy. They are both top-of-the line in my humble opinion, but when you
 connect them you get things like this:
 
 1. you query SQLAlchemy object, that happens to have string fields in
 relational DB.
 
 2. Corresponding Python attributes of those objects then have type str,
 not unicode.
 
Yes, a relational database will often return ASCII, but nowadays people
are increasingly using encoded Unicode. In that case you need to be
aware of the encoding that has been used to render the Unicode values
into the byte strings (which in Python 2 are of type str) so that you
can decode them into Unicode.

 3. then I pass those objects to Mako for HTML rendering.
 
 Typically, it works: but if and only if a character in there does not
 happen to be out of ASCII range. If it does, you get UnicodeDecodeError
 on an unsuspecting user.
 
Well first you need to be clear what you are passing to Mako.

 Sure, I wrote myself a helper that iterates over keyword dictionary to
 make sure to convert all str to unicode and only then passes the
 dictionary to render_unicode. It's an overhead, though. It would be
 nicer to have it all unicode from db and then just pass it for rendering
 and having it working. (unless there's something in filters that I
 missed, but there's encoding of templates, tags, but I didn't find
 anything on automatic conversion of objects passed to method rendering
 template)
 
Some database modules will distinguish between fields of type varchar
and nvarchar, returning Unicode objects for the latter. You will need to
ensure that the module knows which encoding is used in the database.
This is usually automatic.

 But maybe I'm whining.
 
Nope, just struggling with a topic that is far from straightforward the
first time you encounter it.
 
 Unfortunately, the default encoding is ASCII, and the bytestring isn't
 valid ASCII. Python 2 is being 'helpful' in a bad way!
 
 And the default encoding is coded in such way so it cannot be changed in
 sitecustomize (without code modification, that is).
 
Yes, the default encoding is not always convenient.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: python crash on windows but not on linux

2010-02-11 Thread hjebbers
On Feb 11, 8:42 pm, Jerry Hill malaclyp...@gmail.com wrote:
 On Thu, Feb 11, 2010 at 9:32 AM, hjebbers hjebb...@gmail.com wrote:
  To all,
  I am running an EDI translator, and doing stress tests.
  When processing a test with a (relatively) big EDI file(s) on
  windowsXP  I get a crash:
     'sorry for the inconvenience' etc  (so no clues about what is
  causing the problem)

 You need to give us more information if we're going to be able to
 help.  At the very least, you'll need to copy  paste the actual error
 message.  It would be even better if you could show us some of your
 code, and better yet if you could give us a small bit of code that is
 self contained and reproduces the problem you're experiencing.

 --
 Jerry

the error is a windows thing, I can make a screenshot of it, but I can
not copy/paste text.
how do I upload a png-file?

problem is that the same error happens over and over (I can reproduce
it), but not at the same place (the is a logging in the application so
that is quite easy to see.)
but I can show you my code. it's an open source EDI application.
but it is not a small bit of code
I am more than will to show you how to reproduce the error.

kind regards,
henk-jan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python crash on windows but not on linux

2010-02-11 Thread hjebbers
On Feb 11, 8:42 pm, Jerry Hill malaclyp...@gmail.com wrote:
 On Thu, Feb 11, 2010 at 9:32 AM, hjebbers hjebb...@gmail.com wrote:
  To all,
  I am running an EDI translator, and doing stress tests.
  When processing a test with a (relatively) big EDI file(s) on
  windowsXP  I get a crash:
     'sorry for the inconvenience' etc  (so no clues about what is
  causing the problem)

 You need to give us more information if we're going to be able to
 help.  At the very least, you'll need to copy  paste the actual error
 message.  It would be even better if you could show us some of your
 code, and better yet if you could give us a small bit of code that is
 self contained and reproduces the problem you're experiencing.

 --
 Jerry

the error is a windows thing, I can make a screenshot of it, but I can
not copy/paste text.
how do I upload a png-file?

problem is that the same error happens over and over (I can reproduce
it), but not at the same place (the is a logging in the application so
that is quite easy to see.)
but I can show you my code. it's an open source EDI application.
but it is not a small bit of code
I am more than will to show you how to reproduce the error.

kind regards,
henk-jan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bizarre arithmetic results

2010-02-11 Thread Terry Reedy

On 2/11/2010 11:23 AM, Jussi Piitulainen wrote:

Robert Kern writes:

On 2010-02-11 06:31 AM, Shashwat Anand wrote:

There is a little issue here that '  -.1 ** .1' should give you
error message. That is it.


No, fractional powers of negative numbers are perfectly valid
mathematically. The result is a complex number. In Python 3 (what
the OP is using), this has been implemented, but not in Python 2.6.


Perhaps it should raise a MisleadingSpacingError at compile time.


You forgot the smiley ;-).

 The error message could recommend - .1**.1, or better -(.1 ** .1).

The compiler would never see the difference between -.1 ** .1 and the 
first and probably no difference with the second either.



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


Re: python crash on windows but not on linux

2010-02-11 Thread Carl Banks
On Feb 11, 2:39 pm, hjebbers hjebb...@gmail.com wrote:
 On Feb 11, 8:42 pm, Jerry Hill malaclyp...@gmail.com wrote:





  On Thu, Feb 11, 2010 at 9:32 AM, hjebbers hjebb...@gmail.com wrote:
   To all,
   I am running an EDI translator, and doing stress tests.
   When processing a test with a (relatively) big EDI file(s) on
   windowsXP  I get a crash:
      'sorry for the inconvenience' etc  (so no clues about what is
   causing the problem)

  You need to give us more information if we're going to be able to
  help.  At the very least, you'll need to copy  paste the actual error
  message.  It would be even better if you could show us some of your
  code, and better yet if you could give us a small bit of code that is
  self contained and reproduces the problem you're experiencing.

  --
  Jerry

 the error is a windows thing, I can make a screenshot of it, but I can
 not copy/paste text.
 how do I upload a png-file?

 problem is that the same error happens over and over (I can reproduce
 it), but not at the same place (the is a logging in the application so
 that is quite easy to see.)
 but I can show you my code. it's an open source EDI application.
 but it is not a small bit of code
 I am more than will to show you how to reproduce the error.

People coming here ask for help will vary in the amount of detail
given, but I've rarely seen anyone as reluctant as you.  It's like
walking into an auto repair shop and asking the mechanic what's wrong
with your car by trying to imitate the noise it makes.

If your code is very largre, you're not going to get out of this
without doing some of your own legwork.  I'm sorry.

Do this: Take your code, make a copy of it.  Start removing code from
the copy (in a controlled way) until the problem disappears.  When you
remove code don't worry about whether it produces anything useful, the
object is to try to identify what's causing the error.  Whatever code
you removed when the error disappears should give you a clue what's
causing it.  Then, if need be, you can come back and post details.  If
you manage to get the program to a small size without eliminating the
problem, you can post it here.


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


Re: python crash on windows but not on linux

2010-02-11 Thread Terry Reedy

On 2/11/2010 9:32 AM, hjebbers wrote:

To all,
I am running an EDI translator, and doing stress tests.
When processing a test with a (relatively) big EDI file(s) on
windowsXP  I get a crash:
 'sorry for the inconvenience' etc  (so no clues about what is
causing the problem)

This happens with python 2.4, 2.5, 2.6
It does not happen in the same setuptests on linux. (while the linux
machine has only half of the RAM of the windows machine).
I am quite sure it is not some external module; there's no GUI (apart
from 'print'), no network connections.
Actually, the crash is not predictablethe crash occurs most of the
time...but at different points.

So basically I am wondering how to proceed.
Is it related to a memory problem? (which does not occur on Linux)

any pointer is very welcome,


Are you using a 3rd-party extension (compiled-C) module? If so, I would 
suspect something platform specific in that.


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


Re: python crash on windows but not on linux

2010-02-11 Thread Emile van Sebille

On 2/11/2010 6:32 AM hjebbers said...

To all,
I am running an EDI translator,


... let's say bots  :)


and doing stress tests.
When processing a test with a (relatively) big EDI file(s) on
windowsXP  I get a crash:
 'sorry for the inconvenience' etc  (so no clues about what is
causing the problem)


... and it's running directly under python...


I use textpad.  It allows me to launch a script from a command window 
under its control, which when python subsequently crashes, commonly 
leaves the traceback in the textpad launched command window.


Perhaps that'll help?

Emile
--also on the bots list and will be digging in seriously over the next 
several weeks





This happens with python 2.4, 2.5, 2.6
It does not happen in the same setuptests on linux. (while the linux
machine has only half of the RAM of the windows machine).
I am quite sure it is not some external module; there's no GUI (apart
from 'print'), no network connections.
Actually, the crash is not predictablethe crash occurs most of the
time...but at different points.

So basically I am wondering how to proceed.
Is it related to a memory problem? (which does not occur on Linux)

any pointer is very welcome,

henk-jan



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


Re: python and http POST

2010-02-11 Thread Terry Reedy

On 2/11/2010 2:11 PM, galileo228 wrote:

Hey All,

Been teaching myself Python for a few weeks, and am trying to write a
program that will go to a url, enter a string in one of the search
fields, submit the search, and return the contents of the search
result.

I'm using httplib2.

My two particular questions:

1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}),
how do I know what the particular key should be? In other words, how
do I tell python which form on the web page I'm visiting I'd like to
fill in? Do I simply go to the webpage itself and look at the html
source? But if that's the case, which tag tells me the name of the
key?

2) Even once python fills in the form properly, how can I tell it to
'submit' the search?


This
http://groups.csail.mit.edu/uid/sikuli/
*might* help you.

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


Re: Is a merge interval function available?

2010-02-11 Thread Peter
On Feb 12, 8:03 am, Jonathan Gardner jgard...@jonathangardner.net
wrote:
 On Feb 10, 3:23 pm, Peng Yu pengyu...@gmail.com wrote:





  I'm wondering there is already a function in python library that can
  merge intervals. For example, if I have the following intervals ('['
  and ']' means closed interval as 
  inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...)

  [1, 3]
  [2, 9]
  [10,13]
  [11,12]

  I want to get the following merged intervals.

  [1,9]
  [10,13]

  Could somebody let me know if there is a function in the python
  library?

 I vaguely recall a similar question a long time ago. Peng, is this a
 homework assignment?

 Perhaps we should add a standard module called homework. It can have
 functions for all the different homework assignments we see on
 c.l.python. We can simply point people to this module and then can
 include the code in their answers.

Good idea - that would (also) give the teachers a convenient place to
check for what assignments have been solved by this list so they can
propose something else.

They can also grade the submissions against the code kept in this area
- exact copies could receive an F (for example :-))

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


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-11 Thread Terry Reedy

On 2/11/2010 4:43 PM, mk wrote:


Neat, except that the process of porting most projects and external
libraries to P3 seems to be, how should I put it, standing still?


What is important are the libraries, so more new projects can start in 
3.x. There is a slow trickly of 3.x support announcements.



But maybe I'm whining.


Or perhaps explaining why 3.x unicode improvements are needed.

tjr

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


Re: MODULE FOR I, P FRAME

2010-02-11 Thread Rhodri James

On Thu, 11 Feb 2010 19:31:52 -, DANNY danijel.gv...@gmail.com wrote:


Hello!

I am currently developing a simple video player in python, and my
problem is that i can't find a module which has a function that can
determine if frame(image) is I or P coded (MPEG coding). I have been
using PIL but I couldnt find anything that could help me with that
problem.


How are you reading the video?  PIL doesn't claim to do more than identify  
MPEG files.  Also, which MPEG encoding, in which container format?


If you aren't just putting a wrapper around something like ffmpeg, I  
rather suspect you'll have to decode the bitstream yourself.  That could  
be rather painful if you're talking about MPEG-4/10.


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


Please help with MemoryError

2010-02-11 Thread Jeremy
I have been using Python for several years now and have never run into
memory errors…

until now.

My Python program now consumes over 2 GB of memory and then I get a
MemoryError.  I know I am reading lots of files into memory, but not
2GB worth.  I thought I didn't have to worry about memory allocation
in Python because of the garbage collector.  On this note I have a few
questions.  FYI I am using Python 2.6.4 on my Mac.

1.When I pass a variable to the constructor of a class does it
copy that variable or is it just a reference/pointer?  I was under the
impression that it was just a pointer to the data.
2.When do I need to manually allocate/deallocate memory and when
can I trust Python to take care of it?
3.Any good practice suggestions?

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


Re: Function attributes

2010-02-11 Thread Gabriel Genellina

En Thu, 11 Feb 2010 00:25:00 -0300, Terry Reedy tjre...@udel.edu
escribió:

On 2/10/2010 4:49 PM, Gabriel Genellina wrote:


I've written a decorator for injecting a __function__ name into the
function namespace, but I can't find it anywhere. I think I implemented
it by adding a fake additional argument and replacing LOAD_GLOBAL with
LOAD_NAME in the bytecode.


The decorator only needs to replace the defaults args tuple.
It does not even need to know the parameter name,
just that it is the only (or last) with a default .

def f(n, me=None):
 if n  0: return n*me(n-1)
 elif n==0: return 1

f.__defaults__ = (f,) # 3.1
print(f(5))


This is simple to implement, but requires changing the function
definition. My goal was to keep the original code unchanged, that is,
leave it as:

def f(n):
   if n  0: return n*f(n-1)
   elif n==0: return 1

(like a normal, recursive function), and make the 'f' inside the function
body magically refer to the function itself.

Of course, user could still screw up recursion by providing another  
value for 'me'. This strikes me as about a likely (low) as a user  
screwing up recursion in a library module function by rebinding the name  
in the imported module.


Well, if people really want to shoot themselves in the foot, there's
nothing we can do to avoid that...

--
Gabriel Genellina

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


Re: Please help with MemoryError

2010-02-11 Thread Stephen Hansen
On Thu, Feb 11, 2010 at 3:39 PM, Jeremy jlcon...@gmail.com wrote:

 My Python program now consumes over 2 GB of memory and then I get a
 MemoryError.  I know I am reading lots of files into memory, but not
 2GB worth.  I thought I didn't have to worry about memory allocation
 in Python because of the garbage collector.  On this note I have a few
 questions.  FYI I am using Python 2.6.4 on my Mac.


Is this pure-python, or are you using extension modules? Its possible a C
extension has a memory leak. Its also possible you're keeping references to
objects far longer then you need.


 1.When I pass a variable to the constructor of a class does it
 copy that variable or is it just a reference/pointer?  I was under the
 impression that it was just a pointer to the data.


The question doesn't precisely make sense in terms of Python, but I think I
see what you're getting at. Python doesn't implicitly copy anything: you
have to explicitly copy an object to end up with two of them. That said, it
sort of depends on what you're doing. When you pass objects into a class, if
that class stores a reference to those objects, they'll live as long as the
class does. More details would require you showing some examples of what
you're doing.


 2.When do I need to manually allocate/deallocate memory and when
 can I trust Python to take care of it?


Generally, you can trust Python-- and you can't manually
allocate/deallocate even if you wanted to.

If you're suffering a memory leak, it almost certainly comes from one of two
places:

1. Your code is keeping references somewhere to objects that you don't need
anymore, or
2. Some C extension you are using has some ref-counting bugs.

Once upon a time, reference cycles would also cause memory leaks, but the
cyclic GC breaks them now.


 3.Any good practice suggestions?


Look over your code: look at places where you bind objects to any names that
aren't local. Look for lists or dictionaries that you're putting stuff into
without really meaning to keep it forever, and maybe you aren't purging.
Global vars are worth a close look too.

This may be useful:
http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks

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


  1   2   >