Re: Accessing class attribute

2013-09-12 Thread Peter Otten
Peter Otten wrote:

> chandan kumar wrote:
> 
>> Hi ,
>> 
>> I'm new to python ,please correct me if there is any thing wrong with the
>> way accessing class attributes.
>> 
>> Please see the below code .I have inherited confid in ExpectId class,
>> changed self.print_msg  to Hello. Now  inherited confid in TestprintmsgID
>> class.Now  I wanted to print self.print_msg value (which is changed under
>> ExpectId class)  as Hello under TestprintmsgID. I end up with error
>> saying
>> TestprintmsgID has no attribute self.print_msg.  Atleast i expect the
>> null to be printed.
>> 
>> 
>> 
>> class confid():
>> def __init__(self):
>> self.print_msg = ""
>> 
>> class ExpectId(confid):
>> 
>> def __init__(self):
>> self.print_msg = " Hello"
>> 
>> def expectmethod(self):
>> print "self.print_mesg = ",self.print_msg
>> 
>> class TestprintmsgID(confid):
>>  
>> def __init__(self):
>> "Created  Instance"
>> 
>> def printmsgmethod(self):
>> print "printmsgmethod print_msg val = ",self.print_msg Here
>> is
>> the  Attribute error
> 
> If the class has an __init__() method the initializer of the base class is
> not invoked automatically.
> 
> In the above code the initializer of TestprintmsgId does nothing, so you
> can avoid it. ExpectId.__init__() however must invoke confid.__init_().
> 
> The complete example:

Sorry, my examples don't show what I wanted to show. I assumed a class 
hierarchy

confid <-- ExpectId <-- TestprintmsgId

Also, ExpectId.__init__() need not invoke confid.__init__() in this 
particular case because both set the same attribute.

The general ideas however still stand: 

(1) if you write an __init__() method it should invoke the __init__() method 
of the baseclass.
(2) omit no-op __init__() methods altogether.

Again, sorry for the confusion!

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


Re: better and user friendly IDE recommended?

2013-09-12 Thread Joshua Landau
On 12 September 2013 00:44, Ben Finney  wrote:
> [email protected] writes:
>
> My main advice: Avoid non-free (that is, proprietary) software for your
> development tools. Learning a set of development tools is a significant
> investment, and you should not tie that investment to a single vendor;
> if they lose interest for whatever reason, your investment is stranded.

If the time learning a set of tools is enough to make the choice
between tools, I suggest avoiding, say, Vim.

I find that going for whatever makes you most productive is more
important than trying to minimise the learning time. Most software is
much easier to learn that Vim, if you have to replace it after 10
years or not.

YMMV.

---

OP, I suggest Sublime Text as an editor 'cause that's my editor so it
must be the best choice. It's no IDE, though, if it really matters to
you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: better and user friendly IDE recommended?

2013-09-12 Thread Ben Finney
Joshua Landau  writes:

> On 12 September 2013 00:44, Ben Finney  wrote:
> > [email protected] writes:
> >
> > My main advice: Avoid non-free (that is, proprietary) software for your
> > development tools. Learning a set of development tools is a significant
> > investment, and you should not tie that investment to a single vendor;
> > if they lose interest for whatever reason, your investment is stranded.
>
> If the time learning a set of tools is enough to make the choice
> between tools, I suggest avoiding, say, Vim.

Rather, the effort (not merely time) spent learning a set of tools is
enough to advise choosing tools that will be around and supported by the
community for a long time, and have a wide applicability.

Any software that is non-free cannot be improved by its community, only
by the vendor. That makes it a poor choice for a tool that takes effort
to learn (such as an IDE); it can be abandoned by one party, and then
no-one can improve it further. Free software does not have that problem.

Development tools need to repay their user's investment by being
usefully applicable to a wide variety of tasks. The set of tasks a
programmer needs to perform is broad, and cannot be anticipated early
on; the tools need to be flexible and adaptable by the community of
users to tasks that the tool vendor never thought of.

So Vim and Emacs are both good investments by that standard.

> I find that going for whatever makes you most productive is more
> important than trying to minimise the learning time.

Agreed, and productivity is greatly improved if the tool one has already
learned to use can be used for a broad range of tasks for many years.

> Most software is much easier to learn that Vim, if you have to replace
> it after 10 years or not.

Having to learn many incompatible tools for what is effectively the same
task – whether that task is editing text, running the test suite,
interacting with VCS, invoking a debugger, and so on through many other
IDE tasks – is a poor investment.

Better to learn these once, in a single powerful tool that can be
maintained independent of any one vendor for as long as its community is
interested.

-- 
 \   “Never express yourself more clearly than you are able to |
  `\   think.” —Niels Bohr |
_o__)  |
Ben Finney

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


Re: Please omit false legalese footers (was: Language design)

2013-09-12 Thread Skip Montanaro
More likely, JP Morgan's mail system added that footer to the message
on the way out the virtual door. My recommendation would be to not
post using your company email address. Get a free email address.

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


Re: Help please, why doesn't it show the next input?

2013-09-12 Thread Oscar Benjamin
On 12 September 2013 07:04, William Bryant  wrote:
> Thanks everyone for helping but I did listen to you :3 Sorry. This is my 
> code, it works, I know it's not the best way to do it and it's the long way 
> round but it is one of my first programs ever and I'm happy with it:

Hi William, I'm glad you've solved your initial problem and I just
wanted to make a couple of comments about how your program could be
simplified or improved. The comments are below.

>
> '''#*'''
> #* Name:Mode-Median-Mean Calculator   
> *#
> #*
> *#
> #* Purpose: To calculate the mode, median and mean of a list of numbers   
> *#
> #*  and the mode of a list of strings because that is what we are 
> *#
> #*  learning in math atm in school :P 
> *#
> #*
> *#
> #* Author:  William Bryant
> *#
> #*
> *#
> #* Created: 11/09/2013
> *#
> #*
> *#
> #* Copyright:   (c) William 2013  
> *#
> #*
> *#
> #* Licence: IDK :3
> *#
> '''**'''
>
>
>
>
> #-#   ~~Import things I am using~~   
> #-#
>
> # |
> #|
> #   \/
>
> import time
> import itertools
>
>
>
> #-#~~Variables that I am using, including the list.~~
> #-#
>
> # |
> #|
> #   \/
>
> num_or_string = None
> amount_numbers = []
> List = []
> prompt = "Does your list contain, a number or a string?  \nEnter:  "
> user_inputHMNn = None
> user_inputHMNs = None

Of the declarations above only List and prompt are needed. Actually
though I wouldn't use either of those. List should really be a local
variable inside the functions below. And it would be better to write
prompt inline e.g.:

answer = input("Does your list contain, a number or a string?  \nEnter:  ")

That makes it easier to understand what's happening when you look at
the code. So I would remove all of those variable declarations. In
some other programming languages there are reasons to use declarations
like those above but not in Python.

>
> #-#   ~~Functions that I am using.~~ 
> #-#
>
> # |
> #|
> #   \/
>
> user_inputNOS = input(prompt)
> user_inputNOS
> time.sleep(1.5)
>
> def NOS():
> if user_inputNOS == "String" or user_inputNOS == "string" or 
> user_inputNOS == "STRING" or user_inputNOS == "s" or user_inputNOS == "S" or 
> user_inputNOS == "str":
> HMNs()
> elif user_inputNOS == "Number" or user_inputNOS == "number" or 
> user_inputNOS == "NUMBER" or user_inputNOS == "N" or user_inputNOS == "N" or 
> user_inputNOS == "int" or user_inputNOS == "num":
> HMNn()
> else:
> global user_inputNOS2
> global prompt
> prompt = "You did not enter a valid field, :P Sorry.  \nEnter:  "
> user_inputNOS2 = input(prompt)
> user_inputNOS2
> time.sleep(1.5)
> NOS2()
>
> def NOS2():
> if user_inputNOS2 == "String" or user_inputNOS2 == "string" or 
> user_inputNOS2 == "STRING" or user_inputNOS2 == "s" or user_inputNOS2 == "S" 
> or user_inputNOS2 == "str":
> HMNs()
> elif user_inputNOS2 == "Number" or user_inputNOS2 == "number" or 
> user_inputNOS2 == "NUMBER" or user_inputNOS2 == "N" or user_inputNOS2 == "N" 
> or user_inputNOS2 == "int" or user_inputNOS2 == "num":
> HMNn()
> else:
> global prompt
> prompt = "You did not enter a valid field, :P Sorry.  \nEnter:  "
> user_inputNOS2
> time.sleep(1.5)
> NOS2()

The functions above are almost identical. The main difference is just
that NOS2() doesn't call input() which I assume is accidental. So you
could simplify this by only having one function NOS() and having it
call itself rather than NOS2() at the end. Then it would look like:

def NOS():
# code here ...
NOS()

However this is not a common way to use recursive function calls. What
this really does is repeat something forever in a loop. The common way
to do this is to use a for-loop or a while-loop. For example you can
get the same effect with:

while True:  # Loops forever (until the break)
answer = input("Does your list contain, a number or a string?  \nEnter: ")
answer = answer.lower()
if answe

Re: Please omit false legalese footers (was: Language design)

2013-09-12 Thread Oscar Benjamin
On 12 September 2013 10:27, Skip Montanaro  wrote:
>
> More likely, JP Morgan's mail system added that footer to the message
> on the way out the virtual door. My recommendation would be to not
> post using your company email address. Get a free email address.

It wouldn't surprise me if JPMorgan would block free email addresses on site.


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


Pep8 plugin for visual studio

2013-09-12 Thread Chandru Rajendran
Hi all,

I am new to python. Please give information about Pep8 style checker plugin for 
VS2012.

Thanks in Advance,
Chandru

 CAUTION - Disclaimer *
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
for the use of the addressee(s). If you are not the intended recipient, please
notify the sender by e-mail and delete the original message. Further, you are 
not
to copy, disclose, or distribute this e-mail or its contents to any other 
person and
any such actions are unlawful. This e-mail may contain viruses. Infosys has 
taken
every reasonable precaution to minimize this risk, but is not liable for any 
damage
you may sustain as a result of any virus in this e-mail. You should carry out 
your
own virus checks before opening the e-mail or attachment. Infosys reserves the
right to monitor and review the content of all messages sent to or from this 
e-mail
address. Messages sent to or from this e-mail address may be stored on the
Infosys e-mail system.
***INFOSYS End of Disclaimer INFOSYS***
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: better and user friendly IDE recommended?

2013-09-12 Thread Joshua Landau
On 12 September 2013 09:04, Ben Finney  wrote:
> Joshua Landau  writes:
>
>> On 12 September 2013 00:44, Ben Finney  wrote:
>> > [email protected] writes:
>> >
>> > My main advice: Avoid non-free (that is, proprietary) software for your
>> > development tools. Learning a set of development tools is a significant
>> > investment, and you should not tie that investment to a single vendor;
>> > if they lose interest for whatever reason, your investment is stranded.
>>
>> If the time learning a set of tools is enough to make the choice
>> between tools, I suggest avoiding, say, Vim.
>
> Rather, the effort (not merely time) spent learning a set of tools is
> enough to advise choosing tools that will be around and supported by the
> community for a long time, and have a wide applicability.

The sum time it takes to make Vim a good editor and subsequently learn
it is comparable to doing the same for a good number of other editors.
Vim's quite hard to learn, see?

If you accept that point, you should accept that if Vim is worth the
investment then, ignoring issues of other editors being of different
quality¹, the potential of support for your editor being dropped
involves no greater opportunity cost than learning Vim.

As Vim is obviously an editor many consider worth learning, we can
conclude than if you prefer certain non-free alternatives you are not
putting undue effort on yourself.

Of course, there are a lot of other good reasons for OSS to be
favoured and there are a lot of reasons to like other things, too.

¹ Whatever that means

---

I conclude that I am right and everyone else is wrong, because if it
were not the case I would be wrong and I've already asserted that I am
not.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing class attribute

2013-09-12 Thread Dave Angel
On 12/9/2013 02:15, chandan kumar wrote:

> Hi ,
>
> I'm new to python

Welcome. I hope you enjoy your time here, and that the language treats
you as well as it's treated me.

> ,please correct me if there is any thing wrong with the way accessing
class attributes.

None of the following uses class attributes, but instead uses instance
attributes.  For example, any attri bute created with self. = 
inside an instance method will bei an instance attribute.  Class
attributes are typically created by assignments outside any method.


>
> Please see the below code .I have inherited confid in ExpectId class, changed 
> self.print_msg  to Hello. Now  inherited confid in TestprintmsgID class.Now  
> I wanted to print self.print_msg value (which is changed under ExpectId 
> class)  as Hello under TestprintmsgID. I end up with error saying 
> TestprintmsgID has no attribute self.print_msg.  Atleast i expect the null to 
> be printed.

Please include the full error message, (including the traceback), rather
than just paraphrasing.  In this case, it's easy to guess, but
frequently it is not.

>
>
>
> class confid():
In Python 2, you always want to derive from object.  That's to signal
the compiler to use "new style" classes, which have been the preferred
way for many years.  Python 3 only has new-style classes.

class confid(object):

> def __init__(self):
> self.print_msg = ""
>
> class ExpectId(confid):
>
> def __init__(self):
> self.print_msg = " Hello"
>
> def expectmethod(self):
> print "self.print_mesg = ",self.print_msg
>

Each instance of ExpectId is also an instance of confid.

> class TestprintmsgID(confid):   
>  
> def __init__(self):
> "Created  Instance"
>
> def printmsgmethod(self):
> print "printmsgmethod print_msg val = ",self.print_msg Here is 
> the  Attribute error
>
>

Each instance of TestprintmsgID is also an instance of confid, but NOT
of ExpectID.

The base class methods are not
automatically called when the child class methods are.  if you want them
called, you have to do it explicitly.  In particular, you should always
call the base class __init__() method from your __init__() method.  It
didn't happen to matter in the case of ExpectID, but it does here.

Preferred way to do that is to add a line to iTextprintmsgID's
__init__() method:

   super(ExpectId, self).__init__()

should appear at the beginning of your initializer.  This will eliminate
your Attribute error.  But it will still see a value for print_msg of
bank string.


> if __name__ == '__main__':
> ins1 =ExpectId()
> ins1.expectmethod()
>
> ins2 = TestprintmsgID()
> ins2.printmsgmethod()
>

I think you're expecting that deriving from a class somehow patches the
existing class.  But it doesn't.  The existence of the ExpectedID class
only affects instances of that class, not instances of TestprintmsgID. 
If you wanted those to be affected, you'd be needing to inherit from
ExpectID, rather than just from confid.  If you did that, you'd see a
value of "Hello".



-- 
DaveA


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


Re: Parsing an html line and pulling out only numbers that meet a certain criteria

2013-09-12 Thread Dave Angel
On 11/9/2013 23:03, Cory Mottice wrote:

> I am using line.rfind to parse a particular line of html code. For example, 
> this is the line of html code I am parsing:
>
> 79° class="low">Lo 56°
>
> and this is the code I use to split the line to (in this case) pull out the 
> '79'.
>
> position0 = line.rfind('{}'.format(date1.strftime("%a")))
> if position0 > 0 :
> self.high0 = lines[line_number + 4].split('')[0].split('">')[-1]
>
> Now I need to only pull out that number if it is >=94 and <=37. If it does 
> not meet this criteria, I don't want anything to happen. Any ideas? Thank you 
> in advance!

Since no integer is both >=94 and <=37, you'd never have to worry about
it.  But assuming there's a typo there,

temp = lines[line_number + 4.
if 94 <= int(temp) <= 37:
   self.high0 = temp


-- 
DaveA


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


Re: better and user friendly IDE recommended?

2013-09-12 Thread Paul Pittlerson
On Wednesday, September 11, 2013 5:14:04 PM UTC+3, mnishpsyched wrote:
> Hey i am a programmer but new to python. Can anyone guide me in knowing which 
> is a better IDE used to develop web related apps that connect to DB using 
> python?

If you are a programmer in the sense that you are a proficient in something like
C or Java, then whatever development environment you used for that type of 
coding
will surely work just as well for writing python scripts.

But to answer your question: If you want something modern and fresh, maybe give 
Sublime Text a try. Personally, my favorite is Geany, because it has all the 
functionality and customization I want from an editor, but is not very bloated.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Programmers requirement Exp 2 - 3 yrs

2013-09-12 Thread Mobi Esprits
Hi, 

We have python programmers requirement with an experience of 2 -3 yrs. Job 
location shall be bangalore. 

Interested candidates can send their resume to [email protected]

Please do not forget to mention the experience in the subject line.

Best Regards,
Mobi Esprtis Software Technologies Pvt. Ltd.
-- 
https://mail.python.org/mailman/listinfo/python-list


Access to objects in a frame on a web page

2013-09-12 Thread Ddp Ludo
Hello,

I am trying to program a robot which will allow me to test whether a default 
password has been changed on my intranet servers .

And I 'm stuck since 2 days ...

HTML structure of the page:


  
  

  

   
   
 

I try to go to fill the username field and I turn around because of the frames.

I tried to do it with mechanize . But as we can see, there is no body in the 
web page, so I can not instantiate the object form and get the fields on the 
page via this method.

I can directly open the htm page where username and the enable button , but it 
does not work . It lacks all parent functions to actually start the 
identification.

Here is the beginning of my code works . It connects to my page and correctly 
returns me the source code.

br = mechanize.Browser ()
br.set_all_readonly ( False )
br.set_handle_robots ( False ) # ignore robots
br.set_handle_refresh ( False ) # can sometimes hang without this
br.addheaders = [( 'User - Agent ', ' Firefox' ) ]
url = " file :/ / / root/Prog/html/AC1.htm "
response = br.open (url)
response.read print ()

Then, searching the internet, it seemed to understand that the frames were 
referred by links () class

lnkList = []
br.links for lnk in ():
  lnkList.append ( lnk.url )
  print " links " , lnk.url

It correctly list my links.

But can not use follow_link ( ) find_link  I can not do it  impossible 
to reach my username field 

After the best , I can get the pointer of the frame object, but I use mechanize 
no more 

frame = sys._getframe (2)
print frame

Does anyone know a solution?

Either using code or in my thinking and my approach to the problem.
Excuse my poor english.

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


Re: better and user friendly IDE recommended?

2013-09-12 Thread Fabio Zadrozny
You'll probably get way too many answers (everyone has its own personal
favorite).

I suggest you check:
http://stackoverflow.com/questions/81584/what-ide-to-use-for-python and
https://wiki.python.org/moin/IntegratedDevelopmentEnvironments, grab the
ones you think are worth it, experiment with them a bit and use what works
best for you.

Cheers,

Fabio



On Wed, Sep 11, 2013 at 11:14 AM,  wrote:

> Hey i am a programmer but new to python. Can anyone guide me in knowing
> which is a better IDE used to develop web related apps that connect to DB
> using python?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Wing IDE 4.1.14 released

2013-09-12 Thread Wingware

Hi,

Wingware has released version 4.1.14 of Wing IDE, our integrated development
environment designed specifically for the Python programming language.

Wing IDE provides a professional quality code editor with vi, emacs, and 
other
key bindings, auto-completion, call tips, refactoring, context-aware 
auto-editing,
a powerful graphical debugger, version control, unit testing, search, 
and many

other features.  For details see http://wingware.com/

This minor maintenance release includes:

Fix dropped debugger connections when using Python 3.3
Allow C debugger such as gdb to attach to a debug process running 
under Python 3
Allow auto-showing the Debug I/O tool only on first output for each 
debug session
Don't show the run args dialog when restarting the debug process 
(and use same args)

Go to correct symbol when selection range is non-empty
Fix auto-editing when inserting HTML comments to avoid duplicate >
6 other minor bug fixes

For a complete change log see 
http://wingware.com/pub/wingide/4.1.14/CHANGELOG.txt


Free trial: http://wingware.com/wingide/trial
Downloads: http://wingware.com/downloads
Feature matrix: http://wingware.com/wingide/features
More information: http://wingware.com/
Sales: http://wingware.com/store/purchase
Upgrades: https://wingware.com/store/upgrade

Questions?  Don't hesitate to email us at [email protected].

Thanks,

--

Stephan Deibel
Wingware | Python IDE
Advancing Software Development

www.wingware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Send alt key to subprocess.PIPE stdin

2013-09-12 Thread Wanderer
On Wednesday, September 11, 2013 4:23:57 PM UTC-4, Dave Angel wrote:
> On 11/9/2013 10:26, Wanderer wrote:
> 
> 
> 
> > How do I send the command 'Alt+D' to subprocess.PIPE?
> 
> 
> 
> That's not a command, it's a keystroke combination.  And without knowing
> 
> what RSConfig.exe is looking to get its keystrokes, it might not even be
> 
> possible to feed it any keystrokes via the pipe.
> 
> 
> 
> if the program does indeed use stdin, there's no portable encoding for
> 
> Alt-D.  But if your program only runs on one particular platform, you
> 
> might be able to find docs for that platform that explain it.
> 
> 
> 
> >
> 
> > My code is
> 
> >
> 
> > import subprocess
> 
> > rsconfig = subprocess.Popen(["C:\Program 
> > Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", 
> > ],stdin=subprocess.PIPE)
> 
> 
> 
> That string will only work by accident.  You need to make it a raw
> 
> string, or use forward slashes, or double them.  As it happens, with
> 
> this PARTICULAR set of directories, you won't get into trouble with
> 
> Python 2.7.3
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> DaveA

Thanks, I didn't know that. I thought there would be some \n \t kind of 
combination or a unicode string for all the key combinations on my keyboard.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: better and user friendly IDE recommended?

2013-09-12 Thread Wayne Werner

On Thu, 12 Sep 2013, Ben Finney wrote:

Better to learn these once, in a single powerful tool that can be
maintained independent of any one vendor for as long as its community is
interested.


And if you're a developer, even a community of one is enough ;)

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


Re: Send alt key to subprocess.PIPE stdin

2013-09-12 Thread Chris Angelico
On Fri, Sep 13, 2013 at 12:06 AM, Wanderer  wrote:
> Thanks, I didn't know that. I thought there would be some \n \t kind of 
> combination or a unicode string for all the key combinations on my keyboard.

Unicode identifies every character, but keystrokes aren't characters.
Consider, for instance, the difference between the keypress Shift+A
and the letter produced - even in the most simple ASCII-only US-only
situation, that could produce either "A" or (if Caps Lock is active)
"a". So if you actually want to trigger Shift+A, you can't represent
that with a character. Controlling a GUI app has to be done with
keystrokes, so it needs a GUI controlling tool.

That said, though: These sorts of keystrokes often can be represented
with escape sequences (I just tried it in xterm and Alt-D came out as
"\e[d"), so you could control a console program using sequences that
you could put into a string. But that's not true of your typical GUI
system.

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


Re: Language design

2013-09-12 Thread Nobody
On Wed, 11 Sep 2013 00:53:53 +, Steven D'Aprano wrote:

> and most routines that handle file names accept either text strings or 
> bytes strings:

I was going to say "that just leaves environ and argv". But I see that
os.environb was added in 3.2. Which just leaves argv.

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


Re: Language design

2013-09-12 Thread Markus Rother
On 10.09.2013 08:09, Steven D'Aprano wrote:
> What design mistakes, traps or gotchas do you think Python has? Gotchas 
> are not necessarily a bad thing, there may be good reasons for it, but 
> they're surprising.

I have one more:

Dictionaries should iterate over their items instead of their keys.

Looking forward to contrary opinions.

Greets,
Markus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Language design

2013-09-12 Thread Ethan Furman

On 09/12/2013 10:51 AM, Markus Rother wrote:

On 11.09.2013 23:15, Ethan Furman wrote:

On 09/11/2013 01:41 PM, Markus Rother wrote:

  >>> () == []
  False

  But:

  >>> bool(().__eq__([]))
  True


This is not a trap, this is simply the wrong way to do it.  The magic
methods (aka dunder methods) are there for Python to call, not you
(except under special circumstances, such as when writing your own
dunder methods).


While trying to do it, I learned that its not the right way to do it.
However, I was not satisfied with the fact, that there is no built in
pure function for operations on primitives.  Such that


def get_do_stuff (fn):

... def do_stuff(x,y):
... return fn(x,y)
... return do_stuff

I understand that python is not a functional language, but it
frustrates me at times.


--> import operator
--> operator.__all__  # public api methods are in __all__
['abs', 'add', 'and_', 'attrgetter', 'concat', 'contains', 'countOf', 'delitem', 'eq', 'floordiv', 'ge', 'getitem', 
'gt', 'iadd', 'iand', 'iconcat', 'ifloordiv', 'ilshift', 'imod', 'imul', 'index', 'indexOf', 'inv', 'invert', 'ior', 
'ipow', 'irshift', 'is_', 'is_not', 'isub', 'itemgetter', 'itruediv', 'ixor', 'le', 'length_hint', 'lshift', 'lt', 
'methodcaller', 'mod', 'mul', 'ne', 'neg', 'not_', 'or_', 'pos', 'pow', 'rshift', 'setitem', 'sub', 'truediv', 'truth', 
'xor']


Imports are a Good Thing; not everything has to be built in.

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


Re: Python GUI?

2013-09-12 Thread Dave Cook
On 2013-09-12, Michael Torrie  wrote:
> Not me.  wxWidgets' event model is way too MFC-esque for me.  Does it
> still use event numbers that you define?  Shudder.

You don't have to define IDs explicitly.  That's been the case for a
long time.

> Gtk and Qt's method of signals and slots is by far the most powerful and
> flexible.

wxPython's event manager adds some flexibility.

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


Re: print function and unwanted trailing space

2013-09-12 Thread Albert Hopkins


On Wed, Sep 11, 2013, at 07:36 AM, Wayne Werner wrote:
> On Sat, 31 Aug 2013, candide wrote:
> > # -
> > for i in range(5):
> >print(i, end=' ')   # <- The last ' ' is unwanted
> > print()
> > # -
> 
> Then why not define end='' instead?

I think the OP meant that ' ' is wanted up until the final item.. so
something like

for i in range(4):
print(i, end=' ')
print(4)

or, better:
print(' '.join(str(i) for i in range(5)))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-12 Thread Jerry Hill
On Wed, Sep 11, 2013 at 4:55 PM,   wrote:
> Have you got anything to say on what one I should be using(excluding PyQT 
> because it has a D&D designer >:( )? Is Tkinter really dead? Should I stick 
> with wxPython?

If that's a reason for excluding a GUI toolkit, you're in trouble.
Drag and drop layout tools exist for all of your proposed systems.

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


Re: Expected an indented block

2013-09-12 Thread John Gordon
In  
[email protected] writes:

> Hey guys ! its my first topic and I'm gonna start with a problem :) Im
> totally beginner in Python and each time I try to run this program it
> gives me the error down below:

> http://imgur.com/ufUAMTs

That error involves the previous program line, which your screenshot
doesn't show, so it's hard to say exactly what the problem is.

However, I'll take a guess that the previous line is an "if" statement,
which requires that the following line be indented.  Did you indent the
print statement?

This error can also be caused by using a mix of tabs and spaces on the
same line.  Don't do that.

(And by the way, it's generally better to post errors and code as text
instead of a screenshot.)

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Expected an indented block

2013-09-12 Thread Chris Angelico
On Fri, Sep 13, 2013 at 1:43 AM,   wrote:
> Hey guys ! its my first topic and I'm gonna start with a problem :) Im 
> totally beginner in Python and each time I try to run this program it gives 
> me the error down below:
>
> http://imgur.com/ufUAMTs
>
> I'm using Sublime Text, same problems occured in TextWrangler and in Vim too. 
> I tried python3 python.py too nothing has changed. Thanks in advance.

Without the code, we can't much help. But look at line 3 - it probably
has an if, while, or for statement. Did you write python.py? Did you
copy and paste it from somewhere? If the latter, make sure you retain
indentation, as it's important to Python - and it's not always
possible to figure out how far things should be indented otherwise.

If python.py isn't very large, you'd do well to simply include its
content in-line here. Including the full traceback (as text, not as an
image) is also extremely helpful. In a few years, this list/newsgroup
thread will be being read by hundreds or thousands of people, not all
of whom will want to click web links to figure out what you're saying
- and that's assuming imgur is still holding your image, which I'm not
sure is guaranteed. Text is reliable!

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


Re: Language design

2013-09-12 Thread Neil Cerutti
On 2013-09-12, Markus Rother  wrote:
> On 10.09.2013 08:09, Steven D'Aprano wrote:
>> What design mistakes, traps or gotchas do you think Python has? Gotchas 
>> are not necessarily a bad thing, there may be good reasons for it, but 
>> they're surprising.
>
> I have one more:
>
> Dictionaries should iterate over their items instead of their keys.
>
> Looking forward to contrary opinions.

Consider the 'in' operator.

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


Re: Python GUI?

2013-09-12 Thread Ian Foote
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 11/09/13 21:55, [email protected] wrote:
> There are a few known GUI toolkits out there, and the main ones
> from what I can tell are:
> 
> Tkinter -- Simple to use, but limited PyQT -- You have a GUI
> designer, so I'm not going to count that PyGTK -- Gnome officially
> back this I think wxPython -- Very nice, very professional,
> approved by Python creator, but alas hard to get started with
> 
> So, what are your personal preferences and why? Why use X over Y?
> 
> I, personally, really like wxPython, but I also really like
> Tkinter. I've messed with PyGTK, but I'd choose wxPython over it.
> 
> Have you got anything to say on what one I should be
> using(excluding PyQT because it has a D&D designer >:( )? Is
> Tkinter really dead? Should I stick with wxPython?
> 
> It's might be similar to the "What language to use" argument, or
> the "What background to code on" argument(I prefer darker
> backgrounds xD Please don't argue about this though!), in the sense
> that there is *no* answer, just preference.
> 
> Also, with wxPython, it has kind of a "flow" layout like JFrame,
> whereas it will adjust it's layout to look like a native Mac App,
> Windows app or Linux App, correct? It'll look almost identical,
> right? Not that it matters, I'm just curious! :D
> 
> Thanks!
> 

Another GUI toolkit is kivy (kivy.org). It has a focus on supporting a
wide range of platforms, including Android and IOs, and various input
devices (mouse, keyboard, touchscreen, etc).

Kivy is in active development and I think is well worth a look.

Regards,
Ian F
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSMiFNAAoJEODsV4MF7PWzOsAH/3hidUN4pNxDG5ox2hNmfFkz
g8D+hhXz/zKC+MpEh2iEm9G9NhaxoSTLQkcsUs5bxL9MvIQ0TYy68/vbQddRA52I
GN0ofz8+E5h7MX57wegE/uxv0N9+CjdpWfwOfESoR5TXGUD8tr9ONEKAENLvod3W
JUgU0KvN410J8+2yxI+LKpqezW3hNr43VoUO4zEmRgCm6KEK6wdKdooI5j45tb9r
HW7vZgd12RCzE4XMVSBRl20xcYB9isi9erP7UnTCep8FUQKV0XxdnXY00rEBPQEm
7hgh66dIX5c2SC3fPgiYHFA7fSv7x4hrCJcokr+z5LEfdzRInra01tqnQLxnA+Q=
=uPwE
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-12 Thread Benjamin Kaplan
On Sep 12, 2013 9:06 AM,  wrote:
>
> On Thursday, September 12, 2013 6:05:14 AM UTC+1, Michael Torrie wrote:
> > On 09/11/2013 02:55 PM, [email protected] wrote:
> >
> > > PyQT -- You have a GUI designer, so I'm not going to count that
> >
> > What do you mean?  Gtk has a GUI designer too.  what of it
> >
> > > I, personally, really like wxPython, but I also really like Tkinter.
> >
> > > I've messed with PyGTK, but I'd choose wxPython over it.
> >
> > Not me.  wxWidgets' event model is way too MFC-esque for me.  Does it
> >
> > still use event numbers that you define?  Shudder.
> >
> > Gtk and Qt's method of signals and slots is by far the most powerful and
> > flexible.
> >
> > > Have you got anything to say on what one I should be using(excluding
> >
> > > PyQT because it has a D&D designer >:( )? Is Tkinter really dead?
> >
> > > Should I stick with wxPython?
> > I still don't understand why you are excluding Qt.  All modern toolkits
> >
> > are heading towards imperative GUI design.  With Gtk I use Glade and
> >
> > GtkBuilder.  My GUI is in a nice XML file that gets loaded and
> >
> > manipulated by my python class.  It's extremely clean.  And in the case
> >
> > of compiled programming, you don't have to recompile just to tweak
> >
> > something like a layout.
> > At the moment if someone were to come in from scratch and ask what GUI
> > toolkit to use, I would answer Qt with PySide.  It's the most
> > cross-platform of all the toolkits, and it's one of the most mature.
> >
> > Gtk is also good, but Windows and Mac support is always lagging behind
> >
> > X11, and it's not as good at fitting into the native look and feel.
>
> > > Also, with wxPython, it has kind of a "flow" layout like JFrame,
> >
> > > whereas it will adjust it's layout to look like a native Mac App,
> >
> > > Windows app or Linux App, correct? It'll look almost identical,
> >
> > > right? Not that it matters, I'm just curious! :D
> >
> >
> >
> > Possibly.  I know Qt and Gtk both can flip the button orders, etc to
> >
> > look more native.  And all good toolkits give you layout managers so you
> >
> > never have to resort to fixed layouts.  Qt's layout system is very
> >
> > different than Gtk's, but once you get the feel of it (use the Qt
> >
> > Designer program!), it makes a lot of sense.
>
> I didn't realise GTK has a GUI designer too :(
>
> I don't like it when you can D&D to position things. I don't understand
why someone wouldn't want to write the positioning code, and have fun with
the debugging. That's the best part about writing a program, in my opinion.
I'm against D&D with programming, and I'm not sure why.
> --
>

There are gui designers for wx as well. Doesn't mean you ever have to use
any of them (although I wouldn't want to write windows forms code by hand).
I do find it generally nicer to work with the markup formats (xrc for wx,
xaml for wpf, and so on) rather than trying to describe a gui in a
programming language.

The main difference between wx and qt is that qt looks native on every
platform while wx *is* native on every platform (it uses native controls
wherever possible). This means that wx integrates into the OS better, but
your also more likely to need OS-specific tweaks in wx, at least from my
experience from a few years ago.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please omit false legalese footers (was: Language design)

2013-09-12 Thread Grant Edwards
On 2013-09-11, Ben Finney  wrote:
> "Prasad, Ramit"  writes:
>
>> This email is confidential and subject to important disclaimers and
>> conditions including on offers for the purchase or sale of securities,
>> accuracy and completeness of information, viruses, confidentiality,
>> legal privilege, and legal entity disclaimers, available at
>> http://www.jpmorgan.com/pages/disclosures/email.
>
> No, your message was not confidential. You sent it to a public
> mailing list, presumably by choice. So please omit such false and
> pointless legal rubbish from your messages here.

OTOH, perhaps it was confidential.  In which case, J. P. Morgan might
want to know that ramit.prasad is sending confidential information to
a pulic mailing list.

-- 
Grant Edwards   grant.b.edwardsYow! BARRY ... That was
  at   the most HEART-WARMING
  gmail.comrendition of "I DID IT MY
   WAY" I've ever heard!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Expected an indented block

2013-09-12 Thread altugozgercek
Hey guys ! its my first topic and I'm gonna start with a problem :) Im totally 
beginner in Python and each time I try to run this program it gives me the 
error down below:

http://imgur.com/ufUAMTs

I'm using Sublime Text, same problems occured in TextWrangler and in Vim too. I 
tried python3 python.py too nothing has changed. Thanks in advance. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Language design

2013-09-12 Thread Neil Cerutti
On 2013-09-12, Markus Rother  wrote:
> On 11.09.2013 23:15, Ethan Furman wrote:
>> On 09/11/2013 01:41 PM, Markus Rother wrote:
>>>  >>> () == []
>>>  False
>>>
>>>  But:
>>>
>>>  >>> bool(().__eq__([]))
>>>  True
>> 
>> This is not a trap, this is simply the wrong way to do it.  The magic
>> methods (aka dunder methods) are there for Python to call, not you
>> (except under special circumstances, such as when writing your own
>> dunder methods).
>
> While trying to do it, I learned that its not the right way to do it.
> However, I was not satisfied with the fact, that there is no built in
> pure function for operations on primitives.  Such that
>
 def get_do_stuff (fn):
> ... def do_stuff(x,y):
> ... return fn(x,y)
> ... return do_stuff
>
> I understand that python is not a functional language, but it
> frustrates me at times.

>>> import operator
>>> equal = get_do_stuff(operator.eq)(7, 7.0)
True

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


Re: better and user friendly IDE recommended?

2013-09-12 Thread Paul Rudin
Joshua Landau  writes:

> If the time learning a set of tools is enough to make the choice
> between tools, I suggest avoiding, say, Vim.

That's a big if. 

If you expect to spend a lot of time editing text, code, etc. over the
next few years then it's definitely learning at least one of vim or
emacs to a reasonable degree of competency.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: better and user friendly IDE recommended?

2013-09-12 Thread Adrián Espinosa
El miércoles, 11 de septiembre de 2013 16:14:04 UTC+2, mnishpsyched  escribió:
> Hey i am a programmer but new to python. Can anyone guide me in knowing which 
> is a better IDE used to develop web related apps that connect to DB using 
> python?


Hi and welcome.

I suggest you to use IntelliJ IDEA. It has a plugin for Python and Django (web 
framework). It works flawlessly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Language design

2013-09-12 Thread Markus Rother
On 11.09.2013 23:15, Ethan Furman wrote:
> On 09/11/2013 01:41 PM, Markus Rother wrote:
>>  >>> () == []
>>  False
>>
>>  But:
>>
>>  >>> bool(().__eq__([]))
>>  True
> 
> This is not a trap, this is simply the wrong way to do it.  The magic
> methods (aka dunder methods) are there for Python to call, not you
> (except under special circumstances, such as when writing your own
> dunder methods).

While trying to do it, I learned that its not the right way to do it.
However, I was not satisfied with the fact, that there is no built in
pure function for operations on primitives.  Such that

>>> def get_do_stuff (fn):
... def do_stuff(x,y):
... return fn(x,y)
... return do_stuff

I understand that python is not a functional language, but it
frustrates me at times.

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


Re: Python GUI?

2013-09-12 Thread Dave Cook
On 2013-09-12, Dave Cook  wrote:
> There's also a markup language available, enaml:
>
> http://docs.enthought.com/enaml/

I should have mentioned that it's *Python*-based markup, not an XML
horrorshow.

http://pyvideo.org/video/1231/enaml-a-framework-for-building-declarative-user

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


Re: Language design

2013-09-12 Thread Terry Reedy

On 9/12/2013 2:24 PM, Markus Rother wrote:


Dictionaries should iterate over their items instead of their keys.


Dictionaries *can* iterate by keys, values, or items. You would prefer 
that the default iteration be by items rather than keys.



Looking forward to contrary opinions.


When the issue was discussed and decided, a majority of developers 
preferred keys. A large factor was experience and expectation that 
iterating by keys is more common than than iterating by items, coupled 
with the idea that the most common usage should be the default.


--
Terry Jan Reedy

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


Re: Language design

2013-09-12 Thread Chris Angelico
On Fri, Sep 13, 2013 at 4:13 AM, Markus Rother  wrote:
> On 12.09.2013 01:27, Chris Angelico wrote:
>> On Thu, Sep 12, 2013 at 6:41 AM, Markus Rother  
>> wrote:
>>> 3. The default return value of methods is None instead of self.
>>> If it was self, it would be possible to chain method calls (which
>>> is called a cascade in smalltalk).
>>
>> That's a policy decision: a method (or function) will *EITHER* return
>> a value, *OR* mutate its primary argument (in the case of a method,
>> that's self).
>
> You are stating: "All getters must be free of side effects".
> That is not the case.  Furthermore, the demand for getters with hidden
> side effects is the reasoning behind properties.

This isn't a language feature here, just a stdlib policy. It's more
akin to Ruby's habit of adorning the mutating methods with an
exclamation mark - it's a way of stopping you from accidentally doing
what you didn't mean to do. There's a sharp distinction between
list.sort(), which mutates in place and returns None, and sorted(),
which doesn't touch its argument and returns a new list.

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


Re: Python GUI?

2013-09-12 Thread Dave Cook
On 2013-09-12, Robert Kern  wrote:

> There is nothing forcing you to use the GUI designers if you don't want to.

There's also a markup language available, enaml:

http://docs.enthought.com/enaml/

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


Re: Language design

2013-09-12 Thread Ned Batchelder

On 9/12/13 2:24 PM, Markus Rother wrote:

On 10.09.2013 08:09, Steven D'Aprano wrote:

What design mistakes, traps or gotchas do you think Python has? Gotchas
are not necessarily a bad thing, there may be good reasons for it, but
they're surprising.

I have one more:

Dictionaries should iterate over their items instead of their keys.


I understand the natural desire for this, and I sometimes forget and 
have to add a ".items()" to my loops.  But if you consider how "in" 
should work with dicts, it's only reasonable that "k in d" examine if a 
key is in a dict, not if an item is in a dict.  And once you have "in" 
working like that, it's reasonable for iteration to work on keys.


Dicts act like collections of keys, each with an associated value.

--Ned.

Looking forward to contrary opinions.

Greets,
Markus


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


Re: Python GUI?

2013-09-12 Thread Robert Kern

On 2013-09-12 17:03, [email protected] wrote:

On Thursday, September 12, 2013 6:05:14 AM UTC+1, Michael Torrie wrote:

On 09/11/2013 02:55 PM, [email protected] wrote:



Possibly.  I know Qt and Gtk both can flip the button orders, etc to
look more native.  And all good toolkits give you layout managers so you
never have to resort to fixed layouts.  Qt's layout system is very
different than Gtk's, but once you get the feel of it (use the Qt
Designer program!), it makes a lot of sense.


I didn't realise GTK has a GUI designer too :(

I don't like it when you can D&D to position things. I don't understand why someone 
wouldn't want to write the positioning code, and have fun with the debugging. That's 
the best part about writing a program, in my opinion. I'm against D&D with 
programming, and I'm not sure why.


There is nothing forcing you to use the GUI designers if you don't want to.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


ImportError: No module named Image

2013-09-12 Thread Trandang Bao
Dear Python.org,

Recently, I have been studying OpenCV to detect and recognize faces using
C++. In order to execute source code demonstration from the OpenCV website
I need to run Python to crop image first. Unfortunately, the message error
is 'ImportError: No module named Image' when I run the Python script ( this
script is provided by OpenCV website). I installed  python-2.7.amd64 and
downloaded PIL-1.1.7.win32-py2.7 to install Image library. However, the
message error is 'Python version 2.7 required, which was not found in the
registry'. And then, I downloaded the script written by Joakim Löw for
Secret Labs AB / PythonWare to register registry in my computer. But the
message error is "Unable to register. You probably have the another Python
installation". I spent one month to search this issue on the internet but I
cannot find the answer.
So I decide to write this email to Python.org. I hope you give me the
solution or advice to resolve my issue.
I am looking forward your respond. I hope to hear from you soon.

Thanks,
Tran Dang Bao
-- 
https://mail.python.org/mailman/listinfo/python-list


Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread stephen . boulet
I have an excel file. When I select cells, copy from excel, and then use 
win32clipboard to get the contents of the clipboard, I have a 131071 character 
string.

When I save the file as a text file, and use the python 3.3 open command to 
read its contents, I only have 80684 characters.

Excel (and  other programs too) appends a bunch of b'\x00' (or similar) 
characters.

Is there a pythonic way to strip these out?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread Steven D'Aprano
On Thu, 12 Sep 2013 16:01:20 -0700, stephen.boulet wrote:

> I have an excel file. When I select cells, copy from excel, and then use
> win32clipboard to get the contents of the clipboard, I have a 131071
> character string.

How exactly are you using win32clipboard, and what exact result are you 
getting? Start with a smaller selection of cells, say, two cells, so the 
amount of data is manageable.

I doubt very much you are getting 131071 *characters*. Perhaps you are 
getting that many *bytes*. Or perhaps you are getting HTML-formatted 
text. Without seeing what is in the clipboard, who can tell? Remember 
that the clipboard can contain multiple versions of the same data.


> When I save the file as a text file, and use the python 3.3 open command
> to read its contents, I only have 80684 characters.

How exactly are you using the open function? The result you get may 
differ drastically depending on what you do.


> Excel (and  other programs too) appends a bunch of b'\x00' (or similar)
> characters.

Append to what? The .xls file? The text file? What tool are you using to 
see this?



> Is there a pythonic way to strip these out?

It's hard to tell from the limited description, but my guess is that you 
are misinterpreting what you are seeing. Part of the evidence for this is 
that you are conflating bytes and characters, e.g. above where you refer 
to the NUL *byte* b'\x00' as a character. Bytes are not characters. Scrub 
that out of your brain. They never were, not even back in the old ASCII 
days (may they soon be forgotten), despite what many people think.

My guess is that when you save the spreadsheet as text, either Excel by 
default, or possibly because you have ticked a checkbox, have set it to 
save using the UTF-16 encoding. That's a good thing (not ideal, ideally 
they ought to use UTF-8, but UTF-16 is not a bad choice).

But when you open the file in Python, Python defaults to UTF-8, which 
means you get an bunch of extraneous NULs when opening the file in text 
mode, or b'\x00' null bytes in binary mode. For example:


py> with open('/tmp/rubbish', 'w', encoding='utf-16be') as f:
... f.write('hello world blah blah blah\n')
...
27
py> with open('/tmp/rubbish', 'r') as f:   # default encoding is UTF-8
... f.read()
...
'\x00h\x00e\x00l\x00l\x00o\x00 \x00w\x00o\x00r\x00l\x00d\x00 \x00b\x00l
\x00a\x00h\x00 \x00b\x00l\x00a\x00h\x00 \x00b\x00l\x00a\x00h\x00\n'

If you look carefully, you will see that every character appears to be 
preceded by the NUL control character, \x00. But that's because you've 
used the wrong encoding to decode the bytes in the file back to 
characters. The right way to do this is:

py> with open('/tmp/rubbish', 'r', encoding='utf-16be') as f:
... f.read()
...
'hello world blah blah blah\n'


Which encoding should you use? Unfortunately, there is no clean way for 
text files to record which encoding to use inside the file itself, so 
it's often impossible to know for sure. This is why everyone should move 
towards using UTF-8 everywhere. But I digress. 

The fact that you show the NULs as *bytes* b'\x00' rather than characters 
'\x00' suggests that you might be reading the file in binary mode. 
Presumably you did this because you got an error when trying to read it 
in text mode. If you got this error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: 
invalid start byte

then you should go back to text mode, but use 'utf-16' as the codec:

open(filename, 'w', encoding='utf-16')


Otherwise, if the NULs appear before the letters, as in my example, use 
'utf-16be'. If they appear after the letters, use 'utf-16le'. The 
existence of three oh-so-very-slightly different versions of UTF-16 is 
why it is a sub-optimal encoding, and it is oh-so-bloody-typical that 
Microsoft screwed it up for everyone by picking it as their default 
implementation. If they had sensibly used UTF-8, you wouldn't be having 
this problem.


Of course, it is possible I've misdiagnosed your problem. I've had to 
guess a lot because you didn't show us what you actually did to get the 
results you say you got.



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


Re: better and user friendly IDE recommended?

2013-09-12 Thread Veritatem Ignotam

Is this thread going to evolve into your classic vim vs. emacs, sweet!

Also, Paul is completely right.

V.I.

On 09/12/2013 11:47 AM, Paul Rudin wrote:

Joshua Landau  writes:


If the time learning a set of tools is enough to make the choice
between tools, I suggest avoiding, say, Vim.

That's a big if.

If you expect to spend a lot of time editing text, code, etc. over the
next few years then it's definitely learning at least one of vim or
emacs to a reasonable degree of competency.


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


ANN: Obelus 0.1 -- Asterisk AMI / AGI implementation

2013-09-12 Thread Antoine Pitrou

Hello,

I'm pleased to announce the first release of Obelus, a MIT-licensed
library to interact with Asterisk using the AMI and AGI protocols.

This is version 0.1, and as such some APIs are a bit draftish and not 
guaranteed to be stable accross future releases. Also, documentation is
far from exhaustive.

Quick links
---

* Project page: https://pypi.python.org/pypi/obelus/
* Source code, issue tracker: https://bitbucket.org/optiflowsrd/obelus
* Documentation (incomplete): https://obelus.readthedocs.org

Features


* Python 2 and Python 3 support.
* AMI, FastAGI and Async AGI support.
* Event-driven API friendly towards non-blocking ("async") network
  programming styles.
* :pep:`3156`-style protocol implementations.
* Framework-agnostic.
* Adapters for the `Tornado`_, `Twisted`_, `Tulip`_ network programming
  frameworks.
* Unit-tested.

Requirements


* Python 2.7, 3.2 or later.


Regards

Antoine.


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


Re: Send alt key to subprocess.PIPE stdin

2013-09-12 Thread Nobody
On Fri, 13 Sep 2013 01:27:53 +1000, Chris Angelico wrote:

> That said, though: These sorts of keystrokes often can be represented
> with escape sequences (I just tried it in xterm and Alt-D came out as
> "\e[d"),

Technically, that would be Meta-D (even if your Meta key has "Alt" printed
on it).

Alt- produces chr(ord(char)+128); Meta- produces "\e"+char.

At least, that's the historical distinction between Meta and Alt. With
xterm, the behaviour is configurable via the resources altIsNotMeta,
altSendsEscape and metaSendsEscape.

None of which has anything to do with trying to feed a GUI program key
events via stdin ...

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


Re: better and user friendly IDE recommended?

2013-09-12 Thread Westley Martínez
On Wednesday, September 11, 2013 7:14:04 AM UTC-7, mnishpsyched wrote:
> Hey i am a programmer but new to python. Can anyone guide me in knowing which 
> is a better IDE used to develop web related apps that connect to DB using 
> python?

I use vim and idle.
-- 
https://mail.python.org/mailman/listinfo/python-list


When i leave a LineEdit widget and run slot

2013-09-12 Thread Mohsen Pahlevanzadeh
Dear all,

QtCore.QObject.connect(self.checkBox,
QtCore.SIGNAL(_fromUtf8("clicked(bool)")), lambda:
self.interfaceCodesConstructor.setFilterList(self,"name",self.lineEdit.text()))
I code pyqt, I have the following code:

///
QtCore.QObject.connect(self.checkBox,
QtCore.SIGNAL(_fromUtf8("clicked(bool)")), lambda:
self.interfaceCodesConstructor.setFilterList(self,"name",self.lineEdit.text()))
//

Abobe code causes When i click on checkbox, my function : setFilterList
will be run.

i need to run above function:
"setFilterList(self,"name",self.lineEdit.text())" When i leave a
LineEdit widget, But i don't know its signal.

My question is : What's its signal when you leave a widget such as
LineEdit?

Yours,
Mohsen

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


Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread stephen . boulet
Hi Steven. Here is my code:

import win32clipboard, win32con

def getclipboard():
win32clipboard.OpenClipboard()
s = win32clipboard.GetClipboardData(win32con.CF_TEXT)
win32clipboard.CloseClipboard()
return s

I use this helper function to grab the text on the clipboard and do useful 
things with it.

Sorry about the description; I have stuff to learn about strings and python 3.3.

To get the string length, I just do len(s). There were 10 columns and 700+ rows 
of data, so len(s) returned 80684 from an excel spreadsheet saved as a text 
file.

>From the clipboard contents copied from the spreadsheet, the characters 
>s[:80684] were the visible cell contents, and s[80684:] all started with 
>"b'\x0" and lack any useful info for what I'm trying to accomplish.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named Image

2013-09-12 Thread Jugurtha Hadjar

On 09/13/2013 12:31 AM, Trandang Bao wrote:

Dear Python.org,
I installed
  python-2.7.amd64 and downloaded PIL-1.1.7.win32-py2.7 to install Image
library. However, the message error is 'Python version 2.7 required,
which was not found in the registry'.


One is a 32 bit installer, the other is a 64 bit installer. They don't 
look at the same place in the Registry. Try to have them both the same 
(both 32 for example).


Also, it'd be useful to put exactly what you've done to make it 
reproducible to some extent, and to post the names of the files you used 
(like the script you used. I can Google the guy's name, but he might 
have written dozens of things, so .. which one).




--
~Jugurtha Hadjar,
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-12 Thread eamonnrea
On Thursday, September 12, 2013 6:05:14 AM UTC+1, Michael Torrie wrote:
> On 09/11/2013 02:55 PM, [email protected] wrote:
> 
> > PyQT -- You have a GUI designer, so I'm not going to count that
> 
> 
> 
> What do you mean?  Gtk has a GUI designer too.  what of it?
> 
> 
> 
> > I, personally, really like wxPython, but I also really like Tkinter.
> 
> > I've messed with PyGTK, but I'd choose wxPython over it.
> 
> 
> 
> Not me.  wxWidgets' event model is way too MFC-esque for me.  Does it
> 
> still use event numbers that you define?  Shudder.
> 
> 
> 
> Gtk and Qt's method of signals and slots is by far the most powerful and
> 
> flexible.
> 
> 
> 
> > Have you got anything to say on what one I should be using(excluding
> 
> > PyQT because it has a D&D designer >:( )? Is Tkinter really dead?
> 
> > Should I stick with wxPython?
> 
> 
> 
> I still don't understand why you are excluding Qt.  All modern toolkits
> 
> are heading towards imperative GUI design.  With Gtk I use Glade and
> 
> GtkBuilder.  My GUI is in a nice XML file that gets loaded and
> 
> manipulated by my python class.  It's extremely clean.  And in the case
> 
> of compiled programming, you don't have to recompile just to tweak
> 
> something like a layout.
> 
> 
> 
> At the moment if someone were to come in from scratch and ask what GUI
> 
> toolkit to use, I would answer Qt with PySide.  It's the most
> 
> cross-platform of all the toolkits, and it's one of the most mature.
> 
> Gtk is also good, but Windows and Mac support is always lagging behind
> 
> X11, and it's not as good at fitting into the native look and feel.
> 
> 
> 
> > Also, with wxPython, it has kind of a "flow" layout like JFrame,
> 
> > whereas it will adjust it's layout to look like a native Mac App,
> 
> > Windows app or Linux App, correct? It'll look almost identical,
> 
> > right? Not that it matters, I'm just curious! :D
> 
> 
> 
> Possibly.  I know Qt and Gtk both can flip the button orders, etc to
> 
> look more native.  And all good toolkits give you layout managers so you
> 
> never have to resort to fixed layouts.  Qt's layout system is very
> 
> different than Gtk's, but once you get the feel of it (use the Qt
> 
> Designer program!), it makes a lot of sense.

I didn't realise GTK has a GUI designer too :(

I don't like it when you can D&D to position things. I don't understand why 
someone wouldn't want to write the positioning code, and have fun with the 
debugging. That's the best part about writing a program, in my opinion. I'm 
against D&D with programming, and I'm not sure why.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread MRAB

On 13/09/2013 01:58, [email protected] wrote:

Hi Steven. Here is my code:

import win32clipboard, win32con

def getclipboard():
 win32clipboard.OpenClipboard()
 s = win32clipboard.GetClipboardData(win32con.CF_TEXT)
 win32clipboard.CloseClipboard()
 return s

I use this helper function to grab the text on the clipboard and do useful 
things with it.

Sorry about the description; I have stuff to learn about strings and python 3.3.

To get the string length, I just do len(s). There were 10 columns and 700+ rows 
of data, so len(s) returned 80684 from an excel spreadsheet saved as a text 
file.


From the clipboard contents copied from the spreadsheet, the characters s[:80684] were 
the visible cell contents, and s[80684:] all started with "b'\x0" and lack any 
useful info for what I'm trying to accomplish.



From my own experiments (although not with Excel) it appears that
GetClipboardData returns bytes (a bytestring), not (Unicode) strings.
--
https://mail.python.org/mailman/listinfo/python-list


Ann: rom 0.20 - Redis object mapper for Python

2013-09-12 Thread Josiah Carlson
Hey everyone,

As time progresses, so does my Redis object mapper.

The "rom" package is a Redis object mapper for Python. It sports an
interface similar to Django's ORM, SQLAlchemy + Elixir, or Appengine's
datastore.

The changelog for recent releases can be seen below my signature.

You can find the package at:
https://www.github.com/josiahcarlson/rom
https://pypi.python.org/pypi/rom

And docs can be found at:
http://pythonhosted.org/rom/

Please CC me on any replies if you have any questions or comments.

Thank you,
 - Josiah

#--- 0.20

[changed] Added exception when performing .all(), .execute(), or .count() on
query objects that have had no filters or attribute ordering provided.
This addresses issue #12.
[changed] Moved column definitions to their own module, shouldn't affect any
normal uses of rom.
[added] For users of Redis 2.6 and later, there is a beta Lua-enabled
writing
option that allows for multiple unique columns on models. In some cases,
this may improve performance when writing many entities very quickly.
[added] The ability to reload an entity from Redis, optionally discarding
any
modifications to the object itself. Check out the documentation for
Model.refresh(), Session.refresh(), and Session.refresh_all()
[added] Tests for the newly changed/added features.
[changed] Tests no longer use flushdb() - all test models/indexes/etc. are
prefixed with RomTest, and we find/delete such keys before and after any
tests are run. Now anyone can reasonably run the test suite.
#--- 0.19

[fixed] Thanks to a bug report by https://github.com/MickeyKim , was
notified
of a bug when using unique indexes, which is now fixed and has a
testcase.
#--- 0.18

[fixed] Thanks to a bug report by https://github.com/MickeyKim , was
notified
and received an interim patch for a bug that could cause deleted
entities
to be resurrected on session.commit() or session.flush() . This has now
been fixed and a testcase has been added.
#--- 0.17

[added] LGPL 3 licensing option.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: better and user friendly IDE recommended?

2013-09-12 Thread Joe Junior
On 12 September 2013 13:00, Veritatem Ignotam
 wrote:
> Is this thread going to evolve into your classic vim vs. emacs, sweet!

Who doesn't love those? ;-)

On 09/12/2013 11:47 AM, Paul Rudin wrote:
>
> Joshua Landau  writes:
>
>> If the time learning a set of tools is enough to make the choice
>> between tools, I suggest avoiding, say, Vim.
>
> That's a big if.
>
> If you expect to spend a lot of time editing text, code, etc. over the
> next few years then it's definitely learning at least one of vim or
> emacs to a reasonable degree of competency.

I kinda disagree. Though I use and love emacs as my main editor,
simple things you take for granted in modern editors are simply not
there, and you end up spending some precious time finding out how to
have it (like a right-margin marker). Of course that's not a real
issue, since in the end you'll have everything and much more after
configuring and saving your .emacs in the cloud so everything is
always to your liking.

But then comes another problem: we don't live in a bubble. If you'll
ever have to use another programmer's box, you're screwed (That's why
I avoid getting used to non-standard packages).

Not to mention the mental switch. Not everything I need to use has
emacs-binding (I guess the same is true for vim-binding) and, most of
the time, the binding sucks anyway.

But the point I really disagree is that typing/editing speed impacts
so much programmer's productivity. In my experience I spend a lot more
time as a programmer (big emphasis on "lot") reading, thinking and
designing then writing code. So I find a good navigation tool more
important.

My solution/suggestion for python: emacs (in cua-mode for me) with Jedi.

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


Re: Language design

2013-09-12 Thread Markus Rother
On 12.09.2013 01:27, Chris Angelico wrote:
> On Thu, Sep 12, 2013 at 6:41 AM, Markus Rother  wrote:
>> 3. The default return value of methods is None instead of self.
>> If it was self, it would be possible to chain method calls (which
>> is called a cascade in smalltalk).
>>
>>
>> >>> lst = []
>> >>> lst.append(1).append(2).append(3) ## FAIL
>> Traceback (most recent call last):
>> ...
>> AttributeError: 'NoneType' object has no attribute 'append'
> 
> That's a policy decision: a method (or function) will *EITHER* return
> a value, *OR* mutate its primary argument (in the case of a method,
> that's self). 

You are stating: "All getters must be free of side effects".
That is not the case.  Furthermore, the demand for getters with hidden
side effects is the reasoning behind properties.

The policy could as well be: a method (not a function) will either
return a value, or return self, whether or not the object was mutated.

> Why should that be split into two statements? Or alternatively, why
> should an extra copy of the list be created (if you use Python's
> sorted() here)? But for the new programmer, this is a convenient
> safety-net, and if list.sort() worked the other way, it'd be just as
> much a gotcha ("I ask for a sorted list, and it also changed the
> original?!??").
I understand the point you are making in the end, in the interest of
having an easy to start with language.

Markus

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


Re: Python GUI?

2013-09-12 Thread Michael Torrie
On 09/12/2013 10:03 AM, [email protected] wrote:
> I didn't realise GTK has a GUI designer too :(
> 
> I don't like it when you can D&D to position things. I don't
> understand why someone wouldn't want to write the positioning code,
> and have fun with the debugging. That's the best part about writing a
> program, in my opinion. I'm against D&D with programming, and I'm not
> sure why.

Oh, I understand now.  You mean you dislike the old fixed-position,
pixel-based layouts that visual studio used to use, right?   Well, rest
easy, because both Gtk and Qt use layout managers (packing managers)
instead.  Much more flexible, and can automatically resize as a window
sizes, and deal with things like dpi changes.

And in both cases you don't have to use the imperative tools.  You can
still hand-code your GUI in code in Gtk, Qt, or any other gui system.

In any event I think you should give both Glade-3 and Qt Designer a
serious look.  I think your hate of gui designers is about 10 years out
of date now, even if you still prefer not to use them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-12 Thread Michael Torrie
On 09/12/2013 09:02 PM, Michael Torrie wrote:
> In any event I think you should give both Glade-3 and Qt Designer a
> serious look.  I think your hate of gui designers is about 10 years out
> of date now, even if you still prefer not to use them.

This is a bit old but still how Qt works:

http://thelins.se/learnqt/2009/05/qt-layouts-the-basics/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Language design

2013-09-12 Thread Mark Janssen
>> Really?  Are you saying you (and the community at-large) always derive
>> from Object as your base class?
>
> Not directly, that would be silly.

Silly?  "Explicit is better than implicit"... right?

>> But wait is it the "base" (at the bottom of the hierarchy) or is it the
>> "parent" at the top?  You see, you, like everyone else has been using
>> these terms loosely, confusing yourself.
>
> Depends on whether I'm standing on my head or not.
>
> Or more importantly, it depends on whether I visualise my hierarchy going
> top->down or bottom->up. Both are relevant, and both end up with the
> *exact same hierarchy* with only the direction reversed.

Ha,  "only the direction reversed".  That little directionality that
you're passing by so blithely is the difference between whether you're
talking about galaxies or atoms.  Please.

The simplicity of Python has seduced you into making an "equivocation"
of sorts.  It's subtle and no one in the field has noticed it.  It
crept in slowly and imperceptively.

>> By inheriting from sets you get a lot of useful
>> functionality for free.  That you don't know how you could use that
>> functionality is a failure of your imagination, not of the general idea.
>
> No you don't. You get a bunch of ill-defined methods that don't make
> sense on dicts.

They are not necessarily ill-defined.  Keep in mind Python already
chose (way back in 1.x) to arbitrary overwrite the values in a key
collision.  So this problem isn't new.  You've simply adapted to this
limitation without knowing what you were missing.

 3) It used the set literal for dict, so that there's no obvious way to
 do it.  This didn't get changed in Py3k.
>>>
>>> No, it uses the dict literal for dicts.
>>
>> Right.  The dict literal should be {:} -- the one obvious way to do it.
>
> I don't agree it is obvious. It is as obvious as (,) being the empty tuple
> or [,] being the empty list.

You're just being argumentative.  If there are sets as built-ins, then
{:} is the obvious dict literal, because {} is the obvious one for
set.  You don't need [,] to be the list literal because there is no
simpler list-type.

>>> And the obvious way to form an empty set is by calling set(), the same
>>> as str(), int(), list(), float(), tuple(), dict(), ...
>>
>> Blah, blah.  Let me know when you got everyone migrated over to
>> Python.v3.
>
> What does this have to do with Python 3? It works fine in Python 2.

I mean, you're suggestions are coming from a "believer", not someone
wanting to understand the limitations of python or whether v3 has
succeeded at achieving its potential.

>>> I don't even understand what you are talking about here. "[reference]
>>> variables"? What does that mean?
>>
>> It's a just a tricky point, that I will wait to comment on.
>
> I'm looking forward to an explanation, as I'm intrigued.

Well, wer'e here at junior-high.  It will take some time
-- 
MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-12 Thread Peter
I stuck with Tkinter combined with PMW for a very long time, but the lack of 
extra widgets finally drove me to look elsewhere.

I tried PyQT but didn't have a good experience. I can't remember details, but 
things just seemed to have little "gotchas" - which the mailing list were very 
helpful with sorting out, but I found it frustrating to keep asking for help 
over little items of unexpected behaviour.

I have not tried PyGTK so cannot comment.

I finally decided on wxPython - with my basis of Tkinter (graysons book) it was 
quite easy to pick up and run with. The wxPython book is quite good and helps 
get started and using it. I would suggest if you buy and read that, then you 
will no longer find wxPython difficult to get started with.

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


Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread Neil Hodgson

Stephen Boulet:


 From the clipboard contents copied from the spreadsheet, the characters s[:80684] were 
the visible cell contents, and s[80684:] all started with "b'\x0" and lack any 
useful info for what I'm trying to accomplish.


   Looks like Excel is rounding up its clipboard allocation to the next 
64K. There used to be good reasons for trying to leave some extra room 
on the clipboard and avoid reallocating the block but I thought that was 
over a long time ago.


   To strip NULs off the end of the string use s.rstrip('\0')

   Neil

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


Re: Python GUI?

2013-09-12 Thread Michael Torrie
On 09/12/2013 09:39 PM, Peter wrote:
> I stuck with Tkinter combined with PMW for a very long time, but the
> lack of extra widgets finally drove me to look elsewhere.
> 
> I tried PyQT but didn't have a good experience. I can't remember
> details, but things just seemed to have little "gotchas" - which the
> mailing list were very helpful with sorting out, but I found it
> frustrating to keep asking for help over little items of unexpected
> behaviour.

Interesting. I have used Qt and PyQt, and except for the fact that PyQt
isn't very pythonic (feels like C++ translated directly to Python), I
never had any problems with it.  Maybe since I was already familiar with
signals and slots programming I never found any unexpected behavior[1].
 I've never used Tkinter, and I only ever used wxWidgets once (back when
it was called wxWindows), and the close similarity to MFC at the time
(which I was fleeing) didn't sit right with me.  Also the flexible
layout that Qt and Gtk encouraged was a big plus in my mind.  I guess
you like what you get used to.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Language design

2013-09-12 Thread Steven D'Aprano
On Thu, 12 Sep 2013 20:23:21 -0700, Mark Janssen wrote:

>>> Really?  Are you saying you (and the community at-large) always derive
>>> from Object as your base class?
>>
>> Not directly, that would be silly.
> 
> Silly?  "Explicit is better than implicit"... right?

If I'm inheriting from str, I inherit from str explicitly:

class MyStr(str): ...

and then str in turn inherits from object explicitly. I certainly do not 
inherit from object and then re-implement all the string methods from 
scratch:

class MyStr(object):
def __new__(cls, value): ...
def upper(self): ... 
def lower(self): ...
# and so on...

That would be ridiculous, and goes against the very idea of inheritance. 
But nor do I feel the need to explicitly list the entire superclass 
hierarchy:

class MyStr(str, object):
...


which would be silly. Only somebody who doesn't understand how 
inheritance works in Python would do that. There's simply no need for it, 
and in fact it would be actively harmful for larger hierarchies.


>>> But wait is it the "base" (at the bottom of the hierarchy) or is it
>>> the "parent" at the top?  You see, you, like everyone else has been
>>> using these terms loosely, confusing yourself.
>>
>> Depends on whether I'm standing on my head or not.
>>
>> Or more importantly, it depends on whether I visualise my hierarchy
>> going top->down or bottom->up. Both are relevant, and both end up with
>> the *exact same hierarchy* with only the direction reversed.
> 
> Ha,  "only the direction reversed".  That little directionality that
> you're passing by so blithely is the difference between whether you're
> talking about galaxies or atoms.

It makes no difference whether I write:

atoms -> stars -> galaxies

or

galaxies <- stars <- atoms

nor does it make any difference if I write the chain starting at the top 
and pointing down, or at the bottom and pointing up.

Your objection implies that writing family trees with the most distant 
ancestor (the root of the tree) at the top of the page somehow confuses 
people into thinking that perhaps they are the progenitor of people who 
lived generations earlier. That's absurd -- people simply are not as 
stupid as you think.


> The simplicity of Python has seduced you into making an "equivocation"
> of sorts.  It's subtle and no one in the field has noticed it.  It crept
> in slowly and imperceptively.

Ah, and now we come to the heart of the matter -- people have been 
drawing tree-structures with the root at the top of the page for 
centuries, and Mark Janssen is the first person to have realised that 
they've got it all backwards.


>>> By inheriting from sets you get a lot of useful functionality for
>>> free.  That you don't know how you could use that functionality is a
>>> failure of your imagination, not of the general idea.
>>
>> No you don't. You get a bunch of ill-defined methods that don't make
>> sense on dicts.
> 
> They are not necessarily ill-defined.  Keep in mind Python already chose
> (way back in 1.x) to arbitrary overwrite the values in a key collision. 
> So this problem isn't new.  You've simply adapted to this limitation
> without knowing what you were missing.

No, Python didn't "arbitrarily" choose this behaviour. It is standard, 
normal behaviour for a key-value mapping, and it is the standard 
behaviour because it is the only behaviour that makes sense for a general 
purpose mapping.

Python did not invent dicts (although it may have invented the choice of 
name "dict").

If you think of inheritance in the Liskov Substitution sense, then you 
might *consider* building dicts on top of sets. But it doesn't really 
work, because there is no way to sensibly keep set-behaviour for dicts.

For example, take intersection of two sets s and t. It is a basic 
principle of set intersection that s&t == t&s.

But now, take two dicts with the same keys but different values, d and e. 
What values should be used when calculating d&e compared to e&d? Since 
they are different values, we can either:

* prefer the values from the left argument over that from the right;
* prefer the values from the right argument over that from the left;
* refuse to choose and raise an exception;
* consider the intersection empty

The first three choices will break the Liskov Substitution Principle, 
since now dicts *cannot* be substituted for sets. The fourth also breaks 
Liskov, but for a different reason:

# sets
(key in s) and (key in t) implies (key in s&t);

but

# dicts
(key in d) and (key in e) *does not* imply (key in d&e)


So whatever you do, you are screwed Liskov-wise. You cannot derive dicts 
from sets and still keep the Liskov Substitution Principle.

Of course, LSP is not the only way to design your inheritance 
hierarchies. An alternative is to design them in terms of delegating 
implementation to the superclass. As Raymond Hettinger puts it, your 
classes tells it's parent to do some of the work. But in this case, 
you're still screwed: yo

Re: Python GUI?

2013-09-12 Thread CM

> Tkinter -- Simple to use, but limited
> 
> PyQT -- You have a GUI designer, so I'm not going to count that

As others have pointed out, that's nonsensical.  If you don't like the GUI 
designer, just don't use it.  

> wxPython -- Very nice, very professional, approved by Python creator, but 
> alas hard to get started with

Why is it hard to get started with?  Download the installer, install, and:

import wx
app = wx.App(False)  
frame = wx.Frame(None, -1, "Hello World")
frame.Show(True)
app.MainLoop()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Programmers requirement Exp 2 - 3 yrs

2013-09-12 Thread Ben Finney
Mobi Esprits  writes:

> We have python programmers requirement with an experience of 2 -3 yrs.

Please do not use this discussion forum for job advertisements.

Instead, please use the Python Job Board which is designed for this
purpose http://www.python.org/community/jobs/>.

-- 
 \ “Faith may be defined briefly as an illogical belief in the |
  `\  occurrence of the improbable.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


Python -COMMETHOD ,No return value obtained/received

2013-09-12 Thread sanju dhoomakethu
I am very new to COM programming, Our project requires the Python script to 
make communication with a COM dll which is written in C#.

The generated COM signature in Python is as below

COMMETHOD([dispid(1610743820)], HRESULT, 'test',
  ( ['in', 'out'], POINTER(_midlSAFEARRAY(c_double)), 'test' ),
  ( ['retval', 'out'], POINTER(VARIANT_BOOL), 'pRetVal' )),
Where as the C# code for the same is

public bool test(ref double[,] test)
{
if (test == null)
test = new double[1,2];


test[0,0] = 0.0;
test[0,1] = 0.5;

return true;
}
Note: the above is the dummy functions i have created to explain the issue

Now when I try to invoke the COM method from Python , I am only getting the 
values passed by reference to the method (sweepValuesX) as return value and not 
the actual return value (which has to be either true/false)

My function call is as below

print apxWrapper.test()
and the output is ((0.0, 0.5),)

Note: Since i was not able to find a way to pass the last arguement from Python 
,I just omitted the last argument for trial purpose

Any hints why this is happening is highly appreciated or to be specific I have 
two questions

1> How Can i pass the argument to be passed by reference from Python especially 
array (both single and multidimensional)(POINTER(_midlSAFEARRAY(c_double)))
2> How can i get the actual return value (true/false)
Sanjay
-- 
https://mail.python.org/mailman/listinfo/python-list