Re: Just Getting Started with Python on MS XP Pro

2007-01-06 Thread W. Watson
Laszlo Nagy wrote:
> W. Watson wrote:
>> What do I download to use Python with MX XP Pro on an ASUS 4 year old 
>> motherboard? I would guess a good book source for starters would be 
>> the O'Reilly book.
>>   
> You mean Microsoft XP Pro?
> 
> For a beginner, the motherboard does not really matter. First of all, 
> you should download Python itself:
> 
> http://www.python.org/download/
> 
> or more probably:
> 
> http://www.python.org/ftp/python/2.5/python-2.5.msi
> 
> Then you should download a good editor. There are many, listed here: 
> http://wiki.python.org/moin/PythonEditors
> Under Windows, for a beginner, I would recommend pythonwin, but you can 
> decide.
> 
> Finally, you can start practicing. A book is always good. You can read 
> online tutorials too:
> 
> http://docs.python.org/tut/
> http://www.awaretek.com/tutorials.html
> 
> 
> Regards,
> 
>  Laszlo
> 
Many thanks. I've been impressed lately what one finds in Wikipedia. The 
first such occurrence was when I find all the release dates for a photo 
software package that I use. Not even the mfger had that!


  Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA)
  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
   Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

  ""I do not fear death. I had been dead for billions
and billions of years before I was born, and had
not suffered the slightest inconvenience from it."
-- Mark Twain (a nod to evolution)
-- 
 Web Page: 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just Getting Started with Python on MS XP Pro

2007-01-06 Thread W. Watson
Ah, I misread wiki as wikpedia. Nevertheless, wikipedia surprises me, as 
well as just wiki sites.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: program deployment

2007-01-06 Thread Steven D'Aprano
On Fri, 05 Jan 2007 08:01:17 -0800, Michele Simionato wrote:

> king kikapu wrote:
>> > > Are they embarassed by their code?
>>
>> hehehe...no, just worried about stealing their ideas...
> 
> I believe that shipping just the bytecode is a pretty effective way to
> stop 99% of programmers from
> reading your code. Yes, in theory they could decompile it, but in
> practice, programmers are lazy.

99% of programmers won't read the code if you ship the source.

> Look, I am so lazy that usually I don't read the source code, even if
> it is there in plain!

Exactly.



-- 
Steven.

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


Re: program deployment

2007-01-06 Thread Steven D'Aprano
On Fri, 05 Jan 2007 07:19:37 -0800, king kikapu wrote:

> 
> 
>> > Are they embarassed by their code?
> 
> hehehe...no, just worried about stealing their ideas...

I don't understand... how can they steal an idea? If somebody copies your
idea, you've still got it, it's not gone.

-- 
Steven.

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


Re: Encoding / decoding strings

2007-01-06 Thread Steven D'Aprano
On Fri, 05 Jan 2007 09:39:17 -0800, [EMAIL PROTECTED] wrote:

> Basically, what I am trying to do is display all comments by a
> specified user on the website. As the only thing which has =always=
> been used to identify users which never changes is their e-mail
> addresses, 

What are you talking about? I've changed my email address a dozen times
on many mailing lists and websites. I'm still me.

> this is the only thing which I can use. Obviously, I can't
> display this e-mail address though.

There is nothing obvious about that all all. Email addresses are usually
public. But okay, your users aren't expecting their email address to be
public.

Why not do what many jails do with prisoners? Everybody gets a unique
number. In your case, just walk through the database of users, giving
each one a number. You can't reverse engineer the email address from the
number without breaking into the database. Then your website can refer to
them as "Prisoner 123456789" which should be good for a few laughs.

Or simply take the username part of the address. So "[EMAIL PROTECTED]"
would become "fred". Then "[EMAIL PROTECTED]" would become "fred1", and so
forth.

Obviously you don't try to generate the username from the email address
every single time, you do it once, and keep a list of used usernames so
that when "[EMAIL PROTECTED]" joins you know "fred" and "fred1" are both used
and he has to be "fred2".

md5 checksums can now be broken, in both directions: it is relatively
easy to generate collisions, and there are reverse md5 lookup tables.
I imagine your use of md5 would be especially easy to attack, since the
attacker knows that the string is an email address.



-- 
Steven.

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


Re: Newbie XML SAX Parsing: How do I ignore an invalid token?

2007-01-06 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
> My original posting has a funky line break character (it appears as an
> ascii square) that blows up my program, but it may or may not show up
> when you view my message.

Looking at your document, it seems that this "funky line break
character" is character \x1E, which, in latin-1, means "record
separator". It's indeed ill-formed to use it in XML.

> Is there a way to account for the invalid token in the error handler?

Not with a standard XML parser, no. The error you describe is a "fatal
error", and that's not something parsing can recover from. I recommend
that you filter this character out before passing it to the XML parser.
You can use the IncrementalParser interface to do so.

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


Re: attribute decorators

2007-01-06 Thread Steven D'Aprano
On Fri, 05 Jan 2007 20:34:54 -0800, gert wrote:

> Would it not be nice if you could assign decorators to attributes too ?
> for example
> 
> class C:
>   @staticattribute
>   data='hello'


You can. You just have to write it as:

class C:
data = staticattribute('hello')

(Of course, writing the staticattribute function is a non-trivial problem.)


> or
> 
> class C:
>   @privateattribute
>   data='hello'

That would be written as 

class C:
_data = 'hello'

or possibly 

class C:
__data = 'hello' 

depending on whether you want private attributes to be by convention or by
name-mangling.


-- 
Steven.

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


python, zlib, and fedora 64bits

2007-01-06 Thread Tarek Ziadé

Hello,

I am trying to compile Python on a Fedora 64bits, and I can't make zlib
work.

a python setup.py build leads to :

...
building 'zlib' extension
gcc -pthread -shared
build/temp.linux-x86_64-2.4/usr/local/src/Python-2.4.4/Modules/zlibmodule.o
-L/opt/python-2.4.4/lib -L/usr/local/lib -lz -o build/lib.linux-x86_64-2.4
/zlib.so
/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against
`a local symbol' can not be used when making a shared object; recompile with
-fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld gab 1 als Ende-Status zurück
running build_scripts
running install_lib
...

I've tried to recompile zlib, but didn't find any way to avoid this error

any ideas ?

Otherwise, does anyone has a zlib.so for fedora 64bits to send me ?

Thx

Tarek

--
Tarek Ziadé | Association AfPy | www.afpy.org
Blog FR | http://programmation-python.org
Blog EN | http://tarekziade.wordpress.com/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python, zlib, and fedora 64bits

2007-01-06 Thread Jonathan Curran
On Saturday 06 January 2007 03:47, Tarek Ziadé wrote:
> Hello,
>
> I am trying to compile Python on a Fedora 64bits, and I can't make zlib
> work.
>
> a python setup.py build leads to :
>
> ...
> building 'zlib' extension
> gcc -pthread -shared
> build/temp.linux-x86_64-2.4/usr/local/src/Python-2.4.4/Modules/zlibmodule.o
> -L/opt/python-2.4.4/lib -L/usr/local/lib -lz -o build/lib.linux-x86_64-2.4
> /zlib.so
> /usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against
> `a local symbol' can not be used when making a shared object; recompile
> with -fPIC
> /usr/local/lib/libz.a: could not read symbols: Bad value
> collect2: ld gab 1 als Ende-Status zurück
> running build_scripts
> running install_lib
> ...
>
> I've tried to recompile zlib, but didn't find any way to avoid this error
>
> any ideas ?
>
> Otherwise, does anyone has a zlib.so for fedora 64bits to send me ?
>
> Thx
>
> Tarek

Tarek, I would first check and see if fedora offers python for a 64-bit 
environment. If so, it would be easier to get python up and running quickly. 
I haven't used any redhat deviant in a while, but I think the command should 
be: yum search python. This should bring up a list of packages that are 
installable. The rest should be simple as: yum install . I hope 
this helps.

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

Re: (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-06 Thread Stef Mientki

Steven Bethard wrote:
> Stef Mientki wrote:
>> Not sure I wrote the subject line correct,
>> but the examples might explain if not clear
> [snip]
>> class pin2:
>>   def __init__ (self, naam):
>> self.Name  = naam
>>
>> aap2 = pin2('aap2') # seems completely redundant to me.
>> print aap2.Name
> 
> You can use class statements to create your instances with some 
> metaclass trickery. Unlike normal assignments, class statements get 
> access to the name being assigned. So you could write your class like::

thank you all guys,
this gives me a lot to study,
for the moment I'm satisfied with the fact that it "is possible".

cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


howto overload with a NOP (empty statement)

2007-01-06 Thread Stef Mientki
How should I overload / disable a method ?
In the example below I have defined the class "Power_Supply", derived 
from baseclass "device".
The baseclass has a method "execute", which will be implemented in most 
derived classes, but not in all.
Now apparently it's not allowed to overload a method with an empty 
statement.
I could write a nonsense dummy statement, like "A= 3", but isn't there 
another way ?

thanks, Stef Mientki

class device:
   def execute (self):
 print 'execute not yet implemented for', self.Name


class Power_Supply (device):
   def execute (self): ;
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto overload with a NOP (empty statement)

2007-01-06 Thread Robert Kern
Stef Mientki wrote:
> How should I overload / disable a method ?
> In the example below I have defined the class "Power_Supply", derived 
> from baseclass "device".
> The baseclass has a method "execute", which will be implemented in most 
> derived classes, but not in all.
> Now apparently it's not allowed to overload a method with an empty 
> statement.
> I could write a nonsense dummy statement, like "A= 3", but isn't there 
> another way ?

pass

-- 
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: howto overload with a NOP (empty statement)

2007-01-06 Thread Vasily Sulatskov
class Power_Supply (device):
def execute (self):
pass

Stef Mientki wrote:
> How should I overload / disable a method ?
> In the example below I have defined the class "Power_Supply", derived
> from baseclass "device".
> The baseclass has a method "execute", which will be implemented in most
> derived classes, but not in all.
> Now apparently it's not allowed to overload a method with an empty
> statement.
> I could write a nonsense dummy statement, like "A= 3", but isn't there
> another way ?
>
> thanks, Stef Mientki
>
> class device:
>def execute (self):
>  print 'execute not yet implemented for', self.Name
> 
> 
> class Power_Supply (device):
>def execute (self): ;

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


Re: howto overload with a NOP (empty statement)

2007-01-06 Thread Bruno Desthuilliers
Stef Mientki a écrit :
> How should I overload / disable a method ?
> In the example below I have defined the class "Power_Supply", derived 
> from baseclass "device".


Naming conventions are to use CamelCase for class names. So it would be 
better to name your classes 'PowerSupply' (no '_') and 'Device'. You're 
of course free to use whatever naming convention you want, including no 
convention at all, but Python relies *a lot* on naming conventions...


> The baseclass has a method "execute",


Do you know that Python let you define your own 'callable' objects ?

class SomeCallable(object):
   def __init__(self, name):
 self.name = name
   def __call__(self):
 print "wow, %s has been called" % self.name

foo = SomeCallable('foo')
foo()

This may or not make sens in the context of your application, but 
whenever you find yourself naming a method 'execute', it might be worth 
asking yourself if the object should in fact be a callable...


> which will be implemented in most 
> derived classes, but not in all.
 >
> Now apparently it's not allowed to overload a method with an empty 
> statement.
> I could write a nonsense dummy statement, like "A= 3", but isn't there 
> another way ?

the 'pass' statement

def noop():
   pass

> thanks, Stef Mientki
> 
> class device:
>   def execute (self):
> print 'execute not yet implemented for', self.Name

The usual idiom for 'pure virtual methods' is to raise a 
NotImplementedError. Now if it's ok for a subclass to implement the 
method as a no-op, why not just implement it as a no-op in the base 
class itself ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PDF rendering toolkit?

2007-01-06 Thread Diez B. Roggisch
> I'm looking for a tool to take an actual .pdf file and display it in a
> window (I'm using wxwidgets at the moment)

No idea if there is a one-shot-kills-them-all solution out there - but 
if you have a way to go for windows, you might checkout PyQt and PyKDE 
to embed a kpfd-view in a window of yours.

I agree that it is less than desirable to switch toolkits - but if you 
_have_ to...

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


Re: What is proper way to require a method to be overridden?

2007-01-06 Thread Bruno Desthuilliers
Patrick Down a écrit :
> jeremito wrote:
> 
>>I am writing a class that is intended to be subclassed.  What is the
>>proper way to indicate that a sub class must override a method?
>>
(snip)

> Decorators to the rescue?

(snip convoluted code)

What a strange idea...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto overload with a NOP (empty statement)

2007-01-06 Thread robert
Stef Mientki wrote:
> How should I overload / disable a method ?
> In the example below I have defined the class "Power_Supply", derived 
> from baseclass "device".
> The baseclass has a method "execute", which will be implemented in most 
> derived classes, but not in all.
> Now apparently it's not allowed to overload a method with an empty 
> statement.
> I could write a nonsense dummy statement, like "A= 3", but isn't there 
> another way ?
> 
> thanks, Stef Mientki
> 
> class device:
>   def execute (self):
> print 'execute not yet implemented for', self.Name
> 
> 
> class Power_Supply (device):
>   def execute (self): ;




class device:
   def execute (self):
   raise NotImplementedError('virtual: should do this and that')



This NotImplementedError virtual method scheme will also be detected by 
pychecker in order to warn correctly: that classes of actual instances have to 
override all open virtuals.


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


Re: Using sax libxml2 html parser

2007-01-06 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
> I have created an example using libxml2 based in the code that appears
> in http://xmlsoft.org/python.html.
> My example processes an enough amount of html files to see that the
> memory consumption rises till the process ends (I check it with the
> 'top' command).


Try the lxml binding for libxml2. It relieves you from having to do your own
memory management and makes using that library plain easy.

http://codespeak.net/lxml/

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


Re: Pausing for Python Interpreter error messages...

2007-01-06 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> I've written a few classes that I have been testing in IDLE. However,
> every time I make a change to the classes based on the testing I have
> to walk through all he steps of preparing the classes for testing
> again.
> 
> So I wrote a script that does all the set-up work for me. 

You may want to have a look at the unittest module then:
http://docs.python.org/lib/module-unittest.html

> The only
> problem is when I run this script using the Python interpreter I can't
> get the command prompt to stay up long enough for me to read the
> message.
> 
> How do I get the command prompt to stay up?

first open the "command prompt", then launch your script from the 
command prompt.

> Is there a way to run my
> script and view the error message in IDLE?

menu run->run module, or just hit the F5 key.

> Thanks for the help.
> 
> Scott Huey
> 
> P.S. - I'm using Windows XP with the latest Python 2.3.
> 

Python 2.3 is years old. Latest is 2.5.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: howto overload with a NOP (empty statement)

2007-01-06 Thread Jussi Salmela
Bruno Desthuilliers kirjoitti:
> Stef Mientki a écrit :
>> How should I overload / disable a method ?
>> In the example below I have defined the class "Power_Supply", derived 
>> from baseclass "device".
> 
> 
> Naming conventions are to use CamelCase for class names. So it would be 
> better to name your classes 'PowerSupply' (no '_') and 'Device'. You're 
> of course free to use whatever naming convention you want, including no 
> convention at all, but Python relies *a lot* on naming conventions...
> 

Continuing with the style and idioms issues...

1. Don't leave a space between a function/method/class name and the 
opening parenthesis, i.e. instead of:
def execute (self):
use:
def execute(self):

2. It seems to me that you indent your code with 2 spaces. If I'm wrong, 
please ignore me. Otherwise: always use 4 spaces when indenting with spaces.

Following these and the numerous other guidelines (see 
htpp://www.python.org/dev/peps/pep-0008/ for example) on Python style 
you'll be making yourself and others a favor. When these coding 
guidelines become your habit, it will be easier for you to read the code 
of other Pythoners. This is important because a large part of learning 
consists of reading the code of others.

And also vice versa: when you show your code to others, it will be 
easier for them to concentrate on your problem when the idiosyncrasy of 
your code is not there to hinder.

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


Python re expr from Perl to Python

2007-01-06 Thread Michael M.

In Perl, it was:


   ## Example: "Abc | def | ghi | jkl"
   ##   -> "Abc ghi jkl"
   ## Take only the text betewwn the 2nd pipe (=cut the text in the 1st 
pipe).
   $na =~ s/\ \|(.*?)\ \|(.*?)\ \|/$2/g;

   ## -- remove [ and ] in text
   $na =~ s/\[//g;
   $na =~ s/\]//g;
   # print "DEB: \"$na\"\n";


# input string
na="Abc | def | ghi | jkl [gugu]"
# output
na="Abc ghi jkl gugu"


How is it done in Python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python re expr from Perl to Python

2007-01-06 Thread Jorge Godoy
"Michael M." <[EMAIL PROTECTED]> writes:

> In Perl, it was:
>
>
>   ## Example: "Abc | def | ghi | jkl"
>   ##   -> "Abc ghi jkl"
>   ## Take only the text betewwn the 2nd pipe (=cut the text in the 1st pipe).
>   $na =~ s/\ \|(.*?)\ \|(.*?)\ \|/$2/g;
>
>   ## -- remove [ and ] in text
>   $na =~ s/\[//g;
>   $na =~ s/\]//g;
>   # print "DEB: \"$na\"\n";
>
>
> # input string
> na="Abc | def | ghi | jkl [gugu]"
> # output
> na="Abc ghi jkl gugu"
>
>
> How is it done in Python?

The simplest form:

>>> na="Abc | def | ghi | jkl [gugu]"
>>> na_out = na.replace('def', '').replace(' | ', ' ').replace('  ', ' 
>>> ').replace('[', '').replace(']', '').strip()
>>> na_out
'Abc ghi jkl gugu'
>>> 


Another form:

>>> na_out = ' '.join(na.split(' | ')).replace('[', '').replace(']', 
>>> '').replace(' def', '')
>>> na_out
'Abc ghi jkl gugu'
>>> 


There is the regular expression approach as well as several other
alternatives.  I could list other (simpler, more advanced, etc.) alternatives,
but you can also play with Python by yourself.  If you have a more concrete
specification, send it to the group.



-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I add users using Python scripts on a Linux machine

2007-01-06 Thread Piet van Oostrum
> Lawrence D'Oliveiro <[EMAIL PROTECTED]> (LD) wrote:

>LD> No it wouldn't. This security hole was fixed years ago.

How?
-- 
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: Just Getting Started with Python on MS XP Pro

2007-01-06 Thread W. Watson
The wiki site lead to a link to download pythonwin, but the download is 
broken. Googling invariably leads back to that link. I found 
, which has 
two files listed: oadist.exe and win32dbg.exe. Do I need both or is just the 
latter one?


  Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA)
  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
   Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

  ""I do not fear death. I had been dead for billions
and billions of years before I was born, and had
not suffered the slightest inconvenience from it."
-- Mark Twain (a nod to evolution)
-- 
 Web Page: 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Anyone persuaded by "merits of Lisp vs Python"?

2007-01-06 Thread Aahz
In article <[EMAIL PROTECTED]>,
Ant <[EMAIL PROTECTED]> wrote:
>
>So far? After a bit of pain getting started and finding decent docs
>(while waiting for the books to arrive) I've found the language quite
>easy to use. I haven't got into closures or macros yet - I need to get
>more familiar with the basics first, but first impressions are
>favorable. It seems that there is nothing conceptually in Python that I
>can't reasonably easily do in Lisp, but the Python syntax is much more
>straightforward for most of the basics I think (such as dictionaries,
>sets, list comprehensions etc), and the function/naming conventions for
>the core language is much clearer and more obvious than in Lisp.

Just remember: today is the car of the cdr of your life.

Once upon a time, I was working at a company that was a commercialized
MIT Lisp project rewritten in C.  One day I was amused to discover that
buried deep in the code were a pair of functions, car() and cdr()...
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"Plus ca change, plus c'est la meme chose."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python re expr from Perl to Python

2007-01-06 Thread Carsten Haese
On Sat, 2007-01-06 at 15:43 +0100, Michael M. wrote:
> In Perl, it was:
> 
> 
>## Example: "Abc | def | ghi | jkl"
>##   -> "Abc ghi jkl"
>## Take only the text betewwn the 2nd pipe (=cut the text in the 1st 
> pipe).
>$na =~ s/\ \|(.*?)\ \|(.*?)\ \|/$2/g;
> 
>## -- remove [ and ] in text
>$na =~ s/\[//g;
>$na =~ s/\]//g;
># print "DEB: \"$na\"\n";
> 
> 
> # input string
> na="Abc | def | ghi | jkl [gugu]"
> # output
> na="Abc ghi jkl gugu"
> 
> 
> How is it done in Python?

Here's an almost literal translation:

##
import re
na = re.sub(r"\ \|(.*?)\ \|(.*?)\ \|", r"\2", na)
na = na.replace("[", "")
na = na.replace("]", "")
##

Background information on regular expressions in Python can be found
here:

http://www.amk.ca/python/howto/regex/
http://docs.python.org/lib/module-re.html

Hope this helps,

Carsten.


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


Re: Just Getting Started with Python on MS XP Pro

2007-01-06 Thread Thomas Ploch
W. Watson schrieb:
> The wiki site lead to a link to download pythonwin, but the download is 
> broken. Googling invariably leads back to that link. I found 
> , which has 
> two files listed: oadist.exe and win32dbg.exe. Do I need both or is just the 
> latter one?


A google query 'pythonwin' directly brings me here:

https://sourceforge.net/projects/pywin32/

I think this is the place to go

Thomas


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


Re: Just Getting Started with Python on MS XP Pro

2007-01-06 Thread rzed
[EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

> Wise choice + welcome to the club.

Seconded.

> The only real XP drawback is that Python is not bundled on
> Windows, while it is included with OS X and most (all?) Linux
> distros. 
> 

My computer does, in fact, include a Python 2.2.1 installation, 
which the manufacturer uses internally.

> 2.  use any ol' text editor that _you_ are familiar with, save
> to file, and python  under DOS.  later on you can always
> pick an editor. i prefer eclipse + pydev, yes, even on windows.
> 
> personally, i find pythonwin _great_ to test out code
> interactively, mediocre to write lots of code with and
> occasionally handy to debug code in.
> 
> if you hate typing python  under DOS, then I guess you
> will have to run programs from pythonwin.
> 

Not so, but it takes a little setup. If I want to run a Python 
program named, say, "fixthis.py", I can invoke it by typing 
"fixthis.py" at the command-line prompt (if I'm running cmd.exe), 
or by clicking the icon in Windows Explorer. To make the command-
line option work, I have to have file associations set so that .py 
files open with python (and .pyw files open with pythonw, for that 
matter). I *think* this is done at install time, though I may have 
done that separately.

There is also an environment variable called "pathext", which is 
just a list of extensions the system recognizes as being 
executable in some way. if you add .py and .pyw to that list, then 
all you have to type at the command line is "fixthis" to get that 
Python program to run.

I note that I have had my Python root and Python/Scripts directory 
on my path at times. There may be some packages that require these 
things, but what I talked about in the previous two paragraphs 
doesn't require pythonpath to be set specially.

(Fiddling around) Ah! If you want to invoke the interactive python 
shell, you will probably want to add the root location to your 
path, so you can type
> python
... to invoke it, rather than
> c:\python25\python
... and something similar may be true for the Scripts 
subdirectory.

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


C++/Python programmers for a MUD's gamedriver wanted.

2007-01-06 Thread Rythin
Hi everyone.
We are looking for a volunteer co-programmers for a MUD's gamedriver
project. As of now, a gamedriver is divided into two separate but
tightly interconnected systems - C++ driver and Python lib.

C++ Driver is supposed to be managing memory, proccesses and
communication between them (transparent as far as net is concerned).
Python lib is to define the user's interfaces. Both of them are
designed to work in an object-oriented enviroment, with lib's classes
being driver's child-classes.

Competent level of knowledge on C++ and Python (especially embedding
Python's interpreter in apps) is required. Alternatively, we are
seeking people skilled in a use of Unix sockets and C++ system
programming.

If you are interested, email me at [EMAIL PROTECTED] (subject:
Gamedriver project) with a brief summary of your skills, C++/Python/mud
experience and things you are looking to find in this job.

You are welcome to ask any additional questions at [EMAIL PROTECTED]
(subject: Gamedriver project). 


Take care,
Michael

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


Re: Python re expr from Perl to Python

2007-01-06 Thread Paddy

Michael M. wrote:

> In Perl, it was:
>
>
>## Example: "Abc | def | ghi | jkl"
>##   -> "Abc ghi jkl"
>## Take only the text betewwn the 2nd pipe (=cut the text in the 1st
> pipe).
>$na =~ s/\ \|(.*?)\ \|(.*?)\ \|/$2/g;
>
>## -- remove [ and ] in text
>$na =~ s/\[//g;
>$na =~ s/\]//g;
># print "DEB: \"$na\"\n";
>
>
> # input string
> na="Abc | def | ghi | jkl [gugu]"
> # output
> na="Abc ghi jkl gugu"
>
>
> How is it done in Python?

Here is how to do it without regexps in python.
The first and last line below are all that are needed. The others show
intermediate expressions that lead to the result.

>>> from itertools import groupby

>>> na="Abc | def | ghi | jkl [gugu]"
>>> [(g[0], ''.join(g[1])) for g in groupby(na, lambda c: c not in ' \t|[]')]
[(True, 'Abc'), (False, ' | '), (True, 'def'), (False, ' | '), (True,
'ghi'), (False, ' | '), (True, 'jkl'), (False, ' ['), (True, 'gugu'),
(False, ']')]
>>> [''.join(g[1]) for g in groupby(na, lambda c: c not in ' \t|[]') if g[0]]
['Abc', 'def', 'ghi', 'jkl', 'gugu']

>>> ' '.join(''.join(g[1]) for g in groupby(na, lambda c: c not in ' \t|[]') if 
>>> g[0])
'Abc def ghi jkl gugu'
>>> 


- Paddy.

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


Re: Python re expr from Perl to Python

2007-01-06 Thread Paddy

Paddy wrote:

> Michael M. wrote:
>
> > In Perl, it was:
> >
> >
> >## Example: "Abc | def | ghi | jkl"
> >##   -> "Abc ghi jkl"
> >## Take only the text betewwn the 2nd pipe (=cut the text in the 1st
> > pipe).
> >$na =~ s/\ \|(.*?)\ \|(.*?)\ \|/$2/g;
> >
> >## -- remove [ and ] in text
> >$na =~ s/\[//g;
> >$na =~ s/\]//g;
> ># print "DEB: \"$na\"\n";
> >
> >
> > # input string
> > na="Abc | def | ghi | jkl [gugu]"
> > # output
> > na="Abc ghi jkl gugu"
> >
> >
> > How is it done in Python?
>
> Here is how to do it without regexps in python.
> The first and last line below are all that are needed. The others show
> intermediate expressions that lead to the result.
>
> >>> from itertools import groupby
>
> >>> na="Abc | def | ghi | jkl [gugu]"
> >>> [(g[0], ''.join(g[1])) for g in groupby(na, lambda c: c not in ' \t|[]')]
> [(True, 'Abc'), (False, ' | '), (True, 'def'), (False, ' | '), (True,
> 'ghi'), (False, ' | '), (True, 'jkl'), (False, ' ['), (True, 'gugu'),
> (False, ']')]
> >>> [''.join(g[1]) for g in groupby(na, lambda c: c not in ' \t|[]') if g[0]]
> ['Abc', 'def', 'ghi', 'jkl', 'gugu']
>
> >>> ' '.join(''.join(g[1]) for g in groupby(na, lambda c: c not in ' \t|[]') 
> >>> if g[0])
> 'Abc def ghi jkl gugu'
> >>>
>
>
> - Paddy.

And I leave the deletion of def to the reader :-)

(i.e: I missed that bit and adding it in would make a long
comprehension too long to comprehend).

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


Re: C++/Python programmers for a MUD's gamedriver wanted.

2007-01-06 Thread Paul McGuire
"Rythin" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi everyone.
> We are looking for a volunteer co-programmers for a MUD's gamedriver
> project. As of now, a gamedriver is divided into two separate but
> tightly interconnected systems - C++ driver and Python lib.
>
> C++ Driver is supposed to be managing memory, proccesses and
> communication between them (transparent as far as net is concerned).
> Python lib is to define the user's interfaces. Both of them are
> designed to work in an object-oriented enviroment, with lib's classes
> being driver's child-classes.
>

Have you considered whether the C++ Driver is even necessary?  Python's 
run-time engine already implements the memory and process management tasks, 
and does so in compiled C code (and has been tested and retested by 
hundreds, nay thousands, perhaps even millions of Python users). 
Interprocess communication can be done using CORBA or Pyro add-ons.

You may do better by "letting Python be Python" instead of confining it to 
limited user graphical and/or text interaction, and then 
marshaling/unmarshaling commands and responses to and from the C++ layer. 
Before getting too wrapped up in the C++ core/utility layer, get this (or a 
prototype) running in pure Python first, measure the performance, and then 
reimplement in C/Pyrex/ShedSkin/C++ for the performance-intensive bits.

-- Paul


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


Re: python, zlib, and fedora 64bits

2007-01-06 Thread Tarek Ziadé

On 1/6/07, Tarek Ziadé <[EMAIL PROTECTED]> wrote:


I am answering to myself, if it can help someone else.

zlib has to be recompiled with CFLAGS set to -fPIC.

So before launching ./configure do a:

export CFLAGS="-fPIC"

Python then will build properly zlib.so


Tarek





--
Tarek Ziadé | Association AfPy | www.afpy.org
Blog FR | http://programmation-python.org
Blog EN | http://tarekziade.wordpress.com/
-- 
http://mail.python.org/mailman/listinfo/python-list

c# application calling Scipy

2007-01-06 Thread dongarbage
Hi,

Novice here. :)

I'm building a c# application and I want to call functions in SciPy
from that application.

What's the best way to call SciPy methods from a C# program?

Is there a best Python implementation for this? Ironython? Python for
.NET? Enthought?

Thanks in advance,
Don

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


A problem in embedding Python in a plug-in

2007-01-06 Thread Koichi
Hi, I'm now making a plug-in for a CG software. I embed
Python in a plugin and it works. The problem is that it
conflicts with other plugins that also embeds Python because it
runs in the same thread. I don't know when Py_Initialize() and
Py_Finalize() are executed because I don't know when user loads/unloads
a plugin that embeds Python. Is there any right way to embed
Python in a plug-in under the following conditions? If not, what
options do I have to give up any of them?

- My plug-in has no way to know when the user loads/unloads it.
- My plug-in has no way to know when the user loads/unloads somebody
  else's plug-in that embeds Python.
- Somebody else's plug-in might have used any Python/C API including
  GIL related stuff, new_interpreter, PyGILState_*
- Every plug-in initially runs in the same thread but some plug-in
  can start a new thread.
- Preferably my plug-in has its own __main__
- My plug-in doesn't have to be thread safe but shouldn't disturb
  any other plug-in (so should be thread safe anyway)

Typical problem is:
- When somebody else loads or unloads another plugin and calls
  Py_IsInitialized() or Py_Finalize(), my plugin fails
- When some other plugin uses PyGILState*(), both plugin fails
  because my plug-in uses new interpreter
(I'm new to Python/C API so I may be misunderstanding one ore more)

Any suggestion is appreciated.

Koichi


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


still struggling, howto use a list-element as a name ?

2007-01-06 Thread Stef Mientki
In the example below, "pin" is an object with a number of properties.
Now I want
1- an easy way to create objects that contains a number of these "pin"
2- an multiple way to access these "pin", i.e.
 device.pin[some_index]
device.some_logical_name
ad 1:
a dictionary (as "pinlist" in the example) seems a very convenient 
 way (from a viewpoint of the device creator).
As you can see in the "__init__" section this dictionary can easily be 
transported to the pin-objects.

ad 2:
THAT's the problem: how do automate these lines "self.GND = self.pin[0]"

I'm also in for other solutions.

thanks,
Stef


class Power_Supply(device):
 pinlist = {
 0: ('GND', _DIG_OUT, _par2),
 1: ('VCC', _DIG_OUT, _par33)
 }

 def __init__(self):
 # store pin-names and pin-parameters in pins
 for k in self.pinlist.keys():
   self.pin[k].Name = self.pinlist[k][0]
   self.pin[k].Value = self.pinlist[k][2]

 # for some pins, we also want to be able to use logical names
 # HOW TO USE SOMETHING like
 # "self.pinlist[0] = self.pin[0]"
 # INSTEAD OF
 self.GND = self.pin[0]
 self.VCC = self.pin[1]

# create a Power_Supply instance and
# test if pins can be referenced in
Power = Power_Supply()
netlist1 = ( Power.VCC, Power.pin[1], Power.GND, Power.pin[0] )
-- 
http://mail.python.org/mailman/listinfo/python-list


Python and SDK5.1 are just terrific!!!

2007-01-06 Thread Siggi
Thanks, Jussi, for your post, but I found that PythonWin's SDK5.0 option 
works well with MS SDk5.1.
Just had an Email read for me using a small Python program: correct English, 
even the date such as 12/06/06 was correctly transformed into the names of 
the month and year. Python is great1

Siggi


"Jussi Salmela" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
> Siggi kirjoitti:
>> Gabriel Genellina wrote:
>>
>>> After you download and install version 5.1, it should appear on the 
>>> list.
>>
>> It should, but it does not! Shutting down and starting the WinXP Home 
>> system anew did not help.
>> The SDK 5.1 installation went smoothly, however. What can I do to find 
>> out
>> what is wrong?
>>
>> siggi
>>
>
>
> (Sorry for the long post!)
>
>
> Unfortunately I can't comment on this 5.0/5.1 issue but if you look at 
> page
> http://www.cs.unc.edu/~parente/tech/tr02.shtml
> you'll find the pyTTS system. I've used it and everything works.
>
> The funny thing is that the page has a link named "Microsoft SAPI 5.1 
> redistributable" which links to
> http://www.cs.unc.edu/Research/assist/packages/SAPI5SpeechInstaller.msi
> ie. a SAPI 5 installer. So I'm starting to wonder if it matters at all 
> whether the speech kit is a version 5 or 5.1.
>
> Anyway: pyTTS works with Python 2.4 as advertized in the accompanying 
> examples. I've used it to resolve the following dilemma: how to guarantee 
> that I'm aware of new mail appearing on my ISP.
>
> I had an unfortunate experience where a guy I was working with sent me (to 
> my home) mail that I didn't expect to receive just at the moment and to 
> which I would have liked to react immediately. Why I didn't notice the 
> mail coming: I was outside my house pumping more air to my wife's bicycle 
> tires! The mail notification was shown and erased and one more icon among 
> the more than dozen icons on my Windows System Tray didn't account for 
> much.
>
> So I figured out that a voice to remind me would be nice. I have a low 
> rate inbox, usually only a maximum of hald a dozen messages per day so I 
> wouldn't have to listen the voice all day long. So the voice keeps 
> repeating that I have new mail at my ISP until I download the mail and 
> otherwise keeps quiet. So here is my program and a skeleton of the INI 
> file it uses. The program is not finished (I have a few ideas still) but 
> it runs all day long on my computer keeping me happy.
>
> ==
> New Email Notifier.py
> ==
> #!/usr/bin/python
>
> '''
> License: MIT License. See License.txt. If that file is not attached,
> the license is http://www.opensource.org/licenses/mit-license.php, 
> where
>  = 2006 and  = Jussi Salmela, Turku, Finland
> '''
>
> # This program checks for new email at ISP and notifies if new email is 
> found
>
> import win32serviceutil
> import win32service
> import win32event
> import pyTTS, sys, os, poplib, logging, time
> import ConfigParser,pywintypes
>
> print '\nThis is the New Mail Notifier window\n'
> notifierDirectory = r'C:\Python\OMAT___PROJEKTIT\New Email Notifier 
> Service'
> logging.basicConfig(level=logging.DEBUG,
> format='%(asctime)s %(levelname)-8s %(message)s',
> filename=notifierDirectory+r'\error.log')
> logging.info('=')
> logging.info('New Email Notifier Service started')
> config = ConfigParser.ConfigParser()
> config.readfp(open(notifierDirectory+r'\New Email Notifier.INI'))
> POP3Server = config.get('POP3','server')
> POP3Account = config.get('POP3','account')
> POP3Password = config.get('POP3','password')
> totalMessagesFormat = config.get('messages','total_message')
> newMessagesFormat = config.get('messages','new_message')
> wakeupMessageFormat = config.get('messages','wakeup_message')
>
> tts = pyTTS.Create()
> #set the speech volume percentage (0-100%)
> tts.Volume = 100
> #explicitly set a voice
> tts.SetVoiceByName(u'MSMary')
>
> uidDict = {}
> # We wait to be stopped and check for new email every maxTimeToWait 
> seconds
> maxTimeToWait = 1 # First check after 1 second
> while True:
> time.sleep(maxTimeToWait)
> maxTimeToWait = 60 # Rest of the checks after 60 second
> try:
> # Connect to the ISP
> a = poplib.POP3(POP3Server,110)
> answer = a.getwelcome()
> if answer[0:3] != '+OK':
> raise ValueError,'a.getwelcome returned: ' + answer
> answer = a.user(POP3Account)
> if answer[0:3] != '+OK':
> raise ValueError,'a.user returned: ' + answer
> if answer[4:] == 'Password required':
> answer = a.pass_(POP3Password)
> if answer[0:3] != '+OK':
> raise ValueError,'a.pass_ returned: ' + answer
> answer = a.uidl()
> if answer[0][0:3] != '+OK':
> raise ValueError,'a.uidl returned: ' + repr(answer)
> a.quit()
> # Connec

nntplib downloads content with extra linebreaks

2007-01-06 Thread rweth
I am using nntplib to download archived xml messages from our internal 
newsgroup. This is working fine except the download of files  to the 
connected server, has extra embedded
lines in them (all over the place), from the
   s.body(id,afile)  # body method

Is there any way to employ this library to strip out these extra
line breaks? I know this may seem trivial but they cause serious
issues when I try and employ the subsequent downloaded xml file
for a series of processes.

When I forward one of these files from Thunderbird (via the newsgroup)
to outlook and open it up, and then select  "ignore extra line breaks",
and cut and paste the content .. all is well. The file is "healed".

Apart from being just a plain annoyance (all this manual steps) it 
really bothers me something this trivial (the pretty-fication of 
content) would  throw me out of whack so badly .. also that outlook has 
some simple method that magically does what I need and I cannot hack it 
for myself. (not to mention how brittle
the xml processing we must have in place is .. )

First I thought it was a  call to RFC 977(or below)  which I cannot work 
out, but which does the deed! But then I though that the content of the 
forwarded msg has something in it which outlook can filter ..
because the forwarded msg is encapsulated, and likely cut off from the 
news server.
(what do I know these are guesses)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread Patrick Mullen

You would use setattr to bind a name that you don't know:

for pin in self.pin:
  setattr(self,pin.Name,pin.Value)

However, I'm not sure why you're using a dictionary in this way.  I don't
totally understand the context, so I may be wrong, but I would code it more
like this:

class Power_Supply(device):
  pins = {'GND':(_DIG_OUT,_par2),'VCC':(_DIG_OUT,_par33)}
  def __init__(self):
 for pin in pins.items():   #pin will be key,value
setattr(self,pin[0],pin[1])

or even:

class Power_Supply(device):
  pins = {'GND':(_DIG_OUT,_par2),'VCC':(_DIG_OUT,_par33)}
  def __init__(self):
 self.__dict__.update(pins)
#self.__dict__ is the name mapping for any object, update will insert any
new values from a new dictionary into the old one
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Adding a directory to the Python System Path - Edit the registry?

2007-01-06 Thread rweth
[EMAIL PROTECTED] wrote:
> Thanks Martin.
> 
> I'll take a look at the documentation you pointed out.
> 
> Scott
> 
> Martin P. Hellwig wrote:
>> [EMAIL PROTECTED] wrote:
>>> I have been trying to find a way to add a directory to Python's sytem
>>> path on my MS Windows XP computer. I did some searching online, but the
>>> only solution I found involved editing the MS Windows Registry. That
>>> seemed a little to hard core. Is there another easier way to do this?
>>>
>>> Thanks,
>>>
>>> Scott Huey
>>>
>> Take a look at:
>> http://docs.python.org/tut/node8.html
>>
>> Specifically 6.1.1 and 6.2, perhaps that might answer your question.
>>
>> Cheers
>>
>> -- 
>> mph
> 

There is a file you can use to extend your system path on my windows box 
it is here:
C:\Python24\Lib\site-packages\package.pth

Inside the package.pth I have added:
   C:\\QA\\bin
I think I needed to do this in linux as well (and it worked).
Find your installation path to ../Lib/site-packages and if that file 
does not exist create it and add your paths in their own lines no 
separators needed.




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


Re: nntplib downloads content with extra linebreaks

2007-01-06 Thread Klaus Alexander Seistrup
Rweth wrote:

> I am using nntplib to download archived xml messages from our 
> internal newsgroup. This is working fine except the download 
> of files  to the connected server, has extra embedded lines in 
> them (all over the place), from the
>s.body(id,afile)  # body method

The 'linebreaks' are probably '\r\n' pairs, so you could do a

buf.replace('\r\n', '\n')

to convert all such pairs to single LFs (buf being the buffer or 
string that holds the text with 'linebreaks').

Cheers,

-- 
Klaus Alexander Seistrup
http://klaus.seistrup.dk/

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


Re: python, zlib, and fedora 64bits

2007-01-06 Thread Tarek Ziadé

I am answering to myself, if it can help someone else.

zlib has to be recompiled with CFLAGS set to -fPIC.

So before launching ./configure do a:

export CFLAGS="-fPIC"

Python then will build properly zlib.so


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

search mail by date with imaplib

2007-01-06 Thread csselo
Hi
I am looking for a code sample which searches mail by date with imaplib

example:
get email from 01.01.2007 to now

how can I change imaplib search parameters?

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


Re: nntplib downloads content with extra linebreaks

2007-01-06 Thread rweth
Klaus Alexander Seistrup wrote:
> Rweth wrote:
> 
>> I am using nntplib to download archived xml messages from our 
>> internal newsgroup. This is working fine except the download 
>> of files  to the connected server, has extra embedded lines in 
>> them (all over the place), from the
>>s.body(id,afile)  # body method
> 
> The 'linebreaks' are probably '\r\n' pairs, so you could do a
> 
>   buf.replace('\r\n', '\n')
> 
> to convert all such pairs to single LFs (buf being the buffer or 
> string that holds the text with 'linebreaks').
> 
> Cheers,
> 
Well Klaus I tried it .. sadly no joy.
Lets see if I did it the way you would have:
   buf = s.body(id)[3]
   # indexes 0 .. 2 contain disjoint portions but the big part is in
   # [3] so  .. i only did it for 3 for simplification
   bufHeal = []
   for aline in buf:
  bufHeal.append(aline.replace('\r\n', '\n'))

   fn = "c:/boing.xml"
   fh = open(fn.'w')
   for aline in bufHeal:
 fh.write(aline)
   fh.close()

This is giving me a file with no line breaks .. in fact
when I look at the elements in buf .. they don't have \r\n or \n at the 
end of them .. I think the s.body(id,afile) .. does a variety of magic 
to the contents of the buffer .. along with applying "some
magic template directive like an xsd file" again just guessing here.



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


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread rzed
Stef Mientki <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> In the example below, "pin" is an object with a number of
> properties. Now I want
> 1- an easy way to create objects that contains a number of these
> "pin" 2- an multiple way to access these "pin", i.e.
>  device.pin[some_index]
>  device.some_logical_name
> ad 1:
> a dictionary (as "pinlist" in the example) seems a very
> convenient 
>  way (from a viewpoint of the device creator).
> As you can see in the "__init__" section this dictionary can
> easily be transported to the pin-objects.
> 
> ad 2:
> THAT's the problem: how do automate these lines "self.GND =
> self.pin[0]" 
> 
> I'm also in for other solutions.
> 
> thanks,
> Stef
> 
> 
> class Power_Supply(device):
>  pinlist = {
>  0: ('GND', _DIG_OUT, _par2),
>  1: ('VCC', _DIG_OUT, _par33)
>  }
> 
>  def __init__(self):
>  # store pin-names and pin-parameters in pins
>  for k in self.pinlist.keys():
>self.pin[k].Name = self.pinlist[k][0]
>self.pin[k].Value = self.pinlist[k][2]
> 
>  # for some pins, we also want to be able to use logical
>  names # HOW TO USE SOMETHING like
>  # "self.pinlist[0] = self.pin[0]"
>  # INSTEAD OF
>  self.GND = self.pin[0]
>  self.VCC = self.pin[1]
> 
> # create a Power_Supply instance and
> # test if pins can be referenced in
> Power = Power_Supply()
> netlist1 = ( Power.VCC, Power.pin[1], Power.GND, Power.pin[0] )

I may be confused about what you're after, but wouldn't something 
like this work? (I don't know what a _par2 object is; I've named 
it something here.)

class Power_Supply(device):
def __init__(self):
self.pin = {
0:dict(Name='GND',Value=_DIG_OUT,something=_par2),
1:dict(Name='VCC',Value=_DIG_OUT,something=_par33),
}
for k in self.pin.keys():
self.__dict__[self.pin[k]['Name']] = self.pin[k]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search mail by date with imaplib

2007-01-06 Thread rweth
[EMAIL PROTECTED] wrote:
> Hi
> I am looking for a code sample which searches mail by date with imaplib
> 
> example:
> get email from 01.01.2007 to now
> 
> how can I change imaplib search parameters?
> 
So I had to do the same thing a few years back. I love python but
seriously every author spends less than 1/10 of 1% on doc !

Well So do I .. so take it with a grain of salt. Here is what I did,
MANY YEARS AGO .. I don't even have a IMAP account anymore

t,data = M.uid("SEARCH",None,'(FROM blahblah)')
luid = string.split(data[0])
for uid in luid:
   t,d = M.uid("FETCH",uid,"(BODY[HEADER.FIELDS (DATE SUBJECT TO)])")
   date = d[0][1]

This will get you the dates .. and you can write your own
filter off that .. it's trivial. What isn't so great is
getting every piece of mail and then searching for the needle's in
the haystack.

So I guess this is plan c (just in case you don't get a better answer).
I will watch this one for a "plan a | b" answer.


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


Re: nntplib downloads content with extra linebreaks

2007-01-06 Thread Klaus Alexander Seistrup
Rweth wrote:

>for aline in buf:
>   bufHeal.append(aline.replace('\r\n', '\n'))

What does one single aline look like?

> s.body(id,afile)

Does the 'afile' contain a filename or a filepointer?

Cheers,

-- 
Klaus Alexander Seistrup
http://klaus.seistrup.dk/

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


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread Stef Mientki
>> class Power_Supply(device):
>>  pinlist = {
>>  0: ('GND', _DIG_OUT, _par2),
>>  1: ('VCC', _DIG_OUT, _par33)
>>  }
> 
> I may be confused about what you're after, but wouldn't something 
> like this work? (I don't know what a _par2 object is; I've named 
> it something here.)
_par2, is just (a reference to) a constant
> 
> class Power_Supply(device):
> def __init__(self):
> self.pin = {
> 0:dict(Name='GND',Value=_DIG_OUT,something=_par2),
> 1:dict(Name='VCC',Value=_DIG_OUT,something=_par33),
> }
Why so complex, I need 10 or more parameters (or empty),
and then this becomes completely unreadable.
As this is part of the "user interface",
(I want that completely unknown with Python people,
write these lines),
I think my "pinlist" is much easier.


> for k in self.pin.keys():
> self.__dict__[self.pin[k]['Name']] = self.pin[k]
thanks "rzed" ?,
that is exactly what I was looking for:
   self.__dict__[self.pinlist[k][0]] = self.pin[k]


cheers,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dividing integers...Convert to float first?

2007-01-06 Thread Thomas Ploch
Beliavsky schrieb:
> If the C or Fortran committees tried to change
> the meaning of int/int, they would be shot.

Or hanged...

> If you want to be confident that your code will run, unchanged, 10
> years from now on the hardware and OS that will then be common, Python
> 2.x is not the language to use, unfortunately. From what I have read,
> Python 3 will break things more fundamental than int/int.
> 

Yes, but until then we have to use python 2.x. And I think that python
2.x will be around quite a while after python 3000 has been released if
it breaks so much.

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


Re: nntplib downloads content with extra linebreaks

2007-01-06 Thread rweth
Klaus Alexander Seistrup wrote:
> Rweth wrote:
> 
>>for aline in buf:
>>   bufHeal.append(aline.replace('\r\n', '\n'))
> 
> What does one single aline look like?
> 
>> s.body(id,afile)
> 
> Does the 'afile' contain a filename or a filepointer?
> 
> Cheers,
> 
so afile contains a filename.
One single aline looks like so:
   ''


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


Re: File Closing Problem in 2.3 and 2.4, Not in 2.5

2007-01-06 Thread rweth
Martin v. Löwis wrote:
> Carroll, Barry schrieb:
>> What I want to know is:
>>
>> * has anyone else encountered a problem like this, * how was the
>> problem corrected, * can the fix be retro-fitted to 2.5 and 2.4?
> 
> From your description, I suspect an error in your code. Your description
> indicates that you don't expect to have more than five files open
> simultaneously. Yet, the error message "Too many open files" occurs when
> you open many more files (in the order of hundreds of files).
> 
> It is very unlikely that there is a bug in Python where it would fail to
> close a file when .close() is explicitly invoked on it (as your
> description suggests that you do), so if you get that error message, it
> can only mean that you fail to close some files.
> 
> Notice that you may have other files open, as well, and that those also
> count towards the limit.
> 
> As a debugging utility, you can use Sysinternal's process explorer.
> Make the program halt (not exit) when the exception occurs (e.g. by
> having it sleep(1) in a loop), then view all open handles in the
> process explorer (check the menu if it doesn't display them initially).
> 
> Regards,
> Martin

I agree with Martin .. this code to close is solid.

Make certain you are really closing the files when you think you should. 
I am pretty sure you are not. Look at the code that closes the files 
closely. Put a print statement in the block that is supposed to close 
the files (may bee even a raw_input("closing file" + afile)  statement).

My guess is that you won't see the print statements trigger when you 
though they should .. they may be out of "the loop" you thought that 
they were in.


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


Recommended way to force a thread context switch?

2007-01-06 Thread Lloyd Zusman
I have a python (2.5) program with number of worker threads, and I want
to make sure that each of these does a context switch at appropriate
times, to avoid starvation.  I know that I can do a time.sleep(0.001) to
force such a switch, but I'm wondering if this is the recommended
method.

Thanks in advance.


-- 
 Lloyd Zusman
 [EMAIL PROTECTED]
 God bless you.

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


Re: nntplib downloads content with extra linebreaks

2007-01-06 Thread Klaus Alexander Seistrup
Rweth wrote:

> so afile contains a filename.
> One single aline looks like so:
>''

Beats me where those empty lines come from, it doesn't seem to 
happen in nntplib.

Does the same thing happen if you pass .body() a filepointer?

Cheers,

-- 
Klaus Alexander Seistrup
http://klaus.seistrup.dk/

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


Re: Recommended way to force a thread context switch?

2007-01-06 Thread Duncan Booth
Lloyd Zusman <[EMAIL PROTECTED]> wrote:

> I have a python (2.5) program with number of worker threads, and I want
> to make sure that each of these does a context switch at appropriate
> times, to avoid starvation.  I know that I can do a time.sleep(0.001) to
> force such a switch, but I'm wondering if this is the recommended
> method.

The recommended method is to start a new thread rather than following up on 
an existing thread with an unrelated question.

Why do you think that just letting the threads run won't have the effect 
you desire? Leave it to the system to schedule the threads.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread Bruno Desthuilliers
Stef Mientki a écrit :
> In the example below, "pin" is an object with a number of properties.
> Now I want
> 1- an easy way to create objects that contains a number of these "pin"
> 2- an multiple way to access these "pin", i.e.
> device.pin[some_index]
> device.some_logical_name
> ad 1:
> a dictionary (as "pinlist" in the example) seems a very convenient 
> way (from a viewpoint of the device creator).
> As you can see in the "__init__" section this dictionary can easily be 
> transported to the pin-objects.
> 
> ad 2:
> THAT's the problem: how do automate these lines "self.GND = self.pin[0]"
> 
> I'm also in for other solutions.

I'm afraid I don't understand your design (nor the domain FWIW). A few 
comments anyway:

> 
> class Power_Supply(device):

Please reread my comments about naming convention in a previous thread...

> pinlist = {

This is *not* a list, so naming it 'pinlist' is misleading. Also, why is 
this defined here ?

> 0: ('GND', _DIG_OUT, _par2),
> 1: ('VCC', _DIG_OUT, _par33)
> }
> 
> def __init__(self):
> # store pin-names and pin-parameters in pins
> for k in self.pinlist.keys():
>   self.pin[k].Name = self.pinlist[k][0]

What is 'self.pin' ? Where is it defined ? (NB : please try to post 
*runnable* code).

And FWIW, if it's a container, why is it named 'pin', and not 'pins' ?


>   self.pin[k].Value = self.pinlist[k][2]

The appropriate way to use the for loop here is:
   for k, v in self.pinlist.items():
  self.pin[k].name = v[0]
  # etc

> # for some pins, we also want to be able to use logical names
> # HOW TO USE SOMETHING like
> # "self.pinlist[0] = self.pin[0]"
> # INSTEAD OF
> self.GND = self.pin[0]
> self.VCC = self.pin[1]

you can build a 'reversed index':
 # store pin-names and pin-parameters in pins
   for k, v in self.pinlist.items():
  self.pin[k].name = v[0]
  self.pin[k].value = v[2]
  self.reversed_index[v[0]] = self.pin[k]

and then use the __getattr__ hook:

   def __getattr__(self, name):
 return self.reversed_index[name]

But the whole thing still looks awfully convulted and kludgy to me, and 
I suspect serious design flaws... Why don't you try and explain  your 
real problem, instead of asking how to implement what you *think* is the 
solution ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recommended way to force a thread context switch?

2007-01-06 Thread Lloyd Zusman
Duncan Booth <[EMAIL PROTECTED]> writes:

> Lloyd Zusman <[EMAIL PROTECTED]> wrote:
>
>> I have a python (2.5) program with number of worker threads, and I want
>> to make sure that each of these does a context switch at appropriate
>> times, to avoid starvation.  I know that I can do a time.sleep(0.001) to
>> force such a switch, but I'm wondering if this is the recommended
>> method.
>
> The recommended method is to start a new thread rather than following up on 
> an existing thread with an unrelated question.

I accidentally hit "a" in my mailer instead of "w" ("reply" instead of
"compose").  Geez.  It was an accident.  I'm sorry.


> Why do you think that just letting the threads run won't have the effect 
> you desire? Leave it to the system to schedule the threads.

I can already see that they don't have the effect I desire.  They are
long numerical calculations in tight loops.  I have to periodically put
explicit time.sleep(0.001) calls in place to force the context
switching, and I was wondering if that's the recommended method.


-- 
 Lloyd Zusman
 [EMAIL PROTECTED]
 God bless you.

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


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread rzed
Stef Mientki <[EMAIL PROTECTED]> wrote in news:182cf
[EMAIL PROTECTED]:

>>> class Power_Supply(device):
>>>  pinlist = {
>>>  0: ('GND', _DIG_OUT, _par2),
>>>  1: ('VCC', _DIG_OUT, _par33)
>>>  }
>> 
>> I may be confused about what you're after, but wouldn't 
something 
>> like this work? (I don't know what a _par2 object is; I've 
named 
>> it something here.)
> _par2, is just (a reference to) a constant
>> 
>> class Power_Supply(device):
>> def __init__(self):
>> self.pin = {
>> 0:dict(Name='GND',Value=_DIG_OUT,something=_par2),
>> 1:dict(Name='VCC',Value=_DIG_OUT,something=_par33),
>> }
> Why so complex, I need 10 or more parameters (or empty),
> and then this becomes completely unreadable.
> As this is part of the "user interface",
> (I want that completely unknown with Python people,
> write these lines),
> I think my "pinlist" is much easier.
> 

Whatever works for you. In your original example, you first 
created "pinlist" (which is actually a Python dict), and then used 
it to place values in an unspecified type named "pin" (which I 
took to be another dict). I just combined the two steps.

You talk about the "pinlist" being easier ... I'm not sure what 
you mean. Easier to create? Maybe. But if you are then going to 
assign the values to names, then it doesn't strike me as easier to 
go through the two-step process. But as I said, I may be confused 
about what you are really trying to do.

> 
>> for k in self.pin.keys():
>> self.__dict__[self.pin[k]['Name']] = self.pin[k]
> thanks "rzed" ?,
> that is exactly what I was looking for:
>self.__dict__[self.pinlist[k][0]] = self.pin[k]

I'm glad it helped.

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


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread Bruno Desthuilliers
Stef Mientki a écrit :
 > rzed wrote:
(snip)

>> class Power_Supply(device):
>> def __init__(self):
>> self.pin = {
>> 0:dict(Name='GND',Value=_DIG_OUT,something=_par2),
>> 1:dict(Name='VCC',Value=_DIG_OUT,something=_par33),
>> }
> 
> Why so complex, I need 10 or more parameters (or empty),

or empty ???

> and then this becomes completely unreadable.

Named parameters are way much readables than a 10+ tuple. No one is 
going to remember a 10+ list of params.

  > As this is part of the "user interface",
> (I want that completely unknown with Python people,
> write these lines),
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread Bruno Desthuilliers
rzed a écrit :
(snip)
> for k in self.pin.keys():
> self.__dict__[self.pin[k]['Name']] = self.pin[k]

for pin self.pin.values():
   self.__dict__[pin['name']] = pin

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


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread Jussi Salmela
Bruno Desthuilliers kirjoitti:
> Stef Mientki a écrit :
>> In the example below, "pin" is an object with a number of properties.
>> Now I want
>> 1- an easy way to create objects that contains a number of these "pin"
>> 2- an multiple way to access these "pin", i.e.
>> device.pin[some_index]
>> device.some_logical_name
>> ad 1:
>> a dictionary (as "pinlist" in the example) seems a very convenient 
>> way (from a viewpoint of the device creator).
>> As you can see in the "__init__" section this dictionary can easily be 
>> transported to the pin-objects.
>>
>> ad 2:
>> THAT's the problem: how do automate these lines "self.GND = self.pin[0]"
>>
>> I'm also in for other solutions.
> 
> I'm afraid I don't understand your design (nor the domain FWIW). 
ditto
> 
> 
> But the whole thing still looks awfully convulted and kludgy to me, and 
> I suspect serious design flaws... Why don't you try and explain  your 
> real problem, instead of asking how to implement what you *think* is the 
> solution ?
ditto

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


Re: search mail by date with imaplib

2007-01-06 Thread Jean-Paul Calderone
On Sat, 06 Jan 2007 11:49:17 -0800, rweth <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] wrote:
>> Hi
>> I am looking for a code sample which searches mail by date with imaplib
>>
>> example:
>> get email from 01.01.2007 to now
>>
>> how can I change imaplib search parameters?
>>
>So I had to do the same thing a few years back. I love python but
>seriously every author spends less than 1/10 of 1% on doc !
>
>Well So do I .. so take it with a grain of salt. Here is what I did,
>MANY YEARS AGO .. I don't even have a IMAP account anymore
>
>t,data = M.uid("SEARCH",None,'(FROM blahblah)')
>luid = string.split(data[0])
>for uid in luid:
>   t,d = M.uid("FETCH",uid,"(BODY[HEADER.FIELDS (DATE SUBJECT TO)])")
>   date = d[0][1]
>
>This will get you the dates .. and you can write your own
>filter off that .. it's trivial. What isn't so great is
>getting every piece of mail and then searching for the needle's in
>the haystack.
>
>So I guess this is plan c (just in case you don't get a better answer).
>I will watch this one for a "plan a | b" answer.
>

The SEARCH command supports quite a few kinds of criteria.  Several which
may be relevant here are BEFORE, SINCE, SENTBEFORE, and SENTSINCE.  Using
Twisted's IMAP4 code, you can format a query like this:

>>> from twisted.mail.imap4 import Query
>>> Query(after='01-Jan-2007')
'(AFTER "01-Jan-2007")'
>>>

Since documentation was brought up, I'll point out Query's docs too, since
that might help shed some further light on what's possible.

http://twistedmatrix.com/documents/current/api/twisted.mail.imap4.html#twisted.mail.imap4.Query

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


WoC - A web of code

2007-01-06 Thread aliptah
Web Of Code

http://idiki.dyne.org/wiki/WoC

WoC stands for Web Of Code.

The basic idea is to add hyperlink capacities to source code documents,
creating, in this way, a new Web, of code.

The Idiki article describes the idea and shows how it can be
implemented using
existing tools, f.e. ViewVC, cscope and Vim.

Another idea explored by the article is:

   #!/usr/bin/python
   from :openssl.org/ssl: import RSA*

The article is here: http://idiki.dyne.org/wiki/WoC

Best regards.

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


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread Stef Mientki
Jussi Salmela wrote:
> Bruno Desthuilliers kirjoitti:
>> Stef Mientki a écrit :
>>> In the example below, "pin" is an object with a number of properties.
>>> Now I want
>>> 1- an easy way to create objects that contains a number of these "pin"
>>> 2- an multiple way to access these "pin", i.e.
>>> device.pin[some_index]
>>> device.some_logical_name
>>> ad 1:
>>> a dictionary (as "pinlist" in the example) seems a very 
>>> convenient way (from a viewpoint of the device creator).
>>> As you can see in the "__init__" section this dictionary can easily 
>>> be transported to the pin-objects.
>>>
>>> ad 2:
>>> THAT's the problem: how do automate these lines "self.GND = self.pin[0]"
>>>
>>> I'm also in for other solutions.
>>
>> I'm afraid I don't understand your design (nor the domain FWIW). 
> ditto
>> 
>>
>> But the whole thing still looks awfully convulted and kludgy to me, 
>> and I suspect serious design flaws... Why don't you try and explain  
>> your real problem, instead of asking how to implement what you *think* 
>> is the solution ?
> ditto

thank you all guys.
I'm just doing some exercises in Python,
and therefor I'm trying to rewrite some programs
I've written in other languages into Python.

The first program I tried to convert was a MatLab program,
which could almost be written identical in Python.
Even with my little experience in Python,
I can tell you that it could have been written in Python
in a much better way, but I deliberately did not,
to show other people who are familiar with MatLab.

The second example I'm now exercising with,
is a simulator of (electrical) circuits,
which I build in Delphi
   http://oase.uci.kun.nl/~mientki/data_www/pic/jalss/jalss.html





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


Re: search mail by date with imaplib

2007-01-06 Thread rweth
Jean-Paul Calderone wrote:
> On Sat, 06 Jan 2007 11:49:17 -0800, rweth <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>>> Hi
>>> I am looking for a code sample which searches mail by date with imaplib
>>>
>>> example:
>>> get email from 01.01.2007 to now
>>>
>>> how can I change imaplib search parameters?
>>>
>> So I had to do the same thing a few years back. I love python but
>> seriously every author spends less than 1/10 of 1% on doc !
>>
>> Well So do I .. so take it with a grain of salt. Here is what I did,
>> MANY YEARS AGO .. I don't even have a IMAP account anymore
>>
>> t,data = M.uid("SEARCH",None,'(FROM blahblah)')
>> luid = string.split(data[0])
>> for uid in luid:
>>   t,d = M.uid("FETCH",uid,"(BODY[HEADER.FIELDS (DATE SUBJECT TO)])")
>>   date = d[0][1]
>>
>> This will get you the dates .. and you can write your own
>> filter off that .. it's trivial. What isn't so great is
>> getting every piece of mail and then searching for the needle's in
>> the haystack.
>>
>> So I guess this is plan c (just in case you don't get a better answer).
>> I will watch this one for a "plan a | b" answer.
>>
> 
> The SEARCH command supports quite a few kinds of criteria.  Several which
> may be relevant here are BEFORE, SINCE, SENTBEFORE, and SENTSINCE.  Using
> Twisted's IMAP4 code, you can format a query like this:
> 
>>>> from twisted.mail.imap4 import Query
>>>> Query(after='01-Jan-2007')
>'(AFTER "01-Jan-2007")'
>>>>
> 
> Since documentation was brought up, I'll point out Query's docs too, since
> that might help shed some further light on what's possible.
> 
> http://twistedmatrix.com/documents/current/api/twisted.mail.imap4.html#twisted.mail.imap4.Query
>  
> 
> 
> Jean-Paul
Wow looks like twisted took Imap4 and made it better!
I think I had better read up on twisted .. this looks quite
good (Plan A for sure).
-- 
http://mail.python.org/mailman/listinfo/python-list


Crash on

2007-01-06 Thread John Pye
Hi all

I have a unittest test suite that's testing a fairly large SWIG-wrapped
application via Python. All my tests are passing at the moment, but
when Python exits, I get the following (shown below).

Could anyone please help me to understand what precisely this message
means (other than that obviously I have made a mistake with object
ownership or INCREF or DECREF somewhere), and what the best way of
tracking down the source of the problem might be?

Cheers
JP

--
Ran 63 tests in 3.269s

OK
python: Modules/gcmodule.c:275: visit_decref: Assertion `gc->gc.gc_refs
!= 0' failed.
process killed by signal 6
program finished with exit code -1

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


Re: Recommended way to force a thread context switch?

2007-01-06 Thread Duncan Booth
Lloyd Zusman <[EMAIL PROTECTED]> wrote:

>> Why do you think that just letting the threads run won't have the
>> effect you desire? Leave it to the system to schedule the threads.
> 
> I can already see that they don't have the effect I desire.  They are
> long numerical calculations in tight loops.  I have to periodically
> put explicit time.sleep(0.001) calls in place to force the context
> switching, and I was wondering if that's the recommended method.
> 
Not really.

If the context isn't switching enough for you then try calling 
sys.setcheckinterval(n) with varying values of n until you find one which 
is suitable. Calling it with a lower value of n will increase the frequency 
that you switch thread contexts, although of course it will also increase 
the overall runtime for your program.

Alternatively you could try splitting your processing into smaller chunks 
and ensure each thread does a small chunk at a time instead of a large one.

Why does it matter whether individual threads are being 'starved'? Surely 
you want them all to complete in any case, so does it matter if they run 
sequentially or in parallel?

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


sheeps be carefull of Python

2007-01-06 Thread GHUM
sometimes Python is more dangerous than documented:

http://news.nationalgeographic.com/news/2006/09/060915-python-ewe.html


Harald

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


Re: Doing date/time + TZ math in python

2007-01-06 Thread [EMAIL PROTECTED]

Joshua J. Kugler wrote:
> I've read docs (datetime, time, pytz, mx.DateTime), googled, and
> experimented.  I still don't know how to accomplish what I want to
> accomplish.
>
> I'm loading up a bunch of date/time data that I then need to do math on to
> compare it to the current date/time.  I can get the current time easily
> enough:
>
> currentTime = datetime.datetime.now(pytz.timezone('America/Anchorage'))
>
> Then, I want to import data/time pairs that are in "%Y-%m-%d %H:%M:%S"
> format.
>
> So, I do:
>
> For each loop, extract time data, blah, blah, then:
> readingTime = datetime.datetime(rYr, rMo, rDay, rHr, rMin, rSec,
> tzinfo=pytz.timezone('America/Anchorage'))
>
> The problem is, how do I create a datetime object and tell it that it's
> America/Anchorage *daylight savings time* instead of whatever the system is
> currently set at?  pytz only has America/Anchorage, and I saw no way to
> tell it explicitly that the timezone is in Daylight instead of Standard
> time (e.g. using AKST vs. AKDT for the time zone).
>
> I'm sure there is a way to do it, and I'm sure it's quite simple, but it
> hasn't jumped out at me yet.  Is there a module that I haven't seen that
> would be better suited for this?
>
> Thanks!
>
> j
>
> --
> Joshua Kugler
> Lead System Admin -- Senior Programmer
> http://www.eeinternet.com
> PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE
>
> --
> Posted via a free Usenet account from http://www.teranews.com

It looks like3 you're 9 hours in this example:
http://docs.python.org/lib/datetime-tzinfo.html, see e.g.
http://www.worldtimezone.com/index12.php

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


Re: still struggling, howto use a list-element as a name ? Sory, hit send button to early

2007-01-06 Thread Stef Mientki
Stef Mientki wrote:
> Jussi Salmela wrote:
>> Bruno Desthuilliers kirjoitti:
>>> Stef Mientki a écrit :
 In the example below, "pin" is an object with a number of properties.
 Now I want
 1- an easy way to create objects that contains a number of these "pin"
 2- an multiple way to access these "pin", i.e.
 device.pin[some_index]
 device.some_logical_name
 ad 1:
 a dictionary (as "pinlist" in the example) seems a very 
 convenient way (from a viewpoint of the device creator).
 As you can see in the "__init__" section this dictionary can easily 
 be transported to the pin-objects.

 ad 2:
 THAT's the problem: how do automate these lines "self.GND = 
 self.pin[0]"

 I'm also in for other solutions.
>>>
>>> I'm afraid I don't understand your design (nor the domain FWIW). 
>> ditto
>>> 
>>>
>>> But the whole thing still looks awfully convulted and kludgy to me, 
>>> and I suspect serious design flaws... Why don't you try and explain  
>>> your real problem, instead of asking how to implement what you 
>>> *think* is the solution ?
>> ditto
> 
> thank you all guys.
> I'm just doing some exercises in Python,
> and therefor I'm trying to rewrite some programs
> I've written in other languages into Python.
> 
> The first program I tried to convert was a MatLab program,
> which could almost be written identical in Python.
> Even with my little experience in Python,
> I can tell you that it could have been written in Python
> in a much better way, but I deliberately did not,
> to show other people who are familiar with MatLab.
> 
> The second example I'm now exercising with,
> is a simulator of (electrical) circuits,
> which I build in Delphi
>   http://oase.uci.kun.nl/~mientki/data_www/pic/jalss/jalss.html
> 
> 
> Sorry, pressed send button too soon, so here it continuous:

In this exercise, I don't attempt to write "beautiful" Python code,
but the first thing is to write a simple "user-interface" for non-Pythians.
I understand that standardization about naming conventions is important,
but the purpose here is to serve the user, who has to write and 
unerstand this,
therefore IORLW is in the domain always written in capitals,
spaces here makes it lot easier to compare the different actions,
in this domain we're used to 2 spaces etc.

  def IORLW(S):  S.Accu_ZERO ( S.Accu | S.lit [S.PC] )
  def ANDLW(S):  S.Accu_ZERO ( S.Accu & S.lit [S.PC] )
  def XORLW(S):  S.Accu_ZERO ( S.Accu ^ S.lit [S.PC] )
  def SUBLW(S):  S.AddLW (~S.Accu + 1 )
  def ADDLW(S):  S.AddLW ( S,Accu )


So to come back to my last question:
this is what the user has to do:
define devices with pins, and the actions what todo when input signals 
changes.

class LED (device):
  pinlist ={
  # pinname type init-value   other-parameters
  1: ('Cathode',   _DIG_IN,   [],   _par2),
  2: ('Anode', _DIG_OUT,  [],   _par33)
  }

  Status = {True:('On'), False:('Off')}

  def execute (self):
old = self.On
self.On = (~self.Cathode.Value & self.Anode.Value) > 0
if self.On <> old : print self.Name, self.Status[self.On]

And now this looks quit  familiar,
although I miss the "with" statement of Delphi to make it even more 
readable ;-)
like this

class LED (device):
  pinlist ={
  # pinname type init-value   other-parameters
  1: ('Cathode',   _DIG_IN,   [],   _par2),
  2: ('Anode', _DIG_OUT,  [],   _par33)
  }

  Status = {True:('On'), False:('Off')}

  def execute (self):
with self:
  old = On
  On = ( ~Cathode.Value & Anode.Value) > 0
  if On <> old : print Name, Status[On]


thanks again for all your wonderfull help,
cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recommended way to force a thread context switch?

2007-01-06 Thread Lloyd Zusman
Duncan Booth <[EMAIL PROTECTED]> writes:

> [ ... ]
>
> If the context isn't switching enough for you then try calling 
> sys.setcheckinterval(n) with varying values of n until you find one which 
> is suitable. Calling it with a lower value of n will increase the frequency 
> that you switch thread contexts, although of course it will also increase 
> the overall runtime for your program.

Thank you very much.  The sys.setcheckinterval function is what I need.
It seems that the original writer of the app had set this interval to a
high value in a part of the code that I overlooked until you mentioned
this right now.


> [ ... ]
>
> Why does it matter whether individual threads are being 'starved'? Surely 
> you want them all to complete in any case, so does it matter if they run 
> sequentially or in parallel?

Because some of the threads perform monitoring and notification that
need to occur in a timely fashion.  Since these threads are doing IO,
they switch context appropriately, but once one of the big
number-crunching threads gets control, it starves out the monitoring
threads, which is not a good thing for my app ... or at least it did
so with the original large checkinterval.


-- 
 Lloyd Zusman
 [EMAIL PROTECTED]
 God bless you.

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


Traceback of hanged process

2007-01-06 Thread Hynek Hanke

Hello,

please, how do I create a pythonic traceback from a python process that
hangs and is not running in an interpreter that I executed manually
or it is but doesn't react on CTRL-C etc? I'm trying to debug a server
implemented in Python, so I need some analog of 'gdb attach' for C. 

Unfortunatelly, googling and reading documentation revealed nothing, so
please excuse if this question is dumb.

Thank you,
Hynek Hanke


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


Re: Traceback of hanged process

2007-01-06 Thread Jonathan Curran
On Saturday 06 January 2007 16:45, Hynek Hanke wrote:
> Hello,
>
> please, how do I create a pythonic traceback from a python process that
> hangs and is not running in an interpreter that I executed manually
> or it is but doesn't react on CTRL-C etc? I'm trying to debug a server
> implemented in Python, so I need some analog of 'gdb attach' for C.
>
> Unfortunatelly, googling and reading documentation revealed nothing, so
> please excuse if this question is dumb.
>
> Thank you,
> Hynek Hanke

Hynek,
It is possible to redirect stderr to a file so that in case of a crash 
or 
fault the errors will be logged to a file. I think the following code would 
do it.

import sys

log_file = open('errors.log', 'w')
sys.stderr = open('errors.log', 'w')



log_file.close()

Hope it helps.

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


Re: Traceback of hanged process

2007-01-06 Thread Jonathan Curran
Heh, I kinda messed up the code there. It should be:

import sys

log_file = open('errors.log', 'w')
sys.stderr = log_file



log_file.close()

As for the Ctrl-C, you can catch that when KeyboardInterrupt exception is 
raised.

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


Re: c# application calling Scipy

2007-01-06 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> Hi,
> 
> Novice here. :)
> 
> I'm building a c# application and I want to call functions in SciPy
> from that application.
> 
> What's the best way to call SciPy methods from a C# program?
> 
> Is there a best Python implementation for this? Ironython? Python for
> .NET? Enthought?

scipy is a package with many C and FORTRAN extensions, so IronPython won't work
unless someone has figured out a magic way to compile them. The Enthought
distribution (disclosure: I work for Enthought) is just a bundling of the normal
python.org distribution of Python with a bunch of packages; it knows nothing
about C#. I know little about Python for .NET beyond its README, but it does
seem to be able to embed CPython into a C# application and with some elbow
grease, that might work for you.

-- 
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


Parallel Python

2007-01-06 Thread parallelpython
Has anybody tried to run parallel python applications?
It appears that if your application is computation-bound using 'thread'
or 'threading' modules will not get you any speedup. That is because
python interpreter uses GIL(Global Interpreter Lock) for internal
bookkeeping. The later allows only one python byte-code instruction to
be executed at a time even if you have a multiprocessor computer.
To overcome this limitation, I've created ppsmp module:
http://www.parallelpython.com
It provides an easy way to run parallel python applications on smp
computers.
I would appreciate any comments/suggestions regarding it.
Thank you!

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


Why less emphasis on private data?

2007-01-06 Thread [EMAIL PROTECTED]
Coming from a C++ / C# background, the lack of emphasis on private data
seems weird to me. I've often found wrapping private data useful to
prevent bugs and enforce error checking..

It appears to me (perhaps wrongly) that Python prefers to leave class
data public.  What is the logic behind that choice?

Thanks any insight.

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


Re: Why less emphasis on private data?

2007-01-06 Thread Thomas Ploch
[EMAIL PROTECTED] schrieb:
> Coming from a C++ / C# background, the lack of emphasis on private data
> seems weird to me. I've often found wrapping private data useful to
> prevent bugs and enforce error checking..
> It appears to me (perhaps wrongly) that Python prefers to leave class
> data public.  What is the logic behind that choice?
> 
> Thanks any insight.
> 

Python doesn't prefer public data in classes. It leaves the choice to
the programmer. You can define your own private instance variables (or
functions) by using a '__' prefix:

example:
class Foo:
def __init__(self, data):
self.__data = data

def get_data(self):
return self.__data


 >>> f = Foo('bar')
 >>> f.__data
 Traceback (most recent call last):
   File "", line 1, in 
 AttributeError: Foo instance has no attribute '__data'
 >>> f.get_data()
 'bar'

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


Re: Why less emphasis on private data?

2007-01-06 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Coming from a C++ / C# background, the lack of emphasis on private data
> seems weird to me. I've often found wrapping private data useful to
> prevent bugs and enforce error checking..
> 
> It appears to me (perhaps wrongly) that Python prefers to leave class
> data public.  What is the logic behind that choice?

Private data is a convention, not a strict enforcement, for both Java 
and C++.

Depending on your C++ compiler, a simple

#define private public

will give you access to all data you want. Besides the fact that casting 
to a void* pointer and just accessing the private parts isn't rocket 
science.

The same applies to java, for whatever reasons (I presume 
serialization), you can access private fields via reflection.

In python, private members are usually declared using a single or double 
underscore. And the basic idea is: "if you tamper with this, you've been 
warned". Which is the way coding between consenting adults should be.

To be honest: I've stumbled over more cases of unescessary hoops to jump 
through due to private declarations than bugs caused of me exploiting 
things I've been told by the compiler not to tamper with it.

Summary: not important, forget about it, enjoy python!

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


Re: (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-06 Thread Martin Miller
Carl Banks wrote:

> Martin Miller wrote:
> > ### non-redundant example ###
> > import sys
> >
> > class Pin:
> > def __init__(self, name, namespace=None):
> > self.name = name
> > if namespace == None:
> > # default to caller's globals
> > namespace = sys._getframe(1).f_globals
> > namespace[name] = self
> >
> > Pin('aap')  # create a Pin object named 'aap'
> > Pin('aap2') # create a Pin object named 'aap2'
> > print aap.name
> > print aap2.name
>
> The problem with this is that it only works for global namespaces,
> while failing silently and subtly if used in a local namespace:

Oh, contrair. It would work fine with local namespaces simply by
overriding the default value of the optional 'namepace' parameter (see
below).

> def fun():
> Pin('aap')
> aap1 = aap
> fun2()
> aap2 = aap
> print aap1 is aap2
>
> def fun2():
> Pin('aap')
>
> If it's your deliberate intention to do it with the global namespace,
> you might as well just use globals() and do it explicitly, rather than
> mucking around with Python frame internals.  (And it doesn't make the
> class unusable for more straightforward uses.)

You could be more explicit by just passing 'globals()' as a second
parameter to the __init__ constructor (which is unnecessary, since
that's effectively the default).

It's not clear to me how the example provided shows the technique
"failing silently and subtly if used in a local namespace" because what
happens is exactly what I would expect if the constructor is called
twice with the same string and defaulted namespace -- namely create
another object and make the existing name refer to it. If one didn't
want the call to Pin in fun2 to do this, just change fun2 to this:

def fun2():
Pin('aap', locals())

This way the "print aap1 is aap2" statement in fun() would output
"true" since the nested call to Pin would now (explicitly) cause the
name of the new object to be put into fun2's local namespace leaving
the global one created by the call in fun() alone.

Obviously, this was not an objection I anticipated. An important one I
would think is the fact that the current documentation says that
f_globals is a special *read-only* attribute of a frame object implying
that it shouldn't be changed (even though doing so 'works' as my
example illustrates).

I think other valid arguments against this practice might include
whether it's an example of good OOP, or a good programming practice at
all, since it involves possibly subtle side-effects, the use of global
variables, and/or is 'unpythonic'.

Certainly the approach is not without caveats. Despite them, I believe
it can be useful in some contexts, as long as what is going on is
clearly understood. The point of my reply to the OP was mainly just to
illustrate the power and flexibility of Python to the newbie. I guess
to that I should have also added that it gives you "enough rope to
shoot yourself" as Allen Holub said regarding C++.

Cheers,
-Martin

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


Re: Why less emphasis on private data?

2007-01-06 Thread skip

time> Coming from a C++ / C# background, the lack of emphasis on private
time> data seems weird to me.

Python doesn't try to protect you from the authors of the code you use.  You
should be intelligent enough to use it wisely.  On the flip side, the lack
of truly private data and methods means the original author of a piece of
code doesn't need to anticipate all future uses to which the code will be
put.  Here are a couple items along the lines of "we're all adults here".

http://spyced.blogspot.com/2005/06/anders-heljsberg-doesnt-grok-python.html
http://www.mail-archive.com/tutor@python.org/msg17806.html

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


Re: Why less emphasis on private data?

2007-01-06 Thread BJörn Lindqvist
On 6 Jan 2007 16:07:05 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Coming from a C++ / C# background, the lack of emphasis on private data
> seems weird to me. I've often found wrapping private data useful to
> prevent bugs and enforce error checking..
>
> It appears to me (perhaps wrongly) that Python prefers to leave class
> data public.  What is the logic behind that choice?

Google for "python for consenting adults"

Or ask yourself the opposite question. Why does C++ and C# prefer more
private data? It is given that emphasizing private data
(encapsulation) leads to more internal complexity and more lines of
code because you have to write getters and setters and stuff. With
that in mind, why do you think that data encapsulation makes code less
error prone? Can you prove it? Or do you have anecdotal evidence of
where data encapsulation saved your ass?

IMHO, that data hiding is good, is one of those ideas that have been
repeated so much that virtually everyone thinks it is true.  But
Python proves that it isn't necessarily so.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why less emphasis on private data?

2007-01-06 Thread Stefan Schwarzer
On 2007-01-07 01:54, BJörn Lindqvist wrote:
> Google for "python for consenting adults"
>
> Or ask yourself the opposite question. Why does C++ and C# prefer more
> private data? It is given that emphasizing private data
> (encapsulation) leads to more internal complexity and more lines of
> code because you have to write getters and setters and stuff. With
> that in mind, why do you think that data encapsulation makes code less
> error prone? Can you prove it? Or do you have anecdotal evidence of
> where data encapsulation saved your ass?
>
> IMHO, that data hiding is good, is one of those ideas that have been
> repeated so much that virtually everyone thinks it is true.  But
> Python proves that it isn't necessarily so.

I think attributes (callable or not) which relate to the
abstraction of the class should be "public" (special methods
or without leading underscore). Attributes that are there for a
specific implementation of the abstraction should be "private".

The internal implementation of a class is more-often changed
in incompatible ways than the abstraction, so distiguishing
between a public and a private interface will probably save
you from reworking the clients of a class if you prefer the
public interface. It will also make the client code easier to
understand.

Admittedly, there are special cases where you want to access
private attributes, e. g. debugging; that's ok.

In summary, the distinction between public and non-public
attributes IMHO makes sense, but I don't think that the
distinction should be enforced by the language as in C++
or Java.

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


Re: Why less emphasis on private data?

2007-01-06 Thread Paul Rubin
"BJörn Lindqvist" <[EMAIL PROTECTED]> writes:
> It is given that emphasizing private data (encapsulation) leads to
> more internal complexity and more lines of code because you have to
> write getters and setters and stuff.

You can have public variables in Java if you choose to.  Writing
private variables with public setters and getters is just a style choice.

> Or do you have anecdotal evidence of where data encapsulation saved
> your ass?

There are certainly applications that can't live without it, like
browser applets.

As for it saving my ass, there's no way to know, it's like asking
whether garbage collection has saved my ass.  Yes I've had plenty of
pointer related bugs in C programs that don't happen in GC'd
languages, so GC in that sense saves my ass all the time.  I've also
had bugs in Python programs that would have been prevented by better
use of encapsulation (including in the stdlib).  Python certainly
makes you spend more of your attention worrying about possible
attribute name collisions between classes and their superclasses.  And
Python's name mangling scheme is leaky and bug-prone if you ever
re-use class names.  Overall, I think Python would gain from having
better support for encapsulation and C++-like casting between class
instances.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: clarification on open file modes

2007-01-06 Thread Stefan Schwarzer
On 2007-01-05 03:46, tubby wrote:
> Is this the safest, most portable way to open files on any platform:
>
> fp = open(file_name, 'rb')
> fp.close()
>
> I understand that doing the following on Windows to a binary file (a
> jpeg or exe files for example) can cause file corruption, is that correct?
>
> fp = open(file_name, 'r')
> fp.close()

Rule of thumb: If the file is a text file (usually has a concept
of "text lines"), read and write it in text mode (without "b" in
the mode argument). So line endings will be converted, so that
your Python code can process the text data identically on all
platforms. On the other hand, if you process binary files (as you
mention, for example jpg or exe files), read and write them in
binary mode, so the data won't be corrupted.

> How can a simple open in read mode corrupt data???

You won't corrupt the data in the file, but you will kind of
corrupt the data that arrives in your program.

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


AES256 in PyCrypto

2007-01-06 Thread mirandacascade
Attempting to determine whether the PyCrypto package has the capability
to perform AES256 encryption.  I received the following C# snippet:

CryptoProvider provider = new CryptoProvider();
Encrypted_Type password = new Encrypted_Type();
password.EncryptedData = new EncryptedDataType();
password.EncryptedData.EncryptionMethod = new EncryptionMethodType();
password.EncryptedData.EncryptionMethod.Algorithm = "AES256-cbc";

and I was told that it was the setup code for code that later on
performs AES256 encryption.  I'm assuming that setting the Algorithm
property is what informs the system as to the type of encryption to
perform.  I included the above snippet as a reference point, because
I'm attempting to understand how to do something equivalent in Python.

Would the following Python code perform AES256 encryption on plainText
from Crypto.Cipher  import AES
x = AES.new(a, AES.MODE_CBC, iv)
x.encrypt(plainText)

assuming:
a = the key value
iv = an initialization vector
?

If the above Python code does not perform AES256 encryption:
a) is there functionality within PyCrypto that allows one to perform
AES256 encryption?
b) if such functionality does not exist in PyCrypto, does it exist in
some other Python package?

Operating System: Windows XP
Vsn of Python: 2.4

Thank you.

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


How to invoke parent's method?

2007-01-06 Thread many_years_after
Hi, pythoners:

 My wxPython program includes  a panel whose parent is a frame. The
panel has a button. When I click the button , I want to let the frame
destroy. How to implement it? Could the panel invoke the frame's
method?
Thanks.

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


Re: still struggling, howto use a list-element as a name ?

2007-01-06 Thread rzed
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote 
in news:[EMAIL PROTECTED]:

> rzed a écrit :
> (snip)
>> for k in self.pin.keys():
>> self.__dict__[self.pin[k]['Name']] = self.pin[k]
> 
> for pin self.pin.values():
>self.__dict__[pin['name']] = pin
> 

D'oh! Of course! Thank you.

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

How to write code to get focuse the application which is open from server

2007-01-06 Thread vinthan
hi,
I am new to python. I have to write test cases in python. An
application is open in the desk top ( application writen in .Net) I
have to write code to get focuse the application and click on the link
which in the one side  and it will load the map on the other and I have
to check map is loaded. Any one tell me how do I use Dispatch or any
other method to write a code.

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


Re: Just Getting Started with Python on MS XP Pro

2007-01-06 Thread W. Watson
Thomas Ploch wrote:
> W. Watson schrieb:
>> The wiki site lead to a link to download pythonwin, but the download is 
>> broken. Googling invariably leads back to that link. I found 
>> , which has 
>> two files listed: oadist.exe and win32dbg.exe. Do I need both or is just the 
>> latter one?
> 
> 
> A google query 'pythonwin' directly brings me here:
> 
> https://sourceforge.net/projects/pywin32/
> 
> I think this is the place to go
> 
> Thomas
> 
> 
That gets me the python program (pywin), which I got from a URL in a post 
above (python-win.msi). I guess these are the same or at least just the 
interpreter, and do not provide the IDE-debugger. I can't get pythonwin, the 
debugger and IDE. The link was broken last night when I tried it. Well, let 
me try now. Nope, it still reports "Error 404: File Not Found"




  Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA)
  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
   Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

  ""I do not fear death. I had been dead for billions
and billions of years before I was born, and had
not suffered the slightest inconvenience from it."
-- Mark Twain (a nod to evolution)
-- 
 Web Page: 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Closing Problem in 2.3 and 2.4, Not in 2.5

2007-01-06 Thread John Machin
Martin v. Löwis wrote:
> Carroll, Barry schrieb:
> > What I want to know is:
> >
> > * has anyone else encountered a problem like this, * how was the
> > problem corrected, * can the fix be retro-fitted to 2.5 and 2.4?
>
> From your description, I suspect an error in your code. Your description
> indicates that you don't expect to have more than five files open
> simultaneously. Yet, the error message "Too many open files" occurs when
> you open many more files (in the order of hundreds of files).
>
> It is very unlikely that there is a bug in Python where it would fail to
> close a file when .close() is explicitly invoked on it (as your
> description suggests that you do), so if you get that error message, it
> can only mean that you fail to close some files.

I don't understand:  the OP's description suggests nothing of the sort
to me. What he said was:
"""
In this way, a tree of Parser instances is created, each with a single
open file object.  (BTW, recursive and circular references are not
allowed.)  When each Parser instance comes to the end of its table, the
instance is explicitly destroyed, presumably destroying any objects it
holds, AND closing its open file.
"""
which I interpret as: he is doing del parser_instance, and *presuming*
(incorrectly) that attributes of parser_instance (including an open
file object) are magically whisked away instantly, instead of
later/maybe. He later says he explicitly closed the files, which fixed
what he alleges (incorrectly) to be a bug.

To the OP:
(1) The del statement doesn't "destroy" anything. It unbinds the name
from the object in the current namespace, and decrements the object's
reference count. Only if the reference count is then zero will the
janitor be called in.
(2) Check the reference count on the parser_instance just before you
del it. You could be retaining a reference somewhere.
(3) Explicitly close all non-lightweight objects like files (even
read-only ones) and sockets rather than hoping they will go away.

HTH,
John

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