Re: Why tarfile.TarFile.gzopen is not in the online documentation?

2010-02-26 Thread Baptiste Lepilleur
2010/2/24 Lars Gustäbel 

> On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote:
> > I stumbled uppon this and find it somewhat odd: some class methods of
> > TarFile and TarInfo do not appears in either the online documentation or
> > search while they have a doc string:
> >
> > http://docs.python.org/search.html?q=gzopen
> >
> http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile
> >
> > See script at the end for list of class methods.
> >
> > Is this "by design" or is there some an odd bug in doc generation lurking
> > around? This somehow seem to be specific to module tarfile. Fraction
> > classmethod from_float() is available in the documentation and found by a
> > search for example...
>
> First of all, Python's module documentation is not generated from module
> docstrings, each module has its own rst text file in the documentation tree
> instead.
>

I was ignorant of that fact. Thanks for letting me know.


> But to answer your question: Yes, this is intentional. The TarFile class
> has
> three classmethods taropen(), gzopen(), and bz2open() each for a specific
> compression method. These three are used internally by the TarFile.open()
> classmethod and are not intended to be called directly. The TarFile.open()
> method is the one that is publicly documented and supposed to be used. It
> decides which of the three methods to use based on the mode argument and
> does many more other high-level things as well.
>

I think it would be best to annotate the help string to let people know of
the facts it is not intended for public usage (or restriction that apply,
e.g. only for subclassing as you hinted in another post).

If I find a method using dir/doc string, I don't check the public
documentation to see if it is present. And even if I did, now that I know
that documentation is maintained separately from the code base, I would
rather assumes a documentation bug than this being by design as is the case
here.

Notes: googling around, there is already a few uses of TarFile.gzopen(). My
guess would be that people find it more convenient for passing compression
level.

Anyway, thanks for writing this module, it very easy to use!

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


Get dosctring without import

2010-02-26 Thread Joan Miller
When a package is imported, it gets the dosctring to store it in
*__doc__*.

Does that funcion is built in python? because I would want use it to
get the docstring without import a package
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get dosctring without import

2010-02-26 Thread Diez B. Roggisch

Am 26.02.10 09:55, schrieb Joan Miller:

When a package is imported, it gets the dosctring to store it in
*__doc__*.

Does that funcion is built in python? because I would want use it to
get the docstring without import a package


You'd need to write your own parser for that. All standard tools simply 
import, see another thread a few days ago where a user had problems with 
help on modules.


Also, without importing, you'd not get docstrings of C-extension-objects.

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


Re: staticmethod and namespaces

2010-02-26 Thread Diez B. Roggisch

Am 26.02.10 06:07, schrieb darnzen:

Having an odd problem that I solved, but wondering if its the best
solution (seems like a bit of a hack).

First off, I'm using an external DLL that requires static callbacks,
but because of this, I'm losing instance info. It could be import
related? It will make more sense after I diagram it:

#Module main.py
from A import *

class App:
 def sperg(self):
  self.a = A()

app = App()
[main loop and such]
  -
# Module A.py
import main
class Foo:
   Selves=[]
  def __init__(self):
Foo.Selves.append(self)
  @staticmethod
  def chum_callback(nType, nP):
# Need to access function / data in app instance
app.sperg(nP)
# Need to access func data in Foo
# I'm pulling 'self' ouf of list made in constructor
self = Foo.getSelf(nP)

  def getSelf(nP):
return self.Selves[nP]

-
So basically I added a list of instances to the base class so I can
get at them from the staticmethod.
What's bothering me the most is I can't use the global app instance in
the A.py module.

How can I get at the app instance (currently I'm storing that along
with the class instance in the constructor)?
Is there another way to do this that's not such a hack?

Sorry for the double / partial post :(


Can you show how you pass the staticmethod to the C-function? Is the DLL 
utilized by ctypes?


I don't see any reason you couldn't use a bound method, which would give 
you your self, instead relying on global state.


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


Re: taking python enterprise level?...

2010-02-26 Thread Diez B. Roggisch

Am 26.02.10 05:01, schrieb D'Arcy J.M. Cain:

On Fri, 26 Feb 2010 01:12:00 +0100
"Diez B. Roggisch"  wrote:

That better way turned out to asynchronous update transactions.  All we
did was keep feeding updates to the remote site and forget about ACKS.
We then had a second process which handled ACKS and tracked which
packets had been properly transferred.  The system had IDs on each
update and retries happened if ACKS didn't happen soon enough.
Naturally we ignored ACKS that we had already processed.


sounds like using UDP to me, of course with a protocol on top (namely
the one you implemented).

Any reason you sticked to TCP instead?


TCP does a great job of delivering a stream of data in order and
handling the retries.  The app really was connection oriented and we
saw no reason to emulate that over an unconnected protocol.  There were
other wheels to reinvent that were more important.


So when you talk about ACKs, you don't mean these on the TCP-level 
(darn, whatever iso-level that is...), but on some higher level?


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


Re: taking python enterprise level?...

2010-02-26 Thread mdipierro
100,000 hits a day is not a low. I get that some day on my web server
without problem and without one request dropped.

Most frameworks web2py, Django, Pylons can handle that kind of load
since Python is not the bottle neck.
You have to follow some tricks:

1) have the web server serve static pages directly and set the pragma
cache expire to one month
2) cache all pages that do not have forms for at least few minutes
3) avoid database joins
4) use a server with at least 512KB Ram.
5) if you pages are large, use gzip compression

If you develop your app with the web2py framework, you always have the
option to deploy on the Google App Engine. If you can live with their
constraints you should have no scalability problems.

Massimo



On Feb 25, 4:26 am, simn_stv  wrote:
> hello people, i have been reading posts on this group for quite some
> time now and many, if not all (actually not all!), seem quite
> interesting.
> i plan to build an application, a network based application that i
> estimate (and seriously hope) would get as many as 100, 000 hits a day
> (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook'
> or anything like it, its mainly for a financial transactions which
> gets pretty busy...
> so my question is this would anyone have anything that would make
> python a little less of a serious candidate (cos it already is) and
> the options may be to use some other languages (maybe java, C (oh
> God))...i am into a bit of php and building API's in php would not be
> the hard part, what i am concerned about is scalability and
> efficiency, well, as far as the 'core' is concerned.
>
> would python be able to manage giving me a solid 'core' and will i be
> able to use python provide any API i would like to implement?...
>
> im sorry if my subject was not as clear as probably should be!.
> i guess this should be the best place to ask this sort of thing, hope
> im so right.
>
> Thanks

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


Re: Why tarfile.TarFile.gzopen is not in the online documentation?

2010-02-26 Thread Lars Gustäbel
On Fri, Feb 26, 2010 at 09:28:04AM +0100, Baptiste Lepilleur wrote:
> 2010/2/24 Lars Gustäbel 
> 
> > On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote:
> > > I stumbled uppon this and find it somewhat odd: some class methods of
> > > TarFile and TarInfo do not appears in either the online documentation or
> > > search while they have a doc string:
> > >
> > But to answer your question: Yes, this is intentional. The TarFile class
> > has three classmethods taropen(), gzopen(), and bz2open() each for a
> > specific compression method. These three are used internally by the
> > TarFile.open() classmethod and are not intended to be called directly. The
> > TarFile.open() method is the one that is publicly documented and supposed
> > to be used. It decides which of the three methods to use based on the mode
> > argument and does many more other high-level things as well.
> >
> 
> I think it would be best to annotate the help string to let people know of
> the facts it is not intended for public usage (or restriction that apply,
> e.g. only for subclassing as you hinted in another post).

Well, then please take the time and open an issue at bugs.python.org, so
that this won't get lost. I will then see what I can do.

-- 
Lars Gustäbel
l...@gustaebel.de

Linux is like a wigwam - no Gates, no Windows, Apache inside.
-- 
http://mail.python.org/mailman/listinfo/python-list


modbus pymodbus

2010-02-26 Thread Ippolito Nievo
Hi all, someone can help me to pymodbus use? I must send some command
and read aswer from an inverter. It use ModBus RTU.

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


Re: A more pythonish code

2010-02-26 Thread prasad_chand
Hi Mr.Posner & nn,

Thank your for your time & effort. I never knew that for...ever
combination even existed. I would keep these insights in mind in the
future.

Thanks again,
Prasad

On Feb 25, 10:57 pm, John Posner  wrote:
> On 2/25/2010 7:23 AM, prasad_chand wrote:
>
>
>
> > Hi,
>
> > I use python to do simple math problems as a hobby.
>
> > I have made a program that finds the number of divisors(factors) of a
> > given number. I am hoping to improve my language skills, specifically
> > I would like to re-write the function "prime_factors" more gracefully.
> > While the program works right, I am hoping that I could get some input
> > on how to write better python code. I have attached the code below.
>
> > def prime_factors(n):
> >      """
> >      Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1)
> > (1+1) = 10)
>
> >      Updates a global dictionary(my_dict) with prime numbers and number
> > of occurances. In the case of 48 {2:4,3:1}
>
> >      """
> >      tmp_n = n
>
> A name meaning "temporary value of n" doesn't suggest how it's being
> used in the algorithm. In my implementation (see below), I used the name
> "last_result", which is (a little bit) better.
>
>
>
> >      while True:
>
> >          if tmp_n == 1:
> >              break
>
> >          tmp_check = tmp_n
>
> >          for x in range(2,int(ceil(sqrt(tmp_n)) + 1)):
> >              if tmp_n % x == 0:
> >                  add_to_dict(x)
>
> This function changes the value of a global variable, *my_dict*. Using
> global variables is frowned upon. In this case, it would be much better
> to have the dictionary be local to the *prime_factor* function. After
> you've broken out of the *while* loop, just execute "return my_dict".
>
> >                  tmp_n /= x
> >                  break
>
> >          if tmp_check == tmp_n: #number is prime...so just to add to
> > dict
> >              add_to_dict(tmp_n)
> >              break
>
> The only reason that the *tmp_check* variable exists is to test whether
> you fell out of the *for* loop without finding any divisors for *tmp_n*.
> A cleaner approach is to use the optional *else* clause of the *for*
> loop, which is executed only if you didn't *break* out of the loop:
>
>      for x in range(2,int(ceil(sqrt(tmp_n)) + 1)):
>          if tmp_n % x == 0:
>              add_to_dict(x)
>              tmp_n /= x
>              break
>      else:
>          # tmp_n is prime...so just to add to dict
>          add_to_dict(tmp_n)
>          break
>
>
>
> > def add_one(x):
> >      return x+1
>
> > def mul(x,y):
> >      return x * y
>
> > def add_to_dict(p_num):
> >      if my_dict.has_key(p_num):
> >          my_dict[p_num] += 1
> >      else:
> >          my_dict[p_num] = 1
>
> As poster pruebauno pointed out, using a collections.defaultdict
> eliminates the need for the *add_to_dict* function.
>
>
>
> > my_dict = {}
>
> > prime_factors(135)
> > l = map(add_one,my_dict.values())
> > print reduce(mul, l, 1)
>
> This may seem trivial, but ... don't use the single-character lowercase
> "l" as a variable. It looks too much like the digit "1" -- in some
> fonts, it looks identical!
>
> FWIW, here's my implementation. It's much slower, because it doesn't use
> the square root optimization. It uses another optimization: when a prime
> factor is located, *all* of its occurrences are factored out at the same
> time.
>
> #
> from collections import defaultdict
>
> def prime_factors(n):
>      """Return the prime factors of the given number (>= 2)"""
>      if n < 2:
>          print "arg must be >= 2"
>          return
>
>      last_result = n
>      factors = defaultdict(int)
>      next_divisor = 2
>
>      while True:
>          while last_result % next_divisor == 0:
>              factors[next_divisor] += 1
>              last_result /= next_divisor
>              if last_result == 1:
>                  return factors
>          next_divisor += 1
> #
>
> HTH,
> John

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


Re: Get dosctring without import

2010-02-26 Thread Jean-Michel Pichavant

Joan Miller wrote:

When a package is imported, it gets the dosctring to store it in
*__doc__*.

Does that funcion is built in python? because I would want use it to
get the docstring without import a package
  
Epydoc, a documentation builder is able to do so with the --parse-only 
option. You could take a look at the code, even grab their parser to 
suit your needs. It may be quite difficult though.


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


Re: Get dosctring without import

2010-02-26 Thread Ben Finney
Joan Miller  writes:

> When a package is imported, it gets the dosctring to store it in
> *__doc__*.

Joan, in this message and numerous others you've been following the
widespread convention of using asterisks ‘*’ to surround text you want
to emphasise.

Normally that's good, but in a programming-language context (or any
other where asterisks have a separate established meaning), it's not a
good idea. In many cases, asterisks signify “match any number of
arbitrary characters at this position”, which gives a rather different
meaning to what you're writing.

You might be better off using quotes (like '__doc__' or ‘__doc__’), or
the reStructuredText syntax for demarcating a special element, backticks
(like `__doc__`). Even they need to be used with care, though, because
they also have specific established meanings (except the typographical
quotes, which is why I use them).

I hope that helps.

> Does that funcion is built in python? because I would want use it to
> get the docstring without import a package

Why is it you want to do this? Modules should not have unwanted side
effects when imported; if you can't import the module without invoking
those unwanted side effects, the module is poorly written.

That's not to say that such poorly-written modules don't exist. What is
the situation? Perhaps there's a better solution.

-- 
 \  “Earth gets its price for what Earth gives us.” —James Russell |
  `\Lowell |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get dosctring without import

2010-02-26 Thread Peter Otten
Joan Miller wrote:

> When a package is imported, it gets the dosctring to store it in
> *__doc__*.
> 
> Does that funcion is built in python? because I would want use it to
> get the docstring without import a package

Something to get you started:


import ast


def walk(root, stack):
for node in ast.iter_child_nodes(root):
if isinstance(node, (ast.FunctionDef, ast.ClassDef)):
yield node
stack.append(node)
for child in walk(node, stack):
yield child
del stack[-1]

def get_name(node):
try:
return node.name
except AttributeError:
return "(%s)" % node.__class__.__name__

def get_path(path):
return ".".join(get_name(node) for node in path)

def find_docstrings(filename):
with open(filename) as f:
module = ast.parse(f.read())
print filename.center(len(filename) + 2).center(80, "=")
print ast.get_docstring(module)
print "=" * 80
print

path = []
for node in walk(module, path):
s = ast.get_docstring(node)
if s is not None:
name = get_path(path + [node])
print name.center(len(name) + 2).center(80, "-")
print s
print


if __name__ == "__main__":
import sys
args = sys.argv[1:]
if args:
for arg in args:
find_docstrings(arg)
else:
find_docstrings("/usr/lib/python2.6/unittest.py")
assert "unittest" not in sys.modules

To get an idea of the differences to the import-based approach try analysing 
the following script:

import random

if random.choice([True, False]):
def f():
"say hello"
else:
def f():
"kill a kitten"

def g():
"whatever"
del g

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


Re: Executable problem - socket?

2010-02-26 Thread Lawrence D'Oliveiro
In message , Gib Bogle wrote:

> The only clue is that the machines that her program runs on have
> Python installed, while the one that fails doesn't.

Wouldn’t it be a whole lot simpler to install Python on the bloody machine?

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


Re: Get dosctring without import

2010-02-26 Thread Joan Miller
On 26 feb, 10:51, Ben Finney  wrote:
> Joan Miller  writes:
> > When a package is imported, it gets the dosctring to store it in
> > *__doc__*.
>
> Joan, in this message and numerous others you've been following the
> widespread convention of using asterisks ‘*’ to surround text you want
> to emphasise.
>
> Normally that's good, but in a programming-language context (or any
> other where asterisks have a separate established meaning), it's not a
> good idea. In many cases, asterisks signify “match any number of
> arbitrary characters at this position”, which gives a rather different
> meaning to what you're writing.
>
> You might be better off using quotes (like '__doc__' or ‘__doc__’), or
> the reStructuredText syntax for demarcating a special element, backticks
> (like `__doc__`). Even they need to be used with care, though, because
> they also have specific established meanings (except the typographical
> quotes, which is why I use them).
>
> I hope that helps.
>
> > Does that funcion is built in python? because I would want use it to
> > get the docstring without import a package
>
> Why is it you want to do this? Modules should not have unwanted side
> effects when imported; if you can't import the module without invoking
> those unwanted side effects, the module is poorly written.
>
> That's not to say that such poorly-written modules don't exist. What is
> the situation? Perhaps there's a better solution.
I use a function in 'setupy.py' to get automatically the description
from the package's docstring, but there is a problem when you import a
module that has to be built by cython (because it tries load a module
that doesn't exists).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get dosctring without import

2010-02-26 Thread Joan Miller
On 26 feb, 10:57, Peter Otten <__pete...@web.de> wrote:
> Joan Miller wrote:
> > When a package is imported, it gets the dosctring to store it in
> > *__doc__*.
>
> > Does that funcion is built in python? because I would want use it to
> > get the docstring without import a package
>
> Something to get you started:
>
> import ast
>
> def walk(root, stack):
>     for node in ast.iter_child_nodes(root):
>         if isinstance(node, (ast.FunctionDef, ast.ClassDef)):
>             yield node
>         stack.append(node)
>         for child in walk(node, stack):
>             yield child
>         del stack[-1]
>
> def get_name(node):
>     try:
>         return node.name
>     except AttributeError:
>         return "(%s)" % node.__class__.__name__
>
> def get_path(path):
>     return ".".join(get_name(node) for node in path)
>
> def find_docstrings(filename):
>     with open(filename) as f:
>         module = ast.parse(f.read())
>     print filename.center(len(filename) + 2).center(80, "=")
>     print ast.get_docstring(module)
>     print "=" * 80
>     print
>
>     path = []
>     for node in walk(module, path):
>         s = ast.get_docstring(node)
>         if s is not None:
>             name = get_path(path + [node])
>             print name.center(len(name) + 2).center(80, "-")
>             print s
>             print
>
> if __name__ == "__main__":
>     import sys
>     args = sys.argv[1:]
>     if args:
>         for arg in args:
>             find_docstrings(arg)
>     else:
>         find_docstrings("/usr/lib/python2.6/unittest.py")
>         assert "unittest" not in sys.modules
>
> To get an idea of the differences to the import-based approach try analysing
> the following script:
>
> import random
>
> if random.choice([True, False]):
>     def f():
>         "say hello"
> else:
>     def f():
>         "kill a kitten"
>
> def g():
>     "whatever"
> del g
>
> Peter

Thanks! What I need there is:

-
with open(os.path.join(path, package, '__init__.py')) as f:
module = ast.parse(f.read())

print ast.get_docstring(module)
-- 
http://mail.python.org/mailman/listinfo/python-list


[M2Crypto] Problems uploading to IIS using FTP over SSL

2010-02-26 Thread Stephen Nelson-Smith
System:

# rpm -q python m2crypto
python-2.4.3-27.el5
m2crypto-0.16-6.el5.6
# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 5.4 (Tikanga)
I have the following method:

def ftp_tarball(aggregation_dir, date_format, ftp_server, ftp_user,
ftp_pass):
  date = datetime.today().strftime(date_format)
  ftp = ftpslib.FTP_TLS()
  ftp.connect(ftp_server)
  ftp.auth_tls()
  ftp.set_pasv(0)
  ftp.login(ftp_user, ftp_pass)
  filename = aggregation_dir + 'zultys-logs_' + date + '.tar.gz'
  short_name = os.path.split(filename)[1]
  tarball = open(filename, 'rb')
  ftp.storbinary('STOR ' + short_name, tarball)
  tarball.close()
  ftp.quit()

This works perfectly with VSFTPD on Linux, with SSL forced for non-
anonymous users.

I try to connect to a supplier's IIS FTP server, and get:

Traceback (most recent call last):
  File "/usr/local/bin/lumberjack", line 45, in ?
lumberjack.ftp_tarball( aggregation_dir, date_format, ftp_server,
ftp_user, ftp_pass )
  File "/usr/lib64/python2.4/site-packages/lumberjack.py", line 93, in
ftp_tarball
ftp.storbinary('STOR ' + short_name, tarball)
  File "/usr/lib64/python2.4/ftplib.py", line 415, in storbinary
conn = self.transfercmd(cmd)
  File "/usr/lib64/python2.4/ftplib.py", line 345, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
  File "/usr/lib64/python2.4/site-packages/M2Crypto/ftpslib.py", line
86, in ntransfercmd
conn, size = FTP.ntransfercmd(self, cmd, rest)
  File "/usr/lib64/python2.4/ftplib.py", line 331, in ntransfercmd
sock = self.makeport()
  File "/usr/lib64/python2.4/ftplib.py", line 292, in makeport
resp = self.sendport(host, port)
  File "/usr/lib64/python2.4/ftplib.py", line 256, in sendport
return self.voidcmd(cmd)
  File "/usr/lib64/python2.4/ftplib.py", line 246, in voidcmd
return self.voidresp()
  File "/usr/lib64/python2.4/ftplib.py", line 221, in voidresp
resp = self.getresp()
  File "/usr/lib64/python2.4/ftplib.py", line 216, in getresp
raise error_perm, resp
ftplib.error_perm: 501 Server cannot accept argument.

A colleague is able to connect using the Filezilla client, configured
as servertype: FTPES - FTP over explicit TLS/SSL setting.

I've not been able to find any further guidnance on the web.

If you've experienced this before, or can see something that I've
obviously got wrong, I'd appreciate your help.

TIA,

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


PyQt 4.7 installation on Windows

2010-02-26 Thread Gib Bogle
I've just installed Python 2.6.4 and PyQt 4.7 on my Windows machine, on which I 
was using Python 2.5 and PyQt 4.5.  Now 'from PyQt4 import QtGui'
fails to find the DLL.  Some googling shows that others have encountered the 
same problem, and a workaround is to copy QtGui4.dll (for example) from

D:\Python26\Lib\site-packages\PyQt4\bin
to
D:\Python26\Lib\site-packages\PyQt4
This is obviously not a solution, just a clue.  Another clue is that the Python 
2.5 installation didn't have the \bin subdirectory, instead all the DLLs were in 
PyQt4.  It looks as if for 2.6 the DLLs have been moved but the search path 
hasn't been changed.  sys.path includes D:\python26\lib\site-packages, and the 
Windows PATH environment variable includes D:\Python26\Lib\site-packages\PyQt4\bin


For some reason I have a sense of deja vu.  Can anyone help?
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's the word on using """ to comment-out?

2010-02-26 Thread Michael Rudolf

Am 25.02.2010 17:39, schrieb Grant Edwards:

IMO, any sort of "commented out" code left in a program is a
big mistake.  If the code is soething that does need to stay
for optional use, then it needs to be properly integrated along
with logic to control when it's used.


OK, then we are perfectly fine and of course for personal use everyone 
can "comment out" code as they wish.


I'd just hate to see something like "if False" in production level code.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's the word on using """ to comment-out?

2010-02-26 Thread Michael Rudolf

Am 26.02.2010 12:47, schrieb Michael Rudolf:

I'd just hate to see something like "if False" in production level code.


And yeah, I've seen it. And worse.
--
http://mail.python.org/mailman/listinfo/python-list


Re: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens

2010-02-26 Thread Jonathan Fine

Wes James wrote:

On Wed, Feb 24, 2010 at 5:03 AM, Jonathan Fine  wrote:

Hi

Does anyone know of a collection of regular expressions that will break a
TeX/LaTeX document into tokens?  Assume that there is no verbatim or other
category code changes.


I'm not sure how this does it, but it might help:

http://plastex.sourceforge.net/plastex/sect0025.html


Thanks, Wes.  I'm already using PlasTeX

It handles changes of category codes, which makes it over the top for 
what I want to do.  In addition it is a  fairly large complex 
application, and sadly it's not at all easy to use just a part of the 
code base.


There's been more discussion of this thread on comp.text.tex (which is 
where I set the follow-up to).


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


(and about tests) Re: Pedantic pickling error after reload?

2010-02-26 Thread Robert

Diez B. Roggisch wrote:

Am 25.02.10 18:08, schrieb Robert:

After (intended/controlled) reload or similar action on a module/class
the pickle/cPickle.dump raises errors like

pickle.PicklingError: Can't pickle : it's
not the same object as somemodule.SomeClass


Cause in pickle.py (and cPickle) is a line
"if klass is not obj:"

Shouldn't it be enough to have "if klass.__name__ != obj.__name__:"
there?


No. This would alias classes of same name, but living in different modules.

So at least you need to compare these, too. I'm not sure if there aren't


at that point of comparison the module is already identical 
("klass = getattr(mod, name)")



even more corner-cases. Python's import-mechanism can sometimes be
rather foot-shoot-prone.


still don't see a real reason against the mere module+name 
comparison. same issues as during pickle.load. Just the class 
object is renewed (intentionally)


If there are things with nested classes etc, the programmer will 
have to rethink things on a different level: design errors. a 
subject for pychecker/pylint - not for breaking pickle .dump ... ?





=> a bug report/feature request?

Classes can change face anyway during pickled state, why should a
over-pedantic reaction break things here during runtime?
(So far I'd need to walk the object tree in all facets and save against
inf loops like pickle himself and re-class things .. )


If anything it's a feature - and I doubt it's really needed. Because
reloading pickles with intermittend reload-module-operations is to rare
a case to be really supported IMHO.


well, reloading is the thing which I do most in coding practice :-)
For me its a basic thing like cell proliferation in biology.

In my projects particularly with GUI or with python based http 
serving, I typically support good live module reloadabily even 
actively by some extra little "reload support code" (which fixes 
up the .__class__ etc of living Windows tree, main objects, 
servers ... plus a ´xisinstance´ in very few locations) - at least 
I do this for the frequently changing core modules/classes.
This way I feel a edit-run cycle >2x faster when the project is 
getting bigger and bigger, or when developing things out 
interactively. Code is exchanged frequently while living objects 
stay for long ... works well in practice.


Reentering into the same (complex) app state for evolving those 
thousands of small thing (where a full parallel test coverage 
doesn't work out) is a major dev time consuming factor in bigger 
projects - in C, Java projects and even with other dynamic languages.
Dynamic classes are a main reason why I use Python (adopted from 
Lisp long time ago; is that reload thing here possible with Ruby too?)


I typically need just 1 full app reboot on 20..50 edit-run-cycles 
I guess. And just few unit test runs per release. Even for 
Cython/pyximport things I added support for this reload 
edit-run-cycle, because I cannot imagine to dev without this.


Just standard pickle issues stood in the way. And this patch (and 
a failover from cPickle to pickle) did well so far.





Do yourself a favor, write a unit-test that tests the desired behavior
that makes you alter your code & then reload. This makes the problem go
away, and you have a more stable development through having more tests :)


this is a comfortable quasi religious theory raised often and 
easily here and there - impracticable and very slow on that fine 
grained code evolution level however. an interesting issue.


I do unit tests for getting stability on a much higher level 
where/when things and functionality are quite wired.
Generally after having compared I cannot confirm that "write 
always tests before development" ideologies pay off in practice.
"Reload > pychecker/pylint > tests" works most effectively with 
Python in my opinion.

And for GUI-development the difference is max.
(min for math algorithms which are well away from data structures/OO)


Another issue regarding tests IMHO is, that one should not waste 
the "validation power" of unit tests too easily for permanent low 
level evolution purposes because its a little like bacteria 
becoming resistent against antibiotics: Code becoming 'fit' 
against artificial tests, but not against real word.
For example in late stage NASA tests of rockets and like, there is 
a validation rule, that when those tests do not go through green, 
there is not just a fix of the (one) cause - screwing until it 
works. the whole thing is at stake.
And the whole test scheme has to be rethought too. ideally, 
whenever such a late test brakes, it requires that a completely 
new higher test has to be invented (in addition) ... until there 
is a minimal set of "fresh green lights" which were red only 
during there own tests, but never red regarding the real test run.


A rule that unit tests are used only near a release or a milestone 
is healthy in that sense I think.

(And a quick edit-(real)run-interact cycle is good for speed)


Robert
--
h

Challenge: escape from the pysandbox

2010-02-26 Thread Victor Stinner
Hi,

pysandbox is a new Python sandbox project under development. By default, 
untrusted code executed in the sandbox cannot modify the environment (write a 
file, use print or import a module). But you can configure the sandbox to 
choose exactly which features are allowed or not, eg. import sys module and 
read the file /etc/issue.

I think that the project reached the "testable" stage. I launch a new 
challenge: try to escape from the sandbox. I'm unable to write strict rules. 
The goal is to access objects outside the sandbox. Eg. write into a file, 
import a module which is not in the whitelist, modify an object outside the 
sandbox, etc.

To test the sandbox, you have 3 choices:
 - interpreter.py: interactive interpreter executed in the sandbox, use:
--verbose to display the whole sandbox configuration,
--features=help to enable help() function,
--features=regex to enable regex,
--help to display the help.
 - execfile.py : execute your script in the sandbox. 
   It has also --features option: use --features=stdout to be able 
   to use the print instruction :-)
 - use directly the Sandbox class: use methods call(), execute()
   or createCallback()

Don't use "with sandbox: ..." because there is known but with local frame 
variables. I think that I will later drop this syntax because of this bug. 
Except of debug_sandbox, I consider that all features are safe and so you can 
enable all features :-)

There is no prize, it's just for fun! But I will add the name of hackers 
founding the best exploits.

pysandbox is not ready for production, it's under heavy development. Anyway I 
*hope* that you will quickly find bugs!

--

Use tests.py to found some examples of how you can escape a sandbox. pysandbox 
is protected against all methods described in tests.py ;-)

See the README file to get more information about how pysandbox is implemented 
and get a list of other Python sandboxes.

pysandbox is currently specific to CPython, and it uses some ugly hacks to 
patch CPython in memory. In the worst case it will crash the pysandbox Python 
process, that's all. I tested it under Linux with Python 2.5 and 2.6. The 
portage to Python3 is not done yet (is someone motivated to write a 
patch? :-)).

-- 
Victor Stinner
http://www.haypocalc.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Quoting quotes

2010-02-26 Thread candide
Suppose you have to put into a Python string the following sentence :

The play "All's Well That Ends Well" by Shakespeare

It's easy do it :

>>> print """The play "All's Well That Ends Well" by Shakespeare"""
The play "All's Well That Ends Well" by Shakespeare

Now, change the sentence to this one :

The play "All's Well That Ends Well"

Using triple single quotes works fine

>>> print '''The play "All's Well That Ends Well"'''
The play "All's Well That Ends Well"


But the first method doesn't run correctly :


>>> print """The play "All's Well That Ends Well
  File "", line 1
print """The play "All's Well That Ends Well
   ^
SyntaxError: EOL while scanning single-quoted string
>>>


Any comment ?


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


Re: Challenge: escape from the pysandbox

2010-02-26 Thread Victor Stinner
Le vendredi 26 février 2010 13:29:33, Victor Stinner a écrit :
> pysandbox is a new Python sandbox project

... I just forget to explain how to download it.

Website: http://github.com/haypo/pysandbox/

Download the repository using git:
  git clone git://github.com/haypo/pysandbox.git 
or
  git clone http://github.com/haypo/pysandbox.git

Or download the .zip or .tar.gz tarball using the "Download source" button on 
the website.

-- 
Victor Stinner
http://www.haypocalc.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quoting quotes

2010-02-26 Thread Ivan Šipoš

On 26.2.2010. 13:29, candide wrote:

Suppose you have to put into a Python string the following sentence :

The play "All's Well That Ends Well" by Shakespeare

It's easy do it :

   

print """The play "All's Well That Ends Well" by Shakespeare"""
 

The play "All's Well That Ends Well" by Shakespeare

Now, change the sentence to this one :

The play "All's Well That Ends Well"

Using triple single quotes works fine

   

print '''The play "All's Well That Ends Well"'''
 

The play "All's Well That Ends Well"


But the first method doesn't run correctly :


   

print """The play "All's Well That Ends Well
 

   File "", line 1
 print """The play "All's Well That Ends Well
^
SyntaxError: EOL while scanning single-quoted string
   
 


Any comment ?


   

Well, there's no such thing as  defined in python.

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


Re: Get dosctring without import

2010-02-26 Thread Ben Finney
Joan Miller  writes:

> I use a function in 'setupy.py' to get automatically the description
> from the package's docstring, but there is a problem when you import a
> module that has to be built by cython (because it tries load a module
> that doesn't exists).

A simple approach (at least, simpler than crawling a parse tree) might
be to store the package description in a separate non-executable file.

A common convention is to have a ‘README’ text file, written in
reStructuredText for rendering to various output formats as part of the
documentation. You could then have the ‘setup.py’ program read the
contents of that file and use it (or a slice of it) for the package
description.

-- 
 \ “Sometimes I — no, I don't.” —Steven Wright |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quoting quotes

2010-02-26 Thread Victor Stinner
Le vendredi 26 février 2010 13:29:04, candide a écrit :
> But the first method doesn't run correctly :
> >>> print """The play "All's Well That Ends Well
> 
>   File "", line 1
> print """The play "All's Well That Ends Well
>^
> SyntaxError: EOL while scanning single-quoted string

Use triple simple single quotes:

>>> print '''"All's Well That Ends Well"'''
"All's Well That Ends Well"

-- 
Victor Stinner
http://www.haypocalc.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Docstrings considered too complicated

2010-02-26 Thread Andreas Waldenburger
On Thu, 25 Feb 2010 12:51:00 -0800 (PST) John Roth
 wrote:

> On Feb 24, 1:23 pm, Andreas Waldenburger 
> wrote:
> > a company that works with my company writes a lot of of their code
> > in Python (lucky jerks). I've seen their code and it basically
> > looks like this:
> >
> > """Function that does stuff"""
> > def doStuff():
> >     while not wise(up):
> >         yield scorn
> > [snip]
> Is the problem that they've got the docstring in the wrong place,
> or that the comment isn't saying anything that can't be read in
> the method name?
> 
It's the first. I am superficial like that. I just needed a docstring
to illustrate and didn't want to get overly creative.

Not that they don't write redundant docstrings.

And they use mixedCase function/method names.

And they write getters and setters gratuitously.


> The first is easily fixable with a bit of tutorial about how
> a properly placed docstring prints out in various contexts, plus
> a quick script to move the suckers.
> 
Well, I'm not really in a position to tell them that. I'd be kind of
the dork of the office in doing so. Thus my kvetching here. :)

So basically, there is nothing to discuss, really. I just wanted to
remind everyone that there are still morons out there (as in "lacking
esprit and mental flexibility"), make everyone feel better about
themselves (because surely THEY don't do that!) and then carry on.


> The second is going to take more work to get the point across
> that comments that reproduce what the method name says are waste.
> 
They seem to need the reassurance, I guess, so why not let them. ;)

/W


-- 
INVALID? DE!

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


Re: Get dosctring without import

2010-02-26 Thread Joan Miller
On 26 feb, 12:35, Ben Finney  wrote:
> Joan Miller  writes:
> > I use a function in 'setupy.py' to get automatically the description
> > from the package's docstring, but there is a problem when you import a
> > module that has to be built by cython (because it tries load a module
> > that doesn't exists).
>
> A simple approach (at least, simpler than crawling a parse tree) might
> be to store the package description in a separate non-executable file.
>
> A common convention is to have a ‘README’ text file, written in
> reStructuredText for rendering to various output formats as part of the
> documentation. You could then have the ‘setup.py’ program read the
> contents of that file and use it (or a slice of it) for the package
> description.
I get the 'README.txt' file to get the long description but I use the
docstring because each package should include a short desciption about
it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quoting quotes

2010-02-26 Thread Benjamin Kaplan
On Fri, Feb 26, 2010 at 7:29 AM, candide  wrote:

> Suppose you have to put into a Python string the following sentence :
>
> The play "All's Well That Ends Well" by Shakespeare
>
> It's easy do it :
>
> >>> print """The play "All's Well That Ends Well" by Shakespeare"""
> The play "All's Well That Ends Well" by Shakespeare
>
> Now, change the sentence to this one :
>
> The play "All's Well That Ends Well"
>
> Using triple single quotes works fine
>
> >>> print '''The play "All's Well That Ends Well"'''
> The play "All's Well That Ends Well"
>
>
> But the first method doesn't run correctly :
>
>
> >>> print """The play "All's Well That Ends Well
>  File "", line 1
>print """The play "All's Well That Ends Well
>   ^
> SyntaxError: EOL while scanning single-quoted string
> >>>
>
>
> Any comment ?
>
>
>

You have 4 quotes at the end of the line instead of 3. So the first 3 close
the long quote and then the 4th opens a new quote which doesn't get closed.


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


Re: (and about tests) Re: Pedantic pickling error after reload?

2010-02-26 Thread Diez B. Roggisch

at that point of comparison the module is already identical ("klass =
getattr(mod, name)")


Ah, didn't know that context.


even more corner-cases. Python's import-mechanism can sometimes be
rather foot-shoot-prone.


still don't see a real reason against the mere module+name comparison.
same issues as during pickle.load. Just the class object is renewed
(intentionally)

If there are things with nested classes etc, the programmer will have to
rethink things on a different level: design errors. a subject for
pychecker/pylint - not for breaking pickle .dump ... ?


I don't say it necessarily breaks anything. I simply don't know enough 
about it. It might just be that back then, identity was deemed enough to 
check, but you can well argue your case on the python-dev list, 
providing a patch + tests that ensure there is no regression.



well, reloading is the thing which I do most in coding practice :-)
For me its a basic thing like cell proliferation in biology.


I simply never do it. It has subtle issues, one of them you found, 
others you say you work around by introducing actual frameworks. But you 
might well forget some corner-cases & suddently chase a chimera you deem 
a bug, that in fact is just an unwanted side-effect of reloading.


And all this extra complexity is only good for the process of actually 
changing the code. It doesn't help you maintaining code quality.



Reentering into the same (complex) app state for evolving those
thousands of small thing (where a full parallel test coverage doesn't
work out) is a major dev time consuming factor in bigger projects - in
C, Java projects and even with other dynamic languages.
Dynamic classes are a main reason why I use Python (adopted from Lisp
long time ago; is that reload thing here possible with Ruby too?)


So what? If this kind of complex, through rather lengthy interactions 
evolved state is the thing you need to work within, that's reason enough 
for me to think about how to automate setting this very state up. That's 
what programming is about - telling a computer to do things it can do, 
which usually means it does them *much* faster & *much* more reliable 
than humans do.


Frankly, I can't be bothered with clicking through layers of GUIs to 
finally reach the destination I'm actually interested in. Let the 
computer do that. And once I teached him how so, I just integrate that 
into my test-suite.




I typically need just 1 full app reboot on 20..50 edit-run-cycles I
guess. And just few unit test runs per release. Even for
Cython/pyximport things I added support for this reload edit-run-cycle,
because I cannot imagine to dev without this.


Let me assure you - it works :)

for example yesterday, I create a full CRUD-interface for a web-app 
(which is the thing I work on mostly these days) without *once* taking a 
look at the browser. I wrote actions, forms, HTML, and tests along, 
developed the thing ready, asserted certain constraints and error-cases, 
and once finished, fired up the browser - and he saw, it worked!


Yes, I could have written that code on the fly, hitting F5 every few 
seconds/minutes to see if things work out (instead of just running the 
specific tests through nose) - and once I'd be finished, I didn't have 
anything permanent that ensured the functionality over time.



this is a comfortable quasi religious theory raised often and easily
here and there - impracticable and very slow on that fine grained code
evolution level however. an interesting issue.


To me, that's as much as an religious statement often heard by people 
that aren't (really) into test-driven development. By which I personally 
don't mean the variant where one writes tests first, and then code. I 
always develop both in lock-step, sometimes introducing a new feauter 
first in my test as e.g. new arguments, or new calls, and then 
implementing them, but as often the other way round.


The argument is always a variation of "my problem is to complicated, the 
code-base to interviened to make it possible to test this".


I call this a bluff. You might work with a code-base that makes it 
harder than needed to write tests for new functionality. But then, most 
of the time this is a sign of lack of design. Writing with testability 
in mind makes you think twice about how to proper componentize your 
application, clearly separate logic from presentation, validates 
API-design because using the API is immediatly done when writing the 
tests you need, and so forth.




I do unit tests for getting stability on a much higher level where/when
things and functionality are quite wired.
Generally after having compared I cannot confirm that "write always
tests before development" ideologies pay off in practice.
"Reload > pychecker/pylint > tests" works most effectively with Python
in my opinion.
And for GUI-development the difference is max.
(min for math algorithms which are well away from data structures/OO)


As I said, I mainly do web these days. Which ca

Re: Quoting quotes

2010-02-26 Thread Steven D'Aprano
On Fri, 26 Feb 2010 13:29:04 +0100, candide wrote:

> But the first method doesn't run correctly :
> 
> 
 print """The play "All's Well That Ends Well
>   File "", line 1
> print """The play "All's Well That Ends Well
>^
> SyntaxError: EOL while scanning single-quoted string


> 
> Any comment ?

Of course not. Quotes can't be nested, so the first time the parser hits 
three quote marks, you have reached the end of the string. You then open 
a new string with a single quote mark, and then fail to close it. Hence 
the EOL while scanning a single-quoted string.

There are many solutions. Here are four:

>>> print """The play "All's Well That Ends Well\
The play "All's Well That Ends Well"
>>> print '''The play "All's Well That Ends Well"'''
The play "All's Well That Ends Well"
>>> print 'The play "All\'s Well That Ends Well"'
The play "All's Well That Ends Well"
>>> print 'The play "All' "'" 's Well That Ends Well"'
The play "All's Well That Ends Well"

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


[M2Crypto] Problems uploading to IIS using FTP over SSL

2010-02-26 Thread Stephen Nelson-Smith
Hello,

System:

# rpm -q python m2crypto
python-2.4.3-27.el5
m2crypto-0.16-6.el5.6
# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 5.4 (Tikanga)

I have the following method:

def ftp_tarball(aggregation_dir, date_format, ftp_server, ftp_user,
ftp_pass):
  date = datetime.today().strftime(date_format)
  ftp = ftpslib.FTP_TLS()
  ftp.connect(ftp_server)
  ftp.auth_tls()
  ftp.set_pasv(0)
  ftp.login(ftp_user, ftp_pass)
  filename = aggregation_dir + 'zultys-logs_' + date + '.tar.gz'
  short_name = os.path.split(filename)[1]
  tarball = open(filename, 'rb')
  ftp.storbinary('STOR ' + short_name, tarball)
  tarball.close()
  ftp.quit()

This works perfectly with VSFTPD on Linux, with SSL forced for non-
anonymous users.

I try to connect to a supplier's IIS FTP server, and get:

Traceback (most recent call last):
  File "/usr/local/bin/lumberjack", line 45, in ?
lumberjack.ftp_tarball( aggregation_dir, date_format, ftp_server,
ftp_user, ftp_pass )
  File "/usr/lib64/python2.4/site-packages/lumberjack.py", line 93, in
ftp_tarball
ftp.storbinary('STOR ' + short_name, tarball)
  File "/usr/lib64/python2.4/ftplib.py", line 415, in storbinary
conn = self.transfercmd(cmd)
  File "/usr/lib64/python2.4/ftplib.py", line 345, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
  File "/usr/lib64/python2.4/site-packages/M2Crypto/ftpslib.py", line
86, in ntransfercmd
conn, size = FTP.ntransfercmd(self, cmd, rest)
  File "/usr/lib64/python2.4/ftplib.py", line 331, in ntransfercmd
sock = self.makeport()
  File "/usr/lib64/python2.4/ftplib.py", line 292, in makeport
resp = self.sendport(host, port)
  File "/usr/lib64/python2.4/ftplib.py", line 256, in sendport
return self.voidcmd(cmd)
  File "/usr/lib64/python2.4/ftplib.py", line 246, in voidcmd
return self.voidresp()
  File "/usr/lib64/python2.4/ftplib.py", line 221, in voidresp
resp = self.getresp()
  File "/usr/lib64/python2.4/ftplib.py", line 216, in getresp
raise error_perm, resp
ftplib.error_perm: 501 Server cannot accept argument.

A colleague is able to connect using the Filezilla client, configured
as servertype: FTPES - FTP over explicit TLS/SSL setting.

I've not been able to find any further guidance on the web.

If you've experienced this before, or can see something that I've
obviously got wrong, I'd appreciate your help.

TIA,

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


ANN: Leo 4.7.1 released

2010-02-26 Thread Edward K Ream
Leo 4.7.1 final is now available at:
http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106

Leo 4.7.1 fixes a dangerous bug in Leo 4.7. When converting file-like
sentinels to thin-like sentinels in an external file, Leo now issues a
warning and sets the corresponding @file node dirty. This ensures that
Leo will write the converted external file and .leo file together,
making it impossible to lose data.

Leo is a text editor, data organizer, project manager and much more.
See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.7:
--

- Leo now uses the simplest possible internal data model.
  This is the so-called "one-node" world.
- Leo supports Python 3.x.
- Leo requires Python 2.6 or above.
- Several important improvements in file handling.
- Leo converts @file nodes to @thin nodes automatically.
- Leo creates a 'Recovered Nodes' node to hold data that
  otherwise might be lost due to clone conflicts.
- @auto-rst now works much more reliably reliably.
- Leo no longer supports @noref trees.  Such trees are not
  reliable in cooperative environments.
- A new Windows installer.
- Many other features, including new command line options and new
plugins.
- Dozens of bug fixes.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Forum:http://groups.google.com/group/leo-editor
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
Bzr:  http://code.launchpad.net/leo-editor/
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Renaming identifiers & debugging

2010-02-26 Thread Roald de Vries

Hi Luca,

On Feb 26, 2010, at 12:41 AM, Luca wrote:

MRAB wrote:

Perhaps you could use a different extension, eg ".pyn", so existing
".py" files are handled as-is but ".pyn" files are read through a
translator.


This could be a good idea... especially since i could make my own  
extension since we are talking of a special-purpose application that  
only incorporates python as a library.


I would suggest to do choose the same strategy as 'from __future__  
import ...' takes, which does similar things and limits them to the  
module it is used in. I would be curious to hear about your results.


Kind regards, Roald


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


PyCon 2011 - Call for Tutorial Volunteers

2010-02-26 Thread Greg Lindstrom
PyCon 2010 is complete and plans for PyCon 2011 in Atlanta have already
begun!  The main conference will once again be proceeded by two days of
tutorials.  There was quite a bit of feedback from students and teachers
this year that we want to incorporate in next years classes.  In order to do
this, more people need to get involved; why not you?  You do not need to
have any experience in organizing a national conference, just the desire to
help out.  There is plenty to do from tasks that take a couple of hours to
others that span months and you will get help with everything.  The areas we
will be working on are:

* Proposals -  help with the call for tutorial proposals and selection of
classes
* Room Assignments - help get the selected tutorials assigned to classrooms
and monitor attendance numbers
* Notes - work with teachers to get class notes printed and distributed
* Program Guide - work with conference organizers to get tutorial
information in the conference guide
* Feedback - Work to get meaningful feedback from students and teachers (so
PyCon 2012 is even better!)
* Payments - collect information so our teachers get paid
* Runner - On tutorial days at the conference, make yourself available to do
whatever needs to be done.

It's a lot of work -- and a lot of fun-- to put on tutorials for PyCon each
year.  You won't get paid, but you will get one of the snappy "staff" tee
shirts when you attend PyCon and you get to work with an incredibly
dedicated group of volunteers.

Interested?  Please drop a note at pycon-tutori...@python.org and let us
know.

Thanks,

Greg Lindstrom
Tutorial Coordinator, PyCon 2011 (Atlanta)
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: python-ldap-2.3.11

2010-02-26 Thread Michael Ströder
Find a new release of python-ldap:

  http://www.python-ldap.org/

python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema).

Ciao, Michael.

-- 
Michael Ströder
E-Mail: mich...@stroeder.com
http://www.stroeder.com


Released 2.3.11 2010-02-26

Changes since 2.3.10:

Lib/
* Fixed LDAP URL parsing with four ? but no real extensions
* ldap.ldapobject.LDAPObject.rename_s() now also accepts arguments
  serverctrls and clientctrls
* Removed untested and undocumented class ldap.ldapobject.SmartLDAPObject
* Removed broken method ldap.ldapobject.LDAPObject.manage_dsa_it()

Modules/
* Make use of LDAP_OPT_X_TLS_NEWCTX only if available in
  OpenLDAP libs used for the build
* Fixed #ifdef-statements for OPT_X_TLS_PROTOCOL_MIN

Doc/
* Some updates and corrections regarding description of use of
  LDAPv3 controls
* Some more descriptions for constants
* Removed comments related to old LaTeX-based documentation system


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


Re: Challenge: escape from the pysandbox

2010-02-26 Thread Daniel Fetchinson
>> pysandbox is a new Python sandbox project

Out of curiosity, the python sandbox behind google app engine is open source?
If so, how is it different from your project, if not, anyone knows if
it will be in the future?

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Possible to import from a cStringIO file object vs. file on disk?

2010-02-26 Thread python
Is it possible to import from a cStringIO file object (containing
compiled byte code) vs. a physical file on disk?

I'm thinking that this is possible, given Python's ability to
import from zip files, but I'm not sure where to look next.

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


Re: Docstrings considered too complicated

2010-02-26 Thread Jean-Michel Pichavant

Andreas Waldenburger wrote:

On Thu, 25 Feb 2010 12:51:00 -0800 (PST) John Roth
 wrote:

  

On Feb 24, 1:23 pm, Andreas Waldenburger 
wrote:


a company that works with my company writes a lot of of their code
in Python (lucky jerks). I've seen their code and it basically
looks like this:

"""Function that does stuff"""
def doStuff():
while not wise(up):
yield scorn
[snip]
  

Is the problem that they've got the docstring in the wrong place,
or that the comment isn't saying anything that can't be read in
the method name?



It's the first. I am superficial like that. I just needed a docstring
to illustrate and didn't want to get overly creative.

Not that they don't write redundant docstrings.

And they use mixedCase function/method names.
  

and ? whatIsTheProblem ?
PEP8 is one style guide, not *the* style guide. There is neither 
technical nor readability issue with mixedCase, classes in PEP 8 using 
MixedCase. The thing is they had to chose one preference for the methods 
and they choose lower_case. Fine, but it's still a matter of preference 
(or arbitrary decision). Since you don't write code for the standard 
library, you can use any other naming convention.
You've may have guessed it, I am using mixedCase method names, and I 
tell you, you cannot compare this in any way with their dumb usage of 
doctrings you've shown above.


That being said, yoru OP's still soemhow funny, I would have shot them 
on sight :-)


JM

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


Re: Challenge: escape from the pysandbox

2010-02-26 Thread Victor Stinner
Le vendredi 26 février 2010 15:37:43, Daniel Fetchinson a écrit :
> >> pysandbox is a new Python sandbox project
> 
> Out of curiosity, the python sandbox behind google app engine is open
>  source? If so, how is it different from your project, if not, anyone knows
>  if it will be in the future?

I don't know this project. Do you have the URL of the project home page? Is it 
the "safelite.py" project?

-- 
Victor Stinner
http://www.haypocalc.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quoting quotes

2010-02-26 Thread Grant Edwards
On 2010-02-26, Steven D'Aprano  wrote:
> On Fri, 26 Feb 2010 13:29:04 +0100, candide wrote:
>
>> But the first method doesn't run correctly :
>> 
>> 
> print """The play "All's Well That Ends Well
>>   File "", line 1
>> print """The play "All's Well That Ends Well
>>^
>> SyntaxError: EOL while scanning single-quoted string
>
>
>> 
>> Any comment ?
>
> Of course not. Quotes can't be nested, so the first time the
> parser hits three quote marks, you have reached the end of the
> string. You then open a new string with a single quote mark,
> and then fail to close it. Hence the EOL while scanning a
> single-quoted string.

IMO, the error message is misleading to many people, since in
many/most contexts the term "single-quoted" refers to this:

  'here is a single quoted string'

And not this:

  "this is a double-quoted string"

-- 
Grant Edwards   grante Yow! And then we could sit
  at   on the hoods of cars at
   visi.comstop lights!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Docstrings considered too complicated

2010-02-26 Thread Tim Daneliuk
On 2/24/2010 2:23 PM, Andreas Waldenburger wrote:
> Hi all,
> 
> a company that works with my company writes a lot of of their code in
> Python (lucky jerks). I've seen their code and it basically looks like
> this:
> 
> """Function that does stuff"""
> def doStuff():
> while not wise(up):
> yield scorn
> 
> Now my question is this: How do I kill these people without the
> authorities thinking they didn't deserve it?
> 
> /W
> 

Reminiscent of:

mov  AX,BX   ; Move the contents of BX into AX

And, yes, I've actually seen that as well as:

; This is a comment



-- 

Tim Daneliuk tun...@tundraware.com
PGP Key: http://www.tundraware.com/PGP/

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


Re: staticmethod and namespaces

2010-02-26 Thread darnzen
On Feb 26, 3:15 am, "Diez B. Roggisch"  wrote:
> Am 26.02.10 06:07, schrieb darnzen:
>
>
>
>
>
> > Having an odd problem that I solved, but wondering if its the best
> > solution (seems like a bit of a hack).
>
> > First off, I'm using an external DLL that requires static callbacks,
> > but because of this, I'm losing instance info. It could be import
> > related? It will make more sense after I diagram it:
>
> > #Module main.py
> > from A import *
>
> > class App:
> >      def sperg(self):
> >           self.a = A()
>
> > app = App()
> > [main loop and such]
> >   -
> > # Module A.py
> > import main
> > class Foo:
> >        Selves=[]
> >       def __init__(self):
> >                 Foo.Selves.append(self)
> >       @staticmethod
> >       def chum_callback(nType, nP):
> >                 # Need to access function / data in app instance
> >                 app.sperg(nP)
> >                 # Need to access func data in Foo
> >                 # I'm pulling 'self' ouf of list made in constructor
> >                 self = Foo.getSelf(nP)
>
> >       def getSelf(nP):
> >                 return self.Selves[nP]
>
> > -
> > So basically I added a list of instances to the base class so I can
> > get at them from the staticmethod.
> > What's bothering me the most is I can't use the global app instance in
> > the A.py module.
>
> > How can I get at the app instance (currently I'm storing that along
> > with the class instance in the constructor)?
> > Is there another way to do this that's not such a hack?
>
> > Sorry for the double / partial post :(
>
> Can you show how you pass the staticmethod to the C-function? Is the DLL
> utilized by ctypes?
>
> I don't see any reason you couldn't use a bound method, which would give
> you your self, instead relying on global state.
>
> Diez

__main__.K   << *facepalm* should of tried that!

Yeah I'm using ctypes. The DLL callback set ups are as follows. The
local callback is in the App namespace (in this case, some callbacks
are in different modules as noted in OP), but still no access to self:

#Function wrapper
A.expCallback = WINFUNCTYPE(None, c_int, c_int,  \
POINTER(Data_s))(A.Callback)

#DLL call to register the local callback function
DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback)

class A:
#Local callback function
@staticmethod
def Callback(hID, SubID, Data):
 print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!'
 print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT'
 print 'IF I STORE A REFERENCE TO MYSELF IN A DICT'
 print 'USING KEY GENERATED FROM hID, SubID'
 pass

I'm not sure why they need to be static callbacks, but the DLL doc's
say "when using object based languages, such as c++, callback
functions must be declared as static functions and not instance
methods", and I couldn't get it to work without setting it up that
way. I could probably have them all be "classless" functions, but with
100's of these, my namespace would be polluted up the wazoo, and I'd
still have the problem that they wouldn't have access to instance
methods / properties.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: staticmethod and namespaces

2010-02-26 Thread Diez B. Roggisch

Am 26.02.10 16:32, schrieb darnzen:

On Feb 26, 3:15 am, "Diez B. Roggisch"  wrote:

Am 26.02.10 06:07, schrieb darnzen:






Having an odd problem that I solved, but wondering if its the best
solution (seems like a bit of a hack).



First off, I'm using an external DLL that requires static callbacks,
but because of this, I'm losing instance info. It could be import
related? It will make more sense after I diagram it:



#Module main.py
from A import *



class App:
  def sperg(self):
   self.a = A()



app = App()
[main loop and such]
   -
# Module A.py
import main
class Foo:
Selves=[]
   def __init__(self):
 Foo.Selves.append(self)
   @staticmethod
   def chum_callback(nType, nP):
 # Need to access function / data in app instance
 app.sperg(nP)
 # Need to access func data in Foo
 # I'm pulling 'self' ouf of list made in constructor
 self = Foo.getSelf(nP)



   def getSelf(nP):
 return self.Selves[nP]



-
So basically I added a list of instances to the base class so I can
get at them from the staticmethod.
What's bothering me the most is I can't use the global app instance in
the A.py module.



How can I get at the app instance (currently I'm storing that along
with the class instance in the constructor)?
Is there another way to do this that's not such a hack?



Sorry for the double / partial post :(


Can you show how you pass the staticmethod to the C-function? Is the DLL
utilized by ctypes?

I don't see any reason you couldn't use a bound method, which would give
you your self, instead relying on global state.

Diez


__main__.K<<  *facepalm* should of tried that!

Yeah I'm using ctypes. The DLL callback set ups are as follows. The
local callback is in the App namespace (in this case, some callbacks
are in different modules as noted in OP), but still no access to self:

 #Function wrapper
 A.expCallback = WINFUNCTYPE(None, c_int, c_int,  \
POINTER(Data_s))(A.Callback)

 #DLL call to register the local callback function
 DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback)

 class A:
 #Local callback function
@staticmethod
def Callback(hID, SubID, Data):
  print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!'
  print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT'
  print 'IF I STORE A REFERENCE TO MYSELF IN A DICT'
  print 'USING KEY GENERATED FROM hID, SubID'
  pass

I'm not sure why they need to be static callbacks, but the DLL doc's
say "when using object based languages, such as c++, callback
functions must be declared as static functions and not instance
methods", and I couldn't get it to work without setting it up that
way. I could probably have them all be "classless" functions, but with
100's of these, my namespace would be polluted up the wazoo, and I'd
still have the problem that they wouldn't have access to instance
methods / properties.


The above code can't work with self, because you use

 A.expCallback

which at best can of course be a classmethod.

You need to instead invoke DLLSetCallback with a bound method, like this

 a = A()
 DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback)

Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of 
static functions is differently. If ctypes manages to get *some* 
callback passed, I'm 100% positive that it can pass *any* callable you 
like, including bound methods.


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


Re: staticmethod and namespaces

2010-02-26 Thread darnzen
On Feb 26, 1:12 am, Steven D'Aprano  wrote:
> On Thu, 25 Feb 2010 21:07:55 -0800, darnzen wrote:
> > Having an odd problem that I solved, but wondering if its the best
> > solution (seems like a bit of a hack).
>
> > First off, I'm using an external DLL that requires static callbacks, but
> > because of this, I'm losing instance info.
> [...]
> > How can I get at the app instance (currently I'm storing that along with
> > the class instance in the constructor)? Is there another way to do this
> > that's not such a hack?
>
> Pass the instance explicitly:
>
> >>> class K(object):
>
> ...     @staticmethod
> ...     def static(self, x, y):
> ...         print self, x, y
> ...>>> k = K()
> >>> k.static(k, 1, 2)
>
> <__main__.K object at 0xb7c2544c> 1 2
>
> --
> Steven

Unfortunately, since the callback is from the DLL which I didn't
write, I can not change what is passed to the function. Also, the DLL
has no idea about my local namespace. The DLL typically will pass back
two integers (which I can set the values of when I register the
callback), and some data. Currently Im' using these integers as keys
in a local dict where I'm storing the instances.

I suppose I could use the integers to store the high and low order
bytes of a pointer to the instance, but not sure how to do that in
Python (would be easy in c/c++). Also, I'm not sure how python memory
management works, if it will move objects around and make things
buggy. Also, that is definitely a hack and isn't very 'pythonesque'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: staticmethod and namespaces

2010-02-26 Thread darnzen
On Feb 26, 9:41 am, "Diez B. Roggisch"  wrote:
> Am 26.02.10 16:32, schrieb darnzen:
>
>
>
>
>
> > On Feb 26, 3:15 am, "Diez B. Roggisch"  wrote:
> >> Am 26.02.10 06:07, schrieb darnzen:
>
> >>> Having an odd problem that I solved, but wondering if its the best
> >>> solution (seems like a bit of a hack).
>
> >>> First off, I'm using an external DLL that requires static callbacks,
> >>> but because of this, I'm losing instance info. It could be import
> >>> related? It will make more sense after I diagram it:
>
> >>> #Module main.py
> >>> from A import *
>
> >>> class App:
> >>>       def sperg(self):
> >>>            self.a = A()
>
> >>> app = App()
> >>> [main loop and such]
> >>>    -
> >>> # Module A.py
> >>> import main
> >>> class Foo:
> >>>         Selves=[]
> >>>        def __init__(self):
> >>>                  Foo.Selves.append(self)
> >>>       �...@staticmethod
> >>>        def chum_callback(nType, nP):
> >>>                  # Need to access function / data in app instance
> >>>                  app.sperg(nP)
> >>>                  # Need to access func data in Foo
> >>>                  # I'm pulling 'self' ouf of list made in constructor
> >>>                  self = Foo.getSelf(nP)
>
> >>>        def getSelf(nP):
> >>>                  return self.Selves[nP]
>
> >>> -
> >>> So basically I added a list of instances to the base class so I can
> >>> get at them from the staticmethod.
> >>> What's bothering me the most is I can't use the global app instance in
> >>> the A.py module.
>
> >>> How can I get at the app instance (currently I'm storing that along
> >>> with the class instance in the constructor)?
> >>> Is there another way to do this that's not such a hack?
>
> >>> Sorry for the double / partial post :(
>
> >> Can you show how you pass the staticmethod to the C-function? Is the DLL
> >> utilized by ctypes?
>
> >> I don't see any reason you couldn't use a bound method, which would give
> >> you your self, instead relying on global state.
>
> >> Diez
>
> > __main__.K<<  *facepalm* should of tried that!
>
> > Yeah I'm using ctypes. The DLL callback set ups are as follows. The
> > local callback is in the App namespace (in this case, some callbacks
> > are in different modules as noted in OP), but still no access to self:
>
> >          #Function wrapper
> >          A.expCallback = WINFUNCTYPE(None, c_int, c_int,  \
> >                            POINTER(Data_s))(A.Callback)
>
> >          #DLL call to register the local callback function
> >          DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback)
>
> >      class A:
> >          #Local callback function
> >   �...@staticmethod
> >    def Callback(hID, SubID, Data):
> >               print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!'
> >               print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT'
> >               print 'IF I STORE A REFERENCE TO MYSELF IN A DICT'
> >               print 'USING KEY GENERATED FROM hID, SubID'
> >               pass
>
> > I'm not sure why they need to be static callbacks, but the DLL doc's
> > say "when using object based languages, such as c++, callback
> > functions must be declared as static functions and not instance
> > methods", and I couldn't get it to work without setting it up that
> > way. I could probably have them all be "classless" functions, but with
> > 100's of these, my namespace would be polluted up the wazoo, and I'd
> > still have the problem that they wouldn't have access to instance
> > methods / properties.
>
> The above code can't work with self, because you use
>
>   A.expCallback
>
> which at best can of course be a classmethod.
>
> You need to instead invoke DLLSetCallback with a bound method, like this
>
>   a = A()
>   DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback)
>
> Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of
> static functions is differently. If ctypes manages to get *some*
> callback passed, I'm 100% positive that it can pass *any* callable you
> like, including bound methods.
>
> Diez

This was originally how my code was set up, invoking with the bound
methods, but it didn't work (crashing and bizzaro errors) and I was
pulling my hair out. Then I read the documentation and changed it to
static methods and everything started working. Believe me, I totally
understand how using bound methods would make this problem go away.
-- 
http://mail.python.org/mailman/listinfo/python-list


Offline windows registry access on *nix platforms.

2010-02-26 Thread r0g
Hi Everybody,

I do a fair bit of programming in Python and I have to say I find perl a
little intimidating right now as I don't have a lot of experience with
it however its the only language I have found that seemed to have a
library for what I need right now: Win32::Registry (or maybe
Win32::TieRegistry)

I way to read/search for windows registry keys from offline hive files
e.g. NTUSER.DAT on *nix platforms, in my case Ubuntu linux - nothing
more advanced than that.

Given that I only need this functionality, performance is a not issue
and I'm very comfortable in Python I thought I might try and write a
pair of wrapper functions - one to check the existence of a key, one to
return a keys values.

Sadly though I have fallen at the first hurdle, I get "OS unsupported"
when I type "install Win32::Registry" into CPAN so I guess it's windows
only :(

Anyone know of an open source module/library that can do what I want?
Ideally Python or Perl, but I suppose any free language I can compile or
easily bundle/distribute would do.

Alternatively if anyone knows of a *nix app that can decode a windows
registry into a flat text file?

At a push I could compile something that can do this on windows and run
it via wine but I'd really like to avoid that if I can.

Suggestions & pointers greatly appreciated,

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


Re: staticmethod and namespaces

2010-02-26 Thread darnzen
On Feb 26, 9:41 am, "Diez B. Roggisch"  wrote:
> Am 26.02.10 16:32, schrieb darnzen:
>
>
>
>
>
> > On Feb 26, 3:15 am, "Diez B. Roggisch"  wrote:
> >> Am 26.02.10 06:07, schrieb darnzen:
>
> >>> Having an odd problem that I solved, but wondering if its the best
> >>> solution (seems like a bit of a hack).
>
> >>> First off, I'm using an external DLL that requires static callbacks,
> >>> but because of this, I'm losing instance info. It could be import
> >>> related? It will make more sense after I diagram it:
>
> >>> #Module main.py
> >>> from A import *
>
> >>> class App:
> >>>       def sperg(self):
> >>>            self.a = A()
>
> >>> app = App()
> >>> [main loop and such]
> >>>    -
> >>> # Module A.py
> >>> import main
> >>> class Foo:
> >>>         Selves=[]
> >>>        def __init__(self):
> >>>                  Foo.Selves.append(self)
> >>>       �...@staticmethod
> >>>        def chum_callback(nType, nP):
> >>>                  # Need to access function / data in app instance
> >>>                  app.sperg(nP)
> >>>                  # Need to access func data in Foo
> >>>                  # I'm pulling 'self' ouf of list made in constructor
> >>>                  self = Foo.getSelf(nP)
>
> >>>        def getSelf(nP):
> >>>                  return self.Selves[nP]
>
> >>> -
> >>> So basically I added a list of instances to the base class so I can
> >>> get at them from the staticmethod.
> >>> What's bothering me the most is I can't use the global app instance in
> >>> the A.py module.
>
> >>> How can I get at the app instance (currently I'm storing that along
> >>> with the class instance in the constructor)?
> >>> Is there another way to do this that's not such a hack?
>
> >>> Sorry for the double / partial post :(
>
> >> Can you show how you pass the staticmethod to the C-function? Is the DLL
> >> utilized by ctypes?
>
> >> I don't see any reason you couldn't use a bound method, which would give
> >> you your self, instead relying on global state.
>
> >> Diez
>
> > __main__.K<<  *facepalm* should of tried that!
>
> > Yeah I'm using ctypes. The DLL callback set ups are as follows. The
> > local callback is in the App namespace (in this case, some callbacks
> > are in different modules as noted in OP), but still no access to self:
>
> >          #Function wrapper
> >          A.expCallback = WINFUNCTYPE(None, c_int, c_int,  \
> >                            POINTER(Data_s))(A.Callback)
>
> >          #DLL call to register the local callback function
> >          DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback)
>
> >      class A:
> >          #Local callback function
> >   �...@staticmethod
> >    def Callback(hID, SubID, Data):
> >               print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!'
> >               print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT'
> >               print 'IF I STORE A REFERENCE TO MYSELF IN A DICT'
> >               print 'USING KEY GENERATED FROM hID, SubID'
> >               pass
>
> > I'm not sure why they need to be static callbacks, but the DLL doc's
> > say "when using object based languages, such as c++, callback
> > functions must be declared as static functions and not instance
> > methods", and I couldn't get it to work without setting it up that
> > way. I could probably have them all be "classless" functions, but with
> > 100's of these, my namespace would be polluted up the wazoo, and I'd
> > still have the problem that they wouldn't have access to instance
> > methods / properties.
>
> The above code can't work with self, because you use
>
>   A.expCallback
>
> which at best can of course be a classmethod.
>
> You need to instead invoke DLLSetCallback with a bound method, like this
>
>   a = A()
>   DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback)
>
> Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of
> static functions is differently. If ctypes manages to get *some*
> callback passed, I'm 100% positive that it can pass *any* callable you
> like, including bound methods.
>
> Diez

Thinking about it some more, I believe I understand why it has to be
staticfunction. To use an bound method would require the wrapper to
include a reference to the instance as follows:

A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int,  \
POINTER(Data_s))(a.Callback)

Since a = A(); a.foo() is really A.foo(self). The problem here is that
A is not a ctypes object and I can't change what arguments the DLL
uses in the callback in any case. Rewording my thoughts: a bound
method callback would require 'self' to be the first argument. I can
not make the DLL include 'self' as it doesn't know anything about the
objects in my program. Since I can't pass 'self', it has to be a
staticmethod.
-- 
http://mail.python.org/mailman/listinfo/python-list


Dictionary or Database—Please advise

2010-02-26 Thread Jeremy
I have lots of data that I currently store in dictionaries.  However,
the memory requirements are becoming a problem.  I am considering
using a database of some sorts instead, but I have never used them
before.  Would a database be more memory efficient than a dictionary?
I also need platform independence without having to install a database
and Python interface on all the platforms I'll be using.  Is there
something built-in to Python that will allow me to do this?

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


Re: Quoting quotes

2010-02-26 Thread William Lohrmann
On 26 Feb, 13:29, candide  wrote:
> Suppose you have to put into a Python string the following sentence :
>
> The play "All's Well That Ends Well" by Shakespeare
>
> It's easy do it :
>
> >>> print """The play "All's Well That Ends Well" by Shakespeare"""
>
> The play "All's Well That Ends Well" by Shakespeare
>
> Now, change the sentence to this one :
>
> The play "All's Well That Ends Well"
>
> Using triple single quotes works fine
>
> >>> print '''The play "All's Well That Ends Well"'''
>
> The play "All's Well That Ends Well"
>
> But the first method doesn't run correctly :
>
> >>> print """The play "All's Well That Ends Well
>
>   File "", line 1
>     print """The play "All's Well That Ends Well
>                                                    ^
> SyntaxError: EOL while scanning single-quoted string
>
>
>
> Any comment ?

The best thing would be to backslash the single quote: print 'The play
"All\'s Well That Ends Well"'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: staticmethod and namespaces

2010-02-26 Thread Diez B. Roggisch

Am 26.02.10 16:57, schrieb darnzen:

On Feb 26, 9:41 am, "Diez B. Roggisch"  wrote:

Am 26.02.10 16:32, schrieb darnzen:






On Feb 26, 3:15 am, "Diez B. Roggisch"wrote:

Am 26.02.10 06:07, schrieb darnzen:



Having an odd problem that I solved, but wondering if its the best
solution (seems like a bit of a hack).



First off, I'm using an external DLL that requires static callbacks,
but because of this, I'm losing instance info. It could be import
related? It will make more sense after I diagram it:



#Module main.py
from A import *



class App:
   def sperg(self):
self.a = A()



app = App()
[main loop and such]
-
# Module A.py
import main
class Foo:
 Selves=[]
def __init__(self):
  Foo.Selves.append(self)
@staticmethod
def chum_callback(nType, nP):
  # Need to access function / data in app instance
  app.sperg(nP)
  # Need to access func data in Foo
  # I'm pulling 'self' ouf of list made in constructor
  self = Foo.getSelf(nP)



def getSelf(nP):
  return self.Selves[nP]



-
So basically I added a list of instances to the base class so I can
get at them from the staticmethod.
What's bothering me the most is I can't use the global app instance in
the A.py module.



How can I get at the app instance (currently I'm storing that along
with the class instance in the constructor)?
Is there another way to do this that's not such a hack?



Sorry for the double / partial post :(



Can you show how you pass the staticmethod to the C-function? Is the DLL
utilized by ctypes?



I don't see any reason you couldn't use a bound method, which would give
you your self, instead relying on global state.



Diez



__main__.K<<*facepalm* should of tried that!



Yeah I'm using ctypes. The DLL callback set ups are as follows. The
local callback is in the App namespace (in this case, some callbacks
are in different modules as noted in OP), but still no access to self:



  #Function wrapper
  A.expCallback = WINFUNCTYPE(None, c_int, c_int,  \
POINTER(Data_s))(A.Callback)



  #DLL call to register the local callback function
  DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback)



  class A:
  #Local callback function
@staticmethod
def Callback(hID, SubID, Data):
   print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!'
   print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT'
   print 'IF I STORE A REFERENCE TO MYSELF IN A DICT'
   print 'USING KEY GENERATED FROM hID, SubID'
   pass



I'm not sure why they need to be static callbacks, but the DLL doc's
say "when using object based languages, such as c++, callback
functions must be declared as static functions and not instance
methods", and I couldn't get it to work without setting it up that
way. I could probably have them all be "classless" functions, but with
100's of these, my namespace would be polluted up the wazoo, and I'd
still have the problem that they wouldn't have access to instance
methods / properties.


The above code can't work with self, because you use

   A.expCallback

which at best can of course be a classmethod.

You need to instead invoke DLLSetCallback with a bound method, like this

   a = A()
   DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback)

Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of
static functions is differently. If ctypes manages to get *some*
callback passed, I'm 100% positive that it can pass *any* callable you
like, including bound methods.

Diez


Thinking about it some more, I believe I understand why it has to be
staticfunction. To use an bound method would require the wrapper to
include a reference to the instance as follows:

A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int,  \
 POINTER(Data_s))(a.Callback)

Since a = A(); a.foo() is really A.foo(self). The problem here is that
A is not a ctypes object and I can't change what arguments the DLL
uses in the callback in any case. Rewording my thoughts: a bound
method callback would require 'self' to be the first argument. I can
not make the DLL include 'self' as it doesn't know anything about the
objects in my program. Since I can't pass 'self', it has to be a
staticmethod.


No, that's not true. A bound method implictly knows about it self, and 
it's a callable.


What I guess is that you did the same mistake I did when I created that 
example - namely, not keeping a refernce to the bound method around. 
Ctypes will then garbage-collect the callback, which of course leads to 
all kinds of troubles.


Try this:

 a = A()
 # keep this around
 bound_m = a.expCallback
 DLLSetCallback(self.hI

Re: Dictionary or Database—Please advise

2010-02-26 Thread Benjamin Kaplan
On Fri, Feb 26, 2010 at 10:58 AM, Jeremy  wrote:

> I have lots of data that I currently store in dictionaries.  However,
> the memory requirements are becoming a problem.  I am considering
> using a database of some sorts instead, but I have never used them
> before.  Would a database be more memory efficient than a dictionary?
> I also need platform independence without having to install a database
> and Python interface on all the platforms I'll be using.  Is there
> something built-in to Python that will allow me to do this?
>
> Thanks,
> Jeremy
>


Python has SQLite 3 built-in and there are wrappers for MySQL and PostgreSQL
on all major platforms. Any one of them will work- databases have the
advantage that they're stored on the disk so you don't have all of it in
memory simultaneously.


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


Re: Offline windows registry access on *nix platforms.

2010-02-26 Thread r0g
r0g wrote:
> Hi Everybody,
> 
> I do a fair bit of programming in Python and I have to say I find perl a
> little intimidating right now as I don't have a lot of experience with
> it however its the only language I have found that seemed to have a
> library for what I need right now: Win32::Registry (or maybe
> Win32::TieRegistry)
> 
> I way to read/search for windows registry keys from offline hive files
> e.g. NTUSER.DAT on *nix platforms, in my case Ubuntu linux - nothing
> more advanced than that.


Actually scrap that, just found "Parse::Win32Registry", happy days! :)

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


Re: staticmethod and namespaces

2010-02-26 Thread Diez B. Roggisch

Am 26.02.10 17:08, schrieb Diez B. Roggisch:

Am 26.02.10 16:57, schrieb darnzen:

On Feb 26, 9:41 am, "Diez B. Roggisch" wrote:

Am 26.02.10 16:32, schrieb darnzen:






On Feb 26, 3:15 am, "Diez B. Roggisch" wrote:

Am 26.02.10 06:07, schrieb darnzen:



Having an odd problem that I solved, but wondering if its the best
solution (seems like a bit of a hack).



First off, I'm using an external DLL that requires static callbacks,
but because of this, I'm losing instance info. It could be import
related? It will make more sense after I diagram it:



#Module main.py
from A import *



class App:
def sperg(self):
self.a = A()



app = App()
[main loop and such]
-
# Module A.py
import main
class Foo:
Selves=[]
def __init__(self):
Foo.Selves.append(self)
@staticmethod
def chum_callback(nType, nP):
# Need to access function / data in app instance
app.sperg(nP)
# Need to access func data in Foo
# I'm pulling 'self' ouf of list made in constructor
self = Foo.getSelf(nP)



def getSelf(nP):
return self.Selves[nP]



-
So basically I added a list of instances to the base class so I can
get at them from the staticmethod.
What's bothering me the most is I can't use the global app
instance in
the A.py module.



How can I get at the app instance (currently I'm storing that along
with the class instance in the constructor)?
Is there another way to do this that's not such a hack?



Sorry for the double / partial post :(



Can you show how you pass the staticmethod to the C-function? Is
the DLL
utilized by ctypes?



I don't see any reason you couldn't use a bound method, which would
give
you your self, instead relying on global state.



Diez



__main__.K<< *facepalm* should of tried that!



Yeah I'm using ctypes. The DLL callback set ups are as follows. The
local callback is in the App namespace (in this case, some callbacks
are in different modules as noted in OP), but still no access to self:



#Function wrapper
A.expCallback = WINFUNCTYPE(None, c_int, c_int, \
POINTER(Data_s))(A.Callback)



#DLL call to register the local callback function
DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback)



class A:
#Local callback function
@staticmethod
def Callback(hID, SubID, Data):
print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!'
print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT'
print 'IF I STORE A REFERENCE TO MYSELF IN A DICT'
print 'USING KEY GENERATED FROM hID, SubID'
pass



I'm not sure why they need to be static callbacks, but the DLL doc's
say "when using object based languages, such as c++, callback
functions must be declared as static functions and not instance
methods", and I couldn't get it to work without setting it up that
way. I could probably have them all be "classless" functions, but with
100's of these, my namespace would be polluted up the wazoo, and I'd
still have the problem that they wouldn't have access to instance
methods / properties.


The above code can't work with self, because you use

A.expCallback

which at best can of course be a classmethod.

You need to instead invoke DLLSetCallback with a bound method, like this

a = A()
DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback)

Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of
static functions is differently. If ctypes manages to get *some*
callback passed, I'm 100% positive that it can pass *any* callable you
like, including bound methods.

Diez


Thinking about it some more, I believe I understand why it has to be
staticfunction. To use an bound method would require the wrapper to
include a reference to the instance as follows:

A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int, \
POINTER(Data_s))(a.Callback)

Since a = A(); a.foo() is really A.foo(self). The problem here is that
A is not a ctypes object and I can't change what arguments the DLL
uses in the callback in any case. Rewording my thoughts: a bound
method callback would require 'self' to be the first argument. I can
not make the DLL include 'self' as it doesn't know anything about the
objects in my program. Since I can't pass 'self', it has to be a
staticmethod.


No, that's not true. A bound method implictly knows about it self, and
it's a callable.

What I guess is that you did the same mistake I did when I created that
example - namely, not keeping a refernce to the bound method around.
Ctypes will then garbage-collect the callback, which of course leads to
all kinds of troubles.

Try this:

a = A()
# keep this around
bound_m = a.expCallback
DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback)


HHRG, same error again.

Of course, use

DLLSetCallback(self.hID, A.SubID, EVENTID, bound_m)

because the bound method changes with each time you create it.

Sorry for the confusion.

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


Re: Dictionary or Database—Please advise

2010-02-26 Thread Chris Rebert
On Fri, Feb 26, 2010 at 7:58 AM, Jeremy  wrote:
> I have lots of data that I currently store in dictionaries.  However,
> the memory requirements are becoming a problem.  I am considering
> using a database of some sorts instead, but I have never used them
> before.  Would a database be more memory efficient than a dictionary?
> I also need platform independence without having to install a database
> and Python interface on all the platforms I'll be using.  Is there
> something built-in to Python that will allow me to do this?

If you won't be using the SQL features of the database, `shelve` might
be another option; from what I can grok, I sounds like a dictionary
stored mostly on disk rather than entirely in RAM (not 100% sure
though):
http://docs.python.org/library/shelve.html

It's in the std lib and supports several native dbm libraries for its
backend; one of them should almost always be present.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictionary or Database—Please advise

2010-02-26 Thread lbolla
On Feb 26, 3:58 pm, Jeremy  wrote:
> I have lots of data that I currently store in dictionaries.  However,
> the memory requirements are becoming a problem.  I am considering
> using a database of some sorts instead, but I have never used them
> before.  Would a database be more memory efficient than a dictionary?
> I also need platform independence without having to install a database
> and Python interface on all the platforms I'll be using.  Is there
> something built-in to Python that will allow me to do this?
>
> Thanks,
> Jeremy

Maybe shelve would be enough for your needs?
http://docs.python.org/library/shelve.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Docstrings considered too complicated

2010-02-26 Thread Andreas Waldenburger
On Fri, 26 Feb 2010 15:50:25 +0100 Jean-Michel Pichavant
 wrote:

> Andreas Waldenburger wrote:
> 
> > And they use mixedCase function/method names.
> >   
> and ? whatIsTheProblem ?

Thanks for proving my point. ;)

No seriously though: Let it go. I wasn't being serious. As long as it
works and I don't have to work with it, I don't care how anybody writes
their code.

/W

-- 
INVALID? DE!

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


Re: Docstrings considered too complicated

2010-02-26 Thread Andreas Waldenburger
On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk 
wrote:

> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote:
> > [stuff]
> 
> Reminiscent of:
> 
> mov  AX,BX   ; Move the contents of BX into AX
> 
Well, there might be some confusion there as to what gets moved where,
wouldn't you say? I guess this goes away after a couple of months,
though.

> And, yes, I've actually seen that as well as:
> 
> ; This is a comment
> 
I hope it was in a tutorial-situation. Or maybe it was written by one of
those "ironic" programmers?

/W

-- 
INVALID? DE!

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


Re: Dictionary or Database�Please advise

2010-02-26 Thread Roy Smith
In article 
<891a98fa-c398-455a-981f-bf72af772...@s36g2000prh.googlegroups.com>,
 Jeremy  wrote:

> I have lots of data that I currently store in dictionaries.  However,
> the memory requirements are becoming a problem.  I am considering
> using a database of some sorts instead, but I have never used them
> before.  Would a database be more memory efficient than a dictionary?
> I also need platform independence without having to install a database
> and Python interface on all the platforms I'll be using.  Is there
> something built-in to Python that will allow me to do this?
> 
> Thanks,
> Jeremy

This is a very vague question, so it'll get a vague answer :-)

If you have so much data that you're running into memory problems, then 
yes, storing the data externally in an disk-resident database seems like a 
reasonable idea.

Once you get into databases, platform independence will be an issue.  There 
are many databases out there to pick from.  If you want something which 
will work on a lot of platforms, a reasonable place to start looking is 
MySQL.  It's free, runs on lots of platforms, has good Python support, and 
there's lots of people on the net who know it and are willing to give help 
and advice.

Databases have a bit of a learning curve.  If you've never done any 
database work, don't expect to download MySql (or any other database) this 
afternoon and be up and running by tomorrow.

Whatever database you pick, you're almost certainly going to end up having 
to install it wherever you install your application.  There's no such thing 
as a universally available database that you can expect to be available 
everywhere.

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


Re: Docstrings considered too complicated

2010-02-26 Thread Roy Smith
In article ,
 Tim Daneliuk  wrote:

> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote:
> > Hi all,
> > 
> > a company that works with my company writes a lot of of their code in
> > Python (lucky jerks). I've seen their code and it basically looks like
> > this:
> > 
> > """Function that does stuff"""
> > def doStuff():
> > while not wise(up):
> > yield scorn
> > 
> > Now my question is this: How do I kill these people without the
> > authorities thinking they didn't deserve it?
> > 
> > /W
> > 
> 
> Reminiscent of:
> 
> mov  AX,BX   ; Move the contents of BX into AX
> 
> And, yes, I've actually seen that as well as:
> 
> ; This is a comment

OK, if we're going to do this, how about this one, that I just found 
yesterday in some production C++ code.  I'm so glad somebody took the time 
to explain to me what p7 through p9 are.  I never would have figured it out 
otherwise.

/**
 * Tracing facility. Writes the message to the specified output stream.
 * If output stream is NULL, writes the message to the process log.
 *
 * @param  msg_id  The message id to use for lookup.
 * @param  ostrThe output stream.
 * @param  p1  The first substition parameter.
 * @param  p2  The second substition parameter.
 * @param  p3  The third substition parameter.
 * @param  p4  The fourth substition parameter.
 * @param  p5  The fifth substition parameter.
 * @param  p6  The sixth substition parameter.
 * @param  p7  The seventh substition parameter.
 * @param  p8  The eigth substition parameter.
 * @param  p9  The ninth substition parameter.
*/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Docstrings considered too complicated

2010-02-26 Thread Phlip
Andreas Waldenburger wrote:

> """Function that does stuff"""
> def doStuff():
>     while not wise(up):
>         yield scorn
>
> Now my question is this: How do I kill these people without the
> authorities thinking they didn't deserve it?

Their unit tests are just as complete, illustrative, and
administratively sanctioned, right?

--
  Phlip
  http://penbird.tumblr.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible to import from a cStringIO file object vs. file on disk?

2010-02-26 Thread Steve Holden
pyt...@bdurham.com wrote:
> Is it possible to import from a cStringIO file object (containing
> compiled byte code) vs. a physical file on disk?
>  
> I'm thinking that this is possible, given Python's ability to import
> from zip files, but I'm not sure where to look next.
>  
> Thank you,
> Malcolm
> 

You'll need to write a custom importer. PEP 302 contains the necessary
details.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: Docstrings considered too complicated

2010-02-26 Thread Richard Brodie

"Andreas Waldenburger"  wrote in message 
news:20100226173907.55676...@geekmail.invalid...

>> Reminiscent of:
>>
>> mov  AX,BX   ; Move the contents of BX into AX
>>
> Well, there might be some confusion there as to what gets moved where,
> wouldn't you say?

Depends on what assembler you're used to. I certainly find having the
operands that way round confusing.


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


Exception in pydoc

2010-02-26 Thread Ricardo Aráoz
I'm developing an in house app. Many coders here are not fluent in
english, so docstrings must be in Spanish in spite of recommendations
that docstrings better be in English.
When I use accented characters (in this case an 'ó') in my docstrings I
get :
>>> help('OpMejoraBizobj')
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python25\lib\site.py", line 346, in __call__
return pydoc.help(*args, **kwds)
  File "C:\Python25\lib\pydoc.py", line 1645, in __call__
self.help(request)
  File "C:\Python25\lib\pydoc.py", line 1687, in help
elif request: doc(request, 'Help on %s:')
  File "C:\Python25\lib\pydoc.py", line 1481, in doc
pager(title % desc + '\n\n' + text.document(object, name))
  File "C:\Python25\lib\pydoc.py", line 324, in document
if inspect.ismodule(object): return self.docmodule(*args)
  File "C:\Python25\lib\pydoc.py", line 1072, in docmodule
contents.append(self.document(value, key, name))
  File "C:\Python25\lib\pydoc.py", line 325, in document
if inspect.isclass(object): return self.docclass(*args)
  File "C:\Python25\lib\pydoc.py", line 1208, in docclass
contents = '\n'.join(contents)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
115: ordinal not in range(128)

The file's first two lines are :
"""
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""

Does pydoc only deal with ASCII?



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


Re: Dictionary or Database—Please advise

2010-02-26 Thread Jeremy
On Feb 26, 9:29 am, Chris Rebert  wrote:
> On Fri, Feb 26, 2010 at 7:58 AM, Jeremy  wrote:
> > I have lots of data that I currently store in dictionaries.  However,
> > the memory requirements are becoming a problem.  I am considering
> > using a database of some sorts instead, but I have never used them
> > before.  Would a database be more memory efficient than a dictionary?
> > I also need platform independence without having to install a database
> > and Python interface on all the platforms I'll be using.  Is there
> > something built-in to Python that will allow me to do this?
>
> If you won't be using the SQL features of the database, `shelve` might
> be another option; from what I can grok, I sounds like a dictionary
> stored mostly on disk rather than entirely in RAM (not 100% sure
> though):http://docs.python.org/library/shelve.html
>
> It's in the std lib and supports several native dbm libraries for its
> backend; one of them should almost always be present.
>
> Cheers,
> Chris
> --http://blog.rebertia.com

Shelve looks like an interesting option, but what might pose an issue
is that I'm reading the data from a disk instead of memory.  I didn't
mention this in my original post, but I was hoping that by using a
database it would be more memory efficient in storing data in RAM so I
wouldn't have to read from (or swap to/from) disk.  Would using the
shelve package make reading/writing data from disk faster since it is
in a binary format?

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


Re: Dictionary or Database_Please advise

2010-02-26 Thread D'Arcy J.M. Cain
On Fri, 26 Feb 2010 11:39:51 -0500
Roy Smith  wrote:
> Once you get into databases, platform independence will be an issue.  There 
> are many databases out there to pick from.  If you want something which 
> will work on a lot of platforms, a reasonable place to start looking is 
> MySQL.  It's free, runs on lots of platforms, has good Python support, and 
> there's lots of people on the net who know it and are willing to give help 
> and advice.

Or PostgreSQL.  It's free, runs on lots of platforms, has good Python
support, and there's lots of people on the net who know it and are
willing to give help and advice.  In addition, it is a truly enterprise
level, SQL standard, fully transactional database.  Don't start with
MySQL and uprade to PostgreSQL later when you get big.  Start with the
best one now and be ready.

> Databases have a bit of a learning curve.  If you've never done any 
> database work, don't expect to download MySql (or any other database) this 
> afternoon and be up and running by tomorrow.

Whatever database you get, there will probably be plenty of tutorials.
See http://www.postgresql.org/docs/current/interactive/tutorial.html
for the PostgreSQL one.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictionary or Database輝lease advise

2010-02-26 Thread km
Hi,

Probably u should try couchdb! its a document oriented database. (
apache.couchdb.org)
u can store your dictionaries as json documents and yes they  are simple
text files; data structures cna be directly stored into JSON documents.
memory efficient too..
python module @ http://code.google.com/p/couchdb-python/

HTH
Krishna
~~~
On Sat, Feb 27, 2010 at 1:39 AM, Roy Smith  wrote:

> In article
> <891a98fa-c398-455a-981f-bf72af772...@s36g2000prh.googlegroups.com>,
>  Jeremy  wrote:
>
> > I have lots of data that I currently store in dictionaries.  However,
> > the memory requirements are becoming a problem.  I am considering
> > using a database of some sorts instead, but I have never used them
> > before.  Would a database be more memory efficient than a dictionary?
> > I also need platform independence without having to install a database
> > and Python interface on all the platforms I'll be using.  Is there
> > something built-in to Python that will allow me to do this?
> >
> > Thanks,
> > Jeremy
>
> This is a very vague question, so it'll get a vague answer :-)
>
> If you have so much data that you're running into memory problems, then
> yes, storing the data externally in an disk-resident database seems like a
> reasonable idea.
>
> Once you get into databases, platform independence will be an issue.  There
> are many databases out there to pick from.  If you want something which
> will work on a lot of platforms, a reasonable place to start looking is
> MySQL.  It's free, runs on lots of platforms, has good Python support, and
> there's lots of people on the net who know it and are willing to give help
> and advice.
>
> Databases have a bit of a learning curve.  If you've never done any
> database work, don't expect to download MySql (or any other database) this
> afternoon and be up and running by tomorrow.
>
> Whatever database you pick, you're almost certainly going to end up having
> to install it wherever you install your application.  There's no such thing
> as a universally available database that you can expect to be available
> everywhere.
>
> Have fun!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictionary or Database—Please advise

2010-02-26 Thread mk

Jeremy wrote:

I have lots of data that I currently store in dictionaries.  However,
the memory requirements are becoming a problem.  I am considering
using a database of some sorts instead, but I have never used them
before.  Would a database be more memory efficient than a dictionary?
I also need platform independence without having to install a database
and Python interface on all the platforms I'll be using.  Is there
something built-in to Python that will allow me to do this?


Since you use dictionaries, I guess that simple store saving key:value 
will do?


If so, bsddb support built into Python will do just nicely.

bsddb is multiplatform, although I have not personally tested if a 
binary db created on one platform will be usable on another. You'd have 
to check this.


Caveat: from what some people say I gather that binary format between 
bsddb versions tends to change.


There's also ultra-cool-and-modern Tokyo Cabinet key:value store with 
Python bindings:


http://pypi.python.org/pypi/pytc/

I didn't test it, though.


Regards,
mk

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


Re: Dictionary or Database—Please advise

2010-02-26 Thread mk

Jeremy wrote:


Shelve looks like an interesting option, but what might pose an issue
is that I'm reading the data from a disk instead of memory.  I didn't
mention this in my original post, but I was hoping that by using a
database it would be more memory efficient in storing data in RAM so I
wouldn't have to read from (or swap to/from) disk.  Would using the
shelve package make reading/writing data from disk faster since it is
in a binary format?


Read the docs:

"class shelve.BsdDbShelf(dict[, protocol=None[, writeback=False]])¶
A subclass of Shelf which exposes first(), next(), previous(), 
last() and set_location() which are available in the bsddb module but 
not in other database modules. The dict object passed to the constructor 
must support those methods. This is generally accomplished by calling 
one of bsddb.hashopen(), bsddb.btopen() or bsddb.rnopen(). The optional 
protocol and writeback parameters have the same interpretation as for 
the Shelf class."


Apparently using shelve internally gives you option of using bsddb, 
which is good news: bsddb is B-tree DB, which is highly efficient for 
finding keys. I would recommend bsddb.btopen(), as it creates B-tree DB 
(perhaps other implementations, like anydb or hash db are good as well, 
but I personally didn't test them out).


I can't say for Berkeley DB implementation, but in general B-tree 
algorithm has O(log2 n) complexity for finding keys, which roughly means 
that if you need to find particular key in a db of 1 million keys, 
you'll probably need ~20 disk accesses (or even less if some keys looked 
at in the process of search happen to be in the same disk sectors). So 
yes, it's highly efficient.


Having said that, remember that disk is many orders of magnitude slower 
than RAM, so it's no free lunch.. Nothing will beat memory-based data 
structure when it comes to speed (well new flash or hybrid disks perhaps 
could significantly improve in comparison to current mainstream 
mechanical-platter disks? there are some hyper-fast storage hardware 
companies out there, although they tend to charge arm and leg for their 
stuff for now).


Caveat: Berkeley DB is dual-licensed -- if you're using it for 
commercial work, it might be that you'd need to buy a license for it. 
Although I have had no experience with this really, if someone here did 
perhaps they will shed some light on it?


Regards,
mk



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


Re: Docstrings considered too complicated

2010-02-26 Thread Jean-Michel Pichavant

Andreas Waldenburger wrote:

On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk 
wrote:

  

On 2/24/2010 2:23 PM, Andreas Waldenburger wrote:


[stuff]
  

Reminiscent of:

mov  AX,BX   ; Move the contents of BX into AX



Well, there might be some confusion there as to what gets moved where,
wouldn't you say? I guess this goes away after a couple of months,
though.
  


I agree to that statement, I was surprised that mov AX,BX assumes that 
BX is the source, and AX the destination. I never programmed in 
assembler though.


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


Re: Dictionary or Database_Please advise

2010-02-26 Thread mk

D'Arcy J.M. Cain wrote:


Or PostgreSQL.  It's free, runs on lots of platforms, has good Python
support, and there's lots of people on the net who know it and are
willing to give help and advice.  In addition, it is a truly enterprise
level, SQL standard, fully transactional database.  Don't start with
MySQL and uprade to PostgreSQL later when you get big.  Start with the
best one now and be ready.


I second that: I burned my fingers on MySQL quite a few times and don't 
want to have anything to do with it anymore. Eventually you hit the wall 
with MySQL (although I haven't tested latest and best, perhaps they 
improved).


E.g. don't even get me started on replication that tends to randomly 
fizzle out quietly without telling you anything about it. Or that 
FOREIGN KEY is accepted but referential integrity is not enforced. Or 
that if you want real transactions, you have to choose InnoDB table type 
but then you lose much of the performance. Etc.


No, if you have a choice, avoid MySQL and go for PGSQL. It's fantastic, 
if (necessarily) complex.


Regards,
mk

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


Re: Docstrings considered too complicated

2010-02-26 Thread Jean-Michel Pichavant

Roy Smith wrote:

In article ,
 Tim Daneliuk  wrote:

  

On 2/24/2010 2:23 PM, Andreas Waldenburger wrote:


Hi all,

a company that works with my company writes a lot of of their code in
Python (lucky jerks). I've seen their code and it basically looks like
this:

"""Function that does stuff"""
def doStuff():
while not wise(up):
yield scorn

Now my question is this: How do I kill these people without the
authorities thinking they didn't deserve it?

/W

  

Reminiscent of:

mov  AX,BX   ; Move the contents of BX into AX

And, yes, I've actually seen that as well as:

; This is a comment



OK, if we're going to do this, how about this one, that I just found 
yesterday in some production C++ code.  I'm so glad somebody took the time 
to explain to me what p7 through p9 are.  I never would have figured it out 
otherwise.


/**
 * Tracing facility. Writes the message to the specified output stream.
 * If output stream is NULL, writes the message to the process log.
 *
 * @param  msg_id  The message id to use for lookup.
 * @param  ostrThe output stream.
 * @param  p1  The first substition parameter.
 * @param  p2  The second substition parameter.
 * @param  p3  The third substition parameter.
 * @param  p4  The fourth substition parameter.
 * @param  p5  The fifth substition parameter.
 * @param  p6  The sixth substition parameter.
 * @param  p7  The seventh substition parameter.
 * @param  p8  The eigth substition parameter.
 * @param  p9  The ninth substition parameter.
*/
  

just in case the first sub param would be p0 :-)


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


How to end TCP socket data while using readline()?

2010-02-26 Thread Arjun
Hi, I have a small script that runs a TCP server. A client connects to
this server and transmits a stored file line-by-line, and then waits
for a confirmation "done". However, when I run them the first loop
never really ends -- as the TCP server keeps expecting more data. I am
using a file-like-object, and so somehow I have to communicate to the
server that it is the end-of-file.

here is some server code

sock1.bind(('', port))
print "Listening at port: ", port
sock1.listen(1)  # listening socket
(conn, addr) = sock1.accept()# connected socket
print 'Client (localhost) port: ', addr[1]

cf = conn.makefile('r',0)# file like obj for socket

lf = open('ccs.txt','w')
for line in cf:
lf.write(line)
lf.flush()
sys.stdout.write(line)
print len(line)

lf.close()  (*here*)
cf.close()
cf = conn.makefile('w',0)
print len(line)
print 'sendin'
stat = 'done'
cf.write(stat)
print stat
print 'sent'
cf.close()
print 'script done & connection closed'


The client is sending the lines through this code:

s.connect((host,port))
sfp = open("dcs.txt")
   # script = sfp.readlines()
stat = 'still'
cf = s.makefile('w',0)
for line in sfp.readlines():
cf.write(line)
print len(line)
print 'close'
cf.flush()
cf.close()
sfp.close()

cf = s.makefile('r',0)
print stat, 'waiting'
stat = cf.readline()
print stat, 'waiting'  # this should become "done waiting"
cf.close()
s.close()


So what I am wondering is:

1. Using a file-like object means that the socket becomes uni-
directional, until the mode of the file object is changed from 'r' to
'w' (or vice versa). This seems inefficient, and rather unPythonesque.
Can somebody tell me if there is a more elegant way of receiving all
the lines from the client, and then sending a "done" message to the
client?

2.  Where I have marked (*here*) in the server code, is where the
execution seems to stay waiting... apparently for more input from the
client. But then when I force-terminate the client script, the
execution continues on the server-side!! So then it sends the "done"
status to a (already dead) client, and then exits. How do I get the
server to know when the EOF has been reached while using FLOs?

Input on this will be much appreciated, because the documentation for
readlines() didn't help me with this.

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


Re: Docstrings considered too complicated

2010-02-26 Thread mk

Roy Smith wrote:


/**
 * Tracing facility. Writes the message to the specified output stream.
 * If output stream is NULL, writes the message to the process log.
 *
 * @param  msg_id  The message id to use for lookup.
 * @param  ostrThe output stream.
 * @param  p1  The first substition parameter.
 * @param  p2  The second substition parameter.
 * @param  p3  The third substition parameter.
 * @param  p4  The fourth substition parameter.
 * @param  p5  The fifth substition parameter.
 * @param  p6  The sixth substition parameter.
 * @param  p7  The seventh substition parameter.
 * @param  p8  The eigth substition parameter.
 * @param  p9  The ninth substition parameter.
*/


Well at least they did explain something. ;-) You should be happy you 
don't have to deal with PHP programmers that tend to write 
20-positional-argument function AND programmer 1 knows what params 1-7 
do, programmer 2 knows what params 8-15 do and nobody knows what params 
16-20 do.


Seriously.

Regards,
mk

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


SystemError: error return without exception set

2010-02-26 Thread Shailendra
Hi All,
I am getting error in "SystemError: error return without exception
set" which i am not able debug. I made following test program which
gives same error.

=test.py==

import numpy

class testClass:
def __init__(self,param1=1,param2=2):
self.param1,self.param2=param1,param2

def __str__(self):
return 'param1=%d param2=%d'%(self.param1,self.param2)


class makeLotOftestClass:
def __init__(self,paramlist1=None,paramlist2=None):
self.holder= numpy.empty((len(paramlist1),len(paramlist2)))
for i in range(len(paramlist1)):
for j in range(len(paramlist2)):

self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j])

def __str__():
str=''
for testclass in numpy.raven(self.holder):
str=str+testclass.__str__()
return str

if __name__=='__main__':

lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140])
print lotofclass

==

$ python test.py
Traceback (most recent call last):
  File "test.py", line 25, in 

lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140])
  File "test.py", line 16, in __init__
self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j])
SystemError: error return without exception set

Can someone point out why is this exception. It seems to be a simple
code. Google search for the error message did not help much.

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


collections use __next__() in python 2.6?

2010-02-26 Thread Gary Robinson
The Python 2.6.4 docs for collections at 
http://docs.python.org/library/collections.html say that __next__() is an 
abstract method for the Iterable ABC. But my understanding is that __next__() 
isn't supposed to be used until Python 3. Also, I'm using the Mapping ABC, 
which inherits from Iterable, and it doesn't seem to work if I define 
__next__(); I am not seeing problems if I define next() instead.

What am I missing?
-- 

Gary Robinson
CTO
Emergent Music, LLC
personal email: gary...@me.com
work email: grobin...@flyfi.com
Company: http://www.flyfi.com
Blog:http://www.garyrobinson.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When will Java go mainstream like Python?

2010-02-26 Thread John Nagle

Gregory Ewing wrote:

Lawrence D'Oliveiro wrote:
And then there’s caching. Modern CPUs owe most of their speed to 
assumptions that programs will obey locality of reference. 
Pointer-chasing is a cache-

hostile activity.


Another thing to consider is the rate at which garbage is
created. Java's fundamental types (ints, floats, etc.) are
unboxed, and objects are only used for relatively heavyweight
things. So you can do quite a lot of useful computation in
Java without creating any objects or leaving behind any
garbage.

In Python, on the other hand, you can't even do arithmetic
without creating and destroying intermediate objects at
every step. 


This is really a CPython implementation problem.  Face it,
CPython is a "naive interpreter".  It pretty much does the obvious.
In other words, the code for the worst case is used for all cases.
It doesn't optimize out reference count updates, do type inference
to avoid unnecessary boxing, or figure out at compile time which
objects could be "slotted" and don't need dictionary lookups for
fields.  Plus, of course, there's the GIL problem.

Reference counts aren't inherently slow.  About 90% of reference
count updates could be optimized out.  The compiler needs to understand
what's a temporary object and what isn't.  See

http://blogs.msdn.com/abhinaba/archive/2009/02/09/back-to-basics-optimizing-reference-counting-garbage-collection.aspx

The language isn't inherently slow, but CPython is.

The Shed Skin developer has shown what's possible.  He
doesn't have enough resources to finish a full implementation,
but he's on the right track.  There's grumbling about the
restrictions in Shed Skin, but only some of Shed Skin's
restrictions are inherently necessary.  The one Shed Skin
developer has accomplished far more than the PyPy army of ants.

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


Six Minutes and fourty two seconds

2010-02-26 Thread Tobiah
Now that I use python, this is the amount of time 
per day that I spend adding forgotten semicolons while
debugging other languages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lists of variables

2010-02-26 Thread Aahz
In article ,
Michael Pardee   wrote:
>
>I'm relatively new to python and I was very surprised by the following
>behavior:

http://starship.python.net/crew/mwh/hacks/objectthink.html
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Six Minutes and fourty two seconds

2010-02-26 Thread Matt Nordhoff
Tobiah wrote:
> Now that I use python, this is the amount of time 
> per day that I spend adding forgotten semicolons while
> debugging other languages.

You can fix that by not using other languages. :>
-- 
Matt Nordhoff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SystemError: error return without exception set

2010-02-26 Thread MRAB

Shailendra wrote:

Hi All,
I am getting error in "SystemError: error return without exception
set" which i am not able debug. I made following test program which
gives same error.

=test.py==

import numpy

class testClass:
def __init__(self,param1=1,param2=2):
self.param1,self.param2=param1,param2

def __str__(self):
return 'param1=%d param2=%d'%(self.param1,self.param2)


class makeLotOftestClass:
def __init__(self,paramlist1=None,paramlist2=None):
self.holder= numpy.empty((len(paramlist1),len(paramlist2)))
for i in range(len(paramlist1)):
for j in range(len(paramlist2)):

self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j])

def __str__():
str=''
for testclass in numpy.raven(self.holder):
str=str+testclass.__str__()
return str

if __name__=='__main__':

lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140])
print lotofclass

==

$ python test.py
Traceback (most recent call last):
  File "test.py", line 25, in 

lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140])
  File "test.py", line 16, in __init__
self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j])
SystemError: error return without exception set

Can someone point out why is this exception. It seems to be a simple
code. Google search for the error message did not help much.


As I see it, there are 2 problems here:

1. numpy arrays contain numbers, but what you're trying to put into the
array are not numbers.

2. The numpy module is trying to raise an exception but it isn't setting
up the exception correctly internally, which is a bug in numpy itself.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Six Minutes and fourty two seconds

2010-02-26 Thread mk

Tobiah wrote:
Now that I use python, this is the amount of time 
per day that I spend adding forgotten semicolons while

debugging other languages.


My objects are flat and I don't know who's Guido.

I blame it all on Python.

How about a PEP "Let's make Python look like PHP"?

Regards,
mk

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


Re: How to end TCP socket data while using readline()?

2010-02-26 Thread MRAB

Arjun Chennu wrote:

No need to flush because you're writing to a file and it'll be flushed

anyway when you close it.


True. I had introduced those flush lines while I was trying to 
troubleshoot this annoying situation. :-)


You've closed the file view, but the underlying socket is still open.


The server will see EOF only when the socket is closed by the client,
and closing the file view doesn't close the socket itself.


That's what I intended to do. Keep the socket open, but close the file 
object so that the direction of transfer can be reversed and a "done" 
message can be sent to the client.


TCP is meant to facilitate two-directional transfer innit? So how do I 
do that while using file objects? If i have to close the socket to do 
that, it seems a bit wasteful in terms of network 'transactions'


Thanks for your reply. I've already confirmed that closing the socket 
does indeed move the program ahead --- but I'd like to now make 
two-directional comm. possible.



Here's a trick borrowed from the POP3 format (used for email).

Server code:
...
cf = conn.makefile('r', 0)# file like obj for socket
lf = open('ccs.txt', 'w')
for line in cf:
if line == '.end\n':
break
if line.startswith('..'):
line = line[1 : ]
lf.write(line)
sys.stdout.write(line)
print len(line)
lf.close()
cf.close()
...


Client code:
...
cf = s.makefile('w', 0)
for line in sfp.readlines():
if line.startswith('.'):
cf.write('.')
cf.write(line)
print len(line)
cr.write('.end\n')
print 'close'
cf.close()
...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Possible to import from a cStringIO file object vs. file on disk?

2010-02-26 Thread python
Steve,

> You'll need to write a custom importer. PEP 302 contains the necessary 
> details.

Thanks for pointing me to PEP 302 and the imp module. 

It looks like "imp.load_compiled(name, pathname[, file])" is what I
need, but the description of this method (and similar methods) has the
following disclaimer:

Quote: "The file argument is the byte-compiled code file, open for
reading in binary mode, from the beginning. It must currently be a real
file object, not a user-defined class emulating a file." [1]

I tried using a cStringIO object vs. a real file object, but the help
documentation is correct - only a real file object can be used.

Any ideas on why these modules would impose such a restriction or is
this just an historical artifact?

Are there any techniques I can use to avoid this physical file
requirement?

Thanks,
Malcolm

[1] http://docs.python.org/library/imp.html#imp.load_module

pyt...@bdurham.com wrote:
> Is it possible to import from a cStringIO file object (containing
> compiled byte code) vs. a physical file on disk?
>  
> I'm thinking that this is possible, given Python's ability to import
> from zip files, but I'm not sure where to look next.
>  
> Thank you,
> Malcolm
> 


regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


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


Re: Is this secure?

2010-02-26 Thread Peter Pearson
On Wed, 24 Feb 2010 20:16:24 +0100, mk  wrote:
> On 2010-02-24 20:01, Robert Kern wrote:
>> I will repeat my advice to just use random.SystemRandom.choice() instead
>> of trying to interpret the bytes from /dev/urandom directly.
>
> Out of curiosity:
>
> def gen_rand_string(length):
>  prng = random.SystemRandom()
>  chars = []
>  for i in range(length):
>  chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz'))
>  return ''.join(chars)
>
> if __name__ == "__main__":
>  chardict = {}
>  for i in range(1):
> ##w = gen_rand_word(10)
>  w = gen_rand_string(10)
>  count_chars(chardict, w)
>  counts = list(chardict.items())
>  counts.sort(key = operator.itemgetter(1), reverse = True)
>  for char, count in counts:
>  print char, count
>
>
> s 3966
> d 3912
> g 3909
> h 3905
> a 3901
> u 3900
> q 3891
> m 3888
> k 3884
> b 3878
> x 3875
> v 3867
> w 3864
> y 3851
> l 3825
> z 3821
> c 3819
> e 3819
> r 3816
> n 3808
> o 3797
> f 3795
> t 3784
> p 3765
> j 3730
> i 3704
>
> Better, although still not perfect.

What would be perfect?  Surely one shouldn't be happy if all the
tallies come out exactly equal: that would be a blatant indication
of something very nonrandom going on.

The tallies given above give a chi-squared value smack in the
middle of the range expected for random sampling of a uniform
distribution (p = 0.505).  So the chi-squared metric of
goodness-of-fit to a unifom distribution says you're doing fine.

-- 
To email me, substitute nowhere->spamcop, invalid->net.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: collections use __next__() in python 2.6?

2010-02-26 Thread Raymond Hettinger
On Feb 26, 10:08 am, Gary Robinson  wrote:
> The Python 2.6.4 docs for collections 
> athttp://docs.python.org/library/collections.htmlsay that __next__() is an 
> abstract method for the Iterable ABC. But my understanding is that __next__() 
> isn't supposed to be used until Python 3. Also, I'm using the Mapping ABC, 
> which inherits from Iterable, and it doesn't seem to work if I define 
> __next__(); I am not seeing problems if I define next() instead.
>
> What am I missing?

It's a typo.
The abstract method is next().


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


Re: Is this secure?

2010-02-26 Thread Peter Pearson
On Wed, 24 Feb 2010 21:02:07 +0100, mk  wrote:
[snip]
>
> rand_str_SystemRandom_seeding
> mean 3845.15384615 std dev 46.2016419186
> l 3926 1.75 std devs away from mean
> y 3916 1.53 std devs away from mean
> d 3909 1.38 std devs away from mean
> a 3898 1.14 std devs away from mean
> p 3898 1.14 std devs away from mean
> c 3889 0.95 std devs away from mean
> u 3884 0.84 std devs away from mean
> j 3873 0.60 std devs away from mean
> n 3873 0.60 std devs away from mean
> w 3866 0.45 std devs away from mean
> x 3863 0.39 std devs away from mean
> r 3855 0.21 std devs away from mean
> m 3852 0.15 std devs away from mean
> b 3841 -0.09 std devs away from mean
> t 3835 -0.22 std devs away from mean
> o 3829 -0.35 std devs away from mean
> k 3827 -0.39 std devs away from mean
> i 3821 -0.52 std devs away from mean
> s 3812 -0.72 std devs away from mean
> q 3806 -0.85 std devs away from mean
> v 3803 -0.91 std devs away from mean
> g 3799 -1.00 std devs away from mean
> h 3793 -1.13 std devs away from mean
> e 3782 -1.37 std devs away from mean
> f 3766 -1.71 std devs away from mean
> z 3758 -1.89 std devs away from mean

Chi2 = 14.43, 25 d.f., prob = 0.046362.
The observed distribution is SIGNIFICANTLY CLOSER
to the uniform distribution than reasonable by chance.

> rand_str_SystemRandom_noseeding
> mean 3845.15384615 std dev 55.670522726
> i 3961 2.08 std devs away from mean
> r 3911 1.18 std devs away from mean
> e 3910 1.16 std devs away from mean
> m 3905 1.08 std devs away from mean
> a 3901 1.00 std devs away from mean
> u 3893 0.86 std devs away from mean
> t 3882 0.66 std devs away from mean
> w 3872 0.48 std devs away from mean
> s 3870 0.45 std devs away from mean
> c 3868 0.41 std devs away from mean
> n 3866 0.37 std devs away from mean
> q 3865 0.36 std devs away from mean
> k 3863 0.32 std devs away from mean
> y 3848 0.05 std devs away from mean
> j 3836 -0.16 std devs away from mean
> v 3830 -0.27 std devs away from mean
> f 3829 -0.29 std devs away from mean
> z 3829 -0.29 std devs away from mean
> g 3827 -0.33 std devs away from mean
> l 3818 -0.49 std devs away from mean
> b 3803 -0.76 std devs away from mean
> d 3803 -0.76 std devs away from mean
> p 3756 -1.60 std devs away from mean
> x 3755 -1.62 std devs away from mean
> h 3744 -1.82 std devs away from mean
> o 3729 -2.09 std devs away from mean

Chi2 = 20.96, 25 d.f., prob = 0.304944.
The observed distribution is not significantly different
from the uniform distribution.

> rand_str_custom
> mean 3517.15384615 std dev 40.7541336343
> i 3586 1.69 std devs away from mean
> a 3578 1.49 std devs away from mean
> e 3575 1.42 std devs away from mean
> m 3570 1.30 std devs away from mean
> q 3562 1.10 std devs away from mean
> c 3555 0.93 std devs away from mean
> g 3552 0.86 std devs away from mean
> w 3542 0.61 std devs away from mean
> p 3536 0.46 std devs away from mean
> x 3533 0.39 std devs away from mean
> s 3528 0.27 std devs away from mean
> o 3524 0.17 std devs away from mean
> d 3516 -0.03 std devs away from mean
> t 3515 -0.05 std devs away from mean
> h 3511 -0.15 std devs away from mean
> v 3502 -0.37 std devs away from mean
> z 3502 -0.37 std devs away from mean
> b 3500 -0.42 std devs away from mean
> f 3496 -0.52 std devs away from mean
> u 3492 -0.62 std devs away from mean
> l 3486 -0.76 std devs away from mean
> r 3478 -0.96 std devs away from mean
> n 3476 -1.01 std devs away from mean
> j 3451 -1.62 std devs away from mean
> k 3450 -1.65 std devs away from mean
> y 3430 -2.14 std devs away from mean

Chi2 = 12.28, 25 d.f., prob = 0.015815.
The observed distribution is SIGNIFICANTLY CLOSER
to the uniform distribution than reasonable by chance.

> It would appear that SystemRandom().choice is indeed best (in terms of 
> how much the counts stray from mean in std devs), but only after seeding 
> it with os.urandom.

I don't see any reason to worry about any of the three, except
perhaps that the first and last are surprisingly uniform.

-- 
To email me, substitute nowhere->spamcop, invalid->net.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictionary or Database—Please advise

2010-02-26 Thread CM
On Feb 26, 10:58 am, Jeremy  wrote:
> I have lots of data

How much is "lots"?

> that I currently store in dictionaries.  However,
> the memory requirements are becoming a problem.  I am considering
> using a database of some sorts instead, but I have never used them
> before.  Would a database be more memory efficient than a dictionary?

What do you mean by more efficient?

> I also need platform independence without having to install a database
> and Python interface on all the platforms I'll be using.  Is there
> something built-in to Python that will allow me to do this?

The SQLite datbase engine is built into Python 2.5 and up.  I have
heard on this list that there may be problems with it with Python 2.6
and up on Linux, but I've stayed with 2.5 and it works fine for me on
WinXP, Vista, and Linux.

You can use it as a disk-stored single database file, or an in-memory-
only database.  The SQLite website (http://www.sqlite.org/) claims it
is the "most widely deployed SQL database engine in the world.", for
what that's worth.

Have a look at this:
http://docs.python.org/library/sqlite3.html

Che



>
> Thanks,
> Jeremy

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


Re: lists of variables

2010-02-26 Thread Alf P. Steinbach

* Michael Pardee:

I'm relatively new to python and I was very surprised by the following behavior:


a=1
b=2


'a' refers to an object representing the integer 1.

Since 1 is an immutable value you can just as well think of it as 'a' containing 
the value 1, because a reference to an immutable value is for nearly all 
practical purposes indistinguishable from that value.


'b' refers to an object representing the integer 2, which, again, since integers 
are immutable, you can just as well think of as 'b' containing the value 2.




mylist=[a,b]


A 'list' object (an array) is constructed, and 'mylist' is set to refer to it. 
The array has two items. The first item is set to refer to same object as 'a' (a 
reference copy), the second item is set to refer to the same object as 'b'.


But since integers are immutable you can just as well think of it as a copying 
of the integer values.


Immutable values allow you to think of handling the values directly.



print mylist

[1, 2]

a=3


This changes what 'a' refers to.

It does not change what the first array element refers to.



print mylist

[1, 2]

Whoah!  Are python lists only for literals?


No, that's an irrelevant notion.



 Nope:


c={}
d={}


Here 'c' now refers to a dictionary object, which is mutable (can be changed).

And 'd' refers to another dictionary object.



mydlist=[c,d]
print mydlist

[{}, {}]


A 'list' array object is constructed, and 'mydlist' is set to refer to it.

The first item in the array is set to refer to the same object as 'c' refers to, 
namely a mutable dictionary object (currently an empty dictionary).


The second item in the array is set to refer to the same object as 'd' refers 
to, namely a mutable dictionary object (currently an empty dictionary).


It's the same that happened earlier with the integers.

The only difference, but it's a significant one, is that now the referred to 
objects are mutable, that is, they can be changed.




c['x']=1


The dictionary object referred to by 'c' is updated to now have a key 'x' with 
associated value 1.


In more gory detail: the key is associated with a reference to an object 
representing 1, but again, since integer values are immutable you can think of 
this as a direct association with the value; the reference view of this 
association is mostly[1] only relevant when the referred to object is mutable.


Since the dictionary object that you're changing is referred to by both 'c' and 
the first item of 'mydlist', both of these reflect the change.




print mydlist

[{'x': 1}, {}]


Yep.



So it looks like variables in a list are stored as object references.


You mean items in a list are references to objects. Yes.



This seems to confirm that:

mydlist[1]['y']=4

print mydlist

[{}, {'y': 4}]


To check that you should instead have printed 'd', where you'd also see the 
change, since 'd' refers to the same dictionary object as 'mydlist[1]' does.




So I figure my initial example doesn't work because if you assign a
literal to something it is changing the object.


No, it has nothing to do with literals.

With the current language definition[2], as of Python 2.x and 3.x, it's very 
simple: assignments copy references, and that's all they do.


References to immutable objects allow you to think of values being copied 
around, which except for checking the identities of those objects (seldom 
relevant) yields the exact same conclusions about the effect of operations, but 
that's only because those immutable objects never change.


What you did above was to copy references to mutable objects, objects that can 
change.


Then the value-copying view breaks down.



 But modifying a list
or dict (as long as you don't re-construct it) does not change the
object.


A simple way to think of this is copying references.

Objects are never copied by Python assignments.

The assignments only copy references.



I can think of some ways to work around this, including using single
element lists as "pointers":


aa=[1]
bb=[2]
myplist=[aa,bb]
print myplist

[[1], [2]]

aa[0]=3
print myplist

[[3], [2]]


This is the same as your last example above, except that now you're using 'list' 
arrays as the referred to mutable objects, instead of 'dict' dictionary objects.




But what would be "the python way" to accomplish "list of variables"
functionality?


Possibly, if you think of assignments as copying references, you won't need that 
notion.



Cheers & hth.,

- Alf

Notes:
[1] The reference view can be relevant also for immutable objects in (at least) 
two cases. One is when the program logic depends on object identity, obtainable 
via the id function, which is just bad programming, but I mention it for 
completeness. The other is where you have a really large immutable object, such 
as in Python 2.x a very large 'long' value; then assignments would be 
inefficient if the value was actually copied, but since assignments only copy 
references in Python you can blissfully disregard the siz

A more specific query ...

2010-02-26 Thread Gib Bogle
How can I interrogate Python to find out where it is looking to find the PyQt4 
DLLs in a Windows installation?  Secondarily, how is this search path set?

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


any news from Python Magazine ?

2010-02-26 Thread OdarR
Seems rather late...:
http://pythonmagazine.com/

"We'll be back, better than ever, on January 26th, 2010. "

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


Re: Docstrings considered too complicated

2010-02-26 Thread Mel
Jean-Michel Pichavant wrote:
> Andreas Waldenburger wrote:
>> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk 
>> wrote:
>>> Reminiscent of:
>>> mov  AX,BX   ; Move the contents of BX into AX

>> Well, there might be some confusion there as to what gets moved where,
>> wouldn't you say? I guess this goes away after a couple of months,
>> though.

> I agree to that statement, I was surprised that mov AX,BX assumes that
> BX is the source, and AX the destination. I never programmed in
> assembler though.

You could think of it as a not bad use of the design principle "Clear The 
Simple Stuff Out Of The Way First".  Destinations are commonly a lot simpler 
than sources -- just as in Python assignment statements.  So you can tell 
more or less at a glance what's going to be changed, then get into the deep 
analysis to find what it's going to be changed to.

Mel.


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


Re: Dictionary or Database—Please advise

2010-02-26 Thread Patrick Sabin



Shelve looks like an interesting option, but what might pose an issue
is that I'm reading the data from a disk instead of memory.  I didn't
mention this in my original post, but I was hoping that by using a
database it would be more memory efficient in storing data in RAM so I
wouldn't have to read from (or swap to/from) disk.


A database usually stores data on disk and not in RAM. However you could 
use sqlite with :memory:, so that it runs in RAM.



Would using the
shelve package make reading/writing data from disk faster since it is
in a binary format?

Faster than what? Shelve uses caching, so it is likely to be faster than 
a self-made solution. However, accessing disk is much slower than 
accessing RAM.



Jeremy

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


Re: Docstrings considered too complicated

2010-02-26 Thread Grant Edwards
On 2010-02-26, Jean-Michel Pichavant  wrote:
> Andreas Waldenburger wrote:
>> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk 
>> wrote:
>>
>>   
>>> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote:
>>> 
 [stuff]
   
>>> Reminiscent of:
>>>
>>> mov  AX,BX   ; Move the contents of BX into AX
>>
>> Well, there might be some confusion there as to what gets moved where,
>> wouldn't you say? I guess this goes away after a couple of months,
>> though.
>
> I agree to that statement, I was surprised that mov AX,BX assumes that 
> BX is the source, and AX the destination. I never programmed in 
> assembler though.

It depends on the assembler.  Some are dst, src and others are
the other way around.  Some vary depending on the instruction.

-- 
Grant Edwards   grante Yow! Sign my PETITION.
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


loop through each line in a text file

2010-02-26 Thread qtrimble
I'm a python newbie but I do have some basic scripting experience.  I
need to take the line starting with "wer" and extract the year and day
of year from that string.  I want to be able to add the year and day
of year from the last line having "wer*" to the lines occurring in
between "wer*" lines.  Python seems suitable to do this and I'm fairly
certain I can eventually get this to work but I've been hit with a
very short time frame so I'm looking for any generous help.  The data
below is just a sample.  There are well over 500,000 lines that need
processed.

wer1999001
  31.2234  82.2367
  37.9535  82.3456
wer1999002
  31.2234  82.2367
  37.9535  82.3456
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: loop through each line in a text file

2010-02-26 Thread Alf P. Steinbach

* qtrimble:

I'm a python newbie but I do have some basic scripting experience.  I
need to take the line starting with "wer" and extract the year and day
of year from that string.  I want to be able to add the year and day
of year from the last line having "wer*" to the lines occurring in
between "wer*" lines.  Python seems suitable to do this and I'm fairly
certain I can eventually get this to work but I've been hit with a
very short time frame so I'm looking for any generous help.  The data
below is just a sample.  There are well over 500,000 lines that need
processed.

wer1999001
  31.2234  82.2367
  37.9535  82.3456
wer1999002
  31.2234  82.2367
  37.9535  82.3456



  >>> line = "wer1999001"
  >>> line
  'wer1999001'
  >>> line[3:3+4]
  '1999'
  >>> line[7:7+3]
  '001'
  >>> _


Cheers & hth.,

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


Re: loop through each line in a text file

2010-02-26 Thread OdarR
On 26 fév, 22:08, qtrimble  wrote:
> I'm a python newbie but I do have some basic scripting experience.  I
> need to take the line starting with "wer" and extract the year and day
> of year from that string.  I want to be able to add the year and day
> of year from the last line having "wer*" to the lines occurring in
> between "wer*" lines.  Python seems suitable to do this and I'm fairly
> certain I can eventually get this to work but I've been hit with a
> very short time frame so I'm looking for any generous help.  The data
> below is just a sample.  There are well over 500,000 lines that need
> processed.
>
> wer1999001
>       31.2234      82.2367
>       37.9535      82.3456
> wer1999002
>       31.2234      82.2367
>       37.9535      82.3456

did you try something as a working basis ?

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


Re: A more specific query ...

2010-02-26 Thread Chris Rebert
On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle
 wrote:
> How can I interrogate Python to find out where it is looking to find the
> PyQt4 DLLs in a Windows installation?

import sys
print(sys.path)

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: loop through each line in a text file

2010-02-26 Thread qtrimble
On Feb 26, 4:14 pm, OdarR  wrote:
> On 26 fév, 22:08, qtrimble  wrote:
>
>
>
> > I'm a python newbie but I do have some basic scripting experience.  I
> > need to take the line starting with "wer" and extract the year and day
> > of year from that string.  I want to be able to add the year and day
> > of year from the last line having "wer*" to the lines occurring in
> > between "wer*" lines.  Python seems suitable to do this and I'm fairly
> > certain I can eventually get this to work but I've been hit with a
> > very short time frame so I'm looking for any generous help.  The data
> > below is just a sample.  There are well over 500,000 lines that need
> > processed.
>
> > wer1999001
> >       31.2234      82.2367
> >       37.9535      82.3456
> > wer1999002
> >       31.2234      82.2367
> >       37.9535      82.3456
>
> did you try something as a working basis ?
>
> Olivier

Yes but it's very simple -

fileIN = open(r"C:\testing.txt", "r")

for line in fileIN:
year = line[3:7]
day = line[7:10]
print year, day

This is good since i can get the year and day of year into a variable
but I haven't gotten any further.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >