Re: use fileinput to read a specific line

2008-01-07 Thread jo3c
On Jan 8, 2:08 pm, "Russ P." <[EMAIL PROTECTED]> wrote:
> > Given that the OP is talking 2000 files to be processed, I think I'd
> > recommend explicit open() and close() calls to avoid having lots of I/O
> > structures floating around...
>
> Good point. I didn't think of that. It could also be done as follows:
>
> for fileN in files:
>
> lnum = 0 # line number
> input = file(fileN)
>
> for line in input:
> lnum += 1
> if lnum >= 4: break
>
> input.close()
>
> # do something with "line"
>
> Six of one or half a dozen of the other, I suppose.

this is what i did using glob

import glob
for files in glob.glob('/*.txt'):
x = open(files)
x.readline()
x.readline()
x.readline()
y = x.readline()
# do something with y
x.close()

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


Re: Python setup not working on Windows XP

2008-01-07 Thread Tim Roberts
Gowri <[EMAIL PROTECTED]> wrote:
>
>I am new to Python and am trying to setup Apache to serve Python using
>mod_python. I'm using a Windows XP box. here is a list of steps i
>followed for the installation:
>
>1. Installed Apache 2.2.6
>2. Installed Python 2.5.1
>3. Installed mod_python 3.3.1
>
>I then included the line
>LoadModule python_module modules/mod_python.so in httpd.conf
>
>I had this one line python file (print "Hello") in htdocs of Apache.

Did you put it in a file called "hello.py"?  Did you create an AddHandler
for .py files?  Did you create a PythonHandler referring to hello.py?
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Pet Store

2008-01-07 Thread George Maggessy
Hi there,

I'm an experience Java developer trying to learn Python. I just
finished the Python tutorial on python.org and I'm currently reading
the "Learning Python" book. However, if I could find something like a
simple web app with some best practices, such as those famous "Java
Pet Store" apps, I think that would help me to fill up some gaps in my
learning process. Does anybody know any app like that?

Cheers,
George
-- 
http://mail.python.org/mailman/listinfo/python-list


web service between python and c#

2008-01-07 Thread abhishek
Hello group i need to make a web service to work between python and
c# . Where python would server as backend (server) preferebly cherrypy
(turbogears) and client would be on a c# appln.

I have developed a webservice using TGWebServices package which runs
on top of turbogears.

but have no idea on how to interface it with c# client.

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


Re: use fileinput to read a specific line

2008-01-07 Thread Russ P.
On Jan 7, 9:41 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Mon, 7 Jan 2008 20:10:58 -0800 (PST), "Russ P."
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
> > for file0 in files:
>
> > lnum = 0 # line number
>
> > for line in file(file0):
> > lnum += 1
> > if lnum >= 4: break
>
> > # do something with "line"
>
> > where "files" is a list of the files to be read.
>
> Given that the OP is talking 2000 files to be processed, I think I'd
> recommend explicit open() and close() calls to avoid having lots of I/O
> structures floating around...
>
> for fid in file_list:
> fin = open(fid)
> jnk = fin.readline()
> jnk = fin.readline()
> jnk = fin.readline()
> ln = fin.readline()
> fin.close()
>
> Yes, coding three junk reads does mean maintenance will be a pain
> (we now need the 5th line, not the fourth -- and would need to add
> another jnk = line)... I'd maybe consider replacing all four readline()
> with:
>
> for cnt in xrange(4):
> ln = fin.readline()
>
> since it doesn't need the overhead of a separate line counter/test and
> will leave the fourth input line in "ln" on exit.
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED]  [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/

One second thought, I wonder if the reference counting mechanism would
be "smart" enough to automatically close the previous file on each
iteration of the outer loop. If so, the files don't need to be
explicitly closed.
-- 
http://mail.python.org/mailman/listinfo/python-list


User Group

2008-01-07 Thread George Maggessy
Hi Guys,

Is there a python user group in the bay area?

Cheers,
George
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: use fileinput to read a specific line

2008-01-07 Thread Russ P.

> Given that the OP is talking 2000 files to be processed, I think I'd
> recommend explicit open() and close() calls to avoid having lots of I/O
> structures floating around...

Good point. I didn't think of that. It could also be done as follows:

for fileN in files:

lnum = 0 # line number
input = file(fileN)

for line in input:
lnum += 1
if lnum >= 4: break

input.close()

# do something with "line"

Six of one or half a dozen of the other, I suppose.
-- 
http://mail.python.org/mailman/listinfo/python-list


ctypes and 3rd party dll

2008-01-07 Thread hkimball
I am trying to call a function in  a third party dll that spawns
anr exe and I am using ctypes.  Python does not complain at all
but the other process does not get spawned.  It appears that I am
gaining access to the functions but with no results.  Any ideas?
Thanks in advance.

>>> from ctypes import *
>>> cdecl = cdll.LoadLibrary("c:\projects\python\geinterface.dll")
>>> cdecl._GE_Connect

<_FuncPtr object at 0x00B7E378>
>>> cdecl._GE_Connect()
0
>>> cdecl._GE_IsConnected()

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


Re: any() and all() shorthand

2008-01-07 Thread castironpi
>print 'lookahead2(initial=3.14159, last=42)'
>for this, next in lookahead2([1,2,3,4,5],
>initial=3.14159, last=42):
>  print this, next

No, actually.  But my mistake.

[ a.b() or _previous_ for a in c ]

means

1 or 2 or 3 or 4 or 5
where c= [ 1, 2, 3, 4, 5].

The mistake: this was not a list comprehension; I wanted to reduce to
a single value.

It's equivalent to reduce( operator.or_, [ 1, 2, 3, 4, 5 ] ), but
disnecessitates lambdas for slightly more complex reductions.  But the
example is out of stock.  Do we have one?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: use fileinput to read a specific line

2008-01-07 Thread Russ P.
On Jan 7, 7:15 pm, jo3c <[EMAIL PROTECTED]> wrote:
> hi everybody
> im a newbie in python
> i need to read line 4 from a header file
> using linecache will crash my computer due to memory loading, because
> i am working on 2000 files each is 8mb
>
> fileinput don't load the file into memory first
> how do i use fileinput module to read a specific line from a file?
>
> for line in fileinput.Fileinput('sample.txt')
> 

Assuming it's a text file, you could use something like this:

lnum = 0 # line number

for line in file("sample.txt"):
lnum += 1
if lnum >= 4: break

The variable "line" should end up with the contents of line 4 if I am
not mistaken. To handle multiple files, just wrap that code like this:

for file0 in files:

lnum = 0 # line number

for line in file(file0):
lnum += 1
if lnum >= 4: break

# do something with "line"

where "files" is a list of the files to be read.

That's not tested.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: linecache and glob

2008-01-07 Thread jo3c
On Jan 4, 5:25 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> jo3c wrote:
> > i have a 2000 files with header and data
> > i need to get the date information from the header
> > then insert it into my database
> > i am doing it in batch so i use glob.glob('/mydata/*/*/*.txt')
> > to get the date on line 4 in the txt file i use
> > linecache.getline('/mydata/myfile.txt/, 4)
>
> > but if i use
> > linecache.getline('glob.glob('/mydata/*/*/*.txt', 4) won't work
>
> glob.glob returns a list of filenames, so you need to call getline once
> for each file in the list.
>
> but using linecache is absolutely the wrong tool for this; it's designed
> for *repeated* access to arbitrary lines in a file, so it keeps all the
> data in memory.  that is, all the lines, for all 2000 files.
>
> if the files are small, and you want to keep the code short, it's easier
> to just grab the file's content and using indexing on the resulting list:
>
>  for filename in glob.glob('/mydata/*/*/*.txt'):
>  line = list(open(filename))[4-1]
>  ... do something with line ...
>
> (note that line numbers usually start with 1, but Python's list indexing
> starts at 0).
>
> if the files might be large, use something like this instead:
>
>  for filename in glob.glob('/mydata/*/*/*.txt'):
>  f = open(filename)
>  # skip first three lines
>  f.readline(); f.readline(); f.readline()
>  # grab the line we want
>  line = f.readline()
>  ... do something with line ...
>
> 

thank you guys, i did hit a wall using linecache, due to large file
loading into memory.. i think this last solution works well for me
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TIOBE declares Python as programming language of 2007!

2008-01-07 Thread Paddy
On Jan 7, 10:55 am, [EMAIL PROTECTED] wrote:
> Seehttp://www.tiobe.com/index.htm?tiobe_index.
>
> Marc
ohloh "Monthly Commits by Language"
also shows Python open-source work being healthy:
  http://tinyurl.com/2wcadu
If you remove C/C++ the other languages can be more easily compared.
(C/C++ I see as the bedrock language of open-source):
  http://tinyurl.com/2u76d9

- Paddy.

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


use fileinput to read a specific line

2008-01-07 Thread jo3c
hi everybody
im a newbie in python
i need to read line 4 from a header file
using linecache will crash my computer due to memory loading, because
i am working on 2000 files each is 8mb

fileinput don't load the file into memory first
how do i use fileinput module to read a specific line from a file?

for line in fileinput.Fileinput('sample.txt')


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


Python Help

2008-01-07 Thread Donald Bozeman
To all,
Just requesting Python Help - currently taking online courses for Computer
Science degree. Is anyone willing to help on some issues. Please let me
know, thank you.

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

windows service

2008-01-07 Thread Michael Chesterton
I'm trying to get a program that uses M2Crypto ThreadingSSLServer to  
run in windows as a service. I have a few problem, it doesn't listen  
on its port and I don't know how to debug it.

I used the pipeservice example as a framework to get it running as a  
service

 def SvcDoRun(self):
 # Write an event log record - in debug mode we will also
 # see this message printed.
 servicemanager.LogMsg(
 servicemanager.EVENTLOG_INFORMATION_TYPE,
 servicemanager.PYS_SERVICE_STARTED,
 (self._svc_name_, '')
 )

 daemonserver = do_daemon()
 while 1:
 daemonserver.handle_request()

I think I need a way to break out of that while loop when a service  
stop is sent, but not knowing what happening at that point I'm not  
sure how. It's not even listening on its port.

daemonserver is

 daemonserver = SSL.ThreadingSSLServer((host_ip_addr, int 
(host_port_num)), TestRequestHandler, ctx)

any help?

-- 
Michael Chesterton
http://chesterton.id.au/blog/
http://barrang.com.au/



-- 
Michael Chesterton
http://chesterton.id.au/blog/
http://barrang.com.au/



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


Re: I'm searching for Python style guidelines

2008-01-07 Thread ajaksu
On Jan 7, 11:25 am, [EMAIL PROTECTED] wrote:
> There's a lot of dumb stuff out there. "Algorithms should be coded
> efficiently ..." Thanks, I'll keep that in mind.
>
> van Rossum's guidelines tend toward "pick something and stick to it"
> which is OK if you have enough experience to pick something Pythonic.
> I'm a relative newbie, not qualified to pick.
>
> Anything written somewhere that's thorough? Any code body that should
> serve as a reference?

I've done this search before and it was very interesting, doing it
again gave me new results that also seem valuable. Here's most of them
(where PCG = Python Coding Guidelines).

Cogent project PCG
http://jaynes.colorado.edu/PythonGuidelines.html
(also http://jaynes.colorado.edu/PythonIdioms.html)

Freevo Coding Standard
http://doc.freevo.org/CodingStandard

Mercurial Basic Coding Style
http://www.selenic.com/mercurial/wiki/index.cgi/Basic_Coding_Style

PyBlosxom Coding Style Guide
http://pyblosxom.sourceforge.net/blog/static/development#coding

MoinMoin Coding Style
http://moinmoin.wikiwikiweb.de/CodingStyle

Webware Style Guidelines
http://www.webwareforpython.org/Docs/StyleGuidelines.html

NOAA Enhanced Forecaster Tools PCG
http://www-md.fsl.noaa.gov/eft/developer/PythonCodingStandards.html

BioPython Coding Conventions
http://biopython.org/wiki/Contributing#Coding_conventions

Mnet PCG
http://mnet.sourceforge.net/coding_standards.html

Michael Foord's (aka Voidspace) PCG
http://www.voidspace.org.uk/python/weblog/arch_d7_2006_04_01.shtml#e296

SQLObject Coding Style
http://www.sqlobject.org/DeveloperGuide.html#style-guide

WxPython PCG
http://www.wxpython.org/codeguidelines.php

Python coding style guide for Mailman
http://barry.warsaw.us/software/STYLEGUIDE.txt

VoiceCode PCG
http://voicecode.iit.nrc.ca/VoiceCode/uploads/codingGuidelines.html

Bazaar Coding Stile Guidelines
http://doc.bazaar-vcs.org/bzr.dev/en/developer-guide/HACKING.html#coding-style-guidelines

IPython Developer Guidelines
http://ipython.scipy.org/moin/Developer_Zone/Developer_Guidelines

OSAF Chandler PCG
http://chandlerproject.org/Projects/ChandlerCodingStyleGuidelines
(along with http://chandlerproject.org/Projects/ChandlerEpydocStyleGuide)

Twisted Coding Standard
http://twistedmatrix.com/trac/browser/trunk/doc/development/policy/coding-standard.xhtml?format=raw

PyPy RPython and CPython Coding Guidelines
http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html

Django PCG (and general contribution recommendations)
http://www.djangoproject.com/documentation/contributing/#coding-style

Docutils PCG
http://docutils.sourceforge.net/docs/dev/policies.html#python-coding-conventions

Trac Coding Style
http://trac.edgewall.org/wiki/TracDev/CodingStyle

OLPC PCG
http://wiki.laptop.org/go/Python_Style_Guide

Skeletonz Coding and Naming Conventions
http://orangoo.com/skeletonz/Developer_guide/Coding_convention/
http://orangoo.com/skeletonz/Developer_guide/Naming_convention/

CherryPy Code Conventions
http://www.cherrypy.org/wiki/CodeConventions

More generic but still good (or great) insights:
Software Carpentry on style http://www.swc.scipy.org/lec/style.html
Zope's Coding Style http://wiki.zope.org/zope3/CodingStyle
The docstrings PEP http://www.python.org/dev/peps/pep-0257/



The NiceStyle Triad®:
Pyflakes http://divmod.org/trac/wiki/DivmodPyflakes
PyChecker http://pychecker.sourceforge.net/
Pylint http://www.logilab.org/857



Do you think this could be a valuable addition to the Python wiki?

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


Open a List of Files

2008-01-07 Thread BJ Swope
given a list such as

['messages', 'recipients', 'viruses']

how would I iterate over the list and use the values as variables and open
the variable names a files?

I tried

for outfile in ['messages', 'recipients', 'viruses']:
filename = os.path.join(Host_Path, outfile)
outfile = open(filename, 'w')


But it's not working.



-- 
We are all slave to our own paradigm. -- Joshua Williams

If the letters PhD appear after a person's name, that person will remain
outdoors even after it's started raining. -- Jeff Kay
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: code doesn't reference immutables?

2008-01-07 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| >From the manual:
|
| "code objects are immutable and contain no references (directly or
| indirectly) to mutable objects" (3.2)
|
| I thought my code worked with both mutable and immutable objects.
| Whassup?

Consider the following:

>>> def g(): return (1,2), [1,2]

>>> dis.dis(g)
  1   0 LOAD_CONST   3 ((1, 2))
  3 LOAD_CONST   1 (1)
  6 LOAD_CONST   2 (2)
  9 BUILD_LIST   2
 12 BUILD_TUPLE  2
 15 RETURN_VALUE

>>> g.func_code.co_consts
(None, 1, 2, (1, 2))

The code object stores the immutables 1, 2, and (1,2) but not the mutable 
[1,2].  Rather it stores immutable code to create the mutable list.

I tried to see if the addition of closures violated the stipulation, using

>>> def f():
 l = []
 def _(x):
  l.append(x)
 return _

but the inner code object only knows the list by the (immutable) name 'l', 
which does not count as a reference.  Such code objects cannot be directly 
exec'ed but only executed indirectly by calling the function that wraps it 
and that has the reference to the in-this-case mutable object.  (The 
mapping from 'l' to that object appears to be hidden.)

Terry Jan Reedy



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


Re: Python's great, in a word

2008-01-07 Thread jo3c
On Jan 7, 9:09 pm, [EMAIL PROTECTED] wrote:
> I'm a Java guy who's been doing Python for a month now and I'm
> convinced that
>
> 1) a multi-paradigm language is inherently better than a mono-paradigm
> language
>
> 2) Python writes like a talented figure skater skates.
>
> Would you Python old-timers try to agree on a word or two that
> completes:
>
> The best thing about Python is ___.
>
> Please, no laundry lists, just a word or two. I'm thinking "fluid" or
> "grace" but I'm not sure I've done enough to choose.

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


Re: Open source English dictionary to use programmatically w/ python

2008-01-07 Thread [EMAIL PROTECTED]
On Jan 7, 5:10 pm, dgoldsmith_89 <[EMAIL PROTECTED]> wrote:
> On Jan 7, 2:54 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > On Jan 7, 4:37 pm, dgoldsmith_89 <[EMAIL PROTECTED]> wrote:
>
> > > Can anyone point me to a downloadable open source English dictionary
> > > suitable for programmatic use with python: I'm programming a puzzle
> > > generator, and I need to be able to generate more or less complete
> > > lists of English words, alphabetized.  Thanks!  DG
>
> >www.puzzlers.orghasnumerous word lists & dictionarys in text
> > format that can be downloaded. I recommend you insert them into
> > some form of database. I have most of them in an Access db and
> > it's 95 MB. That's a worse case as I also have some value-added
> > stuff, the OSPD alone would be a lot smaller.
>
> > 
>
> Sorry for my ignorance: I can query an Access DB w/ standard SQL
> queries (and this is how I would access it w/ Python)?

Yes, if you have the appropriate way to link to the DB.
I use Windows and ODBC from Win32. I don't know what you
would use on a Mac.

As Paul McGuire said, you could easily do this with SqlLite3.
Personnaly, I always use Access since my job requires it
and I find it much more convenient. I often use Crosstab
tables which I think SqlLite3 doesn't support. Typically,
I'll write complex queries in Access and simple select SQL
statements in Python to grab them.

Here's my anagram locator. (the [signature] is an example
of the value-added I mentioned).

##  I took a somewhat different approach. Instead of in a file,
##  I've got my word list (562456 words) in an MS-Access database.
##  And instead of calculating the signature on the fly, I did it
##  once and added the signature as a second field:
##
##  TABLE CONS_alpha_only_signature_unique
##  --
##  CONS   text  75
##  signature  text  26
##
##  The signature is a 26 character string where each character is
##  the count of occurences of the matching letter. Luckily, in
##  only a single case was there more than 9 occurences of any
##  given letter, which turned not to be a word but a series of
##  words concatenated so I just deleted it from the database
##  (lots of crap in the original word list I used).
##
##  Example:
##
##  CONS signature
##  aah  200100 # 'a' occurs twice & 'h' once
##  aahed2001100100
##  aahing   201111
##  aahs 2001001000
##  aaii 200020
##  aaker2000101001
##  aal  200100
##  aalborg  2111001001
##  aalesund
20011001011010
##
##  Any words with identical signatures must be anagrams.
##
##  Once this was been set up, I wrote a whole bunch of queries
##  to use this table. I use the normal Access drag and drop
##  design, but the SQL can be extracted from each, so I can
##  simply open the query from Python or I can grab the SQL
##  and build it inside the program. The example
##
##signatures_anagrams_select_signature
##
##  is hard coded for criteria 9 & 10 and should be cast inside
##  Python so the criteria can be changed dynamically.
##
##
##  QUERY signatures_anagrams_longest
##  -
##  SELECT   Len([CONS]) AS Expr1,
##   Count(Cons_alpha_only_signature_unique.CONS) AS
CountOfCONS,
##   Cons_alpha_only_signature_unique.signature
##  FROM Cons_alpha_only_signature_unique
##  GROUP BY Len([CONS]),
##   Cons_alpha_only_signature_unique.signature
##  HAVING   (((Count(Cons_alpha_only_signature_unique.CONS))>1))
##  ORDER BY Len([CONS]) DESC ,
##   Count(Cons_alpha_only_signature_unique.CONS) DESC;
##
##  This is why I don't use SQLite3, must have crosstab queries.
##
##  QUERY signatures_anagram_summary
##  
##  TRANSFORM Count(signatures_anagrams_longest.signature) AS
CountOfsignature
##  SELECTsignatures_anagrams_longest.Expr1 AS [length of word]
##  FROM  signatures_anagrams_longest
##  GROUP BY  signatures_anagrams_longest.Expr1
##  PIVOT signatures_anagrams_longest.CountOfCONS;
##
##
##  QUERY signatures_anagrams_select_signature
##  --
##  SELECT   Len([CONS]) AS Expr1,
##   Count(Cons_alpha_only_signature_unique.CONS) AS
CountOfCONS,
##   Cons_alpha_only_signature_unique.signature
##  FROM Cons_alpha_only_signature_unique
##  GROUP BY Len([CONS]),
##   Cons_alpha_only_signature_unique.signature
##  HAVING   (((Len([CONS]))=9) AND
##((Count(Cons_alpha_only_signature_unique.CONS))=10))
##  ORDER BY Len([CONS]) DESC ,
##   Count(Cons_alpha_only_signature_unique.CONS) DESC;
##
##  QUERY signatures_lookup_by_anagram_select_signature
##  ---
##  SELECT signatures_anagrams_s

Re: Does PIL work with Tk 8.5?

2008-01-07 Thread Martin v. Löwis
> Tk itself has a stubs mechanism that allows libraries compiled against
> earlier versions to be used with later versions. It's different than
> Python in this respect. A pure-Tk library (such as Img or TkPNG) built
> against Tk 8.4 would not require re-compilation to be used with 8.5.
> Since PIL is a Python library, however, you may be right.

But aren't the older binaries linked, in a hard-coded manner, against
libtk8.4.so.0 (or .dylib)? If so, how does it help that the Tcl stub
layer could still provide binary compatibility? Won't the operating
system load and use the older Tk version *anyway*?

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


Re: How to refer to the current module?

2008-01-07 Thread Stargaming
On Mon, 07 Jan 2008 05:21:42 -0800, Mike wrote:

> I want to do something like the following (let's pretend that this is in
> file 'driver.py'):
> 
> #!/bin/env python
> 
> import sys
> 
> def foo():
> print 'foo'
> 
> def bar(arg):
> print 'bar with %r' % arg
> 
> def main():
> getattr(driver, sys.argv[1])(*sys.argv[2:])
> 
> if __name__=='__main__':
> main()
> 
> 
> Essentially what I'm trying to get at here is dynamic function
> redirection, like a generic dispatch script.  I could call this as
> 
> python driver.py foo
> 
> or
> 
> python driver.py bar 15
> 
> and at any time later I can add new functions to driver.py without
> having to update a dispatch dict or what-have-you.
> 
> The problem is, 'driver' doesn't exist in main() line 1.  If I 'import
> driver' from the command line, then getattr(driver, ...) works, but it's
> not bound here.
> 
> Is there any way around this?  Can I somehow scope the 'current module'
> and give getattr(...) an object that will (at run time) have the
> appropriate bindings?
> 
> Thanks in advance for all advice!
> 
> Mike

`__main__` (after you did ``import __main__``) could be an option as 
well. But I'd prefer a custom dictionary for your dispatch, rather than 
some magic with the module's names.

See http://docs.python.org/ref/programs.html for details on __main__.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does PIL work with Tk 8.5?

2008-01-07 Thread Kevin Walzer
Kevin Walzer wrote:

> 
> Tk itself has a stubs mechanism that allows libraries compiled against 
> earlier versions to be used with later versions. It's different than 
> Python in this respect. A pure-Tk library (such as Img or TkPNG) built 
> against Tk 8.4 would not require re-compilation to be used with 8.5. 
> Since PIL is a Python library, however, you may be right.
> 

Indeed, this appears to be the problem. I tested my script against the 
Python bundled with Mac OS X, which links against 8.4, and it worked fine.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's great, in a word

2008-01-07 Thread MRAB
On Jan 7, 5:40 pm, Martin Marcher <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > The best thing about Python is ___.
>
> it's pythonicness.
>
I think it sounds better as "its pythonicity".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's great, in a word

2008-01-07 Thread Carl Banks
On Jan 7, 8:09 am, [EMAIL PROTECTED] wrote:
> I'm a Java guy who's been doing Python for a month now and I'm
> convinced that
>
> 1) a multi-paradigm language is inherently better than a mono-paradigm
> language
>
> 2) Python writes like a talented figure skater skates.
>
> Would you Python old-timers try to agree on a word or two that
> completes:
>
> The best thing about Python is ___.
>
> Please, no laundry lists, just a word or two. I'm thinking "fluid" or
> "grace" but I'm not sure I've done enough to choose.

"it doesn't suck".


(Really.  All programming languages have good, useful features.  Even
Perl.  Python is unique in having no very bad ones.)

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


Modules and descriptors

2008-01-07 Thread Chris Leary
As I understand it, the appeal of properties (and descriptors in
general) in new-style classes is that they provide a way to
"intercept" direct attribute accesses. This lets us write more clear
and concise code that accesses members directly without fear of future
API changes.

I love this feature of the language, but find that I still have to
call getter/setter methods of module instances. Since module
attributes are accessed by way of __dict__ and the module type has a
valid __mro__, why doesn't the descriptor protocol apply to module
instances?

TIA!

P.S. There is some previous discussion in comp.lang.python about using
a module like a new-style class.

http://groups.google.com/group/comp.lang.python/browse_thread/thread/bce6c6fba7c06e72/b3a5cd10223d?lnk=gst&q=%09%0D%0AModule+level+descriptors+or+properties

http://groups.google.com/group/comp.lang.python/browse_thread/thread/20c14ffb99f85320/49d0087c269b8296?lnk=gst&q=module+properties

http://groups.google.com/group/comp.lang.python/browse_thread/thread/f41215a8fc475b7c/1690e6ddfbb257c7?lnk=gst&q=module+__call__

The suggested solution is always to provide a class wrapper in the
module itself, and have the module-user instantiate it appropriately.
This is a valid solution, but doesn't ensure that the client will use
it (the descriptor protocol does, as a feature of the language). As a
result, changes like these can break existing code that uses the
module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open source English dictionary to use programmatically w/ python

2008-01-07 Thread Paul McGuire
On Jan 7, 5:10 pm, dgoldsmith_89 <[EMAIL PROTECTED]> wrote:
>
> Sorry for my ignorance: I can query an Access DB w/ standard SQL
> queries (and this is how I would access it w/ Python)?
>
> DG

If you are running on a Mac, just use sqlite, it's built-in to Python
as of v2.5 and you will find more help, documentation, and fellow
Python+sqlite users than you will Python+Access.

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


Re: Python's great, in a word

2008-01-07 Thread Joe Riopel
On Jan 7, 2008 8:09 AM,  <[EMAIL PROTECTED]> wrote:
> The best thing about Python is ___.

it's mailing list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does PIL work with Tk 8.5?

2008-01-07 Thread Kevin Walzer
Martin v. Löwis wrote:

> OTOH, it's more likely that the PIL binaries you are using conflict with
> your Tk installation - if the binaries were for Tk 8.4 (which isn't
> quite clear to me whether that's indeed the case), then they can't work
> with Tk 8.5, as Tk doesn't provide that kind of binary compatibility.

Tk itself has a stubs mechanism that allows libraries compiled against 
earlier versions to be used with later versions. It's different than 
Python in this respect. A pure-Tk library (such as Img or TkPNG) built 
against Tk 8.4 would not require re-compilation to be used with 8.5. 
Since PIL is a Python library, however, you may be right.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open source English dictionary to use programmatically w/ python

2008-01-07 Thread dgoldsmith_89
On Jan 7, 2:54 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Jan 7, 4:37 pm, dgoldsmith_89 <[EMAIL PROTECTED]> wrote:
>
> > Can anyone point me to a downloadable open source English dictionary
> > suitable for programmatic use with python: I'm programming a puzzle
> > generator, and I need to be able to generate more or less complete
> > lists of English words, alphabetized.  Thanks!  DG
>
> www.puzzlers.orghas numerous word lists & dictionarys in text
> format that can be downloaded. I recommend you insert them into
> some form of database. I have most of them in an Access db and
> it's 95 MB. That's a worse case as I also have some value-added
> stuff, the OSPD alone would be a lot smaller.
>
> 

Sorry for my ignorance: I can query an Access DB w/ standard SQL
queries (and this is how I would access it w/ Python)?

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


Re: Open source English dictionary to use programmatically w/ python

2008-01-07 Thread dgoldsmith_89
On Jan 7, 2:47 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> dgoldsmith_89 wrote:
> > Can anyone point me to a downloadable open source English dictionary
> > suitable for programmatic use with python: I'm programming a puzzle
> > generator, and I need to be able to generate more or less complete
> > lists of English words, alphabetized.  Thanks!  DG
>
> here's one:
>
> http://www.dcs.shef.ac.uk/research/ilash/Moby/
>
> 

Excellent, that'll do nicely!  Thanks!!!

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


Re: Does PIL work with Tk 8.5?

2008-01-07 Thread Martin v. Löwis
> Since Python itself is the same version number (2.5.1), the only thing I
> can find to account for the crash is the different version of Tk--could
> this be making a difference, or am I doing something wrong?

Yes, Tk 8.5 isn't quite compatible with existing Tkinter code; there
have been a lot of changes which break Tkinter applications (though not
Tkinter itself).

OTOH, it's more likely that the PIL binaries you are using conflict with
your Tk installation - if the binaries were for Tk 8.4 (which isn't
quite clear to me whether that's indeed the case), then they can't work
with Tk 8.5, as Tk doesn't provide that kind of binary compatibility.

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


Re: What is the encoding of __file__?

2008-01-07 Thread Martin v. Löwis
> Thanks, I'll then use sys.getfilesystemencoding() to decode _file__
> and re-encode into utf-8, which is the default encoding of all strings
> in our software, as we deal a bit with Chinese terms.
> 
> Windows-1252 on my box. I just created a directory containing Chinese
> characters (on Vista), and whoa, files opened with IDLE are empty,
> import doesn't find modules in that directory. Of course Windows-1252
> can't encode these ...
> 
> But I understand that Python 3 will clean this up?

In theory, yes. The current implementation doesn't.

Contributions are welcome.

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


Re: Tkinter variable trace problem

2008-01-07 Thread Fredrik Lundh
C Martin wrote:

> What am I doing wrong in this code? The callback doesn't work from the Entry 
> widget.
> 
> ##start code
> import Tkinter
>   
> tk = Tkinter.Tk()
> var = Tkinter.StringVar()
> print var._name
> 
> def cb(name, index, mode):
>   print "callback called with name=%r, index=%r, mode=%r" % (name, index, 
> mode)
>   varValue = tk.getvar(name)
>   print "and variable value = %r" % varValue

iirc, getvar only looks at local Tcl variables when used inside a 
callback.  variables created with StringVar are global Tcl variables.

but instead of monkeying around at the Tcl level, why not just solve 
this on the Python level instead?

 def cb(variable, name, index, mode):
 ...

 var.trace('w', lambda *args: cb(var, *args)) # or some variation 
thereof

(and for this specific case, Entry content tracking, binding to 
KeyRelease and possibly also ButtonRelease is usually good enough).



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


Re: Open source English dictionary to use programmatically w/ python

2008-01-07 Thread [EMAIL PROTECTED]
On Jan 7, 4:37 pm, dgoldsmith_89 <[EMAIL PROTECTED]> wrote:
> Can anyone point me to a downloadable open source English dictionary
> suitable for programmatic use with python: I'm programming a puzzle
> generator, and I need to be able to generate more or less complete
> lists of English words, alphabetized.  Thanks!  DG


www.puzzlers.org has numerous word lists & dictionarys in text
format that can be downloaded. I recommend you insert them into
some form of database. I have most of them in an Access db and
it's 95 MB. That's a worse case as I also have some value-added
stuff, the OSPD alone would be a lot smaller.


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


Re: Open source English dictionary to use programmatically w/ python

2008-01-07 Thread dgoldsmith_89
On Jan 7, 2:46 pm, Rick Dooling <[EMAIL PROTECTED]> wrote:
> On Jan 7, 4:37 pm, dgoldsmith_89 <[EMAIL PROTECTED]> wrote:
>
> > Can anyone point me to a downloadable open source English dictionary
> > suitable for programmatic use with python: I'm programming a puzzle
> > generator, and I need to be able to generate more or less complete
> > lists of English words, alphabetized.  Thanks!  DG
>
> On Linux?  WordNet and Dict  and many others.
>
> On Windows, maybe try WordWeb?
>
> rd

Sorry, didn't know it would make a difference: on Mac, actually.

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


Re: Open source English dictionary to use programmatically w/ python

2008-01-07 Thread Rick Dooling
On Jan 7, 4:37 pm, dgoldsmith_89 <[EMAIL PROTECTED]> wrote:
> Can anyone point me to a downloadable open source English dictionary
> suitable for programmatic use with python: I'm programming a puzzle
> generator, and I need to be able to generate more or less complete
> lists of English words, alphabetized.  Thanks!  DG

On Linux?  WordNet and Dict  and many others.

On Windows, maybe try WordWeb?

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


Re: Open source English dictionary to use programmatically w/ python

2008-01-07 Thread Fredrik Lundh
dgoldsmith_89 wrote:

> Can anyone point me to a downloadable open source English dictionary
> suitable for programmatic use with python: I'm programming a puzzle
> generator, and I need to be able to generate more or less complete
> lists of English words, alphabetized.  Thanks!  DG

here's one:

http://www.dcs.shef.ac.uk/research/ilash/Moby/



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


Open source English dictionary to use programmatically w/ python

2008-01-07 Thread dgoldsmith_89
Can anyone point me to a downloadable open source English dictionary
suitable for programmatic use with python: I'm programming a puzzle
generator, and I need to be able to generate more or less complete
lists of English words, alphabetized.  Thanks!  DG
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the encoding of __file__?

2008-01-07 Thread anne . nospam01
On 7 Jan., 23:06, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > can someone quickly tell me what the encoding of __file__ is? I can't
> > find it in the documentation.
>
> > BTW, I'm using Python 2.5.1 on WIndows XP and Vista.
>
> It's platform-specific - the same encoding that is used for file names
> (i.e. sys.getfilesystemencoding()). On Windows, it will be "mbcs", which
> in turn is installation-specific - on Western European/US installations,
> it's "windows-1252".

Thanks, I'll then use sys.getfilesystemencoding() to decode _file__
and re-encode into utf-8, which is the default encoding of all strings
in our software, as we deal a bit with Chinese terms.

Windows-1252 on my box. I just created a directory containing Chinese
characters (on Vista), and whoa, files opened with IDLE are empty,
import doesn't find modules in that directory. Of course Windows-1252
can't encode these ...

But I understand that Python 3 will clean this up?

Kind regards,
Sebastian
-- 
http://mail.python.org/mailman/listinfo/python-list


Does PIL work with Tk 8.5?

2008-01-07 Thread Kevin Walzer
I'm using a build of Python 2.5.1 on OS X 10.5.1 that links to Tk 8.5. 
Trying to test PIL with this new build, Python barfs when trying to 
display an image in a Tkinter Label. Here is my sample code:

---
from Tkinter import *
import Image, ImageTk

root = Tk()

im = Image.open('/Users/kevin/Desktop/to.jpg')
newim = im.resize((16, 16))

labelimage = ImageTk.PhotoImage(newim)

w = Label(root,  text="My Test Icon", image=labelimage, width=100)
w.image=labelimage
w.pack()

mainloop()
--

Here's the error message:

Macintosh:Desktop kevin$ python iconlabel.py
alloc: invalid block: 0x5c32b4: 5d 0 0

Abort trap
Macintosh:Desktop kevin$


The build of PIL was made against the pre-compiled binary of Python for 
OS X (from python.org) that links to Tk 8.4.

Since Python itself is the same version number (2.5.1), the only thing I 
can find to account for the crash is the different version of Tk--could 
this be making a difference, or am I doing something wrong?

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter variable trace problem

2008-01-07 Thread C Martin
What am I doing wrong in this code? The callback doesn't work from the Entry 
widget.

##start code
import Tkinter
  
tk = Tkinter.Tk()
var = Tkinter.StringVar()
print var._name

def cb(name, index, mode):
  print "callback called with name=%r, index=%r, mode=%r" % (name, index, mode)
  varValue = tk.getvar(name)
  print "and variable value = %r" % varValue

var.trace('w', cb)

var.set('test')
entry = Tkinter.Entry(tk, textvariable=var)
entry.pack()

tk.mainloop()
##end code

It produces the following output. The first three lines appear right away, and 
the exception occurs when you type in the entry widget:

>test.py
PY_VAR0
callback called with name='PY_VAR0', index='', mode='w'
and variable value = 'test'
callback called with name='PY_VAR0', index='', mode='w'
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
return self.func(*args)
  File "D:\APCC\Projects\Utilities\VisualData\test.py", line 9, in cb
varValue = tk.getvar(name)
  File "C:\Python25\lib\lib-tk\Tkinter.py", line 421, in getvar
return self.tk.getvar(name)
TclError: can't read "PY_VAR0": no such variable

>



--
Protect yourself from spam, 
use http://sneakemail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the encoding of __file__?

2008-01-07 Thread Martin v. Löwis
> can someone quickly tell me what the encoding of __file__ is? I can't
> find it in the documentation.
> 
> BTW, I'm using Python 2.5.1 on WIndows XP and Vista.

It's platform-specific - the same encoding that is used for file names
(i.e. sys.getfilesystemencoding()). On Windows, it will be "mbcs", which
in turn is installation-specific - on Western European/US installations,
it's "windows-1252".

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


What is the encoding of __file__?

2008-01-07 Thread anne . nospam01
Dear all,

can someone quickly tell me what the encoding of __file__ is? I can't
find it in the documentation.

BTW, I'm using Python 2.5.1 on WIndows XP and Vista.

Kind regards,
Sebastian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's great, in a word

2008-01-07 Thread James Matthews
Just Another Vague Acronym = (Java)

On Jan 7, 2008 10:32 PM, Ben Finney <[EMAIL PROTECTED]>
wrote:

> [EMAIL PROTECTED] writes:
>
> > The best thing about Python is ___.
>
> The best thing about Python is its elegance.
>
> --
>  \"Like the creators of sitcoms or junk food or package tours, |
>  `\ Java's designers were consciously designing a product for |
> _o__)people not as smart as them."  -- Paul Graham |
> Ben Finney
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://search.goldwatches.com/?Search=Movado+Watches
http://www.jewelerslounge.com
http://www.goldwatches.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python's great, in a word

2008-01-07 Thread Ben Finney
[EMAIL PROTECTED] writes:

> The best thing about Python is ___.

The best thing about Python is its elegance.

-- 
 \"Like the creators of sitcoms or junk food or package tours, |
  `\ Java's designers were consciously designing a product for |
_o__)people not as smart as them."  -- Paul Graham |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python cache the startup module?

2008-01-07 Thread Baz Walter
John Machin  lexicon.net> writes:
> If you execute that stuff inside a function (see below) instead of in
> global scope, do you get the same effect?

Thanks for your reply.

No, running it inside a function means I can't rely on python to garbage 
collect, so there will be widgets left over whether I've changed names or not.

See Frederik Lundh's last message to see what's really happening.


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


Re: Does Python cache the startup module?

2008-01-07 Thread Baz Walter
Fredrik Lundh  pythonware.com> writes:
> So what you're concerned about is the lack of cleanup during interpreter 
> shutdown, not a true leak (which would result in "Max widgets" growing 
> towards infinity).

Yes, sorry about my sloppy terminology.

> The problem here is that you're relying on Python's GC to remove things 
> in a given order during shutdown, something that may or may not happen
> depending on lots of things that you cannot control:
> 
>  http://www.python.org/doc/essays/cleanup/
> 
> (Note the repeated use of "In an order determined by the dictionary 
> hashing of the names" in that article.)
> 
> The only way to get *predictable* shutdown behaviour in situations like 
> this is to clean things up yourself.  But in this case, you might as 
> well leave the cleanup to the OS.

I think you've found the real cause. I changed the name from 'mainwidget' 
to 'aaa' and the problem went away. I will have to investigate whether there is 
anything I can do from the Qt side to make sure things get cleaned up more 
predictably.

Many Thanks




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


Re: Python's great, in a word

2008-01-07 Thread Stefan Behnel
Henry Chang wrote:
> On Jan 7, 2008 5:41 AM, alain <[EMAIL PROTECTED]> wrote:
>> Paraphrasing Steve Jobs but in this context:
>> PYTHON = a bycycle for the mind
> What exactly does it mean "a bycycle for the mind"??

Ask the Dutch guy near you.

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


Re: Python's great, in a word

2008-01-07 Thread Pablo Ziliani
Dustan wrote:
> On Jan 7, 11:40 am, Martin Marcher <[EMAIL PROTECTED]> wrote:
>   
>> it's pythonicness.
>> 
>
> "it is pythonicness"???
>   

Obviously a typo, for "It is pythonic, Ness".
A reference to the well-known Loch Ness Monster, definitely pythonic if 
you see some pictures:
http://images.google.com/images?q=loch+ness


My 2 cents,
Pablo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's great, in a word

2008-01-07 Thread Martin Marcher
On Monday 07 January 2008 21:25 Dustan wrote:

> On Jan 7, 11:40 am, Martin Marcher <[EMAIL PROTECTED]> wrote:
>> it's pythonicness.
> 
> "it is pythonicness"???

not all here are native english speakers, but thanks for the correction.
I'll try to keep it in mind.

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Killing worker threads

2008-01-07 Thread Ruediger
maybe following recipe from activestate may be usefull.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960
http://sebulba.wikispaces.com/recipe+thread2



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


Re: TIOBE declares Python as programming language of 2007!

2008-01-07 Thread Richard Jones
Berco Beute wrote:
> What I would like to know is what it was that boosted Python's
> popularity in 2004 (see http://www.tiobe.com/tiobe_index/Python.html).
> Equally interesting is the question why it dropped shortly after.

They explain the discontinuity on the index page in the FAQ.


Richard


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


Tutorials at PyCon 2008 (US)

2008-01-07 Thread Greg Lindstrom
Hello Everyone-

I'd like to announce the tutorials sessions for PyCon 2008 (US).  As you may
know, this year PyCon is being held in Chicago, Illinois March 14-16 with
the Thursday before (the 13th) being "Tutorial Thursday".  We are expecting
nearly 600 Python enthusiasts to meet up for the conference and have 29
tutorial sessions scheduled on Thursday in three sessions; morning,
afternoon, and evening.  There is an extra fee to attend a tutorial, but the
sessions are 3 hours long (with a break) and are taught by some of the
smartest cookies in the Python community.  Pop on over to
http://us.pycon.org/2008/about/ for more information

Here's a list of the sessions currently offered (we may cancel a session if
there are fewer than 10 people registered, but that doesn't happen very
often). In particular, note that there are 4 different introduction to
Python tutorials aimed at different audiences.

*Morning Session* (9:00am-12:20pm)

   - Eggs and Buildout Deployment in
Python(Jeff Rush)
   - Python 101 for
Programmers(Steve
Holden)
   - Introduction to
SQLAlchemy(Jonathan
Ellis and and Michael Baye)
   - Python plotting with matplotlib and
pylab(John Hunter)
   - SWIG Master Class
(David Beazley)
   - Secrets of the Framework
Creators(Feihong
Hsu)
   - Introduction to
NumPy(Travis Oliphant
and Eric Jones)
   - Making Small Software for Small People, Sugar/OLPC Coding by
Example(Mike C.
Fletcher)
   - Hands-on Python for the Absolute Beginner
I(Dr. Andrew
Harrington)

*Afternoon Session* (1:20pm-4:40pm)

   - Python 101
(Stuart
Williams)
   - Getting Started with Pylons/TurboGears2 & WSGI: Modern Python Web
   Development  (Mark
   Ramm and Ben Bangert)
   - Advanced 
SQLAlchemy(Jonathan
Ellis and and Michael Baye)
   - Django Tutorial
(Jacob Kaplan-Moss)
   - wxPython I: Intro to GUI Programming with wxPython and
MVC(David
Goodger)
   - Faster Python Programs through Optimization and Extensions
I(Mike
Müller)
   - Tools for Scientific Computing in
Python(Travis
Oliphant and Eric Jones)
   - Generator Tricks for Systems
Programmers(David
Beazley)
   - Basic Python for Java
Programmers(Alex
Martelli and Anna Ravenscroft)
   - Hands-on Python for the Absolute Beginner
II(Dr.
Andrew Harrington)

*Evening Session* (6:10pm-9:30pm)

   - Python 102
(Stuart
Williams)
   - Mastering Pylons and TurboGears 2: Moving Beyond the
Basics.(Mark Ramm,
Ben Bangert)
   - Practical Applications of Agile (Web) Testing
Tools(C. Titus
Brown and Grig Gheorghiu)
   - Django Code Lab
(Jacob Kaplan-Moss,
Adrian Holovaty and James Bennett)
   - wxPython II: Advanced GUI Programming with wxPython and
MVC(David
Goodger)
   - Faster Python Programs through Optimization and Extensions
II(Mike
Müller)
   - Automating Windows Applications with
win32com(Roy H.
Han)
   - Internet Programming with
Python(Wesley
J. Chun)
   - Tail Wags Fangs: What Python Developers Should Know About
Plone(Rob Lineberger)
   - Pygame: Modern game
development(Noah
Kantrowitz and Marc Destefano)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() shorthand

2008-01-07 Thread Tim Chase
> The idea is a shorthand for reduce.  Here, _next_ meant the next item
> in the iterable c.

You mean like one of these:

   def lookahead(iterator):
 i = iter(iterator)
 x = i.next()
 for item in i:
   yield x, item
   x = item

   def lookahead2(iterator, **kwarg):
 i = iter(iterator)
 if 'initial' in kwarg:
   x = kwarg['initial']
 else:
   x = i.next()
 for item in i:
   yield x, item
   x = item
 if 'last' in kwarg:
   yield x, kwarg['last']

   print 'lookahead()'
   for this, next in lookahead([1,2,3,4,5]):
 print this, next

   print 'lookahead2()'
   for this, next in lookahead2([1,2,3,4,5]):
 print this, next

   print 'lookahead2(initial=42)'
   for this, next in lookahead2([1,2,3,4,5], initial=42):
 print this, next

   print 'lookahead2(last=42)'
   for this, next in lookahead2([1,2,3,4,5], last=42):
 print this, next

   print 'lookahead2(initial=3.14159, last=42)'
   for this, next in lookahead2([1,2,3,4,5],
   initial=3.14159, last=42):
 print this, next


There are some alternate behaviors that can happen at the end 
points, so depending on which behavior you want, the lookahead() 
is cleanest, but doesn't allow you to handle edge cases.  The 
lookahead2() is a little more complex, but allows you to specify 
a first item for pairing (so "next" touches every item in your 
list) or a trailing element (so "this" touches every item).

-tkc






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


Re: any() and all() shorthand

2008-01-07 Thread castironpi
On Jan 7, 1:45 pm, [EMAIL PROTECTED] wrote:
> On Jan 7, 1:29 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>
> The idea is a shorthand for reduce.  Here, _next_ meant the next item
> in the iterable c.

'Only' is another known quantifier in logic: 'all and only'.  Any
(there exists) and all (for all) are too.  'Only' (and not others)
could be useful, from the theoretical standpoint.  But where?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's great, in a word

2008-01-07 Thread Dustan
On Jan 7, 11:40 am, Martin Marcher <[EMAIL PROTECTED]> wrote:
> it's pythonicness.

"it is pythonicness"???
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python cache the startup module?

2008-01-07 Thread John Machin
On Jan 8, 6:21 am, Baz Walter <[EMAIL PROTECTED]> wrote:
> Guilherme Polo  gmail.com> writes:
>
> > Uhm.. this didn't make much sense. If you say the module is cached,
> > then supposing you did a minor edit, and then supposing because it is
> > cached your application wouldn't detect the change, then I don't see
> > the connection with memory leak.
>
> > Bring some concrete proof.
>
> Thanks for your reply.
>
> It's hard to supply an example for this, since it is local to the machine I am
> using. The startup module would look something like this:
>
> #!/usr/local/bin/python
>
> if __name__ == '__main__':
>
> import sys
> from qt import QApplication, QWidget
>
> application = QApplication(sys.argv)
> mainwindow = QWidget()
> application.setMainWidget(mainwindow)
> mainwindow.show()
> sys.exit(application.exec_loop())
>
> If I change the name 'mainwindow' to 'mainwidget', the widget it refers to 
> does
> not get destroyed; when I change it back again, it does get destroyed.
> Otherwise, the program runs completely normally.

If you execute that stuff inside a function (see below) instead of in
global scope, do you get the same effect?

if __name__ == '__main__':
import sys

def main():
from qt import QApplication, QWidget
application = QApplication(sys.argv)
mainwindow = QWidget()
application.setMainWidget(mainwindow)
mainwindow.show()
result = application.exec_loop())
return result

sys.exit(main())
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python cache the startup module?

2008-01-07 Thread Fredrik Lundh
Baz Walter wrote:

> Before changing the name 'mainwindow' to 'mainwidget' it reports:
> 
> Widgets left: 0Max widgets: 2
> Widgets left: 0Max widgets: 149 (full program)
> 
> Afterwards it reports:
> 
> Widgets left: 1Max widgets: 2
> Widgets left: 146Max widgets: 149 (full program)

So what you're concerned about is the lack of cleanup during interpreter 
shutdown, not a true leak (which would result in "Max widgets" growing 
towards infinity).

The problem here is that you're relying on Python's GC to remove things 
in a given order during shutdown, something that may or may not happen
depending on lots of things that you cannot control:

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

(Note the repeated use of "In an order determined by the dictionary 
hashing of the names" in that article.)

The only way to get *predictable* shutdown behaviour in situations like 
this is to clean things up yourself.  But in this case, you might as 
well leave the cleanup to the OS.



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


Any interest in an SQS alternative???

2008-01-07 Thread cbmeeks
I'm a big fan of Amazon's SQS web services.  However, I think their
SQS is simply too expensive.  I was doing some tests in python using
SQS and created 1,513 messages in just a few minutes.  Then I looked
at my bill.  It was $0.15 not counting the S3 fee.

$0.15 seems like a lot to me for the application I was writing.  The
application was designed to create MANY MANY small messages.  SQS
allows you to store up to 256k in one message which is pretty cool.
But my app only needed to store URL's.  They were all under 64 bytes.

Granted, I assume most people take that 256k and intelligently handle
many messages in one.  For example, a photo sharing site would
probably store the ID's to maybe 10-50 pictures in one message and
another server would process those pictures as one job.

But surely, I'm not the only one out there that would rather create
10,000 messages that are very small vs 1,000 messages that are
larger?  Or am I?

So anyway, I wrote my own message passing class that works pretty
well.  It is "my" message passing system...as in, message passing for
what I need.

But maybe others need too?

I am seriously thinking of putting it live and let people play around
with it...as an experiment.

I hope this post doesn't come across as spam or "trolley" because I
will probably ask the PHP and Ruby guys too.

My goal for "myself" would be to create a system that is at least half
of what SQS charges.  I know I can't compete with the giant Amazon but
who knows...

Anyway, if anyone has any interest please let me know.  If no one
cares, then I guess I will use it all for myself.  hahaha

Feel free to email me directly too.

cbmeeks  [AT]   gmail.com

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


Re: TIOBE declares Python as programming language of 2007!

2008-01-07 Thread Bruno Desthuilliers
Diez B. Roggisch a écrit :
> Berco Beute schrieb:
> 
>> Cool! We knew it would happen one day :)
>> What could be the reason? Python 3? Jython 2.2? Java's loss of
>> sexiness?
> 
> 
> I'd say Java was never sexy, but dressed up in expensive lingerie by 
> marketing maniacs...

+2 QOTW

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


Re: TIOBE declares Python as programming language of 2007!

2008-01-07 Thread ajaksu
On Jan 7, 9:53 am, Berco Beute <[EMAIL PROTECTED]> wrote:
> Cool! We knew it would happen one day :)
> What could be the reason? Python 3? Jython 2.2? Java's loss of
> sexiness?
>
> What I would like to know is what it was that boosted Python's
> popularity in 2004 (seehttp://www.tiobe.com/tiobe_index/Python.html).
> Equally interesting is the question why it dropped shortly after.
>
> 2B

>From  http://www.tiobe.com/index.htm?tiobe_index(and
http://www.tiobe.com/tiobe_index/images/tpci_trends.png )

# Q: What happened to Java in April 2004? Did you change your
methodology?

A: No, we did not change our methodology at that time. Google changed
its methodology. They performed a general sweep action to get rid of
all kinds of web sites that had been pushed up. As a consequence,
there was a huge drop for languages such as Java and C++. In order to
minimize such fluctuations in the future, we added two more search
engines (MSN and Yahoo) a few months after this incident.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary/hash and '1' versus 1

2008-01-07 Thread Paddy
On Jan 7, 7:26 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:python-
> > [EMAIL PROTECTED] On Behalf Of Paddy
> > Sent: Monday, January 07, 2008 12:52 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: dictionary/hash and '1' versus 1
>
> > Or how using different operators for similar operations on different
> > types causes confusion.
> > i.e. == versus eq; > versus gt
> > If Perl had, for example, a complex number 'base' type would that need
> > yet another set of operators?
>
> The real question is: what's the simplest way to implement complex
> numbers without sacrificing understanding, accuracy, and convenience?  I
> would say, no new operators.  Imaginary numbers are numbers and should
> use numeric operations which means overloaded match operators.
>
> As background:  In order to keep things simple, Perl's string operators
> are string-like.  Math operators are math.
> '2' * 5 = 10
> '2' x 5 = '2'  ('x' is a char, so think strings)
> ==, >, >=, <, <=
> eq, gt, ge, lt, le (string abbreviations for equal, greater
> than, etc.)
> '1' + 1 = 2
> '1' . 1 = 11(Think period at the end of a sentence, which
> implies stringing strings together.)
>
> > Well enough Perl vs Python. The thing is, that when writing in another
> > programming language you have to use its idioms or you end up fighting
> > the language in attempt to make it work like another language you are
> > more familiar with. In Python strings won't ever automatically change
> > to numbers.
>
> Agreed.  However looking towards the future (new versions of
> Perl/Python, new languages, new paradigms) is it worth asking whether
> it's better/clearer/easier/more_accurate to
> a) type cast the data: a + b  (a and b must be of the same type)
>
> a.1)  explicitly type cast the data:  str(a) + str(b)
> (if a and b are different types)
> b) type cast by operator: '1' + 1 = 2; '1' . 1 = '11'
> c) go really old school with: concat('1', 1); add('1', 1)
>
> IMO, since Python is strongly but dynamically typed, a) is the 'worst'
> solution.  If you forget to type cast, you're boned, since you probably
> won't find the problem until the code block is actually executed and an
> exception is thrown.  You could defensively type cast everything, but
> that can clutter the code, and cluttered code is harder to understand
> and keep bug free.  With b) or c), the compiler will type cast as you
> intended.  Again, just my opinion.
>
> Anyway, it's little things like '1' + 1 that will probably prevent
> programming syntax from ever being similar to naturally spoken language.
>

I guess it comes down to the differences in fundamental principles of
Perl and Python. Perl is developed to "Do what I mean", whereas Python
would be more like "Do as I say". Perl strives to be more like a
spoken language, Python strives to have a core set of powerful &
composable ideas.

On your specific example I'd guess that both schemes work well its
just that I am more comfortable with Pythons one set of more
overloaded operators and vice-versa for yourself, leading us both to
have problems when we switch between Perl and Python :-)

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


Re: Does Python cache the startup module?

2008-01-07 Thread Baz Walter
Fredrik Lundh  pythonware.com> writes:

> 
> Baz Walter wrote:
> 
> > It's hard to supply an example for this, since it is local to the machine I 
am 
> > using. The startup module would look something like this:
> 
> would look, or does look?  if it doesn't look like this, what else does 
> it contain?

What I did was create a minimal version of the module which still exhibits the 
same behaviour (for me, that is). Basically, QWidget in the example below 
replaces my MainWindow class.
 
> > #!/usr/local/bin/python
> > 
> > if __name__ == '__main__':
> > 
> > import sys
> > from qt import QApplication, QWidget
> > 
> > application = QApplication(sys.argv)
> > mainwindow = QWidget()
> > application.setMainWidget(mainwindow)
> > mainwindow.show()
> > sys.exit(application.exec_loop())
> > 
> > If I change the name 'mainwindow' to 'mainwidget', the widget it refers to 
does 
> > not get destroyed; when I change it back again, it does get destroyed. 
> > Otherwise, the program runs completely normally.
> 
> I don't see any code in there that destroys the widget, and I also don't 
> see any code in there that creates more than one instance of the main 
> widget.

Qt will try to destroy all widgets that are linked together in the object 
hierarchy.
 
> what do you do to run the code, and how to you measure leakage?

I run it with:

python app.py -widgetcount

The widgetcount switch is a Qt facility which counts how many widgets are 
created and how many destroyed.

Before changing the name 'mainwindow' to 'mainwidget' it reports:

Widgets left: 0Max widgets: 2
Widgets left: 0Max widgets: 149 (full program)

Afterwards it reports:

Widgets left: 1Max widgets: 2
Widgets left: 146Max widgets: 149 (full program)

> is the name "mainwidget" used for some other purpose in your application?

No



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


Re: any() and all() shorthand

2008-01-07 Thread castironpi
On Jan 7, 1:29 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> 2008/1/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> > > You are too late, any and all are built-in into python 2.5
>
> > Hi, excellent.  Now how about something more generic, possibly:
>
> > [ x.y() for x or _next_ in c ]
>
> > where the context of _next_ is limited in complexity, and/or can only
> > occur in a generator?
>
> Would you care to explain what that syntax supposedly means ? By
> _next_ you mean something like the next method in generators ? _next_
> executes if x is false ? so whatever _next_ returns is named as x, so
> you can call x.y() ? I really didn't get your new syntax inside that
> list comprehension, neither its uses.
>

The idea is a shorthand for reduce.  Here, _next_ meant the next item
in the iterable c.

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


Re: Does Python cache the startup module?

2008-01-07 Thread Fredrik Lundh
Baz Walter wrote:

> It's hard to supply an example for this, since it is local to the machine I 
> am 
> using. The startup module would look something like this:

would look, or does look?  if it doesn't look like this, what else does 
it contain?

> #!/usr/local/bin/python
> 
> if __name__ == '__main__':
> 
> import sys
> from qt import QApplication, QWidget
> 
> application = QApplication(sys.argv)
> mainwindow = QWidget()
> application.setMainWidget(mainwindow)
> mainwindow.show()
> sys.exit(application.exec_loop())
> 
> If I change the name 'mainwindow' to 'mainwidget', the widget it refers to 
> does 
> not get destroyed; when I change it back again, it does get destroyed. 
> Otherwise, the program runs completely normally.

I don't see any code in there that destroys the widget, and I also don't 
see any code in there that creates more than one instance of the main 
widget.

what do you do to run the code, and how to you measure leakage?

is the name "mainwidget" used for some other purpose in your application?



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


Re: any() and all() shorthand

2008-01-07 Thread Guilherme Polo
2008/1/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> > You are too late, any and all are built-in into python 2.5
>
> Hi, excellent.  Now how about something more generic, possibly:
>
> [ x.y() for x or _next_ in c ]
>
> where the context of _next_ is limited in complexity, and/or can only
> occur in a generator?

Would you care to explain what that syntax supposedly means ? By
_next_ you mean something like the next method in generators ? _next_
executes if x is false ? so whatever _next_ returns is named as x, so
you can call x.y() ? I really didn't get your new syntax inside that
list comprehension, neither its uses.

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


-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: dictionary/hash and '1' versus 1

2008-01-07 Thread Reedick, Andrew
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Paddy
> Sent: Monday, January 07, 2008 12:52 PM
> To: python-list@python.org
> Subject: Re: dictionary/hash and '1' versus 1
> 
> Or how using different operators for similar operations on different
> types causes confusion.
> i.e. == versus eq; > versus gt
> If Perl had, for example, a complex number 'base' type would that need
> yet another set of operators?

The real question is: what's the simplest way to implement complex
numbers without sacrificing understanding, accuracy, and convenience?  I
would say, no new operators.  Imaginary numbers are numbers and should
use numeric operations which means overloaded match operators. 

As background:  In order to keep things simple, Perl's string operators
are string-like.  Math operators are math.
'2' * 5 = 10
'2' x 5 = '2'  ('x' is a char, so think strings)
==, >, >=, <, <=
eq, gt, ge, lt, le (string abbreviations for equal, greater
than, etc.)
'1' + 1 = 2
'1' . 1 = 11(Think period at the end of a sentence, which
implies stringing strings together.) 


> Well enough Perl vs Python. The thing is, that when writing in another
> programming language you have to use its idioms or you end up fighting
> the language in attempt to make it work like another language you are
> more familiar with. In Python strings won't ever automatically change
> to numbers.

Agreed.  However looking towards the future (new versions of
Perl/Python, new languages, new paradigms) is it worth asking whether
it's better/clearer/easier/more_accurate to 
a) type cast the data: a + b  (a and b must be of the same type)

a.1)  explicitly type cast the data:  str(a) + str(b)
(if a and b are different types)
b) type cast by operator: '1' + 1 = 2; '1' . 1 = '11' 
c) go really old school with: concat('1', 1); add('1', 1)

IMO, since Python is strongly but dynamically typed, a) is the 'worst'
solution.  If you forget to type cast, you're boned, since you probably
won't find the problem until the code block is actually executed and an
exception is thrown.  You could defensively type cast everything, but
that can clutter the code, and cluttered code is harder to understand
and keep bug free.  With b) or c), the compiler will type cast as you
intended.  Again, just my opinion.

Anyway, it's little things like '1' + 1 that will probably prevent
programming syntax from ever being similar to naturally spoken language.


*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA621


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


PostgreSQL Conference East: Call for Papers

2008-01-07 Thread [EMAIL PROTECTED]
PostgreSQL Conference East is being held on the weekend of March 29th
and 30th, 2008 in College Park, Maryland. The conference will have a
series of talks, mini-tutorials and tutorials and we are now accepting
submissions!

If you are a third pary vendor, PostgreSQL developer, PostgreSQL
consultant, DBA, or just a user who really does cool stuff, you need
to
submit a talk, or tutorial.

Do you know how to get that last 20 transactions per second out of an
array using adaptive readahead? Maybe you know more about Autovacuum
than you ever care to admit? Perhaps, you have recently deployed
PostgreSQL and saved a company 300k over the next closest
competitor...

Now is your time to share, learn and participate in the community!
Submit your talk at:

http://www.postgresqlconference.org/talk_submission/ .

PostgreSQL Conference East is part of the PostgreSQL Community
Conference series. All proceeds from the conferences are donations to
PostgreSQL via the non-profit Software in the Public Interest a U.S.
501c3.

Sincerely,

Joshua D. Drake
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python cache the startup module?

2008-01-07 Thread Baz Walter
Guilherme Polo  gmail.com> writes:
> Uhm.. this didn't make much sense. If you say the module is cached,
> then supposing you did a minor edit, and then supposing because it is
> cached your application wouldn't detect the change, then I don't see
> the connection with memory leak.
> 
> Bring some concrete proof.

Thanks for your reply.

It's hard to supply an example for this, since it is local to the machine I am 
using. The startup module would look something like this:

#!/usr/local/bin/python

if __name__ == '__main__':

import sys
from qt import QApplication, QWidget

application = QApplication(sys.argv)
mainwindow = QWidget()
application.setMainWidget(mainwindow)
mainwindow.show()
sys.exit(application.exec_loop())

If I change the name 'mainwindow' to 'mainwidget', the widget it refers to does 
not get destroyed; when I change it back again, it does get destroyed. 
Otherwise, the program runs completely normally.


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


Re: Does Python cache the startup module?

2008-01-07 Thread kyosohma
On Jan 7, 12:30 pm, Baz Walter <[EMAIL PROTECTED]> wrote:
> Hello
>
> I remember reading somewhere (probably this list) that python may cache the
> module that starts a program (e.g. 'main.py'). I'm asking because I have found
> that this can sometimes cause problems when making small edits to the module.
> For instance, in my current module I changed the name of the main gui widget.
> When I ran the program, the program started to leak memory like a sieve. I 
> then
> changed the name back again, and the problem went away. This looks very much
> like some sort of weird caching behaviour to me.
>
> I've tried deleting the .pyc file and even re-booting, but I can't make the
> problem go away!
>
> Can anyone confirm that this caching happens? And if so, is it documented
> anywhere?
>
> TIA

You can run a dir() in the GUI IDLE or the command line IDLE and see
what's currently "cached", so to speak. In the GUI IDLE, you can
"flush" it out by going to the Shell menu and choosing Restart Shell.

It should only display the following after a restart:

>>> dir()
['__builtins__', '__doc__', '__name__']


HTH

Mike

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


Re: any() and all() shorthand

2008-01-07 Thread castironpi
> You are too late, any and all are built-in into python 2.5

Hi, excellent.  Now how about something more generic, possibly:

[ x.y() for x or _next_ in c ]

where the context of _next_ is limited in complexity, and/or can only
occur in a generator?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any() and all() shorthand

2008-01-07 Thread Guilherme Polo
2008/1/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> any( iterab ) and all( iterab )
>
> as shorthand for reduce( operator.or_, iterab ) and
> reduce( operator.and_, iterab ).
>
> What do you think?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

You are too late, any and all are built-in into python 2.5

-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python cache the startup module?

2008-01-07 Thread Guilherme Polo
2008/1/7, Baz Walter <[EMAIL PROTECTED]>:
> Hello
>
> I remember reading somewhere (probably this list) that python may cache the
> module that starts a program (e.g. 'main.py').

Something like mod_python will do caching.

> I'm asking because I have found
> that this can sometimes cause problems when making small edits to the module.
> For instance, in my current module I changed the name of the main gui widget.
> When I ran the program, the program started to leak memory like a sieve. I 
> then
> changed the name back again, and the problem went away. This looks very much
> like some sort of weird caching behaviour to me.

Uhm.. this didn't make much sense. If you say the module is cached,
then supposing you did a minor edit, and then supposing because it is
cached your application wouldn't detect the change, then I don't see
the connection with memory leak.

Bring some concrete proof.

>
> I've tried deleting the .pyc file and even re-booting, but I can't make the
> problem go away!
>
> Can anyone confirm that this caching happens? And if so, is it documented
> anywhere?
>
> TIA
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


any() and all() shorthand

2008-01-07 Thread castironpi
any( iterab ) and all( iterab )

as shorthand for reduce( operator.or_, iterab ) and
reduce( operator.and_, iterab ).

What do you think?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's great, in a word

2008-01-07 Thread George Sakkis
On Jan 7, 8:09 am, [EMAIL PROTECTED] wrote:

> I'm a Java guy who's been doing Python for a month now and I'm
> convinced that
>
> 1) a multi-paradigm language is inherently better than a mono-paradigm
> language
>
> 2) Python writes like a talented figure skater skates.
>
> Would you Python old-timers try to agree on a word or two that
> completes:
>
> The best thing about Python is ___.

... it's a pleasure to write *and* read.
... it keeps simple things simple and makes hard things doable.
... it's the language that sucks the least.

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


Does Python cache the startup module?

2008-01-07 Thread Baz Walter
Hello

I remember reading somewhere (probably this list) that python may cache the 
module that starts a program (e.g. 'main.py'). I'm asking because I have found 
that this can sometimes cause problems when making small edits to the module. 
For instance, in my current module I changed the name of the main gui widget. 
When I ran the program, the program started to leak memory like a sieve. I then 
changed the name back again, and the problem went away. This looks very much 
like some sort of weird caching behaviour to me.

I've tried deleting the .pyc file and even re-booting, but I can't make the 
problem go away!

Can anyone confirm that this caching happens? And if so, is it documented 
anywhere?

TIA


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


Re: I'm searching for Python style guidelines

2008-01-07 Thread Paul McGuire
On Jan 7, 12:26 pm, [EMAIL PROTECTED] wrote:
> Guilherme Polo wrote:
> > foo = [
> >     'too long',
> >     'too long too',
> >     ...
> >     ]
>
> OK, I'll put it there too, and it will be easy for us to read each
> other's code (at least in this particular).

While not required by any means, you will also find it handy to follow
*every* entry in the list with a comma, even the last one in the list
(this is legal Python).  That is, in your example:

 foo = [
 'too long',
 'too long too',
 'too long too',
 'last item',
 ]

Later on when you want to reorder the items, then you can just copy/
paste whole lines, even if moving to or from the bottom of the list.
This is also a good argument for putting the closing ']' on its own
line, instead of on the same line as the last item.

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


Re: I'm searching for Python style guidelines

2008-01-07 Thread MartinRinehart


Guilherme Polo wrote:
> foo = [
> 'too long',
> 'too long too',
> ...
> ]

OK, I'll put it there too, and it will be easy for us to read each
other's code (at least in this particular).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TIOBE declares Python as programming language of 2007!

2008-01-07 Thread George Sakkis
On Jan 7, 9:27 am, Kay Schluehr <[EMAIL PROTECTED]> wrote:

> On Jan 7, 12:53 pm, Berco Beute <[EMAIL PROTECTED]> wrote:
>
> > Cool! We knew it would happen one day :)
> > What could be the reason? Python 3? Jython 2.2? Java's loss of
> > sexiness?
>
> Python eats Perls lunch as a scripting language.

Even better, it is not threatened by Ruby as many from the buzzword-
ridden RoR crowd would like to believe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's great, in a word

2008-01-07 Thread Paddy
On Jan 7, 1:09 pm, [EMAIL PROTECTED] wrote:
> I'm a Java guy who's been doing Python for a month now and I'm
> convinced that
>
> 1) a multi-paradigm language is inherently better than a mono-paradigm
> language
>
> 2) Python writes like a talented figure skater skates.
>
> Would you Python old-timers try to agree on a word or two that
> completes:
>
> The best thing about Python is ___.
>
> Please, no laundry lists, just a word or two. I'm thinking "fluid" or
> "grace" but I'm not sure I've done enough to choose.

Concise!
See http://paddy3118.blogspot.com/2007_11_01_archive.html
For my search!

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


Re: dictionary/hash and '1' versus 1

2008-01-07 Thread Paddy
On Jan 7, 5:09 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:

> Bingo.  Perl has specific operators to establish intent:
> > Perl -e "'1' + 1"
> > 2
> > Perl -e "'1' . 1"
> > 11
> '+' is the operator for addition
> '.' is the operator for string concatenation
>
> int and string comparisons also have specific operators:
> $a == $b  # compare as integers:  ==,  >,  <, <=, >=
> $a eq $b  # compare as strings:   eq, gt, lt, le, ge
>
> Which now morphs the conversation into the issue of how too much
> operator overloading creates confusion and/or ambiguity.
>
Or how using different operators for similar operations on different
types causes confusion.
i.e. == versus eq; > versus gt
If Perl had, for example, a complex number 'base' type would that need
yet another set of operators?

Well enough Perl vs Python. The thing is, that when writing in another
programming language you have to use its idioms or you end up fighting
the language in attempt to make it work like another language you are
more familiar with. In Python strings won't ever automatically change
to numbers.

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


Re: Python's great, in a word

2008-01-07 Thread Martin Marcher
[EMAIL PROTECTED] wrote:
> The best thing about Python is ___.

it's pythonicness.

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Python's great, in a word

2008-01-07 Thread Henry Chang
What exactly does it mean "a bycycle for the mind"??

(assuming s/bycycle/bicycle)

On Jan 7, 2008 5:41 AM, alain <[EMAIL PROTECTED]> wrote:
> On Jan 7, 2:09pm, [EMAIL PROTECTED] wrote:
> > I'm a Java guy who's been doing Python for a month now and I'm
> > convinced that
> >
> > 1) a multi-paradigm language is inherently better than a mono-paradigm
> > language
> >
> > 2) Python writes like a talented figure skater skates.
> >
> > Would you Python old-timers try to agree on a word or two that
> > completes:
> >
> > The best thing about Python is ___.
> >
> > Please, no laundry lists, just a word or two. I'm thinking "fluid" or
> > "grace" but I'm not sure I've done enough to choose.
>
> Paraphrasing Steve Jobs but in this context:
> PYTHON = a bycycle for the mind
>
> Best regards
>
> Alain
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: dictionary/hash and '1' versus 1

2008-01-07 Thread Reedick, Andrew


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Steven D'Aprano
> Sent: Saturday, January 05, 2008 7:01 PM
> To: python-list@python.org
> Subject: Re: dictionary/hash and '1' versus 1
> 
> The problem with automatic conversions between strings and integers is
> that it isn't clear what the user wants when they do something like
> this:
> 
> >>> x = '1' + 1
> 
> Should x be the string '11' or the int 2? Please justify your answer.
> 
> 
> On the other hand, if the language includes separate operators for
> addition and concatenation (say, + and &) then that sort of auto-
> conversion is no longer ambiguous:
> 
> >>> '2' + 3
> 5
> >>> '2' & 3
> '23'


Bingo.  Perl has specific operators to establish intent:
> Perl -e "'1' + 1"
> 2
> Perl -e "'1' . 1"
> 11
'+' is the operator for addition
'.' is the operator for string concatenation

int and string comparisons also have specific operators:
$a == $b  # compare as integers:  ==,  >,  <, <=, >=
$a eq $b  # compare as strings:   eq, gt, lt, le, ge


Which now morphs the conversation into the issue of how too much
operator overloading creates confusion and/or ambiguity.



*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA623


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


Re: dictionary/hash and '1' versus 1

2008-01-07 Thread Sion Arrowsmith
 <[EMAIL PROTECTED]> wrote:
>In Java you can add the number 1 to a string, and have it
>automatically converted to string before the string join... What do
>you think of that feature?

"-%s" % 1

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
-- 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: Killing worker threads

2008-01-07 Thread kyosohma
On Jan 6, 7:48 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> tarun wrote:
> > Can anyone help me with a simple code through which the main thread can
> > kill the worker thread it started.
>
> it cannot.  threads cannot be killed from the "outside".
>
> 

The only way to "kill" a thread is to have the spawned thread have
some kind of passed in argument which will trigger it to shut down.
You could have the thread read a file or file-like object periodically
(like a timer) and if it meets some condition, have the thread quit.

It's kind of like a subscription process. The thread subscribes to the
main program and can accept signals. I suggest that the OP read the
docs on threads:

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

Of special interest to this user: 
http://docs.python.org/lib/condition-objects.html

I have messed with KillProcName, a PyWin32 script with limited
success. There's also the following snippet which is Windows only and
works for some processes and not others (i.e. unreliable):

subprocess.Popen('taskkill /s %s /im %s' % (computer_id, proc))

Hopefully I didn't muddy the waters or write something too off the
mark.

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


Re: python syntax

2008-01-07 Thread Fredrik Lundh
mpho raborife wrote:

> Please help me get this syntax right:
> 
> os.system("HCopy -T 1 -C" 'os.path.join(conf_dir,  "/hcopy.conf")' "-S" 
> 'os.path.join(list_dir, "hcopy_list.txt")')

instead of attempting to get your program working by random trial and 
error process, maybe you should spend an hour or two working through the 
examples in a nice tutorial?  I'd recommend the first few chapters of
Swaroop's "A Byte of Python".  Make sure you read at least "Basics" and 
"Operators and Expressions" before returning to the task at hand:

 http://www.ibiblio.org/swaroopch/byteofpython/read/



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


Re: I'm searching for Python style guidelines

2008-01-07 Thread Guilherme Polo
2008/1/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> Thank you both.
>
> Stupid me, went to Python.org and found Style Guidelines and thought
> that was the last word. Oh well.
>
> PEP 8 reminds me a lot of Sun's Java conventions, in ways I wish it
> didn't. The overall structure seems like a random list of topics and
> it omits a lot. For Java I went from Sun to other conventions to try
> to compile a meta-convention ( 
> http://www.MartinRinehart.com/articles/code-conventions.html
> ).
>
> Here's just one of my questions:
>
> foo = [
> 'some item, quite long',
> 'more items, all demanding there own line as they are not short',
> ...
>
> Where would you put the closing ']'?

I would put ']' at a new line:

foo = [
'too long',
'too long too',
...
]

I don't really believe it should exist style guidelines for everything
that is possible (or if it did I doubt it would matter), many/most
people adapt the guidelines to fetch their own style. That is not
really a problem if you are consistent during all the code, and if it
is not too ugly as well =)

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


-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm searching for Python style guidelines

2008-01-07 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Here's just one of my questions:
> 
> foo = [
> 'some item, quite long',
> 'more items, all demanding there own line as they are not short',
> ...
> 
> Where would you put the closing ']'?

on a line by itself, indented as your favourite Python editor indents it.



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


Re: list property fires get on append

2008-01-07 Thread Soviut
On Jan 6, 11:36 am, Carl Banks <[EMAIL PROTECTED]> wrote:
> On Sun, 06 Jan 2008 00:31:13 -0800, Soviut wrote:
> > I figured that an append would be treated as a set since I'm adding to
> > the list.  But what you say makes sense, although I can't say I'm happy
> > with the behaviour.  Is there any way I can get the append to fire a
> > set?  I'm thinking of properties from my C# background where i believe
> > that manipulation such this would be considered a set.
>
> You'd have to have to hook into the container object itself to detect the
> modification.  This might be pretty workable for you since it's an
> internal object.  Basically, instead of using a list, use a special list-
> like object that notifies it's owner when it changes.  Here's a simple
> example to point you in the right direction:
>
> class NotifierList(list):
>  def __init__(self,*args,**kwargs):
>  super(NotifierList,self).__init__(*args,**kwargs)
>  self.watchers = []
>  def add_watcher(self,watcher):
>  self.watchers.append(watcher)
>  def _notify_watchers(self):
>  for watcher in self.watchers:
>  watcher.object_changed(self)
>  def append(self,value):
>  super(NotifierList,self).append(value)
>  self._notify_watchers()
>  # override all other mutating calls, including __setitem__
>  # left as exercise
>
> class Hierarchy(object):
> def __init__(self):
> self.children = NotifierList()
> self.children.add_watcher(self)
> def object_changed(self,obj):
> print "self.children modified"
> # no need to make children a property then
> # unless you want to trap rebinding it to new object also
>
> A couple other minor suggestions:
>
> print is a statement, not a function.  You should write
>
> print "GETTING"
>
> not
>
> print("GETTING")
>
> The latter works, but it will cease to work if you want to print more
> than one thing.  Note that print is scheduled to become a function in
> Python 3.0, but for now it's a statement.
>
> Based on the name of your class and typical usage, I'm guessing that you
> probably want _children to be an instance attribute rather than a class
> attribute, so I redid it that way, but .)
>
> P.S. Is calling a method called "firing" in C#?
>
> Carl Banks

Thanks for the help, there's a lot to digest there but I realized that
I was having issues with _children being a class attribute when I
noticed every single instance had the same _children list.  I've since
moved things into my __init__ method.

Basically the reason I needed to use a property was to run a private
helper method that sets references to the parent and root nodes of my
hierarchy.  Since I was simply appending to my children list, there
was no callback to tell the container to process the children.

And no, calling a method is not necessarily called "firing", but I've
been using the term a lot recently when dealing with events so it
seemed appropriate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I'm searching for Python style guidelines

2008-01-07 Thread MartinRinehart
Thank you both.

Stupid me, went to Python.org and found Style Guidelines and thought
that was the last word. Oh well.

PEP 8 reminds me a lot of Sun's Java conventions, in ways I wish it
didn't. The overall structure seems like a random list of topics and
it omits a lot. For Java I went from Sun to other conventions to try
to compile a meta-convention ( 
http://www.MartinRinehart.com/articles/code-conventions.html
).

Here's just one of my questions:

foo = [
'some item, quite long',
'more items, all demanding there own line as they are not short',
...

Where would you put the closing ']'?
-- 
http://mail.python.org/mailman/listinfo/python-list


PostgreSQL with Python

2008-01-07 Thread Sunil Ghai
I am looking for an E-Book or some tutorial in which a good explanation
about PostgreSQL/MySQL database, then about interacting with them using
Python is explained.
I want to start RDBMS, i have no idea about them. I have been doing Python,
willing to do some good project in RDBMS.
Thanks in advance :)
Regards
-- 
Sunil Ghai
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: dealing with binary files

2008-01-07 Thread Gerardo Herzig
Tom Brown wrote:

>On Mon, 2008-01-07 at 11:57 -0200, Guilherme Polo wrote:
>  
>
>>2008/1/7, Gerardo Herzig <[EMAIL PROTECTED]>:
>>
>>
>>>Hi all. Im trying to read a binary data from an postgres WAL archive.
>>>If i make a
>>>xfile = open('filename', 'rb').xreadlines()
>>>line = xfile.next()
>>>
>>>i see this sort of thing:
>>>']\xd0\x03\x00\x01\x00\x00\x00\r\x00\x00\x00\x00\x00\x00JM//DI+,D\x00\x00\x00\x01$\x00\x00\x00\x7f\x06\x00\x00y\r\t\x00\x02\x0f\t\x00\x00\x00\x10\x00)\x00\x01\x00\x12\x08
>>>\x00^\xc2\x0c\x00\x08\x00\x00\x003001([EMAIL PROTECTED]'
>>>
>>>This file suppose to have some information about database activity, but
>>>at this point i cant do more than this, because i cant figure out what
>>>to do in order to have some 'readable' text.
>>>
>>>Im guessing is some C code, im reading the struct module to see if it
>>>helps, but im not into C programming, and im lost at the start of my
>>>problem.
>>>  
>>>
>>You are looking at the correct module, struct. But in order to
>>understand or even correctly extract data from a binary file, you need
>>to know its structure. There should be some document describing the
>>Postgre WAL file format.
>>
>>
>>
>
>"The log record headers are described in access/xlog.h"
>
>http://www.postgresql.org/docs/8.2/interactive/wal-internals.html
>
>  
>
Yes Tom, my 'C' comes that far, cant do more, i get quickly 
overwelmed...Guess i will have to spend some time reading about it.
Thanks!

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


Re: introspection question

2008-01-07 Thread Peter Otten
Alex K wrote:

Please don't top-post.

> On 07/01/2008, Peter Otten <[EMAIL PROTECTED]> wrote:
>> Alex K wrote:
>>
>> > What would be the simplest way of enumerating all methods and members
>> > (including inherited) of a given object? Thank you.
>>
>> inspect.getmembers()

> Nice thank you. But anyway to make it look pretty?

Maybe

$ /usr/bin/pydoc -p8080

Otherwise you'd have to explain what you are trying to do.

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


Re: introspection question

2008-01-07 Thread Guilherme Polo
2008/1/7, Alex K <[EMAIL PROTECTED]>:
> Nice thank you. But anyway to make it look pretty?
>

pprint.pprint(inspect.getmembers(someobject))

> On 07/01/2008, Peter Otten <[EMAIL PROTECTED]> wrote:
> > Alex K wrote:
> >
> > > What would be the simplest way of enumerating all methods and members
> > > (including inherited) of a given object? Thank you.
> >
> > inspect.getmembers()
> >
> > Peter
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dealing with binary files

2008-01-07 Thread Tom Brown
On Mon, 2008-01-07 at 11:57 -0200, Guilherme Polo wrote:
> 2008/1/7, Gerardo Herzig <[EMAIL PROTECTED]>:
> > Hi all. Im trying to read a binary data from an postgres WAL archive.
> > If i make a
> > xfile = open('filename', 'rb').xreadlines()
> > line = xfile.next()
> >
> > i see this sort of thing:
> > ']\xd0\x03\x00\x01\x00\x00\x00\r\x00\x00\x00\x00\x00\x00JM//DI+,D\x00\x00\x00\x01$\x00\x00\x00\x7f\x06\x00\x00y\r\t\x00\x02\x0f\t\x00\x00\x00\x10\x00)\x00\x01\x00\x12\x08
> > \x00^\xc2\x0c\x00\x08\x00\x00\x003001([EMAIL PROTECTED]'
> >
> > This file suppose to have some information about database activity, but
> > at this point i cant do more than this, because i cant figure out what
> > to do in order to have some 'readable' text.
> >
> > Im guessing is some C code, im reading the struct module to see if it
> > helps, but im not into C programming, and im lost at the start of my
> > problem.
> 
> You are looking at the correct module, struct. But in order to
> understand or even correctly extract data from a binary file, you need
> to know its structure. There should be some document describing the
> Postgre WAL file format.
> 

"The log record headers are described in access/xlog.h"

http://www.postgresql.org/docs/8.2/interactive/wal-internals.html

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


ctypes

2008-01-07 Thread hkimball
I am trying to call a funtinon in  a third party dll that spawns
another exe and I am using ctypes.  Python does not complain at all
but the other process does not get spawned.  It appears that I am
gaining access to the functions but with no results.  Any ideas?
Thanks in advance.

>>> from ctypes import *
>>> cdecl = cdll.LoadLibrary("c:\projects\python\geinterface.dll")
>>> cdecl._GE_Connect
<_FuncPtr object at 0x00B7E378>
>>> cdecl._GE_Connect()
0
>>> cdecl._GE_IsConnected()
0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to refer to the current module?

2008-01-07 Thread Christian Heimes
Mike wrote:
> Is there any way around this?  Can I somehow scope the 'current
> module' and give getattr(...) an object that will (at run time) have
> the appropriate bindings?

globals() for the current name space

import sys
sys.modules[__name__] gets you the module object

Christian

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


Re: introspection question

2008-01-07 Thread Alex K
Nice thank you. But anyway to make it look pretty?

On 07/01/2008, Peter Otten <[EMAIL PROTECTED]> wrote:
> Alex K wrote:
>
> > What would be the simplest way of enumerating all methods and members
> > (including inherited) of a given object? Thank you.
>
> inspect.getmembers()
>
> Peter
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >