Re: Parsing numeric ranges

2011-02-25 Thread Simon Brunning
On 25 February 2011 09:27, Seldon sel...@katamail.it wrote:
 Hi all,
 I have to convert integer ranges expressed in a popular compact notation
 (e.g. 2, 5-7, 20-22, 41) to a the actual set of numbers (i.e.
 2,5,7,20,21,22,41).

 Is there any library for doing such kind of things or I have to write it
 from scratch ?

I dredged this out:



def _revision_list_with_ranges_to_list_without_ranges(revision_list):
'''Convert a revision list with ranges (e.g. '1,3,5-7') to a
simple list without ranges (1,3,5,6,7)'''
for revision in revision_list:
if '-' in revision:
from_revision, _, to_revision = revision.partition('-')
for revision_in_range in range(int(from_revision),
int(to_revision)+1):
yield revision_in_range
else:
yield int(revision)

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


Re: multiple values for keyword argument

2011-01-31 Thread Simon Brunning
On 29 January 2011 18:39,  pa...@cruzio.com wrote:
 I, myself, use the spanish word 'yo' instead (less keystrokes, I hate
 'self', and it amuses me); if I'm working with my numerical experiments
 I'll use 'n' or 'x'... although, when posting sample code to c.l.py I do
 try to use 'self' to avoid possible confusion.  :)

 I am glad you said this.  I have been avoiding understanding this 'self',
 just accepting it :}  For the time being, since my programs I am creating
 are for my own use, I think I will make my own names up, that are
 descriptive to me as the programmer, it's all going to be interpreted
 anyway.  And the other email equating to C's argv, etc. - now I get it.

It's perfectly legal to use a name other than self. It's alo perfectly
legal never to wash - and you won't make any friends that way either.

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


Re: list 2 dict?

2011-01-02 Thread Simon Brunning
On 2 January 2011 21:04, Octavian Rasnita orasn...@gmail.com wrote:
 No. As Ian said grouper() is a receipe in the itertools documentation.

 http://docs.python.org/library/itertools.html#recipes

 I know that, that is why I used:

 from itertools import *

 Isn't enough?

Did you follow the link? grouper() is a recipe, not part of the
itertools module.

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


Re: remote control firefox with python

2010-11-29 Thread Simon Brunning
On 28 November 2010 15:22, News123 news1...@free.fr wrote:

 I wondered whether there is a simpe way to
 'remote' control fire fox with python.

Selenium might be worth a look, too:
http://code.google.com/p/selenium/wiki/PythonBindings

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


Re: Glob in python which supports the ** wildcard

2010-11-23 Thread Simon Brunning
On 22 November 2010 21:43, Martin Lundberg martin.lundb...@gmail.com wrote:
 Hi,

 I want to be able to let the user enter paths like this:

 apps/name/**/*.js

 and then find all the matching files in apps/name and all its
 subdirectories. However I found out that Python's glob function
 doesn't support the recursive ** wildcard. Is there any 3rd party glob
 function which do support **?

This does roughly what you want:

http://code.activestate.com/recipes/499305-locating-files-throughout-a-directory-tree/

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


Re: Glob in python which supports the ** wildcard

2010-11-23 Thread Simon Brunning
On 23 November 2010 09:26, Martin Lundberg martin.lundb...@gmail.com wrote:
 It does not seem to support the ** wildcard? It will recursively seek
 for files matching a pattern like *.js but it won't support
 /var/name/**/*.js as root, will it?

I did say roughly. ;-) You'd need to do:

for filename in locate(*.js, /var/name/):
print filename

Adding support for ** is left as an exercise for the reader.

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


Re: A question about yield

2010-11-08 Thread Simon Brunning
On 7 November 2010 18:14, Chris Rebert c...@rebertia.com wrote:
 On Sun, Nov 7, 2010 at 9:56 AM, chad cdal...@gmail.com wrote:
 But what happens if the input file is say 250MB? Will all 250MB be
 loaded into memory at once?

 No. As I said, the file will be read from 1 line at a time, on an
 as-needed basis; which is to say, line-by-line.

IIRC, it's somewhere in between. Python will read the file in blocks.
If only *looks* like it's reading the file line by line.

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


Re: ctypes

2010-09-23 Thread Simon Brunning
On 22 September 2010 21:13, jay thompson jayryan.thomp...@gmail.com wrote:
 Hello,

 I posted in regard to this in the past but it didn't go very far, no ones
 fault, but I'm again atempting to make this work and could use some help.

 I would like to use libraw.dll (http://www.libraw.org/  version 0.10) from
 python and can access all the functions fine and produce images but there is
 a structure that holds all the process settings that I cannot access with
 ctypes. I'm sure it's because I'm going about it the wrong way. I was
 wondering if there was anyone in this list with experience with this sort of
 thing that could point me in the right direction.

A good start would be to tell us what you've tried, and what goes
wrong when you try it.

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


Re: How to make a web services in python ???

2010-09-20 Thread Simon Brunning
On 20 September 2010 16:09, Ariel isaacr...@gmail.com wrote:
 Soap web services I think.

I think the cool kids would be using https://fedorahosted.org/suds/,
but for the fact that the cool kids all build REST
(http://oreilly.com/catalog/9780596805838) rather than SOAP these
days.

-- 
Cheers,
Simon B.
-- 
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 stephen.bou...@gmail.com 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'

http://effbot.org/pyfaq/how-can-my-code-discover-the-name-of-an-object.htm

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


Re: python interview quuestions

2010-08-13 Thread Simon Brunning
On 11 August 2010 13:34:09 UTC+1, Steven D'Aprano
st...@remove-this-cybersource.com.au wrote:
 Getting interviewees to do a take-home problem just means you hire the
 guy who is friends with a good programmer, rather than the good
 programmer.

We give a take-home problem. If we like the code we see, we invite the
candidate to come in and pair with one of our devs in adding a simple
feature or two to their own code. It's time consuming, but not so time
consuming as hiring a weak dev.

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


Re: Mechanize - save to XML or CSV

2010-08-02 Thread Simon Brunning
On 2 August 2010 14:13, flebber flebber.c...@gmail.com wrote:
 HI guys and gals this is probably a simple question but I can't find
 the answer directly in the docs for python mechanize.

 http://pypi.python.org/pypi/mechanize/

 Is it possible to retrieve and save a web page data as xml or a csv
 file?

Sure, but mechanize only does the first half of the job. You retrieve
the data using mechanize, then use another module for the save-as bit.
ElementTree for XML and csv for, um, for csv are both in the standard
library.

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


Re: Load/Performance Testing of a Web Server

2010-07-09 Thread Simon Brunning
On 9 July 2010 14:17, kak...@gmail.com kak...@gmail.com wrote:
 Hi to all, i want to stress test   a tomcat web server, so that i
 could find out its limits. e.g how many users can be connected and
 request a resource concurrently.
 I used JMeter which is an excellent tool, but i would like to use a
 more pythonic approach.

The Grinder?

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


Re: optparse TypeError

2010-06-28 Thread Simon Brunning
On 28 June 2010 14:30, dirknbr dirk...@gmail.com wrote:
 I get an int object is not callable TypeError when I execute this. But
 I don't understand why.
 (snip)
    lines=options.lines

Here you are assigning the -l option to the name 'lines'.

    lines(args[0],topbottom=tb,maxi=lines)

Here you are attempting to call a function with the name 'lines'. But
'lines' has been assigned an integer above.

I'm assuming that elsewhere you've defined a function called 'lines'.
You'll need to call either the function or the option by another name.

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


Re: Python on Android Mobile?

2010-06-13 Thread Simon Brunning
On 13 June 2010 21:39, Anthony Papillion papill...@gmail.com wrote:
 I know Python is growing in popularity and some of Palms devices
 already let you run Python apps in a VM environment.  I'm wondering if
 anyone knows (or can make an educated guess) if there are any plans
 for Python to come to the Android environment?  I'm not talking
 backend stuff here but full front and center like full GTK or WX
 development for the devices?

Sadly, I gather that Google has no plans for this. But hey, it's open
source, right?

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


Re: a +b ?

2010-06-11 Thread Simon Brunning
2010/6/11 yanhua gasf...@163.com:
 hi,all!
 it's a simple question:
 input two integers A and B in a line,output A+B?

print sum(int(i) for i in raw_input(Please enter some integers: ).split())

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


Re: grep command

2010-06-10 Thread Simon Brunning
On 10 June 2010 07:38, madhuri vio madhuri@gmail.com wrote:

 i was wondering bout the usage and syntax of
 grep command..can u tall me its syntax so that
 i can use it and proceed...pls

That's really not on topic for this list.

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


Re: regarding the dimensions in gui

2010-06-10 Thread Simon Brunning
On 10 June 2010 08:19, Shashwat Anand anand.shash...@gmail.com wrote:
 And please stop using 'sir' for heaven's sake.

Not least because list list isn't male only.

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


Re: help me

2010-06-09 Thread Simon Brunning
On 9 June 2010 11:44, madhuri vio madhuri@gmail.com wrote:
 thankyou so much ..i made it finally...
 how do i make buttons and i want a lil text to label the buttons also

You might want to run through
http://www.pythonware.com/library/tkinter/introduction/.

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


Re: help me

2010-06-09 Thread Simon Brunning
On 9 June 2010 11:47, madhuri vio madhuri@gmail.com wrote:
 yea i was able to import by capitalizing t...thank u so much
 but wats the reason behind they just changed it for
 the significance of each version ..is it that way?

PEP 8 (http://www.python.org/dev/peps/pep-0008/) suggests that
module names be lower case. Python 3 was an opportunity to make
non-backwardly compatible fixes, including to the standard library.

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


Re: Python Forum

2010-06-02 Thread Simon Brunning
On 2 June 2010 09:04:56 UTC+1, pyDev einars.stra...@gmail.com wrote:
 I hope here will be
 someone ready to welcome and help newcomers to enter the beautiful
 world of Python.

Just send them here, or to
http://mail.python.org/mailman/listinfo/tutor. We'll be happy to
help.

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


Re: Address of an immutable object

2010-05-30 Thread Simon Brunning
On 30 May 2010 18:38:23 UTC+1, candide cand...@free.invalid wrote:
 Two non mutable objects with the same value shall be allocated at a constant 
 and unique address ?

Nope.

 a = 999
 b = 999
 id(a) == id(b)
False

Your statement will be the case for small integers, but this in an
implementation detail. Indeed, this used to be the case for integers
up to 100 (IIRC) or thereabouts, but it's now the case up to 256:

 a = 256
 b = 256
 id(a) == id(b)
True
 a = 257
 a = 257
 id(a) == id(b)
False

Some identifier-like strings are also interned like this:

 a = 'foo'
 b = 'foo'
 id(a) == id(b)
True
 a = 'two words'
 b = 'two words'
 id(a) == id(b)
False

But again, it's an implementation detail, and shouldn't be relied upon.

This same issue also comes up with people noticing that they can
compare small integers with the 'is' operator, and getting a surprise
when bigger numbers come along:

 a = 256
 b = 256
 a is b
True
 a = 257
 b = 257
 a is b
False

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


Re: Email in 2.6.4

2010-05-24 Thread Simon Brunning
On 24 May 2010 14:59:24 UTC+1, dirknbr dirk...@googlemail.com wrote:
 It doesn't error on 'import email' but does on call to MimeText.

 import email
 msg = MIMEText('test')

 NameError: name 'MIMEText' is not defined

Here you want:

msg = email.MIMEText('test')

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


Re: logging: AttributeError: 'module' object has no attribute 'getLogger'

2010-05-23 Thread Simon Brunning
On 23 May 2010 14:46, Frank GOENNINGER dg1...@googlemail.com wrote:
 Traceback (most recent call last):
  File /.../src/pib/logging.py, line 37, in module
    main()

Here's a clue - looks like your own module is called logging. That's
what's getting imported by your import. Try naming your module
something else, and you should be golden.

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


Re: where are the program that are written in python?

2010-05-21 Thread Simon Brunning
On 21 May 2010 11:21:11 UTC+1, Deep_Feelings doctore...@gmail.com wrote:
 1- where are the programs that is written in python ?
 2- python is high productivity language : why there are no commercial
 programs written in python ?

See http://www.python.org/about/success/

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


Re: where are the program that are written in python?

2010-05-21 Thread Simon Brunning
On 21 May 2010 12:12:18 UTC+1, Deep_Feelings doctore...@gmail.com wrote:
 from that list i have a feeling that python is acting only as quick
 and dirty work nothing more !

Really?

Well, in any case, I can tell you that I know of a number of large
commercial web sites built with Django. I just can't tell you what
they are. ;-)

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


Re: Reading data from a Microsoft Access 2003 database

2010-05-19 Thread Simon Brunning
On 19 May 2010 10:28:15 UTC+1, Jimoid jimmy.cul...@gmail.com wrote:
 I use Ubuntu 64 bit and need to develop a programme (ideally in
 Python) to work on data that is contained in a Microsoft Access 2003
 database. I do not need to modify the database, simply read a few
 columns of data from some tables.

mxODBC might well be what you are looking for,

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


Re: Is this an ok thing to do in a class

2010-05-18 Thread Simon Brunning
On 18 May 2010 06:21:32 UTC+1, Vincent Davis vinc...@vincentdavis.net wrote:

 Just wondering if there is a problem with mixing a dictionary into a class 
 like this. Everything seems to work as I would expect.

No problem at all AFAIC.

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


Re: reading XML file using python

2010-05-17 Thread Simon Brunning
On 17 May 2010 09:34:51 UTC+1, shanti bhushan ershantibhus...@gmail.com wrote:
 Hi ,
 i am new to python.i want to read the XML file using python it ,by
 using DOm or SAX any of them.
 I want to read the http://www.google.com(any hyper text) from XML and
 print that.
 please give me the sample program for this.

Your question isn't very clear. Do you want to read the data from a
URL (such as http://www.google.com) and parse it? If so, you probably
don't want an XML parser as such - try Beautiful Soup.

Or do you have a piece of XML with some URLs in it that you want to
extract? ElementTree in the standard library is one good choice here
if you're not wedded to one of DOM or SAX.

What have you tried so far? No one is going to write code for you, but
we'd be happy to help you fix problems with your own code.
http://catb.org/~esr/faqs/smart-questions.html might be worth a
read.

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


Re: reading XML file using python

2010-05-17 Thread Simon Brunning
On 17 May 2010 10:43:06 UTC+1, Shanti Bhushan ershantibhus...@gmail.com wrote:
 Hi simon,
 you are right in 2nd paragaraph.
 i have a piece of XML with some URLs in it that i want to
 extract.
 I have no clue from where to get help on this.
 Please atleast guide me for document or link where i can get such help
 i can use elementary tree also but i dont know how to proceed with that.

You've not given us any idea as to the structure of your XML, so this
won't work. ;-)

import xml.etree.ElementTree as ET

for node in ET.parse('our.xml'):
print node.text

An introduction to ElementTree at http://effbot.org/zone/element-index.htm.

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


Re: Deleting more than one element from a list

2010-04-21 Thread Simon Brunning
On 21 April 2010 20:56, candide cand...@free.invalid wrote:
 Is the del instruction able to remove _at the same_ time more than one
 element from a list ?

Yup:

 z=[45,12,96,33,66,'c',20,99]
 del z[:]
 z
[]

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


Re: An open source AI research project

2010-04-17 Thread Simon Brunning
On 17 April 2010 09:03, David Zhang david...@gmail.com wrote:
 I have started an open source project to develop human-level
 Artificial Intelligence...

Have you people never seen Terminator? Sheesh.

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


Re: Sometimes the python shell cannot recognize the presence of an attribute.

2010-04-12 Thread Simon Brunning
2010/4/12 Ricardo Aráoz ricar...@gmail.com:
 Because .

... Guido says so: http://www.python.org/dev/peps/pep-0008/

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


Re: passing command line arguments to executable

2010-04-04 Thread Simon Brunning
On 3 April 2010 18:20, mcanjo mca...@gmail.com wrote:
 I tried doing the following code:

 from subprocess import Popen
 from subprocess import PIPE, STDOUT
 exefile = Popen('pmm.exe', stdout = PIPE, stdin = PIPE, stderr =
 STDOUT)
 exefile.communicate('MarchScreen.pmm\nMarchScreen.out')[0]

 and the Command Prompt opened and closed, no exceptions were generated
 but the program didn't run. Am I doing something wrong?

Have you tried running pmm.exe from the command line? What does that
look like? Does it matter what the current working directory is at the
time?

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


Re: passing command line arguments to executable

2010-04-03 Thread Simon Brunning
On 3 April 2010 17:09, mcanjo mca...@gmail.com wrote:
 I have an executable (I don't have access to the source code) that
 processes some data. I double click on the icon and a Command prompt
 window pops up. The program asks me for the input file, I hit enter,
 and then it asks me for and output filename, I hit enter a second time
 and it goes off and does its thing and when it is finished running the
 Command Prompt goes away and I have my new output file in the same
 directory as my executable and input file. I would like to be able to
 batch process a group of files. I thought about using os.spawnv() in
 a loop and at each iteration of the loop passing in the file in and
 out names but that didn't work. Does anyone have any ideas?

Have a look at the subprocess module.

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


Re: Can't define __call__ within __init__?

2010-03-10 Thread Simon Brunning
On 10 March 2010 13:12, Neal Becker ndbeck...@gmail.com wrote:
 Want to switch __call__ behavior.  Why doesn't this work?  What is the
 correct way to write this?

 class X (object):
    def __init__(self, i):
        if i == 0:
            def __call__ (self):
                return 0
        else:
            def __call_ (self):
                return 1


 x = X(0)

 x()
 TypeError: 'X' object is not callable

__call__ is in the __init__ method's local namespace - you need to
bind it to the class's namespace instead:

X.__call__ = __call__

But this probably isn't what you want either, since all instances of X
will share the same method.

What are you trying to do? In your simple example, you'd be much
better off with a single __call__ method. But you knew that.

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


Re: Anything like Effective Java for Python?

2010-03-10 Thread Simon Brunning
On 10 March 2010 15:19, kj no.em...@please.post wrote:
 Subject line pretty much says it all: is there a book like Effective
 Java for Python.  I.e. a book that assumes that readers are
 experienced programmers that already know the basics of the language,
 and want to focus on more advanced programming issues?

http://www.packtpub.com/expert-python-programming/book is good.

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


Re: a newbie's question

2010-03-09 Thread Simon Brunning
On 9 March 2010 13:51, Lan Qing efi...@gmail.com wrote:
 Hi all,
       I'm a newbie of python programming language.

Welcome!

 I have used c/c++ for 5
 years, and one year experience in Lua programming language. Can any one give
 me some advice on learning python. Think you for any help!!

You'll find some useful starting points here -
http://wiki.python.org/moin/BeginnersGuide/Programmers.

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


Re: Is automatic reload of a module available in Python?

2010-02-18 Thread Simon Brunning
2010/2/17 Arnaud Delobelle arno...@googlemail.com:
 I know some people will point at more 'pro' ways of testing but this has
 the merit of being very straightforward.  Then when you move on to more
 sophisticated techniques, I think you will understand better the
 motivations behind them.

Oh, I don't know. I like to think I'm fairly pro when it comes to
TDD, and this is exactly what I do - a unit test module run from the
shell.

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


Re: Few questions on SOAP

2010-02-18 Thread Simon Brunning
On 18 February 2010 15:36, joy99 subhakolkata1...@gmail.com wrote:
 (iv)    Is SOAPpy fine?

AFAIK, SOAPpy is unsupported, and a bit on the stale side. Those poor
souls forced to make SOAP calls with Python seem to be using Suds
mostly these days,.

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


Re: search entire drive say c:

2010-02-12 Thread Simon Brunning
On 12 February 2010 12:17, prakash jp prakash.st...@gmail.com wrote:

 can any of u help to search a file say abc.txt in entire c drive (windows)
 and print the path/s stating such a files presence.

http://code.activestate.com/recipes/499305/ might be a useful start.

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


Re: Python version of perl's if (-T ..) and if (-B ...)?

2010-02-12 Thread Simon Brunning
On 12 February 2010 14:14, Christian Heimes li...@cheimes.de wrote:
 That's a butt ugly heuristic

He did say it was from Perl, the home of butt-ugly.

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


Re: Any way to turn off exception handling? (debugging)

2010-02-11 Thread Simon Brunning
On 11 February 2010 16:17, mk mrk...@gmail.com wrote:
 I'm getting an exception (on socket) handled in a program I'm trying to
 debug. I have trouble locating where exactly that happens.

 In such situation turning exception handling off could be useful, bc
 unhandled exception stack trace is precisely what I'm trying to obtain.

 Anybody knows of such possibility?

Not as far as I know. Besides, the chances are that if you were to be
able to turn off exception handling altogether your code wouldn't make
it as far as the code you are interested in anyway.

Is there some way you could monkey patch the exception class to add
some logging in there or something?

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


Re: if {negative} vs. if {positive} style (was: New to Python)

2010-02-10 Thread Simon Brunning
On 10 February 2010 03:36, Tim Chase python.l...@tim.thechases.com wrote:
 Any thoughts on how others make the choice?

There are two criteria that I use here. I'll often tend towards the
positive test; it's just that little bit easier to comprehend, I
think. On the other hand, if one case is overwhelmingly more common,
I'll usually put that first even if it does mean using a negative
test.

I'm not buying the short-case-first argument. If the code in a case
block is long enough for that to matter, it really belongs in a
function of its own anyway.

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


Re: ANN: obfuscate

2010-02-10 Thread Simon Brunning
On 10 February 2010 01:24, Ben Finney ben+pyt...@benfinney.id.au wrote:
 The classic example is rot-13 encryption of text in internet messages;
 it would be a failure of imagination to suggest there are not other,
 similar use cases.

That's built-in:

 Hello World!.encode('rot-13')
'Uryyb Jbeyq!'

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


Re: ANN: obfuscate

2010-02-09 Thread Simon Brunning
On 9 February 2010 16:29, Robert Kern robert.k...@gmail.com wrote:
 On 2010-02-09 09:37 AM, Daniel Fetchinson wrote:
 If the code base stabilizes in a production version after losing the
 alphas and betas they would be a great addition to the stdlib, I
 think.

 Why?

I agree. Why wait? Put them in the stdlib now!

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


Re: Help parsing a page with python

2010-01-27 Thread Simon Brunning
2010/1/27 mierdatutis mi mmm...@gmail.com:
 Hi,

 I would like to parse a webpage to can get the url of the video download. I
 use pyhton and firebug but I cant get the url link.

 Example:

 The url where I have to get the video link is:
 http://www.rtve.es/mediateca/videos/20100125/saber-comer---salsa-verde-judiones-25-01-10/676590.shtml;

 The video is
 http://www.rtve.es/resources/TE_SSAC011/flv/8/2/1264426362028.flv
 Could you help me please?

That URL doesn't appear to be in the HTML - it must be being brought
in by the JavaScript somehow.

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


Re: Help parsing a page with python

2010-01-27 Thread Simon Brunning
2010/1/27 mierdatutis mi mmm...@gmail.com:
 Those videos are generated by javascript.
 There is some parser with python for javascript???

There is http://github.com/davisp/python-spidermonkey, but
simulating the whole context of a browser is going to be a horror.

You are probably far better off automating a real browser. WebDriver
(http://bit.ly/crAEPu) has Python bindings these days. It's
primarily intended for functional testing, but it might be a good fit
here too.

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


Re: Help parsing a page with python

2010-01-27 Thread Simon Brunning
2010/1/27 mierdatutis mi mmm...@gmail.com:
 Hello again,

 What test case for Windmill? Can you say me the link, please?

http://lmgtfy.com/?q=windmill+test

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


Re: Python and Ruby

2010-01-27 Thread Simon Brunning
2010/1/27 Jean Guillaume Pyraksos wis...@hotmail.com:
 What are the arguments for choosing Python against Ruby
 for introductory programming ?

Frankly, either would be a good choice.

I think Python is a little cleaner, but I'm sure you'd find Ruby fans
who'd argue the complete opposite. Both have good ecosystems, (i.e.
good communities, and plenty of good libraries and frameworks) - but
Python is probably a bit ahead here having been around a bit longer.

 Python has no provisions
 for tail recursion, Ruby is going to... So what ?

This would be a very strange reason to pick one language over the
other - it's a very minor point.

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


Re: My experiences building a small app on Python

2010-01-26 Thread Simon Brunning
2010/1/26 Cascade3891 mlee3...@gmail.com:
 It's a bit of a read. But insightful.

We'll be the judge of that, surely? ;-)

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


Re: Is python not good enough?

2010-01-25 Thread Simon Brunning
2010/1/25 Albert van der Horst alb...@spenarnc.xs4all.nl:
 If Go was to compete with anything, they would have give it a name
 that was Googleable. ;-)

If they want it Googleable, it will be. ;-)

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


Re: use of super

2010-01-19 Thread Simon Brunning
2010/1/19 harryos oswald.ha...@gmail.com:
 I was going thru the weblog appln in practical django book by
 bennet .I came across this

 class Entry(Model):
        def save(self):
                dosomething()
                super(Entry,self).save()

 I couldn't make out why Entry and self are passed as arguments to super
 ().Can someone please explain?

Does http://docs.python.org/library/functions.html#super make
anything clearer?

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


Re: Create list/dict from string

2010-01-19 Thread Simon Brunning
2010/1/19 Peter Otten __pete...@web.de:
 Both eval() and json.loads() will do. eval() is dangerous as it allows the
 user to run arbitrary python code.

Something like http://code.activestate.com/recipes/364469/ might be
worth a look too.

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


Re: What is a list compression in Python?

2010-01-18 Thread Simon Brunning
2010/1/18 Kit wkfung.e...@gmail.com:
 Hello Everyone, I am not sure if I have posted this question in a
 correct board. Can anyone please teach me:

 What is a list compression in Python?

Perhaps you mean a list comprehension? If so, see
http://diveintopython.org/native_data_types/mapping_lists.html.

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


Re: Author of a Python Success Story Needs a Job!

2010-01-15 Thread Simon Brunning
2010/1/14 Novocastrian_Nomad gregory.j.ba...@gmail.com:
 Why is it so many, so called high tech companies, insist on the 19th
 century practice of demanding an employee's physical presence in a
 specific geographic location.

Pair programming and co-location with your end users both hugely
increase real productivity, in my experience. The programmer-to-code
step is only one of many parts of the process.

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


Re: Getting access to the process table from python?

2010-01-14 Thread Simon Brunning
2010/1/13 Roy Smith r...@panix.com:
 I need to get information about what processes are running on a box.
 Right now, I'm interested in Solaris and Linux, but eventually
 probably other systems too.  I need to know things like the pid,
 command line, CPU time, when the process started running, and owner.

 Has anybody written a module to do this?  I know I can run ps and
 parse the output, or troll /proc directly, but if somebody's already
 written all that, I'd rather not reinvent the wheel.

http://www.psychofx.com/psi/

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


Re: pywinauto to show the dialog , menu, etc

2010-01-01 Thread Simon Brunning
2009/12/31 Hari h...@pillai.co.uk:
 Hi
 I am using pywinauto to automate an custom program to startup and load
 process , execute etc. But cannot determine menuselect. Is there a way or
 tool which can run against the exe to show the menu, dialog box, list box
 which are contained within it.

Winspector might be worth a try: http://www.windows-spy.com/

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


Re: Absolute beginner

2009-12-30 Thread Simon Brunning
2009/12/30  lucbo...@hotmail.com:

 At a dos-prompt :

 Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit
 (Intel)] on
 win32
 Type help, copyright, credits or license for more information.
 print Hello
  File stdin, line 1
    print Hello
                ^
 SyntaxError: invalid syntax

You are using Python 2 syntax, but a Python 3 interpreter. So, either
download an earlier version of Python, or use a tutorial which covers
Python 3.

Rather unlucky timing, really - Python 3 is the first non-trivially
backward incompatible version for a very long time - at least a decade
and a half.

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


Re: Perl to Python conversion

2009-12-28 Thread Simon Brunning
2009/12/25 Aahz a...@pythoncraft.com:

 I'd write an imperial to metric converter in Python  ;-)

Should be possible to use unum (http://bit.ly/4X0PwR) to do the
conversions. The SI units are already defined - adding in any
necessary imperial units should be easy enough.

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


Re:

2009-12-28 Thread Simon Brunning
2009/12/24 Yulin yu...@linklater.co.za:
 Hi when I start my Pc I get error “ The specified module could not be found.
 LoadLibrary(pythondll)failed

 Please Help once I have enterd I get the following….C:\Documents and
 settings\all users\.clamwin\quarentine\python25.DLL

 PLEASE help I cant load most of my programmes

Is this a new PC, or has this just started happening? Have you
recently installed any new software? Or uninstalled any? Of deleted
any files that you didn't recognise?

Looks like your PC is running something on startup that requires
Python to work, and for some reason it's not available (Anti-virus
software? That quarantine directory name is very suspicious.) There's
not really enough to go on to say more at the moment.

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


Re: OS independent way to check if a python app is running?

2009-12-14 Thread Simon Brunning
2009/12/14  pyt...@bdurham.com:
 Is there an os independent way to check if a python app is running?

if True:
print I'm running.

;-)

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


Re: postgresql_autodoc in Python?

2009-12-07 Thread Simon Brunning
2009/12/6 Wolfgang Keller felip...@gmx.net:
 Hello,

 has anyone ever implemented something similar to postgresql_autodoc in Python?

Dunno - what is it?

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


Re: Where is my namespace?

2009-12-07 Thread Simon Brunning
2009/12/7 vsoler vicente.so...@gmail.com:
 I take the example from Mark Lutz's excellent book Learning Python.

 *** In nested1.py  I have:
 X=99
 def printer(): print X

 *** In nested2.py  I have:
 from nested1 import X, printer
 X=88
 printer()

 What is amazing is that running nested2.py prints 99 and not 88.

 My questions are:

 1. Using statement from instead of import should not create a
 namespace, at least that's what I think. However, the printer()
 function is able to find 99 which is residing in...  a namespace?

Sorry - you think wrong. All modules have their own namespace.

from blah import injects the objects from the imported module
directly into the importing modules namespace, but they are still two
distinct namespaces.

 2. I have tried to access the 88 by qualification from nested2.py.
 However, I cannot. If using print nested1.X in nested2.py I get an
 error

If you do from blah import the imported module itself isn't bound to
any name in the importing module - you can't get at it at all.

 3. Mark says: The from statement is really an assignment to names in
 the importer's scope--a name-copy operation, not a name aliasing.   I
 don't fully understand what he means. Could anybody explain?

Does the above help?

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


Re: Where is my namespace?

2009-12-07 Thread Simon Brunning
2009/12/7 Steven D'Aprano st...@remove-this-cybersource.com.au:
 On Mon, 07 Dec 2009 16:25:39 +, Simon Brunning wrote:
 If you do from blah import the imported module itself isn't bound to
 any name in the importing module - you can't get at it at all.

 Not quite -- you can get to it if you're willing to do some more work.

A little inaccuracy sometimes saves tons of explanation. - Saki, The
Square Egg, 1924

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


Re: can python do this?

2009-12-02 Thread Simon Brunning
2009/12/2 Rounak irounakj...@gmail.com:
 I am a complete newbie. I want to know if the following can be done
 using python or should I learn some other language:
 (Basically, these are applescripts that I wrote while I used Mac OS)

Python can do anything Applescript can do with the appscript module -
see http://appscript.sourceforge.net/py-appscript/index.html. And,
naturally, very much more.

I have some driving iTunes examples I'd be happy to send you off-list
if you're interested.

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


Re: pbs scripts

2009-12-02 Thread Simon Brunning
2009/12/2 aoife aoife...@hotmail.com:
 Hi,very new.hoping to incorporate python into my postgrad.

 Basically I have 2,000 files.I want to write a script that says:

 open each file in turn

If they are in one directory, look at the glob module. If they are in
a bunch of sub-directories, see os.walk(), or http://bit.ly/5Q5Qiv.

For looping through the files, see http://bit.ly/4zvi9P.

 for each file:
       open this pbs script and run MUSCLE (a sequence alignment tool)
 on each file

Is MUSCLE a command-line tool? If so, see the subprocess module.

       close this file

Do you actually need to open the file, or just run a command on it?
Sounds like the latter to me.

       move on to next file.

Give it a go. Any problems, I'm sure we'd be happy to help.

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


Re: reading from a text file

2009-11-30 Thread Simon Brunning
2009/11/27 baboucarr sanneh sanne...@hotmail.com:
 hi all

 i would like to create a python program that would read from a text file and
 returns one result at random.

This might be of use:

http://code.activestate.com/recipes/426332/#c2

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


Re: Is there something similar to list comprehension in dict?

2009-11-20 Thread Simon Brunning
2009/11/20 Michele Simionato michele.simion...@gmail.com:
 Yes, but only in Python 3:

 {(i, x) for i, x in enumerate('abc')}
 {(0, 'a'), (1, 'b'), (2, 'c')}

In Python 2.x, you can do:

 dict((i, x) for i, x in enumerate('abc'))
{0: 'a', 1: 'b', 2: 'c'}

(Works in 2.5 - I can't remember when generator expressions were introduced.)

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-18 Thread Simon Brunning
2009/11/17 sjm sjms...@gmail.com:
 On Nov 16, 12:54 pm, Steve Ferg steve.ferg.bitbuc...@gmail.com
 wrote:
 snip
 Does anybody know a language with this kind of syntax for
 ifThenElseEndif?

 Modern-day COBOL:

 IF      some-condition
        do-something
 ELSE
        do-something-else
 END-IF.

RPG/400's SELEC statement: http://bit.ly/2LDegk

Thing of beauty.

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


Re: QuerySets in Dictionaries

2009-11-12 Thread Simon Brunning
2009/11/12 scoopseven mark.ke...@gmail.com:
 I need to create a dictionary of querysets.  I have code that looks
 like:

 query1 = Myobject.objects.filter(status=1)
 query2 = Myobject.objects.filter(status=2)
 query3 = Myobject.objects.filter(status=3)

 d={}
 d['a'] = query1
 d['b'] = query2
 d['c'] = query3

 Is there a way to do this that I'm missing?

Untested:

wanted = (('a', 1), ('b', 2), ('c', 2))
d = dict((key, Myobject.objects.filter(status=number)) for (key,
number) in wanted)


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


Re: why does help(import) not work?

2009-11-06 Thread Simon Brunning
2009/11/6 Robert P. J. Day rpj...@crashcourse.ca:

  i'm sure there's a painfully obvious answer to this, but is there a
 reason i can't do:

 help(import)
  File stdin, line 1
    help(import)
              ^
 SyntaxError: invalid syntax

import is a keyword, not an object.

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


Re: regexp help

2009-11-04 Thread Simon Brunning
2009/11/4 Nadav Chernin nada...@qualisystems.com:
 I’m trying to write regexp that find all files that are not with next
 extensions:  exe|dll|ocx|py,  but can’t find any command that make it.

http://code.activestate.com/recipes/499305/ should be a good start.
Use the re module and your regex instead of fnmatch.filter(), and you
should be good to go.

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


Re: regexp help

2009-11-04 Thread Simon Brunning
2009/11/4 Nadav Chernin nada...@qualisystems.com:
 Thanks, but my question is how to write the regex.

re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) works for me.

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


Re: regexp help

2009-11-04 Thread Simon Brunning
2009/11/4 Nadav Chernin nada...@qualisystems.com:
 No, I need all files except exe|dll|ocx|py

not re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name)

Now that wasn't so hard, was it? ;-)

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


Re: self.__dict__ tricks

2009-11-03 Thread Simon Brunning
2009/11/1 Steven D'Aprano st...@remove-this-cybersource.com.au:

 The only stupid question is the one you are afraid to ask.

I was once asked, and I quote exactly, are there any fish in the Atlantic sea?

That's pretty stupid. ;-)

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


Re: Help with SOAPpy and WSDL.

2009-11-02 Thread Simon Brunning
2009/11/2 Henrik Aagaard Sørensen henrik.soren...@changenetworks.dk:
 I have a problem with SOAPpy and WSDL. It is explained here:
 http://www.python-forum.org/pythonforum/viewtopic.php?f=3t=15532

Why not explain it here?

In any case, I imagine the advice is going to be to try Suds -
https://fedorahosted.org/suds/.

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


Re: Help with SOAPpy and WSDL.

2009-11-02 Thread Simon Brunning
2009/11/2 Henrik Aagaard Sørensen henrik.soren...@changenetworks.dk:
 I'll try to explain it here then:

 A small example on SOAPpy and WSDL. My code:
 from SOAPpy import WSDL
 wsdlFile = 'http://www.webservicex.net/country.asmx?wsdl'
 server = WSDL.Proxy(wsdlFile)
 server.GetCurrencyByCountry('Zimbabwe')

 returns:

 System.Web.Services.Protocols.SoapException: Server was unable to
 process request. --- System.Data.SqlClient.SqlException: Procedure or
 function 'GetCurrencyByCountry' expects parameter '@name', which was not
 supplied.
   at WebServicex.country.GetCurrencyByCountry(String CountryName)
   --- End of inner exception stack trace ---: 


 It is as if it doesn't get the name Zimbabwe.

Try server.GetCurrencyByCountry(name='Zimbabwe')

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


Re: New Python Novice

2009-10-02 Thread Simon Brunning
2009/10/2 baboucarr sanneh sanne...@hotmail.com:
 Hello Everyone,

 My name is Baboucarr ..am from the gambia (west africa)..

I visited some years back. Friendly people.

 I just read about
 python and i want to know how to program with it..
 I would like you guys to help me in my road to becoming a python guru..Am a
 novice so i would welcome any suggestions etc..

You might want to start with http://wiki.python.org/moin/BeginnersGuide.

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


Re: help wanted with list

2009-09-24 Thread Simon Brunning
2009/9/24 Ahmed Shamim partha.sha...@gmail.com:
 list = [ 'a', '1', 'b', '2']
 what would be the logic, if I input a to get output 1.

Turn it into a dictionary first:

 mylist = [ 'a', '1', 'b', '2']
 mydict = dict(zip(mylist[::2], mylist[1::2]))
 mydict['a']
'1'

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


Re: recommendation for webapp testing?

2009-09-17 Thread Simon Brunning
2009/9/17 Schif Schaf schifsc...@gmail.com:
 What's the difference between WebDriver and Selenium?

Selenium runs in a browser, and uses JavaScript to perform all your
automated actions. It need a browser running to work. Several are
supported, Firefox, Safari, IE and I think others. You are at thier
mercy of the browser's JavaScript engine - I've often had trouble with
IE's XPath support, for instance - tests will run fine in Firefox and
safari, but not work in IE.

One big advantage of Selenium is that there an IDE available, a
Firefox add-on which will allow you to record actions. This is useful
for building regression tests and acceptance tests for bugs. Sadly, it
often tempts people into writing their acceptance tests after the
fact, too - a grave mistake IMHO.

Selenium tests can be written in Python, Ruby, Java, and in the form
of HTML tables. This last seems quite popular with QAs for some reason
which escapes me entirely.

WebDriver runs outside a browser. It can be (and usually is) used to
drive a real browser, though there's is a HtmlUnit driver available,
which bypasses any real browser and goes direct to the site you are
testing. Even this last option, though, does allow the testing of
sites which make use of JavaScript - which is just about all of them
these days.

It makes use of native drivers for each of the browsers it supports,
so it runs very much faster than Selenium. Since it presents the test
program with its own version of the page's DOM tree, it's also less
likely to give browser incompatibilities.

WebDriver tests can be written in Java or Python, at the moment.

The Selenium people have recognized the superiority of the WebDriver
approach, so the nascent Selenium 2 will use WebDriver under the
covers. For the moment, though, you have to pick one or the other.

Mechanize is a superb library for its intended purpose - I use it all
the time. It's lack of support for pages with JavaScript
functionality, though, means it's not very useful at a testing tool
for modern web sites.

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


Re: recommendation for webapp testing?

2009-09-16 Thread Simon Brunning
2009/9/16 Schif Schaf schifsc...@gmail.com:

 I need to do some basic website testing (log into account, add item to
 cart, fill out and submit forms, check out, etc.). What modules would
 be good to use for webapp testing like this?

http://code.google.com/p/webdriver/ might be worth a look.

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


Re: Use python to execute a windows program

2009-09-11 Thread Simon Brunning
2009/9/11 Doran, Harold hdo...@air.org:
 The way we do this now is a person sits in front of their machine and
 proceeds as follows:

 1) Open windows program
 2) Click file - open which opens a dialog box
 3) Locate the file (which is a text file) click on it and let the
 program run.

It might very well be possible, depending upon how the program you
want to automate has been written.

First, make sure, absolutely sure, that's there's no proper
automation option available - a command line version, COM automation,
that kind of thing. These approaches are very much easier than GUI
automation.

If none of these options are available, http://pywinauto.openqa.org/
is probably what you need.

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


Re: The future of Python immutability

2009-09-07 Thread Simon Brunning
2009/9/7 Terry Reedy tjre...@udel.edu:
 Dennis Lee Bieber wrote:
 I'd say the
 mutables are in the majority G

 I think it depends on whether one counts classes or instances. Typical 
 programs have a lot of numbers and strings.

Ah, but immutable instances can be, and often are, interned. This will
cut down on their number considerably. ;-)

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


Re: Usage of main()

2009-09-04 Thread Simon Brunning
2009/9/4 Manuel Graune manuel.gra...@koeln.de:
 How come the main()-idiom is not the standard way of writing a
 python-program (like e.g. in C)?

Speaking for myself, it *is* the standard way to structure a script. I
find it more readable, since I can put my main function at the very
top where it's visible, with the classes and functions it makes use of
following in some logical sequence.

I suspect that this is the case for many real-world scripts. Perhaps
it's mainly in books and demos where the extra stuff is left out so
the reader can focus on what the writer is demonstrating?

 And in addition: Can someone please explain why the first version
 is so much slower?

Access to globals is slower than access to a function's locals.

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


Re: Question on the csv library

2009-08-28 Thread Simon Brunning
2009/8/28 John Machin sjmac...@lexicon.net:

 Mark, there exist parallel universes the denizens of which use strange
 notation e.g. 1.234,56 instead of 1,234.56

When displaying data, sure.

 and would you believe they
 use ';' instead of ',' as a list separator ...

CSV is a data transfer format, not a display format. Locale specific
stuff like this has no place in it. Dates, IMHO, should be in the ugly
but unambiguous ISO 8601 format in a CSV. It's for import and export,
not for looking pretty.

Besides - CSV; the clue's in the name. ;-)

 Excel perfidiously
 gives them what they expect rather than forcing them to comply with
 The One True Way.

When people export to a comma separated value file, they are almost
certainly expecting a file containing values separated by comas. If
Excel isn't giving them this by default, it's broken.

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


Re: Python for professsional Windows GUI apps?

2009-08-26 Thread Simon Brunning
2009/8/26 geekworking geekwork...@gmail.com:
 If you are planning a database driven app, you should first settle on
 a DB server. Any real enterprise DB system will put all of the
 business logic in the database server. The choice of a front end
 should be secondary.

The trend for some years now has been to get behavior out of the
database and into the application, where it belongs. True, we tend to
keep the presentation tier separate too, but we really don't put all
of the business logic in the database server.

Going back to the OP's question, it would be worth taking a look at
what the resolver boys are up to: http://www.resolversystems.com/.

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


Re: Need cleanup advice for multiline string

2009-08-12 Thread Simon Brunning
2009/8/11 Robert Dailey rcdai...@gmail.com:
 On Aug 11, 3:40 pm, Bearophile bearophileh...@lycos.com wrote:
 There are gals too here.

 It's a figure of speech. And besides, why would I want programming
 advice from a woman? lol. Thanks for the help.

Give the attitudes still prevalent in our industry (cf
http://tinyurl.com/c5nqju and many more), I'm sorry to say that I
don't think this is funny.

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


Re: iText for Python

2009-07-27 Thread Simon Brunning
2009/7/27 santhoshvkumar santhosh.vku...@gmail.com:
           One of my cousin  suggested me to do a IText PDF converter
 for python. Actually I heard that there is no separate IText converter
 either we have to go for jython or GCJ with wrapper. Instead of
 wrapping, my plan is to create a separate module with Python and I am
 thinking of doing this in as my final year project also. Kindly give
 me your suggestion.

What would this give us that ReportLab does not? I wouldn't want to
see you spend a lot of time reinventing the wheel...

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


Re: generation of keyboard events

2009-07-06 Thread Simon Brunning
2009/7/6 RAM serverin2...@yahoo.com:

 I am trying to do this on windows. My program(executable) has been
 written in VC++ and when I run this program, I need to click on one
 button on the program GUI i,e just I am entering Enter key on the
 key board. But this needs manual process. So i need to write a python
 script which invokes my program and pass Enter key event to my
 program so that it runs without manual intervention.

Try http://pywinauto.openqa.org/.

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


Re: Need Help

2009-07-02 Thread Simon Brunning
2009/7/2 Tengiz Davitadze davitadze.ten...@gmail.com:
 Hello. I can't find a wright mail address. If you can help me I need to get
 an information about UNICODE. I am georgian and I need to write programs on
 georgian language . If you can transfer this mail or send me a wright mail
 about encoding or unicode information.

Our chief link is
http://www.joelonsoftware.com/articles/Unicode.html.
http://www.joelonsoftware.com/articles/Unicode.html and
http://effbot.org/zone/unicode-objects.htm. Our two links are
http://effbot.org/zone/unicode-objects.htm and
http://www.joelonsoftware.com/articles/Unicode.html. And
http://www.amk.ca/python/howto/unicode. Our *three* links are
http://effbot.org/zone/unicode-objects.htm,
http://www.joelonsoftware.com/articles/Unicode.html, and
http://www.amk.ca/python/howto/unicode. And
http://catb.org/esr/faqs/smart-questions.html. Our *four*...no...
*Amongst* our links Amongst our linkry are such elements as
http://effbot.org/zone/unicode-objects.htm,
http://www.joelonsoftware.com/articles/Unicode.html I'll come in
again.

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


Re: Beginning with Python; the right choice?

2009-06-28 Thread Simon Brunning
2009/6/27 sato.ph...@gmail.com sato.ph...@gmail.com:
 Thank you for all of the links and advice.

 What do I want to learn Python for?

 Again, pardon me for my lack of relevant information.  I am also a
 journalist (an out of work one at the moment, like so many others) and
 I feel that learning python could be useful for computer assisted
 reporting, that is, utilizing databases, creating interactive maps and
 the like.

 http://chicago.everyblock.com/crime/

That's a Python site!

As a journalist, you might also be interested in
http://www.guardian.co.uk/politics/2009/jun/18/mps-expenses-crowdsourcing-app
- The Guardian, a UK national newspaper, quickly wrote and deployed a
Python application to allow their readers to cooperate in the massive
manual task of analysing MPs' expenses receipts, looking for
ill-doing.

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


Re: Programming language comparison examples?

2009-06-06 Thread Simon Brunning
2009/6/5  bearophileh...@lycos.com:
 someone:
 I thought there was a website which demonstrated how to program a bunch of
 small problems in a number of different languages.

 http://www.rosettacode.org/wiki/Main_Page
 http://en.literateprograms.org/LiteratePrograms:Welcome
 http://www.codecodex.com/wiki/index.php?title=Main_Page
 http://merd.sourceforge.net/pixel/language-study/scripting-language/
 http://pleac.sourceforge.net/
 http://www.angelfire.com/tx4/cus/shapes/index.html

And my favorite: http://99-bottles-of-beer.net/

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


Re: Wrapping comments

2009-05-11 Thread Simon Brunning
2009/5/10 Tobias Weber t...@gmx.net:
 (still not gonna use software that doesn't let me type # because it's
 alt+3 on a UK layout; having to re-learn or configure that is just sick)

To use Aquamacs with a UK keyboard, you want to select Options, Option
Key, Meta  British. Things just work then.

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


Re: Return value usage

2009-04-29 Thread Simon Brunning
2009/4/29 Zac Burns zac...@gmail.com:
 I would like to know when my function is called whether or not the
 return value is used. Is this doable in python? If it is, can it ever
 be pythonic?

AFAIK, no, it's not.

 The use case is that I have functions who's side effects and return
 values are cached. I would like to optimize them such that I don't
 have to recall (from a network) the return values if they are not
 used. Obviously it would be possible to add a parameter to the
 function but I would like this optimization to be implemented
 passively because 1. The api is already widely used and 2. I would
 like to keep the complexity of the api to a bare minimum.

Why not return a proxy, and have the proxy do the retrieval of the
needed data if it's used? Delegation is ridiculously easy in Python.

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


Re: v 3.0 mpkg

2009-02-04 Thread Simon Brunning
2009/2/4 John Forse johnfo...@talktalk.net:
  Does anyone know if Python v3.0 is available as an .mpkg installer for Mac
 10.5.6. I have used 2.5  updated to 2.6.1 this way, but can't find any
 reference to one on the Python.org download site. I've downloaded the Python
 3.0 folder but can't follow how to install it without a .mpkg file. Any help
 would be really appreciated.

AFAIK there's no Python 3.0 installer for the Mac. You'll have to
build it yourself - see http://tinyurl.com/6zkem7.

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


Re: Date Comparison

2009-02-03 Thread Simon Brunning
2009/2/3 Diez B. Roggisch de...@nospam.web.de:
 Use the java API of java.util.

Or better still, use Joda.

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


Re: JDBC in CPYTHON

2009-02-03 Thread Simon Brunning
2009/2/3 KMCB kmcbrea...@yahoo.com:
 I was wondering if anyone was aware of a JDBC DBAPI module for
 cpython.  I have looked at PYJDBC and was interested in avoiding using
 that extra level of ICE.  I was thinking maybe someone would have back
 ported zxJDBC from Jython.  Or used that as a starting point, to
 create a module and had a C based wrapper for the driver.  This type
 of activity was talked about back in 2004 on this forum, but I was
 wondering if anyone had newer information.

I don't know if http://jpype.sourceforge.net/ or
http://www.boddie.org.uk/python/javaclass.html might be of help.

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


Re: Reading text file with wierd file extension?

2009-02-02 Thread Simon Brunning
2009/2/2 Lionel lionel.ke...@gmail.com:
 Hi Folks, Python newbie here.

 I'm trying to open (for reading) a text file with the following
 filenaming convension:

 MyTextFile.slc.rsc

Some kind of a resource fork, perhaps? Where did the file come from?

Python doesn't do anything magic with filenames, so this must be some
sort of a fileysytem oddity, I think.

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


Re: Odd syntactic NON-error?

2009-01-30 Thread Simon Brunning
2009/1/30 Alaric Haag h...@lsu.edu:

 So, is the secret that the period is syntactically an operator like
 + or * ?

Exactly that: http://users.rcn.com/python/download/Descriptor.htm.

Sh!

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


  1   2   3   4   5   6   >