PyTables 2.2rc2 ready to test

2010-06-17 Thread Francesc Alted
===
 Announcing PyTables 2.2rc2
===

PyTables is a library for managing hierarchical datasets and designed to
efficiently cope with extremely large amounts of data with support for
full 64-bit file addressing.  PyTables runs on top of the HDF5 library
and NumPy package for achieving maximum throughput and convenient use.

This is the second (and probably last) release candidate for PyTables
2.2, so please test it as much as you can before I declare the beast
stable.  The main new features in 2.2 series are:

  * A new compressor called Blosc, designed to read/write data to/from
memory at speeds that can be faster than a system `memcpy()` call.
With it, many internal PyTables operations that are currently
bounded by CPU or I/O bandwith are speed-up.  Some benchmarks:
http://blosc.pytables.org/trac/wiki/SyntheticBenchmarks

  * A new `tables.Expr` module (based on Numexpr) that allows to do
persistent, on-disk computations on many algebraic operations.
For a brief look on its performance, see:
http://pytables.org/moin/ComputingKernel

  * Support for HDF5 hard links, soft links and automatic external links
(kind of mounting external filesystems).  A new tutorial about its
usage has been added to the 'Tutorials' chapter of User's Manual.

  * Suport for 'fancy' indexing (i.e., à la NumPy) in all the data
containers in PyTables.  Backported from the implementation in the
h5py project.  Thanks to Andrew Collette for his fine work on this!

As always, a large amount of bugs have been addressed and squashed too.

In case you want to know more in detail what has changed in this
version, have a look at:
http://www.pytables.org/moin/ReleaseNotes/Release_2.2rc2

You can download a source package with generated PDF and HTML docs, as
well as binaries for Windows, from:
http://www.pytables.org/download/preliminary

For an on-line version of the manual, visit:
http://www.pytables.org/docs/manual-2.2rc2


Resources
=

About PyTables:

http://www.pytables.org

About the HDF5 library:

http://hdfgroup.org/HDF5/

About NumPy:

http://numpy.scipy.org/


Acknowledgments
===

Thanks to many users who provided feature improvements, patches, bug
reports, support and suggestions.  See the ``THANKS`` file in the
distribution package for a (incomplete) list of contributors.  Most
specially, a lot of kudos go to the HDF5 and NumPy (and numarray!)
makers.  Without them, PyTables simply would not exist.


Share your experience
=

Let us know of any bugs, suggestions, gripes, kudos, etc. you may
have.




  **Enjoy data!**

  -- The PyTables Team

-- 
Francesc Alted
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: gui doubt

2010-06-17 Thread Stephen Hansen
On 6/16/10 10:40 PM, madhuri vio wrote:
 if i want to create a button
 which performs the transcription of dna to rna
 using tkinter in a gui...
 can u give me the method...

You can not possibly be serious.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: basic doubt

2010-06-17 Thread Michael Torrie
On 06/16/2010 11:06 PM, madhuri vio wrote:
 def h(self,event):
 handle = open(myco.fasta,r)
 for seq_record in SeqIO.parse(handle, fasta):
  messenger_rna = coding_myco.fasta.transcribe()
  han1 = open(mycorna.fasta,wU)
  han1.close()
  return self.messenger_rna
 
 
 the error is...
 
 File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1413, in __call__
 return self.func(*args)
 TypeError: h() takes exactly 2 arguments (0 given)
 
  ia m unable to debug...i am stuck

You will have to provide more code than this.  The traceback error you
are getting is coming from Tk's event loop when it tries to execute your
callback.  Your callback is defined as having two parameters, but
whatever is calling it from within Tk is expecting it to have no
parameters.  Without seeing a complete (but minimal!) code example that
folks can run on their own computers and replicate your problem, there's
no way for any of us to help you debug your code.

Given the nature of your queries, I assume your are most likely in
academia, doing bioinformatics research.  You would be wise to seek out
help from a computer science student or professor.  In fact you're
likely to receive more help by doing that than from this mailing list,
at least at this stage.

In your next post, please do at least the following things:
1. Make the e-mail subject clear, precise, and descriptive.  basic
doubt or gui doubt is *simply not acceptable*.  Instead you might
say, How can I run a function when I click a button in Tk? or What
does this traceback mean?
2. Post enough code so that someone can cut and paste it and run it
through python to duplicate your error.

If you don't, I'm afraid that 95% of the list members are going to
silently delete your e-mails, which will no doubt cause you much
frustration.  Many have already blocked your e-mail address.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4.4 Tkinter GUI Example for Modeless Dialog with Menu, Edit, List, Buttons, File Save etc.

2010-06-17 Thread Michael Torrie
On 06/16/2010 04:05 PM, My Python wrote:
 I would like to see some substantial example of an App written for a
 Modeless Dialog (fixed size, non resizable window) (If you have used
 WIndows MFC or Visual Basic you all know how elegant it is) 

What is elegant about a fixed-size, non-re-sizable window?  (Actually
what is elegant about MFC... shudder).  Definitely sounds like something
out of Windows.  How do you plan to deal with varying screen resolutions
and dot pitches if your dialogs are all fixed-size?  What happens when
you run your app on a high res screen where the default font size is
twice as large as what you planned for?

Tk? PyQt? PyGTK? wxPython?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4.4 Tkinter GUI Example for Modeless Dialog with Menu, Edit, List, Buttons, File Save etc.

2010-06-17 Thread Michael Torrie
On 06/17/2010 12:50 AM, Michael Torrie wrote:
 On 06/16/2010 04:05 PM, My Python wrote:
 I would like to see some substantial example of an App written for a
 Modeless Dialog (fixed size, non resizable window)

 Tk? PyQt? PyGTK? wxPython?

Nevermind that question.  You stated that in your subject line.  Perhaps
the best known, large program is IDLE.  But I don't think it implements
any dialog boxes as you desire, though.


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


Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Gabriel Genellina
En Wed, 16 Jun 2010 19:56:39 -0300, Ian Kelly ian.g.ke...@gmail.com  
escribió:



On Wed, Jun 16, 2010 at 3:38 PM, John Nagle na...@animats.com wrote:

That just leaves things in a state where even sys and import
are undefined.


Say what?  It works fine for me.


import proxy_mod
proxy_mod.f()

1

proxy_mod.a = 2

setting a=2

proxy_mod.f()

2

proxy_mod.sys

module 'sys' (built-in)


It *mostly* works, but not always. Try this function:

def g(x):
global a
print 'global a - ', x
a = x

py import fake # ModuleProxy stuff
py fake.f()
1
py fake.a = 3
setting a=3
py fake.f()
3
py fake.g(8)
global a -  8
py fake.f()
8
py fake.a
8

Note the fake.g(8) call: __setattr__ wasn't called.
If the OP wants to trace assignments to global variables, this becomes a  
problem.


A function defined in a module holds a reference to the module's __dict__  
in its func_globals attribute. Getting and setting global variables goes  
directly to this dictionary, and does not use the module object at all.


Even worse, the LOAD_GLOBAL/STORE_GLOBAL opcodes (which implement getting  
and setting global variables) assume func_globals is a true dictionary and  
bypass any overriden __getitem__/__setitem__ methods (an optimization,  
surely). I'm afraid it will be hard to intercept global variable usage in  
these circumstances.


--
Gabriel Genellina

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


Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Alf P. Steinbach

* Gabriel Genellina, on 17.06.2010 09:25:

En Wed, 16 Jun 2010 19:56:39 -0300, Ian Kelly ian.g.ke...@gmail.com
escribió:


On Wed, Jun 16, 2010 at 3:38 PM, John Nagle na...@animats.com wrote:

That just leaves things in a state where even sys and import
are undefined.


Say what? It works fine for me.


import proxy_mod
proxy_mod.f()

1

proxy_mod.a = 2

setting a=2

proxy_mod.f()

2

proxy_mod.sys

module 'sys' (built-in)


It *mostly* works, but not always. Try this function:

def g(x):
global a
print 'global a - ', x
a = x

py import fake # ModuleProxy stuff
py fake.f()
1
py fake.a = 3
setting a=3
py fake.f()
3
py fake.g(8)
global a - 8
py fake.f()
8
py fake.a
8

Note the fake.g(8) call: __setattr__ wasn't called.
If the OP wants to trace assignments to global variables, this becomes a
problem.

A function defined in a module holds a reference to the module's
__dict__ in its func_globals attribute. Getting and setting global
variables goes directly to this dictionary, and does not use the module
object at all.

Even worse, the LOAD_GLOBAL/STORE_GLOBAL opcodes (which implement
getting and setting global variables) assume func_globals is a true
dictionary and bypass any overriden __getitem__/__setitem__ methods (an
optimization, surely). I'm afraid it will be hard to intercept global
variable usage in these circumstances.


Great exposition.

But who would have thunk that Python *isn't dynamic enough*? :-)


Cheers,

- Alf

--
blog at url: http://alfps.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: basic doubt

2010-06-17 Thread Gabriel Genellina
En Thu, 17 Jun 2010 02:06:54 -0300, madhuri vio madhuri@gmail.com  
escribió:



def h(self,event):
handle = open(myco.fasta,r)
for seq_record in SeqIO.parse(handle, fasta):
 messenger_rna = coding_myco.fasta.transcribe()
 han1 = open(mycorna.fasta,wU)
 han1.close()
 return self.messenger_rna


the error is...

File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1413, in __call__
return self.func(*args)
TypeError: h() takes exactly 2 arguments (0 given)

 ia m unable to debug...i am stuck


This is just a guess, but looks like your h function is a plain function,  
not a method, so it doesn't take a self parameter. Also, you are  
probably using it in some place where the callback doesn't receive any  
additional arguments (like a Button command).

Try with def f(): ...
If it doesn't work, show us the part where h is used.

--
Gabriel Genellina

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


Communicating with a program using subprocess

2010-06-17 Thread Laurent Verweijen

I have a file called increment.py as follows: 

#!/usr/bin/python
n = 0
while True:
n = int(raw_input(n)) + 1

This is easy to understand, but I want to pipe it's input/output
by another python program. (I will show what I am doing on the
console to test it)

 from subprocess import *
 p = Popen([python, increment.py], stdin=PIPE, stdout=PIPE)
 p.communicate(5)
Traceback (most recent call last):
  File increment.py, line 4, in module
n = int(raw_input(n)) + 1
EOFError: EOF when reading a line
('06', None)
 p.communicate(7)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.6/subprocess.py, line 701, in communicate
return self._communicate(input)
  File /usr/lib/python2.6/subprocess.py, line 1184, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file

The problem is that I want to use communicate multiple times
before closing the file.

How could I achieve this

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


Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Gabriel Genellina
En Thu, 17 Jun 2010 04:52:48 -0300, Alf P. Steinbach al...@start.no  
escribió:



* Gabriel Genellina, on 17.06.2010 09:25:

En Wed, 16 Jun 2010 19:56:39 -0300, Ian Kelly ian.g.ke...@gmail.com
escribió:


On Wed, Jun 16, 2010 at 3:38 PM, John Nagle na...@animats.com wrote:

That just leaves things in a state where even sys and import
are undefined.


Say what? It works fine for me.


import proxy_mod
proxy_mod.f()

1

proxy_mod.a = 2

setting a=2

proxy_mod.f()

2

proxy_mod.sys

module 'sys' (built-in)


It *mostly* works, but not always. Try this function:

def g(x):
global a
print 'global a - ', x
a = x

py import fake # ModuleProxy stuff
py fake.f()
1
py fake.a = 3
setting a=3
py fake.f()
3
py fake.g(8)
global a - 8
py fake.f()
8
py fake.a
8

Note the fake.g(8) call: __setattr__ wasn't called.
If the OP wants to trace assignments to global variables, this becomes a
problem.

A function defined in a module holds a reference to the module's
__dict__ in its func_globals attribute. Getting and setting global
variables goes directly to this dictionary, and does not use the module
object at all.

Even worse, the LOAD_GLOBAL/STORE_GLOBAL opcodes (which implement
getting and setting global variables) assume func_globals is a true
dictionary and bypass any overriden __getitem__/__setitem__ methods (an
optimization, surely). I'm afraid it will be hard to intercept global
variable usage in these circumstances.


Great exposition.

But who would have thunk that Python *isn't dynamic enough*? :-)


Yep... There are other examples too (e.g. the print statement in 2.x  
bypasses sys.stdout.write; see also a recent thread Which objects are  
expanded by double-star ** operator?)


Most of them seem to be speed optimizations, some might be considered  
subtle bugs. But in this case (global variable references) speed is so  
critical than even the dict lookup is inlined; the code in ceval.c says:


/* Inline the PyDict_GetItem() calls.
WARNING: this is an extreme speed hack.
Do not try this at home. */

Python is dynamic but not so much as to make it crawl like a snail...

--
Gabriel Genellina

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


Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread Fuzzyman
On Jun 17, 10:29 am, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 En Thu, 17 Jun 2010 04:52:48 -0300, Alf P. Steinbach al...@start.no  
 escribió:

  But who would have thunk that Python *isn't dynamic enough*? :-)

 Yep... There are other examples too (e.g. the print statement in 2.x  
 bypasses sys.stdout.write;


What do you mean by this? The print statement in 2.x does *not* bypass
sys.stdout. It may use other methods besides write (writeln perhaps)
but you can *definitely* override sys.stdout to capture the output
from print statements.

Michael Foord


 see also a recent thread Which objects are  
 expanded by double-star ** operator?)

 Most of them seem to be speed optimizations, some might be considered  
 subtle bugs. But in this case (global variable references) speed is so  
 critical than even the dict lookup is inlined; the code in ceval.c says:

 /* Inline the PyDict_GetItem() calls.
 WARNING: this is an extreme speed hack.
 Do not try this at home. */

 Python is dynamic but not so much as to make it crawl like a snail...

 --
 Gabriel Genellina

--
http://www.voidspace.org.uk/
-- 
http://mail.python.org/mailman/listinfo/python-list


List of lists surprising behaviour

2010-06-17 Thread candide

Let's the following code :

 t=[[0]*2]*3
 t
[[0, 0], [0, 0], [0, 0]]
 t[0][0]=1
 t
[[1, 0], [1, 0], [1, 0]]

Rather surprising, isn't it ? So I suppose all the subarrays reférence 
the same array :


 id(t[0]), id(t[1]), id(t[2])
(3077445996L, 3077445996L, 3077445996L)



So what is the right way to initialize to 0 a 2D array ? Is that way 
correct  :



 t=[[0 for _ in range(2)] for _ in range(3)]

It seems there is no more trouble now :

 t
[[0, 0], [0, 0], [0, 0]]
 t[0][0]=1
 t
[[1, 0], [0, 0], [0, 0]]


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


Re: How do I fix this test so it runs on Windows? (it uses tzset)

2010-06-17 Thread Chris Withers

Nobody wrote:

On Wed, 16 Jun 2010 16:30:02 +0100, Chris Withers wrote:

I'd like to make test_non_gmt_timezone at the bottom of 
https://...

run on Windows, any suggestions?


MSVCRT has _tzset(), which understands the TZ environment variable.

http://msdn.microsoft.com/en-us/library/90s5c885%28VS.80%29.aspx

For whatever reason, tython's time module doesn't provide the tzset()
function on Windows. However, you should be able to use it via ctypes.


This sounds pretty heavyweight for a unit test.
I'm not even sure how I would do this ;-)

Where can I find an example?

...or better yet, does anyone have any alternative solutions?

Chris

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


Re: List of lists surprising behaviour

2010-06-17 Thread Lie Ryan
On 06/17/10 20:21, candide wrote:
 Let's the following code :
 
 t=[[0]*2]*3
 t
 [[0, 0], [0, 0], [0, 0]]
 t[0][0]=1
 t
 [[1, 0], [1, 0], [1, 0]]
 
 Rather surprising, isn't it ? So I suppose all the subarrays reférence
 the same array :
 
 id(t[0]), id(t[1]), id(t[2])
 (3077445996L, 3077445996L, 3077445996L)


Yep, you're right. They share the same subarray if you uses
multiplication to build the array.

 So what is the right way to initialize to 0 a 2D array ? Is that way
 correct  :
 t=[[0 for _ in range(2)] for _ in range(3)]

Right again. That's the way to go. Although if the elements are
immutable, you can create the innermost array by multiplication:

t=[[0]*2 for _ in range(3)]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List of lists surprising behaviour

2010-06-17 Thread Matteo Landi
Yes you are. List comprehension makes you create list of lists without
reference-sharing. You should also find a recipe about that on the
python cookbook.

On Thu, Jun 17, 2010 at 12:21 PM, candide cand...@free.invalid wrote:
 Let's the following code :

 t=[[0]*2]*3
 t
 [[0, 0], [0, 0], [0, 0]]
 t[0][0]=1
 t
 [[1, 0], [1, 0], [1, 0]]

 Rather surprising, isn't it ? So I suppose all the subarrays reférence the
 same array :

 id(t[0]), id(t[1]), id(t[2])
 (3077445996L, 3077445996L, 3077445996L)



 So what is the right way to initialize to 0 a 2D array ? Is that way correct
  :


 t=[[0 for _ in range(2)] for _ in range(3)]

 It seems there is no more trouble now :

 t
 [[0, 0], [0, 0], [0, 0]]
 t[0][0]=1
 t
 [[1, 0], [0, 0], [0, 0]]


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




-- 
Matteo Landi
http://www.matteolandi.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Could not import external source folder in Pydev

2010-06-17 Thread Narendran
Env info:
Python version:  '2.6.5 (r265:79063, Apr 16 2010, 13:57:41) \n[GCC
4.4.3]'
Eclipse version: Version: 3.5.2 Build id: M20100211-1343
PyDev version:  PyDev for Eclipse   1.5.7.2010050621
org.python.pydev.feature.feature.group
OS: Ubuntu 10.04

Problem:
I am trying to develop a module using web2py's DAL classes. To be able
to do it, I want to add web2py/gluon source folder as external source
folder to my project. Even after doing that, I am not able to get the
classes/packages in gluon directory in my dev env (auto-completion
doesn't happen; run fails.)

Can someone please let me know if there is any known issue/or if I am
going wrong somewhere? Thanks in advance for your help.

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


Serializing functions

2010-06-17 Thread Matteo Landi
Some weeks ago, here on the mailing list I read about picloud[1], a
python library used for cloud-computing; I was impressed by its
simplicity, here is an example:

import cloud
def square(x):
...  return x * x
cloud.call(square, 10)
cloud.result()
100

So, I tried to figure out how to achieve the same result, i.e. define a
local generic function and send it somewhere for remote execution, and
the get the result back.
So I thought about serialization (pickle): I made a few tries and it
seemed to work.. but I was wrong, because I never tried to load pickled
data from another session different from the one used to pickle data
itself. If you try and pickle a function, it is not pickled as a whole,
indeed, once you unpickle it, it will raise an exception telling you
that the target function was not found in the current module.

So I'm here, with nothing in my hands; how would you implement this?

Thanks in advance.

[1] http://www.picloud.com/

-- 
Matteo Landi
http://www.matteolandi.net

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


Re: a +b ?

2010-06-17 Thread David Robinow
On Wed, Jun 16, 2010 at 11:34 PM, Aahz a...@pythoncraft.com wrote:
 In article mailman.1662.1276743037.32709.python-l...@python.org,
 James Mills  prolo...@shortcircuit.net.au wrote:
...
What in particular do you _not_ enjoy about using map/reduce (and
possibly other functional features of the Python programing language) ?

 map() never felt particularly Pythonic, especially the way it works with
 None as the function combined with multiple arguments.  I can't explain
 why I loathe reduce() -- it just doesn't fit my brain.
 FWIW, I don't know what reduce() does. Every time I see it I have to
look it up.
I think I understand map() but probably wouldn't use it (Note: I
haven't actually written any code in a few years, being retired, or
unemployed, or something)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUIs - A Modest Proposal

2010-06-17 Thread Grant Edwards
On 2010-06-16, Matt m...@themattfella.xxxyyz.com wrote:
 On 06/05/2010 09:22 PM, ant wrote:

  PyQt is tied to one platform.


 Several posters have asked for support for or clarification of this 
 claim of yours.

Let me guess...

The one platform it's tied to is Qt?

-- 
Grant Edwards   grant.b.edwardsYow! Let's all show human
  at   CONCERN for REVERAND MOON's
  gmail.comlegal difficulties!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List of lists surprising behaviour

2010-06-17 Thread Boris Borcic

candide wrote:


So what is the right way to initialize to 0 a 2D array ? Is that way
correct :


  t=[[0 for _ in range(2)] for _ in range(3)]


That's overkill :) You can skip the inner loop by using a list display, eg

t=[[0,0] for _ in range(3)]



It seems there is no more trouble now :

  t
[[0, 0], [0, 0], [0, 0]]
  t[0][0]=1
  t
[[1, 0], [0, 0], [0, 0]]
 

Correct ?



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


Re: Serializing functions

2010-06-17 Thread Bruno Desthuilliers

Matteo Landi a écrit :

Some weeks ago, here on the mailing list I read about picloud[1], a
python library used for cloud-computing; I was impressed by its
simplicity, here is an example:


import cloud
def square(x):

...  return x * x

cloud.call(square, 10)
cloud.result()

100

So, I tried to figure out how to achieve the same result, i.e. define a
local generic function and send it somewhere for remote execution, and
the get the result back.
So I thought about serialization (pickle): I made a few tries and it
seemed to work.. but I was wrong, because I never tried to load pickled
data from another session different from the one used to pickle data
itself. If you try and pickle a function, it is not pickled as a whole,
indeed, once you unpickle it, it will raise an exception telling you
that the target function was not found in the current module.

So I'm here, with nothing in my hands; how would you implement this?


Hint found on picloud's website:


PiCloud's programming library, cloud, automatically transfers the 
necessary source code, byte code, execution state, and data to run your 
function on our cluster.



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


Goals,watch the World Cup .. mondial 2010 Online

2010-06-17 Thread mondial worldcup2010
Goals,watch the World Cup .. mondial 2010 Online
http://www.echance.info/fifa2010
http://www.echance.info/sopcast-en
http://www.echance.info/sopcast-ar
-- 
http://mail.python.org/mailman/listinfo/python-list


كيف تحصل على لاب توب جائزة

2010-06-17 Thread mondial worldcup2010
How to get a laptop gift
http://echance.info/laptop.htm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serializing functions

2010-06-17 Thread Paul Rubin
Matteo Landi landima...@gmail.com writes:
 If you try and pickle a function, it is not pickled as a whole,
 indeed, once you unpickle it, it will raise an exception telling you
 that the target function was not found in the current module.

 So I'm here, with nothing in my hands; how would you implement this?

Use marshal rather than pickle.  Note that requires both ends to be
running the same python version.  Be aware of the obvious security
issues of running code that came from remote machine, either because the
remote machine itself may be untrusted or compromised, or because the
network between the two machines may be compromised (remote machine is
being spoofed or commnications are being modified).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gui doubt

2010-06-17 Thread Tim Chase

On 06/17/2010 01:04 AM, Stephen Hansen wrote:

On 6/16/10 10:40 PM, madhuri vio wrote:

if i want to create a button
which performs the transcription of dna to rna
using tkinter in a gui...
can u give me the method...


You can not possibly be serious.


Oh, it's not that bad

[dna2rna.py]##
import Tkinter as tk

root = tk.Tk()
root.title(dna2rna)

def translate():
  from tkMessageBox import showinfo
  showinfo(Translate,
Do some translating here.\n
Maybe in another thread so the GUI doesn't stall.
)
  # do your actual work here

tk.Button(
  root,
  text=Translate!,
  command=translate
  ).pack()
root.mainloop()
##

Now all one needs to do is fill in the blanks in the Translate 
call to do the actual work...an exercise left for the 
professional in the field. ;-)   I suspect the GUI may need to be 
a bit more complex than that which might lead to wanting a more 
object-oriented code-base, but I leave that too as an exercise 
for the reader.


-tkc



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


Re: Serializing functions

2010-06-17 Thread Matteo Landi
On Thu, 2010-06-17 at 07:37 -0700, Paul Rubin wrote:
 Matteo Landi landima...@gmail.com writes:
  If you try and pickle a function, it is not pickled as a whole,
  indeed, once you unpickle it, it will raise an exception telling you
  that the target function was not found in the current module.
 
  So I'm here, with nothing in my hands; how would you implement this?
 
 Use marshal rather than pickle.  Note that requires both ends to be

I could be wrong, but it seems functions are not marshable objects, is
it right?

 running the same python version.  Be aware of the obvious security
 issues of running code that came from remote machine, either because the
 remote machine itself may be untrusted or compromised, or because the
 network between the two machines may be compromised (remote machine is
 being spoofed or commnications are being modified).

-- 
Matteo Landi
http://www.matteolandi.net

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


RE: gui doubt

2010-06-17 Thread Andreas Tawn
 On 06/17/2010 01:04 AM, Stephen Hansen wrote:
  On 6/16/10 10:40 PM, madhuri vio wrote:
  if i want to create a button
  which performs the transcription of dna to rna
  using tkinter in a gui...
  can u give me the method...
 
  You can not possibly be serious.
 
 Oh, it's not that bad
 
 [dna2rna.py]##
 import Tkinter as tk
 
 root = tk.Tk()
 root.title(dna2rna)
 
 def translate():
from tkMessageBox import showinfo
showinfo(Translate,
  Do some translating here.\n
  Maybe in another thread so the GUI doesn't stall.
  )
# do your actual work here
 
 tk.Button(
root,
text=Translate!,
command=translate
).pack()
 root.mainloop()
 ##
 
 Now all one needs to do is fill in the blanks in the Translate
 call to do the actual work...an exercise left for the
 professional in the field. ;-)   I suspect the GUI may need to be
 a bit more complex than that which might lead to wanting a more
 object-oriented code-base, but I leave that too as an exercise
 for the reader.
 
 -tkc

Seems like a simple problem... or am I missing something?

def translate():
   return dna.replace(d, r)

Cheers,

Drea

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


Re: Serializing functions

2010-06-17 Thread Paul Rubin
Matteo Landi landima...@gmail.com writes:
 I could be wrong, but it seems functions are not marshable objects, is
 it right?

Hmm, you're right, you can marshal code objects, but you can't marshal a
function directly.  It's been a while since I've used marshal and I
forgot how it works.  You might be able to concoct something around it,
but it could be messy.  It may be simplest to send the other side a
python source file that it can import.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serializing functions

2010-06-17 Thread Matteo Landi
On Thu, 2010-06-17 at 07:37 -0700, Paul Rubin wrote:
 Matteo Landi landima...@gmail.com writes:
  If you try and pickle a function, it is not pickled as a whole,
  indeed, once you unpickle it, it will raise an exception telling you
  that the target function was not found in the current module.
 
  So I'm here, with nothing in my hands; how would you implement this?
 
 Use marshal rather than pickle.  Note that requires both ends to be

I could be wrong, but it seems functions are not marshable objects, is
it right?

 running the same python version.  Be aware of the obvious security
 issues of running code that came from remote machine, either because the
 remote machine itself may be untrusted or compromised, or because the
 network between the two machines may be compromised (remote machine is
 being spoofed or commnications are being modified).

-- 
Matteo Landi
http://www.matteolandi.net

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


Re: gui doubt

2010-06-17 Thread Bruno Desthuilliers

Andreas Tawn a écrit :

On 06/17/2010 01:04 AM, Stephen Hansen wrote:

On 6/16/10 10:40 PM, madhuri vio wrote:

if i want to create a button
which performs the transcription of dna to rna


(snip the GUI part)



Seems like a simple problem... or am I missing something?

def translate():
   return dna.replace(d, r)



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


Re: Serializing functions

2010-06-17 Thread Stephen Hansen
On 6/17/10 6:23 AM, Matteo Landi wrote:
 itself. If you try and pickle a function, it is not pickled as a whole,
 indeed, once you unpickle it, it will raise an exception telling you
 that the target function was not found in the current module.

You can pickle functions-- and classes, instances, and such-- just fine.
If you're having specific difficulty with one instance of doing so, show
the actual code.

 def test(one):
... print one + 1
...
 import pickle
 outp = pickle.dumps(test)
 outp
'c__main__\ntest\np0\n.'
 fn = pickle.loads(outp)
 fn(1)
2

Now, complex stuff like classes and functions have to live in the same
place with pickle, and it does need the source to be available and
already imported, but it works fine.

If by pickle a function you mean, take an arbitrary function and
pickle it into some random destination and have it by itself still be
enough to be executable, then no, pickle doesn't do that. To get that,
you'd have to distribute the source to the destination and import it
before-hand.

That or do some crazy-complicated sort of code object marshalling and
manipulation on the other side. I have no idea where to even begin in
that situation (hw do you turn a code object into something you can
actually pass arguments to, hmm? I only know how to 'exec' a bare code
object)

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gui doubt

2010-06-17 Thread Tim Chase

On 06/17/2010 10:07 AM, Andreas Tawn wrote:

On 6/16/10 10:40 PM, madhuri vio wrote:

which performs the transcription of dna to rna

[snip]

Seems like a simple problem... or am I missing something?

def translate():
return dna.replace(d, r)


And I understand people in bioinformatics get paid big 
money...for that!? ;-)


-tkc


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


Re: gui doubt

2010-06-17 Thread Steven W. Orr
On 06/17/10 01:40, quoth madhuri vio:
 if i want to create a button
 which performs the transcription of dna to rna
 using tkinter in a gui...
 can u give me the method...
 
 -- 
 madhuri :)
 

Dear Madasahatter. You need to read the description below on how to properly
implement and use the unsubscribe button. After use, please take a piece of
cardboard and hand it around your neck to announce your accomplishment. The
algorithm below may need to be translated into python, but I would expect that
this would be the easiest part of the problem. We all wish you the best of
luck in your new venture as village idiot. In the future, please let the FBI
know if you have any problems.

From: Dr. Bryan Bledsoe bbled...@earthlink.net
To: prehospitalcare List Member  de...@world.std.com
Subject: [prehospitalcare] How To Remove Yourself From The List
Date: Sat, 10 Aug 2002 20:55:52 -0500
X-Mailer: Microsoft Outlook Express 6.00.2600.
X-MDRemoteIP: 207.217.120.50
Sender: prehospitalc...@emsvillage.com
X-Return-Path: prehospitalc...@emsvillage.com
List-Unsubscribe: mailto:prehospitalcare-unsubscr...@emsvillage.com
X-MDMailing-List: prehospitalc...@emsvillage.com
X-MDSend-Notifications-To: prehospitalc...@emsvillage.com
Reply-To: prehospitalc...@emsvillage.com

Phil:

You are WRONG.  Here is how to unsubscribe from prehospitalc...@emsvillage.com:
How to unsubscribe (as you requested)

First, ask your Internet Provider to mail you an Unsubscribing
Kit. Then follow these directions. The kit will most likely be
the standard no-fault type. Depending on requirements,
System A and/or System B can be used. When operating System A,
depress lever and a plastic dalkron unsubscriber will be dispensed
through the slot immediately underneath. When you have fastened the
adhesive lip, attach connection marked by the large X outlet
hose. Twist the silver- coloured ring one inch below the connection
point until you feel it lock.

The kit is now ready for use. The Cin-Eliminator is activated by the
small switch on the lip. When securing, twist the ring back to its
initial condition, so that the two orange lines meet. Disconnect.

Place the dalkron unsubscriber in the vacuum receptacle to the
rear. Activate by pressing the blue button.

The controls for System B are located on the opposite side. The red
release switch places the Cin-Eliminator into position; it can be
adjusted manually up or down by pressing the blue manual release
button. The opening is self-adjusting. To secure after use, press the
green button, which simultaneously activates the evaporator and
returns the Cin-Eliminator to its storage position.

You may log off if the green exit light is on over the evaporator. If
the red light is illuminated, one of the Cin-Eliminator requirements
has not been properly implemented.

Press the List Guy call button on the right of the evaporator. He
will secure all facilities from his control panel.

To use the Auto-Unsub, first undress and place all your clothes in
the clothes rack. Put on the velcro slippers located in the cabinet
immediately below. Enter the shower, taking the entire kit with
you. On the control panel to your upper right upon entering you will
see a Shower seal button.

Press to activate. A green light will then be illuminated immediately
below. On the intensity knob, select the desired setting. Now depress
the Auto-Unsub activation lever.

Bathe normally.

The Auto-Unsub will automatically go off after three minutes unless
you activate the Manual off override switch by flipping it up. When
you are ready to leave, press the blue Shower seal release
button. The door will open and you may leave. Please remove the
velcro slippers and place them in their container.

If you prefer the ultrasonic log-off mode, press the indicated blue
button. When the twin panels open, pull forward by rings A  B. The
knob to the left, just below the blue light, has three settings, low,
medium or high. For normal use, the medium setting is suggested.

After these settings have been made, you can activate the device by
switching to the ON position the clearly marked red switch. If
during the unsubscribing operation you wish to change the settings,
place the manual off override switch in the OFF position. You may
now make the change and repeat the cycle. When the green exit light
goes on, you may log off and have lunch. Please close the door behind
you.




Bryan E. Bledsoe, DO, FACEP
Midlothian, Texas

All outgoing email scanned by Norton Antivirus and guaranteed
virus free or your money back.

- Original Message -
From: Philip L. Hayes
To: prehospitalcare List Member
Sent: Saturday, August 10, 2002 7:50 PM
Subject: [prehospitalcare] How To Remove Yourself From The List

Hi Everybody-

To remove yourself from the list serv, simply follow
the instructions at the bottom of every e-mail. Sending
an unsubscribe or remove command to the list will not
do it.

Phil Hayes
EMS Village Support



-Original Message-
From: 

Re: Serializing functions

2010-06-17 Thread Matteo Landi
On Thu, 2010-06-17 at 08:31 -0700, Stephen Hansen wrote:
 On 6/17/10 6:23 AM, Matteo Landi wrote:
  itself. If you try and pickle a function, it is not pickled as a whole,
  indeed, once you unpickle it, it will raise an exception telling you
  that the target function was not found in the current module.
 
 You can pickle functions-- and classes, instances, and such-- just fine.
 If you're having specific difficulty with one instance of doing so, show
 the actual code.
 
  def test(one):
 ... print one + 1
 ...
  import pickle
  outp = pickle.dumps(test)
  outp
 'c__main__\ntest\np0\n.'
  fn = pickle.loads(outp)
  fn(1)
 2
 
 Now, complex stuff like classes and functions have to live in the same
 place with pickle, and it does need the source to be available and
 already imported, but it works fine.
 
 If by pickle a function you mean, take an arbitrary function and
 pickle it into some random destination and have it by itself still be
 enough to be executable, then no, pickle doesn't do that. To get that,
 you'd have to distribute the source to the destination and import it
 before-hand.

This is the problem, and I excuse me if I ain't been clear enough while
showing it inside my previous email.

 
 That or do some crazy-complicated sort of code object marshalling and
 manipulation on the other side. I have no idea where to even begin in
 that situation (hw do you turn a code object into something you can
 actually pass arguments to, hmm? I only know how to 'exec' a bare code
 object)
 

So it seems one should go for sending the function and the module with
its definition in order to make the remote side able to execute it.

I'm curious to see how picloud is able to discover the needed modules,
sources etc etc to run the function specified inside picloud.call(); it
seems not an easy task.

-- 
Matteo Landi
http://www.matteolandi.net

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


Re: Serializing functions

2010-06-17 Thread Andreas Löscher
Am Donnerstag, den 17.06.2010, 08:18 -0700 schrieb Paul Rubin:
 Matteo Landi landima...@gmail.com writes:
  I could be wrong, but it seems functions are not marshable objects, is
  it right?
 
 Hmm, you're right, you can marshal code objects, but you can't marshal a
 function directly.  It's been a while since I've used marshal and I
 forgot how it works.  You might be able to concoct something around it,
 but it could be messy.  It may be simplest to send the other side a
 python source file that it can import.

There was a similar thread a while ago.

You can marshal the functions code object and create a new function on
the remote side using this code object.

 import marshal
 def spam(): pass

now marshal the code object

 s = marshal.dumps(spam.func_code)

On the remote side:

 import marshal
 import types
 code = marshal.loads(s)
 spam = types.FunctionType(code, globals())

This works as long as you are using byte code compatible Versions on
both side. The creation of functions has also some optional arguments
you must be aware of, in order to get the result you want. 

Look at help(types.FunctionType) for further information.



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


Re: Serializing functions

2010-06-17 Thread Andreas Löscher
Am Donnerstag, den 17.06.2010, 18:03 +0200 schrieb Andreas Löscher:
 Am Donnerstag, den 17.06.2010, 08:18 -0700 schrieb Paul Rubin:
  Matteo Landi landima...@gmail.com writes:
   I could be wrong, but it seems functions are not marshable objects, is
   it right?
  
  Hmm, you're right, you can marshal code objects, but you can't marshal a
  function directly.  It's been a while since I've used marshal and I
  forgot how it works.  You might be able to concoct something around it,
  but it could be messy.  It may be simplest to send the other side a
  python source file that it can import.
 
 There was a similar thread a while ago.
 

Ah I found it:
Search for:

Object serialization: transfer from a to b (non-implemented code on b)

 in this mailing list.

Is there a good way to link a former thread?


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


Efficiency/style issues of import module vs. from module import name, ...

2010-06-17 Thread python
Are there any efficiency or style guidelines regarding the choice
of import module vs. from module import name, ...?

If one only needs to import a few names from a module, are there
specific benefits to explictly importing these names?

My understanding is that both forms of the import command require
the entire module to be processed.

If this comes down purely to preference, are there PEP 8-like
standards regarding which approach to use when?

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


Re: Upgrading from Python 2.6.5 w.r.t. matplotlib/numpy?

2010-06-17 Thread Robert Kern

On 6/17/10 12:24 AM, Stephen Hansen wrote:

On 6/16/10 10:18 PM, Mark Lawrence wrote:

I'm like to go direct to Python 3.1 if possible, but if necessary I'll
happily use Python 2.7 as an interim measure. However I'm uncertain as
to the status of matplotlib and its dependency on numpy.  I've tried
googling their development mailing lists but don't really understand
what the current situation is.


Asking those mailing lists is probably the best course.


Could somebody please recommend whether
I take the direct or indirect route to Python 3.1.  FWIW I'm on Windows
Vista.


Numpy isn't available for 3.1 yet. IIUC, its not That Terribly Awfully
Long Away (meaning, some indeterminate time probably counted in months
and not years), but its not there yet.


I believe it builds and passes most tests. Maybe not on Vista, though.

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: gui doubt

2010-06-17 Thread Robert Kern

On 6/17/10 10:38 AM, Tim Chase wrote:

On 06/17/2010 10:07 AM, Andreas Tawn wrote:

On 6/16/10 10:40 PM, madhuri vio wrote:

which performs the transcription of dna to rna

[snip]

Seems like a simple problem... or am I missing something?

def translate():
return dna.replace(d, r)


And I understand people in bioinformatics get paid big money...for
that!? ;-)


Actually, the full method is a lot more complicated:

def translate(dna):
return dna.replace('T', 'U')

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Serializing functions

2010-06-17 Thread Robert Kern

On 6/17/10 8:23 AM, Matteo Landi wrote:

Some weeks ago, here on the mailing list I read about picloud[1], a
python library used for cloud-computing; I was impressed by its
simplicity, here is an example:


import cloud
def square(x):

...  return x * x

cloud.call(square, 10)
cloud.result()

100

So, I tried to figure out how to achieve the same result, i.e. define a
local generic function and send it somewhere for remote execution, and
the get the result back.
So I thought about serialization (pickle): I made a few tries and it
seemed to work.. but I was wrong, because I never tried to load pickled
data from another session different from the one used to pickle data
itself. If you try and pickle a function, it is not pickled as a whole,
indeed, once you unpickle it, it will raise an exception telling you
that the target function was not found in the current module.

So I'm here, with nothing in my hands; how would you implement this?


PiCloud's client library is LGPLed. Go take a look for yourself. It's pretty 
nifty.

[Disclosure: My employer, Enthought, has partnered with PiCloud to provide our 
Enthought Python Distribution to PiCloud users. However, I say that it's nifty 
purely because it is.]


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Efficiency/style issues of import module vs. from module import name, ...

2010-06-17 Thread Stephen Hansen
On 6/17/10 9:12 AM, pyt...@bdurham.com wrote:
 Are there any efficiency or style guidelines regarding the choice
 of import module vs. from module import name, ...?

There are no legitimate efficiency issues. In theory, module.blah is
slightly slower then blah, but that slightly is largely irrelevant in
globals. If you need to do module.blah a lot in a loop, you want to
re-bind it into a local anyways before that loop if performance starts
mattering that much.

Style wise, the only guideline is, from module import * is often
(but not always) bad. It pollutes the namespace, making it difficult to
know exactly what's defined and where it is defined. Multiple import
*'s are especially bad.

Explicitly importing certain names is perfectly fine. Its clear and
explicit. Someone seeing, MyRandomClass can search in the code and
they'll find that import and know precisely where to go to look for it.

 If one only needs to import a few names from a module, are there
 specific benefits to explictly importing these names?

Clarity, sometimes. There is no general rule here though. It depends on
the structure and layout. Its a case-by-case situation; is it more clear
to your natural reading to have 'module.MyRandomThing' or just
'MyRandomThing' in your code?

An example: let's say you have a handlers module containing certain...
uh.. handlers.. you have defined for your application.

You could either:

import handlers

Or:

from handlers import MyHTTPHandler, MySMTPHandler, MyNNTPHandler

In this case, I'd consider it possible that in code usage, its entirely
sufficient to call MyHTTPHandler and have it be clear and
understandable for future non-you coders. handlers.MyHTTPHandler is
slightly more explicit, but due to the naming and structure of this
specific code, redundant as well. That may not always hold true.

Now, this is all IMHO: the style guide does not define any 'guidelines'
on this, except that its okay to use from ... import ... to pull in
classes and (implicitly) constants, and despite how the rules say 'one
module per line' its OK to pull in more then one name -from- a module at
once.

 My understanding is that both forms of the import command require
 the entire module to be processed.

Yes.

from module import name is just a shortcut for:

import module
name = module.name

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


super() woes (n00b)

2010-06-17 Thread Deadly Dirk
I cannot get right the super() function:
Python 3.1.1+ (r311:74480, Nov  2 2009, 14:49:22) 
[GCC 4.4.1] on linux2
Type copyright, credits or license() for more information.
 No Subprocess 
 class P:
def __init__(__class__,self):
print(I am a member of class P)


 class C(P):
def __init__(self):
super().__init__(self)
print(I am a member of class C)



class P:
def __init__(self):
print(I am a member of class P)

class C(P):
def __init__(self):
super().__init__(self)
print(I am a member of class C)

x=C()

That is more or less the text from the Quick Python Book. What am I 
doing wrong?

-- 
The missionaries go forth to Christianize the savages - 
as if the savages weren't dangerous enough already.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficiency/style issues of import module vs. from module import name, ...

2010-06-17 Thread Ethan Furman

Stephen Hansen wrote:

On 6/17/10 9:12 AM, pyt...@bdurham.com wrote:

Now, this is all IMHO: the style guide does not define any 'guidelines'
on this, except that its okay to use from ... import ... to pull in
classes and (implicitly) constants, and despite how the rules say 'one
module per line' its OK to pull in more then one name -from- a module at
once.


What do you mean by (implicitly) constants?



My understanding is that both forms of the import command require
the entire module to be processed.


Yes.

from module import name is just a shortcut for:

import module
name = module.name



There should also be a third line:
  del module

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


Re: super() woes (n00b)

2010-06-17 Thread Deadly Dirk
On Thu, 17 Jun 2010 16:36:10 +, Deadly Dirk wrote:

 I cannot get right the super() function: Python 3.1.1+ (r311:74480, Nov 
 2 2009, 14:49:22) [GCC 4.4.1] on linux2
 Type copyright, credits or license() for more information.  No
 Subprocess 
 class P:
 def __init__(__class__,self):
 print(I am a member of class P)
 
 
 class C(P):
 def __init__(self):
 super().__init__(self)
 print(I am a member of class C)
 
 
 
 class P:
 def __init__(self):
 print(I am a member of class P)
 
 class C(P):
 def __init__(self):
 super().__init__(self)
 print(I am a member of class C)
 
 x=C()
 
 That is more or less the text from the Quick Python Book. What am I
 doing wrong?

I tried this, too:

 class C(P):
def __init__(self):
super(__class__).__init__(self)
print(I am a member of class C)


 x=C()
Traceback (most recent call last):
  File pyshell#30, line 1, in module
x=C()
  File pyshell#29, line 3, in __init__
super(__class__).__init__(self)
TypeError: must be type, not C
 



-- 
The missionaries go forth to Christianize the savages - 
as if the savages weren't dangerous enough already.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficiency/style issues of import module vs. from module import name, ...

2010-06-17 Thread Stephen Hansen
On 6/17/10 10:01 AM, Ethan Furman wrote:
 Stephen Hansen wrote:
 On 6/17/10 9:12 AM, pyt...@bdurham.com wrote:

 Now, this is all IMHO: the style guide does not define any 'guidelines'
 on this, except that its okay to use from ... import ... to pull in
 classes and (implicitly) constants, and despite how the rules say 'one
 module per line' its OK to pull in more then one name -from- a module at
 once.
 
 What do you mean by (implicitly) constants?

Quote, PEP-8:

 - Imports should usually be on separate lines, e.g.:

Yes: import os
 import sys

No:  import sys, os

  it's okay to say this though:

from subprocess import Popen, PIPE

It explicitly states later its entirely OK to import classes. It never
says anything else directly, except in the example given, it shows you
importing a constant. So, its giving implicit approval to that without
really directly saying anything about it.

 My understanding is that both forms of the import command require
 the entire module to be processed.

 Yes.

 from module import name is just a shortcut for:

 import module
 name = module.name
 
 
 There should also be a third line:
   del module

You're right, I missed that.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Overriding __setattr__ of a module - possible?

2010-06-17 Thread John Nagle

On 6/17/2010 12:25 AM, Gabriel Genellina wrote:

Note the fake.g(8) call: __setattr__ wasn't called.
If the OP wants to trace assignments to global variables, this becomes a
problem.

A function defined in a module holds a reference to the module's
__dict__ in its func_globals attribute. Getting and setting global
variables goes directly to this dictionary, and does not use the module
object at all.

Even worse, the LOAD_GLOBAL/STORE_GLOBAL opcodes (which implement
getting and setting global variables) assume func_globals is a true
dictionary and bypass any overriden __getitem__/__setitem__ methods (an
optimization, surely). I'm afraid it will be hard to intercept global
variable usage in these circumstances.


   OK, thanks.  You can't actually replace __setattr__ for
a module, and the module as class hack is iffy.  I didn't
really think this would work, but it was worth a try.

   I'm trying out a proof of concept implementation for a new
approach to safe threading.  It's somewhat similar in concept
to Alan Olsen's scheme.  The basic difference is that once
the program goes multi-thread, code objects and some other
bindings are locked down and become unchangeable.  Olsen
was climbing the walls trying to get the locking right for
the awful cases like redefining a function while another thread
is inside it.  I'm trying to lock out some of those cases.
If you do that, removing the GIL requires less pain than
Olsen experienced.

   The key idea is that the use cases for most of Python's
code dynamism are during setup and initialization.  You usually
don't change code once the program has gone into its heavy
parallel processing phase.  This suggests a practical compromise.

   More on this once I have something people can download and try.
I'm doing a test implementation in Python so people can try the
concept and see if it works in practice.  It won't go fast;
it's just to give a feel for what it would be like.

John Nagle

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


Re: Efficiency/style issues of import module vs. from module import name, ...

2010-06-17 Thread Ethan Furman

Stephen Hansen wrote:

On 6/17/10 10:01 AM, Ethan Furman wrote:

Stephen Hansen wrote:

On 6/17/10 9:12 AM, pyt...@bdurham.com wrote:

Now, this is all IMHO: the style guide does not define any 'guidelines'
on this, except that its okay to use from ... import ... to pull in
classes and (implicitly) constants, and despite how the rules say 'one
module per line' its OK to pull in more then one name -from- a module at
once.

What do you mean by (implicitly) constants?


Quote, PEP-8:

 - Imports should usually be on separate lines, e.g.:

Yes: import os
 import sys

No:  import sys, os

  it's okay to say this though:

from subprocess import Popen, PIPE

It explicitly states later its entirely OK to import classes. It never
says anything else directly, except in the example given, it shows you
importing a constant. So, its giving implicit approval to that without
really directly saying anything about it.



Thanks for the clarification -- I was reading it as constants being 
implicitly imported, and I knew that wasn't so!  ;)


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


Re: Efficiency/style issues of import module vs. from module import name, ...

2010-06-17 Thread Jack Diederich
On Thu, Jun 17, 2010 at 12:58 PM, Stephen Hansen
me+list/pyt...@ixokai.io wrote:
 On 6/17/10 10:01 AM, Ethan Furman wrote:
 Stephen Hansen wrote:
 On 6/17/10 9:12 AM, pyt...@bdurham.com wrote:

 Now, this is all IMHO: the style guide does not define any 'guidelines'
 on this, except that its okay to use from ... import ... to pull in
 classes and (implicitly) constants, and despite how the rules say 'one
 module per line' its OK to pull in more then one name -from- a module at
 once.

 What do you mean by (implicitly) constants?

 Quote, PEP-8:

  - Imports should usually be on separate lines, e.g.:

        Yes: import os
             import sys

        No:  import sys, os

      it's okay to say this though:

        from subprocess import Popen, PIPE

 It explicitly states later its entirely OK to import classes. It never
 says anything else directly, except in the example given, it shows you
 importing a constant. So, its giving implicit approval to that without
 really directly saying anything about it.

You want to import a name that is itself a namespace; preferably a
module or package and sometimes a class.  Importing constants can lead
to trouble.  ex/

from settings import DEBUG
if DEBUG: log('debug is on!')

The value of the flag gets fetched at import time.  If code in another
module updates settings.DEBUG later your module won't see it. ditto
for exceptions.

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


Re: Efficiency/style issues of import module vs. from module import name, ...

2010-06-17 Thread Ethan Furman

Jack Diederich wrote:

You want to import a name that is itself a namespace; preferably a
module or package and sometimes a class.  Importing constants can lead
to trouble.  ex/

from settings import DEBUG
if DEBUG: log('debug is on!')

The value of the flag gets fetched at import time.  If code in another
module updates settings.DEBUG later your module won't see it. ditto
for exceptions.

-Jack


The idea behind constants is that they are... um... constant.  ;)  I 
imagine exceptions don't get changed often either.  (At least, I never 
change mine.)


If you have a setting that may change, don't call it a constant and name 
it accordingly.


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


Re: Efficiency/style issues of import module vs. from module import name, ...

2010-06-17 Thread Stephen Hansen
On 6/17/10 10:22 AM, Jack Diederich wrote:
 On Thu, Jun 17, 2010 at 12:58 PM, Stephen Hansen
 It explicitly states later its entirely OK to import classes. It never
 says anything else directly, except in the example given, it shows you
 importing a constant. So, its giving implicit approval to that without
 really directly saying anything about it.
 
 You want to import a name that is itself a namespace; preferably a
 module or package and sometimes a class.  Importing constants can lead
 to trouble.  ex/
 
 from settings import DEBUG
 if DEBUG: log('debug is on!')
 
 The value of the flag gets fetched at import time.  If code in another
 module updates settings.DEBUG later your module won't see it. ditto
 for exceptions.

That argument is invalid on its face; a constant, by definition, is not
to be modified. The convention (recently adopted officially by PEP-8) of
ALL_CAPS makes this promise: this is a static piece of data.

That its possible for misbehaving code to change it due to Python's lax
nature doesn't mean you should organize or write your code in such a way
to take that into account. People can shoot themselves in the foot.

If people do stupid things after writing code that makes promises, stuff
that relies upon the explicit promises made may fail, and that's their
own dumb fault.

And the only time someone is going to go 'change' an exception that
lives in the top-level of some other module is if they're
monkey-patching, which while a legitimate technique to achieve certain
ends when using other people's code-- is also not a technique which has
any place in consideration of the design phase of the original system
itself.

Certainly, importing a non-constant immutable piece of data is
problematic in theory, as it can be rebound and problems arise.

Number of times I've -seen- non-constant immutable data in the top-level
of a module: 0*.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/

P.S. Outside of a throw-away script which is not meant to be imported,
at least.



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python OpenSSL library

2010-06-17 Thread Antoine Pitrou
On Tue, 15 Jun 2010 19:56:46 -0700
John Nagle na...@animats.com wrote:
 
  http://bugs.python.org/issue1589
[...]
 
 The typical Python user will expect SSL checking for URL opening
 to behave like a browser does. They won't be up to speed on the
 internal mechanics of X.509 certificates.  The default case should
 be to require a hostname match (considering certificate wildcards,
 multiple common names, multiple alt names, etc.).
 
 Expecting the caller to do this check is unreasonable.  It's
 about 70 lines of python code to cover all the cases.  And
 that's without proper support for error reporting for internationalized
 host names.

If you are interested in this, I would encourage you to post a patch or
a proposal on the aforementioned bug entry so as to add a hostname
checking function to the SSL module.
(m2crypto has its own implementation that can serve as a source of
inspiration, and test cases)

If/when that is done, the second step would be to integrate it by
default with the urllib module, and perhaps other ones.

Thanks

Antoine.


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


Re: super() woes (n00b)

2010-06-17 Thread J. Cliff Dyer
On Thu, 2010-06-17 at 16:36 +, Deadly Dirk wrote:
 I cannot get right the super() function:
 Python 3.1.1+ (r311:74480, Nov  2 2009, 14:49:22) 
 [GCC 4.4.1] on linux2
 Type copyright, credits or license() for more information.
  No Subprocess 
  class P:
 def __init__(__class__,self):
 print(I am a member of class P)
 
 
  class C(P):
 def __init__(self):
 super().__init__(self)
 print(I am a member of class C)
 
 
 
 class P:
 def __init__(self):
 print(I am a member of class P)
 
 class C(P):
 def __init__(self):
 super().__init__(self)
 print(I am a member of class C)
 
 x=C()
 
 That is more or less the text from the Quick Python Book. What am I 
 doing wrong?
 

super gives you an instantiated version of the super class, which means
that you don't have to explicitly send self to any methods you call on
it.  

So use `super().__init__()` instead.
 -- 
 The missionaries go forth to Christianize the savages - 
 as if the savages weren't dangerous enough already.


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


The inverse of .join

2010-06-17 Thread Neil Cerutti
What's the best way to do the inverse operation of the .join
function?

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


Re: The inverse of .join

2010-06-17 Thread nn

Neil Cerutti wrote:
 What's the best way to do the inverse operation of the .join
 function?

 --
 Neil Cerutti

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


Re: super() woes (n00b)

2010-06-17 Thread Matteo Landi
I found few error in your code:
1 the constructor of P class seems to be wrong:

 class P(object):
...def __init__(self):
...print(I am a member of class P)
...

2 super() works with new style classes, i.e.  the ones which inherit
from 'object'

 class P:
...def __init__(__class__,self):
...print(I am a member of class P)
...

3 super() need a type as first argument, and an instance as second one:

 class C(P):
...def __init__(self):
...super().__init__(self)
...print(I am a member of class C)

Now it should work (not tested).

On Thu, Jun 17, 2010 at 6:53 PM, Deadly Dirk d...@plfn.invalid wrote:
 On Thu, 17 Jun 2010 16:36:10 +, Deadly Dirk wrote:

 I cannot get right the super() function: Python 3.1.1+ (r311:74480, Nov
 2 2009, 14:49:22) [GCC 4.4.1] on linux2
 Type copyright, credits or license() for more information.  No
 Subprocess 
 class P:
     def __init__(__class__,self):
         print(I am a member of class P)


 class C(P):
     def __init__(self):
         super().__init__(self)
         print(I am a member of class C)



 class P:
     def __init__(self):
         print(I am a member of class P)

 class C(P):
     def __init__(self):
         super().__init__(self)
         print(I am a member of class C)

 x=C()

 That is more or less the text from the Quick Python Book. What am I
 doing wrong?

 I tried this, too:

 class C(P):
    def __init__(self):
        super(__class__).__init__(self)
        print(I am a member of class C)


 x=C()
 Traceback (most recent call last):
  File pyshell#30, line 1, in module
    x=C()
  File pyshell#29, line 3, in __init__
    super(__class__).__init__(self)
 TypeError: must be type, not C




 --
 The missionaries go forth to Christianize the savages -
 as if the savages weren't dangerous enough already.
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Matteo Landi
http://www.matteolandi.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The inverse of .join

2010-06-17 Thread MRAB

Neil Cerutti wrote:

What's the best way to do the inverse operation of the .join
function?


.split, possibly, although there will be problems if the string contains
other occurrences of the separator.
--
http://mail.python.org/mailman/listinfo/python-list


Re: The inverse of .join

2010-06-17 Thread Ian Kelly
On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti ne...@norwich.edu wrote:
 What's the best way to do the inverse operation of the .join
 function?

Use the str.split method?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super() woes (n00b)

2010-06-17 Thread Deadly Dirk
On Thu, 17 Jun 2010 13:48:45 -0400, J. Cliff Dyer wrote:

 super gives you an instantiated version of the super class, which means
 that you don't have to explicitly send self to any methods you call on
 it.
 
 So use `super().__init__()` instead.

Thanks. Interestingly enough, it works in Python 3, which is what the 
book is about. It doesn't work in Python 2.6

3.1:

Python 3.1.1+ (r311:74480, Nov  2 2009, 14:49:22) 
[GCC 4.4.1] on linux2
Type copyright, credits or license() for more information.
 No Subprocess 
 class P:
def __init__(self):
print(I am a member of class P)

 class C(P):
def __init__(self):
super().__init__()
print(I am a member of class C)


 x=C()
I am a member of class P
I am a member of class C
 

2.6:
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type copyright, credits or license() for more information.


Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface.  This connection is not visible on any external
interface and no data is sent to or received from the Internet.


IDLE 2.6.4   No Subprocess 
 class P:
def __init__(self):
print(I am a member of class P)

 class C(P):
def __init__(self):
super().__init__()
print(I am a member of class C)

 x=C()
Traceback (most recent call last):
  File pyshell#2, line 1, in module
x=C()
  File pyshell#1, line 3, in __init__
super().__init__()
TypeError: super() takes at least 1 argument (0 given)
 


-- 
The missionaries go forth to Christianize the savages - 
as if the savages weren't dangerous enough already.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super() woes (n00b)

2010-06-17 Thread Benjamin Kaplan
On Thu, Jun 17, 2010 at 10:51 AM, Matteo Landi landima...@gmail.com wrote:
 I found few error in your code:
 1 the constructor of P class seems to be wrong:

 class P(object):
 ...    def __init__(self):
 ...        print(I am a member of class P)
 ...

 2 super() works with new style classes, i.e.  the ones which inherit
 from 'object'


The OP is using Python 3.1. All classes in Python 3.x are new style.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python OpenSSL library

2010-06-17 Thread geremy condra
On Thu, Jun 17, 2010 at 10:49 AM, Antoine Pitrou solip...@pitrou.net wrote:
 On Tue, 15 Jun 2010 19:56:46 -0700
 John Nagle na...@animats.com wrote:

      http://bugs.python.org/issue1589
 [...]

 The typical Python user will expect SSL checking for URL opening
 to behave like a browser does. They won't be up to speed on the
 internal mechanics of X.509 certificates.  The default case should
 be to require a hostname match (considering certificate wildcards,
 multiple common names, multiple alt names, etc.).

 Expecting the caller to do this check is unreasonable.  It's
 about 70 lines of python code to cover all the cases.  And
 that's without proper support for error reporting for internationalized
 host names.

 If you are interested in this, I would encourage you to post a patch or
 a proposal on the aforementioned bug entry so as to add a hostname
 checking function to the SSL module.
 (m2crypto has its own implementation that can serve as a source of
 inspiration, and test cases)

 If/when that is done, the second step would be to integrate it by
 default with the urllib module, and perhaps other ones.

John, I'll do this if you don't want to. Let me know.

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


Re: super() woes (n00b)

2010-06-17 Thread Ethan Furman

Deadly Dirk wrote:

On Thu, 17 Jun 2010 13:48:45 -0400, J. Cliff Dyer wrote:


super gives you an instantiated version of the super class, which means
that you don't have to explicitly send self to any methods you call on
it.

So use `super().__init__()` instead.


Thanks. Interestingly enough, it works in Python 3, which is what the 
book is about. It doesn't work in Python 2.6


as Thomas Jollans said days ago:
 but you should really install Python 3.1 (it's in ubuntu, as others
 have said!) because you will almost certainly hit into other snags.

or, as Gabriele Lanaro said in that same thread:
 else take a book that covers python 2.x syntax

Cut-and-pasting-ly yours,

~Ethan~

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


Import fails (newbie)

2010-06-17 Thread mhorlick
Hello,

I'm a newbie and I have a small problem. After invoking IDLE --

Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
(Intel)] on win32
Type copyright, credits or license() for more information.
 import os,glob
 os.chdir('D:/Python_Programs')
 print(os.getcwd())
D:\Python_Programs
 print(glob.glob('*.*'))
['humansize.py', 'humansize.pyc']
 import humansize
Traceback (most recent call last):
  File pyshell#5, line 1, in module
import humansize
ImportError: No module named humansize


In a DOS command window I have no problems with the program:

 Directory of D:\Python_Programs

17/06/2010  01:56 PMDIR  .
17/06/2010  01:56 PMDIR  ..
17/06/2010  02:53 PM 1,266 humansize.py
17/06/2010  01:56 PM 1,315 humansize.pyc
   2 File(s)  2,581 bytes
   2 Dir(s)  104,122,085,376 bytes free

D:\Python_Programsc:\python31\python humansize.py
1.0 TB
931.3 GiB

This 'humansize.py' program I got from the book 'Dive Into Python 3'.
I don't know if you need to know the source.

Can someone explain why the 'import' fails?

Thanks,

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


Re: The inverse of .join

2010-06-17 Thread Neil Cerutti
On 2010-06-17, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
 ne...@norwich.edu wrote:
 What's the best way to do the inverse operation of the .join
 function?

 Use the str.split method?

split is perfect except for what happens with an empty string.

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


Processing HTML form

2010-06-17 Thread Bradley Hintze
Hi,

I am a newbie to anything web related, I know a bit  of HTML though.
I've been programing in python for a year or so so I know the language
at an intermediate level. I am wondering if its possible to get info
from an HTML form and pass it to my python code and return a page
based on  the code executed. All of my web searches have been
fruitless as I quickly get lost in the jargon and perhaps not sure
what phrase i should search. Any help would be appreciated.

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


Running a program from another program.

2010-06-17 Thread Laurent Verweijen
I have a program called increment.py as follows: 

#!/usr/bin/python
n = 0
while True:
n = int(raw_input(n)) + 1

This is probably very easy to understand, but I want to run this program
from another python program.
Below is an attempt

 from subprocess import *
 p = Popen([python, increment.py], stdin=PIPE,
stdout=PIPE)
 p.communicate(5)
Traceback (most recent call last):
  File increment.py, line 4, in module
n = int(raw_input(n)) + 1
EOFError: EOF when reading a line
('06', None)
 p.communicate(7)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.6/subprocess.py, line 701, in
communicate
return self._communicate(input)
  File /usr/lib/python2.6/subprocess.py, line 1184, in
_communicate
self.stdin.flush()
ValueError: I/O operation on closed file

How do I make sure the inputstream stays open after the first call to
communicate?


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


Black-Jewish History FAQ - Is The Secret Relationshi p between blacks and jews a “hate literature”?

2010-06-17 Thread nanothermite911fbibustards
http://www.blacksandjews.com/JewsBlackHolocaust.html

Blacks and Jews have been involved in a re-evaluation of their current
and historical relationship. Events of the past several years have
raised both tensions and the level of rhetoric coming from all sides.
The Secret Relationship Between Blacks and Jews is a historical
accounting of the part of the relationship that has been ignored by
both Blacks and Jews.

http://www.blacksandjews.com/BlackJewishFAQ.html

http://www.blacksandjews.com/BlackJewishFAQ.Hate.html

Black-Jewish History FAQ - Is The Secret Relationship between blacks
and jews a “hate literature”?


No. It is truth literature. The release in 1991 of The Secret
Relationship Between Blacks and Jews, Vol. 1, offered the world a
glimpse of how the so-called chosen people have historically related
to the Blacks with whom they have come into contact. Jews, upset with
the revelation, have reacted by condemning the book as “unscholarly”
and “hate literature.” But at the same time many, many academic
libraries have quietly bought the book and put it in their
collections. At least 115 libraries around the world now have the book
in their collections, including such prestigious institutions as Yale,
Harvard, Princeton, Brandeis, Yeshiva University, the Jewish
Theological Seminary, Brown University, Stanford University, even
Cambridge University in London, England, and others in Germany and New
Zealand, all of which have the book on their library shelves.

Some libraries have the book but keep it locked away in a special
location, requiring ID in order to see it. At one point the Brandeis
University library kept it, along with other important works, in what
they called “The Cage.” The Library of Congress wrote to the NOI and
demanded a copy (which was supplied).

There have been more than a dozen books and dozens more articles
written to try to refute The Secret Relationship Between Blacks and
Jews, Vol. 1. One scholar called this new body of scholarship spawned
by The Secret Relationship a “cottage industry.” The Jewish leaders
have held high-level meetings at retailers like Barnes  Noble and
Borders about what to do with this bestseller. One store in California
was putting one of these “refutation” books in the bags of any Black
customer who bought any book on any topic. Canada was stopping The
Secret Relationship at the border and labeling it “contraband.” On the
official form the border agents could check one of three categories:
“pornography,” “hate literature,” or “other.” They checked “other.”

Libraries list the book as “history”—not “hate literature”— and have
deemed it too important to the discourse on the Black–Jewish
relationship to exclude it.

Other Libraries that own Volume 1 include:
FOREIGN
London Library of Haringay, UK
London Library of Newham, UK
Yorkshire Library, UK
Senckenberg Univ., Frankfurt, Germany
Univ. of Otago Library, New Zealand
Vancouver Public Library
Univ. of the W. Indies, Barbados
British Library
University of Toronto Libraries
UNITED STATES
New York University
Smith College
Amherst College
College of the Holy Cross
Northeastern University
UCLA Library
University of California, Davis
University of California, Irvine
University of San Diego
University of Southern California
University of California Berkeley
Hoover Institute, Stanford, CA
University of Texas, Austin
Texas AM University, Kingsville
Maricopa Community Colleges
Whitman College, Walla Walla, WA
Multnomah County Library
Pierce College Library
University of Nevada, Reno
Rice University, Fondren Library
Wisconsin Historical Society
Atlanta-Fulton Public Library
Doane College
California State, Northridge
Florida Atlantic University
Missouri State University
Grambling State University
Pittsburg State University
Southern University in New Orleans
Sam Houston State University
University of Miami
University of West Georgia
University of Iowa Library
University of Florida
Saint Louis Public Library
Southeast Missouri State University
Mervyn H. Sterne Library
Grinnell College
University of Chicago
Chicago Public Library

Loyola University Libraries
Saint Xavier University Library
Milwaukee Library System
Western Kentucky University
University of Illinois
Savannah State University
Fayetteville State University
Michigan State University Libraries
Antioch College
Barber-Scotia College
Davidson College Library
Allen County Public Library
Calvin College  Theological Seminary
Indiana State University
University of Akron
Detroit Public Library
Duke University Library
North Carolina State University
Univ. of North Carolina, Chapel Hill
Ohio State University
Toledo-Lucas County Public Library
Eastern Michigan University Library
University of Michigan Library
Bowling Green State University
Bucknell University
Concordia Univ. Library
McGill University
Delaware State University
University of Maryland, College Park
University of Pittsburgh
Hampton University
Elizabeth City State University
Bowdoin College
Temple University 

* Black-Jewish History FAQ - Is The Secret Relations hip between blacks and jews a “hate literature”? *

2010-06-17 Thread nanothermite911fbibustards
http://www.blacksandjews.com/JewsBlackHolocaust.html

Jews and the Black Holocaust - What are the Issues?

Blacks and Jews have been involved in a re-evaluation of their current
and historical relationship. Events of the past several years have
raised both tensions and the level of rhetoric coming from all sides.
The Secret Relationship Between Blacks and Jews is a historical
accounting of the part of the relationship that has been ignored by
both Blacks and Jews. Most people are not even aware of the extensive
record of encounters between the two groups prior to the 20th century.
The Honorable Louis Farrakhan referred to this well-documented history
in 1984 and was immediately labeled an anti-Semite. Merely
questioning the belief that Jews were co-sufferers in the Black slave
experience draws angry rebukes from Jews of all stripes. The book in
question presents indisputable historical data from census records,
wills, Jewish historians and scholars, rabbinical sermons, port
records, court records, runaway slave notices, slave sale
advertisements, etc., which forces all sides to grapple with the long-
held mythology that Black people always found a friend in the Jews.

Some Jews and their dutiful negros have hired the services of Dr.
Harold Brackman of the Simon Wiesenthal Center in an effort to
preserve the comfortable mythology which has obscured the actual
historical record. But unbeknownst to them, Dr. Brackman's 1977
unpublished Ph.D. dissertation, entitled The Ebb and Flow of Conflict,
goes far beyond The Secret Relationship in its claims of Jewish
conspiracy in the Biblical origin of White supremacy. He clearly
states that Jewish Talmudic scholars invented the Hamitic Myth which,
through the story of Noah, everlastingly assigned to the African the
role of slave and divinely cursed servant of White people. According
to Dr. Tony Martin's book, The Jewish Onslaught, the Jewish invention
of the Hamitic Myth provided the moral pretext upon which the entire
trade grew and flourished.

There is no denying, said Brackman of the story of Noah, that the
Babylonian Talmud was the first source to read a Negrophobic content
into the episode... Brackman pointed out further that two third
century Jewish Sages provided homosexual embellishments for the
Biblical story as well.

This curse was the absolute basis for the Europeans' choice of dark-
skinned Africans for chattel slavery. Many denominations of
Christianity, Islam and Judaism believe it and teach it to this very
moment! Southern plantation owners attacked the Abolitionists with it;
its teaching was the foundation of the slaves' permitted religion;
Black inferiority is based on it; the Ku Klux Klan relies on it; even
the Mormons officially taught it until 1978. When the Jews invented it
and promoted it to the world they sentenced the Black Race to a
holocaust the likes of which no people have ever suffered. Hate
teaching will forever be defined by this wicked belief system brought
to us in the Jewish Holy Talmud via Harold Brackman.

The critics curiously use a Harvard English teacher, Henry Louis
Gates, to offer historical clarity. Gates exhibits no evidence that he
even read the book in his oft-quoted NY Times opinion. His willingness
to make asinine historical claims with the glaring absence of support
from reputable Black or Jewish historians proves Adam Clayton Powell's
axiom: Harvard has ruined more negroes than bad whiskey.

Overwhelming Evidence

The history that the old Black-Jewish Coalition clumsily avoids is
the entire three century history of Jewish presence in South America
and the Caribbean. But other highly acclaimed Jewish scholars have not
been so blind:


•Lee M. Friedman, a one-time president of the American Jewish
Historical Society, wrote that in Brazil, where most of the Africans
actually went, the bulk of the slave trade was in the hands of Jewish
settlers.


•Marcus Arkin wrote that the Jews of Surinam used many thousands of
Black slaves.


•Herbert I. Bloom wrote that the slave trade was one of the most
important Jewish activities here (in Surinam) as elsewhere in the
colonies. He even published a 1707 list of Jewish buyers by name with
the number of Black humans they purchased.


•Cecil Roth, writer of 30 books and hundreds of articles on Jewish
history, wrote that the slave revolts in parts of South America were
largely directed against [Jews] as being the greatest slave-holders of
the region.


•I gather, wrote Jewish scholar Wilfred Samuels, that the Jews [of
Barbados] made a good deal of their money by purchasing and hiring out
negroes...


•According to the Jewish historians, all Barbadian Jews owned slaves -
even the rabbi had the enjoyment of his own two negro attendants.


•In Curaçao which was a major slave trading depot, Isaac and Susan
Emmanuel report that the shipping business was mainly a Jewish
enterprise.


•Says yet another Jewish writer of the Jews of Curaçao, Almost every
Jew bought from one to nine slaves for 

Re: The inverse of .join

2010-06-17 Thread MRAB

Neil Cerutti wrote:

On 2010-06-17, Ian Kelly ian.g.ke...@gmail.com wrote:

On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
ne...@norwich.edu wrote:

What's the best way to do the inverse operation of the .join
function?

Use the str.split method?


split is perfect except for what happens with an empty string.


I see what you mean.

This is consistent:

 ','.join([''])
''
 ''.split(',')
['']

but this isn't:

 ','.join([])
''
 ''.split(',')
['']

An empty string could be the result of .join(['']) or .join([]).

Should .split grow an addition keyword argument to specify the desired
behaviour? (Although it's simple enough to define your own function.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Processing HTML form

2010-06-17 Thread Grant Edwards
On 2010-06-17, Bradley Hintze bradle...@aggiemail.usu.edu wrote:

 I am a newbie to anything web related, I know a bit  of HTML though.
 I've been programing in python for a year or so so I know the language
 at an intermediate level. I am wondering if its possible to get info
 from an HTML form and pass it to my python code and return a page
 based on  the code executed. All of my web searches have been
 fruitless as I quickly get lost in the jargon and perhaps not sure
 what phrase i should search. Any help would be appreciated.

It's not clear what you want.  Are you talking about Python code in an
HTTP client or an HTTP server?

-- 
Grant Edwards   grant.b.edwardsYow! ... I have read the
  at   INSTRUCTIONS ...
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The inverse of .join

2010-06-17 Thread Robert Kern

On 6/17/10 2:08 PM, Neil Cerutti wrote:

On 2010-06-17, Ian Kellyian.g.ke...@gmail.com  wrote:

On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
ne...@norwich.edu  wrote:

What's the best way to do the inverse operation of the .join
function?


Use the str.split method?


split is perfect except for what happens with an empty string.


Why don't you try it and find out?

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: The inverse of .join

2010-06-17 Thread Stephen Hansen
On 6/17/10 12:44 PM, MRAB wrote:
 Neil Cerutti wrote:
 On 2010-06-17, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
 ne...@norwich.edu wrote:
 What's the best way to do the inverse operation of the .join
 function?
 Use the str.split method?

 split is perfect except for what happens with an empty string.

 I see what you mean.
 
 This is consistent:
 
 ','.join([''])
 ''
 ''.split(',')
 ['']
 
 but this isn't:
 
 ','.join([])
 ''
 ''.split(',')
 ['']
 
 An empty string could be the result of .join(['']) or .join([]).
 
 Should .split grow an addition keyword argument to specify the desired
 behaviour? (Although it's simple enough to define your own function.)

Guido finds keyword-arguments-to-change-behavior to be unPythonic, IIRC.
It generally means 'make a new API'. But, the question is-- is it worth
the mental strain of a new API?

This is such an extreme edge case, having to do:

  if blah:
result = blah.split(',')
  else:
result = []

Is really not asking too much, I think.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a program from another program.

2010-06-17 Thread Stephen Hansen
On 6/17/10 12:13 PM, Laurent Verweijen wrote:
 How do I make sure the inputstream stays open after the first call to
 communicate?

This was just asked a few days ago in different words-- check out the
thread, a couple solutions are offered. In short, you need to make
stdin/stdout non-blocking:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/066de1c0fd38642f#

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Possible to reach back in stack and grab calling function's locals()?

2010-06-17 Thread python
Is there an elegant way to reach back in the stack and grab the
calling function's copy of locals()?

I'm working on a library that does lots of textmerge operations
and am looking for a way to eliminate the need for many of the
calls to our library to have to explictly pass locals() to our
formatting functions.

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


Re: The inverse of .join

2010-06-17 Thread Neil Cerutti
On 2010-06-17, Robert Kern robert.k...@gmail.com wrote:
 On 6/17/10 2:08 PM, Neil Cerutti wrote:
 On 2010-06-17, Ian Kellyian.g.ke...@gmail.com  wrote:
 On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
 ne...@norwich.edu  wrote:
 What's the best way to do the inverse operation of the .join
 function?

 Use the str.split method?

 split is perfect except for what happens with an empty string.

 Why don't you try it and find out?

I'm currently using the following without problems, while reading
a data file. One of the fields is a comma separated list, and may
be empty.

  f = rec['codes']
  if f == :
f = []
  else:
f = f.split(,)

I just wondered if something smoother was available.

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


Re: how to get bit info

2010-06-17 Thread Laurent Verweijen
Op donderdag 17-06-2010 om 12:51 uur [tijdzone -0700], schreef Back9: 
 Hi,
 
 I have one byte data and want to know each bit info,
 I mean how I can know each bit is set or not?
 
 TIA

def bitset(x, n):
Return whether nth bit of x was set
return bool(x  (1  n))

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


Re: Serializing functions

2010-06-17 Thread Aaron Staley
I am one of the developer's of PiCloud.

To answer your question, we wrote a custom subclass of Pickler to
pickle functions.  As Robert pointed out, the library is LGPL, so you
can see (and use) the source code.  I also presented the details on a
poster at PyCon 2010.  You can see it here:
http://blog.picloud.com/?p=96


On Jun 17, 9:26 am, Robert Kern robert.k...@gmail.com wrote:
 On 6/17/10 8:23 AM, Matteo Landi wrote:





  Some weeks ago, here on the mailing list I read about picloud[1], a
  python library used for cloud-computing; I was impressed by its
  simplicity, here is an example:

  import cloud
  def square(x):
  ...  return x * x
  cloud.call(square, 10)
  cloud.result()
  100

  So, I tried to figure out how to achieve the same result, i.e. define a
  local generic function and send it somewhere for remote execution, and
  the get the result back.
  So I thought about serialization (pickle): I made a few tries and it
  seemed to work.. but I was wrong, because I never tried to load pickled
  data from another session different from the one used to pickle data
  itself. If you try and pickle a function, it is not pickled as a whole,
  indeed, once you unpickle it, it will raise an exception telling you
  that the target function was not found in the current module.

  So I'm here, with nothing in my hands; how would you implement this?

 PiCloud's client library is LGPLed. Go take a look for yourself. It's pretty 
 nifty.

 [Disclosure: My employer, Enthought, has partnered with PiCloud to provide our
 Enthought Python Distribution to PiCloud users. However, I say that it's nifty
 purely because it is.]

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
   that is made terrible by our own mad attempt to interpret it as though it 
 had
   an underlying truth.
    -- Umberto Eco

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


Re: how to get bit info

2010-06-17 Thread Tim Lesher
On Jun 17, 3:51 pm, Back9 backgoo...@gmail.com wrote:
 Hi,

 I have one byte data and want to know each bit info,
 I mean how I can know each bit is set or not?

You want the bitwise-and operator, .

For example, to check the least significant bit, bitwise-and with 1:

 3  1
1
 2  1
0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get bit info

2010-06-17 Thread Stephen Hansen
On 6/17/10 12:51 PM, Back9 wrote:
 I have one byte data and want to know each bit info,
 I mean how I can know each bit is set or not?

 BIT_1 = 1  0
 BIT_2 = 1  1
 BIT_3 = 1  2
 BIT_4 = 1  3
 BIT_5 = 1  4
 BIT_6 = 1  5
 BIT_7 = 1  6
 BIT_8 = 1  7
 byte = 67
 if byte  BIT_1:
... print Bit 1 is set!
... else:
... print Bit 1 is not set!
Bit 1 is set!
 if not byte  BIT_6:
... byte = byte | BIT_6
... print Bit 6 wasn't set, BUT NOW IS.
Bit 6 wasn't set, BUT NOW IS.
 byte
99

(I added 'how to set a specific bit' just cuz)

Basically, those BIT_X lines are creating numbers which have *only* the
specified bit set. Then you do byte  BIT_X, and that will return 0 if
the byte doesn't have the specified bit in it. You can then set the bit
with byte | BIT_X, and unset the bit with byte ^ BIT_X.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get bit info

2010-06-17 Thread Irmen de Jong

On 17-6-2010 21:51, Back9 wrote:

Hi,

I have one byte data and want to know each bit info,
I mean how I can know each bit is set or not?

TIA


Use bitwise and, for instance, to see if the third bit is set:

byte = 0b
if byte  0b0100:
print bit is set

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


Re: Processing HTML form

2010-06-17 Thread Bradley Hintze
I apologize in advance for my lack of knowledge, I really do not know.
I would guess server but I quite honestly I am not clear what an 'HTTP
client' or 'HTTP server' refers to. I am running a webpage and am
serving it locally for the moment. I have a program that is already
written in Python. I want to make the program available on the web
where I receive user input from HTML forms. The user input will then
be used as parameters for the program. I hope this clear things up.

Thanks,
Bradley

On Thu, Jun 17, 2010 at 3:46 PM, Grant Edwards inva...@invalid.invalid wrote:
 On 2010-06-17, Bradley Hintze bradle...@aggiemail.usu.edu wrote:

 I am a newbie to anything web related, I know a bit  of HTML though.
 I've been programing in python for a year or so so I know the language
 at an intermediate level. I am wondering if its possible to get info
 from an HTML form and pass it to my python code and return a page
 based on  the code executed. All of my web searches have been
 fruitless as I quickly get lost in the jargon and perhaps not sure
 what phrase i should search. Any help would be appreciated.

 It's not clear what you want.  Are you talking about Python code in an
 HTTP client or an HTTP server?

 --
 Grant Edwards               grant.b.edwards        Yow! ... I have read the
                                  at               INSTRUCTIONS ...
                              gmail.com
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Bradley J. Hintze
Graduate Student
Duke University
School of Medicine
801-712-8799
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Processing HTML form

2010-06-17 Thread Marco Nawijn
On 17 jun, 21:11, Bradley Hintze bradle...@aggiemail.usu.edu wrote:
 Hi,

 I am a newbie to anything web related, I know a bit  of HTML though.
 I've been programing in python for a year or so so I know the language
 at an intermediate level. I am wondering if its possible to get info
 from an HTML form and pass it to my python code and return a page
 based on  the code executed. All of my web searches have been
 fruitless as I quickly get lost in the jargon and perhaps not sure
 what phrase i should search. Any help would be appreciated.

 Thank you,
 Bradley

Hi Bradley,

If I understand correctly, you want to do the following:
   1. Fill in a HTML form in a client (web browser)
   2. Send the form to a webserver
   3. Have the webserver extract the information from the form
   4. Send the information to a python program for processing
   5. Generate a new HTML page in python based on the information in
step 4
   6. Send the newly generated page back to the client

Possible solutions depend a little on the constraints and/or options
you have for the webserver. If you are free in your choices I would
suggest to start with cherrypy (www.cherrypy.org) for a webserver. It
is simple to start with, very powerfull and well documented. This
would cover steps 3 and 4. For step 5 I suggest you either use the
python builtin string template facility string.Template (for simple
things). If you want more power have a look at Genshi 
http://genshi.edgewall.org.

The two options I mention above help you to understand whats going on.
If you feel comfortable with this, you can take a look at python web
frameworks like Django or Turbogears (or many others).

Good luck and keep us posted with what your progress.

Regards,

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


Re: List of lists surprising behaviour

2010-06-17 Thread J Kenneth King
candide cand...@free.invalid writes:

 Let's the following code :

 t=[[0]*2]*3
 t
 [[0, 0], [0, 0], [0, 0]]
 t[0][0]=1
 t
 [[1, 0], [1, 0], [1, 0]]

 Rather surprising, isn't it ? 

Not at all, actually.

I'd be surprised if the multiplication operator was aware of object
constructors.  Even arrays are objects in Python.  Should the
multiplication operator know how to instantiate three arrays from a
single array instance?  What about an instance of a user-defined class?

 So I suppose all the subarrays reférence
 the same array :

 id(t[0]), id(t[1]), id(t[2])
 (3077445996L, 3077445996L, 3077445996L)



As they should.


 So what is the right way to initialize to 0 a 2D array ? Is that way
 correct  :


 t=[[0 for _ in range(2)] for _ in range(3)]

 It seems there is no more trouble now :

 t
 [[0, 0], [0, 0], [0, 0]]
 t[0][0]=1
 t
 [[1, 0], [0, 0], [0, 0]]


 Correct ?

 2d_zero_vector = lambda len: [[0, 0] for _ in range(len)]
 t = 2d_zero_vector(3)
 print t
[[0, 0], [0, 0], [0, 0]]
 t[0][0] = 1
 print t
[[1, 0], [0, 0], [0, 0], [0, 0]]

(Of course, if you're doing matrix math you'll probably want to work
with numpy which has a function for doing just this)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get bit info

2010-06-17 Thread Grant Edwards
On 2010-06-17, Stephen Hansen me+list/pyt...@ixokai.io wrote:

 BIT_1 = 1  0
 BIT_2 = 1  1

...

 Basically, those BIT_X lines are creating numbers which have *only* the
 specified bit set. Then you do byte  BIT_X, and that will return 0 if
 the byte doesn't have the specified bit in it. You can then set the bit
 with byte | BIT_X, and unset the bit with byte ^ BIT_X.

Just to clarify, byte ^ BIT_X inverts (toggles) bit X.

If you want to make sure bit X is a 0 (which is what people usually
mean by unset), you do byte  ~BIT_X

-- 
Grant Edwards   grant.b.edwardsYow! I know things about
  at   TROY DONAHUE that can't
  gmail.comeven be PRINTED!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Python distributing localization files

2010-06-17 Thread Gabriele Lanaro
Hi, I want to localize my application (a pygtk gui app), what's the best way
to distribute and install localization files?
I'm currently using `distribute` to package it.

Any suggestion?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Processing HTML form

2010-06-17 Thread Grant Edwards
On 2010-06-17, Bradley Hintze bradle...@aggiemail.usu.edu wrote:

 I apologize in advance for my lack of knowledge, I really do not know.
 I would guess server but I quite honestly I am not clear what an 'HTTP
 client' or 'HTTP server' refers to. I am running a webpage and am
 serving it locally for the moment. I have a program that is already
 written in Python. I want to make the program available on the web
 where I receive user input from HTML forms. The user input will then
 be used as parameters for the program. I hope this clear things up.

Something that serves a web page is an HTTP server, so it sounds like
your program is going to be run by/in the HTTP server.  There are
many, many different ways to do that.  For starters you need to tell
us what OS you're using and what HTTP server you're using.

Or do you want your program to _be_ an HTTP server?

-- 
Grant Edwards   grant.b.edwardsYow! I'm having fun
  at   HITCHHIKING to CINCINNATI
  gmail.comor FAR ROCKAWAY!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The inverse of .join

2010-06-17 Thread Robert Kern

On 6/17/10 3:03 PM, Neil Cerutti wrote:

On 2010-06-17, Robert Kernrobert.k...@gmail.com  wrote:

On 6/17/10 2:08 PM, Neil Cerutti wrote:

On 2010-06-17, Ian Kellyian.g.ke...@gmail.com   wrote:

On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
ne...@norwich.edu   wrote:

What's the best way to do the inverse operation of the .join
function?


Use the str.split method?


split is perfect except for what happens with an empty string.


Why don't you try it and find out?


I would like to apologize. I read that sentence as a question for some reason.

That said, it always helps for you to show the results that you are getting (and 
the code that gives those results) and state what results you were expecting.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Running a program from another program.

2010-06-17 Thread Laurent Verweijen
Op donderdag 17-06-2010 om 13:01 uur [tijdzone -0700], schreef Stephen
Hansen: 
 On 6/17/10 12:13 PM, Laurent Verweijen wrote:
  How do I make sure the inputstream stays open after the first call to
  communicate?
 
 This was just asked a few days ago in different words-- check out the
 thread, a couple solutions are offered. In short, you need to make
 stdin/stdout non-blocking:
 
 http://groups.google.com/group/comp.lang.python/browse_thread/thread/066de1c0fd38642f#
 

I tried putting what Ian Kelly said in my code, by it doesn't work for
me.

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type help, copyright, credits or license for more information.
 import os
 import fcntl
 import subprocess
 process = subprocess.Popen([python, increment.py], stdin =
subprocess.PIPE, stdout = subprocess.PIPE)
 flags = fcntl.fcntl(process.stdout, fcntl.F_GETFL)
 fcntl.fcntl(process.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
0
 process.stdin.write(5\n)
 process.stdout.read()
Traceback (most recent call last):
  File stdin, line 1, in module
IOError: [Errno 11] Resource temporarily unavailable

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


Re: Running a program from another program.

2010-06-17 Thread Stephen Hansen
On 6/17/10 1:42 PM, Laurent Verweijen wrote:
 I tried putting what Ian Kelly said in my code, by it doesn't work for
 me.
 
 Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
 [GCC 4.4.3] on linux2
 Type help, copyright, credits or license for more information.
 import os
 import fcntl
 import subprocess
 process = subprocess.Popen([python, increment.py], stdin =
 subprocess.PIPE, stdout = subprocess.PIPE)
 flags = fcntl.fcntl(process.stdout, fcntl.F_GETFL)
 fcntl.fcntl(process.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
 0
 process.stdin.write(5\n)
 process.stdout.read()
 Traceback (most recent call last):
   File stdin, line 1, in module
 IOError: [Errno 11] Resource temporarily unavailable

I *believe* that error in response to read() is something you should
catch: its EAGAIN. Meaning, for it to perform that operation, it would
have to block, but you've set it to not block.

Thus, your subprocess hasn't written anything new out yet by the time
you call that. You have to try/except looking for that and catch it.

That's why I preferred the recipe I linked to in that thread: it uses
select to only read when there's something -to- actually read.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a program from another program.

2010-06-17 Thread Laurent Verweijen
Op donderdag 17-06-2010 om 13:48 uur [tijdzone -0700], schreef Stephen
Hansen: 
 On 6/17/10 1:42 PM, Laurent Verweijen wrote:
  I tried putting what Ian Kelly said in my code, by it doesn't work for
  me.
  
  Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
  [GCC 4.4.3] on linux2
  Type help, copyright, credits or license for more information.
  import os
  import fcntl
  import subprocess
  process = subprocess.Popen([python, increment.py], stdin =
  subprocess.PIPE, stdout = subprocess.PIPE)
  flags = fcntl.fcntl(process.stdout, fcntl.F_GETFL)
  fcntl.fcntl(process.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
  0
  process.stdin.write(5\n)
  process.stdout.read()
  Traceback (most recent call last):
File stdin, line 1, in module
  IOError: [Errno 11] Resource temporarily unavailable
 
 I *believe* that error in response to read() is something you should
 catch: its EAGAIN. Meaning, for it to perform that operation, it would
 have to block, but you've set it to not block.
 
 Thus, your subprocess hasn't written anything new out yet by the time
 you call that. You have to try/except looking for that and catch it.
 
 That's why I preferred the recipe I linked to in that thread: it uses
 select to only read when there's something -to- actually read.
 

It just gives me an empty string.

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type help, copyright, credits or license for more information.
 from asynchronous import *
 p = Popen([python, increment.py], stdin=PIPE, stdout=PIPE)
 send_all(p, 5\n)
 recv_some(p)
''
 send_all(p, 6\n)
 recv_some(p)
''


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


Re: Processing HTML form

2010-06-17 Thread Bradley Hintze
I am on Mac OSX 10.6, server is apache. If I do get this working we
will move it to the main server which also serves apache, i believe.I
dont think I want a whole new server, I'd like to serve from the
apache framework if possible.

On Thu, Jun 17, 2010 at 4:34 PM, Grant Edwards inva...@invalid.invalid wrote:
 On 2010-06-17, Bradley Hintze bradle...@aggiemail.usu.edu wrote:

 I apologize in advance for my lack of knowledge, I really do not know.
 I would guess server but I quite honestly I am not clear what an 'HTTP
 client' or 'HTTP server' refers to. I am running a webpage and am
 serving it locally for the moment. I have a program that is already
 written in Python. I want to make the program available on the web
 where I receive user input from HTML forms. The user input will then
 be used as parameters for the program. I hope this clear things up.

 Something that serves a web page is an HTTP server, so it sounds like
 your program is going to be run by/in the HTTP server.  There are
 many, many different ways to do that.  For starters you need to tell
 us what OS you're using and what HTTP server you're using.

 Or do you want your program to _be_ an HTTP server?

 --
 Grant Edwards               grant.b.edwards        Yow! I'm having fun
                                  at               HITCHHIKING to CINCINNATI
                              gmail.com            or FAR ROCKAWAY!!
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Bradley J. Hintze
Graduate Student
Duke University
School of Medicine
801-712-8799
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Processing HTML form

2010-06-17 Thread Benjamin Kaplan
On Thu, Jun 17, 2010 at 1:15 PM, Bradley Hintze
bradle...@aggiemail.usu.edu wrote:
 I apologize in advance for my lack of knowledge, I really do not know.
 I would guess server but I quite honestly I am not clear what an 'HTTP
 client' or 'HTTP server' refers to. I am running a webpage and am
 serving it locally for the moment. I have a program that is already
 written in Python. I want to make the program available on the web
 where I receive user input from HTML forms. The user input will then
 be used as parameters for the program. I hope this clear things up.

 Thanks,
 Bradley


HTTP Client = web browser.
HTTP Server = the server,

You'll probably want to use a framework like Django to help you with
this- this is exactly what they were designed to do. What the
frameworks do is let you map URLs to functions. Your form data will
get sent to the server in a POST request, and the framework will hand
that to your function as arguments. Then, your function will generate
the web page (often using a template where you just fill in the
blanks) and send that back to the browser.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py_single_input and the side-effects...

2010-06-17 Thread Mark Lawrence

On 05/06/2010 11:11, Gabriel Genellina wrote:

On 31 mayo, 08:11, moerchendiser2k3googler.
1.webmas...@spamgourmet.com  wrote:


you are right, Python still holds the last
reference. I just set a dummy and thats it :)

Can you tell me where did you get the information from?


Do you mean the _ variable?
It's in the tutorial:
http://docs.python.org/tutorial/introduction.html#using-python-as-a-calculator

--
Gabriel Genellina


I have always believed that the _ variable is only available 
interactively because of this comment in the tutorial:-
In interactive mode, the last printed expression is assigned to the 
variable _. This means that when you are using Python as a desk 
calculator, it is somewhat easier to continue calculations, for example: 
...


However a thread from IIRC a couple of days back used _ to say I'm not 
interested in you, I'm throwing you away in a list comprehension or 
whatever.  I've tried this in a script this evening and it works perfectly.


print 'total', sum(amount for _, amount in outputs)

Where is the use of _ in a script documented, I've searched all over and 
can't find it, guess I don't have the Midas touch with google? :)


Kindest regards.

Mark Lawrence.

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


Re: Running a program from another program.

2010-06-17 Thread Stephen Hansen
On 6/17/10 2:09 PM, Laurent Verweijen wrote:
 It just gives me an empty string.
 
 Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
 [GCC 4.4.3] on linux2
 Type help, copyright, credits or license for more information.
 from asynchronous import *
 p = Popen([python, increment.py], stdin=PIPE, stdout=PIPE)
 send_all(p, 5\n)
 recv_some(p)
 ''
 send_all(p, 6\n)
 recv_some(p)
 ''

Yes, that's how it signals the same situation. The point is: your
subprocess isn't outputting anything. You sure its not crashing out, for
instance?

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a program from another program.

2010-06-17 Thread Laurent Verweijen
Op donderdag 17-06-2010 om 23:09 uur [tijdzone +0200], schreef Laurent
Verweijen: 
 Op donderdag 17-06-2010 om 13:48 uur [tijdzone -0700], schreef Stephen
 Hansen: 
  On 6/17/10 1:42 PM, Laurent Verweijen wrote:
   I tried putting what Ian Kelly said in my code, by it doesn't work for
   me.
   
   Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
   [GCC 4.4.3] on linux2
   Type help, copyright, credits or license for more information.
   import os
   import fcntl
   import subprocess
   process = subprocess.Popen([python, increment.py], stdin =
   subprocess.PIPE, stdout = subprocess.PIPE)
   flags = fcntl.fcntl(process.stdout, fcntl.F_GETFL)
   fcntl.fcntl(process.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
   0
   process.stdin.write(5\n)
   process.stdout.read()
   Traceback (most recent call last):
 File stdin, line 1, in module
   IOError: [Errno 11] Resource temporarily unavailable
  
  I *believe* that error in response to read() is something you should
  catch: its EAGAIN. Meaning, for it to perform that operation, it would
  have to block, but you've set it to not block.
  
  Thus, your subprocess hasn't written anything new out yet by the time
  you call that. You have to try/except looking for that and catch it.
  
  That's why I preferred the recipe I linked to in that thread: it uses
  select to only read when there's something -to- actually read.
  
 
 It just gives me an empty string.
 
 Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
 [GCC 4.4.3] on linux2
 Type help, copyright, credits or license for more information.
  from asynchronous import *
  p = Popen([python, increment.py], stdin=PIPE, stdout=PIPE)
  send_all(p, 5\n)
  recv_some(p)
 ''
  send_all(p, 6\n)
  recv_some(p)
 ''
 
 

I also tried running the module as a program:

from asynchronous import *
p = Popen([python, increment.py], stdin=PIPE, stdout=PIPE)

for n in [5, 7, 10, 4]:
send_all(str(p), n)
print(recv_some(p))

It gives:

prompt:~$ python subchronous_test.py
Traceback (most recent call last):
  File subchronous_test.py, line 5, in module
send_all(str(p), n)
  File /home/Somelauw/asynchronous.py, line 145, in send_all
while len(data):
TypeError: object of type 'int' has no len()
prompt:~$ Traceback (most recent call last):
  File increment.py, line 4, in module
n = int(raw_input(n)) + 1
EOFError: EOF when reading a line
close failed in file object destructor:
Error in sys.excepthook:

Original exception was:

By the way:
synchronous is the name I gave to your module

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


Re: how to get bit info

2010-06-17 Thread Stephen Hansen
On 6/17/10 1:29 PM, Grant Edwards wrote:
 On 2010-06-17, Stephen Hansen me+list/pyt...@ixokai.io wrote:
 
 BIT_1 = 1  0
 BIT_2 = 1  1
 
 ...
 
 Basically, those BIT_X lines are creating numbers which have *only* the
 specified bit set. Then you do byte  BIT_X, and that will return 0 if
 the byte doesn't have the specified bit in it. You can then set the bit
 with byte | BIT_X, and unset the bit with byte ^ BIT_X.
 
 Just to clarify, byte ^ BIT_X inverts (toggles) bit X.
 
 If you want to make sure bit X is a 0 (which is what people usually
 mean by unset), you do byte  ~BIT_X

Doh, you're correct. I got so used to the pattern of only ever flipping
the bit off after for some reason I knew it was on, like:

if blah  CONSTANT_A:
   do-stuff
   blah = blah ^ CONSTANT_A

That I forgot ^ was invert _

Ahem! Thanks for the correction.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a program from another program.

2010-06-17 Thread Laurent Verweijen
Op donderdag 17-06-2010 om 14:36 uur [tijdzone -0700], schreef Stephen
Hansen: 
 On 6/17/10 2:09 PM, Laurent Verweijen wrote:
  It just gives me an empty string.
  
  Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
  [GCC 4.4.3] on linux2
  Type help, copyright, credits or license for more information.
  from asynchronous import *
  p = Popen([python, increment.py], stdin=PIPE, stdout=PIPE)
  send_all(p, 5\n)
  recv_some(p)
  ''
  send_all(p, 6\n)
  recv_some(p)
  ''
 
 Yes, that's how it signals the same situation. The point is: your
 subprocess isn't outputting anything. You sure its not crashing out, for
 instance?
 

No, since it responds to the keyboard:

prompt:~$ python increment.py
05
64
53
44
55
66
75
64
53
44
55
66
7

All output is correct.

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


How to print SRE_Pattern (regexp object) text for debugging purposes?

2010-06-17 Thread dmtr
I need to print the regexp pattern text (SRE_Pattern object ) for
debugging purposes, is there any way to do it gracefully? I've came up
with the following hack, but it is rather crude... Is there an
official way to get the regexp pattern text?

 import re, pickle
 r = re.compile('^abc$', re.I)
 r
_sre.SRE_Pattern object at 0xb7e6a330

 ds = pickle.dumps(r)
 ds
cre\n_compile\np0\n(S'^abc$'\np1\nI2\ntp2\nRp3\n.

 re.search(\n\(S'(.*)'\n, ds).group(1)
'^abc$'


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


Re: Running a program from another program.

2010-06-17 Thread Stephen Hansen
On 6/17/10 2:40 PM, Laurent Verweijen wrote:
 Op donderdag 17-06-2010 om 14:36 uur [tijdzone -0700], schreef Stephen
 Hansen: 
 On 6/17/10 2:09 PM, Laurent Verweijen wrote:
 It just gives me an empty string.

 Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
 [GCC 4.4.3] on linux2
 Type help, copyright, credits or license for more information.
 from asynchronous import *
 p = Popen([python, increment.py], stdin=PIPE, stdout=PIPE)
 send_all(p, 5\n)
 recv_some(p)
 ''
 send_all(p, 6\n)
 recv_some(p)
 ''

 Yes, that's how it signals the same situation. The point is: your
 subprocess isn't outputting anything. You sure its not crashing out, for
 instance?

 
 No, since it responds to the keyboard:

That doesn't really prove the point. There's all kinds of things that
can go wrong when you switch how you run a program.

Wrap your increment.py in like:

import sys
import traceback

try:
   ...
except:
   print sys.stderr, traceback.format_exc()

Then add the arg in your Popen, stderr=sys.stderr

And see if any exception is thrown.

The original error you got, and the empty string from the recipe, both
mean interpret.py is not returning any output. Why? Maybe its erroring
out-- the subprocess context is different then the context of running a
program from the keyboard. Or maybe you're not sending:

In your other thread you include an actual traceback:

Traceback (most recent call last):
  File subchronous_test.py, line 5, in module
send_all(str(p), n)
  File /home/Somelauw/asynchronous.py, line 145, in send_all
while len(data):
TypeError: object of type 'int' has no len()

The first argumetn to send_all should be the actual Popen subclass. The
second should be a string to send. I think that line really is intended
to be:

send_all(p, str(n)) # assuming 'n' is say, the number 5.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Processing HTML form

2010-06-17 Thread Grant Edwards
On 2010-06-17, Bradley Hintze bradle...@aggiemail.usu.edu wrote:

 I am on Mac OSX 10.6, server is apache. If I do get this working we
 will move it to the main server which also serves apache, i believe.I
 dont think I want a whole new server, I'd like to serve from the
 apache framework if possible.

There are a couple different ways to integrate python code into
apache. You can use the normal CGI API where apache runs external
programs written in Python:

  http://docs.python.org/library/cgi.html
  
  http://gnosis.cx/publish/programming/feature_5min_python.html
  http://www.cs.virginia.edu/~lab2q/lesson_1/
  http://www.upriss.org.uk/python/PythonCourse.html
  
Or you can embed Python into apache so that it's faster and you can do
some more sophisticated stuff that's above my head:

  http://www.modpython.org/
  http://onlamp.com/pub/a/apache/2003/04/10/apacheandpython.html

More on both of the above at

  http://www.google.com/search?q=apache+python
  
There are people on the list far more experienced with Python+Apache
than I, so I'll leave it at that.

-- 
Grant Edwards   grant.b.edwardsYow! ... he dominates the
  at   DECADENT SUBWAY SCENE.
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py_single_input and the side-effects...

2010-06-17 Thread Stephen Hansen
On 6/17/10 2:32 PM, Mark Lawrence wrote:
 Where is the use of _ in a script documented, I've searched all over and
 can't find it, guess I don't have the Midas touch with google? :)

Its purely a convention, and one that crosses language-bounds, and isn't
entirely universal even given that.

It just means 'placeholder that I care naught for'; its not a feature,
there's no code or any /ability/ to use it. Its the same as any other
variable name.

It just happens to be a name that conveys no meaning while being short
and visually distinct: except to say you don't care about what value
ends up there, consider it thrown away.

That the interactive interpreter happens to store the last value in a
variable of the same name doesn't really mean anything.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >