ANN: Python training, 2006 Feb 1-3, San Francisco

2005-12-08 Thread w chun
What:   Python Programming I: Introduction to Python
When:   February 1-3, 2006
Where:  San Francisco, CA, USA
Web:http://cyberwebconsulting.com

Need to get up-to-speed with Python as quickly as possible?  Come join
us in beautiful Northern California for another rigorous Python
training event taught by software engineer, Core Python Programming
author, and technical instructor Wesley Chun.

This is an intense introduction to Python programming geared towards
those who have some proficiency in another high-level language. Topics
include:

* Syntax, Data Types, Operators, and Methods
* Python's Objects and Memory Model
* Errors and Exception Handling
* Flow Control (Loops and Conditionals)
* Writing Optimized Python
* Files and Input/Output
* Functions and Functional Programming Aspects
* Modules and Packages
* OOP: Classes, Methods, and Class Instances
* OOP: Class Customization, Inheritance
* Execution Environment
* Operating System Interface
* Advanced Topics and Python Updates

This course will take place near the San Francisco International Airport at the:

Staybridge Suites
San Francisco Airport
1350 Huntington Ave
San Bruno, CA  94066 USA
+1-650-588-0770

VISITORS: free transportation to/from the San Francisco International airport
LOCALS and VISITORS:  easy access to public transit (BART [across the
street!], CalTrain, SamTrans) can help you get all over the San
Francisco Bay Area

Discounts are available for multiple registrations as well as
teachers/students.  For more information and registration, go to
http://cyberwebconsulting.com and click on the Python Training link.
Unlike previous courses, we are limiting enrollment to a maximum of 15
attendees.  If you have any questions, feel free to contact us at
cyberweb-at-rocketmail.com.

For those who are interested in more advanced Python topics,
we'reoffering a follow-on course late Spring 2006 (most likely May). 
Also, if there is sufficient interest, we may hold another one of
these Intro to Python courses down in Silicon Valley in April;
contact me directly if you're interested in this location.

Note: i will only send out ONE MORE REMINDER in January... yeah, i
don't like spam either. :-)

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core Python Programming, Prentice Hall, (c)2006,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


[ANN] Python-OpenID 1.0

2005-12-08 Thread Kevin Turner
It is with great pleasure that JanRain, Inc. announces version 1.0 of
the Python OpenID library.  This library contains packages to support
both OpenID consumers (relying parties) and servers.  For back-end
storage, it supports a variety of methods, including flat file, SQL, and
MemCached.

In our own work on making applications OpenID enabled, we've been
reminded that every web framework is different.  For that reason we've
strived to make this library general enough to fit in to any Python web
application.  We also like to think the API is simple to follow.  Let us
know how it works for you.


Home: http://openidenabled.com/openid/libraries/python
License:  LGPL
Download: http://openidenabled.com/openid/libraries/python/downloads/
Docs: http://openidenabled.com/python-openid-docs/1.0.0/

Requires: Python (versions 2.2 through 2.4)


What is this OpenID Thing Anyway?

OpenID is a decentralized identity system that provides authentication
for web applications, i.e. single sign-on for the web.  
See http://openid.net/

If you're interested in OpenID but this library isn't quite what you've
been waiting for for, keep your eye on http://openidenabled.com.
There's more coming.


Share and Enjoy,

 - the OpenID Team at JanRain
   [EMAIL PROTECTED]


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

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


[ANNOUNCE] Twenty-seventh release of PythonCAD now available

2005-12-08 Thread Art Haas
Hi.

I'm pleased to announce the twenty-seventh development release of PythonCAD,
a CAD package for open-source software users. As the name implies,
PythonCAD is written entirely in Python. The goal of this project is
to create a fully scriptable drafting program that will match and eventually
exceed features found in commercial CAD software. PythonCAD is released
under the GNU Public License (GPL).

PythonCAD requires Python 2.2 or newer. The interface is GTK 2.0
based, and uses the PyGTK module for interfacing to GTK. The design of
PythonCAD is built around the idea of separating the interface
from the back end as much as possible. By doing this, it is hoped
that both GNOME and KDE interfaces can be added to PythonCAD through
usage of the appropriate Python module. Addition of other PythonCAD 
interfaces will depend on the availability of a Python module for that
particular interface and developer interest and action.

The twenty-seventh release contains primarily bug fixes and internal
code enhancements. A long-standing interface problem where the display
of selected entities was not clear has been fixed. When you select an
entity it is redrawn in a highlighting color, making it clear which
entities are selected at any one time. Also, the ability to deselect
a selected entity has been added to the interface. The bug fixes included
in this release address a few problems introduced in the previous release
as well as various older issues.

A mailing list for the development and use of PythonCAD is available.
Visit the following page for information about subscribing and viewing
the mailing list archive:

http://mail.python.org/mailman/listinfo/pythoncad

Visit the PythonCAD web site for more information about what PythonCAD
does and aims to be:

http://www.pythoncad.org/

Come and join me in developing PythonCAD into a world class drafting
program!

Art Haas
-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: efficient 'tail' implementation

2005-12-08 Thread Gerald Klix
As long as memory mapped files are available, the fastest
method is to map the whole file into memory and use the
mappings rfind method to search for an end of line.

The following code snippets may be usefull:
 reportFile = open( filename )
 length = os.fstat( reportFile.fileno() ).st_size
 if length == 0:
 # Don't map zero length files, windows will barf
 continue
 try:
 mapping = mmap.mmap( reportFile.fileno(), length,
 mmap.MAP_PRIVATE, mmap.PROT_READ )
 except AttributeError:
 mapping = mmap.mmap(
 reportFile.fileno(),
 0, None,
 mmap.ACCESS_READ )

Then you can use
mapping.rfind( os.linesep )
to find the end of the but last line and so on.

This is very fast, because nearly all work is done by are rfind, which
is implemented in C and the OS' paging logic.

HTH,
Gerald

[EMAIL PROTECTED] schrieb:
 Mike Meyer wrote:
 
It would probably be more efficient to read blocks backwards and paste
them together, but I'm not going to get into that.

 
 That actually is a pretty good idea. just reverse the buffer and do a
 split, the last line becomes the first line and so on. The logic then
 would be no different than reading from beginning of file. Just need to
 keep the last half line of the reversed buffer if the wanted one
 happens to be across buffer boundary.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-08 Thread Antoon Pardon
Op 2005-12-07, Zeljko Vrba schreef [EMAIL PROTECTED]:
 On 2005-12-07, Antoon Pardon [EMAIL PROTECTED] wrote:

 What I don't understand is, that most people who have a problem
 with scope by indentation, want to introduce braces. I think
 braces are the worst solution.

 Braces are very convenient to match block start and end.

Other conventions can be just as convenient.

 Open a C program
 in the VI editor, and press % in command mode on some brace.. It will take
 you to its matching brace. How do you do something like that with python code
 (or any code that is based purely on indentation..)

Not my problem, since I don't suggest pure indentation is the way to go.

I just think braces are the worst solution for it, as python is
concerned.

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-08 Thread Antoon Pardon
Op 2005-12-07, Steven D'Aprano schreef [EMAIL PROTECTED]:
 On Wed, 07 Dec 2005 15:26:59 +, Zeljko Vrba wrote:

 Braces are very convenient to match block start and end. Open a C program
 in the VI editor, and press % in command mode on some brace.. It will take
 you to its matching brace. How do you do something like that with python code
 (or any code that is based purely on indentation..)

 (1) You don't need to, because you can *see* where the indentation
 changes, so you don't need to rely on your editor counting for you.

But you can't alway easily discern by how much.

 (2) And if you do need to, then you should use a smarter editor that
 understands indentation levels, not just braces.

 Braces are superfluous if you use consistent indentation, and indentation
 is superfluous -- to the compiler -- if you use braces. But indentation is
 *not* superfluous to the human eye: we can parse indentation very easily,
 but nested braces/brackets only with great difficulty. That's why
 programmers in languages that ignore indentation still indent their code,
 or at least the sensible ones do.

But sometimes you mess up and your code is no longer indented as it
should. If you marked the end of the indentations, you can easily 
correct this.

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


Re: sql escaping module

2005-12-08 Thread Tim Roberts
David Bear [EMAIL PROTECTED] wrote:

Being new to pgdb, I'm finding there are lot of things I don't understand
when I read the PEP and the sparse documentation on pgdb.

I was hoping there would be a module that would properly escape longer text
strings to prevent sql injection -- and other things just make sure the
python string object ends up being a properly type for postgresql. I've
bought 3 books on postgresql and none of th code samples demonstrate this.

All of the Python database modules will do this protection for you.
Example:

   db = psycopg2.connect(database='dbname')
   c = db.cursor()
   c.execute( INSERT INTO table1 VALUES (%s,%s,%s);, (var1, var2, var3) )

Note that I have used a comma, not the Python % operator, and I have not
done any quoting in the query.  By doing that, I am instructing the
database module to do whatever protective quoting may be required for the
values I have passed, and substitute the quoted values into the string.

As long as you use that scheme, you should be safe from injection.  It's
only when people try to do it themselves that they get in trouble, as in:

   c.execute( INSERT INTO table1 VALUES ('%s','%s','%s'); % (var1, var2,
var3) )   # THIS IS WRONG

-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: hi i have some doubts on a volume and the file system

2005-12-08 Thread Tim Golden
[EMAIL PROTECTED]

 i want to check the position of a volume in a particular 
 drive. say for example in a disk i have 3 different drives: 
 C:\ , D:\  and E:\.
 Now if i want to check what position is the D:\ in, how 
 can i write the code. Means whether its in a 0th position 
 or 1st position or a 2nd position.
 Is there any way using win32api or win32com.

 if i want to check a particular volume is a logical, or a primary one
,
 what is the method i have to use? does it can also be done through
 win32api.

Well, this page suggests that it's possible using WMI:

http://www.microsoft.com/technet/scriptcenter/resources/qanda/may05/hey0
523.mspx

and, using the WMI module from here:

http://timgolden.me.uk/python/wmi.html

this bit of code seems to give you what you want. 

code
import wmi
c = wmi.WMI ()

for physical_disk in c.Win32_DiskDrive ():
  for partition in physical_disk.associators
(Win32_DiskDriveToDiskPartition):
for logical_disk in partition.associators
(Win32_LogicalDiskToPartition):
  print physical_disk.Caption, partition.Caption,
logical_disk.Caption

/code

Obviously, I've just printed the Caption, but you could pick up whatever

information you wanted from the disk, partition  logical_disk objects.
If you just print the object itself, it will give you all its fields 
and values.

By the way, thanks for the question. I've never come across a meaningful
example of WMI associators before, although I've had the code in the
module since the first version.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: python24.dll and encodings ?

2005-12-08 Thread Martin v. Löwis
Bugs wrote:
 I believe I read in a relatively recent thread that the reason 
 python24.dll is so large compared to previous releases is that all the 
 language encodings are linked into the library?

Not only that (but also). In addition, it also contains modules that
were previously implemented as separate .pyd files (_csv, _sre,
_symtable, _winreg, datetime, mmap, parser).

 Are there any plans for future releases to split the encodings out so 
 that, for example, if someone wanted to make a smaller executable using 
 py2exe without all the language encodings, they could do so?

I previously said that I would do such a thing if somebody provided a
specification other than split out the encodings. I.e. write a PEP
that specifies how to determine whether an extension module should be
included into pythonxy.dll, and when it should not; this specification
should allow to reason about modules that haven't yet been contributed.

The PEP should be accompanied with an implementation, i.e. a set of
patches to PCbuild.

Then, the patch should be discussed, and find support in the community.

 I suppose one could always compile their own version of the python24.dll 
 but for those of us that are compiler-challanged, splitting out the 
 encodings would be nice.
 
 Is that even feasible?

Technically, yes. However, somebody needs to take the lead.

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


Re: Documentation suggestions

2005-12-08 Thread Ben Sizer
[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  I suspect I'd have a harder time living without the sys module than with
  many of the builtins.  Then there's os, re, math, ...  Some modules, like
  thread and sys, have to be linked into the interpreter.  Are they core or
  add on?  Once you start migrating stuff from the add on manual (Library
  Reference) to the core manual (Language Reference), where do you stop?

 I think a natural dividing line is import.  If you import it, it
 is in the Library refrence.

Exactly. I'm surprised this is even open to debate. Any built-in which
will work without an import statement - no matter how it's implemented
- should be documented as if it was part of the core language. And
anything you have to explicitly ask for using import, should be in the
library reference under the name of the module or package you're
importing. In terms of knowing where to look for information on a
feature, this is the most sensible approach. In no other language would
I look to the library reference for something which does not appear on
the surface to come from a library.

As an aside, personally I rarely touch the sys module. I use re,
random, threading, and even xml.dom.minidom more than sys.

-- 
Ben Sizer

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


pyparsing with nested table

2005-12-08 Thread astarocean
using pyparsing to deal with nested tables , wanna keep table's
structure and propertys .
but program was chunked with the /td tag of inner table.

have any ideas?

here's the program


from pyparsing import *

mytable = 
table id=leftpage_table width=156 border=0 cellspacing=0
cellpadding=0
  tr id=trtd height=24
td width=153 background=images/bt_kind.gif align=center
class=left_menusystem/td
  /tr
  tr id=trtd_down height=20
td id=trtd_downtable id=inner_lefgpage_table width=100%
height=100% border=0 cellspacing=0 cellpadding=0
tr id=inner_trtd height=20
  td background=images/bt_class.gif align=centerart/td
/tr
tr
  td background=images/bt_class.gif align=centerart/td
/tr
  /table/td
  /tr
/table


startTag = Literal()
endTag = Literal()
idPattern = CaselessLiteral(id).suppress() + Literal(=).suppress()
+ ( quotedString.copy().setParseAction( removeQuotes ) |
Word(srange([a-zA-Z0-9_~])))
attrPattern = Combine(Word(alphanums + _) + Literal(=) + (
quotedString | Word(srange([a-zA-Z0-9_~:@#;?/\.]

tablePattern = Forward()
def getItemCloseTag(x):
itemCloseTag = Combine(startTag + Literal(/) + CaselessLiteral(x)
+ endTag).suppress()
return itemCloseTag
def getItemStartTag(x):
itemStartTag = startTag.suppress() +
Keyword(x,caseless=True).suppress() + Group(ZeroOrMore(idPattern)) +
Group(ZeroOrMore(attrPattern)) + endTag.suppress()
return itemStartTag
def getItemPattern(x):
tCloseTag = getItemCloseTag(x)
itemPattern = getItemStartTag(x) + Group(ZeroOrMore(tablePattern))
+ Group(SkipTo(tCloseTag)) + tCloseTag
return itemPattern
def getMultiLevelPattern(x,y):
tCloseTag = getItemCloseTag(x)
itemPattern = getItemStartTag(x) + Group(OneOrMore(y)) + tCloseTag
return itemPattern

tdPattern = getItemPattern(x='td')
trPattern = getMultiLevelPattern('tr',tdPattern)
tablePattern = getMultiLevelPattern('table',trPattern)
t = tablePattern
for toks,strt,end in t.scanString(mytable):
print toks.asList()


OutPut:
[['leftpage_table'], ['width=156', 'border=0', 'cellspacing=0',
'cellpadding=0'], [['trtd'], ['height=24'], [[], ['width=153',
'background=images/bt_kind.gif', 'align=center',
'class=left_menu'], [], ['system']], ['trtd_down'], ['height=20'],
[['trtd_down'], [], [], ['table id=inner_lefgpage_table width=100%
height=100% border=0 cellspacing=0 cellpadding=0\ntr
id=inner_trtd height=20\n  td
background=images/bt_class.gif align=centerart']], [], [], [[],
['background=images/bt_class.gif', 'align=center'], [], ['art'

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


Re: Is Python string immutable?

2005-12-08 Thread Steve Holden
Frank Potter wrote:
 Thank you very much.
 Steve Holden, I post my soucecode at my blog here:
 http://hiparrot.wordpress.com/2005/12/08/implementing-a-simple-net-spider/ 
 http://hiparrot.wordpress.com/2005/12/08/implementing-a-simple-net-spider/
 I wish you can read and give me some suggestion.
 Any comments will be appreciated.
 
Before any intensive scrutiny of the code perhaps you can answer a few 
questions.

1. Are you absolutely sure you have published the code you are running? 
The code you reference has indentation problems that give syntax errors.

2. Why do you continually create new threads when you could have a fixed 
set of threads sharing a list of URLs to scan?

3. What steps have you taken to ensure that the program does indeed 
perform according to its specifications?

It seems to me that this code is a Java program transliterated into 
Python. A more natural way to express the algorithm would be for a 
number of worker threads to share  Queue.Queue of URLs to be visited. 
The only other data structure that would then need locking would be a 
dictionary of URLs that had already been considered.

Overall you appear to be spending large amounts of time locking and 
unlocking things, and creating threads unnecessarily, but you don't 
claim that the algorithm is particularly refined, and it shouldn;t 
affect memory usage.

However, I would like to be sure that the excessive memory usage *is* 
indeed something to do with your program, as I contend, and not some 
buggy aspect of threading, so I await your answers with interest.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Mutability of function arguments?

2005-12-08 Thread bruno at modulix
ex_ottoyuhr wrote:
 I'm trying to create a function that can take arguments, say, foo and
 bar, and modify the original copies of foo and bar as well as its local
 versions -- the equivalent of C++ funct(foo, bar).

This is already what you have. In Python, all you have are references to
objects, there is no local version.

 I've looked around on this newsgroup and elsewhere, and I gather that
 this is a very common concern in Python, but one which is ordinarily
 answered with No, you can't. Neat, huh? 

Pardon ???

 def appendToList(aList, aValue):
... aList.append(aValue)
...
 mylist = range(10)
 mylist
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 appendToList(mylist, 42)
 mylist
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 42]


Now the usual considerations apply :
- rebinding an arg has of course only local effect
- immutable objects are still immutables

Also note that since
1/ Python as a good support for exception handling
2/ a function can return multiple values [1],
there is less need for such constructs than in C or C++.

[1] the truth is that the function can return a unique tuple, that can
be unpacked as any other.

-- 
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: Bitching about the documentation...

2005-12-08 Thread Steve Holden
Michael Spencer wrote:
[...]
 Allowing quotation, almost anything is possible, e.g.,
 
 
 Fred! Where Guido had had had, Had had had had had.  Had had had a 
 better 
 effect on the reader
 
 or simply
 
 fred, where Guido had had had had had had had had had had, had a better
 effect on the reader
 
 M
 
All this remind me about the Member of Parliament who was required to 
apologise for calling one of his opposite numbers a liar. He did so by 
reading out the statement

I called the Honorable member a liar it is true and I am sorry for it, 
adding that the Honorable member could insert the punctuation wherever 
he so chose.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: pyparsing with nested table

2005-12-08 Thread Paul McGuire

astarocean wrote:
 using pyparsing to deal with nested tables , wanna keep table's
 structure and propertys .
 but program was chunked with the /td tag of inner table.

 have any ideas?

 here's the program


 from pyparsing import *
   ... snip ...

 tablePattern = Forward()
   ... snip ...
 tablePattern = getMultiLevelPattern('table',trPattern)
 t = tablePattern
 for toks,strt,end in t.scanString(mytable):
 print toks.asList()


Load Forward's with '' instead of '='.  Change:
  tablePattern = getMultiLevelPattern('table',trPattern)
to:
  tablePattern  getMultiLevelPattern('table',trPattern)

I think that is all you needed.

Awesome job!  (Also check out the pyparsing built-ins for making HTML
and XML tags.)

-- Paul

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


Re: what's wrong with lambda x : print x/60,x%60

2005-12-08 Thread Steve Holden
Steven D'Aprano wrote:
 On Wed, 07 Dec 2005 10:59:09 +0100, Sybren Stuvel wrote:
[...]
 But then you have all these small functions lying around in your module.
 If you intend to use them multiple times, then obviously you should
 keep them. But if they are intended to be used once, and once only, it
 seems bad to leave them there tempting fate.
 
 E.g. you have some code that uses a large lookup table. Rather than type
 the lookup table in by hand, you write a function which creates all or
 part of it. Once the lookup table is created, you shouldn't use that
 function again -- at best it is just sitting around like a third wheel,
 at worst it might have side-effects you don't want. So I del the function.
 
 The logic seems impeccable to me, and yet somehow deleting them after they
 are used feels ... not so much wrong, as just ... worthy of a
 head-scratching. 
 
 
In cases like this you would be like the law, and not concern yourself 
with trifles. In the majority of cases it costs you more to think about 
this and do the typing than it saves.

I've no objection to the practice when it makes a difference, but ask 
yourself how many bytes you are saving by allowing the code for that 
function to be collected.

Having said this, neither do I have any objection to your continuing to 
anally tidy up your namespace, but then I'm a slob whose partner is a 
neat freak, so I'm well used to accommodating the unnecessary.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: sql escaping module

2005-12-08 Thread Frank Millman
David Bear wrote:
 Being new to pgdb, I'm finding there are lot of things I don't understand
 when I read the PEP and the sparse documentation on pgdb.

 I was hoping there would be a module that would properly escape longer text
 strings to prevent sql injection -- and other things just make sure the
 python string object ends up being a properly type for postgresql. I've
 bought 3 books on postgresql and none of th code samples demonstrate this.

 web searchs for 'python sql escape  string' yeild way too many results.

 Any pointers would be greatly appreciated.


I think I know where David is coming from, as I also battled to
understand this. I think that I have now 'got it', so I would like to
offer my explanation.

I used to think that each DB-API module transformed the 'string +
parameters' into a valid SQL command before passing it to the db.
However, this is not what is happening.

Every modern database provides an API to allow applications to interact
with the database programmatically. Typically these are intended for C
programs, but other languages may be supported. The authors of the
various DB-API modules provide a python wrapper around this to allow
use from a python program.

Each of the API's includes the capability of passing commands in the
form of 'string + parameters' directly into the database. This means
that the data values are never embedded into the SQL command at all,
and therefore there is no possibility of injection attacks.

The various API's use different syntaxes for passing the parameters. It
would have been nice if the DB-API had specified one method, and left
it to the author of each module to transform this into the form
required by the underlying API. Unfortunately the DB-API allows a
choice of 'paramstyles'. There may be technical reasons for this, but
it does make supporting multiple databases awkward.

Frank Millman

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


Re: what's wrong with lambda x : print x/60,x%60

2005-12-08 Thread Steve Holden
Paul Rubin wrote:
 Steve Holden [EMAIL PROTECTED] writes:
 
All joking aside, when I have names (temporary variables or scaffolding
functions) that I need to initialise a module or data structure, but then
outlive their usefulness, I del the name afterwards. Am I the only one? I
can't say I've seen anyone else doing that, and it feels icky to me (for
no reason I can put my finger on) -- what do others think?
 
 
 I do that too sometimes.  I think it's a Python weakness that you
 can't declare a local var like in other languages, to go out of scope
 at the end of the current block, e.g.:
 
   if cond:
 my x = 7# make a new scope for x, goes out of scope at end of if
 
If this genuinely troubles you then you can always isolate the scope 
with a function, though of course you also no longer have the code 
inline then.

 
I don't generally speaking see the point: unless the name is
referencing something potentially large (like the results of a
database query) and won't be going out of scope soon (which typically
happens at the end of the current method or function) I just leave it
to happen automatically. If it doesn't happen (because the name exists
at module scope) thwn what the heck.
 
 
 Well, that makes the code a little bit confusing.  If you say
 
x = some_intermediate_result(...)
do_something_with (x)
 
 do you know for sure whether x will be needed again?

Yes.

 Are you sure you
 didn't use the name x further up in the function for something that's
 still needed?
 
Yes. Of course, otherwise I wouldn't have used it here, would I? 
Meaningful names are the biggest help in avoiding errors like this. Are 
you trying to suggest my memory's going? ;-)

 This is one of the areas where there's tension between Python the
 scripting language, that gains by saving a few keystrokes when
 throwing together a quick hack, and Python the language for developing
 long-lasting applications that have to be maintained by multiple people.
 
 In Haskell you can even have temporary variables inside an expression:
 
x = y + y*y + 3 where y=5
 
 sets x to 33.  I believe (not absolutely sure) that the scope of y is
 limited to that expression.

Well, as warts go the inability to tightly control the scope of 
variables isn't really that terrible, is it?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: first post: new to pythong. some questions.

2005-12-08 Thread Simon Brunning
On 12/8/05, shawn a [EMAIL PROTECTED] wrote:
 Hello. Im brand new to this list and to python.  Ive recently started
 reading about it
   and am now in the tinkering stage.

Welcome to Python!

  I have a script im working on that i
 need some
  asistance debugging. Its super small and should be a snap for you gurus =)

  I have 2 files in a dir off my home dir:
  mkoneurl.py
  make_ou_class.py

  --mkoneurl.py--
  #! /usr/bin/env python

  import make_ou_class

  run = makeoneurl()

You need:

run = make_ou_class.makeoneurl()

See http://docs.python.org/tut/node8.html for why.

(BTW, you would probably have got more of a response with a better
subject line. http://www.catb.org/~esr/faqs/smart-questions.html is
worth a read.)

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


Re: sql escaping module

2005-12-08 Thread Fredrik Lundh
Frank Millman wrote:

 Each of the API's includes the capability of passing commands in the
 form of 'string + parameters' directly into the database. This means
 that the data values are never embedded into the SQL command at all,
 and therefore there is no possibility of injection attacks.

another advantage with parameters is that if you do multiple operations which
differ only in parameters, the database may skip the SQL compilation and query
optimization passes.

 The various API's use different syntaxes for passing the parameters. It
 would have been nice if the DB-API had specified one method, and left
 it to the author of each module to transform this into the form
 required by the underlying API. Unfortunately the DB-API allows a
 choice of 'paramstyles'. There may be technical reasons for this, but
 it does make supporting multiple databases awkward.

agreed.

on the other hand, it shouldn't be that hard to create a function does this 
mapping
on the fly, so that drivers can be updated support any paramstyle...  time for 
a DB
API 3.0 specification, perhaps ?

(I'd also like to see a better granularity; the current connection/cursor model 
is a
bit limited; a connection/cursor/query/result set model would be nicer, but I 
guess
ODBC gets in the way here...)

/F 



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


Re: Another newbie question

2005-12-08 Thread John Bushnell
I think that's supposed to be [(i + j) % 2] for the index to the
(green,red) tuple
(since i*8 is always even).

[EMAIL PROTECTED] wrote:
 Mike,

 Thanks for your insight. It has been a big help.

 I guess I was trying to learn too much with my original code. Trying to
 implement inheritance, object creation, calling methods via inheritance
 made the code harder than it needed to be.

 I'm off to study the code. (Hmm.. how does python parse (green,
 red)[(i * 8 + j) % 2]  command ... he says while reaching for python
 for the semi-illiterate  ...)

 Again, thanks for your help.


 Jpl


 Mike Meyer wrote:
  solaris_1234 [EMAIL PROTECTED] writes:
 
   1)  The stmt board.Blist[10].DrawQueen(board.Blist[10].b1) seems
   awkward. Is there another way (cleaner, more intuitive) to get the
   same thing done?
 
  Yes. Reaching through objects to do things is usually a bad idea. Some
  languages don't allow you to do that at all; they require you to
  provide methods for manipulating the state of the object For instance,
  you can extend your MyBoard class with an extra method:
 
 def DrawQueen(self, cell):
 square = self.Blist[cell]
 square.DrawQueen(square.b1)
 
 
  And then those two lines become:
 
  board.DrawQueen(10)
  board.DrawQueen(22)
 
  Except that's still ugly - you probably want something like
  board.DrawQueen(1, 2).
 
  Basically, Blist should be part of MyBoards implementation, not a
  visible attribute. You should define methods for MyBoard that let
  clients manipulate the board, without needing to know how it's
  represented internally.
 
  Along the same lines, why does MyBoard inherit from MyBox? It's not
  using any of the features of MyBox. The code still works if you don't
  do that. And why do you pass instances of Cavnas to the methods of
  MyBox - it's got a canvas already! Do you really expect a MyBox to
  draw onto Canvases other than it's own (if so, that's a bad design as
  well).
 
  Here's an updated version of your code. I've used the convention of an
  _ prefix on attributes to indicate implementation details, and made
  the classes inherit from object, as well as using box instead of
  b1, and changed the interface to MyBoard squares to use standard
  2d-array indexing instead of forcing the clients to do array
  index calculations. You may have a good reason for doing these things
  that doesn't appear in your code fragment, but I consider these to be
  improvements in the fragment.
 
  Hmm. b1 seems to indicate that you will eventually have more than
  one canvas, which is why you passed in the canvas? In which case, the
  distinguishing feature would be the number (or mabye the b1). In
  that case, have your clients pass in the number (or name), and look up
  the canvas in an internal structure.
 
  mike
 
  from Tkinter import *
  import time
  totalSolutionCount = 0
 
  class MyBox(object):
 def __init__(self, myC, myrow, mycolumn, color):
self._box = Canvas(myC, background=color, width=50, height=50)
self._box.grid(row=myrow, column=mycolumn)
self.occupied = False
 
 def ChangebgColor(self):
self._box.config(bg=black)
 
 def DrawQueen(self):
self._box.item = self._box.create_oval(4,4,50,50,fill=black)
self.occupied = True
self._box.update()
 
 def unDrawQueen(self):
self._box.delete(self._box.item)
self.occupied = False
self._box.update()
 
  class MyBoard(object) :
 def __init__(self, myC):
self._blist = {}
for i in range(8):
   for j in range(8):
   self._blist[i, j] = MyBox(myContainer, i, j,
  (green, red)[(i * 8 + j) % 2])
 def DrawQueen(self, i, j):
 square = self._blist[i, j]
 square.DrawQueen()
 
 def occupied(self, i, j):
 return self._blist[i, j].occupied
 
 
  root=Tk()
  myContainer = Frame(root)
  myContainer.pack()
 
  board=MyBoard(myContainer)
 
  board.DrawQueen(1, 2)
  board.DrawQueen(2, 6)
 
  raw_input()  # A Hack debug statement
 
  for i in range(8):
  for j in range(8):
  if board.occupied(i, j):
  print %d, %d is occupied % (i, j)
 
  raw_input()  # A Hack debug statement
  print \n*3
 
 
 
 
  --
  Mike Meyer [EMAIL PROTECTED]  
  http://www.mired.org/home/mwm/
  Independent WWW/Perforce/FreeBSD/Unix consultant, email for more 
  information.

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


Re: ElementTree - Why not part of the core?

2005-12-08 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
 ElementTree on the other hand provides incredibly easy access to XML
 elements and works in a more Pythonic way.  Why has the API not been
 included in the Python core?

I'd really like to see that too. Sure, it's fairly trivial to install
it, but each different package that needs to be installed from another
source, built and tested on multiple platforms etc, means more work.
For complex software systems, these kinds of configuration issues
take a lot of efforts.

We're deploying our software on a number of different platforms. We
certainly depend on Python, so a standard Python install will always
be included. Using standard library modules is for free. Using yet
another third party library has a cost, even if some Cheese Shop or
whatever might make the cost slightly lower.

We have very friendly configuration management guys here, so if I
insisted, I'm sure they'd let me have elementTree included, but I
hesitate to ask for it. It does add a burden on CM, increases the
risk that a deployment will fail, and from a code maintenance point
of view, it's a double edged sword: On one hand, it's a much better
API, but on the other hand, it's not documented in the standard
Python docs or in the Nutshell book, and a new developer would need
to figure out what this foreign beast was, and where to find docs.
(Alternatively, I'd have to (God forbid) document my actions. ;)


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


spawnle umask

2005-12-08 Thread Yves Glodt
Hi,

I tried something like this but the umask part does not work clearly...:

newpid = 
os.spawnle(os.P_NOWAIT,'/usr/bin/touch','/usr/bin/touch','xyz','umask 0113')

What would be the correct syntax for setting the umask for the created 
process...?


Best regards,
Yves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mutability of function arguments?

2005-12-08 Thread Kent Johnson
Mike Meyer wrote:
 ex_ottoyuhr [EMAIL PROTECTED] writes:
 
I'm trying to create a function that can take arguments, say, foo and
bar, and modify the original copies of foo and bar as well as its local
versions -- the equivalent of C++ funct(foo, bar).
 
 
 C++'s '' causes an argument to be passed by reference. Python does
 that with all arguments. Any changes you make to the argument in the
 function will be seen in the caller unless you explicitly make a copy
 to pass.

I would say, from the point of view of a C++ programmer, Python passes 
references by value. In other words if you think of variables as 
pointers (references) to values, and function call as passing the 
reference by value, the behaviour of Python makes sense.

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


Re: newbie Q on sdtin word completion

2005-12-08 Thread Fredrik Lundh
Bernd wrote:

 I'm on a Linux env and try to get
 word completion form sdtin done,
 like Perl's
  $stdin = Complete( \t: , @choices );

 What I have so far shows me the directory listing
 on the second hit on TAB and not the list of
 choices on the first like I wanted to have.

your completer function is called with a prefix and an index.  for each
completion request, readline will call this function repeatedly, with in-
creasing indices.  for each call, you should return the corresponding
match, or None if there are no more matches.

the second example on this page might help:

http://effbot.org/librarybook/readline.htm

/F 



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


Re: spawnle umask

2005-12-08 Thread Fredrik Lundh
Yves Glodt wrote:

 I tried something like this but the umask part does not work clearly...:

 newpid =
 os.spawnle(os.P_NOWAIT,'/usr/bin/touch','/usr/bin/touch','xyz','umask 0113')

 What would be the correct syntax for setting the umask for the created
 process...?

not sure, but something like

try:
old_mask = os.umask(0113)
newpid = os.spawnle(...)
finally:
os.umask(old_mask) # restore

might work.

/F 



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


Re: spawnle umask

2005-12-08 Thread Yves Glodt
Fredrik Lundh wrote:
 Yves Glodt wrote:
 
 I tried something like this but the umask part does not work clearly...:

 newpid =
 os.spawnle(os.P_NOWAIT,'/usr/bin/touch','/usr/bin/touch','xyz','umask 0113')

 What would be the correct syntax for setting the umask for the created
 process...?
 
 not sure, but something like
 
 try:
 old_mask = os.umask(0113)
 newpid = os.spawnle(...)
 finally:
 os.umask(old_mask) # restore
 
 might work.

It does, I did like this:

os.umask(0113)
newpid = 
os.spawnl(os.P_NOWAIT,'/usr/local/bin/wine','/usr/local/bin/wine',executable)

But I wanted to use spawnle and it's env argument, to avoid setting 
umask manually...

regards,
Yves


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


Re: ElementTree - Why not part of the core?

2005-12-08 Thread Fredrik Lundh
Magnus Lycka wrote:

 We're deploying our software on a number of different platforms. We
 certainly depend on Python, so a standard Python install will always
 be included. Using standard library modules is for free. Using yet
 another third party library has a cost, even if some Cheese Shop or
 whatever might make the cost slightly lower.

 We have very friendly configuration management guys here, so if I
 insisted, I'm sure they'd let me have elementTree included, but I
 hesitate to ask for it. It does add a burden on CM, increases the
 risk that a deployment will fail, and from a code maintenance point
 of view, it's a double edged sword: On one hand, it's a much better
 API, but on the other hand, it's not documented in the standard
 Python docs or in the Nutshell book, and a new developer would need
 to figure out what this foreign beast was, and where to find docs.
 (Alternatively, I'd have to (God forbid) document my actions. ;)

on the other hand, you can bundle ElementTree with your applications simply
by including the ElementTree.py and (optionally) the ElementPath.py modules.

(you are allowed to add new Python modules to the project, I hope ;-)

(and yes, HTML documentation is included in the source distribution kit)


but seriously, given how easy it is to build things with distutils, I don't 
think your
configuration folks would have much trouble adding support for anything that 
has
a setup file, and is reasonably self-contained to their build scripts.

we usually use one large shell script with a bunch of cd source; run setup 
install
sections in it, e.g.

cd $PREFIX
cd src/griblib-2.1.1-20051125
$PYTHON setup.py install --prefix=$PREFIX

plus a Python script that does a sanity check at the end to make sure that the 
build
script actually managed to build and install everything we need.  running the 
regression
test suite on the build is a good way to weed out build problems too; just make 
sure
you redirect the build output to a file, so you can check the logs afterwards.

all source kits are checked into the version management system, of course.  no 
tarballs
are involved in the build process.  just check things out and run the script, 
wait a couple
of minutes, and you're done.

/F 



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


Re: sql escaping module

2005-12-08 Thread Steve Holden
Fredrik Lundh wrote:
 Frank Millman wrote:
 
 
Each of the API's includes the capability of passing commands in the
form of 'string + parameters' directly into the database. This means
that the data values are never embedded into the SQL command at all,
and therefore there is no possibility of injection attacks.
 
 
 another advantage with parameters is that if you do multiple operations which
 differ only in parameters, the database may skip the SQL compilation and query
 optimization passes.
 
 
The various API's use different syntaxes for passing the parameters. It
would have been nice if the DB-API had specified one method, and left
it to the author of each module to transform this into the form
required by the underlying API. Unfortunately the DB-API allows a
choice of 'paramstyles'. There may be technical reasons for this, but
it does make supporting multiple databases awkward.
 
 
 agreed.
 
indeed. I suspect (not having been involved in the decisions) that the 
variations were to minimise the work module implementers had to do to 
get their modules working.

 on the other hand, it shouldn't be that hard to create a function does this 
 mapping
 on the fly, so that drivers can be updated support any paramstyle...  time 
 for a DB
 API 3.0 specification, perhaps ?
 
It would be a little tricky to convert name-based (named and 
pyformat, requiring a data mapping) parameterizations to positional 
ones (qmark, numeric and format, requiring a data sequence) and 
vice versa. It's probably a worthwhile effort, though.

 (I'd also like to see a better granularity; the current connection/cursor 
 model is a
 bit limited; a connection/cursor/query/result set model would be nicer, but I 
 guess
 ODBC gets in the way here...)
 
Yes, it would at least be nice to include some of the more advanced ways 
of presenting query results.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


How to get the extension of a filename from the path

2005-12-08 Thread Lad
Hello,
what is a way to get the the extension of  a filename from the path?
E.g., on my XP windows the path can be
C:\Pictures\MyDocs\test.txt
and I would like to get
the the extension of  the filename, that is here
txt


I would like that to work on Linux also
Thank you for  help
L.

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


Re: ElementTree - Why not part of the core?

2005-12-08 Thread Fuzzyman

Fredrik Lundh wrote:
 Steven Bethard wrote:

   ElementTree on the other hand provides incredibly easy access to XML
   elements and works in a more Pythonic way.  Why has the API not been
   included in the Python core?
 
  While I fully agree that ElementTree is far more Pythonic than the
  dom-based stuff in the core, this issue has been discussed on
  python-dev[1].  Fredrik Lundh's response:
 
   shipping stable versions of ElementTree/cElementTree (or PIL, or
   python-doc, or exemaker, or what else you might find useful) with
   official Python releases is perfectly okay.
 
   moving the main trunk and main development over to the Python CVS is
   another thing, entirely.
 
  I think some people were hoping that instead of adding these things to
  the standard library, we would come up with a better package manager
  that would make adding these things to your local library much simpler.

 I still hope that the standard distribution will, in a not too distant future,
 bundle more external libraries.  as things are today, including something
 in the core means that you have to transfer code and rights to the PSF.

 as I've said many times, if the Linux folks can build distributions that con-
 sists of thousands of individually maintained pieces, the Python distributors
 should be able to handle a few dozen components.


I'd like to add my vote in favour of this.

There are a few popular extensions that most users would like easy
access to. PIL and ElementTree both fall into this category.

Thanks

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

 /F

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


Re: How to get the extension of a filename from the path

2005-12-08 Thread Dale Strickland-Clark
Lad wrote:

 Hello,
 what is a way to get the the extension of  a filename from the path?
 E.g., on my XP windows the path can be
 C:\Pictures\MyDocs\test.txt
 and I would like to get
 the the extension of  the filename, that is here
 txt
 
 
 I would like that to work on Linux also
 Thank you for  help
 L.

Like this, you mean?
 import os.path
 os.path.splitext(c:\\pictures\\mydocs\\test.txt)
('c:\\pictures\\mydocs\\test', '.txt')

-- 
Dale Strickland-Clark
Riverhall Systems www.riverhall.co.uk


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


Re: ElementTree - Why not part of the core?

2005-12-08 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote:

 I think some people were hoping that instead of adding these things
 to
 the standard library, we would come up with a better package manager
 that would make adding these things to your local library much
 simpler.

 STeVe


[1]http://www.python.org/dev/summary/2005-06-01_2005-06-15.html#reorganising-th
e-standard-library-again

 A better package manager would be great but does not
 replace having things in the core.  Distributed code that
 relies on external packages puts a significantly greater
 burden on the user of the code.

Seconded.

One thing I really fear about the otherwise great EasyInstall (and Python Eggs)
is that we could forget about


Let's not turn the Python standard library into the CPAN mess, where there are
5 different libraries for adding two numbers, so that it's then impossible to
grab a random perl program and read it, without going through 150 different man
pages you never saw before. I don't need 450 libraries to compute MD5, or to
zip a file, or 140 different implementations of random numbers. There will
always be external libraries for specific purposes, but I'd rather the standard
library to stay focused on provided a possibly restricted set of common
features with a decent interface/implementation.

This said, I'd also like to see ElementTree in the standard library. We already
have a SAX and a DOM, but we need a Pythonic XML library, and ElementTree is
just perfect.
-- 
Giovanni Bajo


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


Re: How to get the extension of a filename from the path

2005-12-08 Thread Tom Anderson
On Thu, 8 Dec 2005, Lad wrote:

 what is a way to get the the extension of  a filename from the path?
 E.g., on my XP windows the path can be
 C:\Pictures\MyDocs\test.txt
 and I would like to get
 the the extension of  the filename, that is here
 txt

You want os.path.splitext:

 import os
 os.path.splitext(C:\Pictures\MyDocs\test.txt)
('C:\\Pictures\\MyDocs\test', '.txt')
 os.path.splitext(C:\Pictures\MyDocs\test.txt)[1]
'.txt'


 I would like that to work on Linux also

It'll be fine.

tom

-- 
[Philosophy] is kind of like being driven behind the sofa by Dr Who -
scary, but still entertaining. -- Itchyfidget
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ElementTree - Why not part of the core?

2005-12-08 Thread Giovanni Bajo
Giovanni Bajo wrote:

 One thing I really fear about the otherwise great EasyInstall (and
 Python Eggs) is that we could forget about...

... how important is to have a standard library. The fact that it's easy to
install external modules shouldn't make us drop the standard library. A
standard library means a great uniformity across programs. Whenever I open a
Python program which uses ZipFile, or socket, or re, I can read it
*immediately*. If it uses an external library / framework, I have to go study
its manual and documentation. Proliferation of external libraries is good, but
people should normally use the standard library modules for uniformity.

In other words, I disagree with this message:
http://mail.python.org/pipermail/python-dev/2005-June/054102.html

My personal hope is that Python 3.0 will have a nice cleaned-up standard
library with even more features than Python 2.x. As I said the in other
message, let's not end up into the CPAN mess just because it's now technically
easier!
-- 
Giovanni Bajo


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


Re: How to get the extension of a filename from the path

2005-12-08 Thread Fredrik Lundh
Lad [EMAIL PROTECTED] wrote:

 what is a way to get the the extension of  a filename from the path?
 E.g., on my XP windows the path can be
 C:\Pictures\MyDocs\test.txt
 and I would like to get
 the the extension of  the filename, that is here
 txt

 I would like that to work on Linux also
 Thank you for  help

os.path.splitext(filename) splits a filename into a name part (which may include
a path) and an extension part:

import os
f, e = os.path.splitext(filename)

the extension will include the separator, so the following is always true:

assert f + e == filename

if you don't want the period, you can strip it off:

if e[:1] == .:
e = e[1:]

but it's often easier to change your code to take the dot into account; instead
of

if e[:1] == .:
e = e[1:]
if e == txt:
handle_text_file(filename)
elif e in (png, jpg):
handle_image_file(filename)

do

if e == .txt:
handle_text_file(filename)
elif e in (.png, .jpg):
handle_image_file(filename)

on the other hand, for maximum portability, you can use

f, e = os.path.splitext(filename)
if e.startswith(os.extsep):
e = e[len(os.extsep):]
if e == txt:
...

but that's probably overkill...

/F 



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


Re: pyparsing with nested table

2005-12-08 Thread astarocean
Paul McGuire wrote:

 Load Forward's with '' instead of '='.  Change:
   tablePattern = getMultiLevelPattern('table',trPattern)
 to:
   tablePattern  getMultiLevelPattern('table',trPattern)

 I think that is all you needed.

 Awesome job!  (Also check out the pyparsing built-ins for making HTML
 and XML tags.)

 -- Paul

thank you ,  i was wonding why my iteraiton not functional . so it's my
fault .

later , i checked other parsers like Clientable  BeautifulSoap ,
i think with beautifulsoap doing this job is a better idea.

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


Re: How to get the extension of a filename from the path

2005-12-08 Thread gene tani

Lad wrote:
 Hello,
 what is a way to get the the extension of  a filename from the path?
 E.g., on my XP windows the path can be
 C:\Pictures\MyDocs\test.txt
 and I would like to get
 the the extension of  the filename, that is here
 txt


 I would like that to work on Linux also
 Thank you for  help
 L.

minor footnote: windows paths can be raw strings for os.path.split(),
or you can escape /
 tho Tom's examp indicates unescaped, non-raw string works with
splitext()

import os.path
# winpath='C:\\Pictures\\MyDocs\\test.txt'
winpath=r'C:\Pictures\MyDocs\test.txt'
fpath,fname_ext=os.path.split(winpath)
print path: %s   ;  fname and ext: %s%(fpath, fname_ext)
ext=fname_ext.split(.)[-1]
print ext

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


Re: ElementTree - Why not part of the core?

2005-12-08 Thread Magnus Lycka
Fredrik Lundh wrote:
 but seriously, given how easy it is to build things with distutils, I don't 
 think your
 configuration folks would have much trouble adding support for anything that 
 has
 a setup file, and is reasonably self-contained to their build scripts.

True. It's one more thing to keep track of though. It's a separate
configuration item. We need to keep track of which version to use,
and it needs to get built, installed and validated on all supported
platforms.

I already include Twisted (and thus ZopeInterface) like that. We
sometimes need high speed in XML parsing, so I'd like to use
cElementTree, but just like the two other packages, I assume that
it's unproblematic to build the included C code. So, you're right,
it's not much trouble, just two more pebbles (cElementTree and
ElementTree) on a fairly heavy load, where stuff like Oracle and MQ
Series are more like boulders.

Right now, I would like to improve the performace of a program that
does a lot of XML parsing. I haven't profiled that yet, so I don't
know if XML parsing is the bottle neck, but if I can improve perfor-
mance significantly with cElementTree, I'll certainly push for that.


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


Encoding of file names

2005-12-08 Thread utabintarbo
Here is my situation:

I am trying to programatically access files created on an IBM AIX
system, stored on a Sun OS 5.8 fileserver, through a samba-mapped drive
on a Win32 system. Not confused? OK, let's move on... ;-)

When I ask for an os.listdir() of a relevant directory, I get filenames
with embedded escaped characters (ex.
'F07JS41C.04389525AA.UPR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model')
which will read as False when applying an os.path.isfile() to it. I
wish to apply some  operations to these files, but am unable, since
python (on Win32, at least) does not recognize this as a valid
filename.

Help me, before my thin veneer of genius is torn from my boss's eyes!
;-)

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


Re: spawnle umask

2005-12-08 Thread David Wahler
Yves Glodt wrote:
 It does, I did like this:

 os.umask(0113)
 newpid =
 os.spawnl(os.P_NOWAIT,'/usr/local/bin/wine','/usr/local/bin/wine',executable)

 But I wanted to use spawnle and it's env argument, to avoid setting
 umask manually...

The umask is not part of the environment, so there's no way to set it
directly through spawnle. Why don't you want to use os.umask?

-- David

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


Re: Python and OLAP?

2005-12-08 Thread Mike Thompson
Wolfgang Keller wrote:
 Hello,
 
 does anyone know of Python modules for OLAP work? E.g. efficient 
 manipulation of large multi-dimensional structures (arrays) of arbitrary 
 (not only numeric) data?
 
 TIA,
 
 Sincerely,
 
 Wolfgang Keller
 
 


Perhaps this might be useful:

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

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


Re: efficient 'tail' implementation

2005-12-08 Thread Jerry Sievers
[EMAIL PROTECTED] writes:

 hi
 
 I have a file which is very large eg over 200Mb , and i am going to
 use python to code a tail command to get the last few lines of the
 file. What is a good algorithm for this type of task in python for
 very big files?  Initially, i thought of reading everything into an
 array from the file and just get the last few elements (lines) but
 since it's a very big file, don't think is efficient.  thanks


First of all, what makes you think that tail on your system isn't
already optinized for this?  Devil's advocate here... I have no clue
really.

Anyway, if you must roll your own;

Determine some reasonable max line size,, multiply this by a few
larger than the numbers of lines that you want to tail, seek to EOF
and then back to the position in the file where this chunk would
start, get and split that chunk into lines and now output the last 3
or however many you need.

If the read fails to hold enough lines, seek back a bit further and do
same but you'll have to be prepared to concat the second and Nth last
chunks together.

Have fun


-- 
---
Jerry Sievers   305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobilehttp://www.JerrySievers.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Documentation suggestions

2005-12-08 Thread A.M. Kuchling
On 7 Dec 2005 05:51:45 -0800, 
Iain King [EMAIL PROTECTED] wrote:
 Argh, you made me look at the html again - at least now I know *why* it
 is so disgusting.  I understand there's a new version coming out soon,
 hopefully in html 4 strict or xhtml.  I'm sure at that point it'll be
 easier to use.  I can wait. :)

A new version of LaTeX2HTML, you mean?  Can you provide a pointer?  

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


Re: ElementTree - Why not part of the core?

2005-12-08 Thread skip

 ElementTree on the other hand provides incredibly easy access to XML
 elements and works in a more Pythonic way.  Why has the API not been
 included in the Python core?

Magnus I'd really like to see that too. Sure, it's fairly trivial to
Magnus install it, but each different package that needs to be
Magnus installed from another source, built and tested on multiple
Magnus platforms etc, means more work.

More work than reimplementing the functionality or living with a miserable
API (I'm thinking normal DOM APIs)?

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


Re: ElementTree - Why not part of the core?

2005-12-08 Thread skip

 ElementTree on the other hand provides incredibly easy access to XML
 elements and works in a more Pythonic way.  Why has the API not been
 included in the Python core?

I think the key here is ElementTree's Pythoninc API.  While it's clearly
possible to install it as a third-party package, I think there's a clear
best-of-breed aspect here that suggests it belongs in the standard
distribution simply to discourage continued use of DOM-based APIs.

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


Re: Python web publishing framework like Cocoon?

2005-12-08 Thread Paul Boddie
Dan M wrote:
 Dennis Benzinger wrote:
  Is there a Python web publishing framework like Cocoon?

 How about:

[List of the usual suspects]

 just to name a few of my favorites. Take a look at
 http://wiki.python.org/moin/WebProgramming for a more complete list.

Although it is good advice to recommend the WebProgramming page,
despite my reservations about its current state, I don't think it is
particularly helpful for everyone to shout out their favourites - as
appears to be the normal practice on this topic - especially when none
of the suggestions seem to share very much architecturally or
technologically with Cocoon. Aside from Maki, which the questioner
mentioned, I'd imagine that 4Suite Server [1] might have some overlap
with Cocoon, although I've never managed to motivate myself past the
introductions/installations and actually experiment with it.

I can certainly admit that I've developed a forms toolkit [2] which
makes use of XSLT, although you won't see in it anything like the
XML-based site map configuration from Cocoon, and whilst I suppose you
could implement such things on top of my toolkit, you'll need to spend
some time replicating some of the other conveniences of Cocoon that it
seems to manage all by itself (or at least after judicious editing of
various lengthy configuration files). If the forms aspects of my
toolkit aren't interesting, you could concentrate on just using
stylesheets, although I will also admit that you could integrate
convenient stylesheet processing with just about any Web framework, and
there may be components out there which do just that.

My experiences with Cocoon suggested that although the site map concept
is rather enticing, one frequently needs to break out of the functional
programming model that it enforces in order to provide more than very
simple application logic, and I wasn't really encouraged by the Cocoon
developers chosen means of doing this (server side JavaScript), nor by
their ability to break functionality between microreleases. If you're
happy transferring the site map logic into Python - not a difficult
task - then you just need to choose a Web framework that doesn't fight
you over how you do things like URL dispatching.

Anyway, if you're interested in using XSLT with Python, speak up or get
in touch. I think it's an area which has been unfairly overshadowed by
more fashionable technologies.

Paul

[1] http://www.4suite.org/index.xhtml
[2] http://www.python.org/pypi/XSLTools

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


Dr. Dobb's Python-URL! - weekly Python news and links (Dec 7)

2005-12-08 Thread Cameron Laird
QOTW:  ... and to my utter surprise it worked. - Andrew Nagel on 
his move from wxPython to programming Tkinter in desperation

Python has more web application frameworks than keywords. - Skip
Montanaro (but probably others going back years)


Frithiof Andreas Jensen writes frankly on use of SNMP and netconf:
http://groups.google.com/group/comp.lang.python/msg/662032bf92670fd7

Perhaps your application needs something like ping.  Several
distinct ways to achieve that exist:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ced60d60b5942f1f/

You're going to hear about reddit.com, and about how it's been
REimplemented in Python.  Here's a fraction of the commentary:
http://reddit.com/blog/2005/12/night-of-living-python.html
http://www.aaronsw.com/weblog/rewritingreddit

Long discussions about Python documentation lead to no conclusion
this commentator knows how to summarize:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/767470cb3cbc24d5/

http://groups.google.com/group/comp.lang.python/browse_thread/thread/94e2e5244a90a274/

aum's pygene genetic-algorithm solver includes full api
documentation, and an implementation of the travelling
salesman problem ...:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/9901fe0f886893d6/

Jibes against the lambda-clingers lead eventually to serious
questions of style in regard to variable namespacing, 
lifespan, cleanup, and so on:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ad0e15cb6b8f2c32/

To say anything useful about IDEs apart from that one needs to
try each on for personal fit seems *very* difficult:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/eca26b6e6617a591/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf

Re: spawnle umask

2005-12-08 Thread Yves Glodt
David Wahler wrote:
 Yves Glodt wrote:
 It does, I did like this:

 os.umask(0113)
 newpid =
 os.spawnl(os.P_NOWAIT,'/usr/local/bin/wine','/usr/local/bin/wine',executable)

 But I wanted to use spawnle and it's env argument, to avoid setting
 umask manually...
 
 The umask is not part of the environment, so there's no way to set it
 directly through spawnle.

ok

  Why don't you want to use os.umask?

Only because I thought spawnle could set it through env...
But as it can't I will now go with os.umask.

thanks,
Yves

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


Re: newbie Q on sdtin word completion

2005-12-08 Thread Fischer
Thanks, exactly what I was looking for.
I should go and buy you book ;-)

Bernd

Fredrik Lundh wrote:
 Bernd wrote:
 
 
I'm on a Linux env and try to get
word completion form sdtin done,
like Perl's
 $stdin = Complete( \t: , @choices );

What I have so far shows me the directory listing
on the second hit on TAB and not the list of
choices on the first like I wanted to have.
 
 
 your completer function is called with a prefix and an index.  for each
 completion request, readline will call this function repeatedly, with in-
 creasing indices.  for each call, you should return the corresponding
 match, or None if there are no more matches.
 
 the second example on this page might help:
 
 http://effbot.org/librarybook/readline.htm
 
 /F 
 
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you create a custom QCursor in Python Qt?

2005-12-08 Thread Steegg
Thanks Phil,

Good idea, I had failed to notice these code examples and been
struggling the qt3 examples from pyqtsrc.tgz for months.

So, I found my mistake, I was using a 8*8 bitmap, I have now corrected
it and use a 16*16 bitmap (which is the standard size on Mac OS X) read
in from a PNG file created in Photoshop in bitmap mode and it works
just great.

I failed to read the C++ documentation for Qt closely enough where it
states:

 Valid cursor sizes depend on the display hardware (or the underlying
window system). We recommend using 32x32 cursors, because this size is
supported on all platforms. Some platforms also support 16x16, 48x48
and 64x64 cursors.

As a Python novice I had simply taken the bitmap that was available in
the documentation for Qbitmap, which happens to be an 8*8 bitmap.


Interestingly on my G5 iMac Mac OS X 10.4.3 running Python 2.4.1 
Qt3.3.5 QCursors of both 16*16  32*32 works perfectly; whereas on my
G4 Powerbook Mac OS X 10.4.2 running the same Python 2.4.1  Qt3.3.5, a
16*16 QCursor works but a 32*32 QCursor doesn't, but since there are no
error messages that is all that I can report. Interesting!

I have also tested my code on a PC, which supports 32*32 but does not
support
16*16.

---

I have two auxiliary questions if anybody can help me.

1: When I click on a button the cursor does not change immediately, the
cursor only actually gets re-drawn when I physically move the mouse.
Is there a way to get it to update instantaneously?
After setCursor() I call repaint(True)  but this does not have the
desired effect.

def bitmap(self):
self.setCursor(self.inlineBitmapCursor)
self.repaint(True)


2: The cursor that I want to customise is the wait cursor; under Mac OS
X this is an animated cursor displaying a wristwatch with hands that go
around?
So my question is where do I find the code that produces this effect,
is it written in C++ or Python and how can I imitate it?

Steve

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


Re: How to get the extension of a filename from the path

2005-12-08 Thread Peter Hansen
Fredrik Lundh wrote:
 on the other hand, for maximum portability, you can use
 
 f, e = os.path.splitext(filename)
 if e.startswith(os.extsep):
 e = e[len(os.extsep):]
 if e == txt:
 ...

Is there ever a time when the original `e` could evaluate True, yet not 
startswith(os.extsep)?  In other words, could the first test be just

  if e:
  e = e[len(os.extsep):]

Also, note that for truly maximum portability one probably needs to add 
to the code some knowledge of case-sensitivity and do a .lower() when 
appropriate, as txt and TXT (and others) are equivalent on Windows 
file systems.  On that note, is there a common idiom for detecting that 
information?

-Peter

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


Re: Encoding of file names

2005-12-08 Thread Peter Hansen
utabintarbo wrote:
 I am trying to programatically access files created on an IBM AIX
 system, stored on a Sun OS 5.8 fileserver, through a samba-mapped drive
 on a Win32 system. Not confused? OK, let's move on... ;-)
 
 When I ask for an os.listdir() of a relevant directory, I get filenames
 with embedded escaped characters (ex.
 'F07JS41C.04389525AA.UPR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model')
 which will read as False when applying an os.path.isfile() to it. I
 wish to apply some  operations to these files, but am unable, since
 python (on Win32, at least) does not recognize this as a valid
 filename.

I'm not sure of the answer, but note that .isfile() is not just checking 
whether the filename is valid, it's checking that something *exists* 
with that name, and that it is a file.  Big difference... at least in 
telling you where to look for the solution.  In this case, checking 
which of the two tests in ntpath.isfile() is actually failing might be a 
first step if you don't have some other lead.  (ntpath is what os.path 
translates into on Windows, so look for ntpath.py in the Python lib folder.)

If you're really seeing what you're seeing, I suspect a bug since if 
os.listdir() can find it (and it's really a file), os.isfile() should 
report it as a file, I would think.

-Peter

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


Re: efficient 'tail' implementation

2005-12-08 Thread Nick Craig-Wood
Gerald Klix [EMAIL PROTECTED] wrote:
  As long as memory mapped files are available, the fastest
  method is to map the whole file into memory and use the
  mappings rfind method to search for an end of line.

Excellent idea.

It'll blow up for large 2GB files on a 32bit OS though.
-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Documentation suggestions

2005-12-08 Thread A.M. Kuchling
On Wed, 07 Dec 2005 12:10:18 -0500, 
Kent Johnson [EMAIL PROTECTED] wrote:
 OK I'll bite. That Beginners Guide page has bugged me for a long time. 
 It's a wiki page but it is marked as immutable so I can't change it. 
 Here are some immediate suggestions:

Good suggestions; thanks!  I've applied most of them.

 - Change the sentence Read BeginnersGuide/Overview to learn the key 
 points. to Read BeginnersGuide/Overview to learn what makes Python 
 special. Or maybe get rid of it completely - I'm not sure evangelism 
 belongs on this page.

Yes, it does; fairly often the webmaster alias receives e-mails that
ask so what is Python?

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


Is there anything that pickle + copy_reg cannot serialize?

2005-12-08 Thread Maurice LING
Hi,

I need to look into serialization for python objects, including codes, 
recursive types etc etc. Currently, I have no idea exactly what needs to 
be serialized, so my scope is to be as wide as possible.

I understand that marshal is extended by pickle to serialize class 
instances, shared elements, and recursive data structures 
(http://www.effbot.org/librarybook/pickle.htm) but cannot handle code 
types. pickle can be used together with copy_reg and marshal to 
serialize code types as well 
(http://www.effbot.org/librarybook/copy-reg.htm).

So my question will be, are there anything that pickle/copy_reg/marshal 
combination cannot serialize? If so, what are the workarounds?

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


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-08 Thread Dave Hansen
On 8 Dec 2005 08:17:14 GMT in comp.lang.python, Antoon Pardon
[EMAIL PROTECTED] wrote:

[...]

I just think braces are the worst solution for it, as python is
concerned.

Agreed.  A model like Modula-2's would be much preferable, and in fact
is supported (but not enforced) today (as long as you also obey
indentation rules).  Just mark the end of your blocks with #endif,
#endfor, #endwhile, #enddef, #endclass, #endwhatever as appropriate.  

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ElementTree - Why not part of the core?

2005-12-08 Thread Jeremy Hylton
 I still hope that the standard distribution will, in a not too distant future,
 bundle more external libraries.  as things are today, including something
 in the core means that you have to transfer code and rights to the PSF.

Your description of how to include something in the core isn't entirely
accurate.  If you visit  http://www.python.org/psf/contrib.html, you'll
see that you don't need to transfer your rights to the PSF.  Rather,
you need to sign an agreement giving the PSF the rights to relicense
the code.  The PSF currently require that the original submission be
licensed under one of two open source licenses.  Personally, I can
imagine accepting a wider range of initial licenses in the future.

As for transferring the code, there needs to be a copy in the Python
source control system, sure.  There's some unavoidable complexity
involved in managing a software distribution composed of third party
software packages.  At the very least, you've got the original sources
and the copy in the distribution package, which leads to a
synchronization problem.

Jeremy

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


Re: Mutability of function arguments?

2005-12-08 Thread Mike Meyer
Kent Johnson [EMAIL PROTECTED] writes:
 Mike Meyer wrote:
 ex_ottoyuhr [EMAIL PROTECTED] writes:

I'm trying to create a function that can take arguments, say, foo and
bar, and modify the original copies of foo and bar as well as its local
versions -- the equivalent of C++ funct(foo, bar).
 C++'s '' causes an argument to be passed by reference. Python does
 that with all arguments. Any changes you make to the argument in the
 function will be seen in the caller unless you explicitly make a copy
 to pass.
 I would say, from the point of view of a C++ programmer, Python passes
 references by value. In other words if you think of variables as
 pointers (references) to values, and function call as passing the
 reference by value, the behaviour of Python makes sense.

While the description is right, the terminology is wrong, and places
the emphasis in the wrong place.

Your description of passes references by value is a description of
call by reference. C passes all arguments by value, to pass a
reference, the C programmer creates the reference to the value by
hand, then dereferences it by hand at the other end. So C's
call-by-reference passes the reference by value. There's no
difference between C's call-by-reference and Python's
call-by-reference, and using different words to try and imply there is
will just cause problems further on.

The real difference is in the way names behave in the two
languages. As you put it, variables are references to values, except
Python names don't have most of the things associated with variables
in other programming languages, so it's better to call them names. We
use bound to show that we're not copying a value over a fixed memory
location, hence names are bound to values. This is the crucial
point, and the one that need to be emphasized.

  mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the extension of a filename from the path

2005-12-08 Thread Lad
Thank you ALL for help
Regards,
L.

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


Re: Bitching about the documentation...

2005-12-08 Thread Rocco Moretti
Fredrik Lundh wrote:
 Rocco Moretti wrote:
 
 
Insert punctuation  capitalization to make the following a correct and
coherent (if not a little tourtured).

fred where guido had had had had had had had had had had had a better
effect on the reader
 
 
 punctuation, including quote marks, I presume?

Quote marks are acceptable, but no more than two words are inside each set.


B
A
D
G
E
R

.
.
.

E
R


S
P
O
I
L
E
R

W
A
R
N
I
N
G

The accepted way to do it is:

Fred, where Guido had had had, had had had had. Had had had had a 
better effect on the reader.

meaning approximately

In the place where Guido previously put the word had, Fred had 
previously put the phrase had had. Fred's choice of phrasing was more 
appreciated by the reder.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding of file names

2005-12-08 Thread Peter Otten
utabintarbo wrote:

 I am trying to programatically access files created on an IBM AIX
 system, stored on a Sun OS 5.8 fileserver, through a samba-mapped drive
 on a Win32 system. Not confused? OK, let's move on... ;-)
 
 When I ask for an os.listdir() of a relevant directory, I get filenames
 with embedded escaped characters (ex.
 'F07JS41C.04389525AA.UPR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model')
 which will read as False when applying an os.path.isfile() to it. I
 wish to apply some  operations to these files, but am unable, since
 python (on Win32, at least) does not recognize this as a valid
 filename.

Does the problem persist if you feed os.listdir() a unicode path?
This will cause listdir() to return unicode filenames which are less prone
to encoding confusion.

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


Re: efficient 'tail' implementation

2005-12-08 Thread Nick Craig-Wood
Gerald Klix [EMAIL PROTECTED] wrote:
  As long as memory mapped files are available, the fastest
  method is to map the whole file into memory and use the
  mappings rfind method to search for an end of line.

Actually mmap doesn't appear to have an rfind method :-(

Here is a tested solution using mmap using your code.  Inefficient if
number of lines to be tailed is too big.

import os
import sys
import mmap

def main(nlines, filename):
 reportFile = open( filename )
 length = os.fstat( reportFile.fileno() ).st_size
 if length == 0:
 # Don't map zero length files, windows will barf
 return
 try:
 mapping = mmap.mmap( reportFile.fileno(), length,
 mmap.MAP_PRIVATE, mmap.PROT_READ )
 except AttributeError:
 mapping = mmap.mmap(
 reportFile.fileno(),
 0, None,
 mmap.ACCESS_READ )
 search = 1024
 lines = []
 while 1:
 if search  length:
 search = length
 tail = mapping[length-search:]
 lines = tail.split(os.linesep)
 if len(lines) = nlines or search == length:
 break
 search *= 2
 lines = lines[-nlines-1:]
 print \n.join(lines)
 
if __name__ == __main__:
if len(sys.argv) != 3:
print Syntax: %s n file % sys.argv[0]
else:
main(int(sys.argv[1]), sys.argv[2])

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


Post-modernism, Academia, and the Tech Geeking fuckheads

2005-12-08 Thread Xah Lee
Post-modernism, Academia, and the Tech Geeking fuckheads

• the Sokal Affair
http://en.wikipedia.org/wiki/Sokal_Affair

• SCIGen and World Multi-Conference on Systemics, Cybernetics and
Informatics  
 http://pdos.csail.mit.edu/scigen/

• What are OOP's Jargons and Complexities, Xah Lee
 http://xahlee.org/Periodic_dosage_dir/t2/oop.html

• Politics and the English Language, George Orwell
 http://xahlee.org/p/george_orwell_english.html

 Xah
 [EMAIL PROTECTED]
 ∑ http://xahlee.org/

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

Re: Encoding of file names

2005-12-08 Thread Kent Johnson
utabintarbo wrote:
 Here is my situation:
 
 I am trying to programatically access files created on an IBM AIX
 system, stored on a Sun OS 5.8 fileserver, through a samba-mapped drive
 on a Win32 system. Not confused? OK, let's move on... ;-)
 
 When I ask for an os.listdir() of a relevant directory, I get filenames
 with embedded escaped characters (ex.
 'F07JS41C.04389525AA.UPR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model')
 which will read as False when applying an os.path.isfile() to it. I
 wish to apply some  operations to these files, but am unable, since
 python (on Win32, at least) does not recognize this as a valid
 filename.

Just to eliminate the obvious, you are calling os.path.join() with the 
parent name before calling isfile(), yes? Something like

for f in os.listdir(someDir):
   fp = os.path.join(someDir, f)
   if os.path.isfile(fp):
 ...

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


Re: JPEG decoder not available in PIL

2005-12-08 Thread Paul Dickson
On 6 Dec 2005 14:02:37 -0800, Peter wrote:

 I have a problem which seems to come up from time to time but I can't
 find anything relevant in the archives.  I have used PIL v1.1.5 with no
 problem on Windows for some time but now wish to put it on Linux (Suse
 Linux v10.0). I obtained and built the JPEG libraries (jpeg-6b) without
 any problem. The tests for the installation work fine. I built Python
 2.4.2 from the sources but with no special options, just 'out of the
 box'. This works fine. PIL built as it should but the selftest.py fails
 with the  ‘'decoder jpeg is not available'’ message (the other 54
 tests are OK). Other images are opened and shown with xv, no problem. I
 think that there is something wrong with the libraries or the way they
 linked.  

It seems you did not build the RPMs for the JPEG libraries, so the
include files were not placed in the correct location:

# rpm -ql libjpeg-devel
  ...
/usr/include/jpeglib.h
  ...

Perhaps you should try yum install libjpeg libjpeg-devel if Suse
supports yum.

-Paul

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


Re: Documentation suggestions

2005-12-08 Thread A.M. Kuchling
On Wed, 07 Dec 2005 12:58:36 -0800, 
Michael Spencer [EMAIL PROTECTED] wrote:
 I experimented with some more re-organization, but I don't see away
 to attach the resulting file in the SF comments, so I'll post it
 here instead.

I've attached your file to the patch.  Some comments:

 \input{libstruct}   % also/better in File Formats?

Struct operates on string input and produces string output, so I think
it belongs in the string chapter where you've placed it.  We need to
add more cross-references, so File Formats should mention struct as a
related module.

 % Functions, Functional, Generators and Iterators
 \input{libitertools}
 \input{libfunctional}
 \input{liboperator}   % from runtime - better with itertools and 
 functional

 % encoding stuff
  ...
 \input{libxdrlib}

XDR is really more similar to struct or marshal, I think, but on the
other hand it is an Internet RFC (#1014).   Not sure where it should go...

 \input{libsomeos}   % Optional Operating System Services
 \input{libselect}
 \input{libthread}
 \input{libthreading}
 \input{libdummythread}
 \input{libdummythreading}
 \input{libmmap}
 \input{libreadline}
 \input{librlcompleter}



 \input{libunix} % UNIX Specific Services
 \input{libposix}
 \input{libpwd}
 \input{libspwd}
 \input{libgrp}
 \input{libcrypt}
 \input{libdl}
 \input{libtermios}
 \input{libtty}
 \input{libpty}
 \input{libfcntl}
 \input{libpipes}
 \input{libposixfile}
 \input{libresource}
 \input{libnis}
 \input{libsyslog}
 \input{libcommands}
 

 \input{internet}% Internet Protocols

I wonder if the Internet chapter should be split into HTTP/Web Tools
(webbrowser, cgi, cgitb, httplib, urllib) and Non-Web Protocols
(ftplib, gopherlib, smtp, all the rest).

 \input{distutils}

Distutils should probably be in Program Frameworks.  Or it could just
have a chapter of its own, or maybe there are enough modules for an
Application Support chapter.

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


Re: Bitching about the documentation...

2005-12-08 Thread Dave Hansen
On Wed, 07 Dec 2005 12:33:07 -0600 in comp.lang.python, Rocco Moretti
[EMAIL PROTECTED] wrote:

[...]

fred where guido had had had had had had had had had had had a better 
effect on the reader

I've seen this before as

bill had had had but will had had had had had had or had had been
correct had had had

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Documentation suggestions

2005-12-08 Thread BartlebyScrivener
Andrew,

The site changes for the new-to-Python person are a big improvement in
terms of the sequence of exposures, but from a marketing perspective,
the first thing they read about Python is still aimed at a programmer.
The bulleted points in BeginnersGuide/Overview are, again, things that
are important to programmers (Automatic garbage collection frees you
from the hassles of memory management means nothing to me, even now
after reading a Python book and several tutorials).

I wish there were some sort of sexy exposure to Python before hitting
them with the download. Again you purport to be making a page for
someone who's never programmed before, so almost certainly a Windows
user. And a Windows user is not going to download any program until
he's absolutely sure it won't destabilize his fragile system or infect
it. So nobody new to programming and new to Python is going to download
at the point you present them with that opportunity. Too bad there
isn't something like what Ruby does with the Try Ruby In Your Browser
thing, which is a very effective marketing tool (although obviously I
chose Python).

http://tryruby.hobix.com/

The other thing I vividly recall struggling with was: Do I download
this Python.org version for my Windows XP machine, because it's the
official one, or do I use the one from ActiveState because others say
it comes with all sorts of goodies for Windows users? I don't know what
the politics are there, but if I were you I'd take a stand and put it
on the download page to help the new person out, who is uncertain about
what to do.

Ultimately I downloaded ActiveState because I found their site easier
to understand (again speaking as a person relatively new to programming
and absolutely new to Python).

Thanks,

rpd

I read part of it all the way through.--Samuel Goldwyn

www.dooling.com

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


Re: Documentation suggestions

2005-12-08 Thread Kent Johnson
A.M. Kuchling wrote:
 On Wed, 07 Dec 2005 12:10:18 -0500, 
   Kent Johnson [EMAIL PROTECTED] wrote:
 
OK I'll bite. That Beginners Guide page has bugged me for a long time. 
It's a wiki page but it is marked as immutable so I can't change it. 
Here are some immediate suggestions:
 
 
 Good suggestions; thanks!  I've applied most of them.

Thanks, this is a big improvement. Here are a few more ideas:

- change Next, you need to get the Python interpreter installed on your 
computer. to Next, install the Python interpreter on your computer. 
(active voice)

- move and rewrite the You'll want to select a [WWW] text editor... 
sentence. For a raw beginner, this is not the next step and the page it 
links to will not be helpful. Tutorials generally start out at the 
interpreter prompt, not writing programs in an editor. Whatever editor 
is handy and familiar is probably fine for a first program when the time 
comes. Here is a suggested rewrite:

When you are ready to write your first program you will need a text 
editor. To get started you can use any editor you are familiar with such 
as NotePad or insert names of other common editors. As you gain 
experience you may want to use a text editors with features that help 
you write Python programs. A comprehensive list is here link.

I think I would put this before the paragraph beginning Once you've 
read a tutorial.

- Move the Need to know how to run Python programs on Windows? 
sentence to the last bullet of the list in the next paragraph and 
rewrite it to

Most tutorials assume you know how to run a program on your computer. 
If you are using Windows and need help with this, see link.

- Change Next, you're going to want to read a tutorial to Next, read 
a tutorial


With these changes the first links on this page are BG/Overview, 
BG/Download and BG/NonProgrammers. The second link on BG/NonProgrammers 
is a reasonable tutorial and the first link is pretty obviously one to 
skip. So a beginner is guided through the necessary steps with nothing 
extra or distracting or overwhelming intervening.

- Change the sentence Read BeginnersGuide/Overview to learn the key 
 points. to Read BeginnersGuide/Overview to learn what makes Python 
 special. Or maybe get rid of it completely - I'm not sure evangelism 
 belongs on this page.
 
 
 Yes, it does; fairly often the webmaster alias receives e-mails that
 ask so what is Python?

Direct them to the What is Python? link on the front page maybe? ISTM 
the material in BG/Overview belongs on the pages linked from What is 
Python?

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


Re: How to get the extension of a filename from the path

2005-12-08 Thread gene tani

Lad wrote:
 Thank you ALL for help
 Regards,
 L.

addendum: ASPN Python cookbook often has something relevant /
modifiable for your needs:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81931
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52661

(in this case code from 2001 / 2 is probably py 2.0 or 2.1, shd still
work)

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


Re: Is there anything that pickle + copy_reg cannot serialize?

2005-12-08 Thread Jean-Paul Calderone
On Thu, 08 Dec 2005 22:42:32 +0800, Maurice LING [EMAIL PROTECTED] wrote:
Hi,

I need to look into serialization for python objects, including codes,
recursive types etc etc. Currently, I have no idea exactly what needs to
be serialized, so my scope is to be as wide as possible.

I understand that marshal is extended by pickle to serialize class
instances, shared elements, and recursive data structures
(http://www.effbot.org/librarybook/pickle.htm) but cannot handle code
types. pickle can be used together with copy_reg and marshal to
serialize code types as well
(http://www.effbot.org/librarybook/copy-reg.htm).

So my question will be, are there anything that pickle/copy_reg/marshal
combination cannot serialize? If so, what are the workarounds?

Since copy_reg lets you specify arbitrary code to serialize arbitrary 
objects, you shouldn't run into any single object that you cannot 
serialize to a pickle.

However, both pickle implementations are recursive, so you will be 
limited by the amount of memory you can allocate for your stack.  By 
default, this will limit you to something like object graphs 333 edges 
deep or so (if I'm counting stack frames correctly).  Note that this 
does not mean you cannot serialize more than 333 objects at a time, 
merely that if it takes 333 or more steps to go from the first object 
to any other object in the graph (using the traversal order pickle 
uses), the pickling will fail.  You can raise this limit, to a point, 
with sys.setrecursionlimit().

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


Re: Documentation suggestions

2005-12-08 Thread A.M. Kuchling
On Wed, 07 Dec 2005 10:36:52 -0600, 
A.M. Kuchling [EMAIL PROTECTED] wrote:
 of the seealso environment.  I'll talk to Fred about it and begin
 assembling a patch.

Patch #1376361: http://www.python.org/sf/1376361 .  I still need to talk
to Fred about this.

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


Re: Encoding of file names

2005-12-08 Thread Fredrik Lundh
utabintarbo wrote:

 I am trying to programatically access files created on an IBM AIX
 system, stored on a Sun OS 5.8 fileserver, through a samba-mapped drive
 on a Win32 system. Not confused? OK, let's move on... ;-)

 When I ask for an os.listdir() of a relevant directory, I get filenames
 with embedded escaped characters (ex.
 'F07JS41C.04389525AA.UPR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model')

how did you print that name?  \xa6 is a broken vertical bar, which, as
far as I know, is a valid filename character under both Unix and Windows.

if DIR is a variable that points to the remote directory, what does this
print:

import os
files = os.listdir(DIR)
file = files[0]
print file
print repr(file)
fullname = os.path.join(DIR, file)
print os.path.isfile(fullname)
print os.path.isdir(fullname)

(if necessary, replace [0] with an index that corresponds to one of
the problematic filenames)

when you've tried that, try this variation (only the listdir line has
changed):

import os
files = os.listdir(unicode(DIR)) # -- this line has changed
file = files[0]
print file
print repr(file)
fullname = os.path.join(DIR, file)
print os.path.isfile(fullname)
print os.path.isdir(fullname)

/F



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


Re: Mutability of function arguments?

2005-12-08 Thread Fredrik Lundh
Mike Meyer wrote:

 Your description of passes references by value is a description of
 call by reference. C passes all arguments by value, to pass a
 reference, the C programmer creates the reference to the value by
 hand, then dereferences it by hand at the other end. So C's
 call-by-reference passes the reference by value. There's no
 difference between C's call-by-reference and Python's
 call-by-reference, and using different words to try and imply there is
 will just cause problems further on.

can you guys please stop using call by value and call by reference
when you discuss Python.  both terms have established meanings, and
Python's argument passing model doesn't match any of them.

this was known some 30 years ago; here's a quote from a CLU reference
manaual from 1979:

We call the argument passing technique _call by sharing_,
because the argument objects are shared between the
caller and the called routine.  This technique does not
correspond to most traditional argument passing techniques
(it is similar to argument passing in LISP).  In particular IT
IS NOT call by value because mutations of arguments per-
formed by the called routine will be visible to the caller.
And IT IS NOT call by reference because access is not given
to the variables of the caller, but merely to certain objects.

(CLU was one of the first languages to use objects in the Python sense,
as well as the same argument passing model as today's Python)

established terms for Python's argument passing model are

call by object

or

call by sharing

for more on this, see the comp.lang.python archives.

/F



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


Re: how to put form and display its result(data from database) on the same window?

2005-12-08 Thread lli
Hi Peter,

Could you give me detailed information about your idea.

Thanks,


Laya

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


Re: Documentation suggestions

2005-12-08 Thread Fredrik Lundh
A.M. Kuchling wrote:

  of the seealso environment.  I'll talk to Fred about it and begin
  assembling a patch.

 Patch #1376361: http://www.python.org/sf/1376361 .  I still need to talk
 to Fred about this.

cool.  can you post a sample page somewhere?

/F



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


Re: Documentation suggestions

2005-12-08 Thread skip

amk I wonder if the Internet chapter should be split into HTTP/Web
amk Tools (webbrowser, cgi, cgitb, httplib, urllib) and Non-Web
amk Protocols (ftplib, gopherlib, smtp, all the rest).

Note that cgitb works just fine in a non-web environment.  I would actually
prefer it be renamed (fancytb?) and then stuck wherever the traceback
module docs go.

 \input{distutils}

amk Distutils should probably be in Program Frameworks.  Or it could just
amk have a chapter of its own, or maybe there are enough modules for an
amk Application Support chapter.

There are currently 46 module index entries for the various parts of
distutils.  I think it would be helpful to reduce that number a bit...

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


Re: spawnle umask

2005-12-08 Thread Donn Cave
In article [EMAIL PROTECTED],
 Yves Glodt [EMAIL PROTECTED] wrote:

 David Wahler wrote:
  Yves Glodt wrote:
  It does, I did like this:
 
  os.umask(0113)
  newpid =
  os.spawnl(os.P_NOWAIT,'/usr/local/bin/wine','/usr/local/bin/wine',executabl
  e)
 
  But I wanted to use spawnle and it's env argument, to avoid setting
  umask manually...
  
  The umask is not part of the environment, so there's no way to set it
  directly through spawnle.
 
 ok
 
   Why don't you want to use os.umask?
 
 Only because I thought spawnle could set it through env...
 But as it can't I will now go with os.umask.

On UNIX, the spawn functions are just Python code that wraps up
the low level fork and execve system calls.  There's no reason you
can't write your own version if you like, that does what you need.

It does make sense to want to modify umask and who knows what other
inheritable context in the fork, so you might be thinking of an
API with a function that's called at that time, like

  spawnve(wait, file, args, env, func)

The funny thing is, that's such a good idea that the implementation
already has a function with that signature.  The only difference is
that func() also must call the appropriate execve function.  So for
example,

   def execumask113(file, args, env):
  os.umask(0113)
  return os.execve(file, args, env)

   ...
  os._spawnvef(os.P_NOWAIT, '/usr/local/bin/wine',
['wine', exe], os.environ, execumask113)

Now the problem is that this function is evidently not part of the
published API for os.py, so it would be unseemly to complain if it
were to change in later versions.  So I guess the right thing to do
is write your own spawn function from the ground up.  But at least
you have some ideas there about how it might work.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding of file names

2005-12-08 Thread utabintarbo
Fredrik, you are a God! Thank You^3. I am unworthy /ass-kiss-mode

I believe that may do the trick. Here is the results of running your
code:

 DIR = os.getcwd()
 files = os.listdir(DIR)
 file = files[-1]
 file
'L07JS41C.04389525AA.QTR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model'
 print file
L07JS41C.04389525AA.QTRªINR.EªC-P.D11.081305.P2.KPF.model
 print repr(file)
'L07JS41C.04389525AA.QTR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model'
 fullname = os.path.join(DIR, file)
 print os.path.isfile(fullname)
False
 print os.path.isdir(fullname)
False
 files = os.listdir(unicode(DIR))
 file = files[-1]
 print file
L07JS41C.04389525AA.QTR¦INR.E¦C-P.D11.081305.P2.KPF.model
 print repr(file)
u'L07JS41C.04389525AA.QTR\u2592INR.E\u2524C-P.D11.081305.P2.KPF.model'
 fullname = os.path.join(DIR, file)
 print os.path.isfile(fullname)
True --- Success!
 print os.path.isdir(fullname)
False

Thanks to all who posted. :-)

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


Re: Bitching about the documentation...

2005-12-08 Thread Sion Arrowsmith
Steven D'Aprano  [EMAIL PROTECTED] wrote:
 Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.

S
P
O
I
L
E
R
 
S
P
A
C
E



(Good grief, I've not done that in *years*.)

Buffalo from the city of Buffalo, which are intimidated by buffalo
from Buffalo, also intimidate buffalo from Buffalo.

I didn't say it was *good* English, but it is *legal* English.

I *think* that's similar to the one I know about the cannibalistic
behaviour of some oysters, which split open other oysters (to eat
them). It starts:

Oysters oysters split split.

Oysters which oysters split become split.

But there's nothing to stop a third set of oysters predating on the
ones doing the splitting:

Oysters oysters oysters split split split.

And so on. My brain hurts too much to work out if you can do the
same to the buffaloes.

And here endeth today's lesson in recursion.

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

Re: Bitching about the documentation...

2005-12-08 Thread Neil Schemenauer
François Pinard [EMAIL PROTECTED] wrote:
[AMK]
 You may suggest that I should process my e-mail more promptly.

 No, I'm not suggesting you how to work, no more that I would accept that 
 you force me into working your way.  If any of us wants to force the 
 other to speak through robots, that one is not far from unspeakable...

 This is why things need to go into public trackers, or wiki pages.

 Whatever means the maintainer wants to fill his preservation needs, he 
 is free to use them.  The problem arises when the maintainer wants 
 imposing his own work methods on others.  Let contributors be merely
 contributors, and learn how to recognise contributions as such and say 
 thank you, instead of trying to turn contributors into maintainers.

Either I don't understand what you are saying or you are being a
hypocrite.  Andrew is saying that he doesn't have time to detail
with all the messages that get sent to him personally.  What do you
propose he should do?  I think people expect more that a message
saying Thanks for you contribution.  PS: Since I don't have time to
do anything with it, your message will now be discarded..

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


Re: Is there anything that pickle + copy_reg cannot serialize?

2005-12-08 Thread Maurice LING

 Since copy_reg lets you specify arbitrary code to serialize arbitrary 
 objects, you shouldn't run into any single object that you cannot 
 serialize to a pickle.

In http://www.effbot.org/librarybook/pickle.htm, it specifically 
mentions that code objects cannot be pickled and require the use of 
copy_reg, as follows:

import copy_reg
import pickle, marshal, types

#
# register a pickle handler for code objects

def code_unpickler(data):
 return marshal.loads(data)

def code_pickler(code):
 return code_unpickler, (marshal.dumps(code),)

copy_reg.pickle(types.CodeType, code_pickler, code_unpickler)

#
# try it out

CODE = 
print suppose he's got a pointed stick


code = compile(CODE, string, exec)

exec code
exec pickle.loads(pickle.dumps(code))


I cannot understand 2 things, which I seek assistance for:
1. Is code object the only thing can cannot be pickled (less facing 
recursion limits)?
2. In the above example, how copy_reg works with pickle?

Thanks and Cheers
Maurice

 
 However, both pickle implementations are recursive, so you will be 
 limited by the amount of memory you can allocate for your stack.  By 
 default, this will limit you to something like object graphs 333 edges 
 deep or so (if I'm counting stack frames correctly).  Note that this 
 does not mean you cannot serialize more than 333 objects at a time, 
 merely that if it takes 333 or more steps to go from the first object to 
 any other object in the graph (using the traversal order pickle uses), 
 the pickling will fail.  You can raise this limit, to a point, with 
 sys.setrecursionlimit().
 
 Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


newby question: Splitting a string - separator

2005-12-08 Thread Thomas Liesner
Hi all,

i am having a textfile which contains a single string with names.
I want to split this string into its records an put them into a list.
In normal cases i would do something like:

 #!/usr/bin/python
 inp = open(file)
 data = inp.read()
 names = data.split()
 inp.close()

The problem is, that the names contain spaces an the records are also
just seprarated by spaces. The only thing i can rely on, ist that the
recordseparator is always more than a single whitespace.

I thought of something like defining the separator for split() by using
 a regex for more than one whitespace. RegEx for whitespace is \s, but
what would i use for more than one? \s+?

TIA,
Tom
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: efficient 'tail' implementation

2005-12-08 Thread Neal Becker
[EMAIL PROTECTED] wrote:

 hi
 
 I have a file which is very large eg over 200Mb , and i am going to use
 python to code  a tail
 command to get the last few lines of the file. What is a good algorithm
 for this type of task in python for very big files?
 Initially, i thought of reading everything into an array from the file
 and just get the last few elements (lines) but since it's a very big
 file, don't think is efficient.
 thanks
 

You should look at pyinotify.  I assume we're talking linux here.

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


Re: ElementTree - Why not part of the core?

2005-12-08 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
 I think the key here is ElementTree's Pythoninc API.  While it's clearly
 possible to install it as a third-party package, I think there's a clear
 best-of-breed aspect here that suggests it belongs in the standard
 distribution simply to discourage continued use of DOM-based APIs.

I second this.  Guido has said many times that the stdlib is for 
best-of-breed modules that have proven themselves in the wild. 
ElementTree has proven itself in the wild and is clearly best-of-breed. 
  And dramatically better (IMHO) than the APIs currently included in the 
stdlib[1].

I don't have a whole lot of free time, and I'm not sure exactly how I 
could help, but if there's anything I could do that would help get 
ElementTree into the stdlib, let me know.

STeVe

[1] If I had my way, we'd deprecate and then remove the current Python 
xml modules.  But of course then people would complain that Python 
doesn't have a SAX or DOM API.  Of course we could tell them that they 
don't need it and that ElementTree is easier, but I'm not sure people 
really want to fight that battle.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to ping in Python?

2005-12-08 Thread Chris Miles
You could also try the ping module that the Eddie monitoring tool has 
been using successfully, cross-platform, for many years.

http://dev.eddie-tool.net/trac/browser/eddie/trunk/lib/common/Directives/pinger.py

Cheers,
Chris

Nico Grubert wrote:
 I could not find any ping Class or Handler in python (2.3.5) to ping a 
 machine.
 I just need to ping a machine to see if its answering. What's the best 
 way to do it?

-- 
http://chrismiles.info/

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


Images Connected Component labeling

2005-12-08 Thread Jim

Does anyone know where I can find a 'connected component' image
processing function?  I don't see it in numarray or scipy core...

In matlab the function is called bwlabel(bw,4);

and step 8 on this page is an example of what I'm trying to do:
http://www.mathworks.com/access/helpdesk_r13/help/toolbox/images/getting3.html

Thanks,
-Jim

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


Re: sql escaping module

2005-12-08 Thread David Bear
Fredrik Lundh wrote:

 David Bear wrote:
 
 Being new to pgdb, I'm finding there are lot of things I don't understand
 when I read the PEP and the sparse documentation on pgdb.

 I was hoping there would be a module that would properly escape longer
 text strings to prevent sql injection -- and other things just make sure
 the python string object ends up being a properly type for postgresql.
 I've bought 3 books on postgresql and none of th code samples demonstrate
 this.

 web searchs for 'python sql escape  string' yeild way too many results.

 Any pointers would be greatly appreciated.
 
 for x in range(100):
 print USE PARAMETERS TO PASS VALUES TO THE DATABASE
 
 /F
Yes. Fredrik and others. Thank you for the advice.

I know have the following code:

..
parmChar = '%s'
sqlInsert = INSERT INTO %s (%s) VALUES (%s);  % (tn, ,
.join(fieldnames), , .join([parmChar] * len(fieldnames)))
try:
cursor.execute(sqlInsert, datum)
except pgdb.DatabaseError:
logerror(Error on record insert \n %s \n %s % (sqlInsert, 
   traceback.print_exc()))

I was not aware that the python db interface would just handle proper
escaping of python data types to proper postgresql data types.

Any other hints on database programming much appreciated.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there anything that pickle + copy_reg cannot serialize?

2005-12-08 Thread Jean-Paul Calderone
On Fri, 09 Dec 2005 02:17:10 +0800, Maurice LING [EMAIL PROTECTED] wrote:

 Since copy_reg lets you specify arbitrary code to serialize arbitrary
 objects, you shouldn't run into any single object that you cannot
 serialize to a pickle.

 [snip - example of pickling code objects]


I cannot understand 2 things, which I seek assistance for:
1. Is code object the only thing can cannot be pickled (less facing
recursion limits)?

No.  There are lots of objects that cannot be pickled by default.  Any 
extension type which does not explicitly support it cannot be pickled.  
Generators cannot be pickled.  Method descriptors can't be pickled.  Et 
cetera.

2. In the above example, how copy_reg works with pickle?

Any time pickle thinks it has found something it cannot pickle, it asks 
the copy_reg module for some help.  The above example basically teaches 
the copy_reg module how to give the pickle module the help it needs for 
code objects.

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


Re: newby question: Splitting a string - separator

2005-12-08 Thread Michael Spencer
Thomas Liesner wrote:
 Hi all,
 
 i am having a textfile which contains a single string with names.
 I want to split this string into its records an put them into a list.
 In normal cases i would do something like:
 
 #!/usr/bin/python
 inp = open(file)
 data = inp.read()
 names = data.split()
 inp.close()
 
 The problem is, that the names contain spaces an the records are also
 just seprarated by spaces. The only thing i can rely on, ist that the
 recordseparator is always more than a single whitespace.
 
 I thought of something like defining the separator for split() by using
  a regex for more than one whitespace. RegEx for whitespace is \s, but
 what would i use for more than one? \s+?
 
 TIA,
 Tom
\s+ gives one or more, you need \s{2,} for two or more:

   import re
   re.split(\s{2,},Guido van Rossum  Tim Peters Thomas Liesner)
  ['Guido van Rossum', 'Tim Peters', 'Thomas Liesner']
  

Michael

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


Re: newby question: Splitting a string - separator

2005-12-08 Thread Noah

Thomas Liesner wrote:
 ...
 The only thing i can rely on, ist that the
 recordseparator is always more than a single whitespace.

 I thought of something like defining the separator for split() by using
  a regex for more than one whitespace. RegEx for whitespace is \s, but
 what would i use for more than one? \s+?

For your split regex you could say
\s\s+
or
\s{2,}

This should work for you:
YOUR_SPLIT_LIST = re.split(\s{2,}, YOUR_STRING)

Yours,
Noah

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


Re: newby question: Splitting a string - separator

2005-12-08 Thread Jim
Hi Tom,

 a regex for more than one whitespace. RegEx for whitespace is \s, but
 what would i use for more than one? \s+?

For more than one, I'd use

  \s\s+

-Jim

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


Re: unittest and non-.py files

2005-12-08 Thread Michael Hoffman
[Michael Hoffman]
Hi. I am trying to use unittest to run a test suite on some
scripts that do not have a .py extension.

[Sybren Stuvel]
 I'd move the functionality of the script into a separate file that
 does end in .py, and only put the invocation into the .py-less
 script.

That's what I have done, and it is a better solution for other reasons.
Thanks Sybren.

I would still like to do what I originally proposed. Would this warrant
a feature request?
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what's wrong with lambda x : print x/60,x%60

2005-12-08 Thread Scott David Daniels
Steve Holden wrote:
 Paul Rubin wrote:
   I think it's a Python weakness that you can't declare a local var like
 in other languages, to go out of scope at the end of the current block, e.g.:

   if cond:
   my x = 7# make a new scope for x, goes out of scope at end of if

 If this genuinely troubles you then you can always isolate the scope 
 with a function, though of course you also no longer have the code 
 inline then.
Or, if you must:

def called(function):
 function()
 return called

then:

@called
def called():
 whatever

;-)

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


Re: how to put form and display its result(data from database) on the same window?

2005-12-08 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
 Could you give me detailed information about your idea.

I believe I just did.

Really, as I said, this is non-trivial.  I can't give you a three 
minute tutorial that will help you at all, especially if you haven't 
read the information I pointed you to.  (The page I pointed you to 
actually links to the following one, in case you didn't notice: 
http://en.wikipedia.org/wiki/Ajax_%28programming%29 )

-Peter

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


Re: Post-modernism, Academia, and the Tech Geeking fuckheads

2005-12-08 Thread bradb
I don't know about anyone else, but you'd impress me much more if you
didn't swear in your posts.  I am personally not offended, but it does
lower your credibility in my eyes.  Just a tip.

Brad

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


Re: Bitching about the documentation...

2005-12-08 Thread BartlebyScrivener
The actress Margaret Anglin left this note in the dressing froom of
another actress:

'Margaret Anglin says Mrs. Fiske is the best actress in America.'

Mrs. Fiske added two commas and returned the note: 'Margaret Anglin,
says Mrs. Fiske, is the best actress in America.'

Or this, from a George Will column:

Huge doctrinal consequences flow from the placing of a comma in what
Jesus, when on the cross, said to the thief (Luke 23:43): 'Verily, I
say unto thee, This day thou shalt be with me in Paradise' or 'Verily,
I say unto thee this day, Thou shalt be with me in Paradise.' The
former leaves little room for purgatory.

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


Re: what's wrong with lambda x : print x/60,x%60

2005-12-08 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes:
if cond:
  my x = 7# make a new scope for x, goes out of scope at end of if
 
 If this genuinely troubles you then you can always isolate the scope
 with a function, though of course you also no longer have the code
 inline then.
 I don't generally speaking see the point:

The point is something like: it's normal to write
   if cond:
  x = 7
  do_something_with(x)
  # now you don't care about x any more.

Years later, there's some production problem in the middle of the
night and someone has to put in a patch, and they re-use the value in
x for something later in the function, i.e.

 y = x + 3# since x is still in scope from way up there

and check it in.  Years after THAT, yet another person re-uses the
name x for something, etc.  Yeah, yeah, bad programming practice,
blah, blah, blah, but anyone who's maintained code in the real world
knows this stuff happens all the time.

 Well, as warts go the inability to tightly control the scope of
 variables isn't really that terrible, is it?

I wouldn't say it's as terrible as some things might be, but it
contributes to a sense of sloppiness about Python, that there are
always all these dirty dishes laying around.  Even the encrustation we
call Perl doesn't have this problem; it can not only control scope,
but it has the -T (taint checking) feature that analyzes actual
dataflow from one variable to another and flags you if you do
something dangerous with unchecked user input.  This turns out to be
very useful.  I wish Python had something like it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unexpected behavior of read only attributes and super

2005-12-08 Thread Samuel M. Smith


 P.S. Note that there is an additional complication resulting from the
 fact that functions are descriptors:

 class C(dict):
 ... pass
 ...
 C.__iter__
 slot wrapper '__iter__' of 'dict' objects
 C().__iter__
 method-wrapper object at 0x00E74A10

 Even though the C instance is accessing the __iter__ function on the
 class, it gets back a different value because descriptors return
 different values depending on whether they are accessed from a  
 class or
 an instance.  I don't think you need to understand this to solve your
 problem though, so I won't go into any more details unless you  
 think it
 would be helpful.


I found your explanation very helpful. After reading it I went back  
and read
my Nutshell book and realized that the explanation was in there but I  
didn't get it until now.
Although I did find an exception to the rule for attribute writes.  
(See !Whoops below)

If you would care to elaborate on the how the lookup differs with  
method descriptor
it would be most appreciated. Mostly because it seems that having  
slots defined
changes the method lookup as opposed to the variable lookup and  
apparently some of the type class
variables are special enough that they have their own rules.

This might help explain why it is that when I define __slots__, the  
behavior when writing an attribute is different for
attributes that exist in the class versus attributes that exist in  
__slots__ versus attributes that
do not exist at all. It is also different if the class attribute is a  
method vesus a variable.

For example

  class C(dict):
... __slots__ = ['a','b']
...
  c = C()
  c.a
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: a

So slot defined but not assigned gets error

  c.a = 5
  c.a
5

OK here

  c.c
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: 'C' object has no attribute 'c'

Surprise error gives no clue that slots is the reason for the error

  c.c = 4
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: 'C' object has no attribute 'c'

ditto


Now the behavior is different for class variables and methods when  
slots defined
versus when slots is not defined.

  c.__iter__ = 4
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: 'C' object attribute '__iter__' is read-only

  super(C,c).__iter__ = 4
Traceback (most recent call last):
   File stdin, line 1, in ?
TypeError: 'super' object has only read-only attributes (assign  
to .__iter__)
 

  c.__class__ = C
  c.__class__
class '__main__.C'

it let me assign it! But not shadowed
  c.__dict__
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: 'C' object has no attribute '__dict__'

!Whoops now I am confused again. Didn't you say

 When writing an attribute (i.e. using the assignment statement),
 Python does not try to do any namespace searching.  Thus if you use  
 the
 instance in an assignment statement, then it is the instance's
 attributes that get modified, and if you use the class in an  
 assignment
 statement, then it is the class's attributes that get modififed:

Then why wasn't __class__ added to c.__dict__ ? Looks like namespace  
searching to me.

So to cross check if slots is not defined

  class C(dict):
... pass
...
  c = C()
  c.__iter__ = 1
  c.__dict__
{'__iter__': 1}

  c.__class__ = C
  c.__dict__
{'__iter__': 1}
 

try again a different way

class B(C):
... pass
...
  c.__class__ = B
  c.__dict__
{'__iter__': 4}

OK but maybe __class__ is magic, so I tried again

  class C(dict):
... a = 0
...
  c = C()
  c.a
0
  c.a = 4
  c.__dict__
{'a': 4}

OK __class__ is special

now with slots defined

  class C(dict):
... __slots__ = ['b']
... a = 0
...
  c = C()
  c.a
0
  c.a = 4
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: 'C' object attribute 'a' is read-only
 

  C.a = 5
  c.a
5
 

So the rule is that when __slots__ is defined class variables become  
read only.

What if the class variable is included in __slots__

  class C(dict):
... __slots__ = ['b']
... b = 1
...
  c = C()
  c.b
1
  c.b = 2
Traceback (most recent call last):
   File stdin, line 1, in ?
AttributeError: 'C' object attribute 'b' is read-only

So even though b is in slots I still can't create an instance  
variable by that name
and shadow the class variable.

It feels like the implementation of slots is half baked.

Finally
Since the way of python is that if an object does not have an  
attribute
but you can assign it one then it creates one dynamically (in the  
same 'way' that if a variable does not
exist is creates one upon assignment).
Because slots break this paradigm then at the very least the error  
messages should point out that this object
is using slots so beware.

For example I would prefer something like the following

c.a
AttributeError: Slot 'a' not yet assigned

c.c
AttributeError: No slot named 'c' on instance

c.c = 4

  1   2   >