Re: Xah Lee network abuse

2006-06-11 Thread Philippa Cowderoy
On Sat, 10 Jun 2006, Erik Max Francis wrote:

> Mike Schilling wrote:
> 
> > If I were to write, say, that Tony Blair's tax policy will lead to higher
> > deficits, I could be convicted of libel?  Even if that's true, it's not a
> > priori provable. 
> 
> I think what he was getting at is that, unlike many jurisdictions, writing
> something factually true is _not_ in and of itself a defense against a libel
> suit in the UK.
> 

It is. However, the onus is on the defendant to show that it's true, 
rather than on the claimant to show that it's false. I assume the "he" 
refers to Brandon?

-- 
[EMAIL PROTECTED]

A problem that's all in your head is still a problem.
Brain damage is but one form of mind damage.
-- 
http://mail.python.org/mailman/listinfo/python-list


Import elfclass32 issue

2006-06-11 Thread DarkBlue
Hello

 Suse10.1 64 new install

 if I try to import anything into python2.4.2
 like : python - c "import kinterbasdb"

 I get this :  wrong ELF class: ELFCLASS32

 Before doing anything wrong , what would be the right thing
 to do to get rid of this error ?

 Thanks.


  



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


package search

2006-06-11 Thread boris
I have two directories, lib1 and lib2, that both contain the package
foo, one with the submodule mod1
and the other with the submodule mod2:

$ ls lib*/foo/
lib1/foo/:
__init__.py  __init__.pyc mod1.py  mod1.pyc

lib2/foo/:
__init__.py  __init__.pyc mod2.py  mod2.pyc
$

Now this script:

import sys
sys.path.append("lib1")
sys.path.append("lib2")
import foo.mod1

will find the module foo.mod1, while the same script with the two
append-lines interchanged will not:

import sys
sys.path.append("lib2")
sys.path.append("lib1")
import foo.mod1

The error is:

import foo.mod1
ImportError: No module named mod1

So I guess that when Python finds the package foo, it will not look for
it again using the rest of
the search path, even if at that first place the module could not be
found.

Other languages like e.g. Java would find the module mod1 in the second
case too (if Java doesn't
find it in the first place, it will also look for it in the second
place).

This behaviour of Python is very unfortunate, because you always have
to merge your package
trees. In my cvs I have several packages, each in its own cvs module,
all starting with
de.science_computing. Now if I need two of them in a new project, I
will have two package trees
in my cvs sandbox, both starting with de.science_computing. Leaving the
sandbox that way, cvs
will work but Python imports will fail while if I merge all the package
trees, Python will work but cvs
won't.

My questions:
- Have I done anything wrong?
- If not, is this behaviour of Python a bug or intentional?
- If it it intentional, what is the intent?

Thank you for your help
Boris

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


Re: Xah Lee network abuse

2006-06-11 Thread Erik Max Francis
EJP wrote:

> Many states have criminal as well as civil libel. 
> http://en.wikipedia.org/wiki/Slander_and_libel

The idea of using Wikipedia to back up a legal point is rather amusing 
... but still, none of the relevant parties involved live in countries 
which have any form of criminal libel.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   To perceive is to suffer.
   -- Aristotle
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Xah Lee network abuse

2006-06-11 Thread Erik Max Francis
Philippa Cowderoy wrote:

> It is. However, the onus is on the defendant to show that it's true, 
> rather than on the claimant to show that it's false.

That also depends on the jurisdiction.

> I assume the "he" 
> refers to Brandon?

No, I was referring to the person who he was replying to, i.e., you.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Twenty-four hours a day, three-hundred sixty-five days a year as
   Secretary of Defense, I lived the Cold War. -- Robert S. McNamara
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Xah Lee network abuse

2006-06-11 Thread Philippa Cowderoy
On Sun, 11 Jun 2006, Erik Max Francis wrote:

> Philippa Cowderoy wrote:
> 
> > It is. However, the onus is on the defendant to show that it's true, rather
> > than on the claimant to show that it's false.
> 
> That also depends on the jurisdiction.
> 

Hrmm, does that one differ in Scotland?

> > I assume the "he" refers to Brandon?
> 
> No, I was referring to the person who he was replying to, i.e., you.
> 

Wrong pronoun, then.

-- 
[EMAIL PROTECTED]

Society does not owe people jobs. 
Society owes it to itself to find people jobs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very newbie programming

2006-06-11 Thread Fredrik Lundh
TheSaint wrote:

> A part of this, how python catch variables, the longer the slower, isn't it?

nope.



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


Re: Most elegant way to generate 3-char sequence

2006-06-11 Thread Fredrik Lundh
James Stroud wrote:

> See the actual question:
> 
>  >How would you construct a generator to acheive this?

if you don't think the context provided by the subject line and the 
sentence before the question is important, how come you're so sure what 
"this" refers to ?



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


Re: Xah Lee network abuse

2006-06-11 Thread Erik Max Francis
Philippa Cowderoy wrote:

> Hrmm, does that one differ in Scotland?

I don't believe so.

> Wrong pronoun, then.

Well, your comment was challenged, and I offered a reasonable 
interpretation of what you might have meant (which indicated a more 
general point in any case, namely that libel law is not quite as simple 
as the original poster was making it out to be).  If you don't wish to 
defend your position, that's fine, but pointing fingers is kind of weird 
at this stage.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   To perceive is to suffer.
   -- Aristotle
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Xah Lee network abuse

2006-06-11 Thread Philippa Cowderoy
On Sun, 11 Jun 2006, Erik Max Francis wrote:

> Philippa Cowderoy wrote:
> 
> > Hrmm, does that one differ in Scotland?
> 
> I don't believe so.
> 

My statement was intended in the context of UK law - I have to admit to 
not knowing too much about what's different north of the border beyond the 
infamous verdict though.

> > Wrong pronoun, then.
> 
> Well, your comment was challenged, and I offered a reasonable interpretation
> of what you might have meant (which indicated a more general point in any
> case, namely that libel law is not quite as simple as the original poster was
> making it out to be).  If you don't wish to defend your position, that's fine,
> but pointing fingers is kind of weird at this stage.
> 

I'd still appreciate being referred to as "she" rather than "he" though.

-- 
[EMAIL PROTECTED]

'In Ankh-Morpork even the shit have a street to itself...
 Truly this is a land of opportunity.' - Detritus, Men at Arms
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Xah Lee network abuse

2006-06-11 Thread Erik Max Francis
Philippa Cowderoy wrote:

> I'd still appreciate being referred to as "she" rather than "he" though.

Oops, my bad.  Never occurred to me after all these years, which is kind 
of embarrassing, actually :-).

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Isn't jumping of a bridge / Free fallin'
   -- Sandra St. Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learning python idioms

2006-06-11 Thread bayerj
Hi,

If you switched from java to python the best point to start is
http://dirtsimple.org/2004/12/python-is-not-java.html.

Greets,
-Justin

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


Re: learning python idioms

2006-06-11 Thread gene tani

[EMAIL PROTECTED] wrote:
> After several years developing in Java, I've begun to switch to Python
> for several of my new projects as I have found the language quite
> interesting.  I've read several tutorials and implemented a few sample
> programs and I've found that Python enables one to program in a variety
> of different styles (I'm not sure if this was the original intention or
> not).  Thus, I find myself occaisionally slipping into the "Java"

i googled "Python idioms":

http://www.gungfu.de/facts/wiki/Main/PythonIdioms

also look at the OReilly Python cookbook and the online repository it's
based on
http://aspn.activestate.com/ASPN/Cookbook/Python

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


Re: learning python idioms

2006-06-11 Thread gene tani

bayerj wrote:
> Hi,
>
> If you switched from java to python the best point to start is
> http://dirtsimple.org/2004/12/python-is-not-java.html.
>
> Greets,
> -Justin

yup, you could spend weeks reading the Language Wars:

http://www.google.com/search?hl=en&q=site%3Aartima.com+java+python&btnG=Google+Search

http://del.icio.us/tag/python+java

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


Re: Xah Lee network abuse

2006-06-11 Thread EJP
Erik Max Francis wrote:
> EJP wrote:
> 
>> Many states have criminal as well as civil libel. 
>> http://en.wikipedia.org/wiki/Slander_and_libel
> 
> The idea of using Wikipedia to back up a legal point is rather amusing 
> ... but still, none of the relevant parties involved live in countries 
> which have any form of criminal libel.

OK, OK, just proffered as information, not a conclusive proof. It's the 
*courts* that back up legal points of course, not anything said or found 
here.

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


Re: Import elfclass32 issue

2006-06-11 Thread DarkBlue
Sybren Stuvel wrote:

> file /path/to
I installed the package on other 64 machines running 
suse9.2 64 and 9.3 64 without trouble

That's the way :

python setup.py build
result: successfull

python setup.py install
result: successfull

then tried to import and I get the elfclass32 error

and that's all I did. The suse10.1 installation is pristine
only auto updated with the latest patches of the day.

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


Re: package search

2006-06-11 Thread boris

Sybren Stuvel wrote:
> Simplicity and explicitness. You have two packages 'foo', and it
> simply loads the first one it finds.

Yes, here you are right. It is indeed simple.

Boris

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


Re: Import elfclass32 issue

2006-06-11 Thread Fredrik Lundh
DarkBlue wrote:

> and that's all I did. The suse10.1 installation is pristine
> only auto updated with the latest patches of the day.

if you're using a SuSE-provided python interpreter, you should make to 
use the right development files (python-dev, or whatever that's called 
over in SuSE land).

if you do, it's a SuSE problem (this wouldn't be the first time SuSE 
ships broken Python software)

have you checked the SuSE bug databases / support forums for clues, btw?

(if you google for the error message, you'll find several hundreds of 
non-Python-related hits, so it's more of a 32/64-bit compiler problem 
than a Python problem...)



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


Re: Algorithm for Labels like in Gmail

2006-06-11 Thread Gerard Flanagan
[EMAIL PROTECTED] wrote:
> Hello there!
>
> I'm trying to make a simple Contact Manager using python (console
> only), however i'm having trouble implementing a division by "Groups"
> or "Labels" just like in Gmail. I don't have any real code to post
> because all i got now is a raw TXT file holding the names and phones of
> my contacts.
>
> The only idea I could figure out until now seems too weak, so that's
> why i'm asking for help. I thought of making a separate list (in a text
> file) holding all the possible groups, where each group hold the names
> of the contacts. Then if i access a group, i'll be able to see all
> contacts related to that group. On the other hand, i'll also need to
> attach to the contact instance a list of every group it is present.
> I think it's a bad idea because it seems to be very easy to get things
> messed up. Like I can get things corrupted or bad linked, and i'll
> always need to run functions to check all the realations between
> contact names and groups...
>
> I like the way i can "label" emails on Gmail, does anyone know how I
> can implement such kind of feature? What's the best/broadly used
> algorithm?
>
> Sorry for the long message, and thanks in advance
>
> Rodolfo Carvalho

There's a program called 'buzhug' (http://buzhug.sourceforge.net/)
which is described as "a pure-Python database engine, using a Pythonic,
no-SQL syntax".  I think it's in its early stages of development but it
might be suitable for your project.  I spent the morning playing about
with it using your example of a (Very Simple) Contact Manager, and
there's some runnable but unfinished code below.  It only implements a
'Many-to-one' relationship between Contacts and Groups  - in other
words, a Contact can only belong to one Group.  There's probably a lot
I haven't considered, it will break easily, and the docstrings are in
the post, but there you go.

Have fun!

Gerard

(also - http://groups.google.com/group/buzhug)


print

from buzhug import Base
import os

def get_bases():
if os.path.exists('data'):
return Base('data/dt_groups'), Base('data/dt_contacts')
else:
#Bases don't exist, so create them
os.mkdir('data')
groups = Base('data/dt_groups')
groups.create( ('name', str) )
groups.insert( 'Family' )
groups.insert( 'Friends' )
groups.commit()

contacts = Base('data/dt_contacts')
contacts.create( ('group', groups), ('first_name', str),
('last_name', str), ('email', str) )
contacts.insert( groups[0], 'Jack', 'Jones', '[EMAIL PROTECTED]' )
contacts.insert( groups[0], 'John', 'Jones', '[EMAIL PROTECTED]' )

contacts.insert( groups[1], 'James', 'diGriz',
'[EMAIL PROTECTED]' )
contacts.insert( groups[1], 'Dirk', 'Gently',
'[EMAIL PROTECTED]' )
contacts.commit()
return groups, contacts

def usage():
print '''
ADD  - Add a Contact
eg. ADD Family, Susan, Smith, [EMAIL PROTECTED]
eg. ADD Work, Jason, Jones, [EMAIL PROTECTED]
DEL  - Delete a Contact or Group
eg. DEL firstname=Susan, lastname=Smith
eg. DEL group=Family
FIND - Search for contacts
eg. FIND lastname=Smith
eg. FIND group=Family
EXIT - End the program
  '''

def intro():
print '\n' * 5
print '#' * 52
print '#' * 20, ' CONTACTS ', '#' * 20
print '#' * 52
usage()
print '\n' * 2


def get_input(prompt):
s = raw_input(prompt).strip()
if s.upper() == 'EXIT':
raise EOFError
return s

def ADD(groupname, firstname, lastname, email):
groups, contacts = get_bases()
try:
groups.open()
#see if a group with this name exists
records = [ g for g in groups if g.name == groupname ]
if len(records) == 0:
#no group with this name, so create it
gid = groups.insert( name=groupname.strip() )
group = groups[gid]
else:
group = records[0]
finally:
groups.commit()
try:
contacts.open()
contacts.insert(group, firstname.strip(), lastname.strip(),
email.strip())
finally:
contacts.commit()

def test():
groups, contacts = get_bases()
try:
contacts.open()
for contact in contacts:
print contact.group.name, contact.first_name,
contact.last_name
finally:
contacts.commit()

if __name__ == '__main__':

intro()
while True:
try:
s = get_input('-> ')
if s[0] == '?':
usage()
elif s == 'test':
test()
elif s[:4] == 'ADD ':
grp, fname, lname, email = s[4:].split(',')
try:
ADD(grp, fname, lname, email)
except Exception, e:
print e
except EOFError:
break
print '\nbye'

---

Re: regexp questoin

2006-06-11 Thread Simon Brunning
On 9 Jun 2006 17:44:42 -0700, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> actually, i am doing an application that allows user to delete files by
> entering an input pattern.

If you are looking to match filenames, you might want to have a look
at the fnmatch and glob modules. The patterns that they support are
less powerful and flexible than regex patters, but much simpler, and
specifically designed with filename matching in mind.

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


Re: learning python idioms

2006-06-11 Thread bayerj
> yup, you could spend weeks reading the Language Wars:

Actually, that link is not about language wars. It's about making the
switch from java to python. Nothing more, nothing less.

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


[mod_python] using nested blocks in psp

2006-06-11 Thread cloc3
I'm a newbie in python, and I'm fighting against nested blocks in psp.
Thats a little example with a funny behaviour:
[code]





<%
for i in range(50, 350, 50):
 if 'List' in form and int(form['List'])==i:
  sel="selected"
 else:
  sel="pippo"
 %> ><%=i%> 
 <%
%>




[/code]
In my intention, the for instruction have to run two operation:
 first: the if instruction
 second: to print the option tag on the html page.

Instead, the real behaviour is depending on the result of the control
in the if:
 if the control is true, the option tag is not printed, and the for
instruction goes to the successive step.
 if the control is false, the option is correctly printed.

I don't understand the reason of this behaviour.
Which is the right way to control the nested block instructions in psp?

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


[ANN] clnum-1.2.1 Class Library For Numbers Python Binding

2006-06-11 Thread Raymond L. Buvel
The clnum package adds rational numbers and arbitrary precision floating
point numbers in real and complex form to Python. Also provides
arbitrary precision floating point replacements for the functions in the
math and cmath standard library modules.

Home page: http://calcrpnpy.sourceforge.net/clnum.html

Changes in 1.2.1

Updated the unit test so it works on both 32 and 64 bit platforms.  Only
the source package was updated since there are no other changes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import elfclass32 issue

2006-06-11 Thread DarkBlue
Fredrik Lundh wrote:


> if you do, it's a SuSE problem (this wouldn't be the first time SuSE
> ships broken Python software)

Thanks for the input .
Following your message I reinstalled python2.4 and the modules
I want to use and now everything is fine.





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


Re: package search

2006-06-11 Thread imho
boris ha scritto:
> I have two directories, lib1 and lib2, that both contain the package
> foo, one with the submodule mod1
> and the other with the submodule mod2:
> [...]
> Now this script:
> 
> import sys
> sys.path.append("lib1")
> sys.path.append("lib2")
> import foo.mod1
> 
> will find the module foo.mod1, while the same script with the two
> append-lines interchanged will not:
> 
> import sys
> sys.path.append("lib2")
> sys.path.append("lib1")
> import foo.mod1
> 
> The error is:
> 
> import foo.mod1
> ImportError: No module named mod1
 > [...]

You just have to put in "__init__.py" in "lib2" (the package directory 
you are "extending"), the following lines:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

"__path__", in each __init__ module, is a list initialized with the 
module's path, but you can extend it by appending paths where you want 
the interpreter to look for further modules.
pkgutil.extend_path automatically appends to __path__ all subdirectories 
of directories on sys.path named after the package.

HTH :-)

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


Re: package search

2006-06-11 Thread boris

imho wrote:
>
> You just have to put in "__init__.py" in "lib2" (the package directory
> you are "extending"), the following lines:
>
> from pkgutil import extend_path
> __path__ = extend_path(__path__, __name__)
>
> "__path__", in each __init__ module, is a list initialized with the
> module's path, but you can extend it by appending paths where you want
> the interpreter to look for further modules.
> pkgutil.extend_path automatically appends to __path__ all subdirectories
> of directories on sys.path named after the package.
>
> HTH :-)
>
> Diego.

COOL! You just saved me an awful lot of work.

Thanks, Diego!

Boris

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


Re: Algorithm for Labels like in Gmail

2006-06-11 Thread Rodolfo
Thanks to you all.

I'll start trying the buzhug solution, which seems more pythonic. But I
feel like I gotta learn how to use databases... once I studied SQL a
litle bit, but don't remember much.
I'll play around with Python and then I show what I got.

Bye

Rodolfo

P.S:  Is there a way to do a "clear screen" on a Python program? I mean
something like the "cls" command in MS-DOS

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


Re: Intermittent Failure on Serial Port

2006-06-11 Thread Serge Orlov
H J van Rooyen wrote:
> Serge Orloff wrote:
>
> | H J van Rooyen wrote:
> | > Traceback (most recent call last):
> | >   File "portofile.py", line 232, in ?
> | > ret_val = main_routine(port, pollstruct, pfifo)
> | >   File "portofile.py", line 108, in main_routine
> | > send_nak(port, timeout)  # so bad luck - comms error
> | >   File "/home/hvr/Polling/lib/readerpoll.py", line 125, in send_nak
> | > port.flush()
> | > IOError: [Errno 29] Illegal seek
> | > close failed: [Errno 29] Illegal seek
> | >
> |
> |
> | > Where can I find out what the Errno 29 really means?
> | > Is this Python, the OS or maybe hardware?
> |
> | It is from kernel: grep -w 29 `locate errno`
> | /usr/include/asm-generic/errno-base.h: #define   ESPIPE  29
> |  /* Illegal seek */
> |
> | man lseek:
> |
> | ERRORS:
> | ESPIPE fildes is associated with a pipe, socket, or FIFO.
> |
> | RESTRICTIONS:
> | Linux  specific  restrictions:  using  lseek  on  a  tty device
> | returns ESPIPE.
>
>
> Thanks for the info - so the Kernel sometimes bombs me out - does anybody know
> why the python flush sometimes calls lseek?

I thought it was your own flush method. If it is file.flush method that
makes the issue more complicated, since stdlib file.flush doesn't call
lseek method. I suggest you run your program using strace to log system
calls, without such log it's pretty hard to say what's going on. The
most interesting part is the end, but make sure you have enough space
for the whole log, it's going to be big.

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


Re: package search

2006-06-11 Thread imho
boris ha scritto:

> 
> COOL! You just saved me an awful lot of work.
> 
> Thanks, Diego!
> 
> Boris
> 

;-)

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


Re: TKinter

2006-06-11 Thread Chris Lambacher
I would try looking at Django or Turbogears.
http://www.djangoproject.com/
http://www.turbogears.org/

Also have a look at:
How to write a browser-based desktop app using CherryPy 2.0:
http://www.cherrypy.org/wiki/SingleClickAndRun
How to write a a browser-based desktop app using CherryPy 2.1:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442481

-Chris

On Sat, Jun 10, 2006 at 10:25:53AM -0700, V Sivakumar wrote:
>Dear Chris,
> It is really very kind of you. Actually, I planned to do as a web
>program with a in built webserver. In that a the GUI creation becomes
>very easy. Is  Twisted (Python 2.4) a good option?
> 
>I find no good tutorials for Python programming. Like handling HTTPRequest
>and HTTPResponse.
> 
> 
>Kind Regards
>V Sivakumar
> 
>"You cannot know the meaning of your life until you are connected to the
>power that created you" - Shri Mataji Nirmala Devi. [1]www.tnsahaj.org.
> 
>- Original Message 
>From: Chris Lambacher <[EMAIL PROTECTED]>
>To: V Sivakumar <[EMAIL PROTECTED]>
>Cc: python-list@python.org
>Sent: Saturday, 10 June, 2006 9:26:38 AM
>Subject: Re: TKinter
> 
>GTK+ + Glade
>[2]http://pygtk.org/
> 
>WxPython has several GUI editors
>[3]http://wxpython.org
> 
>PyQt has the ability to generate code from the Qt GUI designer
>[4]http://www.riverbankcomputing.co.uk/pyqt/
> 
>I personally have used GTK+ and Glade with great success.  I found
>WxPython to
>be lacking in polish.  I have not worked with PyQt.
> 
>Pretty much all of the above work models are not embedded into an
>IDE.  There
>is a GUI editor, and then you use your regular editor to write code.
> 
>This is actually a pretty good model because from my experience, as your
>application becomes bigger and more complicated, you want less GUI
>generated
>UI and more had written UI code.
> 
>-Chris
> 
>On Thu, Jun 08, 2006 at 10:29:44PM -, V Sivakumar wrote:
>> Dear Group!,
>> I am new to Python. I have Eclipse with Python support , is there
>> better IDE for free and with good support for GUI development. I need
>> to develop a nice looking desktop application. Like we could do in VB,
>> C# and Java Swing. Is there  a drag drop support GUI toolkit for
>> Python like the above languages do?
>>
>> Thanks
>> Siva
>>
>>
>>
>>
>> --
>> [5]http://mail.python.org/mailman/listinfo/python-list
> 
> References
> 
>Visible links
>1. http://www.tnsahaj.org/
>2. http://pygtk.org/
>3. http://wxpython.org/
>4. http://www.riverbankcomputing.co.uk/pyqt/
>5. http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very newbie programming

2006-06-11 Thread George Sakkis
TheSaint wrote:

> Maric Michaud wrote:
>
> > Le Samedi 10 Juin 2006 17:44, TheSaint a écrit :
>
> >>
> > begin using more explicit variable names.
>
> Frankly it's a very rooted way of programming, since C64 basic :-)

If by 'rooted' you mean old enough, so is 'goto'... Except perhaps for
iteration variables ("for i in xrange(10)"), always use names that mean
something; you (and anyone else that might have to read your code) will
thank yourself for doing so if you have to go back at this code a few
months later.

> > this will do exactly  the same
> >
> > for icon_file in (open(dskt + e) for e in os.listdir(dskt) if '.desktop'
> > in e) :
> > for line in icon_file :
> > if  'URL=/media' in line :
> > icon = icon.name
> > dvc = line[11:-1]
> > break
> >
> A simple question, how do I'll get out of all loops, once found the right
> result?

You can set a boolean "found" flag to False, make it True in the if
block, check it in the outer loop and break if it is True. For this
case though I'd use the fileinput module to iterate over the lines of
all files directly (http://docs.python.org/lib/module-fileinput.html):

from fileinput import FileInput

instram = FileInput([dskt+e for e in os.listdir(dskt) if 'desktop' in
e])
for line in instream:
if  'URL=/media' in line :
icon = instream.filename()
dvc = line[11:-1]
break

Btw, you can delete a file or directory with os.unlink and os.rmdir,
respectively; no need for os.system.

George

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


Re: TypeError: unsubscriptable object

2006-06-11 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Can anybody tell me why am I getting this error message while trying to
> print a part of a string. Is there a better approach for this...

Because you don't use a string? The error message is pretty clear:

TypeError: unsubscriptable object

So - what are Function[:10], Description[:10] ? You _assume_ they are 
strings, seems not to be the case.

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


import hook

2006-06-11 Thread Jeremy Sanders
Hi - Is it possible to override the import process so that if in my program
I do

import foo.bar

Python will look for bar in a directory which isn't called foo?

I want my module/program to be able to be run without being installed in
site-packages, so by doing "import foo.bar", it should start looking for
bar in the current directory which could be called "foo-0.43".

I've tried overriding __import__, chopping out "foo." from package names,
but that tends to break. I've also tried overriding imp.find_module() but
Python never appears to use my version.

Any ideas?

Thanks

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 10GB XML Blows out Memory, Suggestions?

2006-06-11 Thread uche . ogbuji
K.S.Sreeram wrote:
> Fredrik Lundh wrote:
> > both ElementTree and cElementTree support "sax-style" event generation
> > (through XMLTreeBuilder/XMLParser) and incremental parsing (through
> > iterparse).  the cElementTree versions of these are even faster than
> > pyexpat.
> >
> > the iterparse interface is described here:
> >
> >  http://effbot.org/zone/element-iterparse.htm
> >
> Thats cool! Thanks for the info!
>
> For a multi-gigabyte file, I would still recommend C/C++, because the
> processing code which sits on top of the XML library needs to be Python,
> and that could turn out to be a significant overhead in such extreme cases.
>
> Of course, the exact strategy to follow would depend on the specifics of
> the case, and all this speculation may not really apply! :)

Honestly, i think that legitimate use-cases for multi-gigabyte XML are
very rare.  Many people abuse XML as some sort of DBMS replacement.
This abuse is part of the reason why so many developers are hostile to
XML.  XML is best for documents, and documents can get to the
multi-gigabyte range, but rarely do.  Usually, when they do, there is a
logical way to decompose them, process them, and re-compose them,
whereas with XML used as a DBMS replacement, relations and datatyping
complicate such natural divide-and-conquer techniques.

I always say that if you're dealing with gigabyte XML, it's well worth
considering whether you're not using a hammer to screw in a bolt.

If monster XML is inevitable, then I extend's Fredrik earlier mention
of Amara to say that Pushdom allows you to pre-declare the chunks of
XML you're interested in, and then it processes the XML in streaming
mode, only instantiating the chunks of interest one at a time.  This
allows for handling of huge files with a very simple programming idiom.

http://uche.ogbuji.net/tech/4suite/amara/

--
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

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


Re: Xah Lee network abuse

2006-06-11 Thread Mike Schilling

"Erik Max Francis" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Mike Schilling wrote:
>
>> If I were to write, say, that Tony Blair's tax policy will lead to higher 
>> deficits, I could be convicted of libel?  Even if that's true, it's not a 
>> priori provable.
>
> I think what he was getting at is that, unlike many jurisdictions, writing 
> something factually true is _not_ in and of itself a defense against a 
> libel suit in the UK.
>
> As for the reverse side of the issue, in jurisdictions where it _is_ a 
> defense, if one were to accuse him of being a pedophile but couldn't prove 
> it, that would certainly be an actionable offense.

In the U.S, for instance, you wouldn't have to prove it.  It would be 
sufficent to demonstrate that there's enough evidence supporting it that you 
weren't reckless in writing it. 


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


Re: Very newbie programming

2006-06-11 Thread TheSaint
Maric Michaud wrote:

> Le Samedi 10 Juin 2006 17:44, TheSaint a écrit :
> devices = [ e for e in devices if e.split('/')[-1] in partitions ]

This is _not_ the expected result :)

is missing a not as :
devices = [ e for e in devices if e.split('/')[-1] *not* in partitions ]

>> if len(c) != 1:
>> sys.exit(0) # if none or more than one match exit
>>
>> cmnd = str(c)[2:-2]
>> err = os.system('umount ' + cmnd)
> 
> why ?
> 
> os.system('umount "%s"' % devices[0])

> for line in icon_file :
> if  'URL=/media' in line :
> icon = icon.name
> dvc = line[11:-1]
> break

The question is correct, I should go a step further. But as it will unmount
multiple (ghost) partitions it should also remove the icons from the
desktop as well. So I'm bit confused how to remove *each* icon, unless do
it into the "for" loop.
I'd like to get the search as fast as possible and solve the appropriate
icon with the right device, after all :)
Suppose to have the pendrive and the Compact Flash, which both are mounted
in /media, what will be removed syncronized with its mount?
I didn't get this problem so deep as long as I just considered to use one
device at time.

F

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


Re: import hook

2006-06-11 Thread Rune Strand
Jeremy Sanders wrote:
> Hi - Is it possible to override the import process so that if in my program
> I do
(...)
>
> Any ideas?


Why not handle the foo.bar/version string separately and just append
the resulting path to sys.path?

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


Re: import hook

2006-06-11 Thread Alex Martelli
Jeremy Sanders <[EMAIL PROTECTED]> wrote:

> Hi - Is it possible to override the import process so that if in my program
> I do
> 
> import foo.bar
> 
> Python will look for bar in a directory which isn't called foo?
> 
> I want my module/program to be able to be run without being installed in
> site-packages, so by doing "import foo.bar", it should start looking for
> bar in the current directory which could be called "foo-0.43".
> 
> I've tried overriding __import__, chopping out "foo." from package names,
> but that tends to break. I've also tried overriding imp.find_module() but
> Python never appears to use my version.
> 
> Any ideas?

Yes, PEP 302 (which despite being marked as "draft" has in fact been
already mostly implemented, since it's used by the zipimport mechanism)
allows you to perform such feats.  Study it at
 ...


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


ANN: PyQt v4.0 Released - Python Bindings for Qt v4

2006-06-11 Thread Phil Thompson
Riverbank Computing is pleased to announce the release of PyQt v4.0 available 
from http://www.riverbankcomputing.co.uk/pyqt/.

The main change from v4.0beta1 is the inclusion of comprehensive HTML 
documentation based on the Qt documentation.

PyQt is a comprehensive set of Qt bindings for the Python programming language 
and supports the same platforms as Qt (Windows, Linux and MacOS/X).  Like Qt, 
PyQt is available under the GPL and a commercial license.

PyQt v4 supports Qt v4 (http://www.trolltech.com/products/qt/index.html).  
PyQt v3 is still available to support earlier versions of Qt.

PyQt v4 is implemented as a set of 8 extension modules containing 
approximately 400 classes and 6,000 functions and methods.

QtCore
The non-GUI infrastructure including event loops, threads, i18n, Unicode,
signals and slots, user and application settings.

QtGui
A rich collection of GUI widgets.

QtNetwork
A set of classes to support TCP and UDP socket programming and higher
level protocols (eg. HTTP).

QtOpenGL
A set of classes that allows PyOpenGL to render onto Qt widgets.

QtSql
A set of classes that implement SQL data models and interfaces to industry
standard databases.  Includes an implementation of SQLite.

QtSvg
A set of classes to render SVG files onto Qt widgets.

QtXML
A set of classes that implement DOM and SAX parsers.

QtAssistant
A set of classes that enables the Qt Assistant online help browser to be
integrated with an application.

A Windows installer is provided for the GPL version of PyQt to be used with 
the GPL version of Qt v4 (http://www.trolltech.com/download/qt/windows.html). 
It enabes a complete PyQt environment to be installed on Windows without the 
need for a C++ compiler.

PyQt includes the pyuic utility which generates Python code to implement user 
interfaces created with Qt Designer in the same way that the uic utility 
generates C++ code.  It is also able to load Designer XML files dynamically.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very newbie programming

2006-06-11 Thread TheSaint
George Sakkis wrote:

> 
> If by 'rooted' you mean old enough, so is 'goto'... 

I was meaning a sort of (very) old style of programming. In fact I wrote
some few hundreds lines on my own, but probably memory was much better
the :)

> will 
> thank yourself for doing so if you have to go back at this code a few
> months later.

I have to admit that's purely true :)
 
> You can set a boolean "found" flag to False, make it True in the if

Thank you to point it out, I forgotten such solution. BTW I was on the way
of an "try/exept". But I should go back study the corect use :)

> from fileinput import FileInput

I'll read the manual (as you pointed hereby) and I think I can read the
entire directory file by file.

> Btw, you can delete a file or directory with os.unlink and os.rmdir,
> respectively; no need for os.system.

I still on learning, you know? :)
Reading is the way to solve some problem, and your suggestions (you all) are
very precious.

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


Re: [ANN] Cerealizer 0.4 -- a secure Pickle-like module

2006-06-11 Thread Aahz
In article <[EMAIL PROTECTED]>,
Jiba   wrote:
>
>Cerealizer is now available under the Python license (and was
>previously GPL'ed).

Nothing except for Python itself should be released under the Python
license.  See
http://wiki.python.org/moin/PythonSoftwareFoundationLicenseFaq
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there."  --Steve Gonedes
-- 
http://mail.python.org/mailman/listinfo/python-list


direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread digitalorganics
What's the difference between initializing class variables within the
class definition directly versus initializing them within the class's
__init__ method? Is there a reason, perhaps in certain situations, to
choose one over the other?

Thank you.

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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> What's the difference between initializing class variables within the
> class definition directly versus initializing them within the class's
> __init__ method? Is there a reason, perhaps in certain situations, to
> choose one over the other?

You are confusing class variables with instance variables. The former 
are what you can initialize inside the class-statement. However, they 
are shared amongst _all_ instances. Consider this little example:

class Foo(object):
 FOO = 1
 BAR = []

 def __init__(self, FOO):
 self.FOO = FOO
 self.BAR.append(FOO)

 def __repr__(self):
 return "FOO: %r\nBAR: %r\n" % (self.FOO, self.BAR)


f1 = Foo(1)
print f1
f2 = Foo(2)
print f2
print f1


--
meskal:~/Projects/CameraCalibrator deets$ python2.4 /tmp/test.py
FOO: 1
BAR: [1]

FOO: 2
BAR: [1, 2]

FOO: 1
BAR: [1, 2]


-

As you can see, the list BAR is shared. And you can also see that 
_assigning_ to something like this:

self.FOO

will create an instance-variable. Even if a variable of the same name 
existed on the class before!

Which is precisely the difference between using variable initialization 
in __init__ and inside the class-statement.

BTW,

self.__class__.FOO = value

will set class-variables inside a method. Just if you wondered.

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


ANN: Dao 1.0.0-alpha is released

2006-06-11 Thread [EMAIL PROTECTED]
Hello,

It is a pleasure to announce in this mailing list the newly released
Dao. This is the first release after the Dao interpreter being
re-designed and re-implemented as a virtual register machine since the
beginning of this year. There have been many great improvements on both
the language and the efficiency of the virtual machine. 10-20 times
speedup has been observed. I am sure you will be surprised when you try
it and compare it with other scripting languages.

Some important language features have been added, such as switch-case
control, for-in-do control, setting function parameter types and
default values, passing parameters by name, and function overloading by
parameter types; OOP in Dao is also greatly improved; reflection
methods are newly supported. In one word, the release represents a
milestone in the development of Dao.

Two modules are also released along with the virtual machine: DaoMySQL
and DaoPyhon. DaoPython is particularly interesting, because it allows
Python modules to be loaded by Dao, then Python variables, functions
and classes can be used conviniently in Dao scripts.

However, since the virtual machine is almost written from scratch only
since the beginning of this year, it could not be very robust (it
should be more robust than any previous releases), that is why it is
release as an alpha release. A formal release will be made once the
virtual machine is well tested (please join us, if you want this
process to be faster).

For more detail about this release: please visit http://www.xdao.org,
and http://xdao.org/dokuwiki/.

Your suggestions and comments are extremely welcome!

Limin FU

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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread digitalorganics
Ah, you've brought me much clarity Diez, thank you. That would explain
some "bugs" I've been having...


Diez B. Roggisch wrote:
> [EMAIL PROTECTED] schrieb:
> > What's the difference between initializing class variables within the
> > class definition directly versus initializing them within the class's
> > __init__ method? Is there a reason, perhaps in certain situations, to
> > choose one over the other?
>
> You are confusing class variables with instance variables. The former
> are what you can initialize inside the class-statement. However, they
> are shared amongst _all_ instances. Consider this little example:
>
> class Foo(object):
>  FOO = 1
>  BAR = []
>
>  def __init__(self, FOO):
>  self.FOO = FOO
>  self.BAR.append(FOO)
>
>  def __repr__(self):
>  return "FOO: %r\nBAR: %r\n" % (self.FOO, self.BAR)
>
>
> f1 = Foo(1)
> print f1
> f2 = Foo(2)
> print f2
> print f1
>
>
> --
> meskal:~/Projects/CameraCalibrator deets$ python2.4 /tmp/test.py
> FOO: 1
> BAR: [1]
>
> FOO: 2
> BAR: [1, 2]
>
> FOO: 1
> BAR: [1, 2]
>
>
> -
>
> As you can see, the list BAR is shared. And you can also see that
> _assigning_ to something like this:
>
> self.FOO
>
> will create an instance-variable. Even if a variable of the same name
> existed on the class before!
>
> Which is precisely the difference between using variable initialization
> in __init__ and inside the class-statement.
>
> BTW,
>
> self.__class__.FOO = value
>
> will set class-variables inside a method. Just if you wondered.
> 
> Diez

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


Re: import hook

2006-06-11 Thread Thomas Heller
Alex Martelli wrote:
> Jeremy Sanders <[EMAIL PROTECTED]> wrote:
> 
>> Hi - Is it possible to override the import process so that if in my program
>> I do
>> 
>> import foo.bar
>> 
>> Python will look for bar in a directory which isn't called foo?
>> 
>> I want my module/program to be able to be run without being installed in
>> site-packages, so by doing "import foo.bar", it should start looking for
>> bar in the current directory which could be called "foo-0.43".
>> 
>> I've tried overriding __import__, chopping out "foo." from package names,
>> but that tends to break. I've also tried overriding imp.find_module() but
>> Python never appears to use my version.
>> 
>> Any ideas?
> 
> Yes, PEP 302 (which despite being marked as "draft" has in fact been
> already mostly implemented, since it's used by the zipimport mechanism)
> allows you to perform such feats.  Study it at
>  ...

There are also other ways.  You could extend __path__ of foo, and the
pkgutil module might also be useful.

Thomas

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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread digitalorganics
Wait a minute! It doesn't explain my bugs. I've got "class variables"
acting like instance variables. What's weirder is that this behavior
occurs on my computer (in both of my installed WinXP copies) but not on
my laptop (WinXP Pro).

See the following test:

class Boo:
jerk = "yes"

def killjerk(self):
self.jerk = self.jerk + "no"
print self.jerk
print self.__class__.jerk

bing = Boo()
bing.killjerk()

outputs:

yesno
yes

At first, I thought that self.jerk was resolving to the class attribute
instead of creating a new variable (w/ a differing scope). But we can
see that there are actually two variables because a direct reference to
self.__class__.jerk returns "yes", not yesno (what we would get if
self.jerk pointed to the same data/object as self.__class__.jerk). Yet,
it's treating self.jerk as a combination of the two (it always add the
class attribute to the instance attribute). Is this normal behavior??
It doesn't work this way on my laptop...

Perhaps you can see why I'd be confused!

Thanks.

[EMAIL PROTECTED] wrote:
> Ah, you've brought me much clarity Diez, thank you. That would explain
> some "bugs" I've been having...
>
>
> Diez B. Roggisch wrote:
> > [EMAIL PROTECTED] schrieb:
> > > What's the difference between initializing class variables within the
> > > class definition directly versus initializing them within the class's
> > > __init__ method? Is there a reason, perhaps in certain situations, to
> > > choose one over the other?
> >
> > You are confusing class variables with instance variables. The former
> > are what you can initialize inside the class-statement. However, they
> > are shared amongst _all_ instances. Consider this little example:
> >
> > class Foo(object):
> >  FOO = 1
> >  BAR = []
> >
> >  def __init__(self, FOO):
> >  self.FOO = FOO
> >  self.BAR.append(FOO)
> >
> >  def __repr__(self):
> >  return "FOO: %r\nBAR: %r\n" % (self.FOO, self.BAR)
> >
> >
> > f1 = Foo(1)
> > print f1
> > f2 = Foo(2)
> > print f2
> > print f1
> >
> >
> > --
> > meskal:~/Projects/CameraCalibrator deets$ python2.4 /tmp/test.py
> > FOO: 1
> > BAR: [1]
> >
> > FOO: 2
> > BAR: [1, 2]
> >
> > FOO: 1
> > BAR: [1, 2]
> >
> >
> > -
> >
> > As you can see, the list BAR is shared. And you can also see that
> > _assigning_ to something like this:
> >
> > self.FOO
> >
> > will create an instance-variable. Even if a variable of the same name
> > existed on the class before!
> >
> > Which is precisely the difference between using variable initialization
> > in __init__ and inside the class-statement.
> >
> > BTW,
> >
> > self.__class__.FOO = value
> >
> > will set class-variables inside a method. Just if you wondered.
> > 
> > Diez

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


math.pow(x,y)

2006-06-11 Thread fl1p-fl0p
import math
math.pow(34564323, 456356)

will give math range error.

how can i force python to process huge integers without math range
error? Any modules i can use possibly?

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


Re: math.pow(x,y)

2006-06-11 Thread Felipe Almeida Lessa
Em Dom, 2006-06-11 às 11:19 -0700, fl1p-fl0p escreveu:
> import math
> math.pow(34564323, 456356)
> 
> will give math range error.
> 
> how can i force python to process huge integers without math range
> error? Any modules i can use possibly?

34564323**456356 ?

-- 
Felipe.

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

Re: math.pow(x,y)

2006-06-11 Thread Wojciech Muła
fl1p-fl0p wrote:
> import math
> math.pow(34564323, 456356)
>
> will give math range error.
>
> how can i force python to process huge integers without math range
> error? Any modules i can use possibly?

You have to use operator **, i.e. 34564323**456356
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> At first, I thought that self.jerk was resolving to the class attribute
> instead of creating a new variable (w/ a differing scope).

When you access an instance attribute, Python first looks in the 
instance object, and then in the class object.

When you assign to an instance attribute, it's *always* assigned to the 
instance object, whether there's a class attribute with the same name or 
not.

If there's already a class attribute with the same name, that attribute 
will be shadowed (but can still be accessed via the class object, of 
course).

> It doesn't work this way on my laptop...

Python's always worked that way, so I find that a bit hard to believe.



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


Re: math.pow(x,y)

2006-06-11 Thread Gary Herron
Wojciech Muła wrote:
> fl1p-fl0p wrote:
>   
>> import math
>> math.pow(34564323, 456356)
>>
>> will give math range error.
>>
>> how can i force python to process huge integers without math range
>> error? Any modules i can use possibly?
>> 
>
> You have to use operator **, i.e. 34564323**456356
>   
That's not very practical. That computation will produce a value with
more than 3.4 million digits. (That is, log10(34564323)*456356 =
3440298.) Python will attempt this, but I was not patient enough to see
if it could calculate an answer today (or even this week).

I doubt that you really *want* all 3.4 million digits. So what is it you
really want? A scientific or engineering result as a floating point
number accurate to some reasonable number of digits? That integer value
modulo some other integer (as used in various cryptology schemes)?

Gary Herron

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

Re: math.pow(x,y)

2006-06-11 Thread Raymond L. Buvel
Felipe Almeida Lessa wrote:
> Em Dom, 2006-06-11 às 11:19 -0700, fl1p-fl0p escreveu:
>> import math
>> math.pow(34564323, 456356)
>>
>> will give math range error.
>>
>> how can i force python to process huge integers without math range
>> error? Any modules i can use possibly?
> 
> 34564323**456356 ?
> 

I just tried this and it is taking an extremely long time even on a fast
machine with 4 Gb of RAM.  Killed it after a couple of minutes.  This
sort of calculation can be done with extended precision floating point
(as long as you don't need an exact answer).  For example (using
defaults on a 64-bit machine),

>>> from clnum import mpf
>>> mpf(34564323)**456356
mpf('1.39518106833639480699862472257296396643e3440298',36)

compute time is about 160 microseconds.

For more information see

http://calcrpnpy.sourceforge.net/clnumManual.html

For calculations involving large powers, you may still be better off
using logarithms.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: math.pow(x,y)

2006-06-11 Thread K.S.Sreeram
Raymond L. Buvel wrote:
> I just tried this and it is taking an extremely long time even on a fast
> machine with 4 Gb of RAM.  Killed it after a couple of minutes.

Thats odd.
34564323**456356 completed on my laptop in 28 seconds.
[Python 2.4.3, Celeron-M 1.3GHz, WinXP], and max memory consumption
during the whole process was about 11megs.

What python version are you using?

Regards
Sreeram



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

wxPython: Keyboard events and TreeCtrl

2006-06-11 Thread Saketh
Hello, everyone.

I  am a writing an application that I want to make a stripped-down
framework of Leo for Cornell note-taking.  I have one TreeCtrl, a menu,
and a status bar. There are two classes currently - the Application
class and the Frame class. The Frame class contains all of the event
handling, such as OnAbout and OnExit.

I am trying to add keyboard shortcuts. When someone hits Ctrl-I, I want
a new node to be added at the bottom level - if you've ever used Leo,
you know what I am talking about. Like in Leo, when the new node is
created, I want the title to be highlighted so that you can type in the
title of the node.

For some reason, the way I am doing it is not working. It's probably
because OnKeyDown is not attached to anything, but I am not sure.
Anyway, here is what my OnKeyDown method looks like:

def OnKeyDown(self, e):
key = e.KeyCode()
controlDown = e.ControlDown()
altDown = e.AltDown()
elif (controlDown and key == WXK_I):
# I want the "Node Title" to be editable upon its creation
self.tree.AppendItem(root, 'Node Title')

Am I supposed to connect the method to the Frame somehow? Or does it
automatically get called when the user hits Ctrl-I, regardless of the
fact that no other methods call OnKeyDown?

Thank you for the assistance.

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


Re: math.pow(x,y)

2006-06-11 Thread K.S.Sreeram
Raymond L. Buvel wrote:
> I just tried this and it is taking an extremely long time even on a fast
> machine with 4 Gb of RAM.  Killed it after a couple of minutes.

You probably tried printing the value.

a = 34564323**456356 (takes just 28 seconds)
whereas
b = str(a) takes forever!

Regards
Sreeram



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

Re: math.pow(x,y)

2006-06-11 Thread Tim Peters
[Wojciech Muła]
>> You have to use operator **, i.e. 34564323**456356

Or the builtin pow() instead of math.pow().

[Gary Herron]
> That's not very practical. That computation will produce a value with
> more than 3.4 million digits.

Yes.

> (That is, log10(34564323)*456356 = 3440298.) Python will attempt this, but
> I was not patient enough to see if it could calculate an answer today (or even
> this week).

On my box it took less than 30 seconds to do

x = 34564323**456356

If you try to _display_ that as a decimal string, it will take
enormously longer.  Python uses a power-of-2 base internally, and
conversion to decimal takes time quadratic in the number of digits.
Doing y = hex(x) instead is very fast (small fraction of a second).

> I doubt that you really *want* all 3.4 million digits. So what is it you
> really want? A scientific or engineering result as a floating point
> number accurate to some reasonable number of digits? That integer value
> modulo some other integer (as used in various cryptology schemes)?

For example, if you only want the last 6 digits, pow(34564323, 456356,
100) returns 986961 in an eyeblink.
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get the length of a number

2006-06-11 Thread Stan Cook
Can anyone tell me how to get the length of a number.  I 
know len(string) will get the length of a string, but it 
doesn't like len(int).  I seem to remember something like %s 
string.  I tried to set a variable = to %s int, but that 
doesn't work.  Is there a function I've forgotten about to 
convert an integer to a string?

Regards

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


Re: Get my airlines boarding pass

2006-06-11 Thread KenAggie
I posted it on activestate already ... sorry. I would like for the
geniuses here to use it and improve upon it so here is the activestate
post URL:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496790

Enjoy.
  Ken

BartlebyScrivener wrote:
> >> SW air script
>
> Post it here, first, and these geniuses will improve it; then post it
> on ActiveState. Besides, if you post it here first, I can use it. That
> would be handy!
> 
> Thanks,
> 
> rpd

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


Re: how to get the length of a number

2006-06-11 Thread Fredrik Lundh
Stan Cook wrote:

> Is there a function I've forgotten about to convert an
 > integer to a string?

str(value)



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


Re: how to get the length of a number

2006-06-11 Thread Saketh

Stan Cook wrote:
> Can anyone tell me how to get the length of a number.  I
> know len(string) will get the length of a string, but it
> doesn't like len(int).  I seem to remember something like %s
> string.  I tried to set a variable = to %s int, but that
> doesn't work.  Is there a function I've forgotten about to
> convert an integer to a string?
>
> Regards
>
> Stan

Use str(int). Then use len(). For example, len(str(12345)) will give
you 5.

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


Re: how to get the length of a number

2006-06-11 Thread Felipe Almeida Lessa
Em Dom, 2006-06-11 às 20:10 +, Stan Cook escreveu:
> Can anyone tell me how to get the length of a number.  I 
> know len(string) will get the length of a string, but it 
> doesn't like len(int).  I seem to remember something like %s 
> string.  I tried to set a variable = to %s int, but that 
> doesn't work.  Is there a function I've forgotten about to 
> convert an integer to a string?

To convert an integer i to a string:

str(i)   or   "%s" % i


To see how many decimal digits it has:

import math
math.ceil(math.log(i, 10))

-- 
Felipe.

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

Re: how to get the length of a number

2006-06-11 Thread Stan Cook
Saketh wrote:
> Stan Cook wrote:
>> Can anyone tell me how to get the length of a number.  I
>> know len(string) will get the length of a string, but it
>> doesn't like len(int).  I seem to remember something like %s
>> string.  I tried to set a variable = to %s int, but that
>> doesn't work.  Is there a function I've forgotten about to
>> convert an integer to a string?
>>
>> Regards
>>
>> Stan
> 
> Use str(int). Then use len(). For example, len(str(12345)) will give
> you 5.
> 
A! How could I have forgotten that.  Boy is my face red :)

Thanks

I'll try to make my next question a more intelligent one.

Regards,

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


Re: how to get the length of a number

2006-06-11 Thread Felipe Almeida Lessa
Em Dom, 2006-06-11 às 13:17 -0700, Saketh escreveu:
> Stan Cook wrote:
> > Can anyone tell me how to get the length of a number.  I
> > know len(string) will get the length of a string, but it
> > doesn't like len(int).  I seem to remember something like %s
> > string.  I tried to set a variable = to %s int, but that
> > doesn't work.  Is there a function I've forgotten about to
> > convert an integer to a string?
> >
> > Regards
> >
> > Stan
> 
> Use str(int). Then use len(). For example, len(str(12345)) will give
> you 5.

$ python2.4 -mtimeit -s 'x=12345' 'len(str(x))' 100 loops, best of
3: 1.33 usec per loop
$ python2.4 -mtimeit -s 'x=12345;from math import ceil,log' 'ceil(log(x,
10))'
100 loops, best of 3: 1.54 usec per loop
$ python2.4 -mtimeit -s 'x=12345**123' 'len(str(x))' 1000 loops, best of
3: 209 usec per loop
$ python2.4 -mtimeit -s 'x=12345**123;from math import ceil,log'
'ceil(log(x, 10))'
100 loops, best of 3: 1.55 usec per loop
$ python2.4 -mtimeit -s 'x=12345**1234' 'len(str(x))' 100 loops, best of
3: 19.2 msec per loop
$ python2.4 -mtimeit -s 'x=12345**1234;from math import ceil,log'
'ceil(log(x, 10))'
100 loops, best of 3: 1.53 usec per loop


-- 
Felipe.

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

Re: Killing a thread

2006-06-11 Thread MacDonald
Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> >> it cannot be done in a portable way, so that's not very likely.
>
> >   def __run(self):
> > """Hacked run function, which installs the trace."""
> > sys.settrace(self.globaltrace)
> > self.__run_backup()
> > self.run = self.__run_backup
>
> I'm not sure using a non-portable API to run the code under a "custom
> debugger" qualifies as a "portable implementation", though...

Everything used is a part of the standard library, which is portable,
AFAICT. Could you say specifically what is non-portable?

> have you benchmarked this, btw?

It has some overhead, but it should only be used in situations where
one line will either return before the timeout or take far too long. E.
g. an eval() statement with code generated from user input should
return quickly for reasonable entries, but something like "9**9**9"
will trigger the timeout.

> 

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


Re: how to get the length of a number

2006-06-11 Thread Felipe Almeida Lessa
Em Dom, 2006-06-11 às 22:33 +0200, Sybren Stuvel escreveu:
> Felipe Almeida Lessa enlightened us with:
> > To see how many decimal digits it has:
> >
> > import math
> > math.ceil(math.log(i, 10))
> 
> That doesn't work properly.
> 
> >>> import math
> >>> math.ceil(math.log(1, 10))
> 4.0
> >>> math.ceil(math.log(10001, 10))
> 5.0
> 
> But "1" certainly has as much digits as "10001".

Hmmm, you're right.

math.floor(math.log(x, 10)) + 1

-- 
Felipe.

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

Re: Killing a thread

2006-06-11 Thread Fredrik Lundh
MacDonald wrote:

>> I'm not sure using a non-portable API to run the code under a "custom
>> debugger" qualifies as a "portable implementation", though...
> 
> Everything used is a part of the standard library, which is portable,
> AFAICT. Could you say specifically what is non-portable?

from the documentation:

 Note: The settrace() function is intended only for implementing
 debuggers, profilers, coverage tools and the like. Its behavior
 is part of the implementation platform, rather than part of the
 language definition, and thus may not be available in all Python
 implementations.



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


Re: how to get the length of a number

2006-06-11 Thread Claudio Grondi
Stan Cook wrote:
> Can anyone tell me how to get the length of a number.  I know 
> len(string) will get the length of a string, but it doesn't like 
> len(int).  I seem to remember something like %s string.  I tried to set 
> a variable = to %s int, but that doesn't work.  Is there a function I've 
> forgotten about to convert an integer to a string?
> 
> Regards
> 
> Stan

len('%s'%(1234567,)) gives   7
len('%s'%(1234**45,)) and len(str(1234**45))
give 140

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


Re: how to get the length of a number

2006-06-11 Thread Fredrik Lundh
Felipe Almeida Lessa wrote:

> Hmmm, you're right.
> 
> math.floor(math.log(x, 10)) + 1

x = 0





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


Re: Most elegant way to generate 3-char sequence

2006-06-11 Thread James Stroud
Fredrik Lundh wrote:
> James Stroud wrote:
> 
>> See the actual question:
>>
>>  >How would you construct a generator to acheive this?
> 
> 
> if you don't think the context provided by the subject line and the 
> sentence before the question is important, how come you're so sure what 
> "this" refers to ?
> 
> 
> 

I'm getting the feeling that "correct" answers have nothing to do with 
correctness (i.e. working code) but on some vague notion of "elegance". 
Please point me to the page where code elegance is precisely defined so 
that I may construct my answers appropriately. And yes, I am too lazy to 
google "code elegance".

James

-- 
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: learning python idioms

2006-06-11 Thread James Stroud
[EMAIL PROTECTED] wrote:
> After several years developing in Java, I've begun to switch to Python
> for several of my new projects as I have found the language quite
> interesting.  I've read several tutorials and implemented a few sample
> programs and I've found that Python enables one to program in a variety
> of different styles (I'm not sure if this was the original intention or
> not).  Thus, I find myself occaisionally slipping into the "Java"
> mindset when writing Python code and I wonder if this is not optimal.
> Python is not Java and there must be more "correct" ways of doing this
> in Python that simply writing Java code with different syntax.  Is
> there a good reference on the internet about Python-specific idioms and
> just good Python style in general.  Which language constructs are
> efficient and which aren't?
> 
> Thanks in advance,
> Ben
> 

As an experiment, I googled 'python idioms' and got a few good hits 
right at the top. I probably should have done this a long time ago.

James








-- 
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: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread digitalorganics

Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > At first, I thought that self.jerk was resolving to the class attribute
> > instead of creating a new variable (w/ a differing scope).
>
> When you access an instance attribute, Python first looks in the
> instance object, and then in the class object.
>
> When you assign to an instance attribute, it's *always* assigned to the
> instance object, whether there's a class attribute with the same name or
> not.
>
> If there's already a class attribute with the same name, that attribute
> will be shadowed (but can still be accessed via the class object, of
> course).
>
> > It doesn't work this way on my laptop...
>
> Python's always worked that way, so I find that a bit hard to believe.
>

No need to be obnoxious. I do appreciate your efforts to help, but you
must admit, your last statement is a bit snide and certainly not
useful. I'm telling you that the code runs differently on my laptop.
Why this is, I don't know any more /or/ less than you do apparently.
Now, it is of course possible that I'm interpreting the results
incorrectly, but that doesn't change the fact that I'm getting
different results per computer with identical code.

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


Re: math.pow(x,y)

2006-06-11 Thread Raymond L. Buvel
K.S.Sreeram wrote:
> Raymond L. Buvel wrote:
>> I just tried this and it is taking an extremely long time even on a fast
>> machine with 4 Gb of RAM.  Killed it after a couple of minutes.
> 
> Thats odd.
> 34564323**456356 completed on my laptop in 28 seconds.
> [Python 2.4.3, Celeron-M 1.3GHz, WinXP], and max memory consumption
> during the whole process was about 11megs.
> 
> What python version are you using?
> 
> Regards
> Sreeram
> 

Sorry, I tripped over the display problem that Tim Peters has repeatedly
explained on this news group (decimal algorithm is quadratic in the
number of digits)  :-(

On a 64-bit 2.2 GHz Opteron running Debian stable, Python 2.3 took 26
seconds and Python 2.4 took 11 seconds.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Most elegant way to generate 3-char sequence

2006-06-11 Thread sam
I have found that the more elegant the code is, the harder it is for me
to understand what it is trying to accomplish. It is my opinion that
"Keep It Simple" wins over elegance. When I have had the urge to get
elegant, I make sure I comment the elegance so my less elegant
co-workers can figure out what I was trying to accomplish.

Sam Schulenburg


James Stroud wrote:
> Fredrik Lundh wrote:
> > James Stroud wrote:
> >
> >> See the actual question:
> >>
> >>  >How would you construct a generator to acheive this?
> >
> >
> > if you don't think the context provided by the subject line and the
> > sentence before the question is important, how come you're so sure what
> > "this" refers to ?
> >
> > 
> >
>
> I'm getting the feeling that "correct" answers have nothing to do with
> correctness (i.e. working code) but on some vague notion of "elegance".
> Please point me to the page where code elegance is precisely defined so
> that I may construct my answers appropriately. And yes, I am too lazy to
> google "code elegance".
>
> James
>
> --
> 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: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread digitalorganics
Thank you Dennis, this makes the behavior so much clearer to me. I see
now that when  self.jerk = self.jerk + 1 is executed that even though
the names are identical, at this point I'm referring to two different
values (one which is being created in part from the other).

As for my laptop, I'm not really sure what's up there. I can change the
class variable self.jerk all I want but it has no influence over the
instance variable.  Here's the code:

class Boo:
jerk = 10

def killjerk(self):
self.jerk += 1
print self.jerk
print self.__class__.jerk

bing = Boo()
bing.killjerk()

On my desktop, I get:

11
10

On my laptop, I get:

1
10

Now, if I remove the class variable, I get an AttributeError, as you'd
expect. This happens on both the desktop and laptop. However, on the
laptop it seems not to care what value I give the class variable jerk,
it only requires that it exist. Any clue what's behind this behavior?
I'm running the same python version on both computers (the ActiveState
distro).

Thanks for all the help...


Dennis Lee Bieber wrote:
> On 11 Jun 2006 10:35:14 -0700, [EMAIL PROTECTED] declaimed the
> following in comp.lang.python:
>
> > Wait a minute! It doesn't explain my bugs. I've got "class variables"
> > acting like instance variables. What's weirder is that this behavior
> > occurs on my computer (in both of my installed WinXP copies) but not on
> > my laptop (WinXP Pro).
> >
>   Don't know about the laptop but...
>
> > See the following test:
> >
>   See the following modified version:
>
> -=-=-=-=-=-=-
> class Boo:
> jerk = "yes"
>
> def killjerk(self):
> print id(self.jerk), id(self.__class__.jerk)
> self.jerk = self.jerk + "no"
> print self.jerk, id(self.jerk)
> print self.__class__.jerk
>
> bing = Boo()
> bing.killjerk()
> bing.killjerk()
> -=-=-=-=-=-=-=-
> 10837696 10837696
> yesno 18264128
> yes
> 18264128 10837696
> yesnono 18289600
> yes
>
>   The initial lookup for "self.jerk" does not find it in the instance,
> so it looks higher, into the class.
>
>   THEN when you "assign" the result to "self.jerk" you create an
> instance specific name entry, which is bound to a string at a different
> location. The lookup on the left side does not go outside of the
> instance. Notice how the second "bing.killjerk()" results in "self.jerk"
> being bound to a third address.
>
> --
>   WulfraedDennis Lee Bieber   KD6MOG
>   [EMAIL PROTECTED]   [EMAIL PROTECTED]
>   HTTP://wlfraed.home.netcom.com/
>   (Bestiaria Support Staff:   [EMAIL PROTECTED])
>   HTTP://www.bestiaria.com/

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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Any clue what's behind this behavior?

a missing plus sign.



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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread Fredrik Lundh
Fredrik Lundh wrote:

> a missing plus sign.

or a misplaced one... (=+ 1 is not the same thing as += 1)



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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread digitalorganics

Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > Any clue what's behind this behavior?
>
> a missing plus sign.
>
> 

Thanks for the guess but not possible given the following:

class Boo:
jerk = 10

def killjerk(self):
counter = 3
while counter !=0:
counter -= 1
self.jerk += 1
print self.jerk
print self.__class__.jerk


bing = Boo()
bing.killjerk()

Output from desktop comp.:
11
10
12
10
13
10

Output from laptop comp.:

1
10
2
10
3
10

?? . . .

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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread Diez B. Roggisch
> No need to be obnoxious. I do appreciate your efforts to help, but you
> must admit, your last statement is a bit snide and certainly not
> useful.
 > I'm telling you that the code runs differently on my laptop.

It certainly doesn't. There is absolutely no imaginable way how this 
behavior could be different, even if the python versions would differ 
considerably. Apart from quantum-fluctuations. Or other SciFi voodoo.

> Why this is, I don't know any more /or/ less than you do apparently.

Frederik (as one of the most profiled python developers out there) might 
not be the most amicable of posters, but he certainly is not wrong when 
it comes to the most basic parts of python's semantics.

> Now, it is of course possible that I'm interpreting the results
> incorrectly, but that doesn't change the fact that I'm getting
> different results per computer with identical code.

It is NOT identical code, otherwise you won't see different
results. It might be code from which you _believe_ it is identical, and 
the difference might be subtle to see. But if you'd store it in a file, 
execute on your laptop, use an usb-stick and then transfer it to 
whatever the other machine of yours is, it will yield the exact same 
results.

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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Output from laptop comp.:
> 
> 1
> 10
> 2
> 10
> 3
> 10

so how are you entering and running the code on your laptop ?

what happens if you set the class attribute to 100 instead of 10 ?



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


Re: Xah Lee network abuse

2006-06-11 Thread George Neuner
On Sun, 11 Jun 2006 06:05:22 GMT, "Mike Schilling"
<[EMAIL PROTECTED]> wrote:

>
>"Philippa Cowderoy" <[EMAIL PROTECTED]> wrote in message 
>news:[EMAIL PROTECTED]
>> On Sun, 11 Jun 2006, Mike Schilling wrote:
>>
>>> I'm not aware of any definition of libel that includes "making statements
>>> that are not provably true".
>>
>> I believe UK law uses one that's close to it.
>
>If I were to write, say, that Tony Blair's tax policy will lead to higher 
>deficits, I could be convicted of libel?  Even if that's true, it's not a 
>priori provable. 

DISCLAIMER - I AM NOT A LAWYER

In the US, the defense against a libel claim is to prove the statement
or accusation is true.

In the US, libel involves damage to someone's reputation by means of
deliberately false statements or accusations.  Expert opinion is
explicitly protected from libel claims unless it malicious.
Non-expert opinion is generally judged on the intent of the author.
Unprovable supposition is generally held to be non-libelous, however
unprovable accusation is not allowed.

Moreover, in the US, political figures are explicitly denied some (but
not all) libel protections because it is expected that their actions
will cause some measure of public dissent.

I don't know UK defamation law but I suspect it is quite similar to US
law.  In your polite example, your opinion of Tony Blair's policy
would be unprovable supposition at the time of the writing (as would
Blair's own) and would therefore not be libelous.  However, if your
opinion took an accusatory tone saying, for example, that he was
increasing the public deficit to line his pockets, then you had better
be right.

George
--
for email reply remove "/" from address
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get my airlines boarding pass

2006-06-11 Thread Jonathan Ellis
KenAggie wrote:
> I posted it on activestate already ... sorry. I would like for the
> geniuses here to use it and improve upon it so here is the activestate
> post URL:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496790

Whoa.  Check out BeautifulSoup -- you will never write HTMLParser-based
screen scrapers again. :)

-Jonathan

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


Re: math.pow(x,y)

2006-06-11 Thread casevh

K.S.Sreeram wrote:
> Raymond L. Buvel wrote:
> > I just tried this and it is taking an extremely long time even on a fast
> > machine with 4 Gb of RAM.  Killed it after a couple of minutes.
>
> You probably tried printing the value.
>
> a = 34564323**456356 (takes just 28 seconds)
> whereas
> b = str(a) takes forever!
>
> Regards
> Sreeram
>

If you really want all 3,440,299 digits, use the DecInt module..

http://home.comcast.net/~casevh/

Using Python 2.4.3 on a 1.4Ghz Celeron, a=DecInt(34564323) ** 456356
takes 20 seconds. astr=str(a) takes just over 1 second.

With DecInt and GMPY, the running times are 6.9 seconds and 0.4 seconds
respectively.

casevh

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


@func call syntax

2006-06-11 Thread teekaysoh
Hi,

I am new to Python, here I'd like to have a question: I noticed a
special way to call a function in a program:

@function_name

No argv is passed, even though the function_name asks for one. Any idea
what this @something syntax is trying to achieve. I haven't been able
to find any answer of on the google web and groups.

TIA.

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


Re: Xah Lee network abuse

2006-06-11 Thread Robert Hicks

Erik Max Francis wrote:
> Mallor wrote:
>
> > I know I'm coming late to the barbeque.  In passing, I ask: do you have
> > an objective, impartial perspective on the subject of committing
> > crimes?  Because libel is a crime.
>
> No, it is a tort.
> 
Can I have whipped cream and strawberries on that tort?

:Robert

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


Re: @func call syntax

2006-06-11 Thread casevh

[EMAIL PROTECTED] wrote:
> Hi,
>
> I am new to Python, here I'd like to have a question: I noticed a
> special way to call a function in a program:
>
> @function_name
>
> No argv is passed, even though the function_name asks for one. Any idea
> what this @something syntax is trying to achieve. I haven't been able
> to find any answer of on the google web and groups.
>
> TIA.

@function_name is called a decorator.

http://www.python.org/dev/peps/pep-0318/

http://docs.python.org/whatsnew/node6.html

casevh

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


Z39.50 and tyrannioware website seems to be down

2006-06-11 Thread bussiere
Title: Z39.50 and tyrannioware website seems to be down






sorry to disturb you but from here :
http://lists.indexdata.dk/pipermail/zoom/2005-October/000806.html

if yes i cannot take this three files : 

asn1.py
z3950_2001.py
zdefs.py

the website seems to be down :
http://cvs.sourceforge.net/viewcvs.py/tyrannioware/

may i ask you if  someone always have these three files and if someone  can mail me them , then ?

Regards

Bussiere


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

Re: @func call syntax

2006-06-11 Thread Schüle Daniel
this is decorator, this is how it's may be implented

 >>> def returns(t):
... def dec(f):
... def wrapped(*args, **kwargs):
... ret = f(*args, **kwargs)
... assert type(ret) is t
... return ret
... return wrapped
... return dec
...
 >>>
 >>> @returns(int)
... def f1():
... return 1
...
 >>> @returns(float)
... def f2():
... return 2.0
...
 >>> @returns(str)
... def f3():
... return 1
...
 >>> f1()
1
 >>> f2()
2.0
 >>> f3()
Traceback (most recent call last):
   File "", line 1, in ?
   File "", line 5, in wrapped
AssertionError
 >>>


I can imagine that stuff like this may be extremely usefull
when testing you program
later one could parse and remove all such assertations
easy and cut them all at once

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


Re: Thread specific singleton

2006-06-11 Thread Aahz
In article <[EMAIL PROTECTED]>,
Gabriele Farina  <[EMAIL PROTECTED]> wrote:
>
>I'm tring to implement a Singleton object that should be specific for 
>every thread who create it, not global.
>I tried a solution that seems to work, but I have a very poor knowledge 
>of concurrent programming, so I'd like someone to help me find some 
>problems in my implementation.

Try using threading.local(), but you'll need 2.4 or later.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there."  --Steve Gonedes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyQt v4.0 Released - Python Bindings for Qt v4

2006-06-11 Thread Butternut Squash
Phil Thompson wrote:

> Riverbank Computing is pleased to announce the release of PyQt v4.0
> available from http://www.riverbankcomputing.co.uk/pyqt/.
> 
> The main change from v4.0beta1 is the inclusion of comprehensive HTML
> documentation based on the Qt documentation.
> 
> PyQt is a comprehensive set of Qt bindings for the Python programming
> language
> and supports the same platforms as Qt (Windows, Linux and MacOS/X).  Like
> Qt, PyQt is available under the GPL and a commercial license.
> 
> PyQt v4 supports Qt v4 (http://www.trolltech.com/products/qt/index.html).
> PyQt v3 is still available to support earlier versions of Qt.
> 
> PyQt v4 is implemented as a set of 8 extension modules containing
> approximately 400 classes and 6,000 functions and methods.
> 
> QtCore
> The non-GUI infrastructure including event loops, threads, i18n,
> Unicode, signals and slots, user and application settings.
> 
> QtGui
> A rich collection of GUI widgets.
> 
> QtNetwork
> A set of classes to support TCP and UDP socket programming and higher
> level protocols (eg. HTTP).
> 
> QtOpenGL
> A set of classes that allows PyOpenGL to render onto Qt widgets.
> 
> QtSql
> A set of classes that implement SQL data models and interfaces to
> industry
> standard databases.  Includes an implementation of SQLite.
> 
> QtSvg
> A set of classes to render SVG files onto Qt widgets.
> 
> QtXML
> A set of classes that implement DOM and SAX parsers.
> 
> QtAssistant
> A set of classes that enables the Qt Assistant online help browser to
> be integrated with an application.
> 
> A Windows installer is provided for the GPL version of PyQt to be used
> with the GPL version of Qt v4
> (http://www.trolltech.com/download/qt/windows.html). It enabes a complete
> PyQt environment to be installed on Windows without the need for a C++
> compiler.
> 
> PyQt includes the pyuic utility which generates Python code to implement
> user interfaces created with Qt Designer in the same way that the uic
> utility
> generates C++ code.  It is also able to load Designer XML files
> dynamically.

Where is the best place to learn how to use this library???

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


Screen Scraping for Modern Applications?

2006-06-11 Thread ljr2600
Hello,

I'm very new to python and still familiarizing myself with the
language, sorry if the post seems moronic or simple.

For a side project I'm working on I need to be able to scrape a modern
computer desktop. Is there any basic material already available to do
this? I'd rather not need to write my own to interact with hardware.

Thanks!

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


Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function

2006-06-11 Thread ycoci0
Hi all,

Not exactly new to Python, just have not programmed a time dependent
function using it before.

I imagine that many of you may also program some JavaScript and may be
familiar with JavaScript's SetTimeout( expression, after time interval
in milliseconds) function.  Does Python have an equivalent to this?

A SetTimeout-like Python function would be ideal for my application.


Best,

Y-coci

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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread digitalorganics
Oh wow, I wasn't expecting so much help. I really appreciate it. My
problem, however, has been solved. I uninstalled my ActiveState Python
distro on my laptop and installed the distro from python.org along with
Stan's Python Editor. I ran the same code I'd run before and guess
what? The behavior now matches that of my desktop! Why? *shrug*

As for the code being identical, it certainly was as I emailed the .py
file to myself (from the laptop) and downloaded it to my desktop where
I then ran it just as I had done on the laptop, with PythonWin. Unless
Google programmed Gmail to muck w/ people's python code
Additionally, the bytes on the files match. Thus, I feel I can
guarantee that the code is indeed identical.

Here's my wild guess: for some reason a bug in PythonWin was causing my
changes to the class attribute (i.e. jerk variable) not to be reflected
in the actual code. This explanation, if you can call it one, still
doesn't make sense to me however because I could make other changes to
the code and it would indeed be reflected in execution. Add to the fact
that PythonWin is essentially just a text editor, I don't see how/why
it would selectively save code changes.

It is true that I never restarted the PythonWin IDE after a change of
the class attribute to something other than 0, and perhaps reinstalling
python etc. was unnecessary. I'm only coming to this realization now.

In any event, I am now problem free and quite pleased to be able to
exchange .py files between computers and know they'll behave the same
(rather, I'm assuming this henceforth).

Furthermore, I'd like to thank everyone who tried to help, and that
certainly includes Fredrik.


Cheers,

DigiO

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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread digitalorganics

Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > Output from laptop comp.:
> >
> > 1
> > 10
> > 2
> > 10
> > 3
> > 10
>
> so how are you entering and running the code on your laptop ?
>
> what happens if you set the class attribute to 100 instead of 10 ?
>
> 

You can see my other post which I just sent but, I was using PythonWin:

1. type code in editor
2. hit run
3. observe output in interactive window

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


Re: direct initialization of class attributes vs. declarations w/in __init__

2006-06-11 Thread digitalorganics

Diez B. Roggisch wrote:
> > No need to be obnoxious. I do appreciate your efforts to help, but you
> > must admit, your last statement is a bit snide and certainly not
> > useful.
>  > I'm telling you that the code runs differently on my laptop.
>
> It certainly doesn't. There is absolutely no imaginable way how this
> behavior could be different, even if the python versions would differ
> considerably. Apart from quantum-fluctuations. Or other SciFi voodoo.

Hmmm

>
> > Why this is, I don't know any more /or/ less than you do apparently.
>
> Frederik (as one of the most profiled python developers out there) might
> not be the most amicable of posters,

Although he dropped what I perceived to be a snide and unhelpful
comment, two things. One, I understand what's behind it in the sense
that the behavior I was describing goes against the semantic
fundamentals of python, and should therefore be impossible. Two,
Fredrik is no doubt a sweetheart and he showed it by continuing to put
his efforts toward helping me despite my criticism of him. I can't
thank him enough. Honestly, I believe newsgroups need more people like
him . . .


> ...
>
> It is NOT identical code, otherwise you won't see different
> results. It might be code from which you _believe_ it is identical, and
> the difference might be subtle to see. But if you'd store it in a file,
> execute on your laptop, use an usb-stick and then transfer it to
> whatever the other machine of yours is, it will yield the exact same
> results.
>
> Diez

Read my other post. The code was/is definitely identical. In any event,
I don't really care. It's working properly now, and if I have similarly
weird problems in future, I'll deal with them at that time. I don't
know what was up, but I understand it doesn't make sense from any
visible standpoint of logic. Thank you for your efforts Diez...

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


Re: Get my airlines boarding pass

2006-06-11 Thread KenAggie
Okay, so too bad I didn't know about this before I wrote the 75 lines
of code based on HTMLParser. That said, it still wasn't that hard and
most of all it is done and it works so I won't be rewriting it. I did
check it out and it seems quite powerful. I'll add it to my library of
tools to use for the next python project. Thanks for the tip.
  - Ken

Jonathan Ellis wrote:
> KenAggie wrote:
> > I posted it on activestate already ... sorry. I would like for the
> > geniuses here to use it and improve upon it so here is the activestate
> > post URL:
> >
> > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496790
>
> Whoa.  Check out BeautifulSoup -- you will never write HTMLParser-based
> screen scrapers again. :)
> 
> -Jonathan

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


Re: Screen Scraping for Modern Applications?

2006-06-11 Thread KenAggie
I just learned about a python library called BeautifulSoup in a thread
responding to my Southwest Airlines script that I wrote and posted on
the Python cookbook web site. I wrote my script using the provided
HTMLParser class. BeautifulSoup could have saved me some time perhaps.
Take a look. Feel free to browse my code for an example of how to use
HTMLParser for a moderately involved project.

BeautifulSoup link:
http://www.crummy.com/software/BeautifulSoup/

My Southwest Boarding pass script link:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496790

Enjoy.
 - Ken


[EMAIL PROTECTED] wrote:
> Hello,
>
> I'm very new to python and still familiarizing myself with the
> language, sorry if the post seems moronic or simple.
>
> For a side project I'm working on I need to be able to scrape a modern
> computer desktop. Is there any basic material already available to do
> this? I'd rather not need to write my own to interact with hardware.
> 
> Thanks!

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


Re: Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function

2006-06-11 Thread KenAggie
Yea -- the "sched" class is exactly what you need. Just import sched
and then use it to schedule a function call in the future, either using
relative time or an absolute time. The python help file tells you how
in detail.
  - Ken

[EMAIL PROTECTED] wrote:
> Hi all,
>
> Not exactly new to Python, just have not programmed a time dependent
> function using it before.
>
> I imagine that many of you may also program some JavaScript and may be
> familiar with JavaScript's SetTimeout( expression, after time interval
> in milliseconds) function.  Does Python have an equivalent to this?
>
> A SetTimeout-like Python function would be ideal for my application.
> 
> 
> Best,
> 
> Y-coci

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


Re: Screen Scraping for Modern Applications?

2006-06-11 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
.
.
.
>For a side project I'm working on I need to be able to scrape a modern
>computer desktop. Is there any basic material already available to do
>this? I'd rather not need to write my own to interact with hardware.
.
.
.
Oh, no.

Very hard.  Very, very hard.

At least as you've expressed it here, this is an exceptionally
difficult task.  What does "scrape" mean to you?  Do you want
to reproduce the display remotely, or extract text, or some other
possibility?  Does "modern computer" mean Windows to you?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the length of a number

2006-06-11 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Felipe Almeida Lessa  <[EMAIL PROTECTED]> wrote:
.
.
.
>math.floor(math.log(x, 10)) + 1
>
>-- 
>Felipe.
>

... and you're restricting to the positive integers, I take it?
I still have rounding problems:
  >>> def l(x):
  ... return math.floor(math.log(x, 10)) + 1
  ... 
  >>> l(10)
  2.0
  >>> l(100)
  3.0
  >>> l(1000)
  3.0
  >>> l(1)
  5.0
  >>> l(10)
  6.0
  >>> l(100)
  6.0
  >>> l(1000)
  8.0

While modest mollification improves these results, it's going
to be tough to beat len(str(x)).
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >