Param decorator - can you suggest improvements

2013-01-17 Thread Mark Carter
I thought it would be interesting to try to implement Scheme SRFI 39 (Parameter 
objects) in Python.

The idea is that you define a function that returns a default value. If you 
call that function with no arguments, it returns the current default. If you 
call it with an argument, it resets the default to the value passed in. Here's 
a working implementation:

# http://www.artima.com/weblogs/viewpost.jsp?thread=240845

from functools import wraps

class Param(object):
def __init__(self, default):
self.default = default
#self.func = func

def __call__(self, func, *args):
@wraps(func)
def wrapper(*args):
#print 'calling hi'
if len(args) 0:
self.default = args[0]
#print len(args),  ' ', args
return self.default # self.func(*args)
return wrapper


@Param(42)
def hi(newval):
pass

print hi() # 42
print hi(12) # 12
print hi() # 12
hi(13) # sets it to 13
print hi() # 13


Can anyone suggest a better implementation?
-- 
http://mail.python.org/mailman/listinfo/python-list


Google spreadsheets - getting started

2012-11-03 Thread Mark Carter
I want to mess around with my online Google spreadsheets from my Linux box 
programmatically. I am TOTALLY confused.

I've got gdata installed, and it appears that the best way to access the 
spreadsheets is to authenticate with Oauth2.

Here's the main thing: how do I get an Oauth2 key to use with Google 
spreadsheets?

I obtain a p12 key, but I don't know if that's for something completely 
different.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google spreadsheets - getting started

2012-11-03 Thread Mark Carter
OK, maybe the p12 file is useful after all (?) I've got the following code:

import gdata

tokenfile = my-privatekey.p12
f = open(tokenfile, 'r')
blob = f.read()
f.close()
token = gdata.gauth.token_from_blob(blob)

When I run that I get:
Traceback (most recent call last):
  File /home/mcarter/wapp.py, line 8, in module
token = gdata.gauth.token_from_blob(blob)
AttributeError: 'module' object has no attribute 'gauth'

I guess I'm using a newer version of gdata (2.0.14). 

None of this makes any sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google spreadsheets - getting started

2012-11-03 Thread Mark Carter
OK, the story so far:


import gdata
import gdata.auth
import gdata.gauth
import gdata.docs.service
import OpenSSL.crypto

tokenfile = privatekey.p12
#f = open(tokenfile, 'r')
#blob = f.read()
#f.close()
#if blob:
p12 = OpenSSL.crypto.load_pkcs12(file(tokenfile, 'rb').read(), 'notasecret')
print p12.get_certificate() 

#token = gdata.gauth.token_from_blob(p12)
#print token: , token

gd_client = gdata.docs.service.DocsService()
#gd_client.SetOAuthToken(token)
gd_client.SetOAuthToken(p12)

feed = gd_client.GetDocumentListFeed() # line 22
for entry in feed.entry:
  print entry.title.text.encode('UTF-8')

print Finished



It baulks as follows:
/usr/bin/python -u  /home/mcarter/wapp.py
X509 object at 0x7fccc0917a50
Traceback (most recent call last):
  File /home/mcarter/wapp.py, line 22, in module
feed = gd_client.GetDocumentListFeed()
  File /usr/lib/pymodules/python2.7/gdata/docs/service.py, line 259, in 
GetDocumentListFeed
return self.QueryDocumentListFeed(uri)
  File /usr/lib/pymodules/python2.7/gdata/docs/service.py, line 238, in 
QueryDocumentListFeed
return self.Get(uri, converter=gdata.docs.DocumentListFeedFromString)
  File /usr/lib/pymodules/python2.7/gdata/service.py, line 1068, in Get
headers=extra_headers)
  File /usr/lib/pymodules/python2.7/atom/__init__.py, line 92, in 
optional_warn_function
return f(*args, **kwargs)
  File /usr/lib/pymodules/python2.7/atom/service.py, line 184, in request
return auth_token.perform_request(self.http_client, operation, url, 
AttributeError: 'PKCS12' object has no attribute 'perform_request'


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


Guarding arithmetic

2012-08-23 Thread Mark Carter
Suppose I want to define a function safe, which returns the argument passed 
if there is no error, and 42 if there is one. So the setup is something like:

def safe(x):
   # WHAT WOULD DEFINE HERE?

print safe(666) # prints 666
print safe(1/0) # prints 42

I don't see how such a function could be defined. Is it possible?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guarding arithmetic

2012-08-23 Thread Mark Carter
On Thursday, 23 August 2012 10:16:08 UTC+1, Chris Angelico  wrote:
 On Thu, Aug 23, 2012 at 7:05 PM, Mark Carter  wrote:
  Suppose I want to define a function safe, which returns the argument 
  passed if there is no error, and 42 if there is one. 

 only possible with floating point, not integer.
 
 try:
 print 1/0
 except ZeroDivisionError:
 print 42

OK, so it looks like a solution doesn't exist to the problem as specified. I 
guess it's something that only a language with macros could accommodate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guarding arithmetic

2012-08-23 Thread Mark Carter
On Thursday, 23 August 2012 10:23:20 UTC+1, Laszlo Nagy  wrote:
 On 2012-08-23 11:05, Mark Carter wrote:

 You are very vague. There is an error - but what kind of error?

Assume that it doesn't matter.


 In some special cases, this can be a good idea to do.

Those are the cases that I'm interested in.


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


Looking for a urllib(2) cookie handler

2011-04-19 Thread Mark Carter
I'm in python 2.6.5, and have Firefox 3.6.13. I would like to download
some html from a site and scrape it programatically. The site requires
a cookie, which I have in Firefox.

Is there a simple python recipe I can use to read the contents of a
url and say just use the cookie that I have in Firefox?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a urllib(2) cookie handler

2011-04-19 Thread Mark Carter
On Apr 19, 12:44 pm, Mark Carter alt.mcar...@gmail.com wrote:

 url and say just use the cookie that I have in Firefox?

mechanize looks kinda like what I want, but i still can't get it to
work properly. So far I have:

import cookielib
import mechanize

cookiefile = C:\\Users\\$ME\\AppData\\Roaming\\Mozilla\\Firefox\
\Profiles\\zl648qvt.default\\cookies.sqlite
cookies = mechanize.MozillaCookieJar(filename = cookiefile,
delayload=True)
#cookies = cookielib.MozillaCookieJar()
#cookies = cookielib.MSIECookieJar()
#cookies.load_from_registry()  # finds cookie index file from registry
br = mechanize.Browser()
br.set_cookiejar(cookies)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-
US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
url = $URL
r = br.open(url)

#print cj
#opener =
mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))


html = r.read()
print html

where $ME and $URL are replaced with suitable values. It doesn't
appear to acutally be using the cookies.
-- 
http://mail.python.org/mailman/listinfo/python-list


wx.Frame hidden, and customising the close button

2011-02-11 Thread Mark Carter
Is there a way of testing whether a frame (suppose I have it as a
variable my_frame) is hidden in wxPython?

Also, is there a way that I can over-ride the close button so that the
frame becomes hidden rather than destroyed, and perform supplementary
tests?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wx.Frame hidden, and customising the close button

2011-02-11 Thread Mark Carter
On Feb 11, 1:39 pm, Vlastimil Brom vlastimil.b...@gmail.com wrote:
 (wxPython-specific questions may be rather discussed  on that 
 maillist:http://groups.google.com/group/wxpython-users/topics?pli=1

Just the ticket! Many thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Printing RTF file under win32

2011-01-21 Thread Mark Carter
I'm using Python 2.6.5 on win32. I would like to print a batch of RTF
files on a printer. I don't want to use the win32api.ShellExecute
command because that invokes Word, and Word has been configured in a
strange way by one of our admins, making it inconvenient to use.

What should I do?
-- 
http://mail.python.org/mailman/listinfo/python-list


wx Just Print!

2011-01-14 Thread Mark Carter
I'm using Python 2.6.5. I would like to be able to print an RTF file,
with no prompts for printers or anything like that.

Here's the code so far:
import wx.richtext
rtp = wx.richtext.RichTextPrinting()
rtp.PrintFile('C:\\path\\to\\file.rtf')

When I run it, it says: ... assert (wxThePrintPaperDatabase*) NULL)
failed ...

What is the fix?
-- 
http://mail.python.org/mailman/listinfo/python-list


Python scripts from DOS

2010-07-09 Thread Mark Carter
On my machine, I can go to a DOS shell, and type
   myscript.py
This will cause the script to be run as a python script. So that bit
works.

On another machine, on which python was set up without admin
privileges, if I type
   myscript.py
it will open the Open With dialog box. It wont let me execute it
with python.exe. It asks me the same question every time, too. If I
type
   python myscript.py
then everything works fine.

Is there a way of setting up the other machine so that it replicates
the behaviour of my machine?
-- 
http://mail.python.org/mailman/listinfo/python-list


win32com sql update problem

2010-05-11 Thread Mark Carter
Consider the following snippet of code:

import win32com.client

DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=M:\\Finance\\camel\
\camel.mdb;'
conn.Open(DSN)
cursor = conn.Execute(UPDATE tblInvoice SET InvComments='Python'
WHERE InvBillingPeriod = 'April 2010' AND InvJobCode = '2169')
rows = cursor.Affected_Rows()
print rows
conn.Close()

I am using Python 2.6.5, and pywin32. If I try to run it, I get the
response:
Traceback (most recent call last):
  File C:/Users/mcarter/tacc/pypms/post.py, line 79, in module
AdjustPms(d)
  File C:/Users/mcarter/tacc/pypms/post.py, line 64, in AdjustPms
cursor = conn.Execute(UPDATE tblInvoice SET InvComments='Python'
WHERE InvBillingPeriod = 'April 2010' AND InvJobCode = '2169')
  File COMObject ADODB.Connection, line 3, in Execute
  File C:\Python26\lib\site-packages\win32com\client\dynamic.py,
line 272, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
u'Microsoft JET Database Engine', uCannot open database ''.  It may
not be a database that your application recognizes, or the file may be
corrupt., None, 5003049, -2147467259), None)

I have used the same DNS to retrieve data from the database using
SELECT statements, so I'm at a loss to figure out what's going wrong.
It seems to think the database name as an empty string. I'm not sure
if that's the root cause of the problem, though. Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Install 2.6.4 as non-admin on Windows

2010-03-18 Thread Mark Carter
How do I install python 2.6.4 on Windows without admin privileges?

Can I install it on a machine I control, zip up the contents, copy it
across to an admin-restricted machine, and set up a couple of
environemtn variables? Does python install files to system
directories, making this impossible?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Install 2.6.4 as non-admin on Windows

2010-03-18 Thread Mark Carter
On 18 Mar, 15:23, egl...@gmail.com egl...@gmail.com wrote:
 The only file written to a system folder is python2x.dll (I think it's
 not true for python2.6 any longer), so your approach is perfectly
 valid if you can put this dll into a folder where it can be found by
 the system.

Thanks. That sounds easy enough to do. I guess it's the same deal with
win32all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting started with OS X Leopard

2008-03-15 Thread Mark Carter
One thing I really liked about Ubuntu was that Nautilus allowed you to 
add scripts to a directory which could be accessed via the RMB. It was a 
very simple thing to do.

I've recently switched to Leopard, and I'm trying to do the same thing. 
I'm fairly experienced with Python, but new to OS X. I have installed 
FinderPop, which lets me add scripts and make them accessible via 
Contextual Menus, but it is not as easy as the Nautilus way.

The sorts of things I want to do are:
* copy the directory of Finder to the clipboard
* add a new file to Finder's directory.
* find out the size of a directory
* open a file with Aquamacs, regardless of file type,

My head's swimming, though. Anyone got any really good pointers and 
sample scripts that will help me work out how to achieve the sorts of 
things I'm trying to do?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting started with OS X Leopard

2008-03-15 Thread Mark Carter
has wrote:
 On 15 Mar, 18:05, Mark Carter [EMAIL PROTECTED] wrote:
 The sorts of things I want to do are:
 * copy the directory of Finder to the clipboard
 * add a new file to Finder's directory.
 * find out the size of a directory
 * open a file with Aquamacs, regardless of file type,
 
 If you want to control desktop applications directly, that generally
 means using Apple event IPC. The most popular language for application
 scripting is traditionally AppleScript, but Apple event bridges exist
 for other languages as well. The best of these is appscript; see my
 sig for links. Some Finder scripting examples:
 
 
 #!/usr/bin/python
 
...
 Control AppleScriptable applications from Python, Ruby and ObjC:
 http://appscript.sourceforge.net


Aah! Many thanks. I see that I had to do
easy_install appscript
and ensure I use /usr/bin/python
I'm off to play with it now. Exciting stuff.

I installed the Python from MacPorts. That's not quite what I wanted, 
because they only have a version for Python 2.4. *Sigh*. MacPorts seems 
to be getting new ports all the time. The problem is, there also seems 
to be an aweful lot of ports gathering bitrot.

Am I the only one to form the opinion that OS X can sometimes appear to 
be a bit of a mish-mash?

I tried XCode the other day. Seemed a bit complicated, if you ask me. 
I've tried to like Lisp, too. In the end, Python just rocks. I started 
out with Glade a short while ago, and I'm impressed how relatively easy 
it is to create GUIs and add handlers in Python.


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


Re: Getting started with OS X Leopard

2008-03-15 Thread Mark Carter
Arnaud Delobelle wrote:

 Is there a particular reason you want python from MacPorts? OSX
 Leopard comes with python 2.5, that's what I use on my mac.

I heard from somewhere that Apple's version was a bit wonky, and that I 
would be better off with a proper build.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting started with OS X Leopard

2008-03-15 Thread Mark Carter
[EMAIL PROTECTED] wrote:
 if you are not satisfied with the native version, why not install the
 official version directly from python site
 http://www.python.org/download/ (macpython) instead of using that of
 macports. It moreover is provided with many utilities
 
 There is a macpython list that you can consult at
 http://www.nabble.com/Python---pythonmac-sig-f2970.html

Thanks.

Actually, I created my first python appscript (well, stole it from a 
previous poster is more like it) - and it's pretty cool when I combine 
it with FinderPop.
-- 
http://mail.python.org/mailman/listinfo/python-list


sqlite3 bug??

2007-06-17 Thread mark carter
I hesitate to ask, but ...

I'm using Ubuntu Feisty:
* Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
* SQLite version 3.3.13

Suppose I run the following program:
import sqlite3

conn = sqlite3.connect('example')


c = conn.cursor()

# Create table
c.execute('''create table stocks
(date text, trans text, symbol text,
  qty real, price real)''')

# Insert a row of data
c.execute(insert into stocks
   values ('2006-01-05','BUY','RHAT',100,35.14))

and then I go into sqlite:
% sqlite3 example
sqlite3 select * from stocks ;

It returns 0 rows. I'm in the right directory. I have experienced this 
problem with some other sqlite3 database work I have done with python, 
so I'm figuring there is something fishy going on. I've tried doing 
similar exercises with Ruby, and they have worked OK.

Anyone else getting these problems?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 bug??

2007-06-17 Thread mark carter
David Wahler wrote:
 On 6/17/07, mark carter [EMAIL PROTECTED] wrote:

 Anyone else getting these problems?
 
 See http://www.python.org/dev/peps/pep-0249/ (emphasis mine):
 
.commit()

OK, I tried that, and I appear to be cooking. The funny thing is, I 
could have sworn that I tried that a few days ago, and it didn't work. 
Weird. Appears to be working now, though, so I guess I must have been 
doing something kooky.

Should I also explicitly close the cursor and connection, or is that 
taken care of automagically?

I'm seriously thinking about reporting the commit() thing as a doc bug 
in python, as this isn't mentioned at
http://docs.python.org/lib/module-sqlite3.html
and I think it's exactly the kind of thing that should be mentioned in 
the examples.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 bug??

2007-06-17 Thread mark carter
7stud wrote:
 On Jun 17, 7:16 am, mark carter [EMAIL PROTECTED] wrote:
 David Wahler wrote:
 On 6/17/07, mark carter [EMAIL PROTECTED] wrote:
 Anyone else getting these problems?
 Seehttp://www.python.org/dev/peps/pep-0249/(emphasis mine):
.commit()


 I'm seriously thinking about reporting the commit() thing as a doc bug
 in python, as this isn't mentioned at
  http://docs.python.org/lib/module-sqlite3.html
 and I think it's exactly the kind of thing that should be mentioned in
 the examples.
 
 Please report the whole docs as a bug.

http://sourceforge.net/tracker/index.php?func=detailaid=1738670group_id=5470atid=105470

That will save a few people tearing their hair out!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 bug??

2007-06-17 Thread mark carter
Carsten Haese wrote:
 On Sun, 2007-06-17 at 07:43 -0700, 7stud wrote:
 Please report the whole docs as a bug.
 
 I imagine the author appreciates constructive criticism. This is not
 constructive criticism.
 
 In other words: Pointing out specific shortcomings and ways to correct
 them, such as what the OP is doing, is helpful. Calling the entire docs
 a bug is not helpful.

You'll be pleased to know that I was specific, and I suggested a change 
that I thought would be good.

Actually, I think the docs are quite good! I went hunting around some 
Scheme implementations lately. What was immediately apparent to me was 
that the docs weren't nearly as good as those for python. Typical 
problems centre about what modules I was supposed to load, and how I was 
supposed to use them. What might be obvious to an old hand might not be 
obvious to someone coming in from fresh. This is where big projects like 
Python tend to score - the docs have been through many iterations.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Working with fixed format text db's

2007-06-08 Thread Mark Carter
Neil Cerutti wrote:

 The underlying problem, of course, is the archaic flat-file
 format with fixed-width data fields. Even the Department of
 Education has moved on to XML for most of it's data files,

:(

I'm writing a small app, and was wondering the best way to store data. 
Currently the fields are separated by spaces. I was toying with the idea 
of using sqlite, yaml or json, but I think I've settled on CSV. Dull, 
but it's easy to parse for humans and computers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Who uses Python?

2007-06-04 Thread Mark Carter
walterbyrd wrote:

 Anything else? Finance? Web-analytics? SEO? Digital art?

I played with NodeBox a little while ago:
http://nodebox.net/code/index.php/Home
NodeBox is a Mac OS X application that lets you create 2D visuals 
(static, animated or interactive) using Python programming code and 
export them as a PDF or a QuickTime movie. NodeBox is free and 
well-documented.

Pretty trippy stuff.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Who uses Python?

2007-06-04 Thread Mark Carter
Thomas Jollans wrote:

 Broadly speaking, everyone who uses python programs in it and may thus be 
 considered a programmer. 

A woman from a job agency 'phoned me up the other day, and asked me if I 
was any good with algortihms. I told her that all programs are 
algorithms, so the question didn't make that much sense.

Needless to say, I wasn't offered an interview ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python rocks

2007-06-03 Thread Mark Carter
Alex Martelli wrote:
 Mark Carter [EMAIL PROTECTED] wrote:

 Yes, GMP is a pain to compile (especially on Mac OS X), but I believe

 Just mentioning this in case you want to give Scheme another chance

Thanks. I'll take a look at it.

I think I've decided to finish off my little in project in Python first, 
though. I'd like to actually get it done (!). I may well decide to 
reimplement bits in either Scheme, or I might try my hand at Forth. My 
app will be small enough to permit re-writes.

I had actually done a small 3-month Java project professionally about 7 
years ago. Can't say I was too impressed. IMO, it was too verbose, I'm 
not an OO fanatic, and some immutable strings turned out to be not quite 
as immutable as I expected.

I had a brief toy around with Java using Xcode very recently, and I was 
able to figure out how to download webpages easy enough (I do this to 
scrape stock quotes). I felt fairly confident that I could achieve what 
I wanted in Java, even though I'm fairly raw with it. I started from a 
default project using Xcode, and it seemed to generate a lot of base 
code. I quickly abandoned the Java idea, as I'm not gunning to be a Java 
developer, and Python seems to do what I want without fuss.

I think that's the key to Python. You can do what you want without fuss, 
and it's copiously documented.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python rocks

2007-06-03 Thread Mark Carter
Alex Martelli wrote:
 Josiah Carlson [EMAIL PROTECTED] wrote:
 
 pitfall of Python is knowing whether an operation is destructive or not.
 If it returns None, it probably changes the content of an object.
 
 A reasonable heuristic, but with lots of exceptions, alas:
 somedict.get(somekey)
 will often return None without performing any change, while
 somelist.pop()
 does modify somelist but typically returns non-None.
 
 The use of trailing-exclamation-point (by convention) to indicate
 mutating methods is a nice plus in languages that allow it.

Actually, that'd be nice to have in Python. And whilst we're about it, 
might as well go the whole hog and allow hyphens in names, too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python rocks

2007-06-02 Thread Mark Carter
Well, I know I'm preaching to the converted - but Python rocks.

I've been enchanted by the siren calls of Scheme, Lisp and Forth, but in 
the end, I find Python much easier. I even tried a little bit of Tcl.

To give a bit of context ... I have recently switched from Windows to OS 
X and Linux. I missed MS Money, but couldn't get on with GnuCash. So I 
decided to write my own little home-brew money management program that 
includes things like downloading share price info from Yahoo Finance.

I picked Chicken Scheme for OS X. Things started well, and even the web 
download and regex stuff worked fairly painlessly. I wanted to work with 
dates, and decided that I needed the SRFI-19 library. Chicken has 
eggs, which you can download and install. The problem is that it 
needed further dependencies. Well, no need to panic just because of 
that; but I found that it ultimately depended on gmp, which turned out a 
pain to compile.

Other languages seem to have neat ideas; like closures or macros in 
Scheme, or ultra-simple syntax like Forth. But what I have generally 
found is that other languages seem to require too much pain for too 
little return. I just seem to be way more productive in Python than in 
any other language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python rocks

2007-06-02 Thread Mark Carter
Steve Howell wrote:
 --- Mark Carter [EMAIL PROTECTED] wrote:
 
 Well, I know I'm preaching to the converted - but
 Python rocks.
 [...]
 
 A few questions from the choir:
 
 As a recent newcomer to the language, did you
 encounter any traps or pitfalls while you were
 learning?  Also, could you single out anything in
 particular about Python that started making you more
 productive, or was it just the overall design?

Well, I've been around the block a few times with Python, and had 
decided to try a couple of other languages. Having poked around, I've 
come to the conclusion that Python is the best language out there, and 
thought I'd share my observation with everyone. I hadn't posted to Lisp, 
because that'd be, like, considered trollish.

Python's biggest win is probably its batteries included philosophy. 
Plus its extensive documentation. IDLE is simple, but it gets the job 
done. The syntax is obvious enough, so there's not much to dislike about 
Python.

Not that I'm particularly knowledgeable about language design issues, 
but maybe closures and slightly different scoping rules would be nice. A 
pitfall of Python is knowing whether an operation is destructive or not. 
I guess if it was a purely functional language, that particular question 
wouldn't arise. Not that I'm saying I want Python to be a purely 
functional language. Oh, and when I read a line, I'd like it to get rid 
of the trailing line-ending characters.

Python is accreting  a lot of language features, and I'm not sure that's 
a good idea. Still, I guess if I don't like them, I don't have to use them.

The thing about Lisp I found is that it's horribly fragmented, and 
doesn't do what I want it to do out of the box. Lisp is just too 
tedious. Python Just Works. I checked out Ruby a couple of years ago, 
but couldn't find anything to be worth the switch. I'm amazed at some of 
the things people have been able to do in Forth; but then, it doesn't 
beat Python's truckload of libraries and stuff like dictionaries, lists 
and other goodies that I get out of the box.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python rocks

2007-06-02 Thread Mark Carter
Josiah Carlson wrote:
 Mark Carter wrote:
 Not that I'm particularly knowledgeable about language design issues, 
 but maybe closures and slightly different scoping rules would be nice.
 
 Python has had closures for years.

I just looked up
http://www.secnetix.de/~olli/Python/lambda_functions.hawk
and was amazed to discover that you were right. Nice one.


  What kind of scoping did you desire?

Well, I had in mind so that if you defined a function, but wanted to 
access a global var, that you didn't have to use the global keyword. Not 
much of a biggie, I guess.

 Refuse the temptation to guess.  As many people want to keep the 
 newlines as not (it disambiguates the case of end of file and blank 
 line), and it is a simple thing to deal with: line.rstrip('\r\n') .

I guess that about wraps it up, then. Python pretty much has it all. 
Except for macros - which is not necessarily a dealbreaker, anyway.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-22 Thread Mark Carter
Mark Carter wrote:

 At the risk of being labelled a troll

One thing I just discovered, and by which I mean *really* discovered ... 
is that Lisp is an interactive environment. I am working on trying to 
verify the contents of disks. I noticed that the input formats are 
slightly wrong, and needed correction. In fact, there's a whole host of 
jiggery pokery that I need to do in order to massage and build up 
everything the way it needs to be.

A programmers mindset is usually geared towards writing applications. 
What I'm currently doing in Lisp is building up functions as I need 
them. Using emacs, I can just C-x C-e to make my functions live, and 
when it's time to stop for the day, save my working image so that I can 
use it the next day.

It seems to me that only Forth or Scheme really matches this capability. 
Ruby and Python come kinda close - they do have a REPL, but it's kinda 
clunky to try to create functions on the fly, plus of course they don't 
support the idea of an image.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-20 Thread Mark Carter
I'd like to propose a coding challenge of my own. The challenge is to 
reproduce the TEA (Tiny Encryption Algorith):
http://www.simonshepherd.supanet.com/tea.htm
in your language of choice.

Here's the code, just two simple functions:

void encipher(unsigned long *const v,unsigned long *const w,
const unsigned long *const k)
{
register unsigned long   y=v[0],z=v[1],sum=0,delta=0x9E3779B9,
a=k[0],b=k[1],c=k[2],d=k[3],n=32;

while(n--0)
   {
   sum += delta;
   y += (z  4)+a ^ z+sum ^ (z  5)+b;
   z += (y  4)+c ^ y+sum ^ (y  5)+d;
   }

w[0]=y; w[1]=z;
}

void decipher(unsigned long *const v,unsigned long *const w,
const unsigned long *const k)
{
register unsigned long   y=v[0],z=v[1],sum=0xC6EF3720,
delta=0x9E3779B9,a=k[0],b=k[1],
c=k[2],d=k[3],n=32;

/* sum = delta5, in general sum = delta * n */

while(n--0)
   {
   z -= (y  4)+c ^ y+sum ^ (y  5)+d;
   y -= (z  4)+a ^ z+sum ^ (z  5)+b;
   sum -= delta;
   }

w[0]=y; w[1]=z;
}

I had a crack at it in Lisp. My version doesn't work - but of greater 
concern to me is that it doesn't appear nearly as compact as the C 
version. Anyway, here's my Lisp code (no prizes for guessing that I'm a 
noob to Lisp):

(defconstant delta 2654435769 ) ; delta= 0x9E3779B9

(defun floorn (n) (nth-value 0 (floor n)))

(defun  (val num-bytes)
   Right-shift positive integer val by num-bytes
   (let* (t1 t2)
 (setf t1 (expt 2 num-bytes))
 (setf t2 (/ val t1))
 (floor t2)))

(defun  (val num-bytes)
   Left-shift positive integer v by num-bytes
   (* val (expt 2 num-bytes)))

(defun 4 (i) ( i 4))

(defun byte-n (v n)
   Return the nth byte of a value v
   (let* ((bits-to-shift (* 8 (1- n)))
 (shifted-value ( v bits-to-shift)))
 (logand shifted-value 256)))


(defun transform (v1 v2 v3 v4)
   (let (t1 t2 t3)
 (setf t1 (4 v1))
 (setf t2 (expt v2 v1))
 (setf t3 (expt v3 ( v2 5)))
 (+ t1 t2 t3 v4)))

(defun pack64 (b1 b2) (+ ( b1 32) b2))

(defun encipher (v k)
   (let ((sum 0)
(a (byte-n k 3))  ; a=k[0]
(b (byte-n k 2))  ; b=k[1]  
(c (byte-n k 1))  ; c=k[2]  
(d (byte-n k 0))  ; d=k[3]  
(y (byte-n v 1))  ; y=v[4]  
(z (byte-n v 0))) ; z=v[1]


 (loop for n from 0 to 31 do  ;n=32, while(n--0)
  (incf sum delta);sum += delta;
  (incf y (transform z a sum b)) ; y += (z  4)+a ^ z+sum ^ (z  5)+b
  (incf z (transform y c sum d)) ;z += (y  4)+c ^ y+sum ^ (y  5)+d;
  )

 (pack64 y z) ; w[0]=y; w[1]=z;
 ))


(defun decipher (v k)
   (let ((sum 3337565984)  ; 0xC6EF3720
(a (byte-n k 3))  ; a=k[0]
(b (byte-n k 2))  ; b=k[1]  
(c (byte-n k 1))  ; c=k[2]  
(d (byte-n k 0))  ; d=k[3]  
(y (byte-n v 1))  ; y=v[4]  
(z (byte-n v 0))) ; z=v[1]

 (loop for n from 0 to 31 do  ;n=32, while(n--0)
  (decf z (transform y c sum d)) ;z -= (y  4)+c ^ y+sum ^ (y  5)+d;
  (decf y (transform z a sum b)) ;y -= (z  4)+a ^ z+sum ^ (z  5)+b;
  (decf sum delta);sum -= delta;
  )

 (pack64 y z) ; w[0]=y; w[1]=z;
 ))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-20 Thread Mark Carter
Mark Tarver wrote:
 Interesting.

At the risk of being labelled a troll, one thought that is occuring to 
me is that in Lisp it seems that sometimes it is difficult to achieve a 
simple thing in a simple way.  To clarify ... recently, I had been 
trying to obtain md5 hashes of the files we had on our server (a 
different exercise than the one I mentioned in my OP, just in case you 
thought that I didn't understand the difference between encryption and 
hashing). There is an md5 package for Lisp available on the web, which I 
used with CLISP. I had a file that contained a non-standard character, 
causing CLISP to throw an error when it tried to print it.

Well, I suppose I could have tried to figure out a way to cajole CLISP 
into printing something it didn't want to print, but I was keen to give 
Corman Lisp 2.5 a try-out anyway, so I tried the package on it. EXCEPT, 
for some reason when you try to read a file with an :element-type  of 
(unsigned-byte 8) (or something similar), Corman didn't like it.

In the end, I hacked together an md5 DLL from some sources I found on 
the internet. You can get the package here, together with Corman Lisp 
bindings:
http://www.markcarter.me.uk/computing/freeware/md5mc/md5mc.htm

In the past, I had also employed a similar technique in order to get 
access to some console functions that I was interested in.

My worry is that it seems to be a recurring theme with me ... get 
stumped in Lisp, realise that it is probably just plain easier in C, and 
then link the whole thing together in Lisp. Which is kinda less than 
expected.

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


Windows and python execution

2005-12-26 Thread Mark Carter
What I would like to do it type something like
  myscript.py
instead of
  python myscript.py
on a Windows console. I know its possible because Ruby scripts manage to 
do this - I just don't know the registry settings that need to be 
tweaked to enable it. Any ideas (I'd prefer to know the registry 
settings rather than a graphical way to accomplish the goal)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows and python execution

2005-12-26 Thread Mark Carter
rzed wrote:
 Mark Carter [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]: 
 
 
What I would like to do it type something like

myscript.py

instead of

python myscript.py

 As another poster points out, be sure that your Python is on your 
 path. 
 
 And there is a PATHEXT environment variable, 

Aha. You'bve provided a significant clue.

What you need to do is include the following line in autoexec.bat:
set .py=c:\python24\python.exe

This will achieve the desired result. I'm suprised more people don't use it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows and python execution

2005-12-26 Thread Mark Carter
BartlebyScrivener wrote:
 The installer can put python.exe in his PATH but if he's storing his
 scripts in some oddball place then he has to tell Windows where to find
 them.

I think you're misunderstanding what I was after. python.exe is already 
in my PATH. What I was trying to do was execute a  python script without 
having to type the word python explicitly. For that, you need the 
set command that I listed in a previous post. Anyway, I want to be 
able to put my scripts in oddball places, as they form part of 
separate projects rather than a generally-runnable script. It doesn't 
matter to me that Windows cannot find the script itself - because I just 
go to the directory where's it's at.

The upshot is that my original problem has now been solved, and that 
discussing the matter further will only likely confuse the issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows and python execution

2005-12-26 Thread Mark Carter
Bengt Richter wrote:

And there is a PATHEXT environment variable, 

Aha. You'bve provided a significant clue.

What you need to do is include the following line in autoexec.bat:
set .py=c:\python24\python.exe

This will achieve the desired result. I'm suprised more people don't use it.
 
 I wasn't aware of that syntax for set. What OS/platform/shell is that from?

Windows XP, bog-standard default shell. UNIXers have it easy because 
they can use the normal shebang.

 How did you go from the PATHEXT clue to the set command you specify 

I can't remember. It was a bit of luck, I think. I happened upon:
http://www.jpsoft.com/help/index.htm?exeext.htm
probably as a result of Googling for PATHEXT.

 and decide
 not to set pathext, e.g., by something like
 set PATHEXT=%PATHEXT%;.py
 Does your set do the pathext and assoc and ftype all in one swell foop?

Actually, I haven't figured out what PATHEXT is actually supposed to 
do. It seemed to me that Windows couldn't possibly know that a py file 
should be started by python.exe, whereas my
set .py= ...
would.

I had installed python 2.4 in the standard way, so py files were already 
associated with python when you double-clicked them from Explorer. Using 
my set meant that if I wanted to use py files from the command line, I 
could just type out the script name (you have to be in the right 
directory, of course), and it works. Here's a snippit from my 
autoexec.bat files:
set PATH=C:\python24;%PATH%
set .py=c:\python24\python.exe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows and python execution

2005-12-26 Thread Mark Carter
rzed wrote:

 I should have asked which Windows version you had.

XP Pro

  My bad. On Win2k
 or XP, adding .py (for instance) to the PATHEXT variable means that 
 you can execute myNeatProgram.py with this command-line:
 promptmyNeatProgram

Oh, now I see! It's beginning to make sense to me. I'll have to try that 
out. Thanks for the tip.
-- 
http://mail.python.org/mailman/listinfo/python-list


Passwords in cron scripts

2005-12-24 Thread Mark Carter
I have some python scripts that run as cron jobs. They connect to 
external resources (like a newsserver) - for which passwords are 
required. I currently have them stored in the scripts themselves (ouch!) 
- and was wondering if there was a more secure solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Xah's Edu Corner: Responsible Software Licensing

2005-12-17 Thread Mark Carter
robic0 wrote:

 Xah, please admit to me that your under the influence of 
 physocopic drugs!  

He could be schizophrenic.

Seekers of all things wierd on the internet can do no better than Gene 
Ray's Timecube:
http://www.timecube.com/

His outpourings are so well known that he even gets a mention in the 
wikipedia:
http://en.wikipedia.org/wiki/Gene_Ray

And once you've fully absorbed the fact that You are educated as a 
stupid android slave to the evil Word Animal Singularity Brotherhood, 
why not play the game of the theory over at:
http://atrocities.primaryerror.net/timecube.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Web functions idea

2005-11-29 Thread Mark Carter
I was musing recently about how one could, for example, set up a really 
simple mailing subscription list. It occurred to me that a really simple 
way to implement it would be to use xmlrpc.
So there could be a function
subscribe(emailAddress),
which would send an email for confirmation, and another function
confirm(emailAddress, password)
which would confirm the address ... and so on.

Now, the problem is that, if you use xmlrpc, it requires some kind of 
fiddly software that the client would have to install. What you would 
really want is some kind of web interface instead of xmlrpc - a kind of 
web driven xmlrpc (that would eliminate the need of an actual xmlrpc 
server).

The point of it being this: a developer would just write the functions 
that he needed, a la xmlrpc, which would be exposed to this new module 
(let's call it webrpc) - and webrpc would examine the function, work out 
how many arguments it had, and display a form for the user to fill out. 
 From an application writer's point-of-view, it abstracts away the whole 
web process, leaving him free to just concentrate on the underlying 
function implementation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web functions idea

2005-11-29 Thread Mark Carter
bruno at modulix wrote:
 Mark Carter wrote:

 Congratulations, you've just rediscovered REST !-)

Huzzah!

 Turbogears is probably what you're looking for (if not quite what you
 describe).

Thanks. It looks quite interesting.

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


ANN: sharep 0.2 - share price downloader module

2005-11-09 Thread Mark Carter
sharep is a Public Domain python module for downloading share prices
from the internet. Currently only UK shares are supported. Feel free to
submit support for other countries.

News
08-Nov-2005 Version 0.2 released  - updates for changes to Yahoo site
21-Dec-2004 Version 0.1 released

Example
   # download bid and ask price for Glaxo Pharmaceuticals; symbol 
name GSK
   import sharep.uk
   sharep.uk.bid('GSK')
'1,184.00'
   sharep.uk.ask('gsk')
'1,186.00'

Webpage:
http://www.markcarter.me.uk/computing/python/sharep/sharep.htm

Download:
http://www.markcarter.me.uk/computing/python/sharep/sharep-0.2.zip
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Port blocking

2005-01-11 Thread Mark Carter
Ed Leafe wrote:
On Jan 10, 2005, at 8:00 PM, Steve Holden wrote:

There isn't, IMHO, anything with the polish of (say) Microsoft Access, 
or even Microsoft SQL Server's less brilliant interfaces. Some things 
Microsoft *can* do well, it's a shame they didn't just stick to the 
knitting.

shameless plugThough it's certainly not anywhere near the polish 
of Access, you should check out Dabo.
Thanks. I'll look into it.
--
http://mail.python.org/mailman/listinfo/python-list


Port blocking

2005-01-10 Thread Mark Carter
Supposing I decide to write a server-side application using something 
like corba or pyro.

What's the chance that in big corporations, the client's ports (in both 
 senses of the word: fee-paying, and application) will be blocked, 
thereby immediately scuppering whatever I have written? Has this problem 
ever arisen for anyone?

Also, is there a good tool for writing database UIs?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Mark Carter
Paul Rubin wrote:
Mark Carter [EMAIL PROTECTED] writes:
Supposing I decide to write a server-side application using something
like corba or pyro.

Usually you wouldn't run a public corba or pyro service over the
internet.  You'd use something like XMLRPC over HTTP port 80 partly
for the precise purpose of not getting blocked by firewalls.
Although, when you think about it, it kinda defeats the purposes of 
firewalls. Not that I'm criticising you personally, you understand.

Also, is there a good tool for writing database UIs?

Yes, quite a few.
Ah yes, but is there really? For example, I did a search of the TOC of 
GTK+ Reference Manual:
http://developer.gnome.org/doc/API/2.0/gtk/index.html
for the word data, and there's apparently no widget which is 
explicitly tied to databases. So in GTKs case, for instance, it looks 
like one has to roll one's own solution, rather than just using one out 
of the box.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Port blocking

2005-01-10 Thread Mark Carter
Mark Carter wrote:
Paul Rubin wrote:

Usually you wouldn't run a public corba or pyro service over the
internet.  You'd use something like XMLRPC over HTTP port 80 partly
for the precise purpose of not getting blocked by firewalls.
I'm not sure if we're talking at cross-purposes here, but the 
application isn't intended for public consumption, but for fee-paying 
clients.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can engineers not understand source-code control?

2005-01-04 Thread Mark Carter
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, first visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
Cameron Laird wrote:
 Well *that* certainly made my morning unpleasant.
Then let's see if I can spoil you afternoon, too ...
I was working on a project (that used Excel, alas) that checked the 
daily allocation of oil and gas. The calculations were very complicated, 
and liable to error. I thought it would be a good idea if I serialised 
intermediate calculations so they could be checked. My solution was to 
save them as a CSV file, with array name in the first column, index 
variables in subsequent columns, and array value in the last column. 
That way, they could be checked manually. The standard approach at my 
company would have been to create honking big spreadsheets to house 
these values.

Anyway, time went on, it was decided that these daily calculations 
needed to be aggregated to monthly values. Well, it turned out that the 
solution I had adopted was quite good, because one could just suck the 
file in, read off the relevant variables, and populate an array. To be 
compared with what would normally happen of creating a nexus of links to 
a disk-busting collection of spreadsheets.

I shall have my revenge, though. The file serve hierarchy that we have 
is very complicated, and is due for simplification in the very near 
future. So all those peeps who did spreadsheets, with hard links to 
other spreadsheets, are in for a bit of a surprise. I think the I-Ching 
expressed it better than I ever could:
The bird's nest burns up.
The wanderer laughs at first,
Then must needs lament and weep.
Through carelessness he loses his cow.
Misfortune.

Source:
http://www.eclecticenergies.com/iching/hexagram.php?nr=56
I'm thinking that the I-Ching is a vast untapped resource for 
programming wisdom, plus it makes it funny. Or haikus, maybe they'd be 
good.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can engineers not understand source-code control?

2005-01-04 Thread Mark Carter
Mark Carter wrote:
I'm thinking that the I-Ching is a vast untapped resource for 
programming wisdom, plus it makes it funny. 
Well, carrying on in the same frivilous and some might say off-topic
mood, I did a bit of a Google, and found that you can generate your very
own I-Ching reading:
http://www.grillet.co.uk/iching/
According to the link at:
http://www.grillet.co.uk/iching/casting.html
The I Ching is a good guide in taking decisions when you have no
rational basis on which to take them.  So if your project manager comes
out with something like A pot upturned to empty the decay. The superior
one attends to the Way of Heaven., you'll know whence he's distilling
his madness.
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2005-01-02 Thread Mark Carter
 It might be nice if it was widely understood (in IT) that Python was 
a language any competent
 programmer could pick up in an afternoon

I am a programmer who works for a firm of engineers, where they program 
in VBA, badly. I've often mentioned Python, whereupon I'm usually 
dismissed as a crank. One of them expressed concern that if they used 
Python and I left, then nobody would understand what to do. I could have 
countered that Python is actually quite an easy language to pick up, but 
what's the point.

We might be doing a project which involves web-type stuff. I pointed out 
that if they did, they wouldn't be able to use VB/VBA, and may need to 
use something like Python. I didn't get a reaction from that at the 
time, but no doubt they'll be telling me that I'll have to make Excel 
work through the internet, or something.
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2005-01-02 Thread Mark Carter
Cameron Laird wrote:
 In article [EMAIL PROTECTED],
 Mark Carter  [EMAIL PROTECTED] wrote:
.
[tale of *very*
typical experience
with non-software
engineers]
.
.

Don't start me! Dammit, too late ...
I've noticed that they have an overwhelming obsession with GUIs, too. 
They design wizards for everything. Damn pretty they are, too. Albeit a 
bit flakey. They seem to conflate pretty interfaces with good interfaces 
and good software.

I used to joke that since our software wasn't particularly magical, it 
didn't need wizards. But I think I just ended up sounding bitter.

We once had a bit of software that we thought we'd like to turn into a 
generic application. The focus on improvements was, predictably enough, 
that we should design a GUI that could do anything a client would likely 
to want to do. It was my opinion, though, having seen the very 
special-cases nature required in the original software, that it was 
almost impossible to predict exactly how a customer might want the 
product tailored. I suggested that what they really needed was a library 
(Python would have been good for this, Lisp might have been even better) 
that could be extended as required. GUIs second, functionality first. 
But hey, what would I know. Fortunately, the whole thing's been put on 
the back burner.

And trying to get through to them why source control makes sense, that 
when more than one person works on a project, some form of coordination 
is required, that copying and pasting code is evil, and that Excel 
probably isn't the hammer for every nail.

Honestly, I thought (real) engineers were supposed to be clever.
--
http://mail.python.org/mailman/listinfo/python-list


Which blog tool

2005-01-01 Thread Mark Carter
I currently use python to automatically summarise a certain newsgroup 
daily, and post the findings that it makes. Someone has suggested that 
they would like a to see a blog of the posts. I wondered if there was a 
python tool/library that could automate the blog postings. Any ideas?

Some details:
* the summaries are basically just text files
* I already have a blog at www.blogger.com 
(http://markcarterturriff.blogspot.com/), so I would like to use that if 
possible; although any alternative free one that I can use to achieve my 
objective would be OK, too.
* I do have my own hosted website, which can use perl but not python; 
but I'd rather use a freebie blog site
* the whole thing must be scriptable, because it will run daily. A GUI 
would therefore likely get in the way.
* generating an RSS feed would be nice
--
http://mail.python.org/mailman/listinfo/python-list


Re: Which blog tool

2005-01-01 Thread Mark Carter
Premshree Pillai wrote:
You can use the Blogger API to post to your Blogger account. There's a
Python interface to the API -- PyBlogger -- available here:
http://beetle.cbtlsl.com/archives/category/pyblogger
Hey, it Just Works! I got the whole basic thing working in a few 
minutes. It was exactly what I was looking for. Thanks for the link.
--
http://mail.python.org/mailman/listinfo/python-list