ANN: SUMMON 1.8.8 Released: 2D Visualization prototyping and scripting

2009-07-08 Thread rasmus
SUMMON 1.8.8

SUMMON is a python extension module that provides rapid prototyping of
2D visualizations.  By heavily relying on the python scripting
language, SUMMON allows the user to rapidly prototype a custom
visualization for their data, without the overhead of a designing a
graphical user interface or recompiling native code. By simplifying
the task of designing a visualization, users can spend more time on
understanding their data.

SUMMON is designed to be a fast interface for developing interactive
scene graphs for OpenGL. Although python libraries already exist for
accessing OpenGL, python is relatively slow for real-time interaction
with large visualizations (trees with 100,000 leaves, sparse matrices
with a million non-zeros, etc.). Therefore, with SUMMON all real-time
interaction is handled with compiled native C++ code (via extension
module). Python is only executed in the construction and occasional
interaction with the visualization. This arrangement provides the best
of both worlds.

SUMMON 1.8.8 comes with the following features:
* a demo large sparse matrix visualizer (ideal for visualizing
  clusterings)
* a demo tree visualizer
* Python C++ extension module
* Fast OpenGL graphics
* Drawing arbitrary points, lines, polygons, text with python
  scripting
* Binding inputs (keyboard, mouse, hotspots) to any python
function
* Separate threads for python and graphics (allows use of python
  prompt and responsive graphics at the same time)
* Transparently handles graphics event loop, scrolling, zooming,
  text layout (auto-clipping, scaling, alignment), and click
  detection; allowing you to focus on viewing your data
* SVG output (also GIF/PNG/JPG/etc via ImageMagick)
* Cross-platform (Linux, Windows, OS/X)
* And lots of examples for how to prototype your own custom 2D
  visualizations

Web site and download:
http://people.csail.mit.edu/rasmus/summon/

Videos:
http://people.csail.mit.edu/rasmus/summon/index.shtml#videos
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: KeepNote 0.5.3 - Note taking and organization

2009-07-08 Thread rasmus
KeepNote is a simple cross-platform note taking program implemented
in Python.  I have been using it for my research and class notes, but
it
should be applicable to many note taking situations.

KeepNote is ideal for storing your class notes, TODO lists, research
notes, journal entries, paper outlines, etc in a simple notebook
hierarchy with rich-text formatting, images, and more. Using full-text
search, you can retrieve any note for later reference.

KeepNote is designed to be cross-platform (runs on Windows, Linux, and
MacOS X, implemented in Python and PyGTK) and stores your notes in
simple and easy to manipulate file formats (HTML and XML). Archiving
and transferring your notes is as easy as zipping or copying a
folder.  KeepNote is licensed under GPL.

KeepNote 0.5.3 has the following features:

* Rich-text formatting
  * Bullet point lists
  * Colored font
  * Inline images
  * hyperlinks
* Hierarchical organization for notes
* File attachments
* Full-text search
* Integrated screenshot
* Extension framework
* Spell checking (via gtkspell)
* Auto-saving
* Built-in backup and restore (archive to zip files)
* Cross-platform (Linux, Windows, MacOS X)

Web site and download:
http://rasm.ods.org/keepnote

Documentation:
http://rasm.ods.org/keepnote/manual.shtml

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

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


Re: tough-to-explain Python

2009-07-08 Thread Steven D'Aprano
On Tue, 07 Jul 2009 20:04:46 +, kj wrote:

 I'm having a hard time coming up with a reasonable way to explain
 certain things to programming novices.

[...]


 Or consider this one:
 
 ham = [1, 2, 3, 4]
 spam = (ham,)
 spam
 ([1, 2, 3, 4],)
 spam[0] is ham
 True
 spam[0] += [5]
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: 'tuple' object does not support item assignment
 ham += [5]
 spam
 ([1, 2, 3, 4, 5, 5],)
 
 
 What do you say to that?


That one surely is very straight forward. Just like the exception says, 
tuples don't support item assignment, so spam[0] += [5] is not allowed.

But just because you have put a list inside a tuple doesn't mean the list 
stops being a list -- you can still append to the list, which is what 
ham += [5] does. So spam is unchanged: it is still the one-item tuple 
containing a list. It is just that the list has now been modified.

This is only troublesome (in my opinion) if you imagine that tuples are 
somehow magical frozen-lists, where the contents can't be modified once 
created. That's not the case -- the tuple itself can't be modified, but 
the objects inside it remain ordinary objects, and the mutable ones can 
be modified.

The thing to remember is that the tuple spam doesn't know anything about 
the *name* ham -- it knows the object referred to by the name ham. You 
can modify the name, and nothing happens to the tuple:

 spam
([1, 2, 3, 4, 5],)
 ham = [5]
 spam
([1, 2, 3, 4, 5],)

Or if you prefer:

 ham = spam[0]  # label the list inside spam as 'ham'
 ham += [6]  # modify the list labelled as 'ham'
 spam
([1, 2, 3, 4, 5, 6],)
 pork = ham  # create a new label, 'pork', and bind it to the same list
 del ham  # throw away the label 'ham'
 pork += [7]  # modify the list labelled as 'pork'
 spam
([1, 2, 3, 4, 5, 6, 7],)


It's all about the objects, not the names.



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


count

2009-07-08 Thread Dhananjay
Dear all,

I have file as follows,however, tab seperated (not shown in following file):

 6   3   4.309726
 7   65 93.377388
 8   47 50.111952
 9   270   253.045923
 10 184182.684670
 11 76 121.853455
 12 85 136.283470
 13 114145.910662
 14 45  80.703013
 15 44  47.154646
 16 41  66.461339
 17 16  33.819488
 18 127 136.105455
 19 70  88.798681
 20 29  61.297823


I wanted to sort column 2 in assending order  and I read whole file in array
data and did the following:

data.sort(key = lambda fields:(fields[2]))

I have sorted column 2, however I want to count the numbers in the column 2.
i.e. I want to know, for example, how many repeates of say '3' (first row,
2nd column in above data) are there in column 2.

I could write seperate programme to get the result.s.

However, is there any way to count the numbers there itself while sorting in
column 2 ?


Thanking you in advance,


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


Re: SSH utility

2009-07-08 Thread romeoamp

Please look at on :


http://www.lag.net/paramiko/ http://www.lag.net/paramiko/ 


Sample Code: Find Attachment


Thanks,
S.V.RAJKUMAR,
XOU Solutions India Private Limited
No. 37, PM Towers,
Greams Road,
Thousand Lights,
Chennai - 6 .
Mobile No : +91 - 9940632275. 





half.italian wrote:
 
 On Aug 11, 5:17 am, edwin.mad...@verizonwireless.com wrote:
 for similar tasks, I use pexpecthttp://pypi.python.org/pypi/pexpect.

 spawning bash process and simulate an interactive session. Here sending
 ls command, retrieving results and exiting. In the spawned process ssh or
 any other command, is just another command.

 actual session--
 $ python
 Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
 [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
 Type help, copyright, credits or license for more information.
 import pexpect
  c = pexpect.spawn('/bin/bash')
  c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
 2
  c.before, c.after

 ('\x1b[?1034hmada...@njwarhqd0it696a:~\r\n', '$ ') c.sendline('ls')
 3
  c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
 2
  c.before, c.after

 ('ls\r\x.txt  xx.txt  xy.txt  y.txt\r\nmada...@njwarhqd0it696a:~\r\n', '$
 ') c.sendline('exit')
 5
  c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
 1
  c.before, c.after

 ('exit\r\nexit\r\n', ) exit()

 mada...@njwarhqd0it696a:~
 $
 ---

 hope that helps.

 regards.
 Edwin

 -Original Message-
 From: python-list-bounces+edwin.madari=verizonwireless@python.org

 [mailto:python-list-bounces+edwin.madari=verizonwireless@python.org]
 On Behalf Of James Brady
 Sent: Monday, August 11, 2008 12:26 AM
 To: python-l...@python.org
 Subject: SSH utility

 Hi all,
 I'm looking for a python library that lets me execute shell commands
 on remote machines.

 I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
 unfortunately all been unreliable, and repeated questions on their
 respective mailing lists haven't been answered...

 It seems like the sort of commodity task that there should be a pretty
 robust library for. Are there any suggestions for alternative
 libraries or approaches?

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

 The information contained in this message and any attachment may be
 proprietary, confidential, and privileged or subject to the work
 product doctrine and thus protected from disclosure.  If the reader
 of this message is not the intended recipient, or an employee or
 agent responsible for delivering this message to the intended
 recipient, you are hereby notified that any dissemination,
 distribution or copying of this communication is strictly prohibited.
 If you have received this communication in error, please notify me
 immediately by replying to this message and deleting it and all
 copies and backups thereof.  Thank you.
 
 I second pexpect and the nice little module that comes with it
 ssh_session.py.
 
 Been using it for ages now!
 
 ~Sean
 --
 http://mail.python.org/mailman/listinfo/python-list
 
 
http://www.nabble.com/file/p24385961/sshclient.py sshclient.py 
-- 
View this message in context: 
http://www.nabble.com/SSH-utility-tp18920030p24385961.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding most common elements between thousands of multiple arrays.

2009-07-08 Thread Raymond Hettinger
[Scott David Daniels]
 def most_frequent(arr, N):
      '''Return the top N (freq, val) elements in arr'''
      counted = frequency(arr) # get an iterator for freq-val pairs
      heap = []
      # First, just fill up the array with the first N distinct
      for i in range(N):
          try:
              heap.append(counted.next())
          except StopIteration:
              break # If we run out here, no need for a heap
      else:
          # more to go, switch to a min-heap, and replace the least
          # element every time we find something better
          heapq.heapify(heap)
          for pair in counted:
              if pair  heap[0]:
                  heapq.heapreplace(heap, pair)
      return sorted(heap, reverse=True) # put most frequent first.

In Py2.4 and later, see heapq.nlargest().
In Py3.1, see collections.Counter(data).most_common(n)


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


Re: How to use Python to interface with Web pages?

2009-07-08 Thread alex23
On Jul 8, 1:18 pm, Peter peter.milli...@gmail.com wrote:
 I can see the web-page source - it looks to be javascript (to my
 untutored eye :-)).

 But how do I enter data and simulated mouse presses on a web-page
 that I have accessed via a Python program?
 [...]
 I have (in the past) written some python to scoop data off web-sites
 but I have never written anything that interactively interacts with
 the web-page contents and don't know where to even start on this one.

I don't have much experience with it, but for interacting with
javascript-heavy pages you might want to take a look at Selenium:

http://seleniumhq.org/
http://pypi.python.org/pypi/selenium
http://jimmyg.org/blog/2009/getting-started-with-selenium-and-python.html
http://joker.linuxstuff.pl/documentation/make_selenium

It's primarily aimed at testing web app UIs, but if it allows for
values to be passed into tests then 'test' == 'action' in terms of
your requirements.

Hope this helps.

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


Re: tough-to-explain Python

2009-07-08 Thread Francesco Bochicchio
On Jul 7, 10:04 pm, kj no.em...@please.post wrote:
 I'm having a hard time coming up with a reasonable way to explain
 certain things to programming novices.

 Consider the following interaction sequence:

  def eggs(some_int, some_list, some_tuple):

 ...     some_int += 2
 ...     some_list += [2]
 ...     some_tuple += (2,)
 ...

  x = 42
  y = (42,)
  z = [42]
  eggs(x, y, z)
  x
 42
  y
 (42,)
  z
 [42, 2]

 How do I explain to rank beginners (no programming experience at
 all) why x and y remain unchanged above, but not z?

 Or consider this one:

  ham = [1, 2, 3, 4]
  spam = (ham,)
  spam
 ([1, 2, 3, 4],)
  spam[0] is ham
 True
  spam[0] += [5]

 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: 'tuple' object does not support item assignment ham += [5]
  spam

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



 What do you say to that?

 I can come up with much mumbling about pointers and stacks and
 heaps and much hand-waving about the underlying this-and-that, but
 nothing that sounds even remotely illuminating.

 Your suggestions would be much appreciated!

 TIA!

 kj

I would go with something like this:


In object oriented programming, the same function or operator can be
used to represent
different things. This is called overloading. To understand what the
operator/function do, we have to look at
the kind of object it is applied to.
In this case, the operator += means two different things:
- for strings and numbers it means : create a new object by merging
the two operands. This is why the original object is left the same.
- for lists, it means : increase the left operand with the contents
of the right operand. This is why the original object is changed


You couuld also add:

You see, in python everithing is an object. Some object can be changed
(mutable objects), others cannot.

but this is another story.


P:S : Sometime I think they should not have allowed += on immutables
and forced everybody to write s = s + some more.

Ciao

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


Re: Check file is locked?

2009-07-08 Thread Tim Golden

Rajat wrote:

On Jul 8, 4:57 am, Lawrence D'Oliveiro l...@geek-
central.gen.new_zealand wrote:

In message mailman.2795.1246997268.8015.python-l...@python.org, Christian

Heimes wrote:

By the way most operating systems don't lock a file when it's opened for
reading or writing or even executed.

The general conclusion seems to be that mandatory locking is more trouble
than it's worth.


My OS is a windows XP sp3. All I'm trying to achieve is to close an
application ( which could be a notepad, a wordpad or some other text
editor) that have opened my file. Once the file is closed I can easily
delete that file.

I guess, if file is opened by one of that application, the file must
be locked and so is the reason I cannot delete the file.



I assume that your real requirement is: I can't open/close/delete
this file; it must be locked by something else; what is that
something else?

The simplest thing is probably to run sysinternals' handle util:

 http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx

and use the subprocess module to parse the output.
That will give you the pid, and you can then use, eg, psutil:

 http://code.google.com/p/psutil/

to get the details of the process.

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


Remoting over SSH

2009-07-08 Thread Hussein B
Hey,
I want to perform commands on a remote server over SSH.
What do I need?
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IP Address Function

2009-07-08 Thread Fred Atkinson
On Tue, 07 Jul 2009 22:54:03 -0300, Gabriel Genellina
gagsl-...@yahoo.com.ar wrote:

En Tue, 07 Jul 2009 22:45:24 -0300, Fred Atkinson fatkin...@mishmash.com  
escribió:

  Is there a Python function I can use to get the user's IP
 address so I can display it on his browser?

There is a long distance between Python and browser - you'll have to  
tell us what is in between the two.

I want to have a Web page come up (written in Python, cgi)
that returns the IP address of the browser (user's PC's IP address).  

By example, do you have a server and the user connects to it? is it  
running Python? how do you run the Python application?
And why do you want to do that on the server side? Isn't easier to do that  
on the client side? What about proxies? NAT?

Yes.  By CGI.  

If using CGI, look at the REMOTE_ADDR environment variable.

I did look at REMOTE_ADDR but I've been unable to figure out
the correct way to code it.  I've tried a number of ways but I've been
unsuccessful.  

Ideally, I'd like to store the brower's IP address in a string
and then print the string on the Web page from a Python CGI script.  

Regards, 



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


Re: tough-to-explain Python

2009-07-08 Thread Gabriel Genellina
En Wed, 08 Jul 2009 04:32:07 -0300, Francesco Bochicchio  
bieff...@gmail.com escribió:



I would go with something like this:


In object oriented programming, the same function or operator can be
used to represent
different things. This is called overloading. To understand what the
operator/function do, we have to look at
the kind of object it is applied to.
In this case, the operator += means two different things:
- for strings and numbers it means : create a new object by merging
the two operands. This is why the original object is left the same.
- for lists, it means : increase the left operand with the contents
of the right operand. This is why the original object is changed



Mmm, but this isn't quite exact. += isn't an operator, but a statement  
(augmented assignment). a += b translates to: [*]


a = a.__iadd__(b) [*]

It's up to the __iadd__ implementation to return the same object or a new  
one, and the assignment occurs even if the same object is returned.


If you think of an assignments as binding names to objects (well, that's  
the documented behavior, btw) things become more clear.



P:S : Sometime I think they should not have allowed += on immutables
and forced everybody to write s = s + some more.


I think not everyone agreed when += was introduced.
But now, having s += some more allows the operation to be optimized.

[*] except 'a' is evaluated only once

--
Gabriel Genellina

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


Re: tough-to-explain Python

2009-07-08 Thread Piet van Oostrum
 Simon Forman sajmik...@gmail.com (SF) wrote:

SF Why would you even tell the poor bastards about += before they were
SF comfortable with (python's style of) function calls, immutable
SF integers, mutable lists and immutable tuples?

SF Let them use x = x + y until they have enough knowledge to
SF understand augmented assignment.

And *then* you can tell them that x += y can be subtly different from 
x = x + y, which is what happened in the example that the OP gave.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


PyQt GUI

2009-07-08 Thread Helvin
Hi experts!

I'm developing a GUI for a software using PyQT, and need 3D
visualization. Should I use PyOpenGL or VTK?
I understand that the PyQt package comes with a opengl module. What
else would I need? I think I need to download opengl. but how? where?
I have VTK and pyVTK installed, but I don't know how to use it in my
code, as when I run it, an error says it can't find the vtk module.

Help would be so appreciated!
Helvin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: count

2009-07-08 Thread Vilya Harvey
2009/7/8 Dhananjay dhananjay.c.jo...@gmail.com:
 I wanted to sort column 2 in assending order  and I read whole file in array
 data and did the following:

 data.sort(key = lambda fields:(fields[2]))

 I have sorted column 2, however I want to count the numbers in the column 2.
 i.e. I want to know, for example, how many repeates of say '3' (first row,
 2nd column in above data) are there in column 2.

One thing: indexes in Python start from 0, so the second column has an
index of 1 not 2. In other words, it should be data.sort(key = lambda
fields: fields[1]) instead.

With that out of the way, the following will print out a count of each
unique item in the second column:

from itertools import groupby
for x, g in groupby([fields[1] for fields in data]):
print x, len(tuple(g))

Hope that helps,
Vil.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt GUI

2009-07-08 Thread Diez B. Roggisch
Helvin wrote:

 Hi experts!
 
 I'm developing a GUI for a software using PyQT, and need 3D
 visualization. Should I use PyOpenGL or VTK?
 I understand that the PyQt package comes with a opengl module. What
 else would I need? I think I need to download opengl. but how? where?
 I have VTK and pyVTK installed, but I don't know how to use it in my
 code, as when I run it, an error says it can't find the vtk module.

VTK won't mix with Qt. And I don't think you need to download opengl - it
either comes with your system (or gfx-drivers), or not. I'm not sure if Qt
actually wraps the OpenGL api itself, AFAIK it doesn't, so you need
PyOpenGL I guess.

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


Re: PyQt GUI

2009-07-08 Thread Phil Thompson
On Wed, 08 Jul 2009 11:11:51 +0200, Diez B. Roggisch
de...@nospam.web.de
wrote:
 Helvin wrote:
 
 Hi experts!
 
 I'm developing a GUI for a software using PyQT, and need 3D
 visualization. Should I use PyOpenGL or VTK?
 I understand that the PyQt package comes with a opengl module. What
 else would I need? I think I need to download opengl. but how? where?
 I have VTK and pyVTK installed, but I don't know how to use it in my
 code, as when I run it, an error says it can't find the vtk module.
 
 VTK won't mix with Qt. And I don't think you need to download opengl - it
 either comes with your system (or gfx-drivers), or not. I'm not sure if
Qt
 actually wraps the OpenGL api itself, AFAIK it doesn't, so you need
 PyOpenGL I guess.

VTK has explicit support for both Qt (ie. via C++) and PyQt.

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


Fractions as result from divisions (was: Re: tough-to-explain Python)

2009-07-08 Thread Ulrich Eckhardt
Bearophile wrote:
 For example a novice wants to see 124 / 38 to return the 62/19
 fraction and not 3 or 3.263157894736842 :-)

Python has adopted the latter of the three for operator / and the the second
one for operator //. I wonder if it was considered to just return a
fraction from that operation.

 x = 3/5
 - x = fraction(3, 5)
 x = x*7
 - x = fraction(21, 5)
 x = x/2
 - x = fraction(21, 10)
 range(x)
 - error, x not an integer
 range(int(x))
 - [0, 1,]
 y = float(x)
 - y = 2.1

This would have allowed keeping the operator what people are used to. On the
other hand, implicit conversion to either of float or int would have been
avoided, which is usually the #1 cause for subtle problems.


Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Python Error from Apress book

2009-07-08 Thread Dave Angel



Gabriel Genellina wrote:
div class=moz-text-flowed style=font-family: -moz-fixedEn Tue, 
07 Jul 2009 09:55:13 -0300, Dave Angel da...@ieee.org escribió:

Gabriel Genellina wrote:
En Mon, 06 Jul 2009 19:56:40 -0300, matt0177 matt0...@gmail.com 
escribió:



When I try to run the command as outlined in
the book simple_markup2.py  test_input.txt  test_output.html i 
get the

following error every time.

IOError: [Errno 9] Bad file descriptor


That's a Windows problem. When you execute the script as itself 
(either as you do in the command line, or by double-clicking on it), 
it doesn't have valid standard handles.

You have to invoke Python explicitely:

python simple_markup2.py  test_input.txt  test_output.html

(you may need to specify the full path to python.exe, or add the 
directory where Python is installed to your system PATH).


I use stdout this way all the time, with no problem (python 2.6, 
Windows XP).  But as you point out, stdin redirection doesn't seem to 
work using the file associations.  I do get a different error though. 
When I look at sys.stdin, it shows an open file, with handle of zero, 
as expected.  But when I do a raw_input(), it gets:

 EOFError: EOF when reading a line


I think the error depends on the specific OS version/service pack. But 
at least on XP this appears to fix it:


http://support.microsoft.com/kb/321788/en-us

Thanks for the link.  Looking at that one, it indicates that Windows 
2000 fixed it in SP4, and XP fixed it in Sp1.  But I'm already running 
XP SP3, so I wonder if it's something new.


Matt, what OS version are you running, and exactly what is happening 
when the error occurs?  (you should be able to figure that out from the 
stack trace)



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


Re: PyQt GUI

2009-07-08 Thread Diez B. Roggisch
Phil Thompson wrote:

 On Wed, 08 Jul 2009 11:11:51 +0200, Diez B. Roggisch
 de...@nospam.web.de
 wrote:
 Helvin wrote:
 
 Hi experts!
 
 I'm developing a GUI for a software using PyQT, and need 3D
 visualization. Should I use PyOpenGL or VTK?
 I understand that the PyQt package comes with a opengl module. What
 else would I need? I think I need to download opengl. but how? where?
 I have VTK and pyVTK installed, but I don't know how to use it in my
 code, as when I run it, an error says it can't find the vtk module.
 
 VTK won't mix with Qt. And I don't think you need to download opengl - it
 either comes with your system (or gfx-drivers), or not. I'm not sure if
 Qt
 actually wraps the OpenGL api itself, AFAIK it doesn't, so you need
 PyOpenGL I guess.
 
 VTK has explicit support for both Qt (ie. via C++) and PyQt.

Oh, I'm sorry for the FUD - they talk about Tk on their homepage.

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


Re: count

2009-07-08 Thread Tim Chase

I wanted to sort column 2 in assending order  and I read whole file in array
data and did the following:

data.sort(key = lambda fields:(fields[2]))

I have sorted column 2, however I want to count the numbers in the column 2.
i.e. I want to know, for example, how many repeates of say '3' (first row,
2nd column in above data) are there in column 2.


I think you're trying to count in the wrong step -- I'd do the 
counting while you read the file in; not while you're trying to 
sort.  Maybe something like this untested file-wrapper:


  class Histo:
def __init__(self, data, column):
  self.data = data
  self.column = column
  self.stats = defaultdict(int)
  self.exhausted = False
def __iter__(self):
  if self.exhausted:
raise StopIteration(Input exhausted)
  for line in self.data:
self.stats[line[self.column]] += 1
yield line
  self.exhausted = True
def stats_so_far(self):
  return self.stats

  with file('in.txt') as f:
r = csv.reader(f, delimiter='\t')
h = Histo(r, 2)
data = list(h) # slurp up the elements
  print repr(h.stats_so_far())
  data.sort(key = lambda fields: (fields[2]))

-tkc




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


Re: Re: Check file is locked?

2009-07-08 Thread Dave Angel

Rajat wrote:

On Jul 8, 4:57 am, Lawrence D'Oliveiro l...@geek-
central.gen.new_zealand wrote:
  

In message mailman.2795.1246997268.8015.python-l...@python.org, Christian

Heimes wrote:


By the way most operating systems don't lock a file when it's opened for
reading or writing or even executed.
  

The general conclusion seems to be that mandatory locking is more trouble
than it's worth.



My OS is a windows XP sp3. All I'm trying to achieve is to close an
application ( which could be a notepad, a wordpad or some other text
editor) that have opened my file. Once the file is closed I can easily
delete that file.

I guess, if file is opened by one of that application, the file must
be locked and so is the reason I cannot delete the file.

Please suggest if this is fine.


  
Neither Wordpad nor Notepad lock the files they have open, at least in 
my experience.  Specifically, I just tried it in XP Sp3.   I created a 
file, opened the file in one of the apps, then deleted the file before 
closing the app.


Word for Windows, on the other hand, has locked files for me in the 
past.  When I tried that one just now (on a text file, because that was 
easy), results were rather confusing.  It let me delete the file, but 
then when I tried to save it, it gave me a permissions error.  My 
experience with Winword has been that it's in a world of its own, best 
not messed with.  And this latest version (Office 2007 or somesuch) is 
so modern that it has removed the Help-About menu to make sure I can't 
even tell what version it is.  Next time I rebuild my system, I think 
I'll go back to Office 97.



But perhaps your question is intended to cover the general case.  You 
can get a program from sysinternals called   handle, which will list all 
the files (and other handles) opened by all the processes in the 
system.  You may be able to run that (with subprocess, or just from the 
commandline), and filter its output for the information you want.



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


Re: DBI module deprecated at Python 2.5--what to use in its place?

2009-07-08 Thread dana
On Jul 8, 12:30 am, John Machin sjmac...@lexicon.net wrote:
 Deprecated certainly doesn't mean removed.
 For a start, none of (DBI, ODBC, dbi, odbc) are standard Python-
 supplied modules. Perhaps you are referring to the odbc (and dbi) from
 the pywin32 package? Where did you get them from? If you can't
 remember, try this:

Thanks John. I mean the lower-case dbi and odbc modules from pywin32.
Sorry for being vague. I assumed incorrectly they were part of the
standard library because they came with pywin32.

 If this is what you're talking about, you should be asking on the
 pywin32 dicussion list (http://mail.python.org/mailman/listinfo/python-
 win32).

Thanks again.

 General advice: if you are thinking of upgrading your Python version,
 go straight to 2.6. odbc is AFAIK stuck at version 1.0 of the Python
 DB API; consider switching to pyodbc (http://code.google.com/p/
 pyodbc/)

Thanks thrice.

We have to use the version of Python our software vendor supports.
Presently, that's pywin32 version 2.5.

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


Re: Catching control-C

2009-07-08 Thread Nick Craig-Wood
Steven D'Aprano st...@remove-this-cybersource.com.au wrote:
  On Mon, 06 Jul 2009 15:02:26 -0700, Michael Mossey wrote:
 
  On Jul 6, 2:47 pm, Philip Semanchuk phi...@semanchuk.com wrote:
  On Jul 6, 2009, at 5:37 PM, Michael Mossey wrote:
 
   What is required in a python program to make sure it catches a
   control-
   c on the command-line? Do some i/o? The OS here is Linux.
 
  You can use a try/except to catch a KeyboardInterrupt exception, or you
  can trap it using the signal
  module:http://docs.python.org/library/signal.html
 
  You want to trap SIGINT.
 
  HTH
  Philip
  
  Thanks to both of you. However, my question is also about whether I need
  to be doing i/o or some similar operation for my program to notice in
  any shape or form that Control-C has been pressed. In the past, I've
  written Python programs that go about their business ignoring Ctrl-C.
 
  I bet that somewhere in your code you have something like:
 
 
  for x in really_big_list:
  try:
  long_running_process(x)
  except:
  continue
 
 
  If that's what you're doing, stop! The correct way is:
 
 
  for x in really_big_list:
  try:
  long_running_process(x)
  except Exception:
  # Let KeyboardInterrupt and SystemExit through.
  continue

Note that it is a relatively recent change (in python 2.5) which made
KeyboardInterrupt not a child of Exception

n...@dogger:~$ python2.4
Python 2.4.6 (#2, Feb 17 2009, 20:01:48)
[GCC 4.3.3] on linux2
Type help, copyright, credits or license for more information.
Loaded customisations from '/home/ncw/.pystartup'
 isinstance(KeyboardInterrupt(), Exception)
True


n...@dogger:~$ python2.5
Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45)
[GCC 4.3.3] on linux2
Type help, copyright, credits or license for more information.
Loaded customisations from '/home/ncw/.pystartup'
 isinstance(KeyboardInterrupt(), Exception)
False


  for x in really_big_list:
  try:
  long_running_process(x)
  except (KeyboardInterrupt, SystemExit):
  print User requested exit... shutting down now
  cleanup()
  raise
  except Exception:
  continue

That is the backwards compatible way

-- 
Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IP Address Function

2009-07-08 Thread Piet van Oostrum
 Fred Atkinson fatkin...@mishmash.com (FA) wrote:

FA On Tue, 07 Jul 2009 22:54:03 -0300, Gabriel Genellina
FA gagsl-...@yahoo.com.ar wrote:

 En Tue, 07 Jul 2009 22:45:24 -0300, Fred Atkinson fatkin...@mishmash.com  
 escribió:
 
 Is there a Python function I can use to get the user's IP
 address so I can display it on his browser?
 
 There is a long distance between Python and browser - you'll have to  
 tell us what is in between the two.

FAI want to have a Web page come up (written in Python, cgi)
FA that returns the IP address of the browser (user's PC's IP address).  

 By example, do you have a server and the user connects to it? is it  
 running Python? how do you run the Python application?
 And why do you want to do that on the server side? Isn't easier to do that  
 on the client side? What about proxies? NAT?

FAYes.  By CGI.  

 If using CGI, look at the REMOTE_ADDR environment variable.

FAI did look at REMOTE_ADDR but I've been unable to figure out
FA the correct way to code it.  I've tried a number of ways but I've been
FA unsuccessful.  

FAIdeally, I'd like to store the brower's IP address in a string
FA and then print the string on the Web page from a Python CGI script.  

Something like:

#! /usr/bin/env python

import cgi
from os import getenv

print Content-type: text/html
print

ipaddr = (getenv(HTTP_CLIENT_IP) or
  getenv(HTTP_X_FORWARDED_FOR) or
  getenv(HTTP_X_FORWARDED_FOR) or
  getenv(REMOTE_ADDR) or
  UNKNOWN)

print ipaddr


-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: count

2009-07-08 Thread Bearophile
Vilya Harvey:
 from itertools import groupby
 for x, g in groupby([fields[1] for fields in data]):
     print x, len(tuple(g))

Avoid that len(tuple(g)), use something like the following, it's lazy
and saves some memory.


def leniter(iterator):
leniter(iterator): return the length of a given
iterator, consuming it, without creating a list.
Never use it with infinite iterators.

 leniter()
Traceback (most recent call last):
  ...
TypeError: leniter() takes exactly 1 argument (0 given)
 leniter([])
0
 leniter([1])
1
 leniter(iter([1]))
1
 leniter(x for x in xrange(100) if x%2)
50
 from itertools import groupby
 [(leniter(g), h) for h,g in groupby(bccaad)]
[(4, 'a'), (1, 'b'), (2, 'c'), (2, 'a'), (1, 'd'), (4, 'e')]

 def foo0():
... if False: yield 1
 leniter(foo0())
0

 def foo1(): yield 1
 leniter(foo1())
1

# This code is faster than:  sum(1 for _ in iterator)
if hasattr(iterator, __len__):
return len(iterator)
nelements = 0
for _ in iterator:
nelements += 1
return nelements

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fractions as result from divisions (was: Re: tough-to-explain Python)

2009-07-08 Thread kj
In c75ei6-e0i@satorlaser.homedns.org Ulrich Eckhardt 
eckha...@satorlaser.com writes:

Bearophile wrote:
 For example a novice wants to see 124 / 38 to return the 62/19
 fraction and not 3 or 3.263157894736842 :-)

Python has adopted the latter of the three for operator / and the the second
one for operator //. I wonder if it was considered to just return a
fraction from that operation.

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

kj

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


Re: Remoting over SSH

2009-07-08 Thread Lucas Carvalho

Hussein B wrote:

Hey,
I want to perform commands on a remote server over SSH.
What do I need?
Thanks.
  

Hi,
If you want to use the SSH2 protocol into a python code, you should
take a look at this module: paramiko [1].

[1] http://www.lag.net/paramiko/

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


Re: tough-to-explain Python

2009-07-08 Thread kj
In 5f0a2722-45eb-468c-b6b2-b7bb80ae5...@q11g2000yqi.googlegroups.com Simon 
Forman sajmik...@gmail.com writes:

Frankly, I'm of the impression that it's a mistake not to start
teaching programming with /the bit/ and work your way up from there.
I'm not kidding. I wrote a (draft) article about this: Computer
Curriculum http://docs.google.com/View?id=dgwr777r_31g4572gp4

I really think the only good way to teach computers and programming is
to start with a bit, and build up from there. Ontology recapitulates
phylogeny


I happen to be very receptive to this point of view.  I had the
benefit of that sort of training (one of the first computer courses
I took started, believe it or not, with Turing machines, through
coding in machine language, and compiler theory, and all the way
up to dabbling with Unix!), and I suspect that the reason it is
sometimes difficult for me to explain even relatively simple-looking
things to others is that I have this background that I unconsciously,
and incorrectly, take for granted in others...  There is this
persistent idea out there that programming is a very accessible
skill, like cooking or gardening, anyone can do it, and even profit
from it, monetarily or otherwise, etc., and to some extent I am
actively contributing to this perception by teaching this course
to non-programmers (experimental biologists to be more precise),
but maybe this idea is not entirely true...  Maybe, to get past
the most amateurish level, one has to, one way or another, come
face-to-face with bits, compilers, algorithms, and all the rest
that real computer scientists learn about in their formal training...

kj

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


Re: Remoting over SSH

2009-07-08 Thread Hendrik van Rooyen
Hussein B hubaghd...@gmail.com wrote:

 Hey,
 I want to perform commands on a remote server over SSH.
 What do I need?
 Thanks.

Access privileges for the remote machine.

- Hendrik



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


Re: DBI module deprecated at Python 2.5--what to use in its place?

2009-07-08 Thread Paul Moore
2009/7/8 dana dana_at_w...@yahoo.com:
 On Jul 8, 12:30 am, John Machin sjmac...@lexicon.net wrote:
 Deprecated certainly doesn't mean removed.
 For a start, none of (DBI, ODBC, dbi, odbc) are standard Python-
 supplied modules. Perhaps you are referring to the odbc (and dbi) from
 the pywin32 package? Where did you get them from? If you can't
 remember, try this:

 Thanks John. I mean the lower-case dbi and odbc modules from pywin32.
 Sorry for being vague. I assumed incorrectly they were part of the
 standard library because they came with pywin32.

pywin32 isn't part of the standard library, either - it just feels
like it if you're on Windows :-)

As you've already seen, the Python-Win32 list is probably of more use
to you: http://mail.python.org/mailman/listinfo/python-win32

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


Re: Fractions as result from divisions (was: Re: tough-to-explain Python)

2009-07-08 Thread Steven D'Aprano
On Wed, 08 Jul 2009 11:24:28 +0200, Ulrich Eckhardt wrote:

 Bearophile wrote:
 For example a novice wants to see 124 / 38 to return the 62/19 fraction
 and not 3 or 3.263157894736842 :-)
 
 Python has adopted the latter of the three for operator / and the the
 second one for operator //.

Up until a few years ago, / would return the integer division if both 
arguments where ints or longs, and // didn't even exist. Even in Python 
2.6, you still need to do

from __future__ import division 

to get the behaviour you describe.


 I wonder if it was considered to just return
 a fraction from that operation.

Because of his experience with ABC, Guido dislikes using fractions for 
standard arithmetic. He was resistant to even allowing the rational 
module be added to the standard library.

The problem with fractions is that, unless you're very careful, repeated 
arithmetic operations on numbers ends up giving you fractions like 

498655847957/569892397664

instead of the 7/8 you were expecting. Not only is that ugly, but it 
becomes slower and slower as the denominator and numerator become larger.

At least, that was Guido's experience.



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


Re: Check file is locked?

2009-07-08 Thread Steven D'Aprano
On Wed, 08 Jul 2009 00:06:11 -0700, Dennis Lee Bieber wrote:

   Also, some applications may still have the file open, but Windows
 allows one to make copies of that file...


Not always though... some applications open files for exclusive read 
access.


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


Re: Fractions as result from divisions

2009-07-08 Thread Hans Nowak

Ulrich Eckhardt wrote:

Bearophile wrote:

For example a novice wants to see 124 / 38 to return the 62/19
fraction and not 3 or 3.263157894736842 :-)


Python has adopted the latter of the three for operator / and the the second
one for operator //. I wonder if it was considered to just return a
fraction from that operation.


http://python-history.blogspot.com/2009/03/problem-with-integer-division.html

For example, in ABC, when you divided two integers, the result was an exact 
rational number representing the result. In Python however, integer division 
truncated the result to an integer.


In my experience, rational numbers didn't pan out as ABC's designers had hoped. 
A typical experience would be to write a simple program for some business 
application (say, doing one’s taxes), and find that it was running much slower 
than expected. After some debugging, the cause would be that internally the 
program was using rational numbers with thousands of digits of precision to 
represent values that would be truncated to two or three digits of precision 
upon printing. This could be easily fixed by starting an addition with an 
inexact zero, but this was often non-intuitive and hard to debug for beginners.


--
Hans Nowak (zephyrfalcon at gmail dot com)
http://4.flowsnake.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: tough-to-explain Python

2009-07-08 Thread Steven D'Aprano
On Wed, 08 Jul 2009 12:23:50 +, kj wrote:

 In 5f0a2722-45eb-468c-b6b2-b7bb80ae5...@q11g2000yqi.googlegroups.com
 Simon Forman sajmik...@gmail.com writes:
 
Frankly, I'm of the impression that it's a mistake not to start teaching
programming with /the bit/ and work your way up from there. I'm not
kidding. I wrote a (draft) article about this: Computer Curriculum
http://docs.google.com/View?id=dgwr777r_31g4572gp4
 
I really think the only good way to teach computers and programming is
to start with a bit, and build up from there. Ontology recapitulates
phylogeny
 
 
 I happen to be very receptive to this point of view.
[...]
 There is this persistent idea out there that
 programming is a very accessible skill, like cooking or gardening,
 anyone can do it, and even profit from it, monetarily or otherwise,
 etc., and to some extent I am actively contributing to this perception
 by teaching this course to non-programmers (experimental biologists to
 be more precise), but maybe this idea is not entirely true...  

There is some evidence that 30-60% of people simply cannot learn to 
program, no matter how you teach them:

http://www.codinghorror.com/blog/archives/000635.html
http://www.cs.mdx.ac.uk/research/PhDArea/saeed/

I'm sympathetic to the idea, but not entirely convinced. Perhaps the 
problem isn't with the students, but with the teachers, and the 
languages: 

http://www.csse.monash.edu.au/~damian/papers/PDF/SevenDeadlySins.pdf

(My money is that it's a little of both.)


 Maybe, to
 get past the most amateurish level, one has to, one way or another, come
 face-to-face with bits, compilers, algorithms, and all the rest that
 real computer scientists learn about in their formal training...

The No True Scotsman fallacy.

There's nothing amateurish about building software applications that 
work, with well-designed interfaces and a minimum of bugs, even if you've 
never heard of Turing Machines.


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


Re: library search path when compiling python

2009-07-08 Thread nn
On Jul 7, 4:06 pm, Christian Heimes li...@cheimes.de wrote:
 nn wrote:
  I am trying to compile python with ssl support but the libraries are
  not in /usr/lib but in /opt/freeware/lib. How do I add that folder to
  the default library search path?

  It looks like configure --libdir=DIR might do the job but I don't want
  to replace the default lib search path, just add an additional folder
  to it.

 You didn't mention your OS. On Linux you can set the environment
 variable LD_RUN_PATH prior to compiling Python. The env var sets the
 rpath for the linker. See man ld(1) for details.

 Christian

Sorry I didn't realize that was OS specific. I am on AIX 5.3.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tough-to-explain Python

2009-07-08 Thread kj
In 5f0a2722-45eb-468c-b6b2-b7bb80ae5...@q11g2000yqi.googlegroups.com Simon 
Forman sajmik...@gmail.com writes:

I'm not kidding. I wrote a (draft) article about this: Computer
Curriculum http://docs.google.com/View?id=dgwr777r_31g4572gp4

Very cool.

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


Re: Newbie needs help

2009-07-08 Thread Aahz
In article mailman.2781.1246979580.8015.python-l...@python.org,
Pablo Torres N. tn.pa...@gmail.com wrote:

Give this one a try too: http://www.mikeash.com/getting_answers.html
It doesn't talk down to you...as much :P

Nice!  I'll try remembering that one.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tough-to-explain Python

2009-07-08 Thread Paul Moore
2009/7/8 kj no.em...@please.post:
 There is this
 persistent idea out there that programming is a very accessible
 skill, like cooking or gardening, anyone can do it, and even profit
 from it, monetarily or otherwise, etc., and to some extent I am
 actively contributing to this perception by teaching this course
 to non-programmers (experimental biologists to be more precise),
 but maybe this idea is not entirely true...  Maybe, to get past
 the most amateurish level, one has to, one way or another, come
 face-to-face with bits, compilers, algorithms, and all the rest
 that real computer scientists learn about in their formal training...

Look at it another way. Experimental biologists don't want to program,
they want to use computers to do experimental biology. It's a tool,
and they (quite reasonably) don't *care* about robustness,
portability, etc. Or even about programming, to be honest.

In the context of the original question, it's entirely reasonable (in
my view) to tell this audience if the code does something weird you
don't understand, either ignore it and find another way or dig into
the manuals and experiment if you care. They'd very quickly find a =
a + b as a less confusing alternative to a += b. (As has been pointed
out earlier, to some extent a += b is quite an advanced construct -
after all, it's essentially an optimisation of a = a + b).

Biologists don't expect me to understand their discipline before I can
plant seeds in my garden, after all. (And when I do plant seeds, I
usually get far more surprising results than I could get from a += b
:-))

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


Re: tough-to-explain Python

2009-07-08 Thread nn
On Jul 7, 5:18 pm, kj no.em...@please.post wrote:
 In mailman.2796.1246997332.8015.python-l...@python.org Chris Rebert 
 c...@rebertia.com writes:

 You might find the following helpful (partially):
 http://effbot.org/zone/call-by-object.htm

 Extremely helpful.  Thanks!  (I learned more from it than someone
 who will teach the stuff would care to admit...)

 And it confirmed Paul Graham's often-made assertion that all of
 programming language design is still catching up to Lisp...

 kj

One possibility is to avoid teaching mutable datatypes at the
beginning (i.e. no lists,dicts and sets), then you would have
something more lispish. You would have to use tuples instead of lists
for everything. That avoids the gotchas of mutable types at the cost
of efficiency.

Python is not a purist language but rather walks a fine line between
high flexible abstractions and simple fast implementation.
-- 
http://mail.python.org/mailman/listinfo/python-list


The meaning of = (Was: tough-to-explain Python)

2009-07-08 Thread kj
In h30e3t$g5...@reader1.panix.com kj no.em...@please.post writes:

I had not realized how *profoundly* different the meaning of the
= in Python's

  spam = ham

is from the = in its

  spam[3] = ham[3]


To clarify, this comes from my reading of Fredrik Lundh's pages
Python Objects (http://effbot.org/zone/python-objects.htm) and
Call By Object (http://effbot.org/zone/call-by-object.htm).
(Thanks to Chris Rebert for the pointer!)

In the first one of these pages, Lundh writes:

[START OF LENGTHY QUOTE]

  Assignment statements modify namespaces, not objects.

  In other words,

  name = 10

  means that you're adding the name 'name' to your local namespace,
  and making it refer to an integer object containing the value
  10.

  If the name is already present, the assignment replaces the
  original name:

  name = 10
  name = 20

  means that you're first adding the name 'name' to the local
  namespace, and making it refer to an integer object containing
  the value 10. You're then replacing the name, making it point to
  an integer object containing the value 20. The original '10'
  object isn't affected by this operation, and it doesn't care.

  In contrast, if you do:

  name = []
  name.append(1)

  you're first adding the name 'name' to the local namespace, making
  it refer to an empty list object. This modifies the namespace.
  You're then calling a method on that object, telling it to append
  an integer object to itself. This modifies the content of the
  list object, but it doesn't touch the namespace, and it doesn't
  touch the integer object.

  Things like name.attr and name[index] are just syntactic sugar
  for method calls. The first corresponds to __setattr__/__getattr__,
  the second to __setitem__/__getitem__ (depending on which side
  of the assignment they appear).

[END OF LENGTHY QUOTE]

Therefore, extending just a bit beyond Lundh's explanation, if we
did:

name = []
name.append(1)
name[0] = 3

...the second assignment would amount to a method call on the object
called 'name', an operation of a very different nature (according
to Lundh) from the first assignment, which is a modification of a
namespace.

In the second one of these pages, Lundh makes a very similar point
(third post from the bottom).

But note that Lundh appears to be contradicting himself somewhat
when he writes Assignment statements modify namespaces, not
objects.  If by assignment statements he means ones consisting
of a left operand, a =, and a right operand, then according to
the rest of what he writes on this subject, this assertion applies
only to *some* assignment statements, namely those of the form

  identifier = expression

and not to those like, for example,

  identifier[expression] = expression

or

  identifier.identifier = expression

The former are syntatic sugar for certain namespace modifications
that leave objects unchanged.  The latter are syntactic sugar for
certain object-modifying method calls that leave namespaces unchanged.

At least this is how I interpret what Lundh writes.

kj

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


Re: Clarity vs. code reuse/generality

2009-07-08 Thread pdpi
On Jul 8, 2:24 am, Paul Rubin http://phr...@nospam.invalid wrote:
 pdpi pdpinhe...@gmail.com writes:
      while abs(func(guess) - target)  epsilon:
          guess = (lo + hi) / 2.
          if sense * func(guess)  sense * target:
              hi = guess
          elif sense * func(guess)  sense * target:
              lo = guess
          elif lo == hi:
              return None
      return guess

 That is completely confusing.  I get the, er, impression that sense
 is supposed to change during the loop, and it takes much head
 scratching to tell whether what you have there is right or not.  Also,
 it calls func 3 times on each loop, which could be extremely slow.
 You don't know what func does, so eliminating 2/3 of the calls to it
 is not a micro-optimization--it could be a major time saving.

 Yet another version:

     def _binary_search(x0, x1, func, target, epsilon):
         y0,y1 = func(x0), func(x1)
         while abs(y1 - target)  epsilon:
             if x0 == x1 or cmp(y0,target) == cmp(y1,target):
                 return None
             xn = (x0 + x1) / 2.
             yn = func(xn)
             if cmp(yn,target) == cmp(y0,target):
                x0,y0 = xn,yn
             else:
                x1,y1 = xn,yn
         return x1

micro-optimization was perhaps too harsh, but it is an optimization
that's not obvious for the newbie, and one best learnt from experience
rather than having it spoon fed. I'll restate: you should start with
the cleanest code possible and mangle it for performance. Then again,
that implicitly assumes that f(x) is more readable than y, which is
really a matter of taste...
-- 
http://mail.python.org/mailman/listinfo/python-list


[0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Daniel Austria
Hi python - hackers,

just one question. How can i remove all 0 values in a list? Sure - i
can loop over it, but that s not a neat style.  list.remove() will
only remove the first occurence. Doing that while no exception is
raised is also uncool, right?

Some suggestions?


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


Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread ma
filter(lambda x: x, your_list)

On Wed, Jul 8, 2009 at 10:44 AM, Daniel Austria futureb...@gmx.at wrote:

 Hi python - hackers,

 just one question. How can i remove all 0 values in a list? Sure - i
 can loop over it, but that s not a neat style.  list.remove() will
 only remove the first occurence. Doing that while no exception is
 raised is also uncool, right?

 Some suggestions?


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

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


Re: The meaning of = (Was: tough-to-explain Python)

2009-07-08 Thread Paul Boddie
On 8 Jul, 16:04, kj no.em...@please.post wrote:

   identifier = expression

 and not to those like, for example,

   identifier[expression] = expression

 or

   identifier.identifier = expression

 The former are syntatic sugar for certain namespace modifications
 that leave objects unchanged.  The latter are syntactic sugar for
 certain object-modifying method calls that leave namespaces unchanged.

Almost. The latter can modify namespaces - the objects themselves -
but through properties or dynamic attribute access, they may choose
not to modify such a namespace. Really, we can phrase assignment (=)
as follows:

thing = expression # make thing refer to the result of
expression

Here, thing has to provide something that can be made to refer to
something else, such as a name within a namespace - the first and last
of your cases - or an item or slice within a sequence - the special
second case which is actually handled differently from the other
cases.

Meanwhile, the expression will always provide an object to refer to,
never anything of the nature of thing referring to something else.
In other words, if you have this...

x[1] = y[2]

...then the expression which is y[2] will yield an object which is
then assigned to x[1]. The concept of y[2] is not assignable - it must
be fully evaluated and produce the object at location #2 in the
sequence for assignment.

I suppose you could say that the left-hand side thing is like a sign
on a signpost which always points to a real place, not another sign on
a signpost. You could stretch this analogy by treating sequences as
signposts holding many signs, each adjustable to point to something
different. Since signposts (not the individual signs) are located in
real places, they would naturally be acceptable as targets of
assignments: where the signs are allowed to point to. Indeed, this
would be a world of signposts with the occasional primitive value
mixed in to keep weary travellers interested. ;-)

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


Re: Remoting over SSH

2009-07-08 Thread Djames Suhanko
Hello!
 I wrote a litle program that send commands to many cluster nodes:

#!/usr/bin/env python
#By: Djames Suhanko

#servers list

sincroniza =[server1.domain,server2.domain, server3.domain]

import pexpect
import sys
from threading import Thread

#the user and pass can be in ini file.

#Test parameters list

try:
if sys.argv[3]:
pass
except:
print  Use:  + script +  command user pass
sys.exit()

#This function send  the command in argument
def executor(command,username,password,server):
a = 'ssh ' + username + '@' + server
foo = pexpect.spawn(a)
foo.expect('.*ssword:')
foo.sendline(password)
foo.sendline('su')
foo.expect('.*sword:')
foo.sendline('root_password_here')
foo.sendline(command + ' exit')
print command to:  + server + ..[OK]
foo.sendline('exit')
foo.expect('.*osed.')
foo.interact()

#make a list
tasks = []

#theading loop
for i in sincroniza:
t = Thread(target=executor,args=(sys.argv[1],sys.argv[2],sys.argv[3],i))
t.start()
tasks.append(t)

#wait the end
for t in tasks:
t.join()

it's all!
On Wed, Jul 8, 2009 at 9:15 AM, Hendrik van Rooyenm...@microcorp.co.za wrote:
 Hussein B hubaghd...@gmail.com wrote:

 Hey,
 I want to perform commands on a remote server over SSH.
 What do I need?
 Thanks.

 Access privileges for the remote machine.

 - Hendrik



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




-- 
Djames Suhanko
LinuxUser 158.760
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Bruno Desthuilliers

Daniel Austria a écrit :

Hi python - hackers,

just one question. How can i remove all 0 values in a list? Sure - i
can loop over it, but that s not a neat style.  list.remove() will
only remove the first occurence. Doing that while no exception is
raised is also uncool, right?

Some suggestions?


the_list = [0, 0, 0, 1, 1, 1, 0]

# Simple solution
print [x for x in the_list if x != 0]

# if you want to mutate the list 'in place':
the_list[:] = [x for x in the_list if x != 0]
print the_list

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


Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Charles Yeomans


On Jul 8, 2009, at 10:54 AM, ma wrote:


filter(lambda x: x, your_list)

On Wed, Jul 8, 2009 at 10:44 AM, Daniel Austria futureb...@gmx.at  
wrote:

Hi python - hackers,

just one question. How can i remove all 0 values in a list? Sure - i
can loop over it, but that s not a neat style.  list.remove() will
only remove the first occurence. Doing that while no exception is
raised is also uncool, right?

Some suggestions?




L = [0, 0, 0, 1, 1, 1, 0]
M = [x for x in L if x !=0]


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


Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread D'Arcy J.M. Cain
On Wed, 8 Jul 2009 10:54:09 -0400
ma mabdelka...@gmail.com wrote:
 filter(lambda x: x, your_list)

Or...

 [x for x in your_list if x]

I'm not sure which one is more efficient but I like the syntax of the
latter.  A smart person could probably figure it out even without
knowing Python syntax.  Clarity is trump.

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Friðrik Már Jónsson


ma wrote:

filter(lambda x: x, your_list)


Good call! Equivalent but more efficient:

 filter(None, your_list)

Regards,
Friðrik Már
--
http://mail.python.org/mailman/listinfo/python-list


Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Diez B. Roggisch
Daniel Austria wrote:

 Hi python - hackers,
 
 just one question. How can i remove all 0 values in a list? Sure - i
 can loop over it, but that s not a neat style.

Why not? If you need to potentially look at *all* elements of a list,
nothing but a loop will take you there.

OTOH, your proposed remove until nothing is found-thingy will become
quadratic in behavior, as remove also loops over the list - so if you have
list with say 10 ones followed by 10 zeros, you will loop ten times for 11
elements, which is in the order of (n/2)**2.

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


Re: Remoting over SSH

2009-07-08 Thread Raúl Gómez C .
You also could use
TwistedConchhttp://twistedmatrix.com/trac/wiki/TwistedConch,
which is an implementation of the SSH2 protocol for Python. I've done
something with it, you can read my first questions on the TwistedConch list
herehttp://twistedmatrix.com/pipermail/twisted-python/2007-October/016121.html
.

Hope that helps...


-- 
Nacho
Linux Counter #156439
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The meaning of = (Was: tough-to-explain Python)

2009-07-08 Thread kj
In 0778f257-d36c-4e13-93ea-bf8d448c8...@b15g2000yqd.googlegroups.com Paul 
Boddie p...@boddie.org.uk writes:

On 8 Jul, 16:04, kj no.em...@please.post wrote:

 =A0 identifier =3D expression

 and not to those like, for example,

 =A0 identifier[expression] =3D expression

 or

 =A0 identifier.identifier =3D expression

 The former are syntatic sugar for certain namespace modifications
 that leave objects unchanged. =A0The latter are syntactic sugar for
 certain object-modifying method calls that leave namespaces unchanged.

Almost. The latter can modify namespaces - the objects themselves -
but through properties or dynamic attribute access, they may choose
not to modify such a namespace. Really, we can phrase assignment (=3D)
as follows:

thing =3D expression # make thing refer to the result of
expression

Here, thing has to provide something that can be made to refer to
something else, such as a name within a namespace - the first and last
of your cases - or an item or slice within a sequence - the special
second case which is actually handled differently from the other
cases.

Thanks for this correction.

OK, so, scratching from my original post the case

identifier.identifier = expression

(as being a special case of identifier = expression), still,
to the extent that I understand your post, the = in

  x = 1

means something fundamentally different (in terms of Python's
underlying implementation) from the = in

  y[0] = 1

No?

You could stretch this analogy by treating sequences as
signposts holding many signs, each adjustable to point to something
different.

Notionally, yes, I can see that, but there's no counterpart of this
analogy at the level of Python's implementation.  The x above is
a sign, as you put it, i.e. an entry in a namespace, but y[0]
is, in essence, a method call.

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


Re: The meaning of = (Was: tough-to-explain Python)

2009-07-08 Thread Aahz
In article 0778f257-d36c-4e13-93ea-bf8d448c8...@b15g2000yqd.googlegroups.com,
Paul Boddie  p...@boddie.org.uk wrote:

Almost. The latter can modify namespaces - the objects themselves -
but through properties or dynamic attribute access, they may choose
not to modify such a namespace. Really, we can phrase assignment (=)
as follows:

thing = expression # make thing refer to the result of expression

Right, except s/thing/target/

http://docs.python.org/reference/simple_stmts.html#assignment-statements
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Error from Apress book

2009-07-08 Thread Matthew Edmondson
I'm running XP SP3. The program now works great from either of the
directories, as long as include 'python' before it. As far as looking at the
error with stack trace, I really don't know enough yet to know how to do
that. I'm running the file from command line, because I'm not sure how to
run it referencing other files from idle. Lot to learn.

Once again, thanks a ton for all of the help.

Matt

On Wed, Jul 8, 2009 at 2:35 AM, Dave Angel da...@ieee.org wrote:



 Gabriel Genellina wrote:

 div class=moz-text-flowed style=font-family: -moz-fixedEn Tue, 07
 Jul 2009 09:55:13 -0300, Dave Angel da...@ieee.org escribió:

 Gabriel Genellina wrote:

 En Mon, 06 Jul 2009 19:56:40 -0300, matt0177 matt0...@gmail.com
 escribió:


  When I try to run the command as outlined in
 the book simple_markup2.py  test_input.txt  test_output.html i get
 the
 following error every time.

 IOError: [Errno 9] Bad file descriptor


 That's a Windows problem. When you execute the script as itself (either
 as you do in the command line, or by double-clicking on it), it doesn't 
 have
 valid standard handles.
 You have to invoke Python explicitely:

 python simple_markup2.py  test_input.txt  test_output.html

 (you may need to specify the full path to python.exe, or add the
 directory where Python is installed to your system PATH).

  I use stdout this way all the time, with no problem (python 2.6,
 Windows XP).  But as you point out, stdin redirection doesn't seem to work
 using the file associations.  I do get a different error though. When I look
 at sys.stdin, it shows an open file, with handle of zero, as expected.  But
 when I do a raw_input(), it gets:
 EOFError: EOF when reading a line


 I think the error depends on the specific OS version/service pack. But at
 least on XP this appears to fix it:

 http://support.microsoft.com/kb/321788/en-us

  Thanks for the link.  Looking at that one, it indicates that Windows 2000
 fixed it in SP4, and XP fixed it in Sp1.  But I'm already running XP SP3, so
 I wonder if it's something new.

 Matt, what OS version are you running, and exactly what is happening when
 the error occurs?  (you should be able to figure that out from the stack
 trace)


 DaveA

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


Re: tough-to-explain Python

2009-07-08 Thread Dave Angel

kj wrote:

In 5f0a2722-45eb-468c-b6b2-b7bb80ae5...@q11g2000yqi.googlegroups.com Simon Forman 
sajmik...@gmail.com writes:

  

Frankly, I'm of the impression that it's a mistake not to start
teaching programming with /the bit/ and work your way up from there.
I'm not kidding. I wrote a (draft) article about this: Computer
Curriculum http://docs.google.com/View?id=dgwr777r_31g4572gp4



  

I really think the only good way to teach computers and programming is
to start with a bit, and build up from there. Ontology recapitulates
phylogeny




I happen to be very receptive to this point of view.  I had the
benefit of that sort of training (one of the first computer courses
I took started, believe it or not, with Turing machines, through
coding in machine language, and compiler theory, and all the way
up to dabbling with Unix!), and I suspect that the reason it is
sometimes difficult for me to explain even relatively simple-looking
things to others is that I have this background that I unconsciously,
and incorrectly, take for granted in others...  There is this
persistent idea out there that programming is a very accessible
skill, like cooking or gardening, anyone can do it, and even profit
from it, monetarily or otherwise, etc., and to some extent I am
actively contributing to this perception by teaching this course
to non-programmers (experimental biologists to be more precise),
but maybe this idea is not entirely true...  Maybe, to get past
the most amateurish level, one has to, one way or another, come
face-to-face with bits, compilers, algorithms, and all the rest
that real computer scientists learn about in their formal training...

kj


  
And I learned to program Analog Computers, along with APL, in an early 
course.  In my case assembly language came later, but by then we had 
covered the electronics behind transistors, and Karnough maps, logic 
diagrams, and so on.  By the time I graduated, I had five six-level 
languages and two assembly languages under my belt.


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


Re: The meaning of = (Was: tough-to-explain Python)

2009-07-08 Thread Aahz
In article h32eoh$ql...@reader1.panix.com, kj  no.em...@please.post wrote:

OK, so, scratching from my original post the case

identifier.identifier = expression

(as being a special case of identifier = expression), still,
to the extent that I understand your post, the = in

  x = 1

means something fundamentally different (in terms of Python's
underlying implementation) from the = in

  y[0] = 1

No?

No.  ;-)  What's different is not the ``=`` but the construction of the
assignment target before ``=`` gets executed.  Consider also this:

x, y = y, x
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


OT: unix to Windows technology

2009-07-08 Thread Xah Lee
Dear unixers  lispers,

i've been using Mac for the past 19 years, and been a professional sys
admin or web app developers on the unix platform, since 1998 (maily
Solaris, Apache, Perl, Java, SQL, PHP). In june, i bought a PC (not
for the first time though), and made a switch to Windows, for the
first time, in the sense as a developer instead of just a casual PC
user i've been.

In the past month, i've spend about 5 hours a day digging into MS
Windows tech, in particluar, read over 200 Wikipedia articles in
detail related to Windows technology. (192 of them linked)

Here's a write up of the whole story, my experiences, including some
tech introduction to MS Windows from a sys admin or programer point of
view.

• Switching from Mac/Unix To PC/Windows
  http://xahlee.org/mswin/switch_to_windows.html

Some slightly noteworthy subsections are:

• Removing HP/Compaq Software
  http://xahlee.org/mswin/hp_bundled_apps.html

• Installing Cygwin Tutorial
  http://xahlee.org/mswin/installing_cygwin.html

• Mac and Windows File Conversion
  http://xahlee.org/mswin/mac_windows_file_conv.html

• Unix And Windows File Permission Systems
  http://xahlee.org/mswin/file_perm_systems.html

• Introduction to Windows Scripting
  http://xahlee.org/mswin/windows_scripting.html

Some articles (not shown above) are still work in progress, such as
VBScript tutorial and PowerShell tutorial. Hoping to complete in the
coming months or years.

comment  feedback welcome, esp if you are a Windows expert and answer
some of my unanswered questions on the page.

  Xah
∑ http://xahlee.org/

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


Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread J Kenneth King
Friðrik Már Jónsson frid...@pyth.net writes:

 ma wrote:
 filter(lambda x: x, your_list)

 Good call! Equivalent but more efficient:

  filter(None, your_list)

 Regards,
 Friðrik Már

I was wondering when someone would mention filter()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does cProfile include IO wait time?

2009-07-08 Thread Robert Kern

On 2009-07-04 19:03, Matthew Wilson wrote:

I have a command-line script that loads about 100 yaml files.  It takes
2 or 3 seconds.  I profiled my code and I'm using pstats to find what is
the bottleneck.

Here's the top 10 functions, sorted by internal time:

 In [5]: _3.sort_stats('time').print_stats(10)
 Sat Jul  4 13:25:40 2009pitz_prof

  756872 function calls (739759 primitive calls) in 8.621 CPU 
seconds

Ordered by: internal time
List reduced from 1700 to 10 due to restriction10

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 151530.4460.0000.5030.000 
build/bdist.linux-i686/egg/yaml/reader.py:134(forward)
 305300.4240.0000.8420.000 
build/bdist.linux-i686/egg/yaml/scanner.py:142(need_more_tokens)
 980370.4230.0000.4230.000 
build/bdist.linux-i686/egg/yaml/reader.py:122(peek)
  19550.4150.0001.2650.001 
build/bdist.linux-i686/egg/yaml/scanner.py:1275(scan_plain)
 699350.3810.0000.3810.000 {isinstance}
 189010.3290.0003.9080.000 
build/bdist.linux-i686/egg/yaml/scanner.py:113(check_token)
  54140.2770.0000.7940.000 
/home/matt/projects/pitz/pitz/__init__.py:34(f)
 309350.2580.0000.3640.000 
build/bdist.linux-i686/egg/yaml/scanner.py:276(stale_possible_simple_keys)
 189450.1920.0000.3140.000 
/usr/local/lib/python2.6/uuid.py:180(__cmp__)
  23680.1720.0001.3450.001 
build/bdist.linux-i686/egg/yaml/parser.py:268(parse_node)

I expected to see a bunch of my IO file-reading code in there, but I don't.  So
this makes me think that the profiler uses CPU time, not
clock-on-the-wall time.


It should be basically wall-clock time on Linux. The timer function underneath 
is gettimeofday(2). Look in Modules/_lsprof.c of the Python sources for the 
function hpTimer().


--
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: The meaning of = (Was: tough-to-explain Python)

2009-07-08 Thread kj
In h32fon$26...@panix3.panix.com a...@pythoncraft.com (Aahz) writes:

In article h32eoh$ql...@reader1.panix.com, kj  no.em...@please.post wrote:

OK, so, scratching from my original post the case

identifier.identifier = expression

(as being a special case of identifier = expression), still,
to the extent that I understand your post, the = in

  x = 1

means something fundamentally different (in terms of Python's
underlying implementation) from the = in

  y[0] = 1

No?

No.  ;-)

No???  Just when I thought I finally understood all this!

What's different is not the ``=`` but the construction of the
assignment target before ``=`` gets executed.

Hmm.  OK, I went to the link you posted in your other message
(http://docs.python.org/reference/simple_stmts.html#assignment-statements)
and I find this (my emphasis):

Assignment of an object to a single target is recursively defined as 
follows.

* If the target is an identifier (name):

  o If the name does not occur in a global statement in
the current code block: the name is bound to the object
^
in the current local namespace.

  o Otherwise: the name is bound to the object in the
   ^
current global namespace.

  The name is rebound if it was already bound. This may cause
  the reference count for the object previously bound to the
  name to reach zero, causing the object to be deallocated and
  its destructor (if it has one) to be called.

* If the target is a target list enclosed in parentheses or in
  square brackets... (I'LL IGNORE THIS FOR NOW)

* If the target is an attribute reference: The primary expression
  in the reference is evaluated. It should yield an object with
  assignable attributes; if this is not the case, TypeError is
  raised. That object is then asked to assign the assigned
  
  object to the given attribute; if it cannot perform the
  ^^
  assignment, it raises an exception (usually but not necessarily
  AttributeError).

* If the target is a subscription: The primary expression in
  the reference is evaluated. It should yield either a mutable
  sequence object (such as a list) or a mapping object (such
  as a dictionary). Next, the subscript expression is evaluated.

  If the primary is a mutable sequence object (such as a
  list),...  [CONDITIONS ON THE INDEX EXPRESSION OMITTED]...
  the sequence is asked to assign the assigned object to its
  ^^^
  item with that index

  If the primary is a mapping object (such as a dictionary),...
  [CONDITIONS ON THE SUBSCRIPT EXPRESSION OMITTED]... the
  ^^^
  mapping is then asked to create a key/datum pair which maps
  ^^^
  the subscript to the assigned object.
  

* If the target is a slicing: [INDEX STUFF OMITTED]... the
   ^^^
  sequence object is asked to replace the slice with the items
  
  of the assigned sequence...
  

OK, I originally interpreted what Lundh wrote in his two articles
that the binding described at the very beginning (i.e. when the
target is an identifier), which I take to make an entry or modify
such an entry in a namespace, is a *categorically different*
operation from the remaining operations underlined above.

I interpreted Paul Boddie's correction in his response to me as
saying that the assignment mentioned for the case when the target
is an attribute reference is actually a special case of the
assignment to simple identifiers (i.e. it also means binding).

But that still leaves all the other assignments (or the like)
underlined above.  I don't think that the full definitions of these
remaining cases are covered by the same rule, even though the rule
is described as recursive.  I think that the writer has something
else in mind, and in particular, something *other* than binding,
but the author remains vague on exactly what this means.

Clearly, both Lundh and the documentation draw some distinction
between binding and some other forms of assignment (which remain
ill-defined throughout).  This distinction is what I was referring
to when I said that = means different things in different contexts.

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


Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Friðrik Már Jónsson

J Kenneth King wrote:

I was wondering when someone would mention filter()


I was happy to see that too.

It's clean, faster than list comprehension and in terms of clarity  
it's only to be expected that the developer is familiar with, or at  
least willing to look up, the available built-in methods.


Regards,
Friðrik Már
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: unix to Windows technology

2009-07-08 Thread Kenneth Tilton

Xah Lee wrote:

Dear unixers  lispers,

i've been using Mac for the past 19 years, and been a professional sys
admin or web app developers on the unix platform, since 1998 (maily
Solaris, Apache, Perl, Java, SQL, PHP). In june, i bought a PC (not
for the first time though), and made a switch to Windows, for the
first time, in the sense as a developer instead of just a casual PC
user i've been.

In the past month, i've spend about 5 hours a day digging into MS
Windows tech, in particluar, read over 200 Wikipedia articles in
detail related to Windows technology. (192 of them linked)

Here's a write up of the whole story, my experiences, including some
tech introduction to MS Windows from a sys admin or programer point of
view.

• Switching from Mac/Unix To PC/Windows
  http://xahlee.org/mswin/switch_to_windows.html

Some slightly noteworthy subsections are:

• Removing HP/Compaq Software
  http://xahlee.org/mswin/hp_bundled_apps.html

• Installing Cygwin Tutorial
  http://xahlee.org/mswin/installing_cygwin.html

• Mac and Windows File Conversion
  http://xahlee.org/mswin/mac_windows_file_conv.html

• Unix And Windows File Permission Systems
  http://xahlee.org/mswin/file_perm_systems.html

• Introduction to Windows Scripting
  http://xahlee.org/mswin/windows_scripting.html

Some articles (not shown above) are still work in progress, such as
VBScript tutorial and PowerShell tutorial. Hoping to complete in the
coming months or years.

comment  feedback welcome, esp if you are a Windows expert and answer
some of my unanswered questions on the page.

  Xah
∑ http://xahlee.org/

☄


You just discovered PCs are cheaper?

The funny thing is that that is Microsoft's answer to the Apple Mac-PC 
ads, they show people shopping for computers and just comparing hardware 
and price as if this is some kind of breakthrough. But I understand: 
they have no answer to Windows being such a nightmare and the Mac being 
such a joy.


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


Re: The meaning of = (Was: tough-to-explain Python)

2009-07-08 Thread Terry Reedy

kj wrote:


To clarify, this comes from my reading of Fredrik Lundh's pages
Python Objects (http://effbot.org/zone/python-objects.htm) and
Call By Object (http://effbot.org/zone/call-by-object.htm).

[snip]

[END OF LENGTHY QUOTE]

Therefore, extending just a bit beyond Lundh's explanation, if we
did:

name = []
name.append(1)
name[0] = 3

...the second assignment would amount to a method call on the object
called 'name', an operation of a very different nature (according
to Lundh) from the first assignment, which is a modification of a
namespace.


I disagree. Assignment creates an association. Modification of a 
namespace, when implemented, amounts to a method call on the concrete 
object, whether a Python object or not, that implements the abstraction 
of a namespace. At module scope,

  name = ob
is the same as
  globals()['name']=ob
Within a class statement, substitute 'class-dict' for 'globals'
Within functions, CPython uses an internal array, so
  name = ob
becomes
  locals_array[name-number] = ob

Or, to put it another way, Python dicts and lists are, considered 
abstractly, associations also, just like namespaces. Dicts are more 
general than namespaces, sequences are 'number-spaces' instead of 
name-spaces.


Terry Jan Reedy

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


Re: Python and webcam capture delay?

2009-07-08 Thread Nobody
On Tue, 07 Jul 2009 22:49:22 -0700, Dennis Lee Bieber wrote:

 On Tue, 07 Jul 2009 23:37:43 +0100, Nobody nob...@nowhere.com
 declaimed the following in gmane.comp.python.general:
 
 AFAIK, the only real difference between USB-1 conformant and USB-2
 conformant is that the latter actually passed a test of its ability to
 say no, I can't do high-speed, while the former didn't. The check for
 high-speed capability was designed such that it shouldn't cause problems
 for USB-1 devices, but individual USB-1 devices weren't actually tested
 for this.
 
   USB-1 or USB-1.1? As I recall the latter is capable of 11Mbps
 whereas the original USB spec was much lower... (of course, USB 2 at top
 is 480Mbps)

USB 1.0 supports 1.5Mbps (low-speed) and 12MBps (full-speed). Hosts and
hubs must support both, functions (devices) can use either. USB 1.1 was
a bug-fix release which solved some interoperability issues arising from
ambiguities in the USB 1.0 standard.

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


Problem with list of dicts and copying

2009-07-08 Thread Cameron Pulsford
Hello all, I'm redoing a sudoku solver of mine and I ran into an issue with
lists of dicts. Bear with me for a second before I get to the actual
problem... I'm representing the board as a dictionary, where the keys are
(x, y) positions, and the values are candidates. So my program goes along
picking numbers from the list of candidates and then propagating the
constraints. So it might place a 6, which would then remove 6 as a candidate
from that row column and grid. However, that might leave a spot with no
candidates, which means we placed a legal but not correct number. This is
where my problem arises. I keep a running list of the boards which is
updated every time I find a legal number that doesn't invalidate the boards.
I add onto this list by doing boards.append(self.board.copy()). When I
place a legal but invalid number I do self.board = boards[-1].copy() to
return the board to the last known good state. And when I completely exhaust
the candidates for a spot and must backtrack to a different spot (instead of
simply trying a different candidate of the current spot) I do self.board =
boards[-1].copy() and then del boards[-1]
Basically my boards list should be copies of good boards, and when I need to
refresh the current board, I want to pull off a copy of the correct one.
Essentially (after watching the debugging output) it looks like this isn't
happening. I am always modifying the same board. The algo follows, and I can
post the rest of the code if necessary. So am I using the dict.copy() wrong?
Am I guessing I have a tricky problem with the = in self.board =
boards[-1].copy()

def solve(self):
previousValue = dict((blank, 0) for blank in self.blanks())
self.fillInCandidates()
continuing, boards, guesses = False, [self.board.copy()], 0
while len(self.blanks())  0:
if continuing == False:
cp = self.mrv()
continuing = False
nl = self.nextLegal(cp, previousValue[cp])
previousValue[cp] = nl
if nl != 0:
self.board[cp] = nl
guesses += 1
self.update(nl, cp[0], cp[1])
if self.isNotLegal():
continuing = True
self.board = boards[-1].copy()
else:
boards.append(self.board.copy())
else:
previousValue[cp] = 0
self.board = boards[-1].copy()
del boards[-1]
-- 
http://mail.python.org/mailman/listinfo/python-list


windows command-line

2009-07-08 Thread Lucas Junqueira
Hi, I'd like to run a simple windows command-line program from within my python 
script and agt all the returt it generates. Is this possible? How can I do it?

Thank you!



  

Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com-- 
http://mail.python.org/mailman/listinfo/python-list


Re: windows command-line

2009-07-08 Thread Emile van Sebille

On 7/8/2009 10:07 AM Lucas Junqueira said...
Hi, I'd like to run a simple windows command-line program from within my 
python script and agt all the returt it generates. Is this possible? How 
can I do it?


Depending on python version, look into subprocess, commands or os.pipe 
and related.


Emile

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


Re: Python and webcam capture delay?

2009-07-08 Thread Nobody
On Tue, 07 Jul 2009 22:11:12 -0700, Tim Roberts wrote:

The webcam is bound to do some encoding; most of them use USB full speed
(12Mbit/sec), which isn't enough for raw 640x480x24...@30fps data.
 
 That's not true.  Most of the web cams made in the last 5 years or so run
 at high speed, 480 Mbps.  Full speed only gets you 1 fps at 640x480
 uncompressed, so it's really only useful for the most primitive video
 conference cams.

The very earliest models typically only did 320x200, while later USB-1
webcams used onboard compression to get a decent framerate.

For internet use, 12Mbps isn't that much of an obstacle; the internet
connection's upload speed is more likely to be the limiting factor. Faster
speeds are more useful for things like LAN-based CCTV systems.

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


Re: Check file is locked?

2009-07-08 Thread Nobody
On Tue, 07 Jul 2009 21:31:12 -0700, Rajat wrote:

  By the way most operating systems don't lock a file when it's opened for
  reading or writing or even executed.

 The general conclusion seems to be that mandatory locking is more trouble
 than it's worth.
 
 My OS is a windows XP sp3. All I'm trying to achieve is to close an
 application ( which could be a notepad, a wordpad or some other text
 editor) that have opened my file. Once the file is closed I can easily
 delete that file.
 
 I guess, if file is opened by one of that application, the file must
 be locked and so is the reason I cannot delete the file.

Windows doesn't allow you to delete (or rename) open files. It's up to the
application as to whether it keeps the file open or closes it once it has
been read.

 Please suggest if this is fine.

If you can't delete the file, then you can't delete it. You shouldn't be
trying to kill off applications so that you can delete the file. Just do
what other Windows programs (including those which are part of Windows)
do: display a dialog telling the user to close the application then try
again.

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


Re: OT: unix to Windows technology

2009-07-08 Thread Xah Lee
Xah Lee wrote:
 • Switching from Mac/Unix To PC/Windows
  http://xahlee.org/mswin/switch_to_windows.html

Kenneth Tilton wrote:
 You just discovered PCs are cheaper?

 The funny thing is that that is Microsoft's answer to the Apple Mac-PC
 ads, they show people shopping for computers and just comparing hardware
 and price as if this is some kind of breakthrough. But I understand:
 they have no answer to Windows being such a nightmare and the Mac being
 such a joy.

well, i've been owning Macs for over the past 19 years. From a
dedicated fan thru-out the 1990s, to still fan in early of 2000s with
debut of OS X.

Mac prices in comparison to PC has gone up and downs. In the early
1990s for example, it is maybe 4 times more. Lowest is probably in the
mid 1990s, where 3rd party companies are licensed to producing clones,
and that happens to also be a period that Mac OS is the worst,
crashing few times per day, similar to Win 95 and 98. I think in the
early 2000s the price gap came closer, and since maybe 2005 it start
to increase again.

for someone like me, i've read all the pros and cons of Mac vs PC.
I've read, for instance, basically all MacWorld and MacUser mags in
the early 1990s until they become defunct. (and often MacWeek too) Not
to mention the huge amount of websites, especially in the late 1990s
where there are a number of high profile dedicated mac fan sites. I
also have often attended the yearly Mac World Expo, eagerly antipating
Steve Job's “O, one more thing...”  etc... and etc and etc. As a
hyperbole, i've prob read more Mac vs PC argument from newsgroup users
combined. LOL

as to the price comparison... a better metric is value/price ratio. I
think, over the past 20 years, the value/price ratio of Mac compared
to PC, namely:

(MacValue/MacPrice)/(PC_value/PC_price)

is going down, starting with Windows NT 4, and going downhill quickly
with Windows XP, and Vista, .NET.

as far as SOFTWARE technology goes, Apple's falling lamer and lamer
from its 1990s mountain top of lisps and hypercards and desktop
publishing stuff. Microsoft Windows, starting from MS-DOS moronicity,
today, with its .NET, F#, PowerShell, is quite beyond Apple's
perpetual diddling with its prettification of OS X.

  Xah
∑ http://xahlee.org/

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


function local namespace question

2009-07-08 Thread Paul LaFollette
Kind people,

Using Python 3.1 under FreeBSD and WinXP.

I've been tearing my hair out trying to solve this myself, but I need
to ask for help.   I want (for obscure reasons) to be able to log
transactions in the namespace(s) of a script.  Specifically I would
like to log creation of identifiers, changes in the binding of
identifiers (assignment) and lookups.  This turns out to be pretty
easy in the global and local namespaces... I simply subclass dict,
override the appropriate operations to include the logging operations
I want, and then exec the code using my dictionaries as the global and
local namespaces.  All  of this  works just dandy until I try to
extend it to functions.

I cannot figure out any way to get a hook into the local namespace of
a user defined function.  I have tried making a wrapper class that
grabs the function call and then uses exec to invoke
myfunction.__code__ with my own dictionaries.  This runs the (no
argument) function properly (losing the return value, but I can deal
with that) but never accesses the local logging dictionary that I
specify in the exec() call. Perhaps the local namespace of a function
is not a dict at all?

Anyway, is there any way (however clumsy) to do what I want to do?
Thank you for your help.
Paul

---
Paul LaFollette
CIS Department
Temple University
paul.lafollette(at)temple.edu
www.cis.temple.edu/~lafollet
-- 
http://mail.python.org/mailman/listinfo/python-list


Emacs Python-mode. Newbie problem.

2009-07-08 Thread Lacrima
Hello!

I have just started using Emacs to write python scripts.
I installed python-mode.el

Then I just tried this code:

print 'hello world'

When I press C-c RET, new blank window is opened and emacs says:
(Shell command succeeded with no output)
So where is my 'hello world'?

When I do C-c C-c, it prints 'hello world' successfully.
Why in the first case I get no output?

Thanks in advance!

With regards, Max
(sorry if my English isn't very proper)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ... remove all 0 values

2009-07-08 Thread Simon Forman
On Jul 8, 10:44 am, Daniel Austria futureb...@gmx.at wrote:
 Hi python - hackers,

 just one question. How can i remove all 0 values in a list? Sure - i
 can loop over it, but that s not a neat style.  list.remove() will
 only remove the first occurence. Doing that while no exception is
 raised is also uncool, right?

 Some suggestions?

 Best,
 Dan

If you are doing something like this:

L = [0, 0, 0, 1, 1, 1, 0]
removeZeros(L)
number_of_ones = len(L)

you can just use sum() like so:

number_of_ones = sum(L)



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


Re: ISO library ref in printed form

2009-07-08 Thread kj
In m2r5wsb55n@cs.uu.nl Piet van Oostrum p...@cs.uu.nl writes:

 kj no.em...@please.post (kj) wrote:

kj Does anyone know where I can buy the Python library reference in
kj printed form?  (I'd rather not print the whole 1200+-page tome
kj myself.)  I'm interested in both/either 2.6 and 3.0.

Maybe you can have a copy printed at lulu.com.

Interesting idea...  Doesn't look like they offer such service.

It would even be nicer if
the PSF would offer them at lulu.

That would be great.

kj

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


Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Paul Rubin
Daniel Austria futureb...@gmx.at writes:
 just one question. How can i remove all 0 values in a list? 

I prefer:

   newlist = list(x for x in oldlist if x != 0)

to the square bracket list comprehension that a few people have
suggested.  This is because in python 2.x, the listcomp leaks its
index variable into the surrounding scope, but the generator
expression above doesn't.  Usually not a big deal, but an extra bit of
hygiene never(?) hurts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Bug By Any Other Name ...

2009-07-08 Thread Daniel Fetchinson
 But this academic discussion is honestly a little pointless. The OP
 was referring to a expectation, coming from C, that is not fulfilled
 in python. What's wrong with mentioning it somewhere for the sake of
 helping C programmers?

   And where does one stop? After all, my primary work language at the
 time I first encountered Python was FORTRAN77; and my home system at the
 time was an Amiga with ARexx... (granted, I did have a C compiler on it
 -- which I do not have on this WinXP machine)... And programming, even
 in C, on the Amiga still inflicted BCPL concepts upon one (AmigaDOS,
 the user view, was a port of Tripos user view on top of the Amiga
 executive libraries).

   Do we mention how Python differs from F77, F90, Ada, Rexx, LISP,
 RPG, APL, Pascal, BASIC, and COBOL (I've done all except RPG since
 graduating high school).

   In my mind... Anyone whose only experience with programming language
 concepts is C/C++ deserves the shock of finding that other languages ARE
 DIFFERENT! Even if they never use other languages they should at least
 have been exposed to language design options and rationales...

   Okay, I don't know what current curricula consist of, but in the
 late 70s, a CS degree at my college required two sessions of FORTRAN,
 two of COBOL, Assembly (numerically, it followed advanced FORTRAN),
 database (followed COBOL)... and then diverged into Business Programming
 vs Systems Programming (Business required lots of accounting/statistics
 courses [stat-II was SPSS], Systems was operating system and language
 design). Electives included BASIC, Pascal, APL (The professor for the
 data structures course made the mistake of once allowing an assignment
 -- hashed head multiple-linked list -- to be done in any language he
 could read G; I did it in a BASIC that only supported 4 open files at
 a time... I think someone did it in SNOBOL)

   C wasn't available on the XEROX Sigma-7; I did have a first edition
 KR. By graduation I'd also been exposed to the initial Ada
 reference/rational (a working compiler -- Ada/Ed -- didn't come out
 until after I'd graduated).


Okay, so where does one stop? I'd say C deserves special treatment as
opposed to all the other languages you mentioned because Guido himself
admits to influences from C (and ABC but I hope you won't assume that
ABC is a widely used language).

Maybe you didn't read these messages from me in this thread:

By the way, assignments in conditionals. Guido explicitly referred to
C when he forbade assignment in conditionals, citing common
typos/errors in C code such as if( x = 5 ){  } instead of if( x ==
5 ){ . }. So even he realized that warning people about different
usage in python and C is a good thing. Expectations from C work
sometimes, and sometimes they don't. In latter case a little warning
is useful.

And also,

Seriously, ask Guido about the influence of C vs. fortran (or cobol,
ada, pascal, etc). Somewhere you can find him quoted as saying that
python was originally intended to bridge the gap between the shell
and C. I've never heard him talk about fortran (or cobol, ada,
pascal, etc).

So don't get me wrong, I'm sufficiently impressed by your knowledge of
various computer languages, I admit to only knowing C and basic and
some fortran (and of course python :)), but if Guido himself thinks
the influence of C on python is more important than the others, then
let's not doubt him.

And yes, I shamelessly admit to arguing based on a higher authority
and not based on merit, but in this case it's appropriate, I think :)

Cheers,
Daniel


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


Re: ISO library ref in printed form

2009-07-08 Thread João Valverde

kj wrote:

Does anyone know where I can buy the Python library reference in
printed form?  (I'd rather not print the whole 1200+-page tome
myself.)  I'm interested in both/either 2.6 and 3.0.

TIA!

kj
  
Why not download the documentation, take it to a local copy shop and 
have it printed and bound there?


http://docs.python.org/download.html
http://docs.python.org/3.1/download.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: count

2009-07-08 Thread Aahz
In article 050094ea-faf4-4e03-875d-9c2c63090...@y17g2000yqn.googlegroups.com,
Bearophile  bearophileh...@lycos.com wrote:
Vilya Harvey:

 from itertools import groupby
 for x, g in groupby([fields[1] for fields in data]):
 =A0 =A0 print x, len(tuple(g))

Avoid that len(tuple(g)), use something like the following, it's lazy
and saves some memory.

The question is whether it saves time, have you tested it?
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Emacs Python-mode. Newbie problem.

2009-07-08 Thread Piet van Oostrum
 Lacrima lacrima.ma...@gmail.com (L) wrote:

L Hello!
L I have just started using Emacs to write python scripts.
L I installed python-mode.el

L Then I just tried this code:

L print 'hello world'

L When I press C-c RET, new blank window is opened and emacs says:
L (Shell command succeeded with no output)
L So where is my 'hello world'?

L When I do C-c C-c, it prints 'hello world' successfully.
L Why in the first case I get no output?

Can you check in the buffer where you have the python code what command
C-c RET is bound to?
With C-h k C-c RET

Shell command succeeded with no output suggests that is has a different
binding than the standard one in python-mode.

Did you happen to name your file 'test' or 'test.py?

C-c RET does an import and 'import test' imports a standard module test.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ISO library ref in printed form

2009-07-08 Thread Piet van Oostrum
 kj no.em...@please.post (k) wrote:

k In m2r5wsb55n@cs.uu.nl Piet van Oostrum p...@cs.uu.nl writes:
 kj no.em...@please.post (kj) wrote:

kj Does anyone know where I can buy the Python library reference in
kj printed form?  (I'd rather not print the whole 1200+-page tome
kj myself.)  I'm interested in both/either 2.6 and 3.0.

 Maybe you can have a copy printed at lulu.com.

k Interesting idea...  Doesn't look like they offer such service.

You can upload your own PDF file and have them print a single copy. You
would have to split the file yourself in manageble pieces ( 600
something pages)

 It would even be nicer if
 the PSF would offer them at lulu.

k That would be great.

k kj


-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: count

2009-07-08 Thread Paul Rubin
Bearophile bearophileh...@lycos.com writes:
      print x, len(tuple(g))
 
 Avoid that len(tuple(g)), use something like the following

print x, sum(1 for _ in g)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function local namespace question

2009-07-08 Thread Miles Kaufmann

On Jul 8, 2009, at 1:35 PM, Paul LaFollette wrote:


I cannot figure out any way to get a hook into the local namespace of
a user defined function.  I have tried making a wrapper class that
grabs the function call and then uses exec to invoke
myfunction.__code__ with my own dictionaries.  This runs the (no
argument) function properly (losing the return value, but I can deal
with that) but never accesses the local logging dictionary that I
specify in the exec() call. Perhaps the local namespace of a function
is not a dict at all?


Right.  Within functions, local variable name accesses and assignments  
are compiled into bytecode instructions (LOAD_FAST, STORE_FAST) that  
manipulate pointers to objects by indexing directly into a C array in  
the frame.  The locals dictionary of a frame is generated on-demand  
from that array when accessed.  There is no way that I'm aware of to  
directly hook into function namespace access and manipulation.


-Miles

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


Re: count

2009-07-08 Thread Paul Rubin
a...@pythoncraft.com (Aahz) writes:
 Avoid that len(tuple(g)), use something like the following, it's lazy
 and saves some memory.
 The question is whether it saves time, have you tested it?

len(tuple(xrange(1))) ... hmm.
-- 
http://mail.python.org/mailman/listinfo/python-list


regex help

2009-07-08 Thread David
Hi

I have a few regexs I need to do, but im struggling to come up with a
nice way of doing them, and more than anything am here to learn some
tricks and some neat code rather than getting an answer - although
thats obviously what i would like to get to.

Problem 1 -

span class=chg
id=ref_678774_cp(25.47%)/spanbr

I want to extract 25.47 from here - so far I've tried -

xPer = re.search('span class=chg id=ref_'+str(xID.group(1))+'_cp
\(.*?)%', content)

and

xPer = re.search('span class=\chg\ id=\ref_+str(xID.group(1))+_cp
\\((\d*)%\)/spanbr', content)

neither of these seem to do what I want - am I not doing this
correctly? (obviously!)

Problem 2 -

tdnbsp;/td

td width=1% class=keyOpen:
/td
td width=1% class=val5.50
/td
tdnbsp;/td
td width=1% class=keyMkt Cap:
/td
td width=1% class=val6.92M
/td
tdnbsp;/td
td width=1% class=keyP/E:
/td
td width=1% class=val21.99
/td


I want to extract the open, mkt cap and P/E values - but apart from
doing loads of indivdual REs which I think would look messy, I can't
think of a better and neater looking way. Any ideas?

Cheers

David

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


Re: count

2009-07-08 Thread Aahz
In article 7xbpnuzw4u@ruckus.brouhaha.com,
Paul Rubin  http://phr...@nospam.invalid wrote:
a...@pythoncraft.com (Aahz) writes:
Paul Rubin deleted an attribution:

Avoid that len(tuple(g)), use something like the following, it's lazy
and saves some memory.

 The question is whether it saves time, have you tested it?

len(tuple(xrange(1))) ... hmm.

When dealing with small N, O() can get easily swamped by the constant
factors.  How often do you deal with more than a hundred fields?
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clarity vs. code reuse/generality

2009-07-08 Thread Tim Rowe
2009/7/7 Steven D'Aprano st...@remove-this-cybersource.com.au:

 Maybe the reason for so much buggy software is that people
 inappropriately use assert, thus changing the behaviour of code depending
 on whether it is run with the -O flag or not.

I've done my share of code review and process audits, and assertions
seem *far* to rare for that distinction.

 I don't know what hostility you're seeing. The only hostility I'm
 seeing is from the OP, which is bizarre considering that he asked for
 advice and we gave it. What I see is a bunch of people concerned that the
 OP is teaching novices a bad habit, namely, using assert for error
 checking. He claims -- angrily and over and over again -- that in his
 code, the assertions should never fail. Great. Good for him for knowing
 when to use assert. But are the novices going to learn that lesson, or
 will they simply learn use assert for error checking?

They are rather more likely to learn if they are taught, aren't they?
Or do you think it's better to keep them in the dark? There are these
things called assertions -- work them out for yourselves.

I am convinced that the time to teach programmers to consider under
what circumstances a routine can be called and who is responsible for
ensuring that those conditions are met is as soon as they hit the
concept of calling routines. And assertions provide an excellent way
of doing that, fostering good habits for the rest of their careers.
Any hostility from the OP seems to be a response to the persistent
refusal to accept his assurances that he is not using the assertions
for run-time error checking, nor teaching the students to do that,
-- 
Tim Rowe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regex help

2009-07-08 Thread Chris Rebert
On Wed, Jul 8, 2009 at 3:06 PM, Daviddavid.bra...@googlemail.com wrote:
 Hi

 I have a few regexs I need to do, but im struggling to come up with a
 nice way of doing them, and more than anything am here to learn some
 tricks and some neat code rather than getting an answer - although
 thats obviously what i would like to get to.

 Problem 1 -

 span class=chg
                id=ref_678774_cp(25.47%)/spanbr

 I want to extract 25.47 from here - so far I've tried -

 xPer = re.search('span class=chg id=ref_'+str(xID.group(1))+'_cp
 \(.*?)%', content)

 and

 xPer = re.search('span class=\chg\ id=\ref_+str(xID.group(1))+_cp
 \\((\d*)%\)/spanbr', content)

 neither of these seem to do what I want - am I not doing this
 correctly? (obviously!)

 Problem 2 -

 tdnbsp;/td

 td width=1% class=keyOpen:
 /td
 td width=1% class=val5.50
 /td
 tdnbsp;/td
 td width=1% class=keyMkt Cap:
 /td
 td width=1% class=val6.92M
 /td
 tdnbsp;/td
 td width=1% class=keyP/E:
 /td
 td width=1% class=val21.99
 /td


 I want to extract the open, mkt cap and P/E values - but apart from
 doing loads of indivdual REs which I think would look messy, I can't
 think of a better and neater looking way. Any ideas?

Use an actual HTML parser? Like BeautifulSoup
(http://www.crummy.com/software/BeautifulSoup/), for instance.

I will never understand why so many people try to parse/scrape
HTML/XML with regexes...

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


Re: Cleaning up after failing to contructing objects

2009-07-08 Thread Mattias Brändström
On Jul 6, 11:15 pm, Scott David Daniels scott.dani...@acm.org wrote:
 brasse wrote:
  I have been thinking about how write exception safe constructors in
  Python. By exception safe I mean a constructor that does not leak
  resources when an exception is raised within it.

 ...
   As you can see this is less than straight forward. Is there some kind
   of best practice that I'm not aware of?

 Not so tough.  Something like this tweaked version of your example:

 class Foo(object):
      def __init__(self, name, fail=False):
          self.name = name
          if not fail:
              print '%s.__init__(%s)' % (type(self).__name__, name)
          else:
              print '%s.__init__(%s), FAIL' % (type(self).__name__, name)
              raise ValueError('Asked to fail: %r' % fail)

      def close(self):
          print '%s.close(%s)' % (type(self).__name__, self.name)

 class Bar(object):
      def __init__(self):
          unwind = []
          try:
              self.a = Foo('a')
              unwind.append(a)
              self.b = Foo('b', fail=True)
              unwind.append(b)
              ...
          except Exception, why:
              while unwind):
                  unwind.pop().close()
              raise

 bar = Bar()


OK. That's another way. I have been thinking about this some more and
right now I am experimenting with a decorator that could help me do
these kinds of things. This is what I have right now:

import functools

class Foo(object):
def __init__(self, name, fail=False):
self.name = name
self.closed = False
if not fail:
print '%s.__init__(%s)' % (self.__class__.__name__,
self.name)
else:
print '%s.__init__(%s), FAIL' % (self.__class__.__name__,
 self.name)
raise Exception()

def close(self):
print '%s.close(%s)' % (self.__class__.__name__, self.name)

def safe(f):
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
variables = []
def recorder(self, name, value):
if name != '__class__':
variables.append(name)
object.__setattr__(self, name, value)

class Customized(object): pass
setattr(Customized, '__setattr__', recorder)
old_class = self.__class__
self.__class__ = Customized

try:
f(self, *args, **kwargs)
self.__class__ = old_class
except:
# clean up objects created in __init__ (i.e. the call to f
())
for name in reversed(variables):
o = getattr(self, name)
if hasattr(o, 'close'):
o.close()
raise
return wrapper

class Bar(object):
@safe
def __init__(self):
self.a = Foo('a')
self.b = Foo('b')
self.c = Foo('c', fail=True)

bar = Bar()

The safe decorator will record all attributes created on self. If an
exception is raised during the execution of the decorated constructor
it will call close on all the recorded objects. I realize that this
decorator still needs a lot of work before it is usable, but I think
it illustrates the concept. It might even be possible for the
decorator to create a close/cleanup method dynamically.

To have a decorator like this that actually worked would be great
since it would remove the need to write error prone cleanup code. Any
thoughts?

:.:: mattias

 --Scott David Daniels
 scott.dani...@acm.org

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


Re: regex help

2009-07-08 Thread Tim Harig
On 2009-07-08, Chris Rebert c...@rebertia.com wrote:
 On Wed, Jul 8, 2009 at 3:06 PM, Daviddavid.bra...@googlemail.com wrote:
 I want to extract the open, mkt cap and P/E values - but apart from
 doing loads of indivdual REs which I think would look messy, I can't
 think of a better and neater looking way. Any ideas?

You are downloading market data?  Yahoo offers its stats in CSV format that
is easier to parse without a dedicated parser.

 Use an actual HTML parser? Like BeautifulSoup
 (http://www.crummy.com/software/BeautifulSoup/), for instance.

I agree with your sentiment exactly.  If the regex he is trying to get is
difficult enough that he has to ask; then, yes, he should be using a
parser.

 I will never understand why so many people try to parse/scrape
 HTML/XML with regexes...

Why?  Because some times it is good enough to get the job done easily.
-- 
http://mail.python.org/mailman/listinfo/python-list


Pydev 1.4.7 Released

2009-07-08 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.4.7 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* The interactive console can be used on the remote debugger
* Remote debugger properly redirects contents from the server on multiple runs.
* Providing context-independent completions when other completions are
not available (until now, it only gave those completions for method
parameters)
* The number of chars required to show the context-insensitive
completion can now be customized.
* Fixed problem with Eclipse 3.5: Invalid Thread Access when trying
to rename a class


Release Highlights in Pydev:
--

* Iron Python support
* Fixed issue when configuring interpreter on Eclipse 3.3 and 3.2 (was
using API only available in 3.4)
* Google App Engine
  o Popup menus for google app engine are now working with eclipse 3.2
  o Fixed issues when google app engine project has spaces in path
* Launching
  o Ctrl+F9 can be used to run as unit-test and select which tests
will be run
  o F9 will now run the current editor based on the project type
  o Changed run icons
  o Run configurations can be created for the project
  o Run as unit-test can have --filter and --tests as a parameter
set in the run configuration
* Shift left can now shift even when there are less chars than the
required indent string
* Top-level modules on .egg files are now properly recognized
* Auto-config fixed
* Fixed problem when .pydevproject was not a parseable xml file (the
pydev package explorer wouldn't work because of that)
* When a new interpreter is created, it's properly selected in the tree
* Code-completion better heuristic when analyzing function return
that's called on self.
* Code-completion in the interactive console now handles import
sections correctly
* Code formatter: Spaces after square and curly braces are no longer
changed when an unary operator is found afterwards
* Fixed problem when recognizing encodings (regexp was not correct)



What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python, Jython
and Iron Python development -- making Eclipse a first class Python IDE
-- It comes with many goodies such as code completion, syntax
highlighting, syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

Aptana
http://aptana.com/python

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Environment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt GUI

2009-07-08 Thread Helvin
On Jul 8, 9:23 pm, Phil Thompson p...@riverbankcomputing.com wrote:
 On Wed, 08 Jul 2009 11:11:51 +0200, Diez B. Roggisch
 de...@nospam.web.de
 wrote:





  Helvin wrote:

  Hi experts!

  I'm developing a GUI for a software using PyQT, and need 3D
  visualization. Should I use PyOpenGL or VTK?
  I understand that the PyQt package comes with a opengl module. What
  else would I need? I think I need to download opengl. but how? where?
  I have VTK and pyVTK installed, but I don't know how to use it in my
  code, as when I run it, an error says it can't find the vtk module.

  VTK won't mix with Qt. And I don't think you need to download opengl - it
  either comes with your system (or gfx-drivers), or not. I'm not sure if
 Qt
  actually wraps the OpenGL api itself, AFAIK it doesn't, so you need
  PyOpenGL I guess.

 VTK has explicit support for both Qt (ie. via C++) and PyQt.

 Phil

Thanks for the fast replies! I will look into how to use VTK now.
Where would I find VTK's explicit support for PyQt?

Because I have installed VTK (using its installer) and pyVTK (using
its setup.py file), but how do I actually use it in my code? According
to: 
http://www.nabble.com/embedded-VTK-window-in-PyQt-application-td23521455.html,
I have tried 'import vtk', but python can't find the vtk module.

Thanks a million!
Helvin
-- 
http://mail.python.org/mailman/listinfo/python-list


tkinter problem

2009-07-08 Thread Paul Simon
I have the tkinter problem and need some assistance to straighten it out.
From the web page http://wiki.python.org/moin/TkInter; I tested as in step
1 and cannot import _tkinter. I do not have that file on my computer, but
do have tkinter.py in /usr/local/lib/python2.6/lib-tk. as well as the
directories /usr/lib/tk8.5 and /usr/lib/tcl8.5.
This  python stuff is great, but the documentation frequently
feels like it is just a bit out of my grasp. I realize that all of this is
free but I understand the instructions on the web page to repair only to the
point of confusion. I'm not an expert. How do I modify my python
configuration? Is there a file that needs to be edited? Which setup.py file
do I use? Make? or python setup.py build and python setup.py install?
Thanks. I appreciate your help.
Paul Simon 


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


Re: regex help

2009-07-08 Thread Rhodri James
On Wed, 08 Jul 2009 23:06:22 +0100, David david.bra...@googlemail.com  
wrote:



Hi

I have a few regexs I need to do, but im struggling to come up with a
nice way of doing them, and more than anything am here to learn some
tricks and some neat code rather than getting an answer - although
thats obviously what i would like to get to.

Problem 1 -

span class=chg
id=ref_678774_cp(25.47%)/spanbr

I want to extract 25.47 from here - so far I've tried -

xPer = re.search('span class=chg id=ref_'+str(xID.group(1))+'_cp
\(.*?)%', content)


Supposing that str(xID.group(1)) == 678774, let's see how that string
concatenation turns out:

span class=chg id=ref_678774_cp(.*?)%

The obvious problems here are the spurious double quotes, the spurious
(but harmless) escaping of a double quote, and the lack of (escaped)
backslash and (escaped) open parenthesis.  The latter you can always
strip off later, but the first sink the match rather thoroughly.



and

xPer = re.search('span class=\chg\ id=\ref_+str(xID.group(1))+_cp
\\((\d*)%\)/spanbr', content)


With only two single quotes present, the biggest problem should be obvious.

Unfortunately if you just fix the obvious in either of the two regular
expressions, you're setting yourself up for a fall later on.  As The Fine
Manual says right at the top of the page on the re module
(http://docs.python.org/library/re.html), you want to be using raw string
literals when you're dealing with regular expressions, because you want
the backslashes getting through without being interpreted specially by
Python's own parser.  As it happens you get away with it in this case,
since neither '\d' nor '\(' have a special meaning to Python, so aren't
changed, and '\' is interpreted as '', which happens to be the right
thing anyway.



Problem 2 -

tdnbsp;/td

td width=1% class=keyOpen:
/td
td width=1% class=val5.50
/td
tdnbsp;/td
td width=1% class=keyMkt Cap:
/td
td width=1% class=val6.92M
/td
tdnbsp;/td
td width=1% class=keyP/E:
/td
td width=1% class=val21.99
/td


I want to extract the open, mkt cap and P/E values - but apart from
doing loads of indivdual REs which I think would look messy, I can't
think of a better and neater looking way. Any ideas?


What you're trying to do is inherently messy.  You might want to use
something like BeautifulSoup to hide the mess, but never having had
cause to use it myself I couldn't say for sure.

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


Re: tkinter problem

2009-07-08 Thread Chris Rebert
On Wed, Jul 8, 2009 at 4:18 PM, Paul Simonpsi...@sonic.net wrote:
 I have the tkinter problem and need some assistance to straighten it out.
 From the web page http://wiki.python.org/moin/TkInter; I tested as in step
 1 and cannot import _tkinter. I do not have that file on my computer, but
 do have tkinter.py in /usr/local/lib/python2.6/lib-tk. as well as the
 directories /usr/lib/tk8.5 and /usr/lib/tcl8.5.
 This  python stuff is great, but the documentation frequently
 feels like it is just a bit out of my grasp. I realize that all of this is
 free but I understand the instructions on the web page to repair only to the
 point of confusion. I'm not an expert. How do I modify my python
 configuration? Is there a file that needs to be edited? Which setup.py file
 do I use? Make? or python setup.py build and python setup.py install?
 Thanks. I appreciate your help.

- How did you install Python?
- What Linux distro are you using?

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


Re: PyQt GUI

2009-07-08 Thread Robert Kern

On 2009-07-08 18:10, Helvin wrote:


Thanks for the fast replies! I will look into how to use VTK now.
Where would I find VTK's explicit support for PyQt?


Wrapping/Python/vtk/qt4/ in the VTK sources.


Because I have installed VTK (using its installer) and pyVTK (using
its setup.py file), but how do I actually use it in my code? According
to: 
http://www.nabble.com/embedded-VTK-window-in-PyQt-application-td23521455.html,
I have tried 'import vtk', but python can't find the vtk module.


Then you have not installed VTK's Python bindings correctly. Note that pyVTK is 
just a library for manipulating VTK files. The VTK Python bindings are part of 
VTK's distribution itself. Exactly how did you install VTK? Did you compile it 
yourself?


--
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: walking a directory with very many files

2009-07-08 Thread Lawrence D'Oliveiro
In message kck0m.406$ze1@news-server.bigpond.net.au, Lie Ryan wrote:

 Lawrence D'Oliveiro wrote:

 ... certainly it is characteristic of GUIs to show you all 400,000 files
 in a directory, or at least try to do so, and either hang for half an
 hour or run out of memory and crash, rather than give you some
 intelligent way of prefiltering the file display up front.
 
 In many debugging cases, you don't even know what to filter ...

So pick a random sample to start with. Do you know of a GUI tool that can do 
that?

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


Re: ANN: GMPY 1.10 alpha with support for Python 3

2009-07-08 Thread Mensanator
On Jul 7, 12:47 am, Mensanator mensana...@aol.com wrote:
 On Jul 7, 12:16 am, casevh cas...@gmail.com wrote:

  I discovered a serious bug with comparisons and have posted alpha2
  which fixes that bug and adds Unicode support for Python 2.x

  casevh

 Damn! I was just congatulating myself for pulling off
 a hat trick (there had been no point in downloading
 3.x without gmpy so I have been putting it off):

 - installing Python 3.1
 - installing gmpy 1.10
 - converting my Collatz Function library to 3.1 syntax

 And it all worked smoothly, just had to add parentheses
 to my print statements, change xrange to range and all
 my / to // (the library is exclusively integer). I had
 gmpy running in my library on 3.1 in about 10 minutes.

 So I'll have to re-do the gmpy install. Shouldn't be
 any big deal.

 I started doing some real world tests. Generally, things
 look good (nothing crashes, timing looks not bad) but
 I'm getting some funny results on one of my tests, so
 I'll report back when I have more information.

As I said, I was getting funny results from one of my tests.

It seemed to work ok, but timing varied from 2 to 88 seconds,
which seemed odd. The other tests were generally consistent
for a given environment (cpu speed, OS, Python version, gmpy
version).

At some point I watched the memory usage profile from Windows.
On the same machine I have both Python 2.6 and 3.1 installed,
with the appropriate gmpy 1.10 version loaded for each.

In Python 2.6, it looks like this:

memory usage profile Python 2.6 gmpy 1.1 Vista

  /--\  /---\ .RESTART SHELL
 /   .\/ \
/.\
   . .
   . .
   start of RUN  start of RUN

The first start of RUN is the first time the test is run
(from IDLE). That change in usage represents about 700 MB
(I'm testing really BIG numbers, up to 500 million digits).

The memory remains allocated after the program terminates
(the flat plateau). When I run a second time, we see the
allocation dip, then climb back up to the plateau, so it
appears that the allocation never climbs above 1.1 GB.

Finally, doing a RESTART SHELL seems to completely free
the allocated memory. I assume this is normal behaviour.

With Python 3.1, it get this profile:

memory usage profile Python 3.1 gmpy 1.1 Vista

 /-
/ |
  //   \--\ .RESTART SHELL
 / .   \
/  .\___
   .   .
   .   .
   start of RUNstart of RUN

Here, at the start of the second RUN, it appears that new
memory is allocated BEFORE the previous is cleared. Is this
a quirk in the way 3.1 behaves? Here, the peak usage climbs
to 1.8 GB which I think causes VM thrashing accounting for
the increased execution times.

My guess is that gmpy is provoking, but not causing this
behaviour.

The actual test is:

t0 = time.time()
n=10
for k in range(1,n):
  for i in range(1,n-2):
print((str(cf.gmpy.numdigits(cf.Type12MH(k,i))).zfill(n)),end=' ')
  print()
print()
t1 = time.time()


The library function Type12MH is:

def Type12MH(k,i):
Find ith, kth Generation Type [1,2] Mersenne Hailstone using
the closed form equation

Type12MH(k,i)
k: generation
i: member of generation
returns Hailstone (a)

ONE = gmpy.mpz(1)
TWO = gmpy.mpz(2)
SIX = gmpy.mpz(6)
NIN = gmpy.mpz(9)

if (k1) or (i1): return 0

i = gmpy.mpz(i)
k = gmpy.mpz(k)

# a = (i-1)*9**(k-1) + (9**(k-1) - 1)//2 + 1
# return 2**(6*a - 1) - 1

a = (i-ONE)*NIN**(k-ONE) + (NIN**(k-ONE) - ONE)//TWO + ONE
return TWO**(SIX*a - ONE) - ONE

##  Sample runs
##
##  Test 1 - create numbers up to 500 million digits
##
##  02 04 06 07 09 11
13
##  09 25 42 58 74 91
000107
##  74 000221 000367 000513 000659 000806
000952
##  000659 001976 003293 004610 005926 007243
008560
##  005926 01 029627 041477 053328 065178
077028
##  053328 159981 266634 373287 479940 586593
693246
##  479940 0001439818 0002399696 0003359574 0004319453 0005279331
0006239209
##  0004319453 0012958355 0021597258 0030236161 0038875064 0047513967
0056152869
##  0038875064 0116625189 0194375315 0272125440 0349875565 0427625691
0505375816
##
##  15.546038
##    RESTART

##  
##  02 04 06 07 09 11
13
##  09 25 42 58 74 91
000107
##  74 000221 000367 000513 000659 000806
000952
##  000659 001976 003293 004610 005926 007243

Re: tkinter problem

2009-07-08 Thread Paul Simon

Chris Rebert c...@rebertia.com wrote in message 
news:mailman.2863.1247095339.8015.python-l...@python.org...
On Wed, Jul 8, 2009 at 4:18 PM, Paul Simonpsi...@sonic.net wrote:
 I have the tkinter problem and need some assistance to straighten it 
 out.
 From the web page http://wiki.python.org/moin/TkInter; I tested as in 
 step
 1 and cannot import _tkinter. I do not have that file on my computer, 
 but
 do have tkinter.py in /usr/local/lib/python2.6/lib-tk. as well as the
 directories /usr/lib/tk8.5 and /usr/lib/tcl8.5.
 This python stuff is great, but the documentation frequently
 feels like it is just a bit out of my grasp. I realize that all of this is
 free but I understand the instructions on the web page to repair only to 
 the
 point of confusion. I'm not an expert. How do I modify my python
 configuration? Is there a file that needs to be edited? Which setup.py 
 file
 do I use? Make? or python setup.py build and python setup.py install?
 Thanks. I appreciate your help.

- How did you install Python?
- What Linux distro are you using?

Cheers,
Chris
-- 
http://blog.rebertia.com
Im using Mandriva 2008.1.  I have to tell you honestly that I'm not sure
exactly how I installed Python.  Originally I had installed 2.5 from RPM but
2.6 was not available for my distro (2008.1) in RPM.  I downloaded something
from python.org and installed.  Not sure if it was tarball or zip file.

Paul


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


Re: ANN: GMPY 1.10 alpha with support for Python 3

2009-07-08 Thread casevh
On Jul 8, 5:03 pm, Mensanator mensana...@aol.com wrote:
 On Jul 7, 12:47 am, Mensanator mensana...@aol.com wrote:



  On Jul 7, 12:16 am, casevh cas...@gmail.com wrote:

   I discovered a serious bug with comparisons and have posted alpha2
   which fixes that bug and adds Unicode support for Python 2.x

   casevh

  Damn! I was just congatulating myself for pulling off
  a hat trick (there had been no point in downloading
  3.x without gmpy so I have been putting it off):

  - installing Python 3.1
  - installing gmpy 1.10
  - converting my Collatz Function library to 3.1 syntax

  And it all worked smoothly, just had to add parentheses
  to my print statements, change xrange to range and all
  my / to // (the library is exclusively integer). I had
  gmpy running in my library on 3.1 in about 10 minutes.

  So I'll have to re-do the gmpy install. Shouldn't be
  any big deal.

  I started doing some real world tests. Generally, things
  look good (nothing crashes, timing looks not bad) but
  I'm getting some funny results on one of my tests, so
  I'll report back when I have more information.

 As I said, I was getting funny results from one of my tests.

 It seemed to work ok, but timing varied from 2 to 88 seconds,
 which seemed odd. The other tests were generally consistent
 for a given environment (cpu speed, OS, Python version, gmpy
 version).

 At some point I watched the memory usage profile from Windows.
 On the same machine I have both Python 2.6 and 3.1 installed,
 with the appropriate gmpy 1.10 version loaded for each.

 In Python 2.6, it looks like this:

 memory usage profile Python 2.6 gmpy 1.1 Vista

       /--\  /---\ .RESTART SHELL
      /               .\/         \
 /                .            \
    .                 .
    .                 .
    start of RUN      start of RUN

 The first start of RUN is the first time the test is run
 (from IDLE). That change in usage represents about 700 MB
 (I'm testing really BIG numbers, up to 500 million digits).

 The memory remains allocated after the program terminates
 (the flat plateau). When I run a second time, we see the
 allocation dip, then climb back up to the plateau, so it
 appears that the allocation never climbs above 1.1 GB.

 Finally, doing a RESTART SHELL seems to completely free
 the allocated memory. I assume this is normal behaviour.

 With Python 3.1, it get this profile:

 memory usage profile Python 3.1 gmpy 1.1 Vista

                          /-
                         / |
       //   \--\ .RESTART SHELL
      /                 .           \
 /                  .            \___
    .                   .
    .                   .
    start of RUN        start of RUN

 Here, at the start of the second RUN, it appears that new
 memory is allocated BEFORE the previous is cleared. Is this
 a quirk in the way 3.1 behaves? Here, the peak usage climbs
 to 1.8 GB which I think causes VM thrashing accounting for
 the increased execution times.


Hmmm. It looks like memory is not being release properly. I don't see
that behavior under Linux. The running time is a very consistent 1.35
seconds. I'm traveling at the moment so it will be at least a week
before I can test under Windows.

Thanks for the report. I'll try to see if I can figure out what is
going on.

casevh
 My guess is that gmpy is provoking, but not causing this
 behaviour.

 The actual test is:

 t0 = time.time()
 n=10
 for k in range(1,n):
   for i in range(1,n-2):
     print((str(cf.gmpy.numdigits(cf.Type12MH(k,i))).zfill(n)),end=' ')
   print()
 print()
 t1 = time.time()

 The library function Type12MH is:

 def Type12MH(k,i):
     Find ith, kth Generation Type [1,2] Mersenne Hailstone using
 the closed form equation

     Type12MH(k,i)
     k: generation
     i: member of generation
     returns Hailstone (a)
     
     ONE = gmpy.mpz(1)
     TWO = gmpy.mpz(2)
     SIX = gmpy.mpz(6)
     NIN = gmpy.mpz(9)

     if (k1) or (i1): return 0

     i = gmpy.mpz(i)
     k = gmpy.mpz(k)

     # a = (i-1)*9**(k-1) + (9**(k-1) - 1)//2 + 1
     # return 2**(6*a - 1) - 1

     a = (i-ONE)*NIN**(k-ONE) + (NIN**(k-ONE) - ONE)//TWO + ONE
     return TWO**(SIX*a - ONE) - ONE

 ##  Sample runs
 ##
 ##  Test 1 - create numbers up to 500 million digits
 ##
 ##  02 04 06 07 09 11
 13
 ##  09 25 42 58 74 91
 000107
 ##  74 000221 000367 000513 000659 000806
 000952
 ##  000659 001976 003293 004610 005926 007243
 008560
 ##  005926 01 029627 041477 053328 065178
 077028
 ##  053328 159981 266634 373287 479940 586593
 693246
 ##  479940 0001439818 0002399696 0003359574 0004319453 0005279331
 0006239209
 ##  0004319453 0012958355 0021597258 0030236161 0038875064 0047513967
 0056152869
 ##  

  1   2   >