Chicago Python Group, Thurs March 10

2005-03-08 Thread Ian Bicking
The Chicago Python User Group, ChiPy, will have its next meeting
on Thursday, March 10, starting at 7pm.  For more information on ChiPy
see http://chipy.org
Presentations
-
This week we will have two presentations.  Robert Ramsdell will talk 
about SimPy.  SimPy (Simulation in Python) is an object-oriented, 
process-based discrete-event simulation language based on standard 
Python. It provides the modeler with components of a simulation model 
including processes, for active components like customers, messages, and 
vehicles, and resources, for passive components that form limited 
capacity congestion points like servers, checkout counters, and tunnels. 
It also provides monitor variables to aid in gathering statistics.

Ian Bicking will be presenting on WSGI, WSGIKit, and Python web 
programming.  WSGI is a new Python standard for interfacing between web 
servers (like Apache or Twisted) and web applications.  WSGIKit is a 
reimplementation of Webware for Python using a series of WSGI 
components.  He will be talking about its design and utilization of WSGI 
to create cross-framework libraries.

Location

This month we will be having our first suburban meeting, in Downer's Grove:
  Acxiom
   Finley Road
  Downer's Grove
  Near the intersection of I-355 and Buttefield Road.
  Convenient to Fry's!
Parking is plentiful.  Some people are carpooling from the city -- 
contact the mailing list if you are [EMAIL PROTECTED]

About ChiPy
---
We meet once amonth, on the second Thursday of the month.  If you can't 
come this month, please join our mailing list:
http://lonelylion.com/mailman/listinfo/chipy
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


py2exe Python2.4 and warning: string/unicode conversion

2005-03-08 Thread Miki Tebeka
Hello All,

I'm shipping an application using py2exe.
With Python2.3 it worked fine but when switching to Python2.4 I started
getting warning: string/unicode conversion all over the place.

Any ideas how to solve this (other than using 'filterwarnings')?

Thanks.

Bye.
--

Miki Tebeka [EMAIL PROTECTED]
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys


pgp3yEdjLYB1o.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: unicode surrogates in py2.2/win

2005-03-08 Thread Martin v. Lwis
Mike Brown wrote:
Very strange how it only shows up after the 1st import attempt seems to 
succeed, and it doesn't ever show up if I run the code directly or run the 
code in the command-line interpreter.
The reason for that is that the Python byte code stores the Unicode
literal in UTF-8. The first time, the byte code is generated, and an
unpaired surrogate is written to disk. The next time, the compiled byte
code is read back in, and the codec complains about the unpaired
surrogate.
Can anyone tell me what's causing this, or point me to a reference to show 
when it was fixed? 
In Misc/NEWS, we have, for 2.3a1:
- The UTF-8 codec will now encode and decode Unicode surrogates
  correctly and without raising exceptions for unpaired ones.
Essentially, Python now allows surrogates to occur in UTF-8 encodings.
 I'm using 2.2.1 and I couldn't find mention of it in any
release notes up through 2.3. Any other comments/suggestions (besides stop 
supporting narrow unicode builds of Py 2.2) would be appreciated, too. Thanks 
:)
I see two options. One is to compile the code with exec, avoiding byte
code generation. Put
exec 
before the code, and

after it. The other option is to use variables instead of literals:
surr1 = unichr(0xd800)
surr2 = unichr(0xdc00)
surr3 = unichr(0xe000)
def chars(s, surr1=surr1, surr2=surr2, surr3=surr3):
...
if surr1 = i  surr2:
...
I would personally go with stop supporting Py 2.2. Unless you have the
time machine, you can't fix the bugs in old Python releases, and it is
a waste of time (IMO) to uglify the code just to work around limitations
in older interpreter versions.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: i18n: looking for expertise

2005-03-08 Thread Martin v. Löwis
klappnase wrote:
I am using python-2.3.4 and get unicode errors:

f = os.path.join(u'/home/pingu/phonoripper', u'\xc3\u20ac')
os.path.isfile(f)
True
os.access(f, os.R_OK)
Traceback (most recent call last):
  File stdin, line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode characters in position
24-25: ordinal not in range(128)
That's apparently a bug in os.access, which doesn't support Unicode file
names. As a work around, do
def access(name, mode, orig=os.access):
try:
   return orig(name, mode)
except UnicodeError:
   return orig(name.encode(sys.getfilesystemencoding(), mode))
os.access=access
Apparently, access is used so rarely that nobody has noticed yet (or
didn't bother to report). os.path.isfile() builds on os.stat(), which
does support Unicode file names.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode BOM marks

2005-03-08 Thread Francis Girard
Hi,

 Well, no. For example, Python source code is not typically concatenated,
 nor is source code in any other language. 

We did it with C++ files in order to have only one compilation unit to 
accelarate compilation time over network. Also, all the languages with some 
include directive will have to take care of it. I guess a unicode aware C 
pre-compiler already does.

 As for the super-cat: there is actually no problem with putting U+FFFE
 in the middle of some document - applications are supposed to filter it
 out. The precise processing instructions in the Unicode standard vary
 from Unicode version to Unicode version, but essentially, you are
 supposed to ignore the BOM if you see it.

Ok. I'm re-assured.

 A Unicode string is a sequence of integers. The numbers are typically
 represented as base-2, but the details depend on the C compiler.
 It is specifically *not* UTF-16, big or little endian (i.e. a single
 number is *not* a sequence of bytes). It may be UCS-2 or UCS-4,
 depending on a compile-time choice (which can be determined by looking
 at sys.maxunicode, which in turn can be either 65535 or 1114111).

 The programming interface to the individual characters is formed by
 the unichr and ord builtin functions, which expect and return integers
 between 0 and sys.maxunicode.

Ok. I guess that Python gives the flexibility of being configurable (when 
compiling Python) to internally represent unicode strings as fixed 2 or 4 
bytes per characters (UCS). 

Thank you
Francis Girard

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


Re: Unicode BOM marks

2005-03-08 Thread Francis Girard
Hi,

Thank you for your answer. That confirms what Martin v. Lwis says. You can 
choose between UCS-2 or UCS-4 for internal unicode representation.

Francis Girard

Le mardi 8 Mars 2005 00:44, Jeff Epler a crit:
 On Mon, Mar 07, 2005 at 11:56:57PM +0100, Francis Girard wrote:
  BTW, the python unicode built-in function documentation says it returns
  a unicode string which scarcely means something. What is the python
  internal unicode encoding ?

 The language reference says farily little about unicode objects.  Here's
 what it does say: [http://docs.python.org/ref/types.html#l2h-48]
 Unicode
 The items of a Unicode object are Unicode code units. A Unicode
 code unit is represented by a Unicode object of one item and can
 hold either a 16-bit or 32-bit value representing a Unicode
 ordinal (the maximum value for the ordinal is given in
 sys.maxunicode, and depends on how Python is configured at
 compile time). Surrogate pairs may be present in the Unicode
 object, and will be reported as two separate items. The built-in
 functions unichr() and ord() convert between code units and
 nonnegative integers representing the Unicode ordinals as
 defined in the Unicode Standard 3.0. Conversion from and to
 other encodings are possible through the Unicode method encode
 and the built-in function unicode().

 In terms of the CPython implementation, the PyUnicodeObject is laid out
 as follows:
 typedef struct {
 PyObject_HEAD
 int length; /* Length of raw Unicode data in buffer
 */ Py_UNICODE *str;/* Raw Unicode buffer */
 long hash;  /* Hash value; -1 if not set */
 PyObject *defenc;   /* (Default) Encoded version as Python
string, or NULL; this is used for
implementing the buffer protocol */
 } PyUnicodeObject;
 Py_UNICODE is some C integral type that can hold values up to
 sys.maxunicode (probably one of unsigned short, unsigned int, unsigned
 long, wchar_t).

 Jeff

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


Re: Default function arguments, KURL::cleanPath() -- a bindings bug?

2005-03-08 Thread Frans Englich

Ups, that was meant to go to the pykde list.

Sorry,

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


Re: parameter name conflict. How to solve?

2005-03-08 Thread Daniel Dittmar
Bo Peng wrote:
def func(output=''):
  output(output=output)
Naturally, I get 'str' object is not callable. Is there a way to tell 
func that the first output is actually a function? (like in C++, 
::output(output) )
output_alias = output
def func (output=''):
output_alias(output=output)
Daniel
--
http://mail.python.org/mailman/listinfo/python-list


Best way to make a list unique?

2005-03-08 Thread Eric Pederson
I have 

 listA=[1,2,3,4,5,4,3,4,3,2,1]

and I want a list of only the unique members.

This seems inefficient, but works fine over my small sample lists:

 listA=[a for a in set(listA)]


Is there a more efficient approach for cases where listA is large?






Eric Pederson
:::
domainNot=@something.com
domainIs=domainNot.replace(s,z)
ePrefix=.join([chr(ord(x)+1) for x in do])
mailMeAt=ePrefix+domainIs
:::

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


Re: How to script DOS app that doesn't use stdout

2005-03-08 Thread Gregor
 Gregor [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]

 There's a DOS console application I am trying to script (in Python),
 but it
 doesn't seem to use stdout or stderr... For example, if I redirect
 output to a file (cmd  file.txt), the output still appears on
 screen. Similarly, the output pipes returned by popen* don't catch
 the app's output. How might this app be generating its output? Any
 thoughts on how it
 could be captured (perhaps with something in the win32 extensions)?

Paul Watson [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 The good-ole DOS app could be doing many things.  It could be making
 BIOS calls or writing directly to the video display memory at segment
 0xB800. One would think that if it did a DUP of stdout that it might
 get captured, but apparently you have tried the popen* family.
 
 Any hints as to what the DOS app is?  If it is known by anyone,
 perhaps a workaround is also known. 

Hmmm. Sounds like scripting this app might be a bit of a problem...

I don't think the program was available to the general public... It's 
called PC-Bill. It's used to send doctors' bills to the Canadian 
government.

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


Re: py2exe Python2.4 and warning: string/unicode conversion

2005-03-08 Thread Martin v. Löwis
Miki Tebeka wrote:
  I'm shipping an application using py2exe.
With Python2.3 it worked fine but when switching to Python2.4 I started
getting warning: string/unicode conversion all over the place.
Any ideas how to solve this (other than using 'filterwarnings')?
It is really surprising that you get this, as the only occurrence of
the string string/unicode conversion in Python was *removed* in
Python 2.4. It was present in 2.3, and occurred if strtoul returned
an overflow error.
Are you sure you are using Python 2.4?
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to make a list unique?

2005-03-08 Thread Diez B. Roggisch
Eric Pederson wrote:

 I have
 
 listA=[1,2,3,4,5,4,3,4,3,2,1]
 
 and I want a list of only the unique members.
 
 This seems inefficient, but works fine over my small sample lists:
 
 listA=[a for a in set(listA)]
 
 
 Is there a more efficient approach for cases where listA is large?

No. But I doubt that that is what you actually want, as listA will lose its
order afterwards. Typically, something like that gets written like this:

inserted = set()
res = []
for e in listA:
   if not e in inserted:
   res.append(e)
   inserted.add(e)
listA = res

Or, with a little helperfunction:

inserted = set()
def foo(e):
inserted.add(e)
return e
listA = [foo(e) for e in listA if not e in inserted]

But ist's not really much better.

-- 
Regards,

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


Re: Creating module skeleton from unit tests

2005-03-08 Thread Edvard Majakari
Peter Maas [EMAIL PROTECTED] writes:

 I think this is too difficult, because there are many ways to write
 code (even skeletons) for a use case. An easier approach would
 be to write the skeleton manually, embed the test cases in the doc
 strings and generate the test code from the doc strings. If I
 remember correctly IBM has published something to generate unit
 tests from code. Python has a doctest module to support testing
 derived from doc strings. This can be combined with unit tests.

Yes - actually I channged my mind in somewhere in the article - I actually
don't want to create typical use-cases in the test bed, rather create a
skeleton which covers each method at least somehow (no code inside skeleton
would be needed).

   The problem can be solved more easily if you design the module
 skeleton first, then the tests and then the logic for the skeleton
 - you would be creating tests before the code, but many people
   wouldn't regard it as TDD then.

 You shouldn't care if your approach works for you.

Yes, you are right. I didn't select my words very well - I just meant that it
wouldn't be TDD then. Of course it might work, but I'd like to to it the TDD
way for now.

But thanks for the tip, I could see what IBM has done and then forget about
doing it automatically :)

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),\n;
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shuffle the lines of a large file

2005-03-08 Thread Nick Craig-Wood
Raymond Hettinger [EMAIL PROTECTED] wrote:
  from random import random
  out = open('corpus.decorated', 'w')
  for line in open('corpus.uniq'):
  print  out, '%.14f %s' % (random(), line),
 
  out.close()
 
  sort corpus.decorated | cut -c 18-  corpus.randomized

Very good solution!

Sort is truly excellent at very large datasets.  If you give it a file
bigger than memory then it divides it up into temporary files of
memory size, sorts each one, then merges all the temporary files back
together.

You tune the memory sort uses for in memory sorts with --buffer-size.
Its pretty good at auto tuning though.

You may want to set --temporary-directory also to save filling up your
/tmp.

In a previous job I did a lot of stuff with usenet news and was
forever blowing up the server with scripts which used too much memory.
sort was always the solution!

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


looking for way to include many times some .py code from another python code

2005-03-08 Thread Martin MOKREJ
Hi,
 I'm looking for some easy way to do something like include in c or PHP.
Imagine I would like to have:
cat somefile.py
a = 222
b = 111
c = 9
cat somefile2.py
self.xxx = a
self.zzz = b
self.c = c
self.d = d
cat anotherfile.py
def a():
   include somefile
   postprocess(a)
def b():
   include somefile
   postprocess(a, b, c)
class klass():
   def __init__(self, a, b, c, d):
   include somefile2

 I know about module imports and reloads, but am not sure if this is the right
way to go. Mainly, I want to assign to multiple object instances some self bound
variables. Their values will be different, so I can't use global variables.
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Speeding up CGIHTTPServer (Tim Roberts)

2005-03-08 Thread Johan Kohler
On Tue,  8 Mar 2005 10:25:46 +0100 (CET), [EMAIL PROTECTED]  
wrote:

I'm using CGIHTTPServer (via its test() method) to test some CGI on my
Windoze 98 box.  I find that the execution is very slow.  Is there
anything I can do to make sure I'm getting the best performance out of
CGIHTTPServer?

Compared to what, and on what hardware?

CGI is not a rip-roaring performance demon on any platform, but
CGIHTTPServer is designed to be convenient more than fast.  It isn't  
going
to do as well as a native server.
The key question you need ask is this: is it fast enough?  If you're  
doing
a web page for internal use that is only going to get a hundred hits a  
day,
who cares if each page takes 5 seconds to render?  If you're doing 10,000
hits a day, you need to choose something other than Windows 98.
Fair enough.  Pretend my question said compared to apache, but also to  
CGIHTTPServer on linux.  The Windows box has modest specs Celeron 2.8GHz,  
256MB, but it takes 30-60s render pages.  I was using it to test my cgi  
locally, ie. no network, one user

Windows bashing is fun :-) but unfortunately I don't think that is the  
issue here.  The answer I was looking for was something like - yes,  
change config file so-and-so in such-and-such a way or simply no.

If there is no way to improve performance, could anyone tell my _why_ it's  
running so slowly?  Presumably spawning a process takes some time.  The  
code I'm running as CGI is not hectic at all.

Thanks in advance,
Johan

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Please find our disclaimer at http://www.ukzn.ac.za/disclaimer

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


Re: Google Technology

2005-03-08 Thread vijay123
Thank you all!

It's a good start for me...with the info. u provided.

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


Re: Speeding up CGIHTTPServer (Tim Roberts)

2005-03-08 Thread Diez B. Roggisch
 If there is no way to improve performance, could anyone tell my _why_ it's
 running so slowly?  Presumably spawning a process takes some time.  The
 code I'm running as CGI is not hectic at all.

Just an educated guess: Maybe some timeouts or slowly answered requests are
the problem - e.g. DNS is often a candidate than can slow down network
experience a lot. So maybe thats causing your trouble?
-- 
Regards,

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


Re: Best way to make a list unique?

2005-03-08 Thread Max M
Eric Pederson wrote:
I have 


listA=[1,2,3,4,5,4,3,4,3,2,1]

and I want a list of only the unique members.
This seems inefficient, but works fine over my small sample lists:

listA=[a for a in set(listA)]
Is there a more efficient approach for cases where listA is large?

no. Even though the code can be a little simpler:
listA = list(Set(listA))
You don't even need to convert it to a list. You can just iterate over 
the set.

 la = [1,2,3,4,3,2,3,4,5]
 from sets import Set
 sa = Set(la)
 for itm in sa:
... print itm
1
2
3
4
5
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: Speeding up CGIHTTPServer

2005-03-08 Thread Steve Holden
Tim Roberts wrote:
Johan Kohler [EMAIL PROTECTED] wrote:
I'm using CGIHTTPServer (via its test() method) to test some CGI on my
Windoze 98 box.  I find that the execution is very slow.  Is there
anything I can do to make sure I'm getting the best performance out of
CGIHTTPServer?

Compared to what, and on what hardware?
CGI is not a rip-roaring performance demon on any platform, but
CGIHTTPServer is designed to be convenient more than fast.  It isn't going
to do as well as a native server.
The key question you need ask is this: is it fast enough?  If you're doing
a web page for internal use that is only going to get a hundred hits a day,
who cares if each page takes 5 seconds to render?  If you're doing 10,000
hits a day, you need to choose something other than Windows 98.
There are some other options.  Microsoft has Personal Web Server for Win98,
although I think it's awfully hard to configure.  thttpd and xitami are
good lightweight web servers.
Apache works quite well in Windows, but I don't think it is very happy on
Windows 98.
It's OK if you update the TCP/IP stack, but Xitami is a much easier 
lightweight install.

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


Re: Speeding up CGIHTTPServer (Tim Roberts)

2005-03-08 Thread Thomas Guettler
Am Tue, 08 Mar 2005 13:56:57 +0200 schrieb Johan Kohler:

 On Tue,  8 Mar 2005 10:25:46 +0100 (CET), [EMAIL PROTECTED]  
 wrote:
 
 I'm using CGIHTTPServer (via its test() method) to test some CGI on my
 Windoze 98 box.  I find that the execution is very slow.  Is there
 anything I can do to make sure I'm getting the best performance out of
 CGIHTTPServer?

Hi,

Maybe a personal firewall or virus-checker slows it down.

 Thomas

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


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


Good variable names (Was: Re: Best way to make a list unique?)

2005-03-08 Thread Roy Smith
Diez B. Roggisch [EMAIL PROTECTED] wrote:
 inserted = set()
 res = []
 for e in listA:
if not e in inserted:
res.append(e)
inserted.add(e)
 listA = res

I'm going to go off on a tangent here and put in a plea for better variable 
naming.  I'm looking at the above code, and can't figure out what res is 
supposed to be.  Is it short for rest, as in the rest of the items?  
Residual?  Result?  Restore?  Any of these seems plausable.  Not knowing 
which makes it much harder to understand what the code does.  When you say 
res.append(e), are you building up the result that you're going to 
return, or are you building up a list of elements that got eliminated (i.e. 
residual) because they are duplicates?

Yes, I did eventually figure it out.  It didn't even take that long, but 
this is a trivial little piece of code; it shouldn't have taken any time at 
all to figure it out.  All you saved by using res instead of result was 
9 keystrokes (ult, in three places), but it cost every one of your 
readers extra brainpower to figure out what you meant.  To quote one of 
Aahz's better signatures, Typing is cheap.  Thinking is expensive. :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for way to include many times some .py code from another python code

2005-03-08 Thread Brano Zarnovican
On Tuesday 08 March 2005 12:41, Martin MOKREJ wrote:
 cat somefile.py
 a = 222
 b = 111
 c = 9

 cat anotherfile.py

 def a():
 include somefile
 postprocess(a)

What about :
def a():
  exec open('somefile.py')
  postprocess(a)

You can even use the optional dictionary parameter:

class klass(object):
  pass

a = klass()

exec open('somefile.py') in a.__dict__

print a.a, a.b, a.c
222 111 9

Cheers,

BranoZ

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


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Scott David Daniels
Martin MOKREJ wrote:
Hi,
 I'm looking for some easy way to do something like include in c or PHP.
Imagine I would like to have:   
 I know about module imports and reloads, but am not sure if this is the 
right way to go. Mainly, I want to assign to multiple object instances 
some self bound variables. Their values will be different, so I can't 
 use global variables.
Someone will, no doubt, find a way to code this.  I suggest you are
fighting the language here -- learn to use it instead.  Decide what
you really want to do, not how you want to do it.  Then try to figure
out how to accomplish your real goal in the normal flow of the language.
-Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


[Fwd: Re: quick question]

2005-03-08 Thread Neil Benn
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : [EMAIL PROTECTED]
Cenix Website : http://www.cenix-bioscience.com
---BeginMessage---
Leeds, Mark wrote:
I have a string variable say 8023  and
I want to get rid of the beginning
And ending quotes.
Ive tried different things
But havent had any success.
Im definitely a python hacker and
Not an expert. Thanks.
Mark
Hello,
You can use strip (pass in a char):
. strDemo = 'neil'
. strDemo.strip('')
'neil'
.
Cheers,
Neil
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : [EMAIL PROTECTED]
Cenix Website : http://www.cenix-bioscience.com

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

RE: Best way to make a list unique?

2005-03-08 Thread Batista, Facundo
Title: RE: Best way to make a list unique?





[Max M]


#-  la = [1,2,3,4,3,2,3,4,5]
#-  from sets import Set
#-  sa = Set(la)
#-  for itm in sa:
#- ... print itm


Remember that in Python 2.4 you have ´´set´´ as a built-in data type:


 la = [1,2,3,4,3,2,3,4,5]
 sa = set(la)
 for it in sa:
 print it
 
1
2
3
4
5



. Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



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

Re: Good variable names (Was: Re: Best way to make a list unique?)

2005-03-08 Thread Diez B. Roggisch
 I'm going to go off on a tangent here and put in a plea for better
 variable
 naming.  I'm looking at the above code, and can't figure out what res is
 supposed to be.  Is it short for rest, as in the rest of the items?
 Residual?  Result?  Restore?  Any of these seems plausable.  Not knowing
 which makes it much harder to understand what the code does.  When you say
 res.append(e), are you building up the result that you're going to
 return, or are you building up a list of elements that got eliminated
 (i.e. residual) because they are duplicates?
 
 Yes, I did eventually figure it out.  It didn't even take that long, but
 this is a trivial little piece of code; it shouldn't have taken any time
 at
 all to figure it out.  All you saved by using res instead of result
 was 9 keystrokes (ult, in three places), but it cost every one of your
 readers extra brainpower to figure out what you meant.  To quote one of
 Aahz's better signatures, Typing is cheap.  Thinking is expensive. :-)

I usually use much more telling variable names - from the source I just
wrote a minute ago:

self.selection_color_map = {}
self.selection_color = (255,255,0)
self.assigned_color_map = {}
self.default_color = (0,0,0)
self.known_names = sets.Set()

As you can see - no desire to shorten names. But res for result is as
hardwired to me as i,j,k for iterating numbers. So bear with me on this
case.

-- 
Regards,

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


Re: Best way to make a list unique?

2005-03-08 Thread Scott David Daniels
Max M wrote:
Eric Pederson wrote:
listA = list(Set(listA))
As of 2.4, set is a built-in type (2.3 had Set in module sets).
Another 2.4-ism is sorted, which might very well be the way you
want to turn the set into a list:
listA = sorted(set(listA))
for this particular use, you can define sorted in 2.3 as:
def sorted(iterable):
result = list(iterable)
result.sort()
return result
The full sorted functionality can be (and has been) defined in 2.3,
but just using 2.4 would be a better bet.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Kent Johnson
Martin MOKREJ wrote:
Hi,
 I'm looking for some easy way to do something like include in c or PHP.
Imagine I would like to have:
cat somefile.py
a = 222
b = 111
c = 9
cat somefile2.py
self.xxx = a
self.zzz = b
self.c = c
self.d = d
cat anotherfile.py
def a():
   include somefile
   postprocess(a)
def b():
   include somefile
   postprocess(a, b, c)
class klass():
   def __init__(self, a, b, c, d):
   include somefile2
You can do this with module-level variables and a base class for klass:
cat somefile.py
a = 222
b = 111
c = 9
cat somefile2.py
class base:
def __init__(self, a, b, c, d):
self.xxx = a
self.zzz = b
self.c = c
self.d = d
cat anotherfile.py
import somefile, somefile2
def a():
   postprocess(somefile.a)
def b():
   postprocess(somefile.a, somefile.b, somefile.c)
class klass(somefile2.base):
   def __init__(self, a, b, c, d):
   somefile2.base.__init__(self, a, b, c, d)
Kent

 I know about module imports and reloads, but am not sure if this is the 
right
way to go. Mainly, I want to assign to multiple object instances some 
self bound
variables. Their values will be different, so I can't use global variables.

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


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Martin MOKREJ
Scott David Daniels wrote:
Martin MOKREJ wrote:
Hi,
 I'm looking for some easy way to do something like include in c or PHP.
Imagine I would like to have:   
 I know about module imports and reloads, but am not sure if this is 
the right way to go. Mainly, I want to assign to multiple object 
instances some self bound variables. Their values will be different, 
so I can't 
  use global variables.
Someone will, no doubt, find a way to code this.  I suggest you are
fighting the language here -- learn to use it instead.  Decide what
you really want to do, not how you want to do it.  Then try to figure
out how to accomplish your real goal in the normal flow of the language.
See my post on Mar 2 about automating assignment of class variables.
I got no answers, maybe I wasn't clear enough ... :(
I need to define lots of variables. The variable names are often identical.
The problem is that if I put such a code into a function ... no, I'm not going
to pass anything to a function to get it returned back. I just want to get
lots of variables assigned, that all. If I put them into module, it get's
exectued only once unless I do reload. And I'd have to use:
from some import *, because mainly I'm interrested in assigning to self:
self.x = blah
self.y = uhm
I'm newbie, sure.
M.
--
http://mail.python.org/mailman/listinfo/python-list


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Martin MOKREJ
Kent Johnson wrote:
Martin MOKREJ wrote:
Hi,
 I'm looking for some easy way to do something like include in c or PHP.
Imagine I would like to have:
cat somefile.py
a = 222
b = 111
c = 9
cat somefile2.py
self.xxx = a
self.zzz = b
self.c = c
self.d = d
cat anotherfile.py
def a():
   include somefile
   postprocess(a)
def b():
   include somefile
   postprocess(a, b, c)
class klass():
   def __init__(self, a, b, c, d):
   include somefile2

You can do this with module-level variables and a base class for klass:
cat somefile.py
a = 222
b = 111
c = 9
cat somefile2.py
class base:
def __init__(self, a, b, c, d):
self.xxx = a
self.zzz = b
self.c = c
self.d = d
cat anotherfile.py
import somefile, somefile2
def a():
   postprocess(somefile.a)
def b():
   postprocess(somefile.a, somefile.b, somefile.c)
class klass(somefile2.base):
   def __init__(self, a, b, c, d):
   somefile2.base.__init__(self, a, b, c, d)
Oh, I've picked up not the best example. I wanted to set the variables
not under __init__, but under some other method. So this is actually
what I really wanted.
class klass(somefile2.base):
  def __init__():
  pass
  def set_them(self, a, b, c, d):
  somefile2.base.__init__(self, a, b, c, d)
Thanks!
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Sorting dictionary by 'sub' value

2005-03-08 Thread Rory Campbell-Lange
I have a dictionary of images. I wish to sort the dictionary 'v' by a
dictionary value using python 2.3. The dictionary value is the date
attribute as shown here:

v[imagename][9]['date']

This attribute is an extracted EXIF value from the following set:

data element [9] of v[imagename]:

{'now': datetime.date(2005, 3, 7),
'y'   : (0x011B) Ratio=72 @ 182,
'ctime'   : datetime.date(2005, 3, 7),
'width'   : (0xA002) Long=1024 @ 434,
'length'  : (0xA003) Long=768 @ 446,
'date': (0x9004) ASCII=2004:12:07 00:18:20 @ 514,
'x'   : (0x011A) Ratio=72 @ 174,
'model'   : (0x0110) ASCII=PENTAX Optio 330 @ 156,
'size': 367415L,
'orientation' : (0x0112) Short=1 @ 42}

Thanks,
Rory

-- 
Rory Campbell-Lange 
[EMAIL PROTECTED]
www.campbell-lange.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Martin MOKREJ
Diez B. Roggisch wrote:
See my post on Mar 2 about automating assignment of class variables.
I got no answers, maybe I wasn't clear enough ... :(

Seems so - I for example didn't understand it.

I need to define lots of variables. The variable names are often
identical. The problem is that if I put such a code into a function ...
no, I'm not going to pass anything to a function to get it returned back.
I just want to get lots of variables assigned, that all. If I put them
into module, it get's exectued only once unless I do reload. And I'd have
to use: from some import *, because mainly I'm interrested in assigning
to self: self.x = blah
self.y = uhm

Okay, I try and guess: From your two posts I infer that you want to set
variables in instances. But you've got lots of these and you don't want to
write code like this:
class Foo:
def __init__(self, a, b, .):
 self.a = a
 self.b = b
 
If that is what you want, then this might help you: Put all the values in a
Good guess! ;)
dictionary - like this:
my_vals = {a: 1, b : 2, }
There are plenty of other ways to create such a dictionary, but I won't
digress on that here.
Now in your class, you pass than dict to your constructor and then simply
update the instance's __dict__ so that the keys-value-pairs in my_vals
become attributes:
class Foo:
def __init__(self, my_vals):
 self.__dict__.update(my_vals)
foo = Foo(my_vals)
print foo.a
- 1
Hope this helps,
Sure. Thanks! Would you prefer exactly for this method over the method 
posted by Kent Johnson
few minutes ago?
Am I so deperately fighting the language? No-one here on the list needs to set 
hundreds
variables at once somewhere in their code? I still don't get why:
include somefile.py would be that non-pythonic so that it's not available, but
I have already two choices how to proceed anyway. Thanks. ;)
Now have to figure out how to assign them easily into the XML tree.
martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing files installed with distutils

2005-03-08 Thread [EMAIL PROTECTED]
I was wondering how to do this too. I'm trying to write a distutils
setup.py script that has some data I'd like to include.  From the
distutils docs I get

data_files specifies a sequence of (directory, files) pairs in the
following way:

setup(...
  data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
  ('config', ['cfg/data.cfg']),
  ('/etc/init.d', ['init-script'])]
 )

I can use sys.prefix to find the top level where python is installed,
but this doesn't tell me specifically where site-packages is. On my
Linux box it is in

{sys.prefix}/lib/python2.3/site-packages

but on Windows, it's in

{sys.prefix}/Lib/site-packages.

Do I need to use sys.platform (along with sys.version) to check what
type of machine I'm on, or is there some better  method to get the
location of site-packages?

Thanks.

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


Re: Appeal for python developers

2005-03-08 Thread huw . davies
BOOGIEMAN [EMAIL PROTECTED] wrote:
 Please include goto command in future python realeses
 I know that proffesional programers doesn't like to use it, 
 but for me as newbie it's too hard to get used replacing it 
 with while, def or other commands

It was only when I read this thread that I realized that Python 
doesn't have a goto! I guess the fact that I wrote programs 25+ years
ago in another programming language that didn't have goto either has
influenced the way I program!
-- 
Huw Davies   | e-mail: [EMAIL PROTECTED]
Melbourne| If soccer was meant to be played in the
Australia| air, the sky would be painted green 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting dictionary by 'sub' value

2005-03-08 Thread Diez B. Roggisch
 I have a dictionary of images. I wish to sort the dictionary 'v' by a
 dictionary value using python 2.3. The dictionary value is the date
 attribute as shown here:
 
 v[imagename][9]['date']
 
 This attribute is an extracted EXIF value from the following set:
 
 data element [9] of v[imagename]:
 
 {'now': datetime.date(2005, 3, 7),
 'y'   : (0x011B) Ratio=72 @ 182,
 'ctime'   : datetime.date(2005, 3, 7),
 'width'   : (0xA002) Long=1024 @ 434,
 'length'  : (0xA003) Long=768 @ 446,
 'date': (0x9004) ASCII=2004:12:07 00:18:20 @ 514,
 'x'   : (0x011A) Ratio=72 @ 174,
 'model'   : (0x0110) ASCII=PENTAX Optio 330 @ 156,
 'size': 367415L,
 'orientation' : (0x0112) Short=1 @ 42}


You can't sort dicts - they don't impose an order on either key or value.
There are ordered dict implementations out there, but AFAIK the only keep
the keys sorted, or maybe the (key,values) in the insertion order.

But maybe this helps you:

l = v.items()
l.sort(lambda a, b: cmp(a[9]['date'], b[9]['date'])


-- 
Regards,

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


Re: parameter name conflict. How to solve?

2005-03-08 Thread Pierre Barbier de Reuille
Bo Peng a écrit :
Dear list,
If you ask: why do you choose these names? The answer is: they need to 
be conformable with other functions, parameter names.

I have a function that pretty much like:
def output(output=''):
  print output
and now in another function, I need to call output function, with again 
keyword parameter output

def func(output=''):
  output(output=output)
Naturally, I get 'str' object is not callable. Is there a way to tell 
func that the first output is actually a function? (like in C++, 
::output(output) )

Thanks.
Bo
What I'd suggest is :
def func(output=''):
  gobals()[output](output=output)
that way, the function resolution is still dynamic, but you explicitly 
ask for a name global and not local ...

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


Re: determine directories with wildcard

2005-03-08 Thread Diez B. Roggisch
Thomas Rademacher wrote:

 Hello,
 
 I want to collect with the wildcard '*' all existing directories.
 For example:  /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*
 
 How can I resolve this problem?

This is some sort of pattern matching. What I'd do is to convert your
pattern to a regex:

rex = re.compile(r/dir/dir/.*/dir/.*/dir/.*)

Then create a list of dirs with os.walk:

dirs = [dirpath for dirpath, foo, bar in os.walk(topdir) if
rex.match(dirpath)]


This is untested, but should do the trick.



-- 
Regards,

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


Re: determine directories with wildcard

2005-03-08 Thread Heiko Wundram
On Tuesday 08 March 2005 14:33, Thomas Rademacher wrote:
 How can I resolve this problem?

python
 import glob
 help(glob)

or look at the online documentation for glob.

-- 
--- Heiko.


pgp6MyvJSQxu3.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Split text file into words

2005-03-08 Thread qwweeeit
The standard split() can use only one delimiter. To split a text file
into words  you need multiple delimiters like blank, punctuation, math
signs (+-*/), parenteses and so on.

I didn't succeeded in using re.split()...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: determine directories with wildcard

2005-03-08 Thread Vincent Wehren
Thomas Rademacher wrote:
Hello,
I want to collect with the wildcard '*' all existing directories.
For example:  /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*
How can I resolve this problem?
Thanks for your hints, Thomas.

You may want to check out the glob module. E.g. something like:
 import glob, os
 p = c:/*/*/site-packages/*
 dirs = [d for d in glob.glob(p) if os.path.isdir(d)]
 print dirs
['c:/Python23\\Lib\\site-packages\\atox', 
'c:/Python23\\Lib\\site-packages\\BDBStorage', 
'c:/Python23\\Lib\\site-packages\\BitTorrent', 
'c:/Python23\\Lib\\site-packages\\BTrees', 
'c:/Python23\\Lib\\site-packages\\ChartDirector', 
'c:/Python23\\Lib\\site-packages\\cjkcodecs', 
'c:/Python23\\Lib\\site-packages\\ctypes', 
'c:/Python23\\Lib\\site-packages\\CVS', 
'c:/Python23\\Lib\\site-packages\\elementtree', 
'c:/Python23\\Lib\\site-packages\\enchant', 
'c:/Python23\\Lib\\site-packages\\Ft', 
'c:/Python23\\Lib\\site-packages\\imdb', 
'c:/Python23\\Lib\\site-packages\\isapi', 
'c:/Python23\\Lib\\site-packages\\logilab', 
'c:/Python23\\Lib\\site-packages\\mx', 
'c:/Python23\\Lib\\site-packages\\MySQLdb', 
'c:/Python23\\Lib\\site-packages\\numarray', 
'c:/Python23\\Lib\\site-packages\\OpenGL', 
'c:/Python23\\Lib\\site-packages\\OpenGLContext', 
'c:/Python23\\Lib\\site-packages\\parallel', 
'c:/Python23\\Lib\\site-packages\\Persistence', 
'c:/Python23\\Lib\\site-packages\\PIL', 
'c:/Python23\\Lib\\site-packages\\psyco', 
'c:/Python23\\Lib\\site-packages\\py2exe', 
'c:/Python23\\Lib\\site-packages\\pychecker', 
'c:/Python23\\Lib\\site-packages\\pynsource', 
'c:/Python23\\Lib\\site-packages\\Pyrex', 
'c:/Python23\\Lib\\site-packages\\Pyro', 
'c:/Python23\\Lib\\site-packages\\pythonwin', 
'c:/Python23\\Lib\\site-packages\\pywin32_system32', 
'c:/Python23\\Lib\\site-packages\\pyXLWriter', 
'c:/Python23\\Lib\\site-packages\\reportlab', 
'c:/Python23\\Lib\\site-packages\\serial', 
'c:/Python23\\Lib\\site-packages\\spambayes', 
'c:/Python23\\Lib\\site-packages\\ThreadedAsync', 
'c:/Python23\\Lib\\site-packages\\vrml', 
'c:/Python23\\Lib\\site-packages\\win32', 
'c:/Python23\\Lib\\site-packages\\win32com', 
'c:/Python23\\Lib\\site-packages\\win32comext', 
'c:/Python23\\Lib\\site-packages\\wx', 
'c:/Python23\\Lib\\site-packages\\wxPython', 
'c:/Python23\\Lib\\site-packages\\ZConfig', 
'c:/Python23\\Lib\\site-packages\\zdaemon', 
'c:/Python23\\Lib\\site-packages\\ZEO', 
'c:/Python23\\Lib\\site-packages\\zLOG', 
'c:/Python23\\Lib\\site-packages\\ZODB', 
'c:/Python23\\Lib\\site-packages\\ZopeUndo', 
'c:/Python23\\Lib\\site-packages\\_xmlplus', 
'c:/Python24\\Lib\\site-packages\\ChartDirector', 
'c:/Python24\\Lib\\site-packages\\elementtidy', 
'c:/Python24\\Lib\\site-packages\\elementtree', 
'c:/Python24\\Lib\\site-packages\\isapi', 
'c:/Python24\\Lib\\site-packages\\py2exe', 
'c:/Python24\\Lib\\site-packages\\pythonwin', 
'c:/Python24\\Lib\\site-packages\\pywin32_system32', 
'c:/Python24\\Lib\\site-packages\\win32', 
'c:/Python24\\Lib\\site-packages\\win32com', 
'c:/Python24\\Lib\\site-packages\\win32comext', 
'c:/Python24\\Lib\\site-packages\\wx-2.5.3-msw-unicode']

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


Out of Office AutoReply: MDaemon Warning - virus found: Returned mail: Data format error

2005-03-08 Thread Jover, Sergi (BPDO VAT Reporting)
Hi,

I will be on vacation from Monday 7th till Friday 11th both included.  And 
during this time I will not be able to access to my phone and email.  

For urgent queries please contact:

* HPIS USZ8 and HP UK ltd please contact Nuria Satorra,
* All other VAT reporting operation queries please contact David Carrion and 
Roberto Collado,
* For general stuff please contact with Roberto Collado,
* For escalations please contact Xavier Romeu

Otherwise, I will get back to you once I am back to the office on the 14th of 
March 05.

Apologies for any inconvenience caused.


Thanks  Regards,

Sergi Jover
VAT Reporting Team Lead
Barcelona Business Center
--
http://mail.python.org/mailman/listinfo/python-list


Re: Split text file into words

2005-03-08 Thread Heiko Wundram
On Tuesday 08 March 2005 14:43, qwweeeit wrote:
 The standard split() can use only one delimiter. To split a text file
 into words  you need multiple delimiters like blank, punctuation, math
 signs (+-*/), parenteses and so on.

 I didn't succeeded in using re.split()...

Then try again... ;) No, seriously, re.split() can do what you want. Just 
think about what are word delimiters.

Say, you want to split on all whitespace, and ,, ., and ?, then you'd 
use something like:

[EMAIL PROTECTED] ~ $ python
Python 2.3.5 (#1, Feb 27 2005, 22:40:59)
[GCC 3.4.3 20050110 (Gentoo Linux 3.4.3.20050110, ssp-3.4.3.20050110-0, 
pie-8.7 on linux2
Type help, copyright, credits or license for more information.
 import re
 teststr = Hello qwweeeit, how are you? I am fine, today, actually.
 re.split(r[\s\.,\?]+,teststr)
['Hello', 'qwweeeit', 'how', 'are', 'you', 'I', 'am', 'fine', 'today', 
'actually', '']

Extending with other word separators shouldn't be hard... Just have a look at

http://docs.python.org/lib/re-syntax.html

HTH!

-- 
--- Heiko.


pgpiHbI7zcTjy.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: determine directories with wildcard

2005-03-08 Thread Simon Brunning
On Tue, 8 Mar 2005 14:33:59 +0100, Thomas Rademacher
[EMAIL PROTECTED] wrote:
 Hello,
 
 I want to collect with the wildcard '*' all existing directories.
 For example:  /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*

How about something like:

import fnmatch
import os

root = 'd:\\'
filter = r'*\*python*\*'

for dirpath, dirnames, filenames in os.walk(root):
if fnmatch.fnmatch(dirpath, filter):
print 'matched', dirpath

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing files installed with distutils

2005-03-08 Thread Steve Holden
[EMAIL PROTECTED] wrote:
I was wondering how to do this too. I'm trying to write a distutils
setup.py script that has some data I'd like to include.  From the
distutils docs I get
data_files specifies a sequence of (directory, files) pairs in the
following way:
setup(...
  data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
  ('config', ['cfg/data.cfg']),
  ('/etc/init.d', ['init-script'])]
 )
I can use sys.prefix to find the top level where python is installed,
but this doesn't tell me specifically where site-packages is. On my
Linux box it is in
{sys.prefix}/lib/python2.3/site-packages
but on Windows, it's in
{sys.prefix}/Lib/site-packages.
Do I need to use sys.platform (along with sys.version) to check what
type of machine I'm on, or is there some better  method to get the
location of site-packages?
This is one of the areas where distutils could probably do with some 
improvement. I don;t know whether it's on any developers priority list, 
though.

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


Re: Speeding up CGIHTTPServer (Tim Roberts)

2005-03-08 Thread Steve Nordby
Diez B. Roggisch wrote:

  If there is no way to improve performance, could anyone tell my _why_ it's
  running so slowly?  Presumably spawning a process takes some time.  The
  code I'm running as CGI is not hectic at all.

 Just an educated guess: Maybe some timeouts or slowly answered requests are
 the problem - e.g. DNS is often a candidate than can slow down network
 experience a lot. So maybe thats causing your trouble?


I also got very slow responses using Python's HTTP server library.  I found that
changing the address_string(self) method in
BaseHTTPServer.BaseHTTPRequestHandler to return self.client_address[0] instead
of doing a hostname lookup cured the problem.  The doc string says the method is
only used for logging, and so far I've experienced no ill side effects.

--
Steve



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


Re: looking for way to include many times some .py code fromanotherpython code

2005-03-08 Thread Kent Johnson
Martin MOKREJ wrote:
Oh, I've picked up not the best example. I wanted to set the variables
not under __init__, but under some other method. So this is actually
what I really wanted.
class klass(somefile2.base):
  def __init__():
  pass
  def set_them(self, a, b, c, d):
  somefile2.base.__init__(self, a, b, c, d)
In that case you can define set_them() directly in the base class and omit 
set_them from klass:
class base:
  def set_them(self, a, b, c, d):
self.a = a
# etc
I'm guessing here, but if a, b, c, d are the same variables defined in your original somefile.py, 
and the intent is to make them attributes of the klass instance, you could do something like this 
and avoid listing all the arguments to klass.set_them():

## somefile.py
a = 222
b = 111
c = 9
def set_them(obj):
  obj.a = a
  obj.b = b
  obj.c = c
## anotherfile.py
import somefile
class klass:
  def set_them(self):
somefile.set_them(self)
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Duncan Booth
Martin MOKREJŠ wrote:

 Am I so deperately fighting the language? No-one here on the list
 needs to set hundreds variables at once somewhere in their code? I
 still don't get why: 

I've certainly never needed to set hundreds of variables at once in my 
code. I might have hundreds of values, but if so they go into a list or a 
dictionary or some other suitable data structure.

There isn't any point setting hundreds of variables unless you also 
have hundreds of different expressions accessing hundreds of variables. If 
they are all accessed in a similar way then this indicates they shouldn't 
be separate variables. If they are all accessed differently then you have 
some very complex code and hard to maintain code which can probably be 
simplified.

Can you give a use case where you think 'hundreds of variables' would be 
needed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: determine directories with wildcard

2005-03-08 Thread Thomas Rademacher
Thanks. It works fine! Thomas
Vincent Wehren [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 Thomas Rademacher wrote:
  Hello,
 
  I want to collect with the wildcard '*' all existing directories.
  For example:  /dir/dir/*/dir/*/dir/* or C:\dir\dir\*\dir\*\dir\*
 
  How can I resolve this problem?
 
  Thanks for your hints, Thomas.
 
 

 You may want to check out the glob module. E.g. something like:

   import glob, os
   p = c:/*/*/site-packages/*
   dirs = [d for d in glob.glob(p) if os.path.isdir(d)]
   print dirs
 ['c:/Python23\\Lib\\site-packages\\atox',
 'c:/Python23\\Lib\\site-packages\\BDBStorage',
 'c:/Python23\\Lib\\site-packages\\BitTorrent',
 'c:/Python23\\Lib\\site-packages\\BTrees',
 'c:/Python23\\Lib\\site-packages\\ChartDirector',
 'c:/Python23\\Lib\\site-packages\\cjkcodecs',
 'c:/Python23\\Lib\\site-packages\\ctypes',
 'c:/Python23\\Lib\\site-packages\\CVS',
 'c:/Python23\\Lib\\site-packages\\elementtree',
 'c:/Python23\\Lib\\site-packages\\enchant',
 'c:/Python23\\Lib\\site-packages\\Ft',
 'c:/Python23\\Lib\\site-packages\\imdb',
 'c:/Python23\\Lib\\site-packages\\isapi',
 'c:/Python23\\Lib\\site-packages\\logilab',
 'c:/Python23\\Lib\\site-packages\\mx',
 'c:/Python23\\Lib\\site-packages\\MySQLdb',
 'c:/Python23\\Lib\\site-packages\\numarray',
 'c:/Python23\\Lib\\site-packages\\OpenGL',
 'c:/Python23\\Lib\\site-packages\\OpenGLContext',
 'c:/Python23\\Lib\\site-packages\\parallel',
 'c:/Python23\\Lib\\site-packages\\Persistence',
 'c:/Python23\\Lib\\site-packages\\PIL',
 'c:/Python23\\Lib\\site-packages\\psyco',
 'c:/Python23\\Lib\\site-packages\\py2exe',
 'c:/Python23\\Lib\\site-packages\\pychecker',
 'c:/Python23\\Lib\\site-packages\\pynsource',
 'c:/Python23\\Lib\\site-packages\\Pyrex',
 'c:/Python23\\Lib\\site-packages\\Pyro',
 'c:/Python23\\Lib\\site-packages\\pythonwin',
 'c:/Python23\\Lib\\site-packages\\pywin32_system32',
 'c:/Python23\\Lib\\site-packages\\pyXLWriter',
 'c:/Python23\\Lib\\site-packages\\reportlab',
 'c:/Python23\\Lib\\site-packages\\serial',
 'c:/Python23\\Lib\\site-packages\\spambayes',
 'c:/Python23\\Lib\\site-packages\\ThreadedAsync',
 'c:/Python23\\Lib\\site-packages\\vrml',
 'c:/Python23\\Lib\\site-packages\\win32',
 'c:/Python23\\Lib\\site-packages\\win32com',
 'c:/Python23\\Lib\\site-packages\\win32comext',
 'c:/Python23\\Lib\\site-packages\\wx',
 'c:/Python23\\Lib\\site-packages\\wxPython',
 'c:/Python23\\Lib\\site-packages\\ZConfig',
 'c:/Python23\\Lib\\site-packages\\zdaemon',
 'c:/Python23\\Lib\\site-packages\\ZEO',
 'c:/Python23\\Lib\\site-packages\\zLOG',
 'c:/Python23\\Lib\\site-packages\\ZODB',
 'c:/Python23\\Lib\\site-packages\\ZopeUndo',
 'c:/Python23\\Lib\\site-packages\\_xmlplus',
 'c:/Python24\\Lib\\site-packages\\ChartDirector',
 'c:/Python24\\Lib\\site-packages\\elementtidy',
 'c:/Python24\\Lib\\site-packages\\elementtree',
 'c:/Python24\\Lib\\site-packages\\isapi',
 'c:/Python24\\Lib\\site-packages\\py2exe',
 'c:/Python24\\Lib\\site-packages\\pythonwin',
 'c:/Python24\\Lib\\site-packages\\pywin32_system32',
 'c:/Python24\\Lib\\site-packages\\win32',
 'c:/Python24\\Lib\\site-packages\\win32com',
 'c:/Python24\\Lib\\site-packages\\win32comext',
 'c:/Python24\\Lib\\site-packages\\wx-2.5.3-msw-unicode']


 --

 Vincent Wehren


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


RE: Sorting dictionary by 'sub' value

2005-03-08 Thread Batista, Facundo
Title: RE: Sorting dictionary by 'sub' value





[Rory Campbell-Lange]


#- I have a dictionary of images. I wish to sort the dictionary 'v' by a
#- dictionary value using python 2.3. The dictionary value is the date
#- attribute as shown here:


You have to use the DSU algorithm (Decorate, Sort, Undecorate), taking in consideration that the final sorted element can not be a dictionary. For example (with a simpler dictionary):

 d = {'a': ('m', 5), 'b': ('k', 9), 'c': ('f', 2)}


I want the dictionary values sorted by the number inside the tuple. So I prepare a list with that number first, and the dictionary key in second place:

 temp_list = [ (x[1][1], x[0]) for x in d.items() ]


Then, just sort it and use it.


 temp_list.sort()
 for (tmp, key) in temp_list:
 print d[key]
 
('f', 2)
('m', 5)
('k', 9)
 



. Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



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

Re: Split text file into words

2005-03-08 Thread Duncan Booth
qwweeeit wrote:

 The standard split() can use only one delimiter. To split a text file
 into words  you need multiple delimiters like blank, punctuation, math
 signs (+-*/), parenteses and so on.
 
 I didn't succeeded in using re.split()...
 

Would you care to elaborate on how you tried to use re.split and failed? We 
aren't mind readers here. An example of your non-working code along with 
the expected result and the actual result would be useful.

This is the first example given in the documentation for re.split:

re.split('\W+', 'Words, words, words.')
   ['Words', 'words', 'words', '']

Does it do what you want? If not what do you want?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe error: 2.4.2.4: No such file or directory

2005-03-08 Thread Larry Bates
Thomas,

Right on the mark.  Thanks for the help.

Larry Bates


Thomas Heller wrote:
 Larry Bates [EMAIL PROTECTED] writes:
 
 
I had occasion to look back at a project I did over a year ago
and needed to make one small change.  I use py2exe to package
it for distribution via Inno Setup.  After making my change
I tried to run my setup script that worked fine before and
get the following message:

F:\SYSCON\WTS\HTMLmenupython HTMLmenuSetup.py py2exe -w
running py2exe
running build
running build_scripts
not copying HTMLmenu.py (up-to-date)
running install_scripts
not copying build\scripts-2.2\HTMLmenu.py (output up-to-date)
+
| Processing script HTMLmenu.py with py2exe-0.3.3
+
Searching modules needed to run 'HTMLmenu.py' on path:
['F:\\SYSCON\\WTS\\HTMLmenu\\build\\bdist.win32\\winexe\\lib\\Python22\\Lib\\sit
e-packages', '', 'F:\\Larry\\Python', 
'C:\\Python22\\Lib\\site-packages\\Pythonw
in', 'C:\\Python22\\Lib\\site-packages\\win32', 
'C:\\Python22\\Lib\\site-package
s\\win32\\lib', 'C:\\Python22\\Lib\\site-packages', 'C:\\Python22\\DLLs', 
'C:\\P
ython22\\lib', 'C:\\Python22\\lib\\lib-tk', 'C:\\Python22', 
'C:\\Python22\\lib\\
site-packages\\HTMLgen', 'F:\\Larry\\Python\\Library', 
'C:\\Python22\\lib\\site-
packages\\PIL', 'C:\\Python22\\lib\\site-packages\\dynwin', 
'C:\\Python22\\lib\\
site-packages\\npstruct', 'C:\\Python22\\lib\\site-packages\\wxPython']
error: 2.4.2.4: No such file or directory

The only thing that I can think of is that perhaps I've upgraded my
wxWindows version.  I checked and 2.4.2.4 is the version, but I don't
know why py2exe is looking for such a directory.
 
 
 Old versions of wxWindows put an entry in the registry under the
 HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.x\Modules key.  This
 registry entry is (was) used to extend the Python path, but wxWindows
 used it to register it's version number.  You should try to remove this
 entry and run py2exe again.
 
 Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


capturing text from a GUI window

2005-03-08 Thread Earl Eiland
Anyone know how to capture text from GUI output?  I need to process
information returned via a GUI window.

Earl

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


Re: shuffle the lines of a large file

2005-03-08 Thread Simon Brunning
On 7 Mar 2005 06:38:49 -0800, gry@ll.mit.edu gry@ll.mit.edu wrote:
 As far as I can tell, what you ultimately want is to be able to extract
 a random (representative?) subset of sentences.

If this is what's wanted, then perhaps some variation on this cookbook
recipe might do the trick:

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

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Steve Holden
Martin MOKREJ wrote:
Diez B. Roggisch wrote:
See my post on Mar 2 about automating assignment of class variables.
I got no answers, maybe I wasn't clear enough ... :(

Seems so - I for example didn't understand it.

I need to define lots of variables. The variable names are often
identical. The problem is that if I put such a code into a function ...
no, I'm not going to pass anything to a function to get it returned 
back.
I just want to get lots of variables assigned, that all. If I put them
into module, it get's exectued only once unless I do reload. And I'd 
have
to use: from some import *, because mainly I'm interrested in 
assigning
to self: self.x = blah
self.y = uhm

Okay, I try and guess: From your two posts I infer that you want to set
variables in instances. But you've got lots of these and you don't 
want to
write code like this:

class Foo:
def __init__(self, a, b, .):
 self.a = a
 self.b = b
 
If that is what you want, then this might help you: Put all the values 
in a

Good guess! ;)
dictionary - like this:
my_vals = {a: 1, b : 2, }
There are plenty of other ways to create such a dictionary, but I won't
digress on that here.
Now in your class, you pass than dict to your constructor and then simply
update the instance's __dict__ so that the keys-value-pairs in my_vals
become attributes:
class Foo:
def __init__(self, my_vals):
 self.__dict__.update(my_vals)
foo = Foo(my_vals)
print foo.a
- 1
Hope this helps,

Sure. Thanks! Would you prefer exactly for this method over the method 
posted by Kent Johnson
few minutes ago?

Am I so deperately fighting the language? No-one here on the list needs 
to set hundreds
variables at once somewhere in their code? I still don't get why:

Well, consider that you haven't actually made any kind of a case for 
using variables!

If the names of these things are dynamic then why would you want to put 
them in an object's namespace, when you could just as easily include

self.insDict = {}
in your __init__() method and then simply update self.insDict whenever 
you want.

If you set hundreds variables, and their names aren't predictable, 
then presumably you will have to go through similar contortions to 
access them.

So it is generally simpler just to use a dictionary to hold the values 
whose names aren't known in advance. Techniques for inserting names into 
namespaces are known (as you have discovered), but when a beginner wants 
 to know about them it's usually considered a sign of fighting the 
language.

So, think about this a while and then tell us exactly *why* it's so 
important that these values are stored in variables.


include somefile.py would be that non-pythonic so that it's not 
available, but
I have already two choices how to proceed anyway. Thanks. ;)

Now have to figure out how to assign them easily into the XML tree.
martin
You do know there are lots of Python libraries that support XML, right?
regards
 Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: looking for way to include many times some .py code fromanotherpython code

2005-03-08 Thread Scott David Daniels
Martin MOKREJ wrote:
  If I put them into a module, it get's executed only once unless I 
 do reload. And I'd have to use: from some import *,
because mainly I'm interrested in assigning to self:
self.x = blah
self.y = uhm
OK, somewhere in here I think I get what you want to do.  Essentially
you want to set a lot of attributes on some object which is almost
always named self, and the set a lot of attributes varies as
separate chunks.  The perfect application for a function (not a _pure_
function in the functional programming sense).  So, it is my opinion
that you want to define a function to call, not include code from some
other file.
How about:
Here are some whole lot of variables functions, put them in 'code.py':
def do_a_bunch(obj):
obj.a = 123
obj.b = 3.141529
obj.c = 'what on earth?'
obj.author = u'Charles Dickens'
...
def do_other_stuff(obj):
obj.a = 123456789
obj.b2 = 3.141529 ** .5
obj.c = u'Where in Jupiter?'
obj.author = u'Martin MOKREJ'
...
And here is how you use them:
from code import do_a_bunch, do_other_stuff
class SomethingOrOther(SomeSuperClass):
def __init__(self, stuff, nonsense):
SomeSuperClass.__init__(self, stuff)
self.fiddle(nonsense)
do_a_bunch(self)
def some_other_method(self):
...
do_a_bunch(self)
def mangle(self):
...
do_other_stuff(self)

I'm newbie, sure.
That is why I was trying to figure out your original requirement,
not how to accomplish your original plan.  I was trying to see if
there was a good reason you needed to use #include - like behavior.
Does something like this address your problem?
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: shuffle the lines of a large file

2005-03-08 Thread Simon Brunning
On Tue, 8 Mar 2005 14:13:01 +, Simon Brunning
[EMAIL PROTECTED] wrote:
 On 7 Mar 2005 06:38:49 -0800, gry@ll.mit.edu gry@ll.mit.edu wrote:
  As far as I can tell, what you ultimately want is to be able to extract
  a random (representative?) subset of sentences.
 
 If this is what's wanted, then perhaps some variation on this cookbook
 recipe might do the trick:
 
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/59865

I couldn't resist. ;-)

import random

def randomLines(filename, lines=1):
selected_lines = list(None for line_no in xrange(lines))

for line_index, line in enumerate(open(filename)):
for selected_line_index in xrange(lines):
if random.uniform(0, line_index)  1:
selected_lines[selected_line_index] = line

return selected_lines

This has the advantage that every line had the same chance of being
picked regardless of its length. There is the chance that it'll pick
the same line more than once, though.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Small but significant memory leak in Pyana XSLT processor

2005-03-08 Thread Ola Natvig
Hi all
I'm working with a long running, threaded server which serves HTTP 
requests with content which are passed through a XSLT processor. The 
XSLT processor I'm using is the Pyana processor.

I have one compiled stylesheet which I uses to process all responses. 
This way I only need to read and compile the stylesheet once.

When serving a rather small page 404-page I get the server to process 
300-400 requests per second over a LAN connection. This is from the 
apache benchmark program, I don't know how reliable these numbers are 
but they give me some guidance.

My problem:
When serving my content without the XSLT processor the process size 
remains the same size. (about 18MB in the windows task manager). But 
when I use the XSLT processor the process will slowly gain size. About 
1MB for each 10k requests, and this memory are not freed.

I feel certain that the leak are located in the XSLT processor since the 
problem occurs when that is plugged into the system.

There is not much wrapping code so I don't think the problem are of that 
manner.

So I wonder if anyone have had the same experience with this XSLT 
toolkit before and if you were able to fix it.

The software I'm using on the computer I've done the tests on:
Python 2.4 (ActivePython)
Pyana 0.9.2
Win XP Pro SP2
I've tried with both precompiled and self compiled versions of the Pyana 
package.

ola
--
--
 Ola Natvig [EMAIL PROTECTED]
 infoSense AS / development
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting dictionary by 'sub' value

2005-03-08 Thread Scott David Daniels
Diez B. Roggisch wrote:
I have a dictionary of images. I wish to sort the dictionary 'v' by a
dictionary value using python 2.3. The dictionary value is the date
attribute as shown here:
   v[imagename][9]['date']
...
You can't sort dicts - they don't impose an order on either key or value.
There are ordered dict implementations out there, but AFAIK the only keep
the keys sorted, or maybe the (key,values) in the insertion order.
But maybe this helps you:
l = v.items()
l.sort(lambda a, b: cmp(a[9]['date'], b[9]['date'])
In 2.4, this is simple:
ordered_keys = sorted(v, key=lambda name: v[name][9]['date'])
In 2.3, or earlier, use decorate-sort-undecorate:
decorated = [(value[9]['date'], key)
 for key, value in v.iteritems()]
decorated.sort()
result = [key for key, date in decorated]
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Recognizing the Arrival of a New File

2005-03-08 Thread Greg Lindstrom
Hello-
I am writing an application where I need to recognize when a file 
arrives in a given directory.  Files may arrive at any time during the 
course of the day.  Do I set up a cron job to poll the directory every 
few minutes?  Write a daemon to monitor the directory?  Or is there some 
other more common/accepted way to perform this task?  I'm using Python 
2.3 on Linux.

Thanks for your help,
--greg
--
Greg Lindstrom   501 975.4859
Computer Programmer  [EMAIL PROTECTED]
NovaSys Health
Little Rock, Arkansas
We are the music makers, and we are the dreamers of dreams.  W.W.
--
http://mail.python.org/mailman/listinfo/python-list


Re: shuffle the lines of a large file

2005-03-08 Thread Heiko Wundram
On Tuesday 08 March 2005 15:28, Simon Brunning wrote:
 This has the advantage that every line had the same chance of being
 picked regardless of its length. There is the chance that it'll pick
 the same line more than once, though.

Problem being: if the file the OP is talking about really is 80GB in size, and 
you consider a sentence to have 80 bytes on average (it's likely to have less 
than that), that makes 10^9 sentences in the file. Now, multiply that with 
the memory overhead of storing a list of 10^9 None(s), and reconsider, 
whether that algorithm really works for the posted conditions. I don't think 
that any machine I have access to even has near enough memory just to store 
this list... ;)

-- 
--- Heiko.


pgpp8eZ4iUwn7.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Small but significant memory leak in Pyana XSLT processor

2005-03-08 Thread Brian Quinlan
Ola Natvig wrote:
My problem:
When serving my content without the XSLT processor the process size 
remains the same size. (about 18MB in the windows task manager). But 
when I use the XSLT processor the process will slowly gain size. About 
1MB for each 10k requests, and this memory are not freed.

I feel certain that the leak are located in the XSLT processor since the 
problem occurs when that is plugged into the system.

There is not much wrapping code so I don't think the problem are of that 
manner.

So I wonder if anyone have had the same experience with this XSLT 
toolkit before and if you were able to fix it.
I'm the author of the Pyana package and, to the best of my knowledge, 
Pyana does not have any memory leaks. It seems like there are three 
possibilities: your code is leaking somehow (seems unlikely based on 
the above), Pyana is leaking (very possible) or Xalan is leaking (very 
possible).

If Pyana is leaking then it is likely that the problem can be fairly 
easily isolated and fixed (by me). Would it be possible for you to 
isolate the leaking code and send it to me? If that is not possible, 
then let me know and I can recommend steps to help find the problem 
youself.

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


Re: shuffle the lines of a large file

2005-03-08 Thread Simon Brunning
On Tue, 8 Mar 2005 15:49:35 +0100, Heiko Wundram [EMAIL PROTECTED] wrote:
 Problem being: if the file the OP is talking about really is 80GB in size, and
 you consider a sentence to have 80 bytes on average (it's likely to have less
 than that), that makes 10^9 sentences in the file. Now, multiply that with
 the memory overhead of storing a list of 10^9 None(s), and reconsider,
 whether that algorithm really works for the posted conditions. I don't think
 that any machine I have access to even has near enough memory just to store
 this list... ;)

Ah, but that's the clever bit; it *doesn't* store the whole list -
only the selected lines.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: quick question

2005-03-08 Thread Simon Brunning
On Mon, 7 Mar 2005 18:58:20 -0500, Leeds, Mark [EMAIL PROTECTED] wrote:
 
 I have a string variable say 8023  and 
 
 I want to get rid of the beginning 
 
 And ending quotes. 

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
 my_string = '8023 '
 my_string
'8023 '
 my_string.strip('')
'8023 '

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Found that out :-(

You can use the local=locals() option so at least you have access to the 
local variables, which in the case of debugging, is exactly what I needed.

Since -i gives you control at the end of the program the locals are already 
gone.

Seems like both approaches have their advantages depending on the situation.

Steve Holden [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Unfortunately it does so in an entirely new namespace, thereby losing the 
 advantage of -i - namely, that you can investigate the program's namespace 
 after it's terminated.


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


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Right, but only one namespace.  Would be nice if there was a way to give it 
both the global and the local namespaces.  In my case though the local 
namespace was sufficient.

Just [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 code.interact() has a namespace argument ('local'), so it really easy to
 have it use the namespace you want.

 Just 


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


RE: Recognizing the Arrival of a New File

2005-03-08 Thread Batista, Facundo
Title: RE: Recognizing the Arrival of a New File





[Greg Lindstrom]


#- I am writing an application where I need to recognize when a file 
#- arrives in a given directory. Files may arrive at any time 
#- during the 
#- course of the day. Do I set up a cron job to poll the 
#- directory every 
#- few minutes? Write a daemon to monitor the directory? Or 
#- is there some 
#- other more common/accepted way to perform this task? I'm 
#- using Python 
#- 2.3 on Linux.


You can check the date info of the directory:


[EMAIL PROTECTED] ~ ll -d gsm
drwxr-xr-x 3 fbatista root 4096 feb 25 2004 gsm


[EMAIL PROTECTED] ~ cd gsm
[EMAIL PROTECTED] ~/gsm touch w
[EMAIL PROTECTED] ~/gsm cd ..


[EMAIL PROTECTED] ~ ll -d gsm
drwxr-xr-x 3 fbatista root 4096 mar 8 12:15 gsm


Regards,


. Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



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

Re: autoexecution in Windows

2005-03-08 Thread Peter Hansen
Bill wrote:
I can double click on a .py file and it executes, or use the command
prompt.
I believe if you install the Activestate distribution it sets up the
file registrations automatically.
As does the standard Windows distribution from python.org.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Recognizing the Arrival of a New File

2005-03-08 Thread TZOTZIOY
On Tue, 08 Mar 2005 08:43:04 -0600, rumours say that Greg Lindstrom
[EMAIL PROTECTED] might have written:

I am writing an application where I need to recognize when a file 
arrives in a given directory.  Files may arrive at any time during the 
course of the day.  Do I set up a cron job to poll the directory every 
few minutes?  Write a daemon to monitor the directory?  Or is there some 
other more common/accepted way to perform this task?  I'm using Python 
2.3 on Linux.

The most common way to watch for a file or a directory change (in my experience)
is to use the SGI fam (file alteration monitor); I think it has been ported to
Linux.  Otherwise, either way you describe is common use.  Suggestion: first
check for changes in the st_mtime of the directory, then search for the file
existence.
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Dr. Dobb's Python-URL! - weekly Python news and links (Mar 7)

2005-03-08 Thread Cameron Laird
QOTW:  Really, of course, the only things you need to make explicit are the
ones that readers don't understand. -- Steve Holden

Working with unicode objects in Python is so transparent, it's easy to
forget about what a C extension would likely want. -- Kevin Dangoor

You take leadership in a small area, and you keep it as long as you
care to. -- Max M, on the slender rewards of open-source authorship


Even with everything else going on at PyCon2005--dynamite
speakers, thrilling Sprints, and so on--the most newsworthy
event of the week likely will be revelations about IronPython's
schedule.  When will it be possible to create .NET services
in Python?  Keep in mind that PythonNet already lets Python
applications be .NET clients:
http://www.zope.org/Members/Brian/PythonNet/index_html
http://python.org/pycon/2005/keynotes.html

Brett C. begins his farewell tour from python-dev summation:

http://groups-beta.google.com/group/comp.lang.python/msg/99e13efba90ca590

Python has a Security Response Team, python-dev has new
summarizers, CPython might soon have a new throwaway
list optimization, and those only hint at the range of
progress python-dev has made in the last fortnight:
http://www.python.org/dev/summary/2005-02-01_2005-02-14.html

Skip Montanaro and Diez Roggisch write with precision on
use of urllib, and particularly its user-agent refinement:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/535ada773d6f6227/

Python is a good extension language, in the sense that an
application or parts of it can be made scriptable under the
control of an end-user.  It's easy to do so--but be careful
to promote safe plugging:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/620954f7d9767af6/

Jeff Epler exhibits a definition which automates remote
control of Tkinter processes:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/2ac9a3f8309d183a/

ChaosKCW offers timings and brief commentary on alternative
wrappings of SQL access with iterables and generators:

http://groups-beta.google.com/group/comp.lang.python/msg/7ff516d7d9387dad

Python is flexible.  You can create applications, you can work
interactively, you can interactively manage applications, you
can create applications that offer interaction under
programmatic control, you can ...:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/76826e3be040d63d/

One of the fundamentals of Python's origin was that the
language play well with others (an innovation, in that
context).  Among the many instances of teamwork between
Python and other languages that turn up daily is Python's
success in development of assemblers:

http://groups-beta.google.com/group/comp.lang.python.announce/browse_thread/thread/ce3329a8e408c202/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce

Brett Cannon continues the marvelous tradition established by 
Andrew Kuchling and Michael Hudson of intelligently summarizing
action on the python-dev mailing list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

The Python Business Forum further[s] the interests of companies
  

Re: select random entry from dictionary

2005-03-08 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
From the Python 2.4 quickreference:
d.popitem()  Removes and returns an arbitrary (key, value) pair from
d
If this isn't random enough, then you can generate a random number in
range(len(d))
Although this idea may suit the OP, arbitrary is
most definitely not random.  Given the same
dictionary on two separate occasions, this approach
results in precisely the same sequence of items
being returned.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: parameter name conflict. How to solve?

2005-03-08 Thread Bo Peng
Delaney, Timothy C (Timothy) wrote:
Is this a style guide thing?
Why not just:
def func(output_param=''):
output(output=output_param)
This is exactly the problem. There are a bunch of other functions that 
use output='' parameter. Changing parameter name for this single 
function may cause confusion.

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


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Martin MOKREJ
Hi to everyone who has repsonded. I'll try to clarify my problem in more detail.
I believe I have the answers how to assign to self. in superclasses. In case
you would know of yet another way, let me know. ;)
Steve Holden wrote:
Martin MOKREJ wrote:
Diez B. Roggisch wrote:
See my post on Mar 2 about automating assignment of class variables.
I got no answers, maybe I wasn't clear enough ... :(

class Foo:
def __init__(self, a, b, .):
 self.a = a
 self.b = b
 
If that is what you want, then this might help you: Put all the 
values in a
The data passed to an instance come from sql tables. I have the idea
every table will be represented by an object. At the most upper level
of abstraction, I work with, partly overlapping set of tables.
imagine two objects, X and Y. X refers to table T1, T2, T3 while
Y refers to T1, T3, T4, T5.
let's say:
T1 has columns T1C1, T1C2, T1C3
T2 has columns T2C1, T2C2, T2C3, ...
and so on
object t1 is something like:
class t1:
   def __init__(self, T1C1, T1C2, T1C3=None):
   self.T1C1 = T1C1
   self.T1C2 = T1C2
   self.T1C3 = T1C3
similarly in case of t2 or any other table. The column names/types are 
different,
also requirements for non-NULL values differ (T1C3 above is allowed to be 
empty).
T1C2 is ENUM type, for example which must be equal ether to a or b or d 
... etc.
object X is something like:
class x:
   def __init__(self, t1object, t2object, t3object):
   self.t1object = t1object
   self.t2object = t2object
   self.t3object = t3object
   self.xml_root = cElementTree.Element(xml root)
   # and now the boring stuff comes
   self.xml_t1 = cElementTree.SubElement(self.xml_root, table 1)
   self.xml_t1_T1C1 = cElementTree.SubElement(self.xml_T1C1, name of T1C1 
comlumn)
   self.xml_t1_T1C1.text = self.t1object.T1C1
   self.xml_t1_T1C2 = cElementTree.SubElement(self.xml_T1C2, name of T1C2 
comlumn)
   self.xml_t1_T1C2.text = self.t1object.T1C2
   # ... and more or less the same for tables t2 and t3
   def set_more_data_from_optional_tables(self, t6object, t7object):
   # I'd do (self, anyobject) on the line above, but the objects represent 
different
   #   sql tables, so different variable names apply. I believe the best I 
could do
   #   is to walk their __dict__ so I could assign the data under 
self.xml_root ...
   #   can any of teh XML: libraries represent an object in XML?
   self.xml_t6_T6C1 = cElementTree.SubElement(self.xml_T6C1, name of T6C1 
comlumn)
   self.xml_t6_T6C1.text = self.t6object.T1C1
   self.xml_t6_T6C2 = cElementTree.SubElement(self.xml_T6C2, name of T6C2 
comlumn)
   self.xml_t6_T6C2.text = self.t6object.T1C2
   # ... and more or less the same for tables t7
class y:
   def __init__(self, t1object, t3object, t4object, t5object=None):
   self.t1object = t1object
   self.t3object = t3object
   self.t4object = t4object
   if t5object:
   self.t5object = t5object
   self.xml_root = cElementTree.Element(xml root)
   # now the code from x.__init__() to table t1 and t3 would be cutpasted,
   #or now I can say any of the two or three approaches suggested in 
this
   #thread will be used

Good guess! ;)
dictionary - like this:
my_vals = {a: 1, b : 2, }
There are plenty of other ways to create such a dictionary, but I won't
digress on that here.
Now in your class, you pass than dict to your constructor and then 
simply
update the instance's __dict__ so that the keys-value-pairs in my_vals
become attributes:

class Foo:
def __init__(self, my_vals):
 self.__dict__.update(my_vals)
foo = Foo(my_vals)
print foo.a
- 1
Hope this helps,

Sure. Thanks! Would you prefer exactly for this method over the method 
posted by Kent Johnson
few minutes ago?

Am I so deperately fighting the language? No-one here on the list 
needs to set hundreds
variables at once somewhere in their code? I still don't get why:

Well, consider that you haven't actually made any kind of a case for 
using variables!
OK, imagine I want to read the data from sql into memory and check the
values (there're some conditions they have to fullfill). Therefore, once
I get the classes defined, I'll implement methods to check every table
t1 to tx for it's contents. ^H^H^H^H^H^H^H^H^H^H^H^H Actually, the checks
have to be based on X or Y instance. The check differs between X.t1
and Y.t1. :(
If you ask me why do I have such a mess, my answer is that I don't want
to store same datatype into two different tables. So the location is only
one, but the value has to be filled in only when X and is unused when Y.
Similarly it happens when some foreign keys are/aren't defined.

If the names of these things are dynamic then why would you want to put 
them in an object's namespace, when you could just as easily include

self.insDict = {}
in your __init__() method and then simply update self.insDict whenever 
you want.

If you set 

Re: parameter name conflict. How to solve?

2005-03-08 Thread Bo Peng
Kent Johnson wrote:
Bo Peng wrote:
def func(output=''):
  output(output=output)
Naturally, I get 'str' object is not callable. Is there a way to tell 
func that the first output is actually a function? (like in C++, 
::output(output) )

You could use a default argument:
def func(output='', output_fn=output):
  output_fn(output=output)
Kent
Thank everyone for the quick responses. All methods work in general. 
Since func() has to take the same parameter set as some other functins, 
I can not use  func(output='', output_fn=output). output_alias=output 
etc are fine.

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


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Steven Bethard
Martin MOKREJ wrote:
The data passed to an instance come from sql tables. I have the idea
every table will be represented by an object.
Have you looked at SQLObject?  I've never used it, but it does seem like 
this is the sort of thing it was designed for:

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


Re: parameter name conflict. How to solve?

2005-03-08 Thread Duncan Booth
Bo Peng wrote:

 Thank everyone for the quick responses. All methods work in general. 
 Since func() has to take the same parameter set as some other functins, 
 I can not use  func(output='', output_fn=output). output_alias=output 
 etc are fine.

One suggestion that I haven't seen so far:

Where does this mysteriously named function 'output' come from? If it is 
defined in another module, then simply call it qualified by the module 
name.

i.e. if the code looks like:

   from othermodule import output

   def func(output=''):
  output(output=output)

change it to:

   import othermodule

   def func(output=''):
  othermodule.output(output=output)

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


Re: Accessing files installed with distutils

2005-03-08 Thread Thomas Heller
Steve Holden [EMAIL PROTECTED] writes:

 [EMAIL PROTECTED] wrote:
 I was wondering how to do this too. I'm trying to write a distutils
 setup.py script that has some data I'd like to include.  From the
 distutils docs I get
 data_files specifies a sequence of (directory, files) pairs in the
 following way:
 setup(...
   data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
   ('config', ['cfg/data.cfg']),
   ('/etc/init.d', ['init-script'])]
  )
 I can use sys.prefix to find the top level where python is installed,
 but this doesn't tell me specifically where site-packages is. On my
 Linux box it is in
 {sys.prefix}/lib/python2.3/site-packages
 but on Windows, it's in
 {sys.prefix}/Lib/site-packages.
 Do I need to use sys.platform (along with sys.version) to check what
 type of machine I'm on, or is there some better  method to get the
 location of site-packages?

 This is one of the areas where distutils could probably do with some
 improvement. I don;t know whether it's on any developers priority
 list, though.

There are some functions in distutils.sysconfig which may help.

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


Re: Unicode BOM marks

2005-03-08 Thread John Roth
Martin v. Lwis [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
Francis Girard wrote:
Well, no text files can't be concatenated ! Sooner or later, someone will 
use cat on the text files your application did generate. That will be a 
lot of fun for the new unicode aware super-cat.
Well, no. For example, Python source code is not typically concatenated,
nor is source code in any other language. The same holds for XML files:
concatenating two XML documents (using cat) gives an ill-formed document
- whether the files start with an UTF-8 signature or not.
And if you're talking HTML and XML, the situation is even worse, since
the application absolutely needs to be aware of the signature. HTML might
have a meta ...  directive close to the front to tell you what the 
encoding
is supposed to be, and then again, it might not. You should be able to 
depend
on the first character being a , but you might not be able to. FitNesse, 
for
example, sends FIT a file that consists of the HTML between the body
and /body tags, and nothing else. This situation makes character set
detection in PyFit, um, interesting. (Fortunately, I have other ways of
dealing with FitNesse, but it's still an issue for batch  use.)

As for the super-cat: there is actually no problem with putting U+FFFE
in the middle of some document - applications are supposed to filter it
out. The precise processing instructions in the Unicode standard vary
from Unicode version to Unicode version, but essentially, you are
supposed to ignore the BOM if you see it.
It would be useful for super-cat to filter all but the first one, however.
John Roth

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


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Peter Hansen
Martin MOKREJ wrote:
Am I so deperately fighting the language? No-one here on the list needs 
to set hundreds variables at once somewhere in their code? 
Nobody needs to do that.  As others have pointed out, creating variables
implies wanting to access them distinctly, not as a whole group.  If
you are just going to access them as a group, use contain objects such
as lists or dicts or a custom class, not individual variables.
Now have to figure out how to assign them easily into the XML tree.
This might be the hint that others were hoping for, about your
real requirements.  Do you mean to say that the whole reason
you have for assigning hundreds of variables is to go and
shove the values right back into another data structure such
as an XML document?  If so, trust us, you very likely don't
want to do it by assigning and then referencing hundreds of
variables.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Martin MOKREJ
Peter Hansen wrote:
Martin MOKREJ wrote:
Am I so deperately fighting the language? No-one here on the list 
needs to set hundreds variables at once somewhere in their code? 

Nobody needs to do that.  As others have pointed out, creating variables
implies wanting to access them distinctly, not as a whole group.  If
you are just going to access them as a group, use contain objects such
as lists or dicts or a custom class, not individual variables.
I understand, but this is unfortunately not my case now. It's really
about assigning data from mysql to some variables and getting them later
checked. The checks will be different for most variables and will even
differ if I read from sql or alternatively I instantiate first new data
obtained from web interface and write subsequently into sql (for example,
all row ID's won't be known while instantiating the objects).
Now have to figure out how to assign them easily into the XML tree.

This might be the hint that others were hoping for, about your
real requirements.  Do you mean to say that the whole reason
you have for assigning hundreds of variables is to go and
shove the values right back into another data structure such
as an XML document?  If so, trust us, you very likely don't
No, the xml is another reason why I wanted to walk over the __dict__
of some object and let something magically constrcut the XML tree for me.
But this is really another, distinct problem from teh one I posted originally.
want to do it by assigning and then referencing hundreds of
variables.
I need to test almost every for it's content. Some tests
are just that the value is non-empty (few cases), but in most cases
a lot more checks (only certain values allowed, or only int type allowed,
or only \w is allowed ...).
FYI: The program/database runs at the moment under php + mysql.
--
http://mail.python.org/mailman/listinfo/python-list


Re: capturing text from a GUI window

2005-03-08 Thread Peter Hansen
Earl Eiland wrote:
Anyone know how to capture text from GUI output?  I need to process
information returned via a GUI window.
It might help (at least in terms of justifying this as an
on-topic post) to describe in what way this is a Python
question.  Is it a Python program that produces the output?
Do you want to write this capture program using Python?
Also, as always, providing some detail about the platform
in question is important if you don't want to see answers
of the form we're not mindreaders.  Operating system,
GUI framework, versions of things.
Finally, note that the process is, when possible at all,
generally highly platform-specific, awkward, and usually
relies on third-party packages (at least in Windows) that
may or may not have any Python-specific interfaces
available.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: quick question

2005-03-08 Thread Peter Hansen
Simon Brunning wrote:
On Mon, 7 Mar 2005 18:58:20 -0500, Leeds, Mark [EMAIL PROTECTED] wrote:
I want to get rid of the beginning 
And ending quotes. 

my_string = '8023 '
my_string.strip('')
'8023 '
Note the risk in this approach, as it blindly
removes any number of leading and trailing quotation marks,
not just the first and last ones.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Speeding up CGIHTTPServer (Tim Roberts)

2005-03-08 Thread elbertlev
Starting a process on WIN98 is VERY slow. (On NT much faster the second
time). If you really want to use WIN98, modify CGIHTTPServer.py in such
a way, that branch

#Other O.S. -- execute script in this process

is executed.

This way CGIHTTPServer is as fast as it gets. At least not slower then
ISAPI in JScript or VBScript and faster then Apache cgi.

If you need the modified module, I can send you one for 2.3.

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


cgi.py bug

2005-03-08 Thread Joe
While debugging a problem I was having I found a bug in the cgi.py module.

When the environment does not have a correctly set REQUEST_METHOD cgi.py 
prompts
for key=value pairs by reading from sys.stdin.  After the values are read 
from
sys.stdin they are never stored in the FieldStorage.list attribute like they 
are
when the FieldStorage.read_urlencoded or FieldStorage.read_multi methods are 
called.

This causes a problem when FieldStorage.keys() is called because although 
the values
were read from sys.stdin they were never stored in FieldStorage.list.

Although you could argue that REQUEST_METHOD should have been set correctly 
in the
first place, it still seems like if cgi.py is going to handle that situation 
by
actually reading the values from sys.stdin it should store them too.

It appears that this can fixed by modifying the read_single method of 
FieldStorage to store
the lines read from sys.stdin just like the other two methods do.

Here is the fix that I proposed that seems to address the problem.

def read_single(self):
Internal: read an atomic part.
if self.length = 0:
self.read_binary()
self.skip_lines()
else:
self.read_lines()
self.file.seek(0)

# Joe's fix
lines = ''.join([line.rstrip('\n') for line in 
self.file.readlines()])
self.file.seek(0)

self.list = list = []

for key, value in parse_qsl(lines, self.keep_blank_values,
self.strict_parsing):
list.append(MiniFieldStorage(key, value))
# End of Joe's fix

I have tested the fix using a few different combinations and also with an 
immediate EOF and it seems to work in
all cases that I have test.

The bug has been reported on Sourceforge and I submitted the above patch.


















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


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Isn't this a bug?

Here's the test program:

import code

def test_func():
lv = 1
print '\n\nBEFORE lv: %s\n' % (lv)
code.interact(local=locals())
print '\n\nAFTER  lv: %s\n' % (lv)
return

test_func()

gv = 1
print '\n\nBEFORE gv: %s\n' % (gv)
code.interact(local=locals())
print '\n\nAFTER  gv: %s\n' % (gv)

Here's the output and interactive session:



BEFORE lv: 1

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
(InteractiveConsole)
 lv = 2
 print lv
2
 ^Z



AFTER  lv: 1



BEFORE gv: 1

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
(InteractiveConsole)
 gv = 2
 print gv
2
 ^Z



AFTER  gv: 2

In the case of code.interact being called inside the function, the locals 
were available to the interactive environment but changes did not stick when 
you returned back the function. (started as lv=1 changed to lv=2 in 
interactive session, back to lv=1 in function)  Since you are still in the 
function and since code.interact used the same local environment why didn't 
the change stick until testfunc ended?

When code.interact was called from the outside the function (globals() == 
locals()) the changes stuck. (started as gv=1, changed to gv=2 in 
interactive session, stuck as gv=2 back in main).





Steve Holden [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Michael Hoffman wrote:
 Joe wrote:

 I want the script to decide whether to fall back to the interactive 
 prompt. You solution makes it ALWAYS fall back to the interactive 
 prompt.


 Actually, using sys.exit() means the program can exit even if python -i
 is used.

 You can use:

 import code
 code.interact()

 which emulates the interactive prompt.

 Unfortunately it does so in an entirely new namespace, thereby losing the 
 advantage of -i - namely, that you can investigate the program's namespace 
 after it's terminated.

 regards
  Steve
 


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


Python 2.4 OSX Package

2005-03-08 Thread Daniel Alexandre
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi there,
I've just finished creating a package for Python 2.4 for users who 
don't want to install it from sources under Mac OS X Panther. The same 
has been tested and it's working perfectly for me. The package is 
available in the .pkg format and it's compressed using Stuffit Expander 
(.sitx); both the Installer and Stuffit already come with OSX so no 
addicional applications are needed to install it.

Download location: http://student.dei.uc.pt/~dfcruz/osxpkgs/
- -- 
Best Regards,
Daniel Alexandre ( [EMAIL PROTECTED] )
PGP Public Key: http://student.dei.uc.pt/~dfcruz/pubring.html
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCLdUlL3+DjgQV3LgRAlxjAJ4qdA97J2pf4qUkFe1LAS1dOywNMgCbBi9p
VIR3Mv3UKnWemXhait2GFXA=
=WxzN
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: python -i (interactive environment)

2005-03-08 Thread Steven Bethard
Joe wrote:
Isn't this a bug?
Here's the test program:
import code
def test_func():
lv = 1
print '\n\nBEFORE lv: %s\n' % (lv)
code.interact(local=locals())
print '\n\nAFTER  lv: %s\n' % (lv)
return
Check the documentation for locals() [1]:
Update and return a dictionary representing the current local symbol 
table. Warning: The contents of this dictionary should not be modified; 
changes may not affect the values of local variables used by the 
interpreter.

So if you change things in the dictionary returned by locals() you won't 
actually change the local variables.

STeVe
[1] http://docs.python.org/lib/built-in-funcs.html#l2h-45
--
http://mail.python.org/mailman/listinfo/python-list


Format strings that contain '%'

2005-03-08 Thread [EMAIL PROTECTED]
I'm trying to do something along the lines of

 print '%temp %d' % 1
Traceback (most recent call last):
  File stdin, line 1, in ?
ValueError: unsupported format character 't' (0x74) at index 1

although, obviously I can't do this, since python thinks that the '%t'
is a format string.

I've tried obvious permutations like

 print '\%temp %d' % 1

which also doesn't work.

For (template) reasons, I can't do

 print '%s %d' % ('%temp',1)

Will anything else work here?

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


Re: Format strings that contain '%'

2005-03-08 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:
I'm trying to do something along the lines of
print '%temp %d' % 1
Traceback (most recent call last):
  File stdin, line 1, in ?
ValueError: unsupported format character 't' (0x74) at index 1
Use %%:
 '%%temp %d' % 1
'%temp 1'
--
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
  A wise man never loses anything if he have himself.
  -- Montaigne
--
http://mail.python.org/mailman/listinfo/python-list


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Steve,

Thanks, I knew about that but my question is why is it not working 
consistently?

Joe


Steven Bethard [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Joe wrote:
 Isn't this a bug?

 Here's the test program:

 import code

 def test_func():
 lv = 1
 print '\n\nBEFORE lv: %s\n' % (lv)
 code.interact(local=locals())
 print '\n\nAFTER  lv: %s\n' % (lv)
 return

 Check the documentation for locals() [1]:

 Update and return a dictionary representing the current local symbol 
 table. Warning: The contents of this dictionary should not be modified; 
 changes may not affect the values of local variables used by the 
 interpreter.

 So if you change things in the dictionary returned by locals() you won't 
 actually change the local variables.

 STeVe

 [1] http://docs.python.org/lib/built-in-funcs.html#l2h-45 


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


Re: Format strings that contain '%'

2005-03-08 Thread Diez B. Roggisch
 Will anything else work here?

Use %%

print %%s %s % foo
-- 
Regards,

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


distutils: binary distribution?

2005-03-08 Thread Stefan Waizmann
Hello,

I would like the distutils are creating a binary distribution only - means
create the distribution file with *.pyc files WITHOUT the *.py files. Any
ideas? Or are the distutils the wrong tool for that?
setup.py bdist creates binary dist, but includes the sourcecode

cheers

Stefan
-- 
Was heute Zeit heißt, ist ein technologisches Konzept,
das asynchron zu den Rhythmen des Lebens läuft.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Format strings that contain '%'

2005-03-08 Thread [EMAIL PROTECTED]
Thanks!!

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


Re: Sorting dictionary by 'sub' value

2005-03-08 Thread Rory Campbell-Lange
Thank you all very much for your help.

I did the following and it works:

imgs=v.keys()
imgs.sort(lambda a,b: cmp(
  time.strptime(str(v[a][9]['date']), '%Y:%m:%d %H:%M:%S'),
  time.strptime(str(v[b][9]['date']), '%Y:%m:%d %H:%M:%S'))
 )
for i in imgs:
...

Regards,
Rory

On 08/03/05, Diez B. Roggisch ([EMAIL PROTECTED]) wrote:
 l = v.items()
 l.sort(lambda a, b: cmp(a[9]['date'], b[9]['date'])

On 08/03/05, Scott David Daniels ([EMAIL PROTECTED]) wrote:
 You can't sort dicts - they don't impose an order on either key or value.
 There are ordered dict implementations out there, but AFAIK the only keep
 the keys sorted, or maybe the (key,values) in the insertion order.
 
 But maybe this helps you:
 
 l = v.items()
 l.sort(lambda a, b: cmp(a[9]['date'], b[9]['date'])
 
 In 2.4, this is simple:
 
 ordered_keys = sorted(v, key=lambda name: v[name][9]['date'])
 
 In 2.3, or earlier, use decorate-sort-undecorate:
 
 decorated = [(value[9]['date'], key)
  for key, value in v.iteritems()]
 decorated.sort()
 result = [key for key, date in decorated]

On 08/03/05, Batista, Facundo ([EMAIL PROTECTED]) wrote:

  temp_list = [ (x[1][1], x[0]) for x in d.items() ]
...
  temp_list.sort()
  for (tmp, key) in temp_list:


-- 
Rory Campbell-Lange 
[EMAIL PROTECTED]
www.campbell-lange.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python -i (interactive environment)

2005-03-08 Thread Steven Bethard
Joe wrote:
Thanks, I knew about that but my question is why is it not working 
consistently?
At the module level, locals() is globals():
py locals() is globals()
True
And the globals() dict is modifiable.
HTH,
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: python -i (interactive environment)

2005-03-08 Thread Joe
Thanks I thought that was also true for globals() but I now see that it is 
not.

Steven Bethard [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Joe wrote:
 Thanks, I knew about that but my question is why is it not working 
 consistently?

 At the module level, locals() is globals():

 py locals() is globals()
 True

 And the globals() dict is modifiable.

 HTH,

 STeVe 


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


Re: How to script DOS app that doesn't use stdout

2005-03-08 Thread Timothy Grant
On Sun, 06 Mar 2005 13:41:57 GMT, Gregor [EMAIL PROTECTED] wrote:
 There's a DOS console application I am trying to script (in Python), but it
 doesn't seem to use stdout or stderr... For example, if I redirect output
 to a file (cmd  file.txt), the output still appears on screen.
 Similarly, the output pipes returned by popen* don't catch the app's
 output. How might this app be generating its output? Any thoughts on how it
 could be captured (perhaps with something in the win32 extensions)?
 
 Thanks,
 
 Greg.

I've had to do this a couple of times but never in recent years. I
don't know your exact needs, but the best tool I ever found for this
sort of job was called Phantom of the Keyboard.

I ran into a couple of apps that I needed data out of and couldn't get
it. They'd only output to screen, never to disk. I used Phantom to
automate the app to dump data to screen and then capture the screen to
disk.

-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mysterious Attribute Errors when GUI Programming

2005-03-08 Thread klappnase
Coral Snake [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]...

 --
 Tkinter:
 
 from Tkinter import *
 root = Tk()

This creates the application's main window. The Tk() command is not
some kind of initialization routine, but actually returns a ready to
use toplevel widget.

 win = Toplevel(root)

This creates a child window with the parent root; 

 win.pack()

here you try to put the child window into the main window; this cannot
work,
because a Tk() or Toplevel() window cannot contain other Toplevel()
instances.
Toplevel() is used for things like dialogs. If you need a separate
container
widget inside root use Frame() instead.

 Label(win, text= Hello, Python World).pack(side=TOP)
 Button(win, text= Close, command=win.quit).pack(side=RIGHT)
 win.mainloop()
 -
 
 AttributeError: Toplevel instance has no attribute 'pack'
 
 -

The correct usage of what you tried looks like this:

from Tkinter import *
root = Tk()
Label(win, text= Hello, Python World).pack(side=TOP)
Button(win, text= Close, command=win.quit).pack(side=RIGHT)
root.mainloop()

I hope this helps

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


Python Presentation

2005-03-08 Thread Colin J. Williams
Rod,
This is to confirm the telephone message I left yesterday.
The Introduction to Python is scheduled for 8.0pm this evening
at the Fulford Academy, 280 King Street East.
Colin W.
--
http://mail.python.org/mailman/listinfo/python-list


MDaemon Warning - virus found: Returned mail: see transcript for details

2005-03-08 Thread image-sig-request

*** WARNING **
Este mensaje ha sido analizado por MDaemon AntiVirus y ha encontrado 
un fichero anexo(s) infectado(s).  Por favor revise el reporte de abajo.

AttachmentVirus name   Action taken
--
text.zip  Email-Worm.Win32.Mydoom.m Removed


**


This message was undeliverable due to the following reason(s):

Your message was not delivered because the destination computer was
unreachable within the allowed queue period. The amount of time
a message is queued before it is returned depends on local configura-
tion parameters.

Most likely there is a network problem that prevented delivery, but
it is also possible that the computer is turned off, or does not
have a mail system running right now.

Your message was not delivered within 6 days:
Mail server 3.202.169.132 is not responding.

The following recipients could not receive this message:
python-list@python.org

Please reply to [EMAIL PROTECTED]
if you feel this message to be in error.

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

  1   2   >