Re: Unicode/ascii encoding nightmare

2006-11-07 Thread Andrea Griffini
John Machin wrote:

> Indeed yourself.

What does the above mean ?

> Have you ever considered reading posts in
> chronological order, or reading all posts in a thread?

I do no think people read posts in chronological order;
it simply doesn't make sense. I also don't think many
do read threads completely, but only until the issue is
clear or boredom kicks in.

Your nice "double whammy" post was enough to clarify
what happened to the OP, I just wanted to make a bit
more explicit what you meant; my poor english also
made me understand that you were just "suspecting"
such an error, so I verified and posted the result.

That your "suspect" was a sarcastic remark could be
clear only when reading the timewise "former" reply
that however happened to be lower in the thread tree
in my newsreader; fact that pushed it into the "not
worth reading" area.

> It might help
> you avoid writing posts with non-zero information content.

Why should I *avoid* writing posts with *non-zero*
information content ? Double whammy on negation or
still my poor english kicking in ? :-)

Suppose you didn't post the double whammy message,
and suppose someone else made it seven minutes later
than your other post. I suppose that in this case
the message would be a zero content noise (and not
the precious pearl of wisdom it is because it
comes from you).

> Cheers,
> John

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


PIL: match for ImageMagick's display -ping

2006-11-07 Thread Torsten Bronger
Hallöchen!

I have to extract the dimensions of many bitmap files.  An old Bash
script did it with ImageMagick's "display -ping ...".  "-ping" means
that it extracts the image dimensions efficiently.  I suspect it
simply doesn't read the image itself.

Now the Bash script has been transformed into Python+PIL.  Is there
a way to get the dimensions equally efficient here, or does the PIL
even do this optimisation implicitly since I never access the image
bitmap itself? ceter

Thank you!

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
ICQ 264-296-646
   (See http://ime.webhop.org for Jabber, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Paul Rubin
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> Ah, but in the case where the lock# signal is used, it's known that
> the data is not in the cache of the CPU performing the lock operation;
> I believe it is also known that the data is not in the cache of any
> other CPU. So the CPU performing the LOCK INC sequence just has
> to perform two memory cycles. No cache coherency protocol runs
> in that case.

How can any CPU know in advance that the data is not in the cache of
some other CPU?

> But even when caching is involved, I don't see why there should be
> more than three memory cycles. The MESI "protocol" really consists
> only of two pins: HIT# and HITM#; the actual implementation is just
> in keeping the state for each cache line, and in snooping. There
> CPU's don't really "communicate". Instead, if one processor tries
> to fill a cache line, the others snoop the read, and assert either
> HIT# (when they have not modified their cache lines) or HITM#
> (when they do have modified their cache lines). Assertions of
> these signals is also immediate.

OK, this is logical, but it already implies a cache miss, which costs
many dozen (100?) cycles.  But this case may be uncommon, since one
hops that cache misses are relatively rare.  

> The worst case would be that one processor performs a LOCK INC,
> and another processor has the modified value in its cache line.
> So it needs to first flush the cache line, before the other
> processor can modify the memory. If the memory is not cached
> yet in another processor, the MESI protocol does not involve
> additional penalties.

I think for Python refcounts this case must occur quite frequently
since there are many Python objects (small integers, None, etc.)
whose refcounts get modified extremely often.  

IIRC, the SPJ paper that I linked claims that lock-free protocols
outperform traditional lock-based ones even with just two processors.
But maybe things are better with a dual core processor (shared cache)
than with two separate packages.
-- 
http://mail.python.org/mailman/listinfo/python-list


PIL: match for ImageMagick's display -ping

2006-11-07 Thread Torsten Bronger
Hallöchen!

I have to extract the dimensions of many bitmap files.  An old Bash
script did it with ImageMagick's "display -ping ...".  "-ping" means
that it extracts the image dimensions efficiently.  I suspect it
simply doesn't read the image itself.

Now the Bash script has been transformed into Python+PIL.  Is there
a way to get the dimensions equally efficient here, or does the PIL
even do this optimisation implicitly since I never access the image
bitmap itself?

Thank you!

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
ICQ 264-296-646
   (See http://ime.webhop.org for Jabber, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assigning values in __init__

2006-11-07 Thread Nick Craig-Wood
Larry Bates <[EMAIL PROTECTED]> wrote:
>  John Salerno wrote:
> > Let's say I'm making a game and I have this base class:
> > 
> > class Character(object):
> > 
> > def __init__(self, name, stats):
> > self.name = name
> > self.strength = stats[0]
> > self.dexterity = stats[1]
> > self.intelligence = stats[2]
> > self.luck = stats[3]
> > 
> > Is this a good way to assign the values to the different attributes?
> > Should 'stats' be a list/tuple (like this), or should I do *stats instead?
> > 
> > I'm trying to think ahead to when I might want to add new attributes,
> > and I want to make sure this doesn't get crazy with individual
> > parameters instead of just the one list.
> > 
> > Or maybe there's some way to loop through two lists (the stats and the
> > attributes) and assign them that way? I was thinking of a nested for
> > statement but that didn't seem to work.
> 
>  Sounds like what you should be doing is something like keyword arguments
>  instead.
> 
>  class Character(object):
>  def __init__(self, name, **kwargs):
>  self.name=name
>  for key, value in kwargs.items():
>  setattr(self, key, value)
> 
> 
>  z=Character('name', strength=10, dexterity=5, intelligence=3,
>  luck=0)

I would say this is a bad idea because you'll get no error messages if
you mis-spell 'dexterity' for instance.

I'd prefer to see a bit more error checking, something like

class Character(object):
attributes = set(['strength', 'dexterity', 'intelligence', 'luck'])
def __init__(self, name, **kwargs):
self.name=name
for key, value in kwargs.items():
if key not in self.attributes:
raise AttributeError("Bad attribute %s for %s" % (key, 
self.__class__.__name__))
setattr(self, key, value)


z = Character('name', strength=10, dexterity=5, intelligence=3, luck=0)

>>> Character('name', strength=10, dexterity=5, intelligence=3, luck=0)

>>> Character('name', strength=10, dextrity=5, intelligence=3, luck=0)
Traceback (most recent call last):
  File "", line 1, in ?
  File "z.py", line 7, in __init__
raise AttributeError("Bad attribute %s for %s" % (key, 
self.__class__.__name__))
AttributeError: Bad attribute dextrity for Character
>>>

You can then add to attributes in the subclasses

class MagicCharacter(Character):
attributes = Character.attributes | set(['spells', 'wand'])

>>> MagicCharacter('name', strength=10, dexterity=5, intelligence=3, 
luck=0, spells=1)

>>>

If I was writing this, I'd probably just stick to named parameters
unless I had more than 10 parameters.  Named parameters are easy to
manage, and you never get confused by their position.

Also pychecker understands named parameters where as if you use a
scheme like the above you'll cause pychecker problems!

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shutil: permission denied errors on windows

2006-11-07 Thread Antoine De Groote
Yes it's strange, I never had the problem before, either. It seems now 
to be only the case for folders. A very simple

shutil.copy('a', 'b')

already fails with the error message.

I reinstalled Python, but that didn't change anything...

Regards,
antoine

John Henry wrote:
> I use the copy function a lot and never have problem.  I suggest that
> you write a no brainer standalone test code and if it still fails
> there, then you have a problem with your installation.
> 
> Antoine De Groote wrote:
>> Google tells quite some things about it, but none of them are satisfactory.
>>
>> I'm on Windows, and shutil operations (e.g. move, copy) throw [Errno 13]
>> Permission denied all the time, for the source files. It seems that this
>> is the case for all my files. But what I don't understand is that
>> yesterday it still worked. I didn't change anything on my system though
>> (at least not that I am aware of). I restarted the computer several
>> times to see if that helped, but it didn't. Also I can't find a process
>> that would be using the files...
>>
>> Has anybody experienced this problem before, or have a solution?
>>
>> Kind regards,
>> antoine
>>
>> Here's the code that throws the errors
>>
>> [...]
>> for l in files:
>>  from_file = os.path.join(dir, l)
>>  to_file = from_file.replace(tree_top, backup_dir)
>>  try:
>>  if not os.path.exists(to_file):
>>  log('Copying new  %s' % from_file)
>>  counter_new += 1
>>  shutil.copy2(from_file, to_file)
>>  elif int(os.path.getmtime(from_file)) >
>> int(os.path.getmtime(to_file)):
>>  log('Copying modified %s' % from_file)
>>  counter_mod += 1
>>  shutil.copy2(from_file, to_file)
>>  elif os.path.getsize(from_file) > os.path.getsize(to_file):
>>  log('Sizes differ, but not rest: Copying %s' %
>> from_file)
>>  counter_special += 1
>>  shutil.copy2(from_file, to_file)
>>  elif os.path.getsize(from_file) < os.path.getsize(to_file):
>>  log('Orig file smaller than backup file: Copying
>> %s' % from_file)
>>  counter_special += 1
>>  shutil.copy2(to_file, backup_dir+'DIFF_SIZE')
>>  shutil.copy2(from_file, to_file)
>>  else:
>>  #log('not treated: %s' % l)
>>  pass
>>
>>  except (OSError, IOError), e:
>>  not_accessible += 1
>>  print e
>> [...]
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyro stability

2006-11-07 Thread Paul Boddie
Beliavsky wrote:
> Carl J. Van Arsdall wrote:

[Enthusiasm for Pyro, not for those with sensitivity to rude words]

> You should watch your language in a forum with thousands of readers.

It was quite an endorsement, though. ;-)

Paul

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


Re: Plot pkg - Multiple Y axes?

2006-11-07 Thread Jeremy Sanders
monkeyboy wrote:

> I'm searching for a plotting package that will allow multiple y axes of
> different scales. For example I'd like to overlay 4 or 5 time series
> with each series having a separate axis. Does anyone know of such a
> package?

My package veusz allows that... 

http://home.gna.org/veusz/

You can have any number of y-axes, see

http://home.gna.org/veusz/screenshots/screenshot1.png

The PyQt4 version is coming along nicely too...

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create global variables?-the full story

2006-11-07 Thread Alistair King
J. Clifford Dyer wrote:
>> OK...
>>
>> from the start.
>>
>> im trying to develop a simple command line application for determining
>> the degree of substitution (DS) on a polymer backbone from elemental
>> analysis, i.e., the % weights of different elements in the
>> monomer-substituent compound ( i want each element to give a result and
>> heaviest atoms give the most accurate results).
>>
>> most basic comp chem programs use input files but i dont know anything
>> about file iteration yet and want the program to be as user friendly as
>> possible..i.e. command line prompt. GUI would be great but too much for
>> me at this stage
>>
>> at the start of the script i have 2 dictionaries 1) containing every
>> atom in the periodic table with associated isotopic average masses 2)
>> containing the molecular forumla of the monomer unit...eg for cellulose
>> AGU {'C': 6, 'H': 10, 'O': 5}.
>>
>> the basic steps are
>>
>> 1. calculate the weight percentage values for each atom in the monomer
>> 2. iterate into dictionaries from DS=0 - DS=15 (0.5 step) the
>> projected % values for the monomer plus substituent, for EACH atom in
>> the compound.
>> 3. find the (local) minimum from each dictionary/atom to give the
>> appropriate DS value.
>>
>> *Note* I have to iterate ALL the values as there is a non-linear
>> relationship between % values and DS due to the different atomic weights
>> The computer seems to cope with this in about 10 seconds with the above
>> parameters and about 8 elements for the iteration step
>>
>> 
>
> Since you have a parallel structure for each element, consider using a 
> dictionary with the element names as keys:
>
>  >>> atomicdata = {}
>  >>> for element in 'C','H','U':
> ...   atomicdata[element] = getAtomVars(element)
> ...
>  >>> print atomicdata
> { 'C': (1, 2), 'H': (4, 5), 'U': (78, 20) }
>
> The first value of each tuple will be your Xaa, and the second value 
> will be Xma.  Do you really need to keep the names Caa, Cma, Haa, Hma 
> around?  Instead of Caa, you have atomicdata['C'][0] and Cma becomes 
> atomicdata['C'][1].  Completely unambiguous.  A bit more verbose, 
> perhaps, but you don't have to try to sneak around the back side of the 
> language to find the data you are looking for.  That's very much against 
> the tao.  If you really want the names, nest dicts, but don't try to get 
> the element name into the keys, because you already have that:
>
>  >>> atomicdata = { 'C': { 'aa': 1,
> ...   'ma': 2},
> ...'H': { 'aa': 4
> ...   'ma': 5},
> ...'U': { 'aa': 78
> ...   'ma': 20} }
>
> and to get from there to storing all your data for all however many 
> steps, change the value of each entry in atomic data from a tuple (or 
> dict) to a list of tuples (or dicts).
>
>
>  >>> atomicdata = { 'C': [ (1,2), (4,6), (7,8), (20,19) ],
> ...'H': [ (5,7), (2,986), (3,4) ] }
>  >>> atomicdata['H'].append((5,9))
>  >>> atomicdata
> { 'C': [ (1, 2), (4, 6), (7, 8), (20, 19) ], 'H': [ (5, 7), (2, 986), 
> (3, 4), (5, 9) ] }
>
> You can build up those lists with nested for loops. (one tells you which 
> element you're working on, the other which iteration).
>
> The indexes of your lists, of course, will not correspond to the DS 
> values, but to the step number.  To get back to the DS number, of 
> course, let the index number be i, and calculate DS = i * 0.5
>
> That should get you off and running now.  Happy pythoning!
>
> Cheers,
> Cliff
>   
Thanks Cliff,

this is what i need, it seems to make much more sense to do this way. I
think once i learn to include datastructures within each other im gonna
try to make up this 3D 'array' (i think this is a word from C, is there
a python equivalent?) of further iterations within each iteration to
take into account the excess water. For this i think ill have to add
another 100 values onto the values i already have, i.e. 1.8x10**8
entries in total and god knows how many calculations in potentially one
datastructure. Could my computer cope with this or should i try a series
of refinement iterations? Does anyone knows of a simple way of
determining how much processer time it takes to do these calculations?

thanks

a

-- 
Dr. Alistair King
Research Chemist,
Laboratory of Organic Chemistry,
Department of Chemistry,
Faculty of Science
P.O. Box 55 (A.I. Virtasen aukio 1)
FIN-00014 University of Helsinki
Tel. +358 9 191 50392, Mobile +358 (0)50 5279446
Fax +358 9 191 50366 

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


Re: Unicode/ascii encoding nightmare

2006-11-07 Thread Paul Boddie
Thomas W wrote:
> Ok, I've cleaned up my code abit and it seems as if I've
> encoded/decoded myself into a corner ;-).

Yes, you may encounter situations where you have some string, you
"decode" it (ie. convert it to Unicode) using one character encoding,
but then you later "encode" it (ie. convert it back to a plain string)
using a different character encoding. This isn't a problem on its own,
but if you then take that plain string and attempt to convert it to
Unicode again, using the same input encoding as before, you'll be
misinterpreting the contents of the string.

This "round tripping" of character data is typical of Web applications:
you emit a Web page in one encoding, the fields in the forms are
represented in that encoding, and upon form submission you receive this
data. If you then process the form data using a different encoding,
you're misinterpreting what you previously emitted, and when you emit
this data again, you compound the error.

> My understanding of unicode has room for improvement, that's for sure. I got 
> some pointers
> and initial code-cleanup seem to have removed some of the strange results I 
> got, which
> several of you also pointed out.

Converting to Unicode for processing is a "best practice" that you seem
to have adopted, but it's vital that you use character encodings
consistently. One trick, that can be used to mitigate situations where
you have less control over the encoding of data given to you, is to
attempt to convert to Unicode using an encoding that is "conservative"
with regard to acceptable combinations of byte sequences, such as
UTF-8; if such a conversion fails, it's quite possible that another
encoding applies, such as ISO-8859-1, and you can try that. Since
ISO-8859-1 is a "liberal"  encoding, in the sense that any byte value
or combination of byte values is acceptable, it should only be used as
a last resort.

However, it's best to have a high level of control over character
encodings rather than using tricks to avoid considering representation
issues carefully.

Paul

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


Re: why does this unpacking work

2006-11-07 Thread Piet van Oostrum
> Carsten Haese <[EMAIL PROTECTED]> (CH) wrote:

>CH> On Fri, 2006-10-20 at 15:14, John Salerno wrote:

>>> What seems to be happening is that 'for x,y in t' is acting like:
>>> 
>>> for x in t:
>>> for y,z in x:
>>> #then it does it correctly

>CH> No, it's actually behaving like

>CH> for x in t:
>CH>   y,z = t
   y,z = x
>CH>   # do something with y and z

-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Ross Ridge
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> Ah, but in the case where the lock# signal is used, it's known that
> the data is not in the cache of the CPU performing the lock operation;
> I believe it is also known that the data is not in the cache of any
> other CPU. So the CPU performing the LOCK INC sequence just has
> to perform two memory cycles. No cache coherency protocol runs
> in that case.

Paul Rubin wrote:
> How can any CPU know in advance that the data is not in the cache of
> some other CPU?

In the case where the LOCK# signal is asserted the area of memory
accessed is marked as being uncachable.  In a SMP system all CPUs must
have the same mapping of cached and uncached memory or things like this
break.  In the case where the LOCK# signal isn't used, the MESI
protocol informs the CPU of which of it's cache lines might also be in
the cache of another CPU.

> OK, this is logical, but it already implies a cache miss, which costs
> many dozen (100?) cycles.  But this case may be uncommon, since one
> hops that cache misses are relatively rare.

The cost of the cache miss is the same whether the increment
instruction is locked or not.

  Ross Ridge

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


Re: using split function

2006-11-07 Thread [EMAIL PROTECTED]
Thanks a lot, I am done with that part. But now I am facing another
problem. I am using the code given below where A is a matrix and row is
a sequence. But it gives following error:

 error--
A[a,:]=row
ValueError: setting an array element with a sequence.

--code
#!/usr/bin/python
import numpy
file1 = open('matrix.txt', 'r')

count =  0
a=0
b=0
c=0
d=0
e=0
A = numpy.zeros([4,4])
while 1:
lineStr = file1.readline()
if not(lineStr):
break

count = count + 1
row=lineStr.split()
if count<=4:
A[a,:]=row
a=a+1
elif count<=8:
B[b,:]=row
b=b+1
elif count<=12:
C[c,:]=row
c=c+1
elif count<=16:
D[d,:]=row
d=d+1
elif count<=20:
E[e,:]=row
e=e+1

file1.close()
-end of code-

is there any way to change a sequence to array?
thank you
Amit

Gabriel Genellina wrote:
> > > I have to write a code in python to read a matrix from a text file and
> > > for that i am using following code. But it gives an error saying
> > > "NameError: name 'split' is not defined". Can anyone help me with this.
>
> A few hints:
> - don't use "file" as a name - it shadows the builtin "file" type
> - matrix.close() won't work, perhaps you meant file.close()?
>
> > > -
> > > Also, i want to initialize the matrix A by zeros, but using A=zeros([4,
> > > 4]) was giving a similar error "NameError: name 'zeros' is not
> > > defined".
>
> Oh, so *that's* why you build it using standard_normal and then
> overwrite the contents!
>
>
> --
> Gabriel Genellina
> Softlab SRL
>
> __
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

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


Python, PHP Developers required for a company in Bangalore.

2006-11-07 Thread prabhusanthanam
Python, PHP  Developers  required for a company in Bangalore.
Hi,


We have immediate requirements for Python, PHP 
Developers with our client in Bangalore.

Skillset : Linux/ Solaris/ FreeBSD/ etc. 
Apache HTTP Server, MySQL Database ,
 PHP , Ruby , Ruby on Rails Web Framework, 
Python Programming Language ,
Tcl / Expect Programming Language

Experience   : 5+ years.
Education: BE/Btech/ME/M.Tech/MCA.
Job Type : Permanent
Job Location : Bangalore.
 

If interested in this opportunity 
kindly email your updated CV with 
contact numbers to andre_unix@
yahoo.com


Do mention in the subject line
"Resume for Python, PHP Developers requirement in Bangalore."


Request you to kindly provide the following details
required by the client while applying:


Experience:
Current CTC :
Expected CTC:
Lead time to Join:
Current Company and Location:


thank you,
Ganesh C


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


__init__ function problem

2006-11-07 Thread kelin,[EMAIL PROTECTED]
Hi,

Today I read the following sentences, but I can not understand what
does the __init__ method of a class do?
__init__ is called immediately after an instance of the class is
created. It would be tempting but incorrect to call this the
constructor of the class. It's tempting, because it looks like a
constructor (by convention, __init__ is the first method defined for
the class), acts like one (it's the first piece of code executed in a
newly created instance of the class), and even sounds like one ("init"
certainly suggests a constructor−ish nature). Incorrect, because the
object has already been constructed by the time __init__ is called, and
you already have a valid reference to the new instance of the class.
But __init__ is the closest thing you're going to get to a constructor
in Python, and it fills much the same role.

It says the __init__ is called immediately after an instance of the
class is created. What dose "immediately" mean?
And what is difference between the init method and the constructor in
Java?

Thanks a lot!

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

Re: PIL: match for ImageMagick's display -ping

2006-11-07 Thread Steve Holden
Torsten Bronger wrote:
> Hallöchen!
> 
> I have to extract the dimensions of many bitmap files.  An old Bash
> script did it with ImageMagick's "display -ping ...".  "-ping" means
> that it extracts the image dimensions efficiently.  I suspect it
> simply doesn't read the image itself.
> 
> Now the Bash script has been transformed into Python+PIL.  Is there
> a way to get the dimensions equally efficient here, or does the PIL
> even do this optimisation implicitly since I never access the image
> bitmap itself?
> 
  >>> import Image
  >>> i = Image.open("Hello.png")
  >>> i.size
(142, 23)
  >>>

The image data isn't read until an operation requires it, so this is an 
efficient way to get its size.

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

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


Re: __init__ function problem

2006-11-07 Thread Duncan Booth
"kelin,[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> Today I read the following sentences, but I can not understand what
> does the __init__ method of a class do?
> __init__ is called immediately after an instance of the class is
> created. It would be tempting but incorrect to call this the
> constructor of the class. It's tempting, because it looks like a
> constructor (by convention, __init__ is the first method defined for
> the class), acts like one (it's the first piece of code executed in a
> newly created instance of the class), and even sounds like one ("init"
> certainly suggests a constructor−ish nature). Incorrect, because the
> object has already been constructed by the time __init__ is called, and
> you already have a valid reference to the new instance of the class.
> But __init__ is the closest thing you're going to get to a constructor
> in Python, and it fills much the same role.

I don't know where you read that, but it is wrong (or at least out of 
date). The closest thing you are going to get to a constructor in Python is 
actually the constructor '__new__'. Mostly though you don't need to worry 
about __new__ in Python.

> 
> It says the __init__ is called immediately after an instance of the
> class is created. What dose "immediately" mean?

It means that when you call:

x = SomeClass()

the interpreter first calls the constructor SomeClass.__new__, and then 
immediately calls the initialiser SomeClass.__init__ on the newly created 
object, and after that it returns the newly created object.

A constructor creates an object and returns it, an initialiser initialises 
an existing object and does not return anything.

The constructor has the power to control how the memory for the object is 
allocated (e.g. in Python it could return an already existing object 
instead of creating a new one, but in that case the initialiser will be 
called again on the existing object).

The initialiser usually sets up the attributes on a newly created object, 
but for immutable objects (e.g. tuple) the attributes must be set by the 
constructor.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Joe Seigh
Paul Rubin wrote:
> robert <[EMAIL PROTECTED]> writes:
> 
>>>I don't want to discourage you but what about reference
>>>counting/memory
>>>management for shared objects? Doesn't seem fun for me.
>>
>>in combination with some simple locking (anyway necessary) I don't
>>see a problem in ref-counting.
>>If at least any interpreter branch has a pointer to the (root)
>>object in question the ref-count is >0. 
>>Question Besides: do concurrent INC/DEC machine OP-commands execute
>>atomically on Multi-Cores as they do in Single-Core threads?
> 
> 
> Generally speaking, no, the inc/dec instructions are not atomic.  You
> can do an atomic increment on the x86 using LOCK XCHG (or maybe LOCK
> INC is possible).  The thing is that the locking protocol that
> guarantees atomicity is very expensive, like 100x as expensive as an
> unlocked instruction on a big multiprocessor.  So yes, of course you
> could accomplish reference counting through locks around the ref
> counts, but performance suffers terribly.  The solution is to get rid
> of the ref counts and manage the entire heap using garbage collection.

Atomic increment and decrement instructions are not by themselves
sufficient to make reference counting safe.  It's what Boost::shared_ptr
uses to make itself internally thread-safe but it's not safe to copy
a shared_ptr without "owning" it. Not like Java where you can safely
copy a reference (Java pointer) no matter what.

Basically there's a race condition where an object containing the
refcount can be deleted between the time you load a pointer to
the object and the time you increment what used to be a refcount
and is possibly something else but definitely undefined.

I have an experimental refcounting implementation at
http://atomic-ptr-plus.sourceforge.net/


> 
> For stuff like dictionary access, there are protocols (again based on
> LOCK XCHG) that don't require locking for lookups.  Only updates
> require locking.  Simon Peyton-Jones has a good paper about how it's
> done in Concurrent Haskell:
> 
>   http://research.microsoft.com/~simonpj/papers/stm/stm.pdf
> 
> This is really cool stuff and has found its way into Perl 6.  I'd like
> to see Python get something like it.

That seems to be about STM (Software Transactional Memory).  What you're
describing seems to be read lock-free using what I call PDR
(PCOW (Partial Copy On Write) Deferred Reclaimation).  Examples of PDR
are RCU (used in Linux kernel),  Maged Michael's SMR hazard pointers,
and thread-safe GC (used in Java's concurrent collections java.util.concurrent).

You can also use PDR to manage safe refcounting ,e.g. RCU based refcounting, 
rcuref,
in the Linux kernel.

-- 
Joe Seigh

When you get lemons, you make lemonade.
When you get hardware, you make software. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shutil: permission denied errors on windows

2006-11-07 Thread [EMAIL PROTECTED]

Antoine De Groote schrieb:

> Yes it's strange, I never had the problem before, either. It seems now
> to be only the case for folders. A very simple
>
> shutil.copy('a', 'b')
>
> already fails with the error message.
>
> I reinstalled Python, but that didn't change anything...
>
> Regards,
> antoine
>

Just a guess, update you virus scanner. Maybe someone sits in the back
and doesn't like what you are doing.

Regards Jürgen

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

Re: sound processing modules in python - anyone?

2006-11-07 Thread marc . wyburn
I've had a brief look at this and there isn't a sound orientated
library as such.  You can however use numpy to do stuff like FFTs and
there are there is a wave module in python that will allow you to
create wavs, you can google for importing wav's into numpy arrays.
This seemed like a good idea to me as I think Numpy is written in C or
C++ (or maybe it was fortran).  There seem to be a lot of people using
numpy in a similar way to matlab so there is a fair ammount of the
standard DSP routines have already been written.


[EMAIL PROTECTED] wrote:
> Hi everyone,
> I'm looking for a module for sound processing (manipulating sound objets,
> filters, ffts etc.).
> I tried Snack, but when i downloaded the package that was supposed to be
> for python, there was only the Tk/Tcl stuff (where's the .py ?).
> could anyone help me with that (or with any other sound module for python)?
> thanks in advance,
> g

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


Re: sound processing modules in python - anyone?

2006-11-07 Thread marc . wyburn
I've had a brief look at this and there isn't a sound orientated
library as such.  You can however use numpy to do stuff like FFTs and
there are there is a wave module in python that will allow you to
create wavs, you can google for importing wav's into numpy arrays.
This seemed like a good idea to me as I think Numpy is written in C or
C++ (or maybe it was fortran).  There seem to be a lot of people using
numpy in a similar way to matlab so there is a fair ammount of the
standard DSP routines have already been written.


[EMAIL PROTECTED] wrote:
> Hi everyone,
> I'm looking for a module for sound processing (manipulating sound objets,
> filters, ffts etc.).
> I tried Snack, but when i downloaded the package that was supposed to be
> for python, there was only the Tk/Tcl stuff (where's the .py ?).
> could anyone help me with that (or with any other sound module for python)?
> thanks in advance,
> g

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


Re: __init__ function problem

2006-11-07 Thread Steven D'Aprano
On Tue, 07 Nov 2006 05:26:07 -0800, kelin,[EMAIL PROTECTED] wrote:

> Hi,
> 
> Today I read the following sentences, but I can not understand what
> does the __init__ method of a class do?

Play around with this class and see if it helps:


class MagicStr(str):
"""Subclass of str with leading and trailing asterisks."""
def __new__(cls, value=''):
print "Calling subclass constructor __new__ ..."
# Construct a MagicStr object.
obj = super(MagicStr, cls).__new__(cls, '***' + value + '***')
print "  - inspecting constructor argument:"
print "value, id, type:", value, id(value), type(value)
print "  - inspecting constructor result:"
print "value, id, type:", obj, id(obj), type(obj)
# Create the instance, and call its __init__ method.
return obj 
def __init__(self, value):
print "Calling subclass __init__ ..."
print "  - inspecting __init__ argument:"
print "value, id, type:", value, id(value), type(value)
print "Done."


Notice that when __new__ is called, the instance doesn't exist yet, only
the class, so the first argument for __new__ is the class, not the
instance.



> __init__ is called immediately after an instance of the class is
> created. It would be tempting but incorrect to call this the
> constructor of the class. It's tempting, because it looks like a
> constructor (by convention, __init__ is the first method defined for
> the class), acts like one (it's the first piece of code executed in a
> newly created instance of the class), 

That's not quite true. For new-style classes __new__ is called before
__init__, as you can see from the MagicStr class above.


> and even sounds like one ("init"
> certainly suggests a constructor-ish nature). Incorrect, because the
> object has already been constructed by the time __init__ is called, and
> you already have a valid reference to the new instance of the class.
> But __init__ is the closest thing you're going to get to a constructor
> in Python, and it fills much the same role.

This is true for old-style classes.
 
> It says the __init__ is called immediately after an instance of the
> class is created. What dose "immediately" mean?

Once the __new__ method creates the instance and returns, before anything
else happens, the instance's __init__ method is called.



-- 
Steven.

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


Simple Tkinter problem

2006-11-07 Thread gmarkowsky
Hi all,

I'm trying to write a GUI that will put up multiple widgets in
succession. My problem is that each widget also contains the previous
widgets when they pop up. How do I reinitialize the widget each time so
that it doesn't contain earlier ones? Actually, another question I have
is, is there a way to set python so that it will assume any undefined
variable is 0 or ''? That is, I have several statements like "If k > 0
then so and so" and I would like it to assume k=0 unless I tell it
otherwise. I've just been defining k=0 at the start of the program but
it seems there should be a better way.

Greg

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


Re: create global variables?-the full story

2006-11-07 Thread Steven D'Aprano
On Tue, 07 Nov 2006 12:54:36 +0200, Alistair King wrote:

> Does anyone knows of a simple way of
> determining how much processer time it takes to do these calculations?


See the timeit module.

-- 
Steven.

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Martin v. Löwis
Paul Rubin schrieb:
> "Martin v. Löwis" <[EMAIL PROTECTED]> writes:
>> Ah, but in the case where the lock# signal is used, it's known that
>> the data is not in the cache of the CPU performing the lock operation;
>> I believe it is also known that the data is not in the cache of any
>> other CPU. So the CPU performing the LOCK INC sequence just has
>> to perform two memory cycles. No cache coherency protocol runs
>> in that case.
> 
> How can any CPU know in advance that the data is not in the cache of
> some other CPU?

AFAIU, the lock# line, in P6, is only used for memory regions that
are marked non-cacheable. The CPU determines a memory region to be
non-cacheable if either the memory-type register (MTRR) says it's
non-cacheable, or if the not-cached bit in the page table is set.

If a certain location is known to be modified a lot from different
CPUs (e.g. a spin lock), it might be best if the operating system
sets the page where this location lives as non-cacheable - it might
be more performant to always modify it through the main memory,
than having cache coherence deal with it.

> OK, this is logical, but it already implies a cache miss, which costs
> many dozen (100?) cycles.  But this case may be uncommon, since one
> hops that cache misses are relatively rare.  

Right - I'm completely uncertain as to what the cost of a cache miss
is, in terms of internal cycles. E.g. how many memory cycles does
the CPU have to perform to fill a cache line? And what is the ratio
between memory cycles and CPU cycles?

> IIRC, the SPJ paper that I linked claims that lock-free protocols
> outperform traditional lock-based ones even with just two processors.
> But maybe things are better with a dual core processor (shared cache)
> than with two separate packages.

Likely, yes. Although different dual-core designs are out there, some
of them not using a shared cache, but two individual ones.

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


Re: sqlite error?

2006-11-07 Thread John Salerno
Frank Millman wrote:

> Definitely not. You could have a sql command like this -
> 
> cur.execute("UPDATE table SET col1 = ?, col2 = ? WHERE col3 = ? AND
> col4 = ?",(1,2,3,4))
> 
> The parameters could be scattered throughout the command. Therefore the
> substitution is one-for-one from left to right using the values in the
> tuple.
>

Thanks! The example I was looking at in the docs didn't use parentheses, 
but I also didn't connect that with the fact that it was only using a 
one-tuple! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Tkinter problem

2006-11-07 Thread Neil Cerutti
On 2006-11-07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I'm trying to write a GUI that will put up multiple widgets in
> succession. My problem is that each widget also contains the
> previous widgets when they pop up. How do I reinitialize the
> widget each time so that it doesn't contain earlier ones?

Show your code.

> Actually, another question I have is, is there a way to set
> python so that it will assume any undefined variable is 0 or
> ''? That is, I have several statements like "If k > 0 then so
> and so" and I would like it to assume k=0 unless I tell it
> otherwise. I've just been defining k=0 at the start of the
> program but it seems there should be a better way.

The best way to do it is to never use undefined names.

-- 
Neil Cerutti
If only faces could talk. --Pat Summerall
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: forwarding *arg parameter

2006-11-07 Thread Tuomas
Steven D'Aprano wrote:
> On Mon, 06 Nov 2006 13:03:55 +, Tuomas wrote:
> 
> 
>>If you read the whole chain you find out what we were talking of.
> 
> 
> I had already read the whole thread, and I've read it again in case I
> missed something the first time, and I still have no idea why you think
> you need to do this. You explain *what* you want to do, but not *why* you
> want to do it.

Redirecting a funtion parameter to an other function is a quite common 
situation in programming. Here the question was forwarding *args 
parameter. Have you ever tried this and found the difference in cases:

def f(*args):
 x = g(args)  # how g sees arguments in this case
 x = g(*args) # and how it sees them in this case

I am happy with what Dennis Lee Bieber wrote in the second latest node 
in this chain. So luckily my "flattern" is not needed because the 
problem I had can be solved in the calling function.

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


Re: __init__ function problem

2006-11-07 Thread babui

Steven D'Aprano ha escrit:

> Once the __new__ method creates the instance and returns, before anything
> else happens, the instance's __init__ method is called.

This only happens when the object created by __new__ isinstance of the
class invoked in the creation statement, that is:

s=MagicStr("lala")

executes:

s = MagicStr.__new__(MagicStr, "lala")
if isinstance(s, MagicStr):
type(s).__init__(s, "lala")

--
Juan M. Gimeno

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


Barry Warsaw giving Python talk at NASA

2006-11-07 Thread A.M. Kuchling
This is at the Goddard campus:


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


Re: Simple Tkinter problem

2006-11-07 Thread gmarkowsky
Here's my Tkinter class:

class TwoChoice:
def __init__(self, master):

frame = Frame(master)
frame.pack()
m = Label(root, text= maentry)
m.pack()
n = Label(root, text= fave)
n.pack()

self.button = Button(frame, text=home_team, command=
self.comm_1)
self.button.pack(side=LEFT)

self.hi_there = Button(frame, text=vis_team,
command=self.comm_2)
self.hi_there.pack(side=LEFT)

def comm_1(self):
print home_team
root.quit()

def comm_2(self):
print vis_team
root.quit()

I call it by

root = Tk()
gui= TwoChoice(root)
root.mainloop()

The next time I call it I want to just run the same thing but with
different values for the variables. Instead it gives me like two copies
of the widget.

Greg

Neil Cerutti wrote:
> On 2006-11-07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > I'm trying to write a GUI that will put up multiple widgets in
> > succession. My problem is that each widget also contains the
> > previous widgets when they pop up. How do I reinitialize the
> > widget each time so that it doesn't contain earlier ones?
>
> Show your code.
>
> > Actually, another question I have is, is there a way to set
> > python so that it will assume any undefined variable is 0 or
> > ''? That is, I have several statements like "If k > 0 then so
> > and so" and I would like it to assume k=0 unless I tell it
> > otherwise. I've just been defining k=0 at the start of the
> > program but it seems there should be a better way.
>
> The best way to do it is to never use undefined names.
> 
> -- 
> Neil Cerutti
> If only faces could talk. --Pat Summerall

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


Re: __div__ not recognized automatically

2006-11-07 Thread Anton81
> If you have the
> 
> from __future__ import division
> 
> statement, you need to override __truediv__(), not __div__()

That worked after I also added
from __future__ import division
to all other modules I created.

Is it possible that there appears an inconsistency if the division is
imported in only some of the modules?

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


Re: Simple Tkinter problem

2006-11-07 Thread jim-on-linux

Greg,

Run the following code to see how pack_forget() or 
grid_forget() works, it makes previous widgets 
disappear but not go away.  If you call grid() or 
pack() again after using grid_forget() the widget 
returns. 


root = Tk()
class Ktest:
def __init__(self):
self.Ftest1()

def  Ftest1(self):

try:
self.test2.grid_forget()
except AttributeError :
pass
self.test1 = Button(root, text='Push #1
   button', bg = 'yellow', width = 25,
command = self.Ftest2,
 height = 25)
self.test1.grid(row=0, column=0)


def Ftest2(self):
   self.test1.grid_forget()
   self.test2 = Button(root, text='Push #2 
   button', bg = 'green',
 width = 15,
command = self.Ftest1,
 height = 10)
   self.test2.grid(row=0, column=0)

if __name__==  '__main__' :
Ktest()
mainloop()



Maybe someone else has an idea about not defining 
a variable.  

My question is how does a budket of wires and 
screws know its a bucket of wires and screws 
unless someone tells it that it's a bucket of 
wires and screws? 








On Tuesday 07 November 2006 09:35, 
[EMAIL PROTECTED] wrote:
> Hi all,
>
> I'm trying to write a GUI that will put up
> multiple widgets in succession. My problem is
> that each widget also contains the previous
> widgets when they pop up. How do I reinitialize
> the widget each time so that it doesn't contain
> earlier ones? Actually, another question I have
> is, is there a way to set python so that it
> will assume any undefined variable is 0 or ''?
> That is, I have several statements like "If k >
> 0 then so and so" and I would like it to assume
> k=0 unless I tell it otherwise. I've just been
> defining k=0 at the start of the program but it
> seems there should be a better way.
>
> Greg
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with installing soappy module on Python 2.4.3 (windows machine)

2006-11-07 Thread [EMAIL PROTECTED]
Hi Folks,


I want to install the SOAPpy module on my windows box. I have python
2.4.3

Can you help me with the steps and the URL from where can I get the
download..??

TIA.

Regards,
Asrarahmed

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Ross Ridge
Joe Seigh wrote:
> Basically there's a race condition where an object containing the
> refcount can be deleted between the time you load a pointer to
> the object and the time you increment what used to be a refcount
> and is possibly something else but definitely undefined.

That doesn't really make sense.  The object can't be deleted because
the thread should already have a reference (directly or indirectly) to
the object, otherwise any access to it can cause the race condition you
describe.

  Ross Ridge

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


ftplib security support

2006-11-07 Thread vedran
Hello,

One simple question.Which security ftplib support,and how to I 'load'
these security to ftputil.
(Please don't give me security modules)

e.g.


ftp=FTPHost('myhost','myusername','mypassword',session_factory=ftplib.FTP)

 is this example well?  (for loading ftplib security to ftputil)






Thanks

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


But it was yesterday here!

2006-11-07 Thread Sorin Schwimmer
(the quote is from 'Le gendarme et les extra-terrestres', a must-see Frech comedy)Hi All,I'm trying to use the smtplib - I did it so many times already. The import statement fails, as theSMTP name cannot be imported. Digging more, I found that SMTP fails becauseemail.base64MIME cannot be imported (ImportError:No module named base64MIME).I don't understand why, as the file is in the right location, has the correct access rights (I'm onLinux), and it's content is not corrupt. I also tried to import email.__init__ and end up with the same error.The only way that works is to navigate to the email directory and perform the import base64MIME there.What may have happened?Thanks,Sorin-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Plot pkg - Multiple Y axes?

2006-11-07 Thread [EMAIL PROTECTED]
You can try matplotlib. It allows multiple plots in one window. To get
the correct rendering of the axis layout needs probably some handwork,
but it should be possible. Two axis are not a problem at all. Got
through the examples and take a look at the wiki cookbook.
All is available at http://matplotlib.sourceforge.net/

Cheers! Bernhard

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


Re: sound processing modules in python - anyone?

2006-11-07 Thread [EMAIL PROTECTED]
Hi,

you might want to take a look at pyaudio. A module to read and write
audio files. It is based on numpy and wraps the libsndfile library to
use it from python. With the capabilites of numpy and scipy you
probably have all you need.

Here's a link to pyaudio
http://www.ar.media.kyoto-u.ac.jp/members/david/softwares/pyaudio/index.html
Here you find numpy and scipy: http://scipy.org/SciPy

Enjoy! Bernhard

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Joe Seigh
Ross Ridge wrote:
> Joe Seigh wrote:
> 
>>Basically there's a race condition where an object containing the
>>refcount can be deleted between the time you load a pointer to
>>the object and the time you increment what used to be a refcount
>>and is possibly something else but definitely undefined.
> 
> 
> That doesn't really make sense.  The object can't be deleted because
> the thread should already have a reference (directly or indirectly) to
> the object, otherwise any access to it can cause the race condition you
> describe.
> 

True but if the thread didn't already have a reference, how would you get
that initial reference to a shared object without a lock?


-- 
Joe Seigh

When you get lemons, you make lemonade.
When you get hardware, you make software. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shutil: permission denied errors on windows

2006-11-07 Thread John Henry
Okay, it's always good that strange things are repeatable and happens
with simple scripts.

Are you saying "a" is a folder?  So, the failure is only with copying
folder?  Not individual file?



Antoine De Groote wrote:
> Yes it's strange, I never had the problem before, either. It seems now
> to be only the case for folders. A very simple
>
> shutil.copy('a', 'b')
>
> already fails with the error message.
>
> I reinstalled Python, but that didn't change anything...
>
> Regards,
> antoine
>
> John Henry wrote:
> > I use the copy function a lot and never have problem.  I suggest that
> > you write a no brainer standalone test code and if it still fails
> > there, then you have a problem with your installation.
> >
> > Antoine De Groote wrote:
> >> Google tells quite some things about it, but none of them are satisfactory.
> >>
> >> I'm on Windows, and shutil operations (e.g. move, copy) throw [Errno 13]
> >> Permission denied all the time, for the source files. It seems that this
> >> is the case for all my files. But what I don't understand is that
> >> yesterday it still worked. I didn't change anything on my system though
> >> (at least not that I am aware of). I restarted the computer several
> >> times to see if that helped, but it didn't. Also I can't find a process
> >> that would be using the files...
> >>
> >> Has anybody experienced this problem before, or have a solution?
> >>
> >> Kind regards,
> >> antoine
> >>
> >> Here's the code that throws the errors
> >>
> >> [...]
> >> for l in files:
> >>  from_file = os.path.join(dir, l)
> >>  to_file = from_file.replace(tree_top, backup_dir)
> >>  try:
> >>  if not os.path.exists(to_file):
> >>  log('Copying new  %s' % from_file)
> >>  counter_new += 1
> >>  shutil.copy2(from_file, to_file)
> >>  elif int(os.path.getmtime(from_file)) >
> >> int(os.path.getmtime(to_file)):
> >>  log('Copying modified %s' % from_file)
> >>  counter_mod += 1
> >>  shutil.copy2(from_file, to_file)
> >>  elif os.path.getsize(from_file) > 
> >> os.path.getsize(to_file):
> >>  log('Sizes differ, but not rest: Copying %s' %
> >> from_file)
> >>  counter_special += 1
> >>  shutil.copy2(from_file, to_file)
> >>  elif os.path.getsize(from_file) < 
> >> os.path.getsize(to_file):
> >>  log('Orig file smaller than backup file: Copying
> >> %s' % from_file)
> >>  counter_special += 1
> >>  shutil.copy2(to_file, backup_dir+'DIFF_SIZE')
> >>  shutil.copy2(from_file, to_file)
> >>  else:
> >>  #log('not treated: %s' % l)
> >>  pass
> >>
> >>  except (OSError, IOError), e:
> >>  not_accessible += 1
> >>  print e
> >> [...]
> >

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


Re: But it was yesterday here!

2006-11-07 Thread Gabriel Genellina

At Tuesday 7/11/2006 13:24, Sorin Schwimmer wrote:

I'm trying to use the smtplib - I did it so many times already. The 
import statement fails, as the

SMTP name cannot be imported. Digging more, I found that SMTP fails because
email.base64MIME cannot be imported (ImportError:No module named base64MIME).
I don't understand why, as the file is in the right location, has 
the correct access rights (I'm on
Linux), and it's content is not corrupt. I also tried to import 
email.__init__ and end up with the same error.


The only way that works is to navigate to the email directory and 
perform the import base64MIME there.


What may have happened?


I bet you have an email.py somewhere in your sources...


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

ChiPy Monthly Meeting, Thursday 7:00 pm.

2006-11-07 Thread bray
Thursday November 9 2006. 7:00 pm.

This may be our best meeting yet. This is our regular Thurs. meeting. In
addition stay tuned for a special meeting to welcome Ed Leafe 
http://chipy.org/EdOnDabo.

Please ping the list to tell us what you want to address in your
lightning talk. Lets try to get one talk from each brave soul for about
5 minutes
a piece.

Topics
--

- Python Mock Library - fawad
- Web log generation and parsing
- lightning talks

Location


Daisychain - 2159 W 21st Pl, Chicago il 60608 http://www.dai5ychain.net/
map - http://tinyurl.com/ybdcxb

About ChiPy
---

ChiPy is a group of Chicago Python Programmers, l33t, and n00bs.
Meetings are held monthly at various locations around Chicago.
Also, ChiPy is a proud sponsor of many Open Source and Educational
efforts in Chicago. Stay tuned to the mailing list for more info.

ChiPy website: 
ChiPy Mailing List: 
Python website: 

---


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


ChiPy (Special) Meeting, Tuesday 14th 5:30 pm.

2006-11-07 Thread bray
NOTE: This is a special meeting on next Tuesday in addition to our
normal Thursday meeting. Attend both, if you can. 

Tuesday. November 14 2006. 5:30 pm. 

Topics
--

Ed Leaf on Dabo is an open-source framework for developing desktop
(i.e., rich client) applications in Python. 

Details
===

Dabo is an open-source framework for developing desktop (i.e., rich
client) applications in Python. Its primary target is the group of
developers who come from a background in the proprietary
Microsoft-centric tools, such as Visual FoxPro and Visual Basic, but it
also targets Delphi, Filemaker, and other desktop application
development systems who want rich client applications that run
unmodified on Windows, Linux and OS X.

The focus of the talk will be on the visual tools available in Dabo to
help you quickly develop serious database applications in Python. Parts
of the talk will also be directed toward existing wxPython developers
who love the results of working with that UI toolkit, but who hate the
non-Pythonic interface. 


Location


Monadnock Building at 53 W. Jackson in downtown Chicago: 
Conference Room 826.

Alternatively, if we need more space, we will relocate to the restaurant
on the first floor: http://www.cavanaughschicago.com. We will leave a
note with the gaurd in case we relocate.

RSVP to carl at personnelware.com  

Stay tuned to the mailing list for more details. 
http://mail.python.org/mailman/listinfo/chicago


About ChiPy
---

ChiPy is a group of Chicago Python Programmers, l33t, and n00bs.
Meetings are held monthly at various locations around Chicago.
Also, ChiPy is a proud sponsor of many Open Source and Educational
efforts in Chicago. Stay tuned to the mailing list for more info.

ChiPy website: 
ChiPy Mailing List: 
Python website: 

---


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


Re: shutil: permission denied errors on windows

2006-11-07 Thread Antoine De Groote
Yes, that's exactly what was the case... But see my other post, that 
straightens things up...

Thanks!
antoine


John Henry wrote:
> Okay, it's always good that strange things are repeatable and happens
> with simple scripts.
> 
> Are you saying "a" is a folder?  So, the failure is only with copying
> folder?  Not individual file?
> 
> 
> 
> Antoine De Groote wrote:
>> Yes it's strange, I never had the problem before, either. It seems now
>> to be only the case for folders. A very simple
>>
>> shutil.copy('a', 'b')
>>
>> already fails with the error message.
>>
>> I reinstalled Python, but that didn't change anything...
>>
>> Regards,
>> antoine
>>
>> John Henry wrote:
>>> I use the copy function a lot and never have problem.  I suggest that
>>> you write a no brainer standalone test code and if it still fails
>>> there, then you have a problem with your installation.
>>>
>>> Antoine De Groote wrote:
 Google tells quite some things about it, but none of them are satisfactory.

 I'm on Windows, and shutil operations (e.g. move, copy) throw [Errno 13]
 Permission denied all the time, for the source files. It seems that this
 is the case for all my files. But what I don't understand is that
 yesterday it still worked. I didn't change anything on my system though
 (at least not that I am aware of). I restarted the computer several
 times to see if that helped, but it didn't. Also I can't find a process
 that would be using the files...

 Has anybody experienced this problem before, or have a solution?

 Kind regards,
 antoine

 Here's the code that throws the errors

 [...]
 for l in files:
  from_file = os.path.join(dir, l)
  to_file = from_file.replace(tree_top, backup_dir)
  try:
  if not os.path.exists(to_file):
  log('Copying new  %s' % from_file)
  counter_new += 1
  shutil.copy2(from_file, to_file)
  elif int(os.path.getmtime(from_file)) >
 int(os.path.getmtime(to_file)):
  log('Copying modified %s' % from_file)
  counter_mod += 1
  shutil.copy2(from_file, to_file)
  elif os.path.getsize(from_file) > 
 os.path.getsize(to_file):
  log('Sizes differ, but not rest: Copying %s' %
 from_file)
  counter_special += 1
  shutil.copy2(from_file, to_file)
  elif os.path.getsize(from_file) < 
 os.path.getsize(to_file):
  log('Orig file smaller than backup file: Copying
 %s' % from_file)
  counter_special += 1
  shutil.copy2(to_file, backup_dir+'DIFF_SIZE')
  shutil.copy2(from_file, to_file)
  else:
  #log('not treated: %s' % l)
  pass

  except (OSError, IOError), e:
  not_accessible += 1
  print e
 [...]
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shutil: permission denied errors on windows

2006-11-07 Thread Antoine De Groote
Thanks for your replies, guys. I found the problem now.

Actually the problem arised just before the code that I had in my 
original post.

Here are the 2 lines that mess things up. It's those that are commented 
out. If not commented, the errors were raised.

Clearly there is an error in the second line. It includes subdirs and s 
instead of files and f. Took me 2 days to finally see it.

for dir, subdirs, files in os.walk(tree_top):

# subdirs[:] = [s for s in subdirs if 
os.path.join(dir,s).replace('\\', '/') not in excluded]
# files[:] = [f for f in subdirs if 
os.path.join(dir,s).replace('\\', '/') not in excluded]

 for s in subdirs:
 bak_sub = os.path.join(dir, s).replace(tree_top, backup_dir)
 if not os.path.exists(bak_sub):
 log('Creating directory %s' % bak_sub)
 os.mkdir(bak_sub)

 for l in files:
 [code pasted earlier]...



But what still beats me is why my minimal example with folders 'a' and 
'b' didn't work... It was independent of this code...

Anyway, my program works now, and that's for the moment the most 
important thing.

Regards,
antoine

John Henry wrote:
> I use the copy function a lot and never have problem.  I suggest that
> you write a no brainer standalone test code and if it still fails
> there, then you have a problem with your installation.
> 
> Antoine De Groote wrote:
>> Google tells quite some things about it, but none of them are satisfactory.
>>
>> I'm on Windows, and shutil operations (e.g. move, copy) throw [Errno 13]
>> Permission denied all the time, for the source files. It seems that this
>> is the case for all my files. But what I don't understand is that
>> yesterday it still worked. I didn't change anything on my system though
>> (at least not that I am aware of). I restarted the computer several
>> times to see if that helped, but it didn't. Also I can't find a process
>> that would be using the files...
>>
>> Has anybody experienced this problem before, or have a solution?
>>
>> Kind regards,
>> antoine
>>
>> Here's the code that throws the errors
>>
>> [...]
>> for l in files:
>>  from_file = os.path.join(dir, l)
>>  to_file = from_file.replace(tree_top, backup_dir)
>>  try:
>>  if not os.path.exists(to_file):
>>  log('Copying new  %s' % from_file)
>>  counter_new += 1
>>  shutil.copy2(from_file, to_file)
>>  elif int(os.path.getmtime(from_file)) >
>> int(os.path.getmtime(to_file)):
>>  log('Copying modified %s' % from_file)
>>  counter_mod += 1
>>  shutil.copy2(from_file, to_file)
>>  elif os.path.getsize(from_file) > os.path.getsize(to_file):
>>  log('Sizes differ, but not rest: Copying %s' %
>> from_file)
>>  counter_special += 1
>>  shutil.copy2(from_file, to_file)
>>  elif os.path.getsize(from_file) < os.path.getsize(to_file):
>>  log('Orig file smaller than backup file: Copying
>> %s' % from_file)
>>  counter_special += 1
>>  shutil.copy2(to_file, backup_dir+'DIFF_SIZE')
>>  shutil.copy2(from_file, to_file)
>>  else:
>>  #log('not treated: %s' % l)
>>  pass
>>
>>  except (OSError, IOError), e:
>>  not_accessible += 1
>>  print e
>> [...]
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Ross Ridge
Ross Ridge wrote:
> That doesn't really make sense.  The object can't be deleted because
> the thread should already have a reference (directly or indirectly) to
> the object, otherwise any access to it can cause the race condition you
> describe.

Joe Seigh wrote:
> True but if the thread didn't already have a reference, how would you get
> that initial reference to a shared object without a lock?

The thread that shares it increments the reference count before passing
its address to directly another thread or indirectly through a shared
container.

Ross Ridge

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Martin v. Löwis
Ross Ridge schrieb:
> The thread that shares it increments the reference count before passing
> its address to directly another thread or indirectly through a shared
> container.

To make a specific example, consider this fragment from
Objects/fileobject.c:

static PyObject *
file_repr(PyFileObject *f)
{
if (PyUnicode_Check(f->f_name)) {
...

Now, assume there wasn't a GIL protecting this all, and also
assume f_name was a mutable member (which it currently isn't).

Then, this access wouldn't be thread-safe: This code roughly
translates to

reg_x = f->f_name
push reg_x
call PyUnicode_Check (assuming this was a function and
not a macro)

Meanwhile, another process might perform

old = f->f_name;
f->f_name = new;
Py_DECREF(old);

i.e. change the file name. Now, it might be that they
interleave this way:

reg_x = f->f_name
old = f->f_name
f->f_name = new
Py_DECREF_old
push reg_x
call PyUnicode_Check

which would now operate on a deallocated object.

To fix this, one might think that we need

   Py_INCREF(f->f_name)
   if(Py_UnicodeCheck(f->f_name))
   ...
   Py_DECREF(f->f_name)

However, this would not help, because the
first incref translates to

   reg_x = f->f_name
   LOCK INC f->ob_refcnt

which again leaves a race condition where the
INCREF operation comes "too late".

How would you propose to fix file_repr to prevent such
a race condition?

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


Re: [DLC] ChiPy Monthly Meeting, Thursday 7:00 pm.

2006-11-07 Thread Steve Holden
I don't suppose there's any chance that someone might be passing 
Schaumberg on their way to this meeting? I'm teaching there, and a ride 
would avoid me having to rent a car (and hence increase the probability 
I'd make it).

regards
  Steve

[EMAIL PROTECTED] wrote:
> Thursday November 9 2006. 7:00 pm.
> 
> This may be our best meeting yet. This is our regular Thurs. meeting. In
> addition stay tuned for a special meeting to welcome Ed Leafe 
> http://chipy.org/EdOnDabo.
> 
> Please ping the list to tell us what you want to address in your
> lightning talk. Lets try to get one talk from each brave soul for about
> 5 minutes
> a piece.
> 
> Topics
> --
> 
> - Python Mock Library - fawad
> - Web log generation and parsing
> - lightning talks
> 
> Location
> 
> 
> Daisychain - 2159 W 21st Pl, Chicago il 60608 http://www.dai5ychain.net/
> map - http://tinyurl.com/ybdcxb
> 
> About ChiPy
> ---
> 
> ChiPy is a group of Chicago Python Programmers, l33t, and n00bs.
> Meetings are held monthly at various locations around Chicago.
> Also, ChiPy is a proud sponsor of many Open Source and Educational
> efforts in Chicago. Stay tuned to the mailing list for more info.
> 
> ChiPy website: 
> ChiPy Mailing List: 
> Python website: 
> 
> ---
> 
> 
> ___
> DLC mailing list
> [EMAIL PROTECTED]
> http://mailman.depaul.edu/mailman/listinfo/dlc
> http://linux.depaul.edu/
> 


-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


But it was yesterday here!

2006-11-07 Thread Sorin Schwimmer
> I bet you have an email.py somewhere in your sources... You won the bet. I owe you one :-)Thanks,Sorin-- 
http://mail.python.org/mailman/listinfo/python-list

os.path.exists and unicode filenames

2006-11-07 Thread Peter Bienstman
Hi,

I'm trying to add support for unicode file names to my application.

I'm running into problems with e.g. the os.path.exists routine, which 
complains if it gets passed a unicode string:

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/mnemosyne/pyqt_ui/main_dlg.py", line 
149, in fileNew
if os.path.exists(out):
  File "/usr/lib/python2.4/posixpath.py", line 171, in exists
st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 24-29: 
ordinal not in range(128)

I could try encoding the string in utg-8, but then it wouldn't work under 
Windows.

Is there an elegant cross-platform solution for this?

Thanks!

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


Re: assigning values in __init__

2006-11-07 Thread John Salerno
John Salerno wrote:

> Is this a good way to assign the values to the different attributes? 
> Should 'stats' be a list/tuple (like this), or should I do *stats instead?

Thanks guys! The main suggestion seems to be to use setattr(), so I 
might give that a try. But I do like Steve's suggestion that it's better 
to be explicit about each attribute, instead of just accepting a list of 
numbers (but I can't help but feel that for some reason this is better, 
because it's more general). We shall see! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


object data member dumper?

2006-11-07 Thread tom arnall
does anyone know of a utility to do a recursive dump of object data members?


-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: os.path.exists and unicode filenames

2006-11-07 Thread Martin v. Löwis
Peter Bienstman schrieb:
> UnicodeEncodeError: 'ascii' codec can't encode characters in position 24-29: 
> ordinal not in range(128)
> 
> I could try encoding the string in utg-8, but then it wouldn't work under 
> Windows.
> 
> Is there an elegant cross-platform solution for this?

I assume you are using some Unix version here. If so, you should set up
the locale correctly. For example, if you set LANG to a UTF-8 locale
supported by your operating system, this (passing Unicode strings to
os.path.exists etc) works just fine.

Python follows the Unix convention that the locale defines how to
interpret characters, in particular for file names.

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


Character encoding

2006-11-07 Thread mp
I have html document titles with characters like >,  , and
‡. How do I decode a string with these values in Python?

Thanks

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


C wrapper

2006-11-07 Thread Sheldon
Hi,

Can anyone give me some idea as to what this error means?

"ImportError: dynamic module does not define init function "

I am new at this and there is still a lot to learn.

Any help is appreciated,

/Sheldon

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


Re: Character encoding

2006-11-07 Thread i80and
I would suggest using string.replace.  Simply replace ' ' with ' '
for each time it occurs.  It doesn't take too much code.

On Nov 7, 1:34 pm, "mp" <[EMAIL PROTECTED]> wrote:
> I have html document titles with characters like >,  , and
> ‡. How do I decode a string with these values in Python?
> 
> Thanks

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


changing sequence to array

2006-11-07 Thread [EMAIL PROTECTED]
Hi,
I am using the code given below where A is a matrix and row is a
sequence. But it gives following error:

 error--
A[a,:]=row
ValueError: setting an array element with a sequence.

--code
#!/usr/bin/python
import numpy
file1 = open('matrix.txt', 'r')

count =  0
a=0
b=0
c=0
d=0
e=0
A = numpy.zeros([4,4])
B= numpy.zeros([4,4])
C = numpy.zeros([4,4])
D = numpy.zeros([4,4])
E = numpy.zeros([4,4])
while 1:
lineStr = file1.readline()
if not(lineStr):
break

count = count + 1
row=lineStr.split()
if count<=4:
A[a,:]=row
a=a+1
elif count<=8:
B[b,:]=row
b=b+1
elif count<=12:
C[c,:]=row
c=c+1
elif count<=16:
D[d,:]=row
d=d+1
elif count<=20:
E[e,:]=row
e=e+1

file1.close()
-end of code-

is there any way to change a sequence to array so that the above
operation could be executed?
thank you
Amit

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


Re: __init__ function problem

2006-11-07 Thread Carl Banks
kelin,[EMAIL PROTECTED] wrote:
> It says the __init__ is called immediately after an instance of the
> class is created. What dose "immediately" mean?
> And what is difference between the init method and the constructor in
> Java?

For all intents and purposes, __init__ is a constructor.  It isn't
technically, but you use it exactly the same way you use constructors
in C++ and Java (well, acutally, Python __init__ is a quite bit more
flexible, though also less convenient in many cases).  Don't worry that
it isn't called a constructor.

In Python, the real constructor is called __new__, but you shouldn't
use __new__ like C++ and Java constructors.  Usually there's no reason
to use __new__ at all.  (The main use case is to return something other
than a newly created object, such as a preallocated or cached object.
For your normally functioning classes, you should use __init__.)


Carl Banks

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


Re: C wrapper

2006-11-07 Thread Farshid Lashkari
Sheldon wrote:
> Can anyone give me some idea as to what this error means?
> 
> "ImportError: dynamic module does not define init function "
> 
> I am new at this and there is still a lot to learn.
> 
> Any help is appreciated,

Take a look at the documentation for creating extension modules, 
especially the following page:

http://docs.python.org/ext/methodTable.html

"The initialization function must be named initname(), where name is the 
name of the module, and should be the only non-static item defined in 
the module file"

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


Tired of spam, unrelated email?

2006-11-07 Thread JFletcher



Post you questions on the python forum at http://www.thescripts.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Ross Ridge

Martin v. Löwis wrote:
> How would you propose to fix file_repr to prevent such
> a race condition?

The race condition you describe is different from the one Joe Seigh
described.  It's caused because without GIL access to the file object
is no longer thread safe, not because reference counting isn't thread
safe.

  Ross Ridge

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

Re: Character encoding

2006-11-07 Thread mp
I'd prefer a more generalized solution which takes care of all possible
ampersand characters. I assume that there is code already written which
does this.

Thanks

i80and wrote:
> I would suggest using string.replace.  Simply replace ' ' with ' '
> for each time it occurs.  It doesn't take too much code.
>
> On Nov 7, 1:34 pm, "mp" <[EMAIL PROTECTED]> wrote:
> > I have html document titles with characters like >,  , and
> > ‡. How do I decode a string with these values in Python?
> > 
> > Thanks

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


Re: C wrapper

2006-11-07 Thread Sheldon

Farshid Lashkari skrev:

> Sheldon wrote:
> > Can anyone give me some idea as to what this error means?
> >
> > "ImportError: dynamic module does not define init function "
> >
> > I am new at this and there is still a lot to learn.
> >
> > Any help is appreciated,
>
> Take a look at the documentation for creating extension modules,
> especially the following page:
>
> http://docs.python.org/ext/methodTable.html
>
> "The initialization function must be named initname(), where name is the
> name of the module, and should be the only non-static item defined in
> the module file"
>
> -Farshid

This function is there and is called init_mymodule() but I have other
functions that are not static.
Could this be the cause?

/Sheldon

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


Re: C wrapper

2006-11-07 Thread Robert Kern
Sheldon wrote:

> This function is there and is called init_mymodule() but I have other
> functions that are not static.

Is the module's name "_mymodule"? Or is it "mymodule"?

-- 
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: Character encoding

2006-11-07 Thread Gabriel Genellina

At Tuesday 7/11/2006 17:10, mp wrote:


I'd prefer a more generalized solution which takes care of all possible
ampersand characters. I assume that there is code already written which
does this.


Try the htmlentitydefs module


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tired of spam, unrelated email?

2006-11-07 Thread skip

Tired of spam, unrelated email?

You mean, like your message?

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


Re: C wrapper

2006-11-07 Thread Sheldon

Robert Kern skrev:

> Sheldon wrote:
>
> > This function is there and is called init_mymodule() but I have other
> > functions that are not static.
>
> Is the module's name "_mymodule"? Or is it "mymodule"?
>
> --
> 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

Here is the file/module name: _msgpps_functions.c
Here is the initfunction:

PyMODINIT_FUNC init_msgpps_functions(void) {
  PyObject* m;
  m=Py_InitModule("_msgpps_functions",_msgpps_functionsMethods);
  ErrorObject = PyString_FromString("_msgpps_functions.error");
  if(ErrorObject == NULL || \
 PyDict_SetItemString(PyModule_GetDict(m),"error",ErrorObject)!=0)
{
Py_FatalError("Can't define _msgpps_functions.error");
import_array();
  } /*  access to Numeric PyArray functions */
}


I have not main() function in the file. Instead the main function is
called the same name:

static PyObject* _msgpps_functions(PyObject* self, PyObject* args)

Now I am new at this and I have been reading anything I can find. The
only thing that is out of place is the part which I didn't include:

/* Initialize the Python interpreter.  Required. */
Py_Initialize();

/* Add a static module */
initspam();
because I still don't understand this part.

/sheldon

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


Re: C wrapper

2006-11-07 Thread Gabriel Genellina

At Tuesday 7/11/2006 17:10, Sheldon wrote:


> Take a look at the documentation for creating extension modules,
> especially the following page:
>
> http://docs.python.org/ext/methodTable.html
>
> "The initialization function must be named initname(), where name is the
> name of the module, and should be the only non-static item defined in
> the module file"
>
> -Farshid

This function is there and is called init_mymodule() but I have other
functions that are not static.
Could this be the cause?


For a module called foo.c the initialization function must be called 
initfoo (*not* init_foo)
And what are those non-static functions used for? The *only* purpose 
of your module should be to provide the Python bindings...



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ctypes, python 2.5, WinFunctionType and _as_parameter_

2006-11-07 Thread Thomas Heller
[EMAIL PROTECTED] schrieb:
> Hello,
> 
> how to get at the function address of a WinFunctionType ctypes object ?
> With ctypes 1.0, I used just myfunc._as_parameter_ and all was well.
> With ctypes 1.0.1, that ships with python 2.5, WinFunctionType has no
> longer an _as_parameter_ attribute

I think the easiest way is to cast to function to a void pointer and
get the value of that.  Something like:

cast(function, c_void_p).value

> Where in the ChangeLog and the documentation is explained how to deal
> with this change ?

Hm, I considered _as_parameter_ an implementation detail ;-)

> Thanks in advance,
> 
> Gerard
> 
Thomas

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


Re: C wrapper

2006-11-07 Thread Gabriel Genellina

At Tuesday 7/11/2006 17:27, Sheldon wrote:


Here is the file/module name: _msgpps_functions.c
Here is the initfunction:

PyMODINIT_FUNC init_msgpps_functions(void) {
  PyObject* m;
  m=Py_InitModule("_msgpps_functions",_msgpps_functionsMethods);
  ErrorObject = PyString_FromString("_msgpps_functions.error");
  if(ErrorObject == NULL || \
 PyDict_SetItemString(PyModule_GetDict(m),"error",ErrorObject)!=0)
{
Py_FatalError("Can't define _msgpps_functions.error");
import_array();
  } /*  access to Numeric PyArray functions */
}


I have not main() function in the file. Instead the main function is
called the same name:

static PyObject* _msgpps_functions(PyObject* self, PyObject* args)

Now I am new at this and I have been reading anything I can find. The
only thing that is out of place is the part which I didn't include:

/* Initialize the Python interpreter.  Required. */
Py_Initialize();

/* Add a static module */
initspam();
because I still don't understand this part.


Are you *extending* Python with a new module written in C (you should 
be using the first part),
or *embedding* python inside your application, mainly written in C 
(you would use something like the last code).



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: C wrapper

2006-11-07 Thread Sheldon

Hi,

> For a module called foo.c the initialization function must be called
> initfoo (*not* init_foo)

Ok, I fixed this part. Thanks


> And what are those non-static functions used for? The *only* purpose
> of your module should be to provide the Python bindings...

I wrote the C module to do some number crunching. Now I just need to
"connect" it to my python program. Should the initmsgpps_functions() be
the only function in the file? Then how do I "connect" my C module to
my Python program?

/Sheldon

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


Re: C wrapper

2006-11-07 Thread Sheldon

Gabriel Genellina skrev:

> At Tuesday 7/11/2006 17:27, Sheldon wrote:
>
> >Here is the file/module name: _msgpps_functions.c
> >Here is the initfunction:
> >
> >PyMODINIT_FUNC init_msgpps_functions(void) {
> >   PyObject* m;
> >   m=Py_InitModule("_msgpps_functions",_msgpps_functionsMethods);
> >   ErrorObject = PyString_FromString("_msgpps_functions.error");
> >   if(ErrorObject == NULL || \
> >  PyDict_SetItemString(PyModule_GetDict(m),"error",ErrorObject)!=0)
> >{
> > Py_FatalError("Can't define _msgpps_functions.error");
> > import_array();
> >   } /*  access to Numeric PyArray functions */
> >}
> >
> >
> >I have not main() function in the file. Instead the main function is
> >called the same name:
> >
> >static PyObject* _msgpps_functions(PyObject* self, PyObject* args)
> >
> >Now I am new at this and I have been reading anything I can find. The
> >only thing that is out of place is the part which I didn't include:
> >
> > /* Initialize the Python interpreter.  Required. */
> > Py_Initialize();
> >
> > /* Add a static module */
> > initspam();
> >because I still don't understand this part.
>
> Are you *extending* Python with a new module written in C (you should
> be using the first part),
> or *embedding* python inside your application, mainly written in C
> (you would use something like the last code).
>
>
> --
> Gabriel Genellina
> Softlab SRL
>
> __
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

Ok,

This I have done but still, the same error message. :(

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Martin v. Löwis
Ross Ridge schrieb:
> Martin v. Löwis wrote:
>> How would you propose to fix file_repr to prevent such
>> a race condition?
> 
> The race condition you describe is different from the one Joe Seigh
> described.  It's caused because without GIL access to the file object
> is no longer thread safe, not because reference counting isn't thread
> safe.

Joe's claim (quoting him) was: "Atomic increment and decrement
instructions are not by themselves sufficient to make reference
counting safe."

Rephrasing this in Python terms is "if the GIL is dropped and
incref/decref are made atomic, the reference counting is not
automatically thread-safe". This is what my example demonstrates:
Drop the GIL, and assume an atomic inc/dec, and it won't be
thread-safe.

It's not that the file object becomes thread-unsafe. Instead,
access to the f_name property won't work anymore (as would
access to any other PyObject* field).

You still didn't say what you would suggest to make it thread-safe
again; most likely, you proposal would be to add locking. If I
understand Joe's approach correctly, he has a solution that does
not involve locking (although I don't understand how it works).

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


sqlite query not working

2006-11-07 Thread John Salerno
Hopefully this is enough code to reveal the problem. When I run the 
program, there are no error messages produced, it's just that the values 
I enter don't seem to get put into the database, even though the query 
seems to be ok.


 def OnSaveRecord(self, event):
 textfield_values = []
 for tab in self.notebook.GetCurrentPage().GetChildren():
 for table in self.get_textfield_ids():
 table_values = []
 for textfield_id in table:
 table_values.append(xrc.XRCCTRL(tab, 
textfield_id).GetValue())
 textfield_values.append(table_values)
 res_id = self.create_id(textfield_values[0][0], 
textfield_values[0][2])
 for table in textfield_values:
 table.insert(0, res_id)
 self.save_to_database(textfield_values)

 def save_to_database(self, data):
 # doesn't work?
 self.connection.execute("""INSERT INTO Personal VALUES
 (?,?,?,?,?,?,?,?,?,?)""", tuple(data[0]))
-- 
http://mail.python.org/mailman/listinfo/python-list


More elegant way to obtain ACLs / permissions for windows directories than using "cacls" dos command?

2006-11-07 Thread dananrg
Is there a standard library module in Python 2.4 (Win32) that will
return directory permissions / ACLs (e.g. users, groups, and what
rights they have)?

Otherwise, I'm faced with sending "cacls dirName" commands via os.popen
as below, and then parsing and comparing the text output.

Basically, I'd like to compare what the ACLs a directory should have
against what the actual ACLs are.

Here's what I started with:

import os   # Cross-platform filesystem manipulation

rootDir = "S:\someRootDirectoryHere"

print "*** Printing DIRECTORY names beneath directory " + rootDir + "
***\n"
for dirpath, dirnames, filenames in os.walk(rootDir):
for dirNm in dirnames:
theDirPath = os.path.join(dirpath, dirNm)
print '"' + theDirPath +'"'
# cacls needs double-quotes around space-containing paths
result = os.popen("cacls " + '"' + theDirPath + '"')
# Print the security info (ACLs)for specified directory
print result.read()

Thanks.

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


Re: object data member dumper?

2006-11-07 Thread Bruno Desthuilliers
tom arnall a écrit :
> does anyone know of a utility to do a recursive dump of object data members? 
> 

What are "object data members" ? (hint: in Python, everything is an 
object - even functions and methods).

What is your real use case ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Dr. Dobb's Python-URL! - weekly Python news and links (Nov 7)

2006-11-07 Thread Cameron Laird
QOTW:  "If you want to become a good Python programmer, you really need to
get over that 'I need a oneliner' idea." - Fredrik Lundh
http://groups.google.com/group/comp.lang.python/msg/9e10957173a20e73

"It is the shortsightedness of the Python core developers that keeps
the palindrome related functions and algorithms out of the standard
library." - Istvan Albert
http://groups.google.com/group/comp.lang.python/msg/da6ce70ae0f4fe06


'Near the US capital?  Hear Barry Warsaw introduce Python to
a public NASA audience:
http://isandtcolloq.gsfc.nasa.gov/fall2006/speaker/warsaw.html

Among the most important work going on in the Python world is
that of the sprints--the recent Duesseldorf one, for example:
http://codespeak.net/pipermail/pypy-dev/2006q4/003396.html

pyjamas is a toolkit which facilitates AJAX composition in Python:
http://pyjamas.pyworks.org/

Carl Banks is one of the people for whom timing is simple:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/a06186617a253757/

In principle, Python is great for extending-and-embedding.
Each of these involves intimidatingly multiple aspects, though,
as we'll discuss over the next few weeks.  Fredrik Lundh bounds
one of them:  installation of an adequate development environment
under Windows:
http://groups.google.com/group/comp.lang.python/msg/b765eb106cc7a8fc

PyParsing!?  Sure, it's powerful, and pythonic, but is it really
appropriate to ... oh, I guess it is.  Paul McGuire releases
another of his pedagogic salvoes (inadvertently?) devoted to
surprising things that can be PyParsed:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/43b240a51e3777f0/
Notice the distinct approaches taken by Fredrik Lundh, Frederic
Rentsch, ... in the same thread.

PyQt 4.1 supports Qt 4.2, confusingly enough.  Consequential news
centers around QtTest (yeah!), QAxContainer, and QGraphicsView:
http://www.riverbankcomputing.co.uk/news.php

Fredrik Lundh collects pyidioms:
http://effbot.org/zone/python-lists.htm


Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/python/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python

Re: sqlite query not working

2006-11-07 Thread Steve Holden
John Salerno wrote:
> Hopefully this is enough code to reveal the problem. When I run the 
> program, there are no error messages produced, it's just that the values 
> I enter don't seem to get put into the database, even though the query 
> seems to be ok.
> 
> 
>  def OnSaveRecord(self, event):
>  textfield_values = []
>  for tab in self.notebook.GetCurrentPage().GetChildren():
>  for table in self.get_textfield_ids():
>  table_values = []
>  for textfield_id in table:
>  table_values.append(xrc.XRCCTRL(tab, 
> textfield_id).GetValue())
>  textfield_values.append(table_values)
>  res_id = self.create_id(textfield_values[0][0], 
> textfield_values[0][2])
>  for table in textfield_values:
>  table.insert(0, res_id)
>  self.save_to_database(textfield_values)
> 
>  def save_to_database(self, data):
>  # doesn't work?
>  self.connection.execute("""INSERT INTO Personal VALUES
>  (?,?,?,?,?,?,?,?,?,?)""", tuple(data[0]))

Have you tried adding a self.connection.commit() to the code? I don't 
know whether sqlite is transactional, but if it is then the changes will 
disappear without a commit.

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

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Joe Seigh
Martin v. Löwis wrote:
> You still didn't say what you would suggest to make it thread-safe
> again; most likely, you proposal would be to add locking. If I
> understand Joe's approach correctly, he has a solution that does
> not involve locking (although I don't understand how it works).
> 
Sun had applied for a patent on it.  You can go to the
uspto search page here http://www.uspto.gov/patft/index.html
and look for

20060218561 Code preparation technique employing lock-free pointer operations
20060037026 Lightweight reference counting using single-target synchronization

Click on the images link on the patent application where the illustrations
are which show the concepts probably better than the text.

The first one above is actually a continuation patent on three different
techniques.  One using double wide compare and swap, one using ROP (Repeat
Offender Problem), a form of PDR, and one using DCAS (compare and swap
of two separate locations) which only exists on MC68020 and MC68030
processors.

-- 
Joe Seigh

When you get lemons, you make lemonade.
When you get hardware, you make software. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite query not working

2006-11-07 Thread John Salerno
Steve Holden wrote:

> Have you tried adding a self.connection.commit() to the code? I don't 
> know whether sqlite is transactional, but if it is then the changes will 
> disappear without a commit.

Wow, that worked! Now, I know I've done some DB work before (very 
similar to this) and never used commit(), so I'm confused but still 
grateful! :)

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


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Nov 7)

2006-11-07 Thread John Salerno
Cameron Laird wrote:

> Fredrik Lundh collects pyidioms:
>   http://effbot.org/zone/python-lists.htm

Not working?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sound processing modules in python - anyone?

2006-11-07 Thread Christian Aastorp
On Mon, 6 Nov 2006 23:06:18 +0100 (CET), [EMAIL PROTECTED] wrote:

>Hi everyone,
>I'm looking for a module for sound processing (manipulating sound objets,
>filters, ffts etc.).
>I tried Snack, but when i downloaded the package that was supposed to be
>for python, there was only the Tk/Tcl stuff (where's the .py ?).
>could anyone help me with that (or with any other sound module for python)?
>thanks in advance,
>g

Here is the download page, listing Python (only version 2.3 though).
The source is available from the same page.

Or maybe, from comp.lang.python.announce:

 An early beta of the csound routine library is out with another
version to follow soon after.  The csound library is a group of
routines to minipulate .csd and .orc .sco  .src (shortened orc format)
combine delete exc.

https://sourceforge.net/project/showfiles.php?group_id=156455 


I believe that csound is a very mature and complete toolbox for music
generation and sound manipulation. 

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


Re: sqlite query not working

2006-11-07 Thread Tim Chase
>> Have you tried adding a self.connection.commit() to the
>> code? I don't know whether sqlite is transactional, but if
>> it is then the changes will disappear without a commit.
> 
> Wow, that worked! Now, I know I've done some DB work before
> (very similar to this) and never used commit(), so I'm
> confused but still grateful! :)


I tinkered with the mx.ODBC drivers a bit and had a similar
difficulty until I realized that it was configured to *not*
autocommit.  At least in the mx.ODBC drivers, you can pass a
param ("clear_auto_commit=1") to the Connect() call to restore
"normal" autocommiting behavior.  I can see both sides of the
fence...it's just a hassle to sniff out which DB drivers
autocommit and which don't.

-tkc




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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Chaz Ginger
Joe Seigh wrote:
> Martin v. Löwis wrote:
>> You still didn't say what you would suggest to make it thread-safe
>> again; most likely, you proposal would be to add locking. If I
>> understand Joe's approach correctly, he has a solution that does
>> not involve locking (although I don't understand how it works).
>>
> Sun had applied for a patent on it.  You can go to the
> uspto search page here http://www.uspto.gov/patft/index.html
> and look for
> 
> 20060218561 Code preparation technique employing lock-free pointer
> operations
> 20060037026 Lightweight reference counting using single-target
> synchronization
> 
> Click on the images link on the patent application where the illustrations
> are which show the concepts probably better than the text.
> 
> The first one above is actually a continuation patent on three different
> techniques.  One using double wide compare and swap, one using ROP (Repeat
> Offender Problem), a form of PDR, and one using DCAS (compare and swap
> of two separate locations) which only exists on MC68020 and MC68030
> processors.
> 
Check out the work in the '80s from the NYU Ultra project. They did a
great deal of work on using atomic incr/decr for all sorts of algorithms
 to get around locking on parallel processors.

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


Re: sqlite query not working

2006-11-07 Thread John Salerno
Tim Chase wrote:

> I tinkered with the mx.ODBC drivers a bit and had a similar
> difficulty until I realized that it was configured to *not*
> autocommit.  At least in the mx.ODBC drivers, you can pass a
> param ("clear_auto_commit=1") to the Connect() call to restore
> "normal" autocommiting behavior.  I can see both sides of the
> fence...it's just a hassle to sniff out which DB drivers
> autocommit and which don't.

What's really strange is that I'm pretty sure (but can always be wrong) 
that I've written SQLite queries just as above, and they were saved to 
the DB without a commit() call, so it's not like I was even using a 
different system. Ah well, I'm sure there was *something* different 
about the two cases! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Nov 7)

2006-11-07 Thread Leonhard Vogt
John Salerno schrieb:
> Cameron Laird wrote:
> 
>> Fredrik Lundh collects pyidioms:
>> http://effbot.org/zone/python-lists.htm
> 
> Not working?

Try
http://effbot.org/zone/python-list.htm

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


Re: Pyro stability

2006-11-07 Thread Carl J. Van Arsdall
Paul Boddie wrote:
> Beliavsky wrote:
>   
>> Carl J. Van Arsdall wrote:
>> 
>
> [Enthusiasm for Pyro, not for those with sensitivity to rude words]
>
>   
>> You should watch your language in a forum with thousands of readers.
>> 
I think you should find better things to complain about and not worry 
about language usage so much.

-c

-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Nov 7)

2006-11-07 Thread Chris Lambacher
On Tue, Nov 07, 2006 at 04:15:39PM -0500, John Salerno wrote:
> Cameron Laird wrote:
> 
> > Fredrik Lundh collects pyidioms:
> > http://effbot.org/zone/python-lists.htm
> 
> Not working?
perhaps http://effbot.org/zone/python-list.htm ?

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


Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?

2006-11-07 Thread Shane Hathaway
robert wrote:
> I'd like to use multiple CPU cores for selected time consuming Python
> computations (incl. numpy/scipy) in a frictionless manner.
> 
> Interprocess communication is tedious and out of question, so I
> thought about simply using a more Python interpreter instances
> (Py_NewInterpreter) with extra GIL in the same process. I expect to
> be able to directly push around Python Object-Trees between the 2 (or
> more) interpreters by doing some careful locking.
> 
> Any hope to come through? If possible, what are the main dangers? Is
> there an example / guideline around for that task? - using ctypes or
> so.
> 
> Or is there even a ready made Python module which makes it easy to
> setup and deal with extra Interpreter instances? If not, would it be
> an idea to create such thing in the Python std libs to make Python
> multi-processor-ready. I guess Python will always have a GIL -
> otherwise it would loose lots of comfort in threaded programming

I'd like to mention mod_python, which creates multiple interpreters
inside Apache.  It does this transparently and works well.  There is no
apparent lock contention between the interpreters, because no Python
objects are shared.

Also, I'd like to make the observation that it is not always necessary
to share the entire interpreter (ala threads) in order to take advantage
of multiple cores.  I think Python only needs a nice way to share a
relatively small set of objects using shared memory.  POSH goes in that
direction, but I don't think it's simple enough yet.

http://modpython.org/
http://poshmodule.sourceforge.net/

Shane

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


Re: sqlite query not working

2006-11-07 Thread BartlebyScrivener

John Salerno wrote:

>> Ah well, I'm sure there was *something* different

Are you sure that it's not you were doing SELECT before, as opposed to
INSERT?

rd

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


Re: Tired of spam, unrelated email?

2006-11-07 Thread Steven D'Aprano
On Tue, 07 Nov 2006 14:28:00 -0600, skip wrote:

> Tired of spam, unrelated email?
> 
> You mean, like your message?

You know what is really funny?

Due to the vagaries of Usenet, I never received the original piece of spam
at all, so if you hadn't replied to it, I never would have been bothered
by it in the least!

Out of curiosity, do you think the spammer actually reads comp.lang.python?



-- 
Steven.

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


Compiling python 2.5 on OS X 10.4.8 with bsddb support

2006-11-07 Thread Yi Qiang
Hi guys,
I am trying to compile python 2.5 on my OSX machine so it includes the
bsddb module.  Currently, when I type 'import bsddb' I get the
following traceback:

/Users/yi/Software/sage-1.4.1.2/local/lib/python2.5/bsddb/__init__.py
in ()
 49 from bsddb3.dbutils import DeadlockWrap as _DeadlockWrap
 50 else:
---> 51 import _bsddb
 52 from bsddb.dbutils import DeadlockWrap as _DeadlockWrap
 53 except ImportError:

: No module named _bsddb

I have the db3 and db4 packages installed from macports.  What else
must I do to get this working?

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


Re: Tired of spam, unrelated email?

2006-11-07 Thread BartlebyScrivener
Steven D'Aprano wrote:

> Due to the vagaries of Usenet,
> I never received the original piece of spam
> at all

Same here. I do all of my persuing via Google Groups, and sometimes the
same thing happens in a legitimate thread. I see somebody responding as
the fist message in the thread, but I never see the OP. 

Odd.

rd

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


Re: C wrapper

2006-11-07 Thread Gabriel Genellina

At Tuesday 7/11/2006 17:43, Sheldon wrote:


> And what are those non-static functions used for? The *only* purpose
> of your module should be to provide the Python bindings...

I wrote the C module to do some number crunching. Now I just need to
"connect" it to my python program. Should the initmsgpps_functions() be
the only function in the file? Then how do I "connect" my C module to
my Python program?


Read again the docs but have in mind that you are *extending* the 
interpreter with a new module - disregard the references to 
*embedding* Python (even if they appear in a section about 
extending!). I can see your confusion reading 
http://docs.python.org/ext/methodTable.html


That is, you *don't* write a main() function, and you *don't* invoke 
Py_Initialize; just write your initXXX() function.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pyro stability

2006-11-07 Thread Steve Holden
Carl J. Van Arsdall wrote:
> Paul Boddie wrote:
> 
>>Beliavsky wrote:
>>  
>>
>>>Carl J. Van Arsdall wrote:
>>>
>>
>>[Enthusiasm for Pyro, not for those with sensitivity to rude words]
>>
>>  
>>
>>>You should watch your language in a forum with thousands of readers.
>>>
> 
> I think you should find better things to complain about and not worry 
> about language usage so much.
> 
It didn't seem like an unreasonable request to me, though I concede that 
you aren't (yet :-) known throughout Usenet for your profanity.

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

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


Re: Unicode/ascii encoding nightmare

2006-11-07 Thread Cliff Wells
On Tue, 2006-11-07 at 08:10 +0200, Hendrik van Rooyen wrote:
> "John Machin" <[EMAIL PROTECTED]> wrote:
> 
> 8<---
> 
> > I strongly suggest that you read the docs *FIRST*, and don't "tinker"
> > at all.
> >

>  This is *good* advice - its unlikely to be followed though, as the OP is 
> prolly
> just like most of us - you unpack the stuff out of the box and start 
> assembling
> it, and only towards the end, when it wont fit together, do you read the 
> manual
> to see where you went wrong...

I fall right into this camp(fire).  I'm always amazed and awed at people
who actually read the docs *thoroughly* before starting.  I know some
people do but frankly, unless it's a step-by-step tutorial, I rarely
read the docs beyond getting a basic understanding of what something
does before I start "tinkering".

I've always been a firm believer in the Chinese proverb:

I hear and I forget
I see and I remember
I do and I understand

Of course, I usually just skip straight to the third step and try to
work backwards as needed.  This usually works pretty well but when it
doesn't it fails horribly.  Unfortunately (for me), working from step
one rarely works at all, so that's the boat I'm stuck in.

I've always been a bit miffed at the RTFM crowd (and somewhat jealous, I
admit).  I *do* RTFM, but as often as not the fine manual confuses as
much as clarifies.  I'm not convinced this is the result of poor
documentation so much as that I personally have a different mental
approach to problem-solving than the others who find documentation
universally enlightening.  I also suspect that I'm not alone in my
approach and that the RTFM crowd is more than a little close-minded
about how others might think about and approach solving problems and
understanding concepts. 

Also, much documentation (including the Python docs) tends to be
reference-manual style.  This is great if you *already* understand the
problem and just need details, but does about as much for
*understanding* as a dictionary does for learning a language.  When I'm
perusing the Python reference manual, I usually find that 10 lines of
example code are worth 1000 lines of function descriptions and
cross-references.

Just my $0.02.

Regards,
Cliff


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


Finding Nonzero Elements in a Sparse Matrix

2006-11-07 Thread deLenn
Hi,

Does scipy have an equivalent to Matlab's 'find' function, to list the
indices of all nonzero elements in a sparse matrix?

Cheers.

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


Re: object data member dumper?

2006-11-07 Thread Steve Holden
Bruno Desthuilliers wrote:
> tom arnall a écrit :
> 
>>does anyone know of a utility to do a recursive dump of object data members? 
>>
> 
> 
> What are "object data members" ? (hint: in Python, everything is an 
> object - even functions and methods).
> 
> What is your real use case ?

Basically it sounds like the OP wants to see the attribute values for an 
object (and those objects' attribute values, ...). Presumably the 
recursive descent could be stopped at the built-in types.

I'm not familiar with any such thing. The code of the standard library's 
pprint module might be a good place to start (and the suggested 
functionality might make a nice addition if we could work out exactly 
what the requirement was).

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

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


Re: object data member dumper?

2006-11-07 Thread tom arnall
Bruno Desthuilliers wrote:

> tom arnall a écrit :
>> does anyone know of a utility to do a recursive dump of object data
>> members?
>> 
> 
> What are "object data members" ? (hint: in Python, everything is an
> object - even functions and methods).
> 
> What is your real use case ?

something like:

   class A:
  def __init__(self, p1):
 self.p1 = p1

   class B: 
  def __init__(self,p1, p2):
 self.a = A(p1)
 self.p2 = p2
 self.v1 = '3'

   class C:
  def __init__(self):
 self.b = B(3,4)
 self.p3 = 5

   class D:
  def __init__(self):
 self.v2=2
 self.o1 = C()
 self.o2 = B(11,12)


   d = D()
   objectDataDumper(d)


would produce something like:

   object of class D with:
   o1(C)->b(B)->a(A)->p1=3
   o1(C)->b(B)->p2=4
   o1(C)->b(B)->v1=3
   o1(C)->p3=5
   o2(B)->a(A)->p1=11
   o2(B)->p2=12
   o2(B)->v1=3
   v2=2


tom arnall
north spit, ca
usa

-- 
Posted via a free Usenet account from http://www.teranews.com

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


  1   2   >