itools 0.13.6 released

2006-06-28 Thread J. David Ibáñez

itools is a Python library, it groups a number of packages into a single
meta-package for easier development and deployment:

  itools.catalogitools.i18n itools.uri
  itools.cmsitools.ical itools.web
  itools.csvitools.resourcesitools.workflow
  itools.datatypes  itools.rss  itools.xhtml
  itools.gettextitools.schemas  itools.xliff
  itools.handlers   itools.stl  itools.xml
  itools.html   itools.tmx

Changes:

  URI
  - Add the method replace to uri objects (this makes the method
Request.build_url from itools.web obsolete).

  Datatypes
  - Add a datatype for decimal numbers, by Hervé Cauwelier [#330].

  Handlers
  - Revert the lazy load patch.

  CSV
  - Now get_rows is a generator, by Hervé Cauwelier [#312].

  iCalendar
  - Various API improvements, by Nicolas Deram [#246].

  STL
  - Now stl:content coerces floats and decimals to strings, by
Hervé Cauwelier [#331].

  Web
  - Improve error logging, print the whole request headers.
  - Don't fail when the Cookie header is present with an empty
value.

  CMS
  - Now locks expire in one hour, by Hervé Cauwelier [#250].
  - Handler for Restructured Text files, by Hervé Cauwelier [#68].
  - Minor user interface improvements, by Hervé Cauwelier [#324,
#334, #340].


Resources
-

Download
http://download.ikaaro.org/itools/itools-0.13.6.tar.gz

Home
http://www.ikaaro.org/itools

Mailing list
http://mail.ikaaro.org/mailman/listinfo/itools

Bug Tracker
http://bugs.ikaaro.org


-- 
J. David Ibáñez
Itaapy http://www.itaapy.com Tel +33 (0)1 42 23 67 45
9 rue Darwin, 75018 Paris  Fax +33 (0)1 53 28 27 88 

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

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


global name is not defined - error - but for array

2006-06-28 Thread a
def fn():
 for i in range(l)
   global count
   count[i]= 

how do i declare count to be global if it is an array

subsequently i should access or define count as an array

error:
global name 'count' is not defined


thanks
-a

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


a class variable question

2006-06-28 Thread micklee74
hi
i have define a class like this

class A:
 _var1 = 0
 def __init__(self):
 ## some initialization
 self.func1()

 def func1():
  .
 _var1 = 1
 

 def getvarValue(self):
 return _var1
I wanted var1 to be global inside Class A.
when i do

AnInstance = A()
AnInstance.getvarValue()

it gives me 0. It should be 1.  What am i doing wrong here..thanks

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


Re: a class variable question

2006-06-28 Thread Pierre Quentel
In func1, _var1 = 1 creates a local variable _var1 (local to the
method), not an attribute of the instance. If you want an instance
attribute you must specify the reference to the instance by
self._var1 = 1 ; self must be passed as an attribute to func1

def func1(self):
self._var1 = 1

Similarly, in getvarValue :

def getvarValue(self):
return self._var1

Pierre

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


Re: a class variable question

2006-06-28 Thread Marco Wahl
Hi,

just some lines added below. hth

[EMAIL PROTECTED] wrote:
 hi
 i have define a class like this

 class A:
  _var1 = 0
  def __init__(self):
  ## some initialization
  self.func1()

  def func1():

self

   .
  _var1 = 1

A._var1 = 1

  

  def getvarValue(self):
  return _var1

 return A._var1

 I wanted var1 to be global inside Class A.
 when i do

 AnInstance = A()
 AnInstance.getvarValue()
 
 it gives me 0. It should be 1.  What am i doing wrong here..thanks

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


Re: a class variable question

2006-06-28 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:

 class A:
  _var1 = 0
  def __init__(self):
  ## some initialization
  self.func1()
 
  def func1():
   .
  _var1 = 1
  

You mean::

class A:
_var1 = 0

...

def func1(self):
A._var1 = 1

All you're doing in your example is setting a local variable inside the 
func1 method, which has no effect.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
  San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   Every path has its puddle.
-- (an English proverb)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a class variable question

2006-06-28 Thread Erik Max Francis
Pierre Quentel wrote:

 In func1, _var1 = 1 creates a local variable _var1 (local to the
 method), not an attribute of the instance. If you want an instance
 attribute you must specify the reference to the instance by
 self._var1 = 1 ; self must be passed as an attribute to func1
 
 def func1(self):
 self._var1 = 1

Note this only changes the attribute in the instance.  If he wants it to 
be changed for all other instances, he needs to change it in the class 
with:: A._var1 = 1

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
  San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   Every path has its puddle.
-- (an English proverb)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml.sax.xmlreader and expat

2006-06-28 Thread Stefan Behnel
Fredrik Lundh wrote:
 Gary Robinson wrote:
 
 We're using xml.sax.xmlreader in our app (http://www.goombah.com,
 which is written in Python).

 In Python 2.3.x, does that use the C-language expat under the hood?
 
 yes.
 
 The reason I'm asking is because we're wondering if we can speed up
 the parsing significantly.
 
 if you want speed, you don't really want any of the xml.sax or xml.dom
 stuff.  I'm a bit biased, but I'd recommend the iterparse interface to
 cElementTree

or to lxml (if you want to do more than just parsing):

http://cheeseshop.python.org/pypi/lxml/1.1alpha

Why?

http://effbot.org/zone/celementtree.htm#benchmarks
http://codespeak.net/lxml/performance.html#parsing-and-serialising

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


Re: Python database access

2006-06-28 Thread Steve Holden
Damjan wrote:
The odbc module is part of the Python Standard Library. 
 
 
 Since when?
 
 
Nope, it's a standard part of Mark Hammond's win32all extensions. As 
such it probably comes with ActivePython for Windows, which many people 
use as their standard distro.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: to py or not to py ?

2006-06-28 Thread Steve Holden
Serge Orlov wrote:
 On 6/27/06, Chandrashekhar kaushik [EMAIL PROTECTED] wrote:
[...]
also is it actually a good idea to write high perf applications in python ?
 
 
 Take a look at Mercurial http://www.selenic.com/mercurial/ sources.
 It's a high performance python application. Or watch Bryan
 O'Sullivan's Mercurial presentation
 http://video.google.com/videoplay?docid=-7724296011317502612 he
 talks briefly how they made it work fast.
 
 But writing high performance application in python requires
 self-discipline and attention to details, looking at the way you spell
 I think it will be a challenge ;)

This doesn't distinguish Python: are there any languages that you can 
write high-performance applications in *without* self-discipline and 
attention to details?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: [W2k, wxPython 2.6.1.0] - MDISashDemo bug?

2006-06-28 Thread Steve Holden
w.p. wrote:
 Steve Holden wrote:
 
 
Well done! Do you know how to feed this information on to the developers 
(probably Robin Dunn)? All such changes are valuable.

 
 
 Hmm... i dont know. wxpython.org - submit a patch or Report a bug ?
 
 w.p.

Either of those would do, since it's not a huge fix and so won't require 
a formal patch file.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: languages with full unicode support

2006-06-28 Thread Tim Roberts
Xah Lee [EMAIL PROTECTED] wrote:

Languages with Full Unicode Support

As far as i know, Java and JavaScript are languages with full, complete
unicode support. That is, they allow names to be defined using unicode.
(the JavaScript engine used by FireFox support this)

As far as i know, here's few other lang's status:

C ? No.

This is implementation-defined in C.  A compiler is allowed to accept
variable names with alphabetic Unicode characters outside of ASCII.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a class variable question

2006-06-28 Thread Pierre Quentel

Erik Max Francis wrote:
 Note this only changes the attribute in the instance.  If he wants it to
 be changed for all other instances, he needs to change it in the class
 with:: A._var1 = 1

Yes, but in the OP's code func1() is called by __init__ for every
instance - which in fact makes declaring _var1 as a class attribute
useless

Anyway, I find that changing the class attribute by calling a method on
an instance is a little confusing. I would rather set the class
attribute like this :

class A2:

 _var1 = 0

 def getvarValue(self):
 return self._var1

a = A2()
print a.getvarValue()
 0
A2._var1 = 0  # change class attribute
print a.getvarValue()
 1
b = A2()
print b.getvarValue()
 1

Or using a class method :

class A3:

_var1 = 0

@classmethod
def func1(cls):
cls._var1 = 1

def getvarValue(self):
return self._var1

a = A3()
print a.getvarValue()
 0
A3.func1() # change class attribute
print a.getvarValue()
 1
b = A3()
print b.getvarValue()
 1

Pierre

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


Re: to py or not to py ?

2006-06-28 Thread Chandrashekhar kaushik
okay so much for a few spelling errors and abbreviations used by me !!we are losing the main point !i had a look at mercurial . It deals with SCM . I am typically looking at an application thats to deal with geometry data ( tetras ) , 
process millions of them and may be process them repeatedly ( iterative ).It would basically involve client-server operations to first distribute dataover a computing network and then send requests to process the data
at the various nodes that contain the data. it is going to be multi-threaded. Carl , what are the problems that could arise with threading ??On 6/28/06, 
Steve Holden [EMAIL PROTECTED] wrote:
Serge Orlov wrote: On 6/27/06, Chandrashekhar kaushik [EMAIL PROTECTED] wrote:[...]also is it actually a good idea to write high perf applications in python ?
 Take a look at Mercurial http://www.selenic.com/mercurial/ sources. It's a high performance python application. Or watch Bryan O'Sullivan's Mercurial presentation
 http://video.google.com/videoplay?docid=-7724296011317502612 he talks briefly how they made it work fast. But writing high performance application in python requires
 self-discipline and attention to details, looking at the way you spell I think it will be a challenge ;)This doesn't distinguish Python: are there any languages that you canwrite high-performance applications in *without* self-discipline and
attention to details?regardsSteve--Steve Holden +44 150 684 7255+1 800 494 3119Holden Web LLC/Ltdhttp://www.holdenweb.comLove me, love my blog
http://holdenweb.blogspot.comRecent Ramblings http://del.icio.us/steve.holden--
http://mail.python.org/mailman/listinfo/python-list-- --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Immutability

2006-06-28 Thread Nick Maclaren

The way that I read it, Python allows only values (and hence types)
to be immutable, and not class members.  The nearest approach to the
latter is to use the name hiding conventions.

Is that correct?


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


documentation for the change of Python 2.5

2006-06-28 Thread bussiere
I've read thsi documentation n:
http://docs.python.org/dev/whatsnew/whatsnew25.html
is there a way to have it in a more printable form ?

Regards
Bussiere

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


Re: global name is not defined - error - but for array

2006-06-28 Thread Fredrik Lundh
a [EMAIL PROTECTED] wrote:

 def fn():
 for i in range(l)
   global count
   count[i]= 

 how do i declare count to be global if it is an array

a couple of notes:

1) global statements should be placed at the top of the function

2) objects don't appear out of nowhere; you need to initialize the count
list before you can assign stuff to it.  this is what causes the exception; the
global statement has nothing to do with that.

3) it's called list on Python, not array.

4) if you read the tutorial, you'll learn better ways to loop over lists, and
build new lists.  see the chapters An Informal Introduction to Python,
More Control Flow Tools, and Data Structures.

5) posting one copy of your question is enough; if you feel that you want
to try out different subject lines, do that for yourself, before posting your
message to the list.

6) this list isn't hosted by googlegroups, so cancelling a post in googlegroups
doesn't mean that other people won't see it.  there's a world outside google
too, you know...

/F 



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


Re: to py or not to py ?

2006-06-28 Thread Robert Kern
Chandrashekhar kaushik wrote:
 pyton does allow this using cPickle , but it bloats the data like 
 anythin !!!
 for example a class containing 2 integers which i expect will be 8 bytes 
 long ..
 cPickle.dumps returns a string thats 86 bytes wide  ( this is the 
 binary version protocol 1 )
 
 anyway to improve serialization ??

Use protocol 2. Also, since it looks like you will be dealing with homogeneous 
arrays of numerical data, you should think about using numpy to store that 
data. 
With protocol 2, cPickle only adds 129 bytes per array no matter the size.

   http://www.scipy.org/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


How to measure execution time of a program

2006-06-28 Thread Girish Sahani
Hi all,

  Can anyone tell me the simplest way to do it (some code snippet that
could be included in the program's main function) ??

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


Re: Immutability

2006-06-28 Thread Robert Kern
Nick Maclaren wrote:
 The way that I read it, Python allows only values (and hence types)
 to be immutable, and not class members.  The nearest approach to the
 latter is to use the name hiding conventions.
 
 Is that correct?

You can also make properties that don't allow writing.

class Foo(object):

 def __init__(self, bar):
 self._bar = bar

 @property
 def bar(self):
 return self._bar

-- 
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: How to measure execution time of a program

2006-06-28 Thread Fredrik Lundh
Girish Sahani wrote:

 Can anyone tell me the simplest way to do it (some code snippet that
 could be included in the program's main function) ??

simplest way:

t0 = time.time()
main()
print time.time() - t0, seconds

(assuming that you want to measure wall time, and that your program runs
for at least a tenth of second, or so.  for benchmarking of short code snippets,
see the timeit module)

/F 



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


Re: How to measure execution time of a program

2006-06-28 Thread Girish Sahani
Sorry for spamming again, but please also enlighten me with some way to
time a function i.e. to find out how much time each function takes for
execution in a big program.
 Hi all,

   Can anyone tell me the simplest way to do it (some code snippet that
 could be included in the program's main function) ??

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


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


Re: Problem with sets and Unicode strings

2006-06-28 Thread Laurent Pointal
Dennis Benzinger a écrit :
 No, byte strings contain characters which are at least 8-bit wide
 http://docs.python.org/ref/types.html. But I don't understand what
 Python is trying to decode and why the exception says something about
 the ASCII codec, because my file is encoded with UTF-8.

[addendum to others replies]

The file encoding directive is used by Python to convert uxxx strings
into unicode objects using right conversion rules when compiling the code.
When a string is written simply with xxx, its a 8 bits string with NO
encoding data associated. When these strings must be converted they are
considered to be using sys.getdefaultencoding() [generally ascii -
forced ascii in python 2.5]

So a short reply: the utf8 directive has no effect on 8 bits strings,
use unicode strings to manage correctly non-ascii texts.

A+

Laurent.

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


Re: Function to prune dictionary keys not working

2006-06-28 Thread Steve Holden
Girish Sahani wrote:
 hi ppl,
  Here is a simple function to remove those keys of a dictionary whose
 values are less than some specified value. But it isnt working. Please
 help.
 
Besides all the good advice you've been given about not expecting 
string/float comparisons to be meaningful, remember too that both your 
function's result and the dict's .keys() method return *lists*.

   [1, 2] == [2, 1]
False
  

Easiest would be to convert both lists to sets and use

 if set(prune(d,cp)) == set(d.keys()):

You could, instead, sort them before comparison, but that's only a win 
if you need them sorted elsewhere.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: to py or not to py ?

2006-06-28 Thread Robert Kern
Chandrashekhar kaushik wrote:
 okay
 so much for a few spelling errors and abbreviations used by me !!
 we are losing the main point !
 i had a look at mercurial . It deals with SCM . I am typically
 looking at an application thats to deal with geometry data ( tetras ) ,
 process millions of them and may be process them repeatedly ( iterative ).
 It would basically involve client-server operations to first distribute data
 over a computing network and then send requests to process the data
 at the various nodes that contain the data.

I do essentially the same thing (only with pickles of constructive solid 
geometry definitions).

 it is going to be multi-threaded.

... because?

 Carl , what are the problems that could arise with threading ??

An old, but still relevant overview is here:

   http://www.softpanorama.org/People/Ousterhout/Threads/index.shtml

A good event-driven framework for Python is Twisted. It's what I use for the 
program I mention above.

   http://twistedmatrix.com/trac/

-- 
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: error in ConfigParser

2006-06-28 Thread Steve Holden
pipehappy wrote:
 Hello everyone:
 
 I came across the module ConfigParser and can use it correctly.
 
 import ConfigParser
 fp = open('test.cfg','w+')
 config = ConfigParser.ConfigParser()
 config.readfp(fp)
 config.add_section('test')
 config.set('test', 'haha', 'hehe')
 print config.sections()
 config.write(fp)
 
 ['test']
 Traceback (most recent call last):
   File configparser.py, line 8, in ?
 config.write(fp)
   File C:\Python24\lib\ConfigParser.py, line 369, in write
 fp.write([%s]\n % section)
 IOError: (0, 'Error')
 
 I trace into the module and when executing the line fp.write([%s]\n
 % section), I find every parameter is correct: fp is still a open file
 object and section is 'test', I may miss something, but I just cannot
 figure it out. Can someone tell me what's going wrong here?
 
What is the exact intent of your code? Note that the w+ mode is 
documented as truncating the file, which means that your starting 
configuration will always be null. My first thoughts were therefore 
related to file position,

For what it's worth, however, note that on my system (Cygwin 2.4.3) this 
code only breaks the *second* time:

   import ConfigParser
   fp = open('test.cfg','w+')
   config = ConfigParser.ConfigParser()
   config.readfp(fp)
   config.add_section('test')
   config.set('test', 'haha', 'hehe')
   print config.sections()
['test']
   config.write(fp)
   ### should really have closed fp here?
   import ConfigParser
   fp = open('test.cfg','w+')
   config = ConfigParser.ConfigParser()
   config.readfp(fp)
   config.add_section('test')
Traceback (most recent call last):
   File stdin, line 1, in ?
   File /usr/lib/python2.4/ConfigParser.py, line 226, in add_section
 raise DuplicateSectionError(section)
ConfigParser.DuplicateSectionError: Section 'test' already exists
   config.set('test', 'haha', 'hehe')
   print config.sections()
['test']
   config.write(fp)
  
  

Adding a seel to the start of the file before the failing statement 
seems to fix the problem, so I guess my conjecture was right. Try

import ConfigParser
fp = open('test.cfg','w+')
config = ConfigParser.ConfigParser()
config.readfp(fp)
config.add_section('test')
config.set('test', 'haha', 'hehe')
print config.sections()
fp.seek(0)
config.write(fp)
fp.close()

But then fix that w+ if this is more than just a test app!

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Beginner question? Classes, variables, ...

2006-06-28 Thread Ángel Gutiérrez Rodríguez
The problem:

I have two classes:
 
class X:
  def __init__(self):
pass

class Y:
  def __init__(self):
self.a=1
self.b=X()

and I would like to make 'a' visible inside 'x'. Is there a way to refer to
the Y class from the X? To make things easier :), each class is in a
different file, so class X is imported. Or the only way I have is to
pass 'a' as a variable in each method call of 'b' ('a' can take different
values that affect to the behaviour of 'b').

Thanks in advance.
-- 
Ángel Gutiérrez Rodríguez - [EMAIL PROTECTED]
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Química Física y Analítica 
Universidad de Oviedo - c/Julián Clavería 8 33006 - Oviedo 
Asturias - Spain
E-mail: [EMAIL PROTECTED] Telf.: +34-985103687
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: a class variable question

2006-06-28 Thread Steve Holden
Erik Max Francis wrote:
[...]
 All you're doing in your example is setting a local variable inside the 
 func1 method, which has no effect.
 
I think EMF was thinking, but failed to write, outside the function at 
the end of that sentence ;-)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Immutability

2006-06-28 Thread Nick Maclaren

In article [EMAIL PROTECTED],
Robert Kern [EMAIL PROTECTED] writes:
| Nick Maclaren wrote:
|  The way that I read it, Python allows only values (and hence types)
|  to be immutable, and not class members.  The nearest approach to the
|  latter is to use the name hiding conventions.
|  
|  Is that correct?
| 
| You can also make properties that don't allow writing.
| 
| class Foo(object):
| 
|  def __init__(self, bar):
|  self._bar = bar
| 
|  @property
|  def bar(self):
|  return self._bar

Thanks very much.  And, what's more, I have even found its documentation!
Whatsnew2.2.  The 2.4.2 reference is, er, unhelpful.

One of Python's less-lovable attributes is the inscrutability of its
documentation :-(

But you knew that 


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


Re: global name is not defined - error - but for array

2006-06-28 Thread Steve Holden
a wrote:
 def fn():
  for i in range(l)
global count
count[i]= 
 
 how do i declare count to be global if it is an array
 
 subsequently i should access or define count as an array
 
 error:
 global name 'count' is not defined
 
The questions you are asking make it likely you would get better help on 
the Python-tutor list ([EMAIL PROTECTED], if memory serves me 
right). It would seem you are new not just to Python but also to 
programming, and that list is specifically for those who might find a 
little coaching helpful.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: How to measure execution time of a program

2006-06-28 Thread Pete Forman
Fredrik Lundh [EMAIL PROTECTED] writes:
  simplest way:
 
  t0 = time.time()

You can get better resolution by using time.clock() instead of
time.time().
-- 
Pete Forman-./\.-  Disclaimer: This post is originated
WesternGeco  -./\.-   by myself and does not represent
[EMAIL PROTECTED]-./\.-   opinion of Schlumberger, Baker
http://petef.port5.com   -./\.-   Hughes or their divisions.

Inviato da X-Privat.Org - Registrazione gratuita 
http://www.x-privat.org/join.php
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to measure execution time of a program

2006-06-28 Thread Fredrik Lundh
Pete Forman wrote:

  t0 = time.time()

 You can get better resolution by using time.clock() instead of
 time.time().

depends on the platform, and whether you want wall time or process time.

/F 



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


Re: Beginner question? Classes, variables, ...

2006-06-28 Thread Diez B. Roggisch
Ángel Gutiérrez Rodríguez wrote:

 The problem:
 
 I have two classes:
  
 class X:
   def __init__(self):
 pass
 
 class Y:
   def __init__(self):
 self.a=1
 self.b=X()
 
 and I would like to make 'a' visible inside 'x'. Is there a way to refer
 to the Y class from the X? To make things easier :), each class is in a
 different file, so class X is imported. Or the only way I have is to
 pass 'a' as a variable in each method call of 'b' ('a' can take different
 values that affect to the behaviour of 'b').

You mean the behavior of X here I guess - b is just a name, there isn't much
behavior in it.

Pass X the instance of Y:

class X:
  def __init__(self, my_y):
self.my_y

  def foo(self):
  print self.my_y.a

class Y:
  def __init__(self):
self.a=1
self.b=X(self)

Then in X you can work with whatever Y contains.

 

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

Re: Immutability

2006-06-28 Thread Georg Brandl
Nick Maclaren wrote:
 In article [EMAIL PROTECTED],
 Robert Kern [EMAIL PROTECTED] writes:
 | Nick Maclaren wrote:
 |  The way that I read it, Python allows only values (and hence types)
 |  to be immutable, and not class members.  The nearest approach to the
 |  latter is to use the name hiding conventions.
 |  
 |  Is that correct?
 | 
 | You can also make properties that don't allow writing.
 | 
 | class Foo(object):
 | 
 |  def __init__(self, bar):
 |  self._bar = bar
 | 
 |  @property
 |  def bar(self):
 |  return self._bar
 
 Thanks very much.  And, what's more, I have even found its documentation!
 Whatsnew2.2.  The 2.4.2 reference is, er, unhelpful.

Is it?

http://docs.python.org/lib/built-in-funcs.html

documents property quite well.

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


Re: Questions about OSS projects.

2006-06-28 Thread Daniel Dittmar
bio_enthusiast wrote:
 I was wondering how to go about starting an open source project for
 doing routine biological problems? There is a plethora of scripts and
 a fairly large biopython project to back up anyone who tried, these
 however cater to the bioinformatics community and it loses the vast
 majority of the wet-lab scientists. How can someone who is used to
 writing small scripts and doing wet-lab work contribute to the open
 source community? Starting software projects seems to be the domain of
 people with much more experience and skill but there are some serious
 needs by people who do not have the skills to upkeep any software
 based project.
 

If you've written a few small scripts that might be of use to others and 
that you assume that there are others who do the same, you might start 
with a wiki or something like the Python Cookbook 
(http://aspn.activestate.com/ASPN/Python/Cookbook/), but geared toward 
labs and biology.

If this gains any traction (that is if you get additional code snippets, 
people are commenting etc.), after a while, it might be useful to look 
at the material and see if there is enough code that warrants a library. 
This does not mean to simply package all the scripts into one package, 
but to see if there are any common tasks among the scripts to 'refactor' 
them into a library.

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


Re: How to disable tk inclusion in py build

2006-06-28 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 since _tkinter.so is only built if it's found by the setup script,
 and if built, it's only loaded if you actually use it, why bother
 disabling it ?

 I don't want it to build tk into the py dist, even if it finds it on
 the build box - its not needed in the deployment. Keeping it
 out will make the deployed pkg leaner.

so don't deploy it.

if you want a lean package, you should use a deployment script that copies
the stuff you need; relying on the build process isn't very reliable (and means
more work when it's time to upgrade to a newer Python).

/F 



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


Re: Beginner question? Classes, variables, ...

2006-06-28 Thread Diez B. Roggisch
Dennis Lee Bieber wrote:

 On Wed, 28 Jun 2006 10:35:10 +0200, Diez B. Roggisch
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:
 
 class X:
   def __init__(self, my_y):
 self.my_y
 self.my_y = my_y

*argl*

Thanks :)

No tea so far...

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


Re: How to measure execution time of a program

2006-06-28 Thread Wolfram Kraus
On 28.06.2006 10:01, Girish Sahani wrote:
 Sorry for spamming again, but please also enlighten me with some way to
 time a function i.e. to find out how much time each function takes for
 execution in a big program.
 Hi all,

   Can anyone tell me the simplest way to do it (some code snippet that
 could be included in the program's main function) ??

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

 

Use the Python profiler:

http://docs.python.org/lib/profile.html

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


Re: Help Installing smartypants.py

2006-06-28 Thread Paul McGuire
Scott McCracken [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I just got Python 2.4 setup locally (Mac OS X) and am trying to extend
 it by installing both the markdown and smartypants plugins. Ultimately
 I'd like to be able use both in a custom CMS I'm building with Django.

 Installing markdown was a snap by following the instructions at
 http://www.freewisdom.org/projects/python-markdown/, but I cannot
 figure out what to do for smartypants. I have found:
 http://web.chad.org/projects/smartypants.py/, but cannot make any sense
 of it. After reading Jeff Croft's wonderful site, I know it's possible
 - and when I asked him in one of his posts he gave me the following
 response:

  As for SmartyPants -- there is a Python port. I've found it to be not
quite as perfect as the original   Perl version, but it basically works.
Just Google for it. You'd install it the same way (drop smartypants.py in
your Python path).

 Does anyone know what port he's talking about? Is it the smartypants.py
 file referenced above? And if so, any quick tips for a clueless UNIX
 user on how to drop smartypants.py in my Python path? Many thanks in
 advance!


Go to the bottom of http://web.chad.org/projects/smartypants.py/ and you
will see a number of links to various versions of this .py module.  If you
right-click/Save As to smartypants.py, and then save this file to a
directory in your Pythonpath, then this will make this module accessible to
you.

-- Paul


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


Re: Immutability

2006-06-28 Thread Nick Maclaren

In article [EMAIL PROTECTED],
Georg Brandl [EMAIL PROTECTED] writes:
|  
|  Thanks very much.  And, what's more, I have even found its documentation!
|  Whatsnew2.2.  The 2.4.2 reference is, er, unhelpful.
| 
| Is it?
| 
| http://docs.python.org/lib/built-in-funcs.html
| 
| documents property quite well.

Sigh.  No.  It's terrible.  What it documents is the use of the property
FUNCTION.  It does not document what properties ARE, and how they interact
with the rest of the language.  Until you know that, it is so ambiguous
as to be almost totally useless - and it is THAT information that needs to
be in the reference manual, but is only in whatsnew2.2.


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


Re: documentation for the change of Python 2.5

2006-06-28 Thread Serge Orlov
On 6/28/06, bussiere [EMAIL PROTECTED] wrote:
 I've read thsi documentation n:
 http://docs.python.org/dev/whatsnew/whatsnew25.html
 is there a way to have it in a more printable form ?

Yep: http://www.python.org/ftp/python/doc/2.5b1/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-28 Thread Joachim Durchholz
Paul Rubin schrieb:
 It starts to look like sufficiently powerful static type systems are
 confusing enough, that programming with them is at least as bug-prone
 as imperative programming in dynamically typed languages.  The static
 type checker can spot type mismatches at compile time, but the
 types themselves are easier and easier to get wrong.

That's where type inference comes into play. Usually you don't write the 
types, the compiler infers them for you, so you don't get them wrong.

Occasionally, you still write down the types, if only for documentation 
purposes (the general advice is: do the type annotations for external 
interfaces, but not internally).

BTW if you get a type wrong, you'll be told by the compiler, so this is 
still less evil than bugs in the code that pop up during testing (and 
*far* less evil than bugs that pop up after roll-out).
And the general consensus among FPL programmers is that you get the hang 
of it fairly quickly (one poster mentioned two to three months - this 
doesn't seem to be slower than learning to interpret synax error 
messages, so it's OK considering it's an entirely new kind of diagnostics).

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


Re: languages with full unicode support

2006-06-28 Thread Joachim Durchholz
Tim Roberts schrieb:
 Xah Lee [EMAIL PROTECTED] wrote:
 C ? No.
 
 This is implementation-defined in C.  A compiler is allowed to accept
 variable names with alphabetic Unicode characters outside of ASCII.

Hmm... that could would be nonportable, so C support for Unicode is 
half-baked at best.

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


Re: What is Expressiveness in a Computer Language [correction]

2006-06-28 Thread Andreas Rossberg
David Hopwood wrote:

(defun blackhole (argument)
 (declare (ignore argument))
 #'blackhole)

 I believe this example requires recursive types. It can also be expressed
 in a gradual typing system, but possibly only using an unknown ('?') type.
 
 ISTR that O'Caml at one point (before version 1.06) supported general
 recursive types, although I don't know whether it would have supported
 this particular example.

No problem at all. It still is possible today if you really want:

   ~/ ocaml -rectypes
 Objective Caml version 3.08.3

   # let rec blackhole x = blackhole;;
   val blackhole : 'b - 'a as 'a = fun

The problem is, though, that almost everything can be typed once you 
have unrestricted recursive types (e.g. missing arguments etc), and 
consequently many actual errors remain unflagged (which clearly shows 
that typing is not only about potential value class mismatches). 
Moreover, there are very few practical uses of such a feature, and they 
can always be coded easily with recursive datatypes.

It is a pragmatic decision born from experience that you simply do *not 
want* to have this, even though you easily could. E.g. for OCaml, 
unrestricted recursive typing was removed as default because of frequent 
user complaints.

Which is why this actually is a very bad example to chose for dynamic 
typing advocacy... ;-)

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


Re: Questions about OSS projects.

2006-06-28 Thread Paul McGuire
Daniel Dittmar [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 If you've written a few small scripts that might be of use to others and
 that you assume that there are others who do the same, you might start
 with a wiki or something like the Python Cookbook
 (http://aspn.activestate.com/ASPN/Python/Cookbook/), but geared toward
 labs and biology.

I would suggest going the wiki route - wikispaces.com makes this very easy,
and free if you don't mind ads on your wikipages.  Could be a
low-cost/low-effort way to get started.

-- Paul


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


Re: Immutability

2006-06-28 Thread Diez B. Roggisch
 Sigh.  No.  It's terrible.  What it documents is the use of the property
 FUNCTION.  It does not document what properties ARE, and how they interact
 with the rest of the language.  Until you know that, it is so ambiguous
 as to be almost totally useless - and it is THAT information that needs to
 be in the reference manual, but is only in whatsnew2.2.

I have to second that - I found myself reading through What's new from
various versions to find that specific feature. It would be at least good
to see all of them grouped together to make an easier read. Still, that is
not optimal.

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


Re: [Pyrex] pyrex functions to replace a method (Re: replace a method in class: how?)

2006-06-28 Thread Bruno Desthuilliers
Greg Ewing wrote:
 Brian Blais wrote:
 
 I have found a very similar problem trying to replace a method using a
 function defined in pyrex.
 
 
 Functions defined in Pyrex are C-implemented functions,
 which don't trigger the method binding magic when you
 access them through a class. The same thing happens if
 you try to use a built-in function as a method.
 
 What *should* work is to define the method inside a
 class in Pyrex (plain class, not extension type) and
 extract it out of the class's __dict__. That's because
 Pyrex pre-wraps a function defined in a class in an
 unbound method object before putting it in the class.

Or write the needed descriptor and wrap the function in (QD, needs a
lot of improvements):

def CFuncWrapper(func, instance):
def _wrappedCFunc(*args, **kw):
return func(instance, *args, **kw)
return _wrappedCFunc

class CFuncMethodType(object):
def __init__(self, func):
self.func = func

def __get__(self, instance, cls=None):
if instance:
return CFuncWrapper(self.func, instance)
else:
assert(cls is not None)
return self.func

 class Foo(object): pass
...
 Foo.isa = CFuncMethodType(isinstance)
 Foo.isa(Foo(), Foo)
True
 f.isa(list)
False
 f.isa(Foo)
True



-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: global name is not defined - error

2006-06-28 Thread Bruno Desthuilliers
a wrote:
 What I want
 ---
 I want to create a list of items from a function operating on an array
 of strings

def func(s):
  return s.upper()

arrayOfStrings = ['bicycle', 'repair', 'man']

print solution 1: with map()
print map(func, arrayOfStrings)
print solution 2: with list comprehension
print [func(s) for s in arrayOfStrings]


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do i make an array global

2006-06-28 Thread Bruno Desthuilliers
a wrote:
 def fn():
  for i in range(l)

l is not defined - you should have an error here.

global count
count[i]= 
 
 how do i declare count to be global if it is an array

Just like it was an integer

 subsequently i should access or define count as an array

You need to define count before.

 error:
 global name 'count' is not defined

He...

*but*
You probably should not do that anyway. Globals are *evil*. And
functions modifying globals is the worst possible thing. There are very
few chances you *need* a global here.

Also, and FWIW:
- Python has lists, not arrays (there's an array type in some numerical
package, but that's another beast)
- 'l' is a very bad name
- 'count' is a bad name for a list - 'counts' would be better (when I
see the name 'count', I think of an integer)



-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a class variable question

2006-06-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
 hi
 i have define a class like this
 
# class A:
  class A(object):
  _var1 = 0
  def __init__(self):
  ## some initialization
  self.func1()
 
#  def func1():
   def func1(self):
   .
#  _var1 = 1
   self.__class__._var1 = 1
# or if func1() does'nt use any instance attributes:
#  @classmethod
#  def func1(cls):
#   
#   cls._var1 = 1

  def getvarValue(self):
#  return _var1
   return self.__class__._var1

 I wanted var1 to be global inside Class A.

The name is class attribute.



-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Immutability

2006-06-28 Thread Bruno Desthuilliers
Nick Maclaren wrote:
 The way that I read it, Python allows only values (and hence types)
 to be immutable,

I don't understand this sentence. Some types are immutable, some are
not. This has nothing to do with values (FWIW, everything in Python is
an object, there's no 'primitive type' vs 'object type' distinction)

 and not class members. 

If an attribute is of an immutable type, it will still be immutable.

If what you want is 'read-only' attributes, then use properties:

class MyClass(object):
  def __init__(self, name):
self._name = name
  name = property(fget=lambda self : self._name)

 m = MyClass('parrot')
 m.name
'parrot'
 m.name = toto
Traceback (most recent call last):
  File stdin, line 1, in ?
AttributeError: can't set attribute


 The nearest approach to the
 latter is to use the name hiding conventions.

naming conventions are used to denote what's API and what's
implementation. But this won't make an attribute read-only. If you want
an attribute to be part of the API *but* read-only, use the solution above.

HTH
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Immutability

2006-06-28 Thread Sion Arrowsmith
Nick Maclaren [EMAIL PROTECTED] wrote:
Georg Brandl [EMAIL PROTECTED] writes:
| [ attributions lost ]
|  Thanks very much.  And, what's more, I have even found its documentation!
|  Whatsnew2.2.  The 2.4.2 reference is, er, unhelpful.
| Is it?
| http://docs.python.org/lib/built-in-funcs.html
| documents property quite well.
Sigh.  No.  It's terrible.  What it documents is the use of the property
FUNCTION.  It does not document what properties ARE, and how they interact
with the rest of the language.  Until you know that, it is so ambiguous
as to be almost totally useless - and it is THAT information that needs to
be in the reference manual, but is only in whatsnew2.2.

Actually, there's an almost throw-away mention in
http://docs.python.org/ref/descriptor-invocation.html
which gives you what you need (although not, I have to say, in an
easily digestible form).

What I've not seen documented anywhere is the:
@property
def fset(self, value):
...
idiom. It's not obvious from the documentation of the property
function that it can be used as a decorator like this. (cf.
classmethod and staticmethod.)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [Pyrex] pyrex functions to replace a method (Re: replace a method in class: how?)

2006-06-28 Thread Brian Blais
Greg Ewing wrote:
 Brian Blais wrote:
 I have found a very similar problem trying to replace a method using a 
 function defined in pyrex.
 
 
 What *should* work is to define the method inside a
 class in Pyrex (plain class, not extension type) and
 extract it out of the class's __dict__. That's because
 Pyrex pre-wraps a function defined in a class in an
 unbound method object before putting it in the class.
 

So I tried:

#-

#module_pyrex.pyx

class update_funcs:

 def pyrex_update_within_class(self,val):
 print pyrex module within class,val


#-

#(adding to test_replace_method.py)

This.update4=module_pyrex.update_funcs.__dict__['pyrex_update_within_class']

t.update4('pyrex within class') # doesn't work

#-

and get:

TypeError: unbound method pyrex_update_within_class() must be called with 
update_funcs instance as first argument (got str instance instead)


did I do this wrong?


thanks,


bb






-- 
-

  [EMAIL PROTECTED]
  http://web.bryant.edu/~bblais
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: languages with full unicode support

2006-06-28 Thread David Hopwood
Tim Roberts wrote:
 Xah Lee [EMAIL PROTECTED] wrote:
 
Languages with Full Unicode Support

As far as i know, Java and JavaScript are languages with full, complete
unicode support. That is, they allow names to be defined using unicode.
(the JavaScript engine used by FireFox support this)

As far as i know, here's few other lang's status:

C ? No.
 
 This is implementation-defined in C.  A compiler is allowed to accept
 variable names with alphabetic Unicode characters outside of ASCII.

It is not implementation-defined in C99 whether Unicode characters are
accepted; only how they are encoded directly in the source multibyte character
set.

Characters escaped using \u or \U00HH (H is a hex digit), and that
are in the sets of characters defined by Unicode for identifiers, are required
to be supported, and should be mangled in some consistent way by a platform's
linker. There are Unicode text editors which encode/decode \u and \U on the fly,
so you can treat this essentially like a Unicode transformation format (it
would have been nicer to require support for UTF-8, but never mind).


C99 6.4.2.1:

# 3 Each universal character name in an identifier shall designate a character
#   whose encoding in ISO/IEC 10646 falls into one of the ranges specified in
#   annex D. 59) The initial character shall not be a universal character name
#   designating a digit. An implementation may allow multibyte characters that
#   are not part of the basic source character set to appear in identifiers;
#   which characters and their correspondence to universal character names is
#   implementation-defined.
#
# 59) On systems in which linkers cannot accept extended characters, an encoding
# of the universal character name may be used in forming valid external
# identifiers. For example, some otherwise unused character or sequence of
# characters may be used to encode the \u in a universal character name.
# Extended characters may produce a long external identifier.

-- 
David Hopwood [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-28 Thread David Hopwood
Paul Rubin wrote:
 David Hopwood [EMAIL PROTECTED] writes:
 
Note that I'm not claiming that you can check any desirable property of
a program (that would contradict Rice's Theorem), only that you can
express any dynamically typed program in a statically typed language --
with static checks where possible and dynamic checks where necessary.
 
 It starts to look like sufficiently powerful static type systems are
 confusing enough, that programming with them is at least as bug-prone
 as imperative programming in dynamically typed languages.  The static
 type checker can spot type mismatches at compile time, but the
 types themselves are easier and easier to get wrong.

My assertion above does not depend on having a sufficiently powerful static
type system to express a given dynamically typed program. It is true for
static type systems that are not particularly complicated, and suffice to
express all dynamically typed programs.

I disagree with your implication that in general, static type systems for
practical languages are getting too confusing, but that's a separate issue.
(Obviously one can find type systems in research proposals that are too
confusing as they stand.)

-- 
David Hopwood [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Immutability

2006-06-28 Thread Steve Holden
Georg Brandl wrote:
 Nick Maclaren wrote:
 
In article [EMAIL PROTECTED],
Robert Kern [EMAIL PROTECTED] writes:
| Nick Maclaren wrote:
|  The way that I read it, Python allows only values (and hence types)
|  to be immutable, and not class members.  The nearest approach to the
|  latter is to use the name hiding conventions.
|  
|  Is that correct?
| 
| You can also make properties that don't allow writing.
| 
| class Foo(object):
| 
|  def __init__(self, bar):
|  self._bar = bar
| 
|  @property
|  def bar(self):
|  return self._bar

Thanks very much.  And, what's more, I have even found its documentation!
Whatsnew2.2.  The 2.4.2 reference is, er, unhelpful.
 
 
 Is it?
 
 http://docs.python.org/lib/built-in-funcs.html
 
 documents property quite well.
 
I can't really agree that quite good documentation doesn't refer to 
the use of property as a decorator. It's obvious that a ncessary upgrade 
to the docs didn't happen (and we can all understand why, I am sure).

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Immutability

2006-06-28 Thread Gerard Flanagan

Nick Maclaren wrote:
 In article [EMAIL PROTECTED],
 Georg Brandl [EMAIL PROTECTED] writes:
 | 
 |  Thanks very much.  And, what's more, I have even found its documentation!
 |  Whatsnew2.2.  The 2.4.2 reference is, er, unhelpful.
 |
 | Is it?
 |
 | http://docs.python.org/lib/built-in-funcs.html
 |
 | documents property quite well.

 Sigh.  No.  It's terrible.  What it documents is the use of the property
 FUNCTION.  It does not document what properties ARE, and how they interact
 with the rest of the language.  Until you know that, it is so ambiguous
 as to be almost totally useless - and it is THAT information that needs to
 be in the reference manual, but is only in whatsnew2.2.



There are (unofficial) documentation wikis here:

pytut.infogami.com
pyref.infogami.com
pyfaq.infogami.com

You might like to consider adding the information you perceive to be
lacking.

All the best.

Gerard

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


Re: global name is not defined - error

2006-06-28 Thread a
i changed it to append and it started working but once in a while
i m getting
l_code.append( len(d_list_code[i]['entries']) )
IndexError: list index out of range

but it is not permanent if i refresh, it goes away!
Marco Wahl wrote:
 a [EMAIL PROTECTED] writes:

  What I want
  ---
  I want to create a list of items from a function operating on an array
  of strings

 Ok.

  What I did
  -
  list=[s0,s1,s2]
  l=len(list)
for i in range(l):
d_list[i]=f.do(list[i])
print d_list[i]

 Aha!

  Error:
  --
  global name 'd_list' is not defined
  Pythonc:\test.py in newClass, line 30

 Just as the error message tells: 'd_list' is not
 defined which is an error.

 Try

 list=[s0,s1,s2]
 d_list = []
 l=len(list)
 for i in range(l):
 #   d_list[i]=f.do(list[i])
 d_list.append(f.do(list[i]))
 print d_list[i]

 This is just one suggestion there may be more elegant
 ways.  Have you heard about list comprehension?
 
 
 HTH

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


Re: Immutability

2006-06-28 Thread Fredrik Lundh
Sion Arrowsmith wrote:

 What I've not seen documented anywhere is the:
@property
def fset(self, value):
...
 idiom. It's not obvious from the documentation of the property
 function that it can be used as a decorator like this.

probably because it cannot be used in that way: the property function
takes the *getter* as its first argument, so you can only use this for read-
only properties...

/F 



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


Re: languages with full unicode support

2006-06-28 Thread Chris Uppal
Joachim Durchholz wrote:

  This is implementation-defined in C.  A compiler is allowed to accept
  variable names with alphabetic Unicode characters outside of ASCII.

 Hmm... that could would be nonportable, so C support for Unicode is
 half-baked at best.

Since the interpretation of characters which are yet to be added to
Unicode is undefined (will they be digits, letters, operators, symbol,
punctuation ?), there doesn't seem to be any sane way that a language could
allow an unrestricted choice of Unicode in identifiers.  Hence, it must define
a specific allowed sub-set.  C certainly defines an allowed subset of Unicode
characters -- so I don't think you could call its Unicode support half-baked
(not in that respect, anyway).  A case -- not entirely convincing, IMO -- could
be made that it would be better to allow a wider range of characters.

And no, I don't think Java's approach -- where there /is no defined set of
allowed identifier characters/ -- makes any sense at all :-(

-- chris




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


Re: Beginner question? Classes, variables, ...

2006-06-28 Thread Ángel Gutiérrez Rodríguez
That wa sneat! Thanks!

-- 
Ángel Gutiérrez Rodríguez - [EMAIL PROTECTED]
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Química Física y Analítica 
Universidad de Oviedo - c/Julián Clavería 8 33006 - Oviedo 
Asturias - Spain
E-mail: [EMAIL PROTECTED] Telf.: +34-985103687
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [Pyrex] pyrex functions to replace a method (Re: replace a method in class: how?)

2006-06-28 Thread Stefan Behnel
Hi Brian,

Brian Blais wrote:
 import module_py   # import a function from a python module
 import module_pyrex # import a function from a pyrex extension module
 
 class This(object):
 
  def update1(self,val):
  print val
 
  def update2(self,val):
  print 2,val
 
  def update3(self,val):
  print 3,val
 
 def local_update(obj,val):
 
  print local,val
 
 
 This.update1=local_update  # replace the method from a local function
 This.update2=module_py.python_update  # replace the method from a python 
 module
 This.update3=module_pyrex.pyrex_update  # replace the method from a pyrex 
 module
 
 t=This()
 
 t.update1('local')  # works fine
 t.update2('python') # works fine
 t.update3('pyrex')  # gives a typeerror function takes exactly 2 arguments (1 
 given)
 #-
 
 #module_py.py
 
 def python_update(self,val):
  print python module,val
 #-
 
 #module_pyrex.pyx
 
 def pyrex_update(self,val):
  print pyrex module,val

What is the 'self' for? After all, you are sticking a /function/ into the
object, not a /method/. Your function will not receive a 'self' argument
automatically as it is stuck into the instance and not part of the class.

Stefan

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


Re: [Pyrex] pyrex functions to replace a method (Re: replace a method in class: how?)

2006-06-28 Thread Stefan Behnel


Brian Blais wrote:
 Greg Ewing wrote:
 Brian Blais wrote:
 I have found a very similar problem trying to replace a method using a 
 function defined in pyrex.

 What *should* work is to define the method inside a
 class in Pyrex (plain class, not extension type) and
 extract it out of the class's __dict__. That's because
 Pyrex pre-wraps a function defined in a class in an
 unbound method object before putting it in the class.

 
 So I tried:
 
 #-
 
 #module_pyrex.pyx
 
 class update_funcs:
 
  def pyrex_update_within_class(self,val):
  print pyrex module within class,val
 
 
 #-
 
 #(adding to test_replace_method.py)
 
 This.update4=module_pyrex.update_funcs.__dict__['pyrex_update_within_class']
 
 t.update4('pyrex within class') # doesn't work
 
 #-
 
 and get:
 
 TypeError: unbound method pyrex_update_within_class() must be called with 
 update_funcs instance as first argument (got str instance instead)
 
 did I do this wrong?

Yes. :)

What you got was an unbound method. You can't call unbound methods without
specifying the object you want to call them on (i.e. the 'self' argument).

http://docs.python.org/tut/node11.html#SECTION001134

When you're using 'plain classes', you can do with them whatever you do in
standard Python, so replacing a method is just done with an attribute 
assignment.

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


Re: to py or not to py ?

2006-06-28 Thread Chandrashekhar kaushik
 it is going to be multi-threaded. ... because?one thread listens for incoming requests . as soon as a request arrives ( a connection is made ) the thread verifies the request and starts another thread where the request is processed ( typically some algorithm is run on the data ).The first thread immediately goes back to listening for new connections. 
On 6/28/06, Robert Kern [EMAIL PROTECTED] wrote:
Chandrashekhar kaushik wrote: okay so much for a few spelling errors and abbreviations used by me !! we are losing the main point ! i had a look at mercurial . It deals with SCM . I am typically
 looking at an application thats to deal with geometry data ( tetras ) , process millions of them and may be process them repeatedly ( iterative ). It would basically involve client-server operations to first distribute data
 over a computing network and then send requests to process the data at the various nodes that contain the data.I do essentially the same thing (only with pickles of constructive solidgeometry definitions).
 it is going to be multi-threaded because? Carl , what are the problems that could arise with threading ??An old, but still relevant overview is here: 
http://www.softpanorama.org/People/Ousterhout/Threads/index.shtmlA good event-driven framework for Python is Twisted. It's what I use for theprogram I mention above. 
http://twistedmatrix.com/trac/--Robert KernI have come to believe that the whole world is an enigma, a harmless enigmathat 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
-- --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: What is Expressiveness in a Computer Language

2006-06-28 Thread Pascal Costanza
David Hopwood wrote:
 Pascal Costanza wrote:
 David Hopwood wrote:
 Marshall wrote:

 The real question is, are there some programs that we
 can't write *at all* in a statically typed language, because
 they'll *never* be typable?
 In a statically typed language that has a dynamic type, all
 dynamically typed programs are straightforwardly expressible.
 What about programs where the types change at runtime?
 
 Staged compilation is perfectly compatible with static typing.
 Static typing only requires that it be possible to prove absence
 of some category of type errors when the types are known; it
 does not require that all types are known before the first-stage
 program is run.

Can you change the types of the program that is already running, or are 
the levels strictly separated?

 There are, however, staged compilation systems that guarantee that
 the generated program will be typeable if the first-stage program
 is.

...and I guess that this reduces again the kinds of things you can express.

 (It's clear that to compare the expressiveness of statically and
 dynamically typed languages, the languages must be comparable in
 other respects than their type system. Staged compilation is the
 equivalent feature to 'eval'.)

If it is equivalent to eval (i.e., executed at runtime), and the static 
type checker that is part of eval yields a type error, then you still 
get a type error at runtime!


Pascal

-- 
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQLdb not updating rows

2006-06-28 Thread Bowen
import md5
import string
import MySQLdb

tc = raw_input(Teacher Code: )
p = raw_input(New Password: )

print tc
hash = md5.new()
hash.update(p)
print p
print hash.hexdigest()
h = hash.hexdigest()

boo = raw_input(Sure you want to update password with above details? Y
or N: )

if boo == 'y':
db = MySQLdb.connect(copweb2, **, **, ***)
cursor = db.cursor()
if cursor.execute(UPDATE teachers SET password = '%s' WHERE
teacher_code = '%s' % (h, tc)):
print Done
else:
print Error
else:
print cancelled

cursor.close()
db.close()


This code doesn't seem to update my database, anyone any idea why? Is
it me being stupid? It doesn't kick out an error at all.

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


Re: MySQLdb not updating rows

2006-06-28 Thread Fredrik Lundh
Bowen [EMAIL PROTECTED] wrote:

 boo = raw_input(Sure you want to update password with above details? Y or N: 
 )

 if boo == 'y':

if you're asking for Y or N, maybe you should check for Y or N ?  or better,
use something like:

if boo.lower() == 'y':
...

or even

if boo.lower().startswith(y):
...

db = MySQLdb.connect(copweb2, **, **, ***)
cursor = db.cursor()
if cursor.execute(UPDATE teachers SET password = '%s' WHERE
 teacher_code = '%s' % (h, tc)):
print Done
else:
print Error
 else:
print cancelled

 cursor.close()

what happens if you add

db.commit()

here?

 db.close()

/F 



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


Re: documentation for the change of Python 2.5

2006-06-28 Thread Martin v. Löwis
bussiere wrote:
 I've read thsi documentation n:
 http://docs.python.org/dev/whatsnew/whatsnew25.html
 is there a way to have it in a more printable form ?

Yes. Download

http://www.python.org/ftp/python/doc/2.5b1/pdf-a4-2.5b1.tar.bz2

and extract whatsnew25.pdf.

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


compiling python (or ironpython) to .exe or .dll for or not for .NET

2006-06-28 Thread per9000
Hi python people,

I am working with .NET (in C++/CLI and C#) but since I really love
python I'd like to do things for .NET (or whatever) from python.

Has anyone tried it?

What (costless) compilers are good?

Are there any (costless) editors like MS Visual Express you have tried?

Is the newest Ironpython really as old as from 2004 July 28 (as stated
on http://www.ironpython.com/)?

Thanks.

/Per Erik Strandberg
yet another Fibonaccilover

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


Re: MySQLdb not updating rows

2006-06-28 Thread Bowen
Thanks for that, it appears it was the db.commit() that sorted it
out.lesson learnt :)

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


Re: Immutability

2006-06-28 Thread Georg Brandl
Steve Holden wrote:

Thanks very much.  And, what's more, I have even found its documentation!
Whatsnew2.2.  The 2.4.2 reference is, er, unhelpful.
 
 
 Is it?
 
 http://docs.python.org/lib/built-in-funcs.html
 
 documents property quite well.
 
 I can't really agree that quite good documentation doesn't refer to 
 the use of property as a decorator. It's obvious that a ncessary upgrade 
 to the docs didn't happen (and we can all understand why, I am sure).

In my opinion property isn't really meant to be used as a decorator since
it's impossible to create a read-write property. The decorator pattern
doesn't really fit here.

What I agree is that it's not really defined what a property object
is and what its properties are. For that, documentation patches are
welcome.

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


Re: how do i make an array global

2006-06-28 Thread Georg Brandl
Erik Max Francis wrote:
 a wrote:
 
 def fn():
  for i in range(l)
global count
count[i]= 
 
 how do i declare count to be global if it is an array
 
   count = [...]
 
   def fn():
   global count
   for i in range(l):
   count[i] = ...
 

No need for global here.

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


Re: how do i make an array global

2006-06-28 Thread Georg Brandl
Bruno Desthuilliers wrote:
 a wrote:
 def fn():
  for i in range(l)
 
 l is not defined - you should have an error here.
 
global count
count[i]= 
 
 how do i declare count to be global if it is an array

 Just like it was an integer

No. If he's only mutating count, he doesn't need a global
declaration.

 subsequently i should access or define count as an array
 
 You need to define count before.
 
 error:
 global name 'count' is not defined
 
 He...
 
 *but*
 You probably should not do that anyway. Globals are *evil*.

Do you realize that every variable you set in a module's namespace is a
global when used by a function? Globals are *not* evil.

 And functions modifying globals is the worst possible thing.
 There are very few chances you *need* a global here.

Look at the use case first.
For small scripts, sometimes re-assigning global names or mutating objects
refered to by global names is essential. For large-scale packages, though,
I agree with you that mutating globals is bad.

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


Java identifiers (was: languages with full unicode support)

2006-06-28 Thread David Hopwood
Note Followup-To: comp.lang.java.programmer

Chris Uppal wrote:
 Since the interpretation of characters which are yet to be added to
 Unicode is undefined (will they be digits, letters, operators, symbol,
 punctuation ?), there doesn't seem to be any sane way that a language 
 could
 allow an unrestricted choice of Unicode in identifiers.  Hence, it must define
 a specific allowed sub-set.  C certainly defines an allowed subset of Unicode
 characters -- so I don't think you could call its Unicode support half-baked
 (not in that respect, anyway).  A case -- not entirely convincing, IMO -- 
 could
 be made that it would be better to allow a wider range of characters.
 
 And no, I don't think Java's approach -- where there /is no defined set of
 allowed identifier characters/ -- makes any sense at all :-(

Java does have a defined set of allowed identifier characters. However, you
certainly have to go around the houses a bit to work out what that set is:


http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8

# An identifier is an unlimited-length sequence of Java letters and Java digits,
# the first of which must be a Java letter. An identifier cannot have the same
# spelling (Unicode character sequence) as a keyword (§3.9), boolean literal
# (§3.10.3), or the null literal (§3.10.7).
[...]
# A Java letter is a character for which the method
# Character.isJavaIdentifierStart(int) returns true. A Java letter-or-digit
# is a character for which the method Character.isJavaIdentifierPart(int)
# returns true.
[...]
# Two identifiers are the same only if they are identical, that is, have the
# same Unicode character for each letter or digit.

For Java 1.5.0:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html

# Character information is based on the Unicode Standard, version 4.0.

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html#isJavaIdentifierStart(int)

# A character may start a Java identifier if and only if one of the following
# conditions is true:
#
#   * isLetter(codePoint) returns true
#   * getType(codePoint) returns LETTER_NUMBER
#   * the referenced character is a currency symbol (such as $)

[This means that getType(codePoint) returns CURRENCY_SYMBOL, i.e. Unicode
General Category Sc.]

#   * the referenced character is a connecting punctuation character (such as 
_).

[This means that getType(codePoint) returns CONNECTOR_PUNCTUATION, i.e. Unicode
General Category Pc.]

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html#isJavaIdentifierPart(int)

# A character may be part of a Java identifier if any of the following are true:
#
#   * it is a letter
#   * it is a currency symbol (such as '$')
#   * it is a connecting punctuation character (such as '_')
#   * it is a digit
#   * it is a numeric letter (such as a Roman numeral character)

[General Category Nl.]

#   * it is a combining mark

[General Category Mc (see 
http://www.unicode.org/versions/Unicode4.0.0/ch04.pdf).]

#   * it is a non-spacing mark

[General Category Mn (ditto).]

#   * isIdentifierIgnorable(codePoint) returns true for the character

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html#isDigit(int)

# A character is a digit if its general category type, provided by
# getType(codePoint), is DECIMAL_DIGIT_NUMBER.

[General Category Nd.]

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html#isIdentifierIgnorable(int)

# The following Unicode characters are ignorable in a Java identifier or a 
Unicode
# identifier:
#
#   * ISO control characters that are not whitespace
# o '\u' through '\u0008'
# o '\u000E' through '\u001B'
# o '\u007F' through '\u009F'
#   * all characters that have the FORMAT general category value

[FORMAT is General Category Cf.]

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html#isLetter(int)

# A character is considered to be a letter if its general category type, 
provided
# by getType(codePoint), is any of the following:
#
#   * UPPERCASE_LETTER
#   * LOWERCASE_LETTER
#   * TITLECASE_LETTER
#   * MODIFIER_LETTER
#   * OTHER_LETTER



To cut a long story short, the syntax of identifiers in Java 1.5 is therefore:

  Keyword ::= one of
abstractcontinuefor   new  switch
assert  default ifpackage  synchronized
boolean do  goto  private  this
break   double  implementsprotectedthrow
byteelseimportpublic   throws
caseenuminstanceofreturn   transient
catch   extends int   shorttry
charfinal   interface static   void
class   finally long  strictfp volatile
const   float   nativesuperwhile

  Identifier::= IdentifierChars butnot (Keyword | true | false | 
null)
  

Re: Immutability

2006-06-28 Thread Sion Arrowsmith
Fredrik Lundh [EMAIL PROTECTED] wrote:
Sion Arrowsmith wrote:
 What I've not seen documented anywhere is the:
@property
def fset(self, value):
...
 idiom. It's not obvious from the documentation of the property
 function that it can be used as a decorator like this.
probably because it cannot be used in that way: the property function
takes the *getter* as its first argument, so you can only use this for read-
only properties...

Ahem. Yes. What I obviously meant to write was:

What I've not seen documented anywhere is the:
   @property
   def fget(self):
   ...
idiom. [ ... ]

(As correctly written by someone else further upthread.) It is possible
to find it described by Googling, but the Cookbook (and python.org) hits
provide much more complicated general-purpose (ie setters as well)
property decorators.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: MySQLdb not updating rows

2006-06-28 Thread Douglas Andrade
Hello Simon,Take a look at this link: http://python.codezoo.com/pub/component/3583
May autocommit (or commit, as Fredrik pointed out) be the solution.On 28 Jun 2006 06:46:54 -0700, Bowen [EMAIL PROTECTED]
 wrote:Thanks for that, it appears it was the db.commit() that sorted itout.lesson learnt :)
--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: MySQLdb not updating rows

2006-06-28 Thread Benjamin Niemann
Bowen wrote:

 import md5
 import string
 import MySQLdb
 
 tc = raw_input(Teacher Code: )
 p = raw_input(New Password: )
 
 print tc
 hash = md5.new()
 hash.update(p)
 print p
 print hash.hexdigest()
 h = hash.hexdigest()
 
 boo = raw_input(Sure you want to update password with above details? Y
 or N: )
 
 if boo == 'y':
 db = MySQLdb.connect(copweb2, **, **, ***)
 cursor = db.cursor()
 if cursor.execute(UPDATE teachers SET password = '%s' WHERE
 teacher_code = '%s' % (h, tc)):
 print Done
 else:
 print Error
 else:
 print cancelled
 
 cursor.close()
 db.close()
 
 
 This code doesn't seem to update my database, anyone any idea why? Is
 it me being stupid? It doesn't kick out an error at all.

Another side note: don't build your queries using (dumb) string formatting,
let the MySQLdb module do it for you. More specifically use:

cursor.execute(
  UPDATE teachers SET password = %s WHERE teacher_code = %s,
  (h, tc)
  )

instead of

cursor.execute(
  UPDATE teachers SET password = '%s' WHERE teacher_code = '%s'
  % (h, tc)
  )

The former form takes care of quoting and escaping, your version did not
escape potentially harmful characters in tc, resulting in a possibly opened
door for SQL injection attacks. 

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-28 Thread David Hopwood
Pascal Costanza wrote:
 David Hopwood wrote:
 Pascal Costanza wrote:
 David Hopwood wrote:
 Marshall wrote:

 The real question is, are there some programs that we
 can't write *at all* in a statically typed language, because
 they'll *never* be typable?

 In a statically typed language that has a dynamic type, all
 dynamically typed programs are straightforwardly expressible.

 What about programs where the types change at runtime?

 Staged compilation is perfectly compatible with static typing.
 Static typing only requires that it be possible to prove absence
 of some category of type errors when the types are known; it
 does not require that all types are known before the first-stage
 program is run.
 
 Can you change the types of the program that is already running, or are
 the levels strictly separated?

In most staged compilation systems this is intentionally not permitted.
But this is not a type system issue. You can't change the types in a
running program because you can't change the program, period. And you
can't do that because most designers of these systems consider directly
self-modifying code to be a bad idea (I agree with them).

Note that prohibiting directly self-modifying code does not prevent a
program from specifying another program to *replace* it.

 There are, however, staged compilation systems that guarantee that
 the generated program will be typeable if the first-stage program
 is.
 
 ...and I guess that this reduces again the kinds of things you can express.

Yes. If you don't want that, use a system that does not impose this
restriction/guarantee.

 (It's clear that to compare the expressiveness of statically and
 dynamically typed languages, the languages must be comparable in
 other respects than their type system. Staged compilation is the
 equivalent feature to 'eval'.)
 
 If it is equivalent to eval (i.e., executed at runtime), and the static
 type checker that is part of eval yields a type error, then you still
 get a type error at runtime!

You can choose to use a system in which this is impossible because only
typeable programs can be generated, or one in which non-typeable programs
can be generated. In the latter case, type errors are detected at the
earliest possible opportunity, as soon as the program code is known and
before any of that code has been executed. (In the case of eval, OTOH,
the erroneous code may cause visible side effects before any run-time
error occurs.)

I don't know what else you could ask for.

-- 
David Hopwood [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compiling python (or ironpython) to .exe or .dll for or not for .NET

2006-06-28 Thread Alan Franzoni
Il 28 Jun 2006 06:29:58 -0700, per9000 ha scritto:

 Is the newest Ironpython really as old as from 2004 July 28 (as stated
 on http://www.ironpython.com/)?

Ironpython homepage seems long to have been abandoned.

Try this:

http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742



-- 
Alan Franzoni [EMAIL PROTECTED]
-
Togli .xyz dalla mia email per contattarmi.
Rremove .xyz from my address in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E 
-
Blog: http://laterradeglieroi.verdiperronchi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compiling python (or ironpython) to .exe or .dll for or not for .NET

2006-06-28 Thread Alan Franzoni
Il 28 Jun 2006 06:29:58 -0700, per9000 ha scritto:

 Is the newest Ironpython really as old as from 2004 July 28 (as stated
 on http://www.ironpython.com/)?

Sorry again, the up to date page is the following one:
http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython

-- 
Alan Franzoni [EMAIL PROTECTED]
-
Togli .xyz dalla mia email per contattarmi.
Rremove .xyz from my address in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E 
-
Blog: http://laterradeglieroi.verdiperronchi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-28 Thread Pascal Costanza
David Hopwood wrote:
 Pascal Costanza wrote:
 David Hopwood wrote:
 Pascal Costanza wrote:
 David Hopwood wrote:
 Marshall wrote:

 The real question is, are there some programs that we
 can't write *at all* in a statically typed language, because
 they'll *never* be typable?
 In a statically typed language that has a dynamic type, all
 dynamically typed programs are straightforwardly expressible.
 What about programs where the types change at runtime?
 Staged compilation is perfectly compatible with static typing.
 Static typing only requires that it be possible to prove absence
 of some category of type errors when the types are known; it
 does not require that all types are known before the first-stage
 program is run.
 Can you change the types of the program that is already running, or are
 the levels strictly separated?
 
 In most staged compilation systems this is intentionally not permitted.
 But this is not a type system issue. You can't change the types in a
 running program because you can't change the program, period. And you
 can't do that because most designers of these systems consider directly
 self-modifying code to be a bad idea (I agree with them).

Whether you consider something you cannot do with statically typed 
languages a bad idea or not is irrelevant. You were asking for things 
that you cannot do with statically typed languages.

There are at least systems that a lot of people rely on (the JVM, .NET) 
that achieve runtime efficiency primarily by executing what is 
essentially self-modifying code. These runtime optimization systems have 
been researched primarily for the language Self, and also implemented in 
Strongtalk, CLOS, etc., to various degrees.

Beyond that, I am convinced that the ability to update a running system 
without the need to shut it down can be an important asset.

 Note that prohibiting directly self-modifying code does not prevent a
 program from specifying another program to *replace* it.

...and this creates problems with moving data from one version of a 
program to the next.


Pascal

-- 
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to measure execution time of a program

2006-06-28 Thread Grant Edwards
On 2006-06-28, Pete Forman [EMAIL PROTECTED] wrote:
 Fredrik Lundh [EMAIL PROTECTED] writes:
  simplest way:
 
  t0 = time.time()

 You can get better resolution by using time.clock() instead of
 time.time().

Oh really?  When I do it, time.clock() is worse:

--timeit.py--
import time

for i in range(5):
t0 = time.time()
print hi there
print time.time()-t0

for i in range(5):
t0 = time.clock()
print hi there
print time.clock()-t0
--timeit.py--

hi there
0.000149011611938
hi there
4.10079956055e-05
hi there
3.981590271e-05
hi there
3.981590271e-05
hi there
3.88622283936e-05
hi there
0.0
hi there
0.0
hi there
0.0
hi there
0.0
hi there
0.0


-- 
Grant Edwards   grante Yow!  I'm a nuclear
  at   submarine under the
   visi.compolar ice cap and I need
   a Kleenex!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb not updating rows

2006-06-28 Thread Bowen
Thanks for that tip, it's a simple script that I am experimenting on,
planning to build a custon gui for my database. It is definately
something for me to note in the future.

Thanks again.

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


Re: What is Expressiveness in a Computer Language

2006-06-28 Thread Matthias Blume
Pascal Costanza [EMAIL PROTECTED] writes:

 Whether you consider something you cannot do with statically typed
 languages a bad idea or not is irrelevant. You were asking for things
 that you cannot do with statically typed languages.

The whole point of static type systems is to make sure that there are
things that one cannot do.  So the fact that there are such things are
not an argument per se against static types.

[ ... ]

 Beyond that, I am convinced that the ability to update a running
 system without the need to shut it down can be an important asset.

And I am convinced that updating a running system in the style of,
e.g., Erlang, can be statically typed.

 Note that prohibiting directly self-modifying code does not prevent a
 program from specifying another program to *replace* it.

 ...and this creates problems with moving data from one version of a
 program to the next.

How does this create such a problem?  The problem is there in either
approach.  In fact, I believe that the best chance we have of
addressing the problem is by adopting the replace the code model
along with a translate the data where necessary at the time of
replacement.  Translating the data, i.e., re-establishing the
invariants expected by the updated/replaced code, seems much harder
(to me) in the case of self-modifying code.  Erlang got this one
right.
-- 
http://mail.python.org/mailman/listinfo/python-list


handling unicode data

2006-06-28 Thread Filipe
Hi all,

I'm starting to learn python but am having some difficulties with how
it handles the encoding of data I'm reading from a database. I'm using
pymssql to access data stored in a SqlServer database, and the
following is the script I'm using for testing purposes.

-
import pymssql

mssqlConnection =
pymssql.connect(host='localhost',user='sa',password='password',database='TestDB')
cur = mssqlConnection.cursor()
query=Select ID, Term from TestTable where ID  200 and ID  300;
cur.execute(query)
row = cur.fetchone()
results = []
while row is not None:
   term = row[1]
   print type(row[1])
   print term
   results.append(term)
   row = cur.fetchone()
cur.close()
mssqlConnection.close()
print results
-

In the console output, for a record where I expected to see França
I'm getting the following:

type 'str'   -When I print the type (print type(row[1]))
Fran+a -When I print the term variable (print term)
Fran\xd8a -When I print all the query results (print results)


The values in Term column in TestTable are stored as unicode (the
column's datatype is nvarchar), yet, the python data type of the values
I'm reading is not unicode.
It all seems to be an encoding issue, but I can't see what I'm doing
wrong..
Any thoughts?

thanks in advance,
Filipe

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


Re: What is Expressiveness in a Computer Language

2006-06-28 Thread Andreas Rossberg
David Hopwood wrote:
 
 (In the case of eval, OTOH,
 the erroneous code may cause visible side effects before any run-time
 error occurs.)

Not necessarily. You can replace the primitive eval by compile, which 
delivers a function encapsulating the program, so you can check the type 
of the function before actually running it. Eval itself can easily be 
expressed on top of this as a polymorphic function, which does not run 
the program if it does not have the desired type:

   eval ['a] s = typecase compile s of
   f : (()-'a) - f ()
   _ - raise TypeError

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


Re: Arrghh... Problems building Python from source on OS X --

2006-06-28 Thread Michael J. Fromberger
In article [EMAIL PROTECTED],
 J. Jeffrey Close [EMAIL PROTECTED] wrote:

 Hi all,
 
 I have been trying for some time to build Python 2.4.x
 from source on OS X 10.4.6.  I've found *numerous*
 postings on various mailing lists and web pages
 documenting the apparently well-known problems of
 doing so.  Various problems arise either in the
 ./configure step, with configure arguments that don't
 work, or in the compile, or in my case in the link
 step with libtool.
 
 The configure options I'm using are the following:
 --enable-framework --with-pydebug --with-debug=yes
 --prefix=/usr --with-dyld --program-suffix=.exe
 --enable-universalsdk
 
 I've managed to get past configure and can compile
 everything, but in the link I get the error Undefined
 symbols:  ___eprintf .  This appears to have
 something to do with dynamic library loading not
 properly pulling in libgcc.  I've tried with -lgcc in
 the LD options, but that produces a configure error
 cannot compute sizeof
 
 If I remove --enable-framework the complete build
 works, but unfortunately that is the one critical
 element that I need.
 
 The web pages I've found referring to this range from
 2001 to present -- still apparently everybody is
 having problems with this.  Does *anybody* here have
 Python built from source on this OS?

Hi, Jeffrey,

Yes, I use Python 2.4.3 built this way.  I did not have any significant 
troubles building Python on my 10.4 system.  My configuration step was a 
little different from yours, but basically I just checked out the 2.4.3 
source from Subversion, and this is how I configured it:

 env CFLAGS=-I/usr/local/include 
-I/Library/Frameworks/Tk.framework/Headers \
 LDFLAGS=-L/usr/local/lib \
 configure --enable-framework --enable-shared

I included /usr/local/include and /usr/local/lib so that the build could 
use the version of GNU readline I installed via Darwin ports.  The Tk 
headers allow pythonw to build properly. 

Having configured, I built and installed via:

  make
  sudo make frameworkinstall

I hope this may be helpful to you.

-M

-- 
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/  | Dartmouth College, Hanover, NH, USA
-- 
http://mail.python.org/mailman/listinfo/python-list


SimpleXMLRPCServer and client IP address

2006-06-28 Thread Jeremy Monnet
Hello,

I've started python a few weeks ago, and to now everything went fine
with my cookbook and a learning book.

Now, I've tried the SimpleXMLRPCServer, and it worked OK untill I
tried to get the client IP address. I have searched a long time the
Internet but couldn't find a _simple_ solution :-)

#Code

from liste_films import *
import SimpleXMLRPCServer

def isOpen():
   # Here I want to get the clien IP address
   if CheckPerms(IP):
   return True
   else:
   return False

if __name__ == '__main__':
   server = SimpleXMLRPCServer.SimpleXMLRPCServer((localhost, 8000))
   server.register_function(isOpen)
   server.serve_forever()

#end code

Tips I've found were :
- inherit from requestDispatcher and overload its methods. But that's
not that Simple.
- use the requestHandler and its method address_string(), but I didn't
an easy to understand example
- http://mail.python.org/pipermail/python-list/2006-May/340266.html
but this thread seems not to have been finished :-(

Furthermore, I think I should be able to access the socket object from
where I am (at starting of isOpen() ), but I don't know how. self
and parent are not defined, I can access the server object, but it
says the other end s not connected (transport endpoint). I think
this SimpleXMLRPCServer was not threaded (because it says in the API :
answer all requests one at a time), so I don't understand why in the
middle of my function the server.socket.getpeername() says it's not
connected.

I'm using python2.3 on linux (debian sid).

Thanks for any help !

Jeremy
-- 
Linux Registered User #317862
Linux From Scratch Registered User #16571
Please do not send me .doc, .xls, .ppt, as I will *NOT* read them.
Please send me only open formats, as OpenDocument or pdf.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to measure execution time of a program

2006-06-28 Thread Fredrik Lundh
Grant Edwards wrote:

 You can get better resolution by using time.clock() instead of
 time.time().

 Oh really?  When I do it, time.clock() is worse:

on Unix, time.clock() is a tick counter; if your process is running when the 
tick
interrupt arrives, the internal counter value is incremented (whether the 
process
actually used the full tick slot or not).  the tick resolution is usually 1-10 
milli-
seconds.

on Windows, time.clock() is a high-resolution CPU counter, with microsecond
resolution.

/F 



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


RE: How do you use this list ?

2006-06-28 Thread Michael . Coll-Barth


-Original Message-
From: Grant Edwards

 Actually having mailing lists send you mail is insane.

Once upon a time, I would have agreed.  However, it is becoming increasingly 
difficuilt to get to the newgroups directly from the workplace.  The only 
recourse is to use the mailing lists, such as those provided by various sites, 
such as python.org.  This might also account for why so many folks top post 
rather than bottom post as postings look like email.  And in a corporate 
setting, most people use top posting for email, pushing the history down and 
out of the way.


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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


Re: Immutability

2006-06-28 Thread Nick Maclaren

In article [EMAIL PROTECTED],
Gerard Flanagan [EMAIL PROTECTED] writes:
| 
| There are (unofficial) documentation wikis here:
| 
| pytut.infogami.com
| pyref.infogami.com
| pyfaq.infogami.com

Thanks very much.

| You might like to consider adding the information you perceive to be
| lacking.

Consider it considered, but I have to start by understanding what is
supposed to happen and what does happen, precisely and in detail.


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


Re: handling unicode data

2006-06-28 Thread Fredrik Lundh
Filipe wrote:

 In the console output, for a record where I expected to see França
 I'm getting the following:

 type 'str'   -When I print the type (print type(row[1]))
 Fran+a -When I print the term variable (print term)
 Fran\xd8a -When I print all the query results (print results)

 The values in Term column in TestTable are stored as unicode (the
 column's datatype is nvarchar), yet, the python data type of the values
 I'm reading is not unicode.
 It all seems to be an encoding issue, but I can't see what I'm doing
 wrong..

looks like the DB-API driver returns 8-bit ISO-8859-1 strings instead of Unicode
strings.  there might be some configuration option for this; see

in worst case, you could do something like

def unicodify(value):
if isinstance(value, str):
value = unicode(value, iso-8859-1)
return value

term = unicodify(row[1])

but it's definitely better if you can get the DB-API driver to do the right 
thing.

/F 



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

Re: Immutability

2006-06-28 Thread Nick Maclaren

In article [EMAIL PROTECTED],
Sion Arrowsmith [EMAIL PROTECTED] writes:
| 
| Actually, there's an almost throw-away mention in
| http://docs.python.org/ref/descriptor-invocation.html
| which gives you what you need (although not, I have to say, in an
| easily digestible form).

Thanks very much.

| What I've not seen documented anywhere is the:
| @property
| def fset(self, value):
| ...
| idiom. It's not obvious from the documentation of the property
| function that it can be used as a decorator like this. (cf.
| classmethod and staticmethod.)

Most especially since it isn't working very well for me, and I am trying
to track down why.  When I run:

class alf :
def pete (self) :
print Inside pete\n

b = alf()
b.pete()

class fred :
@property
def joe (self) :
print Inside /joe\n

a = fred()
a.joe()

I get:

Inside pete

Inside joe

Traceback (most recent call last):
  File crap.py, line 14, in module
a.joe()
TypeError: 'NoneType' object is not callable

VERY weird - I could understand it if I got the error and DIDN'T succeed
in the call 
Regards,
Nick Maclaren.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SimpleXMLRPCServer and client IP address

2006-06-28 Thread Fredrik Lundh
Jeremy Monnet wrote:

 Tips I've found were :
 - use the requestHandler and its method address_string(), but I didn't
 an easy to understand example
 - http://mail.python.org/pipermail/python-list/2006-May/340266.html
 but this thread seems not to have been finished :-(

maybe the explanation in that message was good enough for the poster ?

Your handler object should be getting set up with the client_address 
property.
If not you need to show us some small subset of your app that demonstrates 
the
issue.

You can also inherit from SimpleXMLRPCServer and override verify_request, 
from
BaseServer, if you want the option of blocking requests based on source
address.

the second alternative should be straightforward enough:

class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
def verify_request(self, request, client_address):
return CheckPerms(client_address)

server = MyXMLRPCServer(...)
...

if you need more control, you need to subclass SimpleXMLRPCHandler instead.

 Furthermore, I think I should be able to access the socket object from
 where I am (at starting of isOpen() ), but I don't know how.

you cannot.  the isOpen() function is your RPC handler, and it only sees things 
provided
by the client.

 self and parent are not defined, I can access the server object, but it
 says the other end s not connected (transport endpoint). I think
 this SimpleXMLRPCServer was not threaded (because it says in the API :
 answer all requests one at a time), so I don't understand why in the
 middle of my function the server.socket.getpeername() says it's not
 connected.

because the server socket isn't the same thing as the client socket -- the 
server socket
is only used to listen for incoming connections; it creates a new client socket 
for each
incoming request.

/F 



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


Re: Immutability

2006-06-28 Thread Fredrik Lundh
Nick Maclaren wrote:

 class fred :
@property
def joe (self) :
print Inside /joe\n

 a = fred()
 a.joe()

 Traceback (most recent call last):
  File crap.py, line 14, in module
a.joe()
 TypeError: 'NoneType' object is not callable

 VERY weird - I could understand it if I got the error and DIDN'T succeed
 in the call 

a property looks like an attribute, not a method, so you're trying to call 
whatever
your joe() method returns.

(that's what a function for getting an attribute value in the property 
documentation
refers to).

/F 



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


String Question

2006-06-28 Thread diffuser78
mac_string = '001485e55503'  (This is the mac address of a computer.)

I am using wake on LAN python script to start computer remote.It uses
format like this 

s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
80))

where '\x00\x14\x85\xe5\x55\x03' is the MAC address to be used.


What I do is break the string into 6 parts like this,

str01=mac_string[0:2]
str02=mac_string[2:4]
str03=mac_string[4:6]
str04=mac_string[6:8]
str05=mac_string[8:10]
str06=mac_string[10:12]

and if I use it like this

s.sendto('\xff'*6 + '\xstr01\xstr02\xstr03\xstr04\xstr05\xstr06'*16,
('192.168.1.255', 80))
I get an error


I also tried like this
s.sendto('\xff'*6 + 'mac_string'*16, ('192.168.1.255', 80))

Thiis also didnt work.


Since the MAC adddress are hexadecimal, how should I go about it here.

Please help, every help is appreciated. Thanks

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


Re: String Question

2006-06-28 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 mac_string = '001485e55503'  (This is the mac address of a computer.)

 I am using wake on LAN python script to start computer remote.It uses
 format like this 

 s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
 80))

 where '\x00\x14\x85\xe5\x55\x03' is the MAC address to be used.

s.sendto('\xff'*6 + binascii.unhexlify(mac_string) *16, ('192.168.1.255', 
80))

/F 



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


Re: String Question

2006-06-28 Thread Iain King

[EMAIL PROTECTED] wrote:
 mac_string = '001485e55503'  (This is the mac address of a computer.)

 I am using wake on LAN python script to start computer remote.It uses
 format like this 

 s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
 80))

 where '\x00\x14\x85\xe5\x55\x03' is the MAC address to be used.


 What I do is break the string into 6 parts like this,

 str01=mac_string[0:2]
 str02=mac_string[2:4]
 str03=mac_string[4:6]
 str04=mac_string[6:8]
 str05=mac_string[8:10]
 str06=mac_string[10:12]

 and if I use it like this

 s.sendto('\xff'*6 + '\xstr01\xstr02\xstr03\xstr04\xstr05\xstr06'*16,
 ('192.168.1.255', 80))
 I get an error


 I also tried like this
 s.sendto('\xff'*6 + 'mac_string'*16, ('192.168.1.255', 80))

 Thiis also didnt work.


 Since the MAC adddress are hexadecimal, how should I go about it here.

 Please help, every help is appreciated. Thanks

See http://docs.python.org/lib/typesseq-strings.html

You probably want:

s.sendto('\xff'*6 + ('\x%s\x%s\x%s\x%s\x%s\x%s' % (str01, str02, str03,
 sttr04, str05, str06))*16, ('192.168.1.255', 80))

Iain

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


Re: SimpleXMLRPCServer and client IP address

2006-06-28 Thread Jeremy Monnet
Thanks for your answer !

On 6/28/06, Fredrik Lundh [EMAIL PROTECTED] wrote:
 maybe the explanation in that message was good enough for the poster ?

I think so ... unfortunately not for me ... yet ! :-)


 Your handler object should be getting set up with the client_address 
 property.
 If not you need to show us some small subset of your app that 
 demonstrates the
 issue.

 You can also inherit from SimpleXMLRPCServer and override verify_request, 
 from
 BaseServer, if you want the option of blocking requests based on source
 address.

 the second alternative should be straightforward enough:

 class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
 def verify_request(self, request, client_address):
 return CheckPerms(client_address)

 server = MyXMLRPCServer(...)
 ...

 if you need more control, you need to subclass SimpleXMLRPCHandler instead.


this seems easy, but I'm not sure I could use it : I already provide
more than one method (of course not in the snippet of code I provided,
my mistake probably not to show it) and I plan to add several more in
the near future. Overloading verify_request() in this way means I
can't use the same xmlrpcserver for other methods ? Or am I just wrong
? (I should probably have a look at request, maybe that's a key ?)
Or is it the more control you talked about ?

Jeremy
-- 
Linux Registered User #317862
Linux From Scratch Registered User #16571
Please do not send me .doc, .xls, .ppt, as I will *NOT* read them.
Please send me only open formats, as OpenDocument or pdf.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do i make an array global

2006-06-28 Thread Bruno Desthuilliers
Georg Brandl wrote:
 Bruno Desthuilliers wrote:
 
a wrote:

def fn():
 for i in range(l)

l is not defined - you should have an error here.


   global count
   count[i]= 

how do i declare count to be global if it is an array

Just like it was an integer
 
 
 No. If he's only mutating count, he doesn't need a global
 declaration.

Did I said so ? I just answered the OP's question. If that's the 'int'
that confuse you, then s/int/dict/ - what I meant is that the global
statement doesn't care about types...

 
subsequently i should access or define count as an array

You need to define count before.


error:
global name 'count' is not defined

He...

*but*
You probably should not do that anyway. Globals are *evil*.
  
 Do you realize that every variable you set in a module's namespace is a
 global when used by a function?

Going to teach me Python, Georg ?-) Then let's be accurate first, and
s/variable you set/name you bind/

  Globals are *not* evil.

Yes they are.

And functions modifying globals is the worst possible thing.
There are very few chances you *need* a global here.
  
 Look at the use case first.

The use case here is to avoid either passing a list as param or building
and returning it - and the OP is obviously a newbie, so better for him
to learn the RightThing(tm) from the beginning IMHO.

 For small scripts, sometimes re-assigning global names or mutating objects
 refered to by global names is essential.

s/is essential/seems easier/

Then you or anyone else has to make a quick fix or update, and
everything starts to break down. Too bad.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >