Re: Import order question

2014-02-19 Thread Chris Angelico
On Wed, Feb 19, 2014 at 6:32 PM, Steven D'Aprano  wrote:
> On Tue, 18 Feb 2014 13:44:47 -0800, Rick Johnson wrote:
>
>> Are you telling me you're willing to search through a single file
>> containing 3,734 lines of code (yes, Tkinter) ...
>
> For a mere 4000 lines of code, yes, I'd rather have it all in the one
> file, presuming that they are all related pieces of code.

If Tkinter were horribly unreadable, I would figure it as being
because of the multiple languages involved. But I just pulled up
tkinter/__init__.py to try to find OptionMenu, and it's 35 lines of
easy-to-read code. And there's a destroy method. Not at all hard to
find.

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


Re: Turning an AST node / subnodes into something human-readable

2014-02-19 Thread Irmen de Jong
On 19-2-2014 4:58, Chris Angelico wrote:

> but what I'd really like to do is get something that looks
> approximately like "x[1]". Is there an easy way to do that? Its str
> and repr aren't useful, and I can't see a "reconstitute" method on the
> node, nor a function in ast itself for the job. In theory I could
> write one, but it'd need to understand every node type, so it seems
> the most logical place would be on the node itself - maybe in __str__.
> 
> Is there anything nice and easy? I don't care if it's not perfect, as
> long as it's more readable than ast.dump(). :)
> 

Maybe this https://pypi.python.org/pypi/astor can do what you want?
(found it by following a few links starting from
http://stackoverflow.com/questions/768634/python-parse-a-py-file-read-the-ast-modify-it-then-write-back-the-modified)

Irmen
-- 
https://mail.python.org/mailman/listinfo/python-list


SSH/Telnet program to Router/switch

2014-02-19 Thread Sujith S
Hi,

I am new to programming and python. I am looking for a python script to do 
ssh/telnet to a network equipment ? I know tcl/perl does this using 
expect/send. 

Do we have expect available in python as well or need to use some other method ?

Regards
Sujith
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Turning an AST node / subnodes into something human-readable

2014-02-19 Thread Chris Angelico
On Wed, Feb 19, 2014 at 7:05 PM, Irmen de Jong  wrote:
> On 19-2-2014 4:58, Chris Angelico wrote:
>
>> but what I'd really like to do is get something that looks
>> approximately like "x[1]". Is there an easy way to do that? Its str
>> and repr aren't useful, and I can't see a "reconstitute" method on the
>> node, nor a function in ast itself for the job. In theory I could
>> write one, but it'd need to understand every node type, so it seems
>> the most logical place would be on the node itself - maybe in __str__.
>>
>> Is there anything nice and easy? I don't care if it's not perfect, as
>> long as it's more readable than ast.dump(). :)
>>
>
> Maybe this https://pypi.python.org/pypi/astor can do what you want?
> (found it by following a few links starting from
> http://stackoverflow.com/questions/768634/python-parse-a-py-file-read-the-ast-modify-it-then-write-back-the-modified)
>

Hmm. I saw a few (things like codegen), but was hoping to stick to the
standard library - introducing a dependency in a small script just for
the sake of tidy output is a bit messy. Oh well. Some things just
aren't as ideal as I'd like. Thanks Irmen!

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


Re: SSH/Telnet program to Router/switch

2014-02-19 Thread Chris Angelico
On Wed, Feb 19, 2014 at 7:14 PM, Sujith S  wrote:
> Hi,
>
> I am new to programming and python. I am looking for a python script to do 
> ssh/telnet to a network equipment ? I know tcl/perl does this using 
> expect/send.
>
> Do we have expect available in python as well or need to use some other 
> method ?
>

Yep! Look up the socket module. Straight-forward TCP sockets are
usually easy enough to work.

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


Re: SSH/Telnet program to Router/switch

2014-02-19 Thread Wojciech Łysiak
On 19.02.2014 09:14, Sujith S wrote:
> Hi,
> 
> I am new to programming and python. I am looking for a python script to do 
> ssh/telnet to a network equipment ? I know tcl/perl does this using 
> expect/send. 
> 
> Do we have expect available in python as well or need to use some other 
> method ?

Hello,
 If you are looking for a way to connect to your netdevices and then
execute some shell commands (with output) via ssh then google for
paramiko module for python.

It works on windows and linux.

-- 
BR,
Wojtek
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: a question about list as an element in a tuple

2014-02-19 Thread Marko Rauhamaa
John O'Hagan :

> The weirdest part for me is this:
>
 t = ([],)
 l = t[0]
 l is t[0]
> True
 l += [1]
 t[0] += [1]
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: 'tuple' object does not support item assignment
>
> Whether there is an error or not depends on the name used for the
> object!

Nice catch! The += operator rebinds the reference even if the object
wouldn't change:

   >>> t = 1,
   >>> t[0] = t[0]
   Traceback (most recent call last):
 File "", line 1, in 
   TypeError: 'tuple' object does not support item assignment

See also:

   >>> a = []
   >>> b = a
   >>> a = a + [1]
   >>> a is b
   False
   >>> a = []
   >>> b = a
   >>> a += [1]
   >>> a is b
   True

This behavior is not a bug, though. http://docs.python.org/3.2/library/operator.html#inplace-operators>:

  for example, the statement x += y is equivalent to x =
  operator.iadd(x, y)

operator.iadd(x, y) modifies x in place and returns x. However, (http://docs.python.org/3.2/library/operator.html#operator.add>) x + y is
dealt with by operator.add(x, y), which leaves x and y intact and must
return a new object.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: a question about list as an element in a tuple

2014-02-19 Thread Marko Rauhamaa
Marko Rauhamaa :

> operator.add(x, y) [...] leaves x and y intact and must return a new
> object.

Well, if the addition doesn't modify x, the method can of course return
x.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SSH/Telnet program to Router/switch

2014-02-19 Thread Johannes Schneider

On 19.02.2014 09:14, Sujith S wrote:

Hi,

I am new to programming and python. I am looking for a python script to do 
ssh/telnet to a network equipment ? I know tcl/perl does this using expect/send.

Do we have expect available in python as well or need to use some other method ?

Regards
Sujith





I'm using paramiko to access some routers and firewalls from python and 
it works very well.


bg,
Johannes


--
Johannes Schneider
Webentwicklung
johannes.schnei...@galileo-press.de
Tel.: +49.228.42150.xxx

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn
--
https://mail.python.org/mailman/listinfo/python-list


how to install automatically missing modules on a debian-system

2014-02-19 Thread hugocoolens
It often happens I start a python-script I wrote some time ago on another
system and get messages like "module_x is missing". I then perform an apt-cache 
search module_x, followed by an apt-get install name_of_missing_module.deb
I was wondering whether someone here has a kind of method which automatically
looks for the missing modules as debian-packages and offers to install them?

hugo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wheezy.web - is it been developed?

2014-02-19 Thread Marcio Andrey Oliveira
Hi.

Thanks for replying.

I navigated in its site. I just feel strange that no one wrote tutorials of
it (not counting some speed testing) and that there is no Wheezy.web
community (yet).

I'll give it a try and for sure I'll get in touch in case of problems.

Thank you.


2014-02-19 4:18 GMT-03:00 Andriy Kornatskyy :

> Marcio,
>
> The wheezy.web framework (http://bitbucket.org/akorn/wheezy.web) supplies
> documentation, tutorials, quick starts and benchmark for you. Due to
> modular architecture, it is being developed in several independent loosely
> coupled libraries under wheezy.*. The source code is easy to read, there is
> 100% test coverage.
>
> No bells and whistles.
>
> I believe the web framework should not be something cryptic (requiring
> community to exchange ideas about workarounds) nor something that involves
> infinitive development cycle.
>
> If you have any questions I will be happy to answer in this mailing list
> or personally.
>
> Thanks.
>
> Andriy Kornatskyy
>
> On Feb 19, 2014, at 1:48 AM, Marcio Andrey Oliveira 
> wrote:
>
> > Hi.
> >
> > I stumbled upon Wheezy.web and I got interested into learn more about it.
> >
> > After googling I didn't find that many information about it: only docs
> and samples from its web site.
> >
> > I didn't find a mailing list nor user groups and no tutorials from its
> users.
> >
> > Is Wheezy.web been actively developed? Does it have any user base
> community that I could get in touch with? Or should I forget about it and
> stick to say flask or pyramid?
> >
> > Thank you.
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 


*Do you have an arcade site? I do 1:1 Game Exchange *
*Play free on-line games
*

*Get free games for*

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


Python Requests script to login to a phpbb forum

2014-02-19 Thread Leo

Hi there,

I have decided to jump in at the deep end to try and learn python. I 
have been able to get requests to pull the login page off the server 
and I think send the login request. I don't get logged in though. 
Please let me know if I would be better off asking in a phpBB related 
group or forum.


Here is my code without username and password included:
import requests

payload = {'username': 'username', 'password': 'password'}
r = 
requests.post("http://www.tt-forums.net/ucp.php?mode=login",data=payload)

sidStart = r.text.find("sid")+4
sid = r.text[sidStart:sidStart+32]
parameters = {'mode': 'login', 'sid': sid}
r = 
requests.post("http://www.tt-forums.net/ucp.php",params=parameters,data=payload)

if "Logout" in r.text: print("We are in")

Thank you

--
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Free usenet access at http://www.eternal-september.org


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


Re: Python Requests script to login to a phpbb forum

2014-02-19 Thread Chris “Kwpolska” Warrick
On Wed, Feb 19, 2014 at 12:46 PM, Leo  wrote:
> Hi there,
>
> I have decided to jump in at the deep end to try and learn python. I have
> been able to get requests to pull the login page off the server and I think
> send the login request. I don't get logged in though. Please let me know if
> I would be better off asking in a phpBB related group or forum.
> Here is my code without username and password included:

You need cookies.  In order to do it, simply use sessions instead of
the “global” API.  Code:

import requests

payload = {'username': 'username', 'password': 'password'}
session = requests.Session()
r = session.post("http://www.tt-forums.net/ucp.php?mode=login",data=payload)
sidStart = r.text.find("sid")+4
sid = r.text[sidStart:sidStart+32]
parameters = {'mode': 'login', 'sid': sid}
r = 
session.post("http://www.tt-forums.net/ucp.php",params=parameters,data=payload)
if "Logout" in r.text: print("We are in")

(for the record, I added the session creation line and replaced
requests. with session. so it uses your session.  This code was not
tested on a real phpBB forum; if everything you coded is correct, it
will work.)

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wheezy.web - is it been developed?

2014-02-19 Thread Chris “Kwpolska” Warrick
On Wed, Feb 19, 2014 at 8:18 AM, Andriy Kornatskyy
 wrote:
> I believe the web framework should not be something cryptic (requiring 
> community to exchange ideas about workarounds) nor something that involves 
> infinitive development cycle.

Having lots of humans give support is much better when you have
problems.  You are more likely to get a quick response from a big
group of humans than from one developer.

On Wed, Feb 19, 2014 at 12:31 PM, Marcio Andrey Oliveira
 wrote:
> I navigated in its site. I just feel strange that no one wrote tutorials of 
> it (not counting some speed testing) and that there is no Wheezy.web 
> community (yet).

I personally suggest trying something more popular, like Flask,
Bottle, Pyramid, or Django (though it’s quite big and complicated).
Lots of tutorials exist for those.  There are big, vivid communities
offering help and support.  You can often find good solutions for
popular problems (like user accounts) without reinventing wheels.
Flask is the easiest option, and it’s very popular.

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wheezy.web - is it been developed?

2014-02-19 Thread Marcio Andrey Oliveira
To say the truth right now I'm studying some frameworks (not only in
Python) to get one I feel more comfortable with.

I'm learning Flask too and it seems a very nice project.

And I completely agree with you that the bigger the community the easier is
to get support.

Regards.


2014-02-19 9:01 GMT-03:00 Chris "Kwpolska" Warrick :

> On Wed, Feb 19, 2014 at 8:18 AM, Andriy Kornatskyy
>  wrote:
> > I believe the web framework should not be something cryptic (requiring
> community to exchange ideas about workarounds) nor something that involves
> infinitive development cycle.
>
> Having lots of humans give support is much better when you have
> problems.  You are more likely to get a quick response from a big
> group of humans than from one developer.
>
> On Wed, Feb 19, 2014 at 12:31 PM, Marcio Andrey Oliveira
>  wrote:
> > I navigated in its site. I just feel strange that no one wrote tutorials
> of it (not counting some speed testing) and that there is no Wheezy.web
> community (yet).
>
> I personally suggest trying something more popular, like Flask,
> Bottle, Pyramid, or Django (though it's quite big and complicated).
> Lots of tutorials exist for those.  There are big, vivid communities
> offering help and support.  You can often find good solutions for
> popular problems (like user accounts) without reinventing wheels.
> Flask is the easiest option, and it's very popular.
>
> --
> Chris "Kwpolska" Warrick 
> PGP: 5EAAEA16
> stop html mail | always bottom-post | only UTF-8 makes sense
>



-- 


*Do you have an arcade site? I do 1:1 Game Exchange *
*Play free on-line games
*

*Get free games for*

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


Re: Import order question

2014-02-19 Thread Roy Smith
In article <53045df2$0$2788$c3e8da3$76491...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> How do you know that the module tk_optionmenu.py contains the class 
> OptionMenu? Perhaps it contains the function optionmenu. Or the class 
> TK_OptionMenu. 

Stuff like this is a really important issue once a codebase gets large 
enough that nobody has it all memorized.  If I'm looking at a piece of 
code:

foo = Frobnicator()
foo.flamozilate()

and I want to get a better understanding of what flamozilation involves, 
it saves me a bunch of time if I can look at the class name and guess 
where it lives.  Otherwise, I'm reduced to:

$ cd $BASE_DIR; find . -name '*.py' | xargs grep "class Frobnicator"

In the Songza codebase, we often deal with triples of related names.  A 
class FooBar should live in a file models/foo_bar.py, and the name of 
the related database collection (think: SQL table name) should be 
"foo_bar".  When any of those assumptions are broken (and, sadly, 
sometimes they are), the cost of maintenance goes up.

Sometimes we'll put a small collection of very closely related classes 
in one file.  So, FrobnicatorIndexHelper would probably be in the same 
file as Frobnicator.

I once worked on a huge C++ project that had thousands of classes spread 
out over about 50 modules.  They had adopted the convention that *every* 
class name was something like CI_Frobnicator; the prefix told you where 
the class lived.
-- 
https://mail.python.org/mailman/listinfo/python-list


Win32 Write RAW Physical Disk Python 3.3.2

2014-02-19 Thread khanta
Hello,
 I am trying to write to the raw physical disk on Windows 8.1 but I
get an error:
PermissionError: [Errno 13] Permission denied: '.\\PHYSICALDRIVE2'

OS: Windows 8.1
Python: 3.3.2
Drive is a USB drive
Running as administrator

Code Snippet:

   with open(r"\\.\PHYSICALDRIVE2\\", "rb+") as f:  #Writing Binary!
f.seek(unallocatedoffset + 0)
f.write(t1)


or

with open('.\\PHYSICALDRIVE2\\', "rb+") as f:  #Writing Binary!
f.seek(unallocatedoffset + 0)
f.write(t1)

or

f = os.fdopen(os.open('.\\PHYSICALDRIVE2\\' os.O_CREAT |
os.O_WRONLY | os.O_APPEND | os.O_EXCL))


Any suggestions?  Is it possible?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SSH/Telnet program to Router/switch

2014-02-19 Thread Roy Smith
In article ,
 Sujith S  wrote:

> Hi,
> 
> I am new to programming and python. I am looking for a python script to do 
> ssh/telnet to a network equipment ? I know tcl/perl does this using 
> expect/send. 
> 
> Do we have expect available in python as well or need to use some other 
> method ?

You want two libraries.

First, the low-level paramiko (http://www.lag.net/paramiko/) which 
handles all the basic ssh connection stuff.

Next, fabric (http://docs.fabfile.org/en/1.8/), which layers a very easy 
to use application layer on top of paramiko.  Fabric is most commonly 
used in conjunction with a near command-line driver tool called fab, but 
you can also work directly with the library layer 
(http://docs.fabfile.org/en/1.8/usage/library.html).

Fabric rocks.  Don't waste your time with anything else (but see the 
next paragraph).

As far as I know, fabric only works with ssh.  If you are forced to use 
telnet to talk to legacy equipment, that's another problem.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SSH/Telnet program to Router/switch

2014-02-19 Thread Chris Angelico
On Thu, Feb 20, 2014 at 12:35 AM, Roy Smith  wrote:
> As far as I know, fabric only works with ssh.  If you are forced to use
> telnet to talk to legacy equipment, that's another problem.

If it's telnet, it's likely to be a pretty simple protocol. All you
really need is the socket module, build it all yourself. Networking's
easy enough to handle; it's the crypto on top of it (SSH, in your
case) that's not worth doing manually.

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


Re: SSH/Telnet program to Router/switch

2014-02-19 Thread Roy Smith
In article ,
 Roy Smith  wrote:

> in conjunction with a near command-line driver tool called fab

Typo there: "near" should have been "neat".

[this is why I love wikis]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SSH/Telnet program to Router/switch

2014-02-19 Thread William Ray Wing
On Feb 19, 2014, at 3:14 AM, Sujith S  wrote:

> Hi,
> 
> I am new to programming and python. I am looking for a python script to do 
> ssh/telnet to a network equipment ? I know tcl/perl does this using 
> expect/send. 
> 
> Do we have expect available in python as well or need to use some other 
> method ?
> 
> Regards
> Sujith
> -- 
> https://mail.python.org/mailman/listinfo/python-list

In addition to the other answers you've received (and noting that you are 
familiar with "expect"), you might want to investigate the pexpect module. 
Google will give you quite a long list of references to it, but you could start 
here:  http://pexpect.readthedocs.org/en/latest/

-Bill
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Turning an AST node / subnodes into something human-readable

2014-02-19 Thread Mark Lawrence

On 19/02/2014 03:58, Chris Angelico wrote:

I'm working with the ast module to do some analysis on Python
codebases, and once I've found what I'm looking for, I want to print
something out. The file name I'm hanging onto externally, so that
works; and the nodes all have a lineno. So far so good. But how do I
"reconstitute" a subtree into something fit for human consumption?

Take this cut-down example:

module = ast.parse("x[1] = 345+456")
assign = list(ast.walk(module))[1]
destination = assign.targets[0]

At this point, destination is the subtree representing what's being
assigned to. I can get a verbose dump of that:


print(ast.dump(destination))

Subscript(value=Name(id='x', ctx=Load()), slice=Index(value=Num(n=1)),
ctx=Store())

but what I'd really like to do is get something that looks
approximately like "x[1]". Is there an easy way to do that? Its str
and repr aren't useful, and I can't see a "reconstitute" method on the
node, nor a function in ast itself for the job. In theory I could
write one, but it'd need to understand every node type, so it seems
the most logical place would be on the node itself - maybe in __str__.

Is there anything nice and easy? I don't care if it's not perfect, as
long as it's more readable than ast.dump(). :)

ChrisA



http://alexleone.blogspot.co.uk/2010/01/python-ast-pretty-printer.html ?

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


extend methods of decimal module

2014-02-19 Thread Mark H. Harris
Would it be possible to extend the methods of the decimal module just a bit to 
include atan(), sin(), cos(), and exp() ?

The module has methods for ln() and sqrt(); and that's great!

I have done some rudimentary searching of the pep history and I'm not finding 
any pep related to extending the decimal module with other scientific functions.

It is easy to write them in pure python, of course, but I am interested in 
having the same performance boost with atan(), sin(), cos(), and exp() as I see 
with the rest of the decimal module on 3.3/  Is it possible anytime sooner than 
later?

By-the-by, my hat is off to the person(s) who did the 3.3 work on the decimal 
module --- the performance boost is astounding.  My agm routine for pi100k 
(which runs on 3.2.3 2Ghz in 10.5 minutes) runs on the same processor in 42 
seconds on 3.3.4/  very nice.


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


Re: Turning an AST node / subnodes into something human-readable

2014-02-19 Thread Chris Angelico
On Thu, Feb 20, 2014 at 2:04 AM, Mark Lawrence  wrote:
>> but what I'd really like to do is get something that looks
>> approximately like "x[1]".
>
> http://alexleone.blogspot.co.uk/2010/01/python-ast-pretty-printer.html ?

That's still based on ast.dump(), so it's still highly verbose. I've
stuck with just dumping to screen for the present. This really does
seem like a useful feature addition, though, if anyone wants to push
it through.

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


Re: Win32 Write RAW Physical Disk Python 3.3.2

2014-02-19 Thread Chris Angelico
On Wed, Feb 19, 2014 at 11:42 PM, khanta  wrote:
> PermissionError: [Errno 13] Permission denied: '.\\PHYSICALDRIVE2'

Have you tried running your script as administrator? Raw writing to a
disk quite possibly is (and definitely should be) a restricted action.

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


Re: Win32 Write RAW Physical Disk Python 3.3.2

2014-02-19 Thread Chris Angelico
On Thu, Feb 20, 2014 at 2:44 AM, Chris Angelico  wrote:
> On Wed, Feb 19, 2014 at 11:42 PM, khanta  wrote:
>> PermissionError: [Errno 13] Permission denied: '.\\PHYSICALDRIVE2'
>
> Have you tried running your script as administrator? Raw writing to a
> disk quite possibly is (and definitely should be) a restricted action.

Whoops! I missed seeing that somehow. You already are. Sorry about that!

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


Re: Help creating new module which inherits existing class from another module.

2014-02-19 Thread Jonno
On Tue, Feb 18, 2014 at 11:48 PM, Ben Finney wrote:

> Jonno  writes:
>
> > I tried to explain the necessary properties in the requirements below.
>
> What you've described is a bunch of abstract behaviour.
>
> But as I said, I'm suspecting this is a poor design; and I can't know
> better until you explain what all this is *for*.
>
> What is the purpose of the code you're writing? What is special about it
> that makes you think it needs the specific properties you've described?
>
> I ask all this because I suspect there are better and/or simpler ways to
> achieve your *actual* goals. Maybe not; but to rule that out, I'd need
> to know more about the purpose.
>
>  Let me try to give an example then.
Let's say the existing module provides a class RoboCom() which allows the
user to communicate with robots (it doesn't). It handles all the
communication hooks to send commands to & receive updates from many kinds
of robots.

RoboCom has attributes like:
send_cmd()
receive_cmd()
as well as other attributes like robot_name etc which are created when an
instance of RoboCom is created. But a RoboCom object doesn't have any
attributes specific to the type of robot it will be communicating with.

Let's say the robots can be humanoid or canine.
A command that can be sent to the humanoid robot might look like:
1. send_cmd("left_leg.knee.raise 1.1")# 1.1 being a height in units of m
A command that can be sent to the canine robot might look like:
2. send_cmd("tail.wag 3") # where 3 = number of times to wag.

To be able to use RoboCom the user must currently look up the documentation
for the kind of robot they want to communicate with which is stored
somewhere in a text file and then enter it into the arguments of the
RoboCom methods which is a pain.

What I want to do is create a RoboCom-like object, specific to the type of
robot it will communicate with, which allows the user of that object to
discover which commands can & can't be sent to that type of robot.

The actual code executed to send the commands should be 1. & 2. above but
it would be more convenient to the user if they could type something like:
1A. humanoid_robocom1.left_leg.knee.raise.send(1.1)
2A. canine_robocom1.tail.wag.send(3)


Does that help explain things better?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help creating new module which inherits existing class from another module.

2014-02-19 Thread Jonno
>
>
>
> The idea is that when you have a NewClass instance, calling
> "newobject.foo" will automatically call the descriptor's __getmethod__,
> passing it the class and instance. That descriptor will create and
> populate the FooClass instance, which does the real work.
>
> Descriptors are how methods, classmethods, staticmethods and properties
> work, so they are a fundamental, powerful way of implementing things like
> this.
>

Thanks for the suggestion Steven. Hopefully my last email on the subject
helped explain the intention a little better.
I'll look into descriptors some more. I had the feeling I needed to use one
(or more) of the following:
descriptors
decorators
metaclasses
None of which I know much about yet. I will do some reading & test out your
suggestion. Thanks again.
-- 
https://mail.python.org/mailman/listinfo/python-list


NEW RESEARCH DISPROVES EVOLUTION

2014-02-19 Thread THRINAXODON'S CREATION STUDIES
===
>BREAKING NEWS!
===
NEW YORK TIMES, THRINAXODON, OHIO
=
>
THRINAXODON RECENTLY FOUND 3 HUMAN FOSSILS FROM DEVONIAN STRATA FROM GREENLAND, 
THE EVOLUTIONISTS HAVE NO BONES ABOUT.
>
ONE EVIL EVOLUTIONIST, BOB CASANOVA HAS ADMITTED THAT HUMAN EVOLUTION IS IN 
FREE-FALL.
>
RICHARD LEAKEY HAS DIED FROM A HEART ATTACK DUE TO THIS GROUND-BREAKING FIND 
THAT CONCLUSIVELY SHOWS THAT HUMANS HAVE ORIGINS IN THE DEVONIAN.
>
NOW, IF YOU PLEASE, I HAVE TO SUE THE SMITHSONIAN FOR YEARS OF CENSORSHIP.
>
==
EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f#

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82#
-- 
https://mail.python.org/mailman/listinfo/python-list


NEW STUNNING RESEARCH SHOWS THAT HUMANS HAVE ORIGINS IN THE DEVONIAN

2014-02-19 Thread THRINAXODON OF THRINAXODON
===
>BREAKING NEWS!
===
NEW YORK TIMES, THRINAXODON, OHIO
=
>
THRINAXODON RECENTLY FOUND 3 HUMAN FOSSILS FROM DEVONIAN STRATA FROM GREENLAND, 
THE EVOLUTIONISTS HAVE NO BONES ABOUT.
>
ONE EVIL EVOLUTIONIST, BOB CASANOVA HAS ADMITTED THAT HUMAN EVOLUTION IS IN 
FREE-FALL.
>
RICHARD LEAKEY HAS DIED FROM A HEART ATTACK DUE TO THIS GROUND-BREAKING FIND 
THAT CONCLUSIVELY SHOWS THAT HUMANS HAVE ORIGINS IN THE DEVONIAN.
>
NOW, IF YOU PLEASE, I HAVE TO SUE THE SMITHSONIAN FOR YEARS OF CENSORSHIP.
>
==
EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f#

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82#
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help creating new module which inherits existing class from another module.

2014-02-19 Thread biolord9
On Tuesday, February 18, 2014 3:34:51 PM UTC-5, Jonno wrote:
> I'm not sure if this list is a suitable place to ask for this kind of help so 
> if it's not please just suggest another forum which might be more suitable.
> 
> 
> 
> 
> I'm looking for help/suggestions how to architect a module (perhaps just a 
> class).
> 
> There is an existing module I want to use which has a class we'll call 
> Existing Class.
> 
> I want to create a python module which allows me to create new_objects with 
> the following properties:
> The new_objects have all the attributes of the Existing_Class (simply create 
> a class that inherits from Existing_Class)
> I then want to create a nested structure under the new_objects something like:
> 
> new_object.foo
> 
> 
> new_object.foo.bar
> 
> 
> new_object.foo.bar.baz
> 
> 
> Where foo, bar, baz have the following properties:
> All have docstrings
> All are available for tab completion tools upon new_object creation.
> 
> Some of which will have new methods which act in the following way:
> 
> new_object.foo.bar()
> 
> calls
> new_object.existing_method("foo.bar", *args)
> 
> 
> I believe I'll need to use metaclasses and have an idea that types.MethodType 
> will help but I keep getting stuck. Any pointers would be greatly appreciated.

===
>BREAKING NEWS!
===
NEW YORK TIMES, THRINAXODON, OHIO
=
>
THRINAXODON RECENTLY FOUND 3 HUMAN FOSSILS FROM DEVONIAN STRATA FROM GREENLAND, 
THE EVOLUTIONISTS HAVE NO BONES ABOUT.
>
ONE EVIL EVOLUTIONIST, BOB CASANOVA HAS ADMITTED THAT HUMAN EVOLUTION IS IN 
FREE-FALL.
>
RICHARD LEAKEY HAS DIED FROM A HEART ATTACK DUE TO THIS GROUND-BREAKING FIND 
THAT CONCLUSIVELY SHOWS THAT HUMANS HAVE ORIGINS IN THE DEVONIAN.
>
NOW, IF YOU PLEASE, I HAVE TO SUE THE SMITHSONIAN FOR YEARS OF CENSORSHIP.
>
==
EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f#

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82#
-- 
https://mail.python.org/mailman/listinfo/python-list


NEW STUNNING RESEARCH DISPROVES EVOLUTIONARY FAIRY-TALES

2014-02-19 Thread THRINAXODON
===
>BREAKING NEWS!
===
NEW YORK TIMES, THRINAXODON, OHIO
=
>
THRINAXODON RECENTLY FOUND 3 HUMAN FOSSILS FROM DEVONIAN STRATA FROM GREENLAND, 
THE EVOLUTIONISTS HAVE NO BONES ABOUT.
>
ONE EVIL EVOLUTIONIST, BOB CASANOVA HAS ADMITTED THAT HUMAN EVOLUTION IS IN 
FREE-FALL.
>
RICHARD LEAKEY HAS DIED FROM A HEART ATTACK DUE TO THIS GROUND-BREAKING FIND 
THAT CONCLUSIVELY SHOWS THAT HUMANS HAVE ORIGINS IN THE DEVONIAN.
>
NOW, IF YOU PLEASE, I HAVE TO SUE THE SMITHSONIAN FOR YEARS OF CENSORSHIP.
>
==
EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f#

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82#
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDLE won't run after installing Python 3.3 in Windows

2014-02-19 Thread Mark H. Harris

> 
> Any suggestions?  Thanks in advance!
> 
> 

   Switch to Gnu/Linux.

Which version of tcl/tk is installed.  I would guess that tkinter is honked up 
somehow... did you clear up the old tkinter stuff?


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


Re: IDLE won't run after installing Python 3.3 in Windows

2014-02-19 Thread Mark Lawrence

On 19/02/2014 16:56, Mark H. Harris wrote:




Any suggestions?  Thanks in advance!


Switch to Gnu/Linux.

Which version of tcl/tk is installed.  I would guess that tkinter is honked up 
somehow... did you clear up the old tkinter stuff?



The version of tcl/tk is completely irrelevant as it comes bundled in 
the Python msi installer.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: IDLE won't run after installing Python 3.3 in Windows

2014-02-19 Thread Mark H. Harris

> 
> The version of tcl/tk is completely irrelevant as it comes bundled in 
> 
> the Python msi installer.
> 


Does the previous version put stuff into the registry that keeps the new 
version from running correctly?

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


Re: Turning an AST node / subnodes into something human-readable

2014-02-19 Thread Dan Goodman
Chris Angelico  gmail.com> writes:
> I'm working with the ast module to do some analysis on Python
> codebases, and once I've found what I'm looking for, I want to print
> something out. The file name I'm hanging onto externally, so that
> works; and the nodes all have a lineno. So far so good. But how do I
> "reconstitute" a subtree into something fit for human consumption?

I did something like this, feel free to use my code:

https://github.com/brian-team/brian2/blob/master/brian2/parsing/rendering.py

At the moment, it only works for series of mathematical statements (no
control conditions, loops, array notation, etc.), but it would be pretty
easy to add those. It also puts too many parentheses in outputted
expressions, e.g. 1+2+3 would come back as (1+2)+3, etc.

Dan

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


Re: IDLE won't run after installing Python 3.3 in Windows

2014-02-19 Thread Mark Lawrence

On 19/02/2014 17:30, Mark H. Harris wrote:




The version of tcl/tk is completely irrelevant as it comes bundled in

the Python msi installer.




Does the previous version put stuff into the registry that keeps the new 
version from running correctly?



Not that I'm aware of.  But then again if people knew the answer it 
would have been posted by now.  Where is Terry Reedy when you need him? 
Or possibly rr for that matter? :)


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: "JOBS IN PAKISTAN" www.pakjobs2008.blogspot.com "JOBS IN PAKISTAN" www.pakjobs2008.blogspot.com "JOBS IN PAKISTAN" www.pakjobs2008.blogspot.com "JOBS IN PAKISTAN" www.pakjobs2008.blogspot.com

2014-02-19 Thread iamalimuhammad
On Tuesday, August 4, 2009 3:06:59 PM UTC+5, Riaz Ahmad wrote:
> "JOBS IN PAKISTAN"   www.pakjobs2008.blogspot.com "
> 
> 
> JOBS IN PAKISTAN"   www.pakjobs2008.blogspot.com "
> 
> 
> JOBS IN PAKISTAN"   www.pakjobs2008.blogspot.com "
> 
> JOBS IN PAKISTAN"   www.pakjobs2008.blogspot.com "
> 
> 
> JOBS IN PAKISTAN"   www.pakjobs2008.blogspot.com "

for more http://pak.doortojobs.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extend methods of decimal module

2014-02-19 Thread Terry Reedy

On 2/19/2014 10:30 AM, Mark H. Harris wrote:

Would it be possible to extend the methods of the decimal module just
a bit to include atan(), sin(), cos(), and exp() ?


The decimal module implements IEEE 854


The module has methods for ln() and sqrt(); and that's great!


that includes just these. I am not sure if we have an ironclad policy 
against adding things not in the standard.



By-the-by, my hat is off to the person(s) who did the 3.3 work on the
decimal module --- the performance boost is astounding.


Stephen (?) Krah.

--
Terry Jan Reedy

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


A Brief Introduction to Islam

2014-02-19 Thread BV BV
A Brief Introduction to Islam

A brief introduction to the meaning of Islam, the notion of God in Islam, and 
His basic message to humanity through the Prophets.

http://www.islamhouse.com/426146/en/en/articles/A_Brief_Introduction_to_Islam

Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDLE won't run after installing Python 3.3 in Windows

2014-02-19 Thread Terry Reedy

On 2/19/2014 12:50 PM, Mark Lawrence wrote:

On 19/02/2014 17:30, Mark H. Harris wrote:



Does the previous version put stuff into the registry that keeps the
new version from running correctly?



Not that I'm aware of.  But then again if people knew the answer it
would have been posted by now.  Where is Terry Reedy when you need him?


Puzzled as to what the problem is.

--
Terry Jan Reedy

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


Insert variable into text search string

2014-02-19 Thread Kevin Glover
These two lines are from a program that carries out a phrase search of 
Wikipedia and returns the total number of times that the specific phrase 
occurs. It is essential that the search contains an apostrophe:

results = w.search("\"of the cat's\"", type=ALL, start=1, count=1)
print results.total

I want to replace the word "cat" with a variable, e.g.

q = "cat"

so that I can generate the same search format for a list of different words. 
How do I format the search string to include the variable, please? I am using 
Python 2.7.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Insert variable into text search string

2014-02-19 Thread MRAB

On 2014-02-19 19:39, Kevin Glover wrote:

These two lines are from a program that carries out a phrase search of 
Wikipedia and returns the total number of times that the specific phrase 
occurs. It is essential that the search contains an apostrophe:

results = w.search("\"of the cat's\"", type=ALL, start=1, count=1)
print results.total

I want to replace the word "cat" with a variable, e.g.

q = "cat"

so that I can generate the same search format for a list of different words. 
How do I format the search string to include the variable, please? I am using 
Python 2.7.


Try string concatenation:

results = w.search("\"of the " + q + "'s\"", type=ALL, start=1, 
count=1)


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


Re: Insert variable into text search string

2014-02-19 Thread Jussi Piitulainen
Kevin Glover writes:

> These two lines are from a program that carries out a phrase search
> of Wikipedia and returns the total number of times that the specific
> phrase occurs. It is essential that the search contains an
> apostrophe:
> 
> results = w.search("\"of the cat's\"", type=ALL, start=1, count=1)
> print results.total
> 
> I want to replace the word "cat" with a variable, e.g.
> 
> q = "cat"
> 
> so that I can generate the same search format for a list of
> different words. How do I format the search string to include the
> variable, please? I am using Python 2.7.

Format is the right word: look up the .format method of strings.

   >>> '''"of the {q}'s"'''.format(q='kangaroo')
   '"of the kangaroo\'s"'

That's with Python 2.7.3. An older mechanism uses the percent sign for
place holders and as an operator.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Insert variable into text search string

2014-02-19 Thread Kevin Glover
Thank you both so much. I had tried % but not successfully.
-- 
https://mail.python.org/mailman/listinfo/python-list


Can I use Python 3 - script on github

2014-02-19 Thread Mark Lawrence
https://github.com/brettcannon/caniusepython3 may be of interest to some 
of you fine folks.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: extend methods of decimal module

2014-02-19 Thread Mark H. Harris
> 
> The decimal module implements IEEE 854
> 

Thanks Terry...   ... long time.

I would like to find out if there is some iron-clad policy about extending the 
implementation of an IEEE standard... decimal module in this case;  I'm just 
thinking that this particular extension really fits the python "batteries 
included" philosophy. 

I guess what I'm really asking for are the same routines found in "bc -l" math 
library. I've finally moved my number crunching stuff to python (from bc) 
because the performance of "decimal" is finally way better than bc for the 
moment, and wrapping python are the math routines for control and processing is 
so much better.   Anyway, sure would be nice to have a very speedy atan() 
function built-in for decimal.

Thanks for the answer... I hope you enjoy the day!

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


Re: extend methods of decimal module

2014-02-19 Thread Zachary Ware
On Wed, Feb 19, 2014 at 3:30 PM, Mark H. Harris  wrote:
>>
>> The decimal module implements IEEE 854
>>
>
> Thanks Terry...   ... long time.
>
> I would like to find out if there is some iron-clad policy about extending
> the implementation of an IEEE standard... decimal module in this case;  I'm
> just thinking that this particular extension really fits the python
> "batteries included" philosophy.
>
> I guess what I'm really asking for are the same routines found in "bc -l"
> math library. I've finally moved my number crunching stuff to python (from bc)
> because the performance of "decimal" is finally way better than bc for the
> moment, and wrapping python are the math routines for control and processing
> is so much better.   Anyway, sure would be nice to have a very speedy atan()
> function built-in for decimal.

You might consider suggesting a "decimal.math" module on python-ideas.

-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 2.7 importing pyc files without py files

2014-02-19 Thread Mircescu Andrei
Hi,


I encountered a strange issue. I have an application which uses extensively 
python 2.7.6 (CPython).


The issue that I see is the following:
If there are only pyc files, the loading time of the application is much more 
than if I have pyc and py files. It is behind with 2 minutes more than if it 
had py files

Do you have any idea why this is happening ? Maybe is because, python tries to 
search the py file in all the paths and this search is exhaustive ? This is the 
best guess I could figure it out but I'm not sure. 

Also, if this is the scenario, there is a way I can stop this, to not search 
for the py files ? is there an api ? or a compiling flag I should set ?



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


Re: extend methods of decimal module

2014-02-19 Thread Terry Reedy

On 2/19/2014 4:54 PM, Zachary Ware wrote:

On Wed, Feb 19, 2014 at 3:30 PM, Mark H. Harris  wrote:


The decimal module implements IEEE 854



Thanks Terry...   ... long time.

I would like to find out if there is some iron-clad policy about extending
the implementation of an IEEE standard... decimal module in this case;  I'm
just thinking that this particular extension really fits the python
"batteries included" philosophy.

I guess what I'm really asking for are the same routines found in "bc -l"
math library. I've finally moved my number crunching stuff to python (from bc)
because the performance of "decimal" is finally way better than bc for the
moment, and wrapping python are the math routines for control and processing
is so much better.   Anyway, sure would be nice to have a very speedy atan()
function built-in for decimal.


You might consider suggesting a "decimal.math" module on python-ideas.


Or just dmath. I think this is a better idea than suggesting additions 
to decimal itself. For one thing, anything put in decimal would be 
subject to change if the function were to be added to the standard. It 
is worth noting in such a posting that Krah's speedup make such 
functions really feasible. The algorithms could be similar, at least 
initially, to the one used for floats.


--
Terry Jan Reedy

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


Re: Python 2.7 importing pyc files without py files

2014-02-19 Thread Emile van Sebille

On 2/19/2014 2:03 PM, Mircescu Andrei wrote:

> If there are only pyc files, the loading time of the application is
> much more than if I have pyc and py files. It is behind with 2
> minutes more than if it had py files

You may get some clues by starting python as

/path/to/python/python2.7 -vv

which will provide the details of attempts to import:

[root@vsds4 log]# python2.7 -vv
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# trying /usr/local/lib/python2.7/site.so
# trying /usr/local/lib/python2.7/sitemodule.so
# trying /usr/local/lib/python2.7/site.py
# /usr/local/lib/python2.7/site.pyc matches /usr/local/lib/python2.7/site.py
import site # precompiled from /usr/local/lib/python2.7/site.pyc
# trying /usr/local/lib/python2.7/os.so
# trying /usr/local/lib/python2.7/osmodule.so
# trying /usr/local/lib/python2.7/os.py
# /usr/local/lib/python2.7/os.pyc matches /usr/local/lib/python2.7/os.py
import os # precompiled from /usr/local/lib/python2.7/os.pyc
...



HTH,

Emile


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


Re: Python 2.7 importing pyc files without py files

2014-02-19 Thread Terry Reedy

On 2/19/2014 5:03 PM, Mircescu Andrei wrote:

Hi,


I encountered a strange issue. I have an application which uses
extensively python 2.7.6 (CPython).


The issue that I see is the following: If there are only pyc files,
the loading time of the application is much more than if I have pyc
and py files. It is behind with 2 minutes more than if it had py
files

Do you have any idea why this is happening ? Maybe is because, python
tries to search the py file in all the paths and this search is
exhaustive ? This is the best guess I could figure it out but I'm not
sure.


It seems plausible. Once .py is found, the .pyc is in the same directory.


Also, if this is the scenario, there is a way I can stop this, to not
search for the py files ?


Try reducing sys.path to the minimum needed.

--
Terry Jan Reedy

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


Re: extend methods of decimal module

2014-02-19 Thread Zachary Ware
On Wed, Feb 19, 2014 at 4:10 PM, Terry Reedy  wrote:
> On 2/19/2014 4:54 PM, Zachary Ware wrote:
>> You might consider suggesting a "decimal.math" module on python-ideas.
>
>
> Or just dmath.

The name (and location) is of course endlessly bikesheddable :)

> I think this is a better idea than suggesting additions to
> decimal itself. For one thing, anything put in decimal would be subject to
> change if the function were to be added to the standard. It is worth noting
> in such a posting that Krah's speedup make such functions really feasible.
> The algorithms could be similar, at least initially, to the one used for
> floats.

It might be good to even go a step further, and make it "amath" (or
"numbers.math", or ...), a type-agnostic math module.  Such a module
would likely be slower than math, cmath, or "dmath", but should end
the proliferation of math modules.

-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extend methods of decimal module

2014-02-19 Thread Oscar Benjamin
On 19 February 2014 15:30, Mark H. Harris  wrote:
> Would it be possible to extend the methods of the decimal module just a bit 
> to include atan(), sin(), cos(), and exp() ?
>
> The module has methods for ln() and sqrt(); and that's great!
>
> I have done some rudimentary searching of the pep history and I'm not finding 
> any pep related to extending the decimal module with other scientific 
> functions.

As Terry has pointed out, the decimal module follows IEEE 854 which
doesn't include those.

I think the module sort of has two big use-cases. On the one hand you
have people looking to do financial calculations etc. who are looking
for basic arithmetic with decimal type rounding. On the other hand you
have people like me who see it as a convenient multi-precision library
for when double precision just isn't enough. The module doesn't fully
live up to my use-case because as you say it lacks support for
transcendental functions.

I think, though, that there's a case for having say a "dmath" module
that would export a similar interface to the math and cmath modules
but with functions that work with Decimals in full precision. Someone
has already created a pure Python version of this idea here:
https://code.google.com/p/dmath/

> It is easy to write them in pure python, of course, but I am interested in 
> having the same performance boost with atan(), sin(), cos(), and exp() as I 
> see with the rest of the decimal module on 3.3/  Is it possible anytime 
> sooner than later?

Actually the performance difference isn't as big as you might think.
So given the following exponential function:

from decimal import Decimal, localcontext

e = Decimal('2.7182818284590452353602874713527')

def exp(x):
'''
>>> print exp(Decimal(1))
2.718281828459045235360287471
>>> print exp(Decimal(2))
7.389056098930650227230427461
'''
# Work in slightly higher precision
with localcontext() as ctx:
ctx.prec += 2
xi, xf = divmod(x, 1)
# Use integer exponentiation
yi = e ** xi
# Now use the Maclaurin series for the fractional part
lastyf = -1
yf = 1
n = 0
fact = 1
xfn = 1
while yf != lastyf:
lastyf = yf
n += 1
fact *= n
xfn *= xf
yf += xfn / fact
# Downgrade precision
return yi * yf

import doctest
doctest.testmod()


I get the following timings:
$ python3.3 -m timeit -s 'from decimal import Decimal as D;
d=D('0.123'); from tmp import exp' 'exp(d)'
1 loops, best of 3: 32.3 usec per loop
$ python3.3 -m timeit -s 'from decimal import Decimal as D;
d=D('0.123'); from tmp import exp' 'd.exp()'
1 loops, best of 3: 26.5 usec per loop

So the pure Python exponential function (using the C-accelerated
decimal module) weighs in at 32usec and the pure C version at 26usec.
The intensity of software arithmetic even in C is still dominating the
performance here. The difference becomes more noticeable as you
approach an integer value from below e.g. something like 24.9 but not
more than a factor of 2.

For comparison here's how it looks on the FPU (from Python's perspective):

$ python3.3 -m timeit -s 'd=0.123; from math import exp' 'exp(d)'
1000 loops, best of 3: 0.149 usec per loop

So that's 2 orders of magnitude faster. It makes sense if you think
about it in terms of CPU instructions: on x87 there are about 5
instructions to call exp in (extended) double precision and takes
about 20-30 cycles (with the time dominated by the F2XM1 instruction).
The number of integer instructions required to compute the above with
the decimal module is massive in comparison.


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


Re: IDLE won't run after installing Python 3.3 in Windows

2014-02-19 Thread eglowstein . h
On Wednesday, February 19, 2014 2:00:52 PM UTC-5, Terry Reedy wrote:
> On 2/19/2014 12:50 PM, Mark Lawrence wrote:
> 
> > On 19/02/2014 17:30, Mark H. Harris wrote:
> 
> 
> 
> >> Does the previous version put stuff into the registry that keeps the
> 
> >> new version from running correctly?
> 
> 
> 
> > Not that I'm aware of.  But then again if people knew the answer it
> 
> > would have been posted by now.  Where is Terry Reedy when you need him?
> 
> 
> 
> Puzzled as to what the problem is.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy


I was extremely careful to remove any last bit of evidence in the registry that 
*anything* in the c:\python27 and c:\python33 directories ever existed. After 
the registry was purged of everything and I deleted the directories, I 
restarted the machine to make sure the registry was read afresh (Windows XP is 
wacky that way) and then did a reinstall of Python 3.3.3. Before installing 
anything else, I launched a program by using the 'Edit in Idle' option. Idle 
comes up, flashes briefly and exits. The console window never appears. If I 
bring up a command window and go into the lib\idlelib directory and 
specifically start idle with "python idle.py" or "pythons idle.py", I get Idle, 
but no command window. Load a file in if launched with 'python', it appears but 
you can't run it. If you launch with 'pythons', the whole kit & caboodle just 
exits when you load the file.

That might not help, but that's all I saw. Is there someplace not obvious in 
the registry where any interesting information is kept?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Insert variable into text search string

2014-02-19 Thread Chris Angelico
On Thu, Feb 20, 2014 at 7:15 AM, Kevin Glover  wrote:
> Thank you both so much. I had tried % but not successfully.

To do it with %, just do this:

whatever = "cat"
results = w.search("\"of the %s's\""%whatever, type=ALL, start=1, count=1)

Use either that or .format(), whichever you like - both are fully
supported, and they have different strengths.

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


Re: IDLE won't run after installing Python 3.3 in Windows

2014-02-19 Thread David Robinow
On Tue, Feb 18, 2014 at 9:56 AM,   wrote:
> The next adventure in Python was to install Python 3 into a Windows XP 
> machine. I had a previous 2.7 installation that I uninstalled and carefully 
> removed all traces of from the directory and the registry.

It is not necessary to uninstall previous  versions of Python. They
can live happily together. Not only does it work, it's a supported
configuration. That's what the launcher is for.
Mucking with the registry is generally inadvisable. It's too easy to
make a mistake.
If you do decide to uninstall a Python version, do it through the
Control Panel. If that results in problems, submit a bug report.

> I got the 'python-3.3.3.msi' from Python.org and installed it. From a command 
> window I can run 'python' and I get the Python prompt. I have several Python 
> programs on the machine. If I right click o one, I have the option of 'Edit 
> in IDLE'. If I do that, the disk light blinks briefly, and then nothing. So I 
> went into the \python33\lib\idlelib directory and from a CMD window, ran 
> 'python idle.py'. That loads IDLE. but when I ask IDLE to load a file, it 
> navigates to a FileOpen dialog and then closes everything when I actually 
> open the file. I then tried the same thing but used 'pythonw' instead. Same 
> deal.
>
> I also saw some other threads here about how Python can get befuddled by 
> firewalls, so I disabled that with no effect.
>
> Any suggestions?  Thanks in advance!
 I would reinstall Python2.7 and then reinstall Python3.3. That may
straighten out your registry. (It may not)
Let us know if that works.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help creating new module which inherits existing class from another module.

2014-02-19 Thread Ben Finney
Jonno  writes:

> Let's say the existing module provides a class RoboCom() which allows
> the user to communicate with robots (it doesn't).

Well, can you say what it *does* do? These hypotheticals aren't very
helpful; I don't know what inferences I'm safe to draw from the made-up
situation. What is it you're *actually* trying to allow the user to do?

> A command that can be sent to the humanoid robot might look like:
> 1. send_cmd("left_leg.knee.raise 1.1")# 1.1 being a height in units of m
> A command that can be sent to the canine robot might look like:
> 2. send_cmd("tail.wag 3") # where 3 = number of times to wag.

So, the robot (except it's not a robot, apparently) is controlled by a
textual command API (or is it? is that part true, or just hypothetical?)

If you're trying to wrap a command-line based API in an object-oriented
API, then you're going to have considerable impedance mismatch between
those APIs.

Your success will depend on a number of factors, such as: how frequently
can the command-line interface be expected to change; how much effective
control do you have over the design of the command-line interface; how
sane is the command-line interface design; etc.

I can't recommend much general advice beyond: don't expect to wrap a
command-line interface in an object-oriented interface without greatly
distorting one or the other or both. It may be possible to get a modicum
of success, but you should not expect it to be satisfactory.

Of course, if I knew what you're *actually* trying to program for, I
might be able to offer more specific advice.

> Does that help explain things better?

Not really. It's up to you if you want to be coy about your actual
requirements, but the quality of assistance you can expect will be
commensurately low.

-- 
 \ “Two paradoxes are better than one; they may even suggest a |
  `\ solution.” —Edward Teller |
_o__)  |
Ben Finney

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


Re: extend methods of decimal module

2014-02-19 Thread casevh
On Wednesday, February 19, 2014 1:30:13 PM UTC-8, Mark H. Harris wrote:
> 
> I guess what I'm really asking for are the same routines found in "bc -l"
> math library. I've finally moved my number crunching stuff to python (from
> bc) because the performance of "decimal" is finally way better than bc for
> the moment, and wrapping python are the math routines for control and
> processing is so much better.   Anyway, sure would be nice to have a very
> speedy atan() function built-in for decimal.
> 

Have you looked at the gmpy2 ( https://code.google.com/p/gmpy/ ) module?

It supports all the transcendental function available in the MPFR library. I
did a quick performance test of sqrt() and ln() at around 1000 decimal digits.
gmpy2 was about ~200 times faster than the corresponding functions in decimal.

casevh
-- 
https://mail.python.org/mailman/listinfo/python-list


Tanglin With Alpha

2014-02-19 Thread David Hutto
Just as a quick survey...Are individual programmers happier with tangling with 
the alpha code, or more comfortable with beta versions, or does it matter, 
dependant on the circumstances?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tanglin With Alpha

2014-02-19 Thread Chris Angelico
On Thu, Feb 20, 2014 at 5:06 PM, David Hutto  wrote:
> Just as a quick survey...Are individual programmers happier with tangling 
> with the alpha code, or more comfortable with beta versions, or does it 
> matter, dependant on the circumstances?
>

Depends on the program, enormously. Or, to put it another way, depends
on whether I'm trying to "just get the job done" or am prepared to put
in some effort.

I run a web and mail and etcetera server. For that, I use Apache,
bind9, courier-imap, and a bunch of other programs, all obtained
through apt-get.

I also am the author of a MUD client, written in Pike. Because of the
nature of what I'm doing there, I tend to push the boundaries of the
language itself; that means I sometimes find bugs, submit patches, and
all that. So currently, I'm running a bleeding-edge Pike that consists
of the latest from upstream plus one patch of my own that hasn't yet
been accepted... so it's "from __future__ import socket_nodelay" if
you like. The price I pay for that is that, sometimes, stuff's broken.
I try to import the bittorrent client and boom, it fails because
something's half way through being edited in the SSL code and it
wouldn't load. That's something I choose to accept with Pike, but I
would *not* accept it with, say, gcc. With the C compiler, I expect it
to just work.

But alpha and beta versions? Almost never. I'm currently running
Python 3.4.0b2 on Windows, because I don't have facilities to build
Python from source on Windows; on my Linux boxes, I use Python 3.x
straight from Mercurial (same as with Pike above), or else whatever I
can apt-get. Either I'm prepared to use a development version or I'm
not, with very VERY few exceptions (I think I once built a Linux
kernel from a development tarball - really no point, I could have done
just as well going from git).

Ultimately, it comes down to how much work you want to do versus how
much trust you want to place in someone else. If you'd rather trust
someone else, take a published stable version (especially one that you
can get from a stable OS distribution's repository - not only is it
convenient to apt-get everything, you can be confident that the Debian
Wheezy repo has stuff that's known to work with Debian Wheezy); if
you'd rather do the work yourself, build from source, at whatever
point you like.

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


Cannot figure out line of code, also not understanding error

2014-02-19 Thread ApathyBear
I have two questions that come along with the following code:

--

from __future__ import print_function

def sanitize(time):
if '-' in time:
splitter = '-'
(mins,secs) = time.split(splitter, 1)
return (mins+'.'+secs)
elif ':' in time:
splitter = ':'
(mins,secs) = time.split(splitter, 1)
return (mins+'.'+secs)
else:
return time


#start class
class Athlete:
def __init__(self, a_name, a_dob=None, a_times=[]):
self.name = a_name
self.dob= a_dob
self.times = a_times

def top3(self):
return(sorted(set([sanitize(t) for t in self.times]))[0:3])
#end class  

def get_coach_data(filename):
try:
with open(filename) as f:
data = f.readline()
temp1 = data.strip().split(',')
return(Athlete(temp1.pop(0),temp1.pop(0), temp1)

except IOError:
print ('File error')
return (None)

james = get_coach_data('james2.txt')

print (james.name + "'s fastest times are: " + str(james.top3()))


--
This is the original text file data I am working with called james2.txt located 
on my desktop:

James Lee,2002-3-14,2-34,3:21,2.34,2.45,3.01,2:01,2:01,3:10,2-22,2-01,2.01,2:16




--





1. What does this line of code mean:
return(Athlete(temp1.pop(0),temp1.pop(0), temp1)

Is it making an Athlete class? if you can give examples to help explain what 
this is doing that would be helpful.




2. Why am I getting this error when I try to run the file?
PS C:\Users\N\desktop> python gg.py
  File "gg.py", line 34
except IOError:
 ^
SyntaxError: invalid syntax
PS C:\Users\N\desktop>

What syntax is invalid here?
-- 
https://mail.python.org/mailman/listinfo/python-list