a re problem

2005-05-28 Thread cheng
hi,all, i try to replace every target word found in the text

 for target in splitText:
if stopwords.find(target) >= 0 :
text = re.sub(r'\b%s\b','',text) &target

when i using the statment:

text = re.sub(r'\b%s\b','',text) &target

 get error : unsupported operand type(s) for &: 'str' and 'str'

is it some idea that can modity it and make it work?

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


search/replace in Python

2005-05-28 Thread Vamsee Krishna Gomatam
Hello,
I'm having some problems understanding Regexps in Python. I want
to replace "PHRASE" with
"http://www.google.com/search?q=PHRASE>PHRASE" in a block of 
text. How can I achieve this in Python? Sorry for the naive question but 
the documentation is really bad :-(

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


Re: write to the same file from multiple processes at the same time?

2005-05-28 Thread Do Re Mi chel La Si Do
Hi !


On windows, with PyWin32, to read this little sample-code :


import time
import win32file, win32con, pywintypes

def flock(file):
hfile = win32file._get_osfhandle(file.fileno())
win32file.LockFileEx(hfile, win32con.LOCKFILE_EXCLUSIVE_LOCK, 0, 0x, 
pywintypes.OVERLAPPED())

def funlock(file):
hfile = win32file._get_osfhandle(file.fileno())
win32file.UnlockFileEx(hfile, 0, 0x, pywintypes.OVERLAPPED())


file = open("FLock.txt", "r+")
flock(file)
file.seek(123)
for i in range(500):
file.write("AA")
print i
time.sleep(0.001)

#funlock(file)
file.close()




Michel Claveau



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


Re: What are OOP's Jargons and Complexities?

2005-05-28 Thread Xah Lee
The Rise of “Constructors” and “Accessors”

A instantiation, is when a variable is assigned a super-subroutine
(class). A variable assigned such a super-subroutine is now called a
instance of a class or a object.

In OOP practice, certain inner-subroutines (methods) have developed
into specialized purposes. A inner-subroutine that is always called
when the super-subroutine is assigned to a variable (instantiation), is
called a constructor or initializer. These specialized
inner-subroutines are sometimes given a special status in the language.
For example in Java the language, constructors are different from
methods.

In OOP, it has developed into a practice that in general the data
inside super-subroutines are supposed to be changed only by the
super-subroutine's inner-subroutines, as opposed to by reference thru
the super-subroutine. (In OOP parlance: class's variables are supposed
to be accessed/changed only by the class's methods.) Though this
practice is not universal or absolute. Inner-subroutines that change or
return the value of variables are called accessors. For example, in
Java, a string class's method length() is a accessor.

Because constructors are usually treated as a special method at the
language level, its concept and linguistic issues is a OOP machinery
complexity, while the Accessor concept is a OOP engineering complexity.

-
to be continued tomorrow.

This is part of an installment of the article
“What are OOP's Jargons and Complexities”
by Xah Lee, 20050128. The full text is at
 http://xahlee.org/Periodic_dosage_dir/t2/oop.html

© Copyright 2005 by Xah Lee. Verbatim duplication of the complete
article for non-profit purposes is granted.

The article is published in the following newsgroups:
comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.unix.programmer
comp.lang.python,comp.lang.perl.misc,comp.lang.scheme,comp.lang.java.programmer
comp.lang.functional,comp.object,comp.software-eng,comp.software.patterns

 Xah
 [EMAIL PROTECTED]
∑ http://xahlee.org/

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

Re: lambda a plusieurs arguments

2005-05-28 Thread nico
Bonjour,

> [EMAIL PROTECTED] seems to be a good place to post
> questions related to Python if you intend to use
> french.
> 
> -> http://www.aful.org/wws/arc/python/
> 
> ((
> des questions rédigées en français sont plus
> à leur place sur des liste de diffusions
> nationales ...
> ))

Désolé, je me suis trompé de groupe en postant... :(

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


Tkinter slowes down

2005-05-28 Thread pavel.kosina
It seems to me that in my "again and again repainting canvas" script the 
rendering is slowing down as the time goes.

It is visible even after 10 seconds.
Any idea why?

-- 
geon
The exception is rule.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda a plusieurs arguments

2005-05-28 Thread nico
Jp Calderone wrote:

> On Fri, 27 May 2005 19:38:33 +0200, nico <[EMAIL PROTECTED]> wrote:
>>Bonjour,
>>
>>Comment faire une fonction lambda a plusieurs arguments ?
>>
> (lambda a:a+1)(2)
>>3
> f=(lambda (a,b):a+b)
> f(5,6)
>>Traceback (most recent call last):
>>  File "", line 1, in ?
>>TypeError: () takes exactly 1 argument (2 given)
> f((5.6))
>  ^--- ,
> 
> >>> f((5, 6))
> 11
> >>>
> 
> Aussi,
> 
> >>> f = lambda a, b: a + b
> >>> f(5, 6)
> 11
> >>>
> 
> Jp


Ok, merci.

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


How to load plugins as objects?

2005-05-28 Thread censored
Hi. I'm hoping for a bit of programming guidance here 

I have an application I wrote (it's an irc bot fyi), with which I want to
use plugins. 

Basically, I want there to be directory called plugins/ . 

In plugins, there should be a bunch of *.py files. Each file should
contain a single class.

When the application launches, I want the interpreter to scan the
plugins/ dir for *.py files, and load each class in each every *.py file
as an object an object in memory. 

I want it to so that every time I want the app to perform a new function,
I just write a plugin and stick it in the plugins/ directory.

What's the easiest way to go about this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search/replace in Python

2005-05-28 Thread John Machin
Vamsee Krishna Gomatam wrote:
> Hello,
> I'm having some problems understanding Regexps in Python. I want
> to replace "PHRASE" with
> "http://www.google.com/search?q=PHRASE>PHRASE" in a block of 
> text. How can I achieve this in Python? Sorry for the naive question but 
> the documentation is really bad :-(

VKG,

Sorry you had such difficulty; if you can explain in a bit more detail, 
we could perhaps fix that "really bad" [compared with what?] documentation.

Whether you are doing a substitution programatically in Python, or in 
any other language, or manually using a text editor, you need to specify 
some input text, a pattern, and a replacement.

The syntax for pattern and replacement for what you want to do differs 
in only minor details (if at all) among major languages and common text 
editors, and it's been that way for years. For example, see the 
retro-computing museum exhibit at the end of this posting.

So, did you have any problem determining that PHRASE is represented by 
(.*) -- good enough if there is only one occurrence of your target -- in 
the pattern, and by \1 in the replacement?

Did you have a problem with this part of the docs (which is closely 
followed by an example with \1 in the replacement), and if so, what was 
the problem?

sub( pattern, repl, string[, count])

Return the string obtained by replacing the leftmost non-overlapping 

occurrences of pattern in string by the replacement repl.

Have you used regular expressions before? If not, then you shouldn't 
expect to learn how to use them from the documentation, which does 
adequately _document_ the provided functionality. This is just like how 
the manual supplied with a new car documents the car's functionality, 
but doesn't attempt to teach how to drive it. If you haven't done so 
already, you may like to do what the documentation suggests:

consult the Regular Expression HOWTO, accessible from 
http://www.python.org/doc/howto/.

And out with the magic lantern ... here's the promised blast from the 
past, using Oliver's sample input:

C:\junk>dir \bin\ed.com
[snip]
30/11/1985  04:43p  18,936 ed.com
[snip]
C:\junk>ed
Memory available : 59K bytes
 >a
This is a Python. And some randomnonsense test.
.
 >p
This is a Python. And some randomnonsense test.
 >s/\(.*\)<\/google>/\1<\/a>/
 >p
This is a http://www.google.com/search?q=Python>Python. And 
some randomnonsense test.
 >

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


Re: Software licenses and releasing Python programs for review

2005-05-28 Thread Ivan Voras
poisondart wrote:

> Ultimately I desire two things from the license (but not limited to):
> - being able to distribute it freely, anybody can modify it
> - nobody is allowed to make profit from my code (other than myself)

GPL does something like this, except it doesn't forbid anyone to sell 
the software. Also, you do realize that if you make it freely 
distributable and modifiable, you could get into the situations where 
potential customers say "so why should we buy it from him when we can 
get it free from X"?
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] pysqlite 2.0.3 released

2005-05-28 Thread Gerhard Haering
This is a minor bugfix release.

Wiki, bugtracker, downloads at http://pysqlite.org/

Changes since 2.0.2
===

The changes for prefetching in 2.0.2 were incomplete. A check that made
sense before had to be removed, otherwise fetchone() / fetchmany() /
fetchall() could raise ProgrammingErrors instead of returning None or an
empty list if no more rows are available.

Users of pysqlite 2.0.2 should definitely upgrade!
-- 
Gerhard Häring - [EMAIL PROTECTED] - Python, web & database development


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

Re: search/replace in Python

2005-05-28 Thread Leif K-Brooks
Oliver Andrich wrote:
> re.sub(r"(.*)",r" href=http://www.google.com/search?q=\1>\1", text)

For real-world use you'll want to URL encode and entityify the text:

import cgi
import urllib

def google_link(text):
text = text.group(1)
return '%s' % (cgi.escape(urllib.quote(text)),
cgi.escape(text))

re.sub(r"(.*)", google_link, "foo bar)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search/replace in Python (solved)

2005-05-28 Thread Vamsee Krishna Gomatam
Leif K-Brooks wrote:
> Oliver Andrich wrote:
> 
>
> For real-world use you'll want to URL encode and entityify the text:
> 
> import cgi
> import urllib
> 
> def google_link(text):
> text = text.group(1)
> return '%s' % (cgi.escape(urllib.quote(text)),
> cgi.escape(text))
> 
> re.sub(r"(.*)", google_link, "foo bar)


Thanks a  lot for your reply. I was able to solve it this way:
text = re.sub( "([^<]*)", r'http://www.google.com/search?q=\1";>\1', text )


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


Re: search/replace in Python (solved)

2005-05-28 Thread Leif K-Brooks
Vamsee Krishna Gomatam wrote:
> text = re.sub( "([^<]*)", r' href="http://www.google.com/search?q=\1";>\1', text )

But see what happens when text contains spaces, or quotes, or
ampersands, or...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Questions about wxPython...

2005-05-28 Thread Oliver Albrecht
Helmutt schrieb:
> Whats the name of the event that occur when I press the
> exit/cross-button on the frame?
> How do I connect a function with that event?

Hi,
I try just to begin the same.
I found this in the docu.

wxApp::OnExit
http://wxwidgets.org/manuals/2.5.3/wx_wxapp.html#wxapponexit

wxWindow::Close http://www.wxpython.org/docs/api/wx.Window-class.html#Close

wxCloseEvent
http://www.wxpython.org/docs/api/wx.CloseEvent-class.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to load plugins as objects?

2005-05-28 Thread Fredrik Lundh
"censored" <[EMAIL PROTECTED]> wrote:

> Hi. I'm hoping for a bit of programming guidance here 
>
> I have an application I wrote (it's an irc bot fyi), with which I want to
> use plugins.
>
> Basically, I want there to be directory called plugins/ .
>
> In plugins, there should be a bunch of *.py files. Each file should
> contain a single class.
>
> When the application launches, I want the interpreter to scan the
> plugins/ dir for *.py files, and load each class in each every *.py file
> as an object an object in memory.
>
> I want it to so that every time I want the app to perform a new function,
> I just write a plugin and stick it in the plugins/ directory.
>
> What's the easiest way to go about this?

for file in glob.glob("plugins/*.py"):
ns = {}
execfile(file, ns)
for name, object in ns.items():
# pick out interesting objects





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


smart logging and the "inspect" module ...

2005-05-28 Thread Darran Edmundson

I was playing around with the inspect module the other day
trying to write a quick and dirty "smart" logger.  By this I mean
that writing a message to the global log would also yield some
info about the calling scope.  If you look at my function "test"
below, I'd ideally like log messages:

foo.py:test, "message 1"
foo.py:Foo.__init__, "message 2"
foo.py:Foo.bar, "message 3"

For the life of me I can't figure out how to get this info without
resorting to ridiculous things like parsing the source code (available
via inspect.stack.

Any help would be much appreciated - my unit tests are failing
on this at the moment ;-)

Cheers,
Darran.

# foo.py -

import inspect

class Log:

 def __init__(self):
 pass

 def write(self, msg):
 print 
""
 print msg
 print 
""
 cframe, cmodule, cline, cfunction, csrc, tmp = inspect.stack()[1]
 print inspect.stack()

 # I want to determine if cfunction is a regular function or a 
class method.
 # If the latter, what is the name of the class?

 del cframe


def test():

 log = Log()
 log.write('message 1)

 class Foo:
 def __init__(self):
 log.write('message 2')

 def bar(self):
 log.write('message 3')

 f = Foo()
 f.bar()


test()

#- end of foo.py --
-- 
http://mail.python.org/mailman/listinfo/python-list


Is there a better way of doing this?

2005-05-28 Thread Michael
Hi,
I'm fairly new at Python, and have the following code that works but isn't
very concise, is there a better way of writing it?? It seems much more
lengthy than python code i have read. :-)
(takes a C++ block and extracts the namespaces from it)



def ExtractNamespaces(data):
 print("Extracting Namespaces")
 p = re.compile( 'namespace (?P[\w]*)[\n\t ]*{')

 subNamespaces = []

 newNS = p.search(data)
 while( newNS ):
  print "\t" + newNS.group("name")

  OPCount = 1
  Offset = newNS.end()
  while(OPCount > 0):
   if( data[Offset] == "}" ):
OPCount = OPCount -1;
   elif( data[Offset] == "{" ):
OPCount = OPCount + 1;
   Offset = Offset+1;

  #Extract Data:
  newNSData = data[newNS.end():Offset-1]
  data = data[0:newNS.start()] + data[Offset:]
  newNamespace = [newNS.group("name"), newNSData];
  subNamespaces.append(newNamespace)

  #Perform NewSearch
  newNS = p.search(data)
 return [subNamespaces,data]






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


Re: Tkinter slowes down

2005-05-28 Thread Fredrik Lundh
"pavel.kosina" <[EMAIL PROTECTED]> wrote:

> It seems to me that in my "again and again repainting canvas" script the
> rendering is slowing down as the time goes.

when you add an item to the canvas, it's part of the canvas
until you remove it.  if performance drops, it's usually because
you keep adding new items without removing the old ones.

try adding a w.delete(ALL) call before you "repaint".

for better performance, you should restructure your code so
it modifies existing canvas items, when possible, rather than
deleting and recreating items all the time.

if you want a light-weight canvas, you might wish to look at

http://effbot.org/zone/wck.htm

and especially

http://effbot.org/zone/wck-3.htm





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


Threading questions

2005-05-28 Thread Antal Rutz
Hi, All!

I'm new to threading. I have some design questions:
Task: I collect data and store them in an RDBMS (mysql or pgsql)

The question is how to do that with threading?
The data-collecting piece of the code runs in a thread.

1. Open the db, and each thread writes the result immediately.
   (Sub-question: which is better: cursor object passed to the thread
   or stored in a global var.)
2. Threads return data, which is written to DB after that.
3. Threads write to global variable, after 'join()' data is written.
   (Can be used global (write-only) variables with threads at all?)
4. ?...

I think variable locking isn't an issue here because they are write-only.

Maybe I have fundamentaly misunderstood something...

Thanks

-- 


--arutz

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


CVS interface module

2005-05-28 Thread Jim
Hello,

Inside of a Python script I need to work a CVS archive.  Nothing fancy,
but I need to update the local tree, change or add some files from time
to time, and commit.  Naturally I looked for a module that would allow
me to easily see if there were conflicts, the server is down, etc.

I've looked in this group, Googled around, etc., but I've not found
anything.  Is there a reasonably mature project that people use for
this purpose?

Thanks,
Jim

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


Re: CVS interface module

2005-05-28 Thread Fredrik Lundh
"Jim" wrote:

> Inside of a Python script I need to work a CVS archive.  Nothing fancy,
> but I need to update the local tree, change or add some files from time
> to time, and commit.  Naturally I looked for a module that would allow
> me to easily see if there were conflicts, the server is down, etc.
>
> I've looked in this group, Googled around, etc., but I've not found
> anything.

have you seen

http://pycvs.sourceforge.net/

?

(on the other hand, if it's your own archive, you might wish to switch to
a more modern CVS-style system, http://subversion.tigris.org, which has
a native Python API)





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


Re: unbuffering std streams in code

2005-05-28 Thread Fredrik Lundh
John Reese wrote:

> You know how you can specify that stderr, stdin, stdout should be
> unbuffered by running python with the -u switch?  Is there any way I
> can have the same affect in code by doing something to the sys.std*
> variables?

try this:

>>> import os, sys
>>> sys.stdout = os.fdopen(sys.stdout.fileno(), sys.stdout.mode, 0)

(repeat for the other streams)

(-u does a bit more than this on some platforms, but the above
should be good enough for many purposes)





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


__call__

2005-05-28 Thread TK
Hi,

how can handle __call__? Can you give a sample?

Thanks

o-o

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


Re: CVS interface module

2005-05-28 Thread Jim
Thank you; in fact I did see that.  Forgive me, but it is often
difficult to tell what on sf is helpful.  I noted the version number
0.1, the file date of 2003, that there are essentially no hits (that
is, that people seem not to be downloading), and that there is almost
no traffic in the forums.  It made me wonder if there was something
else that people were using that somehow I was not finding.  But I
guess I was mistaken.

Thank you also for the svn suggestion, but I am working with an
existing archive that at least at the moment is cvs.

I'll do the download,
Jim

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


Is there already a Python module to access the USPTO web site?

2005-05-28 Thread Terry Carroll
I have the need to run periodic searches on the US Patent and
Trademark Office website, .  I need a Python
module to do this.  Before I reinvent the wheel, I thought I'd check
to see if anyone knew of such a beast.

For instance, I'd like to be able to pass an argument like one of
these:

  an/"dis corporation"
  in/newmar-julie

to http://patft.uspto.gov/netahtml/search-adv.htm and get a list of
all the patents owned by Dis Corporation, or invented by the 1960s
Catwoman actress; or pass a patent number like 4,150,505 to
http://patft.uspto.gov/netahtml/srchnum.htm to bring up a particular
patent.

Then I want to be able to parse out the patent metadata, e.g. inventor
names, dates filed and issued, etc.

Has this already been done?

The closest my google searches have turned up is
http://hacks.oreilly.com/pub/h/1724 , but that turns out to be Perl
rather than Python, and not quite dead-on anyway.


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


Re: Software licenses and releasing Python programs for review

2005-05-28 Thread Robert Kern
poisondart wrote:
> Hi,
> 
> I'm not sure if this is the right group to post this. If not, then I
> would appreciate if somebody could point me to the correct group.
> 
> This is my first time releasing software to the public and I'm wanting
> to release a Python program I wrote for review (and critique) and
> testing on other platforms, but also I would like to explore the
> different software licenses that are available (there seems to be
> many). Since the specification for the programs is knowledge-centric
> (related to linguistics), I need a group of people that are
> knowledgeable in this area. Is there a place where I can advertise to
> look for people who are knowledgeable in Python and linguistics?

The NLTK mailing list might be a good place.

http://nltk.sourceforge.net

> Ultimately I desire two things from the license (but not limited to):
> - being able to distribute it freely, anybody can modify it
> - nobody is allowed to make profit from my code (other than myself)

Well, this is vague. Do you want no one else to *distribute* your code 
or derivatives thereof for profit? or do you want no one else to be able 
to *use* the code for profit-making activities?

Either way, it's kind of rude and unproductive to ask people to spend 
their unpaid time to review, critique, and test your code when only you 
can make a profit from it. I highly recommend looking at the GPL. Many 
of the people whom you may want to not distribute your code for profit 
will probably be reluctant to use GPLed code. As a bonus, if they do, 
they will have to contribute their changes back to the community under 
the GPL, too, so you can incorporate them into your own code base.

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


Re: __call__

2005-05-28 Thread Simon Percivall
Look at http://docs.python.org/ref/callable-types.html

>>> class Test(object):
... def __call__(self):
... print "the instance was called"
...
>>> t = Test()
>>> t()
the instance was called

Is this what you wanted?

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


Re: smart logging and the "inspect" module ...

2005-05-28 Thread George Sakkis
"Darran Edmundson" wrote:
> I was playing around with the inspect module the other day
> trying to write a quick and dirty "smart" logger.  By this I mean
> that writing a message to the global log would also yield some
> info about the calling scope.  If you look at my function "test"
> below, I'd ideally like log messages:
>
> foo.py:test, "message 1"
> foo.py:Foo.__init__, "message 2"
> foo.py:Foo.bar, "message 3"
>
> For the life of me I can't figure out how to get this info without
> resorting to ridiculous things like parsing the source code (available
> via inspect.stack.
>
> Any help would be much appreciated - my unit tests are failing
> on this at the moment ;-)
>
> Cheers,
> Darran.

Unfortunately introspection gives access to frame and code objects, but
not to the callable objects (functions, methods, builtins); I think the
reason is that code objects can be shared for different callables.
Also, even the function name and the line number are misleading if
there is an alias (e.g. baz = bar). By the way, here's an alternative
that doesn't use inspect.

import sys

class Log:
def write(self,message):
frame = sys._getframe(1)
code = frame.f_code
print "%s:%d:%s, %s" % (code.co_filename, frame.f_lineno,
code.co_name, message)


There's a logging module in the standard library btw; make sure you
check it out before going on and extending the quick and dirty logger.

Regards,
George

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


Re: Threading questions

2005-05-28 Thread F. GEIGER
Just an idea: You could have n data collector threads, that all put their
results into a queue connected to 1 db thread, that stores the results into
the db.

Cheers
Franz GEIGER


"Antal Rutz" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> Hi, All!
>
> I'm new to threading. I have some design questions:
> Task: I collect data and store them in an RDBMS (mysql or pgsql)
>
> The question is how to do that with threading?
> The data-collecting piece of the code runs in a thread.
>
> 1. Open the db, and each thread writes the result immediately.
>(Sub-question: which is better: cursor object passed to the thread
>or stored in a global var.)
> 2. Threads return data, which is written to DB after that.
> 3. Threads write to global variable, after 'join()' data is written.
>(Can be used global (write-only) variables with threads at all?)
> 4. ?...
>
> I think variable locking isn't an issue here because they are write-only.
>
> Maybe I have fundamentaly misunderstood something...
>
> Thanks
>
> --
>
>
> --arutz
>


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


Re: Tkinter slowes down

2005-05-28 Thread pavel.kosina
Fredrik Lundh napsal(a):
> when you add an item to the canvas, it's part of the canvas
> until you remove it.  if performance drops, it's usually because
> you keep adding new items without removing the old ones.
> 
> try adding a w.delete(ALL) call before you "repaint".
> 

In the meantime I found that widget.destroy() works well, too (before 
"repainting").

Thanks  a lot

-- 
geon
Vyjímka je pravidlo. Rekurzivní.
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with choice of suitable Architecture

2005-05-28 Thread Rob Cowie
Hi,

This is my first post so go easy!

I have been asked (as part of an MSc project) to create a server based
planner for a research group at my uni. It will have a web interface to
interact with data stored in an XML document. Basic functionality is
required such as viewing, searching, editing, creating and deleting
entries for things such as paper submission deadlines, events, funding
application deadlines. I would also like to use AJAX principles in the
web interface.
Additionaly, it must email a BibTex file once a month to a
predetermined address.

I'm totally new to web programming. I have been looking into the best
way to proceed. CGI is of course an option but it seems slow, clunky
and outdated. Twisted provides a rich architecture but might be
overkill. Nevow seems to be very popular.
I suspect I could achieve what I want using PHP but I would really like
to get to grip with Python.

I'm not asking for a comparison of each architecture per se that
seems to be well covered in this group. I would like to know how you
all would set about creating this realtively simple application.

Cheers,
Rob Cowie
Coventry University, Britain

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


Re: Determine if windows drive letter is hard drive or optical from python?

2005-05-28 Thread Wolfgang Strobl
"mh" <[EMAIL PROTECTED]>:

>2. More importantly for those drives that exist, how do I determine if
>it is actually a harddrive?

C:\>python
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32file,string
>>> def harddisks():
... driveletters=[]
... for drive in string.letters[len(string.letters)/2:]:
... if win32file.GetDriveType(drive+":")==win32file.DRIVE_FIXED:
... driveletters.append(drive+":")
... return driveletters
...
>>> harddisks()
['C:', 'F:']

-- 
Thank you for observing all safety precautions
-- 
http://mail.python.org/mailman/listinfo/python-list


a dict problem

2005-05-28 Thread cheng
hi all..it a problem about dict:

print target, dict[target]

get output:

keyword
{page3.html, page2.html, page1.html}

is it some ways to change it to:

keyword
{page1.html, page2.html, page3.html}

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


Re: __call__

2005-05-28 Thread TK
class Test(object):
> 
> ... def __call__(self):
> ... print "the instance was called"
> ...
> 
t = Test()
t()
> 
> the instance was called
> 
> Is this what you wanted?

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


Re: first release of PyPy

2005-05-28 Thread Kay Schluehr
Anton Vredegoor wrote:

> I'm not involved in PyPy myself but this would seem a logical
> possibility. To go a step further, if the compiler somehow would know
> about the shortest machine code sequence which would produce the
> desired effect then there would be no reason to limit onself to only
> those relatively inefficent standard code sequences that are inside
> system dll's.

Are You shure that this problem is effectively solvable in any
language? Since You did not precise Your idea I'm not shure whether You
want to solve the halting-problem in PyPy or not ;)

Kay

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


Re: a dict problem

2005-05-28 Thread Benji York
cheng wrote:
 > hi all..it a problem about dict:
 >
 > print target, dict[target]
 >
 > get output:
 >
 > keyword
 > {page3.html, page2.html, page1.html}
 >
 > is it some ways to change it to:
 >
 > keyword
 > {page1.html, page2.html, page3.html}

First, I would recommend you always post actual code and its output.
It is much easier for people to help you that way.  Also, "dict" is
not a good variable name because it shadows the built-in of the same
name.

I'll extrapolate from your message that you want to get the values of
the dict in sorted order.  If so, here's how:

 >>> d = {'a': 1, 'b': 2, 'c':3}
 >>> d
{'a': 1, 'c': 3, 'b': 2}
 >>> v = d.values()
 >>> v
[1, 3, 2]
 >>> v.sort()
 >>> v
[1, 2, 3]
--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a dict problem

2005-05-28 Thread Steven Bethard
Benji York wrote:
> I'll extrapolate from your message that you want to get the values of
> the dict in sorted order.  If so, here's how:
> 
>  >>> d = {'a': 1, 'b': 2, 'c':3}
>  >>> d
> {'a': 1, 'c': 3, 'b': 2}
>  >>> v = d.values()
>  >>> v
> [1, 3, 2]
>  >>> v.sort()
>  >>> v
> [1, 2, 3]

Or in Python 2.4:

py> d = {'a': 1, 'b': 2, 'c':3}
py> sorted(d.values())
[1, 2, 3]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a re problem

2005-05-28 Thread James Stroud

py> import re
py> target = 'blah'
py> text = 'yaddah blah yaddah yaddah'
py> ext = re.sub(r'\b%s\b' % target,'',text)
py> ext
'yaddah  yaddah yaddah'


On Friday 27 May 2005 10:56 pm, cheng wrote:
> hi,all, i try to replace every target word found in the text
>
>  for target in splitText:
> if stopwords.find(target) >= 0 :
> text = re.sub(r'\b%s\b','',text) &target
>
> when i using the statment:
>
> text = re.sub(r'\b%s\b','',text) &target
>
>  get error : unsupported operand type(s) for &: 'str' and 'str'
>
> is it some idea that can modity it and make it work?

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with choice of suitable Architecture

2005-05-28 Thread Tomasz Rola
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 28 May 2005, Rob Cowie wrote:

[...]
> I'm totally new to web programming. I have been looking into the best
> way to proceed. CGI is of course an option but it seems slow, clunky
> and outdated. Twisted provides a rich architecture but might be
> overkill. Nevow seems to be very popular.

You know, "slow" from 10 years ago, when this opinion formulated, is not
the same "slow" nowadays. Imho, CGI is more straightforward and you can
learn it faster. After all, you have not only to make a web output but
also some mechanics under the hood - manipulating data etc. BTW, does it
have to be stored in xml file? The SQL database could be easier. You can
add import and export to/from xml file if this is really needed.

Whether it is too slow - well, how many times do you expect people will
open this page? I mean, how many times a second? I think this is the most
important question when deciding about CGI.

You may also consider mod_python:

http://www.modpython.org/

> I suspect I could achieve what I want using PHP but I would really like
> to get to grip with Python.
> 
> I'm not asking for a comparison of each architecture per se that
> seems to be well covered in this group. I would like to know how you
> all would set about creating this realtively simple application.

Personally, I would rather use Python. Right now, this app may seem to be
simple but I think it will grow over time. I'm not very used to PHP but
those simple things I did in it make me think Python may help me more as a
language, to program a page. PHP is probably more popular in web desing
circles, and there are some nice packages written in it, that you can drag
from the web and drop into your server, and have all those blogs and
webmails the easy way.

But for programming, and later on for maintaining such project, I'd rather
go with Python. Personal reason: it is cleaner, I like looking at it.

Of course you should decide for yourself. I've just pointed to few things
but it is up to you to taste both languages and decide which one is better
in your case.

Regards,
Tomasz Rola

- --
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[EMAIL PROTECTED] **

-BEGIN PGP SIGNATURE-
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBQpi3VxETUsyL9vbiEQJm6wCdEuOSUKKf7ZERnHOKvezqU9UJ9+QAn18a
GkUjNiMrCaXyQFNU0z7Jj3nq
=4LU4
-END PGP SIGNATURE-


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


Re: Case Sensitive, Multiline Comments

2005-05-28 Thread Mike Meyer
Dennis Lee Bieber <[EMAIL PROTECTED]> writes:

> On 26 May 2005 17:33:33 -0700, "Elliot Temple" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>> Thanks for the link on case sensitivity.  I'm curious about the person
>> who found case sensitivity useful though: what is it useful for?
>> 
>   Making a language run faster on slow machines since the syntax
> parsing doesn't have to do the equivalent of upper or lower casing
> anything that is not a string literal before checking for keywords or
> identifiers.
>
>   Consider the time spent by languages like Ada and Fortran when
> they have to do case normalization every time you compile.

Hopefully, this should be minimal. You canonicalize them all as soon
as you realize you can. With proper language design, this may be as
soon as you recognize that they aren't in a string.

This brings to mind the reason I quit using Microsoft products. I was
writing z80 assembler, and habitually wrote everything in lower case,
including all the op codes.

The assembler refused to recognize the indexed instruction opcodes
that were present on the z80 but not the 8080. I double-checked the op
codes, did the "delete and retype" thing, and in general went crazy
trying to figure out what was wrong.

I eventually called Microsoft and asked. The answer was "Those have to
be in upper case." That told me enough about the insides of MS
software that I swore off it, and have never purchased an MS product
since.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Trying to understand pickle.loads withou class declaration

2005-05-28 Thread Philippe C. Martin
Hi,

Shuffling files around in my project, I notice I broke everything when I
stopped declaring classes in a program that "pickled.loaded" existing
pickled object of type "classes".

The error message being that the class(es) was unknown.

However, I _think_, I did manage to do the following in the past:

1) pickle.dump class "test" with field "A" intialized in declaration
2) pickle.load class "test" and add field "B" then pickle.dumps it
3) pickl.load class "test" with no problem although field "B" was not
initialized in that declaration.


I have two questions:

1) Why cannot the interpreter accept to load an object which class is not
defined ?
2) assuming the above ( I _think_ ) is true, why then is there not
problem in loading an object which changes dynamically.

Hope I'm making sense.

Any clue ?

Thanks,

Philippe

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


Re: Is there already a Python module to access the USPTO web site?

2005-05-28 Thread Tomasz Rola
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Sat, 28 May 2005, Terry Carroll wrote:

> I have the need to run periodic searches on the US Patent and
> Trademark Office website, .  I need a Python
> module to do this.  Before I reinvent the wheel, I thought I'd check
> to see if anyone knew of such a beast.

I don't know but if you are determined to have it in Python, perhaps ypu
should check MozPython.

http://www.thomas-schilz.de/MozPython/README.html

- From what it says, mozpython can access Mozilla internals, so I expect it
to be able to browse in automatic way. This would left only parsing
responces from the server to you.

But I had no time to play with it, so if I am wrong, don't beat me too
hard.

Regards,
Tomasz Rola

- --
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[EMAIL PROTECTED] **


-BEGIN PGP SIGNATURE-
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBQpi6fhETUsyL9vbiEQLJcACfRN99KrmM1g+/ZDGRsEeLASRSItMAn3mc
APaZtygdsUKsQ57B0ZchfTdp
=2wME
-END PGP SIGNATURE-


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


Re: Threading questions

2005-05-28 Thread [EMAIL PROTECTED]
For threading I use usually this recipe as a base:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65448, I think
you can use it for your purpose as well.

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


Re: write to the same file from multiple processes at the same time?

2005-05-28 Thread Mike Meyer
Paul Rubin  writes:
> Really, I think the Python library is somewhat lacking in not
> providing a simple, unified interface for doing stuff like this.

It's got one. Well, three, actually.

The syslog module solves the problem quite nicely, but only works on
Unix. If the OP is working on Unix systems, that may be a good
solution.

The logging module has a SysLogHandler that talks to syslog on
Unix. It also has an NTEventLogHandler for use on NT. I'm not familiar
with NT's event log, but I presume it has the same kind of
functionality as Unix's syslog facility.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand pickle.loads withou class declaration

2005-05-28 Thread Philippe C. Martin
I confirm that all I have to do in order to successfully load a pickled
object of class A is to declare

class A:
def __init__(self):
   pass

Although the object has tons of fields


Quid ?

Regards,

Philippe





Philippe C. Martin wrote:

> Hi,
> 
> Shuffling files around in my project, I notice I broke everything when I
> stopped declaring classes in a program that "pickled.loaded" existing
> pickled object of type "classes".
> 
> The error message being that the class(es) was unknown.
> 
> However, I _think_, I did manage to do the following in the past:
> 
> 1) pickle.dump class "test" with field "A" intialized in declaration
> 2) pickle.load class "test" and add field "B" then pickle.dumps it
> 3) pickl.load class "test" with no problem although field "B" was not
> initialized in that declaration.
> 
> 
> I have two questions:
> 
> 1) Why cannot the interpreter accept to load an object which class is not
> defined ?
> 2) assuming the above ( I _think_ ) is true, why then is there not
> problem in loading an object which changes dynamically.
> 
> Hope I'm making sense.
> 
> Any clue ?
> 
> Thanks,
> 
> Philippe

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


Re: Help with choice of suitable Architecture

2005-05-28 Thread Paul Rubin
"Rob Cowie" <[EMAIL PROTECTED]> writes:
> I have been asked (as part of an MSc project) to create a server based
> planner for a research group at my uni. It will have a web interface to
> interact with data stored in an XML document. 

Why not just a regular database?

> Basic functionality is required such as viewing, searching, editing,
> creating and deleting entries for things such as paper submission
> deadlines, events, funding application deadlines. I would also like
> to use AJAX principles in the web interface.

Yecch, just use standard HTML, don't depend on client scripting
without a concrete good reason.  It makes stuff more confusing for
both human and automated users, and makes people weaken their browser
security by enabling scripting.  That stuff went out of style with
pop-up ads.

> Additionaly, it must email a BibTex file once a month to a
> predetermined address.

That's no big deal.

> I'm totally new to web programming. I have been looking into the best
> way to proceed. CGI is of course an option but it seems slow, clunky
> and outdated. Twisted provides a rich architecture but might be
> overkill. Nevow seems to be very popular.

CGI is conceptually the simplest, but leaves you needing to do a bunch
of stuff yourself.  A database back end helps a lot in dealing with
concurrent updates.  There's a bunch of other Python web frameworks
too (Spyce, CherryPy, Zope, ...).

For a generic overview, you might look at the now-somewhat-outdated
book "Philip and Alex's Guide to Web Publishing",

http://philip.greenspun.com/panda/


> I suspect I could achieve what I want using PHP but I would really like
> to get to grip with Python.

If the goal is simply to get to the finish line, PHP might get you
there faster for something like this.  If it's an academic project
where "the journey is the reward" there's lots of things you can try.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pygame 1.6 for windows (python2.4)

2005-05-28 Thread burlo . stumproot
Will McGugan <[EMAIL PROTECTED]> writes:

> bc wrote:
> > Thanks for the reply, Will... I have been to the site, but I get a "URL
> > not found error" when I try the pygame 1.6 for python24 link;  I guess
> > I will just keep trying until the HTML is fixed.
> > 
> 
> Does seem to be broken at the moment. I've uploaded a copy to my server..
> 
> http://www.willmcgugan.com/pygame-1.6.win32-py2.4.exe
> 
> Will

And thanks from me too.

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


Re: Parsing a Python dictionary inside a Python extension

2005-05-28 Thread tiissa
[EMAIL PROTECTED] wrote:
> I tried something like this and it has not worked.

Oh! What did you ask of it, what did you expect and what did you get?


> if ( (item = PyDict_GetItemString( vdict , "atab1")) != NULL )   
> PyArg_ParseTuple( item , "i" , &atab1   );

This code expects a dictionary in which keys 'atab1' and 'atab2' are 
singletons of integer. If that's what you want, I'd say it should work.


> //  ndict = Py_BuildValue( create dictionary here ..)
> 
> return ndict ;
> }

I personnally prefer 'return Py_BuildValue("");' than returning NULL 
pointers (but I don't like to check the doc just to make sure NULL can 
be interpreted as None).

In order to build a dictionary you could try:

...
 return Py_BuildValue("{s:i,s:i}", "key1", atab1, "key2", atab2);
}

Or even "{s:(i),s:(i)}" to have singletons for values.


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


Re: __call__

2005-05-28 Thread TK
Simon Percivall wrote:
> Look at http://docs.python.org/ref/callable-types.html
> 
> 
class Test(object):
> 
> ... def __call__(self):
> ... print "the instance was called"
> ...
> 
t = Test()
t()
> 
> the instance was called
> 
> Is this what you wanted?

Sorry but it does not work. Here's my code:

 >>> class Test(object):
... def __call__(self):
... print 'Hi'
...
 >>> Test()
<__main__.Test object at 0x3e6d0>


o-o

Thomas

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


Getting value of radiobutton trouble

2005-05-28 Thread VK
Hi!
What I'm missing in following code? Cannot get the values of 
radiobuttons. Starting only one class (GetVariant), it works. When I put 
two classes together, it doesn't.
Regards, VK

from Tkinter import *
class GetVariant:
 def __init__(self):
 self.root = Tk()
 self.mainframe = Frame(self.root,bg="yellow")
 self.mainframe.pack(fill=BOTH,expand=1)

 self.firstframe = Frame(self.mainframe,bg="red")
 self.firstframe.pack(side=BOTTOM,expand=1)

 global v
 v = StringVar()
 self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
1", variable=v, value="Variant 1")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton.select()
 self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
2", variable=v, value="Variant 2")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
3", variable=v, value="Variant 3")
 self.radiobutton.pack(side=TOP,anchor=W)



 self.secondframe = Frame(self.mainframe,bg="blue")
 self.secondframe.pack()
 self.var = Button(self.secondframe,text="What 
Variant",command=self.call)
 self.var.pack(expand=1,side=BOTTOM)



 def call(self):
 self.variant = v.get()
 print 'Input => "%s"' % self.variant

class OneButton:
 def __init__(self):
 self.root = Tk()
 Button(self.root,text="click me",command=self.getvar).pack()
 def getvar(self):
 a=GetVariant()

d = OneButton()
d.root.mainloop()


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


Re: __call__

2005-05-28 Thread Mike Meyer
TK <[EMAIL PROTECTED]> writes:
> Simon Percivall wrote:
>> Look at http://docs.python.org/ref/callable-types.html
>>
>class Test(object):
>> ... def __call__(self):
>> ... print "the instance was called"
>> ...
>>
>t = Test()
>t()
>> the instance was called
>> Is this what you wanted?
>
> Sorry but it does not work. Here's my code:
>
>  >>> class Test(object):
> ... def __call__(self):
> ... print 'Hi'
> ...
>  >>> Test()
> <__main__.Test object at 0x3e6d0>

Test() invokes the class, which returns an instance of the class.

Look back at what Simon did. He stored the value returned by Test() as
t, then called t with "t()". That's what __call__ is - the routine
invoked when an instance of a class is invoked as a callable object.

To change what happens when the class is invoked as a callable object,
you need to fool with metaclasses.

It might help if you told us what you really wanted to do with this
construct.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with choice of suitable Architecture

2005-05-28 Thread Rob Cowie
I agree with the sentiments that a single XML file is not the way to go
for storing data that may be accessed concurrently. However, my hands
are tied.

It seems that CGI is likely to be the most straightforward option. Is
the learning curve likely to be steeper for pure CGI or a web
application architecture such as Nevow?

Paul. I agree that client-side scripting increases the level of
compexity, but did it really go out of fashion with pop-ups? It seems
to be just getting started. Google use it to great effect maps,
suggest etc. I wasn't thinking of using it to deal with any 'business
logic', just to add some dynamism to the interface - use
XMLhttprequests, a bit of DOM scripting etc.

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


Re: __call__

2005-05-28 Thread tiissa
TK wrote:
> Sorry but it does not work.

It _does_ work. It just don't do what you expect. That's different till 
you know how to do it.

Let's see:

 >  >>> class Test(object):
 > ... def __call__(self):
 > ... print 'Hi'
 > ...

You first define a class whose members can be called.

 >  >>> Test()
 > <__main__.Test object at 0x3e6d0>

Then you build an instance of these class. Fine.

If you want to call this instance you have to tell python:

 >>> class Test:
... def __init__(self):
... print 'In init.'
... def __call__(self):
... print 'In call.'
...
 >>> t=Test()
In init.
 >>> t()
In call.
 >>> Test()
In init.
<__main__.Test instance at 0x401e2b6c>
 >>> Test()()
In init.
In call.
 >>>
-- 
http://mail.python.org/mailman/listinfo/python-list


UTF16 codec doesn't round-trip?

2005-05-28 Thread John Perks and Sarah Mount
(My Python uses UTF16 natively; can someone with UTF32 Python let me
know if that behaves differently?)

>>> import codecs
>>> u'\ud800' # part of surrogate pair
u'\ud800'
codecs.utf_16_be_encode(_)[0]
'\xd8\x00'
codecs.utf_16_be_decode(_)[0]
Traceback (most recent call last):
  File "", line 1, in ?
UnicodeDecodeError: 'utf16' codec can't decode bytes in position 0-1:
unexpected end of data

If the ascii can't be recognized as UTF16, then surely the codec
shouldn't have allowed it to be encoded in the first place? I could
understand if it was trying to decode ascii into (native) UTF32.

On a similar note, if you are using UTF32 natively, are you allowed to
have raw surrogate escape sequences (paired or otherwise) in unicode
literals?

Thanks

John


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


Re: Help with choice of suitable Architecture

2005-05-28 Thread Mike Meyer
"Rob Cowie" <[EMAIL PROTECTED]> writes:

> Paul. I agree that client-side scripting increases the level of
> compexity, but did it really go out of fashion with pop-ups? It seems
> to be just getting started. Google use it to great effect maps,
> suggest etc. I wasn't thinking of using it to deal with any 'business
> logic', just to add some dynamism to the interface - use
> XMLhttprequests, a bit of DOM scripting etc.

It's clearly not gone. Just remember, that people do turn it off for
security reasons. Doing so also does a good job of killing popups and
the like. I normally run with JavaScript off, and the local city
government has installed IE with it disabled on all their desktops.

So make sure the functionality of the site doesn't require javascript
to be enabled. This may require duplicating functionality, but you can
save your design by hiding the non-javascript version of the
functionality in a  element.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with choice of suitable Architecture

2005-05-28 Thread Paul Rubin
"Rob Cowie" <[EMAIL PROTECTED]> writes:
> Paul. I agree that client-side scripting increases the level of
> compexity, but did it really go out of fashion with pop-ups? It seems
> to be just getting started.

Pop-ups and scripting-related security holes are why the cool kids all
surf with Javascript turned off.  Who cares about what Joe Sixpack is
doing?  ;-)

Anyway, don't increase complexity without a good reason.

> Google use it to great effect maps, suggest etc. I wasn't
> thinking of using it to deal with any 'business logic',

There is some case to be made that the Google maps interface presents
concrete good reasons to use scripting, falling into the "concrete
good reason" exception.  I dunno about "suggest".  I do see that
Google Groups uses scripting in an unnecessary and obnoxious way, just
like most other uses of scripting.  You're doing a text-only service
so you shouldn't even depend on graphics being available in the
browser (your system is IMO defective it doesn't work properly with
Lynx).

> just to add some dynamism to the interface - use XMLhttprequests, a
> bit of DOM scripting etc.

That's sort of vague.  A concrete good reason means a specific set of
benefits you can provide to the user with scripting that you can't
provide without scripting.

See also: http://www.anybrowser.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __call__

2005-05-28 Thread TK
tiissa wrote:
> TK wrote:
> 
>> Sorry but it does not work.
> 
> 
> It _does_ work. It just don't do what you expect.

Seems so;-).

Thanks a lot for help!!!

o-o

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


Re: Comparing 2 similar strings?

2005-05-28 Thread Rob W. W. Hooft
After reading this thread, I have wrapped up a different approach, 
probably not what you were looking for, but it is very good for what I 
wanted: comparing a command string typed by a user with all possible 
commands a program can accept, to be able to do typo-correction. The 
method will return a floating point number between 0.0 (no match) and 
len(s)+1.0 (if the strings are exactly equal). You can see the score as 
"the number of equal letters".

I put the module at http://starship.python.net/crew/hooft/
It is called comparestrings.py.

It is a comparison algorithm as implemented by Reinhard Schneider and 
Chris Sander for comparison of protein sequences, but implemented to 
compare two ASCII strings.

The comparison makes use of a similarity matrix for letters: in the 
protein case this is normally a chemical functionality similarity, for 
our case this is a matrix based on keys next to each other on a US 
Qwerty keyboard and on "capital letters are similar to their lowercase 
equivalent"

The algorithm does not cut corners: it is sure to find the absolute best 
match between the two strings.

No attempt has been made to make this efficient in time or memory. Time 
taken and memory used is proportional to the product of the lengths of 
the input strings. Use for strings longer than 25 characters is entirely 
for your own risk.

Regards,

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


scipy for python 2.4

2005-05-28 Thread querypk
Did anyone try to install Scipy package on python2.4 linux version. I
see only python2.3 version of scipy released. When I try to install I
get an dependency warning saying scipy cannot find python2.3.

Can someone point me to python2.4 version of scipy and help me install.

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


Re: Getting value of radiobutton trouble

2005-05-28 Thread Philippe C. Martin
Hi, 

I think your second call to Tk() does it: this works although the look is
different:


from Tkinter import *
class GetVariant:
 def __init__(self):
 self.root = Tk()
 self.mainframe = Frame(self.root,bg="yellow")
 self.mainframe.pack(fill=BOTH,expand=1)

 self.firstframe = Frame(self.mainframe,bg="red")
 self.firstframe.pack(side=BOTTOM,expand=1)

 global v
 v = StringVar()
 self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
1", variable=v, value="Variant 1")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton.select()
 self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
2", variable=v, value="Variant 2")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
3", variable=v, value="Variant 3")
 self.radiobutton.pack(side=TOP,anchor=W)



 self.secondframe = Frame(self.mainframe,bg="blue")
 self.secondframe.pack()
 self.var = Button(self.secondframe,text="What 
Variant",command=self.call)
 self.var.pack(expand=1,side=BOTTOM)



 def call(self):
 self.variant = v.get()
 print 'Input => "%s"' % self.variant

class OneButton:
 def __init__(self):
 self.root = Tk()
 Button(self.root,text="click me",command=self.getvar).pack()
 def getvar(self):
 a=GetVariant()

d = OneButton()
d.root.mainloop()




VK wrote:

> Hi!
> What I'm missing in following code? Cannot get the values of
> radiobuttons. Starting only one class (GetVariant), it works. When I put
> two classes together, it doesn't.
> Regards, VK
> 
> from Tkinter import *
> class GetVariant:
>  def __init__(self):
>  self.root = Tk()
>  self.mainframe = Frame(self.root,bg="yellow")
>  self.mainframe.pack(fill=BOTH,expand=1)
> 
>  self.firstframe = Frame(self.mainframe,bg="red")
>  self.firstframe.pack(side=BOTTOM,expand=1)
> 
>  global v
>  v = StringVar()
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
> 1", variable=v, value="Variant 1")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton.select()
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
> 2", variable=v, value="Variant 2")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
> 3", variable=v, value="Variant 3")
>  self.radiobutton.pack(side=TOP,anchor=W)
> 
> 
> 
>  self.secondframe = Frame(self.mainframe,bg="blue")
>  self.secondframe.pack()
>  self.var = Button(self.secondframe,text="What
> Variant",command=self.call)
>  self.var.pack(expand=1,side=BOTTOM)
> 
> 
> 
>  def call(self):
>  self.variant = v.get()
>  print 'Input => "%s"' % self.variant
> 
> class OneButton:
>  def __init__(self):
>  self.root = Tk()
>  Button(self.root,text="click me",command=self.getvar).pack()
>  def getvar(self):
>  a=GetVariant()
> 
> d = OneButton()
> d.root.mainloop()

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


Re: Getting value of radiobutton trouble

2005-05-28 Thread Philippe C. Martin
Sorry,

I still had your code in my clipboard :-) here goes:



from Tkinter import *
class GetVariant(Frame):
 def __init__(self,p):
 self.root = p
 self.mainframe = Frame(self.root,bg="yellow")
 self.mainframe.pack(fill=BOTH,expand=1)

 self.firstframe = Frame(self.mainframe,bg="red")
 self.firstframe.pack(side=BOTTOM,expand=1)


 self.v = StringVar()
 self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
variable=self.v, value="Variant 1")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton.select()
 self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
variable=self.v, value="Variant 2")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
variable=self.v, value="Variant 3")
 self.radiobutton.pack(side=TOP,anchor=W)



 self.secondframe = Frame(self.mainframe,bg="blue")
 self.secondframe.pack()
 self.var = Button(self.secondframe,text="What
Variant",command=self.call)
 self.var.pack(expand=1,side=BOTTOM)



 def call(self):
 print dir(self.v)
 self.variant = self.v.get()
 print 'Input => "%s"' % self.variant

class OneButton(Frame):
 def __init__(self):
 self.root = Tk()
 Button(self.root,text="click me",command=self.getvar).pack()
 def getvar(self):
 print 'HRE'
 a=GetVariant(self.root)

d = OneButton()
d.root.mainloop()






Philippe C. Martin wrote:

> Hi,
> 
> I think your second call to Tk() does it: this works although the look is
> different:
> 
> 
> from Tkinter import *
> class GetVariant:
>  def __init__(self):
>  self.root = Tk()
>  self.mainframe = Frame(self.root,bg="yellow")
>  self.mainframe.pack(fill=BOTH,expand=1)
> 
>  self.firstframe = Frame(self.mainframe,bg="red")
>  self.firstframe.pack(side=BOTTOM,expand=1)
> 
>  global v
>  v = StringVar()
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
> 1", variable=v, value="Variant 1")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton.select()
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
> 2", variable=v, value="Variant 2")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
> 3", variable=v, value="Variant 3")
>  self.radiobutton.pack(side=TOP,anchor=W)
> 
> 
> 
>  self.secondframe = Frame(self.mainframe,bg="blue")
>  self.secondframe.pack()
>  self.var = Button(self.secondframe,text="What
> Variant",command=self.call)
>  self.var.pack(expand=1,side=BOTTOM)
> 
> 
> 
>  def call(self):
>  self.variant = v.get()
>  print 'Input => "%s"' % self.variant
> 
> class OneButton:
>  def __init__(self):
>  self.root = Tk()
>  Button(self.root,text="click me",command=self.getvar).pack()
>  def getvar(self):
>  a=GetVariant()
> 
> d = OneButton()
> d.root.mainloop()
> 
> 
> 
> 
> VK wrote:
> 
>> Hi!
>> What I'm missing in following code? Cannot get the values of
>> radiobuttons. Starting only one class (GetVariant), it works. When I put
>> two classes together, it doesn't.
>> Regards, VK
>> 
>> from Tkinter import *
>> class GetVariant:
>>  def __init__(self):
>>  self.root = Tk()
>>  self.mainframe = Frame(self.root,bg="yellow")
>>  self.mainframe.pack(fill=BOTH,expand=1)
>> 
>>  self.firstframe = Frame(self.mainframe,bg="red")
>>  self.firstframe.pack(side=BOTTOM,expand=1)
>> 
>>  global v
>>  v = StringVar()
>>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>> 1", variable=v, value="Variant 1")
>>  self.radiobutton.pack(side=TOP,anchor=W)
>>  self.radiobutton.select()
>>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>> 2", variable=v, value="Variant 2")
>>  self.radiobutton.pack(side=TOP,anchor=W)
>>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>> 3", variable=v, value="Variant 3")
>>  self.radiobutton.pack(side=TOP,anchor=W)
>> 
>> 
>> 
>>  self.secondframe = Frame(self.mainframe,bg="blue")
>>  self.secondframe.pack()
>>  self.var = Button(self.secondframe,text="What
>> Variant",command=self.call)
>>  self.var.pack(expand=1,side=BOTTOM)
>> 
>> 
>> 
>>  def call(self):
>>  self.variant = v.get()
>>  print 'Input => "%s"' % self.variant
>> 
>> class OneButton:
>>  def __init__(self):
>>  self.root = Tk()
>>  Button(self.root,text="click me",command=self.getvar).pack()
>>  def getvar(self):
>>  a=GetVariant()
>> 
>> d = OneButton()
>> d.root.mainloop()

Re: Help with choice of suitable Architecture

2005-05-28 Thread Kent Johnson
Rob Cowie wrote:
> I agree with the sentiments that a single XML file is not the way to go
> for storing data that may be accessed concurrently. However, my hands
> are tied.

You might like to see the thread "write to the same file from multiple 
processes at the same time?" 
for a preview of the issues this raises.
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/475d065fa7871e63/c2fc42fefe114d38?hl=en#c2fc42fefe114d38

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


Re: Getting value of radiobutton trouble

2005-05-28 Thread VK
Philippe C. Martin wrote:
> Hi, 
> 
> I think your second call to Tk() does it: this works although the look is
> different:
> 
> 
> from Tkinter import *
> class GetVariant:
>  def __init__(self):
>  self.root = Tk()
>  self.mainframe = Frame(self.root,bg="yellow")
>  self.mainframe.pack(fill=BOTH,expand=1)
> 
>  self.firstframe = Frame(self.mainframe,bg="red")
>  self.firstframe.pack(side=BOTTOM,expand=1)
> 
>  global v
>  v = StringVar()
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
> 1", variable=v, value="Variant 1")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton.select()
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
> 2", variable=v, value="Variant 2")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
> 3", variable=v, value="Variant 3")
>  self.radiobutton.pack(side=TOP,anchor=W)
> 
> 
> 
>  self.secondframe = Frame(self.mainframe,bg="blue")
>  self.secondframe.pack()
>  self.var = Button(self.secondframe,text="What 
> Variant",command=self.call)
>  self.var.pack(expand=1,side=BOTTOM)
> 
> 
> 
>  def call(self):
>  self.variant = v.get()
>  print 'Input => "%s"' % self.variant
> 
> class OneButton:
>  def __init__(self):
>  self.root = Tk()
>  Button(self.root,text="click me",command=self.getvar).pack()
>  def getvar(self):
>  a=GetVariant()
> 
> d = OneButton()
> d.root.mainloop()
> 
> 
> 
> 
> VK wrote:
> 
> 
>>Hi!
>>What I'm missing in following code? Cannot get the values of
>>radiobuttons. Starting only one class (GetVariant), it works. When I put
>>two classes together, it doesn't.
>>Regards, VK
>>
>>from Tkinter import *
>>class GetVariant:
>> def __init__(self):
>> self.root = Tk()
>> self.mainframe = Frame(self.root,bg="yellow")
>> self.mainframe.pack(fill=BOTH,expand=1)
>>
>> self.firstframe = Frame(self.mainframe,bg="red")
>> self.firstframe.pack(side=BOTTOM,expand=1)
>>
>> global v
>> v = StringVar()
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>1", variable=v, value="Variant 1")
>> self.radiobutton.pack(side=TOP,anchor=W)
>> self.radiobutton.select()
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>2", variable=v, value="Variant 2")
>> self.radiobutton.pack(side=TOP,anchor=W)
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>3", variable=v, value="Variant 3")
>> self.radiobutton.pack(side=TOP,anchor=W)
>>
>>
>>
>> self.secondframe = Frame(self.mainframe,bg="blue")
>> self.secondframe.pack()
>> self.var = Button(self.secondframe,text="What
>>Variant",command=self.call)
>> self.var.pack(expand=1,side=BOTTOM)
>>
>>
>>
>> def call(self):
>> self.variant = v.get()
>> print 'Input => "%s"' % self.variant
>>
>>class OneButton:
>> def __init__(self):
>> self.root = Tk()
>> Button(self.root,text="click me",command=self.getvar).pack()
>> def getvar(self):
>> a=GetVariant()
>>
>>d = OneButton()
>>d.root.mainloop()
> 
> 

Sorry, but I don't get it. There is no deference between my code and 
your answer. I'm beginner...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting value of radiobutton trouble

2005-05-28 Thread Philippe C. Martin
PS: Since your starting with TKinter, and although I do not know what your
goal is, I suggest you take a look at wxPython: it is _wonderfull_ ! (no
offence to TCL/TK)

Regards,

Philippe






VK wrote:

> Philippe C. Martin wrote:
>> Hi,
>> 
>> I think your second call to Tk() does it: this works although the look is
>> different:
>> 
>> 
>> from Tkinter import *
>> class GetVariant:
>>  def __init__(self):
>>  self.root = Tk()
>>  self.mainframe = Frame(self.root,bg="yellow")
>>  self.mainframe.pack(fill=BOTH,expand=1)
>> 
>>  self.firstframe = Frame(self.mainframe,bg="red")
>>  self.firstframe.pack(side=BOTTOM,expand=1)
>> 
>>  global v
>>  v = StringVar()
>>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>> 1", variable=v, value="Variant 1")
>>  self.radiobutton.pack(side=TOP,anchor=W)
>>  self.radiobutton.select()
>>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>> 2", variable=v, value="Variant 2")
>>  self.radiobutton.pack(side=TOP,anchor=W)
>>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>> 3", variable=v, value="Variant 3")
>>  self.radiobutton.pack(side=TOP,anchor=W)
>> 
>> 
>> 
>>  self.secondframe = Frame(self.mainframe,bg="blue")
>>  self.secondframe.pack()
>>  self.var = Button(self.secondframe,text="What
>> Variant",command=self.call)
>>  self.var.pack(expand=1,side=BOTTOM)
>> 
>> 
>> 
>>  def call(self):
>>  self.variant = v.get()
>>  print 'Input => "%s"' % self.variant
>> 
>> class OneButton:
>>  def __init__(self):
>>  self.root = Tk()
>>  Button(self.root,text="click me",command=self.getvar).pack()
>>  def getvar(self):
>>  a=GetVariant()
>> 
>> d = OneButton()
>> d.root.mainloop()
>> 
>> 
>> 
>> 
>> VK wrote:
>> 
>> 
>>>Hi!
>>>What I'm missing in following code? Cannot get the values of
>>>radiobuttons. Starting only one class (GetVariant), it works. When I put
>>>two classes together, it doesn't.
>>>Regards, VK
>>>
>>>from Tkinter import *
>>>class GetVariant:
>>> def __init__(self):
>>> self.root = Tk()
>>> self.mainframe = Frame(self.root,bg="yellow")
>>> self.mainframe.pack(fill=BOTH,expand=1)
>>>
>>> self.firstframe = Frame(self.mainframe,bg="red")
>>> self.firstframe.pack(side=BOTTOM,expand=1)
>>>
>>> global v
>>> v = StringVar()
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>1", variable=v, value="Variant 1")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton.select()
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>2", variable=v, value="Variant 2")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>3", variable=v, value="Variant 3")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>>
>>>
>>>
>>> self.secondframe = Frame(self.mainframe,bg="blue")
>>> self.secondframe.pack()
>>> self.var = Button(self.secondframe,text="What
>>>Variant",command=self.call)
>>> self.var.pack(expand=1,side=BOTTOM)
>>>
>>>
>>>
>>> def call(self):
>>> self.variant = v.get()
>>> print 'Input => "%s"' % self.variant
>>>
>>>class OneButton:
>>> def __init__(self):
>>> self.root = Tk()
>>> Button(self.root,text="click me",command=self.getvar).pack()
>>> def getvar(self):
>>> a=GetVariant()
>>>
>>>d = OneButton()
>>>d.root.mainloop()
>> 
>> 
> 
> Sorry, but I don't get it. There is no deference between my code and
> your answer. I'm beginner...

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


Re: scipy for python 2.4

2005-05-28 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> Did anyone try to install Scipy package on python2.4 linux version. I
> see only python2.3 version of scipy released. When I try to install I
> get an dependency warning saying scipy cannot find python2.3.
> 
> Can someone point me to python2.4 version of scipy and help me install.

scipy.org has not yet released binaries for Python 2.4. It will compile 
from source just fine, though. Someone may have also released binary 
packages for your particular platform, but since you don't mention which 
one that is, we can't help you with that, yet.

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


Re: scipy for python 2.4

2005-05-28 Thread Philippe C. Martin
In order to help, I just tried to compile it, and it seems to have a bunch
of dependencies to worry about: 


[EMAIL PROTECTED] SciPy_complete-0.3.2]# python setup.py install
fftw_info:
  NOT AVAILABLE

dfftw_info:
  NOT AVAILABLE


FFTW (http://www.fftw.org/) libraries not found.
Directories to search for the libraries can be specified in the
scipy_distutils/site.cfg file (section [fftw]) or by setting
the FFTW environment variable.
djbfft_info:
  NOT AVAILABLE


DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.
Directories to search for the libraries can be specified in the
scipy_distutils/site.cfg file (section [djbfft]) or by setting
the DJBFFT environment variable.
blas_opt_info:
atlas_blas_threads_info:
scipy_distutils.system_info.atlas_blas_threads_info
  NOT AVAILABLE

atlas_blas_info:
scipy_distutils.system_info.atlas_blas_info
  NOT AVAILABLE

scipy_core/scipy_distutils/system_info.py:982: UserWarning:
Atlas (http://math-atlas.sourceforge.net/) libraries not found.
Directories to search for the libraries can be specified in the
scipy_distutils/site.cfg file (section [atlas]) or by setting
the ATLAS environment variable.
  warnings.warn(AtlasNotFoundError.__doc__)
blas_info:
  NOT AVAILABLE

scipy_core/scipy_distutils/system_info.py:991: UserWarning:
Blas (http://www.netlib.org/blas/) libraries not found.
Directories to search for the libraries can be specified in the
scipy_distutils/site.cfg file (section [blas]) or by setting
the BLAS environment variable.
  warnings.warn(BlasNotFoundError.__doc__)
blas_src_info:
  NOT AVAILABLE

scipy_core/scipy_distutils/system_info.py:994: UserWarning:
Blas (http://www.netlib.org/blas/) sources not found.
Directories to search for the sources can be specified in the
scipy_distutils/site.cfg file (section [blas_src]) or by setting
the BLAS_SRC environment variable.
  warnings.warn(BlasSrcNotFoundError.__doc__)
  NOT AVAILABLE

Traceback (most recent call last):
  File "setup.py", line 111, in ?
setup_package(ignore_packages)
  File "setup.py", line 85, in setup_package
ignore_packages = ignore_packages)
  File "scipy_core/scipy_distutils/misc_util.py", line 475, in
get_subpackages
config = setup_module.configuration(*args)
  File
"/home/philippe/downloaded/SciPy_complete-0.3.2/Lib/integrate/setup_integrate.py",
line 22, in configuration
raise NotFoundError,'no blas resources found'
scipy_distutils.system_info.NotFoundError: no blas resources found


Robert Kern wrote:

> [EMAIL PROTECTED] wrote:
>> Did anyone try to install Scipy package on python2.4 linux version. I
>> see only python2.3 version of scipy released. When I try to install I
>> get an dependency warning saying scipy cannot find python2.3.
>> 
>> Can someone point me to python2.4 version of scipy and help me install.
> 
> scipy.org has not yet released binaries for Python 2.4. It will compile
> from source just fine, though. Someone may have also released binary
> packages for your particular platform, but since you don't mention which
> one that is, we can't help you with that, yet.
> 

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


String manipulations

2005-05-28 Thread Lorn
I'm trying to work on a dataset that has it's primary numbers saved as
floats in string format. I'd like to work with them as integers with an
implied decimal to the hundredth. The problem is that the current
precision is variable. For instance, some numbers have 4 decimal places
while others have 2, etc. (10.7435 vs 1074.35)... all numbers are of
fixed length.

I have some ideas of how to do this, but I'm wondering if there's a
better way. My current way is to brute force search where the decimal
is by slicing and then cutoff the extraneous numbers, however, it would
be nice to stay away from a bunch of if then's.

Does anyone have any ideas on how to do this more efficiently?

Many Thanks,
Lorn

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


Re: Getting value of radiobutton trouble

2005-05-28 Thread VK
Philippe C. Martin wrote:
> Sorry,
> 
> I still had your code in my clipboard :-) here goes:

So, your code works, but I need, that first window calls another 
separate window. In your programm they stick together.
Reg, VK

> 
> 
> 
> from Tkinter import *
> class GetVariant(Frame):
>  def __init__(self,p):
>  self.root = p
>  self.mainframe = Frame(self.root,bg="yellow")
>  self.mainframe.pack(fill=BOTH,expand=1)
> 
>  self.firstframe = Frame(self.mainframe,bg="red")
>  self.firstframe.pack(side=BOTTOM,expand=1)
> 
> 
>  self.v = StringVar()
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
> variable=self.v, value="Variant 1")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton.select()
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
> variable=self.v, value="Variant 2")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
> variable=self.v, value="Variant 3")
>  self.radiobutton.pack(side=TOP,anchor=W)
> 
> 
> 
>  self.secondframe = Frame(self.mainframe,bg="blue")
>  self.secondframe.pack()
>  self.var = Button(self.secondframe,text="What
> Variant",command=self.call)
>  self.var.pack(expand=1,side=BOTTOM)
> 
> 
> 
>  def call(self):
>  print dir(self.v)
>  self.variant = self.v.get()
>  print 'Input => "%s"' % self.variant
> 
> class OneButton(Frame):
>  def __init__(self):
>  self.root = Tk()
>  Button(self.root,text="click me",command=self.getvar).pack()
>  def getvar(self):
>  print 'HRE'
>  a=GetVariant(self.root)
> 
> d = OneButton()
> d.root.mainloop()
> 
> 
> 
> 
> 
> 
> Philippe C. Martin wrote:
> 
> 
>>Hi,
>>
>>I think your second call to Tk() does it: this works although the look is
>>different:
>>
>>
>>from Tkinter import *
>>class GetVariant:
>> def __init__(self):
>> self.root = Tk()
>> self.mainframe = Frame(self.root,bg="yellow")
>> self.mainframe.pack(fill=BOTH,expand=1)
>>
>> self.firstframe = Frame(self.mainframe,bg="red")
>> self.firstframe.pack(side=BOTTOM,expand=1)
>>
>> global v
>> v = StringVar()
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>1", variable=v, value="Variant 1")
>> self.radiobutton.pack(side=TOP,anchor=W)
>> self.radiobutton.select()
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>2", variable=v, value="Variant 2")
>> self.radiobutton.pack(side=TOP,anchor=W)
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>3", variable=v, value="Variant 3")
>> self.radiobutton.pack(side=TOP,anchor=W)
>>
>>
>>
>> self.secondframe = Frame(self.mainframe,bg="blue")
>> self.secondframe.pack()
>> self.var = Button(self.secondframe,text="What
>>Variant",command=self.call)
>> self.var.pack(expand=1,side=BOTTOM)
>>
>>
>>
>> def call(self):
>> self.variant = v.get()
>> print 'Input => "%s"' % self.variant
>>
>>class OneButton:
>> def __init__(self):
>> self.root = Tk()
>> Button(self.root,text="click me",command=self.getvar).pack()
>> def getvar(self):
>> a=GetVariant()
>>
>>d = OneButton()
>>d.root.mainloop()
>>
>>
>>
>>
>>VK wrote:
>>
>>
>>>Hi!
>>>What I'm missing in following code? Cannot get the values of
>>>radiobuttons. Starting only one class (GetVariant), it works. When I put
>>>two classes together, it doesn't.
>>>Regards, VK
>>>
>>>from Tkinter import *
>>>class GetVariant:
>>> def __init__(self):
>>> self.root = Tk()
>>> self.mainframe = Frame(self.root,bg="yellow")
>>> self.mainframe.pack(fill=BOTH,expand=1)
>>>
>>> self.firstframe = Frame(self.mainframe,bg="red")
>>> self.firstframe.pack(side=BOTTOM,expand=1)
>>>
>>> global v
>>> v = StringVar()
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>1", variable=v, value="Variant 1")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton.select()
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>2", variable=v, value="Variant 2")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>3", variable=v, value="Variant 3")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>>
>>>
>>>
>>> self.secondframe = Frame(self.mainframe,bg="blue")
>>> self.secondframe.pack()
>>> self.var = Button(self.secondframe,text="What
>>>Variant",command=self.call)
>>> self.var.pack(expand=1,side=BOTTOM)
>>>
>>>
>>>
>>> def call(self):
>>> self.variant = v.get()
>>> print 'Input => "%s"

Re: String manipulations

2005-05-28 Thread Philippe C. Martin
Multiply them by 1 ?

Lorn wrote:

> I'm trying to work on a dataset that has it's primary numbers saved as
> floats in string format. I'd like to work with them as integers with an
> implied decimal to the hundredth. The problem is that the current
> precision is variable. For instance, some numbers have 4 decimal places
> while others have 2, etc. (10.7435 vs 1074.35)... all numbers are of
> fixed length.
> 
> I have some ideas of how to do this, but I'm wondering if there's a
> better way. My current way is to brute force search where the decimal
> is by slicing and then cutoff the extraneous numbers, however, it would
> be nice to stay away from a bunch of if then's.
> 
> Does anyone have any ideas on how to do this more efficiently?
> 
> Many Thanks,
> Lorn

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


Re: Comparing 2 similar strings?

2005-05-28 Thread Irmen de Jong
Rob W. W. Hooft wrote:
> After reading this thread, I have wrapped up a different approach, 
> probably not what you were looking for, but it is very good for what I 
> wanted: comparing a command string typed by a user with all possible 
> commands a program can accept, to be able to do typo-correction. The 
> method will return a floating point number between 0.0 (no match) and 
> len(s)+1.0 (if the strings are exactly equal). You can see the score as 
> "the number of equal letters".
[...]
Interesting, but the result is a bit puzzling.
Wouldn't it be easier if it is normalized to a float between 0.0 and 1.0?

Furthermore, I can also produce wrong(?) results:

$ python comparestrings.py
s1: test
s2: x
Score: -0.4

Minus 0.4... Is this a bug?

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


Re: String manipulations

2005-05-28 Thread Lorn
Yes, that would get rid of the decimals... but it wouldn't get rid of
the extraneous precision. Unfortunately, the precision out to the ten
thousandth is noise... I don't need to round it either as the numbers
are artifacts of an integer to float conversion. Basically, I need to
know how many decimal places there are and then make the necessary
deletions before I can normalize by adding zeros, multiplying, etc.

Thanks for your suggestion, though.

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


Re: scipy for python 2.4

2005-05-28 Thread querypk
I tried to compile it from source. But it dint work.It was looking for
python2.3 .But I want to install it on pyrthon 2.4
PLatform you mean I am using RedHat 9.0. is that what you were
referring?
can you point me to the source you are referring. I used the sourse
from this link...

http://www.scipy.org/download/

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


Re: String manipulations

2005-05-28 Thread John Roth
"Lorn" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> I'm trying to work on a dataset that has its primary numbers saved as
> floats in string format. I'd like to work with them as integers with an
> implied decimal to the hundredth. The problem is that the current
> precision is variable. For instance, some numbers have 4 decimal places
> while others have 2, etc. (10.7435 vs 1074.35)... all numbers are of
> fixed length.

> I have some ideas of how to do this, but I'm wondering if there's a
> better way. My current way is to brute force search where the decimal
> is by slicing and then cutoff the extraneous numbers, however, it would
> be nice to stay away from a bunch of if then's.
>
> Does anyone have any ideas on how to do this more efficiently?

If you can live with a small possibility of error, then:

int(float(numIn) * 100.0)

should do the trick.

If you can't, and the numbers are guaranteed to have a decimal point,
this (untested) could do what you want:

aList = numIn.split(".")
result int(aList[0]) * 100 + int(aList[1][:2])

HTH

John Roth
>
> Many Thanks,
> Lorn
> 

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


Re: String manipulations

2005-05-28 Thread Elliot Temple

On May 28, 2005, at 2:52 PM, Lorn wrote:

> Yes, that would get rid of the decimals... but it wouldn't get rid of
> the extraneous precision. Unfortunately, the precision out to the ten
> thousandth is noise... I don't need to round it either as the numbers
> are artifacts of an integer to float conversion. Basically, I need to
> know how many decimal places there are and then make the necessary
> deletions before I can normalize by adding zeros, multiplying, etc.
>
> Thanks for your suggestion, though.

for s in numbers:
 decimal_index = s.find('.')
 decimal_places = len(s) - decimal_index - 1

Anything wrong with this?  (it will mess up if there isn't a decimal  
but you can fix that if you want)

-- Elliot Temple
http://www.curi.us/


---
[This E-mail scanned for viruses by Declude Virus]

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


Re: Getting value of radiobutton trouble

2005-05-28 Thread Philippe C. Martin
Then I guess you need a TopLevel widget instead:


(I still suggest you look at wxPython)


from Tkinter import *
class GetVariant:
 def __init__(self,p):
 self.root = p

 self.firstframe = Frame(self.root,bg="red")
 self.firstframe.pack(side=BOTTOM,expand=1)


 self.v = StringVar()
 self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
variable=self.v, value="Variant 1")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton.select()
 self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
variable=self.v, value="Variant 2")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
variable=self.v, value="Variant 3")
 self.radiobutton.pack(side=TOP,anchor=W)



 self.secondframe = Frame(self.root,bg="blue")
 self.secondframe.pack()
 self.var = Button(self.secondframe,text="What
Variant",command=self.call)
 self.var.pack(expand=1,side=BOTTOM)



 def call(self):
 self.variant = self.v.get()
 print 'Input => "%s"' % self.variant

class OneButton:
 def __init__(self):
 self.root = Tk()
 Button(self.root,text="click me",command=self.getvar).pack()
 def getvar(self):
 self.mainframe = Toplevel(bg="yellow")
 a=GetVariant(self.mainframe)

d = OneButton()
d.root.mainloop()

VK wrote:

> Philippe C. Martin wrote:
>> Sorry,
>> 
>> I still had your code in my clipboard :-) here goes:
> 
> So, your code works, but I need, that first window calls another
> separate window. In your programm they stick together.
> Reg, VK
> 
>> 
>> 
>> 
>> from Tkinter import *
>> class GetVariant(Frame):
>>  def __init__(self,p):
>>  self.root = p
>>  self.mainframe = Frame(self.root,bg="yellow")
>>  self.mainframe.pack(fill=BOTH,expand=1)
>> 
>>  self.firstframe = Frame(self.mainframe,bg="red")
>>  self.firstframe.pack(side=BOTTOM,expand=1)
>> 
>> 
>>  self.v = StringVar()
>>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
>> variable=self.v, value="Variant 1")
>>  self.radiobutton.pack(side=TOP,anchor=W)
>>  self.radiobutton.select()
>>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
>> variable=self.v, value="Variant 2")
>>  self.radiobutton.pack(side=TOP,anchor=W)
>>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
>> variable=self.v, value="Variant 3")
>>  self.radiobutton.pack(side=TOP,anchor=W)
>> 
>> 
>> 
>>  self.secondframe = Frame(self.mainframe,bg="blue")
>>  self.secondframe.pack()
>>  self.var = Button(self.secondframe,text="What
>> Variant",command=self.call)
>>  self.var.pack(expand=1,side=BOTTOM)
>> 
>> 
>> 
>>  def call(self):
>>  print dir(self.v)
>>  self.variant = self.v.get()
>>  print 'Input => "%s"' % self.variant
>> 
>> class OneButton(Frame):
>>  def __init__(self):
>>  self.root = Tk()
>>  Button(self.root,text="click me",command=self.getvar).pack()
>>  def getvar(self):
>>  print 'HRE'
>>  a=GetVariant(self.root)
>> 
>> d = OneButton()
>> d.root.mainloop()
>> 
>> 
>> 
>> 
>> 
>> 
>> Philippe C. Martin wrote:
>> 
>> 
>>>Hi,
>>>
>>>I think your second call to Tk() does it: this works although the look is
>>>different:
>>>
>>>
>>>from Tkinter import *
>>>class GetVariant:
>>> def __init__(self):
>>> self.root = Tk()
>>> self.mainframe = Frame(self.root,bg="yellow")
>>> self.mainframe.pack(fill=BOTH,expand=1)
>>>
>>> self.firstframe = Frame(self.mainframe,bg="red")
>>> self.firstframe.pack(side=BOTTOM,expand=1)
>>>
>>> global v
>>> v = StringVar()
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>1", variable=v, value="Variant 1")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton.select()
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>2", variable=v, value="Variant 2")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>3", variable=v, value="Variant 3")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>>
>>>
>>>
>>> self.secondframe = Frame(self.mainframe,bg="blue")
>>> self.secondframe.pack()
>>> self.var = Button(self.secondframe,text="What
>>>Variant",command=self.call)
>>> self.var.pack(expand=1,side=BOTTOM)
>>>
>>>
>>>
>>> def call(self):
>>> self.variant = v.get()
>>> print 'Input => "%s"' % self.variant
>>>
>>>class OneButton:
>>> def __init__(self):
>>> self.root = Tk()
>>> Button(self.root,text="click me",command=self.getvar).pack()
>>

Re: UTF16 codec doesn't round-trip?

2005-05-28 Thread "Martin v. Löwis"
John Perks and Sarah Mount wrote:
> If the ascii can't be recognized as UTF16, then surely the codec
> shouldn't have allowed it to be encoded in the first place? I could
> understand if it was trying to decode ascii into (native) UTF32.

Please don't call the thing you are trying to decode "ascii". ASCII
is the name of the American Standard Code for Information Interchange;
it is a 7-bit code, and what you are trying to decode certainly isn't
ascii. Call it "bytes" instead.

So you are trying to decode bytes as UTF-16. The bytes you have
definitely are not UTF-16 - the specific sequence of bytes is invalid
in UTF-16. Therefore, the codec is right to reject it when decoding.

It might be considered as a bug that the codec encoded the characters
in the first place.

> On a similar note, if you are using UTF32 natively, are you allowed to
> have raw surrogate escape sequences (paired or otherwise) in unicode
> literals?

Python accepts such literals.

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


Re: Copy paste in entry widget

2005-05-28 Thread Skip Montanaro

Michael> is copy, paste, cut of selection possible in entry widget? Docs
Michael> say selection must be copied by default, in my programm it
Michael> doesn't work.

What platform?  What GUI toolkit?

-- 
Skip Montanaro
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copy paste in entry widget

2005-05-28 Thread VK
Skip Montanaro wrote:
> Michael> is copy, paste, cut of selection possible in entry widget? Docs
> Michael> say selection must be copied by default, in my programm it
> Michael> doesn't work.
> 
> What platform?  What GUI toolkit?
> 

Linux, Windows. TkInter, Pmw.
I've already implemented this with code under my message, but "cut"
copies entrytext, without deleting selection. Any ideas

def copy(self):
 global copied
 if self.entry.selection_present():
self.entry.clipboard_clear()
copied = self.entry.selection_get()
 self.entry.bell()
 def paste(self):
 self.entry.insert(END, copied)
 def cut(self):
 global copied
 self.entry.clipboard_clear()
 if self.entry.selection_present():
 copied = self.entry.selection_get()
 self.entry.selection_clear()
 self.entry.bell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting value of radiobutton trouble

2005-05-28 Thread VK
Philippe C. Martin wrote:
> Then I guess you need a TopLevel widget instead:
> 
> 
> (I still suggest you look at wxPython)
> 
> 
> from Tkinter import *
> class GetVariant:
>  def __init__(self,p):
>  self.root = p
> 
>  self.firstframe = Frame(self.root,bg="red")
>  self.firstframe.pack(side=BOTTOM,expand=1)
> 
> 
>  self.v = StringVar()
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
> variable=self.v, value="Variant 1")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton.select()
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
> variable=self.v, value="Variant 2")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
> variable=self.v, value="Variant 3")
>  self.radiobutton.pack(side=TOP,anchor=W)
> 
> 
> 
>  self.secondframe = Frame(self.root,bg="blue")
>  self.secondframe.pack()
>  self.var = Button(self.secondframe,text="What
> Variant",command=self.call)
>  self.var.pack(expand=1,side=BOTTOM)
> 
> 
> 
>  def call(self):
>  self.variant = self.v.get()
>  print 'Input => "%s"' % self.variant
> 
> class OneButton:
>  def __init__(self):
>  self.root = Tk()
>  Button(self.root,text="click me",command=self.getvar).pack()
>  def getvar(self):
>  self.mainframe = Toplevel(bg="yellow")
>  a=GetVariant(self.mainframe)
> 
> d = OneButton()
> d.root.mainloop()
> 
> VK wrote:
> 
> 
>>Philippe C. Martin wrote:
>>
>>>Sorry,
>>>
>>>I still had your code in my clipboard :-) here goes:
>>
>>So, your code works, but I need, that first window calls another
>>separate window. In your programm they stick together.
>>Reg, VK
>>
>>
>>>
>>>
>>>from Tkinter import *
>>>class GetVariant(Frame):
>>> def __init__(self,p):
>>> self.root = p
>>> self.mainframe = Frame(self.root,bg="yellow")
>>> self.mainframe.pack(fill=BOTH,expand=1)
>>>
>>> self.firstframe = Frame(self.mainframe,bg="red")
>>> self.firstframe.pack(side=BOTTOM,expand=1)
>>>
>>>
>>> self.v = StringVar()
>>> self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
>>>variable=self.v, value="Variant 1")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton.select()
>>> self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
>>>variable=self.v, value="Variant 2")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
>>>variable=self.v, value="Variant 3")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>>
>>>
>>>
>>> self.secondframe = Frame(self.mainframe,bg="blue")
>>> self.secondframe.pack()
>>> self.var = Button(self.secondframe,text="What
>>>Variant",command=self.call)
>>> self.var.pack(expand=1,side=BOTTOM)
>>>
>>>
>>>
>>> def call(self):
>>> print dir(self.v)
>>> self.variant = self.v.get()
>>> print 'Input => "%s"' % self.variant
>>>
>>>class OneButton(Frame):
>>> def __init__(self):
>>> self.root = Tk()
>>> Button(self.root,text="click me",command=self.getvar).pack()
>>> def getvar(self):
>>> print 'HRE'
>>> a=GetVariant(self.root)
>>>
>>>d = OneButton()
>>>d.root.mainloop()
>>>
>>>
>>>
>>>
>>>
>>>
>>>Philippe C. Martin wrote:
>>>
>>>
>>>
Hi,

I think your second call to Tk() does it: this works although the look is
different:


>>>
from Tkinter import *
>>>
class GetVariant:
def __init__(self):
self.root = Tk()
self.mainframe = Frame(self.root,bg="yellow")
self.mainframe.pack(fill=BOTH,expand=1)

self.firstframe = Frame(self.mainframe,bg="red")
self.firstframe.pack(side=BOTTOM,expand=1)

global v
v = StringVar()
self.radiobutton = Radiobutton(self.firstframe,text= "Variant
1", variable=v, value="Variant 1")
self.radiobutton.pack(side=TOP,anchor=W)
self.radiobutton.select()
self.radiobutton = Radiobutton(self.firstframe,text= "Variant
2", variable=v, value="Variant 2")
self.radiobutton.pack(side=TOP,anchor=W)
self.radiobutton = Radiobutton(self.firstframe,text= "Variant
3", variable=v, value="Variant 3")
self.radiobutton.pack(side=TOP,anchor=W)



self.secondframe = Frame(self.mainframe,bg="blue")
self.secondframe.pack()
self.var = Button(self.secondframe,text="What
Variant",command=self.call)
self.var.pack(expand=1,side=BOTTOM)



def call(self):
self.variant = v.get()
print 'Input => "%s"' % self.varia

Re: scipy for python 2.4

2005-05-28 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> I tried to compile it from source. But it dint work.It was looking for
> python2.3 .But I want to install it on pyrthon 2.4
> PLatform you mean I am using RedHat 9.0. is that what you were
> referring?
> can you point me to the source you are referring. I used the sourse
> from this link...
> 
> http://www.scipy.org/download/

Yes, that's the source I'm talking about (although CVS is better). I 
don't understand what you mean when you say that the source "was looking 
for python2.3." The source distribution certainly doesn't do that.

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


Re: scipy for python 2.4

2005-05-28 Thread Robert Kern
Philippe C. Martin wrote:
> In order to help, I just tried to compile it, and it seems to have a bunch
> of dependencies to worry about: 

Yes, that's true. Only some kind of LAPACK/BLAS (with ATLAS for 
preference) is actually necessary. Coincidentally, there are binaries 
provided if you can't find binary RPMs for your system.

http://www.scipy.org/download/atlasbinaries/linux/

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


Re: String manipulations

2005-05-28 Thread Lorn
Thank you Elliot, this solution is the one I was trying to come up
with. Thank you for your help and thank you to everyone for their
suggestions.

Best regards,
Lorn

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


Re: Software licenses and releasing Python programs for review

2005-05-28 Thread poisondart
Thanks for the replies. They have been very helpful. I'll have to read
through the licenses you've listed in more detail, but the creative
commons license of which James William Pye mentions seems to be what
I'll be using.

The reason why I need people to review my code and also the ideas
behind the code is mostly for academic interest...but not necessarily
reserved to an academic audience...which is why I don't want people to
make profit from it. It uses ideas from a language--which would be
ridiculous (to me) for anybody to make profit from selling the
mechanics of a natural language.

The NLTK mailing list seems to be what I was looking for...I'll start
checking that out. Thanks for the link.

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


Re: Is there already a Python module to access the USPTO web site?

2005-05-28 Thread Terry Carroll
On Sat, 28 May 2005 20:37:40 +0200 (CEST), Tomasz Rola
<[EMAIL PROTECTED]> wrote:

>I don't know but if you are determined to have it in Python, perhaps ypu
>should check MozPython.

Thanks.  That seems a little more than I need, but it looks
intriguing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strings for a newbie

2005-05-28 Thread James Hofmann
Malcolm Wooden  dtptypes.com> writes:

> 
> I'm trying to get my head around Python but seem to be failing miserably. I 
> use RealBasic on a Mac and find it an absolute dream! But PythonUGH!
> 
> I want to put a sentence of words into an array, eg "This is a sentence of 
> words"
> 
> In RB it would be simple:
> 
> Dim s as string
> Dim a(-1) as string
> Dim i as integer
> 
> s = "This is a sentence of words"
> For i = 1 to CountFields(s," ")
>   a.append NthField(s," ",i)
> next
> 
> That's it an array a() containing the words of the sentence.
> 
> Now can I see how this is done in Python? - nope!
> 
> UGH!
> 
> Malcolm
> (a disillusioned Python newbie) 
> 

This is the "verbose" version.

s = "This is a sentence of words"
nextword = ""
words = []
for character in s:
if character==" ":
words.append(nextword)
nextword = ""
else:
nextword+=character # string types use += instead of append
words.append(nextword) # include the last word
print words

The main sticking point for you was probably understanding the way Python lets
you loop through sequence types. In general, sequences(list, string, etc.) can
be iterated either by an explicit function call, item = sequence.next(), or more
commonly with "for item in sequence:" which will make Python go through every
item it sees inside the sequence.

This turns out to be more convenient than keeping a seperate counter in the vast
majority of cases, because it cuts straight to the business of manipulating each
item, rather than tracking where it is.

Now a "slim" version:

s = "This is a sentence of words"
print s.split()
 
But there's no learning from that one, it's just an easy library call.

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


Re: Strings for a newbie

2005-05-28 Thread Warren Block
James Hofmann <[EMAIL PROTECTED]> wrote:
> Malcolm Wooden  dtptypes.com> writes:
>> 
>> I'm trying to get my head around Python but seem to be failing miserably. I 
>> use RealBasic on a Mac and find it an absolute dream! But PythonUGH!
>> 
>> I want to put a sentence of words into an array, eg "This is a sentence of 
>> words"
>> 
>> In RB it would be simple:
>> 
>> Dim s as string
>> Dim a(-1) as string
>> Dim i as integer
>> 
>> s = "This is a sentence of words"
>> For i = 1 to CountFields(s," ")
>>   a.append NthField(s," ",i)
>> next
>> 
>> That's it an array a() containing the words of the sentence.

[snip]

> Now a "slim" version:
>
> s = "This is a sentence of words"
> print s.split()

To match the original program, it should be:

s = "This is a sentence of words"
a = s.split()

...assigning the list returned by split() to a variable called a.

-- 
Warren Block * Rapid City, South Dakota * USA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Intellisense and the psychology of typing

2005-05-28 Thread Lurker
"James D Carroll" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> if I have to type 'boolean' instead of  'boo' I get real cranky real
fast.

Why? Is your programming speed really limited by the difference
between typing "lean" and hitting ? If typing speed is
the limitation - go get some touch-typing courses.


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


Re: Comparing 2 similar strings?

2005-05-28 Thread Rob W. W. Hooft
Irmen de Jong wrote:
> Wouldn't it be easier if it is normalized to a float between 0.0 and 1.0?

Maybe. You could do that by ignoring "negative" values, and by dividing 
by min(len(s1),len(s2))+1. For my application this is irrelevant, I only 
need a scale to compare a single word to many different words, and pick 
the one that stands out. I can relate the (unnormalized) score to the 
number of typos in the word.

> Furthermore, I can also produce wrong(?) results:
> 
> $ python comparestrings.py
> s1: test
> s2: x
> Score: -0.4
> 
> Minus 0.4... Is this a bug?

Not in the procedure, it is a bug in my description. It was late at 
night when I wrote it. What you are doing here is aligning the two words 
like this:

test
--x-

the t opens a gap (score -0.3), e elongates the gap (-0.2), s and x are 
adjacent on the keyboard (score 0.4) and t opens a gap (-0.3). Total 
score is -0.4. If you compare "test" with "l" you even get a score of 
-0.7. You can make arbitrarily low numbers by comparing long strings of 
"a" characters with a single "l".

What this is telling you is that not only are the letters all different 
(score 0.0), but the strings are not even equally long (hence <0.0). The 
gap-open and gap-elongation penalties can be adjusted in the module. The 
-0.3 and -0.2 values were set after some experimentation to make the 
relative scores of different matches "feel" natural.

-- 
Rob W.W. Hooft  ||  [EMAIL PROTECTED]  ||  http://www.hooft.net/people/rob/
-- 
http://mail.python.org/mailman/listinfo/python-list


How do i read just the last line of a text file?

2005-05-28 Thread nephish
Hey there.
i want to set a variable to represent the last line of a text file
how do i do that?
or even better, how do i create a list of the lines of a text file?

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


Re: How do i read just the last line of a text file?

2005-05-28 Thread John Machin
nephish wrote:
> Hey there.
> i want to set a variable to represent the last line of a text file
> how do i do that?
> or even better, how do i create a list of the lines of a text file?
> 

Hey there to you too.

According to the manual 
http://www.python.org/doc/2.4.1/lib/bltin-file-objects.html

readlines([sizehint])
Read until EOF using readline() and return a list containing
the lines thus read.

Which part of this don't you understand?

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


Re: write to the same file from multiple processes at the same time?

2005-05-28 Thread [EMAIL PROTECTED]
Well I just tried it on Linux anyway. I opened the file in two python
processes using append mode.

I then wrote simple function to write then flush what it is passed:

def write(msg):
   foo.write("%s\n" %  msg)
   foo.flush()

I then opened another terminal and did 'tail -f myfile.txt'.

It worked just fine.

Maybe that will help. Seems simple enough to me for basic logging.

Cheers,
Bill

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


Re: How do i read just the last line of a text file?

2005-05-28 Thread Chris F.A. Johnson
On Sun, 29 May 2005 at 04:42 GMT, nephish wrote:
> Hey there.
> i want to set a variable to represent the last line of a text file
> how do i do that?
> or even better, how do i create a list of the lines of a text file?

from sys import argv  ## Import argv from sys module

file = open(argv[1])  ## Open the file given on the command line
all_lines = file.readlines()  ## Read all the lines
last_line = all_lines[-1] ## Assign the last line


-- 
Chris F.A. Johnson 
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress

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


Re: How do i read just the last line of a text file?

2005-05-28 Thread John Machin
Chris F.A. Johnson wrote:

> 
> file = open(argv[1])  ## Open the file given on the command line
> all_lines = file.readlines()  ## Read all the lines

I see your shadowing and raise you one obfuscation:

open = file(argv[1])  ## File the open given on the command line
all_lines = open.readlines()  ## Read all the lines


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


SWIG std::string& passing

2005-05-28 Thread Leonard J. Reder
Hello,

I have been trying to get this simple call to work with a SWIG 
interface.  The problem is I do not know how to pass a const char * or a 
std::string & in python to SWIG wrapped code.  I tried several of the 
*.i libraries at http://www.swig.org/Doc1.3/Library.html.  Most notably 
the "std_string.i" And get the following:

 >>> w.SetDestFilename("test.bmp")
Traceback (most recent call last):
   File "", line 1, in ?
   File 
"/home/soa/dev/users/reder/Dshell++Pkg-reder01/lib/PYTHON/Dspace/Dnoise_Py.py", 
line 1340, in SetDestFilename
 def SetDestFilename(*args): return 
_Dnoise_Py.WriterBMP_SetDestFilename(*args)
TypeError: argument number 2: a 'std::string *' is expected, 
'str(test.bmp)' is received

The C++ method is:

void WriterBMP::SetDestFilename (const std::string& filename)

This should be easy to pass the filename to?  Do you have an example? 
What do I add to the *.i file?

Thanks for any and all replies,

Len

-- 
===
Leonard J. Reder
Home office email : [EMAIL PROTECTED]
Lab email : [EMAIL PROTECTED]
Lab web page  : http://reder.jpl.nasa.gov
===


-- 
===
Leonard J. Reder
Home office email : [EMAIL PROTECTED]
Lab email : [EMAIL PROTECTED]
Lab web page  : http://reder.jpl.nasa.gov
===
-- 
http://mail.python.org/mailman/listinfo/python-list