Re: 32 bit bdist_wininst vs x64 platform

2010-09-10 Thread Mark Hammond

Hi Robin,

On 9/09/2010 9:28 PM, Robin Becker wrote:

A reportlab user is using 32 bit python on x64 win 2003. he has a
problem installing our bdist_wininst exe because the installer cannot
find python.


That should work fine - lots of pywin32 users do exactly that.


Apparently the installer is looking at HKLM\Software to locate python,
but on x64 32 bit program requests get redirected to
HKLM\Software\Wow6432Node (Extended explanation in KB article 896459).

Is this fixable by me making a local patch to my distutils to check for
the real platform and modifying the RegOpenKeyEx call? Or is there some
distutils magic that I'm missing?


As you mention, 32bit apps querying the registry get redirected in some 
cases - but so long as the 32bit bdist_wininst stub is used, that too 
will get redirected, so it should all work out fine.  Is it possible 
they are attempting to install an x64 version of reportlab on a 32bit 
python?


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


Re: Printing the name of a variable

2010-09-10 Thread Paul Rudin
Stephen Boulet  writes:

> Does an arbitrary variable carry an attribute describing the text in
> its name? I'm looking for something along the lines of:
>
> x = 10
> print x.name
 'x'
>
> Perhaps the x.__getattribute__ method? Thanks.

The first thing is... what is your use case for this? I'd guess that you
probably don't want to do this even if you think you do :)

The thing referred to by x is the number 10. When you write x.name (or
property) then you're dealing with the number 10, not with some
representation of the variable x. There may be many variables (or none)
that refer to that number at any given time during the execution of your
code... and the object itself "knows" nothing about any of these.

A good way to think about variable lookup is as a dictionary . It's
something like "variables['x'].name". Once the "varables['x'] bit has
been evaluated the link with 'x' is gone... we just have the result of
the lookup.

If you want to know how it actually works, then read up on python
namespaces and scopes, e.g. here:
.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Python works: What do you know about support for negative indices?

2010-09-10 Thread Ulrich Eckhardt
Raymond Hettinger wrote:
> collections.deque('abcde').__getitem__[-2]  # extension class, magic
> method

Small nit: You don't mean [square] brackets here, right?

Otherwise, good posting, thank you!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


inspect the call stack

2010-09-10 Thread bussiere bussiere
i v'e got this :
i've got toto.py :

import titi
def niwhom():
pass

and titi.py :

def nipang():
 pass

how can i know in titi.py that's it's toto.py that is calling titi.py
and the path of toto ?

how can i inspect the call stack or an other way ?

Regards
Bussiere
Google Fan boy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 32 bit bdist_wininst vs x64 platform

2010-09-10 Thread Robin Becker

..


As you mention, 32bit apps querying the registry get redirected in some cases -
but so long as the 32bit bdist_wininst stub is used, that too will get
redirected, so it should all work out fine. Is it possible they are attempting
to install an x64 version of reportlab on a 32bit python?

..

I'm a bit puzzled about this as well, they mentioned something about the python 
being embedded so perhaps that's the problem. I am trying to ascertain the exact 
context.



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


Re: SendKeys and Python 2.7

2010-09-10 Thread Lawrence D'Oliveiro
In message , Jakson A. 
Aquino wrote:

> I would like to send code from Vim [1] to R [2] on Microsoft Windows.

Why such a roundabout way? Why not just run R in a subprocess and feed it a 
script to run?

> [1] http://www.vim.org/
> [2] http://www.r-project.org/

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


Re: [Tutor] Arguments from the command line

2010-09-10 Thread Lawrence D'Oliveiro
In message <8662yfklzu@aiuole.stru.polimi.it>, Giacomo Boffi wrote:

> Dennis Lee Bieber  writes:
> 
>> FORTRAN just differentiates by having the main file start with
>> PROGRAM random_name
>> whereas subfiles are all either (or both)
>> SUBROUTINE another_name(args)
>> FUNCTION that_other_name(args)
> 
> no BLOCKDATA?

I think you mean COMMON.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Arguments from the command line

2010-09-10 Thread Lawrence D'Oliveiro
In message , Mel wrote:

> But historical COBOL didn't pass parameters anyway.  You read
> your optional arguments from a file, or accepted a few from an input
> device.

I think it could also read from switches. As in front-panel on/off switches.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Python works: What do you know about support for negative indices?

2010-09-10 Thread Giacomo Boffi
Ben Finney  writes:

> Raymond Hettinger  writes:
>
>> It doesn't seem to be common knowledge when and how a[x] gets
>> translated to a[x+len(x)].  So, here's a short info post on how Python
>> supports negative indices for sequences.
>
> Thanks for this. Could you post your messages using a channel that
> doesn't arbitrarily split your paragraphs into long-short-long-short
> lines?

hi Ben, i see that you uses gnus... well, it's gnus that does the
unwanted formatting

try C-u g, as dettailed below, ciao

g runs `gnus-summary-show-article'

`gnus-summary-show-article' is an interactive compiled Lisp function
  -- loaded from "gnus-sum"
(gnus-summary-show-article &optional ARG)

Documentation:
Force redisplaying of the current article.
If ARG (the prefix) is a number, show the article with the charset
defined in `gnus-summary-show-article-charset-alist', or the charset
input.
If ARG (the prefix) is non-nil and not a number, show the raw article
without any article massaging functions being run.  Normally, the key
strokes are `C-u g'.
-- 
la lenza penzola
   -- PMF, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing the name of a variable

2010-09-10 Thread Jonathan Hartley
On Sep 9, 9:11 pm, Albert Hopkins  wrote:
> On Thu, 2010-09-09 at 12:43 -0700, Stephen Boulet wrote:
> > Does an arbitrary variable carry an attribute describing the text in
> > its name? I'm looking for something along the lines of:
>
> > x = 10
> > print x.name
> > >>> 'x'
>
> > Perhaps the x.__getattribute__ method? Thanks.
>
> Variables are not objects and so they have no attributes.
>
> You can't really de-reference the object being referenced as it can
> potentially contain multiple references, but an innacurate way of doing
> this would be, e.g.
>
> >>> x = [1, 2, 3]
> >>> y = x
> >>> g = globals()
> >>> varnames = [i for i in g if g[i] is x]
>
> ['x', 'y']
>
> But this cries the question: why do you want to do this?  And usually
> that question is asked when someone thinks that a: you shouldn't need to
> do this and b: whatever the desired effect there is probably a better
> way of accomplishing it.

I have in the past wondered about creating a kind of graphical
debugger, that rendered representations of all the objects in globals
and/or locals, to give you a visual representation of your variables
and their states. Would this be a valid use case to try and look up
the variable names which reference various in-memory objects?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Python works: What do you know about support for negative indices?

2010-09-10 Thread Steven D'Aprano
On Thu, 09 Sep 2010 18:37:49 -0700, Raymond Hettinger wrote:

> Hello Folks.
> 
> It doesn't seem to be common knowledge when and how a[x] gets translated
> to a[x+len(x)].  So, here's a short info post on how Python supports
> negative indices for sequences.
[...]
> Hope you all found this to be informative,


Thanks Raymond!


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


Re: Printing the name of a variable

2010-09-10 Thread Simon Brunning
On 9 September 2010 20:43, Stephen Boulet  wrote:
> Does an arbitrary variable carry an attribute describing the text in
> its name? I'm looking for something along the lines of:
>
> x = 10
> print x.name
 'x'



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


Re: [Tutor] Arguments from the command line

2010-09-10 Thread Giacomo Boffi
Lawrence D'Oliveiro  writes:

> In message <8662yfklzu@aiuole.stru.polimi.it>, Giacomo Boffi wrote:
>
>> Dennis Lee Bieber  writes:
>> 
>>> FORTRAN just differentiates by having the main file start with
>>> PROGRAM random_name
>>> whereas subfiles are all either (or both)
>>> SUBROUTINE another_name(args)
>>> FUNCTION that_other_name(args)
>> 
>> no BLOCKDATA?
>
> I think you mean COMMON.

i meant BLOCKDATA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Python works: What do you know about support for negative indices?

2010-09-10 Thread Daniel Fetchinson
> Raymond Hettinger  writes:
>
>> It doesn't seem to be common knowledge when and how a[x] gets
>> translated to a[x+len(x)].  So, here's a short info post on how Python
>> supports negative indices for sequences.
>
> Thanks for this. Could you post your messages using a channel that
> doesn't arbitrarily split your paragraphs into long-short-long-short
> lines?

It came across fine for me as well (gmail with basic html interface).

> It makes paragraphs burdensome to read, and I skipped most of the
> message because of that.

You might want to switch to a client where you do not have this problem.

> I encourage anyone whose messages are munged like that to seek
> correction from their mail service provider, and switch to a different
> one until it's fixed.

I encourage anyone who has problems with reading various emails,
newsgroup postings, forums and what not, to start using modern tools
that work with the vast majority of other tools.

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 32 bit bdist_wininst vs x64 platform

2010-09-10 Thread Robin Becker

On 10/09/2010 09:52, Robin Becker wrote:

..


As you mention, 32bit apps querying the registry get redirected in some cases -
but so long as the 32bit bdist_wininst stub is used, that too will get
redirected, so it should all work out fine. Is it possible they are attempting
to install an x64 version of reportlab on a 32bit python?

..

I'm a bit puzzled about this as well, they mentioned something about the python
being embedded so perhaps that's the problem. I am trying to ascertain the exact
context.


I found out that although the end users had installed the amd64 python they were 
using reportlab-2.4.win32-py2.6.exe which is 32 bit. That complained until they 
fixed everything up by brute force registry copying. Fortunately, I don't think 
the pyds are importable and reportlab is robust enough to fall back to a working 
state even without those.

--
Robin Becker

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


Re: include a file in a python program

2010-09-10 Thread Bruno Desthuilliers

Steven D'Aprano a écrit :

On Mon, 06 Sep 2010 00:57:30 +0200, bussiere bussiere wrote:


i've got a python.txt that contain python and it must stay as it
(python.txt)


Why? Is it against the law to change it? *wink*
 

how can i include it in my program ?
import python.txt doesn't work



You could write a custom importer to handle it, but I can't help you with 
that. Try Google.



is there a way :
a) to make an include("python.txt")
b) tell him to treat .txt as .py file that i can make an import python ?


fp = open("python.txt")
text = fp.read()
fp.close()
exec(text)


or just:

execfile("python.txt")


But keep in mind that the contents of python.txt will be executed as if 
you had typed it yourself. If you don't trust the source with your life 
(or at least with the contents of your computer), don't execute it.


+10

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


Re: inspect the call stack

2010-09-10 Thread Bruno Desthuilliers

bussiere bussiere a écrit :

i v'e got this :
i've got toto.py :

import titi
def niwhom():
pass

and titi.py :

def nipang():
 pass

how can i know in titi.py that's it's toto.py that is calling titi.py
and the path of toto ?

how can i inspect the call stack or an other way ?


http://www.google.fr/search?q=python+inspect+the+call+stack

First answer should point you to the relevant part of the FineManual(tm):
http://docs.python.org/library/inspect.html


And while we're at it, what about not opening a new thread for a 
question already partially answered ?



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


Trap Authentication Errors in HTTP Request

2010-09-10 Thread naugiedoggie
Hello,

I have a script that authenticates to a web service provider to
retrieve data.  This script provides an authentication header built in
a very basic way like this:


# Creates an authentication object with the credentials for a given
URL
def createPasswordManager(headers) :
passwordManager = urllib2.HTTPPasswordMgrWithDefaultRealm()
 
passwordManager.add_password(None,overview_url,headers[0],headers[1])
return passwordManager

# Creates an authentication handler for the authentication object
created above
def createAuthenticationHandler(passwordManager) :
authenticationHandler =
urllib2.HTTPBasicAuthHandler(passwordManager)
return authenticationHandler

# Creates an opener that sets the credentials in the Request
def createOpener(authHandler) :
return urllib2.build_opener(authHandler)


This script makes multiple calls for data.  I would like to trap an
exception for authentication failure so that it doesn't go through its
entire list of calls when there's a problem with the login.  The
assumption is that if there is a login failure, the script is using
incorrect authentication information.

I have the call for data retrieval wrapped in try/except, to catch
HTTPError, but apparently no '401' is explicitly thrown when
authentication fails.  And I don't see an explicit Exception that is
thrown in urllib2 for handling these failures.

How can I achieve my goal of trapping these exceptions and exiting
cleanly?

Thanks.

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


How to Convert IO Stream to XML Document

2010-09-10 Thread jakecjacobson
I am trying to build a Python script that reads a Sitemap file and
push the URLs to a Google Search Appliance.  I am able to fetch the
XML document and parse it with regular expressions but I want to move
to using native XML tools to do this.  The problem I am getting is if
I use urllib.urlopen(url) I can convert the IO Stream to a XML
document but if I use urllib2.urlopen and then read the response, I
get the content but when I use minidom.parse() I get a "IOError:
[Errno 2] No such file or directory:" error

THIS WORKS but will have issues if the IO Stream is a compressed file
def GetPageGuts(net, url):
pageguts = urllib.urlopen(url)
xmldoc = minidom.parse(pageguts)
return xmldoc

# THIS DOESN'T WORK, but I don't understand why
def GetPageGuts(net, url):
request=getRequest_obj(net, url)
response = urllib2.urlopen(request)
response.headers.items()
pageguts = response.read()
# Test to see if the response is a gzip/compressed data stream
if isCompressedFile(response, url):
compressedstream = StringIO.StringIO(pageguts)
gzipper = gzip.GzipFile(fileobj = compressedstream)
pageguts = gzipper.read()
xmldoc = minidom.parse(pageguts)
response.close()
return xmldoc

# I am getting the following error
Starting SiteMap Manager ...
Traceback (most recent call last):
  File "./tester.py", line 267, in ?
main()
  File "./tester.py", line 49, in main
fetchSiteMap(ResourceDict, line)
  File "./tester.py", line 65, in fetchSiteMap
pageguts = GetPageGuts(ResourceDict['NET'], url)
  File "./tester.py", line 89, in GetPageGuts
xmldoc = minidom.parse(pageguts)
  File "/usr/lib/python2.4/xml/dom/minidom.py", line 1915, in parse
return expatbuilder.parse(file)
  File "/usr/lib/python2.4/xml/dom/expatbuilder.py", line 922, in
parse
fp = open(file, 'rb')
IOError: [Errno 2] No such file or directory: '\nhttp://www.sitemaps.org/
schemas/sitemap/0.9">\n\nhttp://www.myorg.org/janes/
sitemaps/binder_sitemap.xml\n2010-09-09\n\n\nhttp://www.myorg.org/janes/sitemaps/
dir_sitemap.xml\n2010-05-05\n
\n\nhttp://www.myorg.org/janes/sitemaps/
mags_sitemap.xml\n2010-09-09\n
\n\nhttp://www.myorg.org/janes/sitemaps/
news_sitemap.xml\n2010-09-09\n
\n\nhttp://www.myorg.org/janes/sitemaps/
sent_sitemap.xml\n2010-09-09\n
\n\nhttp://www.myorg.org/janes/sitemaps/
srep_sitemap.xml\n2001-05-04\n
\n\nhttp://www.myorg.org/janes/sitemaps/yb_sitemap.xml\n2010-09-09\n\n\n'

# A couple of supporting things
def getRequest_obj(net, url):
request = urllib2.Request(url)
request.add_header('User-Agent', 'ICES Sitemap Bot dni-ices-
searchad...@ugov.gov')
request.add_header('Accept-encoding', 'gzip')
return request

def isCompressedFile(r, u):
answer=False
if r.headers.has_key('Content-encoding'):
answer=True
else:
# Check to see if the URL ends in .gz
if u.endswith(".gz"):
answer=True
return answer

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


Re: How to Convert IO Stream to XML Document

2010-09-10 Thread Nitin Pawar
try using parse from string ... and try
 minidom.parse(StringIO.StingIO(string)).documentElement

On Fri, Sep 10, 2010 at 9:50 PM, jakecjacobson wrote:

> I am trying to build a Python script that reads a Sitemap file and
> push the URLs to a Google Search Appliance.  I am able to fetch the
> XML document and parse it with regular expressions but I want to move
> to using native XML tools to do this.  The problem I am getting is if
> I use urllib.urlopen(url) I can convert the IO Stream to a XML
> document but if I use urllib2.urlopen and then read the response, I
> get the content but when I use minidom.parse() I get a "IOError:
> [Errno 2] No such file or directory:" error
>
> THIS WORKS but will have issues if the IO Stream is a compressed file
> def GetPageGuts(net, url):
>pageguts = urllib.urlopen(url)
>xmldoc = minidom.parse(pageguts)
>return xmldoc
>
> # THIS DOESN'T WORK, but I don't understand why
> def GetPageGuts(net, url):
>request=getRequest_obj(net, url)
>response = urllib2.urlopen(request)
>response.headers.items()
>pageguts = response.read()
># Test to see if the response is a gzip/compressed data stream
>if isCompressedFile(response, url):
>compressedstream = StringIO.StringIO(pageguts)
>gzipper = gzip.GzipFile(fileobj = compressedstream)
>pageguts = gzipper.read()
>xmldoc = minidom.parse(pageguts)
>response.close()
>return xmldoc
>
> # I am getting the following error
> Starting SiteMap Manager ...
> Traceback (most recent call last):
>  File "./tester.py", line 267, in ?
>main()
>  File "./tester.py", line 49, in main
>fetchSiteMap(ResourceDict, line)
>  File "./tester.py", line 65, in fetchSiteMap
>pageguts = GetPageGuts(ResourceDict['NET'], url)
>  File "./tester.py", line 89, in GetPageGuts
>xmldoc = minidom.parse(pageguts)
>  File "/usr/lib/python2.4/xml/dom/minidom.py", line 1915, in parse
>return expatbuilder.parse(file)
>  File "/usr/lib/python2.4/xml/dom/expatbuilder.py", line 922, in
> parse
>fp = open(file, 'rb')
> IOError: [Errno 2] No such file or directory: ' encoding="UTF-8"?>\nhttp://www.sitemaps.org/
> schemas/sitemap/0.9">\n\nhttp://www.myorg.org/janes/
> sitemaps/binder_sitemap.xml\n2010-09-09\n sitemap>\n\nhttp://www.myorg.org/janes/sitemaps/
> dir_sitemap.xml\n2010-05-05\n
> \n\nhttp://www.myorg.org/janes/sitemaps/
> mags_sitemap.xml\n2010-09-09\n
> \n\nhttp://www.myorg.org/janes/sitemaps/
> news_sitemap.xml\n2010-09-09\n
> \n\nhttp://www.myorg.org/janes/sitemaps/
> sent_sitemap.xml\n2010-09-09\n
> \n\nhttp://www.myorg.org/janes/sitemaps/
> srep_sitemap.xml\n2001-05-04\n
> \n\nhttp://www.myorg.org/janes/sitemaps/yb_sitemap.xml loc>\n2010-09-09\n\n\n'
>
> # A couple of supporting things
> def getRequest_obj(net, url):
>request = urllib2.Request(url)
>request.add_header('User-Agent', 'ICES Sitemap Bot dni-ices-
> searchad...@ugov.gov')
>request.add_header('Accept-encoding', 'gzip')
>return request
>
> def isCompressedFile(r, u):
>answer=False
>if r.headers.has_key('Content-encoding'):
>answer=True
>else:
># Check to see if the URL ends in .gz
>if u.endswith(".gz"):
>answer=True
>return answer
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Ugh! Python 3.1.x and MySQL

2010-09-10 Thread fuglyducky
Most of the python books coming out now are Py3K. I just started
programming and have a need to access a MySQL database. I would like
to use Python to do this. Unfortunately, I cannot find anyone that has
created anything that allows my to do this.

I've tried installing an ODBC driver and using sqlalchemy, oursql, and
a few other things with no luck.

So...just wondering if anyone is aware of any libraries/modules that I
can use to connect to a MySQL DB using Python 3.1.x?

Ideally, I'd like to be able to this from both x86 and x64 systems (if
that makes any difference).

Thanks for any input you may have!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SendKeys and Python 2.7

2010-09-10 Thread Jakson A. Aquino
On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro
 wrote:
> In message , Jakson A.
> Aquino wrote:
>
>> I would like to send code from Vim [1] to R [2] on Microsoft Windows.
>
> Why such a roundabout way? Why not just run R in a subprocess and feed it a
> script to run?

Emacs with ESS runs R in a subprocess (at least I think it does). Vim
can't do that.

The plugin doesn't simply send code to R. It has many other features
that make it easier to edit R scripts.

Best,

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


Re: [Python-ideas] Why not f(*my_list, *my_other_list) ?

2010-09-10 Thread MRAB

On 10/09/2010 17:37, cool-RR wrote:

I noticed that it's impossible to call a Python function with two
starred argument lists, like this: `f(*my_list, *my_other_list)`. I
mean, if someone wants to feed two lists of arguments into a function,
why not?

I understand why you can't have two stars in a function definition; But
why can't you have two (or more) stars in a function call?


Would there be any advantage over `f(*(my_list + my_other_list))`?
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Why not f(*my_list, *my_other_list) ?

2010-09-10 Thread Ian Kelly
On Fri, Sep 10, 2010 at 10:52 AM, MRAB  wrote:
> On 10/09/2010 17:37, cool-RR wrote:
>>
>> I noticed that it's impossible to call a Python function with two
>> starred argument lists, like this: `f(*my_list, *my_other_list)`. I
>> mean, if someone wants to feed two lists of arguments into a function,
>> why not?
>>
>> I understand why you can't have two stars in a function definition; But
>> why can't you have two (or more) stars in a function call?
>>
> Would there be any advantage over `f(*(my_list + my_other_list))`?

That fails if my_list and my_other_list are different types, whereas
the *args syntax happily accepts any iterable object.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Why not f(*my_list, *my_other_list) ?

2010-09-10 Thread Stefan Behnel

Ian Kelly, 10.09.2010 19:03:

On Fri, Sep 10, 2010 at 10:52 AM, MRAB  wrote:

On 10/09/2010 17:37, cool-RR wrote:


I noticed that it's impossible to call a Python function with two
starred argument lists, like this: `f(*my_list, *my_other_list)`. I
mean, if someone wants to feed two lists of arguments into a function,
why not?

I understand why you can't have two stars in a function definition; But
why can't you have two (or more) stars in a function call?


Would there be any advantage over `f(*(my_list + my_other_list))`?


That fails if my_list and my_other_list are different types, whereas
the *args syntax happily accepts any iterable object.


But I think it's still a rare enough use case to require

f(*(tuple(my_list) + tuple(my_other_list)))

when you need it, although the concatenation would likely get split up and 
moved into an explicit variable anyway.


Stefan

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


Re: Function Point Analysis (FPA) - Equivalent lines of code of Python

2010-09-10 Thread John Roth
On Sep 9, 2:30 am, Nicholas  wrote:
> Hi,
>
>   In FPA, there are tables which shows equivalent lines of code for
> each Function Point (FP) for a number of programming languages.
>
>   e.g.http://www.qsm.com/?q=resources/function-point-languages-table/index
>
>   However, I have yet to find the figures for Python.
>
>   Is someone able to advise the closest language equivalent.
>
> Regards

Function points do not translate to lines of code except when they're
standardized across a specific organization's portfolio of software. I
agree with Paul, any global table trying to do that is going to be
pretty bogus.

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


Re: [Python-ideas] Why not f(*my_list, *my_other_list) ?

2010-09-10 Thread Paul Rubin
Ian Kelly  writes:
>> Would there be any advantage over `f(*(my_list + my_other_list))`?
>
> That fails if my_list and my_other_list are different types, whereas
> the *args syntax happily accepts any iterable object.

f(*itertools.chain(my_list, my_other_list))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to kill a subprocess

2010-09-10 Thread cerr
On Sep 9, 4:18 pm, MRAB  wrote:
> On 09/09/2010 23:52, cerr wrote:
>
>
>
> > On Sep 9, 3:29 pm, Alain Ketterlin
> > wrote:
> >> cerr  writes:
> >>> I'm calling a python script from a php script which again calls a perl
> >>> script with subprocess.popen().
> >>> This seems to work fine so far only that once the python script
> >>> completed it is becoming a zombie because the perl script in the
> >>> background is still running... so before i exit the python script, i
> >>> would need to kill my perl subprocess.
> >>> How can i do so?
>
> >> x.terminate() (and then x.wait()) where x is the value returned by
> >> subprocess.Popen().
> > Well, this is what I have:
>
> >    writelog("starting GPS simulator")
> >    commandlist=[GPSsim,proto,GPSfile]
> >    writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2])
> >    process=subprocess.Popen(commandlist)
> >    writelog("GPS simulator started")
> >    ...
> >    ...
> >    os.kill(process.pid,9)
> >    os.wait()
>
> > but this is not working for me... :( any clues?
>
> >> P/S: I'm not sure why the python process survives, and I think your use
> >> of "zombie" is not correct (afaik a zombie is an exited process whose
> >> parent hasn't called wait() yet)
>
> > This is what I have:
>
> > localhost cgi-bin # ps ax | grep py
> > 11853 ?        Z      0:00 [python2.6]
> > 12029 pts/1    S+     0:00 grep --colour=auto py
>
> > The 'Z' you see there stands for Zombie
>
> How about:
>
>      process.kill() # New in Python 2.6
>
> or:
>
>      os.kill(process.pid, 9)
>
> then:
>
>      process.wait()
>
> or:
>
>      os.waitpid(process.pid, 0)

HI MRAB,

Thanks for your suggestion, changed my code now to:

  process=subprocess.Popen(commandlist)
  ...
  ...
  process.kill()
  os.waitpid(process.pid, 0)
but it's not killing the process running. it still runs in the
background and i don't see any errors, we're running python 2.6.4
any more clues?

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


Re: Ugh! Python 3.1.x and MySQL

2010-09-10 Thread Rami Chowdhury
On Fri, Sep 10, 2010 at 22:27, fuglyducky  wrote:

> Most of the python books coming out now are Py3K. I just started
> programming and have a need to access a MySQL database. I would like
> to use Python to do this. Unfortunately, I cannot find anyone that has
> created anything that allows my to do this.
>
> I've tried installing an ODBC driver and using sqlalchemy, oursql, and
> a few other things with no luck.
>
> So...just wondering if anyone is aware of any libraries/modules that I
> can use to connect to a MySQL DB using Python 3.1.x?
>

Have you tried OurSQL (http://packages.python.org/oursql/)?


>
> Ideally, I'd like to be able to this from both x86 and x64 systems (if
> that makes any difference).
>
> Thanks for any input you may have!!!
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


bool constructor is inconsistent?

2010-09-10 Thread Neal Becker
IN [3]: bool('False')
Out[3]: True

In [4]: int('32')
Out[4]: 32

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


Re: bool constructor is inconsistent?

2010-09-10 Thread Stefan Behnel

Neal Becker, 10.09.2010 20:23:

IN [3]: bool('False')
Out[3]: True


Not inconsistent at all:

  >>> bool('false')
  True
  >>> bool('true')
  True
  >>> bool('')
  False
  >>> bool(32)
  True
  >>> bool(0)
  False

It simply follows Python's boolean coercion rules.

If you consider it inconsisten w.r.t. int('32'), then what about

   >>> list('[]')
   ['[', ']']

Stefan

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


Re: bool constructor is inconsistent?

2010-09-10 Thread Emile van Sebille

On 9/10/2010 11:23 AM Neal Becker said...

IN [3]: bool('False')
Out[3]: True

In [4]: int('32')
Out[4]: 32





>>> eval('False')
False
>>> eval('32')
32
>>>


Otherwise, 'False' is just a string?

Emile

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


Re: bool constructor is inconsistent?

2010-09-10 Thread Stefan Schwarzer
Hi Neal,

On 2010-09-10 20:23, Neal Becker wrote:
> IN [3]: bool('False')
> Out[3]: True

If you consider strings, only an empty string has a false
value. So the string 'False' which is non-empty, results in
a true boolean value.

For example, you can use

if my_string:
...

to execute some code if the string is not empty.

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


Re: how to kill a subprocess

2010-09-10 Thread Christian Heimes
Am 10.09.2010 19:51, schrieb cerr:
> Thanks for your suggestion, changed my code now to:
> 
>   process=subprocess.Popen(commandlist)
>   ...
>   ...
>   process.kill()
>   os.waitpid(process.pid, 0)
> but it's not killing the process running. it still runs in the
> background and i don't see any errors, we're running python 2.6.4
> any more clues?

It's not an issue with your Python process but with its parent process.
The parent process has to call the OS's waitpid() function with the PID
of the Python process in order to reap it. Please show us how you are
starting and controlling the Python process in your PHP code.

Christian

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


Re: how to kill a subprocess

2010-09-10 Thread cerr
On Sep 10, 11:45 am, Christian Heimes  wrote:
> Am 10.09.2010 19:51, schrieb cerr:
>
> > Thanks for your suggestion, changed my code now to:
>
> >   process=subprocess.Popen(commandlist)
> >   ...
> >   ...
> >   process.kill()
> >   os.waitpid(process.pid, 0)
> > but it's not killing the process running. it still runs in the
> > background and i don't see any errors, we're running python 2.6.4
> > any more clues?
>
> It's not an issue with your Python process but with its parent process.
> The parent process has to call the OS's waitpid() function with the PID
> of the Python process in order to reap it. Please show us how you are
> starting and controlling the Python process in your PHP code.

But I wanna kill the child process I start from my python code.
It's like
PHP -> Python -> Perl

and when the connection PHP -> Python seems to work well!


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


3D cube navigation

2010-09-10 Thread sahilsk
hi, i need to make a 3d cube as a navigation menu.. each face having
separate  button .. or effect.
any idea,  how can i make one such 3D figures with functionality of
mouse events?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to kill a subprocess

2010-09-10 Thread Christian Heimes
Am 10.09.2010 20:56, schrieb cerr:
> But I wanna kill the child process I start from my python code.
> It's like
> PHP -> Python -> Perl
> 
> and when the connection PHP -> Python seems to work well!

You have said that the Python process becomes a zombie process. This
clearly tells me that the issue is in your PHP script. See
http://en.wikipedia.org/wiki/Fork-exec

Christian

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


Re: bool constructor is inconsistent?

2010-09-10 Thread David Robinow
On Fri, Sep 10, 2010 at 2:35 PM, Stefan Schwarzer
 wrote:
> Hi Neal,
>
> On 2010-09-10 20:23, Neal Becker wrote:
>> IN [3]: bool('False')
>> Out[3]: True
>
> If you consider strings, only an empty string has a false
> value. So the string 'False' which is non-empty, results in
> a true boolean value.
> ...
 I've always felt that if a humorous post needs a smiley, that it's not funny.
However, there is the risk of being misunderstood.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ugh! Python 3.1.x and MySQL

2010-09-10 Thread nn
On Sep 10, 12:27 pm, fuglyducky  wrote:
> Most of the python books coming out now are Py3K. I just started
> programming and have a need to access a MySQL database. I would like
> to use Python to do this. Unfortunately, I cannot find anyone that has
> created anything that allows my to do this.
>
> I've tried installing an ODBC driver and using sqlalchemy, oursql, and
> a few other things with no luck.
>
> So...just wondering if anyone is aware of any libraries/modules that I
> can use to connect to a MySQL DB using Python 3.1.x?
>
> Ideally, I'd like to be able to this from both x86 and x64 systems (if
> that makes any difference).
>
> Thanks for any input you may have!!!

Google found this:

http://sourceforge.net/projects/mysql-python/forums/forum/70460/topic/3831691
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to kill a subprocess

2010-09-10 Thread cerr
On Sep 10, 12:18 pm, Christian Heimes  wrote:
> Am 10.09.2010 20:56, schrieb cerr:
>
> > But I wanna kill the child process I start from my python code.
> > It's like
> > PHP -> Python -> Perl
>
> > and when the connection PHP -> Python seems to work well!
>
> You have said that the Python process becomes a zombie process. This
> clearly tells me that the issue is in your PHP script. 
> Seehttp://en.wikipedia.org/wiki/Fork-exec

No, the Perl becomes the zombie.

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


Re: how to kill a subprocess

2010-09-10 Thread Christian Heimes
Am 10.09.2010 22:14, schrieb cerr:
> No, the Perl becomes the zombie.

How are you killing the Python process? Are you sending SIGINT, SIGTERM
or SIGKILL? SIGKILL can prevent Python from running its cleanup code.

Christian


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


Re: How Python works: What do you know about support for negative indices?

2010-09-10 Thread Terry Reedy

On 9/9/2010 9:37 PM, Raymond Hettinger wrote:


The docs guarantee that Python's builtin sequences implement support
for negative indices (


http://docs.python.org/dev/reference/expressions.html#subscriptions

The relevant paragraphs are
"
For built-in objects, there are two types of objects that support 
subscription:


If the primary is a mapping, the expression list must evaluate to an 
object whose value is one of the keys of the mapping, and the 
subscription selects the value in the mapping that corresponds to that 
key. (The expression list is a tuple except if it has exactly one item.)


If the primary is a sequence, the expression (list) must evaluate to an 
integer. If this value is negative, the length of the sequence is added 
to it (so that, e.g., x[-1] selects the last item of x.) The resulting 
value must be a nonnegative integer less than the number of items in the 
sequence, and the subscription selects the item whose index is that 
value (counting from zero).

"

Reading the third paragraph out of context, one can miss the restriction 
to built-in objects. I had assumed that the conversion using len(), when 
available, happened prior to the __getitem__ call. I believe I need to 
add the restriction in my discussion of negative indexing in my book. I 
would like the above rewritten something like the following:

"
Two types of built-in objects support subscription as primaries: 
mappings and sequences.


For built-in mappings, the

For built-in sequences, the ...
"

The second paragraph was written before defaultdict and does not apply 
to them. I presume that it is an extension rather than built-in class 
for the purpose of the Reference.



Hope you all found this to be informative,


Definitely. I save a copy for future reference.

--
Terry Jan Reedy

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


Re: How Python works: What do you know about support for negative indices?

2010-09-10 Thread Aahz
In article ,
Daniel Fetchinson   wrote:
>Attribution missing:
>>
>> I encourage anyone whose messages are munged like that to seek
>> correction from their mail service provider, and switch to a different
>> one until it's fixed.
>
>I encourage anyone who has problems with reading various emails,
>newsgroup postings, forums and what not, to start using modern tools
>that work with the vast majority of other tools.

Why?  Raymond's post worked fine for me with trn3.6
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Samurai Principle

2010-09-10 Thread Lawrence D'Oliveiro
In message , Ian Kelly 
wrote:

> And returning None on failure is dangerous, because if the programmer
> does not take care to handle that case, the program may attempt to
> regard it as actual data.

But None *is* actual data.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Arguments from the command line

2010-09-10 Thread Lawrence D'Oliveiro
In message <86wrqtsxo2@aiuole.stru.polimi.it>, Giacomo Boffi wrote:

> Lawrence D'Oliveiro  writes:
> 
>> In message <8662yfklzu@aiuole.stru.polimi.it>, Giacomo Boffi wrote:
>>
>>> no BLOCKDATA?
>>
>> I think you mean COMMON.
> 
> i meant BLOCKDATA

BLOCKDATA is an initializer. The actual storage is allocated by COMMON.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SendKeys and Python 2.7

2010-09-10 Thread Lawrence D'Oliveiro
In message , Jakson A. 
Aquino wrote:

> On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro
>  wrote:
>
>> In message , Jakson
>> A. Aquino wrote:
>>
>>> I would like to send code from Vim [1] to R [2] on Microsoft Windows.
>>
>> Why such a roundabout way? Why not just run R in a subprocess and feed it
>> a script to run?
> 
> Emacs with ESS runs R in a subprocess (at least I think it does). Vim
> can't do that.

Why not?

> The plugin doesn't simply send code to R. It has many other features
> that make it easier to edit R scripts.

But those are editing functions, nothing to do with R.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] with statement syntax forces ugly line breaks?

2010-09-10 Thread Lawrence D'Oliveiro
In message , MRAB 
wrote:

> On 08/09/2010 19:07, Georg Brandl wrote:
>
>> Thus spake the Lord: Thou shalt indent with four spaces. No more, no
>> less. Four shall be the number of spaces thou shalt indent, and the
>> number of thy indenting shall be four. Eight shalt thou not indent,
>> nor either indent thou two, excepting that thou then proceed to four.
>> Tabs are right out.
>>
> FYI, that should be "thine indenting".
> 
> "My/thy" before a consonant, "mine/thine" before a vowel. Compare with
> "a/an", which we still do.

The funny thing is, that’s technically “Modern English”...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SendKeys and Python 2.7

2010-09-10 Thread Jakson A. Aquino
On Fri, Sep 10, 2010 at 7:19 PM, Lawrence D'Oliveiro
 wrote:
> In message , Jakson A.
> Aquino wrote:
>> On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro
>>  wrote:
>>> In message , Jakson
>>> A. Aquino wrote:
 I would like to send code from Vim [1] to R [2] on Microsoft Windows.
>>>
>>> Why such a roundabout way? Why not just run R in a subprocess and feed it
>>> a script to run?
>>
>> Emacs with ESS runs R in a subprocess (at least I think it does). Vim
>> can't do that.
>
> Why not?

I don't know how to embed R into Vim, but I would be grateful if you
could explain how to do it since this could be an opportunity to
improve my plugin.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Q] Function Point Analysis (FPA) - Equivalent lines of code of Python

2010-09-10 Thread Lawrence D'Oliveiro
In message <7x4odz5mr3@ruckus.brouhaha.com>, Paul Rubin wrote:

> Nicholas  writes:
>>
>>   http://www.qsm.com/?q=resources/function-point-languages-
table/index.html
> 
> That table looks pretty bogus ...

Dead giveaways are the disparity between the Ada, C++ and PL/I figures, and 
the fact that FORTRAN scores lower than C. Plus the inclusion of HTML and 
Dotnet on a par with the others. And what are “Web Scripts", if not 
JavaScript?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Samurai Principle

2010-09-10 Thread Robert Kern

On 9/10/10 5:17 PM, Lawrence D'Oliveiro wrote:

In message, Ian Kelly
wrote:


And returning None on failure is dangerous, because if the programmer
does not take care to handle that case, the program may attempt to
regard it as actual data.


But None *is* actual data.


And that is exactly the reason why the Samurai Principle says to not return None 
when the function fails to do what it intended to do.


--
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: 3D cube navigation

2010-09-10 Thread Krister Svanlund
On Fri, Sep 10, 2010 at 9:10 PM, sahilsk  wrote:
> hi, i need to make a 3d cube as a navigation menu.. each face having
> separate  button .. or effect.
> any idea,  how can i make one such 3D figures with functionality of
> mouse events?

In what environment, what toolkit, for what purpose?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ugh! Python 3.1.x and MySQL

2010-09-10 Thread John Nagle

On 9/10/2010 12:57 PM, nn wrote:

On Sep 10, 12:27 pm, fuglyducky  wrote:

Most of the python books coming out now are Py3K. I just started
programming and have a need to access a MySQL database. I would like
to use Python to do this. Unfortunately, I cannot find anyone that has
created anything that allows my to do this.

I've tried installing an ODBC driver and using sqlalchemy, oursql, and
a few other things with no luck.

So...just wondering if anyone is aware of any libraries/modules that I
can use to connect to a MySQL DB using Python 3.1.x?

Ideally, I'd like to be able to this from both x86 and x64 systems (if
that makes any difference).

Thanks for any input you may have!!!


Google found this:

http://sourceforge.net/projects/mysql-python/forums/forum/70460/topic/3831691


  That's progress, but it's a fork of MySQLdb.

  Can it be checked into the MySQLdb project on SourceForge?

John Nagle

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


Re: 3D cube navigation

2010-09-10 Thread Phlip
On Sep 10, 12:10 pm, sahilsk  wrote:
> hi, i need to make a 3d cube as a navigation menu.. each face having
> separate  button .. or effect.
> any idea,  how can i make one such 3D figures with functionality of
> mouse events?

omg

If you have to ask, you probably are not ready for the answer!

Is this a personal project, or are you satisfying a customer?

If the latter, is it a desktop project, or a web project?

If a web project, can you use a PNG of a rendered cube? Render it with
PovRay (which is honestly a ton of fun to author in), then use 
tags to define clicks on various faces.

>From here, the question arises WHY your client wants this. Must the
cube rotate? Is it designed to be user hostile? Must the user rotate
the cube to find the correct menu item?

If you want to spend a couple weeks coding a nice learning project,
you could do a rotating cube in HTML5 using the  control.
Someone probably has an example out there, but efficient trigonometric
matrix transformations in JavaScript are not for the faint of heart.

If this is for the desktop, get a Python library that wraps something
that wraps OpenGL or DirectX. Or just google for "python 3d cube".

Have fun!

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


Re: Ugh! Python 3.1.x and MySQL

2010-09-10 Thread Martin Gregorie
On Fri, 10 Sep 2010 09:27:28 -0700, fuglyducky wrote:

> Most of the python books coming out now are Py3K. I just started
> programming and have a need to access a MySQL database. I would like to
> use Python to do this. Unfortunately, I cannot find anyone that has
> created anything that allows my to do this.
> 
> I've tried installing an ODBC driver and using sqlalchemy, oursql, and a
> few other things with no luck.
> 
> So...just wondering if anyone is aware of any libraries/modules that I
> can use to connect to a MySQL DB using Python 3.1.x?
> 
> Ideally, I'd like to be able to this from both x86 and x64 systems (if
> that makes any difference).
>
You don't say what OS you're using, but if you're on a *NIX, take a look 
at pyodbc: http://code.google.com/p/pyodbc/

This Python module is a wrapper for unixODBC and consequently works with 
standard MySQL ODBC drivers.
 
iODBC: http://www.iodbc.org/ is similar

If you want something that's Windows compatible I can't help: I don't use 
either Windows or MySQL.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org   |
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Samurai Principle

2010-09-10 Thread Steven D'Aprano
On Sat, 11 Sep 2010 10:17:21 +1200, Lawrence D'Oliveiro wrote:

> In message , Ian
> Kelly wrote:
> 
>> And returning None on failure is dangerous, because if the programmer
>> does not take care to handle that case, the program may attempt to
>> regard it as actual data.
> 
> But None *is* actual data.

Of course it is. Which makes it hard to distinguish None used as data 
from None used as a signal for an exceptional case.

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


Re: 3D cube navigation

2010-09-10 Thread Steven D'Aprano
On Sat, 11 Sep 2010 01:09:00 +0200, Krister Svanlund wrote:

> On Fri, Sep 10, 2010 at 9:10 PM, sahilsk  wrote:
>> hi, i need to make a 3d cube as a navigation menu.. each face having
>> separate  button .. or effect.
>> any idea,  how can i make one such 3D figures with functionality of
>> mouse events?
> 
> In what environment, what toolkit, for what purpose?

What do you mean, "what environment"? Surely there's only one? The 
Original Poster obviously wants a 3D navigation cube for ksh under 
FreeBSD.

*wink*


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


Re: bool constructor is inconsistent?

2010-09-10 Thread Steven D'Aprano
On Fri, 10 Sep 2010 14:23:34 -0400, Neal Becker wrote:

> IN [3]: bool('False')
> Out[3]: True
> 
> In [4]: int('32')
> Out[4]: 32

Where is the inconsistency? bool('False') returns the same result as for 
any other non-empty string:

>>> bool("not true")
True
>>> bool("no")
True
>>> bool("incorrect")
True
>>> bool("wrong")
True
>>> bool("Faux")
True
>>> bool("Falsch")
True
>>> bool("Falso")
True
>>> bool("偽")
True
>>> bool("Ложно")
True



Treating the string "False" as identical to the named global False would 
be inconsistent. 


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


Re: SendKeys and Python 2.7

2010-09-10 Thread Jakson A. Aquino
On Thu, Sep 9, 2010 at 8:24 PM, Jakson A. Aquino  wrote:
> On Thu, Sep 9, 2010 at 5:40 PM, Michel Claveau - MVP
>  wrote:
>> Hi!
>>
>> Example for send ^V  (with PyWin32):
>>
>>  import time,win32api,win32con
>>  win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0)
>>  win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
>>  time.sleep(0.05)
>>  win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 
>> win32con.KEYEVENTF_KEYUP, 0)
>>  win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0)
>
> Thank you very much! Your code solved my problem. I added some lines
> to set the focus into R before the ^V and then back to Vim:

Unfortunately, I was wrong. Your code do send the ^v as expected, but
I have problem with the selection of the Windows which will receive
the ^v. The code above was OK in a Windows XP running inside
VirtualBox, but when tested in a real machine, it proved to be highly
inconsistent. Sometimes the ^v gets pasted into R, but more frequently
it is pasted into Vim itself or nowhere. Below is the complete code
that I'm using. It's a vim script. The python code is delimited by
"python << EOL" and "EOL":

function! SendToRPy(aString)
python << EOL
import time
import win32api
import win32con
import win32com.client
import win32clipboard
import vim

aString = vim.eval("a:aString")
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(aString)
win32clipboard.CloseClipboard()
shell = win32com.client.Dispatch("WScript.Shell")
ok = shell.AppActivate("R Console")
if ok:
win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0)
win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(0.05)
win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0)
shell.AppActivate("Vim")
else:
vim.command("call RWarningMsg('Is R running?')")
time.sleep(1)
EOL
endfunction

When R isn't running, the script correctly shows the warning message
"Is R running?". Does anyone know what should I do to correctly use
the AppActivate function or is there a better approach to this
problem?

Thanks!

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


Re: 3D cube navigation

2010-09-10 Thread Tim Chase

On 09/10/10 19:20, Steven D'Aprano wrote:

On Sat, 11 Sep 2010 01:09:00 +0200, Krister Svanlund wrote:

On Fri, Sep 10, 2010 at 9:10 PM, sahilsk  wrote:

hi, i need to make a 3d cube as a navigation menu.. each face having
separate  button .. or effect.


In what environment, what toolkit, for what purpose?


What do you mean, "what environment"? Surely there's only one? The
Original Poster obviously wants a 3D navigation cube for ksh under
FreeBSD.


Drat...all my work on a 3d navigation-cube working under ProDos 
on the Apple ][e for naught...what am I gonna do with all these 
360k 5.25" floppies now?!


-tkc



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


Re: How Python works: What do you know about support for negative indices?

2010-09-10 Thread Ben Finney
Ben Finney  writes:

> Raymond Hettinger  writes:
>
> > It doesn't seem to be common knowledge when and how a[x] gets
> > translated to a[x+len(x)]. So, here's a short info post on how
> > Python supports negative indices for sequences.
>
> Thanks for this. Could you post your messages using a channel that
> doesn't arbitrarily split your paragraphs into long-short-long-short
> lines? It makes paragraphs burdensome to read, and I skipped most of
> the message because of that.

For those who think the problem may be with the recipient's software, I
see the same annoying line-wrapping problems in the archived message
http://mail.python.org/pipermail/python-list/2010-September/1255167.html>.

There's been enough sidetracking of Raymond's thread, though, so that
factual contribution will hopefully be my last in this thread on this
issue.

-- 
 \“Choose mnemonic identifiers. If you can't remember what |
  `\mnemonic means, you've got a problem.” —Larry Wall |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SendKeys and Python 2.7

2010-09-10 Thread MRAB

On 11/09/2010 01:45, Jakson A. Aquino wrote:

On Thu, Sep 9, 2010 at 8:24 PM, Jakson A. Aquino  wrote:

On Thu, Sep 9, 2010 at 5:40 PM, Michel Claveau - MVP
  wrote:

Hi!

Example for send ^V  (with PyWin32):

  import time,win32api,win32con
  win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0)
  win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
  time.sleep(0.05)
  win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 
win32con.KEYEVENTF_KEYUP, 0)
  win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0)


Thank you very much! Your code solved my problem. I added some lines
to set the focus into R before the ^V and then back to Vim:


Unfortunately, I was wrong. Your code do send the ^v as expected, but
I have problem with the selection of the Windows which will receive
the ^v. The code above was OK in a Windows XP running inside
VirtualBox, but when tested in a real machine, it proved to be highly
inconsistent. Sometimes the ^v gets pasted into R, but more frequently
it is pasted into Vim itself or nowhere. Below is the complete code
that I'm using. It's a vim script. The python code is delimited by
"python<<  EOL" and "EOL":

function! SendToRPy(aString)
python<<  EOL
import time
import win32api
import win32con
import win32com.client
import win32clipboard
import vim

aString = vim.eval("a:aString")
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(aString)
win32clipboard.CloseClipboard()
shell = win32com.client.Dispatch("WScript.Shell")
ok = shell.AppActivate("R Console")
if ok:
 win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0)
 win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
 time.sleep(0.05)
 win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
 win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0)
 shell.AppActivate("Vim")
else:
 vim.command("call RWarningMsg('Is R running?')")
 time.sleep(1)
EOL
endfunction

When R isn't running, the script correctly shows the warning message
"Is R running?". Does anyone know what should I do to correctly use
the AppActivate function or is there a better approach to this
problem?


I'd add some more small sleeps to give Windows/R time to act, IYSWIM. I
learned that from experience. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Refactoring similar subclasses

2010-09-10 Thread Steven D'Aprano
I have some code that currently takes four different classes, A, B, C and 
D, and subclasses each of them in the same way:

class MyA(A):
def method(self, x):
result = super(MyA, self).method(x)
if result == "spam":
return "spam spam spam"
return result
# many more methods overloaded


class MyB(B):
def method(self, x):
result = super(MyB, self).method(x)
if result == "spam":
return "spam spam spam"
return result
# many more methods overloaded


and so on, for MyC and MyD. There's a lot of duplicated code in there. 
What techniques do you suggest for reducing the code duplication? I 
thought about some variation of:

names = "MyA MyB MyC MyD".split()
bases = [A, B, C, D]
d = dict-of-overloaded-methods
for name, base in zip(names, bases):
globals()[name] = type(name, [base], d)


but I'm not sure that this is a good approach, or how to inject the right 
arguments to super in the dict.

Any suggestions or guidelines?


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


Hide DOS console for .pyc file

2010-09-10 Thread Muddy Coder
Hi Folks,

For a quick testing purpose, I deliver .pyc files to my customer. I
don't want the black DOS console appearing behind my GUI, but I have
no idea how to do it. Somebody can help? Thanks!


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


default value for __init__ doesn't work

2010-09-10 Thread 人言落日是天涯,望极天涯不见家
Please look at below code snippet:
class test():
def __init__(self, a, dic={}):
self.a = a
self.dic = dic
print('__init__ params:',a, dic)

def get(self):
self.dic[1] = 2
self.dic[4] = 5

def foo():
print('in foo function')
bar = test(1)
bar.get()

if __name__ == '__main__':
foo()
foo()
---
Result:
in foo function
__init__ params: 1 {}
in foo function
__init__ params: 1 {1: 2, 4: 5}

But my expect result is :
in foo function
__init__ params: 1 {}
in foo function
__init__ params: 1 {}

it seems that the default value for dic doesn't work on the second
call for the class test.
It's wired. Who can give a explaination for this scenario?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Convert IO Stream to XML Document

2010-09-10 Thread Stefan Behnel

jakecjacobson, 10.09.2010 18:20:

response = urllib2.urlopen(request)
pageguts = response.read()
xmldoc = minidom.parse(pageguts)


Check the minidom docs, there's a parseString() function that does what it 
says.


Also, don't forget to take a look at xml.etree.ElementTree. Depending on 
what you want to do with the XML result, it'll likely be easier to use and 
faster than minidom. The function there is called fromstring(), just in case ;)


Stefan

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


Re: default value for __init__ doesn't work

2010-09-10 Thread Benjamin Kaplan
On Sat, Sep 11, 2010 at 12:38 AM, 人言落日是天涯,望极天涯不见家  wrote:
> Please look at below code snippet:
> class test():
>    def __init__(self, a, dic={}):
>        self.a = a
>        self.dic = dic
>        print('__init__ params:',a, dic)
>


This is a pretty popular mistake to make. Default arguments aren't
evaluated when you call the method. They're created when the method is
created (meaning when you first run the file and the class itself is
defined), and that's it. Because you do self.dic = dic, this means
that every instance of the object will receive the same dict object.
Change it for one object, and the change will show up in all of them.
The solution to this is to use a sentinel value, like None

def __init__(self, a, dic=None) :
if dic is None :
self.dic = {}
else :
self.dic = dic

If None is a valid value for the parameter, make a sentinel object and use that

sentinel = object()
def __init__(self, a, dic=sentinel) :
if dic is sentinel : #you want to use is here, not ==
  ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: default value for __init__ doesn't work

2010-09-10 Thread 人言落日是天涯,望极天涯不见家
On Sep 11, 1:14 pm, Benjamin Kaplan  wrote:
> On Sat, Sep 11, 2010 at 12:38 AM, 人言落日是天涯,望极天涯不见家  
> wrote:
> > Please look at below code snippet:
> > class test():
> >    def __init__(self, a, dic={}):
> >        self.a = a
> >        self.dic = dic
> >        print('__init__ params:',a, dic)
>
> This is a pretty popular mistake to make. Default arguments aren't
> evaluated when you call the method. They're created when the method is
> created (meaning when you first run the file and the class itself is
> defined), and that's it. Because you do self.dic = dic, this means
> that every instance of the object will receive the same dict object.
> Change it for one object, and the change will show up in all of them.
> The solution to this is to use a sentinel value, like None
>
> def __init__(self, a, dic=None) :
>     if dic is None :
>         self.dic = {}
>     else :
>         self.dic = dic
>
> If None is a valid value for the parameter, make a sentinel object and use 
> that
>
> sentinel = object()
> def __init__(self, a, dic=sentinel) :
>     if dic is sentinel : #you want to use is here, not ==
>       ...

Got it. Thanks for point out my mistake. You are very nice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: default value for __init__ doesn't work

2010-09-10 Thread 人言落日是天涯,望极天涯不见家
On Sep 11, 1:55 pm, 人言落日是天涯,望极天涯不见家  wrote:
> On Sep 11, 1:14 pm, Benjamin Kaplan  wrote:
>
>
>
> > On Sat, Sep 11, 2010 at 12:38 AM, 人言落日是天涯,望极天涯不见家  
> > wrote:
> > > Please look at below code snippet:
> > > class test():
> > >    def __init__(self, a, dic={}):
> > >        self.a = a
> > >        self.dic = dic
> > >        print('__init__ params:',a, dic)
>
> > This is a pretty popular mistake to make. Default arguments aren't
> > evaluated when you call the method. They're created when the method is
> > created (meaning when you first run the file and the class itself is
> > defined), and that's it. Because you do self.dic = dic, this means
> > that every instance of the object will receive the same dict object.
> > Change it for one object, and the change will show up in all of them.
> > The solution to this is to use a sentinel value, like None
>
> > def __init__(self, a, dic=None) :
> >     if dic is None :
> >         self.dic = {}
> >     else :
> >         self.dic = dic
>
> > If None is a valid value for the parameter, make a sentinel object and use 
> > that
>
> > sentinel = object()
> > def __init__(self, a, dic=sentinel) :
> >     if dic is sentinel : #you want to use is here, not ==
> >       ...
>
> Got it. Thanks for point out my mistake. You are very nice.

I remember the same issue was occurred in my C++ program. There I have
a function with a parameter referenced a default object . May be C++
also constructs the the default arguments before the function is
called.
Thank you again to help me so much!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hide DOS console for .pyc file

2010-09-10 Thread Jason Earl
On Fri, Sep 10 2010, Muddy Coder wrote:

> Hi Folks,
>
> For a quick testing purpose, I deliver .pyc files to my customer. I
> don't want the black DOS console appearing behind my GUI, but I have
> no idea how to do it. Somebody can help? Thanks!
>
>
> Cosmo

I don't really use Windows any more, so I might be off the mark, but I
think that you need to look into using pythonw.exe instead of
python.exe.  Solving your problem might be as easy as changing the name
of your file from foo.py to foo.pyw.

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