Re: python file API

2012-09-25 Thread Ulrich Eckhardt

Am 24.09.2012 23:49, schrieb Dave Angel:

And what approach would you use for positioning relative to
end-of-file?  That's currently done with an optional second

> parameter to seek() method.

Negative indices.

;)

Uli


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


Re: python file API

2012-09-25 Thread Mark Lawrence

On 25/09/2012 03:32, Mark Adam wrote:

On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin
 wrote:

There are many situations where a little bit of attribute access magic is a
good thing. However, operations that involve the underlying OS and that are
prone to raising exceptions even in bug free code should not be performed
implicitly like this. I find the following a little cryptic:
try:
 f.pos = 256
except IOError:
 print('Unseekable file')


Well it might be that the coupling between the python interpreter and
the operating system should be more direct and there should be a
special exception class that bypasses the normal overhead in the
CPython implementation so that error can be caught in the code without
breaking syntax.  But I don't think I'm ready to argue that point

markj



Something along these lines 
http://docs.python.org/dev/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy 
?


--
Cheers.

Mark Lawrence.

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


Re: python file API

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 07:25:48 +0200, Thomas Rachel wrote:

> Am 25.09.2012 04:28 schrieb Steven D'Aprano:
> 
>> By the way, the implementation of this is probably trivial in Python
>> 2.x. Untested:
>>
>> class MyFile(file):
>>  @property
>>  def pos(self):
>>  return self.tell()
>>  @pos.setter
>>  def pos(self, p):
>>  if p<  0:
>>  self.seek(p, 2)
>>  else:
>>  self.seek(p)
>>
>> You could even use a magic sentinel to mean "see to EOF", say, None.
>>
>>  if p is None:
>>  self.seek(0, 2)
>>
>> although I don't know if I like that.
> 
> The whole concept is incomplete at one place: self.seek(10, 2) seeks
> beyond EOF, potentially creating a sparse file. This is a thing you
> cannot achieve.

On the contrary, since the pos attribute is just a wrapper around seek, 
you can seek beyond EOF easily:

f.pos = None
f.pos += 10

But for anything but the most trivial usage, I would recommend sticking 
to the seek method.

The problem with this idea is that the seek method takes up to three 
arguments (the file being operated on, the position, and the mode), and 
attribute syntax can only take two (the file, the position, e.g.: 
file.pos = position). So either there are cases that file.pos cannot 
handle (and so we need to keep tell/seek around, which leaves file.pos 
redundant), or we need multiple attributes, one for each mode), or we 
build a complicated, inconvenient API using special data types instead of 
plain integers.

So all up, I'm -1 on trying to replace the tell/seek API, and -0 on 
adding a second, redundant API.

Wait, there is another alternative: tuple arguments:

f.pos = (where, whence)

being the equivalent to seek(where, whence). At this point you just save 
two characters "f.pos=a,b" vs "f.seek(a,b)" so it simply isn't worth it 
for such a trivial benefit.


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


Re: For Counter Variable

2012-09-25 Thread Dwight Hutto
> By now I think we're in the DNFTT zone.
> --
Taking a bite yourself there buddy. Hop under the bridge, and
comment...it make you a troll, and you're trying to feed yourself with
pile on comment from the rest of the under bridge dwellers.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: eGenix mxODBC 3.2.1 - Python ODBC Database Interface

2012-09-25 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

 eGenix.com mxODBC

   Python ODBC Database Interface

   Version 3.2.1


mxODBC is our commercially supported Python extension providing
 ODBC database connectivity to Python applications
on Windows, Mac OS X, Unix and BSD platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-3.2.1-GA.html



INTRODUCTION

mxODBC provides an easy-to-use, high-performance, reliable and robust
Python interface to ODBC compatible databases such as MS SQL Server,
MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and
Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more:

 http://www.egenix.com/products/python/mxODBC/

The "eGenix mxODBC - Python ODBC Database Interface" product is a
commercial extension to our open-source eGenix mx Base Distribution:

 http://www.egenix.com/products/python/mxBase/



NEWS

The 3.2.1 release of our mxODBC is the latest patch level release of
our popular Python ODBC Interface. In this release, we've included the
following the following enhancements and fixes:

Feature Enhancements


 * The next SQLAlchemy release will be fully compatible with mxODBC
   3.2.1. Many thanks go to Michael Bayer for working with us to make
   this happen.

Driver Compatibility Enhancements
-

 * Added support for returning SQL Server TIME columns as time value
   instead of as string.

 * Added a work-around to prevent truncation warnings with the SQL
   Server ODBC driver when using .executemany(..., direct=1).


mxODBC 3.2 was released on 2012-08-28. These are the highlights of the
new release:

mxODBC 3.2 Feature Highlights
-

 * Switched to unixODBC 2.3.1+ API: mxODBC is now compiled against
   unixODBC 2.3.1, which finally removes the problems with the ABI
   change between 2.2 and 2.3 by switching to a new library version
   (libodbc.so.2).

 * mxODBC connection objects can now be used as context managers to
   implicitly commit/rollback transactions.

 * mxODBC cursor objects can now be used as context managers to
   implicitly close the cursor when leaving the block (regardless of
   whether an exception was raised or not)

 * mxODBC added support for adjustable .paramstyles. Both 'qmark'
   (default) and 'named' styles are supported and can be set on
   connections and cursors. The 'named' style allows easier porting of
   e.g. Oracle native interface code to mxODBC.

 * mxODBC now supports a writable connection.autocommit attribute to
   easily turn on/off the connection's auto commit mode.

 * mxODBC added support for adjustable TIMESTAMP precision via the new
   connection/cursor.timestampresolution attribute.

 * mxODBC will round to nearest nanosecond fraction instead of
   truncating the value. This will result in fewer conversion errors
   due to floating point second values.

 * mxODBC's connect APIs Connect() and DriverConnect() support setting
   connection options prior to connecting to the database via a new
   connection_options parameter. This allows enabling e.g. the MARS
   feature in SQL Server Native Client.

 * The connection.cursor() constructor now has a new cursor_options
   parameters which allows configuring the cursor with a set of cursor
   options.

 * The .scroll() method supports far more ODBC drivers than before.

 * Updated the SQL lookup object to include more ODBC SQL parameter
   codes, including special ones for SQL Server and IBM DB2.

 * mx.ODBC.Manager will now prefer unixODBC over iODBC. Previous
   mxODBC releases used the order iODBC, unixODBC, DataDirect when
   looking for a suitable ODBC manager on Unix platforms. unixODBC is
   more widely supported nowadays and provides better Unicode support
   than iODBC.

For the full set of features mxODBC has to offer, please see:

http://www.egenix.com/products/python/mxODBC/#Features

mxODBC 3.2 Driver Compatibility Enhancements


 * Added work-around for Oracle Instance Client to prevent use of
   direct execution. cursor.executedirect() will still work, but won't
   actually use direct execution with the Oracle driver.

 * Added work-around for Oracle Instant Client to prevent segfaults in
   the driver when querying the cursor.rowcount or cursor.rownumber.

 * Added check to make sure that Python type binding mode is not used
   with Oracle Instance Client as this can cause segfaults with the
   driver and generally doesn't work.

 * Added a work-around to have the IBM DB2 driver return correct
   .rowcount values.

 * Improved Sybase ASE driver compatibility: this only 

Re: which a is used?

2012-09-25 Thread Mark Lawrence

On 25/09/2012 06:07, Thomas Rachel wrote:

Am 25.09.2012 04:37 schrieb Dwight Hutto:

I honestly could not care less what you think about me, but don't use
that term. This isn't a boys' club and we don't need your hurt ego
driving people away from here.


OH. stirrin up shit and can't stand the smell.


Where did he so?


Thomas


He's referring to threads on the tutor mailing list where I have 
repeatedly asking him to provide context when he replies.  Unfortunately 
he doesn't seem to understand the term context so resorts to attacking 
me.  In a part of one thread he referred to my family as pigs.  I've 
have lived with that, using the sticks and stones reply, but then 
someone had the audacity to protect his stance.  I am sure that people 
have seen enough of his behaviour in the last few hours to see the real 
Dwight Hutto so I'll leave it at that.


--
Cheers.

Mark Lawrence.

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


Re: For Counter Variable

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 07:53:55 +0200, Thomas Rachel wrote:

> When learning Python, it often happend me to re-inven the wheel. But as
> soon as I saw the presence of something I re-wrote, I skipped my
> re-written version and used the built-in.

And me.

Not just Python either. The very first piece of code I wrote on a Linux 
machine was a shell script that (very badly, and even more very slowly) 
counted the number of files in a directory. 20 lines (if I remember 
correctly) to duplicate a simple:

ls | wc -l


It was a humbling lesson to always check what features a programming 
environment or language offers before reinventing the wheel with four 
sides.



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


Re: Who's laughing at my responses, and who's not?

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 00:43:18 -0400, Dwight Hutto wrote:

> It sounds pretentious, but over the past several days, I've been slammed
> on every post almost. 

That's a gross exaggeration.

Over the last few days you have gotten slammed because you mildly broke 
etiquette and then, instead of accepting the minor criticism and moving 
on, you got into an argument about it, and made what seemed like a 
racially motivated joke. Even if it were completely innocent, it didn't 
*seem* innocent.

And then you make rude comments about people, sexist comments about there 
being "ladies present" (my wife can turn the air blue, and sometimes she 
embarrasses me), and you recently accused others of being sock-puppets 
without a shred of evidence.

Dwight, or David if you prefer, sometimes you make useful comments and 
you can be a welcome, useful member of the Python community, but other 
times you display an incoherent, rambling, aggressive style that 
indicates that you are posting while high or drunk.

For your own sake, I suggest you stay off the Internet (including email 
and usenet) unless sober.



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


Re: For Counter Variable

2012-09-25 Thread Chris Angelico
On Tue, Sep 25, 2012 at 11:32 AM, Dwight Hutto  wrote:
>> By now I think we're in the DNFTT zone.
>> --
> Taking a bite yourself there buddy. Hop under the bridge, and
> comment...it make you a troll, and you're trying to feed yourself with
> pile on comment from the rest of the under bridge dwellers.

Dwight/David, may I courteously recommend and request that you refrain
from posting until you've calmed down a little? You're really not
doing your reputation much good. Unfortunately you're also impacting
the reputation of the list/newsgroup. People will come here looking
for help, and will see that people are biting and scratching at one
another[1], and will turn away. And that, in turn, reflects badly on
the language.

It's fine to disagree with someone - that's one of the best ways to
explore a problem space and turn up more information. What's not fine
is the bad language and vitriol.

To Paul Rubin (whose name and citation were omitted from Dwight's
quoted text): My apologies, I fear I am feeding a troll here. But
something needed to be said.

[1] Galations 5:15, eg http://bible.cc/galatians/5-15.htm - come to
think of it, the whole chapter applies fairly well here.
http://www.biblegateway.com/passage/?search=Galatians+5

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


Re: For Counter Variable

2012-09-25 Thread Mark Lawrence

On 25/09/2012 08:46, Steven D'Aprano wrote:

On Tue, 25 Sep 2012 07:53:55 +0200, Thomas Rachel wrote:


When learning Python, it often happend me to re-inven the wheel. But as
soon as I saw the presence of something I re-wrote, I skipped my
re-written version and used the built-in.


And me.

Not just Python either. The very first piece of code I wrote on a Linux
machine was a shell script that (very badly, and even more very slowly)
counted the number of files in a directory. 20 lines (if I remember
correctly) to duplicate a simple:

ls | wc -l


It was a humbling lesson to always check what features a programming
environment or language offers before reinventing the wheel with four
sides.





Thankfully easier in a relatively concise language like Python as 
opposed to (say) Java.  Which reminds me, in what version of Python are 
we getting the singletonMap? :)


--
Cheers.

Mark Lawrence.

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


Re: Seome kind of unblocking input

2012-09-25 Thread janis . judvaitis
Thanks for reply's. I'll be looking into threading, it seems like right way to 
go.

btw. Why  Python developers don't make a wrapper for input() with callback 
function using threads, so people can easily use nonblocking input?
-- 
http://mail.python.org/mailman/listinfo/python-list


Article on the future of Python

2012-09-25 Thread Mark Lawrence

Hi all,

I though this might be of interest.

http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python

--
Cheers.

Mark Lawrence.

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


Re: why do this program not fullscreen?

2012-09-25 Thread Vlastimil Brom
2012/9/25 Levi Nie :
> the code:
> import wx
> app=wx.App()
> win=wx.Frame(None)
> win.ShowFullScreen()
> app.MainLoop()
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Hi,

win.ShowFullScreen(True)
should work, the boolean parameter appears to be required.

hth,
  vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-25 Thread Gelonida N

On 09/25/2012 01:38 AM, alex23 wrote:

On Sep 25, 6:04 am, Gelonida N  wrote:

This all does not sound very comforting. Why is there no fix on the
official site?


Has a bug been logged about the issue?

The Plone community keeps a fairly up-to-date fork called Pillow,
we've had a lot of success using that locally:

http://pypi.python.org/pypi/Pillow/


Thanks for all your answers.

So it seems to be safe to use either Christoph' binary PIL distribution 
or to use Pillow.


The fact, that pillow is accessable via PyPi / easy_install / PIP pushes 
me slightly towards pillow.



I assume it's best to uninstall PIL before installing pillow.


How much would I confuse easy_install / pip in a normal windows
non virutal environment if I didn't uninstall PIP before (or even worse 
if I installed PIL, then pillow and uninstalled then PIL)


(Just anticipating all the smart thigns, that my collegues (or myself) 
might do



On a Linux machine:
What would happen in a virtualenv with sitepackages (amonst them PIL 
installed and a pillow installed ontop of it?

I don't think I can uninstall PIL, as many distro packages depend on it.
I don't want to create a virtualenv without site packages, as I have 
many dependencies and some of them are a little tricky to compile.


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


random access to video file

2012-09-25 Thread JRV
Hello,

Is there a method for randomly accessing a video file in Python / OpenCV ?

A kind of fseek which would allow to go directly to frame n ...

Cordially,
JRV
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keeping information about players around

2012-09-25 Thread Jean-Michel Pichavant
- Original Message -
> PHPMyAdmin? Might I ask why? This is a mud, so it's all command
> based,
> so that's not even a question, but I'm kind of curious how PHPMyAdmin
> factors in there. It's a database creation tool from all I've ever
> seen
> of it, to define tables. Also, using it requires that I have it up on
> some server or another, and I'd really rather avoid that if I can.

Given the nature of your project forget MysQL and phpAdmin. At most you may use 
sqlite. Sqlite data is stored in one file, locally, you can move it back it up 
easily. Sqlite doesn't need any server.
If you don't see How sqlite would benefit your mud, that would be strange, but 
then drop it and use pickled dictionaries if you're familiar with them.

> > Why would you use a dictionary, when it's DB manipulation you're
> > after?
> 
> It is? I don't remember mentioning database anything in my thread.
> Unless I missed it, I mentioned pickle once or twice. But either
> way, I'd use a dictionary to keep a copy of {uid:object} for
> objects and {uid:player} for players. Makes lookup by uid pretty
> easy, as well as for any loaded objects.

Actually you mentioned a "player database" in your original post. Player with 
their stats are typically something that may ends up in a database, along with 
any object and its properties.
That's why people suggested to use a database. Databases provide then powerful 
tools to fetch, search and edit your data. Performances on disk access would be 
handled by sqlite itself, something you may care by yourself if you use 
dictionaries.

Or maybe your mud doesn't store anything on disk, every run start fresh, in 
that case just use dictionaries.

JM



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


Re: Who's laughing at my responses, and who's not?

2012-09-25 Thread Jean-Michel Pichavant


- Original Message -
> On 9/24/2012 10:43 PM, Dwight Hutto wrote:
> > It sounds pretentious, but over the past several days, I've been
> > slammed on every post almost. All because of an argument over me
> > not
> > posting a little context in a conversation, that seemed short and
> > chatty.
> >
> > I was just wondering, if it's just them, or if it's my netiquette.
> >
> > I think you'd have a leg to stand on here if you didn't start
> > cursing at anyone who got on your wrong side. It wasn't really an
> > issue until you threw that
> > up. Granted you did take your cursing off list finally, but you
> > still continued (and as of about 2 hours ago) continue to post
> > trash like you did in response
> > to Alix's message. If you want to argue something, by all means
> > argue. But there's no need to resort to comments like you've made.
> 

Speaking of netiquette, Tyler you're messing  (with ?) your replies a lot. You 
actually answer with the same indent level than the poster.
In some thread with a lot of replies, it makes it impossible to see who's 
writing what.
Only your (long, very long) signature is at the correct level.


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


Re: For Counter Variable

2012-09-25 Thread wxjmfauth
I wrote my first program on a PDP-8. I discovered Python
at release 1.5.?

Now years later... I find Python more and more unusable.

As an exemple related to this topic, which summarizes a
little bit the situation. I just opened my interactive
interpreter and produced this:

>>> for i in range(len(s)-1, -1,-1):
... '{} {}'.format(i, s[i])
... 
'2 c'
'1 b'
'0 a'

I did it so many times with a reverse/enumerate combination,
I'm unable to do it again, I simply do not remember!


One another really annoying aspect of Python, illustrated
in my previous code: ''.format() .
Was it not supposed to be *the* new formating scheme?

I'm toying more and more with the go language. I really
appreciate and rediscover the strictness I learned with
Pascal.

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


Re: python file API

2012-09-25 Thread Ian Kelly
On Mon, Sep 24, 2012 at 11:32 PM, Thomas Rachel

wrote:
> Am 25.09.2012 00:37 schrieb Ian Kelly:
>> Since ints are immutable, the language specifies that it should be the
>> equivalent of "file.pos = file.pos - 100", so it should set the file
>> pointer to 68 bytes before EOF.
>
>
> But this is not a "real int", it has a special use. So I don't think it is
> absolutely required to behave like an int.

The point of the proposal was to simplify the API.  With that in mind,
if it's supposed to look like an int, then it should *be* an int.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-25 Thread Alain Ketterlin
Jayden  writes:

> # Begin
> a = 1
>
> def f():
> print a
>
> def g():
> a = 20
> f()
>
> g()
> #End
>
> I think the results should be 20, but it is 1. Would you please tell me why?

When python looks at g(), it sees that a variable a is assigned to, and
decides it is a local variable. When it looks at f(), it sees a use of a
but no assignment, so it decides it is a global variable and fetches the
value from the outer scope.

If you change f() to:

def f():
print a
a = 30

you change a into a local variable (and get another error).

If you want to change the binding of a in g(), you can declare it
global:

def g():
global a
a = 20
f()

Very tricky, actually.

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


Re: For Counter Variable

2012-09-25 Thread Mark Lawrence

On 25/09/2012 10:32, [email protected] wrote:

I wrote my first program on a PDP-8. I discovered Python
at release 1.5.?

Now years later... I find Python more and more unusable.


Dementia is a growing problem for us older people :)



As an exemple related to this topic, which summarizes a
little bit the situation. I just opened my interactive
interpreter and produced this:


for i in range(len(s)-1, -1,-1):

... '{} {}'.format(i, s[i])
...
'2 c'
'1 b'
'0 a'

I did it so many times with a reverse/enumerate combination,
I'm unable to do it again, I simply do not remember!


Based on things I've read as I've never used it myself try using Perl as 
that should simplify things for you.





One another really annoying aspect of Python, illustrated
in my previous code: ''.format() .
Was it not supposed to be *the* new formating scheme?


That might have been the original intention but it's not going to take 
over the world as there's too much legacy code using the C style % 
formatters.  IIRC isn't there also something about string templates???




I'm toying more and more with the go language. I really
appreciate and rediscover the strictness I learned with
Pascal.


So go and use go as nobody here is stopping you.



jmf



--
Cheers.

Mark Lawrence.

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


Re: For Counter Variable

2012-09-25 Thread Chris Rebert
On Tue, Sep 25, 2012 at 2:46 AM, Mark Lawrence  wrote:
> On 25/09/2012 10:32, [email protected] wrote:
>>
>> I wrote my first program on a PDP-8. I discovered Python
>> at release 1.5.?
>>
>> Now years later... I find Python more and more unusable.

>> I'm toying more and more with the go language. I really
>> appreciate and rediscover the strictness I learned with
>> Pascal.
>
> So go and use go as nobody here is stopping you.

Well, the PSU might, except they emphatically do not exist...

Cheers,
Chris
--
PEP-401 compliant
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-25 Thread Oscar Benjamin
On Sep 25, 2012 9:28 AM, "Dennis Lee Bieber"  wrote:
>
> On Tue, 25 Sep 2012 08:22:05 +0200, Ulrich Eckhardt
>  declaimed the following in
> gmane.comp.python.general:
>
> > Am 24.09.2012 23:49, schrieb Dave Angel:
> > > And what approach would you use for positioning relative to
> > > end-of-file?  That's currently done with an optional second
> >  > parameter to seek() method.
> >
> > Negative indices.
> >
>
> Which still doesn't handle the third seek mode -- relative to
> current position.

f.pos += delta

That's the only part of the proposal that I really think is an improvement
over the current method:

f.seek(delta, 1)

I actually had to google the whence code for relative seeking which I
wouldn't need to do if it were more descriptive.

But then I never do relative seeking. I'm pretty sure my programs have
always either read the whole file in order with no seeking or used random
access with absolute seeking.

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


Re: PHP vs. Python

2012-09-25 Thread andrea crotti
2012/9/25  :
> On Thursday, 23 December 2004 03:33:36 UTC+5:30, (unknown)  wrote:
>> Anyone know which is faster?  I'm a PHP programmer but considering
>> getting into Python ... did searches on Google but didn't turn much up
>> on this.
>>
>> Thanks!
>> Stephen
>
>
> Here some helpful gudance.
>
> http://hentenaar.com/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html
> --
> http://mail.python.org/mailman/listinfo/python-list


Quite ancient versions of everything, would be interesting to see if
things are different now..

Anyway you can switch to Python happily, it might not be faster but
99% of the times that's not an issue..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-25 Thread Mark Lawrence

On 25/09/2012 10:53, Chris Rebert wrote:

[snip]



Well, the PSU might, except they emphatically do not exist...


I know that they exist but if I admit to it I'd have to shoot myself. 
If I can get the bra off of the debutante that is.




Cheers,
Chris
--
PEP-401 compliant



--
Cheers.

Mark Lawrence.

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


Re: PHP vs. Python

2012-09-25 Thread Tejas
How to configure python in apache2 ?

So my html embedded code will works.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 08:27, Mark Lawrence  wrote:

> On 25/09/2012 03:32, Mark Adam wrote:
>
>> On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin
>>  wrote:
>>
>>> try:
>>>  f.pos = 256
>>> except IOError:
>>>  print('Unseekable file')
>>
>>
> Something along these lines http://docs.python.org/dev/**
> whatsnew/3.3.html#pep-3151-**reworking-the-os-and-io-**exception-hierarchy?


I just tried to find out what error would be raised by seeking on a file
that doesn't support seeking and II think it's just OSError in the reworked
hierarchy. The error in Python 2.7 is

Traceback (most recent call last):
  File "tmp.py", line 2, in 
sys.stdin.seek(5)
IOError: [Errno 29] Illegal seek

This corresponds to ESPIPE from errno.h which isn't referred to anywhere in
pip 3151:
http://www.python.org/dev/peps/pep-3151/

So I guess it would still need to be

try:
f.pos = 256
except OSError as e:
if e.errno != 29:
raise
print('Unseekable file')

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


Re: PHP vs. Python

2012-09-25 Thread Mark Lawrence

On 25/09/2012 11:22, Tejas wrote:

How to configure python in apache2 ?

So my html embedded code will works.





Please follow the instructions that you'll find by searching the web.

--
Cheers.

Mark Lawrence.

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


Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Tim Chase
On 09/24/12 23:41, Dennis Lee Bieber wrote:
> On Mon, 24 Sep 2012 14:59:47 -0700 (PDT), MrsEntity
>  declaimed the following in
> gmane.comp.python.general:
> 
>> Hi all,
>>
>> I'm working on some code that parses a 500kb, 2M line file line by line and 
>> saves, per line, some derived strings
> 
>   Pardon? A 2million line file will contain, at the minimum 2million
> line-end characters. That four times 500kB just in the line-ends,
> ignoring any data.

As corrected later in the thread, MrsEntity writes

"""
I have, in fact, this very afternoon, invented a means of writing a
carriage return character using only 2 bits of information. I am
prepared to sell licenses to this revolutionary technology for the
low price of $29.95 plus tax.

Sorry, that should've been a 500Mb, 2M line file.
"""

If only other unnamed persons on the list were so gracious rather
than turning the flame-dial to 11.

I hope that when people come to the list, *this* is what they see,
laugh, and want to participate.

Although, MrsEntity could be zombie David A. Huffman, whose encoding
scheme actually *can* store 2M lines in 500kb :-)

-tkc



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


Re: python file API

2012-09-25 Thread Mark Lawrence

On 25/09/2012 11:38, Oscar Benjamin wrote:

On 25 September 2012 08:27, Mark Lawrence  wrote:


On 25/09/2012 03:32, Mark Adam wrote:


On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin
 wrote:


try:
  f.pos = 256
except IOError:
  print('Unseekable file')




Something along these lines http://docs.python.org/dev/**
whatsnew/3.3.html#pep-3151-**reworking-the-os-and-io-**exception-hierarchy?



I just tried to find out what error would be raised by seeking on a file
that doesn't support seeking and II think it's just OSError in the reworked
hierarchy. The error in Python 2.7 is

Traceback (most recent call last):
   File "tmp.py", line 2, in 
 sys.stdin.seek(5)
IOError: [Errno 29] Illegal seek

This corresponds to ESPIPE from errno.h which isn't referred to anywhere in
pip 3151:
http://www.python.org/dev/peps/pep-3151/

So I guess it would still need to be

try:
 f.pos = 256
except OSError as e:
 if e.errno != 29:
 raise
 print('Unseekable file')

Oscar





The thing I was thinking of is actually in the thread "syntax to 
continue into the next subsequent except block" over on Python ideas.


--
Cheers.

Mark Lawrence.

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


Re: Article on the future of Python

2012-09-25 Thread Michael Harleman


That's a very interesting article.  It is encouraging to me, from reading many 
of the comments made, that I have chosen a good language to spend time learning 
despite the misgivings offered by the author.  I think Python does have a 
future in mobile markets as it is being used by some today according to one 
comment, and I can also see that apparently more development may need to be 
done, but I would think that would be true of any language.  What I like about 
Python among so many other things, is that it lends itself to be useful in 
almost any way I need it to.  Right now I am reading the Jython book, and 
realizing that Python can be wrapped around just about anything.  It truly is 
an amazing and versatile language.  Of course this is speaking as someone who 
has little experience at this point.  Thank you for sharing.  I'll be keeping 
this article bookmarked for future comparison.



Michael Harleman



>
> From: Mark Lawrence 
>To: [email protected] 
>Sent: Tuesday, September 25, 2012 4:15 AM
>Subject: Article on the future of Python
> 
>Hi all,
>
>I though this might be of interest.
>
>http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python
>
>-- Cheers.
>
>Mark Lawrence.
>
>-- http://mail.python.org/mailman/listinfo/python-list
>
>
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Fastest web framework

2012-09-25 Thread Andriy Kornatskyy

The post has been updated with two more frameworks (per community 
request): tornado and web2py.

Comments or suggestions are welcome.

Thanks.

Andriy Kornatskyy



> From: [email protected]
> To: [email protected]
> Subject: Fastest web framework
> Date: Sun, 23 Sep 2012 12:19:16 +0300
>
>
> I have run recently a benchmark of a trivial 'hello world' application for 
> various python web frameworks (bottle, django, flask, pyramid, web.py, 
> wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find 
> it interesting:
>
> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html
>
> Comments or suggestions are welcome.
>
> Thanks.
>
> Andriy Kornatskyy
>
> --
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-25 Thread Tim Chase
On 09/25/12 00:53, Thomas Rachel wrote:
> Am 25.09.2012 01:39 schrieb Dwight Hutto:
>> You don't always know all the built-ins, so the builtin is
>> simpler, but knowing how to code it yourself is the priority of
>> learning to code in a higher level language, which should be
>> simpler to the user of python.
> 
> When learning Python, it often happend me to re-inven the wheel.
> But as soon as I saw the presence of something I re-wrote, I
> skipped my re-written version and used the built-in.

As a beginning Pythonista, I found myself doing the same thing.  I
implemented my own CSV parsing until I discovered how easy it was to
do with the built-in library.  I implemented my own option-parsing
until I found optparse/argparse.  I implemented config-files until I
found ConfigFile.

Coming from C where just about *nothing* is in the stdlib and Java &
PHP where only some core functionalities are in the stdlib, to
Python where just the list of modules in the stdlib is humongous, I
have to make http://docs.python.org/library/ my first stop before I
try implementing anything I think might have even a remote
possibility of being there.

-tkc



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


RE: Fastest web framework

2012-09-25 Thread Andriy Kornatskyy

Alec

While performing benchmark for web2py I noticed a memory leak. It constantly 
grows and never release it...

Thanks.

Andriy Kornatskyy


> Date: Mon, 24 Sep 2012 17:36:25 +1000 
> Subject: Re: Fastest web framework 
> From: [email protected] 
> To: [email protected] 
> CC: [email protected] 
> 
> Can you throw in web2py? 
> 
> Thanks 
> 
> On Sun, Sep 23, 2012 at 7:19 PM, Andriy Kornatskyy 
> mailto:[email protected]>> wrote: 
> 
> I have run recently a benchmark of a trivial 'hello world' application 
> for various python web frameworks (bottle, django, flask, pyramid, 
> web.py, wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... 
> you might find it interesting: 
> 
> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html 
> 
> Comments or suggestions are welcome. 
> 
> Thanks. 
> 
> Andriy Kornatskyy 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list 
> 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Dave Angel
On 09/25/2012 12:21 AM, Junkshops wrote:
>> Just curious;  which is it, two million lines, or half a million bytes?

> 
> Sorry, that should've been a 500Mb, 2M line file.
> 
>> which machine is 2gb, the Windows machine, or the VM?
> VM. Winders is 4gb.
> 
>> ...but I would point out that just because
>> you free up the memory from the Python doesn't mean it gets released
>> back to the system.  The C runtime manages its own heap, and is pretty
>> persistent about hanging onto memory once obtained.  It's not normally a
>> problem, since most small blocks are reused.  But it can get
>> fragmented.  And i have no idea how well Virtual Box maps the Linux
>> memory map into the Windows one.
> Right, I understand that - but what's confusing me is that, given the
> memory use is (I assume) monotonically increasing, the code should never
> use more than what's reported by heapy once all the data is loaded into
> memory, given that memory released by the code to the Python runtime is
> reused. To the best of my ability to tell I'm not storing anything I
> shouldn't, so the only thing I can think of is that all the object
> creation and destruction, for some reason, it preventing reuse of
> memory. I'm at a bit of a loss regarding what to try next.

I'm not familiar with heapy, but perhaps it's missing something there.
I'm a bit surprised you aren't beyond the 2gb limit, just with the
structures you describe for the file.  You do realize that each object
has quite a few bytes of overhead, so it's not surprising to use several
times the size of a file, to store the file in an organized way.  I also
wonder if heapy has been written to take into account the larger size of
pointers in a 64bit build.

Perhaps one way to save space would be to use a long to store those md5
values.  You'd have to measure it, but I suspect it'd help (at the cost
of lots of extra hexlify-type calls).  Another thing is to make sure
that the md5 object used in your two maps is the same object, and not
just one with the same value.


-- 

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


Re: python file API

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 11:51, Mark Lawrence  wrote:

> On 25/09/2012 11:38, Oscar Benjamin wrote:
>
>> On 25 September 2012 08:27, Mark Lawrence 
>> wrote:
>>
>>  On 25/09/2012 03:32, Mark Adam wrote:
>>>
>>>  On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin
  wrote:

  try:
>   f.pos = 256
> except IOError:
>   print('Unseekable file')
>


  Something along these lines http://docs.python.org/dev/**
>>> whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-
>>> exception-hierarchy>> 3.3.html#pep-3151-reworking-**the-os-and-io-exception-**hierarchy
>>> >?
>>>
>>
>>
>> I just tried to find out what error would be raised by seeking on a file
>> that doesn't support seeking and II think it's just OSError in the
>> reworked
>> hierarchy. The error in Python 2.7 is
>>
>> Traceback (most recent call last):
>>File "tmp.py", line 2, in 
>>  sys.stdin.seek(5)
>> IOError: [Errno 29] Illegal seek
>>
>> This corresponds to ESPIPE from errno.h which isn't referred to anywhere
>> in
>> pip 3151:
>> http://www.python.org/dev/**peps/pep-3151/
>>
>> So I guess it would still need to be
>>
>> try:
>>  f.pos = 256
>> except OSError as e:
>>  if e.errno != 29:
>>  raise
>>  print('Unseekable file')
>>
>> Oscar
>>
>>
>>
>>
> The thing I was thinking of is actually in the thread "syntax to continue
> into the next subsequent except block" over on Python ideas.


This?

try:
 f.pos = 256
except OSError as e if e.errno == 29:
 print('Unseekable file')

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


Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Mark Lawrence

On 25/09/2012 11:51, Tim Chase wrote:
[snip]


If only other unnamed persons on the list were so gracious rather
than turning the flame-dial to 11.



Oh heck what have I said this time?



-tkc


--
Cheers.

Mark Lawrence.

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


Re: For Counter Variable

2012-09-25 Thread Mark Lawrence

On 25/09/2012 11:57, Tim Chase wrote:

[snip]



Coming from C where just about *nothing* is in the stdlib and Java &
PHP where only some core functionalities are in the stdlib, to
Python where just the list of modules in the stdlib is humongous, I
have to make http://docs.python.org/library/ my first stop before I
try implementing anything I think might have even a remote
possibility of being there.

-tkc


I find the above paragraph amusing given the recent discussion about the 
Java singletonMap, i.e. it's someone that is rarely if ever needed but 
core functionalities are missing, how strange.


I think the next port of call after the standard library should be pypi 
followed by the search engine, possibly targetted at sites like github, 
followed by a question here.  I'm not certain about the next step, help 
please.


--
Cheers.

Mark Lawrence.

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


Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected'

2012-09-25 Thread Robison Santos
Hello guys,

I'm having a very serious problem with my python3 environment and I'm
completely lost about the problem.
In my server I run two python apps (custom apps) during system start time,
and sometime when the apps are starting a corefile is generated for one one
them (not always the same) and the following error is reported:

"Fatal Python error: Py_Initialize: can't initialize sys standard streams
EOFError: EOF read where not expected"

Does anyone knows more about this problem and how can I fix it?

Looking on the internet, I found issues related to the first line
"Py_Initialize: can't initialize sys standard streams"  and issues for the
second line "EOF read where not expected" but none correlating both
problems.

Thanks a lot.

PS.: I'm not part of this list, so a direct reply to my personal email
would be great.

-- 
Robison W R Santos
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-25 Thread Thomas Rachel

Am 25.09.2012 10:13 schrieb Dennis Lee Bieber:

Or some bit setting registers, like on ATxmega: OUT = 0x10 sets bit 7
and clears all others, OUTSET = 0x10 only sets bit 7, OUTTGL = 0x10
toggles it and OUTCLR = 0x10 clears it.


Umpfzg. s/bit 7/bit 4/.


I don't think I'd want to work with any device where 0x10 (0001
binary) modifies bit SEVEN. 0x40, OTOH, would fit my mental impression
of bit 7.


Of course. My fault.

It can as well be a bit mask, with OUTTGL = 0x11 toggling bit 4 and bit 
0. Very handy sometimes.



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


Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 00:58, Junkshops  wrote:

> Hi Tim, thanks for the response.
>
>
>  - check how you're reading the data:  are you iterating over
>>the lines a row at a time, or are you using
>>.read()/.readlines() to pull in the whole file and then
>>operate on that?
>>
> I'm using enumerate() on an iterable input (which in this case is the
> filehandle).
>
>
>  - check how you're storing them:  are you holding onto more
>>than you think you are?
>>
> I've used ipython to look through my data structures (without going into
> ungainly detail, 2 dicts with X numbers of key/value pairs, where X =
> number of lines in the file), and everything seems to be working correctly.
> Like I say, heapy output looks reasonable - I don't see anything surprising
> there. In one dict I'm storing a id string (the first token in each line of
> the file) with values as (again, without going into massive detail) the md5
> of the contents of the line. The second dict has the md5 as the key and an
> object with __slots__ set that stores the line number of the file and the
> type of object that line represents.


Can you give an example of how these data structures look after reading
only the first 5 lines?

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


Re: gracious responses (was: Memory usage per top 10x usage per heapy)

2012-09-25 Thread Tim Chase
On 09/25/12 06:10, Mark Lawrence wrote:
> On 25/09/2012 11:51, Tim Chase wrote:
>> If only other unnamed persons on the list were so gracious rather
>> than turning the flame-dial to 11.
>>
> 
> Oh heck what have I said this time?

You'd *like* to take credit?  ;-)

Nah, not you or any of the regulars here.  The comment was regarding
the flame-fest that's been running in some parallel threads over the
last ~12hr or so.  Mostly instigated by one person with a
particularly quick trigger, vitriolic tongue, and a disregard for
pythonic code.

-tkc


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


Re: gracious responses

2012-09-25 Thread Mark Lawrence

On 25/09/2012 12:40, Tim Chase wrote:

On 09/25/12 06:10, Mark Lawrence wrote:

On 25/09/2012 11:51, Tim Chase wrote:

If only other unnamed persons on the list were so gracious rather
than turning the flame-dial to 11.



Oh heck what have I said this time?


You'd *like* to take credit?  ;-)

Nah, not you or any of the regulars here.  The comment was regarding
the flame-fest that's been running in some parallel threads over the
last ~12hr or so.  Mostly instigated by one person with a
particularly quick trigger, vitriolic tongue, and a disregard for
pythonic code.

-tkc




Well thank goodness for that.  Of course the person to whom you've 
alluded has been defended over on the tutor mailing list, seriously, and 
as I've said elsewhere after referring to my family as pigs!!!


--
Cheers.

Mark Lawrence.

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


RE: Fastest template engine

2012-09-25 Thread Andriy Kornatskyy

The post has been updated due to comment from Makoto Kuwata (author of tenjin) 
related to use of optimized version of HTML escape in tenjin templates.

I believe Mako and Jinja2 both are using MarkupSafe which serves exactly for 
that purpose there.

The test assert the output is unicode.

http://mindref.blogspot.com/2012/07/python-fastest-template.html

Thanks.

Andriy



> From: [email protected]
> To: [email protected]
> Subject: Fastest template engine
> Date: Sun, 23 Sep 2012 12:24:36 +0300
>
>
> I have run recently a benchmark of a trivial 'big table' example for various 
> python template engines (jinja2, mako, tenjin, tornado and wheezy.template) 
> run on cpython2.7 and pypy1.9.. you might find it interesting:
>
> http://mindref.blogspot.com/2012/07/python-fastest-template.html
>
> Comments or suggestions are welcome.
>
> Thanks.
>
> Andriy Kornatskyy
> --
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-25 Thread alex23
On Sep 25, 6:25 pm, Gelonida N  wrote:
> So it seems to be safe to use either Christoph' binary PIL distribution
> or to use Pillow.
>
> The fact, that pillow is accessable via PyPi / easy_install / PIP pushes
> me slightly towards pillow.


> I assume it's best to uninstall PIL before installing pillow.

I would expect you'd be fine. Being a different package, it's a
different namespace, so they shouldn't conflict.

> On a Linux machine:
> What would happen in a virtualenv with sitepackages (amonst them PIL
> installed and a pillow installed ontop of it?
> I don't think I can uninstall PIL, as many distro packages depend on it.
> I don't want to create a virtualenv without site packages, as I have
> many dependencies and some of them are a little tricky to compile.

Again, you should be fine, as it's in a separate namespace. You
definitely don't want to mess with PIL if you have other dependencies.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gracious responses (was: Memory usage per top 10x usage per heapy)

2012-09-25 Thread alex23
On Sep 25, 9:39 pm, Tim Chase  wrote:
> Mostly instigated by one person with a
> particularly quick trigger, vitriolic tongue, and a disregard for
> pythonic code.

I'm sorry. I'll get me coat.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-25 Thread alex23
On Sep 25, 3:30 pm, Dwight Hutto  wrote:
> You'd have to read the other posts. And remember that some of these
> names are A.K.A.'s, they ask respond, and befriend another name
> through another proxy.

You've actively accused me of this several times. If you have evidence
that there's sockpuppeting, please provide it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected'

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 12:32, Robison Santos  wrote:

> Hello guys,
>
> I'm having a very serious problem with my python3 environment and I'm
> completely lost about the problem.
> In my server I run two python apps (custom apps) during system start time,
> and sometime when the apps are starting a corefile is generated for one one
> them (not always the same) and the following error is reported:
>
> "Fatal Python error: Py_Initialize: can't initialize sys standard streams
> EOFError: EOF read where not expected"
>

What  OS etc. are you using and how are you starting the apps?

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


Re: gracious responses

2012-09-25 Thread Mark Lawrence

On 25/09/2012 13:44, alex23 wrote:

On Sep 25, 9:39 pm, Tim Chase  wrote:

Mostly instigated by one person with a
particularly quick trigger, vitriolic tongue, and a disregard for
pythonic code.


I'm sorry. I'll get me coat.



Oi, back of the queue if you don't mind :)

--
Cheers.

Mark Lawrence.

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


Re: which a is used?

2012-09-25 Thread Colin J. Williams

On 24/09/2012 10:14 PM, alex23 wrote:

On Sep 25, 11:13 am, Dwight Hutto  wrote:

bitch


I honestly could not care less what you think about me, but don't use
that term. This isn't a boys' club and we don't need your hurt ego
driving people away from here.


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


RE: Fastest web framework

2012-09-25 Thread Andriy Kornatskyy

Tarek,

With all respect, running benchmark on something that has sleeps, etc is pretty 
far from real world use case. So I went a little bit different way.

Here is a live demo (a semi real world web application) that comes with 
wheezy.web framework as a template:

http://wheezy.pythonanywhere.com/

I have implemented it in a way that it uses one web framework (wheezy.web) and 
various template engines (jinja2, mako, tenjin, wheezy.template and 
wheezy.template with preprocessor)... Please see the following post under `Real 
World Example` section:

http://mindref.blogspot.com/2012/07/python-fastest-template.html

Source code here:

https://bitbucket.org/akorn/wheezy.web/src/tip/demos/template

The real world example shows the difference between template engines 
implementing the same things. The same applies to web frameworks (more or less 
depending on your choice).

Thanks.

Andriy



> Date: Mon, 24 Sep 2012 13:50:31 +0200
> From: [email protected]
> To: [email protected]
> Subject: Re: Fastest web framework
>
> On 9/23/12 11:19 AM, Andriy Kornatskyy wrote:
> > I have run recently a benchmark of a trivial 'hello world' application for 
> > various python web frameworks (bottle, django, flask, pyramid, web.py, 
> > wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might 
> > find it interesting:
> >
> > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html
> >
> > Comments or suggestions are welcome.
> >
> > Thanks.
> >
> > Andriy Kornatskyy
> >
> I would try this with a web app that does more than 'Hello World'
>
> You may argue that you're just trying the server stack, but that's not
> realistic because you don't really measure how the server behaves with a
> real app.
>
> Have a look at
> https://github.com/mozilla-services/chaussette/blob/master/chaussette/util.py#L188
>
> (setup_bench and teardow_bench have to be run on startup and tear down
> of the server)
>
> I would be curious to see how things goes then
>
> Cheers
> Tarek
> --
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article on the future of Python

2012-09-25 Thread Kevin Walzer

On 9/25/12 4:15 AM, Mark Lawrence wrote:

Hi all,

I though this might be of interest.

http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python



Interesting article, but the comments of those who say "the only 
language I need to know is Python" strike me as a bit limited. If this 
is the case, then Python can never be moved forward, because it is 
written in C.


I program in Python, C, Objective C, JavaScript, Tcl, AppleScript, and 
I'm learning Perl. Python could *not* handle all the domains I target in 
my projects. For instance: if I want to access Mac-native functionality 
via Tkinter that isn't currently available in the library, I have to 
drill down into C or Objective-C, write a wrapper that hooks in to the 
primitives via Tcl's C API, then possibly write some additional Tcl code 
to provide a cleaner interface, *then* write some kind of Python wrapper 
that I can access in my Tkinter app.


I can understand loving the language and wanting to work just in the 
language, but it's another thing entirely to call Python the One 
Language to Rule Them All. (That's C, because all other languages are 
implemented in it. :-) )


--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


data attributes override method attributes?

2012-09-25 Thread Jayden
Dear All,

In the Python Tutorial, Section 9.4, it is said that

"Data attributes override method attributes with the same name."

But in my testing as follows:

#Begin
class A:
i = 10
def i():
print 'i'

A.i
   
#End

I think A.i should be the number 10 but it is the method. There must be 
something I misunderstand. Would you please tell me why?

Thanks,

Jayden


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


Re: Article on the future of Python

2012-09-25 Thread Roy Smith
In article ,
 Kevin Walzer  wrote:

> the comments of those who say "the only 
> language I need to know is Python" strike me as a bit limited.

I have been convinced that "X is the only language I need to know", for 
many different values of X over the years.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: data attributes override method attributes?

2012-09-25 Thread alex23
On Sep 25, 11:41 pm, Jayden  wrote:
> Dear All,
>
> In the Python Tutorial, Section 9.4, it is said that
>
> "Data attributes override method attributes with the same name."
>
> But in my testing as follows:
>
> #Begin
> class A:
>         i = 10
>         def i():
>                 print 'i'
>
> A.i
>    
> #End
>
> I think A.i should be the number 10 but it is the method. There must be 
> something I misunderstand. Would you please tell me why?

What the tutorial is referring to is this, I think:

class A(object):
def i(self):
print 'i'

>>> a = A()
>>> a.i = 10
>>> a.i
10

That is, you can create a data attribute on an object even if a method
attribute of the same name exists.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Article on the future of Python

2012-09-25 Thread Martin P. Hellwig
On Tuesday, 25 September 2012 09:14:27 UTC+1, Mark Lawrence  wrote:
> Hi all,
> 
> I though this might be of interest.
> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python
> -- 
> 
> Cheers.
> Mark Lawrence.

I glanced over the article but it seems to me another 'I am afraid this is not 
the silver bullet I wanted it to be' article without actually going into the 
need of a silver bullet or whether the concept of a silver bullet is sound at 
all.

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


Re: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected'

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 14:56, Robison Santos  wrote:

> I'm using python3.2.1
> on  Enterprise Linux Server release 5.3 (Carthage).
>
> I'm starting my apps calling python3 file.py 
>
> I have a script that runs on system startup executing my python scripts.
>

What happens if you just run the scripts from the shell after starting up?

What arrangement does the startup script provide for the stdio streams?

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


Re: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected'

2012-09-25 Thread Robison Santos
I'm using python3.2.1
on  Enterprise Linux Server release 5.3 (Carthage).

I'm starting my apps calling python3 file.py 

I have a script that runs on system startup executing my python scripts.

Any other info you need?

Thanks so far,

Robison

On Tue, Sep 25, 2012 at 9:49 AM, Oscar Benjamin
wrote:

> On 25 September 2012 12:32, Robison Santos  wrote:
>
>> Hello guys,
>>
>> I'm having a very serious problem with my python3 environment and I'm
>> completely lost about the problem.
>> In my server I run two python apps (custom apps) during system start
>> time, and sometime when the apps are starting a corefile is generated for
>> one one them (not always the same) and the following error is reported:
>>
>> "Fatal Python error: Py_Initialize: can't initialize sys standard streams
>> EOFError: EOF read where not expected"
>>
>
> What  OS etc. are you using and how are you starting the apps?
>
> Oscar
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Stop feeding the trolls (Was: which a is used?)

2012-09-25 Thread D'Arcy Cain
On Tue, 25 Sep 2012 08:44:18 +0100
Mark Lawrence  wrote:
> On 25/09/2012 06:07, Thomas Rachel wrote:
> > Am 25.09.2012 04:37 schrieb Dwight Hutto:
[...usual nonsense]

> someone had the audacity to protect his stance.  I am sure that people 
> have seen enough of his behaviour in the last few hours to see the real 
> Dwight Hutto so I'll leave it at that.

Now if only people would stop feeding the troll, those of us who have
already *plonked* him can stop seeing his ramblings in the responses.

-- 
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.
IM: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 crashes with 'Py_Initialize: can't initialize sys standard streams' + 'EOFError: EOF read where not expected'

2012-09-25 Thread Robison Santos
This problem does not happen very often, but when it happen is only on
system startup, and I couldn't reproduce by starting by hand.
My startup script tries to initiate a lot of services in sequence (ruby,
java, C and python), but does not do anything with stdio streams, at least
not directly.

At first, I thought this could be related to this python issue:
http://bugs.python.org/issue13146
but this does not relate with "can't initialize sys standard streams" error.

I didn't have time, though, to update my python version and check this
won't happen again.


Robison

On Tue, Sep 25, 2012 at 10:59 AM, Oscar Benjamin  wrote:

> On 25 September 2012 14:56, Robison Santos  wrote:
>
>> I'm using python3.2.1
>> on  Enterprise Linux Server release 5.3 (Carthage).
>>
>> I'm starting my apps calling python3 file.py 
>>
>> I have a script that runs on system startup executing my python scripts.
>>
>
> What happens if you just run the scripts from the shell after starting up?
>
> What arrangement does the startup script provide for the stdio streams?
>
> Oscar
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-25 Thread Grant Edwards
On 2012-09-25, Dennis Lee Bieber  wrote:
> On Tue, 25 Sep 2012 08:22:05 +0200, Ulrich Eckhardt
> declaimed the following in
> gmane.comp.python.general:
>
>> Am 24.09.2012 23:49, schrieb Dave Angel:
>> > And what approach would you use for positioning relative to
>> > end-of-file?  That's currently done with an optional second
>>  > parameter to seek() method.
>> 
>> Negative indices.
>>
>
>   Which still doesn't handle the third seek mode -- relative to
> current position.

 fileobj.pos += 

-- 
Grant Edwards   grant.b.edwardsYow! Am I in GRADUATE
  at   SCHOOL yet?
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: data attributes override method attributes?

2012-09-25 Thread Peter Otten
Jayden wrote:

> In the Python Tutorial, Section 9.4, it is said that
> 
> "Data attributes override method attributes with the same name."

The tutorial is wrong here. That should be

"Instance attributes override class attributes with the same name."

As methods are usually defined in the class and data attributes are usually 
set in the instance it will look like data override method attributes. 
What the author had in mind:

>>> class A:
... def i(self): print "method"
... 
>>> 
>>> a = A()
>>> a.i()
method
>>> a.i = 42 # this could also happen in a method with self.i = 42
>>> a.i()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not callable
>>> a.i
42
   
> But in my testing as follows:
> 
> #Begin
> class A:
> i = 10
> def i():
> print 'i'
> 
> A.i
>
> #End

but

class A:
def i(self): print "i"
i = 42

print A().i # 42

If two objects are assigned to the same name the last assignment always 
wins.
 
> I think A.i should be the number 10 but it is the method. There must be 
something I misunderstand. Would you please tell me why?
 
No, you're right. Please file a bug report at http://bugs.python.org


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


Re: data attributes override method attributes?

2012-09-25 Thread alex23
On Sep 26, 12:08 am, Peter Otten <[email protected]> wrote:
> Jayden wrote:
> > In the Python Tutorial, Section 9.4, it is said that
>
> > "Data attributes override method attributes with the same name."
>
> The tutorial is wrong here. That should be
>
> "Instance attributes override class attributes with the same name."
>
> As methods are usually defined in the class and data attributes are usually
> set in the instance it will look like data override method attributes.

But you can assign attributes on the class, which has the same impact,
so the tutorial is correct.

> No, you're right. Please file a bug report athttp://bugs.python.org

Didn't you just demonstrate the behaviour you're now saying is a bug?

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


Re: For Counter Variable

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 11:16:40 +0100, Mark Lawrence wrote:

> On 25/09/2012 10:53, Chris Rebert wrote:
> 
> [snip]
> 
>> Well, the PSU might, except they emphatically do not exist...
> 
> I know that they exist 

You are delusional. The PSU certainly do not exist and it is a myth that 
they 


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


Re: data attributes override method attributes?

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 06:41:43 -0700, Jayden wrote:

> Dear All,
> 
> In the Python Tutorial, Section 9.4, it is said that
> 
> "Data attributes override method attributes with the same name."
> 
> But in my testing as follows:
> 
> #Begin
> class A:
>   i = 10
>   def i():
>   print 'i'
> 
> A.i
>
> #End
> 
> I think A.i should be the number 10 but it is the method. There must be
> something I misunderstand. Would you please tell me why?

When you create the class, two things happen: first you define a class-
level attribute i, then you define a method i. Since you can only have a 
single object with the same name in the same place, the method replaces 
the attribute.

In this case, classes and methods are irrelevant. It is exactly the same 
behaviour as this:

i = 10
i = 20
# i now equals 20, not 10


except that instead of 20, you use a function object:

i = 10
def i():
return "something"
# i is now a function object, not 10


What the manual refers to is the use of attributes on an instance:

py> class Test(object):
... def f(self):
... return "something"
...
py> t = Test()
py> t.f = 20
py> t.f
20

In this case, there is an attribute called "f" (a method) which lives in 
the class and is shared by all instances, and another attribute called 
"f" which lives in the instance t, is not shared, and has the value 20. 
This instance attribute masks the method with the same name. We can see 
that it is only hidden, not gone, by creating a new instance:

py> u = Test()
py> u.f
>



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


Re: Who's laughing at my responses, and who's not?

2012-09-25 Thread Ramchandra Apte
On Tuesday, 25 September 2012 10:40:02 UTC+5:30, Terry Reedy  wrote:
> On 9/25/2012 12:43 AM, Dwight Hutto wrote:
> 
> > It sounds pretentious, but over the past several days, I've been
> 
> > slammed on every post almost. All because of an argument over me not
> 
> > posting a little context in a conversation, that seemed short and
> 
> > chatty.
> 
> >
> 
> > I was just wondering, if it's just them, or if it's my netiquette.
> 
> 
> 
> A 1000 line post with a one line response is not polite. Context free 
> 
> posts are disconcerting, but easier to ignore. Keep at least one 
> 
> sentence of context and cut the potty mouth stuff.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

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


Re: For Counter Variable

2012-09-25 Thread Chris Angelico
On Wed, Sep 26, 2012 at 12:19 AM, Steven D'Aprano
 wrote:
> On Tue, 25 Sep 2012 11:16:40 +0100, Mark Lawrence wrote:
>
>> On 25/09/2012 10:53, Chris Rebert wrote:
>>
>> [snip]
>>
>>> Well, the PSU might, except they emphatically do not exist...
>>
>> I know that they exist
>
> You are delusional. The PSU certainly do not exist and it is a myth that
> they

Something got cut off. I wonder if Steven's computer's Power Supply
Unit just let off its magic smoke...

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


new-style class or old-style class?

2012-09-25 Thread Jayden
In learning Python, I found there are two types of classes? Which one are 
widely used in new Python code? Is the new-style much better than old-style? 
Thanks!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: data attributes override method attributes?

2012-09-25 Thread Peter Otten
alex23 wrote:

> On Sep 26, 12:08 am, Peter Otten <[email protected]> wrote:
>> Jayden wrote:
>> > In the Python Tutorial, Section 9.4, it is said that
>>
>> > "Data attributes override method attributes with the same name."
>>
>> The tutorial is wrong here. That should be
>>
>> "Instance attributes override class attributes with the same name."
>>
>> As methods are usually defined in the class and data attributes are
>> usually set in the instance it will look like data override method
>> attributes.
> 
> But you can assign attributes on the class, which has the same impact,
> so the tutorial is correct.
> 
>> No, you're right. Please file a bug report athttp://bugs.python.org
> 
> Didn't you just demonstrate the behaviour you're now saying is a bug?
> 

To me

"Data attributes override method attributes with the same name"

implies that data attributes take precedence over method attributes, not 
that they replace them only when there is an assignment of data after the 
method definition. 

With your interpretation (if I understand you correctly)

"Method attributes override data attributes with the same name"

is equally correct, and therefore I think it is misleading to focus on the 
type of the attributes at all. 

I would even consider replacing the whole paragraph

"""
Data attributes override method attributes with the same name; to avoid 
accidental name conflicts, which may cause hard-to-find bugs in large 
programs, it is wise to use some kind of convention that minimizes the 
chance of conflicts. Possible conventions include capitalizing method names, 
prefixing data attribute names with a small unique string (perhaps just an 
underscore), or using verbs for methods and nouns for data attributes.
"""
http://docs.python.org/dev/py3k/tutorial/classes.html

with something like

"Data attributes and method attributes share the same namespace. To avoid 
name conflicts consider using verbs for methods and nouns for data 
attributes"


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


Re: new-style class or old-style class?

2012-09-25 Thread Littlefield, Tyler

On 9/25/2012 8:44 AM, Jayden wrote:

In learning Python, I found there are two types of classes? Which one are 
widely used in new Python code? Is the new-style much better than old-style? 
Thanks!!



Perhaps this is useful:
http://docs.python.org/reference/datamodel.html
It's 3.3 I think.

--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.

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


Re: new-style class or old-style class?

2012-09-25 Thread Chris Angelico
On Wed, Sep 26, 2012 at 12:44 AM, Jayden  wrote:
> In learning Python, I found there are two types of classes? Which one are 
> widely used in new Python code? Is the new-style much better than old-style? 
> Thanks!!

Definitely go with new-style. In Python 3, old-style classes aren't
supported, and the syntax that would create an old-style class in
Python 2 will implicitly create a new-style class. (Explicitly
subclassing object still works in Py3, so you can happily use that
syntax for both.)

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


Re: data attributes override method attributes?

2012-09-25 Thread Chris Angelico
On Wed, Sep 26, 2012 at 12:54 AM, Peter Otten <[email protected]> wrote:
> To me
>
> "Data attributes override method attributes with the same name"
>
> implies that data attributes take precedence over method attributes, not
> that they replace them only when there is an assignment of data after the
> method definition.
>
> I would even consider replacing the whole paragraph
> with something like
>
> "Data attributes and method attributes share the same namespace. To avoid
> name conflicts consider using verbs for methods and nouns for data
> attributes"

Instance attributes override (shadow) class attributes. Since methods
tend to be on the class and data tends to be on the instance, the
original sentence does make some sense. The section is talking about
conventions, so it's not inherently wrong, but perhaps just needs a
comment about methods not usually being attached to the instance.

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


Re: How to limit CPU usage in Python

2012-09-25 Thread DPalao
On Jueves septiembre 20 2012 11:12:44 Rolando Cañer Roblejo escribió:
> Hi all,
> 
> Is it possible for me to put a limit in the amount of processor usage (%
> CPU) that my current python script is using? Is there any module useful
> for this task? I saw Resource module but I think it is not the module I
> am looking for. Some people recommend to use nice and cpulimit unix
> tools, but those are external to python and I prefer a python solution.
> I am working with Linux (Ubuntu 10.04).
> 
> Best regards.

Hola,
Sometimes a stupid solution like the following does the trick:

> import time
> for t in tasks:
> do_something(t)
> time.sleep(some_seconds)

where "some_seconds" is a number related to the typical time-scale of the 
tasks you are doing.

Hope it helps,

Regards


-- 
Miller's Slogan:
Lose a few, lose a few.

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


Re: data attributes override method attributes?

2012-09-25 Thread Ulrich Eckhardt

Am 25.09.2012 16:11, schrieb alex23:

On Sep 26, 12:08 am, Peter Otten <[email protected]> wrote:

Jayden wrote:

In the Python Tutorial, Section 9.4, it is said that



"Data attributes override method attributes with the same name."


The tutorial is wrong here. That should be

"Instance attributes override class attributes with the same name."

As methods are usually defined in the class and data attributes are usually
set in the instance it will look like data override method attributes.


But you can assign attributes on the class, which has the same impact,
so the tutorial is correct.


You can assign attributes of the class or the instance, and you can 
assign with functions or data (actually, both functions and data are 
objects, Python doesn't make a distinction there). The important thing 
is that lookup first looks in the instance (where data attributes are 
usually set) before looking in the class (where method attributes are 
usually set). Observing typical use and deriving a rule from this is 
misleading though.




No, you're right. Please file a bug report athttp://bugs.python.org


Didn't you just demonstrate the behaviour you're now saying is a bug?


I think he meant a bug in the tutorial, not in the implementation of Python.


Uli

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


Re: gracious responses

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 12:54:05 +0100, Mark Lawrence wrote:

> Well thank goodness for that.  Of course the person to whom you've
> alluded has been defended over on the tutor mailing list, seriously, and
> as I've said elsewhere after referring to my family as pigs!!!

Since pigs are at least as intelligent as dogs, and in their natural 
state nowhere near as filthy as the stereotype of the pig in a sty, that 
isn't as big an insult as it was intended.


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


Re: Article on the future of Python

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 09:26:19 -0400, Kevin Walzer wrote:

> On 9/25/12 4:15 AM, Mark Lawrence wrote:
>> Hi all,
>>
>> I though this might be of interest.
>>
>> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-
>> python
>>
>>
> Interesting article, but the comments of those who say "the only
> language I need to know is Python" strike me as a bit limited. If this
> is the case, then Python can never be moved forward, because it is
> written in C.

Incorrect. 

IronPython in C#. Jython is written in Java. CLPython is written in Lisp. 
Berp and HoPe are written in Haskell. Nuitka is written in C++. Skulpt is 
written in Javascript. Vyper is written in Ocaml. PyPy is written in 
RPython.

Some of those Python compilers are obsolete, unmaintained or 
experimental. Others are not. But either way, it is certainly not true 
that Python is written in C. One specific Python compiler happens to be 
written in C, that is all.


> I program in Python, C, Objective C, JavaScript, Tcl, AppleScript, and
> I'm learning Perl. Python could *not* handle all the domains I target in
> my projects. 

Unless you are writing code that operates on the bare metal (device 
drivers, operating system kernels) Python probably *could*, even if it 
doesn't *yet*. PyPy now allows you to write real-time video processing 
filters in pure Python:

http://morepypy.blogspot.com.au/2011/07/realtime-image-processing-in-python.html


And if performance was irrelevant, you could even write an operating 
system in Python. A really slow, painful operating system, but still an 
operating system.

Given a sufficiently smart compiler, and sufficiently powerful libraries, 
or sufficiently low expectations, pretty much any programming language 
can do anything any other language can do. Almost all of them are Turing 
complete.

But of course, in practice languages differ in their power and 
capabilities.


> For instance: if I want to access Mac-native functionality
> via Tkinter that isn't currently available in the library, 

That "isn't currently available" part is precisely what I'm talking 
about. Just because it's not available now doesn't mean it can't be made 
available.


> I can understand loving the language and wanting to work just in the
> language, but it's another thing entirely to call Python the One
> Language to Rule Them All. (That's C, because all other languages are
> implemented in it. :-) )

I see your smiley, but that is factually incorrect. Not all compilers or 
interpreters are written in C. Many languages are self-hosted, that is, 
they are written in themselves, using some clever bootstrapping 
techniques. C is neither the most powerful, the oldest, the best, or the 
most fundamental language around.


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


Re: python file API

2012-09-25 Thread Chris Angelico
On Wed, Sep 26, 2012 at 2:07 AM, Dennis Lee Bieber
 wrote:
> f.pos += delta
>
> would be a "seek.set" and with a naive driver might trigger a rewind to
> the start of the tape followed by a seek to the absolute position,
> whereas the seek from current location would only move the tape by the
> specified amount...

But a smart driver should always optimize the absolute seek to a
relative seek, unless there's a hard difference between them. After
all, the standard "read-ahead" technique is going to do an absolute
seek:

opaque_value = f.tell()
f.read(blah blah blah)
f.seek(opaque_value)

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


How to export a logging level?

2012-09-25 Thread Vincent Vande Vyvre
In my application I import a module and I want to set the same logging
level
as the main app to this module.

I've tried this code

main.py

import logging
logger = logging.getLogger(__name__)
lvl = logging.DEBUG
LOG_FORMAT = "%(asctime)-6s %(levelname)s: %(name)s - %(message)s"
logging.basicConfig(format=LOG_FORMAT, datefmt='%H:%M:%S', level=lvl)

from mymodule.myfile import MyClass

...
def load_myclass(self):
lvl = logger.getEffectiveLevel()
mc = MyClass(self, lvl)


myfile.py

import logging
logger = logging.getLogger(__name__)

class MyClass(object):
def __init__(self, main, lvl):
logger.setLevel(lvl)

If I set the level to logging.DEBUG I can see all infos from the main
but anything
from my module.

Thanks for your advice.
-- 
Vincent V.V.
Oqapy  . Qarte
 . PaQager 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style class or old-style class?

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote:

> In learning Python, I found there are two types of classes? Which one
> are widely used in new Python code? 

New-style classes.

> Is the new-style much better than old-style?

Yes.

Always use new-style classes, unless you have some specific reason for 
needing old-style ("classic") classes.

Advantages of new-style classes:

1) They are the future. In Python 3, all classes are "new-style" and 
classic classes are gone.

2) Multiple inheritance works correctly. Multiple inheritance for classic 
classes is buggy.

3) New-style classes support awesome features like super(), properties, 
descriptors, and __getattribute__. Old-style do not.

The main disadvantage is that automatic delegation is a pain to do 
correctly in new-style classes, but trivially simple in classic classes. 
Still, all things considered, it's a good trade.



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


Re: How to export a logging level?

2012-09-25 Thread Peter Otten
Vincent Vande Vyvre wrote:

> In my application I import a module and I want to set the same logging
> level as the main app to this module.

Isn't that the default? If you set the logging level with basicConfig() that 
level should be applied to all messages. 


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


Re: Article on the future of Python

2012-09-25 Thread Paul Rubin
Kevin Walzer  writes:
> language, but it's another thing entirely to call Python the One
> Language to Rule Them All. (That's C, because all other languages are
> implemented in it. :-) )

I got into a discussion about that in another newsgroup and noticed that
C seems to have been a 20th-century language that is still used for
maintaining old programs and in the embedded niche, but that very few
languages or compilers seem to have been newly implemented in C in the
current century.  The main counterexample I was able to find was LuaJIT.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Junkshops

I'm a bit surprised you aren't beyond the 2gb limit, just with the
structures you describe for the file.  You do realize that each object
has quite a few bytes of overhead, so it's not surprising to use several
times the size of a file, to store the file in an organized way.
I did some back of the envelope calcs which more or less agreed with 
heapy. The code stores 1 string, which is, on average, about 50 chars or 
so, and one MD5 hex string per line of code. There's about 40 bytes or 
so of overhead per string per sys.getsizeof(). I'm also storing an int 
(24b) and a <10 char string in an object with __slots__ set. Each 
object, per heapy (this is one area where I might be underestimating 
things) takes 64 bytes plus instance variable storage, so per line:


50 + 32 + 10 + 3 * 40 + 24 + 64 = 300 bytes per line * 2M lines = ~600MB 
plus some memory for the dicts, which is about what heapy is reporting 
(note I'm currently not actually running all 2M lines, I'm just running 
subsets for my tests).


Is there something I'm missing? Here's the heapy output after loading 
~300k lines:


Partition of a set of 1199849 objects. Total size = 89965376 bytes.
Index   Count   %   Size%   Cumulative  %   Kind
0   59  50  3839992043  3839992043  str
1   5   0   2516722428  6356714471  dict
2   28  25  1919987221  8276701692  0xa13330
3   299836  25  7196064 8   89963080100 int
4   4   0   11520   89964232100 
collections.defaultdict

Note that 3 of the dicts are empty. I assume that 0xa13330 is the 
address of the object. I'd actually expect to see 900k strings, but the 
<10 char string is always the same in this case so perhaps the runtime 
is using the same object...? At this point, top reports python as using 
1.1g of virt and 1.0g of res.



I also
wonder if heapy has been written to take into account the larger size of
pointers in a 64bit build.
That I don't know, but that would only explain, at most, a 2x increase 
in memory over the heapy report, wouldn't it? Not the ~10x I'm seeing.



Another thing is to make sure
that the md5 object used in your two maps is the same object, and not
just one with the same value.
That's certainly the way the code is written, and heapy seems to confirm 
that the strings aren't duplicated in memory.


Thanks for sticking with me on this,

MrsE

On 9/25/2012 4:06 AM, Dave Angel wrote:

On 09/25/2012 12:21 AM, Junkshops wrote:

Just curious;  which is it, two million lines, or half a million bytes?



Sorry, that should've been a 500Mb, 2M line file.


which machine is 2gb, the Windows machine, or the VM?

VM. Winders is 4gb.


...but I would point out that just because
you free up the memory from the Python doesn't mean it gets released
back to the system.  The C runtime manages its own heap, and is pretty
persistent about hanging onto memory once obtained.  It's not normally a
problem, since most small blocks are reused.  But it can get
fragmented.  And i have no idea how well Virtual Box maps the Linux
memory map into the Windows one.

Right, I understand that - but what's confusing me is that, given the
memory use is (I assume) monotonically increasing, the code should never
use more than what's reported by heapy once all the data is loaded into
memory, given that memory released by the code to the Python runtime is
reused. To the best of my ability to tell I'm not storing anything I
shouldn't, so the only thing I can think of is that all the object
creation and destruction, for some reason, it preventing reuse of
memory. I'm at a bit of a loss regarding what to try next.

I'm not familiar with heapy, but perhaps it's missing something there.
I'm a bit surprised you aren't beyond the 2gb limit, just with the
structures you describe for the file.  You do realize that each object
has quite a few bytes of overhead, so it's not surprising to use several
times the size of a file, to store the file in an organized way.  I also
wonder if heapy has been written to take into account the larger size of
pointers in a 64bit build.

Perhaps one way to save space would be to use a long to store those md5
values.  You'd have to measure it, but I suspect it'd help (at the cost
of lots of extra hexlify-type calls).  Another thing is to make sure
that the md5 object used in your two maps is the same object, and not
just one with the same value.


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


Re: How to export a logging level?

2012-09-25 Thread Vincent Vande Vyvre
Le 25/09/12 19:01, Peter Otten a écrit :
> Vincent Vande Vyvre wrote:
>
>> In my application I import a module and I want to set the same logging
>> level as the main app to this module.
> Isn't that the default? If you set the logging level with basicConfig() that 
> level should be applied to all messages. 
>
>
Not, only the messages from the main class and the others class that are
in the same module (folder) appears into the console.

Any message from the module imported.

-- 
Vincent V.V.
Oqapy  . Qarte
 . PaQager 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to export a logging level?

2012-09-25 Thread Jean-Michel Pichavant
- Original Message -
> In my application I import a module and I want to set the same
> logging
> level
> as the main app to this module.
> 
> I've tried this code
> 
> main.py
> 
> import logging
> logger = logging.getLogger(__name__)
> lvl = logging.DEBUG
> LOG_FORMAT = "%(asctime)-6s %(levelname)s: %(name)s - %(message)s"
> logging.basicConfig(format=LOG_FORMAT, datefmt='%H:%M:%S', level=lvl)
> 
> from mymodule.myfile import MyClass
> 
> ...
> def load_myclass(self):
> lvl = logger.getEffectiveLevel()
> mc = MyClass(self, lvl)
> 
> 
> myfile.py
> 
> import logging
> logger = logging.getLogger(__name__)
> 
> class MyClass(object):
> def __init__(self, main, lvl):
> logger.setLevel(lvl)
> 
> If I set the level to logging.DEBUG I can see all infos from the main
> but anything
> from my module.
> 
> Thanks for your advice.
> --
> Vincent V.V.
> Oqapy  . Qarte
>  . PaQager
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Life is actually simpler, one rule to remember: you don't configure your 
loggers, ever. You let this worthless task to the user (in your case the 
main.py file or however import your module).

In myfile.py, the only logging related lines are:

import logging
logger = logging.getLogger(__name_)

Then you just log. How the logs  are processed, at which level, for which 
formatter, you don't care. The root logger will take care of that. Keep your 
main.py as it is and it should work.

JM

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


Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Junkshops


Can you give an example of how these data structures look after 
reading only the first 5 lines?

Sure, here you go:

In [38]: mpef._ustore._store
Out[38]: defaultdict(, {'Measurement': 
{'8991c2dc67a49b909918477ee4efd767': 
, 
'7b38b429230f00fe4731e60419e92346': 
, 
'b53531471b261c44d52f651add647544': 
, 
'44ea6d949f7c8c8ac3bb4c0bf4943f82': 
, 
'0de96f928dc471b297f8a305e71ae3e1': 
}})


In [39]: 
mpef._ustore._store['Measurement']['b53531471b261c44d52f651add647544'].typeStr

Out[39]: 'Measurement'

In [40]: 
mpef._ustore._store['Measurement']['b53531471b261c44d52f651add647544'].lineNumber

Out[40]: 5

In [41]: mpef._ustore._idstore
Out[41]: defaultdict('micropheno.exchangeformat.KBaseID.IDStore'>, {'Measurement': 
})


In [43]: mpef._ustore._idstore['Measurement']._SIDstore
Out[43]: defaultdict( at 0x2ece7d0>, {'emailRemoved': 
defaultdict( at 0x2c4caa0>, {'microPhenoShew2011': 
defaultdict(, {0: {'MLR_124572462': 
'8991c2dc67a49b909918477ee4efd767', 'MLR_124572161': 
'7b38b429230f00fe4731e60419e92346', 'SMMLR_12551352': 
'b53531471b261c44d52f651add647544', 'SMMLR_12551051': 
'0de96f928dc471b297f8a305e71ae3e1', 'SMMLR_12550750': 
'44ea6d949f7c8c8ac3bb4c0bf4943f82'}})})})


-MrsE

On 9/25/2012 4:33 AM, Oscar Benjamin wrote:
On 25 September 2012 00:58, Junkshops > wrote:


Hi Tim, thanks for the response.


- check how you're reading the data:  are you iterating over
   the lines a row at a time, or are you using
   .read()/.readlines() to pull in the whole file and then
   operate on that?

I'm using enumerate() on an iterable input (which in this case is
the filehandle).


- check how you're storing them:  are you holding onto more
   than you think you are?

I've used ipython to look through my data structures (without
going into ungainly detail, 2 dicts with X numbers of key/value
pairs, where X = number of lines in the file), and everything
seems to be working correctly. Like I say, heapy output looks
reasonable - I don't see anything surprising there. In one dict
I'm storing a id string (the first token in each line of the file)
with values as (again, without going into massive detail) the md5
of the contents of the line. The second dict has the md5 as the
key and an object with __slots__ set that stores the line number
of the file and the type of object that line represents.


Can you give an example of how these data structures look after 
reading only the first 5 lines?


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


Re: How to export a logging level?

2012-09-25 Thread Vincent Vande Vyvre
Le 25/09/12 19:47, Jean-Michel Pichavant a écrit :
> - Original Message -
>> In my application I import a module and I want to set the same
>> logging
>> level
>> as the main app to this module.
>>
>> I've tried this code
>>
>> main.py
>>
>> import logging
>> logger = logging.getLogger(__name__)
>> lvl = logging.DEBUG
>> LOG_FORMAT = "%(asctime)-6s %(levelname)s: %(name)s - %(message)s"
>> logging.basicConfig(format=LOG_FORMAT, datefmt='%H:%M:%S', level=lvl)
>>
>> from mymodule.myfile import MyClass
>>
>> ...
>> def load_myclass(self):
>> lvl = logger.getEffectiveLevel()
>> mc = MyClass(self, lvl)
>>
>>
>> myfile.py
>>
>> import logging
>> logger = logging.getLogger(__name__)
>>
>> class MyClass(object):
>> def __init__(self, main, lvl):
>> logger.setLevel(lvl)
>>
>> If I set the level to logging.DEBUG I can see all infos from the main
>> but anything
>> from my module.
>>
>> Thanks for your advice.
>> --
>> Vincent V.V.
>> Oqapy  . Qarte
>>  . PaQager
>> 
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> Life is actually simpler, one rule to remember: you don't configure your 
> loggers, ever. You let this worthless task to the user (in your case the 
> main.py file or however import your module).
>
> In myfile.py, the only logging related lines are:
>
> import logging
> logger = logging.getLogger(__name_)
>
> Then you just log. How the logs  are processed, at which level, for which 
> formatter, you don't care. The root logger will take care of that. Keep your 
> main.py as it is and it should work.
>
> JM
>
>
Oops, my fault, I've forgotten a line "logger.setLevel(logging.WARNING)"
into my module.

Thanks
-- 
Vincent V.V.
Oqapy  . Qarte
 . PaQager 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Oscar Benjamin
On 25 September 2012 19:08, Junkshops  wrote:

>
>  Can you give an example of how these data structures look after reading
> only the first 5 lines?
>
> Sure, here you go:
>
> In [38]: mpef._ustore._store
> Out[38]: defaultdict(, {'Measurement':
> {'8991c2dc67a49b909918477ee4efd767':
> ,
> '7b38b429230f00fe4731e60419e92346':
> ,
> 'b53531471b261c44d52f651add647544':
> ,
> '44ea6d949f7c8c8ac3bb4c0bf4943f82':
> ,
> '0de96f928dc471b297f8a305e71ae3e1':
> }})
>

Have these exceptions been raised from somewhere before being stored? I
wonder if you're inadvertently keeping execution frames alive. There are
some problems in CPython with this that are related to storing exceptions.


>
> In [39]:
> mpef._ustore._store['Measurement']['b53531471b261c44d52f651add647544'].typeStr
> Out[39]: 'Measurement'
>

Seeing how long these hex strings are, I'm confident that you would save a
significant amount of memory by converting them to int.


>
> In [40]:
> mpef._ustore._store['Measurement']['b53531471b261c44d52f651add647544'].lineNumber
> Out[40]: 5
>
> In [41]: mpef._ustore._idstore
> Out[41]: defaultdict(,
> {'Measurement':  0x2f0f950>})
>
> In [43]: mpef._ustore._idstore['Measurement']._SIDstore
> Out[43]: defaultdict( at 0x2ece7d0>, {'emailRemoved':
> defaultdict( at 0x2c4caa0>, {'microPhenoShew2011':
> defaultdict(, {0: {'MLR_124572462':
> '8991c2dc67a49b909918477ee4efd767', 'MLR_124572161':
> '7b38b429230f00fe4731e60419e92346', 'SMMLR_12551352':
> 'b53531471b261c44d52f651add647544', 'SMMLR_12551051':
> '0de96f928dc471b297f8a305e71ae3e1', 'SMMLR_12550750':
> '44ea6d949f7c8c8ac3bb4c0bf4943f82'}})})})
>

Also I think lambda functions might be able to keep the frame alive. Are
they by any chance being created in a function that is called in a loop?

>>> def f():
... x = 4
... return lambda : x
...
>>> g = f()
>>> g()  # Accesses local variable from kept-alive frame
4
>>> x
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'x' is not defined

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


Re: Article on the future of Python

2012-09-25 Thread Grant Edwards
On 2012-09-25, Martin P. Hellwig  wrote:
> On Tuesday, 25 September 2012 09:14:27 UTC+1, Mark Lawrence  wrote:
>> Hi all,
>> 
>> I though this might be of interest.
>> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of-python

> I glanced over the article but it seems to me another 'I am afraid
> this is not the silver bullet I wanted it to be' article

Strange.  I didn't get that _at_all_ from the article.  

To me it was expressing concern about what happens when the range of
"niches" where Python is a good solution falls below a certain
critical mass -- will the "Python Community" start to stagnate because
it isn't attacting new developers in the quantity or diversity that it
used to...

-- 
Grant Edwards   grant.b.edwardsYow! Alright, you!!
  at   Imitate a WOUNDED SEAL
  gmail.compleading for a PARKING
   SPACE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style class or old-style class?

2012-09-25 Thread Mark Lawrence

On 25/09/2012 17:20, Steven D'Aprano wrote:

On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote:


In learning Python, I found there are two types of classes? Which one
are widely used in new Python code?


New-style classes.


Is the new-style much better than old-style?


Yes.

Always use new-style classes, unless you have some specific reason for
needing old-style ("classic") classes.

Advantages of new-style classes:

1) They are the future. In Python 3, all classes are "new-style" and
classic classes are gone.

2) Multiple inheritance works correctly. Multiple inheritance for classic
classes is buggy.

3) New-style classes support awesome features like super(), properties,
descriptors, and __getattribute__. Old-style do not.

The main disadvantage is that automatic delegation is a pain to do
correctly in new-style classes, but trivially simple in classic classes.
Still, all things considered, it's a good trade.





Thanks for this reminder, my port of the J word code to Python has just 
been simplified :)


--
Cheers.

Mark Lawrence.

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


Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Dave Angel
On 09/25/2012 01:39 PM, Junkshops wrote:

Procedural point:  I know you're trying to conform to the standard that
this mailing list uses, but you're off a little, and it's distracting.
It's also probably more work for you, and certainly for us.

You need an attribution in front of the quoted portions.  This next
section is by me, but you don't say so.  That's because you copy/pasted
it from elsewhere in the reply, and didn't copy the "... Dave Angel
wrote" part.

Much easier is to take the reply, and remove the parts you're not going
to respond to, putting your own comments in between the parts that are
left (as you're doing).  And generally, there's no need for anything
after your last remark, so you just delete up to your signature, if any.


>> I'm a bit surprised you aren't beyond the 2gb limit, just with the
>> structures you describe for the file.  You do realize that each object
>> has quite a few bytes of overhead, so it's not surprising to use several
>> times the size of a file, to store the file in an organized way.
> I did some back of the envelope calcs which more or less agreed with
> heapy. The code stores 1 string, which is, on average, about 50 chars or
> so, and one MD5 hex string per line of code. There's about 40 bytes or
> so of overhead per string per sys.getsizeof(). I'm also storing an int
> (24b) and a <10 char string in an object with __slots__ set. Each
> object, per heapy (this is one area where I might be underestimating
> things) takes 64 bytes plus instance variable storage, so per line:
> 
> 50 + 32 + 10 + 3 * 40 + 24 + 64 = 300 bytes per line * 2M lines = ~600MB
> plus some memory for the dicts, which is about what heapy is reporting
> (note I'm currently not actually running all 2M lines, I'm just running
> subsets for my tests).
> 
> Is there something I'm missing? Here's the heapy output after loading
> ~300k lines:
> 
> Partition of a set of 1199849 objects. Total size = 89965376 bytes.
> Index Count % Size % Cumulative % Kind
> 0 59 50 38399920 43 38399920 43 str
> 1 5 0 25167224 28 63567144 71 dict
> 2 28 25 19199872 21 82767016 92 0xa13330
> 3 299836 25 7196064 8 89963080 100 int
> 4 4 0 1152 0 89964232 100
> collections.defaultdict
> 
> Note that 3 of the dicts are empty. I assumet 0xa13330 is the
> address of the object. I'd actually expect to see 900k strings, but the
> <10 char string is always the same in this case so perhaps the runtime
> is using the same object...? 

CPython currently interns short strings that conform to variable name
rules.  You can't count on that behavior (and i probably don't have it
quite right anyway), but it's probably what you're seeing.


> At this point, top reports python as using
> 1.1g of virt and 1.0g of res.
> 
>> I also
>> wonder if heapy has been written to take into account the larger size of
>> pointers in a 64bit build.
> That I don't know, but that would only explain, at most, a 2x increase
> in memory over the heapy report, wouldn't it? Not the ~10x I'm seeing.
> 
>> Another thing is to make sure
>> that the md5 object used in your two maps is the same object, and not
>> just one with the same value.
> That's certainly the way the code is written, and heapy seems to confirm
> that the strings aren't duplicated in memory.
> 
> Thanks for sticking with me on this,

You're certainly welcome.  I suspect that heapy has some limitation in
its reporting, and that's what the discrepancy.  Oscar points out that
you have a bunch of exception objects, which certainly looks suspicious.
 If you're somehow storing one of these per line, and heapy isn't
reporting them, that could be a large discrepancy.

He also points out that you have a couple of lambda functions stored in
one of your dictionary.  A lambda function can be an expensive
proposition if you are building millions of them.  So can nested
functions with non-local variable references, in case you have any of those.

Oscar also reminds you of what I suggested for the md5 fields.  Stored
as ints instead of hex strings could save a good bit.  Just remember to
use the same one for both dicts, as you've been doing with the strings.


Other than that, I'm stumped.


-- 

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


google api and oauth2

2012-09-25 Thread Littlefield, Tyler

Hello all:
I've been trying  to figure out the oauth2client part of google's api, 
and I am really confused.
It shows a flow, and even with the client flow, you need a redirect uri. 
This isn't important because I just want to get both an access and 
refresh token.
Has anyone had any experience with this? Is it  easier to use a more 
developed oauth2 library to handle this? If so, can anyone make any 
suggestions?


If I understand everything correctly, it doesn't matter what library I 
would use to work with the oauth2 protocol, so I could break out of this 
workflow thing that looks like it's more designed for web apps.
Finally, they caution you about being careful about your client id and 
your client secret; is  there much in the way of obviscation or 
something I can do to keep this secret?


--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.

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


Re: python file API

2012-09-25 Thread Thomas Rachel

Am 25.09.2012 09:28 schrieb Steven D'Aprano:


The whole concept is incomplete at one place: self.seek(10, 2) seeks
beyond EOF, potentially creating a sparse file. This is a thing you
cannot achieve.


On the contrary, since the pos attribute is just a wrapper around seek,
you can seek beyond EOF easily:

f.pos = None
f.pos += 10


Yes, from a syscall perspective, it is different: it is a tell() 
combined with a seek set instead of a relative seek. As someone 
mentionned, e. g. in the case of a streamer tape this might make a big 
difference.




But for anything but the most trivial usage, I would recommend sticking
to the seek method.


ACK. This should be kept as a fallback.



... or we need multiple attributes, one for each mode ...


Yes. That's what I would favourize: 3 attributes which each take a value 
to be passed to seek.



So all up, I'm -1 on trying to replace the tell/seek API, and -0 on
adding a second, redundant API.


ACK.


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


Re: data attributes override method attributes?

2012-09-25 Thread Terry Reedy

On 9/25/2012 11:03 AM, Chris Angelico wrote:

On Wed, Sep 26, 2012 at 12:54 AM, Peter Otten <[email protected]> wrote:

To me

"Data attributes override method attributes with the same name"

implies that data attributes take precedence over method attributes, not
that they replace them only when there is an assignment of data after the
method definition.

I would even consider replacing the whole paragraph
with something like

"Data attributes and method attributes share the same namespace. To avoid
name conflicts consider using verbs for methods and nouns for data
attributes"


Instance attributes override (shadow) class attributes.


except for (some? all?) special methods


Since methods
tend to be on the class and data tends to be on the instance, the
original sentence does make some sense.


but it *is* wrong


 The section is talking about

conventions, so it's not inherently wrong,


The suggestion to Capitalize method names and prefix data names with '_' 
are wrong with respect to the style guide.


 but perhaps just needs a

comment about methods not usually being attached to the instance.

ChrisA




--
Terry Jan Reedy

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


Re: google api and oauth2

2012-09-25 Thread Demian Brecht
This is a shameless plug, but if you want a much easier to understand
method of accessing protected resources via OAuth2, I have a 55 LOC client
implementation with docs and examples here:
https://github.com/demianbrecht/sanction (Google is one of the tested
providers with an access example).

Are you trying to access resources client side (through Javascript) or
server side? Either way, the redirect URI *is* important. The first step is
to have your user authorize your application using Google's authorization
page. As one of the query parameters, you must specify the redirect URI
(which must match those registered through Google's app console).

Once the user has authorized your application, they're redirected back to
your site (via the specified redirect URI), with a "code" attached as a
query param. Once you get that code, you must exchange that with Google's
token endpoint to retrieve the access and refresh tokens.

No, it doesn't matter which library you use. Google's (imho) is overly
verbose and difficult to grok (especially for someone new to either OAuth
2.0 or Python, or both). The client ID doesn't need to be kept private, but
the secret does. You should *never* put this anywhere that can be read
publicly.

On Tue, Sep 25, 2012 at 12:04 PM, Littlefield, Tyler wrote:

> Hello all:
> I've been trying  to figure out the oauth2client part of google's api, and
> I am really confused.
> It shows a flow, and even with the client flow, you need a redirect uri.
> This isn't important because I just want to get both an access and refresh
> token.
> Has anyone had any experience with this? Is it  easier to use a more
> developed oauth2 library to handle this? If so, can anyone make any
> suggestions?
>
> If I understand everything correctly, it doesn't matter what library I
> would use to work with the oauth2 protocol, so I could break out of this
> workflow thing that looks like it's more designed for web apps.
> Finally, they caution you about being careful about your client id and
> your client secret; is  there much in the way of obviscation or something I
> can do to keep this secret?
>
> --
> Take care,
> Ty
> http://tds-solutions.net
> The aspen project: a barebones light-weight mud engine:
> http://code.google.com/p/**aspenmud 
> He that will not reason is a bigot; he that cannot reason is a fool; he
> that dares not reason is a slave.
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: data attributes override method attributes?

2012-09-25 Thread Thomas Rachel

Am 25.09.2012 16:08 schrieb Peter Otten:

Jayden wrote:


In the Python Tutorial, Section 9.4, it is said that

"Data attributes override method attributes with the same name."


The tutorial is wrong here. That should be

"Instance attributes override class attributes with the same name."


I jump in here:

THere is one point to consider: if you work with descriptors, it makes a 
difference if they are "data descriptors" (define __set__ and/or 
__delete__) or "non-data descriptors" (define neither).


As http://docs.python.org/reference/datamodel.html#invoking-descriptors 
tells us, methods are non-data descriptors, so they can be overridden by 
instances.


OTOH, properties are data descriptors which cannot  be overridden by the 
instance.


So, to stick to the original example:

class TestDesc(object):
def a(self): pass
@property
def b(self): print "trying to get value - return None"; return None
@b.setter
def b(self, v): print "value", v, "ignored."
@b.deleter
def b(self): print "delete called and ignored"


and now

>>> t=TestDesc()
>>> t.a
>
>>> t.b
trying to get value - return None
>>> t.a=12
>>> t.b=12
value 12 ignored.
>>> t.a
12
>>> t.b
trying to get value - return None
>>> del t.a
>>> del t.b
delete called and ignored
>>> t.a
>
>>> t.b
trying to get value - return None


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


Re: data attributes override method attributes?

2012-09-25 Thread Ian Kelly
On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy  wrote:
> On 9/25/2012 11:03 AM, Chris Angelico wrote:
>> Instance attributes override (shadow) class attributes.
>
>
> except for (some? all?) special methods

Those names are shadowed too.  If you call foo.__len__() and the name
is bound on the instance, it will call that function preferentially.
It's just that when the special Python machinery calls the method, it
skips the instance and goes straight to the class.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: data attributes override method attributes?

2012-09-25 Thread Terry Reedy

On 9/25/2012 10:54 AM, Peter Otten wrote:

alex23 wrote:


On Sep 26, 12:08 am, Peter Otten <[email protected]> wrote:

Jayden wrote:

In the Python Tutorial, Section 9.4, it is said that



"Data attributes override method attributes with the same name."


The tutorial is wrong here. That should be

"Instance attributes override class attributes with the same name."


Except for special methods.


I would even consider replacing the whole paragraph


I agree


"""
Data attributes override method attributes with the same name; to avoid
accidental name conflicts, which may cause hard-to-find bugs in large
programs, it is wise to use some kind of convention that minimizes the
chance of conflicts. Possible conventions include capitalizing method names,
prefixing data attribute names with a small unique string (perhaps just an
underscore), or using verbs for methods and nouns for data attributes.
"""
http://docs.python.org/dev/py3k/tutorial/classes.html

with something like

"Data attributes and method attributes share the same namespace.


and instance attributes usually override class attributes

> To avoid

name conflicts consider using verbs for methods and nouns for data
attributes"


This applies within and between. I opened

http://bugs.python.org/issue16048

--
Terry Jan Reedy

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


Re: google api and oauth2

2012-09-25 Thread Littlefield, Tyler

On 9/25/2012 2:05 PM, Demian Brecht wrote:
This is a shameless plug, but if you want a much easier to understand 
method of accessing protected resources via OAuth2, I have a 55 LOC 
client implementation with docs and examples 
here:https://github.com/demianbrecht/sanction (Google is one of the 
tested providers with an access example).




No complaints from me if it works. Honestly I was a bit discouraged at 
Google's decent lack of documentation and the quality of the code.


Are you trying to access resources client side (through Javascript) or 
server side? Either way, the redirect URI *is* important. The first 
step is to have your user authorize your application using Google's 
authorization page. As one of the query parameters, you must specify 
the redirect URI (which must match those registered through Google's 
app console).


I'm trying to access it through a desktop Python application, which made 
me really confused. There was something else that talked about returning 
the tokens in a different way, but it talked about returning them in the 
title of the webpage, and since I'd be spawning a browser to request 
authorization, I'd have to write something that would pull the window 
information and then parse out the token from the title, which doesn't 
sound to stable.


Once the user has authorized your application, they're redirected back 
to your site (via the specified redirect URI), with a "code" attached 
as a query param. Once you get that code, you must exchange that with 
Google's token endpoint to retrieve the access and refresh tokens.


Awesome. I could theoretically just create a webpage on my server to 
redirect people to with the query, but I'm still not quite sure how I'd 
retrieve that from the desktop application.


No, it doesn't matter which library you use. Google's (imho) is overly 
verbose and difficult to grok (especially for someone new to either 
OAuth 2.0 or Python, or both). The client ID doesn't need to be kept 
private, but the secret does. You should *never* put this anywhere 
that can be read publicly.


I plan on storing them both in variables. It's not going to be the best 
solution, but I plan to use python -O to create pyo files, which from 
what I understand are harder to decompile, and it'll be in a py2exe 
executable. Still not to hard to get at, but it's not right there either.



On Tue, Sep 25, 2012 at 12:04 PM, Littlefield, Tyler 
mailto:[email protected]>> wrote:


Hello all:
I've been trying  to figure out the oauth2client part of google's
api, and I am really confused.
It shows a flow, and even with the client flow, you need a
redirect uri. This isn't important because I just want to get both
an access and refresh token.
Has anyone had any experience with this? Is it  easier to use a
more developed oauth2 library to handle this? If so, can anyone
make any suggestions?

If I understand everything correctly, it doesn't matter what
library I would use to work with the oauth2 protocol, so I could
break out of this workflow thing that looks like it's more
designed for web apps.
Finally, they caution you about being careful about your client id
and your client secret; is  there much in the way of obviscation
or something I can do to keep this secret?

-- 
Take care,

Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a
fool; he that dares not reason is a slave.

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






--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.

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


Re: Memory usage per top 10x usage per heapy

2012-09-25 Thread Junkshops

On 9/25/2012 11:17 AM, Oscar Benjamin wrote:
On 25 September 2012 19:08, Junkshops > wrote:



In [38]: mpef._ustore._store
Out[38]: defaultdict(, {'Measurement':
{'8991c2dc67a49b909918477ee4efd767':
, '7b38b429230f00fe4731e60419e92346':
, 'b53531471b261c44d52f651add647544':
, '44ea6d949f7c8c8ac3bb4c0bf4943f82':
, '0de96f928dc471b297f8a305e71ae3e1':
}})


Have these exceptions been raised from somewhere before being stored? 
I wonder if you're inadvertently keeping execution frames alive. There 
are some problems in CPython with this that are related to storing 
exceptions.
FileContext objects aren't exceptions. They store information about 
where the stored object originally came from, so if there's an MD5 or ID 
clash with a later line in the file the code can report both the current 
line and the older clashing line to the user. I have an Exception 
subclass that takes a FileContext as an argument. There are no 
exceptions thrown in the file I processed to get the heapy results 
earlier in the thread.



In [43]: mpef._ustore._idstore['Measurement']._SIDstore
Out[43]: defaultdict( at 0x2ece7d0>, 
{'emailRemoved': defaultdict( at 0x2c4caa0>, 
{'microPhenoShew2011': defaultdict(, {0: 
{'MLR_124572462': '8991c2dc67a49b909918477ee4efd767', 
'MLR_124572161': '7b38b429230f00fe4731e60419e92346', 
'SMMLR_12551352': 'b53531471b261c44d52f651add647544', 
'SMMLR_12551051': '0de96f928dc471b297f8a305e71ae3e1', 
'SMMLR_12550750': '44ea6d949f7c8c8ac3bb4c0bf4943f82'}})})})
Also I think lambda functions might be able to keep the frame alive. 
Are they by any chance being created in a function that is called in a 
loop?



Here's the context for the lambdas:

  def __init__(self):
self._SIDstore = defaultdict(lambda: defaultdict(lambda: 
defaultdict(dict)))


So the lambda is only being called when a new key is added to the top 3 
levels of the datastructure, which in the test case I've been 
discussing, only happens once each.


Although the suggestion to change the hex strings to ints is a good one 
and I'll do it, what I'm really trying to understand is why there's such 
a large difference between the memory use per top (and the fact that the 
code appears to thrash swap) and per heapy and my calculations of how 
much memory the code should be using.


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


Re: data attributes override method attributes?

2012-09-25 Thread Terry Reedy

On 9/25/2012 4:07 PM, Ian Kelly wrote:

On Tue, Sep 25, 2012 at 1:58 PM, Terry Reedy  wrote:

On 9/25/2012 11:03 AM, Chris Angelico wrote:

Instance attributes override (shadow) class attributes.



except for (some? all?) special methods


Those names are shadowed too.  If you call foo.__len__() and the name
is bound on the instance, it will call that function preferentially.
It's just that when the special Python machinery calls the method, it
skips the instance and goes straight to the class.


I added "Ian Kelly reminds me that instance.__xxx__ is only skipped by 
the internal machinery and not by direct accesses in user code. In the 
other hand, docs, official or otherwise, are filled with things like 
'len(a) calls a.__len__', so I think something should be said that 
giving instances special method attributes does not have the effect one 
might expect."


to the issue.


--
Terry Jan Reedy

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


  1   2   >