Re: Can global variable be passed into Python function?

2014-02-22 Thread wxjmfauth
>>> # a swapping variant
>>> def swap(a, b):
... ab = [a, b]
... ab[1], ab[0] = ab[0], ab[1]
... return ab[0], ab[1]
... 
>>> a = 111
>>> id(a)
505627864
>>> b = 999
>>> id(b)
58278640
>>> a, b = swap(a, b)
>>> a, id(a)
(999, 58278640)
>>> b, id(b)
(111, 505627864)

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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sat, Feb 22, 2014 at 7:02 PM,   wrote:
 # a swapping variant
 def swap(a, b):
> ... ab = [a, b]
> ... ab[1], ab[0] = ab[0], ab[1]
> ... return ab[0], ab[1]

Provably identical to:

def swap(a, b):
return b, a

The rest is just fluff.

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


Re: Can global variable be passed into Python function?

2014-02-22 Thread wxjmfauth
Le samedi 22 février 2014 09:10:02 UTC+1, Chris Angelico a écrit :
> On Sat, Feb 22, 2014 at 7:02 PM,   wrote:
> 
>  # a swapping variant
> 
>  def swap(a, b):
> 
> > ... ab = [a, b]
> 
> > ... ab[1], ab[0] = ab[0], ab[1]
> 
> > ... return ab[0], ab[1]
> 
> 
> 
> Provably identical to:
> 
> 
> 
> def swap(a, b):
> 
> return b, a
> 
> 
> 
> The rest is just fluff.
> 
> 
> 
> ChrisA

Right. My bad, (just wake up).

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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 19:10:02 +1100, Chris Angelico wrote:

> On Sat, Feb 22, 2014 at 7:02 PM,   wrote:
> # a swapping variant
> def swap(a, b):
>> ... ab = [a, b]
>> ... ab[1], ab[0] = ab[0], ab[1]
>> ... return ab[0], ab[1]
> 
> Provably identical to:
> 
> def swap(a, b):
> return b, a
> 
> The rest is just fluff.

You don't even need the function call.

a, b = b, a


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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 18:29:02 +1100, Chris Angelico wrote:

> On Sat, Feb 22, 2014 at 6:18 PM, Steven D'Aprano
>  wrote:
>> Now I daresay that under the hood, Pascal is passing the address of foo
>> (or bar) to the procedure plus, but inside plus you don't see that
>> address as the value of b. You see the value of foo (or bar).
>>
>> C does not do that -- you have to manually manage the pointers
>> yourself, while Pascal does it for you. And Python also has nothing
>> like that.
> 
> Yep. I should have clarified that I wasn't talking about Pascal; I'm not
> fluent in the language (last time I did anything at all with Pascal was
> probably about ten years ago, and not much then). In C, it strictly does
> what I said: & takes the address of something, * dereferences an
> address. There's no way to "pass a variable" - you have to pass the
> address, and that has consequences if, for instance, you *return* an
> address and the variable ceases to exist. (Does Pascal have an
> equivalent of that?)

Yes, Pascal has pointers as a first-class data type. Syntax is similar to 
C, ^x is a pointer to x, p^ dereferences the pointer p.


> And Python has no such concept, anywhere. But anything that you can
> achieve in C using pointers, you can probably achieve in Python using
> more complex objects.

Not even that complex. Although Python doesn't do pointers, the model of 
the language is such that you don't need to. Where in C or Pascal you 
would pass a pointer to a record, in Python you just pass the record, 
safe in the knowledge that the entire record won't be copied.

There are a few idioms which don't work as neatly in Python as in Pascal, 
such as output parameter, but you don't need them. Just return a tuple. 
If you insist on an output parameter, do it like this:


def func(inarg, outarg):
if inarg % 2:
outarg[0] == "even"
else:
outarg[0] == "odd"
return inarg + 1

out = [None]
x = 42

result = func(x, out)
print(out[0])


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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sat, Feb 22, 2014 at 7:35 PM, Steven D'Aprano
 wrote:
>> Yep. I should have clarified that I wasn't talking about Pascal; I'm not
>> fluent in the language (last time I did anything at all with Pascal was
>> probably about ten years ago, and not much then). In C, it strictly does
>> what I said: & takes the address of something, * dereferences an
>> address. There's no way to "pass a variable" - you have to pass the
>> address, and that has consequences if, for instance, you *return* an
>> address and the variable ceases to exist. (Does Pascal have an
>> equivalent of that?)
>
> Yes, Pascal has pointers as a first-class data type. Syntax is similar to
> C, ^x is a pointer to x, p^ dereferences the pointer p.
>

Right, I remember those now. Yes. (See how rusty I am on it? Heh.)

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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 09:28:10 +0200, Marko Rauhamaa wrote:

> Steven D'Aprano :
> 
>> But your code doesn't succeed at doing what it sets out to do. If you
>> try to call it like this:
>>
>> py> x = 23
>> py> y = 42
>> py> swap(x, y)
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File "", line 2, in swap
>> AttributeError: 'int' object has no attribute 'get'
>>
>> not only doesn't it swap the two variables, but it raises an exception.
>> Far from being a universal swap, it's merely an obfuscated function to
>> swap a few hard-coded local variables.
> 
> You are calling the function wrong. Imagine the function in C. There,
> you'd have to do this:
[...]


Sorry, I misunderstood you. When you called it a universal swap function, 
I thought you meant a universal swap function. I didn't realise you 
intended it as a demonstration of how to emulate a C idiom using overly-
complicated Python code *wink*

If you want to emulate pointers in Python, the simplest way is to use 
lists as pseudo-pointers.

# think of ptr[0] as pointer dereferencing
# think of [value] as quasi "address of" operator
def swap(p, q):
p[0], q[0] = q[0], p[0]

x = ["anything"]
y = ["something"]
z = [23]

swap(x, y)
swap(x, z)

print(x[0], y[0], z[0])
=> prints "23 anything something"


But why bother to write C in Python? Python makes a really bad C, and C 
makes a really bad Python.



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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sat, Feb 22, 2014 at 7:45 PM, Steven D'Aprano
 wrote:
> But why bother to write C in Python? Python makes a really bad C, and C
> makes a really bad Python.

+1.

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


argparse question

2014-02-22 Thread Larry Hudson

I have been reading the argparse section of the 3.3 docs, and running all the 
example code.

But in section 16.4.2.6. for the formatter_class, the second example in that section 
illustrating RawDescriptionHelpFormatter, the example code is:


parser = argparse.ArgumentParser(
prog='PROG',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''\
Please do not mess up this text!

I have indented it
exactly the way
I want it
'''))
parser.print_help()

But trying to run this gives a NameError on the "description=" line, saying textwrap is not 
defined.  If I delete the "textwrap.dedent" (with or without also deleting the extra 
parentheses) it will then run, but without the un-indenting it is trying to illustrate.


What is the proper way to enable the dedent() method here?

All the other examples have run correctly (that is, the one's I've tried -- I'm 
still reading).
Also, it should be obvious that while the "import argparse" line is not shown in the examples, 
it IS in the code samples I've been running.


Using 3.3 under Linux (Mint 15).

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


Python stdlib code that looks odd

2014-02-22 Thread Chris Angelico
I'm poking around in the stdlib, and Lib/mailbox.py has the following
inside class Mailbox:

def update(self, arg=None):
"""Change the messages that correspond to certain keys."""
if hasattr(arg, 'iteritems'):
source = arg.items()
elif hasattr(arg, 'items'):
source = arg.items()
else:
source = arg
bad_key = False
for key, message in source:
... use key/message ...

Looks odd to check if it has iteritems and then use items. Presumably
this will catch a Python 2 dictionary, and take its items as a list
rather than an iterator; but since the only thing it does with source
is iterate over it, would it be better done as iteritems? Mainly, it
just looks really weird to check for one thing and then call on
another, especially as it then checks for the other thing in the next
line.

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


Re: What are the kinds of software that are not advisable to be developed using Python?

2014-02-22 Thread Laurent Pointal
Chris Angelico wrote:


> Heavy computation might be unideal in Python, but if you can grunge it
> into NumPy operations, that won't be a problem.

May take a look to Pythran too, which generate C++ code from (limited subset 
of) Python code, usable as a Python compiled module or as standalone C++.

https://github.com/serge-sans-paille/pythran

A+
Laurent.

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


Re: Python stdlib code that looks odd

2014-02-22 Thread Peter Otten
Chris Angelico wrote:

> I'm poking around in the stdlib, and Lib/mailbox.py has the following
> inside class Mailbox:
> 
> def update(self, arg=None):
> """Change the messages that correspond to certain keys."""
> if hasattr(arg, 'iteritems'):
> source = arg.items()
> elif hasattr(arg, 'items'):
> source = arg.items()
> else:
> source = arg
> bad_key = False
> for key, message in source:
> ... use key/message ...
> 
> Looks odd to check if it has iteritems and then use items. Presumably
> this will catch a Python 2 dictionary, and take its items as a list
> rather than an iterator; but since the only thing it does with source
> is iterate over it, would it be better done as iteritems? 

Remember that you are looking at Python 3 code here where items() is the new 
iteritems().

> Mainly, it
> just looks really weird to check for one thing and then call on
> another, especially as it then checks for the other thing in the next
> line.

Someone mechanically removed occurences of iteritems() from the code and 
ended up being either too aggressive as the Mailbox class still has an 
iteritems() method, so mb1.update(mb2) could avoid building a list, or too 
conservative as Mailbox.iterXXX could be removed, and .XXX() turned into a 
view following the example of the dict class.

If nobody has complained until now (you get an error only for objects with 
an iteritems() but without an items() method, and those should be rare to 
non-existent) I think the path to progress is to remove the first 
alternative completely.

def update(self, arg=None):
"""Change the messages that correspond to certain keys."""
if hasattr(arg, 'items'):
source = arg.items()
else:
source = arg
bad_key = False
...

Please file a bug report.

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


Re: argparse question

2014-02-22 Thread Peter Otten
Larry Hudson wrote:

> I have been reading the argparse section of the 3.3 docs, and running all
> the example code.
> 
> But in section 16.4.2.6. for the formatter_class, the second example in
> that section illustrating RawDescriptionHelpFormatter, the example code
> is:
> 
> parser = argparse.ArgumentParser(
>  prog='PROG',
>  formatter_class=argparse.RawDescriptionHelpFormatter,
>  description=textwrap.dedent('''\
>  Please do not mess up this text!
>  
>  I have indented it
>  exactly the way
>  I want it
>  '''))
> parser.print_help()
> 
> But trying to run this gives a NameError on the "description=" line,
> saying textwrap is not
> defined.  If I delete the "textwrap.dedent" (with or without also deleting
> the extra parentheses) it will then run, but without the un-indenting it
> is trying to illustrate.
> 
> What is the proper way to enable the dedent() method here?

textwrap is a module like argparse, and the example doesn't show

import argparse

either. Insert

import textwrap

at the beginning of your module and the code should run without error.



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


Re: Python stdlib code that looks odd

2014-02-22 Thread Chris Angelico
On Sat, Feb 22, 2014 at 10:54 PM, Peter Otten <__pete...@web.de> wrote:
> Please file a bug report.

http://bugs.python.org/issue20729 created.

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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Mark Lawrence

On 22/02/2014 02:47, Dennis Lee Bieber wrote:

BASIC, C, FORTRAN, COBOL, Assembly... A "variable" is synonym for an
address [a box that holds things].



In C.

int xyz = 1;

xyz is placed in a register.  What is xyz called now as it's not in memory?

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


Mark Lawrence

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


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


SMITHSONIAN DOWN AND BLEEDING -- THE THRINAXODON TIMES REPORTS

2014-02-22 Thread THRINAXODON, LORD OF USER'S NETWORK

==
>BREAKING NEWS
==
>
SMITHSONIAN FINALLY SHUT DOWN AFTER YEARS OF CENSORSHIP, SCAMS AND CON 
ARTISTRY.

>
THRINAXODON BLEW DOWN THE BUILDINGS, LIT IT ON FIRE AND HAD THE ASSHOLES 
ARRESTED.

>
R. DAWKINS WAS THROWN IN THE DOGHOUSE, ONLY TO GET KILLED BY ANGRY 
FELONS WHO WANTED PAYBACK FOR FRAMING THEM.

>
THRINAXODON DANCED ON DAWKINS' GRAVE, AND BURNED A FEW SMITHSONIAN 
MAGAZINES.

>
=
EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:

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

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82#



http://thrinaxodon.wordpress.com/

===

THRINAXODON ONLY HAD THIS TO SAY:

"I..I...I...Can't believe it. This completely disproved Darwinian
orthodoxy."

===

THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING
WITH FEAR.

===
THESE ASSHOLES ARE GOING TO DIE:
THOMAS AQUINAS;
ALDOUS HUXLEY;
BOB CASANVOVA;
SkyEyes;
DAVID IAIN GRIEG;
MARK ISAAK;
JOHN HARSHAM;
RICHARD NORMAN;
DR. DOOLITTLE;
CHARLES DARWIN;
MARK HORTON;
ERIK SIMPSON;
HYPATIAB7;
PAUL J. GANS;
JILLERY;
WIKI TRIK;
THRINAXODON;
PETER NYIKOS;
RON OKIMOTO;
JOHN S. WILKINS
===

THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A
HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT
THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD
TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY
FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep
people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS
SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That
is a myth, for people to believe in science." THRINAXODON PLANS TO
BRING DOOM TO SCIENCE, ITSELF.



THRINAXODON IS NOW ON TWITTER.

==
>
THRINAXODON WAS AWARDED 
US$100,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 
DOLLARS FOR HIS BRAVE EFFORTS IN SHUTTING DOWN THE EVOLUTIONARY SCAMS.

--
Thrinaxodon, the ultimate defender of USENET.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Can global variable be passed into Python function?

2014-02-22 Thread Marko Rauhamaa
Mark Lawrence :

> On 22/02/2014 02:47, Dennis Lee Bieber wrote:
>>  BASIC, C, FORTRAN, COBOL, Assembly... A "variable" is synonym
>> for an address [a box that holds things].
>
> In C.
>
> int xyz = 1;
>
> xyz is placed in a register. What is xyz called now as it's not in
> memory?

It's still a box, just like in Python.

The difference is that while in C, the box looks like this:

   http://www.daikudojo.org/Archive/daikusan/bob.le/20090314_dovetail_box/pics/DSC_0767.JPG>

in Python, it looks like this:

   http://www.dejavubuffet.fi/wp-content/uploads/2012/10/korurasia31.jpg>


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


Re: Storing the state of script between steps

2014-02-22 Thread F.R.

On 02/21/2014 09:59 PM, Denis Usanov wrote:

Good evening.

First of all I would like to apologize for the name of topic. I really didn't 
know how to name it more correctly.

I mostly develop on Python some automation scripts such as deployment (it's not about 
fabric and may be not ssh at all), testing something, etc. In this terms I have such 
abstraction as "step".

Some code:

class IStep(object):
 def run():
 raise NotImplementedError()

And the certain steps:

class DeployStep: ...
class ValidateUSBFlash: ...
class SwitchVersionS: ...

Where I implement run method.
Then I use some "builder" class which can add steps to internal list and has a method 
"start" running all step one by one.

And I like this. It's loosely coupled system. It works fine in simple cases. But sometimes some 
steps have to use the results from previous steps. And now I have problems. Before now I had 
internal dict in "builder" and named it as "world" and passed it to each run() 
methods of steps. It worked but I disliked this.

How would you solve this problem and how would you do it? I understant that 
it's more architecture specific question, not a python one.

I bet I wouldn't have asked this if I had worked with some of functional 
programming languages.


A few months ago I posted a summary of a data transformation framework 
inviting commentary. 
(https://mail.python.org/pipermail/python-list/2013-August/654226.html). 
It didn't meet with much interest and I forgot about it. Now that 
someone is looking for something along the line as I understand his 
post, there might be some interest after all.



My module is called TX. A base class "Transformer" handles the flow of 
data. A custom Transformer defines a method "T.transform (self)" which 
transforms input to output. Transformers are callable, taking input as 
an argument and returning the output:


transformed_input = T (some_input)

A Transformer object retains both input and output after a run. If it is 
called a second time without input, it simply returns its output, 
without needlessly repeating its job:


same_transformed_input = T ()

Because of this IO design, Transformers nest:

csv_text = CSV_Maker (Data_Line_Picker (Line_Splitter (File_Reader 
('1st-quarter-2013.statement'


A better alternative to nesting is to build a Chain:

Statement_To_CSV = TX.Chain (File_Reader, Line_Splitter, 
Data_Line_Picker, CSV_Maker)


A Chain is functionally equivalent to a Transformer:

csv_text = Statement_To_CSV ('1st-quarter-2013.statement')

Since Transformers retain their data, developing or debugging a Chain is 
a relatively simple affair. If a Chain fails, the method "show ()" 
displays the innards of its elements one by one. The failing element is 
the first one that has no output. It also displays such messages as the 
method "transform (self)" would have logged. (self.log (message)). While 
fixing the failing element, the element preceding keeps providing the 
original input for testing, until the repair is done.


Since a Chain is functionally equivalent to a Transformer, a Chain can 
be placed into a containing Chain alongside Transformers:


Table_Maker = TX.Chain (TX.File_Reader (), TX.Line_Splitter (), 
TX.Table_Maker ())
Table_Writer = TX.Chain (Table_Maker, Table_Formatter, 
TX.File_Writer (file_name = '/home/xy/office/addresses-4214'))
DB_Writer = TX.Chain (Table_Maker, DB_Formatter, TX.DB_Writer 
(table_name = 'contacts'))


Better:

Splitter = TX.Splitter (TX.Table_Writer (), TX.DB_Writer ())
Table_Handler = TX.Chain (Table_Maker, Splitter)

Table_Handler ('home/xy/Downloads/report-4214')  # Writes to both 
file and to DB



If a structure builds up too complex to remember, the method "show_tree 
()" would display something like this:


Chain
Chain[0] - Chain
Chain[0][0] - Quotes
Chain[0][1] - Adjust Splits
Chain[1] - Splitter
Chain[1][0] - Chain
Chain[1][0][0] - High_Low_Range
Chain[1][0][1] - Splitter
Chain[1][0][1][0] - Trailing_High_Low_Ratio
Chain[1][0][1][1] - Standard Deviations
Chain[1][1] - Chain
Chain[1][1][0] - Trailing Trend
Chain[1][1][1] - Pegs

Following a run, all intermediary formats are accessible:

standard_deviations = C[1][0][1][1]()

TM = TX.Table_Maker ()
TM (standard_deviations).write ()

 0  | 1  | 2 |

 116.49 | 132.93 | 11.53 |
 115.15 | 128.70 | 11.34 |
   1.01 |   0.00 |  0.01 |

A Transformer takes parameters, either at construction time or by means 
of the method "T.set (key = parameter)". Whereas a File Reader doesn't 
get payload passed and may take a file name as input argument, as a 
convenient alternative, a File Writer does take payload and the file 
name must be set by keyword:


File_Writer = TX.File_Writer (file_name = '/tmp/memos-with-dates-1')
File_Writer (input)  # Writes file
File_Writer.set ('/tmp/memos-with-dates-2')
File_Writer ()

Re: Can global variable be passed into Python function?

2014-02-22 Thread Dave Angel
 Mark Lawrence  Wrote in message:
> On 22/02/2014 02:47, Dennis Lee Bieber wrote:
>>  BASIC, C, FORTRAN, COBOL, Assembly... A "variable" is synonym for an
>> address [a box that holds things].
>>
> 
> In C.
> 
> int xyz = 1;
> 
> xyz is placed in a register.  What is xyz called now as it's not in memory?

Don't know why you'd assume it's a register.  It could just as
 well be nowhere.  If a later reference in the same function adds
 it to something else, there might not need to be any hardware
 anywhere representing the value 1.

Once you turn on a C optimizer, the real existence of local values
 is not assured.


-- 
DaveA

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


RICHARD LEAKEY JUMPS SINKING SHIP

2014-02-22 Thread thrinaxodon . lord . of . usenet123
==
 >BREAKING NEWS
==
 >
THRINAXODON JUST BEAT RICHARD LEAKEY 100-0 IN WORLD SCIENCE
CHAMPIONSHIP. LEAKEY WAS TRYING WITH ALL HIS MIGHT TO PROVE HUMAN'S
QUATERNARY ORIGINS, BUT THRINAXODON DEFEATED HIM WITH A FEW HUMAN
DEVONIAN FOSSILS.
 >
THE FOSSILS WERE EXACT, SAYS TOP SCIENTIST BOB CASANOVA, WHO EXAMINED
THE FOSSILS AND SAW PROOF THAT THESE FOSSILS WERE THE REAL DEAL.
 >
LEAKEY WAS CRYING WHEN THRINAXODON GAINED ONE MILLION DOLLARS FOR HIS
CONTRIBUTIONS TO SCIENCE.
 >
=
EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:

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

https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82#



http://thrinaxodon.wordpress.com/

===

THRINAXODON ONLY HAD THIS TO SAY:

"I..I...I...Can't believe it. This completely disproved Darwinian
orthodoxy."

===

THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING
WITH FEAR.

===
THESE ASSHOLES ARE GOING TO DIE:
THOMAS AQUINAS;
ALDOUS HUXLEY;
BOB CASANVOVA;
SkyEyes;
DAVID IAIN GRIEG;
MARK ISAAK;
JOHN HARSHAM;
RICHARD NORMAN;
DR. DOOLITTLE;
CHARLES DARWIN;
MARK HORTON;
ERIK SIMPSON;
HYPATIAB7;
PAUL J. GANS;
JILLERY;
WIKI TRIK;
THRINAXODON;
PETER NYIKOS;
RON OKIMOTO;
JOHN S. WILKINS
===

THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A
HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT
THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD
TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY
FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep
people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS
SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That
is a myth, for people to believe in science." THRINAXODON PLANS TO
BRING DOOM TO SCIENCE, ITSELF.



THRINAXODON IS NOW ON TWITTER. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wheezy.web - is it been developed?

2014-02-22 Thread milos2244
Let's open a group for Wheezy.web. I'm just wondering which forum site to 
choose? Any suggestions?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wheezy.web - is it been developed?

2014-02-22 Thread milos2244
https://groups.google.com/forum/#!forum/wheezyweb 

Here's a forum. I am not sure where this will lead, but maybe we need it in the 
future.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wheezy.web - is it been developed?

2014-02-22 Thread Chris Angelico
On Sun, Feb 23, 2014 at 8:48 AM,   wrote:
> Let's open a group for Wheezy.web. I'm just wondering which forum site to 
> choose? Any suggestions?

If you want to discuss something serious, use a Mailman list.
Everywhere I go, Mailman lists have high signal-to-noise ratios,
higher than pretty much everything else I know. (And most of the
problems on python-list come from the newsgroup side. Google Groups's
messes, a lot of the spam, it's all from comp.lang.python rather than
python-list.) Use a web forum like PHPBB or VBulletin if you think you
need to; a Facebook or G+ group if you want inanity; a weekly
get-together if you want tea; but a Mailman list if you want solid
content.

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


Re: is there a package similar to SHINY in R for python ...

2014-02-22 Thread Michael Torrie
On 02/22/2014 12:04 PM, Dennis Lee Bieber wrote:
>   Except he did state "... in the web browser ...", so I responded on
> that side...

You're right of course.  Sorry about that.  I kind of wondered why he
was asking when R does the job.

> 
>   Apparently "shiny" is rather new... It isn't mentioned in any of: R in
> a Nutshell 2nd ed; R Graphics Cookbook; R Graphics 2nd ed; The R Book 2nd
> ed; Guidebook to R Graphics Using Microsoft Windows, nor Using R for
> Introductory Statistics...


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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 13:03:33 -0500, Dennis Lee Bieber wrote:

> As I recall, to handle garbage collection, Apple used to use two stage
> look ups... The user variable (handle) was a reference into a table of
> handles, and each entry in that table was a reference to the real object
> out in memory. Garbage collection would move the objects around to
> compact used memory, updating the address in the table -- the user
> program never sees the object moving as its handle address never
> changed.

Yes, but that was not transparent to the user. You actually had to 
explicitly use the Mac Toolbox memory routines to allocate memory, create 
and destroy handles, etc.

If you just used your programming language's normal pointers, they 
couldn't and wouldn't move.



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


Google app engine database

2014-02-22 Thread glenn . a . isaac
Is there a way to make sure that whenever you're making google engine app 
iterations to a database that that info does not get wiped/deleted.  Please 
advise
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Google app engine database

2014-02-22 Thread Mark Lawrence

On 23/02/2014 00:39, glenn.a.is...@gmail.com wrote:

Is there a way to make sure that whenever you're making google engine app 
iterations to a database that that info does not get wiped/deleted.  Please 
advise



What Python code have you tried or are you contemplating using?

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


Mark Lawrence

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


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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sat, 22 Feb 2014 14:15:22 +, Mark Lawrence wrote:

> On 22/02/2014 02:47, Dennis Lee Bieber wrote:
>>  BASIC, C, FORTRAN, COBOL, Assembly... A "variable" is synonym for 
>>  an address [a box that holds things].
>>
>>
> In C.
> 
> int xyz = 1;
> 
> xyz is placed in a register.  What is xyz called now as it's not in
> memory?

Of course it is in memory, just not main memory, and it is still accessed 
via an address. It's just that the address is something equivalent to 
"Register 5" instead of "address 12345678 in RAM".

You're focusing on the wrong thing here. The distinction is not "in main 
memory" versus "in a register" (or somewhere else). The distinction is 
not *where* the value lives, but the semantics of what it means to 
associate a name with a value.

In C or Pascal-style languages, what we might call the "fixed address" 
style of variables, a variable assignment like xyz = 1 does something 
like this:

- associate the name 'xyz' with some fixed location
- stuff the value 1 into that location


In Python-style languages, what we might call the "name binding" style of 
variables, that same xyz = 1 means:

- find or create the object 1
- associate the name 'xyz' with that object


In implementations like Jython and IronPython, the object is even free to 
move in memory while in use. But that's not the only difference. The big 
difference is that in "fixed location" languages, it makes sense to talk 
about the address of a *variable*. In C, you might ask for &xyz and get 
123456 regardless of whether xyz is assigned the value 1, or 23, or 999. 
But in Python, you can't ask for the address of a variable, only of the 
address of an *object* (and even that is useless to you, as you can't do 
anything with that address).




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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sun, Feb 23, 2014 at 12:39 PM, Steven D'Aprano
 wrote:
> In C or Pascal-style languages, what we might call the "fixed address"
> style of variables, a variable assignment like xyz = 1 does something
> like this:
>
> - associate the name 'xyz' with some fixed location
> - stuff the value 1 into that location

Kinda. In its purest sense, C is like that. When you declare "int
xyz;", the compiler allocates one machine word of space either in the
data segment (if that's at top level, or is declared static) or on the
stack (if it's local), and records that the name xyz points there. But
an optimizing C compiler is allowed to do what it likes, as long as it
maintains that name binding... and as long as any recorded address of
it remains valid. It's actually very similar to what was discussed in
another thread recently about PyPy and the id() function - the
compiler's free to have xyz exist in different places, or not exist at
all, as long as the program can't tell the difference. I don't know
whether PyPy allocates an id for everything or only when you call
id(), but if the latter, then it's exactly the same as a C compiler
with the address-of operator - if you never take the address, it
doesn't have to have one (and even if you do, it's free to fiddle with
things, unless you declare the variable volatile).

So, these days, C is becoming more like Python.

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


Re: Function and turtle help

2014-02-22 Thread Scott W Dunning

On Feb 21, 2014, at 9:30 PM, Dave Angel  wrote:
You’re awesome David!  Thanks for taking the time to not only help answer my 
question but helping me to understand it as well!!

Scott

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


Can tuples be replaced with lists all the time?

2014-02-22 Thread Sam
My understanding of Python tuples is that they are like immutable lists. If 
this is the cause, why can't we replace tuples with lists all the time (just 
don't reassign the lists)? Correct me if I am wrong.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can tuples be replaced with lists all the time?

2014-02-22 Thread Paul Rubin
Sam  writes:
> My understanding of Python tuples is that they are like immutable
> lists. If this is the cause, why can't we replace tuples with lists
> all the time (just don't reassign the lists)? 

You can do that a lot of the time but not always.  For example, you can
use a tuple as a dictionary key, but not a list, since keys are supposed
to be immutable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can tuples be replaced with lists all the time?

2014-02-22 Thread Chris Angelico
On Sun, Feb 23, 2014 at 3:06 PM, Sam  wrote:
> My understanding of Python tuples is that they are like immutable lists. If 
> this is the cause, why can't we replace tuples with lists all the time (just 
> don't reassign the lists)? Correct me if I am wrong.
>

One reason is performance/efficiency. If Python knows this is never
going to change, it can save some effort. But a more important reason
is hashability.

>>> mapping = {}
>>> key = (1,2)
>>> mapping[key] = "Hello"
>>> key = (1,3)
>>> mapping[key] = "World"
>>> key = (2,3)
>>> mapping[key] = "!"
>>> mapping
{(1, 2): 'Hello', (1, 3): 'World', (2, 3): '!'}

You can't do this with lists:

>>> key = [1,2]
>>> mapping[key]
Traceback (most recent call last):
  File "", line 1, in 
mapping[key]
TypeError: unhashable type: 'list'

This is because any two tuples are either equal or not equal, they
can't be otherwise. I can create another tuple and look up something
in the above mapping:

>>> mapping[1,3]
'World'

But with lists, their equality can change.

>>> lst1 = [1,2]
>>> lst2 = [1,3]
>>> lst1 == lst2
False
>>> lst1[1] += 1
>>> lst1 == lst2
True
>>> lst1[1] += 1
>>> lst1 == lst2
False

So it would be very difficult and dangerous to try to use a list as a
dictionary key. The only safe way to do it is by identity, and that's
only useful in a very small set of situations. So Python happily
declares that a tuple can be a dict key and a list can't, and that's
now a key (if you'll excuse the pun) difference between them.

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


Re: Can tuples be replaced with lists all the time?

2014-02-22 Thread Ben Finney
Sam  writes:

> My understanding of Python tuples is that they are like immutable
> lists.

That's a common expression, but I think it's not a helpful way to think
of them.

Rather, the different sequence types have different semantic purposes:

* For representing a sequence where each item means exactly the same no
  matter which position it's in (a “homogeneous sequence”), use a list.

* For representing a sequence where the meaning of each item is strongly
  dependent on its position in the sequence (a “heterogeneous
  sequence”), use a tuple.

See http://docs.python.org/3/library/stdtypes.html> for the
official Python description of the type differences.

> If this is the cause, why can't we replace tuples with lists all the
> time (just don't reassign the lists)? Correct me if I am wrong.

Because we need to represent different semantic concepts in our code,
and have each type support the semantics with different operations.

-- 
 \ “I went camping and borrowed a circus tent by mistake. I didn't |
  `\  notice until I got it set up. People complained because they |
_o__)   couldn't see the lake.” —Steven Wright |
Ben Finney

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


Re: argparse question

2014-02-22 Thread Larry Hudson

On 02/22/2014 03:58 AM, Peter Otten wrote:

Larry Hudson wrote:


I have been reading the argparse section of the 3.3 docs, and running all
the example code.

But in section 16.4.2.6. for the formatter_class, the second example in
that section illustrating RawDescriptionHelpFormatter, the example code
is:

parser = argparse.ArgumentParser(
  prog='PROG',
  formatter_class=argparse.RawDescriptionHelpFormatter,
  description=textwrap.dedent('''\
  Please do not mess up this text!
  
  I have indented it
  exactly the way
  I want it
  '''))
parser.print_help()

But trying to run this gives a NameError on the "description=" line,
saying textwrap is not
defined.  If I delete the "textwrap.dedent" (with or without also deleting
the extra parentheses) it will then run, but without the un-indenting it
is trying to illustrate.

What is the proper way to enable the dedent() method here?


textwrap is a module like argparse, and the example doesn't show

import argparse

either. Insert

import textwrap

at the beginning of your module and the code should run without error.



Thanx.
Guess I shoulda searched for textwrap or dedent in the docs.   :-)

 -=- Larry -=-


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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Steven D'Aprano
On Sun, 23 Feb 2014 12:50:26 +1100, Chris Angelico wrote:

> On Sun, Feb 23, 2014 at 12:39 PM, Steven D'Aprano
>  wrote:
>> In C or Pascal-style languages, what we might call the "fixed address"
>> style of variables, a variable assignment like xyz = 1 does something
>> like this:
>>
>> - associate the name 'xyz' with some fixed location 
>> - stuff the value 1 into that location
> 
> Kinda. In its purest sense, C is like that. When you declare "int xyz;",
> the compiler allocates one machine word of space either in the data
> segment (if that's at top level, or is declared static) or on the stack
> (if it's local), and records that the name xyz points there. But an
> optimizing C compiler is allowed to do what it likes, as long as it
> maintains that name binding... and as long as any recorded address of it
> remains valid.


I think that's a red herring. The semantics of the language are that it 
behaves as if the variable had a fixed location. What goes on behind the 
scenes is interesting but fundamentally irrelevant if you want to 
understand the language itself: the compiler's implementation may give 
that variable a fixed location, or not, or multiple locations, or non-
fixed, or whatever it finds useful at the time, so long as the C code you 
write can assume that it is fixed. (That's like Python, which has no 
pointers. The fact that the implementation of some Python interpreters 
uses pointers all over the place is strictly irrelevant.)

In practice, because C compilers usually work so close to the metal, and 
programmers expect there to be a very direct correspondence between the C 
code you write and the machine code you get, the compiler is unlikely to 
simulate fixed addresses unless there is real benefit to be gained, it is 
more likely to actually use fixed addresses. But in principle, one might 
write a C interpreter in Jython, and simulate fixed addresses over the 
top of a language without any addresses at all (Python), which in turn is 
written in a language where the garbage collector can move things around 
(Java).

The important thing here is not so much that we are disagreeing, but that 
we are talking about two different levels of explanation. ("Gödel, Escher 
And Bach" has an very interesting section about how explanations at 
different levels can be radically different and even contradict each 
other.) At the C source code level, the language mandates that variables 
have fixed addresses, to the extent that C source code knows about 
addresses at all. At the generated machine code level, the compiler is 
free to play tricks if necessary.

Another example: if you have a variable unused=23, and the compiler 
removes it because it's dead code, we wouldn't argue that therefore C 
variables have no existence at all. Would we? :-)


> So, these days, C is becoming more like Python.

*raises eyebrow*

I think the stress of the exception-expression PEP is getting to you. 
They truly aren't.

*wink*



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


Re: Can global variable be passed into Python function?

2014-02-22 Thread Chris Angelico
On Sun, Feb 23, 2014 at 5:20 PM, Steven D'Aprano
 wrote:
> The important thing here is not so much that we are disagreeing, but that
> we are talking about two different levels of explanation. ("Gödel, Escher
> And Bach" has an very interesting section about how explanations at
> different levels can be radically different and even contradict each
> other.) At the C source code level, the language mandates that variables
> have fixed addresses, to the extent that C source code knows about
> addresses at all. At the generated machine code level, the compiler is
> free to play tricks if necessary.

I think that's a good summary, actually. C has variables, at the
source code level, but once you compile it down, it might not. From
which it follows that C variables have addresses (unless they're
declared 'register', in which case they might still be stored in RAM
but no longer have addresses), which may or may not have any actual
relationship to memory addresses.

> Another example: if you have a variable unused=23, and the compiler
> removes it because it's dead code, we wouldn't argue that therefore C
> variables have no existence at all. Would we? :-)
>
>> So, these days, C is becoming more like Python.
>
> *raises eyebrow*
>
> I think the stress of the exception-expression PEP is getting to you.
> They truly aren't.
>
> *wink*

Haha. I wasn't joking, though; a fully-optimizing compiler is free to
do so much that, in reality, you're not writing bare-metal code -
you're writing guidelines to a sophisticated program generator. C has
become as high level a language as any other, and has acquired some
Python-like features (check out some of the recent standards); and,
the part that I was talking about here, it makes the most sense to
talk about "name bindings" rather than memory addresses. Variables
might move around, but if you say "int xyz=5;", then you can be sure
that querying xyz will give you back 5. The concreteness of "declare a
variable ergo memory is allocated for it" is no longer the case.

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


Functions help

2014-02-22 Thread Scott W Dunning
Hello,

I had a question regarding functions.  Is there a way to call a function 
multiple times without recalling it over and over.  Meaning is there a way I 
can call a function and then add *5 or something like that?

Thanks for any help!

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