A class question

2007-10-29 Thread Donn Ingle
Hello,

Is there a way I can, for debugging, access the instance variable name from
within a class?
E.g:
Class X: 
 def debug(self):
  print "My instance var is %s" % (some magic Python stuff)

So that:
>>>x = X()
>>>x.debug()
>>>My Instance var is x

( Without passing the name in like: x=X(name="x") ) 

Thx.
\d

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


Re: cron, python and samba restart

2007-10-29 Thread Nick Craig-Wood
symbioid <[EMAIL PROTECTED]> wrote:
>  Is there something in the way I'm calling with the subprocess.call()
>  function that's not able to work through cron?  My concern is that I'm
>  using sudo, and that may be where the problem lies.

http://www.gratisoft.us/pipermail/sudo-users/2005-May/002518.html

Todd C. Miller Todd.Miller at courtesan.com wrote:
> Your sudo is configured to only run when there is a tty
> present, whcih is not the case for cron jobs.  Usually this
> is due to a line like the following in sudoers:
> 
> Defaults  requiretty
> 
> Removing this (or just disabling it for the user who must run the
> cron job) should eliminate the error.  Note that you will also need
> to disable authentication either via the NOPASSWD tag or the
> "authenticate" Defaults option.

Check the PATH in cron also

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


Re: A class question

2007-10-29 Thread Bruno Desthuilliers
Donn Ingle a écrit :
> Hello,
> 
> Is there a way I can, for debugging, access the instance variable name from
> within a class?
> E.g:
> Class X: 
>  def debug(self):
>   print "My instance var is %s" % (some magic Python stuff)
> 
> So that:
 x = X()
 x.debug()
 My Instance var is x
> 
> ( Without passing the name in like: x=X(name="x") ) 

What should be the "variable name" in the following situations ?

a = b = c = X()
X().debug()


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


Re: sharing vars with different functions

2007-10-29 Thread Marc 'BlackJack' Rintsch
On Mon, 29 Oct 2007 09:03:14 +, [EMAIL PROTECTED] wrote:

> Im tryin to call a var thats sitting in a function, example:
> 
> class someclass(object):
>  somevar = open(blah, 'r').readlines()

Thats a class variable.  Is that really what you want!?

> def something():
> 
> for line in somevar:
>  print line
> ---
> 
> i  guess im not graspng the whole global or local var topic..

There is no real global here.  One is (somewhat) local to the class the
other local to the function.

> Any examples??

def something(lines):
for line in lines:
print lines

And the call it with the object.

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


sharing vars with different functions

2007-10-29 Thread [EMAIL PROTECTED]
Im tryin to call a var thats sitting in a function, example:

class someclass(object):
 somevar = open(blah, 'r').readlines()


def something():

for line in somevar:
 print line
---

i  guess im not graspng the whole global or local var topic..

Any examples??

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


Re: Need some help...

2007-10-29 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> I want to create a program that I type in a word.
> 
> for example...
> 
> chaos
> 
> each letter equals a number
> 
> A=1
> B=20
> 
>  and so on.
> 
> So Chaos would be
> 
> C=13 H=4 A=1 O=7 S=5
> 
> I want to then have those numbers
> 13+4+1+7+5 added together to be 30.
> 
> How can I do that?

If the values are arbitrary:

letters_values = {'A':1, 'B':20, 'C':13, 'H':4, 'O':7, 'S':5, #etc...}
print letters_values['A']


> Also, just curious, but, how could I then have the 3 and 0 added
> together to be 3?

help(sum)
help(map)
help(int)
print int('3')
help(list)
print list('30')
help(str)
print str(30)


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


Re: SQLObject - Connect to established DB with non-int 'id' field

2007-10-29 Thread Pradeep Jindal
On Saturday 20 Oct 2007 5:43:48 am Sean DiZazzo wrote:
> Hi all,
>
> I am just beginning with TurboGears and have run into a problem with
> SQLObject.
>
> I'm trying to connect to an established mysql DB, and use TurboGears
> to display results from the DB only.  The problem is that the DB
> already has an 'id' field that is a string as opposed to an int.
> SQLObject complains because it wants to use the id field for it's own
> purposes.
>
> How can I use TurboGears to get data out of this DB?
>
> Thanks in advance.
>
> ~Sean
I know I am not exactly answering your question, but its much better to use 
sqlalchemy when you already have the databases setup. And especially when you 
can not make any changes to existing database schemas.

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


Re: Python Windows Installation

2007-10-29 Thread TheFlyingDutchman
I finally gave up trying to install to c:\Python25 and went with the
install to C:\.  However, I tried to install a module called pywin32
(Python for Windows Extensions) and after recognizing that the Python
installation was in C:\ and saying it would install to C:\LIB\SITE-
PACKAGES, it would then blow up. This was consistently repeatable.
Seeing PythonWin mentioned regarding pywin32 reminded me of the
ActiveState distribution of Python as I knew that came with
PythonWin.

After uninstalling the python.org Python from C:\, I was able to
successfuly install the ActiveState Python distribution to C:
\Python25.


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


ANN: Veusz 1.0 - a scientific plotting package

2007-10-29 Thread Jeremy Sanders
I'm pleased to announce Veusz 1.0. Source, windows and linux i386 binaries
are available. Jeremy Sanders

Veusz 1.0
-
Velvet Ember Under Sky Zenith
-
http://home.gna.org/veusz/

Veusz is Copyright (C) 2003-2007 Jeremy Sanders <[EMAIL PROTECTED]>
Licenced under the GPL (version 2 or greater).

Veusz is a scientific plotting package written in Python, using PyQt4
for display and user-interfaces, and numpy for handling the numeric
data. Veusz is designed to produce publication-ready Postscript/PDF
output. The user interface aims to be simple, consistent and powerful.

Veusz provides a GUI, command line, embedding and scripting interface
(based on Python) to its plotting facilities. It also allows for
manipulation and editing of datasets.

Feature changes from 0.99.0:
 * Import of Text datasets
 * Labels can be plotted next to X-Y points
 * Numbers can be directly plotted by entering into X-Y datasets as X and Y
 * More line styles
 * Loaded document and functions are checked for unsafe Python features
 * Contours can be labelled with numbers
 * 2D dataset creation to make 2D datasets from x, y, z 1D datasets

Bug and minor fixes from 0.99.0:
 * Zooming into X-Y images works now
 * Contour plots work on datasets with non equal X and Y sizes
 * Various fixes for datasets including NaN or Inf
 * Large changes to data import filter to support loading strings (and dates
   later)
 * Reduce number of undo levels for memory/speed
 * Text renderer rewritten to be more simple
 * Improved error dialogs
 * Proper error dialog for invalid loading of documents

Features of package:
 * X-Y plots (with errorbars)
 * Line and function plots
 * Contour plots
 * Images (with colour mappings and colorbars)
 * Stepped plots (for histograms)
 * Fitting functions to data
 * Stacked plots and arrays of plots
 * Plot keys
 * Plot labels
 * LaTeX-like formatting for text
 * EPS/PDF/PNG export
 * Scripting interface
 * Dataset creation/manipulation
 * Embed Veusz within other programs
 * Text, CSV and FITS importing

Requirements:
 Python (2.3 or greater required)
   http://www.python.org/
 Qt >= 4.3 (free edition)
   http://www.trolltech.com/products/qt/  
 PyQt >= 4.3 (SIP is required to be installed first)
   http://www.riverbankcomputing.co.uk/pyqt/
   http://www.riverbankcomputing.co.uk/sip/
 numpy >= 1.0
   http://numpy.scipy.org/
 Microsoft Core Fonts (recommended for nice output)
   http://corefonts.sourceforge.net/
 PyFITS >= 1.1 (optional for FITS import)
   http://www.stsci.edu/resources/software_hardware/pyfits

For documentation on using Veusz, see the "Documents" directory. The
manual is in pdf, html and text format (generated from docbook).

Issues:
 * Reqires a rather new version of PyQt, otherwise dialogs don't work.
 * Can be very slow to plot large datasets if antialiasing is enabled.
   Right click on graph and disable antialias to speed up output.
 * The embedding interface appears to crash on exiting.

If you enjoy using Veusz, I would love to hear from you. Please join
the mailing lists at

https://gna.org/mail/?group=veusz

to discuss new features or if you'd like to contribute code. The
latest code can always be found in the SVN repository.

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


sorting data

2007-10-29 Thread Beema shafreen
hi all,
   I have problem to sort the data.. the file includes data as
follow.
file:
chrX:123343123123343182A_16_P41787782
chrX:123343417123343476A_16_P03762840
chrX:123343460123343519A_16_P41787783
chrX:1233433612334395A_16_P03655927
chrX:123343756123343815A_16_P03762841
chrX:123343807123343866A_16_P41787784
chrX:123343966123344024A_16_P21578670
chrX:123344059123344118A_16_P21578671
chrX:1233443812334497A_16_P21384637
chrX:123344776123344828A_16_P21578672
chrX:123344811123344870A_16_P03762842
chrX:123345165123345224A_16_P41787789
chrX:123345360123345419A_16_P41787790
chrX:123345380123345439A_16_P03762843
chrX:123345481123345540A_16_P41787792
chrX:123345873123345928A_16_P41787793
chrX:123345891123345950A_16_P03762844


how do is sort the file based on the column 1 and 2 with values..
using sort option works for only one column and not for the other how do is
sort both 1 and 2nd column so that the third column does not change.
my script:#sorting the file
start_lis = []
end_lis = []
fh = open('chromosome_location_346010.bed','r')
for line in fh.readlines():
data = line.strip().split('\t')
start = data[1].strip()
end = data[2].strip()
probe_id  = data[3].strip()
start_lis.append(start)
   end_lis.append(end)
start_lis.sort()
end_lis.sort()
for k in start_lis:
 for i in end_lis
   print k , i , probe_id(this doesnot worK)
  result = start#end#probe_id --->this doesnot work...
print result

What is the error and how do is sort a file based on the two column  to get
the fourth column also with that.
regards
shafreen
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: A class question

2007-10-29 Thread Carl Banks
On Oct 28, 6:01 am, Donn Ingle <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Is there a way I can, for debugging, access the instance variable name from
> within a class?
> E.g:
> Class X:
>  def debug(self):
>   print "My instance var is %s" % (some magic Python stuff)
>
> So that:
>
> >>>x = X()
> >>>x.debug()
> >>>My Instance var is x
>
> ( Without passing the name in like: x=X(name="x") )


You could search the global and local namespaces of the caller for a
symbol that's bound to the same object as self.  For instance, to find
a such a symbol in the caller's global namespace, this might work:

def debug(self):
for sym,value in sys._getframe(1).f_globals:
if value is self:
print "My instance var is %s" % sym

Improving the example left as an exercise.  There's probably quite a
few recipes to do stuff like this in the Python Cookbook (quod
googla).

Also, note that some objects are not bound to any symbols but instead
are referenced by lists or other containers.


Carl Banks

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


Re: ANN: Veusz 1.0 - a scientific plotting package

2007-10-29 Thread Wildemar Wildenburger
Jeremy Sanders wrote:
> I'm pleased to announce Veusz 1.0. Source, windows and linux i386 binaries
> are available. Jeremy Sanders
> 
> [snip]
> 
> Veusz is a scientific plotting package written in Python, using PyQt4
> for display and user-interfaces, and numpy for handling the numeric
> data. Veusz is designed to produce publication-ready Postscript/PDF
> output. The user interface aims to be simple, consistent and powerful.
> 
Not that I don't value your effort, but why another plotting package 
while we have pyx and matplotlib already?

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


Re: sharing vars with different functions

2007-10-29 Thread Martin Marcher
I hate gmail, always forgetting to set the right recipient...


-- Forwarded message --
From: Martin Marcher <[EMAIL PROTECTED]>
Date: 29.10.2007 10:11
Subject: Re: sharing vars with different functions
To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>


2007/10/29, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> Im tryin to call a var thats sitting in a function, example:
>
> i  guess im not graspng the whole global or local var topic..

does this help?

>>> class Foo(object):
... somevar = ["a", "b"]
... def __init__(self):
... self.another_var = ["c", "d"]
...
>>> Foo.somevar
['a', 'b']
>>> f = Foo()
>>> f.somevar
['a', 'b']
>>> f.another_var
['c', 'd']
>>> Foo.somevar = "New Value"
>>> f.somevar
'New Value'
>>> Foo.another_var
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: type object 'Foo' has no attribute 'another_var'



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


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 weirdness when https_proxy environment variable is exported

2007-10-29 Thread Devraj
Hi John,

Thanks for that.

Do you have any web urls that I can see an example of the hack?


On Oct 28, 3:50 am, [EMAIL PROTECTED] (John J. Lee) wrote:
> Devraj <[EMAIL PROTECTED]> writes:
> > I have been extensively using Python's urllib2 while developing a
> > project with the Google Data API. The Google Data API uses httplib to
> > place all of its requests. However I have been using urllib2 and some
> > handlers that I discovered in an ASPN article to handle HTTPS proxies
> > in my code.
>
> > The Google Data API relies on an environment variable called
> > https_proxy to get information about the proxy to be used. However
> > urllib2 starts spitting out the BadStatusLine exception if the
> > https_proxy environment variable is found.
>
> [...]
>
> This is because urllib2 does not support HTTPS proxies (neither does
> urllib).  See Python cookbook for a hack to get it working.
>
> John


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


Re: A class question

2007-10-29 Thread Hrvoje Niksic
Donn Ingle <[EMAIL PROTECTED]> writes:

> Is there a way I can, for debugging, access the instance variable name from
> within a class?
> E.g:
> Class X: 
>  def debug(self):
>   print "My instance var is %s" % (some magic Python stuff)

As others have answered, an instance can live in many variables, so
there is no single way to implement this sort of debugging.  Instead,
print str(self), which will give you an idea of the identity of self,
or its contents.


Sbe unpx inyhr, urer vf n cbffvoyr vzcyrzragngvba:

vzcbeg vafcrpg

qrs _svaq(senzr, bow):
sbe anzr, inyhr va senzr.s_ybpnyf.vgrevgrzf():
vs inyhr vf bow:
erghea anzr
sbe anzr, inyhr va senzr.s_tybonyf.vgrevgrzf():
vs inyhr vf bow:
erghea anzr
envfr XrlReebe("Bowrpg abg sbhaq va senzr tybonyf be ybpnyf")

pynff K:
qrs qroht(frys):
cevag ("Pnyyre fgberf zr va %f (nzbat bgure cbffvoyr cynprf)"
   % _svaq(vafcrpg.pheeragsenzr(1), frys))

>>> klmml = K()
>>> klmml.qroht()
Pnyyre fgberf zr va klmml (nzbat bgure cbffvoyr cynprf)
>>> n = o = K()
>>> n.qroht()
Pnyyre fgberf zr va n (nzbat bgure cbffvoyr cynprf)
>>> o.qroht()
Pnyyre fgberf zr va n (nzbat bgure cbffvoyr cynprf)
>>> K().qroht()
Genpronpx (zbfg erprag pnyy ynfg):
  Svyr "", yvar 1, va 
  Svyr "", yvar 4, va qroht
  Svyr "", yvar 8, va _svaq
XrlReebe: 'Bowrpg abg sbhaq va senzr tybonyf be ybpnyf'
-- 
http://mail.python.org/mailman/listinfo/python-list


Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
Windows XP Pro, Python 2.5.1

import msvcrt
while True:
 if msvcrt.kbhit():
 key = msvcrt.getch()
 if key == 'Enter'
 do something

Is there a way to catch the pressing of the 'Enter' key?

Thanks,

Dick Moores

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


problem opening html file with webbrowser.open

2007-10-29 Thread krishnakant Mane
hello all,
as I posted in my previous thread, I am generating html reports for my
client software.
I am yet to find a satisfactory module which can help me actually
create headings, bold and italics etc without merging html with data
variables.
any ways I am right now doing the hamd coding myself.  may be I have
overlooked some module.
right now I am in the process of trying templayer.
but my main issue is that when I use the
webbrowser.open("file:///home/myname/report.html"), webbroser opens
but the page does not come up.
there is certainly some thing wrong in what I am giving to the open function.
can some one correct me?
regards,
Krishnakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Veusz 1.0 - a scientific plotting package

2007-10-29 Thread Jeremy Sanders
Wildemar Wildenburger wrote:

> Not that I don't value your effort, but why another plotting package
> while we have pyx and matplotlib already?

In addition to the Python based scripting command line and embedding
interface, it has a powerful graphical user interface for constructing
plots and importing data.  Neither matplotlib or pyx have this.
This is the main feature. It was originally intended to be mainly
command-line based, but I've found the GUI to be my main way of using it.

At the time of the first release of Veusz, and for quite long after,
matplotlib was too primitive to use as a backend for Veusz (see previous
threads on this subject). Maybe that has changed now, but IMHO Veusz output
still looks better.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Veusz 1.0 - a scientific plotting package

2007-10-29 Thread Wildemar Wildenburger
Jeremy Sanders wrote:
> Wildemar Wildenburger wrote:
> 
>> Not that I don't value your effort, but why another plotting package
>> while we have pyx and matplotlib already?
> 
> In addition to the Python based scripting command line and embedding
> interface, it has a powerful graphical user interface for constructing
> plots and importing data.  Neither matplotlib or pyx have this.
> This is the main feature. It was originally intended to be mainly
> command-line based, but I've found the GUI to be my main way of using it.
> 
> At the time of the first release of Veusz, and for quite long after,
> matplotlib was too primitive to use as a backend for Veusz (see previous
> threads on this subject). Maybe that has changed now, but IMHO Veusz output
> still looks better.
> 
> Jeremy
> 

Oh, OK. I though it was a library. I now see that it is an actual 
application. Sorry to have bothered you :)

Good luck with that!


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


Re: building a linux executable

2007-10-29 Thread BlueBird

Hi,

Some time ago, I compiled a small list of tools to perform the some
"python executable bundling" tasks.

It might be useful for you. Here is the list:

http://www.freehackers.org/Packaging_a_python_program


   Philippe

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


Re: problem opening html file with webbrowser.open

2007-10-29 Thread Stefan Behnel
krishnakant Mane wrote:
> as I posted in my previous thread, I am generating html reports for my
> client software.
> I am yet to find a satisfactory module which can help me actually
> create headings, bold and italics etc without merging html with data
> variables.

Maybe this is something for you:

http://codespeak.net/lxml/dev/lxmlhtml.html#creating-html-with-the-e-factory


> but my main issue is that when I use the
> webbrowser.open("file:///home/myname/report.html"), webbroser opens
> but the page does not come up.

Maybe your browser is not in the executable path? Try passing the PATH
environment variable to the Python interpreter and make sure it contains the
directory where your browser is installed.

Also, try requesting a specific browser type instead of the default one, and
use its controller object. Read the docs of the webbrowser module for that:

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

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


Re: problem opening html file with webbrowser.open

2007-10-29 Thread Paul Boddie
On 29 Okt, 11:44, "krishnakant Mane" <[EMAIL PROTECTED]> wrote:
> hello all,
> as I posted in my previous thread, I am generating html reports for my
> client software.
> I am yet to find a satisfactory module which can help me actually
> create headings, bold and italics etc without merging html with data
> variables.
> any ways I am right now doing the hamd coding myself.  may be I have
> overlooked some module.
> right now I am in the process of trying templayer.

This somewhat neglected Wiki page may provide some guidance:

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

Dynamically styling data can be somewhat awkward, and I'd probably
have some kind of last-minute transformation on my data to add
presentation-related attributes and then feed it to a generic
templating system.

> but my main issue is that when I use the
> webbrowser.open("file:///home/myname/report.html"), webbroser opens
> but the page does not come up.
> there is certainly some thing wrong in what I am giving to the open function.
> can some one correct me?

Which system and Web browser are you using? Perhaps you'd be
interested in the desktop module instead:

http://www.python.org/pypi/desktop

Paul

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


Re: ANN: Veusz 1.0 - a scientific plotting package

2007-10-29 Thread Jeremy Sanders
Wildemar Wildenburger wrote:
> Oh, OK. I though it was a library. I now see that it is an actual
> application. Sorry to have bothered you :)

It's a library too :-)

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Filip Wasilewski
On Oct 29, 11:26 am, Dick Moores <[EMAIL PROTECTED]> wrote:
> Windows XP Pro, Python 2.5.1
>
> import msvcrt
> while True:
>  if msvcrt.kbhit():
>  key = msvcrt.getch()
>  if key == 'Enter'
>  do something
>
> Is there a way to catch the pressing of the 'Enter' key?

Yes there is. Just open the Python shell and see what is being
returned by `getch` or `getche` functions when you press Enter:

>>> import msvcrt
>>> msvcrt.getch()
'\r'

Also try to avoid `busy waiting` and calling msvcrt.kbhit in a loop
without a sleep statement. I don't know your case but probably this
should be enough:

while True:
if msvcrt.getch() == '\r':
...

fw

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


Re: A class question

2007-10-29 Thread Martin Marcher
2007/10/29, Hrvoje Niksic <[EMAIL PROTECTED]>:
> Sbe unpx inyhr, urer vf n cbffvoyr vzcyrzragngvba:
> ...

was that on purpose?

martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dustan
On Oct 29, 4:26 am, Dick Moores <[EMAIL PROTECTED]> wrote:
> Windows XP Pro, Python 2.5.1
>
> import msvcrt
> while True:
>  if msvcrt.kbhit():
>  key = msvcrt.getch()
>  if key == 'Enter'
>  do something
>
> Is there a way to catch the pressing of the 'Enter' key?
>
> Thanks,
>
> Dick Moores

Let's find out:

>>> from msvcrt import getch
>>> while True:
... key = getch()
... if key: print repr(key)+',',
...
'p', 'r', 'e', 's', 's', 'i', 'n', 'g', ' ', 'e', 'n', 't', 'e', 'r',
':', ' ', '\r',

Gee, I pressed enter, and it returned '\r'. I wonder...

>>> import msvcrt
>>> while True:
... if msvcrt.kbhit():
... key = msvcrt.getch()
... if key == '\r':
... print "success!"
...
success!

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


Re: A class question

2007-10-29 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit :
> Donn Ingle <[EMAIL PROTECTED]> writes:
> 
>> Is there a way I can, for debugging, access the instance variable name from
>> within a class?
>> E.g:
>> Class X: 
>>  def debug(self):
>>   print "My instance var is %s" % (some magic Python stuff)
> 
> As others have answered, an instance can live in many variables,

"be bound to many names" would be more accurate IMHO. Python's 
"variables" are name=>object bindings.

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


Re: sharing vars with different functions

2007-10-29 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> Im tryin to call 

s/call/access/

> a var thats sitting

s/sitting/defined/

> in a function, example:

In this example, s/function/class/

> class someclass(object):

pep08 : should be SomeClass(object):

>  somevar = open(blah, 'r').readlines()

Doing IO in the body of a class statement is IMHO a *very* bad idea.

> 
> def something():
> 
> for line in somevar:
>  print line
> ---
> 
> i  guess im not graspng the whole global or local var topic..

Seems there are a couple other points you're net yet grasping. Anyway, 
in this case, you should pass the iterable object to your function:

def something(iterable):
 for line in iterable:
 print line

something(someclass.somevar)


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


SQLite3; weird error

2007-10-29 Thread TYR
Has anyone else experienced a weird SQLite3 problem?

Going by the documentation at docs.python.org, the syntax is as
follows:
foo = sqlite3.connect(dbname) creates a connection object representing
the state of dbname and assigns it to variable foo. If dbname doesn't
exist, a file of that name is created.

To do anything with it, you then need to create a cursor object by
calling foo's method cursor (bar = foo.cursor).

You can now pass an SQL query or command to the DB by calling the
cursor object's method execute() with the SQL query as a quoted
statement.

(bar.execute("SELECT FROM squid WHERE squamous=True")

And then do other stuff.

Fine. When I call the cursor object, though, I get an AttributeError;
('builtinfunction_or_method object has no attribute 'execute')

Am running Python 2.5.1 on Mandriva Linux '08.

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


Re: A class question

2007-10-29 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]>
writes:

>> As others have answered, an instance can live in many variables,
>
> "be bound to many names" would be more accurate IMHO.

Technically more accurate maybe (but see below), but I was responding
to a beginner's post, so I was striving for ease of understanding.

> Python's "variables" are name=>object bindings.

No reason to use quotes.  Variable is just as acceptable a term, one
used by Python itself, as witnessed by the "vars" builtin, but also in
PEP 8, in the language reference, and elsewhere in the docs.  Even the
quite technical language reference uses both terms, such as in this
paragraph under "Naming and binding":

If a name is bound in a block, it is a local variable of that
block. If a name is bound at the module level, it is a global
variable. (The variables of the module code block are local and
global.) If a variable is used in a code block but not defined
there, it is a free variable.

I disagree with the idea that the terms "name" and "binding" are the
only correct terminology.  Python is not the first language to offer
pass-by-object-reference assignment semantics.  It shares it with
Lisp, Java, and many others, none of which have problems with the term
"variable".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
At 04:29 AM 10/29/2007, Filip Wasilewski wrote:
>On Oct 29, 11:26 am, Dick Moores <[EMAIL PROTECTED]> wrote:
> > Windows XP Pro, Python 2.5.1
> >
> > import msvcrt
> > while True:
> >  if msvcrt.kbhit():
> >  key = msvcrt.getch()
> >  if key == 'Enter'
> >  do something
> >
> > Is there a way to catch the pressing of the 'Enter' key?
>
>Yes there is. Just open the Python shell and see what is being
>returned by `getch` or `getche` functions when you press Enter:
>
> >>> import msvcrt
> >>> msvcrt.getch()
>'\r'

Terrific! Thanks.

>Also try to avoid `busy waiting` and calling msvcrt.kbhit in a loop
>without a sleep statement.
>I don't know your case but probably this
>should be enough:
>
>while True:
> if msvcrt.getch() == '\r':

I tried it and find that without the msvcrt.kbhit the first key I hit 
doesn't do anything. I have to hit that key again, or another key.

Dick

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


Re: Which index can i use ?

2007-10-29 Thread Gerardo Herzig
Abandoned wrote:

>Hi..
>I want to do index in postgresql & python.
>My table:
>id(int) | id2(int) | w(int) | d(int)
>
>My query:
>select id, w where id=x and id2=y (sometimes and d=z)
>
>I have too many insert and select operation on this table.
>And which index type can i use ? Btree, Rtree, Gist or Hash ?
>Also I want to unique (id, id2)..
>Now this is my index. is it give me good performance ?
>CREATE UNIQUE INDEX ind1 ON test USING btree (id, id2)
>CREATE INDEX ind2 ON test USING btree (id)
>CREATE INDEX ind3 ON test USING btree (id2)
>CREATE INDEX ind4 ON test USING btree (w)
>CREATE INDEX ind5 ON test USING btree (d)
>
>I'm too sorry my bad english.
>King regards..
>
>  
>
Well, this is no python-related at all. But, for a start, if you are not 
using the 'w' field in the WHERE clause, the ind4 index is not necesary 
at all. Having more indexes that you need is a waste of space and 
perfomance. It also depends on the amount of records your table has.
-Hash indexes are discouraged
-GiST indexes are for more advanced uses than equality comparisons
-Rtree are used in multidimentional indexing

So, keep the default btree. Do the test with the diff indexes if you 
want. You may use EXPLAIN for viewing the  index usage.
And dont forget about VACUUM too!

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


Re: Yet another comparison of Python Web Frameworks

2007-10-29 Thread Bruno Desthuilliers
johnbraduk a écrit :
> Thomas,
> Like many others I have been going round the same loop for months.
> 
> I have struggled with most of the Python solutions, including
> TurboGears and have given up and gone back to ColdFusion.  I am not
> trying to kick of a religious war about the pros and cons of
> ColdFusion as a scripting langauge, but IMHO, as a development
> environment (Dreamweaver), it is unbeatable.

Won't talk about opinion here. Enough to say that Dreamweaver is IMHO a 
bloated piece of crap.

> In one product, "out of
> the box" I can integrate database access and web design,

Which are totally orthogonal aspects, and as such are better kept 
seperate. In my current shop - as well as in the previous one, 
programmers deal with database access, designers deal with design, and 
integrators deal with html and templates.

> including
> AJAX, in one GUI IDE.

I don't want a "GUI IDE", I want my code editor. Using which I can edit 
(x)html, css, any template language, javascript, python, php, sql, 
whatever...

>  Ok, the IDE is on Windows, but the servers run
> on Linux.

No way I'm going to inflict myself the pain of using Windows. Sorry.

> This seems to be an aspect of web design that has been totally
> ignored in the Python community. 
(snip rant about having too much choice)
> Am I asking too much to have a Python product "X" which is a fully
> self-contained web development framework?

Have you tried Django ? One of the main criticism against it is that 
it's a bit too much "self-contained" !-)

But anyway, since all these are free softwares - freely written and 
contributed by mostly benelovent contributors -, yes, you *are* "asking" 
too much.

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


Re: Capturing output with input

2007-10-29 Thread gopala
On Oct 29, 9:03 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:

> On Linux, use the "script" command.
> On Windows, select the region to copy using the mouse and paste it onto a
> notepad file.
> I don't think Python would help here.

Thanks :-)
Now  i just do os.system(exeFile) and i can easily copy the output
from terminal using mouse selection.

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


Re: SQLite3; weird error

2007-10-29 Thread Duncan Booth
TYR <[EMAIL PROTECTED]> wrote:

> To do anything with it, you then need to create a cursor object by
> calling foo's method cursor (bar = foo.cursor).

Perhaps this would work better if you actually try calling foo's method?

bar = foo.cursor()

Without the parentheses all you are doing is assigning the method to a 
variable, not calling it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SQLite3; weird error

2007-10-29 Thread Diez B. Roggisch
TYR wrote:

> Has anyone else experienced a weird SQLite3 problem?
> 
> Going by the documentation at docs.python.org, the syntax is as
> follows:
> foo = sqlite3.connect(dbname) creates a connection object representing
> the state of dbname and assigns it to variable foo. If dbname doesn't
> exist, a file of that name is created.
> 
> To do anything with it, you then need to create a cursor object by
> calling foo's method cursor (bar = foo.cursor).

is that really from the docs? If yes, they are buggy.

The problem is pretty obvious: foo.cursor is NOT calling a method cursor on
foo. It's a reference to that very method.

So instead write

bar = foo.cursor()

and your done.

> You can now pass an SQL query or command to the DB by calling the
> cursor object's method execute() with the SQL query as a quoted
> statement.
> 
> (bar.execute("SELECT FROM squid WHERE squamous=True")
> 
> And then do other stuff.
> 
> Fine. When I call the cursor object, though, I get an AttributeError;
> ('builtinfunction_or_method object has no attribute 'execute')

Which is a pretty acute description of the error: you are trying to get an
attribute (execute, which you ultimately expect to be a method) from a
method.

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


Re: problem opening html file with webbrowser.open

2007-10-29 Thread Jake McKnight
> Maybe your browser is not in the executable path? Try passing the PATH
> environment variable to the Python interpreter and make sure it contains
the
> directory where your browser is installed.

Clearly the browser is in the path, because it opens.  It just fails to open
the file supplied by the script.

> but my main issue is that when I use the
> webbrowser.open("file:///home/myname/report.html"), webbroser opens
> but the page does not come up.

I just tested this in both Windows (Vista) and Linux (Kubuntu 7.10 and
Slackware 12) without any problems.  Try it from the interpreter; if it's
actually executing successfully, you should see something that looks like
this:

>>> import webbrowser
>>> webbrowser.open("file:///home/user/path/to/file/test.html")
True
>>>


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

Re: Help with pyparsing and dealing with null values

2007-10-29 Thread Paul McGuire
On Oct 29, 1:11 am, avidfan <[EMAIL PROTECTED]> wrote:
> Help with pyparsing and dealing with null values
>
> I am trying to parse a log file (web.out) similar to this:
>
> ---
>
> MBeanName: "mtg-model:Name=mtg-model_managed2,Type=Server"
> AcceptBacklog: 50

> ExpectedToRun: false
> ExternalDNSName:
> ExtraEjbcOptions:
> ExtraRmicOptions:
> GracefulShutdownTimeout: 0
>
> ---
>
> and I need the indented values (eventually) in a dictionary.  As you
> can see, some of the fields have a value, and some do not.  It appears
> that the code I have so far is not dealing with the null values and
> colons as I had planned.
>

This is a very good first cut at the problem.  Here are some tips to
get you going again:

1. Literal("\n") wont work, use LineEnd() instead.  Literals are for
non-whitespace literal strings.


2. "all = SkipTo(end)" can be removed, use restOfLine instead of all.
("all" as a variable name masks Python 2.5's "all" builtin function.)


3. In addition to identity, you might consider defining some other
known value types:

boolean = oneOf("true false")
boolean.setParseAction(lambda toks: toks[0]=="true")

integer = Combine(Optional("-") + Word(nums))
integer.setParseAction(lambda toks: int(toks[0]))

These will do data conversion for you at parse time, so that the
values are already in int or bool form when you access them later.


4. The significant change is to this line (I've replaced all with
restOfLine):

pairs = Group(identity + colon + Optional(identity) + restOfLine)

What gives us a problem is that pyparsing's whitespace-skipping will
read an identity, even if it's not on the same line.  So for keys that
have no value given, you end up reading past the end-of-line and read
the next key name as the value for the previous key.  To work around
this, define the value as something which must be on the same line,
using the NotAny lookahead, which you can abbreviate using the ~
operator.

pairs = Group(identity + colon + Optional(~end + (identity |
restOfLine) ) + end )

If we add in the other known value types, this gets a bit unwieldy, so
I recommend you define value separately:

value = boolean | integer | identity | restOfLine
pairs = Group(identity + colon + Optional(~end + value) + end )

At this point, I think you have a working parser for your log data.


5. (Extra Credit) Lastly, to create a dictionary, you are all set to
just add pyparsing's Dict class.  Change:

logEntry = MBeanName + ServerName("servername") + OneOrMore(pairs)

to:

logEntry = MBeanName + ServerName("servername") +
Dict(OneOrMore(pairs))

(I've also removed ".setResultsName", using the new shortened form for
setting results names.)

Dict will return the parsed tokens as-is, but it will also define
results names using the tokens[0] element of each list of tokens
returned by pairs - the values will be the tokens[1:], so that if a
value expression contains multiple tokens, they all will be associated
with the results name key.

Now you can replace the results listing code with:

for t in tokens:
   print t

with

print tokens.dump()

And you can access the tokens as if they are a dict, using:

print tokens.keys()
print tokens.values()
print tokens["ClasspathServletDisabled"]

If you prefer, for keys that are valid Python identifiers (all of
yours appear to be), you can just use object.attribute notation:

print tokens.ClasspathServletDisabled

Here is some sample output, using dump(), keys(), and attribute
lookup:

tokens.dump() -> ['MBeanName:', '"mtg-model:Name=mtg-
model_managed2,Type=Server"', ['AcceptBacklog', 50],
['AdministrationPort', 0], ['AutoKillIfFailed', False],
['AutoRestart', True], ['COM', 'mtg-model_managed2'], ['COMEnabled',
False], ['CachingDisabled', True], ['ClasspathServletDisabled',
False], ['ClientCertProxyEnabled', False], ['Cluster', 'mtg-model-
cluster'], ['ClusterRuntime', 'mtg-model-cluster'], ['ClusterWeight',
100], ['CompleteCOMMessageTimeout', -1],
['CompleteHTTPMessageTimeout', -1], ['CompleteIIOPMessageTimeout',
-1], ['CompleteMessageTimeout', 60], ['CompleteT3MessageTimeout', -1],
['CustomIdentityKeyStoreFileName'],
['CustomIdentityKeyStorePassPhrase'],
['CustomIdentityKeyStorePassPhraseEncrypted'],
['CustomIdentityKeyStoreType'], ['CustomTrustKeyStoreFileName'],
['CustomTrustKeyStorePassPhrase'],
['CustomTrustKeyStorePassPhraseEncrypted'],
['CustomTrustKeyStoreType'], ['DefaultIIOPPassword'],
['DefaultIIOPPasswordEncrypted'], ['DefaultIIOPUser'],
['DefaultInternalServletsDisabled', False], ['DefaultProtocol', 't3'],
['DefaultSecureProtocol', 't3s'], ['DefaultTGIOPPassword'],
['DefaultTGIOPPasswordEncrypted', ' ** '], ['DefaultTGIOPUser',
'guest'], ['DomainLogFilter'], ['EnabledForDomainLog', True],
['ExecuteQueues', 'weblogic.kernel.Default,foglight'],
['ExpectedToRun', False], ['ExternalDNSName

Re: IEC - cannot find button

2007-10-29 Thread kyosohma
On Oct 29, 12:58 am, [EMAIL PROTECTED] wrote:
> I'm brand new to Python--and programming in general. I'm trying to use
> IEC to control Internet Explorer. I've navigated to a page, and now
> I'm trying to click a button. The button appears to be called 'PDF
> Preview' but I honestly do not know whether that's the name or the
> caption. Here is my code:
>
>  from win32com.client import Dispatch
>  import IEC
>
>  .
>  .
>  .
>
>  ie = IEC.IEController(window_num = 1)
>  ie.Navigate(URL_part_1 + x + URL_part_2)
>  ie.ClickButton(name='PDF Preview')
>
> (I've also tried replacing name w/ caption but I get a similar error
> message.) I get this error message:
>
> Traceback (most recent call last):
>   File "C:\Program Files\Python25\experiment", line 14, in 
> ie.ClickButton(name='PDF Preview')
>   File "C:\Program Files\Python25\lib\IEC.py", line 126, in
> ClickButton
> elem = elemcoll.item(i)
>   File ">", line 3, in item
> com_error: (-2147024891, 'Access is denied.', None, None)
>
> I really have no idea how to interpret this. I'm pasting the button
> tag below:
>
> 
>   onclick="javascript:performPdfPreview(2);"/>
> 

You might want to look at PAMIE instead. It sounds like a Python
project that's aimed at automating Internet Explorer:
http://sourceforge.net/projects/pamie/

But if you really like COM, I found this tutorial:

http://www.evilbitz.com/2006/10/22/python-ie-automation-thorough-tutorial/

I'm not very good with COM, but I would recommend that you do some
research on it. From the traceback, I would guess that you don't have
administrator privileges (of some sort) on the machine you're running
the script on.

Mike

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


Re: SQLite3; weird error

2007-10-29 Thread TYR
On Oct 29, 11:51 am, Duncan Booth <[EMAIL PROTECTED]>
wrote:
> TYR <[EMAIL PROTECTED]> wrote:
> > To do anything with it, you then need to create a cursor object by
> > calling foo's method cursor (bar = foo.cursor).
>
> Perhaps this would work better if you actually try calling foo's method?
>
> bar = foo.cursor()
>
> Without the parentheses all you are doing is assigning the method to a
> variable, not calling it.

Ah. Apologies for a silly question.

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


Re: Pari Python

2007-10-29 Thread Anton Mellit
Hi,
thanks for the comments. I think I should target on making my module
as a normal python module without using any modifications and
additionally (only additionally) provide some optional workaround for
the '^' and '/' problem. I am going to look at what Michael proposed

> With that in mind, why not implement your shell layer using pypy (python
> on python). That way you can have a full python parser that you can
> modify to your hearts content, running on an unmodified cpython core.
> Or implement your own parser using pyparsing.

> Or how about this:  Implement a shell in python that uses regex to
> replace and translate PariPython syntax into python syntax, and then
> evaluate it on the unmodified core.

Also I will look at how it is done in SAGE. SAGE is very difficult to
work with, it is definitely not pythonic and it is not implemented as
a bunch of python modules like I would prefer it. I can't find out how
to eliminate all the garbage there and leave only the python core. Its
pari support seems superficial. In many cases you have to evaluate
strings using pari interpreter like 'gp("a = intnum(x=0,6,sin(x))")'
(excerpt from the documentation).

Actually it should be nice to have this workaround available
separately for use by other math packages.

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


Built-in functions and keyword arguments

2007-10-29 Thread Armando Serrano Lombillo
Why does Python give an error when I try to do this:

>>> len(object=[1,2])
Traceback (most recent call last):
  File "", line 1, in 
len(object=[1,2])
TypeError: len() takes no keyword arguments

but not when I use a "normal" function:

>>> def my_len(object):
return len(object)

>>> my_len(object=[1,2])
2

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


Python-URL! - weekly Python news and links (Oct 29)

2007-10-29 Thread Gabriel Genellina
QOTW:  "Template engines are amongst the things that seem easy enough to
look at the available software and say 'bah, I'll write my own in a day',
but are complex enough to keep them growing over years until they become
as huge and inaccessible as all the other implementations. Then it's time
for someone else to look at it and say 'bah, I'll write my own in a day'."
- Stefan Behnel
http://groups.google.com/group/comp.lang.python/msg/82f632f0b3142f6e

"Lord have mercy." - Bruno Desthuilliers, on learning of composition of
"... 3 decorators named public, private and protected."
http://groups.google.com/group/comp.lang.python/msg/710d3a156bd 76719


An example showing that there is no point in
generating Python source code:

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

Everything you want to know about attribute access:

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

Not only is there a world beyond Web development, it's even 
important enough for people to write books about it.  *Rapid
GUI Programming with Python and Qt: The Definitive Guide to
PyQt Programming* and *Beginning Game Development with Python
and Pygame ...* just hit the store shelves:

http://www.riverbankcomputing.com/pipermail/pyqt/2007-October/017499.html

http://www.willmcgugan.com/2007/10/04/free-chapter-of-beginning-game-development-with-python-and-pygame/

An example of use of *really* big numbers:

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

Sort-of obfuscation contest: write your own factorial function!

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

Proposal: Decimal literals:

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



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

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

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

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiats":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

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

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

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

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

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

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

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

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

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collect

Re: Built-in functions and keyword arguments

2007-10-29 Thread Duncan Booth
Armando Serrano Lombillo <[EMAIL PROTECTED]> wrote:

> Why does Python give an error when I try to do this:
> 
 len(object=[1,2])
> Traceback (most recent call last):
>   File "", line 1, in 
> len(object=[1,2])
> TypeError: len() takes no keyword arguments
> 
> but not when I use a "normal" function:
> 
 def my_len(object):
>  return len(object)
> 
 my_len(object=[1,2])
> 2
> 
At the C level there are several options for how you define a function 
callable from Python. The most general form is 
METH_VARARGS|METH_KEYWORDS which accepts both a tuple of arguments and a 
dictionary of keyword arguments. These then have to be parsed to find 
the actual arguments.

Many of the builtin functions use only METH_VARARGS which means they 
don't support keyword arguments. "len" is even simpler and uses an 
option METH_O which means it gets a single object as an argument. This 
keeps the code very simple and may also make a slight difference to 
performance.

I don't know if the reason that most builtin functions don't accept 
keywords is just historical (someone would have to go through a lot of 
code and add keyword argument names) or if there really is any 
measurable performance difference to not using the METH_KEYWORDS option. 
Being able to write less C code may be the main factor.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A class question

2007-10-29 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]>
> writes:
> 
>>> As others have answered, an instance can live in many variables,
>> "be bound to many names" would be more accurate IMHO.
> 
> Technically more accurate maybe (but see below), but I was responding
> to a beginner's post, so I was striving for ease of understanding.

The problem is that your formulation implies (to me at least) that the 
variable is actually a kind of container for the object. And I'm not 
sure being inaccurate really helps (OTHO, I often tend to get too 
technical, so who knows which approach is the best here... At least, the 
OP will now have both !-)

>> Python's "variables" are name=>object bindings.
> 
> No reason to use quotes. 

Yes, there's one : to mark the difference between Python-like 
name=>object bindings and C-like labels-on-memory-address variables - 
the latter model being the most commonly known to beginners.

> Variable is just as acceptable a term,

Indeed - no need to refer to chapter and verse here, I've read the book 
too !-)

(snip)

> I disagree with the idea that the terms "name" and "binding" are the
> only correct terminology. 

Which is not what I meant here.

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


Re: Built-in functions and keyword arguments

2007-10-29 Thread Bruno Desthuilliers
Armando Serrano Lombillo a écrit :
> Why does Python give an error when I try to do this:
> 
 len(object=[1,2])
> Traceback (most recent call last):
>   File "", line 1, in 
> len(object=[1,2])
> TypeError: len() takes no keyword arguments
> 
> but not when I use a "normal" function:
> 
 def my_len(object):
>   return len(object)
> 
 my_len(object=[1,2])
> 2

In the second case, the name of the argument *is* 'object'. Which is not 
the case for the builtin len (which, fwiw, has type 
'builtin_function_or_method', not 'function', so inspect.getargspec 
couldn't tell me more).


While we're at it, you should avoid using builtin's names for 
identifiers - here, using 'object' as the arg name shadows the builtin 
'object' class).


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


Re: A class question

2007-10-29 Thread emorfo
On Oct 29, 12:46 pm, "Martin Marcher" <[EMAIL PROTECTED]> wrote:
> 2007/10/29, Hrvoje Niksic <[EMAIL PROTECTED]>:
>
> > Sbe unpx inyhr, urer vf n cbffvoyr vzcyrzragngvba:
> > ...
>
> was that on purpose?
>
> martin
>
> --http://noneisyours.marcher.namehttp://feeds.feedburner.com/NoneIsYours

for humans:


For hack value, here is a possible implementation:


import inspect


def _find(frame, obj):
for name, value in frame.f_locals.iteritems():
if value is obj:
return name
for name, value in frame.f_globals.iteritems():
if value is obj:
return name
raise KeyError("Object not found in frame globals or locals")


class X:
def debug(self):
print ("Caller stores me in %s (among other possible places)"
   % _find(inspect.currentframe(1), self))



>>> xyzzy = X()
>>> xyzzy.debug()


Caller stores me in xyzzy (among other possible places)

>>> a = b = X()
>>> a.debug()


Caller stores me in a (among other possible places)

>>> b.debug()


Caller stores me in a (among other possible places)

>>> X().debug()


Traceback (most recent call last):
  File "", line 1, in 
  File "", line 4, in debug
  File "", line 8, in _find
KeyError: 'Object not found in frame globals or locals'

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


Re: Built-in functions and keyword arguments

2007-10-29 Thread Steven D'Aprano
On Mon, 29 Oct 2007 13:52:04 +, Armando Serrano Lombillo wrote:

> Why does Python give an error when I try to do this:
> 
 len(object=[1,2])
> Traceback (most recent call last):
>   File "", line 1, in 
> len(object=[1,2])
> TypeError: len() takes no keyword arguments
> 
> but not when I use a "normal" function:
> 
 def my_len(object):
>   return len(object)
> 
 my_len(object=[1,2])
> 2

Because len() takes no keyword arguments, just like it says, but my_len() 
is written so it DOES take a keyword argument.

When you call a function foo(object=[1,2]) you are instructing Python to 
bind the value [1,2] to the keyword argument "object". But if the 
function doesn't have a keyword argument named "object" then it will fail 
immediately. Since len() doesn't have ANY keyword arguments, naturally it 
doesn't have one called "object".

You can see the same effect here:

>>> def my_len2(*args):
... return len(arg[0])
...
>>> my_len2(object=[1,2])
Traceback (most recent call last):
  File "", line 1, in 
TypeError: my_len2() got an unexpected keyword argument 'object'


Apart from the error message being slightly different, many (most? all?) 
of the built in functions are like my_len2().

You may be thinking that keyword arguments are the equivalent of this:

object=[1,2]
len(object)

That is not the case. They are not at all equivalent.



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


Re: while within while

2007-10-29 Thread Steven D'Aprano
On Sun, 28 Oct 2007 21:02:02 -0400, Shawn Minisall wrote:

> Thanks a lot for your suggestions.  Unfortunately, a lot of the issues
> brought up were simply the way I was taught by my professor and the way
> she wants things done,having to use a numbered menu as opposed to
> entering r, p or s, being taught just to use one main function for the
> entire program, having to init all variables in the program b4 the
> actual program starts or else points off for each program, while
> statements surrounding every input statement for input validation
> purposes...
> 
> Going beyond those things, would look like someone else wrote my program
> since we didn't talk about or ever cover them in class.

Haven't you heard of "I've been reading ahead from the text book" or 
"I've been reading discussion groups where they talk about good 
programming techniques"?

Besides, you'll probably find your prof will forgive nearly anything if 
you acknowledge it first: plagiarism is considered a worse sin than 
failing to learn anything. Look up this thread on Google Groups, and 
include the URL in your assignment (you might want to give a TinyURL as 
well), and your prof can see for herself that we're not doing your 
homework for you.

(Hey, chances are that she's googling for your name already...)

Unless the assignment explicitly says "DO NOT SPLIT YOUR CODE INTO 
FUNCTIONS", you shouldn't be marked down for writing better code than you 
were asked for.

On the other hand, if the assignment specifies "YOU MUST DO THIS" then 
naturally you must follow the instructions.


* shakes head sadly *

Kids today, more concerned about following instructions than learning...

* half wink * 



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


Re: Built-in functions and keyword arguments

2007-10-29 Thread Duncan Booth
Bruno Desthuilliers <[EMAIL PROTECTED]> 
wrote:

> In the second case, the name of the argument *is* 'object'. Which is not 
> the case for the builtin len (which, fwiw, has type 
> 'builtin_function_or_method', not 'function', so inspect.getargspec 
> couldn't tell me more).
> 
>
> While we're at it, you should avoid using builtin's names for 
> identifiers - here, using 'object' as the arg name shadows the builtin 
> 'object' class).
>

I think you are being a little bit unfair here: help(len) says:

len(...)
len(object) -> integer

Return the number of items of a sequence or mapping.

which implies that the argument to len has the name 'object' (although in 
fact it doesn't have a name). The OP was simply asking about the difference 
in calling conventions, not proposing to write code using 'object' as the 
argument name.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New

2007-10-29 Thread Shawn Milochik
On 10/28/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi!
> Am new to Python and am looking for a sample project that demonstrates
> how to connect to MySQL, save data in MySQL database using a form on a
> web page.
>
> Regards,
> Joseph
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


1. Read this: http://catb.org/~esr/faqs/smart-questions.html

2. You can easily find what you're asking for on Google.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Built-in functions and keyword arguments

2007-10-29 Thread Tim Chase
>> 
>> While we're at it, you should avoid using builtin's names for 
>> identifiers - here, using 'object' as the arg name shadows the builtin 
>> 'object' class).
>> 
> 
> I think you are being a little bit unfair here: help(len) says:
> 
> len(...)
> len(object) -> integer
> 
> Return the number of items of a sequence or mapping.
> 
> which implies that the argument to len has the name 'object' (although in 
> fact it doesn't have a name). 

And to confound matters even further for the uninitiated,

http://docs.python.org/lib/built-in-funcs.html#l2h-45

says that it's "len(s)" instead (but "len(s=[])" doesn't work either)

-tkc




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


Handle Exceptions Inside List Comprehension

2007-10-29 Thread beginner
Hi All,

I am wondering if there is any way to handle exceptions inside list
comprehension. For example,

[f(x) for x in xs]

I want to skip the point if f(x) raises an exception. How can I do
that without totally removing the list comprehension?

Thanks,
Geoffrey

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


Re: A class question

2007-10-29 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]>
writes:

> The problem is that your formulation implies (to me at least) that the
> variable is actually a kind of container for the object.

I really didn't expect it to be read that way, especially since the
sentence claims that the same instance can reside in several
variables.  If the term variable implied containment, that would not
be possible because different variables would imply different objects.

To be fair, the OP probably *did* confuse variables with containment,
and I rot13'ed my hack to avoid unnecessarily prolonging that
confusion.  However, I don't think his confusion is a consequence of
inaccurate terminology, but of an inaccurate mental model of Python
objects.  When the mental model is correct, the term "variable" works
as well as any other; when it's incorrect, using different words for
the same thing is of little help.

>>> Python's "variables" are name=>object bindings.
>>
>> No reason to use quotes. 
>
> Yes, there's one : to mark the difference between Python-like
> name=>object bindings and C-like labels-on-memory-address variables
> the latter model being the most commonly known to beginners.

Are you sure about the last part?  It seems to me that in recent times
more Python beginners come from a Java background than from a C one.
In any case, "variable" is a sufficiently general concept not to be
tied to a specific implementation.  That the concept of variable
differs among programming languages is for me not reason enough to
eschew it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Handle Exceptions Inside List Comprehension

2007-10-29 Thread Paul Rubin
beginner <[EMAIL PROTECTED]> writes:
> [f(x) for x in xs]
> 
> I want to skip the point if f(x) raises an exception. How can I do
> that without totally removing the list comprehension?

def ff(xs):
  for x in xs:
 try: yield f(x)
 except: pass

[x for x in ff(xs)]   or alternatively

list(ff(xs))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: while within while

2007-10-29 Thread kyosohma
On Oct 29, 9:26 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sun, 28 Oct 2007 21:02:02 -0400, Shawn Minisall wrote:
> > Thanks a lot for your suggestions.  Unfortunately, a lot of the issues
> > brought up were simply the way I was taught by my professor and the way
> > she wants things done,having to use a numbered menu as opposed to
> > entering r, p or s, being taught just to use one main function for the
> > entire program, having to init all variables in the program b4 the
> > actual program starts or else points off for each program, while
> > statements surrounding every input statement for input validation
> > purposes...
>
> > Going beyond those things, would look like someone else wrote my program
> > since we didn't talk about or ever cover them in class.
>
> Haven't you heard of "I've been reading ahead from the text book" or
> "I've been reading discussion groups where they talk about good
> programming techniques"?
>
> Besides, you'll probably find your prof will forgive nearly anything if
> you acknowledge it first: plagiarism is considered a worse sin than
> failing to learn anything. Look up this thread on Google Groups, and
> include the URL in your assignment (you might want to give a TinyURL as
> well), and your prof can see for herself that we're not doing your
> homework for you.
>
> (Hey, chances are that she's googling for your name already...)
>
> Unless the assignment explicitly says "DO NOT SPLIT YOUR CODE INTO
> FUNCTIONS", you shouldn't be marked down for writing better code than you
> were asked for.
>
> On the other hand, if the assignment specifies "YOU MUST DO THIS" then
> naturally you must follow the instructions.
>
> * shakes head sadly *
>
> Kids today, more concerned about following instructions than learning...
>
> * half wink *
>
> --
> Steven

I had a professor who insisted that we not use loops and what-not
before they were taught in class as well. It seems to be a standard
thing in Computer Science classes. Kind of like learning mathematical
proofs or doing standard deviation the long way first. In some ways,
it's very helpful. In others, it's extremely lame.

Typical of the college education system though.

Mike

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


two file into a single file

2007-10-29 Thread Beema shafreen
hi everybody,
   I have a two file,
 file 1:
17097
17186
1723
17895
17906
18295
18311
1880
19160
19629

file 2:
17097
17186
1723
17895
17906
18295
18311
1880
19160
19629
how do i make into a single file..like this
file 1 file 2
17097  17097
17186  17097
17186   1880
172317895
17895  17895
17906  17895
18295  8311
18311  188
-- 
http://mail.python.org/mailman/listinfo/python-list

what version python and wxPython comes with Mac OS X Leopard

2007-10-29 Thread chewie54
Hello,

Anyone using Leopard know which versions of Python and wxPython and
any other Python related modules are default with the new OS?

Thanks,

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


Re: Built-in functions and keyword arguments

2007-10-29 Thread Armando Serrano Lombillo
On Oct 29, 3:10 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Armando Serrano Lombillo <[EMAIL PROTECTED]> wrote:
>
>
>
> > Why does Python give an error when I try to do this:
>
>  len(object=[1,2])
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > len(object=[1,2])
> > TypeError: len() takes no keyword arguments
>
> > but not when I use a "normal" function:
>
>  def my_len(object):
> >  return len(object)
>
>  my_len(object=[1,2])
> > 2
>
> At the C level there are several options for how you define a function
> callable from Python. The most general form is
> METH_VARARGS|METH_KEYWORDS which accepts both a tuple of arguments and a
> dictionary of keyword arguments. These then have to be parsed to find
> the actual arguments.
>
> Many of the builtin functions use only METH_VARARGS which means they
> don't support keyword arguments. "len" is even simpler and uses an
> option METH_O which means it gets a single object as an argument. This
> keeps the code very simple and may also make a slight difference to
> performance.
>
> I don't know if the reason that most builtin functions don't accept
> keywords is just historical (someone would have to go through a lot of
> code and add keyword argument names) or if there really is any
> measurable performance difference to not using the METH_KEYWORDS option.
> Being able to write less C code may be the main factor.

Ok. I was suspecting something like this. Performance issues aside, I
think it would be a good idea if built-in functions behaved exactly
the same as normal functions.

BTW, I came into this problem when trying to use functools.partial:

import functools
getattrF = functools.partial(getattr, default=False)

which I think should have worked if getattr behaved as normal
functions do.

In the end I did:

def getattrF(object, name):
return getattr(object, name, False)

Any better idea?

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


Re: two file into a single file

2007-10-29 Thread J. Clifford Dyer
You will need to use the open() builtin for each input file, and again for the 
output file.  Documentation is available in the python tutorial here: 

http://docs.python.org/tut/node9.html#SECTION00920

You should read also the whole tutorial, and work with it until you understand 
it, but for now, that section should get you going.

Cheers,
Cliff


On Mon, Oct 29, 2007 at 09:02:30PM +0530, Beema shafreen wrote regarding two 
file into a single file:
> Delivered-To: [EMAIL PROTECTED]
> Date: Mon, 29 Oct 2007 21:02:30 +0530
> From: "Beema shafreen" <[EMAIL PROTECTED]>
> To: [email protected]
> Subject: two file into a single file
> Precedence: list
> List-Id: General discussion list for the Python programming language
>   
> List-Unsubscribe: ,
>   
> List-Archive: 
> List-Post: 
> List-Help: 
> List-Subscribe: ,
>   
> Errors-To: [EMAIL PROTECTED]
> 
>hi everybody,
>   I have a two file,
> file 1:
>17097
>17186
>1723
>17895
>17906
>18295
>18311
>1880
>19160
>19629
>file 2:
>17097
>17186
>1723
>17895
>17906
>18295
>18311
>1880
>19160
>19629
>how do i make into a single file..like this
>file 1 file 2
>17097  17097
>17186  17097
>17186   1880
>172317895
>17895  17895
>17906  17895
>18295  8311
>18311  188

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


simple try/except question

2007-10-29 Thread Alan Isaac
Is the behavior below expected?
If so, why is the exception not caught?
Thanks,
Alan Isaac

>>> x,y='',''
>>> try: x/y
... except TypeError: print 'oops'
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for /: 'str' and 'str'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Built-in functions and keyword arguments

2007-10-29 Thread Armando Serrano Lombillo
On Oct 29, 3:20 pm, Bruno Desthuilliers  wrote:
> Armando Serrano Lombillo a écrit :
>
> > Why does Python give an error when I try to do this:
>
>  len(object=[1,2])
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > len(object=[1,2])
> > TypeError: len() takes no keyword arguments
>
> > but not when I use a "normal" function:
>
>  def my_len(object):
> >return len(object)
>
>  my_len(object=[1,2])
> > 2
>
> In the second case, the name of the argument *is* 'object'. Which is not
> the case for the builtin len (which, fwiw, has type
> 'builtin_function_or_method', not 'function', so inspect.getargspec
> couldn't tell me more).

so that's the point, built-in functions don't behave as normal
functions.

> 
> While we're at it, you should avoid using builtin's names for
> identifiers - here, using 'object' as the arg name shadows the builtin
> 'object' class).
> 

As Duncan points out, I was using the name object because it's what
you get when you type help(len) (or in the calltips, or in). Anyway, I
don't think there's any harm in overriding a builtin name in such a
small scope (the object=[1,2] won't shadow the built-in object outside
of the function).

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

Re: two file into a single file

2007-10-29 Thread Tim Chase
>I have a two file,
>  file 1:
> 17097
> 17186
> 1723
> 17895
> 17906
> 18295
> 18311
> 1880
> 19160
> 19629
> 
> file 2:
> 17097
> 17186
> 1723
> 17895
> 17906
> 18295
> 18311
> 1880
> 19160
> 19629
> how do i make into a single file..like this
> file 1 file 2
> 17097  17097
> 17186  17097
> 17186   1880
> 172317895
> 17895  17895
> 17906  17895
> 18295  8311
> 18311  188

You can use the tool designed for the job:

   bash$ paste file1.txt file2.txt

Or, if you want to use Python you might be interested in

   for a,b in zip(file('file1.txt'), file('file2.txt')):
 print '%s\t%s' % (a.strip(), b.strip())

If they're big, import itertools.izip() and use it instead of zip()

Variants may be needed depending on the behavior if file1 and 
file2 have different numbers of lines in them.

-tkc



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


swig-python -> shared (vs) static libraries

2007-10-29 Thread abarun22
HI
I am new to SWIG & Python and right now i am in the process of
wrapping some "C" functionalities present in a static library for
python. I do have my C file "name.c" which just contains some helper
functions.
I tried to link my object files (e.g name.o & name_wrap.o) with the
static libraries (whose functionalities need to be wrapped) to form a
shared library that can be imported from Python. While doing so i
cannot be able to access the C data structure from Python and i got
all values as zero. I work in Linux gcc version.
I created my shared object like this:
ld -G name.o name_wrap.o -o _name.so -Bstatic -lfoo1 -lfoo2 -lfoo3.
On the other hand to dig more in to this i tried to simulate the
static libraries with simple dummy code in my file "name.c" so that i
can avoid linking the static libraries. This case i could be able to
retrieve the vaues of the data structure. I wonder if the problem
could be due to linking of the static libraries to create the shared
object.
Any body experienced the same problem or having related ideas pls help
me.
Best regards
Arun

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


Re: Built-in functions and keyword arguments

2007-10-29 Thread Marc 'BlackJack' Rintsch
On Mon, 29 Oct 2007 08:34:58 -0700, Armando Serrano Lombillo wrote:

> On Oct 29, 3:10 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
>>
>> I don't know if the reason that most builtin functions don't accept
>> keywords is just historical (someone would have to go through a lot of
>> code and add keyword argument names) or if there really is any
>> measurable performance difference to not using the METH_KEYWORDS option.
>> Being able to write less C code may be the main factor.
> 
> Ok. I was suspecting something like this. Performance issues aside, I
> think it would be a good idea if built-in functions behaved exactly
> the same as normal functions.

As Steven D'Aprano showed they behave like normal functions.  Even pure
Python functions can have arguments without names:

def spam(*args):
pass

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


Re: while within while

2007-10-29 Thread cokofreedom
On Oct 29, 4:28 pm, [EMAIL PROTECTED] wrote:
> On Oct 29, 9:26 am, Steven D'Aprano <[EMAIL PROTECTED]
>
>
>
> cybersource.com.au> wrote:
> > On Sun, 28 Oct 2007 21:02:02 -0400, Shawn Minisall wrote:
> > > Thanks a lot for your suggestions.  Unfortunately, a lot of the issues
> > > brought up were simply the way I was taught by my professor and the way
> > > she wants things done,having to use a numbered menu as opposed to
> > > entering r, p or s, being taught just to use one main function for the
> > > entire program, having to init all variables in the program b4 the
> > > actual program starts or else points off for each program, while
> > > statements surrounding every input statement for input validation
> > > purposes...
>
> > > Going beyond those things, would look like someone else wrote my program
> > > since we didn't talk about or ever cover them in class.
>
> > Haven't you heard of "I've been reading ahead from the text book" or
> > "I've been reading discussion groups where they talk about good
> > programming techniques"?
>
> > Besides, you'll probably find your prof will forgive nearly anything if
> > you acknowledge it first: plagiarism is considered a worse sin than
> > failing to learn anything. Look up this thread on Google Groups, and
> > include the URL in your assignment (you might want to give a TinyURL as
> > well), and your prof can see for herself that we're not doing your
> > homework for you.
>
> > (Hey, chances are that she's googling for your name already...)
>
> > Unless the assignment explicitly says "DO NOT SPLIT YOUR CODE INTO
> > FUNCTIONS", you shouldn't be marked down for writing better code than you
> > were asked for.
>
> > On the other hand, if the assignment specifies "YOU MUST DO THIS" then
> > naturally you must follow the instructions.
>
> > * shakes head sadly *
>
> > Kids today, more concerned about following instructions than learning...
>
> > * half wink *
>
> > --
> > Steven
>
> I had a professor who insisted that we not use loops and what-not
> before they were taught in class as well. It seems to be a standard
> thing in Computer Science classes. Kind of like learning mathematical
> proofs or doing standard deviation the long way first. In some ways,
> it's very helpful. In others, it's extremely lame.
>
> Typical of the college education system though.
>
> Mike

I remember being taught Java in my first year of University and for
the most part we were given a layout of methods, accessors and what-
have-yas to complete. This gave us a grounding from which to go from,
which I always thought helped a lot. However our lecturers also
accepted people trying other techniques as long as they passed all the
test-cases (which were shown to you when you submitted your work onto
the website (a brilliant way to see if at each edit you were getting
closer to having correct code))

However the otherside of the story was that, depending on the marker
you could get marked down for having written too many comments...

Still while code styling is a convention or standard it isn't strict
(though python aids in this manner!) and while certain methods are
frowned upon and often are a poorer implementation...I've heard many
of my friends argue "well it does what you want..."

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


Re: simple try/except question

2007-10-29 Thread Tim Chase
> Is the behavior below expected?
> If so, why is the exception not caught?
> Thanks,
> Alan Isaac
> 
 x,y='',''
 try: x/y
> ... except TypeError: print 'oops'
> ...
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: unsupported operand type(s) for /: 'str' and 'str'

A typo in your code?  It works for me(tm)...

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
 >>> x,y = '',''
 >>> try: x/y
... except TypeError: print 'oops'
...
oops

-tkc



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


Re: IEC - cannot find button

2007-10-29 Thread daniel
On Oct 29, 6:04 am, [EMAIL PROTECTED] wrote:
> On Oct 29, 12:58 am, [EMAIL PROTECTED] wrote:
>
>
>
> > I'm brand new to Python--and programming in general. I'm trying to use
> > IEC to control Internet Explorer. I've navigated to a page, and now
> > I'm trying to click a button. The button appears to be called 'PDF
> > Preview' but I honestly do not know whether that's the name or the
> > caption. Here is my code:
>
> >  from win32com.client import Dispatch
> >  import IEC
>
> >  .
> >  .
> >  .
>
> >  ie = IEC.IEController(window_num = 1)
> >  ie.Navigate(URL_part_1 + x + URL_part_2)
> >  ie.ClickButton(name='PDF Preview')
>
> > (I've also tried replacing name w/ caption but I get a similar error
> > message.) I get this error message:
>
> > Traceback (most recent call last):
> >   File "C:\Program Files\Python25\experiment", line 14, in 
> > ie.ClickButton(name='PDF Preview')
> >   File "C:\Program Files\Python25\lib\IEC.py", line 126, in
> > ClickButton
> > elem = elemcoll.item(i)
> >   File ">", line 3, in item
> > com_error: (-2147024891, 'Access is denied.', None, None)
>
> > I really have no idea how to interpret this. I'm pasting the button
> > tag below:
>
> > 
> >   > onclick="javascript:performPdfPreview(2);"/>
> > 
>
> You might want to look at PAMIE instead. It sounds like a Python
> project that's aimed at automating Internet 
> Explorer:http://sourceforge.net/projects/pamie/
>
> But if you really like COM, I found this tutorial:
>
> http://www.evilbitz.com/2006/10/22/python-ie-automation-thorough-tuto...
>
> I'm not very good with COM, but I would recommend that you do some
> research on it. From the traceback, I would guess that you don't have
> administrator privileges (of some sort) on the machine you're running
> the script on.
>
> Mike

Thanks for the input, Mike. Since I don't have much experience w/
either, I don't have a strong preference for COM over PAMIE. I'm just
frustrated my script isn't working. I guess it could have to do w/
privileges. I'm using a VPN connection. I tried turning off my
antivirus software before running the module. I can click on the
button I want manually, and get the page I need, so I wonder if I can
adjust some settings to allow Python to take control of certain
things? That or I thought it might have to do w/ a javascript error.
By looking at the tag, does 'PDF Preview' look like the name of the
button or the button caption? Let me know what you think.

Daniel

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


Re: simple try/except question

2007-10-29 Thread Gabriel Genellina
On 29 oct, 12:46, Alan Isaac <[EMAIL PROTECTED]> wrote:

> Is the behavior below expected?
> If so, why is the exception not caught?
> Thanks,
> Alan Isaac
>
> >>> x,y='',''
> >>> try: x/y
>
> ... except TypeError: print 'oops'
> ...
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: unsupported operand type(s) for /: 'str' and 'str'

It works for me, using 2.5.1 and 2.4.3 on Windows XP.
Perhaps you reassigned TypeError?
Python 2.5 says:

py> TypeError


Earlier versions:
py> TypeError


--
Gabriel Genellina

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


Re: simple try/except question

2007-10-29 Thread Alan Isaac
Tim Chase wrote:
> It works for me(tm)...
> Python 2.4.3

Sorry to have left out that detail.
Yes, it works for me in Python 2.4,
but not in 2.5.1.

The code I posted was copyied from the interpreter.

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


Re: Solaris 10 + Sun Studio 12 Pyrhon 2.4.4 64-bit build problem

2007-10-29 Thread MrJean1
Maybe this helps.  Using ./configure --without-gcc  in Python
2.5.1 on Solaris 10 gives a different message.  That message indicates
that C++ compiler 'c++' will be used but the Studio C++ compiler on
Solaris is 'CC'.

Using ./configure  --without-gcc  --with-cxx-main=CC  made that
message go away.  Python did build after that and the tests are
running.

But it is a 32-bit binary, not 64-bit. Another ./configure option will
be needed to build that.

/Jean Brouwers

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


interesting threading result..

2007-10-29 Thread Abandoned
Hi..
I have a interesting threading result..

class GetData(threading.Thread):
   def __init__(self, name):
  threading.Thread.__init__(self)
  self.name = name

   def run(self):
self.data={2:3, 3:4...}

current = GetData(a)
nlist.append(current)
current.start()
end=[]
dd=nlist[0]
dd.join()
result=dd.data
print result
(and it gives me : {2:3, 3:4...} )
end.append(result)
print end
(and it gives me: [, {2:3, 3:4...}]  )
What happen ??
What is the ,  ?
In the first print there isn't it but second print it is in there.
I  don't want ..
How can i escape from it ?

I'm sorry my bad english.
King regards..

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


Re: simple try/except question

2007-10-29 Thread Alan Isaac
False alarm.
Fresh start of interpreter and all is well.
Apologies.
Still tracking.
Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simple try/except question

2007-10-29 Thread Alan Isaac
Gabriel Genellina wrote:
> Perhaps you reassigned TypeError?

Yes, that was it.
Sheesh.

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


Re: A class question

2007-10-29 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]>
> writes:
> 
>> The problem is that your formulation implies (to me at least) that the
>> variable is actually a kind of container for the object.
> 
> I really didn't expect it to be read that way, especially since the
> sentence claims that the same instance can reside in several
> variables.  If the term variable implied containment, that would not
> be possible because different variables would imply different objects.
> 
> To be fair, the OP probably *did* confuse variables with containment,
> and I rot13'ed my hack to avoid unnecessarily prolonging that
> confusion.  However, I don't think his confusion is a consequence of
> inaccurate terminology, but of an inaccurate mental model of Python
> objects.

I'd think it has more to do with an inaccurate mental model of Python's 
variables - hence my (perhaps useless) corrections.

>  When the mental model is correct, the term "variable" works
> as well as any other; when it's incorrect, using different words for
> the same thing is of little help.

This is where our POV differ. IMHO, wording and mental model have a 
strong relationship - IOW, incorrect wording leads to incorrect 
representation.

 Python's "variables" are name=>object bindings.
>>> No reason to use quotes. 
>> Yes, there's one : to mark the difference between Python-like
>> name=>object bindings and C-like labels-on-memory-address variables
>> the latter model being the most commonly known to beginners.
> 
> Are you sure about the last part?

Ok, I would not bet my hand on it !-) But the (non appliable) "pass by 
value"/"pass by reference" question is still asked often enough here to 
be an indication.

>  It seems to me that in recent times
> more Python beginners come from a Java background than from a C one.

Java does have "container" variables for primitive types, and even for 
"references", Java's variables are more than names - they do hold type 
informations too. Now I don't pretend to know how this is really 
implemented, but AFAICT, and at least from a cognitive POV, Java's 
variables model looks very close to the C/C++ model.

FWIW, I came to Python with a VB/C/Java/Pascal background, and Python 
was the first language for which I needed to revise my mental model of 
the "variable" concept.

> In any case, "variable" is a sufficiently general concept not to be
> tied to a specific implementation.

I'd say it's like the "type" concept : it's a general concept, but it's 
not totally implementation-independant. "Type" doesn't mean exactly the 
same thing in static or dynamic languages...

>  That the concept of variable
> differs among programming languages is for me not reason enough to
> eschew it.

I didn't mean to imply "variable" was an inappropriate term - just that 
it may have a somewhat different meaning wrt/ some others more 
mainstream languages. My humble experience is that rewording the whole 
concept in terms of name=>object bindings did sometime help in the past.

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


two files into an alternate list

2007-10-29 Thread Beema shafreen
hi everybody ,
i have a file :
 file 1:
1
2
3
4
5
6


file2:
a
b
c
d
e
f
how do i make the two files into  list like this =
[1,a,2,b,3,c,4,d,5,e,6,f]

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

python2.5 and mysqldb

2007-10-29 Thread writeson
Hi all,

At work we're using python2.3 and I'd like to start getting us moved
up to python2.5. We run Centos4 which is the free, open source version
of RedHat Enterprise. I've got python2.5 installed on this machine,
but am stuck trying to get mysqldb installed and running on this
machine. I've tried with easy_install and by building from the tar
file and both return a long list of errors from a gcc compile. I'm not
sure what to do next to resolve this issue, so if anyone could give me
some guidance it would be greatly appreciated.

Thanks in advance,
Doug

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


Re: elementtree w/utf8

2007-10-29 Thread Tim Arnold

"Stefan Behnel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Tim Arnold wrote:
>> On a related note, I have another question--where/how can I get the
>> cElementTree.py module? Sorry for something so basic, but I tried 
>> installing
>> cElementTree, but while I could compile with setup.py build, I didn't end 
>> up
>> with a cElementTree.py file anywhere.
>
> That's because it compiles into a binary extension module, not a plain 
> Python
> module (mind the 'c' in its name, which stands for the C language here).
>
> I don't know what the standard library extension is under HP-UX, but look 
> a
> little closer at the files that weren't there before, you'll find it.
> Depending on what you did to build it, it might also end up in the "build"
> directory or as an installable package in the "dist" directory.
>
>
>> The directory structure on my system
>> (HPux, but no root access) doesn't work well with setup.py install.
>
> That shouldn't be a problem as long as you keep the binary in your 
> PYTHONPATH.
>
> As suggested before, if you have Python 2.5, you don't even need to 
> install it
> yourself.
>
> Stefan

very nice--thanks. I saw the cElementTree.sl file, but didn't realize it 
would work as-is.
thanks,
--Tim


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


Re: python2.5 and mysqldb

2007-10-29 Thread Diez B. Roggisch
writeson wrote:

> Hi all,
> 
> At work we're using python2.3 and I'd like to start getting us moved
> up to python2.5. We run Centos4 which is the free, open source version
> of RedHat Enterprise. I've got python2.5 installed on this machine,
> but am stuck trying to get mysqldb installed and running on this
> machine. I've tried with easy_install and by building from the tar
> file and both return a long list of errors from a gcc compile. I'm not
> sure what to do next to resolve this issue, so if anyone could give me
> some guidance it would be greatly appreciated.

Which we would love to do if you cared to post the long list of errors.
Unless the PSU launches one of it's psychic members to work on your
problem - but they are very usually very busy.

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


Re: what version python and wxPython comes with Mac OS X Leopard

2007-10-29 Thread Stephen Hansen
Python 2.5.1, and wxPython 2.8.4.0.

On 10/29/07, chewie54 <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> Anyone using Leopard know which versions of Python and wxPython and
> any other Python related modules are default with the new OS?
>
> Thanks,
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Gabriel Genellina
On 29 oct, 09:23, Dick Moores <[EMAIL PROTECTED]> wrote:

> >while True:
> > if msvcrt.getch() == '\r':
>
> I tried it and find that without the msvcrt.kbhit the first key I hit
> doesn't do anything. I have to hit that key again, or another key.

I'd say there is a logic error in your program then; keys don't "do
anything" by themselves.
Try posting a small sample, telling what you get and what you expect.

--
Gabriel Genellina

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


Re: Built-in functions and keyword arguments

2007-10-29 Thread Hendrik van Rooyen
"Tim Chase" <[EMAIL PROTECTED]>

> > I think you are being a little bit unfair here: help(len) says:
> > 
> > len(...)
> > len(object) -> integer
> > 
> > Return the number of items of a sequence or mapping.
> > 
> > which implies that the argument to len has the name 'object' (although in 
> > fact it doesn't have a name). 
> 
> And to confound matters even further for the uninitiated,
> 
> http://docs.python.org/lib/built-in-funcs.html#l2h-45
> 
> says that it's "len(s)" instead (but "len(s=[])" doesn't work either)

Looks like a gotcha to me - its the difference between a keyword
(master = 42) and an assignment  (s='I am a string')

You just can't do that - how is the parser supposed to know that
the second one is an assignment and not a keyword?

len([]) should work, though.

- Hendrik

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


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
At 09:53 AM 10/29/2007, Dick Moores wrote:
>At 09:26 AM 10/29/2007, Gabriel Genellina wrote:
> >On 29 oct, 09:23, Dick Moores <[EMAIL PROTECTED]> wrote:
> >
> > > >while True:
> > > > if msvcrt.getch() == '\r':
> > >
> > > I tried it and find that without the msvcrt.kbhit the first key I hit
> > > doesn't do anything. I have to hit that key again, or another key.
> >
> >I'd say there is a logic error in your program then; keys don't "do
> >anything" by themselves.
> >Try posting a small sample, telling what you get and what you expect.
>
>Huh. Works now.
>
>import msvcrt
>while True:
>  key = msvcrt.getch()
>  if key == 'h':
>  print 'Hello'
>  if key == 'b':
>  print 'Bye'
>  if key == '\r': # 'Enter' key
>  break
>
>Dick

But here's a case where it seems I do need the

if msvcrt.kbhit() line

=
#!/usr/bin/env python
#coding=utf-8
import time
import msvcrt
timeNow = time.time()
oldTimeNow = timeNow
while True:
 if msvcrt.kbhit():
 key = msvcrt.getch()
 if key == 'h':
 print 'Hello'
 if key == 'b':
 print 'Bye'
 if key == '\r': # Enter key
 break
 timeNow = time.time()
 if timeNow - oldTimeNow > 5:
 print "5 seconds passed"
 oldTimeNow = timeNow
==

Without that line:
==
#!/usr/bin/env python
#coding=utf-8
import time
import msvcrt
timeNow = time.time()
oldTimeNow = timeNow
while True:
 #if msvcrt.kbhit():
 key = msvcrt.getch()
 if key == 'h':
 print 'Hello'
 if key == 'b':
 print 'Bye'
 if key == '\r': # Enter key
 break
 timeNow = time.time()
 if timeNow - oldTimeNow > 5:
 print "5 seconds passed"
 oldTimeNow = timeNow


Without that line the "5 seconds passed" report is printed ONLY after 
a "b" or an "h", not what I want.

Dick

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


Re: Built-in functions and keyword arguments

2007-10-29 Thread Jean-Paul Calderone
On Mon, 29 Oct 2007 19:03:34 +0200, Hendrik van Rooyen <[EMAIL PROTECTED]> 
wrote:
>"Tim Chase" <[EMAIL PROTECTED]>
>
>> > I think you are being a little bit unfair here: help(len) says:
>> >
>> > len(...)
>> > len(object) -> integer
>> >
>> > Return the number of items of a sequence or mapping.
>> >
>> > which implies that the argument to len has the name 'object' (although in
>> > fact it doesn't have a name).
>>
>> And to confound matters even further for the uninitiated,
>>
>> http://docs.python.org/lib/built-in-funcs.html#l2h-45
>>
>> says that it's "len(s)" instead (but "len(s=[])" doesn't work either)
>
>Looks like a gotcha to me - its the difference between a keyword
>(master = 42) and an assignment  (s='I am a string')
>

But it's not a keyword:

  >>> len(s=[])
  Traceback (most recent call last):
File "", line 1, in ?
  TypeError: len() takes no keyword arguments
  >>>

I think that's the issue here.

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


Re: Built-in functions and keyword arguments

2007-10-29 Thread Bruno Desthuilliers
Armando Serrano Lombillo a écrit :
> On Oct 29, 3:20 pm, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
>> Armando Serrano Lombillo a écrit :
>>
>>> Why does Python give an error when I try to do this:
>> len(object=[1,2])
>>> Traceback (most recent call last):
>>>   File "", line 1, in 
>>> len(object=[1,2])
>>> TypeError: len() takes no keyword arguments
>>> but not when I use a "normal" function:
>> def my_len(object):
>>>return len(object)
>> my_len(object=[1,2])
>>> 2
>> In the second case, the name of the argument *is* 'object'. Which is not
>> the case for the builtin len (which, fwiw, has type
>> 'builtin_function_or_method', not 'function', so inspect.getargspec
>> couldn't tell me more).
> 
> so that's the point, built-in functions don't behave as normal
> functions.

>> 
>> While we're at it, you should avoid using builtin's names for
>> identifiers - here, using 'object' as the arg name shadows the builtin
>> 'object' class).
>> 
> 
> As Duncan points out, I was using the name object because it's what
> you get when you type help(len) 

That what I thought. But anyway, you're not the only person reading this 
newsgroup, and there are a couple gotchas that are worth pointing out 
for those who don't know yet.

>(or in the calltips, or in). Anyway, I
> don't think there's any harm in overriding a builtin name in such a
> small scope 

In this specific case, possibly - because there are few chances you need 
to get at the builtin object type here. Still, it's better to avoid 
shadowing builtin names IMHO - if only for readability.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A class question

2007-10-29 Thread Donn Ingle
bump :)

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


Re: two files into an alternate list

2007-10-29 Thread J. Clifford Dyer
That depends:

What do you want when you have these two files:

file 1:
a
b
c

file 2:
1
2
3
4
5

Options: 
*['a',1,'b',2,'c',3,None,4,None,5]
*['a',1,'b',2,'c',3,4,5]
*['a',1,'b',2,'c',3]
*Throw an exception

And what if file 1 has more lines than file 2?

Cheers,
Cliff
1
On Mon, Oct 29, 2007 at 09:50:51PM +0530, Beema shafreen wrote regarding two 
files into an alternate list:
> Delivered-To: [EMAIL PROTECTED]
> Date: Mon, 29 Oct 2007 21:50:51 +0530
> From: "Beema shafreen" <[EMAIL PROTECTED]>
> To: [email protected]
> Subject: two files into an alternate list
> Precedence: list
> List-Id: General discussion list for the Python programming language
>   
> List-Unsubscribe: ,
>   
> List-Archive: 
> List-Post: 
> List-Help: 
> List-Subscribe: ,
>   
> Errors-To: [EMAIL PROTECTED]
> 
>hi everybody ,
>i have a file :
> file 1:
>1
>2
>3
>4
>5
>6
>file2:
>a
>b
>c
>d
>e
>f
>how do i make the two files into  list like this =
>[1,a,2,b,3,c,4,d,5,e,6,f]
>regards
>shafreen

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


Re: Function to resize global numpy array interactively in ipython

2007-10-29 Thread Robert Kern
David Sanders wrote:
> Hi,
> 
> I have a script with function definitions which I load into ipython
> for interactive use.
> These functions modify a global numpy array, whose size I need to be
> able to change interactively.  I thus have a script which looks like
> this:
> 
> from numpy import *
> 
> def do_resize(N):
>   global a
>   a = resize(a, N)
> 
> a = array([])
> 
> N=10; do_resize(N)
> print "Length of a is: ", len(a)
> N=20; do_resize(N)
> print "Length of a is: ", len(a)
> 
> 
> If I run this in ipython, using "run resize.py", it correctly outputs
> 10 and then 20.
> If I now type *interactively*  N=30; do_resize(N),  then the length of
> a is still 20, rather than 30 as I was hoping -- somehow I seem to be
> now dealing with a different copy of a?
> 
> Doing the same thing in idle works as I expect, i.e. interactively the
> size is changed to 30.
> 
> Could somebody please explain what's going on, and how I solve the
> problem?

By default, %run executes the script in its own namespace. Then the interactive
prompt's namespace gets updated with the values in that namespace. The global
statement refers to that initial namespace, not the one of the interactive
prompt. Give "%run -i resize.py" a try, though. That should execute the code in
the interactive prompt's namespace.

-- 
Robert Kern

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

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


Re: Using msvcrt (in Windows), how to catch Enter key?

2007-10-29 Thread Dick Moores
At 09:26 AM 10/29/2007, Gabriel Genellina wrote:
>On 29 oct, 09:23, Dick Moores <[EMAIL PROTECTED]> wrote:
>
> > >while True:
> > > if msvcrt.getch() == '\r':
> >
> > I tried it and find that without the msvcrt.kbhit the first key I hit
> > doesn't do anything. I have to hit that key again, or another key.
>
>I'd say there is a logic error in your program then; keys don't "do
>anything" by themselves.
>Try posting a small sample, telling what you get and what you expect.

Huh. Works now.

import msvcrt
while True:
 key = msvcrt.getch()
 if key == 'h':
 print 'Hello'
 if key == 'b':
 print 'Bye'
 if key == '\r': # 'Enter' key
 break

Dick 

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


Re: Built-in functions and keyword arguments

2007-10-29 Thread J. Clifford Dyer
On Mon, Oct 29, 2007 at 02:27:50PM +, Duncan Booth wrote regarding Re: 
Built-in functions and keyword arguments:
> 
> Bruno Desthuilliers <[EMAIL PROTECTED]> 
> wrote:
> 
> > In the second case, the name of the argument *is* 'object'. Which is not 
> > the case for the builtin len (which, fwiw, has type 
> > 'builtin_function_or_method', not 'function', so inspect.getargspec 
> > couldn't tell me more).
> > 
> >
> > While we're at it, you should avoid using builtin's names for 
> > identifiers - here, using 'object' as the arg name shadows the builtin 
> > 'object' class).
> >
> 
> I think you are being a little bit unfair here: help(len) says:
> 
> len(...)
> len(object) -> integer
> 
> Return the number of items of a sequence or mapping.
> 
> which implies that the argument to len has the name 'object' (although in 
> fact it doesn't have a name). The OP was simply asking about the difference 
> in calling conventions, not proposing to write code using 'object' as the 
> argument name.

Hmm  To my mind, that just implies that the *type* of the expected input is 
an object.  Just like the "-> integer" tells you that the type of the output is 
an integer.  If the documentation read "len(s=object) -> integer", then I would 
expect a keyword argument s typed as an object.

Now that might also be misleading, as not all objects have a length (integers, 
for example raise a TypeError).  But the documentation has to say something, 
which doesn't imply that every argument has to be a keyword.

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


Re: Built-in functions and keyword arguments

2007-10-29 Thread Duncan Booth
"J. Clifford Dyer" <[EMAIL PROTECTED]> wrote:

>> I think you are being a little bit unfair here: help(len) says:
>> 
>> len(...)
>> len(object) -> integer
>> 
>> Return the number of items of a sequence or mapping.
>> 
>> which implies that the argument to len has the name 'object'
>> (although in fact it doesn't have a name). The OP was simply asking
>> about the difference in calling conventions, not proposing to write
>> code using 'object' as the argument name.
> 
> Hmm  To my mind, that just implies that the *type* of the expected
> input is an object.  Just like the "-> integer" tells you that the
> type of the output is an integer.  If the documentation read
> "len(s=object) -> integer", then I would expect a keyword argument s
> typed as an object. 
> 

How do you interpret:

>>> help(__import__)
Help on built-in function __import__ in module __builtin__:

__import__(...)
__import__(name, globals={}, locals={}, fromlist=[], level=-1) -> 
module
...
>>> help(int)
Help on class int in module __builtin__:

class int(object)
 |  int(x[, base]) -> integer
...

Can you find any case (other than a single parameter identified as 
'object') where you can interpret the help string as telling you the types 
of the parameters?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: coverage.py: "Statement coverage is the weakest measure of code coverage"

2007-10-29 Thread John Roth
On Oct 28, 9:15 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Kay Schluehr <[EMAIL PROTECTED]> writes:
> > I used to write once a coverage tool ( maybe I can factor this out
> > of my tool suite some time )
>
> That'd be wonderful. I'd like to see comparisons between different
> test-coverage tools, just as we have the different but comparable
> 'pyflakes' and 'pylint' code inspection tools.
>
> > Given it's nature it might act transformative. So a statement:
>
> > if a and b:
> > BLOCK
>
> > can be transformed into
>
> > if a:
> > if b:
> > BLOCK
>
> I don't see that this actually helps in the cases described in the
> original post. The lack of coverage checking isn't "are both sides of
> an 'and' or 'or' expression evaluated", since that's the job of the
> language runtime, and is outside the scope of our unit test.
>
> what needs to be tested is "do the tests execute both the 'true' and
> 'false' branches of this 'if' statement", or "do the tests exercise
> the 'no iterations' case for this loop", et cetera. That is, whether
> all the functional branches are exercised by tests, not whether the
> language is parsed correctly.

Since 'and' and 'or' are short-circuit evaluations, you do need
something to determine if each piece was actually executed. Turning it
into an if-else construct would do this nicely.

John Roth

>
> --
>  \"Know what I hate most? Rhetorical questions."  -- Henry N. Camp |
>   `\   |
> _o__)  |
> Ben Finney


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


Re: Solaris 10 + Sun Studio 12 Pyrhon 2.4.4 64-bit build problem

2007-10-29 Thread MrJean1
Building 64-bit Python is still elusive. I tried various ways to add  -
xtarget=opteron -xarch-amd64  to the C/C++ flags but that still fails
to produce a 64-bit build.  Changing the Makefile is not sufficient
since that causes compilation errors.

It looks like the ./configure command must run with those additional
flags.  Passing the flags in environment variables defining CC and CXX
only works for CXX.  The additional flags do not appear on the C
compiler command lines.

/Jean Brouwers



On Oct 28, 11:03 pm, plumb and tree <[EMAIL PROTECTED]> wrote:
> I've been trying for days to build 64 bit python with Solaris 10 + Sun
> Studio 12.
>
> Can anyone helpl please.
>
> This is how I tried to do build:
>
> # ./configure --prefix=/opt/python2.4 --without-gcc --enable-shared
> checking MACHDEP... sunos5
> checking EXTRAPLATDIR...
> checking for --without-gcc... yes
> checking for --with-cxx=... no
> checking for c++... /opt/SUNWspro/bin/CC
> checking for C++ compiler default output file name... a.out
> checking whether the C++ compiler works... yes
> checking whether we are cross compiling... no
> checking for suffix of executables...
> checking for gcc... cc
> checking for C compiler default output file name... a.out
> checking whether the C compiler works... yes
> checking whether we are cross compiling... no
> checking for suffix of executables...
> checking for suffix of object files... o
> checking whether we are using the GNU C compiler... no
> checking whether cc accepts -g... yes
> checking for cc option to accept ANSI C... none needed
> checking how to run the C preprocessor... /opt/SUNWspro/bin/CC
> configure: error: C preprocessor "/opt/SUNWspro/bin/CC" fails sanity
> check
> See `config.log' for more details.
>
> (sorry for the long log file but I'm not sure which part are
> important)
> config.log:
> This file contains any messages produced by compilers while
> running configure, to aid debugging if configure makes a mistake.
>
> It was created by python configure 2.4, which was
> generated by GNU Autoconf 2.59.  Invocation command line was
>
>   $ ./configure --prefix=/opt/python2.4 --without-gcc --enable-shared
>
> ## - ##
> ## Platform. ##
> ## - ##
>
> hostname = zone2
> uname -m = sun4u
> uname -r = 5.10
> uname -s = SunOS
> uname -v = Generic_118833-36
>
> /usr/bin/uname -p = sparc
> /bin/uname -X = System = SunOS
> Node = zone2
> Release = 5.10
> KernelID = Generic_118833-36
> Machine = sun4u
> BusType = 
> Serial = 
> Users = 
> OEM# = 0
> Origin# = 1
> NumCPU = 1
>
> /bin/arch  = sun4
> /usr/bin/arch -k   = sun4u
> /usr/convex/getsysinfo = unknown
> hostinfo   = unknown
> /bin/machine   = unknown
> /usr/bin/oslevel   = unknown
> /bin/universe  = unknown
>
> PATH: /usr/local/bin
> PATH: /usr/xpg4/bin
> PATH: /usr/sfw/bin
> PATH: /opt/SUNWspro/bin
> PATH: /usr/local/mysql/bin
> PATH: /usr/ccs/bin
> PATH: /usr/local/bin
> PATH: /usr/xpg4/bin
> PATH: /usr/sfw/bin
> PATH: /opt/SUNWspro/bin
> PATH: /usr/local/mysql/bin
> PATH: /usr/ccs/bin
> PATH: /usr/local/bin
> PATH: /usr/xpg4/bin
> PATH: /usr/sfw/bin
> PATH: /opt/SUNWspro/bin
> PATH: /usr/local/mysql/bin
> PATH: /usr/ccs/bin
> PATH: /usr/sbin
> PATH: /usr/bin
> PATH: /usr/openwin/bin
> PATH: /usr/sfw/bin
> PATH: /usr/openwin/bin
> PATH: /usr/sfw/bin
> PATH: /usr/openwin/bin
> PATH: /usr/sfw/bin
>
> ## --- ##
> ## Core tests. ##
> ## --- ##
>
> configure:1510: checking MACHDEP
> configure:1655: result: sunos5
> configure:1661: checking EXTRAPLATDIR
> configure:1676: result:
> configure:1697: checking for --without-gcc
> configure:1746: result: yes
> configure:1752: checking for --with-cxx=
> configure:1773: result: no
> configure:1792: checking for c++
> configure:1818: result: /opt/SUNWspro/bin/CC
> configure:1858: checking for C++ compiler default output file name
> configure:1861: /opt/SUNWspro/bin/CC   -L/opt/SUNWmlib/lib -lrt -lm
> conftest.cc  >&5
> configure:1864: $? = 0
> configure:1910: result: a.out
> configure:1915: checking whether the C++ compiler works
> configure:1921: ./a.out
> configure:1924: $? = 0
> configure:1941: result: yes
> configure:1948: checking whether we are cross compiling
> configure:1950: result: no
> configure:1953: checking for suffix of executables
> configure:1955: /opt/SUNWspro/bin/CC -o conftest   -L/opt/SUNWmlib/lib
> -lrt -lm conftest.cc  >&5
> configure:1958: $? = 0
> configure:1983: result:
> configure:2057: checking for gcc
> configure:2083: result: cc
> configure:2327: checking for C compiler version
> configure:2330: cc -V &5
> cc: Sun C 5.9 SunOS_sparc Patch 124867-01 2007/07/12
> usage: cc [ options] files.  Use 'cc -flags' for details
> configure:2333: $? = 1
> configure:2356: checking for C compiler default output file name
> configure:2359: cc -O2  -L/opt/SUNWmlib/lib -lrt -lm conftest.c  >&5
> configure:2362: $? = 0
> configure:2408: result: a.out
> configure:2413: checking whether the C compiler works
> co

Re: python2.5 and mysqldb

2007-10-29 Thread brad
writeson wrote:

... stuck trying to get mysqldb installed and running on this
> machine. I've tried with easy_install and by building from the tar
> file and both return a long list of errors from a gcc compile. I'm not
> sure what to do next to resolve this issue, so if anyone could give me
> some guidance it would be greatly appreciated.

I would stay at Python 2.3... Centos (like redhat) relies heavily on 
Python. Sure, you could hack it a bit and install both versions (which 
you obviously have), but IMO, it's not worth it. What feature of 2.5 is 
required that 2.3 can't do? I'd guess that the mysqldb compile is 
somehow being confused by the default 2.3 and the version you've 
installed or is conflicting with other versions of itself?

Again, unless there is a compelling reason to upgrade, don't or get a 
more flexible OS that easily allows for this sort of thing (like Debian)

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


ANN: Learning Python 3rd Edition

2007-10-29 Thread Mark Lutz
I'm pleased to announce the release of the 3rd Edition of
the book Learning Python.

This new edition has been updated to cover Python 2.5, and
includes numerous pointers for migrating to Python 3.0 in the
future.  Among other things, this edition has been augmented
with material on function decorators, context managers, the
new relative import syntax, generator expressions, and more.

In addition, this edition has been enhanced to be even more
of a self-paced learning resource, with new end-of-chapter
quizzes, new introductory chapters on types and syntax, and
new materials derived from recent Python training sessions.

For more details, see O'Reilly's web page:

http://www.oreilly.com/catalog/9780596513986/

O'Reilly also has a press release about the book here:

http://press.oreilly.com/pub/pr/1843

Thanks,
--Mark Lutz

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


Re: SQLite3; weird error

2007-10-29 Thread Bruno Desthuilliers
TYR a écrit :
> On Oct 29, 11:51 am, Duncan Booth <[EMAIL PROTECTED]>
> wrote:
> 
>>TYR <[EMAIL PROTECTED]> wrote:
>>
>>>To do anything with it, you then need to create a cursor object by
>>>calling foo's method cursor (bar = foo.cursor).
>>
>>Perhaps this would work better if you actually try calling foo's method?
>>
>>bar = foo.cursor()
>>
>>Without the parentheses all you are doing is assigning the method to a
>>variable, not calling it.
> 
> 
> Ah. Apologies for a silly question.
> 
Not so silly (considering you're somewhat new to Python, which seems 
obvious here) - some languages work otherwise.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A class question

2007-10-29 Thread Donn Ingle
> vzcbeg vafcrpg
> 
> qrs _svaq(senzr, bow):
> sbe anzr, inyhr va senzr.s_ybpnyf.vgrevgrzf():
> vs inyhr vf bow:
> erghea anzr
> sbe anzr, inyhr va senzr.s_tybonyf.vgrevgrzf():
> vs inyhr vf bow:
> erghea anzr
> envfr XrlReebe("Bowrpg abg sbhaq va senzr tybonyf be ybpnyf")
> 
> pynff K:
> qrs qroht(frys):
> cevag ("Pnyyre fgberf zr va %f (nzbat bgure cbffvoyr cynprf)"
>% _svaq(vafcrpg.pheeragsenzr(1), frys))

Now that's taking i18n too far. Klingon is not a widely understood
language :D


\d

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


Re: python logging config file doesn't allow filters?

2007-10-29 Thread Vinay Sajip
On 26 Oct, 17:23, Matthew Wilson <[EMAIL PROTECTED]> wrote:
> I'm studying
> filters and the config-file approach.  Is it possible to define a filter
> somehow and then refer to it in my config file?

I'm afraid not. There's currently no support for filters in the
configuration file format, and no plans to include them in the near
future (your post is the first time configuring filters has been
mentioned). However, if you would like to submit a patch, I'll
certainly take a look at it!

Best regards,

Vinay sajip

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


Re: clear shell screen

2007-10-29 Thread Shawn Minisall
Hmm...it works fine within the command line but then when I import os in 
python and then try os.system("cls"), i get that very fast 
opening/closing window and 0 inside the shell.

Gabriel Genellina wrote:
> En Mon, 29 Oct 2007 00:08:14 -0300, Shawn Minisall  
> <[EMAIL PROTECTED]> escribi�:
>
>   
>> Does anyone know how to clear the shell screen completely ?  I tried
>> import os and then os.system("clear") was said to have worked in Windows
>> XP, but it's just bringing up another window, then it turns black and
>> then it closes in within about a second moving the prompt at the
>> os.system("clear") line .  I've also tried os.system("cls") with the
>> same results.
>> 
>
> Try running cls from a command prompt. If it works, it should work from  
> inside Python, using os.system("cls")
>
>
>   

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

Re: setting variables in outer functions

2007-10-29 Thread Tommy Nordgren

On 29 okt 2007, at 21.59, brad wrote:

> Tommy Nordgren wrote:
>> Given the following:
>> def outer(arg)
>>  avar = ''
>>  def inner1(arg2)
>>   # How can I set 'avar' here ?
>
> Try this... works for me... maybe not for you?
>
> def outer(avar=False):
>  print avar
>  if avar == True:
>  return
>
>  def inner(avar=True):
>  print avar
>  return avar
>
>  outer(inner())
>
> outer()
> --  
> http://mail.python.org/mailman/listinfo/python-list
This is not a general solution to this problem.
What works, though, (I just thought of it) is to do the following:
def outer(arg):
 adict = {}
 def inner1(arg):
  adict['avar'] = 'something'
 #now the value set by inner1 is available to other nested functions
--
What is a woman that you forsake her, and the hearth fire and the  
home acre,
to go with the old grey Widow Maker.  --Kipling, harp song of the  
Dane women
Tommy Nordgren
[EMAIL PROTECTED]



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


  1   2   >