Re: howto remove the thousand separator

2013-04-15 Thread Steven D'Aprano
On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote:

> On 15/04/2013 02:14, Steven D'Aprano wrote:
>> On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote:
>>
>>> On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano
>>>  wrote:
 On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote:

> cleaned=''
> for c in myStringNumber:
> if c != ',':
>   cleaned+=c
> int(cleaned)

 due to being an O(N**2)  algorithm.
>>>
>>> What on earth makes you think that is an O(n**2) algorithm and not
>>> O(n)?
>>
>> Strings are immutable. Consider building up a single string from four
>> substrings:
>>
>> s = ''
>> s += 'fe'
>> s += 'fi'
>> s += 'fo'
>> s += 'fum'
>>
>> Python *might* optimize the first concatenation, '' + 'fe', to just
>> reuse 'fe', (but it might not). Let's assume it does, so that no
>> copying is needed. Then it gets to the second concatenation, and now it
>> has to copy characters, because strings are immutable and cannot be
>> modified in place.
> 
> Actually, I believe that CPython is optimised to modify strings in place
> where possible, so that the above would surprisingly turn out to be
> O(n). See the following thread where I asked about this:

I deliberately didn't open that can of worms, mostly because I was in a 
hurry, but also because it's not an optimization you can rely on. It 
depends on the version, implementation, operating system, and the exact 
code running.

1) It only applies to code running under some, but not all, versions of 
CPython. It does not apply to PyPy, Jython, IronPython, and probably not 
other implementations.


2) Even under CPython, it can fail. It *will* fail if you have multiple 
references to the same strings. And it *may* fail depending on the 
vagaries of the memory management system in place, e.g. code that is 
optimized on Linux may fail to optimize under Windows, leading to slow 
code.


As far as I'm concerned, the best advice regarding this optimization is:

- always program as if it doesn't exist;

- but be glad it does when you're writing quick and dirty code in the 
interactive interpreter, where the convenience of string concatenation 
may be just too darn convenient to bother doing the right thing.



> http://groups.google.com/group/comp.lang.python/browse_thread/
thread/990a695fe2d85c52
> 
> (Sorry for linking to Google Groups. Does anyone know of a better c.l.p.
> web archive?)

The canonical (although possibly not the best) archive for c.l.p. is the 
python-list mailing list archive:

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


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


Re: howto remove the thousand separator

2013-04-15 Thread Steven D'Aprano
On Sun, 14 Apr 2013 22:35:42 -0400, Roy Smith wrote:

> In article ,
>  Walter Hurry  wrote:
> 
>> On Mon, 15 Apr 2013 11:29:17 +1000, Chris Angelico wrote:
>> 
>> > There are actually a lot of optimizations done, so it might turn out
>> > to be O(n) in practice. But strictly in the Python code, yes, this is
>> > definitely O(n*n).
>> 
>> In any event, Janssen should cease and desist offering advice here if
>> he can't do better than that.
> 
> That's a little harsh.  Sure, it was a "sub-optimal" way to write the
> code (for all the reasons people mentioned), but it engendered a good
> discussion.


Agreed. I'd rather people come out with poor code, and LEARN from the 
answers, than feel that they dare not reply until they're an expert.



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


Re: classes and sub classes?

2013-04-15 Thread Peter Otten
Jason Friedman wrote:

>> NwInvDb = NetworkInventoryDatabase, yes you are correct, it creates the
> database handle and makes it ready for use.
> 
> I am interested in opinions.  I for one dislike abbreviations on the
> theory
> that programs are read more than they are written.  I would probably use
> this variable name:
> 
> network_inventory_db_connection = ...
> 
> And yes, I'm aware that "db" is an abbreviation.  I believe I am following
> a few Zen principles:
> 
> Beautiful is better than ugly.
> Explicit is better than implicit.
> Readability counts.
> Special cases aren't special enough to break the rules, Although
> practicality beats purity.
> 
> What would others use?

inventory_db

The rest should be clear from the context.

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


Re: howto remove the thousand separator

2013-04-15 Thread Chris Angelico
On Mon, Apr 15, 2013 at 5:03 PM, Steven D'Aprano
 wrote:
> On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote:
>
>> On 15/04/2013 02:14, Steven D'Aprano wrote:
>>> Strings are immutable. Consider building up a single string from four
>>> substrings:
>>
>> Actually, I believe that CPython is optimised to modify strings in place
>> where possible, so that the above would surprisingly turn out to be
>> O(n). See the following thread where I asked about this:
>
> I deliberately didn't open that can of worms, mostly because I was in a
> hurry, but also because it's not an optimization you can rely on. It
> depends on the version, implementation, operating system, and the exact
> code running.
>
> As far as I'm concerned, the best advice regarding this optimization is:
>
> - always program as if it doesn't exist;
>
> - but be glad it does when you're writing quick and dirty code in the
> interactive interpreter, where the convenience of string concatenation
> may be just too darn convenient to bother doing the right thing.

Agreed; that's why, in my reply, I emphasized that the pure Python
code IS quadratic, even though the actual implementation might turn
out linear. (I love that word "might". Covers myriad possibilities on
both sides.)

Same goes for all sorts of other possibilities. I wouldn't test string
equality with 'is' without explicit interning, even if I'm testing a
constant against another constant in the same module - but I might get
a big performance boost if the system's interned all its constants for
me.

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


Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Uday S Reddy
Mark Janssen writes:

> After the 2001 "type/class unification" , it went towards Alan Kay's ideal
> of "everything is an object"
> 
> As a contrast, this is very distinct from C++, where everything is
> concretely rooted in the language's type model which in *itself* is
> rooted (from it's long history) in the CPU architecture. ...
> 
> My question is:  Is there something in the Computer Science literature
> that has noticed this distinction/development in programming language
> design and history?

In programming language theory, there is no law to the effect that
"everything" should be of one kind or another.  So, we would not go with
Alan Kay's ideal.

Having said that, theorists do want to unify concepts wherever possible and
wherever they make sense.  Imperative programming types, which I will call
"storage types", are semantically the same as classes.  Bare storage types
have predefined operations for 'getting' and 'setting' whereas classes allow
user-defined operations.  So, the distinction made between them in typical
programming languages is artificial and implementation-focused.  C and C++
are especially prone to this problem because they were designed for writing
compilers and operating systems where proximity to the machine architecture
seems quite necessary.  The higher-level languages such as Java are moving
towards abolishing the distinction.  Scala might be the best model in this
respect, though I do not know its type system fully.

Here are a couple of references in theoretical work that might be helpful in
understanding these connections:

- John Reynolds, The Essence of Algol, in de Bakker and van Vliet (eds)
Algorithmic Languages, 1981.  Also published in O'Hearn and Tennent (eds)
Algol-like Languages, Vol. A, 1997.

- Uday Reddy, Objects and Classes in Algol-like Languages, Information and
Computation, 172:63-97, 2002. (previously in FOOL workshop 1998.)
http://www.cs.bham.ac.uk/~udr/papers/classes.pdf

However, there are properties that are special to storage types, which are
not shared by all class types.  Sometimes, they simplify some theoretical
aspects.  It is not uncommon for authors to make a distinction between
storage types and general types.  An example is one of our own papers:

- Swarup, Reddy and Ireland: Assignments for applicative languages, FPCA
1991. http://www.cs.bham.ac.uk/~udr/papers/assign.pdf

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


RE: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Moez AbdelGawad





> Date: Sun, 14 Apr 2013 22:55:59 -0700
> From: deles...@gmail.com
> To: dreamingforw...@gmail.com
> CC: types-l...@lists.seas.upenn.edu; python-list@python.org
> Subject: Re: [TYPES] The type/object distinction and possible synthesis of  
> OOP and imperative programming languages
> 
> [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ]
> 
> I'm not quite sure I understand your question, but I'll give it a shot.  :-)
> 

I'm in this same camp too :)

> The C/C++ model, in which the types are anchored to the machine hardware,
> in the exception, not the rule.  In the academic literature,  "type theory"
> is almost entirely focused on studying abstract models of computation that
> are purely mathematical, and bear no resemblance to the underlying
> hardware.  The lambda calculus is the most general, and most commonly used
> formalism, but there are many others; e.g. Featherweight Java provides a
> formal model of objects and classes as they are used in Java.
> 
> "Types and Programming Languages", by Benjamin Pierce, is an excellent
> introductory textbook which describes how various language features,
> including objects, can be formalized.  If you are interested in OOP, Abadi
> and Cardelli's "Theory of Objects" is the obvious place to start, although
> I'd recommend reading Pierce's book first if you want to understand it.
>  :-)  Abadi and Cardelli discuss both class-based languages, and pure
> object languages.  If you are interested in the type/object distinction in
> particular, then I'll shamelessly plug my own thesis: "Pure Subtype
> Systems" (available online), which describes a formal model in which types
> are objects, and objects are types.  If you are familiar with the Self
> language, then you can think of it as a type system for Self.
> 

Offering a different view, I'd like to (also, shamelessly) plug my own thesis: 
"NOOP: A Mathematical Model of OOP" (available online) in which I 
denotationally model nominally-typed (ie, statically-typed class-based) OO 
languages such as Java, C#, C++ and Scala (but not Python).

In agreement with the most common tradition in PL research, types in NOOP are 
modeled abstractly as (certain) sets (of objects).   NOOP largely mimics, for 
nominally-typed OO languages, what Cardelli, Cook, and others earlier did for 
structurally-typed OO languages.

Regards,

-Moez

> Once you have a type system in place, it's usually fairly straightforward
> to compile a language down to actual hardware.  An interpreter, like that
> used in Python, is generally needed only for untyped or "dynamic"
> languages.  There are various practical considerations -- memory layout,
> boxed or unboxed data types, garbage collection, etc. -- but the basic
> techniques are described in any compiler textbook.  Research in the areas
> of "typed assembly languages" and "proof carrying code" are concerned with
> ensuring that the translation from high-level language to assembly language
> is sound, and well-typed at all stages.
> 
>   -DeLesley
> 
> 
> 
> On Sun, Apr 14, 2013 at 8:48 PM, Mark Janssen 
> wrote:
> 
> > [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list]
> >
> > Hello,
> >
> > I'm new to the list and hoping this might be the right place to
> > introduce something that has provoked a bit of an argument in my
> > programming community.
> >
> > I'm from the Python programming community.  Python is an "interpreted"
> > language.  Since 2001, Python's has migrated towards a "pure" Object
> > model (ref: http://www.python.org/download/releases/2.2/descrintro/).
> > Prior to then, it had both types and classes and these types were
> > anchored to the underlying C code and the machine/hardware
> > architecture itself.  After the 2001 "type/class unification" , it
> > went towards Alan Kay's ideal of "everything is an object".  From
> > then, every user-defined class inherited from the abstract Object,
> > rooted in nothing but a pure abstract ideal.  The parser, lexer, and
> > such spin these abstrations into something that can be run on the
> > actual hardware.
> >
> > As a contrast, this is very distinct from C++, where everything is
> > concretely rooted in the language's type model which in *itself* is
> > rooted (from it's long history) in the CPU architecture.   The STL,
> > for example, has many Container types, but each of them requires using
> > a single concrete type for homogenous containers or uses machine
> > pointers to hold arbitrary items in heterogeneous containers (caveat:
> > I haven't programmed in C++ for a long time, so it's possible this
> > might not be correct anymore).
> >
> > My question is:  Is there something in the Computer Science literature
> > that has noticed this distinction/development in programming language
> > design and history?
> >
> > It's very significant to me, because as languages went higher and
> > higher to this pure OOP model, the programmer+data ecosystem tended
> > towards very pers

Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Steven D'Aprano
On Sun, 14 Apr 2013 20:48:05 -0700, Mark Janssen wrote:

> Hello,
> 
> I'm new to the list and hoping this might be the right place to
> introduce something that has provoked a bit of an argument in my
> programming community.
> 
> I'm from the Python programming community.  Python is an "interpreted"
> language.  Since 2001, Python's has migrated towards a "pure" Object
> model (ref: http://www.python.org/download/releases/2.2/descrintro/).
> Prior to then, it had both types and classes and these types were
> anchored to the underlying C code and the machine/hardware architecture
> itself.


Incorrect.

Python's data model has always been 100% object oriented. Prior to the 
"class/type" unification, it simply had *two distinct* implementations of 
objects: types, which were written in C, and classes, which were written 
in Python.

After unification, the two kinds of object were no longer entirely 
distinct -- you could then subclass types in Python code, using the same 
"class" keyword as you would use for a pure-Python class.

And starting with Python 3, the last vestiges of the distinction have 
disappeared. Now, "class" and "type" are mere synonyms. Both built-in 
types and custom classes use the same mechanism.


> After the 2001 "type/class unification" , it went towards Alan
> Kay's ideal of "everything is an object".  From then, every user-defined
> class inherited from the abstract Object, rooted in nothing but a pure
> abstract ideal.

Incorrect. In Python 2.7:


py> class AClass:
... pass
... 
py> issubclass(AClass, object)
False



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


RE: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Ombongi Moraa Fe
hello Team,

I have this fairly simple script to iterate the dictionary items and check
if the items match certain values;

dictionary={'1234567890':001, '0987654321':002}
for k, v in dictionary.iteritems():
.
.  #suds client statements;

if (k == '1234567890' and v == 001):
criteria='Test'
elif (k == '0987654321' and v == 002):
criteria='Running'
client.service.methodcall(value1,value2,criteria)



During the first run of the dictionary items, the client.service.methodcall
is called only once as expected; and a success initiation response is
received from server. However, during the second run, the
client.service.methodcall is called twice - when i check the log files, i
see the client send request is done twice. Duplicate send requests of the
same parameters results in a error in inititating a connection.

Someone please show me why my second run results in the
client.service.methodcall() running twice. I can't seem to get a hang on
it.

Saludos

Ombongi Moraa Faith
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Mark Lawrence

On 15/04/2013 11:50, Ombongi Moraa Fe wrote:

hello Team,

I have this fairly simple script to iterate the dictionary items and
check if the items match certain values;

dictionary={'1234567890':001, '0987654321':002}
for k, v in dictionary.iteritems():
 .
 .  #suds client statements;

 if (k == '1234567890' and v == 001):
 criteria='Test'
 elif (k == '0987654321' and v == 002):
 criteria='Running'
 client.service.methodcall(value1,value2,criteria)

During the first run of the dictionary items, the
client.service.methodcall is called only once as expected; and a success
initiation response is received from server. However, during the second
run, the client.service.methodcall is called twice - when i check the
log files, i see the client send request is done twice. Duplicate send
requests of the same parameters results in a error in inititating a
connection.


What makes you think there should be one call given the code above? 
client.service.methodcall must be called for every loop iteration, so 
there's one call with criteria 'test' and one with 'Running'.  Note 
there's no guarantee that the calls will always take place in the same 
order.  Slight aside there's no need for the round brackets in the if 
and elif above.




Someone please show me why my second run results in the
client.service.methodcall() running twice. I can't seem to get a hang on
it.

Saludos

Ombongi Moraa Faith




--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


RE: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Peter Otten
Ombongi Moraa Fe wrote:

> hello Team,
> 
> I have this fairly simple script to iterate the dictionary items and check
> if the items match certain values;
> 
> dictionary={'1234567890':001, '0987654321':002}
> for k, v in dictionary.iteritems():
> .
> .  #suds client statements;
> 
> if (k == '1234567890' and v == 001):
> criteria='Test'
> elif (k == '0987654321' and v == 002):
> criteria='Running'
> client.service.methodcall(value1,value2,criteria)
> 
> 
> 
> During the first run of the dictionary items, the
> client.service.methodcall is called only once as expected; and a success
> initiation response is received from server. However, during the second
> run, the client.service.methodcall is called twice - when i check the log
> files, i see the client send request is done twice. Duplicate send
> requests of the same parameters results in a error in inititating a
> connection.
> 
> Someone please show me why my second run results in the
> client.service.methodcall() running twice. I can't seem to get a hang on
> it.

methodcall() is inside the for-loop and will be repeated on every iteration.
In your example code the dictionary has two entries -- therefore 
methodcall() will be invoked twice. 

If the length of the dictionary changes from 1 to 2 while your programm is 
running you will see the behaviour you described.

One way to avoid the problem is to omit the loop:

criteria = None
if dictionary.get("1234567890") == 1:
criteria = "Test"
elif dictionary.get("0987654321") == 2:
criteria = "Running
else:
raise Exception("undefined criteria") # for example
client.service.methodcall(value1, value2, criteria)


Note that leading zeros are usually not a good idea as they mark integer 
constants as octal:

>>> 001
1
>>> 010
8
>>> 008
  File "", line 1
008
  ^
SyntaxError: invalid token


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


Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?

2013-04-15 Thread rusi
I am trying to understand your points Chris. On the one hand you say:

On Apr 14, 6:22 pm, Chris Angelico  wrote:
> No, no, a thousand times no! If I am doing financial transactions,
> even if I'm alone on my machine, I will demand full ACID compliance.



On the other you describe a bookmark storage scheme (which it seems
you are recommending); to wit

>  Suppose bookmarks are stored like this:
>
> r"""Some-Browser-Name web bookmarks file - edit with care
> url:http://www.google.com/
> title: Search engine
> icon: whatever-format-you-want-to-use
>
> url:http://www.duckduckgo.com/
> title: Another search engine
>
> url:http://www.python.org/
>
> url:ftp://192.168.0.12/
> title: My FTP Server
> desc: Photos are in photos/, videos are in videos/
>  Everything else is in other/
> user: root
> pass: secret
> """
>
> The parsing of this file is pretty simple. Blank line marks end of
> entry;…

So are you saying that if one switches from the non-ACID compliant
sqlite to your simple-text data-format, the new 'database' (note the
quote marks) will now become ACID compliant?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Dave Angel

On 04/15/2013 06:50 AM, Ombongi Moraa Fe wrote:

hello Team,

I have this fairly simple script to iterate the dictionary items and check
if the items match certain values;

dictionary={'1234567890':001, '0987654321':002}
for k, v in dictionary.iteritems():
 .
 .  #suds client statements;

 if (k == '1234567890' and v == 001):
 criteria='Test'
 elif (k == '0987654321' and v == 002):
 criteria='Running'
 client.service.methodcall(value1,value2,criteria)




That's not the whole script, since at the least, you need some code to 
import or create client, value1 and value2.




During the first run of the dictionary items,


What do you mean by that, exactly?  Do you mean the first time around 
the loop?  Or the first time the script is run?  Or what?



the client.service.methodcall
is called only once as expected; and a success initiation response is
received from server. However, during the second run, the
client.service.methodcall is called twice - when i check the log files, i
see the client send request is done twice. Duplicate send requests of the
same parameters results in a error in inititating a connection.

Someone please show me why my second run results in the
client.service.methodcall() running twice. I can't seem to get a hang on
it.




Why not take out the middleman, and just add some prints in the loop?  I 
don't see any point in the loop;  if you're sure there are exactly two 
items in the dict, just process those two items.  If you're not sure, 
what do you want to happen when you encounter something that doesn't 
match either the if or the elif.  Currently, you'll just repeat the last 
methodcall.


One final thing, a dict's order is not promised.  So you may process 
these items in either as "Test" and "Running", or in the reverse order.


My guess is that this is not your actual code at all, and you're trying 
to "simplify" it for us.  You probably have more than two items in the 
dict, and one of them is NOT matching any of the if/elif tests. 
Possibly it's not matching because of your mistaken use of octal.  Octal 
won't hurt for ints below 8, but you probably don't restrict it in the 
real code.  For example,  v = 030 will not match equal in the following:

 elif v == 30:



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


Re: classes and sub classes?

2013-04-15 Thread Neil Cerutti
On 2013-04-15, Peter Otten <__pete...@web.de> wrote:
> Jason Friedman wrote:
>>> NwInvDb = NetworkInventoryDatabase, yes you are correct, it
>>> creates the database handle and makes it ready for use.
>> 
>> I am interested in opinions.  I for one dislike abbreviations
>> on the theory that programs are read more than they are
>> written.  I would probably use this variable name:
>> 
>> network_inventory_db_connection = ...
>> 
>> And yes, I'm aware that "db" is an abbreviation.  I believe I am following
>> a few Zen principles:
>> 
>> Beautiful is better than ugly.
>> Explicit is better than implicit.
>> Readability counts.
>> Special cases aren't special enough to break the rules, Although
>> practicality beats purity.
>> 
>> What would others use?
>
> inventory_db
>
> The rest should be clear from the context.

How long and descriptive a name is ought to depend on the
wideness of its visibility. n might be acceptable in a short
comprehension, while network_inventory_db_connection might be
apposite for a module-level name.

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


Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?

2013-04-15 Thread Chris Angelico
On Mon, Apr 15, 2013 at 9:45 PM, rusi  wrote:
> I am trying to understand your points Chris. On the one hand you say:
>
> On Apr 14, 6:22 pm, Chris Angelico  wrote:
>> No, no, a thousand times no! If I am doing financial transactions,
>> even if I'm alone on my machine, I will demand full ACID compliance.
>
> On the other you describe a bookmark storage scheme (which it seems
> you are recommending); to wit
> ...
> So are you saying that if one switches from the non-ACID compliant
> sqlite to your simple-text data-format, the new 'database' (note the
> quote marks) will now become ACID compliant?

Unlikely. It theoretically could be made ACID compliant (all it needs
is an OS-guaranteed atomic move/rename operation), but my point is
that some things don't _need_ full-on databases. Financial work *does*
(if I'm accepting money from people, I'd better make pretty sure I
know who's paid me and how much); bookmarks usually don't. Also,
bookmarks are the exclusive property of the person who creates them,
so it's helpful to store them in a way that can be edited; with money
movements, you often want some kind of indelibility guarantee, too
(you can't go back and edit a previous transaction, you have to put in
a correcting transaction). Different tasks demand different storage
schemes.

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


Re: Grammar question: Englisn and Python: qualified names

2013-04-15 Thread Tim Chase
On 2013-04-15 07:50, Chris Angelico wrote:
> Quirky question time!
> ... or possibly a collections.OrderedDict...
> ... or possibly an collections.OrderedDict...

If you're smart enough to elide the "collections [dot]" from your
pronunciation, you're smart enough to adjust the a/an accordingly.
Use the first one :-)

-tkc



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


Making ETL from Access 97 to Access 2003

2013-04-15 Thread Steeve
Hi, 

I need to take data from 5 differents (but similar) database in MS Access 97 
and merge them into one MS Access 2003 database. 

Is some packages exist to do this task?

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


Re: Grammar question: Englisn and Python: qualified names

2013-04-15 Thread Chris Angelico
On Mon, Apr 15, 2013 at 10:28 PM, Tim Chase
 wrote:
> On 2013-04-15 07:50, Chris Angelico wrote:
>> Quirky question time!
>> ... or possibly a collections.OrderedDict...
>> ... or possibly an collections.OrderedDict...
>
> If you're smart enough to elide the "collections [dot]" from your
> pronunciation, you're smart enough to adjust the a/an accordingly.
> Use the first one :-)

I like that reasoning. :) Thanks, all!

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


Re: Making ETL from Access 97 to Access 2003

2013-04-15 Thread rusi
On Apr 15, 5:27 pm, Steeve  wrote:
> Hi,
>
> I need to take data from 5 differents (but similar) database in MS Access 97 
> and merge them into one MS Access 2003 database.

Not sure what this had to do with python.
However…
You could write out the five as csvs and then read in those csvs.
This is assuming that access 2003 cannot read in access 97. [Seems a
bit surprising though]

>
> Is some packages exist to do this task?

Dunno…
Have you seen http://allenbrowne.com/ser-48.html ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Ombongi Moraa Fe
Hello Team,

Thanks for your input.

|Possibly it's not matching because of your mistaken use of octal.  Octal
won't hurt for ints below 8, but you probably don't restrict it in the real
code.  For example,  v = 030 will not match equal in the following:

I've changed the key,value pairs in the dictionary because of privacy
commitment with my provider;

|My guess is that this is not your actual code at all, and you're trying to
"simplify" it for us.  You probably have more than |two items in the dict,
and one of them is NOT matching any of the if/elif tests.

Currently, I only have 2 items in the dictionary. However, this
is a test environment and in the product environ, my items will be as many
as the number of services created on server for my connection. Currently,
the production has 10 services (key,value pairs)

I will only have a set number of key,value pairs and I cannot use other
items outside this range. The connection to providerr wouldn't be establish
for anything out of the allowed item ranges;

|That's not the whole script, since at the least, you need some code to
import or create client, value1 and value2.

The other portion of script to import the client and get values of
parameters value1 and value2 works well. I have tested the script without
using dictionaries by manually changing the items within the dictionary,
inside the code and it works successfully, establishing a connection for
both items; Now I need to iterate this for the sake of numerous items in
the production environment. And that's where I thought to bring in the if
statement.

|What makes you think there should be one call given the code above?
client.service.methodcall must be called for every |loop iteration, so
there's one call with criteria 'test' and one with 'Running'.  Note there's
no guarantee that the calls will |always take place in the same order.

Yes, I do understand that the items in the dictionary are not ordered. And
what I expect is "one call with criteria 'Test' and one with 'Running'. From
my logs file, the duplicate call always occurs at the last iteration of the
dictionary items.

In short, my problem arises after I include the if statement inside the
loop. I am new to python but I am pretty sure my program syntax is correct
here. If I run  a print statement instead of the
client.service.methodcall(value1,
value2), my output is just

Test
Running

2 of the services in the production environment will require the criteria
value. For the rest of the services, the method call will simply be

client.service.methodcall(value1, value2)

I need this criteria value in order to establish a service specific
connection for these 2 matching key,value pairs; instead of a generalised
connection as will be the case for any additional keys.this is where the
else default statement will come in later on. Right now I need to be able
to resolve the problem with my script as-it-is (with 2 dictionary items)

Thanks in advance.


Saludos

Ombongi Moraa Faith
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Matthias Felleisen

On Apr 14, 2013, at 11:48 PM, Mark Janssen wrote:

>  After the 2001 "type/class unification" , it went towards Alan Kay's ideal 

Are you sure? Remember Kay's two motivations [*], which he so elegantly 
describes with "[the] large scale one was to find a better module scheme for 
complex systems involving hiding of details, and the small scale one was to 
find a more flexible version of assignment, and then to try to eliminate it 
altogether."  At least for me, this quote sends a signal to language designers 
that is still looking for a receiver -- Matthias

[*] http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html



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


Cross-compiling Python for ARM?

2013-04-15 Thread Gilles
Hello

I tried running uWSGI on an ARM-based appliance, but it fails. 

Apparently, it could be due to the official Python 2.6.6 interpreter
in the depot not being compiled the way uWSGI expects it to be:

./configure --enable-shared; make; make install;
www.raspberrypi.org/phpBB3/viewtopic.php?f=32&t=15370

I see Python mentioned in /usr/lib and /usr/share, and was wondering
if all it'd take to solve this issue, is just to cross-compile the
interpreter and the rest is just CPU-agnostic Python scripts.

Just in case, here's the output:
www.pastebin.com/wJHjBrfn

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


Re: Making ETL from Access 97 to Access 2003

2013-04-15 Thread Paul Simon

"rusi"  wrote in message 
news:ff550c58-58b0-4bf2-bf12-08986ab2b...@ka6g2000pbb.googlegroups.com...
On Apr 15, 5:27 pm, Steeve  wrote:
> Hi,
>
> I need to take data from 5 differents (but similar) database in MS Access 
> 97 and merge them into one MS Access 2003 database.

Not sure what this had to do with python.
However…
You could write out the five as csvs and then read in those csvs.
This is assuming that access 2003 cannot read in access 97. [Seems a
bit surprising though]

>
> Is some packages exist to do this task?

Dunno…
Have you seen http://allenbrowne.com/ser-48.html ?

If  there are indices and especially linked primary and foreign keys its 
much more complicated than that.  One has to delve into Access container 
structures etc.  As far as I know it has to be done from Access.

Paul Simon 


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


Re: Making ETL from Access 97 to Access 2003

2013-04-15 Thread rusi
Its hard to distinguish what you are saying from what I said because
you've lost the quotes.

On Apr 15, 9:01 pm, "Paul Simon"  wrote:
> "rusi"  wrote in message
>
> news:ff550c58-58b0-4bf2-bf12-08986ab2b...@ka6g2000pbb.googlegroups.com...
> On Apr 15, 5:27 pm, Steeve  wrote:
>
> > Hi,
>
> > I need to take data from 5 differents (but similar) database in MS Access
> > 97 and merge them into one MS Access 2003 database.
>
> Not sure what this had to do with python.
> However…
> You could write out the five as csvs and then read in those csvs.
> This is assuming that access 2003 cannot read in access 97. [Seems a
> bit surprising though]
>
>
>
> > Is some packages exist to do this task?
>
> Dunno…
> Have you seenhttp://allenbrowne.com/ser-48.html?
>
> If  there are indices and especially linked primary and foreign keys its
> much more complicated than that.  One has to delve into Access container
> structures etc.  As far as I know it has to be done from Access.


I assume you are saying this for my csv suggestion?
Yes of course. I gave this as the last resort if direct import and
other such attempts dont work out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threadpool item mailboxes design problem

2013-04-15 Thread Charles Hixson

On 04/14/2013 07:32 PM, Chris Rebert wrote:


On Apr 14, 2013 4:27 PM, "Charles Hixson" > wrote:

>
> What is the best approach to implementing actors that accept and 
post messages (and have no other external contacts).


You might look at how some of the existing Python actor libraries are 
implemented (perhaps one of these might even save you from reinventing 
the wheel):


http://www.pykka.org/en/latest/
http://www.kamaelia.org/Docs/Axon/Axon.html
https://pypi.python.org/pypi/pulsar

Kinda old:
http://candygram.sourceforge.net/contents.html
http://osl.cs.uiuc.edu/parley/

Candygram looks interesting.  I'd forgotten about it.  The others look 
either a bit limited (in different ways), or overly general, with the 
costs that that brings.  I'll need to study Candygram a bit more.  
However, even Candygram seems to have a RAM centric model that I'd need 
to work around.  (Well, the mailbox synchronization must clearly be RAM 
centric, but the storage shouldn't be.)


> So far what I've come up with is something like:
> actors = {}
> mailboxs = {}
>
> Stuff actors with actor instances, mailboxes with 
multiprocessing.queue instances.   (Actors and mailboxes will have 
identical keys, which are id#, but it's got to be a dict rather than a 
list, because too many are rolled out to disk.)  And I'm planning of 
having the actors running simultaneously and continually in a 
threadpool that just loops through the actors that are assigned to 
each thread of the pool.


> It would, however, be better if the mailbox could be specific to the 
threadpool instance, so less space would be wasted.  Or if the queues 
could dynamically resize.  Or if there was a threadsafe dict.  Or... 
 But I don't know that any of these are feasible.  (I mean, yes, I 
could write all the mail to a database, but is that a better answer, 
or even a good one?)


My recollection is that the built-in collection types are threadsafe 
at least to the limited extent that the operations exposed by their 
APIs (e.g. dict.setdefault) are atomic.

Perhaps someone will be able to chime in with more details.

If list operations were threadsafe, why would multiprocessing.queue have 
been created?  I don't recall any claim that they were.  Still, I've 
found an assertion on StackOverflow that they are...at least for simple 
assignment and reading.  And the same would appear to be true of dicts 
from that post.  This *does* require that either the index be constant, 
and the stored value be constant, or that the code section be locked 
during the access.  Fortunately I'm intending to have id#s be 
unchangable, and the messages to be tuples, and thus constant.


OTOH, to use this approach I'll need to find some way to guarantee that 
removing messages and posting messages don't occur at the same time.  So 
that still means I'll need to lock each access.  The answer that seems 
best is for each thread to have a mailbox that cells within the thread 
post and read messages from.  This will automatically deal with internal 
to thread synchronization.  Then I'll need a mailman thread that...


This seems a promising approach, that avoids the problem of fixed length 
queues, but I'll still need to do a lot of synchronization.  Still, it's 
a lot less, and each thread would be locked for shorter amounts of time.


--
Charles Hixson

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


Re: Iterating dictionary items + if statement results in problems

2013-04-15 Thread Dave Angel

On 04/15/2013 09:37 AM, Ombongi Moraa Fe wrote:

Hello Team,

Thanks for your input.

|Possibly it's not matching because of your mistaken use of octal.  Octal
won't hurt for ints below 8, but you probably don't restrict it in the real
code.  For example,  v = 030 will not match equal in the following:

I've changed the key,value pairs in the dictionary because of privacy
commitment with my provider;

|My guess is that this is not your actual code at all, and you're trying to
"simplify" it for us.  You probably have more than |two items in the dict,
and one of them is NOT matching any of the if/elif tests.

 Currently, I only have 2 items in the dictionary. However, this
is a test environment and in the product environ, my items will be as many
as the number of services created on server for my connection. Currently,
the production has 10 services (key,value pairs)

I will only have a set number of key,value pairs and I cannot use other
items outside this range. The connection to providerr wouldn't be establish
for anything out of the allowed item ranges;

|That's not the whole script, since at the least, you need some code to
import or create client, value1 and value2.

The other portion of script to import the client and get values of
parameters value1 and value2 works well. I have tested the script without
using dictionaries by manually changing the items within the dictionary,
inside the code and it works successfully, establishing a connection for
both items; Now I need to iterate this for the sake of numerous items in
the production environment. And that's where I thought to bring in the if
statement.

|What makes you think there should be one call given the code above?
client.service.methodcall must be called for every |loop iteration, so
there's one call with criteria 'test' and one with 'Running'.  Note there's
no guarantee that the calls will |always take place in the same order.

Yes, I do understand that the items in the dictionary are not ordered. And
what I expect is "one call with criteria 'Test' and one with 'Running'. From
my logs file, the duplicate call always occurs at the last iteration of the
dictionary items.


Do you mean there are 3 calls to that method, with only two items in the 
dictionary??  More likely, there's some logic inside the method that's 
faking an extra log entry.




In short, my problem arises after I include the if statement inside the
loop. I am new to python but I am pretty sure my program syntax is correct
here. If I run  a print statement instead of the
client.service.methodcall(value1,
value2), my output is just

Test
Running

2 of the services in the production environment will require the criteria
value. For the rest of the services, the method call will simply be

client.service.methodcall(value1, value2)

I need this criteria value in order to establish a service specific
connection for these 2 matching key,value pairs; instead of a generalised
connection as will be the case for any additional keys.this is where the
else default statement will come in later on. Right now I need to be able
to resolve the problem with my script as-it-is (with 2 dictionary items)



As far as I can see, there's no problem with the script, as far as it 
goes.  If you replace the method call with a print statement, and it 
suddenly starts working, then by definition, there's something wrong 
with the method.  We cannot help there.


Many times, we can play detective, and guess what's going on without 
running a program.  Since we've told you what we each have found, and 
you haven't posted any new version of the code, that's about all we can 
do.  Perhaps someone else who hasn't chimed in can help.  But if I were 
you, I'd post a self-contained program that demonstrates the problem.


Or maybe it's because you're posting in html, rather than the expected 
text, and you have some indent problem that doesn't show up after 
converting round trip.  Please tell your email program to use text 
message format when posting here.





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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Antoon Pardon

Op 15-04-13 12:11, Steven D'Aprano schreef:



Python's data model has always been 100% object oriented. Prior to the
"class/type" unification, it simply had *two distinct* implementations of
objects: types, which were written in C, and classes, which were written
in Python.

After unification, the two kinds of object were no longer entirely
distinct -- you could then subclass types in Python code, using the same
"class" keyword as you would use for a pure-Python class.

And starting with Python 3, the last vestiges of the distinction have
disappeared. Now, "class" and "type" are mere synonyms. Both built-in
types and custom classes use the same mechanism.


I had gotten my hopes up after reading this but then I tried:


$ python3
Python 3.2.3 (default, Feb 20 2013, 17:02:41)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class vslice (slice):
...   pass
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: type 'slice' is not an acceptable base type


It seems types and classes are still not mere synonyms.
--
http://mail.python.org/mailman/listinfo/python-list


Process tuple contents on the fly

2013-04-15 Thread Gnarlodious
Say I have a tuple I want to expand assigning to variables:

tup = *func()
var = tup[0]
lst.append(tup[1])

Or could I do it in one line?

var, lst.append() = *func()

So I want to append one variable to a list on the fly, is it possible?

-- Gnarlie
http://gnarlodious.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode issue with Python v3.3

2013-04-15 Thread Νίκος Γκρ33κ
Hello, can you still help me please?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Process tuple contents on the fly

2013-04-15 Thread Tim Chase
On 2013-04-15 11:25, Gnarlodious wrote:
> Say I have a tuple I want to expand assigning to variables:
> 
> tup = *func()
> var = tup[0]
> lst.append(tup[1])
> 
> Or could I do it in one line?
> 
> var, lst.append() = *func()
> 
> So I want to append one variable to a list on the fly, is it
> possible?

I stumbled across this atrocity[*], which if you chose to use it,
you'd deserve a kick in the pants:

  lst.append("Value I don't care about and will overwrite")
  var, lst[-1] = *func()

It's not quite one step, but at least the *assignment* is one step :-)

-tkc


[*] my original discovery was

  d = {}
  for key, d[key] in (("this",18), ("that",17), ("other",38)):
print key
do_something(d)

but the same applies to a plain ol' assignment statement as to an
assignment in a "for" loop.





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


Re: Process tuple contents on the fly

2013-04-15 Thread Barrett Lewis
>   d = {}
>   for key, d[key] in (("this",18), ("that",17), ("other",38)):
> print key
> do_something(d)
>

Why not use a dict comprehension?
d = {k:v for k,v in  (("this",18), ("that",17), ("other",38))}

I feel this is more straightforward and easier to read. the results are the
same however.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Process tuple contents on the fly

2013-04-15 Thread Peter Otten
Tim Chase wrote:

> On 2013-04-15 11:25, Gnarlodious wrote:
>> Say I have a tuple I want to expand assigning to variables:
>> 
>> tup = *func()
>> var = tup[0]
>> lst.append(tup[1])
>> 
>> Or could I do it in one line?
>> 
>> var, lst.append() = *func()
>> 
>> So I want to append one variable to a list on the fly, is it
>> possible?
> 
> I stumbled across this atrocity[*], which if you chose to use it,
> you'd deserve a kick in the pants:
> 
>   lst.append("Value I don't care about and will overwrite")
>   var, lst[-1] = *func()
> 
> It's not quite one step, but at least the *assignment* is one step :-)

I think the star is on the wrong side. 


So:

>>> items = ["a", "b", "c"]
>>> def f(result=(4, 5, 6)): return result
... 
>>> var, *items[len(items):] = f()
>>> var
4
>>> items
['a', 'b', 'c', 5, 6]


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


Re: Process tuple contents on the fly

2013-04-15 Thread Tim Chase
On 2013-04-15 12:05, Barrett Lewis wrote:
> >   d = {}
> >   for key, d[key] in (("this",18), ("that",17), ("other",38)):
> > print key
> > do_something(d)
> 
> Why not use a dict comprehension?
> d = {k:v for k,v in  (("this",18), ("that",17), ("other",38))}
> 
> I feel this is more straightforward and easier to read. the results
> are the same however.

In the particular case I did it in, I needed the incremental results
passed to a function, not just the final result.  I don't think this
made it into the final code, rather it was expanded to be more
readable.  But the discovery made me feel a disturbance in the
Pythonic force of the universe. :*)

-tkc


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


Re: Making ETL from Access 97 to Access 2003

2013-04-15 Thread Paul Simon

"rusi"  wrote in message 
news:92551c63-1347-4f1a-9dca-d1bbd5e4d...@ys5g2000pbc.googlegroups.com...
Its hard to distinguish what you are saying from what I said because
you've lost the quotes.

On Apr 15, 9:01 pm, "Paul Simon"  wrote:
> "rusi"  wrote in message
>
> news:ff550c58-58b0-4bf2-bf12-08986ab2b...@ka6g2000pbb.googlegroups.com...
> On Apr 15, 5:27 pm, Steeve  wrote:
>
> > Hi,
>
> > I need to take data from 5 differents (but similar) database in MS 
> > Access
> > 97 and merge them into one MS Access 2003 database.
>
> Not sure what this had to do with python.
> However…
> You could write out the five as csvs and then read in those csvs.
> This is assuming that access 2003 cannot read in access 97. [Seems a
> bit surprising though]
>
>
>
> > Is some packages exist to do this task?
>
> Dunno…
> Have you seenhttp://allenbrowne.com/ser-48.html?
>
> If there are indices and especially linked primary and foreign keys its
> much more complicated than that. One has to delve into Access container
> structures etc. As far as I know it has to be done from Access.


I assume you are saying this for my csv suggestion?
Yes of course. I gave this as the last resort if direct import and
other such attempts dont work out.

>>>Could you please append your comments instead of splitting them?
>>>Let me try to be clearer.  If one only wants to merge tables, csv will 
>>>work fine, exporting them from Access.
>>>Reconstucting keys and relationships can be done with some difficulty 
>>>using Access' container model.  See the Developer's Handbook by Getz, 
>>>Litwin and Gilbert.

>>>Paul Simon 


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


Re: Process tuple contents on the fly

2013-04-15 Thread Barrett Lewis
> In the particular case I did it in, I needed the incremental results
> passed to a function, not just the final result.  I don't think this
> made it into the final code, rather it was expanded to be more
> readable.  But the discovery made me feel a disturbance in the
> Pythonic force of the universe. :*)
>
> -tkc
>

I see what you are saying, but I agree that is a disturbance I didn't even
know you could do
for key, d[key], that just feels like bad news. however for what you are
saying it makes sense. TIL that you can use an unpacked value during
unpacking!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Process tuple contents on the fly

2013-04-15 Thread MRAB

On 15/04/2013 20:05, Barrett Lewis wrote:




   d = {}
   for key, d[key] in (("this",18), ("that",17), ("other",38)):
 print key
 do_something(d)


Why not use a dict comprehension?
d = {k:v for k,v in  (("this",18), ("that",17), ("other",38))}

I feel this is more straightforward and easier to read. the results are
the same however.


Why use a dict comprehension? :-)

d = dict((("this",18), ("that",17), ("other",38))}

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


Re: Process tuple contents on the fly

2013-04-15 Thread Tobiah

On 04/15/2013 11:25 AM, Gnarlodious wrote:

Say I have a tuple I want to expand assigning to variables:

tup = *func()


What is the asterisk for?  I assume it's a python 3
thing, because I get a syntax error, but I'm having
trouble Googling it.

Thanks,

Tobiah

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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Dave Angel

On 04/15/2013 01:43 PM, Antoon Pardon wrote:

Op 15-04-13 12:11, Steven D'Aprano schreef:



Python's data model has always been 100% object oriented. Prior to the
"class/type" unification, it simply had *two distinct* implementations of
objects: types, which were written in C, and classes, which were written
in Python.

After unification, the two kinds of object were no longer entirely
distinct -- you could then subclass types in Python code, using the same
"class" keyword as you would use for a pure-Python class.

And starting with Python 3, the last vestiges of the distinction have
disappeared. Now, "class" and "type" are mere synonyms. Both built-in
types and custom classes use the same mechanism.


I had gotten my hopes up after reading this but then I tried:


$ python3
Python 3.2.3 (default, Feb 20 2013, 17:02:41)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> class vslice (slice):
...   pass
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: type 'slice' is not an acceptable base type


It seems types and classes are still not mere synonyms.


No, it seems you're trying to use an internal detail as though it were a 
supported feature.


From page:
http://docs.python.org/3.3/reference/datamodel.html#types

"""Internal types
A few types used internally by the interpreter are exposed to the user. 
Their definitions may change with future versions of the interpreter, 
but they are mentioned here for completeness.

"""


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


Re: Process tuple contents on the fly

2013-04-15 Thread Michael Torrie
On 04/15/2013 02:35 PM, Tobiah wrote:
> On 04/15/2013 11:25 AM, Gnarlodious wrote:
>> Say I have a tuple I want to expand assigning to variables:
>>
>> tup = *func()
> 
> What is the asterisk for?  I assume it's a python 3
> thing, because I get a syntax error, but I'm having
> trouble Googling it.

No it's not.  It's a tuple unpack operator.  It's commonly used in this
context:

def func1(*args, **kwargs): #func1 can take variable args
   # do stuff
   func2( *args ) #unpack the variable args and pass them to func2
   func3( *args )
   func4( *args, **kwargs)

def func2( a, b, c):
   d = a + b + c

def func3 ( *args ):
   pass

def func4 ( *args, **kwargs):
   pass

func1(1,2,3)

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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Rotwang

On 15/04/2013 22:13, Dave Angel wrote:

On 04/15/2013 01:43 PM, Antoon Pardon wrote:

[...]

I had gotten my hopes up after reading this but then I tried:


$ python3
Python 3.2.3 (default, Feb 20 2013, 17:02:41)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> class vslice (slice):
...   pass
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: type 'slice' is not an acceptable base type


It seems types and classes are still not mere synonyms.


No, it seems you're trying to use an internal detail as though it were a
supported feature.

 From page:
 http://docs.python.org/3.3/reference/datamodel.html#types

"""Internal types
A few types used internally by the interpreter are exposed to the user.
Their definitions may change with future versions of the interpreter,
but they are mentioned here for completeness.
"""


To be fair, one can't do this either:

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 
bit (AMD64)] on win32

Type "copyright", "credits" or "license()" for more information.
>>> class C(type(lambda: None)):
pass

Traceback (most recent call last):
  File "", line 1, in 
class C(type(lambda: None)):
TypeError: type 'function' is not an acceptable base type


and I don't think that FunctionType would be considered an "internal 
detail", would it? Not that I'd cite the fact that not all types can be 
inherited from as evidence that types and classes are not synonyms, mind.

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


Re: howto remove the thousand separator

2013-04-15 Thread Rotwang

On 15/04/2013 08:03, Steven D'Aprano wrote:

On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote:

[...]

(Sorry for linking to Google Groups. Does anyone know of a better c.l.p.
web archive?)


The canonical (although possibly not the best) archive for c.l.p. is the
python-list mailing list archive:

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


Thanks to both you and Ned.
--
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Chris Angelico
On Tue, Apr 16, 2013 at 8:12 AM, Rotwang  wrote:
> Traceback (most recent call last):
>   File "", line 1, in 
> class C(type(lambda: None)):
> TypeError: type 'function' is not an acceptable base type
>
>
> and I don't think that FunctionType would be considered an "internal
> detail", would it? Not that I'd cite the fact that not all types can be
> inherited from as evidence that types and classes are not synonyms, mind.

Actually, I'm not sure how you'd go about inheriting from a function.
Why not just create a bare class, then assign its __call__ to be the
function you're inheriting from?

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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Rotwang

On 15/04/2013 23:32, Chris Angelico wrote:

On Tue, Apr 16, 2013 at 8:12 AM, Rotwang  wrote:

Traceback (most recent call last):
   File "", line 1, in 
 class C(type(lambda: None)):
TypeError: type 'function' is not an acceptable base type


and I don't think that FunctionType would be considered an "internal
detail", would it? Not that I'd cite the fact that not all types can be
inherited from as evidence that types and classes are not synonyms, mind.


Actually, I'm not sure how you'd go about inheriting from a function.
Why not just create a bare class, then assign its __call__ to be the
function you're inheriting from?


No idea. I wasn't suggesting that trying to inherit from FunctionType 
was a sensible thing to do; I was merely pointing out that slice's 
status as an internal feature was not IMO relevant to the point that 
Antoon was making.

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


Re: Process tuple contents on the fly

2013-04-15 Thread Gnarlodious
On Monday, April 15, 2013 2:35:10 PM UTC-6, Tobiah wrote:

> > tup = *func()

> What is the asterisk for?  I assume it's a python 3
Not Python 3, pseudocode. I should have said as such, sorry. Supposed to 
indicate an expanded tuple.

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


Re: Cross-compiling Python for ARM?

2013-04-15 Thread Terry Jan Reedy

On 4/15/2013 11:20 AM, Gilles wrote:

Hello

I tried running uWSGI on an ARM-based appliance, but it fails.

Apparently, it could be due to the official Python 2.6.6 interpreter
in the depot not being compiled the way uWSGI expects it to be:

./configure --enable-shared; make; make install;
www.raspberrypi.org/phpBB3/viewtopic.php?f=32&t=15370

I see Python mentioned in /usr/lib and /usr/share, and was wondering
if all it'd take to solve this issue, is just to cross-compile the
interpreter and the rest is just CPU-agnostic Python scripts.

Just in case, here's the output:
www.pastebin.com/wJHjBrfn


I believe some cross-compile support was added to 2.7.4 but I do not 
know the exact nature.



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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Terry Jan Reedy

On 4/15/2013 1:43 PM, Antoon Pardon wrote:


$ python3
Python 3.2.3 (default, Feb 20 2013, 17:02:41)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> class vslice (slice):
...   pass
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: type 'slice' is not an acceptable base type


It seems types and classes are still not mere synonyms.


Some builtin classes cannot be subclassed. There is an issue to document 
which better. That does not mean that it is not a class.



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


Re: Threadpool item mailboxes design problem

2013-04-15 Thread Charles Hixson

On 04/15/2013 10:14 AM, Charles Hixson wrote:

On 04/14/2013 07:32 PM, Chris Rebert wrote:


On Apr 14, 2013 4:27 PM, "Charles Hixson" > wrote:

>
> What is the best approach to implementing actors that accept and 
post messages (and have no other external contacts).


You might look at how some of the existing Python actor libraries are 
implemented (perhaps one of these might even save you from 
reinventing the wheel):


http://www.pykka.org/en/latest/
http://www.kamaelia.org/Docs/Axon/Axon.html
https://pypi.python.org/pypi/pulsar

Kinda old:
http://candygram.sourceforge.net/contents.html
http://osl.cs.uiuc.edu/parley/

Candygram looks interesting.  I'd forgotten about it.  The others look 
either a bit limited (in different ways), or overly general, with the 
costs that that brings.  I'll need to study Candygram a bit more.  
However, even Candygram seems to have a RAM centric model that I'd 
need to work around.  (Well, the mailbox synchronization must clearly 
be RAM centric, but the storage shouldn't be.)


> So far what I've come up with is something like:
> actors = {}
> mailboxs = {}
>
> Stuff actors with actor instances, mailboxes with 
multiprocessing.queue instances.   (Actors and mailboxes will have 
identical keys, which are id#, but it's got to be a dict rather than 
a list, because too many are rolled out to disk.)  And I'm planning 
of having the actors running simultaneously and continually in a 
threadpool that just loops through the actors that are assigned to 
each thread of the pool.


> It would, however, be better if the mailbox could be specific to 
the threadpool instance, so less space would be wasted.  Or if the 
queues could dynamically resize.  Or if there was a threadsafe dict. 
 Or...  But I don't know that any of these are feasible.  (I mean, 
yes, I could write all the mail to a database, but is that a better 
answer, or even a good one?)


My recollection is that the built-in collection types are threadsafe 
at least to the limited extent that the operations exposed by their 
APIs (e.g. dict.setdefault) are atomic.

Perhaps someone will be able to chime in with more details.

If list operations were threadsafe, why would multiprocessing.queue 
have been created?  I don't recall any claim that they were.  Still, 
I've found an assertion on StackOverflow that they are...at least for 
simple assignment and reading.  And the same would appear to be true 
of dicts from that post.  This *does* require that either the index be 
constant, and the stored value be constant, or that the code section 
be locked during the access.  Fortunately I'm intending to have id#s 
be unchangable, and the messages to be tuples, and thus constant.


OTOH, to use this approach I'll need to find some way to guarantee 
that removing messages and posting messages don't occur at the same 
time.  So that still means I'll need to lock each access.  The answer 
that seems best is for each thread to have a mailbox that cells within 
the thread post and read messages from.  This will automatically deal 
with internal to thread synchronization.  Then I'll need a mailman 
thread that...


This seems a promising approach, that avoids the problem of fixed 
length queues, but I'll still need to do a lot of synchronization.  
Still, it's a lot less, and each thread would be locked for shorter 
amounts of time.

--
Charles Hixson

Currently it looks as if Pyro is the best option.  It appears that 
Python threads are very contentious, so I'll need to run in processes 
rather than in threads, but I'll still need to transfer messages back 
and forth.  I'll probably use UnixSockets rather than IP, but this could 
change...and using Pyro would make changing it easy.  Still, pickle is 
used in code transmission, and that makes IP a questionable choice.


--
Charles Hixson

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


Python with Apache

2013-04-15 Thread Renato Barbosa Pim Pereira
I am trying to execute cgi101.py:

#!/usr/bin/python

import cgi

form = cgi.FieldStorage() # parse form data
print('Content-type: text/html\n')# hdr plus blank line
print('Reply Page')# html reply page
if not 'user' in form:
print('Who are you?')
else:
print('Hello %s!' % cgi.escape(form['user'].value))

I have installed mod_python do apache2 and created one entry in
/etc/apache2/sites-available/default:

DocumentRoot /var/www

AddHandler mod_python .py
PythonHandler cgi101
PythonDebug On


What. happen is: when i call this file on browser I have the following
error:
Can someone help?

MOD_PYTHON ERROR

ProcessId:  2742
Interpreter:'127.0.1.1'

ServerName: '127.0.1.1'
DocumentRoot:   '/var/www'

URI:'/py/cgi101.py'
Location:   None
Directory:  '/var/www/py/'
Filename:   '/var/www/py/cgi101.py'
PathInfo:   ''

Phase:  'PythonHandler'
Handler:'cgi101'

Traceback (most recent call last):

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line
1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line
1206, in _process_target
object = apache.resolve_object(module, object_str, arg, silent=silent)

  File "/usr/lib/python2.7/dist-packages/mod_python/apache.py", line
696, in resolve_object
raise AttributeError, s

AttributeError: module '/var/www/py/cgi101.py' contains no 'handler'


MODULE CACHE DETAILS

Accessed:   Mon Apr 15 22:02:42 2013
Generation: 0

_mp_63ea7b6576c7d3a5f48ef8741e8048b0 {
  FileName: '/var/www/py/cgi101.py'
  Instance: 1 [IMPORT]
  Generation:   1
  Modified: Mon Apr 15 21:52:27 2013
  Imported: Mon Apr 15 22:02:42 2013
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python with Apache

2013-04-15 Thread MRAB

On 16/04/2013 03:02, Renato Barbosa Pim Pereira wrote:

I am trying to execute cgi101.py:

#!/usr/bin/python

import cgi

form = cgi.FieldStorage() # parse form data
print('Content-type: text/html\n')# hdr plus blank line
print('Reply Page')# html reply page
if not 'user' in form:
 print('Who are you?')
else:
 print('Hello %s!' % cgi.escape(form['user'].value))

I have installed mod_python do apache2 and created one entry in
/etc/apache2/sites-available/default:

 DocumentRoot /var/www
 
 AddHandler mod_python .py
 PythonHandler cgi101
 PythonDebug On
 

What. happen is: when i call this file on browser I have the following
error:
Can someone help?

MOD_PYTHON ERROR

ProcessId:  2742
Interpreter:'127.0.1.1'

ServerName: '127.0.1.1'
DocumentRoot:   '/var/www'

URI:'/py/cgi101.py'
Location:   None
Directory:  '/var/www/py/'
Filename:   '/var/www/py/cgi101.py'
PathInfo:   ''

Phase:  'PythonHandler'
Handler:'cgi101'

Traceback (most recent call last):

   File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, 
in HandlerDispatch
 default=default_handler, arg=req, silent=hlist.silent)

   File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1206, 
in _process_target
 object = apache.resolve_object(module, object_str, arg, silent=silent)

   File "/usr/lib/python2.7/dist-packages/mod_python/apache.py", line 696, in 
resolve_object
 raise AttributeError, s

AttributeError: module '/var/www/py/cgi101.py' contains no 'handler'


MODULE CACHE DETAILS

Accessed:   Mon Apr 15 22:02:42 2013
Generation: 0

_mp_63ea7b6576c7d3a5f48ef8741e8048b0 {
   FileName: '/var/www/py/cgi101.py'
   Instance: 1 [IMPORT]
   Generation:   1
   Modified: Mon Apr 15 21:52:27 2013
   Imported: Mon Apr 15 22:02:42 2013
}

I think it's looking for a function called 'handler' in the module 
'cgi101.py'.


This might help you:

http://www.modpython.org/live/mod_python-2.7.8/doc-html/tut-overview.html

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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Steven D'Aprano
On Mon, 15 Apr 2013 20:52:58 -0400, Terry Jan Reedy wrote:

> On 4/15/2013 1:43 PM, Antoon Pardon wrote:
> 
>> $ python3
>> Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> class vslice (slice):
>> ...   pass
>> ...
>> Traceback (most recent call last):
>>File "", line 1, in 
>> TypeError: type 'slice' is not an acceptable base type
>>
>>
>> It seems types and classes are still not mere synonyms.
> 
> Some builtin classes cannot be subclassed. There is an issue to document
> which better. That does not mean that it is not a class.


I think it is also important to document whether that is a language 
feature, or a mere restriction of the implementation. There is an 
important distinction to be made between:

"In CPython, you cannot subclass slice or FunctionType. Other Pythons may 
have more, or fewer, restrictions."

and:

"No language that calls itself Python is permitted to allow slice and 
FunctionType to be subclassable."


If I had a say in this, I would vote for the first case, with the 
possible exception of documented singleton types like NoneType and bool.



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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Steven D'Aprano
On Mon, 15 Apr 2013 19:43:32 +0200, Antoon Pardon wrote:

> Op 15-04-13 12:11, Steven D'Aprano schreef:
> 
> 
>> Python's data model has always been 100% object oriented. Prior to the
>> "class/type" unification, it simply had *two distinct* implementations
>> of objects: types, which were written in C, and classes, which were
>> written in Python.
>>
>> After unification, the two kinds of object were no longer entirely
>> distinct -- you could then subclass types in Python code, using the
>> same "class" keyword as you would use for a pure-Python class.
>>
>> And starting with Python 3, the last vestiges of the distinction have
>> disappeared. Now, "class" and "type" are mere synonyms. Both built-in
>> types and custom classes use the same mechanism.
> 
> I had gotten my hopes up after reading this but then I tried:
> 
> 
> $ python3
> Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> class vslice (slice):
> ...   pass
> ...
> Traceback (most recent call last):
>File "", line 1, in 
> TypeError: type 'slice' is not an acceptable base type
> 
> 
> It seems types and classes are still not mere synonyms.


You are misinterpreting what you are reading. The mere fact that 
something cannot be subclassed doesn't mean anything. That's just a 
restriction put on the class by the implementation. It's not even clear 
that it is a guaranteed language restriction or a mere accident of 
implementation. With a bit of metaclass trickery, I could equally create 
a pure-Python class that cannot be easily subclassed.

The proof that types and classes are the same in Python 3 is simple:

py> class C:
... pass
...
py> type(C) is type(int) is type(type) is type
True

The type of the pure-Python class is type itself.

However, even this can be bypassed, using a metaclass!

py> class D(metaclass=Meta):
... pass
...
py> type(D) is type
False
py> issubclass(type(D), type)
True


So when using a metaclass, the type of the class is not necessarily type 
itself, but it will be a subclass of type.

This does not hold in Python 2.x, not for old-style "classic" classes. 
Classic classes are in a world of their own, distinct from types:

# Python 2
py> class C:
... pass
...
py> type(C)

py> issubclass(type(C), type)
False



In Python 3, we can expect these two conditions to always hold:

* all instances are instances of object;

* all classes are instances of type.


Notice that this implies that type and object are circularly defined: 
object, being a class, is an instance of type, but type, being an object, 
is an instance of object:

py> isinstance(type, object)
True
py> isinstance(object, type)
True



These two conditions even apply to unsubclassable objects like slice:

py> isinstance(slice(1, 5, 2), object)
True
py> isinstance(slice, type)
True



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


Re: Grammar question: Englisn and Python: qualified names

2013-04-15 Thread Cameron Simpson
On 15Apr2013 07:50, Chris Angelico  wrote:
| Quirky question time!
| 
| When you read out a qualified name, eg collections.OrderedDict, do you
| read the qualifier ("collections dot ordered dict"), or do you elide
| it ("ordered dict")? I ask because it makes a difference to talking
| about just one of them:
| 
| ... or possibly a collections.OrderedDict...
| ... or possibly an collections.OrderedDict...
| 
| Written, the latter looks completely wrong; but if the name is read in
| its short form, with the "collections" part being implicit, then "an"
| is clearly correct! What do you think, experts and others?

I do the former.
-- 
Cameron Simpson 

Nothing is so smiple that it can't get screwed up.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Terry Jan Reedy

On 4/15/2013 10:32 PM, Steven D'Aprano wrote:

On Mon, 15 Apr 2013 20:52:58 -0400, Terry Jan Reedy wrote:



Some builtin classes cannot be subclassed. There is an issue to document
which better. That does not mean that it is not a class.



I think it is also important to document whether that is a language
feature, or a mere restriction of the implementation. There is an
important distinction to be made between:

"In CPython, you cannot subclass slice or FunctionType. Other Pythons may
have more, or fewer, restrictions."

and:

"No language that calls itself Python is permitted to allow slice and
FunctionType to be subclassable."


If I had a say in this, I would vote for the first case, with the
possible exception of documented singleton types like NoneType and bool.


I will keep the above in mind if I write or review a patch. here are 4 
non-subclassable builtin classes. Two are already documented. Bool in 
one, forget which other. I believe it was recently decided to leave the 
other two as is given the absence of any practical use case.



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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Ian Kelly
On Mon, Apr 15, 2013 at 9:17 PM, Terry Jan Reedy  wrote:
> I will keep the above in mind if I write or review a patch. here are 4
> non-subclassable builtin classes. Two are already documented. Bool in one,
> forget which other. I believe it was recently decided to leave the other two
> as is given the absence of any practical use case.

The four are bool, NoneType, slice and ellipsis, I believe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread rusi
On Apr 16, 7:32 am, Steven D'Aprano  wrote:
>
> If I had a say in this, I would vote for the first case, with the
> possible exception of documented singleton types like NoneType and bool.

How is bool a singleton type?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-15 Thread Steven D'Aprano
On Mon, 15 Apr 2013 21:56:12 -0700, rusi wrote:

> On Apr 16, 7:32 am, Steven D'Aprano  +comp.lang.pyt...@pearwood.info> wrote:
>>
>> If I had a say in this, I would vote for the first case, with the
>> possible exception of documented singleton types like NoneType and
>> bool.
> 
> How is bool a singleton type?


A doubleton, then.


The point being, GvR declared that bool should guarantee the invariant 
that True and False are the only instances of bool, and if you can 
subclass it, either that invariant is violated, or you can't instantiate 
the subclass.



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