Re: whats wrong with this

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

> I'm trying to rum gmmtrain within my pthon program like this:
> 
>  Input -l List -t inittype -e traintype 
> -m mixture -d dimension -v vfloor -n number -p percent -r results -c cycle)
> 
> But i keep on getting an error.

it helps if you include the actual error message in your post, so we 
don't have to guess.

the line you quoted should give you a "SyntaxError: invalid syntax" 
message; the "os.system" call takes a Python string object, so the 
correct syntax is:

 os.system("gmmtrain -o output -i /etc.../")

if that doesn't help, please post the *entire* traceback; also see:

http://effbot.org/pyfaq/tutor-i-need-help-im-getting-an-error-in-my-program-what-should-i-do.htm



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


Re: fastest method to choose a random element

2008-01-07 Thread Paddy
On Jan 5, 6:37 am, Paddy <[EMAIL PROTECTED]> wrote:
> On Jan 4, 7:55 pm, [EMAIL PROTECTED] wrote:
>
>
>
> >   Hello,
> >   This is a question for the best method (in terms of performance
> > only) to choose a random element from a list among those that satisfy
> > a certain property.
>
> >   This is the setting: I need to pick from a list a random element
> > that satisfies a given property. All or none of the elements may have
> > the property. Most of the time, many of the elements will satisfy the
> > property, and the property is a bit expensive to evaluate. Chance of
> > having the property are uniform among elements.
>
> >   A simple approach is:
>
> > import random
> > def random_pick(a_list,property):
> > '''Returns a random element from a list that has the property
>
> > Returns None if no element  has the property
> > '''
> > random.shuffle(a_list)
> > for i in a_list:
> > if property(i): return i
>
> > but that requires to shuffle the list every time.
>
> >  A second approach, that works if we know that at least one element of
> > the list has the property, is:
>
> > import random
> > def random_pick(a_list,property):
> > '''Returns a random element from a list that has the property
>
> > Loops forever if no element has the property
> > '''
> > while 1:
> > i=random.choice(a_list)
> > if property(i): return i
>
> > which is more efficient (on average) if many elements of the list have
> > the property and less efficient if only few elements of the list has
> > the property (and goes crazy if no element has the property)
>
> > Yet another one:
>
> > import random
> > def random_pick(a_list,property):
> > '''Returns a random element from a list that has the property
> > '''
> > b_list=[x for  x in a_list if property(x)]
> > try:
> > return random.choice(b_list)
> > finally: return None
>
> > but this one checks the property on all the elements, which is no
> > good.
>
> > I don't need strong random numbers, so a simple solution like:
> > import random
> > globalRNG=random.Random()
>
> > def random_pick(a_list,property):
> > '''Returns a random element from a list that has the property
>
> > Works only if len(a_list)+1 is prime: uses Fermat's little theorem
> > '''
> > a=globalRNG(1,len(a_list))
> > ind=a
> > for i in xrange(len(a_list)):
> > x=a_list[a-1]
> > if property(x):return x
> > ind*=a
>
> > but this works only if len(a_list)+1 is prime!!! Now this one could be
> > saved if there were an efficient method to find a prime number given
> > than a number n but not very much greater...
>
> > Any other ideas? Thanks everybody
>
> Caching might help.
>
> If random_pick is called several times with the same list(s) then
> cache the result of
>  [property(i) for i in a_list] against a_list.
>
> If random_pick is called several times with list(s) whith multiple
> instances of list items then cache
>  property(i) against i for i in a_list .
>
> You could do both.
>
> You might investigate wether property(i) could be implemented using a
> faster algorithm, maybe table lookup, or interpolation from initial
> table lookup.
>
> - Paddy.

Here's a caching decorator that you could apply to function property:
  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498245

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


[email protected]

2008-01-07 Thread Paddy
On Jan 7, 1:09 am, John Nagle <[EMAIL PROTECTED]> wrote:
>Another in our ongoing series on "Parsing Real-World HTML".
>
>It's wrong, of course.  But Firefox will accept as HTML escapes
>
> &
> >
> <
>
> as well as the correct forms
>
> &
> >
> <
>
> To be "compatible", a Python screen scraper at
>
> http://zesty.ca/python/scrape.py
>
> has a function "htmldecode", which is supposed to recognize
> HTML escapes and generate Unicode.  (Why isn't this a standard
> Python library function?  Its inverse is available.)
>
> This uses the regular expression
>
> charrefpat = re.compile(r'&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?',re.UNICODE)
>
> to recognize HTML escapes.
>
> Note the ";?", which makes the closing ";" optional.
>
> This seems fine until we hit something valid but unusual like
>
>http://www.example.com?foo=1??
>
> for which "htmldecode" tries to convert "1234567" into
> a Unicode character with that decimal number, and gets a
> Unicode overflow.
>
> For our own purposes, I rewrote "htmldecode" to require a
> sequence ending in ";", which means some bogus HTML escapes won't
> be recognized, but correct HTML will be processed correctly.
> What's general opinion of this behavior?  Too strict, or OK?
>
> John Nagle
> SiteTruth

Maybe htmltidy could help:
  http://tidy.sourceforge.net/
?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Patches to Python 2.5.1

2008-01-07 Thread Stefan Behnel
Brad wrote:
> I was just looking through the 2.5.1 source code. I noticed a few
> mis-spellings in the comments. No big deal really. Can patches be
> submitted that correct the spelling errors or should they just be
> pointed out to some mailing list?

Funny you ask, if there were so few, you could already have added the patch
anyway. :)

However, I'd just submit it to Python's bug tracker. Broken documentation is
something that should be fixed.

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


Multiple Bullets

2008-01-07 Thread katie smith
In my game there are planes and I could make multiple bullets fired by the 
plane by keeping track of each bullets x and y coordinates. I was wondering if 
there is an easier way without keeping track of a 150 bullet coordinates.


  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs-- 
http://mail.python.org/mailman/listinfo/python-list

do - loop

2008-01-07 Thread Hita Vora
I have a dataset which has about 3000 subjects in it.  I  take each subject and 
perform 3 to 4 geoprocessing tasks on it.  Currently I have a model where I 
manually feed in each subject's ID and then the rest of the process is 
automated.  I would like to automate the process such that it would 
automatically select another subject after the process has been completed on a 
specfic subject.  ie to repeat the same process on each of the IDs.

Any help such as a dummy code would be greatly appreciated.

Thanks.

Hita

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


Re: do - loop

2008-01-07 Thread Jeroen Ruigrok van der Werven
-On [20080107 09:51], Hita Vora ([EMAIL PROTECTED]) wrote:
>I have a dataset which has about 3000 subjects in it.  I  take each subject
>and perform 3 to 4 geoprocessing tasks on it.  Currently I have a model where
>I manually feed in each subject's ID and then the rest of the process is
>automated.  I would like to automate the process such that it would
>automatically select another subject after the process has been completed on
>a specfic subject.  ie to repeat the same process on each of the IDs.

Well, hopefully I understood you correctly, but if we assume that the dataset
is a simple list you can iterate over it as thus:

for subject in dataset:
do_geoprocessing(subject)

Dictionaries and other datatypes have similar means to construct an iterator.

Is this a bit what you want to achieve?

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Vae victis!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Noob question

2008-01-07 Thread rocco . rossi
On Jan 7, 12:09 am, GHZ <[EMAIL PROTECTED]> wrote:
> Had the same issue.  What you want is: reload()

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


Re: do - loop

2008-01-07 Thread Ben Finney
Hita Vora <[EMAIL PROTECTED]> writes:

> I have a dataset which has about 3000 subjects in it. I take each
> subject and perform 3 to 4 geoprocessing tasks on it. Currently I
> have a model where I manually feed in each subject's ID and then the
> rest of the process is automated. I would like to automate the
> process such that it would automatically select another subject
> after the process has been completed on a specfic subject. ie to
> repeat the same process on each of the IDs.

def do_the_stuff(subject):
""" Do the stuff to a single subject """
pass

for this_subject in all_subjects:
do_the_stuff(this_subject)

-- 
 \ "Unix is an operating system, OS/2 is half an operating system, |
  `\   Windows is a shell, and DOS is a boot partition virus." |
_o__) —Peter H. Coffin |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Python setup not working on Windows XP

2008-01-07 Thread Gowri
Hello,

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. i
then started Apache and it merely echoed my code print and all.

i did some reading and thought something might be wrong with my
sys.path. This is what it reads:
'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\
\Python25\\Lib', 'C:\\Python25\\Lib\\plat-win', 'C:\\Python25\\Lib\
\lib-tk', 'C:\\Python25', 'C:\\Python25\\Lib\\site-packages'

Somebody had said this problem could be because of the .zip file at
the beginning of the path but I haven't been able to get rid of it or
solve my problem in any other way. My Apache error file has the
entries:

[Mon Jan 07 04:11:11 2008] [error] python_init: Python executable
found 'C:\\Program Files\\Apache Software Foundation\\Apache2.2\\bin\
\httpd.exe'.
[Mon Jan 07 04:11:11 2008] [error] python_init: Python path being used
'C:\\WINDOWS\\system32\\python25.zip;C:\\Python25\\Lib;C:\\Python25\
\DLLs;C:\\Python25\\Lib\\lib-tk;;C:\\Program Files\\Apache Software
Foundation\\Apache2.2\\bin'.
[Mon Jan 07 04:11:11 2008] [notice] mod_python: Creating 8 session
mutexes based on 0 max processes and 250 max threads.


Could someone please tell me what I'm doing wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


python syntax

2008-01-07 Thread mpho raborife
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")')


   
-
Looking for last minute shopping deals?  Find them fast with Yahoo! Search.-- 
http://mail.python.org/mailman/listinfo/python-list

TIOBE declares Python as programming language of 2007!

2008-01-07 Thread monkeydance
See http://www.tiobe.com/index.htm?tiobe_index.

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


Re: python syntax

2008-01-07 Thread Jeroen Ruigrok van der Werven
-On [20080107 11:46], mpho raborife ([EMAIL PROTECTED]) wrote:
>os.system("HCopy -T 1 -C" 'os.path.join(conf_dir,  "/hcopy.conf")' "-S"
>'os.path.join(list_dir, "hcopy_list.txt")')

I would guess you would want this:

os.system("HCopy -T 1 -C" + os.path.join(conf_dir,  "/hcopy.conf") + "-S" +
os.path.join(list_dir, "hcopy_list.txt"))

But I'd personally not use such a contracted syntax, it makes detecting
failure on any of the three function calls difficult.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
If I promise you the Moon and the Stars, would you believe it..?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python syntax

2008-01-07 Thread Guilherme Polo
2008/1/7, mpho raborife <[EMAIL PROTECTED]>:
> 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")')
>

import os
import subprocess

subprocess.Popen(["HCopy", "-T", "1", "-C", os.path.join(conf_dir,
"hcopy.conf"),
"-S", os.path.join(list_dir, "hcopy_list.txt")])

>
>
>  
> Looking for last minute shopping deals? Find them fast with Yahoo! Search.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


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


Re: fastest method to choose a random element

2008-01-07 Thread caca

> Just for fun, I profiled my answer versus the final answer...

This mailing list is awesome!


PS:ajaksu, I have to leave now, I hope bukzor's answer was enough to
you (at least for the moment)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TIOBE declares Python as programming language of 2007!

2008-01-07 Thread Berco Beute
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 (see http://www.tiobe.com/tiobe_index/Python.html).
Equally interesting is the question why it dropped shortly after.

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


Re: Delete lines containing a specific word

2008-01-07 Thread mik3l3374
On Jan 7, 1:21 am, Francesco Pietra <[EMAIL PROTECTED]> wrote:
> Please, how to adapt the following script (to delete blank lines) to delete
> lines containing a specific word, or words?
>
> f=open("output.pdb", "r")
> for line in f:
> line=line.rstrip()
> if line:
> print line
> f.close()
>
> If python in Linux accepts lines beginning with # as comment lines, please 
> also
> a script to comment lines containing a specific word, or words, and back, to
> remove #.
>
> Thanks
> francesco pietra
>
>   
> 
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search.  
> http://tools.search.yahoo.com/newsearch/category.php?category=shopping

for line in open("file"):
if not "word" in line:
 print line


on the command, use the ">" operator to redirect to a file
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory Leaks and Heapy

2008-01-07 Thread M.-A. Lemburg
On 2008-01-05 03:19, Yaakov Nemoy wrote:
> On Jan 4, 2008 11:56 AM, M.-A. Lemburg <[EMAIL PROTECTED]> wrote:
>>> The most common answer I heard was possible fragmentation, meaning
>>> there are no or few completely empty blocks to be found.  If there are
>>> no 'leaks' in the VM, then it's probably related to how memory is
>>> freed.
>> You can check for this by using a special build of Python
>> with disabled PyMalloc - Python will then use the standard
>> OS malloc for all object allocations. It still uses free lists
>> for a couple of object types, but those won't cause major
>> leak problems.
> 
> How do I go about setting this up?

There's a configure option for this:

  --with(out)-pymallocdisable/enable specialized mallocs

>> Alternatively, try to tune the PyMalloc implementation (see
>> objmalloc.c), e.g. enable WITH_MEMORY_LIMITS.
>>
 This could be caused by interned strings which are kept in a special
 pool dictionary to speed up string comparisons.
>>> That's quite possible, a majority of the code is a huge number of SQL
>>> connections and code.  All string based.
>> Note that strings are normally *not* interned. However, you can
>> write code in a way that causes Python to intern more strings
>> than needed, e.g. if you dynamically compile code in your app,
>> which then causes all identifiers in the compiled code to be
>> interned.
>>
>> The interned dictionary is not exposed in Python, but you can
>> access it using a debugger via Objects/stringobject.c:interned.
> 
> That's going a bit more low level detail than I think I can handle.
> I'm not much for C programming, and i'll have a hard time sifting
> through the noise to find the signal.

Fair enough. Just wanted to give some more details as to
where to look for things that look like leaks, but are in
fact just results of internal feature of the Python
interpreter.

 However, the first thing to check is whether any of the C extension
 modules you are using is leaking memory. Python itself is usually
 well tested for memory leaks, but this is less so for C extension
 modules and it's easy to mis a few Py_DECREFs (decrementing a
 Python object's reference count), causing objects to live forever.
>>> I'll try to track it down, but AFAIK, most of the code is python, and
>>> the only C code there would be is the MySQL container.  How can I
>>> debug the VM though, to determine where the leak lies?  Heapy wasn't
>>> able to tell me this, and this is the important aspect.  I'm wondering
>>> how most people go about determining the causes of leaks like these,
>>> so I can provide some accurate bug information.
>> Building Python in debug mode provides some help with this.
>> You can then detect whether objects get properly freed.
> 
> Again, what's the best way to go about doing this?

Again, configure with:

 --with-pydebug  build with Py_DEBUG defined

>> Doing explicit garbage collection via the gc module also
>> helps in narrowing down the leak.
> 
> Adding an explicit gc.collect() statement at the end of the offending
> function didn't do much to solve matters much.  It slowed the rate
> that garbage piled up, but it's not a solution.
> 
> Thanks for all the help.

You're welcome.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 07 2008)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
-- 
http://mail.python.org/mailman/listinfo/python-list


Python's great, in a word

2008-01-07 Thread MartinRinehart
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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TIOBE declares Python as programming language of 2007!

2008-01-07 Thread Diez B. Roggisch
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...

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


Re: python interfaces

2008-01-07 Thread Sion Arrowsmith
Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>Sion Arrowsmith a écrit :
>(snip rant about Java's "interfaces")
>
>Hem... Zope3's "interface" system is not exactly the same thing as 
>Java's one.

Yeah, I was in need of letting off some steam in general and
didn't pay enough attention that what I was ranting about was
on topic. Given that Zope3's "interfaces" are the kind of thing
under discussion, the correct response is obviously Michele's
pointing at the ABC PEP.

-- 
\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: Python's great, in a word

2008-01-07 Thread Pablo Ziliani
[EMAIL PROTECTED] wrote:
> Would you Python old-timers try to agree on a word or two that
> completes:
>
> The best thing about Python is ___.

Hi Martin, here is my top three:

1) Fun
2) Simplicity
3) Productivity
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's great, in a word

2008-01-07 Thread Neil Cerutti
On Jan 7, 2008 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 ___.


...its bundled library.

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

Re: dictionary/hash and '1' versus 1

2008-01-07 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Paddy:
>> Not really, it seems to me to be going the exact opposite way with
>> languages with automatic type conversions being seen as not suited for
>> larger programs.
> 
> 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?


This isn't really what is happening. In fact, in Java the +-operator is 
overloaded for strings to invoke the mandatory toString()-method on all 
objects when concatenated with a string.

So

"" + 1

works internally as

StringBuilder sb = new StringBuilder();
sb.append("");
sb.append(new Integer(1).toString());


Or something like that, depending on how optimizing the compiler is.

So you can also do

"" + some_object

However,

some_object + ""

or

1 + ""

don't work - the operator is only overloaded on the left argument.

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


How to refer to the current module?

2008-01-07 Thread Mike
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's great, in a word

2008-01-07 Thread Dustan
On Jan 7, 7: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.

Here's a modest list:

Masterly, tops, best obtainable, high-grade, very good, select,
outstanding, exemplary, top-notch, boss, first-rate, crack, smashing,
excelling, prime, skilled, crackerjack, sublime, super, terrific,
peerless, notable, paramount, divine, premium, hand-picked, estimable,
admirable, prize, choice, competent, desirable, attractive, foremost,
to be desired, A-one, top-flight, dandy, incomparable, grade A,
capital, great, dynamite, heavenly, unique, refined, matchless, high-
quality, well-done, A-OK, blue-chip, frontline, sensational, highest,
jim-dandy, splendid, extraordinary, exquisite, superlative, worthy,
masterful, distinguished, magnificent, tiptop, accomplished, all
right, first, first-class, fine, very fine, ace-high, exceptional,
sharp, supreme, marvelous, transcendent, praiseworthy, custom-made,
remarkable, world-class, invaluable, groovy, champion, rare, best,
wonderful, superb, choicest, enticing, top, superfine, commendable,
skillful, neat, striking, distinctive, priceless, sterling, superior,
cool, classy, finest, hot, keen, above par.
-- 
http://mail.python.org/mailman/listinfo/python-list


I'm searching for Python style guidelines

2008-01-07 Thread MartinRinehart
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?
-- 
http://mail.python.org/mailman/listinfo/python-list


Launching a wx GUI from within our python framework

2008-01-07 Thread bg_ie
Hi,

At my work we have a framework writen in python which allows us to
test our equipment. This framework is quite large and uses a Singelton
called frameworkExec which we pass around between objects in order to
share functionailty. For example, frameWorkExec stores an instance of
the BatteryManagement module which I use to set the voltage during
certain tests.

I've just writen a gui using wx which I wish to use to calibrate our
voltage supply. I launch this app at the moment within python win as
follows -

app = VoltageCalibrationApp(0)
app.MainLoop()

class VoltageCalibrationApp(wx.App):
 def OnInit(self):

  voltageCalibration = {}
  voltageCalibration[0.0] = 1.2
  voltageCalibration[9.0] = 10.1
  voltageCalibration[22.0] = 22.7
  voltageCalibration[24.0] = 24.8
  voltageCalibration[30.0] = 31.1
  voltageCalibration[35.0] = 36.9

  frame = VoltageCalibrationFrame(None, -1, 'Voltage Calibration',
voltageCalibration)
  frame.Show(True)
  frame.Centre()
  return True

I hope that by adding the code above into the framework, I will be
able to call this app as part of the framework before the execution of
certain tests, as follows -

app = VoltageCalibrationApp(0)
app.MainLoop()
test1.run()
test2.run()

As you can see in the VoltageCalibrationApp class, I am currently
hardcoding voltageCalibration. Rather than doing this, I wish to store
them in our singleton which is available at the scope at which I
create my VoltageCalibrationApp instance. But I can't figure our a way
of referencing my singleton with the OnInit function. Normally, you
would pass the reference via __init__

How can I do this?

Thanks,

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


Re: How to refer to the current module?

2008-01-07 Thread Guilherme Polo
2008/1/7, Mike <[EMAIL PROTECTED]>:
> 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?

globals() =)

>
> Thanks in advance for all advice!
>
> Mike
> --
> http://mail.python.org/mailman/listinfo/python-list
>


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


Re: Memory Leaks and Heapy

2008-01-07 Thread Yaakov Nemoy
On Jan 7, 2008 7:55 AM, M.-A. Lemburg <[EMAIL PROTECTED]> wrote:
> Fair enough. Just wanted to give some more details as to
> where to look for things that look like leaks, but are in
> fact just results of internal feature of the Python
> interpreter.

We have a hackfest coming up in the Fedora Community.  I'll at least
show some people a copy of this email, and see if we can peer debug
things a bit, and maybe we'll come up with something.

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


Re: python syntax

2008-01-07 Thread Guilherme Polo
2008/1/7, mpho raborife <[EMAIL PROTECTED]>:
> Thanks. So could you please help me with this one:
> subprocess.Popen(["gmmscore", "-i", Input, "-l", List, "-t", modeltype,
> "-m", mixture, "-d", dimension, "-v", vfloor, "-n", number, "-r", results])

Only if you tell the problem.
But I guess that you maybe passed arguments that aren't strings, so be
sure to convert those arguments to strings. os.path.join in the
previous situation didn't need any conversion because it already
returns a string.

>
> Guilherme Polo <[EMAIL PROTECTED]> wrote:
>  2008/1/7, mpho raborife :
> > 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")')
> >
>
> import os
> import subprocess
>
> subprocess.Popen(["HCopy", "-T", "1", "-C", os.path.join(conf_dir,
> "hcopy.conf"),
>  "-S", os.path.join(list_dir, "hcopy_list.txt")])
>
> >
> >
> > 
> > Looking for last minute shopping deals? Find them fast with Yahoo! Search.
> >
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
> --
> -- Guilherme H. Polo Goncalves
>
>
>
>  
> Looking for last minute shopping deals? Find them fast with Yahoo! Search.
>
>


-- 
-- Guilherme H. Polo Goncalves
-- 
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]>:
> 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?

PEP 8
http://www.python.org/dev/peps/pep-0008/

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


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


code doesn't reference immutables?

2008-01-07 Thread MartinRinehart
>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?

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


Re: I'm searching for Python style guidelines

2008-01-07 Thread Peter Otten
MartinRinehart wrote:

> Anything written somewhere that's thorough? Any code body that should
> serve as a reference?

http://www.python.org/dev/peps/pep-0008/
-- 
http://mail.python.org/mailman/listinfo/python-list


dealing with binary files

2008-01-07 Thread Gerardo Herzig
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.

Can someone point me out some advice?
Thanks!

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


Re: Python's great, in a word

2008-01-07 Thread alain
On Jan 7, 2: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.

Paraphrasing Steve Jobs but in this context:
PYTHON = a bycycle for the mind

Best regards

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


Re: Launching a wx GUI from within our python framework

2008-01-07 Thread Guilherme Polo
2008/1/7, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> Hi,
>
> At my work we have a framework writen in python which allows us to
> test our equipment. This framework is quite large and uses a Singelton
> called frameworkExec which we pass around between objects in order to
> share functionailty. For example, frameWorkExec stores an instance of
> the BatteryManagement module which I use to set the voltage during
> certain tests.
>
> I've just writen a gui using wx which I wish to use to calibrate our
> voltage supply. I launch this app at the moment within python win as
> follows -
>
> app = VoltageCalibrationApp(0)
> app.MainLoop()
>
> class VoltageCalibrationApp(wx.App):
>  def OnInit(self):
>
>   voltageCalibration = {}
>   voltageCalibration[0.0] = 1.2
>   voltageCalibration[9.0] = 10.1
>   voltageCalibration[22.0] = 22.7
>   voltageCalibration[24.0] = 24.8
>   voltageCalibration[30.0] = 31.1
>   voltageCalibration[35.0] = 36.9
>
>   frame = VoltageCalibrationFrame(None, -1, 'Voltage Calibration',
> voltageCalibration)
>   frame.Show(True)
>   frame.Centre()
>   return True
>
> I hope that by adding the code above into the framework, I will be
> able to call this app as part of the framework before the execution of
> certain tests, as follows -
>
> app = VoltageCalibrationApp(0)
> app.MainLoop()
> test1.run()
> test2.run()
>
> As you can see in the VoltageCalibrationApp class, I am currently
> hardcoding voltageCalibration. Rather than doing this, I wish to store
> them in our singleton which is available at the scope at which I
> create my VoltageCalibrationApp instance. But I can't figure our a way
> of referencing my singleton with the OnInit function. Normally, you
> would pass the reference via __init__
>
> How can I do this?

You can define the __init__ method in your wx.App subclass, something like this:

class MyApp(wx.App):
  def __init__(self, thingYouWant, redirect=True, filename=None):
self.thingyouwant = thingYouWant
wx.App.__init__(self, redirect, filename)

  def OnInit(self):
 ... something that uses self.thingyouwant ...
 ...

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


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


Re: How to refer to the current module?

2008-01-07 Thread Mike
Sweet!  Thanks!

Mike

On Jan 7, 8:30 am, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>
> globals() =)
>

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


Re: code doesn't reference immutables?

2008-01-07 Thread Peter Otten
MartinRinehart wrote:

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

A code object is an internal data structure that describes a piece of
compiled python code. You can create one using compile():

>>> code = compile("a = 42", "", "exec")

It is immutable:

>>> code.a = 42
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'code' object has only read-only attributes (assign to .a)

And you can use it like so:

>>> a = "whatever"
>>> exec code
>>> a
42

If you have some spare time you can explore its attributes using
dir(code); otherwise: don't bother.

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


Re: How to refer to the current module?

2008-01-07 Thread Jean-Paul Calderone
On Mon, 7 Jan 2008 05:21:42 -0800 (PST), Mike <[EMAIL PROTECTED]> 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?

How about doing "import driver" and then using "getattr(driver, ...)"?

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


Re: code doesn't reference immutables?

2008-01-07 Thread Guilherme Polo
2008/1/7, [EMAIL PROTECTED] <[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?
>

What was your intention quoting this half-phrase ?
>From the same place, Python Reference Manual, 3.2:

Code objects:
Code objects represent byte-compiled executable Python code, or
bytecode. The difference between a code object and a function object
is that the function object contains an explicit reference to the
function's globals (the module in which it was defined), while a code
object contains no context; also the default argument values are
stored in the function object, not in the code object (because they
represent values calculated at run-time). Unlike function objects,
code objects are immutable and contain no references (directly or
indirectly) to mutable objects.

> --
> 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 Guilherme Polo
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.

>
> Can someone point me out some advice?
> Thanks!
>
> Gerardo
> --
> http://mail.python.org/mailman/listinfo/python-list
>


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


python syntax

2008-01-07 Thread mpho raborife
I need help with the following:
os.system("gmmscore"+"-i" + Input + "-l" + List + "-t" + str(modeltype) + "-m" 
+ str(mixture) + "-d" + str(dimension) + "-v" + str(vfloor) + "-n" + 
str(number) + "-r" + results)

   
-
Never miss a thing.   Make Yahoo your homepage.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python's great, in a word

2008-01-07 Thread Tim Chase
> The best thing about Python is ___.

+ readable
+ productive
+ mind-fitting

-tkc


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


introspection question

2008-01-07 Thread Alex K
Hi Guys,

What would be the simplest way of enumerating all methods and members
(including inherited) of a given object? Thank you.

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


Re: TIOBE declares Python as programming language of 2007!

2008-01-07 Thread Kay Schluehr
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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dealing with binary files

2008-01-07 Thread Peter Otten
Gerardo Herzig wrote:

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

file.readline() or similar functions are certainly the wrong approach if
you want to take a look into a binary file. What readline() interprets as
a newline character could actually be part of an integer:

>>> struct.pack("I", 10)
'\n\x00\x00\x00'

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

The probability is high that the file doesn't contain the information you
want in a human-readable way.

> 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.
> 
> Can someone point me out some advice? Thanks!

Your first and foremost hope is that postgres provides tools to extract
the information you want. You could then call these tools from python
using the subprocess module.

If there are no such tools look for a library in postgres to access WAL
files and use it via ctypes.

If all else fails try to come by a detailed description of the file
format. Here "detailed" includes the meaning of each and every bit. If
you are out of luck that description may come in the form of a few structs
in C source code...

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


Re: introspection question

2008-01-07 Thread Peter Otten
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


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


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


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


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: 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: 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 Guilherme Polo
2008/1/7, Alex K <[EMAIL PROTECTED]>:
> Hi Guys,
>
> What would be the simplest way of enumerating all methods and members
> (including inherited) of a given object? Thank you.
>
> Alex
> --
> http://mail.python.org/mailman/listinfo/python-list
>

import inspect
inspect.getmembers(yourobject)

-- 
-- Guilherme H. Polo Goncalves
-- 
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: 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


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 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: 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: 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: 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: 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: 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: [email protected]
> 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: 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: 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 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: 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: 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: 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: 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


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


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


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


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: 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: [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.


*

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


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


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


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


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


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


  1   2   >