Re: How to implement key of key in python?

2014-05-10 Thread Andrea D'Amore

On 2014-05-10 03:28:29 +, eckhle...@gmail.com said:


While it is fine for a small dataset, I need a more generic way to do so.


I don't get how the dataset size affects the generality of the solution here.


From your first message:



attr = {}
with open('test.txt','rb') as tsvin:
tsvin = csv.reader(tsvin, delimiter='\t')
for row in tsvin:
ID = row[1]


so your is solved by adding a simple
 attr[ID] = {}

after the ID assignment. It seems simple to implement and generic enough to me.


unfortunately none of them illustrates how to store the values and 
access them later.


You access the stored value by using the variable name that holds it, 
but here you should probabily make more clear what your actual issue is.




Moreover, they bring some new terms, e.g. combined, [], etc.


The "[]" syntax is used in Python for lists.

The term "combined" hasn't a specific pythonic meaning there and is 
just used as a meaningful variable name as the author is combining, 
i.e. adding, numerical values.



--
Andrea

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


Re: The � debate

2014-05-10 Thread Chris Angelico
On Sat, May 10, 2014 at 3:58 PM, Gregory Ewing
 wrote:
> Steven D'Aprano wrote:
>>
>> some_function(x, y+1)[key].attribute[num](arg)[spam or eggs] = 42
>>
>> I'm pretty sure that it isn't common to call the LHS of that assignment a
>> variable.
>
>
> A better way of putting it might be "something in the data
> model that can be assigned to".

https://en.wikipedia.org/wiki/Assignment_(computer_science)

Go ahead, start an edit war at that page over its use of "variable".
:) Right there it talks about copying values into variables. So if
Python has no variables, then either that article is inappropriate, or
Python has no assignment either.

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


Re: Why isn't my re.sub replacing the contents of my MS Word file?

2014-05-10 Thread wxjmfauth
Le samedi 10 mai 2014 06:22:00 UTC+2, Rustom Mody a écrit :
> On Saturday, May 10, 2014 1:21:04 AM UTC+5:30, scott...@gmail.com wrote:
> 
> > Hi,
> 
> > 
> 
> > 
> 
> > 
> 
> >  here is a snippet of code that opens a file (fn contains the path\name) 
> > and first tried to replace all endash, emdash etc characters with simple 
> > dash characters, before doing a search.
> 
> > 
> 
> >   But the replaces are not having any effect. Obviously a syntax 
> > problemwwhat silly thing am I doing wrong?
> 
> 
> 
> If you are using MS-Word use that, not python.
> 
> 
> 
> Yeah it is possible to script MS with something like this
> 
> http://timgolden.me.uk/pywin32-docs/
> 
> [no experience myself!]
> 
> but its probably not worth the headache for such a simple job.
> 
> 
> 
> The VBA (or whatever is the modern equivalent) will be about as short and 
> simple
> 
> as your attempted python and making it work will be far easier.
> 
> 
> 
> I way I used to do it with Windows-98 Word. 
> 
> Start a macro
> 
> Do a simple single search and replace by hand
> 
> Close the macro
> 
> Edit the macro (VBA version)
> 
> Replace the single search-n-replace with all the many you require

=

That's a wise reommendation.

Anyway, as Python may fail as soon as one uses an
EM DASH or an EM DASH, I think it's not worth the
effort to spend to much time with it.

LibreOffice could be a solution.

jmf


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


Re: Values and objects

2014-05-10 Thread Chris Angelico
On Sat, May 10, 2014 at 4:15 PM, Steven D'Aprano
 wrote:
> On Sat, 10 May 2014 12:33:28 +1000, Chris Angelico wrote:
>> 1) Passing them as parameters. You can pass a pointer to a variable,
>> which is effectively the same as passing a variable to a function.
>
> No it is not. It is nothing like passing a variable to a function. You
> are passing a pointer, which is itself a value. True, it is a value which
> you, the author, gives meaning as a pointer to a variable, but that need
> not be the case. It might be a pointer to a part of an array, or a
> record, or to some random address in memory, or a dangling pointer. C
> allows you to perform arithmetic on pointers, which means you can
> construct pointers to nothing in particular.

I think at this point it's arguable, in that you can get so close to
"passing a variable to a function" that it doesn't really matter about
the distinction. But as I explained further down, it really just shows
that "patch of memory" can be passed around, and that a variable can
be backed by such a patch of memory.

> Rather than *creating* patches of memory, malloc merely allocates it from
> pre-existing memory.

I disagree. On a modern system with memory management, malloc can grab
memory from the system, thus making it available to your process.
Sure, physical memory will normally have to have been installed in the
system, but conceptually you could have a malloc function that
actually freezes the program, asks the user to build a new computer
and turn it on, connects to a new service on that computer, and
allocates memory from there. As far as your program's concerned,
malloc actually does (attempt to) give you more room than you had.

> Python variables aren't first-class either, but in fact we can get a bit
> closer to first-class than either C or Pascal.
>
> Creating new variables is trivial. Since they don't need to be declared,
> you create a new variable just by assigning to it:
>
> try:
> spam
> except NameError:
> spam = 23

No no no, this is really creating them at compile time. If you do this
inside a function, the name has to be created as a local name before
the function begins execution.

> There are at least two other ways:
>
> globals()['spam'] = 23
> exec('spam = 23')

With exec, you can do anything "at run time". Does that mean that, in
languages with an exec action, absolutely everything is first-class?
I'm not sure that that counts. Maybe I'm wrong.

Subscript-assigning to globals() is actually creating new
(module-level) variables, though. And if Python allowed you to assign
to locals() inside a function, then I would accept that local function
variables can be created and destroyed at run time, but you can't, so
local variables aren't first-class.

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


Re: The � debate

2014-05-10 Thread Steven D'Aprano
On Sat, 10 May 2014 17:10:29 +1000, Chris Angelico wrote:

> On Sat, May 10, 2014 at 3:58 PM, Gregory Ewing
>  wrote:
>> Steven D'Aprano wrote:
>>>
>>> some_function(x, y+1)[key].attribute[num](arg)[spam or eggs] = 42
>>>
>>> I'm pretty sure that it isn't common to call the LHS of that
>>> assignment a variable.
>>
>>
>> A better way of putting it might be "something in the data model that
>> can be assigned to".
> 
> https://en.wikipedia.org/wiki/Assignment_(computer_science)
> 
> Go ahead, start an edit war at that page over its use of "variable". :)
> Right there it talks about copying values into variables. So if Python
> has no variables, then either that article is inappropriate, or Python
> has no assignment either.

Python assignment doesn't copy values.




-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The “does Python have variables?” debate

2014-05-10 Thread Larry Hudson

On 05/09/2014 06:11 PM, Steven D'Aprano wrote:

On Fri, 09 May 2014 17:34:17 -0500, Mark H Harris wrote:


On 5/7/14 8:27 PM, Steven D'Aprano wrote:



  Why are new Python coders 'always' confused by this question of
variable (name value) vs. {name: object} model of Python?


"Always"? I don't think anyone, not even Ben, claims that new Python
coders are "always" confused about Python's variable semantics. That
would be a straw man, easy to disprove by just finding a single person
who wasn't confused. Perhaps someone who had never learned C and didn't
know C variable semantics?



Well, here is that one person.   ;-)

I'm an entirely self-taught amateur/hobbyist programmer, coming to Python from a C background. 
Very early in my reading of books/tutorials on Python I learned that Python variables are 
different, and how they are different from C variables.  Essentially I said, "Okay, they're 
different.  What's next?"  There was no confusion at all.  All I had to do was accept that they 
_are_ different.  (BTW, I'm now quite hooked on Python -- and still learning it.)



  The reason I suggest is that the person has a preconceived idea of
what 'variable' means, and they then attempt to apply their conception
of variable on to Python in some way ending in a surprise.


That's the problem as some of us see it.



As I said above, not a problem.  I already accepted the fact that all programming languages are 
different -- often with similarities, but more often quite different, especially in the details. 
 So when programming in C I think in C-style variables, in Python I think in Python-style 
variables.  And uv course, I nefer make mmistakes...  Yeah, right!;-)





  We need a way to speak about Pythons name object model to avoid
this confusion.


And that would be the "name binding" part.



This is something I absolutely disagree with.  I still think it's only necessary to teach that 
variables in different languages are handled differently.  Insisting on a different name is NOT 
helpful.  And insisting that Python does not have variables is ludicrous!


 -=- Larry -=-

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


Re: Values and objects

2014-05-10 Thread Marko Rauhamaa
Chris Angelico :

> On Sat, May 10, 2014 at 8:34 AM, Marko Rauhamaa  wrote:
>> Right, Python's variables aren't like variables in C. Rather,
>> Python's variables are like CPU registers. They cannot hold typed or
>> structured objects and you can't pass references to them.
>
> Are you thinking that a Python variable is neither more nor less than
> what CPython implements them as?

I was just being more Catholic than the Pope.

To me, a variable is a variable is a variable.


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


dynamic form application

2014-05-10 Thread edd . cowan
hello guys.

i tryng to create a form builder application with a database backend.
like wufoo.com

im stuck,how do i use jquery to create dynamic forms,and how is the database 
designed for the actual forms and the data gathered using those forms i'd like 
to use rdbms preferebly postgres.

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


Re: The � debate

2014-05-10 Thread Chris Angelico
On Sat, May 10, 2014 at 5:48 PM, Steven D'Aprano
 wrote:
>> https://en.wikipedia.org/wiki/Assignment_(computer_science)
>>
>> Go ahead, start an edit war at that page over its use of "variable". :)
>> Right there it talks about copying values into variables. So if Python
>> has no variables, then either that article is inappropriate, or Python
>> has no assignment either.
>
> Python assignment doesn't copy values.

So either the article is wrong, or Python doesn't have assignment. Which is it?

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


Re: Values and objects

2014-05-10 Thread Jussi Piitulainen
Marko Rauhamaa writes:

> To me, a variable is a variable is a variable.

That works only in Python.

Elsewhere, the sentence would be interpreted either as "a variable is
True" or as "a variable is False" depending on whether a distinction
without a difference is deemed helpful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The � debate

2014-05-10 Thread Marko Rauhamaa
Chris Angelico :

> On Sat, May 10, 2014 at 3:58 PM, Gregory Ewing
>  wrote:
>> Steven D'Aprano wrote:
>>>
>>> some_function(x, y+1)[key].attribute[num](arg)[spam or eggs] = 42
>>>
>>> I'm pretty sure that it isn't common to call the LHS of that assignment a
>>> variable.
>
> [...]
> https://en.wikipedia.org/wiki/Assignment_(computer_science)
>
> [...]
>
> So if Python has no variables, then either that article is
> inappropriate, or Python has no assignment either.

Many complaints against Python's variables are really comments on
Python's object model.

Steven's example points out a different angle: many complaints against
Python's variables are really comments on Python's assignment statement
(including argument passing).

In Python,

   x   is a variable, a memory slot that can be assigned to,
   a[3]is a list element, a memory slot that can be assigned to,
   d['y']  is a dict entry, a memory slot that can be assigned to,
   o.f is a field, a memory slot that can be assigned to

Now, Python (together with a host of other programming languages) lacks
a way to pass memory slots by reference (although the list/dict+key
comes close). However, the fact that you can't get a reference to a
variable/list element/dict entry/field doesn't mean Python doesn't have
variables/list elements/dict entries/fields.


Marko

PS I have mentioned before that Python 3 *does* allow you to pass a
reference to any LHS by constructing an ad-hoc accessor object:

x, y = 2, 3
class X:
def get(self): return x
def set(self, v): nonlocal x; x = v
class Y:
def get(self): return y
def set(self, v): nonlocal y; y = v
swap(X(), Y())
print(x, y)
=> 3, 2

Such ad-hoc accessor classes are required for nonglobal variables only.
Generic accessor classes can be written for global variables, list
elements, dict entries and fields.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to implement key of key in python?

2014-05-10 Thread Peter Otten
eckhle...@gmail.com wrote:

> On Saturday, May 10, 2014 10:30:06 AM UTC+8, MRAB wrote:
>> On 2014-05-10 02:22, I wrote:
>> 
>> > I'm migrating from Perl to Python and unable to identify the equivalent
>> > of key of key concept. The following codes run well,
>> 
>> > import csv
>> 
>> > attr = {}
>> 
>> > with open('test.txt','rb') as tsvin:
>> 
>> >  tsvin = csv.reader(tsvin, delimiter='\t')
>> 
>> >  for row in tsvin:
>> 
>> >  ID = row[1]
>> 
>> > until:
>> 
>> >  attr[ID]['adm3'] = row[2]
>> 
>> > I then try:
>> 
>> >  attr[ID].adm3 = row[2]
>> 
>> > still doesn't work. Some posts suggest using module dict but some do
>> > not. I'm a bit confused now. Any suggestions?
>> 
>> Python doesn't have Perl's autovivication feature. If you want the
>> 
>> value to be a dict then you need to create that dict first:
>> 
>> attr[ID] = {}
>> 
>> attr[ID]['adm3'] = row[2]
>>
>> You could also have a look at the 'defaultdict' class in the
>> 
>> 'collections' module.
> 
> I identify the information below:
> s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
> d = defaultdict(list)
> for k, v in s:
>   d[k].append(v)
> 
> While it is fine for a small dataset, I need a more generic way to do so.
> Indeed the "test.txt" in my example contains more columns of attributes
> like:
> 
> ID address age gender phone-number race education ...
> ABC123 Ohio, USA 18 F 800-123-456 european university
> ACC499 London 33 M 800-111-400 african university
> ...
> 
> so later I can retrieve the information in python by:
> 
> attr['ABC123'].address (containing 'Ohio, USA')
> attr['ABC123'].race (containing 'european')
> attr['ACC499'].age (containing '33')

Using a csv.DictReader comes close with minimal effort:

# write demo data to make the example self-contained
with open("tmp.csv", "w") as f:
f.write("""\
ID,address,age,gender,phone-number,race,education
ABC123,"Ohio, USA",18,F,800-123-456,european,university
ACC499,London,33,M,800-111-400,african,university
""")

import csv
import pprint

with open("tmp.csv") as f:
attr = {row["ID"]: row for row in csv.DictReader(f)}

pprint.pprint(attr)

print(attr["ACC499"]["age"])

The "dict comprehension"

attr = {row["ID"]: row for row in csv.DictReader(f)}

is a shortcut for

attr = {}
for row in csv.DictReader(f):
attr[row["ID"]] = row

If you insist on attribute access (row.age instead of row["age"]) you can 
use a namedtuple. This is a bit more involved:

import csv
import pprint
from collections import namedtuple

with open("tmp.csv") as f:
rows = csv.reader(f)
header = next(rows)

# make sure column names are valid Python identifiers
header = [column.replace("-", "_") for column in header]

RowType = namedtuple("RowType", header)
key_index = header.index("ID")
attr = {row[key_index]: RowType(*row) for row in rows}

pprint.pprint(attr)

print(attr["ABC123"].race)

> The following links mention something similar,

Too many, so I checked none of them ;)

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


Re: The � debate

2014-05-10 Thread Marko Rauhamaa
Chris Angelico :

> On Sat, May 10, 2014 at 5:48 PM, Steven D'Aprano
>  wrote:
>>> https://en.wikipedia.org/wiki/Assignment_(computer_science)
>>>
>>> Go ahead, start an edit war at that page over its use of "variable". :)
>>> Right there it talks about copying values into variables. So if Python
>>> has no variables, then either that article is inappropriate, or Python
>>> has no assignment either.
>>
>> Python assignment doesn't copy values.
>
> So either the article is wrong, or Python doesn't have assignment.
> Which is it?

You can understand copying more liberally:

   assignment   -- 0-level copy
   shallow copy -- 1-level copy
   deep copy-- infinite-level copy

Real programs occasionally need 2-level or n-level copies.


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


Re: Why isn't my re.sub replacing the contents of my MS Word file?

2014-05-10 Thread Tim Golden

On 10/05/2014 08:11, wxjmfa...@gmail.com wrote:

Anyway, as Python may fail as soon as one uses an
EM DASH or an EM DASH, I think it's not worth the
effort to spend to much time with it.


Nope -- seems all right to me. (Hopefully helping the OP out as well as 
rebutting a rather foolish assertion).



#!python3.4
import win32com.client
import unicodedata

word = win32com.client.gencache.EnsureDispatch("Word.Application")
try:
doc1 = word.Documents.Add()
doc1.Range().Text += "Hello \u2014 World"
doc1.SaveAs(r"c:\temp\em_dash.docx")
doc1.Close()

doc2 = win32com.client.GetObject(r"c:\temp\em_dash.docx")
for uchar in doc2.Range().Text.strip():
print(unicodedata.name(uchar))

finally:
word.Quit()



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


Re: Values and objects

2014-05-10 Thread Steven D'Aprano
On Sat, 10 May 2014 17:21:56 +1000, Chris Angelico wrote:

> On Sat, May 10, 2014 at 4:15 PM, Steven D'Aprano
>  wrote:
>> On Sat, 10 May 2014 12:33:28 +1000, Chris Angelico wrote:
>>> 1) Passing them as parameters. You can pass a pointer to a variable,
>>> which is effectively the same as passing a variable to a function.
>>
>> No it is not. It is nothing like passing a variable to a function. You
>> are passing a pointer, which is itself a value. True, it is a value
>> which you, the author, gives meaning as a pointer to a variable, but
>> that need not be the case. It might be a pointer to a part of an array,
>> or a record, or to some random address in memory, or a dangling
>> pointer. C allows you to perform arithmetic on pointers, which means
>> you can construct pointers to nothing in particular.
> 
> I think at this point it's arguable, in that you can get so close to
> "passing a variable to a function" that it doesn't really matter about
> the distinction. But as I explained further down, it really just shows
> that "patch of memory" can be passed around, and that a variable can be
> backed by such a patch of memory.

No offence Chris, but I think this demonstrates that learning C causes 
brain damage and prevents clear logical thinking :-P

You're not passing a variable to a function. You're passing a pointer, 
which is itself a first-class value. It could be a pointer to ANYTHING, 
or NOTHING at all -- C doesn't even promise to ensure that it is a valid 
pointer, although more modern languages may. There's certainly no 
guarantee that it's a pointer to a variable. And you cannot create new 
variables -- C only allows variables to be created at compile time.

The question is not, "Can I implement some aspects of first-class 
behaviour for variables by hand?" The question is, "Are variables treated 
as first class values in C?"

If you asked, "Does Pascal have an exponentiation or power operator?", 
and I answered "Sure it does! If you want to calculate x squared, you 
just write x*x, if you want x cubed, write x*x*x, and if you want x to 
the power of twelve, x*x*x*x*x*x*x*x*x*x*x*x" you would rightfully slap 
me with a halibut. Being able to manually perform repeated multiplication 
is not the same as having the language support exponentiation. To say 
nothing of fractional exponents. "How about x to the power of one third?"

Being able to manually pass pointers to variables about is not the same 
as having first class variables. It fails on the very first hurdle, "Are 
variables treated the same as other values?"

How do I pass an int to a function? func(some_int)

How do I pass a double to a function? func(some_double)

How do I pass a bool to a function? func(some_bool)

How do I pass a variable to a function? ptr = &some_variable; func(ptr)

Does that look the same to you? The fact that you can do it at all is not 
sufficient to make it first class. It just makes it a work-around for the 
lack of first class variables in the language.

Personally, I don't imagine that there ever could be a language where 
variables were first class values *exactly* the same as ints, strings, 
floats etc. Otherwise, how could you tell the difference between a 
function which operated on the variable itself, and one which operated on 
the value contained by the value? The best you can do is for variables to 
be "second class" -- you can do these things to them, but you need 
special syntax or declarations to tell the compiler you're operating on 
the variable rather than the variable's value. E.g. Pascal and Algol have 
syntax for instructing the compiler when to pass a variable as a value, 
and when to pass the value. C gives you nothing.

I would say that C variables are *third class*. There's no compiler 
support for variables-as-values at all, but you can manually fake it a 
bit by using pointers. There is no way to tell whether the pointer 
actually points to a variable, and since arrays aren't first class 
neither are pointer-to-arrays.

Algol and Pascal are *second class*, since the compiler does allow you to 
pass variables as arguments (var parameters in Pascal, I forget what they 
are called in Algol). Likewise, Python let's you create new variables at 
runtime, or delete them, but you can't pass them around. But still, 
you're quite limited in what the language does for you, compared to what 
you have to do yourself:

x = 23
function("x", globals())  # See, I can pass a variable! Not.


>> Rather than *creating* patches of memory, malloc merely allocates it
>> from pre-existing memory.
> 
> I disagree. On a modern system with memory management, malloc can grab
> memory from the system, thus making it available to your process. Sure,
> physical memory will normally have to have been installed in the system,
> but conceptually you could have a malloc function that actually freezes
> the program, asks the user to build a new computer and turn it on,
> connects to a new service on that computer, and al

Re: The � debate

2014-05-10 Thread Rustom Mody
On Saturday, May 10, 2014 1:18:27 PM UTC+5:30, Steven D'Aprano wrote:
> Python assignment doesn't copy values.

Maybe our values differ ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Values and objects

2014-05-10 Thread Chris Angelico
On Sat, May 10, 2014 at 7:09 PM, Steven D'Aprano
 wrote:
> On Sat, 10 May 2014 17:21:56 +1000, Chris Angelico wrote:
>
> No offence Chris, but I think this demonstrates that learning C causes
> brain damage and prevents clear logical thinking :-P
>
> You're not passing a variable to a function. You're passing a pointer,
> which is itself a first-class value. It could be a pointer to ANYTHING,
> or NOTHING at all -- C doesn't even promise to ensure that it is a valid
> pointer, although more modern languages may. There's certainly no
> guarantee that it's a pointer to a variable. And you cannot create new
> variables -- C only allows variables to be created at compile time.
>
> The question is not, "Can I implement some aspects of first-class
> behaviour for variables by hand?" The question is, "Are variables treated
> as first class values in C?"

Ehh... good point. I admit my brain damage - which, I have to say, has
earned me a good portion of my life's salaries, so it's not useless :)
Okay. So variables are not first-class in C. I still think memory
blocks are pretty much first class, though; you can declare them at
compile time (usually as an array of char or pointers) or at run time
(with malloc or equivalent), and they can be passed to functions,
returned from functions, etc. The only limitation is that a generic
memory block doesn't maintain its size, so you can't distinguish
between a char[10] and a char[1024].

> Being able to manually pass pointers to variables about is not the same
> as having first class variables. It fails on the very first hurdle, "Are
> variables treated the same as other values?"
>
> How do I pass an int to a function? func(some_int)
>
> How do I pass a double to a function? func(some_double)
>
> How do I pass a bool to a function? func(some_bool)
>
> How do I pass a variable to a function? ptr = &some_variable; func(ptr)
>
> Does that look the same to you? The fact that you can do it at all is not
> sufficient to make it first class. It just makes it a work-around for the
> lack of first class variables in the language.

You can simply say func(&some_variable), but yes, there is that
difference. (This is how "out" parameters usually look in C. You stick
ampersands in front of things.) And that's still passing memory blocks
around, not variables.

>>> Rather than *creating* patches of memory, malloc merely allocates it
>>> from pre-existing memory.
>>
>> I disagree. On a modern system with memory management, malloc can grab
>> memory from the system, thus making it available to your process. Sure,
>> physical memory will normally have to have been installed in the system,
>> but conceptually you could have a malloc function that actually freezes
>> the program, asks the user to build a new computer and turn it on,
>> connects to a new service on that computer, and allocates memory from
>> there. As far as your program's concerned, malloc actually does (attempt
>> to) give you more room than you had.
>
> Ha, well I guess you got me there. Perhaps a less over the top example is
> that you're running in a VM, and malloc can request more information from
> the host (which presumably has unlimited memory). Still impractical, but
> theoretically possible.

Yeah. Completely impractical, but so is "Post-It Note Python" where
everything's done with physical strings and sheets of paper. Thought
experiments don't have to be performant :)

> Nevertheless, blocks of memory are not *first class* because you don't
> handle blocks of memory like other values. To make a new int variable,
> you declare it: "int foo". To make a new block of memory, there is no
> declaration "block foo". Rather, you call malloc() at runtime. And it
> might fail. "int foo" can never fail.

As I mentioned above, you can make a new block of memory with "char
foo[1234]". And that's where a lot of buffer overruns come from,
because someone thinks "1234 is *heaps* of space"... but sometimes you
really can know in advance how long something can be. (Maybe you're
about to ask a file to give you the next 1233 bytes of content.) In
this form, it's as safe as "int foo" - that is to say, safe unless
your stack overflows, in which case all bets are off anyway.

>>> Python variables aren't first-class either, but in fact we can get a
>>> bit closer to first-class than either C or Pascal.
>>>
>>> Creating new variables is trivial. Since they don't need to be
>>> declared, you create a new variable just by assigning to it:
>>>
>>> try:
>>> spam
>>> except NameError:
>>> spam = 23
>>
>> No no no, this is really creating them at compile time.
>
> It certainly isn't. Here's a slightly different demonstration of the same
> principle, this time inside a function to prove that there's nothing
> special about the global namespace:
>
>
> py> def demo():
> ... print('spam' in locals())
> ... spam = 23
> ... print('spam' in locals())
> ...
> py> demo()
> False
> True

Tell me, what may this function do in a compliant

Re: The � debate

2014-05-10 Thread Steven D'Aprano
On Sat, 10 May 2014 11:18:59 +0300, Marko Rauhamaa wrote:

> In Python,
> 
>x   is a variable, a memory slot that can be assigned to,


If your intention was to prove Ben Finney right, then you've done a 
masterful job of it. Python variables ARE NOT MEMORY SLOTS.

(Not even local variables, since that's an implementation detail which 
the language takes pains to hide from the caller. The abstraction leaks a 
bit, but not much.)



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


xmltodict - TypeError: list indices must be integers, not str

2014-05-10 Thread flebber
I am using xmltodict.

This is how I have accessed and loaded my file.

import xmltodict
document = open("/home/sayth/Scripts/va_benefits/20140508GOSF0.xml", "r")
read_doc = document.read()
xml_doc = xmltodict.parse(read_doc)

The start of the file I am trying to get data out of is.


  http://"; />
  


So thought I had it figured. Can access the elements of meeting and the 
elements of club such as by doing this.

In [5]: xml_doc['meeting']['club']['@abbrevname']
Out[5]: u'Gosford Race Club'

However whenever I try and access race in the same manner I get errors.

In [11]: xml_doc['meeting']['club']['race']['@id']
---
KeyError  Traceback (most recent call last)
 in ()
> 1 xml_doc['meeting']['club']['race']['@id']

KeyError: 'race'

In [12]: xml_doc['meeting']['race']['@id']
---
TypeError Traceback (most recent call last)
 in ()
> 1 xml_doc['meeting']['race']['@id']

TypeError: list indices must be integers, not str

why is accessing race @id any different to the access of club @abbrevname and 
how do I get it for race?

Thanks

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


Error while calling round() from future.builtins

2014-05-10 Thread Preethi
Hi,

I am new to python. I am getting an error "AttributeError: type object 
'Decimal' has no attribute 'from_float'" when I run the following in python 
prompt:

>>> from future.builtins import int, round
>>> int(round(5))
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/usr/lib/python2.6/site-packages/future/builtins/backports/newround.py", line 
32, in newround
d = Decimal.from_float(number).quantize(exponent,
AttributeError: type object 'Decimal' has no attribute 'from_float'

I am running this on Centos 6.5 which has python version 2.6.6
This is the output of 'pip freeze':

Django==1.6.4
Mezzanine==3.1.4
Pillow==2.4.0
South==0.8.4
bleach==1.4
django-appconf==0.6
django-compressor==1.3
filebrowser-safe==0.3.3
future==0.9.0
grappelli-safe==0.3.10
html5lib==0.999
iniparse==0.3.1
oauthlib==0.6.1
psycopg2==2.5.2
pycurl==7.19.0
pygpgme==0.1
pytz==2014.2
requests==2.2.1
requests-oauthlib==0.4.0
six==1.6.1
tzlocal==1.0
urlgrabber==3.9.1
yum-metadata-parser==1.1.2

This is the order in which I installed the above packages. (The box initially 
had python 2.6.6 installed)

yum install gcc python python-setuptools python-devel
yum install libjpeg-turbo-devel
python get-pip.py
pip install -U pip
pip install South django-compressor
pip install mezzanine
yum install postgresql93-server.x86_64
yum install postgresql-devel
sudo pip install psycopg2

What am I missing? Any help is greatly appreciated.

Thanks,
Preethi
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error while calling round() from future.builtins

2014-05-10 Thread Steven D'Aprano
On Sat, 10 May 2014 04:39:05 -0700, Preethi wrote:

> Hi,
> 
> I am new to python. I am getting an error "AttributeError: type object
> 'Decimal' has no attribute 'from_float'" when I run the following in
> python prompt:
> 
 from future.builtins import int, round 

I get an error when I try that:


py> from future.builtins import int, round
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named future.builtins


Perhaps you are using the third-party library "future"? 

https://pypi.python.org/pypi/future

If so, then I believe the library is buggy and you should report it to 
the Centos package maintainer. You might also manually install a more 
recent version of future.

Decimal.from_float was only added in 2.7, it is not available in 2.6.

https://docs.python.org/2/library/decimal.html#decimal.Decimal.from_float




-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: xmltodict - TypeError: list indices must be integers, not str

2014-05-10 Thread Peter Otten
flebber wrote:

> I am using xmltodict.
> 
> This is how I have accessed and loaded my file.
> 
> import xmltodict
> document = open("/home/sayth/Scripts/va_benefits/20140508GOSF0.xml", "r")
> read_doc = document.read()
> xml_doc = xmltodict.parse(read_doc)
> 
> The start of the file I am trying to get data out of is.
> 
>  date="2014-05-08T00:00:00" gearchanges="-1" stewardsreport="-1"
> gearlist="-1" racebook="0" postracestewards="0" meetingtype="TAB"
> rail="True" weather="Fine  " trackcondition="Dead  "
> nomsdeadline="2014-05-02T11:00:00" weightsdeadline="2014-05-05T16:00:00"
> acceptdeadline="2014-05-06T09:00:00" jockeydeadline="2014-05-06T12:00:00">
>  website="http://"; />
>  stage="Acceptances" distance="1600" minweight="55" raisedweight="0"
>   class="MDN   " age="~ " grade="0" weightcondition="HCP  
>   " trophy="0" owner="0" trainer="0" jockey="0" strapper="0"
>   totalprize="22000" first="12250" second="4250" third="2100"
>   fourth="1000" fifth="525" time="2014-05-08T12:30:00" bonustype="BX02
>" nomsfee="0" acceptfee="0" trackcondition="  " timingmethod=" 
>   " fastesttime="  " sectionaltime="  "
>   formavailable="0" racebookprize="Of $22000. First $12250, second $4250,
>   third $2100, fourth $1000, fifth $525, sixth $375, seventh $375, eighth
>   $375, ninth $375, tenth $375">
> 
> 
> So thought I had it figured. Can access the elements of meeting and the
> elements of club such as by doing this.
> 
> In [5]: xml_doc['meeting']['club']['@abbrevname']
> Out[5]: u'Gosford Race Club'
> 
> However whenever I try and access race in the same manner I get errors.
> 
> In [11]: xml_doc['meeting']['club']['race']['@id']
> 
---
> KeyError  Traceback (most recent call
> last)  in ()
> > 1 xml_doc['meeting']['club']['race']['@id']
> 
> KeyError: 'race'
> 
> In [12]: xml_doc['meeting']['race']['@id']
> 
---
> TypeError Traceback (most recent call
> last)  in ()
> > 1 xml_doc['meeting']['race']['@id']
> 
> TypeError: list indices must be integers, not str
> 
> why is accessing race @id any different to the access of club @abbrevname
> and how do I get it for race?

If I were to guess: there are multiple races per meeting, xmltodict puts 
them into a list under the "race" key, and you have to pick one:

>>> doc = xmltodict.parse("""\
... 
......
......
... 
... """)
>>> type(doc["meeting"]["race"])

>>> doc["meeting"]["race"][0]["@id"]
'first race'
>>> doc["meeting"]["race"][1]["@id"]
>>> 
>>>   
'second race'   

   

So 

xml_doc['meeting']['race'][0]['@id']

or

for race in xml_doc["meeting"]["race"]:
   print(race["@id"])

might work for you.

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


Fortran (Was: The "does Python have variables?" debate)

2014-05-10 Thread Roy Smith
In article ,
 Dennis Lee Bieber  wrote:

> On 08 May 2014 16:04:51 GMT, Steven D'Aprano
>  declaimed the following:
> 
> >Personally, I think that trying to be general and talk about "many other 
> >languages" is a failing strategy. Better to be concrete: C, Pascal, 
> >Algol, Fortran, VB (I think) are good examples of the "value in a box at 
> >a fixed location" model. Of those, Algol, Pascal and Fortran are either 
> >obsolete or legacy, and C is by far the most well-known by people here. 
> >(For some reason, few people seem to migrate from VB to Python.) Hence, 
> >"C-like".
> >
> 
>   Obsolete and Legacy? Fortran still receives regular standards updates
> (currently 2008, with the next revision due in 2015).


Ars Technica article a couple of days ago, about Fortran, and what is 
likely to replace it:

http://tinyurl.com/mr54p96
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error while calling round() from future.builtins

2014-05-10 Thread Jerry Hill
On Sat, May 10, 2014 at 7:39 AM, Preethi  wrote:
> future==0.9.0

It looks like that library is out of date.  The current version looks
to be 0.12.0, and it also looks like this bug was fixed in the 0.12.0
release.  I'd upgrade your version if at all possible.

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


How can this assert() ever trigger?

2014-05-10 Thread Albert van der Horst
I have the following code for calculating the determinant of
a matrix. It works inasfar that it gives the same result as an
octave program on a same matrix.

/ 

def determinant( mat ):
''' Return the determinant of the n by n matrix mat
i row j column
Destroys mat ! '''
#print "getting determinat of", mat
n=len(mat)
nom = 1.
if n == 1: return mat[0][0]
lastr = mat.pop()
jx=-1
for j in xrange(n):
   if lastr[j]:
   jx=j
   break
if jx==-1: return 0.
result = lastr[jx]
assert(result<>0.)
# Make column jx zero by subtracting a multiple of the last row.
for i in xrange(n-1):
pivot = mat[i][jx]
if 0. == pivot: continue
assert(result<>0.)
nom *= result   # Compenstate for multiplying a row.
for j in xrange(n):
mat[i][j] *= result
for j in xrange(n):
mat[i][j] -= pivot*lastr[j]
# Remove colunm jx
for i in xrange(n-1):
   x= mat[i].pop(jx)
   assert( x==0 )

if (n-1+jx)%2<>0: result = -result
det = determinant( mat )
assert(nom<>0.)
return result*det/nom

/-

Now on some matrices the assert triggers, meaning that nom is zero.
How can that ever happen? mon start out as 1. and gets multiplied
with a number that is asserted to be not zero.

Any hints appreciated.

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: How can this assert() ever trigger?

2014-05-10 Thread Peter Otten
Albert van der Horst wrote:

> I have the following code for calculating the determinant of
> a matrix. It works inasfar that it gives the same result as an
> octave program on a same matrix.
> 
> / 
> 
> def determinant( mat ):
> ''' Return the determinant of the n by n matrix mat
> i row j column
> Destroys mat ! '''
> #print "getting determinat of", mat
> n=len(mat)
> nom = 1.
> if n == 1: return mat[0][0]
> lastr = mat.pop()
> jx=-1
> for j in xrange(n):
>if lastr[j]:
>jx=j
>break
> if jx==-1: return 0.
> result = lastr[jx]
> assert(result<>0.)
> # Make column jx zero by subtracting a multiple of the last row.
> for i in xrange(n-1):
> pivot = mat[i][jx]
> if 0. == pivot: continue
> assert(result<>0.)
> nom *= result   # Compenstate for multiplying a row.
> for j in xrange(n):
> mat[i][j] *= result
> for j in xrange(n):
> mat[i][j] -= pivot*lastr[j]
> # Remove colunm jx
> for i in xrange(n-1):
>x= mat[i].pop(jx)
>assert( x==0 )
> 
> if (n-1+jx)%2<>0: result = -result
> det = determinant( mat )
> assert(nom<>0.)
> return result*det/nom
> 
> /-
> 
> Now on some matrices the assert triggers, meaning that nom is zero.
> How can that ever happen? mon start out as 1. and gets multiplied
> with a number that is asserted to be not zero.
> 
> Any hints appreciated.

Floating point precision is limited:

>>> x = 1.0
>>> for i in itertools.count():
... x *= .1
... assert x
... 
Traceback (most recent call last):
  File "", line 3, in 
AssertionError
>>> i
323


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


Re: How can this assert() ever trigger?

2014-05-10 Thread Ethan Furman

What happens if you run the same matrix through Octave?  By any chance, is nom 
just really, really small?

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


Re: How can this assert() ever trigger?

2014-05-10 Thread Gary Herron

On 05/10/2014 08:24 AM, Albert van der Horst wrote:

I have the following code for calculating the determinant of
a matrix. It works inasfar that it gives the same result as an
octave program on a same matrix.

/ 

def determinant( mat ):
 ''' Return the determinant of the n by n matrix mat
 i row j column
 Destroys mat ! '''
 #print "getting determinat of", mat
 n=len(mat)
 nom = 1.
 if n == 1: return mat[0][0]
 lastr = mat.pop()
 jx=-1
 for j in xrange(n):
if lastr[j]:
jx=j
break
 if jx==-1: return 0.
 result = lastr[jx]
 assert(result<>0.)
 # Make column jx zero by subtracting a multiple of the last row.
 for i in xrange(n-1):
 pivot = mat[i][jx]
 if 0. == pivot: continue
 assert(result<>0.)
 nom *= result   # Compenstate for multiplying a row.
 for j in xrange(n):
 mat[i][j] *= result
 for j in xrange(n):
 mat[i][j] -= pivot*lastr[j]
 # Remove colunm jx
 for i in xrange(n-1):
x= mat[i].pop(jx)
assert( x==0 )

 if (n-1+jx)%2<>0: result = -result
 det = determinant( mat )
 assert(nom<>0.)
 return result*det/nom

/-

Now on some matrices the assert triggers, meaning that nom is zero.
How can that ever happen? mon start out as 1. and gets multiplied
with a number that is asserted to be not zero.


Easily due to *underflow* precision trouble.  Your "result" may never be 
zero, but it can be very small.  Take the product of many of such tiny 
values, and the result can be less then the smallest value representable 
by a float, at which point it becomes zero.


To see this clearly, try this Python code:
>>> a = 1.0
>>> while a > 0:
...   a = a*1.0e-50
...   print(a)
...
1e-50
1e-100
1e-150
1e-200
1e-250
1e-300
0.0

Gary Herron







Any hints appreciated.

Groetjes Albert


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


Re: How can this assert() ever trigger?

2014-05-10 Thread Alain Ketterlin
alb...@spenarnc.xs4all.nl (Albert van der Horst) writes:

[...]
> Now on some matrices the assert triggers, meaning that nom is zero.
> How can that ever happen? mon start out as 1. and gets multiplied

[several times]

> with a number that is asserted to be not zero.

Finite precision. Try: 1.*1e-162*1e-162. Equals zero.

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


Re: How can this assert() ever trigger?

2014-05-10 Thread Albert van der Horst
In article <874n0xvd85@dpt-info.u-strasbg.fr>,
Alain Ketterlin   wrote:
>alb...@spenarnc.xs4all.nl (Albert van der Horst) writes:
>
>[...]
>> Now on some matrices the assert triggers, meaning that nom is zero.
>> How can that ever happen? mon start out as 1. and gets multiplied
>
>[several times]
>
>> with a number that is asserted to be not zero.
>
>Finite precision. Try: 1.*1e-162*1e-162. Equals zero.
>
>-- Alain.

Thanks you Alan and all others to point this out.
That was indeed the problem. Somehow I expected that floating
underflow would raise an exception, so I had a blind spot there.

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-10 Thread Simon Evans
I am new to Python, but my main interest is to use it to Webscrape. I have 
downloaded Beautiful Soup, and have followed the instruction in the 'Getting 
Started with Beautiful Soup' book, but my Python installations keep returning 
errors, so I can't get started. I have unzipped Beautiful Soup to a folder of 
the same name on my C drive, in accordance with the first two steps of page 12 
of the aforementioned publication, but proceeding to navigate to the program as 
in step three, re: "Open up the command line prompt and navigate to the folder 
where you have unzipped the folder as follows:
cd Beautiful Soup
python setup python install "

This returns on my Python 27 :
>>> cd Beautiful Soup
File "",line 1
cd Beautiful Soup
   ^
SyntaxError: invalid syntax
>>>

also I get:
>>> cd Beautiful Soup
SyntaxError: invalid syntax
>>>

to my IDLE Python 2.7 version, same goes for the Python 3.4 installations. 
Hope someone can help. 
Thanks in advance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-10 Thread Chris Angelico
On Sun, May 11, 2014 at 2:58 AM, Simon Evans  wrote:
> "Open up the command line prompt and navigate to the folder where you have 
> unzipped the folder as follows:
> cd Beautiful Soup
> python setup python install "

This would be the operating system command line, not Python's
interactive mode. Since you refer to a C drive, I'm going to assume
Windows; you'll want to open up "Command Prompt", or cmd.exe, or
whatever name your version of Windows buries it under. (Microsoft does
not make it particularly easy on you.) Since you have a space in the
name, you'll need quotes:

cd "c:\Beautiful Soup"

Then proceed as per the instructions.

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


NumPy, SciPy, & Python 3X Installation/compatibility issues

2014-05-10 Thread esawiek
Hi All--

Let me state at the start that I am new to Python. I am moving away from 
Fortran and Matlab to Python and I use all different types of numerical and 
statistical recipes in my work. I have been reading about NumPy and SciPy and 
could not find any definitive answers to my questions, below.  I had run into 
many mostly installation problems that I could never get NumPy or SciPy to work 
with Python 3.3 or newer.  I am using Windows7 64 bit OS. 
A few questions:
1.  What are the latest versions of NumPy and SciPy that are compatible 
with Python 3.3 or newer and Windows7 64 bit? 
2.  What is the best source to download and install them on my computer?
3.  Are they all installable on my OS w/o any major problems/addition?
4.  In the long run, would it be better to use UNIX instead of Windows, if 
I were to use Python for all of my research?
Thanks in advance. EK
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: NumPy, SciPy, & Python 3X Installation/compatibility issues

2014-05-10 Thread Chris Angelico
On Sun, May 11, 2014 at 3:07 AM,   wrote:
> 4.  In the long run, would it be better to use UNIX instead of Windows, 
> if I were to use Python for all of my research?

Yes. Absolutely yes. But that's because it's better to run Unix than
Windows regardless of all other considerations. :)

As a general rule, a Linux (I can't speak for other flavours of Unix,
but I expect they'll be mostly the same) system will tend to settle
into better performance the longer it keeps running, as long as it has
sufficient RAM. The things you use will tend to be in cache, but other
than that, nothing much changes as you seek toward infinite uptime.
Windows, on the other hand, tends to accumulate cruft; the longer you
keep the system running, the more RAM gets wasted in various nooks and
crannies. I can't be sure of whether it's the OS itself or an
application, but I do know that my Windows laptop sometimes needs to
be rebooted just because "stuff's feeling a bit sluggish", and none of
my Linux boxes are like that.

That said, though, my idea of uptime is measured in months. If you're
the sort of person who arrives at work, turns on the computer, uses it
for a day, and then turns it off and goes home, the difference gets a
lot smaller. (Unless you suspend/hibernate rather than actually
shutting down, in which case the difference gets bigger again.) I
still prefer a Unix system, though, because the worst messes I can get
myself into can usually be cured by SSH'ing in and killing some
process, which on Windows is both harder to do and less effective.

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


Re: NumPy, SciPy, & Python 3X Installation/compatibility issues

2014-05-10 Thread Никола Вукосављевић
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 10.5.2014 19:07, esaw...@gmail.com wrote:
> Hi All--
> 
> Let me state at the start that I am new to Python. I am moving away
> from Fortran and Matlab to Python and I use all different types of
> numerical and statistical recipes in my work. I have been reading
> about NumPy and SciPy and could not find any definitive answers to
> my questions, below.  I had run into many mostly installation
> problems that I could never get NumPy or SciPy to work with Python
> 3.3 or newer.  I am using Windows7 64 bit OS. A few questions: 1.
> What are the latest versions of NumPy and SciPy that are compatible
> with Python 3.3 or newer and Windows7 64 bit? 2.  What is the best
> source to download and install them on my computer? 3.Are they all
> installable on my OS w/o any major problems/addition? 4.  In the
> long run, would it be better to use UNIX instead of Windows, if I
> were to use Python for all of my research? Thanks in advance. EK
> 
For 64-bit Windows, I've had luck with installations from
http://www.lfd.uci.edu/~gohlke/pythonlibs/
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.19 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJTbl6WAAoJEB1x37R9kdwnVQ4QAMHRLmwKHKAKDiitrSlt/glo
szOMAcjVff4vjNYt5N0x2Rqr1e6vgte9NoGcOgKPJbR1GUYMphQK3pgbkPfxX2Cl
030MI2ir//0WiCYP80rsLJBgAv88vhWx/dKFpG8EeN7LEP6AkJflVsWKeET4ZGfU
p0S/L1n/pePpiNs15QwZ0LVvTu7u86ZSJuxkLQfznL53aJtl5ztPFgNfvgvbW56f
Dap9KruqhbkC1EZD/6ogBQUgDZS51o0Cv3UsXdZJD0W69elnGXLHmCTY4kUwCDSa
psY29aviZHf8RHn5cb/TWobbu5P5PRJx0PVoIRmE8/CDlQKfXny7wPaU6e6PgT0Y
hmnskuN0PBubDm1zfZgiolOa4g5VzVVuB/r/JRpnAw4nxq6tluHbhs/OfFjSEUPu
n3qA4nCTB2wI5cP32sy3Q87SJ33ZQR0Nc8wHOLDmhgyhox7699q/7yu1RLYUCXAS
VLaQ4WEIgH3xJKrmDjktwdDsC+HBlfZuHqUxpHS/rAi54ey8OLWWoBW4t4ZE2PTn
0FPEejNI526WrUS1G/MjoaFAI/usSjnoThERg8gCroAi89JjoE4B53BT4Z5ONhQU
APPfkCIlzW2WQslxXhuoJY2XWM4NMf/dOOfS60qCVZa3EQaX97xo2j96mKkR9bMO
TYrl2RUWjMetm8t8VFNO
=v+OK
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: NumPy, SciPy, & Python 3X Installation/compatibility issues

2014-05-10 Thread Stefan Behnel
esaw...@gmail.com, 10.05.2014 19:07:
> Let me state at the start that I am new to Python. I am moving away from 
> Fortran and Matlab to Python and I use all different types of numerical and 
> statistical recipes in my work. I have been reading about NumPy and SciPy and 
> could not find any definitive answers to my questions, below.  I had run into 
> many mostly installation problems that I could never get NumPy or SciPy to 
> work with Python 3.3 or newer.  I am using Windows7 64 bit OS. 
> A few questions:
> 1.What are the latest versions of NumPy and SciPy that are compatible 
> with Python 3.3 or newer and Windows7 64 bit? 
> 2.What is the best source to download and install them on my computer?
> 3.Are they all installable on my OS w/o any major problems/addition?
> 4.In the long run, would it be better to use UNIX instead of Windows, if 
> I were to use Python for all of my research?

I concur with Chris that Linux is generally a better choice than Windows,
if only to get a nicely preconfigured system that makes it easy to install
stuff. Especially for "research" (assuming we're talking about the same
thing). If you say that you're "moving away from Fortran" on Windows, then
I guess you're aware how clumsy low level software development can be on
that platform and how tricky it is to set up. That could be enough of a
reason to switch platforms (assuming that's really an option for you).

Ok, if you use only the IPython notebook for all your processing needs, you
may not notice the difference in terms of interface all that much, but in
that case, why stick with Windows in the first place? :)

If you decide to use Windows, try Anaconda. It's an all inclusive installer
that comes with pretty much all of your scientific processing tools in one
package:

http://docs.continuum.io/anaconda/

There's a Py3.3 version.

Stefan


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


Re: Fortran (Was: The "does Python have variables?" debate)

2014-05-10 Thread Terry Reedy

On 5/10/2014 9:42 AM, Roy Smith wrote:

In article ,
  Dennis Lee Bieber  wrote:



Obsolete and Legacy? Fortran still receives regular standards updates
(currently 2008, with the next revision due in 2015).


Ars Technica article a couple of days ago, about Fortran, and what is
likely to replace it:


What might *possibly* replace it.


http://tinyurl.com/mr54p96


The article is deficient in that it ignores the 20-year-old combination 
of python with fortran and the facts that the combination gives fortran 
a repl loop and that this combination has already somewhat replaced bare 
fortran.


--
Terry Jan Reedy

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


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-10 Thread Terry Reedy

On 5/10/2014 1:03 PM, Chris Angelico wrote:

On Sun, May 11, 2014 at 2:58 AM, Simon Evans  wrote:

"Open up the command line prompt and navigate to the folder where you have 
unzipped the folder as follows:
cd Beautiful Soup
python setup python install "


This would be the operating system command line, not Python's
interactive mode. Since you refer to a C drive, I'm going to assume
Windows; you'll want to open up "Command Prompt", or cmd.exe, or
whatever name your version of Windows buries it under. (Microsoft does
not make it particularly easy on you.)


On the All Programs / Start menu, look under Accessories. I have it 
pinned to my Win 7 task bar.


> Since you have a space in the name, you'll need quotes:


cd "c:\Beautiful Soup"


Not for Win 7, at least

C:\Users\Terry>cd \program files

C:\Program Files>

--
Terry Jan Reedy

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


Re: Values and objects

2014-05-10 Thread Ethan Furman

On 05/10/2014 02:32 AM, Chris Angelico wrote:


Tell me, what may this function do in a compliant Python?

def demo():
 ret = spam
 spam = 23
 return ret

In CPython, that'll raise UnboundLocalError, because the local
variable 'spam' does already exist, and currently has no value (no
object bound to it).


No, it does not exist -- or, more accurately, it does not exist *yet* but will.  The fact that there is a slot waiting 
for what will be spam is a cpython implementation detail.


And if you don't like that argument (although it is a perfectly sound and 
correct argument), think of the module name space:

ret = spam
spam = 23

will net you a simple NameError, because spam has not yet been created.



 If a compliant Python implementation is allowed
to have this return the value of a global or builtin spam, then I
would agree that you can create variables at run time.


See module example above.  This behavior is not allowed in functions for scope 
and sanity (mostly sanity) reasons.

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


Re: Values and objects

2014-05-10 Thread MRAB

On 2014-05-10 20:10, Ethan Furman wrote:

On 05/10/2014 02:32 AM, Chris Angelico wrote:


Tell me, what may this function do in a compliant Python?

def demo():
 ret = spam
 spam = 23
 return ret

In CPython, that'll raise UnboundLocalError, because the local
variable 'spam' does already exist, and currently has no value (no
object bound to it).


No, it does not exist -- or, more accurately, it does not exist *yet* but will. 
 The fact that there is a slot waiting
for what will be spam is a cpython implementation detail.

And if you don't like that argument (although it is a perfectly sound and 
correct argument), think of the module name space:

ret = spam
spam = 23

will net you a simple NameError, because spam has not yet been created.



 If a compliant Python implementation is allowed
to have this return the value of a global or builtin spam, then I
would agree that you can create variables at run time.


See module example above.  This behavior is not allowed in functions for scope 
and sanity (mostly sanity) reasons.


UnboundLocalError is like NameError, except that Python knows that the
name is local because somewhere in the function you're binding to that
name and you haven't said that it's global or nonlocal. Having a
different exception for that case makes it clearer to the user what the
problem is.
--
https://mail.python.org/mailman/listinfo/python-list


Question on Debugging a code line

2014-05-10 Thread subhabangalore
Dear Room,

I was trying to go through a code given in 
http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm[ Forward 
Backward is an algorithm of Machine Learning-I am not talking on that
I am just trying to figure out a query on its Python coding.]

I came across the following codes.

>>> states = ('Healthy', 'Fever')
>>> end_state = 'E'
>>> observations = ('normal', 'cold', 'dizzy')
>>> start_probability = {'Healthy': 0.6, 'Fever': 0.4}
>>> transition_probability = {
   'Healthy' : {'Healthy': 0.69, 'Fever': 0.3, 'E': 0.01},
   'Fever' : {'Healthy': 0.4, 'Fever': 0.59, 'E': 0.01},
   }
>>> emission_probability = {
   'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1},
   'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6},
   }

def fwd_bkw(x, states, a_0, a, e, end_st):
L = len(x)
fwd = []
f_prev = {} #THE PROBLEM 
# forward part of the algorithm
for i, x_i in enumerate(x):
f_curr = {}
for st in states:
if i == 0:
# base case for the forward part
prev_f_sum = a_0[st]
else:
prev_f_sum = sum(f_prev[k]*a[k][st] for k in states) ##
 
f_curr[st] = e[st][x_i] * prev_f_sum
 
fwd.append(f_curr)
f_prev = f_curr
 
p_fwd = sum(f_curr[k]*a[k][end_st] for k in states)

As this value was being called in prev_f_sum = sum(f_prev[k]*a[k][st] for k in 
states marked ## 
I wanted to know what values it is generating.
So, I had made the following experiment, after 
for i, x_i in enumerate(x): 
I had put print f_prev 
but I am not getting how f_prev is getting the values.

Here, 
x=observations,
states= states,
a_0=start_probability,
a= transition_probability,
e=emission_probability,
end_st= end_state

Am I missing any minor aspect?
Code is running fine. 

If any one of the esteemed members may kindly guide me.

Regards,
Subhabrata Banerjee. 



 
   

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


Re: The � debate

2014-05-10 Thread Ethan Furman

On 05/10/2014 02:05 AM, Rustom Mody wrote:

On Saturday, May 10, 2014 1:18:27 PM UTC+5:30, Steven D'Aprano wrote:


Python assignment doesn't copy values.


Maybe our values differ?


Obviously they do.  Yours are irrelevant for Python.  They could be, and probably are, useful when comparing and 
contrasting Python with other languages, or maybe when discussing a particular implementation of Python -- but when 
discussing the *language* of Python, your definition of value doesn't exist.


When learning a foreign human language most folks start at, and some stay at, the "think in native language, translate 
on the fly" mode.  And it probably works well enough to get by.  But that is not fluency.  Fluency is understanding the 
meaning behind the words, behind the sounds, and eventually being able to *think* in that other language.


If that is not your goal, fine;  please stop muddying other's understanding of 
how Python the language works.

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


Re: Values and objects

2014-05-10 Thread Ethan Furman

On 05/10/2014 12:22 PM, MRAB wrote:


UnboundLocalError is like NameError, except that Python knows that the
name is local because somewhere in the function you're binding to that
name and you haven't said that it's global or nonlocal. Having a
different exception for that case makes it clearer to the user what the
problem is.


Absolutely.  At one point NameError was raised in both cases, which could be 
very confusing to track down.

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


Re: NumPy, SciPy, & Python 3X Installation/compatibility issues

2014-05-10 Thread esawiek
On Saturday, May 10, 2014 1:07:33 PM UTC-4, esa...@gmail.com wrote:
> Hi All--
> 
> 
> 
> Let me state at the start that I am new to Python. I am moving away from 
> Fortran and Matlab to Python and I use all different types of numerical and 
> statistical recipes in my work. I have been reading about NumPy and SciPy and 
> could not find any definitive answers to my questions, below.  I had run into 
> many mostly installation problems that I could never get NumPy or SciPy to 
> work with Python 3.3 or newer.  I am using Windows7 64 bit OS. 
> 
> A few questions:
> 
> 1.What are the latest versions of NumPy and SciPy that are compatible 
> with Python 3.3 or newer and Windows7 64 bit? 
> 
> 2.What is the best source to download and install them on my computer?
> 
> 3.Are they all installable on my OS w/o any major problems/addition?
> 
> 4.In the long run, would it be better to use UNIX instead of Windows, if 
> I were to use Python for all of my research?
> 
> Thanks in advance. EK
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: NumPy, SciPy, & Python 3X Installation/compatibility issues

2014-05-10 Thread esawiek
On Saturday, May 10, 2014 1:07:33 PM UTC-4, esa...@gmail.com wrote:
> Hi All--
> 
> 
> 
> Let me state at the start that I am new to Python. I am moving away from 
> Fortran and Matlab to Python and I use all different types of numerical and 
> statistical recipes in my work. I have been reading about NumPy and SciPy and 
> could not find any definitive answers to my questions, below.  I had run into 
> many mostly installation problems that I could never get NumPy or SciPy to 
> work with Python 3.3 or newer.  I am using Windows7 64 bit OS. 
> 
> A few questions:
> 
> 1.What are the latest versions of NumPy and SciPy that are compatible 
> with Python 3.3 or newer and Windows7 64 bit? 
> 
> 2.What is the best source to download and install them on my computer?
> 
> 3.Are they all installable on my OS w/o any major problems/addition?
> 
> 4.In the long run, would it be better to use UNIX instead of Windows, if 
> I were to use Python for all of my research?
> 
> Thanks in advance. EK

Thank you all. I checked the website suggested in on of the replies and it 
looks promising. Because I want to use Num, SciPy, and Python on windows just 
to be familiar with them a little more, then I do plan to migrate to UNIX. I 
will let you posted on my progress. Thanks again. EK
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Values and objects

2014-05-10 Thread Terry Reedy

On 5/10/2014 3:10 PM, Ethan Furman wrote:

On 05/10/2014 02:32 AM, Chris Angelico wrote:


Tell me, what may this function do in a compliant Python?

def demo():
 ret = spam
 spam = 23
 return ret

In CPython, that'll raise UnboundLocalError,


Note:
>>> issubclass(UnboundLocalError, NameError)
True

I am not sure if adding the specificity is helpful or not.


because the local
variable 'spam' does already exist, and currently has no value (no
object bound to it).


No, it does not exist -- or, more accurately, it does not exist *yet*
but will.  The fact that there is a slot waiting for what will be spam
is a cpython implementation detail.

And if you don't like that argument (although it is a perfectly sound
and correct argument), think of the module name space:

ret = spam
spam = 23

will net you a simple NameError, because spam has not yet been created.


In other words, those two lines raise a NameError in either case.

--
Terry Jan Reedy

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


Re: NumPy, SciPy, & Python 3X Installation/compatibility issues

2014-05-10 Thread Mark H Harris

On 5/10/14 12:07 PM, esaw...@gmail.com wrote:

4.  In the long run, would it be better to use UNIX instead of Windows, if 
I were to use Python for all of my research?



I concur with Chris and Stefan. The *nix model is faster, cleaner, and 
more secure. I prefer gnu/linux, but mac os/x is also quite nice. Simply 
change... or, if you like, just switch.


I moved away from OS/2 and Windows in the late 1990s and have never 
looked back; no reason to use Windows what-so-ever.


You're question (in the long run) is important, to be fair. Because, in 
the short run there will be some learning curve, and there will be some 
conceptual porting as well as code porting to handle; not to mention 
apps. All critical apps from Windows, and most day-to-day apps have free 
libre counter-parts in the unix world, and most everyday apps have gnu 
counter parts and others. Just switch.


Proprietary code and systems will not survive the 21st century, you can 
be sure of that. 'We' can never allow another Microsoft to rule again; 
not google, nor canonical, nor oracle, nor anyone else. 'We' must have 
net neutrality, and software idea patents must die (world-wide).


Go gnu/linux

Go Python

Go away, Microsoft, go away Oracle.


marcus

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


Re: Values and objects

2014-05-10 Thread Terry Reedy

On 5/10/2014 3:22 PM, MRAB wrote:


UnboundLocalError is like NameError,


More specifically,
>>> isinstance(UnboundLocalError(), NameError)
True

This means that 'except NameError:' clauses written before the 
UnboundLocalError subclass was added still work and do not necessarily 
need to be modified. (I am allowing for the possibility that the body of 
the clause tries to separate the specific error from other NameErrors).


--
Terry Jan Reedy

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


Re: Question on Debugging a code line

2014-05-10 Thread MRAB

On 2014-05-10 20:27, subhabangal...@gmail.com wrote:

Dear Room,

I was trying to go through a code given in 
http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm[ Forward 
Backward is an algorithm of Machine Learning-I am not talking on that
I am just trying to figure out a query on its Python coding.]

I came across the following codes.


states = ('Healthy', 'Fever')
end_state = 'E'
observations = ('normal', 'cold', 'dizzy')
start_probability = {'Healthy': 0.6, 'Fever': 0.4}
transition_probability = {

'Healthy' : {'Healthy': 0.69, 'Fever': 0.3, 'E': 0.01},
'Fever' : {'Healthy': 0.4, 'Fever': 0.59, 'E': 0.01},
}

emission_probability = {

'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1},
'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6},
}

def fwd_bkw(x, states, a_0, a, e, end_st):
 L = len(x)
 fwd = []
 f_prev = {} #THE PROBLEM
 # forward part of the algorithm
 for i, x_i in enumerate(x):
 f_curr = {}
 for st in states:
 if i == 0:
 # base case for the forward part
 prev_f_sum = a_0[st]
 else:
 prev_f_sum = sum(f_prev[k]*a[k][st] for k in states) ##

 f_curr[st] = e[st][x_i] * prev_f_sum

 fwd.append(f_curr)
 f_prev = f_curr

 p_fwd = sum(f_curr[k]*a[k][end_st] for k in states)

As this value was being called in prev_f_sum = sum(f_prev[k]*a[k][st] for k in 
states marked ##
I wanted to know what values it is generating.
So, I had made the following experiment, after
for i, x_i in enumerate(x):
I had put print f_prev
but I am not getting how f_prev is getting the values.

Here,
x=observations,
states= states,
a_0=start_probability,
a= transition_probability,
e=emission_probability,
end_st= end_state

Am I missing any minor aspect?
Code is running fine.

If any one of the esteemed members may kindly guide me.

The values calculated in the inner loop are being put into the dict 
'f_curr'

and then, when that loop has completed, 'f_prev' is being bound to that
dict.

'f_curr' is bound to a new dict just before the inner loop, ready for
the new values.

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


Re: Values and objects

2014-05-10 Thread Devin Jeanpierre
On Sat, May 10, 2014 at 12:10 PM, Ethan Furman  wrote:
> On 05/10/2014 02:32 AM, Chris Angelico wrote:
>>
>>
>> Tell me, what may this function do in a compliant Python?
>>
>> def demo():
>>  ret = spam
>>  spam = 23
>>  return ret
>>
>> In CPython, that'll raise UnboundLocalError, because the local
>> variable 'spam' does already exist, and currently has no value (no
>> object bound to it).
>
>
> No, it does not exist -- or, more accurately, it does not exist *yet* but
> will.  The fact that there is a slot waiting for what will be spam is a
> cpython implementation detail.

The name of the exception is "UnboundLocalError". And the message says
that we referred to a "local variable".

Also see the language reference:

"When a name is not found at all, a NameError exception is raised. If
the name refers to a local variable that has not been bound, a
UnboundLocalError exception is raised. UnboundLocalError is a subclass
of NameError."

spam is referring to a local variable that has not been bound. This is
not an implementation detail.

> And if you don't like that argument (although it is a perfectly sound and
> correct argument), think of the module name space:
>
>
> ret = spam
> spam = 23
>
> will net you a simple NameError, because spam has not yet been created.

Because module level variables work differently from local variables.

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


Re: xmltodict - TypeError: list indices must be integers, not str

2014-05-10 Thread flebber
On Saturday, 10 May 2014 22:10:14 UTC+10, Peter Otten  wrote:
> flebber wrote:
> 
> 
> 
> > I am using xmltodict.
> 
> > 
> 
> > This is how I have accessed and loaded my file.
> 
> > 
> 
> > import xmltodict
> 
> > document = open("/home/sayth/Scripts/va_benefits/20140508GOSF0.xml", "r")
> 
> > read_doc = document.read()
> 
> > xml_doc = xmltodict.parse(read_doc)
> 
> > 
> 
> > The start of the file I am trying to get data out of is.
> 
> > 
> 
> >  
> > date="2014-05-08T00:00:00" gearchanges="-1" stewardsreport="-1"
> 
> > gearlist="-1" racebook="0" postracestewards="0" meetingtype="TAB"
> 
> > rail="True" weather="Fine  " trackcondition="Dead  "
> 
> > nomsdeadline="2014-05-02T11:00:00" weightsdeadline="2014-05-05T16:00:00"
> 
> > acceptdeadline="2014-05-06T09:00:00" jockeydeadline="2014-05-06T12:00:00">
> 
> >
> >   website="http://"; />
> 
> >
> >   stage="Acceptances" distance="1600" minweight="55" raisedweight="0"
> 
> >   class="MDN   " age="~ " grade="0" weightcondition="HCP  
> 
> >   " trophy="0" owner="0" trainer="0" jockey="0" strapper="0"
> 
> >   totalprize="22000" first="12250" second="4250" third="2100"
> 
> >   fourth="1000" fifth="525" time="2014-05-08T12:30:00" bonustype="BX02
> 
> >" nomsfee="0" acceptfee="0" trackcondition="  " timingmethod=" 
> 
> >   " fastesttime="  " sectionaltime="  "
> 
> >   formavailable="0" racebookprize="Of $22000. First $12250, second $4250,
> 
> >   third $2100, fourth $1000, fifth $525, sixth $375, seventh $375, eighth
> 
> >   $375, ninth $375, tenth $375">
> 
> > 
> 
> > 
> 
> > So thought I had it figured. Can access the elements of meeting and the
> 
> > elements of club such as by doing this.
> 
> > 
> 
> > In [5]: xml_doc['meeting']['club']['@abbrevname']
> 
> > Out[5]: u'Gosford Race Club'
> 
> > 
> 
> > However whenever I try and access race in the same manner I get errors.
> 
> > 
> 
> > In [11]: xml_doc['meeting']['club']['race']['@id']
> 
> > 
> 
> ---
> 
> > KeyError  Traceback (most recent call
> 
> > last)  in ()
> 
> > > 1 xml_doc['meeting']['club']['race']['@id']
> 
> > 
> 
> > KeyError: 'race'
> 
> > 
> 
> > In [12]: xml_doc['meeting']['race']['@id']
> 
> > 
> 
> ---
> 
> > TypeError Traceback (most recent call
> 
> > last)  in ()
> 
> > > 1 xml_doc['meeting']['race']['@id']
> 
> > 
> 
> > TypeError: list indices must be integers, not str
> 
> > 
> 
> > why is accessing race @id any different to the access of club @abbrevname
> 
> > and how do I get it for race?
> 
> 
> 
> If I were to guess: there are multiple races per meeting, xmltodict puts 
> 
> them into a list under the "race" key, and you have to pick one:
> 
> 
> 
> >>> doc = xmltodict.parse("""\
> 
> ... 
> 
> ......
> 
> ......
> 
> ... 
> 
> ... """)
> 
> >>> type(doc["meeting"]["race"])
> 
> 
> 
> >>> doc["meeting"]["race"][0]["@id"]
> 
> 'first race'
> 
> >>> doc["meeting"]["race"][1]["@id"]  
> >>>   
> >>>   
> 
> 'second race' 
>   
>
> 
> 
> 
> So 
> 
> 
> 
> xml_doc['meeting']['race'][0]['@id']
> 
> 
> 
> or
> 
> 
> 
> for race in xml_doc["meeting"]["race"]:
> 
>print(race["@id"])
> 
> 
> 
> might work for you.

Thanks so much Peter, yes both worked indeed. 

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


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-10 Thread Chris Angelico
On Sun, May 11, 2014 at 4:39 AM, Terry Reedy  wrote:
>> Since you have a space in the name, you'll need quotes:
>>
>>
>> cd "c:\Beautiful Soup"
>
>
> Not for Win 7, at least
>
> C:\Users\Terry>cd \program files
>
> C:\Program Files>

Huh, good to know.

Unfortunately, Windows leaves command-line parsing completely up to
the individual command/application, so some will need quotes, some
won't, and some will actually do very different things if you put an
argument in quotes (look at START and FIND). There is a broad
convention that spaces in file names get protected with quotes, though
(for instance, tab completion will put quotes around them), so it's
not complete chaos.

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


Re: Values and objects

2014-05-10 Thread Chris Angelico
On Sun, May 11, 2014 at 5:10 AM, Ethan Furman  wrote:
> And if you don't like that argument (although it is a perfectly sound and
> correct argument), think of the module name space:
>
>
> ret = spam
> spam = 23
>
> will net you a simple NameError, because spam has not yet been created.

What about this, though:

ret = int
int = 23

That will *not* net you a NameError, because 'int' exists in an outer
scope (builtins). You can create a new module-scope variable and it
will immediately begin to shadow a builtin; you can delete that
variable and it will immediately cease to shadow that builtin. That's
the difference I'm talking about. With function-local variables, they
all have to exist (as other responses confirmed, that *is* a language
guarantee), even though some of them aren't bound to anything yet.

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


Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues)

2014-05-10 Thread Chris Angelico
On Sun, May 11, 2014 at 6:14 AM, Mark H Harris  wrote:
> Proprietary code and systems will not survive the 21st century, you can be
> sure of that. 'We' can never allow another Microsoft to rule again; not
> google, nor canonical, nor oracle, nor anyone else. 'We' must have net
> neutrality, and software idea patents must die (world-wide).
>
> Go gnu/linux
>
> Go Python
>
> Go away, Microsoft, go away Oracle.

Actually, I'm not so sure of that. If all free software worked only
with itself, was GPL3'd to prevent non-free software from using it,
etc, the world would be a worse place. Part of what makes free
software so tempting is that it happily interacts with *everything*,
not just other free software. Otherwise, there'd be a massive gulf
between the Apple world, the Microsoft world, and the GNU world, with
minimal interoperability between them.

Instead, what we have is a world in which Python can be used to write
closed-source software, LibreOffice Writer will happily open a
Microsoft Word document, Samba communicates with Windows computers,
libc can be linked to non-free binaries, etc, etc, etc. Yes, that
means the open source community can't wield its weight against
closed-source. I am glad of that. Freedom means letting people choose
to be free, not forcing them to be free. (Don't get me wrong, forcing
someone to be free is better than forcing them to be enslaved. I don't
mind a preinstalled LibreOffice on someone's computer as much as I
would a preinstalled MS Office. But actually letting people choose is
better.)

Proprietary code and systems will continue to exist for as long as
people are willing to buy them. Maybe we'll see a shift away from
non-free desktop software, but cloud and mobile are still very much
the domain of closed source at the moment. There might be a shift
toward free mobile platforms, but I doubt the cloud will change. You
can run anything you like on a server, and people will use it if it's
useful. For one very very obvious example: you and I are both posting
from Gmail. :)

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


Re: Values and objects

2014-05-10 Thread Ethan Furman

On 05/10/2014 04:18 PM, Chris Angelico wrote:

On Sun, May 11, 2014 at 5:10 AM, Ethan Furman  wrote:

And if you don't like that argument (although it is a perfectly sound and
correct argument), think of the module name space:


ret = spam
spam = 23

will net you a simple NameError, because spam has not yet been created.


What about this, though:

ret = int
int = 23

That will *not* net you a NameError, because 'int' exists in an outer
scope (builtins). You can create a new module-scope variable and it
will immediately begin to shadow a builtin; you can delete that
variable and it will immediately cease to shadow that builtin. That's
the difference I'm talking about. With function-local variables, they
all have to exist (as other responses confirmed, that *is* a language
guarantee), even though some of them aren't bound to anything yet.


Well, with function variables they have to exist *when you use them*. ;)

This seems like more of a scoping issue than a "can we create variables in 
Python" issue.

I am curious, though, what other python's do with respect to function variables.

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


Re: Values and objects

2014-05-10 Thread Chris Angelico
On Sun, May 11, 2014 at 11:28 AM, Ethan Furman  wrote:
> Well, with function variables they have to exist *when you use them*. ;)
>
> This seems like more of a scoping issue than a "can we create variables in
> Python" issue.
>
> I am curious, though, what other python's do with respect to function
> variables.

Variables exist in scope. Apart from assembly language, where
registers have universal scope, every language I know of has some
concept of scope. (REXX is very different from most, in that
"PROCEDURE EXPOSE" isn't at all your classic notion of scoping, but
there's still the concept that there can be two variables with the
same name.) When you create one, you create it in a particular scope,
and that's how it must be.

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


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-10 Thread Dave Angel

On 05/10/2014 07:23 PM, Chris Angelico wrote:

 There is a broad
convention that spaces in file names get protected with quotes, though
(for instance, tab completion will put quotes around them), so it's
not complete chaos.



"Complete chaos" is a pretty good description, especially since MS 
decided to make the default directory paths for many things have 
embedded spaces in them.  And to change the rules from version to 
version of the OS.  And it's not just the cmd line that's inconsistent; 
 some exec function variants liberally parse unquoted names looking for 
some file that happens to match the first few 'words" of the string.


I once debugged a customer problem (without actually seeing the 
machine), and told tech support to ask him if he had a file in the root 
directory called "program.exe."  I turned out to be right, and the 
customer was sure I must have hacked into his machine.


There was a bug in our code (missing quotes), masked by the liberality 
of the function I mentioned, that wasn't visible till such a file existed.


The customer symptom?  Our code complained that the linker couldn't be 
found.


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


Re: Values and objects

2014-05-10 Thread Steven D'Aprano
On Sun, 11 May 2014 09:18:34 +1000, Chris Angelico wrote:

> On Sun, May 11, 2014 at 5:10 AM, Ethan Furman 
> wrote:
>> And if you don't like that argument (although it is a perfectly sound
>> and correct argument), think of the module name space:
>>
>>
>> ret = spam
>> spam = 23
>>
>> will net you a simple NameError, because spam has not yet been created.
> 
> What about this, though:
> 
> ret = int
> int = 23
>
> That will *not* net you a NameError, because 'int' exists in an outer
> scope (builtins). You can create a new module-scope variable and it will
> immediately begin to shadow a builtin; you can delete that variable and
> it will immediately cease to shadow that builtin. 

Yes. That's part of documented language behaviour to do with scoping 
search paths. See below.


> That's the difference
> I'm talking about. With function-local variables, they all have to exist
> (as other responses confirmed, that *is* a language guarantee), even
> though some of them aren't bound to anything yet.

Define "exist". 

Just because a slot exists waiting for a variable, doesn't mean that the 
variable which would use that slot exists. Like dicts and lists, function 
locals() are over-allocated: CPython pre-allocates slots for locals based 
on compile-time information, even if those locals are never bound to and 
therefore don't exist:

def demo():
if False:
x = 23
print x  # Fails

You're trying to argue that because there is a slot for x, the variable x 
exists. But I think that is the wrong definition of "exists". If you have 
a list L = [], would you say that L[4] exists because the array is over-
allocated and already has (at least) four slots waiting to be used, but 
L[100] doesn't because it isn't over-allocated that much? What if the pre-
allocation rules change? What if an implementation decides not to bother 
pre-allocating empty lists?

What if an implementation pre-allocates a random number of array slots? 
Would you be comfortable saying that there is a 25% chance that L[4] 
exists and a 1% chance that L[100] exists?

In both these cases, array slots in a list or dict, and locals, we risk 
mistaking implementation details for language features. I think you 
actually are making this error when it comes to locals.

When talking about the implementation, it is relevant to discuss the 
existence of slots. But when talking about the language, about features 
visible from Python code such as variables (a.k.a. name bindings), local 
slots don't matter. Jython and IronPython don't (so far as I know) use 
them, and locals() happens to be writable. Here's an example from 
IronPython 2.6:

>>> def test():
... if False: spam = None
... d = locals()
... d['spam'] = 23
... return spam
...
>>> test()
23


And a similar example from Jython 2.5:

>>> def test():
... locals()['spam'] = 42
... return spam
... spam = None
...
>>> test()
42


Neither example works in CPython, you get an UnboundLocalError, but 
whether or not locals() is writable is is *explicitly* documented as an 
implementation detail. How implementations store local variables (in a 
dictionary like globals, slots, in the Cloud) is up to them, so long as 
the implementation follows the scoping rules.

Python determines whether a variable is local or not at compile-time:

(1) If a function contains a binding operation (assignment; import; del) 
on that variable, then the variable is defined as a local unless 
otherwise declared as a global or nonlocal (Python 3 only).

(2) Otherwise it is not a local.

(3) Outside of a function, it is a global whether declared as such or not.

(4) Variables (names) don't exist until they have a value bound to them.

I guess you want to challenge #4, and say that local variables exist as 
soon as the slot that holds them exists. I think that is wrong. And 
besides, even CPython 2 doesn't always use slots for locals: consider 
what happens when you use import * inside a function. And try running 
this function in both 2.7 and 3.3 and see if you can explain the 
difference:

def test():
if False: x = None
exec("x = 1")
return x


But I digress.

Name look-ups for locals look only in the local scope. Name lookups for 
everything else search the chain nonlocals:globals:builtins.

Name bindings (assignments, del, imports) for locals write only to the 
local scope. For globals they write only to the global scope and for 
nonlocals they write to the nearest enclosing nonlocal scope that already 
defines that variable.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Values and objects

2014-05-10 Thread Steven D'Aprano
On Sat, 10 May 2014 14:03:11 -0700, Devin Jeanpierre wrote:

> On Sat, May 10, 2014 at 12:10 PM, Ethan Furman 
> wrote:
>> On 05/10/2014 02:32 AM, Chris Angelico wrote:
>>>
>>>
>>> Tell me, what may this function do in a compliant Python?
>>>
>>> def demo():
>>>  ret = spam
>>>  spam = 23
>>>  return ret
>>>
>>> In CPython, that'll raise UnboundLocalError, because the local
>>> variable 'spam' does already exist, and currently has no value (no
>>> object bound to it).
>>
>>
>> No, it does not exist -- or, more accurately, it does not exist *yet*
>> but will.  The fact that there is a slot waiting for what will be spam
>> is a cpython implementation detail.
> 
> The name of the exception is "UnboundLocalError". And the message says
> that we referred to a "local variable".
> 
> Also see the language reference:
> 
> "When a name is not found at all, a NameError exception is raised. If
> the name refers to a local variable that has not been bound, a
> UnboundLocalError exception is raised. UnboundLocalError is a subclass
> of NameError."
> 
> spam is referring to a local variable that has not been bound. This is
> not an implementation detail.

Of course not. What is an implementation detail is that there is a slot 
waiting to be filled for it, just like Ethan said. It's the existence of 
pre-allocated slots for locals which is an implementation detail, not 
whether a name is treated as local or not.


>> And if you don't like that argument (although it is a perfectly sound
>> and correct argument), think of the module name space:
>>
>>
>> ret = spam
>> spam = 23
>>
>> will net you a simple NameError, because spam has not yet been created.
> 
> Because module level variables work differently from local variables.

But that is an implementation detail. IronPython and Jython use an 
ordinary dict for local variable namespaces, just like globals. Consider 
this example from Jython:

>>> spam = 
>>> def modify(namespace):
... namespace['spam'] = 42
...
>>> def demo():
... modify(locals())
... spam = spam
... return spam
...
>>> demo()
42



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Values and objects

2014-05-10 Thread Chris Angelico
On Sun, May 11, 2014 at 1:17 PM, Steven D'Aprano
 wrote:
> But that is an implementation detail. IronPython and Jython use an
> ordinary dict for local variable namespaces, just like globals. Consider
> this example from Jython:
>
 spam = 
 def modify(namespace):
> ... namespace['spam'] = 42
> ...
 def demo():
> ... modify(locals())
> ... spam = spam
> ... return spam
> ...
 demo()
> 42

All you're proving here is that, in some Pythons, locals() is
writeable. What happens if you remove the "spam = spam" line? Would
demo() not then return spam from the global scope, because the
variable does not exist at local scope? Every example you've shown is
simply giving a value to something that you've created by the normal
method of having an assignment inside the function.

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


Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues)

2014-05-10 Thread Nelson Crosby
I also believe in this more 'BSD-like' view, but from a business point of view. 
No one is going to invest in a business that can't guarantee against piracy, 
and such a business is much less likely to receive profit (see Ardour).

Don't get me wrong - I love free software. It's seriously awesome to she what a 
community can do. But at the same time, some people want to earn a living from 
writing code. That is simply not possible without proprietary software. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues)

2014-05-10 Thread Rustom Mody
On Sunday, May 11, 2014 9:46:06 AM UTC+5:30, Nelson Crosby wrote:
> I also believe in this more 'BSD-like' view, but from a business point of 
> view. No one is going to invest in a business that can't guarantee against 
> piracy, and such a business is much less likely to receive profit (see 
> Ardour).
> 
> 
> 
> Don't get me wrong - I love free software. It's seriously awesome to she what 
> a community can do. But at the same time, some people want to earn a living 
> from writing code. That is simply not possible without proprietary software.

Whenever this (kind of) debate arises people talk of 'Free' vs 'OpenSource'
which then becomes an rms vs esr debate.
It seems to me that esr gets more press than is his due and the more 
significant ideological difference between rms and Torvalds gets neglected.

rms started working on hurd before Linus was a CS student. 
Its taken him a good 20 years to admit the mistake
http://en.wikipedia.org/wiki/GNU_Hurd#cite_note-fsf-future-of-freedom-12

I believe that he still does not get it - that the mistakes were political more
than technical.

By contrast,
- the Linux kernel targeting hardware for which it was never intended
- perl running equally on DOS and unix, (with all due respect python, ruby etc 
just followed the lead)
- Samba talking to Windows as though it were Windows itself

all show that some amount of guerrilla mindset is necessary 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Values and objects

2014-05-10 Thread Steven D'Aprano
On Sun, 11 May 2014 13:30:03 +1000, Chris Angelico wrote:

> On Sun, May 11, 2014 at 1:17 PM, Steven D'Aprano
>  wrote:
>> But that is an implementation detail. IronPython and Jython use an
>> ordinary dict for local variable namespaces, just like globals.
>> Consider this example from Jython:
>>
> spam = 
> def modify(namespace):
>> ... namespace['spam'] = 42
>> ...
> def demo():
>> ... modify(locals())
>> ... spam = spam
>> ... return spam
>> ...
> demo()
>> 42
> 
> All you're proving here is that, in some Pythons, locals() is writeable.
> What happens if you remove the "spam = spam" line? Would demo() not then
> return spam from the global scope, 

Yes, this. See my previous email, and take careful note of Rule #2: in 
the absence of a binding operation, variables are not treated as local.

> because the variable does not exist at local scope? 

No to this. Consider this example:


>>> spam = 
>>> def modify(namespace):
... namespace['spam'] = 42
...
>>> def demo2():
... assert 'spam' not in locals()
... modify(locals())
... assert 'spam' in locals()
... return spam
...
>>> demo2()



This proves that the spam variable *does* exist in locals, but it is not 
seen because the "return spam" doesn't check the local scope, so it sees 
the global spam.

Sadly, the version of Jython I have doesn't provide a working dis module, 
but if it did I expect it would show the equivalent of what CPython does: 
the first version uses LOAD_FAST to look up "spam", and the second 
version used LOAD_GLOBAL (a misnomer since it doesn't *just* look up 
globals).


> Every example you've shown is simply giving a value to
> something that you've created by the normal method of having an
> assignment inside the function.

Nonsense. Look at the original examples again, more closely. Here they 
are again, this time with comments:

def test():
if False: spam = None  # Dead code, never executed.
d = locals()
d['spam'] = 23  # Not a normal assignment.
return spam

def test():
locals()['spam'] = 42  # Not a normal assignment.
return spam
spam = None  # Dead code.


and from my reply to Devin:

def modify(namespace):
namespace['spam'] = 42

def demo():
modify(locals())  # Not an ordinary assignment.
spam = spam  # Where does the initial value of spam come from?
return spam


The *only* purpose of the dead code in the two test() functions is to 
force the compiler to use LOAD_FAST (or equivalent) rather than 
LOAD_GLOBAL. But they aren't ever executed. At no time do I use normal 
name binding assignment to create local variables. In the demo() 
function, if I expand the line "spam = spam" out:

temp = spam  # Look up of spam occurs first.
spam = temp  # Binding occurs second.

the difficulty should be even more obvious. Where does the value of spam 
come from before the binding?

The answer is that it comes from writing directly to the namespace (a 
dict). There is no fixed slot for spam waiting for a value, because 
Jython and IronPython don't use fixed slots. There's only a dict.

If we were using globals, it would be be more obvious what was going on, 
and there would be no argument about whether or not a variable exists 
before you give it a value. The answer would be, of course it doesn't 
exist before it has a value. Python declarations (whether implicit or 
explicit) don't create variables, they just instruct the compiler how to 
perform lookups on them.

# Global scope
print spam  # fails, because there is no spam variable yet
"spam" in globals()  # returns False
globals()['spam'] = 42  # now it exists
spam = spam  # a no-op
print spam


It's only because CPython is special, and locals() is special, that the 
equivalent code is indeterminate inside functions.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Values and objects

2014-05-10 Thread Chris Angelico
On Sun, May 11, 2014 at 3:11 PM, Steven D'Aprano
 wrote:
> Nonsense. Look at the original examples again, more closely. Here they
> are again, this time with comments:
>
> def test():
> if False: spam = None  # Dead code, never executed.
> d = locals()
> d['spam'] = 23  # Not a normal assignment.
> return spam
>
> def test():
> locals()['spam'] = 42  # Not a normal assignment.
> return spam
> spam = None  # Dead code.
>
>
> The *only* purpose of the dead code in the two test() functions is to
> force the compiler to use LOAD_FAST (or equivalent) rather than
> LOAD_GLOBAL.

In a C-like language, locals are created by a declaration, and
assigned a value separately. In Python, locals are created by the
presence of assignment within the function, which in simple cases
coincides with giving the value to it; but guarding the assignment
with "if False" prevents the giving of the value, while still being an
assignment for the sake of creating a local variable. Same if the
assignment happens further down, or even in the same statement ("spam
= spam"). It's still an assignment, so it has the declarative effect
of telling the compiler "this is now local, unless declared
global/nonlocal". It's that declaration that creates the variable, not
changing locals().

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


Re: Values and objects

2014-05-10 Thread Rustom Mody
On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote:
> 
> Personally, I don't imagine that there ever could be a language where 
> variables were first class values *exactly* the same as ints, strings, 
> floats etc. Otherwise, how could you tell the difference between a 
> function which operated on the variable itself, and one which operated on 
> the value contained by the value?

Its standard fare in theorem proving languages -
see eg twelf: https://www.cs.cmu.edu/~fp/papers/cade99.pdf
where the distinction is made between variables in the meta-language (ie twelf 
itself)
and variables in the the object theory

What you mean by *exactly* the same mean, I am not sure...

Also I note that I was not meaning first-classness of variables in C in that
literal sense.  Its just I consider them more first-class than say Pascal but 
less than say Lisp.

[The wikipedia link that Chris posted links to an article that makes the claim 
that
firstclassness is not really defined but can be used in a vague/relative way ]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues)

2014-05-10 Thread Mark H Harris

On 5/10/14 11:16 PM, Nelson Crosby wrote:

I also believe in this more 'BSD-like' view, but from a business
point of view. No one is going to invest in a business that can't
guarantee against piracy, and such a business is much less likely
to receive profit (see Ardour).

Don't get me wrong - I love free software. It's seriously awesome
to see what a community can do. But at the same time, some people want
to earn a living from writing code. That is simply not possible
without proprietary software.



That's just the point...

The twenty-first century is not going to be about making money by moving
bits around a network, nor about making money writing code. It is going
to be about making money|living (whatever that means) by leveraging free 
networking (think libre box) and by leveraging free (as in libre) 
software and libre software engineering.


In other words, no longer are coders going to make a living writing 
proprietary code; rather, coders are going to make a living leveraging 
their skill writing libre software (in the specialized problem domain 
needing their resources --- free agents, have skill, will travel, or 
connect).


So, I go to work for some technical scientific research outfit that just 
got a federal grant for yadda yadda... and I bring in my toolkit|toobox 
(julia, haskell, python, C++ &c whatever) and I make a living coding 
within that specialized domain.  I don't market the app (& they don't 
either).  The killer app in the 21st century IS the unix distro 
(gnu/linux), and the toolbox is (mine, or yours).


We are going to stop purchasing software across the board, and we are 
going to share. In the process we are going to make our livings with our 
skills, services, innovations towards specialized problem domains 
through leveraged technical specialty, and by working together to better 
the whole.


This is already occurring.


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


Re: Values and objects

2014-05-10 Thread Ethan Furman

[accidentally went off-list; sorry]

On 05/10/2014 02:03 PM, Devin Jeanpierre wrote:


spam is referring to a local variable that has not been bound. This is
not an implementation detail.


The implementation detail is that in cpython there is a spot already reserved for what will be the 'spam' variable, as 
opposed to the module level where no such spots are reserved.



Because module level variables work differently from local variables.


Not by language definition.  There are pythons where modifying function locals works, but the working or not-working is 
not a language guarantee.


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


Re: Values and objects

2014-05-10 Thread Ethan Furman

On 05/10/2014 10:22 PM, Chris Angelico wrote:

It's that declaration that creates the variable, not
changing locals().


A Python variable is a name bound to a value (and values, of course, are objects).  If you don't have both pieces, you 
don't have a Python variable.


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


Re: [Python-Dev] Values and objects

2014-05-10 Thread Chris Angelico
[ I think you meant for this to go to python-list, not python-dev.
Sending this to python-list. ]

On Sun, May 11, 2014 at 3:27 PM, Ethan Furman  wrote:
> Seriously though, error messages are chosen to provide a simple and clear
> description that will help the user track down what went wrong, not for
> enshrining in exact detail the language semantics.  Would you really rather
> have:
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 2, in func
> UnboundLocalError: the name 'not_here' does not yet exist as you have not
> yet assigned anything to it so there is currently no variable by that name
> although at some point (in the future of this function, or perhaps in a
> branch that has been passed and did not execute) you will or did assign
> something to it so it will exist in the future of this function or may exist
> at this point in a future run of this function.
>
> or:
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 2, in func
> UnboundLocalError: local variable 'not_here' referenced before assignment

The way I'd say it is: The error text should be brief, and can leave
stuff out, but should not actively *conflict* with language semantics.
So if it says there's a local variable that hasn't been assigned, I
would expect it to mean that there is, according to language
semantics, a local variable that can be in a state of
not-being-assigned to. If that's not the case, the message definitely
needs to be changed, because it's actively misleading.

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


Re: Fortran (Was: The "does Python have variables?" debate)

2014-05-10 Thread Mark H Harris

On 5/10/14 8:42 AM, Roy Smith wrote:

Ars Technica article a couple of days ago, about Fortran, and what is
likely to replace it:

http://tinyurl.com/mr54p96



uhm, yeeah!

'Julia' is going to give everyone a not so small run for competition; 
justifiably so,  not just against FORTRAN.


Julia is Matlab and  R, Python, Lisp, Scheme; all rolled together on 
steroids. Its amazing as a dynamic language, and its fast, like 
lightning fast as well as multiprocessing (parallel processing) at its 
core. Its astounding, really.


Its number concept is unified, BigFloats are by default arbitrary 
precision with full scientific and transcendental functions built-in, 
everything complex just works, and did I mention its fast? The 
bench-marks are within 2x of C across the boards;  makes Matlab look 
like a rock, and is well ahead of python (NumPy SciPy) for technical 
computing.


Julia is still very much beta in my opinion but its maturing fast. Its 
open free (libre) and cross platform and did I mention it flatout 
screams? Not only will it replace FORTRAN completely if things keep 
progressing, but also Matlab, Mathematica, NumPy, & SciPy (and others). 
Keep your eye on her fellows.


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


Re: Question on Debugging a code line

2014-05-10 Thread subhabangalore
On Sunday, May 11, 2014 12:57:34 AM UTC+5:30, subhaba...@gmail.com wrote:
> Dear Room,
> 
> 
> 
> I was trying to go through a code given in 
> http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm[ Forward 
> Backward is an algorithm of Machine Learning-I am not talking on that
> 
> I am just trying to figure out a query on its Python coding.]
> 
> 
> 
> I came across the following codes.
> 
> 
> 
> >>> states = ('Healthy', 'Fever')
> 
> >>> end_state = 'E'
> 
> >>> observations = ('normal', 'cold', 'dizzy')
> 
> >>> start_probability = {'Healthy': 0.6, 'Fever': 0.4}
> 
> >>> transition_probability = {
> 
>'Healthy' : {'Healthy': 0.69, 'Fever': 0.3, 'E': 0.01},
> 
>'Fever' : {'Healthy': 0.4, 'Fever': 0.59, 'E': 0.01},
> 
>}
> 
> >>> emission_probability = {
> 
>'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1},
> 
>'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6},
> 
>}
> 
> 
> 
> def fwd_bkw(x, states, a_0, a, e, end_st):
> 
> L = len(x)
> 
> fwd = []
> 
> f_prev = {} #THE PROBLEM 
> 
> # forward part of the algorithm
> 
> for i, x_i in enumerate(x):
> 
> f_curr = {}
> 
> for st in states:
> 
> if i == 0:
> 
> # base case for the forward part
> 
> prev_f_sum = a_0[st]
> 
> else:
> 
> prev_f_sum = sum(f_prev[k]*a[k][st] for k in states) ##
> 
>  
> 
> f_curr[st] = e[st][x_i] * prev_f_sum
> 
>  
> 
> fwd.append(f_curr)
> 
> f_prev = f_curr
> 
>  
> 
> p_fwd = sum(f_curr[k]*a[k][end_st] for k in states)
> 
> 
> 
> As this value was being called in prev_f_sum = sum(f_prev[k]*a[k][st] for k 
> in states marked ## 
> 
> I wanted to know what values it is generating.
> 
> So, I had made the following experiment, after 
> 
> for i, x_i in enumerate(x): 
> 
> I had put print f_prev 
> 
> but I am not getting how f_prev is getting the values.
> 
> 
> 
> Here, 
> 
> x=observations,
> 
> states= states,
> 
> a_0=start_probability,
> 
> a= transition_probability,
> 
> e=emission_probability,
> 
> end_st= end_state
> 
> 
> 
> Am I missing any minor aspect?
> 
> Code is running fine. 
> 
> 
> 
> If any one of the esteemed members may kindly guide me.
> 
> 
> 
> Regards,
> 
> Subhabrata Banerjee.

Dear Sir,
Thank you for your kind reply. I will check. 
Regards,
Subhabrata Banerjee. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Values and objects

2014-05-10 Thread Marko Rauhamaa
Rustom Mody :

> On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote:
>> 
>> Personally, I don't imagine that there ever could be a language where
>> variables were first class values *exactly* the same as ints,
>> strings, floats etc.
>
> [...]
>
> What you mean by *exactly* the same mean, I am not sure...

Lisp variables (symbols) are on an equal footing with other objects.
IOW, lisp variables are objects in the heap.


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


Re: Free vs proprietary (was Re: NumPy, SciPy, & Python 3X Installation/compatibility issues)

2014-05-10 Thread Mark H Harris

On 5/10/14 6:35 PM, Chris Angelico wrote:


Instead, what we have is a world in which Python can be used to write
closed-source software, LibreOffice Writer will happily open a
Microsoft Word document, Samba communicates with Windows computers,
libc can be linked to non-free binaries, etc, etc, etc. Yes, that
means the open source community can't wield its weight against
closed-source.


Its not open source that's the big deal. Its freedom that's the big 
deal. Many have latched onto open source because its efficient. But that 
was the wrong reason to latch onto it!  Libre software is the ONLY way 
to fight NSA GCHQ. Libre software is the ONLY way to ensure privacy and 
interoperability --- its a huge paradox.


Libre software and libre Internet are absolutely paramount for the 21st 
century. I may not live to see it fully, but I have absolutely no doubt 
that its coming. There is going to be one whopping paradigm shift Chris.



marcus

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


Re: Values and objects

2014-05-10 Thread Steven D'Aprano
On Sat, 10 May 2014 22:42:13 -0700, Ethan Furman wrote:

> On 05/10/2014 10:22 PM, Chris Angelico wrote:
>> It's that declaration that creates the variable, not changing locals().
> 
> A Python variable is a name bound to a value (and values, of course, are
> objects).  If you don't have both pieces, you don't have a Python
> variable.

+1

Well said.


-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Values and objects

2014-05-10 Thread Rustom Mody
On Sunday, May 11, 2014 11:51:59 AM UTC+5:30, Marko Rauhamaa wrote:
> Rustom Mody :
> 
> 
> 
> > On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote:
> 
> >> 
> 
> >> Personally, I don't imagine that there ever could be a language where
> >> variables were first class values *exactly* the same as ints,
> >> strings, floats etc.
> >
> > [...]
> >
> > What you mean by *exactly* the same mean, I am not sure...
> 
> 
> 
> Lisp variables (symbols) are on an equal footing with other objects.
> IOW, lisp variables are objects in the heap.

But is a symbol a variable??
Sure, by providing a data-structure symbol, lisp provides one of 
the key building blocks for developing language processing systems.

However I would argue that a variable is not a merely a symbol (identifier
in more usual programming language-speak) but a relation between 
identifiers/symbols
and some 'rhs'

For an (interpreted?) language like python, rhs is naturally value/object
For a C like language it is memory.

[Just invoking the standard denotational semantics fare:
Env : Symbol → Value for interpreted languages
For 'compiled' languages
Env : Symbol → Location (at compile time)
Store : Location → Value  (at run time)
-- 
https://mail.python.org/mailman/listinfo/python-list