Re: regexp help

2009-08-27 Thread Peter Pearson
On Thu, 27 Aug 2009 11:15:59 -0700 (PDT), Bakes ba...@ymail.com wrote:
 If I were using the code:

 (?Pdata[0-9]+)

 to get an integer between 0 and 9, how would I allow it to register
 negative integers as well?

(?Pdata-?[0-9]+)

-- 
To email me, substitute nowhere-spamcop, invalid-net.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on the csv library

2009-08-27 Thread Andreas Waldenburger
On Thu, 27 Aug 2009 13:12:07 -0700 (PDT) vsoler
vicente.so...@gmail.com wrote:

 On Aug 27, 9:42 pm, Andreas Waldenburger use...@geekmail.invalid
 wrote:
 
 [snip what I wrote]
 
 Thank you for your answers. Let me however make some comments:
 
 1- the csv file was generated with Excel 2007; no prompts for what the
 separator should be; Excel has used ; by default, without asking
 anything
 

Apparently it's possible, but it's a kludge

http://astrochimp.com/2005/12/20/export-csv-with-any-delimiter/comment-page-1/

Anyways, ...


 2- about capitalisation, I used the var spamReader because I just
 copy/pasted from the official python site:
 
   http://docs.python.org/library/csv.html
 
Oh, switcheroo!

Well, those hypocrites!


 3- when I try
 
  sheet = [row for row in spamReader]
  print sheet
 []
 
 all I get is an empty list; something seems not to be working properly
 
 Same result list: I get an empty list
 
  sheet = list(spamReader)
 
 Thank you again for your help, which is highly appreciated.
 

I'm assuming you do that after you've iterated over the file before?
Because it did work in a previous post of yours.

Here's the deal: When you iterate over a file (or read from it in any
other manner) you advance in the file. After iteration, you're at the
end, of course. So iterating again yields silch.

Hmm ... don't know how that translates to a CSVReader. But I postulate
that it'l work on a fresh run.


/W



-- 
INVALID? DE!

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


Re: Question on the csv library

2009-08-27 Thread Mark Lawrence

vsoler wrote:

On Aug 27, 9:42 pm, Andreas Waldenburger use...@geekmail.invalid
wrote:

On Thu, 27 Aug 2009 21:36:28 +0200 Andreas Waldenburger

use...@geekmail.invalid wrote:

[snip]
Might I humbly suggest

sheet = list(spamReader)  # ?

Oh, and while I'm humbly suggesting:

spam_reader instead of spamReader or SpamReader or SpamrEadeR or
suchlike. Caps are reserved for classes.

Not a necessity, of course. But it's the dialect around these parts.

/W

--
INVALID? DE!


Thank you for your answers. Let me however make some comments:

1- the csv file was generated with Excel 2007; no prompts for what the
separator should be; Excel has used ; by default, without asking
anything
I find this difficult to believe, but assuming that you are correct then 
use the delimiter=';' argument in the call to csv.reader.  See the csv 
module documentation section Dialects and Formatting Parameters for 
more information.


2- about capitalisation, I used the var spamReader because I just
copy/pasted from the official python site:

  http://docs.python.org/library/csv.html

3- when I try


sheet = [row for row in spamReader]
print sheet

[]

all I get is an empty list; something seems not to be working properly

Same result list: I get an empty list

 sheet = list(spamReader)

Thank you again for your help, which is highly appreciated.

Vicente Soler



--
Kindest regards.

Mark Lawrence.

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


Re: Does Class implements Interface?

2009-08-27 Thread Jonathan Gardner
On Aug 27, 6:16 am, Emanuele D'Arrigo man...@gmail.com wrote:
 Greetings everybody,

 let's say I have a Class C and I'd like to verify if it implements
 Interface I. If I is available to me as a class object I can use
 issubclass(C, I) and I can at least verify that I is a superclass of
 C. There are a couple of issues with this approach however:

 1) C might override not just I's methods code but also I's methods
 signatures, effectively changing the interface.
 2) What if I is -not- available to me as the superclass of C but as a
 description of the interface, i.e. as an IDL(*) file?

 Are there resources such as tools, recipes, documents or strategies
 that could help me deal with these issues? I've already looked into
 the ABC module and the zope.interface. I'm just fishing for more
 things to look at.


Have you heard of duck typing?

Ignore all those things and rely on human (aka natural language)
documentation. That is, if you want to see if a class will work for an
interface, go read the docs on the interface (or rather, what the
function expects the interface to be) and what the class provides and
see if they fit.

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


Re: Learning Python advanced features

2009-08-27 Thread Jonathan Gardner
On Aug 27, 5:13 am, jvpic jv...@free.fr wrote:
 Hi,

 Learning Python, I understand the mechanism of : closure, __new__,
 descriptors, decorators and __metaclass__, but I interrogate myself on
 the interest of those technics ?

 May somebody explain me the interest ?


I assume you are asking, Why do these features exist? What makes them
useful? When would I use them?

For that, you should re-read the documentation and discussion
surrounding them. The short answer is that the above makes your job,
as a programmer easier. It's easier because you have to write less
code, read less code, and your code has fewer bugs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] How do I reply to a thread by sending a message to python-list@python.org

2009-08-27 Thread Terry Reedy

Terry Reedy wrote:

David House wrote:

2009/8/27 Terry Reedy tjre...@udel.edu:
reply-all may send duplicate messages to the author. Not sure of this 
list.


I'm fairly sure Mailman deals with that.


Nope. I got a duplicate sent to my mailbox, which I hate.


In particular, because there is no indication that it is an exact 
duplicate of what I will also find on the list itself. Please use reply 
instead of reply-all.


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


Re: Python on the Web

2009-08-27 Thread Aahz
In article d2921dc3-646c-49f3-8dd6-228bbc649...@k30g2000yqf.googlegroups.com,
Phil  phil...@gmail.com wrote:

My interest in Python 3.1 was actually to develop a framework. Again,
I can feel the flames. :) I understand there are enough frameworks but
I actually have no applications that I wish to develop. I enjoy
developing these kinds of things from scratch as a learning
experience.

Well, there's a standard joke that just as people learning Scheme write
a new language (following SICP), people learning Python write a new web
framework.  That's why there are so many of them.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

I support family values -- Addams family values --www.nancybuttons.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Telnet client

2009-08-27 Thread Darvin
Is there telnet client in python?
i want to write NetHack telnet GUI app)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Telnet client

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 2:06 PM, Darvinnbdar...@gmail.com wrote:
 Is there telnet client in python?
 i want to write NetHack telnet GUI app)

http://docs.python.org/library/telnetlib.html

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


How to unencode a string

2009-08-27 Thread jakecjacobson
This seems like a real simple newbie question but how can a person
unencode a string?  In Perl I use something like: $part=~ s/\%([A-Fa-
f0-9]{2})/pack('C', hex($1))/seg;

If I have a string like Word1%20Word2%20Word3 I want to get Word1
Word2 Word3.  Would also like to handle special characters like ',(){}
[] etc/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Telnet client

2009-08-27 Thread exarkun

On 09:06 pm, nbdar...@gmail.com wrote:

Is there telnet client in python?
i want to write NetHack telnet GUI app)


The Python stdlib has a module named telnetlib which offers rudamentary 
telnet support.  Twisted includes twisted.conch.telnet which implements 
a much more complete telnet library.  Twisted also includes 
twisted.conch.insults which provides basic terminal control 
functionality (so you can tell what nethack is trying to do over your 
telnet connection).


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


Re: [OT] How do I reply to a thread by sending a message to python-list@python.org

2009-08-27 Thread Aahz
In article mailman.541.1251404574.2854.python-l...@python.org,
Terry Reedy  tjre...@udel.edu wrote:
David House wrote:
 2009/8/27 Terry Reedy tjre...@udel.edu:

 reply-all may send duplicate messages to the author. Not sure of
 this list.

 I'm fairly sure Mailman deals with that.

Nope. I got a duplicate sent to my mailbox, which I hate.

More precisely, there is a Mailman option per-list to suppress list
sending of posts for which you are cc'd.  I don't remember where, you
should be able to find it by poking around the Mailman interface (or
searching the docs).
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

I support family values -- Addams family values --www.nancybuttons.com
-- 
http://mail.python.org/mailman/listinfo/python-list


TypeError: _getfullpathname() argument 1 must be (buffer overflow), not str in windows xp, while making tarfile

2009-08-27 Thread Ryniek90

 Ryniek90 rynie...@gmail.com (R) wrote:
 

   
 R Hahah right. My fault. Must remember to read documentation so many times
 R until I find the solution.  Thanks, now works fine.  :-)
 

 And, by the way, how come the traceback refers to
 File backuper.py, line 197, in module
 while the posted code has only 188 lines?
   

Cuz my original code is bit longer - i've got some bookkeepings like
__author__, __version__ etc., just after module imports.
-- 
http://mail.python.org/mailman/listinfo/python-list


An assessment of Tkinter and IDLE

2009-08-27 Thread r
-
Tkinter and IDLE Shortfalls
-
*The following is an assessment of Tkinter as i have experienced it.
Even with all the problems i list below i strongly believe Tkinter is
a great starter GUI toolkit and we (the Python Community), must keep
and maintain this module for the foreseeable future.

*However, as my assessment will reveal, much needs to be done to
freshen up Tkinter and IDLE, and I am not just asking for someone to
fix these problems. I have already coded solutions for most of them
however, some of course still need work, and i would like to hear from
others on this subject too. So buckle your seat belts folks, cause
here we go...

-
Python offical docs and Tkinter
-
*The Python docs barely cover anything related to actual Tkinter
coding. At the minimum the Tkinter doc page should have a subpage for
all the widgets available --which is very small(approx 15) and each
subpage should list the available methods on that wiget. Here are two
great resources that really like from Fredrik Lundh and John
Shipman...

  http://www.pythonware.com/library/tkinter/introduction/index.htm
  http://infohost.nmt.edu/tcc/help/pubs/tkinter/

...I must say that I prefer the latter written by John Shipman because
of the way he lists each widgets options in a nice table structure,
and then lists the methods below. And intersestingly enough, his
manual only weighs in at about 800kb completely uncommpressed and
unedited. I'll bet you a wooden nickel i can reduce it to around 500kb
for the official Python docs *wink*

*Sadly however neither of these great works is mentioned or linked in
the official docs Why?.

*I think a short-and-to-the-point reference, like the afore mentioned
along with a few links to full featured tuts would be a great addition
to the Tkinter section of the official docs and i would be happy to
help make this happen.

-
from Tkinter import *
-
*Too many noobs start out with the from Tkinter import * idiom,
unknowing that they are horribly polluting their namespace. I feel
that all (tkinter) code should follow the import Tkinter as tk
policy and never use from Tkinter import *. To push this agenda i
propose all docs be modified so that no one should see such global
import blasphemy again. We should at least keep all example code in
the latter non-polluting form and frown heavily upon global imports in
Tkinter code or any code for that matter.

-
Tkinter Constants
-
*The Tkconstants module needs to be removed *yesterday* because i
think it reinforces sloppy coding styles. The main problem is with
subtle bugs that are created when someone rebinds one or more of the
constants, for example W=20. At first i thought the constants were
great but I quickly found out the shortfalls of such a Utopian
approach . Since Tkinter allows strings to be passed-into widget
constructors, we should remove the TkConstants immediately and force
everyone to use strings instead...

 #-- instead of this --#
  w.pack(side=LEFT,fill=BOTH,anchor=W)

 #-- do this --#
  w.pack(side='left',fill='both',anchor='w')

The few extra keystrokes are well worth the effort!

-
IDLE Shell
-
*IDLE and Pyshell are great but have major flaws in design. One of my
biggest complaints is the shell's eight space indention which
completely bloats your screen! Another annoying fact is that the prompt
() is actually inside the text widget. This design is all wrong!
The prompt should be in another widget to the left of the text so it
never gets copied or pasted. Or at-least have the copy/paste action
remove the initial four spaces and the prompt, but i think a full
separation of prompt and text are the best solution. The following
ASCII art won't win me any awards, but it may covey my idea. W1
holds the prompt and W2 is the actual text editor.

 W1  W2 ---
  | for x in range(10): |
 ... |   print x   |
 ... | for y in range(x):  |
 ... |   print y   |
 |1
 |2

And don't tell me about Geany or Pythonwin or emacs or vim or whatever
editor happens to float your boat. I know there are tons of great
editors out there but IDLE is most likely the first one a Pynoob will
use so it must be usable! IDLE and Tkinter  are what make Python a
stater language -- after the beautiful syntax of course :)

-
IDLE Editor
-
*On M$ windows pressing the MMB without a motion causes the selected
text to be pasted at the insertion cursor, and holding it repeats the
action very quickly! Since IDLE has no 

variables of the class are not available as default values?

2009-08-27 Thread seanacais
I'm working on a program where I wish to define the default value of a
method as a value that was set in __init__.  I get a compilation error
saying that self is undefined.

As always a code snippet helps :-)

class foo:
def __init__(self, maxvalue):
self.maxvalue = maxvalue
self.value = 0

def put(self, value=self.maxvalue):
self.value = value

So if I call foo.put() the value is set to maxvalue but maxvalue can
be specified when I instantiate foo.

Explanations and/or workarounds much appreciated.



python test.py
Traceback (most recent call last):
  File test.py, line 1, in module
class foo:
  File test.py, line 6, in foo
def put(self, value=self.maxvalue):
NameError: name 'self' is not defined
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: variables of the class are not available as default values?

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 2:37 PM, seanacaiskccnos...@glenevin.com wrote:
 I'm working on a program where I wish to define the default value of a
 method as a value that was set in __init__.  I get a compilation error
 saying that self is undefined.

 As always a code snippet helps :-)

 class foo:
    def __init__(self, maxvalue):
        self.maxvalue = maxvalue
        self.value = 0

    def put(self, value=self.maxvalue):
        self.value = value

 So if I call foo.put() the value is set to maxvalue but maxvalue can
 be specified when I instantiate foo.

 python test.py
 Traceback (most recent call last):
  File test.py, line 1, in module
class foo:
  File test.py, line 6, in foo
def put(self, value=self.maxvalue):
 NameError: name 'self' is not defined

 Explanations and/or workarounds much appreciated.

Workaround:

class foo:
def __init__(self, maxvalue):
self.maxvalue = maxvalue
self.value = 0

def put(self, value=None):
self.value = self.value if value is None else value

Explanation:

Default values are only evaluated once, when the class is defined,
thus self is not defined at that point since the class is still
being defined when the method definition is executed and thus there
can be no instances yet anyway.

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


Re: How to unencode a string

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 2:10 PM, jakecjacobsonjakecjacob...@gmail.com wrote:
 This seems like a real simple newbie question but how can a person
 unencode a string?  In Perl I use something like: $part=~ s/\%([A-Fa-
 f0-9]{2})/pack('C', hex($1))/seg;

 If I have a string like Word1%20Word2%20Word3 I want to get Word1
 Word2 Word3.  Would also like to handle special characters like ',(){}
 [] etc/

Use the `uu` module together with the `stringio` module:
http://docs.python.org/library/uu.html
http://docs.python.org/library/stringio.html

Not sure about special character handling though.

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


Re: variables of the class are not available as default values?

2009-08-27 Thread Andre Engels
On Thu, Aug 27, 2009 at 11:37 PM, seanacaiskccnos...@glenevin.com wrote:
 I'm working on a program where I wish to define the default value of a
 method as a value that was set in __init__.  I get a compilation error
 saying that self is undefined.

 As always a code snippet helps :-)

 class foo:
    def __init__(self, maxvalue):
        self.maxvalue = maxvalue
        self.value = 0

    def put(self, value=self.maxvalue):
        self.value = value

 So if I call foo.put() the value is set to maxvalue but maxvalue can
 be specified when I instantiate foo.

 Explanations and/or workarounds much appreciated.

Explanation: The default value is calculated at the time the function
is defined, not at the time it is called. And at that time there is no
instance for self to refer to.

Workaround:


class foo:
def __init__(self, maxvalue):
self.maxvalue = maxvalue
self.value = 0

def put(self, value=None):
if value is None:
self.value = self.maxvalue
else:
self.value = value


-- 
André Engels, andreeng...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regexp help

2009-08-27 Thread Mart.
On Aug 27, 7:15 pm, Bakes ba...@ymail.com wrote:
 If I were using the code:

 (?Pdata[0-9]+)

 to get an integer between 0 and 9, how would I allow it to register
 negative integers as well?

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


Re: Python on the Web

2009-08-27 Thread Phil
Haha. While I don't disagree with you, I seem to be under the
impression that you think I haven't been reading the web where nearly
every blog post complains about the abundance of Python frameworks.
The thing is, most of the frameworks being commented on in such a way
are 'microframeworks' that provide next to nothing. I'm do not mean to
say anything negative about them, but I strongly feel that my approach
will be much more functional without having to include, or at least a
good starting point for newcomers to both Python and web programming.
The ideas I had for mine lied somewhere in between a full stack
framework and a minimalist approach like said microframeworks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to unencode a string

2009-08-27 Thread MRAB

jakecjacobson wrote:

This seems like a real simple newbie question but how can a person
unencode a string?  In Perl I use something like: $part=~ s/\%([A-Fa-
f0-9]{2})/pack('C', hex($1))/seg;

If I have a string like Word1%20Word2%20Word3 I want to get Word1
Word2 Word3.  Would also like to handle special characters like ',(){}
[] etc/


The Python equivalent of your regular expression code is:

 import re
 s = Word1%20Word2%20Word3
 re.sub(r%([A-Fa-f0-9]{2}), lambda m: chr(int(m.group(1), 16)), s)
'Word1 Word2 Word3'

The replacement is a lambda expression (an anonymous function), which is
called for each match with the match object and it works like this:

m# m is the match object
m.group(1)   # get group 1 (the 2 hex digits)
int(m.group(1), 16)  # convert to an integer
chr(int(m.group(1), 16)) # convert to a character
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Class implements Interface?

2009-08-27 Thread Emanuele D'Arrigo
On Aug 27, 9:42 pm, Jonathan Gardner jgard...@jonathangardner.net
wrote:
 Have you heard of duck typing?

Yes.

 Ignore all those things and rely on human (aka natural language)
 documentation. That is, if you want to see if a class will work for an
 interface, go read the docs on the interface (or rather, what the
 function expects the interface to be) and what the class provides and
 see if they fit.

Apologies, my fault, I didn't explain that humans are out of the loop
entirely. It's only at runtime that the program obtains the class
object that might or might not conform to an expected interface. In
fact the program might obtain multiple objects and have to decide
which one conforms best to the expected interface. Of course I could
use hasattr() and the inspect module (anything else?) to find out if
existing attributes and method signatures are those expected. Or I
could just deal with the exceptions as they are raised. However, if I
could somehow rely that the object I'm getting has the right methods
and signatures I could avoid peppering the code with try/except
constructs.

I was just wondering then if this has been somewhat dealt with and has
been wrapped in a neat package, set of functions, recipe or pattern.

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


Re: How to unencode a string

2009-08-27 Thread Stephen Fairchild
jakecjacobson wrote:

 This seems like a real simple newbie question but how can a person
 unencode a string?  In Perl I use something like: $part=~ s/\%([A-Fa-
 f0-9]{2})/pack('C', hex($1))/seg;
 
 If I have a string like Word1%20Word2%20Word3 I want to get Word1
 Word2 Word3.  Would also like to handle special characters like ',(){}
 [] etc/

import urllib
print urllib.unquote(Word1%20Word2%20Word3)
-- 
Stephen Fairchild
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Class implements Interface?

2009-08-27 Thread Jonathan Gardner
On Aug 27, 3:09 pm, Emanuele D'Arrigo man...@gmail.com wrote:

 Apologies, my fault,

No apology is necessary.

 I didn't explain that humans are out of the loop
 entirely. It's only at runtime that the program obtains the class
 object that might or might not conform to an expected interface. In
 fact the program might obtain multiple objects and have to decide
 which one conforms best to the expected interface. Of course I could
 use hasattr() and the inspect module (anything else?) to find out if
 existing attributes and method signatures are those expected. Or I
 could just deal with the exceptions as they are raised. However, if I
 could somehow rely that the object I'm getting has the right methods
 and signatures I could avoid peppering the code with try/except
 constructs.

 I was just wondering then if this has been somewhat dealt with and has
 been wrapped in a neat package, set of functions, recipe or pattern.


Don't bother with introspection using hasattr() and such. Use
exceptions. If the object that is instantiated at run-time doesn't
provide the right interface, throw an exception and direct it to the
responsible party.

This isn't much different than what you'd do if you're writing an app
that expects a string of digits but is instead given a string of non-
digits. Rather than inspecting the string before converting it
(introspection), just try to convert it and catch the exception. Then
handle the exception such that you tell the person who entered the
data, I wanted numbers, not letters and allow them to try again.

When you stop asking Did I get something I expect? except only when
it is absolutely necessary, then you can get back to writing your
program.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Class implements Interface?

2009-08-27 Thread Jonathan Gardner
On Aug 27, 3:09 pm, Emanuele D'Arrigo man...@gmail.com wrote:
 On Aug 27, 9:42 pm, Jonathan Gardner jgard...@jonathangardner.net
 wrote:

  Have you heard of duck typing?

 Yes.

 I was just wondering then if this has been somewhat dealt with and has
 been wrapped in a neat package, set of functions, recipe or pattern.


As a joke (but only partly), here's the python code you'd use to check
to see if a value conforms with expectations:

code
/code

As you can see, the above code is not only easy to write, but easy to
write unit tests for, compile, run, and debug. It simply doesn't get
better than this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: variables of the class are not available as default values?

2009-08-27 Thread seanacais
On Aug 27, 5:44 pm, Chris Rebert c...@rebertia.com wrote:
 On Thu, Aug 27, 2009 at 2:37 PM, seanacaiskccnos...@glenevin.com wrote:
  I'm working on a program where I wish to define the default value of a
  method as a value that was set in __init__.  I get a compilation error
  saying that self is undefined.

  As always a code snippet helps :-)

  class foo:
     def __init__(self, maxvalue):
         self.maxvalue = maxvalue
         self.value = 0

     def put(self, value=self.maxvalue):
         self.value = value

  So if I call foo.put() the value is set to maxvalue but maxvalue can
  be specified when I instantiate foo.
  python test.py
  Traceback (most recent call last):
   File test.py, line 1, in module
     class foo:
   File test.py, line 6, in foo
     def put(self, value=self.maxvalue):
  NameError: name 'self' is not defined
  Explanations and/or workarounds much appreciated.

 Workaround:

 class foo:
     def __init__(self, maxvalue):
         self.maxvalue = maxvalue
         self.value = 0

     def put(self, value=None):
         self.value = self.value if value is None else value

 Explanation:

 Default values are only evaluated once, when the class is defined,
 thus self is not defined at that point since the class is still
 being defined when the method definition is executed and thus there
 can be no instances yet anyway.

 Cheers,
 Chris
 --http://blog.rebertia.com

That clears that up for me.   Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Algorithms as objects?

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 4:05 PM,
Kresokkumnotthi...@thatsearchenginesguglsemail.com wrote:

 I am writing an application that essentially calculates set of numbers,
 say N1, N2, ..., where they can be calculated by several different
 algorithms. (One should be able to choose the algorithm at run time.)
 In each algorithm one starts from a set of functions, say f1, f2, ...,
 which are then transformed into some other functions g1(f1, f2, ..),
 g2(f1, f2, ...), ... , then maybe transformed once more and result is
 obtained by evaluating final functions.
  I can naturally think about this as a collection of transformation
 blocks, which have functions as input and output, and which can be
 put together to get the final results. However, I am not sure
 how to program this, especially since one cannot subclass function
 type. To be clear let me give simplified example of what is needed:

 f(x) has unknown shape, so one would like to try, say

 f1(x) = ax - b x**2   or    f2(x) = a sin(b*x),

 where a and b are variable parameters.

 Then, one would like to create, with known k(x,y), function g(x)
 in one of two ways:

 g1(x) = k(x, x)*f(x)  or   g2(x) = integrate(k(x, y) * f(y), y=0..1),

 and finally evaluate N=g(1) as result. In this simple example
 there are 4 different algorithms  for f(x) - g(x) - N, and one
 should be able to simply choose between them, e.g. by calling
 N(g1, f2, (a,b)).

 In practice algorithm is not necessary so linear,  but is
 generally tree-lika:

 (a,b) - f1(x) ---g1(x)---+
                           |-- h(x) -- N
 (c,d) ---+-- g2(x)+
         |
  f2(x) --+


 It would be nice to have some class of function-objects,
 that f1(x), .., g1(x), ... could be members/instances of so that common
 operations on these functions could be possible (checking
 that they satisfy some necessary properties, plotting them, ...),
 and then second class of transformations/methods operating on
 these objects.
 I seem to be confused by the fact that I would like to somehow treat
 algorithms as objects (so that one can experiment with different
 algorithm systems) but I don't have clear picture how to do it.
 I am just brainstorming for ideas. Any advice is welcome.

It sounds like you're describing the Strategy Pattern
(http://en.wikipedia.org/wiki/Strategy_pattern).

To have objects callable like functions, just implement the  __call__
special method in your class(es):
http://docs.python.org/reference/datamodel.html#object.__call__

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


Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-27 Thread Mensanator
On Aug 27, 2:26 pm, Piet van Oostrum p...@cs.uu.nl wrote:
  Mensanator mensana...@aol.com (M) wrote:
 M On Aug 26, 4:59 pm, Piet van Oostrum p...@cs.uu.nl wrote:
   Mensanator mensana...@aol.com (M) wrote:
  M That's my point. Since the common usage of binary is for
  M Standard Positional Number System of Radix 2, it follows
  M that unary is the common usage for Standard Positional
  M Number System of Radix 1. That's VERY confusing since such
  M a system is undefined. Remember, common usage does not
  M necessarily properly define things. Saying simply unary
  M sounds like you're extending common usage beyond its proper
  M boundaries.

  But the customary meaning of `unary' is the tally system, as a radix
  system wouldn't make sense. I don't know when this term came into use
  but I have known it for a long time.
 M Ok, I'll accept that and in the same breath say such common usage
 M is stupid. I, for one, have never heard such usage and would never
 M use unary in the same breath as decimal, octal, binary even if
 M I had.

 As I see it, unary just means that there is one symbol. Binary just
 means that there are two symbols, etc.

Right, and neither word, by itself, gives the full meaning.


 With unary, the only sensible numerical interpretation is to count the
 number of occurrences of that symbol, or if you also want to have the
 number 0, the number of occurrences - 1.

Trouble is, nothing's stopping you from making a non-sensible
interpretation.


 With binary and higher you can come up with more numerical
 interpretations but the most efficient one is the radix interpretation
 (for different values of `efficient'). I doubt that there are many other
 interpretations that you can call sensible.

But not impossible. You could have a base-3 tally system for ticking
off how many cars on a three lane road pass a given point. And you can
have mixed radix systems (pounds, shillings, pence or degrees, minutes
seconds).

 Therefore we immediately
 think of a radix system when we talk about binary, octal, decimal etc.
 But the word `binary' itself doesn't imply that.

Just as unary doesn't imply that it's an extension of binary made by
simply changing the base because there's more to it than that.
Yet, I constantly run into people who get confused by this. As a
result, I will never use the word unary even if it is considered
acceptable. If I'm trying to imply some sort of base-1 system,
I'll explain what I'm talking about and not assume the listener
will fully understand what is meant by unary.

 --
 Piet van Oostrum p...@cs.uu.nl
 URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
 Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


PyGTK problems after Linux update...

2009-08-27 Thread barcaroller

I use a python-based program called 'meld' which worked fine until my latest 
Fedora11/KDE4.3 update; it now gives me the following error:

prompt meld

/usr/lib/python2.6/site-packages/gtk-2.0/glib/_glib.so: undefined 
symbol: PyUnicodeUCS4_DecodeUTF8
Meld requires pygtk 2.8.0 or higher.


If I run another GTK-based utility, I also get errors:

prompt gedit

** (gedit:28289): WARNING **: Error initializing Python interpreter: 
could not import pygtk.



I have installed the latest PyGTK (pygtk-2.14.1), to no avail.  Googling 
these messages have also produced no major results.  When I run 
'pygtk-demo', I get the following errors:

prompt python /usr/lib/pygtk/2.0/pygtk-demo.py

Traceback (most recent call last):
File /usr/lib/pygtk/2.0/pygtk-demo.py, line 18, in module
import gobject
File /usr/lib/python2.6/site-packages/gtk-2.0/gobject/__init__.py, 
line 33, in module
from glib import spawn_async, idle_add, timeout_add, 
timeout_add_seconds, \
File /usr/lib/python2.6/site-packages/gtk-2.0/glib/__init__.py, line 
30, in module
from glib._glib import *
ImportError: /usr/lib/python2.6/site-packages/gtk-2.0/glib/_glib.so: 
undefined symbol: PyUnicodeUCS4_DecodeUTF8


Does anyone know what needs to be done to resolve this?  Using Python 2.6.2 
on Fedora11/KDE4.3 32-bit i386/i586/i686.




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


printing from child process in Tkinter window

2009-08-27 Thread Dan Upton
Hi all,

I've been messing with this for a couple hours now but can't make it work.
Basically I have a Tkinter GUI that creates a child process via
subprocess.Popen, and I would like to capture the child process's output to
display it in a Text widget in the GUI.  Relevant snippets:

def click_start: #launch from clicking a button in the gui
   ...
   self.apppipe = Popen(cmdString, shell=True, stdout=PIPE, stderr=PIPE)
   self.master.after(200, self.readAppStdout)
   ...

def readAppStdout(self):
   readers, writers, exceptionals = select.select( [self.apppipe.stdout],
[], [], 0.001)
   if readers != []:
  pipetext = self.apppipe.stdout.readline()
  self.appoutput.insert(END, pipetext) #self.appoutput is the Text
widget

   (same for apppipe.stderr)
   self.master.after(200, self.readAppStdout)

I don't ever get any output in my window, even though I've waited long
enough that the application would otherwise have printed to the console
(based on its graphical outputs).  Any suggestions for what I'm doing wrong?

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


Re: Need help with Python scoping rules

2009-08-27 Thread kj

Miles Kaufmann mile...@umich.edu writes:

On Aug 26, 2009, at 1:11 PM, kj wrote:
 I think I understand the answers well enough.  What I *really*
 don't understand is why this particular feature of Python (i.e.
 that functions defined within a class statement are forbidden from
 seeing other identifiers defined within the class statement) is
 generally considered to be perfectly OK.  IMO it's a bizarre,
 inexplicable blindspot (which, among other things, gives rise to
 a certain worry about what other similar craziness lurks under
 Python's image of rationality).  I have never seen even a half-hearted
 justification, from a language design point of view, for why this
 particular feature is worth having.

Guido's design justifications:
http://mail.python.org/pipermail/python-dev/2000-November/010598.html

Ah!  Clarity!  Thanks!  How did you find this?  Did you know of
this post already?  Or is there some special way to search Guido's
design justifications?

...because the suite  
namespace and the class namespace would get out of sync when different  
objects were assigned to the class namespace:

class C:
   x = 1
   def foo(self):
   print x
   print self.x

  o = C()
  o.foo()
1
1
  o.x = 2
  o.foo()
1
2

But this unfortunate situation is already possible, because one
can already define

class C:
   x = 1
   def foo(self):
   print C.x
   print self.x

which would lead to exactly the same thing.

I need to learn more about metaclasses, though, to fully understand
your post.

Many thanks!

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


Re: Algorithms as objects?

2009-08-27 Thread Bearophile
Chris Rebert:

 It sounds like you're describing the Strategy Pattern
 (http://en.wikipedia.org/wiki/Strategy_pattern).

 To have objects callable like functions, just implement the  __call__
 special method in your class(es):

Please, can't you just use a bit of functional-style programming? Like
creating nested functions on the fly, etc.

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


why python got less developers ?

2009-08-27 Thread Deep_Feelings
python got relatively fewer numbers of developers than other high
level languages like .NET , java .. etc  why ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Annoying octal notation

2009-08-27 Thread Mel
Steven D'Aprano wrote:

 Leading zeroes in decimal numbers are *very* common in dates and times.

In banking too, according to someone at work today.

Mel.


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


Re: why python got less developers ?

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 5:34 PM, Deep_Feelingsdoctore...@gmail.com wrote:
 python got relatively fewer numbers of developers than other high
 level languages like .NET , java .. etc  why ?

We lack Sun and Microsoft's massive marketing departments. :)

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


Re: why python got less developers ?

2009-08-27 Thread MRAB

Deep_Feelings wrote:

python got relatively fewer numbers of developers than other high
level languages like .NET , java .. etc  why ?


Fewer needed?
--
http://mail.python.org/mailman/listinfo/python-list


Re: why python got less developers ?

2009-08-27 Thread Gary Herron

Deep_Feelings wrote:

python got relatively fewer numbers of developers than other high
level languages like .NET , java .. etc  why ?
  


Perhaps because we value QUALITY over QUANTITY ...

Gary Herron


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


Re: break unichr instead of fix ord?

2009-08-27 Thread rurpy
On 08/26/2009 11:51 PM, Martin v. Löwis wrote:
 [...]
   But regardless, the significant question is, what is
   the reason for having ord() (and unichr) not work for
   surrogate pairs and thus not usable with a large number
   of unicode characters that Python otherwise supports?
 
  See PEP 261, http://www.python.org/dev/peps/pep-0261/
  It specifies all this.

The PEP (AFAICT) says only what we already know... that
on narrow builds unichr() will raise an exception with
an argument = 0x1, and ord() is unichr()'s inverse.

I have read the PEP twice now and still see no justification
for that decision, it appears to have been made by fiat.[*1]

Could you or someone please point me to specific justification
for having unichr and ord work only for a subset of unicode
characters on narrow builds, as opposed to the more general
and IMO useful behavior proposed earlier in this thread?

--
[*1]
The PEP says:
 * unichr(i) for 0 = i  2**16 (0x1) always returns a
   length-one string.

 * unichr(i) for 2**16 = i = TOPCHAR will return a
   length-one string on wide Python builds. On narrow
   builds it will raise ValueError.
and
 * ord() is always the inverse of unichr()

which of course we know; that is the current behavior.  But
there is no reason given for that behavior.

Under the second *unicode bullet point, there are two issues
raised:
   1) Should surrogate pairs be disallowed on narrow builds?
That appears to have been answered in the negative and is
not relevant to my question.
   2) Should access to code points above TOPCHAR be allowed?
Not relevant to my question.

 * every Python Unicode character represents exactly
   one Unicode code point (i.e. Python Unicode
   Character = Abstract Unicode character)

I'm not sure what this means (what's an abstract unicode
character?).  If it mandates that u'\ud800\udc40' be
treated as a len() 2 string, that is that current case
but does not say anything about how unichr and ord
should behave.  If it mandates that that string must
always be treated as two separate code points then
Python itself violates by printing that string as
u'\U00010040' rather than u'\ud800\udc40'.

Finally we read:

 * There is a convention in the Unicode world for
   encoding a 32-bit code point in terms of two
   16-bit code points. These are known as
   surrogate pairs. Python's codecs will adopt
   this convention.

Is a distinction made between Python and Python
codecs with only the latter having any knowledge of
surrogate pairs?  I guess that would explain why
Python prints a surrogate pair as a single character.
But this seems arbitrary and counter-useful if
applied to ord() and unichr().  What possible
use-case is there for *not* recognizing surrogate
pairs in those two functions?

Nothing else in the PEP seems remotely relevant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] How do I reply to a thread by sending a message to python-list@python.org

2009-08-27 Thread Ben Finney
Terry Reedy tjre...@udel.edu writes:

 In particular, because there is no indication that it is an exact
 duplicate of what I will also find on the list itself. Please use
 reply instead of reply-all.

Better: If you don't want to reply to the author directly, and you don't
want to reply to everyone, don't use “reply to author” or “reply to
all”.

When replying to the list, use the “reply to list” command of your mail
client. This will, in a standards-compliant mail client, reply to the
posting address for the list (declared in the message header via the RFC
2369 ‘List-Post’ field, added automatically by every common mailing list
system), without a copy to the sender.

Thunderbird has a long-outstanding bug report requesting this feature
URL:https://bugzilla.mozilla.org/show_bug.cgi?id=45715, which is
apparently fixed in recent versions. Before that bug was fixed, an
add-on URL:http://www.juergen-ernst.de/addons/replytolist.html was
developed to add it in a different way.

If you're using a different mail client, look for the “reply to list”
command, and if it's not there (or doesn't work correctly), report it to
the vendor as a bug and/or switch to one of the many alternative MUAs
that get it right.

-- 
 \  “I think it would be a good idea.” —Mahatma Gandhi (when asked |
  `\  what he thought of Western civilization) |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with Python scoping rules

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 9:49 AM, kj no.em...@please.post wrote:


 Miles Kaufmann mile...@umich.edu writes:

 ...because the suite
 namespace and the class namespace would get out of sync when different
 objects were assigned to the class namespace:

 class C:
x = 1
def foo(self):
print x
print self.x

   o = C()
   o.foo()
 1
 1
   o.x = 2
   o.foo()
 1
 2


I haven't tested either codes, but that isn't out of sync. Your x = 1 is a
static variable, and shared between all isntances of class C.


 But this unfortunate situation is already possible, because one
 can already define

 class C:
   x = 1
   def foo(self):
print C.x
   print self.x

 which would lead to exactly the same thing.


It works because you're simply explicitly referring to the class's local
scope, which leads to the same result.

Again, that's just my understanding of the implementation.

Cheers,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for professsional Windows GUI apps?

2009-08-27 Thread Peter Decker
On Wed, Aug 26, 2009 at 4:47 PM, David C Ullrichdullr...@sprynet.com wrote:
 On Mon, 24 Aug 2009 22:22:20 -0700, sturlamolden wrote:

 On 25 Aug, 05:56, Peter Decker pydec...@gmail.com wrote:

 I use the Dabo Class Designer to visually design my forms. So what's
 you're point?  :)

 Nothing, except lobbying for wxFormBuilder for anyone who still doesn't
 know of it. :)

 That's great. But do you know of anything I can use as a
 visual form design tool in wxPython?

You mean you prefer the wxPython style of coding? No, I don't know
what's available. Once I discovered that Dabo is the smart way to get
all the benefits of wxPython without the ugly C++ style of coding, I
haven't used raw wxPython.

-- 

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


Re: regexp help

2009-08-27 Thread Paul McGuire
On Aug 27, 1:15 pm, Bakes ba...@ymail.com wrote:
 If I were using the code:

 (?Pdata[0-9]+)

 to get an integer between 0 and 9, how would I allow it to register
 negative integers as well?

With that + sign in there, you will actually get an integer from 0 to
9...

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


Re: why python got less developers ?

2009-08-27 Thread Esam Qanadeely
On Aug 28, 3:46 am, Chris Rebert c...@rebertia.com wrote:
 On Thu, Aug 27, 2009 at 5:34 PM, Deep_Feelingsdoctore...@gmail.com wrote:
  python got relatively fewer numbers of developers than other high
  level languages like .NET , java .. etc  why ?

 We lack Sun and Microsoft's massive marketing departments. :)

 Cheers,
 Chris
 --http://blog.rebertia.com

any technical reasons ??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with Python scoping rules

2009-08-27 Thread Stephen Fairchild
kj wrote:

 But this unfortunate situation is already possible, because one
 can already define
 
 class C:
 x = 1
 def foo(self):
 print C.x
 print self.x

How is this a problem? There is no ambiguity between the global scope and
the local from within foo.

From within foo C is accessed from the global scope having not found it as a
local. Once you have C C.x is just one step away. 

Variable self is local to function foo since it was passed in as a parameter
from the method which wraps it. 

Variable self refers to a class instance which contains a dictionary.
Variable x is absent from the instance dictionary so the class
self.__class__ is referenced, again from local scope to find x. If it
wasn't found there the superclasses would have been searched before
throwing an attribute error.

It seems to me, you are confusing instance creation with class creation.
-- 
Stephen Fairchild
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why python got less developers ?

2009-08-27 Thread Benjamin Kaplan
On Thu, Aug 27, 2009 at 10:12 PM, Esam Qanadeelydoctore...@gmail.com wrote:
 On Aug 28, 3:46 am, Chris Rebert c...@rebertia.com wrote:
 On Thu, Aug 27, 2009 at 5:34 PM, Deep_Feelingsdoctore...@gmail.com wrote:
  python got relatively fewer numbers of developers than other high
  level languages like .NET , java .. etc  why ?

 We lack Sun and Microsoft's massive marketing departments. :)

 Cheers,
 Chris
 --http://blog.rebertia.com

 any technical reasons ??
 --

Not really. It's mostly because of the lack of marketing departments
and pieces of paper to placate business majors (what Microsoft and Sun
call certification)

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

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


Re: Need help with Python scoping rules

2009-08-27 Thread Miles Kaufmann

On Aug 27, 2009, at 4:49 PM, kj wrote:


Miles Kaufmann mile...@umich.edu writes:

Guido's design justifications:
http://mail.python.org/pipermail/python-dev/2000-November/010598.html


Ah!  Clarity!  Thanks!  How did you find this?  Did you know of
this post already?  Or is there some special way to search Guido's
design justifications?


I just checked the python-dev archives around the time that PEP 227  
was written.



...because the suite
namespace and the class namespace would get out of sync when  
different

objects were assigned to the class namespace:



class C:
x = 1
def foo(self):
print x
print self.x



o = C()
o.foo()

1
1

o.x = 2
o.foo()

1
2


But this unfortunate situation is already possible, because one
can already define

class C:
 x = 1
 def foo(self):
 print C.x
 print self.x

which would lead to exactly the same thing.


You're right, of course.  If I had been thinking properly, I would  
have posted this:


... the suite namespace and the class namespace would get out of sync  
when different objects were assigned to the class namespace:


   # In a hypothetical Python with nested class suite scoping:
   class C:
   x = 1
   @classmethod
   def foo(cls):
   print x
   print cls.x

C.foo()
   1
   1
C.x = 2
C.foo()
   1
   2

With your example, the result is at least easily explainable: self.x  
is originally 1 because the object namespace inherits from the class  
namespace, but running 'o.x = 2' rebinds 'x' in the object namespace  
(without affecting the class namespace).  It's a distinction that  
sometimes trips up newbies (and me, apparently ;) ), but it's  
straightforward to comprehend once explained.  But the distinction  
between the class suite namespace and the class namespace is far more  
subtle; extending the lifetime of the first so that it still exists  
after the second is created is, IMO, asking for trouble (and trying to  
unify the two double so).


-Miles

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


Re: why python got less developers ?

2009-08-27 Thread r
On Aug 27, 7:34 pm, Deep_Feelings doctore...@gmail.com wrote:
 python got relatively fewer numbers of developers than other high
 level languages like .NET , java .. etc  why ?

Ugh? Well maybe if you put some deep_thoughts into this conundrum you
may reveal the answer to your self. Python is an interpreted
scripting, glue, and sys administation language. As long as Java
can be complied strait to machine code and constantly run light years
faster than Python Java will always win in this area. But who cares,
Python is not meant for writing OS's or 3D games of the year, and i am
quite happy it is made to be that way. Python will never be as popular
as C, Java, etc for all these reasons. And since your chances of
making a living writing Java code verses Python code are absolute,
then of course that is where the pros will go.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with Python scoping rules

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 1:27 PM, Miles Kaufmann mile...@umich.edu wrote:

 You're right, of course.  If I had been thinking properly, I would have
 posted this:

 ... the suite namespace and the class namespace would get out of sync when
 different objects were assigned to the class namespace:


I'm not an expert on Python, but could you define out of sync for me? When
you call the class as a new instance and assign it to a new variable, the
class attributes (self.x) are independent for each instance. The static
variables in the class (x, or C.x in this case) is shared between all
instances of this class.


   # In a hypothetical Python with nested class suite scoping:


Class already provides some kind of scoping/namespace, that is the locals()
method for the class. What is pypothetical about this, if you could
elaborate?

snips the code

With your example, the result is at least easily explainable: self.x is
 originally 1


Incorrect. self.x (or cls.x in your sample code) doesn't exist until you
called o.x = 2, which sets cls.x = 2.

Don't be confused between static variables that are initialised at class
creation, and the class attributes which usually is declared inside the
__init__ method.


 because the object namespace inherits from the class namespace, but running
 'o.x = 2' rebinds 'x' in the object namespace (without affecting the class
 namespace).


See above comment.


 It's a distinction that sometimes trips up newbies (and me, apparently ;)
 ), but it's straightforward to comprehend once explained.  But the
 distinction between the class suite namespace and the class namespace is far
 more subtle; extending the lifetime of the first so that it still exists
 after the second is created is, IMO, asking for trouble (and trying to unify
 the two double so).


It is. I had trouble getting it also, but once I think of all the variables
outside of the __init__() method as static, and the ones within as class
attributes, everything clears out just fine. =]

Any corrections appreciated. I'm merely posting my understanding of Python.

Cheers,
- Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with Python scoping rules

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 1:48 PM, Xavier Ho cont...@xavierho.com wrote:


 Class already provides some kind of scoping/namespace, that is the locals()
 method for the class. What is pypothetical about this, if you could
 elaborate?


Obviously that was supposed to be hypothetical. Oops.
-- 
http://mail.python.org/mailman/listinfo/python-list


Transforming a str to an operator

2009-08-27 Thread Duke Normandin
Hey

I'm a Python noob

So far so good!

I've written the following:

num1 = raw_input('Enter the first number: ')
num2 = raw_input('Enter the second number: ')
op = raw_input('Select one of the following [+-*/]: ')
print 'The answer is: ', int(num1), eval(op), int(num2)


How do I convert the contents of op from a string to an actual
arithmetic operator? eval() does not seem to be the answer. TIA!
-- 
duke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Transforming a str to an operator

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 1:52 PM, Duke Normandin dukeofp...@ml1.net wrote:

 How do I convert the contents of op from a string to an actual
 arithmetic operator? eval() does not seem to be the answer. TIA!


Maybe you were looking for

print eval(num1 + op + num2) # it's a little ugly string concatenation.

Hm? (untested, but it works in my head.)

Cheers,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Transforming a str to an operator

2009-08-27 Thread r
On Aug 27, 10:52 pm, Duke Normandin dukeofp...@ml1.net wrote:
 How do I convert the contents of op from a string to an actual
 arithmetic operator? eval() does not seem to be the answer. TIA!


Try this..

 op = '+'
 one = '1'
 two = '2'
 one+op+two
'1+2'
 eval(one+op+two)
3


you could also use string formatting.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Transforming a str to an operator

2009-08-27 Thread Stephen Hansen

 num1 = raw_input('Enter the first number: ')
 num2 = raw_input('Enter the second number: ')
 op = raw_input('Select one of the following [+-*/]: ')
 print 'The answer is: ', int(num1), eval(op), int(num2)


 How do I convert the contents of op from a string to an actual
 arithmetic operator? eval() does not seem to be the answer. TIA!


You could eval(num1+op+num2), but it'd be safer to do:

import operator
operators = {+: operator.add, -: operator.sub, *: operator.mul, /:
operator.div}
fn = operators[op]
print The answer is:, fn(int(num1), int(num2))

Its best to avoid eval when possible :)

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


Re: Question on the csv library

2009-08-27 Thread John Machin
On Aug 28, 6:44 am, Mark Lawrence breamore...@yahoo.co.uk wrote:
 vsoler wrote:
  On Aug 27, 9:42 pm, Andreas Waldenburger use...@geekmail.invalid

  1- the csv file was generated with Excel 2007; no prompts for what the
  separator should be; Excel has used ; by default, without asking
  anything

 I find this difficult to believe,

Mark, there exist parallel universes the denizens of which use strange
notation e.g. 1.234,56 instead of 1,234.56 and would you believe they
use ';' instead of ',' as a list separator ... Excel perfidiously
gives them what they expect rather than forcing them to comply with
The One True Way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Transforming a str to an operator

2009-08-27 Thread Ben Finney
Duke Normandin dukeofp...@ml1.net writes:

 Hey

 I'm a Python noob

 So far so good!

 I've written the following:

 num1 = raw_input('Enter the first number: ')
 num2 = raw_input('Enter the second number: ')
 op = raw_input('Select one of the following [+-*/]: ')
 print 'The answer is: ', int(num1), eval(op), int(num2)
 

 How do I convert the contents of op from a string to an actual
 arithmetic operator? eval() does not seem to be the answer. TIA!

In general, ‘eval’ on unsanitised input is not the answer.

I would use the following approach:

import operator

op_funcs = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.div,
}

num_1 = int(raw_input('Enter the first number: '))
num_2 = int(raw_input('Enter the second number: '))
op_prompt = (
Select an operator 
+ [ + .join(s for s in op_funcs.keys()) + ]
+ : )
op_symbol = raw_input(op_prompt)
op_func = op_funcs[op_symbol]
print 'The answer is: ', op_func(num_1, num_2)

This has several advantages:

* The input isn't evaluated directly as code.

* The operator symbols are specified in one place, the ‘op_funcs’
  mapping; if you want to change the set of possible operators, you just
  change it there.

* If the input results in an operator that's not defined, it won't
  attempt to perform it; instead, a simple KeyError will result when
  trying to find the corresponding operator function.

-- 
 \   “I do not believe in immortality of the individual, and I |
  `\consider ethics to be an exclusively human concern with no |
_o__)  superhuman authority behind it.” —Albert Einstein, letter, 1953 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Transforming a str to an operator

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 2:35 PM, Ben Finney
ben+pyt...@benfinney.id.auben%2bpyt...@benfinney.id.au
 wrote:

import operator

op_funcs = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.div,
}

num_1 = int(raw_input('Enter the first number: '))
num_2 = int(raw_input('Enter the second number: '))
op_prompt = Select an operator ({}):.format(','.join(op for op in
 op_funcs))

   op_symbol = raw_input(op_prompt)
op_func = op_funcs[op_symbol]
print 'The answer is: ', op_func(num_1, num_2)


Just fixing the code a little to be more Pythonic ;).

Might also want to do exception handling, but with a program this small,
meh.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why python got less developers ?

2009-08-27 Thread Stefan Behnel
r wrote:
 As long as Java
 can be complied strait to machine code

I think you meant compared here.

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


Re: why python got less developers ?

2009-08-27 Thread Esam Qanadeely
who cares if a language is compiled or interpreted as long as it runs
and perform the function.

second thing is : even if java is faster than python , unless you are
making performance critical operations : who cares? computers are
getting faster all the time and languages like python or ruby are fast
enough.

any comment ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why python got less developers ?

2009-08-27 Thread Esam Qanadeely
i meant fast enough for most (but not all) applications
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Transforming a str to an operator

2009-08-27 Thread r
On Aug 27, 11:35 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:
 In general, ‘eval’ on unsanitised input is not the answer.

Yes i agree.

 I would use the following approach:

Abviously the OP is a python baby noob and casting your irrational
fear (and many others irrational fears) of eval at him is akin to
tales of Chupacabras running a muck in the jungle sucking the blood
from live goats in the twilight hours. I use eval all the time and
quite love it.

This is nothing more than a throw away academic exercise that will
serve no useful purpose for him in the future, but serves the very
useful purpose now of establishing an IO between the student and
Python interpretor. I'll bet most your example (albeit a good example)
flew miles above his head into la-la land.

The OP has plenty of time to learn about malicious input and
protecting against it, right now the fundamentals are well...
fundamental :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why python got less developers ?

2009-08-27 Thread Tim Roberts
Deep_Feelings doctore...@gmail.com wrote:

python got relatively fewer numbers of developers than other high
level languages like .NET , java .. etc  why ?

How do you know, and why does it matter?

By the way, .NET is not a language.  I assume you meant C#.
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Class implements Interface?

2009-08-27 Thread Max Landaeus


Emanuele D'Arrigo wrote:

On Aug 27, 9:42 pm, Jonathan Gardner jgard...@jonathangardner.net
wrote:
  

Have you heard of duck typing?



Yes.

  

Ignore all those things and rely on human (aka natural language)
documentation. That is, if you want to see if a class will work for an
interface, go read the docs on the interface (or rather, what the
function expects the interface to be) and what the class provides and
see if they fit.



Apologies, my fault, I didn't explain that humans are out of the loop
entirely. It's only at runtime that the program obtains the class
object that might or might not conform to an expected interface. In
fact the program might obtain multiple objects and have to decide
which one conforms best to the expected interface. Of course I could
use hasattr() and the inspect module (anything else?) to find out if
existing attributes and method signatures are those expected. Or I
could just deal with the exceptions as they are raised. However, if I
could somehow rely that the object I'm getting has the right methods
and signatures I could avoid peppering the code with try/except
constructs.

I was just wondering then if this has been somewhat dealt with and has
been wrapped in a neat package, set of functions, recipe or pattern.

Manu
  
Check out Alex Martelli's recipe 'Checking wheter an object has 
necessary attributes' in the Python Cookbook:
http://books.google.co.uk/books?id=Q0s6Vgb98CQCprintsec=frontcoverdq=python+cookbook#v=onepageq=f=false 
http://books.google.co.uk/books?id=Q0s6Vgb98CQCprintsec=frontcoverdq=python+cookbook#v=onepageq=f=false


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


Re: why python got less developers ?

2009-08-27 Thread Esam Qanadeely
On Aug 28, 8:27 am, Tim Roberts t...@probo.com wrote:
 Deep_Feelings doctore...@gmail.com wrote:

 python got relatively fewer numbers of developers than other high
 level languages like .NET , java .. etc  why ?

 How do you know, and why does it matter?

 By the way, .NET is not a language.  I assume you meant C#.
 --
 Tim Roberts, t...@probo.com
 Providenza  Boekelheide, Inc.

you know when you go to forums and compare the number of posts and
topics ,and you know when you google and compare the number of results

.NET= i meant all .NET languages
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why python got less developers ?

2009-08-27 Thread r
On Aug 27, 7:34 pm, Deep_Feelings doctore...@gmail.com wrote:
 python got relatively fewer numbers of developers than other high
 level languages like .NET , java .. etc  why ?

Oh, and why on god's green would you ever compare Java (*puke*) and
Python in the same breath? You say Python is a high-level-language?
Well sir,  i say Python is a super-high-level-language that
approaches pseudo code simplicity *but* stays far enough away from it
so as not to be scorched by it's asinine synonymous quirks.
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue6783] Add a builtin method to 'int' for base/radix conversion

2009-08-27 Thread Yuv Gre

Yuv Gre ubershme...@gmail.com added the comment:

Use case - 'hashing' a counter for example like video ID's in youtube. 
One could use a regular int internally and publish a shorter 62-base id 
for links.

Guido said on http://mail.python.org/pipermail/python-dev/2006-
January/059923.html
I think we ought to let this sit for a while and come back to it in a
few week's time. Is 'base' really the right name? It could just as
well be considered a conversion in the other direction. In common
usage, 'base' and 'radix' are about synonymous (except no-one uses
radix). Pethaps the 2nd argument should not be a keyword argument?

Also, this discussion made me wonder if conversions using other bases
than 10 should even be built-ins. A library module seems a more
appropriate place

I'm hoping 182 weeks of clarity could help iron this issue out.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6783
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6789] ftplib storelines does not honor strings returned in fp.readline

2009-08-27 Thread Ayman

New submission from Ayman ayman.alsair...@gmail.com:

in ftplibs.storlines, a call is done on what should be a Text stream:
fp.readline()
This would work in pre 3.x as it returns bytes but now that readlines
returns a string, the call at lines 477 would fail:

  File C:\Python31\lib\ftplib.py, line 477, in storlines
if buf[-1] in B_CRLF: buf = buf[:-1]
TypeError: Type str doesn't support the buffer API

The readline call should then be encoded().

--
components: Library (Lib)
messages: 91997
nosy: aymanhs
severity: normal
status: open
title: ftplib storelines does not honor strings returned in fp.readline
type: crash
versions: Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6789
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6784] byte/unicode pickle incompatibilities between python2 and and python3

2009-08-27 Thread RonnyPfannschmidt

RonnyPfannschmidt ronny.pfannschm...@gmx.de added the comment:

its even worse

python3:
 import pickle
 pickle.dumps(b'', protocol=2)
b'\x80\x02c__builtin__\nbytes\nq\x00]q\x01\x85q\x02Rq\x03.'

python2.6:
 import pickle
 pickle.loads('\x80\x02c__builtin__\nbytes\nq\x00]q\x01\x85q\x02Rq\x03.')
'[]'

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6784
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6788] codecs.open on Win32 does not force binary mode

2009-08-27 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

Ryan McGuire wrote:
 
 New submission from Ryan McGuire python@enigmacurry.com:
 
 Opening a UTF-8 encoded file with unix newlines (\n) on Win32:
 
 codecs.open(whatever.txt,r,utf-8).read()
 
 replaces the newlines (\n) with CR+LF (\r\n).
 
 The docs specifically say that :
 
 Files are always opened in binary mode, even if no binary mode was
 specified. This is done to avoid data loss due to encodings using 8-bit
 values. This means that no automatic conversion of '\n' is done on
 reading and writing.
 
 And yet, opening the file with an explicit binary mode resolves the
 situation:
 
 codecs.open(whatever.txt,rb,utf-8).read()
 
 This reads the file with the original newlines unmodified.
 
 The implementation of codecs.open and the documentation are out of sync.

The implementation looks like this:

if encoding is not None and \
   'b' not in mode:
# Force opening of the file in binary mode
mode = mode + 'b'

in both Python 2 and 3, so I'm not sure what could be causing
this.

--
nosy: +lemburg

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6788
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6733] curses line wrap broken when mixing full- and half-width unicode characters

2009-08-27 Thread fugounashi

fugounashi fugounashi+pyt...@gmail.com added the comment:

thanks for looking into it

this should do it:

#! /usr/bin/python
import locale
locale.setlocale(locale.LC_ALL, '')
code = locale.getpreferredencoding()
import curses
def main(stdscr):
stdscr.erase()
stdscr.move(0, 0)
for i in range(0,stdscr.getmaxyx()[1] - 1):
stdscr.addstr(.);
stdscr.addstr(u\u3007\u3007.encode(code));
stdscr.refresh()
curses.wrapper(main)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6733
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6788] codecs.open on Win32 does not force binary mode

2009-08-27 Thread Ryan McGuire

Ryan McGuire python@enigmacurry.com added the comment:

Uploading a doctest for this. 

The tests are successful on Linux using Python 2.6
They fail on Win32 with Python 2.6

--
Added file: http://bugs.python.org/file14788/codecs_bug.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6788
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6784] byte/unicode pickle incompatibilities between python2 and and python3

2009-08-27 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

The problem with trying to solve the following issue:
   a bytes instance from python3 is pickled as custom class in
protocols 3
is that if we pickle bytes from Python 3 as a 2.x str in protocol = 2,
unpickling it using Python 3 will yield a str (unicode), not a bytes
object. Therefore the whole chain (pickling then unpickling) will not be
idempotent.

--
components: +Library (Lib) -None
nosy: +alexandre.vassalotti, gvanrossum, pitrou
versions: +Python 2.7, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6784
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6784] byte/unicode pickle incompatibilities between python2 and and python3

2009-08-27 Thread RonnyPfannschmidt

RonnyPfannschmidt ronny.pfannschm...@gmx.de added the comment:

unpickle of any non-ascii string from python2 will break
the only way out would be to ensure text strings and a single defined
encoding (at that point storing unicode strings in any case seems more
practical)

also byte-strings stored as python2 str would break

and since i pass around binary strings as parts of objects, its just
completely broken for me

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6784
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3143] development docs waste a lot of horizontal space on left nav bar

2009-08-27 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

I just did a quick test about making the sidebar collapsible.
Add these lines at the end of default.css to see how the page might look
like with the sidebar collapsed:

/* collapse the sidebar */
div.sphinxsidebar {
/* border: 3px solid red; */
width: 1em !important;
}
/* hide the content of the sidebar */
div.sphinxsidebarwrapper {
display: none;
}
/* expand the page to use the sidebar space */
div.bodywrapper{
/* border: 3px solid blue; */
margin-left: 1em !important;
}

A  /  button has to be added (via JS) to collapse and restore
the sidebar. The CSS properties have to be changed via JS too, the users
without JS won't notice any difference at all.
When the sidebar is collapsed, it is possible to make it appear again
clicking anywhere on the 1em-wide collapsed sidebar on the left (and not
only on the ).
The sidebar could be hidden completely by placing the  /  button
or an Hide/Show sidebar link in the top-left corner, but I don't know
exactly where (before the small python icon? just under it in a
floating box?).

The WebDeveloper plug-in of Firefox can be used to see the changes on
the fly (CSS - Edit CSS - paste the code at the end of default.css),
otherwise you can edit the CSS manually.
Feedback and comments appreciated.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3143
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3143] development docs waste a lot of horizontal space on left nav bar

2009-08-27 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

Attached a screenshot of the result.
I also made the top bar fixed as described in #4965, so it's always
visible even if the user scrolled till the middle of the page (this is
not related to this issue and will be addressed in #4965 though).

--
Added file: http://bugs.python.org/file14789/nosidebar.gif

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3143
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3143] development docs waste a lot of horizontal space on left nav bar

2009-08-27 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

Another screenshot that shows the page with and without the sidebar,
with a photoshopped  /  button.

--
Added file: http://bugs.python.org/file14790/visible-vs-hidden.gif

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3143
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5148] gzip.open breaks with 'U' flag

2009-08-27 Thread Art Gillespie

Art Gillespie agill...@gmail.com added the comment:

The problem appears to be that the gzip module simply doesn't support
universal newlines yet.

I'm currently working on the zipfile module's universal newline support
(issue6759) so if nobody else is working on this, I'll do it.

I'm not sure if file object's open() behavior when presented with 'rUb'
is correct or not.

 f = open(test.txt, w).write(blah\r\nblah\rblah\nblah\r\n)
 f = open(test.txt, rUb)
 f.read()
'blah\nblah\nblah\nblah\n'

Since 'U' and 'b' are conceptually mutually exclusive on platforms where
'b' matters, I can see this being confusing.

--
nosy: +agillesp

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5148
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5329] os.popen2 and os.popen3 in python 2.6 incompatible with os.popen* in python 2.5

2009-08-27 Thread Jean-Paul Calderone

Changes by Jean-Paul Calderone exar...@divmod.com:


Added file: http://bugs.python.org/file14791/os-popen-list.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5329
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5329] os.popen2 and os.popen3 in python 2.6 incompatible with os.popen* in python 2.5

2009-08-27 Thread Jean-Paul Calderone

Jean-Paul Calderone exar...@divmod.com added the comment:

Attached os-popen-list.patch which includes all of the earlier
os-popen.diff and adds tests which fail without this patch and pass with
it.  They also pass on Python 2.5.  The patch is against the Python 2.6
maintenance branch, but presumably it should be applied to trunk as well.

--
nosy: +exarkun

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5329
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6499] Can't import xmlrpclib, DocXMLRPCServer and SimpleXMLRPCServer when zlib is not available

2009-08-27 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

Not yet, the machine I was using to work on this is currently broken and
I couldn't test the new test_docxmlrpc yet. Once I've fixed the machine
and tried it I'll let you know.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6499
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6787] thread docs contain an incorrect link in a reference to the 'exit' method

2009-08-27 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Fixed in r74555, thanks!

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6787
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6784] byte/unicode pickle incompatibilities between python2 and and python3

2009-08-27 Thread RonnyPfannschmidt

RonnyPfannschmidt ronny.pfannschm...@gmx.de added the comment:

in case the actual behavior is not supposed to change

how about a way to declare one wants exact 1:1 mapping between py2py3,
so strbytes and unicodestr will work for sure

something like load/dump(..., encoding=bytes) just crossed my mind

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6784
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6783] Add a builtin method to 'int' for base/radix conversion

2009-08-27 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

 I'm hoping 182 weeks of clarity could help iron this issue out.

:-)

I really think should bring this up on the python-ideas mailing list[1];  
it's much more likely to get resolved one way or the other if you do.

[1] http://mail.python.org/mailman/listinfo/python-ideas

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6783
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6508] expose setresuid

2009-08-27 Thread Gregory P. Smith

Changes by Gregory P. Smith g...@krypto.org:


--
nosy: +gregory.p.smith

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6508
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6243] getkey() can segfault in combination with curses.ungetch()

2009-08-27 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Andrew - do you still feel responsible for curses?

--
assignee:  - akuchling
nosy: +akuchling, georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6243
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6784] byte/unicode pickle incompatibilities between python2 and and python3

2009-08-27 Thread Martin v . Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

 how about a way to declare one wants exact 1:1 mapping between py2py3,
 so strbytes and unicodestr will work for sure

In a sense, that's already possible. Inherit from _Pickler/_Unpickler,
and replace the dispatch dict with a different mapping.

I wouldn't object to supporting this with an option, though, assuming it
was properly documented and implemented for both pickle and _pickle
(probably along with pickletools).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6784
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6790] httplib and array do not play together well

2009-08-27 Thread Jake McGuire

New submission from Jake McGuire j...@youtube.com:

As of Python 2.6 you can no longer pass an array to 
httplib.HTTPConnection.send.

Issue1065257 added code to httplib to attempt to determine whether a 
file-like object was passed to certain methods (e.g. send), and to 
stream the data if so.

The patch uses hasattr(obj, 'read') as a proxy for is a file-like 
object.

array.array objects have a method called read that is almost entirely 
disanalogous to the read method on a file-like object.

Hilarity ensues.

--
messages: 92015
nosy: jakemcguire
severity: normal
status: open
title: httplib and array do not play together well
type: behavior
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6790
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.

2009-08-27 Thread andrew cooke

andrew cooke and...@acooke.org added the comment:

Came here wondering how best to solve this myself.

I already subclass the request handler to do client validation (password
etc) and it stuck me that a simpler solution would be to use thread
local storage.

This avoids having to modify dispatch.  The disadvantage is that this
uses a single global scope.  I don't think it's a better solution than
that suggested by samwyse for a final solution, but I thought I'd note
it here because it's a simpler alternative for people needing to add a
work-around, and I suspect many people aren't aware of the possibility.

 import _threading_local ; help(_threading_local)

If this wouldn't work (maybe I've misunderstood the server threading?)
then I'd appreciate someone correcting me.  Thanks.

--
nosy: +acooke

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3058
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6790] httplib and array do not play together well

2009-08-27 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

That method of array.array has been deprecated since 1.5.1 according to
the docs.  Too bad nobody finished the job and removed it.

Perhaps array.array could be special cased in the relevant code until
the method can actually be removed.

--
keywords: +easy
nosy: +r.david.murray
priority:  - normal
stage:  - test needed
versions: +Python 2.7, Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6790
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6275] let unittest.assertRaises() return the exception object caught

2009-08-27 Thread Kristján Valur Jónsson

Kristján Valur Jónsson krist...@ccpgames.com added the comment:

Committed this much more harmless patch to the trunk as revision 74556

--
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6275
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6745] (curses) addstr() takes str in Python 3

2009-08-27 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

See also issue #4787

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6745
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6745] (curses) addstr() takes str in Python 3

2009-08-27 Thread Trundle

Trundle andy-pyt...@hammerhartes.de added the comment:

Yes, it uses a version of ncurses which supports wide characters, I
checked that.

I agree that using bytes instead may not be the preferred solution in
Python 3. The point is, currently, it is broken if the user does not
use an utf-8 environment.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6745
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6654] Add path to the xmrlpc dispatcher method

2009-08-27 Thread Kristján Valur Jónsson

Kristján Valur Jónsson krist...@ccpgames.com added the comment:

After a short discussion on python-dev 
(http://mail.python.org/pipermail/python-dev/2009-August/091069.html) 
there were no objections.  On python-ideas there were no responses.  
Commited as revision 74558

--
resolution:  - accepted
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6654
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6745] (curses) addstr() takes str in Python 3

2009-08-27 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

I don't really understand because your example, umlaut3x.py, works
correctly on my computer (py3k, ubunty jaunty).

 The point is, currently, it is broken if the user 
 does not use an utf-8 environment.

So the problem is that the charset is hardcoded to utf8. You would like
to be able to change that. Or better, than Python guess your terminal
charset. Right?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6745
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6745] (curses) addstr() takes str in Python 3

2009-08-27 Thread Trundle

Trundle andy-pyt...@hammerhartes.de added the comment:

Of course it works for you. As you stated in issue #4787, your locale
is 'fr_FR.UTF-8'.

And I don't want Python to guess my terminal's encoding. I want Python
to respect my locale. Which is 'de...@euro', and not utf-8.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6745
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6745] (curses) addstr() takes str in Python 3

2009-08-27 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

Here is a first patch to add a method setcharset() to the window class.

Using my patch, you can fix your example by adding the line:

   screen.setcharset(your charset)

before addstr().

It's an initial hack to fix the issue. Next steps are:
 - use something better than utf8 as the default charset, maybe
locale.getpreferredencoding()
 - copy the charset on new window creation?

--
keywords: +patch
Added file: http://bugs.python.org/file14792/curses_charset.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6745
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3143] Make the left sidebar in the doc collapsible

2009-08-27 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
title: development docs waste a lot of horizontal space on left nav bar - Make 
the left sidebar in the doc collapsible
Added file: http://bugs.python.org/file14793/sidebar.js

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3143
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3143] Make the left sidebar in the doc collapsible

2009-08-27 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

Attached a first attempt to make the sidebar collapsible.
The sidebar.js file is the JS script I did, the sidebar.zip file
contains a couple of pages taken from the doc with the sidebar scripts
already included in a script.

If you want to try it just extract the files, open the *.html with a
browser and it should work.

This is not supposed to be the final version, I tested it only on FF3
(where it seems to work fine) and on IE6 (where it is as broken as you
would expect). This is also the first time I use JQuery, so any comments
and suggestions are welcomed (both about the code and the result).

--
priority: low - normal
Added file: http://bugs.python.org/file14794/sidebar.zip

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3143
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



<    1   2