Learning Python

2006-11-06 Thread kaushal
Hi

How do i start Learning Python,is there any reference material which I
can refer since I dont have
any programming experience

Thanks and Regards

Kaushal

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


Is there any python lib for calling CVS api?

2006-11-06 Thread ironpythonster
  Hi everyone, this should be a quick question.  I'm writing some
scripts
to take some file and move them into a CVS repository, but it's pretty
slow, because it uses system calls to execute the CVS commands.

 Has anyone ever made a python to CVS interface library that I could
use?
Some one sugestion me use the cvsgui lib,but it look like that the lib
could
not use fro Python2.4.I've been trying to google around for something,
but predictably I get
a zillion sourceforge repository hits, and it isn't really helping.  So

anyway, if anyone knows of a useful module, I'd love to hear about it.
Thanks!

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


Re: python GUIs comparison (want)

2006-11-06 Thread Eric Brunel
On Wed, 25 Oct 2006 11:04:57 +0200, Christophe <[EMAIL PROTECTED]>  
wrote:
>>> And no modern layout manager available. Only those old school  
>>> left/right/up/down pack and anchors are available.
>>  huh?  when did you last look at Tk?  1994?
> Yesterday. In fact, I could find no mention at all of layout managers  
> others than those working with anchors. Anchors are s old school  
> nowadays :)

Being "old school" or "modern" is not an argument in itself. How do the  
so-called "modern" layout managers help you do the thing you want to do?

And the fact that you could find no mention of something does not mean  
that it doesn't exist. It may just be a documentation problem.

> Honestly, I can't stand using anchors or the Packer anymore. The systems  
> used in wx, Qt are much better. Use them once and you cannot live  
> without them anymore.

The "Packer" is very rarely used in Tkinter applications when the layout  
becomes complicated. Almost all applications I saw use the "grid" layout  
manager, except for very simple things (like buttons in a row or column,  
where the "pack" layout manager is just enough).
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string to list of numbers conversion

2006-11-06 Thread Frederic Rentsch
[EMAIL PROTECTED] wrote:
> Hi,
>   I have a string '((1,2), (3,4))' and I want to convert this into a
> python tuple of numbers. But I do not want to use eval() because I do
> not want to execute any code in that string and limit it to list of
> numbers.
>   Is there any alternative way?
>
> Thanks.
> Suresh
>
>   
s = '((1,2), (3,4))'
separators = re.compile ('\(\s*\(|\)\s*,\s*\(|\)\s*\)')
tuple ([(float (n[0]), float (n[1])) for n in [pair.split (',') for pair 
in separators.split (s) if pair]])
((1.0, 2.0), (3.0, 4.0))

Frederic


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


Re: Learning Python

2006-11-06 Thread ArdPy

kaushal wrote:
> Hi
>
> How do i start Learning Python,is there any reference material which I
> can refer since I dont have
> any programming experience
>
> Thanks and Regards
>
> Kaushal

Hi kaushal,

Look into http://diveintopython.org. Dive into python is a really
readable ebook...enjoy

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


Re: Learning Python

2006-11-06 Thread Jorge Vargas
On 6 Nov 2006 01:33:36 -0800, ArdPy <[EMAIL PROTECTED]> wrote:
>
> kaushal wrote:
> > Hi
> >
> > How do i start Learning Python,is there any reference material which I
> > can refer since I dont have
> > any programming experience
> >
> > Thanks and Regards
> >
> > Kaushal
>
> Hi kaushal,
>
> Look into http://diveintopython.org. Dive into python is a really
> readable ebook...enjoy
>
Even though that's a great book I don't recomend it for non
programmers I think this http://docs.python.org/tut/ is a better way
to start

also I'll suggest you start learning other programming languaje before
python or else this will be the only one you will code :)

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


Problem with XML-RPC not mounted in /

2006-11-06 Thread Almad
Hi,

I'm trying to build XML-RPC service, both server and client library.

My server is CherryPy with XML-RPC filter. I have here method
registration_ip. When it's in, say http://ws.rpgplanet.nerv/,
everything is OK, but when I move it in http://ws.rpgplanet.nerv/main/,
this behaviour occur:

 srv = ServerProxy('http://ws.rpgplanet.nerv/main/')
 print srv.register_ip("guest")

raises 404, as according to log, library is trying to access /main/
instead of /main/register_ip

 srv = ServerProxy('http://ws.rpgplanet.nerv/')
 print srv.main.register_ip("guest")

raises 500, as client is correctly hitting /main/register_ip, but NOT
sending "guest" argument.

I'm probably missing something obvious, so where should problem be? Is
it not possible for XML-RPC to live not in / ?

Thank You for advices,

Almad

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


Re: Python Distilled

2006-11-06 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Simon Wittber
wrote:

> I'd also like to remove any deprecated or stuff which is left in for
> backwards functionality (eg Classic classes).

Classic classes are still needed for exceptions:

>>> class E(object):
...pass
...
>>> raise E
Traceback (most recent call last):
  File "", line 1, in 
TypeError: exceptions must be classes, instances, or strings (deprecated),
not type

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


Re: Creating db front end or middleware.

2006-11-06 Thread Bruno Desthuilliers
tobiah wrote:
> Let's say I want to write a new tool to do
> something to, or report on people in a database.
> Each tool is going to have to have all sorts of
> routines that know about the relationship between
> the data.  The first thought is to write a library
> of routines that do things like, change_address(),
> or fire_employee() or whatever. 
> Whoops, now we've decided to move to python.  I
> have to write all of that again.
> 
> So I thought, shouldn't there be a cloud that sits
> in front of the database to which I can ask these
> services of?  Some process that awaits requests for
> information, or handles new incoming data.  Now new
> apps written in any language should be able to use a basic protocol in
> order to get the work done.
>
> The question then, is what the best way to do this is.

The first question then is: do you really need a middleware ? Most
RDBMSs are already full-blown server applications - with support for
authentification, permissions, triggers and stored procedures - that can
be accessed by client programs in almost any language.

Now if you effectively want/need a web service, it seems that the
canonical solutions are XMLRPC and SOAP. But if you already use a RDBMS,
 this web service should IMHO mostly be designed as an higher-level
interface to the RDBMS, not as a full-blown app managing domain/business
rules (which is the job of the RDBMS). IOW, it should be still possible
for applications to directly interact with the RDBMS.

> First I thought of using cherrypy to sit and listen to
> POST requests, but this would make passing complex structures
> extremely inconvenient.

There are XMLRPC packages for most languages, that knows how to do the
native data structure <-> XMLRPC translation. Python has both client and
server packages in the standard lib.

>  Then I thought about WSDL.
> Would this be the next logical step, or is this more for
> allowing different companies to communicate with each other
> when there needs to be a broadcast description of the interface?

As the name implies, W(eb) S(ervice) D(escription) L(anguage) is meant
to describe a given web service - and says nothing about implementation.

My 2 cents
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Distilled

2006-11-06 Thread Georg Brandl
Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, Simon Wittber
> wrote:
> 
>> I'd also like to remove any deprecated or stuff which is left in for
>> backwards functionality (eg Classic classes).
> 
> Classic classes are still needed for exceptions:
> 
 class E(object):
> ...pass
> ...
 raise E
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: exceptions must be classes, instances, or strings (deprecated),
> not type

The error is a bit misleading, since in Python 2.5 all exceptions are new-style,
but new exception classes must be derived from an existing one.
Classic classes, their instances and strings are only allowed for backwards 
compatibility.

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


Re: Python Distilled

2006-11-06 Thread Jorge Godoy
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:

> In <[EMAIL PROTECTED]>, Simon Wittber
> wrote:
>
>> I'd also like to remove any deprecated or stuff which is left in for
>> backwards functionality (eg Classic classes).
>
> Classic classes are still needed for exceptions:
>
 class E(object):
> ...pass
> ...
 raise E
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: exceptions must be classes, instances, or strings (deprecated),
> not type

On the other hand...

>>> import exceptions
>>> class E(exceptions.Exception):
... pass
... 
>>> raise E
Traceback (most recent call last):
  File "", line 1, in ?
__main__.E
>>> 


This also has the advantage to let it explicit in the code that E is an
exception. 


-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simple way to un-nest (flatten?) list

2006-11-06 Thread Steven D'Aprano
On Sun, 05 Nov 2006 21:43:33 +, djc wrote:

> There is I am sure an easy way to do this, but I seem to be brain dead 
> tonight. So:
> 
> I have a table such that I can do
> 
>   [line for line  in table if line[7]=='JDOC']
> and
>   [line for line  in table if line[7]=='Aslib']
> and
>   [line for line  in table if line[7]=='ASLIB']
> etc
> 
> I also have a dictionary
>   r=  {'a':('ASLIB','Aslib'),'j':('JDOC', 'jdoc')}
> so I can extract values
> r.values()
> [('ASLIB', 'Aslib'), ('JDOC', 'jdoc')]
> 
> I would like to do
> 
> [line for line  in table if line[7] in ('JDOC','jdoc','Aslib','ASLIB')]

What is the purpose of the "if line[7]" bit?



> so how should I get from
> {'a':('ASLIB','Aslib'),'j':('JDOC','jdoc')}
> to
> ('Aslib','ASLIB','JDOC','jdoc')


Assuming you don't care what order the strings are in:

r = {'a':('ASLIB','Aslib'),'j':('JDOC','jdoc')}
result = sum(r.values(), ())

If you do care about the order:

r = {'a':('ASLIB','Aslib'),'j':('JDOC','jdoc')}
keys = r.keys()
keys.sort()
result = []
for key in keys:
result.extend(r[key])
result = tuple(result)


-- 
Steven.

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


Re: Python Distilled

2006-11-06 Thread Paul McGuire
"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> In <[EMAIL PROTECTED]>, Simon Wittber
> wrote:
>
>> I'd also like to remove any deprecated or stuff which is left in for
>> backwards functionality (eg Classic classes).
>
> Classic classes are still needed for exceptions:
>
 class E(object):
> ...pass
> ...
 raise E
> Traceback (most recent call last):
>  File "", line 1, in 
> TypeError: exceptions must be classes, instances, or strings (deprecated),
> not type
>
> Ciao,
> Marc 'BlackJack' Rintsch

I thought exceptions were converted to new-style classes for Py2.5 
(http://docs.python.org/whatsnew/pep-352.html).  I've not upgraded yet, so 
cannot easily test this - under what version of Python was your posted code 
run?

-- Paul


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


RE: Classes referencing each other

2006-11-06 Thread Ryan Ginstrom
> Behalf Of Manuel Bleichner
> In a module I have a huge number of classes of the form:
> 
> class A(object):
>connected_to = [B, C]
>
> 
> class B(object)
>connected_to = [C]
>
> 
> class C(object)
>connected_to = [A]
>
> 
> As you see, classes A and B reference classes that are not 
> yet defined when the class is being defined.
> It will raise a NameError: 'B'.

How about a connection broker?

Simple example:

#
connections = {}

def Register( obj ):
try:
connections[obj.name]['obj'] = obj
except KeyError:
connections[obj.name] = { 'obj' : obj, 'connected_to' : [] }

def ConnectTo( objname, obj ):
try:
connections[objname]['connected_to'].append( obj )
except KeyError:
connections[objname] = { 'obj' : None, 'connected_to' :
[obj] }

class ConnectionObject:
def __str__(self):
return self.name

class A(ConnectionObject):
def __init__(self):
self.name = 'A'
Register( self )
ConnectTo( 'B', self )


class B(ConnectionObject):
def __init__(self):
self.name = 'B'
Register( self )
ConnectTo( 'A', self )
ConnectTo( 'C', self )


class C(ConnectionObject):
def __init__(self):
self.name = 'C'
Register( self )
ConnectTo( 'A', self )


a = A()
b = B()
c = C()


for (key, val) in connections.iteritems():
print 'object: %s (%s)' % ( key, val['obj'] )
str_vals = []
for obj in val['connected_to']:
str_vals.append( str( obj ) )
print '\tconnections from:', str_vals

#
Output:

object: A (A)
connections from: ['B', 'C']
object: C (C)
connections from: ['B']
object: B (B)
connections from: ['A']
object: D (None)
connections from: ['C']

Regards,
Ryan Ginstrom

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


Re: forwarding *arg parameter

2006-11-06 Thread Steven D'Aprano
On Sun, 05 Nov 2006 19:35:58 +, Tuomas wrote:

> Thanks. My solution became:
> 
>  >>> def flattern(arg):
> ... result = []
> ... for item in arg:
> ... if isinstance(item, (list, tuple)):
> ... result.extend(flattern(item))
> ... else:
> ... result.append(item)
> ... return tuple(result)
> ...
>  >>> def g(*arg):
> ... arg = flattern(arg)
> ... return arg
> ...
>  >>> def f(*arg):
> ... return g(arg)
> ...
>  >>> f('foo', 'bar')
> ('foo', 'bar')


That's the most complicated do-nothing function I've ever seen. Here is a
shorter version:

def shortf(*args):
return args


>>> f('foo', 'bar')
('foo', 'bar')
>>> shortf('foo', 'bar')
('foo', 'bar')

>>> f(1,2,3,4)
(1, 2, 3, 4)
>>> shortf(1,2,3,4)
(1, 2, 3, 4)

>>> f({}, None, 1, -1.2, "hello world")
({}, None, 1, -1.2, 'hello world')
>>> shortf({}, None, 1, -1.2, "hello world")
({}, None, 1, -1.2, 'hello world')

Actually, they aren't *quite* identical: your function rips lists apart,
which is probably not a good idea.

>>> f("foo", [1,2,3], None) # three arguments turns into five
('foo', 1, 2, 3, None)
>>> shortf("foo", [1,2,3], None) # three arguments stays three
('foo', [1, 2, 3], None)



I still don't understand why you are doing this. Can we have an example of
why you think you need to do this?



-- 
Steven.

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


Re: Is there any python lib for calling CVS api?

2006-11-06 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> Hi everyone, this should be a quick question.  I'm writing some scripts
> to take some file and move them into a CVS repository, but it's pretty
> slow, because it uses system calls to execute the CVS commands.

[...]

> anyway, if anyone knows of a useful module, I'd love to hear about it.

You might get some ideas from ViewVC if you're accessing the repository
directly:

http://www.viewvc.org/

There may be scripts out there which import data from various other
revision control systems into CVS, although the focus these days seems
to be on *exporting* data from CVS and putting it into things like
Subversion, Bazaar, Mercurial and so on, but I believe the scripts for
the latter two are Python programs and may also provide some
inspiration.

Paul

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


Re: string to list of numbers conversion

2006-11-06 Thread Paul McGuire
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
>  I have a string '((1,2), (3,4))' and I want to convert this into a
> python tuple of numbers. But I do not want to use eval() because I do
> not want to execute any code in that string and limit it to list of
> numbers.
>  Is there any alternative way?
>
> Thanks.
> Suresh
>

Pyparsing comes with an example that parses strings representing lists. 
Here's that example, converted to parsing only tuples of numbers.  Note that 
this does not presume that tuples are only pairs, but can be any number of 
numeric values, nested to any depth, and with arbitrary whitespace, etc. 
This grammar also includes converters by type, so that ints come out as 
ints, and floats as floats.  (This grammar doesn't handle empty tuples, but 
it does handle tuples that include an extra ',' after the last tuple 
element.)

-- Paul
Download pyparsing at http://sourceforge.net/projects/pyparsing/ .


from pyparsing import *

integer = (Word(nums)|Word('-+',nums)).setName("integer")
real = Combine(integer + "." + Optional(Word(nums))).setName("real")
tupleStr = Forward().setName("tuple")
tupleItem = real | integer | tupleStr
tupleStr << ( Suppress("(") + delimitedList(tupleItem) +
   Optional(Suppress(",")) + Suppress(")") )

# add parse actions to do conversion during parsing
integer.setParseAction( lambda toks: int(toks[0]) )
real.setParseAction( lambda toks: float(toks[0]) )
tupleStr.setParseAction( lambda toks: tuple(toks) )

s = '((1,2), (3,4), (-5,9.2),)'
print tupleStr.parseString(s)[0]

Gives:
((1, 2), (3, 4), (-5, 9.1993))


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


Re: Learning Python

2006-11-06 Thread kaushal
On Nov 6, 2:54 pm, "Jorge Vargas" <[EMAIL PROTECTED]> wrote:
> On 6 Nov 2006 01:33:36 -0800, ArdPy <[EMAIL PROTECTED]> wrote:
>
>
>
> > kaushal wrote:
> > > Hi
>
> > > How do i start Learning Python,is there any reference material which I
> > > can refer since I dont have
> > > any programming experience
>
> > > Thanks and Regards
>
> > > Kaushal
>
> > Hi kaushal,
>
> > Look intohttp://diveintopython.org. Dive into python is a really
> > readable ebook...enjoyEven though that's a great book I don't recomend it 
> > for non
> programmers I think thishttp://docs.python.org/tut/is a better way
> to start
>
> also I'll suggest you start learning other programming languaje before
> python or else this will be the only one you will code :)
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list

Hi

Just wanted to know how is this URL
http://www.ibiblio.org/obp/thinkCSpy/ 

Thanks and Regards

Kaushal

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


Re: Projecting MUD maps

2006-11-06 Thread Neil Cerutti
On 2006-11-05, BJörn Lindqvist <[EMAIL PROTECTED]> wrote:
> Hello, I'm looking for an algorithm to project "MUD maps" such
> as the following map:
> http://www.aww-mud.org/maps/MUD_Maps/Caerin-colour.jpg

Check out the Ruby project IFMapper for a mature project that
might accomplish your goal.  You can write a new back-end for it
to produce MUD code (so you can design your maps graphically), or
you can write a new front-end to interpret MUD code (so you can
make IF-Mapper draw maps for you game in progress).

http://ifmapper.rubyforge.org/

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


Re: Learning Python

2006-11-06 Thread Ramon Diaz-Uriarte
On 6 Nov 2006 03:12:34 -0800, kaushal <[EMAIL PROTECTED]> wrote:
> On Nov 6, 2:54 pm, "Jorge Vargas" <[EMAIL PROTECTED]> wrote:
> > On 6 Nov 2006 01:33:36 -0800, ArdPy <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > kaushal wrote:
> > > > Hi
> >
> > > > How do i start Learning Python,is there any reference material which I
> > > > can refer since I dont have
> > > > any programming experience
> >
> > > > Thanks and Regards
> >
> > > > Kaushal
> >
> > > Hi kaushal,
> >
> > > Look intohttp://diveintopython.org. Dive into python is a really
> > > readable ebook...enjoyEven though that's a great book I don't recomend it 
> > > for non
> > programmers I think thishttp://docs.python.org/tut/is a better way
> > to start
> >
> > also I'll suggest you start learning other programming languaje before
> > python or else this will be the only one you will code :)
> >
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> Hi
>
> Just wanted to know how is this URL
> http://www.ibiblio.org/obp/thinkCSpy/
>


Dear Kaushal,

I was going to recommend exactly that one. That is a very nice book,
clearly written, not patronizing (some begginers books seem to fall
easily into the patronizing mode), and covers a lot of ground.

I think dive into python is a great book, but not the best choice if
you have no programming experience. I also think that the tutorial by
Guido van Rossum is not the best place to start if you have no
programming experience.

You can also go to:

http://www.python.org/doc/


and, in particular,

http://wiki.python.org/moin/BeginnersGuide/NonProgrammers.



If you are looking for a "book I'll pay money for", I'd recommend
"Core Python Programming", by Chun. It's a thick book, which will keep
you busy for a while, and assumes some programming experience. It may
be a good place to go _after_ you've gone through "How to think like a
computer scientist" and, probably, have looked at some other material.

Good luck,

R.


> Thanks and Regards
>
> Kaushal
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Erronous "unsupported locale setting" ?

2006-11-06 Thread robert
Why can the default locale not be set by its true name? but only by '' ? :


PythonWin 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on 
win32.
>>> import locale
>>> locale.getlocale()
(None, None)
>>> locale.setlocale(locale.LC_ALL,"de_DE")
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python25\lib\locale.py", line 476, in setlocale
return _setlocale(category, locale)
Error: unsupported locale setting
>>> locale.getdefaultlocale()
('de_DE', 'cp1252')
>>> locale.setlocale(locale.LC_ALL,locale.getdefaultlocale())
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python25\lib\locale.py", line 476, in setlocale
return _setlocale(category, locale)
Error: unsupported locale setting
>>> locale.setlocale(locale.LC_ALL)
'C'
>>> locale.setlocale(locale.LC_ALL,'')
'German_Germany.1252'
>>> locale.getlocale()
('de_DE', 'cp1252')
>>> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Projecting MUD maps

2006-11-06 Thread BJörn Lindqvist
On 11/5/06, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> BJörn Lindqvist schrieb:
> > Hello, I'm looking for an algorithm to project "MUD maps" such as the
> > following map: http://www.aww-mud.org/maps/MUD_Maps/Caerin-colour.jpg
> >
> > MUD:s consists of rooms, each rooms has up to four orthogonal edges
> > (north, east, west and south) that connects it to another room. So it
> > is very easy to model a MUD as a directed graph. But projecting the
> > graph on a surface is very complicated. For example, Room A:s North
> > edge may connect it to Room B. But Room B:s South edge may connect it
> > to Room C. Or another tricky example: Room A:s East edge connects it
> > to Room B, whose East edge connect it to Room C, whose North edge
> > connects it to Room D, whose West edge connects it to Room E, whose
> > South edge connects it to Room A. In that example, there would be a
> > "hole" between Room D and E.
>
>
> try graphviz. You can also annotate some compass information ther, I
> guess it should make for a better placement.

Sorry, I think everyone misunderstood what my problem is. Which is not
very strange since I see now that I didn't explain it very well.

In the code below, I have created a simple Room class. It has up to
four edges; north, east, west and south. The Room class also has the
method get_projection() which recursively traverses through all
reachable rooms in the graphs and gives them x,y coordinates and
returns a dict containing x,y-coordinates and rooms. The function
project_dict() simply plots the dict on stdout.

The main() function demonstrates how a map consisting of nine rooms
should be plotted. All well so far. But if there had been an east-west
edge from G to I, then that edge would have overlapped C:s position.
That would have been wrong and I want the algorithm in
get_projection() to detect such overlaps and automatically fix them.
In this case, the fix would have been to add 2 to G and I:s
y-coordinate. Then the east-west edge from G to I wouldn't overlap any
room.

So I wonder if there is any algorithm that can do what I'm asking for?

--- mudgraph.py ---
# -*- coding: utf-8 -*-
import sys

class Dir:
dirs = ['n', 'e', 's', 'w']
@classmethod
def opposite(cls, dir):
"""
Return the opposite direction, i.e Dir.opposite('n') => 's'.
"""
opp_idx = (Dir.dirs.index(dir) + 2) % 4
return Dir.dirs[opp_idx]

class Room:
"""
A Room is a node in a mud map. Each room can have up to four
connections (edges) to other rooms in the cardinal directions;
north, east, south and west.
"""
def __init__(self, name = None):
self.name = name or "+"
self.n = None
self.s = None
self.e = None
self.w = None

def connect(self, dir, room):
"""
Create an edge dir from self to room. Also create an edge in
the opposite direction from room to self.
"""
setattr(self, dir, room)
setattr(room, Dir.opposite(dir), self)

def north(self, room):
self.connect('n', room)

def east(self, room):
self.connect('e', room)

def west(self, room):
self.connect('w', room)

def south(self, room):
self.connect('s', room)

def get_projection(self, x = 0, y = 0,
   proj_dict = None,
   visited = None):
"""
Return a dictionary containing all Rooms in the map as
values. Each key is the projected x and y position of the
room.
"""
if proj_dict is None:
proj_dict = {}
if visited is None:
visited = set()
visited.add(self)
proj_dict[x, y] = self
if self.n and not self.n in visited:
self.n.get_projection(x, y - 1, proj_dict, visited)
if self.e and not self.e in visited:
self.e.get_projection(x + 1, y, proj_dict, visited)
if self.w and not self.w in visited:
self.w.get_projection(x - 1, y, proj_dict, visited)
if self.s and not self.s in visited:
self.s.get_projection(x, y + 1, proj_dict, visited)
return proj_dict

def project_dict(dict):
coords = dict.keys()

max_x = 0
max_y = 0
min_x = 999
min_y = 999
for x, y in coords:
if x > max_x:
max_x = x
elif x < min_x:
min_x = x
if y > max_y:
max_y = y
elif y < min_y:
min_y = y

max_x += 1
max_y += 1
for y in range(min_y, max_y):
x_range = range(min_x, max_x)
for x in x_range:
if dict.has_key((x, y)) and dict[x, y].n:
sys.stdout.write(" | ")
else:
sys.stdout.write("   ")
sys.stdout.write("\n")
for x in x_range:
if dict.has_key((x, y)):
room = dict[x, y]
if room.w:
  

Re: forwarding *arg parameter

2006-11-06 Thread Tuomas
Dennis Lee Bieber wrote:
> On Sun, 05 Nov 2006 22:51:00 GMT, Tuomas <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
> 
> 
>>> 
>>
>>I fylly agree with tis: "Typically, the responsibility should be on the 
>>CALLER, not the CALLED..". I just don't know how to unpack *arg for 
>>calling g. I can get the len(arg), but how to formulate an unpacked call 
>>g(arg[0], arg[1], ..). Building a string for eval("g(arg[0], arg[1], 
>>..)") seems glumsy to me.
>>
> 
>   Did you miss the example I gave? Using "*args" on the "def"
> essentially says "pack remaining arguments into one tuple". Using
> "*args" on a CALL says "UNPACK tuple into positional arguments"
> 
> def f(*args):  pack arguments into tuple

Thats it:

>   x = g(*args) unpack args tuple when calling

Yesterday I tested something like this and got a syntax error. So I got 
misunderstanding that "g(*args)" is'nt a proper syntax. Obviously my 
test sentence had some other syntax error. Sorry.

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


Re: ANN: PyQt v4.1 Released

2006-11-06 Thread Tool69
Hi Phil,
I followed the docs to build qscintilla2, all is going well with no
errors, but when I launched the PyQt Syntax Highlighter Example,
nothing is highlighted but the first line of text, whereas the C++
sample works well in the demo.
Any hints ?
Thanks.

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


Re: Python-list Digest, Vol 38, Issue 72

2006-11-06 Thread Santosh Chikkerur
Hi Friends,How to use getchar( ) in python. I want to see the output of the program ,step by step.I have given print statements in between for the results..Hence i would like to print the output everytime there is getchar().which is the
similar fn in pythonthanks,SantoshOn 11/6/06, [EMAIL PROTECTED]
 <[EMAIL PROTECTED]> wrote:
Send Python-list mailing list submissions [email protected] subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-listor, via email, send a message with subject or body 'help' to[EMAIL PROTECTED]
You can reach the person managing the list at[EMAIL PROTECTED]When replying, please edit your Subject line so it is more specificthan "Re: Contents of Python-list digest..."
Today's Topics:   1. Re: Learning Python (Jorge Vargas)   2. Problem with XML-RPC not mounted in / (Almad)   3. Re: Python Distilled (Marc 'BlackJack' Rintsch)   4. Re: Creating db front end or middleware. (Bruno Desthuilliers)
   5. Re: Python Distilled (Georg Brandl)   6. Re: Python Distilled (Jorge Godoy)   7. Re: simple way to un-nest (flatten?) list (Steven D'Aprano)   8. Re: Python Distilled (Paul McGuire)   9. RE: Classes referencing each other (Ryan Ginstrom)
  10. Re: forwarding *arg parameter (Steven D'Aprano)  11. Re: Is there any python lib for calling CVS api? (Paul Boddie)-- Forwarded message --From: "Jorge Vargas" <
[EMAIL PROTECTED]>To: ArdPy <[EMAIL PROTECTED]>Date: Mon, 6 Nov 2006 09:54:26 +Subject: Re: Learning Python
On 6 Nov 2006 01:33:36 -0800, ArdPy <[EMAIL PROTECTED]> wrote:>> kaushal wrote:> > Hi> >> > How do i start Learning Python,is there any reference material which I
> > can refer since I dont have> > any programming experience> >> > Thanks and Regards> >> > Kaushal>> Hi kaushal,>> Look into 
http://diveintopython.org. Dive into python is a really> readable ebook...enjoy>Even though that's a great book I don't recomend it for nonprogrammers I think this 
http://docs.python.org/tut/ is a better wayto startalso I'll suggest you start learning other programming languaje beforepython or else this will be the only one you will code :)> --> 
http://mail.python.org/mailman/listinfo/python-list>-- Forwarded message --From: "Almad" <
[EMAIL PROTECTED]>To: [email protected]: 6 Nov 2006 02:04:12 -0800Subject: Problem with XML-RPC not mounted in /Hi,I'm trying to build XML-RPC service, both server and client library.
My server is CherryPy with XML-RPC filter. I have here methodregistration_ip. When it's in, say http://ws.rpgplanet.nerv/,everything is OK, but when I move it in 
http://ws.rpgplanet.nerv/main/,this behaviour occur: srv = ServerProxy('http://ws.rpgplanet.nerv/main/') print srv.register_ip("guest")raises 404, as according to log, library is trying to access /main/
instead of /main/register_ip srv = ServerProxy('http://ws.rpgplanet.nerv/') print srv.main.register_ip("guest")raises 500, as client is correctly hitting /main/register_ip, but NOT
sending "guest" argument.I'm probably missing something obvious, so where should problem be? Isit not possible for XML-RPC to live not in / ?Thank You for advices,Almad
-- Forwarded message --From: Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>To: [email protected]
Date: Mon, 06 Nov 2006 11:11:41 +0100Subject: Re: Python DistilledIn <[EMAIL PROTECTED]>, Simon Wittber
wrote:> I'd also like to remove any deprecated or stuff which is left in for> backwards functionality (eg Classic classes).Classic classes are still needed for exceptions:>>> class E(object):
...pass...>>> raise ETraceback (most recent call last):  File "", line 1, in TypeError: exceptions must be classes, instances, or strings (deprecated),
not typeCiao,Marc 'BlackJack' Rintsch-- Forwarded message --From: Bruno Desthuilliers <[EMAIL PROTECTED]>To: 
[email protected]: Mon, 06 Nov 2006 11:19:47 +0100Subject: Re: Creating db front end or middleware.tobiah wrote:> Let's say I want to write a new tool to do
> something to, or report on people in a database.> Each tool is going to have to have all sorts of> routines that know about the relationship between> the data.  The first thought is to write a library
> of routines that do things like, change_address(),> or fire_employee() or whatever.> Whoops, now we've decided to move to python.  I> have to write all of that again.>> So I thought, shouldn't there be a cloud that sits
> in front of the database to which I can ask these> services of?  Some process that awaits requests for> information, or handles new incoming data.  Now new> apps written in any language should be able to use a basic protocol in
> order to get the work done.>> The question then, is what the best way to do this is.The first question then is: do you really need a middleware ? MostRDBMSs are already full-blown server applications - with support for
authentification, permissions, triggers and

Building C extensions

2006-11-06 Thread Paolo Pantaleo
Well I'm just courious: if I want to buid a C extension, I shoul use
the same compiler that has been used to build python (right?). Since
python has been built using Visual C, how can I build an extension if
I don't have Visual Studio?

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


Re: forwarding *arg parameter

2006-11-06 Thread Tuomas
Steven D'Aprano wrote:
> On Sun, 05 Nov 2006 19:35:58 +, Tuomas wrote:
> 
> 
>>Thanks. My solution became:
>>
>> >>> def flattern(arg):
>>... result = []
>>... for item in arg:
>>... if isinstance(item, (list, tuple)):
>>... result.extend(flattern(item))
>>... else:
>>... result.append(item)
>>... return tuple(result)
>>...
>> >>> def g(*arg):
>>... arg = flattern(arg)
>>... return arg
>>...
>> >>> def f(*arg):
>>... return g(arg)
>>...
>> >>> f('foo', 'bar')
>>('foo', 'bar')
> 
> 
> 
> That's the most complicated do-nothing function I've ever seen. Here is a
> shorter version:
> 
> def shortf(*args):
> return args
> 
> 
> 
f('foo', 'bar')
> 
> ('foo', 'bar')
> 
shortf('foo', 'bar')
> 
> ('foo', 'bar')
> 
> 
f(1,2,3,4)
> 
> (1, 2, 3, 4)
> 
shortf(1,2,3,4)
> 
> (1, 2, 3, 4)
> 
> 
f({}, None, 1, -1.2, "hello world")
> 
> ({}, None, 1, -1.2, 'hello world')
> 
shortf({}, None, 1, -1.2, "hello world")
> 
> ({}, None, 1, -1.2, 'hello world')
> 
> Actually, they aren't *quite* identical: your function rips lists apart,
> which is probably not a good idea.
> 
> 
f("foo", [1,2,3], None) # three arguments turns into five
> 
> ('foo', 1, 2, 3, None)
> 
shortf("foo", [1,2,3], None) # three arguments stays three
> 
> ('foo', [1, 2, 3], None)
> 
> 
> 
> I still don't understand why you are doing this. Can we have an example of
> why you think you need to do this?

If i redefine the function g the difference comes visible:

  >>> def g(*arg):
... if with_flattern: arg=flattern(arg)
... return arg

 >>> with_flattern=False
 >>> f('foo', 'bar')
(('foo', 'bar'),)
 >>> with_flattern=True
 >>> f('foo', 'bar')

If you read the whole chain you find out what we were talking of.

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


Re: Is there any python lib for calling CVS api?

2006-11-06 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

>   Hi everyone, this should be a quick question.  I'm writing some
> scripts
> to take some file and move them into a CVS repository, but it's pretty
> slow, because it uses system calls to execute the CVS commands.
> 
>  Has anyone ever made a python to CVS interface library that I could
> use?

AFAIK there is no such thing as a CVS-library. Which was one of the
motivations behind subversion, which offers its functionality through a
library that has a python wrapping available.

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


Re: Projecting MUD maps

2006-11-06 Thread Diez B. Roggisch
BJörn Lindqvist wrote:

> On 11/5/06, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
>> BJörn Lindqvist schrieb:
>> > Hello, I'm looking for an algorithm to project "MUD maps" such as the
>> > following map: http://www.aww-mud.org/maps/MUD_Maps/Caerin-colour.jpg
>> >
>> > MUD:s consists of rooms, each rooms has up to four orthogonal edges
>> > (north, east, west and south) that connects it to another room. So it
>> > is very easy to model a MUD as a directed graph. But projecting the
>> > graph on a surface is very complicated. For example, Room A:s North
>> > edge may connect it to Room B. But Room B:s South edge may connect it
>> > to Room C. Or another tricky example: Room A:s East edge connects it
>> > to Room B, whose East edge connect it to Room C, whose North edge
>> > connects it to Room D, whose West edge connects it to Room E, whose
>> > South edge connects it to Room A. In that example, there would be a
>> > "hole" between Room D and E.
>>
>>
>> try graphviz. You can also annotate some compass information ther, I
>> guess it should make for a better placement.
> 
> Sorry, I think everyone misunderstood what my problem is. Which is not
> very strange since I see now that I didn't explain it very well.
> 
> In the code below, I have created a simple Room class. It has up to
> four edges; north, east, west and south. The Room class also has the
> method get_projection() which recursively traverses through all
> reachable rooms in the graphs and gives them x,y coordinates and
> returns a dict containing x,y-coordinates and rooms. The function
> project_dict() simply plots the dict on stdout.
> 
> The main() function demonstrates how a map consisting of nine rooms
> should be plotted. All well so far. But if there had been an east-west
> edge from G to I, then that edge would have overlapped C:s position.
> That would have been wrong and I want the algorithm in
> get_projection() to detect such overlaps and automatically fix them.
> In this case, the fix would have been to add 2 to G and I:s
> y-coordinate. Then the east-west edge from G to I wouldn't overlap any
> room.
> 
> So I wonder if there is any algorithm that can do what I'm asking for?

It depends - it is complicated and very sophisticated and generally
considered a hard, even unsolvable problem. However, a good general
solution is written in the graphviz toolkit. Which is the reason I
suggested it.

But there is no cookbook-algorithm that will produce perfect MUD-maps. For
such a beast, you have to cough up one on your own, with things like
constraint solvers and the like. Certainly over _my_ head, at least without
deep studies of planar graph representation problems.

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

Re: Building C extensions

2006-11-06 Thread casevh

Paolo Pantaleo wrote:
> Well I'm just courious: if I want to buid a C extension, I shoul use
> the same compiler that has been used to build python (right?). Since
> python has been built using Visual C, how can I build an extension if
> I don't have Visual Studio?
>
> PAolo

Use mingw32. It should work fine for most extensions.

For example, see
http://groups.google.com/group/comp.lang.python/msg/8e2260fe4d4b7de9
and the followup messages.

casevh

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


Re: Erronous "unsupported locale setting" ?

2006-11-06 Thread Leo Kislov
robert wrote:
> Why can the default locale not be set by its true name? but only by '' ? :

Probably it is just not implemented. But since locale names are system
specific (For example windows accepts 'ch' as Chinese in Taiwan, where
as IANA 
considers it Chamorro) setlocale should probably grow an additional
keyword parameter: setlocale(LC_ALL, iana='de-DE')

  -- Leo

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


Re: Is there a commas-in-between idiom?

2006-11-06 Thread Fredrik Lundh
Ernesto García García wrote:

> it's very common that I have a list and I want to print it with commas 
> in between. How do I do this in an easy manner, whithout having the 
> annoying comma in the end?

I've collected a bunch of list pydioms and other notes here:

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

For formatting issues, see:

http://effbot.org/zone/python-list.htm#printing



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


Re: Erronous "unsupported locale setting" ?

2006-11-06 Thread robert
Leo Kislov wrote:
> robert wrote:
>> Why can the default locale not be set by its true name? but only by '' ? :
> 
> Probably it is just not implemented. But since locale names are system
> specific (For example windows accepts 'ch' as Chinese in Taiwan, where
> as IANA 
> considers it Chamorro) setlocale should probably grow an additional
> keyword parameter: setlocale(LC_ALL, iana='de-DE')

that'd be another fat database to blow up the python core(s).

I just wonder why locale.setlocale(locale.LC_ALL,"de_DE") doesn't accept the 
name, which 
>>> locale.getlocale() / getdefaultlocale()
('de_DE', 'cp1252') 
already deliver ?

but only this works 

>>> locale.setlocale(locale.LC_ALL,'German_Germany.1252')
'German_Germany.1252'


But 'German_Germany.1252' you cannot get/guess from any locale.get function 
I think ... 


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


Re: Is there a commas-in-between idiom?

2006-11-06 Thread Ernesto García García
> I've collected a bunch of list pydioms and other notes here:
> 
>http://effbot.org/zone/python-list.htm

Thank you for the suggestion.

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


Re: Python Distilled

2006-11-06 Thread Georg Brandl
Paul McGuire wrote:
> "Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> In <[EMAIL PROTECTED]>, Simon Wittber
>> wrote:
>>
>>> I'd also like to remove any deprecated or stuff which is left in for
>>> backwards functionality (eg Classic classes).
>>
>> Classic classes are still needed for exceptions:
>>
> class E(object):
>> ...pass
>> ...
> raise E
>> Traceback (most recent call last):
>>  File "", line 1, in 
>> TypeError: exceptions must be classes, instances, or strings (deprecated),
>> not type
>>
>> Ciao,
>> Marc 'BlackJack' Rintsch
> 
> I thought exceptions were converted to new-style classes for Py2.5 
> (http://docs.python.org/whatsnew/pep-352.html).

Yes, they were. Still, you can't raise instance of arbitrary new-style classes
as exceptions, and you will never be able to. In Py3k, only instances of
"BaseException" subclasses will be raisable.

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


Re: Learning Python

2006-11-06 Thread mohan

Hi Kaushal,

Other than "Core Python" by Chun, also try  "Python: How To Program" by
Dietel & Dietel. It is one of the good books for bigginers.

Good Luck,
Mohan.


On Nov 6, 10:00 am, "kaushal" <[EMAIL PROTECTED]> wrote:
> Hi
>
> How do i start Learning Python,is there any reference material which I
> can refer since I dont have
> any programming experience
> 
> Thanks and Regards
> 
> Kaushal

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


Re: Sorted and reversed on huge dict ?

2006-11-06 Thread Sion Arrowsmith
 <[EMAIL PROTECTED]> wrote:
>so i just have tried, even if i think it will not go to the end => i
>was wrong : it is around 1.400.000 entries by dict...
>
>but maybe if keys of dicts are not duplicated in memory it can be done
>(as all dicts will have the same keys, with different (count) values)?

I've had programs handling dicts with 1.7million items and it isn't
a great problem, providing you're careful not to duplicate data.
Creating a copy of keys() in a separate list, for example, will
inflate memory usage noticably.

>memory is 4Gb of ram, [ ... ]

Unless you're on a 64bit OS, that's irrelevant. You'll hit the 2G
per-process limit before you start putting a strain on real memory.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python GUIs comparison (want)

2006-11-06 Thread metaperl

[EMAIL PROTECTED] wrote:
> Paul Boddie wrote:
>
> """The figures behind the scenes are quite enlightening for that
> particular page. If you (or community experiences) don't agree with the
>
> rankings (wxPython apparently even easier to learn than PythonCard and
> Tinder, a bunch of Gtk-based toolkits having more or less "full" Linux
> scores) then you'll have some surprises, I'm sure. Nevertheless, it's
> an interesting concept. """
>
> Well, I don't know what I was thinking, exactly, when I rated
> PythonCard's ease of use...so I went back and changed it to rate it a
> lot higher. The ratings in this script were done a long time ago now

I dropped Pythoncard when I could not sort multi column lists and when
I posted to the email list and no one answered me.

But prior to that it was great.

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


Re: SPE editor slow?

2006-11-06 Thread SPE - Stani's Python Editor
timmy schreef:

> hello i've been using the SPE editor on a moderately large project and
> it's constantly pausing during editing, like it's attempting to check
> something as i edit.
> as you can imagine a 4 second pause every few characters is EXTREMELY
> annoying when you just want to get some work done. i really like SPE's
> layout and features but if it's going to be dogshit slow all the time
> i'll have to change. please help!

SPE does error syntax checking which works fine for normal sized python
files. With these settings you can speed up SPE for larger projects:
1. Edit>Preferences>Editor: Check realtime with "none" (default value:
compiler)
2. Edit>Preferences>Editor: Update sidebar "when clicked"

You can first try step 1, if you want SPE faster, use step 2 as well.

Stani

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


Re: Timer Usage

2006-11-06 Thread Grant Edwards
On 2006-11-06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I'm planning to do C++ development together with Python on
> Linux. I understand that Linux allows only one timer per
> process. Does Python use the Linux timer?

No.

> If so, how do I use the timer without interfering with Python?

-- 
Grant Edwards   grante Yow!  I feel real
  at   SOPHISTICATED being in
   visi.comFRANCE!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do I pass values between classes?

2006-11-06 Thread Max Erickson
"kath" <[EMAIL PROTECTED]> wrote:

> hi, Larry Bates  thanks for the reply...
> 
>> You might consider doing it the same way wx passes things around.
>> When you instantiate the subclass pass the parent class' instance
>> as first argument to __init__ method.
> 
> Yes thats absolutely right..
> 
>> That way the subclass can
>> easily pass values back to the parent by using that pointer.
> 
> Could you please explain me this.. more clearly. I think it is much
> close to the solution.
> 
> 
> Thank you.
> regards, sudhir
> 

Somewhere in the child class:

self.parent.do_something(something_to_do_it_with)

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


Re: Really strange behavior

2006-11-06 Thread Sion Arrowsmith
IloChab  <[EMAIL PROTECTED]> wrote:
[this works]
>def main():
>app = QtGui.QApplication(sys.argv)
>qt4reactor.install(app)
>MainWindow = QtGui.QMainWindow()
>win = Window(MainWindow)
>MainWindow.show()
>from twisted.internet import reactor
>reactor.run()
[this doesn't]
>def creApp():
>app = QtGui.QApplication(sys.argv)
>qt4reactor.install(app)
>retrun app
>def creWin():
>MainWindow = QtGui.QMainWindow()
>win = Window(MainWindow)
>MainWindow.show()
>def main():
>app = creApp()
>creWin()
>from twisted.internet import reactor
>reactor.run()

I don't know if this is the problem or not (knowing neither Qt nor
Twisted), but creWin() creates a window (or two) then throws it
(them?) away on returning to main() (I assume you've chopped
off the bit where main() is actually called). So it's not too
surprising your window doesn't show: by the time you get to
running anything, you don't have a window object to show. (Unless
a Qt application object is a discoverable global and windows
inject a reference to themselves into it.)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how do I pass values between classes?

2006-11-06 Thread jim-on-linux

Kath,
You can use this class to pass values around 
without concern for conflicts since it has no 
values of its own.


class Kvariable:
  def setVariable(self, variable):
  self.output = variable

  def showVariable(self):
  print self.output 
  
x = Kvariable()
y = Kvariable()

x.setVariable("James_01")
y.setVariable("Kath_01")

x.showVariable()
y.showVariable()


x.setVariable('3.14159')
y.setVariable("python.org")

x.showVariable()
y.showVariable()

jim-on-linux

http://www.inqvista.com














On Monday 06 November 2006 02:00, kath wrote:
> hi, Larry Bates  thanks for the reply...
>
> > You might consider doing it the same way wx
> > passes things around. When you instantiate
> > the subclass pass the parent class' instance
> > as first argument to __init__ method.
>
> Yes thats absolutely right..
>
> > That way the subclass can
> > easily pass values back to the parent by
> > using that pointer.
>
> Could you please explain me this.. more
> clearly. I think it is much close to the
> solution.
>
>
> Thank you.
> regards, sudhir
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Distilled

2006-11-06 Thread Steven Bethard
Simon Wittber wrote:
> I want to build a Python2.5 interpreter for an embedded system. I only
> have 4MB of RAM to play with, so I want to really minimise the python
> binary.
[snip]
> Google tells me that people have done this before, back in Python1.5.2
> days. Has anyone tried to do this recently with a more modern Python?

http://www.python.org/dev/summary/2006-09-16_2006-09-30/#shrinking-python

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


Re: string to list of numbers conversion

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

>   I have a string '((1,2), (3,4))' and I want to convert this into a
> python tuple of numbers. But I do not want to use eval() because I do
> not want to execute any code in that string and limit it to list of
> numbers.

here's yet another approach:

http://online.effbot.org/2005_11_01_archive.htm#simple-parser-1

also see:

http://online.effbot.org/2005_11_01_archive.htm#simple-parser-3



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


Re: Problem with XML-RPC not mounted in /

2006-11-06 Thread Almad
Just FYI, this is bug in CP filter machinery, xmlrpc filter do not
apply recursively so do not dispatch reuqest.

Quick fix is to xmlrpcfilter.on not only on /ws, but also on /ws/main

Regards,

Almad

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


Full-time Python DEVELOPER needed - High-transactional environment

2006-11-06 Thread RM
Hello Python users,

We are currently looking for a PYTHON DEVELOPER in Cleveland, OH. The
full-time position is with a LARGE CLIENT (situated in over 17
countries and headquartered in Cleveland) currently in a high-growth
mode and is WORLD's leading Internet Content Providing firm

The client offers attractive salary and great benefits, plus a creative
and flexible work environment

We are looking for candidates with strong OO background in Python /
Java / C++ / other OO language along with backend experience


If you would like to find out more about the position and/or the
client, kindly give me a call at the number listed below and send me a
copy of your resume for review.


Thank you for your time, I look forward to hearing from you soon.

Kind Regards,
Rozina Mardhani
Sr. Recruiter
Claddagh Resources
678-405-4400 Ext. 211
[EMAIL PROTECTED]

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


Re: MemoDepot: build YOUR OWN online notes library - anything, anytime, anywhere

2006-11-06 Thread metaperl
I'll just use Plone, thanks.

ompaniess wrote:
> Just like everybody else nowadays, you are facing infinite amount of
> information everyday. how can you keep those that truly matters to you?
> MemoDepot allows you to do just that, and much more!
>
> - Capture any information, store as notes in your MemoDepot account,
> and access from anywhere
> - Organize your notes the way you like, they are always available at
> your fingertips
> - Pinpoint any notes by powerful search, just when you need it
> - Share your notes with others
> - Export your notes to local machine, so you take control, not
> MemoDepot
>
> With MemoDepot, you no longer have to throw away any useful
> information: contacts, ideas, experience, coupons, receipts, pictures,
> web pages, hard Googled-out results, programming sample codes,
> teacher's handout, scientific references, or simply favored book
> passages.. yes, ANYTHING. It is the place to deposit your
> knowledge; it is the way to extend your memory.
>
> MemoDepot is NOT merely a storage solution, a screen scraper, NOR is
> another online notebook, search engine or editor - it is an end to end
> knowledge build and management system, everyday, in the most convenient
> way.
>
> To truly appreciate why MemoDepot tool and service are so powerful,
> take a few minutes to check out:
>
> http://www.memodepot.com/noteserver/flashes/memodepot.pps  (PowerPonit)
>
> http://www.memodepot.com/noteserver/flashes/memodepot_demo.html  (Flash
> Demo)
>
> http://www.memodepot.com (Get started!)
> 
> Any comments or suggestions, send to: [EMAIL PROTECTED]

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


Re: ANN: PyQt v4.1 Released

2006-11-06 Thread David Boddie
Tool69 wrote:

> I followed the docs to build qscintilla2, all is going well with no
> errors, but when I launched the PyQt Syntax Highlighter Example,
> nothing is highlighted but the first line of text, whereas the C++
> sample works well in the demo.

Do you mean the example from the PyQt4 distribution? That uses a port
of an old syntax highlighting example from Qt 4.0. Someone needs to
"port" the C++ example from Qt 4.2 to PyQt4.

The example itself doesn't actually use QScintilla2 - there used to
be a demo from Qt that was converted to use QScintilla. Maybe that's
been ported to PyQt as well.

David

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


shutil: permission denied errors on windows

2006-11-06 Thread Antoine De Groote
Google tells quite some things about it, but none of them are satisfactory.

I'm on Windows, and shutil operations (e.g. move, copy) throw [Errno 13] 
Permission denied all the time, for the source files. It seems that this 
is the case for all my files. But what I don't understand is that 
yesterday it still worked. I didn't change anything on my system though 
(at least not that I am aware of). I restarted the computer several 
times to see if that helped, but it didn't. Also I can't find a process 
that would be using the files...

Has anybody experienced this problem before, or have a solution?

Kind regards,
antoine

Here's the code that throws the errors

[...]
for l in files:
 from_file = os.path.join(dir, l)
 to_file = from_file.replace(tree_top, backup_dir)
 try:
 if not os.path.exists(to_file):
 log('Copying new  %s' % from_file)
 counter_new += 1
 shutil.copy2(from_file, to_file)
 elif int(os.path.getmtime(from_file)) > 
int(os.path.getmtime(to_file)):
 log('Copying modified %s' % from_file)
 counter_mod += 1
 shutil.copy2(from_file, to_file)
 elif os.path.getsize(from_file) > os.path.getsize(to_file):
 log('Sizes differ, but not rest: Copying %s' % 
from_file)
 counter_special += 1
 shutil.copy2(from_file, to_file)
 elif os.path.getsize(from_file) < os.path.getsize(to_file):
 log('Orig file smaller than backup file: Copying 
%s' % from_file)
 counter_special += 1
 shutil.copy2(to_file, backup_dir+'DIFF_SIZE')
 shutil.copy2(from_file, to_file)
 else:
 #log('not treated: %s' % l)
 pass

 except (OSError, IOError), e:
 not_accessible += 1
 print e
[...]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Really strange behavior

2006-11-06 Thread David Boddie
Sion Arrowsmith wrote:

> I don't know if this is the problem or not (knowing neither Qt nor
> Twisted), but creWin() creates a window (or two) then throws it
> (them?) away on returning to main() (I assume you've chopped
> off the bit where main() is actually called). So it's not too
> surprising your window doesn't show: by the time you get to
> running anything, you don't have a window object to show.

It seems to me that your analysis is correct. The first example
works as expected because MainWindow is still in scope when
the reactor is run.

def main():
 app = QtGui.QApplication(sys.argv)
 qt4reactor.install(app)
 MainWindow = QtGui.QMainWindow()
 win = Window(MainWindow)
 MainWindow.show()
 from twisted.internet import reactor
 reactor.run()

However, in the second example, MainWindow is created as a local
variable inside creWin() and is deleted when that function returns.

def creWin():
 MainWindow = QtGui.QMainWindow()
 win = Window(MainWindow)
 MainWindow.show()
 def main():
 app = creApp()
 creWin()
 from twisted.internet import reactor
 reactor.run()

By the time the reactor runs, there's no window (open or otherwise)
so the application will never exit the Qt event loop (or whatever
actually runs when Twisted is involved).

> (Unless a Qt application object is a discoverable global and
> windows inject a reference to themselves into it.)

Well, you can access the application's instance, once it's been set
up, via the qApp global variable in the PyQt4.QtGui module. However,
you can't take advantage of Qt's parent-based object ownership
mechanism to get round this issue with local variables because
widgets need to be given QWidget parents, and QApplication is not a
QWidget subclass.

The original poster should either use a global MainWindow variable or
encapsulate the functions in a class.

David

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


Re: python GUIs comparison (want)

2006-11-06 Thread John Henry
Yes, from a easy of use standpoint, I agree that PythonCard is very
high on the list.

Unfortunately there isn't more "activities" as one would like to see.

On the other hand, that's typical of open-source projects.  We can
always roll up our sleeves and do it ourselves.

At least the multicolumn control isn't particularly complex, should be
able to figure out from the source code how to sort.  I believe I did
that some time ago.   I believe I ended up reshuffling the list...

metaperl wrote:
> [EMAIL PROTECTED] wrote:
> > Paul Boddie wrote:
> >
> > """The figures behind the scenes are quite enlightening for that
> > particular page. If you (or community experiences) don't agree with the
> >
> > rankings (wxPython apparently even easier to learn than PythonCard and
> > Tinder, a bunch of Gtk-based toolkits having more or less "full" Linux
> > scores) then you'll have some surprises, I'm sure. Nevertheless, it's
> > an interesting concept. """
> >
> > Well, I don't know what I was thinking, exactly, when I rated
> > PythonCard's ease of use...so I went back and changed it to rate it a
> > lot higher. The ratings in this script were done a long time ago now
>
> I dropped Pythoncard when I could not sort multi column lists and when
> I posted to the email list and no one answered me.
> 
> But prior to that it was great.

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


missing collections module

2006-11-06 Thread Shea Martin
I am getting this error in a python script:

   File "/usr/sfw/lib/python2.3/site-packages/BTL/cache.py", line 12, in ?
 from collections import deque
ImportError: No module named collections

Where can I download the python collection module?  I am no python 
programmer, but I can build/install python packages if I know where to 
get them.

Thanks,

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


Re: missing collections module

2006-11-06 Thread skip

Shea> I am getting this error in a python script:
Shea>File "/usr/sfw/lib/python2.3/site-packages/BTL/cache.py", line 12, 
in ?
Shea>  from collections import deque
Shea> ImportError: No module named collections

Shea> Where can I download the python collection module?

You're probably using a package which is not supported under Python 2.3.
The collections module is new with 2.4.  Try upgrading to 2.4 or 2.5.

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


Re: Building C extensions

2006-11-06 Thread Martin v. Löwis
Paolo Pantaleo schrieb:
> Well I'm just courious: if I want to buid a C extension, I shoul use
> the same compiler that has been used to build python (right?). Since
> python has been built using Visual C, how can I build an extension if
> I don't have Visual Studio?

If you don't have mingw32, either, you can't build the extension module.
You need to get a supported compiler. If you don't have one, find
somebody who builds the extension for you.

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


Plot pkg - Multiple Y axes?

2006-11-06 Thread monkeyboy
Hello,

I'm searching for a plotting package that will allow multiple y axes of
different scales. For example I'd like to overlay 4 or 5 time series
with each series having a separate axis. Does anyone know of such a
package?

Thank you,

Frank

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


Re: how do I pass values between classes?

2006-11-06 Thread Larry Bates
kath wrote:
> hi, Larry Bates  thanks for the reply...
> 
>> You might consider doing it the same way wx passes things around.
>> When you instantiate the subclass pass the parent class' instance
>> as first argument to __init__ method.
> 
> Yes thats absolutely right..
> 
>> That way the subclass can
>> easily pass values back to the parent by using that pointer.
> 
> Could you please explain me this.. more clearly. I think it is much
> close to the solution.
> 
> 
> Thank you.
> regards, sudhir
> 
Just something like:

class foo:
self.__init__(self, parent):
self.parent=parent

class bar:
self.__init__(self, parent):
self.parent=parent
self.foo=foo(self)


class myclass:
self.__init__(self, parent):
self.parent=parent
self.bar=bar(self)

Now in foo I can reference things from myclass easily
self.parent.parent.  Or setattr(self.parent.parent, value).

Hope this helps.

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


Re: RAW network programming under Windows

2006-11-06 Thread Richard Charts

sturlamolden wrote:
> billie wrote:
>
> > RAW network programming under Windows it's not always possible because
> > of the security limitations that microsoft introduced in the latest
> > Windows versions and that affects WinSocket API.
> > On UNIX systems I'm able to freely send raw packets (for example I'm
> > able to compile IP packets with a src address defined by me) through
> > raw socket API, but if I do the same on a Windows system socket module
> > raises an error.
>
> You can try to install "Windows Services for Unix 3.5" (aka SFU 3.5).
> It transforms your Windows into a certified UNIX (not just a Unix
> clone). SFU 3.5 has a full BSD socket API (derived from OpenBSD), not
> just Winsock. As the POSIX subsystem in SFU 3.5 is not layered on top
> of the Win32 subsystem, but talks directly to the NT kernel,
> restrictions in Winsock should not affect the BSD sockets in SFU 3.5.
> This behaviour is different from e.g. Cygwin, where the "Unix APIs" are
> layered on top of the Win32 subsystem.
>
> In any case, I hope you are aware that spoofing IP packets gives you
> bad karma.

Hey, there are a few uses for spoofing source addresses.
Anyway, I didn't know that SHU replaced ( or added to) the stack.
I'll have to give SFU a try.
Thanks.

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


Re: adding python scripting to my application

2006-11-06 Thread Jerry
I am not a Python guru by any means, but I believe that when an
application says that you can "script" their application with Python,
it means that you can actually write Python code to interact with the
application.  Embedding may be the same thing.  Extending (as I read
it) involves writing portions of your program in Python and have do the
logic portions.

If you would like to allow users to write small scripts that interact
with your program and control it (a la VBScript or AppleScript), then I
believe embedding Python in your program is what you want.

If you would like Python to run various parts of your program in order
to make some portions easier to write/manage/whatever, then you want to
"extend" your program using Python.

The key difference being that you aren't providing a way for someone
else to interact with your program using Python if you are extending.

Again, I am not a guru and a read through the docs on python.org would
probably be the best place to get sound technical advice on these
subjects.

--
Jerry

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


Re: tips requested for a log-processing script

2006-11-06 Thread Jaap
Hendrik van Rooyen schreef:
> "Jaap" <[EMAIL PROTECTED]> wrote:
> 
> 
>> Python ers,
Thanks!
all your replies have been both to the point and helpfull for me.

You have proven both Python and it's community are open and welcoming to 
new users.

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


building python with utf-8 default encoding?

2006-11-06 Thread [EMAIL PROTECTED]
I am playing around with OpenSwarm and was shocked to see that I cannot
build Python with default encoding of utf-8 by passing a flag to
configure... did I miss the option for doing so?

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


Re: forwarding *arg parameter

2006-11-06 Thread Steve Holden
Tuomas wrote:
> Steven D'Aprano wrote:
> 
>>On Sun, 05 Nov 2006 19:35:58 +, Tuomas wrote:
>>
>>
>>
>>>Thanks. My solution became:
>>>
>>>
>>def flattern(arg):
>>>
>>>... result = []
>>>... for item in arg:
>>>... if isinstance(item, (list, tuple)):
>>>... result.extend(flattern(item))
>>>... else:
>>>... result.append(item)
>>>... return tuple(result)
>>>...
>>>
>>def g(*arg):
>>>
>>>... arg = flattern(arg)
>>>... return arg
>>>...
>>>
>>def f(*arg):
>>>
>>>... return g(arg)
>>>...
>>>
>>f('foo', 'bar')
>>>
>>>('foo', 'bar')
>>
>>
>>
>>That's the most complicated do-nothing function I've ever seen. Here is a
>>shorter version:
>>
>>def shortf(*args):
>>return args
>>
>>
>>
>>
>f('foo', 'bar')
>>
>>('foo', 'bar')
>>
>>
>shortf('foo', 'bar')
>>
>>('foo', 'bar')
>>
>>
>>
>f(1,2,3,4)
>>
>>(1, 2, 3, 4)
>>
>>
>shortf(1,2,3,4)
>>
>>(1, 2, 3, 4)
>>
>>
>>
>f({}, None, 1, -1.2, "hello world")
>>
>>({}, None, 1, -1.2, 'hello world')
>>
>>
>shortf({}, None, 1, -1.2, "hello world")
>>
>>({}, None, 1, -1.2, 'hello world')
>>
>>Actually, they aren't *quite* identical: your function rips lists apart,
>>which is probably not a good idea.
>>
>>
>>
>f("foo", [1,2,3], None) # three arguments turns into five
>>
>>('foo', 1, 2, 3, None)
>>
>>
>shortf("foo", [1,2,3], None) # three arguments stays three
>>
>>('foo', [1, 2, 3], None)
>>
>>
>>
>>I still don't understand why you are doing this. Can we have an example of
>>why you think you need to do this?
> 
> 
> If i redefine the function g the difference comes visible:
> 
>   >>> def g(*arg):
>  if with_flattern: arg=flattern(arg)
>  return arg
> 
>  >>> with_flattern=False
>  >>> f('foo', 'bar')
> (('foo', 'bar'),)
>  >>> with_flattern=True
>  >>> f('foo', 'bar')
> 
> If you read the whole chain you find out what we were talking of.
> 
> TV

Suppose you did actually want to do this you have chosen about the worst 
possible way: the use of global variables to condition function 
execution is a sure way to get into trouble. Consider if somebody else 
want to use your function: they also have to set a global in their 
program to avoid your function raising an exception.

Fortunately Python has just the thing to make such horrors unnecessary: 
the default argument value. Try something like this (untested):

def g(flattening=True, *arg):
 if flattening:
arg = flatten(arg)
 return arg

Obviously you could use either True or False for the default value. In 
the case above the function flattens by default. You could also, if you 
wished, have f() take the flattening argument, and always pass it to g().

Nothing very sophisticated here, just something to help you flex your 
growing Python and programming muscles.

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


Unicode/ascii encoding nightmare

2006-11-06 Thread Thomas W
I'm getting really annoyed with python in regards to
unicode/ascii-encoding problems.

The string below is the encoding of the norwegian word "fødselsdag".

>>> s = 'f\xc3\x83\xc2\xb8dselsdag'

I stored the string as "fødselsdag" but somewhere in my code it got
translated into the mess above and I cannot get the original string
back. It cannot be printed in the console or written a plain text-file.
I've tried to convert it using

>>> s.encode('iso-8859-1')
Traceback (most recent call last):
  File "", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
ordinal not in range(128)

>>> s.encode('utf-8')
Traceback (most recent call last):
  File "", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
ordinal not in range(128)

And nothing helps. I cannot remember hacing these problems in earlier
versions of python and it's really annoying, even if it's my own fault
somehow, handling of normal characters like this shouldn't cause this
much hassle. Searching google for "codec can't decode byte" and
UnicodeDecodeError etc. produces a bunch of hits so it's obvious I'm
not alone.

Any hints?

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


getchar [was: Re: Python-list Digest, Vol 38, Issue 72]

2006-11-06 Thread Steve Holden
Santosh Chikkerur wrote:
> Hi Friends,
> 
> How to use getchar( ) in python. I want to see the output of the program 
> ,step by step.
> I have given print statements in between for the results..
> Hence i would like to print the output everytime there is 
> getchar().which is the
> similar fn in python
> 
[... several hundred lines of irrelevant digest omitted ...]
In future please don't quote the whole of a digest just to ask a simple 
question! Instead send an email to [EMAIL PROTECTED] Also, it 
helps if you can give a subject line that indicates what you are asking 
about.

Python has getch() in Windows only, there is no getchar(). If you want 
your program to be portable to Linux/Unix as well then getch() won't do. 
I have seen a portable recipe, but my google-fu is low today so I'll 
have to let someone else point that out if you need it.

However, if the Enter key will do then just try inserting

raw_input("Hit Enter to continue: ")

That'll work on any platform.

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: adding python scripting to my application

2006-11-06 Thread martdi
Jerry wrote:
> I am not a Python guru by any means, but I believe that when an
> application says that you can "script" their application with Python,
> it means that you can actually write Python code to interact with the
> application.  Embedding may be the same thing.  Extending (as I read
> it) involves writing portions of your program in Python and have do the
> logic portions.
>
> If you would like to allow users to write small scripts that interact
> with your program and control it (a la VBScript or AppleScript), then I
> believe embedding Python in your program is what you want.
>
> If you would like Python to run various parts of your program in order
> to make some portions easier to write/manage/whatever, then you want to
> "extend" your program using Python.
>
> The key difference being that you aren't providing a way for someone
> else to interact with your program using Python if you are extending.
>
> Again, I am not a guru and a read through the docs on python.org would
> probably be the best place to get sound technical advice on these
> subjects.
>
> --
> Jerry


I'm not sure either, but I though Extending was making the C/C++ Code
available from Python, while Embedding was making Python Code Available
in your app.

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


auto indent

2006-11-06 Thread M.N.Smadi
Hi there;

i have a script that is not indented properly. Is there a way that i can 
have it auto indented.

thanks
moe smadi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: adding python scripting to my application

2006-11-06 Thread John Henry
Take a look at:

http://www.swig.org/

Julian wrote:
> Hi, first of all, I have to say I am new to Python. I have been working
> with a finite element analysis program written in c++. now, I am trying
> to 'rebuild' this code (possibly a full re-write) with scripting
> capability. I did some reading on the web, and found that there are two
> ways to do this : extending and embedding. and I still haven't figured
> out what I should be using. I guess the first thing is to figure out
> what I am to do with the scripting capability - at the very least, I
> would like to run parametric analyses - run multiple analysis models by
> changing certain parameters using for loops.
> i found that the commercial fea package - abaqus uses python as well -
> I don't know whether they embedded or extended ? is there any way to
> find out?
> another fea application called OOF2
> (http://www.ctcms.nist.gov/oof/oof2/#features) says "OOF2 is completely
> scriptable in Python". and I don't really understand what that means...
> maybe I haven't grasped the full potential of what python scripting
> could do for an fea program.
>
> can you tell me how to decide what path I should take - embed or extend
> ? or maybe some one could point me to some document/webpage that talks
> about this.
>
> thanks a lot,
> Julian.
>
> PS, my fea program uses its own script to read the analysis model
> information using the c++ iostream and our own parsing functions - but
> I don't have to stick to those function when I am writing the new code.

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


Re: Unicode/ascii encoding nightmare

2006-11-06 Thread Mark Peters
> The string below is the encoding of the norwegian word "fødselsdag".
>
> >>> s = 'f\xc3\x83\xc2\xb8dselsdag'

I'm not sure which encoding method you used to get the string above.
Here's the result of my playing with the string in IDLE:

>>> u1 = u'fødselsdag'
>>> u1
u'f\xf8dselsdag'
>>> s1 = u1.encode('utf-8')
>>> s1
'f\xc3\xb8dselsdag'
>>> u2 = s1.decode('utf-8')
>>> u2
u'f\xf8dselsdag'
>>> print u2
fødselsdag
>>>

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


Re: building python with utf-8 default encoding?

2006-11-06 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> I am playing around with OpenSwarm and was shocked to see that I cannot
> build Python with default encoding of utf-8 by passing a flag to
> configure... did I miss the option for doing so?

No. The default encoding (the return value of sys.getdefaultencoding()) should
alway be 'ascii'. Otherwise, programs written on one machine will not run on
other machines.

-- 
Robert Kern

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

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


Re: Erronous "unsupported locale setting" ?

2006-11-06 Thread Leo Kislov

robert wrote:
> Leo Kislov wrote:
> > robert wrote:
> >> Why can the default locale not be set by its true name? but only by '' ? :
> >
> > Probably it is just not implemented. But since locale names are system
> > specific (For example windows accepts 'ch' as Chinese in Taiwan, where
> > as IANA 
> > considers it Chamorro) setlocale should probably grow an additional
> > keyword parameter: setlocale(LC_ALL, iana='de-DE')
>
> that'd be another fat database to blow up the python core(s).
>
> I just wonder why locale.setlocale(locale.LC_ALL,"de_DE") doesn't accept the 
> name, which
> >>> locale.getlocale() / getdefaultlocale()
> ('de_DE', 'cp1252')
> already deliver ?

It is documented that those functions return cross platform RFC 1766
language code. This code sometimes won't be compatible with OS specific
locale name. Cross platform code can useful if you want to create your
own locale database for example cross platform language packs.

Right now we have:

setlocale(category) -- get(it's not a typo) OS locale name
getlocale(category) -- get cross platform locale name
setlocale(category,'') -- enable default locale, return OS locale name
getdefaultlocale()  -- get cross platform locale name

I agree it's very confusing API, especially setlocale acting like
getter, but that's what we have. Improvement is welcome.

  -- Leo

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


Re: Unicode/ascii encoding nightmare

2006-11-06 Thread Robert Kern
Thomas W wrote:
> I'm getting really annoyed with python in regards to
> unicode/ascii-encoding problems.
> 
> The string below is the encoding of the norwegian word "fødselsdag".
> 
 s = 'f\xc3\x83\xc2\xb8dselsdag'
> 
> I stored the string as "fødselsdag" but somewhere in my code it got
> translated into the mess above and I cannot get the original string
> back. It cannot be printed in the console or written a plain text-file.
> I've tried to convert it using
> 
 s.encode('iso-8859-1')
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
> ordinal not in range(128)
> 
 s.encode('utf-8')
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
> ordinal not in range(128)
> 
> And nothing helps. I cannot remember hacing these problems in earlier
> versions of python and it's really annoying, even if it's my own fault
> somehow, handling of normal characters like this shouldn't cause this
> much hassle. Searching google for "codec can't decode byte" and
> UnicodeDecodeError etc. produces a bunch of hits so it's obvious I'm
> not alone.

You would want .decode() (which converts a byte string into a Unicode string),
not .encode() (which converts a Unicode string into a byte string). You get
UnicodeDecodeErrors even though you are trying to .encode() because whenever
Python is expecting a Unicode string but gets a byte string, it tries to decode
the byte string as 7-bit ASCII. If that fails, then it raises a 
UnicodeDecodeError.

However, I don't know of an encoding that takes u"fødselsdag" to
'f\xc3\x83\xc2\xb8dselsdag'.

-- 
Robert Kern

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

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

Re: building python with utf-8 default encoding?

2006-11-06 Thread Jim

[EMAIL PROTECTED] wrote:
> I am playing around with OpenSwarm and was shocked to see that I cannot
> build Python with default encoding of utf-8 by passing a flag to
> configure... did I miss the option for doing so?
It is not set when you build but is instead set in sitecustomize.py.
But changing it is typically inadvisable in that any programs you write
will not port to other people's machines.

Jim

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


Re: Learning Python

2006-11-06 Thread [EMAIL PROTECTED]

If you have some math knowledge or what to increase it, plus want to
use that knowledge as leverage when it comes to learning a computer
language, in this case Python, may I suggest my CP4E web page and its
many links to math topics, all explored using open source code, mostly
Python but also some J (if you're curious about a really *different*
language):

http://www.4dsolutions.net/ocn/cp4e.html

Kirby
Oregon Curriculum Network
[EMAIL PROTECTED]


kaushal wrote:
> Hi
>
> How do i start Learning Python,is there any reference material which I
> can refer since I dont have
> any programming experience
> 
> Thanks and Regards
> 
> Kaushal

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


Re: Unicode/ascii encoding nightmare

2006-11-06 Thread John Machin
Thomas W wrote:
> I'm getting really annoyed with python in regards to
> unicode/ascii-encoding problems.
>
> The string below is the encoding of the norwegian word "fødselsdag".
>
> >>> s = 'f\xc3\x83\xc2\xb8dselsdag'

There is no such thing as "*the* encoding" of any given string.

>
> I stored the string as "fødselsdag" but somewhere in my code it got
> translated into the mess above and I cannot get the original string
> back.

Somewhere in your code??? Can't you track through your code to see
where it is being changed? Failing that, can't you show us your code so
that we can help you?

I have guessed *what* you got, but *how* you got it boggles the mind:

The effect is the same as (decode from latin1 to Unicode, encode as
utf8) *TWICE*. That's how you change one byte in the original to *FOUR*
bytes in the "mess":

| >>> orig = 'f\xf8dselsdag'
| >>> orig.decode('latin1').encode('utf8')
| 'f\xc3\xb8dselsdag'
| >>>
orig.decode('latin1').encode('utf8').decode('latin1').encode('utf8')
| 'f\xc3\x83\xc2\xb8dselsdag'
| >>>

> It cannot be printed in the console or written a plain text-file.

Incorrect. *Any* string can be printed on the console or written to a
file. What you mean is that when you look at the output, it is not what
you want.

> I've tried to convert it using
>
> >>> s.encode('iso-8859-1')
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
> ordinal not in range(128)

encode is an attribute of unicode objects. If applied to a str object,
the str object is converted to unicode first using the default codec
(typically ascii).

s.encode('iso-8859-1') is effectively
s.decode('ascii').encode('iso-8859-1'), and s.decode('ascii') fails for
the (obvious(?)) reason given.

>
> >>> s.encode('utf-8')
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
> ordinal not in range(128)

Same story as for 'iso-8859-1'

>
> And nothing helps. I cannot remember hacing these problems in earlier
> versions of python

I would be very surprised if you couldn't reproduce your problem on any
2.n version of Python.

> and it's really annoying, even if it's my own fault
> somehow, handling of normal characters like this shouldn't cause this
> much hassle. Searching google for "codec can't decode byte" and
> UnicodeDecodeError etc. produces a bunch of hits so it's obvious I'm
> not alone.
>
> Any hints?

1. Read the Unicode howto: http://www.amk.ca/python/howto/unicode
2. Read the Python documentation on .decode() and .encode() carefully.
3. Show us your code so that we can help you avoid the double
conversion to utf8. Tell us what IDE you are using.
4. Tell us what you are trying to achieve. Note that if all you are
trying to do is read and write text in Norwegian (or any other language
that's representable in iso-8859-1 aka latin1), then you don't have to
do anything special at all in your code-- this is the good old "legacy"
way of doing things universally in vogue before Unicode was invented!

HTH,
John

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


Re: Unicode/ascii encoding nightmare

2006-11-06 Thread John Machin

Robert Kern wrote:

> However, I don't know of an encoding that takes u"fødselsdag" to
> 'f\xc3\x83\xc2\xb8dselsdag'.

There isn't one.

C3 and C2 hint at UTF-8.
The fact that C3 and C2 are both present, plus the fact that one
non-ASCII byte has morphoploded into 4 bytes indicate a double whammy.

Cheers,
John

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


Re: Unicode/ascii encoding nightmare

2006-11-06 Thread Andrea Griffini
John Machin wrote:

> The fact that C3 and C2 are both present, plus the fact that one
> non-ASCII byte has morphoploded into 4 bytes indicate a double whammy.

Indeed...

 >>> x = u"fødselsdag"
 >>> x.encode('utf-8').decode('iso-8859-1').encode('utf-8')
'f\xc3\x83\xc2\xb8dselsdag'

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


Re: Unicode/ascii encoding nightmare

2006-11-06 Thread Georg Brandl
Thomas W wrote:
> I'm getting really annoyed with python in regards to
> unicode/ascii-encoding problems.
> 
> The string below is the encoding of the norwegian word "fødselsdag".
> 
 s = 'f\xc3\x83\xc2\xb8dselsdag'

Which encoding is this?

> I stored the string as "fødselsdag" but somewhere in my code it got

You stored it where?

> translated into the mess above and I cannot get the original string
> back. It cannot be printed in the console or written a plain text-file.
> I've tried to convert it using
> 
 s.encode('iso-8859-1')
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
> ordinal not in range(128)

Note that "encode" on a string object is often an indication for an error.
The encoding direction (for "normal" encodings, not special things like
the "zlib" codec) is as follows:

encode: from Unicode
decode: to Unicode

(the encode method of strings first DEcodes the string with the default
encoding, which is normally ascii, then ENcodes it with the given encoding)

 s.encode('utf-8')
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
> ordinal not in range(128)
> 
> And nothing helps. I cannot remember hacing these problems in earlier
> versions of python and it's really annoying, even if it's my own fault
> somehow, handling of normal characters like this shouldn't cause this
> much hassle. Searching google for "codec can't decode byte" and
> UnicodeDecodeError etc. produces a bunch of hits so it's obvious I'm
> not alone.

Unicode causes many problems if not used properly. If you want to use Unicode
strings, use them everywhere in your Python application, decode input as early
as possible, and encode output only before writing it to a file or another
program.

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


sqlite error?

2006-11-06 Thread John Salerno
Am I using the ? placeholder wrong in this example?


t = ('hi', 'bye')

self.connection.execute("INSERT INTO Personal (firstName, lastName) 
VALUES ?", t)



Traceback (most recent call last):
   File "C:\Python25\myscripts\labdb\dbapp.py", line 93, in OnSaveRecord
 self.save_to_database(textfield_values)
   File "C:\Python25\myscripts\labdb\dbapp.py", line 97, in save_to_database
 self.connection.execute("INSERT INTO Personal (firstName, lastName) 
VALUES ?", t)
sqlite3.OperationalError: near "?": syntax error
-- 
http://mail.python.org/mailman/listinfo/python-list


os x make install dies when compiling zipfile.py on 2.5 and 2.4.4

2006-11-06 Thread metaperl
I've tried both Python 2.4.4 and Python 2.5. I'm trying to build from
source and install under a local directory Swarm since OpenSwarm
requires builds of Postgres and Python under it's control.

Ok, so I did

./configure --prefix=/Users/tbrannon/Documents/Python/Swarm/Python-2.5

but during make install I get this:

Compiling
/Users/tbrannon/Documents/Python/Swarm/Python-2.5/lib/python2.5/xmlrpclib.py
...
Compiling
/Users/tbrannon/Documents/Python/Swarm/Python-2.5/lib/python2.5/zipfile.py
...
make: *** [libinstall] Error 1


and the same thing happens for Python 2.4.4 leaving me without a
platform-depedent install directory in my build.. any ideas?

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


Re: sqlite error?

2006-11-06 Thread BartlebyScrivener
>> self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES ?", t)

John,

I'm no expert, but try

self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES ?, ?", t)

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


Re: sqlite error?

2006-11-06 Thread [EMAIL PROTECTED]

John Salerno wrote:
> Am I using the ? placeholder wrong in this example?
>
>
> t = ('hi', 'bye')
>
> self.connection.execute("INSERT INTO Personal (firstName, lastName)
> VALUES ?", t)
>
>
>
> Traceback (most recent call last):
>File "C:\Python25\myscripts\labdb\dbapp.py", line 93, in OnSaveRecord
>  self.save_to_database(textfield_values)
>File "C:\Python25\myscripts\labdb\dbapp.py", line 97, in save_to_database
>  self.connection.execute("INSERT INTO Personal (firstName, lastName)
> VALUES ?", t)
> sqlite3.OperationalError: near "?": syntax error

I believe you're missing the parens around your VALUES to insert. Also,
you need 1 placeholder per argument inserted, not just one for the
entire argument list. Try:

self.connection.execute("INSERT INTO Personal (firstName, lastName)
VALUES (?, ?)", t)

HTH

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


Re: WebScraping

2006-11-06 Thread Bernard
yup yup BeautifulSoup is the way to go.

what would you like to scrape by the way?

Graham Feeley wrote:
> Can someone steer me to scripts / modules etc on webscraping please???
> Ultimately I would like someone to write a script for me.
> However i am still searching for documentation on this subject
> Thanks Graham

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


Re: sqlite error?

2006-11-06 Thread John Salerno
[EMAIL PROTECTED] wrote:
> John Salerno wrote:
>> Am I using the ? placeholder wrong in this example?
>>
>>
>> t = ('hi', 'bye')
>>
>> self.connection.execute("INSERT INTO Personal (firstName, lastName)
>> VALUES ?", t)
>>
>>
>>
>> Traceback (most recent call last):
>>File "C:\Python25\myscripts\labdb\dbapp.py", line 93, in OnSaveRecord
>>  self.save_to_database(textfield_values)
>>File "C:\Python25\myscripts\labdb\dbapp.py", line 97, in save_to_database
>>  self.connection.execute("INSERT INTO Personal (firstName, lastName)
>> VALUES ?", t)
>> sqlite3.OperationalError: near "?": syntax error
> 
> I believe you're missing the parens around your VALUES to insert. Also,
> you need 1 placeholder per argument inserted, not just one for the
> entire argument list. Try:
> 
> self.connection.execute("INSERT INTO Personal (firstName, lastName)
> VALUES (?, ?)", t)
> 
> HTH
> 

Thanks guys. I'll try this. I thought the ? stood for the whole tuple.
-- 
http://mail.python.org/mailman/listinfo/python-list


assigning values in __init__

2006-11-06 Thread John Salerno
Let's say I'm making a game and I have this base class:

class Character(object):

 def __init__(self, name, stats):
 self.name = name
 self.strength = stats[0]
 self.dexterity = stats[1]
 self.intelligence = stats[2]
 self.luck = stats[3]

Is this a good way to assign the values to the different attributes? 
Should 'stats' be a list/tuple (like this), or should I do *stats instead?

I'm trying to think ahead to when I might want to add new attributes, 
and I want to make sure this doesn't get crazy with individual 
parameters instead of just the one list.

Or maybe there's some way to loop through two lists (the stats and the 
attributes) and assign them that way? I was thinking of a nested for 
statement but that didn't seem to work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: auto indent

2006-11-06 Thread Larry Bates
M.N.Smadi wrote:
> Hi there;
> 
> i have a script that is not indented properly. Is there a way that i can
> have it auto indented.
> 
> thanks
> moe smadi

Not really.  Indention in python conveys blocks so there is no way
anything automatic could determine where blocks end.  Its just like
asking if you could have something automatically insert parenthesis
everywhere they are needed.

-Larry

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


sound processing modules in python - anyone?

2006-11-06 Thread sittner
Hi everyone,
I'm looking for a module for sound processing (manipulating sound objets,
filters, ffts etc.).
I tried Snack, but when i downloaded the package that was supposed to be
for python, there was only the Tk/Tcl stuff (where's the .py ?).
could anyone help me with that (or with any other sound module for python)?
thanks in advance,
g

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


Re: assigning values in __init__

2006-11-06 Thread Larry Bates
John Salerno wrote:
> Let's say I'm making a game and I have this base class:
> 
> class Character(object):
> 
> def __init__(self, name, stats):
> self.name = name
> self.strength = stats[0]
> self.dexterity = stats[1]
> self.intelligence = stats[2]
> self.luck = stats[3]
> 
> Is this a good way to assign the values to the different attributes?
> Should 'stats' be a list/tuple (like this), or should I do *stats instead?
> 
> I'm trying to think ahead to when I might want to add new attributes,
> and I want to make sure this doesn't get crazy with individual
> parameters instead of just the one list.
> 
> Or maybe there's some way to loop through two lists (the stats and the
> attributes) and assign them that way? I was thinking of a nested for
> statement but that didn't seem to work.

Sounds like what you should be doing is something like keyword arguments
instead.

class Character(object):
def __init__(self, name, **kwargs):
self.name=name
for key, value in kwargs.items():
setattr(self, key, value)


z=Character('name', strength=10, dexterity=5, intelligence=3, luck=0)

Now you can easily introduce new keyword arguments.

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


Re: assigning values in __init__

2006-11-06 Thread Gerard Flanagan

John Salerno wrote:
> Let's say I'm making a game and I have this base class:
>
> class Character(object):
>
>  def __init__(self, name, stats):
>  self.name = name
>  self.strength = stats[0]
>  self.dexterity = stats[1]
>  self.intelligence = stats[2]
>  self.luck = stats[3]
>
> Is this a good way to assign the values to the different attributes?
> Should 'stats' be a list/tuple (like this), or should I do *stats instead?
>

How about:

class Character(object):

def __init__(self, name, **kwargs):
self.name = name
self.__dict__.update(kwargs)

c = Character( "Plato", strength=10, luck=12)

print getattr(c, "strength")
print getattr(c, "luck")

10
12

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


you can erase me last message - a mistake....

2006-11-06 Thread sittner
you can erase the message about python sound modules, my mistake.
thanks,
g

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


Re: Projecting MUD maps

2006-11-06 Thread Gabriel Genellina
At Sunday 5/11/2006 19:32, BJörn Lindqvist wrote:

>Hello, I'm looking for an algorithm to project "MUD maps" such as the
>following map: http://www.aww-mud.org/maps/MUD_Maps/Caerin-colour.jpg
>
>MUD:s consists of rooms, each rooms has up to four orthogonal edges
>(north, east, west and south) that connects it to another room. So it
>is very easy to model a MUD as a directed graph. But projecting the

You could use dot www.graphviz.org
I think there is a python wrapper -pydot maybe?- 
but anyway the dot file format is very easy to write.


-- 
Gabriel Genellina
Softlab SRL 

__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learning Python

2006-11-06 Thread Luis M. González

kaushal wrote:
> Hi
>
> How do i start Learning Python,is there any reference material which I
> can refer since I dont have
> any programming experience
>
> Thanks and Regards
>
> Kaushal

If you have no programming experience at all, I highly recomend "Non
Programmers Tutorial for Python" by Josh Cogliati:
http://www.honors.montana.edu/~jjc/easytut/easytut/easytut.html

This is how I got my feet wet with Python, and it's very easy to
follow.

I also recomend "A Byte of Python" by Swaroop:
http://swaroopch.info/text/Byte_of_Python:Main_Page

Both ebooks are available in multiple formats and are free.
God luck!
Luis

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


Re: forwarding *arg parameter

2006-11-06 Thread Tuomas
Steve Holden wrote:
> Suppose you did actually want to do this you have chosen about the worst 
> possible way: the use of global variables to condition function 
> execution is a sure way to get into trouble. Consider if somebody else 
> want to use your function: they also have to set a global in their 
> program to avoid your function raising an exception.

Do you think all discussion examples are included a producton application.

> Fortunately Python has just the thing to make such horrors unnecessary: 
> the default argument value. Try something like this (untested):
> 
> def g(flattening=True, *arg):
> if flattening:
> arg = flatten(arg)
> return arg
> 
> Obviously you could use either True or False for the default value. In 
> the case above the function flattens by default. You could also, if you 
> wished, have f() take the flattening argument, and always pass it to g().
> 
> Nothing very sophisticated here, just something to help you flex your 
> growing Python and programming muscles.

Thanks for your good purposes.

TV

> regards
>  Steve
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SPE editor slow?

2006-11-06 Thread timmy
SPE - Stani's Python Editor wrote:
> timmy schreef:
> 
> 
>>hello i've been using the SPE editor on a moderately large project and
>>it's constantly pausing during editing, like it's attempting to check
>>something as i edit.
>>as you can imagine a 4 second pause every few characters is EXTREMELY
>>annoying when you just want to get some work done. i really like SPE's
>>layout and features but if it's going to be dogshit slow all the time
>>i'll have to change. please help!
> 
> 
> SPE does error syntax checking which works fine for normal sized python
> files. With these settings you can speed up SPE for larger projects:
> 1. Edit>Preferences>Editor: Check realtime with "none" (default value:
> compiler)
> 2. Edit>Preferences>Editor: Update sidebar "when clicked"
> 
> You can first try step 1, if you want SPE faster, use step 2 as well.
> 
> Stani
> 

thanks stani i actually had an incling that 2. was the real problem. 
i've got probably 200 or so clases in my project and it was pausing 
mainly when it came to names of things or a .
i changed it to on clicked and it's fine now.

it still does something else though that i'm at a loss to fix. when i 
open a file or run a script is throws up errors saying "Failed to 
display HTML document in ISO-8859-1 encoding"

i guess thats a problem with those bottom info windows?
-- 
http://mail.python.org/mailman/listinfo/python-list


python-ldap/win32 or python/ldap/win32

2006-11-06 Thread rcmn
i'm running around in circle trying to to use python/ldap/ on
win32(WinXP). I want to write a script that read SQL data(no pbm) and
insert member in a AD group(pbm).I used the module
Active_Directory(very easy to use).but it read only AD.
So i have been try to install python-ldap on a win32/python2.4
install.But each time i try


setup.py build

i get

-

running build_ext
error: The .NET Framework SDK needs to be installed before building
extensions for Python.
--
of course i insalled .NET ,and it keeped doing it, google around found
some registry key thing that have to be changed.tried that but still
nothing.I have been looking around more but the informations i find on
that topic seems so clunky and out dated(2004-2003) that i really don't
think i should wast my time any further without asking around if i'm
going the right direction.Because i have the feeling Python/Ldap/win32
shouldn't be such a problem to use...And if it isn't then...Python is
not the language i need to accomplish that task.

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


Re: Unicode/ascii encoding nightmare

2006-11-06 Thread Thomas W
Ok, I've cleaned up my code abit and it seems as if I've
encoded/decoded myself into a corner ;-). My understanding of unicode
has room for improvement, that's for sure. I got some pointers and
initial code-cleanup seem to have removed some of the strange results I
got, which several of you also pointed out.

Anyway, thanks for all your replies. I think I can get this thing up
and running with a bit more code tinkering. And I'll read up on some
unicode-docs as well. :-) Thanks again.

Thomas



John Machin wrote:
> Thomas W wrote:
> > I'm getting really annoyed with python in regards to
> > unicode/ascii-encoding problems.
> >
> > The string below is the encoding of the norwegian word "fødselsdag".
> >
> > >>> s = 'f\xc3\x83\xc2\xb8dselsdag'
>
> There is no such thing as "*the* encoding" of any given string.
>
> >
> > I stored the string as "fødselsdag" but somewhere in my code it got
> > translated into the mess above and I cannot get the original string
> > back.
>
> Somewhere in your code??? Can't you track through your code to see
> where it is being changed? Failing that, can't you show us your code so
> that we can help you?
>
> I have guessed *what* you got, but *how* you got it boggles the mind:
>
> The effect is the same as (decode from latin1 to Unicode, encode as
> utf8) *TWICE*. That's how you change one byte in the original to *FOUR*
> bytes in the "mess":
>
> | >>> orig = 'f\xf8dselsdag'
> | >>> orig.decode('latin1').encode('utf8')
> | 'f\xc3\xb8dselsdag'
> | >>>
> orig.decode('latin1').encode('utf8').decode('latin1').encode('utf8')
> | 'f\xc3\x83\xc2\xb8dselsdag'
> | >>>
>
> > It cannot be printed in the console or written a plain text-file.
>
> Incorrect. *Any* string can be printed on the console or written to a
> file. What you mean is that when you look at the output, it is not what
> you want.
>
> > I've tried to convert it using
> >
> > >>> s.encode('iso-8859-1')
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
> > ordinal not in range(128)
>
> encode is an attribute of unicode objects. If applied to a str object,
> the str object is converted to unicode first using the default codec
> (typically ascii).
>
> s.encode('iso-8859-1') is effectively
> s.decode('ascii').encode('iso-8859-1'), and s.decode('ascii') fails for
> the (obvious(?)) reason given.
>
> >
> > >>> s.encode('utf-8')
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
> > ordinal not in range(128)
>
> Same story as for 'iso-8859-1'
>
> >
> > And nothing helps. I cannot remember hacing these problems in earlier
> > versions of python
>
> I would be very surprised if you couldn't reproduce your problem on any
> 2.n version of Python.
>
> > and it's really annoying, even if it's my own fault
> > somehow, handling of normal characters like this shouldn't cause this
> > much hassle. Searching google for "codec can't decode byte" and
> > UnicodeDecodeError etc. produces a bunch of hits so it's obvious I'm
> > not alone.
> >
> > Any hints?
>
> 1. Read the Unicode howto: http://www.amk.ca/python/howto/unicode
> 2. Read the Python documentation on .decode() and .encode() carefully.
> 3. Show us your code so that we can help you avoid the double
> conversion to utf8. Tell us what IDE you are using.
> 4. Tell us what you are trying to achieve. Note that if all you are
> trying to do is read and write text in Norwegian (or any other language
> that's representable in iso-8859-1 aka latin1), then you don't have to
> do anything special at all in your code-- this is the good old "legacy"
> way of doing things universally in vogue before Unicode was invented!
> 
> HTH,
> John

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


Re: Unicode/ascii encoding nightmare

2006-11-06 Thread John Machin

Thomas W wrote:
> Ok, I've cleaned up my code abit and it seems as if I've
> encoded/decoded myself into a corner ;-). My understanding of unicode
> has room for improvement, that's for sure. I got some pointers and
> initial code-cleanup seem to have removed some of the strange results I
> got, which several of you also pointed out.
>
> Anyway, thanks for all your replies. I think I can get this thing up
> and running with a bit more code tinkering. And I'll read up on some
> unicode-docs as well. :-) Thanks again.

I strongly suggest that you read the docs *FIRST*, and don't "tinker"
at all.

HTH,
John

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


Re: simple way to un-nest (flatten?) list

2006-11-06 Thread djc
George Sakkis wrote:
 > Meet itertools:
 >
 > from itertools import chain
 > names = set(chain(*r.itervalues()))
 > print [line for line in table if line[7] in names]

Steven D'Aprano wrote:
> Assuming you don't care what order the strings are in:
> 
> r = {'a':('ASLIB','Aslib'),'j':('JDOC','jdoc')}
> result = sum(r.values(), ())
> 
> If you do care about the order:
> 
> r = {'a':('ASLIB','Aslib'),'j':('JDOC','jdoc')}
> keys = r.keys()
> keys.sort()
> result = []
> for key in keys:
> result.extend(r[key])
> result = tuple(result)

Thank you everybody.
As it is possible that the tuples will not always be the same word in 
variant cases
result = sum(r.values(), ())
  will do fine and is as simple as I suspected the answer would be.





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


Re: Unicode/ascii encoding nightmare

2006-11-06 Thread John Machin

Andrea Griffini wrote:
> John Machin wrote:
>
> > The fact that C3 and C2 are both present, plus the fact that one
> > non-ASCII byte has morphoploded into 4 bytes indicate a double whammy.
>
> Indeed...
>
>  >>> x = u"fødselsdag"
>  >>> x.encode('utf-8').decode('iso-8859-1').encode('utf-8')
> 'f\xc3\x83\xc2\xb8dselsdag'
>

Indeed yourself. Have you ever considered reading posts in
chronological order, or reading all posts in a thread? It might help
you avoid writing posts with non-zero information content.

Cheers,
John

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


Re: Wait for keyboard input

2006-11-06 Thread Gabriel Genellina

At Monday 6/11/2006 09:58, Santosh Chikkerur wrote:

How to use getchar( ) in python. I want to see the output of the 
program ,step by step.

I have given print statements in between for the results..
Hence i would like to print the output everytime there is 
getchar().which is the

similar fn in python


Use raw_input() and press ENTER.


When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."


Best if you follow that suggestion...


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

ctypes, python 2.5, WinFunctionType and _as_parameter_

2006-11-06 Thread gerard5609
Hello,

how to get at the function address of a WinFunctionType ctypes object ?
With ctypes 1.0, I used just myfunc._as_parameter_ and all was well.
With ctypes 1.0.1, that ships with python 2.5, WinFunctionType has no
longer an _as_parameter_ attribute

Where in the ChangeLog and the documentation is explained how to deal
with this change ?

Thanks in advance,

Gerard

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


  1   2   >