Re: UNIX shell in Python?

2007-02-09 Thread Gary Herron
Deniz Dogan wrote:
> Hello.
>
> I was thinking about writing a UNIX shell program using Python.  Has 
> anyone got any experience on this?  Is it even possible?  I have 
> programmed a simple shell in C before and I came to think about how 
> perfect Python would be for parsing user input.
>
> Regards,
> Deniz Dogan
>   
Not only *can* it be done, but it *has* been done and well:  See IPython at:
  http://ipython.scipy.org/moin/

Gary Herron

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


Re: Referencing vars, methods and classes by name

2007-02-09 Thread Sagari
> For your other examples there are gross hacks using the dictionaries
> that represent the local and global symbol tables, so we translate
> your examples fairly directly, but stylistically we'd usually stay
> away from that kind of thing.

Thanks to everyone for all the comments. I am migrating from PHP to
Python and I am looking for the means to port a controller code that
would, roughly speaking, call a certain method of a certain class
(both class and method names taken from user input). Putting aside
input verification (by the moment I perform the call input must have
been verified), what would be the recommended way of doing the trick?

Thanks!

All the best,

Konstantin

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


Re: Latest approach to controlling non-printable / multi-byte characters

2007-02-09 Thread Peter Otten
metaperl wrote:

> There is no end to the number of frantic pleas for help with
> characters in the realm beyond ASCII.

And the answer is "first decode to unicode, then modify" in nine out of ten
cases.

> However, in searching thru them, I do not see a workable approach to
> changing them into other things.
> 
> I am dealing with a file and in my Emacs editor, I see "MASSACHUSETTS-
> AMHERST" ... in other words, there is a dash between MASSACHUSETTS and
> AMHERST.
> 
> However, if I do a grep for the text the shell returns this:
> 
> MASSACHUSETTS–AMHERST
> 
> and od -tc returns this:
> 
> 540O   F   M   A   S   S   A   C   H   U   S   E   T
> T
> 560S 342 200 223   A   M   H   E   R   S   T   ;   U   N
> I
> 
> 
> So, the conclusion is the "dash" is actually 3 octal characters. My
> goal is to take those 3 octal characters and convert them to an ascii
> dash. Any idea how I might write such a filter? The closest I have got
> it:
> 
> unicodedata.normalize('NFKD', s).encode('ASCII', 'replace')
> 
> but that puts a question mark there.

No idea where the character references come from but the dump suggests that
your text is in UTF-8.

>>> "MASSACHUSETS\342\200\223AMHERST".decode("utf8")
u'MASSACHUSETS\u2013AMHERST'
>>> "MASSACHUSETS\342\200\223AMHERST".decode("utf8").replace(u"\u2013", "-")
u'MASSACHUSETS-AMHERST'

u"\2013" is indeed a dash, by the way:
>>> import unicodedata
>>> unicodedata.name(u"\u2013")
'EN DASH'

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


Re: Thanks for the help

2007-02-09 Thread [EMAIL PROTECTED]
On 9 fév, 04:06, "Reid" <[EMAIL PROTECTED]> wrote:
> Hello All
>
> Thanks for taking the time to answer my question. I do not need 3d stuff.
> Just a couple of buttons and menu's.

That's not "3D", that's GUI (Graphical User Interface). "3D" usually
refers to "3D graphics"...

> The reason I am looking at python is it
> is free to download. I cannot afford VB or other commercial languages.

It's not only "free to download", it's free (as in "free speech")
software.
And FWIW, there are other good reasons to use Python, one of them
being that it's a pretty good language !-)

Now, what is your question, exactly ?-)

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


Re: Dictionary Question

2007-02-09 Thread [EMAIL PROTECTED]
On 9 fév, 04:02, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Thu, 08 Feb 2007 23:32:50 -0300, Sick Monkey <[EMAIL PROTECTED]>
> escribió:
>
> > db = {'[EMAIL PROTECTED]':'none', '[EMAIL PROTECTED]':'none',
> > '[EMAIL PROTECTED]':'none',
> > '[EMAIL PROTECTED]':'none',}
>
> > And I want to pull out all of the "gmail.com" addresses..  How would I do
> > this?
>
> > NOTE:  I already have a regular expression to search for this, but I feel
> > that looping over a dictionary is not very efficient.

(answer to the OP)

Looping over a dict keys should be quite fast. If you're worried about
perfs, it would be better to first get rid of useless regexps:

filtered_db = dict((k, v) for k, v in db.iteritems() \
 if not k.endswith('@gmail.com'))



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


Re: Thanks for the help

2007-02-09 Thread [EMAIL PROTECTED]
On 9 fév, 07:43, "azrael" <[EMAIL PROTECTED]> wrote:
> On Feb 9, 4:06 am, "Reid" <[EMAIL PROTECTED]> wrote:
>
> > Hello All
>
> > Thanks for taking the time to answer my question. I do not need 3d stuff.
> > Just a couple of buttons and menu's. The reason I am looking at python is it
> > is free to download. I cannot afford VB or other commercial languages.
>
> > Reid
>
> there is also other free stuff. c, c++, c#, java,..
> i also prefere python.
>
> i don't want to bring you to stupid ideas, but what about illegal
> software.

It's a stupid idea IMHO.

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


Problem - Win32 Programming

2007-02-09 Thread Finger . Octopus
Hi ..

I'm a newbie to python win32 programming. I was just reading Python
Programming on Win32 and I was trying to run this program:

# SimpleCOMServer.py - A sample COM server - almost as small as they
come!
#
# We expose a single method in a Python COM object.
class PythonUtilities:
_public_methods_ = [ 'SplitString' ]
_reg_progid_ = "PythonDemos.Utilities"
# NEVER copy the following ID
# Use "print pythoncom.CreateGuid()" to make a new one.
_reg_clsid_ = "{41E24E95-D45A-11D2-852C-204C4F4F5020}"

def SplitString(self, val, item=None):
import string
if item != None: item = str(item)
return string.split(str(val), item)

# Add code so that when this script is run by
# Python.exe, it self-registers.
if __name__=='__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)


I am using Python 2.5 and it says:

Traceback (most recent call last):
  File "E:/PyEN/PythonUtilities.py", line 20, in 
import win32com.server.register
ImportError: No module named win32com.server.register

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


Re: from __future__ import absolute_import ?

2007-02-09 Thread Peter Otten
Ron Adam wrote:

> Peter Otten wrote:
>> Ron Adam wrote:
>>
>>>
>>> work
>>>   |
>>>   |- foo.py# print "foo not in bar"
>>>   |
>>>   `- bar
>>>   |
>>>   |- __init__.py
>>>   |
>>>   |- foo.py# print "foo in bar"
>>>   |
>>>   |- absolute.py   # from __futer__ import absolute_import
>>>   |# import foo
>>>   |
>>>   `- relative.py   # import foo
>>>
>>>
>>> * Where "work" is in the path.
>>>
>>>
>>> (1)
>>>
>>> C:\work>python -c "import bar.absolute"
>>> foo not in bar
>>>
>>> C:\work>python -c "import bar.relative"
>>> foo in bar
>>>
>>>
>>> (2)
>>>
>>> C:\work>python -m "bar.absolute"
>>> foo not in bar
>>>
>>> C:\work>python -m "bar.relative"
>>> foo not in bar
>>>
>>>
>>> (3)
>>>
>>> C:\work>python
>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
>>> (Intel)] on win 32
>>> Type "help", "copyright", "credits" or "license" for more information.
>>>  >>> import bar.absolute
>>> foo not in bar
>>>  >>> import bar.relative
>>> foo in bar
>>>
>>>
>>> (4)
>>>
>>> C:\work>cd bar
>> 
>> A path below the package level is generally a good means to shoot
>> yourself in the foot and should be avoided with or without absolute
>> import.
> 
> Seems so.  :-/
> 
> 
>>> C:\work\bar>python -c "import bar.absolute"
>>> foo in bar
>>>
>>> C:\work\bar>python -c "import bar.relative"
>>> foo in bar
>>>
>>>
>>> (5)
>>>
>>> C:\work\bar>python
>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
>>> (Intel)] on win 32
>>> Type "help", "copyright", "credits" or "license" for more information.
>>>  >>> import bar.absolute
>>> foo in bar
>>>  >>> import bar.relative
>>> foo in bar
>>>  >>>
>>>
>>>
>>>
>>> Case (2) seems like it is a bug.
>> 
>> I think so, too.
> 
> This one is the reasons I had trouble figuring it out.  I was using the -m
> command option when I tried to test it.
> 
> There is a bug report on absolute/relative imports already.  I'm not sure
> if
> this particular item is covered under it or not.  Doesn't sound like it as
> the bug report address the relative aspects of it.
> 
> 
>>> Why not also have (4), and (5) do the same as cases (1) and (3)?
>> 
>> The work/bar directory is the current working directory and occurs in the
>> path before the work directory.
> 
> Yes. Unfortunately this is a side effect of using the os's directory
> structure
> to represent a python "package" structure.  If a package was represented
> as a
> combined single file.  Then the working directory would always be the
> package directory.
> 
> 
>  > When bar.absolute imports foo python is
>  > unaware that work/bar/foo.py is part of the bar package.
> 
> Umm isn't the "bar" stuck on the front of "bar.absolute" a pretty
> obvious
> hint.  ;-)
> 
> If you run the module directly as a file...
> 
>  python bar/foo.py
> or  python foo.py
> 
> Then I can see that it doesn't know.  But even then, it's possible to find
> out.
>   ie... just check for an __init__.py file.
> 
> Python has a certain minimalist quality where it tries to do a lot with a
> minimum amount of resources, which I generally love.  But in this
> situation that
> might not be the best thing.  It would not be difficult for python to
> detect if
> a module is in a package, and determine the package location.  With the
> move to explicit absolute/relative imports, it would make since if python
> also were a little smarter in this area.

I have not used the new import behaviour seriously, but -- I think I like
it :-)

>>> in cases (4) and (5), that is the result I would expect if I did:
>>>
>>> import absolute   # with no 'bar.' prefix.
>>> import relative
>>>
>>>
>>>  From what I understand, in 2.6 relative imports will be depreciated,
>>>  and in 2.7
>>> they will raise an error.  (providing plans don't change)
>>>
>>> Would that mean the absolute imports in (4) and (5) would either find
>>> the 'foo not in bar' or raise an error?
>> 
>> No, in 1, 3 -- and 2 if the current behaviour is indeed a bug. This is
>> only for the relative import which would have to be spelt
>> 
>> from . import foo
> 
> Was that a 'yes' for exampels 4 and 5, since 1,2 and 3 are 'no'?

(4) and (5) are misconfigurations, IMHO.

>> in an absolute-import-as-default environment;
>> 
>> import foo
>> 
>> would always be an absolute import.
> 
> But what is the precise meaning of "absolute import" in this un-dotted
> case?
> 
> Currently it is:
> 
>  "A module or package that is located in sys.path or the current
>  directory".
> 
> But maybe a narrower interpretation may be better?:
> 
>  "A module or package found in sys.path, or the current directory
>   and is *not* in a package."

You'd have to add a not-in-package test to every import - I don't think it's
worth the effort.

> If it's in a package then the dotted "absolute" name should be used.
> Right?

Either that or the full path. The dotted path makes it easy to move the
module between packages.

> I gu

Re: Calling J from Python

2007-02-09 Thread Ant
On Feb 6, 12:21 am, greg <[EMAIL PROTECTED]> wrote:
...
> Yes, but with Python you wouldn't have to spend a
> couple of weeks sitting and thinking before starting
> to type that line...

This is a good point often overlooked. You often get these threads on
c.l.python about "How can I do this in one line", usually with some
example of how it is done in only 13 characters in Perl. Yes you may
spend less time typing - but unless you are a true expert in (J, Perl,
other terse language) the time you spend actually working out how to
type it, and in debugging it far outweighs the time you'd spend on all
of that typing in a clean but more verbose language such as Python.


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


unique elements from list of lists

2007-02-09 Thread Tekkaman
I have a list of lists and I want to define an iterator (let's call
that uniter) over all unique elements, in any order. For example,
calling:

sorted(uniter([['a', 'b', 'd'], ['b', 'c'], ['a', 'c', 'd']]))

must return ['a', 'b', 'c', 'd']. I tried the following
implementations:

from itertools import chain
def uniter1(listOfLists):
for item in set(chain(*listOfLists)): yield item

def uniter2(listOfLists):
for item in reduce(
lambda x,y: x|y,
[set(list_) for list_ in listOfLists]
): yield item

speed test with timeit says the first one is slightly faster. What
bothers me is that it builds a set from an iterator and then another
iterator from the set. Is there a way to implement this using only
iterators? I also tried a "full python" implementation (by that I mean
one that does not use the built-in set and keeps track of previously
yielded items in a list) but the one I pulled out is about 180 times
slower. Here it is:

def uniter3(listOfLists):
done = []
for list_ in listOfLists:
for item in list_:
if not item in done:
done.append(item)
yield item

Thanks in advance for any contribution.

-- Simone

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


A little more advanced for loop

2007-02-09 Thread Horta
Hi folks,

  Suppose I have to loop over 3 lists being the same size at the same
time and order. How can I do that without using the range() function
or whatever indexing?

Example using range:

a = ['aaa', '']
b = ['bb', '']
c = ['c', '']

for i in range(len(a)):
# using a[i], b[i], and c[i]

  I'm sure there's a elegant way to do that...

  Thanks in advance.

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


Re: A little more advanced for loop

2007-02-09 Thread Diez B. Roggisch
Horta wrote:

> Hi folks,
> 
>   Suppose I have to loop over 3 lists being the same size at the same
> time and order. How can I do that without using the range() function
> or whatever indexing?
> 
> Example using range:
> 
> a = ['aaa', '']
> b = ['bb', '']
> c = ['c', '']
> 
> for i in range(len(a)):
> # using a[i], b[i], and c[i]
> 
>   I'm sure there's a elegant way to do that...


Use zip:

for av, bv, cv in zip(a, b, c):
print av, bv, cv

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


Re: Thanks for the help

2007-02-09 Thread Toby A Inkster
[EMAIL PROTECTED] wrote:
> Reid wrote:
>
>> I do not need 3d stuff. Just a couple of buttons and menu's.
> 
> That's not "3D", that's GUI (Graphical User Interface). "3D" usually
> refers to "3D graphics"...

Hence the original poster's clever use of the word "not" ;-)

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A little more advanced for loop

2007-02-09 Thread Stephan Diehl
Horta wrote:
> Hi folks,
> 
>   Suppose I have to loop over 3 lists being the same size at the same
> time and order. How can I do that without using the range() function
> or whatever indexing?
> 
> Example using range:
> 
> a = ['aaa', '']
> b = ['bb', '']
> c = ['c', '']
> 
> for i in range(len(a)):
> # using a[i], b[i], and c[i]
> 
>   I'm sure there's a elegant way to do that...
> 
>   Thanks in advance.
> 
Sure, there is:

for a_item, b_item , c_item in zip(a,b,c):
# do something
-- 
http://mail.python.org/mailman/listinfo/python-list


python shelve on win vs unix

2007-02-09 Thread Tor Erik Soenvisen
Hi,

Have a problem using shelve on windows and unix. While my windows box 
supports dbhash, my unix box supports gdbm, and neither supports what the 
other does. The problem arises when I try to use the shelve generated in 
unix on my windows box.

Hoepfully there are alternatives to installing the berkeley db (needed by 
dbhash) on unix, which I'm looking at now. I'm no unix guru and would 
probably use "forever" to get it up and running.

Any suggestions for a quick and dirty solution (such as alternatives to 
shelve for persistent storage) to this problem would be appreciated.

regards, Tor Erik
-- 
http://mail.python.org/mailman/listinfo/python-list


os.popen and broken pipes

2007-02-09 Thread Philipp Pagel

Hi Pythoneers,

I need to process a large number of files which have been packed by the
UNIX compress tool (*.Z files). As I am not aware of a compress
equivalent of the gzip, zipfile or bzip2 modules, I thought I'd use the
uncompress or zcat commands directly to deal with the files:

for filename in file_list:
file = os.popen('uncompress -c '+filename, 'r')
do_something(file)
file.close()


This works fine for some files but results in

'write error onstdout: Broken pipe'

emitted by uncompress for others. Using zcat instead of uncompress
changes the wording of the error message but not the result.

I tried to give popen a large bufsize argument but that didn't really
help.

Probably I'm overlooking something obvious here but right now I can't
see it. Any hints?

cu
Philipp

-- 
Dr. Philipp Pagel  Tel. +49-8161-71 2131
Dept. of Genome Oriented BioinformaticsFax. +49-8161-71 2186
Technical University of Munich
http://mips.gsf.de/staff/pagel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UNIX shell in Python?

2007-02-09 Thread Bart Ogryczak
On Feb 9, 8:49 am, Deniz Dogan <[EMAIL PROTECTED]> wrote:
> Hello.
>
> I was thinking about writing a UNIX shell program using Python.  Has
> anyone got any experience on this?  Is it even possible?

Use the Google, Luke.
http://sourceforge.net/projects/pyshell/



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


Re: A little more advanced for loop

2007-02-09 Thread Horta
On Feb 9, 9:00 am, Stephan Diehl <[EMAIL PROTECTED]> wrote:
> Horta wrote:
> > Hi folks,
>
> >   Suppose I have to loop over 3 lists being the same size at the same
> > time and order. How can I do that without using the range() function
> > or whatever indexing?
>
> > Example using range:
>
> > a = ['aaa', '']
> > b = ['bb', '']
> > c = ['c', '']
>
> > for i in range(len(a)):
> > # using a[i], b[i], and c[i]
>
> >   I'm sure there's a elegant way to do that...
>
> >   Thanks in advance.
>
> Sure, there is:
>
> for a_item, b_item , c_item in zip(a,b,c):
> # do something

  Thanks guys!

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


Re: unique elements from list of lists

2007-02-09 Thread Peter Otten
Tekkaman wrote:

> I have a list of lists and I want to define an iterator (let's call
> that uniter) over all unique elements, in any order. For example,
> calling:
> 
> sorted(uniter([['a', 'b', 'd'], ['b', 'c'], ['a', 'c', 'd']]))
> 
> must return ['a', 'b', 'c', 'd']. I tried the following
> implementations:
> 
> from itertools import chain
> def uniter1(listOfLists):
> for item in set(chain(*listOfLists)): yield item

def uniter(lists):
   return iter(set(chain(*lists)))

This avoids the explicit for-loop. 

Peter


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


Re: unique elements from list of lists

2007-02-09 Thread azrael
try something else. im posting the code from a kiosk which has no
python, sooo. no code. only explanation

if my memory works well there is a function in python that takes a
multidimensional list and returns its values as a one-dimension list.

def main():
   list =unknownFunction([['a', 'b', 'd'], ['b', 'c'], ['a', 'c',
'd'])# =a, b, d, b, c, a, c, d
   temp = []
   for i in list:
  check(i, temp, list)
   sort(list)

def check(pos, temp, list ):
   for i in temp:
  if temp[i]== list[pos]
 del list[pos]
 check(pos, temp, list)
  temp.append(list[pos])

im not sure if this should work but the meaning is:
the first three elements will be  appended into the list directly
because there was no like this in the temp
while there are elements in the list take a pivot value and check if
they are unique in the list.

check:
 while there are elements in the temporary list check if the pivot
exists in the temp. if false then append it to temp.

if true delete the element and go into the recursion on the same index
 why?

temp a, b, d
list a, b, d, (b), c, a, c, d

temp a, b, d
list a, b, d, (c) a, c, d

temp a, b, d, c
list a, b, d, c, (a) c, d

temp a, b, d, c
list a, b, d, c, (c), d

temp a, b, d, c
list a, b, d, c, (d)


temp a, b, d, c
list a, b, d, c

list a, b, c, d

one way to do it. this works well if you need the list in the order
they appear. sort it and it works well


but i think that there is the possibility to do it somthing like the
merge sort. maybee it would work. try it. Merge the sublists and
remove the duplicates. (L1,L2,L3) -> (L12, L3) -> (L123)
this should work pretty well




Tekkaman je napisao/la:
> I have a list of lists and I want to define an iterator (let's call
> that uniter) over all unique elements, in any order. For example,
> calling:
>
> sorted(uniter([['a', 'b', 'd'], ['b', 'c'], ['a', 'c', 'd']]))
>
> must return ['a', 'b', 'c', 'd']. I tried the following
> implementations:
>
> from itertools import chain
> def uniter1(listOfLists):
> for item in set(chain(*listOfLists)): yield item
>
> def uniter2(listOfLists):
> for item in reduce(
> lambda x,y: x|y,
> [set(list_) for list_ in listOfLists]
> ): yield item
>
> speed test with timeit says the first one is slightly faster. What
> bothers me is that it builds a set from an iterator and then another
> iterator from the set. Is there a way to implement this using only
> iterators? I also tried a "full python" implementation (by that I mean
> one that does not use the built-in set and keeps track of previously
> yielded items in a list) but the one I pulled out is about 180 times
> slower. Here it is:
>
> def uniter3(listOfLists):
> done = []
> for list_ in listOfLists:
> for item in list_:
> if not item in done:
> done.append(item)
> yield item
>
> Thanks in advance for any contribution.
>
> -- Simone

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


Re: unique elements from list of lists

2007-02-09 Thread azrael
tra using the firs sublist (list[1]) as cell.then take zhe second
sublist and take a value from it at once and if the value from list[2]
doesnt exist in list[1] then insert it into list[1] at the correct
place. Something like the insertionsort.

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


resolve environment variables in string - regular expression

2007-02-09 Thread Kai Rosenthal
Hello,

how can I resolve envionment variables in a string.
e.g.

strVar = /myVar
resolve in
str1 = /mytest02/$MYVAR/mytest02 --> /mytest02//myVar/mytest02
(unix)
str2 =$MYVAR/mytest03 --> /myVar/mytest03 (unix)
str3 =%MYVAR%/mytest03 --> /myVar/mytest03 (windows)
I would not set the variables in this time.

I think I need a little regular expression code snippet, but I have
not work with regular expression before.

Thanks for your help, Kai.

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


Re: Problem - Win32 Programming

2007-02-09 Thread Finger . Octopus
What shoud I do to fix it?

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


Re: os.popen and broken pipes

2007-02-09 Thread Chris
It could easily be the 2gig file size limitation, how large are the
extracts?

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


Re: os.popen and broken pipes

2007-02-09 Thread Antoon Pardon
On 2007-02-09, Philipp Pagel <[EMAIL PROTECTED]> wrote:
>
>   Hi Pythoneers,
>
> I need to process a large number of files which have been packed by the
> UNIX compress tool (*.Z files). As I am not aware of a compress
> equivalent of the gzip, zipfile or bzip2 modules, I thought I'd use the
> uncompress or zcat commands directly to deal with the files:
>
> for filename in file_list:
> file = os.popen('uncompress -c '+filename, 'r')
> do_something(file)
> file.close()
>
>
> This works fine for some files but results in
>
> 'write error onstdout: Broken pipe'
>
> emitted by uncompress for others. Using zcat instead of uncompress
> changes the wording of the error message but not the result.
>
> I tried to give popen a large bufsize argument but that didn't really
> help.
>
> Probably I'm overlooking something obvious here but right now I can't
> see it. Any hints?

As far as I can tell, your do_something doesn't consume the entire file.
So you close the file prematurly, which results in the uncompress/zcat
program trying to write to a pipe that is closed on the otherside,
giving you the above message.

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


Re: TimedRotatingFileHandler() isn't rotating at midnight?

2007-02-09 Thread Vinay Sajip
On 1 Feb, 05:32, Chris Shenton <[EMAIL PROTECTED]> wrote:
> I set this up 3 days ago and have not seen any of the logs I've
> created this way being rotated.  I expected them to rotate every
> midnight.  I'm calling the code that uses this logger many times, each
> a separate run, if that matters.

It might. I assume you have a long-running process which runs past
midnight - that's the scenario that TimedRotatingFileHandler is meant
for. Can you post a complete minimal example which shows the problem?

> Am I doing something stupid? I can't find anything on google and don't
> see anything in the code that would prevent rotating.
>

Rotating should happen when the logging process creates the handler
before midnight and makes a logging call destined for that handler
after midnight.

Regards,

Vinay Sajip

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


Re: Problem - Win32 Programming

2007-02-09 Thread Roger Upole

<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Hi ..
>
> I'm a newbie to python win32 programming. I was just reading Python
> Programming on Win32 and I was trying to run this program:
>
> # SimpleCOMServer.py - A sample COM server - almost as small as they
> come!
> #
> # We expose a single method in a Python COM object.
> class PythonUtilities:
>_public_methods_ = [ 'SplitString' ]
>_reg_progid_ = "PythonDemos.Utilities"
># NEVER copy the following ID
># Use "print pythoncom.CreateGuid()" to make a new one.
>_reg_clsid_ = "{41E24E95-D45A-11D2-852C-204C4F4F5020}"
>
>def SplitString(self, val, item=None):
>import string
>if item != None: item = str(item)
>return string.split(str(val), item)
>
> # Add code so that when this script is run by
> # Python.exe, it self-registers.
> if __name__=='__main__':
>print "Registering COM server..."
>import win32com.server.register
>win32com.server.register.UseCommandLine(PythonUtilities)
>
>
> I am using Python 2.5 and it says:
>
> Traceback (most recent call last):
>  File "E:/PyEN/PythonUtilities.py", line 20, in 
>import win32com.server.register
> ImportError: No module named win32com.server.register

Have you installed the Pywin32 extensions from here:
http://sourceforge.net/projects/pywin32/ ?

Roger




== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen and broken pipes

2007-02-09 Thread Philipp Pagel
Antoon Pardon <[EMAIL PROTECTED]> wrote:
> On 2007-02-09, Philipp Pagel <[EMAIL PROTECTED]> wrote:
> > for filename in file_list:
> > file = os.popen('uncompress -c '+filename, 'r')
> > do_something(file)
> > file.close()
> >
> > This works fine for some files but results in
> >
> > 'write error onstdout: Broken pipe'

> As far as I can tell, your do_something doesn't consume the entire file.
> So you close the file prematurly, which results in the uncompress/zcat
> program trying to write to a pipe that is closed on the otherside,
> giving you the above message.

You are right: some of the files do not fulfill certain
critereia causing so_somehting() to return before the entire file is
processed.

Thanks!

cu
Philipp

-- 
Dr. Philipp Pagel  Tel. +49-8161-71 2131
Dept. of Genome Oriented BioinformaticsFax. +49-8161-71 2186
Technical University of Munich
http://mips.gsf.de/staff/pagel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen and broken pipes

2007-02-09 Thread Philipp Pagel
Chris <[EMAIL PROTECTED]> wrote:
> It could easily be the 2gig file size limitation, how large are the
> extracts?

The files are much smaller than that, so that's not the issue.
Anyway, Antoon pointed me in the right direction.

Thanks for the help
Philipp

-- 
Dr. Philipp Pagel  Tel. +49-8161-71 2131
Dept. of Genome Oriented BioinformaticsFax. +49-8161-71 2186
Technical University of Munich
http://mips.gsf.de/staff/pagel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: resolve environment variables in string - regular expression

2007-02-09 Thread [EMAIL PROTECTED]
On 9 fév, 12:30, "Kai Rosenthal" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> how can I resolve envionment variables in a string.
> e.g.
>
> strVar = /myVar
> resolve in

nothing. This raises a SyntaxError. Python is *not* a shell script
language.

> str1 = /mytest02/$MYVAR/mytest02 --> /mytest02//myVar/mytest02
> (unix)
> str2 =$MYVAR/mytest03 --> /myVar/mytest03 (unix)
> str3 =%MYVAR%/mytest03 --> /myVar/mytest03 (windows)
> I would not set the variables in this time.
>
> I think I need a little regular expression code snippet,

Nope.

my_var = "/myVar"
str1 = "/mytest02/%s/mytest02" % my_var
str2 = "%(my_var)s/mytest03" % {'my_var': my_var}
import os
str3=os.path.join(my_var, "mytest03")

hth

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


Re: Newbie Question

2007-02-09 Thread [EMAIL PROTECTED]
On 9 fév, 00:16, [EMAIL PROTECTED] wrote:
> On Feb 8, 2:17 pm, Grant Edwards <[EMAIL PROTECTED]> wrote:
>
>
>
> > On 2007-02-08, Reid <[EMAIL PROTECTED]> wrote:
>
> > > I am just starting to play with programing again as a hobby. I have heard
> > > good things about python. I have not really looked into the language much.
> > > My question is, will python make programs with a gui under windows xp.
>
> > Yes.
>
> > There are a number of GUI toolkits for python that will work
> > with Windows.  Some of the more common ones are listed 
> > athttp://www.python.org/about/apps/underthe "Desktop GUIs"
> > section.
>
> > --
> > Grant Edwards   grante Yow!  Someone is DROOLING
> >   at   on my collar!!
> >visi.com
>
> yes as the guy above stated it does but another fairly easy language
> that supports windows gui is pascal inspecific borland delphi which
> uses the pascal language I learned some of it and gui development and
> coding in it was fun also i found free video tutorials which helped
> alot,http://www.3dbuzz.com you can click on delphi classroom, they
> will explain the rest

Delphi is a (dying) proprietary, MS-Windows-only[1] software relying
on a low-level language.

[1] Please don't argue about Kylix - it's not dying, it's long dead
and buried...

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


Re: Is Python for me?

2007-02-09 Thread [EMAIL PROTECTED]
On Feb 9, 5:08 am, "jiddu" <[EMAIL PROTECTED]> wrote:
> I'm planning to create a poker calculator, I learned some basic in
> highschool years ago and I was told for beginners Python is a good
> language to start.

Be sure to check out the Python411 podcast
http://awaretek.com/python/index.html

Take care,
Davy

http://www.latedecember.co.uk/sites/personal/davy/?clp

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


Re: Newbie Question

2007-02-09 Thread Stef Mientki
>> will explain the rest
> 
> Delphi is a (dying) proprietary, MS-Windows-only[1] software relying
> on a low-level language.
> 
Well it may be dying,
but for the moment it beats Python with a factor of 10,
when it comes to user (the majority of PC users) friendly GUI ;-)

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


Re: Object type check

2007-02-09 Thread Steven D'Aprano
On Thu, 08 Feb 2007 03:00:39 -0800, king kikapu wrote:

>> def modify(list_of_x):
>> for x in list_of_x:
>> try:
>> x.change_in_place  # don't call the method, just check it exists
> 
> XX...what exactly is going on here ? I mean, what is actually
> happens if you omit the parenethesis as you just did ? I understand
> that it does not call the method, but what is really doing ??

The same as for any attribute: x.name gives the object referred to by the
attribute name, and x.name() calls that object.

He's a simple example:

>>> def foo():
... return "foo"
...
>>> type(foo)  # the name alone

>>> type(foo())  # call the function



-- 
Steven.

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


Re: Strings in Python

2007-02-09 Thread Johny
Thanks ALL for help and ideas
L

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


Re: UNIX shell in Python?

2007-02-09 Thread Deniz Dogan
Bart Ogryczak wrote:
> On Feb 9, 8:49 am, Deniz Dogan <[EMAIL PROTECTED]> wrote:
>> Hello.
>>
>> I was thinking about writing a UNIX shell program using Python.  Has
>> anyone got any experience on this?  Is it even possible?
> 
> Use the Google, Luke.
> http://sourceforge.net/projects/pyshell/
> 

Have patience, young padawan.
-- 
http://mail.python.org/mailman/listinfo/python-list


pycallgraph 0.1.0

2007-02-09 Thread Gerald Kaszuba
Hi

I've just released the first version of Python Call Graph. I haven't
tested it too much so don't expect it not to crash :)

An example of its output is:
http://pycallgraph.slowchop.com/files/examples/mongballs-client.png

It's easy to use... you just need Graphviz installed and in your path
and a few lines of code changes.

More details at http://pycallgraph.slowchop.com/

If you have any problems, don't hesitate to ask here or email me directly.

Enjoy!

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


pygame and python 2.5

2007-02-09 Thread siggi
@Ben Sizer

Hi Ben,

in January I received your message re Pygame and Python 2.5:

>pygame and python 2.5
>Ben Sizer kylotan at gmail.com
>Fri Jan 12 11:01:00 CET 2007
>
>
>siggi wrote:
>
>> when I rtry to install pygame (pygame-1.7.1release.win32-py2.4.exe, the
>> most
>> ciurrent version I found) it requires Python 2.4! Will I really have to
>> uninstall my Python 2.5 and install the old Python 2.4 in order to use
>> pygame?
>
>For now, yes. This is a long-standing problem with Python really,
>requiring extensions to always be recompiled for newer versions. I
>usually have to wait about 6 months to a year after any new release
>before I can actually install it, due to the extension lag.
>
>-- 
>Ben Sizer

As a Python (and programming ) newbie  allow me a  - certainly naive -
question:

What is this time consuming part of recompiling an extension, such as
Pygame, from source code to Windows? Is it a matter of spare time to do the
job? Or do you have to wait for some Windows modules that are necessary for
compiling?

I am just asking for sake of "scientific" interest; building, compiling
from source code is a mystery to me poor Windows user ;-)

Thank you,

siggi



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


Re: unique elements from list of lists

2007-02-09 Thread bearophileHUGS
Tekkaman:

If the sublists contain hashable elements you can use this:

def uniter(lists):
merge = set()
for sub in lists:
merge = merge.union(sub)
for el in merge:
yield el

data = [['a', 'b', 'd'], ['b', 'c'], ['a', 'c', 'd']]
print list(uniter(data))

But often this too may be enough:

def uniter(lists):
merge = set()
for sub in lists:
merge = merge.union(sub)
return merge

Bye to the gentle Pegas too,
bearophile

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


Re: excel find last column

2007-02-09 Thread Lance Hoffmeyer
I ran makepy.py and loaded Microsoft Excel Object Library 11.0
I have imported:

import win32com.client
from win32com.client import constants
import re
import codecs,win32com.client
import time
import datetime
import win32com.client.dynamic


using this expression

lastcol = sh.UsedRange.Find("*", "A1", 
win32com.client.constant.SearchOrder=xlByColumns, 
win32com.client.constants.SearchDirection=xlPrevious).Column

I get error:

, line 245
lastcol = sh.UsedRange.Find("*", "A1", 
win32com.client.constant.SearchOrder=xlByColumns, 
win32com.client.constants.SearchDirection=xlPrevious).Column
SyntaxError: keyword can't be an expression

Tool completed with exit code 1


Guess I am getting closer to the solution? LOL
Sorry for being ignorant but I am a newbie and I don't understand all this 
python/excel stuff.

Lance







[EMAIL PROTECTED] wrote:
>> I get the error that xlPrevious is not defined.
>>
> 
> If you are using pythonwin, run the COM Makepy utility on Microsoft
> Excel Object Library. Then you have access to the defined constants as
> follows.
> 
 import win32com.client
 win32com.client.constants.xlPrevious
> 2
> 
> Hope this helps.
> 
> Paul
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Glob returning an empty list when passed a variable

2007-02-09 Thread Neil Webster
Hi,

I was wondering whether anybody could help me out.

I have a program, for part of it I am trying to pass a variable to a
glob function, this returns an empty list.  The strange thing is when
I hard code in the variable the glob section works.

Does anybody have any ideas as why it is not working?

The section of code that is not working is:

# The variable to be passed to the glob function
area_name_string = '"*% s*"' % (Area_name)

os.chdir(Input)

filename = glob.glob(area_name_string)

Thanks in advance

Neil

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


Re: TimedRotatingFileHandler() isn't rotating at midnight?

2007-02-09 Thread Chris Shenton
"Vinay Sajip" <[EMAIL PROTECTED]> writes:

> It might. I assume you have a long-running process which runs past
> midnight - that's the scenario that TimedRotatingFileHandler is meant
> for. Can you post a complete minimal example which shows the problem?

> Rotating should happen when the logging process creates the handler
> before midnight and makes a logging call destined for that handler
> after midnight.

Ah, then maybe I'm expecting the wrong thing.  The python code is
invoked from cron every 10 minutes or so, it's not long-running.
Each time it opens the same log file.  Sounds like this isn't going to
do what I want.

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


Re: TimedRotatingFileHandler() isn't rotating at midnight?

2007-02-09 Thread skip

>> Rotating should happen when the logging process creates the handler
>> before midnight and makes a logging call destined for that handler
>> after midnight.

Chris> Ah, then maybe I'm expecting the wrong thing.  The python code is
Chris> invoked from cron every 10 minutes or so, it's not long-running.
Chris> Each time it opens the same log file.  Sounds like this isn't
Chris> going to do what I want.

Right.  Check out the logrotate facility on your system.

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


Re: Sending CTRL-C event to console application

2007-02-09 Thread Daniel Clark
On Feb 8, 9:12 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Thu, 08 Feb 2007 15:54:05 -0300, Daniel Clark <[EMAIL PROTECTED]>
> escribió:
> > I have a Windows command line based application that only shuts down
> > cleanly if it sees "CTRL-C" on the console. I need to automate the
> > running of this application, but still allow the user sitting at the
> > machine to cancel the process cleanly if he/she needs to. In Unix this
> > would be a tiny shell script that used "kill -15", but under Windows
> > there does not seem to be an easy way to do this, at least that I can
> > find.
>
> > Below is a test program, based on CreateProcess.py from "Python
> > Programming on Win32". The
> > win32api.GenerateConsoleCtrlEvent(win32con.CTRL_C_EVENT, pid) lines
> > don't seem to do anything. What they should do is nothing in the case
> > of notepad, and exit out of the dir builtin process in the case of the
> > cmd.exe process.
>
> > Any ideas on how to make this work?
>
>  From your process creation code:
>
> > CreationFlags = win32process.CREATE_NEW_CONSOLE | \
> > win32process.CREATE_NEW_PROCESS_GROUP | \
> > win32process.NORMAL_PRIORITY_CLASS
>
>  Fromhttp://msdn2.microsoft.com/en-us/library/ms683155.aspx
> "Only those processes in the group that share the same console as the
> calling process receive the signal. In other words, if a process in the
> group creates a new console, that process does not receive the signal, nor
> do its descendants."

Thanks, although I'm 99% sure I've also tried it without
CREATE_NEW_CONSOLE (with a process that should just die if sent CTRL-
C, so it was monitorable via Task Manager) and it still didn't work.

I'm going to try taking a different approach by using a GUI Automation
tool like WATSUP [1] or pywinauto[2] next.

> Maybe you have better luck on a Windows programming group, asking how to
> send a Ctrl-C event (or a SIGINT signal) to another process attached to a
> different console.

>From what I've found via Google [3], Windows has no real concept of
signals, and no equivalent to SIGINT.

[1] WATSUP - Windows Application Test System Using Python
http://www.tizmoi.net/watsup/intro.html

[2] pywinauto - Python Win32 Automation
http://www.openqa.org/pywinauto/

[3] how to send a SIGINT to a Python process?
http://mail.python.org/pipermail/python-list/2005-October/343461.html

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


Re: Glob returning an empty list when passed a variable

2007-02-09 Thread Philipp Pagel
Neil Webster <[EMAIL PROTECTED]> wrote:

> area_name_string = '"*% s*"' % (Area_name)
> os.chdir(Input)
> filename = glob.glob(area_name_string)

Too many quotation marks.

>>> Area_name='Foo'
>>> '"*% s*"' % (Area_name)
'"*Foo*"'

Unless there are files with funny names containing '"' you will not get a
match.

cu
Philipp

-- 
Dr. Philipp Pagel  Tel. +49-8161-71 2131
Dept. of Genome Oriented BioinformaticsFax. +49-8161-71 2186
Technical University of Munich
http://mips.gsf.de/staff/pagel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Glob returning an empty list when passed a variable

2007-02-09 Thread Steve Holden
Neil Webster wrote:
> Hi,
> 
> I was wondering whether anybody could help me out.
> 
> I have a program, for part of it I am trying to pass a variable to a
> glob function, this returns an empty list.  The strange thing is when
> I hard code in the variable the glob section works.
> 
> Does anybody have any ideas as why it is not working?
> 
> The section of code that is not working is:
> 
> # The variable to be passed to the glob function
> area_name_string = '"*% s*"' % (Area_name)
> 
> os.chdir(Input)
> 
> filename = glob.glob(area_name_string)
> 
> Thanks in advance

Because you are trying to match filenames that have a double-quote 
character at the start and end? Try

area_name_string = '*% s*' % (Area_name)

Interesting, I never realised until now that you can have spaces between 
the percent sign and th format effector.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

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


Re: python shelve on win vs unix

2007-02-09 Thread Istvan Albert
On Feb 9, 6:06 am, Tor Erik Soenvisen <[EMAIL PROTECTED]> wrote:

> Any suggestions for a quick and dirty solution (such as alternatives to
> shelve for persistent storage) to this problem would be appreciated.

the easiest might be to just pickle your data into files. You could
also use Durus

http://www.mems-exchange.org/software/durus/

or ZODB, there are also some other object persistence libraries that
I've recently seen mentioned.

i.

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


Re: Glob returning an empty list when passed a variable

2007-02-09 Thread Neil Webster
On 9 Feb, 14:15, Steve Holden <[EMAIL PROTECTED]> wrote:
> Neil Webster wrote:
> > Hi,
>
> > I was wondering whether anybody could help me out.
>
> > I have a program, for part of it I am trying to pass a variable to a
> > glob function, this returns an empty list.  The strange thing is when
> > I hard code in the variable the glob section works.
>
> > Does anybody have any ideas as why it is not working?
>
> > The section of code that is not working is:
>
> > # The variable to be passed to the glob function
> > area_name_string = '"*% s*"' % (Area_name)
>
> > os.chdir(Input)
>
> > filename = glob.glob(area_name_string)
>
> > Thanks in advance
>
> Because you are trying to match filenames that have a double-quote
> character at the start and end? Try
>
> area_name_string = '*% s*' % (Area_name)
>
> Interesting, I never realised until now that you can have spaces between
> the percent sign and th format effector.
>
> regards
>   Steve
> --
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenwebhttp://del.icio.us/steve.holden
> Blog of Note:  http://holdenweb.blogspot.com
> See you at PyCon?http://us.pycon.org/TX2007- Hide quoted text -
>
> - Show quoted text -

Steve and Philipp,

Thanks very much for the promptness of the reply and providing the
answer.

Steve, it appears to work so I left it, should it not be possible?

Regards

Neil

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


Re: pycallgraph 0.1.0

2007-02-09 Thread Stef Mientki
Gerald Kaszuba wrote:
> Hi
> 
> I've just released the first version of Python Call Graph. I haven't
> tested it too much so don't expect it not to crash :)
> 
> An example of its output is:
> http://pycallgraph.slowchop.com/files/examples/mongballs-client.png
> 
> It's easy to use... you just need Graphviz installed and in your path
> and a few lines of code changes.
> 
> More details at http://pycallgraph.slowchop.com/
> 
> If you have any problems, don't hesitate to ask here or email me directly.
> 
> Enjoy!
> 
> Gerald

looks quit good ...
... but isn't "__main__." non-information ?
cheers,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: excel find last column

2007-02-09 Thread Tim Golden
Lance Hoffmeyer wrote:
> I ran makepy.py and loaded Microsoft Excel Object Library 11.0
> I have imported:
> 
> import win32com.client
> from win32com.client import constants
> import re
> import codecs,win32com.client
> import time
> import datetime
> import win32com.client.dynamic
> 
> 
> using this expression
> 
> lastcol = sh.UsedRange.Find("*", "A1", 
> win32com.client.constant.SearchOrder=xlByColumns, 
> win32com.client.constants.SearchDirection=xlPrevious).Column
> 
> I get error:
> 
> , line 245
> lastcol = sh.UsedRange.Find("*", "A1", 
> win32com.client.constant.SearchOrder=xlByColumns, 
> win32com.client.constants.SearchDirection=xlPrevious).Column
> SyntaxError: keyword can't be an expression

I suspect you're getting unnecessarily (but understandably)
confused by the wrapping which the win32com does for you.

Basically, when you run the makepy stuff, a module is generated
(which you can go and look at if you feel so inclined) which
defines the operations this COM object allows. To handle the
constants, a sort of pseudo module is available to you called
win32com.client.constants which you use just like any other
Python module.

In the interpreter dump below, I import the win32com.client
stuff and force the module to be generated programatically
(essentially the same as calling makepy against the
Excel.Application COM library).

Then the constants "module" contains, among other things,
the xlByColumns constant.


Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import win32com.client
 >>> xl = win32com.client.gencache.EnsureDispatch ("Excel.Application")
 >>> win32com.client.constants.xlByColumns
2
 >>>



If you want to you can use the usual shortcuts:

const = win32com.client.constants
print const.xlByColumns
# or even
xlByColumns = const.xlByColumns

and use that anywhere you need, so in your example:

sh.UsedRange.Find (
   "*",
   "A1",
   SearchOrder=const.xlByColumns,
   SearchDirectory=const.xlPrevious
).Column

NB I haven't bothered to see whether what your code
is doing is correct, merely illustrating the use
of constants.

HTH a bit
TJG
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: doctests for interactive functions

2007-02-09 Thread Neil Cerutti
On 2007-02-08, Brian van den Broek <[EMAIL PROTECTED]> wrote:
> Can I run the rough structure of my code past you to see if it
> is in the vicinity of what you mean? (I have removed some
> details for sake of a short(er :-)) post.)

Yes, this is a good way to think about it. Separate input from
validation. The downside is that control flow grows warts.

> My .get method looks like:
>
> def get(self, input_function=raw_input):
>  while True:
>  self._prompt_user()
>  self._input = input_function()
>  if self._is_valid_input():
>  break
>  else:
>  self._process_invalid_input()
>  self._set_data()
>
> The base class ._prompt_user just displays a prompt. Individual
> subclasses might implement ._prompt_user to both display a
> prompt, and further information about constraints on valid
> inputs, or generate a menu of options on the fly, etc.
>
> Subclasses implement ._is_valid_input to return True if the
> input meets the desired constraints, False otherwise. So,
> YesNo._is_valid_input ensures that ._input.lower() is in ['y',
> 'n', 'yes', 'no'], for instance.

Your scheme may run into trouble with unexpected end of file when
input_function is not raw_input. File methods don't raise an
exception for EOF, they just return "", the empty string. So you
may need to check of that return value, and raise IOError for
that case.

> ._process_invalid_input is implemented to provide useful
> feedback about invalid input. So,
> YesNo._process_invalid_input() emits a reminder that a value in
> ['y', 'n', 'yes', 'no'] is needed, for instance.
>
> ._set_data is usually implemented to just store the user's
> input as .data, but in some cases, it first subjects it to
> further processing. For instance YesNo._set_data sets .data to
> True if the user entered a yes value, False if they entered a
> no value.
>
> Is this the sort of thing you mean, or is this the sort of
> coupling you suggest I avoid?

It has to be coupled somewhere. This seems like a good place to
do it. The private methods can all be tested individually, so the
doctests for get can be quite simple, or even absent.

Note that sequestering the test input in a file doesn't allow for
good examples, unfortunately.

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


Re: Is Python for me?

2007-02-09 Thread Neil Cerutti
On 2007-02-09, jiddu <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm planning to create a poker calculator, I learned some basic
> in highschool years ago and I was told for beginners Python is
> a good language to start.

Python *is* a good language to start.

> What I wanted to do is to first write a program which will be
> able to run through all the possible combinations of cards
> dealt out and use some counters to calculate different
> probabilities at different stages. Since that is a lot of data
> I think I have to store it in some kind of database or
> spreadsheet type thing? 

Unfortunately, that is a very *difficult* problem; no programming
library (save a hypothetical poker probability library) can make
it easy.

> Then I wanted to write a simple user interface so I could use
> my mouse to make selections of cards that I am dealt and that
> come on the flop and how many opponents and have the program
> find the calculated information and display it on the screen.
>
> I am wondering if I learn to use Python will I be able to write
> something like this? My friend studied some C in college so I
> thought I'd learn C++, turns out it is a very complicated
> language so I thought maybe I should try something else before
> I commit more time to the language.

Python can help you with creating an user interface, and with
several simple, powerful data structures. I think you ought to
lower your ambition a bit, at first. Firts write a program to
rank complete sets of poker hands. That should hold you for a
while.

-- 
Neil Cerutti
The recording I listened to had Alfred Brendel doing the dirty work of
performing this sonata (Liszt B minor) --Music Lit Essay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unique elements from list of lists

2007-02-09 Thread Tekkaman
Thanks everybody!
Azrael: your suggestions involve python-level membership testing and
dummy list construction just like my uniter3 example, so I'm afraid
they would not go any faster. There's no built-in sequence flattening
function that I know of btw.
bearophile: your implementation is very similar to my uniter2
(subsequent set unions) but without the additional lambda def
overhead, and in fact it goes faster. Not faster than uniter though.
Peter: your solution is the fastest, removing the explicit for loop
resulted in a 30% speed gain. Looks like using set() is a must.

-- Simone

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


Re: multithreading concept

2007-02-09 Thread S.Mohideen
I am sorry if I sound foolish.
Suppose I split my Net application code using parallel python into several 
processes based upon the number of CPU available. That means a single socket 
descriptor is distributed across all processes. Is parallelity can be 
acheived using the processes send/recv on the single socket multiplexed 
across all the processes.. I haven't tried it yet - would like to have any 
past experience related to this.

- Original Message - 
From: "Carl J. Van Arsdall" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, February 08, 2007 3:44 PM
Subject: Re: multithreading concept


> Bjoern Schliessmann wrote:
>> [snip]
>> What makes you think that'll be faster?
>>
>> Remember:
>> - If you have one CPU, there is no parallelity at all.
>> - If you do have multiple CPUs but only one network device, there is
>> no parallel networking.
>>
>>
> Not necessarily, if he's on a full duplex ethernet connection, then
> there is some parallelity he can take advantage of.  He has upstream and
> downstream.
>
> -c
>
> -- 
>
> Carl J. Van Arsdall
> [EMAIL PROTECTED]
> Build and Release
> MontaVista Software
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list 

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


Re: pycallgraph 0.1.0

2007-02-09 Thread Gerald Kaszuba
On 2/10/07, Stef Mientki <[EMAIL PROTECTED]> wrote:
> ... but isn't "__main__." non-information ?

Good point -- I'll consider removing it in the next version.

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


Database Programming with Python

2007-02-09 Thread Finger . Octopus
Hi

I wanted to connect Python to Ms-Access database using ADO or ODBC. I
have Python 2.5 and on mxODBC site, it has no higher version build
than 2.4. Moreoever, mxODBC is required for ADODB.
Can anyone guide me on this what should I do to make it work on Python
2.5? I have python 2.5 running on server.

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


Re: pyExcelerator - Protecting Cells

2007-02-09 Thread John Machin
On 9/02/2007 6:36 PM, Chris wrote:
> I'm sitting with a bit of an issue with pyExcelerator and creating an
> Excel file with certain cells protected while the rest of the
> spreadsheet is password protected.
> 
> The Protection class under Formatting has 2 variables for cell_locked
> and formula_hidden, tbh I only need to alter cell_locked to 0 to make
> those cells writable but changing that on a global scale ends up with
> everything I write being "writeable" if you re-open the file after it
> has been produced.
> 

"tbh" means what?
"changing that on a global scale" means what??

Please write a small *test* script (along the lines of those in 
pyExcelerator's examples directory, without 
irrelevant/private/otherwise_inappropriate code from your app) which 
tries to set some cells to locked and some to unlocked. If you can't get 
it to work:
(1) ensure that you have checked the bug register on Sourceforge and 
applied any patch that seems relevant to your problem
(2) come back here with a copy/paste of the actual code that you have run.

> I decided to import Formatting into the Worksheet module like this:

Why? What made you think that this would achieve your goal?

> import Formatting
> self.Formatting = Formatting.Protection
> 
> self.__cell_protect = 1
> self.__formula_hidden = 0
> 
> which is the defaults in the Protection class anyway but now when I do
> my create file routine when I try to change the cell_protect variable
> to 0 it makes absolutely no effect.

Of course it would have no effect. You appear to have given Worksheet 
objects a gratuitous __cell_protect attribute -- but no code to use it.

Protection is like a pattern or a font -- you have to cram it into an 
XFStyle object which you use as the style arg of the Worksheet.write() 
method. You will need of course at least 2 different XFStyle objects: 
one locked, another unlocked.

>  The code has been written as
> such:
> 
> if protection:
> work_sheet.set_protect(protection)
> work_sheet.set_password(password)
> else:
> pass

What induced you to write the above two statements?

> 
> for each_heading in each_work_sheet[1]:
> work_sheet.write(7, heading_cnt, str(each_heading),
> header_style)
> heading_cnt += 1
> 
> vert_cnt = 8
> 
> for each_set in each_work_sheet[2]:
> horiz_cnt = 0
> 
> for data_set in each_set:
> work_sheet.cell_protect = 1

Now the Worksheet object has *TWO* useless attributes, one named 
__cell_protect and one named cell_protect ...

> work_sheet.formula_hidden = 1
> 
> if len(str(data_set)) < 1:
> work_sheet.cell_protect = 0
> work_sheet.formula_hidden = 0
> work_sheet.write(vert_cnt, horiz_cnt, ' ')
> horiz_cnt += 1
> else:
> work_sheet.write(vert_cnt, horiz_cnt,
> str(data_set), data_style)
> horiz_cnt += 1
> 
> vert_cnt += 1
> 
> As you can see I only want to be able to write to cells that have a
> string '' which is parsed correctly through to data which was
> originally extracted from a database.  The problem is that I can only
> seem to set it to protect all written cells or not.
> 

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


NYC Python User Group Meeting

2007-02-09 Thread John Clark
Greetings!

The next New York City Python Users Group meeting is this Tuesday, Feb.
13th, 6:30pm at at the Millennium Partners office at 666 Fifth Avenue (53rd
St. and 5th Ave.) on the 8th Floor. We welcome all those in the NYC area who
are interested in Python to attend. However, we need a list of first and
last names to give to building security to make sure you can gain access to
the building. RSVP to [EMAIL PROTECTED] to add your name to the list. 

More information can be found on the yahoo group page:

http://tech.groups.yahoo.com/group/nycpython/

Hope to see you there!

-John

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


Re: multithreading concept

2007-02-09 Thread Paul Rubin
"S.Mohideen" <[EMAIL PROTECTED]> writes:
> Suppose I split my Net application code using parallel python into
> several processes based upon the number of CPU available. That means a
> single socket descriptor is distributed across all processes. Is
> parallelity can be acheived using the processes send/recv on the
> single socket multiplexed across all the processes.. I haven't tried
> it yet - would like to have any past experience related to this.

In Linux, you can open the socket before forking and then use it in
the child processes; there is also a way to pass open sockets from one
process to another, but the Python lib currently does not support that
feature.  It's worth adding and there's an open RFE for it, but it
hasn't been important enough that anyone's bothered coding it so far.
-- 
http://mail.python.org/mailman/listinfo/python-list


MOSSAD AND 911 - Zack was the anthrax mailer ?

2007-02-09 Thread stj911


WHAT DID ISRAEL KNOW IN ADVANCE OF THE SEPTEMBER 11 ATTACKS?

* Those Celebrating "Movers" and Art Student Spies
* Who were the Israelis living next to Mohammed Atta?
* What was in that Moving Van on the New Jersey shore?
* How did two hijackers end up on the Watch List weeks before 9/11?

At last, the answers. Read Christopher Ketcham's exclusive expose
in CounterPunch special double-issue February newsletter. Plus,
Cockburn and St. Clair on how this story was suppressed and ultimately
found its home in CounterPunch.

==
There are more questions that Alex Cockburn does not ask:

1) Who is the anthrax mailer ? Was the anthrax produced in US or
Israeli Labs ? So much for the Israeli love for America.
2) Why did the FBI release the five dancing israelis and not send them
to Guantanamo Bay for Interrogation ?
3) What about the pager message to Israelis in WTC not to come to work
on 9/11 ?
4) Who rigged Larry Silverstein's towers, WTC1,2,7 and how much larry
silverstein, a likudnik jew himself involved in 911 demolitions ?

==
But Bush was merely an ego front for the neocons ... He spoke their
speeches, signed their recommendations, and ordered their wars, go and
listen to Benjamin Friedman's excellent video in his very passionate
voice ...

http://video.google.com/videoplay?docid=3552214685532803163&q


911blogger.com <--- the best 911 site, the master site to all other
sites

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


Re: Calling J from Python

2007-02-09 Thread Alexander Schmolck
[restoring context]
"Ant" <[EMAIL PROTECTED]> writes:
> > On Feb 6, 12:21 am, greg <[EMAIL PROTECTED]> wrote:
> >
> > Alexander Schmolck wrote:
> > > For example I once wrote this (slow) code to display
> > > part of a mandelbrot fractal:
> > > load'viewmat'
> > > viewmat+/2&>:|((j.~/~(%~i:)99)&+@:*:)^:(i.32)0
> > > It'll likely require you more typing in python,
> >
> > Yes, but with Python you wouldn't have to spend a
> > couple of weeks sitting and thinking before starting
> > to type that line...

(it's actually reasonably straightforward, if someone really cares I might
post a translation)

> 
> This is a good point often overlooked. 

There is of course some truth in Greg's statement -- J code will likely have a
higher thought/character ratio (even after adjusting for differences in
average token-length) -- but I don't think that is in itself terribly
interesting.

What is in my opinion of interest is how much of the additional thought you
need to put in in order to achieve higher terseness is spent

a) on more pentrating insight on the problem as such, encouraged by the
   mind-set and abstractions associated with a language (let's call this
   expressiveness)

and how much of it is spent

b) on perl-golf style geek masturbation that focuses on recalling and
   exploiting the language's various behavioral oddities that are only of
   coincidental or low-level relevance to the problem (let's call this
   golf-syndrome)

I'm not claiming that the boundaries between the two are always unambigious,
but I think the distinction is pretty important when discussing pros and cons
of differences in terseness between languages.

Apart from scaling better, one reason that a), expressiveness, is much more
interesting than b), golf-syndrome, is that it translates to some extent even
to writing code in other languages as it enriches the programmer's reservoir
of metaphors and abstractions. Typically this also has a beneficial effect
for coding even in languages that offer no direct support for these
abstractions (I bet a programmer with, say extensive python, J and prolog
experience and just a little bit of C background is in many cases likely to
come up with a superior C solutions to challenging problems than someone who's
got the same amount of experience in C only).

Therefore...

> You often get these threads on c.l.python about "How can I do this in one
> line", usually with some example of how it is done in only 13 characters in
> Perl. Yes you may spend less time typing - but unless you are a true expert
> in (J, Perl, other terse language) the time you spend actually working out
> how to type it, and in debugging it far outweighs the time you'd spend on
> all of that typing in a clean but more verbose language such as Python.

... I also don't think your pairing of J and Perl is particularly helpful. As
long as no one can point me to some resonable examples demonstrating otherwise
I flattly deny that Perl is more concise than python in an *interesting* way,
i.e. by encouraging or enabling a)

(BTW "not interesting" != "not practically relevant"; harking back to my
previous posts, typing effort *does matter* in some contexts, such as
command-line one-liners; IMO the only thing perl is useful for.)

J, on the other hand, whilst also suffering somewhat from golf-syndrome, does
in my opinion also enable a)-style terseness. Let me give an example:

Before reading further, how would you code a program that gives the following
output ('skewed' sierpinski-triangle) in python? I'll give some remarkably
concise and IMO lucid J code and a python translation below.


*   
**  
* * 

*   *   
**  **  
* * * * 

*   *   
**  **  
* * * * 

*   *   *   *   
**  **  **  **  
* * * * * * * * 









SPOILERS AHEAD

































J solution
--

I can think of two nice ways in J, 13 and 16 characters long respectively and
each expressing something essential and non-trival about the problem in a way
that would be more cumbersome in python.

Here's the first one:

(,,.~)^:4,'*'  NB. due to Cliff Reiter, slightly adapted


Possible Python translation
---

Here's a python transiteration attempt:

# ^: ,   ~,.
print rep(hook(vertcat, self(horzcat)),4)('*')

or slightly more idiomatic:

def sierpinski(x):
return vertcat(x,horzcat(x,x))

print rep(sierpinsky,4)('*')

With:

def identity(x): return x
def rep(f,n): # f^:n
if   n < 0: return lambda *args: rep(inverse(f),-n)(*args)
elif n == 0: return identity
else:   return lambda *args: rep(f,n-1)(f(*args))
# horzcat and vertcat are only string-based special purpose mockups for this
# problem since python doesn't have arrays
def horzcat(a,b): # a,.b
return "\n".join

Re: *** Short Course: THE SECRET HISTORY OF THE UNITED STATES OF AMERICA ***

2007-02-09 Thread thermate2
Excellent Course Professor !!!

On Jan 9, 7:28 pm, [EMAIL PROTECTED] wrote:
> Here is a short course, enjoyment and fun:
>
> Audio speech by Benjamin Freedman in his own voice you can hear here :
>
> http://video.google.com/videoplay?docid=3552214685532803163&q
>
> Free Science History Ebook: THE MANUFACTURE AND SALE of Saint Einstein
>
> The following passage by Benjamin Disraeli (who has very interesting
> quotes in the searcheable free pdf book) at
>
> http://jewishracism.com/SaintEinstein.htm
>
> After Hechler came David Ben-Gurion, who stated,
> "The First World War brought us the Balfour Declaration. The Second
> ought to bring us the Jewish State."1772 .. read the book
>
> Please visit st911.org to view the thriller videos
>
> Terror Storm - Alex Jones
>
> Loose Change - High school kids
>
> and dont forget to view the complete video on the Bohemian Grove by
> Alex Jones
> and the video on Republican Pedophilia, a distinguished record,
>
> Also visit the sites,
>
> www.infowars.comwww.prisonplanet.org
>
> The Professor


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


Question about optparse/OptionParser callback.

2007-02-09 Thread Steven W. Orr
I'm new to python and I have a need to do this.

The Cookbook almost takes me there with:

def check_order(option, opt_str, value, parser):
 if parser.values.b:
 raise OptionValueError("can't use %s after -b" % opt_str)
 setattr(parser.values, option.dest, 1)

but warns that the "it needs a bit of work: the error message and the flag 
that it sets must be generalized". I do need to do my option processing in 
an option processor with many options. Is it possible to have a callback 
that knows how to access all of the options?

Many thanks. All I need is to be taught how to fish...

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Can't import Stackless in Pythonwin

2007-02-09 Thread archaegeo
I am getting started in Python, and I have looked on both the
stackless page and python.org and cannot find the answer to what I
think is a simple problem.

If I start the python command line or idle, i can
>>>import stackless

If I start pythonwin I get the following error
...No Module named Stackless

Any help?

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


Re: Database Programming with Python

2007-02-09 Thread fumanchu
On Feb 9, 7:28 am, [EMAIL PROTECTED] wrote:
> I wanted to connect Python to Ms-Access database using ADO or ODBC. I
> have Python 2.5 and on mxODBC site, it has no higher version build
> than 2.4. Moreoever, mxODBC is required for ADODB.
> Can anyone guide me on this what should I do to make it work on Python
> 2.5? I have python 2.5 running on server.

You could use Dejavu 1.5, which has its own wrapper [1] for ADO (both
MS Access and SQL Server/MSDE). No ODBC necessary or desired.

If you want an ADO wrapper without the full Dejavu ORM, it's possible
(but not heavily documented) to use dejavu's geniusql layer on its
own. That would give you connection mgmt (and pooling), along with the
ability to execute arbitrary SQL.


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

[1] http://projects.amor.org/dejavu/browser/trunk/storage/storeado.py

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


Re: pygame and python 2.5

2007-02-09 Thread Ben Sizer
On Feb 9, 1:48 pm, "siggi" <[EMAIL PROTECTED]> wrote:
> @Ben Sizer

Lucky I spotted this...

> As a Python (and programming ) newbie  allow me a  - certainly naive -
> question:
>
> What is this time consuming part of recompiling an extension, such as
> Pygame, from source code to Windows? Is it a matter of spare time to do the
> job? Or do you have to wait for some Windows modules that are necessary for
> compiling?

The problem is something like this:
 - Python extensions written in C require recompilation for each new
version of Python, due to Python limitations.
 - Recompiling such an extension requires you to have a C compiler set
up on your local machine.
 - Windows doesn't come with a C compiler, so you have to download
one.
 - The compiler that Python expects you to use (Visual Studio 2003) is
no longer legally available.
 - The other compiler that you can use (MinGW) is requires a slightly
convoluted set of steps in order to build an extension.

Hopefully in the future, some of those convoluted steps will be fixed,
but that requires someone putting in the effort to do so. As is often
the case with Python, and indeed many open source projects, the people
who are knowledgeable enough to do such things usually don't need to
do them, as their setup already works just fine.

--
Ben Sizer

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


Re: pygame and python 2.5

2007-02-09 Thread skip
Ben> Python extensions written in C require recompilation for each new
Ben> version of Python, due to Python limitations.

Can you propose a means to eliminate this limitation?

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


Re: pygame and python 2.5

2007-02-09 Thread John Nagle
Ben Sizer wrote:
>  The problem is something like this:
>  - Python extensions written in C require recompilation for each new
> version of Python, due to Python limitations.
>  - Recompiling such an extension requires you to have a C compiler set
> up on your local machine.
>  - Windows doesn't come with a C compiler, so you have to download
> one.
>  - The compiler that Python expects you to use (Visual Studio 2003) is
> no longer legally available.
>  - The other compiler that you can use (MinGW) is requires a slightly
> convoluted set of steps in order to build an extension.
> 
> Hopefully in the future, some of those convoluted steps will be fixed,
> but that requires someone putting in the effort to do so. As is often
> the case with Python, and indeed many open source projects, the people
> who are knowledgeable enough to do such things usually don't need to
> do them, as their setup already works just fine.

True.  There really should be no need to recompile a C extension unless
the linkage format of the C compiler changes, which is a very rare event.
Binary compatibility needs to be improved.

In the GCC world, any compiler since 3.2 should generate interchangeable
output.

http://gcc.gnu.org/onlinedocs/gcc/Compatibility.html

In the Windows world, I'm not sure about compatibility across the
VC6/.NET transition, but I think you only need one version for either
side of that one.

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


Re: Best Free and Open Source Python IDE

2007-02-09 Thread Bastos
On Feb 8, 10:03 am, "Srikanth" <[EMAIL PROTECTED]> wrote:
> Yes,
>
> All I need is a good IDE, I can't find something like Eclipse (JDT).
> Eclipse has a Python IDE plug-in but it's not that great. Please
> recommend.
>
> Thanks,
> Srikanth

Gedit and some plugins, definitely.

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


Re: Best Free and Open Source Python IDE

2007-02-09 Thread km

check out SPE (StanisPpython Editor)
KM

On 9 Feb 2007 10:43:00 -0800, Bastos <[EMAIL PROTECTED]> wrote:


On Feb 8, 10:03 am, "Srikanth" <[EMAIL PROTECTED]> wrote:
> Yes,
>
> All I need is a good IDE, I can't find something like Eclipse (JDT).
> Eclipse has a Python IDE plug-in but it's not that great. Please
> recommend.
>
> Thanks,
> Srikanth

Gedit and some plugins, definitely.

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

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

ANN: Wing IDE 2.1.4 Released

2007-02-09 Thread Wingware Announce
Hi, 

I'm happy to announce version 2.1.4 of Wing IDE, an integrated 
development environment for the Python programming language. 

This is a bug fix release that among other things fixes handling of
UTF-8 byte order marks, improves auto-completion for PyQt 4, reports
exceptions correctly in Python < 2.2, fixes some problems with
Subversion 1.4, does better adaptive scrolling on OS X, and displays
menus correctly in Hebrew locales.

The release can be downloaded from: 

http://wingware.com/downloads 

A detailed list of all changes is available here: 

http://wingware.com/pub/wingide/2.1.4/CHANGELOG.txt 

Wing IDE provides powerful debugging, editing, code intelligence, 
and search capabilities that reduce development and debugging 
time, cut down on coding errors, and make it easier to understand 
and navigate Python code. 

Highlights of Wing IDE 2.1: 

* Professional quality code editor 
* Visual Studio, VI/Vim, Emacs, and Brief key bindings 
* Auto-completion, call tips, and source browser 
* Graphical debugger for Python, Zope, and Plone 
* Subversion, CVS, and Perforce integration 
* Powerful search interface 
* User-extensible with Python scripts 
* Templates (code snippets), bookmarks, folding, macros, and more 

Some features are available in Wing IDE Pro only -- for details 
see http://wingware.com/wingide/features 

This release is available for Windows (2000+), Linux, and Mac OS X 
(10.3+ with X11 installed) and can be compiled from sources on *BSD, 
Solaris, and other Posix operating systems. 

For more information see: 

Product Info:   http://wingware.com/products 
Sales:  http://wingware.com/store/purchase 

Sincerely, 

The Wingware Team 


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


Re: Best Free and Open Source Python IDE

2007-02-09 Thread Szabolcs Nagy

Srikanth wrote:
> Yes,
>
> All I need is a good IDE, I can't find something like Eclipse (JDT).
> Eclipse has a Python IDE plug-in but it's not that great. Please
> recommend.
>
> Thanks,
> Srikanth

try pida
http://pida.co.uk/index.php/Main_Page

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


Re: Database Programming with Python

2007-02-09 Thread Finger . Octopus
> You could use Dejavu 1.5, which has its own wrapper [1] for ADO (both
> MS Access and SQL Server/MSDE). No ODBC necessary or desired.
>
> If you want an ADO wrapper without the full Dejavu ORM, it's possible
> (but not heavily documented) to use dejavu's geniusql layer on its
> own. That would give you connection mgmt (and pooling), along with the
> ability to execute arbitrary SQL.
>
> Robert Brewer
> System Architect
> Amor Ministries
> [EMAIL PROTECTED]
>
> [1]http://projects.amor.org/dejavu/browser/trunk/storage/storeado.py


There are no examples of Dejavu that I found yet. I have installed it
but don't know how to use or call its functions.

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


Re: Can't import Stackless in Pythonwin

2007-02-09 Thread Gabriel Genellina
En Fri, 09 Feb 2007 13:50:56 -0300, <[EMAIL PROTECTED]> escribió:

> I am getting started in Python, and I have looked on both the
> stackless page and python.org and cannot find the answer to what I
> think is a simple problem.
>
> If I start the python command line or idle, i can
 import stackless
>
> If I start pythonwin I get the following error
> ...No Module named Stackless
>
> Any help?
>

Maybe they are different versions, or installed on different places.

In those three environments, execute:

import sys
print sys.version
print sys.executable

All should report the same version.
The executables for both python and IDLE should reside on the same  
directory; for pythonwin, you should get the *same* directory plus  
"Lib\site-packages\pythonwin\Pythonwin.exe"

-- 
Gabriel Genellina

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


Re: from __future__ import absolute_import ?

2007-02-09 Thread Ron Adam
Peter Otten wrote:
> Ron Adam wrote:
> 
>> Peter Otten wrote:
>>> Ron Adam wrote:
>>>
 work
   |
   |- foo.py# print "foo not in bar"
   |
   `- bar
   |
   |- __init__.py
   |
   |- foo.py# print "foo in bar"
   |
   |- absolute.py   # from __futer__ import absolute_import
   |# import foo
   |
   `- relative.py   # import foo


 (4)

 C:\work\bar>python -c "import bar.absolute"
 foo in bar


 (5)

  >>> import bar.absolute
 foo in bar


> (4) and (5) are misconfigurations, IMHO.

But it's a very common configuration.  So it will most likely cause problems 
for 
someone.

 From what I understand these will probably do what I want in python 2.6, which 
is either import the foo not in bar, or give an error if foo not in bar doesn't 
exist instead of importing foo in bar.


>>> in an absolute-import-as-default environment;
>>>
>>> import foo
>>>
>>> would always be an absolute import.
>> But what is the precise meaning of "absolute import" in this un-dotted
>> case?
>>
>> Currently it is:
>>
>>  "A module or package that is located in sys.path or the current
>>  directory".
>>
>> But maybe a narrower interpretation may be better?:
>>
>>  "A module or package found in sys.path, or the current directory
>>   and is *not* in a package."
> 
> You'd have to add a not-in-package test to every import - I don't think it's
> worth the effort.

No, you only need to test the (first) module you explicitly run is in a 
package. 
  For any imports after that, the absolute import code can exclude any of the 
package directories for un-dotted top level absolute imports.  It may be a 
performance net gain because there is less disk searching.


>> All in all, what I'm suggesting is that the concept of a package (type) be
>> much
>> stronger than that of a search path or current directory.  And that this
>> would add a fair amount of reliability to the language.
> 
> I think if you go that way, ultimately you will need some kind of package
> registry. I expect that the new import behaviour will get you 99 percent
> there with one percent of the hassle. But we will see...

It won't need a registry.

Check the python-ideas list for further discussion on this.

Cheers,
Ron

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


Thanks to all

2007-02-09 Thread jiddu
Thanks for all the input guys, I know it is difficult, but the calculators
and statistic sites/books are missing some things which I need for my play
so I guess I have no choice but to study up and work.

When I was learning C++ I wrote some code to calculate simple things like
probability of 1 or more player to have pocket pair in 9 handed game, its
not finished but I realised I need to use some kind of database and
someone suggested to me try python because it will be easier to learn.

Again thanks for the help guys

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


Re: pygame and python 2.5

2007-02-09 Thread Mike C. Fletcher
[EMAIL PROTECTED] wrote:
> Ben> Python extensions written in C require recompilation for each new
> Ben> version of Python, due to Python limitations.
>
> Can you propose a means to eliminate this limitation?
>   
Sure, write your wrapper-style extensions in ctypes :) .  For example, 
pygame-ctypes[1] should work on Python 2.5.  Of course, you need to get 
the PyGame dependencies (SDL) installed via some external mechanism, but 
the ctypes-based code should run in Python 2.5 today (with the caveat 
that it's not finished software).

[1] http://www.pygame.org/ctypes/

Have fun,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: Referencing vars, methods and classes by name

2007-02-09 Thread Terry Reedy

"Sagari" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Thanks to everyone for all the comments. I am migrating from PHP to
| Python and I am looking for the means to port a controller code that
| would, roughly speaking, call a certain method of a certain class
| (both class and method names taken from user input). Putting aside
| input verification (by the moment I perform the call input must have
| been verified), what would be the recommended way of doing the trick?

Use getattr(ob, name).
Suppose
mod = 
cname = 
mname = 

Then
classobj = getattr(mod, cname)
methobj = getattr(classobj, mname)

However: Python generally uses methods for instance methods.  Would you be 
creating an instance of the class (easily done -- inst = classobj(args)) 
before calling the method?  If so, call methodobj(inst, args).  If not, I 
wonder I you should really be using (Python) classes.

Terry Jan Reedy



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


Re: Best Free and Open Source Python IDE

2007-02-09 Thread Stef Mientki
Szabolcs Nagy wrote:
> Srikanth wrote:
>> Yes,
>>
>> All I need is a good IDE, I can't find something like Eclipse (JDT).
>> Eclipse has a Python IDE plug-in but it's not that great. Please
>> recommend.
>>
>> Thanks,
>> Srikanth
> 
> try pida
> http://pida.co.uk/index.php/Main_Page
> 
nice idea to re-use components you already have.

Which brings me to some other questions on waste:
- isn't it a pitty so many people are involved in writing another editor / IDE ?
- isn't it a waste for newbies to evaluate a dozen editors / IDE's ?

What anser do we really give here ?
Aren't we just telling the guy,
what we've chozen (with our limited overview of our newbie time) ;-)
(sorry, I also gave an answer ;-)

Can't we persuade the next newbie, asking this question,
to start some kind of wiki page,
where the differences between editors / IDE's are listed ?

Unfortunately he number of IDE's / editors is so large,
a simple 2 dimensional array of features would become too large ;-)
Maybe a first split would be the required OS ?
Next split could be editor-features and IDE features ?

just some thoughts,
of a some months old newbie,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thanks to all

2007-02-09 Thread Grant Edwards
On 2007-02-09, jiddu <[EMAIL PROTECTED]> wrote:

> Thanks for all the input guys, I know it is difficult, but the
> calculators and statistic sites/books are missing some things
> which I need for my play so I guess I have no choice but to
> study up and work.

You're most welcome.

Though I really have no idea whom you're thanking or for what
you're thanking them [a situation remedied by posting your
thank-you as a follow-up to the relevent thread], it would be
rude for nobody to acknowledge your thanks.  ;)

-- 
Grant Edwards   grante Yow!  ... this must be what
  at   it's like to be a COLLEGE
   visi.comGRADUATE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pygame and python 2.5

2007-02-09 Thread skip

Ben> Python extensions written in C require recompilation for each new
Ben> version of Python, due to Python limitations.

>> Can you propose a means to eliminate this limitation?

Mike> Sure, write your wrapper-style extensions in ctypes :).

I was think more along the lines of how could the Python extension module
API change so that for example, modules compiled for Python 2.6 would
continue to work without warning under Python 2.7.  Maybe ctypes is the
answer, but suspect it addresses a different API than I was thinking of.

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


Re: python linux distro

2007-02-09 Thread [EMAIL PROTECTED]
Try this. It's a pre-build VMware image.

Torrent hasn't worked for me. I tracked down a physical copy.

http://www.vmware.com/vmtn/appliances/directory/289

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


Re: pygame and python 2.5

2007-02-09 Thread Ben Sizer
On Feb 9, 5:53 pm, [EMAIL PROTECTED] wrote:
> Ben> Python extensions written in C require recompilation for each new
> Ben> version of Python, due to Python limitations.
>
> Can you propose a means to eliminate this limitation?

By putting an intermediate layer between the extensions and the
language. I suppose this is essentially what ctypes does, except from
the other direction.

If someone could explain the limitation in detail, I expect ways could
be found around it. After all, I don't know of any other systems that
require you to recompile all the extensions when you upgrade the
application.

Winamp is one application that comes to mind which has kept plugins
working across many upgrades. I doubt they're still compiling with
Visual Studio 6. Perhaps it works because they have a more restrictive
API that isn't passing non-primitive types across the DLL boundary.

--
Ben Sizer

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


Re: ANN: Wing IDE 2.1.4 Released

2007-02-09 Thread Damjan
> This is a bug fix release that among other things fixes handling of
> UTF-8 byte order marks, 

What are UTF-8 byte order marks ?!? 
There's only one order in the UTF-8 bytes!


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


Re: ANN: Wing IDE 2.1.4 Released

2007-02-09 Thread Robert Kern
Damjan wrote:
>> This is a bug fix release that among other things fixes handling of
>> UTF-8 byte order marks, 
> 
> What are UTF-8 byte order marks ?!? 
> There's only one order in the UTF-8 bytes!

It's a misnomer, but one that persists.

  http://unicode.org/unicode/faq/utf_bom.html#29

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: os.popen and broken pipes

2007-02-09 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 Philipp Pagel <[EMAIL PROTECTED]> wrote:

> Antoon Pardon <[EMAIL PROTECTED]> wrote:
> > On 2007-02-09, Philipp Pagel <[EMAIL PROTECTED]> wrote:
> > > for filename in file_list:
> > > file = os.popen('uncompress -c '+filename, 'r')
> > > do_something(file)
> > > file.close()
> > >
> > > This works fine for some files but results in
> > >
> > > 'write error onstdout: Broken pipe'
> 
> > As far as I can tell, your do_something doesn't consume the entire file.
> > So you close the file prematurly, which results in the uncompress/zcat
> > program trying to write to a pipe that is closed on the otherside,
> > giving you the above message.
> 
> You are right: some of the files do not fulfill certain
> critereia causing so_somehting() to return before the entire file is
> processed.

Most programming environments don't have this problem, though.

If you like, your program can undo what Python does:

signal.signal(signal.SIGPIPE, signal.SIG_DFL)
for filename in file_list:
...

Then it will work as if you had written it in C, or awk
or whatever.

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


[pywin32] - Excel COM problem

2007-02-09 Thread Andrea Gavana
Hi All,

   I have a very simple python script that tries to put a rectangular
shape in a worksheet and then add some text inside that shape. The
main problem, is that as usual Excel doesn't like input strings longer
than 200 and something characters. So, by just recording a macro in
Excel, I tried to append the text in the shape by dividing it in
chunks. For example, I tried this little script:

#--
from win32com.client import Dispatch

finalText = "A"*1250

xlsapp = Dispatch("Excel.Application")
wb = xlsapp.Workbooks.Add()
sheet = wb.Sheets[0]

myShape = sheet.Shapes.AddShape(1, 315, 200, 400, 300)
myShape.Select()

xlsapp.Selection.Characters.Text = finalText[0:200]
xlsapp.Selection.Characters(200).Insert(finalText[200:400])

excelfile = "Hello.xls"
wb.SaveAs(excelfile)
wb.Close()
xlsapp.Quit()

#--

And it crashes with an impossible error:

Traceback (most recent call last):
 File "D:\MyProjects\pywin32.py", line 13, in 
   xlsapp.Selection.Characters(200).Insert(finalText[200:400])
 File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 172, in
__call__
   return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.
defaultDispatchName,None)
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)

However, the macro I recorded in Excel does exactly that: it appends
chunks of the string with a maximum length of 200 chars.
Am I missing something here?
This is with Python 2.5, PythonWin 2.5 (r25:51908, Sep 19 2006,
09:52:17) [MSC v.1310 32 bit (Intel)] on win32, Windows XP SP2.

Thank you for your consideration.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending CTRL-C event to console application

2007-02-09 Thread Daniel Clark
On Feb 9, 9:12 am, "Daniel Clark" <[EMAIL PROTECTED]> wrote:
> I'm going to try taking a different approach by using a GUI Automation
> tool like WATSUP [1] or pywinauto[2] next.

This works:

AutoIT [1] code (compiled to an executable):
Run(@ComSpec & ' /k ' & $CmdLineRaw )
This was necessary because other means of starting cmd.exe didn't
actually spawn a new window. Syntax is just like:
C:\> autoitrun.exe "cd c:\Program Files\Tivoli\TSM & dir /s/p"
And that will pop up a new cmd.exe window with a dir /s/p listing of
cd c:\Program Files\Tivoli\TSM

Python code (changes service to be able to interact with desktop and
then runs the above):

import win32service
import os, sys

def EnsureInteractiveService(servicename):
scm = win32service.OpenSCManager(None, None,
win32service.SC_MANAGER_ALL_ACCESS)
try:
svc = win32service.OpenService(scm, servicename,
win32service.SC_MANAGER_ALL_ACCESS)
except:
print '''Error: Couldn't open service with name "''' +
servicename + '''"'''
sys.exit(1)
oldsvccfg = win32service.QueryServiceConfig(svc)
win32service.ChangeServiceConfig(svc, # scHandle
 oldsvccfg[0] |
win32service.SERVICE_INTERACTIVE_PROCESS, # serviceType
 oldsvccfg[1], # startType
 oldsvccfg[2], # errorControl
 oldsvccfg[3], # binaryFile
 oldsvccfg[4], # loadOrderGroup
 oldsvccfg[5], # bFetchTag
 oldsvccfg[6], # serviceDeps
 oldsvccfg[7], # acctName
 '', # password
 oldsvccfg[8]) # displayName
win32service.CloseServiceHandle(svc)
win32service.CloseServiceHandle(scm)

EnsureInteractiveService("TSM for WPLC")
os.chdir("c:\\Program Files\\WPLC-TSM\\updates")
os.system("autoitrun.exe dir /s/p")

[1] AutoIt v3 - Automate and Script Windows Tasks
http://www.autoitscript.com/autoit3/

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


interacting with shell - another newbie question

2007-02-09 Thread James
Hello,

I work in this annoying company where I have to autheticate myself to
the company firewall every 30-50 minutes in order to access the
internet.  (I think it's a checkpoint fw).

I have to run "telnet what.ever.ip.address 259" then it prompts me
with userid, then password, then I have to select "1".  Then the
program closes itself and the internet is enabled.

I would like to automate this process with Python and run it every 30
miniutes so I don't have to keep typing in these userid/password
everytime.  How can this be done?  Is there a module I can use to
interact with the shell? (I'm running linux)

Thank you.

James

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


Re: pygame and python 2.5

2007-02-09 Thread skip

Ben> If someone could explain the limitation in detail, I expect ways
Ben> could be found around it. After all, I don't know of any other
Ben> systems that require you to recompile all the extensions when you
Ben> upgrade the application.

Python used to work that way.  You'd then silently get errors if the API
changed between version A and version B and you neglected to recompile the
extensions you compiled against version A.  Maybe the Python extension API
is mature enough now that it can be frozen, but I sort of doubt it.

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


Retry:Question about optparse/OptionParser callback.

2007-02-09 Thread Steven W. Orr
I decided I could be more articulate. I hope this helps.

I'm writing a program that needs to process options. Due to the nature of 
the program with its large number of commandline options, I would like to 
write a callback to be set inside add_option.

Something like this:

parser.add_option("-b", action="callback", callback=optionhandlr, dest='b')

The Cookbook almost takes me there with a callback function that only 
works for an option called b that takes no argument:

def optionhndlr(option, opt_str, value, parser):
  if parser.values.b:
  raise OptionValueError("can't use %s after -b" % opt_str)
  setattr(parser.values, option.dest, 1)

but warns that "it needs a bit of work: the error message and the flag 
that it sets must be generalized". I do need to do my option processing in 
an option processor with many options and I'd both like to do it in one 
method (if possible) and learn a trick or two while I'm at it. Is it 
possible to have a single callback that could be used in the general case?

All I need is to be taught how to fish...

TIA

--
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Django, one more newbie question

2007-02-09 Thread Boris Ozegovic
Umm, can somebody tell me which language is this one:

{% if latest_poll_list %}

{% for poll in latest_poll_list %}
{{ poll.question }}
{% endfor %}

{% else %}
No polls are available.
{% endif %}

Whole tutorial is on this page:
http://www.djangoproject.com/documentation/tutorial3/
 
endfor, endif, {{?  :)

-- 
http://www.nacional.hr/articles/view/23894/23
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Django, one more newbie question

2007-02-09 Thread Robert Kern
Boris Ozegovic wrote:
> Umm, can somebody tell me which language is this one:
> 
> {% if latest_poll_list %}
> 
> {% for poll in latest_poll_list %}
> {{ poll.question }}
> {% endfor %}
> 
> {% else %}
> No polls are available.
> {% endif %}
> 
> Whole tutorial is on this page:
> http://www.djangoproject.com/documentation/tutorial3/
>  
> endfor, endif, {{?  :)

It's the Django templating language:

  http://www.djangoproject.com/documentation/templates/

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: pygame and python 2.5

2007-02-09 Thread bearophileHUGS
Skip:
> Python used to work that way.  You'd then silently get errors if the API
> changed between version A and version B and you neglected to recompile the
> extensions you compiled against version A.

Can't the compiled module have one or more test functions that can be
used during linking to see if the compiled module respects the
expected standard?

Bye,
bearophile

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


Re: python linux distro

2007-02-09 Thread Szabolcs Nagy

> Now what would be interesting (and *really* crazy) would be Linux (or
> BSD or whatever) distro written almost entirely *in* Python, with the
> goal of eliminating as much bash/sh as possible.
>
> That would be fun.

actually there was(is) an os whitch is written "almost entirely *in*
Python":
http://en.wikipedia.org/wiki/Unununium_(operating_system)

(their main site http://unununium.org seems to be down)

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


Re: Database Programming with Python

2007-02-09 Thread fumanchu
On Feb 9, 11:03 am, [EMAIL PROTECTED] wrote:
> There are no examples of Dejavu that I found yet. I have installed it
> but don't know how to use or call its functions.

Read http://projects.amor.org/docs/dejavu/1.5.0RC1/ to learn how to
use Dejavu. It's short and should at least give you an idea whether or
not Dejavu is right for you.


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

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


Re: interacting with shell - another newbie question

2007-02-09 Thread Larry Bates
James wrote:
> Hello,
> 
> I work in this annoying company where I have to autheticate myself to
> the company firewall every 30-50 minutes in order to access the
> internet.  (I think it's a checkpoint fw).
> 
> I have to run "telnet what.ever.ip.address 259" then it prompts me
> with userid, then password, then I have to select "1".  Then the
> program closes itself and the internet is enabled.
> 
> I would like to automate this process with Python and run it every 30
> miniutes so I don't have to keep typing in these userid/password
> everytime.  How can this be done?  Is there a module I can use to
> interact with the shell? (I'm running linux)
> 
> Thank you.
> 
> James
> 

You shouldn't have to work through the shell.  Just connect
directly via telnetlib.  Here is an example that you should
be able to modify easily to meet your needs.

http://docs.python.org/lib/telnet-example.html

-Larry

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


Re: huge amounts of pure Python code broken by Python 2.5?

2007-02-09 Thread Klaas
On Feb 8, 6:37 pm, "kernel1983" <[EMAIL PROTECTED]> wrote:
> On Feb 9, 10:29 am, "Klaas" <[EMAIL PROTECTED]> wrote:

> > The changes listed dont' seem particularly huge considering the size,
> > complexity, and boundary-pushingness of Twisted, coupled with the
> > magnitude of the 2.5 release.
>
> Just keep using python2.4

I have converted our 100 kloc from 2.4 to 2.5.  It was relatively
painless, and 2.5 has features we couldn't live without.

-Mike

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


Re: A little more advanced for loop

2007-02-09 Thread Larry Bates
Horta wrote:
> On Feb 9, 9:00 am, Stephan Diehl <[EMAIL PROTECTED]> wrote:
>> Horta wrote:
>>> Hi folks,
>>>   Suppose I have to loop over 3 lists being the same size at the same
>>> time and order. How can I do that without using the range() function
>>> or whatever indexing?
>>> Example using range:
>>> a = ['aaa', '']
>>> b = ['bb', '']
>>> c = ['c', '']
>>> for i in range(len(a)):
>>> # using a[i], b[i], and c[i]
>>>   I'm sure there's a elegant way to do that...
>>>   Thanks in advance.
>> Sure, there is:
>>
>> for a_item, b_item , c_item in zip(a,b,c):
>> # do something
> 
>   Thanks guys!
> 
Note: if lists are long take a look at itertools izip.  zip creates
a list of lists which could take lots of memory/time if they are VERY
large.  itertools izip iterates over them in place.

from itertools import izip

for a_item, b_item, c_item in izip(a,b,c):
# do something

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


Re: multithreading concept

2007-02-09 Thread sturlamolden
On Feb 9, 4:00 pm, "S.Mohideen" <[EMAIL PROTECTED]>
wrote:

> I am sorry if I sound foolish.
> Suppose I split my Net application code using parallel python into several
> processes based upon the number of CPU available. That means a single socket
> descriptor is distributed across all processes. Is parallelity can be
> acheived using the processes send/recv on the single socket multiplexed
> across all the processes.. I haven't tried it yet - would like to have any
> past experience related to this.

Is CPU or network the speed limiting factor in your application? There
are two kinds of problems: You have a 'CPU-bound problem' if you need
to worry about 'flops'. You have an 'I/O bound' problem if you worry
about 'bits per second'.

If your application is I/O bound, adding more CPUs to the task will
not help. The network connection does not become any faster just
because two CPUs share the few computations that need to be performed.
Python releases the GIL around all i/o operations in the standard
library, such as reading from a socket or writing to socket. If this
is what you need to 'parallelize', you can just use threads and ignore
the GIL. Python's threads can handle concurrent I/O perfectly well.
Remember that Google and YouTube use Python, and the GIL is not a show
stopper for them.

The GIL locks the process to one CPU. You need to get around this if
the power of one CPU or CPU core limits the speed of the application.
This can be the case in e.g. digital image processing, certain
computer games, and scientific programming. I have yet to see a CPU-
bound 'Net application', though.

If you are running Windows: take a look at the CPU usage in the task
manager. Does it say that one of the CPUs is running at full speed for
longer periods of time? If not, there is noting to gained from using
multiple CPUs.







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


  1   2   >