Re: installing 2 and 3 alongside on MS Windows

2012-05-25 Thread Max Erickson
Ulrich Eckhardt ulrich.eckha...@dominolaser.com wrote:

 Hi!
 
 I'm using Python 2.7 for mostly unit testing here. I'm using
 Boost.Python to wrap C++ code into a module, in another place I'm
 also embedding Python as interpreter into a test framework. This
 is the stuff that must work, it's important for production use.
 I'm running MS Windows XP here and developing C++ with
 VS2005/VC8. 
 
 What I'm considering is installing Python 3 alongside, in order
 to prepare the code for this newer version. What I'd like to know
 first is whether there are any problems I'm likely to encounter
 and possible workarounds.
 
 Thank you!
 
 Uli
 
 PS: Dear lazyweb, is there any way to teach VC8 some syntax
 highlighting for Python?
 

One hassle is that .py files can only be associated with one 
program. The proposed launcher works fine for me:

https://bitbucket.org/vinay.sajip/pylauncher/downloads

(I'm not sure that is the most up to date place for the launcher, 
but that's the one I am using)


Max

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


Re: How to convert simple B/W graphic to the dot matrix for the LED display/sign

2012-03-04 Thread Max Erickson
Petr Jakes petr.jakes@gmail.com wrote:

 
 What file format is the graphic in? How big is it?

 What file format do you want it to be?

 
 Now, I am able to create the png file with the resolution 432x64
 using PIL (using draw.text method for example).
 
 I would like to get the 432x64 True/False (Black/White) lookup
 table from this file, so I can switch LEDs ON/OFF accordingly.
 
 --
 Petr
 

The convert and load methods are one way to do it:

 import Image
 im=Image.new('L', (100,100))
 im=im.convert('1')
 px=im.load()
 px[0,0]
0

That's the numeral one in the argument to convert. The load method 
returns a pixel access object.


Max

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


Re: GDAL-1.7.1 : vcvarsall.bat missing

2010-06-25 Thread Max Erickson
kBob krd...@gmail.com wrote:

 On Jun 25, 1:26 am, Mark Lawrence breamore...@yahoo.co.uk
 wrote: 
 On 24/06/2010 21:48, Christian Heimes wrote:

    I am attempting to install the GDAL bindings (GDAL-1.7.1)
  on a Windows XP Desktop with Python 2.6 and GDAL. During
  install, the 

If it suits your needs, you can wire the OSGEO installation of GDAL
to a python.org python installation (rather than a bundled OSGEO
python interpreter, which is another option): 

http://trac.osgeo.org/osgeo4w/

Setting the correct paths was enough to get the basic things I used
to work (but I haven't used it extensively). 

 
  Thanks for the tips, gentlemen.
 
  I'll try my luck with Cygwin's ggc before I look into another
  C/C++ 
 compiler.
 
 Kelly Dean
 Fort Collins, CO

Giovanni Bajo packages a version of MinGW GCC for use with Python:

http://www.develer.com/oss/GccWinBinaries

He does note on the page that the MinGW project isn't quite so sure
that GCC 4.x is ready for release. 


Max

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


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-23 Thread Max Erickson
bartc ba...@freeuk.com wrote:

 
 Scott David Daniels scott.dani...@acm.org wrote in message 
 news:kn2dnszr5b0bwazxnz2dnuvz_s-dn...@pdx.net...
 James Harris wrote:...
 Another option:
 
 It can be assumed however that .9. isn't in binary?
 
 That's a neat idea. But an even simpler scheme might be:
 
 .octal.100
 .decimal.100
 .hex.100
 .binary.100
 .trinary.100
 
 until it gets to this anyway:
 
 .thiryseximal.100
 

At some point, abandoning direct support for literals and just 
having a function that can handle different bases starts to make a 
lot of sense to me:

 int('100', 8)
64
 int('100', 10)
100
 int('100', 16)
256
 int('100', 2)
4
 int('100', 3)
9
 int('100', 36)
1296


max

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


Re: httplib incredibly slow :-(

2009-08-12 Thread Max Erickson
Chris Withers ch...@simplistix.co.uk wrote:
 
 I'm still reeling from what seems to be such a huge problem with
 httplib that seem to be largely ignored :-(
 
 Chris
 

There is an httplib2 (but I don't know anything further about it...):

http://code.google.com/p/httplib2/

Calling wget or curl using a subprocess is probably as easy as it is 
ugly, I use the wget build from here:

http://gnuwin32.sourceforge.net/packages/wget.htm


max

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


Re: Python graphics / imaging library

2009-07-18 Thread Max Erickson
Peter Chant rempete...@cappetezilla.italsco.uk wrote:

 No, it does not.  However, if PIL was updated last in 2006. 
 Python in 2009 has gone to version 3.1.  If PIL is compatible
 with 3.1 then I'm fine.  But I don't want to have to stick with
 Python 2.5 as the rest of the world moves on.
 
 Pete
 
 

Various messages to the Image-SIG mailing list indicate that support 
for 3.x is coming after a release of 1.1.7:

http://mail.python.org/pipermail/image-sig/2009-March/005498.html

More here:

http://mail.python.org/pipermail/image-sig/2009-March/thread.html

More recent months contain updates to the status of 1.1.7, it is 
headed towards a release. Preliminary tarballs and binaries are 
available on effbot.org:

http://effbot.org/downloads/#imaging
http://effbot.org/downloads/#pil


max

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


Re: Delicious API and urllib2

2009-04-07 Thread Max Erickson
Bill bsag...@gmail.com wrote:

 The delicious api requires http authorization (actually https). A
 generic delicious api post url is https://
 username:passw...@api.api.del.icio.us/v1/posts/add?url=http://
 example.com/description=interestingtags=whatever.
 

The simplest way is probably to manually add the authentication 
header, as shown here:

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

This article discusses the above strategy, and a strategy using 
HTTPBasicAuthHandler with a password manager default realm (I think 
getting the realm correct is what has stymied me in my attempts to use 
handlers, rather than injecting the header):

http://www.voidspace.org.uk/python/articles/authentication.shtml 


Max

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


Re: Geometry package

2009-03-29 Thread Max Erickson
Justin Pearson justin.pear...@gmail.com wrote:

 Hi all,
 
 I'm looking for a geometry package in Python; something that will
 let me define line segments, and can tell me if two line segments
 intersect. It would be nice if the lines could be defined in
 n-space (rather than be confined to 2 or 3 dimensions), but this
 is not a hard constraint. Other functionality might include
 support for polygons, convex hulls, etc.
 
 I've searched Pypi and found a package called Shapely, but when I
 followed its installation instructions, it threw a bunch of
 errors and tried to re-install Python :(.
 
 Is there a well-known geometry package I'm missing?
 
 Thanks for your help,
 Justin
 --
 http://mail.python.org/mailman/listinfo/python-list
 

I don't know if it is well known, but you could take a look at 
Euclid:

http://partiallydisassembled.net/euclid.html

The geometry support is pretty basic.


max

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


Re: A different kind of interface

2009-01-23 Thread Max Erickson
bearophileh...@lycos.com wrote:
 Years ago I have found this nice small program, TextCalc:
 http://www.atomixbuttons.com/textcalc/
 
 Despite being very limited and being not integrated with
 everything else, it's so handy that for me in certain situations
 it's the right tool to use when I have to process numbers and
 data in simple ways. It helps me keep all the intermediate
 solutions, you can save the working page just as the text file
 you are seeing, it's passive, it doesn't go bang, so if you
 want you can use it just a primitive text editor. It does
 something only when you ask it to. And for a basic usage there 
 is nearly nothing to remember.
 

This is mostly an aside to your question, but depending on what you
aredoing, Speq Mathematics may be an improvement over TextCalc. The
homepage is at http://www.speqmath.com/index.php?id=1.

The big differences are that it adds a good deal of functionality
(variables, a larger variety of functions, plotting, etc.) and that
it treats plain text as an error (unless the text is marked as a
comment). 


max

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


Re: Flash Decoder

2008-05-28 Thread Max Erickson
Mathieu Prevot [EMAIL PROTECTED] wrote:

 2008/5/28 Diez B. Roggisch [EMAIL PROTECTED]:
 Ankit wrote:

 Hi everyone,i wanted to build a flash decoder using python can
 somebody tell me which library to use and what steps should i
 follow to make a flash(video) decoder?By a decoder i mean that
 i need to display all the pixel values of each frame.Waiting
 for your replies. 

 Check out libffmpeg. It should be accessible using python by
 various means, including gstreamer or ctypes.

 This is however a rather advanced topic.

 Diez
 
 I think you might want make an ffmpeg/libffmpeg python wrap. It
 could be really useful, and faster than a pure python decoder.
 Even for fun. 
 
 Cheers
 Mathieu
 --
 http://mail.python.org/mailman/listinfo/python-list
 
 

It even already exists. There is a binary interface that is 
maintained alongside pyglet:

http://code.google.com/p/avbin/

and then ctypes wrapper for that interface in pyglet:

http://code.google.com/p/pyglet/source/browse/trunk/pyglet/media/avb
in.py
http://www.pyglet.org/doc/programming_guide/sound_and_video.html

I haven't used either one, but it's where I would start.


Max

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


Re: send yield

2008-05-15 Thread Max Erickson
castironpi [EMAIL PROTECTED] wrote:

 Why can't I write this?
 --
 http://mail.python.org/mailman/listinfo/python-list
 
 

Because you don't know how?



max

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


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Max Erickson
Arnaud Delobelle [EMAIL PROTECTED] wrote:

 On May 12, 1:30 pm, John Machin [EMAIL PROTECTED] wrote:
 Duncan Booth wrote:
 [...]
  I think the variant I came up with is a bit clearer:

  for i in range(1,101):
     print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else
  'Buzz') or 
  i

 More than a bit clearer, IMO. How about
      print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or
 i (or perhaps
      print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz'))
 or i to save looking up the precedence rules) ?
 
 Stuff clarity!  How about
 
 for i in xrange(1, 101):
 print 'FizzBuzz'[4*(i%30):4+4*(i%51)] or i
 
 --
 Arnaud
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 
 

With no loop:

i=1
execprint'FizzBuzz'[4*(i%30):4+4*(i%51)]or i;i+=1;*100


max

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

Re: What is the purpose of ptyhon in Windows

2008-05-07 Thread Max Erickson
WolfgangZ [EMAIL PROTECTED] wrote:

 [EMAIL PROTECTED] schrieb:
 hi All,
 http://mail.python.org/mailman/listinfo/python-list
 
 At least I'm living in a free country and nobody forces me to
 learn python. So I don't fully understand why you HAVE TO learn
 it. When your problems can be solved in a different programming
 language than you should be free to use whatever you like. And
 also why should it be forbidden to create a new programming
 language? Diversity and competition is usually not bad.
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 

I imagine that there is some English as a second language getting 
involved and the intent of the question was more like What is 
python useful for on Windows?, which has pretty much the same 
meaning but is open to a slightly friendlier interpretation(i.e., 
tell me how I can use python instead of tell me why I should use 
python).

The other question might be more like I already know VBS, what do I 
gain by learning python?.

(the answers could be lots of things, including full applications 
and among other things, you can use it on other platforms, and you 
might prefer the syntax.)


max

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


Re: ISBN Barecode reader in Python?

2008-05-05 Thread Max Erickson
Nick Craig-Wood [EMAIL PROTECTED] wrote:

 Joseph [EMAIL PROTECTED] wrote:
  All: I have written a program to query Amazon with ISBN and get
  the book details. I would like to extend so that I can read
  ISBN from the barcode (I will take a photo of the same using
  webcam or mobile). Are there any opensource/free SDK doing the
  same? As it is a hobby project, I don't like to spend money on
  the SDK. 
 
 Pick yourself up a cue-cat barcode reader, eg from here or ebay
 
   http://www.librarything.com/cuecat
 
 These appear as a keyboard and type the barcode in to your
 program. 
 
 Cheap and effective.
 

The killer application for ISBN lookup on Amazon is checking prices 
while in the bookstore. Being able to email a photo from your phone  
and then getting an email with the Amazon price in response would be 
way easier than typing the isbn into Google or whatever.


max

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


Re: Python equivalent to PHP's SPL __autoload() ??

2008-04-27 Thread Max Erickson
Ixiaus [EMAIL PROTECTED] wrote:

 I was curious (and have spent an enormous amount of time on Google
 trying to answer it for myself) if Python has anything remotely
 similar to PHP's SPL __autoload() for loading classes on the fly??
 
 After digging through docs I feel doubtful there is such a language
 feature, but, it is possible I missed something or maybe someone has
 written an extension?!?
 
 Thanks in advance!
 --
 http://mail.python.org/mailman/listinfo/python-list
 

If I'm understanding __autoload() correctly, not in the box, but most 
of what you need is built in, you just have to do a little work to use 
it. See the Loading and reloading modules section on this page:

http://effbot.org/librarybook/builtin.htm


max

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


Re: urllib2 Basic authentication, what am I doing wrong?

2008-04-13 Thread Max Erickson
On Apr 13, 2:11 pm, Michel Bouwmans [EMAIL PROTECTED] wrote:

 Using this nice class (adapted to urllib2) as a basehandler I see that no
 Authentication-header is being send 
 out:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440574

 What am I doing wrong here? I spend almost my entire free time today on this
 and couldn't find any problem with my code, anyone else has a thought?
 Thanks in advance.

 MFB

I've attempted to use a password manager and auth manager and failed
in the past, so this is only a guess, but presumably, between the
realm and uri that you are providing to the password manager, it isn't
providing a password for the page you want to load. I've had success
just explicitly setting the authorization header, using the method
discussed in the comments on this page:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267197


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


Re: [ANN]: Python-by-Example updates

2008-04-12 Thread Max Erickson
AK [EMAIL PROTECTED] wrote:

 Python-by-Example is a guide to LibRef, aiming to give examples
 for all functions, classes, modules, etc. Right now examples
 for functions in some of the most important modules are
 included.
 
 http://pbe.lightbird.net/
 
 thanks,
 

The second set of examples on the page for decimal doesn't look quite 
right.

The first couple of lines:

getcontext().prec = 6   # Decimal('3.0')
Decimal(3.0)  # Decimal('3.1415926535')

I would assume that the  = 6 isn't getting processed correctly.


max

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


Re: Mutagen File Problem

2008-03-12 Thread Max Erickson
aiwarrior [EMAIL PROTECTED] wrote:

 Hi i'm having a IO error saying a file does not exist even though
 i perform a isFile() check. Can you help me out figuring what is
 wrong? 
 
 Thanks in advance
 
 from mutagen.easyid3 import EasyID3
 from mutagen.mp3 import MP3
 
 for root, dirs, files in os.walk('''C:\\Documents and
 Settings\\pneves\ \Music\\''', topdown=False):
 for name in files:
 joined = os.path.join(root, name)
 if (name[-3:] == 'mp3' ):
 audio = MP3(joined, ID3=EasyID3)
 if not audio.has_key('album') and
 os.path.isfile(joined):
print os.path.join(root, name)
 
 I get an error as following:
 
 IOError: [Errno 2] No such file or directory: 'C:\\Documents and
 Settings\\pneves\\Music\\Naked Music - Miguel Migs - Colorful
 You\ \Miguel Migs - Colorful you - Full album\\Miguel Migs -
 Colorful you - Cd 2 -Mixed and mastered by J. Mark Andrus\\7 -
 Miguel Migs feat. Lisa Shaw - You Bring Me Up (Main Vocal
 Mix).mp3' 

It looks like the error is happending in MP3(join...), so the 
os.path.isfile check is never reached. If that is the case, 
something along the lines of:

try:
audio=MP3(joined, ID3=EasyID3)
except: #catches any error in MP3...
print joined

should suppress the error and print the filename that triggered it.


max

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


Re: Hyphenation module PyHyphen-0.3 released

2008-02-23 Thread Max Erickson
thebjorn [EMAIL PROTECTED] wrote:
   Visual Studio 2003 was not found on this system. If you have
   Cygwin 
 installed,
   you can try compiling with MingW32, by passing -c mingw32 to
 setup.py.
 -- bjorn

You need to convince MingW to use the correct VS runtime. Cribbing 
from:

http://www.develer.com/oss/GccWinBinaries

the easy way to do this might be to find(in your mingw /lib directory) 
and copy or rename libmsvcr71.a and libmsvcr71d.a into libmsvcrt.a and 
libmsvcrtd.a (backing up the originals if desired). If the MingW you 
have installed doesn't provide the appropriate runtime, you would have 
to track that down.

The MingW/GCC package from the linked page provides a utility to do 
this, but it is a tossup/up to you if the version of GCC provided is 
suitable for 'production' use.


max

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


Re: a newbie regex question

2008-01-25 Thread Max Erickson
Dotan Cohen [EMAIL PROTECTED] wrote:
 Maybe you mean:
 for match in re.finditer(r'\([A-Z].+[a-z])\', contents):
 Note the last backslash was in the wrong place.

The location of the backslash in the orignal reply is correct, it is 
there to escape the closing paren, which is a special character:

 import re
 s='Abcd\nabc (Ab), (ab)'
 re.findall(r'\([A-Z].+[a-z]\)', s)
['(Ab), (ab)']

Putting the backslash at the end of the string like you indicated 
results in a syntax error, as it escapes the closing single quote of 
the raw string literal: 

 re.findall(r'\([A-Z].+[a-z])\', s)
   
SyntaxError: EOL while scanning single-quoted string
 


max


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


Re: Extracting images from a PDF file

2007-12-27 Thread Max Erickson
Doug Farrell [EMAIL PROTECTED] wrote:

 Hi all,
 
 Does anyone know how to extract images from a PDF file? What I'm
 looking to do is use pdflib_py to open large PDF files on our
 Linux servers, then use PIL to verify image data. I want to do
 this in order to find corrupt images in the PDF files. If anyone
 could help me out, or point me in the right direction, it would
 be most appreciated!
 
 Also, does anyone know of a way to validate a PDF file? 
 
 Thanks in advance,
 Doug

There is some discussion here: 

http://nedbatchelder.com/blog/200712.html#e20071210T064608



max

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


Re: Converting Excel time-format (hours since 1.1.1901)

2007-12-07 Thread Max Erickson
Dirk Hagemann [EMAIL PROTECTED] wrote:

 Dirk
 Additional to my last posting: if you want to try this out in
 Excel you should replace the command REST by the english
 command what should be something like remainder.

The equivalent in my (U.S. English, 2000) version of excel is called 
'MOD'.

Also, you have misread or miscopied something, or are encountering 
some very strange issue, as when I put your formula in excel, I get 
the following output:

11/27/2307 7:00


max


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


Re: matching a street address with regular expressions

2007-10-11 Thread Max Erickson
Andy Cheesman [EMAIL PROTECTED] wrote:

 Check out kodos http://kodos.sourceforge.net/ for an interactive
 python regexp tester
 
 Andy
 

On systems with tkinter installed(So pretty much all Windows and lots 
and lots of Linux systems), the redemo.py script in the Tools/Scripts 
directory of the python installation will be a little quicker to get 
running.


max

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


Re: setuptools without unexpected downloads

2007-10-03 Thread Max Erickson
Gabriel Genellina [EMAIL PROTECTED] wrote:
...
 This recent blog post contains step-by-step instructions on using
 free  tools to compile python extensions:  
 http://boodebr.org/main/python/build-windows-extensions
 -- 
...

The package available here:

http://www.develer.com/oss/GccWinBinaries

is quite a lot more straightforward. You do have to be okay with using 
GCC 4.1 though. As a bonus, it supports versions of python that link 
against several different versions of the Microsoft runtime, rather 
than just one.


max

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


Re: Python command line error

2007-05-28 Thread Max Erickson
Mick Duprez [EMAIL PROTECTED] wrote:

 Hi All,
 
 I've installed Python 2.5 on a number of machines but on one I'm
 having problems with the CLI.
 If I fire up the 'cmd' dos box and type 'python' I get a line of
 gibberish and it locks up the cli, if I run the 'command' dos box
 I get a few lines of garbage and it crashes/closes the dos box.
 
 I've tried a re-install, checked my system paths etc but I can't
 get it to work, it works ok for running scripts from a dbl click
 in explorer for instance and from Idle, I just can't run scripts
 from the command line.
 
 I have installed -
 xp pro sp2
 Python25
 wxPython2.8 unicode
 PIL
 numpy
 
 any clues to what's causing this behavior?
 tia,
 Mick.
 

What kind of gibberish? Actual garbage characters and the like?

Anyway, maybe try running which; this one should be easy to get 
going:

http://gnuwin32.sourceforge.net/packages/which.htm

But I have never used it, I use the one in this package:

http://unxutils.sourceforge.net/

It expects 'python.exe' or whatever, not just 'python', I would 
expect the gnuwin32 version to behave similarly.


max


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


Re: Installation of eyeD3 on Windows (newbie)

2007-05-06 Thread Max Erickson
[EMAIL PROTECTED] wrote:

 I would highly appreciate if someone could help me with how to
 proceed (step-by-step) to get started and use the eyeD3 library
 in Windows? 
 
 Many thanks in advance!
 

It appears that you need to do as follows:

Extract the tar.gz to a temporary directory.

rename 'eyeD3-6.13\src\eyeD3\__init__.py.in' 
to 'eyeD3-6.13\src\eyeD3\__init__.py'

run 'python setup.py.in install' from 
the eyeD3-6.13 directory.

(It appears you may have extracted the files into the site-packages 
directory; if so, move them somewhere else before running the 
commands.)

I have just done this and 

from eyeD3.tag import *

completes successfully. There is some reference to a C library in 
the build files, but no importing of it in the source code, so this 
might just make it appear to install but not actually work, I don't 
know. 

The steps I outlined only install the library, the eyeD3 utility is 
not installed. If you want to use it, you need to drop it somewhere 
in your path and give windows some way to find it, by wrapping it in 
a batch file or renaming it to eyeD3.py and making .py files 
executable or whatever.

You might also give mutagen a look, I settled on it last time I went  
looking for an id3 library:

http://www.sacredchao.net/quodlibet/wiki/Development/Mutagen

(I was not using if for writing though)


max

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


Re: Do other Python GUI toolkits require this?

2007-04-20 Thread Max Erickson
Antoon Pardon [EMAIL PROTECTED] wrote:

 On 2007-04-20, Max Erickson [EMAIL PROTECTED] wrote:

 If we are being pedantic about describing a curve that shows the
 progress of a person in learning a topic, there is no arguing
 with you, a steep curve describes fast uptake and is a good
 thing. 

 If we are being pedantic about what a learning curve describes,
 it seems possible that it describes the rate of knowledge uptake
 required to master a given topic, and that such a learning curve
 could exclude people that were unable to take in knowledge at
 that rate(for whatever reason) from mastering that topic, making
 it reasonable to describe such a topic as both 'hard' and
 'having a steep learning curve'.
 
 I must confess I don't follow you here. A rate is a single
 number. Now some second variable can be a function of this rate
 or vice versa but I can't make out what this second variable is
 supposed to be from your explanation.
 

I'm stopping after this because it is offtopic noise, but take a
graph of position vs time for an object; the slope of that graph
happens to be related to the velocity of the object, so you can
'see' the velocity of the object even though the graph is of
position and time. The slope of the graph can be said to describe a
rate. 

(and a graph that showed the movement of the world around that
object would be quite different, and similar lines on those
different graphs would thus elecit rather different descriptions,
which is the point, pretending that all graphs of learning curves
only describe what you assume they describe and then being pedantic
about what information can be inferred from the graphs isn't going
to get you anywhere, hence this thread) 

My english is full of colloquialisms and idioms and I am not
interested in learning Antoon Pardon's Dictionary of Exact Usage,
so I fear that further explanation will be fruitless. 


max

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


Re: Do other Python GUI toolkits require this?

2007-04-20 Thread Max Erickson
Antoon Pardon [EMAIL PROTECTED] wrote:
 Just asserting how something can make a difference withouth
 arguing how in the particular case it actucally makes a
 difference is just a divertion tactic without real merrit.
 
 In the face of a notion that all steep curves determining
 progress made in something must be good I stand with my mouth
 agape. I am aware that common usage does not concur with
 academic rigor, but in this particular instance I'm with the
 common herd. 
 
 Well that notion is entirely yours. My notion was only that
 progres in productivity, earnings and learning was good and thus
 that curves that are to be prefered tend to be the same shape for
 those three subjects. 
 

If we are being pedantic about describing a curve that shows the 
progress of a person in learning a topic, there is no arguing with 
you, a steep curve describes fast uptake and is a good thing.

If we are being pedantic about what a learning curve describes, it 
seems possible that it describes the rate of knowledge uptake 
required to master a given topic, and that such a learning curve 
could exclude people that were unable to take in knowledge at that 
rate(for whatever reason) from mastering that topic, making it 
reasonable to describe such a topic as both 'hard' and 'having a 
steep learning curve'.


max

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


Re: Python Web Servers and Page Retrievers

2007-04-11 Thread Max Erickson
Collin Stocks [EMAIL PROTECTED] wrote:

 --=_Part_19087_21002019.1176329323968
 I tried it, and when checking it using a proxy, saw that it
 didn't really work, at least in the version that I have (urllib
 v1.17 and urllib2 v2.5). It just added that header onto the end,
 therefore making there two User-Agent headers, each with
 different values. I might add that my script IS able to retrieve
 search pages from Google, whereas both urllibs are FORBIDDEN with
 the headers that they use. 
 

I don't know enough about either library to argue about it, but here 
is what I get following the Dive Into Python example(but hitting 
google for a search):

 import urllib2
 opener=urllib2.build_opener()
 request=urllib2.Request('http://www.google.com/search?
q=tesla+battery')
 request.add_header('User-Agent','OpenAnything/1.0 
+http://diveintopython.org/')
 data=opener.open(request).read()
 data
'htmlheadmeta http-equiv=content-type content=text/html; 
charset=ISO-8859-1titletesla battery - Google Search/title
[snip rest of results page]

This is with python 2.5 on windows.


max

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


Re: Python Web Servers and Page Retrievers

2007-04-08 Thread Max Erickson
Subscriber123 [EMAIL PROTECTED] wrote:
 urllib, or urllib2 for advanced users. For example, you can
 easily set your own headers when retrieving and serving pages,
 such as the User-Agent header which you cannot set in either
 urllib or urllib2. 

Sure you can. See:

http://www.diveintopython.org/http_web_services/user_agent.html

(though the behavior was changed for python 2.3 to make setting the 
user agent work better)


max


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


Re: How to find tag to /tag HTML strings and 'save' them?

2007-03-26 Thread Max Erickson
John Nagle [EMAIL PROTECTED] wrote:

 htags = soup.findAll({'h2':True, 'H2' : True}) # get all H2 tags,
 both cases 

Have you been bitten by this? When I read this, I was operating under 
the assumption that BeautifulSoup wasn't case sensitive, and then I 
tried this:

 import BeautifulSoup as BS

 soup=BS.BeautifulSoup('bone/bBtwo/B')
 soup.findAll('b')
[bone/b, btwo/b]
 soup.findAll({'b':True})
[bone/b, btwo/b]
 

So I am a little curious.


max

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


Re: Join strings - very simple Q.

2007-03-24 Thread Max Erickson
7stud [EMAIL PROTECTED] wrote:

 On Mar 24, 8:30 am, Duncan Booth [EMAIL PROTECTED]
 wrote: 
 In case you are feeling that the ','.join(l) looks a bit
 jarring, be aware that there are alternative ways to write it.
 You can call the method on the class rather than the instance:

jl = str.join(',', l)
jl = unicode.join(u'\u00d7', 'l')

... the catch is you need to know
 the type of the separator in advance.
 
 When I try the latter example, I get an error:
 
 lst = [hello, world]
 print unicode.join(u\u00d7, lst)
 
 Traceback (most recent call last):
   File test1.py, line 2, in ?
 print unicode.join(u\u00d7, lst)
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xd7'
 in position 5: ordinal not in range(128)
 

Your terminal is likely the problem. Get rid of the print:

q=unicode.join(u'\u00d7',['hello','world'])

and you will probably get rid of the exception.

(so I guess the issue is the display, not the logic)


max

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


Re: Idiom for running compiled python scripts?

2007-03-20 Thread Max Erickson
Mark [EMAIL PROTECTED] wrote:

...
 #!/usr/bin/env python
 from myprog import main
 if __name__ == __main__:
 main()
 
 Of course this compiles myprog.py into myprog.pyc on first run as
 I am wanting.
 
 I have one of these stubs for all my python scripts I've created
 so far. Is there not a better way? Do I have to create a separate
 stub each time? I find it a bit messy to require a pair of
 scripts for each utility and it also contributes some
 inefficiency. Given the above stub is so boilerplate, why does
 python not provide a general stub/utility mechanism for this?

I don't know of a better way to organize things, but as an 
alternative, you could have a script where you import each of the 
scripts that you want compiled, python will write the compiled files 
to disk when you run it(thus avoiding the need to split the other 
scripts). There are also the py_compile and compileall modules, which 
have facilities for generating byte code.

More here:

http://effbot.org/zone/python-compile.htm

under 'Compiling python modules to byte code'.


max

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


Re: help!! *extra* tricky web page to extract data from...

2007-03-13 Thread Max Erickson
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 How extract the visible numerical data from this Microsoft
 financial web site?
 
 http://tinyurl.com/yw2w4h
 
 If you simply download the HTML file you'll see the data is *not*
 embedded in it but loaded from some other file.
 
 Surely if I can see the data in my browser I can grab it somehow
 right in a Python script?
 
 Any help greatly appreciated.
 
 Sincerely,
 
 Chris
 

The url for the data is in an iframe. If you need to scrape the 
original page for some reason(instead of iframe url directly), you can 
use urlparse.urljoin to resolve the relative url.


max

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


Re: PIL: reading bytes from Image

2007-03-11 Thread Max Erickson
cyberco [EMAIL PROTECTED] wrote:

 Thanks,
 
 I've tried the StringIO option as follows:
 
 =
 img = Image.open('/some/path/img.jpg')
 img.thumbnail((640,480))
 file = StringIO, StringIO()

Is the above line exactly what you tried? If it is, the comma and 
space in the line are likely the problem. Try either:

from StringIO import StringIO 
file=StringIO()

or

import StringIO
file=StringIO.StringIO()

(using file as a variable name can cause issues if you later want 
access to the built in object 'file')

The following:

 import Image
 import StringIO
 im=Image.new('RGB', (100,100))
 fp=StringIO.StringIO()
 im.save(fp, 'jpeg')
 len(fp.getvalue())
823

Works for me on python 2.5 on windows.


max

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


Re: PIL: reading bytes from Image

2007-03-10 Thread Max Erickson
cyberco [EMAIL PROTECTED] wrote:

 I'm using web.py to send an image to the client. This works
 (shortened):
 
 print open(path, rb).read()
 
 but this doesn't:
 
 img = Image.open(path)
 img.thumbnail((10,10))
 print img.getdata()
 
 or
 
 print img.load()
 
 
 How do I get the bytes of the Image object? 'getdata()' seemed the
 way, but unfortunately...
 

getdata() returns the data in a PIL format. Saving the image, in a 
format your client understands, to a file like object like 
StringIO.StringIO is an easy path to take.

Sparklines shows this in action:

http://bitworking.org/projects/sparklines/


max

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


Re: Alternatives for Extracting EXIF and JPEG Data from Images

2007-03-04 Thread Max Erickson
Roger [EMAIL PROTECTED] wrote:

 Does anybody have a pointer to a Python library/utility that will
 extract the chrominance and luminance quantization tables from
 JPG images? 
 
 I have been using the _getexif method from PIL, which works fine,
 but doesn't extract the quantization data.  I am a bit fuzzy on
 the terminology, but the quantization data  seems to be JPEG data
 rather than EXIF data.  One utility that extracts the
 quantization tables is JPEGsnoop -- there is a link to download
 the utility here: 
http://www.impulseadventure.com/photo/jpeg-quantization.html
 
 The source code for the above isn't available and may not be
 callable from a Python script even  if it were available.
 
 Roger
 

I don't know what the format is, etc, but jpegs I open with PIL have a 
quantization attribute, e.g:

 im.quantization
{0: array('b', [6, 4, 4, 5, 4, 4, 6, 5, 5, 5, 6, 6, 6, 7, 9, 14, 9, 9, 
8, 8, 9, 18, 13, 13, 10, 14, 21, 18, 22, 22, 21, 18, 20, 20, 23, 26, 
33, 28, 
snip a bunch more numbers


max

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


Re: PyCon blogs?

2007-02-28 Thread Max Erickson
[EMAIL PROTECTED] wrote:

 Was anybody blogging about PyCon (talks and/or sprints)?  Got any
 pointers? 
 
 Thanks,
 
 Skip

In no particular order:

http://www.nedbatchelder.com/blog/20070226T075948.html
http://www.oreillynet.com/onlamp/blog/2007/02/pycon_day_1_1.html
http://wamber.net/PyCon-2007/


max

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


Re: urllib2 and HTTPBasicAuthHandler

2007-01-16 Thread Max Erickson
m.banaouas [EMAIL PROTECTED] wrote:

 Hi all,
 I started to use urllib2 library and HTTPBasicAuthHandler class
 in order to authenticate with a http server (Zope in this case).
 I don't know why but it doesn't work, while authenticating with
 direct headers manipulation works fine!
 
...
 port':'8080','path':'manage','realm':'Zope'} 
url = '%(prot)s://%(host)s:%(port)s/%(path)s' % data
...

Are you certain that the realm on the server matches 'Zope'?

HTTPBasicAuthHandler uses the realm to look for the password, if the 
realm the server provides is different, urllib2 will respond as if it 
does not have a user/password.

If you are only doing one request, it isn't that big a deal; if you 
are doing many requests or want urllib2 to handle the response for 
other reseans, you can use a default realm, see the bottom of this 
example:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305288

(The advantage of using a default rather than making sure the realm is 
correct is that it can change and you won't have to do anything)



max

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


Re: urllib2 and HTTPBasicAuthHandler

2007-01-16 Thread Max Erickson
m.banaouas [EMAIL PROTECTED] wrote:

...
passman.add_password(None, auth_url, data['user'] ,
...


The only thing I can come up with is that auth_url can't begin with a 
protocol, like http:// or whatever. 


max

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


Re: Universal Feed Parser - How do I keep attributes?

2007-01-11 Thread Max Erickson
Gabriel Genellina [EMAIL PROTECTED] wrote:

 At Wednesday 10/1/2007 14:38, [EMAIL PROTECTED] wrote:
 
  d =
  feedparser.parse('http://weather.yahooapis.com/forecastrss?p=
 94089')
  d.feed.yweather_location
u''
 
 You have to feed it the *contents* of the page, not its URL.
 
 

The online documentation disagrees with you:

http://feedparser.org/docs/introduction.html


max

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


Re: recursive function

2007-01-08 Thread Max Erickson
cesco [EMAIL PROTECTED] wrote:

 Hi,
 
 I have a dictionary of lists of tuples like in the following
 example: dict = {1: [(3, 4), (5, 8)],
 2: [(5, 4), (21, 3), (19, 2)],
 3: [(16, 1), (0, 2), (1, 2), (3, 4)]]
 
 In this case I have three lists inside the dict but this number
 is known only at runtime. I have to write a function that
 considers all the possible combinations of tuples belonging to
 the different lists and return a list of tuples of tuples for
 which the sum of the first element of the most inner tuple is
 equal to N. 
 
 For example, assuming N = 24, in this case it should return:
 [((3, 4), (5, 4), (16, 1)), ((3, 4), (21, 3), (0, 2)), ((5, 8),
 (19, 2), (0, 2))]
 
 A simple list comprehension would be enough if only I knew the
 number of keys/lists beforehand but this is not the case. I guess
 I need a recursive function. Can anyone help?
 
 Thanks in advance
 Francesco
 

This thread is probably of interest:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/f0c0
406fce981a54/59a2a5dcd1507ab9#59a2a5dcd1507ab9


max

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


Re: path.py and directory naming: trailing slash automatic?

2006-11-10 Thread Max Erickson
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Hi,
 
 I'm a big fan of path.py. One thing that I think is a good idea
 is for directories to automatically have a slash appended to them
 if it is not automatically added. Eg:
 
 from path import path
 
 dir = path('/some/dir')
 
 x = dir + file # should yield /some/dir/file
 
 
 I emailed the author of path.py but I think he must be extremely
 busy. It took him 2-3 weeks to answer my first email and it's
 been longer than that for the one I sent regarding this.
 

just use '/' if that is what you want:

 from path import path
 d=path('/some/dir')
 d / file
path(u'/some/dir\\file')
 

If + also did that, it would be more difficult to change the extension 
when renaming a file or whatever.

max

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


Re: Py3K idea: why not drop the colon?

2006-11-10 Thread Max Erickson
 color='orange'
 if color=='red' or 'blue' or 'green':
print Works?


Works?
 

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


Re: PIL - Pixel Level Image Manipulation?

2006-11-08 Thread Max Erickson
Gregory Piñero [EMAIL PROTECTED] wrote:

 On 11/8/06, Gregory Piñero [EMAIL PROTECTED] wrote:
 I want to be able to randomly change pixels in an image and view
 the results.  I can use whatever format of image makes this
 easiest, e.g., gray scale, bit tonal, etc.

 Ideally I'd like to keep the pixels in an intermediate format
 like a list of (integers?) or an array and convert that to an
 image as needed.

 I'm hoping someone has some experience on this and could offer
 some advice or code.  I thought it would be easy in PIL  but I'm
 not sure. 
 
 I did find these functions after more searching:
 http://mail.python.org/pipermail/image-sig/2002-July/001914.html
 
 Perhaps I'll try those out tonight if I don't hear of anything
 better in the meantime.
 
 -Greg

Maybe something of use at:

http://online.effbot.org/2005_10_01_archive.htm#20051003


max

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

Re: how do I pass values between classes?

2006-11-06 Thread Max Erickson
kath [EMAIL PROTECTED] wrote:

 hi, Larry Bates  thanks for the reply...
 
 You might consider doing it the same way wx passes things around.
 When you instantiate the subclass pass the parent class' instance
 as first argument to __init__ method.
 
 Yes thats absolutely right..
 
 That way the subclass can
 easily pass values back to the parent by using that pointer.
 
 Could you please explain me this.. more clearly. I think it is much
 close to the solution.
 
 
 Thank you.
 regards, sudhir
 

Somewhere in the child class:

self.parent.do_something(something_to_do_it_with)

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


Re: Converting a .dbf file to a CSV file

2006-11-02 Thread Max Erickson
Johanna Pfalz [EMAIL PROTECTED] wrote:

 Is there a module/method in python to convert a file from .DBF
 format to .CSV format?
 
 Johanna Pfalz
 

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715

There is an example provided.

max

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


Re: question about True values

2006-10-25 Thread Max Erickson
Steve Holden [EMAIL PROTECTED] wrote:

 Gabriel Genellina wrote:
 At Wednesday 25/10/2006 22:29, Terry Reedy wrote:
 
  the string class's nil value.  Each of the builtin types
  has such an empty or nil value:
 
  string  
  list[]
  tuple   ()
  dict{}
  int 0
  float   0.0
  complex 0j
  set set()
 
  Any other value besides the above will compare as not
  false. 
 
 
  And today's question for the novices is: which Python type
  did Skip 
 miss
  from the above list?

 more that one:

 0L
 decimal.Decimal(0) # is decimal.Decimal('0'), also
 u''
 array.array('c') # or any other typecode, I suspect, without
 initializer 
 
 
 Just for fun:
 buffer('')
 frozenset()
 iter(())
 xrange(0)
 
 There's still a very obvious omission ...
 
 regards
   Steve

bool.

unicode and long if you are fussy.

max

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


Re: list comprehension (searching for onliners)

2006-10-20 Thread Max Erickson
Gerardo Herzig [EMAIL PROTECTED] wrote:

 Hi all: I have this list thing as a result of a db.query: (short
 version) result = [{'service_id' : 1, 'value': 10},
 {'service_id': 2, 'value': 5},
 {'service_id': 1, 'value': 15},
 {'service_id': 2, 'value': 15},
  ]
 
 and so on...what i need to do is some list comprehension that
 returns me something like
 
 result = [
 {
 'service_id' : 1, 'values': [ {'value': 10}, 
 {'value': 15}]
  },
 {
   'service_id' : 2, 'values': [ {'value': 5},
   {'value': 15}] 
 }

 
 My problem now is i cant avoid have repeteated entries, lets
 say, in this particular case, 2 entries for service_id = 1, and
 other 2 for service_id =2.
 Ill keeping blew off my hair and drinking more cofee while
 searching for this damn onliner im looking for.
 
 Thanks dudes.
 Gerardo

Is three lines ok?

 output=dict()
 for record in result:
output.setdefault(record['service_id'], list()).append(record
['value'])


 output
{1: [10, 15], 2: [5, 15]}
 

Creating the more verbose output that you specified should be 
pretty straighforward from there.

max

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


Re: wxPython help wxSashWindow

2006-10-19 Thread Max Erickson
MatthewWarren [EMAIL PROTECTED] wrote:

 
 Thanks, is that a newsgroup I can view through google groups? I
 tried seraching for it but google says no..
 
 And I'll give that list a subscribe.
 
 I have found a wxPython google group, but only 11 members and a
 handfull of posts in a year...
 

Gmane archives many mailing lists and also allows access to the lists 
through a news server gateway(news.gmane.org). Posting throught the 
news gateway is allowed for many groups(including this one), but not 
all. For more information and web access to the archives, visit 
http://gmane.org.

max

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


Re: advice for web-based image annotation

2006-10-19 Thread Max Erickson
Brian Blais [EMAIL PROTECTED] wrote:

 Hello,
 
 I want to set up a system where I can have my family members
 write comments about a number of pictures, as part of a family
 tree project.  Essentially, I want them to be able to log into a
 website (I already have the webspace, and the server runs python,
 but not mod_python), see images, and be able to fill in text
 boxes for comments and enter dates for the pictures.  These
 comments and dates will then be viewable by the others logging
 in, so that I can keep track of collect stories, details, dates, 
 etc...and also, who is writing what, when.
 
 I've written some basic CGI python scripts, and can imagine how
 to do this, but I was wondering if it would better to look into a
 framework like cherrypy, turbogears, zope, etc.  I have never
 done any database programming, but have written CGI scripts to
 modify excel sheets and text files to store state.  I am not
 adverse to learning the database end, but I don't want to climb
 that hill unless I feel there is a significant benefit.  I don't
 have admin rights on the server, if that makes a difference.
 
 Any suggestions would be greatly appreciated!
 
 
   thanks,
 
 Brian Blais
 

You might want to look at gallery:

http://gallery.menalto.com/

It is big and heavy and php, but it has most of what you want, an 
image gallery with user permissions and comments.

max

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


Re: Attribute error

2006-10-14 Thread Max Erickson
Teja [EMAIL PROTECTED] wrote:

 Hi all,
 
 What is attribute error? what causes that error, especially with COM
 objects?
 
 To be precise :
 
 Attribute Error: LCAS.LabcarController.writeLogWindow()
 
 Here, LCAS is a COM object
 
 Thanks
 Teja.P
 

LabcarController might be a function. See:

http://groups.google.com/group/comp.lang.python/msg/d7341f1aedcae6d3

for more detail.

hope this helps,
max

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


Re: Ok. This IS homework ...

2006-10-14 Thread Max Erickson
spawn [EMAIL PROTECTED] wrote:

 but I've been struggling with this for far too long and I'm about
 to start beating my head against the wall.
 --
 
 I tried adding an additional while statement to capture the
 second number, but it didn't seem to solve my problem.  Help!
 

Reread whatever material you have about while loops, or just consult 
the python documentation, and then think about why your program(as 
posted anyway) is never printing done.

Hope this isn't too much help,
max

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


Re: problem with the 'math' module in 2.5?

2006-10-14 Thread Max Erickson
Chris [EMAIL PROTECTED] wrote:

 from math import *
 sin(0)
 0.0
 sin(pi)
 1.2246063538223773e-016
 sin(2*pi)
 -2.4492127076447545e-016
 cos(0)
 1.0
 cos(pi)
 -1.0
 cos(2*pi)
 1.0
 
 The cosine function works fine, but I'm getting weird answers for
 sine. Is this a bug? Am I doing something wrong?
 

From help(math) in an interactive window:


DESCRIPTION
This module is always available.  It provides access to the
mathematical functions defined by the C standard.

So what you are seeing is the behavior of the C library being exposed.


Try sin(pi*0.5) to see similar behavior to cos(pi) or cos(pi*2).

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


Re: problem with the 'math' module in 2.5?

2006-10-14 Thread Max Erickson
Max Erickson [EMAIL PROTECTED] wrote:
 
 Try sin(pi*0.5) to see similar behavior to cos(pi) or cos(pi*2).
 

Uhh, switch that, cos(pi*0.5)...

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


Re: MP3 files and Python...

2006-10-10 Thread Max Erickson
Karlo Lozovina [EMAIL PROTECTED] wrote:

 I'm looking for a Python lib which can read and _write_ ID3v1 and
 ID3v2 tags, and as well read as much as possible data from MP3
 file (size, bitrate, samplerate, etc...).
 
 MP3 reproduction is of no importance...
 

Try mutagen:

http://www.sacredchao.net/quodlibet/

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


Re: changing a file's permissions

2006-10-02 Thread Max Erickson
James [EMAIL PROTECTED] wrote:
 --=_Part_63041_761240.1159752399799
 I'm writing a script in linux to excercise my python skills and
 have encountered a minor issue.
 
 Writing the script and creating an ouput file was simple enough
 and didn't take too long. However, I don't have permissions to
 execute the file by default. Now, I could simply chmod 755 the
 sucker and have done with it, but I want to apply the permissions
 within the python script if I can. 
 
 So my question is: how does one change a file's permissions
 inside of python?
 
 James
 

Assuming you want to operate on the output file:

import os
os.chmod(path, 755)


Hope this helps,

max

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


Re: Is it possible to change a picture resolution with Python?

2006-09-20 Thread Max Erickson
Lad [EMAIL PROTECTED] wrote:

 from
 image:
 http://www.pythonware.com/library/pil/handbook/image.htm

 This is some example code:

 from PIL import Image
 im = Image.open(1.jpg)
 nx, ny = im.size
 im2 = im.resize((int(nx*1.5), int(ny*1.5)), Image.BICUBIC)
 im2.save(2.png)

 Bye,
  bearophile,
 Thank you for your reply.
 But the above code increases size only , but not DPI resolutions(
 vertical nad horizontal).I need  a higher  vertical and horisontal
 resolutions.
 Any idea how to do that?
 Thank you
 

If you just want to change the dpi flag that some software uses to 
interpret the size of the image when rendering it, something like:

im.save('c:/tmp/out.jpg', dpi=(100,100))

might work. You can get lots of info on why this doesn't really change 
the resolution of the image from google.

max

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


Re: Eval (was Re: Question about the use of python as a scripting language)

2006-08-10 Thread Max Erickson
[EMAIL PROTECTED] wrote:

 
 Brendon A shortcut occurs to me; maybe someone can tell me
 what's wrong Brendon with my reasoning here. It seems that
 any string that is unsafe Brendon to pass to eval() must
 involve a function call, and thus must Brendon contain an
 opening paren. Given that I know that the data I Brendon
 expect contains no parens, would people expect this code to
 be Brendon safe:
 
 Unfortunately, no.  If I define a class which has properties,
 attribute assignment can involve arbitrary numbers of function
 calls. 
 
 Skip

Is it possible to define a class and create an instance without using 
an open parens? I don't know how, but that isn't saying a great 
deal...

max

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


Re: class return another instance

2006-08-08 Thread Max Erickson
Keith [EMAIL PROTECTED] wrote:

  
 
 Any help would be great.
 
  
 
 Cheers,
 
 Keith
 
 

Do you absolutely need the functionality to be in the __init__ method, 
or does something like the following work:


 IDs={}
 class ID: pass

 def factory(ident):
if ident in IDs:
instance=IDs[ident]
else:
instance=ID()
IDs[ident]=instance
return instance

 g=factory(1)
 h=factory(2)
 i=factory(1)
 g,h,i
(__main__.ID instance at 0x00A45FD0, __main__.ID instance at 
0x00A4B918, __main__.ID instance at 0x00A45FD0)
 


max

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


Re: Unicode question

2006-07-28 Thread Max Erickson
Ben Edwards (lists) [EMAIL PROTECTED] wrote:

 I am using python 2.4 on Ubuntu dapper, I am working through Dive
 into Python.
...
 Any insight?
 Ben


Did you follow all the instructions, or did you try to call 
sys.setdefaultencoding interactively?

See:

http://diveintopython.org/xml_processing/unicode.html#kgp.unicode.4.1


hope this helps,
max

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


Re: code is data

2006-06-23 Thread Max Erickson
Anton Vredegoor [EMAIL PROTECTED] wrote: 

 
 However, I knew of the existence of such languages but I am 
 mostly interested in standardized code interchange, like for 
 example with JSONP which fetches some external javascriptcode 
 from another server using JSON and places the translated 
 javascript into a webpage at the request of the clients browser 
 or so it seems. Maybe a Python webserver could also emit pieces 
 of javascript code by getting them from a *Python* code library 
 after translating Python code on the fly? 
 

 Anton 

I have no idea how close it is to what you are talking about, but pypy  
does have some sort of python-javascript support:

http://codespeak.net/pypy/dist/pypy/doc/getting-
started.html#translating-the-flow-graph-to-javascript-code

About two thirds down, if the above link is broken:

http://codespeak.net/pypy/dist/pypy/doc/getting-started.html


max

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


Re: very strange bug coercing to Unicode: need string or buffer, int found

2006-06-21 Thread Max Erickson
bussiere maillist [EMAIL PROTECTED] wrote:

 --=_Part_118629_1441854.1150895040355
 i truly didn't understand this error :
 Traceback (most recent call last):
   File D:\Programmation\FrancePaquet\FrancePaquet.py, line 77,
   in ? 
 cabtri = zz + chiffrescabtri + clefc
 TypeError: coercing to Unicode: need string or buffer, int found

 
 def calculclef(nombre):
 if clef == 10:
 clef = 0
 return clef
 

 clefb = calculclef(debutplage)
 clefb = str(clefb)
 print clefb

 clefc = calculclef(chiffrescabtri)

 cabtri = zz + chiffrescabtri + clefc


Your calculclef function returns an integer. You explitly convert 
clefb into a string, but you never convert clefc into a string, hence 
the TypeError.

max

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


Re: mapping None values to ''

2006-06-18 Thread Max Erickson
Roberto Bonvallet [EMAIL PROTECTED] wrote:
 You don't need map when using list comprehensions:
 
 [ for i in [a, b, c] if i in (None, None)]
 

That loses list elements that aren't in the tests:

 a=7
 b=None
 c=None
 [ for i in [a,b,c] if i in (None,None)]
['', '']
 

max

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


Re: Package

2006-06-02 Thread Max Erickson
I'm no expert, but your post made me curious. It appears that __all__ 
has the effect of ensuring that 

from test import *

picks up test1, but doesn't go any further than that. 

from test.test1.test2 import * 

should cause test3 to be imported.

max

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


Re: argmax

2006-06-01 Thread Max Erickson
David Isaac [EMAIL PROTECTED] wrote:

 1. Why is there no argmax built-in?
 (This would return the index of the largest element in a
 sequence.) 
 
 2. Is this a good argmax (as long as I know the iterable is
 finite)? def argmax(iterable): return max(izip( iterable, count()
 ))[1] 
 

use len:

len(iterable)-1


max


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


Re: Variable name has a typo, but code still works. Why?

2006-05-31 Thread Max Erickson
mateus [EMAIL PROTECTED] wrote:

 print hello world
 
 I have a nested loop where the outer loop iterates over key value
 pairs of a dictionary and the inner loop iterates over a list
 each list of which is a mapped value from the dictionary
 
 def showReport(self):
 for dev, sessions in self.logger.items():
 for tree in session:
 self.addTestItem(self, tree)
 
 What I don't understand is why this executes w/o any problems
 when sessions was spelled as plural (sessionS) while later
 being spelled in the singular (session).
 
 Is there some type of name resolution of local variables where
 Python makes assumptions?
 

Is self.logger.items() empty?

This does not raise a NameError even when 'explode' is not defined:

for x in []:
explode


max

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


Re: create a text file

2006-05-30 Thread Max Erickson
per9000 [EMAIL PROTECTED] wrote:

 # w is for writing
 myfile = open('theoutfile',w)

That won't work, the second argument to open needs to be a string:

myfile  = open('theoutfile', 'w')


max

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


Re: create a text file

2006-05-30 Thread Max Erickson
Fredrik Lundh [EMAIL PROTECTED] wrote:

 Max Erickson wrote:
 
 # w is for writing
 myfile = open('theoutfile',w)
 
 That won't work, the second argument to open needs to be a string:
 
 w = 'w'
 
 /F
 

Is it inappropriate to call the w on the left side of the equal's sign 
a string? I.e., w refers to a string(object) that contains 'w'?

My goal was to point out that the code would not work as posted.

max

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


Re: regex/lambda black magic

2006-05-25 Thread Max Erickson
Andrew Robert [EMAIL PROTECTED] wrote:

 ValueError: invalid literal for int(): %
 
 Does anyone see what I am doing wrong?
 

Try getting rid of the lamba, it might make things clearer and it 
simplifies debugging. Something like(this is just a sketch):

def callback(match):
print match.group()
return chr(int(match.group(),16)) % ord(match.group())

output.write(re.sub('r([^\w\s])', callback, line)

It looks like your match.group is a '%' character:

 int('%', 16)
Traceback (most recent call last):
  File pyshell#108, line 1, in ?
int('%', 16)
ValueError: invalid literal for int(): %
 


max

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


Re: regex/lambda black magic

2006-05-25 Thread Max Erickson
Andrew Robert [EMAIL PROTECTED] wrote:
 import re,base64
 
 # Evaluate captured character as hex
 def ret_hex(value):
  return base64.b16encode(value)
 
 def ret_ascii(value):
  return base64.b16decode(value)
 

Note that you can just do this:

from base64 import b16encode,b16decode 

and use them directly, or 

ret_hex=base64.b16encode

ret_ascii=base64.b16decode

if you want different names.


As far as the rest of your problem goes, I only see one pass being 
made, is the code you posted the code you are running?

Also, is there some reason that base64.b16encode should be returning a 
string that starts with a '%'? 

All I would expect is:

base64.b16decode(base64.b16encode(input))==input

other than that I have no idea about the expected behavior.

max

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


Re: Accessing object parent properties

2006-05-23 Thread Max Erickson
One way:

class Boo:
def __init__(self, parent):
self.parent=parent


class Foo:
X=1
def __init__(self):
self.test=boo(self)


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


Re: Which is More Efficient?

2006-05-19 Thread Max Erickson
Dustan [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 
 The task manager says CPU Usage: 100% when the program is
 running, and only when the program is running.
 
 Efficiency is a measure of 2 things: CPU usage and time. If you
 measure just time, you're not necessarily getting the efficiency.
 

A lot of people, when they say 'uses a lot of CPU' are leaving off 
'time'. I.e., CPU usage is pretty much talked about in terms of 
cycles, which is roughly utilization*time. Profiling tools often 
report both clock time and cpu time. Cpu time is a rough analog for 
cycles, clock time is self explanatory.

max

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


Re: altering an object as you iterate over it?

2006-05-19 Thread Max Erickson
Bruno Desthuilliers wrote
 
 It has been, at a time, recommended to use file() instead of
 open(). Don't worry, open() is ok - and I guess almost anyone
 uses it. 

http://mail.python.org/pipermail/python-dev/2005-December/059073.html

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


Re: Option parser question - reading options from file as well as command line

2006-05-16 Thread Max Erickson
Andrew Robert [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Hi Everyone.
 
 
 I tried the following to get input into optionparser from either
 a file or command line.
 
 
 The code below detects the passed file argument and prints the
 file contents but the individual swithces do not get passed to
 option parser. 
 
 Doing a test print of options.qmanager shows it unassigned.
 
 Any ideas?
 

Check parser.usage, it is likely to look a lot like your infile.

I'm not sure, but I think you need to pass your alternative arguments 
to parser.parse_args.

max

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


Re: Option parser question - reading options from file as well as command line

2006-05-16 Thread Max Erickson
Andrew Robert [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Any ideas?

I don't know much about optparse, but since I was bored:

 help(o.parse_args)
Help on method parse_args in module optparse:

parse_args(self, args=None, values=None) method of 
optparse.OptionParser instance
parse_args(args : [string] = sys.argv[1:],
   values : Values = None)
- (values : Values, args : [string])

Parse the command-line options found in 'args' (default:
sys.argv[1:]).  Any errors result in a call to 'error()', which
by default prints the usage message to stderr and calls
sys.exit() with an error message.  On success returns a pair
(values, args) where 'values' is an Values instance (with all
your option values) and 'args' is the list of arguments left
over after parsing options.

 o.parse_args('seven')
Traceback (most recent call last):
  File pyshell#15, line 1, in ?
o.parse_args('seven')
  File C:\bin\Python24\lib\optparse.py, line 1275, in parse_args
stop = self._process_args(largs, rargs, values)
  File C:\bin\Python24\lib\optparse.py, line 1322, in _process_args
del rargs[0]
TypeError: object doesn't support item deletion
 

That's the result of poking an optionParser instance in Idle. 
parse_args is expecting something that looks like sys.argv[1:], which 
is a list. You are passing it a string.

max

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


Re: cross platform libraries

2006-05-05 Thread Max Erickson
[EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 I went to this webpage
 
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649
 
 Isn't it supposed to run on the network and close the connected
 machine.

That code uses the windows libraries on the machine it is run on to 
generate a request to the networked machine to shutdown. The code 
executes locally and sends the request over the network.

 Every help is appreciate,
 

If you have some way of remotely running programs on the windows 
machine(ssh, telnet, etc.), you might try pstools:

http://www.sysinternals.com/Utilities/PsTools.html

specifically, psshutdown.

max

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


Re: Need help removing list elements.

2006-04-29 Thread Max Erickson
[EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 But this gives me IndexError: list out of range

You are making the list shorter as you are iterating. By the time your 
index is at the end of the original list, it isn't that long any more. 
Creating a new list and appending the elements you want to keep avoids 
the problem. Or you can just use a list comprehension(untested):

returned_lines=[line for line in open(lines.txt, 'rb') 
if line != ]

or just

returned_lines=[line for line in open(lines.txt) if line]

max


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


Re: Is Python a Zen language?

2006-02-25 Thread Max Erickson
Given that python code is often described in terms of being 'pythonic' or 
not, and that pythonic is a term that is apparently well agreed upon yet 
seemingly impossible to define for someone who does not already understand 
the word, python is probably a zen language.

max 


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


Re: How to I write DBASE files without ODBC

2006-02-06 Thread Max Erickson
Durumdara [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]:

 Can anybody known about DBASE handler module for Python ?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715


max

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


Re: How to generate graphics dynamically on the web using Python CGI script?

2006-01-20 Thread Max Erickson

Sparklines is a script that does exactly what you are asking using python 
and PIL:

http://bitworking.org/projects/sparklines/

max

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


Re: OT: excellent book on information theory

2006-01-17 Thread Max Erickson
Steve Holden [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Grant Edwards wrote:
 On 2006-01-16, Tim Peters [EMAIL PROTECTED] wrote:
 
 
http://www.inference.phy.cam.ac.uk/mackay/itila/Potter.html

[Grant Edwards]

That made me smile on a Monday morning (not an insignificant
accomplishment).  I noticed in the one footnote that the H.P.
book had been translated into American.  I've always wondered
about that.  I noticed several spots in the H.P. books where
the dialog seemed wrong: the kids were using American rather
than British English.  I thought it rather jarring.

You should enjoy:

   http://www.hp-lexicon.org/about/books/differences.html
 
 
 Very interesting.  And rather sad that editors think the
 average Amermican reader too dim-witted to figure out (in
 context, even) that a car park is a parking lot and a
 dustbin is a trash can.
 
 They know that the average American could work it out. They also know 
 that the average American doesn't like to do anything remotely like
 hard thinking, hence they make these changes so the books don't read
 like foreign literature.
 
 regards
   Steve

A rather less cynical interpretation is that they are attempting to make
a children's book accessible to as many children as possible, i.e., the
youngest readers as is practical. I don't mean to disparage the book by
calling it a children's book, I have read and enjoyed several of them,
but the target audience for the books is clearly kids. 

max




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


Re: Decimal ROUND_HALF_EVEN Default

2006-01-16 Thread Max Erickson
3c273 [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 
 Hello,
 
 I'm just curious as to why the default rounding in the decimal module
 is ROUND_HALF_EVEN instead of ROUND_HALF_UP. All of the decimal
 arithmetic I do is rounded half up and I can't think of why one might
 use round half even. I googled a bit and didn't really find a good
 answer. Any insight is appreciated.
 
 Louis
 
 

see http://www2.hursley.ibm.com/decimal/damodel.html#refdefcont

decimal.py was written following the specification at
 
http://www2.hursley.ibm.com/decimal/decarith.html

max

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


Re: Recursive tree list from dictionary

2006-01-14 Thread Max Erickson
David Pratt [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Hi. I am wanting to create a tree list result structure from a 
 dictionary to categorize results. The dictionary contains elements
 that identify its parent. The levels of categorization is not fixed,
 so there is a need for the code to be recursive to drill down to the
 lowest level. I have contrived a small source and result list to
 illustrate: 
 
   
 imd=dict()
 for d in source_list:
par=d['parent']
v=d['title']
try:
imd[par].append(v)
except:
imd[par]=[v]


 imd
{'Project': ['Geometries', 'Verticals'], 'Geometry': ['Points',
'Layers', 'Water'], 'root': ['Project', 'Geometry', 'Soil'], 'Soil':
['Soiltypes']} 
 

And then do whatever you need to do from here...

max

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


Re: Unicode Question

2006-01-09 Thread Max Erickson
The encoding argument to unicode() is used to specify the encoding of the 
string that you want to translate into unicode. The interpreter stores 
unicode as unicode, it isn't encoded...

 unicode('\xbe','cp1252')
u'\xbe'
 unicode('\xbe','cp1252').encode('utf-8')
'\xc2\xbe'
 


max

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


Re: Converting milliseconds to human time

2006-01-06 Thread Max Erickson
the hard way(in that you have to do it yourself):

def prntime(ms):
s=ms/1000
m,s=divmod(s,60)
h,m=divmod(m,60)
d,h=divmod(h,24)
return d,h,m,s

 print '%d days %d hours %d minutes %d seconds' % prntime(100)
0 days 0 hours 16 minutes 40 seconds
 print '%d days %d hours %d minutes %d seconds' % prntime(1000)
0 days 2 hours 46 minutes 40 seconds
 print '%d days %d hours %d minutes %d seconds' % prntime(1)
1 days 3 hours 46 minutes 40 seconds
 print '%d days %d hours %d minutes %d seconds' % prntime(10)
11 days 13 hours 46 minutes 40 seconds
 print '%d days %d hours %d minutes %d seconds' % prntime(418235000)
4 days 20 hours 10 minutes 35 seconds
 

max

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


Re: Newbie Question: CSV to XML

2006-01-06 Thread Max Erickson
ProvoWallis [EMAIL PROTECTED] wrote in 
news:[EMAIL PROTECTED]:

 Hi,
 
 I'm learning more and more about Python all the time but I'm still a
 real newbie. I wrote this little script to convert CSV to XML and I 
was
 hoping to get some feedback on it if anyone was willing to comment.
 
 It works but I was wondering if there was anything I could do better.
 E.g., incorporate minidom somehow? But I'm totally in the dark as how 
I
 would do this.
 
 Thanks,
 
 Greg
 
 
 ###
 
 #csv to XML conversion utility
 
 import os, re, csv
 root = raw_input(Enter the path where the program should run: )
 fname = raw_input(Enter name of the uncoverted file: )

consider parsing the command line to get the file to convert, ie
csvtoxml.py FILE

searching on sys.argv, getopt and optparse will give you lots of info on 
this.


 
 for row in reader:
  for i in range(0, len(row)):
 
   if i == 0:
output.write('\nrow\nentry
 colname=col%s%s/entry' % (i, row[i]))
   if i  0 and i  len(row) - 1:
output.write('\nentry colname=col%s%s/entry' % 
(i,
 row[i]))
   if i == len(row) - 1:
output.write('\nentry
 colname=col%s%s/entry\n/row' % (i, row[i]))

instead of testing for the first and last rows, just write the row
stuff in the outer loop. Untested, but it should work the same...

for row in reader:
output.write('\nrow')
for i, cell in enumerate(row):
output.write('\nentry colname=col%s%s/entry' % (i,cell)
output.write('\n/row')


max

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


Re: New to Python, WxPython etc, etc

2006-01-03 Thread Max Erickson
rodmc [EMAIL PROTECTED] wrote in news:1136299565.613252.202670
@g44g2000cwa.googlegroups.com:


 import _gaim
 import wx
 
 from wxPython.wx import *
 
 ID_ABOUT = 101
 ID_EXIT  = 102
 
 class MyFrame(wxFrame):
 def __init__(self, parent, ID, title):

I don't have an answer to your question, but as an aside, you should 
think about using the wx namespace if you move forward with wxPython. 
Basically, you would just eliminate 'from wxPython.wx import *' as you 
are already importing wx. Then, instead of referring to wxFrame, you 
would refer to wx.Frame.

See:
http://www.wxpython.org/MigrationGuide.html#the-wx-namespace

for more information about this.

Max

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


Re: Accessing next/prev element while for looping

2005-12-18 Thread Max Erickson
j is a built-in object used to make complex numbers. Or at least it
was, until you rebound it to the current element from myarray. That's bad
practice, but since using complex numbers is rather unusual, one you will
probably get away with.

Is it?

 j

Traceback (most recent call last):
  File pyshell#0, line 1, in -toplevel-
j
NameError: name 'j' is not defined
 1 + 2j
(1+2j)
 j=4
 1 + 2j
(1+2j)


I am actually curious, as it doesn't appear to be, but you are usually
'right' when you say such things...

Max

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


Re: tutorial example

2005-11-12 Thread Max Erickson

Not in python.

For example, what would you call the following?

def rsum(n, m):
print n+m
return n+m


In python a method is callable attached to an object. A function is a 
callable object constructed with a def statement.

max

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


Re: tutorial example

2005-11-11 Thread Max Erickson
 import math
 def distance1(x1, y1, x2, y2): 
   dx = x2 - x1 
   dy = y2 - y1 
   dsquared = dx**2 + dy**2 
   result = math.sqrt(dsquared) 
   print result
   return result

 def distance2(x1, y1, x2, y2): 
   dx = x2 - x1 
   dy = y2 - y1 
   dsquared = dx**2 + dy**2 
   result = math.sqrt(dsquared) 
   print result

 
They don't do the same thing here...
  
 distance1(1,2,3,4)
2.82842712475
2.8284271247461903
 distance2(1,2,3,4)
2.82842712475


the 'return result' line passes the result object in the function 
back to where the function was called. Functions without a return 
statement  default to returning 'None'. Calling the functions within 
a print statement illustrates the difference:

 print distance1(1,2,3,4)
2.82842712475
2.82842712475
 print distance2(1,2,3,4)
2.82842712475
None
 

As you can see, distance2 does not actually return the result of the 
calculation to the interactive prompt...

max

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


Re: wxPython newbie question, creating mega widgets , and DnD

2005-11-10 Thread Max Erickson
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 A side question - why is their a EVT_LIST_BEGIN_DRAG but no
 EVT_LIST_END_DRAG, unlike tree's which have BEGIN and END?  I
 need a draggable list box, and would prefer to not handle low
 level mouse events.

My intuition(so take it with a grain of salt) says that it wouldn't 
make any sense for the list control to generate an event when the drag 
and drop lands on a different control.

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


Re: How to use writelines to append new lines to an existing file

2005-09-22 Thread Max Erickson
Nico Grubert [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Hi there,
 
 I would like to open an existing file that contains some lines of
 text in order to append a new line at the end of the content.
 
 My first try was:
 
  f = open('/tmp/myfile', 'w') #create new file for writing
  f.writelines('123')  #write first line
  f.close()
  f = open('/tmp/myfile', 'w') #open existing file to append
  new line f.writelines('456')
  f.close()
  f = open('/tmp/myfile', 'r') # open file for reading
  f.read()
 '456'
 
 I supposed to have:
  f.read()
 '123\n456\n'
 
 
 Does  f = open('/tmp/myfile', 'w')  overwrite the existing file
 or does f.writelines('456') replace the first line in the
 existing file? 
 
 Nico

There is a good explanation in the tutorial:
http://docs.python.org/tut/node9.html#SECTION00920

and more detail is available in the docs for builtin functions:
http://docs.python.org/lib/built-in-funcs.html
(look under file() but probably still use open())

That said, open(file, 'a') will open an existing file to append.

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


Re: Replacing an XML element?

2005-09-20 Thread Max Erickson
Nick Vargish [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 I've been trying to figure out how to do something that seems
 relatively simple, but it's just not coming together for me. I'm
 hoping someone will deign to give me a little insight here.
 
 The problem: We have XML documents that use a custom table format
 that was designed primarily for typesetting documents. It's a
 column-first oriented scheme, and now we need a way to convert
 these table elements to HTML style row-first tables.
 
 I would like to be able to do something like this:
 
 doc = xml.dom.minidom.parse(input)
 for table in doc.getElementsByTagName('COLTABLE'):
 newtable = coltable_to_rowtable(table)
 ## this is what I can't figure out
 doc.replace(table, newtable)
 output.write(doc.toxml('utf-8'))
 
 I'm pretty sure I'm missing something obvious, but haven't been
 able to find any examples. 
 
 Someone please whack me with a cluestick,
 
 Nick
 

table.parentNode.replaceChild(newtable, table)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: web scrapping - POST and auto-login

2005-09-19 Thread Max Erickson
james at hal-pc.org wrote in
news:[EMAIL PROTECTED]: 

 james at hal-pc.org wrote:
 the entire 26 character string from site A, but [1] how do i
 crop it to 10 characters.
 
 [1] still at a loss on this one, but i can get to it later,
 unless you've got any ideas.

strings are slicable:

 s='a string of characters'
 s[:10]
'a string o'
 s[-10:]
'characters'
 

As far as your other problem, it might make sense(I don't know...) to 
just generate the post request for saving the new password yourself 
and never bother with parsing/filling the form.

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


Re: web scrapping - POST and auto-login

2005-09-19 Thread Max Erickson
james at hal-pc.org wrote in
news:[EMAIL PROTECTED]: 

 Max Erickson wrote:
the entire 26 character string from site A, but [1] how do i
crop it to 10 characters.
 
 strings are slicable:
 
 The only reason i've gotten this far is a basic understanding of
 syntax and programming in general :)
 care to enlighten me a little on how to do that?

I did. If you have some text in VARIABLE, and do something like:
substring=VARIABLE[:10], substring will be the first 10 characters of 
VARIABLE.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: nested tuples

2005-09-09 Thread Max Erickson
Luis P. Mendes [EMAIL PROTECTED] wrote in
 suppose I'm reading a csv file and want to create a tuple of all
 those rows and values, like ((row1value1, row1value2,
 row1value3),(row2value1, row2value2, row2value3),...,
 (rowNvalue1, rowNvalue2, rowNvalue3)) 
 
 I haven't found the way to do it just using tuples.  How can I do
 it? 
 
 Nevertheless, I can solve it like this:
 a=[]
 
 for row in reader:
 ~   elem = (row[0],row[1],row[2])
 ~   a.append(elem)
 
 which will result in a list of tuples: [(row1value1, row1value2,
 row1value3),(row2value1, row2value2, row2value3),...,
 (rowNvalue1, rowNvalue2, rowNvalue3)]

tuple() will consume a list.

 tuple([1,2,3])
(1, 2, 3)
 tuple([(1,2),(3,4),(5,6)])
((1, 2), (3, 4), (5, 6))


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


Re: is dict.copy() a deep copy or a shallow copy

2005-09-04 Thread Max Erickson
Alex [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 
 D={'Python': 'good', 'Basic': 'simple'}
 E=D.copy()
 E
 {'Python': 'good', 'Basic': 'simple'}
 D['Basic']='oh my'
 D
 {'Python': 'good', 'Basic': 'oh my'}
 E
 {'Python': 'good', 'Basic': 'simple'}

 
 Hmm, this looks like a deep copy to me?? I also tried
 

It is shallow, but strings are immutable so the difference is fairly 
moot.

 D={'Python': 'good', 'Basic': 'simple'}
 E=D
 E
 {'Python': 'good', 'Basic': 'simple'}
 E['Basic']='oh my'
 E
 {'Python': 'good', 'Basic': 'oh my'}
 D
 {'Python': 'good', 'Basic': 'oh my'}

 

Here, E and D are different names for the same object. There is no 
copy.

 which looks like a shallow copy to me?? So my hypothesis is that
 E=D is a shallow copy while E=D.copy() is a deep copy.
 

 So is the documentation wrong when they claim that D.copy()
 returns a shallow copy of D, or did I misunderstand the
 difference between a deep and shallow copy?

Sort of, some examples:

Here d1 and d2 are copies. They can be independently changed to 
refer to different objects:

 d1={'a':1,'b':2}
 d2=d1.copy()
 d1['a']=3
 d2['b']=4
 d1
{'a': 3, 'b': 2}
 d2
{'a': 1, 'b': 4}

Again, d3 and d4 are copies, but instead of changing the objects 
they refer to, we change the contents of the objects they refer to:

 d3={'c':[3],'d':[4]}
 d4=d3.copy()
 d3['c'][0]=5
 d4['d'][0]=6
 d3
{'c': [5], 'd': [6]}
 d4
{'c': [5], 'd': [6]}

Both cases are shallow copies. In a deep copy, altering the contents 
of d3['c'] would have no impact on the contents of d4['c'].

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


Re: Dynamic image creation for the web...

2005-08-28 Thread Max Erickson
Tompa [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Hi,
 
 I would like to create images on the fly as a response to an http
 request. I can do this with PIL like this (file create_gif.py):
 from PIL import Image, ImageDraw
 

check out sparklines:

http://bitworking.org/projects/sparklines/

It is a script very similar to what you want to do.

The difference between your script and sparklines is mostly that it 
sends:

print Content-type: image/png

instead of:

print 'Content-type: text/html'


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


Re: Excel Character object through COM

2005-08-26 Thread Max Erickson
Krisz [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 A.book.Worksheets(1).Range(a1).Characters(1,1)
 Traceback (most recent call last):
   File interactive input, line 1, in ?
 AttributeError: Characters instance has no __call__ method
 
 So my question is that am I doing something wrong or there is a
 different way to modify the color of a charater through COM.
 

try GetCharacters(1,1)

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


  1   2   >