Re: ctypes

2010-09-23 Thread Simon Brunning
On 22 September 2010 21:13, jay thompson  wrote:
> Hello,
>
> I posted in regard to this in the past but it didn't go very far, no ones
> fault, but I'm again atempting to make this work and could use some help.
>
> I would like to use libraw.dll (http://www.libraw.org/  version 0.10) from
> python and can access all the functions fine and produce images but there is
> a structure that holds all the process settings that I cannot access with
> ctypes. I'm sure it's because I'm going about it the wrong way. I was
> wondering if there was anyone in this list with experience with this sort of
> thing that could point me in the right direction.

A good start would be to tell us what you've tried, and what goes
wrong when you try it.

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


Re: HTML6 proposal (Re: sexp xml syntax transformation)

2010-09-23 Thread smh
The following is not exactly what you are looking for, but you might
find it interesting.

http://www.franz.com/support/tech_corner/xml-generator-blurb.html

This blurb is an example of a self-embedding document.
I've used this XML generator in many applications, and it is usually
elegant to use the structural parallel between an XML tree and the
Lisp code that generates it.

I haven't thought whether it could be reasonable to port it to
scheme.  Anyone who wants to think about it has my blessing!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Macros's Not the Power in OOo they should be ?

2010-09-23 Thread Boris Borcic

Lawrence D'Oliveiro wrote:

flebber wrote:


Has anyone had much success with python macro's. Or developing powerful
macro's in an language?


I did an application for my own use recently, involving automatically
generating invoices in editable OOWriter format from my billing database. I
gave up on all the PyUNO stuff, and used ODFPY instead—so much easier to
generate ODF directly, without having to go through OpenOffice code.

And OpenOffice has been able to open the results for final tweaking just
fine.


A nice package to manipulate Ooo text documents with python is the pod module of 
the appy framework. It uses the same approach with a twist.



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


Re: HTML6 proposal (Re: sexp xml syntax transformation)

2010-09-23 Thread Xah Lee
On Sep 23, 1:18 am, smh  wrote:
> The following is not exactly what you are looking for, but you might
> find it interesting.
>
> http://www.franz.com/support/tech_corner/xml-generator-blurb.html
>
> This blurb is an example of a self-embedding document.
> I've used this XML generator in many applications, and it is usually
> elegant to use the structural parallel between an XML tree and the
> Lisp code that generates it.

Thanks. Very interesting.

i guess that's like lisp's PHP.

> I haven't thought whether it could be reasonable to port it to
> scheme.  Anyone who wants to think about it has my blessing!

just curious, i can't believe if there's not already something similar
in scheme lisp.

 Xah ∑ xahlee.org ☄
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Macros's Not the Power in OOo they should be ?

2010-09-23 Thread Lawrence D'Oliveiro
In message , Tim Harig wrote:

> The UNO architecture seems to have been rather mishandled. While the
> general idea was nice, the implementation seems to be overly complicated
> and poorly documented.

For an example of a much nicer way of doing things, compare the Python 
support in Blender: it’s a lot easier to get something simple working, and 
there are loads of scripts already written by others that you can refer to.

Of course, they’ve completely reworked the scripting API in 2.5, but I think 
that’s for the better.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Macros's Not the Power in OOo they should be ?

2010-09-23 Thread John Pinner
On Sep 23, 10:12 am, Boris Borcic  wrote:
> Lawrence D'Oliveiro wrote:
> > flebber wrote:
>
> >> Has anyone had much success with python macro's. Or developing powerful
> >> macro's in an language?
>
> > I did an application for my own use recently, involving automatically
> > generating invoices in editable OOWriter format from my billing database. I
> > gave up on all the PyUNO stuff, and used ODFPY instead—so much easier to
> > generate ODF directly, without having to go through OpenOffice code.
>
> > And OpenOffice has been able to open the results for final tweaking just
> > fine.
>
> A nice package to manipulate Ooo text documents with python is the pod module 
> of
> the appy framework. It uses the same approach with a twist.

One of our guys, David Chan, has done something you may find useful,
'OpenDocMill':

http://www.troi.org/opendoc-mill.html

We use it to produce some quite complicated documents, for example
Engineering Reports, Invoices, Certificates.

Best wishes,

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


Scheduling in python

2010-09-23 Thread loial
I want to enable my end users to be able to schedule a task(actually
running another python or shell script). Rather than scheduling it
directly in cron, are there any python modules I could use?

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


Re: lists and list item matches (ghost wodgame)

2010-09-23 Thread nn
On Sep 22, 6:39 pm, Baba  wrote:
> On Sep 22, 9:18 pm, Baba  wrote:
>
>
>
> > On Sep 22, 3:38 pm, nn  wrote:
>
> > > On Sep 21, 6:39 pm, Baba  wrote:
>
> > > > Hi
>
> > > > query level: beginner
>
> > > > as part of a learning exercise i have written code that:
>
> > > > a) asks for a single letter input (assumption: only 1 letter wil be
> > > > entered)
> > > > b) adds that letter to list1 and then goes through list2 and checks:
>
> > > >     1) if any item in list2 starts with list1 > if False: break
> > > >     2) if list1 == any item in list2 > if True: break
>
> > > > c) start again until 2) is True
>
> > > > wordlist = ['hello', 'bye']
> > > > handlist = []
> > > > letter = raw_input('enter letter: ')
> > > > handlist.append(letter)
> > > > hand = "".join(handlist)
> > > > for item in wordlist:
> > > >     if item.startswith(hand):
> > > >         while item.startswith(hand):
> > > >             if hand not in wordlist:
> > > >                 letter = raw_input('enter letter: ')
> > > >                 handlist.append(letter)
> > > >                 hand = "".join(handlist)
> > > >             else: break
> > > >         else: break
> > > > print 'you loose'
>
> > > > this code works but can it be optimised? i have the feeling that my
> > > > nesting of IF, WHILE and FOR statements is overkill?
>
> > > > inspired by part IV 
> > > > ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc...
>
> > > > thanks
> > > > Baba
>
> > > Yes it is overkill. Especially the else:break from the while loop
> > > makes it difficult to follow the logic. Also the program breaks down
> > > if I use the following word list:
>
> > > wordlist = ['hello', 'hamburger', 'bye']
>
> > > enter letter: h
> > > enter letter: a
> > > you loose
>
> > > I am not going to post any spoilers but I wrote your program using one
> > > while loop and one generator expression for a total of 5 lines. My
> > > version might be a bit too advanced but you should still be able to do
> > > it using only one while, one for and one if instead.
>
> > Hi nn,
>
> > i wasn't expecting my code to fail with an additional word in it.
> > While i was conscious that the whole construct was heavy i thought the
> > reasoning worked. I keep looking at it but can't figure out the
> > problem Can you give me a hint?
>
> > In the meantime i found out that it is actually possible to populate a
> > string (just like a list, a dictionary or a tuple). Here's what i've
> > got now:
>
> > wordlist = ['hello', 'bye']
> > hand = ''
> > for item in wordlist:
> >     if item.startswith(hand):
> >         while item.startswith(hand):
> >             if hand not in wordlist:
> >                 hand += raw_input('enter letter: ')
> >                 print hand
> >             else: break
> >         else: break
> > print 'you loose'
>
> > But i can't figure out why it won't work when adding the extra word.
> > Thanks by the way, it taught me not to be too confident when things
> > SEEM to work...
>
> > Why does it work when i use the built-in function any(iterable)?? To
> > me using the any(iterable) function seems just like regrouping 3 lines
> > into one...
>
> > wordlist = ['hello','hamburger', 'bye', 'cello']
> > hand = ''
> > while any(item.startswith(hand) for item in wordlist):
> >     if hand not in wordlist:
> >         hand += raw_input('enter letter: ')
> >     else: break
> > print 'you loose'
>
> > thanks
>
> > Baba
>
> Hi nn,
>
> looking at my original code again i realise that having a raw_input
> inside a FOR loop is flawed per se (at least for my purposes) so i
> will just assume that i was taking the wrong approach initially. No
> point in analysing it further. Thanks for your help.
>
> Baba

Since you seem to have figured it out I will post my version (python
3):

wordlist = ['hello', 'hamburger', 'bye']
inp=''
while any(word.startswith(inp) and word!=inp for word in wordlist):
inp += input('enter letter: ')
print('you lose')

The reason why your original version didn't work was because each time
you add a letter you have to go again over all words (in reality only
a subset is required) and find a new one. Your version would find one
word using the first letter and then exit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lists and list item matches (ghost wodgame)

2010-09-23 Thread nn
On Sep 23, 10:56 am, nn  wrote:
> On Sep 22, 6:39 pm, Baba  wrote:
>
>
>
> > On Sep 22, 9:18 pm, Baba  wrote:
>
> > > On Sep 22, 3:38 pm, nn  wrote:
>
> > > > On Sep 21, 6:39 pm, Baba  wrote:
>
> > > > > Hi
>
> > > > > query level: beginner
>
> > > > > as part of a learning exercise i have written code that:
>
> > > > > a) asks for a single letter input (assumption: only 1 letter wil be
> > > > > entered)
> > > > > b) adds that letter to list1 and then goes through list2 and checks:
>
> > > > >     1) if any item in list2 starts with list1 > if False: break
> > > > >     2) if list1 == any item in list2 > if True: break
>
> > > > > c) start again until 2) is True
>
> > > > > wordlist = ['hello', 'bye']
> > > > > handlist = []
> > > > > letter = raw_input('enter letter: ')
> > > > > handlist.append(letter)
> > > > > hand = "".join(handlist)
> > > > > for item in wordlist:
> > > > >     if item.startswith(hand):
> > > > >         while item.startswith(hand):
> > > > >             if hand not in wordlist:
> > > > >                 letter = raw_input('enter letter: ')
> > > > >                 handlist.append(letter)
> > > > >                 hand = "".join(handlist)
> > > > >             else: break
> > > > >         else: break
> > > > > print 'you loose'
>
> > > > > this code works but can it be optimised? i have the feeling that my
> > > > > nesting of IF, WHILE and FOR statements is overkill?
>
> > > > > inspired by part IV 
> > > > > ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc...
>
> > > > > thanks
> > > > > Baba
>
> > > > Yes it is overkill. Especially the else:break from the while loop
> > > > makes it difficult to follow the logic. Also the program breaks down
> > > > if I use the following word list:
>
> > > > wordlist = ['hello', 'hamburger', 'bye']
>
> > > > enter letter: h
> > > > enter letter: a
> > > > you loose
>
> > > > I am not going to post any spoilers but I wrote your program using one
> > > > while loop and one generator expression for a total of 5 lines. My
> > > > version might be a bit too advanced but you should still be able to do
> > > > it using only one while, one for and one if instead.
>
> > > Hi nn,
>
> > > i wasn't expecting my code to fail with an additional word in it.
> > > While i was conscious that the whole construct was heavy i thought the
> > > reasoning worked. I keep looking at it but can't figure out the
> > > problem Can you give me a hint?
>
> > > In the meantime i found out that it is actually possible to populate a
> > > string (just like a list, a dictionary or a tuple). Here's what i've
> > > got now:
>
> > > wordlist = ['hello', 'bye']
> > > hand = ''
> > > for item in wordlist:
> > >     if item.startswith(hand):
> > >         while item.startswith(hand):
> > >             if hand not in wordlist:
> > >                 hand += raw_input('enter letter: ')
> > >                 print hand
> > >             else: break
> > >         else: break
> > > print 'you loose'
>
> > > But i can't figure out why it won't work when adding the extra word.
> > > Thanks by the way, it taught me not to be too confident when things
> > > SEEM to work...
>
> > > Why does it work when i use the built-in function any(iterable)?? To
> > > me using the any(iterable) function seems just like regrouping 3 lines
> > > into one...
>
> > > wordlist = ['hello','hamburger', 'bye', 'cello']
> > > hand = ''
> > > while any(item.startswith(hand) for item in wordlist):
> > >     if hand not in wordlist:
> > >         hand += raw_input('enter letter: ')
> > >     else: break
> > > print 'you loose'
>
> > > thanks
>
> > > Baba
>
> > Hi nn,
>
> > looking at my original code again i realise that having a raw_input
> > inside a FOR loop is flawed per se (at least for my purposes) so i
> > will just assume that i was taking the wrong approach initially. No
> > point in analysing it further. Thanks for your help.
>
> > Baba
>
> Since you seem to have figured it out I will post my version (python
> 3):
>
> wordlist = ['hello', 'hamburger', 'bye']
> inp=''
> while any(word.startswith(inp) and word!=inp for word in wordlist):
>     inp += input('enter letter: ')
> print('you lose')
>
> The reason why your original version didn't work was because each time
> you add a letter you have to go again over all words (in reality only
> a subset is required) and find a new one. Your version would find one
> word using the first letter and then exit.

Actually my version isn't right (for some values of right):

wordlist = ['hello', 'hamburger', 'bye']
inp=''
while any(word.startswith(inp) for word in wordlist) and (inp not in
wordlist):
inp += input('enter letter: ')
print('you lose')

An explanation of how this changes the rules of the wordgame is left
as an exercise to the reader.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Check whether file is being written to

2010-09-23 Thread Seebs
On 2010-09-23, loial  wrote:
> How can I check whether a file is being written to by another process
> before I access it?

You mean "written to" or "open for possible writing"?

It may be possible (with sufficient privileges) to determine that a
file has been opened for writing.  I don't think you can detect
being-written-to.

More importantly, though, the question is irrelevant, because even if
you absolutely, conclusively, prove that a file is not open nor being
written to, before your next machine instruction loads, the file could
be opened and rewritten multiple times by whole new processes that weren't
even running when you checked.

I suggest you look into advisory locks.

-s
-- 
Copyright 2010, all wrongs reversed.  Peter Seebach / [email protected]
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Check whether file is being written to

2010-09-23 Thread Thomas Jollans
On Thursday 23 September 2010, it occurred to loial to exclaim:
> How can I check whether a file is being written to by another process
> before I access it?
> 
> Platform is unix.

As such, you can't. But you can lock the file using the functions in the fcntl 
module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scheduling in python

2010-09-23 Thread Thomas Jollans
On Thursday 23 September 2010, it occurred to loial to exclaim:
> I want to enable my end users to be able to schedule a task(actually
> running another python or shell script). Rather than scheduling it
> directly in cron, are there any python modules I could use?

If you have a "master" process running -- it strongly depends on how that 
process is structured. Is there a main loop? What does it look like? Is it 
provided by some toolkit? Maybe that toolkit has an alarm event?
In the end, there isn't much too it: periodically check if "it's time", and 
then possibly do something.
I doubt there's a package to do this. The basics are trivial to implement, and 
everything depends strongly on the program structure, which could vary 
greatly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Distributing Packages

2010-09-23 Thread Greg Lindstrom
I am not intending to start anything, here, but would like to know if any
consensus has been reached in how to distribute Python modules.
Specifically, I'd like to use something to install packages on various
machines in our enterprise (mostly Linux, but some windows boxes, too).
I've read up on distutils, but also recall hearing about Python eggs and
sitting in on a talk or two at PyCon (US) that seemed to indicate that the
community was in a state of flux over how to distribute things.  What are
the current thoughts on the subject?

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


Re: Too much code - slicing

2010-09-23 Thread Andreas Waldenburger
On 23 Sep 2010 03:54:52 GMT Seebs  wrote:

> On 2010-09-23, Steven D'Aprano 
> wrote:
> [snip]
> > I don't see anyone bitching about:
> 
> > for x in seq:
> > if x:
> > f(x)
> 
> > vs 
> 
> > [f(x) for x in seq if x]
> 
> In my case, that's because I only ran into that syntax about an hour
> and a half ago.  I have the same basic objection to it.  If it were:
> 
> [for x in seq: if x: f(x)]
> 
> I'd find it substantially easier to understand.
> 
> I don't generally like constructs where important structural
> information comes late in the construct. [snip]

I think that is precisely the reason that the elements of the list come
*first* in the list comprehension expression. The foremost idea of list
comprehensions is "build a list", while the idea of a for-loop is
"iterate over something".

/W

-- 
INVALID? DE!

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


Re: Too much code - slicing

2010-09-23 Thread Andreas Waldenburger
On 23 Sep 2010 00:33:28 GMT Steven D'Aprano
 wrote:

> On Tue, 21 Sep 2010 12:26:29 -0400, Andreas Waldenburger wrote:
> 
> > On Sat, 18 Sep 2010 19:09:33 -0700 (PDT) Carl Banks
> >  wrote:
> > 
> >> On Sep 17, 1:01 pm, Andreas Waldenburger 
> >> wrote:
> >> > On Thu, 16 Sep 2010 16:20:33 -0400 AK 
> >> > wrote:
> >> >
> >> > > I also like this construct that works, I think, since 2.6:
> >> >
> >> > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)]
> >> >
> >> > I wonder when this construct will finally start to look good.
> >> 
> >> I don't know if it'll ever look good, per se, but it looks better
> >> when it's used in rule-exception sort of case:
> >> 
> >> something = rule if condition else exception
> >> 
> > Spot on. I (more or less) like it when used that way, too. But it
> > seems to invite crackers like the example above, and that irks me.
> 
> 
> I don't see that one of these is more of a cracker than the other:
> 
> 
> code = if side == 'l' then dir[int(num):] else dir[:-1*int(num)]
> code = side == 'l' if dir[int(num):] else dir[:-1*int(num)]
> code = dir[int(num):] if side == 'l' else dir[:-1*int(num)]
> 
> 
> If you ask me, the *least* hard to read is the last.
> 
I agree again. I wasn't really talking about the specific order of the
ternary operator but rather about the whole idea. It invites messiness.

/W


-- 
INVALID? DE!

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


Re: Too much code - slicing

2010-09-23 Thread Andreas Waldenburger
On Wed, 22 Sep 2010 20:45:55 -0500 John Bokma 
wrote:

> What surprises me is that this is still discussed. It's like argueing
> about significant whitespace. :-)

Which is evil!

/W

-- 
INVALID? DE!

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


Re: Playing sounds at time indexes

2010-09-23 Thread Thomas Jollans
On Wednesday 22 September 2010, it occurred to OKB (not okblacke) to exclaim:
>   I'm looking for an audio library for Python.  I googled and found a
> few, but none of them seem to have a simple way to play a particular
> sound file from a particular start-time to an end-time.  Like, I'd want
> to load a file and say "Play the section of this file from 10.25 seconds
> to 11.73 seconds."  Is there a library that makes this easy in Python?

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


Re: Too much code - slicing

2010-09-23 Thread Seebs
On 2010-09-23, Andreas Waldenburger  wrote:
> On 23 Sep 2010 03:54:52 GMT Seebs  wrote:
>> I don't generally like constructs where important structural
>> information comes late in the construct. [snip]

> I think that is precisely the reason that the elements of the list come
> *first* in the list comprehension expression. The foremost idea of list
> comprehensions is "build a list", while the idea of a for-loop is
> "iterate over something".

Interesting!  I tend to think of "building a list" as more like a for loop
than like a data item with a qualifier.  If the first word inside the
[] were "for", that would tell me that the list was going to have some kind
of looping or generating going on, while if it's an expression, especially
a complicated expression, I don't know that right away.

But I can see it making sense either way for the loop, just because of
the similarity to mathematical notation.

-s
-- 
Copyright 2010, all wrongs reversed.  Peter Seebach / [email protected]
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scheduling in python

2010-09-23 Thread Paul Rudin
loial  writes:

> I want to enable my end users to be able to schedule a task(actually
> running another python or shell script). Rather than scheduling it
> directly in cron, are there any python modules I could use?

First hit when googling "python schedule"?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Check whether file is being written to

2010-09-23 Thread Diez B. Roggisch
Thomas Jollans  writes:

> On Thursday 23 September 2010, it occurred to loial to exclaim:
>> How can I check whether a file is being written to by another process
>> before I access it?
>> 
>> Platform is unix.
>
> As such, you can't. But you can lock the file using the functions in the 
> fcntl 
> module.

Last time I checked, file-locking in unix was co-operative.

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


Re: Playing sounds at time indexes

2010-09-23 Thread Burton Samograd
"OKB (not okblacke)"  writes:
>   I'm looking for an audio library for Python.  I googled and found a 
> few, but none of them seem to have a simple way to play a particular 
> sound file from a particular start-time to an end-time.  Like, I'd want 
> to load a file and say "Play the section of this file from 10.25 seconds 
> to 11.73 seconds."  Is there a library that makes this easy in Python?

You might want to check out this question on StackOverflow:

http://stackoverflow.com/questions/108848/python-music-library


--
Burton Samograd

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


collections.namedtuple: conflicting instances?

2010-09-23 Thread David A. Barrett
 I've noticed that it's possible to create conflicting instances of the 
collections.namedtuple class:


  from collections  import namedtuple as nt
  IX = nt('X', 'a b')
  IY = nt('Y', 'c d')
  x = IX(0, 1)
  y = IY(2, 3)

The above are non-conflicting class instances and of two distinct 
namedtuple classes and distinct instances of those classes, but what 
happens with this?


  IX2 = nt('X', 'g')
  z = IX2(10)

It looks like IX and IX2 are two distinct classes, which makes sense, 
but what is the classname parameter passed to the constructor used for?  
Is it an error to construct two distinct classes with the same value?


I was wondering if it's useful to allow duplicate (consistant) 
constructions, but have them simply return the same class instance.  
Should inconsistant constructions with the same name raise and exception?

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


Re: Subprocess does not return for longer-running process

2010-09-23 Thread Nobody
On Thu, 23 Sep 2010 12:25:53 +1200, Lawrence D'Oliveiro wrote:

>> And I can't think of any reason why you should use os.waitpid() or
>> similar; use the .wait() method.
> 
> I have used WNOHANG to poll for completion of a subprocess while providing 
> progress updates to the user.

This can be done via the .poll() method.

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


Parsing error for ConfigParser

2010-09-23 Thread Andrew Z.
Is there a way to parse RealPlayer's realplayerrc in Python?  I need
to support Python 2.5 - 2.7

Example code

import urllib2
import ConfigParser
f = urllib2.urlopen('http://pastebin.com/download.php?i=N1AcUg3w')
config = ConfigParser.RawConfigParser()
config.readfp(f)


Error
Traceback (most recent call last):
  File "test_config_parser_real_player.py", line 6, in 
config.readfp(f)
  File "/usr/lib/python2.6/ConfigParser.py", line 305, in readfp
self._read(fp, filename)
  File "/usr/lib/python2.6/ConfigParser.py", line 510, in _read
raise e
ConfigParser.ParsingError: File contains parsing errors: 
[line 31]: '%0aCopyright (c) 1995-2000 Macromedia, Inc. All
rights reserved.\r\n'
[line 34]: '%0a\r\n'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Check whether file is being written to

2010-09-23 Thread Nobody
On Thu, 23 Sep 2010 17:55:52 +0200, Diez B. Roggisch wrote:

> Last time I checked, file-locking in unix was co-operative.

Linux supports mandatory locking, but it's seldom enabled.

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


Re: lists and list item matches (ghost wodgame)

2010-09-23 Thread Baba
On Sep 23, 4:17 pm, nn  wrote:
> On Sep 23, 10:56 am, nn  wrote:
>
>
>
> > On Sep 22, 6:39 pm, Baba  wrote:
>
> > > On Sep 22, 9:18 pm, Baba  wrote:
>
> > > > On Sep 22, 3:38 pm, nn  wrote:
>
> > > > > On Sep 21, 6:39 pm, Baba  wrote:
>
> > > > > > Hi
>
> > > > > > query level: beginner
>
> > > > > > as part of a learning exercise i have written code that:
>
> > > > > > a) asks for a single letter input (assumption: only 1 letter wil be
> > > > > > entered)
> > > > > > b) adds that letter to list1 and then goes through list2 and checks:
>
> > > > > >     1) if any item in list2 starts with list1 > if False: break
> > > > > >     2) if list1 == any item in list2 > if True: break
>
> > > > > > c) start again until 2) is True
>
> > > > > > wordlist = ['hello', 'bye']
> > > > > > handlist = []
> > > > > > letter = raw_input('enter letter: ')
> > > > > > handlist.append(letter)
> > > > > > hand = "".join(handlist)
> > > > > > for item in wordlist:
> > > > > >     if item.startswith(hand):
> > > > > >         while item.startswith(hand):
> > > > > >             if hand not in wordlist:
> > > > > >                 letter = raw_input('enter letter: ')
> > > > > >                 handlist.append(letter)
> > > > > >                 hand = "".join(handlist)
> > > > > >             else: break
> > > > > >         else: break
> > > > > > print 'you loose'
>
> > > > > > this code works but can it be optimised? i have the feeling that my
> > > > > > nesting of IF, WHILE and FOR statements is overkill?
>
> > > > > > inspired by part IV 
> > > > > > ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc...
>
> > > > > > thanks
> > > > > > Baba
>
> > > > > Yes it is overkill. Especially the else:break from the while loop
> > > > > makes it difficult to follow the logic. Also the program breaks down
> > > > > if I use the following word list:
>
> > > > > wordlist = ['hello', 'hamburger', 'bye']
>
> > > > > enter letter: h
> > > > > enter letter: a
> > > > > you loose
>
> > > > > I am not going to post any spoilers but I wrote your program using one
> > > > > while loop and one generator expression for a total of 5 lines. My
> > > > > version might be a bit too advanced but you should still be able to do
> > > > > it using only one while, one for and one if instead.
>
> > > > Hi nn,
>
> > > > i wasn't expecting my code to fail with an additional word in it.
> > > > While i was conscious that the whole construct was heavy i thought the
> > > > reasoning worked. I keep looking at it but can't figure out the
> > > > problem Can you give me a hint?
>
> > > > In the meantime i found out that it is actually possible to populate a
> > > > string (just like a list, a dictionary or a tuple). Here's what i've
> > > > got now:
>
> > > > wordlist = ['hello', 'bye']
> > > > hand = ''
> > > > for item in wordlist:
> > > >     if item.startswith(hand):
> > > >         while item.startswith(hand):
> > > >             if hand not in wordlist:
> > > >                 hand += raw_input('enter letter: ')
> > > >                 print hand
> > > >             else: break
> > > >         else: break
> > > > print 'you loose'
>
> > > > But i can't figure out why it won't work when adding the extra word.
> > > > Thanks by the way, it taught me not to be too confident when things
> > > > SEEM to work...
>
> > > > Why does it work when i use the built-in function any(iterable)?? To
> > > > me using the any(iterable) function seems just like regrouping 3 lines
> > > > into one...
>
> > > > wordlist = ['hello','hamburger', 'bye', 'cello']
> > > > hand = ''
> > > > while any(item.startswith(hand) for item in wordlist):
> > > >     if hand not in wordlist:
> > > >         hand += raw_input('enter letter: ')
> > > >     else: break
> > > > print 'you loose'
>
> > > > thanks
>
> > > > Baba
>
> > > Hi nn,
>
> > > looking at my original code again i realise that having a raw_input
> > > inside a FOR loop is flawed per se (at least for my purposes) so i
> > > will just assume that i was taking the wrong approach initially. No
> > > point in analysing it further. Thanks for your help.
>
> > > Baba
>
> > Since you seem to have figured it out I will post my version (python
> > 3):
>
> > wordlist = ['hello', 'hamburger', 'bye']
> > inp=''
> > while any(word.startswith(inp) and word!=inp for word in wordlist):
> >     inp += input('enter letter: ')
> > print('you lose')
>
> > The reason why your original version didn't work was because each time
> > you add a letter you have to go again over all words (in reality only
> > a subset is required) and find a new one. Your version would find one
> > word using the first letter and then exit.
>
> Actually my version isn't right (for some values of right):
>
> wordlist = ['hello', 'hamburger', 'bye']
> inp=''
> while any(word.startswith(inp) for word in wordlist) and (inp not in
> wordlist):
>     inp += input('enter letter: ')
> print('you lose')
>
> An explanation of how this changes the rules of the wo

Re: collections.namedtuple: conflicting instances?

2010-09-23 Thread Chris Rebert
On Thu, Sep 23, 2010 at 9:28 AM, David A. Barrett  wrote:
>  I've noticed that it's possible to create conflicting instances of the
> collections.namedtuple class:
>
>  from collections  import namedtuple as nt
>  IX = nt('X', 'a b')
>  IY = nt('Y', 'c d')
>  x = IX(0, 1)
>  y = IY(2, 3)
>
> The above are non-conflicting class instances and of two distinct namedtuple
> classes and distinct instances of those classes, but what happens with this?
>
>  IX2 = nt('X', 'g')
>  z = IX2(10)
>
> It looks like IX and IX2 are two distinct classes, which makes sense, but
> what is the classname parameter passed to the constructor used for?

Documentation for human readers (the .__name__ class attribute). As
your example shows, the name you pass in doesn't have to match the
name you assign the resulting class to and actually use (i.e. "X" vs.
"IX"); it's rather like how you were able to use "nt" instead of
"namedtuple".

> Is it
> an error to construct two distinct classes with the same value?

Of course not. Otherwise, classes would have to have *globally unique*
names, and stuff like the following wouldn't be possible (which would
be bad):

# mechanical.py
class Engineer(object):
'''Models a mechanical engineer.'''
# ...

# trains.py
class Engineer(object):
'''Models a person who drives a train.'''
# ...

# main.py
# Models a train company and associated repair yard.
import mechanical
import trains
# ...

> Should
> inconsistant constructions with the same name raise and exception?

Probably not (see answer to previous sentence); showing a warning
/might/ be appropriate.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: collections.namedtuple: conflicting instances?

2010-09-23 Thread nn
On Sep 23, 1:40 pm, Chris Rebert  wrote:
> On Thu, Sep 23, 2010 at 9:28 AM, David A. Barrett  
> wrote:
>
>
>
> >  I've noticed that it's possible to create conflicting instances of the
> > collections.namedtuple class:
>
> >  from collections  import namedtuple as nt
> >  IX = nt('X', 'a b')
> >  IY = nt('Y', 'c d')
> >  x = IX(0, 1)
> >  y = IY(2, 3)
>
> > The above are non-conflicting class instances and of two distinct namedtuple
> > classes and distinct instances of those classes, but what happens with this?
>
> >  IX2 = nt('X', 'g')
> >  z = IX2(10)
>
> > It looks like IX and IX2 are two distinct classes, which makes sense, but
> > what is the classname parameter passed to the constructor used for?
>
> Documentation for human readers (the .__name__ class attribute). As
> your example shows, the name you pass in doesn't have to match the
> name you assign the resulting class to and actually use (i.e. "X" vs.
> "IX"); it's rather like how you were able to use "nt" instead of
> "namedtuple".
>
> > Is it
> > an error to construct two distinct classes with the same value?
>
> Of course not. Otherwise, classes would have to have *globally unique*
> names, and stuff like the following wouldn't be possible (which would
> be bad):
>
> # mechanical.py
> class Engineer(object):
>     '''Models a mechanical engineer.'''
>     # ...
>
> # trains.py
> class Engineer(object):
>     '''Models a person who drives a train.'''
>     # ...
>
> # main.py
> # Models a train company and associated repair yard.
> import mechanical
> import trains
> # ...
>
> > Should
> > inconsistant constructions with the same name raise and exception?
>
> Probably not (see answer to previous sentence); showing a warning
> /might/ be appropriate.
>
> Cheers,
> Chris
> --http://blog.rebertia.com

This parallels another wrinkle:

>>> A=type('X',(),{'a':''})
>>> B=type('X',(),{'z':''})
>>> A

>>> B

>>> i=A()
>>> j=B()
>>> i
<__main__.X object at 0x013A63F0>
>>> j
<__main__.X object at 0x013A6ED0>
>>> dir(i)
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__',
'__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a']
>>> dir(j)
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__',
'__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'z']
>>>

The first parameter to type and namedtuple looks redundant to me.

class A: pass

should be the equivalent to

A=type((),{})

my guess is that it has to do with Python's internals: the function
probably has no way to know what variable name it is being assigned to
and anonymous classes are not wanted.
-- 
http://mail.python.org/mailman/listinfo/python-list


upload file using post to https server

2010-09-23 Thread cerr
hi,

I've been unsucessfully trying to upload a file using POST to an https
server.
I've succesfully logged in and gotten to read something from the
server..
I have come up with something like this:

authinfo = urllib2.HTTPBasicAuthHandler()

authinfo.add_password(realm='Configuration Software',
uri=url,
user='admin',
passwd='**')

opener = urllib2.build_opener(authinfo)
pagePtr = opener.open(url)

dataRead = str(pagePtr.read())

#Look for 'Software Upload' in the page
if( "Software Upload" in dataRead ):
  print "FOUND Software Upload in string..."
else:
  print "Software Upload page not found.  Exiting..."
  sys.exit()

values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' }

try:
data = urllib.urlencode( values )
req = urllib2.Request( url, data )
#response = urllib2.urlopen( req )
response = opener.open( req )

the_page = response.read()
#print the_page

except Exception,detail:
print "err ",detail

#Look for 'file must be efs' in the page
if( "file must be efs" in the_page ):
  print "file must be efs.  Exiting..."
  sys.exit()
else:
  print "OK"

But the file doesn't seem to get there correctly. What I wanna do, is
mocking the upload from the html site with my python script the
html looks something like this:


  

Thanks for your hints and suggestions on how I have to go about this!

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


Re: lists and list item matches (ghost wodgame)

2010-09-23 Thread nn
On Sep 23, 1:25 pm, Baba  wrote:
> On Sep 23, 4:17 pm, nn  wrote:
>
>
>
> > On Sep 23, 10:56 am, nn  wrote:
>
> > > On Sep 22, 6:39 pm, Baba  wrote:
>
> > > > On Sep 22, 9:18 pm, Baba  wrote:
>
> > > > > On Sep 22, 3:38 pm, nn  wrote:
>
> > > > > > On Sep 21, 6:39 pm, Baba  wrote:
>
> > > > > > > Hi
>
> > > > > > > query level: beginner
>
> > > > > > > as part of a learning exercise i have written code that:
>
> > > > > > > a) asks for a single letter input (assumption: only 1 letter wil 
> > > > > > > be
> > > > > > > entered)
> > > > > > > b) adds that letter to list1 and then goes through list2 and 
> > > > > > > checks:
>
> > > > > > >     1) if any item in list2 starts with list1 > if False: break
> > > > > > >     2) if list1 == any item in list2 > if True: break
>
> > > > > > > c) start again until 2) is True
>
> > > > > > > wordlist = ['hello', 'bye']
> > > > > > > handlist = []
> > > > > > > letter = raw_input('enter letter: ')
> > > > > > > handlist.append(letter)
> > > > > > > hand = "".join(handlist)
> > > > > > > for item in wordlist:
> > > > > > >     if item.startswith(hand):
> > > > > > >         while item.startswith(hand):
> > > > > > >             if hand not in wordlist:
> > > > > > >                 letter = raw_input('enter letter: ')
> > > > > > >                 handlist.append(letter)
> > > > > > >                 hand = "".join(handlist)
> > > > > > >             else: break
> > > > > > >         else: break
> > > > > > > print 'you loose'
>
> > > > > > > this code works but can it be optimised? i have the feeling that 
> > > > > > > my
> > > > > > > nesting of IF, WHILE and FOR statements is overkill?
>
> > > > > > > inspired by part IV 
> > > > > > > ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc...
>
> > > > > > > thanks
> > > > > > > Baba
>
> > > > > > Yes it is overkill. Especially the else:break from the while loop
> > > > > > makes it difficult to follow the logic. Also the program breaks down
> > > > > > if I use the following word list:
>
> > > > > > wordlist = ['hello', 'hamburger', 'bye']
>
> > > > > > enter letter: h
> > > > > > enter letter: a
> > > > > > you loose
>
> > > > > > I am not going to post any spoilers but I wrote your program using 
> > > > > > one
> > > > > > while loop and one generator expression for a total of 5 lines. My
> > > > > > version might be a bit too advanced but you should still be able to 
> > > > > > do
> > > > > > it using only one while, one for and one if instead.
>
> > > > > Hi nn,
>
> > > > > i wasn't expecting my code to fail with an additional word in it.
> > > > > While i was conscious that the whole construct was heavy i thought the
> > > > > reasoning worked. I keep looking at it but can't figure out the
> > > > > problem Can you give me a hint?
>
> > > > > In the meantime i found out that it is actually possible to populate a
> > > > > string (just like a list, a dictionary or a tuple). Here's what i've
> > > > > got now:
>
> > > > > wordlist = ['hello', 'bye']
> > > > > hand = ''
> > > > > for item in wordlist:
> > > > >     if item.startswith(hand):
> > > > >         while item.startswith(hand):
> > > > >             if hand not in wordlist:
> > > > >                 hand += raw_input('enter letter: ')
> > > > >                 print hand
> > > > >             else: break
> > > > >         else: break
> > > > > print 'you loose'
>
> > > > > But i can't figure out why it won't work when adding the extra word.
> > > > > Thanks by the way, it taught me not to be too confident when things
> > > > > SEEM to work...
>
> > > > > Why does it work when i use the built-in function any(iterable)?? To
> > > > > me using the any(iterable) function seems just like regrouping 3 lines
> > > > > into one...
>
> > > > > wordlist = ['hello','hamburger', 'bye', 'cello']
> > > > > hand = ''
> > > > > while any(item.startswith(hand) for item in wordlist):
> > > > >     if hand not in wordlist:
> > > > >         hand += raw_input('enter letter: ')
> > > > >     else: break
> > > > > print 'you loose'
>
> > > > > thanks
>
> > > > > Baba
>
> > > > Hi nn,
>
> > > > looking at my original code again i realise that having a raw_input
> > > > inside a FOR loop is flawed per se (at least for my purposes) so i
> > > > will just assume that i was taking the wrong approach initially. No
> > > > point in analysing it further. Thanks for your help.
>
> > > > Baba
>
> > > Since you seem to have figured it out I will post my version (python
> > > 3):
>
> > > wordlist = ['hello', 'hamburger', 'bye']
> > > inp=''
> > > while any(word.startswith(inp) and word!=inp for word in wordlist):
> > >     inp += input('enter letter: ')
> > > print('you lose')
>
> > > The reason why your original version didn't work was because each time
> > > you add a letter you have to go again over all words (in reality only
> > > a subset is required) and find a new one. Your version would find one
> > > word using the first letter and then exit.
>
> > Actually 

Re: ctypes

2010-09-23 Thread jay thompson
My apologies! I worte the email while doing 3 other things.

I haven't really tried anything to access this struct other than trying to
find different elements with ctypes.c_int.in_dll(dll, 'symbol') and access
the elements in the same way I do in C. I didn't think either of these would
work but hoped I would get some type of return that would give me a little
more info.

I have been using a cli to access the library from python and would just
send the image data via stdin and the parameters of the struct as command
line args. From C the struct is easily accessible through the class instance
(libraw::imgdata) and I tried similar variations with ctypes but just get
'function not found'. Makes sense though.

this works:

lr = ctypes.cdll.LoadLibrary(libraw)

handle = lr.libraw_init(0)

lr.libraw_open_buffer(handle, buf, len(buf)) # buf is an image read by
python
lr.libraw_unpack(handle, buf, len(buf))

# imgdata attampt. returns  "function 'imgdata' not found"
#lr.imgdata.params.bright(2)

lr.libraw_dcraw_process(handle)
lr.libraw_dcraw_ppm_tiff_writer(handle,'test.ppm')
lr.libraw_close(handle)



These are the 'exposed' functions, if that is the right term, and will
produce an rgb image. There are a few other functions but they are not
important atm.

I know I don't know what I'm doing with this but it will be worth it if I
can struggle through. Is there a way I can access this struct via python?
Alternatively I could also write a new function in libraw that can access
this struct and be exposed to ctypes.

jt



On Thu, Sep 23, 2010 at 12:28 AM, Simon Brunning
wrote:

> On 22 September 2010 21:13, jay thompson 
> wrote:
> > Hello,
> >
> > I posted in regard to this in the past but it didn't go very far, no ones
> > fault, but I'm again atempting to make this work and could use some help.
> >
> > I would like to use libraw.dll (http://www.libraw.org/  version 0.10)
> from
> > python and can access all the functions fine and produce images but there
> is
> > a structure that holds all the process settings that I cannot access with
> > ctypes. I'm sure it's because I'm going about it the wrong way. I was
> > wondering if there was anyone in this list with experience with this sort
> of
> > thing that could point me in the right direction.
>
> A good start would be to tell us what you've tried, and what goes
> wrong when you try it.
>
> --
> Cheers,
> Simon B.
>



-- 
"It's quite difficult to remind people that all this stuff was here for a
million years before people. So the idea that we are required to manage it
is ridiculous. What we are having to manage is us."   ...Bill Ballantine,
marine biologist.




-- 
"It's quite difficult to remind people that all this stuff was here for a
million years before people. So the idea that we are required to manage it
is ridiculous. What we are having to manage is us."   ...Bill Ballantine,
marine biologist.
-- 
http://mail.python.org/mailman/listinfo/python-list


Raw Sockets - IP-Encapsulation

2010-09-23 Thread Matthias Guentert
Hello list members

I would like to create an IP tunnel using the IP protocol type 4
(socket.IPPROTO_IPIP) on a Linux host. (I also would be happy if I
could create a GRE tunnel)

The thing is, I just don't understand how I such a socket could be
created and then later on handled.

Regarding to help(socket.socke()) the constructor looks like this:

 | socket([family[, type[, proto]]]) -> socket object
 |
 |  Open a socket of the given type.  The family argument specifies the
 |  address family; it defaults to AF_INET.  The type argument specifies
 |  whether this is a stream (SOCK_STREAM, this is the default)
 |  or datagram (SOCK_DGRAM) socket.  The protocol argument defaults to 0,
 |  specifying the default protocol.  Keyword arguments are accepted.

This means to create a simple UDP socket I can do the following where
the last argument is optional.

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IP)

So to create an IP-Encapsulation socket I would have to do this:

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IPIP)

or for GRE this.

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_GRE)

But how can I now set the fields? How do I really encapsulate other
data (=sockets?)? Do I need a Raw socket at all? Or should this work
somehow like the following to encapsulate UDP payload?

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IPIP)

I really would be happy if someone could help me with this and even
better could provide some examples on the usage.

Thanks in advance, Matthias
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing error for ConfigParser

2010-09-23 Thread Philip Semanchuk

On Sep 23, 2010, at 1:22 PM, Andrew Z. wrote:

> Is there a way to parse RealPlayer's realplayerrc in Python?  I need
> to support Python 2.5 - 2.7
> 
> Example code
> 
> import urllib2
> import ConfigParser
> f = urllib2.urlopen('http://pastebin.com/download.php?i=N1AcUg3w')
> config = ConfigParser.RawConfigParser()
> config.readfp(f)
> 
> 
> Error
> Traceback (most recent call last):
>  File "test_config_parser_real_player.py", line 6, in 
>config.readfp(f)
>  File "/usr/lib/python2.6/ConfigParser.py", line 305, in readfp
>self._read(fp, filename)
>  File "/usr/lib/python2.6/ConfigParser.py", line 510, in _read
>raise e
> ConfigParser.ParsingError: File contains parsing errors: 
>[line 31]: '%0aCopyright (c) 1995-2000 Macromedia, Inc. All
> rights reserved.\r\n'
>[line 34]: '%0a\r\n'

Hi Andrew,
Hopefully someone familiar with the topic of RealPlayer file formats will step 
in, but while you're waiting here's my $.02. 

Looks like this is an INI file, and since there's no defined standard for INI 
files, it's hard for anyone to write a parser that is guaranteed to work with 
all INI files. 

In this particular case you've got a multiline entry in the INI file which 
apparently ConfigParser doesn't like. One approach would be to subclass 
ConfigParser and massage the lines it doesn't like into something ConfigParser 
finds more palatable. Or if you're not interested in those lines, parse the 
error message, delete the offending lines and re-run the INI file through 
ConfigParser.

Good luck
Philip








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


Python 2.6: How to turn off cgitb.py's DeprecationWarning: BaseException.message has been deprecated

2010-09-23 Thread python
Python 2.6: We're using the standard lib's cgitb module to
provide diagnostic messages when unexpected exceptions occur.

Unfortunately, this module raises a DeprecationWarning like below
when it is used:

C:\Python26\lib\cgitb.py:245: DeprecationWarning:
BaseException.message has been
 deprecated as of Python 2.6
  value = pydoc.text.repr(getattr(evalue, name))

Is there some way to disable this specific warning message (our
customers find it disconcerting) or do we have to go in and edit
the cgitb.py module itself? Also, wondering if this warning has
been addressed in Python 2.7/3.x?

Thank you,
Malcolm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lists and list item matches (ghost wodgame)

2010-09-23 Thread Baba
On Sep 23, 8:13 pm, nn  wrote:
> On Sep 23, 1:25 pm, Baba  wrote:
>
>
>
> > On Sep 23, 4:17 pm, nn  wrote:
>
> > > On Sep 23, 10:56 am, nn  wrote:
>
> > > > On Sep 22, 6:39 pm, Baba  wrote:
>
> > > > > On Sep 22, 9:18 pm, Baba  wrote:
>
> > > > > > On Sep 22, 3:38 pm, nn  wrote:
>
> > > > > > > On Sep 21, 6:39 pm, Baba  wrote:
>
> > > > > > > > Hi
>
> > > > > > > > query level: beginner
>
> > > > > > > > as part of a learning exercise i have written code that:
>
> > > > > > > > a) asks for a single letter input (assumption: only 1 letter 
> > > > > > > > wil be
> > > > > > > > entered)
> > > > > > > > b) adds that letter to list1 and then goes through list2 and 
> > > > > > > > checks:
>
> > > > > > > >     1) if any item in list2 starts with list1 > if False: break
> > > > > > > >     2) if list1 == any item in list2 > if True: break
>
> > > > > > > > c) start again until 2) is True
>
> > > > > > > > wordlist = ['hello', 'bye']
> > > > > > > > handlist = []
> > > > > > > > letter = raw_input('enter letter: ')
> > > > > > > > handlist.append(letter)
> > > > > > > > hand = "".join(handlist)
> > > > > > > > for item in wordlist:
> > > > > > > >     if item.startswith(hand):
> > > > > > > >         while item.startswith(hand):
> > > > > > > >             if hand not in wordlist:
> > > > > > > >                 letter = raw_input('enter letter: ')
> > > > > > > >                 handlist.append(letter)
> > > > > > > >                 hand = "".join(handlist)
> > > > > > > >             else: break
> > > > > > > >         else: break
> > > > > > > > print 'you loose'
>
> > > > > > > > this code works but can it be optimised? i have the feeling 
> > > > > > > > that my
> > > > > > > > nesting of IF, WHILE and FOR statements is overkill?
>
> > > > > > > > inspired by part IV 
> > > > > > > > ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc...
>
> > > > > > > > thanks
> > > > > > > > Baba
>
> > > > > > > Yes it is overkill. Especially the else:break from the while loop
> > > > > > > makes it difficult to follow the logic. Also the program breaks 
> > > > > > > down
> > > > > > > if I use the following word list:
>
> > > > > > > wordlist = ['hello', 'hamburger', 'bye']
>
> > > > > > > enter letter: h
> > > > > > > enter letter: a
> > > > > > > you loose
>
> > > > > > > I am not going to post any spoilers but I wrote your program 
> > > > > > > using one
> > > > > > > while loop and one generator expression for a total of 5 lines. My
> > > > > > > version might be a bit too advanced but you should still be able 
> > > > > > > to do
> > > > > > > it using only one while, one for and one if instead.
>
> > > > > > Hi nn,
>
> > > > > > i wasn't expecting my code to fail with an additional word in it.
> > > > > > While i was conscious that the whole construct was heavy i thought 
> > > > > > the
> > > > > > reasoning worked. I keep looking at it but can't figure out the
> > > > > > problem Can you give me a hint?
>
> > > > > > In the meantime i found out that it is actually possible to 
> > > > > > populate a
> > > > > > string (just like a list, a dictionary or a tuple). Here's what i've
> > > > > > got now:
>
> > > > > > wordlist = ['hello', 'bye']
> > > > > > hand = ''
> > > > > > for item in wordlist:
> > > > > >     if item.startswith(hand):
> > > > > >         while item.startswith(hand):
> > > > > >             if hand not in wordlist:
> > > > > >                 hand += raw_input('enter letter: ')
> > > > > >                 print hand
> > > > > >             else: break
> > > > > >         else: break
> > > > > > print 'you loose'
>
> > > > > > But i can't figure out why it won't work when adding the extra word.
> > > > > > Thanks by the way, it taught me not to be too confident when things
> > > > > > SEEM to work...
>
> > > > > > Why does it work when i use the built-in function any(iterable)?? To
> > > > > > me using the any(iterable) function seems just like regrouping 3 
> > > > > > lines
> > > > > > into one...
>
> > > > > > wordlist = ['hello','hamburger', 'bye', 'cello']
> > > > > > hand = ''
> > > > > > while any(item.startswith(hand) for item in wordlist):
> > > > > >     if hand not in wordlist:
> > > > > >         hand += raw_input('enter letter: ')
> > > > > >     else: break
> > > > > > print 'you loose'
>
> > > > > > thanks
>
> > > > > > Baba
>
> > > > > Hi nn,
>
> > > > > looking at my original code again i realise that having a raw_input
> > > > > inside a FOR loop is flawed per se (at least for my purposes) so i
> > > > > will just assume that i was taking the wrong approach initially. No
> > > > > point in analysing it further. Thanks for your help.
>
> > > > > Baba
>
> > > > Since you seem to have figured it out I will post my version (python
> > > > 3):
>
> > > > wordlist = ['hello', 'hamburger', 'bye']
> > > > inp=''
> > > > while any(word.startswith(inp) and word!=inp for word in wordlist):
> > > >     inp += input('enter letter: ')
> > > > print('you lose')
>
> > > 

Re: lists and list item matches (ghost wodgame)

2010-09-23 Thread Baba
On Sep 23, 8:13 pm, nn  wrote:
> On Sep 23, 1:25 pm, Baba  wrote:
>
>
>
> > On Sep 23, 4:17 pm, nn  wrote:
>
> > > On Sep 23, 10:56 am, nn  wrote:
>
> > > > On Sep 22, 6:39 pm, Baba  wrote:
>
> > > > > On Sep 22, 9:18 pm, Baba  wrote:
>
> > > > > > On Sep 22, 3:38 pm, nn  wrote:
>
> > > > > > > On Sep 21, 6:39 pm, Baba  wrote:
>
> > > > > > > > Hi
>
> > > > > > > > query level: beginner
>
> > > > > > > > as part of a learning exercise i have written code that:
>
> > > > > > > > a) asks for a single letter input (assumption: only 1 letter 
> > > > > > > > wil be
> > > > > > > > entered)
> > > > > > > > b) adds that letter to list1 and then goes through list2 and 
> > > > > > > > checks:
>
> > > > > > > >     1) if any item in list2 starts with list1 > if False: break
> > > > > > > >     2) if list1 == any item in list2 > if True: break
>
> > > > > > > > c) start again until 2) is True
>
> > > > > > > > wordlist = ['hello', 'bye']
> > > > > > > > handlist = []
> > > > > > > > letter = raw_input('enter letter: ')
> > > > > > > > handlist.append(letter)
> > > > > > > > hand = "".join(handlist)
> > > > > > > > for item in wordlist:
> > > > > > > >     if item.startswith(hand):
> > > > > > > >         while item.startswith(hand):
> > > > > > > >             if hand not in wordlist:
> > > > > > > >                 letter = raw_input('enter letter: ')
> > > > > > > >                 handlist.append(letter)
> > > > > > > >                 hand = "".join(handlist)
> > > > > > > >             else: break
> > > > > > > >         else: break
> > > > > > > > print 'you loose'
>
> > > > > > > > this code works but can it be optimised? i have the feeling 
> > > > > > > > that my
> > > > > > > > nesting of IF, WHILE and FOR statements is overkill?
>
> > > > > > > > inspired by part IV 
> > > > > > > > ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc...
>
> > > > > > > > thanks
> > > > > > > > Baba
>
> > > > > > > Yes it is overkill. Especially the else:break from the while loop
> > > > > > > makes it difficult to follow the logic. Also the program breaks 
> > > > > > > down
> > > > > > > if I use the following word list:
>
> > > > > > > wordlist = ['hello', 'hamburger', 'bye']
>
> > > > > > > enter letter: h
> > > > > > > enter letter: a
> > > > > > > you loose
>
> > > > > > > I am not going to post any spoilers but I wrote your program 
> > > > > > > using one
> > > > > > > while loop and one generator expression for a total of 5 lines. My
> > > > > > > version might be a bit too advanced but you should still be able 
> > > > > > > to do
> > > > > > > it using only one while, one for and one if instead.
>
> > > > > > Hi nn,
>
> > > > > > i wasn't expecting my code to fail with an additional word in it.
> > > > > > While i was conscious that the whole construct was heavy i thought 
> > > > > > the
> > > > > > reasoning worked. I keep looking at it but can't figure out the
> > > > > > problem Can you give me a hint?
>
> > > > > > In the meantime i found out that it is actually possible to 
> > > > > > populate a
> > > > > > string (just like a list, a dictionary or a tuple). Here's what i've
> > > > > > got now:
>
> > > > > > wordlist = ['hello', 'bye']
> > > > > > hand = ''
> > > > > > for item in wordlist:
> > > > > >     if item.startswith(hand):
> > > > > >         while item.startswith(hand):
> > > > > >             if hand not in wordlist:
> > > > > >                 hand += raw_input('enter letter: ')
> > > > > >                 print hand
> > > > > >             else: break
> > > > > >         else: break
> > > > > > print 'you loose'
>
> > > > > > But i can't figure out why it won't work when adding the extra word.
> > > > > > Thanks by the way, it taught me not to be too confident when things
> > > > > > SEEM to work...
>
> > > > > > Why does it work when i use the built-in function any(iterable)?? To
> > > > > > me using the any(iterable) function seems just like regrouping 3 
> > > > > > lines
> > > > > > into one...
>
> > > > > > wordlist = ['hello','hamburger', 'bye', 'cello']
> > > > > > hand = ''
> > > > > > while any(item.startswith(hand) for item in wordlist):
> > > > > >     if hand not in wordlist:
> > > > > >         hand += raw_input('enter letter: ')
> > > > > >     else: break
> > > > > > print 'you loose'
>
> > > > > > thanks
>
> > > > > > Baba
>
> > > > > Hi nn,
>
> > > > > looking at my original code again i realise that having a raw_input
> > > > > inside a FOR loop is flawed per se (at least for my purposes) so i
> > > > > will just assume that i was taking the wrong approach initially. No
> > > > > point in analysing it further. Thanks for your help.
>
> > > > > Baba
>
> > > > Since you seem to have figured it out I will post my version (python
> > > > 3):
>
> > > > wordlist = ['hello', 'hamburger', 'bye']
> > > > inp=''
> > > > while any(word.startswith(inp) and word!=inp for word in wordlist):
> > > >     inp += input('enter letter: ')
> > > > print('you lose')
>
> > > 

Re: Best way for rotating a matrix of data?

2010-09-23 Thread Raphaël Plasson
On Sep 23, 1:50 am, Nobody  wrote:

> You can use arrays as indices, so applying a transformation to a set of
> index arrays (e.g. np.indices) then using those as indices is equivalent
> to applying a spatial transform to the data.

I am not sure that this would do the trick, e.g. for extracting a
transversal slice of a 3D array.

> Also: scipy.ndimage.


But this seems to do exactly what I am looking for, thanks :). There
actually may be another solution, that is to use the VTK library.
However, it is a much more complex package, much more powerful but
maybe too much for what I want to do. The scipy.ndimage module ("Multi-
dimensional image processing") is probably the best solution for me.

Thank you,

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


pyqt on portable python?

2010-09-23 Thread Lee Harr

Is it possible / easy to use PyQt with portable python?

I've done some googling and found one message that said
this is coming in the next version, but I can't find anything
on portablepython.com that mentions it.


Has anyone done this before? Have any better information
on how to set it up, or when it might come to the default
version of portable python?


Thanks.

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


Call for proposals -- PyCon 2011

2010-09-23 Thread Jesse Noller
Call for proposals -- PyCon 2011 -- 
===

Proposal Due date: November 1st, 2010

PyCon is back! With a rocking new website, a great location and
more Python hackers and luminaries under one roof than you could
possibly shake a stick at. We've also added an "Extreme" talk
track this year - no introduction, no fluff - only the pure
technical meat!

PyCon 2011 will be held March 9th through the 17th, 2011 in Atlanta,
Georgia. (Home of some of the best southern food you can possibly
find on Earth!) The PyCon conference days will be March 11-13,
preceded by two tutorial days (March 9-10), and followed by four
days of development sprints (March 14-17).

PyCon 2011 is looking for proposals for the formal presentation
tracks (this includes "extreme talks"). A request for proposals for
poster sessions and tutorials will come separately.

Want to showcase your skills as a Python Hacker? Want to have
hundreds of people see your talk on the subject of your choice? Have
some hot button issue you think the community needs to address, or have
some package, code or project you simply love talking about? Want to
launch your master plan to take over the world with Python?

PyCon is your platform for getting the word out and teaching something
new to hundreds of people, face to face.

In the past, PyCon has had a broad range of presentations, from reports
on academic and commercial projects, tutorials on a broad range of
subjects, and case studies. All conference speakers are volunteers and
come from a myriad of backgrounds: some are new speakers, some have been
speaking for years. Everyone is welcome, so bring your passion and your
code! We've had some incredible past PyCons, and we're looking to you to
help us top them!

Online proposal submission is open now! Proposals  will be accepted
through November 10th, with acceptance notifications coming out by
January 20th. To get started, please see:



For videos of talks from previous years - check out:



For more information on "Extreme Talks" see:



We look forward to seeing you in Atlanta!

Please also note - registration for PyCon 2011 will also be capped at a
maximum of 1,500 delegates, including speakers. When registration opens
(soon), you're going to want to make sure you register early! Speakers
with accepted talks will have a guaranteed slot.

Important Dates:
* November 1st, 2010: Talk proposals due.
* December 15th, 2010: Acceptance emails sent.
* January 19th, 2010: Early bird registration closes.
* March 9-10th, 2011: Tutorial days at PyCon.
* March 11-13th, 2011: PyCon main conference.
* March 14-17th, 2011: PyCon sprints days.

Contact Emails:
Van Lindberg (Conference Chair) - [email protected]
Jesse Noller (Co-Chair) - [email protected]
PyCon Organizers list: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Finding email threads with mailbox.mbox

2010-09-23 Thread Skye
Hello,

I'm working on a script to read large numbers of mail list archives in
mbox format and dump them into a database.  I was happy to find
mailbox.mbox because I like writing Python =)

However I need to find email threads (replies, quoted test, Re:
subjects etc) and it doesn't look like anything in the standard Python
library will help me with that.

I suppose I could yank some code from Mailman's pipermail or something
for identifying discussion threads, but I was wondering if anyone had
any other suggestions before I reinvent the wheel.

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


Re: Subprocess does not return for longer-running process

2010-09-23 Thread Lawrence D'Oliveiro
In message , Nobody wrote:

> On Thu, 23 Sep 2010 12:25:53 +1200, Lawrence D'Oliveiro wrote:
> 
>>> And I can't think of any reason why you should use os.waitpid() or
>>> similar; use the .wait() method.
>> 
>> I have used WNOHANG to poll for completion of a subprocess while
>> providing progress updates to the user.
> 
> This can be done via the .poll() method.

And what do you think the poll method uses?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python in Linux - barrier to Python 3.x

2010-09-23 Thread Lawrence D'Oliveiro
In message
<[email protected]>, Ant 
wrote:

> Still, no Python 3 unless I upgrade to Fedora 13, and upgrading
> an OS in order to get the latest version of one package is a bit much!

You’re using Fedora, a distro that pretty much demands you upgrade at least 
every 12 months, and you’re complaining about it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python in Linux - barrier to Python 3.x

2010-09-23 Thread Lawrence D'Oliveiro
In message <[email protected]>, Diez B. Roggisch wrote:

> Of course, in a ideal world, distutils would hook into the distros
> dependency system + simply say "please install python-dev first".
> 
> But I'm not convinced that putting the weight here on the shoulders of
> the python-communtiy to deal with arbirtray decisions of the dozen or
> how many distros + packaging schemes out there is possible - and helpful.

Fair enough. I think the right answer is for the package-management systems 
to bear the burden of coping with the established installation mechanisms of 
particular major subsystems.

There may be a slight mismatch, in that distutils is source-based, whereas 
most Linux distros (with the notable exception of Gentoo) expect to 
distribute and install prebuilt binaries. I suspect this is not 
insurmountable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python in Linux - barrier to Python 3.x

2010-09-23 Thread Lawrence D'Oliveiro
In message , Antoine 
Pitrou wrote:

> comp.lang.python doesn't handle Linux packaging [issues] ...

Why not? We regularly seem to was^H^H^Hspend a lot of time with Windows-
specific packaging problems, installation problems and configuration 
problems, why not Linux ones as well?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-23 Thread Aahz
In article ,
Ian Hobson   wrote:
>
>I am attempting to create a Windows Service in Python.

BTW, you probably want to subscribe to 
http://mail.python.org/mailman/listinfo/python-win32
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
-- 
http://mail.python.org/mailman/listinfo/python-list