Re: IDE recommendation please

2005-10-23 Thread Brendan
As mentioned, there isn't a whole lot.  I've beta tested Komodo, and it
looks promising.  SPE might start working now that stani has a mac.

For now I use TextWrangler - a free text editor with good python
support.  http://www.barebones.com/products/textwrangler/index.shtml

For interactive python, I use PyCrust (though the terminal works just
as well), and for building wxpython guis I use XrCed,  both of which
are available as native mac apps in the wxPython docs/demos package ):
http://www.wxpython.org/download.php.

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


Newbie Alert: Help me store constants pythonically

2005-11-06 Thread Brendan
Hi all

I'm new to Python (and programming in general), and I can't decide what
is the most 'pythonic' way to approach a problem.  Your advice would be
appreciated.

I have a bunch of 'scans', containing the data measured from one of
several types of 'model'. Each 'model' has different values for a list
of constants  I want to create 'analyses' which interpret the data from
the scans, with reference the appropriate model.  So far, I have come
up with three strategies to store this information, illustrated below
(I've simplified the constant list to just two):

1) Store the model constants as class instances:

class Model:
def __init__(self, numBumps, sizeOfBumps):
self.__dict__.update(locals()); del self.self

MODEL1 = Model(1, 2)
MODEL2 = Model(3, 4)
#etc

class Analysis:
def __init__(self, scanData, model):
#do analysis

2) Store the model constants as class variables:

class MODEL1:
numBumps = 1
sizeOfBumps = 2

class MODEL2:
numBumps = 3
sizeOfBumps = 4

class Analysis:
#as with 1

3) Store the model constants as class variables of the analysis class:

class Model1Analysis:
numBumps = 1
sizeOfBumps = 2

def __init__(self, scanData):
   #do analysis

class Model2Analysis(Model1Analysis):
numBumps = 3
sizeOfBumps = 4

There may be more options, but at this point I became paralyzed with
choice.  I worry about getting stuck with an unworkable structure since
I don't have the experience to decide the merits of each in advance.  I
get way too frustrated about these things :)
   Brendan

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


Re: Newbie Alert: Help me store constants pythonically

2005-11-06 Thread Brendan
Thanks for the vote FB.  The reason I'm using that method for assigning
instance attributes is that the argument list for __init__ is LOOONG.
(There are many constants, I only gave two for the examples).  I wanted
to avoid typing them out twice.

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


Re: ? MDI depreciated

2005-11-06 Thread Brendan
This is probably a question better suited for a wxPython or MSDN
newsgroup.  What OS are you referring to?  What GUI toolkit are you
using?

Microsoft's office on Windows has moved to a model where every document
has its own toolbar, menubar, and taskbar entry.  Windows developers
tend to mimic MS Office, so many are also moving to this model. Mac
apps have never had MDI.

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


Re: Newbie Alert: Help me store constants pythonically

2005-11-07 Thread Brendan

> How many is LOOONG? Ten? Twenty? One hundred?

About 50 per Model

> If it is closer to 100 than to 10, I would suggest
> putting your constants into something like an INI file:
>
> [MODEL1]  # or something more meaningful
> numBumps: 1
> sizeOfBumps: 99
>
> [MODEL2]
> numBumps: 57
> sizeOfBumps: 245
>
>
> etc.
>
> Then sub-class the ConfigParser to create struct-like
> objects from an ini file. Something vaguely like:
>
> # warning: pseudo-code, seriously not tested!!!
> class Config2Consts(ConfigParser):
>  """Reads an INI file, and creates a struct-like
>  object from each section, storing that object
>  in the local scope with the name of the section.
>  """
>
>  class Struct:
>  def __init__(self):
>  pass
>
>  def make_single_constant_object(self, sectionname):
>  obj = Struct()
>  for field in INI_FILE[sectionname]:
>   obj.__dict__[field.name] = field.value
>  locals().update({sectionname: obj})
>
>
>
> If you are likely to be changing the constants (either
> names, field names, or values) an hour or three
> developing this code will save you a lot of heart-ache
> later.

Thanks for your reply Steve.  I like this suggestion because it
separates my config data from the code, which could mean less headaches
editing the values later.  It also lets me keep my constants
language-neutral, which is good because I haven't convinced my boss yet
that Python's the way to go.

The only downside is that it doesn't do any 'name checking', so any
mistakes in my config file won't show up until the middle of the
analysis.  Maybe this is a 'static language' mode of thinking, but it
seems risky.  Also my config files have (a tiny bit of) nested
structure, such as:

Model1(
   numBumps = 1
   sizeOfBumps = 2
   transversePlanes = [
Plane(type=3, z=4),
Plane(type=5, z=6),
Plane(type=3, z=8)
]
)

which I'm not sure the .ini format can easily support.  I could use
(key buzzword voice) XML, but  I fear that might send me down the
'overcomplicating things' path.  Your suggestion has given me some new
places to search Google (configparser, python config files), so I'll
look around for better ideas.

   Brendan

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


Re: XML GUI

2005-11-08 Thread Brendan

py wrote:
> how about wxPython?  I am interested in something that will look native
> on various operating systems (win, mac, *nix).
>
> any good tutorial on using wxPython with XML?

The wxPython distribution comes with  XRCed, which is a graphical
gui-builder that serializes to XRC (wxWidgets XML syntax).

(I'm assuming you just want to use XML to describe the gui.  If you
want to define your own xml syntax, then you'll have to wait for
someone more experienced than me for help.  There are several packages
for using cusom XML. You can start here:
http://effbot.org/zone/element-index.htm)

Brendan

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


Re: Newbie Alert: Help me store constants pythonically

2005-11-08 Thread Brendan
Thanks for all the suggestions everyone.

After a bit of googling on the c.l.p. group, I see that building config
files is one of those 'Everyone has a favourite way of doing it' types
of problems, with lots of reimplementations.  I should change the
thread topic to "Yet Another Config File Question"!

Based on my requirements (thanks again for helping me identify these),
my config file should:

a) store numbers, strings, bools, keyed dictionaries and un-keyed lists
b) store nested structures of the above
c) be language neutral, preferably well supported in other languages,
and editors
d) have a simple api in Python, preferably translating values to native
types
e) be validated when read

I've checked out ConfigParser, ConfigObj, Pickle, PyYaml and
gnossis.xml.serialize, and none meet all the above criteria (though
they're all neat).

So I've decide to use ...drumroll please plistlib (
http://svn.python.org/projects/python/trunk/Lib/plat-mac/plistlib.py ).
 Why plists?

- I've got a simple api (readPlist(pathOrFile), writePlist(rootObject,
pathOrFile) ) already installed with macPython
- I have a dirt simple plist editor for knocking out the hundreds of
config values I need (
http://homepage.mac.com/bwebster/plisteditpro.html )
- The file format is xml, which is well supported in all languages.
- Since plists are the standard approach on the mac (though they aren't
OS specific by definition), the XML schema is well documented
(http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html),
and shared with thousands of other apps, so I won't have to worry about
obsolescence.

So away I go.  If anyone can suggest reasons I should avoid this
approach, please let me know before I get too invested.  Otherwise,
this might be a reasonable avenue for standardizing Python. (I hope
that doesn't draw to many flames :)

Brendan.

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


Re: SPE IDE for Python

2005-11-08 Thread Brendan
SPE doesn't yet integrate with CVS, but it's in active development.
CVS support may come sooner than later.

I have been demoing Komodo which integrates with CVS, SVN and perforce.
 I've been very impressed.
http://aspn.activestate.com/ASPN/docs/Komodo/3.1/komodo-doc-scc.html

On my pc I just use the tortoiseSVN windows explorer plugin -
http://tortoisesvn.tigris.org/

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


Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Brendan
There must be an easy way to do this:

For classes that contain very simple data tables, I like to do
something like this:

class Things(Object):
def __init__(self, x, y, z):
#assert that x, y, and z have the same length

But I can't figure out a _simple_ way to check the arguments have the
same length, since len(scalar) throws an exception.  The only ways
around this I've found so far are

a)  Cast each to a numeric array, and check it's dimension and shape.
This seems like far too many dependencies for a simple task:

def sLen(x):
"""determines the number of items in x.
Returns 1 if x is a scalar. Returns 0 if x is None
"""
xt = numeric.array(x)
if xt == None:
return 0
elif xt.rank == 0:
return 1
else:
return xt.shape[0]

b) use a separate 'Thing' object, and make the 'Things' initializer
work only with Thing objects.  This seems like way too much structure
to me.

c) Don't bother checking the initializer, and wait until the problem
shows up later.  Maybe this is the 'dynamic' way, but it seems a little
fragile.

Is there a simpler way to check that either all arguments are scalars,
or all are lists of the same length?  Is this a poor way to structure
things?  Your advice is appreciated
   Brendan
--
Brendan Simons

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


Re: Checking length of each argument - seems like I'm fighting Python

2005-12-04 Thread Brendan
Thank you all for your help.  Alex's listify does the job well.  I will
reconsider using an atomic "Thing" class with Michaels' safeList.
Bengt wins the prize for reducing sLen to one line!

I still feel like I'm working against the grain somewhat, (Mike's
right, I am coming at this with a "C++ mindset) but at least I have
tools to do it efficiently :)

Brendan

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


Help me dig my way out of nested scoping

2005-04-03 Thread Brendan
Hi everyone

I'm new to Python, so forgive me if the solution to my question should
have been obvious.  I have a function, call it F(x), which asks for two
other functions as arguments, say A(x) and B(x).  A and B are most
efficiently evaluated at once, since they share much of the same math,
ie, A, B = AB(x), but F wants to call them independantly (it's part of
a third party library, so I can't change this behaviour easily).   My
solution is to define a wrapper function FW(x), with two nested
functions,  AW(x) and BW(x), which only call AB(x) if x has changed.

To make this all clear, here is my (failed) attempt:

#--begin code -

from ThirdPartyLibrary import F
from MyOtherModule import AB

def FW(x):
lastX = None
aLastX = None
bLastX = None

def AW(x):
if x != lastX:
lastX = x
# ^ Here's the problem.  this doesn't actually
# change FW's lastX, but creates a new, local lastX

aLastX, bLastX = AB(x)
return aLastX

def BW(x):
if x != lastX:
lastX = x
# ^ Same problem

aLastX, bLastX = AB(x)
return bLastX

#finally, call the third party function and return its result
return F(AW, BW)

# end code -

OK, here's my problem:  How do I best store and change lastX, A(lastX)
and B(lastX) in FW's scope?  This seems like it should be easy, but I'm
stuck.  Any help would be appreciated!

  -Brendan
--
Brendan Simons

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


Re: Help me dig my way out of nested scoping

2005-04-03 Thread Brendan
Thanks for the tips.  Making FW a callable class (choice 5) seems to be
a good (if verbose) solution.  I might just wrap my temporary values in
a list [lastX, lastA, lastB] and mutate them as Michael suggests.
Thanks to Michael especially for the explanation of the name-binding
process that's at the heart of the issue.

The other choicess are not as helpful to me for the following reasons:

choice 1: I don't want the temporary values of lastA and lastB to be
global variables in my case as they are great big numeric arrays, and
I'd like their memory to be reclaimed after FW is done.

choice 2:  I tried this without success.  Using Micheal's example, I
would assume you mean something like this:

def outer():
b = 1
def inner():
outer.b += 1
print outer.b
inner()
outer()

Which gives me:
AttributeError: 'function' object has no attribute 'b'

Perhaps I misapplied this method?

choice 3:  I know that Python can return multiple values in one line,
but I don't think that applies here.  My library function F, is looking
for two separate function arguments

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


Re: Help me dig my way out of nested scoping

2005-04-03 Thread Brendan
F -is- in fact an iterative optimizer that minimizes A on x (B is the
derivative of A).  So yes, F will call A and B on mulitple 'x's.   In
that case, it seems the mutable object trick is the way to go.  Thanks.

I didn't follow your last sentence.  What about the Python Cookbook?

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


Re: Help me dig my way out of nested scoping

2005-04-03 Thread Brendan

>James Stroud  Apr 3, 3:18 pm:
>I think you might want to look at "python generators".

I've seen discussion of generators before, but haven't invested the
time to understand them yet.  This might be a good excuse.

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


Re: Python IDE (was: PythonWin troubleshooting)

2005-12-16 Thread Brendan
I use Komodo now, and love it.  It has all the features you'd expect:
code completion, object browsing, folding, docstring previews etc.  Of
course it's the only full-featured, native and stable Python IDE
currently available for the mac (SPE is close), so my choice is
limited.

  Brendan


Martin Miller wrote:
> You might want to also to consider the Komodo IDE from ActiveState (the
> same company that produces ActivePython and hosts the ASPN Cookbook).
> This isn't an endorsement -- I have no experience with it --  but its
> feature set looks good  [see http://activestate.com/Products/Komodo].
>
> If someone with actual experience using Komodo with Python is
> listening, I'd be very interested in hearing what you think of it or
> other alternatives (I plan on taking a look at PyScripter and any
> others I hear about).

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


Re: New Python.org website ?

2006-01-13 Thread Brendan
Steve

I didn't realize Python.org was being revamped.  The site looks
awesome!
One thing I noticed:  The mac download site still references Jack
Jansen's site, which hasn't been updated since 2004 afaik.  These days
I get most of my mac python downloads from
http://pythonmac.org/packages/

Brendan

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


Re: Serializing / Unserializing datetime

2006-05-28 Thread Brendan
Thanks John.   I've discovered that datetime.strptime will be available
in 2.5, (http://docs.python.org/dev/whatsnew/modules.html) but your
example will work in the meantime.

BJ

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


Python 2.5 WinXP AMD64

2006-09-21 Thread Brendan
Hello,
I just tried to use the Windows XP installer for Python 2.5 AMD64 but I
get the error message: "Installation package not supported by processor
type"

I am running Windows XP Pro on an AMD Athon 64 Processor.

Do I need to have a 64-bit OS to use this version?

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


Re: Python 2.5 WinXP AMD64

2006-09-21 Thread Brendan
Thanks.

Christophe wrote:
> Brendan a écrit :
> > Hello,
> > I just tried to use the Windows XP installer for Python 2.5 AMD64 but I
> > get the error message: "Installation package not supported by processor
> > type"
> >
> > I am running Windows XP Pro on an AMD Athon 64 Processor.
> >
> > Do I need to have a 64-bit OS to use this version?
> 
> To be exact, you need a 64bit Windows OS on a 64bit cpu.

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


Why are the topic and keyword documentation not includded in the chm?

2006-09-22 Thread Brendan
1)Why are the  topic and keyword documentation not included in the
Windows installation chm? I have to have both the html(with the env var
PYTHONDOCS set) and the chm installed? What is the point of that?

2)Is there no simple way to open the chm docs in a browser from within
python?

3)How do I open the online pydoc browser from within python? (Sure I
can open it using the start menu shortcut or from the OS command prompt
with: python C:\python25\lib\pydoc.py -w, but why would I not want to
be able to open it from the python command prompt?)

Why are these issues not made clear somewhere in plain view such as
Getting Started or in the installation notes?

Thanks

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


Re: Scientific Computing with NumPy

2006-02-06 Thread Brendan
As of version 0.4.x, Scipy exclusively uses the newer NumPy module
instead of the older Numeric module.  The confusion is inevitable in
this time of transition, but their intent is to standardize on one
array package.

Brendan
--
Brendan Simons



mclaugb wrote:
> This page documents the differences.  It seems that NumPy is supported and
> more recent.
> http://numeric.scipy.org/
>
>
> "linda.s" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> On 2/6/06, mclaugb <[EMAIL PROTECTED]> wrote:
> > Has anyone recompiled the Scientific Computing package using NumPy instead
> > of Numeric?
> > I need a least squares algorithm and a Newton Rhaphson algorithm which is
> > contained in Numeric but all the documentation out there says that Numeric
> > is crap and all code should be using NumPy.
> > Thanks,
> > Bryan
> what is the relationship between Numeric and Numpy?

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


Re: Using python for a CAD program

2006-05-17 Thread Brendan
On 17-May-06, at 6:33 AM, comp.lang.python group wrote:

>>I'd like my program
>>to *look* slick, like it belongs in a movie or something.  I think that
>>means starting from scratch, since I've not seen any CAD program
>>take
>>any artistic/human/psychological approach to its design.

>That *is* true - the problem with CAD programs are that they need the
>*exact* details to be entered at design time so one cannot easily
>schetch in them and fix the design errors later.


Not universally true, and here's a niche for you Andreas:

Most 2D cad requires that you enter ALL design information as you go.
You can't, for instance, draw a line at 30degrees to another line and
then change the second without having to redraw the first.  "Sketchers"
from 3D cad programs (like Solidworks, Inventor, Solid Edge,
Pro/Engineer) are more like geometry solvers - by putting in a
dimension, you say  "line a is always 30 degrees to line b".Now
when you change the angle of line b, line a changes too!  In this way,
you can sketch out the SHAPE of your drawing, and worry about the
DIMENSIONS later.  You can't imagine how useful this is.  Now that I've
switched to Solidworks, my
drafting speed has doubled.

I haven't seen anyone make a 2D cad package with this behaviour.  I'm
sure there's a market for one if you go that route.

-Brendan

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


Serializing / Unserializing datetime

2006-05-27 Thread Brendan
Hi All

I can't find the "Python Way" of writing a datetime instance to a
string so that it can be easily parsed back again.  time.strptime is
apparantly not supported on some platforms, and time.time <==>
datetime.utcfromtimestamp will cause problems come 2038.  Unfortunately
there don't seem to be "fromstring" equivalents for datetime.ctime or
datetime.isoformat.

Ideally the serialized datetime should be human readable, and
potentially parseable from other languages.  Any suggestions?

  Brendan
--
Brendan Simons

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


Reading online zip files - zipfile and zlib, wbits

2008-12-12 Thread Brendan
I am fooling around with accessing contents of zip files online. I
download the tail end of the zip and use zipfile to get the zip
central directory structure. I download the section of the zip file I
need, directly read the zip file headers and use that information with
zlib to uncompress the data. The files I am examining will always be
compressed using deflate, with a wbits value of -15(minus for
headerless data because I am unsure whether the zip file header is
what zlib expects).

I can not find anywhere in the PK Zip Application notes (
http://www.pkware.com/documents/casestudies/APPNOTE.TXT ) how to
determine the value I should uze for wbits with zlib.decompress. I
have determined it is -15 from experimentation. Does anyone know the
answer to this?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reading online zip files - zipfile and zlib, wbits

2008-12-12 Thread Brendan
On Dec 12, 10:25 am, Brendan  wrote:
> I am fooling around with accessing contents of zip files online. I
> download the tail end of the zip and use zipfile to get the zip
> central directory structure. I download the section of the zip file I
> need, directly read the zip file headers and use that information with
> zlib to uncompress the data. The files I am examining will always be
> compressed using deflate, with a wbits value of -15(minus for
> headerless data because I am unsure whether the zip file header is
> what zlib expects).
>
> I can not find anywhere in the PK Zip Application notes 
> (http://www.pkware.com/documents/casestudies/APPNOTE.TXT) how to
> determine the value I should uze for wbits with zlib.decompress. I
> have determined it is -15 from experimentation. Does anyone know the
> answer to this?

Okay, I found part of the answer here in the zip app notes
[quote]
general purpose bit flag: (2 bytes)

  Bit 0: If set, indicates that the file is encrypted.

  (For Method 6 - Imploding)
  Bit 1: If the compression method used was type 6,
 Imploding, then this bit, if set, indicates
 an 8K sliding dictionary was used.  If clear,
 then a 4K sliding dictionary was used.
  Bit 2: If the compression method used was type 6,
 Imploding, then this bit, if set, indicates
 3 Shannon-Fano trees were used to encode the
 sliding dictionary output.  If clear, then 2
 Shannon-Fano trees were used.

  (For Methods 8 and 9 - Deflating)
  Bit 2  Bit 1
0  0Normal (-en) compression option was used.
0  1Maximum (-exx/-ex) compression option was
used.
1  0Fast (-ef) compression option was used.
1  1Super Fast (-es) compression option was used.
[/quote]

Now I just don't understand Why Normal deflate corresponds to 15
wbits, and why I have to use headerless for the data, i.e. wbits = -15.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reading online zip files - zipfile and zlib, wbits

2008-12-12 Thread Brendan
On Dec 12, 10:46 am, Brendan  wrote:
> On Dec 12, 10:25 am, Brendan  wrote:
>
> > I am fooling around with accessing contents of zip files online. I
> > download the tail end of the zip and use zipfile to get the zip
> > central directory structure. I download the section of the zip file I
> > need, directly read the zip file headers and use that information with
> > zlib to uncompress the data. The files I am examining will always be
> > compressed using deflate, with a wbits value of -15(minus for
> > headerless data because I am unsure whether the zip file header is
> > what zlib expects).
>
> > I can not find anywhere in the PK Zip Application notes 
> > (http://www.pkware.com/documents/casestudies/APPNOTE.TXT) how to
> > determine the value I should uze for wbits with zlib.decompress. I
> > have determined it is -15 from experimentation. Does anyone know the
> > answer to this?
>
> Okay, I found part of the answer here in the zip app notes
> [quote]
> general purpose bit flag: (2 bytes)
>
>           Bit 0: If set, indicates that the file is encrypted.
>
>           (For Method 6 - Imploding)
>           Bit 1: If the compression method used was type 6,
>                  Imploding, then this bit, if set, indicates
>                  an 8K sliding dictionary was used.  If clear,
>                  then a 4K sliding dictionary was used.
>           Bit 2: If the compression method used was type 6,
>                  Imploding, then this bit, if set, indicates
>                  3 Shannon-Fano trees were used to encode the
>                  sliding dictionary output.  If clear, then 2
>                  Shannon-Fano trees were used.
>
>           (For Methods 8 and 9 - Deflating)
>           Bit 2  Bit 1
>             0      0    Normal (-en) compression option was used.
>             0      1    Maximum (-exx/-ex) compression option was
> used.
>             1      0    Fast (-ef) compression option was used.
>             1      1    Super Fast (-es) compression option was used.
> [/quote]
>
> Now I just don't understand Why Normal deflate corresponds to 15
> wbits, and why I have to use headerless for the data, i.e. wbits = -15.

Seems the bit flags are not properly set, bit 2 should be 0 and bit 1
should be 1, to correspond to maximum compression i.e. wbit = 15.
Still don't know why wbits has to be negative.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reading online zip files - zipfile and zlib, wbits

2008-12-12 Thread Brendan
On Dec 12, 11:36 am, Brendan  wrote:
> On Dec 12, 10:46 am, Brendan  wrote:
>
>
>
>
>
> > On Dec 12, 10:25 am, Brendan  wrote:
>
> > > I am fooling around with accessing contents of zip files online. I
> > > download the tail end of the zip and use zipfile to get the zip
> > > central directory structure. I download the section of the zip file I
> > > need, directly read the zip file headers and use that information with
> > > zlib to uncompress the data. The files I am examining will always be
> > > compressed using deflate, with a wbits value of -15(minus for
> > > headerless data because I am unsure whether the zip file header is
> > > what zlib expects).
>
> > > I can not find anywhere in the PK Zip Application notes 
> > > (http://www.pkware.com/documents/casestudies/APPNOTE.TXT) how to
> > > determine the value I should uze for wbits with zlib.decompress. I
> > > have determined it is -15 from experimentation. Does anyone know the
> > > answer to this?
>
> > Okay, I found part of the answer here in the zip app notes
> > [quote]
> > general purpose bit flag: (2 bytes)
>
> >           Bit 0: If set, indicates that the file is encrypted.
>
> >           (For Method 6 - Imploding)
> >           Bit 1: If the compression method used was type 6,
> >                  Imploding, then this bit, if set, indicates
> >                  an 8K sliding dictionary was used.  If clear,
> >                  then a 4K sliding dictionary was used.
> >           Bit 2: If the compression method used was type 6,
> >                  Imploding, then this bit, if set, indicates
> >                  3 Shannon-Fano trees were used to encode the
> >                  sliding dictionary output.  If clear, then 2
> >                  Shannon-Fano trees were used.
>
> >           (For Methods 8 and 9 - Deflating)
> >           Bit 2  Bit 1
> >             0      0    Normal (-en) compression option was used.
> >             0      1    Maximum (-exx/-ex) compression option was
> > used.
> >             1      0    Fast (-ef) compression option was used.
> >             1      1    Super Fast (-es) compression option was used.
> > [/quote]
>
> > Now I just don't understand Why Normal deflate corresponds to 15
> > wbits, and why I have to use headerless for the data, i.e. wbits = -15.
>
> Seems the bit flags are not properly set, bit 2 should be 0 and bit 1
> should be 1, to correspond to maximum compression i.e. wbit = 15.
> Still don't know why wbits has to be negative.- Hide quoted text -
>
> - Show quoted text -

Arg!  Tried a different tack. Took the file header plus compressed
file and concatenated with central directory. Now need only zipfile
module.
--
http://mail.python.org/mailman/listinfo/python-list


zipfile.is_zipfile() and string buffers

2008-12-16 Thread Brendan
I would like zipfile.is_zipfile(), to operate on a cStringIO.StringIO
string buffer, but is seems only to accept file names as arguments.
Should it not be able to handle string buffers too?
--
http://mail.python.org/mailman/listinfo/python-list


ftplib - 226 message not received

2009-01-08 Thread Brendan
I am trying to download a file within a very large zipfile. I need two
partial downloads of the zipfile. The first to get the file byte
offset, the second to get the file itself which I then inflate.

I am implementing the partial downloads as follows:

con = ftp.transfercmd('RETR ' + filename, rest_offset)  # the data
socket
while True:
block = con.recv(blocksize)
# stop transfer while it isn't finished yet
if bytes_recv >= buf_length:
break
elif not block:
break
buf = ''.join([buf, block])
bytes_recv += len(block)
con.close()

My problem is that even though the socket is closed, I have no way to
receive the 226 response from server so I can proceed with the next
download.  Of course I could close the ftp connection entirely and
open a new one, but I am hoping to avoid doing so.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ftplib - 226 message not received

2009-01-08 Thread Brendan
Okay, found it on my own. ftp.voidresp() is what is needed, and it
does _not_ seem to be in the Python documentation for ftplib.

On Jan 8, 1:58 pm, Brendan  wrote:
> I am trying to download a file within a very large zipfile. I need two
> partial downloads of the zipfile. The first to get the file byte
> offset, the second to get the file itself which I then inflate.
>
> I am implementing the partial downloads as follows:
>
> con = ftp.transfercmd('RETR ' + filename, rest_offset)  # the data
> socket
> while True:
>     block = con.recv(blocksize)
> # stop transfer while it isn't finished yet
>     if bytes_recv >= buf_length:
>         break
>     elif not block:
>         break
>     buf = ''.join([buf, block])
>     bytes_recv += len(block)
> con.close()
>
> My problem is that even though the socket is closed, I have no way to
> receive the 226 response from server so I can proceed with the next
> download.  Of course I could close the ftp connection entirely and
> open a new one, but I am hoping to avoid doing so.

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


Installing multiple python versions - CentOs Linux

2008-10-17 Thread Brendan
The current CentOs Linux distro includes python 2.4.3. I need to
install a more recent version but I am worried about breaking CentOs
python dependencies. Is it safe to install python 2.6 using pup?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Installing multiple python versions - CentOs Linux

2008-10-17 Thread Brendan
> If you install from sources, the safest path is to run
>
> $ sudo make altinstall (will add the version number to the executable)
>
> and NOT
>
> $ sudo make install
Ah, that is perfect. Thank-you!


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


B-Soup: broken iterator, tag a keyword?

2008-07-10 Thread Brendan
Hi there,
I have the following using Beautiful Soup:

soup = BeautifulSoup(data)
tags = soup.findAll(href=re.compile("/MER_FRS_L2_Canada/MER_FRS_\S
+gz"))
for tag in tags:
print tag['href']
print tag.parent.nextSibling.string
print tag.parent.nextSibling.nextSibling.string
print tag.parent.nextSibling.nextSibling.nextSibling.string
print
tag.parent.nextSibling.nextSibling.nextSibling.nextSibling.contents[0].string


For some reason I do not understand, using 'tag' as an iterator breaks
the code. Can someone tell me why? reading dir(soup) did not
illuminate me.

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


urllib2 HTTPBasicAuthHandler and resumingbroken downloads

2008-08-21 Thread Brendan
Is there any way to resume an https file download using urllib2 and an
HTTPBasicAuthHandler?
--
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 HTTPBasicAuthHandler and resumingbroken downloads

2008-08-22 Thread Brendan
On Aug 21, 3:57 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Thu, 21 Aug 2008 15:37:41 -0300, Brendan <[EMAIL PROTECTED]>  
> escribi :
>
> > Is there any way to resume an https file download using urllib2 and an
> > HTTPBasicAuthHandler?
>
> You should provide the Range header (and probably If-Range too) in the  
> request.http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
>
> --
> Gabriel Genellina

Many thanks for your help.

Ug. Why does everything in Python boil down to reading rfcs? It really
slows us non computer science types down. I'll probably spend a day on
this instead of an hour. I did search the web but had no luck finding
an example, so I posted here as a last resort.
--
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 HTTPBasicAuthHandler and resumingbroken downloads

2008-08-25 Thread Brendan
On Aug 22, 1:59 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 22 Aug 2008 08:55:57 -0300, Brendan <[EMAIL PROTECTED]>  
> escribi :
>
>
>
>
>
> > On Aug 21, 3:57 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> > wrote:
> >> En Thu, 21 Aug 2008 15:37:41 -0300, Brendan <[EMAIL PROTECTED]>  
> >>  
> >> escribi :
>
> >> > Is there any way to resume an https file download using urllib2 and an
> >> > HTTPBasicAuthHandler?
>
> >> You should provide the Range header (and probably If-Range too) in the  
> >> request.http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
>
> > Ug. Why does everything in Python boil down to reading rfcs? It really
> > slows us non computer science types down. I'll probably spend a day on
> > this instead of an hour. I did search the web but had no luck finding
> > an example, so I posted here as a last resort.
>
> The easy way is to use wget...
> If you want a Python example, go to the Python 
> cookbook:http://code.activestate.com/recipes/langs/python/
> enter "resume download" in the search box, and the very first recipe shows  
> how to use the Range header.
>
> --
> Gabriel Genellina- Hide quoted text -
>
> - Show quoted text -

Thanks for the link. Much appreciated.
--
http://mail.python.org/mailman/listinfo/python-list


Python 2.6 ftplib has timeout parameter, but how to detect a timeout

2009-12-14 Thread Brendan
I was quite happy to see that ftplib in Python 2.6 now has a timeout
parameter. With large file downloads my script would often hang,
presumably from timing out. Now that there is a timeout parameter, how
would I detect when a timeout occurs?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ftplib retrlines timeout

2009-12-16 Thread Brendan
On Dec 15, 6:17 pm, Jennifer  wrote:
> I am writing a program that has a requirement for  a timeout of
> retrlines after the connection established. I just wonder if timeout
> of ftplib.FTP('.xxx.com',username,password,timeout) will work for
> retrlines method after the connection established. Or
> socket.setdefaulttimeout will work in this case. Please let me know.
>
> What exception will be throwed if ftp.retrlines timed out.
>
> Many Thanks!
>
> - Jennifer

I asked a similar question on here a few days ago and got no response,
however I tried a large download which timed out with the following:
Traceback (most recent call last):
  File "./download_r1_neodf.py", line 167, in 
result = ftp.quit()
  File "/usr/local/lib/python2.6/ftplib.py", line 566, in quit
resp = self.voidcmd('QUIT')
  File "/usr/local/lib/python2.6/ftplib.py", line 248, in voidcmd
return self.voidresp()
  File "/usr/local/lib/python2.6/ftplib.py", line 223, in voidresp
resp = self.getresp()
  File "/usr/local/lib/python2.6/ftplib.py", line 209, in getresp
resp = self.getmultiline()
  File "/usr/local/lib/python2.6/ftplib.py", line 195, in getmultiline
line = self.getline()
  File "/usr/local/lib/python2.6/ftplib.py", line 182, in getline
line = self.file.readline()
  File "/usr/local/lib/python2.6/socket.py", line 406, in readline
data = self._sock.recv(self._rbufsize)
socket.error: [Errno 110] Connection timed out


BTW, if you want to use the timeout paramter, you must also use the
account parameter. Set it to ''.
-- 
http://mail.python.org/mailman/listinfo/python-list


KirbyBase : replacing string exceptions

2009-11-23 Thread Brendan
In KirbyBase there is a method that uses string exceptions for
control, even though it has a defined exception. Is there any reason
the string exceptions below could not be replaced?
i.e. in code below replace:
raise "No Match"
with:
raise KBError()
and
except 'No Match':
with:
except KBError:

I have pasted the relevant method and the class definition of KBError
below

 
#--
# _getMatches
 
#--
def _getMatches(self, fptr, fields, patterns, useRegExp):
# Initialize a list to hold all records that match the search
# criteria.
match_list = []

# If one of the fields to search on is 'recno', which is the
# table's primary key, then search just on that field and
return
# at most one record.
if 'recno' in fields:
return self._getMatchByRecno(fptr,patterns)
# Otherwise, search table, using all search fields and
patterns
# specified in arguments lists.
else:
new_patterns = []
fieldNrs = [self.field_names.index(x) for x in fields]
for fieldPos, pattern in zip(fieldNrs, patterns):
if self.field_types[fieldPos] == str:
# If useRegExp is True, compile the pattern to a
# regular expression object and add it to the
# new_patterns list.  Otherwise,  just add it to
# the new_patterns list.  This will be used below
# when matching table records against the
patterns.
if useRegExp:
new_patterns.append(re.compile(pattern))
# the pattern can be a tuple with re flags
like re.I
else:
new_patterns.append(pattern)
elif self.field_types[fieldPos] == bool:
# If type is boolean, I am going to coerce it to
be
# either True or False by applying bool to it.
This
# is because it could be '' or [].  Next, I am
going
# to convert it to the string representation:
either
# 'True' or 'False'.  The reason I do this is
because
# that is how it is stored in each record of the
table
# and it is a lot faster to change this one value
from
# boolean to string than to change possibly
thousands
# of table values from string to boolean.  And, if
they
# both are either 'True' or 'False' I can still
# compare them using the equality test and get the
same
# result as if they were both booleans.
new_patterns.append(str(bool(pattern)))
else:
# If type is int, float, date, or datetime, this
next
# bit of code will split the the comparison string
# into the string representing the comparison
# operator (i.e. ">=" and the actual value we are
going
# to compare the table records against from the
input
# pattern, (i.e. "5").  So, for example, ">5"
would be
# split into ">" and "5".
r = re.search('[\s]*[\+-]?\d', pattern)
if self.field_types[fieldPos] == int:
patternValue = int(pattern[r.start():])
elif self.field_types[fieldPos] == float:
patternValue = float(pattern[r.start():])
else:
patternValue = pattern[r.start():]
new_patterns.append(
 [self.cmpFuncs[pattern[:r.start()]],
patternValue]
)

fieldPos_new_patterns = zip(fieldNrs, new_patterns)
maxfield = max(fieldNrs)+1

# Record current position in table. Then read first detail
# record.
fpos = fptr.tell()
line = fptr.readline()

# Loop through entire table.
while line:
# Strip off newline character and any trailing spaces.
line = line[:-1].strip()
try:
# If blank line, skip this record.
if line == "": raise 'No Match'
# Split the line up into fields.
record = line.split("|", maxfield)

# Foreach correspond field and pattern, check to
see
# if the table record's field matches
successfully.
for fieldPos, pattern in fieldPos_new_patterns:
# If the field type is string, it
# must be an exact match or a regular
expression,
# so we will compa

Re: KirbyBase : replacing string exceptions

2009-11-23 Thread Brendan
On Nov 23, 12:21 pm, Steve Howell  wrote:
> On Nov 23, 7:22 am, Brendan  wrote:
>
> > In KirbyBase there is a method that uses string exceptions for
> > control, even though it has a defined exception. Is there any reason
> > the string exceptions below could not be replaced?
> > i.e. in code below replace:
> > raise "No Match"
> > with:
> > raise KBError()
> > and
> > except 'No Match':
> > with:
> > except KBError:
>
> It looks like in some cases KBError() should fall through and only 'No
> Match' was intended to be silently caught.
>
> I would consider either leaving it alone if it works, or doing more
> serious surgery on the code to simplify the control flow.  The method
> is awfully long and nested.
>
>
>
> > I have pasted the relevant method and the class definition of KBError
> > below
>
> > #--
> >     # _getMatches
>
> > #--
> >     def _getMatches(self, fptr, fields, patterns, useRegExp):
> >         # Initialize a list to hold all records that match the search
> >         # criteria.
> >         match_list = []
>
> >         # If one of the fields to search on is 'recno', which is the
> >         # table's primary key, then search just on that field and
> > return
> >         # at most one record.
> >         if 'recno' in fields:
> >             return self._getMatchByRecno(fptr,patterns)
> >         # Otherwise, search table, using all search fields and
> > patterns
> >         # specified in arguments lists.
> >         else:
> >             new_patterns = []
> >             fieldNrs = [self.field_names.index(x) for x in fields]
> >             for fieldPos, pattern in zip(fieldNrs, patterns):
> >                 if self.field_types[fieldPos] == str:
> >                     # If useRegExp is True, compile the pattern to a
> >                     # regular expression object and add it to the
> >                     # new_patterns list.  Otherwise,  just add it to
> >                     # the new_patterns list.  This will be used below
> >                     # when matching table records against the
> > patterns.
> >                     if useRegExp:
> >                         new_patterns.append(re.compile(pattern))
> >                         # the pattern can be a tuple with re flags
> > like re.I
> >                     else:
> >                         new_patterns.append(pattern)
> >                 elif self.field_types[fieldPos] == bool:
> >                     # If type is boolean, I am going to coerce it to
> > be
> >                     # either True or False by applying bool to it.
> > This
> >                     # is because it could be '' or [].  Next, I am
> > going
> >                     # to convert it to the string representation:
> > either
> >                     # 'True' or 'False'.  The reason I do this is
> > because
> >                     # that is how it is stored in each record of the
> > table
> >                     # and it is a lot faster to change this one value
> > from
> >                     # boolean to string than to change possibly
> > thousands
> >                     # of table values from string to boolean.  And, if
> > they
> >                     # both are either 'True' or 'False' I can still
> >                     # compare them using the equality test and get the
> > same
> >                     # result as if they were both booleans.
> >                     new_patterns.append(str(bool(pattern)))
> >                 else:
> >                     # If type is int, float, date, or datetime, this
> > next
> >                     # bit of code will split the the comparison string
> >                     # into the string representing the comparison
> >                     # operator (i.e. ">=" and the actual value we are
> > going
> >                     # to compare the table records against from the
> > input
> >                     # pattern, (i.e. "5").  So, for example, ">5"
> > would be
> >                     # split into ">" and "5".
> >                     r = re.search('[\s]*[\+-]?\d', pattern)
> >                     if self.field_types[fieldPos] == int:
> >   

pywin32 - word object reference module - automating form filling

2009-06-09 Thread Brendan
I was hoping to use pywin32 to automate some rather tedious filling in
of Word forms. I thought
-- 
http://mail.python.org/mailman/listinfo/python-list


pywin32 - word object reference module - automating form filling

2009-06-09 Thread Brendan
I was hoping to use pywin32 to automate some rather tedious filling in
of Word forms. I thought
-- 
http://mail.python.org/mailman/listinfo/python-list


pywin32 - word object reference module - automating form filling

2009-06-09 Thread Brendan
I was hoping to use pywin32 to automate some rather tedious filling in
of Word forms. I thought the process would be analogous to dealing
with xml documents or DOM but find myself somewhat lost in the word
object reference manual (http://msdn.microsoft.com/en-us/library/
bb244515.aspx) .  I was hoping to easily load all document objects
into a list so that I could poke around, examine and experiment with
them. So far all I have managed to do is load the page content as a
string, not particularly helpful.

Could someone please point me in the right direction?

Also, help, __doc__ and dir do not return anything meaningful(to me
anyway) or helpful. There seem to be no exposed methods or properties.
e.g. I have a word document object:
wd = wordapp.Documents.Open('blah.dic')
But:
>>> dir(wd)
['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum',
'_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__cmp__',
'__doc__', '__getattr__', '__getitem__', '__init__', '__int__',
'__len__', '__module__', '__nonzero__', '__repr__', '__setattr__',
'__setitem__', '__str__', '_builtMethods_', '_enum_',
'_find_dispatch_type_', '_get_good_object_',
'_get_good_single_object_', '_lazydata_', '_make_method_',
'_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_',
'_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_']

And:
>>> print wd.__doc__

The dynamic class used as a last resort.
The purpose of this overriding of dynamic.CDispatch is to
perpetuate the policy
of using the makepy generated wrapper Python class instead of
dynamic.CDispatch
if/when possible.

Furthermore:
>>> help(wd)
Help on instance of CDispatch in module win32com.client object:

class instance(object)
 |  instance(class[, dict])
 |
 |  Create an instance without calling its __init__() method.
 |  The class must be a classic class.
 |  If present, dict must be a dictionary or None.
 |
 |  Methods defined here:
 |
 |  __abs__(...)
 |  x.__abs__() <==> abs(x)

~ ~ snip ~ ~

|  __truediv__(...)
 |  x.__truediv__(y) <==> x/y
 |
 |  __xor__(...)
 |  x.__xor__(y) <==> x^y
 |
 |  next(...)
 |  x.next() -> the next value, or raise StopIteration
 |
 |
--
 |  Data and other attributes defined here:
 |
 |  __new__ = 
 |  T.__new__(S, ...) -> a new object with type S, a subtype of T


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


Re: pywin32 - word object reference module - automating form filling

2009-06-09 Thread Brendan
On Jun 9, 9:54 am, Brendan  wrote:
> I was hoping to use pywin32 to automate some rather tedious filling in
> of Word forms. I thought the process would be analogous to dealing
> with xml documents or DOM but find myself somewhat lost in the word
> object reference manual (http://msdn.microsoft.com/en-us/library/
> bb244515.aspx) .  I was hoping to easily load all document objects
> into a list so that I could poke around, examine and experiment with
> them. So far all I have managed to do is load the page content as a
> string, not particularly helpful.
>
> Could someone please point me in the right direction?
>
> Also, help, __doc__ and dir do not return anything meaningful(to me
> anyway) or helpful. There seem to be no exposed methods or properties.
> e.g. I have a word document object:
> wd = wordapp.Documents.Open('blah.dic')
> But:>>> dir(wd)
>
> ['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum',
> '_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__cmp__',
> '__doc__', '__getattr__', '__getitem__', '__init__', '__int__',
> '__len__', '__module__', '__nonzero__', '__repr__', '__setattr__',
> '__setitem__', '__str__', '_builtMethods_', '_enum_',
> '_find_dispatch_type_', '_get_good_object_',
> '_get_good_single_object_', '_lazydata_', '_make_method_',
> '_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_',
> '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_']
>
> And:
>
> >>> print wd.__doc__
>
>     The dynamic class used as a last resort.
>     The purpose of this overriding of dynamic.CDispatch is to
> perpetuate the policy
>     of using the makepy generated wrapper Python class instead of
> dynamic.CDispatch
>     if/when possible.
>
> Furthermore:>>> help(wd)
>
> Help on instance of CDispatch in module win32com.client object:
>
> class instance(object)
>  |  instance(class[, dict])
>  |
>  |  Create an instance without calling its __init__() method.
>  |  The class must be a classic class.
>  |  If present, dict must be a dictionary or None.
>  |
>  |  Methods defined here:
>  |
>  |  __abs__(...)
>  |      x.__abs__() <==> abs(x)
>
> ~ ~ snip ~ ~
>
> |  __truediv__(...)
>  |      x.__truediv__(y) <==> x/y
>  |
>  |  __xor__(...)
>  |      x.__xor__(y) <==> x^y
>  |
>  |  next(...)
>  |      x.next() -> the next value, or raise StopIteration
>  |
>  |
> --
>  |  Data and other attributes defined here:
>  |
>  |  __new__ = 
>  |      T.__new__(S, ...) -> a new object with type S, a subtype of T
>
> What gives?

Hmmm.  The VB examples in the Word Object Reference give the best idea
of how to play with Word documents. No further help required on this
although I am still curious about why the python does not return the
"real" objects and methods for the COM object.
-- 
http://mail.python.org/mailman/listinfo/python-list


Alter list items within loop

2009-06-11 Thread Brendan
Can someone please explain what is happening in the output below? The
number 3 never gets printed. Does Python make a copy of a list before
it iterates through it?:
>>> e = range(1,5)
>>> for i in e:
print i
if i == 2 :
e.remove(i)


1
2
4
>>> e
[1, 3, 4]
-- 
http://mail.python.org/mailman/listinfo/python-list


exit() or sys.exit()

2009-06-17 Thread Brendan
What is the difference on exit() and sys.exit() when called in the
main body of a script? From the command line they seem to have the
same effect.

Aside: Just used a python dictionary in which the keys were compiled
regular expressions. Provided a very elegant solution. Have to love it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exit() or sys.exit()

2009-06-17 Thread Brendan
On Jun 17, 1:33 pm, Tim Chase  wrote:
> Brendan wrote:
> > What is the difference on exit() and sys.exit() when called in the
> > main body of a script? From the command line they seem to have the
> > same effect.
>
> In Python <=2.4 you had to use sys.exit() because
> __builtins__.exit() griped:
>
>    tch...@asgix:~$ python2.4
>    Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
>    [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
> Type "help", "copyright", "credits" or "license" for more
> information.
>    >>> type(exit)
>    
>    >>> exit()
>    Traceback (most recent call last):
>      File "", line 1, in ?
>    TypeError: 'str' object is not callable
>
> In 2.5, it's an instance of site.Quitter which is callable,
> allowing it to behave like sys.exit()  (from my observations,
> __builtins__.exit() and sys.exit() behave the same).
>
> I tend to use sys.exit() because I've still got code running on
> machines mired at 2.4
>
> -tkc

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


embarrassing class question

2010-10-21 Thread Brendan
Two modules:
x.py:
class x(object):
pass

y.py:
from x import x
class y(x):
pass

Now from the python command line:
>>> import y
>>> dir(y)
['__builtins__', '__doc__', '__file__', '__name__', '__package__',
'x', 'y']

I do not understand why class 'x' shows up here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embarrassing class question

2010-10-21 Thread Brendan
On Oct 21, 3:47 pm, Carl Banks  wrote:
> On Oct 21, 11:09 am, Brendan  wrote:
>
>
>
>
>
> > Two modules:
> > x.py:
> > class x(object):
> >     pass
>
> > y.py:
> > from x import x
> > class y(x):
> >     pass
>
> > Now from the python command line:>>> import y
> > >>> dir(y)
>
> > ['__builtins__', '__doc__', '__file__', '__name__', '__package__',
> > 'x', 'y']
>
> > I do not understand why class 'x' shows up here.
>
> Because you imported it into the namespace, which is what the import
> statement does.  dir() shows you what's in the namesace; therefore it
> lists x.  dir() doesn't care, and can't know, if something was defined
> in a namespace, or merely imported.
>
> If it bothers you, you can put "del x" after the class y definition,
> but I recommend against doing that in general.  If there's a reference
> to x inside a function that function will raise an exception if
> called, because it expects x to be inside the namespace.
>
> Carl Banks- Hide quoted text -
>
> - Show quoted text -

So it must never make sense to put subclasses in separate modules?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embarrassing class question

2010-10-21 Thread Brendan
On Oct 21, 3:56 pm, Ethan Furman  wrote:
> Jonas H. wrote:
> > On 10/21/2010 08:09 PM, Brendan wrote:
> >> Two modules:
> >> x.py:
> >> class x(object):
> >>      pass
>
> >> y.py:
> >> from x import x
> >> class y(x):
> >>      pass
>
> >> Now from the python command line:
> >>>>> import y
> >>>>> dir(y)
> >> ['__builtins__', '__doc__', '__file__', '__name__', '__package__',
> >> 'x', 'y']
>
> >> I do not understand why class 'x' shows up here.
>
> > Because that's how `import` behaves. It imports *every* member of the
> > module into the importing module's global namespace (except for
> > attributes that start with an underscore).
>
> Um, no.  (unless you do "from  import *" at the module level)
>
> What it does is add whatever you imported into the namespace where you
> imported it.
>
> Because y.py has "from x import x" the x class from x.py is added to the
> y.py namespace.
>
> ~Ethan~- Hide quoted text -
>
> - Show quoted text -

So what is usually done to prevent this? (In my case not wanting class
x added to the y.py namespace)
It seems sloppy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embarrassing class question

2010-10-22 Thread Brendan
On Oct 22, 5:02 am, Steven D'Aprano  wrote:
> On Thu, 21 Oct 2010 12:12:34 -0700, Brendan wrote:
> >> Because y.py has "from x import x" the x class from x.py is added to
> >> the y.py namespace.
>
> >> ~Ethan~- Hide quoted text -
>
> >> - Show quoted text -
>
> > So what is usually done to prevent this? (In my case not wanting class x
> > added to the y.py namespace)
> > It seems sloppy.
>
> (1) Don't import it in the first place.
>
> (2) Import it with a different name, possibly private:
>
> from module import x as _x
>
> (3) Delete it when you're done:
>
> from module import x
> class Y(x):
>     pass
> del x
>
> (4) Don't be so fussy and just accept that importing adds names to the
> namespace, as does any other assignment or class or function definition.
>
> --
> Steven

I'll take (2) and pass on (4)
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embarrassing class question

2010-10-22 Thread Brendan
On Oct 22, 9:16 am, Dave Angel  wrote:
> On 2:59 PM, Brendan wrote:> On Oct 21, 3:56 pm, Ethan 
> Furman  wrote:
> >> 
> >> Because y.py has "from x import x" the x class from x.py is added to the
> >> y.py namespace.
>
> >> ~Ethan~- Hide quoted text -
>
> >> - Show quoted text -
> > So what is usually done to prevent this? (In my case not wanting class
> > x added to the y.py namespace)
> > It seems sloppy.
>
> Since you make the common mistake of using the same name for the module
> as you do for the class, it's hard to demonstrate.  But if you used Pep8
> naming conventions, the classes would be capitalized.
>
> Instead of using
>
> from x import X
>
> try using
>
> import x
>
> class Y(x.X):
>      pass
>
> Now, you still have a symbol x in your namespace, but it's just the
> module, which is perfectly public.  So you could access a dozen classes
> within x, but only the module itself would be visible to others.
>
> As someone else pointed out, you could also delete the module reference
> when you're done with it.
>
> import x
>
> class Y(x.X):
>      pass
>
> del x
>
> DaveA

x.py
class X(object):
pass

y.py
import x
class Y(x.X):
pass

z.py
import x
import y
class ZX(x.X):
pass
class ZY(y.Y):
pass

w.py
import x
import y
import z
class WX(x.X):
pass
class WY(y.Y):
pass
class WZX(z.ZX):
pass
class WZY(z.ZY):
pass

>>> import x, y, z, w
>>> dir(x)
['X', '__builtins__', '__doc__', '__file__', '__name__',
'__package__']
>>> dir(y)
['Y', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', 'x']
>>> dir(z)
['ZX', 'ZY', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', 'x', 'y']
>>> dir(w)
['WX', 'WY', 'WZX', 'WZY', '__builtins__', '__doc__', '__file__',
'__name__', '__package__', 'x', 'y', 'z']
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ftplib - Did the whole file get sent?

2010-10-25 Thread Brendan
On Oct 23, 1:03 pm, Sean DiZazzo  wrote:
> On Oct 22, 10:48 pm, Steven D'Aprano 
> cybersource.com.au> wrote:
> > On Fri, 22 Oct 2010 22:03:38 -0700, Sean DiZazzo wrote:
> > > How can I assure him (and the client) that the transfer completed
> > > successfully like my log shows?
>
> > "It has worked well for many years, there are no reported bugs in the ftp
> > code
> > [...]
>
> Thanks for your advice Steven.  I agree with you,and did take that
> approach to start with.  Then the request for the actual FTP "ack"
> caught me off guard.  I had to break out Wireshark and run a few tests
> just to make sure I knew exactly what I was talking about.
>
> I think I will try to explain that asking for the "ack" is not really
> a valid request.  Something like this:
>
> "Technically, these messages are used only on the lowest level of the
> FTP protocol itself.  Any client or library implementing FTP would be
> sending these messages under the covers...in this case I think its
> done in the socket library.  It is possible that there is a bug in the
> Python FTP library, just like it's possible there is a bug in any
> other FTP client.  Considering how long this library has been around
> (~15-20 years), and how often it is used, it is very unlikely that a
> bug causing a partial transfer but showing a success has managed to
> stick around for so long."
>
> Does that make sense?
>
> > > Is ftplib reliable enough to say that if an exception is not thrown,
> > > that the file was transferred in full?
>
> > Python 2.4 is pretty old. Have you checked the bug tracker to see if
> > there are any reported bugs in ftplib that might be relevant? Or the
> > What's New for 2.5, 2.6 and 2.7? The source code for ftplib seems fairly
> > straightforward to me -- if there was an error, I can't see that it could
> > have been suppressed.
>
> > But really, unless you can reproduce the error, I'd say the error lies
> > elsewhere.
>
> > --
> > Steven
>
> I'll check bugs and whats new before sending any response.  The more I
> think about this, I am beginning to think that he is just trying to
> find someone to blame for a problem, and has chosen me.
>
> Thanks again.
>
> ~Sean

Your boss is both moron and wanker.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embarrassing class question

2010-10-25 Thread Brendan
On Oct 22, 2:21 pm, Peter Pearson  wrote:
> On Fri, 22 Oct 2010 07:49:39 -0700 (PDT), Brendan wrote:
>
> [snip]
>
>
>
>
>
> > x.py
> > class X(object):
> >     pass
>
> > y.py
> > import x
> > class Y(x.X):
> >     pass
>
> > z.py
> > import x
> > import y
> > class ZX(x.X):
> >     pass
> > class ZY(y.Y):
> >     pass
>
> > w.py
> > import x
> > import y
> > import z
> > class WX(x.X):
> >     pass
> > class WY(y.Y):
> >     pass
> > class WZX(z.ZX):
> >     pass
> > class WZY(z.ZY):
> >     pass
>
> >>>> import x, y, z, w
> >>>> dir(x)
> > ['X', '__builtins__', '__doc__', '__file__', '__name__',
> > '__package__']
> >>>> dir(y)
> > ['Y', '__builtins__', '__doc__', '__file__', '__name__',
> > '__package__', 'x']
> >>>> dir(z)
> > ['ZX', 'ZY', '__builtins__', '__doc__', '__file__', '__name__',
> > '__package__', 'x', 'y']
> >>>> dir(w)
> > ['WX', 'WY', 'WZX', 'WZY', '__builtins__', '__doc__', '__file__',
> > '__name__', '__package__', 'x', 'y', 'z']
>
> I apologize for being dense, but I don't understand what bothers
> you about this behavior.  Yes, module w imports x, and therefore
> w.x exists.  Is that bad?
>
> --
> To email me, substitute nowhere->spamcop, invalid->net.- Hide quoted text -
>
> - Show quoted text -

No worries. I am the one who is dense. What bothers me is that I have
not noticed this before when importing other Python modules. I use
Python sporadically, and frequently use the dir command to learn or
remind myself of class methods. Python examples/tutorials on classes
always show everything(classes and subclasses) in the same module.
-- 
http://mail.python.org/mailman/listinfo/python-list


j2py - overloading __init__

2010-10-25 Thread Brendan
I am posting here in the hopes the author of java2python will see it.
Does j2py handle overloading of the __init__ constructor?  For me it
is calling __init__ and not calling the decorator overloaded __init__0.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: j2py - overloading __init__

2010-10-25 Thread Brendan
On Oct 25, 12:57 pm, Brendan  wrote:
> I am posting here in the hopes the author of java2python will see it.
> Does j2py handle overloading of the __init__ constructor?  For me it
> is calling __init__ and not calling the decorator overloaded __init__0.

Never mind. Moronic type mistake.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python benefits over Cobra

2011-04-05 Thread Brendan Simon



>  On 05-Apr-11 06:22 AM, Brendan Simon (eTRIX) wrote:
>>
>>  Any other arguments where Python has benefits over Cobra ??
>>
>>  Cheers, Brendan.
>>
>  Two questions:
> 1. Is Cobra Open Source?
> 2. The blog ended on October, did he run out of steam?
>
>  I liked the '.', in place of '.self', but that's been rejected for Python.


"Cobra is an open source project under the MIT license." according to 
the web site.


It seems that it mostly, if not all, the work of one person.  All code 
commits seem to be from Charles Esterbrook.


It seems the latest release is Oct 2010, but I can see posts in the 
forum for April 2011, March, Feb, .


I too like the '.' in place of self :)  However, I don't like _ as line 
continuation :(   Life is tough, eh ??


It also looks like there is work to have it run in a JVM.  I presume 
that means that no .NET/Mono framework is required ??


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


Re: Python inner function parameter shadowed

2016-09-13 Thread Brendan Abel
This looks like a decorator function that optionally accepts arguments to
change the behavior.

You can safely ignore the warning form PyCharm.  the variable won't be
shadowed it's included in the function signature of the inner function.

A lot of times, the outside decorator will just use the *args or **kwargs
parameters and check whether the first arg is callable or not and if any
keywords have been passed in to decide which version of the wrapped
function to return

Here is an example:
http://stackoverflow.com/questions/653368/how-to-create-a-python-decorator-that-can-be-used-either-with-or-without-paramet

On Tue, Sep 13, 2016 at 9:40 AM, Chris Angelico  wrote:

> On Wed, Sep 14, 2016 at 2:34 AM, Daiyue Weng  wrote:
> > Hi, I am using inner function like this,
> >
> > def timeit(func=None, loops=1, verbose=False):
> > if func is not None:
> > def inner(*args, **kwargs):
> >
> > # some code
> >
> > return inner
> > else:
> > def partial_inner(func):
> > return timeit(func, loops, verbose)
> >
> > return partial_inner
> >
> >
> > PyCharm warns about "Shadows name 'func' from outer scope" on
> >
> > def partial_inner(func):
> >
> > How to fix it?
> >
> > cheers
>
> Hmm. I think the real solution here is to separate this into two functions:
>
> def timeit(func, loops=1, verbose=False):
> def inner(*args, **kwargs):
>
> # some code
>
> return inner
>
> def timeit_nofunc(loops=1, verbose=False):
> def partial_inner(func):
> return timeit(func, loops, verbose)
> return partial_inner
>
> But without knowing more about what you're accomplishing, I can't
> really say. If you just want a quick fix to shut the linter up (note
> that this is NOT a Python error, it's just a message from a linter),
> you could use a different name for one of the variables.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python inner function parameter shadowed

2016-09-13 Thread Brendan Abel
Yeah, you could change the name, but it shouldn't matter, the "func" in the
inner function will always be the one passed into it, it won't be the
"func" from the outer function, which in this specific case, would always
be None (at least as far as the second inner function is concerned.)

On Tue, Sep 13, 2016 at 11:31 AM, Chris Angelico  wrote:

> On Wed, Sep 14, 2016 at 4:28 AM, Brendan Abel <[email protected]>
> wrote:
> > This looks like a decorator function that optionally accepts arguments to
> > change the behavior.
>
> Oh, I get it. So, yeah, it is one function doing two jobs -
> legitimately. In that case, I'd just rename one of the 'func'
> arguments - probably the inner one, since that's never going to be
> passed as a keyword.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is the correct form for saying "licensed under the same terms as Python itself"?

2016-09-14 Thread Brendan Abel
Unless you're actually distributing python (as in, the interpreter or it's
source code), you don't need to include the python license or the copyright
notice.  You also don't need a Contributor agreement just to distribute a
python library.  That is more for people who are contributing to core
Python or if your package is being added to the standard library.

Python has a custom license, though it is GPL-compatible.  The python
license has a lot of wording that is specific to python and the PSF, so it
probably doesn't make sense for you to use their license.  Also, according
to the python web site, they only accept contributions under the following
licenses:


   - Academic Free License v. 2.1
   
   - Apache License, Version 2.0
   

https://www.python.org/psf/contrib/

So, if you want your code to be available to the Python team (which is what
it sounds like), you should use one of those 2 licenses, or consider using
an even more permissive license (like the MIT license) that would not
prohibit your project from being relicensed under the Apache or Python
license.

On Wed, Sep 14, 2016 at 7:58 AM, Mark Summerfield 
wrote:

> Hi,
>
> I'm developing a small Python software library that I want to publish as
> free software under the same terms as Python itself.
>
> I notice that a few of Python's own files begin like this:
>
> # Copyright 2007 XXX. All Rights Reserved.
> # Licensed to PSF under a Contributor Agreement.
>
> Is this form sufficient?
> Do I need to include the PSF license with the package?
> (Also, I don't actually remember if I've signed a Contributor Agreement.)
>
> Thanks!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to import all things defined the files in a module directory in __init__.py?

2016-09-24 Thread Brendan Abel
> Splitting it up would make it slower to load.

It's usually the opposite.  When packages are split up, you only have to
load the specific portions you need.  Putting it all in a single module
forces you to always load everything.

On Fri, Sep 23, 2016 at 11:59 PM, Lawrence D’Oliveiro <
[email protected]> wrote:

> On Saturday, September 24, 2016 at 2:11:09 PM UTC+12, Chris Angelico wrote:
> > It's a large and complex module, and about at the boundary of being
> > broken up a bit.
>
> Splitting it up would make it slower to load.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-29 Thread Brendan Abel
Yes, loops don't have their own scope.  Indeed, very few flow elements in
python -- if, with, try/except -- create a new scope.  In that sense, it's
fairly consistent, but can be unexpected for people that have used
languages with many nested scopes.

The lambda behavior is a common gotcha - there are hundreds of questions on
StackOverflow that are caused by that misunderstanding

http://stackoverflow.com/questions/7368522/weird-behavior-lambda-inside-list-comprehension

The most common solution is to just provide the variable as a default
argument to the lambda function, which will bind it how you'd expect

[lambda base, exponent=exponent: (base ** exponent) for exponent in
range(9)]

On Thu, Sep 29, 2016 at 12:29 PM,  wrote:

> hello pythonistas
>
> i've had a nodding acquaintance with python for some time, and all along i
> assumed that for-loops got a namespace of their own; now i'm reading up on
> the language and i find out that's not the case: the loop variable gets put
> into the enclosing namespace, overwriting any former value that was already
> there; of course i realize there are situations where one is interested in
> the value that a loop variable has after the loop has been exited, but this
> behavior seems grossly unintuitive to me: has there ever been any
> discussion of giving for-loops the option of running in namespaces of their
> own?
>
> and it gets even worse; consider the following means of raising an
> exception:
>
> #)-- begin code
>
> def powerfunction(exponent):
> return lambda base: (base ** exponent)
>
> p1 = [powerfunction(exponent) for exponent in range(9)]
> p2 = [lambda base: (base ** exponent) for exponent in range(9)]
>
> assert p1[3](4) == p2[3](4)
>
> #) end code
>
> apparently the problem is that "exponent" gets evaluated when the relevant
> lambda function is run, not when it's defined, but no binding for
> "exponent" gets put into the enclosing namespace: it seems that python
> remembers this ghostly "exponent" for me on the theory that i don't WANT
> "p1" and "p2" to be the same; can anyone help to reconcile me to this
> semantics?
>
> thanks if you can help
> stm
>
>
>
>
>
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-30 Thread Brendan Abel
> a = 1
if condition:
print(a)  # UnboundLocalError: local 'a' referenced before assignment
a += 1


For-loops are no different. Making them their own namespace is a very
strange thing to do, it would mean you couldn't re-bind a value inside a
for-loop:

count = 0
for x in sequence:
count += 1
# raises UnboundLocalError: local 'count' referenced before assignment

--

That's generally not how nested scopes work, you could still reference
objects in the outer scope from the inner scope, but the outer scope
couldn't reference objects in the inner scope

a = 1
if condition:
b = a + 2

print b # UnboundLocalError: local 'b' referenced before assignment


for x in sequence:
print x

print x  # UnboundLocalError: local 'x' referenced before assignment.


--

I wouldn't call either behavior intuitive or unintuitive.  They're just
different behaviors of different languages.


On Fri, Sep 30, 2016 at 5:33 AM, Steve D'Aprano 
wrote:

> On Fri, 30 Sep 2016 05:29 am, [email protected] wrote:
>
> > hello pythonistas
> >
> > i've had a nodding acquaintance with python for some time, and all along
> i
> > assumed that for-loops got a namespace of their own;
>
> Giving for-loops their own namespace is a grossly unintuitive and a very
> weird thing to do. Modules, classes and functions are obviously namespaces.
> Why should arbitrary syntactic structures create their own namespace?
>
> It would be terribly inconvenient and surprising for if...else blocks to be
> separate namespaces:
>
> a = 1
> if condition:
> print(a)  # UnboundLocalError: local 'a' referenced before assignment
> a += 1
>
>
> For-loops are no different. Making them their own namespace is a very
> strange thing to do, it would mean you couldn't re-bind a value inside a
> for-loop:
>
> count = 0
> for x in sequence:
> count += 1
> # raises UnboundLocalError: local 'count' referenced before assignment
>
>
> unless you declared it nonlocal or global, depending on whether your for
> loop was inside a function or not.
>
> To me, "make for-loops be their own scope" sounds like a joke feature out
> of
> joke languages like INTERCAL. I'm not aware of any sensible language that
> does anything like this.
>
> No, wait a minute, I tell a lie, I recall Chris Angelico mentioning that
> one
> of his favourite languages, Pike or REXX, does it. I forget which.
>
>
>
>
> --
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Passing Variable to Function

2016-10-05 Thread Brendan Abel
Define your colors as actual number variables instead of a string

color = (255,0,0)
color2 = (0,0,255)

Then use argument expansion to pass them in as separate arguments to the
function

colorFunction(*color)

Brendan

On Wed, Oct 5, 2016 at 12:17 PM, John McKenzie 
wrote:

>
>  Hello, all.
>
>  I have a function that takes three arguments, arguments to express an RGB
> colour. The function controls an LED light strip (a Blinkytape).
>
>  Sometimes I might need to be change what colour is sent to the function,
> so I set a variable with the idea that I can change just the variable
> later if I need to instead of changing a bunch of different lines.
>
> So I have variables along the lines of this:
>
> colour ="255, 0, 0"
> colour2 ="100, 0, 0"
>
>
> My function, written by the Blinkytape people:
>
>
> def changeColor(r, g, b):
>  serialPorts = glob.glob("/dev/ttyACM0*")
>  port = serialPorts[0]
>
>  if not port:
>  sys.exit("Could not locate a BlinkyTape.")
>
>  print "BlinkyTape found at: %s" % port
>
>  bt = BlinkyTape.BlinkyTape(port)
>  bt.displayColor(r, g, b)
>  time.sleep(.1)  # Give the serial driver some time to actually send
> the data
>  bt.close()
>
>
>  Later, I have conditional statements like:
>
>
> if latitude > maxNetural and latitude < NorthLine:
> changeColor(colour)
> elif latitude > NorthLine:
> changeColor(colour2)
>
>
>
> (There is a GPS device connected, there are variables defined based on
> latitude earlier in the script.)
>
>  I get an error stating that changeColor takes three arguments and I am
> just giving it one (either "colour1" or "colour2").
>
>
>  Is there a way to format the "colour" variable so that the changeColor
> function takes it as the three numbers it is meant to be defined as?
>
>
> Entire script:
> http://hastebin.com/qaqotusozo.py
>
>
>  Thanks.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: User Interface Suggestions? (newbie)

2016-10-05 Thread Brendan Abel
You should look into using PyQt or PySide.  They are python bindings for
the very popular Qt GUI framework.



On Wed, Oct 5, 2016 at 2:33 PM, Beverly Howard  wrote:

> >> if it is a pi controlling the system I would tend towards controlling it
> from a web page via the network. to keep it updating would require AJAX
> style programming of the web page. <<
>
> Thanks.  I am interested in eventually doing that, but it seems that
> learning how to do it on a local console first would be to my advantage...
> especially during initial testing stages.
>
> fwiw, this project is to transfer (actually re-create) a basic program
> that I wrote for a Tandy Model 100 portable back in the early 80's to
> control ceramic kilns which get to over 2,000 degrees F.
>
> Worked perfectly until a few years ago when there were no longer any Tandy
> Model 100s available at any cost ;-)  (In case anyone is interested in
> fossilized projects, see http://bevhoward.com/kiln/KilnCtrl.htm)
>
> Thanks again for the response and pointers,
> Beverly Howard
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Are imports supposed to be like this?

2016-05-09 Thread Brendan Abel
Consider the following example python package where `a.py` and `b.py`
depend on each other:

/package
__init__.py
a.py
b.py


There are several ways I could import the "a.py" module in "b.py"

import package.a   # Absolute import
import package.a as a_mod  # Absolute import bound to different name
from package import a  # Alternate absolute import
import a   # Implicit relative import (deprecated, py2
only)
from . import a# Explicit relative import

Unfortunately, only the 1st and 4th syntax actually work when you have
circular dependencies (the rest all raise `ImportError` or
`AttributeError`), and the 4th syntax only works in python 2 and is
generally discouraged because of the possibility of name conflicts.

I'd much rather use relative imports, or the "from x import y" syntax, or
at least be able to use the "as" import syntax.  If I have a deeply nested
package, the imports become unruly rather quickly, and I have to use that
long, ugly name throughout the entire module!

import package.subpackage.submodule.module  # fugly!

Are imports designed to work this way, or is this a bug in the import
machinery?  What reasoning is there for the first syntax to work, but all
the others should fail?  Admittedly, I haven't used Python3 yet, does it
fix this?  It seems odd to me that the documentation seems to encourage
relative imports or at least the "from x.y.z import a" forms of imports,
yet they don't work the same as "import x.y.z.a".


//Brendan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Were is a great place to Share your finished projects?

2016-07-14 Thread Brendan Abel
A lot of these arguments and points have already been made and hashed out
on the python-dev list.  There's a very good article that one of the python
core developers wrote about the decision to move to github

http://www.snarky.ca/the-history-behind-the-decision-to-move-python-to-github

Basically, maintaining an open source git server, bug tracker, etc. would
have cost time and money, and historically very few people were willing to
contribute those, especially the people who were the most opinionated on
the desire to remain "pure to open source".  Github gives all these things
away for free.  And pretty much every python developer has already used
github for other projects.  In the article he makes a good point that if
you're that worried about always using open-source, then you shouldn't be
using gmail, or twitter, or even automobiles, since they all use software
that is closed-source.  At some point, paying for software just makes sense.



On Thu, Jul 14, 2016 at 12:34 PM, Terry Reedy  wrote:

> On 7/14/2016 3:04 PM, [email protected] wrote:
>
> Python's primary repository is Mercurial (hg.python.org), not Git.
>>
>
> CPython's current repository 
> Ditto for the PSF Python docs.
>
> Were python to switch,
>>
>
> Like it or not, CPython and the Docs are moving to git and github.
> PEPs and the devguide have already been moved.
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: reversed(enumerate(x))

2016-07-20 Thread Brendan Abel
You could create your own generator that wraps enumerate

def reverse_enumerate(iterable):
for i, val in enumerate(reversed(iterable)):
yield len(iterable) - 1 - i, val

for i, val in reverse_enumerate(x):
...

On Wed, Jul 20, 2016 at 10:42 AM, Ian Kelly  wrote:

> I had occasion to write something like this:
>
> for i, n in reversed(enumerate(x)): pass
>
> Of course this fails with "TypeError: argument to reversed() must be a
> sequence". I ended up using this instead:
>
> for i, n in zip(reversed(range(len(x))), reversed(x)): pass
>
> This works but is extraordinarily ugly and not terribly clear. I think
> it's less confusing however than:
>
> for i, n in zip(range(len(x)-1, -1, -1), reversed(n)): pass
>
> How would you write this?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unittest

2016-07-25 Thread Brendan Abel
Generally, all your unittests will be inside a "tests" directory that lives
outside your package directory.  That directory will be excluded when you
build or install your project using your setup.py script.  Take a look at
some popular 3rd party python packages to see how they structure their
projects and setup their setup.py.

On Mon, Jul 25, 2016 at 9:45 AM, Joaquin Alzola 
wrote:

> Hi Guys
>
> I have a question related to unittest.
>
> I suppose a SW that is going to live will not have any trace of unittest
> module along their code.
>
> So is it the way to do it to put all unittest in a preproduction
> environment and then remove all lines relate to unittest once the SW is
> release into production?
>
> What is the best way of working with unittest?
>
> BR
>
> Joaquin
>
> This email is confidential and may be subject to privilege. If you are not
> the intended recipient, please do not copy or disclose its content but
> contact the sender immediately upon receipt.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Jargons of Info Tech industry

2005-10-13 Thread Brendan Guild
Roedy Green wrote in news:[EMAIL PROTECTED]:

> On Tue, 11 Oct 2005 11:45:03 -0400, Mike Meyer <[EMAIL PROTECTED]> wrote
> or quoted :
> 
>>Jeff Poskanzer, now *he* has a spam problem. He gets a few million
>>spams a day: http://www.acme.com/mail_filtering/ >.
> 
> It is a bit like termites. If we don't do something drastic to deal
> with spam, the ruddy things will eventually make the entire Internet
> unusable.
> 
> the three keys to me are:
> 
> 1. flipping to a digital id based email system so that the sender of
> any piece of mail can be legally identified and prosecuted.
> If every piece of anonymous email disappeared that would go a long
> way to clearing up spam.  Let those sending ransom notes, death
> threats and  hate mail use snail mail.  As a second best,
> correspondents are identified by permission/identity/encryption keys
> given to them by their recipients.

The first part seems rather expensive and I'm not sure it would help. 
Is spam illegal? I don't see how it can be. I mean, those messages are 
annoying, but not that annoying. I get unsolicited email that I 
actually want often enough to want to avoid gumming it up in legal 
issues.

The second part seems like it would be annoying for the recipients and 
would make just sending ordinary email more complicated.

> 2. flipping to a sender pays system so that the Internet does not
> subsidise spam.

This is very promising. Our ISPs should put limits on how much email we 
can send. The limits should be rather insane, nothing that any 
nonspammer would ever come close to, but low enough to stop spam dead. 
If we want to send more than that, we'd better be charged extra.

We could make each mail server responsible for the spam that it sends 
out. It seems that currently mail servers are swamped and spending big 
money on handling the vast loads of spam that gets pumped into them 
from other mail servers, so I'm sure they wouldn't mind having a rule 
like: Refuse to allow email to be transported from any server that 
spews more than 50% spam. Servers could be audited occasionally to 
check if they are spammers.

I don't know exactly how spammers send spam, but a rule like that would 
sure stop ISPs from allowing any one person to send a thousand emails a 
day.

In fact, if 99% of the email sent is spam, then we can safely assume 
that the proper email traffic is 1/100th of what it is now. We just 
have to close the valves a little. Mail servers could have an upper 
limit on how much they will transfer each day to force restrictions 
throughout the system and finally to the individual emailer. I'd rather 
have my mail server give me an error message saying that I've sent too 
much email every once in a while than have the entire Internet clogged 
with spam.

[snipped third key]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jargons of Info Tech industry

2005-10-13 Thread Brendan Guild
Gordon Burditt wrote in
news:[EMAIL PROTECTED]: 

> Does the language allow Javascript to open a new window?  Does the
> language allow Javascript to trigger a function when a window is
> closed?  I believe the answer to both questions is YES.  Then it
> is possible to have a page that pops up two windows whenever you
> close one.

This was a problem, but modern browsers implement Javascript in such a 
way that it requires permission from the user before it will open a new 
window.

> If it can reveal my email address to any web site, it's a bug.  If
> it can access or alter my personal files or address book, it's a
> bug.  If it can generate hits on web sites other than that specified
> in the HTML, it's a bug.  If it can open sockets, it's a bug.
> If it can look at or set cookies stored on my system, it's a bug.
> If it can look at or alter the list of previously visited URLs, it's
> a bug.

All of those things seem like major problems except the bit about 
cookies. What possible harm can reading and setting cookies do? I had 
always thought they were carefully and successfully designed to be 
harmless. That's not personal information in your cookies. That 
information is set by websites for the sole purpose of being read by 
websites. Plus, I'm pretty sure that browsers have always allowed us to 
disable cookies.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FTP Windows AS/400

2005-09-13 Thread Brendan Bispham
Hi Tim,
On Tuesday 13 September 2005 17:31, Tim G. wrote:

> I cannot get the script to switch from native to IFS. 

Yes you can...

> Traceback (most recent call last):
>   File "C:\Python24\Tools\scripts\ftp400.py", line 9, in ?
> ftp.cwd(path)

It's the cwd which is having a problem

> here is the script:
>
> import ftplib, os
>
> filename=''
> path = "directory"

Change the path to an absolute path, eg:
>>> ftp.sendcmd('site namefmt 1')
'250  Now using naming format "1".'
>>> ftp.cwd('/home')
'250 "/home" is current directory.'

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


Re: standard IDE in python 3000 (or beyond)? *semi-newbie*

2004-12-30 Thread Brendan Kohler
"mike kreiner" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Are there any plans for developing a standard IDE for python that's
> included with the python installation? I found information about other
> IDE's elsewhere online, but couldn't even find any mention of this
> possibility.
>
> I'm still relatively new to Python--I switched over from VB--and I
> found it difficult to learn python without an IDE. Most experienced
> programmers I know started out using Emacs or another text editor, and
> are very happy with that; however, I found it difficult to put all the
> pieces (like GUI, etc.) together myself. i tried many of the free IDEs,
> but was dissatisfied (VS is tough to beat in my opinion, much better
> than the average m$ application *plz don't flame*). although it'd be a
> difficult undertaking, i think an IDE would be a tremendous boost for
> python in terms of gaining support in education and the business
> community. has anyone else discussed this? does anyone know the BDFL's
> stance? thanks.
>
> ~mike
>

That would be something called IDLE, which is included with python already.


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


Imports and cyclical dependencies

2013-11-13 Thread Brendan Abel
I have a relatively large python package that has several cyclical 
dependencies.  The cyclical dependencies typically aren't a problem so long as 
I'm just importing modules, and not named attributes (ie. function, class, 
globals), which may not be defined at a given point in the import routine 
because of the cyclical dependency.

The problem I'm encountering is that relative imports and any import that uses 
the  "from package import module" or "import package.module as module" syntax 
results in an ImportError (or AttributeError for the "as" syntax).  I would 
much rather use this import syntax for several reasons:

1. Relative imports seem to be the recommended syntax going forward for 
intra-package imports.
2. One of the two import syntaxes that work does not work in Python3, or if 
absolute imports are used in Python2.
3. Imports with nested subpackages are wordy (eg. package.packa.packb.module) 
and make the code longer and harder to read.

I posted the question to stackoverflow with an example and got some useful 
information, but not the answer I was looking for.

http://stackoverflow.com/questions/19822281/why-do-these-python-import-statements-behave-differently

At this point, I'm wondering if I should report this as a bug/feature request, 
since it seems that these imports should be able to resolve to the correct 
module.
-- 
https://mail.python.org/mailman/listinfo/python-list


what's wrong here? (search script)

2006-07-06 Thread Brendan Fay
Dear Someone:

 I have written a script that accesses the googleAPI through
pygoogle and saves each of the ten documents as a .txt file by using a
specific function for each respective file type (.doc, .pdf, .html) to
convert it to such.  Everything works fine, except that I am trying to
make it search and return another result in the event that a file type
other than .doc, .pdf, .html, or .txt comes up.  Python is new to me
and I'm not sure why my method doesn't work.  I'd really appreciate any
advice; here is the relevant code:

def searchhelper(words, start=0, max=10):
data = google.doGoogleSearch(words)
objlist = data.results
urllist = map((lambda x: x.URL), objlist)
return urllist


def searchhelper2(initwords, urls, counter):
for url in urls:
if findinlink(url, 'pdf'): # all these functions are defined
elsewhere,
convertpdf(url)  # fbut they definitely are working 
properly
elif findinlink(url, 'htm'):
converthtml(url)
elif findinlink(url, 'txt'):
urllib.urlretrieve(url, parse(x))
elif findinlink(url, 'doc'):
convertdoc(url)
elif not findinlink(url, '.'):
converthtml(url)
else:
urllist = urls[counter + 1:] + searchhelper(initwords, 
11 + counter,
1) # (I'm
searchhelper2(initwords, urllist, counter + 1)# 
assuming this is
where I have  #
  erred; however, I'm not sure)


def search(initwords):
urllist = searchhelper(initwords)
searchhelper2(initwords, urllist, 0)

Thanks,
Brendan

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


Re: what's wrong here? (search script)

2006-07-06 Thread Brendan Fay
I figured it out.  Is there any way to delete your own posts?

Brendan Fay wrote:
> Dear Someone:
>
>  I have written a script that accesses the googleAPI through
> pygoogle and saves each of the ten documents as a .txt file by using a
> specific function for each respective file type (.doc, .pdf, .html) to
> convert it to such.  Everything works fine, except that I am trying to
> make it search and return another result in the event that a file type
> other than .doc, .pdf, .html, or .txt comes up.  Python is new to me
> and I'm not sure why my method doesn't work.  I'd really appreciate any
> advice; here is the relevant code:
>
> def searchhelper(words, start=0, max=10):
>   data = google.doGoogleSearch(words)
>   objlist = data.results
>   urllist = map((lambda x: x.URL), objlist)
>   return urllist
>
>
> def searchhelper2(initwords, urls, counter):
>   for url in urls:
>   if findinlink(url, 'pdf'): # all these functions are defined
> elsewhere,
>   convertpdf(url)  # fbut they definitely are working 
> properly
>   elif findinlink(url, 'htm'):
>   converthtml(url)
>   elif findinlink(url, 'txt'):
>   urllib.urlretrieve(url, parse(x))
>   elif findinlink(url, 'doc'):
>   convertdoc(url)
>   elif not findinlink(url, '.'):
>   converthtml(url)
>   else:
>   urllist = urls[counter + 1:] + searchhelper(initwords, 
> 11 + counter,
> 1) # (I'm
>   searchhelper2(initwords, urllist, counter + 1)# 
> assuming this is
> where I have  #
>       erred; however, I'm not sure)
>
>
> def search(initwords):
>   urllist = searchhelper(initwords)
>   searchhelper2(initwords, urllist, 0)
> 
> Thanks,
> Brendan

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


pep 8 constants

2009-01-13 Thread Brendan Miller
PEP 8 doesn't mention anything about using all caps to indicate a constant.

Is all caps meaning "don't reassign this var" a strong enough
convention to not be considered violating good python style? I see a
lot of people using it, but I also see a lot of people writing
non-pythonic code... so I thought I'd see what the consensus is.

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


Re: pep 8 constants

2009-01-13 Thread Brendan Miller
> FOO = 1
>
> def f(x=FOO):
>   ...
>
>
> Use this instead:
>
> def f(x=1):
>   ...


I tend to use constants as a means of avoiding the proliferation of
magic literals for maintenance reasons... Like say if your example of
FOO would have been used in 10 places. Maybe it is more pythonic to
simply denote such a thing as simply a normal variable? That doesn't
seem to give a hint that it shouldn't be assigned a second time.
--
http://mail.python.org/mailman/listinfo/python-list


what's the point of rpython?

2009-01-16 Thread Brendan Miller
So I kind of wanted to ask this question on the pypy mailing list..
but there's only a pypy-dev list, and I don't want to put noise on the
dev list.

What's the point of RPython? By this, I don't mean "What is RPython"?
I get that. I mean, why?

The goals of the pypy project seems to be to create a fast python
implementation. I may be wrong about this, as the goals seem a little
amorphous if you look at their home page.

So, to do that this RPython compiler was created? Except that it
doesn't compile python, it compiles a static subset of python that has
type inference like ML.

This RPython thing seems like a totally unnecessary intermediate step.
Instead of writing an implementation of one language, there's an
implementation of two languages.

Actually, it seems like it harms the ultimate goal. For the
interpreted pyton to be fast, the interpreter has to be written in a
reasonably fast language. ML, and C++ compilers have had a lot of work
put into their optimization steps. A lot of the performance boost you
get from a static language is that knowing the types at compile time
lets you inline code like crazy, unroll loops, and even execute code
at compile time.

RPython is a statically typed language because I guess the developers
associate static languages with speed? Except that they use it to
generate C code, which throws away the type information they need to
get the speed increase. Huh? I thought the goal was to write a fast
dynamic language, not a slow static one?

Is this going anywhere or is this just architecture astronautics?

The RPython project seems kind of interseting to me and I'd like to
see more python implementations, but looking at the project I can't
help but think that they haven't really explained *why* they are doing
the things they are doing.

Anyway, I can tell this is the sort of question that some people will
interpret as rude. Asking hard questions is never polite, but it is
always necessary :)

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


Re: what's the point of rpython?

2009-01-17 Thread Brendan Miller
>> The goals of the pypy project seems to be to create a fast python
>> implementation. I may be wrong about this, as the goals seem a little
>> amorphous if you look at their home page.
>
> The home page itself is ambiguous, and does oversell the performance
> aspect. The *actual* goal as outlined by their official docs is to
> implement Python in Python, at every level.

Ok fair enough. In some ways I see that as more of a purely
intellectual exercise than the practical endeavor that I assumed the
project was originally.

However, one of the links I was sent had one of the devs talking about
using the translation process to make C/Java/LLVM implementations out
of the same interpreter code. I'll say that makes a lot of sense.

Another question I was wondering about is whether they plan on
maintaining good C bindings? Will existing bindings for third party
libraries be able to work?

Also, are they going to do away with the GIL? The python devs seem to
consider the GIL a non-issue, though they may change their mind in 3
years when we all have 32 core desktops, until then getting rid of the
GIL would make pypy pretty attractive in some quarters. I know the
scons project was running into GIL issues.

Finally, I'm pretty unclear on what versions of python that pypy is targeting.
--
http://mail.python.org/mailman/listinfo/python-list


Re: what's the point of rpython?

2009-01-18 Thread Brendan Miller
On Sat, Jan 17, 2009 at 7:57 PM, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> alex23  writes:
>> Here's an article by Guido talking about the last attempt to remove
>> the GIL and the performance issues that arose:
>>
>> "I'd welcome a set of patches into Py3k *only if* the performance for
>> a single-threaded program (and for a multi-threaded but I/O-bound
>> program) *does not decrease*."
>
> The performance decrease is an artifact of CPython's rather primitive
> storage management (reference counts in every object).  This is
> pervasive and can't really be removed.  But a new implementation
> (e.g. PyPy) can and should have a real garbage collector that doesn't
> suffer from such effects.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

That's interesting, I hadn't heard the reference counting mechanism
was related to the GIL. Is it just that you need to lock the reference
count before mutating it if there's no GIL? Really, that shouldn't be
the case. Reference counting can be done with a lock free algorithm.

Garbage collection is definitely in vogue right now. However, people
tend to treat it more like a religion than an algorithm. Garbage
collection vs reference counting  actually has some trade offs both
ways. GC gets you some amortized performance gains, and some space
gains because you don't need to hang on to a bunch of counts. However,
GC also has the problem of having a very loose memory profile and poor
interactive performance during compaction if the heap is large. In
some cases this discussion becomes complicated with python because
python has both reference counting and GC.
--
http://mail.python.org/mailman/listinfo/python-list


Re: braces fixed '#{' and '#}'

2009-01-18 Thread Brendan Miller
Yes, I also recently noticed the bug in python's parser that doesn't
let it handle squigly braces and the bug in the lexer that makes white
space significant. I'm surprised the dev's haven't noticed this yet.

On Sat, Jan 17, 2009 at 2:09 AM, v4vijayakumar
 wrote:
> I saw some code where someone is really managed to import braces from
> __future__. ;)
>
> def test():
> #{
>print "hello"
> #}

This seems like the best workaround.  Hopefully python curly brace
support will be fixed soon. I think technically a language can't be
turing complete without curly braces right? That's definitely how I
read this:

http://www.thocp.net/biographies/papers/turing_oncomputablenumbers_1936.pdf

"If the negation of what Gödel has shown had been proved, i.e. if, for each U,
either U or –U is provable, then we should have an immediate solution of the
Entscheidungsproblem. As a corollary we also have that real
programmers use squigly braces and everyone else is nubs"
--
http://mail.python.org/mailman/listinfo/python-list


Re: pep 8 constants

2009-01-19 Thread Brendan Miller
> Constants would be a nice addition in python, sure enough.

My original question was about PEP-8 and whether it is pythonic to use
all caps to denote a variable that shouldn't be changed. More of a
style question than a language question.

I actually think *enforcing* constantness seems to go against the
grain of the language so to speek
--
http://mail.python.org/mailman/listinfo/python-list


Re: what's the point of rpython?

2009-01-19 Thread Brendan Miller
Maybe I'm missing something here but a lock free algorithm for
reference counting seems pretty trivial. As long as you can atomically
increment and decrement an integer without locking you are pretty much
done.

For a reference implementation of lock free reference counting on all
common platforms check out boosts implementation of shared_ptr (a
reference counting smart pointer designed around multithreaded use
cases).

>There are well known concurrent and parallel GC techniques that
Hmm... I didn't really mention poor parallelism as a problem of GC. As
I see it the two trade offs that have to be made for GC vs alternative
techniques. The "embarrassing pause" during compaction which makes it
impossible to use for applications like interactive video display that
can't halt to compact a several gigabyte heap without causing stutter,
and the loose memory profile.

Maybe the document you sent me addresses those, and I'd be interested
if it did. It's 150~ pages though so I haven't really had time to read
it yet.

As far as parallelism problems with GC go... the only ones I can
imagine is that if you had a lot of threads going generating lots of
garbage you would need to start to compact more frequently. Since
compaction halts all threads, this could potentially cause very
frequent compactions? Is that what you were getting at? I'd wondered
about that before, but didn't know for a fact whether it came up in
real world scenarios.
--
http://mail.python.org/mailman/listinfo/python-list


Re: what's the point of rpython?

2009-01-20 Thread Brendan Miller
On Tue, Jan 20, 2009 at 3:46 AM, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> [email protected] writes:
>> Carl, I'm quite unfamiliar with Boost and am not a C++ person, so may have
>> read what you saw but not recognized it in the C++ punctuation soup.  I
>> couldn't find what you referred to.  Can you provide a URL?
>
> http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety

I think you are misreading that. It says that multiple assignments to
different copies of a share_ptr in different threads are fine. This is
the important bit because copies of the same pointer share the same
reference count, and assignments and resets will decrement that ref
count. They say they don't handle mutations of the *same* pointer in
different threads, which is a different issue.

The programmer is responsible for synchronizing access to the pointer,
and the pointed to object, but not the ref count. This may be not be
obvious if you don't use shared_ptr a lot.

You also mentioned in an earlier post that most processors don't
support automic increments... I'm hesitant to dispute you here because
this is outside of my field of expertise. However, a quick google
search for "x86 atomic increment" comes up with this:

XADD

http://www.codemaestro.com/reviews/8
http://siyobik.info/index.php?module=x86&id=159

Again, I'm not an assembly guru, but his sounds like exactly what
you'd want. It gains exclusive access to system memory in a
multi-processor environtment without leaving user space. Thus XADD is
an atomic increment/decrement. It would be educational if someone more
famliar with x86 than me could speak to the performance merits of this
on modern multicore machines.
--
http://mail.python.org/mailman/listinfo/python-list


Re: what's the point of rpython?

2009-01-20 Thread Brendan Miller
On Tue, Jan 20, 2009 at 6:29 PM, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> "Rhodri James"  writes:
>> > What cpu's do you know of that can atomically increment and decrement
>> > integers without locking?
>>
>> x86 (and pretty much any 8080 derivative, come to think of it).
>
> It would not have occurred to me that "lock inc" increments "without
> locking".  I understand that's different from a lock value sitting in
> the data object but I thought that "lock-free algorithm" meant one
> that didn't assert any of these hardware locks either.  Maybe I'm
> wrong.

Right... I was wondering about that. Well, any kind of memory access
gets exclusive control of the bus except on NUMA, but I'm wondering
how CMPXCHG
http://en.wikipedia.org/wiki/Compare-and-swap

compares to XADD performance wise.

It seems to me that both of them must pull the old value across the
bus, hang onto the bus, and move the new value in. Maybe since XADD
needs to perform arithmetic there will be a few cycles lag between
getting the old value and pushing the new value? Maybe CMPXCHG doesn't
go through the ALU?

If the bus isn't just sitting idle and you can immediately push out
the new value then there's no real locking. Actually this article
explicitly mentions CMPXCHG as lock free.

http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms
--
http://mail.python.org/mailman/listinfo/python-list


Re: what's the point of rpython?

2009-01-20 Thread Brendan Miller
On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> "Rhodri James"  writes:
>> You asked a question about CPUs with atomic update, strongly implying
>> there were none.  All I did was supply a counter-example,
>
> Well, more specifically, atomic update without locking, but I counted
> the LOCK prefix as locking while other people didn't, and that caused
> some confusion.  Of course I'm aware of the LOCK prefix but it slows
> down the instruction enormously compared with a non-locked instruction.

I'm curious about that. I've been looking around for timing
information on the lock signal, but am having some trouble finding
them. Intuitively, given that the processor is much faster than the
bus, and you are just waiting for processor to complete an addition or
comparison before put the new memory value on the bus, it seems like
there should be very little additional bus contention vs a normal add
instruction.
--
http://mail.python.org/mailman/listinfo/python-list


Re: what's the point of rpython?

2009-01-21 Thread Brendan Miller
On Wed, Jan 21, 2009 at 8:19 AM, Scott David Daniels
 wrote:
> Brendan Miller wrote:
>>
>> On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin
>> <"http://phr.cx"@nospam.invalid> wrote:
>>>
>>>   Of course I'm aware of the LOCK prefix but it slows
>>> down the instruction enormously compared with a non-locked instruction.
>>
>> I'm curious about that. I've been looking around for timing
>> information on the lock signal, but am having some trouble finding
>> them. Intuitively, given that the processor is much faster than the
>> bus, and you are just waiting for processor to complete an addition or
>> comparison before put the new memory value on the bus, it seems like
>> there should be very little additional bus contention vs a normal add
>> instruction.
>
> The opcode cannot simply talk to its cache, it must either go directly
> to off-chip memory or communicate to other processors that it (and it
> alone) owns the increment target.

Oh, right. *light bulb goes on* I wasn't thinking about cache at all.
--
http://mail.python.org/mailman/listinfo/python-list


import reassignment different at module and function scope

2009-01-30 Thread Brendan Miller
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

If I:

import sys

sys = sys.version

This executes find but:

import sys

def f():
sys = sys.version

This gives an error indicating that the sys on the right hand side of =
is undefined. What gives?
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmD/mMACgkQ4eGWG/zYzOmrWgCbBLuD2HNDJJly3Z1KCPoNOB1G
sDgAoJ+gMCt9hWKuDUN30VUP40zqtbmJ
=+pND
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


install modules for specific python version

2009-01-31 Thread Brendan Miller
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I have several version of python running side by side on my ubuntu
install (2.5,2.6,3.0).

I'm installing a module with a setup.py script, in this case
logilab-common, so that I can get pylint going. However, I need to
install into python 2.6, but by default it picks out 2.5 and throws
things in the site packages for that version.

Is there a standard way to specify what version of python you want to
install into? I originally installed my other python versions with the
altinstall method.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmE9BIACgkQ4eGWG/zYzOmmdgCfbjr3p3wQ8A0TpjeFaPJtmHkx
ktQAoI7wONrj5gT4BDclePpwY5kiCy8p
=Pg9L
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


documentation link for python 3.0.1 on python.org is broken

2009-02-15 Thread Brendan Miller
Like the title says.
--
http://mail.python.org/mailman/listinfo/python-list


PyYaml in standard library?

2009-02-18 Thread Brendan Miller
I'm just curious whether PyYaml is likely to end up in the standard
library at some point?
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyYaml in standard library?

2009-02-18 Thread Brendan Miller
On Wed, Feb 18, 2009 at 1:34 AM, Chris Rebert  wrote:
> On Wed, Feb 18, 2009 at 1:11 AM, Brendan Miller  wrote:
>> I'm just curious whether PyYaml is likely to end up in the standard
>> library at some point?
>
> I don't personally have a direct answer to your question, but I can
> point out that JSON and YAML are mostly compatible (JSON is almost a
> perfect YAML subset) and the `json` module is already in the Python
> std lib.
>
> Cheers,
> Chris

Yes, JSON is an (I think unintentional) subset of YAML... but a fairly
small subset.

A list in YAML looks like

--- # my list
- Elem 1
- Elem 2

Whereas in JSON you have ["Elem 1", "Elem 2"]. People say JSON is a
subset because YAML will also accept the JSON style syntax if you want
to do something inline for convenience:

--- # my list containing a sublist in the second element.
- Elem 1
- ["Sub elem 1", "Sub elem 2"]

But this is really a special purpose syntax in the context of YAML.

I think the json module sticks everything on the same line, which
isn't readable for large data structures. My impression is YAML is
that is is more readable than JSON, whereas JSON is mostly for browser
interop.
--
http://mail.python.org/mailman/listinfo/python-list


hiding modules in __init__.py

2008-10-18 Thread Brendan Miller
How would I implement something equivalent to java's package private in
python?

Say if I have

package/__init__.py
package/utility_module.py

and utility_module.py is an implementation detail subject to change.

Is there some way to use __init__.py to hide modules that I don't want
clients to see? Or is the best practice just to name the module you don't
want clients to use _utility_module and have it private by convention?

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


best python unit testing framwork

2008-11-11 Thread Brendan Miller
What would heavy python unit testers say is the best framework?

I've seen a few mentions that maybe the built in unittest framework
isn't that great. I've heard a couple of good things about py.test and
nose. Are there other options? Is there any kind of concensus about
the best, or at least how they stack up to each other?

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


Re: best python unit testing framwork

2008-11-14 Thread Brendan Miller
On Thu, Nov 13, 2008 at 3:54 AM, James Harris
<[EMAIL PROTECTED]> wrote:
> On 11 Nov, 22:59, Brendan Miller <[EMAIL PROTECTED]> wrote:
>> What would heavy python unit testers say is the best framework?
>>
>> I've seen a few mentions that maybe the built in unittest framework
>> isn't that great. I've heard a couple of good things about py.test and
>> nose. Are there other options? Is there any kind of concensus about
>> the best, or at least how they stack up to each other?
>
> You don't mention what you want from testing so it's hard to say which
> is "best" as it depends on one's point of view.
>
> For example, I had a requirement to test more than just Python
> programs. I wanted to test code written in any language. None of the
> frameworks I found supported this so I wrote my own tester. It
> interacts with programs via file streams - principally stdin, stdout
> and stderr though others can be added as needed.

I was speaking to unit tests (tests of individual classes and
functions in isolation of the rest of the program) and a test driven
development approach. I find those to be much more useful, and good
for pinpointing bugs and guiding development. In contrast regression
tests tend to be slow, and are the programmatic equivalent of kicking
the tires and seeing if they fall off.

I've also seen regression tests lead to a "sweep the bugs under the
rug mentality" where developers will code to prevent errors from
crashing the regression test, e.g. by catching and swallowing all
exceptions without fixing the underlying problem. It's easy to fool
regression tests since what it does works at such a high level that
most aspects of program correctness can't be directly checked. This is
very frustrating to me because it actually leads to lower code
quality.

>
> One nice by-product is that test code does not bloat-out the original
> source which remains unchanged.
That's the main reason most people don't write unit tests. It forces
them to properly decouple their code so that parts can be used
independently of one another. Adding such things to messy ball of mud
code after the fact is an enourmous pain in the butt. Thankfully,
since python is duck typed and doesn't require lots of boilerplate
writing interfaces and abstract factories (since the class object
itself acts as an abstract factory), writing properly decoupled code
in the first place doesn't look nearly as hard as in C++ or Java.
--
http://mail.python.org/mailman/listinfo/python-list


py2exe linux equivalent

2009-03-20 Thread Brendan Miller
I have a python application that I want to package up and deploy to
various people using RHEL 4.

I'm using python 2.6 to develop the app. The RHEL 4 machines have an
older version of python I'd rather not code against (although that's
an option). My main stumbling block is I need to use a couple of
python modules (paramiko and pycrypto) that include C bits in them.

Is there any tool out there that can pull in my dependencies and give
me a packaged binary that I can hand off to my users without worrying
about them having my modules or the right version of python? Extra
credit if it generates an RPM for me.

It really doens't matter if the binary generated is somewhat bloated
with excess dependencies. It can include glibc for all I care.

The main thing keeping me from using all kinds of python in my linux
development at work is not being able to package up the results and
hand them off in a convenient way.

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


Re: py2exe linux equivalent

2009-03-20 Thread Brendan Miller
> platform. AFAICT there are RHEL4 rpms for these, and RHEL4 already comes
> with its own version of Python so it seems you are attempting to make
> things much more difficult than need be.

There are no rpm's in our repository for the third party modules I
need... If it was that easy I wouldn't be asking.
--
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe linux equivalent

2009-03-20 Thread Brendan Miller
So it sounds like the options are PyInstaller, cx_freeze, and
bbfreeze. Has anyone used any of these, and knows which one works best
on linux?
--
http://mail.python.org/mailman/listinfo/python-list


PyHeapTypeObject

2009-04-11 Thread Brendan Miller
What's the point of PyHeapTypeObject in Include/object.h? Why does the
layout of object types need to be different on the heap vs statically
allocated?

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


  1   2   >