Re: Augument assignment versus regular assignment

2006-07-08 Thread Kirk McDonald
Frank Millman wrote:
> nagy wrote:
> 
>>Thanks, Kirk.
>>I considered the += as only a shorthand notation for the assignment
>>operator.
>>Since for lists + is simply a concatetation, I am not sure it x=x+[2]
>>is creating a brand
>>new list. Could you refer me to any documentation on this?
>>Thanks,
>>Nagy
> 
> 
> My habit is to check the id.
> 
> 
x = [1,2]
id(x)
> 
> -1209327188
> 
x += [4]
x
> 
> [1,2,4]
> 
id(x)
> 
> -1209327188
> 
x = x + [6]
x
> 
> [1,2,4,6]
> 
id(x)
> 
> -1209334664
> 
> So it looks as if x +=  [] modifies the list in place, while x = x + []
> creates a new list.
> 
> I am not sure if this is 100% guaranteed,

It is. This is true for any mutable type.

> as I have noticed in the past
> that id's can be reused under certain circumstances. Perhaps one of the
> resident gurus can comment.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: first book about python

2006-07-08 Thread Vittorio
I read almost every published book about Python and I found Magnus'
"Beginning Python" the best book to start with. As Alex said it is
particularly appreciated by those who like learning by examples and by "try
and error": it is actually the opposite to what Alex believed as "Beginning
Python" is meant to be a sort of update of the previous book "Practical
Python".

In addition and maybe before of Magnus book I would suggest "A byte of
Python" http://www.byteofpython.info/ the best fast introduction to Python I
have ever seen.

"Alex Martelli" <[EMAIL PROTECTED]> ha scritto nel messaggio
news:[EMAIL PROTECTED]
> Jake Emerson <[EMAIL PROTECTED]> wrote:
>
> > There have been lots of recommendations for the O'Reilly book, which is
> > a good one. However, I would recommend "Beginning Python" by Magnus Lie
> > Hetland. All I knew before starting Python was Mathematica, and this
> > book was very helpful. It may seem to start out slow, but I've found
> > that I'm going back to those first chapters occasionally to review and
> > practice the syntax. It, and this group, have carried me through some
> > pretty tough problems (for me anyway). It's been worth it. Good luck.
>
> Hetland's books are excellent, particularly if you like to learn by
> example -- I believe the current one "Practical Python" is meant to
> supersede the earlier "Beginning Python" (but I'm not sure).
>
>
> Alex


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


Re: Python *Eggs* on Win32

2006-07-08 Thread Srijit Kumar Bhadra
I got the answers myself. Thanks to http://tinyurl.com/ld2c9. With just
basic installation of Python on Win32 (i.e.
http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi) it is possible
to install .egg files (Python Eggs).

1) download http://peak.telecommunity.com/dist/ez_setup.py
2) run ez_setup.py
3) download
http://cheeseshop.python.org/packages/2.4/l/lxml/lxml-1.1alpha-py2.4-static-win32.egg
4) In dos command line go to the same directory where
lxml-1.1alpha-py2.4-static-win32.egg has been downloaded
5) From dos command line type
d:\python24\scripts\easy_install lxml-1.1alpha.win32-static-py2.4.exe

That's all. But Note:
a) for running ez_setup.py (which is a bootstrap module) unrestricted
Internet connection is necessary.

http://peak.telecommunity.com/DevCenter/EasyInstall?action=highlight&value=EasyInstall
has all the answers.

I am still not sure:
a) Whether it is always sufficient to have only MinGW GCC installation
on my Win XP machine and not MS Visual Studio.

Best Regards,
Srijit

Srijit Kumar Bhadra wrote:
> I have browsed the following links
> 1) http://peak.telecommunity.com/DevCenter/EasyInstall
> 2) When Python *Eggs* better than Python *distutils*?? What's Eggs?
> (http://tinyurl.com/m8dyd)
>
> But I am still not clear what to do with an .egg file. For example, if
> I have a basic Python installation
> (http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi) what should I
> do with a typical .egg file (e.g.
> http://cheeseshop.python.org/packages/2.4/l/lxml/lxml-1.1alpha-py2.4-static-win32.egg)?
>
> I have only MinGW GCC compiler on my Win XP machine. Is it mandatory to
> have Internet connection during installation of .egg files?
> 
> Best Regards,
> Srijit

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


Re: Augument assignment versus regular assignment

2006-07-08 Thread Frank Millman

nagy wrote:
> Thanks, Kirk.
> I considered the += as only a shorthand notation for the assignment
> operator.
> Since for lists + is simply a concatetation, I am not sure it x=x+[2]
> is creating a brand
> new list. Could you refer me to any documentation on this?
> Thanks,
> Nagy

My habit is to check the id.

>>> x = [1,2]
>>> id(x)
-1209327188
>>> x += [4]
>>> x
[1,2,4]
>>> id(x)
-1209327188
>>> x = x + [6]
>>> x
[1,2,4,6]
>>> id(x)
-1209334664

So it looks as if x +=  [] modifies the list in place, while x = x + []
creates a new list.

I am not sure if this is 100% guaranteed, as I have noticed in the past
that id's can be reused under certain circumstances. Perhaps one of the
resident gurus can comment.

Frank Millman

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


Re: Inheritance error: class Foo has no attribute "bar"

2006-07-08 Thread Simon Forman
crystalattice wrote:
> I've finally figured out the basics of OOP; I've created a basic character
> creation class for my game and it works reasonably well. Now that I'm
> trying to build a subclass that has methods to determine the rank of a
> character but I keep getting errors.
>
> I want to "redefine" some attributes from the base class so I can use them
> to help determine the rank. However, I get the error that my base class
> doesn't have the dictionary that I want to use. I've tried several things
> to correct it but they don't work (the base class is called "Character"
> and the subclass is called "Marine"):
>
> *explicitly naming the Marine's attribute self.intel =
> Character.attrib_dict["intel"]
> *adding Character.__init__(self) to the Marine's __init__(self) method
> *changing the self.intel attribute from referencing the Character's
> dictionary to self (based on the assumption that since Marine is a
>   subset of Character, it should have it's own attrib_dict being 
> created
>
> Nothing seems to work; I still get the error "class Character has no
> attribute "attrib_dict".
>
> I can't see why it's saying this because Character.__init__(self) not only
> has self.attrib_dict = {} but it also calls the setAttribute method
> explicitly for each attribute name. If I do a print out of the dictionary
> just for Character, the attributes are listed.
>

Without a sample of your code and the actual tracebacks you're getting
it is difficult to know what's going wrong.


Are you writing your class like this:

class Character:
def __init__(self):
# do some stuff here..

class Marine(Character):
def __init__(self):
Character.__init__(self)
# do some stuff here..

?


Peace,
~Simon

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


Re: Tkinter problem

2006-07-08 Thread Nick Craig-Wood
Simon Forman <[EMAIL PROTECTED]> wrote:
>  Just an idea, but if you're sure that
>  /usr/lib/python2.4/lib-dynload/_tkinter.so exists, check it's
>  permissions and the permissions of /usr/lib/python2.4/lib-dynload/

Also run ldd on it - you could be missing a library

eg

$ ldd /usr/lib/python2.4/lib-dynload/_tkinter.so
linux-gate.so.1 =>  (0xe000)
libBLT.2.4.so.8.4 => /usr/lib/libBLT.2.4.so.8.4 (0xb7e8)
libtk8.4.so.0 => /usr/lib/libtk8.4.so.0 (0xb7dab000)
libtcl8.4.so.0 => /usr/lib/libtcl8.4.so.0 (0xb7cfc000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0xb7c31000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7c1e000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7ae6000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7ac)
libnsl.so.1 => /lib/tls/i686/cmov/libnsl.so.1 (0xb7aa9000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7aa5000)
/lib/ld-linux.so.2 (0x8000)

If there are any missing things then you need to re-install those
packages.

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


How properly manage memory of this PyObject* array?? (C extension)

2006-07-08 Thread [EMAIL PROTECTED]
Suppose a C extension locally built an array of PyObject* 's as
follows...

my_array = malloc(n * sizeof(PyObject*));
for (i = 0; i < n; i++) {
   my_array[i] = PyList_New(0);
}

Q1: Must I do a Py_DECREF(my_array[i]) on all elements
  before exiting this C extension function? (What if
 the elements got used in other objects?)

Q2: Must I do free(my_array); at end of function??  What if
my_array[i]'s are
  used in other objects so that I can't necessarily just
  nuke it!!!

Chris

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


Python *eggs* on Win32

2006-07-08 Thread Srijit Kumar Bhadra
I have browsed the following links
1) http://peak.telecommunity.com/DevCenter/EasyInstall
2) When Python *Eggs* better than Python *distutils*?? What's Eggs?
(http://tinyurl.com/m8dyd)

But I am still not clear what to do with an .egg file. For example, if
I have a basic Python installation
(http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi) what should I
do with a typical .egg file (e.g.
http://cheeseshop.python.org/packages/2.4/l/lxml/lxml-1.1alpha-py2.4-static-win32.egg)?

I have only MinGW GCC compiler on my Win XP machine. Is it mandatory to
have Internet connection during installation of .egg files?

Best Regards,
Srijit

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


Fwd: please remove posting we are receiving unsolicited emails

2006-07-08 Thread homeprice maps


dear python ,
 
as a result of the following posting http://mail.python.org/pipermail/python-list/2006-January/318387.html
   as well as this posting
 
http://mail.python.org/pipermail/python-list/2006-January/318938.html
 
we are receiving emails from people regarding services and websites we have no relation to. 
 
please please have this posting removed asap.
 
thank you 
 
abe
-- 
http://mail.python.org/mailman/listinfo/python-list

xpath question...

2006-07-08 Thread bruce
hi...

i have the following section of test code where i'm trying to get the
attribute of a frame
   

i'm trying to print/get the src value. the xpath query that i have displays
the "src" attribute in the Xpather/Firefox plugin. however, i can't quite
figure out how to get the underlying value in my test app...

  sxpath = "/html/frameset/frame[2]/attribute::src"
# s contains HTML not XML text
  d = libxml2dom.parseString(s, html=1)

  #get the tr list
  tr1 = d.xpath(sxpath)

  url = tr1[0]

  #get the url/link >>semester page
  #link = br.find_link(nr=1)

  #url = link.url
  print "link = ",url
  sys.exit()

err output
link =  

--

i'm not sure what i need to add to the line
  url = tr1
to resolve the issue/error...

looking over google hasn't given any real pointers...


thanks

-bruce


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


Re: first book about python

2006-07-08 Thread Alex Martelli
Jake Emerson <[EMAIL PROTECTED]> wrote:

> There have been lots of recommendations for the O'Reilly book, which is
> a good one. However, I would recommend "Beginning Python" by Magnus Lie
> Hetland. All I knew before starting Python was Mathematica, and this
> book was very helpful. It may seem to start out slow, but I've found
> that I'm going back to those first chapters occasionally to review and
> practice the syntax. It, and this group, have carried me through some
> pretty tough problems (for me anyway). It's been worth it. Good luck.

Hetland's books are excellent, particularly if you like to learn by
example -- I believe the current one "Practical Python" is meant to
supersede the earlier "Beginning Python" (but I'm not sure).


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


Re: first book about python

2006-07-08 Thread Jake Emerson
There have been lots of recommendations for the O'Reilly book, which is
a good one. However, I would recommend "Beginning Python" by Magnus Lie
Hetland. All I knew before starting Python was Mathematica, and this
book was very helpful. It may seem to start out slow, but I've found
that I'm going back to those first chapters occasionally to review and
practice the syntax. It, and this group, have carried me through some
pretty tough problems (for me anyway). It's been worth it. Good luck.

Jake

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


Inheritance error: class Foo has no attribute "bar"

2006-07-08 Thread crystalattice
I've finally figured out the basics of OOP; I've created a basic character  
creation class for my game and it works reasonably well. Now that I'm  
trying to build a subclass that has methods to determine the rank of a  
character but I keep getting errors.

I want to "redefine" some attributes from the base class so I can use them  
to help determine the rank. However, I get the error that my base class  
doesn't have the dictionary that I want to use. I've tried several things  
to correct it but they don't work (the base class is called "Character"  
and the subclass is called "Marine"):

*explicitly naming the Marine's attribute self.intel =  
Character.attrib_dict["intel"]
*adding Character.__init__(self) to the Marine's __init__(self) method
*changing the self.intel attribute from referencing the Character's  
dictionary to self (based on the assumption that since Marine is a  
subset of Character, it should have it's own attrib_dict being 
created

Nothing seems to work; I still get the error "class Character has no  
attribute "attrib_dict".

I can't see why it's saying this because Character.__init__(self) not only  
has self.attrib_dict = {} but it also calls the setAttribute method  
explicitly for each attribute name. If I do a print out of the dictionary  
just for Character, the attributes are listed.

-- 
Python-based online RPG based on the Colonial Marines from "Aliens" -  
http://www.colonialmarinesrpg.com

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: first book about python

2006-07-08 Thread Paul Rubin
IOANNIS MANOLOUDIS <[EMAIL PROTECTED]> writes:
> I plan to buy a book. I always find printed material more convenient than
> reading on-line tutorials.

Why not print out the on-line tutorial and read the hardcopy?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wx Browser-objekt for python on Linux

2006-07-08 Thread Nigel Rowe
spooky wrote:

> Hey,
> 
>> Try looking at the wx.HtmlWindow demo
> 
> Thank you...I know wx.HtmlWindow but that object can not parse
> Javascript code :((
> 
> I need a cross-platform object that can parse js-scripts :(
> 
> Can someone help me??
> 
> Bye,
> 
> Spooky

http://wxmozilla.sourceforge.net/ exists to embed mozilla in wxwindows,
but I have no idea how well it does it, nor its current status.


-- 
Nigel Rowe
A pox upon the spammers that make me write my address like..
rho (snail) swiftdsl (stop) com (stop) au
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: first book about python

2006-07-08 Thread crystalattice
On Sat, 08 Jul 2006 14:41:52 -1000, IOANNIS MANOLOUDIS  
<[EMAIL PROTECTED]> wrote:

> I want to learn python.
> I plan to buy a book. I always find printed material more convenient than
> reading on-line tutorials.
> I don't know PERL or any other scripting language. I only know some BASH
> programming. I am looking for a book which will help me get started and
> should contain the foundations. I am not looking for the Python bible.
> Any recommendations?
> Ioannis
>
I started out w/ "Learning Python" from O'Reilly which is good for a nice,  
general overview of the language but I wanted something more detailed.  I  
found the "Python Learn to Program" textbook from Deitel & Deitel to be  
very good.  It's based on v2.2 but it still has practical use.  Since it's  
a text book it has many examples and small problems to try as you develop  
your skills.  If you can find it used online you should be able to get it  
<$40.


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: first book about python

2006-07-08 Thread BartlebyScrivener
>> I always find printed material more convenient than
>> reading on-line tutorials.

If you are sure you want a book and not online tutorials, then it's
important that you have many code examples which include both the
statements and the results. You may like Chris Fehily's Python Visual
Quickstart Guide for this.

http://www.amazon.com/exec/obidos/asin/0201748843/inscape-20/

It's long in the tooth (only covers up to 2.2 and doesn't get too much
into OO), but it features abundant examples running in columns right
alongside lucid explanations of how Python works.

rd

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


Re: first book about python

2006-07-08 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
IOANNIS MANOLOUDIS  <[EMAIL PROTECTED]> wrote:
>I want to learn python.
>I plan to buy a book. I always find printed material more convenient than
>reading on-line tutorials.
>I don't know PERL or any other scripting language. I only know some BASH
>programming. I am looking for a book which will help me get started and
>should contain the foundations. I am not looking for the Python bible.
>Any recommendations?
>Ioannis
>

http://groups.google.com/group/comp.lang.python/msg/3539b0fbd9c04db8

http://groups.google.com/groups?as_q=book+beginner&num=10&scoring=d&hl=en&as_ugroup=comp.lang.python*

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


Re: first book about python

2006-07-08 Thread tac-tics
Philippe Martin wrote:
> I don't know, if I were the genious that made up Python I would not believe
> in any bible (small b)

Take it to alt.religion please.

> I want to learn python.
> I plan to buy a book. I always find printed material more convenient than
> reading on-line tutorials.

I had the same problem as you. I heard lots of good things about
Python, but was unable to sit myself down in front of my computer long
enough to learn it. So I picked up a copy of Learning Python and read
the entire thing in a night.

http://www.amazon.com/gp/product/0596002815/ref=pd_bxgy_img_b/002-4705377-6120028?ie=UTF8

I'm sorry I can't really do a comparison between different books, this
being the only one I bought, but it got me to the point where I could
start playing with code and reading the online documentation (which is
superb).

Coming from a relatively strong background in Java and C++, this book
was very easy to digest. The book is not a "teaching programming" book,
so unless you have experience in at least one real language programming
language, it might not be worth your time.

My only complaint about this book is the confusing way it presenting
Python's OOP model and the way they present for loops (they make it
sound like for loops are 100 times slower than in Java or C++... They
don't get the actual point across effectively, that  they are just
different.)

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


Re: first book about python

2006-07-08 Thread gregarican
Try "Learning Python" which is part of the O'Reilly series of books
they publish on computer programming. It's a good start. Most public
library systems have copies you can check out, and most larger
bookstores have it. Otherwise there's always Amazon.Com. Welcome to
Python and enjoy!

IOANNIS MANOLOUDIS wrote:
> I want to learn python.
> I plan to buy a book. I always find printed material more convenient than
> reading on-line tutorials.
> I don't know PERL or any other scripting language. I only know some BASH
> programming. I am looking for a book which will help me get started and
> should contain the foundations. I am not looking for the Python bible.
> Any recommendations?
> Ioannis

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


Re: first book about python

2006-07-08 Thread Philippe Martin
I don't know, if I were the genious that made up Python I would not believe
in any bible (small b)





IOANNIS MANOLOUDIS wrote:

> I want to learn python.
> I plan to buy a book. I always find printed material more convenient than
> reading on-line tutorials.
> I don't know PERL or any other scripting language. I only know some BASH
> programming. I am looking for a book which will help me get started and
> should contain the foundations. I am not looking for the Python bible.
> Any recommendations?
> Ioannis

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


first book about python

2006-07-08 Thread IOANNIS MANOLOUDIS
I want to learn python.
I plan to buy a book. I always find printed material more convenient than
reading on-line tutorials.
I don't know PERL or any other scripting language. I only know some BASH
programming. I am looking for a book which will help me get started and
should contain the foundations. I am not looking for the Python bible.
Any recommendations?
Ioannis

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


Re: urllib2 on Windows Vista

2006-07-08 Thread Rune Strand

Sriram  Krishnan wrote:
> I'm running Python 2.4.3 on Windows Vista June CTP. I'm not able to
> open any site using the urllib2 and related family of modules

My wil guess is that it is a firewall problem. Perhaps you'll have to
specify that python.exe is trusted.

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


Re: multithreading and shared dictionary

2006-07-08 Thread Aahz
In article <[EMAIL PROTECTED]>,
Istvan Albert <[EMAIL PROTECTED]> wrote:
>Marc 'BlackJack' Rintsch wrote:
>>
>> It's not in Jython nor IronPython and maybe not forever in
>> CPython.
>
>Whether or not a feature is present in Jython or IronPython does not
>seem relevant, after all these languages emulate Python, one could
>argue that it only means that this emulation is incomplete.  Same for
>changes way out in the future that may or may not materialize. 

The GIL is *NOT* part of the Python language spec; it is considered a
CPython implementation detail.  Other implementations are free to use
other mechanisms -- and they do.
-- 
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: split a line, respecting double quotes

2006-07-08 Thread Jim

Jim wrote:
> Is there some easy way to split a line, keeping together double-quoted
> strings?
Thank you for the replies.

Jim

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


Re: check uploaded file's file size?

2006-07-08 Thread h3m4n
> Try this
> 
> fileitem.seek(0, 2)  # Seek to the end of the file.
> filesize = fileitem.tell()  # Get the position of EOF.
> fileitem.seek(0)  # Reset the file position to the beginning.

thanks for the info.  i just had to change it from fileitem to 
fileitem.file, e.g. fileitem.file.seek(0, 2), and it worked fine.

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


Re: How to check if the connectivity is via Ethernet or dial-up

2006-07-08 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 "jb" <[EMAIL PROTECTED]> wrote:

> Hi all:
> 
> I was just wondering if there is a way to check (using python
> scripting) whether the computer's connectivity is via Dial-up or
> LAN/Ethernet adaptor? Is there a way in python to check the status of
> all available Ethernet adaptors?  If not is there a way to achieve this
> by  just checking some network parameters using System module?.

The best I could suggest is get the pysnmp module, and that to poke around 
in the interface table (assuming your box is running an SNMP agent).
-- 
http://mail.python.org/mailman/listinfo/python-list


How to check if the connectivity is via Ethernet or dial-up

2006-07-08 Thread jb
Hi all:

I was just wondering if there is a way to check (using python
scripting) whether the computer's connectivity is via Dial-up or
LAN/Ethernet adaptor? Is there a way in python to check the status of
all available Ethernet adaptors?  If not is there a way to achieve this
by  just checking some network parameters using System module?.

Please help.

Thanks,
-JS

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


Re: The Split String Function - How to preserve whitespace?

2006-07-08 Thread [EMAIL PROTECTED]
Just wrote:
>>>> "a\nb\nc\n".splitlines(True)
>['a\n', 'b\n', 'c\n']

Genius - Thanks alot  for the quick response !! :-)

Thanks,
Davy Mitchell

The Good Ol' Blog 
http://www.latedecember.com/sites/personal/davy/

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


Re: The Split String Function - How to preserve whitespace?

2006-07-08 Thread Just
In article <[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> I am trying to scan the lines in the string text:
> lines = text.split('\n')
> 
> seemed to do the job but has the side effect of stripping the
> whitespace. As I am reading Python source in this text and checking
> identation this is a bit annoying :-)
> 
> How can I stop this happening? Doesn't look like an option from the
> documents. Do I have to use a regexp (scary unchartered stuff for
> me...)?

   >>> "a\nb\nc\n".splitlines(True)
   ['a\n', 'b\n', 'c\n']

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


Re: wx Browser-objekt for python on Linux

2006-07-08 Thread spooky
Hey,

> Try looking at the wx.HtmlWindow demo

Thank you...I know wx.HtmlWindow but that object can not parse 
Javascript code :((

I need a cross-platform object that can parse js-scripts :(

Can someone help me??

Bye,

Spooky 

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


The Split String Function - How to preserve whitespace?

2006-07-08 Thread [EMAIL PROTECTED]
Hi Folks,

I am trying to scan the lines in the string text:
lines = text.split('\n')

seemed to do the job but has the side effect of stripping the
whitespace. As I am reading Python source in this text and checking
identation this is a bit annoying :-)

How can I stop this happening? Doesn't look like an option from the
documents. Do I have to use a regexp (scary unchartered stuff for
me...)?

Thanks,
Davy Mitchell

The Good Ol' Blog
http://www.latedecember.com/sites/personal/davy/

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


Re: Augument assignment versus regular assignment

2006-07-08 Thread Kirk McDonald
nagy wrote:
> Thanks, Kirk.
> I considered the += as only a shorthand notation for the assignment
> operator.
> Since for lists + is simply a concatetation, I am not sure it x=x+[2]
> is creating a brand
> new list. Could you refer me to any documentation on this?

Yes:

http://docs.python.org/ref/augassign.html
"An augmented assignment expression like x += 1 can be rewritten as x = 
x + 1 to achieve a similar, but not exactly equal effect. In the 
augmented version, x is only evaluated once. Also, when possible, the 
actual operation is performed in-place, meaning that rather than 
creating a new object and assigning that to the target, the old object 
is modified instead."

This behavior is only logical. Consider:

 >>> x = [2]
 >>> y = x + [4]

After these operations, we have two lists: x (the list [2]) and y (the 
list [2, 4]). This is because the expression "x + [4]" creates a new 
list. We then bind this new list to the name 'y', and leave the name 'x' 
alone.

If we then say this:

 >>> x = x + [6]

We are doing much the same operation. We are creating a new list (the 
list [2, 6]), and binding it to the name 'x'. The list [2], previously 
bound to 'x', is no longer bound to anything, so Python frees it.

The augmented assignment, as I went over previously, attempts to modify 
the list object directly. Any names bound to the object (or any other 
objects that reference the object) will see the changes.

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


Re: Augument assignment versus regular assignment

2006-07-08 Thread Chris Lambacher
Looks like x=x+[2] creats a new list to me:
>>> b = [8,5,6]
>>> x = b
>>> x = x + [2]
>>> print b,x
[8, 5, 6] [8, 5, 6, 2]

-Chris
On Sat, Jul 08, 2006 at 11:56:11AM -0700, nagy wrote:
> Thanks, Kirk.
> I considered the += as only a shorthand notation for the assignment
> operator.
> Since for lists + is simply a concatetation, I am not sure it x=x+[2]
> is creating a brand
> new list. Could you refer me to any documentation on this?
> Thanks,
> Nagy
> Kirk McDonald wrote:
> > nagy wrote:
> > > I do the following. First create lists x,y,z. Then add an element to x
> > > using the augumented assignment operator. This causes all the other
> > > lists to be changed also.
> > > But if I use the assignment x=x+[4] instead of using the augumented
> > > assignment, the y and z lists do not change.
> > > Why is that?
> > > This does not happen when I work with integer data type for example, as
> > > shown below.
> > >
> > > Thanks for your help
> > > Nagy
> > >
> > >
> > x=y=z=[]
> >
> > In this example, the '[]' creates a new list object. x, y, and z are all
> > set to reference that object.
> >
> > x+=[2]
> >
> > This does an "in-place" operation on that list, modifying (or
> > "mutating") the object directly.
> >
> > x
> > >
> >
> > > [2]
> > >
> > y
> > >
> > > [2]
> > >
> > z
> > >
> > > [2]
> > >
> > x=x+[4]
> >
> > This creates a new list that is the concatenation of the list created
> > above (the list [2]) with a new list (the list [4]). This brand new list
> > is bound to the name 'x'. The names 'y' and 'z' are left unchanged. That
> > is, they still point to the original list.
> >
> > 
> > x
> > >
> > > [2, 4]
> > >
> > y
> > >
> > > [2]
> > >
> > z
> > >
> > > [2]
> > >
> > a=b=4
> >
> > This binds the names 'a' and 'b' to the integer object 4.
> >
> > b
> > >
> > > 4
> > >
> > a+=2
> >
> > This attempts to mutate the integer object 4, by adding 2 to it.
> > However, numbers in Python are immutable, and so the in-place operation
> > fails. Thus, it creates a new integer object equal to 6 (actually,
> > CPython keeps a cache of certain smaller integer objects and reuses
> > them, but this does not matter in practice). This new integer object is
> > bound to the name 'a'. The name 'b' remains bound to the original 4 object.
> > 
> > a
> > > 
> > > 6
> > > 
> > b
> > > 
> > > 4
> > >
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested scopes, and augmented assignment

2006-07-08 Thread Antoon Pardon
On 2006-07-07, Piet van Oostrum <[EMAIL PROTECTED]> wrote:
>> Antoon Pardon <[EMAIL PROTECTED]> (AP) wrote:
>
>>AP> On 2006-07-07, Piet van Oostrum <[EMAIL PROTECTED]> wrote:
> Antoon Pardon <[EMAIL PROTECTED]> (AP) wrote:
 
>>AP> Could you maybe clarify what problem we are discussing? All I wrote
>>AP> was that with an assignment the search for the lefthand variable
>>AP> depends on whether the lefthand side is a simple variable or
>>AP> more complicated. 
 
 What do you mean with `the lefthand variable'? Especially when talking
 about `complicated lefthand sides'?
>
>>AP> The name on the left side of an assignment that refers to a variable,
>>AP> as opposed to names that are attributes.
>
> So let me get it clear:
> In a.b = c, a is the lefthand variable, but b is not?

Yes, b is an attribute of a

> If that is what you mean then I interpret your statement 
>>AP> `with an assignment the search for the lefthand variable
>>AP> depends on whether the lefthand side is a simple variable or
>>AP> more complicated'
>
> as meaning that the search for `a' in `a.b = c' would be different than the
> search for `a' in `a = b'.

It is conceptually different. In the line 'a = b' you don't need to
search for the scope of a. You know it is the current scope, if you
want to know the scope of b on the other hand, you need to search
for statement where it is assigned to.

Sure you can set things up in the interpreter so that the same search
routine is used, but that is IMO an implementation detail.

> Well, it is not. But I can understand the
> confusion. Namely, `a = b' introduces a binding for `a' in the local scope,
> unless `a' was declared global. So the search will find `a' in the local
> scope and it stops there. On the other hand `a.b = c' will not introduce a
> binding for `a'. So the search for `a' may stop in the local space (if
> there was another binding for `a' in the local scope) or it may need to
> continue to outer scopes. The difference, however is not the
> complicatedness of the lefthand side but whether the local scope contains a
> binding for the variable.

The complicatedness of the lefthand side, decided on whether the
variable was introduced in the local scope or not during startup
time. So that complicatedness decided whether the search was
to stop at the local level or not.

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


urllib2 on Windows Vista

2006-07-08 Thread Sriram Krishnan
I'm running Python 2.4.3 on Windows Vista June CTP. I'm not able to
open any site using the urllib2 and related family of modules

Here's what I get

>>> import urllib2
>>> urllib2.urlopen("http://www.microsoft.com";)
Traceback (most recent call last):
  File "", line 1, in ?
  File "D:\python24\lib\urllib2.py", line 130, in urlopen
return _opener.open(url, data)
  File "D:\python24\lib\urllib2.py", line 358, in open
response = self._open(req, data)
  File "D:\python24\lib\urllib2.py", line 376, in _open
'_open', req)
  File "D:\python24\lib\urllib2.py", line 337, in _call_chain
result = func(*args)
  File "D:\python24\lib\urllib2.py", line 1021, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "D:\python24\lib\urllib2.py", line 996, in do_open
raise URLError(err)
urllib2.URLError: 

Is this a known issue on Windows Vista?

Thanks,
Sriram

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


Re: Detecting 64bit vs. 32bit Linux

2006-07-08 Thread Robert Kern
Jim Segrave wrote:
> In article <[EMAIL PROTECTED]>,
> dwelch91  <[EMAIL PROTECTED]> wrote:
>> I need to detect whether the operating system I am running on (not the 
>> Python version) is 64bit or 32bit. One requirement is that I need to 
>> include support for non-Intel/AMD architectures.
>>
>> The 2 ways I have thought detecting 64bit are:
>>
>> 1. struct.calcsize("P") == 8
>> 2. '64' in os.uname()[4]
>>
>> I'm not convinced that either one of these is really adequate. Does 
>> anybody have any other ideas on how to do this?
> 
> Does sys.maxint give what you need? 
> 
> I think for most machines this will give you the answer you are
> looking for - either 2**31 -1 for a 32 bit version or 2**63-1 for a 64
> bit version. It's set up during the configure phase of building python

No. Some 64-bit systems (notably Win64) leave C longs as 32-bit. This is known 
as the LLP64 data model.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


Re: wx Browser-objekt for python on Linux

2006-07-08 Thread [EMAIL PROTECTED]
Hi Spooky,

Try looking at the wx.HtmlWindow demo - it is cross platform and is
pretty capable.

Thanks,
Davy Mitchell

http://www.latedecember.com/sites/personal/davy/

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


Re: Nested scopes, and augmented assignment

2006-07-08 Thread Antoon Pardon
On 2006-07-07, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> "Antoon Pardon" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> And if  Nested variables are harmfull,
>
> I don't know if anyone said that they were, but Guido obviously does not 
> think so, or he would not have added them.  So skip that.
>
>> what is then the big difference between rebinding them and mutating them
>
> A variable is a name.  Name can be rebound (or maybe not) but they cannot 
> be mutated.  Only objects (with mutation methods) can be mutated.  In other 
> words, binding is a namespace action and mutation is an objectspace action. 
> In Python, at least, the difference is fundamental.
>
> Or, in other other words, do not be fooled by the convenient but incorrect 
> abbreviated phrase 'mutate a nested variable'.

I'm not fooled by that phrase. I just think the mutate vs rebind
explanation is not complete.

If we have two statements "a = b" and "c.d = b" the fact that a is being
rebound while c is mutated doesn't explain why we allow c to be searched
out of the local scope.

By only stating that the first statement is a rebinding and the second
is a mutation and that this is a fundamental difference in python you
seem to suggest that this fundamental differenence implies this
difference in searching scopes. Python could have made the choice
that in an assignment the variable on the left side was always to
be searched in local space so that code like the following would
throw: UnboundLocalError: local variable 'c' referenced before assignment

c = SomeObject
def f():
  c.a = 5

Now I'm not arguing python should have made this choice. But the
possibility shows IMO this has more to do with search policies
of names than with the distinction between a rebinding and a mutation.

AFAIK when nested scopes where introduced everyone agreed that scopes
had to have access to outer scopes. There were voices that supported
allowing a rebinding in an outer scope but no consensus on how to
do this was reached, so this possibility was dropped. So we can't
rebind an outer scope variable but we can mutate such a variable
because for mutation we only need access.

>> I understand that python evolved and that this sometimes results
>> in things that in hindsight could have been done better.
>
> So does Guido.  That is one explicit reason he gave for not choosing any of 
> the nunerous proposals for the syntax and semantics of nested scope write 
> access.  In the face of anti-consensus among the developers and no 
> particular personal preference, he decided, "Better to wait than roll the 
> dice and make the wrong, hard to reverse, choice now".  (Paraphrased quote)
>
>>I have to wonder if someone really thought this through at design time
>
> Giving the actual history of, if anything, too many people thinking too 
> many different thoughts, this is almost funny.

Maybe I didn't made myself clear enough, but I never meant to imply
people hadn't thought thouroughly about this. If I gave you this
impression I appologize. What I was wondering about was that those
that had thought about it, would have reached a certain conclusion
that seemed suggested.

> Recently however, Guido has rejected most proposals to focus attention on 
> just a few variations and possibly gain a consensus.  So I think there is 
> at least half a chance that some sort of nested scope write access will 
> appear in 2.6 or 3.0.

Well I have browsed the discussion, which is why I react so lately to
this, and there is one thing I wonder about. As far as I can see no
suggestion removes the difference in the default search. The following
code will still work and won't need an outer statement. (or global,
nonlocal or whatever it will be)

c = SomeObject
def f():
  c.a = 5

I don say they have to change this, but since it seemed decided this
was a python3k thing, i think the question deserved to be raised.

But I'm glad with this turn of events anyhow.

Just my 2 cent.

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


Re: Augument assignment versus regular assignment

2006-07-08 Thread nagy
Thanks, Kirk.
I considered the += as only a shorthand notation for the assignment
operator.
Since for lists + is simply a concatetation, I am not sure it x=x+[2]
is creating a brand
new list. Could you refer me to any documentation on this?
Thanks,
Nagy
Kirk McDonald wrote:
> nagy wrote:
> > I do the following. First create lists x,y,z. Then add an element to x
> > using the augumented assignment operator. This causes all the other
> > lists to be changed also.
> > But if I use the assignment x=x+[4] instead of using the augumented
> > assignment, the y and z lists do not change.
> > Why is that?
> > This does not happen when I work with integer data type for example, as
> > shown below.
> >
> > Thanks for your help
> > Nagy
> >
> >
> x=y=z=[]
>
> In this example, the '[]' creates a new list object. x, y, and z are all
> set to reference that object.
>
> x+=[2]
>
> This does an "in-place" operation on that list, modifying (or
> "mutating") the object directly.
>
> x
> >
>
> > [2]
> >
> y
> >
> > [2]
> >
> z
> >
> > [2]
> >
> x=x+[4]
>
> This creates a new list that is the concatenation of the list created
> above (the list [2]) with a new list (the list [4]). This brand new list
> is bound to the name 'x'. The names 'y' and 'z' are left unchanged. That
> is, they still point to the original list.
>
> 
> x
> >
> > [2, 4]
> >
> y
> >
> > [2]
> >
> z
> >
> > [2]
> >
> a=b=4
>
> This binds the names 'a' and 'b' to the integer object 4.
>
> b
> >
> > 4
> >
> a+=2
>
> This attempts to mutate the integer object 4, by adding 2 to it.
> However, numbers in Python are immutable, and so the in-place operation
> fails. Thus, it creates a new integer object equal to 6 (actually,
> CPython keeps a cache of certain smaller integer objects and reuses
> them, but this does not matter in practice). This new integer object is
> bound to the name 'a'. The name 'b' remains bound to the original 4 object.
> 
> a
> > 
> > 6
> > 
> b
> > 
> > 4
> >

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


Re: Detecting 64bit vs. 32bit Linux

2006-07-08 Thread Paul McGuire
"MrJean1" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Try function architecture() from the platform module in Python 2.3 and
> 2.4.  The first item of the returned tuple shows whether the underlying
> system is 64-bit capable.
>
> Here is what it returns on RedHat Fedora Core 2 Linux on Opteron:
>
> >>> platform.architecture()
> ('64bit', 'ELF')
> >>> platform.uname()
> ('Linux', '', '2.6.16.14', '#1 SMP Sat Jul 1 14:09:18 CDT 2006',
> 'x86_64', 'x86_64')
>
>
> On RedHat Fedora Core 2 on Pentium 4:
>
> >>> platform.architecture()
> ('32bit', 'ELF')
> >>> platform.uname()
> ('Linux', '', '2.6.10-1771-FC2', '#1 Mon Mar 28 00:50:14 EST 2005',
> 'i686', 'i686')
>
>
> And on MacOS X 10.3.9 G4:
>
> >>> platform.architecture()
> ('32bit', '')
> >>> platform.uname()
> ('Darwin', '', '7.9.0', 'Darwin Kernel Version 7.9.0: Wed Mar 30
> 20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC ', 'Power
> Macintosh', 'powerpc')
>
>

One Windows XP 32-bit, I get:

>>> import platform
>>> platform.architecture()
('32bit', 'WindowsPE')
>>> platform.uname()
('Windows', 'awa1', 'XP', '5.1.2600', '', '')
>>>


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


Re: wx Browser-objekt for python on Linux

2006-07-08 Thread spooky
IE is for Windows...I need something for unix-systems :(

Thx


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


Re: Detecting 64bit vs. 32bit Linux

2006-07-08 Thread MrJean1
Try function architecture() from the platform module in Python 2.3 and
2.4.  The first item of the returned tuple shows whether the underlying
system is 64-bit capable.

Here is what it returns on RedHat Fedora Core 2 Linux on Opteron:

>>> platform.architecture()
('64bit', 'ELF')
>>> platform.uname()
('Linux', '', '2.6.16.14', '#1 SMP Sat Jul 1 14:09:18 CDT 2006',
'x86_64', 'x86_64')


On RedHat Fedora Core 2 on Pentium 4:

>>> platform.architecture()
('32bit', 'ELF')
>>> platform.uname()
('Linux', '', '2.6.10-1771-FC2', '#1 Mon Mar 28 00:50:14 EST 2005',
'i686', 'i686')


And on MacOS X 10.3.9 G4:

>>> platform.architecture()
('32bit', '')
>>> platform.uname()
('Darwin', '', '7.9.0', 'Darwin Kernel Version 7.9.0: Wed Mar 30
20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC ', 'Power
Macintosh', 'powerpc')


/Jean Brouwers



dwelch91 wrote:
> I need to detect whether the operating system I am running on (not the
> Python version) is 64bit or 32bit. One requirement is that I need to
> include support for non-Intel/AMD architectures.
>
> The 2 ways I have thought detecting 64bit are:
>
> 1. struct.calcsize("P") == 8
> 2. '64' in os.uname()[4]
>
> I'm not convinced that either one of these is really adequate. Does
> anybody have any other ideas on how to do this?
> 
> Thanks,
> 
> Don

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


Re: wx Browser-objekt for python on Linux

2006-07-08 Thread shibaji . bannerjee
The wx demos contain an embedded browser (integrates an IE window)
example.

spooky wrote:
> Hey,
>
> For windows there is a object wx.lib.iewin to integrate a browserwindow
> into a python-wx-application.
> I need a similar object, that runs under linux.
> 
> Need help!!!
> 
> Thx,
> 
> Spooky

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


Re: wx Browser-objekt for python on Linux

2006-07-08 Thread shibaji . bannerjee
The wx demos contain an embedded browser (integrates an IE window)
example.

spooky wrote:
> Hey,
>
> For windows there is a object wx.lib.iewin to integrate a browserwindow
> into a python-wx-application.
> I need a similar object, that runs under linux.
> 
> Need help!!!
> 
> Thx,
> 
> Spooky

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


Re: multithreading and shared dictionary

2006-07-08 Thread Alex Martelli
K.S.Sreeram <[EMAIL PROTECTED]> wrote:
   ...
> Alex Martelli wrote:
> > Well then, feel free to code under such assumptions (as long as you're
> > not working on any project in which I have any say:-)
> 
> Hey, I would *never* write code which depends on such intricate
> implementation details! Nonetheless, its good to *know* whats going on
> inside. As they say.. Knowledge is Power!

Since "all abstractions leak" (Spolski), it's indeed worthwhile knowing
what goes on "below" the abstraction (to be wary in advance about such
possible "leaks") -- but studying the sources (and the rich notes that
accompany them) is my favorite approach towards such knowledge!-)


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


Re: handling unicode data

2006-07-08 Thread Filipe

Frank Millman wrote:
> Filipe wrote:
> Try out the suggestions and let us know what happened. I for one will
> be very interested.

The last version of ODBTPAPI is 0.1-alpha, last updated 2004-09-25.
Which is a bit scary...
I might try it just the same though.

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


[Jython-users] Pydev and Pydev Extensions 1.0.6 release

2006-07-08 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.0.6 have been released

Check http://www.fabioz.com/pydev for details on Pydev Extensions

and http://pydev.sf.net for details on Pydev

Release Highlights in Pydev Extensions:
-

- New Feature: Show hierarchy (F4) -- Still in a beta state (currently only looks for subclasses on the same project).
- Analysis happens in a Thread, so, you should now always have the
latest parse without any halts (this happened only when the option was
set to analyze only on save).
- Class variable marked as error when self ommitted
- when an undefined import is found within a try..except ImportError, it will not be reported.
- Allow changing the keybinding for activating the Interactive Console (Ctrl+Enter)
- Added a simple text-search that looks for in all .py and .pyw files
(will be improved in the future to make a real python-like search).
- The keywords that match the 'simple' keywords completion do not show up.


Release Highlights in Pydev:
--

- Assign variables to attributes (Ctrl+2+a): Contributed by Joel
Hedlund (this is the first contribution using the new jython scripting
engine).
- 3 minor 'quirks' were fixed in the indentation engine
- The debugger had some changes (so, if you had halts with it, please try it again).
- Allow changing the keybinding for activating the Find next problem (Ctrl+.)
- The debugger step-return had its behaviour changed.
- Additional scripts location added to pythonpath in the jython scripting engine
- Transversal of nested references improved
- Fixed problems with compiled modules when they had 'nested' module structures (e.g.: wx.glcanvas)

What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Alex Martelli wrote:
> Well then, feel free to code under such assumptions (as long as you're
> not working on any project in which I have any say:-)

Hey, I would *never* write code which depends on such intricate
implementation details! Nonetheless, its good to *know* whats going on
inside. As they say.. Knowledge is Power!

Regards
Sreeram



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

Re: Tkinter and dialogs

2006-07-08 Thread madpython
dwelch91 wrote:
> I'm trying unsuccessfully to do something in Tk that I though would be
> easy.
It is easy.
> The basic idea is that my application will consist of a series of modal
> dialogs, that are chained together in "wizard" fashion.
Didn't have time to get into the code you posted. Just think that the
solution I use might be of some help.

#!/usr/bin/env python
import Tkinter
class PrevNextPane(Tkinter.Frame):
def __init__(self,master):
self.master=master
Tkinter.Frame.__init__(self,master)

self.prvBtn=Tkinter.Button(self,text="Prev",command=self.do_prev).grid(row=0,column=0)

self.nxtBtn=Tkinter.Button(self,text="Next",command=self.do_next).grid(row=0,column=1)
def do_next(self):
self.master.paneNumber+=1
self.master.displayPane()

def do_prev(self):
self.master.paneNumber-=1
self.master.displayPane()

class Pane0(Tkinter.Frame):
def __init__(self,master):
Tkinter.Frame.__init__(self,master)
for i in range(5):
Tkinter.Entry(self).grid(row=i,column=0)

class Pane1(Tkinter.Frame):
def __init__(self,master):
Tkinter.Frame.__init__(self,master)
for i in range(5):
Tkinter.Label(self,text="Label %s"% i).grid(row=i,column=0)

class Pane2(Tkinter.Frame):
def __init__(self,master):
Tkinter.Frame.__init__(self,master)
for i in range(5):
Tkinter.Button(self,text="BtnPane2-%s"%
i).grid(row=i,column=0)

class Wizard(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.topPane=None
self.prevNextPane=PrevNextPane(self).pack(side=Tkinter.BOTTOM)
self.paneNumber=0
self.displayPane()
def displayPane(self):
if self.topPane!=None:
self.topPane.forget()
try:
self.topPane=globals()["Pane%s"% self.paneNumber](self)
except KeyError:
pass
self.topPane.pack(side=Tkinter.TOP)

if __name__=="__main__":
w=Wizard()
w.mainloop()

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


Re: multithreading and shared dictionary

2006-07-08 Thread Alex Martelli
Istvan Albert <[EMAIL PROTECTED]> wrote:

> Marc 'BlackJack' Rintsch wrote:
> 
> > It's not in Jython nor IronPython and maybe not forever in
> > CPython.
> 
> Whether or not a feature is present in Jython or IronPython does not
> seem relevant, after all these languages emulate Python, one could

Not at all, but rather: these _implementations_ are implementations of
the language Python; no "emulation" is involved at all.

> argue that it only means that this emulation is incomplete.  Same for
> changes way out in the future that may or may not materialize. 

What Python semantics' are is supposedly defined by the (normative)
Language Reference.  "One could argue" anything one wishes, of course,
but the existence of freedom of speech does not necessarily make such
arguments sensible nor at all useful.


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


Re: multithreading and shared dictionary

2006-07-08 Thread Alex Martelli
K.S.Sreeram <[EMAIL PROTECTED]> wrote:
   ...
> Consider two threads A and B, which are independent except for the fact
> that they reside in the same module.
> 
> def thread_A() :
> global foo
> foo = 1
> 
> def thread_B() :
> global bar
> bar = 2
> 
> These threads create entries in the same module's dict, and they *might*
> execute at the same time. Requiring a lock in this case is very
> non-intuitive, and my conclusion is that dict get/set operations are
> indeed atomic (thanks to the GIL).

Well then, feel free to code under such assumptions (as long as you're
not working on any project in which I have any say:-) -- depending on
subtle (and entirely version-dependent) considerations connected to
string interning, dict size, etc, you _might_ never run into failing
cases (as long as, say, every key in play is a short internable string
[never an instance of a _subtype_ of str of course], every value an int
small enough to be kept immortally in the global small-ints cache, etc,
etc)... why, dicts that forever remain below N entries for sufficiently
small (and version-dependent) N may in fact never be resized at all.

Most of us prefer to write code that will keep working a bit more
robustly (e.g. when the Python interpreter is upgraded from 2.5 to 2.6,
which might change some of these internal implementation details), and
relying on subtle reasoning about what might be "very non-intuitive" is
definitely counterproductive; alas, testing is not a great way to
discover "race conditions", deadlocks, etc, so threading-related errors
must be avoided ``beforehand'', by taking a very conservative stance
towards what operations might or might not happen to be
atomic/threadsafe unless specifically guaranteed by the Language
Reference (or the specific bits of the Library Reference).


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


Re: multithreading and shared dictionary

2006-07-08 Thread Istvan Albert
Marc 'BlackJack' Rintsch wrote:

> It's not in Jython nor IronPython and maybe not forever in
> CPython.

Whether or not a feature is present in Jython or IronPython does not
seem relevant, after all these languages emulate Python, one could
argue that it only means that this emulation is incomplete.  Same for
changes way out in the future that may or may not materialize. 

i.

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


Mechanize-Browser question..

2006-07-08 Thread bruce
hi..

i have the following piece of test code. i'm trying to implement/check out
the follow-link method. i'm just trying to figure out how to get a link from
the page.

i was hoping that the regex would basically get the 1st url link...

any thoughts/comments/ideas as to what i'm doing wrong.

thanks

-bruce

  br = Browser()
  br.set_handle_redirect(True)
  br.set_handle_referer(True)
  br.open(url2)
  #br.set_cookiejar(cj)
  br.set_debug_redirects(True)
  # Log HTTP response bodies (ie. the HTML, most of the time).
  br.set_debug_responses(True)
  # Print HTTP headers.
  br.set_debug_http(True)
  r2 = br.follow_link(url_regex=re.compile(r"\*"),nr=1)   <<<

  response = br.response()  # this is a copy of response
  print response.read()






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


Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Alex Martelli wrote:
> Wrong, alas: each assignment *could* cause the dictionary's internal
> structures to be reorganized (rehashed) and impact another assignment
> (or even 'get'-access).

(been thinking about this further...)

Dictionary get/set operations *must* be atomic, because Python makes
extensive internal use of dicts.

Consider two threads A and B, which are independent except for the fact
that they reside in the same module.

def thread_A() :
global foo
foo = 1

def thread_B() :
global bar
bar = 2

These threads create entries in the same module's dict, and they *might*
execute at the same time. Requiring a lock in this case is very
non-intuitive, and my conclusion is that dict get/set operations are
indeed atomic (thanks to the GIL).

Regards
Sreeram



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

Re: check uploaded file's file size?

2006-07-08 Thread Simon Forman
h3m4n wrote:
> i have a short script that allows users to upload files, but when i try
> to check for a valid filesize (using fileitem) i get '-1'  i can't find
> information about using filesize anywhere.  any ideas?
>
> code:
>
> form = cgi.FieldStorage()
> fileitem = form["datafile"]
> print str(fileitem.filesize)
>
> -h3m4n

Try this

fileitem.seek(0, 2)  # Seek to the end of the file.
filesize = fileitem.tell()  # Get the position of EOF.
fileitem.seek(0)  # Reset the file position to the beginning.

If the fileitem is a normal file this should work.


Peace,
~Simon

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


wx Browser-objekt for python on Linux

2006-07-08 Thread spooky
Hey,

For windows there is a object wx.lib.iewin to integrate a browserwindow 
into a python-wx-application.
I need a similar object, that runs under linux.

Need help!!!

Thx,

Spooky 

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


Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Marc 'BlackJack' Rintsch wrote:
>>> Wrong, alas: each assignment *could* cause the dictionary's internal
>>> structures to be reorganized (rehashed) and impact another assignment
>>> (or even 'get'-access).
>> but wont the GIL be locked when the rehash occurs?
> 
> If there is a GIL then maybe yes.  But the GIL is an implementation
> detail.  It's not in Jython nor IronPython and maybe not forever in
> CPython.  Don't know about PyPy.

Just wondering.. Is this simply a case of defensive programming or is it
an error? (say, we're targeting only CPython).
For instance, what happens when there's dictionary key with a custom
__hash__ or __eq__ method?

Its probably wise to simply use a lock and relieve ourselves of the
burden of thinking about these cases. But it still is worth knowing...

Regards
Sreeram



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

Search for python-tool to parse Javascript code...

2006-07-08 Thread spooky
Hey,

I need a tool for python to create dynamic links from a javascript.

Thx,

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


Print Tkinter canvas oject contents from Windows?

2006-07-08 Thread [EMAIL PROTECTED]
What is the best way to print a graphic image contained within the
canvas oject in Tkinter ruinng under Windows (XP)?  The only thing I
found so far was the canvas postscript method...it there a more direct
way?

thanks

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


Pls excuse if you consider this off-topic. Conceptual artists seek programmers here.

2006-07-08 Thread M_Mann
Hello,

Pls excuse if you consider this off-topic. Conceptual artists seek
programmers here.

We are authors of "Exhibition of Living Managers" (MANAGEX,
www.managex.info) which is is global conceptual art project, performed
in world's leading contemporary art centres. Art objects at MANAGEX are
real employed managers, who volunteer to exhibit themselves in a galery
setting. Our new project is  "Exhibition of Living Programmers"
(PROGRAMEX), which is similar to MANAGEX but focusing on professional
programmers.

Managex' official website is www.managex.info. We have also just opened
a Google Group here on Managex project:
http://groups.google.com/group/Exhibition-of-Living-Managers-MANAGEX,
where you are welcome to register and participate. Once we have
substantial number of interested programmers, we will open a dedicated
group on Programex.

Hope to hear from you and see you at Programex. Again, sorry if this
posting disturbed anybody.

Best, 

MANAGEX / PROGRAMEX team www.managex.info

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


Re: multithreading and shared dictionary

2006-07-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, K.S.Sreeram
wrote:

> Alex Martelli wrote:
>> Wrong, alas: each assignment *could* cause the dictionary's internal
>> structures to be reorganized (rehashed) and impact another assignment
>> (or even 'get'-access).
> 
> but wont the GIL be locked when the rehash occurs?

If there is a GIL then maybe yes.  But the GIL is an implementation
detail.  It's not in Jython nor IronPython and maybe not forever in
CPython.  Don't know about PyPy.

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


Re: Parsing HTML--looking for info/comparison of HTMLParser vs. htmllib modules.

2006-07-08 Thread Fredrik Lundh
Fredrik Lundh wrote:

> the only difference between the libs (*) is that HTMLParser is a bit 
> stricter

*) "the libs" referring to htmllib and HTMLParser, not htmllib and sgmllib.



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


Re: Detecting 64bit vs. 32bit Linux

2006-07-08 Thread Jim Segrave
In article <[EMAIL PROTECTED]>,
dwelch91  <[EMAIL PROTECTED]> wrote:
>I need to detect whether the operating system I am running on (not the 
>Python version) is 64bit or 32bit. One requirement is that I need to 
>include support for non-Intel/AMD architectures.
>
>The 2 ways I have thought detecting 64bit are:
>
>1. struct.calcsize("P") == 8
>2. '64' in os.uname()[4]
>
>I'm not convinced that either one of these is really adequate. Does 
>anybody have any other ideas on how to do this?

Does sys.maxint give what you need? 

I think for most machines this will give you the answer you are
looking for - either 2**31 -1 for a 32 bit version or 2**63-1 for a 64
bit version. It's set up during the configure phase of building python

If you want to detect a 64bit OS running a compatibility mode for a 32
bit version of Python, then you'll need to figure out how to build and
incorporate a Python extension which can detect this situation




-- 
Jim Segrave   ([EMAIL PROTECTED])

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


Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Alex Martelli wrote:
> Wrong, alas: each assignment *could* cause the dictionary's internal
> structures to be reorganized (rehashed) and impact another assignment
> (or even 'get'-access).

but wont the GIL be locked when the rehash occurs?

Regards
Sreeram



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

Re: how can I avoid abusing lists?

2006-07-08 Thread Jim Segrave
In article <[EMAIL PROTECTED]>,
Rob Cowie <[EMAIL PROTECTED]> wrote:
>Just forget the lists...
>
>counters = {0:0, 1:0, 2:0, 3:0, 4:0}
>
>def increment(value):
>counters[value] += 1
>
>increment(1)
>increment(1)
>increment(3)
>increment(4)
>
>print counters[0]
 0
>print counters[1]
 2
>print coutners[2]
 0
>print counters[3]
 1
>print coutners[4]
 1
>
>The increment function should probably include a try:...except:
>statement to catch KeyErrors that would arise if you passed a value
>that is not a key in the counters dictionary.
>
>Rob C
>

counters = {}
def increment(value):
counters[value] = counters.get(value, 0) + 1

increment(1)
increment(1)
increment(3)
increment(4)
increment('a string key')


keyz = counters.keys()
keyz.sort()
for k in keyz:
print k, counters[k]

Takes care of IndexError and ValueError. It does not report keys that
don't get incremented. If that's important, then initalise counters as
in the quoted posting.

For Python 2.4 and later, you can replace the keyz =
counts.keys()/keyz.sourt() for k in keyz: with

for k in sorted(counters.heys()):
   print k, counters[k]


-- 
Jim Segrave   ([EMAIL PROTECTED])

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


Re: Out of the box database support

2006-07-08 Thread Shane Hathaway
Alex Biddle wrote:
> Ah, so separate downloads then. At least now I know.
> 
> Ergh... I checked the version of Python my current host is running and its 
> 2.2.
> 
> ...ergh

This is why you really want a VPS (virtual private server).  The cost is 
similar to a web host but you get to choose your own technologies and 
versions.  Several companies come to mind:

http://westhost.com/
http://jvds.com/
http://linode.com/

I'm using Westhost, which provides Python 2.2 if you ask for it, but I 
compiled Python 2.4 instead.  I didn't even have to ask whether I was 
allowed to do that. :-)

Shane

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


python-dev Summary for 2006-06-01 through 2006-06-15

2006-07-08 Thread Steven Bethard
python-dev Summary for 2006-06-01 through 2006-06-15


.. contents::

[The HTML version of this Summary is available at
http://www.python.org/dev/summary/2006-06-01_2006-06-15]



=
Announcements
=

---
Python 2.5 schedule
---

Python 2.5 is moving steadily towards its next release.  See `PEP
356`_ for more details and the full schedule.

.. _PEP 356: http://www.python.org/dev/peps/pep-0356/

Contributing threads:

- `beta1 coming real soon
`__
- `2.5 issues need resolving in a few days
`__

---
Request for Bug Trackers to replace SourceForge
---

The Python Software Foundation's Infrastructure committee asked for
suggestions for tracker systems that could replace SourceForge. The
minimum requirements are:

* Can import SourceForge data
* Can export data
* Has an email interface

and if you'd like to suggest a particular tracker system all you need to do is:

* Install a test tracker
* Import the `SourceForge data dump`_
* Make the `Infrastructure committee members`_ administrators of the tracker
* Add your tracker to the `wiki page`_
* Email `the Infrastructure committee`_

Be sure to check the `wiki page`_ for additional information.

.. _SourceForge data dump: http://effbot.org/zone/sandbox-sourceforge.htm
.. _Infrastructure committee members:
http://wiki.python.org/moin/PythonSoftwareFoundationCommittees#infrastructure-committee-ic
.. _wiki page: http://wiki.python.org/moin/CallForTrackers
.. _the Infrastructure committee: [EMAIL PROTECTED]

Contributing thread:

- `Request for trackers to evaluate as SF replacement for Python
development 
`__


=
Summaries
=


Getting more comparable results from pybench


Skip Montanaro mentioned that the NeedForSpeed_ folks had some trouble
with the pybench_ string and unicode tests. In some discussions both
on the checkins list and off-list, Fredrik Lundh had concluded that
stringbench more reliably reported performance than pybench. There was
then a long discussion about how to improve pybench including:

* Using time.clock() on Windows and time.time() on Linux. This was
accompanied by a long debate about whether to use wall-time or process
time.  Both wall time and process time can see interference from other
programs running at the same time; wall time because the time consumed
by other programs running at the same time is also counted, and
process time because it is sampled so that other processes can charge
their time to the running process by using less than a full time
slice. In general, the answer was to use the timer with the best
resolution.

* Using the minimum time rather than the average. Andrew Dalke
explained that timing results do not have a Gaussian distribution
(they have more of a gamma distribution) and provided some graphs
generated on his machine to demonstrate this. Since the slower runs
are typically caused by other things running at the same time (which
is pretty much unpredictable), it's much better to report the fastest
run, which should more consistently approximate the best possible
time.

* Making sure to use an appropriate warp factor. Marc-Andre Lemburg
explained that each testing round of pybench is expected to take
around 20-50 seconds. If rounds are much shorter than this, pybench's
warp factor should be adjusted until they are long enough.

At the end of the thread, Marc-Andre checked in pybench_ 2.0, which
included the improvements suggested above.

.. _NeedForSpeed: http://wiki.python.org/moin/NeedForSpeed
.. _pybench: http://svn.python.org/view/python/trunk/Tools/pybench/
.. _stringbench: http://svn.python.org/view/sandbox/trunk/stringbench/

Contributing threads:

- `Python Benchmarks
`__
- `Python Benchmarks
`__

---
PEP 360: Externally Maintained Packages
---

After checking wsgiref into the Python repository, Phillip J. Eby
requested in `PEP 360`_ that patches to wsgiref be passed to him
before being committed on the trunk. After a number of changes were
committed to the trunk and he had to go through a complicated two-way
merge, he complained that people were not following the posted
procedures. Guido suggested that `PEP 360`_ was a mistake, and that
whenever possible, development for any module in the stdlib should be
done in the Python trunk, not externally. He also requested that the
PEP indicate that even for externally maint

Re: multithreading and shared dictionary

2006-07-08 Thread placid

Alex Martelli wrote:
> Istvan Albert <[EMAIL PROTECTED]> wrote:
>
> > Stéphane Ninin wrote:
> >
> > > Is a lock required in such a case ?
> >
> > I believe that assignment is atomic and would not need a lock.
>
> Wrong, alas: each assignment *could* cause the dictionary's internal
> structures to be reorganized (rehashed) and impact another assignment
> (or even 'get'-access).


Oh yeah you are correct, i forgot about possible rehashing after
assignment operation, so to that means you do need to use a lock to
restrict only one thread at time from accessing the dictionary. Again i
recommend using a Queue to do this. If you need help with usage of
Queue object first see
http://www.google.com/notebook/public/14017391689116447001/BDUsxIgoQkcSO3bQh
or contact me

-Cheers

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


Re: some questions on how to study the bittorent.

2006-07-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Moore Liu
wrote:

> Hi all,
> 
> I am very interesting in the detailed implement of bittorrent and have
> read some p2p protocol document, but I want to know more of the
> technique implementation. It's time-consuming to reverse-engineering
> the code to understand the design intention of it. So my question is:
> 
> Is there any well written "Design document" we can find, which descibe
> the detail technical in the code. For example: the seed format, the
> algorithm of how to divide the files into blocks, how to schdule
> threads, how to decide which part of the file should be receive first,
> the credit system(something like that in the eMule), and so on...

You can start with the `protocol description`_ on the BitTorrent website
and the `BitTorrent Economics Paper`_.

.. _protocol description: http://www.bittorrent.org/protocol.html
.. _BitTorrent Economics Paper:
   http://www.bittorrent.com/bittorrentecon.pdf

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


Re: handling unicode data

2006-07-08 Thread Frank Millman

Filipe wrote:
>
> The only reason I still think Pymssql (and therefore, DB-Library) might
> be the best option is that, it is the only one I know that is both
> cross-platform and free - as in beer and as in freedom. (check, in this
> thread, a previous message by Tim Golden)
>

I have bookmarked this post dated October 2004, intending to look into
it one day. I have not done so yet (where does all the time go?). The
subject is "Connecting to SQL Server from Unix".

http://tinyurl.com/zc7so

Try out the suggestions and let us know what happened. I for one will
be very interested.

Frank Millman

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


some questions on how to study the bittorent.

2006-07-08 Thread Moore Liu
Hi all,

I am very interesting in the detailed implement of bittorrent and have
read some p2p protocol document, but I want to know more of the
technique implementation. It's time-consuming to reverse-engineering
the code to understand the design intention of it. So my question is:

Is there any well written "Design document" we can find, which descibe
the detail technical in the code. For example: the seed format, the
algorithm of how to divide the files into blocks, how to schdule
threads, how to decide which part of the file should be receive first,
the credit system(something like that in the eMule), and so on...

Could you pls tell me the methology to study the code or show me some
link to these document or some specific forum to delve in?

Thanks,
Moore

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


Re: Parsing HTML--looking for info/comparison of HTMLParser vs. htmllib modules.

2006-07-08 Thread Fredrik Lundh
Kenneth McDonald wrote:

> The problem I'm having with HTMLParser is simple; I don't seem to be 
> getting the actual text in the HTML document. I've implemented the 
> do_data method of HTMLParser.HTMLParser in my HTMLParser subclass, but 
> it never seems to receive any data. Is there another way to access the 
> text chunks as they come along?

the method is called "handle_data":

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

> HTMLParser would probably be the way to go if I can figure this out. It 
> seems much simpler than htmllib, and satisfies my requirements.
> 
> htmllib will write out the text data (using the AbstractFormatter and 
> AbstractWriter), but my problem here is conceptual. I simply don't 
> understand why all of these different "levels" of abstractness are 
> necessary, nor how to use them.

if you're not interested in HTML *rendering*, use sgmllib instead.

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

the only difference between the libs is that HTMLParser is a bit 
stricter; on the other hand, if you want to parse really messy HTML, you 
should probably use BeautifulSoup instead:

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



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