Re: Galois field

2004-12-03 Thread Mikael Olofsson
Roie Kerstein wrote:
I am looking for a python package that deals with galois fields.
Does anybody know where can I find it?
Googling for
   python "finite field"
reveals among other things the URLs
   http://www.hpcf.upr.edu/~humberto/software/fields/
   http://www.csua.berkeley.edu/~emin/source_code/py_ecc/
I have not looked into those, but at least the first one seems to be in a 
very early state, since its version number is 0.1.1. The second one contains 
code for handling Reed-Solomon codes, which among other things includes 
arithmetic for finite fields.

Good luck!
/Mikael Olofsson
Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE])
Linköpings universitet
---
E-Mail:  [EMAIL PROTECTED]
WWW: http://www.dtr.isy.liu.se/en/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
---
Linköpings kammarkör: www.kammarkoren.com   Vi söker tenorer och basar! 

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


Re: Python 2.4 and Tkinter

2004-12-03 Thread Eric Brunel
Jeffrey Barish wrote:
[snip]
OK, I downloaded tcl8.4.8 and tk8.4.8.  They are now installed.  Back to
python2.4 make.  It now bombs at:
gcc -pthread -shared build/temp.linux-i686-2.4/_tkinter.o
build/temp.linux-i686-2.4/tkappinit.o -L/usr/X11R6/lib64
-L/usr/X11R6/lib -L/usr/local/lib -ltk8.4 -ltcl8.4 -lX11 -o
build/lib.linux-i686-2.4/_tkinter.so
*** WARNING: renaming "_tkinter" since importing it failed: libtk8.4.so:
cannot open shared object file: No such file or directory
running build_scripts
Here's what I don't get:
[EMAIL PROTECTED]:/tmp/Python-2.4# ls -l /usr/local/lib/libtk8.4.so
-rwxr-xr-x1 root staff  893866 2004-12-02
15:28 /usr/local/lib/libtk8.4.so
The library is there but gcc claims that it isn't.  Any suggestions?
Is /usr/local/lib in your LD_LIBRARY_PATH environment variable? It needs to be 
in the compiler options for the compilation phase, but then you have to put it 
in $LD_LIBRARY_PATH to be able to import the module.

HTH
--
- Eric Brunel  -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: PySQLLite Speed

2004-12-03 Thread Gerhard Haering
On Thu, Dec 02, 2004 at 04:22:25PM -0800, Kevin wrote:
> Hello All,
> 
> I wondering if anyone has encountered the same issue
> with using PySQL.  This is my first time using this DB
> so this preformance may be typical.  I'm reading an
> ASCII file through PyParse that contains about 1.3Meg
> of Float data.  8000 Triangles (3 Vertexes and 1
> Normal).  This file reads fine the PC has a
> utilization of 50% for Python.  Then when it starts to
> write the Database, the PC Util drops to 1-2% and it
> takes forever.  I'm not PC related preformance
> barriers that I'm aware of.
> 
> Regards,
>Kevin
> 
> OS : Windows
> PySQLLite Version: 1.1.5

You're not doing silly things like using pysqlite's autocommit mode or
.commit()-ing too often, are you?

Like already mentioned, PRAGMA SYNCHRONOUS should boost performance.

-- Gerhard


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

hello all

2004-12-03 Thread Ishwor Gurung
Hello all,
  I am just starting out on learning Python and joined this list. I
have grabbed the Learning Perl book by Mark & David. This book really
seems good so far.. the concepts are explained pretty nicely. :) I
have a background a bit in Java but Python seems so cooler. The
concept of Dynamically assigning values n the objects springing into
existence is really nice to see especially you don't have to declare
variable everytime its used. In this book though it says Python 3.0 as
upcoming python version but all i see so far is Python 2.4 ?? Any
hints anyone has? So contrasting with Java  which is a bit like C++
where values and object has to be "created" before assigning, Python
seems very typical of "on the edge" language, "ready to go" language
:)
cheers,
Ishwor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PySQLLite Speed

2004-12-03 Thread Gerhard Haering
On Thu, Dec 02, 2004 at 08:39:31PM -0800, Kevin wrote:
> Hello All,
> 
> I wanted to thank Roger Binn for his email.  He had
> the answer to my issue with writing speed.  It's
> actual made an incredible change in the preformace.  I
> didn't have to go all the way to implementing the
> synchronous mode(for my app).  Previously, I was
> insert one record at a time.  The key was to write
> them all at one time.  I moved up to a 13 meg file and
> wrote it to the db in secs.  Now the issue is the 120
> meg of RAM consumed by PyParse to read in a 13 meg
> file.  If anyone has thoughts on that, it would be
> great.  Otherwise, I will repost under a more specific
> email.
> 
> Thanks,
>   Kevin
> 
> 
> 
> db.execute("begin")
> 
> while i < TriNum
>db.execute("""insert into TABLE(V1_x)
> values(%f),""" (data[i]))
> i = i + 1

If you're using pysqlite 2.0alpha, then .executemany() will boost performance
*a lot*. For pysqlite 1.x, unfortunately, it won't make any difference. But
generally, .executemany() is a good idea.

Also note that the preferred way of using transactions is to let the DB-API
adapter BEGIN the connection for you, then invoke .commit() on the connection
object.

Sending BEGIN/ROLLBACK/COMMIT via .execute() is bad.

-- Gerhard


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

Re: ANNOUNCE: Ice 2.0 released

2004-12-03 Thread James Stroud

> > PS: Please feel free to set FU-Ts as appropriate.
>
> What are FU-Ts?


"It took me 3 hours to figure out FU meant 'Felix Unger'.""
   -- Oscar Madison, The Odd Couple

MTC.




-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
611 Charles E. Young Dr. S.
MBI 205, UCLA 951570
Los Angeles CA 90095-1570
http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: efficient intersection of lists with rounding

2004-12-03 Thread Raymond Hettinger
"Gordon Williams" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> I have to lists that I need to find the common numbers (2nd rounded to
> nearest integral) and I am wondering if there is a more efficient way of
> doing it.
>
> >>> a= [(123,1.3),(123,2.4),(123,7.8),(123,10.2)]
> >>> b= [(123, 0.9), (123, 1.9), (123, 8.0)]
> >>> [ (i,round(j)) for i,j in a for l,m in b if (i,round(j)) ==
> (l,round(m))]
> [(123, 1.0), (123, 2.0), (123, 8.0)]
> >>>
> This works but a and b can be in the order of 30K long.
>
> A couple of other bits of info.
> - a and b are ordered smallest to largest (could bisect module be used?)
> - in the future I will want to round the second number of closest 0.25
> rather than whole number.
>
> Would the sets module be more efficient?

Yes:

>>> set((x,round(y)) for x,y in a) & set((x,round(y)) for x,y in b)
set([(123, 8.0), (123, 2.0), (123, 1.0)])


> I'm using python 2.3.

>>> from sets import Set as set
>>> set([(x,round(y)) for x,y in a]) & set([(x,round(y)) for x,y in b])
set([(123, 8.0), (123, 2.0), (123, 1.0)])


Raymond Hettinger


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


Re: installing 2.4

2004-12-03 Thread Matt Gerrans
"Peter Hansen" <[EMAIL PROTECTED]> wrote:
> Only pure Python code can run without change on a newer interpreter.

Is the interpreter smart enough to rebuild a pyc (if the corresponding py 
file is there of course) file that was built by a previous version?



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


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

2004-12-03 Thread David Fraser
Rocco Moretti wrote:

For some reason I can't seem to make use of the google links. When I 
use the above eg

http://groups.google.com/groups?frame=right&th=e562a771d1c827c9
I get a not found google page with url
http://groups-beta.google.com/groups?frame=right&th=e562a771d1c827c9
really wanted to spell file in a sickly manner :)

It seems Google recently redid their groups interface. By searching for 
"group:comp.lang.python Coghlan" on http://groups.google.com, I was able 
to find the probable post (Sort by Date, titled "Restricted Execution on 
the cheap", about four down)
Nicely, google seems to have reverted their main google groups page to 
the original system, and left the new one at groups-beta.google.com

I'm sorry I'm not able to give a direct URL, but it seems they've 
switched over to a horrendously long, stateful URL system which doesn't 
lend itself to direct linkage.
Doesn't seem stateful to me, just has different thread / message ids to 
the old system:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1db72429a2b05ce0/2c1679d365ffe9dd#2c1679d365ffe9dd
The syntax is thread/$threadid/$messageid#$messageid
At least for me, these URLs are transferable between computers / browsers
You can also access the message directly:
http://groups-beta.google.com/group/comp.lang.python/msg/2c1679d365ffe9dd
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: inheritance problem with 2 cooperative methods

2004-12-03 Thread David Fraser
Dan Perl wrote:
Here is a problem I am having trouble with and I hope someone in this group 
will suggest a solution.  First, some code that works.  3 classes that are 
derived from each other (A->B->C), each one implementing only 2 methods, 
__init__ and setConfig.
---
#!/usr/bin/python
class A (object):
   def __init__(self):
  super(A, self).__init__()
  self.x = 0
   def setConfig(self, config):
  self.x += config['x']

class B (A):
   def __init__(self):
  super(B, self).__init__()
  self.y = 0
   def setConfig(self, config):
  super(B, self).setConfig(config)
  self.y += config['y']
class C (B):
   def __init__(self):
  super(C, self).__init__()
  self.z = 0
   def setConfig(self, config):
  super(C, self).setConfig(config)
  self.z += config['z']
config = {'x':1, 'y':2, 'z':3}
alpha = A()
alpha.setConfig(config)
print alpha.x
beta = B()
beta.setConfig(config)
print beta.x, beta.y
beta.setConfig(config)
print beta.x, beta.y
gamma = C()
gamma.setConfig(config)
print gamma.x, gamma.y, gamma.z
gamma.setConfig(config)
print gamma.x, gamma.y, gamma.z
--
The output from that code is:
1
1 2
2 4
1 2 3
2 4 6
So far, so good!  But let's assume that I want to change the __init__ 
methods so that they take a configuration as an argument so the objects are 
created and configured in one step, like this:
alpha = A(config)

How can the code be changed to implement this?  It is tempting to modify the 
__init__ methods like this:
class A (object):
   def __init__(self, config):
  super(A, self).__init__(config)
  self.x = 0
  A.setConfig(self, config)

However, if implemented this way, the output is:
1
2 2
3 4
3 4 3
4 6 6
This shows that setConfig gets called more than once because both __init__ 
and setConfig are cooperative methods.

I have been thinking about this for a day now and I cannot find a good 
solution.  I imagine this would be a common problem and that there would be 
a recipe somewhere, but I couldn't find one (I looked in the Python 
Cookbook).  I've thought of creating 2 separate methods instead of 
setConfig, one that does the "local" configuration and another one that 
takes care of invoking super.  But I don't like the idea of creating 2 
methods in each class and I haven't been able to think of a way to solve the 
problem with just one change in the base class that would be inherited by 
all the subclasses.

Anyone has any ideas?  Thanks.
What about using an attribute in the base class to remember whether 
initial config has been done? This seems to work:

#!/usr/bin/python
class A (object):
   def __init__(self, config):
  self.x = 0
  self.configinitialized = False
  super(A, self).__init__()
  if not self.configinitialized:
self.setConfig(config)
   def setConfig(self, config):
  self.x += config['x']
  self.configset = True
class B (A):
   def __init__(self, config):
  self.y = 0
  super(B, self).__init__(config)
   def setConfig(self, config):
  super(B, self).setConfig(config)
  self.y += config['y']
class C (B):
   def __init__(self, config):
  self.z = 0
  super(C, self).__init__(config)
   def setConfig(self, config):
  super(C, self).setConfig(config)
  self.z += config['z']
config = {'x':1, 'y':2, 'z':3}
alpha = A(config)
print alpha.x
beta = B(config)
print beta.x, beta.y
beta.setConfig(config)
print beta.x, beta.y
gamma = C(config)
print gamma.x, gamma.y, gamma.z
gamma.setConfig(config)
print gamma.x, gamma.y, gamma.z
--
http://mail.python.org/mailman/listinfo/python-list


window size in IDLE

2004-12-03 Thread p.kosina
Can I somehow in config-main.cfg set how big shall (and where) open  the 
IDLE window?  Cause in my w98 it is always opening so that I can not see 
the bottom line

Thank you
Pavel
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic use of CSV module to skip headers?

2004-12-03 Thread Peter Otten
Ramon Felciano wrote:

> I'm using the csv module to parse a tab-delimited file and wondered
> whether there was a more elegant way to skip an possible header line.
> I'm doing
> 
> line = 0
> reader = csv.reader(file(filename))
> for row in reader:
> if (ignoreFirstLine & line == 0):
> continue
> line = line+1
> # do something with row
> 
> The only thing I could think of was to specialize the default reader
> class with an extra skipHeaderLine constructor parameter so that its
> next() method can skip the first line appropriate. Is there any other
> cleaner way to do it w/out subclassing the stdlib?

>>> import csv
>>> f = file("tmp.csv")
>>> f.next()
'# header\n'
>>> for row in csv.reader(f):
... print row
...
['a', 'b', 'c']
['1', '2', '3']

This way the reader need not mess with the header at all.

Peter

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


Re: How is Python designed?

2004-12-03 Thread Limin Fu

--- Timo Virkkala <[EMAIL PROTECTED]> wrote:
> 
> Do you mean the structure and design of the
> language, or the process of 
> designing the language?

I mean the structure and design of the language.
Sorry for the umbiguous question.

> 
> Well, in either case, you'll probably find your
> answer at http://www.python.org
> 
> Take a look at the Docs -> Language Reference and
> PEP sections.

I will have a look at there. Thanks.
Limin



__ 
Do you Yahoo!? 
Dress up your holiday email, Hollywood style. Learn more.
http://celebrity.mail.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


MDaemon Warning - virus found: Mail System Error - Returned Mail

2004-12-03 Thread The Post Office

*** WARNING **
Este mensaje ha sido analizado por MDaemon AntiVirus y ha encontrado 
un fichero anexo(s) infectado(s).  Por favor revise el reporte de abajo.

AttachmentVirus name   Action taken
--
letter.zipI-Worm.Mydoom.m  Removed


**


Dear user of python.org,

We have detected that your email account was used to send a huge amount of 
unsolicited email during this week.
Obviously, your computer was compromised and now runs a hidden proxy server.

We recommend that you follow instructions in order to keep your computer safe.

Best wishes,
The python.org support team.

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

Re: pre-PEP generic objects

2004-12-03 Thread Nick Craig-Wood
Peter Otten wrote:
> Functions written in Python have a __get__ attribute while builtin
> functions (implemented in C) don't. Python-coded functions therefore
> automatically act as descriptors while builtins are just another
> attribute.

Jp Calderone <[EMAIL PROTECTED]> wrote:
> When the class object is created, the namespace is scanned for
> instances of .  For those and only those, a
> descriptor is created which will produce bound and unbound methods.
> Instances of other types, such as  or  'builtin_function_or_method'>, are ignored, leading to the critical
> difference in this case:

I think I finally understand now - thank you to you both!

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


Re: RotatingFileHandler

2004-12-03 Thread Vinay Sajip
Robert Brewer wrote:
Kamus of Kadizhar wrote:
I'm having a problem with logging.  I have an older app that used the
RotatingFileHandler before it became part of the main distribution (I
guess in 2.3).
[snip]
The offending snippet of code is:
  logFile = 
logging.handlers.RotatingFileHandler('/var/log/user/movies2.lo
g','a',2000,4)
  logFile.emit(movieName)

Making a quick run-through of the logging module, it looks like you need
to have a Formatter object added to your Handler:
filename = '/var/log/user/movies2.log'
logFile = logging.handlers.RotatingFileHandler(filename,'a',2000,4)
formatter = logging.Formatter()
logFile.setFormatter(formatter)
...then you can call emit.
Of course, you should not normally be calling emit() from user code. The 
 correct approach is to log events to loggers, and not emit them to 
handlers directly.

Best regards,
Vinay Sajip
--
http://mail.python.org/mailman/listinfo/python-list


Re: How is Python designed?

2004-12-03 Thread Limin Fu
To clarify, I mean the internal structure and design
of python interpreter. Any hint? Thanks.
Regards,
Limin



__ 
Do you Yahoo!? 
Yahoo! Mail - 250MB free storage. Do more. Manage less. 
http://info.mail.yahoo.com/mail_250
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pickle and py2exe

2004-12-03 Thread Johan Lindberg
>>> Im trying to compile a script with py2exe. The pickle module is
causing the
>>> program to give an error.
>>> 
>>> Traceback (most recent call last):
>>>   File "SETIstat.pyw", line 330, in ?
>>>   File "SETIstat.pyw", line 84, in start_up
>>>   File "SETIstat.pyw", line 79, in config_load
>>>   File "pickle.pyc", line 1390, in load
>>>   File "pickle.pyc", line 872, in load
>>>   File "pickle.pyc", line 985, in load_string
>>> LookupError: unknown encoding: string-escape
>>> 
>>> the data in the pickled file is a dictionary containing a couple
>>> strings. The
>>> strings do contain \n and \t charaters but no other special
characters or
>>> anything. 
>>> 
>>> Does anyone have any suggestions to what I can try to get around
this? The
>>> pickle module works fine when the .pyw file is run. Its only when
I compile
>>> this is there an issue. 
>>> 
>>> Thanks for any help,
>>> 
>>> Justin

>>Have you included string-escape encoding in your setup.py?
>>My guess is that you can fix the problem with something similar to:
>>
>> from distutils.core import setup
>> import py2exe
>> opts = { "py2exe": { "packages": ["encodings"], } }
>> setup(windows= ["spam.py"], options= opts)
>>
>>in your setup.py.
>>
>>Hope it helps
>>/Johan Lindberg
 
> Thanks Johan,  but unfortunately the same traceback is given in the log. 
> I should have mentioned in my previous post that Im using win2000, if it
> matters any. 
> 

Hi Justin.

I'm assuming that your library.zip now has several encoding-files in
it? And more specifically that you have a file called
"string_escape.pyc" in path "encodings". Right?

I don't think it's got anything to do with your windows version but it
might be helpful to know your python and py2exe versions.
Unfortunately I haven't been able to reproduce the error on either of
my windows machines (using python 2.3.4 and py2exe 0.5.3 on both, one
is win2k and the other XP).

Line 985 in pickle.py says:
self.append(rep.decode("string-escape"))
so that's why you need the encoding, even though you "don't use it".
Will the same lookup error show up in a smallest possible program,
such as:

 # encoding= iso-8859-1
 spam= "Det här är svenska"
 print spam.decode("string-escape")

What happens when you compile that script to an exe using the above
setup.py?
(don't forget to change windows= ["spam.py"] to console= ["spam.py"])

Also you might want to try the py2exe-users list (see
http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/py2exe-users).

BR
/Johan Lindberg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File locking and logging

2004-12-03 Thread Vinay Sajip
Kamus of Kadizhar <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> Thanks to Robert Brewer, I got enough insight into logging to make it work
> 
> Now I have another issue:  file locking.  Sorry if this is a very basic
> question, but I can't find a handy reference anywhere that mentions this.
> 
> When a logger opens a log file for append, is it automatically locked so
> other processes cannot write to it?  And what happens if two or more
> processes attempt to log an event at the same time?
> 
> Here's my situation.  I have two or three workstations that will log an
> event (the playing of a movie).  The log file is NFS mounted and all
> workstations will use the same log file.  How is file locking implemented?
> Or is it?
> 

No file locking is attempted by current logging handlers with respect
to other processes - an ordinary open() call is used. Within a given
Python process, concurrency support is is provided through threading
locks. If you need bullet-proof operation in the scenario where
multiple workstations are logging to the same file, you can do this
through having all workstations log via a SocketHandler to a
designated node, where you run a server process which locally logs to
file events received across the network. There is a working example of
this in the Python 2.4 docs.

Best regards,


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


Re: Galois field

2004-12-03 Thread Roie Kerstein
Terry Reedy wrote:

> Googling python 'galois fields' gives over 500 hits, the most recent being
> your identical question on catalog-sig.  Have you looked at them?

Yes. Nothing there is a module. only discussions.
:(

-- 
Best regards
Roie Kerstein

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


Re: efficient intersection of lists with rounding

2004-12-03 Thread Michael Hoffman
Steven Bethard wrote:
Yeah, almost certainly since he's looking at lists 3K long.  If they 
were small, you never know since the list comprehension gets the C-code 
speedup, while sets.Set is Python code:

> [list comprehension]
1 loops, best of 3: 27.5 usec per loop
> [Python 2.3 Set]
1 loops, best of 3: 47.7 usec per loop
In the case given, the O(n**2) list comprehension is faster than the 
O(n) set intersection.  Of course, this is not likely to be true with 
any reasonable sized data.  But it's something worth keeping in mind.
Of course if you're working with a dataset that small, it probably 
doesn't really matter which of these implementations you use.

The exception would be if this were in an inner loop in the actual 
program and *were* being run 1 times or more.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Virus in your Mail to empire.support

2004-12-03 Thread root at smtp

  The VirusCheck at the IMST generated the following Message:

 V I R U S  A L E R T

  Our VirusCheck found a Virus (W32/Netsky-Q) in your eMail to "empire.support".

  This eMail has been deleted !

  Now it is on you to check your System for Viruses   



  This System is running with Linux and Amavis (www.amavis.org).   :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


python-mode question

2004-12-03 Thread Thomas Heller
When I edit a Python script with XEmacs, then hit C-c C-c, the script is
executed, the output is shown in a *Python Output* buffer, and the
cursor is moved into this buffer.

How can I change the behaviour so that the cursor stays where it was
before?  I'm using Revision 4.29, if it matters.

Thanks,

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


Curses programming, threads?

2004-12-03 Thread Bartlomiej Rymarski
Hello, 

I'm writing this little program, and I've came across a function
that I need to call. Since the execution of the function takes a 
real long time I want to put a timer, or an animated 'loading' 
screen (it would be best if it was a progressbar). The questions is
how to make two commands to run at the same time. 

I'm talking about a function which (for example) is connecting to
the database, and while it's connecting I would like to display a
nice loading animation. It could be a ascii sequence like this:
 [/] [-] [\] [|] [/] [-] [\] [|]

I could write a function like this:

#v+
def function:
print "[/]"
command
print "[-]"
command
print "[\]"
command
...
#v-

But is this really the way other programs work? I don't think so.
And they don't use threads AFAIK. How can I accomplish something 
like this?

It would be best if I could operate with like this:

#v+
def function:
do loader() while
connect_db()
#v-

And the loader() function would run in a loop until connect_db() is 
is finished. Is that possible in python? Or are there any other,
better ways to do it?

Thanks a lot.

Regards,

-- 
Bartek Rymarski <[EMAIL PROTECTED]>
$ %blow
bash: fg: %blow: no such job
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: window size in IDLE

2004-12-03 Thread Ishwor Gurung
hi kosina although i am new to this list as well, please CC to the
python list as well. That way not only 'we' but everyone benefits. :)

On Fri, 03 Dec 2004 11:30:06 +0100, gen2n <[EMAIL PROTECTED]> wrote:
> Thanks a lot. Could you help me once more with beginners question?
> In IDLE, when saving a file, I have to always add .py to to name. Otherwise
> it didnt work then.
> Could it also be somehow automatically?

 I don't really understand what you mean by 'automatically' but i
tried the following in my machine :

test ( i didn't put .py as extension to test)
*
print "Hello";

Then at the prompt i did
python test

hello 

It seems that it works for me both at the prompt (using Python
interpreter as well as in IDLE's Run > Run Module (F5)
 :)
> I have IDLE 1.0.2.

IDLE 1.1 is pretty good. If you have chance grab it :)
[snip]
 
cheers,
Ishwor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Curses programming, threads?

2004-12-03 Thread Bartlomiej Rymarski
Bartlomiej Rymarski <[EMAIL PROTECTED]> wrote:
> [...]
> And the loader() function would run in a loop until connect_db() is 
> is finished. Is that possible in python? Or are there any other,
> better ways to do it?
> [...]

Oh, I forgot - I'm using Linux, and curses module in Python 2.3.

-- 
Bartek Rymarski <[EMAIL PROTECTED]>
$ %blow
bash: fg: %blow: no such job
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Galois field

2004-12-03 Thread Roie Kerstein
Mikael Olofsson wrote:

> Googling for
> 
> python "finite field"
> 
> reveals among other things the URLs
> 
> http://www.hpcf.upr.edu/~humberto/software/fields/
> http://www.csua.berkeley.edu/~emin/source_code/py_ecc/
> 

Thank you very much!
However, I lack two important things in the packages introduced there:
1. There is only element arithmetic - no polynomials, in which I have need.
2. there is support only for fields of order 2^p, while I need fields of
prime order.
You still helped me, as before I searched for galois fields and found
nothing, and search for finite fields yields more results.

-- 
Best regards
Roie Kerstein

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


Re: Versioning Libraries

2004-12-03 Thread Richard Brodie

"Peter Hansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]

> Python is exceptionally backwards compatible, so generally
> code from an older version will run unchanged on newer
> Pythons.

I'm just curious: why exceptionally? I like Python for a lot of
reasons but I wouldn't put API stability high on the list.
Not compared with a traditional language like C or Fortran,
anyway. Which languages go around breaking backwards
conmpatibility in a cavalier way?


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


Mouse and/or keyboard simulation

2004-12-03 Thread lamb2000
 
No one in the world knows the answer to my question!
" Is it possible to emulate in Python for Linux the mouse and/or the 
keyboard?"
I am coming from XP, where I have plenty of methods (AutoIt, Macro 
Express,
 Macro Scheduler and even VBA macro registration in Excel).

It is not necessary that I use Python (it should be better!). The goal 
of my request is
obviously automatization of tasks in X environment, like shell programming in 
non-graphic
environment.
Examples of application could be:
- Send queries to the server exacly simulating what I do by hand (urllib 
technique is difficult 
to apply with certain servers...)
- Send to the printer or delete part of documents 
-  ... and so on

   I know that all this tasks could be programmed, but for a newbie like me 
it is easier to 
follow what I already know.null

Lycos Mail: casella da 300 MB gratis per te con sicurezza antispam e antivirus 
-  http://mail.lycos.it

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

Re: decorators ?

2004-12-03 Thread Simon Brunning
On Fri, 03 Dec 2004 02:43:22 GMT, Jp Calderone <[EMAIL PROTECTED]> wrote:
>   Bob Ippolito, you mean.  And, no offense to Bob, but woopidy freaking doo.  
> Now the vast hordes of PyObjC developers get to use their editor's name 
> completion feature a little bit less.  What an awesome justification for 
> adding a whole new syntactic construct to the language.

It's not the typing that's the problem. "The Pragmatic Programmer"[1]
covers the DRY (Do Not Repeat yorself) principal at some length, but
briefly, the major problem is with maintainability. The danger is that
when wne instance of the fiunction name is changed, other won't be,
leading to breakage.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
[1] http://pragmaticprogrammer.com/ppbook/extracts/rule_list.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie alert !

2004-12-03 Thread Jean Montambeault
I am not only learning Python but programming itself ; reading your 
posts makes me believe that nobody is that much of a beginner here. Is 
there a newgroup or list for my type somewhere I can't find it ?

To illustrate my case this script :

# function to draw rings for an Olympic flag
def rings(size,offsetX,offsetY,coul):
x1,y1,x2,y2 = 170, 103, 170, 103,
can1.create_oval(x1-size-offsetX,y1+size+offsetY,\
 x2+size-offsetX,y2-size+offsetY,\
 width=8, outline=coul)
# **mainmainmainmainmainmain**
fen1=Tk()
can1=Canvas(fen1, bg='white', height=206, width=340)
can1.pack(side=LEFT)
bou_europe=Button(fen1, text='Europe',\
  command=rings(41, 100, -22, 'blue'))
bou_europe.pack( )
bou_asia=Button(fen1, text='Asia',\
  command=rings(size=41, offsetX=50,offsetY=22, 
coul='yellow'))
bou_asia.pack( )

bou_africa=Button(fen1, text='Africa',\
  command=rings(size=41, offsetX=0,offsetY=-22, 
coul='black'))
bou_africa.pack( )

bou_australia=Button(fen1, text='Australia',\
  command=rings(size=41, offsetX=-50,offsetY=22, 
coul='dark green'))
bou_australia.pack( )

bou_america=Button(fen1, text='America',\
  command=rings(size=41, offsetX=-100,offsetY=-22, 
coul='Red'))
bou_america.pack( )

bou_quit=Button(fen1, text='Quit', command=fen1.quit)
bou_quit.pack(side=BOTTOM)
fen1.mainloop()
fen1.destroy()

I just cannot figure out why the rings are draw right from the start and 
 don't wait for their buttons to be pressed before being drawn :  I've 
written similar functions before to draw lines, rectangles and whatever 
else with success.

Using Python 2.3, IDLE and Win2k.
Thanks for your time
Jean Montambeault
--
http://mail.python.org/mailman/listinfo/python-list


Re: Versioning Libraries

2004-12-03 Thread Simon Brunning
On Fri, 3 Dec 2004 11:03:58 -, Richard Brodie <[EMAIL PROTECTED]> wrote:

> I'm just curious: why exceptionally? I like Python for a lot of
> reasons but I wouldn't put API stability high on the list.
> Not compared with a traditional language like C or Fortran,
> anyway. Which languages go around breaking backwards
> conmpatibility in a cavalier way?

VB, for a start. 

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Versioning Libraries

2004-12-03 Thread Peter Hansen
Richard Brodie wrote:
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]

Python is exceptionally backwards compatible, so generally
code from an older version will run unchanged on newer
Pythons.

I'm just curious: why exceptionally? I like Python for a lot of
reasons but I wouldn't put API stability high on the list.
Not compared with a traditional language like C or Fortran,
anyway. Which languages go around breaking backwards
conmpatibility in a cavalier way?
Anything from Microsoft, for a start.
Anyway, you're confusing "instability" (I hate that word,
it has connotations of unreliability, which aren't intended)
with "enhancement".  The API gets changed, yes, but by
adding new things, almost never by removing the old stuff
or changing how it works.  You are free to ignore the new
stuff, and almost all old code will work unchanged.  That's
what backwards compatibility means, not that no new features
are ever added.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re:Of course I have 'from Tkinter import *'...

2004-12-03 Thread Jean Montambeault
... at the start of the file.
I just thought it to be too obvious to be included : my mistake.
Thanks
Jean
--
http://mail.python.org/mailman/listinfo/python-list


Re: installing 2.4

2004-12-03 Thread Peter Hansen
Matt Gerrans wrote:
"Peter Hansen" <[EMAIL PROTECTED]> wrote:
Only pure Python code can run without change on a newer interpreter.
Is the interpreter smart enough to rebuild a pyc (if the corresponding py 
file is there of course) file that was built by a previous version?
Yes.  The .pyc files contain a magic cookie that is
different in each major version, so 2.4 will recompile
your 2.3 .pyc files.   .pyc files are not portable
between versions, generally, excepting maintenance releases.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie alert !

2004-12-03 Thread Simon Brunning
On Fri, 03 Dec 2004 06:38:54 -0500, Jean Montambeault
<[EMAIL PROTECTED]> wrote:
> I am not only learning Python but programming itself ; reading your
> posts makes me believe that nobody is that much of a beginner here. Is
> there a newgroup or list for my type somewhere I can't find it ?

The tutor mailing list might be just the place -
.

> To illustrate my case this script :

(Snip)

Sorry, I'm not much of a GUI programmer...

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PySQLLite Speed

2004-12-03 Thread Kent Johnson
Kevin wrote:
Hello All,
I wanted to thank Roger Binn for his email.  He had
the answer to my issue with writing speed.  It's
actual made an incredible change in the preformace.  I
didn't have to go all the way to implementing the
synchronous mode(for my app).  Previously, I was
insert one record at a time.  The key was to write
them all at one time.  I moved up to a 13 meg file and
wrote it to the db in secs.  Now the issue is the 120
meg of RAM consumed by PyParse to read in a 13 meg
file.  If anyone has thoughts on that, it would be
great.  Otherwise, I will repost under a more specific
email.
If your data is (or can be) created by an iterator, you can use this recipe to group the data into 
batches of whatever size you choose and write the individual batches to the db.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279

Kent
Thanks,
  Kevin

db.execute("begin")
while i < TriNum
   db.execute("""insert into TABLE(V1_x)
values(%f),""" (data[i]))
i = i + 1
db.execute("commit")

	
		
__ 
Do you Yahoo!? 
Yahoo! Mail - You care about security. So do we. 
http://promotions.yahoo.com/new_mail
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie alert !

2004-12-03 Thread Eric Brunel
Jean Montambeault wrote:
I am not only learning Python but programming itself ; reading your 
posts makes me believe that nobody is that much of a beginner here. Is 
there a newgroup or list for my type somewhere I can't find it ?

To illustrate my case this script :

# function to draw rings for an Olympic flag
def rings(size,offsetX,offsetY,coul):
x1,y1,x2,y2 = 170, 103, 170, 103,
can1.create_oval(x1-size-offsetX,y1+size+offsetY,\
 x2+size-offsetX,y2-size+offsetY,\
 width=8, outline=coul)
# **mainmainmainmainmainmain**
fen1=Tk()
can1=Canvas(fen1, bg='white', height=206, width=340)
can1.pack(side=LEFT)
bou_europe=Button(fen1, text='Europe',\
  command=rings(41, 100, -22, 'blue'))
Here is what you do here: you *call* your "rings" function with the given 
parameters, and you assign the *result* of the function (which is None, since 
you do not have any "return" statement in rings) to the "command" option of your 
button. Since you do that for all buttons, all circles are drawn right away and 
no command is attached to any of your buttons.

The basic solution would be to create 5 different functions - one for each ring 
- and assign the function to the button's command option:

def ringEurope():
  rings(41, 100, -22, 'blue')
bou_europe = Button(fen1, text='Europe', command=ringEurope)
And so on...
Another shorter, but more difficult to understand solution would be to use an 
anonymous function built with lambda. Here is how it goes:

bou_europe = Button(fen1, text='Europe',
command=lambda: rings(41, 100, -22, 'blue'))
There are however some issues with lambda, so you'd probably better stick to the 
first solution.

[snip]
bou_africa=Button(fen1, text='Africa',\
  command=rings(size=41, offsetX=0,offsetY=-22, 
coul='black'))
(BTW, why do you pass the function arguments as positional parameters in the 
first call and as named parameters in the following ones? IMHO, since the 
parameters are positional in the function definition, you'd better pass them as 
such in the calls, i.e: rings(41, 0, -22, 'black')

(Et sinon, il existe un newsgroup Python francophone (fr.comp.lang.python) sur 
lequel tu seras le bienvenu si jamais tu préfères discuter en français)

HTH
--
- Eric Brunel  -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: PySQLLite Speed

2004-12-03 Thread Gerhard Haering
On Fri, Dec 03, 2004 at 06:06:11AM -0500, Kent Johnson wrote:
> If your data is (or can be) created by an iterator, you can use this recipe 
> to group the data into batches of whatever size you choose and write the 
> individual batches to the db.
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279

If your data is (or can be) created by an iterator, then you might find it
interesting that *pysqlite2*'s .executemany() not only works on lists, but also
on iterators.

Example:

import pysqlite2.dbapi2 as sqlite
...
# A generator function (which returns an iterator)
def gen():
for i in xrange(5):
yield (5, 'foo')

cu.executemany("insert into foo(x, y) values (?, ?)", gen())

So, in pysqlite2, .executemany() and iterators provide best
performance.  .executemany() reuses the compiled SQL statement (so the
engine only needs to parse it once), and the iterator, if used
smartly, reduces the amount of memory used because you don't need to
construct large lists any more.

I hope I don't create too much confusion here ;-)

-- Gerhard


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

Re: pythonwin broke

2004-12-03 Thread Steve Holden
Jive wrote:
I've un-installed Python 2.4, re-installed Python 2.3 and PythonWin for 2.3,
but it's still broke.
When I start PythonWin, sometimes it looks like it is going to be okay.  But
as soon as I open a .py file, the interactive window grabs the focus and
will not let go.  I am stumped.
Is there something PythonWin uses that I could try re-installing?  WxPython
maybe?

This isn't something I can ever remember happening. You might consider 
asking on the python-win32 list, which is more specifically directed at 
Mark Hammond's stuff.

regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: pre-PEP generic objects

2004-12-03 Thread Steve Holden
Paul Rubin wrote:
Steven Bethard <[EMAIL PROTECTED]> writes:
IMHO this too easy to accomplish right now to warrant
an "official" implementation:
class Bunch:
   pass
b = Bunch()
b.one, b.two, b.three = 1,2,3
works just fine, depending on the problem I might add a few special
operators. For anything more complicated I'd rather write a real class.
...
The belief that I gathered from the end of the previous thread
discussing this (check last week's python-list I think) was that there
were a significant number of people who had wanted a class like this
(notably IPython), and more than one of them had rewritten the class a
few times.

I've written that class more than a few times myself, and ended up
adding operations to print the objects (show the member values),
serialize them (don't output any member whose name starts with _), etc.
I think it would be worthwhile to standardize something like this.
For this reason a PEP would have value: if it's rejected, the reasons 
for its rejection will be recorded for posterity. If it isn't rejected, 
of course, we get a bunch as part of the included batteries.

Next question: bunch is a cute name, but not very suggestive of purpose. 
Who can think of a better one?

regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Galois field

2004-12-03 Thread Mikael Olofsson
Roie Kerstein wrote:
Thank you very much!
However, I lack two important things in the packages introduced there:
1. There is only element arithmetic - no polynomials, in which I have 
need.
2. there is support only for fields of order 2^p, while I need fields of
prime order.
You still helped me, as before I searched for galois fields and found
nothing, and search for finite fields yields more results.
Off topic for the list, but possibly on topic for this thread:
At our department we use Magma (http://magma.maths.usyd.edu.au/) for finite 
field arithmetic and error control codes. Magma has nothing to do with 
Python, instead it is a very mature tool of its own, mainly for descrete 
math. It knows what a permutation group is, it knows what GF(81) is, and 
much more. Check out the handbook (Magma on-line help) on the web site and 
be impressed. You will find finite fields under Basic Rings. Magma is not 
free, though, and licence fees vary depending on who is buying the licence, 
see the web site for details. Note that under certain circumstances you may 
be eligible for a free version. If you have access to Magma where you are, 
do consider using it.

An example Magma session:
banin:~> magma
Magma V2.8-9  Fri Dec  3 2004 13:17:54 on banin[Seed = 735720219]
Type ? for help.  Type -D to quit.
R:=PolynomialAlgebra(GF(3));
F:=GF(27);
for el in F do
for>  print el, "   ", MinimalPolynomial(el);
for> end for;
1 x + 2
a x^3 + 2*x + 1
a^2 x^3 + x^2 + x + 2
a^3 x^3 + 2*x + 1
a^4 x^3 + x^2 + 2
a^5 x^3 + 2*x^2 + x + 1
a^6 x^3 + x^2 + x + 2
a^7 x^3 + x^2 + 2*x + 1
a^8 x^3 + 2*x^2 + 2*x + 2
a^9 x^3 + 2*x + 1
a^10 x^3 + x^2 + 2
a^11 x^3 + x^2 + 2*x + 1
a^12 x^3 + x^2 + 2
2 x + 1
a^14 x^3 + 2*x + 2
a^15 x^3 + 2*x^2 + x + 1
a^16 x^3 + 2*x + 2
a^17 x^3 + 2*x^2 + 1
a^18 x^3 + x^2 + x + 2
a^19 x^3 + 2*x^2 + x + 1
a^20 x^3 + 2*x^2 + 2*x + 2
a^21 x^3 + x^2 + 2*x + 1
a^22 x^3 + 2*x + 2
a^23 x^3 + 2*x^2 + 1
a^24 x^3 + 2*x^2 + 2*x + 2
a^25 x^3 + 2*x^2 + 1
0 x

Regards
/Mikael Olofsson
Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE])
Linköpings universitet
---
E-Mail:  [EMAIL PROTECTED]
WWW: http://www.dtr.isy.liu.se/en/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
---
Linköpings kammarkör: www.kammarkoren.com   Vi söker tenorer och basar! 

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


Re: Versioning Libraries

2004-12-03 Thread Richard Brodie

"Peter Hansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]

> Anyway, you're confusing "instability" (I hate that word,
> it has connotations of unreliability, which aren't intended)
> with "enhancement".  The API gets changed, yes, but by
> adding new things, almost never by removing the old stuff
> or changing how it works.

I'm not confusing it, I'm disagreeing. Take xreadlines, for
example. Added in 2.1, deprecated in 2.3, removed in 2.4
Perhaps I lead a sheltered life but that's almost infinitely
worse than any other language I have used. It's not a big
issue though: I'm just surprised that what I would regard as
a weakness in Python, others consider a strength.


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


Re: How is Python designed?

2004-12-03 Thread Steve Holden
Limin Fu wrote:
To clarify, I mean the internal structure and design
of python interpreter. Any hint? Thanks.
Regards,
Limin
In the open source world, of course, the usual answer from people like 
me (who don't delve deeply into the internals most of the time) is "use 
the source, Luke".

But I'm sure you'll get plenty of useful answers here now the question 
is clear.

regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mouse and/or keyboard simulation

2004-12-03 Thread Radovan Garabik
lamb2000 <[EMAIL PROTECTED]> wrote:
> [-- text/plain, encoding 7bit, charset: us-ascii, 21 lines --]
> 
> 
>No one in the world knows the answer to my question!
>" Is it possible to emulate in Python for Linux the mouse and/or the 
> keyboard?"
>I am coming from XP, where I have plenty of methods (AutoIt, Macro 
> Express,
> Macro Scheduler and even VBA macro registration in Excel).
> 
>It is not necessary that I use Python (it should be better!). The goal 
> of my request is
> obviously automatization of tasks in X environment, like shell programming in 
> non-graphic
> environment.
>Examples of application could be:
> - Send queries to the server exacly simulating what I do by hand (urllib 
> technique is difficult 
> to apply with certain servers...)
> - Send to the printer or delete part of documents 
> -  ... and so on
> 
>   I know that all this tasks could be programmed, but for a newbie like 
> me it is easier to 
> follow what I already know.null
>

what you want is an interface to xtest

look for xautomation package (not python, but calling xautomation from
python is trivial)

I used it successfully to get an information out of old win3.1 program
running under WINE
(1 times (pagedown + screenshot + OCR))

-- 
 ---
| Radovan GarabÃk http://melkor.dnp.fmph.uniba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Automated mail bounce handling.

2004-12-03 Thread Alan Kennedy
Hi All,
I'm writing an application that sends out emails, for workflow-item 
tracking purposes.

I am using a VERP-style addressing mechanism, whereby I send each 
message from an uniquely generated email address, so that I can relate 
bounces, notification failures, etc, to the original address to which 
the email was sent.

Problem is differentiating between the different types of message that 
can come back to that address. For example, if the message was 
undeliverable for "permanent" reasons, e.g. user moved on, invalid email 
address, etc, then I get back an email to the unique address, which 
needs to be parsed in order to find the reason for failure. But I also 
get back vacation emails to the same address, e.g. "I'm out of the 
office at the moment, I'll read your email when I get back". The former 
should be recognised by the application, so that appropriate action can 
be taken, i.e. ask admin for a new address. But the latter should be 
essentially ignored, because it doesn't affect whether the recipient 
actually received the email.

I've been researching a little, and found the following approaches:-
1. RFC 1839, which specifies header values giving easy-to-parse 
reason-codes for the return mail. But I'm uncertain as to how widely 
supported RFC 1839 is "in the wild".

2. The mailman approach, which is essentially the linear application of 
algorithmic matchers, each of which is given a chance to recognise 
bounced mails, in order to determine the nature of the bounce. AFAICT, 
this method involves a significant amount of coding, as it requires 
writing a new matcher for each MTA/MUA in existence (surprise, surprise, 
they all do it slightly differently). I see that the mailman 
distribution comes with a couple dozen matchers, which is obviously far 
from complete. I'd prefer not to go down this path, since I could end up 
writing hundreds of matchers, as I incrementally discover the different 
styles that real-world M[T|U]As use. And mailman is GPL, which is a 
problem in this case.

I am trying to think of more robust and less costly (in coding time) 
approaches. Maybe some form of text-matching algorithm, such as

1. Bayesian classification?
2. Keyword recognition?
I'd be grateful for any pointers or suggestions for existing python 
solutions to this problem.

TIA,
--
alan kennedy
--
email alan:  http://xhaus.com/contact/alan
--
http://mail.python.org/mailman/listinfo/python-list


Re: inheritance problem with 2 cooperative methods

2004-12-03 Thread Dan Perl
This is almost the same code as Greg's with the only difference being that 
test for configuration having been done.  But the test is unnecessary.  I 
don't see how setConfig could be invoked in the super of the base class (A), 
so such a test would be relevant only in subclasses, if they DO invoke 
setConfig.  But it's better if they just don't invoke it, which makes for a 
much cleaner solution.  Thanks anyway.

BTW, you named the attribute configinitialized in one place and configSet in 
the other place.  Which proves that the test is redundant, because it does 
work anyway as is.

I had a similar solution, where I was invoking setConfig only if the class 
of self is the same as the class where __init__ is defined, something like 
this:
class A (object):
def __init__(self, config):
   self.x = 0
   super(A, self).__init__()
   if A == self.__class__:
 self.setConfig(config)

I didn't like it though because it has to be done like this in every 
subclass's __init__.  And it's a problem that I didn't realize at the time 
if a subclass just does not need to override __init__ (then the 
configuration is just not set).

Dan

"David Fraser" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> What about using an attribute in the base class to remember whether 
> initial config has been done? This seems to work:
>
> #!/usr/bin/python
> class A (object):
>def __init__(self, config):
>   self.x = 0
>   self.configinitialized = False
>   super(A, self).__init__()
>   if not self.configinitialized:
> self.setConfig(config)
>def setConfig(self, config):
>   self.x += config['x']
>   self.configset = True
>
> class B (A):
>def __init__(self, config):
>   self.y = 0
>   super(B, self).__init__(config)
>def setConfig(self, config):
>   super(B, self).setConfig(config)
>   self.y += config['y']
>
> class C (B):
>def __init__(self, config):
>   self.z = 0
>   super(C, self).__init__(config)
>def setConfig(self, config):
>   super(C, self).setConfig(config)
>   self.z += config['z']
>
> config = {'x':1, 'y':2, 'z':3}
> alpha = A(config)
> print alpha.x
> beta = B(config)
> print beta.x, beta.y
> beta.setConfig(config)
> print beta.x, beta.y
> gamma = C(config)
> print gamma.x, gamma.y, gamma.z
> gamma.setConfig(config)
> print gamma.x, gamma.y, gamma.z 


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


Re: help running python in a limited interpreted environment

2004-12-03 Thread Nick Coghlan
Mike wrote:
AttributeError: 'module' object has no attribute 'xxx'
We know the calling script finds the necessary modules, and the
attribute clearly appears in the module's .py file.
Can anyone tell me what the problem is or if what we're trying to do is
not possible?  Is there something in addition to the .dll that needs to
be present?
Are there any circular imports in the scripts (e.g. A imports B which imports C 
which imports A)? This error message is sometimes seen when attempting to access 
attributes of a module which is still in the process of being imported.

There are a couple of bug reports on Source Forge about it - it hasn't been 
fixed yet, mainly because it's a damn hard problem in need of a solution that is 
still to be found ;)

The simplest resolution is to find a way to break the circularity (usually by 
moving the code responsible for the circularity to a different - possibly new - 
module)

If you don't have any circular imports, then I'm out of ideas :)
Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Re: installing 2.4

2004-12-03 Thread Steve Holden
Peter Hansen wrote:
Matt Gerrans wrote:
"Peter Hansen" <[EMAIL PROTECTED]> wrote:
Only pure Python code can run without change on a newer interpreter.

Is the interpreter smart enough to rebuild a pyc (if the corresponding 
py file is there of course) file that was built by a previous version?

Yes.  The .pyc files contain a magic cookie that is
different in each major version, so 2.4 will recompile
your 2.3 .pyc files.   .pyc files are not portable
between versions, generally, excepting maintenance releases.
-Peter
In fact this hidden recompilation, when it has to be applied to large 
libraries, can impact performance considerably. I first came across this 
when testing an application (which had its own, quite significant, 
libraries) for compatibility between Cygwin and the standard Windows 
interpreter, across different version numbers.

It was only when I started to look at file creation times I twigged that 
running the program (for the first time only) under a different regime 
was causing the libraries to be recompiled. Then the reason for the 
inconsistency in run times was then obvious.

regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Pre-PEP: Executing modules inside packages with '-m'

2004-12-03 Thread Nick Coghlan
Anyone playing with the CPython interpreter's new command line switch might have 
noticed that it only works with top-level modules (i.e. scripts that are 
directly on sys.path). If the script is inside a package, the invocation will 
fail with a "Module not found" error.

This PEP is aimed at fixing that :)
Cheers,
Nick.
===
PEP: XXX
Title: Executing modules inside packages with '-m'
Version: $Revision:$
Last-Modified: $Date:$
Author: Nick Coghlan <[EMAIL PROTECTED]>,
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 16-Oct-2004
Python-Version: 2.5
Post-History: 8-Nov-2004
Abstract

This PEP defines semantics for executing modules inside packages as
scripts with the ``-m`` command line switch.
The proposed semantics are that the containing package be imported prior
to execution of the script.
Rationale
=
Python 2.4 adds the command line switch ``-m`` to allow modules to be
located using the Python module namespace for execution as scripts.
The motivating examples were standard library modules such as ``pdb``
and ``profile``.
A number of users and developers have requested extension of the
feature to also support running modules located inside packages.
One example provided is pychecker's ``pychecker.checker`` module.
This capability was left out of the Python 2.4 implementation
because the appropriate semantics were not entirely clear.
The opinion on python-dev was that it was better to postpone the
extension to Python 2.5, and go through the PEP process to help
make sure we got it right.
Scope of this proposal
==
In Python 2.4, a module located using ``-m`` is executed just as if its
filename had been provided on the command line.  The goal of this PEP is
to get as close as possible to making that statement also hold true for
modules inside packages.
Prior discussions suggest it should be noted that this PEP is **not**
about any of the following:
- changing the idiom for making Python modules also useful as scripts (see PEP 
299[1]_).

- lifting the restriction of ``-m`` to modules of type PY_SOURCE or
  PY_COMPILED (i.e. ``.py``, ``.pyc``, ``.pyo``,``.pyw``).
- addressing the problem of ``-m`` not understanding zip imports or
  Python's sys.metapath.
The issues listed above are considered orthogonal to the specific
feature addressed by this PEP.
Current Behaviour
=
Before describing the new semantics, it's worth covering the existing
semantics for Python 2.4 (as they are currently defined only by the
source code).
When ``-m`` is used on the command line, it immediately terminates the
option list (like ``-c``).  The argument is interpreted as the name of
a top-level Python module (i.e. one which can be found on ``sys.path``).
If the module is found, and is of type ``PY_SOURCE`` or ``PY_COMPILED``, then
the command line is effectively reinterpreted from ``python  -m
 `` to ``python   ``. This includes
setting ``sys.argv[0]`` correctly (some scripts rely on this -
Python's own ``regrtest.py`` is one example).
If the module is not found, or is not of the correct type, an error
is printed.
Proposed Semantics
==
The semantics proposed are fairly simple: if ``-m`` is used to execute
a module inside a package as a script, then the containing package is
imported before executing the module in accordance with the semantics
for a top-level module.
This is necessary due to the way Python's import machinery locates
modules inside packages.  A package may modify its own __path__ variable
during initialisation.  In addition, pathing may be affected by ``*.pth``
files. Accordingly, the only way for Python to reliably locate the module
is by importing the containing package and inspecting its __path__
variable.
Note that the package is *not* imported into the ``__main__`` module's
namespace.  The effects of these semantics that will be visible to the
executed module are:
- the containing package will be in sys.modules
- any external effects of the package initialisation (e.g. installed
  import hooks, loggers, atexit handlers, etc)
Reference Implementation

A reference implementation is available on SourceForge [2]_.  In this
implementation , if the ``-m`` switch fails to locate the requested
module at the top level, it effectively reinterprets the command
from ``python -m 

Re: RotatingFileHandler

2004-12-03 Thread Kamus of Kadizhar
On Fri, 03 Dec 2004 09:40:07 +, Vinay Sajip wrote:

> Of course, you should not normally be calling emit() from user code. The 
>   correct approach is to log events to loggers, and not emit them to 
> handlers directly.

Thanks, I finally got that figured out.  Lots changed between the time I
originally wrote the code a couple of years ago and today

--Kamus

-- 
   o   |
 o__  >[]  | A roadie who doesn't ride a mountain bike has no soul.
 ,>/'_/\   | But then a mountain biker who doesn't ride a road bike has no 
legs...
(_)\(_)   \ \  | -Doug Taylor, alt.mountain-bike

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


Re: pickle and py2exe

2004-12-03 Thread Daniel Bickett
> While looking into this, I had seen some mention of protocol option in 
> pickle. I
> hadnt specified anything for protocol, so it defaults to 0 though I dont know
> what that is. Its my first time using pickle and second with py2exe.

If you think this might be your problem, then it would be best to
specify your protocol using the variable HIGHEST_PROTOCOL as defined
in the Pickle module. However, if this does fix your problem, keep in
mind it won't fix the problem for earlier pickle versions.

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


Re: installing wxPython on Linux and Windows

2004-12-03 Thread Daniel Bickett
> I have no way to build it on Windows though, as I don't have Visual C++
> 7.1, for that we must wait for Robin Dunn.

Would it be too difficult of a task to try getting the build working
with Dev-C++? That way those without enough incentive for purchasing
Visual C++ (in excess of $100, I believe) could build it. Forgive my
ignorance if this has already been considered ;)

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


Re: pre-PEP generic objects

2004-12-03 Thread Carlos Ribeiro
On Fri, 03 Dec 2004 07:41:59 -0500, Steve Holden <[EMAIL PROTECTED]> wrote:
> Next question: bunch is a cute name, but not very suggestive of purpose.
> Who can think of a better one?

"Better"is highly subjective in this context. There are several alternatives:

Bunch
Generic
Record
DataRecord

I use "DataRecord" in my own code, because it's readable and makes it
clear that it's not a full fledged class, but a data-only structure.

Given my Pascal roots, I'm also fond of "Record". But given that many
people actually loathe Pascal (probably for reasons deeply rooted in a
bad academic experience :-), that may be a big "turn off".

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie alert !

2004-12-03 Thread Adam DePrince
On Fri, 2004-12-03 at 06:38, Jean Montambeault wrote:
> I am not only learning Python but programming itself ; reading your 
> posts makes me believe that nobody is that much of a beginner here. Is 
> there a newgroup or list for my type somewhere I can't find it ?
> 
> To illustrate my case this script :
> 
> 
> 
> # function to draw rings for an Olympic flag
> def rings(size,offsetX,offsetY,coul):
>  x1,y1,x2,y2 = 170, 103, 170, 103,
>  can1.create_oval(x1-size-offsetX,y1+size+offsetY,\
>   x2+size-offsetX,y2-size+offsetY,\
>   width=8, outline=coul)
> 
> # **mainmainmainmainmainmain**
> 
> fen1=Tk()
> can1=Canvas(fen1, bg='white', height=206, width=340)
> can1.pack(side=LEFT)
> 
> bou_europe=Button(fen1, text='Europe',\
>command=rings(41, 100, -22, 'blue'))
> bou_europe.pack( )
> 
> bou_asia=Button(fen1, text='Asia',\
>command=rings(size=41, offsetX=50,offsetY=22, 
> coul='yellow'))
> bou_asia.pack( )
> 
> bou_africa=Button(fen1, text='Africa',\
>command=rings(size=41, offsetX=0,offsetY=-22, 
> coul='black'))
> bou_africa.pack( )
> 
> bou_australia=Button(fen1, text='Australia',\
>command=rings(size=41, offsetX=-50,offsetY=22, 
> coul='dark green'))
> bou_australia.pack( )
> 
> bou_america=Button(fen1, text='America',\
>command=rings(size=41, offsetX=-100,offsetY=-22, 
> coul='Red'))
> bou_america.pack( )
> 
> bou_quit=Button(fen1, text='Quit', command=fen1.quit)
> bou_quit.pack(side=BOTTOM)
> 
> fen1.mainloop()
> fen1.destroy()
> 
> 
> 
> I just cannot figure out why the rings are draw right from the start and 
>   don't wait for their buttons to be pressed before being drawn :  I've 
> written similar functions before to draw lines, rectangles and whatever 
> else with success.

Because Button creates a button on the screen and moves on.  Would it be
correct to say that you want the program to block on the creation of
each button until it was pressed?

Typically, GUI's rely on the notion of a callback.  You create a widget,
assign some function to be called when something happens and then enter
your "mainloop" where you wait.  If you want your rings to be created
with button presses then you should be creating them in the button
callbacks ... 

- Adam
> 
> Using Python 2.3, IDLE and Win2k.
> 
> Thanks for your time
> 
> Jean Montambeault
Adam DePrince 
973-723-8597 cell voice/tdd
973-983-7576 home voice/tdd

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


Re: pre-PEP generic objects

2004-12-03 Thread Istvan Albert
Steven Bethard wrote:
> The question is not how easy it is to write,
> but how many times it's going to get written.
but with that logic we could  create a standard
"looping" construct called loop(x) that would stand in for
for i in range(x):
or a file_reader('whatever') generator that would be
a shortcut for:
for line in file('whatever'):
   line  = line.strip()
   elems = line.split()
> and more than one of them had rewritten the class a few times.
Two observations regarding that:
1. Probably not entirely true. They might have used something like a Bunch
but it is a bit too optimistic to believe that they could have directly used
your Bunch. My Bunches turn out to be just a ever so slightly different.
Either have an update operation or an equality, or can be hashed etc.
So in the end it might save a lot less work.
2. Even if it was, no big deal. It takes too little time to do it.
On the other hand, it would be nice to have a module that
implements various design patterns. The Bunch, the Borg, the Null,
the Proxy all nicely documented tucked away in their separate
module. That would feel a lot less like littering the standard name space
with an class that just "seems"  to be useful.
just an opinion.
Istvan
--
http://mail.python.org/mailman/listinfo/python-list


distinction between float & int

2004-12-03 Thread Ishwor
hi all,
 can anyone tell me why this distinction? i mean why it returns False
on floats??
>>> a = 1
>>> b = 1
>>> a is b
True
>>> a = 1.1
>>> b = 1.1
>>> a is b
False
>>> 

thanx .
-- 
cheers,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pre-PEP generic objects

2004-12-03 Thread Remy Blank
Istvan Albert wrote:
> On the other hand, it would be nice to have a module that
> implements various design patterns. The Bunch, the Borg, the Null,
> the Proxy all nicely documented tucked away in their separate
> module. That would feel a lot less like littering the standard name space
> with an class that just "seems"  to be useful.

+1 for a "patterns" module.

-- Remy


Remove underscore and suffix in reply address for a timely response.

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


Re: Newbie alert !

2004-12-03 Thread Adam DePrince
>  
> > bou_europe=Button(fen1, text='Europe',\
> >command=rings(41, 100, -22, 'blue'))

Silly me.  I misunderstood what you wanted first time around.  

In Python functions are "first class objects" that are treated no
differently than anything else.  When you setup your button you
executing the function rings, taking its return value (None) and asking
command to call it when the button is clicked.  

Look at the following code for illustration:

def call_and_print( parameter ):
print parameter()

def myfunction( ):
return "abc"

>>>call_and_print( myfunction )
abc
>>>call_and_print( myfunction() )
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 2, in call_and_print
TypeError: 'str' object is not callable

Now, your function rings returns None, which is similarly not callable. 
Tk has the good manners to ignore your exception and move on.  

What you want to do is pass a function as a parameter.  rings mustn't be
the function that draws the ring, rather it must return a function that
draws your ring.  

There are several ways of doing this.  You can use lambda as somebody
else suggested.  My prefered way of doing this is to use python's
optional parameter mechanism.  Look at this code first:

def number_generator( number ):
def func_to_return( num=number ):
return num

return func_to_return

make_a_10 = number_generator( 10 )
make_a_20 = number_generator( 20 )

# Now call ...

print make_a_10
print make_a_20

print make_a_10( )
print make_a_20( )
print make_a_10( )
print make_a_20( )
print make_a_10( )
print make_a_20( )

When run ... 



10
20
10
20
10
20

Now, to make your program work, we make a small change to rings and
nothing else ... 

def rings(size,offsetX,offsetY,coul):
 def internal_rings(size=size,
offsetX=offsetX,
offsetY=offsetY,
coul=coul):
  x1,y1,x2,y2 = 170, 103, 170, 103,
  can1.create_oval(x1-size-offsetX,y1+size+offsetY,\
   x2+size-offsetX,y2-size+offsetY,\
   width=8, outline=coul)
 return internal_rings

Of course, you could say ... 

...internal_rings(size=size,offsetX=offsetX...
but that would mean that I must argue with my mail client.

Enjoy!


> > bou_europe.pack( )
> > 
> > bou_asia=Button(fen1, text='Asia',\
> >command=rings(size=41, offsetX=50,offsetY=22, 
> > coul='yellow'))
> > bou_asia.pack( )
> > 
> > bou_africa=Button(fen1, text='Africa',\
> >command=rings(size=41, offsetX=0,offsetY=-22, 
> > coul='black'))
> > bou_africa.pack( )
> > 
> > bou_australia=Button(fen1, text='Australia',\
> >command=rings(size=41, offsetX=-50,offsetY=22, 
> > coul='dark green'))
> > bou_australia.pack( )
> > 
> > bou_america=Button(fen1, text='America',\
> >command=rings(size=41, offsetX=-100,offsetY=-22, 
> > coul='Red'))
> > bou_america.pack( )
> > 
> > bou_quit=Button(fen1, text='Quit', command=fen1.quit)
> > bou_quit.pack(side=BOTTOM)
> > 
> > fen1.mainloop()
> > fen1.destroy()
> > 
> > 
> > 
> > I just cannot figure out why the rings are draw right from the start and 
> >   don't wait for their buttons to be pressed before being drawn :  I've 
> > written similar functions before to draw lines, rectangles and whatever 
> > else with success.
> 
> Because Button creates a button on the screen and moves on.  Would it be
> correct to say that you want the program to block on the creation of
> each button until it was pressed?
> 
> Typically, GUI's rely on the notion of a callback.  You create a widget,
> assign some function to be called when something happens and then enter
> your "mainloop" where you wait.  If you want your rings to be created
> with button presses then you should be creating them in the button
> callbacks ... 
> 
> - Adam
> > 
> > Using Python 2.3, IDLE and Win2k.
> > 
> > Thanks for your time
> > 
> > Jean Montambeault
> Adam DePrince 

Adam DePrince 


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


Re: distinction between float & int

2004-12-03 Thread Steve Holden
Ishwor wrote:
hi all,
 can anyone tell me why this distinction? i mean why it returns False
on floats??
a = 1
b = 1
a is b
True
a = 1.1
b = 1.1
a is b
False
thanx .
There is no guarantee that this will hold in all implementations of Python.
The majority implementation, usually called CPython because its 
implementation language is C, keeps copies of the first 100 (?) integers 
so it doesn't have to create separate integer objects each time they are 
required.

No caching at all is applied to floats, as far as I can tell.
>>> a = 250
>>> b = 250
>>> a is b
False
regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: installing wxPython on Linux and Windows

2004-12-03 Thread Rob Williscroft
Daniel Bickett wrote in news:mailman.7076.1102081193.5135.python-
[EMAIL PROTECTED] in comp.lang.python:

>> I have no way to build it on Windows though, as I don't have Visual C++
>> 7.1, for that we must wait for Robin Dunn.
> 
> Would it be too difficult of a task to try getting the build working
> with Dev-C++? That way those without enough incentive for purchasing
> Visual C++ (in excess of $100, I believe) could build it. Forgive my
> ignorance if this has already been considered ;)
> 

Just the tools (no IDE):

http://msdn.microsoft.com/visualc/vctoolkit2003/

Its a 33 MB download, a bit less than $100. 

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: distinction between float & int

2004-12-03 Thread Adam DePrince
On Fri, 2004-12-03 at 09:01, Ishwor wrote:
> hi all,
>  can anyone tell me why this distinction? i mean why it returns False
> on floats??
> >>> a = 1
> >>> b = 1
> >>> a is b
> True
> >>> a = 1.1
> >>> b = 1.1
> >>> a is b
> False
> >>> 
> 
> thanx .
> -- 
> cheers,
> Ishwor Gurung


In Python, some integers and strings are interned.  

1 is 1 is true because 1 and 1 are "simplified" to point to the same
object.  

>>> 2 is (1+1)
True
>>> 102 is (101+1)
False
>>> 102 == (101+1)
True

Why?  To quote the Python/C API Reference Manual (section 7.2.1) 

The current implementation keeps an array of integer objects for all
integers between -1 and 100, when you create an int in that range you
actually just get back a reference to the existing object. 

When strings are compiled, they are interned, so ... 
>>> "abc" is "abc"
True
>>> "abc" is ("ab" + "c")
False
>>> "abc" == ( "ab" + "c" )
True
>>> "abc" is intern("ab" + "c" )
True


Is does not measure equality ... the _is_ operator returns true if its
two parameters internally have the same pointer value and are the same
object.

Floating point values are not interned, so 1.1 is 1.1 is false.


Adam DePrince 


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


Re: pre-PEP generic objects

2004-12-03 Thread Carlos Ribeiro
On Fri, 03 Dec 2004 08:58:48 -0500, Istvan Albert
<[EMAIL PROTECTED]> wrote:
> On the other hand, it would be nice to have a module that
> implements various design patterns. The Bunch, the Borg, the Null,
> the Proxy all nicely documented tucked away in their separate
> module. That would feel a lot less like littering the standard name space
> with an class that just "seems"  to be useful.

Great idea. I have explored some ideas relating generic objects with
"standard" patterns, namely "observer" & "proxy".

One of the applications of generic objects is to allow for data
sharing between objects of different classes that happen to share a
few attributes; sometimes it's not possible to pass the entire object
around for the other one to copy the data, either because of safety
reasons, or because there is some slightly mismatch between the
interfaces. The generic, in this case, can be implemented either as an
intermediate storage structure (as a data-only records) or as an
"proxy" that exposes only the desired attributes. In this case, data
is passed around and copied manually, using the generic (or the
"proxy" object).
 
Another use case is when one wants to implement the "observer" pattern
(which would allow for a "live" data sharing).   One alternative is to
use a "generic" as the base "observable'  object; other objects can
register with the generic and simply receive notifications, or even
share the references to its internal attributes (btw, Python
descriptors & properties are incredibly useful in this case).
Extending it even further -- the observed object could accept
modifications from its observers, although in this case we're already
talking a about more complex pattern than the standard "observer"
(btw, how is it called?).

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


float point properties access

2004-12-03 Thread Neal D. Becker
Is there a way in python to access properties of floats?  I need something
equiv to C DBL_EPSILON defined in .


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


Display Adapter Information from Registry?

2004-12-03 Thread Omer Ahmad
Hi All,

I've been working with python for about 6 months now, and have been
very impressed with the size and scope of the libraries.  I have,
however, run into a bit of a problem.

I discoverred Marc Hammonds PyWin32 extensions, (whcih are awesome)
and Tim Golden's WMI wrapper for accessing the Windows Management
Instrumentation  (Win32_Classes) but now I have been asked to remove
these dependandcies and still obtain machine information from the
registry (Windows only of course) so that we do not have to ship any
extensions to Python with our commercial software.

I need to grab the following information:

CPU(s) Descriptions strings (for multiple processors)  (found in
registry)
Display Adapter description string (found in registry)
Display Adapter Memory (found in registry)

What I'm having trouble with is to grab the DISPLAY ADAPTER version
using python and no Win32com client (i.e. pyWin32).  I thought about
grabbing the file name of the driver from the registry and then
looking up the file and calculating the version number (by parsing the
binary) but this only works if i can find the file.  I tried it out on
a few machines with different video adapters and thsi didn't prove to
be a reliable method.

Any suggestions? Please

Omer Ahmad.

ps: here is the code i'm using right now (minus all the debug strings)


def main():
"""Retrieves Machine information from the registry"""

try:
   hHardwareReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
"HARDWARE")
   hDescriptionReg = _winreg.OpenKey(hHardwareReg, "DESCRIPTION")
   hSystemReg = _winreg.OpenKey(hDescriptionReg, "SYSTEM")
   hCentralProcessorReg = _winreg.OpenKey(hSystemReg,
"CentralProcessor")
   nbProcessors = _winreg.QueryInfoKey(hCentralProcessorReg)[0]

   for idxKey in range(nbProcessors):
   #get a handle to the processor ID key
   hProcessorIDReg = _winreg.OpenKey(hCentralProcessorReg,
str(idxKey))
   processorDescription =
_winreg.QueryValueEx(hProcessorIDReg,"ProcessorNameString")[0]
   mhz = _winreg.QueryValueEx(hProcessorIDReg, "~MHz")[0]
   print "Processor " + str(idxKey) + ": " +
string.lstrip(processorDescription) + " Clock Speed: " + str(mhz)
   
except WindowsError:
   print "Cannot retrieve processor information from registry!"

   #get handle to device map, reusing hardware handle

   try:
   hDeviceMapReg = _winreg.OpenKey(hHardwareReg, "DEVICEMAP")
   hVideoReg = _winreg.OpenKey(hDeviceMapReg, "VIDEO")
   VideoCardString =
_winreg.QueryValueEx(hVideoReg,"\Device\Video0")[0]
   #Get Rid of Registry/Machine from the string
   VideoCardStringSplit = VideoCardString.split("\\")
   ClearnVideoCardString =
string.join(VideoCardStringSplit[3:], "\\")
   #Go up one level for detailed
   VideoCardStringRoot =
string.join(VideoCardStringSplit[3:len(VideoCardStringSplit)-1], "\\")

   #Get the graphics card information
   hVideoCardReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
ClearnVideoCardString)
   VideoCardDescription  = _winreg.QueryValueEx(hVideoCardReg,
"Device Description")[0]
   VideoCardMemorySize = _winreg.QueryValueEx(hVideoCardReg,
"HardwareInformation.MemorySize")[0]

   print "Graphics Card: " + VideoCardDescription
   print "Memory: " +
str(struct.unpack('l',VideoCardMemorySize)[0])

   except WindowsError:
   print "Cannot Retrieve Graphics Card Name and Memory Size!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: float point properties access

2004-12-03 Thread Robin Becker
Neal D. Becker wrote:
Is there a way in python to access properties of floats?  I need something
equiv to C DBL_EPSILON defined in .

you could try the traditional algorithm
>>> def dbl_epsilon():
... n = 0
... while 1:
... e = 1.0/2**n
... if (1.0+e==1.0): break
... n += 1
... pe = e
... return pe
...
>>> print dbl_epsilon()
2.22044604925e-016
>>>
--
Robin Becker
--
http://mail.python.org/mailman/listinfo/python-list


How did you learn Python?

2004-12-03 Thread Shawn Milo
I was just wondering what the best books were for learning Python.

Which books are good for getting started, and which should be saved for
later, or or not useful except as a reference for the learned?

I have a decent programming background in VB, JavaScript, VBScript,
Net.Data (IBM's macro language), regular expressions, and a teensy bit of
Perl. My point is, I don't want something that is going to explain the basic
programming concepts, but does give a good introduction to Python-specific
things. Then, once I know how to get the job done, I would like a good book 
or two at the intermediate to advanced level, to learn how to write really good 
code.

I understand that resources such as this list and Google searches have all the 
answers,
but it seems like a more structured tool, such as a book or formal class, would 
be
of great benefit to me. The other languages I have used were picked up because 
of the
need to get a job done. As a result, I am able to get the job done, but any 
experienced
coder can show me six more efficient ways to do what I'm doing. I'm new to
Python, and I want to do this one right. I believe that Python will be
around for a good, long time, and it matches my values as an Open-Source/Linux
supporter, while having relevance in the Windows and Mac world, as well. 
Plus, it looks like it was designed extremely well, and I'm excited about the 
principles I've read about.

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


Re: Curses programming, threads?

2004-12-03 Thread Michele Simionato
Bartlomiej Rymarski <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> Bartlomiej Rymarski <[EMAIL PROTECTED]> wrote:
> > [...]
> > And the loader() function would run in a loop until connect_db() is 
> > is finished. Is that possible in python? Or are there any other,
> > better ways to do it?
> > [...]
> 
> Oh, I forgot - I'm using Linux, and curses module in Python 2.3.

You don't need curses. Some time ago somebody (I forgot the name)
posted this spinner class:

class Spinner( threading.Thread ): # a google search should find the author

DELAY = 0.1
DISPLAY = [ '|', '/', '-', '\\' ]

def __init__( self, before='', after='' ):
threading.Thread.__init__( self )
self.before = before
self.after = after

def run( self ):
write, flush = sys.stdout.write, sys.stdout.flush
self.running = 1
pos = -1
while self.running:
pos = (pos + 1) % len(self.DISPLAY)
msg = self.before + self.DISPLAY[pos] + self.after
write( msg )
flush()
write( '\x08' * len(msg) )
time.sleep( self.DELAY )
write( ' ' * len(msg) + '\x08' * len(msg) )
flush()

def stop( self ):
self.running = 0
self.join()

if __name__=="__main__":
spinner = Spinner('Be patient please ...')
spinner.start()
time.sleep(5) # doing a long operation
spinner.stop()



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


RE: How did you learn Python?

2004-12-03 Thread Batista, Facundo
Title: RE: How did you learn Python?





[Shawn Milo]


#- I was just wondering what the best books were for learning Python.
#- 
#- Which books are good for getting started, and which should 
#- be saved for
#- later, or or not useful except as a reference for the learned?


My particular process did not involve any printed book. It was something like this:


- GvR and FL intro tutorial (don't matter how much you know about languages, just read it).
- General overview of standard library
- Language reference
- Dive into Python


Of course, program as much as you can in the whole process. And always read other's code.


.   Facundo



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

Re: Plone

2004-12-03 Thread Joe Raul
verzeihung , was ist das?

- Original Message - 
From: "merman" <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python.announce
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 25, 2004 8:12 PM
Subject: Plone


> Hallo,
> 
> das ist schon wichtig:
> 
> http://plone.org/newsitems/plone-2.0.5-rc
> 
> o-o
> 
> T. Kaufmann-- 
http://mail.python.org/mailman/listinfo/python-list

Re: float point properties access

2004-12-03 Thread Robin Becker
Robin Becker wrote:
Neal D. Becker wrote:
Is there a way in python to access properties of floats?  I need 
something
equiv to C DBL_EPSILON defined in .


you could try the traditional algorithm
 >>> def dbl_epsilon():
... n = 0
... while 1:
... e = 1.0/2**n
... if (1.0+e==1.0): break
... n += 1
... pe = e
... return pe
...
 >>> print dbl_epsilon()
2.22044604925e-016
 >>>
on looking further I find my 'traditional' algorithm is actually 
something like this

def dbl_epsilon(_eps=[]):
if not _eps:
etop = 1.0
ebot = 0.0
eps = ebot+(etop-ebot)/2.0
while eps!=ebot and eps!=etop:
epsp1 = 1.0 - eps
if epsp1<1.0: etop = eps
else: ebot = eps
eps = ebot+(etop-ebot)/2.0
_eps.append(etop)
assert (1.0-etop)<1.0 and (1.0-ebot)==1.0, 'Error in epsilon 
calculation'
return _eps[0]
print dbl_epsilon()
which gives 5.55111512313e-017
-senility is making me stupidly yrs-
Robin Becker
--
http://mail.python.org/mailman/listinfo/python-list


Module list generation

2004-12-03 Thread Doug Kearns
Is this the best/simplest way to generate a module list?

python -c 'from pydoc import help; help("modules")'

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


Re: How did you learn Python?

2004-12-03 Thread Thomas Guettler
Am Fri, 03 Dec 2004 09:54:36 -0500 schrieb Shawn Milo:

> I was just wondering what the best books were for learning Python.
> 
> Which books are good for getting started, and which should be saved for
> later, or or not useful except as a reference for the learned?

Hi,

I learned a lot by reading the python cookbook.

 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: Display Adapter Information from Registry?

2004-12-03 Thread Larry Bates
Let's see, there are tools that do what you want but you are
being told not use them?  If you use py2exe to bundle up all
your commercial software (with extensions) and then Inno Setup
to create a setup.exe file for setting everything up, nobody
ever knows about Python, extensions, etc.  This eliminates the
need to have Python (and any extensions) installed on the
target machines.  I (and many others) do this for all my
Windows software that is to be distributed.
Hope information helps.
Larry Bates
Omer Ahmad wrote:
Hi All,
I've been working with python for about 6 months now, and have been
very impressed with the size and scope of the libraries.  I have,
however, run into a bit of a problem.
I discoverred Marc Hammonds PyWin32 extensions, (whcih are awesome)
and Tim Golden's WMI wrapper for accessing the Windows Management
Instrumentation  (Win32_Classes) but now I have been asked to remove
these dependandcies and still obtain machine information from the
registry (Windows only of course) so that we do not have to ship any
extensions to Python with our commercial software.
I need to grab the following information:
CPU(s) Descriptions strings (for multiple processors)  (found in
registry)
Display Adapter description string (found in registry)
Display Adapter Memory (found in registry)
What I'm having trouble with is to grab the DISPLAY ADAPTER version
using python and no Win32com client (i.e. pyWin32).  I thought about
grabbing the file name of the driver from the registry and then
looking up the file and calculating the version number (by parsing the
binary) but this only works if i can find the file.  I tried it out on
a few machines with different video adapters and thsi didn't prove to
be a reliable method.
Any suggestions? Please
Omer Ahmad.
ps: here is the code i'm using right now (minus all the debug strings)
def main():
"""Retrieves Machine information from the registry"""
try:
   hHardwareReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
"HARDWARE")
   hDescriptionReg = _winreg.OpenKey(hHardwareReg, "DESCRIPTION")
   hSystemReg = _winreg.OpenKey(hDescriptionReg, "SYSTEM")
   hCentralProcessorReg = _winreg.OpenKey(hSystemReg,
"CentralProcessor")
   nbProcessors = _winreg.QueryInfoKey(hCentralProcessorReg)[0]
   for idxKey in range(nbProcessors):
   #get a handle to the processor ID key
   hProcessorIDReg = _winreg.OpenKey(hCentralProcessorReg,
str(idxKey))
   processorDescription =
_winreg.QueryValueEx(hProcessorIDReg,"ProcessorNameString")[0]
   mhz = _winreg.QueryValueEx(hProcessorIDReg, "~MHz")[0]
   print "Processor " + str(idxKey) + ": " +
string.lstrip(processorDescription) + " Clock Speed: " + str(mhz)
   
except WindowsError:
   print "Cannot retrieve processor information from registry!"

   #get handle to device map, reusing hardware handle
   try:
   hDeviceMapReg = _winreg.OpenKey(hHardwareReg, "DEVICEMAP")
   hVideoReg = _winreg.OpenKey(hDeviceMapReg, "VIDEO")
   VideoCardString =
_winreg.QueryValueEx(hVideoReg,"\Device\Video0")[0]
   #Get Rid of Registry/Machine from the string
   VideoCardStringSplit = VideoCardString.split("\\")
   ClearnVideoCardString =
string.join(VideoCardStringSplit[3:], "\\")
   #Go up one level for detailed
   VideoCardStringRoot =
string.join(VideoCardStringSplit[3:len(VideoCardStringSplit)-1], "\\")
   #Get the graphics card information
   hVideoCardReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
ClearnVideoCardString)
   VideoCardDescription  = _winreg.QueryValueEx(hVideoCardReg,
"Device Description")[0]
   VideoCardMemorySize = _winreg.QueryValueEx(hVideoCardReg,
"HardwareInformation.MemorySize")[0]
   print "Graphics Card: " + VideoCardDescription
   print "Memory: " +
str(struct.unpack('l',VideoCardMemorySize)[0])
   except WindowsError:
   print "Cannot Retrieve Graphics Card Name and Memory Size!"
--
http://mail.python.org/mailman/listinfo/python-list


RE: How did you learn Python?

2004-12-03 Thread Doran_Dermot
Hi Shawn,

I would recommend the following for starters:
- The Tutorial (http://www.python.org/dev/doc/devel/tut/tut.html)
- Python "How to Program" by Deitel 

After that it is like any language, natural or computer related!  Use it!

However, I think you'll find that it is a lot easier to use than most other
languages.

Cheers!!

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Shawn Milo
Sent: 03 December 2004 14:55
To: [EMAIL PROTECTED]
Subject: How did you learn Python?

I was just wondering what the best books were for learning Python.

Which books are good for getting started, and which should be saved for
later, or or not useful except as a reference for the learned?

I have a decent programming background in VB, JavaScript, VBScript,
Net.Data (IBM's macro language), regular expressions, and a teensy bit of
Perl. My point is, I don't want something that is going to explain the basic
programming concepts, but does give a good introduction to Python-specific
things. Then, once I know how to get the job done, I would like a good book 
or two at the intermediate to advanced level, to learn how to write really
good code.

I understand that resources such as this list and Google searches have all
the answers,
but it seems like a more structured tool, such as a book or formal class,
would be
of great benefit to me. The other languages I have used were picked up
because of the
need to get a job done. As a result, I am able to get the job done, but any
experienced
coder can show me six more efficient ways to do what I'm doing. I'm new to
Python, and I want to do this one right. I believe that Python will be
around for a good, long time, and it matches my values as an
Open-Source/Linux
supporter, while having relevance in the Windows and Mac world, as well. 
Plus, it looks like it was designed extremely well, and I'm excited about
the 
principles I've read about.

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


Re: How did you learn Python?

2004-12-03 Thread Jeffrey Maitland
Well I would suggest the Python in a Nutshell and the Python Cookbook  both 
by O'Reilly as references.  They are great for a desktop reference and I 
check them first before I google/search else where for answers.  Being they 
are reference books they or more on aide then a teaching device however I 
have learned from those books how to use certain standard classes, such as 
the re class for example. 

Hope this helps you out. 

Jeff 

Shawn Milo writes: 

I was just wondering what the best books were for learning Python. 

Which books are good for getting started, and which should be saved for
later, or or not useful except as a reference for the learned? 

I have a decent programming background in VB, JavaScript, VBScript,
Net.Data (IBM's macro language), regular expressions, and a teensy bit of
Perl. My point is, I don't want something that is going to explain the basic
programming concepts, but does give a good introduction to Python-specific
things. Then, once I know how to get the job done, I would like a good book 
or two at the intermediate to advanced level, to learn how to write really good code. 

I understand that resources such as this list and Google searches have all the answers,
but it seems like a more structured tool, such as a book or formal class, would be
of great benefit to me. The other languages I have used were picked up because of the
need to get a job done. As a result, I am able to get the job done, but any experienced
coder can show me six more efficient ways to do what I'm doing. I'm new to
Python, and I want to do this one right. I believe that Python will be
around for a good, long time, and it matches my values as an Open-Source/Linux
supporter, while having relevance in the Windows and Mac world, as well. 
Plus, it looks like it was designed extremely well, and I'm excited about the 
principles I've read about. 

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

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


Re: Galois field

2004-12-03 Thread Nick Craig-Wood
Mikael Olofsson <[EMAIL PROTECTED]> wrote:
>  At our department we use Magma (http://magma.maths.usyd.edu.au/)
>  for finite field arithmetic and error control codes. Magma has
>  nothing to do with Python, instead it is a very mature tool of its
>  own, mainly for descrete math. It knows what a permutation group
>  is, it knows what GF(81) is, and much more.

I think pari/gp can do arithmetic over general Galois fields.  I
certainly have a recollection of doing that with it in the past.  Its
free (GPL) too, and has a library that could be wrapped with SWIG/etc
to make it python friendly.

  http://pari.math.u-bordeaux.fr/

  * PARI is a C library, allowing fast computations.
  * gp is an interactive shell giving access to PARI functions, much easier to 
use.
  * GP is the name of gp' s scripting language
  * gp2c the GP-to-C compiler makes the best of both worlds

If someone did wrap PARI in python it would certainly be easier to use
than GP which I found very unintuitive!

In fact I just found this which looks like just the job!

  http://www.fermigier.com/fermigier/PariPython/readme.html

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


Replace string except inside quotes?

2004-12-03 Thread beliavsky
The code 

for text in open("file.txt","r"):
print text.replace("foo","bar")[:-1]

replaces 'foo' with 'bar' in a file, but how do I avoid changing text
inside single or double quotes? For making changes to Python code, I
would also like to avoid changing text in comments, either the '#' or
'""" ... """' kind.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: disk based dictionaries

2004-12-03 Thread Chris Cioffi
I'd like to second this suggestion.  While there are a few things you
need to be aware of when writing your code (mostly taken care of in
the latest release) it's a mostly trivial code change.  (For me it was
replacing a few dictionaries with PersistentMap objects and changing
the base class of a few objects to Persistant from object.

FWIW, I'm using ZODB to help track EDI transactions for a help desk
application.  Right now my database hovers in the 100MB range with
several ten of thousands of objects.  I also use it for single object
temp storage, so I feel it works well from both the small and mid-size
scale.  (It probably works fine for large projects as well, I just
don't have one right now...)

Chris


On Thu, 02 Dec 2004 18:53:44 -0600, Larry Bates <[EMAIL PROTECTED]> wrote:
> You may also want to take a look at ZODB (Zope database).
> It handles the pickling, storage and retrieval of all
> Python objects (including dictionaries) very well.  And yes
> you can use ZODB without using Zope proper.
> 
> http://www.zope.org/Products/StandaloneZODB
> 
> http://zope.org/Members/adytumsolutions/HowToLoveZODB_PartII/HowToLoveZODB_PartI
> 
> http://www.h7.dion.ne.jp/~harm/ZODB-Tutorial.py
> 
> 
> Larry Bates
> 
> 
> 
> 
> Shivram U wrote:
> > Hi,
> >
> >   I want to store dictionaries on disk. I had a look at a few modules
> > like bsddb, shelve etc. However would it be possible for me to do the
> > following
> >
> > hash[1] = [1, 2, 3] where the key is an int and not a string
> >
> > bsddb requires that both the key,value are string.
> > shelve does support values being object but not the keys. Is there any
> > module which support keys which are not strings
> >
> > Also how do i use disk based hashes for multidimensional hashes such as
> > below
> >
> > #!/usr/bin/python
> >
> > dict={}
> > dict['key1'] = {}
> > dict[('key1')][('key2')] = 'value'
> >
> > key1=dict['key1']
> > print key1['key2']
> >
> > I have read of mxBeeDict but was unable to get it work properly. I am
> > not sure if it supports what i need as i was unable to get any
> > documentation about it. Is the module used widely ?
> >
> > Below is how i am using the module
> >
> > bdict = BeeDict('/tmp/beedict')
> >
> > bdict[1] = 1
> > print bdict.keys()
> >
> > bdict.commit()
> > bdict.close()
> >
> > bdict1 = BeeDict('/tmp/beedict')
> > print bdict1.keys()
> > print bdict1.values()
> >
> >
> > Would it be that using disk based dictionaries once opened are as fast
> > as in memory dictionaries ?
> >
> > Thanks in advance,
> >
> > Best Regards,
> > Shivram U
> >
> >
> >
> >
> > Confidentiality Notice
> >
> > The information contained in this electronic message and any attachments to 
> > this message are intended
> > for the exclusive use of the addressee(s) and may contain confidential or 
> > privileged information. If
> > you are not the intended recipient, please notify the sender at Wipro or 
> > [EMAIL PROTECTED] immediately
> > and destroy all copies of this message and any attachments.
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
"It is our responsibilities, not ourselves, that we should take
seriously." -- Peter Ustinov
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 and Tkinter

2004-12-03 Thread Jeffrey Barish
Eric Brunel wrote:

> Jeffrey Barish wrote:
> [snip]
>> OK, I downloaded tcl8.4.8 and tk8.4.8.  They are now installed.  Back
>> to
>> python2.4 make.  It now bombs at:
>> 
>> gcc -pthread -shared build/temp.linux-i686-2.4/_tkinter.o
>> build/temp.linux-i686-2.4/tkappinit.o -L/usr/X11R6/lib64
>> -L/usr/X11R6/lib -L/usr/local/lib -ltk8.4 -ltcl8.4 -lX11 -o
>> build/lib.linux-i686-2.4/_tkinter.so
>> *** WARNING: renaming "_tkinter" since importing it failed:
>> libtk8.4.so: cannot open shared object file: No such file or
>> directory running build_scripts
>> 
>> Here's what I don't get:
>> 
>> [EMAIL PROTECTED]:/tmp/Python-2.4# ls -l /usr/local/lib/libtk8.4.so
>> -rwxr-xr-x1 root staff  893866 2004-12-02
>> 15:28 /usr/local/lib/libtk8.4.so
>> 
>> The library is there but gcc claims that it isn't.  Any suggestions?
> 
> Is /usr/local/lib in your LD_LIBRARY_PATH environment variable? It
> needs to be in the compiler options for the compilation phase, but
> then you have to put it in $LD_LIBRARY_PATH to be able to import the
> module.
> 
> HTH

That was the problem.  Thanks for the help.
-- 
Jeffrey Barish

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


Re: How did you learn Python?

2004-12-03 Thread Eric Pederson
"Shawn Milo" wrote:

> My point is, I don't want something that is going to explain the 
> basic
> programming concepts, but does give a good introduction to 
> Python-specific
> things. 


I think you might appreciate "Learning Python" as it's written very succinctly, 
but it goes through the language features pretty comprehensively.  Very nicely 
written.  Afterwards, the "Python Cookbook" might be useful, you can dip into 
it and discover better ways to do certain things, as you do them.  Either book 
should be read next to the computer with IDLE open, IMO.  The interpreter 
really makes learning by doing easy.

I have not heard of a great Python design patterns type book, but you will see 
discussion of the essence of that subject on this list every day: advice on how 
to write more "Pythonic" code, how to design code that runs faster, and even 
just "how do I accomplish this?" answers.

Having a project to code may be one of the best tools for learning python.

Python code is cleaner by nature, and will encourage + facilitate "cleaner code 
think" if you let it.

Definitely read some of the materials on the Python.org site, by Guido et. al.  
 
Introductions:  http://python.org/doc/Intros.html
Topic specific:  http://python.org/topics/
FAQs:  http://python.org/doc/faq/general.html


Have fun!


Eric Pederson

:::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::

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


Re: installing wxPython on Linux and Windows

2004-12-03 Thread Michael Hobbs
Daniel Bickett <[EMAIL PROTECTED]> wrote:
>> I have no way to build it on Windows though, as I don't have Visual C++
>> 7.1, for that we must wait for Robin Dunn.
> 
> Would it be too difficult of a task to try getting the build working
> with Dev-C++? That way those without enough incentive for purchasing
> Visual C++ (in excess of $100, I believe) could build it. Forgive my
> ignorance if this has already been considered ;)

I'm pretty sure that I once built wxPython using Cygwin. It was a 
while ago, though, and I was switching back and forth between windows
and Linux very frequently; so I may just be imagining it...

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


Help with use of code.InteractiveInterpreter for multiline code

2004-12-03 Thread [EMAIL PROTECTED]
I'm trying to embed a Python interpreter in a GUI I'm developing, and
I'm having trouble understanding the proper use of
code.InteractiveInterpreter.

Here's what I'm trying:

% python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from code import InteractiveInterpreter
>>> a = InteractiveInterpreter()
>>> a.runsource('a = 0')
False
>>> a.runsource('b = 0')
False
>>> a.runsource('print a,b')
0 0
False
>>> a.runsource('def q():')
True
>>> a.runsource('print "hi"')
File "", line 1
print "hi"
^
SyntaxError: invalid syntax
False


What's the proper way to call the interpreter instance for a multiline
example like this?

Thanks in advance,

Rick

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


Re: PyQt on a Server

2004-12-03 Thread Jerry Sievers
Bob Parnes <[EMAIL PROTECTED]> writes:
> my /etc/ld.so.conf file already has that lib in it. So something else is
> happening, but it clearly has nothing to do with python.

Have you run ldconfig (probably /sbin/ldconfig) since the line was
added to the /etc ld config file?

-- 
---
Jerry Sievers   305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobilehttp://www.JerrySievers.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hello all

2004-12-03 Thread Brian van den Broek
Ishwor Gurung said unto the world upon 2004-12-03 03:36:
Hello all,
  I am just starting out on learning Python and joined this list. I
have grabbed the Learning Perl book by Mark & David. This book really
seems good so far.. the concepts are explained pretty nicely. :) I
have a background a bit in Java but Python seems so cooler. The
concept of Dynamically assigning values n the objects springing into
existence is really nice to see especially you don't have to declare
variable everytime its used. In this book though it says Python 3.0 as
upcoming python version but all i see so far is Python 2.4 ?? Any
hints anyone has? So contrasting with Java  which is a bit like C++
where values and object has to be "created" before assigning, Python
seems very typical of "on the edge" language, "ready to go" language
:)
cheers,
Ishwor
Hi Ishwor,
*Learning Perl*? -- burn him, he's a witch! ;-)
I am only a hobbyist, and know just enough Python to be dangerous. But,
for what you ask:
Python recently released 2.4. Python 3.0 is definitely in the future.
Python seems to have quite a conservative stance with respect to
backwards compatibility. Most (all?) Python 1.5.2 code will still run on
Python 2.4. Python 3.0 is being pondered well in advance, because, as I
understand it, the 2.x to 3.x switch will be allowed to loosen the
backwards comp. requirement considerably. 2.3 -> 2.4 took 18 months. I
don't know how many more 2.x's are planned/likely, but there will be, as
I understand it, at least a 2.5.
Since you have a Java background, you might find the recent
 interesting. I
did, but I know even less Java than Python. So, YMMV.
Also, while you might be more of a programmer than the target audience,
the Tutor list is very good for people just getting started with Python.
 The main list is also quite
happy to answer newcomer help questions, but the Tutor folk specialize
at it.
HTH,
Brian vdB
--
http://mail.python.org/mailman/listinfo/python-list


We what judge the string using which encode?

2004-12-03 Thread hlddn
unicode or other?
we what judge?
thank all
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: window size in IDLE

2004-12-03 Thread Brian van den Broek
p.kosina said unto the world upon 2004-12-03 04:04:
Can I somehow in config-main.cfg set how big shall (and where) open  the 
IDLE window?  Cause in my w98 it is always opening so that I can not see 
the bottom line

Thank you
Pavel
Hi Pavel,
I had the same issue with IDLE 1.03 running on Python 2.3.4 with WinMe. 
(Please pity me.)

Yesterday I installed Python 2.4, and the included version of IDLE (1.1) 
has solved this for me. Try Menu->Options->Configure IDLE->General 
tab->Initial Window size. That option never did anything for me with 
IDLE 1.03, but with 1.1, works like a charm.

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


Re: how to list files with extension .txt in windows?

2004-12-03 Thread ed
I do have  permission toa ccess the file as that file is careted and read my me.
I have read/write access to that location. regards
Aaron Bingham <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> ed wrote:
> 
> >I have used batch script to do it but it has a lot of issues with
> >access denied... errors I pretty much given up using batch to do this.
> >  
> >
> If you do not have permission to access the files, switching to a 
> different language will not help you.  You need to determine the cause 
> of your access errors first.
> 
> Aaron
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How did you learn Python?

2004-12-03 Thread Philippe C. Martin
I used those:
http://diveintopython.org/
http://www.fzu.cz/texty/ruzne/python/
http://www.pythonware.com/library/tkinter/introduction/


Then O'Reilly 'Programming Python'

Regards,

Philippe



-- 
*
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How did you learn Python?

2004-12-03 Thread Brian van den Broek
Shawn Milo said unto the world upon 2004-12-03 09:54:
I was just wondering what the best books were for learning Python.
Which books are good for getting started, and which should be saved for
later, or or not useful except as a reference for the learned?
I have a decent programming background in VB, JavaScript, VBScript,
Net.Data (IBM's macro language), regular expressions, and a teensy bit of
Perl. My point is, I don't want something that is going to explain the basic
programming concepts, but does give a good introduction to Python-specific
things. Then, once I know how to get the job done, I would like a good book 
or two at the intermediate to advanced level, to learn how to write really good code.

I understand that resources such as this list and Google searches have all the answers,
but it seems like a more structured tool, such as a book or formal class, would be
of great benefit to me. The other languages I have used were picked up because of the
need to get a job done. As a result, I am able to get the job done, but any experienced
coder can show me six more efficient ways to do what I'm doing. I'm new to
Python, and I want to do this one right. I believe that Python will be
around for a good, long time, and it matches my values as an Open-Source/Linux
supporter, while having relevance in the Windows and Mac world, as well. 
Plus, it looks like it was designed extremely well, and I'm excited about the 
principles I've read about.

Thanks,
Shawn
Hi Shawn,
I'm not done learning (and not just in the sense that no one ever 
finishes learning -- I'm a hobbyist not a pro). But, I found Learning 
Python  really useful. Once 
I'd read that, Python in a Nutshell has been great to remind me of what 
I learned but 'misplaced' .

I've not read all of it, and it overlaps a fair bit with Learning 
Python, but the free Dive Into Python reads well and is often cited as a 
good intro for those with programming experience. 
. It is also available as a dead-tree 
product from APress.

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


Re: disk based dictionaries

2004-12-03 Thread Shivram U

Hi Steve, Larry,
   Thanks for the Help! I am using the pickle module now as i just need
to store and retrieve dictionaries. 

Best Regards,
Shivram U

On Thu, 2004-12-02 at 23:59, Steve wrote:
> Hi Shivam,
> 
> If storing and retrieving is all that you are interested in, you
> should consider 'pickling' your dicts, using python's pickle module.
> It's part of the standard library.
> Learn more about it here:
> http://docs.python.org/lib/module-pickle.html
> 
> Here's an example usage:
> 
> [EMAIL PROTECTED] ~]$ python
> Python 2.3.4 (#2, Aug 19 2004, 15:49:40) 
> [GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import pickle
> >>> d = {'foo':'bar', 1:'ham', 'eggs':10}
> >>> fl = open('mydict', 'wb')
> >>> pickle.dump(d, fl)
> >>> del(d)
> >>> dir()
> ['__builtins__', '__doc__', '__file__', '__name__', 'fl', 'pickle']
> >>> fl.close()
> >>> fl = open('mydict')
> >>> d = pickle.load(fl)
> >>> d
> {1: 'ham', 'eggs': 10, 'foo': 'bar'}
> >>>
> 
> HTH
> Regards
> steve
> 
> 
> On 02 Dec 2004 20:33:22 +0600, Shivram U <[EMAIL PROTECTED]> wrote:
> > 
> > Hi,
> > 
> >   I want to store dictionaries on disk. I had a look at a few modules
> > like bsddb, shelve etc. However would it be possible for me to do the
> > following
> > 
> > hash[1] = [1, 2, 3] where the key is an int and not a string
> > 
> > bsddb requires that both the key,value are string.
> > shelve does support values being object but not the keys. Is there any
> > module which support keys which are not strings
> > 
> > Also how do i use disk based hashes for multidimensional hashes such as
> > below
> > 
> > #!/usr/bin/python
> > 
> > dict={}
> > dict['key1'] = {}
> > dict[('key1')][('key2')] = 'value'
> > 
> > key1=dict['key1']
> > print key1['key2']
> > 
> > I have read of mxBeeDict but was unable to get it work properly. I am
> > not sure if it supports what i need as i was unable to get any
> > documentation about it. Is the module used widely ?
> > 
> > Below is how i am using the module
> > 
> > bdict = BeeDict('/tmp/beedict')
> > 
> > bdict[1] = 1
> > print bdict.keys()
> > 
> > bdict.commit()
> > bdict.close()
> > 
> > bdict1 = BeeDict('/tmp/beedict')
> > print bdict1.keys()
> > print bdict1.values()
> > 
> > Would it be that using disk based dictionaries once opened are as fast
> > as in memory dictionaries ?
> > 
> > Thanks in advance,
> > 
> > Best Regards,
> > Shivram U
> > 
> > Confidentiality Notice
> > 
> > The information contained in this electronic message and any attachments to 
> > this message are intended
> > for the exclusive use of the addressee(s) and may contain confidential or 
> > privileged information. If
> > you are not the intended recipient, please notify the sender at Wipro or 
> > [EMAIL PROTECTED] immediately
> > and destroy all copies of this message and any attachments.
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >




Confidentiality Notice 

The information contained in this electronic message and any attachments to 
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or 
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.
-- 
http://mail.python.org/mailman/listinfo/python-list


finding byte order

2004-12-03 Thread biner
Hello,

  I am using a program that has to read binary data from files coming
from different machines. The file are always written with big endian.
I am using the struct module to read the data and it is fine because I
can specify in the format if the data are to be read with big or small
endian convention.

  I would like to use the array module instead of struct because it is
suppose to be faster for big arrays. However, this module does not
provide a format specifier to say if the data are writtent with big or
small endian. The result is that it works on big-endian machine and
not on small-endian machine.

  I would like to have a test to tell me if the current machine is
using big or small endian, this way I could use the array module in
the first case and the *slower* struct module on the second. I looked 
but did not find. Is there a python function to know that?

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


freetype2 bindings?

2004-12-03 Thread Bill McClain
I have googled for Python bindings for freetype2 and have not found any recent
projects. The freetype page references this at Sourceforge:

   http://www.sourceforge.net/projects/pyft2

...but it is "nonexistent". Nothing else at Sourceforge for python + freetype.

I will wrap the api myself (my first such effort) but I didn't want to
duplicate someone else's efforts.

Regards,

-Bill
-- 
Sattre Press  History of Astronomy 
http://sattre-press.com/   During the 19th Century
[EMAIL PROTECTED]   by Agnes M. Clerke
  http://sattre-press.com/han.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pre-PEP generic objects

2004-12-03 Thread Ian Bicking
Istvan Albert wrote:
Steven Bethard wrote:
 > The question is not how easy it is to write,
 > but how many times it's going to get written.
but with that logic we could  create a standard
"looping" construct called loop(x) that would stand in for
for i in range(x):
IMHO, that example is quite the opposite of what you are advocating. 
range() is a simple function, and one which could be written by anyone 
with little chance of flaw.  Why not do:

i = 0
while i < x
...
i += 1
?  The three arguments to range are all present (how valuable are a few 
defaults).  It's more general.  You can extend it and modify it easily. 
 These are all the same properties of bunch.  Easy things have value; 
maybe that applies here, but saying that it is easy is not the same as 
saying it isn't valuable.  For instance, we now have the sorted 
function, equivalent to:

def sorted(lst, *args, **kw):
lst = list(list)
lst.sort(*args, **kw)
return lst
People have been writing this function over and over.  Only there are a 
few subtlely different ways you can implement it, and you'll never know 
which from the function name alone.  dict's keyword argument constructor 
is similar.  And maybe bunch is similar; at least, I'd argue for or 
against it based on that, not merely on how easy it is to reimplement. 
"If the implementation is easy to explain, it may be a good idea." 
(import this)

If it existed, I'd probably use it some where I'm currently using 
dictionaries (but where I don't want to give the data behavior), and I'd 
probably subclass it.  Now, when it doesn't exist, I frequently 
implement the behavior in classes that have other logic as well, and I 
almost never use it without logic; I use dict() with its keyword 
argument constructor, and just suffer the quotation marks when I'm 
retrieving members.

BTW, in class that look like bunch, I usually implement it like:
class bunch(object):
def __init__(self, **kw):
for name, value in kw.items():
# IMPORTANT!  This is subclass friendly: updating __dict__
# is not!
setattr(self, name, value)
def __call__(self, **kw):
# I'm not entirely happy with this:
new_values = self.__dict__.copy()
new_values.update(kw)
return self.__class__(**new_values)
--
Ian Bicking  /  [EMAIL PROTECTED]  /  http://blog.ianbicking.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help with use of code.InteractiveInterpreter for multiline code

2004-12-03 Thread Jean Brouwers

Take a look at the source code of the code module (file code.py in the
lib directory).  The push() method of the InteractiveConsole class
shows how to handle multi-line statements.

Basically, keep collecting lines as long as the result returned by the
runsource() call is true.  Maybe instead of calling the runsource()
method, just call the push() method.

/Jean Brouwers


In article <[EMAIL PROTECTED]>,
<"[EMAIL PROTECTED]"> wrote:

> I'm trying to embed a Python interpreter in a GUI I'm developing, and
> I'm having trouble understanding the proper use of
> code.InteractiveInterpreter.
> 
> Here's what I'm trying:
> 
> % python
> Python 2.3 (#1, Sep 13 2003, 00:49:11)
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from code import InteractiveInterpreter
> >>> a = InteractiveInterpreter()
> >>> a.runsource('a = 0')
> False
> >>> a.runsource('b = 0')
> False
> >>> a.runsource('print a,b')
> 0 0
> False
> >>> a.runsource('def q():')
> True
> >>> a.runsource('print "hi"')
> File "", line 1
> print "hi"
> ^
> SyntaxError: invalid syntax
> False
> 
> 
> What's the proper way to call the interpreter instance for a multiline
> example like this?
> 
> Thanks in advance,
> 
> Rick
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Difficulties POSTing to RDP Hierarchy Browse Page

2004-12-03 Thread Chris Lasher
Hello,
  I'm trying to write a tool to scrape through some of the Ribosomal
Database Project II's (http://rdp.cme.msu.edu/) pages, specifically,
through the Hierarchy Browser. (http://rdp.cme.msu.edu/hierarchy/)
  The Hierarchy Browser is accessed first through a page with a form.
There are four fields with several options to be chosen from (Strain,
Source, Size, and Taxonomy) and then a submit button labeled "Browse".
The HTML of the form is as follows (note, I am also including the
Javascript code, as it is called by the submit button):

excerpted HTML


function resetHiddenVar(){
var f_form = document.forms['hierarchyForm']; 
f_form.action= "HierarchyControllerServlet/start";
return ;
}




 

Hierarchy Browser - Start[ help ]

 

 

  
  


Strain:

 Type

Non Type 

Both 



Source:

 Uncultured 

 Isolates

 Both



Size:

 >1200

 <1200

 Both



Taxonomy:

 Bergey's

 NCBI

  

   
  









--end excerpted HTML--


The options I would like to simulate are browsing by strain=type,
source=both, size = gt1200, and taxonomy = bergeys. I see that the
form method is POST, and I read through the urllib documentation, and
saw that the syntax for POSTing is urllib.urlopen(url, data). Since
the submit button calls HierarchyControllerServlet/start (see the
Javascript), I figure that the url I should be contacting is
http://rdp.cme.msu.edu/hierarchy/HierarchyControllerServlet/start
Thus, I came up with the following test code:

Python test code---
#!/usr/bin/python

import urllib

options = [("strain", "type"), ("source", "both"),
   ("size", "gt1200"), ("taxonomy", "bergeys"),
   ("browse", "Browse")]

params = urllib.urlencode(options)

rdpbrowsepage = urllib.urlopen(
"http://rdp.cme.msu.edu/hierarchy/HierarchyControllerServlet/start";,
params)

pagehtml = rdpbrowsepage.read()

print pagehtml
-end Python test code--


However, the page that is returned is an error page that says the
request could not be completed. The correct page should show various
bacterial taxonomies, which are clickable to reveal greater detail of
that particular taxon.

I'm a bit stumped, and admittedly, I am in over my head on the subject
matter of networking and web-clients. Perhaps I should be using the
httplib module for connecting to the RDP instead, but I am unsure what
methods I need to use to do this. This is complicated by the fact that
these are JSP generated pages and I'm unsure what exactly the server
requires before giving up the desired page. For instance, there's a
jsessionid that's given and I'm unsure if this is required to access
pages, and if it is, how to place it in POST requests.

If anyone has suggestions, I would greatly appreciate them. If any
more information is needed that I haven't provided, please let me know
and I'll be happy to give what I am able. Thanks very, very much in
advance.

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


Re: Help with use of code.InteractiveInterpreter for multiline code

2004-12-03 Thread Jim Sizelove
[EMAIL PROTECTED] wrote:
I'm trying to embed a Python interpreter in a GUI I'm developing, and
I'm having trouble understanding the proper use of
code.InteractiveInterpreter.
[examples of calling the interpreter instance]
What's the proper way to call the interpreter instance for a multiline
example like this?
Thanks in advance,
Rick
I haven't worked with the code module before, but here is my go at it. 
It seems that the call to runsource() needs the entire multiline code at 
once, with newlines including a trailing newline:

>>> import code
>>> a = code.InteractiveInterpreter()
>>> a.runsource('def q():\nprint "hi, a"\n')
False
>>> a.runsource('q()')
hi, a
False
With the InteractiveConsole, you can push each line of code 
individually, like so:

>>> import code
>>> b = code.InteractiveConsole()
>>> b.push('def q():')
True
>>> b.push('print "hi, b"')
True
>>> b.push('')
False
>>> b.runsource('q()')
hi, b
False
HTH,
Jim
--
http://mail.python.org/mailman/listinfo/python-list


Re: We what judge the language using which question?

2004-12-03 Thread David Fraser
hlddn wrote:
unicode or other?
we what judge?
thank all
You need to usually know the encoding from the context, otherwise you'll 
have to guess. In this regard I find http://www.eki.ee/letter/ helpful

But if you want more details, you'll need to provide a clearer question ...
David
--
http://mail.python.org/mailman/listinfo/python-list


Psyco 1.3 released

2004-12-03 Thread Armin Rigo
Hi all,

Psyco 1.3 has been released:

 
  http://sourceforge.net/project/showfiles.php?group_id=41036   
 

 
Includes support for Python 2.4 (and of course still supports Python 2.1
to 2.3).  As always it comes with a few bugfixes, including a memory leak
when using the profiler.  Another good news is that the built-in functions
that read the local variables -- locals(), eval(), execfile(), vars(),
dir(), input() -- now work correctly!


A bientot,

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


Re: Module list generation

2004-12-03 Thread Scott David Daniels
Doug Kearns wrote:
Is this the best/simplest way to generate a module list?
python -c 'from pydoc import help; help("modules")'
Thanks,
Doug
I am not sure if this is what you want, but how about:
For python 2.4, try:
python -c "import sys; print sorted(sys.modules)"
For earlier pythons, use:
 python -c "import sys; nms = sys.modules.keys(); nms.sort(); print nms"
or:
 python -c "import sys; print sys.modules.keys()"
if you don't care about order.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >