Re: Using 'apply' as a decorator, to define constants

2009-08-21 Thread alex23
On Aug 21, 11:36 pm, Jonathan Fine jf...@pytex.org wrote:
 It might seem odd to use 'apply' as a decorator, but it can make sense.

Yes, it's an idiom I've used myself for property declarations, but one
I find myself using less often:

class ColourThing(object):
@apply
def rgb():
def fset(self, rgb):
self.r, self.g, self.b = rgb
def fget(self):
return (self.r, self.g, self.b)
return property(**locals())

Unfortunately, apply() has been removed as a built-in in 3.x. I'm not
sure if it has been relocated to a module somewhere, there's no
mention of such in the docs.

 Without using 'apply' as a decorator one alternative is
      def tmp():
          value = []
          # complicated code
          return value
      tags = tmp()
      del tmp

You can save yourself the tidy up by using the same name for the
function  the label:

def tags():
value = []
# ...
return value
tags = tags()

 Like all uses of decorators, it is simply syntactic sugar.  It allows
 you to see, up front, what is going to happen.  I think, once I get used
 to it, I'll get to like it.

The question is, is it really that useful, or is it just a slight
aesthetic variation? Given that apply(f, args, kwargs) is identical to
f(*args, **kwargs), it's understandable that's apply() isn't seen as
worth keeping in the language.

Why I've personally stopped using it: I've always had the impression
that decorators were intended to provide a convenient and obvious way
of augmenting functions. Having one that automatically executes the
function at definition just runs counter to the behaviour I expect
from a decorator. Especially when direct assignment... foo = foo
() ...is a far more direct and clear way of expressing exactly what is
happening.

But that's all IMO, if you feel it makes your code cleaner and don't
plan on moving to 3.x any time soon (come on in! the water's great!),
go for it :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using 'apply' as a decorator, to define constants

2009-08-21 Thread alex23
Jonathan Gardner jgard...@jonathangardner.net wrote:
 This is brilliant. I am going to use this more often. I've all but
 given up on property() since defining get_foo, get_bar, etc... has
 been a pain and polluted the namespace.

Unfortunately I can't remember who I first learned it from - it was
definitely in a post to this group - otherwise all credit would be
their's.

 It's one of those functions that is easier to define than import.

And so obvious now :)

 If anyone reads the decorator and doesn't think this thing below is
 defined as the result of this decorator function then they don't
 understand decorators at all.

Well, it's not so much a question of the reader's intelligence as that
Python already has a readily identifiable assignment operator. Having
a second mechanism for assignment with no real similarity to the first
just adds cognitive friction to reading the code...not because the
reader doesn't understand what is happening, but because it's not
obvious _why_ this second form would have been chosen.

Nothing that couldn't be mitigated with a comment, I guess.

# @apply used to prevent having to repeat references

That would work for me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6 windows install

2009-08-20 Thread alex23
Tim Arnold tim.arn...@sas.com wrote:
 Any ideas on what I'm missing here?

Most likely the required configuration of the local environments.

Did you install Python to the network device from your XP box? That
would explain why you can run it: the required registry settings 
environment variables are added by the installer, none of which is
occurring on any computer other than the one from which you installed.

To be honest, I've never seen a single-point-of-access network
installation of Python for a Windows environment. If it was possible,
I'd expect ActiveState's ActivePython to support it but there's no
mention of it in the list of acceptable installer switches[1].

[1]: http://docs.activestate.com/activepython/2.6/installnotes.html#msi

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


Re: How do I convert an iterator over bytes into a str?

2009-08-19 Thread alex23
markscottwright markscottwri...@gmail.com wrote:
 Thanks Jan (and all other responders).  I suppose I shouldn't be
 surprised - it's a known wart (http://wiki.python.org/moin/
 PythonWarts), but it just looks so darn wrong.

Don't forget that it's exceptionally easy to create your own mechanism
for doing this:

  def join(seq, sep):
 return sep.join(map(str, seq))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to overload operator (a x b)?

2009-08-08 Thread alex23
Diez B. Roggisch de...@nospam.web.de wrote:
 Not really. I didn't get the chaining, and Peter is right that for that
 there is no real overloading.

I'm sorry, I don't really get why overloading lt  gt isn't an answer
to the OP's question... His terminology may not have been correct but
I'm not sure why it's not a sufficient response.

(then again it is a Friday night and I have been out drinking...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-08 Thread alex23
Paul Rubin http://phr...@nospam.invalid wrote:
 Stephen, Alex, etc.: have you actually used the php.net doc system?
 Don't knock it til you've tried it.  IMO it is superior to Python's
 system.  

I've tried it, a lot. Is it okay for me to keep criticising it now, or
would you like some time to find some other allusion to ignorance with
which to wave away my opinion?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to kill subprocess when Python process is killed?

2009-08-07 Thread alex23
On Aug 7, 3:42 pm, mark.v.we...@gmail.com mark.v.we...@gmail.com
wrote:
 When I kill the main process (cntl-C) the subprocess keeps running.
 How do I kill the subprocess too? The subprocess is likey to run a
 long time.

You can register functions to run when the Python process ends by
using the atexit[1] module.

The following has been tested  works under Python 2.6 on Windows XP:

import atexit

def cleanup():
print 'stop the subprocess in here'

atexit.register(cleanup)

while True:
pass


[1]: http://docs.python.org/library/atexit.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to overload operator (a x b)?

2009-08-07 Thread alex23
On Aug 7, 10:50 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote:
 That isn't an operator at all. Python does not support compound
 comparisons like that. You have to do a  b and b  c.

You know, it costs nothing to open up a python interpreter and check
your certainty:

 x = 10
 1  x  20
True

This is a _very_ common pattern.

 class X(object):
...   def __lt__(self, other):
... print 'in lt'
... return True
...   def __gt__(self, other):
... print 'in gt'
... return True
...
 x = X()
 1  x  20
in gt
in lt
True
 20  x  1
in gt
in lt
True

dmitrey: Diez' advice was the best you received.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode() vs. s.decode()

2009-08-07 Thread alex23
Thorsten Kampe thors...@thorstenkampe.de wrote:
 Bollocks. No one will even notice whether a code sequence runs 2.7 or
 5.7 seconds. That's completely artificial benchmarking.

But that's not what you first claimed:

 I don't think any measurable speed increase will be
 noticeable between those two.

But please, keep changing your argument so you don't have to admit you
were wrong.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread alex23
Paul Rubin http://phr...@nospam.invalid wrote:
 Such evaluation would only do them good.  The official docs are full
 of errors and omissions, which is why we have this thread going on
 here in the newsgroup.

And there is a process for reporting and correcting such errors and
omissions, which is what I pointed out in my post.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting matrix from a text file

2009-08-07 Thread alex23
On Aug 8, 2:19 am, bbarb...@inescporto.pt wrote:
 I am new in python, and I am running it on Mac with Smultron editor. I  
 need to read a textfile that includes numbers (in a matrix form),  
 indexes, and strings, like this:

 Marsyas-kea distance matrix for MIREX 2007 Audio Similarity Exchange
 Q/R     1       2       3       4       5
 1       0       4.54592 4.36685 5.29463 3.85728
 2       4.54592 0       3.97667 5.02151 4.64284
 3       4.36685 3.97667 0       4.98743 4.83683
 4       5.29463 5.02151 4.98743 0       6.04393
 5       3.85728 4.64284 4.83683 6.04393 0

 So I just want to keep the matrix in the middle for math computations.

         0       4.54592 4.36685 5.29463 3.85728
         4.54592 0       3.97667 5.02151 4.64284
         4.36685 3.97667 0       4.98743 4.83683
         5.29463 5.02151 4.98743 0       6.04393
         3.85728 4.64284 4.83683 6.04393 0

 I've seen and tried a lot of ways, like split or isinstance.. but  
 never get the wanted result does anyone have an idea, or hint?  
 Thank you once more for your help!


isinstance? Are you just randomly trying functions hoping they'll
work? :)

Untested code follows:

with open(textfile,'r') as textfile:
header = textfile.next() # skip the header
col_0_size = 8 # cos it does
for line in textfile:
newline = line[col_0_size:] # strip off the index column
columns = newline.split(' ') # will give you a tuple of
strings
one, two, three, four, five = map(float, columns) # turns the
strings into floats
# do whatever you want to those values here

This is fairly standard text handling with Python, if you haven't
already you should really work through the Python tutorial[1],
especially the section on strings [2], and if you have, perhaps David
Mertz's 'Text Processing in Python'[3] may be of use.

1: http://docs.python.org/tutorial/
2: http://docs.python.org/tutorial/introduction.html#strings
3: http://gnosis.cx/TPiP/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 exegetics: conditional imports?

2009-08-07 Thread alex23
On Aug 8, 2:50 am, kj no.em...@please.post wrote:
 Conditional imports make sense to me, as in the following example[...]
 And yet, quoth PEP 8:

     - Imports are always put at the top of the file, just after any module
       comments and docstrings, and before module globals and constants.

 ...which seems to condemn conditional imports unequivocally.

Really? It doesn't mention conditionals at all, it simply says that
imports should occur before globals and constants, not before
conditions. If you want to put conditions around your imports, then
that's the place to do it.

 I seek the wisdom of the elders.  Is there a consensus on the matter
 of conditional imports?  Are they righteous?  Or are they the way
 of the wicked?

Bear in mind that PEP 8 primarily applies to submissions to the
standard library, in order to provide a standard that aids in
understanding them. If a module is used throughout a body of code,
it's helpful to list these modules at the top of the code, for
clarity. However, if a module is only required under exceptional
conditions, you'll often see it imported at the point which it's
required: as the import occurs near the code, this mitigates the
initial requirement somewhat, and reduces the startup time of the
code.

The style guide also states:
But most importantly: know when to be inconsistent -- sometimes
the style
guide just doesn't apply.  When in doubt, use your best judgment.
Look
at other examples and decide what looks best.  And don't hesitate
to ask!

Checks around imports are often used to provide cross-version
compatibility. Embedded imports are often used when the code relying
on them is barely used. These are all very common uses.

pystone is a good example. Nothing within the modular code of pystone
requires sys, it's only imported if the module is executed, primarily
for error reporting  argument handling.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting matrix from a text file

2009-08-07 Thread alex23
MRAB pyt...@mrabarnett.plus.com wrote:
 Or:
          columns = line.split(' ')[1 : ]

Even better, well spotted.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bug or feature: double strings as one

2009-08-07 Thread alex23
kj no.em...@please.post wrote:
 Feature, as others have pointed out, though I fail to see the need
 for it, given that Python's general syntax for string (as opposed
 to string literal) concatenation is already so convenient.  I.e.,
 I fail to see why

 x = (first part of a very long string 
      second part of a very long string)

 is so much better than

 x = (first part of a very long string  +
      second part of a very long string)

My impression is it's mostly for one of clarity. It's especially
useful with regular expressions, as it allows for comments to document
each element of the regex (following example shamelessly taken from
the docs (albeit with personal preferences on formatting))):

re.compile(
[A-Za-z_]   # letter or underscore
[A-Za-z0-9_]*   # letter, digit or underscore
)

Not having the plus sign present does assist (IMO) in the ease of
parsing the regex.
re.compile(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode() vs. s.decode()

2009-08-07 Thread alex23
garabik-news-2005...@kassiopeia.juls.savba.sk wrote:
 I am not sure I understood that. Must be my English :-)

I just parsed it as blah blah blah I won't admit I'm wrong and
didn't miss anything substantive.


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


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread alex23
Kee Nethery k...@kagi.com wrote:
 I'm looking forward to the acceleration of improvements to the  
 official docs based upon easy to provide user feedback. Glad to see  
 that the bug tracking system is going to not be the primary means for  
 documentation changes.

I'm not sure what you see as being fundamentally different between
open access to a bug tracker  open access to a wiki, other than it
being a lot more difficult to have threaded discussion on a wiki.

Why exactly is posting an open comment on a bug tracker somehow
inferior to posting an open comment on a wiki?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread alex23
David Robinow drobi...@gmail.com wrote:
  When one believes that development is controlled by a cabal which is
 jealous of outsiders and actively prevents improvements to the docs,
 any change, even if only in perception, helps to weaken the hold of
 the evil forces holding back the success of Python.

Yeah, it's clearly all ego and assholes that's preventing Python from
being the enochian equivalent of programming languages :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is feedparser deprecated?

2009-08-07 Thread alex23
John Nagle na...@animats.com wrote:
    Feedparser requires SGMLlib, which has been removed from Python 3.0.
 Feedparser hasn't been updated since 2007. Does this mean Feedparser
 is dead?

Wouldn't you be better served asking this on the feedparser bug
tracker?

http://code.google.com/p/feedparser/issues/list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 exegetics: conditional imports?

2009-08-07 Thread alex23
Peter Otten __pete...@web.de wrote:
 This criterion is unlikely to be met for the examples you give above. time
 is a built-in module, and gzip a thin wrapper around zlib which is also
 built-in.

This is something I was _utterly_ unaware of. Is there a list of what
modules are built-in readily available?

The only reference[1] I could find via Google doesn't list zlib at
all.

[1]: 
http://www.vldb.informatik.hu-berlin.de/Themen/manuals/python/python-texinfo/built-in_modules.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-06 Thread alex23
Kee Nethery wrote:
 As I struggle through trying to figure out how to make python do  
 simple stuff for me, I frequently generate samples. If some volunteer  
 here would point me towards the documentation that would tell me how I  
 can alter the existing Python docs to include sample code, I'd be more  
 than happy to do so.

No offence, but the last thing the official documentation needs is
example code written by people learning how to code. Suggest changes,
request clarifications, submit samples for review, sure, but direct
modification by users? I've seen the PHP docs; thanks but no thanks.

 I would like to do it. Please point me to the docs that tell me how  
 to do it so that we people with newbie questions and a need for  
 examples can get out of your way and do it ourselves.

You start by reading this: http://docs.python.org/documenting/index.html
And this: http://www.python.org/dev/contributing/
And this: http://wiki.python.org/moin/WikiGuidelines

The first link, which directly answers your question, is clearly
listed on the doc contents page as Documenting Python. I'm uncertain
how the docs could be made any _more_ helpful if people aren't
prepared to put effort into reading them. We're a long way away from
direct upload to the brain, unfortunately.

If you're learning the language, you should also consider using more
appropriate resources:
http://mail.python.org/mailman/listinfo/tutor
http://www.doughellmann.com/PyMOTW/
http://diveintopython.org/

The documentation cannot be all things to all people, and it most
certainly can't be a guide to general programming, which is what often
seems to be the issue with novice users. Python's a great language to
learn how to program in, sure, but I would hate to see that become the
focus of the docs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with regex

2009-08-06 Thread alex23
On Aug 7, 1:35 am, Robert Dailey rcdai...@gmail.com wrote:
 I'm creating a python script that is going to try to search a text
 file for any text that matches my regular expression. The thing it is
 looking for is:

 FILEVERSION 1,45,10082,3

Would it be easier to do it without regex? The following is untested
but I would probably do it more like this:

TOKEN = 'FILEVERSION '
for line in file:
  if line.startswith(TOKEN):
version = line[len(TOKEN):]
maj, min, rev, other = version.split(',')
break # if there's only one occurance, otherwise do stuff here
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-06 Thread alex23
Paul Rubin http://phr...@nospam.invalid wrote:
 The PHP docs as I remember are sort of regular (non-publically
 editable) doc pages, each of which has a public discussion thread
 where people can post questions and answers about the topic of that
 doc page.  I thought it worked really well.  The main thing is that
 the good stuff from the comment section gets folded into the actual
 doc now and then.

I'd still like to see this kept out of the official docs as much as
possible, mostly for reasons of brevity  clarity. I think the
official docs should be considered definitive and not require a
hermeneutic evaluation against user comments to ensure they're still
correct...

How about a secondary site that embeds the docs and provides
commenting functionality around it? That's certainly a finitely scoped
project that those with issues about the docs could establish and
contribute to, with the possibility of it gaining official support
later once it gains traction.



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


Re: trouble with complex numbers

2009-08-05 Thread alex23
On Aug 5, 4:28 pm, Dr. Phillip M. Feldman pfeld...@verizon.net
wrote:
 When I try to compute the phase of a complex number, I get an error message:
 [...]
 Any advice will be appreciated.

1. What version of Python are you using, and on what platform?

2. What you snipped is necessary to help debug your problem.

3. Do you have a cmath.py in the folder you're running the interpreter
in?

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


Re: intricated functions: how to share a variable

2009-08-05 Thread alex23
TP tribulati...@paralleles.invalid wrote:
 Then, as advised Diez, perhaps the best solution is to have true global
 variables by using a class and defining the variable a as a member self.a
 of the class. By doing like this, a will be known everywhere.

Or, as Bearophile suggested, you could use the standard way of passing
arguments into a function:

 def tutu():
...   a = 2
...   def toto(a=a):
... print 'toto', a
... a = 4
... print 'toto', a
...   print 'tutu', a
...   toto()
...   print 'tutu', a
...
 tutu()
tutu 2
toto 2
toto 4
tutu 2

You could also just do 'toto(a)', but as you're trying to create a
closure here, binding the external scope 'a' to toto via the default
argument will (probably) do what you need.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble with complex numbers

2009-08-05 Thread alex23
Piet van Oostrum p...@cs.uu.nl wrote:
 That should be z += 0j

Pardon my ignorance, but could anyone explain the rationale behind
using 'j' to indicate the imaginary number (as opposed to the more
intuitive 'i')?

(Not that I've had much call to use complex numbers but I'm
curious)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble with complex numbers

2009-08-05 Thread alex23
On Aug 6, 1:18 am, Scott David Daniels scott.dani...@acm.org wrote:
 I think it explained in the complex math area, but basically EE types
 use j, math types use i for exactly the same thing.  Since i is so
 frequently and index in CS, and there is another strong convention,
 why not let the EE types win?

That 'i' tends to be used as index did occur to me, I just wasn't
aware of what conventions were used in other contexts.

Thanks, Scott, much appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subclassing Python's dict

2009-08-05 Thread alex23
Xavier Ho wrote:
 You should subclass collections.UserDict, and not the default dict class.
 Refer to the collections module.

Xavier, why do you think that is the correct approach? The docs say
The need for this class has been largely supplanted by the ability to
subclass directly from dict (a feature that became available starting
with Python version 2.2).

If you mean that Sergey should subclass _in this instance_ could you
please explain why? (Sorry if you already have, I never saw your
original post...)


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


Re: Python docs disappointing - group effort to hire writers?

2009-08-04 Thread alex23
On Aug 4, 3:55 pm, David Lyon david.l...@preisshare.net wrote:
 It isn't totally about the writers...
 Peoples egos are also at stake - it seems.

Citation please.

 If Fred X wrote Doc Y.. they don't want their name taken off.. So
 they generally speaking don't want the docs changed.

Ditto.

 If you talk too much about docs.. you can be told you're OT..
 even in a thread about docs...

And again.

All I've _ever_ seen (on this group at least) is the much repeated
phrase All patches to the docs are welcomed. If you'd like to cast
aspersions on the characters of those doing the work over actually
contributing yourself, you're certainly free to do so, just don't
expect your claims to be taken seriously.

Other people's refusal to do the work that _you_ consider to be
necessary isn't ego.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling regex inside function?

2009-08-03 Thread alex23
Anthra Norell anthra.nor...@bluewin.ch wrote:
 def entries (l):
         r = re.compile ('([0-9]+) entr(y|ies)')
         match = r.search (l)
         if match: return match.group (1)

 So the question is: does r get regex-compiled once at py-compile time
 or repeatedly at entries() run time?

The docs say:
The compiled versions of the most recent patterns passed to re.match
(), re.search() or re.compile() are cached, so programs that use only
a few regular expressions at a time needn’t worry about compiling
regular expressions.

(But they don't say how few is 'only a few'...)

If you're concerned about it, you could always set the compiled
pattern to a default value in the function's argspec, as that _is_
only executed the once:

def entries(line, regex = re.compile('([0-9]+) entr(y|ies)'):
match = regex.search(line)
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help understanding the decisions *behind* python?

2009-08-03 Thread alex23
John Nagle na...@animats.com wrote:
 Every function returned a tuple as an argument.  This had a nice
 symmetry; function outputs and function inputs had the same form.  
 Mesa was the first language to break through the single return
 value syntax problem.

     Python doesn't go that far.

I assume here you're referring to the former point and not the latter?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no-clobber dicts?

2009-08-03 Thread alex23
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote:
 I also have a series of unit tests for it if you're interested in them.

That's several times today that kj has asked a question and you've
responded with ready-to-go code. If this was Stackoverflow, I'd accuse
you of reputation-whoring...

You _can_ just post your cool code without the double act, y'know! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generate a new object each time a name is imported

2009-08-02 Thread alex23
On Aug 3, 4:07 am, Terry Reedy tjre...@udel.edu wrote:
 Peter Otten wrote:
  Steven D'Aprano wrote:
[...]

Fantastic question, answer  explanation, guys. Well done.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does underscore has any special built-in meaningin Python ?

2009-07-29 Thread alex23
On Jul 30, 3:59 am, dandi kain dandi.k...@gmail.com wrote:
 What is the functionality of __ or _ , leading or trailing an object ,
 class ot function ? Is it just a naming convention to note special
 functions and objects , or it really mean someting to Python ?

I think everyone else has covered what you need to know, but there's
still one remaining pseudo-convention you might see in Python code,
and that's using _ as a label to indicate that you don't care about
the value it holds.

Overly simplistic example:

data_set = [('gold','junk'),('gold','junk'),...]

for keep, _ in data_set:
...

It's a convenient way of not having to come up with a label for
something you're not going to use, although arguably you get the same
effect with names like 'dummy', 'ignore' etc. Not everyone agrees with
this usage but you _will_ see it in use in other people's code, so it
helps to have a heads up.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Confessions of a Python fanboy

2009-07-29 Thread alex23
On Jul 30, 1:06 pm, r rt8...@gmail.com wrote:
 1.) No need to use () to call a function with no arguments.
 Python -- obj.m2().m3() --ugly
   Ruby -- obj.m1.m2.m3  -- sweeet!
 Man, i must admit i really like this, and your code will look so much
 cleaner.

How do you distinguish between calling a method with no arguments, and
getting access to the method object itself (because it _is_ an object,
y'know, it's OO all the way down...)?

 2.) the .each method
 container.each{|localVar| block}
 This method can really cleanup some ugly for loops, although i really
 like the readability of for loops.

map(lambda localVar: block, sequence)

or:

def usefully_named_func(var):
block
return var

transformed = [usefully_named_func(v) for v in sequence]

 3.) true OOP
 Now before you go and get all huffy over this statement, hear me
 out. Python is the best language in the world. But it damn sure has
 some warts! len(this) instead of obj.length max(that) instead of
 [1,2,3,4,5].max().

As the Zen says: '[P]racticality beats purity'. Personally, I'm not
sure how a handful of convenient built-in functions make a language in
which _everything is an object_ somehow false OO.

If you're really that concerned with writing true OO (for some
wildly variable value of true), there's nothing stopping you from
doing so now:

obj.__len__()

With max(), this is a built-in that takes _any_ iterable and an
optional key function, and returns the highest value as per the key.
This means that _every_ iterable object - as _well_ as every object
that supports enough of the iterator protocol - can be handed to max()
and a result obtained. So at best, I just need to make sure my new
sequence-type provides the iterator protocol and viola, it works with
max() without me having to hand-code a .max() that's specialised for
my new type, and without Python forcing me to have a complex
inheritance chain just to make sure I include the right
MaxableSequence ancestor to inherit the right .max().

 PS stay tuned for more from this series

Is this going to be more of you telling us - without any apparent
irony whatsoever - how Ruby has some valid points after all your
vilification last year when we said the same to you?  If so, where can
I sign up?!

(You should consider trading guest spot posts with Xah Lee on your
respective blogs. You both have a very similar approach to programming
 programming languages and I think the synergy would be amazing to
see.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE Config Problems

2009-07-29 Thread alex23
On Jul 30, 6:55 am, Russ Davis russ.da...@njpines.state.nj.us
wrote:
 I am just getting started with Python and have installed v. 2.5.4  
 Idle version 1.2.4  I can't seem to get the idle to display text.  It
 seems as if the install went fine.  I start up the idle and the screen
 is blank.  No text.  It seems as if I can type on the screen but I just
 can't see the characters.

Is this the official python.org distribution you're trying? I can't
speak from experience, but I'm wondering if it doesn't include the
pyreadline module by default, which you'll require under Windows
(although I would've expected to hear more problems like your's if
this is the case). You can easily check this by going to C:
\Python25\Lib\site-packages and looking for a folder or a file called
pyreadline. If it's not, you'll have to install it separately.

If you're not already familiar with it, I do recommend checking out
the ActiveState ActivePython distribution instead, especially if
you're working under Windows. It includes a lot of Windows-specific
3rd party modules, such as the win32all modules, and it definitely
includes pyreadline.

Is there any particular reason why you're opting for Python 2.5.x? 2.6
should be pretty compatible with most things in the 2.x stream and
it's a handy stepping stone towards using 3.x (which, admittedly, is
probably the last of your concerns when you're first setting up...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ideas for problem with chat server application!

2009-07-22 Thread alex23
On Jul 22, 6:27 pm, David Adamo Jr. dtgead...@yahoo.com wrote:
 Suggestions are highly appreciated.

I haven't used it but I've heard good things about FireDaemon, which
can run any script or program as a Windows service.

Apparently the Lite version is free:
http://www.download-freeware-shareware.com/Freeware-System-Utilities.php?Type=14387

Hope this helps.

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


Re: UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in position 13: ordinal not in range(128)

2009-07-16 Thread alex23
On Jul 16, 9:00 pm, akhil1988 akhilan...@gmail.com wrote:
 I have switched to python 3.1 , but now I am getting some syntax errors in
 the code:

Python 3.x was a major release that endeavoured to clean up a number
of lingering issues with the language, the upshot being that it isn't
entirely backwards compatible with past versions. Unicode became the
default string type, which is what is causing the error here: the u-
prefix is no longer required (or even allowed).

However, Py3.x _does_ come with a handy tool for automatically
converting Python 2.x code to 3.x, called 2to3. One of the things it
should do is convert Py2.x unicode values into their correct
representation in 3.x.

With any luck, it should be able to convert the code you're using
entirely. Let us know how it goes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread alex23
On Jul 16, 9:18 pm, superpollo u...@example.net wrote:
 lol. ;-) the title was indeed supposed to stir a bit of curiosity upon
 the reader...

Which isn't really useful when trying to obtain assistance... you want
certainty, not curiosity.

 in fact i was looking for a *platform independent* way to draw into a
 graphics file (say, a postscript or a png) using the turtle module. so i
 understand that dumping a window is not a good expression... maybe
 redirecting graphics commands to a file instead of a window?

You didn't actually answer Diez question. The turtle module is only a
recent (2.6/3.0) addition to Python and is probably obscure enough not
to have tracked across everyone's radar.

So _if_ you're talking about the standard lib turtle module, you're
not looking to 'dump a window', you're looking to write the contents
of turtle.Canvas to file. Canvas only supports writing to postscript,
so you'll have to do something like this (untested):

import turtle
screen = turtle.Screen()
# go go gadget turtle...
screen._canvas.postscript(file='turtle.ps')

Or it may be open('turtle.ps','w').write(screen._canvas.postscript
())... I couldn't find a definitive answer. Try looking through the Tk
docs, it should be covered there.

Note that this is a postscript _text_ file, so you'll also need to
find something to render it with.

Hope this helps point you in the right direction.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread alex23
On Jul 16, 10:11 pm, superpollo u...@example.net wrote:
 actually i am still using 2.3.4, which means that...

  screen = turtle.Screen()

 ... is not possible

Ah, sorry about that. My belief that turtle was a new module was based
on a line from 
http://us.pycon.org/media/2009/talkdata/PyCon2009/065/SevenWaysToUseTurtle-PyCon2007.pdf

   Since Python 2.6/3.0, Python has had a new turtle module.

At which point I stopped reading and missed the following line:

   Its development was based entirely on the previous one.

In my defence, I _had_ been drinking.

Thankfully Peter stepped up with a more appropriate solution, and
Michiel pointed out the more suitable API calls over dealing directly
with the underlying implementation :) Good work guys!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread alex23
  Help on method postscript:
  postscript(self, *args, **kw) method of turtle.ScrolledCanvas instance
  is spectacularly useless.

 This is from interactive help.

The help in iPython says the same, but also mentions that it's a
dynamically generated function, so it may not be picking up the
docstring that way. turtle.ScrolledCanvas.postscript is similarly
terse, but you can find more info in turtle.Canvas.postscript:

  Print the contents of the canvas to a postscript
  file. Valid options: colormap, colormode, file, fontmap,
  height, pageanchor, pageheight, pagewidth, pagex, pagey,
  rotate, witdh, x, y.

 The doc says

  Return the Canvas of this TurtleScreen. Useful for insiders who know
 what to do with a Tkinter Canvas.

  The module is a bit messy, but the accompanying documentation seems OK to
  me.

 ?? I am not an 'insider' ;-).

I don't think the intent of the turtle module is to be a primer in Tk,
but more of an educational tool. The lack of image export niceties has
a lot to do with the limitations of Tk, but was probably (and I'm
conjecturing here) felt to be outside the scope of what the module
aims to achieve.

 Of Canvas, mostly methods. I can understand that no one who could write
 decent doc strings for the 100 methods has actually volunteered to do so.

I think they all _have_ doc strings, or at least the code they
eventually call does, but I'd have to look into the module itself to
see if they could be brought over dynamically.

You may be interested in the final page of Greg Lingl's PyCon talk,
Seven Ways to use Turtle[1] which states:

  The turtle module is designed in a way so that essentially all of
the turtle
  graphics machinery is based on a class TurtleScreenBase, which
provides the
  interface to the underlying graphics toolkit Tkinter.

  So it‘s easy to port turtle.py to different graphics toolkits/
libraries,
  simply by replacing this Tkinter base class with an appropriate
different one.

  I‘ve done two ports: Pygame  Jython

If you're after bitmap, I'd suggest contacting Greg and asking about
the Pygame port. His contact info can be found at the original site
for the revised turtle module[2], hopefully it's still up to date.

1: us.pycon.org/media/2009/talkdata/PyCon2009/065/SevenWaysToUseTurtle-
PyCon2007.pdf
2: http://xturtle.rg16.at/download.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: one more question

2009-07-15 Thread alex23
amr...@iisermohali.ac.in wrote:
 I tried but its not coming.

How much are you prepared to pay for help with this? Or are you just
asking us to do all the work for you?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: one more question

2009-07-15 Thread alex23
On Jul 15, 4:50 pm, alex23 wuwe...@gmail.com wrote:
 amr...@iisermohali.ac.in wrote:
  I tried but its not coming.

 How much are you prepared to pay for help with this? Or are you just
 asking us to do all the work for you?

Or to be a _little_ less blunt: if you want people here to _assist_
you with _your_ code, then post what you've tried here, along with
tracebacks if errors are occurring, or an explanation as to what it
isn't doing that you require.

Spawning a new thread restating your question every time someone
suggests you RTFM isn't the best way to show that you're actually
trying to solve this issue yourself.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can module tell if running from interpreter vs Windows command line ?

2009-07-15 Thread alex23
On Jul 16, 10:41 am, alex23 wuwe...@gmail.com wrote:
 It's recommended that you search through the list for similar
 questions before posting.

Of course, it's even MORE important that one actually ensures they're
responding to the _same_ question before pointing at an answer...

This older post should help:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/6c587ba377ae045a/0df10b077f5ee5d4

But the quick answer is to import sys into your program, and do a test
on hasattr(sys, 'ps1'), which is only created when running the
interactive prompt.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can module tell if running from interpreter vs Windows command line ?

2009-07-15 Thread alex23
On Jul 16, 10:07 am, pdlem...@earthlink.net wrote:
 The WConio console module produces different colors, sometimes quite
 different, when run from Windows command line vs from Python
 interpreter  .  A good foregnd/backgnd combination under one
 may be unreadable under the other  : (
 I'm using Python 3.0 with the corresponding WConio on XP.
 Is there any way for the module to detect under which it has been
 started ?    Thanks

It's recommended that you search through the list for similar
questions before posting. This was covered just yesterday:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/fb2f075ccc796b63#
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: one more question

2009-07-15 Thread alex23
On Jul 15, 5:51 pm, koranthala koranth...@gmail.com wrote:
    I am not saying that what you said was wrong, only that I felt that
 she got tense looking up regular expressions. So a python reply which
 basically does the basic checking without going to re etc might be
 more helpful for her to start her own coding.

Using regexps wasn't the only advice given, and string manipulation is
covered well in pretty much every tutorial I've taken a look at. The
issue is that no evidence was shown that the OP was even trying to
resolve this themself, and the new posting of the question every time
an unsatisfactory answer was provided doesn't give me any faith they
were endeavouring to do this at all.

It's annoying seeing these stone soup attempts at coding come
through here, whether its to answer someone's homework or to do
someone's job for them. If the end result has value to the poster, I
expect to see either effort on their behalf or at least a nominal
attempt to reward others for their time.

But if you want to do their work for them, I don't think anyone here
would object, especially if you both took it to private correspondence.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can module tell if running from interpreter vs Windows command line ?

2009-07-15 Thread alex23
On Jul 16, 12:56 pm, Asun Friere afri...@yahoo.co.uk wrote:
 As you note there, this will work when running the vanilla shell (ie
 running  it from the command line), but not (potentially) in other
 interactive environments (IronPython being the example you give).

Actually, that was IPython, which is an enhanced interactive prompt,
and a totally different beastie altogether :)

 Another instance:  there is not sys.ps1 when running a python shell
 under idle.  Since this solution differs whether the interactive
 session is taking place from the cmd line, idle, IronPython etc. it
 seems to me not terribly robust.

Well, none of {idle, IronPython, IPython} were specified by the OP AND
you're citing back what I myself wrote in the link to which I also
referred the OP - whom has subsequently posted his success with this
technique - so I'm not really sure what the point is here other than
if you have a different use case, you'll need a different
solution...

 Depending on the use case, it is of course easy to tell whether the
 module was executed on the command line, or imported (from an
 interactive shell or another script) using the __name__ trick.  (eg.
 is_imported = __name__ == '__main__')

That should be:

is_imported = __name__ != '__main__'

And such a test is all well and good if the main code body is the one
that needs to know about the execution mode, but if you need to know
under which conditions the program is being run within a module
imported by the main body, well, that check is _always_ going to be
true...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: does python have a generic object pool like commons-pool in Java

2009-07-15 Thread alex23
On Jul 16, 2:03 pm, John Nagle na...@animats.com wrote:
      fcgi is an option for this sort of thing.  With mod_fcgi installed
 in Apache, and fcgi.py used to manage the Python side of the problem, you
 can have semi-persistent programs started up and shut down for you on the
 server side.

Hey John,

The environments in which I've been asked to develop webs apps using
Python have all utilised mod_wsgi. Do you have any experience with
mod_wsgi vs mod_fcgi, and if so, can you comment on any relevant
performance / capability / ease-of-use differences?

Cheers,
alex23


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


Re: one more question

2009-07-15 Thread alex23
On Jul 16, 2:29 pm, koranthala koranth...@gmail.com wrote:
 It is not that I do want to do the work for them. It is just that I
 was in the same position just 6 months back. My first pieces of code
 were very poor - full of errors and quite horrible indeed. I was even
 afraid to post it anywhere. I came here, and I found so much helpful
 people who helped me out so much, that I think my coding has improved
 a little bit. So, I just thought that we should always give people the
 benefit of doubt.

Which is why I waited until the 5th repeated post on the topic before
commenting.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: explode()

2009-07-14 Thread alex23
Fred Atkinson fatkin...@mishmash.com wrote:
         I wish the Python site was as well written as the PHP site. On
 the PHP site, I can look up a command and they show not only the docs
 on that command but a list of all other commands associated with it.  

Hey Fred,

My problem is the complete opposite, I wish I could as easily
interrogate objects in PHP about their behaviour as I can Python :)

In case you're not familiar with this, you can see what methods are
attached to an object using the intepreter via dir() and see the
associated docstring for them via help(). Try looking at 'dir(str)'
for a list of methods that strings recognise, then 'help(str.join)' to
see the help on join.

This is such a handy ability to have that I miss this casual
introspection in everything else in which I'm required to develop.

Hope this helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to use Python to interface with Web pages?

2009-07-08 Thread alex23
On Jul 8, 1:18 pm, Peter peter.milli...@gmail.com wrote:
 I can see the web-page source - it looks to be javascript (to my
 untutored eye :-)).

 But how do I enter data and simulated mouse presses on a web-page
 that I have accessed via a Python program?
 [...]
 I have (in the past) written some python to scoop data off web-sites
 but I have never written anything that interactively interacts with
 the web-page contents and don't know where to even start on this one.

I don't have much experience with it, but for interacting with
javascript-heavy pages you might want to take a look at Selenium:

http://seleniumhq.org/
http://pypi.python.org/pypi/selenium
http://jimmyg.org/blog/2009/getting-started-with-selenium-and-python.html
http://joker.linuxstuff.pl/documentation/make_selenium

It's primarily aimed at testing web app UIs, but if it allows for
values to be passed into tests then 'test' == 'action' in terms of
your requirements.

Hope this helps.

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


Re: Remoting over SSH

2009-07-07 Thread alex23
On Jul 8, 12:46 am, Hussein B hubaghd...@gmail.com wrote:
 I want to perform commands on a remote server over SSH.
 What do I need?

Take a look at pexpect: http://pexpect.sourceforge.net/pexpect.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Bug By Any Other Name ...

2009-07-06 Thread alex23
On Jul 6, 5:56 pm, Tim Golden m...@timgolden.me.uk wrote:
 Gabriel Genellina wrote:
  In this case, a note in the documentation warning about the potential
  confusion would be fine.

 The difficulty here is knowing where to put such a warning.
 You obviously can't put it against the ++ operator as such
 because... there isn't one. You could put it against the unary
 plus operator, but who's going to look there? :)

The problem is: where do you stop? If you're going to add something to
the documentation to address every expectation someone might hold
coming from another language, the docs are going to get pretty big.

I think a language should be intuitive within itself, but not be
required to be intuitable based on _other_ languages (unless, of
course, that's an objective of the language). If I expect something in
language-A to operate the same way as completely-unrelated-language-B,
I'd see that as a failing on my behalf, especially if I hadn't read
language-A's documentation first. I'm not adverse to one language
being _explained_ in terms of another, but would much prefer to see
those relegated to Python for x programmers articles rather than
in the main docs themselves.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic question from pure beginner

2009-07-02 Thread alex23
Dennis Lee Bieber wlfr...@ix.netcom.com wrote:
         There is also the getpass module to play with!

I don't think I've ever seen getpass, so thanks for pointing that out.
Unfortunately, it wouldn't have helped the OP understand why his
original code wasn't working ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing windows structures through ctypes.

2009-07-02 Thread alex23
On Jul 2, 3:42 pm, Rajat rajat.dud...@gmail.com wrote:
 Using ctypes can I access the windows structures like:

 PROCESS_INFORMATION_BLOCK, Process Environment Block(PEB),
 PEB_LDR_DATA, etc?

ctypes.wintypes lists all of the Windows structures included with the
module.

You should be able to use ctypes.Structure class to roll your own:

http://docs.python.org/library/ctypes.html#structured-data-types
http://code.activestate.com/recipes/208699/
http://msdn.microsoft.com/en-us/library/ms684855(VS.85).aspx

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


Re: Basic question from pure beginner

2009-07-01 Thread alex23
On Jul 1, 3:38 pm, sato.ph...@gmail.com sato.ph...@gmail.com
wrote:
 I have been able to make the module quit after entering a password
 three times, but can't get it to quit right away after the correct one
 is entered.  

Not with the code you pasted, you haven't. There's a missing colon on
line 7  line 9 isn't indented properly. It's always best if we're
referring to the same source when trying to help with a problem.

The problem you're having, though, has to do with the while loop and
the fact that it's only checking one condition: has the 'count'
counter been incremented to 3. What you need to do is _also_ check for
the success condition:

is_confirmed = False
while count != 3 or is_confirmed:
  guess = raw_input(Enter your password: )
  guess = str(guess)
  if guess != password:
print Access Denied
count = count + 1
  else:
print Password Confirmed
is_confirmed = True

This also provides you with a nice boolean that shows whether or not
the password was confirmed, which may be useful for latter code.

However, whenever you want to loop a set number of times, it's usually
better to use a 'for' loop instead:

PASSWORD = 'qwerty'
MAXRETRY = 3
for attempt in xrange(MAXRETRY):
  guess = str(raw_input('Enter your password: '))
  is_complete = guess == PASSWORD
  if is_complete:
print 'Password confirmed'
break # this exits the for loop
  else:
print 'Access denied: attempt %s of %s' % (attempt+1, MAXRETRY)

This saves you from the burden of creating, incrementing  testing
your own counter.

If there's anything here that isn't clear, please don't hesitate to
ask.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python to set desktop background image under Windows XP

2009-07-01 Thread alex23
On Jul 2, 8:02 am, ELLINGHAUS, LANCE lance.ellingh...@hp.com
wrote:
 Does anyone have any code that would allow setting the desktop background 
 image under Windows XP?

It's amazing what typing python windows desktop into Google will
find you:

http://snippets.dzone.com/posts/show/3348

Any other searches you'd like us to do?

(Also: please post a new message instead of replying to an existing
one and changing the subject, it screws up threading)

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


Re: Getting input the scanf way

2009-07-01 Thread alex23
On Jul 1, 6:33 pm, Mr.SpOOn mr.spoo...@gmail.com wrote:
 I need to do some kind of interactive command line program.

 I mean: I run the program, it asks me for input, I type something and
 then I get the output or other questions.
 I'm not sure what is the right way to achieve this.

While the simplest way would be raw_input  print, as suggested,
there's also the cmd[1] module in the stdlib, which is what the
standard CPython interpreter uses, I believe.

[1]: http://docs.python.org/library/cmd.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source RSS Reader in Python?

2009-07-01 Thread alex23
On Jul 2, 9:18 am, Alex alex.lavoro.pro...@gmail.com wrote:
 I am looking for an open source RSS reader (desktop, not online)
 written in Python but in vain. I am not looking for a package but a
 fully functional software.

 Google: python open source (rss OR feeds) reader

 Any clue ?

It's always worth taking a look at PyPI. Some packages work perfectly
well as stand alone applications.

http://pypi.python.org/pypi?%3Aaction=searchterm=rsssubmit=search

These two look promising:
+ NewsFeed (Tk-based): http://home.arcor.de/mdoege/newsfeed/
+ urssus (QT-based): http://code.google.com/p/urssus/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic question from pure beginner

2009-07-01 Thread alex23
On Jul 2, 3:47 am, Scott David Daniels scott.dani...@acm.org wrote:
 And even simpler:
      PASSWORD = qwerty
      MAXRETRY = 3
      for attempt in range(MAXRETRY):
          if raw_input('Enter your password: ') == PASSWORD:
              print 'Password confirmed'
              break # this exits the for loop
          print 'Access denied: attempt %s of %s' % (attempt+1, MAXRETRY)
      else:
          # The else for a for statement is not executed for breaks,
          # So indicates the end of testing without a match
          raise SystemExit # Or whatever you'd rather do.

Nice one, I always forget about for-else :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: handeling very large dictionaries

2009-06-28 Thread alex23
On Jun 29, 9:13 am, mclovin hanoo...@gmail.com wrote:
 Is there something like it that is more flexible?

Have you seen the stdlib module 'shelve'? 
http://docs.python.org/library/shelve.html

It creates a persistent file-based dictionary, which can hold any type
of object as long as it can be pickled.

I really like the 3rd party module 'shove': http://pypi.python.org/pypi/shove

It's similar to shelve but provides many more backend options,
including dbs, svn and Amazon S3. Very handy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pep 8 constants

2009-06-28 Thread alex23
Eric S. Johansson e...@harvee.org wrote:
 no, I know the value if convention when editors can't tell you anything about
 the name in question.  I would like to see more support for disabled 
 programmers
 like myself and the thousands of programmers injured every year and forced to
 leave the field.  seriously, there is no money in disability access especially
 for programmers.

Well, if we can't use conventions like uppercasing, camelcasing and
underscoring, what are you recommending we do instead?

You seem to be asking us to change our behaviour to benefit only
others, but without offering any guidance on to how that is possible.
More importantly, shouldn't these modifications to common conventions
be coming _from_ the community of disabled programmers? I have a hard
time ensuring that I've gotten accurate requirements from co-workers
with whom I can actually see and speak, trying to determine how I
could write my code with accessibility in mind without any established
means of gauging success just seems impossible.

 and forgive me if this comes off sounding like a jerk but if
 the collective you don't give a sh** about your fellow programmers, who will?

This isn't intended to be callous, as I feel that the collective
doesn't care as a whole about _any_ programmers, but isn't the answer
the very same disabled programmers for whom accessibility is an issue?
Programming tends to be needs driven (which, admittedly, can be simply
to pay the bills), and those who have a need tend to be better at
working out how to address it.

One possibility may be to approach a group for whom accessibility is
already a consideration, such as the Gnome Accessibility Project:
http://live.gnome.org/GAP

As they are already developing Python-based accessibility tools for
Gnome - http://live.gnome.org/Accessibility/PythonPoweredAccessibility
- it wouldn't be a big stretch to start addressing coding
accessibility within that scope, either as part of the project or as
an independent adjunct to it, especially if someone with domain
knowledge volunteered ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object reincarnation

2009-06-11 Thread alex23
On Jun 11, 5:34 am, Manavan manava...@gmail.com wrote:
 Since the real world objects often needs to be deleted even if they
 have some reference from some other object [...]

From this it sounds like you're trying to implement some form of weak
referencing. Are you familiar with weakref?

A weak reference to an object is not enough to keep the object alive:
when the only remaining references to a referent are weak references,
garbage collection is free to destroy the referent and reuse its
memory for something else. A primary use for weak references is to
implement caches or mappings holding large objects, where it’s desired
that a large object not be kept alive solely because it appears in a
cache or mapping.

http://docs.python.org/library/weakref.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-11 Thread alex23
On Jun 12, 1:56 pm, lucius lucius.fo...@gmail.com wrote:
  w, h, absX, absY = result.group(3), result.group(4), result.group
 (5), result.group(6)

 w = 100
 h = 200

 absX = 10.0
 absY = 20.0

Are you sure those values are ints  floats? I would expect your
regexp would be returning strings...

Try replacing the %f  %d strsubs with %s and see if that works. (You
shouldn't need to typecast the values if you're just reinserting them
into a string...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread alex23
On Jun 10, 3:24 pm, John Yeung gallium.arsen...@gmail.com wrote:
 Alex, did you bother to read what I quoted?  Paul McGuire suggested an
 alternative in case the OP was choosing integers in a roundabout way.
 I was merely pointing out that Paul's solution can be more simply
 achieved using a library function.

My apologies, John. I *did* read the quote, my brain just didn't parse
it correctly.

Sorry about that :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread alex23
On Jun 10, 11:32 am, John Yeung gallium.arsen...@gmail.com wrote:
 On Jun 9, 8:39 pm, Paul McGuire pt...@austin.rr.com wrote:
  Are you trying to generate a number in the
  range [0,n] by multiplying a random function that
  returns [0,1] * n?  If so, then you want to do
  this using: int(random.random()*(n+1))  This will
  give equal chance of getting any number from 0 to n.

 Better still is simply

   random.randint(0, n)

There's a big difference between randint - which generates _integers_
in the range 0  n - and the OPs request for generating random
floating point values between  inclusive of 0  n.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Start the interactive shell within an application

2009-06-09 Thread alex23
On Jun 10, 1:40 am, Ben Charrow bchar...@csail.mit.edu wrote:
 If you're looking to debug your program, try import pdb

Another option, if you wish to debug an error, is to run python using
the -i parameter. This will leave you inside the interpreter at the
point that execution stops. Very handy.

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


Re: .pth files and figuring out valid paths..

2009-06-09 Thread alex23
On Jun 10, 8:00 am, rh0dium steven.kl...@gmail.com wrote:
 Apparently there is a problem with the if statement???

Try restructuring the if as a ternary condition:

import os, site; smsc = os.environ.get(TECHROOT, /home/tech); smsc
= smsc if os.path.isdir(smsc) else /home/tech; site.addsitedir
(os.path.join(smsc, tools/python/Linux/%arch/lib/python2.5/site-
packages))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there any module for sea tides?

2009-06-01 Thread alex23
alejandro aleksanda...@brisiovonet.hr wrote:
 I found some in C but could not find in Python

The best I could find was a reference to some in-house code used by
the US National Oceanoic  Atmospheric Association:

  http://tinyurl.com/mct9zz

You might be able to contact the email address at the bottom and
inquire about the code.

Another alternative is to look into using the ctypes module to create
bindings for the C libs you found...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: try except inside exec

2009-05-31 Thread alex23
Michele Petrazzo michele.petra...@remove_me_unipex.it wrote:
 I want to execute a python code inside a string and so I use the exec
 statement. The strange thing is that the try/except couple don't catch
 the exception and so it return to the main code.
 Is there a solution to convert or make this code work?

 My code:

 STR = 
 err = 0
 try:
    def a_funct():
      1/0
 except:
    import traceback
    err = traceback.format_exc()
 

 env = {}
 exec STR in env
 env[a_funct]()
 print env[err]

Hello Michele,

From your code, I'm not sure if you're aware that functions are
themselves objects within Python. You could avoid the use of exec
entirely by doing something like the following:

import traceback

class FuncTester(object):
  def __init__(self, function):
self.function = function

  def test(self, *args, **kwargs):
self.result, self.error = None, None
try:
  self.result = self.function(*args, **kwargs)
  success = True
except:
  self.error = traceback.format_exc()
  success = False
return success

 def f(x): return 'f does this: %s' % x
...
 ft = FuncTester(f) # note that we're referring to the function directly
 ft.test('foo')
True
 ft.result
'f does this: foo'
 ft.test()
False
 print ft.error
Traceback (most recent call last):
  File tester.py, line 10, in test
self.result = self.function(*args, **kwargs)
TypeError: f() takes exactly 1 argument (0 given)

I think you'll find this approach to be a lot more flexible than using
exec.

Hope this helps,
alex23
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling and transporting modules/libraries in python

2009-05-31 Thread alex23
On May 31, 2:27 am, Abe abeg...@gmail.com wrote:
     I use python at a home office and in a university computer lab,
 but I don't have the administrative rights to install libraries on the
 lab computers.  It would be really nice if there were a way I could
 put, say, all of numpy into a file my_numpy.pyc and treat it as a
 single (large) module.

You should be able to use virtualenv to provide this functionality:

  http://pypi.python.org/pypi/virtualenv

Create the environment you want on your home computer, then copy it
wholesale to your lab computer or even use it directly from a USB
device.

You might also want to look into one of the portable Python set ups.
This way you can have a fully portable environment that you control
completely:

  Portable Python: http://www.portablepython.com/
  Movable Python: http://www.voidspace.org.uk/python/movpy/

Hope this helps.

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


Re: What text editor is everyone using for Python

2009-05-26 Thread alex23
On May 26, 3:01 pm, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 I dislike Gnome's user-interface, and I find gedit slightly too
 underpowered and dumbed down for my taste. (Although it has a couple of
 nice features.)

Gedit is also nicely extensible: 
http://www.instructables.com/id/Using-Gedit-as-a-Python-IDE/

Not that I'm trying to change your editor, preferences are just
that :) (I tend to alternate between gvim, SPE and Komodo Edit...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i use Spread Sheet as Data Store

2009-05-19 Thread alex23
On May 19, 11:57 pm, D'Arcy J.M. Cain da...@druid.net wrote:
 I hear you but I'm not so sure that that is an absolute.  There are
 many applications that allow you to have your password emailed to you.
 For something with low risk that's perfectly acceptable.

Having -any- password stored in plaintext is unacceptable. I'm pretty
sure I'm not the only person who uses a simple algorithm to generate
passwords based on context. If you're running a site and you're not
going to bother to secure my credentials, I'd hope you'd at least
mention that at sign up so I could adjust my behaviour as appropriate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strip char from list of strings

2009-05-19 Thread alex23
On May 20, 12:55 am, Laurent Luce laurentluc...@yahoo.com wrote:
 I had a simple loop stripping each string but I was looking for
 something concise and efficient. I like the following answer:
 x = [s.rstrip('\n') for s in x]

Your initial requirement stated that you needed this to happen in-
place. What you're doing here is creating a completely new list and
then assigning it to x. While this is most likely what you want, note
that this will not update any other reference to that list:

 x = ['test\n', 'test2\n', 'test3\n']
 y = x
 x = [s.rstrip() for s in x]
 x
['test', 'test2', 'test3']
 y
['test\n', 'test2\n', 'test3\n']

To perform the same operation in-place, you can use the slice operator
to assign to the list object rather than to the label:

 x = ['test\n', 'test2\n', 'test3\n']
 y = x
 x[:] = [s.rstrip() for s in x] # note the slice operator
 x
['test', 'test2', 'test3']
 y
['test', 'test2', 'test3']

The latter example is especially important if you have more than one
reference to the list you're modifying and wish them all to have the
updated value.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert a list of strings to a tuple of floats?

2009-05-18 Thread alex23
On May 18, 5:51 pm, boblat...@googlemail.com
boblat...@googlemail.com wrote:
 ['1.1', '2.2', '3.3'] - (1.1, 2.2, 3.3)

 Currently I'm disassembling the list by hand, like this:

     fields = line.split('; ')
     for x in range(len(fields)):
         fields[x] = float(fields[x])
     ftuple = tuple(fields)

 Of course it works, but it looks inelegant. Is there a more Pythonisch
 way of doing this? In C I'd just use sscanf.

Either:

ftuple = tuple(map(float, fields))

Or the BDFL-endorsed:

ftuple = tuple(float(f) for f in fields)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: http://orbited.org/ - anybody using it?

2009-05-17 Thread alex23
On May 18, 9:14 am, Aljosa Mohorovic aljosa.mohoro...@gmail.com
wrote:
 can anybody comment onhttp://orbited.org/?
 is it an active project? does it work?

I have no idea about your second question but looking at PyPI,the
module was last updated on the 9th of this much, so I'd say it's very
much an active project:

http://pypi.python.org/pypi/orbited/0.7.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: x.abc vs x['abc']

2009-05-15 Thread alex23
On May 14, 5:49 am, Gunter Henriksen gunterhenrik...@gmail.com
wrote:
 Presuming it is very common to have objects created
 on the fly using some sort of external data
 definitions, is there an obvious common standard
 way to take a dict object and create an object
 whose attribute names are the keys from the dict?

I've always liked this approach, which I first saw in a post by Alex
Martelli:

 class Bunch(object):
... def __init__(self, **kwargs):
... self.__dict__.update(kwargs)
...
 b = Bunch(a=1,b=2,c=3)
 b.a
1
 b.b
2
 b.d = 22
 b.d
22


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


Re: OS X: How to play .wav file w/Python?

2009-05-11 Thread alex23
On May 12, 11:55 am, kj so...@987jk.com.invalid wrote:
 import pygame.mixer

 pygame.mixer.init()
 pygame.mixer.Sound(bell.wav).play
 print done

 What am I doing wrong?

Your first mistake is not pasting here the traceback you received.
That always makes it easier to assist with problems like this.

However, my guess is it's this line:

 pygame.mixer.Sound(bell.wav).play

'play' is a method, which means you need to call it. Try the following
instead:

 pygame.mixer.Sound(bell.wav).play()

And let us know how that goes :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP Abstract Classes

2009-05-11 Thread alex23
On May 12, 1:22 am, Mike Driscoll kyoso...@gmail.com wrote:
 I've never used (or heard of) the Abstract type...and the guy who
 wrote the FAQ was being a jerk. It looks like he was just throwing in
 an undefined variable name just to make his Python program break while
 taking a pot shot at people who use that sort of thing. Whatever.

The IAQ's entry on Abstract classes predates the introduction of
Abstract Base Classes to Python 2.6/3.0. Rather than being a jerk,
the example shows how to produce similar behaviour without code AS
WELL as demonstrating a more extended approach. (You're not breaking
your program if the behaviour is intentional...)

 Hopefully someone who has used Abstract classes will jump in here and
 give you more information about whether or not they matter in Python.

Abstract classes are one mechanism for defining interfaces, but as
we've covered it's not the only approach that can be taken. I've
always been happy defining abstract methods using 'raise
NotImplementedError', but clearly the ABC approach is perceived as
having value otherwise it would never have been introduced into
2.6/3.0.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing from a module which contains more than one Class...

2009-05-10 Thread alex23
GKalman kalma...@msn.com wrote:
 from MyClass import *
 from MyOtherClass import *     # error msg: no such module!

 As I mentioned above,  the code for MyClass  MyOtherClass is in the same
 file . This program only works with a single Class in a file. That is when
 the File name is the SAME as the Class name.

 How to import from a File which contains more than one (unrelated) Classes?

You seem to have misunderstood how 'import' works, I strongly
recommend re-reading the tutorial section:
http://docs.python.org/tutorial/modules.html

Basically, the import statement has two forms:

   1. from module import contents
   2. import module

So your example of 'from classname import *' just doesn't make a lot
of sense within Python.

If MyClass.py contains two classes, MyClass and MyOtherClass, you
should be able to import them with:

   from MyClass import MyClass, MyOtherClass

However, you _should_ be already getting _everything_ MyClass.py
contains as you're using the grab-all asterisk. Could you open a
python shell in your Module_Class folder, type 'from MyClass import
MyClass, MyOtherClass', and past whatever traceback you get here?
--
http://mail.python.org/mailman/listinfo/python-list


Re: free chart lib for Python?

2009-05-07 Thread alex23
On May 8, 12:27 pm, oyster lepto.pyt...@gmail.com wrote:
 is there such a thing with many kinds of chart, i.e. pie-chart,
 line-chart, ..?

The best place to look is PyPI, there are several possible candidates
there:
http://pypi.python.org/pypi?%3Aaction=searchterm=chartssubmit=search

I've had a lot of success with the Python Google Chart module:
http://pygooglechart.slowchop.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: list comprehension question

2009-05-06 Thread alex23
On May 6, 2:10 pm, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 It's precisely the indentation and colons (plus newlines) that makes
 nested for-loops easier to read than list-comps with multiple fors.

 You can get back *nearly* all the readability by splitting the list comp
 into multiple lines:

It was less the overall readability I was commenting on, and more the
claim that the listcomp required a 'back-and-forth' parsing to
understand. As you've reinforced, the listcomp can be readily
converted back to the multiple-line form by the inclusion of colons 
EOL markers, which means you can make as much sequential sense from a
listcomp as you can a for-loop.
--
http://mail.python.org/mailman/listinfo/python-list


Re: list comprehension question

2009-05-05 Thread alex23
On May 6, 4:01 am, J. Cliff Dyer j...@sdf.lonestar.org wrote:
 The way you have to bounce your eyes back and forth in the comprehension
 makes it hard to read the logic.  With the loop, on the other hand it is
 blatantly obvious which way the nesting occurs.

   [ item for j in a if len(j)==2 for item in j if item % 2 ]
   ...opposed to...
   for j in a:
   ...     if len(j)==2:
   ...         for item in j:
   ...             if item % 2:
   ...                 b.append(item)
   ...

 Much nicer.  Thank you.

Apart from the presence of 'item' at the beginning of the list
comprehension as opposed to 'b.append(item)' at the end of the for-
loop, how exactly does the listcomp force you to bounce [..] back and
forth to follow the logic? The only other difference between the two
is in the layout - the indentation  colons - otherwise they're
structurally identical.
--
http://mail.python.org/mailman/listinfo/python-list


Re: for with decimal values?

2009-05-03 Thread alex23
On May 4, 11:41 am, Esmail ebo...@hotmail.com wrote:
 All this discussion makes me wonder if it would be a good idea
 for Python to have this feature (batteries included and all) - it
 would have its uses, no?

Well, sometimes more discussion == less consensus :)

But it's really easy to roll your own:

from decimal import Decimal

def args2dec(fn):
'''*args to Decimal decorator'''
float2dec = lambda f: Decimal(str(f))
def _args2dec(*args):
args = map(float2dec, args)
return fn(*args)
return _args2dec

@args2dec
def drange(start, stop, step):
while start  stop:
yield start
start += step

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


Re: import and package confusion

2009-05-01 Thread alex23
On May 1, 4:24 pm, Arnaud Delobelle arno...@googlemail.com wrote:
 It's a challenge to do it in a list comprehension, but here it is!
  data
 'AAABCDD'
  field_sizes
 [3, 5, 9, 2]
  [data[i:j] for j in [0] for s in field_sizes for i, j in [(j, j+s)]]
 ['AAA', 'B', 'C', 'DD']

Ugh. I know using a listcomp was the point but I find using struct so
much more elegant.

 import struct
 data = 'AAABCDD'
 format = '3s5s9s2s'
 struct.unpack(format, data)
('AAA', 'B', 'C', 'DD')

Friends don't let friends abuse list comprehensions.

I made sure the code works this time :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: import and package confusion

2009-04-30 Thread alex23
On Apr 30, 1:10 pm, Dale Amon a...@vnl.com wrote:
 I do not really see any other way to do what I want. If
 there is a way to get rid of the exec in the sample code
 I have used, I would love to know... but I can't see how
 to import something where part of the name comes from user
 command line input without interpreting the code via exec.

Are you familiar with __import__?

iotypes = [WINGTL,VLMPC,VLM4997]
for iotype in iotypes:
  packagename = VLMLegacy. + iotype + .Conditions
  classname   = iotype + _Conditions
  module  = __import__(packagename)
  cls = getattr(module, classname)
  # etc

Much cleaner :) And far more secure: any time you think user input
AND exec, you're probably going in the wrong direction...
--
http://mail.python.org/mailman/listinfo/python-list


Re: import and package confusion

2009-04-30 Thread alex23
On Apr 30, 5:33 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 (doesn't work as written, because [...]

Man, I don't get Python... I can write a program that runs properly on
the first try but every time I post untested code to c.l.p I regret
it...

Thanks, Gabriel :)

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


Re: command prompt history filtered by initial letters

2009-04-30 Thread alex23
On May 1, 8:01 am, limit todd.les...@gmail.com wrote:
 How do I get this command history filter working on the centos
 install? I see that ctrl-r allows history search. That is the
 workaround.

If you can, try installing  using iPython instead:
http://ipython.scipy.org/

Along with a wealth of other useful features, it provides exactly the
kind of history behaviour you're looking for.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web framework for embedded system

2009-04-29 Thread alex23
On Apr 30, 3:32 am, Thomas Heller thel...@python.net wrote:
 I'm very happy to see that these frameworks deliver ~10 pages per second
 (cherrypy) or ~3.5 pages per second (webpy) out of the box on a system
 that is 50 times slower than a typical desktop PC.  Of course these
 were very short pages.

I was remiss earlier in not mentioning circuits:
http://trac.softcircuit.com.au/circuits/
http://groups.google.com/group/circuits-users

Circuits is an event  component framework that just happens to
include a cherrypy-like web server, and apparently (I can't find a
cite) outperforms cherrypy in a number of tests:

from circuits.web import Server, Controller

class Root(Controller):
   def index(self):
  return Hello World!

(Server(8000) + Root()).run()

Full disclaimer: circuits is written by a friend  former colleague,
who will never forgive me for not having mentioned it in the first
place :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: AtrributeDict

2009-04-29 Thread alex23
On Apr 30, 9:09 am, Дамјан Георгиевски gdam...@gmail.com wrote:
 I've needed an attribute accessible dict, so I created this.
 Are there any obviously stupid shortcomings?

 class AttrDict(dict):
    def __getattr__(self, name):
        try:
            return self[name]
        except KeyError, e:
            raise AttributeError(e)

Have you seen Alex Martelli's Bunch class?

class Bunch:
def __init__(self, **kwds):
self.__dict__.update(kwds)

From http://code.activestate.com/recipes/52308/

With Alex' version, you're not overloading a commonly called method,
nor do you have to worry about the performance of the exception
handling for misses. Plus it's half as long ;)

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


Re: Web framework for embedded system

2009-04-28 Thread alex23
On Apr 28, 5:43 pm, Thomas Heller thel...@python.net wrote:
 I'm looking for a lightweight web-framework for an embedded system.
 [...]
 Does this sound sensible at all? Any suggestions?

I'd highly recommend taking a look at CherryPy: http://www.cherrypy.org/

The developers describe it as a HTTP framework, being lower-level
than most of the available web frameworks. But it should be very
straightforward and more than suitable for your needs.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Presentation software for Python code

2009-04-24 Thread alex23
On Apr 24, 4:23 pm, Michael Hoffman 4g4trz...@sneakemail.com wrote:
 That looks like it would be perfect. Unfortunately it doesn't seem to
 work on my Windows laptop:

 I don't understand this. OpenGL Extensions Viewer says I have OpenGL 1.5
 and the glGenBuffers function.

That's a shame, if you feel like pursuing it you should report the
error to the pyglet devs, but I'd certainly understand if you didn't.

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


Re: Presentation software for Python code

2009-04-23 Thread alex23
On Apr 24, 3:52 am, Michael Hoffman 4g4trz...@sneakemail.com wrote:
 Does anyone here have software they would suggest for making a
 presentation that includes Python code? Other than that it would
 probably be mainly bullet points. I'm willing to consider TeX- and
 HTML-based approaches.

How do you feel about reStructuredText? If you're open to it, I highly
recommend Bruce: http://pypi.python.org/pypi/bruce

It also supports embedded interpreters in the presentation, which I've
seen using to good effect at conventions.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the best framework or module in Python for a small GUI based application development?

2009-04-22 Thread alex23
On Apr 23, 2:13 am, Mike Driscoll kyoso...@gmail.com wrote:
 Technically speaking, Silverlight can be run with IronPython...which
 works on Windows and Linux (through Mono), but not Mac (as far as I
 know).

It looks like MS provide a Mac version as well:
http://www.apple.com/downloads/macosx/development_tools/silverlight.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: the correct way to install python packages as non root user in non default path

2009-04-20 Thread alex23
On Apr 21, 8:32 am, News123 news...@free.fr wrote:
 I'm having an Ubuntu host, but want to (experimentally)
 install some modules, which are newer than the Ubuntu ones
 (distros lag always a little behind and some tools need newer versions.)

 What would be a clean way to do this?

I think virtualenv will help you here: http://pypi.python.org/pypi/virtualenv


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


Re: The Python standard library and PEP8

2009-04-20 Thread alex23
On Apr 21, 1:18 pm, Tim Wintle tim.win...@teamrubber.com wrote:
 There was some suggestion about introducing synonyms that followed PEP8
 and introducing deprecation warnings as you suggested, but I can't
 remember the outcome. I'd suggest checking the dev archives.

What about the possibility of offering an additional, PEP8-compliant
API for each?

   import logging # the current interface
   import logging.pep8 # the PEP8-compliant interface

I'd be happy to contribute to this if it was considered worthwhile.

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


Re: Any adv. in importing a module and some objects in the same module, into the same file?

2009-04-19 Thread alex23
On Apr 17, 7:19 pm, Visco Shaun visc...@gmail.com wrote:
 What is the use of second import as the first import will be
 enough(AFAIK) to access anything intended by the second import?
 Is there any kind of advantage?

While Piet's explanation is correct for the logging module, you'll
also see examples like:

import os
import os.path

Where os.path _is_ accessible via the original os import.

I believe that in this case, os.path is imported and stored against
'os.path', so any further references to it will be handled by the
standard module lookup, rather than having to look up the 'os' import
and then use getattr to reach path. I would expect that this is mostly
of interest if you were using os.path.methods in an inner loop, to
reduce the number of lookups.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Too early implementation

2009-04-18 Thread alex23
On Apr 18, 9:48 pm, Filip Gruszczyński grusz...@gmail.com wrote:
 With Python you rarely are sorry, because you can do everything so
 quickly. And yet, at some point you see, that flaws in design get so
 annoying, that you need to do something about them. Usually at that
 point it's a bit problematic ;-)

 So, do you know some good methods to prevent myself from just starting
 coding (which I like very much) and do some thinking about the problem
 (which I like a little less ;-))?

Try test-driven development: 
http://en.wikipedia.org/wiki/Test-driven_development
--
http://mail.python.org/mailman/listinfo/python-list


Re: howto submit documentation bugs on python V3 web-site ?

2009-04-17 Thread alex23
On Apr 17, 4:36 pm, Andreas Otto aotto1...@onlinehome.de wrote:
 Hi,

   is an email or something else available ?

http://docs.python.org/3.0/bugs.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question to python C API

2009-04-17 Thread alex23
On Apr 17, 4:22 pm, Andreas Otto aotto1...@onlinehome.de wrote:
         Question 1: Why you wall it Pyrex package ?

From the first paragraph on the Cython site: Cython is based on the
well-known Pyrex, but supports more cutting edge functionality and
optimizations.

 python ./setup.py install

 Traceback (most recent call last):
   File ./setup.py, line 5, in module
     from Cython.Compiler.Version import version
   File /home/dev1usr/src/Cython-0.11.1/Cython/__init__.py, line 2, in
 module
     from Shadow import *
 ImportError: No module named Shadow

Did you unpack the Cython archive correctly? Is there a Shadow.py in
your src/Cython-0.11.1/Cython/ folder?

   4. than I try the second part from INSTALL.txt
 (2) If you prefer not to modify your Python
     installation, arrange for the directory
     containing this file (INSTALL.txt) to be in
     your PYTHONPATH. On unix, also put the bin
     directory on your PATH.

 Traceback (most recent call last):
   File setup.py, line 3, in module
     from Cython.Distutils import build_ext
 ImportError: No module named Cython.Distutils

Did you follow the 2nd set of instructions  modify both your
PYTHONPATH  PATH env vars? Have you confirmed they're correct? This
is the sort of error I'd expect if those weren't set up properly.

   7. a little bit to much errors for the first step, isn't it ?

Yes, however none of these happened when I just installed Cython to
the XP, OSX  Ubuntu boxen I'm working on, so this isn't usual
behaviour.

What is your setup? What OS?
--
http://mail.python.org/mailman/listinfo/python-list


Re: script question

2009-04-17 Thread alex23
On Apr 17, 5:00 pm, Stefano stef...@vulcanos.it wrote:
 How can i execute my func in the code ?

 import myscript
 for i in range(1,n):
     myscript.func??


for i in range(1,n):
getattr(myscript, 'func%d' % i)()
--
http://mail.python.org/mailman/listinfo/python-list


<    5   6   7   8   9   10   11   12   13   14   >