Re: removing redundant elements in a dictionary

2007-08-01 Thread Antti Rasinen


On 2007-08-01, at 06:50, Astan Chee wrote:


Hi,
I have a dictionary which looks something like this:

elem = {"co":[1,2,3],"cp":[3,2,1],"pp":[5,6,7],"cl":[1,2,3],"qw": 
[6,7,8],"qa":[8,7,6]}


what Im trying to do is find all keys in the list that have the  
same value and delete those (except one); thereby removing all  
redundant keys so that the above dict will look like this:


elem = {"co":[1,2,3],"pp":[5,6,7],"qa":[8,7,6]}

my code so far looks like this:

for out1 in elem.keys():
for out2 in elem.keys():
if out1 != out2:
elem[out1].sort()
elem[out2].sort()
if elem[out1] == elem[out2]:
del elem[out1]

This returns in a KeyError exception when sorting. What am I  
missing here?


Consider a dict {'a': [1], 'b': [1], 'c': [1]}.

First time we reach the innerloop, out1 == 'a'. Then we iterate over  
the list ['a', 'b', 'c'].


'a' is skipped. At 'b', we remove 'a' from the dictionary. And then  
it all goes wrong.


The last time we go through the inner loop, out1 is still 'a' -- an  
element which does not exist in the dictionary anymore. Then your  
attempts to reference it fail at both the sorting and comparison  
stages. You should break out of the inner loop immediately after  
you've deleted the item or delete out2 instead..


Furthermore, the algorithm is somewhat inefficient due to the fact  
that it sorts the lists O(n^2) times when you only need to do them n  
times. If your data allows it, you might like to use sets instead of  
lists. This would avoid the need to sort the lists.


However, here is a very quick version that works in my tests:
for out_list in elem.values():
out_list.sort()

for out1 in elem.keys():
for out2 in elem.keys():
if out1 != out2 and elem[out1] == elem[out2]:
del elem[out1]
break

There are probably several ways to improve on that, however.

--
[ [EMAIL PROTECTED] <*> Antti Rasinen ]

"Pay the man his wage, he's making paper to fuel the Information Age."


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

Strange problems with subprocess

2007-08-01 Thread Michele Petrazzo
Hi all. I have a simple "ping tester" program that, every 1 minute
(execute by linux crontab), create, with subprocess, a
"ping -c 1 my_addrs". All work, but sometime (about 1/2 times at a day),
I receive this error message:

File "/exports/srv-wipex/net_test/ping_tester.py", line 88, in pyPing
   cmd_p = Popen(cmd, stdout=PIPE, stderr=PIPE)
File "subprocess.py", line 543, in __init__
   errread, errwrite)
File "subprocess.py", line 970, in _execute_child
   data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB

What can be that raise this?

Python 2.4 in deb etch

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


Re: Any way to monitor windows network connection?

2007-08-01 Thread momobear
On Aug 1, 1:47 pm, Gordon Airporte <[EMAIL PROTECTED]> wrote:
> momobear wrote:
> > hi, Is there any way to show me detailed listings of all TCP and UDP
> > endpoints in my microsoft windows XP in python way?
> > thanks.
>
> Unless you're looking for a programming 
> exercise:http://www.microsoft.com/technet/sysinternals/Utilities/TcpView.mspx

Ok, It works, but there're no source code of it. I wish to build a
tools to show all the network endpoints, cpu usage and top ten
processes in a dockapp like application.

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


Re: Any way to monitor windows network connection?

2007-08-01 Thread momobear
On Aug 1, 12:22 pm, Jay Loden <[EMAIL PROTECTED]> wrote:
> momobear wrote:
> > hi, Is there any way to show me detailed listings of all TCP and UDP
> > endpoints in my microsoft windows XP in python way?
> > thanks.
>
> Not sure if it's exactly what you're looking for, but this might be of use as 
> a starting point at 
> least:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/392572

yes, I get it, iphelp api could do that for me. thanks for help.

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


Re: Iteration over strings

2007-08-01 Thread Duncan Booth
Jay Loden <[EMAIL PROTECTED]> wrote:

> This isn't just a problem with the socket module, so please don't
> think I'm picking on it or singling it out, it's something I've seen a
> number of places. e.g. from os.stat: 
> 
> os.stat = stat(...)
> stat(path) -> stat result
> 
> Perform a stat system call on the given path.
> 
> Ok...and what is the return value? a list? tuple? string? some type of
> stat object? dictionary? The only way to find out is to read the os
> module's source code or try it to find out. If you were really lucky
> you might find the related documentation from class statvfs_result and
> put two and two together to figure it out. 

Or if you were really, really lucky you might try reading the 
documentation (http://docs.python.org/lib/os-file-dir.html):

stat( path) 

Perform a stat() system call on the given path. The return value is an 
object whose attributes correspond to the members of the stat structure, 
namely: st_mode (protection bits), st_ino (inode number), st_dev 
(device), st_nlink (number of hard links), st_uid (user ID of owner), 
st_gid (group ID of owner), st_size (size of file, in bytes), st_atime 
(time of most recent access), st_mtime (time of most recent content 
modification), st_ctime (platform dependent; time of most recent 
metadata change on Unix, or the time of creation on Windows): 

>>> import os
>>> statinfo = os.stat('somefile.txt')
>>> statinfo
(33188, 422511L, 769L, 1, 1032, 100, 926L, 1105022698,1105022732, 
1105022732)
>>> statinfo.st_size
926L
>>>

Changed in version 2.3: If stat_float_times returns true, the time 
values are floats, measuring seconds. Fractions of a second may be 
reported if the system supports that. On Mac OS, the times are always 
floats. See stat_float_times for further discussion. 

On some Unix systems (such as Linux), the following attributes may also 
be available: st_blocks (number of blocks allocated for file), 
st_blksize (filesystem blocksize), st_rdev (type of device if an inode 
device). st_flags (user defined flags for file). 

On other Unix systems (such as FreeBSD), the following attributes may be 
available (but may be only filled out if root tries to use them): st_gen 
(file generation number), st_birthtime (time of file creation). 

On Mac OS systems, the following attributes may also be available: 
st_rsize, st_creator, st_type. 

On RISCOS systems, the following attributes are also available: st_ftype 
(file type), st_attrs (attributes), st_obtype (object type). 

For backward compatibility, the return value of stat() is also 
accessible as a tuple of at least 10 integers giving the most important 
(and portable) members of the stat structure, in the order st_mode, 
st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, 
st_ctime. More items may be added at the end by some implementations. 
The standard module stat defines functions and constants that are useful 
for extracting information from a stat structure. (On Windows, some 
items are filled with dummy values.) 

Note: The exact meaning and resolution of the st_atime, st_mtime, and 
st_ctime members depends on the operating system and the file system. 
For example, on Windows systems using the FAT or FAT32 file systems, 
st_mtime has 2-second resolution, and st_atime has only 1-day 
resolution. See your operating system documentation for details. 

Availability: Macintosh, Unix, Windows. 

Changed in version 2.2: Added access to values as attributes of the 
returned object. Changed in version 2.5: Added st_gen, st_birthtime. 

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


Re: split a string of space separated substrings - elegant solution?

2007-08-01 Thread Helmut Jarausch
Many thanks to all of you!
It's amazing how many elegant solutions there are in Python.


-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iteration over strings

2007-08-01 Thread Stefan Behnel
> Robert Dailey wrote:
>> I have the following code:
>>
>> str = "C:/somepath/folder/file.txt"
>>
>> for char in str:
>> if char == "\\":
>> char = "/"
>>
>> The above doesn't modify the variable 'str' directly. I'm still pretty new
>> to Python so if someone could explain to me why this isn't working and what
>> I can do to achieve the same effect I would greatly appreciate it.

I assume what you are actually looking for is the os.path module.

http://docs.python.org/lib/module-os.path.html

Especially the normpath() function should be of interest.

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


Re: Error with Tkinter and tkMessageBox

2007-08-01 Thread Fabio Z Tessitore
Il Tue, 31 Jul 2007 18:45:57 -0400, jim-on-linux ha scritto:

> Try This:
> 
>  def reply():
>  showinfo('ciao','hello')
> 

I've tried without success ... thanks

I've also discovered that when I (or some other prog using tkinter) 
display menu, the underscore is an ugly little black box. So, tkinter 
don't work fine on my machine. What a pity!

thanks, all, bye
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free SMS from Computer Worldwide

2007-08-01 Thread Dan Anos
Hi Lowbowman,

 Interested in expanding your SMS website to other countries,
check out our affiliate scheme on FreebieSMS.co.uk.

 I cant see your email address on your website.

Fiach


On Jul 31, 4:09 am, lowboman <[EMAIL PROTECTED]> wrote:
> Hello there I invite you to check out my sitehttp://www.nocostsms.com
> you can sendfreesmstext messages from your computer to any mobile
> phone and receive replies in you email account, also check out cell
> phone forums out while your there


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


Re: Where do they tech Python officialy ?

2007-08-01 Thread Alex Popescu
[EMAIL PROTECTED] (Alex Martelli) wrote in news:1i23wyk.avc945i4dwsiN%
[EMAIL PROTECTED]:

> NicolasG <[EMAIL PROTECTED]> wrote:
>...
>> The problem is that I would like to work as a Python programmer but
>> all the job vacancies I can find requires a couple of years of
>> professional experience ... that I don't have. How a wanna be
>> programmer can start working as a programmer if there is no chance to
>> start from somewhere ? That's the reason I created this topic.
> 
> Open source projects do not require previous professional experience 
to
> accept volunteers.  So, one way out of your dilemma is to make a name
> for yourself as an open source contributor -- help out with Python
> itself and/or with any of the many open source projects that use 
Python,
> and you will both learn a lot _and_ acquire "professional experience"
> that any enlightened employer will recognize as such.  

It depends :-). In my experience I met employers being concerned by my 
implication in the oss world :-).

> That will take a
> while, but not as long as getting a college degree (and it will be far
> cheaper than the degree).
> 

I don't know much about the open community in Python world, but in Java 
world becoming a project member may be more difficult than getting a 
degree (or close to :-)) ).

bests,
./alex
--
.w( the_mindstorm )p.

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


Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread Ben Finney
beginner <[EMAIL PROTECTED]> writes:

> In perl, I can write __END__ in a file and the perl interpreter will
> ignore everything below that line.

IIRC, this Perl feature is specifically intended to work with its
feature of reading data from the same file, as all the lines following
that marker.

> This is very handy when testing my program.

If my understanding above is correct, then your use of it is a happy
repurposing of the feature, and not an intended use.

> Does python have something similar?

Since it doesn't have the behaviour that inspired that feature in
Perl, I doubt it.

-- 
 \  "Everything is futile."  -- Marvin of Borg |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Process Control Help

2007-08-01 Thread Hendrik van Rooyen

"Walt Leipold"  wrote:

8<--- summary of state of the art -

> (Wow, that was a depressing post to write.)

Cheer up! - The end is nigh! 

Warning:
The rest of this post is barely on topic for python,
and contains some shameless self advertising. Its
probably bad for your health too.

I have just spent considerable time developing some stuff.

I call it SDCL - simple distributed control language

Its a simple scripting language, that is interpreted.

The HMI bits are python, the "compiler" is python, 
the simulator is python, the interpreter in the PC is
python.  What is not python is the interpreter in the 
PLC - that is a mix of Assembler and C, for speed.

You can run the code either in the PC, or in the PLC,
or as a mix of both - obviously fast stuff needs to run
in the real hardware, but a lot of the control, checking
and sequencing functions fall naturally into the PC.  
With the PC logging, you get ISO 900x almost 
automatically, as any change to a variable that lives in 
the PC is logged.

The language is still a bit "brain dead" - it implements a
virtual Reverse Polish Notation stack machine and reads 
like assembler, with less than 40 instructions to learn.

A real compiler is planned for some unspecified future time.

The first app is an injection moulding machine, and it has
been working for some months now, with crude animation
of the machine's motions on screen, and everything from
star-delta timing to thermocouple heating inputs and control,
as well as screw position and injection pressure sensing on 
the PLC.

There are just over 3000 instructions in the sequence to 
control this machine, and the "address space" is 64k of
instructions - so it is aimed at fairly serious control.

Unfortunately at this stage the "PLC" is Microcorp proprietary.

But the whole thing is aimed at simplifying the problem of 
putting voltages on wires and reporting the results to a PC.

I intend to open the spec as soon as I am satisfied that there
are no fearsome dragons left lurking in the code or the design.

- Hendrik


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


Re: standalone process to interact with the web

2007-08-01 Thread Diez B. Roggisch
beginner wrote:

> Hi Everyone,
> 
> I am looking for a way to allow a standalone python process to easily
> interactive with a few web pages. It has to be able to easily receive
> requests from the web and post data to the web.
> 
> I am thinking about implementing a standalone soap server, but I am
> not sure which library is good.
> 
> Any suggestions?

Forget SOAP. Use XMLRPC. SOAP is bloated, not to interoperable and the last
time I checked (has been a while though) the python-implementations were
troublesome.

http://wanderingbarque.com/nonintersecting/2006/11/15/the-s-stands-for-simple

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


Re: Reload after an exception, not possible ?

2007-08-01 Thread Stef Mientki
Steve Holden wrote:
> Stef Mientki wrote:
>> hello,
>>
>> I've a graphical application (wxPython),
>> where the code in the main GUI loop is given below.
>>
>>
>> 1JAL_Loaded = False
>> 2while len(App_Running) > 0:
>> 3if JALsPy_globals.State == SS_Run:
>> 4try:
>> 5if JAL_Loaded:
>> 6reload ( JAL_simulation_file )
>> 7else:
>> 8JAL_Loaded = True
>> 9import JAL_simulation_file
>> 10   except JALsPy_globals.Reload_Exception:
>> 11   JALsPy_globals.State = SS_Halt
>>
>>
>> The first time the while loop is entered,
>> JAL_Loaded is False (line 1),
>> and when I press some button,
>> the code will enter at line 8,
>> importing a module, that has executable code with an infinite loop.
>>
>> To exit this infinite loop, an exception is generated (by a button 
>> press),
>> and program comes back in the above while-loop line (10,11,2).
>>
>> So far so good.
>>
>> Then I change the code in the imported file,
>> and when I start the engine again,
>> the flag JAL_Loaded is True, so I don't import,
>> but I reload the file.
>>
>> Now I get the next exception
>>UnboundLocalError: local variable 'JAL_simulation_file' referenced 
>> before assignment
>>
>> So obviously I can't reload but have to do an import again
>> (which makes the code much simpler ;-)
>> but I don't understand why the reload raises an exception 
>>
> You have an assignment to JAL_simulation_file elsewhere inside the same 
> function,
No these are the only 2 uses of "JAL_simulation_file" in the whole project.

  later in the code. This means that Python will assume that it
> is local to the function, but the import statement will affect the 
> module namespace rather than the function namespace.
> 
> In other words, your code is roughly equivalent to what follows, with 
> the added complexity that the illegal reference isn't triggered until 
> the second iteration of a loop.
> 
>  >>> def f():
> ...   print os
> ...   import os
> ...   os = "Something"
> ...
>  >>> f()
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 2, in f
> UnboundLocalError: local variable 'os' referenced before assignment
>  >>>
> 
> The solution? Don't assign to JAL_simulation_file, and the function will 
> use the local instead.
> 

The solution is much simpler, but I don't understand why the "import",
which really reloads the changed code in JAL_simulation_file,
works the second time :-(

2while len(App_Running) > 0:
3if JALsPy_globals.State == SS_Run:
4try:
9import JAL_simulation_file
10   except JALsPy_globals.Reload_Exception:
11   JALsPy_globals.State = SS_Halt

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


Re: simple string backspace question

2007-08-01 Thread Hendrik van Rooyen
"John Machin"  wrote:

> Point (2): Backspace??? YAGNI --- backspace hasn't been much use for
> anything (except when typing text) since the days when in order to get
> a bold letter (say X) on a character impact printer, one would
> transmit X\bX\bX ...

ooh!  Ugly!

Almost as bad as, on a golf ball printer:

"I am a little nodding man, I always nod my head..."

followed by an infinite loop of shift-in, shift-out characters.

- Hendrik

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


Re: access the name of my method inside it

2007-08-01 Thread Marc 'BlackJack' Rintsch
On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote:

> for example I have this method
> 
> def my_method():
> # do something
> 
> # how do I get the name of this method which is my_method here?

Why do you need this?  There are ways but those are not really good for
production code.

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


Re: standalone process to interact with the web

2007-08-01 Thread Bruno Desthuilliers
beginner a écrit :
> Hi Steve,
> 
> On Jul 31, 11:42 am, Steve Holden <[EMAIL PROTECTED]> wrote:
>> beginner wrote:
>>> Hi Everyone,
>>> I am looking for a way to allow a standalone python process to easily
>>> interactive with a few web pages. It has to be able to easily receive
>>> requests from the web and post data to the web.
>>> I am thinking about implementing a standalone soap server, but I am
>>> not sure which library is good.
>>> Any suggestions?
>>> Thanks a lot,
>>> Geoffrey
>> Look nor further than mechanize -
>>
(snip)

> This seems to be an HTTP client library. It is very interesting, but
> is not what I need. I am looking for something that can provide
> service to web pages. For example, when a browser requests a web page,
> the web page is going to send a few requests to my server. My server
> then is going to respond, and the web page takes the response and
> format it in human readable form.

IOW, you want to embed a web server in your application.



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


Re: Where do they tech Python officialy ?

2007-08-01 Thread Magnus Lycka
On July 23, NicolasG wrote:
 > I want to be a professional python programmer...
 > unfortunately sometimes to work as a programmer is really hard in this
 > world, every employee requires professional experience and you can't
 > really start as a beginner..

On July 24, NicolasG wrote:
> Python is what I like, I would love to be more creative with this
> language and be able to produce things that I can't right now..
> Why not try to find a work that you would like ? I don't want to work
> as a programmer to became one because I'm already a programmer, I just
> want to work as a programmer ..

I'm not sure I understand what you mean by "I'm already a programmer"
if you can't get jobs because you're a beginner. That sounds a bit
like "I'm a surgeon, except that I haven't done any surgery just yet."

I also don't understand the concept on choosing a university depending
on whether they use a particular language in their courses. I think it's
a good idea with a good academic education, but whether Python is part
of that is really a minor issue. The most important part of education
for people who are going to work as programmers is advanced mathematics!
That's what will teach you logic and systematic problem solving.

Learning Python is a very small and easy part in learning to develop
software in a professional way. There are no silver bullets. You won't
find a language or a university course that will "fix" things for you.

The world (and your job) is full of problems waiting to be solved.
Solve them with Python, use your spare time if you're ambitious and
don't get the opportunity to use working hours. Use the internet to
find ideas and libraries etc. Doing this will make work more fun, if
you are talented enough it will make you much more productive, you
should be appreciated for the improvements you achieve, and you will
build up a portfolio of software and solutions that you can show a
prospective employer.

If I'm hiring a consultant for a few weeks, prior Python experience
might be an issue, but if I employ someone, I don't care whether they
already know Python. I expect them to know a few languages well.
I assert that they are capable of applying a programming language to
solve problems swiftly and intelligently, and I'm pretty sure they
pick up Python quickly.
-- 
http://mail.python.org/mailman/listinfo/python-list


access the name of my method inside it

2007-08-01 Thread james_027
Hi,

for example I have this method

def my_method():
# do something

# how do I get the name of this method which is my_method here?

Thanks,
james

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


calling a .net application from Python 2.5

2007-08-01 Thread Acm
I am working with Python 2.5.

I would like to know how to call a .NET application (or .dll) from a
Python script.

Can anyone help please?

Thank you.

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


Floats as keys in dict

2007-08-01 Thread Brian Elmegaard
Hi

I am making a script to optimiza by dynamic programming. I do not know
the vertices and nodes before the calculation, so I have decided to
store the nodes I have in play as keys in a dict.

However, the dict keys are then floats and I have to round the values
of new possible nodes in each step. When profiling I see that the most
time consuming part of my script is rounding.

Is there a faster way than round() or is there a better way to test
than 'in' or should I store the keys in another way than a dict?

tia,
-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with subprocess.Popen()

2007-08-01 Thread The Cruisemaniac
Hi all,

I'm trying to run a windows batch file from a python script using
subprocess.popen().

The issue that I'm facing is that, if i give the batch file as
parameter to the popen function, the script runs, but if i provide a
parameter, it is not working.

Can someone help me with the command.

The actual windows command to be executed is:

test.bat -t ABC_DE_FG_HI_001 "C:\ABCDEFGHIJKLMNOP.TXT"

What is the actual parameter required for subprocess.Popen(parameter
chain) in this case??

Kindly help me out...

Regards and Thanks in advance...
Ashwin Murali.

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


Re: Extending Python by Adding Keywords & Data types

2007-08-01 Thread Bjoern Schliessmann
Maximus Decimus wrote:

> Since, I am an amateur in using python, 


| Most commonly an amateur is understood to be someone who does
| something without pay or formal training. Conversely, a
| professional is someone who has received training in a particular
| area and who also makes a living from it.

So, you're not being paid coding in Python, and/or have
no "official" training. Many readers of this list share this
situation, me too.

> could you please be more specific. 

I return the question. Your statements are most vague. Please give
an example of what you try to realise.

> For new data types, you had asked to implement the classes. I
> intend to use C for implementing these data types. So where do i
> need to implement these classes ie under which file or module in
> the python package. 

Please do yourself a favor and read. Feel free to ask again for
specific problems.

http://docs.python.org/tut/node3.html
http://docs.python.org/tut/node11.html

Regards,


Björn
-- 
BOFH excuse #135:

You put the disk in upside down.

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


Re: standalone process to interact with the web

2007-08-01 Thread Bruno Desthuilliers
beginner a écrit :
(snip)
> Yes exactly. I just don't want to reinvent the wheel as I imagine
> there are already tons of libraries and frameworks that support RPC or
> the like functions.

Why go thru the pain of RPC, SOAP or such bloated horrors ? Why not just 
use plain old HTTP with a RESTful API ? Then you just need to make your 
app wsgi compliant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread Steve Holden
Stargaming wrote:
> On Wed, 01 Aug 2007 05:44:21 +, Michele Simionato wrote:
> 
>> On Aug 1, 5:53 am, beginner <[EMAIL PROTECTED]> wrote:
>>> Hi All,
>>>
>>> This is just a very simple question about a python trick.
>>>
>>> In perl, I can write __END__ in a file and the perl interpreter will
>>> ignore everything below that line. This is very handy when testing my
>>> program. Does python have something similar?
>> I wished from something like that. What you can do at the moment, is to
>> comment or triple quote the code you don't want to run.
> 
> Or, if in a function body, you could insert a `return` statement. When in 
> top-level code, invoking `sys.exit` (or exit/quit) can do the trick. A 
> ``raise Exception`` might help, too, but could be kinda distracting 
> sometimes.
> 
> So, there is no general purpose solution as perl has it (I guess that 
> __END__ works everywhere at least), rather different solutions for 
> different cases.

I think you have missed the point. A return statement or call to 
sys.exit() doesn't remove the requirement that the rest ofthe source 
file be legal Python. In a Perl program you can put anything you like 
after __END__.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: access the name of my method inside it

2007-08-01 Thread Marc 'BlackJack' Rintsch
On Wed, 01 Aug 2007 07:01:42 -0400, Steve Holden wrote:

> Marc 'BlackJack' Rintsch wrote:
>> On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote:
>> 
>>> for example I have this method
>>>
>>> def my_method():
>>> # do something
>>>
>>> # how do I get the name of this method which is my_method here?
>> 
>> Why do you need this?  There are ways but those are not really good for
>> production code.
>> 
> Maybe he wants to write a recursive method?
> 
> Once way is to call self.__calss__.mymethod(self). Ugly, isn't it?

Ugly yes, unnecessary convoluted yes, solution no.  You typed `my_method`
in the source.  The OP wants to know how to avoid that.

>  >>> class p:
> ...   def mymethod(self, n):
> ... if n <= 1:
> ...   return 1
> ... else:
> ...   return n * self.__class__.mymethod(self, n-1)

Why not simply ``self.mymethod(n - 1)`` instead!?

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


MIMEText breaking the rules?

2007-08-01 Thread Dale Strickland-Clark
The email module's mimetext handling isn't what you might expect from
something that appears to behave like a dictionary.

$ python
Python 2.5 (r25:51908, May 25 2007, 16:14:04)
[GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from email.mime.text import MIMEText
>>> msg = MIMEText("A message")
>>> msg["To"] = "[EMAIL PROTECTED]"
>>> msg["To"] = "[EMAIL PROTECTED]"
>>> print msg.as_string()
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]

A message
>>>

Having apparently REPLACED my recipient, what I've ended up with is both of
them.

-- 
Dale Strickland-Clark
Riverhall Systems - www.riverhall.co.uk 

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


Re: access the name of my method inside it

2007-08-01 Thread Steve Holden
Marc 'BlackJack' Rintsch wrote:
> On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote:
> 
>> for example I have this method
>>
>> def my_method():
>> # do something
>>
>> # how do I get the name of this method which is my_method here?
> 
> Why do you need this?  There are ways but those are not really good for
> production code.
> 
Maybe he wants to write a recursive method?

Once way is to call self.__calss__.mymethod(self). Ugly, isn't it?

 >>> class p:
...   def mymethod(self, n):
... if n <= 1:
...   return 1
... else:
...   return n * self.__class__.mymethod(self, n-1)
...
 >>> pp = p()
 >>> pp.mymethod(10)
3628800
 >>>

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread Stargaming
On Wed, 01 Aug 2007 06:56:36 -0400, Steve Holden wrote:

> Stargaming wrote:
>> On Wed, 01 Aug 2007 05:44:21 +, Michele Simionato wrote:
>> 
>>> On Aug 1, 5:53 am, beginner <[EMAIL PROTECTED]> wrote:
 Hi All,

 This is just a very simple question about a python trick.

 In perl, I can write __END__ in a file and the perl interpreter will
 ignore everything below that line. This is very handy when testing my
 program. Does python have something similar?
>>> I wished from something like that. What you can do at the moment, is
>>> to comment or triple quote the code you don't want to run.
>> 
>> Or, if in a function body, you could insert a `return` statement. When
>> in top-level code, invoking `sys.exit` (or exit/quit) can do the trick.
>> A ``raise Exception`` might help, too, but could be kinda distracting
>> sometimes.
>> 
>> So, there is no general purpose solution as perl has it (I guess that
>> __END__ works everywhere at least), rather different solutions for
>> different cases.
> 
> I think you have missed the point. A return statement or call to
> sys.exit() doesn't remove the requirement that the rest ofthe source
> file be legal Python. In a Perl program you can put anything you like
> after __END__.
> 
> regards
>   Steve

That was my point actually. No, there is no such general purpose solution 
as in perl, but if he just wanted to quit execution (to, eg., not commit 
changes to his database), this would be the way to go. Multiline strings 
are the other way to include (nearly) arbitrary data.
-- 
http://mail.python.org/mailman/listinfo/python-list


Plain old SAX and minidom useable? But how then?

2007-08-01 Thread Dobedani
Dear All,

I guess I don't know where to look for the right information. I hope
you guys can help me on the way. I want to retrieve a string from an
XML-file. If Python were to have XPath available, my problem would be
solved. The xquery string would be enough and I have already obtained
that the string. The problem is that I cannot use any add-on - like
xmllib, sax2 or elementtree - as my customers only have the so-called
stock Python install - i.e. version 2.4.1. I've seen some posts from
2½ years ago by Nelson Minar and also by Uche Ogbuji who wrote:
"Nelson says: There's the stock Python install, which barely does
anything [for XML]. That's overstated. Plain old SAX and minidom may
not be ideal, but they're useable."

Please: where then can I find examples of such use? If I cannot use
xpath, I would not mind to browse a bit - e.g. using functions like
getElementByTag() but I don't even know how to use those. TIA

Kind regards,
Dobedani

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


Re: Plain old SAX and minidom useable? But how then?

2007-08-01 Thread Carsten Haese
On Wed, 2007-08-01 at 04:58 -0700, Dobedani wrote:
> [...]
> "Nelson says: There's the stock Python install, which barely does
> anything [for XML]. That's overstated. Plain old SAX and minidom may
> not be ideal, but they're useable."
> 
> Please: where then can I find examples of such use? If I cannot use
> xpath, I would not mind to browse a bit - e.g. using functions like
> getElementByTag() but I don't even know how to use those. TIA

Here's a micro-tutorial:

>>> import xml.dom.minidom
>>> contents = """\
... 
...   Parrot
...   Holy Grail
... """
>>> dom = xml.dom.minidom.parseString(contents)
>>> things = dom.getElementsByTagName("thing")
>>> print things[0].childNodes
[]
>>> print things[0].childNodes[0].nodeValue
Parrot
>>> print things[0].hasAttribute("class")
False
>>> print things[0].getAttribute("class")

>>> print things[1].childNodes
[]
>>> print things[1].childNodes[0].nodeValue
Holy Grail
>>> print things[1].hasAttribute("class")
True
>>> print things[1].getAttribute("class")
special

There's also the online documentation at
http://docs.python.org/lib/module-xml.dom.minidom.html

Hope this helps,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


wxPython version question

2007-08-01 Thread The Max
Hi at all


Hi have need of testing the version of wxPython in use  at the
moment I use wxversion, but I don't can find a method for testing
version like this:

if versionOfWX() <= 2.8:

or

if versionOfWX() >= 2.8:

( versioneOfWX is a pseudo-function  create for this example )



Someone know a solution for this ?



Thanks and sorry for my orrible english

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


Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread Magnus Lycka
beginner wrote:
> Hi All,
> 
> This is just a very simple question about a python trick.
> 
> In perl, I can write __END__ in a file and the perl interpreter will
> ignore everything below that line. This is very handy when testing my
> program. Does python have something similar?

raise SystemExit() exits the program at that point (unless you
catch the exception...) "import sys;sys.exit(0)" is basically
another spelling of the same thing. It doesn't mean that the
interpreter ignores the rest of the file though, so it will
complain about syntax in the whole file.

Since I don't usually write linear top-to-bottom scripts in Python,
I don't really see the use of splitting a file in an interpreted
top and an ignored bottom though.

I'd suggest employing a test driven approach to development. Then
you don't usually have big chunks of code that you don't want to
run. All that's there works (almost)...

See e.g. 
http://powertwenty.com/kpd/downloads/TestDrivenDevelopmentInPython.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: access the name of my method inside it

2007-08-01 Thread Steve Holden
Marc 'BlackJack' Rintsch wrote:
> On Wed, 01 Aug 2007 07:01:42 -0400, Steve Holden wrote:
> 
>> Marc 'BlackJack' Rintsch wrote:
>>> On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote:
>>>
 for example I have this method

 def my_method():
 # do something

 # how do I get the name of this method which is my_method here?
>>> Why do you need this?  There are ways but those are not really good for
>>> production code.
>>>
>> Maybe he wants to write a recursive method?
>>
>> Once way is to call self.__calss__.mymethod(self). Ugly, isn't it?
> 
> Ugly yes, unnecessary convoluted yes, solution no.  You typed `my_method`
> in the source.  The OP wants to know how to avoid that.
> 
>>  >>> class p:
>> ...   def mymethod(self, n):
>> ... if n <= 1:
>> ...   return 1
>> ... else:
>> ...   return n * self.__class__.mymethod(self, n-1)
> 
> Why not simply ``self.mymethod(n - 1)`` instead!?
> 
Well, absolutely no reason if you want to go making things simple ;-)

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: wxPython version question

2007-08-01 Thread Bjoern Schliessmann
The Max wrote:

> Hi have need of testing the version of wxPython in use  at the
> moment I use wxversion, but I don't can find a method for testing
> version like this:
> 
> if versionOfWX() <= 2.8:
> 
> or
> 
> if versionOfWX() >= 2.8:
> 
> ( versioneOfWX is a pseudo-function  create for this example )
> 
> Someone know a solution for this ?

>>> import wx
>>> wx.VERSION
(2, 8, 1, 1, '')
>>> 

Regards,


Björn

-- 
BOFH excuse #298:

Not enough interrupts

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


Re: Plain old SAX and minidom useable? But how then?

2007-08-01 Thread Stefan Behnel
Hi,

calm down, minidom is not easy to use, but it can solve your problem.

Dobedani wrote:
> I guess I don't know where to look for the right information. I hope
> you guys can help me on the way. I want to retrieve a string from an
> XML-file. If Python were to have XPath available, my problem would be
> solved. The xquery string would be enough and I have already obtained
> that the string. The problem is that I cannot use any add-on - like
> xmllib, sax2 or elementtree - as my customers only have the so-called
> stock Python install - i.e. version 2.4.1.

Too bad, that rules out lxml.etree (which has XPath and loads of other goodies).


> Please: where then can I find examples of such use? If I cannot use
> xpath, I would not mind to browse a bit - e.g. using functions like
> getElementByTag() but I don't even know how to use those. TIA

Try one of these (I looked for "minidom example"):

http://www.faqs.org/docs/diveintopython/kgp_parse.html
http://docs.python.org/lib/dom-example.html
http://www.cutthecrap.biz/software/whitepapers/minidom.html

Maybe that helps?

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


Re: Plain old SAX and minidom useable? But how then?

2007-08-01 Thread Dobedani
Darsten and Stefan,

Yeah, thank you very much! I actually found a good example at
http://www.python.org/doc/2.4/lib/dom-example.html

Your input was also helpful, so now I have been able to "walk" through
the XML and to retrieve the text strings I need:

doc = parse(configfile);
elems = doc.getElementsByTagName("Environment")
for elem in elems:
name = elem.getElementsByTagName("Name")[0];
if getText(name.childNodes) == "workspace":
...

with getText as defined on the webpage referenced above.

Kind regards,
Dobedani


http://www.python.org/doc/2.4/lib/dom-example.html

On Aug 1, 2:26 pm, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Hi,
>
> calm down, minidom is not easy to use, but it can solve your problem.
>
> Dobedani wrote:
> > I guess I don't know where to look for the right information. I hope
> > you guys can help me on the way. I want to retrieve a string from an
> > XML-file. If Python were to have XPath available, my problem would be
> > solved. The xquery string would be enough and I have already obtained
> > that the string. The problem is that I cannot use any add-on - like
> > xmllib, sax2 or elementtree - as my customers only have the so-called
> > stock Python install - i.e. version 2.4.1.
>
> Too bad, that rules out lxml.etree (which has XPath and loads of other 
> goodies).
>
> > Please: where then can I find examples of such use? If I cannot use
> > xpath, I would not mind to browse a bit - e.g. using functions like
> > getElementByTag() but I don't even know how to use those. TIA
>
> Try one of these (I looked for "minidom example"):
>
> http://www.faqs.org/docs/diveintopython/kgp_parse.html
> http://docs.python.org/lib/dom-example.html
> http://www.cutthecrap.biz/software/whitepapers/minidom.html
>
> Maybe that helps?
>
> Stefan


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


Re: Extending Python by Adding Keywords & Data types

2007-08-01 Thread Paul McGuire
On Jul 31, 3:28 pm, Maximus Decimus <[EMAIL PROTECTED]> wrote:
>
> I am using python v2.5 and I am an amateur working on python. I am
> extending python for my research work and would like some help and
> guidance w.r.t this matter from you experienced python developers.
>
> II want to add some more KEYWORDS and DATATYPES into the python script
> apart from the existing ones.
>

Vishak -

Let me echo the sentiments of the other posters who replied to your
message.  It is *very* unusual for a new Python user to begin their
Pythonic journey by modifying the Python interpreter to add new
keywords and datatypes.  Python is designed to be a very flexible and
extensible language just as it is.

Since you are familiar with C, your question strikes those of us on
this group as one who would write "I'm just learning C and I would
like to modify the core library to add some new functions for my
research."  And all the readers on comp.lang.c scratch their heads,
thinking "Huh?  Why doesn't this guy just write the functions in his
own program, the way the language was designed for him to do in the
first place?"

Now maybe your research is in the field of language design, and has
something to do with the relative ease/difficulty of modifying
computer languages.  Then it would make sense for you to dive right in
to learning how to modify Python's compiler.

But if your research was in just about any other field (from finite
elements analysis to genetic programming to genetics to simulations to
process control to whatever), DON'T start by modifying Python - start
by LEARNING Python.

When a new datatype is required in a Python program, then the
programmer writes a class to implement this datatype.  The class
itself is written in Python, but it can be used just like any built-in
datatype.  For instance, here is a new datatype I just thought up - a
Box that can hold up to 'n' objects.

class Box(object):
def __init__(self,n):
self.capacity = n
self.contents = []

def add(self,other):
if len(self.contents) < self.capacity:
self.contents.append( other )
else:
raise ValueError("can't add any more to this Box")

def __iadd__(self,other):
self.add(other)
return self

box = Box(3)

# add stuff to the box until it overflows
while(True):
box += object()


Voila!  I created a new datatype, Box, and even added support for it
to understand how to use the '+=' operator so that adding objects to
the Box looks like an addition statement.  All without modifying
Python itself.  (Here's an exercise - extend this example so that the
Box has a limited capacity in the *weight* of the added objects, as
well as in the number of objects.)

This is the basic way that one extends Python with their own new
datatypes and methods.  New keywords are a little rarer, but really,
start by just adding methods, like the add method above.  Python users
around the world develop a wide range of applications and programs
using just these techniques, and never touch the Python compiler
itself.

And here is a case you'd like to avoid.  Let's say you start by
learning how to modify Python because you need a general-purpose
container for things.  You spend two weeks learning how to do this,
getting your code mostly debugged, and then you post to
comp.lang.python your proud achievement.  Immediately the replies come
back, "Congratulations, newbie, you just reinvented the built-in list
type."  Without LEARNING Python, you wont know what is already
provided in the language.

So, in general this is a helpful group, and it is possible that you DO
need to learn how to add datatypes and keywords to Python as your
first objective.  We're not trying to pry, but give us a bit more
detail.  Someone might even rough out for you what one of your new
datatypes might look like.  So pray, tell us what sort of specialized
datatypes and keywords do you think you need to add, and we'll try to
point you in one or more directions.

-- Paul

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


Re: access the name of my method inside it

2007-08-01 Thread Bruno Desthuilliers
james_027 a écrit :
> Hi,
> 
> On Aug 1, 5:18 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote:
>>> for example I have this method
>>> def my_method():
>>> # do something
>>> # how do I get the name of this method which is my_method here?
>> Why do you need this?  There are ways but those are not really good for
>> production code.
>>
> 
> I am going to use this in Django. I am trying to implement a
> permission here, where in the database store the methods that the user
> are allowed to execute. for example if the method is def
> create_event(): the method will look for create_event in the database
> to see if it allow to be execute.

Then the solution is definitively to use a decorator, cf Paul's answer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Equivalent to gzinflate() function in PHP.

2007-08-01 Thread Adam Kubica
Hellou.

Anybody know about code that work equivalent to gzinflate()
function used in PHP?

I search via google but I don't found anything sensible :-(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: access the name of my method inside it

2007-08-01 Thread Paul McGuire
On Aug 1, 8:07 am, james_027 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> On Aug 1, 5:18 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> > On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote:
> > > for example I have this method
>
> > > def my_method():
> > > # do something
>
> > > # how do I get the name of this method which is my_method here?
>
> > Why do you need this?  There are ways but those are not really good for
> > production code.
>
> I am going to use this in Django. I am trying to implement a
> permission here, where in the database store the methods that the user
> are allowed to execute. for example if the method is def
> create_event(): the method will look for create_event in the database
> to see if it allow to be execute.
>
> Thanks.
> james

How about using a decorator?  Here is a rough version:

def checkPrivs(fn):
fnName = fn.func_name
def restricted(*args):
print "about to call function", fnName
if fnName in listOfAllowedFunctions:
return fn(*args)
else:
raise KeyError("you don't have sufficient privileges to do
THAT")
return restricted

listOfAllowedFunctions = ['add','subtract']

@checkPrivs
def add(a,b):
return a+b

@checkPrivs
def subtract(a,b):
return a-b

@checkPrivs
def multiply(a,b):
return a*b

add(1,2)
subtract(4,1)
multiply(3,2)

-- Paul


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


Re: access the name of my method inside it

2007-08-01 Thread Jay Loden
james_027 wrote:
> Hi,
> 
> On Aug 1, 5:18 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote:
>>> for example I have this method
>>> def my_method():
>>> # do something
>>> # how do I get the name of this method which is my_method here?
>> Why do you need this?  There are ways but those are not really good for
>> production code.
>>
> 
> I am going to use this in Django. I am trying to implement a
> permission here, where in the database store the methods that the user
> are allowed to execute. for example if the method is def
> create_event(): the method will look for create_event in the database
> to see if it allow to be execute.

This might help, I used it for a similar need I had in the past where I needed 
a method to know the name it was called with

class TestClass:
def __init__(self):
pass

def __getattr__(self, name):
try:
return getattr(self.__class__, name)
except AttributeError:
return functools.partial(self.foo, name)

def foo(self, name, **args): 
print name
for i in args:
print " %s=%s" % (i, args[i])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: access the name of my method inside it

2007-08-01 Thread james_027
Hi,

On Aug 1, 5:18 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote:
> > for example I have this method
>
> > def my_method():
> > # do something
>
> > # how do I get the name of this method which is my_method here?
>
> Why do you need this?  There are ways but those are not really good for
> production code.
>

I am going to use this in Django. I am trying to implement a
permission here, where in the database store the methods that the user
are allowed to execute. for example if the method is def
create_event(): the method will look for create_event in the database
to see if it allow to be execute.

Thanks.
james

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


Re: Strange problems with subprocess

2007-08-01 Thread kyosohma
On Aug 1, 2:20 am, Michele Petrazzo <[EMAIL PROTECTED]>
wrote:
> Hi all. I have a simple "ping tester" program that, every 1 minute
> (execute by linux crontab), create, with subprocess, a
> "ping -c 1 my_addrs". All work, but sometime (about 1/2 times at a day),
> I receive this error message:
>
> File "/exports/srv-wipex/net_test/ping_tester.py", line 88, in pyPing
>cmd_p = Popen(cmd, stdout=PIPE, stderr=PIPE)
> File "subprocess.py", line 543, in __init__
>errread, errwrite)
> File "subprocess.py", line 970, in _execute_child
>data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB
>
> What can be that raise this?
>
> Python 2.4 in deb etch
>
> Thanks,
> Michele

This doesn't look like a complete traceback. It doesn't give what the
error was.

Mike

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


Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread beginner
On Jul 31, 10:53 pm, beginner <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> This is just a very simple question about a python trick.
>
> In perl, I can write __END__ in a file and the perl interpreter will
> ignore everything below that line. This is very handy when testing my
> program. Does python have something similar?
>
> Thanks,
> Geoffrey

Thanks everyone for responding. It doesn't look like python has it. I
would definitely miss it. As Steve said, the nice thing about __END__
is that things below __END__ do not have to have legit syntax. That
let me focus on the lines of code I am debugging and do not have to
worry about some bad syntax down the line. This feature is especially
handy if I am, saying, replacing modoules or changing data structures.


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


Re: Equivalent to gzinflate() function in PHP.

2007-08-01 Thread kyosohma
On Aug 1, 8:44 am, Adam Kubica <[EMAIL PROTECTED]> wrote:
> Hellou.
>
> Anybody know about code that work equivalent to gzinflate()
> function used in PHP?
>
> I search via google but I don't found anything sensible :-(

I'm not sure what gzinflate does, but it looks like it's some kind of
compression/decompression method. Python can do that. Check out the
following links:

http://www.python.org/doc/lib/module-gzip.html
http://www.python.org/doc/lib/module-zlib.html
http://python.active-venture.com/lib/module-bz2.html

Hopefully this is the type of thing you were looking for.

Mike

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


Re: zip() function troubles

2007-08-01 Thread Chris Mellon
On 31 Jul 2007 12:57:13 -0700, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> "Chris Mellon" <[EMAIL PROTECTED]> writes:
> > Better hand in your computer, then. You're never going to find a
> > situation where the environment won't affect the running time of your
> > algorithms.
>
> The environment may affect the running time by an additive or linear
> multiplicative constant but it should never turn an O(n) algorithm
> into an O(n**2) one.
>

Hardly true. When you start to factor real world issues like memory
allocations (and all the complexities thereof) and cache misses into
algorithmic performance an algorithm certainly can change from O(n) to
O(n**2). This is one reason why real world performance is tested and
compared using benchmarks and not Big O notation.

> > For the record, the python GC is generational. This is a case of a
> > default heuristic giving pathological behavior in a corner case, not
> > anything broken about the design of the python GC.
>
> No, it is broken, per discussion on a
> comp.compilers/comp.lang.functional thread this week.  The notion of
> using a generational collector was to collect less and less frequently
> for older and older generations (e.g. doubling the amount of
> allocation between generations) but the usual solution is apparently
> to increase the heap size by some multiplicative factor when GC fails
> to free enough memory.
> --

The issue at hand has nothing to do with the generational nature of
the Python GC. It's caused by a heuristic that aggressively attempts
to reclaim objects when there are large numbers of allocations without
releases. This is a tuneable GC parameter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: http client module

2007-08-01 Thread stefano
On 31 jul, 23:07, Steve Holden <[EMAIL PROTECTED]> wrote:
> stefano wrote:
> > Hello i'm looking for a http client for python i found this one call
> > httplib2
>
> >http://64.233.169.104/search?q=cache:0jJWNfodK6gJ:bitworking.org/proj...
>
> > but is too old
>
> Look at urllib and urllib2 in the standard library. If they don't give
> you what you want, think about using mechanize and ClientForm, or
> possible beautifulsoup, all of which Google should be able to find for you.
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -

thanks

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


Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread Neil Cerutti
On 2007-08-01, beginner <[EMAIL PROTECTED]> wrote:
> Thanks everyone for responding. It doesn't look like python has
> it. I would definitely miss it. As Steve said, the nice thing
> about __END__ is that things below __END__ do not have to have
> legit syntax. That let me focus on the lines of code I am
> debugging and do not have to worry about some bad syntax down
> the line. This feature is especially handy if I am, saying,
> replacing modoules or changing data structures.

A C-like trick might be helpful while refactoring:


if False:
   

You have to indent all the non-working code by one level, but
with a good editor that's a snap.

Python will still parse the following lines (it must be valid
Python syntax), but the resulting parse tree won't be executed.

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


Re: wxPython version question

2007-08-01 Thread Chris Mellon
On 8/1/07, The Max <[EMAIL PROTECTED]> wrote:
> Hi at all
>
>
> Hi have need of testing the version of wxPython in use  at the
> moment I use wxversion, but I don't can find a method for testing
> version like this:
>
> if versionOfWX() <= 2.8:
>
> or
>
> if versionOfWX() >= 2.8:
>
> ( versioneOfWX is a pseudo-function  create for this example )
>
>
>
> Someone know a solution for this ?
>
>
>
> Thanks and sorry for my orrible english
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

help(wxversion) describes in some detail all the methods you need.
-- 
http://mail.python.org/mailman/listinfo/python-list


Emacs + python

2007-08-01 Thread Hadron

Could anyone put me on the right track to developing Python with emacs
please : modes to consider, debugging etc hopefully all within emacs.

Any help and shared experiences much appreciated.

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


Re: Floats as keys in dict

2007-08-01 Thread Alex Martelli
Brian Elmegaard <[EMAIL PROTECTED]> wrote:

> I am making a script to optimiza by dynamic programming. I do not know
> the vertices and nodes before the calculation, so I have decided to
> store the nodes I have in play as keys in a dict.
> 
> However, the dict keys are then floats and I have to round the values
> of new possible nodes in each step. When profiling I see that the most
> time consuming part of my script is rounding.
> 
> Is there a faster way than round() or is there a better way to test
> than 'in' or should I store the keys in another way than a dict?

You may want to consider keeping a sorted list and using standard
library module bisect for searches and insertions -- its behavior is
O(log N) for a search, O(N) for an insertion, but it might be that in
your case saving the rounding could be worth it.

Otherwise, you need to consider a different container, based either on
comparisons (e.g. AVL trees, of which there are several 3rd party
implementations as Python extensions) or on a hashing function that will
give the same hash for two numbers that are "close enough" (e.g., hash
ignoring the lowest N bits of the float's mantissa for some N).

round() operates on decimals and that may not be as fast as working on
binary representations, but, to be fast, a helper function giving the
"hash of a binary-rounded float" would have to be coded in C (or maybe
use psyco).


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


Re: Where do they tech Python officialy ?

2007-08-01 Thread Alex Martelli
NicolasG <[EMAIL PROTECTED]> wrote:

> > Open source projects do not require previous professional experience to
> > accept volunteers.  So, one way out of your dilemma is to make a name
> > for yourself as an open source contributor -- help out with Python
> > itself and/or with any of the many open source projects that use Python,
> > and you will both learn a lot _and_ acquire "professional experience"
> > that any enlightened employer will recognize as such.  That will take a
> > while, but not as long as getting a college degree (and it will be far
> > cheaper than the degree).
> >
> > Alex
> 
> I think this is the best idea to escape the python amateur circle and
> go in to open source project that are considered to be professional
> projects. I don't know if it will be better to find a project to
> contribute or to start a new one .. Will have a look around and think
> about.

Unless you have some specific new idea that you're keen to address and
can't be met by existing projects, joining an existing project would
normally be a better bet.  One-person projects are rarely as important
as larger ones, and it's quite hard to get other collaborators to a new
project; working in a project with existing code and contributors will
also be more instructive.  As for which OS projects are "considered to
be professional", just about all large successful ones are so
considered: after all, even games, say, are "professional projects" from
the POV of firms that develop and sell them, such as EA!-)


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


Extending doctest

2007-08-01 Thread Neil Cerutti
One of my current tests looks like this (the program is an
interpreter for a scheme-like language):

>>> result = parse_op('(with (b (newbox 5))'
... '   (seqn (setbox b 1)'
... ' (setbox b 2)'
... ' (setbox b 3)'
... ' b))').interp(EmptyEnv(), EmptyStore())
>>> result #doctest: +ELLIPSIS
(, ~...:  ~)
>>> result[0].location == result[1].location
True

The memrory location that the box refers to must match the actual
location in storage. Currently, the doctest stinks because it
depends on internal details of my implementation.

Is there a doctest feature that will allow me to stipulate that
one thing in a result is arbitrary, but identical to another
thing in that result?

-- 
Neil Cerutti
Trespassers will be prosecuted to the full extent of the law --sign at Sisters
of Mercy Nunnery
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with subprocess.Popen()

2007-08-01 Thread O.R.Senthil Kumaran
> I'm trying to run a windows batch file from a python script using
> subprocess.popen().
> 
> The issue that I'm facing is that, if i give the batch file as
> parameter to the popen function, the script runs, but if i provide a
> parameter, it is not working.
> 
> The actual windows command to be executed is:
> 
> test.bat -t ABC_DE_FG_HI_001 "C:\ABCDEFGHIJKLMNOP.TXT"

do something like:
subprocess.Popen(r'test.bat -t ABC_DE_FG_HI_001
"C:\ABCDEFGHIJKLMNOP.TXT",shell=True)

This is same as doing os.system()

If even this results in any error (post back the error message) and try
setting the executable argument explicit.

subprocess.Popen(r'test.bat -t ABC_DE_001
"C:\ABCD.TXT",executable="test.bat",shell=True)


-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where do they tech Python officialy ?

2007-08-01 Thread Ant
On Aug 1, 9:40 am, Alex Popescu <[EMAIL PROTECTED]> wrote:
...
> It depends :-). In my experience I met employers being concerned by my
> implication in the oss world :-).

I have the opposite experience. It was predominantly the fact that I
was involved in several open source projects that got me into
professional development 3 years ago. The employers in the market at
the time required 2 years+ of commercial experience - the fact that I
was involved in OSS helped on two counts, firstly that it showed that
I actually have an interest in development (rather than being another
Comp Sci graduate just after a wage), and secondly that I have
experience in good development practice (the open source projects I
worked on had better infrastructure in place than two of the three
companies I've worked for since!)

--
Ant...

http://antroy.blogspot.com/


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


Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread Diez B. Roggisch
beginner wrote:

> On Jul 31, 10:53 pm, beginner <[EMAIL PROTECTED]> wrote:
>> Hi All,
>>
>> This is just a very simple question about a python trick.
>>
>> In perl, I can write __END__ in a file and the perl interpreter will
>> ignore everything below that line. This is very handy when testing my
>> program. Does python have something similar?
>>
>> Thanks,
>> Geoffrey
> 
> Thanks everyone for responding. It doesn't look like python has it. I
> would definitely miss it. As Steve said, the nice thing about __END__
> is that things below __END__ do not have to have legit syntax. That
> let me focus on the lines of code I am debugging and do not have to
> worry about some bad syntax down the line. This feature is especially
> handy if I am, saying, replacing modoules or changing data structures.

In emacs, I simply mark that portion of code and do

M-x comment-region

That's it. And I don't think a language should support things __END__ -
commenting is enough. It's unfortunate that Python doesn't support
multi-line-comments though. But as I said, that my Editor can handle for
me.

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


Re: Where do they tech Python officialy ?

2007-08-01 Thread Alex Martelli
Alex Popescu <[EMAIL PROTECTED]> wrote:
   ...
> > and you will both learn a lot _and_ acquire "professional experience"
> > that any enlightened employer will recognize as such.  
> 
> It depends :-). In my experience I met employers being concerned by my
> implication in the oss world :-).

Considering that even the King of Proprietary Software, Microsoft, now
happily hires major Open Source figures such as Jim Hugunin (MS was also
a top-tier sponsor at the recent OSCON, with both managerial and senior
technical employees giving keynotes and tech talks), it boggles the mind
to think about which kind of company would instead be "concerned" by a
candidate's OS experience.


> > That will take a
> > while, but not as long as getting a college degree (and it will be far
> > cheaper than the degree).
> 
> I don't know much about the open community in Python world, but in Java
> world becoming a project member may be more difficult than getting a 
> degree (or close to :-)) ).

In a major project, you will of course have to supply useful
contributions as well as proving to have a reasonable personality &c
before being granted committer privileges; and a few projects (centered
on a group of committers employed by a single firm or on an otherwise
close-knit small clique) are not very open to the outside world at all.
But (at least wrt projects using Python, C, C++ -- I have no experience
of opensource projects focused on Java instead) that is the exception,
not the rule.


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


force unicode strings

2007-08-01 Thread Thomas Guettler
Hi,

is it possible to force all non ascii strings to be unicode strings
somehow?

Sometimes I forget that I need to write u'...' if the string contains
an umlaut. I get an exception in django later. But since the
exception does not show the string it is hard to find it.

Is it possible to loop over all strings the interpreter has parsed?

Pure ascii strings are OK.

 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: [EMAIL PROTECTED]

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


Assertion in list comprehension

2007-08-01 Thread beginner
Hi,

Does anyone know how to put an assertion in list comprehension? I have
the following list comprehension, but I want to use an assertion to
check the contents of rec_stdl. I ended up using another loop which
essentially duplicates the functions of list comprehension. It just
look like a waste of coding and computer time to me.

I just wish I could put the assertions into list comprehensions.

x=[(rec_stdl[0].st/1.0,
rec_stdl[0].cl,
rec_stdl[0].bb,
rec_stdl[0].bo,
rec_stdl[1].bb,
rec_stdl[1].bo,
rec_stdl[0].ex
   )
   for rec_stdl in rec_by_ex if len(rec_stdl)==2
]

#duplicated loop
if __debug__:
for rec_stdl in rec_by_ex:
l=len(rec_stdl)
assert(l<=2 and l>0)
if l==2:
assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
assert(rec_stdl[0].ex==rec_stdl[1].ex)
assert(rec_stdl[0].st==rec_stdl[1].st)
assert(rec_stdl[0].cp==rec_stdl[1].cp)

Thanks,
Geoffrey

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


Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread Chris Mellon
On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> On Jul 31, 10:53 pm, beginner <[EMAIL PROTECTED]> wrote:
> > Hi All,
> >
> > This is just a very simple question about a python trick.
> >
> > In perl, I can write __END__ in a file and the perl interpreter will
> > ignore everything below that line. This is very handy when testing my
> > program. Does python have something similar?
> >
> > Thanks,
> > Geoffrey
>
> Thanks everyone for responding. It doesn't look like python has it. I
> would definitely miss it. As Steve said, the nice thing about __END__
> is that things below __END__ do not have to have legit syntax. That
> let me focus on the lines of code I am debugging and do not have to
> worry about some bad syntax down the line. This feature is especially
> handy if I am, saying, replacing modoules or changing data structures.
>

You'll probably find greater gains by embracing the limitation and
using it to help you refactor your code into smaller, more discrete
modules. Many of pythons limitations that beginners complain about are
of this nature.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floats as keys in dict

2007-08-01 Thread Steve Holden
Alex Martelli wrote:
> Brian Elmegaard <[EMAIL PROTECTED]> wrote:
> 
>> I am making a script to optimiza by dynamic programming. I do not know
>> the vertices and nodes before the calculation, so I have decided to
>> store the nodes I have in play as keys in a dict.
>>
>> However, the dict keys are then floats and I have to round the values
>> of new possible nodes in each step. When profiling I see that the most
>> time consuming part of my script is rounding.
>>
>> Is there a faster way than round() or is there a better way to test
>> than 'in' or should I store the keys in another way than a dict?
> 
> You may want to consider keeping a sorted list and using standard
> library module bisect for searches and insertions -- its behavior is
> O(log N) for a search, O(N) for an insertion, but it might be that in
> your case saving the rounding could be worth it.
> 
> Otherwise, you need to consider a different container, based either on
> comparisons (e.g. AVL trees, of which there are several 3rd party
> implementations as Python extensions) or on a hashing function that will
> give the same hash for two numbers that are "close enough" (e.g., hash
> ignoring the lowest N bits of the float's mantissa for some N).
> 
That might be a bit dangerous in cases close to changes in exponent, 
though, where you could get numbers that were very close but had hugely 
different mantissa values because their exponents were one different, no?

> round() operates on decimals and that may not be as fast as working on
> binary representations, but, to be fast, a helper function giving the
> "hash of a binary-rounded float" would have to be coded in C (or maybe
> use psyco).
> 
Your first suggestion was better, I think. Bisect would do the job. I 
have always thought that dict's numerical index semantics were suspect, 
but it's probably way too late to alter that now. [I'm assuming that 
Py3.0 is retaining the numerical equivalence relations].

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: What is the "functional" way of doing this?

2007-08-01 Thread Alexander Schmolck
beginner <[EMAIL PROTECTED]> writes:

> Hi,
>
> If I have a number n and want to generate a list based on like the
> following:
>
> def f(n):
>  l=[]
>  while n>0:
>  l.append(n%26)
>  n /=26
> return l
>
> I am wondering what is the 'functional' way to do the same.

This is very 'functional' (and also quite concise):

f = compose(list,partial(unfold, divmod(_,26)))

The definitions of compose, unfold, and _ are left as excercises (of
increasing difficulty) for the reader.

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


Re: Assertion in list comprehension

2007-08-01 Thread [EMAIL PROTECTED]
On Aug 1, 9:37 am, beginner <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Does anyone know how to put an assertion in list comprehension? I have
> the following list comprehension, but I want to use an assertion to
> check the contents of rec_stdl. I ended up using another loop which
> essentially duplicates the functions of list comprehension. It just
> look like a waste of coding and computer time to me.
>
> I just wish I could put the assertions into list comprehensions.
>
> x=[(rec_stdl[0].st/1.0,
> rec_stdl[0].cl,
> rec_stdl[0].bb,
> rec_stdl[0].bo,
> rec_stdl[1].bb,
> rec_stdl[1].bo,
> rec_stdl[0].ex
>)
>for rec_stdl in rec_by_ex if len(rec_stdl)==2
> ]
>
> #duplicated loop
> if __debug__:
> for rec_stdl in rec_by_ex:
> l=len(rec_stdl)
> assert(l<=2 and l>0)
> if l==2:
> assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
> assert(rec_stdl[0].ex==rec_stdl[1].ex)
> assert(rec_stdl[0].st==rec_stdl[1].st)
> assert(rec_stdl[0].cp==rec_stdl[1].cp)
>
> Thanks,
> Geoffrey

Can't you just call a function from within your list comprehension and
do whatever you want for each item? Something like this (not tested):

def checker(item):
assert(len(item) <= 2 and len(item) > 0)
if len(item) == 2:
assert(item[0].c == "C" and item[1].c == "P"

return len(item) == 2

x = [whatever for item in all_items if checker(item = item)]

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


Awkward format string

2007-08-01 Thread beginner
Hi,

In order to print out the contents of a list, sometimes I have to use
very awkward constructions. For example, I have to convert the
datetime.datetime type to string first, construct a new list, and then
send it to print. The following is an example.

x=(e[0].strftime("%Y-%m-%d"), e[1].strftime("%Y-%m-%d"))+e[2:]
print  >>f, "%s\t%s\t%d\t%f\t%f\t%f\t%d" % x

e is a tuple. x is my new tuple.

Does anyone know better ways of handling this?

Thanks,
Geoffrey

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


Re: What is the "functional" way of doing this?

2007-08-01 Thread Chris Mellon
On 7/31/07, Ricardo Aráoz <[EMAIL PROTECTED]> wrote:
> Steven D'Aprano wrote:
> > On Tue, 31 Jul 2007 09:01:42 -0300, Ricardo Aráoz wrote:
> >
> >> Considering I am a beginner I did a little test. Funny results too. The
> >> function I proposed (lists1.py) took 11.4529998302 seconds, while the
> >> other one (lists2.py) took 16.141324 seconds, thats about 40% more.
> >> They were run in IDLE from their own windows (F5).
> >
> > [snip code]
> >
> > You may find that using the timeit module is better than rolling your own
> > timer.
> >
>  def recursive_func(n):
> > ... if n > 0:
> > ... return [n % 26] + recursive_func(n/26)
> > ... else:
> > ... return []
> > ...
>  def generator_func(n):
> > ... def mseq(n):
> > ... while n > 0:
> > ... n, a = divmod(n, 26)
> > ... yield a
> > ... return list(mseq(n))
> > ...
>  import timeit
>  N = 10**6+1
>  timeit.Timer("recursive_func(N)",
> > ... "from __main__ import N, recursive_func").repeat()
> > [16.48972487449646, 17.000514984130859, 16.520529985427856]
>  timeit.Timer("generator_func(N)",
> > ... "from __main__ import N, generator_func").repeat()
> > [27.938560009002686, 28.970781087875366, 23.977837085723877]
> >
> >
> > If you're going to compare speeds, you should also test this one:
> >
>  def procedural_func(n):
> > ... results = []
> > ... while n > 0:
> > ... n, a = divmod(n, 26)
> > ... results.append(a)
> > ... return results
> > ...
>  timeit.Timer("procedural_func(N)",
> > ... "from __main__ import N, procedural_func").repeat()
> > [15.577107906341553, 15.60145378112793, 15.345284938812256]
> >
> >
> > I must admit that I'm surprised at how well the recursive version did, and
> > how slow the generator-based version was. But I'd be careful about drawing
> > grand conclusions about the general speed of recursion etc. in Python from
> > this one single example. I think this is simply because the examples tried
> > make so few recursive calls. Consider instead an example that makes a few
> > more calls:
> >
>  N = 26**100 + 1
> 
>  timeit.Timer("recursive_func(N)",
> > ... "from __main__ import N, recursive_func").repeat(3, 1)
> > [7.0015969276428223, 7.6065640449523926, 6.8495190143585205]
>  timeit.Timer("generator_func(N)",
> > ... "from __main__ import N, generator_func").repeat(3, 1)
> > [3.5656340129, 3.1132731437683105, 3.8274538516998291]
>  timeit.Timer("procedural_func(N)",
> > ... "from __main__ import N, procedural_func").repeat(3, 1)
> > [3.3509068489074707, 4.0872640609741211, 3.3742849826812744]
> >
> >
>
> Yup! As soon as the size of the list increases the generator function
> gets better (50% in my tests). But it's interesting to note that if the
> list is within certain limits (I've tested integers (i.e. 2,100,000,000
> => 7 member list)) and you only vary the times the funct. is called then
> the recursive one does better.
>
>

Not especially surprising. Suspending and resuming a generator is
naturally more expensive than a single function call. The advantages
of generators are time/space tradeoffs, greater expressiveness, and
state preservation (not used here).
-- 
http://mail.python.org/mailman/listinfo/python-list


Time object?

2007-08-01 Thread Robert Dailey
Hi,

I'm well aware of the datetime module, however it is really inconsistent and
useless to me. In order to do any arithmetic on time objects, I have to use
the 'timedelta' class, which doesn't even allow me to do all the math I want
to do.

For example, I want to do "1 / timeobj", where timeobj might represent a
time in the format of "00:00:00.00". Do I have to code my own class for
this, or is there some other third party library out there that will allow
me to do this?

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

Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Neil Cerutti  <[EMAIL PROTECTED]> wrote:
>On 2007-08-01, beginner <[EMAIL PROTECTED]> wrote:
>> Thanks everyone for responding. It doesn't look like python has
>> it. I would definitely miss it. As Steve said, the nice thing
>> about __END__ is that things below __END__ do not have to have
>> legit syntax. That let me focus on the lines of code I am
>> debugging and do not have to worry about some bad syntax down
>> the line. This feature is especially handy if I am, saying,
>> replacing modoules or changing data structures.
>
>A C-like trick might be helpful while refactoring:
>
>
>if False:
>   
>
>You have to indent all the non-working code by one level, but
>with a good editor that's a snap.
>
>Python will still parse the following lines (it must be valid
>Python syntax), but the resulting parse tree won't be executed.
.
.
.
I want to re-emphasize the "triple-quote it" tip mentioned
earlier in this thread.  I think the original questioner
will find this quite satisfying, if I understand his situ-
ation at all.

*I* certainly have source code with embedded "junk" 
commented out as multi-line strings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread Neil Cerutti
On 2007-08-01, Cameron Laird <[EMAIL PROTECTED]> wrote:
> In article <[EMAIL PROTECTED]>,
> Neil Cerutti  <[EMAIL PROTECTED]> wrote:
>>On 2007-08-01, beginner <[EMAIL PROTECTED]> wrote:
>>> Thanks everyone for responding. It doesn't look like python has
>>> it. I would definitely miss it. As Steve said, the nice thing
>>> about __END__ is that things below __END__ do not have to have
>>> legit syntax. That let me focus on the lines of code I am
>>> debugging and do not have to worry about some bad syntax down
>>> the line. This feature is especially handy if I am, saying,
>>> replacing modoules or changing data structures.
>>
>>A C-like trick might be helpful while refactoring:
>>
>>
>>if False:
>>   
>>
>>You have to indent all the non-working code by one level, but
>>with a good editor that's a snap.
>>
>>Python will still parse the following lines (it must be valid
>>Python syntax), but the resulting parse tree won't be executed.
>   .
>   .
>   .
> I want to re-emphasize the "triple-quote it" tip mentioned
> earlier in this thread.  I think the original questioner
> will find this quite satisfying, if I understand his situ-
> ation at all.
>
> *I* certainly have source code with embedded "junk" 
> commented out as multi-line strings.

I used to do that, but now that I use doctests so much it's
infeasible to comment out arbitrary code that way, since they
can't necessarily nest.

But Diez suggestion is even easier than the if False suggestion I
made.

-- 
Neil Cerutti

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


Re: Awkward format string

2007-08-01 Thread beginner
On Aug 1, 11:31 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > In order to print out the contents of a list, sometimes I have to use
> > very awkward constructions. For example, I have to convert the
> > datetime.datetime type to string first, construct a new list, and then
> > send it to print. The following is an example.
>
> > x=(e[0].strftime("%Y-%m-%d"), e[1].strftime("%Y-%m-%d"))+e[2:]
> > print  >>f, "%s\t%s\t%d\t%f\t%f\t%f\t%d" % x
>
> > e is a tuple. x is my new tuple.
>
> > Does anyone know better ways of handling this?
>
> You seem to be doing quite complicated things with your magical e
> tuple. Do you have some specific aversion to classes?

e is not complicated. It is a record that have 7 fields. In my program
a function outputs a list of tuples, each is of type e, and now I just
need to send them to a text file.

I have no problem using classes and I do use them everywhere. But
using classes does not solve my problem here. I will probably find
myself doing:

print  >>f, "%s\t%s\t%d\t%f\t%f\t%f\t%d" % (x.field1..strftime("%Y-%m-
%d"), x.field2..strftime("%Y-%m-%d"), x.field3, x.field4, x.field5,
x.field.6, x.field7)

This is also tedious and error-prone.



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


Re: Time object?

2007-08-01 Thread Steve Holden
Robert Dailey wrote:
> Hi,
> 
> I'm well aware of the datetime module, however it is really inconsistent 
> and useless to me. In order to do any arithmetic on time objects, I have 
> to use the 'timedelta' class, which doesn't even allow me to do all the 
> math I want to do.
> 
> For example, I want to do "1 / timeobj", where timeobj might represent a 
> time in the format of "00:00:00.00". Do I have to code my own class 
> for this, or is there some other third party library out there that will 
> allow me to do this?
> 
> Thanks.
> 
But surely all you really need is a function to convert a timedelta to 
seconds. Like:

secs(td):
   return (td.days*24*3600)+td.seconds+(td.microseconds/100.0)

So I don't really see the need for a third party library. It may be 
useless to you: have you considered that your use case might be 
non-standard? Or perhaps you just like to make things difficult.

Once you have your times in seconds then rate calculations are a piece 
of cake.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Awkward format string

2007-08-01 Thread Chris Mellon
On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> Hi,
>
> In order to print out the contents of a list, sometimes I have to use
> very awkward constructions. For example, I have to convert the
> datetime.datetime type to string first, construct a new list, and then
> send it to print. The following is an example.
>
> x=(e[0].strftime("%Y-%m-%d"), e[1].strftime("%Y-%m-%d"))+e[2:]
> print  >>f, "%s\t%s\t%d\t%f\t%f\t%f\t%d" % x
>
> e is a tuple. x is my new tuple.
>
> Does anyone know better ways of handling this?
>

You seem to be doing quite complicated things with your magical e
tuple. Do you have some specific aversion to classes?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Assertion in list comprehension

2007-08-01 Thread Chris Mellon
On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Does anyone know how to put an assertion in list comprehension? I have
> the following list comprehension, but I want to use an assertion to
> check the contents of rec_stdl. I ended up using another loop which
> essentially duplicates the functions of list comprehension. It just
> look like a waste of coding and computer time to me.
>
> I just wish I could put the assertions into list comprehensions.
>
> x=[(rec_stdl[0].st/1.0,
> rec_stdl[0].cl,
> rec_stdl[0].bb,
> rec_stdl[0].bo,
> rec_stdl[1].bb,
> rec_stdl[1].bo,
> rec_stdl[0].ex
>)
>for rec_stdl in rec_by_ex if len(rec_stdl)==2
> ]
>
> #duplicated loop
> if __debug__:
> for rec_stdl in rec_by_ex:
> l=len(rec_stdl)
> assert(l<=2 and l>0)
> if l==2:
> assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
> assert(rec_stdl[0].ex==rec_stdl[1].ex)
> assert(rec_stdl[0].st==rec_stdl[1].st)
> assert(rec_stdl[0].cp==rec_stdl[1].cp)

First: All your asserts are wrong. Assert is a statement, not a
function. These specific ones will behave as expected, but it's easy
to accidentally write ones that always pass this way.

Secondly: This is a waste of code, because if __debug__ is not defined
asserts will be skipped by the compiler. You could use the same loop
block for both branches.

Thirdly: This sort of testing is precisely what unit tests and/or
doctests are for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling a .net application from Python 2.5

2007-08-01 Thread James Matthews
http://pythonnet.sourceforge.net/

On 8/1/07, Acm <[EMAIL PROTECTED]> wrote:
>
> I am working with Python 2.5.
>
> I would like to know how to call a .NET application (or .dll) from a
> Python script.
>
> Can anyone help please?
>
> Thank you.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.goldwatches.com/
http://www.jewelerslounge.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: calling a .net application from Python 2.5

2007-08-01 Thread Chris Mellon
Note that for 2.5 you'll want the released snapshot, not the official release.

On 8/1/07, James Matthews <[EMAIL PROTECTED]> wrote:
> http://pythonnet.sourceforge.net/
>
>
> On 8/1/07, Acm <[EMAIL PROTECTED] > wrote:
> > I am working with Python 2.5.
> >
> > I would like to know how to call a .NET application (or .dll) from a
> > Python script.
> >
> > Can anyone help please?
> >
> > Thank you.
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
>
> --
> http://www.goldwatches.com/
> http://www.jewelerslounge.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Assertion in list comprehension

2007-08-01 Thread beginner
On Aug 1, 11:09 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Aug 1, 9:37 am, beginner <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hi,
>
> > Does anyone know how to put an assertion in list comprehension? I have
> > the following list comprehension, but I want to use an assertion to
> > check the contents of rec_stdl. I ended up using another loop which
> > essentially duplicates the functions of list comprehension. It just
> > look like a waste of coding and computer time to me.
>
> > I just wish I could put the assertions into list comprehensions.
>
> > x=[(rec_stdl[0].st/1.0,
> > rec_stdl[0].cl,
> > rec_stdl[0].bb,
> > rec_stdl[0].bo,
> > rec_stdl[1].bb,
> > rec_stdl[1].bo,
> > rec_stdl[0].ex
> >)
> >for rec_stdl in rec_by_ex if len(rec_stdl)==2
> > ]
>
> > #duplicated loop
> > if __debug__:
> > for rec_stdl in rec_by_ex:
> > l=len(rec_stdl)
> > assert(l<=2 and l>0)
> > if l==2:
> > assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
> > assert(rec_stdl[0].ex==rec_stdl[1].ex)
> > assert(rec_stdl[0].st==rec_stdl[1].st)
> > assert(rec_stdl[0].cp==rec_stdl[1].cp)
>
> > Thanks,
> > Geoffrey
>
> Can't you just call a function from within your list comprehension and
> do whatever you want for each item? Something like this (not tested):
>
> def checker(item):
> assert(len(item) <= 2 and len(item) > 0)
> if len(item) == 2:
> assert(item[0].c == "C" and item[1].c == "P"
>
> return len(item) == 2
>
> x = [whatever for item in all_items if checker(item = item)]- Hide quoted 
> text -
>
> - Show quoted text -

Good idea! Thank you!

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


Re: Assertion in list comprehension

2007-08-01 Thread Stargaming
On Wed, 01 Aug 2007 11:28:48 -0500, Chris Mellon wrote:

> On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> Does anyone know how to put an assertion in list comprehension? I have
>> the following list comprehension, but I want to use an assertion to
>> check the contents of rec_stdl. I ended up using another loop which
>> essentially duplicates the functions of list comprehension. It just
>> look like a waste of coding and computer time to me.
>>
>> I just wish I could put the assertions into list comprehensions.
>>
>> x=[(rec_stdl[0].st/1.0,
>> rec_stdl[0].cl,
>> rec_stdl[0].bb,
>> rec_stdl[0].bo,
>> rec_stdl[1].bb,
>> rec_stdl[1].bo,
>> rec_stdl[0].ex
>>)
>>for rec_stdl in rec_by_ex if len(rec_stdl)==2
>> ]
>>
>> #duplicated loop
>> if __debug__:
>> for rec_stdl in rec_by_ex:
>> l=len(rec_stdl)
>> assert(l<=2 and l>0)
>> if l==2:
>> assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
>> assert(rec_stdl[0].ex==rec_stdl[1].ex)
>> assert(rec_stdl[0].st==rec_stdl[1].st)
>> assert(rec_stdl[0].cp==rec_stdl[1].cp)
> 
> First: All your asserts are wrong. Assert is a statement, not a
> function. These specific ones will behave as expected, but it's easy to
> accidentally write ones that always pass this way.

Could you come up with an example? I can only think of accidentally 
injecting a comma, what would create a (true, in a boolean context) tuple.

And, well, if you're only using () for readabilty, this might sometimes 
look messy when calling assert with the extended syntax::

  assert(False), "error text"

Where one could expect the construction of a tuple.

> Secondly: This is a waste of code, because if __debug__ is not defined
> asserts will be skipped by the compiler. You could use the same loop
> block for both branches.

Well, the `assert` isn't there for no reason, but if you're serious about 
it, `raise` could be better.

> Thirdly: This sort of testing is precisely what unit tests and/or
> doctests are for.

Huh? What beginner is doing there seems more like input validation than 
testing. Unit or doctests are meant for testing (and in case of doctests, 
showing) whether a function works as expected.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Awkward format string

2007-08-01 Thread Ian Clark
beginner wrote:
> Hi,
> 
> In order to print out the contents of a list, sometimes I have to use
> very awkward constructions. For example, I have to convert the
> datetime.datetime type to string first, construct a new list, and then
> send it to print. The following is an example.
> 
>   x=(e[0].strftime("%Y-%m-%d"), e[1].strftime("%Y-%m-%d"))+e[2:]
>   print  >>f, "%s\t%s\t%d\t%f\t%f\t%f\t%d" % x
> 
> e is a tuple. x is my new tuple.
> 
> Does anyone know better ways of handling this?
> 
> Thanks,
> Geoffrey
> 

>>> import datetime
>>> old_tuple = (
... datetime.datetime(2007, 8, 1),
... datetime.datetime(2007, 8, 2),
... 1,
... 2.0,
... 3.0,
... 4
... )
>>> first_date = old_tuple[0].strftime('%Y-%m-%d')
>>> second_date = old_tuple[1].strftime('%Y-%m-%d')
>>> new_tuple = (first_date, second_date) + old_tuple[2:]
>>> print '\t'.join(str(i) for i in new_tuple)
2007-08-01  2007-08-02  1   2.0 3.0 4

Without more information that's the best I can think of.

Ian

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


Checking object types

2007-08-01 Thread Robert Dailey
Hi,

I'm currently interested in creating an __add__() operator for one of my
classes. This class handles both integers and objects its own type, however
I don't know how I can perform special add operations depending on which is
passed in. Since I haven't seen any evidence of function overloading, I'm
assuming I'll have to check the types of the variables passed in inside of
my __add__() method.

Take the two following examples:

vector3(3,4,2) + 5 = vector3(8,9,7)
vector3(3,2,1) + vector3(4,5,6) = vector3(7,7,7)

Any tips? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Assertion in list comprehension

2007-08-01 Thread Marc 'BlackJack' Rintsch
On Wed, 01 Aug 2007 16:55:53 +, Stargaming wrote:

>> Thirdly: This sort of testing is precisely what unit tests and/or
>> doctests are for.
> 
> Huh? What beginner is doing there seems more like input validation than 
> testing. Unit or doctests are meant for testing (and in case of doctests, 
> showing) whether a function works as expected.

If it is input validation I wouldn't expect it protected by a ``if
__debug__:``.  That looks more like debugging/testing.

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


Re: Assertion in list comprehension

2007-08-01 Thread beginner
On Aug 1, 11:28 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hi,
>
> > Does anyone know how to put an assertion in list comprehension? I have
> > the following list comprehension, but I want to use an assertion to
> > check the contents of rec_stdl. I ended up using another loop which
> > essentially duplicates the functions of list comprehension. It just
> > look like a waste of coding and computer time to me.
>
> > I just wish I could put the assertions into list comprehensions.
>
> > x=[(rec_stdl[0].st/1.0,
> > rec_stdl[0].cl,
> > rec_stdl[0].bb,
> > rec_stdl[0].bo,
> > rec_stdl[1].bb,
> > rec_stdl[1].bo,
> > rec_stdl[0].ex
> >)
> >for rec_stdl in rec_by_ex if len(rec_stdl)==2
> > ]
>
> > #duplicated loop
> > if __debug__:
> > for rec_stdl in rec_by_ex:
> > l=len(rec_stdl)
> > assert(l<=2 and l>0)
> > if l==2:
> > assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
> > assert(rec_stdl[0].ex==rec_stdl[1].ex)
> > assert(rec_stdl[0].st==rec_stdl[1].st)
> > assert(rec_stdl[0].cp==rec_stdl[1].cp)
>
> First: All your asserts are wrong. Assert is a statement, not a
> function. These specific ones will behave as expected, but it's easy
> to accidentally write ones that always pass this way.


Do you mean I should not use the parentheses?


> Secondly: This is a waste of code, because if __debug__ is not defined
> asserts will be skipped by the compiler. You could use the same loop
> block for both branches.

I know. My original question was how. Dan suggested to write a checker
function.


> Thirdly: This sort of testing is precisely what unit tests and/or
> doctests are for.

Agreed.

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


Re: Awkward format string

2007-08-01 Thread Chris Mellon
On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> On Aug 1, 11:31 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> > On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> >
> > > In order to print out the contents of a list, sometimes I have to use
> > > very awkward constructions. For example, I have to convert the
> > > datetime.datetime type to string first, construct a new list, and then
> > > send it to print. The following is an example.
> >
> > > x=(e[0].strftime("%Y-%m-%d"), e[1].strftime("%Y-%m-%d"))+e[2:]
> > > print  >>f, "%s\t%s\t%d\t%f\t%f\t%f\t%d" % x
> >
> > > e is a tuple. x is my new tuple.
> >
> > > Does anyone know better ways of handling this?
> >
> > You seem to be doing quite complicated things with your magical e
> > tuple. Do you have some specific aversion to classes?
>
> e is not complicated. It is a record that have 7 fields. In my program
> a function outputs a list of tuples, each is of type e, and now I just
> need to send them to a text file.
>
> I have no problem using classes and I do use them everywhere. But
> using classes does not solve my problem here. I will probably find
> myself doing:
>
> print  >>f, "%s\t%s\t%d\t%f\t%f\t%f\t%d" % (x.field1..strftime("%Y-%m-
> %d"), x.field2..strftime("%Y-%m-%d"), x.field3, x.field4, x.field5,
> x.field.6, x.field7)
>
> This is also tedious and error-prone.
>

If you ever need to write this more than once you're doing it wrong.
I'm not sure what's "tedious and error prone" about specifying the
format of your data file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Awkward format string

2007-08-01 Thread Neil Cerutti
On 2007-08-01, beginner <[EMAIL PROTECTED]> wrote:
> print  >>f, "%s\t%s\t%d\t%f\t%f\t%f\t%d" %
> (x.field1..strftime("%Y-%m- %d"),
> x.field2..strftime("%Y-%m-%d"), x.field3, x.field4, x.field5,
> x.field.6, x.field7)
>
> This is also tedious and error-prone.

Providing a suitable .str or .__repr__ method for your class
may make that problem disappear.

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


Re: Assertion in list comprehension

2007-08-01 Thread Chris Mellon
On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> On Aug 1, 11:28 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> > On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> >
> >
> > > Hi,
> >
> > > Does anyone know how to put an assertion in list comprehension? I have
> > > the following list comprehension, but I want to use an assertion to
> > > check the contents of rec_stdl. I ended up using another loop which
> > > essentially duplicates the functions of list comprehension. It just
> > > look like a waste of coding and computer time to me.
> >
> > > I just wish I could put the assertions into list comprehensions.
> >
> > > x=[(rec_stdl[0].st/1.0,
> > > rec_stdl[0].cl,
> > > rec_stdl[0].bb,
> > > rec_stdl[0].bo,
> > > rec_stdl[1].bb,
> > > rec_stdl[1].bo,
> > > rec_stdl[0].ex
> > >)
> > >for rec_stdl in rec_by_ex if len(rec_stdl)==2
> > > ]
> >
> > > #duplicated loop
> > > if __debug__:
> > > for rec_stdl in rec_by_ex:
> > > l=len(rec_stdl)
> > > assert(l<=2 and l>0)
> > > if l==2:
> > > assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
> > > assert(rec_stdl[0].ex==rec_stdl[1].ex)
> > > assert(rec_stdl[0].st==rec_stdl[1].st)
> > > assert(rec_stdl[0].cp==rec_stdl[1].cp)
> >
> > First: All your asserts are wrong. Assert is a statement, not a
> > function. These specific ones will behave as expected, but it's easy
> > to accidentally write ones that always pass this way.
>
>
> Do you mean I should not use the parentheses?
>

Yes.

>
> > Secondly: This is a waste of code, because if __debug__ is not defined
> > asserts will be skipped by the compiler. You could use the same loop
> > block for both branches.
>
> I know. My original question was how. Dan suggested to write a checker
> function.
>

Use the second block in all cases. In any situation where "if
__debug__" is False, the asserts are a noop and in fact won't even be
present in the bytecode.

>
> > Thirdly: This sort of testing is precisely what unit tests and/or
> > doctests are for.
>
> Agreed.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Assertion in list comprehension

2007-08-01 Thread Chris Mellon
On 01 Aug 2007 16:55:53 GMT, Stargaming <[EMAIL PROTECTED]> wrote:
> On Wed, 01 Aug 2007 11:28:48 -0500, Chris Mellon wrote:
>
> > On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> >> Hi,
> >>
> >> Does anyone know how to put an assertion in list comprehension? I have
> >> the following list comprehension, but I want to use an assertion to
> >> check the contents of rec_stdl. I ended up using another loop which
> >> essentially duplicates the functions of list comprehension. It just
> >> look like a waste of coding and computer time to me.
> >>
> >> I just wish I could put the assertions into list comprehensions.
> >>
> >> x=[(rec_stdl[0].st/1.0,
> >> rec_stdl[0].cl,
> >> rec_stdl[0].bb,
> >> rec_stdl[0].bo,
> >> rec_stdl[1].bb,
> >> rec_stdl[1].bo,
> >> rec_stdl[0].ex
> >>)
> >>for rec_stdl in rec_by_ex if len(rec_stdl)==2
> >> ]
> >>
> >> #duplicated loop
> >> if __debug__:
> >> for rec_stdl in rec_by_ex:
> >> l=len(rec_stdl)
> >> assert(l<=2 and l>0)
> >> if l==2:
> >> assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
> >> assert(rec_stdl[0].ex==rec_stdl[1].ex)
> >> assert(rec_stdl[0].st==rec_stdl[1].st)
> >> assert(rec_stdl[0].cp==rec_stdl[1].cp)
> >
> > First: All your asserts are wrong. Assert is a statement, not a
> > function. These specific ones will behave as expected, but it's easy to
> > accidentally write ones that always pass this way.
>
> Could you come up with an example? I can only think of accidentally
> injecting a comma, what would create a (true, in a boolean context) tuple.
>
> And, well, if you're only using () for readabilty, this might sometimes
> look messy when calling assert with the extended syntax::
>
>   assert(False), "error text"
>

It's very easy to write this as assert(False, "error text") if you're
in the habit of thinking that assert is a function.

> Where one could expect the construction of a tuple.
>
> > Secondly: This is a waste of code, because if __debug__ is not defined
> > asserts will be skipped by the compiler. You could use the same loop
> > block for both branches.
>
> Well, the `assert` isn't there for no reason, but if you're serious about
> it, `raise` could be better.
>
> > Thirdly: This sort of testing is precisely what unit tests and/or
> > doctests are for.
>
> Huh? What beginner is doing there seems more like input validation than
> testing. Unit or doctests are meant for testing (and in case of doctests,
> showing) whether a function works as expected.

Not in a big __debug__ block it isn't.

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


Python IMAP web-access

2007-08-01 Thread Damjan
Is there some project that implements web access to an IMAP store?

Maybe something AJAXy like http://roundcube.net/??


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


Re: Strange problems with subprocess

2007-08-01 Thread Michele Petrazzo
[EMAIL PROTECTED] wrote:
> This doesn't look like a complete traceback. It doesn't give what the
>  error was.
> 

Forgot a line, sorry!

exceptions.OSError: [Errno 4] Interrupted system call

> Mike
> 

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


Re: Checking object types

2007-08-01 Thread Alex Popescu
"Robert Dailey" <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> --=_Part_51775_19953536.1185988361742
> Hi,
> 
> I'm currently interested in creating an __add__() operator for one of
> my classes. This class handles both integers and objects its own type,
> however I don't know how I can perform special add operations
> depending on which is passed in. Since I haven't seen any evidence of
> function overloading, I'm assuming I'll have to check the types of the
> variables passed in inside of my __add__() method.
> 
> Take the two following examples:
> 
> vector3(3,4,2) + 5 = vector3(8,9,7)
> vector3(3,2,1) + vector3(4,5,6) = vector3(7,7,7)
> 
> Any tips? Thanks.
> 

That's an option. Another option was posted a while ago by GvR and was 
using some decorator to dispatch to different methods according to the 
type. I don't seem to find the link right now, but you can search it on GvR 
blog.

bests,
./alex
--
.w( the_mindstorm )p.

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


Re: Assertion in list comprehension

2007-08-01 Thread beginner
On Aug 1, 12:35 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Aug 1, 11:28 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> > > On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
>
> > > > Hi,
>
> > > > Does anyone know how to put an assertion in list comprehension? I have
> > > > the following list comprehension, but I want to use an assertion to
> > > > check the contents of rec_stdl. I ended up using another loop which
> > > > essentially duplicates the functions of list comprehension. It just
> > > > look like a waste of coding and computer time to me.
>
> > > > I just wish I could put the assertions into list comprehensions.
>
> > > > x=[(rec_stdl[0].st/1.0,
> > > > rec_stdl[0].cl,
> > > > rec_stdl[0].bb,
> > > > rec_stdl[0].bo,
> > > > rec_stdl[1].bb,
> > > > rec_stdl[1].bo,
> > > > rec_stdl[0].ex
> > > >)
> > > >for rec_stdl in rec_by_ex if len(rec_stdl)==2
> > > > ]
>
> > > > #duplicated loop
> > > > if __debug__:
> > > > for rec_stdl in rec_by_ex:
> > > > l=len(rec_stdl)
> > > > assert(l<=2 and l>0)
> > > > if l==2:
> > > > assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
> > > > assert(rec_stdl[0].ex==rec_stdl[1].ex)
> > > > assert(rec_stdl[0].st==rec_stdl[1].st)
> > > > assert(rec_stdl[0].cp==rec_stdl[1].cp)
>
> > > First: All your asserts are wrong. Assert is a statement, not a
> > > function. These specific ones will behave as expected, but it's easy
> > > to accidentally write ones that always pass this way.
>
> > Do you mean I should not use the parentheses?
>
> Yes.
>
>
>
> > > Secondly: This is a waste of code, because if __debug__ is not defined
> > > asserts will be skipped by the compiler. You could use the same loop
> > > block for both branches.
>
> > I know. My original question was how. Dan suggested to write a checker
> > function.
>
> Use the second block in all cases. In any situation where "if
> __debug__" is False, the asserts are a noop and in fact won't even be
> present in the bytecode.
>
>
>
>
>
> > > Thirdly: This sort of testing is precisely what unit tests and/or
> > > doctests are for.
>
> > Agreed.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

I see. In fact I want to whole block surrounded by __debug__ to be
optimized away in non-debug runs. If the logic of my program is
correct, the asserts are guaranteed to be true, no matter what the
input is. It is not input checking.

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


Re: Assertion in list comprehension

2007-08-01 Thread beginner
On Aug 1, 12:38 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 01 Aug 2007 16:55:53 GMT, Stargaming <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Wed, 01 Aug 2007 11:28:48 -0500, Chris Mellon wrote:
>
> > > On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> > >> Hi,
>
> > >> Does anyone know how to put an assertion in list comprehension? I have
> > >> the following list comprehension, but I want to use an assertion to
> > >> check the contents of rec_stdl. I ended up using another loop which
> > >> essentially duplicates the functions of list comprehension. It just
> > >> look like a waste of coding and computer time to me.
>
> > >> I just wish I could put the assertions into list comprehensions.
>
> > >> x=[(rec_stdl[0].st/1.0,
> > >> rec_stdl[0].cl,
> > >> rec_stdl[0].bb,
> > >> rec_stdl[0].bo,
> > >> rec_stdl[1].bb,
> > >> rec_stdl[1].bo,
> > >> rec_stdl[0].ex
> > >>)
> > >>for rec_stdl in rec_by_ex if len(rec_stdl)==2
> > >> ]
>
> > >> #duplicated loop
> > >> if __debug__:
> > >> for rec_stdl in rec_by_ex:
> > >> l=len(rec_stdl)
> > >> assert(l<=2 and l>0)
> > >> if l==2:
> > >> assert(rec_stdl[0].c=="C" and rec_stdl[1].c=="P")
> > >> assert(rec_stdl[0].ex==rec_stdl[1].ex)
> > >> assert(rec_stdl[0].st==rec_stdl[1].st)
> > >> assert(rec_stdl[0].cp==rec_stdl[1].cp)
>
> > > First: All your asserts are wrong. Assert is a statement, not a
> > > function. These specific ones will behave as expected, but it's easy to
> > > accidentally write ones that always pass this way.
>
> > Could you come up with an example? I can only think of accidentally
> > injecting a comma, what would create a (true, in a boolean context) tuple.
>
> > And, well, if you're only using () for readabilty, this might sometimes
> > look messy when calling assert with the extended syntax::
>
> >   assert(False), "error text"
>
> It's very easy to write this as assert(False, "error text") if you're
> in the habit of thinking that assert is a function.
>
> > Where one could expect the construction of a tuple.
>
> > > Secondly: This is a waste of code, because if __debug__ is not defined
> > > asserts will be skipped by the compiler. You could use the same loop
> > > block for both branches.
>
> > Well, the `assert` isn't there for no reason, but if you're serious about
> > it, `raise` could be better.
>
> > > Thirdly: This sort of testing is precisely what unit tests and/or
> > > doctests are for.
>
> > Huh? What beginner is doing there seems more like input validation than
> > testing. Unit or doctests are meant for testing (and in case of doctests,
> > showing) whether a function works as expected.
>
> Not in a big __debug__ block it isn't.


No I was trying to test the logic of my code not validating the
contents of the data. Thanks.

>
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


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


Re: Assertion in list comprehension

2007-08-01 Thread Chris Mellon
On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> On Aug 1, 12:35 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> > On 8/1/07, beginner <[EMAIL PROTECTED]> wrote:
> >



> I see. In fact I want to whole block surrounded by __debug__ to be
> optimized away in non-debug runs. If the logic of my program is
> correct, the asserts are guaranteed to be true, no matter what the
> input is. It is not input checking.
>

I inferred as much. That's why placing it in a unit or doctest is even better.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where do they tech Python officialy ?

2007-08-01 Thread Bruno Desthuilliers
Alex Popescu a écrit :
> [EMAIL PROTECTED] (Alex Martelli) wrote in news:1i23wyk.avc945i4dwsiN%
> [EMAIL PROTECTED]:
> 
> 
>>NicolasG <[EMAIL PROTECTED]> wrote:
>>   ...
>>
>>>The problem is that I would like to work as a Python programmer but
>>>all the job vacancies I can find requires a couple of years of
>>>professional experience ... that I don't have. How a wanna be
>>>programmer can start working as a programmer if there is no chance to
>>>start from somewhere ? That's the reason I created this topic.
>>
>>Open source projects do not require previous professional experience 
> 
> to
> 
>>accept volunteers.  So, one way out of your dilemma is to make a name
>>for yourself as an open source contributor -- help out with Python
>>itself and/or with any of the many open source projects that use  
>> Python, 
>>and you will both learn a lot _and_ acquire "professional experience"
>>that any enlightened employer will recognize as such.  
> 
> 
> It depends :-). In my experience I met employers being concerned by my 
> implication in the oss world :-).
> 
These are the ones you don't wan't to work for anyway !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Buffering HTML as HTMLParser reads it?

2007-08-01 Thread chrispwd
Hello,

I am working on a project where I'm using python to parse HTML pages,
transforming data between certain tags. Currently the HTMLParser class
is being used for this. In a nutshell, its pretty simple -- I'm
feeding the contents of the HTML page to HTMLParser, then I am
overriding the appropriate handle_ method to handle this extracted
data. In that method, I take the found data and I transform it into
another string based on some logic.

Now, what I would like to do here is take that transformed string and
put it "back into" the HTML document. Has anybody ever implemented
something like this with HTMLParser?

I'm thinking maybe somehow have HTMLParser append each character it
reads except for data inside tags in some kind of buffer? This way I
can have the HTML contents read into a buffer, then when I do my own
handle_ overrides, I can also append to that buffer with the
transformed data. Once the HTML page is finished parsing, ideally I
would be able to print the contents of the buffer and the HTML would
be identical except for the string transformations.

I also need to make sure that all newlines, tags, spacing, etc are
kept in tact -- this part is a requirement for other reasons.

Thanks!

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


Re: Pythonic way for missing dict keys

2007-08-01 Thread John J. Lee
Steve Holden <[EMAIL PROTECTED]> writes:
[...]
> Yup. Anyway there's a trivial translation for uses of apply.
>
> apply(f, *args, **kw) =>  f(*args, **kw)
[...]

Steve means:

apply(f, args, kw) =>  f(*args, **kw)


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


Re: Subprocess and pipe-fork-exec primitive

2007-08-01 Thread Rafael V.
Hi Martin,

   the operating system I'm using is SUSE Linux 10, kernel 2.6.13.

   You're right, I was missing something. After you told me that it
couldn't be Python preforming wait() on SIGCHLD, I decided to
investigate further.

   My application requires access to a Informix database, and uses
informixdb. The problem seems to be related to that module. I wrote a
small piece of code to test it:

---
#!/usr/bin/env python

from os import fork, execl, waitpid
from informixdb import connect

try:
   conf = {}
   conf['dsn'] = '[EMAIL PROTECTED]'
   conf['user'] = 'user'
   conf['password'] = 'password'
   connection = connect(**conf)

except:
   pass

pid = fork()

if pid == 0:
   # Child
   execl("/bin/sh", "/bin/sh", "-c", "true")

# Parent
waitpid(pid, 0)

print pid
---

   If you run the code above multiple times, some runs will trigger
exceptions on the waitpid calls. Commenting the call to
informixdb.connect(), no exceptions are triggered. I am concluding that
informixdb, not Python, is handling the signals and reaping the
subprocesses.

   Now Martin, do you think I can use informixdb.py and subprocess.py in
the same application? I was thinking on forking subprocesses from the
main thread and using other threads to access the Informix database,
would that work?

Thanks,
Rafael.

Martin v. Löwis escreveu:
>>   From my experience, this primitive will fail with 'no child processes'
>> at the waitpid call if the forked child dies very quickly - before the
>> parent is scheduled back for execution. This seems to happen because
>> Python has a default SIGCHLD handler that, in this case, will reap the
>> process before the parent has the chance to do it.
> 
> What operating system is your experience from? On a POSIX system,
> this should not happen - i.e. delivery of SIGCHLD should not cause
> to make the child waited-for. Python itself does not perform wait()
> in response to SIGCHLD.
> 
>>   I would like to know if this is correct, or am I missing something here?
> 
> You must be missing something, although I'm uncertain what precisely
> that is.
> 
> Regards,
> Martin



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


Re: Buffering HTML as HTMLParser reads it?

2007-08-01 Thread Paul McGuire
On Aug 1, 1:31 pm, [EMAIL PROTECTED] wrote:

>
> I'm thinking maybe somehow have HTMLParser append each character it
> reads except for data inside tags in some kind of buffer? This way I
> can have the HTML contents read into a buffer, then when I do my own
> handle_ overrides, I can also append to that buffer with the
> transformed data. Once the HTML page is finished parsing, ideally I
> would be able to print the contents of the buffer and the HTML would
> be identical except for the string transformations.
>
> I also need to make sure that all newlines, tags, spacing, etc are
> kept in tact -- this part is a requirement for other reasons.
>
> Thanks!

What you describe is almost exactly how pyparsing implements
transformString.  See below:

from pyparsing import *

boldStart,boldEnd = makeHTMLTags("B")

# convert  to  and  to 
boldStart.setParseAction(replaceWith(''))
boldEnd.setParseAction(replaceWith(''))
converter = boldStart | boldEnd

html = "Display this in bold"
print converter.transformString(html)

Prints:

Display this in bold

All text not matched by a pattern in the converter is left as-is.  (My
CSS style/form may not be up to date, but I hope you get the idea.)

-- Paul

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


Re: Extending Python by Adding Keywords & Data types

2007-08-01 Thread Maximus Decimus
On Aug 1, 9:08 am, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Jul 31, 3:28 pm, Maximus Decimus <[EMAIL PROTECTED]> wrote:
>
>
>
> > I am using python v2.5 and I am an amateur working on python. I am
> > extending python for my research work and would like some help and
> > guidance w.r.t this matter from you experienced python developers.
>
> > II want to add some more KEYWORDS and DATATYPES into the python script
> > apart from the existing ones.
>
> Vishak -
>
> Let me echo the sentiments of the other posters who replied to your
> message.  It is *very* unusual for a new Python user to begin their
> Pythonic journey by modifying the Python interpreter to add new
> keywords and datatypes.  Python is designed to be a very flexible and
> extensible language just as it is.
>
> Since you are familiar with C, your question strikes those of us on
> this group as one who would write "I'm just learning C and I would
> like to modify the core library to add some new functions for my
> research."  And all the readers on comp.lang.c scratch their heads,
> thinking "Huh?  Why doesn't this guy just write the functions in his
> own program, the way the language was designed for him to do in the
> first place?"
>
> Now maybe your research is in the field of language design, and has
> something to do with the relative ease/difficulty of modifying
> computer languages.  Then it would make sense for you to dive right in
> to learning how to modify Python's compiler.
>
> But if your research was in just about any other field (from finite
> elements analysis to genetic programming to genetics to simulations to
> process control to whatever), DON'T start by modifying Python - start
> by LEARNING Python.
>
> When a new datatype is required in a Python program, then the
> programmer writes a class to implement this datatype.  The class
> itself is written in Python, but it can be used just like any built-in
> datatype.  For instance, here is a new datatype I just thought up - a
> Box that can hold up to 'n' objects.
>
> class Box(object):
> def __init__(self,n):
> self.capacity = n
> self.contents = []
>
> def add(self,other):
> if len(self.contents) < self.capacity:
> self.contents.append( other )
> else:
> raise ValueError("can't add any more to this Box")
>
> def __iadd__(self,other):
> self.add(other)
> return self
>
> box = Box(3)
>
> # add stuff to the box until it overflows
> while(True):
> box += object()
>
> Voila!  I created a new datatype, Box, and even added support for it
> to understand how to use the '+=' operator so that adding objects to
> the Box looks like an addition statement.  All without modifying
> Python itself.  (Here's an exercise - extend this example so that the
> Box has a limited capacity in the *weight* of the added objects, as
> well as in the number of objects.)
>
> This is the basic way that one extends Python with their own new
> datatypes and methods.  New keywords are a little rarer, but really,
> start by just adding methods, like the add method above.  Python users
> around the world develop a wide range of applications and programs
> using just these techniques, and never touch the Python compiler
> itself.
>
> And here is a case you'd like to avoid.  Let's say you start by
> learning how to modify Python because you need a general-purpose
> container for things.  You spend two weeks learning how to do this,
> getting your code mostly debugged, and then you post to
> comp.lang.python your proud achievement.  Immediately the replies come
> back, "Congratulations, newbie, you just reinvented the built-in list
> type."  Without LEARNING Python, you wont know what is already
> provided in the language.
>
> So, in general this is a helpful group, and it is possible that you DO
> need to learn how to add datatypes and keywords to Python as your
> first objective.  We're not trying to pry, but give us a bit more
> detail.  Someone might even rough out for you what one of your new
> datatypes might look like.  So pray, tell us what sort of specialized
> datatypes and keywords do you think you need to add, and we'll try to
> point you in one or more directions.
>
> -- Paul

On Aug 1, 9:08 am, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Jul 31, 3:28 pm, Maximus Decimus <[EMAIL PROTECTED]> wrote:
>
>
>
> > I am using python v2.5 and I am an amateur working on python. I am
> > extending python for my research work and would like some help and
> > guidance w.r.t this matter from you experienced python developers.
>
> > II want to add some more KEYWORDS and DATATYPES into the python script
> > apart from the existing ones.
>
> Vishak -
>
> Let me echo the sentiments of the other posters who replied to your
> message.  It is *very* unusual for a new Python user to begin their
> Pythonic journey by modifying the Python interpreter to add new
> keywords and datatypes.  Python is designed to be a very flexible and
>

Re: Pythonic way for missing dict keys

2007-08-01 Thread Bruno Desthuilliers
John J. Lee a écrit :
> Alex Popescu <[EMAIL PROTECTED]> writes:
> 
> 
>>Zentrader <[EMAIL PROTECTED]> wrote in news:1185041243.323915.161230
>>@x40g2000prg.googlegroups.com:
>>
>>
>>>On Jul 21, 7:48 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
>>>
>>>[snip...]
>>>
>>>
From the 2.6 PEP #361 (looks like dict.has_key is deprecated)
>>>Python 3.0 compatability: ['compatibility'-->someone should use a
>>>spell-checker for 'official' releases]
>>>- warnings were added for the following builtins which no
>>>longer exist in 3.0:
>>> apply, callable, coerce, dict.has_key, execfile, reduce,
>>>reload
>>>
>>
>>I see... what that document doesn't describe is the alternatives to be 
>>used. And I see in that list a couple of functions that are probably used a 
>>lot nowadays (callable, reduce, etc.).
> 
> 
> callable and reduce are rarely used, at least in code I've seen.

I do use callable(). Not everyday, for sure, but still often enough to 
have to reimplement it when I'll switch to Py3K.

And while I rarely use it, I'll regret reduce().

>  I
> would agree there will be a large number of programs that contain one
> or two calls to these functions, though.  Certainly has_key will be
> the most common of those listed above (but trivial to fix).  apply
> will be common in old code from the time of Python 1.5.2.

I still use it (in a somewhat deviant way) to define properties:

class MyClass(object):
   def __init__(self, val):
 self.val = val
   @apply
   def val():
 def fget(self):
   return self._val
 def fset(self, val):
   self._val = val


>  execfile is
> perhaps more common that callable (?) 

Never used it, never saw it used.

> but again is really a "maybe 1
> call in a big program" sort of thing.  Anybody using coerce or reload
> deserves to lose ;-)
> 
> 
> John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way for missing dict keys

2007-08-01 Thread Chris Mellon
On 7/28/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Sat, 28 Jul 2007 11:52:48 +, Alex Popescu wrote:
>
> > [EMAIL PROTECTED] (John J. Lee) wrote in news:[EMAIL PROTECTED]:
> >
> >> Alex Popescu <[EMAIL PROTECTED]> writes:
> >>
> >>> Zentrader <[EMAIL PROTECTED]> wrote in
> >>> news:1185041243.323915.161230 @x40g2000prg.googlegroups.com:
> >>>
>  On Jul 21, 7:48 am, Duncan Booth <[EMAIL PROTECTED]>
>  wrote:
> 
>  [snip...]
> 
> 
> >From the 2.6 PEP #361 (looks like dict.has_key is deprecated)
>  Python 3.0 compatability: ['compatibility'-->someone should use a
>  spell-checker for 'official' releases]
>  - warnings were added for the following builtins which no
>  longer exist in 3.0:
>   apply, callable, coerce, dict.has_key, execfile,
>   reduce,
>  reload
> 
> >>>
> >>> I see... what that document doesn't describe is the alternatives to
> >>> be used. And I see in that list a couple of functions that are
> >>> probably used a lot nowadays (callable, reduce, etc.).
> >>
> >> callable and reduce are rarely used, at least in code I've seen.
> >
> > I thought G would be using that function a lot.
>
> Who or what is G? Guido?
>
> And which of the two functions mentioned is "that function"? callable()?
>
>
> Instead of doing:
>
>
> if callable(function): function()
>
> you should do:
>
> try:
> function()
> except TypeError:
> pass
>
>
> That should work for most uses of callable(), but isn't quite the same.
> (What if function() has side-effects, or is expensive, and you want to
> determine if it is callable, but not actually call it _now_?)
>

It's *really* not the same. Not only does it call the function, which
has all kinds of potential problems like you listed, but this also
will convert TypeErrors in the called function into "this is not a
callable", which is almost certainly not what you want. hasattr(x,
'__call__') works but is annoying to write and hides intent. I'd be
happy if inspect grew iscallable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UK Ordnance survey coordinates and Geocoding anyone ?

2007-08-01 Thread John J. Lee
Ken Starks <[EMAIL PROTECTED]> writes:
[...]
> http://www.magic.gov.uk/ [snip rest of URL...]

Cool, I had no idea we still had a department of magic!

I'll keep my eyes peeled for Mr. Norrell...


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


  1   2   >