Re: problem writing to a file each record read

2006-03-14 Thread Peter Otten
Eduardo Biano wrote:

> #---
> #  This is the problem code. Ten records
> #  is  lump into 1 row and written
> #  in the output file.
> #
> #  My expected output is 10 rows.
> #---
> info = string.join([fn, mi, ln, deg, dat]

Should probably be ",".join([fn, mi, ln, deg, dat])

> outfile.write(info)

You have to add a newline explicitly if you want one:

outfile.write("\n") 

Using the csv module that comes with Python may simplify your task a lot.

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


Re: Printable string for 'self'

2006-03-14 Thread Fredrik Lundh
Don Taylor wrote:

> And if I call my method: A().qualify global_names_bound_to_me() then I
> get an empty list back.
>
> Is what I want to do not possible without referring back to the source?

objects don't have names in Python, and the source is not part of
the running program.

have you read this ?

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





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


Re: andmap and ormap

2006-03-14 Thread Peter Otten
Peter Otten wrote:

> def andmap(predicate, items):
> return False not in (predicate(item) for item in items)
> 
> def ormap(predicate, items):
> return True in (predicate(items) for item in items)

These are both broken because they imply the test (in e. g. ormap)

if True == predicate(item): ... where if predicate(item): ...

would be appropriate. Sorry for the garbage post.

Follow Felipe's or Scott's recipes. 

Peter




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


Re: Is this possible in Python?

2006-03-14 Thread alainpoint

Steven D'Aprano wrote:

>
> Doesn't work for me either:
>
> >>> def magic(arg):
> ... import inspect
> ... return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
> ...
> >>> magic(3+4)
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 3, in magic
> TypeError: unsubscriptable object
>
>
> Kay gets an AssertionError, I get a TypeError. I think describing it as
> "proof of concept" is rather optimistic.
>
> Here is the inspect.stack() I get:
>
> [(, '', 2, 'magic', None, None),
> (, '', 1, '?', None, None)]
>
>
> --
> Steven.

You just proved what i was saying: this is no robust code. It
apparently does not work from the command line. It has problems with
comments on the same line. It might have problems with multi-line
arguments, etc 
Please feel free to improve the above function and make it robust.
(meanwhile, i removed the SOLUTION FOUND from the subject title, until
you come up with such a robust version ;-))
Alain

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


problem writing to a file each record read

2006-03-14 Thread Eduardo Biano

I am a python newbie and I have a problem with writing
each record read to a file. The expected output is 10
rows of records, but the actual output of the code
below is only one row with a very long record (10
records are lump into one record). Thank you in
advance for your help. Here is the code:
  


infile = open('c:/grad3650txt.csv', 'r')
outfile = open('c:/idmast01.txt', 'w')

a = 1
b = 10
for line in infile.readlines():
if a <= b:
c1 = line.find(',',0)   
ln = line[1:c1] 
l2 = line.find('"', c1)
l2a = l2 - 1
l2c = l2
if line[l2a] == '.':
l2b = l2 - 3
if line[l2b] == ' ':
mi = line[l2b+1:l2a+1]
l2c = l2b
else:
mi = '  '
l2c = l2
fn = line[c1+2:l2c]
c2 = line.find(',', l2)
c3 = line.find(',', c2+1)
deg = line[c2+1:c3]
l5 = len(line)
c4 = line.find(',', c3+1)
l7 = c3 + 14
if l5 <= l7 or c4 <= l5:
l8 = l5
if c4 <= l5:
dat = line[c3+1:c4]

#---
#  This is the problem code. Ten records 
#  is  lump into 1 row and written
#  in the output file.
# 
#  My expected output is 10 rows. 
#---
info = string.join([fn, mi, ln, deg, dat] 
  
outfile.write(info)
#--
# 
a = 1 + a
else:
a = 1 + a

infile.close()
outfile.close()
# 

Thank you very much for your help.





__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory visualization

2006-03-14 Thread Tim Peters
[EMAIL PROTECTED]
> Icon is a language that share some similarities with Python:
> http://www.cs.arizona.edu/icon/
>
> During the execution of a Icon script there are ways to visualize the
> memory:
> http://www.cs.arizona.edu/icon/progvis/memmon/memmon.htm
>
> Related pages:
> http://www.cs.arizona.edu/icon/progvis/workshop/workshop.htm
> http://www.cs.arizona.edu/icon/progvis/progvis.htm
>
> I'd like to know if for Python there is a similar program to
> dynamically see the memory in a similar way.
> If such tool doesn't exist yet, I'd like to know if it may be diffifult
> to create it.

Long-time Icon developer Clinton Jeffery gave a presentation on this
topic at PyCon 2005:

Profiling and Visualizing Python Program Behavior


It was a delight for me to meet him there, since I was an Icon
programmer before Python existed ;-)  He had some impressive
preliminary CPython visualization results, which required (a) a lot of
work, and (b) some modest changes to the core interpreter.  Alas, I
haven't heard more about it since then.  If I were you, I'd ask Dr.
Jeffery what became of that project.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: recycling internationalized garbage

2006-03-14 Thread Serge Orlov
[EMAIL PROTECTED] wrote:

> Unless someone has any other ideas I'm
> giving up now.

Frederick also suggested http://chardet.feedparser.org/ that is port of
Mozilla's character detection algorithm to pure python. It works pretty
good for web pages, since I haven't seen garbled russian text for years
of using Mozilla/Firefox. You should definitely try it.

  -- Serge

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


Re: elementtree and gbk encoding

2006-03-14 Thread Fredrik Lundh
Diez B. Roggisch wrote:

>   2) your xml is _not_ well-formed, as it doesn't contain a xml-header!
> You need ask these guys to deliver the xml with header. Of course for
> now it is ok to just prepend the text with something like  version="1.0" encoding="gbk"?>. But I'd still request them to deliver it
> with that header - otherwise it is _not_ XML, but just something that
> happens to look similar and doesn't guarantee to be well-formed and thus
> can be safely fed to a parser.

good advice, but note that an envelope (e.g a HTTP request or response
body) may override the encoding in the XML file itself.  if this arrives in a
MIME message with the proper charset information, it's perfectly okay to
leave out the encoding from the file.





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


Re: elementtree and gbk encoding

2006-03-14 Thread Fredrik Lundh
Steven Bethard wrote:

> I'm having trouble using elementtree with an XML file that has some
> gbk-encoded text.  (I can't read Chinese, so I'm taking their word for
> it that it's gbk-encoded.)  I always have trouble with encodings, so I'm
> sure I'm just screwing something simple up.  Can anyone help me?

absolutely!

pyexpat has only limited support for non-standard encodings; the core
expat library only supports UTF-8, UTF-16, US-ASCII, and ISO-8859-1,
and the Python glue layer then adds support for all byte-to-byte en-
codings support by Python on top of that.

if you're using any other encoding, you need to recode the file on the
way in (just decoding to Unicode doesn't work, since the parser expects
an encoded byte stream).  the approach shown on this page should work

http://effbot.org/zone/celementtree-encoding.htm

except that it uses the new XMLParser interface which isn't available in
ET 1.2.6, and the corresponding XMLTreeBuilder interface in ET doesn't
support the encoding override argument...

the easiest way to fix this is to modify the file header on the way in; if
the file has an  header, rip out the header and recode
from that encoding to utf-8 while parsing.





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


Re: Little Help with Exceptions and ConfigParser

2006-03-14 Thread mwt
(Whoops, again.)

def __init__(self, config_file):
self.fahdata = fahdata.FAHData()
self.INI = ConfigParser.ConfigParser()
if os.path.exists(config_file):
try:
self.INI.read(config_file)
except ConfigParser.Error, err:
print "Cannot parse configuration file. %s" %err
except IOError, err:
print "Problem opening configuration file. %s" %err
except Error, err:
print "Problem with with configuration file. %s" %err

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


Re: SSL/TLS - am I doing it right?

2006-03-14 Thread Frank Millman

Michael Ekstrand wrote:
> Disclaimer: I am not an expert. Take this with a grain of salt... but
> I'll throw it out for what it's worth.
>
>
> For what it's worth, the Web does not authenticate clients (for the
> most part anyway). The server is authenticated - its certificate is
> checked against the root CA list. But clients aren't expected to have
> their own certificates. I think that the only time you really need the
> clients to have certificates is when the certificate *is* your
> authentication (e.g., in OpenVPN). Likewise, SSH does not verify client
> certificates (unless you're using PKA, but that's different).
>

Thanks for this, Michael - this is what I feel as well. Unless I hear
to the contrary from Paul or Sybren, this is the approach I will
follow.

My next problem is that TLSLite does not seem to support select().
There is an abstract class called AsyncStateMachine which I think is
provided to simulate this. If I do not figure it out I may come back
here with more questions, but I will start a new thread for that.

Many thanks to all.

Frank

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


Re: Little Help with Exceptions and ConfigParser

2006-03-14 Thread mwt
Would something like this be more useful?

def __init__(self, config_file):
self.fahdata = fahdata.FAHData()
self.INI = ConfigParser.ConfigParser()
if os.path.exists(config_file):
try:
self.INI.read(config_file)
except ConfigParser.Error, err:
print "Cannot parse configuration file. %s" %err
except IOError:
print "Problem opening configuration file. %s" %err
except Error:
print "Problem with with configuration file. %s" %err

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


Re: Newbie Class/Counter question

2006-03-14 Thread Michael Spencer
ProvoWallis wrote:
> 
> My document looks like this
> 
> A. Title Text
> 1. Title Text
> 1. Title Text
> 1. Title Text
> B. Title Text
> 1. Title Text
> 1. Title Text
> 
> but I want to change the numbering of the second level to sequential
> numbers like 1, 2, 3, etc. so my output would look like this
> 
> A. Title Text
> 1. Title Text
> 2. Title Text
> 3. Title Text
> B. Title Text
> 1. Title Text
> 2. Title Text
> 
...

Here's a fixed-up version of your approach:

import re

source_text = """
A. Title Text
1. Title Text
1. Title Text
1. Title Text
B. Title Text
1. Title Text
1. Title Text"""


class ReplacePtSubNumber(object):

 line_pattern = re.compile("""
 (\<\w+\>)   # 
 (\w)# second level
 (\.\s+\w+\s*\w+)# . Title Text
 """, re.VERBOSE)

 def __init__(self):
 self._count = 0

 def sub(self, match):
 level, second, rest = match.groups()
 if second.isalpha():
 self._count = 0
 else:
 self._count +=1
 second = str(self._count)
 return "%s%s%s" % (level, second, rest)

 def replace(self, source):
 return self.line_pattern.sub(self.sub, source)

 >>> r = ReplacePtSubNumber()
 >>> print r.replace(source_text)

A. Title Text
1. Title Text
2. Title Text
3. Title Text
B. Title Text
1. Title Text
2. Title Text

HTH
Michael

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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread Steve
I have found the Python sidebar VERY helpful:
http://projects.edgewall.com/python-sidebar/

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


Re: Newbie Class/Counter question

2006-03-14 Thread Michael Tobis
Paul, thanks for the enlightening intro to pyparsing!

We don't really know what the application is (I suspect it's homework),
but whether it's homework or a real-world one-off this all seems like
overkill to me. There's a time for elegance and a time for quick and
dirty. Assuming line oriented input as shown, I can do it in 9 simple
lines (or 7, if there is no "level3" or higher case) with no imports,
no regular expressions, and no user defined classes. However, I hate to
submit someone's homework.

Anyway, Provo seems confused, and should focus more on technique, I
think. Remember that "simple is better than complex" and "readability
counts". Try to find a way to take smaller steps toward your goal.

mt

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


Re: Printable string for 'self'

2006-03-14 Thread Ben Cartwright
Don Taylor wrote:
> Is there a way to discover the original string form of the instance that
> is represented by self in a method?
>
> For example, if I have:
>
>   fred = C()
>   fred.meth(27)
>
> then I would like meth to be able to print something like:
>
>   about to call meth(fred, 27) or
>   about to call fred.meth(27)
>
> instead of:
>
>   about to call meth(<__main__.C instance at 0x00A9D238>, 27)


Not a direct answer to your question, but this may be what you want:
If you give class C a __repr__ method you can avoid the default  string.

  >>> class C(object):
  def __init__(self, name):
  self.name = name
  def __repr__(self):
  return '%s(%r)' % (self.__class__.__name__, self.name)
  def meth(self, y):
  print 'about to call %r.meth(%r)' % (self, y)

  >>> fred = C('Fred')
  >>> fred.meth(27)
  about to call C('Fred').meth(27)
  >>> def meth2(x, y):
  print 'about to call meth2(%r, %r)' % (x, y)

  >>> meth2(fred, 42)
  about to call meth2(C('Fred'), 42)


Of course, this doesn't tell you the name of the variable that points
to the instance.  For that (here's your direct answer), you will have
to go to the source:

  >>> import inspect
  >>> import linecache
  >>> def f(a, b):
  print 'function call from parent scope:'
  caller = inspect.currentframe().f_back
  filename = caller.f_code.co_filename
  linecache.checkcache(filename)
  line = linecache.getline(filename, caller.f_lineno)
  print '' + line.strip()
  return a*b

  >>> fred = 4
  >>> x = f(3, fred)
  function call from parent scope:
  x = f(3, fred)


But defining __repr__ is far easier and more common.

--Ben

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


Re: Please, I Have A Question before I get started

2006-03-14 Thread Ravi Teja
I did not check prices earlier. There are many other clones. How about
Hyperstudio? $70 for student edition?

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


Re: Printable string for 'self'

2006-03-14 Thread Terry Reedy

"Don Taylor" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Is there a way to discover the original string form of the instance that
> is represented by self in a method?
> For example, if I have:
> fred = C()
> fred.meth(27)
> then I would like meth to be able to print something like:
> about to call meth(fred, 27) or
> about to call fred.meth(27)
> instead of:
> about to call meth(<__main__.C instance at 0x00A9D238>, 27)

That last *is* the default 'original string form of the instance'. 
Consider
>>> [C() for i in [1,2,3]]
[<__main__.C object at 0x00B536F0>, <__main__.C object at 0x00B53D90>, 
<__main__.C object at 0x00B53830>]

If you want your instances to have a name attribute, as with functions, 
classes, and modules, then give them one and supply it to the init method. 
Note that it does not have to be a bindable name, just a string.  IE, 
'a[1]' could be the string identifier.

Terry Jan Reedy



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


Re: Little Help with Exceptions and ConfigParser

2006-03-14 Thread Kent Johnson
mwt wrote:
> Hi -
> I'm having a little trouble using exceptions properly. I currently have
> an initialization function on a little app that looks like this:
> 
> def __init__(self, config_file):
> self.fahdata = fahdata.FAHData()
> self.INI = ConfigParser.ConfigParser()
> if os.path.exists(config_file):
> try:
> self.INI.read(config_file)
> except ConfigParser.ParsingError:
> print "Cannot parse configuration file!"
> 
> This is just a hack I came up with to load the configuration file and
> try to test for serious problems with it. Trouble is, it doesn't really
> do that, and furthermore, if there are small problems with the file
> (such as a NoSectionError) the whole program bombs. Instead, I would
> like to test for the relevant Errors and Exceptions, and have the
> program deal with them gracefully.

All the ConfigParser exceptions are subclasses of ConfigParser.Error so 
if you catch that instead of ConfigParser.ParsingError your code will 
catch NoSectionError as well.

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


Re: Newbie Class/Counter question

2006-03-14 Thread Paul McGuire
"ProvoWallis" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> I've always struggled with classes and this one is no exception.
>
> I'm working in an SGML file and I want to renumber a couple of elements
> in the hierarchy based on the previous level.
>
> E.g.,
>
> My document looks like this
>
> A. Title Text
> 1. Title Text
> 1. Title Text
> 1. Title Text
> B. Title Text
> 1. Title Text
> 1. Title Text
>
> but I want to change the numbering of the second level to sequential
> numbers like 1, 2, 3, etc. so my output would look like this
>
> A. Title Text
> 1. Title Text
> 2. Title Text
> 3. Title Text
> B. Title Text
> 1. Title Text
> 2. Title Text
>
> This is what I've come up with on my own but it doesn't work. I was
> hoping someone could critique this and point me in the right or better
> direction.
>
> Thanks,
>
> Greg
>
> ###
>
>
> def Fix(m):
>
>  new = m.group(1)
>
>  class ReplacePtSubNumber(object):
>
>   def __init__(self):
>self._count = 0
>self._ptsubtwo_re = re.compile(r' no=\"[0-9]\">', re.IGNORECASE| re.UNICODE)
>   # self._ptsubone_re = re.compile(r' re.IGNORECASE| re.UNICODE)
>
>   def sub(self, new):
>return self._ptsubtwo_re.sub(self._ptsubNum, new)
>
>   def _ptsubNum(self, match):
>self._count +=1
>return '' % (self._count)
>
>
>  new = ReplacePtSubNumber().sub(new)
>  return '
> data = re.sub(r'(?i)(?m)(?s)

This may not be as elegant as your RE approach, but it seems more readable
to me.  Using pyparsing, we can define search patterns, attach callbacks to
be invoked when a match is found, and the callbacks can return modified text
to replace the original.  Although the running code matches your text
sample, I've also included commented statements that match your source code
sample.

Download pyparsing at http://pyparsing.sourceforge.net.

-- Paul


testData = """A. Title Text
1. Title Text
1. Title Text
1. Title Text
B. Title Text
1. Title Text
1. Title Text
"""

from pyparsing import *

class Fix(object):
def __init__(self):
self.curItem = 0

def resetCurItem(self,s,l,t):
self.curItem = 0

def nextCurItem(self,s,l,t):
self.curItem += 1
return "%d." % self.curItem
# return '' % self.curItem

def fixText(self,data):
# set up patterns for searching
lev1 = Literal("")
lev2 = Literal("") + Word(nums) + "."
# lev1 = CaselessLiteral("")
# lev2 = CaselessLiteral(''

# when level 1 encountered, reset the cur item counter
lev1.setParseAction(self.resetCurItem)

# when level 2 encountered, use next cur item counter value
lev2.setParseAction(self.nextCurItem)

patterns = (lev1 | lev2)
return patterns.transformString( data )

f = Fix()
print f.fixText( testData )

returns:
A. Title Text
1. Title Text
2. Title Text
3. Title Text
B. Title Text
1. Title Text
2. Title Text


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


Re: Printable string for 'self'

2006-03-14 Thread Don Taylor
Michael Spencer wrote:
>
> 
> In general, this requires exhaustive search of name bindings e.g.,:
> 
>  >>> def get_names_of(obj, ns):
> ... return [name for name, value in ns.iteritems() if value is obj]
> ...
>  >>> class A(object):
> ... def global_names_bound_to_me(self):
> ... return get_names_of(self, globals())
> ...
>  >>> a = A()
>  >>> a.global_names_bound_to_me()
> ['a']
>  >>> b = a
>  >>> a.global_names_bound_to_me()
> ['a', 'b']
>  >>>
> 
Ah, ok.

But, as you show in the example, this technique does not let me figure 
out which of 'a' or 'b' was used to qualify global_names_bound_to_me().

And if I call my method: A().qualify global_names_bound_to_me() then I 
get an empty list back.

Is what I want to do not possible without referring back to the source?

Don.


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


Re: Cheese Shop: some history for the new-comers--Gratuitous self-quote

2006-03-14 Thread Chris Smith
http://it.slashdot.org/article.pl?sid=05/08/01/0150222

Customer: Well, then, have you got any Venezuelan Beaver Cheese?
Owner: Sir, this is a self-respecting establishment. I shall thank you
not to imply we should traffic in VB, much less, even mention the foul
product.

Props,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printable string for 'self'

2006-03-14 Thread Michael Spencer
Don Taylor wrote:
> Is there a way to discover the original string form of the instance that 
> is represented by self in a method?
> 
> For example, if I have:
> 
>   fred = C()
>   fred.meth(27)
> 
> then I would like meth to be able to print something like:
> 
>   about to call meth(fred, 27) or
>   about to call fred.meth(27)
> 
> instead of:
> 
>   about to call meth(<__main__.C instance at 0x00A9D238>, 27)
> 
> Thanks in advance,
> 
> Don.
> 
In general, this requires exhaustive search of name bindings e.g.,:

 >>> def get_names_of(obj, ns):
... return [name for name, value in ns.iteritems() if value is obj]
...
 >>> class A(object):
... def global_names_bound_to_me(self):
... return get_names_of(self, globals())
...
 >>> a = A()
 >>> a.global_names_bound_to_me()
['a']
 >>> b = a
 >>> a.global_names_bound_to_me()
['a', 'b']
 >>>

HTH
Michael

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


Printable string for 'self'

2006-03-14 Thread Don Taylor
Is there a way to discover the original string form of the instance that 
is represented by self in a method?

For example, if I have:

fred = C()
fred.meth(27)

then I would like meth to be able to print something like:

about to call meth(fred, 27) or
about to call fred.meth(27)

instead of:

about to call meth(<__main__.C instance at 0x00A9D238>, 27)

Thanks in advance,

Don.

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


Re: Trace dynamically compiled code?

2006-03-14 Thread Ed Leafe
On Mar 14, 2006, at 12:45 PM, Ziga Seilnacht wrote:

> Try not using bare exec statements, since they pollute the local  
> scope.
> In your example you could use:
>
> compCode = compile(code, "", "exec")
> d = {}
> exec compCode in d
> func = d[nm]

OK, noted and changed in my source.

>> exec "self.%s = %s.__get__(self)" % (nm, nm)
>
> You don't need dynamic execution here; you can simply use
> setattr and the new module:
>
> import new
> method = new.instancemethod(func, self)
> setattr(self, nm, method)
>
> and yes, I remember that I was the one who suggested you
> the __get__ hack.

I've made the change you suggested. May I ask why one is better than  
the other? Namespace pollution doesn't seem to be an issue here.

>>  Does anyone know a way to compile the dynamic code so that pdb can
>> 'see' the source? I suppose I could write it all out to a bunch of
>> temp files, but that would be terribly messy. Are there any neater
>> solutions?
>
> You should check py lib: http://codespeak.net/py/current/doc/ ,
> specifically the py.code "module". Then you can modify the
> function from above:
>
> import inspect
> f = inspect.currentframe()
> lineno = f.f_lineno - 5 # or some other constant
> filename = f.f_code.co_filename
>
> import py
> co = py.code.Code(func)
> new_code = co.new(co_lineno=lineno, co_filename=filename)
> new_func = new.function(new_code, func.func_globals, nm,
> func.func_defaults, func.func_closure)

OK, thanks for the lead. I will take a look at this as soon as I  
have the time to sit down and attempt to digest it. But before I do,  
will I be able to add code like this to the same part of the  
framework where the dynamic code is created, and have it work? I ask  
this because an even bigger problem is the matter of creating dynamic  
classes on the fly from saved XML files. I have a class that converts  
the XML to the corresponding Python code for the class, and it's  
working great, except for the tracing through the debugger issue.  
Would I be able to apply the py lib stuff to this, too?

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com



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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread Paul Boddie
[EMAIL PROTECTED] wrote:

[Quoting Aaron Watters - *the* Aaron Watters?!]

> > And the patch procedure you described requires
> > a higher degree of motivation (and free time) than
> > most potential contributors might have on offer, imo.

The patch procedure described seemed to involve mailing python-dev,
which I thought was not the accepted practice. Even making patch
descriptions in SourceForge won't apparently get patches straight into
Python, although there may be fewer restrictions on submitting
documentation patches.

> Another option is to simply email the author/maintainer
> for a given module your modifications to their module.
>
> cd ~/dev/python/modified_modules
> cp /path/to/module_needs_docs.py .
> vim ./module_needs_docs.py   # add docs

True, but I'm not convinced this is going to work when the modules are
in the standard library. Anyway, there were going to be some
improvements to the processes, last time I looked, and various editable
resources did spring up to meet the need for documentation edits - none
of them official as far as I know, though.

Paul

P.S. On the documentation-from-sources question, I've had some success
with epydoc. Some documentation systems (even those for
statically-typed languages) have you describe parameters in
mind-numbing detail, but all I would expect from a documentation tool
is that it highlight mentions of the parameter names in my docstrings.
Having some understanding of the nasty issues around deducing types, I
wouldn't expect a tool to fill in the gaps about parameter types: good
documentation for dynamic languages like Python should be able to
describe what kind of objects should be passed in, and type deduction
could actually give quite the wrong impression about acceptable
arguments to functions, although interface descriptions could be
helpful.

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


Re: markov query

2006-03-14 Thread Robert Kern
kpp9c wrote:
>>Yes, a system which does this has to build a Markov
>>chain from a data set and then traverse it.
> 
>>>Any program that actually uses Markov chains to generate
>>>new text based on existing input as you've described
> 
> Hi. That isn't really what i have described. If i did i could use
> exsisting algorithms. What you describe is exactly what i don't want in
> this particular case. I am actually not wanting it to build a chain
> from some input that it analyzes. There is no input. If you see, i am
> trying to define a table that tells it how to proceed forward from
> scratch as a stochastic process.

Any such program has two main parts, one that trains the transition matrix from
a data set, and one that generates output from that transition matrix. You
should be able to take such a program and only use the latter component with
your transition matrix, however you choose to create it. Googling for 'python
markov' generates several leads.

-- 
Robert Kern
[EMAIL PROTECTED]

"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: Little Help with Exceptions and ConfigParser

2006-03-14 Thread mwt
Whoops. Those page numbers are from "Cookbook."
As well as the Except section in "Nutshell."
Still stewing away here. ;)

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


Newbie Class/Counter question

2006-03-14 Thread ProvoWallis
Hi,

I've always struggled with classes and this one is no exception.

I'm working in an SGML file and I want to renumber a couple of elements
in the hierarchy based on the previous level.

E.g.,

My document looks like this

A. Title Text
1. Title Text
1. Title Text
1. Title Text
B. Title Text
1. Title Text
1. Title Text

but I want to change the numbering of the second level to sequential
numbers like 1, 2, 3, etc. so my output would look like this

A. Title Text
1. Title Text
2. Title Text
3. Title Text
B. Title Text
1. Title Text
2. Title Text

This is what I've come up with on my own but it doesn't work. I was
hoping someone could critique this and point me in the right or better
direction.

Thanks,

Greg

###


def Fix(m):

 new = m.group(1)

 class ReplacePtSubNumber(object):

  def __init__(self):
   self._count = 0
   self._ptsubtwo_re = re.compile(r'', re.IGNORECASE| re.UNICODE)
  # self._ptsubone_re = re.compile(r'' % (self._count)


 new = ReplacePtSubNumber().sub(new)
 return 'http://mail.python.org/mailman/listinfo/python-list


Re: markov query

2006-03-14 Thread kpp9c
>Yes, a system which does this has to build a Markov
>chain from a data set and then traverse it.

>>Any program that actually uses Markov chains to generate
>> new text based on existing input as you've described

Hi. That isn't really what i have described. If i did i could use
exsisting algorithms. What you describe is exactly what i don't want in
this particular case. I am actually not wanting it to build a chain
from some input that it analyzes. There is no input. If you see, i am
trying to define a table that tells it how to proceed forward from
scratch as a stochastic process.

cheers,

-kp--

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


Re: elementtree and gbk encoding

2006-03-14 Thread Steven Bethard
Diez B. Roggisch wrote:
>> Here's what I get with the prepending hack:
>>
>>  >>> et.fromstring('\n' + 
>> open(filename).read())
>> Traceback (most recent call last):
>>   File "", line 1, in ?
>>   File "C:\Program 
>> Files\Python\lib\site-packages\elementtree\ElementTree.py", line 960, 
>> in XML
>> parser.feed(text)
>>   File "C:\Program 
>> Files\Python\lib\site-packages\elementtree\ElementTree.py", line 1242, 
>> in feed
>> self._parser.Parse(data, 0)
>> ExpatError: unknown encoding: line 1, column 30
>>
>>
>> Are the XML encoding names different from the Python ones?  The "gbk" 
>> encoding seems to work okay from Python:
> 
> I had similar trouble with cElementTree and cp1252 encodings. But 
> upgrading to a more recent version helped. Did you try parsing with e.g. 
>  sax?

Hmm...  The builtin xml.dom.minidom and xml.sax both also fail to find 
the encoding:


 >>> import xml.dom.minidom as dom
 >>> dom.parseString('' + 
open(filename).read())
Traceback (most recent call last):
   File "", line 1, in ?
   File "C:\Program 
Files\Python\lib\site-packages\_xmlplus\dom\minidom.py", line 1925, in 
parseString
 return expatbuilder.parseString(string)
   File "C:\Program 
Files\Python\lib\site-packages\_xmlplus\dom\expatbuilder.py", line 942, 
in parseString
 return builder.parseString(string)
   File "C:\Program 
Files\Python\lib\site-packages\_xmlplus\dom\expatbuilder.py", line 223, 
in parseString
 parser.Parse(string, True)
ExpatError: unknown encoding: line 1, column 30


 >>> import xml.sax as sax
 >>> sax.parseString('' + 
open(filename).read(), sax.handler.ContentHandler())
Traceback (most recent call last):
   File "", line 1, in ?
   File "C:\Program 
Files\Python\lib\site-packages\_xmlplus\sax\__init__.py", line 47, in 
parseString
 parser.parse(inpsrc)
   File "C:\Program 
Files\Python\lib\site-packages\_xmlplus\sax\expatreader.py", line 109, 
in parse
 xmlreader.IncrementalParser.parse(self, source)
   File "C:\Program 
Files\Python\lib\site-packages\_xmlplus\sax\xmlreader.py", line 123, in 
parse
 self.feed(buffer)
   File "C:\Program 
Files\Python\lib\site-packages\_xmlplus\sax\expatreader.py", line 220, 
in feed
 self._err_handler.fatalError(exc)
   File "C:\Program 
Files\Python\lib\site-packages\_xmlplus\sax\handler.py", line 38, in 
fatalError
 raise exception
SAXParseException: :1:30: unknown encoding
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: markov query

2006-03-14 Thread kpp9c
> Yes, a system which does this has to build a Markov chain from a data
> set and then traverse it.

>Any program that actually uses Markov chains to generate new text based
>on existing input as you've described will necessarily create a Markov
>chain.

I think you misunderstood. If you see my original post my whole point
was that this was exactly what i don't want. There are several
algorithms out that that already do that. I want to use a table that i
define from scratch to shape a stochastic process. In this case there
is no original input to analyze and i don't want a chain built by
analysis and i am not using necessarily texts.

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


Re: Python Debugger / IDE ??

2006-03-14 Thread Felipe Almeida Lessa
Em Ter, 2006-03-14 às 09:44 -0800, [EMAIL PROTECTED] escreveu:
> >Is there any editor or IDE in Python (either Windows or Linux) which
> >has very good debugging facilites like MS VisualStudio has or something
> >like that.
> 
> I've been using Eclipse with PyDev and am very happy with it.

I second that. It's the best Python IDE I've ever used. But you won't
get too far with less than 512 MiB of RAM...

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

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

Re: andmap and ormap

2006-03-14 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:
> The following works perfectly:
> import operator
> def andmap(b,L):
> return reduce(operator.and_, [b(x) for x in L])
> def ormap(b,L):
> return reduce(operator.or_, [b(x) for x in L]) 

Note your [b(x) for x in L] evaluates b(x) for all elements of L
before you begin the analysis.
In 2.3 and beyond, you could define:

 def imap(function, source):
 for element in source:
 yield function(element)

And apply any or all (as defined below) to imap(b, L)

Although, you often needn't use bool(expr) in Python, more things are
reasonable to use directly as tests; if implicitly converts to bool.
So, for those cases, you could simply use any(L) or all(L).

If you wish to use any and all (coming in 2.5), you could go with:

def any(iterable):
 '''True iff at least one element of the iterable is True'''
 for element in iterable:
if element:
return True # or element and change the definition
 return False

def all(iterable):
 '''True iff no element of the iterable is True'''
 for element in iterable:
if not element:
return False
 return True

These will short-circuit in 2.3 and up (where iterators live).
In 2.4 and up, generator expressions can be used:

 any(x*7-4 > 100 for x in xrange(50))

Even in 2.3, any and all as defined above work with generators:

 def generates(limit):
 for i in xrange(limit):
 yield i * 7 - 4 > 100

 any(generates(8))
True
 any(generates(8))
False

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


Re: Python Debugger / IDE ??

2006-03-14 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> Is there any editor or IDE in Python (either Windows or Linux) which
> has very good debugging facilites like MS VisualStudio has or something
> like that.
> 
> I like SPE but couldn't easily use winPDP. I need tips to debug my code
> easily.
> 
> Every help is greatly appreciated.
> 
> Thanks
> 
I've found that using logging works well for me.  I put statements in
my program that log information, trace, intermediate results, ..., and
wrap them in trace/debug if statements.  Higher values of debug get more
"stuff" logged.  Then I leave everything in the program.  When something
goes wrong, run it with debug level and I can figure out what is
happening.  This is especially good when problem pops up 2 years from
now.  I just have client run with debug=4 and I look at the logfile.  If
you get in a habit of writing ALL your software this way, you find that
it is quite powerful and easy.  I haven't found the overhead of all the
if statements to be anything to worry about.  You can use the standard
library logging module (I wrote my own before it was available and I've
never changed to the one in the standard library).

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


Threads: does Thread.start() atomically set Thread.__started ?

2006-03-14 Thread Enigma Curry
Can some kind person please further my education on Threads?

When I create a thread called "t" and I do a "t.start()" am I
guaranteed that "t.isAlive()" will return True as long as the thread
hasn't already completed? Put another way, does "t.start()" ever return
before t.__started is set to True?

consider this example:

import time
import threading
class MyThread(threading.Thread):
def __init__(self):
self.completed = False
threading.Thread.__init__(self)
def run(self):
#do something
time.sleep(1)
self.completed = True

t = MyThread()
while t.isAlive() == False and t.completed == False:
t.start()

In the above code, am I guaranteed that t will only be (attempted to
be) started once?


Thanks,
Ryan

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


Re: elementtree and gbk encoding

2006-03-14 Thread Diez B. Roggisch
> Here's what I get with the prepending hack:
> 
>  >>> et.fromstring('\n' + 
> open(filename).read())
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "C:\Program 
> Files\Python\lib\site-packages\elementtree\ElementTree.py", line 960, in 
> XML
> parser.feed(text)
>   File "C:\Program 
> Files\Python\lib\site-packages\elementtree\ElementTree.py", line 1242, 
> in feed
> self._parser.Parse(data, 0)
> ExpatError: unknown encoding: line 1, column 30
> 
> 
> Are the XML encoding names different from the Python ones?  The "gbk" 
> encoding seems to work okay from Python:

I had similar trouble with cElementTree and cp1252 encodings. But 
upgrading to a more recent version helped. Did you try parsing with e.g. 
  sax?

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


Re: Cheese Shop: some history for the new-comers

2006-03-14 Thread Tim Parkin
Fredrik Lundh wrote:

>A.M. Kuchling wrote:
>
>  
>
>>I've changed the PSF link, but am not sure what to do about the
>>python-dev link.  As others have noted, "Developers" is ambiguous
>>about whether it's for people who develop in Python or who develop
>>Python itself."Core Development"?  (Used on both perl.org and tcl.tk, so
>>maybe this is the best option.)
>>
>
>"core development" is fine with me.
>
>
>
>
>  
>
forgot the link..

http://psf.pollenation.net/cgi-bin/trac.cgi/attachment/ticket/47/python-amends-2.png

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


Re: Cheese Shop: some history for the new-comers

2006-03-14 Thread Tim Parkin
Fredrik Lundh wrote:

>A.M. Kuchling wrote:
>
>  
>
>>I've changed the PSF link, but am not sure what to do about the
>>python-dev link.  As others have noted, "Developers" is ambiguous
>>about whether it's for people who develop in Python or who develop
>>Python itself."Core Development"?  (Used on both perl.org and tcl.tk, so
>>maybe this is the best option.)
>>
>>
>
>"core development" is fine with me.
>
>
>
>  
>

I've tried this out on a test page and I think it works well.. I've also
removed a couple of bits from the left hand nav and moved the style
sheet switcher elsewhere (it probably should be in the help section). I
think the left hand nav is a lot clearer if kept simple.

Tim Parkin

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


Re: Is this possible in Python? SOLUTION FOUND

2006-03-14 Thread Steven D'Aprano
On Tue, 14 Mar 2006 13:33:01 -0800, alainpoint wrote:

> 
> Kay Schluehr wrote:
>> [EMAIL PROTECTED] wrote:
>> > jalanb wrote:
>> > > You might like the version here:
>> > > http://www.jorendorff.com/toys/out.html
>> > >
>> > > Especially the "need to know" presentation, which is cute
>> > >
>> > > --
>> > > Alan
>> > > http://aivipi.blogspot.com
>> >
>> > Thank you for the tip.
>> > Meanwhile, I found a shorter solution to my problem:
>> > def magic(arg):
>> >import inspect
>> >return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
>> >
>> > assert magic(3+4)=="3+4"
>> >
>> > Alain
>>
>> Does it? Using your function I keep an assertion error. Storing the
>> return value of magic()in a variable s I receive the following result:
>>
>> def magic(arg):
>> import inspect
>> return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
>>
>> s = magic(3+4) # magic line
>>
>> >>> s
>> 'lin'
>>
>>
>> BTW grepping the stack will likely cause context sensitive results.
>>
>> Kay
> 
> 
> This is no production-ready code, just a proof of concept.
> Adding 3 or 4 lines would make it more robust.
> Just hope someone else will benefit from this discussion.

Doesn't work for me either:

>>> def magic(arg):
... import inspect
... return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
...
>>> magic(3+4)
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 3, in magic
TypeError: unsubscriptable object


Kay gets an AssertionError, I get a TypeError. I think describing it as
"proof of concept" is rather optimistic.

Here is the inspect.stack() I get:

[(, '', 2, 'magic', None, None),
(, '', 1, '?', None, None)]


-- 
Steven.

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


Re: elementtree and gbk encoding

2006-03-14 Thread Steven Bethard
Diez B. Roggisch wrote:
> Steven Bethard schrieb:
>> I'm having trouble using elementtree with an XML file that has some 
>> gbk-encoded text.  (I can't read Chinese, so I'm taking their word for 
>> it that it's gbk-encoded.)  I always have trouble with encodings, so 
>> I'm sure I'm just screwing something simple up.  Can anyone help me?
>>
>> Here's the interactive session.  Sorry it's a little verbose, but I 
>> figured it would be better to include too much than not enough.  I 
>> basically expected et.ElementTree(file=...) to fail since no encoding 
>> was specified, but I don't know what I'm doing wrong when I use 
>> codecs.open(...)
> 
> The first and most important lesson to learn here is that well-formed 
> XML must contain a xml-header that specifies the used encoding. This has 
> two consequences for you:
> 
>  1) all xml-parsers expect byte-strings, as they have to first read the 
> header to know what encoding awaits them. So no use reading the xml-file 
> with a codec - even if it is the right one. It will get converted back 
> to a string when fed to the parser, with the default codec being used - 
> resulting in  the well-known unicode error.
> 
>  2) your xml is _not_ well-formed, as it doesn't contain a xml-header! 
> You need ask these guys to deliver the xml with header. Of course for 
> now it is ok to just prepend the text with something like  version="1.0" encoding="gbk"?>. But I'd still request them to deliver it 
> with that header - otherwise it is _not_ XML, but just something that 
> happens to look similar and doesn't guarantee to be well-formed and thus 
> can be safely fed to a parser.

Thanks, that's very helpful.  I'll definitely harrass the people 
producing these files to make sure they put encoding declarations in them.

Here's what I get with the prepending hack:

 >>> et.fromstring('\n' + 
open(filename).read())
Traceback (most recent call last):
   File "", line 1, in ?
   File "C:\Program 
Files\Python\lib\site-packages\elementtree\ElementTree.py", line 960, in XML
 parser.feed(text)
   File "C:\Program 
Files\Python\lib\site-packages\elementtree\ElementTree.py", line 1242, 
in feed
 self._parser.Parse(data, 0)
ExpatError: unknown encoding: line 1, column 30


Are the XML encoding names different from the Python ones?  The "gbk" 
encoding seems to work okay from Python:

 >>> open(filename).read().decode('gbk')
u'\nART242\n\n 
\n\n\n\n\n( (IP-HLN 
(LCP-TMP (IP (NP-PN-SBJ (NR \u4f0f\u660e\u971e)) \n\t\t   (VP (VV 
\u83b7\u5f97) \n\t\t\t   (NP-OBJ (NN \u5973\u5b50) \n\t\t\t\t   (NN 
\u8df3\u53f0) \n\t\t\t\t   (NN \u8df3\u6c34) \n\t\t\t\t   (NN 
\u51a0\u519b \n\t\t   (LC \u540e)) \n  (PU \uff0c) \n 
(NP-SBJ (NP-PN (NR \u82cf\u8054\u961f)) \n  (NP (NN 
\u6559\u7ec3))) \n  (VP (ADVP (AD \u70ed\u60c5)) \n 
  (PP-DIR (P \u5411) \n\t\t  (NP (PN \u5979))) \n  (VP 
(VV \u795d\u8d3a))) \n  (PU \u3002)) ) \n\n\n( 
(FRAG  (NR \u65b0\u534e\u793e) \n (NN \u8bb0\u8005) \n 
(NR \u7a0b\u81f3\u5584) \n (VV \u6444) )) 
\n\n\n\n\n\n\n'


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


Re: elementtree and gbk encoding

2006-03-14 Thread Diez B. Roggisch
Steven Bethard schrieb:
> I'm having trouble using elementtree with an XML file that has some 
> gbk-encoded text.  (I can't read Chinese, so I'm taking their word for 
> it that it's gbk-encoded.)  I always have trouble with encodings, so I'm 
> sure I'm just screwing something simple up.  Can anyone help me?
> 
> Here's the interactive session.  Sorry it's a little verbose, but I 
> figured it would be better to include too much than not enough.  I 
> basically expected et.ElementTree(file=...) to fail since no encoding 
> was specified, but I don't know what I'm doing wrong when I use 
> codecs.open(...)

The first and most important lesson to learn here is that well-formed 
XML must contain a xml-header that specifies the used encoding. This has 
two consequences for you:

  1) all xml-parsers expect byte-strings, as they have to first read the 
header to know what encoding awaits them. So no use reading the xml-file 
with a codec - even if it is the right one. It will get converted back 
to a string when fed to the parser, with the default codec being used - 
resulting in  the well-known unicode error.

  2) your xml is _not_ well-formed, as it doesn't contain a xml-header! 
You need ask these guys to deliver the xml with header. Of course for 
now it is ok to just prepend the text with something like . But I'd still request them to deliver it 
with that header - otherwise it is _not_ XML, but just something that 
happens to look similar and doesn't guarantee to be well-formed and thus 
can be safely fed to a parser.


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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread john_sips_tea
> And the patch procedure you described requires
> a higher degree of motivation (and free time) than
> most potential contributors might have on offer, imo.

Another option is to simply email the author/maintainer
for a given module your modifications to their module.

cd ~/dev/python/modified_modules
cp /path/to/module_needs_docs.py .
vim ./module_needs_docs.py   # add docs

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


Re: PEP 8 example of 'Function and method arguments'

2006-03-14 Thread Martin P. Hellwig

Steven, Bruno, Terry & Duncon, thank you for your insights, it really 
helped me a great deal.

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


Re: recycling internationalized garbage

2006-03-14 Thread Martin v. Löwis
Ross Ridge wrote:
> [EMAIL PROTECTED] wrote:
> 
>>try:
>>(uni, dummy) = utf8dec(s)
>>except:
>>(uni, dummy) = iso88591dec(s, 'ignore')
> 
> 
> Is there really any point in even trying to decode with UTF-8?  You
> might as well just assume ISO 8859-1.

The point is that you can tell UTF-8 reliably. If the data decodes
as UTF-8, it *is* UTF-8, because no other encoding in the world
produces the same byte sequences (except for ASCII, which is
an UTF-8 subset).

So if it is not UTF-8, the guessing starts.

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


Re: Is this possible in Python? SOLUTION FOUND

2006-03-14 Thread alainpoint

Kay Schluehr wrote:
> [EMAIL PROTECTED] wrote:
> > jalanb wrote:
> > > You might like the version here:
> > > http://www.jorendorff.com/toys/out.html
> > >
> > > Especially the "need to know" presentation, which is cute
> > >
> > > --
> > > Alan
> > > http://aivipi.blogspot.com
> >
> > Thank you for the tip.
> > Meanwhile, I found a shorter solution to my problem:
> > def magic(arg):
> > import inspect
> > return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
> >
> > assert magic(3+4)=="3+4"
> >
> > Alain
>
> Does it? Using your function I keep an assertion error. Storing the
> return value of magic()in a variable s I receive the following result:
>
> def magic(arg):
> import inspect
> return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
>
> s = magic(3+4) # magic line
>
> >>> s
> 'lin'
>
>
> BTW grepping the stack will likely cause context sensitive results.
>
> Kay


This is no production-ready code, just a proof of concept.
Adding 3 or 4 lines would make it more robust.
Just hope someone else will benefit from this discussion.

Alain

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


elementtree and gbk encoding

2006-03-14 Thread Steven Bethard
I'm having trouble using elementtree with an XML file that has some 
gbk-encoded text.  (I can't read Chinese, so I'm taking their word for 
it that it's gbk-encoded.)  I always have trouble with encodings, so I'm 
sure I'm just screwing something simple up.  Can anyone help me?

Here's the interactive session.  Sorry it's a little verbose, but I 
figured it would be better to include too much than not enough.  I 
basically expected et.ElementTree(file=...) to fail since no encoding 
was specified, but I don't know what I'm doing wrong when I use 
codecs.open(...)

Thanks in advance for the help!

 >>> import elementtree.ElementTree as et
 >>> import codecs
 >>> et.ElementTree(file=filename)
Traceback (most recent call last):
   File "", line 1, in ?
   File "C:\Program 
Files\Python\lib\site-packages\elementtree\ElementTree.py", line 543, in 
__init__
 self.parse(file)
   File "C:\Program 
Files\Python\lib\site-packages\elementtree\ElementTree.py", line 583, in 
parse
 parser.feed(data)
   File "C:\Program 
Files\Python\lib\site-packages\elementtree\ElementTree.py", line 1242, 
in feed
 self._parser.Parse(data, 0)
ExpatError: not well-formed (invalid token): line 8, column 6
 >>> et.ElementTree(file=codecs.open(filename, 'r', 'gbk'))
Traceback (most recent call last):
   File "", line 1, in ?
   File "C:\Program 
Files\Python\lib\site-packages\elementtree\ElementTree.py", line 543, in 
__init__
 self.parse(file)
   File "C:\Program 
Files\Python\lib\site-packages\elementtree\ElementTree.py", line 583, in 
parse
 parser.feed(data)
   File "C:\Program 
Files\Python\lib\site-packages\elementtree\ElementTree.py", line 1242, 
in feed
 self._parser.Parse(data, 0)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 
133-135: ordinal not in range(128)
 >>> text = open(filename).read()
 >>> text
'\nART242\n\n 
\n\n\n\n\n( (IP-HLN 
(LCP-TMP (IP (NP-PN-SBJ (NR \xb7\xfc\xc3\xf7\xcf\xbc)) \n\t\t   (VP 
(VV \xbb\xf1\xb5\xc3) \n\t\t\t   (NP-OBJ (NN \xc5\xae\xd7\xd3) 
\n\t\t\t\t   (NN \xcc\xf8\xcc\xa8) \n\t\t\t\t   (NN \xcc\xf8\xcb\xae) 
\n\t\t\t\t   (NN \xb9\xda\xbe\xfc \n\t\t   (LC \xba\xf3)) \n 
   (PU \xa3\xac) \n  (NP-SBJ (NP-PN (NR 
\xcb\xd5\xc1\xaa\xb6\xd3)) \n  (NP (NN 
\xbd\xcc\xc1\xb7))) \n  (VP (ADVP (AD \xc8\xc8\xc7\xe9)) \n 
  (PP-DIR (P \xcf\xf2) \n\t\t  (NP (PN \xcb\xfd))) \n 
(VP (VV \xd7\xa3\xba\xd8))) \n  (PU \xa1\xa3)) ) 
\n\n\n( (FRAG  (NR \xd0\xc2\xbb\xaa\xc9\xe7) \n 
(NN \xbc\xc7\xd5\xdf) \n (NR \xb3\xcc\xd6\xc1\xc9\xc6) \n 
   (VV \xc9\xe3) )) \n\n\n\n\n\n\n'


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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread aaronwmail-usenet
hmmm.  Interesting about the wiki.
It's unusable in my version of IE.  Javascript error
on almost every keystroke :(!

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

It works in Firefox, which I have, of course, but
still...

And the patch procedure you described requires
a higher degree of motivation (and free time) than
most potential contributors might have on offer, imo.

   -- Aaron Watters

===
"I weep for you," the walrus said, I deeply sympathize.
With sobs and tears he sorted out those of the largest size.
Holding his pocket handkercheif before his streaming eyes.
   from "The Walrus and the Carpenter", Lewis Carroll

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


Re: Cheese Shop: some history for the new-comers

2006-03-14 Thread Fredrik Lundh
A.M. Kuchling wrote:

> I've changed the PSF link, but am not sure what to do about the
> python-dev link.  As others have noted, "Developers" is ambiguous
> about whether it's for people who develop in Python or who develop
> Python itself."Core Development"?  (Used on both perl.org and tcl.tk, so
> maybe this is the best option.)

back in the old days, python.org used "core developers" ;-)

"core development" is fine with me.





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


Re: Very, Very Green Python User

2006-03-14 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
> I have used Perl for a long time, but I am something of an experimental
> person and mean to try something new. Most of my 'work' with Vector
> Linux entails the use of Perl (a bit of a misnomer as it is not now a
> paid position -- I am not yet even out of K-12), and there a lot of
> things I love about it. I can look past a number of misfeatures in
> Perl, but I am surprised to see that Python has very few (that I know
> of). Most of them are documented here, it would seem:
> http://www.c2.com/cgi/wiki?PythonProblems.

Seems that this page is sometimes just plain wrong and somewhat
outdated. Let's see some of them:

1/Memory Management The reference implementation uses reference
counting, the worst-performing memory management scheme there is

Actually, Python uses *both* reference-counting and a garbage collector.

2/ No Ternary If
Well... actually true, but not such a major annoyance.
NB : the "tuple_dispatch" option works well if you know how-to python.
IOW, you can avoid useless evaluation with a simple lambda :

result = (lambda: action_if_true, lambda : action_if_false)[test]()

3/ Dynamic Typing
Err... Actually, this is not a problem, Sir, it's a feature.

4/ Speed
Never been a problem for me so far.

5/ Ugly mechanism for privates
This is *not* a mechanism for "privates". This is a mechanism to protect
some crucial implementation attributes from being *accidentally*
overriden in a child class.

6/ SelfDotSyndrome
As for 3, this is definitively a feature. I've always used the implicit
'this' in Java and C++ anyway.


> Is the Python debugger
> fairly stable? 

can't tell, almost never had a use for it.

> More than
> anything else, I would like to have a powerful OO environment where I
> do not have to worry about the debugger sucking ass.

What makes you think you have such a need for a debugger ?

> A couple blemishes I'm concerned about, though:
> 
> Python closures are apparently very poor,

In Python, encapsuling state is better done with objects. Once you'll
get a better understanding of Python's object model, you'll find out
that there's not such a need for more powerfull closures (well, that's
MHO at least). Amongst other things, functions and methods are objects,
and any other class can be made callable if you implement a method for
the call operator...

> but from what I can surmise
> of the PyGTK2 page, instances of objects are dynamic enough to add new
> methods, so you get your callbacks, at least.

You don't even need this to use callbacks. Remember, functions and
methods are objects, and other objects can be callable too...

> Double-underscore methods are rewritten with the class name? That's an
> ugly hack,

Ever looked at what a C++ compiler do to symbols ?-)

> but remember I'm coming from Perl. 

Talking about ugky hacks... !-)


-- 
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 IDE: great headache....

2006-03-14 Thread Michael Amrhein
Sullivan WxPyQtKinter schrieb:
> IDLE is no longer satisfactory for me. Other IDEs make me very
> confused. Really do not know which one to use.
> 
> I use WinXP sp2 for current development.
> 
> So far as I know, Eclipse + PyDev + PyDev Extension is perfect for
> source code editing. Since I am really not sure how to use the debugger
> module, I really do not know how to add watch to variables etc. Anyone
> knows if this platform is a good one?
> 
> I hope that an IDE should be featured with:
> 1. Grammar Colored highlights.
> 2. Manage project in a tree view or something alike, ie, a project file
> navigator.
> 3. Code collapse and folding.
> 4. Code auto-completion: especially prompting function parameters when
> I am typing a function previously defined by myself. Like the one in
> Visual Studio series.
> 5. Debugging: Breakpoints, conditional pause. watch for variables.step
> into, over and out of a function.
> What about other IDEs? Since I do not need GUI development. More over,
> the free-of-charge IDE is highly preferred.
> 6.Indentation management like in IDLE: press ctrl+[/] to modify the
> identation of a line or a block.
> 
> In addition, I have seen quite a few editors, which are definitely not
> what I want. 
> 
> Thank you so much for suggestions.
> 
Give Komodo (http://www.activestate.com/Products/Komodo/?mp=1) a try.
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cheese Shop: some history for the new-comers

2006-03-14 Thread Steven Bethard
A.M. Kuchling wrote:
> On Sun, 12 Mar 2006 10:25:19 +0100, 
>   Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>> and while you're at it, change "python-dev" to "developers" and
>> "psf" to "foundation" (or use a title on that link).
> 
> I've changed the PSF link, but am not sure what to do about the
> python-dev link.  As others have noted, "Developers" is ambiguous
> about whether it's for people who develop in Python or who develop
> Python itself."Core Development"?  (Used on both perl.org and tcl.tk, so
> maybe this is the best option.) "Development Team"?  

+1 on Core Development.  It's still ambiguous, but less so.  And I can't 
think of anything better. ;)

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


Re: Python Debugger / IDE ??

2006-03-14 Thread krypto . wizard
My code has got big and it is an iterative program. I use print
statements but I thought I could get something handy it would be useful
to me.

thanks

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


Re: Python Debugger / IDE ??

2006-03-14 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
> Is there any editor or IDE in Python (either Windows or Linux) which
> has very good debugging facilites like MS VisualStudio has or something
> like that.
> 
> I like SPE but couldn't easily use winPDP. I need tips to debug my code
> easily.

pythonic "debugging" in three steps:

1/ unit tests
2/ a bunch of print statements
3/ the interactive python shell

All this relying on well-decoupled, modular code.

FWIW, I've almost never used a debugger with Python.

HTH
-- 
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: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread john_sips_tea
Well, we've already got a wiki, of course: http://wiki.python.org/moin/

Regarding the docs for the module you're asking about, the way it's
supposed to work is (I think), you're supposed to checkout the Python
source, add your docs to the docstrings of that module, then either
commit your changes back in (if you have access privileges) or else
send a patch to the right list (python-dev?) so your patch can be
integrated.

It seems to me that it's best to write your docstring as epytext. That
way, for now, it just looks like regular plain text (though neatly
formatted) when viewed with the pydoc tool...

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


Re: andmap and ormap

2006-03-14 Thread Terry Reedy

"Joel Hedlund" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> footnote: if you have a recent Python 2.5 build,
>
> Who would have that? Is it a good idea to use a pre-alpha python version?

The pre-public release version compiles as 'alpha0'.  I have the impression 
the current alpha0 is being kept closer to releaseable more of the time 
than used to be the case.  For instance, the developers recently set up a 
buildbot system to compile and run all unit tests on several systems with a 
variety of hardware and OSes up to several times a day.  The results are 
available at
http://www.python.org/dev/buildbot/

At of minutes ago, 5 systems are green (ok), 1 orange (warn) , and 1 red 
(fail).

> ... Or should I start grabbing the Subversion trunk on a nightly basis?

'Should' if you want to experiment with new features or test existing code 
now rather than later.  I would only grab it when the tests pass on the 
system closest to yours, and only repeat when there is a reason to.

Terry Jan Reedy



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


Re: calling another python file within python

2006-03-14 Thread Ben C
On 2006-03-14, Kevin <[EMAIL PROTECTED]> wrote:
> i have a python file called pyq which outputs stock quotes, currently i 
> also have a html file that takes stock ticker inputs, i would like to 
> bridge the two by building another program that takes the html inputs 
> and uses them to call the pyq stock ticker program and then output them 
> into a text file...
>
> any idea how to do this? my tentative code is:
>
>
>
> #!/usr/bin/python
>
> import os
> import urllib
> os.system("python pyq.py ibm > text1.txt")

Rather than invoke the shell (which is what system does), you can just
do it all from Python. Something like:

import pyq
pyq.run("ibm")

Then in pyq.py, you could have something like this:

def run(filename):
# do whatever...

def main():
# check args etc..
run(sys.argv[1])

if __name__ == "__main__":
main()

This way pyq would work from the shell if you wanted to run it that way,
and also as a module.

Not quite sure of the details of the input. If the other program is
creating this file ibm which you're immediately reading as soon as it
appears you'd probably be better off with a pipe.

See Python docs for the "socket" module. Or less portably and if you're
on a UNIX system you could use a named pipe (created with mkfifo).

> note: currently the text1.txt outputted is just blank, however if i
> run the command normally as 'python pyq.py ibm' in the command line,
> it works correctly and gives me the price of ibm.

If you launch pyq.py like this it has to be in the current working
directory of the other program. If you just go os.system("pyq.py ibm")
and pyq.py has the #! business at the start of it, then pyq.py has to be
in your PATH. Otherwise it should work. So long as you're sure the file
ibm has been created by this point.

One of the benefits of doing it with import instead (the thing I
described above) is you don't have to worry about the shell and its
environment, or what PATH is, but only the Python environment
(PYTHONPATH, sys.path, that kind of thing). It's more portable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread aaronwmail-usenet
I agree that more progress is needed on the Python documentation
front.  For example if you look at the "codecs" module documentation
there is no hint of what a codec is anywhere that I can see. Also
the distinction between an "encoder" and a "decoder" is not explained.
Even though I've used it many times and understand it, I still find
myself using the interactive interpreter to make sure I'm sending the
bytes in the right direction...

Perhaps some faqwiz/wiki-like tool to allow the broader community to
propose documentation enhancements would be useful?

  -- Aaron Watters

===

"I know what it's like to put food on my family."  G.W.Bush

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


Re: Please, I Have A Question before I get started

2006-03-14 Thread paron
Well, Nicholas Chase just posted an OpenLaszlo tutorial/app that shows
how OpenLaszlo handles sounds. Try
http://www-128.ibm.com/developerworks/edu/os-dw-os-php-openlaszlo1-i.html
You have to register, but it's free, and they don't bug you. It's PHP
driven, but that part's easily ported to Python.

Anyway, there's the basis of an all open-source or freeware application
that animates with sounds.

Ron

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


Little Help with Exceptions and ConfigParser

2006-03-14 Thread mwt
Hi -
I'm having a little trouble using exceptions properly. I currently have
an initialization function on a little app that looks like this:

def __init__(self, config_file):
self.fahdata = fahdata.FAHData()
self.INI = ConfigParser.ConfigParser()
if os.path.exists(config_file):
try:
self.INI.read(config_file)
except ConfigParser.ParsingError:
print "Cannot parse configuration file!"

This is just a hack I came up with to load the configuration file and
try to test for serious problems with it. Trouble is, it doesn't really
do that, and furthermore, if there are small problems with the file
(such as a NoSectionError) the whole program bombs. Instead, I would
like to test for the relevant Errors and Exceptions, and have the
program deal with them gracefully.

Would one of you gurus be so kind as to point me in the right direction
here? I know that there are many possibilities, but what would be a
sane and reasonable set of exceptions to throw?

Meanwhile, I will be reading pages 337-339 in my copy of Python in a
Nutshell to try to get clearer about exceptions and how to use them.

Thanks.
mwt

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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread Terry Hancock
On 14 Mar 2006 09:25:07 -0800
[EMAIL PROTECTED] wrote:
> Do you prefer epytext or reST?

I personally prefer epytext primarily because it has support
for greek letters and math symbols. That could be very
useful in documenting certain kinds of software. OTOH, I
haven't had much occasion to use that feature (once upon a
time almost all the software I wrote was scientific, but it
seems I've pretty much given it up -- not that I
particularly planned to, but it's turned out that way).

I was under the impression that pydoc already interpreted
restructured text notation, but maybe I was wrong. I don't
like pydoc because it doesn't make useable static
documentation sets -- that's where epydoc (which I suppose
stands for "extended pydoc") shines.

Although it's great to have "manpage" type help, I
personally find HTML documentation much easier to read and
browse.  Pydoc can do this if you are willing to use it as a
server, but it doesn't do so well at making an in-package
website, which is what I usually want to do.

There's also happydoc, which was better than either at
discovering documentation, but stagnated somewhere between
2.x and 3.x with bugs that make it fairly unusable.  What
would be cool is if some of happydoc's unique features were
ported to epydoc (such as getting information from comments
as well as docstrings).

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: Tree and Graph structures in Python.

2006-03-14 Thread bearophileHUGS
http://www.osl.iu.edu/~dgregor/bgl-python/
http://sourceforge.net/projects/pygraphlib/
http://sourceforge.net/projects/pynetwork/
https://networkx.lanl.gov/
http://starship.python.net/crew/aaron_watters/kjbuckets/
http://www.python.org/doc/essays/graphs.html
http://yapgvb.sourceforge.net/
http://dkbza.org/pydot.html
http://www.geocities.com/foetsch/mfgraph/index.htm

(Some of them are just explanations, or interfaces with a well known
graph plotting package).
With Google you can probably find 2-4 other libraries...
I think there are so many of them because some people need them, but
there isn't a standard one yet in the built-in library.

Bye,
bearophile

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


Re: Tree and Graph structures in Python.

2006-03-14 Thread Istvan Albert
See this:

https://networkx.lanl.gov/

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


Re: convert hex to decimal

2006-03-14 Thread challman

Oh, that should have been whole number; not while.

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


Re: Python Debugger / IDE ??

2006-03-14 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:
> Is there any editor or IDE in Python (either Windows or Linux) which
> has very good debugging facilites like MS VisualStudio has or something
> like that.
> 
> I like SPE but couldn't easily use winPDP. I need tips to debug my code
> easily.
> 
> Every help is greatly appreciated.
> 
> Thanks
> 
If you don't mind spending (not so much) money, ActiveState's Komodo
is a nice debugger.   With it you can even debug a Python program on
a remote machine over a network connection (ideal for GUI problems).

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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread Nick Craig-Wood
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>  IMO, Perl has docs nailed. I learned Perl before coming
>  to Python, and I can tell you that their docs kick butt.
>  I believe the reason why is (besides Larry's excellent
>  and entertaining writing) because of perldoc. Here's how
>  it works: they write special doc directives into their .pl
>  files that the interpreter ignores, but that the perldoc
>  command processes into a manpage for you. This is a *bit*
>  like what pydoc does, only pydoc just regurgitates docstrings,
>  while perldoc formats special directives into headings, code
>  listings, bulleted lists, etc.

As another perl refugee I agree with you 100% here.

"perldoc perltoc" then "perldoc " will find you anything in perl.

Its frustrating that pydoc is only half (or less) of the docs.

However having bedded into python for a few years, I now just reach
for my web browser for the global module index instead of pydoc.  Its
not as good as perldoc as it doesn't cover all the modules I've got
installed, but its very good documentation.  Some modules have good
pydoc-umentation but not all of them.  Code examples tend to be
missing.

I think a major problem with our way of thinking about
perldoc/pydoc/man pages is that it is a) unix centric, and b) possibly
a bit old fashioned!  a) and b) apply to perl certainly, but I don't
think they apply to python in the same way.

I'd love to have a unified documentation system where *all* the
documentation for *all* installed modules was available to pydoc *and*
the web browser and *all* this documentation was in .py files.

(Putting the code together with the documentation is essential in my
opinion and experience - if you seperate the two then the documention
will lag the code.)

PS I've used reST and perldoc.  reST is easier to use for the easy
things, but gets complicated for the hard things.

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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread john_sips_tea
Ok. I'm going to try and make something happen. Give me a day or so.

:)
---John

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


Re: Is this possible in Python? SOLUTION FOUND

2006-03-14 Thread Kay Schluehr

[EMAIL PROTECTED] wrote:
> jalanb wrote:
> > You might like the version here:
> > http://www.jorendorff.com/toys/out.html
> >
> > Especially the "need to know" presentation, which is cute
> >
> > --
> > Alan
> > http://aivipi.blogspot.com
>
> Thank you for the tip.
> Meanwhile, I found a shorter solution to my problem:
> def magic(arg):
>   import inspect
>   return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
>
> assert magic(3+4)=="3+4"
>
> Alain

Does it? Using your function I keep an assertion error. Storing the
return value of magic()in a variable s I receive the following result:

def magic(arg):
import inspect
return inspect.stack()[1][4][0].split("magic")[-1][1:-1]

s = magic(3+4) # magic line

>>> s
'lin'


BTW grepping the stack will likely cause context sensitive results.

Kay

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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread Colin J. Williams
Diez B. Roggisch wrote:
>>Thanks Diez! Epydoc looks great.
>>
>>Can we use epytext to generate output suitable for a manpage?
> 
> 
> Don't know, never tried that.
>  
The answer appear to be No, but there is a man.py file which indicates 
that some work was done on it.

Below is the epydoc commandline guide.

Colin W.

epydoc [OPTIONS] MODULES...

 MODULES...The Python modules to document.
 --htmlGenerate HTML output (default).
 --latex   Generate LaTeX output.
 --pdf Generate pdf output, via LaTeX.
 --check   Run documentation completeness checks.
 -o DIR, --output DIR  The output directory.
 -n NAME, --name NAME  The documented project's name.
 -u URL, --url URL The documented project's url.
 -t PAGE, --top PAGE   The top page for the HTML documentation.
 -c SHEET, --css SHEET CSS stylesheet for HTML files.
 --private-css SHEET   CSS stylesheet for private objects.
 --inheritance STYLE   The format for showing inherited objects.
 -V, --version Print the version of epydoc.
 -h, -?, --help, --usage   Display this usage message.
 -h TOPIC, --help TOPICDisplay information about TOPIC (docformat,
   css, inheritance, usage, or version).
> 
>>Do you prefer epytext or reST?
> 
> 
> So far epytext suited my needs.
> 
> Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trace dynamically compiled code?

2006-03-14 Thread Ziga Seilnacht
Ed Leafe wrote:
> Hi,
>
>   Thanks to the help of many on this list, I've been able to take code
> that is created by the user in my app and add it to an object as an
> instance method. The technique used is roughly:

Just some notes about your code:

> nm = "myMethod"
> code = """def myMethod(self):
> print "Line 1"
> print "My Value is %s" % self.Value
> return
> """
> compCode = compile(code, "", "exec")
> exec compCode

Try not using bare exec statements, since they pollute the local scope.
In your example you could use:

compCode = compile(code, "", "exec")
d = {}
exec compCode in d
func = d[nm]

See http://docs.python.org/ref/exec.html for details.

> exec "self.%s = %s.__get__(self)" % (nm, nm)

You don't need dynamic execution here; you can simply use
setattr and the new module:

import new
method = new.instancemethod(func, self)
setattr(self, nm, method)

and yes, I remember that I was the one who suggested you
the __get__ hack.

>   This is working great, but now I'm wondering if there is a way to
> enable pdb tracing of the code as it executes? When tracing "normal"
> code, pdb will show you the name of the script being executed, the
> line number and the source code for the line about to be executed.
> But when stepping through code compiled dynamically as above, the
> current line's source code is not available to pdb, and thus does not
> display.
>
>   Does anyone know a way to compile the dynamic code so that pdb can
> 'see' the source? I suppose I could write it all out to a bunch of
> temp files, but that would be terribly messy. Are there any neater
> solutions?

You should check py lib: http://codespeak.net/py/current/doc/ ,
specifically the py.code "module". Then you can modify the
function from above:

import inspect
f = inspect.currentframe()
lineno = f.f_lineno - 5 # or some other constant
filename = f.f_code.co_filename

import py
co = py.code.Code(func)
new_code = co.new(co_lineno=lineno, co_filename=filename)
new_func = new.function(new_code, func.func_globals, nm,
func.func_defaults, func.func_closure)


> -- Ed Leafe
> -- http://leafe.com
> -- http://dabodev.com

Ziga Seilnacht

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


Re: Python Debugger / IDE ??

2006-03-14 Thread [EMAIL PROTECTED]
>Is there any editor or IDE in Python (either Windows or Linux) which
>has very good debugging facilites like MS VisualStudio has or something
>like that.

I've been using Eclipse with PyDev and am very happy with it.

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


Re: Python Debugger / IDE ??

2006-03-14 Thread Rene Pijlman
[EMAIL PROTECTED]:
>Is there any editor or IDE in Python (either Windows or Linux) which
>has very good debugging facilites like MS VisualStudio has or something
>like that.

Here's a recent thread about IDEs:
http://groups.google.nl/group/comp.lang.python/browse_frm/thread/fd9604e225252ad4

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: recycling internationalized garbage

2006-03-14 Thread Ross Ridge
[EMAIL PROTECTED] wrote:
> try:
> (uni, dummy) = utf8dec(s)
> except:
> (uni, dummy) = iso88591dec(s, 'ignore')

Is there really any point in even trying to decode with UTF-8?  You
might as well just assume ISO 8859-1.

   Ross Ridge

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


Re: Python Debugger / IDE ??

2006-03-14 Thread olsongt

[EMAIL PROTECTED] wrote:
> Is there any editor or IDE in Python (either Windows or Linux) which
> has very good debugging facilites like MS VisualStudio has or something
> like that.
>
> I like SPE but couldn't easily use winPDP. I need tips to debug my code
> easily.
>
> Every help is greatly appreciated.
>
> Thanks

I've always been happy with the debugger in PythonWin.  You can even
use:

from pywin.debugger import set_trace;set_trace()

to bring up the debugger directly from a script that wasn't originally
run in the ide.

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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread john_sips_tea
> So far epytext suited my needs.

I like it too.

Ok, now I'm starting to get excited. :)

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


Python Debugger / IDE ??

2006-03-14 Thread krypto . wizard
Is there any editor or IDE in Python (either Windows or Linux) which
has very good debugging facilites like MS VisualStudio has or something
like that.

I like SPE but couldn't easily use winPDP. I need tips to debug my code
easily.

Every help is greatly appreciated.

Thanks

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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread Diez B. Roggisch
> Thanks Diez! Epydoc looks great.
> 
> Can we use epytext to generate output suitable for a manpage?

Don't know, never tried that.
 
> Do you prefer epytext or reST?

So far epytext suited my needs.

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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread john_sips_tea
Thanks Diez! Epydoc looks great.

Can we use epytext to generate output suitable for a manpage?

Do you prefer epytext or reST?

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


How to create a Visual SourceSafe plugin in Python

2006-03-14 Thread looping
Hi,
I try to create a COM object with win32com to track events in Visual
SourceSafe.
I tried to modify ExcelAddin.py demo but with no luck.
I've now a Delphi DLL that make that job so I know it's possible.

If someone have an exemple, please help me.

Best regards.
Kadeko

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


Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread Diez B. Roggisch
> Please note, I certainly don't want to step on the doc-sig folks'
> toes here -- but rather to generate more interest in what they're
> doing, and to help make Python be even better in an area that I
> see it struggling.
> 
> What do you folks think?
> 
> Yes, I'm trying to make time to look at the docutils code and the
> pydoc command to see what's involved. Unfortunately, my spare
> time is vanishingly close to zero right now.


You heard of epydoc? http://epydoc.sourceforge.net/

It pretty much does what you say I think - and for my personal projects I
use it. Maybe we an adopt it as standard-tool.

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


Re: Please, I Have A Question before I get started

2006-03-14 Thread Steve Holden
Skipper wrote:
> Well, thank you so much for taking the time to reply.  I guess that
> about wraps up all my questions.
> 
> 
> You fucking putz
> 

I'd appreciate it if you;d keep that sort of response to yourself. While 
I don't mind you *thinking* it, it isn't the kind of behaviour we want 
to encourage in these parts, no matter how fatuous you may have found 
the response that triggered your profanity.

Thanks
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

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


Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread john_sips_tea
Just tried Ruby over the past two days. I won't bore you
with the reasons I didn't like it, however one thing really
struck me about it that I think we (the Python community)
can learn from.

Ruby has ... an issue with docs. That is to say, there are
almost none. Well, actually, there are some. For example,
the "PickAxe" book (google it), and "Why's" Poignant Guide.
But there's a disturbing lack of *built-in* docs for Ruby.
Now, the situation is getting better. In fact, it's getting
better very quickly. Let me explain.

IMO, Perl has docs nailed. I learned Perl before coming
to Python, and I can tell you that their docs kick butt.
I believe the reason why is (besides Larry's excellent
and entertaining writing) because of perldoc. Here's how
it works: they write special doc directives into their .pl
files that the interpreter ignores, but that the perldoc
command processes into a manpage for you. This is a *bit*
like what pydoc does, only pydoc just regurgitates docstrings,
while perldoc formats special directives into headings, code
listings, bulleted lists, etc.

Now, the *real* magic of perldoc is that it makes writing
small self-contained little manpage style docs easy as pie.
What this means is that really good doc writers can sit down
and quickly produce something that can be readily incorporated
into the perl-doc distribution. *That's* the magic. That's
why I think they've organically grown such an amazing crop
of great docs. Anyone can quickly and easily write docs that
the community can then filter to find the best ones.

Back to Ruby's docs. Their situation is getting better. This
is because they're picking up on Perl's doc success and doing
the same sort of thing. Only, I think their solution may be
clunkier because it requires a separate program (rdoc) to
process the doc directives, and then you actually read the
docs with a program called ri (not sure). Regardless of the
minute details, it looks like their docs are starting to get
better, rapidly.

Here's what I think is currently happening with Python
(please correct me if I'm wrong): There's the docutils project
http://docutils.sourceforge.net/ which, AFAICT, is working on a
number of complicated things, one of which is to have a way to
allow you to put reStructuredText markup (aka "reST")
( http://docutils.sourceforge.net/rst.html ) into your docstrings
(and presumably have the pydoc command understand it). There's
more info in PEP 287 http://www.python.org/doc/peps/pep-0287/ .

I certainly don't understand all that Docutils is trying to
do. All I'm convinced of is, the real magic is in being able to
quickly write a .py file containing marked up docstrings and
have the pydoc command be able to render it as something that
looks like a man page in my terminal window. If it can later
also produce html, that's great too. But *that's* the essense,
IMO, of what will foster community involvement in making the
docs great, as well as allowing folks to more easily document
their own modules and contribute integrated docs to all the
great modules already available.

It looks like we have the tools do this *right now*. We've got
the markup (reST), we've got the tools to churn that into a
manpage or html (part of docutils?), and we've got the pydoc
command. I think the current hangup is that the docutils guys
(being smart and ambitious folks) want to get some sort of
inter-doc linking thing working so you can refer from one doc
page to another (?). I don't think perldoc has (or needs) that
feature... maybe we could put that on the "would be nice to
have down the road" list, and get a quick common-sense
docstring-reST pydoc setup working for us much sooner? I
don't know for sure, but my guess is "yes".

Eventually, maybe the tutorial, language reference, library ref,
etc., could even all make it into this format, with the html
versions generated from the .py/docstring/reST sources. That might
make it easier for the community to contribute to them (if their
respective maintainers are interested in that).

Please note, I certainly don't want to step on the doc-sig folks'
toes here -- but rather to generate more interest in what they're
doing, and to help make Python be even better in an area that I
see it struggling.

What do you folks think?

Yes, I'm trying to make time to look at the docutils code and the
pydoc command to see what's involved. Unfortunately, my spare
time is vanishingly close to zero right now.

Related link:
Doc-SIG http://www.python.org/community/sigs/current/doc-sig/

Thanks,
---John

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


Re: calling another python file within python

2006-03-14 Thread Rene Pijlman
Kevin:
>#!/usr/bin/python
>
>import os
>import urllib
>os.system("python pyq.py ibm > text1.txt")

Check the return value of os.system.

>note: currently the text1.txt outputted is just blank, however if i run 
>the command normally as 'python pyq.py ibm' in the command line, it 
>works correctly and gives me the price of ibm.

Same PATH, PYTHONPATH, current working directory, user,... ?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tree and Graph structures in Python.

2006-03-14 Thread Lonnie Princehouse
Google for "boost graph python"

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


Tree and Graph structures in Python.

2006-03-14 Thread Ant
Hi all,

Are there any tree or graph modules available for python?

Cheers,

-- 
Ant...

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


Re: [Numpy-discussion] [ANN] NumPy 0.9.6 released

2006-03-14 Thread Colin J. Williams
Travis Oliphant wrote:

> This post is to announce the release of NumPy 0.9.6 which fixes some 
> important bugs and has several speed improvments.
>
> NumPy is a multi-dimensional array-package for Python that allows 
> rapid high-level array computing with Python.  It is successor to both 
> Numeric and Numarray.  More information at http://numeric.scipy.org
>
> The release notes are attached:
>
> Best regards,
>
> NumPy Developers
>
>  - __array_finalize__ is now called for every array sub-class creation.
>  
>
Thanks.  What are the parameters for this method and what does it do?

How does it differ from the common Python usage of __new__ followed by 
__init__?

[Dbg]>>>
Help on built-in function __array_finalize__:

__array_finalize__(...)


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


calling another python file within python

2006-03-14 Thread Kevin
i have a python file called pyq which outputs stock quotes, currently i 
also have a html file that takes stock ticker inputs, i would like to 
bridge the two by building another program that takes the html inputs 
and uses them to call the pyq stock ticker program and then output them 
into a text file...

any idea how to do this? my tentative code is:



#!/usr/bin/python

import os
import urllib
os.system("python pyq.py ibm > text1.txt")




note: currently the text1.txt outputted is just blank, however if i run 
the command normally as 'python pyq.py ibm' in the command line, it 
works correctly and gives me the price of ibm.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cheese Shop: some history for the new-comers

2006-03-14 Thread Robert Boyd
On 3/14/06, A.M. Kuchling <[EMAIL PROTECTED]> wrote:
> On Sun, 12 Mar 2006 10:25:19 +0100,
> Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> > and while you're at it, change "python-dev" to "developers" and
> > "psf" to "foundation" (or use a title on that link).
>
> I've changed the PSF link, but am not sure what to do about the
> python-dev link.  As others have noted, "Developers" is ambiguous
> about whether it's for people who develop in Python or who develop
> Python itself."Core Development"?  (Used on both perl.org and tcl.tk, so
> maybe this is the best option.) "Development Team"?
>
> --amk
>

"Core Development" is good IMO,  or "Language Development". I think
the latter is explicit and distinguishes itself from "using the
language to write programs" aka "Developing in (or with) Python".

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


Re: Please, I Have A Question before I get started

2006-03-14 Thread Terry Hancock
On Mon, 13 Mar 2006 02:19:39 GMT
Skipper <[EMAIL PROTECTED]> wrote:
> Basically the program will blank the screen and call up
> (for example) 6 pictures.  A flashing border with travel
> from picture to picture. When the computer senses a mouse
> click it will clear the screen and present a second set of
> choices ... one level deeper than the first ... based on
> the chosen picture.

So the key difference from, say, a web page in a browser,
is that you want the choice to be determined by timing,
not by where the mouse is pointed?

This is actually quite non-standard, so there won't be
a lot of support for it in GUI-building tools.

However, it is the sort of thing that a game toolkit is
well-organized for. IMHO, PyGame is probably very close
to the fastest way to achieve this.  But you will have
to learn how to create a data model for your menus,
etc.

The main module can be dead simple, though. You just
need to paste in a little PyGame boilerplate at the
top (examples are included in the PyGame distribution),
then you'll have a loop that handles displaying a menu,
rotating through the choices, and listening for keyboard
input.  Something like this (I'm writing from memory --
you'll have to check the pygame documentation (which is
excellent, BTW) to find details):

import pygame
from pygame.locals import *
pygame.init()

screen = pygame.display.set_mode((800,600))
# There are smarter ways to do this, but for
# a one-off project, just use your known screen size

# HERE YOU NEED TO BUILD YOUR MENU TREE
# I'm assuming a tree structure of some
# kind with some obvious methods attached
# to each node

current_menu = root_menu
while 1:
current_menu.display()
try:
for choice in current_menu.choices:
root_menu.highlight(choice)
t0= pygame.time.get_ticks()
t = t0
while thttp://www.AnansiSpaceworks.com

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


EVT_ICONIZE lost focus

2006-03-14 Thread lux
Hi,
I have a wxFrame with some TextCtrl,
if I minimize the Frame when normalize it
lost the Focus and I must click to give the focus to textCtrl again

How can resolve?

Thank's,
Luca

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


Re: recycling internationalized garbage

2006-03-14 Thread aaronwmail-usenet
Regarding cleaning of mixed string encodings in
the discography search engine

http://www.xfeedme.com/discs/discography.html

Following 's suggestion I came up with this:

utf8enc = codecs.getencoder("utf8")
utf8dec = codecs.getdecoder("utf8")
iso88591dec = codecs.getdecoder("iso-8859-1")

def checkEncoding(s):
try:
(uni, dummy) = utf8dec(s)
except:
(uni, dummy) = iso88591dec(s, 'ignore')
(out, dummy) = utf8enc(uni)
return out

This works nicely for Nordic stuff like
"björgvin halldórsson - gunnar Þórðarson",
but russian seems to turn into garbage
and I have no idea about chinese.

Unless someone has any other ideas I'm
giving up now.
   -- Aaron Watters

===

In theory, theory is the same as practice.
In practice it's more complicated than that.
  -- folklore

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


Re: Writing 'C' structures out in cPickle format?

2006-03-14 Thread Diez B. Roggisch
> On the Python side I decided to use cPickle. On the C side I would
> write a library that can read the cPickle and generate the correct
> C structure (the data is, more or less, self-describing) and visa
> versa.
> 
> I was wondering if anyone has done something like this before
> and if so can they point me to information on how to easily do it?
> The structures I am using on the C side are pretty simple (very
> flat and using only integers and strings).

I guess it might be the more sensible choice to use module struct and
transform your python-data to C-structs. The reason is simply that to teach
the old dog C new tricks (namely react flexible on cPickle) is a hard task,
whereas customizing python objects serialization is comparably easy.

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


Re: Cheese Shop: some history for the new-comers

2006-03-14 Thread A.M. Kuchling
On Sun, 12 Mar 2006 10:25:19 +0100, 
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> and while you're at it, change "python-dev" to "developers" and
> "psf" to "foundation" (or use a title on that link).

I've changed the PSF link, but am not sure what to do about the
python-dev link.  As others have noted, "Developers" is ambiguous
about whether it's for people who develop in Python or who develop
Python itself."Core Development"?  (Used on both perl.org and tcl.tk, so
maybe this is the best option.) "Development Team"?  

--amk

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


Writing 'C' structures out in cPickle format?

2006-03-14 Thread Chance Ginger
I have a problem that I am trying to solve. I have two different
systems - one written in C and another in Python. I would like the
two to exchange some information. 

On the Python side I decided to use cPickle. On the C side I would
write a library that can read the cPickle and generate the correct
C structure (the data is, more or less, self-describing) and visa
versa. 

I was wondering if anyone has done something like this before
and if so can they point me to information on how to easily do it?
The structures I am using on the C side are pretty simple (very
flat and using only integers and strings).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Customizing character set conversions with an error handler

2006-03-14 Thread Jukka Aho
Serge Orlov wrote:

>> # So the question becomes: how can I make this work
>> # in a graceful manner?

> change the return statement with this code:
>
> return (substitution.encode(error.encoding,"practical").decode(
>error.encoding), error.start+1)

Thanks, that was a quite neat recursive solution. :) I wouldn't have 
thought of that.

I ended up doing it without the recursion, by testing the individual 
problematic code points with .encode() within the handler, and catching 
the possible exceptions:

--- 8< ---

# This is our original problematic code point:
c = error.object[error.start]

while 1:

# Search for a substitute code point in
# our table:

c = table.get(c)

# If a substitute wasn't found, convert the original code
# point into a hexadecimal string representation of itself
# and exit the loop.

if c == None:
c = u"[U+%04x]" % ord(error.object[error.start])
break

# A substitute was found, but we're not sure if it is OK
# for for our target encoding. Let's check:

try:
c.encode(error.encoding,'strict')
# No exception; everything was OK, we
# can break off from the loop now
break

except UnicodeEncodeError:
# The mapping that was found in the table was not
# OK for the target encoding. Let's loop and try
# again; there might be a better (more generic)
# substitution in the chain waiting for us.
pass

--- 8< ---

-- 
znark

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


Re: Which GUI toolkit is THE best?

2006-03-14 Thread Chris Mellon
On 14 Mar 2006 06:10:19 -0800, Paul Boddie <[EMAIL PROTECTED]> wrote:
> Alan Franzoni wrote:
> >
> > Just one thing I don't understand: if you're developing all your software
> > inside your company, how would they know if you already coded it or you
> > still have to?
>
> I have no idea. But as I said elsewhere, I'm not in any sense a party
> to the process that would attempt to define such enforcement matters.
>
> > Also, couldn't a big company buy a *single* commercial license from the
> > beginning, build a software employing hundreds of developers using the GPL
> > license, and then distribute the software pretending that the single
> > developer had done everything? This would hit Trolltech anyway.
>
> True, but then have you ever used proprietary software with those
> irritating floating licences or with licence keys? Sure, a company
> doing stuff on the cheap could buy fewer licences than they need - I've
> been in a situation where an employer has bought n licences of some
> flashy-but-not-exactly-necessary solution that everyone (n + x people)
> has been forced to use, and you end up with all sorts of management
> workarounds ("if you're not using product X, can you log off and log
> back in later?") - and I'd imagine that where technical measures aren't
> the means of limiting the number of users, you get all sorts of
> management workarounds to give the impression that only one developer
> is using the software in other enforcement regimes: having one person
> that collates and forwards support requests, for example. That
> businesses would rather waste their employees' time at a much higher
> cost than just forking out for more software isn't a surprise to me
> whatsoever.
>
> > I think the problem has to do with the QT license system. It's their
> > problem, not a developer's one. Also, I suppose one of their commercial
> > licenses provides with far lot more than a license - e.g. I think they'll
> > offer support, design tools, additional docs and libraries.
>
> I believe so, yes. However, the problem with any licensing system is
> generally the developer's: if you want to sell a solution based on
> Microsoft Office, is it Microsoft's problem that they chose an
> ultra-proprietary licence? As a developer you do get to choose other
> solutions, however. (Perhaps I've misinterpreted what you meant,
> though.)
>
> > And what would then be their income if they refused to sell you a
> > commercial license because they *know* you've already coded your app using
> > the GPL license of Qt? You could simply throw away your app and never
> > distribute it, and they would'nt see a cent anyway.
>
> I have no idea. It's best to ask them that question rather than random
> newsgroup contributors, I think. ;-)
>

It's pretty obvious, though. The whole point of people doing this is
that they only want to pay for 1 license once rather than X licenses
for the whole dev cycle. By not selling you a license they lose $1000,
but they keep enforcing a licensing system that makes them a lot more
money. Their leverage comes from the fact that you've invested however
much time and effort into the app development and while you can toss
it you're out a great deal more than they are.

I suspect that if enough money changed hands (like, you paid for your
X developers backdated to when you started development) you could
convince TT to sell you a license, too.
> Paul
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trace dynamically compiled code?

2006-03-14 Thread Thomas Heller
Ed Leafe wrote:
> Hi,
> 
>   Thanks to the help of many on this list, I've been able to take code  
> that is created by the user in my app and add it to an object as an  
> instance method. The technique used is roughly:
> 
> nm = "myMethod"
> code = """def myMethod(self):
> print "Line 1"
> print "My Value is %s" % self.Value
> return
> """
> compCode = compile(code, "", "exec")
> exec compCode
> exec "self.%s = %s.__get__(self)" % (nm, nm)
> 
>   This is working great, but now I'm wondering if there is a way to  
> enable pdb tracing of the code as it executes? When tracing "normal"  
> code, pdb will show you the name of the script being executed, the  
> line number and the source code for the line about to be executed.  
> But when stepping through code compiled dynamically as above, the  
> current line's source code is not available to pdb, and thus does not  
> display.
> 
>   Does anyone know a way to compile the dynamic code so that pdb can  
> 'see' the source? I suppose I could write it all out to a bunch of  
> temp files, but that would be terribly messy. Are there any neater  
> solutions?

You coud monkey-patch the getline function in the linecache module, so
that it is able to find your dynamically generated code.  IMO that is
what pdb uses.c

Thomas

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


Re: Which GUI toolkit is THE best?

2006-03-14 Thread Paul Boddie
Alan Franzoni wrote:
>
> Just one thing I don't understand: if you're developing all your software
> inside your company, how would they know if you already coded it or you
> still have to?

I have no idea. But as I said elsewhere, I'm not in any sense a party
to the process that would attempt to define such enforcement matters.

> Also, couldn't a big company buy a *single* commercial license from the
> beginning, build a software employing hundreds of developers using the GPL
> license, and then distribute the software pretending that the single
> developer had done everything? This would hit Trolltech anyway.

True, but then have you ever used proprietary software with those
irritating floating licences or with licence keys? Sure, a company
doing stuff on the cheap could buy fewer licences than they need - I've
been in a situation where an employer has bought n licences of some
flashy-but-not-exactly-necessary solution that everyone (n + x people)
has been forced to use, and you end up with all sorts of management
workarounds ("if you're not using product X, can you log off and log
back in later?") - and I'd imagine that where technical measures aren't
the means of limiting the number of users, you get all sorts of
management workarounds to give the impression that only one developer
is using the software in other enforcement regimes: having one person
that collates and forwards support requests, for example. That
businesses would rather waste their employees' time at a much higher
cost than just forking out for more software isn't a surprise to me
whatsoever.

> I think the problem has to do with the QT license system. It's their
> problem, not a developer's one. Also, I suppose one of their commercial
> licenses provides with far lot more than a license - e.g. I think they'll
> offer support, design tools, additional docs and libraries.

I believe so, yes. However, the problem with any licensing system is
generally the developer's: if you want to sell a solution based on
Microsoft Office, is it Microsoft's problem that they chose an
ultra-proprietary licence? As a developer you do get to choose other
solutions, however. (Perhaps I've misinterpreted what you meant,
though.)

> And what would then be their income if they refused to sell you a
> commercial license because they *know* you've already coded your app using
> the GPL license of Qt? You could simply throw away your app and never
> distribute it, and they would'nt see a cent anyway.

I have no idea. It's best to ask them that question rather than random
newsgroup contributors, I think. ;-)

Paul

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


Re: Very, Very Green Python User

2006-03-14 Thread bruno at modulix
Scott David Daniels wrote:
> [EMAIL PROTECTED] wrote:
> 
>> ... Is the Python debugger fairly stable?
> 
> Yes, but it is not massively featured.  The "Pythonic" way is to
> rarely use a debugger (test first and straightforward code should
> lead to "shallow" bugs).  Often for most of us judiciously placed
> print statements suffice.

Well, the fact is that I haven't used pdb on more than two or three
occasions, and I'm using Python since the 1.5.x.


-- 
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: andmap and ormap

2006-03-14 Thread wkehowski
The following works perfectly:

import operator

def andmap(b,L):
return reduce(operator.and_, [b(x) for x in L])

def ormap(b,L):
return reduce(operator.or_, [b(x) for x in L]) 

Thanks!

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


  1   2   >