Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Chris Angelico
On Wed, Jun 26, 2013 at 11:07 AM, Mark Janssen
 wrote:
 Combining two integers lets you make a Rational.
>>>
>>> Ah, but what is going to group them together?  You see you've already
>>> gotten seduced.  Python already uses a set to group them together --
>>> it's called a Dict and it's in every Class object.
>>
>> When you inherit a "set" to make a Rational, you're making the
>> statement (to the interpreter, if nothing else) that a Rational is-a
>> set.
>
> No you don't *inherit* a set to make a Rational, although you gain a
> set to make it.  It's a subtle thing, because at the center of it
> articulates the very difference between a piece of data and a
> container to hold that data.  Or is the container the data?
>
> C++ already solves this di-lemma.  It made "class" which is exactly
> like a "struct", but hides all it's data members.  That critical
> distinction makes all the difference.  I don't know how many people on
> the list really appreciate it.

I certainly don't. In fact, I hardly use "class" in C++ these days - I
just use "struct" and let the members be public. How is that
significant?

The thing you're completely missing, though, is that NONE of what
you're saying has anything to do with inheritance or super(). It's all
composition.

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


Re: Is this PEP-able? fwhile

2013-06-26 Thread Chris Angelico
On Wed, Jun 26, 2013 at 10:47 AM, Dennis Lee Bieber
 wrote:
> On Tue, 25 Jun 2013 17:20:43 +1000, Neil Hodgson 
> declaimed the following:
>
>>jim...@aol.com:
>>
>>> Syntax:
>>> fwhile X in ListY and conditionZ:
>>
>>There is precedent in Algol 68:
>>
>>for i from 0 to n while safe(i) do .. od
>>
> The REXX variant would be
>
> do for i = 0 to n while safe(i)
> ...
> end
>
> Basically one has an optional "for" clause ( for index = initial to 
> end
> by step ), and one has an optional while/until clause -- Hmm, wonder if
> some interpreters would parse both while and until . I need to install
> Regina Rexx on this new machine...

Modulo the 'for' keyword, which is superfluous there. Here's a test
script I knocked up on my OS/2 box back home:

/* */
do i=0 to 9 while safe(i)
say i" is safe"
end
exit

safe: procedure
return arg(1)\=6

The \= in the last line is the REXX "not-equal" operator, like != in
Python. This outputs:

0 is safe
1 is safe
2 is safe
3 is safe
4 is safe
5 is safe

and then terminates. It's pretty clean; the DO/END construct defines a
block, and may optionally execute it more than once. With no
arguments, it just creates a block that executes once (equivalent to
C's braces); valid args include FOREVER (infinitely loop), WHILE
condition (iterate while condition is true), UNTIL condition (execute
once, then check condition, iterate while condition is false - like a
do/while in C), var=value (eg "I=1" - set var to value, then increment
by 1 or by the "BY" value, continue forever or until the "TO" value),
and possibly another that's slipped my mind. Aside from FOREVER, which
stands alone, they're completely independent.

But that's syntax, lots of it. What I'd like to see in Python is
simply a bit of flexibility in the rule about newlines. The for/if
construct in Python could be exactly the same as it now is, only with
the two statements on one line, and it would look very similar to the
existing notation. I can already one-line a simple statement:

for i in range(10): print(i)

I just can't put in an if:

>>> for i in range(10): if i%3: print(i)
SyntaxError: invalid syntax

But I can, as long as I use expression-if:

>>> for i in range(10): print(i) if i%3 else None

Seriously, I can use Perl-style notation to achieve this. Does that
seem right to you? *boggle*

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


Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-26 Thread 88888 Dihedral
Michael Torrie於 2013年6月20日星期四UTC+8下午2時01分11秒寫道:
> 
>  But since the LISP never really got a form beyond S-expressions,
> 
> leaving us with lots of parenthesis everywhere, Python wins much as the
> 
> Hitchhiker's Guide to the Galaxy wins.

Yep, a list is mutable even it's empty.
But constant integers, floats, strings, and None is immutable.

The  variables in a function of python with default 
parameters which could be mutable or immutable.

def fun1( x, alist=[]):
alist.append(x*x)
return alist   ## valid

def fun2(x, alist=None):
if alist==None: alist=[]
alist.append(x*x)
return alist

# kind of boring to show the name binding mechanism of objects
# in Python in different usages
 




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


Re: newbie EOL while scanning string literal

2013-06-26 Thread Steven D'Aprano
On Tue, 25 Jun 2013 17:05:50 -0700, willlewis965 wrote:

> thanks man you answered my questions very clear, btw do you know of a
> place where I can learn python I know some tutorials but are 2.
> something and I'm using 3.3 and I've been told they are different.

Try here:

http://mail.python.org/mailman/listinfo/tutor


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


Re: Returned mail: Data format error

2013-06-26 Thread noreply

 
  
   This email was blocked due to unallowed file attachment.  
   
   From: python-list@python.org  
   Recipient: jbee...@lakeport.k12.ca.us  
   Subject: Returned mail: Data format error  
   Date: Wed, 26 Jun 2013 16:30:55 +0800  
  
  
  
   powered by 
   mxHero
  
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Steven D'Aprano
On Tue, 25 Jun 2013 16:19:08 -0700, Mark Janssen wrote:

> Well you've been spoiled by all the work that came before you.  The
> issue now is not to go "back to the machine" so much as to tear down and
> build up again from raw materials, objects of more and more complexity
> where very complex "meta-objects" upon meta-objects can be built until
> the "whole of human knowledge can be contained".

It must be a wonderful view from way, way up there, but how do you 
breathe?

http://www.joelonsoftware.com/items/2008/05/01.html


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


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Ian Kelly
On Tue, Jun 25, 2013 at 7:07 PM, Mark Janssen  wrote:
>> When you inherit a "set" to make a Rational, you're making the
>> statement (to the interpreter, if nothing else) that a Rational is-a
>> set.
>
> No you don't *inherit* a set to make a Rational, although you gain a
> set to make it.

Okay, then.  Since you started this discussion from the topic of
multiple inheritance I was under the impression that you were talking
about using inheritance to construct Rationals from integers and sets.
 Evidently that is not so, and you've been talking about composition
all along, in which case I have no idea how any of this relates to
your original suggestion of putting superclasses "in charge" of their
subclasses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-26 Thread Thomas Rachel

Am 12.06.2013 03:46 schrieb Rick Johnson:

On Tuesday, June 11, 2013 8:25:30 PM UTC-5, nagia@gmail.com wrote:


is there a shorter and more clear way to write this?
i didnt understood what Rick trie to told me.


My example included verbatim copies of interactive sessions within the Python 
command line. You might understand them better if you open the Python command 
line and type each command in one-by-one. Here is an algoritm that explains the 
process:

open_command_window()
whilst learning or debugging:
 type_command()
 press_enter()
 observe_output()
 if self.badder.is_full:
 take_potty_break()
close_command_window()


with command_window():
   whilst learning or debugging:
  type_command()
  press_enter()
  observe_output()
  if self.badder.is_full:
  take_potty_break()

looks nicer.

SCNR


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


Re: Is this PEP-able? fwhile

2013-06-26 Thread jfharden
On Wednesday, 26 June 2013 01:40:22 UTC+1, Dennis Lee Bieber  wrote:

> (hmmm, does any
> language have a continue that can go to the next iteration of an outer
> loop?)

Perl allows next with a label:

> perldoc -f next
   next LABEL
   nextThe "next" command is like the "continue" statement in C; it
   starts the next iteration of the loop:

LINE: while () {
   next LINE if /^#/;  # discard comments
   #...
   }

   Note that if there were a "continue" block on the above, it
   would get executed even on discarded lines.  If the LABEL is
   omitted, the command refers to the innermost enclosing loop.
-- 
http://mail.python.org/mailman/listinfo/python-list


Is this PEP-able? fwhile

2013-06-26 Thread jimjhb

On Tuesday, June 25, 2013 9:30:54 PM UTC+5:30, Ian wrote:
> In my experience the sorts of people who preach "one exit point" are
> also all about defining preconditions and postconditions and proving
> that the postconditions follow from the preconditions.  I think that
> the two are linked, because the "one exit point" rule makes those
> sorts of proofs simpler.

Ah! utopia!

For every one who knows about pre/post/invariant conditions, there are 10 who 
follow goto-statement-is-harmful like a religious edict.



I just checked and MISRA-C 2012 now allows gotos in specific, limited 
circumstances.  I think it was the MISRA-C 1998 standard that caused all this 
trouble.  So if MISRA now allows goto, why not Python  :)


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


problem with pyinstaller: packaging multiple python scripts under Mac

2013-06-26 Thread Boxuan Cui
This is my first time using pyinstaller. My goal is to build an .app in Mac. 
The app is basically a GUI written in PySide, and I have about 7 different 
Python scripts + 1 .png file. The main file calls 4 of the files, and the 4 
files will call the rest of the 2 files repeatedly. The .png file is nothing 
but the window logo. Could someone help me with some diagnosis? I do not know 
what went wrong. I searched a lot of documentations online, i.e., change spec, 
add import, ... etc. but my app still doesn't run.

FYI, Pyinstaller could generate an app for me, but there are two issues:
1. Icon is not changed for the app.
2. App crashes when opened.

My Python version is 2.7.5 and I am using PyInstaller-2.0. Here is my code for 
packaging:
python pyinstaller.py --onefile --windowed --name=MyApplication -i 
~/Documents/AASource/icon.ico ~/Documents/AASource/Scripts/main_file.py
Here is the spec file:
# -*- mode: python -*-
a = Analysis(['/Users/boxuancui/Documents/AASource/Scripts/main_file.py'],
 pathex=['/Users/boxuancui/Documents/pyinstaller-2.0'],
 hiddenimports=[],
 hookspath=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
  a.scripts,
  a.binaries,
  a.zipfiles,
  a.datas,
  name=os.path.join('dist', 'MyApplication'),
  debug=False,
  strip=None,
  upx=True,
  console=False , icon='/Users/boxuancui/Documents/AASource/icon.ico')
app = BUNDLE(exe,
 name=os.path.join('dist', 'MyApplication.app'))
Here is part of the crash message:
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x54d8
Thanks in advance! Any help will be appreciated!


Best,
Boxuan-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Chris Angelico
On Wed, Jun 26, 2013 at 9:19 AM, Mark Janssen  wrote:
> Did you ever hear of the Glass Bead Game?

Yeah, it's Magic: The Gathering and its counters.

http://www.wizards.com/magic/magazine/Article.aspx?x=mtgcom/daily/mr195

:)

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


Re: Don't feed the troll...

2013-06-26 Thread Ian Kelly
On Mon, Jun 24, 2013 at 7:37 AM, Antoon Pardon
 wrote:
> What do you mean with not a participant in the past? As far
> as I can see his first appearance was in dec 2011. That is
> over a year ago. It also seems that he always find people
> willing to engage with him. Is how the group treats him
> not also an aspect in deciding whether he belongs or not?

Although it's true that he's been around for a while, it has in my
mind only been very recently that his posts have started to become a
problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about pickle

2013-06-26 Thread Phu Sam
f.seek(0)  really does the trick.

Danke sehr,

Phu


On Tue, Jun 25, 2013 at 6:47 AM, Peter Otten <__pete...@web.de> wrote:

> Phu Sam wrote:
>
> > I have a method that opens a file, lock it, pickle.load the file into a
> > dictionary.
> > I then modify the status of a record, then pickle.dump the dictionary
> back
> > to the file.
> >
> > The problem is that the pickle.dump never works. The file never gets
> > updated.
> >
> > def updateStatus(self, fp, stn, status):
> >   f = open(fp, 'rw+')
> >   fcntl.flock(f.fileno(),fcntl.LOCK_EX | fcntl.LOCK_NB)
> >
> >   tb = pickle.load(f)
> >
> >   self.modifyDict(tb, stn, status)
>
> f.seek(0)
>
> >   pickle.dump(tb, f)
> >
> >   fcntl.flock(f.fileno(),fcntl.LOCK_UN)
> >   f.close()
> >
> >
> > What could be the problem here?
>
> pickle.load() moves the file position to the end of the (first) pickle.
> pickle.dump() writes the modified dict starting at the current position.
> You
> end up with two versions of the dict, but you'll only ever read the first.
>
> The fix is to go back to the start of the file with f.seek().
>
> > What mode should I use to open the file to allow both pickle.load and
> > pickle.dump?
>
> Assuming that the file already exists when updateStatus() is invoked for
> the
> first time: "r+b".
>
> I usually open the file twice, once for reading and then for writing, but I
> guess that would interfere with locking.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit Lines of Output

2013-06-26 Thread Gene Heskett
On Tuesday 25 June 2013 17:47:22 Joshua Landau did opine:

> On 25 June 2013 21:22, Bryan Britten  wrote:
> > Ah, I always forget to mention my OS on these forums. I'm running
> > Windows.
> 
> Supposedly, Windows has "more"
> [http://superuser.com/questions/426226/less-or-more-in-windows],

Yes, but less is more than more.
 
> For Linux+less; this works:
> 
> from subprocess import Popen, PIPE
> less = Popen("less", stdin=PIPE)
> less.stdin.write(b"\n".join("This is line number
> {}".format(i).encode("UTF-8") for i in range(1000)))
> less.wait()


Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page:  is up!
My views 

Campbell's Law:
Nature abhors a vacuous experimenter.
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a name for a deployment framework...

2013-06-26 Thread xDog Walker
On Tuesday 2013 June 25 19:16, Dave Angel wrote:
> On 06/25/2013 03:38 PM, Stig Sandbeck Mathisen wrote:
> > jonathan.slend...@gmail.com writes:
> >> Any suggestions for a good name, for a framework that does automatic
> >> server deployments?

Yet Another Deployment Framework?

-- 
Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
strainers.

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


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Antoon Pardon
Op 26-06-13 00:27, Mark Janssen schreef:
>> The main problem is getting to the top/end of the call chain. Classic
>> example is with __init__, but the same problem can also happen with
>> other calls. Just a crazy theory, but would it be possible to
>> construct a black-holing object that, for any given method name,
>> returns a dummy function that ignores its args? (Other forms of
>> attribute lookup aren't going to be a problem, I think, so this can be
>> just methods/functions.) Then you just subclass from that all the
>> time, instead of from object itself, and you should be able to safely
>> call super's methods with whatever kwargs you haven't yourself
>> processed. Would that work?
>>
>> Caveat: I have not done much with MI in Python, so my idea may be
>> complete balderdash.
> Here's how it *should* be made:  the most superest, most badassed
> object should take care of its children.  New instances should
> automatically call up the super chain (and not leave it up to the
> subclasses), so that the parent classes can take care of the chil'en.
>  When something goes wrong the parent class has to look in and see
> what's wrong.
Could you explain why you think it should work this way? Maybe illustrate
how this is supposed to work.

Let take a very simple example. We have a class that works with a stream
(anything with a write method).

class Streamer:
def __init__(self, strm):
...

Now we find that we very often use this class with a file, so we would
like to make a subclass that takes a filename as parameter. This we would 
write somehow like the following

class Filer(Streamer):
def __init__(self, fn):
fl = open(fn, "a+")
super.__init__(fl)
...


Can you explain how this example should be written en work as you view things?

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


Re: Looking for a name for a deployment framework...

2013-06-26 Thread Roy Smith
In article ,
 xDog Walker  wrote:

> On Tuesday 2013 June 25 19:16, Dave Angel wrote:
> > On 06/25/2013 03:38 PM, Stig Sandbeck Mathisen wrote:
> > > jonathan.slend...@gmail.com writes:
> > >> Any suggestions for a good name, for a framework that does automatic
> > >> server deployments?
> 
> Yet Another Deployment Framework?

Boring.

How about "Soliloquy".  Then the project tag line could be, "Deploy, or 
not deploy, that is the question".

For further hack value, require that all pull requests to the project be 
done entirely in iambic pentameter:

for host in hosts:
   deploy(the_code).remote()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limit Lines of Output

2013-06-26 Thread Alister
On Tue, 25 Jun 2013 14:39:30 -0600, Ian Kelly wrote:

> On Tue, Jun 25, 2013 at 2:31 PM, Joshua Landau
>  wrote:
>> On 25 June 2013 21:22, Bryan Britten  wrote:
>>> Ah, I always forget to mention my OS on these forums. I'm running
>>> Windows.
>>
>> Supposedly, Windows has "more"
>> [http://superuser.com/questions/426226/less-or-more-in-windows],
>>
>> For Linux+less; this works:
>>
>> from subprocess import Popen, PIPE less = Popen("less", stdin=PIPE)
>> less.stdin.write(b"\n".join("This is line number
>> {}".format(i).encode("UTF-8") for i in range(1000)))
>> less.wait()
> 
> 
> Or simply:
> 
> $ python my_script.py | less
> 
> It works the same way in Windows:
> 
> C:\> python my_script.py | more

this would be my approach
it leaves it to the user to decide what to do with the output (they may 
even decide to write it to a file themselves)

and obeys to very good principles

1) Do not re-invent the wheel.
2) do only 1 job but do it well. 




-- 
"Every morning, I get up and look through the 'Forbes' list of the
richest people in America.  If I'm not there, I go to work"
-- Robert Orben
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this PEP-able? fwhile

2013-06-26 Thread Fábio Santos
On 26 Jun 2013 11:45,  wrote:
>
> On Tuesday, June 25, 2013 9:30:54 PM UTC+5:30, Ian wrote:
> > In my experience the sorts of people who preach "one exit point" are
> > also all about defining preconditions and postconditions and proving
> > that the postconditions follow from the preconditions.  I think that
> > the two are linked, because the "one exit point" rule makes those
> > sorts of proofs simpler.
>
> Ah! utopia!
>
> For every one who knows about pre/post/invariant conditions, there are 10
who follow goto-statement-is-harmful like a religious edict.
>
>
>
> I just checked and MISRA-C 2012 now allows gotos in specific, limited
circumstances.  I think it was the MISRA-C 1998 standard that caused all
this trouble.  So if MISRA now allows goto, why not Python  :)
>

What is the matter? Just use the goto module...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "unresolved externals" error message building pywin32 for pypy

2013-06-26 Thread joshanderson99
On Wednesday, 26 June 2013 12:57:32 UTC+10, jasonve...@gmail.com  wrote:
> Hi,
> 
> 
> 
> I get an "unresolved externals" error message when building pywin32 for pypy, 
> as listed below.  Both are the latest versions, 
> amauryfa-pywin32-pypy-2a1da51e8152 and pypy-2.0.2.  As per build 
> requirements, VS2012 and Win 7 SDD are installed.
> 
> 
> 
> Not sure what the error msg indicates, but maybe the python lib in linking is 
> missing some required functions.
> 
> 
> 
> Possible cause of error may be a python installation on the same system 
> (build could be using python lib instead of pypy lib), but python has been 
> removed from path, and its folder name has also been changed.
> 
> 
> 
> Any suggestions as to cause of this error would be appreciated.
> 
> 
> 
> Thanks
> 
> 
> 
> Jason
> 
> 
> 
> 
> 
> H:> pypy setup.py install
> 
> 
> 
> Building pywin32 2.7.217.1
> 
> running install
> 
> running build
> 
> running build_py
> 
> running build_ext
> 
> Found version 0x601 in H:\Program Files (x86)\Microsoft 
> SDKs\Windows\v7.0A\include\SDKDDKVER.H
> 
> building 'pywintypes' extension
> 
> ...
> 
> 
> 
> H:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\BIN\link.exe /DLL 
> /nologo /INCREMENTAL:NO /LIBPATH:H:\pypy-2.0.2\include 
> /LIBPATH:build\temp.win32-2.7\Release /LIBPATH:H:\Program Files 
> (x86)\Microsoft SDKs\Windows\v7.0A\lib advapi32.lib user32.lib ole32.lib 
> oleaut32.lib /EXPORT:initpywintypes 
> build\temp.win32-2.7\Release\win32\src\PyACL.obj 
> build\temp.win32-2.7\Release\win32\src\PyDEVMODE.obj 
> build\temp.win32-2.7\Release\win32\src\PyHANDLE.obj 
> build\temp.win32-2.7\Release\win32\src\PyIID.obj 
> build\temp.win32-2.7\Release\win32\src\PyLARGE_INTEGER.obj 
> build\temp.win32-2.7\Release\win32\src\PyOVERLAPPED.obj 
> build\temp.win32-2.7\Release\win32\src\PySECURITY_ATTRIBUTES.obj 
> build\temp.win32-2.7\Release\win32\src\PySECURITY_DESCRIPTOR.obj 
> build\temp.win32-2.7\Release\win32\src\PySID.obj 
> build\temp.win32-2.7\Release\win32\src\PyTime.obj 
> build\temp.win32-2.7\Release\win32\src\PyUnicode.obj 
> build\temp.win32-2.7\Release\win32\src\PyWAVEFORMATEX.obj 
> build\temp.win32-2.7\Release\win32\sr
 c\PyWinTypesmodule.obj 
/OUT:build\lib.win32-2.7\pywin32_system32\pywintypes27.dll 
/IMPLIB:build\temp.win32-2.7\Release\win32\src\pywintypes27.lib /MANIFEST 
/MANIFEST:NO /MACHINE:x86 /BASE:0x1e7a /DEBUG 
/PDB:build\temp.win32-2.7\Release\pywintypes.pdb
> 
> 
> 
> Creating library build\temp.win32-2.7\Release\win32\src\pywintypes27.lib and 
> object build\temp.win32-2.7\Release\win32\src\pywintypes27.exp
> 
> 
> 
> PyTime.obj : error LNK2001: unresolved external symbol _PyArg_ParseTuple
> 
> PyWAVEFORMATEX.obj : error LNK2001: unresolved external symbol 
> _PyArg_ParseTuple
> 
> 
> 
> PyWinTypesmodule.obj : error LNK2019: unresolved external symbol 
> _PyArg_ParseTuple referenced in function "int __cdecl 
> PyWinGlobals_Ensure(void)" (?PyWinGlobals_Ensure@@YAHXZ)
> 
> 
> 
> PyOVERLAPPED.obj : error LNK2001: unresolved external symbol _PyArg_ParseTuple
> 
> 
> 
> PySECURITY_ATTRIBUTES.obj : error LNK2001: unresolved external symbol 
> _PyArg_ParseTuple
> 
> 
> 
> PySECURITY_DESCRIPTOR.obj : error LNK2001: unresolved external symbol 
> _PyArg_ParseTuple
> 
> 
> 
> ...
> 
> 
> 
> build\lib.win32-2.7\pywin32_system32\pywintypes27.dll : fatal error LNK1120: 
> 106 unresolved externals
> 
> 
> 
> error: command 'H:\Program Files (x86)\Microsoft Visual Studio 
> 11.0\VC\BIN\link.exe' failed with exit status 1120


Solution found:  the setup.py-generated link.exe command omitted python27.lib 
for some reason.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this PEP-able? fwhile

2013-06-26 Thread Steven D'Aprano
On Tue, 25 Jun 2013 12:39:53 -0400, jimjhb wrote:

> I just checked and MISRA-C 2012 now allows gotos in specific, limited
> circumstances.  I think it was the MISRA-C 1998 standard that caused all
> this trouble.  So if MISRA now allows goto, why not Python  :)

[humour]
You can! Just use the goto module. It supports both GOTO and COMEFROM:

http://entrian.com/goto/

[/humour]



But seriously... GOTO works best in low-level languages. It is not very 
well suited for high-level languages like Python. Nevertheless, Python 
does support a very limited number of flow control statements which are 
like GOTO in some ways: `break` and `continue` for jumping out of loops, 
and exceptions which are cheap enough to be used as flow control.

You cannot jump into the middle of a function, or to an arbitrary line, 
or into a loop. But this is a good thing -- languages that allow 
unrestricted flow control end up with unmaintainable spaghetti code.


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


class factory question

2013-06-26 Thread Tim
I am extending a parser and need to create many classes that are all subclassed 
from the same object (defined in an external library).  When my module is 
loaded I need all the classes to be created with a particular name but the 
behavior is all the same. Currently I have a bunch of lines like this:

class Vspace(Base.Command): pass
class Boldpath(Base.Command): pass

There are a bunch of lines like that.
Is there a better way? Something like
  
newclasses = ['Vspace', 'Boldpath', ... ]
for name in newclasses:
tmp = type(name, (Base.Command,) {})
tmp.__name__ = name

Is there a more pythonic way?
thanks,
--Tim



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


Re: Is this PEP-able? fwhile

2013-06-26 Thread Neil Cerutti
On 2013-06-25, rusi  wrote:
> On Tuesday, June 25, 2013 9:30:54 PM UTC+5:30, Ian wrote:
>> In my experience the sorts of people who preach "one exit point" are
>> also all about defining preconditions and postconditions and proving
>> that the postconditions follow from the preconditions.  I think that
>> the two are linked, because the "one exit point" rule makes those
>> sorts of proofs simpler.
>
> Ah! utopia!
>
> For every one who knows about pre/post/invariant conditions,
> there are 10 who follow goto-statement-is-harmful like a
> religious edict.

The one-exit-point rule is helpful for tracking entry and exit
invariants. But in my view it shouldn't be followed when it makes
code worse.

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


Re: Is this PEP-able? fwhile

2013-06-26 Thread rusi
On Wednesday, June 26, 2013 6:03:39 PM UTC+5:30, Steven D'Aprano wrote:
> On Tue, 25 Jun 2013 12:39:53 -0400, jimjhb wrote:
> 
> 
> 
> > I just checked and MISRA-C 2012 now allows gotos in specific, limited
> 
> > circumstances.  I think it was the MISRA-C 1998 standard that caused all
> 
> > this trouble.  So if MISRA now allows goto, why not Python  :)
> 
> 
> 
> [humour]
> You can! Just use the goto module. It supports both GOTO and COMEFROM:
> [/humour]

Comefrom + inverted inheritance !
Are we ready for a new pep?
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class factory question

2013-06-26 Thread Peter Otten
Tim wrote:

> I am extending a parser and need to create many classes that are all
> subclassed from the same object (defined in an external library).  When my
> module is loaded I need all the classes to be created with a particular
> name but the behavior is all the same. Currently I have a bunch of lines
> like this:
> 
> class Vspace(Base.Command): pass
> class Boldpath(Base.Command): pass
> 
> There are a bunch of lines like that.
> Is there a better way? Something like
>   
> newclasses = ['Vspace', 'Boldpath', ... ]
> for name in newclasses:
> tmp = type(name, (Base.Command,) {})
> tmp.__name__ = name
> 
> Is there a more pythonic way?

What is your objection against that approach?
By the way, I don't think you need

> tmp.__name__ = name


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


Re: Is this PEP-able? fwhile

2013-06-26 Thread rusi
On Tuesday, June 25, 2013 10:09:53 PM UTC+5:30, jim...@aol.com wrote:
> I just checked and MISRA-C 2012 now allows gotos in specific, limited 
> circumstances.  I think it was the MISRA-C 1998 standard that caused all this 
> trouble.  So if MISRA now allows goto, why not Python  :)

Not sure who is joking and who serious in this thread.

As for who started the 'goto-trouble' it was 30 years before 1998
http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class factory question

2013-06-26 Thread Tim
On Wednesday, June 26, 2013 9:39:12 AM UTC-4, Peter Otten wrote:
> Tim wrote:
> > I am extending a parser and need to create many classes that are all 
> > subclassed from the same object (defined in an external library).  When my 
> > module is loaded I need all the classes to be created with a particular 
> > name but the behavior is all the same. Currently I have a bunch of lines
> > like this: 
> > 
> > class Vspace(Base.Command): pass
> > class Boldpath(Base.Command): pass
> > 
> > There are a bunch of lines like that.
> > Is there a better way? Something like
> >   
> > newclasses = ['Vspace', 'Boldpath', ... ]
> > for name in newclasses:
> > tmp = type(name, (Base.Command,) {})
> > tmp.__name__ = name
> > 
> > Is there a more pythonic way?
> 
> What is your objection against that approach?
> By the way, I don't think you need
> > tmp.__name__ = name


I am not completely understanding the type function I guess. Here is an example 
from the interpreter:

In [1]: class MyClass(object):
   ...: pass
   ...:
In [2]: type('Vspace', (MyClass,), {})
Out[2]: __main__.Vspace
In [3]: x = Vspace()
---
NameError Traceback (most recent call last)
C:\Python27\Scripts\ in ()
> 1 x = Vspace()

NameError: name 'Vspace' is not defined

In [4]: Vspace = type('Vspace', (MyClass,), {})
In [5]: x = Vspace()
In [6]: type(x)
Out[6]: __main__.Vspace

I don't understand how to make `Vspace` usable for creating instances later 
(line 3) when I just call `type`; that is why I thought adding the `__name__` 
attribute would work. Hmm, now I know that doesn't work either:

In [8]: del Vspace
In [9]: m = type('Vspace', (MyClass,), {})
In [10]: m.__name__ = 'Vspace'
In [11]: x = Vspace()
---
NameError Traceback (most recent call last)
C:\Python27\Scripts\ in ()
> 1 x = Vspace()

NameError: name 'Vspace' is not defined
In [11]: m
Out[12]: __main__.Vspace

Maybe this is too much trouble just to save a few lines (~50) of code.

thanks,
--Tim

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


Re: io module and pdf question

2013-06-26 Thread wxjmfauth
Le mardi 25 juin 2013 06:18:44 UTC+2, jyou...@kc.rr.com a écrit :
> Would like to get your opinion on this.  Currently to get the metadata out of 
> a pdf file, I loop through the guts of the file.  I know it's not the 
> greatest idea to do this, but I'm trying to avoid extra modules, etc.
> 
> 
> 
> Adobe javascript was used to insert the metadata, so the added data looks 
> something like this:
> 
> 
> 
> XYZ:colorList="DarkBlue,Yellow"
> 
> 
> 
> With python 2.7, it successfully loops through the file contents and I'm able 
> to find the line that contains "XYZ:colorList".
> 
> 
> 
> However, when I try to run it with python 3, it errors:
> 
> 
> 
>   File 
> "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/codecs.py", 
> line 300, in decode
> 
> (result, consumed) = self._buffer_decode(data, self.errors, final)
> 
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 10: 
> invalid continuation byte
> 
> 
> 
> I've done some research on this, and it looks like encoding it to latin-1 
> works.  I also found that if I use the io module, it will work on both python 
> 2.7 and 3.3.  For example:
> 
> 
> 
> --
> 
> import io
> 
> import os
> 
> 
> 
> pdfPath = '~/Desktop/test.pdf'
> 
> 
> 
> colorlistData = ''
> 
> 
> 
> with io.open(os.path.expanduser(pdfPath), 'r', encoding='latin-1') as f:
> 
> for i in f:
> 
> if 'XYZ:colorList' in i:
> 
> colorlistData = i.split('XYZ:colorList')[1]
> 
> break
> 
> 
> 
> print(colorlistData)
> 
> --
> 
> 
> 
> As you can tell, I'm clueless in how exactly this works and am hoping someone 
> can give me some insight on:
> 
> 1. Is there another way to get metadata out of a pdf without having to 
> install another module?
> 
> 2. Is it safe to assume pdf files should always be encoded as latin-1 (when 
> trying to read it this way)?  Is there a chance they could be something else?
> 
> 3. Is the io module a good way to pursue this?
> 
> 
> 
> Thanks for your help!
> 
> 
> 
> Jay

---


Forget latin-1.
There is nothing wrong in attempting to get such information
by reading a pdf file in a binary mode. What is important
is to know and be aware about what you are searching and to
do the work correctly.

A complete example with the pdf file, hypermeta.pdf, I produced
which contains the string "abcé€" as Subject metadata.
pdf version: 1.4
producer: LaTeX with hyperref package
(personal comment: "xdvipdfmx")
Python 3.2

>>> with open('hypermeta.pdf', 'rb') as fo:
... r = fo.read()
... 
>>> p1 = r.find(b'Subject<')
>>> p1
4516
>>> p2 = r.find(b'>', p1)
>>> p2
4548
>>> rr = r[p1:p2+1]
>>> rr
b'Subject'
>>> rrr = rr[len(b'Subject<'):-1]
>>> rrr
b'feff00610062006300e920ac'
>>> # decoding the information
>>> rrr = rrr.decode('ascii')
>>> rrr
'feff00610062006300e920ac'
>>> i = 0
>>> a = []
>>> while i < len(rrr):
... t = rrr[i:i+4]
... a.append(t)
... i += 4
... 
>>> a
['feff', '0061', '0062', '0063', '00e9', '20ac']
>>> b = [(int(e, 16) for e in a]
  File "", line 1
b = [(int(e, 16) for e in a]
   ^
SyntaxError: invalid syntax
>>> # oops, error allowed
>>> b = [int(e, 16) for e in a]
>>> b
[65279, 97, 98, 99, 233, 8364]
>>> c = [chr(e) for e in b]
>>> c
['\ufeff', 'a', 'b', 'c', 'é', '€']
>>> # result
>>> d = ''.join(c)
>>> d
'\ufeffabcé€'
>>> d = d[1:]
>>> 
>>> 
>>> d
'abcé€'


As Christian Gollwitzer pointed out, not all objects in a pdf
are encoded in that way. Do not expect to get the contain,
the "text" is that way.
When built with the Unicode technology, the text of a pdf is
composed with a *unique* set of abstract ID's, constructed with
the help of the unicode code points table and with the properties
of the font (OpenType) used in that pdf, this is equivalent to
the utf8/16/32 transformers in "plain unicode".

Luckily for the crowd, in 2103, there are people (devs) who
are understanding the coding of characters, unicode and how
to use it.

jmf

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


Re: Is this PEP-able? fwhile

2013-06-26 Thread William Ray Wing
On Jun 26, 2013, at 7:49 AM, Fábio Santos  wrote:
> On 26 Jun 2013 11:45,  wrote:
> >
> > On Tuesday, June 25, 2013 9:30:54 PM UTC+5:30, Ian wrote:
> > > In my experience the sorts of people who preach "one exit point" are
> > > also all about defining preconditions and postconditions and proving
> > > that the postconditions follow from the preconditions.  I think that
> > > the two are linked, because the "one exit point" rule makes those
> > > sorts of proofs simpler.
> >
> > Ah! utopia!
> >
> > For every one who knows about pre/post/invariant conditions, there are 10 
> > who follow goto-statement-is-harmful like a religious edict.
> >
> >
> >
> > I just checked and MISRA-C 2012 now allows gotos in specific, limited 
> > circumstances.  I think it was the MISRA-C 1998 standard that caused all 
> > this trouble.  So if MISRA now allows goto, why not Python  :)
> >
> 
> What is the matter? Just use the goto module...
> 
> 

Wondered when that would be mentioned.

Personally, I've never found that much use for GoTo, but as old timers know, 
that same module adds the Come_From entry point, which is priceless.  ;-)

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


Re: class factory question

2013-06-26 Thread Peter Otten
Tim wrote:

> I am not completely understanding the type function I guess. Here is an
> example from the interpreter:
> 
> In [1]: class MyClass(object):
>...: pass
>...:
> In [2]: type('Vspace', (MyClass,), {})
> Out[2]: __main__.Vspace
> In [3]: x = Vspace()
> 
---
> NameError Traceback (most recent call
> last) C:\Python27\Scripts\ in ()
> > 1 x = Vspace()
> 
> NameError: name 'Vspace' is not defined

No, you are not understanding how Python namespaces work ;) 
To get a Vspace in the global namespace you'd have to bind that name

Vspace = type(...)

which defeats your plan of mass creation of such names. The clean way to 
cope with the situation is to use a dict:

classnames = ["Vspace", ...]
classes = {name: type(name, ...) for name in classnames}

Then you can access the Vspace class with

classes["Vspace"]

If that is inconvenient for your usecase you can alternatively update the 
global (module) namespace:

globals().update((name, type(name, ...) for name in classnames)

For example:

>>> class A(object): pass
... 
>>> globals().update((n, type(n, (A,), {})) for n in ["Beta", "Gamma"])
>>> Beta

>>> issubclass(Beta, A)
True


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


Re: class factory question

2013-06-26 Thread Tim
On Wednesday, June 26, 2013 10:46:55 AM UTC-4, Peter Otten wrote:
> Tim wrote:
> > I am not completely understanding the type function I guess. Here is an
> > example from the interpreter:
> 
> No, you are not understanding how Python namespaces work ;) 
> To get a Vspace in the global namespace you'd have to bind that name
> Vspace = type(...)
> 
> which defeats your plan of mass creation of such names. The clean way to 
> cope with the situation is to use a dict:
> 
> classnames = ["Vspace", ...]
> classes = {name: type(name, ...) for name in classnames}
> 
> Then you can access the Vspace class with 
> classes["Vspace"]
>  
> If that is inconvenient for your usecase you can alternatively update the 
> global (module) namespace:
> globals().update((name, type(name, ...) for name in classnames)
>  
> For example:
> >>> class A(object): pass
> ... 
> >>> globals().update((n, type(n, (A,), {})) for n in ["Beta", "Gamma"])
> >>> Beta
> 
> >>> issubclass(Beta, A)
> True

Thank you for that great explanation. That is exactly what I needed to know!
What a fantastic group this is.
--Tim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class factory question

2013-06-26 Thread Joshua Landau
On 26 June 2013 15:46, Peter Otten <__pete...@web.de> wrote:
> The clean way to
> cope with the situation is to use a dict:
>
> classnames = ["Vspace", ...]
> classes = {name: type(name, ...) for name in classnames}
>
> Then you can access the Vspace class with
>
> classes["Vspace"]
>
> If that is inconvenient for your usecase you can alternatively update the
> global (module) namespace:
>
> globals().update((name, type(name, ...) for name in classnames)
>
> For example:
>
 class A(object): pass
> ...
 globals().update((n, type(n, (A,), {})) for n in ["Beta", "Gamma"])
 Beta
> 
 issubclass(Beta, A)
> True

I would say if a dict isn't good, there are still some cases where you
might not want to use globals.

I _might_ do:

import sys
from types import ModuleType

# As before
newclasses = ['Vspace', 'Boldpath', "and so on", "and yes, these all
become variables"]
little_classes = {name: type(name, (int,), {}) for name in newclasses}

# Make a module
module_for_little_classes = ModuleType("module_for_little_classes",
"All the things")
module_for_little_classes.__dict__.update(little_classes)

# Hack it in there!
sys.modules["module_for_little_classes"] = module_for_little_classes

# Now we can undo all
import module_for_little_classes as mlc
mlc.Vspace
mlc.Boldpath
...

# And undo all our hard work avoiding globals():
from module_for_little_classes import *
Vspace
Boldpath


So, why avoid globals()?
1) Linters don't like globals()
2) Urm... it's ugly?
3) Ur...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Rotwang

On 25/06/2013 23:57, Chris Angelico wrote:

On Wed, Jun 26, 2013 at 8:38 AM, Mark Janssen  wrote:

Combining integers with sets I can make
a Rational class and have infinite-precision arithmetic, for example.


Combining two integers lets you make a Rational. Python integers are
already infinite-precision. Or are you actually talking of using
"machine words" and sets as your fundamental? Also, you need an
ordered set - is the set {5,3} greater or less than the set {2} when
you interpret them as rationals? One must assume, I suppose, that any
one-element set represents the integer 1, because any number divided
by itself is 1. Is the first operand 3/5 or 5/3?


You could use Kuratowski ordered pairs:

http://en.wikipedia.org/wiki/Ordered_pair#Kuratowski_definition

Not that doing so would be sensible, of course. I don't know much about 
low-level data structures but it seems obvious that it's much easier to 
implement an ordered container type than an unordered set on a computer.

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


Re: Limit Lines of Output

2013-06-26 Thread Joshua Landau
On 25 June 2013 22:48, Gene Heskett  wrote:
> On Tuesday 25 June 2013 17:47:22 Joshua Landau did opine:

I did not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Chris Angelico
On Thu, Jun 27, 2013 at 1:16 AM, Rotwang  wrote:
> On 25/06/2013 23:57, Chris Angelico wrote:
>>
>> On Wed, Jun 26, 2013 at 8:38 AM, Mark Janssen 
>> wrote:
>>>
>>> Combining integers with sets I can make
>>> a Rational class and have infinite-precision arithmetic, for example.
>>
>>
>> Combining two integers lets you make a Rational. Python integers are
>>
>> already infinite-precision. Or are you actually talking of using
>> "machine words" and sets as your fundamental? Also, you need an
>>
>> ordered set - is the set {5,3} greater or less than the set {2} when
>> you interpret them as rationals? One must assume, I suppose, that any
>>
>> one-element set represents the integer 1, because any number divided
>> by itself is 1. Is the first operand 3/5 or 5/3?
>
>
> You could use Kuratowski ordered pairs:
>
> http://en.wikipedia.org/wiki/Ordered_pair#Kuratowski_definition
>
> Not that doing so would be sensible, of course. I don't know much about
> low-level data structures but it seems obvious that it's much easier to
> implement an ordered container type than an unordered set on a computer.

Yeah, I don't think Mark is much concerned about implementing things
on actual computers, somehow :)

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


Re: class factory question

2013-06-26 Thread Peter Otten
Joshua Landau wrote:

> I would say if a dict isn't good, there are still some cases where you
> might not want to use globals.
> 
> I _might_ do:

> # Make a module
> module_for_little_classes = ModuleType("module_for_little_classes",
> "All the things")
> module_for_little_classes.__dict__.update(little_classes)

Hm, from within module_for_little_classes that is globals(). To illustrate:

>>> import __main__ as main
>>> globals() is main.__dict__
True

Also, I'd spell module.__dict__ vars(module).

That said I agree that it's a good idea to use a dedicated module (not 
necessarily created on the fly) for those dynamically generated classes.

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


Re: Limit Lines of Output

2013-06-26 Thread Chris Angelico
On Thu, Jun 27, 2013 at 1:24 AM, Joshua Landau
 wrote:
> On 25 June 2013 22:48, Gene Heskett  wrote:
>> On Tuesday 25 June 2013 17:47:22 Joshua Landau did opine:
>
> I did not.

Beg pardon? It looked like an accurate citation to me - you quoted the
OP's second post, then added the line beginning "Supposedly". That's
what Gene quoted, so I'm not understanding this rejection.

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


Re: Limit Lines of Output

2013-06-26 Thread Steven D'Aprano
On Wed, 26 Jun 2013 16:24:56 +0100, Joshua Landau wrote:

> On 25 June 2013 22:48, Gene Heskett  wrote:
>> On Tuesday 25 June 2013 17:47:22 Joshua Landau did opine:
> 
> I did not.

Unless there are two people called "Joshua Landau" with email address 
, I'm afraid that you did.

Here's the email that started the subthread, by Bryan Britten:

http://mail.python.org/pipermail/python-list/2013-June/650697.html

Your, or possibly your evil doppelganger's, reply to Bryan:

http://mail.python.org/pipermail/python-list/2013-June/650698.html

Followed by Gene's reply to your reply:

http://mail.python.org/pipermail/python-list/2013-June/650750.html

And your, or your evil doppelganger's, reply to Gene:

http://mail.python.org/pipermail/python-list/2013-June/650773.html


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


Re: Limit Lines of Output

2013-06-26 Thread rusi
On Wednesday, June 26, 2013 8:54:56 PM UTC+5:30, Joshua Landau wrote:
> On 25 June 2013 22:48, Gene Heskett  wrote:
> > On Tuesday 25 June 2013 17:47:22 Joshua Landau did opine:
> 
> I did not.

I guess Joshua is saying that saying ≠ opining

[Or is he opining?]
-- 
http://mail.python.org/mailman/listinfo/python-list


re.finditer() skips unicode into selection

2013-06-26 Thread akshay . ksth
I am using the following Highlighter class for Spell Checking to work on my 
QTextEdit.

class Highlighter(QSyntaxHighlighter):
pattern = ur'\w+'
def __init__(self, *args):
QSyntaxHighlighter.__init__(self, *args)
self.dict = None

def setDict(self, dict):
self.dict = dict

def highlightBlock(self, text):
if not self.dict:
return
text = unicode(text)
format = QTextCharFormat()
format.setUnderlineColor(Qt.red)
format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
unicode_pattern=re.compile(self.pattern,re.UNICODE|re.LOCALE)

for word_object in unicode_pattern.finditer(text):
if not self.dict.spell(word_object.group()):
print word_object.group()
self.setFormat(word_object.start(), word_object.end() - 
word_object.start(), format)

But whenever I pass unicode values into my QTextEdit the re.finditer() does not 
seem to collect it.

When I pass "I am a नेपाली" into the QTextEdit. The output is like this:

I I I a I am I am I am a I am a I am a I am a I am a I am a I am a I am a

It is completely ignoring the unicode. What might be the issue. I am new to 
PyQt and regex. Im using Python 2.7 and PyQt4.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't feed the troll...

2013-06-26 Thread Antoon Pardon

Op 25-06-13 17:56, ru...@yahoo.com schreef:

On 06/24/2013 07:37 AM, Antoon Pardon wrote:

Op 23-06-13 16:29, ru...@yahoo.com schreef:

On 06/21/2013 01:32 PM, Antoon Pardon wrote:

Op 19-06-13 23:13, ru...@yahoo.com schreef:

[...]

I put forward what I thought was a rational way of thinking
about the problem that balances the competing desires.  You
reject it with, "too easy to neglect the concerns of individuals
or small groups".  I point out that I don't see any way of
satisfying the concerns of "individuals or small groups" and
the majority and you accuse me "going for debating points".


But you didn't even go to the trouble of trying to find out
what those concerns would be and how strong people feel about
them. You just took your assumptions about those concerns for
granted and proceeded from there.



Second having concerns and showing them are two different things.
It may be possible that you have a lot of concerns for the flamers,
that doesn't mean you actually showed them.


If you need some sort of public "show", then I will publicly
state that I too have been very frustrated with many of
Nikos' posts and I am greatly sympathetic to the desire to
tell the SOB to go take a flying fuck.  That not withstanding
I believe that responding that way does not help anything
and is destructive.


You really should learn the difference between telling and showing.


So I'll stand by my statement that you show no concern for the
discomfort of this group you are contributing to. As far as I
can see your only concern is make them behave according to the
solution, you arrived at without any contribution from themselves.


The operative part there is: as far as you can see.


There seem to be two options. Either there is nothing to see or
I missed it, in which case this would have been a very good
opportunity to point it out.


You are free to ignore that and do what you want.
But remember to tell me again how *I* have no concern for
others.


This is not a competion in trying to make the other look less
concerned than the other. I don't care whether or not you
have concerns for others. I'm just pointing out that if you
would like to influence the behaviour of others in a direction
you'd prefer, then you'd better show concerns about what drives
them to that behaviour.



I don't think that just stating that some group of people
are somehow to blame according to some conclusion that logically
followed from assumptions you could choose, and that thus this
other group has to adapt its behaviour while you can carry on
as usual, is such a good way either.


You persist in presenting the situation as though I am just
making things up to justify a proposal that makes my own
use of the group easier.  You ignore the rational I gave and
the experience of countless internet users over the history
of the internet.


Why should I care about the rational you gave. It is based on
your own assumptions, on how you weight the possible outcomes against
each other. Someone who doesn't care about trolls or even may
enjoy observing a heated exchange may come to an entirely different
conclusion on what behaviour is good for the group in case he
extrapolated his own preferences on the group.

And you may not have purposely made things up to justify your
proposal, but how you went about it, that is probably what you
actually did. Because that is what we as humans generally do
in this kind of situations.


You sure seem awful careful with regards to someone you view as being
outside the volition of the group while a the same time seeing nothing
wrong with being very blunt about some subgroup of people you seem to
consider inside the volition of the group, and whith which you have
a particular problem.


Again this is an "no concern" argument.
Additionally...
It is wrong.

I've not advocated "being very blunt" to those who aggravate
the situation by responding to trolling with flames and more
aggression.


I didn't mean you advocated it. I mean that you actually have been
blunt about these people. These are you words:

] The primary problem is a (relatively small) number of people
] who respond to every post by Nikos with a barrage of insults,
] demands, (what they think are) witty repartee, hints intended
] to "make" Nikos learn something, useless (to Nikos) links,
] new threads to discuss the "Nikos problem", and other trash
] that is far more obnoxious that anything Nikos posts and just
] serves to egg him on.

Now as far as I am concerned you can be as blunt as you want to
be. I just don't understand why you think you should be so
careful to Nikos, while at the same time you saw no need for
careful wording here.



A disproportionate number of your arguments above are that I am
not concerned about those (including you) who are deeply frustrated
with Nikos' bad behavior.


No, I point out that your behaviour doesn't *show* any such concern.


First, what my internal emotions (concern) are or are not is
irrelevant -- what I have expr

Re: Is this PEP-able? fwhile

2013-06-26 Thread Jerry Peters
Dennis Lee Bieber  wrote:
> On Mon, 24 Jun 2013 19:01:11 -0700 (PDT), rusi 
> declaimed the following:
> 
>>On Tuesday, June 25, 2013 3:08:57 AM UTC+5:30, Chris Angelico wrote:
>>> On Tue, Jun 25, 2013 at 5:52 AM,  <> wrote:
>>> 
>>> > (NOTE:  Many people are being taught to avoid 'break' and 'continue' at 
>>> > all
>>> > costs...
>>> 
>>> Why? Why on earth should break/continue be avoided?
>>
>>Because breaks and continues are just goto-in-disguise?
>>
>Because GOTO is a wild-card, capable of redirecting to anywhere;
> whereas break can only go to the exit of the loop (and in languages with
> labeled loops, possibly the exit of an outermost loop -- cf: Ada), and
> continue can only go to the next iteration of the loop (hmmm, does any
> language have a continue that can go to the next iteration of an outer
> loop?)

Bash:
continue: continue [n]
Resume for, while, or until loops.

Resumes the next iteration of the enclosing FOR, WHILE or
UNTIL loop.
If N is specified, resumes the Nth enclosing loop.

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


Re: re.finditer() skips unicode into selection

2013-06-26 Thread Terry Reedy

On 6/26/2013 3:18 PM, akshay.k...@gmail.com wrote:

I am using the following Highlighter class for Spell Checking to work on my 
QTextEdit.

class Highlighter(QSyntaxHighlighter):
 pattern = ur'\w+'
 def __init__(self, *args):
 QSyntaxHighlighter.__init__(self, *args)
 self.dict = None

 def setDict(self, dict):
 self.dict = dict

 def highlightBlock(self, text):
 if not self.dict:
 return
 text = unicode(text)
 format = QTextCharFormat()
 format.setUnderlineColor(Qt.red)
 format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
 unicode_pattern=re.compile(self.pattern,re.UNICODE|re.LOCALE)

 for word_object in unicode_pattern.finditer(text):
 if not self.dict.spell(word_object.group()):
 print word_object.group()
 self.setFormat(word_object.start(), word_object.end() - 
word_object.start(), format)

But whenever I pass unicode values into my QTextEdit the re.finditer() does not 
seem to collect it.

When I pass "I am a नेपाली" into the QTextEdit. The output is like this:

 I I I a I am I am I am a I am a I am a I am a I am a I am a I am a I am a

It is completely ignoring the unicode.


The whole text is unicode. It is ignoring the non-ascii, as you asked it 
to with re.LOCALE.


With 3.3.2:
import re

pattern = re.compile(r'\w+', re.LOCALE)
text = "I am a नेपाली"

for word in pattern.finditer(text):
print(word.group())
>>>
I
am
a

Delete ', re.LOCALE' and the following are also printed:
न
प
ल

There is an issue on the tracker about the vowel marks in नेपाली being 
mis-seen as word separators, but that is another issue.


Lesson: when you do not understand output, simplify code to see what 
changes. Separating re issues from framework issues is a big step in 
that direction.


? What might be the issue. I am new to PyQt and regex. Im using Python 
2.7 and PyQt4.


--
Terry Jan Reedy


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


Re: re.finditer() skips unicode into selection

2013-06-26 Thread MRAB

On 26/06/2013 20:18, akshay.k...@gmail.com wrote:

I am using the following Highlighter class for Spell Checking to work on my 
QTextEdit.

class Highlighter(QSyntaxHighlighter):


In Python 2.7, the re module has a somewhat limited idea of what a
"word" character is. It recognises 'DEVANAGARI LETTER NA' as a letter,
but 'DEVANAGARI VOWEL SIGN E' as a diacritic. The pattern ur'(?u)\w+'
will therefore split "नेपाली" into 3 parts.


 pattern = ur'\w+'
 def __init__(self, *args):
 QSyntaxHighlighter.__init__(self, *args)
 self.dict = None

 def setDict(self, dict):
 self.dict = dict

 def highlightBlock(self, text):
 if not self.dict:
 return
 text = unicode(text)
 format = QTextCharFormat()
 format.setUnderlineColor(Qt.red)
 format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)


The LOCALE flag is for locale-sensitive 1-byte per character
bytestrings. It's rarely useful.

The UNICODE flag is for dealing with Unicode strings, which is what you
need here. You shouldn't be using both at the same time!


 unicode_pattern=re.compile(self.pattern,re.UNICODE|re.LOCALE)

 for word_object in unicode_pattern.finditer(text):
 if not self.dict.spell(word_object.group()):
 print word_object.group()
 self.setFormat(word_object.start(), word_object.end() - 
word_object.start(), format)

But whenever I pass unicode values into my QTextEdit the re.finditer() does not 
seem to collect it.

When I pass "I am a नेपाली" into the QTextEdit. The output is like this:

 I I I a I am I am I am a I am a I am a I am a I am a I am a I am a I am a

It is completely ignoring the unicode. What might be the issue. I am new to 
PyQt and regex. Im using Python 2.7 and PyQt4.


There's an alternative regex implementation at:

http://pypi.python.org/pypi/regex

It's a drop-in replacement for the re module, but with a lot of
additions, including better handling of Unicode.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Ethan Furman

On 06/23/2013 12:05 PM, Ian Kelly wrote:

On Sun, Jun 23, 2013 at 12:46 PM, Steven D'Aprano
 wrote:

All is not lost, there are ways to make your classes cooperative. The
trick is to have your classes' __init__ methods ignore keyword arguments
they don't know what to do with. object used to do the same thing, but it
no longer does, so you need to add an extra class just before object to
swallow any args before they read object.


class Blocker(object):
 def __init__(self, **kwargs):
 # Block kwargs from reaching object
 super(Blocker, self).__init__()


I don't like the idea of doing this with a cooperative __init__
method.  If any keyword arguments were passed that weren't consumed,
that is probably a bug, and this just swallows the exception instead
of reporting it.


+1

Z

Of course, if you're doing cooperative inheritance with some other
method that doesn't exist on object, then this technique is necessary
to prevent the topmost class from trying to call that method on object
and erroring out.


But in that case the Blocker wouldn't call super since it is acting as the base 
class.

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


Re: Is this PEP-able? fwhile

2013-06-26 Thread Jan Riechers

On 26.06.2013 16:28, William Ray Wing wrote:

On Jun 26, 2013, at 7:49 AM, Fábio Santos mailto:fabiosantos...@gmail.com>> wrote:


On 26 Jun 2013 11:45, mailto:jim...@aol.com>> wrote:
>
> On Tuesday, June 25, 2013 9:30:54 PM UTC+5:30, Ian wrote:
> > In my experience the sorts of people who preach "one exit point" are
> > also all about defining preconditions and postconditions and proving
> > that the postconditions follow from the preconditions.  I think that
> > the two are linked, because the "one exit point" rule makes those
> > sorts of proofs simpler.
>
> Ah! utopia!
>
> For every one who knows about pre/post/invariant conditions, there
are 10 who follow goto-statement-is-harmful like a religious edict.
>
>
>
> I just checked and MISRA-C 2012 now allows gotos in specific,
limited circumstances.  I think it was the MISRA-C 1998 standard that
caused all this trouble.  So if MISRA now allows goto, why not
Python  :)
>

What is the matter? Just use the goto module...




Wondered when that would be mentioned.

Personally, I've never found that much use for GoTo, but as old timers
know, that same module adds the Come_From entry point, which is
priceless.  ;-)

Bill





Actually, jumping to any place a program (I know it from QBasic :) ) is 
some kind of voodoo.


At first it seems that any function calling itself or calling another 
function from another function solves the "goto" puzzle - called OO 
programming, objects in space and inheritance?


But at 2nd glimpse, jumping in any place of code (function) or routine, 
at a given place precisely - and to avoid any checks and unrelated code 
which might occur on a regular function call and without the need to 
provide additional arguments - that's kinda cool (if variables are in 
scope by the target statements :) )


That's somehow how I remember it.

But I guess if everything should run as in a factory, one entrance, one 
component, one result and independently from each other (isolated) and 
on many cores and such, a goto without argument passing or state 
variables might just end up in a big mess.


What do you think?



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


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Ethan Furman

On 06/23/2013 11:50 AM, Steven D'Aprano wrote:

On Sun, 23 Jun 2013 12:04:35 -0600, Ian Kelly wrote:


On Sun, Jun 23, 2013 at 11:36 AM, Steven D'Aprano
 wrote:

On Sun, 23 Jun 2013 11:18:41 -0600, Ian Kelly wrote:


Incidentally, although super() is useful, it's not perfect, and this
is one of my grievances with it: that a user can, based upon the name,
draw an inaccurate assumption about what it does without reading or
fully understanding the documentation on it, which might then result
in misusing it.


Wait a second... are you saying that the Python developers created an
advanced language feature relating to multiple inheritance, one of the
most complex OOP concepts around, so difficult that most other
languages simply prohibit it completely, and it wasn't instantly and
correctly intuited by every single programmer based only on the name?
Oh my stars, somebody call Ranting Rick, he needs to write a PyWart
post to expose this scandal!!!


Mostly I'm saying that super() is badly named.



What else would you call a function that does lookups on the current
object's superclasses?


Well, I would call it super().  Trouble is, that is not all that super() does.  
Going back to Ian's example:


On 06/23/2013 10:08 AM, Ian Kelly wrote:


class Base1(object):
def __init__(self, foo, **kwargs):
   super(Base1, self).__init__(**kwargs)

class Base2(object):
def __init__(self, bar, **kwargs):
   super(Base2, self).__init__(**kwargs)

class Derived(Base1, Base2):
def __init__(self, **kwargs):
   super(Derived, self).__init__(**kwargs)


Notice how Base1 calls super(), but depending on circumstances, it could by Base2 that super() calls.  Surely you are 
not suggesting that Base2 is therefore an ancestor of Base1?


It's too late to change the name now, but pretending there is no good and valid 
reason for confusion doesn't help.

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


Need help removing trailing zeros

2013-06-26 Thread bandcamp57
Hello, i'm making a calculator and I want to be able to use decimals but I 
don't like it when it comes out as ex.12.0 when it should be 12. I tried using 
.rstrip("0".rstrip(".") but that never seemed to work. If anyone has a solution 
please let me know, all help is greatly appreciated.

Code:

def Main():
print(" Welcome to the Calculator! What would you like to do?")
print("")
print("1) Basic Operations")

user_input = input("Enter the number corresponding with your choice: ")

if user_input == "1":
BasicOperations()

def BasicOperations():
def Add():
A = float(input("Enter the first number you want to add: "))
B = float(input("Enter the second number you want to add: "))
Answer = A+B
print("The sum of", A, "and", B, "is: ", Answer)
print("")
Main()

def Sub():
A = float(input("Enter the first number you want to subtract: "))
B = float(input("Enter the second number you want to subtract: "))
Answer = A-B
print("The difference between", A, "and", B, "is: ", Answer)
print("")
Main()

def Mul():
A = float(input("Enter the first number you want to multiply: "))
B = float(input("Enter the second number you want to multiply: "))
Answer = A*B
print("The product of", A, "and", B, "is: ", Answer)
print("")
Main()

def Div():
A = float(input("Enter the first number you want to divide: "))
B = float(input("Enter the second number you want to divide: "))
Answer = A/B
print("The quotient of", A, "and", B, "is: ", Answer)
print("")
Main()

print("You have selected Basic Operations.")
print("1) Addition")
print("2) Subtraction")
print("3) Multiplication")
print("4) Division")
print("")

choice = input("Select the number corresponding with your choice: ")

if choice == "1":
Add()
elif choice == "2":
Sub()
elif choice == "3":
Mul()
elif choice == "4":
Div()

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


Re: Limit Lines of Output

2013-06-26 Thread Joshua Landau
On 26 June 2013 17:46, Steven D'Aprano
 wrote:
> On Wed, 26 Jun 2013 16:24:56 +0100, Joshua Landau wrote:
>
>> On 25 June 2013 22:48, Gene Heskett  wrote:
>>> On Tuesday 25 June 2013 17:47:22 Joshua Landau did opine:
>>
>> I did not.
>
> Unless there are two people called "Joshua Landau" with email address
> , I'm afraid that you did.

Ah, but as rusi has understood, I did not.

(Although "I did not" may itself be opining, that was not the quoted text.)

Hey, sometimes I just like being cryptic.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help removing trailing zeros

2013-06-26 Thread Joshua Landau
On 26 June 2013 23:02,   wrote:
> Hello, i'm making a calculator and I want to be able to use decimals but I 
> don't like it when it comes out as ex.12.0 when it should be 12. I tried 
> using .rstrip("0".rstrip(".") but that never seemed to work. If anyone has a 
> solution please let me know, all help is greatly appreciated.
>
> Code:


Was that really necessary?

All you needed to give use was "print(1.0)"; why post so much?

Either:
"{:g}".format(1.0)

or, if you hate scientific notation:
"{:f}".format(1.0).rstrip(".0")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help removing trailing zeros

2013-06-26 Thread PyNoob
Sorry about that... And thanks for your help, but I don't quite understand. 
Would that make it off your example print("{:g}".format(1.0))?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help removing trailing zeros

2013-06-26 Thread Joshua Landau
On 26 June 2013 23:21, PyNoob  wrote:
> Sorry about that... And thanks for your help, but I don't quite understand.
That's fine, but...

> Would that make it off your example print("{:g}".format(1.0))?
I don't understand this sentence.

But, hey, I forgot to check what level you were working at -- there's
little point running ahead of what you know.

Did you try:
print("{:g}".format(1.0))
? It works for me. So, yes, that's what you want.

So instead of:
print("The quotient of", A, "and", B, "is: ", Answer)

you want
print("The quotient of", A, "and", B, "is: ", "{:g}".format(Answer))

See how I just used "{:g}".format as some kind of magic-fixing-power?

Well, why does it work?

[See http://docs.python.org/3/library/stdtypes.html#str.format and the
sub-links for a more full explanation]

Run each of these in an interpreter:

"{} {} {} {} {}".format("This", "is", "a", "formatted", "string!")

"It is really useful: I have {} cows and {}
sheep".format(number_of_cows, number_of_sheep)

"It gives me back a formatted {}, which I can
print".format(type("".format()).__name__)

"I can also give things indexes: {3} {2} {1} {0}".format("Print",
"in", "reverse", "order")

"I can also give things names: {egg} {ham}
{flies}".format(egg="Are", ham="you", flies="there?")

"It's not just {:!<10}".format("that")

"It lets me choose how I want things to be printed: {0:@^6},
{0:~>10}, {0:£<8}".format("Hi")

"And for numbers: {0:e}, {0:.10%}, {0:#.1f}".format(123.456)

So you just want the best formatter; see
[http://docs.python.org/3/library/string.html#format-specification-mini-language]

Your best choice is "{:g}" which just means "general format".

Note that you can also write your prints as so:

print("The quotient of {} and {} is: {:g}".format(A, B, Answer))

Whether you prefer it is your choice.


--


In regards to .rstrip: It will only work on strings; so you need to
convert like so:
str(1.0).rstrip("0").rstrip(".")

And note that:
1) My .rstrip("0.") was wrong and foolish (try str(10).rstrip("0."))
2) This needs the string to be reliably formatted in this style:
"{:#f}" *and* requires it to be a float.

So really, you'd need:

"{:#f}".format(float(number)).rstrip("0").rstrip(".")

Which is ugly, but I guess it works.
-- 
http://mail.python.org/mailman/listinfo/python-list


SQL code generation from table-free boolean queries?

2013-06-26 Thread Foo Stack
Given string input such as:
foo=5 AND a=6 AND date=now OR date='2013/6' AND bar='hello'

I am going to implement:

- boolean understanding (which operator takes precendence)
- spliting off of attributes into my function which computes their table in the 
SQL database
- piece everything together into an SQL query

However, it came to me that this is probably a very generic thing; and there 
might be a library for it.

If that's so, can you recommend it?

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


Re: class factory question

2013-06-26 Thread Joshua Landau
On 26 June 2013 16:40, Peter Otten <__pete...@web.de> wrote:
> Joshua Landau wrote:
>
>> I would say if a dict isn't good, there are still some cases where you
>> might not want to use globals.
>>
>> I _might_ do:
>
>> # Make a module
>> module_for_little_classes = ModuleType("module_for_little_classes",
>> "All the things")
>> module_for_little_classes.__dict__.update(little_classes)
>
> Hm, from within module_for_little_classes that is globals(). To illustrate:
>
 import __main__ as main
 globals() is main.__dict__
> True

Yes, that's true - but the point wasn't not to use "globals the
function", but not to use *this* global scope.

> Also, I'd spell module.__dict__ vars(module).

Again, good catch. Definitely that.

> That said I agree that it's a good idea to use a dedicated module (not
> necessarily created on the fly) for those dynamically generated classes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SQL code generation from table-free boolean queries?

2013-06-26 Thread Tim Chase
On 2013-06-26 16:17, Foo Stack wrote:
> Given string input such as:
> foo=5 AND a=6 AND date=now OR date='2013/6' AND bar='hello'
> 
> I am going to implement:
> 
> - boolean understanding (which operator takes precendence)
> - spliting off of attributes into my function which computes their
> table in the SQL database
> - piece everything together into an SQL query
> 
> However, it came to me that this is probably a very generic thing;
> and there might be a library for it.

It sounds like you might want to use pyparsing and start with
something akin to this[1]

-tkc

[1]
http://pyparsing.wikispaces.com/file/view/simpleSQL.py




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


Re: class factory question

2013-06-26 Thread Fábio Santos
On 26 Jun 2013 14:14, "Tim"  wrote:
>
> I am extending a parser and need to create many classes that are all
subclassed from the same object (defined in an external library).  When my
module is loaded I need all the classes to be created with a particular
name but the behavior is all the same. Currently I have a bunch of lines
like this:
>
> class Vspace(Base.Command): pass
> class Boldpath(Base.Command): pass
>
> There are a bunch of lines like that.
> Is there a better way? Something like
>
> newclasses = ['Vspace', 'Boldpath', ... ]
> for name in newclasses:
> tmp = type(name, (Base.Command,) {})
> tmp.__name__ = name
>
> Is there a more pythonic way?
> thanks,
> --Tim
>

I would say The Most Pythonic Way is to use the class declarations as you
are doing now. Explicit is better than implicit, or so the zen says.

It will be better for tools as well. I'd like to see code completion work
on dynamically created classes like that (unless you use __all__ to list
them.).

And, are you really looking for classes here? If you just want to create
different names with different identities, you could consider using plain
old strings or object() to do that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Steven D'Aprano
On Wed, 26 Jun 2013 13:14:44 -0700, Ethan Furman wrote:

> On 06/23/2013 11:50 AM, Steven D'Aprano wrote:

>> What else would you call a function that does lookups on the current
>> object's superclasses?
> 
> Well, I would call it super().  Trouble is, that is not all that super()
> does.  Going back to Ian's example:
> 
>> On 06/23/2013 10:08 AM, Ian Kelly wrote:
>>>
>>> class Base1(object):
>>> def __init__(self, foo, **kwargs):
>>>super(Base1, self).__init__(**kwargs)
>>>
>>> class Base2(object):
>>> def __init__(self, bar, **kwargs):
>>>super(Base2, self).__init__(**kwargs)
>>>
>>> class Derived(Base1, Base2):
>>> def __init__(self, **kwargs):
>>>super(Derived, self).__init__(**kwargs)
> 
> Notice how Base1 calls super(), but depending on circumstances, it could
> by Base2 that super() calls.  Surely you are not suggesting that Base2
> is therefore an ancestor of Base1?

No. But "the current object" is not Base1, but an instance of Derived, 
and Base2 *is* an ancestor of Derived. Perhaps if I had said "self" 
instead of current object, you wouldn't have made this error. If so, I 
apologise for confusing you.

When your inheritance chain begins from an instance of Base1, Base2 
methods will never be called. It is only when the chain begins from 
Derived that Base2 may be called, which is exactly as it should be.


> It's too late to change the name now, but pretending there is no good
> and valid reason for confusion doesn't help.

The confusion is not with the name, or what super does, but with 
inheritance itself.


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


Re: Limit Lines of Output

2013-06-26 Thread Steven D'Aprano
On Wed, 26 Jun 2013 10:09:13 -0700, rusi wrote:

> On Wednesday, June 26, 2013 8:54:56 PM UTC+5:30, Joshua Landau wrote:
>> On 25 June 2013 22:48, Gene Heskett  wrote:
>> > On Tuesday 25 June 2013 17:47:22 Joshua Landau did opine:
>> 
>> I did not.
> 
> I guess Joshua is saying that saying ≠ opining

But it is. From WordNet:

opine
v 1: express one's opinion openly and without fear or
 hesitation; "John spoke up at the meeting" [syn: opine,
 speak up, speak out, animadvert, sound off]


Admittedly we cannot tell what Joshua's mental state was at the time he 
responded to Bryan, he may have been absolutely terrified for all we 
know, but there's no sign of this fear, and no reason to think that he 
hesitated, given that his response came through a mere nine minutes after 
Bryan's comment.

Or if you prefer the Collaborative International Dictionary of English:

Opine \O*pine"\, v. t. & i. [imp. & p. p. Opined; p. pr. & vb.
   n. Opining.] [L. opinari, p. p. opinatus; akin to opinus
   (in comp.) thinking, and perh. to E. apt: cf. F. opiner.]
   To have an opinion; to judge; to think; to suppose. --South.
   [1913 Webster]



> [Or is he opining?]

That's just his opinion, man.

*wink*



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


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Ian Kelly
On Wed, Jun 26, 2013 at 5:54 PM, Steven D'Aprano
 wrote:
> No. But "the current object" is not Base1, but an instance of Derived,
> and Base2 *is* an ancestor of Derived. Perhaps if I had said "self"
> instead of current object, you wouldn't have made this error. If so, I
> apologise for confusing you.

If I am reading a class definition and see the code
super().__init__(), and I am not familiar with super() and do not
bother to go look it up in the docs because it looks "obvious" (or
perhaps I have read a tutorial that simply mentions that super() is
used to call methods from a superclass and elides over the details) --
my assumption is not going to be that super() is looking into
superclasses relative to the class of self, but more simply that
super() is looking into superclasses relative to the class that I'm
currently reading.

Why?  Because that's the way that "super" works in every other
language I know of that has it.

Java: super looks depth-first from the contextual class (no multiple
inheritance allowed)
Ruby: super looks depth-first from the contextual class (no multiple
inheritance allowed)
Objective-C: super looks depth-first from the contextual class (no
multiple inheritance allowed)
Perl 5: by default, super looks depth-first from the contextual class
(multiple inheritance IS allowed; the C3 linearization (MRO) CAN be
used, but it must first be explicitly enabled with a pragma directive)

Now if you're coming from Java, Ruby, or Objective-C and reading a
Python super() statement, then hopefully you will stop and think,
"Hey, wait a minute.  [Other language] doesn't have multiple
inheritance and Python does, so how does super() work here?"  More
likely though you're not even thinking about multiple inheritance when
you read that statement, and you just assume that it works exactly
like the super keyword that you're used to, and you move on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the semantics meaning of 'object'?

2013-06-26 Thread Ethan Furman

On 06/26/2013 04:54 PM, Steven D'Aprano wrote:

On Wed, 26 Jun 2013 13:14:44 -0700, Ethan Furman wrote:


On 06/23/2013 11:50 AM, Steven D'Aprano wrote:



What else would you call a function that does lookups on the current
object's superclasses?


Well, I would call it super().  Trouble is, that is not all that super()
does.  Going back to Ian's example:


On 06/23/2013 10:08 AM, Ian Kelly wrote:


class Base1(object):
 def __init__(self, foo, **kwargs):
super(Base1, self).__init__(**kwargs)

class Base2(object):
 def __init__(self, bar, **kwargs):
super(Base2, self).__init__(**kwargs)

class Derived(Base1, Base2):
 def __init__(self, **kwargs):
super(Derived, self).__init__(**kwargs)


Notice how Base1 calls super(), but depending on circumstances, it could
by Base2 that super() calls.  Surely you are not suggesting that Base2
is therefore an ancestor of Base1?


No. But "the current object" is not Base1, but an instance of Derived,
and Base2 *is* an ancestor of Derived. Perhaps if I had said "self"
instead of current object, you wouldn't have made this error. If so, I
apologise for confusing you.


No apology necessary.  I understand both inheritance and super fairly well, and 
you did not confuse me.



When your inheritance chain begins from an instance of Base1, Base2
methods will never be called. It is only when the chain begins from
Derived that Base2 may be called, which is exactly as it should be.


Absolutely.  That doesn't change the fact that when writing Base1 you are still using the word 'super', and hopefully 
remembering that even though it's named 'super' it may in fact call an object that is sideways from where you're at now 
and have absolutely no relation to Base1's ancestors.




It's too late to change the name now, but pretending there is no good
and valid reason for confusion doesn't help.


The confusion is not with the name, or what super does, but with
inheritance itself.


Good names are important because a good name can help alleviate confusion.  A bad name can exacerbate it.  Given the 
terminology of superclasses and subclasses, naming a function 'super' that can in fact call another class that is in no 
way the superclass of the class in which it is written, can easily cause confusion.


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


Re: Need help removing trailing zeros

2013-06-26 Thread PyNoob
I get it now! Thank you so much for your help, I really appreciate it. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re.finditer() skips unicode into selection

2013-06-26 Thread darpan6aya
Thanks MRAB, your suggestion worked. But then it brought an error 

'ascii' codec can't encode characters in position 0-1: ordinal not in 
range(128)

I corrected this by encoding it to 'utf-8'. The code looks like this now. 

pattern = ur'(?u)\w+' 

def __init__(self, *args):
QSyntaxHighlighter.__init__(self, *args)
self.dict = None

def setDict(self, dict):
self.dict = dict

def highlightBlock(self, text):
if not self.dict:
return
text = unicode(text)
format = QTextCharFormat()
format.setUnderlineColor(Qt.red)
format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)

unicode_pattern=re.compile(self.pattern,re.UNICODE)

for word_object in unicode_pattern.finditer(text):
if not self.dict.spell(word_object.group().encode('utf-8')):
print word_object.group().encode('utf-8')
self.setFormat(word_object.start(), word_object.end() - 
word_object.start(), format)

The problem now is that all the vowels are separated from the root word, such 
that if you type मेरो, the म and े are printed separately. (the े appears as a 
box instead). What am I doing wrong?

Like this.

मेरो नाम रुपा हो।
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re.finditer() skips unicode into selection

2013-06-26 Thread darpan6aya
[IMG]http://i41.tinypic.com/35002rr.png[/IMG]

Heres a screenshot http://i41.tinypic.com/35002rr.png
-- 
http://mail.python.org/mailman/listinfo/python-list


FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-26 Thread Thrinaxodon

=
>MESSAGE FROM COMPUTER GEEK.
=
>
THRINAXODON HAS RECENTLY RECEIVED THIS MESSAGE FROM THE PYTHON FOUNDER:

Oh my God! It's hard to program with, it`s troubling for so many people! 
I call for the cancellation of the Python programming language.

>
THRINAXODON: Wow! I had much trouble, myself. In fact; the makers of the 
Python language watch every move o, it, therefore violating privacy.

>
FOUNDER: It`s weird...I have 5,000 pieces of info. on every person that 
uses it. That`s the real reason...

>
THRINAXODON: I used it!
>
FOUNDER: It`s really hard to use. It requires 20 books just to know how 
to code with it.

>
THRINAXODON: Time to announce the cancellation at comp.lang.python!
>
===
THRINAXODON IS NOW ON TWITTER.
--
http://mail.python.org/mailman/listinfo/python-list


Re: re.finditer() skips unicode into selection

2013-06-26 Thread darpan6aya
Thanks MRAB your alternative regex implementation worked flawlessly. 
It works now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-26 Thread Ben Finney
Thrinaxodon  writes:

> [… strange fictitious dialogue …]
> THRINAXODON IS NOW ON TWITTER.

Thrinaxodon should not bother to post such hostility here again.

-- 
 \  “I don't want to live peacefully with difficult realities, and |
  `\ I see no virtue in savoring excuses for avoiding a search for |
_o__)real answers.” —Paul Z. Myers, 2009-09-12 |
Ben Finney

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


Re: "private" class attributes

2013-06-26 Thread wgtrey


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