Subject: mrjob v0.2.6 released

2011-05-25 Thread Jimmy Retzlaff
What is mrjob?
-
mrjob is a Python package that helps you write and run Hadoop Streaming jobs.

mrjob fully supports Amazon's Elastic MapReduce (EMR) service, which
allows you to buy time on a Hadoop cluster on an hourly basis. It also
works with your own Hadoop cluster.

Some important features:

 * Run jobs on EMR, your own Hadoop cluster, or locally (for testing).
 * Write multi-step jobs (one map-reduce step feeds into the next)
 * Duplicate your production environment inside Hadoop
   * Upload your source tree and put it in your job's $PYTHONPATH
   * Run make and other setup scripts
   * Set environment variables (e.g. $TZ)
   * Easily install python packages from tarballs (EMR only)
   * Setup handled transparently by mrjob.conf config file
 * Automatically interpret error logs from EMR
 * SSH tunnel to hadoop job tracker on EMR
 * Minimal setup
   * To run on EMR, set $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY
   * To run on your Hadoop cluster, install simplejson and make sure
$HADOOP_HOME is set.

More info:

 * Install mrjob: python setup.py install
 * Documentation: http://packages.python.org/mrjob/
 * PyPI: http://pypi.python.org/pypi/mrjob
 * Development is hosted at github: http://github.com/Yelp/mrjob


What's new?
-
v0.2.6, 2011-05-24 -- fix bootstrapping mrjob
 * Set Hadoop to run on EMR with --hadoop-version (Issue #71).
   * Default is still 0.18, but will change to 0.20 in mrjob v0.3.0.
 * New inline runner, for testing locally with a debugger
 * New --strict-protocols option, to catch unencodable data (Issue #76)
 * Added steps_python_bin option (for use with virtualenv)
 * mrjob no longer chokes when asked to run on an EMR job flow running
Hadoop 0.20 (Issue #110)
 * mrjob no longer chokes on job flows with no LogUri (Issue #112)
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: eGenix mxODBC - Python ODBC Database Interface 3.1.1

2011-05-25 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

 eGenix.com mxODBC - Python ODBC Database Interface

   Version 3.1.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.1.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


mxODBC 3.1 Update
-

The mxODBC 3.1.1 patch level release adds compatibility to our new
eGenix.com mx Base Distribution 3.2.0, which includes Windows x64
support.

If you are currently using the combinations mxODBC 3.1.0 + mx Base
3.1.3, please consider upgrading to our latest releases
mxODBC 3.1.1 + mx Base 3.2.0.

Licenses for mxODBC 3.1.0 remain valid for mxODBC 3.1.1 as well.


Release Highlights
--

* We've added Python 2.7 support and builds for all platforms.

* mxODBC 3.1 adds native support for the Windows 64-bit platforms
  as well as the Mac OS X 10.6 (Snow Leopard) 64-bit builds of
  Python.

* mxODBC now fully supports the Oracle Instant Client ODBC driver.

* We have updated the support for the latest IBM DB2 9.7 ODBC
  drivers and enhanced compatibility of mxODBC with the MS SQL
  Server Native Client ODBC driver on Windows and the Sybase ASE 15
  ODBC drivers on Unix.

* mxODBC 3.1 adds support for large-scale data warehouse databases
  Netezza and Teradata.

* In addition to the Windows, Mac OS X, iODBC and unixODBC ODBC
  driver managers, we now also include support for the DataDirect
  ODBC manager.

* The 64-bit support on Unix platforms was updated to support the
  new unixODBC 2.3.0 version.

* We've improved the documentation on how to connect to various
  popular databases and now include many tips  tricks for each
  database/driver.

* The Python 2.7 memoryview object is now supported as binary data
  container.

* We have simplified handling of database warnings using a new
  customizable .warningformat attribute.

* The catalog methods now accept both Unicode and 8-bit strings as
  parameters.

* You can now select whether to use ANSI (8-bit) or Unicode ODBC
  APIs in the ODBC drivers, removing unnecessary data conversions
  and enhancing ODBC driver compatibility.

For the full set of changes please check the mxODBC change log:

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


Feature Highlights
--

* Python Database API 2.0 Compliance: the mxODBC API is fully
  Python DB-API 2.0 compatible and implements a large number of
  powerful extensions.

* Support for all popular ODBC Drivers: mxODBC includes
  adjustments and work-arounds to support MS SQL Server Native
  Client, MS SQL Server ODBC Driver, FreeTDS ODBC Driver, Oracle
  Instant Client ODBC Driver, IBM DB2 ODBC Driver, Sybase ASE ODBC
  Driver, Netezza ODBC Driver, Teradata ODBC Driver, PostgreSQL
  ODBC Driver, MySQL ODBC Driver, .MaxDB ODBC Driver as well as
  the ODBC driver sets of EasySoft, DataDirect, OpenLink, Actual
  Technologies.

* Support for all popular ODBC Driver Managers: mxODBC comes with
  subpackages for the native Windows and Mac OS X ODBC managers,
  as well as the ODBC managers unixODBC, iODBC and DataDirect,
  which are commonly used on Unix systems.

* Stable, robust and reliable:the mxODBC API has been in active
  production use for more than 10 years.

* Full Python Support: mxODBC works with Python 2.4, 2.5, 2.6
  and 2.7.

* Full 64-bit Support: mxODBC runs on the following 64-bit
  platforms: Windows, Linux, FreeBSD and Mac OS X.

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

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


New mxODBC Editions
---

Due to popular demand, we have extended the set of available mxODBC
editions and included a new low-cost standard edition. mxODBC is now
available in thesethree editions:

* The low-cost Standard Edition which provides data connectivity
  to a selected set of database 

Re: English Idiom in Unix: Directory Recursively

2011-05-25 Thread Xah Lee
On May 24, 3:06 pm, Rikishi42 skunkwo...@rikishi42.net wrote:
 On 2011-05-24, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

  I think that is a patronizing remark that under-estimates the
  intelligence of lay people and over-estimates the difficulty of
  understanding recursion.

  Why would you presume this to be related to intelligence? The point was
  not about being *able* to understand, but about *needing* to understand
  in order to use.

  Maybe they don't need to understand recursion. So what?

 I think you should read the earlier posts again, this is drifting so far
 from what I intended.

 What I mean is: I'm certain that over the years I've had more than one
 person come to me and ask what 'Do you wish to delete this directory
 recursively?' meant. BAut never have I been asked to explain what 'Do you
 wish to delete this directory and it's subdirs/with all it's contents?'
 meant. Never.

  Recursion is a perfectly good English word, no more technical than
  accelerate or incinerate or dissolve or combustion. Do people
  need to know the word combustion when they could say burn instead?

 It wasn't about the word, but about the nature of the function. Besides, if
 the chance exists of a confusion between a recursive job and the fact the
 job is done using a recursive function... I would try staying away from the
 expression.  

 Why not use 'delete a directory'. It's obvious the content gets binned, too.

 Do you know many people who incinerate leaves and branches in their garden?
 I burn them.

  Do they need to know the words microwave oven when they could be saying
  invisible rays cooking thing?

 The word oven has existed for ages, microwave is just a name for the type of
 oven. Not even a description, just a name.

  I wonder whether physicists insist that cars should have a go faster
  pedal because ordinary people don't need to understand Newton's Laws of
  Motion in order to drive cars?

 Gas pedal. Pedal was allraedy known when the car was invented. The simple
 addition of gas solved that need. Oh, and it's break pedal, not
 descellarator. (sp?)

  Who are you to say that people shouldn't be exposed to words you deem
  that they don't need to know?

 I'm one of the 'people'. You say exposed to, I say bothered/bored with.

 I have nothing against the use of a proper, precise term. And that word can
 be a complex one with many, many sylables (seems to add value, somehow).

 But I'm not an academic, so I don't admire the pedantic use of terms that
 need to be explained to 'lay' people. Especially if there is a widespread,
 usually shorter and much simpler one for it. A pointless effort if
 pointless, even when comming from a physicist.  :-)

very well said, Rikishi42.

this one is probably the most intelligent post in this thread.

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


Re: Beginner needs advice

2011-05-25 Thread Lew Schwartz
So, if I read between the lines correctly, you recommend Python 3? Does the
windows version install with a development environment?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Obtaining a full path name from file

2011-05-25 Thread Ulrich Eckhardt
RVince wrote:
 s = C:\AciiCsv\Gravity_Test_data\A.csv
 f = open(s,r)
 
 How do I obtain the full pathname given the File, f?

Apart from the issue that the 'name' attribute is only the name used to open 
the file, there is another issue, though not on the platform you're using: 
Multiple directory entries can point to the same file, all of which can be 
changed (including deletion!) even while you have the file open.

I'm not sure what problem you're trying to solve, but I'm afraid your 
approach is at least limited.

Good luck!

Uli


-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Code Review

2011-05-25 Thread Peter Otten
ad wrote:

 Please review the code pasted below. I am wondering what other ways
 there are of performing the same tasks. This was typed using version
 3.2. The script is designed to clean up a directory (FTP, Logs, etc.)
 Basically you pass two arguments. The first argument is an number of
 days old to delete. The second argument is the directory where the
 files and folders should be deleted. I imagine one enhancement would
 be to create a function out of some of this.

 CurrentTime = time.time()

Read PEP 8 on naming conventions etc., see 
http://python.org/dev/peps/pep-0008/
 
 epocDay = 86400   # seconds
 
 
 
 
 
 parser = argparse.ArgumentParser(description = Delete files and

What's the purpose of those many empty lines?

 folders in a directory N days old, add_help=False,
 prog='directorycleaner', usage='%(prog)s 7 c:\\temp')
 
 parser.add_argument('days', type=int, help=Numeric value: delete
 files and folders older then N days)
 
 parser.add_argument('directory', help=delete files and folders in
 this directory)
 
 parser.print_help()

What's the idea behind add_help=False and the explicit print_help()?

 dictKeys = (vars(args))
 HowManyDays = dictKeys['days']

This can be simplified to

HowManyDays = args.days

 if dirExists == False: print (The directory is missing)

if x == False: ...

is normally written as 

if not x: ...

 DirListing = os.listdir(WhatDirectory)
 for files in DirListing:

You might write this as

for filename in os.listdir(WhatDirectory): ...

or even

for filename in os.listdir(args.directory): ...

Personally I would put this stuff in a separate function like

def remove_old_files_and_folders(parent_directory, age_in_seconds):
...

 # time.ctime converts epoch to a normal date
 
 #print (time.ctime(CurrentTime))
 
 # Get the date from seven days ago
 
 WeekOldFileDate = CurrentTime - DaysToDelete
 
 #print (CurrentTime)
 
 #print (FileCreationTime)
 
 #print (WeekOldFileDate)

Don't let out-commented code eclipse the actual code; remove it. If you want 
to preserve it for eternity, have a look at version control systems, e. g. 
Mercurial.

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


Re: Obtaining a full path name from file

2011-05-25 Thread Tim Golden

On 25/05/2011 07:36, Ulrich Eckhardt wrote:

RVince wrote:

s = C:\AciiCsv\Gravity_Test_data\A.csv
f = open(s,r)

How do I obtain the full pathname given the File, f?


Apart from the issue that the 'name' attribute is only the name used to open
the file, there is another issue, though not on the platform you're using:
Multiple directory entries can point to the same file, all of which can be
changed (including deletion!) even while you have the file open.


FWIW that's true even on Windows. (Although arguably less common).


I'm not sure what problem you're trying to solve, but I'm afraid your
approach is at least limited.


Depends on what the requirement is. If it is, essentially: give me
at least one of the names this file had when I opened it, then this
approach is surely adequate. Certainly, things could have happened in 
the meantime. Obviously, only the OP can know the circumstances he's 
dealing with, but ISTM that far and away the most common case will

be that the file has exactly one name and that it hasn't changed.

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


Re: English Idiom in Unix: Directory Recursively

2011-05-25 Thread Thorsten Kampe
* Rikishi42 (Wed, 25 May 2011 00:06:06 +0200)
 
 On 2011-05-24, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
  I think that is a patronizing remark that under-estimates the
  intelligence of lay people and over-estimates the difficulty of
  understanding recursion.
  
  Why would you presume this to be related to intelligence? The point was
  not about being *able* to understand, but about *needing* to understand
  in order to use.
 
  Maybe they don't need to understand recursion. So what?
 
 I think you should read the earlier posts again, this is drifting so far
 from what I intended.
 
 What I mean is: I'm certain that over the years I've had more than one
 person come to me and ask what 'Do you wish to delete this directory
 recursively?' meant. BAut never have I been asked to explain what 'Do you
 wish to delete this directory and it's subdirs/with all it's contents?'
 meant. Never.

Naming something in the terms of its implementation details (in this 
case recursion) is a classical WTF.

On the other hand, it's by far not the only WTF in Unix. For instance, 
how often have you read unlink instead of delete? Or directory 
instead of folder, pointing out that directory is the correct term 
because a directory is just a listing and does not contain the actual 
files. Of course these implementation details will never matter to 
anyone except under the rarest conditions.

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Thorsten Kampe
* Chris Angelico (Wed, 25 May 2011 08:01:38 +1000)
 
 On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain da...@druid.net wrote:
  One of my favorite quotes (not sure if it was about Perl or APL) is 
I
  refuse to use a programming language where the proponents of it stick
  snippets under each other's nose and say 'I bet you can't guess what
  this does.'
 
 Yes, I believe that was Perl. And an amusing quote. But most of the
 point of it comes from the fact that Perl uses punctuation for most of
 its keywords, whereas (say) Python uses English words; it's a lot more
 fun to crunch something down when you can use $| and friends than when
 you have to put x and y, complete with spaces, for a simple boolean.
 But that says nothing about which language is actually better for
 working with... [...]

It does say something about readibility. And yes, readability counts. 
And yes, readability says a lot about how good a language is for reading 
and working with.

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


Re: File access denied after subprocess completion on Windows platform

2011-05-25 Thread Tim Golden

On 24/05/2011 21:18, Claudiu Nicolaie CISMARU wrote:

Now. There is one more issue. Seems that on faster computers and/or
Windows 7 (the Win32 thing I have tested on a HVM Xen machine with
Windows XP) the os.rename is too fast after fp.close() and generates the
same Exception. The code follows:

curl.close()
fp.close()
os.rename(tfile, actualfile)

Where, tfile is the .part file, actual file is the real destination, fp
was opened with open(..., wb) and the descriptor passed to curl.

I have solved the issue with self.msleep(10) - msleep is a method of
QThread. But I don't think it's an elegant and normal solution. Did
fp.close() is delayed, or? I mean, I don't want to rely on a sleep in
order to workaround the access issue.


There used to be a problem with subprocess fds being held by
a traceback. IIRC, the problem could be triggered by having
an except clause around a subprocess call within which something 
attempted to, eg,

remove one of the affected files. I'm sorry if that's a bit
of a woolly description but if you think this might be
biting you I'll dive in and look at the code. What version
of Python are you using?

(That said, the fact that the behaviour varies between faster
and slower computers makes that cause unlikely. Maybe we're
back to looking at virus checkers and the like...)

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


Re: Code Review

2011-05-25 Thread Chris Torek
In article
37ba7b40-3663-4094-b507-696fc598b...@l26g2000yqm.googlegroups.com
ad  adsquai...@gmail.com wrote:
Please review the code pasted below. I am wondering what other ways
there are of performing the same tasks. ...  I imagine one enhancement
would be to create a function out of some of this.

Indeed -- recommended styles include defining a main()
function and calling main at the bottom, e.g., with:

if __name__ == '__main__':
main()

or:

if __name__ == '__main__':
main(sys.argv)

Something has also double-spaced your code; I will undo that below.

import os
import time
import shutil
import argparse

So far so good.

Let me start by putting the next parts into main().  I will use
the no-argument format since we can simply let parser.parse_args()
fetch sys.argv the same way you did (we could def main(argv) and
pass argv; this is sometimes useful for testing purposes, but here
it makes little difference one way or another).

def main():
CurrentTime = time.time()
epocDay = 86400   # seconds

(You could write 24 * 60 * 60, but again this is sort of a six-of-one
half-a-dozen-of-the-other situation.)  What is not clear is why you
are setting these now, rather than later, closer to where they are
going to be used.

Many style guides, including Guido's and pylint's, dislike
UppercaseVariableName and camelCase style names within functions.
(UppercaseNames are reserved to classes.)  I am leaving these alone
for now though.

parser = argparse.ArgumentParser(description = Delete files and
folders in a directory N days old, add_help=False,
prog='directorycleaner', usage='%(prog)s 7 c:\\temp')

Line wrap has done bad things to this.  Still, there is something
odd about it other than the line wrap:

  - sometimes you write:
param_name = value
but sometimes you use:
param_name=value
and in one case you even use both:
usage= [string]

  - you switch back and forth between single and double quoted
strings, without much reason.

Consistency is not *required* but it is generally a good idea.
(This is also minor, like deciding between 86400 or 24*60*60.
Eventually, though, lots of minor things add up.)

(I have to admit here that I tend to switch back and forth on
quotes too. :-) )

Another sixes case occurs here with the backslashes: to get
a literal backslash in a string, you can use raw strings.  Here
it makes no difference but I will go ahead and do it just for
illustration:

parser = argparse.ArgumentParser(
description='Delete files and folders in a directory N days old',
add_help=False,
prog='directorycleaner',
usage=r'%(prog)s 7 c:\temp')

Finally, I am not sure why you do not want to allow a -h / --help 
option (but if you take out the add_help=False, it's probably best
to take out the call to parser.print_help() too), and there is no
need to supply a usage= argument at all -- argparse() will build
one for you.

parser.add_argument('days', type=int, help=Numeric value: delete
files and folders older then N days)
parser.add_argument('directory', help=delete files and folders in
this directory)

(Again, line wrap has broken these; the fixes are obvious so I skip
over them here.)

parser.print_help()
args = parser.parse_args()

(So far so good, although again, you probably want to remove the call
to print_help() if you allow argparse to add a -h / --help option,
at least.)

dictKeys = (vars(args))

There is no *need* to do this, although it is documented as allowed.
I prefer to just use args.field myself:

HowManyDays = dictKeys['days']
WhatDirectory = dictKeys['directory']

so this would become:

HowManyDays = args.days
WhatDirectory = args.directory

print (HowManyDays)
print (WhatDirectory)

These are presumably debug statements and should be removed, but
until then, it might be good to prefix the output with what is
being printed (i.e., a debug message).  (I have taken them out
of my copy, for output shown below.)

(In a fancier program, you could use the logging module and
logging.debug().)

DaysToDelete = HowManyDays * epocDay

Right before this would be a good place to create epocDay.

dirExists = os.path.exists(WhatDirectory)
if dirExists == False: print (The directory is missing)

An explicit if expr == False is generally a bad idea -- if an
expression can be considered boolean (and the return value of
os.path.exists certainly can), just write if not expr.

Most style guides suggest putting subsequent statements on new
lines, rather than right after the :.

Checking that the directory exists seems reasonable enough.  However,
after printing that it does not, you continue on with code that is
going to immediately raise an OSError exception:

DirListing = os.listdir(WhatDirectory)

In general, it is better to try to do the operation, and catch the
failure and do something about it at that point, than to test to
see if the 

BEST WAY TO EARN DOLLARS FROM COMPANY JUST SUBSCRIBE AND SEE , JOIN NOW

2011-05-25 Thread shoba kasthuri
shoba.1...@rediffmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: English Idiom in Unix: Directory Recursively

2011-05-25 Thread Xah Lee
On May 25, 12:26 am, Thorsten Kampe thors...@thorstenkampe.de wrote:
 * Rikishi42 (Wed, 25 May 2011 00:06:06 +0200)











  On 2011-05-24, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
   I think that is a patronizing remark that under-estimates the
   intelligence of lay people and over-estimates the difficulty of
   understanding recursion.

   Why would you presume this to be related to intelligence? The point was
   not about being *able* to understand, but about *needing* to understand
   in order to use.

   Maybe they don't need to understand recursion. So what?

  I think you should read the earlier posts again, this is drifting so far
  from what I intended.

  What I mean is: I'm certain that over the years I've had more than one
  person come to me and ask what 'Do you wish to delete this directory
  recursively?' meant. BAut never have I been asked to explain what 'Do you
  wish to delete this directory and it's subdirs/with all it's contents?'
  meant. Never.

 Naming something in the terms of its implementation details (in this
 case recursion) is a classical WTF.

 On the other hand, it's by far not the only WTF in Unix. For instance,
 how often have you read unlink instead of delete? Or directory
 instead of folder, pointing out that directory is the correct term
 because a directory is just a listing and does not contain the actual
 files. Of course these implementation details will never matter to
 anyone except under the rarest conditions.

 Thorsten

well said.

half of posts in this thread are from idiots. just incredible, but
again, its newsgroups ... what am i thinking ...

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


Re: English Idiom in Unix: Directory Recursively

2011-05-25 Thread Chris Angelico
On Wed, May 25, 2011 at 5:51 PM, Xah Lee xah...@gmail.com wrote:
 well said.

 half of posts in this thread are from idiots. just incredible, but
 again, its newsgroups ... what am i thinking ...

  Xah


Thank you. As soon as we figure out which half of us you just publicly
insulted, we'll see about getting offended. Until then, thank you for
your contribution and please, have a nice day.

Chris Angelico
removing tongue from cheek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code Review

2011-05-25 Thread Ulrich Eckhardt
ad wrote:
 Please review the code pasted below. I am wondering what other ways
 there are of performing the same tasks.

On a unix system, you would call find with according arguments and then 
handle the found files with -exec rm ... or something like that, but I see 
you are on MS Windows.


 args = parser.parse_args()
 
 dictKeys = (vars(args))

The first of these looks okay, while I don't get the additional brackets in 
the second one. Another habit I observe here is the Hungarian notation of 
prefixing the type to the name and using camelCaps. PEP 8 (IIRC) has 
something to say on the preferred naming. I'm not 100% against encoding the 
type in the variable name in Python, since it lacks static type checking, I 
would have chosen key_dict here though, or, due to the small size of the 
overall program just keys.

 print (HowManyDays)

This puzzled me at first, again the useless additional brackets I thought. 
However, in Python 3, print is a function, so that is correct. Still, it 
should be print(foo) not print (foo).

 for files in DirListing:
 
 # Get the absolute path of the file name
 abspath = (os.path.join(WhatDirectory, files))

files is just the name of a single file, right? In that case the name is a 
bit confusing.

 # Get the date from seven days ago
 WeekOldFileDate = CurrentTime - DaysToDelete

You are repeating this calculation for every file in the loop.

 if FileCreationTime  WeekOldFileDate:
 #check if the object is a file
 if os.path.isfile(abspath): os.remove(abspath)
 # It is not a file it is a directory
 elif os.path.isdir(abspath): shutil.rmtree(abspath)

I'm not sure, but I believe you could use shutil.rmtree() for both files and 
directories. In any case, be prepared for the file still being open or 
otherwise read-only, i.e. for having to handle errors.

Also, what if a directory is old but the content is new? Would this cause 
the non-old content to be deleted?


Cheers!

Uli


-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


pyGTK identify a button

2011-05-25 Thread Tracubik

Hi all,
i'm trying to write a simple windows with two button in GTK, i need a 
way to identify wich button is pressed.

Consider that:

the two button are connected (when clicked) to infoButton(self, widget, 
data=None)


infoButton() is something like this

infoButton(self, widget, data=None):
# discover wich button was pressed
...
# say hello to the button
if button1pressed:
print Hi, button1!
else:
print Hi, button2!

so, how can I know wich button was pressed without using data and 
without reading the label of the button (i could have buttons with the 
same label)


If data is needed, can someone pls tell me how to set it properly in 
glade 3.8


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


Re: File access denied after subprocess completion on Windows platform

2011-05-25 Thread Claudiu Nicolaie CISMARU

 There used to be a problem with subprocess fds being held by
 a traceback. IIRC, the problem could be triggered by having
 an except clause around a subprocess call within which something 
 attempted to, eg,
 remove one of the affected files.

I have no subprocess call.. in this last issue. And I didn't triggered 
one (disabled the Button that runs the subprocess).

try:
for line in t.splitlines():

[...]

ret = self.downloadFileToDisk(filename, do_rename)

if not ret:
print DEBUG: Problema la download
raise Exception()

(1) except Exception as inst:
print type(inst)
print inst.args

self.updateText.emit(EROARE: Eroare la descarcare)
self.updateStatusBar.emit(EROARE: Eroare la descaracare 
fisiere)
return

Where downloadFileToDisk():

def downloadFileToDisk(self, filename, final_rename=True):
dfilename = os.path.join(saveBasePATH, filename)
sfilename = dfilename + .part

dfolder = os.path.dirname(sfilename)
if dfolder != :
if not os.path.isdir(dfolder):
os.makedirs(dfolder)

try:
fp = open(sfilename, wb)
except:
return False

curl = pycurl.Curl()

curl.setopt(pycurl.URL, baseUpdateURL + /client/ + filename)
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
curl.setopt(pycurl.NOPROGRESS, 0)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.PROGRESSFUNCTION, self.updateFileProgress)
curl.setopt(pycurl.WRITEDATA, fp)
curl.setopt(pycurl.BUFFERSIZE, 4194304)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.perform()

retcode = curl.getinfo(pycurl.HTTP_CODE)

curl.close()

fp.close()

if retcode != 200:
(2) os.unlink(sfilename)
return False

self.msleep(10)

if final_rename:
os.rename(sfilename, dfilename)

return True

Without self.msleep(10), (1) catches WindowsError: file access ... blah 
blah. Maybe at (2) can be an access violation, but it wasn't triggered 
yet in tests. I will move the sleep after fp.close(). Yes, I know that 
what it've done with raise Exception() is UGLY, since this program it's 
more a quick hack solution to a problem :). Anyway the Exception that is 
catched is not rised by my code (it's a WindowsError). 

 I'm sorry if that's a bit
 of a woolly description but if you think this might be
 biting you I'll dive in and look at the code. What version
 of Python are you using?

Last 2.7.x. Well, if os.rename is instead a subprocess call, then it's 
subprocess based. I'm new to Python but 99% I think it's a system call 
:)

 (That said, the fact that the behaviour varies between faster
 and slower computers makes that cause unlikely. Maybe we're
 back to looking at virus checkers and the like...)

On that virtual machine there is no virus checker. On the faster machine 
I disabled and closed the antivirus.

-- 
  Claudiu Nicolaie CISMARU
  GNU GPG Key: http://claudiu.targujiu.net/key.gpg
  T: +40 755 135455
  E: clau...@virtuamagic.com, claudiu.cism...@gmail.com


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyGTK identify a button

2011-05-25 Thread Claudiu Nicolaie CISMARU
 the two button are connected (when clicked) to infoButton(self, 
 widget, 
 data=None)

From documentation:
handler_id = object.connect(name, func, func_data)

So:

button1.connect(when is pressed, your_function, 1)
button2.connect(when is pressed, your_function, 2)
(This code is conception, I don't really know how is done in GTK).

On the callback:
infoButton(self, widget, data=None):
# discover wich button was pressed
...
# say hello to the button
if data == 1:
print Hi, button1!
else:
print Hi, button2!

-- 
  Claudiu Nicolaie CISMARU
  GNU GPG Key: http://claudiu.targujiu.net/key.gpg
  T: +40 755 135455
  E: clau...@virtuamagic.com, claudiu.cism...@gmail.com


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hotshoting recursive function

2011-05-25 Thread Gabriel Genellina
En Sun, 22 May 2011 10:42:08 -0300, Selvam s.selvams...@gmail.com  
escribió:



I am using  hotshot module to profile my python function.

I used the details from (
http://code.activestate.com/recipes/576656-quick-python-profiling-with-hotshot/
).

The function I profile is a recursive one and I am getting the following
error,

ProfilerError: profiler already active

I guess this is due to the recursive call to the profiling function.

I would like to get some suggestions.


The recursive call inside your function should call the undecorated  
function, not the decorated function again. Decorator syntax is not  
convenient anymore.


Using the same names as in the recipe example:


# a recursive function
def my_slow_function(n):
  ...
  return my_slow_function(n-1)


my_profiled_slow_function = hotshotit(my_slow_function)
my_profiled_slow_function(n)


This works, in the sense that it does not raise ProfileError anymore.  
Interpreting profile data is up to you...



--
Gabriel Genellina

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


Re: Link errors embedding Python 3.2

2011-05-25 Thread Chris Angelico
Followup. I'm now using Python 3.3 straight from Mercurial, and am
seeing the same issues. I've managed to get the compilation step to
succeed by naming the library for full inclusion and adding -lutil
-ldl (sounding rather Donizetti there), and my program runs. However,
it's unable to import all its modules. I can happily import re,
string, and sys, but importing math or time results in an ImportError
citing undefined symbol: PyExc_ValueError. I think there's still
something I'm mucking up in the link process.

The exception is ImportError, with text:
'/usr/local/lib/python3.3/lib-dynload/time.cpython-33m.so: undefined
symbol: PyExc_ValueError'

Any ideas?

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


Re: pyGTK identify a button

2011-05-25 Thread Tracubik

On 25/05/2011 10:44, Claudiu Nicolaie CISMARU wrote:

the two button are connected (when clicked) to infoButton(self,
widget,
data=None)


 From documentation:
handler_id = object.connect(name, func, func_data)

So:

button1.connect(when is pressed, your_function, 1)
button2.connect(when is pressed, your_function, 2)
(This code is conception, I don't really know how is done in GTK).


thanks but, as i've sayed before, i can't use func_data 'cause i don't 
know how to set it on glade3.8, that is the program i use to create the 
GUI.

Anyway, i think this is the only way to identify the button :-/
--
http://mail.python.org/mailman/listinfo/python-list


Re: pyGTK identify a button

2011-05-25 Thread Chris Angelico
On Wed, May 25, 2011 at 6:18 PM, Tracubik affdfsdfds...@b.com wrote:
 Hi all,
 i'm trying to write a simple windows with two button in GTK, i need a way to
 identify wich button is pressed.
 Consider that:

 the two button are connected (when clicked) to infoButton(self, widget,
 data=None)

I'm not terribly familiar with GTK, but I believe the 'widget'
parameter is the button that was clicked on. Whatever means you have
for distinguishing them (saving another reference to each object in a
named variable, etc), you should be able to do with that parameter.

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


Re: pyGTK identify a button

2011-05-25 Thread Claudiu Nicolaie CISMARU
 thanks but, as i've sayed before, i can't use func_data 'cause i don't 
 know how to set it on glade3.8, that is the program i use to create 
 the 
 GUI.
 Anyway, i think this is the only way to identify the button :-/

Hack into the generated source!

-- 
  Claudiu Nicolaie CISMARU
  GNU GPG Key: http://claudiu.targujiu.net/key.gpg
  T: +40 755 135455
  E: clau...@virtuamagic.com, claudiu.cism...@gmail.com


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner needs advice

2011-05-25 Thread Jean-Michel Pichavant

Lew Schwartz wrote:
So, if I read between the lines correctly, you recommend Python 3? 
Does the windows version install with a development environment?


If you want to use python 3, make sure before that all the good stuff 
you need (==modules) have been ported to python 3.

If you are a complete beginner, I would advise python 2.7.

JM



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


Re: pexpect: TIMEOUT no longer clears child.before

2011-05-25 Thread Gabriel Genellina
En Thu, 19 May 2011 08:29:21 -0300, Adrian Casey m...@agcasey.com  
escribió:


The behaviour of pexpect has changed between version 2.1 and 2.3.  In  
version 2.1, the following code would result in child.before being  
cleared -:


 child.expect(pexpect.TIMEOUT,1)
 In version 2.3, this is no longer the case.  No matter how many times  
the above code is run, child.before continues to hold the output from  
previous commands.  It is important to be able to clear the contents of  
child.before between each command.  What is the correct way to do this  
in version 2.3?


Try contacting the author: www.noah.org

--
Gabriel Genellina

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


[pyodbc] Setting values to SQL_* constants while creating a connection

2011-05-25 Thread srinivasan munisamy
Hi,
I would like to know how to set values to values to SQL_*  constants while
creating a db connection through pyodbc module.
For example, i am getting a connection object like below:

In [27]: dbh1 = pyodbc.connect(DSN=dsn;UID=
uid;PWD=pwd;DATABASE=database;APP=app_name)

In [28]: dbh1.getinfo(pyodbc.SQL_DESCRIBE_PARAMETER)

Out[28]: True

I want to set this SQL_DESCRIBE_PARAMETER to false for this connection
object. How could i do that?
Please help me in figuring it out.

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


Re: English Idiom in Unix: Directory Recursively

2011-05-25 Thread Steven D'Aprano
On Wed, 25 May 2011 08:14:27 +1000, Chris Angelico wrote:

 On Wed, May 25, 2011 at 3:40 AM, Xah Lee xah...@gmail.com wrote:
 On May 23, 9:28 pm, Chris Angelico ros...@gmail.com wrote:
 Because I do not consider its behaviour to be errant. And I suspect
 its main developers won't either. That's why I suggested you grab the
 sources and make The Perfect Emacs.

 why don't you try http://ergoemacs.org/ ?
 
 You miss my point. I am not desiring of a different emacs; you were the
 one complaining about its shortcomings.

It's Xah Lee. Of course he misses your point. He refuses to stop spamming 
newsgroups even after being banned by his ISP, and he refuses to listen 
to any opinion that doesn't agree with his own. Everyone else is an idiot.



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


Re: Obtaining a full path name from file

2011-05-25 Thread Dave Angel

On 01/-10/-28163 02:59 PM, RVince wrote:

s = C:\AciiCsv\Gravity_Test_data\A.csv
f = open(s,r)

How do I obtain the full pathname given the File, f? (which should
equal C:\AciiCsv\Gravity_Test_data). I've tried all sorts of stuff
and am just not finding it. Any help greatly appreciated !



I saw lots of responses, but I don't think anybody pointed out that the 
filename is probably invalid.  This particular string will work, but if 
you have a directory that starts with a T or an N, you may get some 
surprises.  The backslash is treated specially in a literal string.


When building a Windows directory name in a literal string, you 
generally need to do one of three things:


1) use raw literals
2) double the backslash
3) use a forward slash

DaveA


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


ANN: eGenix mxODBC - Python ODBC Database Interface 3.1.1

2011-05-25 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

 eGenix.com mxODBC - Python ODBC Database Interface

   Version 3.1.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.1.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


mxODBC 3.1 Update
-

The mxODBC 3.1.1 patch level release adds compatibility to our new
eGenix.com mx Base Distribution 3.2.0, which includes Windows x64
support.

If you are currently using the combinations mxODBC 3.1.0 + mx Base
3.1.3, please consider upgrading to our latest releases
mxODBC 3.1.1 + mx Base 3.2.0.

Licenses for mxODBC 3.1.0 remain valid for mxODBC 3.1.1 as well.


Release Highlights
--

* We've added Python 2.7 support and builds for all platforms.

* mxODBC 3.1 adds native support for the Windows 64-bit platforms
  as well as the Mac OS X 10.6 (Snow Leopard) 64-bit builds of
  Python.

* mxODBC now fully supports the Oracle Instant Client ODBC driver.

* We have updated the support for the latest IBM DB2 9.7 ODBC
  drivers and enhanced compatibility of mxODBC with the MS SQL
  Server Native Client ODBC driver on Windows and the Sybase ASE 15
  ODBC drivers on Unix.

* mxODBC 3.1 adds support for large-scale data warehouse databases
  Netezza and Teradata.

* In addition to the Windows, Mac OS X, iODBC and unixODBC ODBC
  driver managers, we now also include support for the DataDirect
  ODBC manager.

* The 64-bit support on Unix platforms was updated to support the
  new unixODBC 2.3.0 version.

* We've improved the documentation on how to connect to various
  popular databases and now include many tips  tricks for each
  database/driver.

* The Python 2.7 memoryview object is now supported as binary data
  container.

* We have simplified handling of database warnings using a new
  customizable .warningformat attribute.

* The catalog methods now accept both Unicode and 8-bit strings as
  parameters.

* You can now select whether to use ANSI (8-bit) or Unicode ODBC
  APIs in the ODBC drivers, removing unnecessary data conversions
  and enhancing ODBC driver compatibility.

For the full set of changes please check the mxODBC change log:

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


Feature Highlights
--

* Python Database API 2.0 Compliance: the mxODBC API is fully
  Python DB-API 2.0 compatible and implements a large number of
  powerful extensions.

* Support for all popular ODBC Drivers: mxODBC includes
  adjustments and work-arounds to support MS SQL Server Native
  Client, MS SQL Server ODBC Driver, FreeTDS ODBC Driver, Oracle
  Instant Client ODBC Driver, IBM DB2 ODBC Driver, Sybase ASE ODBC
  Driver, Netezza ODBC Driver, Teradata ODBC Driver, PostgreSQL
  ODBC Driver, MySQL ODBC Driver, .MaxDB ODBC Driver as well as
  the ODBC driver sets of EasySoft, DataDirect, OpenLink, Actual
  Technologies.

* Support for all popular ODBC Driver Managers: mxODBC comes with
  subpackages for the native Windows and Mac OS X ODBC managers,
  as well as the ODBC managers unixODBC, iODBC and DataDirect,
  which are commonly used on Unix systems.

* Stable, robust and reliable:the mxODBC API has been in active
  production use for more than 10 years.

* Full Python Support: mxODBC works with Python 2.4, 2.5, 2.6
  and 2.7.

* Full 64-bit Support: mxODBC runs on the following 64-bit
  platforms: Windows, Linux, FreeBSD and Mac OS X.

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

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


New mxODBC Editions
---

Due to popular demand, we have extended the set of available mxODBC
editions and included a new low-cost standard edition. mxODBC is now
available in thesethree editions:

* The low-cost Standard Edition which provides data connectivity
  to a selected set of database 

Re: Why did Quora choose Python for its development?

2011-05-25 Thread Roy Smith
In article mailman.2052.1306303508.9059.python-l...@python.org,
 Dennis Lee Bieber wlfr...@ix.netcom.com wrote:

 On Tue, 24 May 2011 13:39:02 -0400, D'Arcy J.M. Cain da...@druid.net
 declaimed the following in gmane.comp.python.general:
 
 
  My point was that even proponents of the language can make a
  significant error based on the way the variable is named.  It's like
  the old Fortran IV that I first learned where the name of the variable
  determined whether it was an integer or a floating point.
 
   Only if one didn't declare the type ahead of time...
 
   And even then it wasn't that hard to remember (using a non-PC
 mnemonic): Indian's are integer (variables starting I to N inclusive
 were integers)

Remembering that I, J, K, L, M, and N were integer was trivial if you 
came from a math background.  And, of course, Fortran was all about 
math, so that was natural.  Those letters are commonly used for integers 
in formulae.  If I write $ x sub i $, anybody who knows math would 
immediately assume that the range of x was reals and the range of i was 
integers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Chris Angelico
On Wed, May 25, 2011 at 9:36 PM, Roy Smith r...@panix.com wrote:
 Remembering that I, J, K, L, M, and N were integer was trivial if you
 came from a math background.  And, of course, Fortran was all about
 math, so that was natural.  Those letters are commonly used for integers
 in formulae.  If I write $ x sub i $, anybody who knows math would
 immediately assume that the range of x was reals and the range of i was
 integers.

When I studied maths, x and y were reals, and i wasn't. But it wasn't
integer either... :)

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread John Bokma
Dennis Lee Bieber wlfr...@ix.netcom.com writes:

 Python books than after six months of trying to understand PERL... And

Perl is the language, and perl is what runs Perl.

-- 
John Bokma   j3b

Blog: http://johnbokma.com/Perl Consultancy: http://castleamber.com/
Perl for books:http://johnbokma.com/perl/help-in-exchange-for-books.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did Quora choose Python for its development?

2011-05-25 Thread John Bokma
Thorsten Kampe thors...@thorstenkampe.de writes:

 * Chris Angelico (Wed, 25 May 2011 08:01:38 +1000)
 
 On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain da...@druid.net wrote:
  One of my favorite quotes (not sure if it was about Perl or APL) is 
 I
  refuse to use a programming language where the proponents of it stick
  snippets under each other's nose and say 'I bet you can't guess what
  this does.'
 
 Yes, I believe that was Perl. And an amusing quote. But most of the
 point of it comes from the fact that Perl uses punctuation for most of
 its keywords, whereas (say) Python uses English words; it's a lot more
 fun to crunch something down when you can use $| and friends than when
 you have to put x and y, complete with spaces, for a simple boolean.
 But that says nothing about which language is actually better for
 working with... [...]

 It does say something about readibility. And yes, readability counts. 
 And yes, readability says a lot about how good a language is for reading 
 and working with.

To people used to the latin alphabet languages using a different script
are unreadable. So readability has a lot to do with what one is used
to. Like I already stated before: if Python is really so much better
than Python readability wise, why do I have such a hard time dropping
Perl and moving on?

-- 
John Bokma   j3b

Blog: http://johnbokma.com/Perl Consultancy: http://castleamber.com/
Perl for books:http://johnbokma.com/perl/help-in-exchange-for-books.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Unable to make ironpython run in browser with silverlight

2011-05-25 Thread ErichCart ErichCart
Basically i am following this tutorial:
http://blog.jimmy.schementi.com/2010/03/pycon-2010-python-in-browser.html
According to it, this code should run fine:

!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01//EN
   http://www.w3.org/TR/html4/strict.dtd;
html
  head
  script type=text/javascript
  src=http://gestalt.ironpython.net/dlr-20100305.js;/
script
  script type=text/python src=http://github.com/jschementi/
pycon2010/raw/master/repl.py/script
  /head
  body
script type=text/python
  window.Alert(Hello from Python!)
/script

  /body
/html

And in fact, it does, for example here: 
http://ironpython.net/browser/examples/pycon2010/start.html

You will see it if you have silverlight installed.

But the problem is that when I try to make the same code run on my PC,
I can't do it. I create a text file, copy this code there, save it as
test.html, and run with firefox, but nothing happens. Code does not
execute, i just get a blank page. I can't understand the reason why
the same code runs here: 
http://ironpython.net/browser/examples/pycon2010/start.html,
but not on my PC, given that it is a client side code, and not the
server side.

And there is nothing written in firefox error console, when I run it
locally.
But if I host it on my webhosting account, then I get this error:

Error: uncaught exception: [Exception... Component returned failure
code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]
nsresult: 0x80004005 (NS_ERROR_FAILURE) location: JS frame :: http://
sitename .com/silverlighttest.html :: DLR_DownloadResource :: line 15
data: no]

I uploaded the html file I am using here: 
http://www.filedropper.com/silverlighttest
But it just a text file with that code with extension changed
to .html.

What can I do?
-- 
http://mail.python.org/mailman/listinfo/python-list


mresh

2011-05-25 Thread Vijayakumar Vijayakumar
website --  www.srilakshmi.infoinyohyou
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Roy Smith
In article mailman.2069.1306324514.9059.python-l...@python.org,
 Chris Angelico ros...@gmail.com wrote:

 On Wed, May 25, 2011 at 9:36 PM, Roy Smith r...@panix.com wrote:
  Remembering that I, J, K, L, M, and N were integer was trivial if you
  came from a math background.  And, of course, Fortran was all about
  math, so that was natural.  Those letters are commonly used for integers
  in formulae.  If I write $ x sub i $, anybody who knows math would
  immediately assume that the range of x was reals and the range of i was
  integers.
 
 When I studied maths, x and y were reals, and i wasn't. But it wasn't
 integer either... :)

I was talking of i in the context of a variable, not as a constant.  If 
I write $ 3 + 7i $ in one place and $ x sub i $ in another, most people 
will figure out from the context which is which.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner needs advice

2011-05-25 Thread Colin J. Williams

On 25-May-11 02:22 AM, Lew Schwartz wrote:

So, if I read between the lines correctly, you recommend Python 3? Does
the windows version install with a development environment?



It would be safer to stick with Python 2.7 initially and then consider 
the transition to 3.2 later.


No, there is not more than Idle.

PyScripter provides an excellent development environment.  See: 
http://en.wikipedia.org/wiki/PyScripter


Colin W.

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


Newbie string questions

2011-05-25 Thread Matty Sarro
Hey everyone,
This is a super noob question, so please be gentle.
I am working my way through Learn Python the Hard Way using both
python 2.7 and python 3.1 (I want to get a handle on the differences
between the two - the intention to write things in python 3 but be
able to understand things from python 2).

The first quarter or so of the book details lots of stuff about
strings. Most of the learning is by doing, with less of an emphasis on
the theory behind what certain things actually do. The issue is, I
can't seem to find some of the items in the documentation. Right now
what is stumping me... what exactly does %r do? I can't find it in the
documentation anywhere.
-Matty
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie string questions

2011-05-25 Thread Chris Angelico
On Wed, May 25, 2011 at 11:06 PM, Matty Sarro msa...@gmail.com wrote:
 Right now what is stumping me... what exactly does %r do?

You're talking about the formatting operator? It's like the repr function:

http://docs.python.org/library/functions.html#repr

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


Re: Newbie string questions

2011-05-25 Thread Chris Guidry
On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote:
 can't seem to find some of the items in the documentation. Right now
 what is stumping me... what exactly does %r do? I can't find it in the
 documentation anywhere.

Matty, %r in a format string is very much like %s.  %s calls str(your_object) 
in order to produce the resulting string.  %r calls repr(your_object).  
Generally, you'd want to use %s for strings that will surface to a user, while 
%r is great for debugging and logging.

Also, if you haven't come across repr(), you should be able to find that in the 
docs; it's also considered good practice to overload repr() in your own classes 
in order to provide a useful representation for your objects.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie string questions

2011-05-25 Thread Matty Sarro
Thanks guys! I appreciate it. I was wondering why %r was always
showing things enclosed in single-quotes.

On Wed, May 25, 2011 at 9:13 AM, Chris Guidry ch...@theguidrys.us wrote:
 On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote:
 can't seem to find some of the items in the documentation. Right now
 what is stumping me... what exactly does %r do? I can't find it in the
 documentation anywhere.

 Matty, %r in a format string is very much like %s.  %s calls str(your_object) 
 in order to produce the resulting string.  %r calls repr(your_object).  
 Generally, you'd want to use %s for strings that will surface to a user, 
 while %r is great for debugging and logging.

 Also, if you haven't come across repr(), you should be able to find that in 
 the docs; it's also considered good practice to overload repr() in your own 
 classes in order to provide a useful representation for your objects.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


FW: python

2011-05-25 Thread Shawnta Henman
python
We should take a look at how this latest good fortune is going to change your 
lifestyle. Don't you remember all of those times I said how hard it's been just 
to get by? Alright you know what?,  Your computer is going to be your very best 
pal once you try out this thing for one month's time.  There's really no way in 
hell I'd wind up where I am these days if it all wasn't for this.  You can give 
thanks to me soon.  The couple of people I sometimes will need to deal with 
help to make everything far more easy on me that I couldn't have this another 
way.  I can't wait to meet you once again and show you lots more. If you fail 
to build an income with this method, you're probably stupid. I'm sorry if that 
offends you, but I recognize you're capable and this is extremely straight 
forward! http://jesus21news.com Right here is the chance of your life. When 
you're ready to transform your way of life around, I'm going to be right here 
to assist. So whaddaya think, python, think you're prepared for a change?
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to make ironpython run in browser with silverlight

2011-05-25 Thread ErichCart ErichCart
Here is how it looks on free webhosting account:

http://silverlighttest.zzl.org/silverlighttest.html

It is supposed to show a window with Hello from python, but it shows
smth else completely.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code Review

2011-05-25 Thread ad
On May 25, 4:06 am, Ulrich Eckhardt ulrich.eckha...@dominolaser.com
wrote:
 ad wrote:
  Please review the code pasted below. I am wondering what other ways
  there are of performing the same tasks.

 On a unix system, you would call find with according arguments and then
 handle the found files with -exec rm ... or something like that, but I see
 you are on MS Windows.

  args = parser.parse_args()

  dictKeys = (vars(args))

 The first of these looks okay, while I don't get the additional brackets in
 the second one. Another habit I observe here is the Hungarian notation of
 prefixing the type to the name and using camelCaps. PEP 8 (IIRC) has
 something to say on the preferred naming. I'm not 100% against encoding the
 type in the variable name in Python, since it lacks static type checking, I
 would have chosen key_dict here though, or, due to the small size of the
 overall program just keys.

  print (HowManyDays)

 This puzzled me at first, again the useless additional brackets I thought.
 However, in Python 3, print is a function, so that is correct. Still, it
 should be print(foo) not print (foo).

  for files in DirListing:

      # Get the absolute path of the file name
      abspath = (os.path.join(WhatDirectory, files))

 files is just the name of a single file, right? In that case the name is a
 bit confusing.

      # Get the date from seven days ago
      WeekOldFileDate = CurrentTime - DaysToDelete

 You are repeating this calculation for every file in the loop.

      if FileCreationTime  WeekOldFileDate:
          #check if the object is a file
          if os.path.isfile(abspath): os.remove(abspath)
          # It is not a file it is a directory
          elif os.path.isdir(abspath): shutil.rmtree(abspath)

 I'm not sure, but I believe you could use shutil.rmtree() for both files and
 directories. In any case, be prepared for the file still being open or
 otherwise read-only, i.e. for having to handle errors.

 Also, what if a directory is old but the content is new? Would this cause
 the non-old content to be deleted?

 Cheers!

 Uli

 --
 Domino Laser GmbH
 Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Thank you guys very much for the excellent points. I will use this
information as a reference as I write more code and fix up the
existing script.

Chris, thank you for putting so much time into your post!

Until we type again...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did Quora choose Python for its development?

2011-05-25 Thread D'Arcy J.M. Cain
On Wed, 25 May 2011 07:36:40 -0400
Roy Smith r...@panix.com wrote:
 Remembering that I, J, K, L, M, and N were integer was trivial if you 
 came from a math background.  And, of course, Fortran was all about 

The easiest way to remember was that the first two letters of INteger
gave you the range.

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Chris Angelico
On Thu, May 26, 2011 at 12:23 AM, D'Arcy J.M. Cain da...@druid.net wrote:
 The easiest way to remember was that the first two letters of INteger
 gave you the range.


G for Green and R for Right, which are the first two letters of Green.

(I wonder how many Pythonistas are familiar with that?)

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


Re: Code Review

2011-05-25 Thread Iain King
On May 25, 2:44 pm, ad adsquai...@gmail.com wrote:
 On May 25, 4:06 am, Ulrich Eckhardt ulrich.eckha...@dominolaser.com
 wrote:



  ad wrote:
   Please review the code pasted below. I am wondering what other ways
   there are of performing the same tasks.

  On a unix system, you would call find with according arguments and then
  handle the found files with -exec rm ... or something like that, but I see
  you are on MS Windows.

   args = parser.parse_args()

   dictKeys = (vars(args))

  The first of these looks okay, while I don't get the additional brackets in
  the second one. Another habit I observe here is the Hungarian notation of
  prefixing the type to the name and using camelCaps. PEP 8 (IIRC) has
  something to say on the preferred naming. I'm not 100% against encoding the
  type in the variable name in Python, since it lacks static type checking, I
  would have chosen key_dict here though, or, due to the small size of the
  overall program just keys.

   print (HowManyDays)

  This puzzled me at first, again the useless additional brackets I thought.
  However, in Python 3, print is a function, so that is correct. Still, it
  should be print(foo) not print (foo).

   for files in DirListing:

       # Get the absolute path of the file name
       abspath = (os.path.join(WhatDirectory, files))

  files is just the name of a single file, right? In that case the name is a
  bit confusing.

       # Get the date from seven days ago
       WeekOldFileDate = CurrentTime - DaysToDelete

  You are repeating this calculation for every file in the loop.

       if FileCreationTime  WeekOldFileDate:
           #check if the object is a file
           if os.path.isfile(abspath): os.remove(abspath)
           # It is not a file it is a directory
           elif os.path.isdir(abspath): shutil.rmtree(abspath)

  I'm not sure, but I believe you could use shutil.rmtree() for both files and
  directories. In any case, be prepared for the file still being open or
  otherwise read-only, i.e. for having to handle errors.

  Also, what if a directory is old but the content is new? Would this cause
  the non-old content to be deleted?

  Cheers!

  Uli

  --
  Domino Laser GmbH
  Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

 Thank you guys very much for the excellent points. I will use this
 information as a reference as I write more code and fix up the
 existing script.

 Chris, thank you for putting so much time into your post!

 Until we type again...


Wrote something to do the same basic thing a little while ago.  Less
verbose than yours, and it only does files, not folders.  If I was
going to do folders though, I'd do them by recursing into them and
pruning files, and not go by the folder modify date, which I don't
think changes the way you think it changes (for example, if a file
inside a folder got updated such that it shouln't be deleted it still
will be with your code if the folder modify date is old [this is on
Windows])

import os, glob, time, sys

if len(sys.argv)  3:
print USAGE: %s PATTERN DAYS % sys.argv[0]
sys.exit(1)

pattern = sys.argv[1]
days = int(sys.argv[2])
threshold = days * 24 * 60 * 60
t = time.time()

for f in glob.glob(pattern):
if t - os.stat(f)[9]  threshold:
print f
os.remove(f)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Steven D'Aprano
On Wed, 25 May 2011 10:23:59 -0400, D'Arcy J.M. Cain wrote:

 On Wed, 25 May 2011 07:36:40 -0400
 Roy Smith r...@panix.com wrote:
 Remembering that I, J, K, L, M, and N were integer was trivial if you
 came from a math background.  And, of course, Fortran was all about
 
 The easiest way to remember was that the first two letters of INteger
 gave you the range.

Huh. I never knew that. I just learned from use that I, J, K, M and N 
were traditionally integers. I never used L for an integer variable, and 
don't know anyone who does.

I for integer is obvious. If you need a second one, you use the next 
letter J, and if you need a third, the one after that, K. If you need 
four, you're probably doing something wrong.

Likewise, N for number (as in, *counting* number). If you need two, using 
N and O is stupid, because O can be confused with 0, so you go backwards 
and use M.

However, using P and Q for integers is merely arbitrary convention.



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


Kind of OT - Books on software development?

2011-05-25 Thread Matty Sarro
Hey everyone,
I am looking at some projects coming up, which may or may not involve
python. So I figured I would throw the question out there and see what
everyone thinks.
I am looking for some books on software engineering/development...
something that discusses techniques from ideation, up through testing,
QA, production, and then maintenance. Is there such a book?
-Matthew
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Matty Sarro
I hate using L for anything, namely because if you type it lowercase
you always have to wonder if its an l or a 1 in a terminal window.
-Matthew

On Wed, May 25, 2011 at 10:56 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 On Wed, 25 May 2011 10:23:59 -0400, D'Arcy J.M. Cain wrote:

 On Wed, 25 May 2011 07:36:40 -0400
 Roy Smith r...@panix.com wrote:
 Remembering that I, J, K, L, M, and N were integer was trivial if you
 came from a math background.  And, of course, Fortran was all about

 The easiest way to remember was that the first two letters of INteger
 gave you the range.

 Huh. I never knew that. I just learned from use that I, J, K, M and N
 were traditionally integers. I never used L for an integer variable, and
 don't know anyone who does.

 I for integer is obvious. If you need a second one, you use the next
 letter J, and if you need a third, the one after that, K. If you need
 four, you're probably doing something wrong.

 Likewise, N for number (as in, *counting* number). If you need two, using
 N and O is stupid, because O can be confused with 0, so you go backwards
 and use M.

 However, using P and Q for integers is merely arbitrary convention.



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

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


Re: Kind of OT - Books on software development?

2011-05-25 Thread Ed Keith
I do not have my library with me, but I remember a book that fits the bill 
exactly, is was from Microsoft Press, I think it was called Writing Solid Code

Hope this helps,

   -EdK

Ed Keith
e_...@yahoo.com

Blog: edkeith.blogspot.com


--- On Wed, 5/25/11, Matty Sarro msa...@gmail.com wrote:

 From: Matty Sarro msa...@gmail.com
 Subject: Kind of OT - Books on software development?
 To: Python list python-list@python.org
 Date: Wednesday, May 25, 2011, 11:40 AM
 Hey everyone,
 I am looking at some projects coming up, which may or may
 not involve
 python. So I figured I would throw the question out there
 and see what
 everyone thinks.
 I am looking for some books on software
 engineering/development...
 something that discusses techniques from ideation, up
 through testing,
 QA, production, and then maintenance. Is there such a
 book?
 -Matthew
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kind of OT - Books on software development?

2011-05-25 Thread gregarican
On May 25, 11:45 am, Ed Keith e_...@yahoo.com wrote:
 I do not have my library with me, but I remember a book that fits the bill 
 exactly, is was from Microsoft Press, I think it was called Writing Solid 
 Code

 Hope this helps,

    -EdK

 Ed Keith
 e_...@yahoo.com

 Blog: edkeith.blogspot.com

 --- On Wed, 5/25/11, Matty Sarro msa...@gmail.com wrote:



  From: Matty Sarro msa...@gmail.com
  Subject: Kind of OT - Books on software development?
  To: Python list python-l...@python.org
  Date: Wednesday, May 25, 2011, 11:40 AM
  Hey everyone,
  I am looking at some projects coming up, which may or may
  not involve
  python. So I figured I would throw the question out there
  and see what
  everyone thinks.
  I am looking for some books on software
  engineering/development...
  something that discusses techniques from ideation, up
  through testing,
  QA, production, and then maintenance. Is there such a
  book?
  -Matthew
  --
 http://mail.python.org/mailman/listinfo/python-list- Hide quoted text -

 - Show quoted text -

If you are talking about general concepts in efficient, effective OO
programming I'd suggest Smalltalk Best Practice Patterns by Kent
Beck. I've developed in Java, C#, Python, Ruby, Smalltalk, and other
languages and this book is an eye opener!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kind of OT - Books on software development?

2011-05-25 Thread Verde Denim
Hey everyone,
I am looking at some projects coming up, which may or may not involve
python. So I figured I would throw the question out there and see what
everyone thinks.
I am looking for some books on software engineering/development...
something that discusses techniques from ideation, up through testing,
QA, production, and then maintenance. Is there such a book?
-Matthew

On Wed, May 25, 2011 at 11:45 AM, Ed Keith e_...@yahoo.com wrote:

 I do not have my library with me, but I remember a book that fits the bill
 exactly, is was from Microsoft Press, I think it was called Writing Solid
 Code


Matt -

Roger Pressman - Software Engineering, A Practicioner's Approach is a good
one.
Donald E. Knuth. - The Art of Computer Programming (5 Volumes) -
http://www-cs-faculty.stanford.edu/~uno/taocp.html
Horowitz - Fundamentals of Computer Algorithms
Dowd, Macdonald, Shuh - The Art of Software Security Assessments

Good Basic Reference Library for engineering, designing, writing, and
SECURING code. I've got lots more titles on various aspects of engineering
and OOA/OOD construction, design methods, etc., but these are (imo) a good
foundation.

Regards

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


Re: pyGTK identify a button

2011-05-25 Thread Cousin Stanley
Tracubik wrote:

 Hi all,
 i'm trying to write a simple windows with two button in GTK, 
 i need a  way to identify wich button is pressed.
 

#!/usr/bin/env python

import gtk

def console_display( button , args ) :

a0 , a1 , a2 = args

print '%s  %s %s ' % ( a0 , a1 , a2 )


window = gtk.Window()

window.set_title( gtk.buttons.01 )
  
window.set_size_request( 300 , -1 )

window.set_position( gtk.WIN_POS_CENTER )

window.connect( destroy , gtk.main_quit )


# Create VBox and add in Window

vbox = gtk.VBox()

window.add( vbox )


# Create buttons

dict_buttons = {
12   :  [ 'OneTwo' , 'Buckle ' , 'My Shoe' ] ,
34   :  [ 'TreFor' , 'Shut   ' , 'The Door' ] ,
56   :  [ 'FivSix' , 'Pick   ' , 'Up Sticks' ] ,
78   :  [ 'SvnAte' , 'Lay' , 'Them Straight' ] ,
910  :  [ 'NinTen' , 'Big' , 'Fat Hen' ] }

list_keys = dict_buttons.keys()

list_keys.sort()

for this_button in list_keys :

this_name = dict_buttons[ this_button ][ 0 ]

b = gtk.Button( this_name )

b.set_name( this_name )

b.connect( clicked , console_display , dict_buttons[ this_button ] )

vbox.pack_start( b )


window.show_all()

gtk.main()


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Terry Reedy

On 5/25/2011 8:01 AM, John Bokma wrote:


to. Like I already stated before: if Python is really so much better
than Python readability wise, why do I have such a hard time dropping
Perl and moving on?


[you meant 'than Perl'] You are one of the people whose brain fits Perl 
(or vice versa) better than most. So enjoy it. Ignore anyone who says 
otherwise.


--
Terry Jan Reedy

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Ethan Furman

Terry Reedy wrote:

On 5/25/2011 8:01 AM, John Bokma wrote:


to. Like I already stated before: if Python is really so much better
than Python readability wise, why do I have such a hard time dropping
Perl and moving on?


[you meant 'than Perl'] You are one of the people whose brain fits Perl 
(or vice versa) better than most. So enjoy it. Ignore anyone who says 
otherwise.


+1

If everybody's brain worked the same, we wouldn't have so many different 
languages to choose from.


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


Re: Kind of OT - Books on software development?

2011-05-25 Thread Ed Keith
--- On Wed, 5/25/11, Ed Keith e_...@yahoo.com wrote:

 I do not have my library with me, but
 I remember a book that fits the bill exactly, is was from
 Microsoft Press, I think it was called Writing Solid Code

I have done some research at amazon.com, and while Writing Solid Code is an 
excellent book that I would also recommend highly, the book I was thinking of 
was Code Complete.

   -EdK

Ed Keith
e_...@yahoo.com

Blog: edkeith.blogspot.com


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


super() in class defs?

2011-05-25 Thread Jess Austin
I may be attempting something improper here, but maybe I'm just going
about it the wrong way. I'm subclassing
http.server.CGIHTTPRequestHandler, and I'm using a decorator to add
functionality to several overridden methods.

def do_decorate(func):
.   def wrapper(self):
.   if appropriate():
.   return func()
.   complain_about_error()
.   return wrapper

class myHandler(CGIHTTPRequestHandler):
.   @do_decorate
.   def do_GET(self):
.   return super().do_GET()
.   # also override do_HEAD and do_POST

My first thought was that I could just replace that whole method
definition with one line:

class myHandler(CGIHTTPRequestHandler):
.   do_GET = do_decorate(super().do_GET)

That generates the following error:

SystemError: super(): __class__ cell not found

So I guess that when super() is called in the context of a class def
rather than that of a method def, it doesn't have the information it
needs. Now I'll probably just say:

do_GET = do_decorate(CGIHTTPRequestHandler.do_GET)

but I wonder if there is a correct way to do this instead? Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Cherrypy

2011-05-25 Thread Bryton
Is anyone having a step by step tutorial of cherrypy(or book title).I 
have used the tutorial in their site as well as the book (cherrypy 
essentials) and I would like to have a one that is a bit more step by 
step...Please help...


--
Regards,
Bryton.

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


Newbie question about SQLite + Python and twitter

2011-05-25 Thread Jayme Proni Filho
Helo guys,

I'm building a local application for twitter for my brother's store. I'm in
the beginning and I have some newbie problems, so:

I create a table called tb_messages with int auto increment and varchar(140)
fields;
I did three SQL funcionts, insert_tweet, delete_tweet, select_tweet

select_tweet is use for getting messages for sending them to twitter;

My problem is: How can i make my select_tweet works at the same time that
insert or delete funcions. I just got to work when I stop select function.

I would like to do my app works all the time.

---
Jayme Proni Filho
Skype: jaymeproni
Twitter: @jaymeproni
Phone: +55 - 17 - 3631 - 6576
Mobile: +55 - 17 - 9605 - 3560
e-Mail: jaymeproni at yahoo dot com dot br
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super() in class defs?

2011-05-25 Thread Ian Kelly
On Wed, May 25, 2011 at 11:54 AM, Jess Austin jess.aus...@gmail.com wrote:
 So I guess that when super() is called in the context of a class def
 rather than that of a method def, it doesn't have the information it
 needs. Now I'll probably just say:

    do_GET = do_decorate(CGIHTTPRequestHandler.do_GET)

 but I wonder if there is a correct way to do this instead? Thanks!

I would recommend against using super() in general.

http://fuhm.net/super-harmful/

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread John Bokma
Ethan Furman et...@stoneleaf.us writes:

 Terry Reedy wrote:
 On 5/25/2011 8:01 AM, John Bokma wrote:

 to. Like I already stated before: if Python is really so much better
 than Python readability wise, why do I have such a hard time dropping
 Perl and moving on?

 [you meant 'than Perl'] You are one of the people whose brain fits
 Perl (or vice versa) better than most. So enjoy it. Ignore anyone
 who says otherwise.

 +1

 If everybody's brain worked the same, we wouldn't have so many
 different languages to choose from.

So, this means that in general language readability is not as clear cut
as some seem to advertise ;-).

-- 
John Bokma   j3b

Blog: http://johnbokma.com/Perl Consultancy: http://castleamber.com/
Perl for books:http://johnbokma.com/perl/help-in-exchange-for-books.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread tkp...@hotmail.com
The following function that returns the last line of a file works
perfectly well under Python 2.71. but fails reliably under Python 3.2.
Is this a bug, or am I doing something wrong? Any help would be
greatly appreciated.


import os

def lastLine(filename):
'''
Returns the last line of a file
file.seek takes an optional 'whence' argument which allows you
to
start looking at the end, so you can just work back from there
till
you hit the first newline that has anything after it
Works perfectly under Python 2.7, but not under 3.2!
   '''
offset = -50
with open(filename) as f:
while offset  -1024:
offset *= 2
f.seek(offset, os.SEEK_END)
lines = f.readlines()
if len(lines)  1:
return lines[-1]

If I execute this with a valid filename fn. I get the following error
message:

 lastLine(fn)
Traceback (most recent call last):
  File pyshell#12, line 1, in module
lastLine(fn)
  File pyshell#11, line 13, in lastLine
f.seek(offset, os.SEEK_END)
io.UnsupportedOperation: can't do nonzero end-relative seeks

Sincerely

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


bdist_wininst: install_script not run on uninstall

2011-05-25 Thread Wilbert Berendsen
Hi,

according to the docs the installer bdist_wininst creates will run the 
install-script on install with -install (which works perfectly) and on 
uninstall with the -remove argument (which seemingly never happens).

However I want to cleanup some registry stuff on uninstall so I want the 
uninstall script to work.

Studying the source code of the installer[1] in the Run_RemoveScript 
function...

[1] http://svn.python.org/view/python/trunk/PC/bdist_wininst/install.c

... it checks for the line '%d Run Script: %s' in the log, which is there. But 
can anybody find out why the install script is not run?

with best regards,
Wilbert Berendsen

-- 
http://www.wilbertberendsen.nl/
You must be the change you wish to see in the world.
-- Mahatma Gandhi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread MRAB

On 25/05/2011 20:33, tkp...@hotmail.com wrote:

The following function that returns the last line of a file works
perfectly well under Python 2.71. but fails reliably under Python 3.2.
Is this a bug, or am I doing something wrong? Any help would be
greatly appreciated.


import os

def lastLine(filename):
 '''
 Returns the last line of a file
 file.seek takes an optional 'whence' argument which allows you
to
 start looking at the end, so you can just work back from there
till
 you hit the first newline that has anything after it
 Works perfectly under Python 2.7, but not under 3.2!
'''
 offset = -50
 with open(filename) as f:
 while offset  -1024:
 offset *= 2
 f.seek(offset, os.SEEK_END)
 lines = f.readlines()
 if len(lines)  1:
 return lines[-1]

If I execute this with a valid filename fn. I get the following error
message:


lastLine(fn)

Traceback (most recent call last):
   File pyshell#12, line 1, inmodule
 lastLine(fn)
   File pyshell#11, line 13, in lastLine
 f.seek(offset, os.SEEK_END)
io.UnsupportedOperation: can't do nonzero end-relative seeks


You're opening the file in text mode, and seeking relative to the end
of the file is not allowed in text mode, presumably because the file
contents have to be decoded, and, in general, seeking to an arbitrary
position within a sequence of encoded bytes can have undefined results
when you attempt to decode to Unicode starting from that position.

The strange thing is that you _are_ allowed to seek relative to the
start of the file.

Try opening the file in binary mode and do the decoding yourself,
catching the DecodeError exceptions if/when they occur.
--
http://mail.python.org/mailman/listinfo/python-list


Re: super() in class defs?

2011-05-25 Thread Eric Snow
On Wed, May 25, 2011 at 12:31 PM, Ian Kelly ian.g.ke...@gmail.com wrote:

 On Wed, May 25, 2011 at 11:54 AM, Jess Austin jess.aus...@gmail.com
 wrote:
  So I guess that when super() is called in the context of a class def
  rather than that of a method def, it doesn't have the information it
  needs. Now I'll probably just say:
 
 do_GET = do_decorate(CGIHTTPRequestHandler.do_GET)
 
  but I wonder if there is a correct way to do this instead? Thanks!

 I would recommend against using super() in general.


That position is understandable.  However, super is fine for single
inheritance, and works fine in cooperative multiple inheritance.  You can
just as easily argue that multiple inheritance is more harmful than super
is.  If fact, I would generally recommend against using multiple inheritance
if you can avoid it (though it has its place).

Personally, I find super to make maintenance and refactoring easier, since I
don't have to fiddle with the base class name, or with passing self.

Cheers,

-eric


 http://fuhm.net/super-harmful/

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

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


Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread Ian Kelly
On Wed, May 25, 2011 at 2:00 PM, MRAB pyt...@mrabarnett.plus.com wrote:
 You're opening the file in text mode, and seeking relative to the end
 of the file is not allowed in text mode, presumably because the file
 contents have to be decoded, and, in general, seeking to an arbitrary
 position within a sequence of encoded bytes can have undefined results
 when you attempt to decode to Unicode starting from that position.

 The strange thing is that you _are_ allowed to seek relative to the
 start of the file.

I think that with text files seek() is only really meant to be called
with values returned from tell(), which may include the decoder state
in its return value.
-- 
http://mail.python.org/mailman/listinfo/python-list


using masks and numpy record arrays

2011-05-25 Thread Catherine Moroney

Hello,

I am trying to work with a structured array and a mask, and am 
encountering some problems.


For example:

 xtype = numpy.dtype([(n, numpy.int32), (x, numpy.float32)])
 a = numpy.zeros((4), dtype=xtype)
 b = numpy.arange(0,4)
 a2 = numpy.zeros((4), dtype=xtype)
 mask = numpy.where(b%2 == 0)
 a2[:][n] += b! this changes the values of a2
 a[mask][n] += b[mask]! this does not change the values of a
 a2
array([(0, 0.0), (1, 0.0), (2, 0.0), (3, 0.0)],
  dtype=[('n', 'i4'), ('x', 'f4')])
 a
array([(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)],
  dtype=[('n', 'i4'), ('x', 'f4')])

Why do the values of a2 get updated, and yet the values of a do not?
How do I update a's contents using a mask?

If a is not a record array, but instead simply an array of ints, then
the a[mask] += b[mask] statement does alter the values of a.

 a = numpy.zeros((4))
 a[mask] += b[mask]
 a
array([ 0.,  0.,  2.,  0.])

What is it about a numpy record array that prevents the mask statement
from working, and how do I get around this?

Thanks,

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Matty Sarro
On Wed, May 25, 2011 at 3:14 PM, John Bokma j...@castleamber.com wrote:
 Ethan Furman et...@stoneleaf.us writes:

 Terry Reedy wrote:
 On 5/25/2011 8:01 AM, John Bokma wrote:

 to. Like I already stated before: if Python is really so much better
 than Python readability wise, why do I have such a hard time dropping
 Perl and moving on?

 [you meant 'than Perl'] You are one of the people whose brain fits
 Perl (or vice versa) better than most. So enjoy it. Ignore anyone
 who says otherwise.

 +1

 If everybody's brain worked the same, we wouldn't have so many
 different languages to choose from.

 So, this means that in general language readability is not as clear cut
 as some seem to advertise ;-).

 --
 John Bokma                                                               j3b

 Blog: http://johnbokma.com/        Perl Consultancy: http://castleamber.com/
 Perl for books:    http://johnbokma.com/perl/help-in-exchange-for-books.html
 --
 http://mail.python.org/mailman/listinfo/python-list


General readability is a farce. If it was true we would only have one
section to the library. Different people enjoy reading, and can
comprehend better in different ways. THat's why some people are super
verbose - hell, just look at this here post! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using masks and numpy record arrays

2011-05-25 Thread Robert Kern

On 5/25/11 3:27 PM, Catherine Moroney wrote:

Hello,

I am trying to work with a structured array and a mask, and am encountering some
problems.


You will want to ask numpy questions on the numpy mailing list:

  http://www.scipy.org/Mailing_Lists


For example:

  xtype = numpy.dtype([(n, numpy.int32), (x, numpy.float32)])
  a = numpy.zeros((4), dtype=xtype)
  b = numpy.arange(0,4)
  a2 = numpy.zeros((4), dtype=xtype)
  mask = numpy.where(b%2 == 0)
  a2[:][n] += b ! this changes the values of a2
  a[mask][n] += b[mask] ! this does not change the values of a
  a2
array([(0, 0.0), (1, 0.0), (2, 0.0), (3, 0.0)],
dtype=[('n', 'i4'), ('x', 'f4')])
  a
array([(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)],
dtype=[('n', 'i4'), ('x', 'f4')])

Why do the values of a2 get updated, and yet the values of a do not?


Only the final [] on the left-hand side of the assignment actually turns into a 
.__setitem__() call to the object that is the result of the expression to its 
left. a[mask] makes a copy while a2[:] makes a view.


You could do

  a[n][mask] += b[mask]

since a[n] will also make a view and the .__setitem__() on it will propagate 
back to the original memory.


--
Robert Kern

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

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread theg...@nospam.net

On 5/24/2011 1:39 PM, D'Arcy J.M. Cain wrote:
[snip]

One of my favorite quotes (not sure if it was about Perl or APL) is I
refuse to use a programming language where the proponents of it stick
snippets under each other's nose and say 'I bet you can't guess what
this does.'

I dunno. That sounds about like how most programming course
exams are written, no?
The point is that puzzling through arcane bits of code are crucial to 
learning

any language. It's a valuable exercise.

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


Re: super() in class defs?

2011-05-25 Thread Steven D'Aprano
On Wed, 25 May 2011 12:31:33 -0600, Ian Kelly wrote:

 I would recommend against using super() in general.
 
 http://fuhm.net/super-harmful/

If you actually read that article, carefully, without being fooled by the 
author's provocative ex-title and misleading rhetoric, you will discover 
that super is not harmful. What is harmful is making unjustified 
assumptions about what super does, and about the code you are calling, 
and hence misusing super.

You have to read all the way to the bottom of the article to see the 
author say in the TODO section:

Give some examples of why super really is necessary sometimes

Even before that, you will read why *not* using super often fails badly. 
If James Knight, the author, is correct that super is harmful, it seems 
that you're in trouble because *not using super* is also harmful.

If you search the mailing lists of python-...@python.org, you will find a 
debate between James and Guido van Russum where James eventually 
acknowledges that he is wrong to call super harmful. There's a reason 
that he has changed the title of the page from Python's Super Considered 
Harmful to the damning-with-faint-praise Python's Super is nifty, but 
you can't use it. 

The new title is also *simply wrong*, because you can use it. James even 
tells you what you need to do to use it correctly.

The truth is that for multiple inheritance, you better be using super or 
your code is probably buggy (unless you manually duplicate what super 
does for you). And for single inheritance, it makes no difference whether 
you use super or not.



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


Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread MRAB

On 25/05/2011 21:54, Ian Kelly wrote:

On Wed, May 25, 2011 at 2:00 PM, MRABpyt...@mrabarnett.plus.com  wrote:

You're opening the file in text mode, and seeking relative to the end
of the file is not allowed in text mode, presumably because the file
contents have to be decoded, and, in general, seeking to an arbitrary
position within a sequence of encoded bytes can have undefined results
when you attempt to decode to Unicode starting from that position.

The strange thing is that you _are_ allowed to seek relative to the
start of the file.


I think that with text files seek() is only really meant to be called
with values returned from tell(), which may include the decoder state
in its return value.


What do you mean by may include the decoder state in its return value?

It does make sense that the values returned from tell() won't be in the
middle of an encoded sequence of bytes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: English Idiom in Unix: Directory Recursively

2011-05-25 Thread Steven D'Aprano
On Wed, 25 May 2011 09:26:11 +0200, Thorsten Kampe wrote:

 Naming something in the terms of its implementation details (in this
 case recursion) is a classical WTF.

*If* that's true, it certainly doesn't seem to apply to real-world 
objects. Think about the exceptions:

microwave oven
vacuum cleaner
oven fries
electric car
chain saw
flintlock rifle
air gun
vulcanised rubber
kerosene heater
aluminium foil
diamond saw
gas stove
wood stove
four-wheel drive car
incandescent light bulb
electric razor
unleaded petrol

to mention only a few.

Naming the thing after the implementation would often seem to be *good 
advice*, not bad. We often do care about implementations. You really do 
need to know whether the car you drive uses leaded or unleaded.

Being able to swap implementations without changing the interface is an 
abstraction that doesn't apply all the time, in either code or real life.




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


Re: English Idiom in Unix: Directory Recursively

2011-05-25 Thread Steven D'Aprano
On Wed, 25 May 2011 00:06:06 +0200, Rikishi42 wrote:

 On 2011-05-24, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info
 wrote:
 I think that is a patronizing remark that under-estimates the
 intelligence of lay people and over-estimates the difficulty of
 understanding recursion.
 
 Why would you presume this to be related to intelligence? The point
 was not about being *able* to understand, but about *needing* to
 understand in order to use.

 Maybe they don't need to understand recursion. So what?
 
 I think you should read the earlier posts again, this is drifting so far
 from what I intended.
 
 What I mean is: I'm certain that over the years I've had more than one
 person come to me and ask what 'Do you wish to delete this directory
 recursively?' meant. BAut never have I been asked to explain what 'Do
 you wish to delete this directory and it's subdirs/with all it's
 contents?' meant. Never.

I know many people who have no idea what a directory is, let alone a 
subdirectory, unless it's the phone directory. They're non-computer 
users. Once they start using computers, they quickly work out what the 
word means in context, or they ask and get told, and then they've learned 
a new word and never need ask again. This is a good thing.

The idiom of recursively delete is no different. Of course some people 
will have to learn a new term in order to make sense of it. So what?


 Do you know many people who incinerate leaves and branches in their
 garden? I burn them.

I know many people who incinerate leaves in an incinerator. Or at least 
they used to, until the government here banned it. It might only have 
been a 44 gallon drum with holes punched in the side, but they still 
called it an incinerator.

I learned that word from my father, who left school at 14 to work in a 
shoe shop. He isn't especially educated, doesn't read much beyond the 
daily tabloid, and thinks Benny Hill is the height of wit. But he's not 
an idiot and even at 72 is capable of learning new words.


 Do they need to know the words microwave oven when they could be
 saying invisible rays cooking thing?
 
 The word oven has existed for ages, microwave is just a name for the
 type of oven. Not even a description, just a name.

Why do you think they're called microwave ovens instead of fizzbaz 
ovens? Could it possibly have something to do with the fact that they 
cook with microwaves?

So not actually just a name at all. It's a jargon description of the 
implementation of the oven.


 I wonder whether physicists insist that cars should have a go faster
 pedal because ordinary people don't need to understand Newton's Laws
 of Motion in order to drive cars?
 
 Gas pedal. Pedal was allraedy known when the car was invented. The
 simple addition of gas solved that need. 

What's a gas pedal? Is that some strange American term for what most of 
the English-speaking world knows as the accelerator? *wink*


 Oh, and it's break pedal, not descellarator. (sp?)

That would be brake, and decelerator.


 Who are you to say that people shouldn't be exposed to words you deem
 that they don't need to know?
 
 I'm one of the 'people'. You say exposed to, I say bothered/bored with.

You can't force people to learn new words, although you would be 
surprised how even the most disinterested, lazy speaker manages to pick 
up vocabulary without even being aware of it.

But nor do you have to pander to the slackers. They can learn the word, 
or not, I don't care. If I'm writing for an audience of children, or 
English as a second language, or the otherwise linguistically challenged, 
I'll simplify my vocabulary appropriately. For everyone else, I'll use an 
ordinary adult vocabulary, and that includes the word recursion or 
recursive. It's hardly technical jargon -- I've found a discussion of 
gangsta rap that uses it. Even children understand the concept of 
recursion (self-reference). People put it in comedies like Blazing 
Saddles and Space Balls! How difficult is it to put a name to the concept?


 I have nothing against the use of a proper, precise term. And that word
 can be a complex one with many, many sylables (seems to add value,
 somehow).
 
 But I'm not an academic, so I don't admire the pedantic use of terms
 that need to be explained to 'lay' people.

Pedantic... that's another one of those academic words that need to be 
explained to lay people, isn't it? As is academic itself, and in fact 
lay people. Who uses lay people in conversation?

Conversation -- another one of those four syllable words that should be 
avoided, since we have talk. I don't remember that last time I've heard 
Bazza or Jimbo say I was on the Internet having a conversation on 
Jabber, do you?

Oh, actually I do. So much for that argument.


 widespread, usually shorter and much simpler one for it. A pointless
 effort if pointless, even when comming from a physicist.  :-)

I think you *grossly* underestimate how many words people know, 
particularly if you include 

Re: Why did Quora choose Python for its development?

2011-05-25 Thread Steven D'Aprano
On Wed, 25 May 2011 07:01:07 -0500, John Bokma wrote:

 if Python is really so much better than Python [Perl] 
 readability wise, why do I have such a hard time dropping
 Perl and moving on?

My guess is that you have an adversarial view of computer languages, 
therefore after investing so much time and energy and, most importantly, 
self-image into becoming a Perl programmer, dropping it and moving on 
would be tantamount to admitting to yourself that you were wrong to 
have wasted so many years on the wrong language.

Whether it is objectively wrong or not rarely enters into these things.

That *you personally* can't or won't let go of Perl says nothing about 
the relative readability of Perl and Python code.


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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Steven D'Aprano
On Wed, 25 May 2011 08:01:38 +1000, Chris Angelico wrote:

 On Wed, May 25, 2011 at 3:39 AM, D'Arcy J.M. Cain da...@druid.net
 wrote:

 When I first looked at Perl it looked like line noise.  When I first
 looked at Python it looked like pseudo-code.
 
 When I first looked at assembly language it looked like random junk left
 behind in memory. When I first looked at COBOL it looked like ... COBOL.
 Doesn't make either of them better or worse.

Er, yes it does.

Writing code is primarily for *human readers*. Once you've compiled the 
code once, the computer never need look at it again, but human being come 
back to read it over and over again, to learn from it, or for 
maintenance. We rightfully value our own time and convenience as more 
valuable than that of the computer's, which is why we use programming 
languages at all, instead of having custom-made hardware built for every 
task we want the computer to do: 

I have to rename a file before August 2015, but the rename itself needs 
to be done in under a picosecond. Know any bespoke chip manufacturers who 
do small runs?

From that perspective, COBOL is an improvement on assembly, which is why 
there are probably still more COBOL programmers around than people who 
work exclusively on assembly.

Sometimes we compromise, or even subvert, that trade-off: for speed 
critical code where we do care more about the computer's time than our 
own, or for esoteric languages designed to be as hard to read as 
possible. My personal favourites, Oook and Whitespace.

But generally, people spend more time reading code than writing it, 
therefore we should weigh ease of reading higher than ease of 
writing. (My guess is, the weights should be about 5:1.)


 Pseudo-code is not a viable language for a computer to parse, 

Only because pseudo-code implies that the code is ambiguous or 
otherwise cannot be parsed. If it could be, it wouldn't be *pseudo*, it 
would be real code (possibly for some compiler that hasn't been written 
yet).


 but it's a
 good language for scribbling down comments in. That doesn't necessarily
 mean that a programming language that's closer to pseudo-code is good.

That depends on the nature of pseudo-code. Pseudo-assembly has all the 
disadvantages of assembly with none of the advantages, i.e. it doesn't 
actually work. So in that sense, pseudo-code is not necessarily a good 
thing nor a bad thing.

But in general conversation, pseudo-code is usually implied to mean that 
the language is as close to human language as you can make it, while 
still be parsable by a compiler.


 And verbosity doesn't necessarily equate to quality; for instance, when
 I'm working in both Python and PHP, I find it FAR tidier to use Python's
 {1:2,3:4] notation than PHP's array(1=2,3=4) - but on the flip side, I
 would prefer to have program structure defined by keywords like if and
 while than obscure random line noise. (Fortunately, most sane
 languages do indeed use keywords there.)

True. That's one of the limitations of the xtalk family of languages 
derived from Apple's (defunct) Hypertalk: it's awfully verbose, which is 
good for newbies but not quite so good for experts.



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


Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread tkp...@hotmail.com
Thanks for the guidance - it was indeed an issue with reading in
binary vs. text., and I do now succeed in reading the last line,
except that I now seem unable to split it, as I demonstrate below.
Here's what I get when I read the last line in text mode using 2.7.1
and in binary mode using 3.2 respectively under IDLE:

2.7.1
Name31/12/2009  0   0   0

3.2
b'Name\t31/12/2009\t0\t0\t0\r\n'

if, under 2.7.1 I read the file in text mode and write
 x = lastLine(fn)
I can then cleanly split the line to get its contents
 x.split('\t')
['Name', '31/12/2009', '0', '0', '0\n']

but under 3.2, with its binary read, I get
 x.split('\t')
Traceback (most recent call last):
  File pyshell#26, line 1, in module
x.split('\t')
TypeError: Type str doesn't support the buffer API

If I remove the '\t', the split now works and I get a list of bytes
literals
 x.split()
[b'Name', b'31/12/2009', b'0', b'0', b'0']

Looking through the docs did not clarify my understanding of the
issue. Why can I not split on '\t' when reading in binary mode?

Sincerely

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


Re: super() in class defs?

2011-05-25 Thread Carl Banks
On Wednesday, May 25, 2011 10:54:11 AM UTC-7, Jess Austin wrote:
 I may be attempting something improper here, but maybe I'm just going
 about it the wrong way. I'm subclassing
 http.server.CGIHTTPRequestHandler, and I'm using a decorator to add
 functionality to several overridden methods.
 
 def do_decorate(func):
 .   def wrapper(self):
 .   if appropriate():
 .   return func()
 .   complain_about_error()
 .   return wrapper
 
 class myHandler(CGIHTTPRequestHandler):
 .   @do_decorate
 .   def do_GET(self):
 .   return super().do_GET()
 .   # also override do_HEAD and do_POST
 
 My first thought was that I could just replace that whole method
 definition with one line:
 
 class myHandler(CGIHTTPRequestHandler):
 .   do_GET = do_decorate(super().do_GET)
 
 That generates the following error:
 
 SystemError: super(): __class__ cell not found
 
 So I guess that when super() is called in the context of a class def
 rather than that of a method def, it doesn't have the information it
 needs.

Right.  Actually the class object itself doesn't even exist yet when super() is 
invoked.  (It won't be created until after the end of the class statement 
block.)

 Now I'll probably just say:
 
 do_GET = do_decorate(CGIHTTPRequestHandler.do_GET)
 
 but I wonder if there is a correct way to do this instead? Thanks!

Well, since the class object isn't created until after the end of the class 
statement block, it's impossible to invoke super() on the class from inside the 
block.  So there's only two ways to invoke super(): 1. like you did above, by 
calling it inside a method, and 2. call it beyond the end of the class 
statement, like this:

class myHandler(CGIHTTPRequestHandler):
pass

myHandler.do_GET = do_decorate(super(myHandler).do_GET)

I wouldn't call that correct, though.  (I'm not even sure it'll work, since I 
don't have Python 3 handy to test it, but as far as I can tell it will.)

It's just one of the quirks of Python's type system.

I don't agree with Ian's recommendation not to use super() in general, but I'd 
probably agree that one should stick to using it only in its intended way (to 
invoke base-class methods directly).


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


Re: super() in class defs?

2011-05-25 Thread Ian Kelly
On Wed, May 25, 2011 at 3:40 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 If you actually read that article, carefully, without being fooled by the
 author's provocative ex-title and misleading rhetoric, you will discover
 that super is not harmful. What is harmful is making unjustified
 assumptions about what super does, and about the code you are calling,
 and hence misusing super.

Yes.  As others have noted, the problem is really multiple
inheritance, not super.  Super can be a useful tool, but unless you
have taken some time to learn its intricacies, I think that it is best
avoided so that it is not misused.

 You have to read all the way to the bottom of the article to see the
 author say in the TODO section:

 Give some examples of why super really is necessary sometimes

 Even before that, you will read why *not* using super often fails badly.
 If James Knight, the author, is correct that super is harmful, it seems
 that you're in trouble because *not using super* is also harmful.

Essentially, super can fail when you use it inconsistently.  Not using
super can fail when you have a diamond inheritance situation, or when
you mix it with super.

In this case, the OP is using super while inheriting from
http.server.CGIHTTPServer, which does not use super, and so is
inconsistent.

 If you search the mailing lists of python-...@python.org, you will find a
 debate between James and Guido van Russum where James eventually
 acknowledges that he is wrong to call super harmful. There's a reason
 that he has changed the title of the page from Python's Super Considered
 Harmful to the damning-with-faint-praise Python's Super is nifty, but
 you can't use it.

Thanks.  I found this quote from James that pretty much sums up my
position perfectly:


This is where I'm coming from:
In my own code, it is very rare to have diamond inheritance structures.
And if there are, even more rare that both sides need to cooperatively
override a method. Given that, super has no necessary advantage. And it
has disadvantages.
- Backwards compatibility issues
- Going along with that, inadvertent mixing of paradigms (you have to
remember which classes you use super with and which you don't or your
code might have hard-to-find errors).
- Take your choice of: a) inability to add optional arguments to your
methods, or b) having to use *args, **kwargs on every method and call
super with those.
- Having to try/catch AttributeErrors from super if you use interfaces
instead of a base class to define the methods in use.


 The new title is also *simply wrong*, because you can use it. James even
 tells you what you need to do to use it correctly.

Yes, you need to fundamentally alter the structure of your code to
throw away any semblance of run-time argument checking by having every
method that might conceivably be cooperatively inherited take *args,
**kwargs.  You also need to take care to always call super from such
methods, even when it appears to be unnecessary.  And don't forget to
catch the AttributeError if the method is something other than __new__
or __init__ and the current class turns out to be the last one in the
MRO that has it.

In short, if you're using super and don't feel burdened by it, then
you're probably using it incorrectly.

 The truth is that for multiple inheritance, you better be using super or
 your code is probably buggy (unless you manually duplicate what super
 does for you).

No.  For diamond inheritance, you better be using super or your code
is probably buggy.  For typical diamond-less multiple inheritance,
super is both unnecessary and tricky to use correctly.

 And for single inheritance, it makes no difference whether
 you use super or not.

Right.  It's unnecessary, so why saddle yourself with it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread Ethan Furman

tkp...@hotmail.com wrote:

Thanks for the guidance - it was indeed an issue with reading in
binary vs. text., and I do now succeed in reading the last line,
except that I now seem unable to split it, as I demonstrate below.
Here's what I get when I read the last line in text mode using 2.7.1
and in binary mode using 3.2 respectively under IDLE:

3.2
b'Name\t31/12/2009\t0\t0\t0\r\n'

under 3.2, with its binary read, I get
-- x.split('\t')
Traceback (most recent call last):
  File pyshell#26, line 1, in module
x.split('\t')
TypeError: Type str doesn't support the buffer API


You are trying to split a bytes object with a str object -- the two are 
not compatible.  Try splitting with the bytes object b'\t'.


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


Re: bdist_wininst: install_script not run on uninstall

2011-05-25 Thread Mark Hammond

On 26/05/2011 5:28 AM, Wilbert Berendsen wrote:

Hi,

according to the docs the installer bdist_wininst creates will run the
install-script on install with -install (which works perfectly) and on
uninstall with the -remove argument (which seemingly never happens).

However I want to cleanup some registry stuff on uninstall so I want the
uninstall script to work.

Studying the source code of the installer[1] in the Run_RemoveScript
function...

[1] http://svn.python.org/view/python/trunk/PC/bdist_wininst/install.c

... it checks for the line '%d Run Script: %s' in the log, which is there. But
can anybody find out why the install script is not run?


Works for me in the pywin32 install script - maybe you should make the 
smallest possible example that doesn't work and post the entire thing here?


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


Re: super() in class defs?

2011-05-25 Thread Raymond Hettinger
On May 25, 4:31 pm, Ian Kelly ian.g.ke...@gmail.com wrote:
 Right.  It's unnecessary, so why saddle yourself with it?

FWIW, I expect to release a blog post tomorrow about the principal use
cases for super() and how to use it effectively.

With just a little bit of know-how, it can be an important tool in
your Python toolkit.

If any of the comp.lang.python readers want to review and comment on
my latest draft, please email me and I'll send it to you directly.

Cheers,


Raymond Hettinger

my email address is listed at 
http://users.rcn.com/python/download/Descriptor.htm

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Steven D'Aprano
On Wed, 25 May 2011 17:30:48 -0400, theg...@nospam.net wrote:

 On 5/24/2011 1:39 PM, D'Arcy J.M. Cain wrote: [snip]
 One of my favorite quotes (not sure if it was about Perl or APL) is I
 refuse to use a programming language where the proponents of it stick
 snippets under each other's nose and say 'I bet you can't guess what
 this does.'
 I dunno. That sounds about like how most programming course exams are
 written, no?
 The point is that puzzling through arcane bits of code are crucial to
 learning
 any language. It's a valuable exercise.

You seem to miss the point that a good language shouldn't make it 
possible to write arcane code that needs to be puzzled out.

Although in fairness, what's arcane to me might be straightforward to 
you... and vice versa.

In that sense, there probably aren't any good languages, because it is 
impractical to have a language that cannot be obfuscated in any way. 
Nevertheless, we can distinguish less good from more good in 
languages in the sense of readability.  The fact that some languages not 
just allow such obfuscation but encourage it makes the language great for 
puzzles but not so good for when you actually want to get work done and 
have to deal with code written by someone else. *Especially* if they're 
significantly smarter, or dumber, than you.

Worst of all is dealing with code written by somebody who *thinks* 
they're smarter but is actually dumber.



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


Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread MRAB

On 26/05/2011 00:25, tkp...@hotmail.com wrote:

Thanks for the guidance - it was indeed an issue with reading in
binary vs. text., and I do now succeed in reading the last line,
except that I now seem unable to split it, as I demonstrate below.
Here's what I get when I read the last line in text mode using 2.7.1
and in binary mode using 3.2 respectively under IDLE:

2.7.1
Name31/12/2009  0   0   0

3.2
b'Name\t31/12/2009\t0\t0\t0\r\n'

if, under 2.7.1 I read the file in text mode and write

x = lastLine(fn)

I can then cleanly split the line to get its contents

x.split('\t')

['Name', '31/12/2009', '0', '0', '0\n']

but under 3.2, with its binary read, I get

x.split('\t')

Traceback (most recent call last):
   File pyshell#26, line 1, inmodule
 x.split('\t')
TypeError: Type str doesn't support the buffer API

If I remove the '\t', the split now works and I get a list of bytes
literals

x.split()

[b'Name', b'31/12/2009', b'0', b'0', b'0']

Looking through the docs did not clarify my understanding of the
issue. Why can I not split on '\t' when reading in binary mode?


x.split('\t') tries to split on '\t', a string (str), but x is a
bytestring (bytes).

Do x.split(b'\t') instead.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why did Quora choose Python for its development?

2011-05-25 Thread RainyDay
On May 25, 3:14 pm, John Bokma j...@castleamber.com wrote:
 Ethan Furman et...@stoneleaf.us writes:
  Terry Reedy wrote:
  On 5/25/2011 8:01 AM, John Bokma wrote:

  to. Like I already stated before: if Python is really so much better
  than Python readability wise, why do I have such a hard time dropping
  Perl and moving on?

  [you meant 'than Perl'] You are one of the people whose brain fits
  Perl (or vice versa) better than most. So enjoy it. Ignore anyone
  who says otherwise.

  +1

  If everybody's brain worked the same, we wouldn't have so many
  different languages to choose from.

 So, this means that in general language readability is not as clear cut
 as some seem to advertise ;-).


I only know a tiny bit of Perl but I think you may
prefer it because it gives you some advantages in
short term but you have to pay more than it's
worth (arguably) in the long term. When you sit
down to write a new program, it's easier to do
than in python because it's quicker to type and,
of the proverbial many ways, you chose the ones
that suit your taste better.

However, when you sit down to read someone else's
code, it's harder to read because you don't know
the intent of their authors. If they had different
taste for idioms or formatting style than you do,
you will chalk it up to them being bad programmers
and having bad coding or formatting style, so it's
not perceived as a perl's failing.

Python way has more of an emphasis on everyone
agreeing on some preferred, standard idioms so
that everyone can pick up each others' code
quickly.

Similarly, when we write in english, we have
conventions of, for instance, capitalizing at the
start of a sentence and having a period at the end
of it, and following rules of grammar. However, if
I'm writing notes for my own use, I might write:

similarly when we write in english we have
conventions of eg capitalizing at start of
sentence and having period at the end 
following rules of grammar   but since i'm
writing for my own use maybe it's easier to
write in lower caps and use 3 spaces at the
end of sentences, since no-ones has to read
it but me?

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


Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread Ethan Furman

MRAB wrote:

On 26/05/2011 00:25, tkp...@hotmail.com wrote:

Thanks for the guidance - it was indeed an issue with reading in
binary vs. text., and I do now succeed in reading the last line,
except that I now seem unable to split it, as I demonstrate below.
Here's what I get when I read the last line in text mode using 2.7.1
and in binary mode using 3.2 respectively under IDLE:

2.7.1
Name31/12/2009000

3.2
b'Name\t31/12/2009\t0\t0\t0\r\n'

if, under 2.7.1 I read the file in text mode and write

x = lastLine(fn)

I can then cleanly split the line to get its contents

x.split('\t')

['Name', '31/12/2009', '0', '0', '0\n']

but under 3.2, with its binary read, I get

x.split('\t')

Traceback (most recent call last):
   File pyshell#26, line 1, inmodule
 x.split('\t')
TypeError: Type str doesn't support the buffer API

If I remove the '\t', the split now works and I get a list of bytes
literals

x.split()

[b'Name', b'31/12/2009', b'0', b'0', b'0']

Looking through the docs did not clarify my understanding of the
issue. Why can I not split on '\t' when reading in binary mode?


x.split('\t') tries to split on '\t', a string (str), but x is a
bytestring (bytes).

Do x.split(b'\t') instead.


nitpick
Instances of the bytes class are more appropriately called 'bytes 
objects' rather than 'bytestrings' as they are really lists of integers. 
 Accessing a single element of a bytes object does not return a bytes 
object, but rather the integer at that location; i.e.


-- b'xyz'[1]
121

Contrast that with the str type where

-- 'xyz'[1]
'y'
/nitpick

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


Re: Unable to make ironpython run in browser with silverlight

2011-05-25 Thread Jimmy Schementi
You need to run it from a web-server; it doesn't work when running from file:// 
due to Silverlight's security sandbox. Read the comments on my blog-post, it 
mentions the web-server there.


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


Re: Python-list Digest, Vol 92, Issue 221

2011-05-25 Thread Richard Parker

 Writing code is primarily for *human readers*. Once you've compiled the 
 code once, the computer never need look at it again, but human being come 
 back to read it over and over again, to learn from it, or for 
 maintenance. We rightfully value our own time and convenience as more 
 valuable than that of the computer's, which is why we use programming 
 languages at all, instead of having custom-made hardware built for every 
 task we want the computer to do: 

Not only the code itself, but, hopefully, embedded comments help even 
non-authors of the code to understand, maintain and improve it. Programming 
books that include examples often spend many pages dissecting even short 
segments of the code to tutor would-be developers how it works and what it 
does. Well written code in any language, with accompanying comments, is 
invaluable for anyone who has the need or interest to Understand and maintain 
it.

My (ancient) books about object-oriented programming were used to teach 
hundreds of computer science students in universities all over the world, and 
the stressed the importance of embedded comments.

How many times has any programmer looked at (even inscrutable) code with 
accompanying comments and hasn't said to themselves so that's how to do it, or 
that's what it does.

It's time to stop having flame wars about languages and embrace programmers who 
care enough about possible future readers of their code to thoroughly comment 
it. Comments are far more valuable than the actual language in which the code 
is written, IMHO.

Sent from my iPad.


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


Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread Ian Kelly
On Wed, May 25, 2011 at 3:52 PM, MRAB pyt...@mrabarnett.plus.com wrote:
 What do you mean by may include the decoder state in its return value?

 It does make sense that the values returned from tell() won't be in the
 middle of an encoded sequence of bytes.

If you take a look at the source code, tell() returns a long that
includes decoder state data in the upper bytes.  For example:

 data = b' ' + '\u0302a'.encode('utf-16')
 data
b' \xff\xfe\x02\x03a\x00'
 f = open('test.txt', 'wb')
 f.write(data)
7
 f.close()
 f = open('test.txt', 'r', encoding='utf-16')
 f.read()
Traceback (most recent call last):
  File stdin, line 1, in module
  File c:\python32\lib\codecs.py, line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
  File c:\python32\lib\encodings\utf_16.py, line 61, in _buffer_decode
codecs.utf_16_ex_decode(input, errors, 0, final)
UnicodeDecodeError: 'utf16' codec can't decode bytes in position 6-6:
truncated data

The problem of course is the initial space, throwing off the decoder.
We can try to seek past it:

 f.seek(1)
1
 f.read()
'\ufeff\u0302a'

But notice that since we're not reading from the beginning of the
file, the BOM has now been interpreted as data.  However:

 f.seek(1 + (2  65))
73786976294838206465
 f.read()
'\u0302a'

And you can see that instead of reading from position
73786976294838206465 it has read from position 1 starting in the read
a BOM state.  Note that I wouldn't recommend doing anything remotely
like this in production code, not least because the value that I
passed into seek() is platform-dependent.  This is just a
demonstration of how the seek() value can include decoder state.

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


Re: Cherrypy

2011-05-25 Thread Miki Tebeka
I wrote 
http://drdobbs.com/showArticle.jhtml?articleID=199102936queryText=query way 
back then. It might be of some help.

If you have any specific questions, feel free to post them to the group.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Odp: Re: Strange behaviour of input() function (Python 3.2)

2011-05-25 Thread Algis Kabaila
On Wednesday 25 May 2011 06:27:52 sunrrrise wrote:
 Ok, another time I'd like to thank you for your help. I gave
 up, I'm going to get used to IDLE GUI... at least this one
 works!
With IDLE, after any changes to the program, you are asked to 
save file.  IDLE knows that a file in python needs to be saved 
before it can be run!

If you use Notepad, it does not know that Python programs need 
to be saved to disk before they can be executed.  So you should 
remember to save them first.

To use IDLE is a good choice, particularly if you are a 
beginner!

OldAl.
-- 
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to make ironpython run in browser with silverlight

2011-05-25 Thread Sunny
On May 26, 9:44 am, Jimmy Schementi jscheme...@gmail.com wrote:
 You need to run it from a web-server; it doesn't work when running from 
 file:// due to Silverlight's security sandbox. Read the comments on my 
 blog-post, it mentions the web-server there.

I see..
But here: http://silverlighttest.zzl.org/silverlighttest.html , it
runs from a web server, but still gives error.
And it has the same source code as your example, except that I replace
repl.py with the direct link, as you advise on your blog.

I think the problem is with this part:
script type=text/python src=http://github.com/jschementi/pycon2010/
raw/master/repl.py/script

Because when I delete it, it runs properly.

Do you know why is that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about SQLite + Python and twitter

2011-05-25 Thread Philip Semanchuk

On May 25, 2011, at 2:17 PM, Jayme Proni Filho wrote:

 Helo guys,
 
 I'm building a local application for twitter for my brother's store. I'm in
 the beginning and I have some newbie problems, so:
 
 I create a table called tb_messages with int auto increment and varchar(140)
 fields;
 I did three SQL funcionts, insert_tweet, delete_tweet, select_tweet
 
 select_tweet is use for getting messages for sending them to twitter;
 
 My problem is: How can i make my select_tweet works at the same time that
 insert or delete funcions. I just got to work when I stop select function.
 
 I would like to do my app works all the time.

Hi Jayme,
You need to provide a lot more information for us to be able to help you. 

Some suggestions -- 
http://www.istf.com.br/perguntas/#beprecise



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


Re: Unable to make ironpython run in browser with silverlight

2011-05-25 Thread ErichCart ErichCart
On May 26, 9:44 am, Jimmy Schementi jscheme...@gmail.com wrote:

 You need to run it from a web-server; it doesn't work when running from 
 file:// due to Silverlight's security sandbox. Read the comments on my 
 blog-post, it mentions the web-server there.

I see..
But here: http://silverlighttest.zzl.org/silverlighttest.html , it
runs from a web server, but still gives error.
And it has the same source code as your example, except that I replace
repl.py with the direct link, as you advise on your blog.

I think the problem is with this part:
script type=text/python src=http://github.com/jschementi/
pycon2010/
raw/master/repl.py/script

Because when I delete it, it runs properly.

Do you know why is that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why did Quora choose Python for its development?

2011-05-25 Thread John Bokma
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:

 On Wed, 25 May 2011 07:01:07 -0500, John Bokma wrote:

 if Python is really so much better than Python [Perl] 
 readability wise, why do I have such a hard time dropping
 Perl and moving on?

 My guess is that you have an adversarial view of computer languages, 

Well, it's clear that you are indeed the fuckwit I suspected you
are. What's a pity is that you are so vocal in this group and to me at
least makes it a way less pleasant experience to read this group.

Get a life. Or better, just fuck off and die. It will improve both the
world and the Python community, of which you are nothing but a little,
smelly shitstain.

-- 
John Bokma   j3b

Blog: http://johnbokma.com/Perl Consultancy: http://castleamber.com/
Perl for books:http://johnbokma.com/perl/help-in-exchange-for-books.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: English Idiom in Unix: Directory Recursively

2011-05-25 Thread Chris Angelico
On Thu, May 26, 2011 at 8:58 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 ... For everyone else, I'll use an
 ordinary adult vocabulary, and that includes the word recursion or
 recursive.

Overheard yesterday: Our conversation was recursing... I don't know
what they were talking about, but I'm pretty sure it wasn't the
technical details of a function's implementation, given that one of
the people concerned was anything but a computer programmer (I don't
know about the other). It's a perfectly good word, useful in many
contexts.

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


Re: Python-list Digest, Vol 92, Issue 221

2011-05-25 Thread Chris Angelico
On Thu, May 26, 2011 at 10:58 AM, Richard Parker
r.richardpar...@comcast.net wrote:
 It's time to stop having flame wars about languages and embrace programmers
 who care enough about possible future readers of their code to thoroughly
 comment it. Comments are far more valuable than the actual language in which
 the code is written, IMHO.

The problem with comments (and documentation in general) is that they
are often imperfect. If the code is absolutely opaque but it has a
comment next to it, you still have that niggling doubt: has the
comment been updated whenever the code has? Was it even accurate in
the first place? (Comments often say what a piece of code _ought_ to
do, but the code might have a bug in it. And sometimes, that bug ends
up being part of the function's definition, and people depend on it.)
I'd rather have both - reasonably readable code AND a comment, where
the comment explains the intent behind the code.

// allow space for frobnostication
height += BTN_HEIGHT;

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


Re: Why did Quora choose Python for its development?

2011-05-25 Thread Ben Finney

 Get a life. Or better, just fuck off and die. It will improve both the
 world and the Python community, of which you are nothing but a little,
 smelly shitstain.

That abuse is entirely unwelcome in this community, against any person.
Please desist.

If you find any contributing members so difficult to deal with, please
don't respond at all.

-- 
 \   “We have met the enemy and he is us.” —Walt Kelly, _Pogo_ |
  `\1971-04-22 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Parse config file and command-line arguments, to get a single collection of options

2011-05-25 Thread Ben Finney
Howdy all,

Python's standard library has modules for configuration file parsing
(configparser) and command-line argument parsing (optparse, argparse). I
want to write a program that does both, but also:

* Has a cascade of options: default option values, overridden by config
  file options, overridden by command-line options.

* Reads a different, or even additional, configuration file if specified
  on the command-line (e.g. --config-file foo.conf) and yet still obeys
  the above cascade.

* Allows a single definition of an option (e.g. logging level) to define
  the same option for parsing from configuration files and the command
  line.

* Unifies the parsed options into a single collection for the rest of
  the program to access without caring where they came from.

How can I achieve this with minimum deviation from the Python standard
library?


(For anyone interested in gaining StackOverflow points, I'm also asking
this as a question there so feel free to post answers on that site
URL:http://stackoverflow.com/questions/6133517/parse-config-file-and-command-line-arguments-to-get-a-single-collection-of-optio.)

-- 
 \ “Apologize, v. To lay the foundation for a future offense.” |
  `\   —Ambrose Bierce, _The Devil's Dictionary_, 1906 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >