Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Gregory Ewing

Steven D'Aprano wrote:

py class MyDict(dict):
... @classmethod
... def fromkeys(cls, func):
... # Expects a callback function that gets called with no arguments
... # and returns two items, a list of keys and a default value.
... return super(MyDict, cls).fromkeys(*func())


Here you've overridden a method with one having a
different signature. That's not something you'd
normally do, because, being a method, it's likely
to get invoked polymorphically.

Constructors, on the other hand, are usually *not*
invoked polymorphically. Most of the time we know
exactly which constructor we're calling, because we
write the class name explicitly at the point of call.

Consequently, we have a different attitude when it
comes to constructors. We choose not to require LSP
for constructors, because it turns out to be very
useful not to be bound by that constraint.
Practicality beats purity here.

The reason IPython gets into trouble is that it tries
to make a polymorphic call to something that nobody
expects to need to be polymorphic.

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


Re: SOAP web services using python. Would like to change the Envelope Document using MessagePlugin before sending it using suds

2013-02-19 Thread dieter
sarat.devin...@gmail.com writes:
 My current SOAP request sent via suds.client looks like this:

 SOAP-ENV:Envelope (some name space URIs)
   SOAP-ENV:Header /
 SOAP-ENV:Body
   ns5:saveModule
 request xsi:type=ns3:SaveModule
   Module xsi:type=ns4:Module
 ModuleName xsi:type=ns1:stringTest/ModuleName
   /Module
 /request
   /ns5:saveModule
 /SOAP-ENV:Body
 /SOAP-ENV:Envelope

 This request fails on my server. If i take the same XML request and massage 
 it and send it visa SOAPUI, it works fine. What I did was

 soapenv:Envelope (some name space URIs)
   soapenv:Header /
 soapenv:Body
   saveModule
 request
   Module
 ModuleNameTest/ModuleName
   /Module
 /request
   /saveModule
 /soapenv:Body
 /soapenv:Envelope

 As you see, I had to change SOAP-ENV to soapenv, modify node ns5:saveModule 
 to saveModule and also remove attributes such xsi:type to other child nodes

Looks as if you had a bad WSDL description of your service
and a server which fails to honor elementary standard elements
(of the XML-namespace standard, in particular).

The XML-namespace standard dictates that the concrete namespace prefixes
are (apart from some xml prefixes) insignificant; namespace prefixes
are use only to refer to namespace uris and only these uris
are relevant. Thus, a standard conform XML-namespace application
should world with whatever prefix is used as long as they refer
to the correct namespace uri.

According to the standard, xsi:type is used when the underlying schema
(in your WSDL) does not statically determine the type. In this
case, missing type information is provided by xsi:type.
A standard conform application should not have problems with xsi:type
attributes. Alternatively, the schema (in the WSDL) can assign types
and suds will not generate xsi:type attribute (at least not in
simple cases).

 How can I , modify the request in above manner using suds.client. 
 Documentation suggests to use a plugin with Client using marshalled method. 
 But I was unsuccessful

I cannot answer you concrete question.

However, when you are working with a component that does not honor
standards (this seems to be the case for your server component),
it may not be possible to use (other) components developed against
those standards.

In your particular case, it might be necessary to generate the SOAP 
messages yourself - in the peculiar way, your server expects them -
rather than use suds.

By the way: when I remember right, then suds supports some
control over the namespace prefixes used. Apparently, servers
not honoring the XML-namespace standard are not so rare.
Fortunately, I never needed this feature but I think I
have read something about it in the suds documentation.

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


Re: improving performance of writing into a pipe

2013-02-19 Thread mikprog
On Monday, February 18, 2013 6:12:01 PM UTC, Michael Torrie wrote:
 On 02/18/2013 10:00 AM, mikp...@gmail.com wrote:
 
  [..]
 
 
 
  I don't see an exception in your answer. Where did you put it for us?
 
 
 
  
 
  well I just did print a message:
 
  
 
  PIPEPATH = [/tmp/mypipe]
 
  
 
  [..]
 
  try:
 
  self.process = os.popen( self.PIPEPATH, 'w')
 
  except:
 
  print Error while trying opening the pipe!
 
  print check: , self.PIPEPATH
 
  exit()
 
  
 
  I see the error messages.
 
 
 
 Unfortunately your attempt to catch this exception is hiding the true
 
 cause.  You need to give us the actual exception.  Otherwise it could be
 
 anything from self.PIPEPATH not existing to who knows what.
 
 
 
 Almost never do you want to catch all exceptions like you're doing.  You
 
 should only catch the specific exceptions you know how to deal with in
 
 your code.
 
 
 
 For testing purposes, if your code really is as you put it, then
 catching exceptions is kind of silly since you're just re-raising the
 exception (sort of) but without any contextual information that would
 make the error meaningful.


Ok, I get your point.
But on the other hand how do I know what to catch if I have no clue what is 
causing the error?
There must be a way to catch all the possible errors and then investigate what 
is the problem, right? (which is not what I have done so far).

Or rather: what would you try to catch in this particular case?

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


Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread John Reid


On 19/02/13 00:18, Steven D'Aprano wrote:
 Terry Reedy wrote:
 
 On 2/18/2013 6:47 AM, John Reid wrote:

 I was hoping namedtuples could be used as replacements for tuples
in all instances.

 This is a mistake in the following two senses. First, tuple is a class
 with instances while namedtuple is a class factory that produces
 classes. (One could think of namedtuple as a metaclass, but it was not
 implemented that way.) 
 
 
 I think you have misunderstood. I don't believe that John wants to use the
 namedtuple factory instead of tuple. He wants to use a namedtuple type
 instead of tuple.
 
 That is, given:
 
 Point3D = namedtuple('Point3D', 'x y z')
 
 he wants to use a Point3D instead of a tuple. Since:
 
 issubclass(Point3D, tuple) 
 
 holds true, the Liskov Substitution Principle (LSP) tells us that anything
 that is true for a tuple should also be true for a Point3D. That is, given
 that instance x might be either a builtin tuple or a Point3D, all of the
 following hold:
 
 - isinstance(x, tuple) returns True
 - len(x) returns the length of x
 - hash(x) returns the hash of x
 - x[i] returns item i of x, or raises IndexError
 - del x[i] raises TypeError
 - x + a_tuple returns a new tuple
 - x.count(y) returns the number of items equal to y
 
 etc. Basically, any code expecting a tuple should continue to work if you
 pass it a Point3D instead (or any other namedtuple).
 
 There is one conspicuous exception to this: the constructor:
 
 type(x)(args)
 
 behaves differently depending on whether x is a builtin tuple, or a Point3D.
 

Exactly and thank you Steven for explaining it much more clearly.

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


Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread John Reid


On 19/02/13 01:47, alex23 wrote:
 On Feb 18, 9:47 pm, John Reid johnbaronr...@gmail.com wrote:
 See http://article.gmane.org/gmane.comp.python.ipython.user/10270 for more 
 info.
 
 One quick workaround would be to use a tuple where required and then
 coerce it back to Result when needed as such:
 
 def sleep(secs):
 import os, time, parallel_helper
 start = time.time()
 time.sleep(secs)
 return tuple(parallel_helper.Result(os.getpid(), time.time() -
 start))
 
 rc = parallel.Client()
 v = rc.load_balanced_view()
 async_result = v.map_async(sleep, range(3, 0, -1), ordered=False)
 for ar in async_result:
 print parallel_helper.Result(*ar)
 
 You can of course skip the creation of Result in sleep and only turn
 it into one in the display loop, but it all depends on additional
 requirements (and adds some clarity to what is happening, I think).
 

Thanks all I really need is a quick work around but it is always nice to
discuss these things. Also this class decorator seems to do the job for
ipython although it does change the construction syntax a little and is
probablty overkill. No doubt the readers of this list can improve it
somewhat as well.


import logging
_logger = logging.getLogger(__name__)
from collections import namedtuple

def make_ipython_friendly(namedtuple_class):
A class decorator to make namedtuples more ipython friendly.

_logger.debug('Making %s ipython friendly.', namedtuple_class.__name__)

# Preserve original new to use if needed with keyword arguments
original_new = namedtuple_class.__new__

def __new__(cls, *args, **kwds):
_logger.debug('In decorator __new__, cls=%s', cls)
if args:
if kwds:
raise TypeError('Cannot construct %s from an positional
and keyword arguments.', namedtuple_class.__name__)
_logger.debug('Assuming construction from an iterable.')
return namedtuple_class._make(*args)
else:
_logger.debug('Assuming construction from keyword arguments.')
return original_new(namedtuple_class, **kwds)

namedtuple_class.__new__ = staticmethod(__new__) # set the class'
__new__ to the new one
del namedtuple_class.__getnewargs__ # get rid of getnewargs

return namedtuple_class

Result = make_ipython_friendly(namedtuple('Result', 'pid duration'))

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


Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Steven D'Aprano
On Mon, 18 Feb 2013 23:48:46 -0800, raymond.hettinger wrote:

[...]
 If your starting point is an existing iterable such as s=['Guido',
 'BDFL', 1], you have a couple of choices:   p=Person(*s) or
 p=Person._make(s).  The latter form was put it to help avoid unpacking
 and repacking the arguments.


It might not be obvious to the casual reader, but despite the leading 
underscore, _make is part of the public API for namedtuple:

http://docs.python.org/2/library/collections.html#collections.namedtuple



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


Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Steven D'Aprano
Pardon me for the double-post, if any, my news client appears to have 
eaten my first reply.

On Mon, 18 Feb 2013 23:48:46 -0800, raymond.hettinger wrote:

[...]
 If your starting point is an existing iterable such as s=['Guido',
 'BDFL', 1], you have a couple of choices:   p=Person(*s) or
 p=Person._make(s).  The latter form was put it to help avoid unpacking
 and repacking the arguments.


It might not be obvious to the casual reader, but despite the leading 
underscore, _make is part of the public API for namedtuple:

http://docs.python.org/2/library/collections.html#collections.namedtuple



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


Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Steven D'Aprano
On Mon, 18 Feb 2013 23:48:46 -0800, raymond.hettinger wrote:

[...]
 If your starting point is an existing iterable such as s=['Guido',
 'BDFL', 1], you have a couple of choices:   p=Person(*s) or
 p=Person._make(s).  The latter form was put it to help avoid unpacking
 and repacking the arguments.


It might not be obvious to the casual reader, but despite the leading 
underscore, _make is part of the public API for namedtuple:

http://docs.python.org/2/library/collections.html#collections.namedtuple



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


Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Steven D'Aprano
On Mon, 18 Feb 2013 23:48:46 -0800, raymond.hettinger wrote:

[...]
 If your starting point is an existing iterable such as s=['Guido',
 'BDFL', 1], you have a couple of choices:   p=Person(*s) or
 p=Person._make(s).  The latter form was put it to help avoid unpacking
 and repacking the arguments.


It might not be obvious to the casual reader, but despite the leading 
underscore, _make is part of the public API for namedtuple:

http://docs.python.org/2/library/collections.html#collections.namedtuple



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


Re: improving performance of writing into a pipe

2013-02-19 Thread Peter Otten
mikp...@gmail.com wrote:

 On Monday, February 18, 2013 6:12:01 PM UTC, Michael Torrie wrote:
 On 02/18/2013 10:00 AM, mikp...@gmail.com wrote:
 
  [..]
 
 
 
  I don't see an exception in your answer. Where did you put it for us?
 
 
 
  
 
  well I just did print a message:
 
  
 
  PIPEPATH = [/tmp/mypipe]
 
  
 
  [..]
 
  try:
 
  self.process = os.popen( self.PIPEPATH, 'w')
 
  except:
 
  print Error while trying opening the pipe!
 
  print check: , self.PIPEPATH
 
  exit()
 
  
 
  I see the error messages.
 
 
 
 Unfortunately your attempt to catch this exception is hiding the true
 
 cause.  You need to give us the actual exception.  Otherwise it could be
 
 anything from self.PIPEPATH not existing to who knows what.
 
 
 
 Almost never do you want to catch all exceptions like you're doing.  You
 
 should only catch the specific exceptions you know how to deal with in
 
 your code.
 
 
 
 For testing purposes, if your code really is as you put it, then
 catching exceptions is kind of silly since you're just re-raising the
 exception (sort of) but without any contextual information that would
 make the error meaningful.
 
 
 Ok, I get your point.
 But on the other hand how do I know what to catch if I have no clue what
 is causing the error? There must be a way to catch all the possible errors
 and then investigate what is the problem, right? (which is not what I have
 done so far).
 
 Or rather: what would you try to catch in this particular case?

Nothing. 

Once you get your script working you can try to provoke errors, and for 
those errors you can recover from you can write error handlers. For IOError 
and Python  3.3 that may involve inspecting the errno attribute and 
conditionally reraising.

By the way, I don't think

  PIPEPATH = [/tmp/mypipe]
  self.process = os.popen( self.PIPEPATH, 'w')

can work. As a few people already told you the built-in open()

with open(PIPEPATH, w) as f:
   f.write(...)

is the way to go.



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


Re: Instances as dictionary key, __hash__ and __eq__

2013-02-19 Thread Jean-Michel Pichavant

  Additionally, If I'm making things much more complicated than they
  need to be, let me know.
 

 You are. There are ways to achieve what you want, but it requires a
 lot more setup and discipline. The simplest way is probably to have
 a _equal_fields() method that subclasses override, returning a tuple
 of the attributes that should be hashed. Then in __hash__() and
 __eq__ you iterate over the returned tuple, get the value for each
 attribute and either hash or compare.

 Of course, you have to take into account in __eq__ that the other
 instance may not have the same attributes (e.g. self is a subclass
 that uses extra attributes in its __hash__ and __eq__).

 Tim Delaney

I will happily restrain myself to never subclass such class.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: improving performance of writing into a pipe

2013-02-19 Thread mikprog
 
 Once you get your script working you can try to provoke errors, and for 
 
 those errors you can recover from you can write error handlers. For IOError 
 
 and Python  3.3 that may involve inspecting the errno attribute and 
 
 conditionally reraising.


Ok.



 By the way, I don't think
 
 
   PIPEPATH = [/tmp/mypipe]
 
   self.process = os.popen( self.PIPEPATH, 'w')
 
 
 
 can work. As a few people already told you the built-in open()


Few people?
I thought Oscar was a singular person, not a group of people :-)
Seriously, I am convinced by that approach (thanks) and I wish to go that way, 
but the problem I am getting now is that the open fails and then I can't go on.

Also, I am now looking at the subprocess as os.popen seems deprecated.
Any opinion on that?
Thanks for your suggestion.

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


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Anssi Saari
John Immarino joh...@gmail.com writes:

 I coded a Python solution for Problem #14 on the Project Euler
 website. I was very surprised to find that it took 107 sec. to run
 even though it's a pretty simple program.  I also coded an equivalent
 solution for the problem in the old MSDOS basic. (That's the 16 bit
 app of 1980s vintage.)

Just out of curiosity, can you post the basic version as well?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Serhiy Storchaka

On 18.02.13 21:13, John Immarino wrote:

max=0
m=0
while m=100:
 m+=1
 count=0
 n=m
 while n!=1:
 count+=1
 if n%2==0:
 n=n//2
 else:
 n=3*n+1
 if countmax:
  max=count
  num=m
print(num,max)


Some minor tips:

1. Use range() for m iteration.
2. Instead of if n%2==0: use just if n%2:.
3. Convert all you code to a function. Python is a little faster with 
locals than with globals.


In sum all this tips will speedup your code about 2x.

And one big tip:

Use cashing (and recursion). This will speedup your code more than 10x.


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


Re: improving performance of writing into a pipe

2013-02-19 Thread Oscar Benjamin
On 19 February 2013 10:27,  mikp...@gmail.com wrote:
 can work. As a few people already told you the built-in open()


 Few people?
 I thought Oscar was a singular person, not a group of people :-)

Serhiy also suggested it.

 Seriously, I am convinced by that approach (thanks) and I wish to go that 
 way, but the problem I am getting now is that the open fails and then I can't 
 go on.

Perhaps no-one has been explicit enough about what you should do here:

1) Remove all try/except from your code.
2) Run the code
3) Look at the *unadulterated* error message that Python prints out
4) Either fix the error if you know how or
5) Reply here posting the exact error message.

Also, in future:
6) Don't use bare try/except and don't catch errors while you're
debugging. Allow the errors to be printed as they are so that you can
read the message and see the line that triggers the error.
7) Don't post to a mailing list saying I get an error, I can see
errors or it doesn't work. If you have errors paste the exact error
message (all of it!). If you don't get errors but it doesn't do what
you want explain exactly what happened and also what you wanted to
happen. If you had followed this procedure at the start of this
thread, then you would already have a solution to (or at least an
explanation of) your problem by now.

 Also, I am now looking at the subprocess as os.popen seems deprecated.
 Any opinion on that?

I'm not convinced that either is appropriate for your problem.


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


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Piet van Oostrum
Terry Reedy tjre...@udel.edu writes:

 On 2/18/2013 2:13 PM, John Immarino wrote:
 I coded a Python solution for Problem #14 on the Project Euler
 website. I was very surprised to find that it took 107 sec. to run
 even though it's a pretty simple program.  I also coded an equivalent
 solution for the problem in the old MSDOS basic. (That's the 16 bit
 app of 1980s vintage.)  It ran in 56 sec. Is there a flaw in my
 coding, or is Python really this slow in this particular application.
 MSDOS Basic usually runs at a snails pace compared to Python.

 I find this surprising too. I am also surprised that it even works,
 given that the highest intermediate value is about 57 billion and I do
 not remember that Basic had infinite precision ints.

That may explain why the Basic version is faster: it gets overflow and
then it may have taken some shortcuts.
-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: improving performance of writing into a pipe

2013-02-19 Thread mikprog
On Monday, February 18, 2013 7:29:09 PM UTC, Serhiy Storchaka wrote:
 On 18.02.13 17:12, mikp...@gmail.com wrote:
 
  on an embedded linux system (BeagleBoard) I am writing data coming from 
  bluetooth dongle into a pipe.
 
  The function is the following one:
 
 
 
 
 
  def write_to_pipe(line):
 
 
 
   # next line ensures that bytes like '0x09' are not translated into 
  '\t' for
 
   #example, and they are sent as such
 
   hexbytes = \\x + \\x.join([hex(ord(c))[2:].zfill(2) for c in line])
 
   wrap = [echo -en ', '  /tmp/mypipe]
 
   msg = hexbytes.join(wrap)
 
   print DBG: sending: , msg
 
 
 
   try:
 
   os.popen( msg )
 
   except:
 
   print Error: write_to_pipe has failed!
 
 
 
 
 
  Now I typically receive 4 bytes from the bluetooth dongle and that is fine.
 
  However when I receive many more than that it seems that the writing into 
  the pipe is too slow.
 
 
 
  Is there any clever/obvious way to improve the code above?
 
  (I am quite sure there is to be honest).
 
 
 
 def write_to_pipe(line):
 
  hexbytes = ''.join('\\x%02x' % ord(c) for c in line)
 
  with open('/tmp/mypipe', 'w') as f:
 
  f.write(hexbytes)


I'll take your hexbytes = '' line (which is surely more efficient than mine).
However whit this approach open + write it seems the pipe doesn't get the 
data...
I am not sure what is going on. 
At this point I suspect it could be a problem on the pipe itself (which I 
inherited). 

It is just weird that the pipe accept this correctly:
wrap = [echo -en ', '  /tmp/midi]
msg = hexbytes.join(wrap)
os.popen( msg )

but seems to be careless of approach open + write.

I need to investigate there.

Thanks a lot, to you and to everyone else.
Mik

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


Data Tree urgent help!!!!!!

2013-02-19 Thread anadionisio257
Hello! 
I have this lists with information and I need to make a tree by associating 
the information inside the lists. For example:

l1 = [apple, pear]
l2 = [dog, cat]
l3 = [fork, spoon]

And I need to make something like this:

l4 = [apple, dog, fork]
l5 = [apple, dog, spoon]
l6= [apple, cat, fork]
l7 = [apple, cat, spoon]
l8 = [pear, dog, fork]
etc...

How can I do this? I could use for cycles and if...else but with larger 
lists it gets complicated   

Is there some simple solution that I can use?

I hope you could help me  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data Tree urgent help!!!!!!

2013-02-19 Thread Peter Otten
anadionisio...@gmail.com wrote:

 Hello!
 I have this lists with information and I need to make a tree by
 associating the information inside the lists. For example:
 
 l1 = [apple, pear]
 l2 = [dog, cat]
 l3 = [fork, spoon]
 
 And I need to make something like this:
 
 l4 = [apple, dog, fork]
 l5 = [apple, dog, spoon]
 l6= [apple, cat, fork]
 l7 = [apple, cat, spoon]
 l8 = [pear, dog, fork]
 etc...
 
 How can I do this? I could use for cycles and if...else but with
 larger lists it gets complicated
 
 Is there some simple solution that I can use?

Try itertools.product():

 class Name(str):
... def __repr__(self):
... return self
... 
 apple, pear, dog, cat, fork, spoon = map(Name, apple pear dog cat fork 
spoon.split())
 fruit = [apple, pear]
 pets = [dog, cat]
 cutlery = [fork, spoon]
 from itertools import product
 for item in product(fruit, pets, cutlery):
... print item
... 
(apple, dog, fork)
(apple, dog, spoon)
(apple, cat, fork)
(apple, cat, spoon)
(pear, dog, fork)
(pear, dog, spoon)
(pear, cat, fork)
(pear, cat, spoon)



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


Facebook Graph API

2013-02-19 Thread takeshi honda
The following code gave me the error, facebook.GraphAPIError: Unsupported 
operation. How can I fix this error?

import facebook
import sys;

token = 'mytokenx';

graph = facebook.GraphAPI(token)
profile = graph.get_object(myusername)
friends = graph.get_connections(myusername, friends) # error occured at 
this line.

friend_list = [friend['name'] for friend in friends['data']]
print friend_list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data Tree urgent help!!!!!!

2013-02-19 Thread Ana Dionísio
Thank you so much!!! It works perfectly!!!

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


ANN: pyftpdlib 1.0.0 released

2013-02-19 Thread Giampaolo Rodolà
Hi there guys,
After 1 year of development and refinements I'm pleased to announce a
release of pyftpdlib which appears to be the fastest FTP server out
there (on UNIX at least)! See:
http://code.google.com/p/pyftpdlib/wiki/Benchmarks

1.0.0 release introduces serious improvements amongst which python 3
support (finally!) and full Unicode support.  Here's the major ones.


=== New IO loop and epoll() / kqueue() support ===

The IO loop, originally relying on asyncore, has been rewritten from
scratch 
(http://code.google.com/p/pyftpdlib/source/browse/trunk/pyftpdlib/ioloop.py)
and now supports epoll() on Linux and kqueue() on OSX/BSD.
Also select() (Windows) and poll() pollers have been rewritten
resulting in pyftpdlib being an order of magnitude faster and more
scalable than ever. Read the full story here:
http://code.google.com/p/pyftpdlib/issues/detail?id=203

=== Alternative concurrency model ===

It is now possible to change the default concurrency model from async
(non blocking) to multiple processes / threads based, meaning you are
now free to block as long as you want and support particularly slow
filesystems.
Switching is as easy as changing an import. More information are here:
http://code.google.com/p/pyftpdlib/wiki/Tutorial#4.6_-_Changing_the_concurrency_model

=== Python 3 porting + full Unicode support ===

Finally!

=== Logging ===

logging module is now used for logging as replacement for log(),
logline() and logerror() functions which are now deprecated. Also, the
whole logging infrastructure has been refactored and it is more
compact and consistent. Also by default pyftpdlib logs will have
colors.

=== Other improvements ===

 * a new FilesystemError exception class is available in order send
   custom error strings to client from an AbstracteFS subclass.

 * on_connect() and on_disconnect() callbacks

 * FTPHandler.ftp_* methods implementing filesystem-related commands
   now return a meaningful value on success (tipically the path name).

 * FTPServer.serve_forever() has a new handle_exit parameter which
   can be set to False in order to avoid handling SIGTERM/SIGINT signals.

=== Backward compatibility breakage ===

A lot of backward incompatible changes have been introduced amongst
which the different import system, the different
validate_authentication() signature and the fact that the filesystem
class now expects Unicode strings rather than bytes. HISTORY file
enlists all of them and also provides a guide on how to port your
existent to this new version.
http://code.google.com/p/pyftpdlib/source/browse/trunk/HISTORY?spec=svn1175r=1172#85


=== Some links ===

Home: http://code.google.com/p/pyftpdlib/
Download: http://code.google.com/p/pyftpdlib/list/downloads
Tutorial: http://code.google.com/p/pyftpdlib/wiki/Tutorial
Complete list of changes:
http://code.google.com/p/pyftpdlib/source/browse/trunk/HISTORY


That should be all folks.
I hope you'll enjoy this new version,

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


Re: improving performance of writing into a pipe

2013-02-19 Thread mikprog
 
 def write_to_pipe(line):
 
  hexbytes = ''.join('\\x%02x' % ord(c) for c in line)
 
  with open('/tmp/mypipe', 'w') as f:
 
  f.write(hexbytes)


Update:
with a fix in the pipe THIS was the right way to do it, and it now works.
Thanks a lot Serhiy to you and to everyone else.

Mik

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


Making unhashable object

2013-02-19 Thread Olive
I am trying to define a class whose instances should not be hashable, 
following: http://docs.python.org/2/reference/datamodel.html#object.__hash__

class A:
def __init__(self,a):
self.value=a
__hash__=None


Then:

 a=A(3)
 hash(a)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'NoneType' object is not callable
 hash([2])
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unhashable type: 'list'

I would expect the same error in both case and the error is confusing in the 
first case. What's the proper way of making an object non hashable?

Olive

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


Re: Making unhashable object

2013-02-19 Thread Jean-Michel Pichavant
- Original Message -
 I am trying to define a class whose instances should not be hashable,
 following:
 http://docs.python.org/2/reference/datamodel.html#object.__hash__
 
 class A:
 def __init__(self,a):
 self.value=a
 __hash__=None
 
 
 Then:
 
  a=A(3)
  hash(a)
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: 'NoneType' object is not callable
  hash([2])
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: unhashable type: 'list'
 
 I would expect the same error in both case and the error is confusing
 in the first case. What's the proper way of making an object non
 hashable?
 
 Olive

Try

class A:
  def __hash__(self):
raise TypeError(unhashable type: '%s' % self.__class__.__name__)

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making unhashable object

2013-02-19 Thread Chris Angelico
On Wed, Feb 20, 2013 at 12:38 AM, Olive
diolu.remove_this_p...@bigfoot.com wrote:
 I am trying to define a class whose instances should not be hashable, 
 following: http://docs.python.org/2/reference/datamodel.html#object.__hash__

 class A:
 def __init__(self,a):
 self.value=a
 __hash__=None

This is an old-style class. If you subclass object, it works as you expect:

 class A(object):
def __init__(self,a):
self.value=a
__hash__=None

 a=A(3)
 hash(a)

Traceback (most recent call last):
  File pyshell#7, line 1, in module
hash(a)
TypeError: unhashable type: 'A'

This is with Python 2.6. With Python 3 and later, that distinction no
longer exists.

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


Re: Making unhashable object

2013-02-19 Thread Peter Otten
Olive wrote:

 I am trying to define a class whose instances should not be hashable,
 following:
 http://docs.python.org/2/reference/datamodel.html#object.__hash__
 
 class A:
 def __init__(self,a):
 self.value=a
 __hash__=None
 
 
 Then:
 
 a=A(3)
 hash(a)
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: 'NoneType' object is not callable
 hash([2])
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: unhashable type: 'list'
 
 I would expect the same error in both case and the error is confusing in
 the first case. What's the proper way of making an object non hashable?
 
 Olive

Deriving your classes from object has several advantages, among them:

 class A:
... __hash__ = None
... 
 hash(A())
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'NoneType' object is not callable
 class B(object):
... __hash__ = None
... 
 hash(B())
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unhashable type: 'B'


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


Re: improving performance of writing into a pipe

2013-02-19 Thread Peter Otten
mikp...@gmail.com wrote:

 def write_to_pipe(line):
  hexbytes = ''.join('\\x%02x' % ord(c) for c in line)

I thought this was only needed to have 'echo' except your data.

  with open('/tmp/mypipe', 'w') as f:
  f.write(hexbytes)

 Update:
 with a fix in the pipe THIS was the right way to do it, and it now works.
 Thanks a lot Serhiy to you and to everyone else.

Do you mind telling us what fix you applied?

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


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Olive

 max=0
 m=0
 while m=100:
 m+=1
 count=0
 n=m
 while n!=1:
 count+=1
 if n%2==0:
 n=n//2
 else:
 n=3*n+1
 if countmax:
  max=count
  num=m
 print(num,max)
 

I have tried to run your program with pypy (Python git compiler) 
(http://pypy.org/), it runs about 15x faster (8 sec instead of 2m2sec in my old 
Celeron M420 computer).

Olive

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


Re: improving performance of writing into a pipe

2013-02-19 Thread mikprog
  Thanks a lot Serhiy to you and to everyone else.
 
 
 Do you mind telling us what fix you applied?


Oh, apologies Peter, I thought it was clear as I posted it after the lines 
written by Serhiy.
So it was what Serhiy suggest in addition to some (?minor?) modification to the 
pipe itself, which I cannot comment about as I don't have access to it.
But apparently the problem of not being able to open it was due to it.
(It does not help much I am afraid... but that's all I know).

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


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Tim Daneliuk

On 02/18/2013 03:54 PM, Ian Kelly wrote:

On Mon, Feb 18, 2013 at 12:13 PM, John Immarino joh...@gmail.com wrote:

I coded a Python solution for Problem #14 on the Project Euler website. I was 
very surprised to find that it took 107 sec. to run even though it's a pretty 
simple program.  I also coded an equivalent solution for the problem in the old 
MSDOS basic. (That's the 16 bit app of 1980s vintage.)  It ran in 56 sec. Is 
there a flaw in my coding, or is Python really this slow in this particular 
application. MSDOS Basic usually runs at a snails pace compared to Python.


Well, I don't see anything that looks especially slow in that code,
but the algorithm that you're using is not very efficient.  I rewrote
it using dynamic programming (details left as an exercise), which got
the runtime down to about 4 seconds.



Are you sure you wouldn't like to share with the class?  I'd be interested
in seeing your approach...



--

Tim Daneliuk tun...@tundraware.com
PGP Key: http://www.tundraware.com/PGP/

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


Python module import failed error

2013-02-19 Thread matt . doolittle33
Hello all; I am using Ubuntu 12.10 and Python v2.7.3.  I am trying to add a 
directory to the PYTHONPATH.  All of the commands I have found on the web have 
failed.  Please help me to add a directory to the PYHONPATH.  The file path is 
Home/home/bin.  Thanks in advance.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python module import failed error

2013-02-19 Thread Chris Angelico
On Wed, Feb 20, 2013 at 2:23 AM,  matt.doolittl...@gmail.com wrote:
 Hello all; I am using Ubuntu 12.10 and Python v2.7.3.  I am trying to add a 
 directory to the PYTHONPATH.  All of the commands I have found on the web 
 have failed.  Please help me to add a directory to the PYHONPATH.  The file 
 path is Home/home/bin.  Thanks in advance.

What do you mean by that path? That doesn't look like an Ubuntu/Linux
path name. Pull up a terminal (Ctrl-Alt-T should do that for you,
though I haven't used an Ubuntu since 10.10) and see if you can 'ls'
the path - once you have the real path name (it might start with
/home/your_user_name/ for instance), go back to the commands you found
on the web and try them - they'll probably work, then.

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


Re: CBT code in python

2013-02-19 Thread Megha Agrawal
Plsss help !!

On Tue, Feb 19, 2013 at 12:40 AM, Megha Agrawal me...@greybatter.comwrote:

 Hi,


 Does anybody have code for Complete Binary tree for a given no of leaves??


 Thanks in advance!!

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


Re: Facebook Graph API

2013-02-19 Thread Terry Reedy

On 2/19/2013 7:37 AM, takeshi honda wrote:

The following code gave me the error, facebook.GraphAPIError: Unsupported 
operation. How can I fix this error?

import facebook
import sys;

token = 'mytokenx';

graph = facebook.GraphAPI(token)
profile = graph.get_object(myusername)
friends = graph.get_connections(myusername, friends) # error occured at 
this line.


Look in the reference for GraphAPI (Facebook account login required) to 
find out what you should have written instead of 'get_connections'.



friend_list = [friend['name'] for friend in friends['data']]
print friend_list




--
Terry Jan Reedy

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


IOerror : need urgent help

2013-02-19 Thread inshu chauhan
Here is my attempt to merge 10 files stored in a folder into a single file :

import csv

with open(C:\Users\inshu.chauhan\Desktop\test.arff, w) as w:
writer = csv.writer(w)
for f in glob.glob(C:\Users\inshu.chauhan\Desktop\For
Model_600\*.arff):
rows = open(f, r).readlines()
writer.writerows(rows)


Error:

Traceback (most recent call last):
  File C:\Users\inshu.chauhan\Desktop\Mergefiles.py, line 3, in module
with open(C:\Users\inshu.chauhan\Desktop\test.arff, w) as w:
IOError: [Errno 22] invalid mode ('w') or filename:
'C:\\Users\\inshu.chauhan\\Desktop\test.arff'

Why my programme is not working ?? :(

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


Re: IOerror : need urgent help

2013-02-19 Thread Thomas Calmant
hi

It seems you forgot to escape the escape character in the file names ('\'):
C:\Users\inshu.chauhan\Desktop\test.arff
= rC:\Users\inshu.chauhan\Desktop\test.arff
or
= C:\\Users\\inshu.chauhan\\Desktop\\test.arff

++
Thomas

2013/2/19 inshu chauhan insidesh...@gmail.com

 Here is my attempt to merge 10 files stored in a folder into a single file
 :

 import csv

 with open(C:\Users\inshu.chauhan\Desktop\test.arff, w) as w:
 writer = csv.writer(w)
 for f in glob.glob(C:\Users\inshu.chauhan\Desktop\For
 Model_600\*.arff):
 rows = open(f, r).readlines()
 writer.writerows(rows)


 Error:

 Traceback (most recent call last):
   File C:\Users\inshu.chauhan\Desktop\Mergefiles.py, line 3, in module
 with open(C:\Users\inshu.chauhan\Desktop\test.arff, w) as w:
 IOError: [Errno 22] invalid mode ('w') or filename:
 'C:\\Users\\inshu.chauhan\\Desktop\test.arff'

 Why my programme is not working ?? :(

 Thanks in Advance !!




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


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


Re: CBT code in python

2013-02-19 Thread Mark Lawrence

On 19/02/2013 15:27, Megha Agrawal wrote:

Plsss help !!

On Tue, Feb 19, 2013 at 12:40 AM, Megha Agrawal me...@greybatter.com
mailto:me...@greybatter.com wrote:

Hi,

Does anybody have code for Complete Binary tree for a given no of
leaves??

Thanks in advance!!



Search engines are available to get your answer.  Why not use one before 
posting your question?


--
Cheers.

Mark Lawrence

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


Re: IOerror : need urgent help

2013-02-19 Thread Mark Lawrence

On 19/02/2013 15:27, inshu chauhan wrote:

Here is my attempt to merge 10 files stored in a folder into a single file :

import csv

with open(C:\Users\inshu.chauhan\Desktop\test.arff, w) as w:
 writer = csv.writer(w)
 for f in glob.glob(C:\Users\inshu.chauhan\Desktop\For
Model_600\*.arff):
 rows = open(f, r).readlines()
 writer.writerows(rows)


Error:

Traceback (most recent call last):
   File C:\Users\inshu.chauhan\Desktop\Mergefiles.py, line 3, in module
 with open(C:\Users\inshu.chauhan\Desktop\test.arff, w) as w:
IOError: [Errno 22] invalid mode ('w') or filename:
'C:\\Users\\inshu.chauhan\\Desktop\test.arff'

Why my programme is not working ?? :(

Thanks in Advance !!



Use a raw string for the output file name or forward instead of back 
slashes.  Explanation here 
http://docs.python.org/2/reference/lexical_analysis.html


--
Cheers.

Mark Lawrence

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


Re: Facebook Graph API

2013-02-19 Thread Сахнов Михаил
You need to get token from API server before signing requests with it,
don't you?
19.02.2013 16:42 пользователь takeshi honda moech...@gmail.com написал:

 The following code gave me the error, facebook.GraphAPIError: Unsupported
 operation. How can I fix this error?

 import facebook
 import sys;

 token = 'mytokenx';

 graph = facebook.GraphAPI(token)
 profile = graph.get_object(myusername)
 friends = graph.get_connections(myusername, friends) # error occured
 at this line.

 friend_list = [friend['name'] for friend in friends['data']]
 print friend_list
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: CBT code in python

2013-02-19 Thread Megha Agrawal
I am not getting my answer thats why I am asking.

On Tue, Feb 19, 2013 at 9:10 PM, Mark Lawrence breamore...@yahoo.co.ukwrote:

 On 19/02/2013 15:27, Megha Agrawal wrote:

 Plsss help !!

 On Tue, Feb 19, 2013 at 12:40 AM, Megha Agrawal me...@greybatter.com
 mailto:me...@greybatter.com wrote:

 Hi,

 Does anybody have code for Complete Binary tree for a given no of
 leaves??

 Thanks in advance!!


 Search engines are available to get your answer.  Why not use one before
 posting your question?

 --
 Cheers.

 Mark Lawrence

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

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


Re: IOerror : need urgent help

2013-02-19 Thread MRAB

On 2013-02-19 15:27, inshu chauhan wrote:

Here is my attempt to merge 10 files stored in a folder into a single file :

import csv

with open(C:\Users\inshu.chauhan\Desktop\test.arff, w) as w:
 writer = csv.writer(w)
 for f in glob.glob(C:\Users\inshu.chauhan\Desktop\For
Model_600\*.arff):
 rows = open(f, r).readlines()
 writer.writerows(rows)


Error:

Traceback (most recent call last):
   File C:\Users\inshu.chauhan\Desktop\Mergefiles.py, line 3, in module
 with open(C:\Users\inshu.chauhan\Desktop\test.arff, w) as w:
IOError: [Errno 22] invalid mode ('w') or filename:
'C:\\Users\\inshu.chauhan\\Desktop\test.arff'

Why my programme is not working ?? :(


Look at the traceback. It says that the path is:

'C:\\Users\\inshu.chauhan\\Desktop\test.arff'

All but one of the backslashes are doubled.

That's because the backslash character \ starts an escape sequence, but
if it can't recognise the escape sequence, it treats the backslash as a
literal character.

In that string literal, '\t' is an escape sequence representing a tab
character (it's equal to chr(9)), but '\U', '\i' and '\D' are not
escape sequences, so they are equivalent to '\\U, '\\i' and '\\D'
respectively.

What you should do is use raw string literals for paths:

rC:\Users\inshu.chauhan\Desktop\test.arff

or use '/' instead (Windows allows it as an alternative, unless it
occurs initially, which you'll rarely want to do in practice):

C:/Users/inshu.chauhan/Desktop/test.arff

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


Re: CBT code in python

2013-02-19 Thread Chris Angelico
On Wed, Feb 20, 2013 at 2:49 AM, Megha Agrawal me...@greybatter.com wrote:
 I am not getting my answer thats why I am asking.

Making repeated requests is usually not an effective way to get
information. Especially considering how brief and incomplete your
original question was, I suspect a lot of people deleted it and moved
on. Have a read of this, and follow its advice; you'll either solve
the problem yourself, or make it a lot easier (and therefore more
likely) for someone to help you:

http://www.catb.org/esr/faqs/smart-questions.html

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


Re: Awsome Python - chained exceptions

2013-02-19 Thread rurpy
On 02/18/2013 07:18 PM, alex23 wrote:
[...]
 Weird, I'm using GG too and not seeing any doubling of my messages. I
 have reverted to using the old interface, though, so it might be a
 side-effect of the new version they're hyping, which does seem to have
 been designed by Satan himself (the way they've separated thread view
 from article view is a huge WTF). I've sent a heap of feedback to them
 as well with no response. Google don't really seem to want to hype
 Usenet as anything other than a target for blogspot spam, it appears.

In their new interface, GG presents a checkbox for cc: addresses in 
the post being replied to.  Unchecking the cc: pytho...@python.org
box will prevent the double posts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IOerror : need urgent help

2013-02-19 Thread inshu chauhan
On Tue, Feb 19, 2013 at 4:54 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 On 2013-02-19 15:27, inshu chauhan wrote:

 Here is my attempt to merge 10 files stored in a folder into a single
 file :

 import csv

 with open(C:\Users\inshu.chauhan\**Desktop\test.arff, w) as w:
  writer = csv.writer(w)
  for f in glob.glob(C:\Users\inshu.**chauhan\Desktop\For
 Model_600\*.arff):
  rows = open(f, r).readlines()
  writer.writerows(rows)


 Error:

 Traceback (most recent call last):
File C:\Users\inshu.chauhan\**Desktop\Mergefiles.py, line 3, in
 module
  with open(C:\Users\inshu.chauhan\**Desktop\test.arff, w) as w:
 IOError: [Errno 22] invalid mode ('w') or filename:
 'C:\\Users\\inshu.chauhan\\**Desktop\test.arff'

 Why my programme is not working ?? :(

  Look at the traceback. It says that the path is:

 'C:\\Users\\inshu.chauhan\\**Desktop\test.arff'

 All but one of the backslashes are doubled.

 That's because the backslash character \ starts an escape sequence, but
 if it can't recognise the escape sequence, it treats the backslash as a
 literal character.

 In that string literal, '\t' is an escape sequence representing a tab
 character (it's equal to chr(9)), but '\U', '\i' and '\D' are not
 escape sequences, so they are equivalent to '\\U, '\\i' and '\\D'
 respectively.

 What you should do is use raw string literals for paths:


 rC:\Users\inshu.chauhan\**Desktop\test.arff

 or use '/' instead (Windows allows it as an alternative, unless it
 occurs initially, which you'll rarely want to do in practice):

 C:/Users/inshu.chauhan/**Desktop/test.arff

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


Thanks I understood the problem now and my programme is working !!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IOerror : need urgent help

2013-02-19 Thread Mark Lawrence

On 19/02/2013 15:40, Thomas Calmant wrote:

hi

It seems you forgot to escape the escape character in the file names ('\'):
C:\Users\inshu.chauhan\Desktop\test.arff
= rC:\Users\inshu.chauhan\Desktop\test.arff
or
= C:\\Users\\inshu.chauhan\\Desktop\\test.arff

++
Thomas



Yuck :)

--
Cheers.

Mark Lawrence

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


Re: Python module import failed error

2013-02-19 Thread matt . doolittle33

 
 What do you mean by that path? That doesn't look like an Ubuntu/Linux
 
 path name. Pull up a terminal (Ctrl-Alt-T should do that for you,
 
 though I haven't used an Ubuntu since 10.10) and see if you can 'ls'
 
 the path - once you have the real path name (it might start with
 
 /home/your_user_name/ for instance), go back to the commands you found
 
 on the web and try them - they'll probably work, then.
 
thats the file path.  the directory bin in my home directory.  in bash it 
obviously looks like this  ~/bin using the file system folder the path is 
home/Home/bin.  i have tried commands like, export 
PYTHONPATH=${PYTHONPATH}:/users/matt/bin or home/matt/bin or Home/home/bin and 
nothing has worked.
from what ive found on the web the Python import process is notoriously 
underspecified, notwithstanding i was under the impression that PYTHONPATH is a 
global variable that i can add directories to at anytime to tell Python where 
to look, without having to add some sort of code to every program.  is this 
impression incorrect?  is there some code i need to add to the Python program 
call the modules in the bin dir?  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python module import failed error

2013-02-19 Thread Chris Angelico
On Wed, Feb 20, 2013 at 3:17 AM,  matt.doolittl...@gmail.com wrote:
 thats the file path.  the directory bin in my home directory.  in bash it 
 obviously looks like this  ~/bin using the file system folder the path is 
 home/Home/bin.  i have tried commands like, export 
 PYTHONPATH=${PYTHONPATH}:/users/matt/bin or home/matt/bin or Home/home/bin 
 and nothing has worked.

Change to that directory, then type 'pwd'. That'll tell you the actual
path. My guess would be /home/matt/bin - note the leading slash.

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


Re: Python module import failed error

2013-02-19 Thread matt . doolittle33
 My guess would be /home/matt/bin - note the leading slash.
 
 
 
 ChrisA

correct. and in the home directory i run export 
PYTHONPATH=${PYTHONPATH}:/home/matt/bin and have had no luck?  am i using the 
wrong command?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python module import failed error

2013-02-19 Thread Chris Angelico
On Wed, Feb 20, 2013 at 3:28 AM,  matt.doolittl...@gmail.com wrote:
  My guess would be /home/matt/bin - note the leading slash.



 ChrisA

 correct. and in the home directory i run export 
 PYTHONPATH=${PYTHONPATH}:/home/matt/bin and have had no luck?  am i using the 
 wrong command?

What exactly do you mean by no luck? More details would be good.

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


Re: Python module import failed error

2013-02-19 Thread Thomas Calmant
Hi,

Do you run Python in the same terminal than where you run the export
command ?

++
Thomas

2013/2/19 matt.doolittl...@gmail.com

  My guess would be /home/matt/bin - note the leading slash.
 
 
 
  ChrisA

 correct. and in the home directory i run export
 PYTHONPATH=${PYTHONPATH}:/home/matt/bin and have had no luck?  am i using
 the wrong command?
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Python module import failed error

2013-02-19 Thread Mark Lawrence

On 19/02/2013 16:28, matt.doolittl...@gmail.com wrote:

  My guess would be /home/matt/bin - note the leading slash.




ChrisA


correct. and in the home directory i run export 
PYTHONPATH=${PYTHONPATH}:/home/matt/bin and have had no luck?  am i using the 
wrong command?



What is PYTHONPATH actually set to?  You can find out by running python 
interactively, then


import os
os.environ['PYTHONPATH']

--
Cheers.

Mark Lawrence

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


Re: Python module import failed error

2013-02-19 Thread matt . doolittle33
On Tuesday, February 19, 2013 11:39:14 AM UTC-5, Chris Angelico wrote: 
 
 What exactly do you mean by no luck? More details would be good.
 

The program i am using (GNU radio companion) that wants to import the modules 
from the ~/bin folder shows this error:

Block - import_0_0_0 - Import(import):
  Param - Import(import):
Import import multimode_helper as mh failed.

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


Re: Python module import failed error

2013-02-19 Thread matt . doolittle33
On Tuesday, February 19, 2013 11:44:32 AM UTC-5, Thomas Calmant wrote:
 Hi,
 
 Do you run Python in the same terminal than where you run the export command ?
 

no i dont. the python program looking for the modules in the ~/bin directory is 
called GNU radio companion.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python module import failed error

2013-02-19 Thread matt . doolittle33
 
 What is PYTHONPATH actually set to?  You can find out by running python 
 
 interactively, then

i dont know.  how do i run pythoin interactively? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python module import failed error

2013-02-19 Thread matt . doolittle33
Does anyone know why i keep having these double posts?  please excuse them; i 
am a super newbie to this forum (and python obviously). 

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


Re: Awsome Python - chained exceptions

2013-02-19 Thread rusi
On Feb 19, 7:18 am, alex23 wuwe...@gmail.com wrote:
 On Feb 18, 3:51 pm, Rick Johnson rantingrickjohn...@gmail.com wrote:

  I apologize for this doubling of my messages and i can assure you i
  don't do this intentionally. Proper netiquette is very important to me.
  These double posts are another unfortunate side-effect of using the
  buggy Google Groups web-face to read/write Usenet. I've sent feedback
  to the Google Groups long ago and have yet to see any changes or even
  get any replys.

 Weird, I'm using GG too and not seeing any doubling of my messages. I
 have reverted to using the old interface, though, so it might be a
 side-effect of the new version they're hyping, which does seem to have
 been designed by Satan himself (the way they've separated thread view
 from article view is a huge WTF). I've sent a heap of feedback to them
 as well with no response. Google don't really seem to want to hype
 Usenet as anything other than a target for blogspot spam, it appears.

How do you revert to old interface?
So far I have managed to keep to the old by
- logging out of gmail
- reload GG -- now the choice to revert should appear

It seems everyone does not get that option
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python module import failed error

2013-02-19 Thread matt . doolittle33

 
 What is PYTHONPATH actually set to?  


OK so i ran python and then :

import sys
sys.path

bash returned:

['', '/home/matt', '/users/matt/bin', '/home/matt/bin', '/Home/bin', 
'/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', 
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', 
'/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', 
'/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', 
'/usr/lib/python2.7/dist-packages/gst-0.10', 
'/usr/lib/python2.7/dist-packages/gtk-2.0', 
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client', 
'/usr/lib/python2.7/dist-packages/ubuntuone-client', 
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', 
'/usr/lib/python2.7/dist-packages/ubuntuone-couch', 
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', 
'/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']

so the paths i have been adding are there.  should i be adding the python file 
names in the bin directory as well?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python module import failed error

2013-02-19 Thread Dave Angel

On 02/19/2013 11:57 AM, matt.doolittl...@gmail.com wrote:



What is PYTHONPATH actually set to?  You can find out by running python

interactively, then


i dont know.  how do i run pythoin interactively?



By typing the simple command  'python'
   davea@think2:~$ python
Python 2.7.3 (default, Aug  1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type help, copyright, credits or license for more information.



But since you're running some non-python program which is in turn 
launching python, perhaps you'd better give more details.  And not 
scattered over a half dozen tiny emails, but all at once.


Do you, in a single terminal, do the export, then run the 
gnuradiocompanion.py ?  And does the error message/stacktrace appear in 
the same terminal window?


Please show us just what you're running, from start to finish.  Thanks.

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


Re: Python module import failed error

2013-02-19 Thread Mark Lawrence

On 19/02/2013 16:57, matt.doolittl...@gmail.com wrote:



What is PYTHONPATH actually set to?  You can find out by running python

interactively, then


i dont know.  how do i run pythoin interactively?



Type python at a command prompt :)

--
Cheers.

Mark Lawrence

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


Re: Python module import failed error

2013-02-19 Thread matt . doolittle33
 
 
 gnuradiocompanion.py ?  And does the error message/stacktrace appear in 
 
 the same terminal window?
 


hi.  ok so i  am trying to run the python module (multimode_helper.py) in the 
GNU radio companion (GRC) which is sort of like an IDE which lets you organize 
code blocks by arranging them in a flow graph instead of having to write the 
code that would call the blocks in some particular order. GRC shows the import 
error in its flow graph error viewer:

Error 0:
Block - import_0_0_0 - Import(import):
  Param - Import(import):
Import import multimode_helper as mh failed.

The directory /home/matt/bin contains multimode_helper.py and this file path 
is in the PYTHONPATH.  I still get the import error however. so now that i know 
the file path is in PYTHONPATH but i am still getting the import error i am 
really confused here.

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


Re: improving performance of writing into a pipe

2013-02-19 Thread Michael Torrie
On 02/19/2013 02:24 AM, mikp...@gmail.com wrote:
 Or rather: what would you try to catch in this particular case?

As Peter said, nothing for now.  But you seem very resistant to telling
us what exception was raised.

Though looking at your code more closely I can see that likely the error
is related to the fact that /tmp/mypipe is not an executable program.
popen (which is deprecated and replaced by the subprocess module) is for
running programs and communicating with them over pipes created by the
popen function.  So your code is not likely to ever work as it is
presently given.

Here's the bash equivalent of your code:

$ mkfifo /tmp/path
$ cat /tmp/path 
$ echo hello, world | /tmp/path

Bash will say, bash: /tmp/path: Permission denied

The correct bash line is:
$ echo hello, world  /tmp/path

popen() (and subprocess) is the equivalent of the first bash command.
open() is the equivalent of the second line.

Do you understand the difference?

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


Double posts (was Re: Python module import failed error)

2013-02-19 Thread Lele Gaifax
matt.doolittl...@gmail.com writes:

 Does anyone know why i keep having these double posts?

That's because your posts carry the following headers:

  To: python-list@python.org
  Cc: python-list@python.org

or these (from a previous message):

  To: comp.lang.pyt...@googlegroups.com
  Cc: python-list@python.org

So it seems you are answering using Google Groups, *and* putting
“python-list@python.org” in the CC field. This “forum” has three heads,
one mirroring the others: whatever you send to one of the addresses is
automatically “copied” on the other sides, and viceversa; see also

  http://wiki.python.org/moin/GoogleGroupsPython

So, simply avoid adding an explicit CC field when you send your message/reply.

Hope this helps,
bye, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Ian Kelly
On Tue, Feb 19, 2013 at 7:46 AM, Tim Daneliuk tun...@tundraware.com wrote:
 Are you sure you wouldn't like to share with the class?  I'd be interested
 in seeing your approach...

Very well:

def collatz(n, memo):
if n not in memo:
if n % 2 == 0:
next_n = n // 2
else:
next_n = 3 * n + 1
memo[n] = collatz(next_n, memo) + 1
return memo[n]

def run_collatz(upper):
table = {1: 0}
max_n = max(range(1, upper), key=lambda n: collatz(n, table))
return max_n, table[max_n]

 run_collatz(100)
(837799, 524)

It could certainly be optimized further, but at about 4 seconds it's
already fast enough for most purposes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Double posts (was Re: Python module import failed error)

2013-02-19 Thread matt . doolittle33
Thanks Lele.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First attempt at a Python prog (Chess)

2013-02-19 Thread Ian Kelly
On Mon, Feb 18, 2013 at 9:15 PM, Tim Roberts t...@probo.com wrote:
 Chris Hinsley chris.hins...@gmail.com wrote:

Is a Python list as fast as a bytearray ?

 Python does not actually have a native array type.  Everything in your
 program that looked like an array was actually a list.

How do you mean?

 isinstance(bytearray(b'RNBQKBNR'), list)
False
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Serhiy Storchaka

On 19.02.13 20:31, Ian Kelly wrote:

On Tue, Feb 19, 2013 at 7:46 AM, Tim Daneliuk tun...@tundraware.com wrote:

Are you sure you wouldn't like to share with the class?  I'd be interested
in seeing your approach...


Very well:

def collatz(n, memo):
 if n not in memo:
 if n % 2 == 0:
 next_n = n // 2
 else:
 next_n = 3 * n + 1
 memo[n] = collatz(next_n, memo) + 1
 return memo[n]

def run_collatz(upper):
 table = {1: 0}
 max_n = max(range(1, upper), key=lambda n: collatz(n, table))
 return max_n, table[max_n]


run_collatz(100)

(837799, 524)

It could certainly be optimized further, but at about 4 seconds it's
already fast enough for most purposes.


10-15% faster:

def f(M):
def g(n, cache = {1: 0}):
if n in cache:
return cache[n]
if n % 2:
m = 3 * n + 1
else:
m = n // 2
cache[n] = count = g(m) + 1
return count
num = max(range(2, M + 1), key=g)
return num, g(num)

print(*f(100))


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


Verification of bank number using modulus 11

2013-02-19 Thread Morten Engvoldsen
Hi Team,
I am trying to verify the account number using the following algorithm:

The valid account number is 11 numeric digit without seperator. Eg.
8607947 is a valid account number. All banks apply a modulus-based
method for the validation of the account structure. The 10-digit account
number is multiplied from left to right by the following weights: 5, 4, 3,
2, 7, 6, 5, 4, 3, 2. The resulting numbers are added up and divided by 11.
The remainder is subtracted from 11 and becomes the check digit. If the
remainder is 0, the check digit will be 0. If digits 5 and 6 of the account
number are zeros, the check digit is calculated on the 7, 8, 9 and 10th
digit of the account number. Account numbers for which the remainder is 1
(check digit 10) cannot be used.

 I am trying to validate the Norway account number using the algorithm
mentioned in the following document:
http://www.cnb.cz/miranda2/export/sites/www.cnb.cz/cs/platebni_styk/iban/download/TR201.pdf

Here is my code:
 def calc_checkdigit(isbn):
isbn = isbn.replace(., )
check_digit = int(isbn[-1])
isbn = isbn[:-1]
if len(isbn) != 10:
   return False
result = sum((10 - i) * (int(x) if x != 'X' else 10) for i, x in
enumerate(isbn))
return (result % 11) == check_digit

calc_checkdigit(8601.11.17947)

In my program : it is calculating 10 digit with weights 10-1, but according
to above algorithm the weights should be : 5, 4, 3, 2, 7, 6, 5, 4, 3, 2.

Could you please let me know how can i calculate the 10 digit with weights
5, 4, 3, 2, 7, 6, 5, 4, 3, 2. I am using python 2.7.

Thanks in advance team for help..







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


backporting PEP 3134 Exception Chaining and Embedded Tracebacks to Python 2.7

2013-02-19 Thread Piotr Dobrogost
Hi!

What is a chance of backporting PEP 3134 Exception Chaining and Embedded 
Tracebacks to Python 2.7?


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


Re: backporting PEP 3134 Exception Chaining and Embedded Tracebacks to Python 2.7

2013-02-19 Thread Demian Brecht
Zero. There are no new features being added to 2.7.

Demian Brecht
http://demianbrecht.github.com




On 2013-02-19 12:54 PM, Piotr Dobrogost
p...@google-groups-2013.dobrogost.net wrote:

Hi!

What is a chance of backporting PEP 3134 Exception Chaining and Embedded
Tracebacks to Python 2.7?


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


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


Re: Verification of bank number using modulus 11

2013-02-19 Thread Dave Angel

On 02/19/2013 03:50 PM, Morten Engvoldsen wrote:

Hi Team,
I am trying to verify the account number using the following algorithm:

The valid account number is 11 numeric digit without seperator. Eg.
8607947 is a valid account number. All banks apply a modulus-based
method for the validation of the account structure. The 10-digit account
number is multiplied from left to right by the following weights: 5, 4, 3,
2, 7, 6, 5, 4, 3, 2. The resulting numbers are added up and divided by 11.
The remainder is subtracted from 11 and becomes the check digit. If the
remainder is 0, the check digit will be 0. If digits 5 and 6 of the account
number are zeros, the check digit is calculated on the 7, 8, 9 and 10th
digit of the account number. Account numbers for which the remainder is 1
(check digit 10) cannot be used.

  I am trying to validate the Norway account number using the algorithm
mentioned in the following document:
http://www.cnb.cz/miranda2/export/sites/www.cnb.cz/cs/platebni_styk/iban/download/TR201.pdf

Here is my code:
  def calc_checkdigit(isbn):
 isbn = isbn.replace(., )
 check_digit = int(isbn[-1])
 isbn = isbn[:-1]
 if len(isbn) != 10:
return False
 result = sum((10 - i) * (int(x) if x != 'X' else 10) for i, x in
enumerate(isbn))
 return (result % 11) == check_digit

calc_checkdigit(8601.11.17947)

In my program : it is calculating 10 digit with weights 10-1, but according
to above algorithm the weights should be : 5, 4, 3, 2, 7, 6, 5, 4, 3, 2.

Could you please let me know how can i calculate the 10 digit with weights
5, 4, 3, 2, 7, 6, 5, 4, 3, 2. I am using python 2.7.



Without analyzing your code, the direct answer to your code would be to 
make a table, something like:


weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]

and multiple by weights[i]  rather than (10-i)




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


Re: First attempt at a Python prog (Chess)

2013-02-19 Thread Neil Cerutti
On 2013-02-15, MRAB pyt...@mrabarnett.plus.com wrote:
 On 2013-02-15 16:17, Neil Cerutti wrote:
 On 2013-02-15, Oscar Benjamin oscar.j.benja...@gmail.com wrote:
 if score  best_score or best_score is None:

 You need the None check first to avoid an exception from the
 comparison.

 Only in Python 3.

It is a more difficult to find bug in Python 2, which will not
even throw an exception, but instead silently do the wrong thing.

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


Re: Verification of bank number using modulus 11

2013-02-19 Thread Ian Kelly
On Tue, Feb 19, 2013 at 1:50 PM, Morten Engvoldsen mortene...@gmail.com wrote:
 Here is my code:
  def calc_checkdigit(isbn):
 isbn = isbn.replace(., )
 check_digit = int(isbn[-1])
 isbn = isbn[:-1]
 if len(isbn) != 10:
return False
 result = sum((10 - i) * (int(x) if x != 'X' else 10) for i, x in
 enumerate(isbn))
 return (result % 11) == check_digit

 calc_checkdigit(8601.11.17947)

 In my program : it is calculating 10 digit with weights 10-1, but according
 to above algorithm the weights should be : 5, 4, 3, 2, 7, 6, 5, 4, 3, 2.

 Could you please let me know how can i calculate the 10 digit with weights
 5, 4, 3, 2, 7, 6, 5, 4, 3, 2. I am using python 2.7.

Use zip with the weight sequence instead of enumerate:

weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]
result = sum(w * (int(x) if x != 'X' else 10) for w, x in
zip(weights, isbn))

Do the account numbers actually use 'X', or is that just left over
from the ISBN algorithm?  If not, then you could replace (int(x) if x
!= 'X' else 10) with just int(x).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Verification of bank number using modulus 11

2013-02-19 Thread MRAB

On 2013-02-19 20:50, Morten Engvoldsen wrote:

Hi Team,
I am trying to verify the account number using the following algorithm:



The valid account number is 11 numeric digit without seperator. Eg.
8607947 is a valid account number. All banks apply a modulus-based
method for the validation of the account structure. The 10-digit account
number is multiplied from left to right by the following weights: 5, 4,
3, 2, 7, 6, 5, 4, 3, 2. The resulting numbers are added up and divided
by 11. The remainder is subtracted from 11 and becomes the check digit.
If the remainder is 0, the check digit will be 0. If digits 5 and 6 of
the account number are zeros, the check digit is calculated on the 7, 8,
9 and 10th digit of the account number. Account numbers for which the
remainder is 1 (check digit 10) cannot be used.



  I am trying to validate the Norway account number using the algorithm
mentioned in the following document:
http://www.cnb.cz/miranda2/export/sites/www.cnb.cz/cs/platebni_styk/iban/download/TR201.pdf

Here is my code:
  def calc_checkdigit(isbn):
 isbn = isbn.replace(., )
 check_digit = int(isbn[-1])
 isbn = isbn[:-1]
 if len(isbn) != 10:
return False
 result = sum((10 - i) * (int(x) if x != 'X' else 10) for i, x in 
enumerate(isbn))
 return (result % 11) == check_digit

calc_checkdigit(8601.11.17947)

In my program : it is calculating 10 digit with weights 10-1, but
according to above algorithm the weights should be : 5, 4, 3, 2, 7, 6,
5, 4, 3, 2.

Could you please let me know how can i calculate the 10 digit with
weights 5, 4, 3, 2, 7, 6, 5, 4, 3, 2. I am using python 2.7.

Thanks in advance team for help..


Put the weights into a list and use 'zip' instead of 'enumerate':

sum(w * (10 if d == 'X' else int(d)) for w, d in zip(weights, isbn))

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


Re: Python module import failed error

2013-02-19 Thread matt . doolittle33
Here is the PYTHONPATH

 import sys
 sys.path
['', '/home/matt', '/users/matt/bin', '/home/matt/bin', '/Home/bin', 
'/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', 
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', 
'/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', 
'/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', 
'/usr/lib/python2.7/dist-packages/gst-0.10', 
'/usr/lib/python2.7/dist-packages/gtk-2.0', 
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client', 
'/usr/lib/python2.7/dist-packages/ubuntuone-client', 
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', 
'/usr/lib/python2.7/dist-packages/ubuntuone-couch', 
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', 
'/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Chris Angelico
On Wed, Feb 20, 2013 at 7:28 AM, Serhiy Storchaka storch...@gmail.com wrote:
 10-15% faster:
 ... num = max(range(2, M + 1), key=g) ...

Yes, but 20-30% less clear and readable. Though I do like the idea of
playing this code in the key of G Major.

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


Re: Python module import failed error

2013-02-19 Thread Chris Angelico
On Wed, Feb 20, 2013 at 4:45 AM,  matt.doolittl...@gmail.com wrote:
 The directory /home/matt/bin contains multimode_helper.py and this file 
 path is in the PYTHONPATH.  I still get the import error however. so now that 
 i know the file path is in PYTHONPATH but i am still getting the import error 
 i am really confused here.

Do you understand how Unix environment variables work? You're using
the 'export' command, but that doesn't make any sort of global change
- it still applies only to things done in the same session. (Actually,
your change applies only to children of the shell where you do it...
but never mind that now.) You may do better by putting the export
command into your .bashrc - that would apply to all sessions created
by your user.

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


Is there a graphical GUI builder?

2013-02-19 Thread Rex Macey
I'm new to Python and only a hobbyist programmer.  A long time ago I used 
Microsoft's Visual Basic which had a nice (graphical) facility for creating 
GUIs which was part of the development environment.  I'm wondering if there's a 
utility for Python to build GUIs.  I see that there is TKinter, which is a 
scripting function to build GUIs. To be clear, I'm looking for a graphical 
interface to build GUIs. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a graphical GUI builder?

2013-02-19 Thread Mark Lawrence

On 19/02/2013 22:19, Rex Macey wrote:

I'm new to Python and only a hobbyist programmer.  A long time ago I used 
Microsoft's Visual Basic which had a nice (graphical) facility for creating 
GUIs which was part of the development environment.  I'm wondering if there's a 
utility for Python to build GUIs.  I see that there is TKinter, which is a 
scripting function to build GUIs. To be clear, I'm looking for a graphical 
interface to build GUIs. Thanks.



Try typing python gui builder into your favourite search engine.  If 
you're lucky you might find something, if not you'll have to write your 
own or do without.


--
Cheers.

Mark Lawrence

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


Re: Is there a graphical GUI builder?

2013-02-19 Thread Ian Kelly
On Tue, Feb 19, 2013 at 3:19 PM, Rex Macey xer0...@gmail.com wrote:
 I'm new to Python and only a hobbyist programmer.  A long time ago I used 
 Microsoft's Visual Basic which had a nice (graphical) facility for creating 
 GUIs which was part of the development environment.  I'm wondering if there's 
 a utility for Python to build GUIs.  I see that there is TKinter, which is a 
 scripting function to build GUIs. To be clear, I'm looking for a graphical 
 interface to build GUIs. Thanks.

wxFormBuilder seems to be popular and works with wxPython.  Beyond
that, you might also take a look at the GUI Design Tools and IDEs
list at:

http://wiki.python.org/moin/GuiProgramming
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a graphical GUI builder?

2013-02-19 Thread Chris Angelico
On Wed, Feb 20, 2013 at 9:19 AM, Rex Macey xer0...@gmail.com wrote:
 I'm new to Python and only a hobbyist programmer.  A long time ago I used 
 Microsoft's Visual Basic which had a nice (graphical) facility for creating 
 GUIs which was part of the development environment.  I'm wondering if there's 
 a utility for Python to build GUIs.  I see that there is TKinter, which is a 
 scripting function to build GUIs. To be clear, I'm looking for a graphical 
 interface to build GUIs. Thanks.

That way of building a window tends to produce programs that port
badly to other systems. Back in the 1990s, I used to build windows
that way (mainly using VX-REXX); playing with Java applets introduced
the novel and somewhat strange idea that your window should be built
using rules and layouts, to avoid problems with button sizes, fonts,
etc, etc. Today, cross-platform code is the norm, not a curiosity, so
this method of building up a window is correspondingly more plausible.
I strongly recommend it.

You have to think about your window differently - think about what
you're putting where, rather than going visually that looks about
right - but the reward is that it'll look right no matter where you
run your app. As an added bonus, you don't need any sort of graphical
builder; you can just write code directly in your editor.

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


Re: Is there a graphical GUI builder?

2013-02-19 Thread Phil

On 20/02/13 08:19, Rex Macey wrote:

I'm new to Python and only a hobbyist programmer.  A long time ago I used 
Microsoft's Visual Basic which had a nice (graphical) facility for creating 
GUIs which was part of the development environment.  I'm wondering if there's a 
utility for Python to build GUIs.  I see that there is TKinter, which is a 
scripting function to build GUIs. To be clear, I'm looking for a graphical 
interface to build GUIs. Thanks.



I'm new to Python myself and the best IDE that I've found is Eric.

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


Re: Verification of bank number using modulus 11

2013-02-19 Thread Morten Engvoldsen
Hi Team,
Thanks for the code.
 I have altered the code with below code, it is able to validate the number
now,

def calc_checkdigit(isbn):
isbn = isbn.replace(., )
check_digit = int(isbn[-1])
isbn = isbn[:-1]
if len(isbn) != 10:
  return False
weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]
result = sum(w * (int(x)) for w, x in zip(weights, isbn))
remainder = result % 11
if remainder == 0:
   check = 0
else:
   check = 11 - remainder
return check == check_digit

calc_checkdigit(8601.11.**17947)


But can you tell me how could i implement below

If digits 5 and 6 of the account number are zeros, the check digit is
calculated on the 7, 8, 9 and 10th digit of the account number.

which means if account number is 8601.00.**17947 then check digit is
calculate as

 result = (1*5) + (7*4)+ (9*3)+(4*2)

remainder = result % 11

check_digit = 11 - remainder

Can you tell me how can i implement this ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Verification of bank number using modulus 11

2013-02-19 Thread Ian Kelly
On Tue, Feb 19, 2013 at 3:59 PM, Morten Engvoldsen mortene...@gmail.com wrote:
 But can you tell me how could i implement below

 If digits 5 and 6 of the account number are zeros, the check digit is
 calculated on the 7, 8, 9 and 10th digit of the account number.

 which means if account number is 8601.00.17947 then check digit is
 calculate as

  result = (1*5) + (7*4)+ (9*3)+(4*2)

 remainder = result % 11

 check_digit = 11 - remainder

 Can you tell me how can i implement this ?

After this code:

isbn = isbn[:-1]
if len(isbn) != 10:
  return False

Add:

if isbn[4:6] == 00:
isbn = isbn[6:]

And that should do it.  Thanks to the symmetry of the weights
sequence, you don't even need to change that part at all.  The zip
function will automatically truncate to the length of the shorter
input sequence.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a graphical GUI builder?

2013-02-19 Thread Miki Tebeka
 I'm wondering if there's a utility for Python to build GUIs.
IIRC the Qt builder can generate Python code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Import Json web data source to xls or csv

2013-02-19 Thread io
Hi,

i'm new to python and programming with it and so for json format.
I have my excel 2010 program with vba that does the following :

- read the data flow from http://bitcoincharts.com/t/markets.json
- elaborate it and puts it in excel 2010 for further calculations

What i'm willing to do is the same using Linux (xubuntu) and libreoffice.

I thought learning python would be a smart idea for dealing with json 
format as it has a json library/module.

How do i manage to read the data source from http://bitcoincharts.com/t/
markets.json  and then place it in different cell of a new or existing 
xls worksheet?

I'm trying some code with SPE but i can't sort the problem and i'm 
receiving many errors.

I just need currency, symbol, bid, ask, volume
This is the source code i was trying to use :


import json
import csv
import urllib

url = http://bitcoincharts.com/t/markets.json;
response = urllib.urlopen(url);
data = json.loads(response.read())

f = csv.writer(open('file.csv', 'wb+'))
# use encode to convert non-ASCII characters
for item in data:
values = [ x.encode('utf8') for x in item['0'].values() ]
f.writerow([item['currency'], item['high']] + values)



Thanks for any help :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simulation of human body in movement

2013-02-19 Thread Nick Mellor
LOL thanks Rick,

I'm a movement teacher and want to demonstrate how head balance affects the 
rest of the body. I want to do something simple to start with, probably with 
blocks, hinges and springs.

Ideally I'd like the simulation to be an interactive, real-time element on a 
web page. By moving the mouse or pressing keys the user can subtly move the 
head element and watch how the rest of the body (or set of blocks) needs to 
adapt to keep balance.

I'm investigating Arboris and the Python Computer Graphics Kit.

http://cgkit.sourceforge.net/

http://pypi.python.org/pypi/arboris/0.1.0pre7

Arboris is a rigid body dynamics and contacts simulator written in python.

[snip]

Arboris is mostly useful for robotic applications and human motion studies. The 
python language makes it particularly suited for fast-paced development 
(prototyping) and education.

On Tuesday, 19 February 2013 06:25:50 UTC+11, Rick Johnson  wrote:
 Nick Mellor thebalancepro at gmail.com writes:
 
 
 
  I'm looking for a fairly undetailed simulation of the human body walking and
 
 standing. Has anyone had a go at
 
  this in cgkit or similar?
 
 
 
 Hi nick, your question contains too many variables to provide a proper 
 response.
 
 It would equivalent to asking:
 
 
 
  I need a fairly ubiquitous automobile that can drive and park
 
 
 
 Okay, but what do you intent to use the automobile /for/? 
 
 
 
 If you will be transporting many people on a sleazy tour of overpriced 
 Hollywood
 
 stars' extravagant homes you would probably need a large bus, or if you were
 
 going to help your bum of a brother-in-law move out of the apartment he cannot
 
 afford anymore (and unfortunately into your spare bedroom!) then you may want 
 a
 
 pick-up truck, if however you are going to see your grandma on her deathbed 
 and
 
 the hospital is 2000 miles away, and your absolutely phobic about flying, and
 
 you're on a crusade to save the environment, then you might want a prius! 
 
 
 
 The point is: just as there are many types of specialized automobiles for
 
 specialized purposes there are also many cgkits for specialized purposes. 
 Are
 
 you wanting to write code that is close to the metal like OpenGL; which 
 offers
 
 more control and almost unlimited extensibility, or are you looking for
 
 something very high level, like VPython; which is easy to use but quite 
 limiting.
 
 
 
 You also were vague about the Level-Of-Detail. You mentioned fairly 
 undetailed
 
 -- does that mean stick figures (composed of simple lines) or marionettes;
 
 composed of geometric primitives (say cylinders)? Or something more?
 
 
 
 And what about the LOD of the hinged joints? Are we talking only articulating
 
 hips (goose stepping)? What about shoulders, elbows and wrist; knees and 
 ankles
 
 and toes? Perhaps something more, perhaps less?
 
 
 
 But then again you used the word simulation so i am beginning to think you
 
 don't want to actually code the walk loop for specific purposed, you merely 
 wish
 
 to attain a pre-coded simulation? Then why not use a motion-capture like 
 Juhani
 
 suggested? 
 
 
 
 You supply the What Where When and Why and we'll supply the How.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Alexander Blinne
Am 19.02.2013 12:42, schrieb Piet van Oostrum:
 Terry Reedy tjre...@udel.edu writes:
 I find this surprising too. I am also surprised that it even works,
 given that the highest intermediate value is about 57 billion and I do
 not remember that Basic had infinite precision ints.
 
 That may explain why the Basic version is faster: it gets overflow and
 then it may have taken some shortcuts.

Consider this C program

#include stdio.h

int main(void) {

  int max = 0;
  int m = 0;
  long int n;
  int count;
  int num;

  while(m=100) {
m++;
n = m;
count = 0;

while(n != 1) {
  count++;
  if(n % 2 == 0) {
n = n / 2;
  }
  else {
n = n*3 + 1;
  }
}

if(count  max) {
  max = count;
  num = m;
}
  }

  printf(%d, %d\n, num, max);
}

If the line

long int n;

is changed into

unsigned int n;

the program runs in 0.68 sec instead of 0.79, so there is some shortcut.
If changed into

signed int n;

there is a veeery long, perhaps infinite loop.

Greetings
Alexander

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


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Ian Kelly
On Tue, Feb 19, 2013 at 5:23 PM, Alexander Blinne n...@blinne.net wrote:
 If changed into

 signed int n;

 there is a veeery long, perhaps infinite loop.

Yes, infinite.  Here's the first such sequence encountered with a
signed 32-bit int.

[113383, 340150, 170075, 510226, 255113, 765340, 382670, 191335,
574006, 287003, 861010, 430505, 1291516, 645758, 322879, 968638,
484319, 1452958, 726479, 2179438, 1089719, 3269158, 1634579, 4903738,
2451869, 7355608, 3677804, 1838902, 919451, 2758354, 1379177, 4137532,
2068766, 1034383, 3103150, 1551575, 4654726, 2327363, 6982090,
3491045, 10473136, 5236568, 2618284, 1309142, 654571, 1963714, 981857,
2945572, 1472786, 736393, 2209180, 1104590, 552295, 1656886, 828443,
2485330, 1242665, 3727996, 1863998, 931999, 2795998, 1397999, 4193998,
2096999, 6290998, 3145499, 9436498, 4718249, 14154748, 7077374,
3538687, 10616062, 5308031, 15924094, 7962047, 23886142, 11943071,
35829214, 17914607, 53743822, 26871911, 80615734, 40307867, 120923602,
60461801, 181385404, 90692702, 45346351, 136039054, 68019527,
204058582, 102029291, 306087874, 153043937, 459131812, 229565906,
114782953, 344348860, 172174430, 86087215, 258261646, 129130823,
387392470, 193696235, 581088706, 290544353, 871633060, 435816530,
217908265, 653724796, 326862398, 163431199, 490293598, 245146799,
735440398, 367720199, 1103160598, 551580299, 1654740898, 827370449,
-1812855948, -906427974, -453213987, -1359641960, -679820980,
-339910490, -169955245, -509865734, -254932867, -764798600,
-382399300, -191199650, -95599825, -286799474, -143399737, -430199210,
-215099605, -645298814, -322649407, -967948220, -483974110,
-241987055, -725961164, -362980582, -181490291, -544470872,
-272235436, -136117718, -68058859, -204176576, -102088288, -51044144,
-25522072, -12761036, -6380518, -3190259, -9570776, -4785388,
-2392694, -1196347, -3589040, -1794520, -897260, -448630, -224315,
-672944, -336472, -168236, -84118, -42059, -126176, -63088, -31544,
-15772, -7886, -3943, -11828, -5914, -2957, -8870, -4435, -13304,
-6652, -3326, -1663, -4988, -2494, -1247, -3740, -1870, -935, -2804,
-1402, -701, -2102, -1051, -3152, -1576, -788, -394, -197, -590, -295,
-884, -442, -221, -662, -331, -992, -496, -248, -124, -62, -31, -92,
-46, -23, -68, -34, -17, -50, -25, -74, -37, -110, -55, -164, -82,
-41, -122, -61, -182, -91, -272, -136, -68, ...]
-- 
http://mail.python.org/mailman/listinfo/python-list


encoding error

2013-02-19 Thread halagamal2009
i'm trying to make indexing of csv file contain arabic words
my code:
from whoosh import fields, index
import os.path
import csv
import codecs
# This list associates a name with each position in a row
columns = [juza,chapter,verse,voc,analysis, unvoc,root]

schema = fields.Schema(juza=fields.NUMERIC,
   chapter=fields.NUMERIC,
   verse=fields.NUMERIC,
   voc=fields.TEXT,
   analysis=fields.KEYWORD,
   unvoc=fields.TEXT,
   root=fields.TEXT)


# Create the Whoosh index
indexname = index
if not os.path.exists(indexname):
  os.mkdir(indexname)
ix = index.create_in(indexname, schema)

# Open a writer for the index
with ix.writer() as writer:
  # Open the CSV file
  fi = codecs.open('q.csv', 'rb','utf8') 
  data = fi.read() 
  fi.close() 
  f= codecs.open('mynew.csv', 'wb','utf-8') 
  f.write(data.replace('\x00', '')) 
  f.close() 
  with codecs.open(mynew.csv, rb,utf8) as csvfile:
# Create a csv reader object for the file
csvreader = csv.reader(csvfile)
  with codecs.open(q.csv, r,utf8) as csvfile:
# Create a csv reader object for the file
csvreader = csvfile.read()

# Read each row in the file
for row in csvreader:

  # Create a dictionary to hold the document values for this row
  doc = {}

  # Read the values for the row enumerated like
  # (0, name), (1, quantity), etc.
  for colnum, value in enumerate(row):

# Get the field name from the columns list
fieldname = columns[colnum]

# Strip any whitespace and convert to unicode
# NOTE: you need to pass the right encoding here!
try:
value = unicode(value.strip(), utf8)
except TypeError:
 value=value.strip()
# Put the value in the dictionary
doc[fieldname] = value

  # Pass the dictionary to the add_document method
  writer.add_document(**doc)
and i got this error:
raceback (most recent call last):
  File D:/Python27/rr.py, line 62, in module
writer.add_document(**doc)
  File D:/Python27\whoosh\filedb\filewriting.py, line 369, in add_document
items = field.index(value)
  File D:/Python27\whoosh\fields.py, line 466, in index
return [(txt, 1, 1.0, '') for txt in self._tiers(num)]
  File D:/Python27\whoosh\fields.py, line 454, in _tiers
yield self.to_text(num, shift=shift)
  File D:/Python27\whoosh\fields.py, line 487, in to_text
return self._to_text(self.prepare_number(x), shift=shift,
  File D:/Python27\whoosh\fields.py, line 476, in prepare_number
x = self.type(x)
UnicodeEncodeError: 'decimal' codec can't encode character u'\ufeff' in 
position 0: invalid decimal Unicode string

my file is here: http://www.mediafire.com/view/?wy3asap4ba7dknl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import Json web data source to xls or csv

2013-02-19 Thread Michael Herman
First - you can use Python in Excel. http://www.python-excel.org/ or
https://www.datanitro.com/

Updated code:

import json
import urllib
import csv

url = http://bitcoincharts.com/t/markets.json;
response = urllib.urlopen(url);
data = json.loads(response.read())

f = open(bitcoin.csv,wb)
c = csv.writer(f)

# write headers
c.writerow([Currency,Symbol,Bid, Ask, Volume])


for d in data:

c.writerow([str(d[currency]),str(d[symbol]),str(d[bid]),str(d[ask]),str(d[currency_volume])])



On Tue, Feb 19, 2013 at 3:48 PM, io mar...@libero.it wrote:

 Hi,

 i'm new to python and programming with it and so for json format.
 I have my excel 2010 program with vba that does the following :

 - read the data flow from http://bitcoincharts.com/t/markets.json
 - elaborate it and puts it in excel 2010 for further calculations

 What i'm willing to do is the same using Linux (xubuntu) and libreoffice.

 I thought learning python would be a smart idea for dealing with json
 format as it has a json library/module.

 How do i manage to read the data source from http://bitcoincharts.com/t/
 markets.json  and then place it in different cell of a new or existing
 xls worksheet?

 I'm trying some code with SPE but i can't sort the problem and i'm
 receiving many errors.

 I just need currency, symbol, bid, ask, volume
 This is the source code i was trying to use :


 import json
 import csv
 import urllib

 url = http://bitcoincharts.com/t/markets.json;
 response = urllib.urlopen(url);
 data = json.loads(response.read())

 f = csv.writer(open('file.csv', 'wb+'))
 # use encode to convert non-ASCII characters
 for item in data:
 values = [ x.encode('utf8') for x in item['0'].values() ]
 f.writerow([item['currency'], item['high']] + values)



 Thanks for any help :-)
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Is there a graphical GUI builder?

2013-02-19 Thread duncan smith

On 19/02/13 22:19, Rex Macey wrote:

I'm new to Python and only a hobbyist programmer.  A long time ago I used 
Microsoft's Visual Basic which had a nice (graphical) facility for creating 
GUIs which was part of the development environment.  I'm wondering if there's a 
utility for Python to build GUIs.  I see that there is TKinter, which is a 
scripting function to build GUIs. To be clear, I'm looking for a graphical 
interface to build GUIs. Thanks.



Boa Constructor perhaps (http://boa-constructor.sourceforge.net/).

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


Re: Is there a graphical GUI builder?

2013-02-19 Thread Roland Koebler
Hi,

 I'm new to Python and only a hobbyist programmer.  A long time ago I used 
 Microsoft's Visual Basic which had a nice (graphical) facility for creating 
 GUIs which was part of the development environment.  I'm wondering if there's 
 a utility for Python to build GUIs.
yes, there are several, depending on the GUI-toolkit (GTK+, Qt, ...)
you want to use.

But I would recommend Glade and the GTK+-Toolkit. Simply search
for Glade, GTK and Python in your favourite search engine, and you
will find several tutorials.

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


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread workshed
On Tuesday, February 19, 2013 3:28:25 PM UTC-5, Serhiy Storchaka wrote:
 10-15% faster:


 def f(M):
  def g(n, cache = {1: 0}):
  if n in cache:
  return cache[n]
  if n % 2:
  m = 3 * n + 1
  else:
  m = n // 2
  cache[n] = count = g(m) + 1
  return count
  num = max(range(2, M + 1), key=g)
  return num, g(num)

 print(*f(100))

I managed another 15-20% (on my machine) with a different caching scheme.

def g(n):
cache = [1,1] + [0]*(n - 2)
longest = 0
for x in range(1, n):
num = 0
y = x
while True:
if x  n and cache[x]:
cache[y] = num + cache[x]
break
if x1:
x = (3*x + 1)//2#Credit to Terry
num += 2
else:
x = x//2
num += 1
ans = cache.index(max(cache))
return ans, cache[ans] - 1

Python 3.2.3 (default, Oct 19 2012, 19:53:57)
[GCC 4.7.2] on linux2
Type help, copyright, credits or license for more information.
 import timeit
 timeit.Timer('euler014.f(10**6)', 'import euler014').timeit(10)
16.590431928634644
 timeit.Timer('euler014.f(10**7)', 'import euler014').timeit(1)
17.689634084701538
 timeit.Timer('euler014.g(10**6)', 'import euler014').timeit(10)
13.558412790298462
 timeit.Timer('euler014.g(10**7)', 'import euler014').timeit(1)
14.075398921966553

In this code only entries less than n (100 in the project Euler problem)
are cached, and only one is cached per run of the inner loop, which to
me would seem to me much less efficient. I supposed the advantages are no
overhead from dict lookups, function calls, or recursion, plus it uses Terry
Reedy's nice observation that one can take two steps at a time for odd
values. I would think my version uses less memory as well, since the cache
dict/list would be maximally dense for indices less than n in either scheme.

I'm still surprised that both algorithm's seem pretty much O(n) tho.
Intuitively I'd have thought mine would start to lose out with larger
numbers, given the much lower degree of caching.

With PyPy the results are more striking:

Python 2.7.2 (1.9+dfsg-1, Jun 19 2012, 23:23:45)
[PyPy 1.9.0 with GCC 4.7.0] on linux2
Type help, copyright, credits or license for more information.
And now for something completely different: ``Is rigobot around when the
universe ceases to exist?''
 import timeit
 timeit.Timer('euler014.f(10**6)', 'import euler014').timeit(10)
26.138880014419556
 timeit.Timer('euler014.g(10**6)', 'import euler014').timeit(10)
1.5725858211517334

I guess PyPy can JIT the iterative loop more effectively than it can the
recursion.

This is my first post on this list btw, please let me know if I screwed
anything up.

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


Python problem

2013-02-19 Thread ach360
I'm so lost. Given the formula pi=4-4/3+4/5-4/7+4/9-4/11+.. How do I print 
a table showing approximate value of pi by computing one term4-4/3 then two 
terms4-4/3+4/5, and so on.Then how many terms of the series before I get 3.14, 
3.141, 3.1415, 3.14159. Please helps computer teacher literally says figure it 
out and doesn't help and expects a perfect program.this is in python 3 please 
give an answer I can understand and an example. 
Thanks :) :) 
I need this right now. 
Thanks for your time.

I need this ASAP
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Differences creating tuples and collections.namedtuples

2013-02-19 Thread Terry Reedy

On 2/18/2013 7:18 PM, Steven D'Aprano wrote:

Terry Reedy wrote:


On 2/18/2013 6:47 AM, John Reid wrote:


I was hoping namedtuples could be used as replacements for tuples
 in all instances.


This is a mistake in the following two senses. First, tuple is a class
with instances while namedtuple is a class factory that produces
classes. (One could think of namedtuple as a metaclass, but it was not
implemented that way.)



I think you have misunderstood.


Wrong, which should be evident to anyone who reads the entire paragraph 
as the complete thought exposition it was meant to be. Beside which, 
this negative ad hominem comment is irrelevant to the rest of your post 
about the Liskov Substitution Principle.


The rest of the paragraph, in two more pieces:


Second, a tuple instance can have any length and
different instances can have different lengths. On the other hand, all
instances of a particular namedtuple class have a fixed length.


In other words, neither the namedtuple object nor any namedtuple class 
object can fully substitute for the tuple class object. Nor can 
instances of any namedtuple class fully substitute for instances of the 
tuple class. Therefore, I claim, the hope that namedtuples could be 
used as replacements for tuples in all instances is a futile hope, 
however one interprets that hope.


 This affects their initialization.

Part of the effect is independent of initialization. Even if namedtuples 
were initialized by iterator, there would still be glitches. In 
particular, even if John's named tuple class B *could* be initialized as 
B((1,2,3)), it still could not be substituted for t in the code below.


 t = (1,2,3)
 type(t) is type(t[1:])
True
 type(t)(t[1:])
(2, 3)

As far as read access goes, B effectively is a tuple. As soon as one 
uses type() directly or indirectly (by creating new objects), there may 
be problems. That is because the addition of field names *also* adds a 
length constraint, which is a subtraction of flexibility.


---
Liskov Substitution Principle (LSP): I met this over 15 years ago 
reading debates among OOP enthusiasts about whether Rectangle should be 
a subclass of Square or Square a subclass of Rectangle, and similarly, 
whether Ostrich can be a legitimate subclass of Bird.


The problem I see with the LSP for modeling either abstract or concrete 
entities is that we in fact do define subclasses by subtraction or 
limitation, as well as by augmentation, while the LSP only allows the 
latter.


On answer to the conundrums above to to add Parallelepiped as a 
superclass for both Square and Rectangle and Flying_bird as an 
additional subclass of Bird. But then the question becomes: Does obeying 
the LSP count as 'necessity' when one is trying to follow Ockham's 
principle of not multiplying classes without necessity?


--
Terry Jan Reedy

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


Re: Is there a graphical GUI builder?

2013-02-19 Thread Michael Torrie
On 02/19/2013 07:53 PM, Roland Koebler wrote:
 Hi,
 
 I'm new to Python and only a hobbyist programmer.  A long time ago
 I used Microsoft's Visual Basic which had a nice (graphical)
 facility for creating GUIs which was part of the development
 environment.  I'm wondering if there's a utility for Python to
 build GUIs.
 yes, there are several, depending on the GUI-toolkit (GTK+, Qt, ...) 
 you want to use.
 
 But I would recommend Glade and the GTK+-Toolkit. Simply search for
 Glade, GTK and Python in your favourite search engine, and you will
 find several tutorials.

I agree that on Linux GTK is pretty darn slick.  I use it for all my
little GUIs.  But on Windows, GTK, particularly under python, isn't
quite as easy to get running.  Just be forewarned.  Doesn't seem to me
that GTK on windows is being developed at the same pace as it is on Linux.

I think if the OP is on windows (which it seems like he is) then Qt with
PySide (using either QML or QtDesigner to manipulate ui files) is an
excellent choice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python problem

2013-02-19 Thread Steven D'Aprano
On Tue, 19 Feb 2013 19:01:53 -0800, ach360 wrote:

 I'm so lost. Given the formula pi=4-4/3+4/5-4/7+4/9-4/11+.. How do I
 print a table showing approximate value of pi by computing one term4-4/3
 then two terms4-4/3+4/5, and so on.Then how many terms of the series
 before I get 3.14, 3.141, 3.1415, 3.14159. Please helps computer teacher
 literally says figure it out and doesn't help and expects a perfect
 program.this is in python 3 please give an answer I can understand and
 an example. Thanks :) :)

First, you need to know what the formula for pi actually is. You can find 
that by googling, or look it up in a maths book. You should expect 
something like

pi = sum from i=0 to infinity of 4 divided by (something)


Then you want a program to print a table that looks something like this:

i   value
0   x
1   x
2   x


etc., where the x will get filled in later, and the table stops at 
a certain maximum value of i. Here is a hint:


for i in range(100):
x = calculate something
print(%d   %s % (i, x)


Does that get you started? Try writing some code and see how far you get.


Good luck!




 I need this right now.
 Thanks for your time.
 
 I need this ASAP

Then you better get started straight away then. Turn off Facebook and 
Twitter and do some real work.


-- 
Steven

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


Re: Python problem

2013-02-19 Thread ach360
Loop_variable= 1
Pi=1.0
term=0
T=1.0
While (loop_variable 0):
 Loop_variable=Loop_variable+1
 T=T+2.0
 
If (loop_variable%2 ==0):
 Term=0;
Else:
  term=1;


If term  ==0:
 Pi=Pi- float(1/T);
Else:
   Pi=Pi+ float(1/T);


 

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


Re: Python 3.3 vs. MSDOS Basic

2013-02-19 Thread Gregory Ewing

Chris Angelico wrote:

On Wed, Feb 20, 2013 at 7:28 AM, Serhiy Storchaka storch...@gmail.com wrote:


10-15% faster:
... num = max(range(2, M + 1), key=g) ...


Yes, but 20-30% less clear and readable. Though I do like the idea of
playing this code in the key of G Major.


On the SmartStupid, presumably.

http://wordsmith.org/board/ubbthreads.php?ubb=showflatNumber=101906

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


  1   2   3   >