Re: refresing the edited python function

2013-08-18 Thread dieter
Sudheer Joseph  writes:

> I have been using ipython and ipython with qtconsole and working on a code 
> with functions. Each time I make a modification in function  
>
> I have to quit IPTHON console (in both with and with out qt console ) and 
> reload the function freshly. If I need to see the changed I made in the 
> function. I tried below options
> del function name
>
> import the module again  by issuing "from xxx.py import yy"
> import xxx.py
> make changes
> reload(xxx.py)
> this
>  works only if the the function in the code has same name as the code. 
> But even this do not reflect the changes made by editing the code.
> So what is the standard way to update the function for further tests after an 
> edit?

Getting changes into a running application is difficult.
Python has not been designed to make this easy.

The "reload" above is one partial way to achieve something like this.
The "reload" causes the module to be reloaded. If you have changed
the modules code, these changes will be reflected *inside* the reloaded
module. However, other modules may have imported objects from
this module (as  in your "from xxx.py import yy"). To see changes
in those objects, they, too, must repeat the import (otherwise,
they continue to use the old, unchanged object).

There is an additional approach, used e.g. by "plone.reload".
In this approach, the objects are modified "in place". All usage
points of the modified object will see changes.
However, there are (quite severe) limitations to what changes
can be made "in place". Thus, this, too, does not give a complete
solution.

In simple cases, one of those approaches can avoid a restart
after modifications. However, in general, a restart is required.

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


ANN: rom 0.18 - Redis object mapper for Python

2013-08-18 Thread Josiah Carlson
Hey everyone,

As time progresses, so does my Redis object mapper.

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

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

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

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

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

Thank you,
 - Josiah

#--- 0.18

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

[added] LGPL 3 licensing option.
#--- 0.16

[added] Thanks to a feature request from https://github.com/jrsmith ,
Boolean
column support is now available.
[added] DateTime, Date, and Time column types because I was already adding
Boolean columns.
#--- 0.15

[fixed] Thanks to https://github.com/MickeyKim who fixed Json columns so
that
they round-trip after multiple saves.
-- 
http://mail.python.org/mailman/listinfo/python-list


refresing the edited python function

2013-08-18 Thread Sudheer Joseph


Hi,
I have been using ipython and ipython with qtconsole and working on a code with 
functions. Each time I make a modification in function  

I have to quit IPTHON console (in both with and with out qt console ) and 
reload the function freshly. If I need to see the changed I made in the 
function. I tried below options
del function name

import the module again  by issuing "from xxx.py import yy"
import xxx.py
make changes
reload(xxx.py)
this
 works only if the the function in the code has same name as the code. 
But even this do not reflect the changes made by editing the code.
So what is the standard way to update the function for further tests after an 
edit?
with best regards,
Sudheer 
 
***
Sudheer Joseph 
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India
POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.in...@gmail.com;sudheer.jos...@yahoo.com
Web- http://oppamthadathil.tripod.com
***-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need somebody schmardter than me

2013-08-18 Thread Gene Heskett
On Sunday 18 August 2013 19:30:43 Chris Angelico did opine:

> On Sun, Aug 18, 2013 at 9:48 PM, Gene Heskett  wrote:
> >> import time
> > 
> > That of course goes near the top of the script.
> > 
> >> time.sleep(1.5)
> > 
> > I'll see if I can see a sensible place to add this one.
> 
> The import doesn't have to happen near the top of the script; it's an
> executable statement like any other. If you want to keep it near the
> time.sleep() call, that'll work fine. It's up to you to decide what
> goes where.
> 
> ChrisA

Actually, I just found the authors names in the manpage.  They wrote this 
thing back in Ubuntu Hardy 8.04 LTS days, so I have posted a note and a 
screen shot pix to them as I am now convinced its a Hardy to Lucid thing.

Thank you for taking the time to try & sort me, I know most have better 
things to do.

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

All things are possible, except for skiing through a revolving door.
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about crypto

2013-08-18 Thread Roy Smith
In article ,
 Anthony Papillion  wrote:

> I've just started working with the Crypto library and I've already run
> into a wall even though I'm following a tutorial. Basically, I'm trying
> to encrypt a string using AES in CBC mode. Here is the code:
> 
> from Crypto import AES

You don't say exactly what module you're using.  I'm assuming 
https://www.dlitz.net/software/pycrypto/api/current/, yes?

> import hashlib
> 
> text_to_encrypt = 'This is a super secret encrypted message, yo!'
> key = '0123456789abcdef'
> mode = AES.MODE_CBC
> encryptor = AES.new(key, mode)
> 
> ciphertext = encryptor.encrypt(text)
> 

There's a good explanation of CBC in Wikipedia:
 
http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher-block_
chaining_.28CBC.29

In a nutshell, AES-CBC works is to break the input up into 16-byte 
blocks.  Each 16-byte block of input plaintext is encrypted to yield a 
16-byte block of ciphertext.  This 16-byte ciphertext block is also fed 
forward into the encryption step for the next block.

The IV is just the feed-forward block used for the first step.  So, it 
has to be the same size as the cipher block (i.e. 16 bytes).

AES can have different length keys (128, 192, or 256 bits), but the size 
of the cipher block is always 256 bits.  This can get confusing because 
most people just use a 256 bit key and incorrectly assume that the key 
size and block size are somehow related.  They're not.  When you say:

> When I run the code above, I am told that the IV must be 16 bytes long.
> I'm assuming that the IV (I know that means "Initialization Vector") is
> either the key OR something else I can set.

you're making that mistake.  The key can't (in general) be used as the 
IV.  In this particular case, you happen to have picked a key length 
which is the same as the block length, but that's just coincidence.

What you need to do is pick a 16 byte (256 bit) IV.

> Does anyone see what is wrong with the code above and could suggest 
> ways to make it work? I've spent the last 45 minutes googling around 
> and nothing comes up specific to my problem.

45 minutes is nothing when trying to understand crypto :-)

I've never used this particular module, but from the docs, I think what 
you want to do is:

iv = "SpamSpamSpamSpam"
encryptor = AES.new(key, mode, iv)

Keep in mind that the receiver will need the iv to decrypt your message.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about crypto

2013-08-18 Thread Skip Montanaro
> When I run the code above, I am told that the IV must be 16 bytes long.
> I'm assuming that the IV (I know that means "Initialization Vector") is
> either the key OR something else I can set. But I don't know how or what
> to do.

Does this Stack Overflow thread help?  It looks to me like you aren't
defining an initialization vector at all.

http://stackoverflow.com/questions/14716338/pycrypto-how-does-the-initialization-vector-work

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


Question about crypto

2013-08-18 Thread Anthony Papillion
I've just started working with the Crypto library and I've already run
into a wall even though I'm following a tutorial. Basically, I'm trying
to encrypt a string using AES in CBC mode. Here is the code:

from Crypto import AES
import hashlib

text_to_encrypt = 'This is a super secret encrypted message, yo!'
key = '0123456789abcdef'
mode = AES.MODE_CBC
encryptor = AES.new(key, mode)

ciphertext = encryptor.encrypt(text)

When I run the code above, I am told that the IV must be 16 bytes long.
I'm assuming that the IV (I know that means "Initialization Vector") is
either the key OR something else I can set. But I don't know how or what
to do.

Does anyone see what is wrong with the code above and could suggest ways
to make it work? I've spent the last 45 minutes googling around and
nothing comes up specific to my problem.

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


Re: Need somebody schmardter than me

2013-08-18 Thread Chris Angelico
On Sun, Aug 18, 2013 at 9:48 PM, Gene Heskett  wrote:
>> import time
>
> That of course goes near the top of the script.
>
>> time.sleep(1.5)
>
> I'll see if I can see a sensible place to add this one.

The import doesn't have to happen near the top of the script; it's an
executable statement like any other. If you want to keep it near the
time.sleep() call, that'll work fine. It's up to you to decide what
goes where.

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


Re: Need somebody schmardter than me

2013-08-18 Thread Gene Heskett
On Sunday 18 August 2013 16:38:52 Roy Smith did opine:

> In article ,
>  Gene Heskett  wrote:
> 
> [much that doesn't appear to have anything to do with Python elided]
> 
> > When cheese runs this camera, there is a several second delay while
> > cheese is apparently talking to it to establish the correct output
> > format before cheese starts displaying its output, so I am wondering
> > if an initialization time delay might be the fix,
> 
> In general, when you have some sort of synchronization problem, i.e.,
> "this piece of code must not start running until that other thing is
> completed", sticking in a time delay is:
> 
> 1) Almost always the wrong thing to do.
> 
> 2) Very often the most simple solution.
> 
> How it can simultaneously be both of these is left as an exercise for
> the reader :-)
> 
Oh Loverly...

> > but I haven't a clue about how to go about that in python
> 
> import time

That of course goes near the top of the script.

> time.sleep(1.5)

I'll see if I can see a sensible place to add this one.
> will sleep for 1.5 seconds.

Thanks.  Its likely I'll be back because now that I think about it, that 
first line I quoted is quite likely from the function itself, and doesn't 
serve to establish the context of the call, hence the actual arguments to 
it.

Its one of those cases where, if the function were to also echo the 
arguments it was handed, the troubleshooting would be a lot more 
straightforward because you could then see the error causer right up front.

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

Automobile, n.:
A four-wheeled vehicle that runs up hills and down pedestrians.
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: log incoming ip/porrt connections

2013-08-18 Thread D. Xenakis
This monitors also ip/port of incoming udp packets?
Or just tcp after a connection has been enstablished?
If i dont make any sense, plz correct me. Not much experience with networking 
here :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Local variable in a closure

2013-08-18 Thread Terry Reedy

On 8/18/2013 6:44 AM, Dave Angel wrote:

w.w.mil...@googlemail.com wrote:


Is f local or not?
http://pastebin.com/AKDJrbDs


Please have a little respect, and include the source in your message.
You managed quite nicely to keep it small, but you put it in an obscure
place that some people won't be able to reach, and that might not
survive for the archives.

def multiplier(f):
 def times(n):
 # is f local?
 nonlocal f
 f=f+1
 # if not, why is it here?
 print("Locals: ",locals())


Because nonlocal names are not in the global dict and the devs wanted 
globals() + locals() to report all accessible names, rather than add 
nonlocals() or leave them invisible.



 return n*f
 return times

times2 = multiplier(2)
print(times2(4)) # 3X4=12
print(times2(4)) # 4X4=16

Inside function times, the variable 'f' is a free variable, not a local.
  You can prove that to yourself by adding a dis.dis(times) just before
the "return times" statement.  Here's how it begins:

   7   0 LOAD_DEREF   0 (f)
   3 LOAD_CONST   1 (1)
   6 BINARY_ADD
   7 STORE_DEREF  0 (f)

In the dis.dis listing, the LOAD_DEREF and STORE_DEREF opcodes are
referring to free variables, the LOAD_FAST is referring to a local, and
the LOAD_GLOBAL is referring to a global.

The locals() function is just over-simplifying.  it's only a convenience
function, not what I would consider part of the language,


I think this is a good way to look at it.


and it wasn't apparently deemed necessary to have a separate function

> for debugging free varaibles.

One should think of 'locals' as meaning 'non_globals', which was exactly 
true when there were no non-global, non-local names. When closures were 
first added, such names were only readable. There was a long debate over 
what term to use for the keyword that would allow rebinding the names in 
outer functions. 'Nonlocal' is, at best, the least bad of the options 
considered.


In standard usage, the terms 'free' and 'bound' are context dependent.
https://en.wikipedia.org/wiki/Free_variable
Within a function or class body, all global variables are non-local and 
free, just like 'nonlocals'.


--
Terry Jan Reedy

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


Re: Need somebody schmardter than me

2013-08-18 Thread Roy Smith
In article ,
 Gene Heskett  wrote:

[much that doesn't appear to have anything to do with Python elided]

> When cheese runs this camera, there is a several second delay while cheese 
> is apparently talking to it to establish the correct output format before 
> cheese starts displaying its output, so I am wondering if an initialization 
> time delay might be the fix,

In general, when you have some sort of synchronization problem, i.e., 
"this piece of code must not start running until that other thing is 
completed", sticking in a time delay is:

1) Almost always the wrong thing to do.

2) Very often the most simple solution.

How it can simultaneously be both of these is left as an exercise for 
the reader :-)

> but I haven't a clue about how to go about that in python

import time
time.sleep(1.5)

will sleep for 1.5 seconds.
-- 
http://mail.python.org/mailman/listinfo/python-list


Need somebody schmardter than me

2013-08-18 Thread Gene Heskett
Greetings all;

I am trying to make a machine vision kit of modules work in linuxcnc, which 
uses a lot of python for scripts and gui controls in the user interface.

This is on a Ubu 10.04.4 LTS install, which because linuxcnc is intimately 
married to an RTAI equipt kernel version, has not been updated past 
2.6.32-12x-RTAI.  Those patches are very invasive but a 3.8.something 
version is being worked on as we speak.

But in the meantime, in an effort to debug the failure of the camera 
application to work WITH linuxcnc, I ran the debug level up to maximum to 
see if I might find the first point of failure, and get this on the console 
when linuxcnc is launched from the cli:


Xlib.protocol.request.QueryExtension
parse error?
unable to instantiate [/dev/video0]



Then it reverts to the normal traceback reporting the same thing but 
quoting the line numbers of the two scripts that led to the failed call.

/dev/video0 exists, is created when the usb cable from the camera is 
plugged in, and the program "cheese" can display this cameras output just 
fine using /dev/video0 as the src device.

When cheese runs this camera, there is a several second delay while cheese 
is apparently talking to it to establish the correct output format before 
cheese starts displaying its output, so I am wondering if an initialization 
time delay might be the fix, but I haven't a clue about how to go about 
that in python despite my copying the list for what, a year or more now?

So, where should I start?

Heck, maybe I might learn a bit of python while running this one down. ;-)

Thanks all.

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

>From 0 to "what seems to be the problem officer" in 8.3 seconds.
-- Ad for the new VW Corrado
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
 law-abiding citizens.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to I do this in Python ?

2013-08-18 Thread Ganesh Pal
Hi Steven ,

Firstly thanks for responding to the question and also guiding me on how to
post the question in the right order ( general to least important order )

Please find the comments >>> inline

On Fri, 16 Aug 2013 11:51:32 +0530, Ganesh Pal wrote:

> My goal is to create various kinds of files like sparse, regular
> ,directories, hard and symlinks etc
> what would be the best way to do achieve this ?

Use your shell, such as bash or csh or equivalent. For simple tasks like
that, it will solve the problem much more simply than Python.

There are three good reasons for doing this in Python:

- "This is only a small part of a larger Python application."

- "I'm doing this to learn how to use Python."

- "I really hate my shell."

But of you just want to get the job done, and don't care what language
you use, use the shell.


Now, having said that, I'm going to assume you have a good reason to use
Python:

>>>  You  have  hit the nail on the head  - The main goal there was to
learn python and avoid using shell commands as much as possible  , I want
to avoid shell and use Python even if its costly.

Example : I don' want to create sparse files using  dd   command ( #dd
if=/dev/zero of=sparse-file bs=1 count=1 seek=1024k ) If  the same can be
done  fseek .

 But I guess we might have to d


> Case (2) :
>
> Is there a better way to create the files in Python other than using
> sub process module and running dd command as shown below ..
>
> Example :
>
> # creating sparse File
>  sparse_path = os.path.join(path,'sparsefiles')
>  os.makedirs(sparse_path)
>  os.chdir(sparse_path)
>  sparsefiles = "dd if=/dev/zero of=sp1 count=0 bs=1 seek=10G"
>  process_0 = subprocess.Popen(sparsefiles, stdout=subprocess.PIPE,
> stderr=subprocess.PIPE, shell=True)
>
> # Creating Regular files
>  Regular_path = os.path.join(path,'regularfiles')
>  os.makedirs(Regular_path)
>  os.chdir(Regular_path)
>  regularfiles = " dd if=/dev/urandom of=file1 count=0 bs=1 seek=10"
>  process_1 = subprocess.Popen(regularfiles, stdout=subprocess.PIPE,
> stderr=subprocess.PIPE, shell=True)

What do you mean by "better"? There's probably nothing that will be
faster at rapidly copying bytes from one file to another than dd. But not
with a blocksize of 1 byte at a time. It's more usual to set bs=512 or
bs=1024.

Oh, I see you're not actually writing anything to the file (count=0). In
that case, instead of using dd, you should use touch.

I'm not sure that shell=True is a good idea.

In Python, to create a new empty file, setting its contents to empty if
it already exists:

open("filename", "w").close()


That will open the file, creating it if it doesn't exist, emptying it if
it does, then close it.

To touch a file without emptying it:

open("filename", "a").close()


To make a sparse file, assuming your file system supports it, I believe
you actually have to write at least one byte to the file:

f = open('foo', 'w')
f.seek(1)
f.write('\0')
f.close()

>>>   Thanks for the suggestion on creating empty files and  they worked
fine . I was today playing with the temp-file  module to create  temporary
files and directories ,
 Iam yet to explore it completely, but in current context , I had a
quick question using temp-file module is its  possible to create empty
 temporary files and save them on disk in the user-defined path ?
 If  " yes "  then can this also be an alternative and does this
have any drawback  ?


On Fri, Aug 16, 2013 at 4:29 PM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> Hi Ganesh, and welcome!
>
> Unfortunately, you ask your questions in reverse order. The most general
> (and important) question comes last, and the least important first, so
> I'm going to slice-and-dice your post and answer from most general to
> least.
>
>
> On Fri, 16 Aug 2013 11:51:32 +0530, Ganesh Pal wrote:
>
> > My goal is to create various kinds of files like sparse, regular
> > ,directories, hard and symlinks etc
> > what would be the best way to do achieve this ?
>
> Use your shell, such as bash or csh or equivalent. For simple tasks like
> that, it will solve the problem much more simply than Python.
>
> There are three good reasons for doing this in Python:
>
> - "This is only a small part of a larger Python application."
>
> - "I'm doing this to learn how to use Python."
>
> - "I really hate my shell."
>
> But of you just want to get the job done, and don't care what language
> you use, use the shell.
>
>
> Now, having said that, I'm going to assume you have a good reason to use
> Python:
>
>
> > Case (2) :
> >
> > Is there a better way to create the files in Python other than using
> > sub process module and running dd command as shown below ..
> >
> > Example :
> >
> > # creating sparse File
> >  sparse_path = os.path.join(path,'sparsefiles')
> >  os.makedirs(sparse_path)
> >  os.chdir(sparse_path)
> >  sparsefiles = "dd if=/dev/zero of=sp1 co

Re: Encapsulation unpythonic?

2013-08-18 Thread Joshua Landau
On 17 August 2013 17:17, Steven D'Aprano
 wrote:
> On Sat, 17 Aug 2013 05:26:32 -0700, fsaldan1 wrote:
>> how do I
>> deal with the fact that other programmers can easily alter the values of
>> members of my classes?
> ...
> If they insist on messing with your private single-underscore
> _attributes, you can't stop them, but that's okay, you don't have to be
> sympathetic when they shoot their foot off. Just slap them with a large
> halibut[1] and laugh.

I know I've cropped your points but I just want to mention here that
the only reason to monkey-patch code in these ways where you'd want to
stop them is when the alternative is *worse*. It's like removing railings from
a cliff to stop people hitting the bars.
-- 
http://mail.python.org/mailman/listinfo/python-list


crawling/parsing a webpage based on dynamic javascript

2013-08-18 Thread bruce
Hi.

Looking at using python/cerely/twisted to test in parsing a test site. Also
looking at being able to parse a site created using dynamic javascript.

I've got test apps to parse a site, but I'm interested in getting a better
understanding of using multi-thread/multi-processing approaches to spin out
as many fetch processes as possible.

At the same time, I'm interested in understanding a bit better what's used
for parsing the javascript pages in the py world.

Also, rather than just point me to something like "scrapy", I'm actually
interested in finding someone who's done this that I can talk to.

Heck, for the right person, I'll even toss some cash your way!!

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


Re: Local variable in a closure

2013-08-18 Thread Dave Angel
w.w.mil...@googlemail.com wrote:

> Is f local or not?
> http://pastebin.com/AKDJrbDs

Please have a little respect, and include the source in your message. 
You managed quite nicely to keep it small, but you put it in an obscure
place that some people won't be able to reach, and that might not
survive for the archives.

def multiplier(f):
def times(n):
# is f local?
nonlocal f
f=f+1
# if not, why is it here?
print("Locals: ",locals())
return n*f   
return times

times2 = multiplier(2)
print(times2(4)) # 3X4=12
print(times2(4)) # 4X4=16

Inside function times, the variable 'f' is a free variable, not a local.
 You can prove that to yourself by adding a dis.dis(times) just before
the "return times" statement.  Here's how it begins:

  7   0 LOAD_DEREF   0 (f) 
  3 LOAD_CONST   1 (1) 
  6 BINARY_ADD   
  7 STORE_DEREF  0 (f) 


In the dis.dis listing, the LOAD_DEREF and STORE_DEREF opcodes are
referring to free variables, the LOAD_FAST is referring to a local, and
the LOAD_GLOBAL is referring to a global.

The locals() function is just over-simplifying.  it's only a convenience
function, not what I would consider part of the language, and it wasn't
apparently deemed necessary to have a separate function for debugging
free varaibles.

-- 
DaveA


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


Re: Local variable in a closure

2013-08-18 Thread Ian Kelly
f is nonlocal to times(), local to multiplier().  As the docs for the
locals() function say, "Free variables are returned by locals() when
it is called in function blocks, but not in class blocks."

On Sun, Aug 18, 2013 at 3:41 AM,   wrote:
> Is f local or not?
> http://pastebin.com/AKDJrbDs
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Local variable in a closure

2013-08-18 Thread Chris Angelico
On Sun, Aug 18, 2013 at 10:41 AM,   wrote:
> Is f local or not?
> http://pastebin.com/AKDJrbDs

With something that short, it'd be easier to simply paste it straight
into your post, rather than having it off elsewhere. But to answer
your question: It is its own kind of beast. You can play around with
the dis.dis() function (start with "import dis", which is not just
"import this" with an accent) in the interactive interpreter, as an
effective way of finding out what actually happens. In my testing, the
opcodes for retrieving and updating 'f' are LOAD_DEREF and
STORE_DEREF, different from LOAD_FAST/STORE_FAST as used for locals,
and LOAD_GLOBAL/STORE_GLOBAL for globals. In normal usage, nonlocal
variables are most like local variables, but they happen to span one
level of function nesting. So they're still basically locals, hence
they appear in locals(). At least, that's my understanding of it.

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


Local variable in a closure

2013-08-18 Thread w . w . milner
Is f local or not?
http://pastebin.com/AKDJrbDs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .split() Qeustion

2013-08-18 Thread wxjmfauth
Le dimanche 18 août 2013 01:30:14 UTC+2, Gregory Ewing a écrit :
> wxjmfa...@gmail.com wrote:
> 
> > Na  + Cl   -->   NaCl
> 
> > 
> 
> > the chemist combines *one mole* of sodium and *one
> 
> > mole* of chlorine to get *one mole* of sodium chloride
> 
> > 
> 
> > It's independent of the number of "particles" in a mole.
> 
> 
> 
> The actual number chosen for the unit is arbitrary, but
> 
> number of particles is still the central issue. The
> 
> important thing is to have the *same* number of particles
> 
> of Na and Cl.
> 
> 
> 
> Weight only comes into it because it's totally impractical
> 
> to count particles. And the particular number 6.02e23 is
> 
> chosen because it happens to give a convenient relationship
> 
> between number of particles and grams. If chemists had
> 
> decided to use ounces instead, the number would be different.
> 
> 
> 
> -- 
> 
> Greg




"The actual number chosen for the unit is arbitrary, but
number of particles is still the central issue."

No.


"The important thing is to have the *same* number of particles
of Na and Cl."

Yes.
And it is precisely for that reason, a chemist works in "mole
arithetic".

Same reaction as above

Na  + Cl   -->   NaCl

in pseudo math, with n = number of elements in a mole.


n * Na  + n * Cl  --> n * NaCl<==>
n * (Na + Cl)  -->  n * NaCl  <==> division by n
Na + Cl   -->  NaCl


for any n.



The determination of n, the number of elements in
a mole, is an indipendent and separate problem.
(BTW, a very complicate task).


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