Re: Annoying octal notation

2009-08-25 Thread Mensanator
On Aug 24, 10:20�pm, Erik Max Francis m...@alcyone.com wrote:
 Steven D'Aprano wrote:
  On Mon, 24 Aug 2009 09:14:25 -0500, Derek Martin wrote:

  Assuming I'm right about that, then the use of a leading 0 to represent
  octal actually predates the prevalence of using 0 in dates by almost two
  decades. �And while using leading zeros in other contexts is familiar
  to me, I would certainly not consider it common by any means. �Thus I
  think it's fair to say that when this syntax was selected, it was a
  rather good choice.

  Except of course to anyone familiar with mathematics in the last, oh,
  five hundred years or so. Mathematics has used a positional system for
  numbers for centuries now: leading zeroes have been insignificant, just
  like trailing zeroes after the decimal point:

  9 = 09 = 009 = 9.0 = 9.00 = 0009.000 etc.

 Trailing zeroes are quite important when you're indicating the
 significance of a figure. �9 is not the same as 9.0 or 9.000.

Tell me about it. Unfortunnately, Microsoft doesn't understand
the difference between precision and significance. Makes my
job a nightmare when I have to convert ug/kg to mg/kg.


 --
 Erik Max Francis  m...@alcyone.com http://www.alcyone.com/max/
 � San Jose, CA, USA  37 18 N 121 57 W  AIM/Y!M/Skype erikmaxfrancis
 � �If the sky should fall, hold up your hands.
 � � -- (a Spanish proverb)- Hide quoted text -

 - Show quoted text -

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


Re: your favorite debugging tool?

2009-08-25 Thread Robert Marshall
On 24 Aug 2009, Paul Rubin wrote:

 Esmail ebo...@hotmail.com writes:
 What is your favorite tool to help you debug your
 code? I've been getting along with 'print' statements
 but that is getting old and somewhat cumbersome.
 
 Beyond print statements, I use pdb a lot.  Winpdb (www.winpdb.org) is
 even better, but is kind of cumbersome to get working.

And you can run it (pdb) within emacs - though I find a little roughness
in working out the exact interactions keeps ending up (ie the source
buffer displayed) in the wrong stack frame - afaict

Robert
-- 
La grenouille songe..dans son château d'eau
Links and things http://rmstar.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 still not giving memory back to the OS...

2009-08-25 Thread John Machin
On Aug 25, 2:08 am, Chris Withers ch...@simplistix.co.uk wrote:
 Martin v. Löwis wrote:
  Today, there are two cases when malloc returns memory on a typical
  Unix system (in particular, in Linux malloc):
  a) if the malloc block block is small (below page size), it is allocated
     from the brk heap, where it can only be returned if the last page of
     that heap is completely free, and
  b) if the block is large (multiple pages), it gets returned to the
     system right away.

  Case b) can only happen if the C malloc uses mmap to allocate large
  blocks.

 I believe (and John will correct me if I'm wrong) that xlrd uses mmap,
 so why am I not seeing the memory being returned?

xlrd uses mmap to access the input file; this seems to have zero
correlation with the C malloc uses mmap to allocate large blocks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to display photos

2009-08-25 Thread Thomas Guettler
Some years ago I had the same problem.

I wrote a simple app with pygtk. You get get it from here:
   http://guettli.sourceforge.net/gthumpy/src/README.html
The next pictures get loaded in background. Switching from
one image to the next is faster then in some other apps. But
somehow it is not ready for the public. I guess I am the only
one who uses it.

Flags are symlinks in the home directory .local/share/app/gthumpy. This
means you should not move your images, otherwise the flags get lost.

I don't think it will work on ms-windows, but it could be ported.

Or you use mirage:
http://mirageiv.berlios.de/index.html

It is a pygtk image viewer. You can define shortcuts that execute user defined
commands.

  Thomas

samwyse schrieb:
 I have several thousand photographs that I need to quickly classify,
 all by myself.  After extensive searches, I have been unable to find
 anything to my liking, so desire to write something myself.  I'm
 thinking about displaying a photo and waiting for keystrokes to tag
 it; 'i' for interior, 'e' for exterior, etc., while hitting space or
 enter will advance to the next photo.  My big question is, what's the
 best way to display the photos.  I've used PIL in the past, but IIRC
 it uses an external program.  Pygame is the next obvious choice, but
 like PIL it requires an add-in.  That leaves Tkinter.  Has anyone used
 it to display .JPG files, perhaps with rescaling to fit my screen?
 How is its performance?  Is there any other possibilities that I've
 missed?  Thanks.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: elementtree

2009-08-25 Thread Nadia Johnson
On Aug 24, 7:29 pm, Dave Angel da...@ieee.org wrote:
 Stefan Behnel wrote:
  Hi,

  elsa wrote:

  I know how to turn HTML into an ElementTree object

  I don't. ;)

  ElementTree doesn't have an HTML parser, so what do you use for parsing?

  but I don't know
  how to then view the structure of this object. Is there a method or
  module that you can give an ElementTree object to, and it returns some
  kind of graphical or printed representation of the tree? Otherwise, if
  you can't see you're tree's structure, how do you know what is a
  sensible way of iterating over the tree to access the info you need?

  ElementTree has a tostring() method that returns a string. To get a pretty
  printed representation, you can use the indent() function from this recipe:

 http://effbot.org/zone/element-lib.htm#prettyprint

  Stefan

 Perhaps the OP was referring to XHTML, which should be eligible for
 ElementTree.  But could you tell me whether ElementTree is at all
 tolerant of malformed XML?   Most HTML and XHTML I encounter in the wild
 is so  buggy it's amazing it all works at all.

 DaveA

I used elementtidy, also available from effbot
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python memory management - virtualized server environments

2009-08-25 Thread gravityzoo-dmo
On 24 aug, 20:35, Martin P. Hellwig martin.hell...@dcuktec.org
wrote:
 gravityzoo-dmo wrote:
  Hello everyone,

  I was wondering if anyone here has had any experience in running
  Python in a virtualized server environment?
  The reason I'm asking is the recent thing I noticed when running my
  server application (written in Python + Twisted);
  The memory of the server application seems to only grow, and not give
  back memory space to the OS. I realize that this won't be a problem on
  a single physical server, but I'm curious of the effect this behaviour
  has on a virtualized environment.
  Could anyone provide me with a little more insight please?
  Thanks in advance!

  Dirk

 Might help if you say which version of Python you are running, although
 I'm not a memory expert I do know there have been some changes between
 the versions.

 --
 MPHhttp://blog.dcuktec.com
 'If consumed, best digested with added seasoning to own preference.'

Hi, I'm sorry, I forgot to post the version indeed.

The Python version I'm running is 2.5.2 (r252:60911, January 4 2009)
The Twisted version I'm running is 8.2.0, and I'm using the EPOLL-
Reactor (don't know if that matters)
The OS I'm running on is Debian version 2.6.26-2-686 (i686 GNU/Linux)

Is that enough info?

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


Re: Putting together a larger matrix from smaller matrices

2009-08-25 Thread Peter Otten
Matjaz Bezovnik wrote:

 This is something which is done often in FEM methods, and the alike.
 
 I have matrix A of 3x3 elements, and B, of the same number of
 elements, 3x3.
 
 What would be the most obvious way to assemble a matrix which:
 a11 a12 a13
 a21 a22 a23
 a31 a32 a33+b11 b12 b13
   b21 b22 b23
   b31 b32 b33
 
 (the missing elements = zero)
 
 (you see the pattern - if there was a third matrix C, it would
 connect to b33 on the main diagonal)

Unless there is a dedicated function:

partial = [...] # list of matrices of shape NxN

N = partial[0].shape[0]
width = N*len(partial)
b = numpy.zeros((width, width))

off = 0
for m in partial:
b[off:off+N, off:off+N] = m
off += N
print b

Peter


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


Re: Python memory management - virtualized server environments

2009-08-25 Thread Martin P. Hellwig

gravityzoo-dmo wrote:

On 24 aug, 20:35, Martin P. Hellwig martin.hell...@dcuktec.org
wrote:

gravityzoo-dmo wrote:

Hello everyone,
I was wondering if anyone here has had any experience in running
Python in a virtualized server environment?
The reason I'm asking is the recent thing I noticed when running my
server application (written in Python + Twisted);
The memory of the server application seems to only grow, and not give
back memory space to the OS. I realize that this won't be a problem on
a single physical server, but I'm curious of the effect this behaviour
has on a virtualized environment.
Could anyone provide me with a little more insight please?
Thanks in advance!
Dirk

Might help if you say which version of Python you are running, although
I'm not a memory expert I do know there have been some changes between
the versions.

--
MPHhttp://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'


Hi, I'm sorry, I forgot to post the version indeed.

The Python version I'm running is 2.5.2 (r252:60911, January 4 2009)
The Twisted version I'm running is 8.2.0, and I'm using the EPOLL-
Reactor (don't know if that matters)
The OS I'm running on is Debian version 2.6.26-2-686 (i686 GNU/Linux)

Is that enough info?

Best regards,
Dirk



According to Python 2.6 release document:
To reduce memory usage, the garbage collector will now clear internal 
free lists when garbage-collecting the highest generation of objects. 
This may return memory to the operating system sooner.


Which might apply to your situation, but to be really sure you can only 
try it out :-)


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


matplotlib / backend

2009-08-25 Thread Pierre
Hello,

I'm to plot some results but it doesn't work.
I got this error :

/usr/local/libre_rep/python-2.6.1/RHEL_5__x86_64/lib/python2.6/site-
packages/matplotlib/backends/__init__.py:41: UserWarning:
Your currently selected backend, 'agg' does not support show().
Please select a GUI backend in your matplotlibrc file ('/usr/local/
libre_rep/python-2.6.1/RHEL_5__x86_64/lib/python2.6/site-packages/
matplotlib/mpldata/matplotlibrc')
or with matplotlib.use()

Any idea to fix it ?

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


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-25 Thread James Harris
On 25 Aug, 01:25, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:

 On Mon, 24 Aug 2009 16:23:06 -0700, James Harris wrote:

  Sure but while I wouldn't normally want to type something as obscure as
  32rst into a file of data I might want to type 0xff00 or similar. That
  is far clearer than 65280 in some cases.

  My point was that int('ff00', 16) is OK for the programmer but cannot be
  used generally as it includes a function call.

 No, it's the other way around. If you have *data*, whether entered at run
 time by the user or read from a file, you can easily pass it to a
 function to convert to an int. (In fact you have to do this anyway,
 because the data will be a string and you need an int.)

 If you want your data file to have values entered in hex, or oct, or even

You are looking at this the other way round from me and I'll explain
why I think this is important. I'm not talking about the *programmer*
prescribing how the user should enter the data but the *user* being
able to choose to prepare the data in a certain format - the format
which makes sense for the data being entered. Your way only works if
those fields in every row have the same format. That may be the case
sometimes but is not general.


 unary (1=one, 11=two, 111=three, =four...) you can. There's no need
 to have the user enter int('ff00', 16) to get hex, just have them enter
 ff00.

 But when writing *code*, you want syntax which will accept integers in
 the most common bases (decimal, a distant second hex, an even more
 distant third octal, and way out on the horizon binary) without the
 runtime cost of a function call.

Be careful! When designing a language feature don't be too ready to
*tell* the users of that language what restrictions they want. Just
because the designer wants features with a certain frequency does not
mean that all users will have the same priorities. (If it is
impossible or unreasonable to support a feature then by all means
don't support it. But don't decide up-front before examining the
options that something in not personally appealing.)

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


Re: Protecting against callbacks queuing up?

2009-08-25 Thread Hendrik van Rooyen
On Monday 24 August 2009 17:32:23 Esben von Buchwald wrote:
 Hendrik van Rooyen wrote:

8 -- some stuff about an after call --

 I'm new to python, what is an after function and an after call? Couldn't
 find excact answer on google...? Do you have a link to some docs?

The after call is common in GUI stuff.

Here is a link to nice Tkinter manual - it is the first link if you google 
for:   tkinter new mexico tech shipman

www.nmt.edu/tcc/help/pubs/tkinter/

What after does is that it is like a normal call, except that it is not done 
immediately, but after some settable time, hence the after.

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


os.popen output different from native shell output

2009-08-25 Thread nickname
Hi all,
   I am a relative newbie to python, I am using os.popen to run an
ls command. The output that I get using the read() function is
different in look and feel from when I run the ls command natively
from the shell (not via python). I display the ouput via python by
using the print function on the variable that accepts the os.popen
().read() function.

For example:

output from native shell (as seen on the bash shell)

file1 file2 dir1(highlighted in blue color)
file3longnamewhichwillcausenextfiletoappearonnextline

file 4

output from python (as seen on the bash shell)

file1
file2
dir1 (no blue color)
file3longnamewhichwillcausenextfiletoappearonnextline
file4

Is there an easy way to mirror the output. When python displays the
output, how can it tell the bash shell that some of the entries are
directories and they should appear blue on the bash shell, and that
everything should not be appearing on 1 column only.

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


Re: os.popen output different from native shell output

2009-08-25 Thread Chris Rebert
On Tue, Aug 25, 2009 at 1:36 AM, nicknamethebiggestbangthe...@gmail.com wrote:
 Hi all,
       I am a relative newbie to python, I am using os.popen to run an
 ls command. The output that I get using the read() function is
 different in look and feel from when I run the ls command natively
 from the shell (not via python). I display the ouput via python by
 using the print function on the variable that accepts the os.popen
 ().read() function.

 For example:

 output from native shell (as seen on the bash shell)

 file1 file2 dir1(highlighted in blue color)
 file3longnamewhichwillcausenextfiletoappearonnextline

 file 4

 output from python (as seen on the bash shell)

 file1
 file2
 dir1 (no blue color)
 file3longnamewhichwillcausenextfiletoappearonnextline
 file4

 Is there an easy way to mirror the output. When python displays the
 output, how can it tell the bash shell that some of the entries are
 directories and they should appear blue on the bash shell, and that
 everything should not be appearing on 1 column only.

I would assume the difference is caused by `ls` changing behavior (for
example, enabling/disabling colorization) based on whether its output
is going to a terminal or a pipe.

Is there a reason you can't use os.listdir() instead of running ls?:
http://docs.python.org/library/os.html#os.listdir

For the colorization, google for ANSI color escape sequences

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


Re: Questions on XML

2009-08-25 Thread SUBHABRATA BANERJEE
I was trying this. Looks perfectly fine. There must be something really
wrong. If you can reinstall Python 2.5.
 a1=raw_input(String)
Stringআম

On Mon, Aug 24, 2009 at 12:18 AM, Rami Chowdhury
rami.chowdh...@gmail.comwrote:

 My problem is with IDLE on Windows. When I try to type Bangla directly into
 the IDLE window I only get '?' characters, and repr() fails with a
 UnicodeDecodeError. I expect, though, that that's because of my specific
 installation / Windows issues, as it works fine on Fedora 10...

  I do not get any problem in processing Hindi or Bangla or any Indian
  language in Python it is perfectly fine.
 I have no problems either -- my issues are with IDLE, and only on Windows.

 
 Rami Chowdhury
 Strangers are just friends who haven't had enough gin. -- Howdle's Saying
 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

  On Saturday 22 August 2009 13:27:02 SUBHABRATA BANERJEE wrote:
  Should I help you? If you answered my questions I am differing from your
  view I do not get any problem in processing Hindi or Bangla or any Indian
  language in Python it is perfectly fine.
  Best Regards,
  Subhabrata.
 
  On Sat, Aug 22, 2009 at 9:48 AM, Rami Chowdhury
 rami.chowdh...@gmail.comwrote:
   I am using primarily UTF-8 based strings, like Hindi or Bengali. Can I
  
   use Python to help me in this regard?
  
   I can say from experience that Python on Windows (at least, Python 2.5
 on
   32-bit Vista) works perfectly well with UTF-8 files containing Bangla.
 I
   have had trouble with working with the data in IDLE, however, which
 seems
   to prefer ASCII by default.
  
   -
   Rami Chowdhury
   Never assume malice when stupidity will suffice. -- Hanlon's Razor
   408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
  
  
  
  
  
   On Aug 21, 2009, at 19:15 , joy99 wrote:
  
 Dear Group,
  
   I like to convert some simple strings of natural language to XML. May
   I use Python to do this? If any one can help me, on this.
  
   I am using primarily UTF-8 based strings, like Hindi or Bengali. Can I
   use Python to help me in this regard?
  
   How can I learn good XML aspects of Python. If any one can kindly name
   me a book or URL.
  
   I am using Python2.6 on Windows XP with IDLE as GUI.
  
   Best Regards,
   Subhabrata.
   --
   http://mail.python.org/mailman/listinfo/python-list


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


Re: matplotlib / backend

2009-08-25 Thread baloan
On Aug 25, 10:12 am, Pierre pierre.gaill...@gmail.com wrote:
 Hello,

 I'm to plot some results but it doesn't work.
 I got this error :

 /usr/local/libre_rep/python-2.6.1/RHEL_5__x86_64/lib/python2.6/site-
 packages/matplotlib/backends/__init__.py:41: UserWarning:
 Your currently selected backend, 'agg' does not support show().
 Please select a GUI backend in your matplotlibrc file ('/usr/local/
 libre_rep/python-2.6.1/RHEL_5__x86_64/lib/python2.6/site-packages/
 matplotlib/mpldata/matplotlibrc')
 or with matplotlib.use()

 Any idea to fix it ?

 Thanks

Try:

import matplotlib
matplotlib.use('TkAgg')

before coding anything else

from the examples section of the matplotlib documentation
http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen output different from native shell output

2009-08-25 Thread Thomas Guettler
hi,

you get the popen output like this:

u...@unixhost ls | cat


nickname schrieb:
 Hi all,
I am a relative newbie to python, I am using os.popen to run an
 ls command. The output that I get using the read() function is
 different in look and feel from when I run the ls command natively
 from the shell (not via python). I display the ouput via python by
 using the print function on the variable that accepts the os.popen
 ().read() function.
...

 Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: your favorite debugging tool?

2009-08-25 Thread Michele Simionato
On Aug 22, 4:25 pm, Esmail ebo...@hotmail.com wrote:
 Hi all,

 What is your favorite tool to help you debug your
 code?

The times when I would just use 'print' are long past. Nowadays I
spend lots of my time
with code written by others than myself. I use pdb all the time, and
now also ipdb
(ipdb is very cool if you are used to ipython).

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


Re: print() and unicode strings (python 3.1)

2009-08-25 Thread 7stud
On Aug 24, 10:09 pm, Ned Deily n...@acm.org wrote:
 In article
 e5e2ec2e-2b4a-4ca8-8c0f-109e5f4eb...@v23g2000pro.googlegroups.com,



  7stud bbxx789_0...@yahoo.com wrote:
  On Aug 24, 2:41 pm, Martin v. Löwis mar...@v.loewis.de wrote:
I can't figure out a way to programatically set the encoding for
sys.stdout.  So where does that leave me?

   You should be setting the terminal encoding administratively, not
   programmatically.

  The terminal encoding has always been utf-8.  It was not set
  programmatically.

  It seems to me that python 3.1's string handling is broken.
  Apparently, in python 3.1 I am unable to explicitly set the encoding
  of a string and print() it out with the result being human readable
  text.  On the other hand, if I let python do the encoding implicitly,
  python uses a codec I don't want it to.

 If you are running on a Unix-y system, check your locale settings (LANG,
 LC.*, et al).  I think you'll likely find that your locale is really not
 UTF-8.   The following was on Python 3.1 on OS X 10.5, similar results
 on Debian Linux:

 $ cat t3.py
 import sys
 print(sys.stdout.encoding)
 s = ¤
 print(s.encode(utf-8))
 print(s)

 $ export LANG=en_US.UTF-8
 $ python3.1 t3.py
 UTF-8
 b'\xe2\x82\xac'
 ¤

 $ export LANG=C
 $ python3.1 t3.py
 US-ASCII
 b'\xe2\x82\xac'
 Traceback (most recent call last):
   File t3.py, line 7, in module
 print(s)
 UnicodeEncodeError: 'ascii' codec can't encode character '\u20ac' in
 position 0: ordinal not in range(128)

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

Hi,

Thanks for the response.  My OS is mac osx 10.4.11.  I'm not really
sure how to check my locale settings.  Here is some stuff I tried:

$ echo $LANG

$ echo $LC_ALL

$ echo $LC_CTYPE

$ locale
LANG=
LC_COLLATE=C
LC_CTYPE=C
LC_MESSAGES=C
LC_MONETARY=C
LC_NUMERIC=C
LC_TIME=C
LC_ALL=C

$man locale
...
...
...

ENVIRONMENT:
LANG
Used as a substitute for any unset LC_* variable.  If LANG is unset it
will act as if set to C.  If any of LANG or LC_* are set to invalide
values locale acts as if they are all unset.

===

As in your last example, my 'C' settings mean that an ascii codec is
used somewhere to encode() the unicode string.

--
The locale C or POSIX is a portable locale; its LC_CTYPE part
corresponds to the 7-bit ASCII character set.

http://linux.about.com/library/cmd/blcmdl3_setlocale.htm
--


Is this the way it works:


1) python sets the codec for sys.stdout to the LANG environment
variable.
2) It doesn't matter that my terminal's encoding is set to utf-8
because output has to pass through sys.stdout first.

So:

a) My terminal's environment is telling python(and all other programs
running in the terminal) that output sent to sys.stdout must be
encoded in ascii.
b) The solution is to set a LANG environment variable.


Why does echoing $LC_ALL or $LC_CTYPE just give me a blank string?


Previously, I've set environment variables that I want to be
permanent, e.g PATH, in ~/.bash_profile, so I did this:

~/.bash_profile:
--
...
...
LANG=en_US.UTF-8
export LANG

and now python 3.1 acts like I expect it to:

---
import locale
import sys

print(locale.getlocale(locale.LC_CTYPE))
print(sys.stdout.encoding)


s = €
print(s)

print(s.encode(utf-8))

--output:--
('en_US', 'UTF8')
UTF-8
€
b'\xe2\x82\xac'
--

In conclusion, as far as I can tell, if your python 3.1 program tries
to output a unicode string, and the unicode string cannot be encoded
by the codec specified in the user's LANG environment variable**, then
the user will get an encode error. Just because the programmer's
system can handle the output doesn't mean that another user's system
can.  I guess that's the way it goes: if a user's environment is
telling all programs that it only wants ascii output to go to the
screen(sys.stdout), you can't(or shouldn't) do anything about it.

**Or if the LANG environment variable is not present, then the codec
corresponding to the locale settings(C' corresponds to ascii).

some good locale info:
http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_19.html
-- 
http://mail.python.org/mailman/listinfo/python-list


unexpected token `;'

2009-08-25 Thread bbarbero

Hello to all!

I am struggling with a script in python for a while now, and decided  
to look for some help. I am running a code that takes commands from  
Marsyas(open source for Music analysis).


#!/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
#!/bin/bashimport math
import re
import numpy
import string
import os.path
import sys
import commands



l =  
/Users/bmorab/Audio_Projecto/Data/Palco/PP3_44_distance_matrix/PP3_44_5.mf


Col = open(l, 'r')
colist= []
songlist = []
for line in Col:
#print line
song = os.path.split(line)[1]
#print song
songlist.append(song)
colist.append(line)



cmd = sfplay  + colist[2]
print cmd
fileout = commands.getoutput(cmd)
print fileout



It basically reads song files from the .mf file, stores them in a list  
and play  one of the songs from the list. It does work with some music  
but mostly it gives an error like this:


sfplay  
/Volumes/HAL/Datasets/Audio/PalcoPrincipal/mp3_resampled_44100/10005.mp3


sh: -c: line 1: syntax error near unexpected token `;'
sh: -c: line 1: `; } 21'


Ive been searching for the meaning of the error, and It really depends  
on the script, but I would conclude that I am missing a punctuation  
mark??


Thank you very much for taking your time reading my request.

Looking forward to hearing from you.

Regards,
Bea



This message was sent using IMP, the Internet Messaging Program.
--
http://mail.python.org/mailman/listinfo/python-list


Re: unexpected token `;'

2009-08-25 Thread mmelchert
bbarb...@inescporto.pt wrote:

 Hello to all!
 
 I am struggling with a script in python for a while now, and decided
 to look for some help. I am running a code that takes commands from
 Marsyas(open source for Music analysis).
 
 #!/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
 #!/bin/bashimport math  ==
 import re
 import numpy

have a close look at the == line: I think you wanted it to read
import math rather than #!/bin/bashimport math?

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


PyCon 2010 - Call for Tutorials

2009-08-25 Thread Greg Lindstrom
The period to submit proposals for PyCon 2010 in Atlanta, Georgia (USA) is
now open and will close on October 18.  Tutorials are 3-hour long classes on
a specific Python technique, package or technology and are taught by members
of the Python community.  If you have knowledge in a particular topic and
would like to be considered to teach a class we invite you to submit a
proposal outlining the material you would like to cover.  Once we receive
your proposal, we will score it based on content and then select 24
classes (subject to change) for presentation.

Class instructors will be paid $1000.00 per class.  If a class has more than
one teacher, the fee will be split between them.

Interested?  Click on over to the Tutorial Proposal
Pagehttp://us.pycon.org/2010/tutorials/proposals/to see more
details, examples of classes that have been requested in the
past (though you are free to submit a proposal on anything Python), an
example proposal and an empty template to help you prepare your own
proposal.  Once complete, email your proposal to
pycon-tutori...@python.orgso we can get it out to the evaluation
committee and get you on your way to
being a PyCon

Questions?  You can contact us at the PyCon Email
Listpycon-tutori...@python.organd we will get back with you.

We look forward to hearing from you!

Greg Lindstrom
Tutorial Coordinator
PyCon 2010 (Atlanta)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unexpected token `;'

2009-08-25 Thread Diez B. Roggisch
bbarb...@inescporto.pt wrote:

 Hello to all!
 
 I am struggling with a script in python for a while now, and decided
 to look for some help. I am running a code that takes commands from
 Marsyas(open source for Music analysis).
 
 #!/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
 #!/bin/bashimport math

This is bogus. Replace it with

  #!/usr/bin/python

and put the import math on the next line.

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


Re: Python for professsional Windows GUI apps?

2009-08-25 Thread Wolfgang Keller
 I need controls for business apps like access to databases, good data
 grid, printing reports (with or without barcodes), etc.

The area of _desktop_ database application development indeed looks like a vast 
and very hostile desert in the Python landscape.

The only framework that seems to be worth trying is Dabo. Unfortunately there's 
little documentation, and that's mostly outdated.

There's also Kiwi, but that's even less well documented.

And GNU Enterprise essentially seems to be dead.

Sincerely,

Wolfgang

-- 
NO Courtesy Copies PLEASE!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can python make web applications?

2009-08-25 Thread Mark
On Sun, 23 Aug 2009 21:45:17 +0100, Goke Aruna wrote:

 A lot check this fantastic open source application,
 http://www.openerp.com, all done is python.

That does look impressive. Is that Django or Turbogears?


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


Re: problem to write a THREAD enabled python extension

2009-08-25 Thread Andreas Otto
Stefan Behnel wrote:

 
 You forgot to create a thread state for the new thread. See the
 PyThreadState_New() function.
 

this does not really solve the problem even if the original error does no 
happen anymore ...

but a bucket of other error happen  sometimes  and this mean
that time and (I call it so) internal state stuff has influence on the 
problem and create errors like:

 1. http://mail.python.org/pipermail/python-list/2004-January/242740.html
 2. various PyThreadState_Get - PyThreadState_Get: no current thread
 3. sometimes ThreadState has NULL sometimes not and NULL create an
 CORE for tstate pointer access operations
 4. ... a lot of other problems too

all problems together I come to the conclusion:

 1. I spend ~ 1week for a job done in C# or java in a day - and have no
 usable solution
 2. python need a couple of 100+ C API function for the same job
 java need 10+
 3. the design on the C-API is amateurish - significant parts are
 implemented as GLOBAL variables
 4. the thread support is not more than a joke - go to 3
 5. after pay a lot of effort to get something working the final solution 
 is significant slower than C# or JAVA
 6. you can not truss any-thing in python because you never know
 if under some circumstance you get a CORE 
 
the resulting PYTHON code is usable but not significant more readable
as JAVA, C* or even C++ code


mfg

  aotto1968

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


Re: basic thread question

2009-08-25 Thread Piet van Oostrum
 sturlamolden sturlamol...@yahoo.no (s) wrote:

s On 25 Aug, 01:26, Piet van Oostrum p...@cs.uu.nl wrote:
 That's because it doesn't use copy-on-write. Thereby losing most of its
 advantages. I don't know SUA, but I have vaguely heard about it.

s SUA is a version of UNIX hidden inside Windows Vista and Windows 7
s (except in Home and Home Premium), but very few seem to know of it.
s SUA (Subsystem for Unix based Applications) is formerly known as
s Interix, which is a certified version of UNIX based on OpenBSD. If you
s go to http://www.interopsystems.com (a website run by Interop Systems
s Inc., a company owned by Microsoft), you will find a lot of common
s unix tools prebuilt for SUA, including Python 2.6.2.

s The NT-kernel supports copy-on-write fork with a special system call
s (ZwCreateProcess in ntdll.dll), which is what SUA's implementation of
s fork() uses.

I have heard about that also, but is there a Python implementation that
uses this? (Just curious, I am not using Windows.)
-- 
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: web frameworks that support Python 3

2009-08-25 Thread Nobody
On Sun, 23 Aug 2009 16:32:09 -0400, Albert Hopkins wrote:

 What's different about Python 3 is that there is only unicode strings,
 whereas Python 2 has a string type and a unicode type.

Python 2 has str (char) and unicode (wchar) types.

Python 3 has bytes (char) and str (wchar) types.

The main difference is that Python 3 uses unicode by default, i.e.
string literals are unicode rather than byte strings, variables
such as sys.argv and os.environ contain unicode strings, etc.

There are other differences, e.g.:

+ Passing a bytes object where str is expected will raise an exception
rather than using an automatic conversion
+ Subscripting a bytes object returns an integer between 0 and 255
+ upper(), isalpha(), etc assume ASCII rather than the system encoding

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


Re: unexpected token `;'

2009-08-25 Thread Benjamin Kaplan
On Tue, Aug 25, 2009 at 7:25 AM, Diez B. Roggisch de...@nospam.web.dewrote:


  Hello to all!
 
  I am struggling with a script in python for a while now, and decided
  to look for some help. I am running a code that takes commands from
  Marsyas(open source for Music analysis).
 
  #!/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
  #!/bin/bashimport math

 This is bogus. Replace it with

  #!/usr/bin/python

 and put the import math on the next line.



 Diez


It's not bogus. That is perfectly legitimate for using the user-installed
Python2.6 on OS X. /usr/bin/ is reserved for system programs on that
platform so it will always point to the system python install, which is
2.5.1 on Leopard and 2.3.5 on Tiger. That being said, the #!/bin/bash line
is what's screwing it up.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sgmllib.py

2009-08-25 Thread Nobody
On Mon, 24 Aug 2009 09:08:07 +0200, Stefan Behnel wrote:

 But note that sgmllib is a particularly cumbersome way to deal with HTML.

Mostly because it only provides a tokeniser, not a parser. Whoever wrote
it doesn't appear to understand the difference.

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


Re: unexpected token `;'

2009-08-25 Thread Peter Otten
bbarb...@inescporto.pt wrote:

 I am struggling with a script in python for a while now, and decided
 to look for some help. I am running a code that takes commands from
 Marsyas(open source for Music analysis).

 cmd = sfplay  + colist[2]
 print cmd
 fileout = commands.getoutput(cmd)

You have to ensure here that characters that have a special meaning for the 
shell are escaped correctly. The best approach is probably to use subprocess 
instead of commands:

fileoutput = subprocess.Popen([sfplay, colist[2]],
stdout=subprocess.PIPE, 
stderr=subprocess.STDOUT).communicate()[0]  
  

Peter

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


Re: your favorite debugging tool?

2009-08-25 Thread Esmail

Paul Rubin wrote:

Esmail ebo...@hotmail.com writes:

What is your favorite tool to help you debug your
code? I've been getting along with 'print' statements
but that is getting old and somewhat cumbersome.


Beyond print statements, I use pdb a lot.  Winpdb (www.winpdb.org) is
even better, but is kind of cumbersome to get working.


Hi,

2 quick questions.

Re pdb, if you have a 'pointer' (ie reference) to an object, is there
an easy way to dump out its contents, ie all of its members short of
writing a method that does that and then calling it?

Anyone know what is going on with the winpdb site? I haven't been able to
get to it in the last few days.

Thanks,
Esmail

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


Re: your favorite debugging tool?

2009-08-25 Thread Esmail

Michele Simionato wrote:

On Aug 22, 4:25 pm, Esmail ebo...@hotmail.com wrote:

Hi all,

What is your favorite tool to help you debug your
code?


The times when I would just use 'print' are long past. Nowadays I
spend lots of my time
with code written by others than myself. I use pdb all the time, and
now also ipdb
(ipdb is very cool if you are used to ipython).


Never heard of ipdb, I'll have to check it out.

Thanks,
Esmail

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


Re: your favorite debugging tool?

2009-08-25 Thread Esmail

Robert Marshall wrote:

On 24 Aug 2009, Paul Rubin wrote:


Esmail ebo...@hotmail.com writes:

What is your favorite tool to help you debug your
code? I've been getting along with 'print' statements
but that is getting old and somewhat cumbersome.

Beyond print statements, I use pdb a lot.  Winpdb (www.winpdb.org) is
even better, but is kind of cumbersome to get working.


And you can run it (pdb) within emacs - though I find a little roughness
in working out the exact interactions keeps ending up (ie the source
buffer displayed) in the wrong stack frame - afaict


Thanks Robert, I'll have to give that a try.

Esmail

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


Re: [ANN] pyxser-1.2r --- Python-Object to XML serialization module

2009-08-25 Thread Daniel Molina Wegener
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Stefan Behnel stefan...@behnel.de
on Tuesday 25 August 2009 01:23
wrote in comp.lang.python:


 Stefan Behnel wrote:
 for all byte
 strings, regardless of their encoding (since you can't even know if they
 represent encoded text at all).
 
 Hmm, having written that, I guess it's actually best to encode byte
 strings as base64 instead. Otherwise, null bytes and other special byte
 values won't pass.

  Sure, base64 is a good option for byte string input.

 
 I also think that if the user wants readable output for text strings, it's
 reasonable to require Unicode input instead of byte strings. Handling text
 in byte strings is just too error prone.
 
 Still, you may have to sanitize text input to make sure it doesn't contain
 special characters either. Take a look at the way lxml does it in the
 apihelpers.pxi source file, or read the XML spec on character content.

  Thanks, I will look for that. I must to do a better implementation on
handling byte strings, since would be many cases on where encoded strings
are mixed. For example different database inputs with different
encodings --- if those byte strings are not readed as Unicode strings.

  Both sanitizing and base64 encoding are good options, and also, both are
readable from other platforms. The problem with later implementations of
pyxser was that it was using *RawUnicodeEscape* which is not readable from
other platforms.

 
 Stefan

Best regards,
- -- 
 .O. | Daniel Molina Wegener   | FreeBSD  Linux
 ..O | dmw [at] coder [dot] cl | Open Standards
 OOO | http://coder.cl/| FOSS Developer
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (FreeBSD)

iQIcBAEBCgAGBQJKk9QiAAoJEHxqfq6Y4O5NvxcP/1plIdop5ghbwAKwavU8PSSe
05Lx/3AqThiQTJgG1qIrUXqA70KKGbgnyRAyOb8lTo3E1EcYnrEyM3pIg9xKbEr1
aRbpMVPIUPv//ckJxIwJlszjWoxjpSWKpRFqOkHnBjL6NcAqD7r3LxMLaDKMHNXl
Ka07clukcarEeU5f93mcOpCXMg1XFxfQFr126wbEkC5M2WxwpSJrsX6NIXL34peU
37sjuYOQGEgifw7KKVDNCmt3JNTmojCeRL+xzUiFDXRmm2B9A2Q7fGKKudNC2+u7
d5vUdWUhsK8a2P7o3c8ka/N9hcZ7ESjhlLDjtXEAb45yGUOXkpoOSLznObhGM3H9
MpPbmprvFL8sUX8F8+EOHOAbfaTtTRO384hwY2e7tVaaf6CNutK00Z5nBM7UPdWW
nclS7owNOVsrR62ZGwEcjDwjeYqXp3kIixbbSM9kALu1iKYxaueauIXct6oPQwl7
A3rEmultt7pjfbaDw+kYCouP4YnbPQn84H7Qgle/TMATPgnlD+93OnbCgWhpkx0h
21l4STWHNIZ2yi538lDDnkxKXS9reJQOYiiB9ImueIJJBZhqTwCDiCZDJg7QBVH0
7zsKH70Pbl3ENpTjBmPsxTUbOjzMwaFCbJ/h9+JCLV98TRfwa4KOAsRDC+mThnrY
k6Pj1jxY4uYmAn+xK+x+
=5B9H
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Would there be work for a sysadmin who specializes in python?

2009-08-25 Thread walterbyrd
If I took the time to really learn to use python for sysadmin work,
would I be able to find jobs, or even contract jobs?

From what I am seeing on the job boards etc., I would have to say no.
It looks to me as though I could possibly do that with perl, but not
python.

Of course, I could be missing something. Job board ads can be
deceptive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Temat:, Re: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile

2009-08-25 Thread ryniek
On 25 Sie, 07:33, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:
 On Mon, 24 Aug 2009 14:23:41 -0700 (PDT), ryniek rynie...@gmail.com
 declaimed the following in gmane.comp.python.general:

  C:\Users\Ryniek's WinSe7en\Documents\My Dropbox\Aplikacje
  \Moje_aplikacje\Pythonowe_aplikacje\Skryptypython ba
  ckuper.py -f E:\APLIKACJE\nowegg.exe E:\ MyGG

         snip

  OSError: [Errno 22] Invalid argument: 'E:\\MyGG(2009-08-24
  23:18:25).tar.bz2'
  

         WHERE in your program are you creating that file name? Based upon
 the invocation line, all you are supplying is the E:\MyGG part...
 Somewhere you are creating a timestamp and attaching that to the prefix.

         THAT is where you need to get rid of the colons -- the ones in the
 timestamp. Instead of 23:18:25 (or whatever the next run generates) you
 want something like 23_18_25...
 --
         Wulfraed         Dennis Lee Bieber               KD6MOG
         wlfr...@ix.netcom.com      HTTP://wlfraed.home.netcom.com/

Yep, i realized that it were THOSE colons. Thanks very much.
I think i must work on my perceptivity  : P

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


Re: print() and unicode strings (python 3.1)

2009-08-25 Thread Nobody
On Tue, 25 Aug 2009 03:41:54 -0700, 7stud wrote:

 Why does echoing $LC_ALL or $LC_CTYPE just give me a blank string?

Because the variables aren't set.

The default locale for a particular category (e.g. LC_CTYPE) is taken from
$LC_ALL if that is set, otherwise $LC_CTYPE, otherwise $LANG, otherwise
C is used.

Normally, you would either set LANG (and possibly some individual LC_*
variables), or LC_ALL. There's no point in setting all of them.

 In conclusion, as far as I can tell, if your python 3.1 program tries
 to output a unicode string, and the unicode string cannot be encoded
 by the codec specified in the user's LANG environment variable**, then
 the user will get an encode error. Just because the programmer's
 system can handle the output doesn't mean that another user's system
 can.  I guess that's the way it goes: if a user's environment is
 telling all programs that it only wants ascii output to go to the
 screen(sys.stdout), you can't(or shouldn't) do anything about it.
 
 **Or if the LANG environment variable is not present, then the codec
 corresponding to the locale settings(C' corresponds to ascii).

The underlying OS primitive can only handle bytes. If you read or write a
(unicode) string, Python needs to know which encoding is used. For Python
file objects created by the user (via open() etc), you can specify the
encoding; for those created by the runtime (e.g. sys.stdin), Python uses
the locale's LC_CTYPE category to select an encoding.

Data written to or read from text streams is encoded or decoded using the
stream's encoding. Filenames are encoded and decoded using the
filesystem encoding (sys.getfilesystemencoding()). Anything else uses the
default encoding (sys.getdefaultencoding()).

In Python 3, text streams are handled using io.TextIOWrapper:

http://docs.python.org/3.1/library/io.html#text-i-o

This implements a stream which can read and/or write text data on top of
one which can read and/or write binary data. The sys.std{in,out,err}
streams are instances of TextIOWrapper. You can get the underlying
binary stream from the buffer attribute, e.g.:

sys.stdout.buffer.write(b'hello world\n')

If you need to force a specific encoding (e.g. if the user has specified
an encoding via a command-line option), you can detach the existing
wrapper and create a new one, e.g.:

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 
new_encoding)

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


Re: Would there be work for a sysadmin who specializes in python?

2009-08-25 Thread Esmail

walterbyrd wrote:

If I took the time to really learn to use python for sysadmin work,
would I be able to find jobs, or even contract jobs?



FWIW, I think one of the qualities of a good system admin would be the ability
to work with a variety of tools and languages and not focus on one particular
language. Though Perl (not a favorite of mine at all :) seems to be quite
popular for admin type work, and of course knowing some sort of shell
programming etc would come in handy.

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


Re: your favorite debugging tool?

2009-08-25 Thread Ben Finney
Esmail ebo...@hotmail.com writes:

 While I do believe in a minimalist approach (part of the reason I find
 Python so appealing), using print statements sometimes only goes so
 far (for me).

Right, which is where the Python interactive interpreter (which I failed
to mention in my initial response) comes in as my favourite debugging
tool.

-- 
 \ “When I was a kid I used to pray every night for a new bicycle. |
  `\Then I realised that the Lord doesn't work that way so I stole |
_o__)   one and asked Him to forgive me.” —Emo Philips |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: your favorite debugging tool?

