Can't understand python C apis

2012-06-23 Thread gmspro
I'm trying to understand the source code of python and how it works internally.
But i can't understand the python C apis.
Too much macro calling there and python C api.
I can't understand those.
I've also read the doc for python C api.

What should i do? Which file's code should i read to understand those PyObject 
or other type and other C apis?

Any answer would be highly appreciated.

Thanks.

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


Re: Can't understand python C apis

2012-06-23 Thread Stefan Behnel
gmspro, 23.06.2012 09:02:
> I'm trying to understand the source code of python and how it works 
> internally.
> But i can't understand the python C apis.
> Too much macro calling there and python C api.
> I can't understand those.
> I've also read the doc for python C api.
> 
> What should i do? Which file's code should i read to understand those 
> PyObject or other type and other C apis?

The first thing to ask yourself is: why do you want to understand it? What
is the thing you are trying to do with it? Once you've answered that, it'll
be easy to tell you where to look.

Stefan

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


Re: Can't understand python C apis

2012-06-23 Thread Dieter Maurer
gmspro  writes:
>  I'm trying to understand the source code of python and how it works 
> internally.  
>  But i can't understand the python C apis.

Usually, you try to understand the Python C api in order to write
extensions for Python in C (e.g. to interface with an existing C library
or to optimize a tight loop).

If this is the case for you, then there is an alternative: "Cython".
"Cython" actually is a compiler which compiles an extended Python
source language (Python + type/variable declarations + extension types)
into "C". With its help, you can create C extensions for Python
without a need to know all the details of the Python C API.

It might still be necessary at some point to understand more
of the API but highly likely it will take considerable time
to reach that point -- and then you might already be more familiar
and the understanding might be easier.

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


cPickle - sharing pickled objects between scripts and imports

2012-06-23 Thread Rotwang
Hi all, I have a module that saves and loads data using cPickle, and 
I've encountered a problem. Sometimes I want to import the module and 
use it in the interactive Python interpreter, whereas sometimes I want 
to run it as a script. But objects that have been pickled by running the 
module as a script can't be correctly unpickled by the imported module 
and vice-versa, since how they get pickled depends on whether the 
module's __name__ is '__main__' or 'mymodule' (say). I've tried to get 
around this by adding the following to the module, before any calls to 
cPickle.load:


if __name__ == '__main__':
import __main__
def load(f):
p = cPickle.Unpickler(f)
def fg(m, c):
if m == 'mymodule':
return getattr(__main__, c)
else:
m = __import__(m, fromlist = [c])
return getattr(m, c)
p.find_global = fg
return p.load()
else:
def load(f):
p = cPickle.Unpickler(f)
def fg(m, c):
if m == '__main__':
return globals()[c]
else:
m = __import__(m, fromlist = [c])
return getattr(m, c)
p.find_global = fg
return p.load()
cPickle.load = load
del load


It seems to work as far as I can tell, but I'll be grateful if anyone 
knows of any circumstances where it would fail, or can suggest something 
less hacky. Also, do cPickle.Pickler instances have some attribute 
corresponding to find_global that lets one determine how instances get 
pickled? I couldn't find anything about this in the docs.



--
Hate music? Then you'll hate this:

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


Re: cPickle - sharing pickled objects between scripts and imports

2012-06-23 Thread Peter Otten
Rotwang wrote:

> Hi all, I have a module that saves and loads data using cPickle, and
> I've encountered a problem. Sometimes I want to import the module and
> use it in the interactive Python interpreter, whereas sometimes I want
> to run it as a script. But objects that have been pickled by running the
> module as a script can't be correctly unpickled by the imported module
> and vice-versa, since how they get pickled depends on whether the
> module's __name__ is '__main__' or 'mymodule' (say). I've tried to get
> around this by adding the following to the module, before any calls to
> cPickle.load:
> 
> if __name__ == '__main__':
>  import __main__
>  def load(f):
>  p = cPickle.Unpickler(f)
>  def fg(m, c):
>  if m == 'mymodule':
>  return getattr(__main__, c)
>  else:
>  m = __import__(m, fromlist = [c])
>  return getattr(m, c)
>  p.find_global = fg
>  return p.load()
> else:
>  def load(f):
>  p = cPickle.Unpickler(f)
>  def fg(m, c):
>  if m == '__main__':
>  return globals()[c]
>  else:
>  m = __import__(m, fromlist = [c])
>  return getattr(m, c)
>  p.find_global = fg
>  return p.load()
> cPickle.load = load
> del load
> 
> 
> It seems to work as far as I can tell, but I'll be grateful if anyone
> knows of any circumstances where it would fail, or can suggest something
> less hacky. Also, do cPickle.Pickler instances have some attribute
> corresponding to find_global that lets one determine how instances get
> pickled? I couldn't find anything about this in the docs.

if __name__ == "__main__":
from mymodule import *

But I think it would be cleaner to move the classes you want to pickle into 
another module and import that either from your main script or the 
interpreter. That may also spare you some fun with unexpected isinstance() 
results.


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


Re: emded revision control in Python application?

2012-06-23 Thread duncan smith

On 23/06/12 06:45, rusi wrote:

On Jun 22, 8:58 pm, duncan smith
wrote:

Hello,
I have an application that would benefit from collaborative
working. Over time users construct a "data environment" which is a
number of files in JSON format contained in a few directories (in the
future I'll probably place these in a zip so the environment is
contained within a single file). At the moment there is one individual
constructing the data environment, and me occasionally applying
corrections after being e-mailed the files. But in the future there
might be several individuals in various locations.

As a minimum requirement I need to embed some sort of version control,
so that changes committed by one individual will be seen in the local
environments of the others. Some of the work involves editing graphs
which have restrictions on their structure. In this case it would be
useful for edits to be committed / seen in real time. The users will not
be particularly technical, so the version control will have to happen
relatively quietly in the background.

My immediate thoughts are to (somehow) embed Mercurial or Subversion. It
would certainly be useful to be able to revert to a previous version of
the data environment if an individual does something silly. But I'm not
actually convinced that this is the whole solution for collaborative
working. Any advice regarding the embedding of a version control system
or alternative approaches would be appreciated. I haven't tried anything
like this before. The desktop application is written in Python (2.6)
with a wxPython (2.8) GUI. Given the nature of the application / data
the machines involved might be locally networked but without web access
(if this makes a difference). TIA.

Duncan


If you are looking at mercurial and subversion you may want to look at
git also.

 From http://en.wikipedia.org/wiki/Git_%28software%29#Implementation
(quoting Linus Torvalds)
---
In many ways you can just see git as a filesystem — it's content-
addressable, and it has a notion of versioning, but I really really
designed it coming at the problem from the viewpoint of a filesystem
person (hey, kernels is what I do), and I actually have absolutely
zero interest in creating a traditional SCM system.

More details https://git.wiki.kernel.org/index.php/Git#Design
-
Of course its good to say upfront that git is mostly C+shell ie its
not python
There is gitpython http://packages.python.org/GitPython/0.1/tutorial.html
but I know nothing about it


Thanks. I'm trying to figure out whether I'm better of with a version 
control system, a virtual filesystem (e.g. 
http://code.google.com/p/pyfilesystem/), remote procedure calls or some 
combination of these.


What I really need is a flexible framework that I can experiment with, 
as it's not clear what the best strategy for collaborative working might 
be. e.g. It might be best to restrict working on certain elements of the 
data environment to a single individual. Cheers.


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


SSL handshake hanging, despite bugfix in stdlib

2012-06-23 Thread Michael Gundlach
Hello,

http://bugs.python.org/issue5103 fixed a bug in Python2.6 where SSL's
handshake would hang indefinitely if the remote end hangs.

However, I'm getting hanging behavior in an IMAP script.  When I Ctrl-C it
after hours of hanging, I get the same stacktrace as reported in
http://bugs.python.org/issue1251#msg72363 , though Antoine said that r80452
fixed issue 5103 as well as this bug.

This script sends automatic response emails.  Every 10 seconds it uses IMAP
to check for unread messages in a GMail label, then replies via SMTP and
marks the message as read.  The script seems to work the first time an
unread message is found; the next time there's a message to be had, it
hangs trying to complete the SSL handshake.

  File "./main.py", line 21, in thank_new_signups
the_emails = list(emails.messages('(UNSEEN)'))
  File "./emails.py", line 129, in messages
for chunk in chunks_of_length(32, messages):
  File "./chunks.py", line 9, in chunks_of_length
for item in iterable:
  File "./emails.py", line 90, in email_messages
m = open_mailbox(label, readonly=True)
  File "./emails.py", line 30, in open_mailbox
m = imaplib.IMAP4_SSL('imap.gmail.com', 993)
  File "/usr/lib64/python2.6/imaplib.py", line 1138, in __init__
IMAP4.__init__(self, host, port)
  File "/usr/lib64/python2.6/imaplib.py", line 163, in __init__
self.open(host, port)
  File "/usr/lib64/python2.6/imaplib.py", line 1150, in open
self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
  File "/usr/lib64/python2.6/ssl.py", line 338, in wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs)
  File "/usr/lib64/python2.6/ssl.py", line 120, in __init__
self.do_handshake()
  File "/usr/lib64/python2.6/ssl.py", line 279, in do_handshake
self._sslobj.do_handshake()
KeyboardInterrupt

(This behavior started only in the last couple of weeks after a longer
period working correctly, so I suspect something changed on GMail's end to
trigger the bug.)

Am I do something wrong, or is this bug still not fixed?  Any pointers
would be appreciated.  Python 2.6.6 (r266:84292, Dec  7 2011, 20:48:22) on
64-bit Linux 2.6.32.
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cPickle - sharing pickled objects between scripts and imports

2012-06-23 Thread Dave Angel
On 06/23/2012 12:13 PM, Peter Otten wrote:
> Rotwang wrote:
>
>> Hi all, I have a module that saves and loads data using cPickle, and
>> I've encountered a problem. Sometimes I want to import the module and
>> use it in the interactive Python interpreter, whereas sometimes I want
>> to run it as a script. But objects that have been pickled by running the
>> module as a script can't be correctly unpickled by the imported module
>> and vice-versa, since how they get pickled depends on whether the
>> module's __name__ is '__main__' or 'mymodule' (say). I've tried to get
>> around this by adding the following to the module, before any calls to
>> cPickle.load:
>>
>> if __name__ == '__main__':
>>  import __main__
>>  def load(f):
>>  p = cPickle.Unpickler(f)
>>  def fg(m, c):
>>  if m == 'mymodule':
>>  return getattr(__main__, c)
>>  else:
>>  m = __import__(m, fromlist = [c])
>>  return getattr(m, c)
>>  p.find_global = fg
>>  return p.load()
>> else:
>>  def load(f):
>>  p = cPickle.Unpickler(f)
>>  def fg(m, c):
>>  if m == '__main__':
>>  return globals()[c]
>>  else:
>>  m = __import__(m, fromlist = [c])
>>  return getattr(m, c)
>>  p.find_global = fg
>>  return p.load()
>> cPickle.load = load
>> del load
>>
>>
>> It seems to work as far as I can tell, but I'll be grateful if anyone
>> knows of any circumstances where it would fail, or can suggest something
>> less hacky. Also, do cPickle.Pickler instances have some attribute
>> corresponding to find_global that lets one determine how instances get
>> pickled? I couldn't find anything about this in the docs.
> if __name__ == "__main__":
> from mymodule import *
>
> But I think it would be cleaner to move the classes you want to pickle into 
> another module and import that either from your main script or the 
> interpreter. That may also spare you some fun with unexpected isinstance() 
> results.
>
>



I would second the choice to just move the code to a separately loaded
module, and let your script simply consist of an import and a call into
that module.

It can be very dangerous to have the same module imported two different
ways (as __main__ and as mymodule), so i'd avoid anything that came
close to that notion.

Your original problem is probably that you have classes with two leading
underscores, which causes the names to be mangled with the module name. 
You could simply remove one of the underscores for all such names, and
see if the pickle problem goes away.




-- 

DaveA

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


Re: cPickle - sharing pickled objects between scripts and imports

2012-06-23 Thread Rotwang

On 23/06/2012 17:13, Peter Otten wrote:

Rotwang wrote:


Hi all, I have a module that saves and loads data using cPickle, and
I've encountered a problem. Sometimes I want to import the module and
use it in the interactive Python interpreter, whereas sometimes I want
to run it as a script. But objects that have been pickled by running the
module as a script can't be correctly unpickled by the imported module
and vice-versa, since how they get pickled depends on whether the
module's __name__ is '__main__' or 'mymodule' (say). I've tried to get
around this by adding the following to the module, before any calls to
cPickle.load:

if __name__ == '__main__':
  import __main__
  def load(f):
  p = cPickle.Unpickler(f)
  def fg(m, c):
  if m == 'mymodule':
  return getattr(__main__, c)
  else:
  m = __import__(m, fromlist = [c])
  return getattr(m, c)
  p.find_global = fg
  return p.load()
else:
  def load(f):
  p = cPickle.Unpickler(f)
  def fg(m, c):
  if m == '__main__':
  return globals()[c]
  else:
  m = __import__(m, fromlist = [c])
  return getattr(m, c)
  p.find_global = fg
  return p.load()
cPickle.load = load
del load


It seems to work as far as I can tell, but I'll be grateful if anyone
knows of any circumstances where it would fail, or can suggest something
less hacky. Also, do cPickle.Pickler instances have some attribute
corresponding to find_global that lets one determine how instances get
pickled? I couldn't find anything about this in the docs.


if __name__ == "__main__":
 from mymodule import *

But I think it would be cleaner to move the classes you want to pickle into
another module and import that either from your main script or the
interpreter. That may also spare you some fun with unexpected isinstance()
results.


Thanks.

--
Hate music? Then you'll hate this:

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


Re: cPickle - sharing pickled objects between scripts and imports

2012-06-23 Thread Rotwang

On 23/06/2012 18:31, Dave Angel wrote:

On 06/23/2012 12:13 PM, Peter Otten wrote:

Rotwang wrote:


Hi all, I have a module that saves and loads data using cPickle, and
I've encountered a problem. Sometimes I want to import the module and
use it in the interactive Python interpreter, whereas sometimes I want
to run it as a script. But objects that have been pickled by running the
module as a script can't be correctly unpickled by the imported module
and vice-versa, since how they get pickled depends on whether the
module's __name__ is '__main__' or 'mymodule' (say). I've tried to get
around this by adding the following to the module, before any calls to
cPickle.load:

if __name__ == '__main__':
  import __main__
  def load(f):
  p = cPickle.Unpickler(f)
  def fg(m, c):
  if m == 'mymodule':
  return getattr(__main__, c)
  else:
  m = __import__(m, fromlist = [c])
  return getattr(m, c)
  p.find_global = fg
  return p.load()
else:
  def load(f):
  p = cPickle.Unpickler(f)
  def fg(m, c):
  if m == '__main__':
  return globals()[c]
  else:
  m = __import__(m, fromlist = [c])
  return getattr(m, c)
  p.find_global = fg
  return p.load()
cPickle.load = load
del load


It seems to work as far as I can tell, but I'll be grateful if anyone
knows of any circumstances where it would fail, or can suggest something
less hacky. Also, do cPickle.Pickler instances have some attribute
corresponding to find_global that lets one determine how instances get
pickled? I couldn't find anything about this in the docs.

if __name__ == "__main__":
 from mymodule import *

But I think it would be cleaner to move the classes you want to pickle into
another module and import that either from your main script or the
interpreter. That may also spare you some fun with unexpected isinstance()
results.






I would second the choice to just move the code to a separately loaded
module, and let your script simply consist of an import and a call into
that module.

It can be very dangerous to have the same module imported two different
ways (as __main__ and as mymodule), so i'd avoid anything that came
close to that notion.


OK, thanks.



Your original problem is probably that you have classes with two leading
underscores, which causes the names to be mangled with the module name.
You could simply remove one of the underscores for all such names, and
see if the pickle problem goes away.


No, I don't have any such classes. The problem is that if the object was 
pickled by the module run as a script and then unpickled by the imported 
module, the unpickler looks in __main__ rather than mymodule for the 
object's class, and doesn't find it. Conversely if the object was 
pickled by the imported module and then unpickled by the module run as a 
script then the unpickler reloads the module and makes objects 
referenced by the original object into instances of 
mymodule.oneofmyclasses, whereas (for reasons unknown to me) the object 
itself is an instance of __main__.anotheroneofmyclasses. This means that 
any method of anotheroneofmyclasses that calls isinstance(attribute, 
oneofmyclasses) doesn't work the way it should.


--
Hate music? Then you'll hate this:

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


Re: cPickle - sharing pickled objects between scripts and imports

2012-06-23 Thread Steven D'Aprano
On Sat, 23 Jun 2012 19:14:43 +0100, Rotwang wrote:

> The problem is that if the object was
> pickled by the module run as a script and then unpickled by the imported
> module, the unpickler looks in __main__ rather than mymodule for the
> object's class, and doesn't find it. 

Possibly the solution is as simple as aliasing your module and __main__. 
Untested:

# When running as a script
import __main__
sys['mymodule'] = __main__


# When running interactively
import mymodule
__main__ = mymodule


of some variation thereof.

Note that a full solution to this problem actually requires you to deal 
with three cases:

1) interactive interpreter, __main__ normally would be the interpreter 
global scope

2) running as a script, __main__ is your script

3) imported into another module which is running as a script, __main__ 
would be that module.

In the last case, monkey-patching __main__ may very well break that 
script.


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


Why is python source code not available on github?

2012-06-23 Thread gmspro
Why is python source code not available on github?

Make it available on github so that we can git clone and work on source code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python source code not available on github?

2012-06-23 Thread George Silva
http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2

On Sat, Jun 23, 2012 at 9:16 PM, gmspro  wrote:

> Why is python source code not available on github?
>
> Make it available on github so that we can git clone and work on source
> code.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
George R. C. Silva

Desenvolvimento em GIS
http://geoprocessamento.net
http://blog.geoprocessamento.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python source code not available on github?

2012-06-23 Thread Andrew Berg
On 6/23/2012 7:16 PM, gmspro wrote:
> Why is python source code not available on github?
If you mean CPython, it's because the devs use Mercurial and have their
own hosting on python.org.

hg clone http://hg.python.org/cpython
http://docs.python.org/devguide/setup.html

github is far from the only place to host an open source project.
-- 
CPython 3.3.0a4 | Windows NT 6.1.7601.17803
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python source code not available on github?

2012-06-23 Thread Chris Angelico
On Sun, Jun 24, 2012 at 10:16 AM, gmspro  wrote:
>
> Why is python source code not available on github?
>
> Make it available on github so that we can git clone and work on source
> code.

It's done with Mercurial, not git, but the same can be done:

hg clone http://hg.python.org/cpython

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


Re: Why is python source code not available on github?

2012-06-23 Thread gmspro
No,
I can download as .tar.bz2, but i'm talking about using git.
git clone, git add ., git commit -a, git push is easier to keep track of my 
code. Then for git pull request.

--- On Sat, 6/23/12, George Silva  wrote:

From: George Silva 
Subject: Re: Why is python source code not available on github?
To: "gmspro" 
Cc: [email protected]
Date: Saturday, June 23, 2012, 7:23 PM

http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2

On Sat, Jun 23, 2012 at 9:16 PM, gmspro  wrote:


Why is python source code not available on github?



Make it available on github so that we can git clone and work on source code.

--

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





-- 
George R. C. Silva

Desenvolvimento em GIS
http://geoprocessamento.net
http://blog.geoprocessamento.net





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


Re: Why is python source code not available on github?

2012-06-23 Thread Chris Angelico
On Sun, Jun 24, 2012 at 10:34 AM, gmspro  wrote:
>
> No,
> I can download as .tar.bz2, but i'm talking about using git.
> git clone, git add ., git commit -a, git push is easier to keep track of
> my code. Then for git pull request.

Mercurial can do all that. I'm not as familiar with it as I am with
git, so I can't quote the commands, but certainly you can do all the
same clone/add/commit/etc with it. I build my cpython straight from
hg, mainly because I like living on the edge :)

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


Filenames started with _(underscore) in Modules/ why?

2012-06-23 Thread gmspro
There are some files whose filename is started with _(underscore). Why are they 
started with
a underscore?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Filenames started with _(underscore) in Modules/ why?

2012-06-23 Thread Thomas Jollans

On 06/24/2012 02:54 AM, gmspro wrote:

There are some files whose filename is started with _(underscore). Why
are they started with
a underscore?


By convention, a leading underscore means private/internal.

A module with a leading underscore is typically an implementation detail 
of another module with a public API, and should be ignored.


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


Getting lazy with decorators

2012-06-23 Thread Josh English
I'm creating a cmd.Cmd class, and I have developed a helper method to easily 
handle help_xxx methods.

I'm trying to figure out if there is an even lazier way I could do this with 
decorators.

Here is the code:
*
import cmd


def add_help(func):
if not hasattr(func, 'im_class'):
return func #probably should raise an error
cls = func.im_class
setattr(cls, func.im_func.__name__.replace("do","help"), None)

return func


class BaseCmd(cmd.Cmd):
def __init__(self, *args, **kwargs):
cmd.Cmd.__init__(self, *args, **kwargs)

def show_help(self, func):
print "\n".join((line.strip() for line in func.__doc__.splitlines()))

@add_help
def do_done(self, line):
"""done
Quits this and goes to higher level or quits the application.
I mean, what else do you expect?
"""
return True

if __name__=='__main__':
c = BaseCmd()

print c.help_done


* 

This generates "AttributeError: BaseCmd instance has no attribute 'help_done'"

The show_help method is the shortcut I want to use (I'm pretty sure it's from 
Doug Hellman's site). I'm wondering if it's possible to use a decorator such as 
add_help to automatically create the appropriate help_xxx function.

In the decorator, I can get the function and the name of the class, but I can't 
find the instance of  the class that the method is attached to. Maybe this is 
just one step of lazy too far.


Am I right in thinking that I can't do this? There is no way to access the 
class instance from the method?
-- 
http://mail.python.org/mailman/listinfo/python-list


How can i call array_length to get the length of array object?

2012-06-23 Thread gmspro
Hi,

I tried this, 
>>> import array
>>> from array import array
>>> arr=array('i',[5,7,8])
>>> arr.sg_length
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'array.array' object has no attribute 'sg_length'
>>> arr=array('i'[5,8,7])
Traceback (most recent call last):
  File "", line 1, in 
TypeError: string indices must be integers
>>> arr=array('i',[5,8,7])
>>> arr.length
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'array.array' object has no attribute 'length'
>>> arr.length()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'array.array' object has no attribute 'length'
>>> length(arr)
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'length' is not defined
>>> array_length(arr)
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'array_length' is not defined
>>> arr.array_length()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'array.array' object has no attribute 'array_length'
>>> arr.array_length
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'array.array' object has no attribute 'array_length'

I'm trying to call this function, 
http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657

Is that possible to call that function?

I know it's possible to do:
>>>len(arr)
>>>arr.itemsize

Any asnwer will be highly appreciated.

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


Re: How can i call array_length to get the length of array object?

2012-06-23 Thread Ignacio Mondino
On Sat, Jun 23, 2012 at 11:23 PM, gmspro  wrote:
>
> Hi,
>
> I tried this,
> >>> import array
> >>> from array import array
> >>> arr=array('i',[5,7,8])
> >>> arr.sg_length
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'sg_length'
> >>> arr=array('i'[5,8,7])
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: string indices must be integers
> >>> arr=array('i',[5,8,7])
> >>> arr.length
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'length'
> >>> arr.length()
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'length'
> >>> length(arr)
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'length' is not defined
> >>> array_length(arr)
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'array_length' is not defined
> >>> arr.array_length()
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'array_length'
> >>> arr.array_length
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'array_length'
>
> I'm trying to call this function, 
> http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657
>
> Is that possible to call that function?
>
> I know it's possible to do:
> >>>len(arr)
> >>>arr.itemsize
>
> Any asnwer will be highly appreciated.
>
> Thanks.
>
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,

something along the lines
>>> s = 'supercalifragilisticexpialidocious'
>>> len(s)
34

check http://docs.python.org/ for more on this.

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


Re: How can i call array_length to get the length of array object?

2012-06-23 Thread gmspro
@Ignacio Mondino,

Doesn't it call this : 
http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283 
instead of this: 
http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657

--- On Sat, 6/23/12, Ignacio Mondino  wrote:

From: Ignacio Mondino 
Subject: Re: How can i call array_length to get the length of array object?
To: "gmspro" 
Cc: "python-list" 
Date: Saturday, June 23, 2012, 10:34 PM

On Sat, Jun 23, 2012 at 11:23 PM, gmspro  wrote:
>
> Hi,
>
> I tried this,
> >>> import array
> >>> from array import array
> >>> arr=array('i',[5,7,8])
> >>> arr.sg_length
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'sg_length'
> >>> arr=array('i'[5,8,7])
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: string indices must be integers
> >>> arr=array('i',[5,8,7])
> >>> arr.length
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'length'
> >>> arr.length()
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'length'
> >>> length(arr)
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'length' is not defined
> >>> array_length(arr)
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'array_length' is not defined
> >>> arr.array_length()
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'array_length'
> >>> arr.array_length
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'array.array' object has no attribute 'array_length'
>
> I'm trying to call this function, 
> http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657
>
> Is that possible to call that function?
>
> I know it's possible to do:
> >>>len(arr)
> >>>arr.itemsize
>
> Any asnwer will be highly appreciated.
>
> Thanks.
>
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,

something along the lines
>>> s = 'supercalifragilisticexpialidocious'
>>> len(s)
34

check http://docs.python.org/ for more on this.

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


Re: SSL handshake hanging, despite bugfix in stdlib

2012-06-23 Thread Terry Reedy

On 6/23/2012 1:29 PM, Michael Gundlach wrote:

Hello,

http://bugs.python.org/issue5103 fixed a bug in Python2.6 where SSL's


I believe the fix first appeared in 2.6.6.


handshake would hang indefinitely if the remote end hangs.

However, I'm getting hanging behavior in an IMAP script.  When I Ctrl-C
it after hours of hanging, I get the same stacktrace as reported in
http://bugs.python.org/issue1251#msg72363 , though Antoine said that
r80452 fixed issue 5103 as well as this bug.


He claimed that it should fix 1251, but I cannot see that there was a 
dependable code for making the problem appear.



(This behavior started only in the last couple of weeks after a longer
period working correctly, so I suspect something changed on GMail's end
to trigger the bug.)


Possible.


Am I do something wrong, or is this bug still not fixed?  Any pointers
would be appreciated.  Python 2.6.6 (r266:84292, Dec  7 2011, 20:48:22)
on 64-bit Linux 2.6.32.
Michael


If you want any attention from developers, you will have to show a 
problem with 2.7.3 or latest 3.2+. I do not know that there is much 
change in 2.7, but I know there is more in change in 3.3 (the 
do_handshake call is moved and has a different context.


--
Terry Jan Reedy



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


Re: How can i call array_length to get the length of array object?

2012-06-23 Thread Ian Kelly
On Sat, Jun 23, 2012 at 8:23 PM, gmspro  wrote:
> I'm trying to call this function, 
> http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657
>
> Is that possible to call that function?
>
> I know it's possible to do:
> >>>len(arr)

You call it just like that.  array_length is the C implementation of
__len__ for arrays.

> Doesn't it call this :
> http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283
> instead of this:
> http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657

Yes, and builtin_len calls PyObject_Size, which in turn calls the
object's sq_length method, which is defined to be array_length for
arrays.
-- 
http://mail.python.org/mailman/listinfo/python-list