Re: Self-awareness of imported modules? Do they know where they live?

2005-12-14 Thread Heiko Wundram
Martin M. wrote:
> So how can I do this? In AppleScript I would try something like "path
> to me", but this does not work for imported scripts in AppleScript, as
> you then only get the path to the main script. But can this be done in
> Python? Can modules know where they are currently located, where they
> live? Can they be self-aware?

Yes, they can be:

[EMAIL PROTECTED] ~ $ cat test.py
import os

print os.path.abspath(__file__)
[EMAIL PROTECTED] ~ $ python test.py
/home/modelnine/test.py
[EMAIL PROTECTED] ~ $

HTH!

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


Re: IsString

2005-12-14 Thread Donn Cave
Quoth Mike Meyer <[EMAIL PROTECTED]>:
| Donn Cave <[EMAIL PROTECTED]> writes:
...
|> Historically, the way I remember it, there was a time not too
|> long ago when GvR and his minions sort of dismissed the idea
|> that you needed to understand the reference/object model from
|> the outset.  I mean, obviously you need to get there eventually
|> if you're going to be a hard core Python programmer, but they
|> wanted to see people learning to write programs, without being
|> encumbered by knowledge of implementation details, and ideas
|> about the difference between "variable" and "binding" are
|> certainly about implementation details.
|
| No, they're not. They're a fundamental part of the semantics of the
| language. But you are right - you should be able to learn how to
| program in Python without having to learn about those thing. The fact
| is, you can do that - if you don't have any preconcieved notions about
| what the names are and how they behave. If you have to unlearn things
| from another language (like that variables have types, or values that
| can be changed), then you'll need the difference explained the first
| time the difference is noticable.

Yes, it may be easier to learn from a blank slate, though I wouldn't
be too sure.  But that is kind of beside the point (are you trying to
answer too many messages per day here?)  Either you have to learn it,
or you don't.

Eventually, of course you do have to learn it.  At some point you're
confronted with the need to predict what will happen in one of those
perennial examples like a = [], b = a, a.append(c).  If you can predict
results accurately every time, then whether you learned it by reading
the documentation or by experimentation, whether you learned it in CS
terminology or understand it in some non-verbal way, in any case you
have learned something about the language itself.

The question is whether basically everyone needs to get there, or we
can expect the masses to use the language _without understanding it_
in this sense, without understanding the language-specific stuff.
I don't know how important that is, I guess it depends on how real
the CP4E world is ever going to be, but I think it's wishful thinking
to expect that to work with Python.

Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Self-awareness of imported modules? Do they know where they live?

2005-12-14 Thread Martin M.
Hi,

I have the following question: How can an imported module see/find the
path to itself?

Background: From my main script I import a module which needs a file
(AppleScript) located in the same directory as the imported module.
What I do not want is to tell the module the location of the
AppleScript file by passing this information from the main script,
because I want my imported module to be independent from the main
script.

So how can I do this? In AppleScript I would try something like "path
to me", but this does not work for imported scripts in AppleScript, as
you then only get the path to the main script. But can this be done in
Python? Can modules know where they are currently located, where they
live? Can they be self-aware?

I hope you understand my problem and I appreciate any helpful answers!

Happy scripting!

Martin

P.S.: Background-background: I try to build myself a library of Python
scripts, which are getting a lot of infro from AppleScripts which
reside in the same directoty (e.g. usrdrs.py & usrdrs.scpt, usrdrs.py
is reading/executing usrdrs.scpt and returning the gathered info).

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


Re: How to get the local mac address?

2005-12-14 Thread bonono

Frank Millman wrote:
> [EMAIL PROTECTED] wrote:
> > Sorry that I can't help you in any way but have a question myself.  Is
> > there an OS independent way to get this thing(regardless of how to
> > format it) in Python ? I know this may not matter if all you want is
> > Windows but there is just another thread talking about one should write
> > programs that is OS independent.
> >
> > Is this a problem of the network library of python ?
>
> This is not a generic solution, but it works for me on Linux and
> Windows
>
> def getMacAddress():
> if sys.platform == 'win32':
> for line in os.popen("ipconfig /all"):
> if line.lstrip().startswith('Physical Address'):
> mac = line.split(':')[1].strip().replace('-',':')
> break
> else:
> for line in os.popen("/sbin/ifconfig"):
> if line.find('Ether') > -1:
> mac = line.split()[4]
> break
> return mac
>
Thanks, but how can I associate the result to the socket, assuming that
is the reason for wanting to get at the MAC ?

I see that some *nix implementation use fcntl/ioctl to read this info
out of the file handle of a socket but these modules don't exist on
Windows(may be some other platform as well).

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


Re: How to get the local mac address?

2005-12-14 Thread Frank Millman

[EMAIL PROTECTED] wrote:
> Sorry that I can't help you in any way but have a question myself.  Is
> there an OS independent way to get this thing(regardless of how to
> format it) in Python ? I know this may not matter if all you want is
> Windows but there is just another thread talking about one should write
> programs that is OS independent.
>
> Is this a problem of the network library of python ?

This is not a generic solution, but it works for me on Linux and
Windows

def getMacAddress():
if sys.platform == 'win32':
for line in os.popen("ipconfig /all"):
if line.lstrip().startswith('Physical Address'):
mac = line.split(':')[1].strip().replace('-',':')
break
else:
for line in os.popen("/sbin/ifconfig"):
if line.find('Ether') > -1:
mac = line.split()[4]
break
return mac

HTH

Frank Millman

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


Re: set & random.choice question

2005-12-14 Thread cgriddell
Oh duh.  :)

Thanks for pointing out the obvious without mocking...

sc

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


Re: Online Ruby

2005-12-14 Thread Paddy
That reminds me of TclTutor:
  http://www.msen.com/~clif/TclTutorTour.html

TclTutor is a great Tk application that teaches Tcl/Tk by having all
the lessons and examples set up waiting in the app. The examples can be
edited/fixed and re-executed.

I still bring up TclTutor when I delve into Tcl programming (after
several years), it is invaluable.

I guess a Python equivalent would be Idle, pre-packaged with lessons
and examples from the Python tutorial available from the Idle menus.

- Pad.

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


Re: quick unicode Q

2005-12-14 Thread Heiko Wundram
Erik Max Francis wrote:
> Flags in the ID3 tag specify the encoding.  It is not always UTF-8.
> 
> http://www.id3.org/id3v2.4.0-structure.txt

Okay... Didn't know that, and I'm pretty sure with ID3V1 this was always
utf-8 in case it was unicode (which was a non-standard extension anyway).
Thanks for the info.

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


Re: Python packages on OS X vs Windows

2005-12-14 Thread Kenneth McDonald
If the amount of time it saved me justified it, I wouldn't hesitate to spend250 pounds. To put it in a more measurable manner, I've found myselfspending so much time attempting to get packages compiled underUNIXes (OS X, Linux, FreeBSD, etc.) that I would have no difficultywhatsoever in spending $500/year (or more) simply to get librariesand programs in a precompiled format that I could just install and havework--even if, in theory, I could get all that stuff "for free" by doing a fullinstall myself.I'd hoped that most of this stuff would appear in precompiled formatfor OS X, but unfortunately it hasn't.Cheers,KenOn 14-Dec-05, at 10:16 PM, Alex Martelli wrote:On the other hand, it seems like most of this stuff is just available as installers for PCs. Am I being naive to think that installation of most of this stuff   (including getting it working) will be much easier in the PC world?  PyQt for Windows is not available under GPL (as it is for Mac).  If shelling out 250 pounds (plus VAT) is "much easier" for you than doing a little compilation, or you can't use the GPL version anyway, etc, etc, then, maybe. -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python C/API - *arg,**kwds variable argumnents

2005-12-14 Thread [EMAIL PROTECTED]

thanks, I get it now.

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


Re: OO in Python? ^^

2005-12-14 Thread bonono

Alex Martelli wrote:
> <[EMAIL PROTECTED]> wrote:
>
> > Alex Martelli wrote:
> > > <[EMAIL PROTECTED]> wrote:
> > >
> > > > > those convoluted templates that were added to the language as
> > > > > an afterthought.
> > > > I don't see this in Haskell.
> > >
> > > Well, historically templates HAVE been added to Haskell "as an
> > > afterthought" (well after the rest of the language was done), and
> > > judging mostly from
> > >  > > .ps> it doesn't seem unfair to call them "convoluted"...
> > >
> > I think I was talking about the need to add templates in order for
> > writing generic functions that was mentioned(see the example given
> > about sum), not in the context you are talking about. You seem to have
> > skipped the other half of the text I quoted.
>
> Right, you can get good genericity with Haskell's typeclasses (I've
> posted about that often in the past, and desperately and so far
> unsuccessfully tried to convince Guido to use something close to
> typeclasses rather than "interfaces" for such purposes as PEP 246
> [protocol adaptation]); it's the state of _templates_ in Haskell,
> specifically, which I was rather dubious about (it may be that I just
> haven't dug into them deep enough yet, but they do seem not a little
> "convoluted" to me, so far).
>
Yup, the templates is an afterthought and the point of discussion by
Lispers(?) too. I have no idea what it is intended for, there must be
some need for it but definitely beyond what I can handle.

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


Re: Python packages on OS X vs Windows

2005-12-14 Thread Kenneth McDonald
I've often found the Linux world to be like falling off a log,specifically, a log above a deep chasm with sharp rocksat the bottom :-)Linux has its place (though I tended to use FreeBSD more),but it's been several years since I've wanted to actually knowhow to manage my own system. I'd suggest that the variety ofdistribution/installation schemes that have been developedfor these systems indicate that software installation is _not_that easy to do on them.IMHO, any installation procedure that requires the user tocompile a piece of software is fundamentally broken; thecompilation step is part of the software development process,and should be done at the source, so that compilation/linking/make/etc.bugs can be handled there. Hence my question about installingPython-related packages on Windows (in spite of all of my otherdislikes of Windows, which are numerous).On 14-Dec-05, at 9:16 PM, Dan Sommers wrote:On the other hand, it seems like most of this stuff is just available as installers for PCs.  Am I being naive to think that installation of most of this stuff (including getting it working) will be much easier in the PC world?  It can be like falling off a log in the Linux world. -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python packages on OS X vs Windows

2005-12-14 Thread Mike Meyer
Scott David Daniels <[EMAIL PROTECTED]> writes:
> BartlebyScrivener wrote:
> The tough part on Windows (for the Linux/Unix/*ix bigots) is that
> each program scans the command line that invoked it in its own
> inimitable way.  This is not really the fault of the windows command
> line processor; this comes from allowing flexibility to individual
> programs.

If you mean what I think you mean, I'd say it's the fault of
Windows. I don't do much Windows, and no Windows-specific development,
so maybe this has been fixed since I last checkd on it.

I consider Unix shells to be less than good as command line
processors. Yes, they have lots of really spiffy features, but most of
them just aren't very bright when it comes to being a command line
processor.

zsh is the only exception I know about, but that requires someone
familiar with both zsh and the command in question to teach zsh about
each individual command in a language that looks like line noise in
places, and adds a level of indirection to all your commands. And
that's for the easy cases.

A good command processor provides an API so that commands can tell the
command processor about their arguments, allowing the command
processor to do completion on flags or command words, to complete
arguments and do pattern matching against the appropriate universe,
instead of just against file names, and so on.

Windows seems to have APIs for nearly everything. Is there one like I
described above?

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OO in Python? ^^

2005-12-14 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> > <[EMAIL PROTECTED]> wrote:
> >
> > > > those convoluted templates that were added to the language as
> > > > an afterthought.
> > > I don't see this in Haskell.
> >
> > Well, historically templates HAVE been added to Haskell "as an
> > afterthought" (well after the rest of the language was done), and
> > judging mostly from
> >  > .ps> it doesn't seem unfair to call them "convoluted"...
> >
> I think I was talking about the need to add templates in order for
> writing generic functions that was mentioned(see the example given
> about sum), not in the context you are talking about. You seem to have
> skipped the other half of the text I quoted.

Right, you can get good genericity with Haskell's typeclasses (I've
posted about that often in the past, and desperately and so far
unsuccessfully tried to convince Guido to use something close to
typeclasses rather than "interfaces" for such purposes as PEP 246
[protocol adaptation]); it's the state of _templates_ in Haskell,
specifically, which I was rather dubious about (it may be that I just
haven't dug into them deep enough yet, but they do seem not a little
"convoluted" to me, so far).


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


Re: OO in Python? ^^

2005-12-14 Thread bonono

Alex Martelli wrote:
> <[EMAIL PROTECTED]> wrote:
>
> > > those convoluted templates that were added to the language as
> > > an afterthought.
> > I don't see this in Haskell.
>
> Well, historically templates HAVE been added to Haskell "as an
> afterthought" (well after the rest of the language was done), and
> judging mostly from
>  .ps> it doesn't seem unfair to call them "convoluted"...
>
I think I was talking about the need to add templates in order for
writing generic functions that was mentioned(see the example given
about sum), not in the context you are talking about. You seem to have
skipped the other half of the text I quoted.

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


Re: OO in Python? ^^

2005-12-14 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:

> > those convoluted templates that were added to the language as
> > an afterthought.
> I don't see this in Haskell.

Well, historically templates HAVE been added to Haskell "as an
afterthought" (well after the rest of the language was done), and
judging mostly from
 it doesn't seem unfair to call them "convoluted"...


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


Re: PHP = Perl Improved

2005-12-14 Thread John Bokma
Martin Christensen <[EMAIL PROTECTED]> wrote:

> Perl, too, since he doesn't seem to understand it when people tell him
> to bugger off in plain English.

"It" buggers off if everybody ignores it. "It" posts because it knows that 
its actions pisses off so many people.

-- 
John   Small Perl scripts: http://johnbokma.com/perl/
   Perl programmer available: http://castleamber.com/
I ploink googlegroups.com :-)

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


Re: ActivePython and Amara

2005-12-14 Thread alex23
Jay wrote:

> [T]here are multiple items in channel, how do i tell it to
> go to the next item and get that title??

channel = rssDigg.find('//channel')
for item in channel.findall('item'):
print item.find('title').text

-alex23

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


Re: How do I bind to scrollbar?

2005-12-14 Thread James Stroud
Nicholas Shewmaker wrote:
> (I apologize if this posts twice. My AVG is being fussy.)
> 
>  From what I've read, MouseWheel is a very tricky event.  I have 
> replaced my Python tcl84.dll and tk84.dll files with those in the 
> ActiveTcl distribution to fix the crashes caused by the event.  Then, I 
> managed to see that my test script (see code below) was registering the 
> event by printing the delta value (+/- 120).
> 
> -
> from Tkinter import *
> 
> def reportScroll(event):
> print "scrolled", event.delta, event
> 
> root = Tk()
> 
> myListbox = Listbox(root, selectmode=SINGLE, height=10, width=20)
> for x in range(30):
> myListbox.insert(END, x)
> myListbox.pack(side=LEFT, expand=YES, fill=BOTH)
> 
> myScrollbar = Scrollbar(root, command=myListbox.yview)
> myScrollbar.bind('', reportScroll)
> myScrollbar.focus_set()
> myScrollbar.pack(side=RIGHT, fill=Y)
> 
> myListbox.config(yscrollcommand=myScrollbar.set)
> 
> root.mainloop()
> -
> 
> The scrollbar and listbox are tied together, but moving the wheelmouse 
> does nothing.  I realize the code above doesn't give the event any real 
> duties, but I'm not really sure how to make that leap.  How and to what 
> do I bind  so that it will affect the listbox and the 
> scrollbar?

I don't think  is a real event in Tkinter. Try binding to 
 and :

myListbox.bind('', lambda e, s=self:  \
s._scroll(SCROLL, -1, UNITS))
myListbox.bind('', lambda e, s=self:  \
 s._scroll(SCROLL, 1, UNITS))

These have worked for me on Linux and OS X. They probably work under 
windows if you are lucky.

You will need to bind the scrollbar separately if you want it to respond 
to the mousewheel.

See also:

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

(and the discussion that follows).

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


Re: ActivePython and Amara

2005-12-14 Thread Jay
really quick question, if you look at the XML doc of digg.com then you
will see that there are multiple items in channel, how do i tell it to
go to the next item and get that title??

title2 = rssDigg.find("//channel/item//title").text  Didnt work
title2 = rssDigg.find("//channel/item[1]/title").textDidnt work

Umm, any help?

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


Re: Optimize function similiar to dict.update() but adds common values

2005-12-14 Thread Gregory Piñero
OK, I ran Peter's add_freq3 and it ran four times on really large
dictionaries in about 3000 seconds.  So I'd say that at a minimum
that's ten times faster than my original function since it ran all
last night and didn't finish.

Much obliged, Peter!

-Greg


On 12/14/05, Gregory Piñero <[EMAIL PROTECTED]> wrote:
> Yes, that makes sense.  I can't wait to run it tonight.  Sorry I can't
> give you the running time of my original function as it never finished
> :-(
>
> I'll report back the running time of the new function though, assuming
> it finishes ;-)
>
> Thanks again,
>
> -Greg
>
>
> On 12/14/05, Peter Otten <[EMAIL PROTECTED]> wrote:
> > Gregory Piñero wrote:
> >
> > > Here's a question about your functions.  if I only look at the keys in
> > > freq2 then won't I miss any keys that are in freq1 and not in freq2?
> >
> > No. As I start with a copy of freq1, all keys  of freq1 are already there.
> > There is probably a loop involved, but it in Python's underlying C
> > implementation, which is a bit faster.
> >
> > What is left to do is to (1) add key and value for the 20% of freq2 that are
> > not in freq1, and to (2) increase the value for the 80% where the key
> > occurs in both freq1 and freq2. This is done by the for-loop.
> >
> > Peter
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
> --
> Gregory Piñero
> Chief Innovation Officer
> Blended Technologies
> (www.blendedtechnologies.com)
>


--
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python packages on OS X vs Windows

2005-12-14 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Kenneth McDonald  <[EMAIL PROTECTED]> wrote:
.
.
.
>And on a somewhat related note, do people find ipython to be a decent  
>replacement
>on Windows for the fact that the Windows shell is braindead?
.
.
.
Some do.  Some find it a life-altering marvel.

I'll make this explicit:  yes, people working under Windows ought
to give ipython a chance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I use win32 COM object in a thread?

2005-12-14 Thread Pelmen
Sorry for post, answer was near ... just do search

2. Ixokai

From: "Ixokai" <[EMAIL PROTECTED]>
Mon, 9 Feb 2004 11:05:08 -0800


Basically, adodbapi uses COM, and COM and threads require a bit of
care,
apparently.  Your webkit thing may be using a thread to handle stuff.


import pythoncom
pythoncom.CoInitialize()
... code ...
pythoncom.CoUnitialize()


You need to call pythoncom.CoInitialize() once for each thread...
theres
something about sys.coinit_flags = 0 (or 1) that may be nessecary but I

don't know what they mean precisely :) 


--Stephen

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


Re: Python packages on OS X vs Windows

2005-12-14 Thread Scott David Daniels
BartlebyScrivener wrote:
> I'm curious about this part of the post. Any fluent Pythoners actually
> happy using Windows XP and, if so, do they use ipython as a kind of
> bash shell substitute? Other alternatives to compensate for the widely
> derided command line in windows?
The widely derided command line in Windows is largely widely derided by
people who are used to a different command line and wish windows matched
the one they were used to.  I have moved between a number of different
"shells" in my programming career, and Windows "cmd.exe" is not at all
the worst (though I had to do a lot of "help" command to learn how to
use it).  The tough part on Windows (for the Linux/Unix/*ix bigots) is
that each program scans the command line that invoked it in its own
inimitable way.  This is not really the fault of the windows command
line processor; this comes from allowing flexibility to individual
programs.  The Windows model is big programs that do everything; the *ix
model is small independent processes that connect in interesting ways.
I like the latter, but there is something to be said for the former.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python packages on OS X vs Windows

2005-12-14 Thread BartlebyScrivener
> And on a somewhat related note, do people find ipython to be a decent
> replacement
> on Windows for the fact that the Windows shell is braindead?

I'm curious about this part of the post. Any fluent Pythoners actually
happy using Windows XP and, if so, do they use ipython as a kind of
bash shell substitute? Other alternatives to compensate for the widely
derided command line in windows?

rpd

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


Re: Test the system is despised.

2005-12-14 Thread Grant Edwards
On 2005-12-15, James Stroud <[EMAIL PROTECTED]> wrote:

>> Why insist on using broken news servers? There are plenty of
>> free news servers that carry c.l.p, you know.
>
> This I don't know. Please elucidate. I guess I could find one
> by google, eventually, but a recommendation from the list
> might save a lot of time for me in terms of the testing cycle.
> E.g., I've already tested one that should be bonafide and you
> know the result...

Hmm.  The one I used to use is gone, but here's a list:

http://www.elfqrin.com/hacklab/pages/nntpserv.php?NG=comp.lang.python&cn=on

-- 
Grant Edwards   grante Yow!  -- I can do
  at   ANYTHING... I can
   visi.comeven... SHOPLIFT!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Can I use win32 COM object in a thread?

2005-12-14 Thread Pelmen
When I try to call a method of COM object, it return error about "There
wasn't 'CoInitialize' call", or if I use thread, I have to access COM
object methods in other way?

thanks for any help

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


Re: Python packages on OS X vs Windows

2005-12-14 Thread Bugs
Have you tried the ActiveState version of Python?
http://www.activestate.com/Products/Download/Download.plex?id=ActivePython

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


Re: Python packages on OS X vs Windows

2005-12-14 Thread Alex Martelli
Kenneth McDonald <[EMAIL PROTECTED]> wrote:

> At the moment I'm doing most of my stuff on a Mac, but I've been  
> considering also getting
> a Windows laptop. One of the reasons is that I've found it very  
> difficult to get certain
> Python related things running on the Mac; for example, if one wants  
> to use the most
> up-to-date Python on the mac, rather than the one installed by Apple,
> things can get
> a bit hairy,

Such as, downloading

and doubleclicking on the package it contains?  I don't see how it could
get any less hairy than that.

> and then if one wants to go PyQT/wxPy/etc, it can get  
> even worse with
> trying to get all the compiling/linking to work.

I assume that's because the pre-built versions of these various packages
are built for Python 2.3.5 (the version Apple bundles with MacOSX)
rather than for ActivePython.  But one run of "python setup.py install",
while perhaps "worse" than doubleclicking on a pkg within a dmg, is
still not really "hairy".

> On the other hand, it seems like most of this stuff is just available
> as installers for PCs.
> Am I being naive to think that installation of most of this stuff  
> (including getting it working)
> will be much easier in the PC world?

PyQt for Windows is not available under GPL (as it is for Mac).  If
shelling out 250 pounds (plus VAT) is "much easier" for you than doing a
little compilation, or you can't use the GPL version anyway, etc, etc,
then, maybe.

Me, I'd rather stick to the Mac...!-)


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


Re: to write set of values to a file from python

2005-12-14 Thread Bengt Richter
On 14 Dec 2005 15:39:02 -0800, [EMAIL PROTECTED] wrote:

>thanks lawrence
>it did work.
>and i have one more question for you
>
>its printing the feilds name in the following way
>
>CompName
>IpAddr
>MacAddr
>
>that means each row its printing one field name, can i make it to print
>each one of the field in different columns, in this way
>
>CompName   IpAddr  MacAddr
>
>and then to fill up the values for these fields , something like this
>
>
>CompName   IpAddr   MacAddr
>XXX   192.178.23.1178.23.34.23.12
>YYY  192.189.22.11   89.23.43.12.34
>ZZZ192.179.24.45   89.23.34.12.45
>
>etc.

Ok, we'll copy your data:
 >>> data = """\
 ... CompName   IpAddr   MacAddr
 ... XXX   192.178.23.1178.23.34.23.12
 ... YYY  192.189.22.11   89.23.43.12.34
 ... ZZZ192.179.24.45   89.23.34.12.45
 ... """

and define a generator that will deliver the test data above as a rows in the 
form
of lists of items, to simulate your source of rows:

 >>> def rowsource():
 ... for line in data.splitlines():
 ... yield line.split()
 ...

See if that worked:
 >>> for row in rowsource(): print row
 ...
 ['CompName', 'IpAddr', 'MacAddr']
 ['XXX', '192.178.23.11', '78.23.34.23.12']
 ['YYY', '192.189.22.11', '89.23.43.12.34']
 ['ZZZ', '192.179.24.45', '89.23.34.12.45']

Use csv with default options, which will separate with commas.
Make a writer that will output back to the screen instead of a file,
so we can see without having to mess with an actual file:
 >>> import csv
 >>> import sys
 >>> csv_writer = csv.writer(sys.stdout) # or supply file open for writing

Write the same rows-as-item-lists as above:

 >>> for row in rowsource(): csv_writer.writerow(row)
 ...
 CompName,IpAddr,MacAddr
 XXX,192.178.23.11,78.23.34.23.12
 YYY,192.189.22.11,89.23.43.12.34
 ZZZ,192.179.24.45,89.23.34.12.45

Looks like nothing needed quoting, just comma separation.
Try something different:

 >>> csv_writer.writerow(['has space', 2.5, "has,comma", 
 >>> 'extra','fields','...'])
 has space,2.5,"has,comma",extra,fields,...

Only the comma needed special treatment.

 >>> csv_writer.writerow(['empties:', None, '',[], (), {}, False])
 empties:,,,[],(),{},False

Looks like None and '' translate to the same empty fields (nothing between 
delimiting commas)
but the other stuff is getting converted by str or repr (we'll check which 
below)

 >>> csv_writer.writerow(['empties:', None, '','(one comma for each separated 
 >>> field)'])
 empties:,,,(one comma for each separated field)

 >>> csv_writer.writerow([.1])
 0.1
 >>> .1
 0.10001

Apparently it's str, not repr being used, so you may want to convert to string 
representation
yourself, according to need. See also help(csv) for other options.

HTH

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Test the system is despised.

2005-12-14 Thread Robert Kern
James Stroud wrote:

> This I don't know. Please elucidate. I guess I could find one by google, 
> eventually, but a recommendation from the list might save a lot of time 
> for me in terms of the testing cycle. E.g., I've already tested one that 
> should be bonafide and you know the result...

I use GMane to read python-list via its newsgroup gmane.comp.python.general .
It's *slightly* different from the real comp.lang.python, but mostly just by the
Mailman-generated block at the bottom of each message.

I started using GMane so I could read c.l.py on campus and at home.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: Test the system is despised.

2005-12-14 Thread James Stroud
Grant Edwards wrote:
> On 2005-12-15, James Stroud <[EMAIL PROTECTED]> wrote:
> 
> 
>>I know this is despised, but I am actually testing this list with an 
>>email. If you knew the circles I've been running around trying to get 
>>UCLA to fix their news server for the c.l.python list, you would not 
>>blame me. The hours I've wasted on this. I just want to be able to use 
>>this list with a decent news reader (thunderbird) and the ucla news 
>>servers.
> 
> 
> Why insist on using broken news servers? There are plenty of
> free news servers that carry c.l.p, you know.
> 

This I don't know. Please elucidate. I guess I could find one by google, 
eventually, but a recommendation from the list might save a lot of time 
for me in terms of the testing cycle. E.g., I've already tested one that 
should be bonafide and you know the result...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the local mac address?

2005-12-14 Thread bonono

Daniel Crespo wrote:
> Hi, I tried:
>
> import ctypes
> import socket
> import struct
>
> def get_macaddress(host):
> """ Returns the MAC address of a network host, requires >= WIN2K.
> """
>
> # Check for api availability
> try:
> SendARP = ctypes.windll.Iphlpapi.SendARP
> except:
> raise NotImplementedError('Usage only on Windows 2000 and
> above')
>
> # Doesn't work with loopbacks, but let's try and help.
> if host == '127.0.0.1' or host.lower() == 'localhost':
> host = socket.gethostname()
>
> # gethostbyname blocks, so use it wisely.
> try:
> inetaddr = ctypes.windll.wsock32.inet_addr(host)
> if inetaddr in (0, -1):
> raise Exception
> except:
> hostip = socket.gethostbyname(host)
> inetaddr = ctypes.windll.wsock32.inet_addr(hostip)
>
> buffer = ctypes.c_buffer(6)
> addlen = ctypes.c_ulong(ctypes.sizeof(buffer))
> if SendARP(inetaddr, 0, ctypes.byref(buffer), ctypes.byref(addlen))
> != 0:
> raise WindowsError('Retreival of mac address(%s) - failed' %
> host)
>
> # Convert binary data into a string.
> macaddr = ''
> for intval in struct.unpack('BB', buffer):
> if intval > 15:
> replacestr = '0x'
> else:
> replacestr = 'x'
> macaddr = ''.join([macaddr, hex(intval).replace(replacestr,
> '')])
>
> return macaddr.upper()
>
> if __name__ == '__main__':
> print 'Your mac address is %s' % get_macaddress('localhost')
>
> It works perfect under W2K and above. But I would like to run it on
> Win98 too. Any help?
>
Sorry that I can't help you in any way but have a question myself.  Is
there an OS independent way to get this thing(regardless of how to
format it) in Python ? I know this may not matter if all you want is
Windows but there is just another thread talking about one should write
programs that is OS independent.

Is this a problem of the network library of python ?

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


Re: Bad marshal data

2005-12-14 Thread Alex Martelli
Michael McGarry <[EMAIL PROTECTED]> wrote:

> Pickle is working well for me. I do not need speed or small file size.
> Flexibility is more important for me. If speed was important I would
> write the app in C.

Coding an app in C which writes very large text files would probably be
the wrong choice for speed if the app was I/O bound (as is likely when
the files get large enough, or get pushed through some narrow bandwidth
bottleneck, e.g. on a network filesystem): using Python and writing
small binary files instead might easily get better optimization with
less effort.


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


Re: Xah's Edu Corner: Examples of Quality Technical Writing

2005-12-14 Thread Luc The Perverse
"javuchi" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Why do you have such a need of being hating everything and everybody
> and expressing it so offen?
> Can you live without hate?
> Can you let others live without your hates?

A person can live without hate, living love and working towards bettering 
humanity.

But as for people in general - I'm not so sure.  I'm not sure my opinion on 
hate - since I value people's opinions and diversity, hate seems unbecoming, 
but then so does computer gaming ;)

Westernization sweeps accross all countries though, and it is no longer 
vogue to be so self centered.   This will help with the most overt types of 
hatred.

--
LTP

:)



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


Re: Python packages on OS X vs Windows

2005-12-14 Thread SPE - Stani's Python Editor
With some good guidance, it goes much more smooth than I thought, even
for a total Mac newbie like me. For example to install the latest
Python 2.4.2 and wxPython2.6 on the Mac was very easy. You can find
instructions in the SPE Python IDE manual and also how to install SPE
on the Mac in case you want a full featured IDE as well:
http://pythonide.stani.be/manual/html/manual2.html

Here as well you'll find a lot of installers as well for MacOS X:
http://pythonmac.org/packages/

Good luck,
Stani
--
http://pythonide.stani.be

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


ANN: SPE 0.8.1.b Python IDE (complete rewrite for running files)

2005-12-14 Thread SPE - Stani's Python Editor
Release news from http://pythonide.stani.be

This release is the result of a complete rewrite of the run system.
It's now possible to run multi-threaded applications (like wxPython,
gtk, ...) with SPE and still control them through the debugger. Also
selected text can be executed in the shell.

Read more at http://pythonide.stani.be/manual/html/manual3.html (see
1.3 Running files).

New features:
* launch the debugger at any time at a running script
* launch the debugger at unhandled exceptions when running your
script
* execute selected lines as code snippets in the shell

Improved features:
* redesigned toolbar

Bug fixes:
* Show/hide shell (Mac)
* Check run (0.8.1.b)

Installation:
* See http://pythonide.stani.be/manual/html/manual2.html
* There is now an update section for MacOS X!

Contributors:
* Nir Aides (debug support)
* Thurston Stone (bug report)

Development:
* http://developer.berlios.de/mail/?group_id=4161

Donations (thanks!):
* Widhaya Trisarnwadhana

About SPE:
SPE is a python IDE with auto-indentation, auto completion, call tips,
syntax coloring, uml viewer, syntax highlighting, class explorer,
source index, auto todo list, sticky notes, integrated pycrust shell,
python file browser, recent file browser, drag&drop, context help, ...
Special is its blender support with a blender 3d object browser and its
ability to run interactively inside blender. Spe integrates with XRCed
(gui
designer) and ships with wxGlade (gui designer), PyChecker (source
code doctor), Kiki (regular expression console) and WinPdb (remote,
multi-threaded debugger).

SPE is looking for native English speakers to review its manual.

The development of SPE is driven by its donations. Anyone who donates
can ask for an nice pdf version of the manual without ads (60 pages).

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


Re: Python packages on OS X vs Windows

2005-12-14 Thread Mike Meyer
Kenneth McDonald <[EMAIL PROTECTED]> writes:
> At the moment I'm doing most of my stuff on a Mac, but I've been
> considering also getting
> a Windows laptop. One of the reasons is that I've found it very
> difficult to get certain
> Python related things running on the Mac; for example, if one wants
> to use the most
> up-to-date Python on the mac, rather than the one installed by Apple,
> things can get
> a bit hairy, and then if one wants to go PyQT/wxPy/etc, it can get
> even worse with
> trying to get all the compiling/linking to work.

Have you considered using the Unix/X distribution of Python? OS X is
ok as a Unix system, and comes with a not unreasonable X server. I
tend to install things from darwin ports, but you might prefer fink
(or even emerge, though I've pretty much given up on it).

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python packages on OS X vs Windows

2005-12-14 Thread Dan Sommers
On Wed, 14 Dec 2005 20:50:47 -0600,
Kenneth McDonald <[EMAIL PROTECTED]> wrote:

> ... I've found it very difficult to get certain Python related things
> running on the Mac ... if one wants to go PyQT/wxPy/etc, it can get
> even worse with trying to get all the compiling/linking to work.

Have you tried fink ()?

> On the other hand, it seems like most of this stuff is just available
> as installers for PCs.  Am I being naive to think that installation of
> most of this stuff (including getting it working) will be much easier
> in the PC world?

It can be like falling off a log in the Linux world.

Regards,
Dan

-- 
Dan Sommers

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


Re: IsString

2005-12-14 Thread Mike Meyer
"Tuvas" <[EMAIL PROTECTED]> writes:
> I don't know if I can help with this much, I'm still somewhat new to
> python, but it is my understanding that "simple" variable, ei, strings,
> ints, etc, although they don't have such names, behave like variables,
> ei, if you pass them to a function, the function will copy them into a
> new spot.

No, it doesn't copy them:

>>> def same_object(x, x_id):
...  return id(x) == x_id
... 
>>> a = "abc"
>>> same_object(a, id(a))
True
>>> b = 1
>>> same_object(b, id(b))
True
>>> b = 2 * 20
>>> same_object(b, id(b))
True
>>> 

> However, if you use lists, then it only passes a pointer, or
> tuples as well. Ei, I just ran this through the python IDE.

It passes a reference to the object in both cases.

 x="Test"
 def modstring(var):
>   var="Blah"
 modstring(x)
 print x
> Test
> This seems to indicate that the variable is copied, as the value didn't
> change.

Except that modstring didn't do anything to change the value of x. It
bound the name var in the modstring function to the string "Blah".

> Weither or not Python keeps the variables as pointers internally, it
> doesn't really matter.  Actually, all languages do such things,
> except assembly.

No, they don't. In a conventional language - including assembler - a
variable is a *compile-time* object that refers to a specific bit of
memory. Mentioning the name of the variable in your source causes code
to be emitted that loads the value stored in that memory. An
assignment statement causes code to be emitted to that stores a value
in that memory. By the time you get to run time, the variable per se
no longer exists - all references to it have been converted to
references to the memory it specifies.  This is grossly
oversimplified, and not true for all languages, including some that
would otherwise be considered conventional.

> Other than this, I basically see a fight on terminology, and that's
> that.

Could well be.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IsString

2005-12-14 Thread bonono

Tuvas wrote:
> I don't know if I can help with this much, I'm still somewhat new to
> python, but it is my understanding that "simple" variable, ei, strings,
> ints, etc, although they don't have such names, behave like variables,
> ei, if you pass them to a function, the function will copy them into a
> new spot. However, if you use lists, then it only passes a pointer, or
> tuples as well. Ei, I just ran this through the python IDE.
>
> >>> x="Test"
> >>> def modstring(var):
>   var="Blah"
> >>> modstring(x)
> >>> print x
> Test
>
> This seems to indicate that the variable is copied, as the value didn't
> change. Weither or not Python keeps the variables as pointers
> internally, it doesn't really matter. Actually, all languages do such
> things, except assembly.
No. They are not copied, at least not at function invokation. The
parameter in the functions scope got rebound(that is the term python
people like to use) to a new value(or object in python term as
everything in python is an object) if you use the "=" operator.

x="test"
y=["test"]
def mod_1(v):
  v="blah"

def mod_2(v):
  v[0]="blah"

mod_1(x)
print x
mod_1(y)
print y
mod_2(x)
print x
mod_2(y)
print y

You can see that neither x or y changed with mod_1, regardless whether
it is mutable or not. mod_2(x) is an error as it kind of use 'v' as an
object pointer and invoke some method on it(the object) which doesn't
exist for x. mod_2(y) works as expected, because y in this case is sort
of an object which is a container which has the "[]" method.

> I just ran the test on lists and tuples, it was the same results,
> nothing moved.
>
> Other than this, I basically see a fight on terminology, and that's
> that.

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


Re: newbie: generate a function based on an expression

2005-12-14 Thread Jacob Rael
Thanks for all the suggestions and comments!!

I will try all those suggestions just to I can figure out how they
work. For phase 1 of this project, I will probably go with the eval.

thanks again, happy hacking...

jr

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


Re: how to get select label?

2005-12-14 Thread Mike Meyer
Dan M <[EMAIL PROTECTED]> writes:
> On Wed, 14 Dec 2005 13:56:24 -0800, lli wrote:
>> I build web application. So I use CGI. I need to show select text in
>> the html page. Now I can only display select value such as '001'. But I
>> need to display its text 'AAA'.
> I'm a Python newbie, so by all means verify this answer with more
> experienced folks. But what you're running into is a limitation of
> HTML/HTTP/CGI. When your form contains a  element, the values that
> get passed to the CGI are the VALUE elements. If you want to get, for
> example, AAA then you would need to put AAA in the VALUE field.

If you leave the VALUE attribute, you'll get the contents of the
OPTION element. This saves having to duplicate the value.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: access to preallocated block of memory?

2005-12-14 Thread Grant Edwards
On 2005-12-15, Do Re Mi chel La Si Do <[EMAIL PROTECTED]> wrote:
 vxworks tasks writes to a reserved area of memory.
>
> Is it compatible with the mmap module ?

I've never written a VxWorks module, but it would only take a
dozen or two lines of code to write a Linux driver that would
impliment mmap() to allow a pre-defined block of address space
to be mapped into user space.

-- 
Grant Edwards   grante Yow!  Yow! I threw up on
  at   my window!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Test the system is despised.

2005-12-14 Thread Grant Edwards
On 2005-12-15, James Stroud <[EMAIL PROTECTED]> wrote:

> I know this is despised, but I am actually testing this list with an 
> email. If you knew the circles I've been running around trying to get 
> UCLA to fix their news server for the c.l.python list, you would not 
> blame me. The hours I've wasted on this. I just want to be able to use 
> this list with a decent news reader (thunderbird) and the ucla news 
> servers.

Why insist on using broken news servers? There are plenty of
free news servers that carry c.l.p, you know.

-- 
Grant Edwards   grante Yow!  PEGGY FLEMING is
  at   stealing BASKET BALLS to
   visi.comfeed the babies in VERMONT.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Online Ruby

2005-12-14 Thread Mike Meyer
[EMAIL PROTECTED] writes:

> Maybe a page like this for Python exists already, or it can be useful
> to create it:
> http://tryruby.hobix.com/

Working on it, in my spare time (~1hr/day). You can poke at it at
http://www.mired.org/home/mwm/try_python/, but it's *very* much not
ready for release.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda (and reduce) are valuable

2005-12-14 Thread bonono

Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, Christopher Subich wrote:
>
> > Chris Mellon wrote:
> >> functions with real names is crucial to maintainable code. The only
> >> reason to ever use a lamdba in Python is because you don't want to
> >> give a function a name, and that is just not a compelling use case for
> >> GUI events.
> >
> > Ah, but that neglects the sheer utility of delayed-evaluation
> > expressions.  Consider the key= parameter to list.sort, et. al:
> >
> > complicated_list.sort(key=lambda x: x[3])
>
> This can be written as::
>
>   from operator import itemgetter
>   complicated_list.sort(key=itemgetter(3))
>
Though I find the lambda form easier for me to understand but
itemgetter should be the preferred way as it should have some
performance advantage and sort are those kind of functions that need
it, in general.

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


Re: IsString

2005-12-14 Thread Mike Meyer
Donn Cave <[EMAIL PROTECTED]> writes:
> I would like to argue that "value" basically means the
> computational effect.  In "s = a + b", the value of "b"
> is whatever ends up applied to that "+" operator.  In
> isolation, the value of some object is its computational
> potential - the object isn't its value, rather the
> implementation of the value.  Parameter passing isn't
> a computation in this sense, and it doesn't make sense
> for it to have its own interpretation of "value".

Now you're hovering on the edge of call by name.

> Historically, the way I remember it, there was a time not too
> long ago when GvR and his minions sort of dismissed the idea
> that you needed to understand the reference/object model from
> the outset.  I mean, obviously you need to get there eventually
> if you're going to be a hard core Python programmer, but they
> wanted to see people learning to write programs, without being
> encumbered by knowledge of implementation details, and ideas
> about the difference between "variable" and "binding" are
> certainly about implementation details.

No, they're not. They're a fundamental part of the semantics of the
language. But you are right - you should be able to learn how to
program in Python without having to learn about those thing. The fact
is, you can do that - if you don't have any preconcieved notions about
what the names are and how they behave. If you have to unlearn things
from another language (like that variables have types, or values that
can be changed), then you'll need the difference explained the first
time the difference is noticable.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OO in Python? ^^

2005-12-14 Thread bonono

Donn Cave wrote:
> Really, this kind of abstraction of data types is not only well
> supported in Haskell, it can be almost a curse, at least for
> someone like myself who has fairly superficial experience with
> this kind of programming.  After all the functions have been
> zealously scrubbed clean of any trace of concrete data types and
> rendered maximally abstract, they can be a little hard to understand.
>
My experience too. An interesting thing I experienced with Haskell is
that even though it is strongly and statically typed, I seldom think
about data types when writing programs, kind of typeless to me.

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


Questions about working with character encodings

2005-12-14 Thread Kenneth McDonald
I am going to demonstrate my complete lack of understanding as to  
going back and forth between
character encodings, so I hope someone out there can shed some light  
on this.  I have always
depended on the kindness of strangers... :-)

I'm playing around with some very simplistic french to english  
translation. As some text to
work with, I copied the following from a french news site:

 Dans les années 1960, plus d'une voiture sur deux vendues aux  
Etats-Unis était fabriquée par GM.
 Pendant que les ventes s'effondrent, les pertes se creusent :  
sur les neuf premiers mois de l'année 2005,
 elles s'élèvent à 3,8 milliards de dollars (3,18 milliards  
d'euros), et le dernier trimestre s'annonce difficile.
 Quant à la dette, elle est hors normes : 285 milliards de  
dollars, soit une fois et demie le chiffre d'affaires.
 GM est désormais considéré par les agences de notation  
financière comme un investissement spéculatif.
 Un comble pour un leader mondial !

Of course, it has lots of accented, non-ascii characters. However, it  
posted just fine into both
this email program (hopefully it displays equally well at the other  
end), and into my Python
editing program (jEdit).

To start with, I'm not at all cognizant of how either the editor or  
the mail program could even
know what encodings to use to display this text properly...

Next, having got the text into the Python file, I presumably have to  
encode it as a Unicode
string, but trying something like   text = u"""désormais considéré"""  
complains to the effect
that :

 UnicodeEncodeError: 'ascii' codec can't encode character u'\x8e'  
in position 13: ordinal not in range(128)

This occurs even with the first line in the file of

 # -*- coding: latin-1 -*-

which I'd hoped would include what I think of as the latin characters  
including all those ones with
graves, agues, circonflexes, umlauts, cedilles, and so forth.  
Apparently it does not :-)

So I really have two questions:

   1) How the heck did jEdit understand the text with all the accents  
I pasted into it? More
specifically, how did it know the proper encoding to use?

   2) How do I get Python to understand this text? Is there some sort  
of coding that will
work in almost every circumstance?

Many thanks for your patience with someone completely new to this  
aspect of text handling,

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


Python packages on OS X vs Windows

2005-12-14 Thread Kenneth McDonald
At the moment I'm doing most of my stuff on a Mac, but I've been  
considering also getting
a Windows laptop. One of the reasons is that I've found it very  
difficult to get certain
Python related things running on the Mac; for example, if one wants  
to use the most
up-to-date Python on the mac, rather than the one installed by Apple,  
things can get
a bit hairy, and then if one wants to go PyQT/wxPy/etc, it can get  
even worse with
trying to get all the compiling/linking to work.

On the other hand, it seems like most of this stuff is just available  
as installers for PCs.
Am I being naive to think that installation of most of this stuff  
(including getting it working)
will be much easier in the PC world?

And on a somewhat related note, do people find ipython to be a decent  
replacement
on Windows for the fact that the Windows shell is braindead?

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


Re: IsString

2005-12-14 Thread Mike Meyer
Tom Anderson <[EMAIL PROTECTED]> writes:
>> Python does call by reference, which means that it passes pointers
>> to objects by value.
> That's not what call by reference is - call by reference is passing
> pointers to *variables* by value.

In which case, Python can't do call-by-reference at all, because it
doesn't have variable.

Of course, I think call-by-reference is passing references to
*objects* by value. 

> As a bonus, here's a similarly literal python translation of your C
> program:
>
 i = 1
 ref = "i"
 i = 2
 assert ref == "i"

I claim that's not correct, because ref can be used to change i in any
context in C. In your version, ref can only be used to change i if you
have access to the namespace that i lives in. In my version, ref can't
be used to change i at all.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Worthwhile to reverse a dictionary

2005-12-14 Thread Mike Meyer
Erik Max Francis <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED] wrote:
>> What is the difference between
>>  " d1 = {'A' : '1', 'B' : '2', 'C' : '3'} "
>> and
>> " d1 = dict(A = 1, B = 2, C = 3) "  ?
>> All of the dictionary examples I saw (python.org,
>> aspn.activestate.com,
>> Learning Python by Lutz, among others) use d={'x' : 'y'}.
>
> In the latter case the values are ints, whereas in the former they are
> strings.  But you probably didn't mean that; indeed it is the case that
>   d1 = {'A': 1, 'B': 2, 'C': 3}
> and
>   d2 = dict(A=1, B=2, C=3)
> are equivalent.

Not quite:

>>> def f():
...  a = {'a': 1, 'b': 2}
...  b = dict(a = 1, b = 2)
... 
>>> dis.dis(f)
  2   0 BUILD_MAP0
  3 DUP_TOP 
  4 LOAD_CONST   1 ('a')
  7 LOAD_CONST   2 (1)
 10 ROT_THREE   
 11 STORE_SUBSCR
 12 DUP_TOP 
 13 LOAD_CONST   3 ('b')
 16 LOAD_CONST   4 (2)
 19 ROT_THREE   
 20 STORE_SUBSCR
 21 STORE_FAST   0 (a)

  3  24 LOAD_GLOBAL  1 (dict)
 27 LOAD_CONST   1 ('a')
 30 LOAD_CONST   2 (1)
 33 LOAD_CONST   3 ('b')
 36 LOAD_CONST   4 (2)
 39 CALL_FUNCTION  512
 42 STORE_FAST   1 (b)
 45 LOAD_CONST   0 (None)
 48 RETURN_VALUE


The first form builds the dict in place, and assigns the result. The
second form invokes the "dict" object on the keyword arguments, which
function then builds the dict. They have the same effect, provided no
one has shadowed the definition of the builtin "dict" function.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ?: in Python

2005-12-14 Thread Steven Bethard
Andy Leszczynski wrote:
> How can do elegantly in Python:
> 
> if condition:
>a=1
> else:
>a=2
> 
> like in C:
> 
> a=condition?1:2

Step (1): Wait for Python 2.5[1]
Step (2): Write the code::

 a = 1 if condition else 2

STeVe

[1]http://www.python.org/peps/pep-0308.html
-- 
http://mail.python.org/mailman/listinfo/python-list


iniciante

2005-12-14 Thread tetri
alguém recomenda algum material disponível na internet para iniciar
os estudos em python?
outra coisa, peço que brasileiros (ou ao menos aqueles que me
entendem) se identifiquem, assim podemos começar discussões em
português mesmo, o que acham?

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-14 Thread Mike Meyer
[Not sure if this attribution is correct.]
> Alex Martelli wrote:
> Because of course if other languages have 1 or two frameworks, python
> needs a dozen.

People keep talking about Python's wealth of web frameworks as if it
were a bad thing. I just don't see it. Just like I like to have more
than 1 or 2 languages available for programming, I like to have more
than 1 or 2 web frameworks available for building web sites. That I
can get the flexibility I want in this area *without* having to
abandon Python is a plus for Python.

Or are the web frameworks for the languages with an impoverished
selection really that flexible? Is Ruby on Rail, for instance, really
going to do the things that Zope does well almost as well as Zope does
them, and the things that Cheetah does well almost as well as Cheetah
does them, and the things that web.py does well almost as well as
web.py does them? If that's the case, the complaint isn't "Python has
to many web frameworks", it's "Python doesn't have a good web
framework."

Thanks,
  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Xah's Edu Corner: Examples of Quality Technical Writing

2005-12-14 Thread javuchi
Why do you have such a need of being hating everything and everybody
and expressing it so offen?
Can you live without hate?
Can you let others live without your hates?

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


Re: access to preallocated block of memory?

2005-12-14 Thread Do Re Mi chel La Si Do
>>> vxworks tasks writes to a reserved area of memory.

Is it compatible with the mmap module ?



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


Re: IsString

2005-12-14 Thread Tuvas
I don't know if I can help with this much, I'm still somewhat new to
python, but it is my understanding that "simple" variable, ei, strings,
ints, etc, although they don't have such names, behave like variables,
ei, if you pass them to a function, the function will copy them into a
new spot. However, if you use lists, then it only passes a pointer, or
tuples as well. Ei, I just ran this through the python IDE.

>>> x="Test"
>>> def modstring(var):
var="Blah"
>>> modstring(x)
>>> print x
Test

This seems to indicate that the variable is copied, as the value didn't
change. Weither or not Python keeps the variables as pointers
internally, it doesn't really matter. Actually, all languages do such
things, except assembly.

I just ran the test on lists and tuples, it was the same results,
nothing moved.

Other than this, I basically see a fight on terminology, and that's
that.

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


Re: ?: in Python

2005-12-14 Thread Andy Leszczynski
Steven D'Aprano wrote:
> On Wed, 14 Dec 2005 14:09:10 -0500, Andy Leszczynski wrote:
> 
> 
>>How can do elegantly in Python:
>>
>>if condition:
>>a=1
>>else:
>>a=2
>>
>>like in C:
>>
>>a=condition?1:2
> 
> 
> I thought you wanted to do it *elegantly*?
> 
> Your first solution is perfectly elegant to my eyes, unlike that horrible
> C syntax.

I can tell you what is not elegant in the if else: approach. It is 
logically a one operation while you are forced to use varaible "a" 
twice. Fundamental flaw IMO.

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


Re: PHP = Perl Improved

2005-12-14 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

> "Tin" == Tin Gherdanarra <[EMAIL PROTECTED]> writes:

Tin> Xah Lee wrote:
>> recently i got a project that involves the use of php. In 2 days, i
>> read almost the entirety of the php doc. Finding it a breeze
>> because it is roughly based on Perl, of which i have mastery.

Tin> I suspect that you are a computer program posing as a human
Tin> usenet correspondent.

Tin> Please answer these questions: [...]

Will you accept a solution in Perl? He has mastery of that language,
you know. You might have better luck if you phrase your questions in
Perl, too, since he doesn't seem to understand it when people tell him
to bugger off in plain English.

Say, there's a thought...

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG 

iEYEARECAAYFAkOg0CUACgkQYu1fMmOQldVP9ACfSzQBq7S1QX0jA2/nA2JaC+BB
4ZoAoMOn5Qe9oJHGtINWKNBQsz879R6r
=bp6G
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question - deleting records from anydbm database

2005-12-14 Thread Steve Holden
Dan M wrote:
> I've been Googling like a mad fiend and flipping through my hard-copy
> Python books, but still haven't located the one little bit of info I need.
> 
> I've put together a simple SMTP-after-IMAP script that gets the authorized
> IP info from the mail log (I know, it's not elegant but it works). All
> works fine up until I go to scan the database of added IP addresses to
> delete the old ones. The problem is, I don't know how to drop a record
> from an anydbm database!
> 
> The database file in question is compatible with the database built using
> "makemap hash imapauth < imapauth" - in fact, I'm using makemap to check
> the file contents against what I'm expecting.
> 
> I'm adding records with code such as:
>  db = anydbm.open(accessDbPath, "w")
>  db[ipAddress] = str(time.time())
> 
> Now how can I go about deleting that record when it's too old?
> 
(untested)

try

 del db[ipAddress]

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: writing a Mail Server

2005-12-14 Thread sujata
Thank you to everyone. Looks like, I have got reading to do.

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


Re: Test the system is despised.

2005-12-14 Thread James Stroud
James Stroud wrote:
> I know this is despised, but I am actually testing this list with an 
> email. If you knew the circles I've been running around trying to get 
> UCLA to fix their news server for the c.l.python list, you would not 
> blame me. The hours I've wasted on this. I just want to be able to use 
> this list with a decent news reader (thunderbird) and the ucla news 
> servers. Unfortunately, I am going to test until it works. Trust me, 
> I've tried everything. It should not be so damn hard. How old is nntp? 
> 30 years old or more. One would think that it could be gotten right at 
> some point. Well, write back with your admonishments, they will be 
> wasted keystrokes. Sorry, I just want to read this list.
> 
> On the upside, I wouldn't be so vehement about any other list.
> 
> James

Damn. Still didn't work.

Perhaps a job is waiting for someone out there who is capable of helping 
UCLA fix this. Contact UCLA, not me. I'm terribly frustrated.

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


Test the system is despised.

2005-12-14 Thread James Stroud
I know this is despised, but I am actually testing this list with an 
email. If you knew the circles I've been running around trying to get 
UCLA to fix their news server for the c.l.python list, you would not 
blame me. The hours I've wasted on this. I just want to be able to use 
this list with a decent news reader (thunderbird) and the ucla news 
servers. Unfortunately, I am going to test until it works. Trust me, 
I've tried everything. It should not be so damn hard. How old is nntp? 
30 years old or more. One would think that it could be gotten right at 
some point. Well, write back with your admonishments, they will be 
wasted keystrokes. Sorry, I just want to read this list.

On the upside, I wouldn't be so vehement about any other list.

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


Re: Horribly noobful string question

2005-12-14 Thread SeNTry
SRY, that last bit of code got messed up. Hopefully it will look right 
now...

#define two functions first, then use them.

def loopfunc(looping):
while looping:
guess= input("guess a number. see if you can guess what I'm thinking")
if guess == number:
print "you got it!"
looping=False
playagain("")
print "looping while statement now complete"
elif guess < number:
print "nope, a little higher!"
else:
print "no, a little lower!"

def playagain(again):
again=""
again= input("would you like to play again? type '1' for yes and '2' for 
no")
if again==1:
print "great!"
loopfunc(True)
elif again==2:
print "aww!  Ok, bye then"
return
else:
print "that's not a 1 or a 2!  Try again!"
playagain("")
number=24
loopfunc(True)

>
> 


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


Re: Horribly noobful string question

2005-12-14 Thread SeNTry

"Xavier Morel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Fredrik Lundh wrote:
>> "SeNTry" wrote:
>>
>>> My first post here as I just begin to learn programming in general and
>>> python in particular.  I have all the noobie confused questions, but as 
>>> I
>>> work thru the tutorials I'm sure I'll find most my answers.
>>>
>>> This one is eluding me tho... I am working in the tutorials, writing 
>>> scripts
>>> as presented and then modifying and expanding on my own to try to learn.
>>> I'm working with one that asks the user to 'guess a number I'm 
>>> thinking',
>>> and with simple while loop, flow control and operands, returning an 
>>> answer
>>> to guess again or you got it.  I've added a 'playagain' function I've 
>>> got
>>> working, but what I want is to stop the program from crashing when 
>>> someone
>>> enters a string value instead of a int value.  I know strings are 
>>> immutable,
>>> and they can be changed to an int equivalent, but I just want the script 
>>> to
>>> recognize the input as a string and print a simple "that's not a number, 
>>> try
>>> again' type of message.  I can't find the syntax to include in the
>>> if/elif/else block to include a line that says something like,
>>
>> assuming you're using raw_input() to get the guess, you always
>> have a string (in python's sense of that word).
>>
>> what you seem to want is to check if the string contains a number
>> or not.  here's one way to do this:
>>
>> guess = raw_input("make a guess: ")
>> if guess == secret:
>> print "congratulations!"
>> elif not guess.isdigit():
>> print "that's not a number! please guess again!"
>> ...
>>
>
> that, or just write something like
>
> guess = raw_input("Make your guess > ")
> try:
> if int(guess) == secret:
> # ok
> except ValueError:
> # no good

>>
>> assuming you're using raw_input() to get the guess, you always
>> have a string (in python's sense of that word).
>>
>> what you seem to want is to check if the string contains a number
>> or not.  here's one way to do this:
>>
>> guess = raw_input("make a guess: ")
>> if guess == secret:
>> print "congratulations!"
>> elif not guess.isdigit():
>> print "that's not a number! please guess again!"
>> ...
>>
>
> that, or just write something like
>
> guess = raw_input("Make your guess > ")
> try:
> if int(guess) == secret:
> # ok
> except ValueError:
> # no good

Sry for late reply, I've been out of town.  Thanks for the responses, I'm 
just sitting down to try these out.  I'm kind of surprised there's not a 
more obvious way to handle simply identifying strings.

Anyways, here's the original code snippet from a tut. and then my modified 
effort.  I was using input instead of raw_input.  Looking at it now I'm not 
even sure why I did some of the stuff I did HAHA!  I just made functions for 
convenience and practice.  I'm sure it's laughable, but maybe you can see 
what I was doing and tell me what other errors I made just for learning...

Everything seems to work well, except when the playagain function in my 
modified code gets a '2' input to quit, it prints 'aw, ok bye then' and then 
the next line is the print from the loopfunc if statement, "looping while 
statement now complete".  If I remove the again="" line in the playagain 
function, it prints 2 times... wierd.  I put this in there because I 
suspected that the variable was remaining and wanted to clear it at the 
start of the function, but I've now read that the variable in a function is 
destroyed when the function ends... is this right?  My brain hurts...

ORIGINAL
number = 24
guess = int(raw_input('Enter an integer : '))

if guess == number:
print 'Congratulations, you guessed it.' # New block starts here
print "(but you do not win any prizes!)" # New block ends here
elif guess < number:
print 'No, it is a little higher than that' # Another block
# You can do whatever you want in a block ...
else:
print 'No, it is a little lower than that'
# you must have guess > number to reach here

print 'Done'
# This last statement is always executed, after the if statement is 
executed**MODIFIED**#define two functions first, then use them.def 
loopfunc(looping):while looping:guess= input("guess a number. 
see if you can guess what I'm thinking")if guess == number: 
print "you got it!"looping=Falseplayagain("") 
print "looping while statement now complete" #for clarification when running 
elif guess < number:print "nope, a little higher!"else: 
print "no, a little lower!"def playagain(again):again=""   #removing 
this line make the 'looping while..' statement print 2 timesagain= 
input("would you like to play again? type '1' for yes and '2' for no")if 
again==1:print "great!"loopfunc(True)elif again==2: 
print "aww!  Ok, bye then"returnelse:print "that

Re: Bad marshal data

2005-12-14 Thread Michael McGarry
Pickle is working well for me. I do not need speed or small file size.
Flexibility is more important for me. If speed was important I would
write the app in C.

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


Newbie question - deleting records from anydbm database

2005-12-14 Thread Dan M
I've been Googling like a mad fiend and flipping through my hard-copy
Python books, but still haven't located the one little bit of info I need.

I've put together a simple SMTP-after-IMAP script that gets the authorized
IP info from the mail log (I know, it's not elegant but it works). All
works fine up until I go to scan the database of added IP addresses to
delete the old ones. The problem is, I don't know how to drop a record
from an anydbm database!

The database file in question is compatible with the database built using
"makemap hash imapauth < imapauth" - in fact, I'm using makemap to check
the file contents against what I'm expecting.

I'm adding records with code such as:
 db = anydbm.open(accessDbPath, "w")
 db[ipAddress] = str(time.time())

Now how can I go about deleting that record when it's too old?

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


Re: quick unicode Q

2005-12-14 Thread Erik Max Francis
Heiko Wundram wrote:

> Most probably, the OP is asking what to do with an UTF-8 encoded string.
> 
> To decode that, just use:
> 
> s.decode("utf-8")
> 
> to get a unicode string object.

Flags in the ID3 tag specify the encoding.  It is not always UTF-8.

http://www.id3.org/id3v2.4.0-structure.txt

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   You are in the music / In the man's car next to me
   -- Sade
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: quick unicode Q

2005-12-14 Thread Heiko Wundram
Erik Max Francis wrote:
> Read it as a string, and then decode it with the .decode method.  You
> specify what encoding it's in.

Most probably, the OP is asking what to do with an UTF-8 encoded string.

To decode that, just use:

s.decode("utf-8")

to get a unicode string object.

Example:

>>> s
'\xc3\xa4\xc3\xb6\xc3\xbc'
>>> print s
ÀöÌ
>>> print s.decode("utf-8")
äöü
>>>

HTH!

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


Re: Still Loving Python

2005-12-14 Thread Paul Boddie
J�r�me Laheurte wrote:
> > P.S. Why does Google Groups have to mangle J�r�me's name
>
> I didn't see anything wrong... Encoding problem ?

The preview and subsequent re-editing page typically show trashed
non-ASCII characters in Konqueror, which doesn't usually show such
brokenness on the pages I view, but I've become accustomed to taking
evasive action and editing my messages in the re-editing page which
then seems to respect what I've typed.

Anyway, here's a straight response without preview. Let's see how it
turns out!

Paul

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

Re: how to get select label?

2005-12-14 Thread Dan M
On Wed, 14 Dec 2005 13:56:24 -0800, lli wrote:

> I build web application. So I use CGI. I need to show select text in
> the html page. Now I can only display select value such as '001'. But I
> need to display its text 'AAA'.
> 
> LLI

I'm a Python newbie, so by all means verify this answer with more
experienced folks. But what you're running into is a limitation of
HTML/HTTP/CGI. When your form contains a  element, the values that
get passed to the CGI are the VALUE elements. If you want to get, for
example, AAA then you would need to put AAA in the VALUE field.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bug? file.write('\n') produces a carriage return and a line feed

2005-12-14 Thread jcb
Thanks much.

Yes, I am using Windows.

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


Re: quick unicode Q

2005-12-14 Thread Erik Max Francis
John Morey wrote:

> I have a variable that contains a string which may or may not include 
> unicode characters, I understand that I declare a unicode string like this
> u'whatever' , the question is that when that string is read in from
> an external source (in this case an id3 tag) how do I make the
> interpretter understand that it may contain unicode?

Read it as a string, and then decode it with the .decode method.  You 
specify what encoding it's in.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   You are in the music / In the man's car next to me
   -- Sade
-- 
http://mail.python.org/mailman/listinfo/python-list


quick unicode Q

2005-12-14 Thread John Morey
I have a variable that contains a string which may or may not include 
unicode characters, I understand that I declare a unicode string like this
u'whatever' , the question is that when that string is read in from
an external source (in this case an id3 tag) how do I make the
interpretter understand that it may contain unicode?

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


Re: bug? file.write('\n') produces a carriage return and a line feed

2005-12-14 Thread Heiko Wundram
[EMAIL PROTECTED] wrote:

> ...
> 0D0A  to the file.
> 
> Is this a bug or expected behavior?
> It sure took me by surprise.

You're running Windows, right? Then, this is expected behaviour, as Windows
treats text and binary files different, extending \n to \r\n (as that is
the Windows end of line marker).

If you want to only write \n to the file, use:

f = file("t.txt","wb")

...

windows-line-feeds-are-from-hell'ly yours,
--- Heiko.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between ActivePython and Python.org

2005-12-14 Thread Trent Mick
[S.Chang wrote]
> Anyone knows the difference(s) between the Python binaries from 
> ActiveState and Python.org?

The responses to this thread so far gave most of the differences. In
summary:

- On Windows, ActivePython includes the PyWin32 extensions.
- ActivePython rolls the core Python docs and a bunch of extra doc bits
  into one package, as detailed here:
http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/about.html
- We have binary installers for more platforms:
win32-x86
linux-x86
macosx-powerpc
solaris-sparc
solaris-x86
hpux-parisc
aix-powerpc
  (And we'll likely have a few more in the future, in particular
  macosx-x86 and perhaps some newer 64-bit platforms.)
- As Neil pointed out, ActivePython does not currently have SSL bindings
  (the _ssl module) that python.org's Python builds do. We are currently
  going through the legal hurdles so that we can include those. I expect
  that by or before the Python 2.5 timeframe we'll have _ssl in
  ActivePython.
- ActivePython is free, but is not open source so, as Steve mentioned,
  you need permission if you want to *re-distribute* ActivePython.
  However, *using* ActivePython is still completely free and using tools
  like py2exe and py2app to wrap up your scripts and distribute those is
  fine.
- ActivePython provides a Windows "debug" package: a zip of the
  debug-build libs that you can install into your Python install
  (python.org installs to as of the next release[1]). This can be useful
  for some people building debug builds of Python extensions.

One of the important things is how ActivePython is NOT different:
ActivePython should be fully binary compatible with python.org builds.
This is to ensure that 3rd-party extensions built for and tested on one
will just work on the other.


[BartlebyScrivener wrote]
> The ActiveState version lags behind for a month or two in versions,

That is occassionaly true, yes, but not always. ActivePython 2.4.2 was,
I believe, a few weeks behind. 2.4.0 was released within a day or two. 


[Neil Hodgson wrote]
> It would be helpful if the ActivePython "What's Included" page listed
> which parts of the python.org distribution are not included.

Good point. I'll update those docs now for the next release.


Cheers,
Trent (the ActivePython dude at ActiveState)

[1] Distributing the Python Windows debug build libs. 
http://mail.python.org/pipermail/python-dev/2005-November/057896.html
http://mail.python.org/pipermail/python-dev/2005-December/058446.html

-- 
Trent Mick
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


bug? file.write('\n') produces a carriage return and a line feed

2005-12-14 Thread jcb
The following code in Python 2.3
f = file('t.txt', 'wt')
f.write('\n')
f.close()

writes
0D0A  to the file.

Is this a bug or expected behavior?
It sure took me by surprise.

If it is not a bug, is this behavior documented?

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


Re: lambda (and reduce) are valuable

2005-12-14 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Christopher Subich wrote:

> Chris Mellon wrote:
>> functions with real names is crucial to maintainable code. The only
>> reason to ever use a lamdba in Python is because you don't want to
>> give a function a name, and that is just not a compelling use case for
>> GUI events.
> 
> Ah, but that neglects the sheer utility of delayed-evaluation 
> expressions.  Consider the key= parameter to list.sort, et. al:
> 
> complicated_list.sort(key=lambda x: x[3])

This can be written as::

  from operator import itemgetter
  complicated_list.sort(key=itemgetter(3))

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


Re: Simple (?) question about print statement

2005-12-14 Thread Dan M
On Wed, 14 Dec 2005 15:27:58 -0800, TY wrote:

> So I guess then my next question is why does adding comma to print
> statement cause buffering, but not when you don't have comma?

Because of the line buffering. If you don't have a comma at the end, the
print statement prints the numeric value and a newline, which signals the
end of the line.

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


Re: to write set of values to a file from python

2005-12-14 Thread muttu2244
thanks lawrence
it did work.
and i have one more question for you

its printing the feilds name in the following way

CompName
IpAddr
MacAddr

that means each row its printing one field name, can i make it to print
each one of the field in different columns, in this way

CompName   IpAddr  MacAddr

and then to fill up the values for these fields , something like this


CompName   IpAddr   MacAddr
XXX   192.178.23.1178.23.34.23.12
YYY  192.189.22.11   89.23.43.12.34
ZZZ192.179.24.45   89.23.34.12.45

etc.

thanks again
yogi


Lawrence Oluyede wrote:
> Il 2005-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> ha scritto:
> > I have tried with the following code
> >
> > import csv
> > file = open("some.csv","wb")
> > writer = csv.writer(file)
> > list = ["CompName", "IpAddr", "MacAddr","OpSys"]
> > for row in list:
> > writer.writerow(row)
> >
> > file.close()
>
> writerow() wants a sequence, a string is a sequence of chars and hence
> it writes a char at time, replace with
>
> writer.writerow([row])
>
>
>
> --
> Lawrence - http://www.oluyede.org/blog
> "Anyone can freely use whatever he wants but the light at the end
> of the tunnel for most of his problems is Python"

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


Re: definition of 'polymorphism' and python

2005-12-14 Thread Mike Meyer
"gene tani" <[EMAIL PROTECTED]> writes:
> Grant Edwards wrote:
>> On 2005-12-14, Gabriel Zachmann <[EMAIL PROTECTED]> wrote:
>> > I understand the Wikipedia article on Polymorphism (
>> > http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29
>> > ) that it doesn't make sense to talk about polymorphism in a
>> > fully dynamically typed language -- does the Python community
>> > agree?
>> No.
> Excellent.  Maybe we can have a gentleman's agreement to confine all
> unfocused arguments about following terms to Artima.com and C2 wiki
> Strong, weak, static, dynamic, latent, duck typing
> polymorphism, encapsulation, delegation, 

How about we add "Call by FOO", for any FOO?

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple (?) question about print statement

2005-12-14 Thread TY
So I guess then my next question is why does adding comma to print
statement cause buffering, but not when you don't have comma?

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


Re: Still Loving Python

2005-12-14 Thread Mike Meyer
[EMAIL PROTECTED] (Bengt Richter) writes:
> On Wed, 14 Dec 2005 10:07:04 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote:
>>[EMAIL PROTECTED] (Bengt Richter) writes:
>>> A single click compiles, links and runs the resulting independent windows 
>>> .exe in a fraction of a second
>>> for the above, and I can see the hint, kill the .exe, and go on where I was.
>>Click? Yuck. If I wanted it, I've had environments where a single
>>keystroke (much better) compiled, linked and ran the resulting
>>app. Not in a fraction of a second, but that's sort of irrelevant to
>>the GUI/non-GUI question.
> You don't have to click. A single keystroke (F9) does it too ;-)

F9? Better, but not much. Especially considering that my desktop keyboard
doens't have an F9 key: http://www.tldp.org/linuxfocus/English/January1999/article75.html >.

> Just that if you are testing for a hint appearing when you mouse over a 
> button,
> it's handier to move the cursor a coule of inches and click a Delphi IDE 
> button
> with the same hand than it is to go for F9. But either way works.

That doesn't sound like a likely sequence - if the hint appears, then
you're done with that and it's time to code. If the hint doesn't
appear, then you're not done, and you have to fix the things, which
means taking your hands off the mouse to type the hint in.

> An integrated debugger that lets you step through your app and watch the 
> visuals
> happen as you step by various chunks or run to breakpoints etc is useful 
> sometimes too.

Yup. I like mine very much. But that's got nothing to do with how the
GUI is built.

> You can also do totally command-line oriented, non-GUI stuff much as you'd do 
> C, except
> in object pascal. A minimal app:

You now seem to be trying to sell a language.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: disassemble, was(How do (not) I distribute my Python progz?)

2005-12-14 Thread gene tani

Paul Boddie wrote:
> Juergen Kareta wrote:
> > look at:
> > http://www.crazy-compilers.com/decompyle/
> >
> > it's only a online service. But if it works, it would be nice to have
> > such a tool as standalone programm.
>
> And the next search result for decompyle on Google is...
>
> http://packages.debian.org/unstable/python/decompyle
>
> Get the source package from there, or check out your favourite
> distribution's package repository. Very useful for investigating and
> revealing the embarrassing secrets of closed source software, I think.
>
> Paul

http://users.cs.cf.ac.uk/J.P.Giddy/python/decompiler/decompiler.html
http://www.logilab.org/projects/pyreverse/
http://docs.python.org/lib/module-dis.html
http://docs.python.org/lib/bytecodes.html

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


Re: to write set of values to a file from python

2005-12-14 Thread Lawrence Oluyede
Il 2005-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> ha scritto:
> I have tried with the following code
>
> import csv
> file = open("some.csv","wb")
> writer = csv.writer(file)
> list = ["CompName", "IpAddr", "MacAddr","OpSys"]
> for row in list:
> writer.writerow(row)
>
> file.close()

writerow() wants a sequence, a string is a sequence of chars and hence
it writes a char at time, replace with

writer.writerow([row])



-- 
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Still Loving Python

2005-12-14 Thread Valentino Volonghi aka Dialtone
Paul Rubin  wrote:

> Glade also does something like that.

Indeed. I'd also add some lines on this.

There is a very nice designer for GTK+ applications called Gazpacho,
written in python and available here: http://gazpacho.sicem.biz/

It generates an XML file in the same Glade format (actually it's
slightly different for the Menus). It doesn't require libglade though
because it has its own .glade loader and thanks to this at load time it
can bind events using method names in your 'controller' class (which
inherits from gazpacho's Proxy class.

This means that, if you are using python, you don't even have to define
the actions and action handlers in the designer.

for example:

class LogsterClient(Proxy):

def on_connect__clicked(self, button):



def on_logster__destroy(self, window):



p = Proxy('my_ui.glade')

And it also provide an easy and flexible way to integrate additional
custom widgets in the design process.

Of course it's always possible to build powerful GUIs without using
designers at all:

http://www.lethalman.net/?p=21 

-- 
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.4
Blog: http://vvolonghi.blogspot.com
http://weever.berlios.de
-- 
http://mail.python.org/mailman/listinfo/python-list


access to preallocated block of memory?

2005-12-14 Thread Greg Copeland
I am running python on VxWorks.  In the course of operation, a vxworks
tasks writes to a reserved area of memory.  I need access to this chunk
of memory from within python.  Initially I thought I could simply
access it as a string but a string would reallocate and copy this chunk
of memory; which is not something I can have as it would waste a huge
amount of memory.  We're talking about something like 40MB on a device
with limited RAM.  I have been looking at array.  It looks promising.
What's the best route to go here?  Ideally, I would like to simply pass
in the address of the reserved block and a length, and have the memory
accessible.

Is there some existing python object/facility I can use or will I need
to create a custom module?  Any tips, hints, or pointers would
certainly be appreciated!


Thanks,

Greg

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


Re: IsString

2005-12-14 Thread Fredrik Lundh
Donn Cave wrote:

> While I agree (with another post) that there seems to be
> a difference in perspective that depends on what language
> you were using when you first heard these terms, in the
> end it really seems sort of almost disingenuous to argue
> that the "value" in question is actually a pointer.

The word "value" has a defined meaning in python:

http://docs.python.org/ref/objects.html

> (The pointer is in a practical sense a reference, so what
> if we say "pass by reference value?!"

"call by object reference" ?

as the CLU folks noted some thirty years ago (my emphasis):

"IN PARTICULAR IT IS NOT CALL BY VALUE because mutations
of arguments performed by the called routine will be visible to
the caller. And IT IS NOT CALL BY REFERENCE because access
is not given to the variables of the caller, but merely to certain
objects."

Arguing that "as long as I can define the word value/reference, it's
call-by-value/reference" is somewhat disingenuous, indeed.





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


Re: how to get select label?

2005-12-14 Thread Yuri
[EMAIL PROTECTED] wrote:
> I built a select in a form. My select is:
> print ''
> print 'ALL'
> print 'AAA'
> print 'BBB'
> print ''
> 
> I can get which item value users select. For example users select item
> 2, I can get its value "001". But now I want to get item label "AAA",
> not its value "001". How I can do this. I use python to code.

This is actually a HTML question, not python:

You're doing it almost right except that the option tag should be closed 
as always.


   ALL
   AAA
   BBB


better yet but may not be supported in all browsers (try):


   
   
   

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


Re: disassemble, was(How do (not) I distribute my Python progz?)

2005-12-14 Thread Juergen Kareta
Hi Paul,

I had looked to the same link and downloaded the package. Maybe I'll 
give it a try at the christmas holidays - hope so ;-)

Thanks
Jürgen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: to write set of values to a file from python

2005-12-14 Thread muttu2244
I have tried with the following code

import csv
file = open("some.csv","wb")
writer = csv.writer(file)
list = ["CompName", "IpAddr", "MacAddr","OpSys"]
for row in list:
writer.writerow(row)

file.close()

And the result am getting in a "some.csv" file is as below

c   o   m  p  N  a  m  e
Ip   A  d  d  r
M  a   c  A  d  d  r
O  p   S  y   s

each charatecr its printing in a different cell of excel sheet(some.csv
file).
so can i print the whole strings like "compName" "ipAddr" etc in  a
different cells(columns)

thanks and regards
yogi

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


Re: How to get the local mac address?

2005-12-14 Thread Daniel Crespo
Hi, Scott,

Thanks for your answer

>> Hi, I tried: ...
>> # Convert binary data into a string.
>> macaddr = ''
>> for intval in struct.unpack('BB', buffer):
>> if intval > 15:
>> replacestr = '0x'
>> else:
>> replacestr = 'x'
>> macaddr = ''.join([macaddr, hex(intval).replace(replacestr, '')])
>
>
>Replace the above by:
>   return '%02X' * 6 % struct.unpack('BB', buffer)

Replace all the above? I mean all this:

 # Convert binary data into a string.
 macaddr = ''
 for intval in struct.unpack('BB', buffer):
 if intval > 15:
 replacestr = '0x'
 else:
 replacestr = 'x'
 macaddr = ''.join([macaddr, hex(intval).replace(replacestr,
'')])

?

>(doesn't help with win98, though)

Sorry, but I don't understand... I would like it to get running on
Win98. I know I have to change some code here, but don't know what :(

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


Re: SVG rendering with Python

2005-12-14 Thread richard
Dennis Benzinger wrote:
> Does anybody know of a SVG rendering library for Python?

Google "python svg"


Richard

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


Re: how to get select label?

2005-12-14 Thread Lawrence Oluyede
Il 2005-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> ha scritto:
> I build web application. So I use CGI. I need to show select text in
> the html page. Now I can only display select value such as '001'. But I
> need to display its text 'AAA'.

There are tons of way to build web apps in Python and CGI is the last I
rely on. Anyway you can make a dirty trick passing in hidden HTML fields
the text values and match against.


-- 
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IsString

2005-12-14 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 "Ben Sizer" <[EMAIL PROTECTED]> wrote:
> Steven D'Aprano wrote:
> > def modify_in_place(obj):
> > """Modify an arbitrary object in place."""
> > obj = None
> >
> > x = [1, 2, 3] # mutable object
> > modify_in_place(x)
> > assert x is None
> >
> >
> > Doesn't work either.
> 
> To be fair, this isn't because the function is not pass by reference,
> but because the assignment operator reassigns the reference rather than
> altering the referent, and thus modify_in_place doesn't actually
> contain any modifying operations. With a good understanding of what
> Python's assignment operator actually does, (I believe) you can view
> Python as pass-by-reference without any semantic problems.

What he said!

While I agree (with another post) that there seems to be
a difference in perspective that depends on what language
you were using when you first heard these terms, in the
end it really seems sort of almost disingenuous to argue
that the "value" in question is actually a pointer.  (The
pointer is in a practical sense a reference, so what if we
say "pass by reference value?!"

I would like to argue that "value" basically means the
computational effect.  In "s = a + b", the value of "b"
is whatever ends up applied to that "+" operator.  In
isolation, the value of some object is its computational
potential - the object isn't its value, rather the
implementation of the value.  Parameter passing isn't
a computation in this sense, and it doesn't make sense
for it to have its own interpretation of "value".

--

Historically, the way I remember it, there was a time not too
long ago when GvR and his minions sort of dismissed the idea
that you needed to understand the reference/object model from
the outset.  I mean, obviously you need to get there eventually
if you're going to be a hard core Python programmer, but they
wanted to see people learning to write programs, without being
encumbered by knowledge of implementation details, and ideas
about the difference between "variable" and "binding" are
certainly about implementation details.

It depends on your ambitions, I suppose, whether that's really
a good idea, since there's no question that some understanding
of the principles involved has to come fairly early.  But I think
we really lose out when we try to make it be about the words -
"Python doesn't have variables"/"Does too", "Python passes by
value"/"Does not", etc.  When the words really clearly express
the right thing to anyone with a reasonable background, that's
great.  But usually, they don't.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ?: in Python

2005-12-14 Thread bonono

Andy Leszczynski wrote:
> How can do elegantly in Python:
>
> if condition:
> a=1
> else:
> a=2
>
> like in C:
>
> a=condition?1:2

a=(condition and [1] or [2])[0]

For this simple snippet, I don't think it is better than if/else, But
you can use it in map/reduce or list comprehension/generator expression.

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


Re: "0 in [True,False]" returns True

2005-12-14 Thread bonono

Mike Meyer wrote:
> [EMAIL PROTECTED] writes:
> > Steve Holden wrote:
> >> >>It would be somewhat more self-documenting, but why not just use one
> >> >>name to indicate the state and another, only meaningful in certain
> >> >>states, to indicate the callback?
> >> > Why should I do that? Checking the type of a variable is conceptually
> >> > no different form testing set membership. So what I did, was just
> >> > bringing two disjoint sets togther and working with a variable from
> >> > that union. This is all in all a rather simple mathematical idea.
> >> > And I don't see why I should put certain information into a seperate
> >> > variable. It makes as much sense as working with numbers and using
> >> > a seperate variable to store whether a particular number is postive,
> >> > even or has some other characteristic. You don't seperate information
> >> > you can easily acquire from the variable itself. So why should I
> >> > seperate this information that is aquired just as easily?
> >> Well, as you might argue, I'm not tryng to effect a change in your
> >> behaviour, I'm simply trying to point out how it could be made more
> >> rational.
> > What would be the difference in his usage and allowing Null in a RDBMS
> > column ? Or return NaN instead of raising exception for numeric
> > functions ?
>
> Having a value to indicate "no value" is, of course, perfectly
> reasonable. However, you then test *for that value*; you don't test
> the type of the value to see if it's of the right type.
>
> Once you get beyond the variable either having a valid value or not,
> it's really time to consider a different approach. As has been
> indicated, using two variables is ba well-respected method of doing
> this. Another alternative (on the spur of the moment - I have no idea
> how well this will really work) is a value-carrying "invalid value":
>
> # untested code:
> class Invalid:
> state =  'unknown'
>
> ...
>
> if self.count is Invalid:
>if self.count.state == 'unregistered':
>   # Register self.
>elif self.count.state == 'registered':
>   # Whatever
> else:
> # Deal with self.count outstanding requests
>
> Hmm. I'm not sure I like this...
>
He doesn't need to test the type, in this case.

if self.count is False:
elif self.count is True:
else:

The alternative suggested :

if self.state is False:
elif self.state is True:
else: deal with self.count

I don't see much difference. He can also use a better name to represent
True/False.

Registered=True
UnRegistered=False

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


SVG rendering with Python

2005-12-14 Thread Dennis Benzinger
Hi!

Does anybody know of a SVG rendering library for Python?

Bye,
Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   >