Re: OT: regular expression matching multiple occurrences of one group

2009-11-09 Thread Gabriel Genellina
En Mon, 09 Nov 2009 12:59:53 -0300, Jon Clements   
escribió:

On Nov 9, 1:53 pm, pinkisntwell  wrote:



How can I make a regular expression that will match every occurrence
of a group and return each occurrence as a group match? For example,
for a string "-c-c-c-c-c", how can I make a regex which will return a
group match for each occurrence of "-c"?


As well as what Diez has said, unless you absolutely want regexp's,
and by the sounds of it I'm guessing you may be after something more
flexible: what about the pyparsing module [1]. It handles your
situation quite nicely.


import pyparsing
parser = pyparsing.ZeroOrMore('-c')
parser.parseString('-c-c-c-c-c-c')

(['-c', '-c', '-c', '-c', '-c', '-c'], {})


Not that I like regexes very much, but findall does exactly that:

py> re.findall('-c', '-c-c-c-c-c-c')
['-c', '-c', '-c', '-c', '-c', '-c']

Now, the OP said "return each occurrence as a group match":

py> for g in re.finditer("-c", '-c-c-c-c-c-c'): print g, g.span(),  
g.group()

...
<_sre.SRE_Match object at 0x00C096E8> (0, 2) -c
<_sre.SRE_Match object at 0x00C09410> (2, 4) -c
<_sre.SRE_Match object at 0x00C096E8> (4, 6) -c
<_sre.SRE_Match object at 0x00C09410> (6, 8) -c
<_sre.SRE_Match object at 0x00C096E8> (8, 10) -c
<_sre.SRE_Match object at 0x00C09410> (10, 12) -c

--
Gabriel Genellina

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


Re: how to create a pip package

2009-11-09 Thread Gabriel Genellina

En Tue, 10 Nov 2009 00:48:26 -0300, Phlip  escribió:


I have a single file that I need my crew to pip install.

When I Google for "how to create a pip package" I don't hit anything.
Of course that info is out there; I can't seem to pick up the trail of
breadcrumbs to it.


See http://pip.openplans.org/
You're looking for the "freeze" command.

--
Gabriel Genellina

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


Re: on "Namespaces"

2009-11-09 Thread Steven D'Aprano
On Sun, 08 Nov 2009 13:20:23 -0800, webtourist wrote:

> New bie Question:
> in "Zen of Python" - what exactly does the last one mean ? - Namespaces
> are one honking great idea -- let's do more of those!
> 
> I mean why the emphasis ? Is it like saying "put modules into packages"
> in other programming paradigm s ?

Modules are namespaces. So are packages.

Classes and class instances are namespaces.

Even function scopes are namespaces. When you write:


n = None

def spam(n):
print "spam" * n

def ham(n):
print "ham" * n

the n inside spam() and ham() and the global n are in different 
namespaces, and so independent.


http://en.wikipedia.org/wiki/Namespace
http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces


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


Re: Most efficient way to "pre-grow" a list?

2009-11-09 Thread Gabriel Genellina
En Sun, 08 Nov 2009 10:08:35 -0300, gil_johnson  
 escribió:

On Nov 6, 8:46 pm, gil_johnson  wrote:

The problem I was solving was this: I wanted an array of 32-bit
integers to be used as a bit array, and I wanted it initialized with
all bits set, that is, each member of the array had to be set to
4294967295. Of course, you could set your initializer to 0, or any
other 32-bit number.

Originally I found that the doubling method I wrote about before was a
LOT faster than appending the elements one at a time, and tonight I
tried the "list = initializer * N" method. Running the code below, the
doubling method is still fastest, at least on my system.

Of course, as long as you avoid the 'one at a time' method, we're
talking about fractions of a second, even for arrays that I think are
huge, like the 536,870,912 byte beastie below.


I don't get your same results; one_item*N is faster on my tests. Note that  
you're comparing disparate things:



# Doubling method, run time = 0.413938045502
newArray = array.array('I') # 32-bit unsigned
integers


Method 1 creates an array object; this takes roughly 2**29 bytes


# One at a time, run time = 28.5479729176
newArray2 = array.array('I')
for i in range(134217728):# the same size as above
newArray2.append(4294967295)


This creates also an array object, *and* 134 million integer objects in  
the meantime.



# List with "*", run time = 1.06160402298
newList = [4294967295] * 134217728


And this creates a list object, not an array.

Note that all your 3 methods create global objects and you never delete  
them - so the last method is at a disadvantage.

A more fair test would use timeit, and run just one method at a time:


# Written in Python 3.x
# use xrange everywhere with Python 2.x

import array

INITIAL_VALUE = 4294967295
LOG2SIZE=25
SIZE = 2**LOG2SIZE

def method1a():
  newArray = array.array('I')
  newArray.append(INITIAL_VALUE)
  for i in range(LOG2SIZE):
newArray.extend(newArray)
  assert len(newArray)==SIZE
  assert newArray[SIZE-1]==INITIAL_VALUE

def method2a():
  newArray = array.array('I')
  for i in range(SIZE):
newArray.append(INITIAL_VALUE)
  assert len(newArray)==SIZE
  assert newArray[SIZE-1]==INITIAL_VALUE

def method3a():
  newArray = array.array('I', [INITIAL_VALUE]) * SIZE
  assert len(newArray)==SIZE
  assert newArray[SIZE-1]==INITIAL_VALUE

def method1l():
  newList = [INITIAL_VALUE]
  for i in range(LOG2SIZE):
newList.extend(newList)
  assert len(newList)==SIZE
  assert newList[SIZE-1]==INITIAL_VALUE

def method2l():
  newList = []
  for i in range(SIZE):
newList.append(INITIAL_VALUE)
  assert len(newList)==SIZE
  assert newList[SIZE-1]==INITIAL_VALUE

def method3l():
  newList = [INITIAL_VALUE] * SIZE
  assert len(newList)==SIZE
  assert newList[SIZE-1]==INITIAL_VALUE


D:\temp>python31 -m timeit -s "from arraygrow import method1a" "method1a()"
10 loops, best of 3: 411 msec per loop

D:\temp>python31 -m timeit -s "from arraygrow import method2a" "method2a()"
...aborted, too long...

D:\temp>python31 -m timeit -s "from arraygrow import method3a" "method3a()"
10 loops, best of 3: 377 msec per loop

D:\temp>python31 -m timeit -s "from arraygrow import method1l" "method1l()"
10 loops, best of 3: 628 msec per loop

D:\temp>python31 -m timeit -s "from arraygrow import method3l" "method3l()"
10 loops, best of 3: 459 msec per loop

So arrays are faster than lists, and in both cases one_item*N outperforms  
your doubling algorithm.
Adding one item at a time is -at least- several hundred times slower; I  
was not patient enough to wait.



Finally, I just looked into calling C functions, and found
PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management
section of the Python/C API Reference Manual. This gives you
uninitialized memory, and should be really fast, but it's 6:45 AM
here, and I don't have the energy to try it.


No, those are for internal use only, you can't use the resulting pointer  
in Python code. An array object is a contiguous memory block, so you don't  
miss anything.


--
Gabriel Genellina

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


Re: sort values from dictionary of dictionaries python 2.4

2009-11-09 Thread Steven D'Aprano
On Mon, 09 Nov 2009 06:02:09 -0800, J Wolfe wrote:

> Hi,
> 
> I would like to sort this dictionary by the values of the inner
> dictionary ‘ob’ key.

You can't sort dictionaries in Python, because they are unordered hash 
tables. Giving up the ability to store items in order is one of the 
things which makes them so fast.

You have five choices:

(1) Create your own implementation of a sortable dictionary, perhaps 
using a red-black tree or similar. Unless you write it in C, expect it to 
be massively slower than the built-in dict type. If you write it in C, 
expect it to be merely slower than the built-in dict type.

(2) Write small helper functions that sort the keys from the dict when 
you need them sorted. Since you (probably) only have a small number of 
items in each dict, it should be fast.

(3) Use a subclass of dict that sorts the items as needed.

(4) Give up on using dictionaries for this, and use some other mapping, 
like a list of (key, value) tuples. Expect it to be massively slower than 
the built-in dict type.

(5) Give up on the need to have them sorted.


My advice is to go with #2, 3 or 5. Here's a basic version of 3 to get 
you started:

class SortedDict(dict):
# Untested.
def items(self):
"""Return items of self in sorted order."""
L = super(SortedDict, self).items()
L.sort()
return L

You may even find a version with an appropriate licence you can freely 
use if you google for "Python Sorted Dict".




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


how to create a pip package

2009-11-09 Thread Phlip
Py hont:

I have a single file that I need my crew to pip install.

When I Google for "how to create a pip package" I don't hit anything.
Of course that info is out there; I can't seem to pick up the trail of
breadcrumbs to it.

While I'm looking, could someone push the link in here? Purely for
posterity? Thanks!

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to get the Physical memory address of a variable in python?

2009-11-09 Thread Carl Banks
On Nov 9, 4:47 pm, Ognjen Bezanov  wrote:
> Hello all,
>
> Say I have a python variable:
>
> a = "hello"
>
> Is it possible for me to get the physical address of that variable (i.e.
> where it is in RAM)?
>
> I know that id(a) will give me it's memory address, but the address
> given does not seem to correlate with the physical memory. Is this even
> possible?


I'm going to guess that

A. You don't really want physical address but logical address (i.e.,
the address where you might access the memory with a C pointer), and

B. You want the address not of the object itself, but of the data
within (that is, you'd want the "pointer" you receive to point to the
ASCII string hello)

Python's way to handle cases like this is called buffer protocol, but
it only operates at the C-extension level.  There is a set of
functions in the C API that look like this

PyObject_AsReadBuffer(obj,**buffer,*len)

Calling this will return the address of the string "hello" in
*buffer.   See C API Reference Manual for more details.  This function
can also be called from ctypes, but I don't remember the exact
procedure for modifying input arguments through a pointer.

Note: If you really want a PHYSCIAL RAM address you'll have to make
some OS-specific system call (I think) with the logical address,
probably needing superuser privileges.  Obviously this call isn't
exposed in Python, because there's no use for it in Python.  Unless
you're programming DMA transfers or something like that, there's no
use for it in C, either.


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


Re: Is it possible to get the Physical memory address of a variable in python?

2009-11-09 Thread Dave Angel

Benjamin Kaplan wrote:

On Mon, Nov 9, 2009 at 7:47 PM, Ognjen Bezanov  wrote:
  

Hello all,

Say I have a python variable:

a = "hello"

Is it possible for me to get the physical address of that variable (i.e.
where it is in RAM)?

I know that id(a) will give me it's memory address, but the address given
does not seem to correlate with the physical memory. Is this even possible?


Thank you!


Ognjen




When you use Python, program in Python and not C. What do you need the
memory location of a variable for? Python, like Java and .NET is a
higher level language. You're not supposed to worry about things like
the physical location in memory. There's probably some ugly hack using
ctypes, or just writing the code in C but I don't know enough about
Python's C API to know what it is.

FWIW, even the id(x) == address of x is only an implementation detail
of CPython. Other Python implementations don't use that scheme.

  

Following is for the CPython implementation.  As Benjamin says, each 
implementation can do different things, as long as the documented 
semantics are preserved.


The "variable" aaa is not at any particular location, and will quite 
likely move when you define a new "variable" bbb or ccc in the same 
scope.  aaa is just a dictionary entry after all, in some scope.  
(Although it may be optimized, for locals, and for slots)


aaa is bound to a particular object, and that object won't move.  That 
object has an id() value, and I believe that id value is the address.   
And when you bind aaa to a different object, there'll be a different 
id() and address.  But unless you're writing a C extension, the actual 
address is kind of irrelevant, isn't it?


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


Re: Debugging python in emacs isn't working.

2009-11-09 Thread menomnon
On Nov 8, 6:36 pm, menomnon  wrote:
> Hi,
>
> Emacs 22.3, python 2.6.4
>
> Put the following into my .emacs:
>
> (setq pdb-path 'c:\\python26\\lib\\pdb.py
>       gud-pdb-command-name (symbol-name pdb-path))
> (defadvice pdb (before gud-query-cmdline activate)
>   "Provide a better default command line when called interactively."
>   (interactive
>    (list (gud-query-cmdline pdb-path
>                             (file-name-nondirectory buffer-file-name)
>
> So when I'm in a python buffer (I've tried both python.el and python-
> mode.el) and do M-x pdb I get, say:
>
> c:\python26\lib\pdb.py rpytest.py
>
> hit  and get an empty buffer that says "Comint: no process".  And
> the status line says: "Spawning child process: invalid argument".
>
> I've run into "spawning child process: invalid argument" before but
> not being an emacs uber-geek I never solved it directly.
>
> Hope someone has an idea of what I'm doing wrong.

python -i.  It's the -i part that's important.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comparing alternatives to py2exe

2009-11-09 Thread Gabriel Genellina
En Fri, 06 Nov 2009 17:00:17 -0300, Philip Semanchuk  
 escribió:

On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote:


Recently I put together this incomplete comparison chart in an attempt
to choose between the different alternatives to py2exe:

http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html


I was interested in py2exe because we'd like to provide a one download,  
one click install experience for our Windows users. I think a lot of  
people are interested in py2exe for the same reason. Well, one thing  
that I came across in my travels was the fact that distutils can create  
MSIs. Like py2exe, MSIs provide a one download, one click install  
experience under Windows and therefore might be a replacement for py2exe.


But py2exe and .msi are complementary, not a replacement.
py2exe collects in one directory (or even in one file in some cases) all  
the pieces necesary to run your application. That is, Python itself + your  
application code + all referenced libraries + other required pieces.
The resulting files must be installed in the client machine; you either  
build a .msi file (a database for the Microsoft Installer) or use any  
other installer (like InnoSetup, the one I like).


For me, the following command was sufficient to create an msi, although  
it only worked under Windows (not under Linux or OS X):

python setup.py bdist_msi

The resulting MSI worked just fine in my extensive testing (read: I  
tried it on one machine).


The resulting .msi file requires Python already installed on the target  
machine, if I'm not mistaken. The whole point of py2exe is to avoid  
requiring a previous Python install.


It seems, then, that creating an MSI is even within the reach of someone  
like me who spends very little time in Windows-land, so it might be  
worth a column on your chart alongside rpm/deb.


As said in http://wiki.python.org/moin/DistributionUtilities the easiest  
way is to use py2exe + InnoSetup.


--
Gabriel Genellina

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


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Dave Angel

Victor Subervi wrote:

On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi wrote:

  

On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury wrote:







Hold everything. Apparently line-endings got mangled. What I don't


understand is why I didn't see them when I opened the file to edit, and why
they didn't copy and paste when I did that. But dos2unix cleaned up a couple
of files so I presume it will clean up the rest. However, I tried one file,
that reads exactly the same as index.py, and when I surfed to it got a 500
error. Here's what the log said:


  

What I've diagnosed as happening when a python script with Windows 
line-ending was posted on my server's cgi environment:


The actual error seemed to be a failure to find the python interpreter, 
since some Unix shells take the shebang line to include the \r character 
that preceded the newline.   Seems to me they could be more tolerant, 
since I don't think control characters are likely in the interpreter 
file name.


DaveA

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


Re: pythonw.exe under Windows-7 (Won't run for one admin user)

2009-11-09 Thread Rhodri James

On Fri, 06 Nov 2009 21:19:44 -, SD_V897  wrote:


Rhodri James wrote:
On Tue, 03 Nov 2009 16:00:16 -, SD_V897   
wrote:


I have a perplexing issue, I have four users set up on a W7 computer.  
The program runs fine for all users except the admin user who needs it  
for school assignments.

 A little more information, please.  How does it not work for the admin
user?  Is there a traceback?  What do you get if you try to invoke it
from a command line?




Hi Rhodri, here's a dump file, don't know if this helps or not..


So Windows is reporting a crash, then.  I'll repeat my last question in  
particular; what happens when your admin user runs the program you're  
trying to invoke from the command line?


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: NEWB problem with urllib2

2009-11-09 Thread Penn

Thanks Simon!

You are right.. I also believe it is something with Eclipse.

I've been working since... the module below runs.. but Eclipse is
still showing an error when I reference urlopen with a little red X...
saying it is an undefined variable in the IDE.. but not giving me an
runtime errors.




#URL LIBRARY
from urllib2 import *


def openfilereadaline(a):

f = open(a)
print f
for line in f:
print line.rstrip()
f.close()

def openWebSite(a):

ur = urlopen(a) #open url
contents = ur.readlines()#readlines from url file
fo = open("test.txt", "w")#open test.txt
for line in contents:
print "writing %s to a file" %(line,)
fo.write(line)#write lines from url file to text file
fo.close()#close text file

if __name__ == '__main__':

openWebSite("http://www.daniweb.com/forums/thread161312.html";)

print "Hello World"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: on "Namespaces"

2009-11-09 Thread Rhodri James
On Sun, 08 Nov 2009 21:20:23 -, webtourist   
wrote:




New bie Question:
in "Zen of Python" - what exactly does the last one mean ? -
Namespaces are one honking great idea -- let's do more of those!

I mean why the emphasis ? Is it like saying "put modules into
packages" in other programming paradigm s ?


Like all things zen, 'meaning' as applied to this koan is a shifting  
concept best considered after deep meditiation on... oh, who am I kidding.


If you keep names in separate namespaces, you are less likely to screw up  
by forgetting that you meant something else by that name 30 lines above.   
It's less about "put modules in packages" and more about "put code in  
modules."


Corollary: what happens after "from somewhere import *" is all your own  
fault.


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to get the Physical memory address of a variable in python?

2009-11-09 Thread MRAB

Ognjen Bezanov wrote:

Hello all,

Say I have a python variable:

a = "hello"

Is it possible for me to get the physical address of that variable (i.e. 
where it is in RAM)?


I know that id(a) will give me it's memory address, but the address 
given does not seem to correlate with the physical memory. Is this even 
possible?



Python doesn't have variables as such. The variable's name is just a key
in a dict and the variable's value is the corresponding value for that
key (or, to be exact, a reference to the value). A particular value can
be referred to by any number of 'variables'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: NEWB problem with urllib2

2009-11-09 Thread Simon Forman
On Mon, Nov 9, 2009 at 6:29 PM, Penn  wrote:
> I just installed PyDev into Eclipse using the 'update' method and did
> the standard installation.  I allowed it to Auto Configure itself and
> ran a "Hello World" module to make sure I was in the ballpark.
>
> I got an starting module up and have run "Hello World" but now am
> stuck on getting urlopen to import from urllib2 for the following
> example.
>
> from urllib2 import *    # doesn't give me an error
> ur = urlopen("http://www.daniweb.com/forums/thread161312.html";) #
> gives me Undefined Variable: urlopen
>
> so I tried just
>
> import urllib2        # Eclipse gives "Unresolved Import"
>
> Is urllib2 not on my path?  Isn't urllib2 in the standard installation
> and shouldn't that automatically be on my path?  If not, how can I get
> it on the path?
>
> ThankS!!

This sounds more like a PyDev and/or Eclipse problem than an urllib2 problem. :)

One thing you can check: open the "raw" python interpreter outside of
Eclipse and try importing urllib2 there.  You might also try the
interpreter interface within Eclipse (if it provides one.)

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


Re: Is it possible to get the Physical memory address of a variable in python?

2009-11-09 Thread Benjamin Kaplan
On Mon, Nov 9, 2009 at 7:47 PM, Ognjen Bezanov  wrote:
> Hello all,
>
> Say I have a python variable:
>
> a = "hello"
>
> Is it possible for me to get the physical address of that variable (i.e.
> where it is in RAM)?
>
> I know that id(a) will give me it's memory address, but the address given
> does not seem to correlate with the physical memory. Is this even possible?
>
>
> Thank you!
>
>
> Ognjen
>

When you use Python, program in Python and not C. What do you need the
memory location of a variable for? Python, like Java and .NET is a
higher level language. You're not supposed to worry about things like
the physical location in memory. There's probably some ugly hack using
ctypes, or just writing the code in C but I don't know enough about
Python's C API to know what it is.

FWIW, even the id(x) == address of x is only an implementation detail
of CPython. Other Python implementations don't use that scheme.

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


Is it possible to get the Physical memory address of a variable in python?

2009-11-09 Thread Ognjen Bezanov

Hello all,

Say I have a python variable:

a = "hello"

Is it possible for me to get the physical address of that variable (i.e. 
where it is in RAM)?


I know that id(a) will give me it's memory address, but the address 
given does not seem to correlate with the physical memory. Is this even 
possible?



Thank you!


Ognjen

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


Re: is None or == None ?

2009-11-09 Thread Rhodri James

On Sun, 08 Nov 2009 19:45:31 -, Terry Reedy  wrote:

I believe the use of tagged pointers has been considered and so far  
rejected by the CPython developers. And no one else that I know of has  
developed a fork for that. It would seem more feasible with 64 bit  
pointers where there seem to be spare bits. But CPython will have to  
support 32 bit machines for several years.


I've seen that mistake made twice (IBM 370 architecture (probably 360 too,  
I'm too young to have used it) and ARM2/ARM3).  I'd rather not see it a  
third time, thank you.


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Indentation problems

2009-11-09 Thread Rhodri James
I'm going to make a whole bunch of wild guesses here, since you don't give  
us a lot to go on.


Wild Guess #1: you're using IDLE.

On Sun, 08 Nov 2009 19:01:37 -, Ray Holt   
wrote:


I am having problems with indentation some times. When I hit the enter  
key
after if statements or while statemt there are times when the  
indentation is

too much


Wild Guess #2: you've forgotten to close a bracket of some sort.


and other times too little.


Wild Guess #3: you've forgotten the colon on the end of the line


When I try to manually make sure the
indentation is correct and try to print, I ge the error message of  
invalid

syntax or incorrect indentation.


Ah.  Wild Guess 1a: you're using IDLE in interactive mode.

In that case, bear in mind Wild Guesses 2 and 3, but they aren't the whole  
story.  In interactive mode, IDLE executes the code that you type Right  
Now This Instant And No Messing.  When you type a compound statement like  
"if" or "while", that presents a bit of a problem since the statement  
isn't really finished until you've typed in all the statements that belong  
to that "if" or "while".  Knowing this, IDLE puts off executing it, and  
helpfully adds the indentation that it knows you'll need.  If you fiddle  
with that extra space and delete too much of it (easily done here), IDLE  
will tick you off for getting your indentation wrong.  If you hit Return  
without typing anything else, IDLE will do exactly the same thing since it  
knows Python requires you to have at least one statement inside the "if".   
Once you've typed that one statement, you can carry on typing more to your  
hearts content; at this point, IDLE treats a blank line as meaning "I'm  
done."  At this point it goes away and executes what you've typed Right  
Now This Instant And No Messing, and may end up complaining about  
something you got wrong three lines ago.



Can someone help me. Also when I open the
edit window instead of the shell the programs tend not to run. Help! Ray


Well, no.  Unlike the interactive window, typing into the edit window  
doesn't cause anything to be executed Right Now Etc Etc.  It doesn't even  
cause anything to be executed Sometime Soon Honest Guv'nor.  It just saves  
up what you've done so that it can be run later, assuming you remember to  
save it to a file.  Unlike the interactive window, you can go back and  
change what you've written earlier to correct a mistake, and re-run the  
entire script rather than type it in again line by line.


To actually run your program you have two alternatives.  Either you can  
use the "Run Module" entry in the "Run" menu (F5 on my version: it may be  
called something slightly different in a slightly different menu with a  
slightly different shortcut key depending on your operating system and  
which version of IDLE you're running), or you can pull up a console  
(command line, terminal, xterm, whatever your OS calls it) and invoke  
Python on your file directly.  If that last bit didn't make any sense to  
you, don't worry, just leave that particular adventure in computing for  
another day.


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Socket programming with NetCom serial-to-ethernet module

2009-11-09 Thread Ryan Swindle
Hi,

This is my first Python-list post; I hope it's going to the right place.
 Here's my problem:

I've read many tutorials on socket programming, but I can't seem to piece
them together for my particular case.  I have 3 serial ports, each of which
individually connects to a port on a NetCom box, which converts them to
TCP/IP ports (see e.g.
http://www.serialgear.com/4--Port-Serial-TCP-IP-NETCOM-411.html).  But I'll
just focus on communicating with 1 serial port right now (assume that I have
a 1-port NetCom box).  So, the flow pattern goes like this -- ascii string
from my Python program via the ethernet card to the NetCom box, which feeds
the serial port; this serial port is the input/output to a board that
controls a motor.  So, I can send an ascii string like "MI100\n", which
tells that motor to move 100 steps.  Currently, I can accomplish this using
sockets.  But if I instead want to request something from the motor, like
it's current position, how do I return this information back to my Python
program and still keep the socket alive and listening for say another
position request?

FYI, the NetCom box works on DHCP.  So, I could use 'arp' or another method
to actually find it's IP address, and I can connect to it using say port
2000.  At this point, it looks as if I would setup a server socket for the
NetCom box, and then create a client socket for the motor controller board
to talk to the NetCom box (and e.g. give the current position of the motor,
upon my request).  But the hard part seems to be how to retrieve that
information from the controller board, once it responds.  For instance, if I
were to just use pySerial, I open up a connection to the serial port, then
serial.send(ascii) sends the request, and serial.readline() reads the
response.  I need to know how to implement this basic functionality with
sockets, where the sockets remain alive and listening after each
request/response, just as pySerial does.

Any advice, sockets or not, is helpful and appreciated, and I can elaborate
further on the problem, if requested.  (Again, I hope this was not a misuse
of the list in some way; I apologize, if so).  Many thanks.

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


Re: PiCloud Beta Release

2009-11-09 Thread Ken Elkabany
On Thu, Nov 5, 2009 at 3:19 PM, Jacob Shaw  wrote:
> On Nov 1, 5:13 pm, Ken Elkabany  wrote:
>> Hello,
>>
>> PiCloud has just released a Python library, cloud, which allows you to
>> easily offload the execution of a function to a cluster of servers
>> running on Amazon Web Services. As a beta product, we are currently
>> free to all users who sign up with beta code "PYTHONLIST". To
>> register, go tohttp://www.picloud.com
>>
>> Full service description:
>> PiCloud is a cloud-computing platform that integrates into the Python
>> Programming Language. It enables you to leverage the compute power of
>> Amazon Web Services without having to manage, maintain, or configure
>> virtual servers.
>>
>> PiCloud integrates seamlessly into your existing code base through a
>> custom Python library, cloud. To offload the execution of a function
>> to the cloud, all you must do is pass your desired function into the
>> cloud library. PiCloud will then run the function on its
>> high-performance and automatically-scaling cluster. We quickly scale
>> our server capacity, both up and down, to meet your computational
>> needs, and only charge you for the resources you actually consume.
>> Getting on the cloud has never been this easy!
>>
>> PiCloud improves the full cycle of software development and
>> deployment. Functions that are run on PiCloud have their resource
>> usage monitored, performance analyzed, and errors traced; we further
>> aggregate all your functions to give you a bird's eye view of your
>> service. Through these introspective capabilities, PiCloud enables you
>> to develop faster, easier, and smarter.
>>
>> Common use cases for our platform:
>> * Crawling the web
>> * Manipulating images and videos
>> * Generating charts and graphs
>> * Statistical/Mathematical analysis of data sets
>> * Real-time data processing
>>
>> Cheers,
>>
>> Ken Elkabany
>> PiCloud, Inc.
>
> Wow, amazing service.  I used PiCloud for some scraping work, and my
> script ran about 10x as fast.
>
> Some questions though:
> 1) I have another project which uses a custom python extension written
> in C++.  Is there a way to use it on PiCloud?
> 2) I noticed you guys only support python 2.5 and 2.6.  Will there be
> 3.1 support eventually?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Thanks for the compliments.

1) PiCloud will not automatically transfer libraries that require
python C++ extensions. However, in your control panel, you can upload
a tarball or synchronize an svn repository that contains your
extension's code and we'll automatically compile/install it on our
systems.
2) We are currently working on support for python 3.x (we've had
requests from a fair number of users), and plan to release a
compatible client library in a couple of weeks.

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


NEWB problem with urllib2

2009-11-09 Thread Penn
I just installed PyDev into Eclipse using the 'update' method and did
the standard installation.  I allowed it to Auto Configure itself and
ran a "Hello World" module to make sure I was in the ballpark.

I got an starting module up and have run "Hello World" but now am
stuck on getting urlopen to import from urllib2 for the following
example.

from urllib2 import *# doesn't give me an error
ur = urlopen("http://www.daniweb.com/forums/thread161312.html";) #
gives me Undefined Variable: urlopen

so I tried just

import urllib2# Eclipse gives "Unresolved Import"

Is urllib2 not on my path?  Isn't urllib2 in the standard installation
and shouldn't that automatically be on my path?  If not, how can I get
it on the path?

ThankS!!

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


Re: Can't Find Module

2009-11-09 Thread Rhodri James
On Sat, 07 Nov 2009 16:59:29 -, Victor Subervi  
 wrote:



ImportError: No module named template

[snip]


I can import this just fine from the python command prompt. So, what  
gives?


Is template.py in your current directory when you run the script from the  
command line?


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE python shell freezes after running show() of matplotlib

2009-11-09 Thread Michael
On Oct 28, 11:09 pm, Chris Colbert  wrote:
> This is a threading issue that is very common when using gui toolkits
> with the interactive interpreter.
>
> You're better off just using ipython, which already has builtin
> support for matplotlib when you start it via "ipython -pylab"
>
> On Wed, Oct 28, 2009 at 7:41 PM, OKB (not okblacke)
>
>
>
>  wrote:
> > Forrest Sheng Bao wrote:
>
> >> I am having a weird problem on IDLE. After I plot something using show
> >> () of matplotlib, the python shell prompt in IDLE just freezes that I
> >> cannot enter anything and there is no new ">>>" prompt show up. I
> >> tried ctrl - C and it didn't work. I have to restart IDLE to use it
> >> again.
>
> >> My system is Ubuntu Linux 9.04. I used apt-get to install IDLE.
>
> >        I believe this is the intended behavior.  Look in matplotlib
> > documentation on the difference between interactive and non-interactive
> > modes.
>
> > --
> > --OKB (not okblacke)
> > Brendan Barnwell
> > "Do not follow where the path may lead.  Go, instead, where there is
> > no path, and leave a trail."
> >        --author unknown
> > --
> >http://mail.python.org/mailman/listinfo/python-list

Same problem for me using IDLE 1.2.4, python 2.5.4, and matplotlib
0.99.1.1. Windows XP 32bit.

Turning on interactive mode solved the problem with IDLE freezing,
however the plot window still comes up empty and frozen.

Using iPython now with no problems so far. Hopefully the problem with
IDLE gets fixed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set the range for x-axis

2009-11-09 Thread Martin
On Nov 9, 8:45 pm, Robert Kern  wrote:
> On 2009-11-09 10:43 AM, Moses wrote:
>
>
>
> > Hi Chris,
>
> > I am using python 2.6 and am using scipy and pylab. See the code below.
>
> You will want to ask matplotlib questions on the matplotlib mailing list:
>
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
> --
> 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

import matplotlib.pyplot as plt
plt.xlim(0., 1.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Victor Subervi
On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi wrote:

>
> On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury 
> wrote:
>
>> On Mon, 09 Nov 2009 11:24:33 -0800, Victor Subervi <
>> victorsube...@gmail.com> wrote:
>>
>>  On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury >> >wrote:
>>>
>>>  On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi <
 victorsube...@gmail.com> wrote:

  Of course. Let me start with some updates to httpd.conf, which didn't
 help

> anyway:
>
> 
> ServerAdmin m...@creative.vi
> DocumentRoot /var/www/html/angrynates.com
> ServerName angrynates.com
> Options +ExecCGI -IncludesNoExec
> 
>  Options +ExecCGI
>  AllowOverride All
>  AllowOverride FileInfo
>  #AddHandler mod_python .py
>  #PythonHandler mod_python.publisher
>  #PythonDebug On
> AddHandler cgi-script .cgi .py
> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI
> 
>  SecFilterEngine Off
> 
> 
>  SecRuleEngine Off
> 
> AddHandler cgi-script .cgi .py
> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI
>
> 
>  SecFilterEngine Off
> 
> 
>  SecRuleEngine Off
> 
>
> 
> 
>
> Here's index.py:
>
> #!/usr/bin/python
>
> import string
> import cgitb; cgitb.enable()
> import cgi
> import sys,os
> sys.path.append(os.getcwd())
> from template import template
>
> ourFile = string.split(__file__, "/")
> page = ourFile[len(ourFile) - 1][:-3]
>
> form = cgi.FieldStorage()
> w = form.getfirst('w', '1024')
>
> template(page, w)
>
>
>
>  Can you try running index.py from the command-line, and let me know if
 that
 works?


>>> It runs fine. So I created a test file of the same, chmod and tried it on
>>> my
>>> browser. Rendered. So I deleted index.py and recreated it from the
>>> command
>>> line, chmod. Rendered! Apparently, somehow in the translation from
>>> uploading
>>> it via ftp to moving the files to a new dir, something got screwed up in
>>> the
>>> permissions that I can't see! Any idea what the heck that could possibly
>>> be??
>>> TIA,
>>> V
>>>
>>
>> What platform did you upload from? Something as seemingly insignificant as
>> Windows line-endings can mess up file execution...
>>
>
> OS is Windoze XL. Have we caught the thief? How can I upload from this box
> and not have this problem, or undo it at the server? You know, of course, I
> don't see this line-ending from the command prompt when I vi it.
> TIA,
> V
>
> Hold everything. Apparently line-endings got mangled. What I don't
understand is why I didn't see them when I opened the file to edit, and why
they didn't copy and paste when I did that. But dos2unix cleaned up a couple
of files so I presume it will clean up the rest. However, I tried one file,
that reads exactly the same as index.py, and when I surfed to it got a 500
error. Here's what the log said:

[Mon Nov 09 12:30:27 2009] [notice] mod_python: (Re)importing module
'mptest'
[Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler
mptest: Traceback (most recent call last):, referer:
http://www.angrynates.com/global_solutions/
[Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler
mptest:   File "/usr/lib64/python2.4/site-packages/mod_python/apache.py",
line 287, in HandlerDispatch\nlog=debug), referer:
http://www.angrynates.com/global_solutions/
[Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler
mptest:   File "/usr/lib64/python2.4/site-packages/mod_python/apache.py",
line 461, in import_module\nf, p, d = imp.find_module(parts[i], path),
referer: http://www.angrynates.com/global_solutions/
[Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler
mptest: ImportError: No module named mptest, referer:
http://www.angrynates.com/global_solutions/

Huh? Got no "mptest" anywhere. Not even using mod_python. Why doesn't it
refer to a specific file in the folder? Any ideas on this one?
TIA,
V

>
>>
>>
>> --
>> Rami Chowdhury
>> "Never attribute to malice that which can be attributed to stupidity" --
>> Hanlon's Razor
>> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [PYTHON] How to set the range for x-axis

2009-11-09 Thread Robert Kern

On 2009-11-09 10:43 AM, Moses wrote:


Hi Chris,

I am using python 2.6 and am using scipy and pylab. See the code below.


You will want to ask matplotlib questions on the matplotlib mailing list:

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
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: [PYTHON] How to set the range for x-axis

2009-11-09 Thread David Robinow
On Mon, Nov 9, 2009 at 11:46 AM, Moses  wrote:
> Hi Chris,
>
> The code is
>
> from scipy import *
> from pylab import *
>
> x = [0.5,0.6,0.7,0.8,0.9,1.0]
> y = [2,6,8,10,10,10]
>
> plot(x,y,linewidth=5.0)
> show()
>
> and not
>
> from scipy import *
> from pylab import *
>
> x1 = [0.5,0.6,0.7,0.8,0.9,1.0]
> x2 = [0,1,2,3,4,5,6,7,8,9,10]
>
> plot(x1,y01,linewidth=5.0)
> show()
>
Don't top-post
use: axis([xmin,xmax,ymin,ymax])
See the documentation for details
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing GUI Module for Python

2009-11-09 Thread Simon Hibbs
Having tried most of the options out there, personaly I've settled on
two.

I use Tkinter for ver simple GUIs such as single dialog boxes or
results displays. The advantage of it being built-in to Python
outweighs it's limitations.

For anything more complex, I go for PyQT every time. QTDesigner is a
full drag-and-drop GUI builder that rivals Visual Studio, and PyQT
comes with a script to convert QTDesigner XML files into Python code,
which you then subclass in your own script and attach your own code to
the GUI widgets. There's a longer learning curve than Tkinter, but
it's very much worth it for access to QTs mature and rich framework,
with excellent professional-class documentation. Sorry, but wxWidgets
which I have used doesn't come anywhere close.

The main objection to using PyQT untill now was that for commercial
development you needed to buy a license (it was free for GPL
projects). That's rapidly becoming a non-issue as the core QT
framework is now LGPL and Nokia have a project underway to produce
PyQT compatible LGPL python bindings under the PySide project.

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


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Rami Chowdhury
On Mon, 09 Nov 2009 11:24:33 -0800, Victor Subervi  
 wrote:


On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury  
wrote:



On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi <
victorsube...@gmail.com> wrote:

 Of course. Let me start with some updates to httpd.conf, which didn't  
help

anyway:


ServerAdmin m...@creative.vi
DocumentRoot /var/www/html/angrynates.com
ServerName angrynates.com
Options +ExecCGI -IncludesNoExec

 Options +ExecCGI
 AllowOverride All
 AllowOverride FileInfo
 #AddHandler mod_python .py
 #PythonHandler mod_python.publisher
 #PythonDebug On
AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI

 SecFilterEngine Off


 SecRuleEngine Off

AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI


 SecFilterEngine Off


 SecRuleEngine Off





Here's index.py:

#!/usr/bin/python

import string
import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())
from template import template

ourFile = string.split(__file__, "/")
page = ourFile[len(ourFile) - 1][:-3]

form = cgi.FieldStorage()
w = form.getfirst('w', '1024')

template(page, w)



Can you try running index.py from the command-line, and let me know if  
that

works?



It runs fine. So I created a test file of the same, chmod and tried it  
on my
browser. Rendered. So I deleted index.py and recreated it from the  
command
line, chmod. Rendered! Apparently, somehow in the translation from  
uploading
it via ftp to moving the files to a new dir, something got screwed up in  
the

permissions that I can't see! Any idea what the heck that could possibly
be??
TIA,
V


What platform did you upload from? Something as seemingly insignificant as  
Windows line-endings can mess up file execution...




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Victor Subervi
On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury wrote:

> On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi <
> victorsube...@gmail.com> wrote:
>
>  Of course. Let me start with some updates to httpd.conf, which didn't help
>> anyway:
>>
>> 
>> ServerAdmin m...@creative.vi
>> DocumentRoot /var/www/html/angrynates.com
>> ServerName angrynates.com
>> Options +ExecCGI -IncludesNoExec
>> 
>>  Options +ExecCGI
>>  AllowOverride All
>>  AllowOverride FileInfo
>>  #AddHandler mod_python .py
>>  #PythonHandler mod_python.publisher
>>  #PythonDebug On
>> AddHandler cgi-script .cgi .py
>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI
>> 
>>  SecFilterEngine Off
>> 
>> 
>>  SecRuleEngine Off
>> 
>> AddHandler cgi-script .cgi .py
>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI
>>
>> 
>>  SecFilterEngine Off
>> 
>> 
>>  SecRuleEngine Off
>> 
>>
>> 
>> 
>>
>> Here's index.py:
>>
>> #!/usr/bin/python
>>
>> import string
>> import cgitb; cgitb.enable()
>> import cgi
>> import sys,os
>> sys.path.append(os.getcwd())
>> from template import template
>>
>> ourFile = string.split(__file__, "/")
>> page = ourFile[len(ourFile) - 1][:-3]
>>
>> form = cgi.FieldStorage()
>> w = form.getfirst('w', '1024')
>>
>> template(page, w)
>>
>>
>>
> Can you try running index.py from the command-line, and let me know if that
> works?
>

It runs fine. So I created a test file of the same, chmod and tried it on my
browser. Rendered. So I deleted index.py and recreated it from the command
line, chmod. Rendered! Apparently, somehow in the translation from uploading
it via ftp to moving the files to a new dir, something got screwed up in the
permissions that I can't see! Any idea what the heck that could possibly
be??
TIA,
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: String prefix question

2009-11-09 Thread Alan Harris-Reid


Benjamin Kaplan wrote:

On Sun, Nov 8, 2009 at 9:38 PM, Alan Harris-Reid
 wrote:
  

In the Python.org 3.1 documentation (section 20.4.6), there is a simple
"Hello World" WSGI application which includes the following method...

def hello_world_app(environ, start_response):
status ='200 OK' # HTTP Status
headers =(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers
start_response(status, headers)

# The returned object is going to be printed
return [b"Hello World"]

Question - Can anyone tell me why the 'b' prefix is present before each
string? The method seems to work equally well with and without the prefix.
From what I can gather from the documentation the b prefix represents a
bytes literal, but can anyone explain (in simple english) what this means?

Many thanks,
Alan



The rather long version:
read http://www.joelonsoftware.com/articles/Unicode.html

A somewhat shorter summary, along with how Python deals with this:

Once upon a time, someone decided to allocate 1 byte for each
character. Since everything the Americans who made the computers
needed fit into 7 bits, this was alright. And they called this the
American Standard Code for Information Interchange (ASCII). When
computers came along, device manufacturers realized that they had 128
characters that didn't mean anything, so they all made their own
characters to show for the upper 128. And when they started selling
computers internationally, they used the upper 128 to store the
characters they needed for the local language. This had several
problems.

1) Files made by on one computer in one country wouldn't display right
in a computer made by a different manufacturer or for a different
country

2) The 256 characters were enough for most Western languages, but
Chinese and Japanese need a whole lot more.

To solve this problem, Unicode was created. Rather than thinking of
each character as a distinct set of bits, it just assigns a number to
each one (a code point). The bottom 128 characters are the original
ASCII set, and everything else you could think of was added on top of
that - other alphabets, mathematical symbols, music notes, cuneiform,
dominos, mah jong tiles, and more. Unicode is harder to implement than
a simple byte array, but it means strings are universal- every program
will interpret them exactly the same. Unicode strings in python are
the default ('') in Python 3.x and created in 2.x by putting a u in
front of the string declaration (u'')

Unicode, however, is a concept, and concepts can't be mapped to bits
that can be sent through the network or stored on the hard drive. So
instead we deal with strings internally as Unicode and then give them
an encoding when we send them back out. Some encodings, such as UTF-8,
can have multiple bytes per character and, as such, can deal with the
full range of Unicode characters. Other times, programs still expect
the old 8-bit encodings like ISO-8859-1 or the Windows Ansi code
pages. In Python, to declare that the string is a literal set of bytes
and the program should not try and interpret it, you use b'' in Python
3.x, or just declare it normally in Python 2.x ('').

--
What happens in your program:

When you print a Unicode string, Python has to decide what encoding to
use. If you're printing to a terminal, Python looks for the terminal's
encoding and uses that. In the event that it doesn't know what
encoding to use, Python defaults to ASCII because that's compatible
with almost everything. Since the string you're sending to the web
page only contains ASCII characters, the automatic conversion works
fine if you don't specify the b''. Since the resulting page uses UTF-8
(which you declare in the header), which is compatible with ASCII, the
output looks fine. If you try sending a string that has non-ASCII
characters, the program might throw a UnicodeEncodeError because it
doesn't know what bytes to use for those characters. It may be able to
guess, but since I haven't used WSGI directly before, I can't say for
sure.
  


Thanks Benjamin - great 'history' lesson - explains it well.

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


questions regarding stack size use for multi-threaded python programs

2009-11-09 Thread Eyal Gordon
Hi,

background:
we are using python 2.4.3 on CentOS 5.3 with many threads - and our shell's
default stack size limit is set to 10240KB (i.e. ~10MB).

we noticed that python's Threading module appears to create threads with
this value as their stack size (we ran a sample program that creates 10
threads and measured its virtual memory size, then reduced the stack size
limit of the shell to 5120KB - and saw that the program's virtual memory
size was reduced by ~50MBs).

the problem:
our program uses numerous threads, and thus the virtual memory size gets to
be very large. we would like to reduce the size of the stack to reduce this
size. we were looking for information about recommendation for the stack
size to use, but found none.

questions:
1. is there some rule-of-thumb for the recommended stack size for python
programs of various sorts?

2. is there a way for us, at runtime (from inside the code or outside the
process), to find how much of a thread's stack we are using (in KB or some
other size units)?

3. when we define local objects - do the objects themselves get allocated on
the stack - or are they allocated on the heap and only references to them
are kept on the stack?

4. would the size of the stacks (which are probably not really allocated by
the linux virtual memory sub-system, unless used) have a noticeable
performance effect on a python program? same question regarding the use of a
large number of threads?

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


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Rami Chowdhury
On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi  
 wrote:


Of course. Let me start with some updates to httpd.conf, which didn't  
help

anyway:


ServerAdmin m...@creative.vi
DocumentRoot /var/www/html/angrynates.com
ServerName angrynates.com
Options +ExecCGI -IncludesNoExec

 Options +ExecCGI
 AllowOverride All
 AllowOverride FileInfo
 #AddHandler mod_python .py
 #PythonHandler mod_python.publisher
 #PythonDebug On
AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI

 SecFilterEngine Off


 SecRuleEngine Off

AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI


 SecFilterEngine Off


 SecRuleEngine Off





Here's index.py:

#!/usr/bin/python

import string
import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())
from template import template

ourFile = string.split(__file__, "/")
page = ourFile[len(ourFile) - 1][:-3]

form = cgi.FieldStorage()
w = form.getfirst('w', '1024')

template(page, w)




Can you try running index.py from the command-line, and let me know if  
that works?


Also, as you've already been asked - please start your replies *below* the  
text you are replying to. Putting your replies above the last email, or  
"top-posting" makes reading long email threads with lots of text  
distracting and frustrating.




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows)

2009-11-09 Thread Jon Clements
On Nov 9, 5:22 pm, "Alf P. Steinbach"  wrote:
> * Jon Clements:
>
>
>
> > On Nov 9, 4:10 pm, "Alf P. Steinbach"  wrote:
> >> Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far.
>
> >> It's now Python 3.x, and reworked with lots of graphical examples and more
> >> explanatory text, plus limited in scope to Basic Concepts (which I 
> >> previously
> >> just had as a first ch 2 section  --  but there's rather a lot of 
> >> concepts!).
>
> >> I think it's wise to invite comments even when it's not 100% completed. 
> >> First,
> >> because as opposed to ch 1 there is quite a bit of code here, and since 
> >> I'm a
> >> Python newbie I may be using non-idiomatic constructs, not to mention doing
> >> worse things. :-) Second, because comments in general can improve the text.
>
> >> Contents:
>
> >> 2.1 Super-basic concept: why programming is not DWIM.   1
> >> 2.2 Reported errors.    4
> >> 2.2.1   Case-sensitity. 4
> >> 2.2.2   Syntax / compilation errors.    4
> >> 2.2.3   Runtime errors / crashes.   5
> >> 2.3 A programming exploration tool: turtle graphics.    6
> >> 2.4 Naming things.  8
> >> 2.4.1   Naming actions: routines.   8
> >> 2.4.2   Naming data part I: variables.  11
> >> 2.4.3   Naming data part II: routine arguments. 13
> >> 2.5 Controlling the flow of execution.  14
> >> 2.5.1   Repeating actions automatically: loops. 14
> >> 2.5.2   Basic comparisions & boolean values.    16
> >> 2.5.3   Interlude I: a function graph program / about types.    17
> >> 2.5.4   Automated action choices.   21
> >> 2.5.5   Value-producing (function-like) routines.   23
> >> 2.5.6   Interlude II: a graph with zeroes marked / about program 
> >> structure. 26
> >> 2.5.7   Dynamically nested actions: recursive routines. 28
> >> 2.6 Objects.     [Not started on this] 31
> >> 2.7 Collections.    [Not started on this] 31
>
> >> In Google Docs (both chapters available here):
>
> >>      http://preview.tinyurl.com/ProgrammingBookP3>
> >>      Formats: PDF
>
> >> Cheers,
>
> >> - Alf
>
> > Well, you may not like it, but it is perfectly acceptable and indeed
> > promoted to use CONSTANT_VAR_NAMES. You're almost discouraging the use
> > of a well understood and oft-used idiom. I they're a lot of them, you
> > generally have a settings module, that just lists all of the
> > 'constants' (.h files effectively).
>
> Yeah, I thought of that angle so I emphasized 'programs'.
>
> As it happens about half or more of the variables in the examples are 
> constants.
>
> All uppercase convention for that would be ugly to me. :-)

Okies, maybe introducing the fact that lots of 'programs' often have
constants, which are quite often settings or whatever and they would
use the uppercase notation (and if numerous, in a separate module).
Also maybe you can introduce the fundamental idea of a 'namespace',
maybe something like:

class const:
pi = 3.14
name = 'Alf'
language = 'Python'

or whatever, then reference const. ?

I'm not 100% sure I'm keen on this idea, but it's an option you can
consider at least. Introduces a couple of bits that may be discussed
later, but I'd be a little scared that people would start thinking
'const.' was something magical.

>
> > "Technically line_length is a variable"...: No - it's a name that
> > binds to an object that happens to be an integer. You've participated
> > in discussions re: this. Similarly 'number_of_apples =
> > number_of_apples + 1' is not an assignment ;)
>
> Ah, you're kidding.
>
> Probably.
>
> Anyways, that's the terminology employed by the language reference, and even 
> if
> it wasn't I'd use it because this is primarily introduction to programming in
> general, where Python just happens to be the vehicle; thus, language 
> independent
> terminology preferred (e.g., I use "routine" instead of C/Python "function").
>
> > It's nit-picky and I
> > realise you're trying to keep it simple, but as it's meant for new
> > programmers to the Python language, then introduce them to Python's
> > way of "variables", they'll thank you for it later... (or run
> > screaming, or start another thread here...)
>
> Yeah, good point, thanks!
>
> But it will have to wait till I get down into details... ;-)
>

Fair enough. It would be nice though to cover stuff like:

a = [1,2,3]
b = a

- b is not a *copy* of a
- b is not a *reference* to a
- b just happens to be another name for the list object.

And stuff about mutable/immutable: it would certainly help with a lot
of gotcha's.

> > I've never seen/heard != described as "different from"; what's wrong
> > with "not equal to"?
>
> Thanks!
>
> > And why no mention of 'not' (should be mentioned
> > with booleans surely?).
>
> Again, I'll discuss that later. It's just too much to bring up. Most of my 
> work
> with this has been to pare down to essentials and *remove* stuff I'd written.
>

Well, should you re-write != as "not equal to", it wouldn't hurt to
mention a little later that not False is True and vice versa...

> > That's as 

Re: Choosing GUI Module for Python

2009-11-09 Thread r
On Nov 9, 3:59 am, Antony  wrote:
> I would like to know about that pros and cons only ...

I'll reiterate what i have said and others have said. WE NEED MORE
INFO TO PROPERLY GUIDE YOU!!!

Survey: What GUI is right for you?

1. What is your level of GUI programming? (0 1 2 3 4 5)
2. Will you be using this GUI for your own apps or distributing the
apps?
3. What is the primary OS that this app will be used on (or any)?
4. What type of app (graphics(2D/3D), texteditor, hello world)?
5. Are themes/customizable look and feel important?
*. You mentioned IDE's. That of course will narrow your choice pool
substantially.

Tkinter:
 +Is included in Python as a built-in module!
 +very easy to learn!
 +adequate docs!
 -lacks professional appearance
 -lacks many important widgets
 http://infohost.nmt.edu/tcc/help/pubs/tkinter/
 http://effbot.org/tkinterbook/

wxPython:
 +larger richer widget set than tk!
 +better look and feel than tk!
 +opengl canvas built-in!
 -not as easy to learn as tk
 -docs are lacking at best (i really wish this were better!)
 -not built-in to Python (rightly so, too big!)


i won't comment on the others. If you have absolutely no experience
try out Tkinter just to a feel for GUI in a hand holding environment.
If you are not happy with Tkinter's simplicity then move on to a full
featured GUI kit if you need the more advanced stuff. I would say try
them all! I would also suggest you learn to code GUI's without an IDE.
I think the experience is more rewarding. You should know every bit of
code you create personally!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Victor Subervi
Of course. Let me start with some updates to httpd.conf, which didn't help
anyway:


ServerAdmin m...@creative.vi
DocumentRoot /var/www/html/angrynates.com
ServerName angrynates.com
Options +ExecCGI -IncludesNoExec

 Options +ExecCGI
 AllowOverride All
 AllowOverride FileInfo
 #AddHandler mod_python .py
 #PythonHandler mod_python.publisher
 #PythonDebug On
AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI

 SecFilterEngine Off


 SecRuleEngine Off

AddHandler cgi-script .cgi .py
Options Includes Indexes SymLinksIfOwnerMatch ExecCGI


 SecFilterEngine Off


 SecRuleEngine Off





Here's index.py:

#!/usr/bin/python

import string
import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())
from template import template

ourFile = string.split(__file__, "/")
page = ourFile[len(ourFile) - 1][:-3]

form = cgi.FieldStorage()
w = form.getfirst('w', '1024')

template(page, w)


Here's template.py:

#!/usr/bin/python

import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())

p = 'template'

def template(page, w):
  wn = int(w)/1024
  print "Content-Type: text/html"
  print
  print '''
http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";>
http://www.w3.org/1999/xhtml";>

.text {  font-family: Arial, Helvetica, sans-serif; font-size: 16px;
text-decoration: none; text-align: justify}

Global Solutions Group









'''
  print "


'''

TIA,
V

On Mon, Nov 9, 2009 at 1:14 PM, Rami Chowdhury wrote:

> On Mon, 09 Nov 2009 09:44:24 -0800, Victor Subervi <
> victorsube...@gmail.com> wrote:
>
>  Did you give up on me?
>> V
>>
>> On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi > >wrote:
>>
>>  [r...@13gems angrynates.com]# chcon -R -h
>>> unconfined_u:object_r:httpd_sys_content_t global_solutions/*
>>>
>>> Then I surfed to
>>> http://209.216.9.56/global_solutions/index.py
>>>
>>> [r...@13gems angrynates.com]# tail /var/log/messages
>>> Nov  8 04:26:02 13gems syslogd 1.4.1: restart.
>>> [r...@13gems angrynates.com]# tail /var/log/httpd/error_log
>>> [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest
>>> authentication ...
>>> [Sun Nov 08 05:35:10 2009] [notice] Digest: done
>>> [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session
>>> mutexes
>>> based on 10 max processes and 0 max threads.
>>> [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured --
>>> resuming normal operations
>>> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not
>>> exist: /var/www/html/angrynates.com/favicon.ico
>>> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such file
>>> or directory: exec of '/var/www/html/
>>> angrynates.com/global_solutions/index.py' failed, referer:
>>> http://209.216.9.56/global_solutions/
>>> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end
>>> of
>>> script headers: index.py, referer: http://209.216.9.56/global_solutions/
>>> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not
>>> exist: /var/www/html/angrynates.com/favicon.ico
>>> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such file
>>> or directory: exec of '/var/www/html/
>>> angrynates.com/global_solutions/index.py' failed, referer:
>>> http://209.216.9.56/global_solutions/
>>> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end
>>> of
>>> script headers: index.py, referer: http://209.216.9.56/global_solutions/
>>>
>>> TIA,
>>> V
>>>
>>> On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury <
>>> rami.chowdh...@gmail.com>wrote:
>>>
>>>  On Sunday 08 November 2009 05:44:31 Victor Subervi wrote:
 > [r...@13gems angrynates.com]# chcon -u unconfined_u -r object_r -t
 > httpd_sys_content_t global_solutions
 > chcon: can't apply partial context to unlabeled file global_solutions
 > Please advise.

 Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t
 global_solutions/*', which should specif

Re: Tax Calculator--Tkinter

2009-11-09 Thread Marcus Gnaß
Someone Something wrote:
> > from Tkinter import *;

Try to avoid this. Better import Tkinter. And don't forget to import
Tkconstants too!

> > rate=Frame(root)
> > income=Frame(root)
> > result=Frame(root)

Why do you use three frames? You only need one. And you can make your
class TaxCalc inherit from Tkinter.Frame ...

> > The thing is, that even if I put "12" in the result text field, get
> > returns an empty string. How can I fix this?

I haven't found the reason for that, but this should work. I also added
MRABs version of printResult().

import Tkinter, Tkconstants

class TaxCalc(Tkinter.Frame):

def __init__(self, root):

Tkinter.Frame.__init__(self, root)

Tkinter.Button(self,
text='Enter tax rate',
command=self.getRate).pack()

self.rate=Tkinter.Entry(self)
self.rate.pack()

Tkinter.Button(self,
text='Enter income',
command=self.getIncome).pack()  

self.income=Tkinter.Entry(self)
self.income.pack()

Tkinter.Button(self,
text='Get result',
command=self.printResult).pack()

self.result=Tkinter.Entry(self)
self.result.pack()

self.pack()

def getRate(self):
print "srate: ", self.rate.get()

def getIncome(self):
print "sincome: ", self.income.get()

def printResult(self):
try:
rate = float(self.rate.get())
income = float(self.income.get())
result = ((100.0 - rate) / 100.0) * income
self.result.insert(Tkconstants.END, str(result))
except ValueError:
print "Clear everything and start again."
print "Don't fool around with me."

root=Tkinter.Tk()
MyCalc=TaxCalc(root)
root.mainloop()

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


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Rami Chowdhury
On Mon, 09 Nov 2009 09:44:24 -0800, Victor Subervi  
 wrote:



Did you give up on me?
V

On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi  
wrote:



[r...@13gems angrynates.com]# chcon -R -h
unconfined_u:object_r:httpd_sys_content_t global_solutions/*

Then I surfed to
http://209.216.9.56/global_solutions/index.py

[r...@13gems angrynates.com]# tail /var/log/messages
Nov  8 04:26:02 13gems syslogd 1.4.1: restart.
[r...@13gems angrynates.com]# tail /var/log/httpd/error_log
[Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest
authentication ...
[Sun Nov 08 05:35:10 2009] [notice] Digest: done
[Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session  
mutexes

based on 10 max processes and 0 max threads.
[Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured --
resuming normal operations
[Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not
exist: /var/www/html/angrynates.com/favicon.ico
[Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such  
file

or directory: exec of '/var/www/html/
angrynates.com/global_solutions/index.py' failed, referer:
http://209.216.9.56/global_solutions/
[Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end  
of

script headers: index.py, referer: http://209.216.9.56/global_solutions/
[Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not
exist: /var/www/html/angrynates.com/favicon.ico
[Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such  
file

or directory: exec of '/var/www/html/
angrynates.com/global_solutions/index.py' failed, referer:
http://209.216.9.56/global_solutions/
[Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end  
of

script headers: index.py, referer: http://209.216.9.56/global_solutions/

TIA,
V

On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury  
wrote:



On Sunday 08 November 2009 05:44:31 Victor Subervi wrote:
> [r...@13gems angrynates.com]# chcon -u unconfined_u -r object_r -t
> httpd_sys_content_t global_solutions
> chcon: can't apply partial context to unlabeled file global_solutions
> Please advise.

Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t
global_solutions/*', which should specify the whole context at once and
avoid
that error, as well as apply it recursively to all files and
subdirectories.

Also, to narrow down the error, can you let us have the output of:
   tail /var/log/messages
tail /var/log/httpd/error_log



OK, after all this I've forgotten what your .py file looked like -- can  
you post that please?




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Simon Forman
On Mon, Nov 9, 2009 at 12:44 PM, Victor Subervi  wrote:
> Did you give up on me?
> V
>

Please don't top-post.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows)

2009-11-09 Thread Alf P. Steinbach

* sstein...@gmail.com:


On Nov 9, 2009, at 11:54 AM, Jon Clements wrote:


On Nov 9, 4:10 pm, "Alf P. Steinbach"  wrote:
First, because as opposed to ch 1 there is quite a bit of code here, 
and since I'm a

Python newbie I may be using non-idiomatic constructs,


Welp, there goes my last excuse.

I'm off to write my book:

Heart Surgery at Home

***
How to Save Thousands and
Get Results Just Like in Hospital


Chapter 1: Sanitation, Schmanitation: How Clean is Clean Enough?
Chapter 2: Surgical Tools vs. Ginsu: How Sharp is Sharp Enough?
Chapter 3: Gray's Anatomy and Sharpies: Laying out The Surgery
Chapter 4: Before You Start: Charging Your Cell Phone, and Testing 911
Chapter 5: Anesthesia: Jack Daniels or Smirnoffs; How Much is Enough?
Chapter 6: The Insanity Defense: Laying the Groundwork with 6 Month Plan

That's as far as I've gotten...

Amazon best seller list, here I come!

S


It helps if you have some experience with surgery on other parts of the body.


Cheers & hth.,

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


Re: Serious Privileges Problem: Please Help

2009-11-09 Thread Victor Subervi
Did you give up on me?
V

On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi wrote:

> [r...@13gems angrynates.com]# chcon -R -h
> unconfined_u:object_r:httpd_sys_content_t global_solutions/*
>
> Then I surfed to
> http://209.216.9.56/global_solutions/index.py
>
> [r...@13gems angrynates.com]# tail /var/log/messages
> Nov  8 04:26:02 13gems syslogd 1.4.1: restart.
> [r...@13gems angrynates.com]# tail /var/log/httpd/error_log
> [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest
> authentication ...
> [Sun Nov 08 05:35:10 2009] [notice] Digest: done
> [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session mutexes
> based on 10 max processes and 0 max threads.
> [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured --
> resuming normal operations
> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not
> exist: /var/www/html/angrynates.com/favicon.ico
> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such file
> or directory: exec of '/var/www/html/
> angrynates.com/global_solutions/index.py' failed, referer:
> http://209.216.9.56/global_solutions/
> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end of
> script headers: index.py, referer: http://209.216.9.56/global_solutions/
> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not
> exist: /var/www/html/angrynates.com/favicon.ico
> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such file
> or directory: exec of '/var/www/html/
> angrynates.com/global_solutions/index.py' failed, referer:
> http://209.216.9.56/global_solutions/
> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end of
> script headers: index.py, referer: http://209.216.9.56/global_solutions/
>
> TIA,
> V
>
> On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury 
> wrote:
>
>> On Sunday 08 November 2009 05:44:31 Victor Subervi wrote:
>> > [r...@13gems angrynates.com]# chcon -u unconfined_u -r object_r -t
>> > httpd_sys_content_t global_solutions
>> > chcon: can't apply partial context to unlabeled file global_solutions
>> > Please advise.
>>
>> Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t
>> global_solutions/*', which should specify the whole context at once and
>> avoid
>> that error, as well as apply it recursively to all files and
>> subdirectories.
>>
>> Also, to narrow down the error, can you let us have the output of:
>>tail /var/log/messages
>> tail /var/log/httpd/error_log
>>
>> HTH,
>> Rami
>>
>> 
>> Rami Chowdhury
>> "As an online discussion grows longer, the probability of a comparison
>> involving Nazis or Hitler approaches one." -- Godwin's Law
>> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: String prefix question

2009-11-09 Thread Alan Harris-Reid


Gerard Flanagan wrote:

Alan Harris-Reid wrote:
In the Python.org 3.1 documentation (section 20.4.6), there is a 
simple “Hello World” WSGI application which includes the following 
method...


def hello_world_app(environ, start_response):
status ='200 OK' # HTTP Status
headers =(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers
start_response(status, headers)

# The returned object is going to be printed
return [b"Hello World"]

Question - Can anyone tell me why the 'b' prefix is present before 
each string? The method seems to work equally well with and without 
the prefix. From what I can gather from the documentation the b 
prefix represents a bytes literal, but can anyone explain (in simple 
english) what this means?


Many thanks,
Alan


Another link:

http://www.stereoplex.com/two-voices/python-unicode-and-unicodedecodeerror 








Gerard - thanks for the link - explains it well.

Many thanks,
Alan

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


Re: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows)

2009-11-09 Thread sstein...@gmail.com


On Nov 9, 2009, at 11:54 AM, Jon Clements wrote:


On Nov 9, 4:10 pm, "Alf P. Steinbach"  wrote:
First, because as opposed to ch 1 there is quite a bit of code  
here, and since I'm a

Python newbie I may be using non-idiomatic constructs,


Welp, there goes my last excuse.

I'm off to write my book:

Heart Surgery at Home

***
How to Save Thousands and
Get Results Just Like in Hospital


Chapter 1: Sanitation, Schmanitation: How Clean is Clean Enough?
Chapter 2: Surgical Tools vs. Ginsu: How Sharp is Sharp Enough?
Chapter 3: Gray's Anatomy and Sharpies: Laying out The Surgery
Chapter 4: Before You Start: Charging Your Cell Phone, and Testing 911
Chapter 5: Anesthesia: Jack Daniels or Smirnoffs; How Much is Enough?
Chapter 6: The Insanity Defense: Laying the Groundwork with 6 Month Plan

That's as far as I've gotten...

Amazon best seller list, here I come!

S



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


Re: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows)

2009-11-09 Thread Alf P. Steinbach

* Jon Clements:

On Nov 9, 4:10 pm, "Alf P. Steinbach"  wrote:

Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far.

It's now Python 3.x, and reworked with lots of graphical examples and more
explanatory text, plus limited in scope to Basic Concepts (which I previously
just had as a first ch 2 section  --  but there's rather a lot of concepts!).

I think it's wise to invite comments even when it's not 100% completed. First,
because as opposed to ch 1 there is quite a bit of code here, and since I'm a
Python newbie I may be using non-idiomatic constructs, not to mention doing
worse things. :-) Second, because comments in general can improve the text.

Contents:

2.1 Super-basic concept: why programming is not DWIM.   1
2.2 Reported errors.4
2.2.1   Case-sensitity. 4
2.2.2   Syntax / compilation errors.4
2.2.3   Runtime errors / crashes.   5
2.3 A programming exploration tool: turtle graphics.6
2.4 Naming things.  8
2.4.1   Naming actions: routines.   8
2.4.2   Naming data part I: variables.  11
2.4.3   Naming data part II: routine arguments. 13
2.5 Controlling the flow of execution.  14
2.5.1   Repeating actions automatically: loops. 14
2.5.2   Basic comparisions & boolean values.16
2.5.3   Interlude I: a function graph program / about types.17
2.5.4   Automated action choices.   21
2.5.5   Value-producing (function-like) routines.   23
2.5.6   Interlude II: a graph with zeroes marked / about program structure. 26
2.5.7   Dynamically nested actions: recursive routines. 28
2.6 Objects. [Not started on this] 31
2.7 Collections.[Not started on this] 31

In Google Docs (both chapters available here):

 http://preview.tinyurl.com/ProgrammingBookP3>
 Formats: PDF

Cheers,

- Alf


Well, you may not like it, but it is perfectly acceptable and indeed
promoted to use CONSTANT_VAR_NAMES. You're almost discouraging the use
of a well understood and oft-used idiom. I they're a lot of them, you
generally have a settings module, that just lists all of the
'constants' (.h files effectively).


Yeah, I thought of that angle so I emphasized 'programs'.

As it happens about half or more of the variables in the examples are constants.

All uppercase convention for that would be ugly to me. :-)




"Technically line_length is a variable"...: No - it's a name that
binds to an object that happens to be an integer. You've participated
in discussions re: this. Similarly 'number_of_apples =
number_of_apples + 1' is not an assignment ;)


Ah, you're kidding.

Probably.

Anyways, that's the terminology employed by the language reference, and even if 
it wasn't I'd use it because this is primarily introduction to programming in 
general, where Python just happens to be the vehicle; thus, language independent 
terminology preferred (e.g., I use "routine" instead of C/Python "function").




It's nit-picky and I
realise you're trying to keep it simple, but as it's meant for new
programmers to the Python language, then introduce them to Python's
way of "variables", they'll thank you for it later... (or run
screaming, or start another thread here...)


Yeah, good point, thanks!

But it will have to wait till I get down into details... ;-)



I've never seen/heard != described as "different from"; what's wrong
with "not equal to"?


Thanks!



And why no mention of 'not' (should be mentioned
with booleans surely?).


Again, I'll discuss that later. It's just too much to bring up. Most of my work 
with this has been to pare down to essentials and *remove* stuff I'd written.




That's as far as I've got; might get around to reading more later...

Cool tree at the end :)


Thanks!

Cheers,

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


Re: OT: regular expression matching multiple occurrences of one group

2009-11-09 Thread J�rgen Exner
pinkisntwell  wrote:
>How can I make a regular expression that will match every occurrence
>of a group and return each occurrence as a group match? For example,
>for a string "-c-c-c-c-c", how can I make a regex which will return a
>group match for each occurrence of "-c"?

Where is the problem? The most straight-forward, simplest approach works
just fine:
use strict; use warnings;
my $s = '-c-c-c-c-c';

my @matched = $s=~/-c/g;

print "Found ". @matched . " occurences of '-c':\n";
print join "\n", @matched;

Or did you forget to use the g modifier?

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


Re: OT: regular expression matching multiple occurrences of one group

2009-11-09 Thread sln
On Mon, 9 Nov 2009 05:53:00 -0800 (PST), pinkisntwell  
wrote:

>How can I make a regular expression that will match every occurrence
>of a group and return each occurrence as a group match? For example,
>for a string "-c-c-c-c-c", how can I make a regex which will return a
>group match for each occurrence of "-c"?

Is this a ludicrous question, or is it meant for the python group?

use strict;
use warnings;

my @matches = "-c-c-c-c-c" =~ /(-c)/g;
print "\...@matches\n";

@matches = ();
"-c-a-c-c-c" =~ /(?:(-c)(?{push @matches, $^N})|.)+/x;
print "@matches\n";

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


Re: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows)

2009-11-09 Thread Jon Clements
On Nov 9, 4:10 pm, "Alf P. Steinbach"  wrote:
> Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far.
>
> It's now Python 3.x, and reworked with lots of graphical examples and more
> explanatory text, plus limited in scope to Basic Concepts (which I previously
> just had as a first ch 2 section  --  but there's rather a lot of concepts!).
>
> I think it's wise to invite comments even when it's not 100% completed. First,
> because as opposed to ch 1 there is quite a bit of code here, and since I'm a
> Python newbie I may be using non-idiomatic constructs, not to mention doing
> worse things. :-) Second, because comments in general can improve the text.
>
> Contents:
>
> 2.1 Super-basic concept: why programming is not DWIM.   1
> 2.2 Reported errors.    4
> 2.2.1   Case-sensitity. 4
> 2.2.2   Syntax / compilation errors.    4
> 2.2.3   Runtime errors / crashes.   5
> 2.3 A programming exploration tool: turtle graphics.    6
> 2.4 Naming things.  8
> 2.4.1   Naming actions: routines.   8
> 2.4.2   Naming data part I: variables.  11
> 2.4.3   Naming data part II: routine arguments. 13
> 2.5 Controlling the flow of execution.  14
> 2.5.1   Repeating actions automatically: loops. 14
> 2.5.2   Basic comparisions & boolean values.    16
> 2.5.3   Interlude I: a function graph program / about types.    17
> 2.5.4   Automated action choices.   21
> 2.5.5   Value-producing (function-like) routines.   23
> 2.5.6   Interlude II: a graph with zeroes marked / about program structure. 26
> 2.5.7   Dynamically nested actions: recursive routines. 28
> 2.6 Objects.     [Not started on this] 31
> 2.7 Collections.    [Not started on this] 31
>
> In Google Docs (both chapters available here):
>
>      http://preview.tinyurl.com/ProgrammingBookP3>
>      Formats: PDF
>
> Cheers,
>
> - Alf

Well, you may not like it, but it is perfectly acceptable and indeed
promoted to use CONSTANT_VAR_NAMES. You're almost discouraging the use
of a well understood and oft-used idiom. I they're a lot of them, you
generally have a settings module, that just lists all of the
'constants' (.h files effectively).

"Technically line_length is a variable"...: No - it's a name that
binds to an object that happens to be an integer. You've participated
in discussions re: this. Similarly 'number_of_apples =
number_of_apples + 1' is not an assignment ;) It's nit-picky and I
realise you're trying to keep it simple, but as it's meant for new
programmers to the Python language, then introduce them to Python's
way of "variables", they'll thank you for it later... (or run
screaming, or start another thread here...)

I've never seen/heard != described as "different from"; what's wrong
with "not equal to"? And why no mention of 'not' (should be mentioned
with booleans surely?).

That's as far as I've got; might get around to reading more later...

Cool tree at the end :)

Cheers,

Jon









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


Re: String prefix question

2009-11-09 Thread Gerard Flanagan

Alan Harris-Reid wrote:
In the Python.org 3.1 documentation (section 20.4.6), there is a simple 
“Hello World” WSGI application which includes the following method...


def hello_world_app(environ, start_response):
status = b'200 OK' # HTTP Status
headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers
start_response(status, headers)

# The returned object is going to be printed
return [b"Hello World"]

Question - Can anyone tell me why the 'b' prefix is present before each 
string? The method seems to work equally well with and without the 
prefix. From what I can gather from the documentation the b prefix 
represents a bytes literal, but can anyone explain (in simple english) 
what this means?


Many thanks,
Alan


Another link:

http://www.stereoplex.com/two-voices/python-unicode-and-unicodedecodeerror


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


Re: [PYTHON] How to set the range for x-axis

2009-11-09 Thread Moses
Hi Chris,

The code is

from scipy import *
from pylab import *

x = [0.5,0.6,0.7,0.8,0.9,1.0]
y = [2,6,8,10,10,10]

plot(x,y,linewidth=5.0)
show()

and not

from scipy import *
from pylab import *

x1 = [0.5,0.6,0.7,0.8,0.9,1.0]
x2 = [0,1,2,3,4,5,6,7,8,9,10]

plot(x1,y01,linewidth=5.0)
show()


Moses

On Mon, Nov 9, 2009 at 6:43 PM, Moses  wrote:

>
> Hi Chris,
>
> I am using python 2.6 and am using scipy and pylab. See the code below.
> Cheers.
>
> from scipy import *
> from pylab import *
>
> x1 = [0.5,0.6,0.7,0.8,0.9,1.0]
> x2 = [0,1,2,3,4,5,6,7,8,9,10]
>
> plot(x1,y01,linewidth=5.0)
> show()
>
> Thanks.
> .
>
>
>
> On Mon, Nov 9, 2009 at 5:49 PM, Chris Rebert  wrote:
>
>> On Mon, Nov 9, 2009 at 7:45 AM, Moses  wrote:
>> > I have written a script in python to plot a graph. However, the
>> > range for the x-axis starts from 0.5 to 1.0. However, I would like
>> > to start from 0 to 1. Any pointer to this shall be appreciated.
>>
>> Some /very/ basic information such as what plotting library you're
>> using would be necessary to answer your question. What version of
>> Python you're using would also be useful.
>>
>> Cheers,
>> Chris
>> --
>> http://blog.rebertia.com
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [PYTHON] How to set the range for x-axis

2009-11-09 Thread Moses
Hi Chris,

I am using python 2.6 and am using scipy and pylab. See the code below.
Cheers.

from scipy import *
from pylab import *

x1 = [0.5,0.6,0.7,0.8,0.9,1.0]
x2 = [0,1,2,3,4,5,6,7,8,9,10]

plot(x1,y01,linewidth=5.0)
show()

Thanks.
.


On Mon, Nov 9, 2009 at 5:49 PM, Chris Rebert  wrote:

> On Mon, Nov 9, 2009 at 7:45 AM, Moses  wrote:
> > I have written a script in python to plot a graph. However, the
> > range for the x-axis starts from 0.5 to 1.0. However, I would like
> > to start from 0 to 1. Any pointer to this shall be appreciated.
>
> Some /very/ basic information such as what plotting library you're
> using would be necessary to answer your question. What version of
> Python you're using would also be useful.
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows)

2009-11-09 Thread Alf P. Steinbach

Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far.

It's now Python 3.x, and reworked with lots of graphical examples and more 
explanatory text, plus limited in scope to Basic Concepts (which I previously 
just had as a first ch 2 section  --  but there's rather a lot of concepts!).


I think it's wise to invite comments even when it's not 100% completed. First, 
because as opposed to ch 1 there is quite a bit of code here, and since I'm a 
Python newbie I may be using non-idiomatic constructs, not to mention doing 
worse things. :-) Second, because comments in general can improve the text.



Contents:

2.1 Super-basic concept: why programming is not DWIM.   1
2.2 Reported errors.4
2.2.1   Case-sensitity. 4
2.2.2   Syntax / compilation errors.4
2.2.3   Runtime errors / crashes.   5
2.3 A programming exploration tool: turtle graphics.6
2.4 Naming things.  8
2.4.1   Naming actions: routines.   8
2.4.2   Naming data part I: variables.  11
2.4.3   Naming data part II: routine arguments. 13
2.5 Controlling the flow of execution.  14
2.5.1   Repeating actions automatically: loops. 14
2.5.2   Basic comparisions & boolean values.16
2.5.3   Interlude I: a function graph program / about types.17
2.5.4   Automated action choices.   21
2.5.5   Value-producing (function-like) routines.   23
2.5.6   Interlude II: a graph with zeroes marked / about program structure. 26
2.5.7   Dynamically nested actions: recursive routines. 28
2.6 Objects. [Not started on this] 31
2.7 Collections.[Not started on this] 31


In Google Docs (both chapters available here):

http://preview.tinyurl.com/ProgrammingBookP3>
Formats: PDF


Cheers,

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


Re: OT: regular expression matching multiple occurrences of one group

2009-11-09 Thread Jon Clements
On Nov 9, 1:53 pm, pinkisntwell  wrote:
> How can I make a regular expression that will match every occurrence
> of a group and return each occurrence as a group match? For example,
> for a string "-c-c-c-c-c", how can I make a regex which will return a
> group match for each occurrence of "-c"?

As well as what Diez has said, unless you absolutely want regexp's,
and by the sounds of it I'm guessing you may be after something more
flexible: what about the pyparsing module [1]. It handles your
situation quite nicely.

>>> import pyparsing
>>> parser = pyparsing.ZeroOrMore('-c')
>>> parser.parseString('-c-c-c-c-c-c')
(['-c', '-c', '-c', '-c', '-c', '-c'], {})

hth,
Jon.


[1] http://pyparsing.wikispaces.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI vs mod_python

2009-11-09 Thread Victor Subervi
Uuuuh. Thanks!
V

On Mon, Nov 9, 2009 at 10:45 AM, sstein...@gmail.com wrote:

> On Nov 9, 2009, at 10:41 AM, Victor Subervi wrote:
>
> On Mon, Nov 9, 2009 at 10:29 AM, sstein...@gmail.com 
> wrote:
>
>>
>> On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote:
>>
>>  Yes, obviously. But if CGI is enabled, it should work anyway, should it
>>> not?
>>>
>>
>> Depends on what "CGI is enabled" means.
>>
>> Usually, web servers are not set to just handle cgi scripts from anywhere,
>> but only from specific file system locations.  Otherwise, an an anonymous
>> upload could be executed as CGI and wreak havoc.
>>
>
> Of course, yes.
>
>>
>> And "it should work anyway, should it not" is already answered by "they're
>> having trouble getting my scripts to work."
>>
>
> They're having _all_sorts_of_trouble_ getting my scripts to work, not just
> this issue. These scripts worked fine on another server. I don't understand
> what the problems are, and I'm trying to parameterize.
>
>
> Gotcha.
>
> Do you have access to and have you given them the old httpd.conf?
>
> That could certainly give them some clues about what's different.
>
> Also, there is (on apache 2.x+ anyway) a whole directory tree full of
> included files that get sucked in as the configuration is getting built so
> that whole tree would give them everything they would need (if they know how
> to work from it which they should if they're running a "server farm").
>
> S
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: regular expression matching multiple occurrences of one group

2009-11-09 Thread Diez B. Roggisch

pinkisntwell schrieb:

How can I make a regular expression that will match every occurrence
of a group and return each occurrence as a group match? For example,
for a string "-c-c-c-c-c", how can I make a regex which will return a
group match for each occurrence of "-c"?


Why is this flagged "OT"?

And in python, you can't do that. Groups are based upon the lexical 
structure of the regexp, and thus have a fixed number of groups.


Either use repetitive searches over the input, or postprocess the 
combined group by e.g. splitting it.


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


Re: [PYTHON] How to set the range for x-axis

2009-11-09 Thread Chris Rebert
On Mon, Nov 9, 2009 at 7:45 AM, Moses  wrote:
> I have written a script in python to plot a graph. However, the
> range for the x-axis starts from 0.5 to 1.0. However, I would like
> to start from 0 to 1. Any pointer to this shall be appreciated.

Some /very/ basic information such as what plotting library you're
using would be necessary to answer your question. What version of
Python you're using would also be useful.

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


[PYTHON] How to set the range for x-axis

2009-11-09 Thread Moses
Hi Everyone,

I have written a script in python to plot a graph. However, the
range for the x-axis starts from 0.5 to 1.0. However, I would like
to start from 0 to 1. Any pointer to this shall be appreciated.

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


Re: CGI vs mod_python

2009-11-09 Thread sstein...@gmail.com


On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote:

Yes, obviously. But if CGI is enabled, it should work anyway, should  
it not?


Depends on what "CGI is enabled" means.

Usually, web servers are not set to just handle cgi scripts from  
anywhere, but only from specific file system locations.  Otherwise, an  
an anonymous upload could be executed as CGI and wreak havoc.


And "it should work anyway, should it not" is already answered by  
"they're having trouble getting my scripts to work."


S



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


Re: CGI vs mod_python

2009-11-09 Thread Victor Subervi
Yes, obviously. But if CGI is enabled, it should work anyway, should it not?
V

On Mon, Nov 9, 2009 at 9:46 AM, sstein...@gmail.com wrote:

>
> On Nov 9, 2009, at 9:32 AM, Victor Subervi wrote:
>
>  Hi;
>> I've  been told by a server farm that they're having trouble getting my
>> scripts to work because they're written with cgi calls as opposed to
>> mod_python. Is there a basis for their complaint? These pages serve fine on
>> another server.
>>
>
> Does the server they're working fine on use CGI?  Yes, they're different.
>
> S
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing GUI Module for Python

2009-11-09 Thread Kevin Walzer

On 11/8/09 11:49 PM, Antony wrote:

Hi all
I just wanted to know which module is best for developing designing
interface in python .
i have come across some modules which are listed here . please tell
your suggestions and comments to choose best one
  1. PyGTK
  2. PyQT
  3. PySide
  4.  wxPython
  5 . TKinter

Also i need to know is there any IDE for developing these
things . . .



http://lmgtfy.com/?q=gui+toolkit+for+python

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Query about doing fortran-esque repeat formatting

2009-11-09 Thread Rob Briggs
Thanks to the chaps who answered,  

I knew there would be an efficient answer to this.

regards, 

Rob


On Mon, 2009-11-09 at 13:31 +0100, Jean-Michel Pichavant wrote:
> Glenn Hutchings wrote: 
> > Rob Briggs  mun.ca> writes:
> > 
> >   
> > > Is there a way to do a repeat formatting command like in Fortran? Rather
> > > that doing this:
> > > 
> > > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" %
> > > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4],  tmp[i][6],  tmp[i][7],
> > > tmp[i][8],  tmp[i][9])
> > > 
> > 
> > There certainly is.  You can use python's string concatenation
> > and repeat operators:
> > 
> > print "%s" + " %-5.3f" * 7 % 
> > 
> > Glenn
> > 
> >   
> 
> data = tuple(parmName[i]) + tuple(tmp[i]) 
> print "%s" + " %-5.3f" * len(tmp[i]) % data
> 
> That should do the trick.
> 
> JM

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


Re: CGI vs mod_python

2009-11-09 Thread sstein...@gmail.com


On Nov 9, 2009, at 9:32 AM, Victor Subervi wrote:


Hi;
I've  been told by a server farm that they're having trouble getting  
my scripts to work because they're written with cgi calls as opposed  
to mod_python. Is there a basis for their complaint? These pages  
serve fine on another server.


Does the server they're working fine on use CGI?  Yes, they're  
different.


S

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


CGI vs mod_python

2009-11-09 Thread Victor Subervi
Hi;
I've  been told by a server farm that they're having trouble getting my
scripts to work because they're written with cgi calls as opposed to
mod_python. Is there a basis for their complaint? These pages serve fine on
another server.
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sort values from dictionary of dictionaries python 2.4

2009-11-09 Thread Peter Otten
J Wolfe wrote:

> I would like to sort this dictionary by the values of the inner
> dictionary ‘ob’ key.

Python's built-in dictionary is unsorted by design.
 
> mydict =
> {’WILW1′: {’fx’: ‘8.1′, ‘obtime’: ‘2009-11-07 06:45:00′, ‘ob’: ‘6.9′},
> ‘GRRW1′: {’fx’: ‘12.8′, ‘obtime’: ‘2009-11-07 04:15:00′, ‘ob’: ‘6.7′},
> ‘NASW1′: {’fx’: ‘6.8′, ‘obtime’: ‘2009-11-07 06:30:00′, ‘ob’: ‘7.1′}
> }
> 
> In this case, this would become:
> 
> mysorteddic =
> {’NASW1′: {’fx’: ‘6.8′, ‘obtime’: ‘2009-11-07 06:30:00′, ‘ob’: ‘7.1′},
> ‘WILW1′: {’fx’: ‘8.1′, ‘obtime’: ‘2009-11-07 06:45:00′, ‘ob’: ‘6.9′},
> ‘GRRW1′: {’fx’: ‘12.8′, ‘obtime’: ‘2009-11-07 04:15:00′, ‘ob’: ‘6.7′}
> }
> 
> I have had no luck in trying to figure this out. I am restricted to
> using python 2.4.3.
> 
> Any help would be appreciated!

You may be able to work around that limitation by putting the dict items 
into a list and sort that:

>>> for item in sorted(mydict.items(), key=lambda (k, v): float(v["ob"]), 
reverse=True):
... print item
...
('NASW1', {'fx': '6.8', 'obtime': '2009-11-07 06:30:00', 'ob': '7.1'})
('WILW1', {'fx': '8.1', 'obtime': '2009-11-07 06:45:00', 'ob': '6.9'})
('GRRW1', {'fx': '12.8', 'obtime': '2009-11-07 04:15:00', 'ob': '6.7'})

Peter

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


Re: Choosing GUI Module for Python

2009-11-09 Thread sstein...@gmail.com


On Nov 9, 2009, at 3:59 AM, Antony wrote:


You may want to offer a little more info, like what exactly you are
looking to do with such GUI. are your needs for a  VW, Corvette, or
Mercedes? etc, etc. All these kits have pros and cons, some better  
for

this some for that, yadda yadda


I would like to know about that pros and cons only ...


What might be a "pro" for one use case could easily be a "con" for  
another.


For example, Kit-X may be infinitely configurable to run on everything  
from 800x600  to 1680x1050 pixel monitors with full viewport control,  
full zoom, pan,  etc. and requires that all those cases be handled  
with correct configuration.


That's great if you're writing an application that requires that.

But, if you're writing a Pref Pane for OS X, which will never be any  
bigger than the pref-pane window and will only run on OS X, that  
particular kit might be a huge waste of time.


The "pro" of infinite flexibility becomes a huge "con" for the OS X  
Pref Pane use-case.


S

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


OT: regular expression matching multiple occurrences of one group

2009-11-09 Thread pinkisntwell
How can I make a regular expression that will match every occurrence
of a group and return each occurrence as a group match? For example,
for a string "-c-c-c-c-c", how can I make a regex which will return a
group match for each occurrence of "-c"?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: advice needed for lazy evaluation mechanism

2009-11-09 Thread markolopa
On Nov 9, 1:34 am, MRAB  wrote:
> markolopa wrote:
> > Hi again,
>
> > I put a copy of the message and the tarball of the code here (because
> > of the problem of line breaks):
>
> >http://python-advocacy.wikidot.com/comp-lang-python-question
>
> Here's a slightly different approach:

A clean and elegant solution, very impressive! Also a collection of
nice Python features I had never used.

Thanks a lot!
Marko
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: superpy 1.2.1

2009-11-09 Thread Emin.shopper Martinian.shopper
I am pleased to announce the release of superpy 1.2.1 available from
http://code.google.com/p/superpy.

As this is the first announcement of superpy, any comments and
feedback would be much appreciated.

--

Superpy distributes python programs across a cluster of machines or
across multiple processors on a single machine. This is a
coarse-grained form of parallelism in the sense that remote tasks
generally run in separate processes and do not share memory with the
caller.

Key features of superpy include:

* Send tasks to remote servers or to same machine via XML RPC call
* GUI to launch, monitor, and kill remote tasks
* GUI can automatically launch tasks every day, hour, etc.
* Works on the Microsoft Windows operating system
  o Can run as a windows service
  o Jobs submitted to windows can run as submitting user or as
service user
* Inputs/outputs are python objects via python pickle
* Pure python implementation
* Supports simple load-balancing to send tasks to best servers

The ultimate vision for superpy is that you:

   1. Install it as an always on service on a cloud of machines
   2. Use the superpy scheduler to easily send python jobs into the
cloud as needed
   3. Use the SuperWatch GUI to track progress, kill tasks, etc.

For smaller deployments, you can use superpy to take advantage of
multiple processors on a single machine or multiple machines to
maximize computing power.

What makes superpy different than the many other excellent parallel
processing packages already available for python? The superpy package
is designed to allow sending jobs across a large number of machines
(both Windows and LINUX). This requires the ability to monitor, debug,
and otherwise get information about the status of jobs.

While superpy is currently used in production for a number of
different purposes, there are still many features we want to add. For
a list of future plans and opportunities to help out or add to the
discussion, please visit
http://code.google.com/p/superpy/wiki/HelpImproveSuperpy.

For a quick example of some of the the things superpy can do, check
out http://code.google.com/p/superpy/wiki/Demos or in particular the
demo application PyFog at http://code.google.com/p/superpy/wiki/PyFog.

To install, you can use easy_install to try superpy via "easy_install
superpy" or download a python egg from downloads. Of course, you will
need python installed and if you are using windows, you should also
install the python windows tools from
http://sourceforge.net/projects/pywin32/files. See
http://code.google.com/p/superpy/wiki/InstallFAQ if you have more
questions about installation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Query about doing fortran-esque repeat formatting

2009-11-09 Thread Jean-Michel Pichavant

Glenn Hutchings wrote:

Rob Briggs  mun.ca> writes:

  

Is there a way to do a repeat formatting command like in Fortran? Rather
that doing this:

print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" %
(parmName[i], tmp[i][1], tmp[i][2], tmp[i][4],  tmp[i][6],  tmp[i][7],
tmp[i][8],  tmp[i][9])



There certainly is.  You can use python's string concatenation
and repeat operators:

print "%s" + " %-5.3f" * 7 % 

Glenn

  


data = tuple(parmName[i]) + tuple(tmp[i])

print "%s" + " %-5.3f" * len(tmp[i]) % data

That should do the trick.

JM

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


Re: Cancelling a python thread (revisited...)

2009-11-09 Thread Antoine Pitrou
Le Sun, 08 Nov 2009 21:04:06 -0800, John Nagle a écrit :
> Antoine Pitrou wrote:
>> John Nagle  animats.com> writes:
>>> I'd argue against general thread cancellation.  Inter-thread
>>> signals, though, have safety problems no worse than the first-thread
>>> only signals we have now.  You're allowed to raise an exception in a
>>> signal handler, which is effectively thread cancellation.
>> 
>> Can you give an example of such "cancellation"? In any case, this would
>> be a side-effect of the current implementation, not officially
>> supported behaviour.
> 
> It's not only documented behavior, it's an example in the official
> documentation.  See
> 
>   http://docs.python.org/library/signal.html#example

Well, the only supported behaviour is to send signals to the main thread. 
Besides, it doesn't "cancel" the thread, it just raises an exception in 
it, which can be caught and silenced. Just try the following:


import signal, time

def handler(signum, frame):
print 'Signal handler called with signal', signum
raise IOError

# Set the signal handler and a 5-second alarm
signal.signal(signal.SIGALRM, handler)
signal.alarm(2)

try:
time.sleep(10)
except IOError:
print "got IOError!"


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


Re: username/password dialog prompt

2009-11-09 Thread Dan Winsor
On Nov 6, 4:40 pm, Cousin Stanley  wrote:
> > My Tkinter is very rusty but perhaps you could do it
> > something like this :  http://pastebin.com/m5e49da19
>
> > I forgot how to get rid of the empty root window
> > that appears, sorry.
>
>   root.withdraw()   # should do it

Thanks to you both - exactly what I was looking for.  Much
appreciated.


--
Dan Winsor


Soy un poco loco en el coco.


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


Re: how to remove the same words in the paragraph

2009-11-09 Thread Tim Chase

I think simple regex may come handy,

  p=re.compile(r'(.+) .*\1')#note the space
  s=p.search("python and i love python")
  s.groups()
  (' python',)

But that matches for only one double word.Someone else could light up here
to extract all the double words.Then they can be removed from the original
paragraph.


This has multiple problems:

>>> p = re.compile(r'(.+) .*\1')
>>> s = p.search("python one two one two python")
>>> s.groups()
('python',)
>>> s = p.search("python one two one two python one")
>>> s.groups() # guess what happened to the 2nd "one"...
('python one',)

and even once you have the list of theoretical duplicates (by 
changing the regexp to r'\b(\w+)\b.*?\1' perhaps), you still have 
to worry about emitting the first instance but not subsequent 
instances.


-tkc




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


Re: Query about doing fortran-esque repeat formatting

2009-11-09 Thread Glenn Hutchings
Rob Briggs  mun.ca> writes:

> Is there a way to do a repeat formatting command like in Fortran? Rather
> that doing this:
> 
> print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" %
> (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4],  tmp[i][6],  tmp[i][7],
> tmp[i][8],  tmp[i][9])

There certainly is.  You can use python's string concatenation
and repeat operators:

print "%s" + " %-5.3f" * 7 % 

Glenn

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


Re: installing library on MAC OS X 10.5.8

2009-11-09 Thread Diez B. Roggisch

Xbiton schrieb:

Hi,
I'm new to mac and I'm having a lot of problems installing library on
mac ox x 10.5.8.
I want to install PyXML and although the install procedure - just done
like described on the web page of PyXML -


That's a 5-years-old XML package. Don't use it. Your python2.5 already 
features element-tree, which is much nicer to use.


Or is there a specific reason you need PyXML?

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


how to close not response win32 IE com interface

2009-11-09 Thread elca

hello,
these day im making some script that use win32 IE com interface.
one of problem is , my internet line is very slow, so sometimes my
IE.navigate("http://www.example.com";)
not response timely.
it looks hang and open status, not complete status.
so my IE.navigate function is not correctly working.
anyone can help me? in that case ,how to close or restart my script from
start.
thanks in advance
Paul
-- 
View this message in context: 
http://old.nabble.com/how-to-close-not-response-win32-IE-com-interface-tp26265055p26265055.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Choosing GUI Module for Python

2009-11-09 Thread Antony
On Nov 9, 11:49 am, r  wrote:
> On Nov 8, 10:49 pm, Antony  wrote:
>
> > Hi all
> >    I just wanted to know which module is best for developing designing
> > interface in python .
> > i have come across some modules which are listed here . please tell
> > your suggestions and comments to choose best one
> >  1. PyGTK
> >  2. PyQT
> >  3. PySide
> >  4.  wxPython
> >  5 . TKinter
>
> > Also i need to know is there any IDE for developing these
> > things . . .
>
> You may want to offer a little more info, like what exactly you are
> looking to do with such GUI. are your needs for a  VW, Corvette, or
> Mercedes? etc, etc. All these kits have pros and cons, some better for
> this some for that, yadda yadda

I would like to know about that pros and cons only ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Indentation problems

2009-11-09 Thread r
On Nov 8, 1:48 pm, Tim Chase  wrote:
> > I am having problems with indentation some times. When I hit the enter key
> > after if statements or while statemt there are times when the indentation is
> > too much and other times too little.

Check for omitted brackets, braces and parenthesis. If you editor uses
an auto indent function like even IDLE does then this will be the
culprit!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing GUI Module for Python

2009-11-09 Thread r
On Nov 8, 10:49 pm, Antony  wrote:
> Hi all
>    I just wanted to know which module is best for developing designing
> interface in python .
> i have come across some modules which are listed here . please tell
> your suggestions and comments to choose best one
>  1. PyGTK
>  2. PyQT
>  3. PySide
>  4.  wxPython
>  5 . TKinter
>
> Also i need to know is there any IDE for developing these
> things . . .

You may want to offer a little more info, like what exactly you are
looking to do with such GUI. are your needs for a  VW, Corvette, or
Mercedes? etc, etc. All these kits have pros and cons, some better for
this some for that, yadda yadda
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cancelling a python thread (revisited...)

2009-11-09 Thread John Nagle

Antoine Pitrou wrote:

John Nagle  animats.com> writes:

I'd argue against general thread cancellation.  Inter-thread
signals, though, have safety problems no worse than the first-thread
only signals we have now.  You're allowed to raise an exception
in a signal handler, which is effectively thread cancellation.


Can you give an example of such "cancellation"?
In any case, this would be a side-effect of the current implementation, not
officially supported behaviour.


   It's not only documented behavior, it's an example in the official 
documentation.  See


http://docs.python.org/library/signal.html#example

where an exception is raised in a signal handler.

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


Choosing GUI Module for Python

2009-11-09 Thread Antony
Hi all
   I just wanted to know which module is best for developing designing
interface in python .
i have come across some modules which are listed here . please tell
your suggestions and comments to choose best one
 1. PyGTK
 2. PyQT
 3. PySide
 4.  wxPython
 5 . TKinter

Also i need to know is there any IDE for developing these
things . . .

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


Re: Help with OS X installation

2009-11-09 Thread stephen_b
Thanks all. That did it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonw.exe under Windows-7 (Won't run for one admin user)

2009-11-09 Thread SD_V897



Dennis Lee Bieber wrote:

On Fri, 06 Nov 2009 21:19:44 GMT, SD_V897 
declaimed the following in gmane.comp.python.general:


AppPath=C:\Program Files\Utilities\Python Scripting v2.62\pythonw.exe


That's an interesting path... Did the install path for Python (from
either python.org or activestate) change that much from 2.5.x, or is
that a custom install path (and is it the same path for the accounts it
works in). Especially as there is no "v2.62" to my knowledge... a 2.6.2,
OTOH...

Now... I did change the upper level directory for mine (E:\; my C:
partition is rather packed, and I tend to install a lot of packages from
my user account), but the installer named top level was
"\Python25\pythonw.exe"




I've added the folder directory to my PATH statement and also tried 
installing to the root but it doesn't make a difference. The 2.62 should 
be 2.64 my bad..


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


Re: String prefix question

2009-11-09 Thread Ben Finney
Alan Harris-Reid  writes:

> From what I can gather from the documentation the b prefix represents
> a bytes literal

Yes. In Python 3 there are two types with similar-looking literal
syntax: ‘str’ and ‘bytes’. The types are mutually incompatible (though
they can be explicitly converted).

http://docs.python.org/3.1/library/stdtypes.html#typesseq>
http://docs.python.org/3.1/reference/lexical_analysis.html#strings>

> but can anyone explain (in simple english) what this means?

It means the difference between “a sequence of bytes” and “a sequence of
characters”. The two are not the same, have not ever been the same
despite a long history in computing of handwaving the differences, and
Python 3 finally makes them unambiguously distinct.

A general solution wasn't even feasible for a long time, but now we have
Unicode, a mature standard for uniformly representing all the world's
writing systems in software. So Python 3 made ‘str’ the Unicode “string
of characters” type, and the ‘'foo'’ literal syntax creates objects of
this type.

The Python 3.1 documentation has a Unicode HOWTO that you should read
http://docs.python.org/3.1/howto/unicode.html>.

-- 
 \   “We must respect the other fellow's religion, but only in the |
  `\   sense and to the extent that we respect his theory that his |
_o__) wife is beautiful and his children smart.” —Henry L. Mencken |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Debugging python in emacs isn't working.

2009-11-09 Thread menomnon
Hi,

Emacs 22.3, python 2.6.4

Put the following into my .emacs:

(setq pdb-path 'c:\\python26\\lib\\pdb.py
  gud-pdb-command-name (symbol-name pdb-path))
(defadvice pdb (before gud-query-cmdline activate)
  "Provide a better default command line when called interactively."
  (interactive
   (list (gud-query-cmdline pdb-path
(file-name-nondirectory buffer-file-name)


So when I'm in a python buffer (I've tried both python.el and python-
mode.el) and do M-x pdb I get, say:

c:\python26\lib\pdb.py rpytest.py

hit  and get an empty buffer that says "Comint: no process".  And
the status line says: "Spawning child process: invalid argument".

I've run into "spawning child process: invalid argument" before but
not being an emacs uber-geek I never solved it directly.

Hope someone has an idea of what I'm doing wrong.



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