Re: IDE, widget library

2005-09-16 Thread Max M
[EMAIL PROTECTED] wrote:
> I like to use Eclipse with the Pydev plugin which is quite good and is
> cross-platform.


I have used those on Windows for about 3 weeks now, and I must say that 
the switch has been allmost completely painless.

I have only good things to say about it.

I can see that my Java process takes up about 80 MBytes, so it is a bit 
of a hog. But who cares... isn't 1 GB getting to be the standard these days?

I have a 1 GHz machine, and the IDE is plenty fast. It has a few 
idiosyncrasies that needs to be learned, but I guess that Emacs has more ...


Good job on pydev!

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No newline using printf

2005-09-16 Thread Sybren Stuvel
Johnny Lee enlightened us with:
> Why the prompt followed after the output? Maybe it's not as
> expected.

Because it did what you ask of it: write "012" to stdout, and nothing
else. Hence, no newline at the end, hence the prompt is on the same
line.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read stdout/stderr without blocking

2005-09-16 Thread Adriaan Renting
Great reply,

I had just mixed Pexpect and subProcess code until I'd got something that 
worked, you can actually explain my code better a I can myself. I find it quite 
cumbersome to read stdout/strerr separately, and to be able to write to stdin 
in reaction to either of them, but at least on Linux you can get it to work. My 
NON_BLOCKing command might be unnecesary, I'll try without it.

The OP seemed interested on how to do this on Windows, but I've yet to see an 
answer on that one I think.
 
Thank you for the reply.

Adriaan Renting
 
|>>>Donn Cave <[EMAIL PROTECTED]> 09/15/05 6:19 pm >>> 
|In article <[EMAIL PROTECTED]>, 
|Peter Hansen <[EMAIL PROTECTED]> wrote: 
| 
|>Jacek Pop³awski wrote: 
|>>Grant Edwards wrote: 
|>> 
|>>>On 2005-09-12, Jacek Pop?awski <[EMAIL PROTECTED]> wrote: 
|>>> 
|>   ready = select.select(tocheck, [], [], 0.25) ##continues 
|>after 0.25s 
|>   for file in ready[0]: 
|>   try: 
|>   text = os.read(file, 1024) 
| 
| 
|How do you know here, that you should read 1024 characters? 
|What will happen when output is shorter? 
|>>> 
|>>>It will return however much data is available. 
|>> 
|>>My tests showed, that it will block. 
|> 
|>Not if you use non-blocking sockets, as I believe you are expected to 
|>when using select(). 
| 
|On the contrary, you need non-blocking sockets only if 
|you don't use select.  select waits until a read [write] 
|would not block - it's like "if dict.has_key(x):" instead of 
|"try:  val = dict[x] ; except KeyError:".  I suppose you 
|knew that, but have read some obscure line of reasoning 
|that makes non-blocking out to be necessary anyway. 
|Who knows, but it certainly isn't in this case. 
| 
|I don't recall the beginning of this thread, so I'm not sure 
|if this is the usual wretched exercise of trying to make this 
|work on both UNIX and Windows, but there are strong signs 
|of the usual confusion over os.read (a.k.a. posix.read), and 
|file object read.  Let's hopefully forget about Windows for 
|the moment. 
| 
|The above program looks fine to me, but it will not work 
|reliably if file object read() is substituted for os.read(). 
|In this case, C library buffering will read more than 1024 
|bytes if it can, and then that data will not be visible to 
|select(), so there's no guarantee it will return in a timely 
|manner even though the next read() would return right 
|away.   Reading one byte at a time won't resolve this problem, 
|obviously it will only make it worse.   The only reason to 
|read one byte at a time is for data-terminated read semantics, 
|specifically readline(), in an unbuffered file.  That's what 
|happens -- at the system call level, where it's expensive -- 
|when you turn off stdio buffering and then call readline(). 
| 
|In the C vs. Python example,  read() is os.read(), and file 
|object read() is fread();  so of course, C read() works 
|where file object read() doesn't. 
| 
|Use select, and os.read (and UNIX) and you can avoid blocking 
|on a pipe.  That's essential if as I am reading it there are supposed 
|to be two separate pipes from the same process, since if one is 
|allowed to fill up, that process will block, causing a deadlock if 
|the reading process blocks on the other pipe. 
| 
|Hope I'm not missing anything here. I just follow this group 
|to answer this question over and over, so after a while it 
|gets sort of automatic. 
| 
|  Donn Cave, [EMAIL PROTECTED] 

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


Re: re and escape character

2005-09-16 Thread Sinan Nalkaya
Thomas Guettler wrote:

>Am Thu, 15 Sep 2005 14:36:38 +0300 schrieb Sinan Nalkaya:
>
>  
>
>>i re-format incoming messages like this,
>>command = re.findall("^\002(.{2})\|.*\003$", response)[0]
>>it works well but when response comes with escape characters , my 
>>command variable crashes,
>>i cannot parse if response variable is like ,
>>response = '\002AB|TIasdasdasd
>>asdasdasd
>>xzczxc
>>qwewer
>>werwer|\003'
>>
>>ps:there must be \002 at the start and \003 at the end.
>>thanks.
>>
>>
>
>Hi,
>
>I don't know what you mean with "escape characters".
>The dot does not match a newline. You  have to use the
>re.DOTALL option if you want this.
>
> HTH,
>   Thomas
>
>  
>
thats exactly what i want, how can i use DOTALL, by doing re.compile ?
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No newline using printf

2005-09-16 Thread Samuel
Thanks for your help, Guys. This works of course.

-Samuel

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


Re: Removing duplicates from a list

2005-09-16 Thread martijn
Thanks for all the information.
And now I understand the timeit module ;)

GC-Martijn

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


Re: IDE, widget library

2005-09-16 Thread Adriaan Renting
I find developing in Eric3 + QtDesigner to be very quick and easy. It does 
everything you want and much more,
only it uses Qt3. The new Qt4 has an official GPL version for Windows, and 
there are GPL ports versions of Qt3 as pointed out by other posters.
I am realy impressed by the elegance of Qt, and because it's all OO C++ PyQt 
mixes easily with Python.
I think your dismissal of Qt is to quick, I suggest you at least take it into 
consideration.
eric3 is a nice IDE for any kind of Python dev, but it realy shines when using 
it to develop Qt apps.
If Qt realy isn't an option I would go with wxWidgets/windows. But basically 
from my POV all the toolkits are available as GPL, so if you need it for free, 
the licencing for all is basically the same.
 
>>>Thomas Jollans <[EMAIL PROTECTED]> 09/15/05 9:39 pm >>> 
I guess questions like this come all the time here ... well: 
 
I a looking for a python IDE for gnu/linux that : 
- has decent sytax highlighting (based on scintilla would be neat) 
- has basic name completition, at least for system-wide modules 
- has an integrated debugger 
- is open source, or at least free of charge 
 
an integrated GUI designer would of course be cool, but cannot be 
counted as a requirement. 
 
With that I come to the second question: 
What cross-platform GUI libraries are there ? cross-platform meaning 
functional and free on (at least) X11 and Win32 
PyQT obviously doesn't count because qt3 is not free on windows. 
Tk is ugly. (how well) is Tile supported with python ? 
does PyGTK/Glade work on win32 ? 
-- 
http://mail.python.org/mailman/listinfo/python-list 

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


Re: How to clear screen in Python interactive shell mode?

2005-09-16 Thread Laszlo Zsolt Nagy
A. L. wrote:

>In Python interactive mode, is there some function acting like 'clear'
>command in bash?  Could somebody here give some advice?
>  
>
Under Linux/UNIX system (on x86 at least) you can use the CTRL+L 
combination to clear the screen.
I do not now similar for Windows and MACs.

   Les

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


Lines of Strings

2005-09-16 Thread Reem Mohammed
Hi

Suppose we have data file like this one (Consider all lines as strings )

1 2 3 3 4 4 4 4 5 6
2 2 2 5 5 5 6
3 2 1 1 1 3 3 3 4 6

I would like to remove line if its belong to another one, and will be able 
to do this if longer line come after a short one.

Thanks

_
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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


Tear off menus

2005-09-16 Thread keithlackey








Ok I got a really great system tray script working… 

 

It’s based off the pysystray script…

which is based on the SysTrayIcon script…

which is just based on the win32gui_menu script…

Point is that all of us are basing are scripts on someone
else’s work…

 

Anyways, my script adds some of the functionality that was
lost through all the conversions… like I added separators, checkboxes,
radio buttons, and can use bmp back into there too… I also added some
functions to restart the menu so that you can have the menus change when you
click on an action…

 

Ok on to the real question… 

I want to be able to rip off a menu or a submenu from this
menu system… I don’t know if anyone has used Maya… but they
have a really great feature where you can rip off any drop down menu…
really great if you have to do a lot of function from set of menus and
don’t want to keep pulling the drop down menu down.

 

I guess I could create a separate TKinter window  for this, and recreate all the menu
options as buttons… but how do I keep this menu or window above other
windows… I want use this menu while I’m working in other software
packages so the window needs to be on top of the rest. 

 

I would like to try and make a new windows popup and make it
so that it cant be hidden: kinda like what this guy does on accident
here…

http://www.uselesspython.com/download.php?script_id=27

but I cant figure out what he is doing that is making his
menu not disappear when you click outside his menu.

 

 

Cheers…






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

Re: Looking for a database. Sugestions?

2005-09-16 Thread Gerhard Häring
Ed Hotchkiss wrote:
> On 15 Sep 2005 21:31:27 -0700, *gsteff* wrote:
> 
> SQLite rocks, its definitely the way to go.  Its binary is around 250K,
> but it supports more of the SQL standard than MySQL.  It CAN be thread
> safe, but you have to compile it with a threadsafe macro enabled. [...]
> 
> Is this for running an SQL database, then using a separate python
> module to access the database?

SQLite being an embedded database, if you use it via pysqlite 
(http://pysqlite.org/), it is part of your Python application, i. e. 
there is no separate SQL server and client, the SQL engine is just part 
of your application and the data is located in one local file.

pysqlite itself is a little larger than SQLite, of course, for example 
the statically linked binary extension module on Windows is 331.776 
bytes in the latest version:

C:\>dir c:\Python24\lib\site-packages\pysqlite2
  Datenträger in Laufwerk C: ist Lokaler Datenträger
  Volumeseriennummer: 8C7F-873C

  Verzeichnis von c:\Python24\lib\site-packages\pysqlite2

26.08.2005  11:00  .
26.08.2005  11:00  ..
16.05.2005  21:11 2.525 dbapi2.py
12.09.2005  10:49 2.425 dbapi2.pyc
12.09.2005  10:49 2.425 dbapi2.pyo
26.08.2005  11:00  test
12.09.2005  00:56   331.776 _sqlite.pyd
16.05.2005  21:11 1.016 __init__.py
12.09.2005  10:49   131 __init__.pyc
12.09.2005  10:49   131 __init__.pyo
7 Datei(en)340.429 Bytes


-- Gerhard


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


Re: help for conversion of NUMARRAY to PIL object

2005-09-16 Thread A. L.
Sorry, I make the mistakes.  I have known how to use to/fromstring
method to interface between  PIL and Numarray.
And your code does work.

Another question. Just like the code you provide, is it possible to
directly load image data from PIL to Numarray array without use of
to/fromstring method? 

Thank you very much for your kindly help.

A.L.

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


Re: How to clear screen in Python interactive shell mode?

2005-09-16 Thread A. L.
Thank you very much. I have tested it under Cygwin, and that works. But
it fails under Windows Python Shell Mode.

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


Re: Lines of Strings

2005-09-16 Thread bruno modulix
Reem Mohammed wrote:
> Hi
> 
> Suppose we have data file like this one (Consider all lines as strings )
> 
> 1 2 3 3 4 4 4 4 5 6
> 2 2 2 5 5 5 6
> 3 2 1 1 1 3 3 3 4 6
> 
> I would like to remove line if its belong to another one, and will be
> able to do this if longer line come after a short one.

That's fine. Now try and do it, and ask for help when you're in trouble.

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


Re: 2.3 -> 2.4: long int too large to convert to int

2005-09-16 Thread Bengt Richter
On Fri, 16 Sep 2005 01:25:30 -, Grant Edwards <[EMAIL PROTECTED]> wrote:

>On 2005-09-15, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
>>>I give up, how do I make this not fail under 2.4?
>>> 
>>> fcntl.ioctl(self.dev.fileno(),0xc0047a80,struct.pack("HBB",0x1c,0x00,0x00))
>>>
>>> I get an OverflowError: long int too large to convert to int
>>>
>>> ioctl() is expecting a 32-bit integer value, and 0xc0047a80 has
>>> the high-order bit set.  I'm assuming Python thinks it's a
>>> signed value.  How do I tell Python that 0xc0047a80 is an
>>> unsigned 32-bit value?
>>
>> In 2.3 and before, you get this:
> 0xc0047a80
>> -1073448320
>
>I don't particular care how Python prints the value -- I just
>want that value passed to the function I'm calling.
>
I do care, dang it. IMIFO (in my increasingly frustrated opinion ;-)
one ought to be able to write literals for negative integers.
A simple variation on 0x... coul be 0h... where what follows 0h is
base-16-complement, which turns out to be 0hfc0047a80 for the negative
number you want, and would be 0h0c0047a80 if you wanted the positive number
with the same least significant bits.

>> In 2.4, positive hex literals are treated as positive numbers, and that is 
>> your problem: your literal is greater than the largest int and hence gets 
>> stored as long int.
>
>I knew that, I just couldn't come up with a good way to fix it.
IMO you shouldn't have to fight it.
>
>> I would try -1073448320 as the arg.
>
>That should work, but it's kind of lame (no offense).
Yes, it is lame ;-)

see more on the notation (of which hex is only the particular base-16 case)

http://groups.google.co.uk/group/comp.lang.python/msg/2c411ca9251774dc

(It doesn't show in the examples, but unfortunately the code has a bug that I 
fixed
in a later post,

http://groups.google.co.uk/group/comp.lang.python/msg/359927a23eb15b3e


the encoding of -1073448320 would be

 >>> from ut.basecompl import basecompl as bc, bcdecode as bcd
 >>> '0h'+bc(-1073448320, 16)
 '0hfc0047a80'

or you could use other bases with 0b. prefix:

 >>> '0b2.'+bc(-1073448320, 2)
 '0b2.100010000101000'
 >>> '0b8.'+bc(-1073448320, 8)
 '0b8.70001075200'
 >>> '0b16.'+bc(-1073448320, 16)
 '0b16.fc0047a80'
 >>> '0b10.'+bc(-1073448320, 10)
 '0b10.98926551680'
   -1073448320  note the correspondence to previous line for base 10 ;-)

 >>> bcd('0101',2)
 5
 >>> bcd('1101',2)
 -3

repeating the "sign digit" doesn't change the decoded value:

 >>> bcd('1101',2)
 -3
 >>> bcd('0101',2)
 5

irrespective of the base:

 >>> bcd('98926551680', 10)
 -1073448320L
 >>> bcd('8926551680', 10)
 -1073448320L
 >>> bcd('fc0047a80', 16)
 -1073448320L
 >>> bcd('fffc0047a80', 16)
 -1073448320L

>
>ioctl values are always, always written in hex.  A block of
>ioctl values is generally assigned to a particular driver such
>that the high order N (is it 4 oe 5?) hex digits are unique to
>that driver.  Writing the value in decimal is going to
>completely confuse anybody looking at the code.
>
>I rather like the other suggestion of writing a function that
>accepts 0x and returns the appropriate integer value.
>
Sure, but there's no reason we shouldn't be allowed to specify a constant
as a literal IMO.

>Another poster suggested a solution using struct.  Here's my
>solution (which assume python integers are represented in 2's
>compliment binary):
>
>def ioctlValue(i):
>if i & 0x8000:
>i = -((i^0x)+1)
>return i
>
Do you think it's PEP-able, or should I quit being obnoxious ;-)

I think str.mod format like %x except %.b would make it
easy to write '0h%08b.16' % a_signed_integer and get something both
readable and inputtable as a constant. (0h. would be short
for 0b16.) BTW, %b (or %B for uppercase) could default to base 16.
The ouput would only be as wide as necessary, with the leading digit
guaranteed 0 or f (which is 0 or  in the general case).


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


Re: read stdout/stderr without blocking

2005-09-16 Thread Jacek Popławski
Donn Cave wrote:
> I don't recall the beginning of this thread, so I'm not sure
> if this is the usual wretched exercise of trying to make this
> work on both UNIX and Windows, 

It is used in "test framework" which runs on Linux, Windows (Cygwin) and 
QNX. I can't forget about Windows.
-- 
http://mail.python.org/mailman/listinfo/python-list


wxPython, using sizers.

2005-09-16 Thread Iain King
I'm making a program to view log files.  The main display is a multi
column listbox.  I want to add combobox filters above the listbox
headers.  The filters contain each unique instance in the list column
below it, and if any filter has text selected in it then the listbox
will only display rows in which the relevant column contains that text
(MS Excel's Autofilter, basically).  I need to get the comboboxes to be
positioned directly above the column headers, and be the same width,
and I've had no luck.  I tried with a horizontal boxsizer, but it
resets the widths automatically (as I imagine it is supposed to).  Any
tips?

Iain

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


/usr/lib/python2.3/site-packages/_mysql.so: undefined symbol: mysql_rollback

2005-09-16 Thread thomas Armstrong
Hello.

Python 2.3.4 (#1, Feb  2 2005, 12:11:53)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
MySQL-python-1.2.0

I'm trying to execute this script:
--
#!/usr/bin/python 
import MySQLdb
conn = MySQLdb.connect (host = "localhost", user = "root", passwd =
"", db = "test")
cursor = conn.cursor ()
cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
print "server version:", row0
cursor.close ()
conn.close ()
--

But I get this error message:

[ ]# python test.py
Traceback (most recent call last):
  File "test.py", line 2, in ?
import MySQLdb
  File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line 27, in ?
import _mysql
ImportError: /usr/lib/python2.3/site-packages/_mysql.so: undefined
symbol: mysql_rollback


What am I doing wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


MemoryError in httplib

2005-09-16 Thread ZhangYue张岳
The problem from

http://www.thescripts.com/forum/thread25490.html

can be repeated here with python2.4.1 on WinXP. 

Test sample: sending about 5MB http data. 

It appears to be caused by line 545, httplib.py. 

chunk = self.fp.read(amt)

It seems that reading too much from that sock causes
leak. Thus trying to edit the line making it

chunk = self.fp.read(min(amt,5))

the problem will be solved. //Not sure whether it was
sock error for using pure sock for http won't cause
this problem. 

Best regards. 

ZhangYue张岳
[EMAIL PROTECTED]
2005-09-16
-- 
http://mail.python.org/mailman/listinfo/python-list

Rendering HTML

2005-09-16 Thread Harlin Seritt
I am looking for a module that will render html to console but
formatted much like one might see with Lynx. Is there such a module
already out there for this?

Thanks,

Harlin

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Jerzy Karczmarczuk
Terry Reedy cites:
> "Mike Meyer" who fights with:
>>>While that's true, one of the reasons Guido has historically rejected
>>>this optimization is because there are plenty of recursive algorithms
>>>not amenable to tail-call optimization.

>>Since the BDFL is *not* known for doing even mildly silly things when
>>it comes to Python's design and implementation, I suspect there's more
>>to the story than that.
> 
> 
> Yes.  The reason Guido rejected tail-call optimization the last time it was 
> suggested is because it is semanticly incorrect for Python.  Python's name 
> bindings are dynamic, not static, and the optimization (and the discussion 
> here) assumes static bindings.  In Python, runtime recursiveness (defined 
> as a function *object* calling itself directly or indirectly), is 
> dynamically determined.  You cannot tell whether a function object will act 
> recursive or not just by looking at its code body.  

Hmm.

The question is to optimize the TAIL CALLS, not just the recursivity.
Mind you, Scheme has also a dynamical name binding, yet it does this
optimization. This is for me more a question of policy than of
semantics [with the *true* meaning of the word "semantics"].

The situation is a bit different in, say, Prolog, where the tail calls
cannot - typically - be optimized for *serious* reasons, the indeterminism.
Prolog has to keep/stack the choice points in recursive generators.
In Python not so.

Hm.
Now I began to scratch my head. I will have to translate some Prolog
algorithms to Python generators...

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Steven D'Aprano
On Thu, 15 Sep 2005 18:07:28 +0100, phil hunt wrote:

> On Thu, 15 Sep 2005 21:56:06 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>>
>>Are you saying that the recursion done by "serious" languages is a fake?
>>That it is actually implemented behind the scenes by iteration?
>>
>>It seems to me that if recursion and iteration produce "the exact same
>>machine code", the argument for preferring recursion over iteration is
>>gutted.
> 
> It seems to me that if a high level language and assembler produce
> "the exact same machine code", the argument for preferring high
> level languages is gutted.
> 
> Do you see the fallacy in your statement now?

Ah, yes, you got me on that one.

But there is a difference: writing assembly is *hard*, which is why we
prefer not to do it. Are you suggesting that functional programming is
significantly easier to do than declarative?

-- 
Steven.

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


Is There the Equivalent of FLT_EPS of C In Python?

2005-09-16 Thread A. L.
I am writing the code involved in numerical computation. When I need a
float epsilon similar to FLT_EPS in C, eps in matlab, I fail to find
the equivalent in python. Could somebody here can give me some advices?

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Michael Sparks
Paddy wrote:

> A work colleague circulated this interesting article about reducing
> software bugs by orders of magnitude:

The problem that these sorts of approaches don't address is the simple
fact that simple creating a formal spec and implementing it, even if
you manage to create a way of automating the test suite from the spec
*doesn't guarantee that it will do the right thing*.

The hidden assumption is that the formal spec will be correct. If it
isn't then you have the same problems as before. Sure you might be able
to reduce the number of bugs, but you can be certain of one thing,
given:
   * Customer has a need
   * Customer communicates this to Supplier
   * Supplier translates needs to spec
   * Supplier translates spec back to english
   * Customer agrees spec

This involves human communication, and misunderstandings happen all
the time then.  Sure it can be easier to detect errors at this stage,
but you can't guarantee that it will do so. You can almost guarantee
though that people will misunderstand each other from time to time.
A purely engineering approach to dealing with correctness cannot
guarantee that misunderstandings won't occur. Those misunderstandings
translate into bugs, no matter what approach you use.

It's why I find XP and agile approaches interesting, they're often more
than just engineering.

As a result I'd say that the subject "Software bugs aren't inevitable"
is not true.

Regards,


Michael.
-- 
[EMAIL PROTECTED], http://kamaelia.sourceforge.net/
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This message (and any attachments) may contain personal views
which are not the views of the BBC unless specifically stated.

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


Re: How to clear screen in Python interactive shell mode?

2005-09-16 Thread Steven D'Aprano
On Thu, 15 Sep 2005 21:18:33 -0700, A. L. wrote:

> In Python interactive mode, is there some function acting like 'clear'
> command in bash?  Could somebody here give some advice?
> 
> Thanks in advance.


Something like this may help:

def clearscreen(numlines=100):
"""Clear the console.

numlines is an optional argument used only as a fall-back.
"""
import os
if os.name == "posix":
# Unix/Linux/MacOS/BSD/etc
os.system('clear')
elif os.name in ("nt", "dos", "ce"):
# DOS/Windows
os.system('CLS')
else:
# Fallback for other operating systems.
print '\n' * numlines


-- 
Steven.

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


Re: Creating Pie Chart from Python

2005-09-16 Thread paron
If you can wait a week or two, you can use svg and it will work for  IE
or Firefox.

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


RE: [Python-Dev] python optimization

2005-09-16 Thread Neal Becker
One possible way to improve the situation is, that if we really believe
python cannot easily support such optimizations because the code is too
"dynamic", is to allow manual annotation of functions.  For example, gcc
has allowed such annotations using __attribute__ for quite a while.  This
would allow the programmer to specify that a variable is constant, or that
a function is pure (having no side effects).

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


Re: Self reordering list in Python

2005-09-16 Thread Laszlo Zsolt Nagy

>I wonder why you don't use a dictionary? The only time I used a
>move-front algorithm I stored algorithms and had to evaluate a
>condition to select the correct algo. That means no constant search key
>was available for accessing the correct one. In case of an image list I
>would implement a self-ordering list if I have to do some pattern
>recognition in order to select the correct image. Holding a reference
>as a search key a Python hash-table will always have a better average
>time complexity no matter which language is used to implement
>move-front. 
>
You are right in that holding a reference will have a better time 
complexity. But holding a reference makes it impossible to free the 
object. :-) As I said, my list has a maximum length. I just can't store 
any number of images in memory. I need to keep only the most frequently 
used ones. I do not know which ones will be used the most frequently, 
this is why I need a self reordering list. Accessing an element makes it 
"more imporant" than the others. I already implemented this in Python 
and it was ten times faster compared to the original version. (200 
frames per sec instead of 20 fps)

Probably my problem was a "no-problem". I realized that it does not 
matter how fast is my list. The most time consuming part is still the 
rendering of the images that are not in the cache. I need to speed up 
rendering and have more RAM, of course. :-)

   Les

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


Re: MySQLdb UPDATE does nothing

2005-09-16 Thread Magnus Lycka
Steve Horsley wrote:
> Or, as I found out yesterday, cursor.execute('commit') afterwards.

The correct way to do it is to close the cursor object, and
then do "db.commit()". Don't rely on a cursor object to work
across transaction boundries!

See e.g. www.thinkware.se/epc2004db/epc04_mly_db.pdf and
http://www.thinkware.se/epc2004db/dbapitest.py
-- 
http://mail.python.org/mailman/listinfo/python-list


multiple replaces

2005-09-16 Thread Harald Armin Massa
again, and again ... another try of templating

txt="""


whatever

the machine with bing

10% of boo is foo
"""

h1=txt.replace("%","%%")
h2=h1.replace("","%(tree)s")
h3=h2.replace("","%(house)s")

house="something awfull"
tree="something beautifull"
print h3 % locals()


--> the  approach allows it for me, that I can write
real HTML which looks fair. The replacing-chain takes care of % signs
within the file, and also makes a template for string replaces

BUT... it looks terribly inefficient to me. There are 3 strings which
are only there to be garbage collected. I am looking for a speedy way
of
"go through the text, and if you find sth. that is in REPLACEMENT,
replace it with it"

sth. like
rpdict={"":"%(tree)s","":"%(house)s","%","%%"}

for key, value in rpdict.iteritems():
h1=h1.replace(key, value)

but ... without the garbage, in one command.

I guess there are very, very, very wise solution for this problem, but
I do not know of them.

Who knows and tells me?

Harald

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


dictionary to file

2005-09-16 Thread Enrique Palomo Jiménez
Hi all,

I'm writing an application who needs to handle a lot of information of several 
files.
So, i think the better way is design a batch process to catch that information 
in a dictionary and write it in a file.
So, after that when a user wants to retrieve something, only with an execfile 
i'll have all the information avaiable.

Creating the file with pythonic syntax will be a hard job so,

is there some module to do that?
is there a better way?

The information will be used no more than 3-4 days a month and install 
databases is not allowed.

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


Re: 2.3 -> 2.4: long int too large to convert to int

2005-09-16 Thread Raymond L. Buvel
Grant Edwards wrote:
> I give up, how do I make this not fail under 2.4?
> 
>   fcntl.ioctl(self.dev.fileno(),0xc0047a80,struct.pack("HBB",0x1c,0x00,0x00))
> 
> I get an OverflowError: long int too large to convert to int
> 
> ioctl() is expecting a 32-bit integer value, and 0xc0047a80 has
> the high-order bit set.  I'm assuming Python thinks it's a
> signed value.  How do I tell Python that 0xc0047a80 is an
> unsigned 32-bit value?
>   
Everyone seems to be suggesting that the fix for the problem is to
somehow cobble together some way of forcing an unsigned integer into a
signed integer (what you would do with a cast in C).  However, if I
understand the long<->int consolidation this is not consistent with that
effort.

As far as I can tell, the underlying problem is that the C routine
fcntl.ioctl is expecting a signed integer.  These are the kinds of
problems that need to be fixed.  The function should be asking for an
unsigned integer.  This is possible with the C API at least since Python
2.3.  Without these fixes, the long<->int consolidation is going to
continue to produce frustration.  There are many functions in the
standard library that you would expect to take unsigned integers but
actually specify signed integers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Software bugs aren't inevitable

2005-09-16 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> But there is a difference: writing assembly is *hard*, which is why we
> prefer not to do it. Are you suggesting that functional programming is
> significantly easier to do than declarative?

I think you mean imperative.  Yes, there is a community that believes
that writing bug-free programs in functional style is easier than
writing them in imperative style.  Writing buggy programs might be
easier in imperative style, but in some application areas, that's not
good enough.

Why don't you read the Hughes paper I cited instead of taking cheap
shots at it without reading it, if you want to understand the issues
better.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary to file

2005-09-16 Thread Max M
Enrique Palomo Jiménez wrote:
> Hi all,
> 
> I'm writing an application who needs to handle a lot of information of 
> several files.
> So, i think the better way is design a batch process to catch that 
> information in a dictionary and write it in a file.
> So, after that when a user wants to retrieve something, only with an execfile 
> i'll have all the information avaiable.
> 
> Creating the file with pythonic syntax will be a hard job so,
> 
> is there some module to do that?
> is there a better way?


You can easily pickle a dictionary and save that to a file.

http://docs.python.org/lib/module-pickle.html

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is There the Equivalent of FLT_EPS of C In Python?

2005-09-16 Thread jburgy
A. L. wrote:
> I am writing the code involved in numerical computation. When I need a
> float epsilon similar to FLT_EPS in C, eps in matlab, I fail to find
> the equivalent in python. Could somebody here can give me some advices?

Have you searched the documentation? I you can't find anything there,
you can always calculate it yourself. Epsilon is usually defined as
follows:

>>> eps = 1.
>>> while 1. + eps != 1.:
... eps /= 2.
...
>>> eps
1.1102230246251565e-16

Then some people actually multiply the above number by 2. In other
words (on my machine), eps is math.ldexp(1, -52). YMMV

Jan

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


Re: re and escape character

2005-09-16 Thread Fredrik Lundh
Sinan Nalkaya wrote:

> thats exactly what i want, how can i use DOTALL, by doing re.compile ?

there's always the manual:

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

compile(pattern[, flags])

Compile a regular expression pattern into a regular expression object,
which can be used for matching using its match() and search() methods,
described below.

The expression's behaviour can be modified by specifying a flags value.

/.../

S
DOTALL

Make the "." special character match any character at all, including a
newline; without this flag, "." will match anything except a newline.

/.../

 



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


Re: Rendering HTML

2005-09-16 Thread Fredrik Lundh
Harlin Seritt wrote:

>I am looking for a module that will render html to console but
> formatted much like one might see with Lynx. Is there such a module
> already out there for this?

use htmllib+formatter:

http://effbot.org/librarybook/formatter.htm

 



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


Re: multiple replaces

2005-09-16 Thread Fredrik Lundh
Harald Armin Massa wrote:

> sth. like
> rpdict={"":"%(tree)s","":"%(house)s","%","%%"}
>
> for key, value in rpdict.iteritems():
>h1=h1.replace(key, value)
>
> but ... without the garbage, in one command.
>
> I guess there are very, very, very wise solution for this problem, but
> I do not know of them.

http://effbot.org/zone/python-replace.htm

 



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


Re: How to clear screen in Python interactive shell mode?

2005-09-16 Thread A. L.
I have tested it under windows python console, and it works.

Thank you very much.

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


Re: Looking for a database. Sugestions?

2005-09-16 Thread Christoph Haas
On Thu, Sep 15, 2005 at 11:00:46PM +0200, ionel wrote:
> I'm looking for a thread-safe database.
> Preferably an embedded, sql database.
> 
> What are the best choices in terms of speed ?

Sqlite may be a good choice. It doesn't have network overhead, operates
on simple files on the disk (nothing to configure) and is often faster
than MySQL & Co.

Regards
 Christoph
-- 
~
~
~
".signature" [Modified] 3 lines --100%--3,41 All
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to clear screen in Python interactive shell mode?

2005-09-16 Thread bruce
elif os.name in ("nt", "dos", "ce"):
# emacs/Windows 
What`s the right statement here?

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


ANN: Pyrex 0.9.3.1

2005-09-16 Thread Greg Ewing
Giovanni Bajo has put together a Pyrex release incorporating
patches to address the Python 2.4 distutils compatibility
problem and the GCC 4 lvalue cast problem.

http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

Thanks to Giovanni for filling a gap until I can get back
to working on Pyrex again.


What is Pyrex?
--

Pyrex is a new language for writing Python extension modules.
It lets you freely mix operations on Python and C data, with
all Python reference counting and error checking handled
automatically.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,   
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing shared library file...

2005-09-16 Thread Ernesto
Where is the ctypes mailing list?

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


Multi-Screen display

2005-09-16 Thread Bartosz Ptaszynski
Hi,
Currently I'm working on a project in which I have to display a
window on each of the monitors connected to the PC. I've been looking
around for a way to detect how many monitors are connected to the
machine (windows box) and how to force a window to launch at specific
monitor, without luck.

Launching window on specific screen may be possible by detecting the
resolution of first screen and adding +1px to it as a start position
for the window. But that's only a theory.

btw. I'm using wxPython for GUI.

Any suggestions?

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


Py.java out of memory exception.

2005-09-16 Thread deeptirev
Working on a CLI application that uses python package. The memory
consumed is around 200 Mb. Heap size allocated is 512 Mb. But still I
am getting outofmeomory exception due to which the JVM is killed.
Working on Windows 2000.

Any idea what could cause this?? There are no more system exits in our
code!

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


Re: Creating Pie Chart from Python

2005-09-16 Thread John Hunter
> "Thierry" == Thierry Lam <[EMAIL PROTECTED]> writes:

Thierry> Let's say I have the following data: 500 objects: -100
Thierry> are red -300 are blue -the rest are green

Thierry> Is there some python package which can represen the above
Thierry> information in a pie chart?


It looks like in python there is more than one way to make a pie
chart.  Here's another

from pylab import figure, pie, show
N, red, blue = 500, 100, 300
green = N - (red + blue)
figure(figsize=(6,6))
pie( (red, blue, green),
 labels=('red', 'blue', 'green'),
 colors=('red', 'blue', 'green'),)
show()

A screenshot of a slightly more elaborate example is at

http://matplotlib.sourceforge.net/screenshots.html#pie_demo

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


Python:C++ interfacing. Tool selection recommendations

2005-09-16 Thread adsheehan
Hi,

I am embedding Python with a C++ app and need to provide the Python
world with access to objects & data with the C++ world.

I am aware or SWIG, BOOST, SIP. Are there more?

I welcome comments of the pros/cons of each and recommendations on when
it appropriate to select one over the others.

Thanks in advance.

Alan

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Michael Sparks
Steven D'Aprano wrote:

> On Thu, 15 Sep 2005 18:07:28 +0100, phil hunt wrote:
>> On Thu, 15 Sep 2005 21:56:06 +1000, Steven D'Aprano
>> <[EMAIL PROTECTED]> wrote:
>>>
>>>Are you saying that the recursion done by "serious" languages is a fake?
>>>That it is actually implemented behind the scenes by iteration?
>>>
>>>It seems to me that if recursion and iteration produce "the exact same
>>>machine code", the argument for preferring recursion over iteration is
>>>gutted.
>> 
>> It seems to me that if a high level language and assembler produce
>> "the exact same machine code", the argument for preferring high
>> level languages is gutted.
>> 
>> Do you see the fallacy in your statement now?
> 
> Ah, yes, you got me on that one.
> 
> But there is a difference: writing assembly is *hard*, which is why we
> prefer not to do it. Are you suggesting that functional programming is
> significantly easier to do than declarative?
> 

But there is a difference: writing assembly is *hard*, which is why we
prefer not to do it. Are you suggesting that object oriented programming is
significantly easier to do than old style imperative?

(sorry, couldn't resist)

FWIW, IMO once you've learnt functional programming's idioms it certainly
can be easier and more natural. The problem is the tools that make things
like recursion efficient aren't available normally in mainstream languages
meaning that most people simply don't get the practice.

Essentially it's about expressiveness.

Think of it this way - we normally write left to write, however some
languages read up and down. Neither is inherently better or easier
than the other, but for some things *may* be more expressive. 

If you think about it being about choosing the most clear/expressive way to
describe an algorithm, the argument may become clearer. After all, the
recursive definition of some things is clearer than the non-recursive.


Michael.

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


Re: My First Python Script

2005-09-16 Thread Gary Wilson Jr
Ed Hotchkiss wrote:
> def ZeroThrough255():
>   x = 0
>   while x <= 255:
>   if len(x) == 1:
>   mySet = '00' + str(x)
>   elif len(x) == 2:
>   mySet = '0' + str(x)
>   else:
>   mySet = x
>   print mySet
>   x +=1   
> 
> ZeroThrough255()

Instead of using the while loop and a counter, you can use the range() 
function.  Using range() and string formatting you could to something like:

def ZeroThrough255():
for num in range(256):
print "%03d" % num

which, using a list comprehension and the string join() function, could also 
be written as:

def ZeroThrough255():
print "\n".join(["%03d" % num for num in range(256)])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI Problem on MS IIS 5.0 - Trying to access files on other machines

2005-09-16 Thread paulp
Based on your comment, I finally realized that IIS is running under the
IUSR_ account.  So I changed the priveleges on this account on my test IIS
server as related elsewhere in this note.  So now I'm getting a different
error.

1326, "LogonUser", "Logon failure: unknown user name or bad password"

It's progress of a sort.

My test box is running IIS, and I set up a local test account (PYTHONTEST)
on my primary box.  This is the account I'm trying to hook into at the
moment.

Any thoughts on this?

Many thanks for your help.

Paul


"Pat [MSFT]" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Set the site to be Basic Authentication and login as you.  I suspect that
> the .exe is either running as IWAM/IUSER (i.e. GUEST) or you are running
> into a double hop issue.
>
>
> Pat
>
> "paulp" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Greetings,
> >
> > I'm working on a CGI program that will run under MS IIS 5.0 and will
> > browse folders on three other machines, building HTML pages that will
> > provide links to these folders.
> >
> > Essentially, the CGI will connect to each machine in turn, doing the
> > FindFirst/FindNext process based on the current criteria.  It will
> > select certain files/folders, and build an HTML page as it goes.
> >
> > The premise is fine.  If I run the program from the command line, it
> > seems to work fine and I get my HTML code out.  I can copy the code
> > into a separate file, open it in the browser, and all appears right
> > with the world.
> >
> > However, when I try to run the CGI from the browser itself, I get all
> > kinds of problems.  The first one I got was a 1312, "A specified logon
> > session does not exist.  It may have already been terminated."  After
> > doing some searching, I began to investigate impersonation of a logged
> > on user.  This produces a different error: 1314, "A required privilege
> > is not held by the client."
> >
> > The code involved and the output I'm getting follows:
> >
> > -BEGIN--
> > class Impersonate:
> >def __init__(self, login, password ):
> >self.domain = '4Q9ND21'
> >self.login = login
> >self.password = password
> >self.handel = None
> >def logon(self):
> >tracelist.append("Impersonate logon step 0")
> >win32security.RevertToSelf()# terminates impersonation
> >tracelist.append("Impersonate logon step 1")
> >self.handel = win32security.LogonUser( self.login, self.domain,
> > self.password, win32con.LOGON32_LOGON_INTERACTIVE,
> > win32con.LOGON32_PROVIDER_DEFAULT )
> >tracelist.append("Impersonate logon step 2")
> >win32security.ImpersonateLoggedOnUser(self.handel)
> >tracelist.append("Impersonate logon step complete")
> >def logoff(self):
> >win32security.RevertToSelf()# terminates impersonation
> >if self.handel != None:
> >self.handel.Close() # guarantee cleanup
> > --END---
> >
> > and I execute this code with the following
> >
> > -BEGIN--
> >impersonate = Impersonate( 'PYTHONTEST', 'PYTHONTEST' )
> >try:
> >tracelist.append("about to attempt the IMPERSONATE")
> >impersonate.logon()
> >tracelist.append("impersonate did NOT throw exception")
> >b=AdjustPrivilege(SE_SYSTEM_PROFILE_NAME)
> >b=AdjustPrivilege(SE_TCB_NAME)
> >try:
> >tracelist.append("win32api.GetUserName = " +
> > win32api.GetUserName() )
> ># print win32api.GetUserName() #show you're someone else
> >finally:
> >impersonate.logoff() #return to normal
> >except:
> >a = "Impersonate Logon Error: %s %s" % (sys.exc_type,
> > sys.exc_value)
> >tracelist.append(a)
> ># print sys.exc_type, sys.exc_value
> > --END---
> >
> > When I run this code, my tracelist comes out with
> >
> > -BEGIN--
> > 2005-09-15 16:43:37
> > about to attempt the IMPERSONATE
> > Impersonate logon step 0
> > Impersonate logon step 1
> > Impersonate Logon Error: pywintypes.error (1314, 'LogonUser', 'A
required
> > privilege is not held by the client.')
> > --END---
> >
> >
> > I'm coding this in Python 2.4 and the Windows extensions.  I have a
> > number of other CGI programs in Python running under IIS that work
> > correctly, but those only do database accesses.  This one I'm trying to
> > put together is the first one to actually do file searches.
> >
> >
> > I have set the privileges for the logged on account on my IIS box for
> > SE_TCB_NAME, SE_CHANGE_NOTIFY_NAME and SE_ASSIGNPRIMARYTOKEN_NAME and
> > rebooted.  To no avail.  I'm not sure if there are additional
> > alterations that need to be done to the security policies or not.
> > Again, I'm not a guru.
> >
> >
> > If anyone can give me more information/guidance I would greatly
> > appreciate it.  If you need more information from me, I will

Re: Is There the Equivalent of FLT_EPS of C In Python?

2005-09-16 Thread A. L.
Thank you very much.

I have searched in python's documentation, and I am sure that python
doesn't provide an epsilon.

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


Re: strptime() doesn't recognize BST as a valid timezone

2005-09-16 Thread Dan
> I get: "ValueError: time data did not match format: ..."

I'm running Linux in London, and I don't get that error.

Python 2.3.5 (#2, May 29 2005, 00:34:43)
[GCC 3.3.6 (Debian 1:3.3.6-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> date_str = "Wed Sep 14, 2005 5:07 PM BST"
>>> format = "%a %b %d, %Y %I:%M %p %Z"
>>> time.strptime(date_str, format)
(2005, 9, 14, 17, 7, 0, 2, 257, 1)

However, when I used another timezone (I tried EST and PST), I got the
same error you did.

I really don't know enough about how Python handles dates to tell you
anything more.

-- 
  Diplomacy is saying "nice doggy" until you find a rock.
 - submitted by Nancy Greer
   to the CleanStuff mailing list


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


Walking through directories and files

2005-09-16 Thread Thierry Lam
I'm trying to use the os.walk() method to search all the directory from
a root directory and display their contents. For example, I want my
output to be like the following:


directoryA
stuffs.c
stuffs2.cpp

directoryB
asd.c
asdf.cpp


Any ideas how to do it? Currently, I can only print all the filenames
first and then the directory names.

Thanks
Thierry

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


Re: Creating Pie Chart from Python

2005-09-16 Thread Markus Weihs
Hi!

I tried your script and got the following error:

  Traceback (most recent call last):
File "pie_chart.py", line 302, in OnPaint
  self.OnDraw()
File "pie_chart.py", line 336, in OnDraw
  segment.Draw(self.angle, self.rot, self.explode)
File "pie_chart.py", line 46, in Draw
  glPopMatrix()
  OpenGL.GL.GLerror: [Errno 1281] invalid value

What am I doing wrong?


Regards, Markus


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


Re: multiple replaces

2005-09-16 Thread D H
You can use python's re.sub function.  But also look into full fledged 
template engines like Cheetah.

import re

txt="""


whatever

the machine with bing

10% of boo is foo
"""

h1=txt.replace("%","%%")
h3 = re.sub("", "%(\\1)s", h1)

house="something awfull"
tree="something beautifull"
print h3 % locals()

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


Re: Creating Pie Chart from Python

2005-09-16 Thread Thierry Lam
Those python pie chart add ons are not very useful. For my specific pie
chart, I have some 6-8 items to show up and some of them occupy only
2-5% of the pie. This cause the names and percentages to overlap each
other.

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


Re: Is There the Equivalent of FLT_EPS of C In Python?

2005-09-16 Thread A. L.
According to pp 134 of  "C: A Reference Manual", it's better to use
eps*2 in your code.

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Giles Brown

Michael Sparks wrote:
> The problem that these sorts of approaches don't address is the simple
> fact that simple creating a formal spec and implementing it, even if
> you manage to create a way of automating the test suite from the spec
> *doesn't guarantee that it will do the right thing*.

> As a result I'd say that the subject "Software bugs aren't inevitable"
> is not true.

I think you can argue (I would) that any behaviour that is in the
specification this "isn't right" is not a software bug, but a
specification error.  This obviously puts the focus on specification
errors, but standard development processes don't guarantee the absence
of specification errors either.

Btw, I'm not arguing that this type of approach is widely applicable,
but the "you'll always face specification errors" argument isn't well
reasoned I think.  

Cheers,
Giles

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


Re: Rendering HTML

2005-09-16 Thread D H
Harlin Seritt wrote:
> I am looking for a module that will render html to console but
> formatted much like one might see with Lynx. Is there such a module
> already out there for this?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52297
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Software bugs aren't inevitable

2005-09-16 Thread Terry Hancock
On Thursday 15 September 2005 04:38 am, Jerzy Karczmarczuk wrote:
> is for me a biased view of the problem. Justified only by the fact that
> at the beginning of functional programming (sixties) nobody cared about
> the efficiency. Now, such languages as Clean, or good implementations of
> Scheme are very well optimized. OCaml as well, and Haskell is improving
> every 3 months. Functional languages did take off, but since a pure
> functionalism requires particular, quite sophisticated techniques in
> GOOD algorithm design and implementation, they are less adapted to the
> brutal world than C or Python. The reasons of relatively small popularity
> are much less technical than psychological, and this is KNOWN.

This is ludicrous sophistry. The technical reason for having ANY high
level languages is "psychological".  Computers are happier with binary
code, over ANY language that must be interpreted.  So, presumeably, would
some perfect intellectual being not limited by "mere psychology".

Programming languages are an interface to Human minds, so the argument
that one system of representation is easier to understand is an argument
that that system is *better* in that it is a better interface.
 
> (Terry Hancock formulated this plainly, he prefers dumb ways because
> he wants to solve problems, and he doesn't like to perform gymnastics
> with his brain. We have to accept those attitudes. But I believe that
> this is the effect of teaching standards; people don't learn high-level
> algorithm design when they are young enough...)

Clearly Jerry here believes that arrogance and intelligence must go hand
in hand: just for your education, there is a difference between *being*
intelligent and feeling like you have to *prove* it to everyone you meet.
I learned a long time ago, that there are plenty of *unavoidably* complex
problems out there, so that there's so need to make simple ones complex,
just to prove how clever you are.  You're darned right I avoid wasting
time on problems that don't require it.

As for the education claim, you are just *so* out of your depth ...
Humans learn to program about as early now as they can handle the subject.
Many working programmers today started learning to program in grade school,
most of the ones under 30 or so started in high school at the latest.

As a matter of observable fact, people tend to solve problems in certain
ways more naturally than others (and not necessarily the same way as
other people). There's nothing "more natural" about functional
programming than procedural.  In fact, it would appear that some
problems are more intuitive to solve one way or the other.

The FP camp (apparently) wants to advance the claim that FP will *always*
reduce bugs.  I find that very hard to believe. It seems to me that programmers
will always have an easier time reducing bugs in programs they *understand*
well.  While cleverness in algorithm design is always respected for the
intellectual prowess it demonstrates, it is almost always bad engineering.

"Keep It Simple Stupid" is just as good a rule in computer science
as in any other area of engineering -- and given the natural complexity
of CS, it clearly needs such admonitions more.

I don't avoid complex code because I *can't* understand it. I avoid it,
because complex code gets in the way of solving problems. You might argue
that FP code is simpler because it is shorter or encodes fewer conceptual
steps (within the FP framework), but this is just as false a measure, IMHO,
as Perl (or C) advocates' tendency to measure complexity in keystrokes
or lines of code.

Just because something involves fewer symbols doesn't necessarily make it
simpler. There's a correlation -- but other factors, like the amount of
time the reader is going to have to spend visualizing or stepping through
the process are just as important.

Rules like estimating project complexity in lines of code rely on
assumptions that the average level of understanding required to deal
with average lines of code are about the same. It would seem that in
practice this is true.

But that is tangential to this argument: if you insist on a difficult
methodology, then you are violating the assumption of the LOC estimation
model, and it will no longer be accurate. To the degree that FP makes
each LOC harder to understand, it is cancelling out any LOC savings it
makes.

So, when FP is intuitive AND reduces code complexity AND is reasonably
efficient, it's a good buy, and I'll use it -- but to argue that it
will *always* do so seems insane.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Walking through directories and files

2005-09-16 Thread Fredrik Lundh
Thierry Lam wrote:

> I'm trying to use the os.walk() method to search all the directory from
> a root directory and display their contents. For example, I want my
> output to be like the following:
>
>
> directoryA
> stuffs.c
> stuffs2.cpp
>
> directoryB
> asd.c
> asdf.cpp
>
> Any ideas how to do it?

import os

for dirpath, dirnames, filenames in os.walk("."):
print os.path.basename(dirpath)
for file in filenames:
print file
print

> Currently, I can only print all the filenames first and then the directory
> names.

why you cannot just put the print statements in the right order is more
than I can figure out, but I haven't had enough coffee today, so there's
probably a simple explanation.

 



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


Re: Python:C++ interfacing. Tool selection recommendations

2005-09-16 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:
> Hi,
> 
> I am embedding Python with a C++ app and need to provide the Python
> world with access to objects & data with the C++ world.
> 
> I am aware or SWIG, BOOST, SIP. Are there more?
> 
> I welcome comments of the pros/cons of each and recommendations on when
> it appropriate to select one over the others.

SWIG is rather primitive - to get OO-Style Objects, you need to create 
python wrappers yourself, that have an object-reference and call all 
generated wrapper functions with that as fisrt argument. SIP is way more 
elegant in thast respect. I never tried boost.

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


Why doesn't IDLE editor windows have horizontal scrollbars?

2005-09-16 Thread chuck
The browser windows do.  Why not the editor windows?

I hate to complain but is there any way to get IDLE to run in more of
an MDI mode?  Having the floating windows everywhere is rather
confusing to me.

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


Wrapper module for Linux shared lib

2005-09-16 Thread Ernesto
What's the best resource for finding out how to write a wrapper module
for a shared library file *.so* in Linux?

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


Re: Creating Pie Chart from Python

2005-09-16 Thread Will McGugan
Markus Weihs wrote:
> Hi!
> 
> I tried your script and got the following error:
> 
>   Traceback (most recent call last):
> File "pie_chart.py", line 302, in OnPaint
>   self.OnDraw()
> File "pie_chart.py", line 336, in OnDraw
>   segment.Draw(self.angle, self.rot, self.explode)
> File "pie_chart.py", line 46, in Draw
>   glPopMatrix()
>   OpenGL.GL.GLerror: [Errno 1281] invalid value
> 
> What am I doing wrong?

I'm not sure. Thats a strange place for it to fail. Do you have the 
latest version of pyOpenGL / wxPython?

Its only been tested on Windows, but it just uses basic OpenGL so there 
is not that much to go wrong..

Will McGugan
-- 
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in 
"jvyy*jvyyzpthtna^pbz")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.3 -> 2.4: long int too large to convert to int

2005-09-16 Thread Grant Edwards
On 2005-09-16, Raymond L. Buvel <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>> I give up, how do I make this not fail under 2.4?
>> 
>>   fcntl.ioctl(self.dev.fileno(),0xc0047a80,struct.pack("HBB",0x1c,0x00,0x00))
>> 
>> I get an OverflowError: long int too large to convert to int
>> 
>> ioctl() is expecting a 32-bit integer value, and 0xc0047a80 has
>> the high-order bit set.  I'm assuming Python thinks it's a
>> signed value.  How do I tell Python that 0xc0047a80 is an
>> unsigned 32-bit value?
>
> Everyone seems to be suggesting that the fix for the problem
> is to somehow cobble together some way of forcing an unsigned
> integer into a signed integer (what you would do with a cast
> in C).  However, if I understand the long<->int consolidation
> this is not consistent with that effort.
>
> As far as I can tell, the underlying problem is that the C
> routine fcntl.ioctl is expecting a signed integer.

Well, that's what the man page says. 

In practice it's just expecting an int-sized chunk of bits: it
wants a unique bit pattern to feed to a 'case' statement rather
than an "integer" in the number-line, arithmetic operations
sense of the word.  C's implicit coercion rules make it a moot
point, but Python's coercion rules have been changed to be
incompatible with C's.  Hilarity ensues. ;)

> These are the kinds of problems that need to be fixed.  The
> function should be asking for an unsigned integer.  This is
> possible with the C API at least since Python 2.3.  Without
> these fixes, the long<->int consolidation is going to continue
> to produce frustration.  There are many functions in the
> standard library that you would expect to take unsigned
> integers but actually specify signed integers.

Unfortunately the C API is cast in stone (at least in
comparison to Python standards).  I guess somebody could go
through the C-Python code and "lie" to Python about it in order
to fix some of the issues.

What I would really, really like are fixed length integer types
so that I can manipulate 8, 16, 32 and maybe 64 bit, 2's
compliment values.  I've seen some pretty good "user-space"
pure-python implimentations, but haven't gotten around to using
them in production yet.  

One of the nasty bits in a pure-python approach is that there's
no way to write a literal with a fixed length.  For example,
instead of writing 0xf7 to get an 8-bit value and 0x12345789 to
get a 32-bit value, you have to instantiate a class like 
Word8(0xf7) and Word32(0x12345678).

That starts to make things pretty hard to read.

-- 
Grant Edwards   grante Yow!  Yow! Now we can
  at   become alcoholics!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encryption with python?

2005-09-16 Thread Larry Bates
I've successfully used this toolkit to implement AES encryption in
a recent project.

http://www.amk.ca/python/code/crypto

-Larry Bates

Robert Kern wrote:
> Ed Hotchkiss wrote:
> 
>>What's the best module for encryption with python, anyone out there
>>using python and encryption together?
> 
> 
> It depends on what your needs are. What do you need to accomplish?
> 

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Sybren Stuvel
Terry Hancock enlightened us with:
> This is ludicrous sophistry. The technical reason for having ANY high
> level languages is "psychological".  Computers are happier with binary
> code, over ANY language that must be interpreted.

Computers aren't happy. They couldn't care less about the programming
language.

> Programming languages are an interface to Human minds, so the
> argument that one system of representation is easier to understand
> is an argument that that system is *better* in that it is a better
> interface.

Well said! I'm going to remember that one :)

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapper module for Linux shared lib

2005-09-16 Thread Sybren Stuvel
Ernesto enlightened us with:
> What's the best resource for finding out how to write a wrapper
> module for a shared library file *.so* in Linux?

The extension documentation on the python website.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lines of Strings

2005-09-16 Thread Larry Bates
If these were the lines what would the output look like?
>From your example it doesn't appear that any of the lines
would be eliminated.

Larry Bates

Reem Mohammed wrote:
> Hi
> 
> Suppose we have data file like this one (Consider all lines as strings )
> 
> 1 2 3 3 4 4 4 4 5 6
> 2 2 2 5 5 5 6
> 3 2 1 1 1 3 3 3 4 6
> 
> I would like to remove line if its belong to another one, and will be
> able to do this if longer line come after a short one.
> 
> Thanks
> 
> _
> Express yourself instantly with MSN Messenger! Download today - it's
> FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> 

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


Re: dictionary to file

2005-09-16 Thread Larry Bates
You don't define what you mean by "a lot".  Python can read
a tremendous amount of information from files in a very short
amount of time so I wouldn't try to prematurely optimize this.
Just read the information and see how long it takes.  If it
is really a long time, then look for alternatives.  It will
take some time to read the dictionary and to unpickle it.

-Larry

Enrique Palomo Jiménez wrote:
> Hi all,
> 
> I'm writing an application who needs to handle a lot of information of 
> several files.
> So, i think the better way is design a batch process to catch that 
> information in a dictionary and write it in a file.
> So, after that when a user wants to retrieve something, only with an execfile 
> i'll have all the information avaiable.
> 
> Creating the file with pythonic syntax will be a hard job so,
> 
> is there some module to do that?
> is there a better way?
> 
> The information will be used no more than 3-4 days a month and install 
> databases is not allowed.
> 
> Thanks

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


Re: Wrapper module for Linux shared lib

2005-09-16 Thread Matt Hammond
On Fri, 16 Sep 2005 15:49:15 +0100, Ernesto <[EMAIL PROTECTED]> wrote:

> What's the best resource for finding out how to write a wrapper module
> for a shared library file *.so* in Linux?

I thoroughly recommend pyrex ... it was a joy to use:

http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/


-- 

| Matt Hammond
| R&D Engineer, BBC Research & Development, Tadworth, Surrey, UK.
| http://kamaelia.sf.net/
| http://www.bbc.co.uk/rd/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Software bugs aren't inevitable

2005-09-16 Thread Terry Hancock
On Friday 16 September 2005 08:35 am, Michael Sparks wrote:
> Steven D'Aprano wrote:
> > But there is a difference: writing assembly is *hard*, which is why we
> > prefer not to do it. Are you suggesting that functional programming is
> > significantly easier to do than declarative?
> 
> But there is a difference: writing assembly is *hard*, which is why we
> prefer not to do it. Are you suggesting that object oriented programming is
> significantly easier to do than old style imperative?

The answer in both cases, is that it depends very much on what you're
trying to write.

> FWIW, IMO once you've learnt functional programming's idioms it certainly
> can be easier and more natural.

In particular domains of problem-solving, yes.

> The problem is the tools that make things
> like recursion efficient aren't available normally in mainstream languages
> meaning that most people simply don't get the practice.

There's also an assumption here (which I regard as a fallacy), that different
models of programming are equally intuitive. Some models, like OOP, draw
heavily on experience *outside* the realm of programming (in many cases,
you can successfully apply machine-shop experience to a programming problem
if the program is object-oriented -- in fact, ISTM, this is the *primary*
power of OOP, that it allows you to provide experience from the problem
domain to the process of writing a software program to work with that domain).

Functional programming (and I am no expert here), seems to me to draw
heavily on the problem domain *of* computer science. So naturally,
computer scientists think it's brilliant and intuitive.

But for those of us who primarily regard computers as tools for solving
problems in other domains -- such as image-processing, web-application,
handling business transactions, or simulating supernovae -- FP just doesn't
seem very natural at all.  In fact it seems completely backwards, perverse,
and twisted, as if the designer were simply trying to confuse and
obfuscate the problem instead of solving it.

Or at least, it frequently does.

> Essentially it's about expressiveness.

Yes, and expressiveness means keeping vocabulary and grammar for
different applications, not throwing one out on the basis that it
is somehow superior. If you *are* making the latter claim, then
the burden is on you to prove that your method is really that much
better.

> Think of it this way - we normally write left to write, however some
> languages read up and down. Neither is inherently better or easier
> than the other, but for some things *may* be more expressive. 

I *really* doubt that, actually. ;-)
But I heard what you meant.

> If you think about it being about choosing the most clear/expressive way to
> describe an algorithm, the argument may become clearer. After all, the
> recursive definition of some things is clearer than the non-recursive.

Yes.  I think all we're claiming is that the reverse is equally true.

In addition to this kind of elegance argument, there is also a pragmatic
argument that, with existing technology, it is sometimes much more efficient
to write an iterative solution than to insist on recursion. Even if it can
then be shown for particular cases that a recursive solution that is also
efficient exists, and even if it can be proven that, in general, all such
efficient iterative solutions have equivalent recursive solutions, it does
not defeat the simple point that the obvious iterative solution is faster
and more efficient than the obvious recursive solution.

Let's not forget that this started with an example of the Fibonacci series.

Who in their right mind would *actually* be trying to solve the Fibonacci
series for a practical programming application?  It's a toy, like the
"hello world" program.  I have no doubt that I can handle the extra burden
of understanding the cleverly structured "efficient recursive" algorithm,
versus the alternatives.  But I can also see that it *is* more of a burden
to understand it -- it causes confusion.

Now what happens when the complexity goes up ten-fold, and we add extra
bells and whistles to it that theoretical programs usually skip over, and
real world programs have in abundance?

At that point, I *really* want that core problem to be simple to understand.
Ideally, as simple as it can possibly be.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Terry Hancock
On Friday 16 September 2005 09:41 am, Terry Hancock wrote:
> > (Terry Hancock formulated this plainly, he prefers dumb ways because
> > he wants to solve problems, and he doesn't like to perform gymnastics
> > with his brain. We have to accept those attitudes. But I believe that
> > this is the effect of teaching standards; people don't learn high-level
> > algorithm design when they are young enough...)
> 
> Clearly Jerry here believes that arrogance and intelligence must go hand
> in hand: just for your education, there is a difference between *being*
> intelligent and feeling like you have to *prove* it to everyone you meet.
> I learned a long time ago, that there are plenty of *unavoidably* complex
> problems out there, so that there's so need to make simple ones complex,
> just to prove how clever you are.  You're darned right I avoid wasting
> time on problems that don't require it.

I *probably* should've used a little more restraint here. ;-)

I *definitely* should've spelled Jerzy's name correctly.
Sorry, no offense intended.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Self reordering list in Python

2005-09-16 Thread Terry Hancock
On Friday 16 September 2005 06:03 am, Laszlo Zsolt Nagy wrote:
> You are right in that holding a reference will have a better time 
> complexity. But holding a reference makes it impossible to free the 
> object. :-) As I said, my list has a maximum length. I just can't store 
> any number of images in memory. I need to keep only the most frequently 
> used ones. I do not know which ones will be used the most frequently, 
> this is why I need a self reordering list. Accessing an element makes it 
> "more imporant" than the others. I already implemented this in Python 
> and it was ten times faster compared to the original version. (200 
> frames per sec instead of 20 fps)

This is actually the use-case for an "LRU cache"="least recently used
cache", which is probably already implemented in Python somewhere (or
even as a fast extension).  I'd do a google search for it.  It almost
certainly would use a dictionary interface within Python, ISTM.

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Ron Adam
Paul Rubin wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
> 
>>But there is a difference: writing assembly is *hard*, which is why we
>>prefer not to do it. Are you suggesting that functional programming is
>>significantly easier to do than declarative?
> 
> 
> I think you mean imperative.  Yes, there is a community that believes
> that writing bug-free programs in functional style is easier than
> writing them in imperative style.  Writing buggy programs might be
> easier in imperative style, but in some application areas, that's not
> good enough.
> 
> Why don't you read the Hughes paper I cited instead of taking cheap
> shots at it without reading it, if you want to understand the issues
> better.


Just some comments from my own experiences concerning bugs and writing 
dependable software.  It pretty much depends on a number of things and 
isn't just a matter of good design or what language is used.

* The dependability of the hardware
* The dependability of the OS
* The stability of the language used
* The programmers knowledge of the language used
* Program design
* How many programmers are working on the same project
* How many extensions are used and written by other people
* The stability of those extensions
* Rate of change of the program design, and all underlying parts.

A small program with no external modules and written by a single person 
can be fairly dependable, or as dependable as the underlying language, 
OS, and hardware.

But as soon as the softwares complexity increases and/or multiple 
programmers are used, either directly or indirectly through third party 
extensions, then the probability of bugs increases substantially.

Given *enough* time, effort, and testing, without changing the design, 
even a large program can be nearly as dependable as the least dependable 
part of the platform it is running on.  ("enough" could be a long time 
here.)

To increase reliability to nearly 100%, you need to run different 
versions of a program on several different platforms simultaneously and 
use only the results that have a majority agreement.

Or to put it another way; risk management by ... "keep it simple", 
"don't have too many cooks", "get second opinions", and "don't put all 
your eggs in one basket".

Cheers,
Ron

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


Re: Python:C++ interfacing. Tool selection recommendations

2005-09-16 Thread Neal Becker
[EMAIL PROTECTED] wrote:

> Hi,
> 
> I am embedding Python with a C++ app and need to provide the Python
> world with access to objects & data with the C++ world.
> 
> I am aware or SWIG, BOOST, SIP. Are there more?
> 
> I welcome comments of the pros/cons of each and recommendations on when
> it appropriate to select one over the others.
> 

boost::python is alien technology.  It is amazingly powerful.  Once you
learn how to use it it's wonderful, but unless you are comfortable with
modern c++ you may find the learning curve steep.

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


Re: My First Python Script

2005-09-16 Thread Ed Hotchkiss
 
Sweet, time to play with python for a whole day today :P 
On 9/16/05, Gary Wilson Jr <[EMAIL PROTECTED]> wrote:
Ed Hotchkiss wrote:> def ZeroThrough255():>   x = 0>   while x <= 255:
>   if len(x) == 1:>   mySet = '00' + str(x)>   elif len(x) == 2:>   mySet = '0' + str(x)>   else:>   mySet = x
>   print mySet>   x +=1>> ZeroThrough255()Instead of using the while loop and a counter, you can use the range()function.  Using range() and string formatting you could to something like:
def ZeroThrough255():   for num in range(256):   print "%03d" % numwhich, using a list comprehension and the string join() function, could alsobe written as:def ZeroThrough255():
   print "\n".join(["%03d" % num for num in range(256)])--http://mail.python.org/mailman/listinfo/python-list
-- edward hotchkiss 
-- 
http://mail.python.org/mailman/listinfo/python-list

xml2schema

2005-09-16 Thread Mikael Larsson
Hi
Is there any python tool to generate a schema from xml ??

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Ron Adam
Terry Reedy wrote:

> You cannot tell whether a function object will act
> recursive or not just by looking at its code body.  Trivial examples:

I was thinking last night that maybe it would be useful to be able to 
define a function explicitly as a recursive object where it's frame is 
reused on successive calls, but then I realized that it's nearly 
identical to a loop in that context, so why not just write it as a loop 
to start with.

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



Re: Python:C++ interfacing. Tool selection recommendations

2005-09-16 Thread float_dublin
Neal Becker wrote:
> [EMAIL PROTECTED] wrote:
> 
> 
>>Hi,
>>
>>I am embedding Python with a C++ app and need to provide the Python
>>world with access to objects & data with the C++ world.
>>
>>I am aware or SWIG, BOOST, SIP. Are there more?
>>
>>I welcome comments of the pros/cons of each and recommendations on when
>>it appropriate to select one over the others.
>>
> 
> 
> boost::python is alien technology.  It is amazingly powerful.  Once you
> learn how to use it it's wonderful, but unless you are comfortable with
> modern c++ you may find the learning curve steep.
> 
Note: there is excelent Pyste python prog  inside that autogenerates 
boost::python code for you from special describtion files (where you can 
actualy write AllFromHeader("xxx.h")) and your header files.
Boost::python is the best solution, but the compile time of wrappers.

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


Re: Software bugs aren't inevitable

2005-09-16 Thread phil hunt
On Fri, 16 Sep 2005 20:36:02 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>On Thu, 15 Sep 2005 18:07:28 +0100, phil hunt wrote:
>
>> On Thu, 15 Sep 2005 21:56:06 +1000, Steven D'Aprano <[EMAIL PROTECTED]> 
>> wrote:
>>>
>>>Are you saying that the recursion done by "serious" languages is a fake?
>>>That it is actually implemented behind the scenes by iteration?
>>>
>>>It seems to me that if recursion and iteration produce "the exact same
>>>machine code", the argument for preferring recursion over iteration is
>>>gutted.
>> 
>> It seems to me that if a high level language and assembler produce
>> "the exact same machine code", the argument for preferring high
>> level languages is gutted.
>> 
>> Do you see the fallacy in your statement now?
>
>Ah, yes, you got me on that one.
>
>But there is a difference: writing assembly is *hard*, which is why we
>prefer not to do it. Are you suggesting that functional programming is
>significantly easier to do than declarative?

No. I'm saying that under some circumstances it might be easier to 
write code as a recursive routine than a loop. In those 
circumstances, why should I care if the compiler then re-encodes my 
recursive routine as a loop, so long as the program gives the 
correct answer.

Compilers/interpreters/runtimes are black boxes: we don't (or
shouldn't) care how they do their work as long as they run correctly 
and aren't too heavy on system resources like CPU time and memory.


-- 
Email: zen19725 at zen dot co dot uk


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


Re: IDE, widget library

2005-09-16 Thread float_dublin
Thomas Jollans wrote:
> I guess questions like this come all the time here ... well:
> 
> I a looking for a python IDE for gnu/linux that :
> - has decent sytax highlighting (based on scintilla would be neat)
> - has basic name completition, at least for system-wide modules
> - has an integrated debugger
> - is open source, or at least free of charge
> 
> an integrated GUI designer would of course be cool, but cannot be 
> counted as a requirement.
> 
> With that I come to the second question:
> What cross-platform GUI libraries are there ? cross-platform meaning 
> functional and free on (at least) X11 and Win32
> PyQT obviously doesn't count because qt3 is not free on windows.
> Tk is ugly. (how well) is Tile supported with python ?
> does PyGTK/Glade work on win32 ?
wxPython + boaconstructor as IDE + RAD (looks like delphi or VB) and 
easy to use (i'm c++'er but it took 15minutes to create some 15 buttons 
application and 5 to create win32exe with py2exe, so I'm happy, cause I 
don't even know python)
http://boa-constructor.sourceforge.net/

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


Re: Self reordering list in Python

2005-09-16 Thread Fredrik Lundh
Terry Hancock wrote:

> This is actually the use-case for an "LRU cache"="least recently used
> cache", which is probably already implemented in Python somewhere (or
> even as a fast extension).  I'd do a google search for it.

reposted, in case there are more people who cannot be bothered
to read other replies before posting:

http://www.python.org/pypi/lrucache/0.2

(it's a straight-forward and rather flexible implementation, which uses
a dictionary to quickly find existing objects, and a heap to keep track
of access times.  if you have more control over the stuff that goes into
the cache, you can strip things down to 10-20 lines of code and code
it in about the same time it took me to write this post)

 



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


Re: No newline using printf

2005-09-16 Thread Gary Herron
Samuel wrote:

>Hello,
>
>I have been searching for an answer for almost two hours now and have
>not found an answer. I want this code:
>
>for i in range(3):
>  print i   # or whatever
>
>To produce this output:
>012
>
>How can I print a word without appending a newline character? Appending
>a "," to the print statement only substitutes the newline for a space,
>which is not what I am looking for.
>
>Any hints?
>
>Thanks,
>-Samuel
>
>  
>
The solution is to take over full control of the output with 
sys.stdout.write.

Use '%1d' % i to convert your number into a single character string.

Use sys.stdout.write to send exactly the characters you want to sys.stdout.

Thus:  sys.stdout.write('%1d' % i) should do what you want.

Dr Gary Herron
Digipen Institute of Technology

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


Re: Wrapper module for Linux shared lib

2005-09-16 Thread Michele Petrazzo
Ernesto wrote:
> What's the best resource for finding out how to write a wrapper
> module for a shared library file *.so* in Linux?
> 

If you have only the .so file, not the source, you can use ctypes.
I work always with it without problems.

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


Odd behavior with os.fork and time.sleep

2005-09-16 Thread Yin
I am writing a script that monitors a child process.  If the child
process dies on its own, then the parent continues on.  If the child
process is still alive after a timeout period, the parent will kill the
child process.  Enclosed is a snippet of the code I have written.  For
some reason, unless I put in two time.sleep(4) commands in the parent,
the process will not sleep.  Am I forgetting something?  Any reasons
for this strange behavior?

Linux Fedora Core 4
Python 2.4.1

Thanks.

#!/usr/bin/env python

import os, time
import signal
import sys

def chldhandler(signum, stackframe):
  while 1:
try:
  result = os.waitpid(-1, os.WNOHANG)
except:
  break
print "Reaped child process %s" % result[0]
  signal.signal(signal.SIGCHLD, chldhandler)

signal.signal(signal.SIGCHLD, chldhandler)

pid = os.fork()
if pid:  # parent
  print "Parent.  Child is %d" % pid

  try:
os.kill(pid, 0)
print "Killed child"
os.kill(pid, signal.SIGKILL)
  except OSError, err:
print "Child is dead"

  print "In parent again"
  time.sleep(4)
  time.sleep(4)

  print "Parent awake"
else:  # child
  print "Child sleeping 5 seconds..."
  time.sleep(5)
  print "Child awake"

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


Re: Looking for a database. Sugestions?

2005-09-16 Thread Ed Hotchkiss
Awesome, I'm checking both out right now, trying to get it setup - thanks.
On 9/16/05, Christoph Haas <[EMAIL PROTECTED]> wrote:
On Thu, Sep 15, 2005 at 11:00:46PM +0200, ionel wrote:> I'm looking for a thread-safe database.
> Preferably an embedded, sql database.>> What are the best choices in terms of speed ?Sqlite may be a good choice. It doesn't have network overhead, operateson simple files on the disk (nothing to configure) and is often faster
than MySQL & Co.RegardsChristoph--~~~".signature" [Modified] 3 lines --100%--3,41 All--
http://mail.python.org/mailman/listinfo/python-list-- edward hotchkiss 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: List of integers & L.I.S.

2005-09-16 Thread n00m
Anton,

it simply does not work! Try supernumbers([2,1,4,5,3]).

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


distutils problem

2005-09-16 Thread Michele Petrazzo
I create a setup script for distribute my application, but I have a
problems with the exe package.

When I create the package with:
python setup.py win bdist_wininst

and execute if after, it'll copy the data file specified by data_files
directive into the C:\python23\python23\lib\site-package\my_lib, so not
on the right site-package directory (python23 + python23).
Otherwise if I use the same script from the source (python setup.py
install) it work well, so it copy on C:\python23\lib\site-package\my_lib
or /usr/lib/python23/site-package/ on linux. (this for python 2.3, of
course :) )

My script:

dataToCopy = glob.glob("FreeImagePy/data/*.*")
if sys.platform == 'win32': prefix = os.path.join(sys.prefix, 
"Lib/site-packages/FreeImagePy")
else: prefix = os.path.join(sys.exec_prefix, "lib/python%s" % 
sys.version[:3], "site-packages/FreeImagePy")
setup( 
 packages=['FreeImagePy', 'FreeImagePy.test', 'FreeImagePy.tools'],
 data_files=[ (prefix, dataToCopy),],
)


How can I modify my script, for make it work with exe package?

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


Problem with Help when using numarray

2005-09-16 Thread Colin J. Williams
Python advertises some basic service:

C:\Python24>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>>

With numarray, help gives unhelpful responses:

import numarray.numarraycore as _n
c= _n.array((1, 2))
print 'rank Value:', c.rank
print 'c.rank Help:', help(c.rank)

Results:
rank Value: 1
c.rank Help:Help on int object:

class int(object)
  |  int(x[, base]) -> integer
  |
  |  Convert a string or number to an integer, if possible.  A floating 
point
  |  argument will be truncated towards zero (this does not include a 
.  etc etc.

Another example:

 >>> help(c.copy)

 >>> help(c.copy)
Traceback (most recent call last):
   File "", line 1, in ?
   File "site.py", line 328, in __call__
 return pydoc.help(*args, **kwds)
   File "C:\Python24\lib\pydoc.py", line 1647, in __call__
 self.help(request)
   File "C:\Python24\lib\pydoc.py", line 1691, in help
 else: doc(request, 'Help on %s:')
   File "C:\Python24\lib\pydoc.py", line 1475, in doc
 pager(title % desc + '\n\n' + text.document(object, name))
   File "C:\Python24\lib\pydoc.py", line 297, in document
 if inspect.isroutine(object): return self.docroutine(*args)
   File "C:\Python24\lib\pydoc.py", line 1226, in docroutine
 if object.im_self:
   File "C:\Python24\Lib\site-packages\numarray\generic.py", line 537, 
in __nonzero__
 raise RuntimeError("An array doesn't make sense as a truth value. 
Use any(a) or all(a).")
RuntimeError: An array doesn't make sense as a truth value.  Use any(a) 
or all(a).
 >>>

c.copy.__doc_ does return the __doc__ string OK:
 >>> c.copy.__doc__
'Returns a native byte order copy of the array.'
 >>>

But c.rank.__doc__ does not:
 >>> c.rank.__doc__
'int(x[, base]) -> integer\n\nConvert a string or number to an integer, 
if possible.  A floating point\nargument will be truncated towards zero 
(this does not include a string\nrepresentation of a floating point 
number!)  When converting a string, use\nthe optional base.  It is an 
error to supply a base when converting a\nnon-string. If the argument is 
outside the integer range a long object\nwill be returned instead.'
 >>>

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


Re: Accessing shared library file...

2005-09-16 Thread Thomas Jollans
Ernesto wrote:
> The .dll file is a shared library file that is associated with a
> programming interface for a semi-conductor chip.  The chip drivers come
> in two different flavors:  One is a .dll (for Windows) and the other is
> a shared library file for Linux.  The name of the Linux file is
> "nameofFile.so.0.4.5"  The company that makes these drivers (FTDI) says
> that the API's for both OS's are practically the same (except you
> obviously cannot use WIN32 functions when running on Linux).  I wish I
> knew more about Linux drivers...
> 

on linux, usually *all* library files are stored in dedicated 
directories like /lib /usr/lib or /usr/local/lib you can then acces the 
lib just by 'nameofFile'. example: if you have 
'/usr/lib/libqt-mt.so.3.3.4' installed, you only need to tell the 
compiler to use the library 'qt-mt'. You can create a seperate lib 
directory for your project, but you probably need to set some 
environment variables for that. I believe pyrex is your friend when 
dealing with C libraries in python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with Help when using numarray

2005-09-16 Thread Robert Kern
Colin J. Williams wrote:
> Python advertises some basic service:
> 
> C:\Python24>python
> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on 
> win32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>>
> 
> With numarray, help gives unhelpful responses:
> 
> import numarray.numarraycore as _n
> c= _n.array((1, 2))
> print 'rank Value:', c.rank
> print 'c.rank Help:', help(c.rank)
> 
> Results:
> rank Value: 1
> c.rank Help:Help on int object:
> 
> class int(object)
>   |  int(x[, base]) -> integer
>   |
>   |  Convert a string or number to an integer, if possible.  A floating 
> point
>   |  argument will be truncated towards zero (this does not include a 
> .  etc etc.

c.rank is an integer, not a method. It doesn't have a docstring. It
can't have a docstring.

> Another example:
> 
>  >>> help(c.copy)
> 
>  >>> help(c.copy)
> Traceback (most recent call last):
>File "", line 1, in ?
>File "site.py", line 328, in __call__
>  return pydoc.help(*args, **kwds)
>File "C:\Python24\lib\pydoc.py", line 1647, in __call__
>  self.help(request)
>File "C:\Python24\lib\pydoc.py", line 1691, in help
>  else: doc(request, 'Help on %s:')
>File "C:\Python24\lib\pydoc.py", line 1475, in doc
>  pager(title % desc + '\n\n' + text.document(object, name))
>File "C:\Python24\lib\pydoc.py", line 297, in document
>  if inspect.isroutine(object): return self.docroutine(*args)
>File "C:\Python24\lib\pydoc.py", line 1226, in docroutine
>  if object.im_self:
>File "C:\Python24\Lib\site-packages\numarray\generic.py", line 537, 
> in __nonzero__
>  raise RuntimeError("An array doesn't make sense as a truth value. 
> Use any(a) or all(a).")
> RuntimeError: An array doesn't make sense as a truth value.  Use any(a) 
> or all(a).
>  >>>

c.copy.im_self is c . pydoc is trying to use it as a truth value (I'm
not sure why, you'll have to take it up with pydoc, not numarray), but
numarray has made a decision not to implement __nonzero__.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: Problem with Help when using numarray

2005-09-16 Thread Fredrik Lundh
Colin J. Williams wrote:

> With numarray, help gives unhelpful responses:
>
> import numarray.numarraycore as _n
> c= _n.array((1, 2))
> print 'rank Value:', c.rank
> print 'c.rank Help:', help(c.rank)

c.rank returns a Python integer object.

if you pass in an object to help(), help figures out what that object is,
and tries to tell you what you can do with that object.

the integer itself has no idea whatsoever from where it came; it's just
an integer, and that's all Python knows about it.

cf.

>>> import sys
>>> help(sys)
Help on built-in module sys:
NAME
sys

>>> help(sys.stdout)
Help on file object:
class file(object)
 |  file(name[, mode[, buffering]]) -> file object

>>> help(sys.stdout.softspace)
Help on int object:
class int(object)

>>> help(sys.stdout.softspace.__int__)
Help on method-wrapper object:
__int__ = class method-wrapper(object)

and so on.

 



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


Re: Why doesn't IDLE editor windows have horizontal scrollbars?

2005-09-16 Thread bruno modulix
chuck wrote:
> The browser windows do.  Why not the editor windows?
> 
> I hate to complain but is there any way to get IDLE to run in more of
> an MDI mode?  Having the floating windows everywhere is rather
> confusing to me.
> 

IDLE is open source, so you may want to consider contributing to it !-)
More seriously, I dont think IDLE is intended to be a real professional
IDE - anyway, I would not use it as such.

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


influence platorm during install -end user question

2005-09-16 Thread Peter Hartmann
How do I influence the platform type during install?  Could you look
at this and tell me what I'm doing wrong?  It's still using
information from get_platform instead of using my preference.

[EMAIL PROTECTED] pyosd-0.2.14]# python setup.py install
--install-purelib=lib.linux=i686-2.3 
--install-lib=/usr/lib/python2.3/site-packages
running install
running build
running build_py
running build_ext
running install_lib
creating /usr/lib/python2.3/site-packages/pyosd
copying build/lib.linux-x86_64-2.3/pyosd/__init__.py ->
/usr/lib/python2.3/site-packages/pyosd
copying build/lib.linux-x86_64-2.3/pyosd/daemon.py ->
/usr/lib/python2.3/site-packages/pyosd
byte-compiling /usr/lib/python2.3/site-packages/pyosd/__init__.py to
__init__.pyc
byte-compiling /usr/lib/python2.3/site-packages/pyosd/daemon.py to daemon.pyc


On 9/15/05, Peter Hartmann <[EMAIL PROTECTED]> wrote:
> Hello,
> I could really use some help.  I'm trying to install a python program
> on centos4 x86_64.  When I run 'python setup.py' it ends up in
> /usr/lib64/python2.3/site-packages/  instead of
> /usr/lib/python2.3/site-packages.  It's a problem because the program
> I'm trying to install is a dependency for something that is only
> 32bit.  How can I specify a 32bit install?What I've tried so far:
> When I try 'python setup.py build --build-lib
> /usr/lib/python2.3/site-packages'  and  'python setup.py install
> --install-lib /usr/lib/python2.3/site-packages', it installs the 64bit
> version into the 32bit library.Can anyone help me?
> 
> Thanks,
> Peter
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Run VPython on FC3

2005-09-16 Thread York
Hi everybody,

I am trying to run VPython on FC3. The installation was fine. But when I 
"import visual", an error occurs:

"""
 >>> import visual
Traceback (most recent call last):
   File "", line 1, in ?
   File "/usr/lib/python2.3/site-packages/visual/__init__.py", line 15, in ?
 import array_backend
   File "/usr/lib/python2.3/site-packages/visual/array_backend.py", line 
1, in ?
 import cvisual
ImportError: libgtkgl.so.4: cannot open shared object file: No such file 
or directory
 >>>
"""

It seems Python cannot open/find the file "libgtkgl.so.4", but it 
definitely lies in the lib directory:

/usr/local/lib/libgtkgl.so.4.0.0
/usr/local/lib/libgtkgl.so.4

Does anybody know a solution for this problem?

Thanks very much,

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


Re: MySQLdb UPDATE does nothing

2005-09-16 Thread Steve Horsley
Magnus Lycka wrote:
> Steve Horsley wrote:
>> Or, as I found out yesterday, cursor.execute('commit') afterwards.
> 
> The correct way to do it is to close the cursor object, and
> then do "db.commit()". Don't rely on a cursor object to work
> across transaction boundries!
> 
> See e.g. www.thinkware.se/epc2004db/epc04_mly_db.pdf and
> http://www.thinkware.se/epc2004db/dbapitest.py

Good reference, thank you.

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


Re: Odd behavior with os.fork and time.sleep

2005-09-16 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 "Yin" <[EMAIL PROTECTED]> wrote:
> I am writing a script that monitors a child process.  If the child
> process dies on its own, then the parent continues on.  If the child
> process is still alive after a timeout period, the parent will kill the
> child process.  Enclosed is a snippet of the code I have written.  For
> some reason, unless I put in two time.sleep(4) commands in the parent,
> the process will not sleep.  Am I forgetting something?  Any reasons
> for this strange behavior?

...
> signal.signal(signal.SIGCHLD, chldhandler)

If you can possibly revise your design to avoid the need
for this, by all means do so.

The SIGCHLD signal interrupts functions like sleep(), and
that's what you're seeing:  the parent process didn't return
to its sleep after handling the signal.  What's worse, it
affects other functions in a similar way, such as I/O.  Try
to read some input from the terminal, instead if sleeping,
and you should crash with an EINTR error.  Makes it harder
to write a reliable program, when you're inviting such trouble.

So far this is a low level UNIX issue that isn't peculiar to
Python, but Python adds to the difficulties just in the general
awkwardness of signal handling in an interpreted language,
where handlers may execute somewhat later than you would expect
from experience with lower level languages.  And then if you
decide to add threads to the mix, there are even more issues
as signals may be delivered to one thread and handled in another,
etc.

If you're dispatching on I/O, for example with select, you
can use an otherwise unused pipe to notice the child fork's
exit -- close the parent's write end right away, and then
when the pipe becomes readable it must be because it closed
on child exit.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI Problem on MS IIS 5.0 - Trying to access files on other machines

2005-09-16 Thread Pat [MSFT]
Don't change the account IIS is running under - that is a pretty big 
security issue waiting to happen.

Change the authentication model for the web site to Basic, then logon as 
you.  That will cause any execution to be in the security context you are 
expecting.

Pat

"paulp" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Based on your comment, I finally realized that IIS is running under the
> IUSR_ account.  So I changed the priveleges on this account on my test IIS
> server as related elsewhere in this note.  So now I'm getting a different
> error.
>
> 1326, "LogonUser", "Logon failure: unknown user name or bad password"
>
> It's progress of a sort.
>
> My test box is running IIS, and I set up a local test account (PYTHONTEST)
> on my primary box.  This is the account I'm trying to hook into at the
> moment.
>
> Any thoughts on this?
>
> Many thanks for your help.
>
> Paul
>
>
> "Pat [MSFT]" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Set the site to be Basic Authentication and login as you.  I suspect that
>> the .exe is either running as IWAM/IUSER (i.e. GUEST) or you are running
>> into a double hop issue.
>>
>>
>> Pat
>>
>> "paulp" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>> > Greetings,
>> >
>> > I'm working on a CGI program that will run under MS IIS 5.0 and will
>> > browse folders on three other machines, building HTML pages that will
>> > provide links to these folders.
>> >
>> > Essentially, the CGI will connect to each machine in turn, doing the
>> > FindFirst/FindNext process based on the current criteria.  It will
>> > select certain files/folders, and build an HTML page as it goes.
>> >
>> > The premise is fine.  If I run the program from the command line, it
>> > seems to work fine and I get my HTML code out.  I can copy the code
>> > into a separate file, open it in the browser, and all appears right
>> > with the world.
>> >
>> > However, when I try to run the CGI from the browser itself, I get all
>> > kinds of problems.  The first one I got was a 1312, "A specified logon
>> > session does not exist.  It may have already been terminated."  After
>> > doing some searching, I began to investigate impersonation of a logged
>> > on user.  This produces a different error: 1314, "A required privilege
>> > is not held by the client."
>> >
>> > The code involved and the output I'm getting follows:
>> >
>> > -BEGIN--
>> > class Impersonate:
>> >def __init__(self, login, password ):
>> >self.domain = '4Q9ND21'
>> >self.login = login
>> >self.password = password
>> >self.handel = None
>> >def logon(self):
>> >tracelist.append("Impersonate logon step 0")
>> >win32security.RevertToSelf()# terminates impersonation
>> >tracelist.append("Impersonate logon step 1")
>> >self.handel = win32security.LogonUser( self.login, self.domain,
>> > self.password, win32con.LOGON32_LOGON_INTERACTIVE,
>> > win32con.LOGON32_PROVIDER_DEFAULT )
>> >tracelist.append("Impersonate logon step 2")
>> >win32security.ImpersonateLoggedOnUser(self.handel)
>> >tracelist.append("Impersonate logon step complete")
>> >def logoff(self):
>> >win32security.RevertToSelf()# terminates impersonation
>> >if self.handel != None:
>> >self.handel.Close() # guarantee cleanup
>> > --END---
>> >
>> > and I execute this code with the following
>> >
>> > -BEGIN--
>> >impersonate = Impersonate( 'PYTHONTEST', 'PYTHONTEST' )
>> >try:
>> >tracelist.append("about to attempt the IMPERSONATE")
>> >impersonate.logon()
>> >tracelist.append("impersonate did NOT throw exception")
>> >b=AdjustPrivilege(SE_SYSTEM_PROFILE_NAME)
>> >b=AdjustPrivilege(SE_TCB_NAME)
>> >try:
>> >tracelist.append("win32api.GetUserName = " +
>> > win32api.GetUserName() )
>> ># print win32api.GetUserName() #show you're someone else
>> >finally:
>> >impersonate.logoff() #return to normal
>> >except:
>> >a = "Impersonate Logon Error: %s %s" % (sys.exc_type,
>> > sys.exc_value)
>> >tracelist.append(a)
>> ># print sys.exc_type, sys.exc_value
>> > --END---
>> >
>> > When I run this code, my tracelist comes out with
>> >
>> > -BEGIN--
>> > 2005-09-15 16:43:37
>> > about to attempt the IMPERSONATE
>> > Impersonate logon step 0
>> > Impersonate logon step 1
>> > Impersonate Logon Error: pywintypes.error (1314, 'LogonUser', 'A
> required
>> > privilege is not held by the client.')
>> > --END---
>> >
>> >
>> > I'm coding this in Python 2.4 and the Windows extensions.  I have a
>> > number of other CGI programs in Python running under IIS that work
>> > correctly, but those only do database accesses.  This one I'm trying to
>> > put together is the first one to actually do f

  1   2   >