Re: newbie: dictionary - howto get key value

2005-03-13 Thread Bengt Richter
On Mon, 14 Mar 2005 05:02:25 GMT, Joal Heagney <[EMAIL PROTECTED]> wrote:

>Tim Roberts wrote:
>> "G. Völkl" <[EMAIL PROTECTED]> wrote:
>> 
>>>I use a dictionary:
>>>
>>>phone = {'mike':10,'sue':8,'john':3}
>>>
>>>phone['mike']   --> 10
>>>
>>>I want to know who has number 3?
>>>
>>>3 -->  'john'
>>>
>>>How to get it in the python way ?
>> 
>> 
>> If you need to do this a lot, just keep two dictionaries, where the keys in
>> each are the values in the other.
>> 
>>   reversephone = dict( zip( phone.values(), phone.keys() ) )
>
>(Been away from python for a while, so forgive me if I'm asking a silly 
>question.)
>Does python guarantee that the lists given by phone.values() and 
>phone.keys() are in mutual order? Or is it possible that python will 
>return the lists in different orders for .values() and .keys()?
>
Good question. I don't know. I hope so, but I would tend to write dict((v,k) 
for k,v in phone.items())
to do the equivalent, but note that it only works if everyone has a different 
phone number.

 >>> dict((v,k) for k,v in {'sue':3, 'bob':4}.items())
 {3: 'sue', 4: 'bob'}
 >>> dict((v,k) for k,v in {'sue':3, 'bob':4, 'mike':4}.items())
 {3: 'sue', 4: 'bob'}

Surprised at who got left out?
 >>> {'sue':3, 'bob':4, 'mike':4}.items()
 [('sue', 3), ('mike', 4), ('bob', 4)]

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


Re: [Python-Dev] RELEASED Python 2.4.1, release candidate 1

2005-03-13 Thread "Martin v. Löwis"
Brian van den Broek wrote:
A comment about the msi process: even though I set it to install to a 
different directory, 2.4.1c1 clobbered my 2.4 install. I remember 
reading something somewhere such that I expected this, but a quick 
glance at the obvious places for the 2.4.1c1 doesn't produce anything, 
nor does the install process itself explain that this will happen.

Perhaps its not a big deal, but I'd prefer the install process to inform 
me if it detected a previous install and intended to remove it.
Having both 2.4 and 2.4.1 on the same machine is not supported, as there
is only one python24.dll - atleast if this is an "allusers" installation.
I'll see what I can do wrt. telling the user, but I may not find the
time; contributions are welcome.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] RELEASED Python 2.4.1, release candidate 1

2005-03-13 Thread Brian van den Broek
Martin v. Löwis said unto the world upon 2005-03-10 20:55:
Anthony Baxter wrote:
On behalf of the Python development team and the Python community, I'm
happy to announce the release of Python 2.4.1 (release candidate 1).

I'd like to encourage feedback on whether the Windows installer works
for people. It replaces the VBScript part in the MSI package with native
code, which ought to drop the dependency on VBScript, but might
introduce new incompatibilities.
Regards,
Martin
Seems to have successfully installed for me on Windows Me.
A comment about the msi process: even though I set it to install to a 
different directory, 2.4.1c1 clobbered my 2.4 install. I remember 
reading something somewhere such that I expected this, but a quick 
glance at the obvious places for the 2.4.1c1 doesn't produce anything, 
nor does the install process itself explain that this will happen.

Perhaps its not a big deal, but I'd prefer the install process to 
inform me if it detected a previous install and intended to remove it.

Best to all,
Brian vdB
--
http://mail.python.org/mailman/listinfo/python-list


html parsing

2005-03-13 Thread Suchitra



Hi all,
    
Please help me in parsing  the html document 
and extract the http links .
 
Thanks in advance!!1
 
Suchitra
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Who Knows of a Good Computational Physics Textbook?

2005-03-13 Thread Sean Richards

This may be of interest

http://farside.ph.utexas.edu/teaching/329/lectures/lectures.html

Cheers,  Sean

-- 
"Hver sin smak", sa vintapperen, han drakk mens de andre sloss."
-- 
http://mail.python.org/mailman/listinfo/python-list


some information

2005-03-13 Thread Sandeep Avinash Gohad

Hi,I want to know weather python conducts any certification exams like the other programming languages - 
Microsoft (MCP,MCSD)
Sun  (sun certification)

Regards,
Sandeep   




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

Re: SimpleHTTPRequestHandler handling long lasting requests problem

2005-03-13 Thread Andy Leszczynski
Steve Holden wrote:
Andy Leszczynski wrote:
Sorry for questioning Python :-) - it turned out that this is a 
problem with Mozilla. For some reason it holds up with opening second 
connection to given host until the previous one is completed. 
Interestingly enough, IE works better with Python multi threaded 
server in that regard.

Thx, A.

Try switching keepalives off, or falling back to HTTP 1.0 - ironically 
it may be the attempt to use the same connection for both pieces of 
content that holds things up.

regards
 Steve
I tested it before and it did not work either. Have to try  HTTP 1.0 thouh.
Thanks, A.
--
http://mail.python.org/mailman/listinfo/python-list


A Font Dialog (Tkinter)

2005-03-13 Thread Harlin Seritt
Is there a way to call up the Font dialog box (at least in the Windows
API) from Tkinter or another module?

thanks,

Harlin Seritt

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


Re: issues installing readine-1.12 on WinXP

2005-03-13 Thread Michele Simionato
Well, this is ugly as the sin but it seems to work, at least for the
moment:

  vk = VkKeyScan(ord(char))
  if vk == -1: # ugly fix for backtips
vk = 96

I will write to Gary Bishop to point out this issue with the Italian
keyboard and see if he has some decent
solution.

  Michele Simonato

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


Re: Unimport module

2005-03-13 Thread Chmouel Boudjnah

Terry Reedy wrote:
Yes, Python's import mechanism assumes that sys.path is relatively static, 
or grow only.  I not sure what 'reload Module' would do after the first 
loop.
it does work using like that :
if sys.modules.has_key("Module"):
reload(Module)
else:
import Module
i think it's kind of cleaner solution.
which after it does works fine. But my question is what's happenning in 
the internals, does it free the memory of Module to do a sys.modules.pop 
A Python implementation *may* 'free' an object anytime after the last 
reference to the object disappears.  Whether the name Module and the slot 
in sys.modules are the only two references depends, I believe, on both the 
code in the module and the code the uses it.  sys.getrefcount() can help 
answer this.
ah ok, thanks to make this thing clear, do you have any pointer how to 
debug/watch the python internals ?

Cheers, Chmouel.
--
Chmouel Boudjnah -- Squiz.net -- http://www.squiz.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Itertools wishlists

2005-03-13 Thread Raymond Hettinger
[bearophile]
> This was my suggestion for a possible flatten():
>
> flatten(sequence, level=-1, tuples=True, strings=False, safe=False)
> - tuples=True then it flattens tuples too.
> - strings=True then it flattens strings with len(s)>1 too.
> - safe if True it cheeks (with something like an iterative isrecursive)
> for
>   recursive references inside the sequence.
> - level allows to specify the mapping level:
>   level=0 no flattening.
>   level=1 the flattening is applied to the first level only.
>   level=2 the flattening is applied to the first and second level only.
>   level=m where m>=actual depth. This is as level=-1.
>   Etc.
>   And like in the indexing of lists:
>   level=-1 or None (default) means the flattening is applied up to the
> leaves.
>   level=-2 flattens up to pre-leaves.
>   Etc.

My suggestion is to stop smoking Crack and check into rehab ;-)

Each one of the options listed is a reason that flatten() shouldn't be an
itertool.  It fails tests of obviousness, learnability, complexity of
implementation, and simplicity of API.  The options also suggest that the
abstraction is not as basic or universal as we would hope.



> >And, there is also the issue of use cases. It appears to be much more
> fun to toy around with developing flatten() recipes than it is to work
> on applications that require it.<
>
> It's not easy to define "require" because usually there are many ways
> to solve every problem.

Perhaps "require" was the wrong word.  The issue is that appear to be very few
real situations where flatten() would be the tool of choice.




> There are two situations that I've found can make use of the
> flatten/partition, but you can probably find better ways to do the same
> thing (and I can appreciate suggestions):
>
> 1)
> The function f returns two values, but you need a flat list as result:
> def f(x): return x, x**2
> r = flatten( f(i) for i in range(10) )
> print r

This is not a good way to store the function's results.  It unnecessarily throws
away structure.  Unless creating some type of serialization function, it likely
the wrong thing to do.  Also, the example appears to be contrived and not
representative of real code.  If there is actually a need to treat multiple
return values as being undifferentiated, then your alternate solution with
extend() is the most appropriate solution.


> 2)
> A file with columns of numbers separated by a space/tab:
. . .
> ll = open("namefile").read().splitlines()
> r = [map(float, l.split()) for l in ll]

If you need that to be flattened one level, it would have been better to do all
the splits at once:

   # split on tabs, spaces, and newlines
   r = map(float, open('namefile').read().split())

Generalizing the two results, it may be fair to say that the desire to flatten
is a code smell indicating that structure is being unnecessarily destroyed or
that earlier processing introduced unwanted structure.  Let the data guide the
programming.



Raymond Hettinger


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


Re: how to delete the close button (the X on the right most corner of the window) on a window

2005-03-13 Thread Harlin Seritt
What GUI toolkit are you using? I think this is the point Jeremy is
making.

Harlin Seritt

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


Re: urllib's functionality with urllib2

2005-03-13 Thread Harlin Seritt
Is there any reason why you can't import both?

import urllib as u
import urllib2 as uu

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


Re: Searching for a ComboBox for Tkinter?

2005-03-13 Thread Harlin Seritt
ahh Frame! I didn't even think of extending Frame. I kept wondering how
I could instead extend entry and listbox... thanks for the pointer.
Yeah I know there are others out there, I just wanted to create one
from tkinter widgets and keep the constructor as close to other tkinter
widgets as possible. I notice that when you use Pmw you have different
option names and methods that are a bit inconsistent (not too hard to
remember though--it's not a criticism of Pmw or Tix). I am very
narrow-minded. :-)

As far as the other lists/wiki, I will be looking at them.

Thanks,

Harlin

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


Re: Searching for a ComboBox for Tkinter?

2005-03-13 Thread Harlin Seritt
Thanks nirinA... I've played with that one before. I'm not a big fan of
Pmw or Tix so much I guess although when it gets down to it, those
'extra' toolkits are probably more functional.

Cheers,

Harlin

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


Re: newbie: dictionary - howto get key value

2005-03-13 Thread Joal Heagney
Tim Roberts wrote:
"G. Völkl" <[EMAIL PROTECTED]> wrote:
I use a dictionary:
phone = {'mike':10,'sue':8,'john':3}
phone['mike']   --> 10
I want to know who has number 3?
3 -->  'john'
How to get it in the python way ?

If you need to do this a lot, just keep two dictionaries, where the keys in
each are the values in the other.
  reversephone = dict( zip( phone.values(), phone.keys() ) )
(Been away from python for a while, so forgive me if I'm asking a silly 
question.)
Does python guarantee that the lists given by phone.values() and 
phone.keys() are in mutual order? Or is it possible that python will 
return the lists in different orders for .values() and .keys()?

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


Re: Linux Multimedia System

2005-03-13 Thread Lucas Raab
Marek Franke wrote:
Just wondering how you're supporting the Xbox controller. I bought a
cable and driver a few months back to hook up to my computer. Are you
using a Python alternative??
No, I rebuild the connector to USB and loaded the xpad-driver (Linux),
that's all. Just the same with the SNES pads (parallel-support, not USB).
The xpad-driver loads automatically on startup, for the rest I have written
a little script:
#!/bin/sh
#echo Loading analog joystick support
#modprobe gameport
#modprobe analog
#modprobe ns558
#modprobe joydev
echo Loading parallel port support io=0x378 irq=7
modprobe parport_pc io=0x378 irq=7
echo Loading SNES gamepad support
modprobe gamecon map=0,1,1
#echo Loading 2 Button Mustisystem gamepad support
#modprobe db9 dev=0,2
After that I will get some new devices /dev/input/js* and they work fine
with python/pygame.
Marek
Huh. Interesting.
--
--
Lucas Raab
lvraab located at earthlink.net
dotpyFE located at gmail.com
AIM:Phoenix11890
MSN:[EMAIL PROTECTED]
IRC:lvraab
ICQ:324767918
Yahoo:  Phoenix11890
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unimport module

2005-03-13 Thread Terry Reedy

"Chmouel Boudjnah" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> dir = listdir('/path/')
> for i in dir:
> sys.path.append('/path/' + i "/")
> import Module
> doStuff()
> sys.path.remove('/path/' + i "/")
>
> it's obviously not working since it get only the first import Module 
> while the others doent get replaced, the only solution for me was too :
>
> sys.modules.pop('Module')

Yes, Python's import mechanism assumes that sys.path is relatively static, 
or grow only.  I not sure what 'reload Module' would do after the first 
loop.

> which after it does works fine. But my question is what's happenning in 
> the internals, does it free the memory of Module to do a sys.modules.pop 
> ?

A Python implementation *may* 'free' an object anytime after the last 
reference to the object disappears.  Whether the name Module and the slot 
in sys.modules are the only two references depends, I believe, on both the 
code in the module and the code the uses it.  sys.getrefcount() can help 
answer this.

Terry J. Reedy



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


Re: Linux Multimedia System

2005-03-13 Thread Marek Franke

> Freevo is pure python already ;)
> 
> Greetings, Roland

OK, but it's more the 'thrill' to create something own, not the matter which
language we/they use. And even there is only a little image-viewer and  a
little CD-player, it's fun (for me) to use it already on my TV.

Marek

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


Re: Linux Multimedia System

2005-03-13 Thread Marek Franke

> Just wondering how you're supporting the Xbox controller. I bought a
> cable and driver a few months back to hook up to my computer. Are you
> using a Python alternative??
> 
No, I rebuild the connector to USB and loaded the xpad-driver (Linux),
that's all. Just the same with the SNES pads (parallel-support, not USB).
The xpad-driver loads automatically on startup, for the rest I have written
a little script:

#!/bin/sh
#echo Loading analog joystick support
#modprobe gameport
#modprobe analog
#modprobe ns558
#modprobe joydev
echo Loading parallel port support io=0x378 irq=7
modprobe parport_pc io=0x378 irq=7
echo Loading SNES gamepad support
modprobe gamecon map=0,1,1
#echo Loading 2 Button Mustisystem gamepad support
#modprobe db9 dev=0,2

After that I will get some new devices /dev/input/js* and they work fine
with python/pygame.

Marek

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


Re: Python-list Digest, Vol 18, Issue 208

2005-03-13 Thread Charles Hartman
I know this isnt that big of a problem,
but i cannot think of one reason why they would not allow numbers 
preceded with a 0 to have a number
higher then a 7 in them...
And it seems very inconsistant to me...

Is there a reason for this?
I *love* questions I can answer! Answer: because that's how you tell 
Python you're entering an octal number. (Parallel to 0x for 
hexadecimals.) So beware of 010, which isn't the number of fingers you 
presumably have, unless you don't count the thumbs.

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


Unimport module

2005-03-13 Thread Chmouel Boudjnah
Hi,
I have some code like that to do kind of plugins load :
dir = listdir('/path/')
for i in dir:
sys.path.append('/path/' + i "/")
import Module
doStuff()
sys.path.remove('/path/' + i "/")
it's obviously not working since it get only the first import Module 
while the others doent get replaced, the only solution for me was too :

sys.modules.pop('Module')
which after it does works fine. But my question is what's happenning in 
the internals, does it free the memory of Module to do a sys.modules.pop ?

Cheers, Chmouel.
PS: Please Mail-Copy-To: i am not subscribed to the list
--
http://mail.python.org/mailman/listinfo/python-list


Re: Who Knows of a Good Computational Physics Textbook?

2005-03-13 Thread beliavsky
There is some info on teaching computational physics at Rubin Landau's
site http://www.physics.orst.edu/~rubin/ .

Springer recently published the book "Python Scripting for
Computational Science" by Hans P. Langtangen .

Searching "computational physics" at Amazon returns some relevant
books.

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


[OT] Who Knows of a Good Computational Physics Textbook?

2005-03-13 Thread Dan Sommers
Hi,

I posted this to sci.physics and alt.sci.physics and got nowhere;
perhaps the much more friendly and helpful crowd here can help me.  I
know that a lot of pythonistas are, in fact, scientists.

I am a non-traditional, undergraduate physics (and math) student with
20+ years of professional software development behind me.

Does anyone have any recommendations for a good book from which my
professor and I can construct a one-semester independent study course on
computational physics?

Since this will be in the physics department at school, we are more
concerned with the direct applicability of the material to physics
rather than an extensive study of numerical methods from a strictly
mathematical or computer science point of view.  Also, while I am not
afraid to learn yet another computer language, a steep learning curve in
that area would probably end up detracting from the physics aspects of
the course.

If you know of some place I can go in order to find the right questions
to ask (and possibly the right place to ask them!), then don't be afraid
to let me know that, too.

Thanks,
Dan

-- 
Dan Sommers

Îâ à Îâ à c = 1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert python to exe

2005-03-13 Thread [EMAIL PROTECTED]
Thanks.

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


Re: Adapting code to multiple platforms

2005-03-13 Thread Peter Hansen
Paul Watson wrote:
"Peter Hansen" <[EMAIL PROTECTED]> wrote:
Simon John wrote:
You could try import win32api and checking for an exception ;-)
(Winky noted)  Just in case anyone thinks that last is a
useful idea, keep in mind that win32api is not installed
(with the standard distribution) but must be installed
with a separate download of the pywin32 package by Mark
Hammond.
How about try: import msvcrt 
Sure, that works, but it would make for pretty
inscrutable code if you were doing this just to
check whether you were on Windows, and not because
you really intended to use the msvcrt module.
sys.platform exists for a good reason.  Use it!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Convert python to exe

2005-03-13 Thread Stephen Thorne
On 13 Mar 2005 14:31:53 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hi
> 
> I have a python script under linux, I wonder if I can be converted to
> an executable or not?

Yes, you can use cx_Freeze.

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


Re: Bug?

2005-03-13 Thread Artie Gold
[EMAIL PROTECTED] wrote:
Hello
Ive recently found that you cannot type anything over 7 into a number that is 
preceded with a 0.
ex:
 >>> 01
1
>>> 07
7
>>> 08
SyntaxError: invalid token
>>> 011
9
>>> 017
15
>>> 077
63
>>> 078
SyntaxError: invalid token
I know this isnt that big of a problem,
but i cannot think of one reason why they would not allow numbers preceded with 
a 0 to have a number
higher then a 7 in them...
And it seems very inconsistant to me...
Is there a reason for this?
Yup. ;-)
Numbers beginning with a `0' are in octal (base 8), so only the digits 
`0' through `7' are valid.

HTH,
--ag
--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bug?

2005-03-13 Thread Joe Wong



I think python is expecting a octet number from the 
input?
 
- Joe
 

  - Original Message - 
  From: 
  [EMAIL PROTECTED] 

  To: python-list@python.org 
  Sent: Monday, March 14, 2005 10:51 
AM
  Subject: Bug?
  HelloIve recently found that you cannot type anything 
  over 7 into a number that is preceded with a 
  0.ex: >>> 01    
  1    >>> 07    
  7    >>> 08    SyntaxError: 
  invalid token    >>> 011    
  9    >>> 017    
  15    >>> 077    
  63    >>> 078    SyntaxError: 
  invalid tokenI know this isnt that big of a problem,but i cannot 
  think of one reason why they would not allow numbers preceded with a 0 to have 
  a numberhigher then a 7 in them...And it seems very inconsistant to 
  me...Is there a reason for 
  this?ThanksPeter-- No virus found in this 
  outgoing message.Checked by AVG Anti-Virus.Version: 7.0.308 / Virus 
  Database: 266.7.2 - Release Date: 3/11/2005-- http://mail.python.org/mailman/listinfo/python-list
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.7.2 - Release Date: 2005/3/11
-- 
http://mail.python.org/mailman/listinfo/python-list

Bug?

2005-03-13 Thread [EMAIL PROTECTED]
Hello

Ive recently found that you cannot type anything over 7 into a number that is 
preceded with a 0.
ex:
 >>> 01
1
>>> 07
7
>>> 08
SyntaxError: invalid token
>>> 011
9
>>> 017
15
>>> 077
63
>>> 078
SyntaxError: invalid token

I know this isnt that big of a problem,
but i cannot think of one reason why they would not allow numbers preceded with 
a 0 to have a number
higher then a 7 in them...
And it seems very inconsistant to me...

Is there a reason for this?

Thanks
Peter



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.7.2 - Release Date: 3/11/2005

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


[ANN] pysqlite 2.0.alpha2

2005-03-13 Thread Gerhard Haering
pysqlite 2.0.alpha2
===

The last release was back in Nov. 2004, but pysqlite 2 development is going on
faster now. So it's time for another alpha release to collect feedback.

Please report any bugs you find on the pysqlite mailing list, or even better on
the trac tracking system at http://initd.org/tracker/pysqlite

Downloads at Sourceforge:
http://sourceforge.net/project/showfiles.php?group_id=54058&package_id=134545

The project itself at http://pysqlite.org/ 



Changes since pysqlite 2.0.alpha1
=

Namespaces change:
- the DB-API module is now called pysqlite2.dbapi2 instead of sqlite, you
  typically import it using "from pysqlite2 import dbapi2 as sqlite"

DB-API compliance:
- implemented all module-level constants and functions that are required
  for DB-API compliance

Type system:
<< Type conversion SQLite => Python >>

** SQLite types mode (default **
- nothing happens behind your back. if you SELECT, you get back the types
  SQLite reports. So, you will only get strings, ints, floats, and BLOBs
  (BLOBs as Python buffer objects)

** pysqlite types mode (have to activate explicitly) **
- the returned type depends on the decleared column for the SELECTed data.
  To use it successfully, you must register converters for the column types
  (see below). You can also set the declared column types explicitly using
  the coltypes property of cursors (see below)
- new method register_converter(coltypes, converter) for connection objects:
* con.register_converter("int": int)
* con.register_converter("unicode": unicode)
* con.register_converter("boolean": bool)
* con.register_converter("foo": lambda x: "<%s>" % x)
* class Bar: ...
  con.register_converter("bar": Bar)
- new property coltypes of cursor objects:
cur.coltypes = {"col1": int}
cur.execute("select foo as col1 from bar")

<< Type conversion Python => SQLite >>
- Like in PEP 246 (Object Adaptation)
- the default protocol does nothing, except handle Unicode strings
- the protocol's __adapt__ returns the SQLite value directly at the moment
  (this will perhaps change in the next release)
- example protocol:
class P(dbapi2.SQLitePrepareProtocol):
def __adapt__(self, obj):
if isinstance(obj, Point):
return "(%s/%s)" % (obj.x, obj.y)
else:
return dbapi2.SQLitePrepareProtocol.__adapt__(self, obj)
con = sqlite.connect(":memory:", more_types=True, prepareProtocol=P())

Connect call:
- Syntax is now:
con = sqlite.connect(database, timeout, protocol, more_types)

* timeout: timeout parameter in seconds, until error raised if
  concurrent access. in alpha1, it just failed immediately
* protocol: see Type system
* more_types: set to true if you want to use the pysqlite types mode
  instead of the default SQLite one

Misc.:
- pysqlite.dbapi2 now has constants version and version_info


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Apparently, I don't understand threading

2005-03-13 Thread Dave Brueck
[EMAIL PROTECTED] wrote:
The following script does not behave as expected. I wanted to terminate 
the 'mythread' thread after 5 seconds.

What I see is the threading.Thread call blocking until the 15 second 
sleep is done. Suggestions?
[snip]
foo = FooClass()
mythread = threading.Thread(foo.stall())
I think you meant to write:
mythread = threading.Thread(target=foo.stall)
In the original version, you're _calling_ foo.stall at the time of thread 
creation.
-Dave
--
http://mail.python.org/mailman/listinfo/python-list


RE: Apparently, I don't understand threading

2005-03-13 Thread jwsacksteder
I realize that. I'm using a variant of the polite shutdown request technique
used in the python cookbook. The problem is that thread creation is
apparently blocking instead of continuing program execution.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Sunday, March 13, 2005 9:03 PM
To: Jeff Sacksteder
Cc: python-list@python.org
Subject: Re: Apparently, I don't understand threading

The Python threading model doesn't allow one thread to forcibly terminate
another.  This has been discussed many times before, I think that the short
answer is a combination of (a) it's hard to specify what happens in the
terminated thread, without the possibility of leaving the program in an
unknown
state and (b) the threading modules are very lowest-common-denominator, not
requiring features that aren't already built into all the targeted
OS/threading
library combination.

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


Re: Apparently, I don't understand threading

2005-03-13 Thread jepler
The Python threading model doesn't allow one thread to forcibly terminate
another.  This has been discussed many times before, I think that the short
answer is a combination of (a) it's hard to specify what happens in the
terminated thread, without the possibility of leaving the program in an unknown
state and (b) the threading modules are very lowest-common-denominator, not
requiring features that aren't already built into all the targeted OS/threading
library combination.

Jeff


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

Re: Creating desktop icons for Innosetup file

2005-03-13 Thread Greg Ewing
Will McGugan wrote:
You need to set the working dir for the icon in the [Icons] sections. 
It would be better to re-design the application so that
it doesn't rely on being started with any particular
working directory. Then it will still work if the user
creates additional shortcuts that don't have the
working directory set, launches the app directly, etc.
--
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: Unicode BOM marks

2005-03-13 Thread Steve Horsley
Martin v. LÃwis wrote:
Steve Horsley wrote:
It is my understanding that the BOM (U+feff) is actually the  Unicode 
character "Non-breaking zero-width space". 

My understanding is that this used to be the case. According to
http://www.unicode.org/faq/utf_bom.html#38
the application should now specify specific processing, and both
simply dropping it, or reporting an error are both acceptable behaviour.
Applications that need the ZWNBSP behaviour (i.e. want to indicate that
there should be no break at this point) should use U+2060 (WORD JOINER).
Regards,
Martin
I'm out of date, then. Thanks for the link.
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Convert python to exe

2005-03-13 Thread [EMAIL PROTECTED]
I wonder if I get the executable like c program compiled by gcc

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


Re: Convert python to exe

2005-03-13 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> I have a python script under linux, I wonder if I can be converted to
> an executable or not?

Place '#!/usr/bin/env python' as the first line of your script and type::

  chmod u+x yourscript.py

at the command line.  ;-)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determining the length of strings in a list

2005-03-13 Thread Michael Hoffman
[EMAIL PROTECTED] wrote:
I have a dictionary.  Each key contains a list.  I am using the
contents of the list to build a portion of a command line.
However, before I can build the command line, I have to make sure that
the command isn't too long.  This means that I have to step through
each item in the list twice: once to check the length and once to build
the command.  Is there an easier/better way to do this?
I'm not exactly sure what is done in "break command portion into
multiple portions," but you could always build the command and then
check the list.
Or you can get the length of all of the values this way:
sum(len(value) for value in cmdline_dict.itervalues())
I don't think it's a good idea to call your dict "dict" as it shadows a
built-in.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: pyasm 0.2 - dynamic x86 assembler for python

2005-03-13 Thread olsongt
[JanC]
> The code below makes it possible to write assembler code for
different
> architectures (in case pyasm ever supports that ;) and also a Python
> code version to use when running on a system where no assembler code
> can be used.  It prints:

[Michael]
> Another (perhaps wacky) approach would be to change the assembler
> source syntax
> enough to make it legal Python - in particular, this means
parenthesizing
>the
> arguments - then it can just be stored in-line with other Python
source. This
> has the additional benefit that one could write support functions to
enable
> the
> source to be executed interactively in Python.
>
> The following example uses the CPython opcodes, represented as Python

> functions.
>  Python control structures 'while' and 'if' are used as assembler
directives
> for flow.

I've been trying to come up with responses to these two posts, but I'm
just plain speechless.  That should be taken as a complement.

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


Re: Regular Expressions: large amount of or's

2005-03-13 Thread Scott David Daniels
Daniel Yoo wrote:
John Machin <[EMAIL PROTECTED]> wrote:
: tree.search("I went to alpha beta the other day to pick up some spam")
: could use a startpos (default=0) argument for efficiently restarting
: the search after finding the first match
Ok, that's easy to fix.  I'll do that tonight.
I have a (very high speed) modified Aho-Corasick machine that I sell.
The calling model that I found works well is:
 def chases(self, sourcestream, ...):
  '''A generator taking a generator of source blocks,
  yielding (matches, position) pairs where position is an
  offset within the "current" block.
  '''
You might consider taking a look at providing that form.
-Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter: always scroll to show last line of text

2005-03-13 Thread Raseliarison nirinA
"Martin Franklin"  wrote:

> Benjamin Rutt wrote:
> > I have a tkinter 'Text' and 'Scrollbar' connected and working
> > normally.  When a new line of text is inserted (because I'm
> > monitoring
> > an output stream), I'd like the text and scrollbar to be scrolled
> > to
> > the bottom, so the latest line of text is always shown.  How to do
> > this?  Thanks,
>
>
> text.yview_pickplace("end")
>

or

text.see('end')

there is also a "ScrolledText" module

>>> import ScrolledText
>>> 'see' in dir(ScrolledText.ScrolledText)
True

--
nirinA
--
same-response-again-and-again
--



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


Apparently, I don't understand threading

2005-03-13 Thread jwsacksteder








The following script does not behave as expected. I wanted
to terminate the 'mythread' thread after 5 seconds. 

What I see is the threading.Thread call blocking until the
15 second sleep is done. Suggestions?

 

import threading

from time import sleep

 

class FooClass:

    def
__init__(self):

    self._stop
= threading.Event()

 

    def
stall(self):

    print
self._stop.isSet()

    while
not self._stop.isSet():

    print
"Please hold..."

    sleep(15)

    print
"Done - Nudge,Nudge."

 

foo = FooClass()

mythread = threading.Thread(foo.stall())

print 'thread created'

mythread.start()

print 'thread started'

time.sleep(5)

print "thread stopped - Wink, Wink"

comm1._stop.Set()






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

Determining the length of strings in a list

2005-03-13 Thread robin . siebler
I have a dictionary.  Each key contains a list.  I am using the
contents of the list to build a portion of a command line.

However, before I can build the command line, I have to make sure that
the command isn't too long.  This means that I have to step through
each item in the list twice: once to check the length and once to build
the command.  Is there an easier/better way to do this?

for key in dict:
tlen = 0
for item in dict[key]:
tlen = tlen + len(item)
if tlen > 200:
#break command portion into multiple portions ...
for key in dict:
for item in dict[key]:
#buld command

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


Convert python to exe

2005-03-13 Thread [EMAIL PROTECTED]
Hi

I have a python script under linux, I wonder if I can be converted to
an executable or not?

Richard

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


Re: running a python script in drpython

2005-03-13 Thread john
john wrote:
Haveing problems writeing a program then running it in python 2.3.5 
interpreter.  Called the program test.py used chmod to make it 
executable in linux

#! /usr/bin/python
print 2** 8
print 'the bright side ' + 'of life'

 >>> python test.py
  File "", line 1
python test.py
  ^
SyntaxError: invalid syntax
how do you run a script you create in the python interpreter?
Thanks
John
You have to import the script into the interpreter.
>>> import test
256
the bright side of life
--
http://mail.python.org/mailman/listinfo/python-list


Re: pyasm 0.2 - dynamic x86 assembler for python

2005-03-13 Thread Michael Spencer
JanC wrote:
[an example of using decorators to control pyasm]
Another (perhaps wacky) approach would be to change the assembler source syntax 
enough to make it legal Python - in particular, this means parenthesizing the 
arguments - then it can just be stored in-line with other Python source.  This 
has the additional benefit that one could write support functions to enable the 
source to be executed interactively in Python.

The following example uses the CPython opcodes, represented as Python functions. 
 Python control structures 'while' and 'if' are used as assembler directives 
for flow.

Michael
 >>> import ackermann
 >>> Ackermann = assemble(ackermann.ackSrc)
 [snip assembler output]
 >>> Ackermann
 
 >>> Ackermann(3,8)
 2045
# ackermann.py  --
def ackSrc(m,n):
"Compute Ackermann's function on a stack"
# Can be assembled to Python bytecode, or (not implemented yet)
# executed in Python with suitable support functions
LOAD_CONST("Return")
LOAD_FAST(m)
LOAD_FAST(n)
while condition(ROT_TWO(), DUP_TOP(), LOAD_CONST("Return"), 
COMPARE_OP("!=")):
if condition(POP_TOP(), DUP_TOP(), LOAD_CONST(0), COMPARE_OP("==")):
POP_TOP()
POP_TOP()
LOAD_CONST(1)
BINARY_ADD()
else:
if condition(POP_TOP(), ROT_TWO(), DUP_TOP(), LOAD_CONST(0), 
COMPARE_OP("==")):
POP_TOP()
POP_TOP()
LOAD_CONST(1)
BINARY_SUBTRACT()
LOAD_CONST(1)
else:
POP_TOP()
DUP_TOP()
LOAD_CONST(1)
BINARY_SUBTRACT()
ROT_THREE()
POP_TOP()
DUP_TOP()
LOAD_CONST(1)
BINARY_SUBTRACT()
ROT_THREE()
ROT_TWO()
POP_TOP()
POP_TOP()
return

# ByteCode.py --
"""Python ByteCode Assembler
Author: Michael Spencer
Version: 0 - Experiment
3/11/2005
Example usage:
 >>> import ackermann
 >>> Ackermann = assemble(ackermann.ackSrc)
 [snip assembler output]
 >>> Ackermann
 
 >>> Ackermann(3,8)
 2045
"""
import dis
import compiler
import compiler.ast as ast
opmap = dis.opmap
import new
import inspect
class AbstractVisitor(object):
"""Standard depth-first AST walker - dispatches to methods
based on Node class name"""
def __init__(self):
self._cache = {} # dispatch table
def visit(self, node,**kw):
#print "Visiting: %s" % node.__class__
if node is None: return None
cls = node.__class__
meth = self._cache.setdefault(cls,
getattr(self,'visit'+cls.__name__,self.default))
return meth(node, **kw)
def default(self, node, **kw):
for child in node.getChildNodes():
self.visit(child, **kw)
visitExpression = default
class Assembler(AbstractVisitor):
"""Python bytecode assembler"""
def __init__(self):
self._cache = {} # dispatch table
self.i = 0   # Bytecode instruction counter
self.co_varnames = []
self.co_consts = []
self.jumptable = {}
self.co_codelst = []
def emit(self, funcname, arg = None):
i = self.i
try:
opcode = opmap[funcname]
except KeyError:
raise SyntaxError, "Unknown operation: %s" % funcname
self.co_codelst.append(opcode)
if opcode > dis.HAVE_ARGUMENT:
print "%4s %4s  %s %s" % (i, opcode, funcname.ljust(20), arg)
self.co_codelst.extend(self._getlohi(arg))
self.i = i + 3
else:
print "%4s %4s  %s" % (i, opcode, funcname.ljust(20))
self.i = i + 1
def getcodestring(self):
self._resolvejumps()
return "".join(map(chr, self.co_codelst))
def getcode(self):
return new.code(self.co_argcount, # argcount
self.co_argcount, # nlocals
1,# stacksize
67,   # flags
self.getcodestring(), # codestring
tuple(self.co_consts),  # constants
tuple(self.co_varnames),# names
tuple(self.co_varnames),# varnames
"assembly", # filename
self.co_name,   # name
0,  # firstlineno
""  # lnotab
)
def _getlohi(self, arg):
if isinstance(arg, int):
return arg % 256, arg / 256
else:
return None,None
def _resolvejumps(self):
for origin, dest in self.jumptable.iteritems():
self.co_codelst[origin+1:origin+3] = self._getlohi(dest - origin - 
3)
def visitFunction(self, node, **kw):
sel

Re: [Python-Dev] RELEASED Python 2.4.1, release candidate 1

2005-03-13 Thread "Martin v. Löwis"
Richie Hindle wrote:
I could try again, but maybe there's some useful information you can get
from the partially upgraded environment.  Here's how the \python24
directory looks:
I tried to reproduce it, and failed - if the DLL is not in use, it is
updated correctly; if it is in use, a window pops up telling you so, and
it won't let you proceed until you have terminated the process that has
it open.
However, I just noticed that the python24.dll is in c:\python24. Could
it be that you have another one in \windows\system32? If so, could it
also be that the installer has told you that the target directory 
exists, and asked whether you want to proceed anyway?

In that case, your 2.4 installation was a per-user installation, and the
2.4.1c1 installation was a per-machine (allusers) installation. These
are mutually not upgradable, so you should now have the option of
uninstalling both in add-and-remove programs.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Licensing Python code under the Python license

2005-03-13 Thread "Martin v. Löwis"
JanC wrote:
This is difficult to do right, if you have to consider all the laws in 
different countries...
Right. So he points out that his explanations are for US copyright law
only, and then that legislation even in different US states, or perhaps
even in districts, might be different. Therefore, a license should state
what jurisdiction it applies to.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter: always scroll to show last line of text

2005-03-13 Thread Benjamin Rutt
Martin Franklin <[EMAIL PROTECTED]> writes:

> text.yview_pickplace("end")

Thank you, works perfectly!
-- 
Benjamin Rutt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching for a ComboBox for Tkinter?

2005-03-13 Thread Raseliarison nirinA
"Harlin Seritt" wrote:

> I've created a ghetto-ized ComboBox that should work nicely for
> Tkinter
> (unfortunately no dropdown capabilities yet).
>

how about:

>>> import Tix
>>> print Tix.ComboBox.__doc__
ComboBox - an Entry field with a dropdown menu. The user can select a
choice by either typing in the entry subwdget or selecting from
the listbox subwidget.

Subwidget   Class
-   -
entry   Entry
arrow   Button
slistboxScrolledListBox
tickButton
cross   Button : present if created with the fancy option

--
nirinA





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


Re: Install problem Windows xp HE

2005-03-13 Thread Raseliarison nirinA
"Jan Ekström" wrote:
> Here is the error.
> IDLE 1.1
> >>> python
>
> Traceback (most recent call last):
>   File "", line 1, in -toplevel-python
> NameError: name 'python' is not defined
> >>>

this should be a success install report! not an error.
start coding and see what happens.

>>> print "Hello World!"

--
nirinA





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


Re: issues installing readine-1.12 on WinXP

2005-03-13 Thread Simon Percivall
Well, just modify the source in that case.

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


Re: smtplib / solaris (newbie problem?)

2005-03-13 Thread "Martin v. Löwis"
[EMAIL PROTECTED] wrote:
The error message 'Connection refused' got me thinking that the SMTP
server wouldn't allow this or required some authentication, or etc.
In case this isn't clear yet: the "connection refused" error happens
in TCP sockets if the remote machine is turned on, but offers no service
at the requested port. To see that in action, try connecting to any
unused port, e.g.
[EMAIL PROTECTED]:~$ telnet localhost 12354
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
The error message that you get when you *do* connect, but then the
application rejects its service because of missing credentials or
some such should be different.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extending and Embedding

2005-03-13 Thread Eduardo Rodrigues
Sorry, I guess that I wasn't clear. I've made a module
using swig that wrap functions written in C. If I load
that module in python using:

>>> from  import *

it works fine. But if I execute this same command
using PyRun_SimpleString in another code written in C,
it doesn't work, i.e. I can't load a module (made by
swig) in a embedding code.

Erocha

--- "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Eduardo Rodrigues wrote:
> 
> > How can I load a module (written in C as a shared
> > library (.so)) through "PyRun_SimpleString"?
> > 
> > I've tried "from  import *", but a got a
> > message: ImportError: No module named 
> 
> You can't do this. You have to either wrap the
> module - which is possible in
> several ways, including hand-written code, pyrex,
> swig and sip. Maybe even
> more, I don't know. 
> 
> Or you access it using the module ctypes that allows
> to invoke arbitrary
> methods/funtctions of C-libs. google for it.
> -- 
> Regards,
> 
> Diez B. Roggisch
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





Yahoo! Mail - Com 250MB de espaço. Abra sua conta! http://mail.yahoo.com.br/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Licensing Python code under the Python license

2005-03-13 Thread JanC
Martin v. Löwis schreef:

> Larry argues that a license should be legally meaningful, and
> legally clear - or else there is little point in formulating
> a license in the first place.

This is difficult to do right, if you have to consider all the laws in 
different countries...

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


running a python script in drpython

2005-03-13 Thread john
Haveing problems writeing a program then running it in python 2.3.5 
interpreter.  Called the program test.py used chmod to make it 
executable in linux
#! /usr/bin/python
print 2** 8
print 'the bright side ' + 'of life'
>>> python test.py
  File "", line 1
python test.py
  ^
SyntaxError: invalid syntax
how do you run a script you create in the python interpreter?
Thanks
John
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expressions: large amount of or's

2005-03-13 Thread Daniel Yoo
John Machin <[EMAIL PROTECTED]> wrote:


: tree.search("I went to alpha beta the other day to pick up some spam")

: could use a startpos (default=0) argument for efficiently restarting
: the search after finding the first match

Ok, that's easy to fix.  I'll do that tonight.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adapting code to multiple platforms

2005-03-13 Thread Paul Watson
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Simon John wrote:
>> If you're using a GUI, then that may help you decode the platform too -
>> for example wxPython has wx.Platform, there's also platform.platform()
>> , sys.platform and os.name
>>
>> You could try import win32api and checking for an exception ;-)
>
> (Winky noted)  Just in case anyone thinks that last is a
> useful idea, keep in mind that win32api is not installed
> (with the standard distribution) but must be installed
> with a separate download of the pywin32 package by Mark
> Hammond.
>
> -Peter

How about try: import msvcrt 


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


Re: Web framework

2005-03-13 Thread Venkat B
> I'd say Nevow! For apache setup, you might be interested in my wsgi [1]
> implementation.

Hi Sridhar,

Are you aware of Nevow's "integrability" with the webservers (CGIHTTPServer
in particular) that come packaged with Python itself ?

Thanks,
/venkat


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


Re: is there a problem on this simple code

2005-03-13 Thread John Machin

Jan Rienyer Gadil wrote:
> @ sir Peter
> so you mean that it is correct (at least on the unpack() part)

No he doesn't mean that at all. All it means is that minor scuffles
have broken out among the spectators. Don't worry about them, batons &
water cannon will fix them; you concentrate on the football match :-)

>
> when i run this program on IDLE , Python 2.3 (enthought edition),
> nothing is outputted on the shell, until i decide to close the shell,
> wherein it tells me if i would like to kill a process...

So you did some elementary debugging, like putting in some print
statements at various places, as shown below, and what happened?

>
> import serial
> import string

Redundant.

> import time
> from struct import *
>
> ser = serial.Serial()
>
> ser.baudrate = 9600
> ser.port = 0
> ser

What is the above line meant to do? It actually does nothing.

> ser.close()
> ser.open()
>
> command = 67
> message_no = 1
> total_data = 2
>
> item = 1

Redundant.
>

print "DEBUG: before outer loop"


> for item in range(1, 30001, 250):

print "DEBUG: inside outer loop; item =", repr(item)

>data_hi, data_lo = divmod(item, 0x100)
>checksum = -(data_hi + data_lo + 0x46) & 0xff

You obviouly haven't taken the advice to generalise your checksum
calculation.

>ser.write(pack('6B', command, message_no, total_data, data_lo,
> data_hi, checksum))
>
>rx_data1=0

print "DEBUG: before inner loop"

>while (rx_data1 != 0x46):
>rx_data1 = ser.read(1)
>(rx_command) = unpack('1B', rx_data1)

print "DEBUG: inside inner loop; rx_data1 =", repr(rx_data1), ";
rx_command =", repr(rx_command)

And if you had have done that, you would/should have realised that you
have a:
!! CODING BUG !!
ser.read(1) will return a STRING, so even if you get the byte you are
looking for, rx_data1 will refer to 'F' == chr(70) == chr(0x46) ==
'\x46' none of which are == 0x46, and you will loop forever (if the
hardware is continuously outputting data) or hang waiting for data from
the hardware.

!! DESIGN BUG !!
HOWEVER, as Dennis and I have been trying to tell you, it is WRONG to
be looping trying to sync on the first character in the packet. You
need to fix your data loss problem, not try to kludge your way around
it. I'll say it again, but only once: go back to the code of your
original posting. That code was not losing data. Among whatever else is
needed to revert to the first-shown code, put back the sleep() between
iterations.
As advised earlier, make sure that you use separate rx_command and
tx_command so that you don't accidentally start sending 70 as the
command.
Then show us what happened.

> rx_data2=ser.read(9)
> (rx_msg_no, rx_no_databyte, temp1, temp2, pyra1, pyra2, voltage,
>  current, rx_checksum) = unpack('9B', data)

!! CODING BUG !!
You read into "rx_data2" but unpack from "data". The result, when you
reach it after fixing the earlier bug, will be either an exception or
an utter nonsense, depending on what "data" is bound to at the time (if
anything).

>  print rx_command, rx_msg_no, rx_no_databyte, temp1, temp2,
pyra1,
>  pyra2, voltage, current, rx_checksum
>

You obviously haven't taken the advice from Dennis and myself to
validate the packet you receive -- (1) checksum is OK (2)
rx_no_databyte == 6

> ser.close()

HTH,
John

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


Re: Debugging Python Scripts inside other processes

2005-03-13 Thread Peter Maas
A. Klingenstein schrieb:
I embedded Python in a Windows C++ program. Now I want to debug my 
embedded scripts which of course won't run in any IDE process. 
Commercial IDEs like WingIDE can attach to external processes by 
importing a module in the scripts. Is there a debugger capable of this 
which is Free or Open Source?

What I need are the following things:
- runs in Windows
- single stepping
- variable watches
- breakpoints
Does your Windows C++ program have a working stdin/stdout/stderr,
i.e. kind of a console? Then you could insert
import pdb
pdb.set_trace()
at a position in your embedded scripts where you want debugging to
start. If your C++ program doesn't have a console then perhaps you
can provide one with a Win32 call? Just guessing here.
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: Huge performance gain compared to perl while loading a text file in a list ...!?

2005-03-13 Thread Martin Franklin
Paul Rubin wrote:
"Marc H." <[EMAIL PROTECTED]> writes:
I'm fairly new to python, and don't know much of its inner working so
I wonder if someone could explain to me why it is so much faster in
python to open a file and load it in a list/array ?

My guess is readlines() in Python is separating on newlines while Perl
is doing a regexp scan for the RS string (I forget what it's called in
Perl).
I remember when it was the other way round ;-)
http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/fe217ae9723f7a38/23477243324bebc6?q=python+file+IO+speed#23477243324bebc6
--
http://mail.python.org/mailman/listinfo/python-list


Re: autoexecution in Windows

2005-03-13 Thread Thorsten Kampe
On Mon, 07 Mar 2005 16:06:46 -0500, rbt wrote:

> Earl Eiland wrote:
>> In Linux, if I make the first line #!/path/to/Python, all I have to do
>> to execute the program is type ./FileName (assuming my pwd is the same
>> as FileName).  what's the Windows equivalent?
>> Earl
>> 
>> On Mon, 2005-03-07 at 13:36, F. Petitjean wrote:
>> 
>>>Le Mon, 07 Mar 2005 13:25:35 -0700, Earl Eiland a écrit :
>>>
How does one make a Python program auto-execute in Windows?

Earl

>>>
>>>write a virus ?  :-)
>>>
>>>What do you mean by « auto-execute » ?
>>>
>>>Regards
>> 
> 
> Look at the 'pathext' variable under the system's environmental 
> variables. Add .py and .pyw to that and you're good to go.

No, that's just so you can omit the extension.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Linux Multimedia System

2005-03-13 Thread Lucas Raab
Marek Franke wrote:
Hi there,
we have started with some people from our LUG (Linux User Group) a 'little'
project, called LMMS (Linux Multimedia System). When it's 'finished' it
shall be a window-manager for use on TV and handle with joysticks/gamepads. 

As the name says, it is for multimedia-applications, like listening to
music, watching videos and maybe playing some games. The idea is to create
a gui for application like mplayer, ogg123, mpg123, cdrecord etc.
For now there are some widgets for displaying images, labels and some
messages. Actually there is a working LMMS with a little menu, an
image-viewer and a CD-player. Supperted joysticks/gamepads are Gravis
Gamepad Pro, Nintendo's SNES Pads, Microsoft's X-Box pad and keyboard.
The whole project is written in python/pygame and can be found here:
http://home.arcor.de/mfranke78/
There is a little mailinglist too (German & Yahoo):
http://de.groups.yahoo.com/group/dulugprojekt/
Remember that the whole project is very basic for now! But it seems to work.
Greets, Marek
BTW, I'd be happy to help with a Windows version.
--
--
Lucas Raab
lvraab located at earthlink.net
dotpyFE located at gmail.com
AIM:Phoenix11890
MSN:[EMAIL PROTECTED]
IRC:lvraab
ICQ:324767918
Yahoo:  Phoenix11890
--
http://mail.python.org/mailman/listinfo/python-list


Re: Linux Multimedia System

2005-03-13 Thread Lucas Raab
Marek Franke wrote:
Hi there,
we have started with some people from our LUG (Linux User Group) a 'little'
project, called LMMS (Linux Multimedia System). When it's 'finished' it
shall be a window-manager for use on TV and handle with joysticks/gamepads. 

As the name says, it is for multimedia-applications, like listening to
music, watching videos and maybe playing some games. The idea is to create
a gui for application like mplayer, ogg123, mpg123, cdrecord etc.
For now there are some widgets for displaying images, labels and some
messages. Actually there is a working LMMS with a little menu, an
image-viewer and a CD-player. Supperted joysticks/gamepads are Gravis
Gamepad Pro, Nintendo's SNES Pads, Microsoft's X-Box pad and keyboard.
The whole project is written in python/pygame and can be found here:
http://home.arcor.de/mfranke78/
There is a little mailinglist too (German & Yahoo):
http://de.groups.yahoo.com/group/dulugprojekt/
Remember that the whole project is very basic for now! But it seems to work.
Greets, Marek
Just wondering how you're supporting the Xbox controller. I bought a 
cable and driver a few months back to hook up to my computer. Are you 
using a Python alternative??

--
--
Lucas Raab
lvraab located at earthlink.net
dotpyFE located at gmail.com
AIM:Phoenix11890
MSN:[EMAIL PROTECTED]
IRC:lvraab
ICQ:324767918
Yahoo:  Phoenix11890
--
http://mail.python.org/mailman/listinfo/python-list


Re: Searching for a ComboBox for Tkinter?

2005-03-13 Thread Martin Franklin
Martin Franklin wrote:
Harlin Seritt wrote:
I've created a ghetto-ized ComboBox that should work nicely for Tkinter
(unfortunately no dropdown capabilities yet).
I've found why it's such a pain in the @ss to create one. You have to
re-create common methods and make sure they're mapped to the right
component (inside this widget are frame, entry, listbox, and scrollbar
widgets). I tried to look for ways I could inherit some methods from
other widgets but couldn't think of how to do it in an efficient way.
If anyone has suggestions to improve it, please respond... Remember...
I'm a traditional c/c++ turned python programmer who forgets that there
usually is a better, faster more graceful way to do things with Python
than with C/C++/Java.
Cheers,
Harlin
##
# Seritt Extensions:
# Date: 02262005
# Class ComboBox
# Add this section to your Tkinter.py file in 'PYTHONPATH/Lib/lib-tk/'
# Options: width, border, background, foreground, fg, bg, font
#, relief, cursor, exportselection, selectbackgroun,
selectforeground, height
#
# Methods: activate(int index) => int, curselection() => int,
delete(item=["ALL" or int], start=int, end=["END" or
# int],
# focus_set()/focus(), get()=>selected string in box, pack(padx=int,
pady=int,  fill(X, Y, BOTH), expand=bool, # side=LEFT,
# RIGHT, TOP, BOTTOM, CENTER
#
class ComboBox:

Why not extend an existing Tkinter widget?  This way you get at
least the geometry (pack, grid etc) methods thown in for free!
class ComboBox(Frame):
def __init__(self, parent, *args, **kw):
Frame.__init__(self, parent, *args, **kw)
You could extend Entry above is just an example...
Also worth pointing out are a couple of ComboBox's out there already
Pmw includes one as does Tix (IIRC)
Cheers,
Martin.

I forgot to say good work!  and you may be interested in the Tkinter 
mailing list and Wiki (where you could post your 'mega' widget as an example

http://mail.python.org/mailman/listinfo/tkinter-discuss
gmane.comp.python.tkinter
http://tkinter.unpythonic.net/wiki/
(There seems to be a lot of Tkinter related posts recently)
Martin

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


Re: Itertools wishlists

2005-03-13 Thread Terry Reedy

"Raymond Hettinger" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> FWIW, requests for additions to the itertools module have not fallen on 
> deaf
> ears.  There are no arbitrary restraints on building out this module. 
> Each
> request has gotten careful thought and a couple of them were accepted in 
> Py2.4
> (itertools.tee and itertools.groupby).  If you would like to know the 
> reasoning
> behind any particular acceptance, rejection, or deferral, then just ask.

[nice rundown snipped]

Is this list of reasonings permanently posted somewhere, like on the wiki? 
It's too good to just disappear.

TJR



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


Re: Bind Escape to Exit

2005-03-13 Thread Martin Franklin
Kent Johnson wrote:
Binny V A wrote:
Hello Everyone,
I am new to python and I am trying to get a program to close a 
application when the Escape Key is pressed.

Here is a version that works. The changes from yours:
- Bind , not 
These amount to the same thing AFAIK
- Bind the key to the root, not the frame
This is the 'fix'  Tkinter's Tk (and Toplevel) widgets will allow key 
bindings, Frames do not.

- Define a quit() method that takes an event parameter
Yep the bind'ing will pass an event object to the callback.
just FYI, you may be interested in the Tkinter mailing list:-
http://mail.python.org/mailman/listinfo/tkinter-discuss
also available from gmane:-
gmane.comp.python.tkinter
Martin.

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


Re: Overloading the "and" operator

2005-03-13 Thread Terry Reedy

"Fredrik Bertilsson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I am trying to overload the "and" operatior, but my __and__ method is
> never called.

That is because, properly speaking, 'and' and 'or' are, in Python, in-line 
flow-control keywords (related to 'if' and 'else'),  and not operators. 
Operators are abbreviated function calls.  For binary operators, this means 
evaluating both left and right operands and then calling the function, 
which may hook into a special method, as you tried to do.  'And' and 'or', 
on the other hand, try to avoid evaluating the right expression.

Terry J. Reedy




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


Re: Searching for a ComboBox for Tkinter?

2005-03-13 Thread Martin Franklin
Harlin Seritt wrote:
I've created a ghetto-ized ComboBox that should work nicely for Tkinter
(unfortunately no dropdown capabilities yet).
I've found why it's such a pain in the @ss to create one. You have to
re-create common methods and make sure they're mapped to the right
component (inside this widget are frame, entry, listbox, and scrollbar
widgets). I tried to look for ways I could inherit some methods from
other widgets but couldn't think of how to do it in an efficient way.
If anyone has suggestions to improve it, please respond... Remember...
I'm a traditional c/c++ turned python programmer who forgets that there
usually is a better, faster more graceful way to do things with Python
than with C/C++/Java.
Cheers,
Harlin
##
# Seritt Extensions:
# Date: 02262005
# Class ComboBox
# Add this section to your Tkinter.py file in 'PYTHONPATH/Lib/lib-tk/'
# Options: width, border, background, foreground, fg, bg, font
#   , relief, cursor, exportselection, selectbackgroun,
selectforeground, height
#
# Methods: activate(int index) => int, curselection() => int,
delete(item=["ALL" or int], start=int, end=["END" or
# int],
#   focus_set()/focus(), get()=>selected string in box, pack(padx=int,
pady=int,  fill(X, Y, BOTH), expand=bool, # side=LEFT,
#   RIGHT, TOP, BOTTOM, CENTER
#
class ComboBox:
Why not extend an existing Tkinter widget?  This way you get at
least the geometry (pack, grid etc) methods thown in for free!
class ComboBox(Frame):
def __init__(self, parent, *args, **kw):
Frame.__init__(self, parent, *args, **kw)
You could extend Entry above is just an example...
Also worth pointing out are a couple of ComboBox's out there already
Pmw includes one as does Tix (IIRC)
Cheers,
Martin.
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter: always scroll to show last line of text

2005-03-13 Thread Martin Franklin
Benjamin Rutt wrote:
I have a tkinter 'Text' and 'Scrollbar' connected and working
normally.  When a new line of text is inserted (because I'm monitoring
an output stream), I'd like the text and scrollbar to be scrolled to
the bottom, so the latest line of text is always shown.  How to do
this?  Thanks,

text.yview_pickplace("end")

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


Re: brand new to python

2005-03-13 Thread Bengt Richter
On 13 Mar 2005 11:22:54 -0800, [EMAIL PROTECTED] wrote:

>I am sure this is old news, the syntax of python is crazy to me.
>There I said it, I'm sure I'll get over it or around it.
>
>I was trying to make a whois script work and was unable.
>
>May be someone with lint-like eyes can tell what's wrong.
I haven't tried
>
>Using xemacs I had hoped that python mode would do more
>for syntax problems, maybe I'm just not using python mode
>correctly in xemacs??
>
>./whois.py yahoo.com
>  File "./whois.py", line 117
>class DomainRecord:
>^
>SyntaxError: invalid syntax

Yeah, that's not terribly informative. But notice that all your try/except 
pairs aren't lined up.
The second except is at the same indentation as the first below the second try. 
Multiple excepts
are legal under a try, but in your case it leaves the outer (first) try without 
any matching-indent except.

After fixing that, you may have to join some broken lines, if your post is 
accurately reflecting your source.

[...]
>  ## try until we are connected
>
>  while s == None:
>try:
The above try has no matching except

>  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>  s.setblocking(0)
>  try:
>s.connect(whoisserver, 43)
>  except socket.error, (ecode, reason):
>if ecode in (115, 150):
>  pass
>else:
>  raise socket.error, (ecode, reason)
>ret = select.select([s], [s], [], 30)
>
>if len(ret[1]) == 0 and len(ret[0]) == 0:
>  s.close()
>  raise TimedOut, "on connect "
>s.setblocking(1)
>
>  except socket.error, (ecode, reason):
The above except is at the same indentation as the previous one,
which is legal syntax, but you probably meant it to match the first try?

>print ecode, reason
>time.sleep(10)
>s = None
>
>s.send("%s \n\n" % domainname)
>page = ""
>while 1:
>  data = s.recv()
>  if not data: break
>
>  page = page + data
>
>  s.close()
>
>  if string.find(page, "No match for") != -1:
>raise NoSuchDomain, domainname
>
>  if string.find(page, "No entries found") != -1:
>raise NoSuchDomain, domainname
>
>  if string.find(page, "no domain specified") != -1:
>raise NoSuchDomain, domainname
>
>  if string.find(page, "NO MATCH") != -1:
>raise NoSuchDomain, domainname
>  return page
Careful with the above return's indentation after you fix the try/excepts.
>
>##
>##
>--
I've heard pychecker (http://pychecker.sourceforge.net/) catches a lot of stuff.
Maybe it would help you. Having lint-eyes, I haven't yet tried it, though it
would probably save me some time ;-)

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


Re: pyasm 0.2 - dynamic x86 assembler for python

2005-03-13 Thread JanC
Stefan Behnel schreef:

> Meaning: Put the assembler into the doc-string of a function. Then 
> use a decorator to run the assembler on the function's __doc__ string 
> and build an assembly function that takes the same arguments to make 
> the assembly function directly callable.

That would 'disable' a programmer's ability to add useful documentation 
in the comments, but I played a bit further with the decorator idea.

The code below makes it possible to write assembler code for different 
architectures (in case pyasm ever supports that ;) and also a Python 
code version to use when running on a system where no assembler code 
can be used.  It prints:

  Hello x86 world!
  Hello python world!
  Hello i386 world!

Note: there is no serious error checking in this code and it's maybe 
not the best possible solution (this is my first decorator code), but 
it seems to work...  :-)

--
# supported_architectures should be defined in pyasm
# this is just to show how it could work...
supported_architectures = ['x86','i386']

# asm optimization decorator
def asm_optimise(*architectures):
arch_iter = architectures.__iter__()
try:
arch = arch_iter.next()
while arch not in supported_architectures:
arch = arch_iter.next()

def decorate(f):
# x86 only at this moment  ;-)
def optimized(self):
from pyasm.x86asm import codePackageFromFile
from pyasm.x86cpToMemory import CpToMemory
from pyasm.pythonConstants import PythonConstants
import cStringIO

arch_asm = eval('self._asm_%s' % arch)
cp = 
codePackageFromFile(cStringIO.StringIO(arch_asm),PythonConstants)
mem = CpToMemory(cp)
mem.MakeMemory()
mem.BindPythonFunctions(globals())
return __call__()
return optimized
except StopIteration:
# no supported architecture found
def decorate(f):
return f

return decorate


class hello_world(object):
"""Hello world with assembler optimisation for x86."""

_asm_x86 = r"""
!CHARS hello_str 'Hello x86 world!\n\0'

!PROC __call__ PYTHON
!ARG  self
!ARG  args
PUSH hello_str
CALL PySys_WriteStdout
ADD ESP, 0x4
MOV EAX,PyNone
ADD [EAX],1
!ENDPROC
"""

@asm_optimise('x86')
def __call__(self):
print 'Hello python world!'

test = hello_world()
test()


class hello_world2(object):
"""Hello world with assembler optimisation for unknown architecture."""

# fake unknown architecture asm  :)
_asm_unknown = r"""
!CHARS hello_str 'Hello unknown world!\n\0'

!PROC __call__ PYTHON
!ARG  self
!ARG  args
PUSH hello_str
CALL PySys_WriteStdout
ADD ESP, 0x4
MOV EAX,PyNone
ADD [EAX],1
!ENDPROC
"""

@asm_optimise('unknown')
def __call__(self):
print 'Hello python world!'

test = hello_world2()
test()


class hello_world3(object):
"""Hello world with assembler optimisation for x86."""

_asm_x86 = r"""
!CHARS hello_str 'Hello x86 world!\n\0'

!PROC __call__ PYTHON
!ARG  self
!ARG  args
PUSH hello_str
CALL PySys_WriteStdout
ADD ESP, 0x4
MOV EAX,PyNone
ADD [EAX],1
!ENDPROC
"""

_asm_i386 = r"""
!CHARS hello_str 'Hello i386 world!\n\0'

!PROC __call__ PYTHON
!ARG  self
!ARG  args
PUSH hello_str
CALL PySys_WriteStdout
ADD ESP, 0x4
MOV EAX,PyNone
ADD [EAX],1
!ENDPROC
"""

# i386 will be tried first, then x86
@asm_optimise('i386','x86')
def __call__(self):
print 'Hello python world!'

test = hello_world3()
test()
--


-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beware complexity

2005-03-13 Thread Brandon J. Van Every
Philip Smith wrote:
>
> Conventions on type conversion are just one example.  Without using
> strict coding conventions the richness of the language could, and
> often did, result in ambiguity.  In my experience too C++ has
> defeated its own object (eg portability) - I've given up in many
> cases trying to compile third party libraries because I don't have
> the time to collect every version of every compiler for every
> platform in existence which is what C++ seems to demand (particularly
> if you are trying to cross-compile Unix->Windows).

Isn't that going to happen to any popular, ISO standard language?  An ISO
standard, oddly enough, means that compiler vendors will compete to add
value to the standard.  Having a language remain under the iron grip of 1
developer is both a blessing and a curse.  Some things remain wonderfully
well controlled and coordinated; other things are suppressed according to
the idiosyncratic whim of the arch-developer.

FWIW this dilemma has had profound historical importance.  It's the main
reason the Chinese didn't colonize and conquer the world, despite having a
61 year head start in maritime expansion.  Isolationist agrarian Confucians
beat expansionist maritime Eunuchs in a civil war, then banned all the
shipping for 130 years.  Europe, being composed of many competing powers who
would try new things to gain an advantage, cleaned up.

My point is that Python may someday grow beyond the notion of 'BDFL', as
heretical as that may sound.

-- 
Cheers, www.indiegamedesign.com
Brandon Van Every   Seattle, WA

"Troll" - (n.) Anything you don't like.
Usage: "He's just a troll."

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


Re: brand new to python

2005-03-13 Thread Dmitry A.Lyakhovets
Hello!

You should at least close the 'try' block, which you started
at line 68 (if i'm not mistaken):


def _whois(domainname, whoisserver):
  s = None

  ## try until we are connected

  while s == None:
try:


There is no corresponding 'except' till DomainRecord class
definition.




On 13 Mar 2005 11:22:54 -0800
[EMAIL PROTECTED] wrote:

> I am sure this is old news, the syntax of python is crazy
> to me. There I said it, I'm sure I'll get over it or
> around it.
> 
> I was trying to make a whois script work and was unable.
> 
> May be someone with lint-like eyes can tell what's wrong.
> 
> Using xemacs I had hoped that python mode would do more
> for syntax problems, maybe I'm just not using python mode
> correctly in xemacs??
> 
> ../whois.py yahoo.com
>   File "./whois.py", line 117
> class DomainRecord:
> ^
> SyntaxError: invalid syntax
> 
> 
> #!/usr/bin/env python
> 
> 
> #usage: %(progname)s [--test] [domain...]
> 
> #Version: %(version)s
> 
> #Contacts the NetworkSolutions whois database for each
> #domain and
> displays
> #the result.
> 
> #public methods:
> 
> #  def whois(domainname, whoisserver=None, cache=0)
> #   raises NoSuchDomain if the domain doesn't exist.
> 
>   #  return the result of contacting NetworkSolutions
> 
>   #def ParseWhois(page)
> # returns a DomainRecord object that contains a parsed
>   #version of the information contained in 'page'.
> 
> #class DomainRecord:
> # self.domain -- name of the domain
>   #self.domainid   -- domainid for this domain
> #  self.created-- date in which the domain was
> #  created
> # self.lastupdated-- date in which the domain was
> # last updated.
> #  self.expires-- date in which the domain
> #  expires self.databaseupdated-- date in which the
> #  database was last
> updated.
> #  self.servers-- list of (hostname, ip) pairs
> #  of the
> #nameservers.
> #  self.registrant -- name of the person or
> #  organization that
> #registered the domain.
> #  self.registrant_address -- address of the person or
> #  organization
> that
> #registered the domain.
> #  self.contacts   -- dictionary of contacts###
> ##
> #
> #"""
> 
> #_version = "1.0"
> 
> import os, sys, string, time, getopt, socket, select, re
> 
> NoSuchDomain = "NoSuchDomain"
> 
> def whois(domainname, whoisserver=None, cache=0):
>   if whoisserver is None:
> whoisserver = "whois.networksolutions.com"
> 
> if cache:
>   fn = "%s.dom" % domainname
>   if os.path.exists(fn):
> return open(fn).read()
> 
>   page = _whois(domainname, whoisserver)
> 
>   if cache:
> open(fn, "w").write(page)
> 
> return page
> 
> def _whois(domainname, whoisserver):
>   s = None
> 
>   ## try until we are connected
> 
>   while s == None:
> try:
>   s = socket.socket(socket.AF_INET,
>   socket.SOCK_STREAM) s.setblocking(0)
>   try:
> s.connect(whoisserver, 43)
>   except socket.error, (ecode, reason):
> if ecode in (115, 150):
>   pass
> else:
>   raise socket.error, (ecode, reason)
> ret = select.select([s], [s], [], 30)
> 
> if len(ret[1]) == 0 and len(ret[0]) == 0:
>   s.close()
>   raise TimedOut, "on connect "
> s.setblocking(1)
> 
>   except socket.error, (ecode, reason):
> print ecode, reason
> time.sleep(10)
> s = None
> 
> s.send("%s \n\n" % domainname)
> page = ""
> while 1:
>   data = s.recv()
>   if not data: break
> 
>   page = page + data
> 
>   s.close()
> 
>   if string.find(page, "No match for") != -1:
> raise NoSuchDomain, domainname
> 
>   if string.find(page, "No entries found") != -1:
> raise NoSuchDomain, domainname
> 
>   if string.find(page, "no domain specified") !=
>   -1:
> raise NoSuchDomain, domainname
> 
>   if string.find(page, "NO MATCH") != -1:
> raise NoSuchDomain, domainname
>   return page
> 
> ##
> ##
> -
> -
> ##
> 
> class DomainRecord:
>   def __init__(self, domain):
> self.domain = domain
> self.domainid = None
> self.created = None
> self.lastupdated = None
> self.expires = None
> self.databaseupdated = None
> self.servers = None
> self.registrant = None
> self.registrant_address = None
> self.contacts = {}
> 
> def __str__(self):
>   return "%s (%s): (created:%s) (lastupdated:%s)
> (databaseupdated:%s) (servers:%s) (registrant:%s)
> (address:%s)(contacts:%s)" % (self.domain, self.domainid,
> self.created, self.lastupdated, self.databaseupdated,
> self.servers, self.registrant,
> repr(self.registrant_address), self.contacts)
> 
> 
> ##
> ##
> -
> ---

Re: how to delete the close button (the X on the right most corner of the window) on a window

2005-03-13 Thread Jeremy Bowers
On Sun, 13 Mar 2005 09:25:43 -0800, jrlen balane wrote:

> i am working on an MDIParentFrame and MDIChildFrame. Now, what i want
> to do is make the ChildFrame not that easy to close by removing the
> close button (the X on the right most corner of the window) if this is
> possible...
> 
> how am i going to do this?

Why is this a Python question?

(This isn't just a snide comment; it matters what you're doing to know
what to say. And of course, if you're not using Python, you're in the
wrong place...)

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


Re: PEP 246 revision

2005-03-13 Thread boisgera
> >Have you read the BDFL's "Python Optional Typechecking Redux" ?
> 
> Yes.
> 
> >(http://www.artima.com/weblogs/viewpost.jsp?thread=89161)
> >It's usage of adapt assumes that "a class is a protocol", so I
> >guess that it does not work with the new version of PEP 246.
> 
> Why not? There's nothing wrong with classes (or anything else) being
> protocols...? AFAIK, the current version of the PEP was specifically
> rewritten in order to fit the BDFL blog (as stated in the PEP).
> 
> [snip]
> 
> I don't quite see the conflict (between the blog and the PEP) here...

There is no conflict, I was wrong ! I guess that I should stop
drinking so much ;). Thanks for your help.

Regards,

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


brand new to python

2005-03-13 Thread richard . hubbell
I am sure this is old news, the syntax of python is crazy to me.
There I said it, I'm sure I'll get over it or around it.

I was trying to make a whois script work and was unable.

May be someone with lint-like eyes can tell what's wrong.

Using xemacs I had hoped that python mode would do more
for syntax problems, maybe I'm just not using python mode
correctly in xemacs??

./whois.py yahoo.com
  File "./whois.py", line 117
class DomainRecord:
^
SyntaxError: invalid syntax


#!/usr/bin/env python


#usage: %(progname)s [--test] [domain...]

#Version: %(version)s

#Contacts the NetworkSolutions whois database for each domain and
displays
#the result.

#public methods:

#  def whois(domainname, whoisserver=None, cache=0)
#   raises NoSuchDomain if the domain doesn't exist.

  #  return the result of contacting NetworkSolutions

  #def ParseWhois(page)
# returns a DomainRecord object that contains a parsed
  #version of the information contained in 'page'.

#class DomainRecord:
# self.domain -- name of the domain
  #self.domainid   -- domainid for this domain
#  self.created-- date in which the domain was created
# self.lastupdated-- date in which the domain was last updated.
#  self.expires-- date in which the domain expires
#  self.databaseupdated-- date in which the database was last
updated.
#  self.servers-- list of (hostname, ip) pairs of the
#nameservers.
#  self.registrant -- name of the person or organization that
#registered the domain.
#  self.registrant_address -- address of the person or organization
that
#registered the domain.
#  self.contacts   -- dictionary of contacts###
##
#
#"""

#_version = "1.0"

import os, sys, string, time, getopt, socket, select, re

NoSuchDomain = "NoSuchDomain"

def whois(domainname, whoisserver=None, cache=0):
  if whoisserver is None:
whoisserver = "whois.networksolutions.com"

if cache:
  fn = "%s.dom" % domainname
  if os.path.exists(fn):
return open(fn).read()

  page = _whois(domainname, whoisserver)

  if cache:
open(fn, "w").write(page)

return page

def _whois(domainname, whoisserver):
  s = None

  ## try until we are connected

  while s == None:
try:
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.setblocking(0)
  try:
s.connect(whoisserver, 43)
  except socket.error, (ecode, reason):
if ecode in (115, 150):
  pass
else:
  raise socket.error, (ecode, reason)
ret = select.select([s], [s], [], 30)

if len(ret[1]) == 0 and len(ret[0]) == 0:
  s.close()
  raise TimedOut, "on connect "
s.setblocking(1)

  except socket.error, (ecode, reason):
print ecode, reason
time.sleep(10)
s = None

s.send("%s \n\n" % domainname)
page = ""
while 1:
  data = s.recv()
  if not data: break

  page = page + data

  s.close()

  if string.find(page, "No match for") != -1:
raise NoSuchDomain, domainname

  if string.find(page, "No entries found") != -1:
raise NoSuchDomain, domainname

  if string.find(page, "no domain specified") != -1:
raise NoSuchDomain, domainname

  if string.find(page, "NO MATCH") != -1:
raise NoSuchDomain, domainname
  return page

##
##
--
##

class DomainRecord:
  def __init__(self, domain):
self.domain = domain
self.domainid = None
self.created = None
self.lastupdated = None
self.expires = None
self.databaseupdated = None
self.servers = None
self.registrant = None
self.registrant_address = None
self.contacts = {}

def __str__(self):
  return "%s (%s): (created:%s) (lastupdated:%s)
(databaseupdated:%s) (servers:%s) (registrant:%s) (address:%s)
(contacts:%s)" % (self.domain, self.domainid, self.created,
self.lastupdated, self.databaseupdated, self.servers, self.registrant,
repr(self.registrant_address), self.contacts)


##
##
--
##

def _ParseContacts_RegisterCOM(page):
  contactDict = {}
  parts = re.split("((?:(?:Administrative|Billing|Technical|Zone)
Contact,?[ ]*)+:)\n", page)

  contacttypes = None
  for part in parts:
if string.find(part, "Contact:") != -1:
  if part[-1] == ":": part = part[:-1]
  contacttypes = string.split(part, ",")
  continue
part = string.strip(part)
if not part: continue

record = {}

lines = string.split(part, "\n")
m = re.search("(.+)  ([EMAIL PROTECTED])", lines[0])
if m:
  record['name'] = string.strip(m.group(1))
  record['handle'] = None
  record['email'] = string.lower(string.strip(m.group(2)))

  flag = 0
  phonelines = string.strip(lines[1])

Re: Linux Multimedia System

2005-03-13 Thread Roland Heiber
Marek Franke wrote:
too. The whole project is just for fun. Afaik Freevo and/or MythTV are
written in C/C++ and don't have any support for joysticks (afaik!). And the
Freevo is pure python already ;)
Greetings, Roland
--
http://mail.python.org/mailman/listinfo/python-list


Re: is there a problem on this simple code

2005-03-13 Thread Bengt Richter
On Sun, 13 Mar 2005 10:46:52 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:

>Bengt Richter wrote:
>> Sorry for jumping in with a largely irrelevant comment. I didn't look
>> at the code, just sought to illustrate the 6/18 thing further, in a kneejerk 
>> reaction.
>> Though BTW FWIW the visual sequence of glyphs representing the data was more 
>> a str output
>> than repr, I guess:
>> 
>>  >>> repr("C\x01\x02\x10'\x83")
>>  '"C\\x01\\x02\\x10\'\\x83"'
>>  >>> str("C\x01\x02\x10'\x83")
>>  "C\x01\x02\x10'\x83"
>
>Actually, both of those have an additional repr() call
>courtesy of the Python interactive console.  The output
>of str() on that string is unprintable, but the above
>representation has already been repr()ed by Python for
>consumption by fragile hyoo-mans...
Ok,

 >>> print repr("C\x01\x02\x10'\x83")
 "C\x01\x02\x10'\x83"

But note that _no_ str-type string is printable at all until you assume
that it is an encoding identifying a glyph sequence and you (re)encode/interpret
for a device (virtual or not) that has a font and can present the font
information visually to your eyes (or via some modulation of sensible
environment for other senses) ;-)

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


Re: Linux Multimedia System

2005-03-13 Thread Marek Franke
> Be sure to check out freevo at http://freevo.sourceforge.net/ as it is
> quite similar to what you are describing and they are quite far along.
> 
> max

Yes, there are a lot of projects like LMMS, just take a look at
www.freshmeat.net or www.sourceforge.net. Or MythTV is something like LMMS
too. The whole project is just for fun. Afaik Freevo and/or MythTV are
written in C/C++ and don't have any support for joysticks (afaik!). And the
most prjects are going into different directions. We try to put all those
projects together and there are some other ideas what to do with the LMMS.

Marek

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


Re: Coding help...very basic

2005-03-13 Thread Igorati
Hello all, I am still needing some help on this code, I have gone a bit
further on it. Thank you for the help. I am trying to understand how to
make the file searchable and how I am to make the deposit and withdrawl
interact with the transaction class. 

class Account:
def __init__(self, initial):
 self.balance = initial
def deposit(self, amt):
 self.balance = self.balance + amt
def withdraw(self, amt):
 self.balance = self.balance - amt
def getbalance(self):
 return self.balance 

class Transactoin:
def transaction(self, 
   
self.transaction = 
import time
time.asctime()
raw_input("Is this a deposit or withdrawl?")
if withdrawl:
elif 
raw_input("Please enter amount here.")
   
class Deposit(Transaction):
def deposit(self, amt):
self.balance = self.balance + amt
def getbalance(self):
return self.balance

class Withdrawl(Trasaction):
def withdrawl(self, amt):
self.balance = self.balance - amt
def getbalance(self):
return self.balance
import pickle
pickle.dump ((withdrawl), file ('account.pickle', 'w'))
pickle.dump ((deposit), file ('account.pickle', 'w'))



print "Your current account total is.", self.balance


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


Re: Web framework

2005-03-13 Thread Diez B. Roggisch
Joe wrote:

> On 13 Mar 2005 01:13:00 -0800, [EMAIL PROTECTED] wrote:
> 
>>You should definitely have a look at Zope 3. There is good
>>documentation available and it can do a lot of good stuff.
> 
> But then, the thing I hate about Zope, is that source code is not
> accessible with normal development tools since it's stuck in the ZODB.

Plain wrong. You can access them via FTP and WEBDAV. In kde under linux, all
file-io can be done through these protocols, so you can operate on them as
if they were local files.
-- 
Regards,

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


Re: Linux Multimedia System

2005-03-13 Thread Max Erickson

Marek Franke wrote:
> Hi there,
>
> we have started with some people from our LUG (Linux User Group) a
'little'
> project, called LMMS (Linux Multimedia System). When it's 'finished'
it
> shall be a window-manager for use on TV and handle with
joysticks/gamepads.
>
> As the name says, it is for multimedia-applications, like listening
to
> music, watching videos and maybe playing some games. The idea is to
create
> a gui for application like mplayer, ogg123, mpg123, cdrecord etc.
>
> For now there are some widgets for displaying images, labels and some
> messages. Actually there is a working LMMS with a little menu, an
> image-viewer and a CD-player. Supperted joysticks/gamepads are Gravis
> Gamepad Pro, Nintendo's SNES Pads, Microsoft's X-Box pad and
keyboard.
>
> The whole project is written in python/pygame and can be found here:
> http://home.arcor.de/mfranke78/
> There is a little mailinglist too (German & Yahoo):
> http://de.groups.yahoo.com/group/dulugprojekt/
>
> Remember that the whole project is very basic for now! But it seems
to work.
>
> Greets, Marek

Be sure to check out freevo at http://freevo.sourceforge.net/ as it is
quite similar to what you are describing and they are quite far along.

max

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


Re: Web framework

2005-03-13 Thread Joe
On 13 Mar 2005 01:13:00 -0800, [EMAIL PROTECTED] wrote:

>You should definitely have a look at Zope 3. There is good
>documentation available and it can do a lot of good stuff.

But then, the thing I hate about Zope, is that source code is not
accessible with normal development tools since it's stuck in the ZODB.

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


Re: issues installing readine-1.12 on WinXP

2005-03-13 Thread Michele Simionato
No, I don't even know how to get it under Windows (usually I use
Linux). Switching to the US keyboard
does not help, anyway. I get the same error.

  Michele

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


Linux Multimedia System

2005-03-13 Thread Marek Franke
Hi there,

we have started with some people from our LUG (Linux User Group) a 'little'
project, called LMMS (Linux Multimedia System). When it's 'finished' it
shall be a window-manager for use on TV and handle with joysticks/gamepads. 

As the name says, it is for multimedia-applications, like listening to
music, watching videos and maybe playing some games. The idea is to create
a gui for application like mplayer, ogg123, mpg123, cdrecord etc.

For now there are some widgets for displaying images, labels and some
messages. Actually there is a working LMMS with a little menu, an
image-viewer and a CD-player. Supperted joysticks/gamepads are Gravis
Gamepad Pro, Nintendo's SNES Pads, Microsoft's X-Box pad and keyboard.

The whole project is written in python/pygame and can be found here:
http://home.arcor.de/mfranke78/
There is a little mailinglist too (German & Yahoo):
http://de.groups.yahoo.com/group/dulugprojekt/

Remember that the whole project is very basic for now! But it seems to work.

Greets, Marek

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


how to delete the close button (the X on the right most corner of the window) on a window

2005-03-13 Thread jrlen balane
i am working on an MDIParentFrame and MDIChildFrame. Now, what i want
to do is make the ChildFrame not that easy to close by removing the
close button (the X on the right most corner of the window) if this is
possible...

how am i going to do this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turning String into Numerical Equation

2005-03-13 Thread Brian Kazian
Wow, thanks so much guys!


"Michael Spencer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Brian Kazian wrote:
>> Thanks for the help, I didn't even think of that.
>>
>> I'm guessing there's no easy way to handle exponents or logarithmic 
>> functions?  I will be running into these two types as well.
>> "Artie Gold" <[EMAIL PROTECTED]> wrote in message 
>> news:[EMAIL PROTECTED]
>>
>
> eval will handle exponents just fine: try eval("2**16")
> in fact, it will evaluate any legal python expression*
>
> logarithmic functions live in the math module, so you will either need to 
> import the functions/symbols you want from math, or give that namespace to 
> eval:
>
>  >>> import math
>  >>> eval("log(e)", vars(math))
>  1.0
>  >>>
>
> * this means that, eval("sys.exit()") will likely stop your interpreter, 
> and there are various other inputs with possibly harmful consequences.
>
> Concerns like these may send you back to your original idea of doing your 
> own expression parsing.  The good news is that the compiler package will 
> parse any legal Python expression, and return an Abstract Syntax Tree. 
> It's straightforward to walk the tree and achieve fine-grain control over 
> evaluation.
>
> Here's an example of a math calculator that doesn't use eval.  It 
> evaluates any Python scalar numeric expression (i.e., excludes container 
> types), and only those symbols and functions that are explicity specified. 
> This code is barely tested and probably not bullet-proof.  But with care 
> and testing it should be possible to achieve a good balance of 
> functionality and security.
>
>
> import compiler
> import types
> import math
>
> # create a namespace of useful funcs
> mathfuncs = {"abs":abs, "min": min, "max": max}
> mathfuncs.update((funcname, getattr(math,funcname)) for funcname in 
> vars(math)
> if not funcname.startswith("_"))
>
> mathsymbols = {"pi":math.pi, "e":math.e}
>
> # define acceptable types - others will raise an exception if
> # entered as literals
> mathtypes = (int, float, long, complex)
>
> class CalcError(Exception):
> def __init__(self,error,descr = None,node = None):
> self.error = error
> self.descr = descr
> self.node = node
> #self.lineno = getattr(node,"lineno",None)
>
> def __repr__(self):
> return "%s: %s" % (self.error, self.descr)
> __str__ = __repr__
>
>
> class EvalCalc(object):
>
> def __init__(self):
> self._cache = {} # dispatch table
>
> def visit(self, node,**kw):
> cls = node.__class__
> meth = self._cache.setdefault(cls,
> getattr(self,'visit'+cls.__name__,self.default))
> return meth(node, **kw)
>
> def visitExpression(self, node, **kw):
> return self.visit(node.node)
>
> def visitConst(self, node, **kw):
> value = node.value
> if isinstance(value, mathtypes):
> return node.value
> else:
> raise CalcError("Not a numeric type", value)
>
> # Binary Ops
> def visitAdd(self,node,**kw):
> return self.visit(node.left) + self.visit(node.right)
> def visitDiv(self,node,**kw):
> return self.visit(node.left) / self.visit(node.right)
> def visitFloorDiv(self,node,**kw):
> return self.visit(node.left) // self.visit(node.right)
> def visitLeftShift(self,node,**kw):
> return self.visit(node.left) << self.visit(node.right)
> def visitMod(self,node,**kw):
> return self.visit(node.left) % self.visit(node.right)
> def visitMul(self,node,**kw):
> return self.visit(node.left) * self.visit(node.right)
> def visitPower(self,node,**kw):
> return self.visit(node.left) ** self.visit(node.right)
> def visitRightShift(self,node,**kw):
> return self.visit(node.left) >> self.visit(node.right)
> def visitSub(self,node,**kw):
> return self.visit(node.left) - self.visit(node.right)
>
> # Unary ops
> def visitNot(self,node,*kw):
> return not self.visit(node.expr)
> def visitUnarySub(self,node,*kw):
> return -self.visit(node.expr)
> def visitInvert(self,node,*kw):
> return ~self.visit(node.expr)
> def visitUnaryAdd(self,node,*kw):
> return +self.visit(node.expr)
>
> # Logical Ops
> def visitAnd(self,node,**kw):
> return reduce(lambda a,b: a and b,[self.visit(arg) for arg in 
> node.nodes])
> def visitBitand(self,node,**kw):
> return reduce(lambda a,b: a & b,[self.visit(arg) for arg in 
> node.nodes])
> def visitBitor(self,node,**kw):
> return reduce(lambda a,b: a | b,[self.visit(arg) for arg in 
> node.nodes])
> def visitBitxor(self,node,**kw):
> return reduce(lambda a,b: a ^ b,[self.visit(arg) for arg in 
> node.nodes])
> def visitCompare(self,node,**kw):
> comparisons = {
> "<": operator.lt, # strictly less than
> "<=": operator.le,# less than or equal
>  

Re: is there a problem on this simple code

2005-03-13 Thread Jan Rienyer Gadil
@ sir Peter
so you mean that it is correct (at least on the unpack() part) 

when i run this program on IDLE , Python 2.3 (enthought edition),
nothing is outputted on the shell, until i decide to close the shell,
wherein it tells me if i would like to kill a process...

import serial
import string
import time
from struct import *

ser = serial.Serial()

ser.baudrate = 9600
ser.port = 0
ser
ser.close()
ser.open()

command = 67
message_no = 1
total_data = 2

item = 1

for item in range(1, 30001, 250):
   data_hi, data_lo = divmod(item, 0x100)
   checksum = -(data_hi + data_lo + 0x46) & 0xff
   ser.write(pack('6B', command, message_no, total_data, data_lo,
data_hi, checksum))

   rx_data1=0
   while (rx_data1 != 0x46):
   rx_data1 = ser.read(1)
   (rx_command) = unpack('1B', rx_data1)

rx_data2=ser.read(9)
(rx_msg_no, rx_no_databyte, temp1, temp2, pyra1, pyra2, voltage,
 current, rx_checksum) = unpack('9B', data)
 print rx_command, rx_msg_no, rx_no_databyte, temp1, temp2, pyra1,
 pyra2, voltage, current, rx_checksum

ser.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


urllib's functionality with urllib2

2005-03-13 Thread Monty
Hello,
Sorry for this maybe stupid newbie question but I didn't find any
answer in all my readings about python:

With urllib, using urlretrieve, it's possible to get the number of
blocks transferred and the total size of the file.

Is it possible to get those informations with urllib2 ?

( I have to use urllib2 and a Request Object with headers, urlretieve
doesn't work. Well, at least, all my attempts with urllib were
denied...)

Thanks for any help,

Monty

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


Re: Turning String into Numerical Equation

2005-03-13 Thread Paul McGuire
Almost this exact parser, called fourFn.py, is included in the examples
with pyparsing (at http://pyparsing.sourceforge.net).  Since it is pure
Python, you can extend the grammar with whatever builtin functions you
like.  But it *is* a parser, not just a short cut.

-- Paul

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


Re: survey

2005-03-13 Thread Peter Hansen
D H wrote:
Peter Hansen wrote:
Dave Zhu wrote:
Is there any survey on scripting languages? I would
like to get information on several scripting languages
including Python, Perl, Ruby, Tcl, etc.
What kind of information? ...
See the other responses to his question.
Why would I want to do that?  Did somebody else manage
to read his mind and post the missing information?
Or are you just assuming that the others have correctly
guessed what he intended?  (FWIW, I have been skimming
the other responses as the thread progresses, and
even so your comment still makes no sense to me.)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


An array of a "list" of names.

2005-03-13 Thread spencer
Hi,
I'm using NumPy to build an array of a
list of names that will be of multiple
dimensions.I did do a google on this 
subject, but couldn't find what I was looking
for. The problem I'm having is there are 
space between each character in each name.
To fix this
I used the attribute 'tostring'. This did
remove the spaces but now I got to walk
the string to rebuild the array with
each name being a list.Is there an
easier way? If so, how?
TIA
Wayne


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


tkinter: always scroll to show last line of text

2005-03-13 Thread Benjamin Rutt
I have a tkinter 'Text' and 'Scrollbar' connected and working
normally.  When a new line of text is inserted (because I'm monitoring
an output stream), I'd like the text and scrollbar to be scrolled to
the bottom, so the latest line of text is always shown.  How to do
this?  Thanks,
-- 
Benjamin Rutt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does this not work?

2005-03-13 Thread Peter Hansen
D H wrote:
Ask on the wxpython or python-tutor list instead of this one.  You'll 
get better help than there as you've already found out.
Not likely.  IMHO he got the best help he could possibly
have gotten, but clearly that's debatable. :-)
The only thing I'd agree with is what Michael Hoffman said about posting 
a snippet of your code instead of a zip file.
This is also debatable.  I'd strongly recommend against
ever referencing a zip file in some other location when
posting requests for help, unless it's a very complex
situation and you have laid the groundwork for people
to be bothered going to all that effort.  Even then,
there's at least one serious disadvantage... see below.
The benefits of posting a snippet are many, provided
we define an appropriate snippet to be "the smallest
piece of code that you can produce which reproduces
the problem and has the fewest external dependencies"
or some such:
1. The act of creating the above almost always leads
to the discovery of the problem and a solution, meaning
you don't even get to the posting stage.
2. Posting a snippet vastly increases the likelihood
someone (often many) will help, versus the chances when
you post a link to code elsewhere (which are near zero).
3. Posting a snippet means that the code is archived
along with the request, allowing people who follow
along later, perhaps with the same question, to reliably
find the code in question, and the fixed code in the
followups.  Posting links to elsewhere makes it very
likely the code in question will have vanished, wasting
lots of time for those who come later.
4. It's just plain polite, good netiquette.
Caveat: posting monster programs is never a good idea,
and a good rule of thumb is probably that any snippet
posted (for any reason) in a mailing list or newsgroup
like this should be no more than about fifty lines
long.  That should be enough to reproduce just about
any problem, if you aren't lazy...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web framework

2005-03-13 Thread Sridhar
I'd say Nevow! For apache setup, you might be interested in my wsgi [1]
implementation.

[1]
http://twistedmatrix.com/pipermail/twisted-web/2005-March/001293.html

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


Re: confusion around CustomException example in 'Python in a Nutshell'

2005-03-13 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
  What I am trying to do is get information
from a raised custom exception.  I am catching the exception in a
main() function but it was actually raised in a separate module
function.  It would be nice if I could print out where the exception
was raised from (module.function name + line number).
Ah, good.  Exactly what the useful functions in the
'traceback' module are intended for, if I understand
your meaning...
If doing "traceback.print_exc()" is printing the
information you want (in a traceback that has much
more than what you say you want), then you can use
the other functions in that module, and methods in
the 'traceback' objects themselves (the third item
in the tuple returned by sys.exc_info()), will
give you all you could ever want...
Google can help you find examples of usage as well,
in the archives for this group.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: is there a problem on this simple code

2005-03-13 Thread Peter Hansen
Dennis Lee Bieber wrote:
rx_data1=0
while (rx_data1 != 0x46):
   rx_data1 = ser.read(1)
   (rx_command) = unpack('1B', rx_data1)
Isn't this unpack rather redundant -- assuming ser.read(1) only
reads one byte, then rx_data1 and rx_command would be identical.
Brain fart... unpack converts the raw bytes to integer
values with the "B" format character.  You're thinking
of what would happen with a "1c" format.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >