Re: lies about OOP

2004-12-13 Thread Tim Daneliuk
projecktzero wrote:
I know this might not be the correct group to post this, but I thought
I'd start here.
A co-worker considers himself "old school" in that he hasn't seen the
light of OOP.(It might be because he's in love with Perl...but that's
another story.) He thinks that OOP has more overhead and is slower than
programs written the procedural way. I poked around google, but I don't
know the magic words to put in to prove or disprove his assertion. Can
anyone point me toward some resources?
We do web programming. I suspect that OO apps would behave as good as
procedural apps, and you'd get the benefit of code reuse if you do it
properly. Code reuse now consists of cutting and pasting followed by
enough modification that I wonder if it was worth it to cut and paste
in the first place.
Thanks.
https://www.tundraware.com/Technology/Bullet/
--

Tim Daneliuk [EMAIL PROTECTED]
PGP Key: http://www.tundraware.com/PGP/
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can I import a module without using pythonpath?

2004-12-13 Thread Fredrik Lundh
Doug Holton wrote:

>> I'm using python 2.2, I want to import a module by referring to its relative 
>> location. The reason 
>> for this is that there is another module with the same name that's already 
>> in pythonpath( not my 
>> decision, but I got to work around it, bummer). So is there any easy way to 
>> do it?
>
> import sys, os
> sys.path.insert(0,os.path.abspath("relative path"))
> import module
> sys.path.remove(os.path.abspath("relative path"))

a try-finally clause is a pretty good idea, in this case.

you might also wish to store the calculated path, in case the module
changes the current directory.  or store the original sys.path, in case
the module messes with the path but shouldn't.  (on the other hand, if
the module is nice and well behaved, you can replace the last line with
del sys.path[0]...)

 



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


Re: New versions breaking extensions, etc.

2004-12-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Jive <[EMAIL PROTECTED]> wrote:
.
.
.
>Bit by bit, I am remembering now just how stupifyingly brain-dead the MS DLL
>scheme is.
.
.
.
Part of the trick is that it demands deep understanding
to detect the antisynergies that arise from the interac-
tions of the DLL, registry, and filesystem schemes.  I
know it was only this year that I realized the whole
installation-requires-reboot absurdity is a consequence
of DLL (mis-)design.

That's judgmental of me.  What I'm saying is *I* wouldn't
do an OS that way.  It's certain, though, that I'll never
extract as much consumer surplus as Microsoft has, so my
evaluations should count for little.
-- 
http://mail.python.org/mailman/listinfo/python-list


lies about OOP

2004-12-13 Thread projecktzero
I know this might not be the correct group to post this, but I thought
I'd start here.

A co-worker considers himself "old school" in that he hasn't seen the
light of OOP.(It might be because he's in love with Perl...but that's
another story.) He thinks that OOP has more overhead and is slower than
programs written the procedural way. I poked around google, but I don't
know the magic words to put in to prove or disprove his assertion. Can
anyone point me toward some resources?

We do web programming. I suspect that OO apps would behave as good as
procedural apps, and you'd get the benefit of code reuse if you do it
properly. Code reuse now consists of cutting and pasting followed by
enough modification that I wonder if it was worth it to cut and paste
in the first place.

Thanks.

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


Re: ANN: IPython 0.6.5 is out.

2004-12-13 Thread Fernando Perez
Fernando Perez wrote:

> I'm glad to announce the release of IPython 0.6.6.  IPython's homepage is at:

Sorry, the _title_ was incorrect.  0.6.6 is indeed a new release put out today,
I just copied an old title and missed the change.

Regards,

f

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


Re: lies about OOP

2004-12-13 Thread Steve Holden
Paul McGuire wrote:
"Jive" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

But by '86, the Joy of OOP was widely known.

"Widely known"?  Errr?  In 1986, "object-oriented" programming was barely
marketing-speak.  Computing hardware in the mid-80's just wasn't up to the
task of dealing with OO memory and "messaging" overhead.  Apple Macs were
still coding in C and Forth.  Borland didn't ship Turbo-Pascal with
Object-Oriented programming until 1989, and Turbo-C++ shipped in 1991.
Smalltalk had been around for 10 years by 1986, but it was still a
curiosity, hardly "widely known."  It wasn't until the publication of David
Taylor's "Object Technology: A Manager's Guide" in 1990 that OOP began to be
legitimized to many management decision makers, that it was more than just
"fairy dust" (as Bill Gates had characterized it in an attempt to discredit
Borland's forays into the field).
Well, that's not true either, and the fact that Bill Gates was 
denigrating it implies that he at least knew about it, even if he chose 
not to adopt it (then: of course nowadays Microsoft call almost all 
their technologies "object oriented"; sometimes this description is as 
accurate as when Gates speaks about "our open Windows environment").

I would pick the publication of "Design Patterns" in 1995 by the Gang of
Four (Gamma, Helm, Johnson, and Vlissides),  to be the herald of when "the
Joy of OOP" would be "widely known."  DP formalized a taxonomy for many of
the heuristics that had evolved only intuitively up until then.  Its
emergence reflects a general maturation of concept and practice, sufficient
to say that the Joy of OOP could be said to be "widely known."
We could all make our own choices, but anyone who's been programming 
*seriously* since the 60s will likely remember Simula as the birth of 
many oft he ideas later picked up by Alan Kay and promoted by the Xerox 
PARC SmallTalk group.

I visited that group in 1981 (after Kay left, unfortunately, and then 
being headed by Adele Goldberg, who is now coincidentally promoting the 
delights of Python at conferences like OSCON), and object-oriented 
programming was certainly something that was being taken pretty 
seriously in the academic world as a potential solution to some serious 
PLIT engineering problems.

The fact that it took the technology a relatively long time to appear 
"in the wild", so to speak, is simply the natural maturation of any new 
technology. Given that UNIX was developed in the early 1970s I'd say it 
took UNIX 20 years to start becoming mainstream. But a lot of people 
knew about it before it *became* mainstream, especially those who had to 
place their technology bets early. The same is true of object-oriented 
concepts.

I guess this is just to say that I'd dispute your contention that 
SmallTalk was a curiosity - unless you define anything of interest 
mostly to the academic world as a curiosity, in which case there's no 
way to overcome your objection. It was the first major implementation of 
an entire system based exclusively on OO programming concepts and, while 
far from ideal, was a seminal precursor to today's object-oriented systems.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help need with converting Hex string to IEEE format float

2004-12-13 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> Newbie Python programmer here, so please be patient. I have spent all
> day googling for an answer to my problem, but everything I try fails to
> work (or works from the Interpreter with a set value but not from my
> code with dynamic values).
>
> Okay, here is the general gist of the problem. I am using Python to
> parse an output file (from a MAK Logger but that is not really
> important). Now I have some data that is contained on a line in this
> file like:
>
> 80 00 00 00
>
> Each of these numbers is a Hex byte making up a four byte (32 bit
> Big-Endian) IEEE float. I have read this data into Python using
> readlines and then line.split(). This gives me:
>
> ['80', '00', '00', '00']

how about:

# convert to byte string
import struct
s = "".join([chr(int(c, 16)) for c in x])
v = struct.unpack("!f", s)

or

# convert to byte string, via the array module
import array, struct
a = array.array("B", [int(c, 16) for c in x])
v = struct.unpack("!f", )

 



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


Re: PyQt on MAC OS X

2004-12-13 Thread Michael McGarry
whamoo wrote:
Michael McGarry <[EMAIL PROTECTED]> wrote:

thanks that did the trick!!!
One problem is my Window created in Qt appears underneath all others on
the screen and focus never goes completely onto this window. Kind of weird.
Any ideas?

You must use pythonw for graphics application =)
So launch the script with pythonw instead of python ;-)
Thanks using pythonw did the trick.
I appreciate everyone's help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: gather information from various files efficiently

2004-12-13 Thread Peter Hansen
Keith Dart wrote:
Sigh, this reminds me of a discussion I had at my work once... It seems 
to write optimal Python code one must understand various probabilites of 
your data, and code according to the likely scenario. 
And this is different from optimizing in *any* other language
in what way?
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: [dictionary] how to get key by item

2004-12-13 Thread Skip Montanaro

Egor> i know how to get item by key
...
Egor> but i wonder how to get key by item

Assuming your dictionary defines a one-to-one mapping, just invert it:

>>> forward = {10 : 50, 2 : 12, 4 : 43}
>>> reverse = dict([(v,k) for (k,v) in forward.iteritems()])
>>> print forward
{10: 50, 4: 43, 2: 12}
>>> print reverse
{50: 10, 43: 4, 12: 2}

That doubles your storage, so you'll have to trade that off against the
speed gain of not having to loop over the entire dictionary.

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


Help need with converting Hex string to IEEE format float

2004-12-13 Thread i_vincent
Hi all,

Newbie Python programmer here, so please be patient. I have spent all
day googling for an answer to my problem, but everything I try fails to
work (or works from the Interpreter with a set value but not from my
code with dynamic values).

Okay, here is the general gist of the problem. I am using Python to
parse an output file (from a MAK Logger but that is not really
important). Now I have some data that is contained on a line in this
file like:

80 00 00 00

Each of these numbers is a Hex byte making up a four byte (32 bit
Big-Endian) IEEE float. I have read this data into Python using
readlines and then line.split(). This gives me:

['80', '00', '00', '00']

I am then reading these in as:

wib[0] + wib[1] + wib[2] + wib[3] = 800 as a string

Now this is the point where I get stuck, I have tried various ways of
implementing the pack/unpack methods of the struct module but with no
luck.

One example I tried was:

wibble = struct.unpack("f", struct.pack("l", long(conv_str, 16)))
OverflowError: long int too large to convert to int

If I follow the examples I have found on the net using a set value of
0x8000 in them, everything works fine from the interpreter line.

Arrrg.

Everything has worked really easily up this point but I am now stuck
completely, I would be grateful for any help people can offer.
Regards

Ian Vincent

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


Re: Regexp problem, which pattern to use in split

2004-12-13 Thread Hans Almåsbakk
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:


> >>> import csv
> 
> http://online.effbot.org/2003_08_01_archive.htm#librarybook-csv-module
> 

This seems be just the thing I need.

Now ofcourse, another problem arouse:
The csv module is new in Python 2.3.

hans:~# python -V
Python 2.1.3

Is there a relatively hassle-free way to get the csv module working with
2.1? The server is running Debian stable/woody, and it also seemed 2.2 can
coexist with 2.1, when I checked the distro packages, if that is any help.

Regards
-- 
Hans Almåsbakk
-remove .invalid for correct email
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some help quickly

2004-12-13 Thread Thomas Guettler
Am Tue, 14 Dec 2004 04:46:24 -0800 schrieb Allan Irvine:

> HI
> 
> Hope this is the right place for this, I am new. I have a spec to
> create
> a (dual screen) framework application that
> 
> 1 displays mp3, flash, jpegs etc. on top screen
> 2: displays buttons on bottom screen which alter image when a key is
> pressed.

What operating system do you use?

Please choose a better subject next time.

"need some help quickly": I don't think the
application you are looking for is done quickly.

 Thomas


-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: Looking for a coder to do some work

2004-12-13 Thread John Hunter
> "Cameron" == Cameron Laird <[EMAIL PROTECTED]> writes:

Cameron> I don't understand the last sentence; in particular,
Cameron> "fort hsi" is beyond my power to decode unambiguously.

"for this", clearly 

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


Re: RegEx: find all occurances of a single character in a string

2004-12-13 Thread Fredrik Lundh
Franz Steinhaeusler wrote:
> given a string:
>
> st="abcdatraataza"
>^   ^ ^ ^ (these should be found)
> I want to get the positions of all single 'a' characters.

for m in re.finditer("a+", st):
if len(m.group()) == 1:
print m.start()

or, perhaps:

indexes = [m.start() for m in re.finditer("a+", st) if len(m.group()) == 1]

 



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


Re: Regexp problem, which pattern to use in split

2004-12-13 Thread Matthias Huening
Hans Almåsbakk (14.12.2004 16:02):
Any pointer will be greatly appreciated. Maybe I'm attacking this problem
the wrong way already from the start? (Not that I can see another way
myself :)
Hans, did you try the csv module in the Python library?
Matthias
--
http://mail.python.org/mailman/listinfo/python-list


[dictionary] how to get key by item

2004-12-13 Thread Egor Bolonev
saluton al ciuj
i know how to get item by key
==
dict = {10 : 50, 2 : 12, 4 : 43}
print dict[2]
12
but i wonder how to get key by item
print dict[12]
2
==
is there a more fast way than that one (my dictionary is really big)
==
dict = {10 : 50, 2 : 12, 4 : 43}
item = 12
for key in dict.keys():
if dict[key] == item:
print key
break
==
--
http://mail.python.org/mailman/listinfo/python-list


Re: Organising data within a program

2004-12-13 Thread James Stroud
Python is an object oriented (OO) language. The very best thing if you have a 
lot of time is to learn the language fully, read several books on database 
design, and implement a gui driven app, OO from top to bottom.

If you need to get something to work before you have time to become a 
pythonologist, try an array of dictionaries (AoD), a datastructure I find 
very handy in a pinch. Here are some patterns for you to think about (also 
have some masochistic fun trying to do something similar in perl--now try in 
perl without pointers if you cheated!):

#
# my_aod.py : an aod example module
#

# top of your module
import pickle

# saving your database (3 steps recommended)
def my_save_aod(aod,filename):
  afile = open(filename,"w")
  pickle.dump(aod,afile)
  afile.close()

# load your database (3 steps recommended)
def my_load_aod(filename):
  afile = open(filename)
  an_aod = pickle.load(afile)
  afile.close()
  return an_aod

# get a subset whose records match the key
def my_aod_find(aod,akey,avalue):
  sub_aod = []
  for element in aod:
if element[akey] == avalue:
  sub_aod.append(element)
  return sub_aod

# a simple key based sort
def my_aod_sort(aod,akey):
  return_aod = aod[:]
  return_aod.sort(lambda x,y : cmp(x[akey],y[akey]))
  return return_aod
#
# methinks a module hath I begun
#
# end my_aod.py



###
# example usage of an aod (new file)
#

from my_aod import *

# some records to start you off
bob = {"name":"Bob","spouse":"Carol","phone":"8675309"}
carol = {"name":"Ted","spouse":"Alice","phone":"5551212"}
ted = {"name":"Alice","spouse":"Ted","phone":"5551212"}
alice = {"name":"Carol","spouse":"Bob","phone":"8675309"}

# adding records arbitrarily
database = [bob]
database.extend([carol,ted])
database.append(alice)

# playing with find and sort
for person in my_aod_find(database,"name","Bob"):
   print "name:", person["name"], "; spouse:", person["spouse"]

for person in my_aod_sort(database,"name"):
   print "name:", person["name"]

for person in my_aod_sort(database,"spouse"):
   print "name:", person["name"], "; spouse:", person["spouse"]

my_save_aod(database,"people.pkl")

new_db = my_load_aod("people.pkl")

for person in new_db:
  print "name:", person["name"], "; spouse:", person["spouse"]





On Monday 13 December 2004 03:06 pm, Nick Evans wrote:
> Hey all,
> I am currently working on a simple program (small group membership
> database) just to get to grips with the language (bit of a newbie here :-))
> and am wondering about the best way of organising the data within the
> program.
>
> >From my understanding I would have something like person1
>
> =("name","address","phone","subs-due")
> Then you would putmembershipdatabase = (person1, person2, personX)
> etc
> Now is this the best way of organising this data within the program or is
> there a better "known" way?
>
> Also I want to just store this info to a standard txt file. Probably CSV or
> something. Is there any particular way I should be saving this data to
> file?
>
>
> Thanks in advance
>
> Nick

-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
611 Charles E. Young Dr. S.
MBI 205, UCLA 951570
Los Angeles CA 90095-1570
http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-13 Thread Jive

"Cameron Laird" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Tcl went through this epiphany a few years, and has largely,
> though not exclusively, committed to use of the once-more-
> redirected API called Stubs http://wiki.tcl.tk/stubs >.
> Some Tcl-ers are orgasmic about the wonders of Stubs, some
> ignore it, a few don't like it, and most, perhaps, aren't
> even aware of its existence.  Performance doesn't appear to
> be much of an issue, though.

It uses function pointer tables (like COM), but in the "other direction"
apparently.

Bit by bit, I am remembering now just how stupifyingly brain-dead the MS DLL
scheme is.
Back in '87 or so, I wrote a better dynamic linker (for a Unix) in a couple
of days.





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


Re: Python mascot proposal

2004-12-13 Thread Jive
P.s.  I never could stand Beanie and Cecil.


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


Re: Regexp problem, which pattern to use in split

2004-12-13 Thread Fredrik Lundh
Hans Almåsbakk wrote:

> These lines are in a csv file exported from excel.

> Any pointer will be greatly appreciated. Maybe I'm attacking this problem
> the wrong way already from the start? (Not that I can see another way
> myself :)

>>> import csv

http://online.effbot.org/2003_08_01_archive.htm#librarybook-csv-module

 



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


Re: Python mascot proposal

2004-12-13 Thread Jive
I've yet to see a Python logo that I thought was really good.  The cartoon
green snake icon is okay, I guess, if a bit cutesy for my taste.

Random thoughts:  It is unreasonable to use the name "Python" and not expect
people to associate it with a snake.  I say that although I'm a big Python
(Monte) fan from the beginning.  I think it would be a bad idea to market
the etymological connection between Python the language and the comedy
group.  Always remember that most people are pig-ignorant philistines.
Besides, Monte Python stuff is trademarked and copyrighted..  And what have
you got against snakes, huh?  Huh?

Jive


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


Re: [dictionary] how to get key by item

2004-12-13 Thread Skip Montanaro

Fredrik> Skip Montanaro wrote:
>> That doubles your storage

Fredrik> careful: it creates another dictionary structure with the same
Fredrik> size as the first one, but it doesn't copy the objects in the
Fredrik> dictionary.

Yes, sorry.  The OP indicated the original dictionary was very big, so it
seemed like duplicating the dictionary storage would potentially be costly
since dictionaries hold extra storage (on average, twice the storage needed
to hold the references to its keys?) to support O(1) average time lookup.

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


RegEx: find all occurances of a single character in a string

2004-12-13 Thread Franz Steinhaeusler
given a string:

st="abcdatraataza"
^   ^ ^ ^ (these should be found)
I want to get the positions of all single 'a' characters.
(Without another 'a' neighbour)

So I tried: 
r=re.compile('[^a]a([^a]') 

but this applies only for 
the a's, which has neighbours.
So I need also '^a' and 'a$'.

Am I doing something wrong? 
Is there a easier solution?
How can I quickly get all these positions?

Thank you in advance.
-- 
Franz Steinhaeusler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do I "peek" into the next line?

2004-12-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

>I should have also said that I am using the same file handle.
> So suppose the file handle is fp
> then I read some lines from fp and I hand it over to other
> functions that read other things from fp (in an ordered manner).

another part of your program?  so why not use one of the wrappers
that people have posted?  or just pass the extra line to the next step:

while 1:
s = file.readline()
if not s or s[0] == "#":
break
# process lines that belong to section 1

while 1:
# process lines that belong to section 2
if not s or s[0] == "#":
break
s = file.readline()

(etc)

 



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


RE: Suggestion for "syntax error": ++i, --i

2004-12-13 Thread Robert Brewer
Terry Reedy wrote:
> "Petr Prikryl" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
> >Summary: In my opinion, the C-like prefix
> >increment and decrement operators (++i and --i)
> 
> You could propose to the author of Pychecker that he include, 
> if possible, an option to check for and warn about '++', '--'.

+1

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


Re: lies about OOP

2004-12-13 Thread Stefan Seefeld
Craig Ringer wrote:
On Tue, 2004-12-14 at 16:02, Mike Thompson wrote:

I would pick the publication of "Design Patterns" in 1995 by the Gang of
Four (Gamma, Helm, Johnson, and Vlissides),  to be the herald of when "the
Joy of OOP" would be "widely known."  DP formalized a taxonomy for many of
the heuristics that had evolved only intuitively up until then.  Its
emergence reflects a general maturation of concept and practice, sufficient
to say that the Joy of OOP could be said to be "widely known."

In actual fact, virtually all the design patterns came from the 
Interviews C++ GUI toolkit written in the early '90s. What an utterly 
brilliant piece of work that was.

As somebody who has just been bowled over by how well Qt works, and how
it seems to make OOP in C++ work "right" (introspection, properties,
etc), I'd be interested in knowing what the similarities or lack thereof
between Qt and Interviews are.
Qt provides widgets that a client app. can compose into a GUI.
InterViews provides 'glyphs' [*] that form a scene graph in a display
server. Although InterViews usually was compiled into a client-side
library, it provided all the functionality required by a display server
such as redisplay and pick traversals. Indeed, the X Consortium
supported InterViews (and its successor Fresco) for a while as the next
generation for its 'X Windowing System', until it was dropped (for
mostly political reasons, as usual) about '95.
(Fresco had been nominated, together with OpenDoc, as candidates for an
'Compound Document Architecture' RFP on the Object Management Group.
OpenDoc won.)
[*] The term 'glyph' reflexts the fact that the scene graph nodes in
InterViews are extremely fine-grained, i.e. glyphs can represent
individual characters or elements of vector graphics such as paths.
That's unlike any conventional 'toolkit' such as Qt, where a 'widget'
is quite coarse-grained, and the display of such 'widgets' is typically
not that of a structured graphic, but procedural.
Regards,
Stefan
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you master list comprehensions?

2004-12-13 Thread Will Stuyvesant
Okay that was fun.  Enlightening as I hoped.  unroll() in Python, for
arbitrary depth, _flatten in Tkinter (what else is in Tkinter!), sum()
abuse.

The sum(data,[]) was funniest, it works like ((['foo','bar'] + []) +
['my','your']) + ['holy','grail'].  Before I think of such things I
have already coded an algorithm in imperative style.  Guess I have not
been exposed to functional programming enough.

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


Re: PyQt on MAC OS X

2004-12-13 Thread glenn andreas
In article <[EMAIL PROTECTED]>,
 Michael McGarry <[EMAIL PROTECTED]> wrote:

> One problem is my Window created in Qt appears underneath all others on 
> the screen and focus never goes completely onto this window. Kind of weird.
> 
> Any ideas?
> 

If the application is not properly bundled you will see symptoms like 
this - perhaps this is the problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: do you master list comprehensions?

2004-12-13 Thread Fredrik Lundh
Max M wrote:

>> I tried funnies like [[w for w in L] for L in data],
>> that is correct syntax, but you'd never guess.
>
> That is absolutely correct. It's not a funnie at all. If you find it odd it's 
> only because you are 
> not used to list comprehensiones.

well, syntactically correct or not, it doesn't do what he want...

> In that case you might be more comfortable with:
>
> data = [['foo','bar','baz'],['my','your'],['holy','grail']]
> result = []
> for l in data:
> result += l

how about (slightly evil):

result = []; map(result.extend, data)

 



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


Re: gather information from various files efficiently

2004-12-13 Thread Keith Dart
Fredrik Lundh wrote:
...
if dct.has_key(a):
   dct[a].append(b)
else:
   dct[a] = [b]

the drawback here is that if the number of collisions are high, you end
up doing lots of extra dictionary lookups.  in that case, there are better
ways to do this.
Sigh, this reminds me of a discussion I had at my work once... It seems 
to write optimal Python code one must understand various probabilites of 
your data, and code according to the likely scenario. 8-) Now, perhaps 
we could write an adaptive data analyzer-code-generator... ;-)




--
   \/ \/
   (O O)
-- oOOo~(_)~oOOo
Keith Dart <[EMAIL PROTECTED]>
public key: ID: F3D288E4

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


Re: Python mascot proposal

2004-12-13 Thread Adam DePrince
On Mon, 2004-12-13 at 14:50, James Stroud wrote:
> As far as python.png below is concerned, I am reminded of the structure of 
> the 
> HIV virus: http://www.avert.org/pictures/hivstructure.htm
> 
> Pleasing to virologists and drug companies, but as a single, computer-type 
> guy, it makes my skin crawl in more ways than one.
> 
> On Sunday 12 December 2004 07:40 pm, Brian Beck wrote:
> > Here are a couple of images/logos (quite a bit
> > different from a mascot) I've been working on...
> >
> > http://exogen.cwru.edu/python.png
> > http://exogen.cwru.edu/python2.png
> >
> > If anyone can think of a way to break free of the reptile-oriented
> > thought process but maintain clear, symbolic imagery, I'd love to see
> > more suggestions or renditions!

The notion of python as a meme, a mental virus, something ubiquitous,
invasive and unavoidable like the common cold or a half time ad isn't
bad.  A rebellion against the accusations made by some that open source
code is viral would be nice.

But I agree, python.png is a bit harsh.  It screams "rigid,
militaristic, violent."  It is also dangerous; if I saw that on the
bumper of an overturned car I wouldn't stop to help -- I'd run like
hell.  We don't want Python aficionados to die from lack of medical care
while hazmat teams look up arcane symbols on underpowered field hardened
laptops while wearing inch thick gloves.

When I think of Python in emotional terms.  A plush toy like Tux is more
appealing.

As for python2.png ... does the snake get all smushed up in the gear if
it turns? 


Adam DePrince 


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


Re: Path problem

2004-12-13 Thread Lars Yencken
On 13/12/2004, at 6:39 PM, Binu K S wrote:
sys.path[0] will contain the path to the script.
From the sys module documentation:
"As initialized upon program startup, the first item of this list,
path[0], is the directory containing the script that was used to
invoke the Python interpreter. If the script directory is not
available (e.g. if the interpreter is invoked interactively or if the
script is read from standard input), path[0] is the empty string,
which directs Python to search modules in the current directory first.
Notice that the script directory is inserted before the entries
inserted as a result of PYTHONPATH."
Thanks, that's very helpful!!! That's fixed up a lot of scripts of mine 
already, since many rely on an additional R script.

As to finding the path to my project root, I've managed to get the 
other pathconf module going. Yay!

Thanks Binu and Limodou for your help.
Lars
--
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a coder to do some work

2004-12-13 Thread Diez B. Roggisch
Have you seen freevo?

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: system requirements for python 2.4

2004-12-13 Thread Dave Reed
On Monday 13 December 2004 18:17, Martin v. Löwis wrote:
> ben wrote:
> > I'm trying to upgrade python from 2.2 to 2.4 on a RH9 system, and 
can't
> > find any rpm that will let me install it.
> > Is FC3 required for python 2.4?
> 
> No. However, you may have to build Python yourself. Try using the 
source
> RPM; if that fails to work, either correct the spec file, or build
> directly from the pydotorg sources.
> 
> Regards,
> Martin


And you don't want to install an rpm with 2.4 that overwrites the 2.2 
version that came with Red Hat. Many of the Red Hat configurations 
tools rely on the existing 2.2 version so you need to keep it there.

You want to install python 2.4 somewhere else (/usr/local is the usual 
place).

It really isn't difficult. Grab the .tgz file and untar it, cd into the 
python directory, execute "./configure; make;make install" assuming you 
have write permissions on /usr/local; if not su to root before doing 
"make install".

Dave



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


Re: system requirements for python 2.4

2004-12-13 Thread "Martin v. Löwis"
ben wrote:
I'm trying to upgrade python from 2.2 to 2.4 on a RH9 system, and can't
find any rpm that will let me install it.
Is FC3 required for python 2.4?
No. However, you may have to build Python yourself. Try using the source
RPM; if that fails to work, either correct the spec file, or build
directly from the pydotorg sources.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: while 1 vs while True

2004-12-13 Thread Steve Holden
Raymond Hettinger wrote:
Dan Bishop wrote:
Out of pure curiousity,
Why wasn't 'While True' optimized also?

Probably has something to do with "True" and "False" not being
constants.

[Nick Coghlan]
Yup. Even 'None' only just became a constant in 2.4.
I don't know if 'True' and 'False' are in line for similar treatment (there
are
obvious backwards compatibility issues in doing so).

It is unlike to before Py3.0.  Making them constants would break the reams of
compatability code:  True, False = (1==1), (1!=1).
It was unfortunate that so many people chose to use that for 
compatibility, when if they'd used the same code that the win32all 
extensions did they could have retained backward compatibility even 
across a change to constants:

try:
True
except AttributeError:
True, False = (1==1), (1!=1)
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Automate Python-2.4 Installs on Windows

2004-12-13 Thread Fredrik Lundh
Martin v. Löwis wrote:

> I personally recommend
>
> http://www.python.org/2.4/msi.html
>
> to learn about automatic installation.

which might be great if you know how things work, but is bloody confusing
if you don't.  most importantly, how do you set properties?  a couple of larger
examples wouldn't hurt (which was Brad's point, I think).

 



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


Re: while 1 vs while True

2004-12-13 Thread Peter Otten
Fredrik Lundh wrote:

> Steve Holden wrote:
> 
>> It was unfortunate that so many people chose to use that for
>> compatibility, when if they'd used the same code that the win32all
>> extensions did they could have retained backward compatibility even
>> across a change to constants:
>>
>> try:
>> True
>> except AttributeError:
>> True, False = (1==1), (1!=1)
> 
> that doesn't work, though:
> 
> $ python2.1 test.py
> Traceback (most recent call last):
>   File "test.py", line 2, in ?
> True
> NameError: name 'True' is not defined


Fixing the exception type doesn't help if the change is implemented like the
constancy of None:

>>> try:
... None
... except NameError:
... None = object()
...
SyntaxError: assignment to None

Another workaround seems viable:

>>> globals()["None"] = "Evil Nun"
>>> None
>>>

Peter

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


Re: PyQt on MAC OS X

2004-12-13 Thread Michael McGarry
Kevin Walzer wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
I've assembled a binary installer for the native version of PyQt. See
http://www.wordtech-software.com/pyqt-mac.html
I built it on Panther. Not sure if it will work on Jaguar, but you're
welcome to give it a try.

Michael McGarry wrote:
| Hi,
|
| I'm trying to get PyQt up and running under Mac OS X 10.2.8, but
| can't get past configuring sip.
|
| I installed fink's qt3-3.2.3-2 and restarted my shells to get
| qt3's environment variables QTDIR and QMAKESPEC.
|
| I downloaded sip-4.1 from
| http://www.river-bank.demon.co.uk,
| unpacked it, ran
|
| python configure.py
|
| and got this error:
|
| Error: /sw/share/qt3/mkspecs/darwin-g++/qmake.conf: macro
| 'QMAKE_LIBDIR/$(TARGET1)' is not defined.
|
|
| Any ideas?
|
| Michael
- --
Cheers,
Kevin Walzer, PhD
WordTech Software--Open Source Applications and Packages for OS X
http://www.wordtech-software.com
http://www.smallbizmac.com
http://www.kevin-walzer.com
mailto:[EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (Darwin)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFBvb9CJmdQs+6YVcoRAsv2AJ4rkwZ2kO8kPcBKoZ5h1F8vEof+lwCeNO8n
rK8yurwPQaJFH8yK6PlbOtg=
=0LQg
-END PGP SIGNATURE-
Kevin,
thanks that did the trick!!!
One problem is my Window created in Qt appears underneath all others on 
the screen and focus never goes completely onto this window. Kind of weird.

Any ideas?
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you master list comprehensions?

2004-12-13 Thread Max M
Fredrik Lundh wrote:
Max M wrote:

I tried funnies like [[w for w in L] for L in data],
That is absolutely correct. It's not a funnie at all.
well, syntactically correct or not, it doesn't do what he want...
Doh! *I* might not be used to list comprehensions then... You are right.
That example could have been expressed more clearly as:
result = data
;-)
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a coder to do some work

2004-12-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Allan Irvine <[EMAIL PROTECTED]> wrote:
>HI
>>
>> Hope this is the right place for this, I am new. I have a spec to
>create
>> a (dual screen) framework application that
>>
>> 1 displays mp3, flash, jpegs etc. on top screen
>> 2: displays buttons on bottom screen which alter image when a key is
>> pressed.
>>
>> The hardware is a dell pc basically, no mouse and the keyboard is a
>> simple 8 key pad that outputs numbers 1-8 (I think but can be
>mapped).
>>
>> I am looking for the best way to create this and tools to use etc.
>>
>> The system is basically an information kiosk like you see in airports
>> etc. the presentation screen on top may show several borderless
>frames
>> containing differing media.
>>
>> Hope you can help - any thoughts welcome
>Am willing to pay fort hsi to be done
>

I don't understand the last sentence; in particular, "fort hsi" is
beyond my power to decode unambiguously.

I suspect that others have more current experience with kiosk-style
setups.  It strikes me that Python might have a particular advantage
at work such as this, which combines curses-level input with graphical
output.  I suspect a VB, or, more generally, "forms painter" programmer
would be lost without his usual point-and-click model, while, to 
Tkinter of wxPy, it's all just scripts anyway.

What's your real target?  Do you want to program this yourself, and
just get help, or do you prefer a specialist just create a turnkey
package and hand it over to you?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: building extension modules under 2.4 / cygwin

2004-12-13 Thread "Martin v. Löwis"
John Hunter wrote:
  the procedure entry point _ctype could not be located in the dynamic
  link libary msvcr71.dll
This sounds like a bug in the Cygwin linker or header files to me.
I cannot fully check, but it seems to me that msvcr71.dll does not
have a _ctype variable. Instead, the is* functions (which may have
traditionally used _ctype - can't check that, either) are now
implemented through function calls. Can you (e.g. using nm) find
out where the reference to _ctype originates from?
If you remove usage of _ctype in your extension module (e.g. by not
using isupper() and the like), it probably will work fine.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: how do I "peek" into the next line?

2004-12-13 Thread Adam DePrince
On Mon, 2004-12-13 at 16:24, [EMAIL PROTECTED] wrote:
> OK, I am sorry , I did not explain my problem completely.
> I can easily break from the loop when I see the character in a line
> that I just read; however my problem involves putting back the line I
> just read since if I have seen this special character, I have read one
> line too many. Let me illustrate
> suppose the file has 3 lines
> 
> line1.line1.line1
> >line2.line2.line
> line3.line3.line3
> 
> now suppose I have read the first line already.
> then I read the second line and notice
> that there is a ">" in front (my special character)
> then I want the put back the second line into the
> file or the stdin.
> 
> An easy way is if i read all the lines in to an array
> and then I can put back the line with the special
> character back into this array. However,
> this file I am readding is huge! and I can read
> it all in one swoop (not enough memory).
> 
> for x in stdin:
> if x[0]==">":
>  put back the x some how... <-
> break
>   else:
>   print x
> 
> I hope this is clear
> thanks

class stackfile:
def __init__( self, f ):
self.f = f
self.stack = []

def readline( self ):
if len( self.stack ):
return self.stack.pop()
return self.f.readline()

def unreadline( self, lastline ):
self.stack.append( lastline )



if __name__=="__main__":
import StringIO

f = stackfile(StringIO.StringIO("a\nb\nc\nd\ne\nf\ng\n"))
# You would say: myfile = stackfile( stdin ) 

line = f.readline()
print line,

line = f.readline()
print line,

line = f.readline()
print line,

f.unreadline( line )

line = f.readline()
print line,

line = f.readline()
print line,

Running this prints:

a
b
c
c
d

Hope this helps.


Adam DePrince 


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


Re: Python vs. Perl

2004-12-13 Thread Ian Bicking
Jon Perez wrote:
Michael McGarry wrote:
I intend to use a scripting language for GUI development and front end 
code for my simulations in C. I want a language that can support SQL, 
Sockets, File I/O, and shell interaction.

In my experience, Python is definitely much more suitable than Perl
for the first four areas mentioned in the last sentence.  For the
last area, I'm not sure, but Python's capabilities in this area are
also quite good.
Shell interaction (or rather, external process interaction) is a lot 
better with Python 2.4's subprocess module.  Better or worse than Perl? 
 I'm not sure; generally I'd guess better, as it avoids the shell with 
all the shell's issues, and provides a more controlled programmatic way 
of interacting with subprocesses.  OTOH, Perl might have perfectly good 
modules for doing the same thing.  I can only say it's been missing for 
a while in Python, and it's good to see this done right.

--
Ian Bicking  /  [EMAIL PROTECTED]  /  http://blog.ianbicking.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: while 1 vs while True

2004-12-13 Thread Fredrik Lundh
Steve Holden wrote:

> It was unfortunate that so many people chose to use that for compatibility, 
> when if they'd used 
> the same code that the win32all extensions did they could have retained 
> backward compatibility 
> even across a change to constants:
>
> try:
> True
> except AttributeError:
> True, False = (1==1), (1!=1)

that doesn't work, though:

$ python2.1 test.py
Traceback (most recent call last):
  File "test.py", line 2, in ?
True
NameError: name 'True' is not defined

 



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


Re: gather information from various files efficiently

2004-12-13 Thread Richie Hindle

[Keith]
> Sigh, this reminds me of a discussion I had at my work once... It seems 
> to write optimal Python code one must understand various probabilites of 
> your data, and code according to the likely scenario. 8-)

s/Python //g

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: RegEx: find all occurances of a single character in a string

2004-12-13 Thread Franz Steinhaeusler
On Tue, 14 Dec 2004 14:19:35 +0100, "Fredrik Lundh"
<[EMAIL PROTECTED]> wrote:

>Franz Steinhaeusler wrote:
>> given a string:
>>
>> st="abcdatraataza"
>>^   ^ ^ ^ (these should be found)
>> I want to get the positions of all single 'a' characters.
>
>for m in re.finditer("a+", st):
>if len(m.group()) == 1:
>print m.start()
>
>or, perhaps:
>
>indexes = [m.start() for m in re.finditer("a+", st) if len(m.group()) == 1]
>
> 
>
>

Great!

thank you for your quick and helpful reply!

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


Re: system requirements for python 2.4

2004-12-13 Thread ben
Ah, I figured I would have to resort to that.

Thanks.

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


Re: Automate Python-2.4 Installs on Windows

2004-12-13 Thread "Martin v. Löwis"
Brad Tilley wrote:
Windows users may find this of interest:
http://filebox.vt.edu/users/rtilley/downloads/automatic_python_install.html
It gives me a dialog 'Enter username and password for "Authentication"'.
What username and password should I use?
I personally recommend
http://www.python.org/2.4/msi.html
to learn about automatic installation.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Organising data within a program

2004-12-13 Thread Nick Evans
Hey all,
I am currently working on a simple program (small group membership database)
just to get to grips with the language (bit of a newbie here :-)) and am
wondering about the best way of organising the data within the program.

>From my understanding I would have something like person1
=("name","address","phone","subs-due")
Then you would putmembershipdatabase = (person1, person2, personX)
etc
Now is this the best way of organising this data within the program or is
there a better "known" way?

Also I want to just store this info to a standard txt file. Probably CSV or
something. Is there any particular way I should be saving this data to file?


Thanks in advance

Nick


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


Re: thread/queue bug

2004-12-13 Thread Steve Holden
Antoon Pardon wrote:
Op 2004-12-13, Tim Peters schreef <[EMAIL PROTECTED]>:
[Antoon Pardon]
I don't see why starting a thread as a side effect of importing is
bad thread practice. Sure python doesn't cater for it, but IMO
that seems to be python failing.
Obviously, it's bad practice in Python because it can lead to
deadlocks in Python.

By that argument any use of locks is bad practice because it
can lead to deadlock.
Not at all. You mentioned locks, not Tim. The reason it can lead to 
deadlocks is because import, being an executable statement, must 
terminate correctly in order to return control to the module that 
executed the import statement.

It's nearly tautological.  Import is an
executable statement in Python, not, e.g., as in many other languages,
a declaration directed at the system linker.  With that power comes
opportunities to shoot yourself, although they're generally easy to
avoid.  Come up with a practical design that doesn't have this
limitation, and then perhaps your characterization of the current
design as "a failing" would be both credible and constructive.

If a car model has cranky brakes, I think I can call that a failing
even without having the ability to come up with a pratical design
that doesn's has those limitations.
But in fact your situation is more closely analogous to a customer who's 
bought a car that can be stopped by pressing on the brake pedal now 
complaining that sideways pressure on the brake pedal doesn;t affect the 
car's motion.

I judge a language by what it can and cannot do, not by my ability
to correct the things I perceive as failings. For all I know python
may have taken some design decisions that might have seen perfectly
logical but now prohibit a a practical design that doesn't have this
limitation. I don't see why something like that would make this
any less a failing then when a practical design was easy in the
current implemenation.
All that Tim was suggesting is that it's MORE SENSIBLE to start a thread 
as the result of a specific call to programmed functionality rather than 
as the side effect of an import. The reason for this is due to the 
semantics of the import statement. If you perceive that as a failing 
then you'd be better rewarded by an attempt to modify your perceptions.

I've always found "don't argue with Tim about Python" to be a useful 
rule of thumb. He's wrong much less often than I am. I suspect he's also 
wrong much less often than you ;-)

Apart from that, ya, I do think it would *uisually* be poor practice
to start a thread as a side effect of importing anyway.  It's too
mysterious, and IME has caused trouble even when it didn't lead to
deadlocks.  The fundamental purpose of import in Python is to add
useful names to the importer's namespace, and users of a module
generally think of it as doing no more than that.

Importing a module in general also does some kind of initialisation.
If starting a thread is a logical thing to do in this initialisation
fase I see nothing wrong with it.
But the reason, I suspect, that it's being suggested this is bad design 
is because it would be tricky (in any language) to ensure that the 
satisfactory conclusion of the import didn't depend on successful thread 
startup (and possibly termination).

Plus, of course, in Python the side-effect of the import (creating the 
thread) can happen precisely once, because the module body is executed 
precisely once no matter how many times it's imported. That's not really 
the issue, however.


Note that the OP's example had a module that, upon the first attempt
to import it, ran an infinite loop (even if it hadn't deadlocked), and
it's clearly severe abuse of import's purpose.to write a module M such
that "import M" *never* returns.  Indeed, that's the other half of how
deadlock occurs:  not only that the imported module spawn a thread as
a side effect of importing, but also that the imported module refuse
to allow the import to complete.

Well I'll agree here. An import that has as a side effect that the
import doesn't return is bad practice.
But that's precisely the risk you run when starting up threads!

The current design actually supports spawning all the threads you like
as a side effect of importing, provided you ensure also that the
import ompletes.

Well in that case I don't have any problems with it. The perceived
failing was because of only knowing part of it based on what I had
read in this thread.

The easiest way to avoid trouble remains not to
spawn threads as a side effect of importing to begin with, although a
programmer determined to demonstrate their bad taste  can easily
enough make it work.

Well then probably I have a bad taste. I have though of designs in which
it seemed very natural to have a thread started as part of the
initialisation in a module. Other limitations of python didn't make
it workable but in priciple I saw nothing wrong with doing it.
Bearing in mind that module initialisation is always one-off, relying on 
import to 

Re: character encoding conversion

2004-12-13 Thread "Martin v. Löwis"
Max M wrote:
A smiple way to try out different encodings in a given order:
The loop is fine - although ('UTF-8', 'Latin-1', 'ASCII') is
somewhat redundant. The 'ASCII' case is never considered, since
Latin-1 effectively works as a catch-all encoding (as all byte
sequences can be considered Latin-1 - whether they are meaningful
data is a different question).
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: system requirements for python 2.4

2004-12-13 Thread Jean Brouwers

FWIIW, we use Python 2.4 on RH8 and FC2 systems.  In both cases, built
from scratch, following the build instructions.

/Jean Brouwers


In article <[EMAIL PROTECTED]>, ben
<[EMAIL PROTECTED]> wrote:

> I'm trying to upgrade python from 2.2 to 2.4 on a RH9 system, and can't
> find any rpm that will let me install it.
> Is FC3 required for python 2.4?
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: character encoding conversion

2004-12-13 Thread "Martin v. Löwis"
Christian Ergh wrote:
Once more, indention should be correct now, and the 128 is gone too. So, 
something like this?
Yes, something like this. The tricky part is of, course, then the
fragments which you didn't implement.
Also, it might be possible to do this in a for loop, e.g.
for encoding in (pageencoding, xmlencoding, htmlmetaencoding,
 "UTF-8", "Latin-1-no-controls", "cp1252", "Latin-1"):
try:
   data = data.encode(encoding)
   break;
except UnicodeError:
   pass
You then just need to add the Latin-1-no-controls codec, or you need
to special-case this in the loop.
# if it is not in the pagecode, how do i get the encoding of the page?
pageencoding = '???'
You need to remember the HTTP connection that you got the HTML file
from. The webserver may have sent a Content-Type header.
xmlencoding  = 'whatever i parsed out of the file'
htmlmetaencoding = 'whatever i parsed out of the metatag'
Depending on the library you use, these aren't that trivial, either.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


compiling ming on win32/python 2.3

2004-12-13 Thread Jelle Feringa // EZCT / Paris








I wonder whether anyone on this list has been able to
compile the ming .swf output library successfully on win32/python2.3?

I have quite some trouble trying to compile these kind of libraries, maybe you could point me to a good
starters tutorial on this?

 

Cheers,

 

Jelle.






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

Re: Why are tuples immutable?

2004-12-13 Thread Fredrik Lundh
Gerrit <[EMAIL PROTECTED]> wrote:

> Apart from historical, compatibility reasons, why is
>
>"foo %s bar %s" % [2, 4]
>
> illegal?
>
> I could imagine that anything accepting numerical values for __getitem__
> (foo[0], foo[1], ...) or that is iterable (foo.next(), foo.next()) could
> be sensibly used as a formatting rhs. Of course, it is not compatible
> because "foo %s" % [2, 4] is correct and "foo %s" % (2, 4) is not, but
> are there other reasons that it has been chosen like this?

so what should

"foo %s bar %s" % "24"

do?

 



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


Re: subprocess vs. proctools

2004-12-13 Thread Keith Dart
Nick Craig-Wood wrote:
Keith Dart <[EMAIL PROTECTED]> wrote:
Oh, I forgot to mention that it also has a more user- and 
programmer-friendly ExitStatus object that processess can return. This 
is directly testable in Python:

proc = proctools.spawn("somecommand")
exitstatus = proc.wait()
if exitstatus:
print "good result (errorlevel of zero)"
else:
 print exitstatus # prints message with exit value

This sounds rather like the new subprocess module...

import subprocess
rc = subprocess.call(["ls", "-l"])
total 381896
-rw-r--r--1 ncw ncw  1542 Oct 12 17:55 1
[snip]
-rw-r--r--1 ncw ncw   713 Nov 16 08:18 z~
print rc
0
But this evaluates to False in Python, but True in a shell. It also 
requires an extra check for normal exit, or exit by a signal. The 
proctools ExitStatus object avaluates to True only on a normal exit, 
period. Thus it follows a shell semantics for clarity. You cannot do 
this with the subprocess module:

if rc:
print "exited normally"
But in proctools, the exitstatus is an object that evaluates True only 
for normal exit.

import proctools
proc = proctools.spawnpipe("ls -l")
print proc.read()
 
print proc.exitstatus
ls: Exited normally.
proc = proctools.spawnpipe("ls -l xx")
print proc.read()
'ls: xx: No such file or directory\n'
print proc.exitstatus
ls: Exited abnormally with status 1.
if proc.exitstatus:
print "returned normally"
But you can get the integer return value, if you want it, like this:
int(proc.exitstatus)
or query it with methods returning booleans:
exitstatus.exited()
exitstatus.signalled()
exitstatus.stopped()
Also, proctools lets you use a pty, if you choose. Not every program 
works well from a pipe.

IMHO the new subprocess module is a very well thought out interface...
The proctools Process object presents a file-like object to the rest of 
Python, which makes a process polymorhic with any other file, pipe or 
socket object. It has the usual read, write, readline, and readlines 
methods. It can also be made non-blocking, and you can have many open at 
once. In addition, there are special methods for controlling the 
sub-process: You can kill it, stop it, re-start it, clone it, wait on 
it, and get stats from it. The stat() method returns a ProcStat object, 
which has attributes like what you get from the 'ps' program. Need to 
know the process's RSS? No problem. It also supports logging to a log 
file, and on-exit callback for persistent process requirements.

You always invoke the spawn* functions with a string. This is parsed by 
a shell-like parser (the shparser module that comes with it), but no 
/bin/sh is invoked. The parser can handle single and double quotes, and 
backslash escapes.

Alas, one thing the proctools module does not do well yet is create a 
pipeline. I have plans to fix that.

It does not work with MS Windows, but can work with cygwin on Windows.
Whew... and I have not even covered the ProcessManager object...

--
   \/ \/
   (O O)
-- oOOo~(_)~oOOo
Keith Dart <[EMAIL PROTECTED]>
vcard: 
public key: ID: F3D288E4   URL: 

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


Re: RegEx: find all occurances of a single character in a string

2004-12-13 Thread Franz Steinhaeusler
On Tue, 14 Dec 2004 14:05:38 +0100, Franz Steinhaeusler
<[EMAIL PROTECTED]> wrote:

sorry
>r=re.compile('[^a]a([^a]') 
 r=re.compile('[^a]a[^a]') 

I meant.

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


Re: lies about OOP

2004-12-13 Thread [EMAIL PROTECTED]
Hello,

Instead of copy and paste, I use functions for code reuse. I didn't see
the light of OOP, yet. I use Python but never did anything with OOP. I
just can't  see what can be done with OOP taht can't be done with
standart procedural programing.

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


Re: Suggestion for "syntax error": ++i, --i

2004-12-13 Thread Terry Reedy

"Petr Prikryl" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

>Summary: In my opinion, the C-like prefix
>increment and decrement operators (++i and --i)

Python is not C.  In Python, ++x and --x are the same as + + x and - - x 
are the same as +(+x) and -(-x) (as you later guessed, and could verify in 
the Ref Manual).  A pair of operators is not an operator, let alone an 
increment or decrement operator.  The pair of operators is just that, a 
pair.  So the premise of this opinion is wrong.

To succeed in Python, one must drop the C mindset and switch to a Python 
mindset.  And there are much deeper issues than this surface syntax one, 
such at the difference in object models.

>should be marked as "syntax error".

I completely disagree.

Unless you also propose to ban syntactical equivalents such as I gave above 
(even worse), you are proposing two nitpicky lexical exceptions to Python's 
general lexical rules.  They would, I believe, be unprecedented.  They are 
certainly senseless within Python itself.  They are also contrary to the 
basic philosophy of Python of avoiding unnecessary exceptions, which 
complicate both the learning of the language and its parsing.

You could propose to the author of Pychecker that he include, if possible, 
an option to check for and warn about '++', '--'.  But it should be 
optional because '++' and '--' could be legitimate and sensible when 
applied to user-class instances.  Consider the (non-circular) Python 
definition of bool (now builtin):

def bool(obj): return not not obj

Terry J. Reedy



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


Reading raw data from disc

2004-12-13 Thread Ivo Woltring
Dear Pythoneers,

Is it possible to read e.g. the first 3 sectors of a disc without opening a
file or somesuch?
I want to bitwise read a cd-rom or other media without consulting a table of
contents. Just start at track 0 and go on for x bytes. Is it possible with
python and if so, please help me in the right direction

thankx
Ivo.


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


Looking for a coder to do some work

2004-12-13 Thread Allan Irvine
HI
>
> Hope this is the right place for this, I am new. I have a spec to
create
> a (dual screen) framework application that
>
> 1 displays mp3, flash, jpegs etc. on top screen
> 2: displays buttons on bottom screen which alter image when a key is
> pressed.
>
> The hardware is a dell pc basically, no mouse and the keyboard is a
> simple 8 key pad that outputs numbers 1-8 (I think but can be
mapped).
>
> I am looking for the best way to create this and tools to use etc.
>
> The system is basically an information kiosk like you see in airports
> etc. the presentation screen on top may show several borderless
frames
> containing differing media.
>
> Hope you can help - any thoughts welcome
Am willing to pay fort hsi to be done

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


Re: gather information from various files efficiently

2004-12-13 Thread Fredrik Lundh
Keith Dart wrote:

>>> try:
>>> dict[a].append(b)
>>> except KeyError:
>>> dict[a] = [b]

the drawback here is that exceptions are relatively expensive; if the
number of collisions are small, you end up throwing and catching lots
of exceptions.  in that case, there are better ways to do this.

>> dict.setdefault(a, []).append(b)

the drawback here is that you create a new object for each call, but
if the number of collisions are high, you end up throwing most of them
away.  in that case, there are better ways to do this.

(gotta love that method name, btw. a serious candidate for the "most
confusing name in the standard library" contest...  or maybe even the
"most confusing name in the history of python" contest...)

> Hey, when did THAT get in there? ;-) That's nice. However, the try..except 
> block is a useful 
> pattern for many similiar situations that the OP might want to keep in mind. 
> It is usually better 
> than the following, also:
>
> if dct.has_key(a):
> dct[a].append(b)
> else:
> dct[a] = [b]

the drawback here is that if the number of collisions are high, you end
up doing lots of extra dictionary lookups.  in that case, there are better
ways to do this.

 



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


Re: how do I "peek" into the next line?

2004-12-13 Thread les_ander
I should have also said that I am using the same file handle.
So suppose the file handle is fp
then I read some lines from fp and I hand it over to other
functions that read other things from fp (in an ordered manner).
les

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


Re: Reading raw data from disc

2004-12-13 Thread Grant Edwards
On 2004-12-13, Ivo Woltring <[EMAIL PROTECTED]> wrote:

> Is it possible to read e.g. the first 3 sectors of a disc
> without opening a file or somesuch?

Under Linux, no.  

You have to open the device.

> I want to bitwise read a cd-rom or other media without
> consulting a table of contents. Just start at track 0 and go
> on for x bytes. Is it possible with python and if so, please
> help me in the right direction

sectorsize = 2048   # hard drives are usually 512, CDs 2K or 4K
bytes = file('/dev/cdrom','rb').read(3*sectorsize)

I've no idea what to do under Windows...

-- 
Grant Edwards   grante Yow!  And furthermore,
  at   my bowling average is
   visi.comunimpeachable!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do I "peek" into the next line?

2004-12-13 Thread Adam DePrince
On Mon, 2004-12-13 at 16:44, fuzzylollipop wrote:
> reads are not destructive there is nothing to "put back" becuase it is
> never removed to begin with.
> just change your logic and thing of about what you really need to do

Not true.  

Character special devices in Unix
Named pipes in Windows NT
Pipes in Unix
Comx: where x is your com port in DOS
Sockets
gzip and zlib file objects; this file was described as being *so* large
that it should not be read into memory.  IIRC seek operations are
linear; while it is correct you can seek backwards, I don't think you
would really want to.


Adam DePrince 


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


Re: jython and concatenation of strings

2004-12-13 Thread Jan Gregor
Ok, thanks. I didn't think that += operator is nondestructive operation
- but strings are immutable so this makes sense.

On 2004-12-13, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
>>  I found that price of += operator on string is too high in jython. For
>>  example 5000 such operations took 90 seconds (i generated html copy of
>>  table with 1000 rows and 5 columns). Generation of row data into separate
>>  string and joining after lead to time 13 seconds !!!
>
> Its generally not recommended to use simple string concatenation for
> building larger strings - neither in python nor in java/jython.
>
> afaik there are two solutions to this: The java-way and the jython way:
>
> java: Use StringBuffer
> python: use a list, and append the strings to that. Then, when you want the
> result, do
>
> "".join(stringlist)
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i send 8-bit data or binary data with pyserial?

2004-12-13 Thread Diez B. Roggisch
> i have an electronic module which only understand binary data.
> i use  python pyserial.
> for example the module starts when 00100 8-bit binary data sent.but
> pyserial sent only string data.
> Can i send this binary data with pyserial or another way with python.

Strings _are_ binary data. Use the module struct to convert data from more
convenient representations (numbers) to strings, or use chr() to convert
them yourself.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: do you master list comprehensions?

2004-12-13 Thread Max M
Will Stuyvesant wrote:
I tried funnies like [[w for w in L] for L in data],
that is correct syntax, but you'd never guess.
That is absolutely correct. It's not a funnie at all. If you find it odd 
it's only because you are not used to list comprehensiones.

In that case you might be more comfortable with:
data = [['foo','bar','baz'],['my','your'],['holy','grail']]
result = []
for l in data:
result += l
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: how do I "peek" into the next line?

2004-12-13 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
now suppose I have read the first line already.
then I read the second line and notice
that there is a ">" in front (my special character)
then I want the put back the second line into the
file or the stdin.
Another possibility -- have each call to __iter__ produce the next 
"section" of your data:

>>> class strangefileiter(object):
... def __init__(self, file):
... self.iter = peekable(file)
... self.yield_last = False
... def __iter__(self):
... if self.yield_last:
... yield self.iter.next()
... self.yield_last = False
... while True:
... next = self.iter.peek()
... if next.rstrip('\n') == "|":
... self.yield_last = True
... break
... yield self.iter.next()
...
>>> f = strangefileiter(file('temp.txt'))
>>> file('temp.txt', 'w').write("""\
... text
... before first |
... |
... text after
... first |
... |
... final text""")
>>> f = strangefileiter(file('temp.txt'))
>>> for line in f:
... print repr(line)
...
'text\n'
'before first |\n'
>>> for line in f:
... print repr(line)
...
'|\n'
'text after\n'
'first |\n'
>>> for line in f:
... print repr(line)
...
'|\n'
'final text'
I'm not sure I'd do it this way -- it makes me a little nervous that 
each call to __iter__ iterates over something different.  But it might 
be closer to what you were trying to do...

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


ANN: Python Computer Graphics Kit v2.0.0alpha1

2004-12-13 Thread Matthias Baas
The first alpha release of version 2 of the Python Computer Graphics
Kit is available at http://cgkit.sourceforge.net
There are still a lot of things missing, but on the other hand, there
is also quite a lot that is already working and that might make the
current version useful nevertheless.


What is it?
---

The Python Computer Graphics Kit is a generic 3D package written in
C++ and Python that can be used for a variety of domains such as
scientific visualization, photorealistic rendering, Virtual Reality or
even games. The package contains a number of generic modules that can
be useful for any application that processes 3D data. This includes
new types such as vectors, matrices and quaternions. Furthermore, the
package can read and store 3D models in memory where they can be
manipulated by Python programs. The kit comes with tools that can be
used to display the scene either interactively or by rendering it
offline via a RenderMan renderer.


What's new?
---

The new version of the kit can store 3D data in memory where it can be
manipulated via Python programs. The new main features are:

- 3D data can be stored and manipulated in memory 
- Imports 3DS, VRML, X3D, OFF, IFS
- Exports RIB (shaders are generated on-the-fly) 
- Create 3D scenes via Python scripting 
- Interactive OpenGL viewer tool 
- OpenGL stereo output (vertical split or quad buffer) 
- Offline render tool that feeds a RenderMan renderer 
- Use the latest graphics card features using the interactive OGRE
viewer tool (not included in the Windows binary)
- Connect arbitrary attributes of the same type to create animations 
- Rigid body dynamics via the Open Dynamics Engine 
- Extensible via regular modules or plugins


For more information, visit:

http://cgkit.sourceforge.net


- Matthias -


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


Re: how do I "peek" into the next line?

2004-12-13 Thread Steven Bethard
I wrote:
... while True:
... next = self.iter.peek()
... if not next or next.rstrip('\n') == "|":
... break
... yield self.iter.next()
...
Actually, the 'not next' test is not necessary since I'm using an 
iterator over the file (end of file is signified by StopIteration, not a 
value of '' returned by the iterator).  The amended version:

... while True:
... next = self.iter.peek()
... if next.rstrip('\n') == "|":
... break
... yield self.iter.next()
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 338: Executing modules inside packages with '-m'

2004-12-13 Thread Nick Coghlan
Fredrik Lundh wrote:
in my original post, I said
I'd say that for a typical user, "A" is a marginal improvement over
"B", compared to "C".
which, I thought, tried to say that for a user expecting "C", neither "A" nor 
"B"
is good enough.
Ah, OK - that makes a lot more sense than the way I read it (it looked to me as 
if you expected option B to do the same thing as option A. It didn't seem likely 
you really believed that, but that was the only interpretation I saw at the time).

Anyway, as my other rambling message points out (eventually) - this feature is 
intended for developers and Python version specific utility scripts like pdb, 
profile and pychecker.checker, rather than launch scripts for full applications.

For end users, I agree with you wholeheartedly - applications should behave like 
applications, no matter what language they're written in :)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Jive <[EMAIL PROTECTED]> wrote:
.
.
.
>Doesn't Microsoft have an answer for that?  There are (at last count) nine
>skillion ActiveX
>components in the wild.  Surely Microsoft didn't blast them into oblivion
>with dot-net -- did it?
.
.
.
Microsoft *constantly* obsoletes all sorts of third-party creations.
There's no simple formula for their actions, but, in this case, it's
fairly safe to say that substantial portions of the Redmond Monster
are actively seeking to eliminate ActiveX.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gather information from various files efficiently

2004-12-13 Thread Keith Dart
Kent Johnson wrote:
Keith Dart wrote:
try:
dict[a].append(b)
except KeyError:
dict[a] = [b]

or my favorite Python shortcut:
dict.setdefault(a, []).append(b)
Kent
Hey, when did THAT get in there? ;-) That's nice. However, the 
try..except block is a useful pattern for many similiar situations that 
the OP might want to keep in mind. It is usually better than the 
following, also:

if dct.has_key(a):
dct[a].append(b)
else:
dct[a] = [b]
Which is a pattern I have seen often.

--
   \/ \/
   (O O)
-- oOOo~(_)~oOOo
Keith Dart <[EMAIL PROTECTED]>
vcard: 
public key: ID: F3D288E4   URL: 

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


Re: do you master list comprehensions?

2004-12-13 Thread Peter Otten
Will Stuyvesant wrote:

 data = [['foo','bar','baz'],['my','your'],['holy','grail']]
 result = []
 for d in data:
> ... for w in d:
> ...result.append(w)
 print result
> ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail']
> 
> puts all the words in a list, like I want.
> 
> How to do this with [lc] instead of for-loops?

>>> data = [['foo','bar','baz'],['my','your'],['holy','grail']]
>>> [w for d in data for w in d]
['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail']

See how the for expressions in the list comprehension exactly match your
nested for loops? That's all there is to it.

Peter

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


Re: how do I "peek" into the next line?

2004-12-13 Thread fuzzylollipop
reads are not destructive there is nothing to "put back" becuase it is
never removed to begin with.
just change your logic and thing of about what you really need to do

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


Re: how do I "peek" into the next line?

2004-12-13 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
now suppose I have read the first line already.
then I read the second line and notice
that there is a ">" in front (my special character)
then I want the put back the second line into the
file or the stdin.
Amended iterator class example using my peekable recipe:
>>> class strangefileiter(object):
... def __init__(self, file):
... self.iter = peekable(file)
... def __iter__(self):
... while True:
... next = self.iter.peek()
... if not next or next.rstrip('\n') == "|":
... break
... yield self.iter.next()
...
>>> file('temp.txt', 'w').write("""\
... some text
... some more
... |
... not really text""")
>>> f = strangefileiter(file('temp.txt'))
>>> for line in f:
... print repr(line)
...
'some text\n'
'some more\n'
>>> remainder = f.iter
>>> for line in remainder:
... print repr(line)
...
'|\n'
'not really text'
Note that because I wrap the file iterator with a peekable[1] object, 
the lines aren't consumed when I test them.  So to access the remaining 
lines, I just use the iter field of the strangefileiter object.

Steve
[1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304373
--
http://mail.python.org/mailman/listinfo/python-list


Re: how do I "peek" into the next line?

2004-12-13 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> now suppose I have read the first line already.
> then I read the second line and notice
> that there is a ">" in front (my special character)
> then I want the put back the second line into the
> file or the stdin.

the line doesn't disappear from the file just because you
read it.  so who do you want to pass it to?  someone else?
some other part of your program?  what exactly are you
doing?

 



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


ANN: IPython 0.6.5 is out.

2004-12-13 Thread Fernando Perez
Hi all,

I'm glad to announce the release of IPython 0.6.6.  IPython's homepage is at:

http://ipython.scipy.org

and downloads are at:

http://ipython.scipy.org/dist

I've provided RPMs (Py2.2 and 2.3), plus source downloads (.tar.gz and .zip).

Debian, Fink and BSD packages for this version should be coming soon, as the 
respective maintainers (many thanks to Jack Moffit, Andrea Riciputi and Dryice 
Liu) have the time to follow their packaging procedures.

Many thanks to Enthought for their continued hosting support for IPython, and 
to all the users who contributed ideas, fixes and reports.


Release notes
-

This release was made to fix a few crashes recently found by users, and also 
to keep compatibility with matplotlib, whose internal namespace structure was 
recently changed.

* Adapt to matplotlib's new name convention, where the matlab-compatible 
module is called pylab instead of matlab.  The change should be transparent to 
all users, so ipython 0.6.6 will work both with existing matplotlib versions 
(which use the matlab name) and the new versions (which will use pylab
instead).

* Don't crash if pylab users have a non-threaded pygtk and they attempt to use 
the GTK backends.  Instead, print a decent error message and suggest a few 
alternatives.

* Improved printing of docstrings for classes and instances.  Now, class, 
constructor and instance-specific docstrings are properly distinguished and 
all printed.  This should provide better functionality for matplotlib.pylab 
users, since matplotlib relies heavily on class/instance docstrings for 
end-user information.

* New timing functionality added to %run.  '%run -t prog' will time the 
execution of prog.py.  Not as fancy as python's timeit.py, but quick and easy 
to use.  You can optionally ask for multiple runs.

* Improved (and faster) verbose exeptions, with proper reporting of dotted 
variable names (this had been broken since ipython's beginnings).

* The IPython.genutils.timing() interface changed, now the repetition number 
is not a parameter anymore, fixed to 1 (the most common case).  timings() 
remains unchanged for multiple repetitions.

* Added ipalias() similar to ipmagic(), and simplified their interface.  They 
now take a single string argument, identical to what you'd type at the ipython 
command line.  These provide access to aliases and magics through a python 
function call, for use in nested python code (the special alias/magic syntax 
only works on single lines of input).

* Fix an obscure crash with recursively embedded ipythons at the command line.

* Other minor fixes and cleanups, both to code and documentation.


The NEWS file can be found at http://ipython.scipy.org/NEWS, and the full 
ChangeLog at http://ipython.scipy.org/ChangeLog.


Enjoy, and as usual please report any problems.

Regards,

Fernando.

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


Re: while 1 vs while True

2004-12-13 Thread Nick Coghlan
Paul Rubin wrote:
"Raymond Hettinger" <[EMAIL PROTECTED]> writes:
It is unlike to before Py3.0.  Making them constants would break the
reams of compatability code: True, False = (1==1), (1!=1).

I don't see why that particular statement needs to fail.  The
interpreter could permit assigning True=True or False=False without
raising an error.  Then True and False wouldn't really be constants,
but they'd instead be variables whose value was always known to the
compiler, which for optimization purposes is just as good.  The
compiler could alternatively do some simple dataflow analysis to make
sure the values of True and False haven't been changed in a particular
module, before doing that particular optimization.
Until this code:
.>>> import pdb
.>>> pdb.True = 0
.>>> pdb.x = "Darn writeable module dictionaries"
.>>> from pdb import True
.>>> True
0
.>>> from pdb import x
.>>> x
'Darn writeable module dictionaries'
is illegal, the compiler is really limited in what it can safely assume about 
the contents of module dictionaries. There's such a thing as being *too* 
flexible - and in this case, the flexibility eliminates some potential 
optimisations (in this case, "I know what this is" compile time name binding).

I believe modifying a module's globals dictionary from outside the module is in 
the process of being deprecated - the catch is that distinguishing it from some 
legitimate accesses to a module's globals is not straightforward.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python mascot proposal

2004-12-13 Thread Graham Fawcett
Luis M. Gonzalez wrote:
> Hey Dimitri,
>
> I completely agree with you in that Python needs once for all a cool
> logo.
> I like your design very much, but I have a few thoughts about it:
>
> 1) I think that Python's logo should reflect its power.
> If we use a mascot as its image, we would be giving the wrong idea:
> that Python is a "toy" language, instead of a very good alternative
to
> other mainstream languages.

+1. But I think your logo would be a great identifier for Python when
teaching it to younger students. Perhaps the EDU-SIG/Python in
Education folks might be interested.

The American wrestler Hulk Hogan used to intimidate his opponents by
flexing the muscles of his arms, which he refered to as his "26-inch
Pythons". Now, there's a powerful image that would strike an awe-ful
chord in the hearts of many a thick-glassed geek! "Whatcha gonna do,
when the world's most powerful dynamic language comes after you?"
-- Graham

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


Re: urllib2 and Set-Cookie with "302 Moved temporarily"

2004-12-13 Thread Eino Mäkitalo
Fredrik Lundh wrote:
"Eino Mäkitalo" <[EMAIL PROTECTED]> wrote:
# this is ugly
Yes, but short and easy. Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


do you master list comprehensions?

2004-12-13 Thread Will Stuyvesant
Here is a question about list comprehensions [lc].  The
question is dumb because I can do without [lc]; but I am
posing the question because I am curious.

This:

>>> data = [['foo','bar','baz'],['my','your'],['holy','grail']]
>>> result = []
>>> for d in data:
... for w in d:
...result.append(w)
>>> print result
['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail']

puts all the words in a list, like I want.

How to do this with [lc] instead of for-loops?

I tried funnies like [[w for w in L] for L in data],
that is correct syntax, but you'd never guess.

I know, silly!  No need for [lc]!  So there's my
question.  I am sure a one-liner using [lc] will be very
enlightening.  Like studying LISP.


--
I wish there was a knob on the TV to turn up the intelligence.
There's a knob called `brightness', but it doesn't work.
-- Gallagher

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


Re: [dictionary] how to get key by item

2004-12-13 Thread Nick Coghlan
Ola Natvig wrote:
If some keys has the same value as the item this will cause problems 
because keys in your result dictionary can be overwritten. Could it be a 
 option to build the result dictionary as a dictionary with the values 
as the keys, and lists of keys as the value. Perhaps you need to use a 
loop for this.

<>
.>>> d = dict(foo=1, bar=1, bob=7, jane=42, mary=16, fred=16)
.>>> from itertools import groupby
.>>> val = d.__getitem__
.>>> grouped = groupby(sorted(d.iterkeys(), key=val), val)
.>>> r = dict((value, list(keys)) for value, keys in grouped)
.>>> r
{16: ['mary', 'fred'], 1: ['bar', 'foo'], 42: ['jane'], 7: ['bob']}
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you master list comprehensions?

2004-12-13 Thread Diez B. Roggisch
>>> data = [['foo','bar','baz'],['my','your'],['holy','grail']]
>>> [e for l in data for e in l]
['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail']
-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do I "peek" into the next line?

2004-12-13 Thread les_ander
OK, I am sorry , I did not explain my problem completely.
I can easily break from the loop when I see the character in a line
that I just read; however my problem involves putting back the line I
just read since if I have seen this special character, I have read one
line too many. Let me illustrate
suppose the file has 3 lines

line1.line1.line1
>line2.line2.line
line3.line3.line3

now suppose I have read the first line already.
then I read the second line and notice
that there is a ">" in front (my special character)
then I want the put back the second line into the
file or the stdin.

An easy way is if i read all the lines in to an array
and then I can put back the line with the special
character back into this array. However,
this file I am readding is huge! and I can read
it all in one swoop (not enough memory).

for x in stdin:
if x[0]==">":
 put back the x some how... <-
break
  else:
  print x

I hope this is clear
thanks

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


Re: Fun with Outlook and MAPI

2004-12-13 Thread Steve Holden
Chris wrote:
Okay, here's the results.  The good news is that the code sent the 
mail without any popup's.  The bad news is that the sent e-mail stays 
in the outbox instead of the sent folder.  Any suggestions?
Well, only the same one I've already made, which is to look on the 
win32all mailing list archives. Since this appears to be beyond you, 
here's a note by Chad Stryker commenting on an original work by David 
Fraser.

It may give you the clues you need, otherwise Google for the whole 
thread(s).

"""Thank you for figuring this extended MAPI interface all out.  I 
discovered a couple of problems with the code (on my system at least). 
First, the message in my outbox was marked as read.  Second, the 
message would remain in the outbox after it was sent.  After several 
hours of work, I added three lines to the function that mark the 
message as unread and cause the message to be deleted from the outbox 
after it is sent.

First, I added a constant that I found in the MAPI header file 
MAPIDefS.h.

CLEAR_READ_FLAG = 4
Next I added two lines just before “outboxfolder.SaveChanges(0)”.
message.SetReadFlag(CLEAR_READ_FLAG)
message.SetProps([(mapitags.PR_DELETE_AFTER_SUBMIT,1)])
With these changes, the behavior in the outbox is consistent with 
sending messages directly from Outlook.
"""

regards
 Steve

Actually, I had already found that message.  It still doesn't do what 
I'm looking for(namely moving sent messages to the Sent folder).

Chris

Well, in that case please excuse my crotchetiness. It's probably the 
time of year.

bah-humbug-ly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 338: Executing modules inside packages with '-m'

2004-12-13 Thread Fredrik Lundh
Just wrote:

> This subthread was specifically about your
>
>   python -c "import foo.bar" arg
>
> suggestion.

in my original post, I said

I'd say that for a typical user, "A" is a marginal improvement over
"B", compared to "C".

which, I thought, tried to say that for a user expecting "C", neither "A" nor 
"B"
is good enough.

 



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


Re: do you master list comprehensions?

2004-12-13 Thread Steven Bethard
Will Stuyvesant wrote:
data = [['foo','bar','baz'],['my','your'],['holy','grail']]
result = []
for d in data:
... for w in d:
...result.append(w)
print result
['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail']
Take advantage of the fact that you can have more than one 'for' in a 
list comprehension:

>>> data = [['foo','bar','baz'],['my','your'],['holy','grail']]
>>> [item for item_list in data for item in item_list]
['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail']
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
John Machin <[EMAIL PROTECTED]> wrote:
>Jive wrote:
>> "Martin v. Löwis" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>> > OTOH, people who only have VC6 just need to buy VS.NET 2003,
>> > which is still available.
>>
>> I don't even know how to do that! :-)  What's the difference between
>VC++
>> .net Standard and Visual Studio .net Pro?  (Besides $370?)  Is the
>former
>> C++ only, but with the IDE, and the later the whole shebang with
>SourceSafe,
>> VBASIC, and all that?
>>
>> OH NO!  I've gone seriously off-topic.  Please don't call the Spanish
>> Inquisiton.  Allow me to re-phrase the question:  What do I need to
>build
>> (on-topic) Python extensions?
>
>Short answer to Jive's question: (1) free non-MS C compiler (either
>MinGW or Borland) (2) inner calm.
>
>I really can't understand what all the screaming and yelling is about.
>Windows Python is built using an MS compiler. Those extension
>developers who can't/won't buy the MS compiler use either the free
>MinGW compiler or the free Borland 5.5 compiler (or both!). Yes, you
.
.
.
?  As I read your description, it obscures the existence of 
the free lcc and the no-charge Microsoft compilers http://msdn.microsoft.com/visualc/vctoolkit2003/ > (along
with such other popular alternatives as Cygwin, the Intel
compiler, ...).

It's been years since I've tried any of these with Python.
They *ought* to work, though ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do I "peek" into the next line?

2004-12-13 Thread Craig Ringer
On Tue, 2004-12-14 at 03:09, [EMAIL PROTECTED] wrote:
> Hi,
> suppose I am reading lines from a file or stdin.
> I want to just "peek" in to the next line, and if it starts
> with a special character I want to break out of a for loop,
> other wise I want to do readline().

Assuming there's a good reason, such as monster lines, not to just read
the next line anyway, I'd suggest read()ing the next character then
seek()ing back by one character to restore the file position.

def peekChar(fileobj):
   ch = fileobj.read(1)
   fileobj.seek(-1,1)
   return ch

--
Craig Ringer

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


Re: New versions breaking extensions, etc.

2004-12-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Nick Coghlan  <[EMAIL PROTECTED]> wrote:
>Jive wrote:
>> Can someone explain to me why Python 2.4 on MS Windows has these backward
>> compatibility problems?  What am I missing?
>
>The problem is the Python C/API. At the moment, it exposes things
>directly (like 
>data structures) that may change size between major version releases. The 
>other 
>issue is that the interpreter and the extensions may be linked to different 
>versions of the Microsoft runtime.
>
>This is a solvable problem, but it would require:
>   1. Major additions to the C/API - a "Python Major Version Agnostic" API 
> that 
>hides all data structures behind opaque pointers, never passes file 
>descriptors 
>between the interpreter and the extension and never gets Python to
>delete memory 
>allocated by the extension (or vice-versa)
>   2. Rewriting extensions to use the new API functions instead of the current 
>major version specific ones.
>
>Such an API is likely to be both harder to work with and slower, simply due to 
>the limitations of C.
>
>To this date, no-one has cared enough about the problem to put in the effort 
>required to make the C API version agnostic. Given that the API almost always 
.
.
.
Tcl went through this epiphany a few years, and has largely, 
though not exclusively, committed to use of the once-more-
redirected API called Stubs http://wiki.tcl.tk/stubs >.
Some Tcl-ers are orgasmic about the wonders of Stubs, some
ignore it, a few don't like it, and most, perhaps, aren't
even aware of its existence.  Performance doesn't appear to
be much of an issue, though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion for "syntax error": ++i, --i

2004-12-13 Thread Richard Brodie

"Terry Reedy" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> You could propose to the author of Pychecker that he include, if possible,
> an option to check for and warn about '++', '--'.

It does already.


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


Re: Read a gzip file from inside a tar file

2004-12-13 Thread Fredrik Lundh
Craig Ringer wrote:

>> These are huge files. My goal is to analyze the content of the gzip
>> file in the tar file without having to un gzip.  If that is possible.
>
> As far as I know, gzip is a stream compression algorithm that can't be
> decompressed in small blocks. That is, I don't think you can seek 500k
> into a 1MB file and decompress the next 100k.

correct.

> I'd say you'll have to progressively read the file from the beginning,
> processing and discarding as you go. It looks like a no-brainer to me -
> see zlib.decompressobj.

it can be a bit tricky to set things up properly, though.  here's a piece
of code that uses Python's good old consumer interface to decode things
incrementally:

http://effbot.org/zone/consumer-gzip.htm

you can either use this as is; just create a "target consumer", wrap it in the
gzip consumer, and feed data to the gzip consumer in suitable pieces.

alternatively, hack it until it does what you want.

 



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


Re: Suggestion for "syntax error": ++i, --i

2004-12-13 Thread Pierre Barbier de Reuille
Christian Ergh a écrit :
Hmm, i never liked the i++ syntax, because there is a value asignment 
behind it and it does not show - except the case you are already used to 
it.

 >>> i = 1
 >>> i +=1
 >>> i
2
I like this one better, because you see the assignment at once, it is 
easy to read and inuitive usability is given - in my opinion.
Chris

IMO, there is an assignement only for languages like python ! (ie. 
reference languages)

In languages like C or C++ (in which variables correspond to values) it 
makes perfect sens to modify the current value by an operator.

Nevertheless, I agree with you concerning Python ! But not for C++ :)
Pierre
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 338: Executing modules inside packages with '-m'

2004-12-13 Thread Nick Coghlan
Fredrik Lundh wrote:
my suggestion was to make sure that the user can type "bar arg" to start a
Python program called "bar" with the argument "arg".  that's trivial, on all
major platforms, despite what Nick says -- and yes, you can start threads
from a program named "bar".  try it.
The command line switch came out of a pydev discussion regarding making pdb and 
profile easy to run for developers using multiple versions of Python on the same 
computer (e.g. someone running a Python 2.3 default installation, a Python 2.4 
alpha alternate installation and a Python build from CVS).

Making a *single* version of an end-user application available on a platform is, 
as you say, quite straightforward. Versioning issues may need to be considered, 
but they're usually limited to making sure you get the 'right' Python out of any 
which are available on the machine.

And for an application, especially one not aimed at developers, that's almost 
certainly the right road to take. You'll have a name already, and presumably a 
versioning system as well (I believe dist_utils provides something along those 
lines).

Making a Python-version specific developer tool easily accessible isn't quite as 
straightforward, since you need to deal with making multiple versions available 
simultaneously, and each version has a different definition of the 'right' 
interpreter. As happened in the standard library with pdb and profile, the 
result is often to just not bother with it - leaving the developer to specify 
the full path to the particular version they want to run. That is, quite 
frankly, a pain - the same info is getting specified twice (once in selecting 
the python version to run, and again in specifying the full path to the 
associated tool)

One of the options explored in the original pydev discussion that led to '-m' 
was standalone, executable scripts for pdb and profile. The major issue with 
that idea was that it didn't scale very well - to use that solution for any 
other potentially useful scripts in the standard library, we would have had to 
come up with a decent name for each one, and then apply whatever versioning 
mechanism we settled on.

Using the Python module namespace to find the script means that all the 
versioning issues are already taken care of by the Python interpreters own 
versioning system - whichever version of Python you specify in the command line 
invocation, you get the correct version of the tool for that version of Python. 
It has the added bonus of working not only for pdb and profile, but any other 
scripts which are found to be useful (even those in extension packages, if this 
PEP is accepted by the BDFL).

Cheers,
Nick.
P.S. As you might have guessed from the above, it's not the least bit 
coincidental that the example scripts I generally use when discussing '-m' are 
pdb, profile and pychecker.checker. This feature is a convenience for command 
line junkies - which seems to be a fairly common trait amongst the developers I 
know :)

--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-13 Thread Lucas Hofman
Mark Asbach wrote:
Hi Lucas,

On a dual Xeon 3.0 Ghz:

[...]

Which shows a decrease in performance. Could this have anything to do with the
fact that is is a dual processor box?

Maybe. But my 3Gh P4/HT is also detected as a dual processor machine
(Kernel 2.6), so it might be a general problem with the Xeon?
Hi Mark,
No,the reason that you see 2 times as many processors as really are 
installed is the hyperthreading feature of the Xeon (see 
http://www.infoworld.com/infoworld/article/02/02/25/020225plxeon_1.html)

I turned it off (in the BIOS). The machine I tested on has 2 (pysical) 
processors installed. Turning on or off does not influence the pystone 
number significantly..

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


Re: uptime for Win XP?

2004-12-13 Thread David Bolen
Andrey Ivanov <[EMAIL PROTECTED]> writes:

(...)
> Writting this script was harder than I initially thought due to
> a lack of documentation for win32all. And I still don't know what
> that bizzare_int value stands for (an error/status code?).

The pywin32 documentation tends not to duplicate information already
available via MSDN (whether in a local installation or at
msdn.microsoft.com) on the underlying Win32 API, so when in doubt,
that's where to look.  Then, the pywin32 documentation will sometimes
qualify how the Python interface maps that function.

But in particular, a general rule (as has already been posted) is that
any out parameters are aggregated along with the overall result code
into a result tuple.

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


  1   2   3   4   >