2009-08-25 Thread Esmail

Hi Ben,

Ben Finney wrote:


Whenever a simple output statement is too cumbersome for debugging, I
take it as a sign that the program is too cumbersome to follow.


I'll have to think about this .. though my gut says this is true :-)

re your other point about the interactive shell, I agree it's useful, but
to me still doesn't quite do what a full-fledged debugger can - but perhaps
that is a reflection of my skill with the shell at this point.

Always more to learn.

Esmail

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


Re: proposal: add setresuid() system call to python

2009-08-25 Thread Hrvoje Niksic
travis+ml-pyt...@subspacefield.org writes:

 On Mon, Jul 20, 2009 at 04:10:35PM +0200, Hrvoje Niksic wrote:
 To emulate the os-module-type calls, it's better to raise exceptions
 than return negative values:
 
  def setresuid(ruid, euid, suid):
  return _setresuid(__uid_t(ruid), __uid_t(euid), __uid_t(suid))
 
 def setresuid(ruid, euid, suid):
 res = _setresuid(__uid_t(ruid), __uid_t(euid), __uid_t(suid))
 if res  0:
 raise OSError('[Errno %d] %s' % (os.errno, errno.strerror(os.errno)))

 I am working on a module to implement all of this, but that raise command
 won't work in Python 2.6.1; it turns out that os.errno is a module, not
 an integer.  Does anyone know how to do what I want (that is, how to access
 the errno set in C functions)?

You should use ctypes.get_errno() instead of os.errno; sorry about that.

Also, when raising OSError, you should set the 'errno' attribute to the
appropriate code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen output different from native shell output

2009-08-25 Thread Nobody
On Tue, 25 Aug 2009 01:36:08 -0700, nickname wrote:

I am a relative newbie to python, I am using os.popen to run an
 ls command. The output that I get using the read() function is
 different in look and feel from when I run the ls command natively
 from the shell (not via python).

As others have pointed out, the default behaviour of ls is different if
its output is a terminal.

 Is there an easy way to mirror the output. When python displays the
 output, how can it tell the bash shell that some of the entries are
 directories and they should appear blue on the bash shell, and that
 everything should not be appearing on 1 column only.

You can get the terminal-style behaviour even when using a pipe with:

ls -x --color

But why are you reading this information into Python then writing it
back out to the terminal?

If you're planning on processing the output within Python, both the
multi-column format and the escape sequences used for colour will make
such processing awkward.

If you want to enumerate the contents of a directory within Python, use
os.listdir().

If you want to generate coloured output, use the curses module, e.g.:

#!/usr/bin/env python

import sys
import curses

curses.setupterm()
setaf = curses.tigetstr('setaf') or 
setab = curses.tigetstr('setab') or 
origp = curses.tigetstr('op') or 

def fg(c):
sys.stdout.write(curses.tparm(setaf, c))

def bg(c):
sys.stdout.write(curses.tparm(setab, c))

def orig():
sys.stdout.write(origp)

# example
bg(curses.COLOR_BLUE)
fg(curses.COLOR_YELLOW)
print hello, world
orig()

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


Re: Protecting against callbacks queuing up?

2009-08-25 Thread Esben von Buchwald

Dennis Lee Bieber wrote:

On Mon, 24 Aug 2009 17:32:23 +0200, Esben von Buchwald
find@paa.google declaimed the following in
gmane.comp.python.general:

I'm new to python, what is an after function and an after call? Couldn't 
find excact answer on google...? Do you have a link to some docs?


They would be particular to whatever GUI/event library is in use.
They aren't part of Python itself.


This is how the accelerometer is accessed
http://pys60.garage.maemo.org/doc/s60/node59.html

I found this called after...
http://pys60.garage.maemo.org/doc/s60/node12.html

would that be usable?

If so, how?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Items inheriting attributes from its container?

2009-08-25 Thread Kreso
Jan Kaliszewski z...@chopin.edu.pl wrote:
[...]


Great! Thanks to all of you for advices and code.

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


Re: Would there be work for a sysadmin who specializes in python?

2009-08-25 Thread Brent Bloxam

walterbyrd wrote:

If I took the time to really learn to use python for sysadmin work,
would I be able to find jobs, or even contract jobs?


From what I am seeing on the job boards etc., I would have to say no.

It looks to me as though I could possibly do that with perl, but not
python.

Of course, I could be missing something. Job board ads can be
deceptive.


Being a system admin is about being able to handle to many different 
situations, and your tasks can often include automating various things 
and writing tools. Depending on the sort of place you're working in and 
the size of the IT department, you could find yourself doing a lot of 
work that lies outside of the standard job description for a system 
administrator. If you're looking to start out in the field, it would be 
better to have general knowledge, and as you gain experience you can 
begin to specialize.


Being adaptable is key, so specializing in python probably won't gain 
you any ground as a system administrator. That being said, knowing 
python will mean you have another tool in your chest, which is 
definitely a good thing. If there's one thing I'd recommend, if you're 
not going to focus on a windows environment, would be to at least get 
perl under your belt as well.

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


Re: csv module and None values

2009-08-25 Thread JKPeck
On Aug 24, 10:43 pm, John Yeung gallium.arsen...@gmail.com wrote:
 On Aug 24, 5:00 pm, Peter Otten __pete...@web.de wrote:

  If I understand you correctly the csv.writer already does
  what you want:

   w.writerow([1,None,2])
  1,,2

  just sequential commas, but that is the special treatment.
  Without it the None value would be converted to a string
  and the line would look like this one:

  1,None,2

 No, I think he means he is getting

  w.writerow([1,None,2])

 1,,2

 He evidently wants to quote all strings, but doesn't want None to be
 considered a string.

 John

Exactly so.  The requirement of the receiving program, which is out of
my control, is that all strings be quoted but a None in a numeric
field result in the ,, output rather than .  Excel quotes strings
conditionally, which doesn't do what is needed in this case.  For
QUOTE_NONNUMERIC to quote None values makes some sense, but it gets in
the way of representing missing values in a numeric field.  It would
be nice to have a choice here in the dialects.

I thought of replacing the None values with float(nan), since that has
a numeric type, but unfortunately that results in writing the string
(unquoted) nan for the value.  So the sentinel approach seems to be
the best I can do.

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


multiprocessing managers and socket connection.

2009-08-25 Thread Chris
I've been using multiprocessing managers and I really like the
functionality.

I have a question about reconnecting to a manager. I have a situation
where I start on one machine (A) a manager that is listening and then
on another machine (B) connects to that manager and uses its proxy
object to call functions on the manager's computer; this all works as
expected. But, if the manager from A shuts down, B's application won't
notice because in the MP code it ignores socket error
errno.ECONNREFUSED. If A becomes available again or is restarted, B
doesn't automatically reconnect either and continue its operation.
It's function is basically stopped.

Here is the code from connection.py:
while 1:
try:
s.connect(address)
except socket.error, e:
if e.args[0] != errno.ECONNREFUSED: # connection refused
debug('failed to connect to address %s', address)
raise
time.sleep(0.01)
else:
break

How can I have B automatically reconnect to A and continue its work
once A is available again?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-25 Thread Steven D'Aprano
On Mon, 24 Aug 2009 18:01:38 -0700, Mensanator wrote:

 If you want your data file to have values entered in hex, or oct, or
 even unary (1=one, 11=two, 111=three, =four...) you can.
 
 Unary? I think you'll find that Standard Positional Number Systems are
 not defined for radix 1.

Of course not. But unary isn't a positional number system. It's a tally 
system, like my example above shows. Roman numerals are another tally 
system. Like Roman numerals, the disadvantages of unary are that you 
can't represent negative numbers, zero, or fractions, and anything but 
addition and subtraction is difficult. But if you want to use it, perhaps 
out of a sense of sadism towards your users, it's easy:

def int2unary(n):
return '1'*n

def unary2int(s):
n = 0
for c in s:
if c == '1': n+=1
else: raise ValueError('invalid unary string')
return n



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


Re: your favorite debugging tool?

2009-08-25 Thread Jean-Michel Pichavant

Esmail wrote:

Hi Ben,

Ben Finney wrote:


Whenever a simple output statement is too cumbersome for debugging, I
take it as a sign that the program is too cumbersome to follow.


I'll have to think about this .. though my gut says this is true :-)

That is not always true. When it comes to implement complex tasks, you 
can't always avoid writing complex code. Python does not get your code 
more complex than your algorithm, but it cannot always simplify it.


Ben is right when he says that code can often be written in a more 
simpler manner, but they are some occasions when you have to write 
complex code, that the print debug statement won't be efficient enough 
to sort things out. I personally develop/maintain a full application 
written in python (and quite complex for some parts), using the ipdb 
debugger just saved my hours (days) of headache about some very 
difficult bug to spot

re your other point about the interactive shell, I agree it's useful, but
to me still doesn't quite do what a full-fledged debugger can - but 
perhaps

that is a reflection of my skill with the shell at this point.

Always more to learn.

Esmail



90% of the time, print statements + ipython shell will do the trick. The 
post mortem debugging is also very useful. Execute your  python file in 
ipython, then when it exits upon exception, execute

 import pdb ; pdb.pm()
You can then inspect the symbols easily.

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


TypeError: _getfullpathname() argument 1 must be (buffer overflow), not str in windows xp, while making tarfile

2009-08-25 Thread Ryniek90

Referring to my earlier posts:
http://groups.google.pl/group/comp.lang.python/browse_thread/thread/4e34f995800f5352?hl=pl

and

http://groups.google.pl/group/comp.lang.python/browse_thread/thread/abf5573b8fceb37e?hl=pl#

I've dealt with those errors. but now have another.
When my backup scripts starts to backup chosen file, python gave me 
Traceback:



C:\Users\Ryniek's WinSe7en\Documents\My 
Dropbox\Aplikacje\Moje_aplikacje\Pythonowe_aplikacje\Skryptypython ba

ckuper.py -f F:\APLIKACJE\nowegg.exe F:\ MyGGBackup
Checking permissions for reading and writing...
Have permissions on [F:\APLIKACJE\nowegg.exe] for reading.
Have permissions on [F:\] for writing.
Preparing for backup [nowegg.exe]...
Starting backup...
Now adding [nowegg.exe]...
Traceback (most recent call last):
 File backuper.py, line 197, in module
   main_meth()
 File backuper.py, line 189, in main_meth
   paq.backup_file(pars.options.filename[0], pars.options.filename[1], 
pars.options.filename[2])

 File backuper.py, line 127, in backup_file
   backup_obj.add(read_bin_obj)
 File E:\WinSe7en Apps\APLIKACJE\ActiveState Python 
2.6\lib\tarfile.py, line 1948, in add

   if self.name is not None and os.path.abspath(name) == self.name:
 File E:\WinSe7en Apps\APLIKACJE\ActiveState Python 
2.6\lib\ntpath.py, line 458, in abspath

   path = _getfullpathname(path)
TypeError: _getfullpathname() argument 1 must be (buffer overflow), not str


I've searched over google, but found only that is bug in Python ( 
http://bugs.python.org/issue4071  - in that issue bug is inside Python 
2.5.2 - i've got ActiveState Active Python with core Python 2.6.2), and 
another  info:   *http://tinyurl.com/lvyn7o  and **http://tinyurl.com/kn49vk

*

Here's my script code:
*http://paste.ubuntu.com/259310/

*Shouldn't that bug be patched already  :-?
--
http://mail.python.org/mailman/listinfo/python-list


inconsistent sitecustomize.py importing...

2009-08-25 Thread Chris Withers

Hi All,

Give this sitecustomize.py:

print ping

...and this script:

#!/usr/local/bin/python2.5
print pong!

...both in ~/folder, I would expect the output from:

~$./folder/script

...to be:

ping
pong

...but sitecustomize.py is not imported :-(

If I do:

~$/usr/local/bin/python2.5 folder/script

...still no import.

However, if I do:

~/folder$/usr/local/bin/python2.5 script

...sitecustomize.py IS imported!

What gives?!

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: csv module and None values

2009-08-25 Thread Peter Otten
JKPeck wrote:

 On Aug 24, 10:43 pm, John Yeung gallium.arsen...@gmail.com wrote:
 On Aug 24, 5:00 pm, Peter Otten __pete...@web.de wrote:

  If I understand you correctly the csv.writer already does
  what you want:

   w.writerow([1,None,2])
  1,,2

  just sequential commas, but that is the special treatment.
  Without it the None value would be converted to a string
  and the line would look like this one:

  1,None,2

 No, I think he means he is getting

  w.writerow([1,None,2])

 1,,2

 He evidently wants to quote all strings, but doesn't want None to be
 considered a string.

 John
 
 Exactly so.  The requirement of the receiving program, which is out of
 my control, is that all strings be quoted but a None in a numeric
 field result in the ,, output rather than .  Excel quotes strings
 conditionally, which doesn't do what is needed in this case.  For
 QUOTE_NONNUMERIC to quote None values makes some sense, but it gets in
 the way of representing missing values in a numeric field.  It would
 be nice to have a choice here in the dialects.
 
 I thought of replacing the None values with float(nan), since that has
 a numeric type, but unfortunately that results in writing the string
 (unquoted) nan for the value.  So the sentinel approach seems to be
 the best I can do.

How about:

 import csv, sys
 class N(int):
... def __str__(self): return 
...
 pseudo_none = N()
 w = csv.writer(sys.stdout, quoting=csv.QUOTE_NONNUMERIC)
 w.writerow([1, foo, pseudo_none, bar])
1,foo,,bar

Peter

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


Re: your favorite debugging tool?

2009-08-25 Thread Ben Finney
Esmail ebo...@hotmail.com writes:

 Hi Ben,

 Ben Finney wrote:
 
  Whenever a simple output statement is too cumbersome for debugging, I
  take it as a sign that the program is too cumbersome to follow.

 I'll have to think about this .. though my gut says this is true :-)

Note that it's only a sign, *not* an ironclad guarantee. But it's the
right way to bet, IME.

 re your other point about the interactive shell, I agree it's useful,
 but to me still doesn't quite do what a full-fledged debugger can -
 but perhaps that is a reflection of my skill with the shell at this
 point.

This, on the other hand, I find even more consistent: if the code can't
be effectively inspected from the interactive interpreter, that's a sure
sign that its external interfaces are poor or its internal dependencies
too tightly coupled; or more likely both.

Fixing that set of problems is both useful for debugging *and* good
design.

-- 
 \ “Alternative explanations are always welcome in science, if |
  `\   they are better and explain more. Alternative explanations that |
_o__) explain nothing are not welcome.” —Victor J. Stenger, 2001-11-05 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Even more inconsistent sitecustomize.py importing with PYTHONPATH rolled in...

2009-08-25 Thread Chris Withers

Chris Withers wrote:

However, if I do:

~/folder$/usr/local/bin/python2.5 script

...sitecustomize.py IS imported!


However, the following doesn't import sitecustomize.py:

~/folder$ ./script

While the following DOES import sitecustomize.py:

~/folder$ export PYTHONPATH=
~/folder$ ./script

Bizarrely, none of the following import sitecustomize.py:

~$ export PYTHONPATH=~/folder
~$ ./script

~$ export PYTHONPATH=~/folder/
~$ ./script

~$ export PYTHONPATH=~/folder
~/folder$ ./script

~$ export PYTHONPATH=~/folder/
~/folder$ ./script

Does anyone have any clue why there's such a huge level of inconsistency 
here?!


Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Even more inconsistent sitecustomize.py importing with PYTHONPATH rolled in...

2009-08-25 Thread Chris Withers

Chris Withers wrote:

Bizarrely, none of the following import sitecustomize.py:

~$ export PYTHONPATH=~/folder
~$ ./script

~$ export PYTHONPATH=~/folder/
~$ ./script

~$ export PYTHONPATH=~/folder
~/folder$ ./script

~$ export PYTHONPATH=~/folder/
~/folder$ ./script


Okay, brain fail on my part, these do work, the others are still as 
described though...


Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Putting together a larger matrix from smaller matrices

2009-08-25 Thread Scott David Daniels

Matjaz Bezovnik wrote:

If you are using numpy (which it sounds like you are):

IDLE 2.6.2
 import numpy as np
 v = np.array([[0,1,2],[3,4,5],[6,7,8]], dtype=float)
 v
array([[ 0.,  1.,  2.],
   [ 3.,  4.,  5.],
   [ 6.,  7.,  8.]])
 w = np.array([[10,11,12],[13,14,15],[16,17,18]], dtype=float)
 w
array([[ 10.,  11.,  12.],
   [ 13.,  14.,  15.],
   [ 16.,  17.,  18.]])
 r = np.zeros((6,6))
 r
array([[ 0.,  0.,  0.,  0.,  0.,  0.],
   [ 0.,  0.,  0.,  0.,  0.,  0.],
   [ 0.,  0.,  0.,  0.,  0.,  0.],
   [ 0.,  0.,  0.,  0.,  0.,  0.],
   [ 0.,  0.,  0.,  0.,  0.,  0.],
   [ 0.,  0.,  0.,  0.,  0.,  0.]])
 r[:3,:3] = v
 r
array([[ 0.,  1.,  2.,  0.,  0.,  0.],
   [ 3.,  4.,  5.,  0.,  0.,  0.],
   [ 6.,  7.,  8.,  0.,  0.,  0.],
   [ 0.,  0.,  0.,  0.,  0.,  0.],
   [ 0.,  0.,  0.,  0.,  0.,  0.],
   [ 0.,  0.,  0.,  0.,  0.,  0.]])
 r[3:,3:] = w
 r
array([[  0.,   1.,   2.,   0.,   0.,   0.],
   [  3.,   4.,   5.,   0.,   0.,   0.],
   [  6.,   7.,   8.,   0.,   0.,   0.],
   [  0.,   0.,   0.,  10.,  11.,  12.],
   [  0.,   0.,   0.,  13.,  14.,  15.],
   [  0.,   0.,   0.,  16.,  17.,  18.]])


In general, make the right-sized array of zeros, and at various points:
and you can ssign to subranges of the result array:

N = 3
result = np.zeros((len(parts) * N, len(parts) * N), dtype=float)
for n, chunk in enumerate(parts):
base = n * 3
result[base : base + 3, base : base + 3] = chunk

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: inconsistent sitecustomize.py importing...

2009-08-25 Thread Steven D'Aprano
On Tue, 25 Aug 2009 15:45:53 +0100, Chris Withers wrote:

 Hi All,
 
 Give this sitecustomize.py:
[...]
 What gives?!

Perhaps this?

http://bugs.python.org/issue1734860


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


Need help with Python scoping rules

2009-08-25 Thread kj



I have many years of programming experience, and a few languages,
under my belt, but still Python scoping rules remain mysterious to
me.  (In fact, Python's scoping behavior is the main reason I gave
up several earlier attempts to learn Python.)

Here's a toy example illustrating what I mean.  It's a simplification
of a real-life coding situation, in which I need to initialize a
private class variable by using a recursive helper function.

class Demo(object):
def fact(n):
if n  2:
return 1
else:
return n * fact(n - 1)

_classvar = fact(5)

This code fails to compile, with the error global name 'fact' not
defined.

Scanning the Python Language Reference page I see nothing that
would suggest to me a discussion of Python's scoping rules, let
alone anything that would help me solve the specific problem above.
I'm sure it's in there, *somewhere*, but it's anyone's guess where.

Likewise, my book, Beazley's Python: Essential Reference is of
no help.  I don't doubt that the answer to my question is in there,
*somewhere*, but finding it (without reading the book sequentially
from page 1) is a tall order.

All that's left is trial-and-error, the worst kind of programming.
And still I can't find the right way to do this...  I've tried
every variant of this code that I can imagine, including decorating
fact with @staticmethod or @classmethod, etc., etc.  (In the latter
case, I get cryptic errors saying that the staticmethod or classmethod
object is not callable.  Or something like that.)

Needless to say, I'm pretty beat by this point.  Any help would be
appreciated.

Thanks,

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


Re: Putting together a larger matrix from smaller matrices

2009-08-25 Thread Matjaz Bezovnik
On Tue, 25 Aug 2009 08:26:44 -0700, Scott David Daniels
scott.dani...@acm.org wrote:

Matjaz Bezovnik wrote:

If you are using numpy (which it sounds like you are):

IDLE 2.6.2
  import numpy as np
  v = np.array([[0,1,2],[3,4,5],[6,7,8]], dtype=float)
  v
array([[ 0.,  1.,  2.],
[ 3.,  4.,  5.],
[ 6.,  7.,  8.]])
  w = np.array([[10,11,12],[13,14,15],[16,17,18]], dtype=float)
  w
array([[ 10.,  11.,  12.],
[ 13.,  14.,  15.],
[ 16.,  17.,  18.]])
  r = np.zeros((6,6))
  r
array([[ 0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.]])
  r[:3,:3] = v
  r
array([[ 0.,  1.,  2.,  0.,  0.,  0.],
[ 3.,  4.,  5.,  0.,  0.,  0.],
[ 6.,  7.,  8.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.]])
  r[3:,3:] = w
  r
array([[  0.,   1.,   2.,   0.,   0.,   0.],
[  3.,   4.,   5.,   0.,   0.,   0.],
[  6.,   7.,   8.,   0.,   0.,   0.],
[  0.,   0.,   0.,  10.,  11.,  12.],
[  0.,   0.,   0.,  13.,  14.,  15.],
[  0.,   0.,   0.,  16.,  17.,  18.]])
 

In general, make the right-sized array of zeros, and at various points:
and you can ssign to subranges of the result array:

 N = 3
 result = np.zeros((len(parts) * N, len(parts) * N), dtype=float)
 for n, chunk in enumerate(parts):
 base = n * 3
 result[base : base + 3, base : base + 3] = chunk

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



Scott, thank you very much for the snippet.

It is exactly what I looked for; simple to read and obvious as to what
it does even a month later to a non-pythonist!

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


Re: Graph library recommendations for large graphs

2009-08-25 Thread Neal Becker
VanL wrote:

 I am working on a project that will require building and querying large
 graph objects (initially 8M nodes, 30-40M edges; eventually 40M nodes,
 100M edges). NetworkX seems to be the most popular, but I am concerned
 that a dict representation for nodes would use too much memory -- my
 initial tests suggest that a graph with 3M nodes and 12M edges creates
 substantial memory pressure on my machine.
 
 Can anybody who has worked with large graphs before give a recommendation?
 
 Thanks,
 
 Van
 
How about python-igraph?

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


Re: TypeError: _getfullpathname() argument 1 must be (buffer overflow), not str in windows xp, while making tarfile

2009-08-25 Thread MRAB

Ryniek90 wrote:

Referring to my earlier posts:
http://groups.google.pl/group/comp.lang.python/browse_thread/thread/4e34f995800f5352?hl=pl 



and

http://groups.google.pl/group/comp.lang.python/browse_thread/thread/abf5573b8fceb37e?hl=pl# 



I've dealt with those errors. but now have another.
When my backup scripts starts to backup chosen file, python gave me 
Traceback:



C:\Users\Ryniek's WinSe7en\Documents\My 
Dropbox\Aplikacje\Moje_aplikacje\Pythonowe_aplikacje\Skryptypython ba

ckuper.py -f F:\APLIKACJE\nowegg.exe F:\ MyGGBackup
Checking permissions for reading and writing...
Have permissions on [F:\APLIKACJE\nowegg.exe] for reading.
Have permissions on [F:\] for writing.
Preparing for backup [nowegg.exe]...
Starting backup...
Now adding [nowegg.exe]...
Traceback (most recent call last):
 File backuper.py, line 197, in module
   main_meth()
 File backuper.py, line 189, in main_meth
   paq.backup_file(pars.options.filename[0], pars.options.filename[1], 
pars.options.filename[2])

 File backuper.py, line 127, in backup_file
   backup_obj.add(read_bin_obj)
 File E:\WinSe7en Apps\APLIKACJE\ActiveState Python 
2.6\lib\tarfile.py, line 1948, in add

   if self.name is not None and os.path.abspath(name) == self.name:
 File E:\WinSe7en Apps\APLIKACJE\ActiveState Python 2.6\lib\ntpath.py, 
line 458, in abspath

   path = _getfullpathname(path)
TypeError: _getfullpathname() argument 1 must be (buffer overflow), not str


I've searched over google, but found only that is bug in Python ( 
http://bugs.python.org/issue4071  - in that issue bug is inside Python 
2.5.2 - i've got ActiveState Active Python with core Python 2.6.2), and 
another  info:   *http://tinyurl.com/lvyn7o  and 
**http://tinyurl.com/kn49vk

*

Here's my script code:
*http://paste.ubuntu.com/259310/

*Shouldn't that bug be patched already  :-?

Are you giving it the contents of the file when it's actually expecting
the filename?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Protecting against callbacks queuing up?

2009-08-25 Thread Hendrik van Rooyen
On Tuesday 25 August 2009 15:21:16 Esben von Buchwald wrote:
 Dennis Lee Bieber wrote:
  On Mon, 24 Aug 2009 17:32:23 +0200, Esben von Buchwald
  find@paa.google declaimed the following in
 
  gmane.comp.python.general:
  I'm new to python, what is an after function and an after call? Couldn't
  find excact answer on google...? Do you have a link to some docs?
 
  They would be particular to whatever GUI/event library is in use.
  They aren't part of Python itself.

 This is how the accelerometer is accessed
 http://pys60.garage.maemo.org/doc/s60/node59.html

 I found this called after...
 http://pys60.garage.maemo.org/doc/s60/node12.html

 would that be usable?
Probably

 If so, how?

This is a guess, for your device,  but I suspect
something along these lines:

t = Ao_timer()

cb = t.after(100,thing_that_does_the_work(with_its_arguments))

Lots of assumptions here - the 100 should give you a tenth of a second...
Don't know what the arguments look like, and if you need to pass an instance 
(like self) - that would depend on where you are calling it from.

Play and see :-)

You should also be able to cancel the callback like this:

t.cancel(cb)

If you do it before the time out

- Hendrik

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


Re: Code formatting question: conditional expression

2009-08-25 Thread Nicola Larosa (tekNico)
John Posner wrote:
 Is there any consensus on how to format a conditional expression
 that is too long for one line?

Here's my take:

excessblk = Block(total - P.BASE, srccol,
carry_button_suppress=True
) if total  P.BASE else None

--
Nicola Larosa - http://www.tekNico.net/

Nobody knows everything, and nobody is expected to be perfect
in the Ubuntu community (except of course the SABDFL).
 - https://launchpad.net/codeofconduct/1.0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with Python scoping rules

2009-08-25 Thread Martin P. Hellwig

kj wrote:
cut


Here's a toy example illustrating what I mean.  It's a simplification
of a real-life coding situation, in which I need to initialize a
private class variable by using a recursive helper function.


eh?



class Demo(object):
def fact(n):
if n  2:
return 1
else:
return n * fact(n - 1)

_classvar = fact(5)


cut
Sorry still doesn't make sense, I'll give it a try though:

class Demo(object):
Apparently a 'real-life coding situation'
def __init__(self):
# Look at http://docs.python.org/tutorial/classes.html
# for init explanation.
self.__class_var = self.fact(5)

def fact(self, number):
Look at http://docs.python.org/tutorial/classes.html why you 
need

self.
if number  2:
return(1)
else:
return_value = number * self.fact(number -1)
return(return_value)


TEST = Demo()
# Print the 'private' class variable
print(TEST._Demo__class_var)

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: your favorite debugging tool?

2009-08-25 Thread Falcolas
On Aug 23, 1:21 am, Hendrik van Rooyen hend...@microcorp.co.za
wrote:
 On Saturday 22 August 2009 16:49:22 Aahz wrote:

  In article mailman.227.1250951162.2854.python-l...@python.org,

  Esmail  ebo...@hotmail.com wrote:
  What is your favorite tool to help you debug your code? I've been
  getting along with 'print' statements but that is getting old and
  somewhat cumbersome.

  Despite the fact that I've been using Python for more than a decade,
  print is still my mainstay (or possibly logging to a file).

 Same here, although I have not been abusing python for as long as Aahz has
 been using it.

 ...

 And the final arbiter is of course the interactive prompt.

 - Hendrik

The only thing I would add to these comments is the fact that writing
helper functions for using print with complicated routines is very
simple, though perhaps not obvious. For example, consider the
following for unrolling list comprehensions or generators without
having to re-write them:

def trace(iterable):
for x in iterable:
print x
yield x

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


Re: Need help with Python scoping rules

2009-08-25 Thread Diez B. Roggisch
kj wrote:

 
 
 
 I have many years of programming experience, and a few languages,
 under my belt, but still Python scoping rules remain mysterious to
 me.  (In fact, Python's scoping behavior is the main reason I gave
 up several earlier attempts to learn Python.)
 
 Here's a toy example illustrating what I mean.  It's a simplification
 of a real-life coding situation, in which I need to initialize a
 private class variable by using a recursive helper function.
 
 class Demo(object):
 def fact(n):
 if n  2:
 return 1
 else:
 return n * fact(n - 1)
 
 _classvar = fact(5)
 
 This code fails to compile, with the error global name 'fact' not
 defined.
 
 Scanning the Python Language Reference page I see nothing that
 would suggest to me a discussion of Python's scoping rules, let
 alone anything that would help me solve the specific problem above.
 I'm sure it's in there, *somewhere*, but it's anyone's guess where.
 
 Likewise, my book, Beazley's Python: Essential Reference is of
 no help.  I don't doubt that the answer to my question is in there,
 *somewhere*, but finding it (without reading the book sequentially
 from page 1) is a tall order.
 
 All that's left is trial-and-error, the worst kind of programming.
 And still I can't find the right way to do this...  I've tried
 every variant of this code that I can imagine, including decorating
 fact with @staticmethod or @classmethod, etc., etc.  (In the latter
 case, I get cryptic errors saying that the staticmethod or classmethod
 object is not callable.  Or something like that.)

Classes are not scopes. 

So the above doesn't work because name resolution inside functions/methods
looks for local variables first, then for the *global* scope. There is no
class-scope-lookup.

If you want anything else, you need to qualify it with a full name,
Demo.fact. Which isn't working for your example because Demo isn't
available yet.

But if you insist on the above methodology, you can do this:


class Demo(object):

def fact(n):
def inner(n):
if n  2:
return 1
else:
return n * inner(n - 1)
return inner(n)

_classvar = fact(5)

This makes inner a *local* variable, which is found.

Diez

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


Re: Web Services examples using raw xml?

2009-08-25 Thread John Gordon
In 4a936e84$0$31337$9b4e6...@newsspool4.arcor-online.net Stefan Behnel 
stefan...@behnel.de writes:

  I tried WSDL.Proxy() from the SOAPpy package and eventually end up
  with this error:
  
  xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, 
  column 6

 Is that while parsing the WSDL file? Have you tried pushing it through an
 XML parser yourself (or opening it with an XML editor) to see if it really
 is XML?

The 'invalid token' error happens if the argument to WSDL.Proxy() is a
string containing a URL beginning with https.  (It doesn't happen with a
http URL, but I'm stuck with https.)

As a next step, I grabbed the content from the https url in a browser,
saved it to a file, inserted it into the python code as a large string,
and passed that string to WSDL.Proxy().

That produced a KeyError 'targetNamespace' from this snippet of XML:

  xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema;
xs:import 
namespace=http://schemas.microsoft.com/exchange/services/2006/messages; 
schemaLocation=messages.xsd/
  /xs:schema

I looked at the code and it apparently requires that the parent tag of
xs:import have a targetNamespace attribute.  So I made one up and added
it, like so:

  xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema; targetNamespace=xyz

I have no idea if this was the right thing to do, but it did let me advance
to the next error:

  Traceback (most recent call last):
  File soappytest.py, line 1020, in ?
server = jrgWSDL.Proxy(wsdlFile)
  File /home/gordonj/wsdl/jrgSOAPpy/jrgWSDL.py, line 75, in __init__
service = self.wsdl.services[0]
  File /home/gordonj/wsdl/jrgwstools/Utility.py, line 631, in __getitem__
return self.list[key]
IndexError: list index out of range

After poking around in the code a bit more, I think that self.wsdl.services
is supposed to be a collection of all the services offered by the wsdl, but
it's actually empty, which is why it throws an error when it tries to
access the first element.

So that's where I'm stuck at the moment.  I have no idea why
self.wsdl.services isn't getting populated correctly -- or even if that's
the real problem!

Any suggestions?

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

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


Re: Need help with Python scoping rules

2009-08-25 Thread Jean-Michel Pichavant

kj wrote:


I have many years of programming experience, and a few languages,
under my belt, but still Python scoping rules remain mysterious to
me.  (In fact, Python's scoping behavior is the main reason I gave
up several earlier attempts to learn Python.)

Here's a toy example illustrating what I mean.  It's a simplification
of a real-life coding situation, in which I need to initialize a
private class variable by using a recursive helper function.

class Demo(object):
def fact(n):
if n  2:
return 1
else:
return n * fact(n - 1)

_classvar = fact(5)

This code fails to compile, with the error global name 'fact' not
defined.
  

[snip]

fact is defined within the Demo class, so to access it, you'll need to 
prefix it with Demo:


_classvar = Demo.fact(5).

The problem is, Demo will raise a NameError exception.
The solution is pretty simple, cause your fact function seems to be 
unrelated to the Demo class :


def _fact(n):
   # some code

class Demo(object):
   _classvar = _fact(5)


It may happen that you *want* your fact within the Demo, in you example 
it's not that obvious, but I think Java would allow such following patern:


class Color:
   def __init__(self, r, g,b):
 pass
   BLACK = Color(0,0,0)

It make sens from a design point of view to put BLACK in the Color 
namespace. But I don't think it's possible with python.

You could trick the system using inheritance:

class Chrome:
   def __init__(self, r,g,b)
  pass
Putting all your code in the Chrome class then:

class Color(Chrome):
   BLACK = Chrome(0,0,0)

I'm not sure this is satisfying.

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


Re: Need help with Python scoping rules

2009-08-25 Thread Jean-Michel Pichavant

Diez B. Roggisch wrote
Classes are not scopes. 

  

Too bad, could have been handy.

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


Re: Need help with Python scoping rules

2009-08-25 Thread Xavier Ho
I'm not really quite sure what voodoo I did here, but my code seems to work
in Python 3.1.1 in the following way:

class Demo(object):
def func(self, n):
return n * 5
_f = func(None, 5)

d = Demo()
print(d._f)
print(d.func(5))

# OUTPUT
25
25

So, hmm?

Regards,

Ching-Yun Xavier Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com
Website: http://xavierho.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with Python scoping rules

2009-08-25 Thread Xavier Ho
On Wed, Aug 26, 2009 at 2:14 AM, Diez B. Roggisch de...@nospam.web.dewrote:


 Classes are not scopes.

 So the above doesn't work because name resolution inside functions/methods
 looks for local variables first, then for the *global* scope. There is no
 class-scope-lookup.


Sorry, I'm coming here with sincere ignorance. If local variables and global
variables are not scopes, then what would it be?

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


Re: Need help with Python scoping rules

2009-08-25 Thread Diez B. Roggisch
Jean-Michel Pichavant wrote:

 Diez B. Roggisch wrote
 Classes are not scopes.

   
 Too bad, could have been handy.

Nope. Because then a lot of people would write something like this:


class Foo(object):


   def bar(self):
   bar() # note the missing self.


And this would lead to errors because self was missing from the call
to bar.

And you'd need a disambiguation for methodname/global-name-clashes. The
global-statement would work, but then code could break when all  of a
sudden a subclass defines a method that hitherto was only known as global.
So via subclassing, you introduce *arbitray* and hard to debug errors.

No. I'm certain, not a good idea.

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


Re: conditional for-statement

2009-08-25 Thread seb
On Aug 23, 11:02 pm, Chris Rebert c...@rebertia.com wrote:
 On Sun, Aug 23, 2009 at 1:36 PM, sebsdemen...@gmail.com wrote:
  On Aug 23, 6:18 pm, John Posner jjpos...@optimum.net wrote:
   Hi,

   i was wondering if there is a syntax alike:

   for i in range(10) if i  5:
       print i

   You can write

   for i in filter(lambda i: i  5, range(10)):
       print i

   but

   for i in range(10):
       if i  5:
           print i

   it' better readable, and

   for i in range(6,10):
       print i

   it's event better.

  How about using a generator expression instead of a list?

    for i in (x for x in range(10) if x  5):
        print i

  -John

  Indeed, but we could have the same syntax than for generators but
  directly in the for statement as in
  for variable in generator if condition:
     body

  Is there a special reason for not doing so ? A rejected PEP ?

 It's not been added since it's completely unnecessary (see the several
 alternatives already presented by others).
 There have been a few other mailinglist threads on adding essentially
 the same syntax. None have proved fruitful.

 Cheers,
 Chris
 --http://blog.rebertia.com- Hide quoted text -

 - Show quoted text -

On Aug 23, 11:02 pm, Chris Rebert c...@rebertia.com wrote:
 On Sun, Aug 23, 2009 at 1:36 PM, sebsdemen...@gmail.com wrote:
  On Aug 23, 6:18 pm, John Posner jjpos...@optimum.net wrote:
   Hi,

   i was wondering if there is a syntax alike:

   for i in range(10) if i  5:
   print i

   You can write

   for i in filter(lambda i: i  5, range(10)):
   print i

   but

   for i in range(10):
   if i  5:
   print i

   it' better readable, and

   for i in range(6,10):
   print i

   it's event better.

  How about using a generator expression instead of a list?

for i in (x for x in range(10) if x  5):
print i

  -John

  Indeed, but we could have the same syntax than for generators but
  directly in the for statement as in
  for variable in generator if condition:
 body

  Is there a special reason for not doing so ? A rejected PEP ?

 It's not been added since it's completely unnecessary (see the several
 alternatives already presented by others).
 There have been a few other mailinglist threads on adding essentially
 the same syntax. None have proved fruitful.

 Cheers,
 Chris
 --http://blog.rebertia.com- Hide quoted text -

 - Show quoted text -

Tx Chris for your reply !

i am still a bit puzzle by the following.

I read in http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Generators

Python 3.0 unifies all collection types by introducing dict and set
comprehensions, similar to list comprehensions:

 [ n*n for n in range(5) ] # regular list comprehension
[0, 1, 4, 9, 16]

 { n*n for n in range(5) } # set comprehension
{0, 1, 4, 16, 9}

 { n: n*n for n in range(5) } # dict comprehension
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}

and we can add to this list the quite similar syntax for generator
expressions.

On all these loop constructs, one can consistenly add filtering on a
condition by adding an if ... after the for ... in ... part (and
it looks to me difficult to argue, for instance, that we should not
allow filtering for dict comprehesion because we could get the same
result by some other construct)

If the if ... part after the for ... in ... is so much used in all
these list/dict/set comprehensions and in the generator expressions,
it makes sense to me to have it also for the for as a statement
syntax :
[ n*n for n in range(10) if n%3 == 0]
{ n*n for n in range(10) if n%3 == 0}
{ n: n*n for n in range(10) if n%3 == 0}
( n*n for n in range(10) if n%3 == 0)
for n in range(10) if n%3 == 0:
  print n*n

In fact, we often see the list comprehension [ n*n for n in range(10)
if n%3 == 0] explained as being equivalent to
l = []
for n in range(10):
  if n%3 == 0:
l.append(n)

We could as consistenly explain that the syntax

for n in range(10) if n%3==0:
  body

means

for n in range(10):
  if n%3==0:
body

This syntax has also the benefit of avoiding an extra level of
indentation (the one for the if) that bears no real meaning on a
structural level.

Maybe a PEP could do the job...

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


Re: conditional for-statement

2009-08-25 Thread seb
On Aug 24, 12:05 am, Mel mwil...@the-wire.com wrote:
 seb wrote:
  On Aug 23, 6:18 pm, John Posner jjpos...@optimum.net wrote:
 [ ... ]
  How about using a generator expression instead of a list?

  for i in (x for x in range(10) if x  5):
  print i

  -John

  Indeed, but we could have the same syntax than for generators but
  directly in the for statement as in
  for variable in generator if condition:
      body

  Is there a special reason for not doing so ? A rejected PEP ?

 Well, the Zen of Python does say

 There should be one-- and preferably only one --obvious way to do it.

 Beyond that, I refer you to Gerald M. Weinberg's _The Psychology of Computer
 Programming_, specifically chapters 11 and 12, about Programming Languages,
 and their design.

 The proposal creates an case where one particular pair of syntactic
 constructs can be mooshed together.  OK for them, but everything else
 becomes an exception; what about

 while a==c if b != d:

 why not

 if b != d while a==c:


what would be the unambiguous meaning of any of these forms ?
they could be interesting but I do not understand them (yet!).


 or

 for a in range(7) if os.name == 'posix':

 It winds up burdening the programmers with remembering which constructs are
 and which are not mooshable.  Weinberg gave an example: FORTRAN had some
 stringent rules for what expressions were and were not allowed as array
 subscripts.  The result was that many programmers couldn't remember all the
 rules, and often avoided using legal forms, having forgotten they were
 legal.

indeed, the language features should stay as orthogonal as possible
(at least as a general rule)


 Maybe the line was already crossed when list comprehensions came into being,
 still, the damage is localized in a particular context: building a list.  It
 isn't out creating wild options in the program control flow at large.


indeed and it proved to be very useful  successful.
one cannot recommend to mix all features together as a general rule
but using common sense and practice, we can have some exceptions that
are definitely worth.

         Mel.- Hide quoted text -

 - Show quoted text -

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


Re: Web Services examples using raw xml?

2009-08-25 Thread Stefan Behnel
John Gordon wrote:
 Any suggestions?

Well, yes, see the link I posted.

http://effbot.org/zone/element-soap.htm

That might actually be the easiest way to get your stuff done, and it
avoids external dependencies (well, except for ElementTree, if you continue
to use Python = 2.4).

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


Re: Need help with Python scoping rules

2009-08-25 Thread John Posner

Diez said:


Classes are not scopes. 


So the above doesn't work because name resolution inside functions/methods
looks for local variables first, then for the *global* scope. There is no
class-scope-lookup.


But http://docs.python.org/tutorial/classes.html says, in Section 9.3 A 
First Look at Classes:


When a class definition is entered, a new namespace is created,
and used as the local scope — thus, all assignments to local variables
go into this new namespace. In particular, function definitions bind
the name of the new function here.


The following example confirms this:

class Spam(object):
clsvar_1 = 555
clsvar_2 = clsvar_1 + 222

def __init__(self):
print Spam instance initialized

sp = Spam()
print sp.clsvar_1, sp.clsvar_2

output:
Spam instance initialized
555 777


Does the OP (kj) have a legitimate gripe, though? I confess that I know 
nothing about Python's implementation -- I'm strictly a user. So it's 
just a suspicion of mine that
something special enables a recursive function definition to refer to 
the function's own name before the definition has been completed. It 
works at the module-namespace (i.e. global) level, and Diez's toy 
example shows that it works at function-namespace level:


   class Demo(object):

   def fact(n):
   def inner(n):
   if n  2:
   return 1
   else:
   return n * inner(n - 1)
   return inner(n)

   _classvar = fact(5)


So why can't it work at the class-namespace level, too?

(BTW, Diez, your toy example is another demonstration that there *is* a 
class-scope-lookup: the def statement binds the name fact in the 
class scope, and the assignment statement looks up the name fact in 
that scope.)


-John

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


Re: conditional for-statement

2009-08-25 Thread Rami Chowdhury

We could as consistenly explain that the syntax

for n in range(10) if n%3==0:
  body

means

for n in range(10):
  if n%3==0:
body

This syntax has also the benefit of avoiding an extra level of
indentation (the one for the if) that bears no real meaning on a
structural level.



I'm sorry, I don't see what you mean about avoiding the extra level of  
indentation? I can see a very real structural and logical distinction that  
the if-block makes, and IMO it's a good thing that that needs to be set  
apart.


On Tue, 25 Aug 2009 10:25:27 -0700, seb sdemen...@gmail.com wrote:



Tx Chris for your reply !

i am still a bit puzzle by the following.

I read in  
http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Generators


Python 3.0 unifies all collection types by introducing dict and set
comprehensions, similar to list comprehensions:


[ n*n for n in range(5) ] # regular list comprehension

[0, 1, 4, 9, 16]


{ n*n for n in range(5) } # set comprehension

{0, 1, 4, 16, 9}


{ n: n*n for n in range(5) } # dict comprehension

{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}

and we can add to this list the quite similar syntax for generator
expressions.

On all these loop constructs, one can consistenly add filtering on a
condition by adding an if ... after the for ... in ... part (and
it looks to me difficult to argue, for instance, that we should not
allow filtering for dict comprehesion because we could get the same
result by some other construct)

If the if ... part after the for ... in ... is so much used in all
these list/dict/set comprehensions and in the generator expressions,
it makes sense to me to have it also for the for as a statement
syntax :
[ n*n for n in range(10) if n%3 == 0]
{ n*n for n in range(10) if n%3 == 0}
{ n: n*n for n in range(10) if n%3 == 0}
( n*n for n in range(10) if n%3 == 0)
for n in range(10) if n%3 == 0:
  print n*n

In fact, we often see the list comprehension [ n*n for n in range(10)
if n%3 == 0] explained as being equivalent to
l = []
for n in range(10):
  if n%3 == 0:
l.append(n)

We could as consistenly explain that the syntax

for n in range(10) if n%3==0:
  body

means

for n in range(10):
  if n%3==0:
body

This syntax has also the benefit of avoiding an extra level of
indentation (the one for the if) that bears no real meaning on a
structural level.

Maybe a PEP could do the job...

Sébastien




--
Rami Chowdhury
Never attribute to malice that which can be attributed to stupidity --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: basic thread question

2009-08-25 Thread sturlamolden
On 25 Aug, 13:33, Piet van Oostrum p...@cs.uu.nl wrote:

 I have heard about that also, but is there a Python implementation that
 uses this? (Just curious, I am not using Windows.)

On Windows we have three different versions of Python 2.6:

* Python 2.6 for Win32/64 (from python.org) does not have os.fork.

* Python 2.6 for Cygwin has os.fork, but it is non-COW and sluggish.

* Python 2.6 for SUA has a fast os.fork with copy-on-write.

You get Python 2.6.2 for SUA prebuilt by Microsoft from 
http://www.interopsystems.com.

Using Python 2.6 for SUA is not without surprices: For example, the
process is not executed from the Win32 subsystem, hence the Windows
API is inaccessible. That means we cannot use native Windows GUI.
Instead we must run an X11 server on the Windows subsystem (e.g. X-
Win32), and use the Xlib SUA has installed. You can compare SUA to a
stripped down Linux distro, on which you have to build and install
most of the software you want to use. I do not recommend using Python
for SUA instead of Python for Windows unless you absolutely need a
fast os.fork or have a program that otherwise requires Unix. But for
running Unix apps on Windows, SUA is clearly superior to Cygwin.
Licencing is also better: Programs compiled against Cygwin libraries
are GPL (unless you buy a commercial license). Program compiled
against SUA libraries are not.



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


Re: Python for professsional Windows GUI apps?

2009-08-25 Thread Gilles Ganault
On Tue, 25 Aug 2009 13:24:39 +0200, Wolfgang Keller felip...@gmx.net
wrote:
The area of _desktop_ database application development indeed looks like a 
vast and very hostile desert in the Python landscape.

The only framework that seems to be worth trying is Dabo. Unfortunately 
there's little documentation, and that's mostly outdated.

There's also Kiwi, but that's even less well documented.

And GNU Enterprise essentially seems to be dead.

Combined with the comment above about issues with printing, it looks
like Python for GUI apps isn't a very good idea :-/

I'd be interested in checking out commercial applications written in
Python for the Windows OS, if there are any.

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


Re: Need help with Python scoping rules

2009-08-25 Thread 7stud
On Aug 25, 12:11 pm, John Posner jjpos...@optimum.net wrote:
 Diez said:



  Classes are not scopes.

  So the above doesn't work because name resolution inside functions/methods
  looks for local variables first, then for the *global* scope. There is no
  class-scope-lookup.

 Buthttp://docs.python.org/tutorial/classes.htmlsays, in Section 9.3 A
 First Look at Classes:

 When a class definition is entered, a new namespace is created,
 and used as the local scope — thus, all assignments to local variables
 go into this new namespace. In particular, function definitions bind
 the name of the new function here.

 The following example confirms this:

 class Spam(object):
 clsvar_1 = 555
 clsvar_2 = clsvar_1 + 222

 def __init__(self):
 print Spam instance initialized

 sp = Spam()
 print sp.clsvar_1, sp.clsvar_2

 output:
 Spam instance initialized
 555 777

 Does the OP (kj) have a legitimate gripe, though? I confess that I know


I guess a counter example would be something like this:

y = hello

class Demo(object):
y = goodbye

def __init__(self):
self.x = 10
print y

Demo()

--output:--
hello



 nothing about Python's implementation -- I'm strictly a user. So it's
 just a suspicion of mine that
 something special enables a recursive function definition to refer to
 the function's own name before the definition has been completed.


python ignores the names inside a function when it creates the
function.  This program will not produce an error:


def f():
print x

python parses the file and creates the function object and assigns the
function object to the variable f.  It's not until you execute the
function that python will raise an error.  The same thing happens with
the recursive function.


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


Re: Python for professsional Windows GUI apps?

2009-08-25 Thread David Boddie
On Tuesday 25 August 2009 13:24, Wolfgang Keller wrote:

 The area of _desktop_ database application development indeed looks like a
 vast and very hostile desert in the Python landscape.
 
 The only framework that seems to be worth trying is Dabo. Unfortunately
 there's little documentation, and that's mostly outdated.
 
 There's also Kiwi, but that's even less well documented.
 
 And GNU Enterprise essentially seems to be dead.

There's also Camelot, if that's the kind of thing you're after:

  http://www.conceptive.be/projects/camelot

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


Re: Putting together a larger matrix from smaller matrices

2009-08-25 Thread sturlamolden
On 25 Aug, 17:37, Matjaz Bezovnik mbezov...@freenet.si wrote:

 Scott, thank you very much for the snippet.

 It is exactly what I looked for; simple to read and obvious as to what
 it does even a month later to a non-pythonist!


Since you were talking about matrices, observe that numpy has a matrix
subclass of ndarray, which e.g. changes the meaning of the * operator
mean indicate matrix multiplication. Thus,

 import numpy as np
 np.eye(4)
array([[ 1.,  0.,  0.,  0.],
   [ 0.,  1.,  0.,  0.],
   [ 0.,  0.,  1.,  0.],
   [ 0.,  0.,  0.,  1.]])
 np.matrix(np.eye(4))
matrix([[ 1.,  0.,  0.,  0.],
[ 0.,  1.,  0.,  0.],
[ 0.,  0.,  1.,  0.],
[ 0.,  0.,  0.,  1.]])

 a = np.ones((4,4))
 a*a
array([[ 1.,  1.,  1.,  1.],
   [ 1.,  1.,  1.,  1.],
   [ 1.,  1.,  1.,  1.],
   [ 1.,  1.,  1.,  1.]])
 b = np.matrix(a)
 b*b
matrix([[ 4.,  4.,  4.,  4.],
[ 4.,  4.,  4.,  4.],
[ 4.,  4.,  4.,  4.],
[ 4.,  4.,  4.,  4.]])
 b**2
matrix([[ 4.,  4.,  4.,  4.],
[ 4.,  4.,  4.,  4.],
[ 4.,  4.,  4.,  4.],
[ 4.,  4.,  4.,  4.]])
 b**4
matrix([[ 64.,  64.,  64.,  64.],
[ 64.,  64.,  64.,  64.],
[ 64.,  64.,  64.,  64.],
[ 64.,  64.,  64.,  64.]])

In Matlab, you use .* vs. * and .^ vs. ^ to obtain the same effect. In
NumPy we use different classes for arrays and matrices.



Sturla Molden



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


Re: Putting together a larger matrix from smaller matrices

2009-08-25 Thread Robert Kern

On 2009-08-24 21:30 PM, Matjaz Bezovnik wrote:

Dear all,

I'm but a layman so do not take offence at this maybe over simple
question.

This is something which is done often in FEM methods, and the alike.

I have matrix A of 3x3 elements, and B, of the same number of
elements, 3x3.

What would be the most obvious way to assemble a matrix which:
a11 a12 a13
a21 a22 a23
a31 a32 a33+b11 b12 b13
   b21 b22 b23
   b31 b32 b33

(the missing elements = zero)

(you see the pattern - if there was a third matrix C, it would
connect to b33 on the main diagonal)


You will certainly want to use numpy for this and ask questions on the numpy 
mailing list.


  http://www.scipy.org/Mailing_Lists

I believe that someone recently posted a recipe for constructing such block 
diagonal arrays. I think it will be included in a future release of numpy.


--
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: os.popen output different from native shell output

2009-08-25 Thread nickname
On Aug 25, 6:16 am, Nobody nob...@nowhere.com wrote:
 On Tue, 25 Aug 2009 01:36:08 -0700, nickname wrote:
         I am a relative newbie to python, I am using os.popen to run an
  ls command. The output that I get using the read() function is
  different in look and feel from when I run the ls command natively
  from the shell (not via python).

 As others have pointed out, the default behaviour of ls is different if
 its output is a terminal.

  Is there an easy way to mirror the output. When python displays the
  output, how can it tell the bash shell that some of the entries are
  directories and they should appear blue on the bash shell, and that
  everything should not be appearing on 1 column only.

 You can get the terminal-style behaviour even when using a pipe with:

         ls -x --color

 But why are you reading this information into Python then writing it
 back out to the terminal?

 If you're planning on processing the output within Python, both the
 multi-column format and the escape sequences used for colour will make
 such processing awkward.

 If you want to enumerate the contents of a directory within Python, use
 os.listdir().

 If you want to generate coloured output, use the curses module, e.g.:

 #!/usr/bin/env python

 import sys
 import curses

 curses.setupterm()
 setaf = curses.tigetstr('setaf') or 
 setab = curses.tigetstr('setab') or 
 origp = curses.tigetstr('op') or 

 def fg(c):
     sys.stdout.write(curses.tparm(setaf, c))

 def bg(c):
     sys.stdout.write(curses.tparm(setab, c))

 def orig():
     sys.stdout.write(origp)

 # example
 bg(curses.COLOR_BLUE)
 fg(curses.COLOR_YELLOW)
 print hello, world
 orig()

wow guys! thanks for all the great leads! this is awesome!

The reason why I want to do this is because I am going to do a little
project. I will write a python script called ls which will log the
time and username and then will show the actual ls output. I want this
to be transparent and so want to throw the ls output (via python)
exactly as it will be in native shell execution.

I know there's history files I can look up, but I just am exploring my
own intermediate-logging-layer the functionality for which is executed
right before the actual command is executed.

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


Re: Python for professsional Windows GUI apps?

2009-08-25 Thread sturlamolden
On 25 Aug, 20:30, Gilles Ganault nos...@nospam.com wrote:

 Combined with the comment above about issues with printing, it looks
 like Python for GUI apps isn't a very good idea :-/

With pywin32, printing is the same as for any other Windows app (you
get MFC for Python).

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


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-25 Thread Mensanator
On Aug 25, 9:14 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Mon, 24 Aug 2009 18:01:38 -0700, Mensanator wrote:
  If you want your data file to have values entered in hex, or oct, or
  even unary (1=one, 11=two, 111=three, =four...) you can.

  Unary? I think you'll find that Standard Positional Number Systems are
  not defined for radix 1.

 Of course not. But unary isn't a positional number system. It's a tally
 system, like my example above shows. Roman numerals are another tally
 system. Like Roman numerals, the disadvantages of unary are that you
 can't represent negative numbers, zero, or fractions, and anything but
 addition and subtraction is difficult. But if you want to use it, perhaps
 out of a sense of sadism towards your users, it's easy:

 def int2unary(n):
     return '1'*n

 def unary2int(s):
     n = 0
     for c in s:
         if c == '1': n+=1
         else: raise ValueError('invalid unary string')
     return n

But without insignificant leading 0's, I fail to see the relevance
of unary to this discussion. And what would you call a tally system
of radix 2? Certainly not binary.


 --
 Steven

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


Re: your favorite debugging tool?

2009-08-25 Thread Robert Kern

On 2009-08-25 09:49 AM, Ben Finney wrote:

Esmailebo...@hotmail.com  writes:


Hi Ben,

Ben Finney wrote:


Whenever a simple output statement is too cumbersome for debugging, I
take it as a sign that the program is too cumbersome to follow.


I'll have to think about this .. though my gut says this is true :-)


Note that it's only a sign, *not* an ironclad guarantee. But it's the
right way to bet, IME.


re your other point about the interactive shell, I agree it's useful,
but to me still doesn't quite do what a full-fledged debugger can -
but perhaps that is a reflection of my skill with the shell at this
point.


This, on the other hand, I find even more consistent: if the code can't
be effectively inspected from the interactive interpreter, that's a sure
sign that its external interfaces are poor or its internal dependencies
too tightly coupled; or more likely both.


And a debugger is a great tool to help you figure out exactly why your code 
doesn't actually have the wonderful decoupling that you thought you designed 
into it so you can fix it. :-)


--
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: Python for professsional Windows GUI apps?

2009-08-25 Thread sturlamolden
On 25 Aug, 13:24, Wolfgang Keller felip...@gmx.net wrote:

 The area of _desktop_ database application development indeed looks like a 
 vast and very hostile desert in the Python landscape.

Yes, you don't have drag-and-drop database tools like MS Access or
FoxPro. You actually have to use a database API (such as pyodbc or
pymssql) with GUI (tkinter, wxPython, PyGTK, PyQt, MFC) manually. If
you need a framework for this, you should not be developing software
anyway.

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


Re: proposal: add setresuid() system call to python

2009-08-25 Thread travis
On Tue, Aug 25, 2009 at 03:03:12PM +0200, Hrvoje Niksic wrote:
 You should use ctypes.get_errno() instead of os.errno; sorry about that.
 
 Also, when raising OSError, you should set the 'errno' attribute to the
 appropriate code.

How does that compare to:

raise pythonapi.PyErr_SetFromErrno(py_object(OSError))

?
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


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


Re: Waiting for a subprocess to exit

2009-08-25 Thread Aahz
In article mailman.161.1250835519.2854.python-l...@python.org,
Miles Kaufmann  mile...@umich.edu wrote:

debacle[1]).  Leaving shell=3DFalse makes scripts more secure and =20
robust; besides, when I'm putting together a command and its =20
arguments, it's as convenient to build a list (['mycmd', 'myarg']) as =20=

it is a string (if not more so).

unless you want to use ~ on Mac or Unix.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

I support family values -- Addams family values --www.nancybuttons.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple IRC library

2009-08-25 Thread jason

On 2009-08-24 01:39:21 -0600, devaru ajoys...@gmail.com said:


Hi all,
I am new to Python language. I want to capture(either in database or a
file) the conversation in IRC.


Fed.


Please suggest me some simple IRC library or code snippet for this.


I have used the oyoyo library with success. It's pretty nice and has a 
framework for bots which you might be interested in looking at.


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

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


Re: Need help with Python scoping rules

2009-08-25 Thread John Posner

7stud said:

python ignores the names inside a function when it creates the
function.  This program will not produce an error:


def f():
print x

python parses the file and creates the function object and assigns the
function object to the variable f.  It's not until you execute the
function that python will raise an error.  The same thing happens with
the recursive function.
  



Thanks for that explanation. So in the OP's example:

Class Demo(object):
   def fact(n):
   if n  2:
   return 1
   else:
   return n * fact(n - 1)

   _classvar = fact(5)


... no failure occurs when fact(5) is invoked, because the lookup of 
fact in the local scope is a class-scope-lookup, which succeeds. The 
failure occurs on the first recursive invocation of fact() in the 
statement return n * fact(n - 1): the function-scope-lookup of fact 
fails, and then the interpreter falls back to a global-scope-lookup of 
fact, which also fails.


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


Re: Object Reference question

2009-08-25 Thread Aahz
In article mailman.164.1250837108.2854.python-l...@python.org,
Hendrik van Rooyen  hend...@microcorp.co.za wrote:
On Friday 21 August 2009 08:07:18 josef wrote:

 My main focus of this post is: How do I find and use object reference
 memory locations?

 a = [1,2,3,4]
 id(a)
8347088
  

Of course, that doesn't actually allow you to do anything...
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

I support family values -- Addams family values --www.nancybuttons.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-25 Thread Evan Driscoll
(If you don't want to read the following, note that you can answer my
question by writing a swap function.)

I want to make a context manager that will temporarily change the
value of a variable within the scope of a 'with' that uses it. This is
inspired by a C++ RAII object I've used in a few projects. Ideally,
what I want is something like the following:

x = 5
print x   # prints 5
with changed_value(x, 10):
print x  # prints 10
print x  # prints 5

This is similar to PEP 343's example 5 (Redirect stdout temporarily;
see http://www.python.org/dev/peps/pep-0343/), except that the
variable that I want to temporarily change isn't hard-coded in the
stdout_redirected function.

What I want to write is something like this:
@contextmanager
def changed_value(variable, temp_value):
old_value = variable
variable = temp_value
try:
yield None
finally:
variable = old_value
with maybe a check in 'finally' to make sure that the value hasn't
changed during the execution of the 'with'.

Of course this doesn't work since it only changes the binding of
'variable', not whatever was passed in, and I kind of doubt I can
stick a  and * in a couple places to make it do what I want. :-)

So my question is: is what I want possible to do in Python? How?

I think it might be possible to rig something up by passing in the
variable that i want to change as a *string* and looking up that
string in a dictionary somewhere, but I think what I need is the locals
() dictionary of the calling function, and I'm not sure how to get
that.

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


Re: your favorite debugging tool?

2009-08-25 Thread Robert Kern

On 2009-08-25 06:57 AM, Esmail wrote:

Michele Simionato wrote:

On Aug 22, 4:25 pm, Esmail ebo...@hotmail.com wrote:

Hi all,

What is your favorite tool to help you debug your
code?


The times when I would just use 'print' are long past. Nowadays I
spend lots of my time
with code written by others than myself. I use pdb all the time, and
now also ipdb
(ipdb is very cool if you are used to ipython).


Never heard of ipdb, I'll have to check it out.


It's not really a separate thing, just the pdb integration into the IPython 
interactive shell (which I highly recommend that you check out).


--
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: os.popen output different from native shell output

2009-08-25 Thread Thomas Guettler
In one of the first chapters of Advanced programming in the unix
environment (second edition) there is explained how a unix shell works.

You could write you own shell using python. This way the python
interpreter gets stared only once, and not for every call to ls.



Have fun,
  Thomas

nickname schrieb:
 wow guys! thanks for all the great leads! this is awesome!
 
 The reason why I want to do this is because I am going to do a little
 project. I will write a python script called ls which will log the
 time and username and then will show the actual ls output. I want this
 to be transparent and so want to throw the ls output (via python)
 exactly as it will be in native shell execution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: conditional for-statement

2009-08-25 Thread Falcolas
On Aug 25, 11:25 am, seb sdemen...@gmail.com wrote:
 We could as consistenly explain that the syntax

 for n in range(10) if n%3==0:
   body

 means

 for n in range(10):
   if n%3==0:
     body

 This syntax has also the benefit of avoiding an extra level of
 indentation (the one for the if) that bears no real meaning on a
 structural level.

 Maybe a PEP could do the job...

 Sébastien

So, what part of the statement does the if statement belong to;
particularly a concern considering this is valid python:

for x in y if y else z:
body

You can always do the following at the cost of 6 symbols, and the gain
of clarity:

for n in (x for x in y if y%3==0):
body

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


Python, qt, and lgpl

2009-08-25 Thread Terry Reedy


New LGPL Python bindings for Qt slither into the light

A new set of LGPL-licensed Python bindings for Qt has been announced. 
The project, which is backed by Nokia, will make it easier for 
commercial software developers to adopt Python and Qt for rapid 
application development.


http://arstechnica.com/open-source/news/2009/08/openbossa-announces-new-lgpl-python-bindings-for-qt.ars

Will be good news if realized.

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


Re: Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-25 Thread Emile van Sebille

On 8/25/2009 12:33 PM Evan Driscoll said...
snip

So my question is: is what I want possible to do in Python? 


Probably not with immutables (as in your example) -- maybe otherwise.

Emile

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


break unichr instead of fix ord?

2009-08-25 Thread rurpy
In Python 2.5 on Windows I could do [*1]:

  # Create a unicode character outside of the BMP.
   a = u'\U00010040'

  # On Windows it is represented as a surogate pair.
   len(a)
  2
   a[0],a[1]
  (u'\ud800', u'\udc40')

  # Create the same character with the unichr() function.
   a = unichr (65600)
   a[0],a[1]
  (u'\ud800', u'\udc40')

  # Although the unichr() function works fine, its
  # inverse, ord(), doesn't.
   ord (a)
  TypeError: ord() expected a character, but string of length 2 found

On Python 2.6, unichr() was fixed (using the word
loosely) so that it too now fails with characters outside
the BMP.

   a = unichr (65600)
  ValueError: unichr() arg not in range(0x1) (narrow Python build)

Why was this done rather than changing ord() to accept a
surrogate pair?

Does not this effectively make unichr() and ord() useless
on Windows for all but a subset of unicode characters?
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >