ANN: ChiPy Thurs. October 12, 2006. 7pm @ Performics 180 N. Lasalle

2006-10-08 Thread Chris McAvoy
Join us for our best meeting ever!

Thurs. October 12th, 2006. 7pm.

Topics
-
* PLY (Python Lex Yacc) David Beazley
* Performance Python (without PyPy) Michael Tobis

Location

Performics  180 N. Lasalle 12th floor. Chicago RSVP (for building
security) by Tuesday night to [EMAIL PROTECTED] with subject
RSVP Chipy

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


ANN: geopy 0.93 - Geocoding Toolbox for Python

2006-10-08 Thread Brian Beck
Hi everyone,

geopy 0.93 was released tonight.

What is geopy?
==
geopy is a geocoding toolbox for Python. It includes support for many
popular geocoders including Google Maps, Yahoo! Maps, Virtual Earth,
geocoder.us, GeoNames, MediaWiki (with the GIS extension), and Semantic
MediaWiki. It also includes a module for calculating geodesic distances
using different models (spherical and ellipsoidal).


Where can I get it?
===
setuptools: sudo easy_install geopy
Cheese Shop: http://cheeseshop.python.org/pypi/geopy
svn: svn co http://geopy.googlecode.com/svn/tags/release-0.93 geopy-0.93
Documentation: http://exogen.case.edu/projects/geopy


What's new in this version?
===
geopy.geocoders now includes GeoNames (www.geonames.org).

geopy.distance module was added: calculate geodesic distances.

geopy.util module was added: geocoders.Geocoder.parse_geo was moved there.

geopy.geocoders.Google can now be used with different domains (such
as 'maps.google.co.uk') and different resources ('maps' for the standard
Google Maps interface, 'maps/geo' for the HTTP geocoder interface).


How about an example?
=

py from geopy import geocoders
py us = geocoders.GeocoderDotUS()  
py place, (lat, lng) = us.geocode(1600 Pennsylvania Ave, Washington DC)  
py print %s: %.5f, %.5f % (place, lat, lng)  
1600 Pennsylvania Ave NW, Washington, DC 20502: 38.89875, -77.03768  

py from geopy import distance
py _, a = us.geocode('10900 Euclid Ave, Cleveland, OH 44106')
py _, b = us.geocode('1600 Pennsylvania Ave, Washington, DC')
py distance.distance(a, b).miles
301.35526872700962

py from geopy import util
py util.parse_geo(u23° 26m 22s N 23° 27m 30s E)
(23.439, 23.4583332)

-- 
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Dumping the state of a deadlocked process

2006-10-08 Thread MrJean1
[EMAIL PROTECTED] wrote:
 MrJean1 wrote:
  Did you try using the signal module?  If not, a basic example is here
  http://docs.python.org/lib/node546.html which may need to be
  extended.

 I looks useful. I gave it a try, and the only weakness it has is that
 when my process locks, it locks so badly that it doesn't respond to
 CTRL-C, or any other signal. But by sending it a SIGQUIT which causes
 it to dump the current state, and then kill it, I get the dump I need.

The Ctrl-C signal SIGINT is caught by Python by default and the signal
handler
raises a KeyboardInterrupt exception.  For any other signals, the
signal is caught
but the signal handler is not called until Python returns to the main
loop.

Therefore, if some extension -like Postgresql in this case- is busy or
hangs, nothing
will happen until Python regains control.



 This is actually not a multi-threaded app. It's an application which
 uses a SQL DB. The problem I was having was that I had a cursor which
 started a transaction, and then never finished. Then some other cursor
 came along and tried to perform a delete table, and they both locked
 up. The cursor isn't ending it's transaction, and the transaction
 prevents the delete table from being executed. Luckily Postgresql
 allows me to list current activity, otherwise I would have been
 scratching my head still.

 Using logging or print statements to debug this sort of things is
 highly unsatisfactory. I think the way Java uses SIGQUIT is pretty
 neat, are there any reasons why Python can't adopt something similar?

I can not anwer that.

/Jean Brouwers

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


Re: Is there an alternative to os.walk?

2006-10-08 Thread Ant
The idiomatic way of doing the tree traversal is:

def search(a_dir):
   valid_dirs = []
   for dirpath, dirnames, filenames in os.walk(a_dir):
   if dirtest(filenames):
   valid_dirs.append(dirpath)
   return valid_dirs

Also since you are given a list of filenames in the directory, then why
not just check the list of those files for your test files:

def dirtest(filenames):
   testfiles = ['a','b','c']
   for f in testfiles:
   if not f in filenames:
   return False
   return False

You'd have to test this to see if it made a difference in performance,
but it makes for more readable code

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


Re: need some regular expression help

2006-10-08 Thread Diez B. Roggisch

hanumizzle wrote:
 On 7 Oct 2006 15:00:29 -0700, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 
  Chris wrote:
   I need a pattern that  matches a string that has the same number of '('
   as ')':
   findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [
   '((2x+2)sin(x))', '(log(2)/log(5))' ]
   Can anybody help me out?
 
  This is not possible with regular expressions - they can't remember
  how many parens they already encountered.

 Remember that regular expressions are used to represent regular
 grammars. Most regex engines actually aren't regular in that they
 support fancy things like look-behind/ahead and capture groups...IIRC,
 these cannot be part of a true regular expression library.

Certainly true, and it always gives me a hard time because I don't know
to which extend a regular expression nowadays might do the job because
of these extensions. It was so much easier back in the old times

 With that said, the quote-unquote regexes in Lua have a special
 feature that supports balanced expressions. I believe Python has a
 PCRE lib somewhere; you may be able to use the experimental ??{ }
 construct in that case.

Even if it has - I'm not sure if it really does you good, for several
reasons:

 - regexes - even enhanced ones - don't build trees. But that is what
you ultimately want
   from an expression like sin(log(x))

 - even if they are more powerful these days, the theory of context
free grammars still applies.
   so if what you need isn't LL(k) but LR(k), how do you specify that
to the regex engine?

 - the regexes are useful because of their compact notations, parsers
allow for better structured outcome 


Diez

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


Re: need some regular expression help

2006-10-08 Thread Theerasak Photha
On 8 Oct 2006 01:49:50 -0700, Diez B. Roggisch [EMAIL PROTECTED] wrote:

 Even if it has - I'm not sure if it really does you good, for several
 reasons:

  - regexes - even enhanced ones - don't build trees. But that is what
 you ultimately want
from an expression like sin(log(x))

  - even if they are more powerful these days, the theory of context
 free grammars still applies.
so if what you need isn't LL(k) but LR(k), how do you specify that
 to the regex engine?

  - the regexes are useful because of their compact notations, parsers
 allow for better structured outcome

Just wait for Perl 6 :D

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


Re: A critique of cgi.escape

2006-10-08 Thread Duncan Booth
Lawrence D'Oliveiro [EMAIL PROTECTED] wrote:

 Another useful function is this:
 
 def JSString(Str) :
 returns a JavaScript string literal that evaluates to Str.
 Note I'm not worrying about non-ASCII characters for now.
snip

Here is a shorter alternative that handles non-ASCII sequences provided you 
pass in unicode:

def JSString(s):
return repr(unicode(s))[1:]

 print JSString(u\u201chi there!\u201d)
'\u201chi there!\u201d'
 print JSString(Hello world)
'Hello world'
 print JSString(Hello 'world')
Hello 'world'

For ascii strings you could also use the string-escape codec, but strangely 
the unicode-escape codec doesn't escape quotes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: People's names (was Re: sqlite3 error)

2006-10-08 Thread Steve Holden
Lawrence D'Oliveiro wrote:
 In message [EMAIL PROTECTED], Steve
 Holden wrote:
 
 
John Machin wrote:

[lots of explanation about peculiarities of people's names]

While I don't dispute any of this erudite display of esoteric
nomenclature wisdom the fact remains that many (predominantly Western)
databases do tend to use first and last name (in America often with the
addition of a one- or two-character middle initial field).
 
 
 Just because most Western designers of databases do it wrong doesn't mean
 that a) you should do it wrong, or b) they will continue to do it wrong
 into the future, as increasing numbers of those designers come from Asian
 and other non-Western backgrounds.
 
I quite agree: my comment was really intended to highlight the fact that 
most Western database designers (myself included) do tend to be quite 
locale-centric. I haven't any experience with Eastern design, so can't 
say whether the same holds true.
 
So, having distilled your knowledge to its essence could you please give
me some prescriptive advice about what I *should* do? :-)
 
 
 Has anyone come up with a proper universal table design for storing people's
 names?
 
 Certainly first name and last name are the wrong column names to use. I
 think family name and given names would be a good start. For the
 Icelanders, Somalians and the Muslims, their father's name goes in
 the family name field, which makes sense because all their siblings (of
 the same sex, at least) would have the same value in this field.
 
 I wonder if we need another middle field for holding the bin/binte part
 (could also hold, e.g. Van for those names that use this).
 
 There would also need to be a flag field to indicate the canonical ordering
 for writing out the full name: e.g. family-name-first, given-names-first.
 Do we need something else for the Vietnamese case?

You'd think some standards body would have worked on this, wouldn't you. 
I couldn't think of a Google search string that would lead to such 
information, though. Maybe other, more determined, readers can do better.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: need some regular expression help

2006-10-08 Thread bearophileHUGS
Tim Chase:
 It still doesn't solve the aforementioned problem
 of things like ')))((('  which is balanced, but psychotic. :)

This may solve the problem:

def balanced(txt):
d = {'(':1, ')':-1}
tot = 0
for c in txt:
tot += d.get(c, 0)
if tot  0:
return False
return tot == 0

print balanced(42^((2x+2)sin(x)) + (log(2)/log(5))) # True
print balanced(42^((2x+2)sin(x) + (log(2)/log(5))) # False
print balanced(42^((2x+2)sin(x))) + (log(2)/log(5))) # False
print balanced()))((() # False

A possibile alternative for Py 2.5. The dict solution looks better, but
this may be faster:

def balanced2(txt):
tot = 0
for c in txt:
tot += 1 if c==( else (-1 if c==) else 0)
if tot  0:
return False
return tot == 0

Bye,
bearophile

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


Re: Access to static members from inside a method decorator?

2006-10-08 Thread glen . coates . bigworld
Peter Otten wrote:
 [EMAIL PROTECTED] wrote:

 You define one base type with a custom metaclass and inherit from that. Your
 example then becomes:

 import sys

 class ExposedType( type ):
 def __init__( cls, *args, **kw ):
 # Track marked exposed methods
 cls.s_exposedMethods = []
 for superclass in cls.__mro__:
 for name, meth in superclass.__dict__.items():
 if hasattr( meth, exposed ):
 cls.s_exposedMethods.append( name )

 class Exposed:
 __metaclass__ = ExposedType
 def getExposedMethods(self):
 return self.s_exposedMethods
 def bar(self):
 print bar\n
 @staticmethod
 def expose( f ):
 f.exposed = True
 return f

 class Process( Exposed):
 @Exposed.expose
 def foo( self ):
 pass
 def bar( self ):
 print BAR


 class BotProcess( Process ):
 @Exposed.expose
 def addBots( self ):
 pass

 p = Process()
 p.bar()

 This prints BAR as expected.

 Peter

Thanks Peter.  Yeah I had thought of that earlier, but wasn't sure if
this is a standard design pattern for what I'm trying to achieve.  It
seems ugly to me to use 2 classes when you are essentially describing a
single type.  Is the Splat/SplatType pairing really a common design
pattern when trying to use metaclasses in this way?

Also ... as for the 'inspect' based solution, yeah I can see that would
work, but it seems very hacky to me and my gut reaction is to avoid
that kind of thing ...

Cheers,
Glen

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


Re: need some regular expression help

2006-10-08 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

  The dict solution looks better, but this may be faster:

it's slightly faster, but both your alternatives are about 10x slower 
than a straightforward:

def balanced(txt):
 return txt.count(() == txt.count())

/F

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


Re: People's names (was Re: sqlite3 error)

2006-10-08 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes:
  There would also need to be a flag field to indicate the canonical
  ordering
  for writing out the full name: e.g. family-name-first, given-names-first.
  Do we need something else for the Vietnamese case?
 
 You'd think some standards body would have worked on this, wouldn't
 you. I couldn't think of a Google search string that would lead to
 such information, though. Maybe other, more determined, readers can do
 better.

Librarians have to deal with this all the time, I expect.  I believe
library catalogs often use two separate fields, one for some
representation of the name intended for lexicographic sorting, and
another for display to the user.  There's an exercise in Knuth vol 3
showing a bunch of examples, using both author names and book titles.
-- 
http://mail.python.org/mailman/listinfo/python-list


A curses-game I need help with.

2006-10-08 Thread Gasten
Hello.
The last weeks I've been coding a roguelike (you know, like nethack) in
python using the nCurses library. Some week ago I ran into a problem:
When I made the object for messagebar-output, I found a bug that I
can't figure out (believe me; I've tried everything and asked for help
several times on the IRC-channel).

The updateMsg() and iMsg() takes a list of message-lines as argument
(or process a string to a list), and it'll output each of them to the
messagebar, output a sign that say: More, and wait for the user to hit
space, and then output another line. The last line will just be
outputed, without waiting for the user to hit space. Thou, that doesn't
work. It doesn't output the last line. Not when there are more than one
line, and not when there is just that one line.

I've tried calling noutrefresh() and doupdate() instead of just
refresh(), I've rebuilt the structure of the methods, and done all
sorts of things. By writing debug-messages to a file, I've understood
that the last addstr() DO output the line, but the refresh isn't
working. Or something else isn't working.

Can you help?

I'll just append all my code here (for anyone to test), so you who
doesn't want to read this humble beginners code can skip to another
message. Thank you  for your time.

(So far I've understood, is that iMsg() and updateMsg() is wrong. Line
71 and 92.)


try:
import curses
except ImportError:
print Missing the Curses-library.
print Please install the curses-library correctly.
SystemExit

#---

class Game:
The Game-object. Controls the windows, global settings and so
on.
def __init__(self):
self.mainwin = curses.initscr()

## Some basic settings
curses.noecho()
curses.cbreak()
self.mainwin.keypad(1)
curses.curs_set(0)

self.msg = Msg()
self.msg.msg([Welcome to The Game! Lets watch another fearless
samurai, get beaten bloody in the arena!])

self.mainwin.addstr(3,15, '+' + '-' * 62 + '+')
self.mainwin.addstr(22,15, '+' + '-' * 62 + '+')
self.mainwin.vline(4,15, '|', 18)
self.mainwin.vline(4,78, '|', 18)


movedir = {
'up':   {'x':0, 'y':-1},
'down': {'x':0, 'y':+1},
'right':{'x':+1, 'y':0},
'left': {'x':-1, 'y':0},
'downright':{'x':+1, 'y':+1},
'upright':  {'x':+1, 'y':-1},
'downleft': {'x':-1, 'y':+1},
'upleft':   {'x':-1, 'y':-1}
}

walls = (
ord('|'),
ord('+'),
ord('-')
)

#---

class Msg:
The messagehandeling and -bar system.
def __init__(self):
self.msgs = []

def printMore(self):
# Print the little #More#-sign
game.mainwin.addch(1, 71, curses.ACS_BLOCK, curses.A_REVERSE)
game.mainwin.addstr(1, 72, More, curses.A_REVERSE)
game.mainwin.addch(1, 76, curses.ACS_BLOCK, curses.A_REVERSE)

def msg(self, msg):
if isinstance(msg, str):
self.msgs.append(msg)
else:
self.msgs = self.msgs + msg

def ereasMsg(self):
for count in range(0,2):
game.mainwin.move(count,0)
game.mainwin.clrtoeol()

def updateMsg(self):
count = len(self.msgs)
for msg in self.msgs:   # Print one msg after
another
game.mainwin.addstr(0,0, msg)   # Print the actual message
if count  1:   # If there are two or more
laft, print a #More#-sign.
count -= 1
self.printMore()
game.mainwin.refresh()
while 1:
next = game.mainwin.getch()
if next == ord(' '):
self.ereasMsg()
break
else:
continue
else:
game.mainwin.refresh()

self.msgs = [] # When done, kill all messages
return True

def iMsg(self, msg):
Same as msg(), but the screen will refresh instantly.
'i' is standing for Interface or Instant message.
if isinstance(msg, str):
msg = [msg] # List'it!
count = len(msg)
for item in msg:
if count  1:
count -= 1
self.printMore()
game.mainwin.addstr(0,0, item)
game.mainwin.refresh()
while 1:
next = game.mainwin.getch()
if next == ord(' '):
self.ereasMsg()
break
else:
continue
else:
game.mainwin.addstr(0,0, item)

return


#---

class Samurai:

Implementing a circular counter using property / descriptors?

2006-10-08 Thread IloChab
I'd like to implement an object that represents a circular counter, i.e.
an integer that returns to zero when it goes over it's maxVal.

This counter has a particular behavior in comparison: if I compare two of
them an they differ less than half of maxVal I want that, for example, 
0  maxVal gives true. 
This is because my different counters  grew together and they never
differ a lot between them and so a value of 0 compared with an other of
maxVal means that the previous one just made its increment before the
other one.

The python problem that I give you it's about style. 
I'd like to write in my code something that looks almost like using an
integer object.  

I mean, I'd like to write:

cnt = CircularConter(maxVal=100, initialVal=10) 
cnt += 100 # cnt value is 9
print cnt  # prints 9
100  cnt  # is false
cnt = 100  # cnt new value is 100 [NOT  rebind cnt with 100]

Until now I used this class:

class CircularConter:

def __init__(self, maxVal, initialVal=0):
self.maxVal = maxVal
self.val = None
self.set( initialVal )

def __add__(self, increment):
self.set( self.val + increment )
return self

def __cmp__(self, operand):
return cmp(self.maxVal/2, abs(operand - self.val)) * cmp(self.val,
operand)

def __repr__(self):
return str(self.val)
def __str__(self):
return str(self.val)

def set(self, val):
if val  self.maxVal:   self.val = val-self.maxVal-1 
else:   self.val = val


... and so my real writing was:

cnt = CircularConter(maxVal=100, initialVal=10) 
cnt += 100   
print cnt
100  cnt# is false  
cnt.set(100)   

The fact is that I don't like to write cnt.set(100) or  
cnt = CircularConter(100, 100) instead of cnt = 100. 
So I thought that property or descriptors could be useful. 
I was even glad to write:

cnt = CircularConterWithProperty(maxVal=100, initialVal=10) 
cnt.val += 100
print cnt.val
100  cnt.val  # is false
cnt.val = 100

just to give uniformity to counter accessing syntax. 
But I wasn't able to implement nothing working with my __cmp__ method.

I'll post one of mine NOT WORKING implementation.


class pro(object):

def __init__(self, maxVal, val):
self._maxVal = maxVal
self._val = val

def getval(self):
return self._val

def setval(self, val):
if val  self._maxVal:   self._val = val-self._maxVal-1 
else:self._val = val
val = property(getval, setval)


class CircularConterWithProperty(pro):

def __init__(self, maxVal, val=0):
super(CircularConterWithProperty, self).__init__( maxVal, val)

def __cmp__(self, operand):
return cmp(self.maxVal/2, abs(operand - self.val)) * cmp(self.val,
operand)



__ I know why this doesn't work. __

__ What I don't know __  is if there is a way to write a class that allows
my desire of uniform syntax or if IT IS JUST A NON SENSE.

I'll thank in advance for any answer.

Saluti a tutti
Licia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error handling in user input: is this natural or just laborious

2006-10-08 Thread Steve Holden
Lawrence D'Oliveiro wrote:
 In message [EMAIL PROTECTED], James Stroud
 wrote:
 
 
Patently. Tabs should be reserved for tables, for which tabs were named.
If they were meant to be used for indenting, they would have been
named indenters. 
 
Or possibly inds, in a similarly abbreviative spirit.
 
 Really? I thought they were for tabulators
 http://www.columbia.edu/acis/history/tabulator.html.

Well, let's ignore the fact that this was probably a tongue-in-cheek reply.

Firstly, the article you quote shows clearly that Hollerith invented the 
tabulator in the late 19th century. C L Scholes was granted the first 
typewriter paten in 1868, and Remington started manufacture in 1873. So 
tabs were already used (to produce tables) by the time the tabulator 
arrived on the scene.

Secondly the tabulator was originally simply a device for counting the 
occurrences of the various values possible for a field (you may know it 
was invented to assist in the processing of the US census), and when 
printing was later added the output to the printer wasn't sequential 
anyway, so no tab character was required: the positions of report 
fields would be hard-programmed into the patch panel.

ObPython: PEP 8 (http://www.python.org/dev/peps/pep-0008/) was 
originally an essay by Guido in which he listed his own personal 
stylistic preferences. Naturally his opinions were taken seriously 
because he has proved to be a capable language designer, and when the 
PEP scheme was introduced his essay (originally published under the 
title A Foolish Consistency is the Hobgoblin of Little Minds) was 
adopted more or less unchanged. It has since been revised, but still 
refers to the original. Ultimately a conformance with PEP 8 can be taken 
as an indication that the author has reached a certain stylistic maturity.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: operator overloading + - / * = etc...

2006-10-08 Thread Steve Holden
Tim Chase wrote:
Can these operators be overloaded?

Yes.
 
 
 With the caveat of the = mentioned in the subject-line (being 
 different from ==)...I haven't found any way to override 
 assignment in the general case.  There might be some oddball way 
 to do it via property() but AFAIK, this only applies to 
 properties of objects, not top-level names/variables.  I'd love 
 to know if there's some workaround for this though...
 
That's because assignment isn't an operator - that's why (for example)

 print x = 33

would be a syntax error. This is a deliberate design decision about 
which, history shows, there is little use complaining.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Can't get around IndexError: list index out of range

2006-10-08 Thread Steven D'Aprano
On Sat, 07 Oct 2006 18:06:47 -0700, MonkeeSage wrote:

 On Oct 7, 7:59 pm, Steven D'Aprano
 [EMAIL PROTECTED] wrote:
 Because they aren't needed often, and when they are, they are easy to
 implement?
 
 More often and easier to implement than dict.has_key / get?

No, *less* often. That's the point -- it is fairly common for people to
want dictionary lookup to return a default value, but quite rare for them
to want sequence lookup to return a default value. A sequence with a
default value would be, in some sense, equivalent to an infinite list:

[A, B, ... , Z, default, default, default, ... ]

where the A...Z are actual values. (Obviously you don't actually have an
infinite list.) 

I can't think of any practical use for such a thing; the only thing that
comes close is in some Cellular Automata it is sometimes useful to imagine
cells out of range to be always in some default state. But generally
speaking, you don't implement Cellular Automata with lists.



 It is hard to see where list.get(index, default) would be useful, since
 accessing an index out of range of a list is generally an error, unlike
 accessing a missing key.
 
 Uh, no. KeyError.

dict.get() doesn't raise KeyError. That's the whole point of get(), it
returns a default value instead of raising KeyError.


 Not every piece of functionality needs to be a built-in.
 
 Agreed. but why implement a certain functionality in one place but leave
 it out of another?

Because implementation requires time and effort. It makes the regression
tests more complicated and bloats the code base. If the feature doesn't
scratch anybody's itch, if there isn't a clear use for it, it won't be
implemented. If you don't care enough to even make a formal feature
request, let alone a PEP, then why should people who care even less
actually write the code?


-- 
Steven.

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


Re: Implementing a circular counter using property / descriptors?

2006-10-08 Thread Steven D'Aprano
On Sun, 08 Oct 2006 12:25:10 +0200, IloChab wrote:

 I'd like to implement an object that represents a circular counter, i.e.
 an integer that returns to zero when it goes over it's maxVal.

[snip]

 The python problem that I give you it's about style. 
 I'd like to write in my code something that looks almost like using an
 integer object.  
 
 I mean, I'd like to write:
 
 cnt = CircularConter(maxVal=100, initialVal=10) 
 cnt += 100 # cnt value is 9
 print cnt  # prints 9
 100  cnt  # is false

All this is perfectly sensible.

 cnt = 100  # cnt new value is 100 [NOT  rebind cnt with 100]

This is not possible. Names like cnt are just labels, they don't have
behaviour. Objects have behaviour; but objects don't and can't know what
name or names they are assigned to.

[snip]

 The fact is that I don't like to write cnt.set(100) or  
 cnt = CircularConter(100, 100) instead of cnt = 100. 

How do you expect the Python compiler to know you want a CircularConter
instance if you just write 100?

(By the way, in English, the correct spelling is counter, not conter.)

 So I thought that property or descriptors could be useful. 
 I was even glad to write:
 
 cnt = CircularConterWithProperty(maxVal=100, initialVal=10) 
 cnt.val += 100
 print cnt.val
 100  cnt.val  # is false
 cnt.val = 100
 
 just to give uniformity to counter accessing syntax. 
 But I wasn't able to implement nothing working with my __cmp__ method.

__cmp__ is for CoMParisons, not binding names to objects.


-- 
Steven.

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


Re: dictionary containing a list

2006-10-08 Thread Ben
I think what you mean is that if you change your list, it is changed
somewhere in your dicrionary to. Lists are always copied as pointers,
except explicitly told other wise. So a = b = [] makes a and be the
same list, and a.append(1) makes b -  [1].
So do something like mydict[mykey] = mylist[:] (Slicing gives a copy
of the list, not the pointer).
Hope this helps.

Moi
Dolf

Ah  -this is exactly what I was doing wrong -thaks very much! Aologies
also for not posting sooner, I have been away for a few days.

Thanks for all of your help,

Ben

On 6 Oc
John Machin wrote:
 Steve Holden wrote:
  John Machin wrote:
   Ben wrote:
  
  Hello...
  
  I have set up a dictionary into whose values I am putting a list. I
  loop around and around filling my list each time with new values, then
  dumping this list into the dictionary. Or so I thought...
  
  It would appear that what I am dumping into the dictionary value is
  only a pointer to the original list, so after all my iterations all I
  have is a dictionary whose every value is equal to that of the list the
  final time I looped around :-(
  
  Is there a way to acheive what I was attempting ? I have done something
  almost identical with classes  in a list before, and in that case a new
  instance was created for each list entry...
  
  
  I hope this makes some sense, and doesn't seem to head bangingly
  simple...
  
  
  
   Do you consult your physician over a video link while wearing a ninja
   costume down an unlit coal mine at midnight?
  
   Please consider the possibility that your description of what you think
   your code might be doing is not enough for diagnosis.
  
   You may need to supply:
   (1) a listing of your code
   (2) a small amount of input data
  e.g. [(1, 'foo'), (42, 'bar'), (1, 'zot')]
   (3) the output you expect from that input:
  e.g. {1: ['foo', 'zot'], 42: ['bar']}
  
  One of the fascinating things about c.l.py is that sometimes a questin
  will be posted that makes almost no sense to me, and somebody else will
  casually read the OP's mind, home in on the issue and provide a useful
  and relevant answer.
 
  In this case it seems transparent to me, though probably not to you,
  that Ben's problem is rootd in the following behaviour, well-known in
  python but frequently confusing to noobs:
 
 a = [1, 2, 3]
 firstlist = a
 a.append('another element')
 firstlist
  [1, 2, 3, 'another element']

 

 It's quite transparent to me that his symptom is caused by the one list
 being used throughout the exercise, instead of one per different dict
 key. What you have described is one possibility.

 Here's another possibility: Making the charitable assumption that he
 has an outer loop and an inner loop, maybe (as I think another poster
 has already suggested) all he needs to do is move mylist = [] inside
 the outer loop. Note that he doesn't say explicitly whether the one
 list that he gets is the *correct* list for the last key, or whether
 it's the catenation of all the correct lists, or something else.

 Yet another: Noobs do all sorts of funny things. He could be operating
 on a clean the bucket out after each use instead making a new one
 paradigm:

 |  d= {}
 |  L = []
 |  L.append(1)
 |  L.append(2)
 |  d['a'] = L
 |  d
 | {'a': [1, 2]}
 |  del L[:]
 |  d
 | {'a': []}
 |  L.append(3)
 |  L.append(4)
 |  d['b'] = L
 |  d
 | {'a': [3, 4], 'b': [3, 4]}
 
 Cheers,
 John

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


Bizzare lst length problem

2006-10-08 Thread Ben
Hello...hopefully my last question :-)

I ave a dictionary, where each value is a class instance. I access it
using:

for k, v in self.panels.panel_list.items():
print Number:\t,v.number
print Level:\t,v.level
print Location:\t,v.location
print MOPS:\t,v.mops
print List length:\t,len(v.mops)
print Matrix:\t,v.matrix,\n\n

The output from this would be (for a given key value):
Number: 181
Level:  ovride+supvis
Location:mons=4 v8.0 3rd floor
MOPS:   ['287', '288', '289', '290']
List Length:28
Matrix: kng

This is really odd...my len(v.mops) ought to return 4 (4 elements in
the list). In fact it returns 28. looking at outputs from lots of
records, it seems that the length is almost always 7 time too great
(28/7=4)but not always. This is really confusing...can anyon
suggest what is going on?

I've been trying to output the list elements as a string with equally
limmited success, but the thing seems so simple I can't see where the
prblem might lie

Cheers,

Ben

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


Re: Bizzare lst length problem

2006-10-08 Thread Fredrik Lundh
Ben wrote:

 The output from this would be (for a given key value):
 Number:   181
 Level:ovride+supvis
 Location:  mons=4 v8.0 3rd floor
 MOPS: ['287', '288', '289', '290']
 List Length:  28
 Matrix:   kng
 
 This is really odd...my len(v.mops) ought to return 4 (4 elements in
 the list).

adding a

 print type(v.mops), repr(v.mops)

debug statement might provide you with the clues you need.

  In fact it returns 28. looking at outputs from lots of
 records, it seems that the length is almost always 7 time too great
 (28/7=4)but not always.

  len(['287',)
7
  len( '288',)
7
  len( '289',)
7
  len( '290'])
7

/F

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


sign in

2006-10-08 Thread Fulvio
***
Your mail has been scanned by InterScan MSS.
***



confirm 48f0beb37c698f0bb7b4c0327cf30dbd7a4b6335

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


Re: Scientific computing and data visualization.

2006-10-08 Thread [EMAIL PROTECTED]
  I can definitively second that. ROOT is a bit hard to learn but very,
  very powerful and PyRoot is really a pleasure to work with.

 It sounds interesting. Right now, I use matplotlib for
 2D plotting and vtk for 3D. Do you have any experience and
 can give some recommendations?

Hi Fabian!

I recommend using matplotlib for data visualization, because the usage
of the plotting commands is much(!!!) more convenient. In ROOT you have
to create objects before you can draw your diagrams. The constructor
often requires arguments about the number of space points, axis length,
name etc. On the other hand, the figure itself has a GUI to manipulate
the plot, which sometimes is nicer than doing everything in the script.
In particular the 3D visualization seems to be more comprehensive (lots
of drawing options, rotation of the plot with the mouse, changing of
visualization lego, surf, contour plots etc.).

ROOT has more than plotting. For example it has a whole bunch of
containers to store very large amounts of data (within complex
datastructures), fitting routines, minimizers etc. But you get that
with scipy and numpy.

I'm using 80% of the time matplotlib because it's much quicker for
quick glances at your data. If I need sophisitcated 3D plots, I use
ROOT, but I would love to switch to matplotlib for this, as well.

My guess is that using python and matplotlib with scipy speeds up my
work by at least 30% in comparison to using purely ROOT (and code in
C++). And even 10-15% in comparison to the usage of ROOT with pyRoot.

Enjoy! Bernhard

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


wxpython problems using GLCanvas

2006-10-08 Thread nelson
Hi,
  i'm coding a 3d interactive geometry progam and i want to use opengl
for displaying ogbjects. I can open a opengl canvas (i follow the
wxpython demo) and i can draw a cube. First time i execute the
application all is ok. second time it freezes X and i can't interact
with my machine. I hava only to press power button.. what will
cause it? the code i use is exactly the code of the demo

If using openGL is so difficult to do together with wxpython, what
toolkit can i use do do 3d graphics? Simple graphics, i have to plot
point, lines, sphere, surfaces and their intersections...

thanks,
  nelson

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


Re: need some regular expression help

2006-10-08 Thread Mirco Wahab
Thus spoke Diez B. Roggisch (on 2006-10-08 10:49):
 Certainly true, and it always gives me a hard time because I don't know
 to which extend a regular expression nowadays might do the job because
 of these extensions. It was so much easier back in the old times

Right, in perl, this would be a no-brainer,
its documented all over the place, like:

   my $re;

   $re = qr{
(?:
  (? [^\\()]+ | \\. )
   |
 \( (??{ $re }) \)
)*
}xs;

where you have a 'delayed execution'
of the

  (??{ $re })

which in the end makes the whole a thing
recursive one, it gets expanded and
executed if the match finds its way
to it.

Above regex will match balanced parens,
as in:

   my $good = 'a + (b / (c - 2)) * (d ^ (e+f))  ';
   my $bad1 = 'a + (b / (c - 2)  * (d ^ (e+f))  ';
   my $bad2 = 'a + (b / (c - 2)) * (d) ^ (e+f) )';

if you do:

   print ok \n if $good =~ /^$re$/;
   print ok \n if $bad1 =~ /^$re$/;
   print ok \n if $bad2 =~ /^$re$/;


This in some depth documented e.g. in
http://japhy.perlmonk.org/articles/tpj/2004-summer.html
(topic: Recursive Regexes)

Regards

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


Re: Names changed to protect the guilty

2006-10-08 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], John
Machin wrote:

 
 Steven D'Aprano wrote:
 On Fri, 06 Oct 2006 18:29:34 -0700, John Machin wrote:

 
  MonkeeSage wrote:
  On Oct 6, 8:02 pm, MonkeeSage [EMAIL PROTECTED] wrote:
   it is clearer to you to make the condition explicit (blah not
   False),
 
  blah not False - blah is False
 
  Whichever way your team wants to interpret it, d00d.
 
  Please consider whether you should be writing (blah is False) is
  True, that would be more explicit.

 Puh-lease! Get it right!

 It should be ((blah is False) is True) is True.

 
 Yes, but it stops after one more iteration. What I tell you three
 times is true -- the Bellman, The Hunting of the Snark, by Lewis
 Carroll.

But that was only said once, wasn't it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kde Taskbar

2006-10-08 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], David Boddie
wrote:

 I'd be interested in an example of how to use knotify via DCOP.

Found a tutorial here http://lukeplant.me.uk/articles.php?id=3.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some regular expression help

2006-10-08 Thread Diez B. Roggisch
Mirco Wahab schrieb:
 Thus spoke Diez B. Roggisch (on 2006-10-08 10:49):
 Certainly true, and it always gives me a hard time because I don't know
 to which extend a regular expression nowadays might do the job because
 of these extensions. It was so much easier back in the old times
 
 Right, in perl, this would be a no-brainer,
 its documented all over the place, like:
 
my $re;
 
$re = qr{
 (?:
   (? [^\\()]+ | \\. )
|
  \( (??{ $re }) \)
 )*
 }xs;
 
 where you have a 'delayed execution'
 of the
 
   (??{ $re })
 
 which in the end makes the whole a thing
 recursive one, it gets expanded and
 executed if the match finds its way
 to it.
 
 Above regex will match balanced parens,
 as in:
 
my $good = 'a + (b / (c - 2)) * (d ^ (e+f))  ';
my $bad1 = 'a + (b / (c - 2)  * (d ^ (e+f))  ';
my $bad2 = 'a + (b / (c - 2)) * (d) ^ (e+f) )';
 
 if you do:
 
print ok \n if $good =~ /^$re$/;
print ok \n if $bad1 =~ /^$re$/;
print ok \n if $bad2 =~ /^$re$/;
 
 
 This in some depth documented e.g. in
 http://japhy.perlmonk.org/articles/tpj/2004-summer.html
 (topic: Recursive Regexes)

That clearly is a recursive grammar rule, and thus it can't be regular 
anymore :) But first of all, I find it ugly - the clean separation of 
lexical and syntactical analysis is better here, IMHO - and secondly, 
what are the properties of that parsing? Is it LL(k), LR(k), backtracking?

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


Re: Newbie - Stuck

2006-10-08 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
 The perl version of this code works but not the python version. What am
 I doing wrong?
 
 message = abc
 password = z12
 
 scrambled = message ^ password
 
 I also wondered why this errored as well...
 
 int(messege)
 
 Is it not meant to convert a string to a number?

Including error messages  stacktraces helps tremendously when asking 
such questions - especially on a weekend, when our crystall balls are in 
maintenance in the elves headquarters at the north pole.

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


Re: need some regular expression help

2006-10-08 Thread bearophileHUGS
Fredrik Lundh wrote:

 it's slightly faster, but both your alternatives are about 10x slower
 than a straightforward:
 def balanced(txt):
  return txt.count(() == txt.count())

I know, but if you read my post again you see that I have shown those
solutions to mark )))((( as bad expressions. Just counting the parens
isn't enough.

Bye,
bearophile

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


Re: Newbie - Stuck

2006-10-08 Thread bearophileHUGS
[EMAIL PROTECTED]:

Python is strongly typed, and it converts types automatically less
often than Perl.
The purpose of such strong(er) typing is to allow to catch some kind of
bugs, and to make the syntax simpler, more readable, etc.

 message = abc
 password = z12
 scrambled = message ^ password

^ is defined among integers:
 55 ^ 126
73

You need more explicit code like:

 msg = abc
 pwd = z12
 [ord(c1) ^ ord(c2) for c1,c2 in zip(msg, pwd)]
[27, 83, 81]
 [chr(ord(c1)^ord(c2)) for c1,c2 in zip(msg, pwd)]
['\x1b', 'S', 'Q']
 .join( chr(ord(c1)^ord(c2)) for c1,c2 in zip(msg, pwd) )
'\x1bSQ'


 I also wondered why this errored as well...
 int(messege)
 Is it not meant to convert a string to a number?

You can use int to truncate a float to int, or a string containing an
int to int (it accepts an optional base too):

 int(55)
55
 int(5.23)
5
 int(5.23)
Traceback
  ...
ValueError: invalid literal for int() with base 10: '5.23'
 int(abc)
Traceback
  ...

Bye,
bearophile

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


Re: Names changed to protect the guilty

2006-10-08 Thread John Machin

Lawrence D'Oliveiro wrote:
 In message [EMAIL PROTECTED], John
 Machin wrote:

 
  Steven D'Aprano wrote:
  On Fri, 06 Oct 2006 18:29:34 -0700, John Machin wrote:
 
  
   MonkeeSage wrote:
   On Oct 6, 8:02 pm, MonkeeSage [EMAIL PROTECTED] wrote:
it is clearer to you to make the condition explicit (blah not
False),
  
   blah not False - blah is False
  
   Whichever way your team wants to interpret it, d00d.
  
   Please consider whether you should be writing (blah is False) is
   True, that would be more explicit.
 
  Puh-lease! Get it right!
 
  It should be ((blah is False) is True) is True.
 
 
  Yes, but it stops after one more iteration. What I tell you three
  times is true -- the Bellman, The Hunting of the Snark, by Lewis
  Carroll.
 
 But that was only said once, wasn't it?

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


Re: Painless way to do 3D visualization

2006-10-08 Thread Peter Beattie
faulkner wrote:
 http://www.vpython.org/

Oh, thanks, but let me quote myself:

 So far, I've only tinkered a little with VPython, but the lack
 of any decent documentation has proved to be a major turn-off.

So, I'd really appreciate any hints as to where to look for anything a
little more usable.

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
Ah... my list is a string. That explains the len() results, but not why
it is a string in the dirst place.

I have a dictionary containing a number of instances of the following
class as values:

class panel:
mops =[]

def __init__(self,number,level,location,mops,matrix):
 self.number=number
 self.level=level
 self.location=location
 self.mops=mops
 self.matrix=matrix


abve mops is a list, yet when I access it it is a string...



Fredrik Lundh wrote:
 Ben wrote:

  The output from this would be (for a given key value):
  Number: 181
  Level:  ovride+supvis
  Location:mons=4 v8.0 3rd floor
  MOPS:   ['287', '288', '289', '290']
  List Length:28
  Matrix: kng
 
  This is really odd...my len(v.mops) ought to return 4 (4 elements in
  the list).

 adding a

  print type(v.mops), repr(v.mops)

 debug statement might provide you with the clues you need.

   In fact it returns 28. looking at outputs from lots of
  records, it seems that the length is almost always 7 time too great
  (28/7=4)but not always.

   len(['287',)
 7
   len( '288',)
 7
   len( '289',)
 7
   len( '290'])
 7
 
 /F

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


Re: Newbie - Stuck

2006-10-08 Thread Paddy
[EMAIL PROTECTED] wrote:
 The perl version of this code works but not the python version. What am
 I doing wrong?

 message = abc
 password = z12

 scrambled = message ^ password

 I also wondered why this errored as well...

 int(messege)

 Is it not meant to convert a string to a number?
Hmm,
Looks like you need to learn more elementary Python before we can even
attempt to help you more, but here goes anyway...

Python has strict typing compared to Perl (a good thing)!
The string abc is not a valid representation of an integer in Python,
 and, unlike Perl, Python will complain about its use when an integer
is expected:

$ perl -e 'print abc ^ 123, \n'
123

$ python -c 'print abc ^ 123'
Traceback (most recent call last):
  File string, line 1, in ?
TypeError: unsupported operand type(s) for ^: 'str' and 'int'

$

Please don't give up on Python. It *is* different to Perl. 

- Paddy.

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


Re: Names changed to protect the guilty

2006-10-08 Thread John Machin

Lawrence D'Oliveiro wrote:
 In message [EMAIL PROTECTED], John
 Machin wrote:

 
  Steven D'Aprano wrote:
  On Fri, 06 Oct 2006 18:29:34 -0700, John Machin wrote:
 
  
   MonkeeSage wrote:
   On Oct 6, 8:02 pm, MonkeeSage [EMAIL PROTECTED] wrote:
it is clearer to you to make the condition explicit (blah not
False),
  
   blah not False - blah is False
  
   Whichever way your team wants to interpret it, d00d.
  
   Please consider whether you should be writing (blah is False) is
   True, that would be more explicit.
 
  Puh-lease! Get it right!
 
  It should be ((blah is False) is True) is True.
 
 
  Yes, but it stops after one more iteration. What I tell you three
  times is true -- the Bellman, The Hunting of the Snark, by Lewis
  Carroll.

 But that was only said once, wasn't it?

And the Bellman made no statement at all about the truthfulness of
statements made any other number of times than three.

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
...and when I print out the string, it is still formatted as one would
expect a list to be:

type 'str' ['01', '02', '03', '04']



Ben wrote:
 Ah... my list is a string. That explains the len() results, but not why
 it is a string in the dirst place.

 I have a dictionary containing a number of instances of the following
 class as values:

 class panel:
 mops =[]

 def __init__(self,number,level,location,mops,matrix):
  self.number=number
  self.level=level
  self.location=location
  self.mops=mops
  self.matrix=matrix


 abve mops is a list, yet when I access it it is a string...



 Fredrik Lundh wrote:
  Ben wrote:
 
   The output from this would be (for a given key value):
   Number:   181
   Level:ovride+supvis
   Location:  mons=4 v8.0 3rd floor
   MOPS: ['287', '288', '289', '290']
   List Length:  28
   Matrix:   kng
  
   This is really odd...my len(v.mops) ought to return 4 (4 elements in
   the list).
 
  adding a
 
   print type(v.mops), repr(v.mops)
 
  debug statement might provide you with the clues you need.
 
In fact it returns 28. looking at outputs from lots of
   records, it seems that the length is almost always 7 time too great
   (28/7=4)but not always.
 
len(['287',)
  7
len( '288',)
  7
len( '289',)
  7
len( '290'])
  7
  
  /F

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


Re: Bizzare lst length problem

2006-10-08 Thread John Machin

Ben wrote:
 Ah... my list is a string. That explains the len() results, but not why
 it is a string in the dirst place.

 I have a dictionary containing a number of instances of the following
 class as values:

 class panel:
 mops =[]

 def __init__(self,number,level,location,mops,matrix):
  self.number=number
  self.level=level
  self.location=location
  self.mops=mops
  self.matrix=matrix


 abve mops is a list, yet when I access it it is a string...


Well, if you are going to spare us from reading all of your code,
you'll have to debug it yourself. The clue that Fredrik gave you is
*not* of the use-once-and-discard variety -- when you are having
problems with the pixies changing your lists into strings, you need to
sprinkle prints of type(pixie_prey) and repr(pixie_prey) at salient
points in your code; as first statement in that __init__ method would
be a good start.

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


Re: Bizzare lst length problem

2006-10-08 Thread John Machin

Ben wrote:
 Ah... my list is a string. That explains the len() results, but not why
 it is a string in the dirst place.

 I have a dictionary containing a number of instances of the following
 class as values:

 class panel:
 mops =[]

 def __init__(self,number,level,location,mops,matrix):
  self.number=number
  self.level=level
  self.location=location
  self.mops=mops
  self.matrix=matrix


 abve mops is a list, yet when I access it it is a string...


Well, if you are going to spare us from reading all of your code,
you'll have to debug it yourself. The clue that Fredrik gave you is
*not* of the use-once-and-discard variety -- when you are having
problems with the pixies changing your lists into strings, you need to
sprinkle prints of type(pixie_prey) and repr(pixie_prey) at salient
points in your code; as first statement in that __init__ method would
be a good start.

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
Thanks for the advice  - I'm already doing just that, so hopefully will
soon be sorted :-p


John Machin wrote:
 Ben wrote:
  Ah... my list is a string. That explains the len() results, but not why
  it is a string in the dirst place.
 
  I have a dictionary containing a number of instances of the following
  class as values:
 
  class panel:
  mops =[]
 
  def __init__(self,number,level,location,mops,matrix):
   self.number=number
   self.level=level
   self.location=location
   self.mops=mops
   self.matrix=matrix
 
 
  abve mops is a list, yet when I access it it is a string...
 

 Well, if you are going to spare us from reading all of your code,
 you'll have to debug it yourself. The clue that Fredrik gave you is
 *not* of the use-once-and-discard variety -- when you are having
 problems with the pixies changing your lists into strings, you need to
 sprinkle prints of type(pixie_prey) and repr(pixie_prey) at salient
 points in your code; as first statement in that __init__ method would
 be a good start.

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


Re: Bizzare lst length problem

2006-10-08 Thread John Machin

Ben wrote:
 ...and when I print out the string, it is still formatted as one would
 expect a list to be:

 type 'str' ['01', '02', '03', '04']


We know that. Fredrik deduced it and told you well over an hour ago.

Show us the code that is creating instances of the panel class ...

panel1 =
panel(number=?,level=?,location=?,mops=,matrix=?)
What are you passing as the 4th positional arg
^^^ ???

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
Using Fredericks advice I managed to track down the problem - it was
really very stupid. I had accidentally cast the list to a string
earlier in another part of the code. Its a bit of an anticlimax really
- not mysterious at all (just mysteriously remiss on my part)

Apologies for not simple posting the entire code earlier on - but
thanks for everyone for puttin up with me, and in particular to
Frederick for his very useful hint :-)

Cheers,

Ben


John Machin wrote:
 Ben wrote:
  ...and when I print out the string, it is still formatted as one would
  expect a list to be:
 
  type 'str' ['01', '02', '03', '04']
 

 We know that. Fredrik deduced it and told you well over an hour ago.

 Show us the code that is creating instances of the panel class ...

 panel1 =
 panel(number=?,level=?,location=?,mops=,matrix=?)
 What are you passing as the 4th positional arg
 ^^^ ???

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


Re: Bizzare lst length problem

2006-10-08 Thread Theerasak Photha
On 8 Oct 2006 06:12:48 -0700, John Machin [EMAIL PROTECTED] wrote:


 Show us the code that is creating instances of the panel class ...

 panel1 =
 panel(number=?,level=?,location=?,mops=,matrix=?)
 What are you passing as the 4th positional arg
 ^^^ ???

This is wholly unnecessary.

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


Re: Bizzare lst length problem

2006-10-08 Thread John Machin

Theerasak Photha wrote:
 On 8 Oct 2006 06:12:48 -0700, John Machin [EMAIL PROTECTED] wrote:

 
  Show us the code that is creating instances of the panel class ...
 
  panel1 =
  panel(number=?,level=?,location=?,mops=,matrix=?)
  What are you passing as the 4th positional arg
  ^^^ ???

 This is wholly unnecessary.
 
 -- Theerasak


What is wholly unnecessary?

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


Re: Bizzare lst length problem

2006-10-08 Thread Ben
Ah - I found out why I had cast it to a string. I had not, at that
point, worked out ho to pass the list by value rather than reference,
and so was casting to a string as a stopgap measure that I then forgot
about. Now the problem is fixed after this group told me how to pass a
list by value (by slicing the entire list)


John Machin wrote:

 Theerasak Photha wrote:
  On 8 Oct 2006 06:12:48 -0700, John Machin [EMAIL PROTECTED] wrote:
 
  
   Show us the code that is creating instances of the panel class ...
  
   panel1 =
   panel(number=?,level=?,location=?,mops=,matrix=?)
   What are you passing as the 4th positional arg
   ^^^ ???
 
  This is wholly unnecessary.
  
  -- Theerasak
 
 
 What is wholly unnecessary?

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


Re: need some regular expression help

2006-10-08 Thread Roy Smith
Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Certainly true, and it always gives me a hard time because I don't know
 to which extend a regular expression nowadays might do the job because
 of these extensions. It was so much easier back in the old times

What old times?  I've been working with regex for mumble years and there's 
always been the problem that every implementation supports a slightly 
different syntax.  Even back in the good old days, grep, awk, sed, and ed 
all had slightly different flavors.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some regular expression help

2006-10-08 Thread Theerasak Photha
On 10/8/06, Roy Smith [EMAIL PROTECTED] wrote:
 Diez B. Roggisch [EMAIL PROTECTED] wrote:
  Certainly true, and it always gives me a hard time because I don't know
  to which extend a regular expression nowadays might do the job because
  of these extensions. It was so much easier back in the old times

 What old times?  I've been working with regex for mumble years and there's
 always been the problem that every implementation supports a slightly
 different syntax.  Even back in the good old days, grep, awk, sed, and ed
 all had slightly different flavors.

Which grep? Which awk? :)

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


Re: Bizzare lst length problem

2006-10-08 Thread Fredrik Lundh
Ben wrote:

 Ah - I found out why I had cast it to a string. I had not, at that
 point, worked out ho to pass the list by value rather than reference,
 and so was casting to a string as a stopgap measure that I then forgot
 about. Now the problem is fixed after this group told me how to pass a
 list by value (by slicing the entire list)

if you write code that needs to treat a list as a distinct mutable 
value, make sure *your* code makes a copy.  relying on the caller to 
remember to do that in all cases is way too error prone.

in other words, instead of doing

def function(seq):
# modify the sequence

...

# must pass in a copy, or things will break in mysterious ways
function(list(mylist))

do

def function(seq):
seq = list(seq) # make a distinct copy
# modify the sequence

...

function(seq)

/F

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


Re: Bizzare lst length problem

2006-10-08 Thread John Machin

Ben wrote:
 Ah - I found out why I had cast it to a string. I had not, at that
 point, worked out ho to pass the list by value rather than reference,
 and so was casting to a string as a stopgap measure that I then forgot
 about. Now the problem is fixed after this group told me how to pass a
 list by value (by slicing the entire list)


All argument passing is by reference. What you are calling pass a list
by value is actually two steps:

(1) make a copy of a list
(2) pass a reference to the copy

At the C implementation level, it's a (PyObject *) -- the address of
the object.

HTH,
John

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


Re: Kde Taskbar

2006-10-08 Thread David Boddie
On Sunday 08 October 2006 14:16, Lawrence D'Oliveiro wrote:

 In message [EMAIL PROTECTED], David Boddie
 wrote:
 
 I'd be interested in an example of how to use knotify via DCOP.
 
 Found a tutorial here http://lukeplant.me.uk/articles.php?id=3.

Thanks for the link. Maybe the original poster can use something
from the tutorial if the window activation trick doesn't work.

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


Re: Encoding and norwegian (non ASCII) characters.

2006-10-08 Thread Paul Boddie
[EMAIL PROTECTED] wrote:

 I am having great problems writing norwegian characters æøå to file
 from a python application. My (simplified) scenario is as follows:

 1. I have a web form where the user can enter his name.

 2. I use the cgi module module to get to the input from the user:
 
 name = form[name].value

The cgi module should produce plain strings, not Unicode objects, which
makes some of the later behaviour quite interesting.

 3. The name is stored in a file

 fileH = open(namefile , a)
 fileH.write(name:%s \n % name)
 fileH.close()

 Now, this works very well indeed as long the users have 'ascii' names,
 however when someone enters a name with one of the norwegian characters
 æøå - it breaks at the write() statement.

UnicodeDecodeError: 'ascii' codec can't decode byte 0x8f in position

This is odd, since writing plain strings to files shouldn't involve any
Unicode conversions. If you received a plain string from the cgi
module, the text you write to the file should still be a plain string.
This is like obtaining a sequence of bytes and just passing them
around. Perhaps your Python configuration is different in some
non-standard way, although I wouldn't want to point the finger at
anything in particular (although sys.getdefaultencoding might suggest
something).

 Now - I understand that the ascii codec can't be used to decode the
 particular characters, however my attempts of specifying an alternative
 encoding have all failed.

 I have tried variants along the line:

fileH = codecs.open(namefile , a , latin-1) / fileH = open(namefile , 
 a)
fileH.write(name)   /fileH.write(name.encode(latin-1))

 It seems *whatever* I do the Python interpreter fails to see my pledge
 for an alternative encoding, and fails with the dreaded
 UnicodeDecodeError.

To use a file opened through codecs.open, you really should present
Unicode objects to the write method. Otherwise, I imagine that the
method will try and automatically convert to Unicode the plain string
that the name object supposedly is, and this conversion will assume
that the string only contains ASCII characters (as is Python's default
behaviour) and thus cause the error you are seeing. Only after getting
the text as a Unicode object will the method then try to encode the
text in the specified encoding in order to write it to the file.

In other words, you'll see this behaviour:

  name (plain string) - Unicode object - encoded text (written to
file)

Or rather, in the failure case:

  name (plain string) - error! (couldn't produce the Unicode object)

As Peter Otten suggests, you could first make the Unicode object
yourself, stating explicitly that the name object contains latin-1
characters. In other words:

  name (plain string) - Unicode object

Then, the write method has an easier time:

  Unicode object - encoded text (written to file)

All this seems unnecessary for your application, I suppose, since you
know (or believe) that the form values only contain latin-1
characters. However, as is the standard advice on such matters, you may
wish to embrace Unicode more eagerly, converting plain strings to
Unicode as soon as possible and only converting them to text in various
encodings when writing them out.

In some Web framework APIs, the values of form fields are immediately
available as Unicode without any (or much) additional work. WebStack
returns Unicode objects for form fields, as does the Java Servlet API,
but I'm not particularly aware of many other Python frameworks which
enforce or promote such semantics.

Paul

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


Re: Python to use a non open source bug tracker?

2006-10-08 Thread Ilias Lazaridis
Ben Finney wrote:
 Ilias Lazaridis [EMAIL PROTECTED] writes:

  As for Mr. Holden... it's not a matter of not respecting you.
  It is in his nature to babble in this way.
  Sometimes it's even funny!

 Oh my. You have *seriously* misjudged this group if you think that
 comment will give you any net gain in discussions here.

I'm not interested in any gain (except within the systems that I
produce).

My intention was mainly to place myself on the side of the OP, before
the 'Herd of Savages' (the 'Regular Posters') get's out of control and
eat's him.

.

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


Re: operator overloading + - / * = etc...

2006-10-08 Thread SpreadTooThin

Daniel Nogradi wrote:
  Can these operators be overloaded?
  If so.  How?
 

 http://www.python.org/doc/ref/numeric-types.html
 
 HTH,
 Daniel

Thanks everyone.

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


Re: Painless way to do 3D visualization

2006-10-08 Thread Ron Adam
Peter Beattie wrote:
 Hey folks,
 
 I need to do the following relatively simple 3D programming:
 
 I want to convert data from four-item tuples into 3D co-ordinates in a
 regular tetrahedron. Co-ordinates come in sequences of 10 to 20, and the
 individual dots in the tetrahedron need to be connected into
 discontinuous lines. A single tetrahedron should contain at least two,
 possibly more, such lines. I would like to show certain similarities in
 the sequences/lines, eg by changing color, thickness, or maybe attaching
 indeces to certain points in a particular sequence.
 
 I'd welcome suggestions as to what might be the most painless way to
 achieve this in Python. So far, I've only tinkered a little with
 VPython, but the lack of any decent documentation has proved to be a
 major turn-off.
 
 TIA!

What exactly are the four-items in the tuples?


I think this is what you need along with an example...


  http://www.vpython.org/webdoc/visual/curve.html




from visual import *

# a simple polygon

points = [(0,0,0),(0,1,0),(1,1,0),(1,0,0),(0,0,0)]
curve(pos=points, color=color.red)


# a polygon as separate segments grouped together in a frame.

square2 = frame()
points = [(0,0,1),(0,1,1),(1,1,1),(1,0,1),(0,0,1)]
for i in xrange(len(points)-1):
 curve(frame=square2, pos=[points[i],points[i+1]], color=color.blue)
square2.objects[2].color = color.green   # change a line segments color
square2.objects[2].radius = .02  # change a line segments thickness


# looking at objects after they are made.
print square2
print dir(square2)
print square2.objects
print dir(square2.objects[0])


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


SqlAlchemy how and where it can be used?

2006-10-08 Thread tomec
hello,

Ive read some articles about SqlAlchemy but i don't know where i can
use this?
Lets say that i would like to create some application which will be
using sqlAlchemy My question is
which programming language can i code to use it? (only Python)? Do you
know any good python editors which supports SqlAlchemy?

I would be gratefull for any kind of help
Best regards

Tom Agents

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


Re: missing has_column_major_storage

2006-10-08 Thread Robert Kern
Dave wrote:
 hello
I have intalled the Enthought Edition 1.0.0, when i successed use
 f2py compile my fortran file to python module. But when I call
 has_column_major_storage function in the extended module. it's cannot
 find. has_column_major_storage function function have been remove
 from numpy/f2py ?? how can i change the array storage C to Fortran
 type??

Possibly. Please ask on the numpy list, though.

http://www.scipy.org/Mailing_Lists

-- 
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


recommendations for personal journaling application

2006-10-08 Thread Donnie Rhodes
Hi. I've been sort of standing back on the sidelines reading this list
for awhile, and this is my first posting. So a little about myself and
my skill level. My name is Bryan. I'm new to Python and have very
little experience. I've gone through a few of the tutorials. I
understand the different data-types, basic syntax, functions and
function definition, basic iteration, and calling from modules.

I might be getting ahead of myself, but I think the best way for me to
learn things is by having a goal and working towards it. My goal is to
create a personal command line journaling application. I would like to
store all the entries in one file, have them searchable by keywords,
date, topic, etc... I think I would like to use /* type commands. For
instance, you call the application from a terminal window and start
with a generic prompt. You would type '/ne /t topic' to begin a new
entry and assign the topic; '/d' to set a date. You should be able to
use the slash commands while editing as well. For instance while
writing in an entry you could isolate a phrase or word with /k phrase
to be marked as searchable keyword / to mark the enclosed text as a
searchable keyword/keyphrase.

So what I'm interested in is how this would work. Is this 'event
driven' in nature? Would I define the bulk of these slash commands in a
function and then call it at the end of the script? What would be a
good module to look at for the text processing and searching aspects?
Anyways, I'm not sure how you would create a program that would
listen for commands and then parse them accordingly. I think for
starters I will sketch out on paper the slash commands I need, and try
to break apart the general operations into pseudo code. How would you
all approach this?

Thank you all and I hope I'm not biting off too much at once...

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


Re: A critique of cgi.escape

2006-10-08 Thread Scott David Daniels
Lawrence D'Oliveiro wrote:
 Another useful function is this:
 
 def JSString(Str) :
 returns a JavaScript string literal that evaluates to Str

You can do this more simply:

 _map = {\\ : , \ : \\\, \t : \\t, \n : \\n}
 def JSString(Str) :
 mapped = [_map.get(Ch, Ch) for Ch in Str]
 return \ + .join(mapped) + \



-- 
--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: ChiPy Thurs. October 12, 2006. 7pm @ Performics 180 N. Lasalle

2006-10-08 Thread Chris McAvoy
Join us for our best meeting ever!

Thurs. October 12th, 2006. 7pm.

Topics
-
* PLY (Python Lex Yacc) David Beazley
* Performance Python (without PyPy) Michael Tobis

Location

Performics  180 N. Lasalle 12th floor. Chicago RSVP (for building
security) by Tuesday night to [EMAIL PROTECTED] with subject
RSVP Chipy

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


Re: Can't get around IndexError: list index out of range

2006-10-08 Thread MonkeeSage

On Oct 8, 5:57 am, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 No, *less* often. That's the point -- it is fairly common for people to
 want dictionary lookup to return a default value, but quite rare for them
 to want sequence lookup to return a default value. A sequence with a
 default value would be, in some sense, equivalent to an infinite list:

Ah, yes. Infinite dictionaries are much better! I guess you could think
of it like providing a infinitely indexed list (or infinitely keyed
dict), but a better way to think of it is as providing a
non-terminating exception where the default value is the exceptional
case. And I don't see why it would be so rare to do something like:

if sys.argv.get(1): ...

With list.has_index() / get(), the following (pretty common I think)
idiom:

try:
  data = some_unknown_seq[2]
except IndexError:
  data = None
if data: ...

Can become:

data = some_unknown_seq.get(2)
if data: ...

Perhaps list.get() wouldn't be used as often as dict.get(), but it
would be used a fair amount I think. Looking at the standard library
(2.5 source), I find 30 places where except IndexError appears, and
two places where a comment says that some method raises IndexError on
some condition. I haven't looked at the context of them, but I'd wager
that many of them would benefit from list.has_index() and / or get().
Here is my script to search the libs:

import os, re
found = {}
for path, dirs, files in os.walk('./Lib'):
  for afile in files:
afile = open(os.path.join(path, afile))
lines = afile.readlines()
afile.close()
for line in lines:
  match = re.search(r'((except|raises) IndexError)', line)
  if match:
found[afile.name] = match.group(1)
for item in found.items():
  print '%s (%s)' % item
print 'Found %d matches' % len(found)

 dict.get() doesn't raise KeyError. That's the whole point of get(), it
 returns a default value instead of raising KeyError.

Right. Exactly. Accessing a non-existent key raises a KeyError, but
dict.get() short-curcuits the exception and gives you a default value
(which is None unless explicitly changed). So instead of trying the key
and catching a KeyError, you can use a simple conditional and ask if
d.has_key(key), or assign d.get(key) and test the assignee. So, why
isn't there a list.has_index() / get()?

 If you don't care enough to even make a formal feature
 request, let alone a PEP, then why should people who care even less
 actually write the code?

I'm thinking about it. I just wanted to see if anyone knew of, or could
come up with, a good reason why it isn't / shouldn't be there.
Apparently not (at least not one that doesn't also bite the dict
convenience methods), so I'll probably go ahead and make a feature
request in the next few days.

Regards,
Jordan

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


references and buffer()

2006-10-08 Thread km

Hi all,

was looking at references in python...
 a = 10
 b = a
 id(a)
153918788
id(b)
153918788

where a and b point to the same id. now is this id an address ? 
can one dereference a value based on address alone in python?
is id similar to the address of a variable or a class ? 

read abt buffers as a refernce to a buffer object. 
actually i tried passing list and dict types to buffer function, but only with string type i could createa buffer reference,
y = 'GATCGTACC'
x = buffer(y, 0,8)
 x
read-only buffer for 0xbf4cd3b8, size 8, offset 2 at 0xbf4cf0e0
print x
TCGTACC
 id(y)
-1085484104
 id(x)
-1085476384

now the ids of y and x are not the same - why ? 
In which situatons are buffers used against the strings ? 
can i create a write buffer instead of readonly buffer ?
what exactly are buffer object types ? and how can i instantiate them ? 

regards,
KM

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

Re: Can't get around IndexError: list index out of range

2006-10-08 Thread Fredrik Lundh
MonkeeSage wrote:

 With list.has_index() / get(), the following (pretty common I think)
 idiom:
 
 try:
   data = some_unknown_seq[2]
 except IndexError:
   data = None
 if data: ...

umm.  you could at least write:

 try:
 data = some_unknown_seq[2]
 except IndexError:
 pass
 else:
 ... deal with data ...

but let's hypergeneralize and treat sequences and mappings as the same 
thing proposals are nothing new; a trip to the archives might be help-
ful.

/F

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


print time comparison: IDLE versus terminal on ultra 20

2006-10-08 Thread sam
hi all,

i continue to footle around on my spanking new ultra 20 (1.8GHz /
Opteron Model 144), gradually trying to get to grips with python and
unix both.

the slow print time in IDLE had already struck me as rather odd.
running programs with heavy print requirements from the terminal was a
major discovery though, printing being so fast as to make everything
appear at once except in the case of literally thousands of items to be
printed.

test case:

import time

time1 = time.time()
for i in range(100):
print 'go get \'em, son!'
time2 = time.time()

print time2-time1


in IDLE:
4.433 seconds

in terminal:
0.001 seconds

a difference of between 3 and 4 orders of magnitude is rather striking.
anyone know what's going on here? is it a python, a unix thing, or
something else?

sam

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


Re: references and buffer()

2006-10-08 Thread Fredrik Lundh
km wrote:
 
 Hi all,
 
 was looking at references  in python...
   a = 10
   b = a
   id(a)
 153918788
  id(b)
 153918788
 
 where a and b point to the same id. now is this id an address ?

no, it's the object identity, and all it tells you is that both names 
point to the same object.

 can one dereference a value based on address alone in python?

no.

 is id similar to the address of a variable or a class ?

in the CPython implementation, it's the address where the object is 
stored.  but that's an implementation detail.

/F

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


Re: print time comparison: IDLE versus terminal on ultra 20

2006-10-08 Thread Fredrik Lundh
sam wrote:

 in IDLE:
 4.433 seconds

IDLE is designed for tinkering, not fast handling of non-trivial amounts 
  of output (it runs your program in a separate process and pipes data 
to the interactive window over the network.  and the interactive seems 
to be redrawing the display for every line that arrives...)

but on the other hand, IDLE runs your sample script in less than 0.5 
seconds on my cheap Windows box.  complain to Sun ;-)

/F

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


Re: references and buffer()

2006-10-08 Thread Theerasak Photha
On 10/8/06, km [EMAIL PROTECTED] wrote:

  Hi all,

  was looking at references  in python...
   a = 10
   b = a
id(a)
  153918788
  id(b)
  153918788

  where a and b point to the same id. now is this id an address ?

The id may be considered similar to an address in C, etc. slightly
different but conceptually close.

  can one dereference a value based on address alone in python?

Not to my knowledge. Generally speaking, you wouldn't want to anyway.

  is id similar to the address of a variable or a class ?

Exactly. Similar. Not the same, but similar.

  read abt buffers as a refernce to a buffer object.
  actually i tried passing list and dict types to buffer function, but only
 with string type i could createa buffer reference,
  y = 'GATCGTACC'
  x = buffer(y, 0,8)
   x
  read-only buffer for 0xbf4cd3b8, size 8, offset 2 at 0xbf4cf0e0
  print x
  TCGTACC
   id(y)
  -1085484104
   id(x)
  -1085476384

  now the ids of y and x are not the same - why ?

You assigned two different object values to these names. In Python, a
name is just a name. It can point at any object. This relation becomes
very clear with mutable objects.

 x = {'foo':42, 'bar':69}
 id(x)
1076761980
 y = x
 y['baz'] = 36
 id(y)
1076761980
 y
{'baz': 36, 'foo': 42, 'bar': 69}
 x
{'baz': 36, 'foo': 42, 'bar': 69}

When I wrote y = x, all I did was make the variable y point to the
dictionary object x is also pointing at. Hence they point to the same
object. Things would be different if I decided to copy an object
instead:

 x = {'foo':42, 'bar':69}
 import copy
 y = copy.deepcopy(x)
 y['baz'] = 36
 id(x)
1076761164
 id(y)
1076890180
 x
{'foo': 42, 'bar': 69}
 y
{'baz': 36, 'foo': 42, 'bar': 69}

Since your name is Sri Krishna, an avatar of Vishnu, the concept
should be familiar. Variables are like avatars; they represent the
object (whether this is a humble dictionary or Vishnu the Preserver)
for the user, and serve as a bridge between the computer and the user,
as an avatar of Vishnu is a bridge between the physical world and the
supernatural.

Dasha Avatar -- one god. Think about it.

  what exactly are buffer object types ? and how can i instantiate them ?

If you want to get a line of user input, the basic function is raw_input().

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


Re: Painless way to do 3D visualization

2006-10-08 Thread Erik Max Francis
Peter Beattie wrote:

 faulkner wrote:
 http://www.vpython.org/
 
 Oh, thanks, but let me quote myself:
 
 So far, I've only tinkered a little with VPython, but the lack
 of any decent documentation has proved to be a major turn-off.
 
 So, I'd really appreciate any hints as to where to look for anything a
 little more usable.

There's also ZOE:

http://www.alcyone.com/software/zoe/

but if a lack of documentation turned you off to VPython then ZOE is 
probably not for you either.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
  San Jose, CA, USA  37 20 N 121 53 W  AIM, Y!M erikmaxfrancis
   No need to tell her there's a world out there / She knows / She just
doesn't seem worried at all -- Nik Kershaw
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: recommendations for personal journaling application

2006-10-08 Thread Karsten W.
Hi!

Donnie Rhodes wrote:
 So what I'm interested in is how this would work. Is this 'event
 driven' in nature? Would I define the bulk of these slash commands in a
 function and then call it at the end of the script? What would be a
 good module to look at for the text processing and searching aspects?

For implementing the commandline interface, have a look at the getopt
module.

If you store your data in a flat text file, you might use string.find()
or the re module to do the searching. The re module can search case
insensitive and is more versatile.

But maybe you want let your script create some SQL statements and use
the pysqlite module to store and search the data.

Kind regards,
Karsten.

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


Re: Newbie - Stuck

2006-10-08 Thread r3bol

Thanks everyone. I guess I was a little quick to think I could jump
straight into Python. I understand the principals of what was said but
not the code just yet. I was always under the impression that python
was a cleaned up version of perl. I guess this excercise put me
straight! I will try and get through a lot more beginners tutorials
before attempting a stunt like that again ;)
Python has surprised me already (a good thing!)
Regards.

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


Re: references and buffer()

2006-10-08 Thread km
Hi all,
in the CPython implementation, it's the address where the object isstored.but that's an implementation detail.

ok so can i point a vairiable to an address location just as done in C language ? 
 y = 'ATGCATGC'
 x = buffer(y)
 del(y)
 x
read-only buffer for 0xbf4cf0e0, size -1, offset 0 at 0xbf4cf240
 print x
ATGCATGC

now even when i delete y, why is that x still exists ? 
thats true even in the case of vairable assignment which states it a a reference !
 a = 10
 b = a
 del(a)
 b
10
i always thought if u modify the referred variable/buffer object it
should be reflected in the referenced variables/buffers objects . am i
wrong ? 
does it mean that references in python are not true references ? 

regards,
KM


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

Re: references and buffer()

2006-10-08 Thread Carl Friedrich Bolz
Fredrik Lundh wrote:
[snip]
 is id similar to the address of a variable or a class ?

 in the CPython implementation, it's the address where the object is
 stored.  but that's an implementation detail.

Just as an obscure sidenote, in PyPy it is ~address some of the time.
This is due to the fact that since PyPy can use the Boehm garbage
collector. The Boehm collector is conservative and therefore has to
assume that everything in RAM could be a pointer. Now if somebody stores
the id of an object the GC could not distinguish this from a real pointer
if id returned the address, which would keep the object alive.

/sidenode

Cheers,

Carl Friedrich Bolz

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


Re: Newbie - Stuck

2006-10-08 Thread Paul Rubin
[EMAIL PROTECTED] writes:
 Thanks everyone. I guess I was a little quick to think I could jump
 straight into Python.

Well, if you're willing to try diving into it instead of jumping, you
might like

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


Re: references and buffer()

2006-10-08 Thread Fredrik Lundh
km wrote:

 ok so can i point a vairiable to an address location just as done in C 
 language ?

no.  there are no C-style variables in Python; just objects and names 
bound to objects.  Python variables are names, not memory locations.

   y = 'ATGCATGC'
   x = buffer(y)
   del(y)
   x
 read-only buffer for 0xbf4cf0e0, size -1, offset 0 at 0xbf4cf240
   print x
 ATGCATGC
 
 now even when i delete y,  why is that x still exists ?

because it's an object.

 thats true even in the case of vairable assignment which states it a a 
 reference !
   a = 10
   b = a
   del(a)
   b
 10
 i always thought if u modify the referred variable/buffer object it 
 should be reflected in the referenced variables/buffers objects . am i 
 wrong ?

reset your brain:

 http://effbot.org/zone/python-objects.htm

/F

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


Re: references and buffer()

2006-10-08 Thread Theerasak Photha
On 10/8/06, km [EMAIL PROTECTED] wrote:
 Hi all,


  in the CPython implementation, it's the address where the object is
  stored.  but that's an implementation detail.

   ok so can i point a vairiable to an address location just as done in C
 language ?
   y = 'ATGCATGC'
   x = buffer(y)
   del(y)
   x
  read-only buffer for 0xbf4cf0e0, size -1, offset 0 at 0xbf4cf240
   print x
  ATGCATGC

  now even when i delete y,  why is that x still exists ?

Say that you copy the contents of file foo into file bar and delete
the original foo. Of course file bar still exists in this case. Not
much of a difference; I haven't seen buffer objects yet (I am also new
to Python), but the initialization for the buffer probably copies
whatever is in y somewhere.

  thats true even in the case of vairable assignment which states it a a
 reference !
   a = 10
   b = a
   del(a)
   b
  10
  i always thought if u modify the referred variable/buffer object it should
 be reflected in the referenced variables/buffers objects

You didn't modify the object that the variable /refers to/.
Furthermore, numbers are immutable anyway. To continue with the Hindu
god analogy, Vishnu did not cease to exist when any of his avatars
passed from the physical world; it is no different with objects in
Python.

IOW

a -- 10
b -/

Delete the 'a' reference and:

b -- 10

Or:

 class god(object):
...   pass
...
 vishnu = god()
 matsya = vishnu
 kurma = vishnu
 varaha = vishnu
 narasimha = vishnu
 # Etc
...
 del narasimha
 matsya
__main__.god object at 0x402e3c6c
 kurma
__main__.god object at 0x402e3c6c

What is a little different is this: if there are no references left to
an object (such as variables), the object the references point to will
eventually be deleted. Variables are one way to have a reference to an
object. References to an object may also exist in a list, hash, or
other data type.

 a = 'foo'
 b = [1,2,3,a]
 del(a)
 b
[1, 2, 3, 'foo']

 am i wrong ?
  does it mean that references  in python are not true references ?

Python is object-oriented in either sense of the word (think Lisp
sense then think Smalltalk sense). These are true references.

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


Re: Can't get around IndexError: list index out of range

2006-10-08 Thread MonkeeSage

On Oct 8, 1:44 pm, Fredrik Lundh [EMAIL PROTECTED] wrote:
 but let's hypergeneralize and treat sequences and mappings as the same
 thing proposals are nothing new; a trip to the archives might be help-
 ful.

Huh? I don't want to treat sequences and mappings as the same thing.
I'm talking about adding two similar convenience methods for sequences
as already exist for mappings. That may make the two APIs closer, but
that's not necessarily a bad thing (think the square-bracket accessor).
Besides, has_index is sufficiently different already. If it's really a
problem, change get() to at() for sequences. seq.at(2).

So far the reasons offered against adding those convenience methods
are:

Reason: It's unnecessary / bloat.
- Then the same thing is true of the dict methods.

Reason: It's not useful.
- I know of several use cases and could probably find others.

Reason: It takes effort to implement it. Why don't you do it yourself
if it's such a great idea!
- Mabye I will. But that is only a reason why they aren't currently
implemented, not why they *shouldn't* be.

Reason: It makes sequences and mapping to much alike.
- Then change the names for the sequences methods.

That is to say, no good reason has been offered for why these methods
shouldn't be implemented.

Regards,
Jordan

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


Re: references and buffer()

2006-10-08 Thread Steve Holden
km wrote:
 Hi all,
 
 in the CPython implementation, it's the address where the object is
 stored.  but that's an implementation detail. 
 
 
  ok so can i point a vairiable to an address location just as done in C 
 language ?
   y = 'ATGCATGC'
   x = buffer(y)
   del(y)
   x
 read-only buffer for 0xbf4cf0e0, size -1, offset 0 at 0xbf4cf240
   print x
 ATGCATGC
 
 now even when i delete y,  why is that x still exists ?

Because assignment is a *binding* of a name, in some namespace, to an 
object. x still exists because it hasn't been deleted. Because it is a 
reference to the object formerly bound to the name y, that object still 
also exists.

 thats true even in the case of vairable assignment which states it a a 
 reference !
   a = 10
   b = a
   del(a)
   b
 10
 i always thought if u modify the referred variable/buffer object it 
 should be reflected in the referenced variables/buffers objects . am i 
 wrong ?

Yes, you are wrong. Think of Python names as pure references.

 does it mean that references  in python are not true references ?
 
No, it doesn't mean that. Python bindings are exactly true references 
(think pointer in C), the storage for the referred objects is 
allocated from a heap and has a lifetime as long as the last reference 
to it and possibly, depending on the storage allocation and garbage 
collection strategy of the specific implementation, rather longer. Once 
all references have been deleted it can no longer be reached from inside 
Python code, however.

The original CPython implementation uses reference counting to control 
storage reclamation, but other implementations used other strategies.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


WSGI - How Does It Affect Me?

2006-10-08 Thread Gregory Piñero
So I keep hearing more and more about this WSGI stuff, and honestly I
still don't understand what it is exactly and how it differs from CGI
in the fundamentals (Trying to research this on the web now)

What I'm most confused about is how it affects me.  I've been writing
small CGI programs in Python for a while now whenever I have a need
for a web program.  Is CGI now considered Bad?  I've just always
found it easier to write something quickly with the CGI library than
to learn a framework and fool with installing it and making sure my
web host supports it.

Should I switch from CGI to WSGI?  What does that even mean?  What is
the equivalent of a quick CGI script in WSGI, or do I have to use a
framework even for that?  What do I do if frameworks don't meet my
needs and I don't have a desire to program my own?

Examples of how frameworks don't meet my needs sometimes:
1. Working with SQL Server (Most frameworks seem to at least make it extra work)
2. Need web app to get data from other programs via API (eg QuickBooks)
   Can any web framework work happily with win32 extensions?
3. Using IIS at all for that matter, does WSGI work on IIS, do any frameworks?

Hope this question isn't too confusing or rambling, or it hasn't been
covered before.  (it's hard to frame these questions as search terms
at least for me)

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


PEP 342 misunderstanding

2006-10-08 Thread metamoof
So I've been reading up on all the new stuff in PEP 342, and trying to
understand its potential. So I'm starting with a few simple examples to
see if they work as expected, and find they dont.

I'm basically trying to do the following:

for x in range(10):
print x*2

but coroutine-style.

My initial try was:

 def printrange():
... for x in range(10):
... x = yield x
... print x
...
 g = printrange()
 for x in g:
... g.send(x*2)
...
0
1
None
4
3
None
8
5
None
12
7
None
16
9
None


Now, I was expecting that to be 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20.

What am I missing here?

Moof

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


Re: PEP 342 misunderstanding

2006-10-08 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 def printrange():
 ... for x in range(10):
 ... x = yield x
 ... print x
 ...
 g = printrange()
 for x in g:
 ... g.send(x*2)
 ...
 0
 1
 None
 4
 3
 None
 8
 5
 None
 12
 7
 None
 16
 9
 None
 
 Now, I was expecting that to be 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20.
 
 What am I missing here?

the output doesn't match your sample program; I assume you left out a 
print statement or two from the second loop.

what you seem to be missing is that next (which is called by the 
for-in loop) is basically the same thing as send(None).  in other
words, you end up pulling two items from the generator for each iteration.

/F

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


Re: PEP 342 misunderstanding

2006-10-08 Thread Jean-Paul Calderone
On 8 Oct 2006 12:33:02 -0700, [EMAIL PROTECTED] wrote:
So I've been reading up on all the new stuff in PEP 342, and trying to
understand its potential. So I'm starting with a few simple examples to
see if they work as expected, and find they dont.

I'm basically trying to do the following:

for x in range(10):
print x*2

but coroutine-style.

My initial try was:

 def printrange():
... for x in range(10):
... x = yield x
... print x
...
 g = printrange()
 for x in g:
... g.send(x*2)
...

Try this instead:

   x = None
   while 1:
  ... if x is None:
  ... send = None
  ... else:
  ... send = x * 2
  ... try:
  ... x = g.send(send)
  ... except StopIteration:
  ... break
  ...
  0
  2
  4
  6
  8
  10
  12
  14
  16
  18



Now, I was expecting that to be 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20.

What am I missing here?

Your code was calling next and send, when it should have only been calling
send.

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


Re: recommendations for personal journaling application

2006-10-08 Thread Ant

Donnie Rhodes wrote:
...

 Thank you all and I hope I'm not biting off too much at once...

Not if you break it up into pieces. Look at the things you want to do,
and in the first instance, create a function for each. Then you can
start to fill in the blanks, and if neccessary ask back here for advice
on each bit.

For example, your skeleton script may look something like:

def main():
options = get_options()
text = fetch_body()
entry_data = parse_text(text, options)
store_entry(entry_data)

def get_options():
pass

def fetch_body()
pass
...

if __name__ == __main__:
main()

Ideas for the various parts:

get_options() - getopt or optparse modules (the former is simpler to
start with);

fetch_body() - just read from sys.stdin (that way you can also pipe
text into it from a file or the output from another program as well);

parse_text() - regexes could suffice if the flags and what they are
supposed to do is simple, otherwise a grammar parsing module could be
useful such as pyparsing (http://pyparsing.wikispaces.com/);

store_entry() - I'd probably go with XML for the storage format if you
really want to store the entries in a single text file, as you can
structure it well, there are good tools in python 2.5 for building xml
(xml.etree.ElementTree) and you could implement a fast search engine
using SAX. Otherwise a database may be a better option (e.g. sqlite).

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


Re: references and buffer()

2006-10-08 Thread km
Hi all,Say that you copy the contents of file foo into file bar and delete
the original foo. Of course file bar still exists in this case. Notmuch of a difference; I haven't seen buffer objects yet (I am also newto Python), but the initialization for the buffer probably copieswhatever is in y somewhere.

that means when u refer to an object with different names
(variable), it referes to the same object- fine. but is it
that the original object stays in memory until it is Garbage
Collected ?
is it that del() deletes the link of variable to the object
and not the object ? and thats why u can access it from other variables
? 

You didn't modify the object that the variable /refers to/.Furthermore, numbers are immutable anyway. To continue with the Hindu
god analogy, Vishnu did not cease to exist when any of his avatarspassed from the physical world; it is no different with objects inPython.
vishnu analogy is a bit complicated as it is a manifestation of
divine energy in terms of earthly object(avatar). Its clearly not a
reference. each avatar is himself (vishnu). It is the same energy
people around have too (coz of manifestation). ofcourse they dont
realise coz of ego (id in python) and so the object class (divine
energy) is the same - unlike python where we have different classes
derived from object class.
IOWa -- 10b -/Delete the 'a' reference and:b -- 10

got it!

What is a little different is this: if there are no references left toan object (such as variables), the object the references point to will
eventually be deleted. Variables are one way to have a reference to anobject. References to an object may also exist in a list, hash, orother data type.
so the object exists until there are no references to it and will be Garbage Collected immediately? 
regards,
KM

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

Re: Can't get around IndexError: list index out of range

2006-10-08 Thread Steve Holden
MonkeeSage wrote:
 On Oct 8, 1:44 pm, Fredrik Lundh [EMAIL PROTECTED] wrote:
 
but let's hypergeneralize and treat sequences and mappings as the same
thing proposals are nothing new; a trip to the archives might be help-
ful.
 
 
 Huh? I don't want to treat sequences and mappings as the same thing.
 I'm talking about adding two similar convenience methods for sequences
 as already exist for mappings. That may make the two APIs closer, but
 that's not necessarily a bad thing (think the square-bracket accessor).
 Besides, has_index is sufficiently different already. If it's really a
 problem, change get() to at() for sequences. seq.at(2).
 
 So far the reasons offered against adding those convenience methods
 are:
 
 Reason: It's unnecessary / bloat.
 - Then the same thing is true of the dict methods.
 
No: you are proposing to add features to the sequence interface for 
which there are few demonstrable use cases.

 Reason: It's not useful.
 - I know of several use cases and could probably find others.
 
Well I certainly didn't find your last one particularly convincing: the 
attempt to reference a non-existent sequence member is almost always a 
programming error.

 Reason: It takes effort to implement it. Why don't you do it yourself
 if it's such a great idea!
 - Mabye I will. But that is only a reason why they aren't currently
 implemented, not why they *shouldn't* be.
 
 Reason: It makes sequences and mapping to much alike.
 - Then change the names for the sequences methods.
 
 That is to say, no good reason has been offered for why these methods
 shouldn't be implemented.
 
I would argue exactly the opposite: the reason why they shouldn't be 
implemented is because no good reason has been presented why they *should*.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: WSGI - How Does It Affect Me?

2006-10-08 Thread Sybren Stuvel
Gregory Piñero enlightened us with:
 So I keep hearing more and more about this WSGI stuff, and honestly I
 still don't understand what it is exactly

AFAIK it's a standard for web frameworks. In such a framework, you
receive a 'request' object, and return a 'response' object. If I'm
correct, the WSGI describes things like the method and property names
on those objects etc.

 What I'm most confused about is how it affects me.  I've been writing
 small CGI programs in Python for a while now whenever I have a need
 for a web program.  Is CGI now considered Bad?

I've never considered CGI bad, but I do consider it to be a hassle to
make anything non-trivial. If you want a website with template engine,
web-based database admin, and automatic form generation and
validation, it's easier to use an existing web framework.

 What is the equivalent of a quick CGI script in WSGI, or do I have
 to use a framework even for that?

I'd simply use CGI for that.

 What do I do if frameworks don't meet my needs and I don't have a
 desire to program my own?

That depends on the needs I guess.

 Examples of how frameworks don't meet my needs sometimes:
 1. Working with SQL Server (Most frameworks seem to at least make it
 extra work)

I've never seen a framework that's unable to work with an SQL server.

 2. Need web app to get data from other programs via API (eg
 QuickBooks) Can any web framework work happily with win32
 extensions?

You can use any module you want in a Django view, including win32.

 3. Using IIS at all for that matter, does WSGI work on IIS, do any
 frameworks?

Why would you want to use that monstrosity?

Sybren
-- 
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scientific computing and data visualization.

2006-10-08 Thread Fabian Braennstroem
Hi Bernhard,

* [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  I can definitively second that. ROOT is a bit hard to learn but very,
  very powerful and PyRoot is really a pleasure to work with.

 It sounds interesting. Right now, I use matplotlib for
 2D plotting and vtk for 3D. Do you have any experience and
 can give some recommendations?

 Hi Fabian!

 I recommend using matplotlib for data visualization, because the usage
 of the plotting commands is much(!!!) more convenient. In ROOT you have
 to create objects before you can draw your diagrams. The constructor
 often requires arguments about the number of space points, axis length,
 name etc. On the other hand, the figure itself has a GUI to manipulate
 the plot, which sometimes is nicer than doing everything in the script.
 In particular the 3D visualization seems to be more comprehensive (lots
 of drawing options, rotation of the plot with the mouse, changing of
 visualization lego, surf, contour plots etc.).

 ROOT has more than plotting. For example it has a whole bunch of
 containers to store very large amounts of data (within complex
 datastructures), fitting routines, minimizers etc. But you get that
 with scipy and numpy.

 I'm using 80% of the time matplotlib because it's much quicker for
 quick glances at your data. If I need sophisitcated 3D plots, I use
 ROOT, but I would love to switch to matplotlib for this, as well.

 My guess is that using python and matplotlib with scipy speeds up my
 work by at least 30% in comparison to using purely ROOT (and code in
 C++). And even 10-15% in comparison to the usage of ROOT with pyRoot.

Thanks for your advice!

Greetings!
 Fabian

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


Re: Can't get around IndexError: list index out of range

2006-10-08 Thread Fredrik Lundh
MonkeeSage wrote:

 but let's hypergeneralize and treat sequences and mappings as the same
 thing proposals are nothing new; a trip to the archives might be help-
 ful.
 
 Huh? I don't want to treat sequences and mappings as the same thing.
 I'm talking about adding two similar convenience methods for sequences
 as already exist for mappings.

so what makes you think you're the first one who's ever talked about that?

/F

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


Re: references and buffer()

2006-10-08 Thread Theerasak Photha
On 10/8/06, km [EMAIL PROTECTED] wrote:
 Hi all,


  Say that you copy the contents of file foo into file bar and delete
  the original foo. Of course file bar still exists in this case. Not
  much of a difference; I haven't seen buffer objects yet (I am also new
  to Python), but the initialization for the buffer probably copies
  whatever is in y somewhere.

  that means when u refer to an object  with different names (variable), it
 referes to the same object- fine. but  is it that  the original object stays
 in memory until it is Garbage Collected ?

Exactly.

  is it that  del() deletes  the link of variable to the object and not the
 object ? and thats why u can access it from other variables ?

Exactly.

  You didn't modify the object that the variable /refers to/.
  Furthermore, numbers are immutable anyway. To continue with the Hindu
  god analogy, Vishnu did not cease to exist when any of his avatars
  passed from the physical world; it is no different with objects in
  Python.

  vishnu analogy is a bit complicated as  it is a manifestation of divine
 energy in terms of earthly object(avatar). Its clearly not a reference. each
 avatar is himself (vishnu). It is the same energy people around have too
 (coz of manifestation). ofcourse they dont realise coz of ego (id in python)
  and so the object class (divine energy) is the same - unlike python where
 we have different classes derived from object class.

Congratulations, you understand both Hinduism and Python better than I
do now.  :) c.f.
http://www.swami-krishnananda.org/brdup/brhad_III-09.html

Kati references, Yajnavalkya, iti?

(It is worth noting that a subclass is an instance of its superclass,
both in terms of interface and implementation.)

  so the object exists until there are no references  to it and  will be
 Garbage Collected  immediately?

Python uses two garbage collection schemes together. It uses reference
counting (when number of references goes to zero, remove object from
memory) and mark-and-sweep (comb through process memory methodically
looking for objects that are no longer accessible). This is what
allows it to collect cyclic structures, such as trees whose nodes
links to their parents and vice versa.

GC intercedes at various intervals when convenient. I don't think it
would be immediate though.

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


Re: WSGI - How Does It Affect Me?

2006-10-08 Thread Theerasak Photha
On 10/8/06, Sybren Stuvel [EMAIL PROTECTED] wrote:

  3. Using IIS at all for that matter, does WSGI work on IIS, do any
  frameworks?

 Why would you want to use that monstrosity?

Two words: contractual obligation

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


Re: Python to use a non open source bug tracker?

2006-10-08 Thread Terry Reedy

Giovanni Bajo [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 tracker. I was claiming that, if such a group was ever formed, it was 
 better
 spent on bug triage rather than keeping their keys ready all day long to
 quick-fix any server breakage in minutes.

This could be made into an argument for accepting the Jira offer so we 
don't 'waste' *any* more Python-knowledgable volunteer time on admin. 
However, thinking about it more, I think that wrestling with a software 
system like Roundup and interacting with sometimes naive and non-responsive 
bug submitters are two different skills and likely to attract different 
volunteers.

[snip]

 Either close directly any nonsense, or ask for more feedback to the 
 poster,
 until the bug/patch/rfe is sufficiently clear to be handled, or 3 months 
 are
 passed and you close the bug for no further feedback from the poster. 
 If this
 would dramatically reduce the number of open bugs, then yes, Python 
 really
 needs someone to do bug triaging.

I have thought this for some time based on my occasional efforts at 
'first-response' reviewing.  But I have not tried to do anything because of 
the difficulty of working with the SF tracker.  Perhaps submissions by new 
submitters should start in 'limbo' until rejected or accepted into active 
open status.  I hope that whichever new tracker we get will allow for 
automated followups at determined intervals, such as 3 mos or whatever.

 It might be not a good use of your time at all, since you are a 
 developer. But
 having a database with 938 open bugs most of which are
 incomplete/nonsense/unconfirmed is much less useful than it could be.

Perhaps when the new tracker is set up, you can help scratch the 'too many 
open bugs' itch.

 It also
 raises the bar for new developers: it's much harder to just pick one 
 and fix
 it. I know because I tried sometimes, and after half an hour I couldn't 
 find
 any bug that was interesting to me and complete enough to work on it. I 
 also
 noticed that most bugs are totally uncommented like nobody cared at all. 
 This
 is where my thought about Python missing bug triaging started.

s/most/some/

When I read a bug with no comment I sometimes put extra energy into 
thinking of something to say or ask just so the reporter will know the 
report has been read.

Terry Jan Reedy



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


Re: print time comparison: IDLE versus terminal on ultra 20

2006-10-08 Thread sam
i was actually experimenting on windows on my own pc before the
workstation arrived, and IDLE printed a lot faster on windows than in
solaris for me too.

i would indeed complain to sun if i had ever got the impression that
anyone over there ever knew what was going on...   : )

 but on the other hand, IDLE runs your sample script in less than 0.5
 seconds on my cheap Windows box.  complain to Sun ;-)
 
 /F

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


Re: New-style classes slower than old-style classes? (Was: n-body problem at shootout.alioth.debian.org)

2006-10-08 Thread Peter Maas
Richard Jones wrote:
 Giovanni Bajo wrote:
[...]
 Anyway, this is a bug on its own I believe. I don't think new-style
 classes are meant to be 25% slower than old-style classes. Can any guru
 clarify this?
 
 Please try 2.5 - there's been significant optimisation work put into 2.5

I checked that:

1 runs of nbody.py, time in sec

   | classic | new-style |   n/c
---+-+---+--
python 2.4 |  2.33 s |  2.89 s   |  1.24
python 2.5 |  2.06 s |  2.61 s   |  1.27
  2.4/2.5  |  1.13   |  1.11 |-

You are right, 2.5 is better than 2.4. But the runtime penalty
for using new-style classes remains.

-- 
Regards/Gruesse,

Peter Maas, Aachen
E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')
-- 
http://mail.python.org/mailman/listinfo/python-list


Some advice needed on an Tkinter app that I try to write

2006-10-08 Thread Svenn Bjerkem
Hi,

Armed with Programming Python 3rd Edition and Learning Python 2nd
edition I try to write an application which I at first thought was
simple, at least until I was finished with the GUI and then wanted to
start putting some data into it.

As you will see, the program is not yet finished but I post what I have
so far.

It will read a spice file and extract the interfaces to the
subcircuits. The purpose of the program is to assign the interface pins
to sides of a rectangular box symbol which will represent the
subcircuit in a graphical design tool dedicated for electronics design
(Cadence to be precise) The output of the tool will be a lisp like text
format which can be read into that tool and there the actual generation
of the graphical symbol will take place.

The name of the subcircuits will be shown in the ScrolledList Widget.
When the user click on one of the entries of that widget, the pins of
the interface will be shown in the AssignList widget. (I have not
managed this, yet) If the user select any of the ScrolledList entries
(Single selection) the current setting is shown in the other widgets.
This implies that the user can move from one subcircuit to the next
before all pins have been placed. (I need some kind of an in-memory
database to take care of the data)

In the AssignList widget, either the user can select one or more
entries (extended selection) and press one of the four buttons
left,top,bottom,right and the pins will be moved to the respective
PinList widget. This process goes on until all the pins have been
assigned a side. When a pin is moved from the AssignList to one of the
PinList widgets, the pin is deleted from the AssignList.

If the user by accident move a pin to the wrong side, he can select the
wrongly placed pin and press the Move here button under the proper
PinList widget. Pins will always be placed at the bottom of a PinList.
This will make a rudimentary rearrange possible: If the Move Here
button of the same PinList widget is pressed, the selected pins
(extended selection) are moved to the bottom. (in an extended selection
the highest index will be moved first)

When I have come this far, I will add a menu line with options to save
the whole database to the text format which I can read into Cadence.

My biggest problem is probably that I have to implement a model view
controller but none of the books cover how to do this in Python. I have
tried to search on the web with google and find a lot of descriptions,
but so far nothing that make me more clever.

The problem which I have been chewing on the whole weekend is how to
tell the AssignList to load the pins belonging to the subcircuit
selected in ScrolledList.

Any ideas?
--
Svenn

#!/bin/env python

from Tkinter import *

class ScrolledList(Frame):
def __init__(self, data, parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets(data)

def handleList(self, event):
index = self.listbox.curselection()
label = self.listbox.get(index)
self.listbox.insert(END, label)
self.runCommand(label)

def makeWidgets(self, options):
sbar = Scrollbar(self)
list = Listbox(self, relief=SUNKEN)
sbar.config(command=list.yview)
list.config(yscrollcommand=sbar.set)
sbar.pack(side=RIGHT, fill=Y)
list.pack(side=LEFT, expand=YES, fill=BOTH)
pos=0
for label in options:
list.insert(pos,label)
pos += 1
list.bind('ListboxSelect', self.handleList)
list.bind('Double-1', self.handleList)
list.configure(selectmode=EXTENDED)
self.listbox = list

def runCommand(self, selection):
print 'You selected in: ', self
g_from=self

#--
# A Widget to set some pins
#--
class PinList(Frame):
def __init__(self, text=, parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets(text)
def makeWidgets(self, text):
frame = LabelFrame(self, text=text)
list = Listbox(frame, relief=SUNKEN)
sbar = Scrollbar(frame)
button = Button(frame, text='Move here',
command=self.handleList)
sbar.config(command=list.yview)
list.config(yscrollcommand=sbar.set)
frame.pack(side=LEFT, expand=YES, fill=BOTH)
button.grid(column=0, row=1, sticky=E+W)
list.grid(column=0, row=0, sticky=N+S+E+W)
sbar.grid(column=1, row=0, sticky=N+S)

Re: Raw beginner....

2006-10-08 Thread Fabio Zadrozny
On 10/8/06, Colin Lehmann [EMAIL PROTECTED] wrote:
 I am new to Python although I have been using Delphi since version one,
 I have been employed as a C and C++ programmer so when I went to Linux
 (Ubuntu 5.10) I thought Python looked pretty good.
 I downloaded and installed 'Eric Python IDE' which seems OK, any
 alternatives suggested will be looked at

Suggestions: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments

Cheers,

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


Re: Python to use a non open source bug tracker?

2006-10-08 Thread Martin v. Löwis
Giovanni Bajo schrieb:
 So, you might prefer 6-10 people to activate a new tracker account
 faster than light. I'd rather have 3-days delay in administrative
 issues because our single administrator is sleeping or whatever, and
 then have 2-3 people doing regular bug processing.
 
 Are you ever going to try and make a point which is not you are not entitled
 to have opinions because you do not act? Your sarcasm is getting annoying. 
 And
 since I'm not trolling nor flaming, I think I deserve a little bit more of
 respect.

You seem to imply that people who are willing to do roundup admin could
regularly, easily do bug triage, and also would be willing to do so. I
can attest that this assumption is sooo remote from the truth that
I can't really believe you really meant it.

I have called for people doing bug review and providing patches many
many times, and most of these calls got unheard.

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


Re: Python to use a non open source bug tracker?

2006-10-08 Thread Martin v. Löwis
Paul Boddie schrieb:
 When SF is down, people sometimes send tracker items to
 the pydev list instead, when means someone else (who?) has to put in the
 tracker or it gets lost.
 
 According to Harald Armin Massa's PostgreSQL talk at EuroPython, the
 PostgreSQL people manage all their bugs via mailing lists. Given that
 trends in revision control point towards completely decentralised
 solutions, I wonder whether there's anything to learn from less
 centralised (or more flexible) approaches to bug management.

From my experience with GCC, I can only report that this is definitely
not working. There used to be a mailing list [EMAIL PROTECTED], and
reports got either answered immediately, or not at all. People who
thought they were responsible put the mails in some folder, and then
never found the time to come back. This is why I set up a bug tracker
for GCC.

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


Re: Python to use a non open source bug tracker?

2006-10-08 Thread Fredrik Lundh
Martin v. Löwis wrote:

From my experience with GCC, I can only report that this is definitely
 not working. There used to be a mailing list [EMAIL PROTECTED], and
 reports got either answered immediately, or not at all. People who
 thought they were responsible put the mails in some folder, and then
 never found the time to come back.

you need tools to help you track the bugs and their status, but you can 
handle issue registration, discussion, and most maintenance stuff using 
good old mail just fine.

/F

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


Re: WSGI - How Does It Affect Me?

2006-10-08 Thread Sybren Stuvel
Theerasak Photha enlightened us with:
  3. Using IIS [...]

 Why would you want to use that monstrosity?

 Two words: contractual obligation

That doesn't answer the question. It only makes me ask it to someone
else, namely the parties involved in creating the contract.

Sybren
-- 
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: references and buffer()

2006-10-08 Thread km

Hi all, 
Congratulations, you understand both Hinduism and Python better than Ido now.:) 
c.f.http://www.swami-krishnananda.org/brdup/brhad_III-09.htmlKati references, Yajnavalkya, iti?
the answer lies in a single line as pronounced by sri adi sankaracharya - 
aham bramhasmi sivoha sivoham  , which is still not implemented in
python. infact not in any other language! which is a limitatin of
computers (and comp languages) - they simply arent intelligent.
 aham, tvam sah: cha madhye kim bhedam bhavati ? bhedam nasti !
Python uses two garbage collection schemes together. It uses referencecounting (when number of references goes to zero, remove object from
memory) and mark-and-sweep (comb through process memory methodicallylooking for objects that are no longer accessible). This is whatallows it to collect cyclic structures, such as trees whose nodeslinks to their parents and vice versa.

why is that python doesnt implement direct memory addressing provided a reference to an object exists ?
GC intercedes at various intervals when convenient. I don't think itwould be immediate though.
what is the interval and what is its effect on the performance of python interpreter ?
regards,
KM


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

Re: Python to use a non open source bug tracker?

2006-10-08 Thread skip

Fredrik you need tools to help you track the bugs and their status, but
Fredrik you can handle issue registration, discussion, and most
Fredrik maintenance stuff using good old mail just fine.

Which is something SourceForge has yet to learn.  At work we use a system
called RT (http://www.bestpractical.com/rt/).  While it's not perfect, it
does allow submissions and responses via email.  That feature alone puts it
miles ahead of SF in my mind.

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


Re: Python to use a non open source bug tracker?

2006-10-08 Thread Paul Rubin
[EMAIL PROTECTED] writes:
 Which is something SourceForge has yet to learn.  At work we use a system
 called RT (http://www.bestpractical.com/rt/).  While it's not perfect, it
 does allow submissions and responses via email.  That feature alone puts it
 miles ahead of SF in my mind.

I'm on the other side--I think spam has destroyed the usefulness of
email as a communications medium and I don't want to depend on
anything having to do with email any more.  I hate the way SF requires
registering an email address and then it emails you every update to
your SF issues.  As a low-intensity user, I sort of tolerate it.  But
if I used SF more, I'd have to direct all the SF email to a spam
bucket and never look at it.  At most I'd want it to send about one
email per week.  But I'd much rather have a personalized RSS feed that
delivers updates about the bugs that I'm following.

I also notice that the PyPy mailing list now delivers mostly spam, so
I've had to direct that to a spam bucket.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >