i have error then use ftplib

2006-03-29 Thread Леонов Алексей
Hello!
I use this code:

from ftplib import FTP
def handleDownload(block):
file.write(block)
print "."

file = open('1', 'wb')
ftp = FTP('ftp.utk.ru')
ftp.set_pasv(1)
ftp.login()
ftp.retrlines('LIST')
ftp.cwd('users/video/Anime/Beyond the Clouds')
ftp.retrbinary('RETR "[Triad]_Beyond_the_Clouds_CD1.srt"', handleDownload, 
1024, 600 )

ftp.quit()
file.close()


and have this error message.

Traceback (most recent call last):
  File "ftp.py", line 10, in ?
ftp.retrlines('LIST')
  File "C:\Python24\lib\ftplib.py", line 396, in retrlines
conn = self.transfercmd(cmd)
  File "C:\Python24\lib\ftplib.py", line 345, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
  File "C:\Python24\lib\ftplib.py", line 324, in ntransfercmd
conn.connect(sa)
  File "", line 1, in connect
socket.error: (10065, 'No route to host')


Programs that not use Python connect to the server ok.
Where I do mistake?

   Best regards
   nazarianin

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


Re: any() and all() on empty list?

2006-03-29 Thread Steven D'Aprano
Tim Peters wrote:

>>In the all() example, if there *are* no values in S, then none of the
>>values can be != 0, and IMHO all() should return False.
> 
> 
> That would break everything mentioned above.  Think of it another way:
>  if all(seq) is false, shouldn't it be the case that you can point to
> a specific element in seq that is false?  

Think of it this way: if all(seq) is true, shouldn't it 
be the case that you can point to a specific element in 
seq that is true?

It may be that all([]) => True is useful more often 
than all([]) => False would be, in the same way that it 
is useful to define 0! = 1 and other mathematical 
identities, but that doesn't imply that, strictly 
speaking, there isn't some monkey-business going on there.

Now, I'm happy to admit that this is useful 
monkey-business, but it can still lead to unexpected 
results, as in my example in a previous post.



-- 
Steven.

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


Re: difference between .cgi and .py

2006-03-29 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:
> Hi,
> I am new to python.. I have uploaded few scripts in my cgi-bin folder,
> some with extension .cgi and some with .py.

Only how the Web server is configured.

> What is the difference between the two extensions.. which one is more
> prefered, do it effects performance ??

Unless the server is fundamentally broken, it will make no difference 
whatsoever.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Physics, as we know it, will be over in six months.
   -- Max Born (1928)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dynamic construction of variables / function names

2006-03-29 Thread Steven D'Aprano
Sakcee wrote:

> python provides a great way of dynamically creating fuctions calls and
> class names from string
> 
> a function/class name can be stored as string and called/initilzed
> 
> e.g
> 
> def foo(a,b):
> return a+b
> 
> def blah(c,d):
> return c*d
> 
> 
> list = ["foo", "blah"]
> 
> for func in list:
>   print func(2,4)
> 
> or similar items

Have you actually tried to do this? It doesn't work:

Traceback (most recent call last):
   File "", line 2, in ?
TypeError: object of type 'string' is not callable

(Also, it is poor practice to shadow the built-in list 
as you have.)

You are attempting to call "foo"(2, 4). Strings are not 
callable.

Two ways to actually do what you are trying to do is 
with eval and exec:

 >>> eval("foo(2, 3)")
5
 >>> exec("print foo(2, 3)")
5

but be aware of the possible security implications of 
eval and exec.

If you are calling instance methods, you can use getattr:

 >>> class Foo:
... def foo(self, x,y):
... return x+y
...
 >>> getattr(Foo(), "foo")(2, 3)
5

But the best way is, if possible, avoid this altogether 
and remember that functions are first-class objects in 
Python. Instead of doing this:

L = ["foo", "bar"]
for func in L:
 print eval(func + "(2, 3)")

do this:

L = [foo, bar]  # list containing function objects
for func in L:
 print func(2, 3)


> what is the way if the names of functions are some modification e.g

As far as I know, the only ways are: use eval or exec, 
or look in locals and/or globals:

 >>> func = locals().get("f" + "oo", None)
 >>> if callable(func):
... func(2, 3)
...
5

You can use globals() instead of locals(), but there 
may be issues with scoping rules that I can't think of.

Personally, I think the best way is: find another way 
to solve your problem.


> is it correct way, is there a simple way, is this techniqe has a name?

I'm told that some people call this "dynamic 
programming", but personally I call it "difficult to 
maintain, difficult to debug programming".

(Before people get all cranky at me, I'm aware that it 
isn't *always* the Wrong Way to solve problems, but it 
is a technique which is subject to abuse and can often 
be avoided by using function objects instead of 
function names.)


-- 
Steven.

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


Re: any() and all() on empty list?

2006-03-29 Thread Duncan Booth
Ron Adam wrote:

> Where we are assembling widgets in a manufacturing plant. Where we don't 
> want to go to the next step until *all* the sub parts are present.
> 
> if all(part.status == 'present' for part in unit):
>  do_release()
> 
> Oops!  Some empty bins showed up at the next assembly station. ;-)

I don't see the problem. You only get an empty bin if there is some part 
assembled from no sub-parts, in which case you wanted an empty bin.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: difference between .cgi and .py

2006-03-29 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with:
> I am new to python.. I have uploaded few scripts in my cgi-bin
> folder, some with extension .cgi and some with .py.
>
> What is the difference between the two extensions..

None at all, except the way you write them.

> which one is more prefered

That depends. If you want to hide the fact that you're using Python,
use .cgi. If you want to show that, use .py.

> do it effects performance ??

Nope.

This is all assuming you're using the most widely used webserver
Apache.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dynamic construction of variables / function names

2006-03-29 Thread Duncan Booth
Sakcee wrote:

> python provides a great way of dynamically creating fuctions calls and
> class names from string
> 
> a function/class name can be stored as string and called/initilzed
> 
> e.g
> 
> def foo(a,b):
> return a+b
> 
> def blah(c,d):
> return c*d
> 
> 
> list = ["foo", "blah"]
> 
> for func in list:
>  print func(2,4)
> 
> or similar items

No, that doesn't work. To convert a string to a function name you have to 
look it up in a suitable namespace, or store a list of functions instead of 
a list of strings. So something like this would work:

 lst = [foo, blah]
 
 for func in lst:
  print func(2,4)


> 
> 
> what is the way if the names of functions are some modification e.g
> 
> def Newfoo(a,b):
> return a+b
> 
> def Newblah(c,d):
> return c*d
> 
> list = ["foo", "blah"]
> 
> for func in list:
>  print "New"+func(2,4)
> 
> or define a variable
> 
> "New"+list[0] = "First Funciton"
> 
> 
> I think ,   print "New"+func(2,4)  and "New"+list[0] = "First
> Funciton"
> 
> will not work,  either eval or exec should be used
> is it correct way, is there a simple way, is this techniqe has a name?
> 
One common way is to group the functions you want callable together in a 
class and then use getattr to access them.

class Commands:
  def Newfoo(self, a,b):
  return a+b
 
  def Newblah(self, c,d):
  return c*d

  def call(self, fname, *args. **kw):
  fn = getattr(self, "New"+fname)
  return fn(*args, **kw)

cmds = Commands()
lst = ["foo", "blah"]
for func in lst:
print cmds.call(func, 2, 4)
-- 
http://mail.python.org/mailman/listinfo/python-list


does python could support sequence of short or int?

2006-03-29 Thread momobear
hi, is there a way to let python operate on sequence of int or short?
In C, we just need declare a point, then I could get the point value,
just like:
short* k = buffer, //k is a point to a sequence point of short.
short i = *k++,
but python is a dynamic language,
a = buffer
i = ? I don't know how to continue, what's a? a seems to be a str?

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


Re: dynamic construction of variables / function names

2006-03-29 Thread Felipe Almeida Lessa
Em Qua, 2006-03-29 às 22:44 -0800, Sakcee escreveu:
> either eval or exec should be used
> is it correct way, is there a simple way, is this techniqe has a name?

eval and exec are insecure. Try looking at globals():

$ python2.4
Python 2.4.3c1 (#2, Mar 29 2006, 08:34:35)
[GCC 4.0.3 (Debian 4.0.3-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def Newfoo(a, b):
... return a+b
...
>>> def Newblah(c, d):
... return c*d
...
>>> list = ["foo", "blah"]
>>> for func in list:
... print globals()["New"+func](2, 4)
...
6
8
>>> # That was a bit confusing, let see in parts
... print globals()
{'Newblah': ,
 '__builtins__': ,
 'Newfoo': ,
 'list': ['foo', 'blah'],
 'func': 'blah',
 '__name__': '__main__',
 '__doc__': None}
>>> print globals()["New"+func]

>>> print globals()["New"+func](2, 4)
8
>>> # HTH,
...

-- 
Felipe.

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

Re: python challenge question (string manipulation)

2006-03-29 Thread Felipe Almeida Lessa
Em Qua, 2006-03-29 às 22:20 -0800, Caleb Hattingh escreveu:
> That is very succint.  Rewriting my shift function given earlier:
> 
> >>> import string
> >>> alpha = string.ascii_lowercase
> >>> print alpha
> abcdefghijklmnopqrstuvwxyz
> >>> def shift(lst, n):
>   return [lst[(i+len(lst)-n)%len(lst)] for i,item in enumerate(lst)]

It sure is short, but is it fast? Compare to the function below (the
fastest I can think of ATM):

def shift(lst, n):
first = (-n) % len(lst)
result = list(lst[first:]) # if lst is a iterable but not a list
result.extend(lst[:first])
return result

Now benchmarking:

$ python2.4 -mtimeit -s "def shift(lst, n): return [lst[(i+len(lst)-n)%
len(lst)] for i,item in enumerate(lst)]"
"shift('abcdefghijklmnopqrstuvwxyz',2)"
1 loops, best of 3: 21.5 usec per loop
$ python2.4 -mtimeit -s "def shift(lst, n): length = len(lst); first =
(-n) % length; result = list(lst[first:]); result.extend(lst[:first]);
return result" "shift('abcdefghijklmnopqrstuvwxyz',2)"
10 loops, best of 3: 3.98 usec per loop

The five-line version is more than five times faster than the two-line
counterpart. But it scales better too:

$ python2.4 -mtimeit -s "string = 'abcdefghijklmnopqrstuvwxyz'*1 def
shift(lst, n): length = len(lst); first = (-n) % length; result =
list(lst[first:]); result.extend(lst[:first]); return result"
"shift(string,2)"
100 loops, best of 3: 10.6 msec per loop
$ python2.4 -mtimeit -s "string = 'abcdefghijklmnopqrstuvwxyz'*1
def shift(lst, n): return [lst[(i+len(lst)-n)%len(lst)] for i,item in
enumerate(lst)]" "shift(string,2)"
10 loops, best of 3: 206 msec per loop

With a 10 000 times larger list it takes almost 20 times less time.

Of course a human can't perceive a 17.52 usec difference in time, but
I'd like to make it clear that the two-line function shouldn't be used
on a real system.

What we learn from this? When it's not needed (like now), please don't
iterate over all items of a list.

HTH,

-- 
Felipe.

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

Re: dynamic construction of variables / function names

2006-03-29 Thread limodou
On 29 Mar 2006 22:44:24 -0800, Sakcee <[EMAIL PROTECTED]> wrote:
> python provides a great way of dynamically creating fuctions calls and
> class names from string
>
> a function/class name can be stored as string and called/initilzed
>
> e.g
>
> def foo(a,b):
> return a+b
>
> def blah(c,d):
> return c*d
>
>
> list = ["foo", "blah"]
>
> for func in list:
> print func(2,4)
>
> or similar items
>
>
> what is the way if the names of functions are some modification e.g
>
> def Newfoo(a,b):
> return a+b
>
> def Newblah(c,d):
> return c*d
>
> list = ["foo", "blah"]
>
> for func in list:
> print "New"+func(2,4)
>
> or define a variable
>
> "New"+list[0] = "First Funciton"
>
>
> I think ,   print "New"+func(2,4)  and "New"+list[0] = "First
> Funciton"
>
> will not work,  either eval or exec should be used
> is it correct way, is there a simple way, is this techniqe has a name?
>
> thanks
>

You could get the function object from globals(), for example:

for func in list:
   f = globals().get("New"+func, None)
   if f and callable(f):
print f(2, 4)

--
I like python!
My Blog: http://www.donews.net/limodou
My Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit
-- 
http://mail.python.org/mailman/listinfo/python-list


difference between .cgi and .py

2006-03-29 Thread amaltasb
Hi,
I am new to python.. I have uploaded few scripts in my cgi-bin folder,
some with extension .cgi and some with .py.

What is the difference between the two extensions.. which one is more
prefered, do it effects performance ??

Thanks

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


dynamic construction of variables / function names

2006-03-29 Thread Sakcee
python provides a great way of dynamically creating fuctions calls and
class names from string

a function/class name can be stored as string and called/initilzed

e.g

def foo(a,b):
return a+b

def blah(c,d):
return c*d


list = ["foo", "blah"]

for func in list:
print func(2,4)

or similar items


what is the way if the names of functions are some modification e.g

def Newfoo(a,b):
return a+b

def Newblah(c,d):
return c*d

list = ["foo", "blah"]

for func in list:
print "New"+func(2,4)

or define a variable

"New"+list[0] = "First Funciton"


I think ,   print "New"+func(2,4)  and "New"+list[0] = "First
Funciton"

will not work,  either eval or exec should be used
is it correct way, is there a simple way, is this techniqe has a name?

thanks

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


Re: excel application

2006-03-29 Thread luca72
Thanks Peter

Regards

Luca

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


Re: Simple py script to calc folder sizes

2006-03-29 Thread Caleb Hattingh
Hi John

Your code works on some folders but not others.   For example, it works
on my /usr/lib/python2.4 (the example you gave), but on other folders
it terminates early with StopIteration exception on the
os.walk().next() step.

I haven't really looked at this closely enough yet, but it looks as
though there may be an issue with permissions (and not having enough)
on subfolders within a tree.

I don't want you to work too hard on what is my problem, but are there
any ideas that jump out at you?

Regards
Caleb

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


Re: python challenge question (string manipulation)

2006-03-29 Thread Caleb Hattingh
Terry

That is very succint.  Rewriting my shift function given earlier:

>>> import string
>>> alpha = string.ascii_lowercase
>>> print alpha
abcdefghijklmnopqrstuvwxyz
>>> def shift(lst, n):
return [lst[(i+len(lst)-n)%len(lst)] for i,item in enumerate(lst)]

>>> print shift(alpha,2)
['y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x']

Shorter and possibly as clear too; thanks!

Keep well
Caleb

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


Re: Try Python!

2006-03-29 Thread Ben Finney
"Michael Tobis" <[EMAIL PROTECTED]> writes:

> So what is the scoop? Why does Guido say there is no such thing as a
> secure Python, and (as is generally reasonable) presuming he is correct
> on the matter, how can these sites work safely? 

"Security is a process, not a product."

There's no such thing as "a secure foo", in absolute terms. One can
point to flaws in non-foo and show how foo avoids those flaws; one can
possibly even defend a claim that "foo is more secure than bar". But
to state "there is no such thing as a secure foo" simply points out
that it is always possible to be "more secure", which is an ongoing
process of improvement that can never be complete.

Security is also not an absolute good. It's a truism that measures
which prevent illegitimate activity also incrementally make legitimate
activity more onerous. The real trick is to maximise the one and
minimise the other. The tradeoff can never be complete or perfect,
since everyone's definition of the right tradeoff is different and
constantly evolving.

Security is also not a single dimension. Physical security, personnel
security, network security, data security, risk management, etc
cetera; all these are areas that have their own set of security versus
accessibility tradeoffs.

In this light, the process of Python security must be ongoing; if it's
not, it's regressing. This doesn't mean Python is "not secure", or
"not safe"; those are absolutes again, and they don't apply.

Sites can operate securely by being aware of the security
ramifications of their infrastructure decisions, and being aware of
security issues that apply to anything they do. To pretend that
security can be obtained by getting hold of a "secure programming
language" is a delusion.

-- 
 \  "One thing vampire children have to be taught early on is, |
  `\   don't run with a wooden stake."  -- Jack Handey |
_o__)  |
Ben Finney

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


List conversion

2006-03-29 Thread yawgmoth7
Hello, I have a piece of code:

  command = raw_input("command> ")
   words = string.split(command, ' ')
   temparg = words
   if len(words)<= 3:
   temparg = words[4:]
   else:
   temparg = words[5:]
   funcarg = string.upper(temparg)
   str(funcarg)
   continue

There's a little snippet of code from my script, it all looks fine,
well, then I have a function that looks something like:

def nick(funcarg):
   sock.send(funcarg\r\n)
Well, that's okay, but i get this error when I try to run that command
at the commmand prompt like enviroment I wrote:

TypeError: send() argument 1 must be string or read-only buffer, not list

Well, that is why I put in the str(funcarg) line, hoping that it would
convert it to a string, instead of being a list, does anyone have any
suggestions, thanks, bye.
--
gurusnetwork.org ( Note, it's not dead..under heavy contruction).
Gurus'Network - Are you a guru?
/me goes off and codes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Try Python!

2006-03-29 Thread Serge Orlov
Michael Tobis wrote:
> We had some discussion of this in the edu-sig meeting at PyCon.
>
> I alleged that I had read that there is no such thing as a Python
> sandbox. Others claimed that one could simply preprocess and disallow
> "dangerous" constructs. My allegation was based on an argument from
> authority; I recalled reading the assertion from one of the c.l.p.
> regulars that I consider authoritative, though I don't remember which
> (Frederick, Alex, Aahz perhaps?).
>
> This is all in relation to why the rexec module went away, and is
> certainly relevant to what can be achieved in the sphere of teaching
> with python in general, and teaching python with python in particular.
>
> I refer you in particular to these messages from BDFL:
>
> http://mail.python.org/pipermail/python-dev/2002-December/031246.html
>
> http://mail.python.org/pipermail/python-dev/2002-December/031251.html
>
> So what is the scoop? Why does Guido say there is no such thing as a
> secure Python, and (as is generally reasonable) presuming he is correct
> on the matter, how can these sites work safely?

They should rely on the OS ability to restrict processes: set max
amount of physical and virtual memory used by the process, disable file
system access, disable sending of signals, set max amount of CPU time,
disable creation of new processes, etc... 

  Serge.

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


Re: Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread John Hunter
> "Enigma" == Enigma Curry <[EMAIL PROTECTED]> writes:

Enigma> pylab.xlim(0.5,6.5) should be:

Enigma> pylab.xlim(min_x-(bar_width/2),max_x+(bar_width/2))

Glad it's working better for you -- just a couple more smallish hints.

You might prefer to have your grid lines behind, rather than above the
bars.  In that case create the subplot or axes with the axisbelow=True
kwarg.  Despite the fact that you found the kwargs a little annoying
at first, you will probably come to love them.  matplotlib makes very
heavy use of them and they are very useful since they allow matplotlib
to usually do the right things while exposing most of the settings to
you.  Eg

   plot(x, y, 
linewidth=2, linestyle='--', 
marker='o', markerfacecolor='r', markeredgecolor='g'
markeredgewith=2, markersize=10)

and so on.  There are lots of properties you can set on almost every
command.  Because noone wants to type all that, you can use aliases

   plot(x, y, lw=2, ls='--', marker='o', mfc='r', mec='g', mew=2, ms=10)


Secondly, in your example, you are relying implicitly on matplotlib to
pick integer ticks for the xaxis.  It's doing it right in this
example, but might prefer other tick locations for other examples
depending on your x_values.  So set xticks explicitly.

Below is a slightly modified example showing these two ideas.

You also might want to consider joining the mailing list at 

  http://lists.sourceforge.net/mailman/listinfo/matplotlib-users

since you appear to be a little finicky about your figures :-)

def ryan_hist(data, bar_width, min_x, max_x):
"""
Create a frequency histogram over a continuous interval

min_x = the low end of the interval
max_x = the high end of the interval

bar_width = the width of the bars

This will correctly align the bars of the histogram
to the grid lines of the plot
"""
#Make histogram with bars of width .9 and center
#them on the integer values of the x-axis
bins = pylab.nx.arange(1-(bar_width/2),max(data))
pylab.subplot(111, axisbelow=True)
n,bins,patches = pylab.hist(data, bins, width=bar_width)

#Make Y axis integers up to highest n
pylab.yticks(pylab.arange(max(n)))
pylab.xticks(pylab.arange(max(n)+1))
pylab.axis('scaled')
pylab.xlim(min_x-(bar_width/2),max_x+(bar_width/2))
pylab.grid()
pylab.show()


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


Re: Try Python!

2006-03-29 Thread Armin Ronacher
BartlebyScrivener wrote:
> Armin,
>
> Mike Meyer already took a crack at this, and his starts right up just
> by clicking on the link.
>
> http://www.mired.org/home/mwm/try_python/
Hm. Looks not that useful since you can't create any functions and you
can remove the prompt :-)

> Yours looks prettier, but I don't think novices are going to be able to
> figure out how to start it.
They don't have to figure out if someone would install that on a public
host. But therefore the application has to run inside of a jail or a
XEN since python doesn't have a secure sandbox.

Regards,
Armin

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


Re: GUI in python

2006-03-29 Thread riplin
For quick, no learning curve, simple:

http://www.ferg.org/easygui/

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


Re: Seems like I want a pre-processor, but...

2006-03-29 Thread Michael Tobis
Well, Bill Mill and I simultaneously and independently decided to write
a preprocessor to strip out the unfortunate "@" decorator syntax. I
think we were both aiming at a polemic purpose rather than a practical
one, but as time fades it seems less clear what we were simultaneously
inspired to achieve. Each of us did a crude pass at it and then on
encountering each other's approach realized a truly satisfactory
implementation would probably be harder than it was worth...

In any case isn't ipython an instance of a useful preprocessor?

mt

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


Re: a hobbyist's dilemma

2006-03-29 Thread Ravi Teja
I don't have any dearth of Python needs ( I now, sort of pay my tuition
through Python :-) ). But I use it for fun as well, say gaming. For
example, I have scripts that send keystrokes based on voice commands or
other keystrokes.

Having a productive language like Python at your disposal can help
automate many of your day to day tasks.
http://www.python.org/doc/essays/cp4e.html

Besides, it's a lot easier (and fun) to write code for yourself than to
make it to distribute to others.

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


Re: Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread Enigma Curry
pylab.xlim(0.5,6.5)

should be:

pylab.xlim(min_x-(bar_width/2),max_x+(bar_width/2))

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


Re: Uninstalling Python

2006-03-29 Thread Pete
John Salerno wrote:
> Robert Kern wrote:
>
>> "Why is Python Installed on my Computer?" FAQ:
>> http://www.python.org/doc/faq/installed/
>
> Most importantly from that link:
>
> Some Windows machines also have Python installed. At this writing
> we're aware of computers from Hewlett-Packard and Compaq that include
> Python. Apparently some of HP/Compaq's administrative tools are
> written in Python.

Thanks to Everyone...I will leave it to be safe.  I  don't think I will ever 
need any of HP's tools or utilities either, but I will leave it.  Am I 
correct in assuming that "administrative tools" and "user accounts" in the 
control panel is windows driven and not HP driven (excuse my choice of words 
if not correct).  This gets into the folders in c:\docs and settings, so I'm 
not sure what the interface is between the windows operating system and 
HP...Pete 


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


Re: Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread Enigma Curry
Thank you John. Your explanation helped a lot!

In case it helps anyone else in the future, here is my code for
*exactly* what I was after:

import pylab

def ryan_hist(data, bar_width, min_x, max_x):
"""
Create a frequency histogram over a continuous interval

min_x = the low end of the interval
max_x = the high end of the interval

bar_width = the width of the bars

This will correctly align the bars of the histogram
to the grid lines of the plot
"""
#Make histogram with bars of width .9 and center
#them on the integer values of the x-axis
bins = pylab.nx.arange(1-(bar_width/2),max(data))
n,bins,patches = pylab.hist(data, bins, width=bar_width)

#Make Y axis integers up to highest n
pylab.yticks(pylab.arange(sorted(n)[-1]))
pylab.axis('scaled')
pylab.xlim(0.5,6.5)
pylab.grid()
pylab.show()

#Create a historgram
data=[1,1,2,2,2,2,2,2,3,3,3,4,4,4,5,5,6,6,6]
bar_width = 0.9
ryan_hist(data,bar_width,min(data),max(data))

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


Re: Seems like I want a pre-processor, but...

2006-03-29 Thread Russell Warren
Yes, I definitely should have done that for that case.  I'm not
entirely sure why I didn't.  If I had, though, I may not have been
prompted to ask the question and get all the other great little
tidbits!

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


Re: a hobbyist's dilemma

2006-03-29 Thread John Salerno
Jim Sizelove wrote:
> John Salerno wrote:
>> Now that I've learned much of Python, I'm sort of stuck with what to do 
>> with it. I'm not a professional programmer, so I don't really have a use 
>> for Python now. But I really want to come up with some neat uses for it 
>> (for fun, and so I don't just start forgetting it right after I learned 
>> it).
> 
> Here are some other ideas:
> 
> You can find sample code for project ideas at Useless Python 
> (http://uselesspython.com) and the Python Cookbook 
> (http://aspn.activestate.com/ASPN/Python/Cookbook/).
> 
> Hang out at the python tutor mailing list 
> (http://mail.python.org/mailman/listinfo/tutor) and learn from others 
> and learn by helping others.
> 
> Enjoy your python adventures,
> Jim Sizelove

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


Re: is 2.4.3 final?

2006-03-29 Thread John Salerno
Terry Reedy wrote:
> "John Salerno" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> I just noticed on one page of the Python website that it said:
>>
>> "We are pleased to announce the release of Python 2.4.3 (final), a
>> bugfix release of Python 2.4, on March 29, 2006."
> 
> I believe today was the target date for this.  Given that there have been 
> no mentions of problems either here or on py-dev, I would expect it to have 
> appeared.

Thanks. I'll wait a few days before installing, just to be sure.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Uninstalling Python

2006-03-29 Thread John Salerno
Robert Kern wrote:

> "Why is Python Installed on my Computer?" FAQ:
> http://www.python.org/doc/faq/installed/

Most importantly from that link:

Some Windows machines also have Python installed. At this writing we're 
aware of computers from Hewlett-Packard and Compaq that include Python. 
Apparently some of HP/Compaq's administrative tools are written in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a hobbyist's dilemma

2006-03-29 Thread Jim Sizelove
John Salerno wrote:
> Now that I've learned much of Python, I'm sort of stuck with what to do 
> with it. I'm not a professional programmer, so I don't really have a use 
> for Python now. But I really want to come up with some neat uses for it 
> (for fun, and so I don't just start forgetting it right after I learned 
> it).

Here are some other ideas:

You can find sample code for project ideas at Useless Python 
(http://uselesspython.com) and the Python Cookbook 
(http://aspn.activestate.com/ASPN/Python/Cookbook/).

Hang out at the python tutor mailing list 
(http://mail.python.org/mailman/listinfo/tutor) and learn from others 
and learn by helping others.

Enjoy your python adventures,
Jim Sizelove
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI in python

2006-03-29 Thread Peter Decker
On 29 Mar 2006 14:20:03 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:

> I am a python newbie and have used it for about a month. I want to make
> a simple GUI app in Python ( I take input form user and do processing
> and show results).
>
> Which gui package is good for me. I need to do it quick and I would not
> want a long learning curve.
>
> I was taking look at wxPython, pyGTK etc.
>
>
> Please suggest me the most simplest and easiest one as I dont need
> super cool aesthetics just a plain simple GUI app.

You might want to look at Dabo. Not only do they wrap wxPython to make
its API more Pythonic, but they now have visual design tools that make
it very simple to create a UI. http://dabodev.com

I've been using Dabo for a few months now, and can't say enough good
things about it.
--

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Uninstalling Python

2006-03-29 Thread Michael Ekstrand
Pete wrote:
> Ben Finney wrote:
>> "Pete" <[EMAIL PROTECTED]> writes:
>>
>>> I googled "python" and have no interest in it and know nothing about
>>> it.
>>>
>>> Therefore, I would like to uninstall  both the versions since I do
>>> not believe I need them.  Would it be okay to uninstall them or
>>> would you recommend that I keep them even though I will probably
>>> never use them (ie for the future just in case).
>> It should be okay to uninstall *any* software on your system if you
>> believe you don't want it.
>>
>> If you don't have a system that defaults to removing software without
>> checking if other packages depend on it, I'd hope you have stern words
>> to say to your operating system vendor and seek out more user-friendly
>> operating systems.
> 
> Thanks Ben...I told you in my very first few words who my operating system 
> vendor was (ie non other than "Bill Gates").  I said I was using xpsp2.  So 
> do all "windows" xp computer operating systems do what you said (ie, check 
> if other packages depend on something that you are uninstalling).  I would 
> certainly hope so, since MS is the world leader with "windows".  I am not a 
> pc guru like you are, so when you tell me to seek out more user friendly 
> operator systems, it is over my head.  I buy my pc's out of the box with 
> windows installed on them...Pete

AFAIK, Windows does not have such dependency information standard.

My recommendation: If it was, in fact, installed by HP's standard stuff,
leave it there. It's taking up relatively little space, most likely
isn't hurting anything, and is quite possibly used by some of the HP
utilities (they wouldn't install it if it wasn't).

- Michael

-- 
mouse, n: a device for pointing at the xterm in which you want to type.
-- Fortune
Visit me on the Web: http://www.elehack.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Try Python!

2006-03-29 Thread Terry Reedy

"Michael Tobis" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
...
> I refer you in particular to these messages from BDFL:
>
> http://mail.python.org/pipermail/python-dev/2002-December/031246.html

This one says that new style classes in 2.2 opened a new, sizable, security 
hole.  One can avoid this by running 2.1.

> http://mail.python.org/pipermail/python-dev/2002-December/031251.html

This one says that he doubts that Python will ever reach a level of no 
security flaws.  And that he does not want to spend his life just getting 
close.
>
> So what is the scoop? Why does Guido say there is no such thing as a
> secure Python, and (as is generally reasonable) presuming he is correct
> on the matter, how can these sites work safely?

There are, of course, degrees of security.  Any site can choose to operate 
with a lesser degree than Guido would accept for a 'secure Python' release.

If I were running a publicly available site, I would run Python under *nix 
with someone with some security admin experience.  I would use a dedicated 
machine from a few years ago not needed for anything else.  I would have 
the full installation backed up on a bootable CD or DVD.  I would expect 
most visitors to not pee in the fountain.  And I would expect to have to 
reinstall occasionally  when someone did.

And I would at least remove all the net access and protocol modules and 
worry about making sure that the interpreter had no access to the system 
net resources so as to not be a vehicle for damaging other machines.

Terry Jan Reedy



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


Re: Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread John Hunter
> "Enigma" == Enigma Curry <[EMAIL PROTECTED]> writes:

Enigma> I'm playing around with matplotlib for the first time. I'm
Enigma> trying to make a very simple histogram of values 1-6 and
Enigma> how many times they occur in a sequence. However, after
Enigma> about an hour of searching I cannot make the histogram
Enigma> stay within the bounds of the grid lines.

Enigma> Here is my example:

Enigma> pylab.grid() x_values=[1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6]
Enigma> pylab.hist(x_values,6) pylab.show()

Enigma> This produced the following image:
Enigma> http://enigmacurry.com/usenet/historgram-bars-not-in-grid-lines.png

Enigma> Starting with bar number 2, it creeps into grid 1.. and
Enigma> finally with bar number 5 it's almost entirely in grid
Enigma> 4.. how do I make the bars stay in their own grid lines?

While exactly what you want is something of an enigma to me, I can
offer some advice and terminology.  The bars of hist make no attempt
to stay within the bounds of the grid lines...  The bars have as their
left most boundary the bins you choose for the histogram.  As a first
step, I suggest setting these bins explicitly, rather than letting the
hist command choose them automatically

from pylab import hist, xlim, nx, show

x_values= [1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6]
bins = nx.arange(0.5, 7.)
hist(x_values, bins)
xlim(0,6.5)
show()

The grid line locations are determined by the xtick locations, which
you can set with the xticks command.

Good luck!
JDH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Uninstalling Python

2006-03-29 Thread Robert Kern
Pete wrote:
> I am using xpsp2, and I have two versions of python (2.2 and 2.2.3 - both 
> are listed as 29.3 mb, and listed as rarely used, which means never to me) 
> listed in add/remove programs in the control panel.  I assume they were put 
> in by HP out of the factory install, when I got my pc last April, since I 
> certainly did not install the first one or do an update to it.
> 
> I googled "python" and have no interest in it and know nothing about it.
> 
> Therefore, I would like to uninstall  both the versions since I do not 
> believe I need them.  Would it be okay to uninstall them or would you 
> recommend that I keep them even though I will probably never use them (ie 
> for the future just in case).  Or could something else get screwed up if I 
> uninstalled them.  Is this analogous to java (which I also do not believe I 
> have a need for).

"Why is Python Installed on my Computer?" FAQ:
http://www.python.org/doc/faq/installed/

-- 
Robert Kern
[EMAIL PROTECTED]

"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: symbolic links, aliases, cls clear

2006-03-29 Thread SM Ryan
"mp" <[EMAIL PROTECTED]> wrote:
# i have a python program which attempts to call 'cls' but fails:
# 
# sh: line 1: cls: command not found
# 
# i tried creating an alias from cls to clear in .profile, .cshrc, and
# /etc/profile, but none of these options seem to work.
# 
# my conclusion is that a python program that is executing does not use
# the shell (because it does not recognize shell aliases). is this
# correct?

Shell command alias or Mac OSX file alias, like a Finder Make Alias?

A file alias is similar to a soft link except it has both path
and device/inode like information so that it can still identify
a renamed file. However aliasses are handled at the toolbox level
instead of the kernel, so that unix only code cannot resolve them.


//  readalias - Resolve Finder alias files to the actual
//file, if it can be found. The interface is modelled
//after readlink. If the original is not alias
//or could not be resolved, return 0 and set errno.
//Otherwise return a mallocked string with the
//actual file path; caller must free.
//
//  On non-macintosh systems, this always returns an
//  error.

#ifdef ALIAS
  #include 
  #include 

  static char *readalias(char *original) {
int ec = 0;
CFStringRef path = 0;
CFStringRef resolvedPath = 0;
CFURLRef url = 0;
CFURLRef resolvedUrl = 0;
FSRef fsRef;
char *s = 0;
if (!(path=CFStringCreateWithCString(NULL,original,kCFStringEncodingUTF8))) 
{
  ec = EFAULT; goto exit;
}
if (!(url=CFURLCreateWithFileSystemPath(NULL,path,kCFURLPOSIXPathStyle,0))) 
{
  ec = EFAULT; goto exit;
}
if (!CFURLGetFSRef(url,&fsRef)) {
  ec = ENOENT; goto exit;
}
Boolean targetIsFolder,wasAliased;
if ((ec=FSResolveAliasFile(&fsRef,true,&targetIsFolder,&wasAliased))) {
  goto exit;
}
if (!wasAliased) {
  ec = EINVAL; goto exit;
}
if (!(resolvedUrl=CFURLCreateFromFSRef(NULL,&fsRef))) {
  ec = EFAULT; goto exit;
}
if (!(resolvedPath = 
CFURLCopyFileSystemPath(resolvedUrl,kCFURLPOSIXPathStyle))) {
  ec = EFAULT; goto exit;
}
s = (char*)CFStringGetCStringPtr(resolvedPath,kCFStringEncodingUTF8);
if (s) {
  s = strcpy(malloc(strlen(s)+1),s);
}else {
  int n = 3*CFStringGetLength(resolvedPath) + 1; s = malloc(n);
  if (CFStringGetCString(resolvedPath,s,n,kCFStringEncodingUTF8)) {
s = realloc(s,strlen(s)+1);
  }else {
ec = EFAULT; goto exit;
  }
}
  exit:
if (path) CFRelease(path);
if (resolvedPath) CFRelease(resolvedPath);
if (url) CFRelease(url);
if (resolvedUrl) CFRelease(resolvedUrl);
if (ec) {
  if (ec<0) ec = ENOENT;
  errno = ec; free(s); s = 0;
}
return s;
  }
#else
  static char *readalias(char *original) {
errno = EINVAL;
return 0;
  }
#endif

--
SM Ryan http://www.rawbw.com/~wyrmwif/
But I do believe in this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No Cookie: how to implement session?

2006-03-29 Thread Alex Martelli
Aahz <[EMAIL PROTECTED]> wrote:

> In article <[EMAIL PROTECTED]>,
> Alex Martelli <[EMAIL PROTECTED]> wrote:
> >
> >Cookies aren't "tricks" -- they are THE standard, architected solution
> >for session persistence in HTTP 1.1 -- people who disable them are
> >saying they do not *WANT* persistent sessions... on their heads be it.
> 
> OTOH, there are too many sites out there that mandate persistent sessions
> for no good reason.  NetFlix being a canonical example (before logging
> in, that is).  Sites should degrade gracefully in the absence of cookies
> unless they are absolutely essential for site operation.

I entirely agree with you -- do you mean netflix just won't work if I
try to visit it, not log in, with cookies disabled in my browser?!


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


Re: gtk.spinbutton and set_value

2006-03-29 Thread John Bushnell
Sandro Dentella wrote:
> Hi all,
>
>   why my spinbutton doesn't show '120'?
>   why, if I write in a number, it is reset to 0 wen Enter is pressed?
>
>   TYA
>   sandro
>
>
>import gtk
>
>w = gtk.Window()
>spin = gtk.SpinButton()
>w.add(spin)
>w.show_all()
>spin.set_value(120)
>gtk.main()
>

You should probably try pygtk questions out on the PyGTK mailing list:

http://www.daa.com.au/mailman/listinfo/pygtk

 Good luck!  -  John

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


Re: is 2.4.3 final?

2006-03-29 Thread Terry Reedy

"John Salerno" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I just noticed on one page of the Python website that it said:
>
> "We are pleased to announce the release of Python 2.4.3 (final), a
> bugfix release of Python 2.4, on March 29, 2006."

I believe today was the target date for this.  Given that there have been 
no mentions of problems either here or on py-dev, I would expect it to have 
appeared.

> Yet elsewhere it refers to it as a "release candidate" and still refers
> to 2.4.2 as the "current production version".

You seem to have caught the site in an inconsistent state.  Perhaps you 
could revisit in a day and if problems continue, email the web maintainers 
(link on sidebar) with the cut and pasted urls of offending pages.

Terry Jan Reedy



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


[ANN] Dabo Runtime Engine For Windows 0.6.2 released

2006-03-29 Thread Ed Leafe
The Dabo Runtime Engine for Windows is a self-contained environment  
that allows you to run Dabo on Windows without having to first  
install all of the requirements. It comes with its own version of  
Python 2.4.2, wxPython 2.6.3.0, MySQLdb 1.2.0, kinterbasdb 3.2.0a1,  
ReportLab v.2463, and several other modules used in Dabo.

The Dabo Runtime Engine is designed for people who are curious about  
Dabo, but who don't want the bother of installing all the required  
modules just to see what Dabo can do. It doesn't change any Windows  
Registry settings, so it will not affect any existing applications on  
your machine.

This version installs several shortcuts that allow you to simple  
double-click an icon to run the desired file. Such shortcuts include  
the AppWizard, ClassDesigner and ReportDesigner, as well as several  
of the demo applications.

The Dabo Runtime Engine comes in two versions: the regular version  
that just runs the applications, and the Console version that display  
a command line window containing the application output. Besides  
that, they are identical.

You can download either version, along with all other things Dabo,  
from:

http://dabodev.com/download


-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com





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


Re: Uninstalling Python

2006-03-29 Thread Pete
Ben Finney wrote:
> "Pete" <[EMAIL PROTECTED]> writes:
>
>> I googled "python" and have no interest in it and know nothing about
>> it.
>>
>> Therefore, I would like to uninstall  both the versions since I do
>> not believe I need them.  Would it be okay to uninstall them or
>> would you recommend that I keep them even though I will probably
>> never use them (ie for the future just in case).
>
> It should be okay to uninstall *any* software on your system if you
> believe you don't want it.
>
> If you don't have a system that defaults to removing software without
> checking if other packages depend on it, I'd hope you have stern words
> to say to your operating system vendor and seek out more user-friendly
> operating systems.

Thanks Ben...I told you in my very first few words who my operating system 
vendor was (ie non other than "Bill Gates").  I said I was using xpsp2.  So 
do all "windows" xp computer operating systems do what you said (ie, check 
if other packages depend on something that you are uninstalling).  I would 
certainly hope so, since MS is the world leader with "windows".  I am not a 
pc guru like you are, so when you tell me to seek out more user friendly 
operator systems, it is over my head.  I buy my pc's out of the box with 
windows installed on them...Pete


>
> On the other hand, if packaged programs depend on other packages but
> don't use the operating system package manager to declare this, those
> programs are poorly packaged.
>
> In short: it's your computer. We hope you'll one day be interested
> enough in Python to want to use it some more. For now, if you want to
> uninstall it, you should feel free, and demand an explanation from
> anything that breaks as a result. 


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


Re: Uninstalling Python

2006-03-29 Thread Ben Finney
"Pete" <[EMAIL PROTECTED]> writes:

> I googled "python" and have no interest in it and know nothing about it.
>
> Therefore, I would like to uninstall  both the versions since I do not 
> believe I need them.  Would it be okay to uninstall them or would you 
> recommend that I keep them even though I will probably never use them (ie 
> for the future just in case).

It should be okay to uninstall *any* software on your system if you
believe you don't want it.

If you don't have a system that defaults to removing software without
checking if other packages depend on it, I'd hope you have stern words
to say to your operating system vendor and seek out more user-friendly
operating systems.

On the other hand, if packaged programs depend on other packages but
don't use the operating system package manager to declare this, those
programs are poorly packaged.

In short: it's your computer. We hope you'll one day be interested
enough in Python to want to use it some more. For now, if you want to
uninstall it, you should feel free, and demand an explanation from
anything that breaks as a result.

-- 
 \"I have one rule to live by: Don't make it worse."  -- Hazel |
  `\  Woodcock |
_o__)  |
Ben Finney

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


Re: Content Management System

2006-03-29 Thread Adam
On Wed, 29 Mar 2006 16:32:39 GMT, Adrienne Boswell wrote:

>Gazing into my crystal ball I observed "Water Cooler v2" 
><[EMAIL PROTECTED]> writing in news:1143627824.174540.13710
>@z34g2000cwc.googlegroups.com:
>
>> I know what it is, and yet the knowledge of what a CMS is, is so vague
>> that I find myself asking this question every now and then. I've
>> googled and read the resources too. However, the knowledge is still not
>> clear. It is so vague.
>> 
>> 
>
>For me, it was a way to give my client (local parish) some things:
>1. An easy way for them to make _content_ changes to their website, 
>without getting into the nuts and bolts and potentially creating havoc.
>2. A way to make the site searchable for the user.
>3. A way from keeping them from publishing Word documents as HTML - urgh!
>4. A way to have content changes immediate, and not have to wait for 24 
>hours before their current hosting company downloads content (in Word, 
>with no navigation).
>
>I rolled my own in ASP/Access, not very complicated because I didn't need 
>anything complicated.

Try taking a look at Joomla:

http://www.joomla.org/

I generally hand code PHP sites, but occasionally use a CMS. Of all
the ones I tested, Joomla seemed (to me) to be the most flexible.

If you install the JCE (WYSIWYG) editor, it actually has a "paste from
Word" function that tries to strip out as much MX cr*p as it can - but
it's a tall order!

I've [even] used Joomla for pretty simple non-"blog" sites simply for
the remote admin and the search functions. It really is best suited
for the more "newsy" community sites. It's definitely worth a look at,
IMHO.

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


Uninstalling Python

2006-03-29 Thread Pete
I am using xpsp2, and I have two versions of python (2.2 and 2.2.3 - both 
are listed as 29.3 mb, and listed as rarely used, which means never to me) 
listed in add/remove programs in the control panel.  I assume they were put 
in by HP out of the factory install, when I got my pc last April, since I 
certainly did not install the first one or do an update to it.

I googled "python" and have no interest in it and know nothing about it.

Therefore, I would like to uninstall  both the versions since I do not 
believe I need them.  Would it be okay to uninstall them or would you 
recommend that I keep them even though I will probably never use them (ie 
for the future just in case).  Or could something else get screwed up if I 
uninstalled them.  Is this analogous to java (which I also do not believe I 
have a need for).

Thanks...Pete 


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


Updated: python ctype question about "access violation reading location 0x5a5a5a5a"

2006-03-29 Thread Yanping Zhang
Here are more details about my codes, please help!

The function declared in C:
typedef void (WINAPI *PLEARNCALLBACKPROC) (unsigned int progress, unsigned int 
sigQuality,
unsigned long carrierFreq, void *userData);

UUIRTDRV_API BOOL PASCAL UUIRTLearnIR(HUUHANDLE hHandle, int codeFormat, char 
*IRCode,
PLEARNCALLBACKPROC progressProc, void *userData, BOOL *pAbort, unsigned int 
param1, void
*reserved0, void *reserved1);

My python codes:

import ctypes

port = windll.uuirtdrv

myhandle = c_void_p()
  
myhandle = port.UUIRTOpen()


#+++ Call back function 
LEARNCALLBACKFUNC = CFUNCTYPE(c_void_p, c_uint, c_uint, c_ulong, c_void_p)

def py_learncallback_func(progress,sigQuality, carrierFreq, userdata):

print "progress is: %d %d %d %d" % (progress, sigQuality & 0xff, 
carrierFreq, userdata)
if progress == 100:
   mybool = c_int(1)
   
return 

callback_func = LEARNCALLBACKFUNC(py_learncallback_func)

#++

glearnBuffer = create_string_buffer('\000'*2048)

mybool = c_int(0)
param1 = c_int(0)
reserved0 = c_void_p(0)
reserved1 = c_void_p(0)

mydata = create_string_buffer("0x5a5a5a5a")
#userdata = c_long(0x5a5a5a5a)  #failed
#userdata = byref(mydata)   #failed
#userdata = pointer(mydata) #failed 
userdata = c_void_p(0x5a5a5a5a) #failed

 
learnformat = c_int(0x)

port.UUIRTLearnIR(myhandle, learnformat, glearnBuffer, callback_func, userdata,
mybool,param1,reserved0, reserved1)


I tried to define userdata in different ways and all failed with "access 
violation
reading(writing) location...". The c routine just passes userdata to call back 
function and didn't
use it anywhere else.

Thanks!



> Hi All,
> 
> I need to use this C routine in python and there is a void pointer parameter 
> in it: 
> (this routine was written by someone else):
> 
> myfunc(int a, (void *)userdata, int b)
> 
> I saw someone in his C++ wrapper used this routine in this way:
> myfunc(a, (void *)0x5a5a5a5a, b)
> 
> In my python wrapper, I tried  to call it as the following and both failed:
> 1. myfunc(c_int(a), 0x5a5a5a5a, c_int(b))
>got error "access voilation reading from 0x5a5a5a5a"
> 2. 
>   data = 0x5a5a5a5a
>   mydata = c_void_p(data)
>   myfunc(c_int(a), mydata, c_int(b))
>   same error as in 1
> 
> Can anyone know how to fix it? Thanks!
> 
> 
> 
> __
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any() and all() on empty list?

2006-03-29 Thread Ron Adam
Carl Banks wrote:
> Steve R. Hastings wrote:
>> I'm completely on board with the semantics for any().  But all() bothers
>> me.  If all() receives an empty list, it will return True, and I don't
>> like that.  To me, all() should be a more restrictive function than any(),
>> and it bothers me to see a case where any() returns False but all()
>> returns True.
> 
> Perhaps a practical example will illustrate why all() returns False
> better than all this mathematical mumbo-jumbo.
> 
> Ok, say you're writing a simple software management/bug tracking
> system.  It manage another software package that is to have periodic
> releases, but the release can only be made when there are no
> outstanding bugs.  You might have a line of code that looks like this:
> 
> if all(bug.status == 'closed' for bug in bugs_filed):
> do_release()
> 
> As you can see, the release will only happen if all the bugs are marked
> closed.  But... what if no bugs have been filed?  If all() were to
> return False on an empty sequence, the software couldn't be fixed until
> at least one bug had been filed and closed!
> 
> The point is, whenever you have to test that every item in a list is
> true, it is almost always correct for the test to pass when the list is
> empty.  The behavior of all() is correct.
> 
> 
> Carl Banks


Yes, But that should be a test for 'not any()'.

if not any(bug.status == 'open' for bug in bugs_filed):
do_release()


So to give a counter example...

Where we are assembling widgets in a manufacturing plant. Where we don't 
want to go to the next step until *all* the sub parts are present.

if all(part.status == 'present' for part in unit):
 do_release()

Oops!  Some empty bins showed up at the next assembly station. ;-)


Cheers,
Ron

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


Re: Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread Enigma Curry
Two things:

1) I now see where width is defined in the hist() documentation... I
was expecting it to be in the definition up at the top, but instead the
definition has **kwords.. not very helpful.

2) I noticed in my original historgram, that the y scale was not the
same as the x scale.. so I updated my code:

import pylab

pylab.grid()
x_values=[1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6]
pylab.hist(x_values,6)
pylab.yticks(pylab.arange(3))
pylab.axis('scaled')
pylab.show()


It produced this image:
http://enigmacurry.com/usenet/historgram-bars-not-in-grid-lines2.png

It has the same problem..

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


Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread Enigma Curry
I'm playing around with matplotlib for the first time. I'm trying to
make a very simple histogram of values 1-6 and how many times they
occur in a sequence. However, after about an hour of searching I cannot
make the histogram stay within the bounds of the grid lines.

Here is my example:

pylab.grid()
x_values=[1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6]
pylab.hist(x_values,6)
pylab.show()

This produced the following image:
http://enigmacurry.com/usenet/historgram-bars-not-in-grid-lines.png

Starting with bar number 2, it creeps into grid 1.. and finally with
bar number 5 it's almost entirely in grid 4.. how do I make the bars
stay in their own grid lines?

I can see that hist() is somehow derived from bar() ... so it appears
that hist() has some undocumented parameters. I tried specifiying
width=1 but that just squished all of the bars together.

Also, is there a more object-oriented graphing package for Python? (How
am I supposed to know that hist() is derived from bar() if the docs
don't show proper inheritance?)

Thanks!

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


Re: any() and all() on empty list?

2006-03-29 Thread Ron Adam
Paul Rubin wrote:
> Ron Adam <[EMAIL PROTECTED]> writes:
>> Just thinking about things.  I really just want what is best for
>> Python in the long term and am not trying to be difficult.
> 
> I'm sorry, maybe it's the math geek in me, but I just see all those
> suggestions about "not not S" as being contorted.  It's obvious to me
> that all([]) should be True, that while(any(S)) should not terminate
> if S is empty, etc.

The 'not not S' is just a conversion to bool. Is the following less 
contorted to you?

 >>> bool([])
False

> Someone asked for a cite; I listed one before:
> 
> http://en.wikipedia.org/wiki/For_all
> 
> See the "Negation" section.


'Is all True' isn't the same as 'Has all True'.  As I said, I'm not 
questioning the mathematical meaning of the set relation 'is all True', 
but wondering weather or not an alternate relation 'has all True' would 
be better for use as a flow control test.


Do you have some examples uses since it's obvious to you?

We could all probably come up with examples that support either side. 
What I'm looking for are the obvious and common use examples.  How would 
they behave differently depending on weather 'is all true' or 'has all 
true' is used?  Which would be faster and simpler to use in most cases.

I just have a feeling we will see a lot of "S and all(S)" expressions 
being used.  Maybe that's not so bad,  but I would prefer to not have to 
do that if it turns out to the standard idiom for all testing within a loop.


The actual code used would be more efficient than my examples, they will 
have shortcutting behavior, and written in C.  Those examples where 
meant to show the principle.

And the question still stands:

"Does it do the right thing in most situations it will be used in?"


That will of course depend on weather it's being used as a mathematics 
test, or for flow control test.  Which is why I suggested the possibly 
of having both. I believe the flow control semantics will be the more 
common use, but I may be mistaken thinking "S and all(S)" will be needed 
in most cases.

This doesn't seem to be an issue for anyone else, so I'll wait 
and see how it turns out.

Cheers,
Ron

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


Re: ldap usage

2006-03-29 Thread Jed Parsons

Hi, Michael,

Thanks very much for your response.  I think I can work it out now.

 >> authenticated = False
 >   ^^^
 > Identiation is wrong here.

Yes, sorry about that - doesn't always work on this email client :(

As an addendum, I discovered one little gotcha, namely that this:

l.bind_s(username, password, ldap.AUTH_SIMPLE)

throws an ldap.INVALID_CREDENTIALS error if the password contains the 
wrong text, but works if the password is empty.  I guess this is 
tantamount to binding as ("", ""), but I wasn't expecting it; I figured 
if a username was specified, the password would have to agree.  So my 
little authentication example also needs to test for empty passwords.

Neither here nor there, really; just thought I'd mention it since I ran 
into it.

Now I'm off to check out the Demo/*.py scripts you pointed me to.

Thanks again.  Cheers!
j

Michael Ströder wrote:
> Jed Parsons wrote:
>> import ldap
>> l = ldap.open('our.ldap.server')
>> try:
>> l.bind_s(username, password, ldap.AUTH_SIMPLE)
>> authenticated = True
>> except:
>> authenticated = False
>   ^^^
> Identiation is wrong here.
> 
> Also I'd recommend to catch the ldap.LDAPError exceptions more
> specifically (ldap.INVALID_CREDENTIALS indicates wrong password):
> 
>  try:
>  l.bind_s(username, password, ldap.AUTH_SIMPLE)
>  except ldap.INVALID_CREDENTIALS:
>  authenticated = False
>  else:
>  authenticated = True
> 
>> But this uses the plaintext of the user's password.
> 
> Yes, since this is a LDAP Simple Bind Request as defined in RFC 2251.
> 
>>  Is there a proper
>> way to send a cryptographic hash to the ldap server?  Or do I have to
>> negotiate this through an ssl tunnel or something?
> 
> SSL (either LDAPS or StartTLS extended operation) is one possibility to
> secure the whole connection including bind requests (see
> Demo/initialize.py).
> 
> Another option is to use SASL with DIGEST-MD5 if your server supports it
> (see Demo/sasl_bind.py) and has the cleartext passwords available. Other
> options with SASL, e.g. GSSAPI (Kerberos), exist but highly depends on
> your IT infrastructure and LDAP server configuration.
> 
> Just follow-up here or on the python-ldap-dev mailing list if you have
> further problems.
> 
> Ciao, Michael.

-- 
Jed Parsons   Industrial Light + Magic  (415) 746-2974

grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6}},(split(//,
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0.  What!?")));

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


Re: bandwidth shaping on urllib2

2006-03-29 Thread Larry Bates
outune wrote:
> Hello,
> I'm using urllib2 with threading and semaphore,
> it works fine, but can I set a bandwidth limit in that process?
> 
Use cstream:

http://www.cons.org/cracauer/cstream.html

or Wonder Shaper:

http://lartc.org/wondershaper/

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


Re: Try Python!

2006-03-29 Thread Paul Rubin
"Michael Tobis" <[EMAIL PROTECTED]> writes:
> So what is the scoop? Why does Guido say there is no such thing as a
> secure Python, and (as is generally reasonable) presuming he is correct
> on the matter, how can these sites work safely? 

One way is to run the Python interpreter itself in a sandbox, e.g.  a
virtual computer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Try Python!

2006-03-29 Thread Michael Tobis
We had some discussion of this in the edu-sig meeting at PyCon.

I alleged that I had read that there is no such thing as a Python
sandbox. Others claimed that one could simply preprocess and disallow
"dangerous" constructs. My allegation was based on an argument from
authority; I recalled reading the assertion from one of the c.l.p.
regulars that I consider authoritative, though I don't remember which
(Frederick, Alex, Aahz perhaps?).

This is all in relation to why the rexec module went away, and is
certainly relevant to what can be achieved in the sphere of teaching
with python in general, and teaching python with python in particular.

I refer you in particular to these messages from BDFL:

http://mail.python.org/pipermail/python-dev/2002-December/031246.html

http://mail.python.org/pipermail/python-dev/2002-December/031251.html

So what is the scoop? Why does Guido say there is no such thing as a
secure Python, and (as is generally reasonable) presuming he is correct
on the matter, how can these sites work safely? 

thanks
mt

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


Re: Apache and Python and Ubuntu

2006-03-29 Thread msuemnig
Thanx a lot for your input and advice.  I went through the
documentation on httpd.apache.org/docs/2.2/howto/cgi.html and added the
following:
AddModule cgi-script .cgi .py

 Options +ExecCGI


It now gives me a 403 forbidden.  When I check the error logs, it still
says that Options ExecCGI is not turned on in /var/www/

Is there a special place inside of apache2.conf I'm supposed to have
the  tag? and/or AddModule line?

I also double checked to make sure owner/group/other all have execute
and it does.

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


Re: excel application

2006-03-29 Thread Petr Jakes
Luca,
you can find a lot of answers to your questions on this discussion
group. If you will try to search using key words "excel constants" for
example, you will get the link to the following link (among others):
http://tinyurl.com/go3qf

IMHO it is good idea to search the web and discussion groups before
posting questions (I am not saying it is a bad idea to ask here, I am
only trying to show an simple alternative how to get an answers to your
questions to you)

HTH
Regards
Petr Jakes

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


Re: Content Management System

2006-03-29 Thread Jeff
Water Cooler v2 wrote:
> I know what it is, and yet the knowledge of what a CMS is, is so vague
> that I find myself asking this question every now and then. I've
> googled and read the resources too. However, the knowledge is still not
> clear. It is so vague.
> 
> 
> Me: Just what is a content management system?


There's many different CMS sytems out there. How they work vary widely. 
But basically it's about making the site maintainable. Creating pages ad 
hoc on your desktop can lead to variations in a website depending on 
when and who made that page. That can cause problems as a site expands.

Let's talk about web based.

Common and necesary features are:

1) A Page Manager that shows you the site structure and lets you add 
edit or move pages about the site. Since this is stored in an online 
database, everyone who needs to edit the site will have the same data. 
That's an advantage over having this on your desktop where syncing the 
data is necesary.

2) A page editor. The idea here is to seperate the content from the 
presentation. Typically the content will be plugged into a template(s) 
that conforms to your site so that all pages will have the same look and 
feel. If you need to make a change sitewide, changing the template(s) 
will do that,other than making changes one page at a time.

What you want is to seperate content from presentation. You want your 
pages to be reasonable HTML instead of what an inexperienced (or even 
experienced) might create on their own.

3) Navigation. CMS should be able to update your navigation as you add 
pages, or move them.

4) Controlling access to editing and making navigation changes. This can 
be by directory, subdirectory or even page. I usually see the first two, 
sometimes an editor will need to to have access to different sections of 
the site, but not to the whole site. Sometimes this will need to be 
reviewed by an administrator. Every site tends to have differing needs.

5)Ability to upload PDF's, word docs, etc... and link them into your 
site. Usually you will want to do this online, rather than having to FTP 
content up, typically you don't want CMS users to even have to know 
about FTP.


   So you want your CMS to be easy for the html illiterate to use, you 
want to be able to make sitewide changes easily, you want your 
navigation to automatically update and you want to be able to control 
access and if necesaary review changes.
> 
> Myself: A place where content can be stored.

Online in a structured place, this usually involves a database in some 
way. How that all works should be something you don't need to know or 
worry about.
> 
> Me: OK. So, then what's a file system?
> 
> Myself: That's not web-based. File-Systems are desktop-based.

   Everything is file based, even database tables.

HTH,

   Cheers,
Jeff
> 
> Me: You can have a file-system on a common network server. I can even
> have a network server and give remote access to people over a VPN. I
> can host content on a terminal server, I can give them VNC clients, or
> an RDP client, and let them browse what they want to.
> 
> Myself: How will they know "where" to find what?
> 
> Me: Come again?
> 
> Myself: With all those avenues you mentioned, you won't publish
> content. There will not be a taxonomy. You will just be dumping files
> on another remote server. How will the users "find" what they want?
> 
> 
> 
> So, is a CMS all about:
> 
> 1. Taxonomy
> 2. Publishing content in a Web based format
> 
> Me: What about binary objects that cannot be published in HTML?
> 
> Myself: Yeah! What about them, dude? Use your head. What about them?
> Heard of a hyperlink? Heard of HTTP? FTP? No?
> 
> Me: OK. I get it. But...I *still* don't get it, man. Why did we need
> this? More importantly, where are the boundaries? I believe CMS also
> lets users edit and publish content on-the-fly.
> 
> 
> So, again, where are the boundaries? What about non-public content?
> What about access rights? Do you have seperate users on CMS's having
> their seperate folders as well, where they could put their own private
> content? Or, is the idea behind CMS about "sharing" and so they put
> only that which they need to share and not the private stuff.
> 
> Do CMS's also allow access rights or authorization levels *per*
> resource/file/unit of content that is uploaded on to them? Or, are they
> role-based - e.g all users of this group will be able to access all
> files, and users of that group will have read-only access to this
> website.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-03-29 Thread Chris F.A. Johnson
On 2006-03-29, mp wrote:
> i have a python program which attempts to call 'cls' but fails:
>
> sh: line 1: cls: command not found
>
> i tried creating an alias from cls to clear in .profile, .cshrc, and
> /etc/profile, but none of these options seem to work.

   Why not call 'clear', since 'cls' does not exist?

> my conclusion is that a python program that is executing does not use
> the shell (because it does not recognize shell aliases). is this
> correct?

   Even shell scripts do not normally expand aliases.

> should i use a symbolic link? if so, where should i place it?
>
> what is the difference between aliases and symbolic links?

   What's the difference between a raven and a writing desk?

> if i execute a command like 'clear' to clear the screen, where does the
> shell look to find the command 'clear'?

   In a directory listed in the PATH variable.

-- 
   Chris F.A. Johnson, author   |
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LDTP 0.4.0 released !!!

2006-03-29 Thread Ben Finney
"A Nagappan" <[EMAIL PROTECTED]> writes:

> Welcome to the seventh issue of LDTP Newsletter!

Nowhere in this newsletter do I see anything germane to a forum about
Python. Why post it here, rather than somewhere more related to Linux
or Desktops or Testing?

And no, "because many Python programmers may be interested" is not
good enough.

-- 
 \ "If you ever catch on fire, try to avoid seeing yourself in the |
  `\mirror, because I bet that's what REALLY throws you into a |
_o__)  panic."  -- Jack Handey |
Ben Finney

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


Re: Seems like I want a pre-processor, but...

2006-03-29 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Russell Warren <[EMAIL PROTECTED]> wrote:
.
.
.
>Anyway - it worked... you've answered my question perfectly, thanks.  I
>hadn't considered that the module loading phase could basically used
>for preprocessing.  You even helped by subtly providing a better
>version checker... I didn't even know you could use < with a tuple like
>that.  I'll have to look into the logic rules there.
.
.
.
I'm working on an article on this topic, as it happens.
Yes, in general pre-processors are strictly inferior for
all realistic use-cases.  Any time you think you need a
pre-processor in Python, you should ask for help to learn
of the better way that Python affords.

Even while writing this, I realize that some people have
implemented pre-processors for their Python, and expressed
satisfaction with the result.  The cases familiar to me
had to do syntactic style--folks who don't like significant
white space, and so on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: operation complexities of lists and dictionaries

2006-03-29 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> what are the time complexities of inserting / removing / checking if an
> element is present in 1) a list and 2) a dictionary?
> does anybody know?

I assume in the list case, the element you want to operate on is in
the middle of the list.  In CPython, those are linear time operations.
If you just want to append to the end or remove from the end, those
are approximately constant time.  For dicts, all those operations are
approximately constant time in CPython.  Approximately means
occasionally something happens that makes it slower, but it's constant
time on average.

The Python docs don't specify this anywhere but it's so fundamental to
how people expect Python to work that it's not likely to be much worse
in any other implementation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-03-29 Thread Keith Thompson
"mp" <[EMAIL PROTECTED]> writes:
> i have a python program which attempts to call 'cls' but fails:
>
> sh: line 1: cls: command not found
>
> i tried creating an alias from cls to clear in .profile, .cshrc, and
> /etc/profile, but none of these options seem to work.
>
> my conclusion is that a python program that is executing does not use
> the shell (because it does not recognize shell aliases). is this
> correct?

Yes.

> should i use a symbolic link? if so, where should i place it?

You could, but I don't think it's the best solution.

> what is the difference between aliases and symbolic links?

Aliases exist only in a shell.  Symbolic links exist in the file
system.

> if i execute a command like 'clear' to clear the screen, where does the
> shell look to find the command 'clear'?

Generally it searches $PATH for an executable file called "clear".

I don't know Python very well (note the cross-post), but if it
provides a way to detect which operating system you're running on, you
could execute "cls" if you're on Windows, or "clear" if you're on a
Unix-like system.  Or there might be some Python library with a
clear-screen function.

Are you sure you want to clear the screen?  If I run your program and
it clears my screen for me, it could be erasing significant
information.  If you want complete control over the screen, you should
probably use something like curses or ncurses (there may be a Python
interface to it).

-- 
Keith Thompson (The_Other_Keith) [EMAIL PROTECTED]  
San Diego Supercomputer Center <*>  
We must do something.  This is something.  Therefore, we must do this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to capture os.execvp into variable

2006-03-29 Thread Ben C
On 2006-03-28, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> hi
> i am using this code to run a ps command in unix
>
> def run(program, *args):
> pid = os.fork()
> if not pid:
> os.execvp(program, (program,) +  args)
> return os.wait()[0]
>
> run("ps", "-eo pid,ppid,args")
>
> It runs fine, but i wish to store the results into a variablehow
> can i do this ? I tried
> to put ret=os.execvp(program, (program,) +  args) but ret has no value
> thanks

Do you mean you want the output of ps? That seems most likely. In that
case use os.popen.

p = os.popen("ps -eo pid,ppid,args")
output = p.read()
p.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: operation complexities of lists and dictionaries

2006-03-29 Thread Ben Finney
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> what are the time complexities of inserting / removing / checking if an
> element is present in 1) a list and 2) a dictionary?

Partly dependent on the implementation, of which there are several for
Python (CPython, Jython, PyPy, and others). Which one are you most
interested in?

> does anybody know?

The 'timeit' module can help you discover the answers for yourself, on
your current implementation.

-- 
 \   "You could augment an earwig to the point where it understood |
  `\ nuclear physics, but it would still be a very stupid thing to |
_o__)   do!"  -- The Doctor, _The Two Doctors_ |
Ben Finney

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


Re: Apache and Python and Ubuntu

2006-03-29 Thread Jorge Godoy
[EMAIL PROTECTED] writes:

> The problem is the programs just dump the contents to the browser in
> plain text.  Or, in the case of the .py files, I am prompted to
> download the .py file.  How can I get apache to recognize that it
> should execute the .cgi script?
>
> Is there any special thing I need to do to apache to get it to know
> that the python interpreter should be used for all .cgi files?

You should configure your Apache: 

- http://httpd.apache.org/docs/2.2/
  - http://httpd.apache.org/docs/2.2/howto/cgi.html


-- 
Jorge Godoy  <[EMAIL PROTECTED]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list


bandwidth shaping on urllib2

2006-03-29 Thread outune
Hello,
I'm using urllib2 with threading and semaphore,
it works fine, but can I set a bandwidth limit in that process?

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


Re: Apache and Python and Ubuntu

2006-03-29 Thread grahamd

[EMAIL PROTECTED] wrote:
> I've create an Ubuntu Linux box, which comes pre-installed with Python
> (I've added the libapache2-mod-python throught the app manager).  I've
> created  .cgi and .py simple programs in the www root of apache.
>
> The problem is the programs just dump the contents to the browser in
> plain text.  Or, in the case of the .py files, I am prompted to
> download the .py file.  How can I get apache to recognize that it
> should execute the .cgi script?
>
> Is there any special thing I need to do to apache to get it to know
> that the python interpreter should be used for all .cgi files?

You do not need mod_python if you want to use Python in traditional
CGI scripts. Simply follow the Apache instructions for setting up
CGI scripts and ignore mod_python all together.

If you really did want to use mod_python, consider reading:

  http://www.dscpl.com.au/articles/modpython-001.html

It provides more detailed instructions on getting a first test handler
running.

Graham

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


symbolic links, aliases, cls clear

2006-03-29 Thread mp
i have a python program which attempts to call 'cls' but fails:

sh: line 1: cls: command not found

i tried creating an alias from cls to clear in .profile, .cshrc, and
/etc/profile, but none of these options seem to work.

my conclusion is that a python program that is executing does not use
the shell (because it does not recognize shell aliases). is this
correct?

should i use a symbolic link? if so, where should i place it?

what is the difference between aliases and symbolic links?

if i execute a command like 'clear' to clear the screen, where does the
shell look to find the command 'clear'?

i'm using os x.

thanks
mp

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


Apache and Python and Ubuntu

2006-03-29 Thread msuemnig
I've create an Ubuntu Linux box, which comes pre-installed with Python
(I've added the libapache2-mod-python throught the app manager).  I've
created  .cgi and .py simple programs in the www root of apache.

The problem is the programs just dump the contents to the browser in
plain text.  Or, in the case of the .py files, I am prompted to
download the .py file.  How can I get apache to recognize that it
should execute the .cgi script?

Is there any special thing I need to do to apache to get it to know
that the python interpreter should be used for all .cgi files?

Thanx all for your help in advance!
pen

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


Re: GUI in python

2006-03-29 Thread I. Myself
[EMAIL PROTECTED] wrote:
> Hi,
>
> I am a python newbie and have used it for about a month. I want to make
> a simple GUI app in Python ( I take input form user and do processing
> and show results).
>
> Which gui package is good for me. I need to do it quick and I would not
> want a long learning curve.
>
> I was taking look at wxPython, pyGTK etc.
>
>
> Please suggest me the most simplest and easiest one as I dont need
> super cool aesthetics just a plain simple GUI app.
>
> Thanks
>
>   
I've had very good results with Tkinter, which is the standard Python 
GUI system.  On windows, it comes with the standard download.  With 
linux you have to download it separately.

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  I'm currently working on a
major update of the SailChallenge package.  If you want to write software,
or articles, or do testing for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


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


Re: operation complexities of lists and dictionaries

2006-03-29 Thread Steven D'Aprano
On Wed, 29 Mar 2006 09:38:05 -0800, [EMAIL PROTECTED] wrote:

> 
> hi,
> i've just a simple question:
> what are the time complexities of inserting / removing / checking if an
> element is present in 1) a list and 2) a dictionary?
> does anybody know?
> thanks

No no no, that's not the way to ask the question, you're hardly likely to
get answers that way.

What you do is, you write in and say "I need a more efficient way of
adding data to a list, because adding data to a list is O(n**2) and that's
too slow. Also, how do I implement hash tables in Python, because I need
O(1) searching?"

That way you'll have dozens, maybe hundreds of replies from people
explaining that adding data to Python lists is O(log n) amortized, and
that dictionaries are hash tables.

*wink*

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


GUI in python

2006-03-29 Thread diffuser78
Hi,

I am a python newbie and have used it for about a month. I want to make
a simple GUI app in Python ( I take input form user and do processing
and show results).

Which gui package is good for me. I need to do it quick and I would not
want a long learning curve.

I was taking look at wxPython, pyGTK etc.


Please suggest me the most simplest and easiest one as I dont need
super cool aesthetics just a plain simple GUI app.

Thanks

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


Re: python challenge question (string manipulation)

2006-03-29 Thread Terry Reedy

"John Salerno" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> John Salerno wrote:
>
>> It works, but is there a better way to shift the letters of the alphabet
>> for 'code'? I remember a method that did this for lists, I think, but I
>> can't remember what it was or if it worked for strings.
>
> Ah ha! This is cleaner:
>
> alphabet = string.ascii_lowercase
> code = string.ascii_lowercase[2:] + string.ascii_lowercase[:2]
>
> Yet it still seems kind of verbose. But since that's the official
> solution, I guess there's no other way to shift the characters in a 
> string?

The above would look less verbose if the second line 'paid attention' to 
the first and were written as the slightly more efficient

code = alphabet[2:] + alphabet[:2]

An alternative is shifted access.  alphabet[(i+24)%26]

Terry Jan Reedy




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


RELEASED Python 2.4.3, final.

2006-03-29 Thread Anthony Baxter

On behalf of the Python development team and the Python community,
I'm happy to announce the release of Python 2.4.3 (final).

Python 2.4.3 is a bug-fix release. See the release notes at the
website (also available as Misc/NEWS in the source distribution)
for details of the more than 50 bugs squished in this release,
including a number found by the Coverity Scan project.

Assuming no major bugs pop up, the next release of Python will
be Python 2.5 (alpha 1), with a final 2.4.4 release of Python 
shortly after the final version of Python 2.5. The release plan
for Python 2.5 is documented in PEP-0356.

For more information on Python 2.4.3, including download links for
various platforms, release notes, and known issues, please see:

http://www.python.org/2.4.3/

Highlights of this new release include:

  - Bug fixes. According to the release notes, at least 50
have been fixed.

  - A small number of bugs, regressions and reference leaks 
have been fixed since Python 2.4.3 release candidate 1. 
See NEWS.txt for more.

Highlights of the previous major Python release (2.4) are
available from the Python 2.4 page, at 

http://www.python.org/2.4/highlights.html

Enjoy this new release,
Anthony

Anthony Baxter
[EMAIL PROTECTED]
Python Release Manager
(on behalf of the entire python-dev team)


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

Re: a hobbyist's dilemma

2006-03-29 Thread Terry Reedy

"John Salerno" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> Try creating simple games using PyGame. Think of simple things like
>> minesweeper.
>>
>
> Actually, PyGame *is* something I am interested in experimenting with. I
> definitely want to use it, but I also want to try some stuff with the
> basics too, just so I don't immediately get into the complicated stuff
> without working with the usual things first, like lists and
> dictionaries, etc.

So start with a game that is playable with a text interface.  Perhaps 
hangman, perhaps with a different metaphor ;-)  That requires basic i/o, 
lists, import of random module, and conditional statements.

tjr



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


Re: tkinter question

2006-03-29 Thread linuxnooby
Ultimately what I am trying to is create a public computer session
manager.

1) User logs in and main application window is withdrawn (easy)
2) After (for example) 55 minutes - a warning window/dialoguebox
"session will end in 5 minutes"
3) With 30 seconds to go  - a warning window/dialoguebox "session will
end in 30 seconds"
4) User logged out (easy)

I am having problems with steps 2 and 3
Either the window/dialoguebox  will
(a) pause the program execution upon display waiting for user input
or (b) both warnings display together when application has finished.

What I want want is a window/dialogue box that will not halt
application logic, and will display immediately.

cheers David

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


Re: python challenge question (string manipulation)

2006-03-29 Thread Felipe Almeida Lessa
Em Qua, 2006-03-29 às 19:34 +, John Salerno escreveu:
> alphabet = string.ascii_lowercase
> code = string.ascii_lowercase[2:] + string.ascii_lowercase[:2]
> 
> Yet it still seems kind of verbose. But since that's the official 
> solution, I guess there's no other way to shift the characters in a string?

---

from collections import deque
from string import ascii_lowercase

a = deque(ascii_lowercase)
a.rotate(-2)
print list(a)
# prints ['c', 'd', ..., 'z', 'a', 'b']

---

But mind the performance! (as an exercise, time the performance of mine
and your approach using the timeit module and post back to the list)

HTH,

-- 
Felipe.

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

Re: Python Debugger / IDE ??

2006-03-29 Thread Christoph Zwerschke
Don Taylor wrote:
> Is there a free or low-cost version of Delphi for Windows available 
> anywhere?

I don't know (never used Delphi actually). Anyway, you don't need to 
have Delphi to use PyScripter, and PyScripter is completely free. 
However, it will only run on Windows because it is developed with 
Delphi. The advantage is that it is noticeably faster than most other 
free Python IDEs written in Python.

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


is 2.4.3 final?

2006-03-29 Thread John Salerno
I just noticed on one page of the Python website that it said:

"We are pleased to announce the release of Python 2.4.3 (final), a 
bugfix release of Python 2.4, on March 29, 2006."

Yet elsewhere it refers to it as a "release candidate" and still refers 
to 2.4.2 as the "current production version".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Command line option -Q (floor division)

2006-03-29 Thread Georg Brandl
Christoph Zwerschke wrote:
> Just for the records, Anthony Baxter explained that this is by intent, 
> because it would be still too disruptive a change. The testsuite does 
> not even run completely with -Qnew yet.

Now it does, thanks for the nudge. ;)

> So it will be probably only changed with Python 3.0.

Most certainly.

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


Re: No Cookie: how to implement session?

2006-03-29 Thread I V
Sullivan WxPyQtKinter wrote:
> As you said, There is no solution? I mean, tracing a real session
> without using tricks like hidden field and cookies in CGI script?

As people have said, this isn't a limitation of python, it's a feature
of HTTP. You might want to consider whether you actually need sessions
- see if you can design your application to use REST (see e.g.
http://www.xfront.com/REST-Web-Services.html , or there's lots of
information on Google).

People have also mentioned this in passing, but third alternative to
cookies and hidden fields is to use a session key in the query string -
this can be used for GET requests, so would work in redirects as well
as form submissions. Try:

http://yoursite.example/page?session=key

Then you need to remember, whenever you include a link to your site
that should retain the session information to add the session key to
the URL. You could define a function:

def session_url(url, key, **params={}):
qstring = "%s=%s" % ('session', urllib.quote(key))
for (name, value) in params.items():
qstring += "&%s=%s" %(urllib.quote(name), urllib.quote(value))
return qstring

And use it like:

#Do redirect
print "Location: " + session_url('new_page', session_key)

Or:

# Redirect to a page that loads the item called 'anitem'
print "Location: " + session_url('new_page', session_key, {'item',
'anitem'})

If you want to link to this URL in an HTML page, you need to remember
to escape the '&' character:

print "Edit item %s" % (cgi.escape(session_url('edit',
session_key, {'item', item_name})), item_name)

Then, if you need to submit a form, you can add the key as a hidden
field.

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


Re: Convert Word .doc to Acrobat .pdf files

2006-03-29 Thread kbperry
Wow...thanks again for the replies!

I will try both of these out at work tomorrow.  (I only work 3 days a
week because of school).

Thanks,

Keith

www.301labs.com

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


Re: Free Python IDE ?

2006-03-29 Thread Fabio Zadrozny
On 3/29/06, Jarek Zgoda <[EMAIL PROTECTED]> wrote:
Ernesto napisał(a):> I'm looking for a tool that I can use to "step through" python software> (debugging environment).  Is there a good FREE one (or one which is> excellent and moderately priced ) ?
Good free: PyDev for Eclipse.Good moderately priced: Komodo.You forgot excellent and moderately priced: Pydev Extensions ;-P (it is an extension to Pydev that adds many nice features... check it at 
http://www.fabioz.com/pydev). Cheers,Fabio
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Try Python!

2006-03-29 Thread BartlebyScrivener
Armin,

Mike Meyer already took a crack at this, and his starts right up just
by clicking on the link.

http://www.mired.org/home/mwm/try_python/

Yours looks prettier, but I don't think novices are going to be able to
figure out how to start it.

Regards,

rick

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


Re: Free Python IDE ?

2006-03-29 Thread Colin J. Williams
Ernesto wrote:
> I'm looking for a tool that I can use to "step through" python software
> (debugging environment).  Is there a good FREE one (or one which is
> excellent and moderately priced ) ?
> 
Ernesto,

If you are using Windows then you migt consider PyScripter.
http://mmm-experts.com/

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


Re: Free Python IDE ?

2006-03-29 Thread Jarek Zgoda
Ernesto napisał(a):

> I'm looking for a tool that I can use to "step through" python software
> (debugging environment).  Is there a good FREE one (or one which is
> excellent and moderately priced ) ?

Good free: PyDev for Eclipse.
Good moderately priced: Komodo.

But from my long experience with Python, you rarely need a debugger,
since most of time your program will work as expected, if you had good
algorithm. Treat it as a language feature - you don't need to debug good
algorithms in Python. ;)

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python challenge question (string manipulation)

2006-03-29 Thread John Salerno
Caleb Hattingh wrote:

> Also, I suspect you meant to say:
> 
 alphabet = string.ascii_lowercase
 code = alphabet[2:] + alphabet[:2]

Ah yes, I see what you did there. :)

> I actually create a new list here, although since lists are mutable, I
> could probably just change items in-place.   There is very likely
> something already in the builtins or the standard library for this, but
> I just haven't searched hard enough.


I'm pretty sure I read about a method for moving the items in lists 
around like that, so that you can shift the beginning to the end and 
vice versa. If I can find it, I'll let you know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python challenge question (string manipulation)

2006-03-29 Thread Caleb Hattingh
John

In python, strings are immutable - you have to create a new string no
matter what you do.

Also, I suspect you meant to say:

>>> alphabet = string.ascii_lowercase
>>> code = alphabet[2:] + alphabet[:2]

I had a similar need recently for a guitar chord generator program I've
been working on.  Here is a "shift" function from my utilities module:

def shift(list,num):
'''Shifts sequence "list" by "num" places.
if num is positive, list scrolls forwards,
otherwise, backwards.'''
if abs(num) > len(list):
num=num%len(list) # Use mod to remove full list entry rotations
newlist=list[-num:]+list[:-num]
return newlist

I actually create a new list here, although since lists are mutable, I
could probably just change items in-place.   There is very likely
something already in the builtins or the standard library for this, but
I just haven't searched hard enough.

Interesting trap I kept falling into: calling a guitar string a
"string" and then having collisions with the python type of the same
name.   Over and over again :)

Regards
Caleb

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


Re: Tkinter and fixed-size frames

2006-03-29 Thread msoulier
> calling pack_propagate(0) on the parent widget should work:

Indeed it does. 

Many thanks.

Mike

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


Try Python!

2006-03-29 Thread Armin Ronacher
Hiho,

One week ago I came across the nice `Try Ruby!`_ demonstration which
features an ajax based ruby console and a 20 minutes ruby tutorial.
I really liked that application and so I started to port that to
python.
Since I got a bit confused by the very complex javascript code I wrote
a
webconsole from scratch.

The result is a very basic python console which behaves like the CLI
one, except that it can't handle `raw_input` or any other method call
trying to access `sys.stdin`.

At the moment the application is multithreaded and evaluated
expressions
in a dict holding the sessions variables of the client connections.

Because of the behaviour the application breaks down easily and isn't
secure. This happens because I haven't finished it yet. Additionally
sessions don't have a timeout so you have to restart the server if it's
eating to much RAM.

If someone is interested in putting up that application on a public
server I can tell the application to spawn from inside XEN hosts and to
use forking instead of the multithreaded approach currently used.

The application is licensed under the GNU GPL, the sourcecode is
available via svn from::

http://trac.pocoo.org/repos/trypy

Since it requires Paste, PasteDeploy and the current colubrid checkout,
here the installation for copy/pasteing:

- easy_install Paste
- easy_install PasteDeploy
- svn co http://trac.pocoo.org/repos/trypy
- cd trypy
- svn co http://trac.pocoo.org/repos/colubrid/trunk/colubrid
- python trypy.py

The last command starts the application.

And here a screenshot of a running session:
http://trac.pocoo.org/wiki/TryPy

Regards,
Armin

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


Re: Free Python IDE ?

2006-03-29 Thread Caleb Hattingh
Hi Ernesto

SPE, or Stani's python editor is actually a decent IDE that can lauch
the winpdb debugger to step through code, with side windows for locals,
and watches and so on.   It's not exactly integrated debugging a la
Delphi, but in general my need for debugging is much less with python;
the few times I have needed debugging, SPE did the job well.

I also like that SPE automatically checks my code with tabnanny and
pychecker.  That way I don't have to do anything extra to use these
tools.

Oh, and SPE is free.

Keep well
Caleb

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


Re: COM callbacks in Python

2006-03-29 Thread Dan
One final note, The code posted does work. Unfortunately, the event
only fires for the ADO connection who actually triggered the event. In
my opinion, completely useless event. So the Python worked, The ADO
does not do what its name implies. Thanks to all. Dan

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


Re: operation complexities of lists and dictionaries

2006-03-29 Thread Caleb Hattingh
Hi

Use the "timeit" module, like so:

>>> from timeit import Timer
>>> t = Timer('[i for i in range(1)]')  # The string is code to execute 
>>> (for timing)
>>> print t.timeit(100) # execute it 100 times and print the result
0.222389936447

I would appreciate it if you could present your results in this thread.
 I have also been wondering about timings for simple operations.

Thanks
Caleb

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


Re: Creating COM server Events?

2006-03-29 Thread Dan
Here is what little I have so far. I can use clients to call the advise
method and store in the mylist set (should be named myset i guess).
Now, I want the client to have to implement a callback and register the
interface in the AdviseChange method.

glcount=0
mylist= set()
class TestTTechPycom:
_public_methods_= ["AdviseChange","ShowTheList"]
_reg_progid_ = "TestTTechPycom"
_reg_clsid_ = "{D5BA19AA-0F4D-4022-A811-40C087FE089A}"

def AdviseChange(self):
if not self in mylist:
mylist.add(self)
print "added"
else:
print "already added"

def ShowTheList(self):
print mylist


if __name__=='__main__':
print "Registering TestTTechPycom server"
import win32com.server.register
win32com.server.register.UseCommandLine(TestTTechPycom)

So, when I call the AdviseChange now, a unique ID is placed into
mylist. If you run ShowTheList()
it will give a different instance ID for each registered client. Great!
So given something like;

def AdviseChange(self,interfacepointer)
mylist.add(interfacepointer)
How do I define what the interface for the interfacepointer should look
like. I mean in my typelib listed in my previous post, the interface
for the events were marked as Source so that COM knows that the client
must implement them. How do you do that in Python? Dan

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


Re: Validating Syntax only with PyParser_SimpleParseString ?

2006-03-29 Thread olsongt

[EMAIL PROTECTED] wrote:
> I am seeking for a method to parse single lines of Python code (infact
> they are only formulas, so I generate a line like RESULT=). I
> do only want to know if the syntax is correct and if there is an error
> best would be to know where.
>
> I did find PyParser_SimpleParseString which does return a node
> structure. If there is an error it seems to return NULL, while I did
> not find this documented.
>
> Th eproblem with this is that first I do not get th elopcation of the
> syntax error, and second I don't know what is the proper method to free
> the node structure after I got it, since I will not use it. Or is there
> any better method doing this anyway.
>
> Environment: Windows / Borland C++

The builtin function compile will throw a SyntaxError if the syntax is
bad.

>>> compile("1=a","","single")
Traceback (most recent call last):
  File "", line 1, in ?
SyntaxError: can't assign to literal
>>>

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


Re: Terminating a subprocess question

2006-03-29 Thread Fredrik Lundh
Ernesto wrote:

> > > tn = telnetlib.Telnet("localhost",6000)
> > > print tn.read_all()
> > > # CRASH
> >
> > that's an unusual error message.  are you sure you didn't get a
> > traceback?  if so, what did it say?
>
> I was running it directly in a python shell.  After the tn.read_all()
> call, the python shell window freezes up, and I have to do a hard
> termination of the shell.  There is no traceback message, just a freeze.

hmm.  that hardly qualifies as a "CRASH"; rather, it's pretty much
what you'd expect from a read_all call:

>>> help(tn.read_all)
Help on method read_all in module telnetlib:

read_all(self) method of telnetlib.Telnet instance
Read all data until EOF; block until connection closed.

(note the "block until connection closed" part)

what happens if you use a non-blocking method instead ?  e.g.

>>> help(tn.read_very_eager)
Help on method read_very_eager in module telnetlib:

read_very_eager(self) method of telnetlib.Telnet instance
Read everything that's possible without blocking in I/O (eager).

Raise EOFError if connection closed and no cooked data
available.  Return '' if no cooked data available otherwise.
Don't block unless in the midst of an IAC sequence.





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


Re: python challenge question (string manipulation)

2006-03-29 Thread John Salerno
John Salerno wrote:

> It works, but is there a better way to shift the letters of the alphabet 
> for 'code'? I remember a method that did this for lists, I think, but I 
> can't remember what it was or if it worked for strings.

Ah ha! This is cleaner:

alphabet = string.ascii_lowercase
code = string.ascii_lowercase[2:] + string.ascii_lowercase[:2]

Yet it still seems kind of verbose. But since that's the official 
solution, I guess there's no other way to shift the characters in a string?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a hobbyist's dilemma

2006-03-29 Thread Gerard Flanagan
John Salerno wrote:

> Now that I've learned much of Python, I'm sort of stuck with what to do
> with it. I'm not a professional programmer, so I don't really have a use
> for Python now. But I really want to come up with some neat uses for it
> (for fun, and so I don't just start forgetting it right after I learned it).
>
> I found a few exercises online, but I wonder if anyone has other ideas
> (or exercise websites) that I can use to keep my Python skills going.
> The projects in Dive Into Python are a little too complicated for me
> right now, I think. I kind of like doing functional stuff, because OOP
> still has my mind warped, and I love that Python lets you write programs
> without having to mess with classes.
>
> Anyway, any suggestions are appreciated!

Having worked (briefly) as a teacher and tutor, I know that a good way
of helping *oneself* to really understand something is thinking "Ok,
how would I explain this to someone else?"  It is also very rewarding
to pass on knowledge, and, in particular, to see a 'furrowed brow' turn
into 'Ah, I see!' (and even more satisfying if the student is not
strong academically). [that's possibly a bit rose-tinted...:-1]

So my suggestion would be to write some exercises yourself, something
that you think would be useful to someone with less knowledge of the
language than you.

Gerard

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


python challenge question (string manipulation)

2006-03-29 Thread John Salerno
Ok, for those who have gotten as far as level 2 (don't laugh!), I have a 
question. I did the translation as such:

import string

alphabet = string.lowercase[:26]
code = string.lowercase[2:26] + 'ab'
clue = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc 
  dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm 
jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."

trans = string.maketrans(alphabet, code)
clue = clue.translate(trans)

print clue
raw_input()



It works, but is there a better way to shift the letters of the alphabet 
for 'code'? I remember a method that did this for lists, I think, but I 
can't remember what it was or if it worked for strings.

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


  1   2   3   >