Re: To Troll or Not To Troll (aka: "as" keyword woes)

2008-12-05 Thread Michael Mabin
Warren, weren't you aware that Python.org is now a church.  So you can never
live up to the standards of the Pythonista high priests.  You can only ask a
question or submit your comment then cower, hoping the pythonista high
priests don't beat you with clubs for heresy.

;)



2008/12/4 Warren DeLano <[EMAIL PROTECTED]>

> > From: Ben Finney <[EMAIL PROTECTED]<[EMAIL PROTECTED]>
> >
> >
> > "Chris Mellon" <[EMAIL PROTECTED]> writes:
> >
> > > Peculiarities in usenet resulted in this discussion having several
> > > threads and I missed some messages before I wrote this email.
> >
> > I'll put this more bluntly: Warren's messages to date
> > egregiously break the flow of discussion.
> >
> > Warren, in the interest of sane discussion in these forums, please:
> >
> > * preserve attribution lines on quoted material so we can see who
> >   wrote what.
> >
> > * use the convention of ?New subject (was: Old subject)? when you
> >   change the ?Subject? field of a message.
> >
> > * switch to a client that preserves threading in messages you send,
> >   i.e. that properly constructs the ?References? and ?In-Reply-To?
> >   fields.
> >
> > General advice good for everyone, of course, but particularly
> > apropos to this reply. Any one of the above is detrimental to
> > omit; striking on all three makes a discussion almost
> > impossible to follow. (Thank you, though, for avoiding the
> > worse habit of top posting!)
>
> Thank so much for the suggestions Ben.  Sorry that I am personally
> unable to live up to your high standards, but it is nevertheless an
> honor to partipicate in such a helpful and mutually respectful community
> mailing list!
>
> Warren
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to replace and string in a "SELECT ... IN ()"

2008-09-28 Thread Michael Mabin
Sadly no.  There is no utterance too inconsequential.

On Sun, Sep 28, 2008 at 3:10 PM, Steve Holden <[EMAIL PROTECTED]> wrote:

> Michael Mabin wrote:
> > Tino, dude, I'm afraid I lied about my previous post being the last
> > word.  There are some things you said here that must be addressed.
>
> Good grief, is there no utterance so inconsequential that you will walk
> away from it without yet another round of retaliation?
>
> I believe that all people were trying to convey is:
>
> 1. There are some data patterns that cannot be directly incorporated
> into SQL statements without additional processing, regardless of whether
> the "intention" of the data's originator is malevolent. A good example
> is a string value containing an apostrophe, which in most SQL
> implementations you can escape by preceding the apostrophe with another
> apostrophe.
>
> 2. SQL drivers in Python are written so that no matter what the values
> of the data may be, and no matter which backend they implement, data may
> safely be passed as a tuple to a parameterized statement without such
> cleansing because the drivers are written to ensure "dangerous" values
> are appropriately handled.
>
> Having said all that, if you are positive none of your string data
> contains apostrophes you are, of course, free to build SQL statements
> yourself - though doing so will on some systems lose you the speed
> advantages offered by "prepared statements". Similarly, if you are *not*
> positive of the quality of your data you are free to do the escaping in
> your logic rather than using parameterized queries. This could be called
> "buying a dog and barking yourself".
>
> regards
>  Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-28 Thread Michael Mabin
Tino, dude, I'm afraid I lied about my previous post being the last word.
 There are some things you said here that must be addressed.

On Sun, Sep 28, 2008 at 6:00 AM, Tino Wildenhain <[EMAIL PROTECTED]> wrote:

> Michael Mabin wrote:
>
>> I'm exhausted, so I'll just shut up about this after a few final words.
>>
>
> Thank you for your time :-)
>
>> 1.  "edits" is used in data warehousing to describe data scrubbing or
>> filtering of fields in records that are used as input sources for loading
>> into data warehouses. It's a term that goes way back to batch processing on
>> the mainframe, so it's been used this way for a long time. Sometimes we use
>> 'validation' interchangeably with 'edit' but our use of validation usually
>> involves a check of input data against business rules and not type or range
>> checking which we consider 'edits'.  So maybe you're not used to hearing the
>> term used this way, but it is a variation perhaps of what you're used to.
>>
>
> And so on and so on in the regular top posting manner


I thought I was clearing up your statement that "there is no such thing as
edits" and then you went on  about not knowing what I meant by "edits" .
 Why do you dismiss my effort to clarify a point you were clearly wrong
about?

...
>
> Just to give you some thoughts again: your solution might be valid for
> you in your controlled environment. Yet you just presented it to the
> OP without telling him the limits of when this can be used. And this
> is outright dangerous. If one sees this without comment and without your
> background she will run into problems sooner or later. So my suggestion
> was to either don't tell people such solutions at all or tell them
> exactly under which circumstances they might be used.
>

Outright dangerous?  Again, you're assuming the OP's problem involved user
input from a web-page.  I was addressing the stated requirement of the
problem.  You can't automatically assume that this problem is related to
input from a web-page.  Why should I code in a manner that I will never
encounter?  Maybe instead of suggesting that my recommendation is outright
dangerous, you yourself might suggest the caveats.  Again, most of my
experiences lie within the batch environment, but I shouldn't have to
qualify my suggestions with 'this is what we do in the batch environment'.
 On a mailing list, people are free to point out the limits of my
recommendation, but that doesn't necessarily disqualify my recommendation.

>
> Still I think nailing the problem at the apropriate place is a habit
> which should generally devloped - as in your example an additional
> int() would have fixed it - but still it would not work if you
> want to deal with arbitrary strings. So its good to make suggestions
> but pretty please think ahead how someone would use it instead of
> investing all your energy into defending dangerous programming practice.


Again, danger is in the eye of the beholder and the hands of the user and
determined mostly by the circumstances.  A code generator written in Python
is going to be subject to all kinds of programming considerations that are
different from those in web applications.


> With "we in python" I referred to a fairly amount of literature about
> programming in python and it design patterns. Nothing me personally.
>

I wasn't aware that we are what has been written or what we have read.  I
thought we refers to people.  Though this sounds a lot like religion. And
maybe I am guilty of heresy.


> Ah and some final words to the controlleness of datawarehouse
> applications and similar things: by the time you are designing such
> a solutuion you will never know what future applications will be
> developed around it so its always best to be prepared.
>

Huh? What are you talking about?


>
> "Data scrubbing" seems a common idea but in fact its very hard to do
> it right due to the nature of different systems using different
> quoting logic. "Dont trust your input" is a habit not only applicable
> to web programming - in fact the company I work for does not do much
> web application but input validation is something we get even audited
> for.
>

"We" are always mindful of the problems "data scrubbing" entails.

Data scrubbing depends on the requirements, like everything else.  And of
course, it goes without saying that you should not trust your input, that
you should check and validate where appropriate.



>
> Nevertheless I wish you a very good weekend :-)
>
> Tino
>
>
Peace.
Michael

-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-27 Thread Michael Mabin
I'm exhausted, so I'll just shut up about this after a few final words.
1.  "edits" is used in data warehousing to describe data scrubbing or
filtering of fields in records that are used as input sources for loading
into data warehouses. It's a term that goes way back to batch processing on
the mainframe, so it's been used this way for a long time. Sometimes we use
'validation' interchangeably with 'edit' but our use of validation usually
involves a check of input data against business rules and not type or range
checking which we consider 'edits'.  So maybe you're not used to hearing the
term used this way, but it is a variation perhaps of what you're used to.

2.  The data warehousing world is quite different from the web world in many
respects.  I appreciate the fact that web application developers must always
be mindful of the 'barbarians at the gates' but our batch environments are
locked down, especially our databases.  We have secured batch IDs. Our
programs are run using an automated schedule.  Our databases are secured to
begin with so not even our batch IDs have alter, create or drop permissions
on the database.  There's no way this exploit would ever enter this
environment because those servers aren't accessible through the web or
online.

3.  When you say 'in python we don not fear that' it's curious, because it
assumes that all Python users must think as you do.  And yet, clearly I
don't think as you do.  I really like this language and praise the
Netherlands each day I wake up that they gave us someone as brilliant as
Guido to make programming fun and not such a chore.  But I think there are
valid reasons for taking different approaches to security, data validation
and dare I say it -- field editing -- despite the claims of many who say
that in Python - TOOWTDI.

4. It's also curious that I was obliged to state my assumptions about batch
programming vs. web programming.  There is nothing in the OP to suggest that
the problem was related to web programming.  It's a question about how to
interpolate the values in a list with format specifiers in a SQL statement.
 Still, if this list is not the result of user input but was derived within
the body of the program, which by itself has no malicious intent, are we
still going to code this as if it were input by a user that might be a
hacker?  This seems retarded and paranoid to me.  And where in that post
does it say that the list is from web input?  Although to be fair maybe most
of the Python community is doing web development.

Thanks for the stimulating and educational discussion.

On Sat, Sep 27, 2008 at 4:30 PM, Tino Wildenhain <[EMAIL PROTECTED]> wrote:

> Hi,
>
> Michael Mabin wrote:
>
>> If the inputs are edited prior to the construction of the string and these
>> fields are used for more than one update then it's not an exploit.  It's
>> simply a matter not repeating yourself when coding.
>>
>
> In python we do not fear that.
>
>  In this particular case too, we're talking about a list of integers that
>> gets inserted into a string.  If the list is validated prior to its
>>
>
> Its a list, if it indeed has integers in it is uncertain. It is so very
> easy to check that that it doesnt even make sense to write such lengthy
> emails about how bad you want to avoid it. Just do it. And even more so
> if you are telling others how to do things make sure they do not so easy
> shoot themselfes in their feet.
>
>  insertion into an SQL statement then there is no exploit.  If I write a
>> batch program (not a web program) that retrieves this list of integers from
>> other sources and validates the data prior to using it in an SQL statement,
>> that should be sufficient.
>>
>
> This might be well true but if you have a look at your original
> contribution you see that all these your asumtions are just not in.
>
>  As far as wrong and right is concerned. I think it's more about doing what
>> is appropriate according to the circumstances.  As a rule you
>>
>
> If its easy to do, why not just doing it correctly (or robust) in all
> circumstances to just avoid overlooking a case?
>
>  should only code what is appropriate for the circumstances.  If it's
>> appropriate to code more simply without introducing unnecessary complexity
>> you should do so.
>>
>
> But you did not tell us about your asumtations about the circumstances.
>
>  I work in the data warehousing ETL world, where we have to perform field
>> edits or transformations to load source data into databases.  If I'm
>>
>
> Thats wrong. You do not "edit" fields. You have a validating type path and
> _always_ the database is most 

Re: python for *nix system admins

2008-09-27 Thread Michael Mabin
import commands ?

On Sat, Sep 27, 2008 at 8:06 AM, George Boutsioukis
<[EMAIL PROTECTED]>wrote:

> On Sat, 27 Sep 2008 10:05:01 +0200, Lars Stavholm wrote:
>
> > Hi All,
> >
> > I'm new to this list and hoping that this is not off-topic. If it is,
> > please point me in the right direction.
> >
> > I seem to recollect a python module or library for *nix sysadmins, but I
> > can't for the life of me find it again.
> >
> > The module (or library) somehow added unix command capabilities to the
> > python language. It seemed like a lesser known, perhaps new, python
> > library or module.
> >
> > Any input or ideas appreciated
> > /Lars Stavholm
>
> The only modules I've come across that barely fit your description are
> python-unixtools(gzip, bzip only) and shutil(some limited capabilities).
> Running unix commands is usually done directly(os.popen, os.system) on
> *nix platforms. Why(and how) would anyone rewrite them as python modules?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-27 Thread Michael Mabin
If the inputs are edited prior to the construction of the string and these
fields are used for more than one update then it's not an exploit.  It's
simply a matter not repeating yourself when coding.
In this particular case too, we're talking about a list of integers that
gets inserted into a string.  If the list is validated prior to its
insertion into an SQL statement then there is no exploit.  If I write a
batch program (not a web program) that retrieves this list of integers from
other sources and validates the data prior to using it in an SQL statement,
that should be sufficient.

As far as wrong and right is concerned. I think it's more about doing what
is appropriate according to the circumstances.  As a rule you should only
code what is appropriate for the circumstances.  If it's appropriate to code
more simply without introducing unnecessary complexity you should do so.

I work in the data warehousing ETL world, where we have to perform field
edits or transformations to load source data into databases.  If I'm already
performing edits on these fields and if these fields are going to be used
for more updates downstream, it's wasteful to perform them again when I
build the SQL insert with the list and execute it.

Finally, whatever happened to the practice of granting appropriate
privileges to IDs that perform database operations?  Shouldn't the person
acting in the capacity of DBA ensure that the user updating or retrieving
data from the database does not have DROP, ALTER, or CREATE privileges on
that database?

On Sat, Sep 27, 2008 at 9:14 AM, Tino Wildenhain <[EMAIL PROTECTED]> wrote:

> Hi,
>
> Michael Mabin wrote:
>
>> so you wouldn't object then to something like
>>  ' in (%)' % ','.join([str_edit_for_exploit(x) for x in
>> aList])
>> if str_edit_for_exploit applied security edits?
>>
>
> Whats an security edit btw? If it is something meant to turn possibly
> insecure data into 'secure' then, no I would still object.
> Why? Because its a bad example of "default permit". Its always better
> to have a whitelist - even more so when its so easy to do.
>
> Its just a habit you develope - if you never do it right, how would you
> know when and how to do it right when you need to?
>
> Tino
>



-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-26 Thread Michael Mabin
oops. i meant.
' in (%s)' % ','.join([str_edit_for_exploit(x) for x in aList])


On Fri, Sep 26, 2008 at 5:05 PM, Michael Mabin <[EMAIL PROTECTED]> wrote:

> so you wouldn't object then to something like ' in (%)' %
> ','.join([str_edit_for_exploit(x) for x in aList])
>
> if str_edit_for_exploit applied security edits?
>
> On Fri, Sep 26, 2008 at 2:28 PM, Benjamin Kaplan <[EMAIL PROTECTED]
> > wrote:
>
>>
>>
>> On Fri, Sep 26, 2008 at 3:04 PM, Michael Mabin <[EMAIL PROTECTED]>wrote:
>>
>>> Doesn't it depend on where and why you intend to execute the code?
>>> Obviously some SQL is more at risk for exploit when the input is from the
>>> screen on a web page than if you were running parameterized code in a
>>> controlled batch environment.  Or if you were writing code generators (which
>>> is what I happen to do) which won't be run by the general public.
>>>
>>> Incidentally, couldn't input field edits prevent such exploits prior to
>>> interpolation?
>>>
>>
>> There are ways to avoid SQL injection attacks, such as escaping all quotes
>> in the text. We were simply pointing out that you have to be very careful
>> when you add arbitrary strings into SQL statements. If you control
>> everything going into the statement, you shouldn't have to worry about this.
>>
>>
>>
>
>
> --
> | _ | * | _ |
> | _ | _ | * |
> | *  | * | * |
>



-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-26 Thread Michael Mabin
so you wouldn't object then to something like ' in (%)' %
','.join([str_edit_for_exploit(x) for x in aList])

if str_edit_for_exploit applied security edits?

On Fri, Sep 26, 2008 at 2:28 PM, Benjamin Kaplan
<[EMAIL PROTECTED]>wrote:

>
>
> On Fri, Sep 26, 2008 at 3:04 PM, Michael Mabin <[EMAIL PROTECTED]> wrote:
>
>> Doesn't it depend on where and why you intend to execute the code?
>> Obviously some SQL is more at risk for exploit when the input is from the
>> screen on a web page than if you were running parameterized code in a
>> controlled batch environment.  Or if you were writing code generators (which
>> is what I happen to do) which won't be run by the general public.
>>
>> Incidentally, couldn't input field edits prevent such exploits prior to
>> interpolation?
>>
>
> There are ways to avoid SQL injection attacks, such as escaping all quotes
> in the text. We were simply pointing out that you have to be very careful
> when you add arbitrary strings into SQL statements. If you control
> everything going into the statement, you shouldn't have to worry about this.
>
>
>


-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-26 Thread Michael Mabin
Doesn't it depend on where and why you intend to execute the code?
Obviously some SQL is more at risk for exploit when the input is from the
screen on a web page than if you were running parameterized code in a
controlled batch environment.  Or if you were writing code generators (which
is what I happen to do) which won't be run by the general public.

Incidentally, couldn't input field edits prevent such exploits prior to
interpolation?
On Fri, Sep 26, 2008 at 11:38 AM, D'Arcy J.M. Cain <[EMAIL PROTECTED]> wrote:

> On Fri, 26 Sep 2008 11:00:59 -0500
> "Michael Mabin" <[EMAIL PROTECTED]> wrote:
> > So we can drop a table in an in clause?  How is this a use case.
>  Cartoons
> > are funny but actual proof that this example using an in-clause provides
> an
> > exploit would be more helpful I think.
>
> I'm not sure what proof you require.  If you program such that users
> can enter arbitrary stings into your database it is obvious that the
> exploit in that cartoon can be used against you.  And the point is that
> it has nothing to do with IN clauses.  It can be any SQL.  Go read that
> cartoon carefully.  It says nothing about IN clauses.  Consider;
>
> "UPDATE student SET name = '%s' WHERE student_id = %s" % (name, id);
>
> Now set name to "Robert'; DROP TABLE student;" and see what happens if
> you feed that to your SQL database.  Hell, just put "';" in the string
> for fun.
>
> --
> D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
> http://www.druid.net/darcy/|  and a sheep voting on
> +1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
>



-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-26 Thread Michael Mabin
So we can drop a table in an in clause?  How is this a use case.  Cartoons
are funny but actual proof that this example using an in-clause provides an
exploit would be more helpful I think.

On Fri, Sep 26, 2008 at 9:50 AM, Benjamin Kaplan
<[EMAIL PROTECTED]>wrote:

>
>
>  On Fri, Sep 26, 2008 at 10:38 AM, Michael Mabin <[EMAIL PROTECTED]>wrote:
>
>>  I laugh in the face of danger.
>>
>> Give me a use case for an exploit.
>>
>
> http://xkcd.com/327/
>
>


-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-26 Thread Michael Mabin
I laugh in the face of danger.

Give me a use case for an exploit.

On Fri, Sep 26, 2008 at 8:05 AM, Tino Wildenhain <[EMAIL PROTECTED]> wrote:

> Michael Mabin wrote:
>
>>   cursor.execute("""
>>   SELECT titem.object_id, titem.tag_id
>>   FROM tagging_taggeditem titem
>>   WHERE titem.object_id IN (%s)
>>   """ % ','.join([str(x) for x in [1,5,9]])
>>
>
> Nope. That would be dangerous! -> google for SQL injection
>
> Tino
>



-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-26 Thread Michael Mabin
   cursor.execute("""
   SELECT titem.object_id, titem.tag_id
   FROM tagging_taggeditem titem
   WHERE titem.object_id IN (%s)
   """ % ','.join([str(x) for x in [1,5,9]])

On Fri, Sep 26, 2008 at 6:23 AM, Tino Wildenhain <[EMAIL PROTECTED]> wrote:

> Hi,
>
> Bruno Desthuilliers wrote:
>
>> bcurtu a écrit :
>>
>>> Hi,
>>>
>>> I have a BIG problem with the next query:
>>>
>>>cursor.execute("""
>>>SELECT titem.object_id, titem.tag_id
>>>FROM tagging_taggeditem titem
>>>WHERE titem.object_id IN (%s)
>>>""",( eid_list))
>>>
>>> eid_list is suppossed to be a list of ids = [1,5,9]
>>>
>>> How can I make it work?
>>>
>>
>> You have to build your sql statement in three stages:
>>
>> # stage 0: the template
>> sql_template = """
>>SELECT titem.object_id, titem.tag_id
>>FROM tagging_taggeditem titem
>>WHERE titem.object_id IN (%s)
>> """
>>
>> # stage 1: build correct place_holders string for the actual number
>> # of items in eid_list
>> place_holders = ", " .join("%s" for x in xrange(len(eid_list)))
>>
>
> Hm. either ", ".join(["%s"]*len(eid_list))
> or ", ".join("%s" for x in eid_list)
>
> should produce the same, wouldn't it? :-)
>
>  # stage 2 : build the effective sql statement
>> sql = sql_template % place_holders
>>
>> # ok, let's go:
>> cursor.execute(sql_template, eid_list)
>>
>>
>> NB : you can of course make it in a single statement, but readability will
>> suffer:
>>
>> cursor.execute(
>>"""
>>SELECT titem.object_id, titem.tag_id
>>FROM tagging_taggeditem titem
>>WHERE titem.object_id IN (%s)
>>""" % ", " .join("%s" for x in xrange(len(eid_list))),
>>eid_list
>>)
>>
>
> I'd think giving the arguments in a form of an array type should
> work too. At least in postgres there are references to do so.
>
> Regards
> Tino
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Fwd: Twisted vs. CherryPy vs. ??? for light-weight web servers

2008-09-24 Thread Michael Mabin
I just want to be able to write simple scripts to serve xml data and don't
want the headache of administrating an apache server.  I want to collect
some data from some of our production servers and share them with a
sharepoint website.

On Wed, Sep 24, 2008 at 12:29 PM, Jean-Paul Calderone <[EMAIL PROTECTED]>wrote:

> On Tue, 23 Sep 2008 21:22:08 -0500, Michael Mabin <[EMAIL PROTECTED]>
> wrote:
>
>> Is there any consensus on what the best lightweight web-server is?  Or
>> rather would Twisted be a better choice to choose as a framework that
>> allows
>> me to serve html or xml data for light webservices. Or is CherryPy just as
>> good?
>>
>>
> You haven't described the problem you want to solve in very much detail.  I
> can't tell, for example, why I shouldn't recommend that you use Apache
> instead
> of CherryPy or Twisted or anything else.  Apache has a huge user community,
> lots of documentation, and lots of developers fixing its bugs and making it
> work well.  What are you trying to do that would make Apache a bad choice?
>
> Jean-Paul
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Twisted vs. CherryPy vs. ??? for light-weight web servers

2008-09-23 Thread Michael Mabin
Is there any consensus on what the best lightweight web-server is?  Or
rather would Twisted be a better choice to choose as a framework that allows
me to serve html or xml data for light webservices. Or is CherryPy just as
good?

-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: From Ruby to Python?

2008-08-14 Thread Michael Mabin
I kind of went the other way.  I knew some Python and then learned Ruby.  I
found that the two languages were similar enough that I didn't really need a
Ruby for Python programmers help doc.  There's not much of a paradigm shift
(except for the whitespace and indentedness of Python) going from one to the
other.  Of course, I had done quite a bit of Perl too.

Ruby does have a little of the Perl spirit of 'There's More Than One Way to
Do It'. And you do need shift to Python's 'There's Only One Way To Do It'.

On Thu, Aug 14, 2008 at 4:26 AM, Simon Mullis <[EMAIL PROTECTED]> wrote:

> In case anyone else has the same question:
>
> This has been very useful:  http://www.poromenos.org/tutorials/python
>
> Short, concise. Enough to get me going.
>
> SM
>
> 2008/8/13 Simon Mullis <[EMAIL PROTECTED]>
>
> Hi All,
>>
>> I just finally found 30 minutes to try and write some code in Python and
>> realized after a couple of minor syntactic false starts that I'd finished my
>> initial attempt without needing to refer to any documention... And after the
>> first few minutes I stopped noticing the whitespace thing that had scared me
>> off previously.  (Admittedly it's a very basic script using telnetlib to log
>> into a bunch of network devices via a few console servers and put the
>> results of some remote commands into a data-structure).
>>
>> So, after this initially promising start:
>>
>> Are there any good cheatsheets / guides for a Ruby programmer to learn
>> Python?
>>
>> I searched this list and couldn't find anything, and wasn't successful
>> with google either...
>>
>> Many thanks in advance,
>>
>> SM
>>
>> --
>>
>
>
>
> --
> Simon Mullis
> _
> [EMAIL PROTECTED]
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: SSH utility

2008-08-11 Thread Michael Mabin
I use pexpect.

On Mon, Aug 11, 2008 at 7:22 AM, Jean-Paul Calderone <[EMAIL PROTECTED]>wrote:

> On Sun, 10 Aug 2008 21:25:38 -0700 (PDT), James Brady <
> [EMAIL PROTECTED]> wrote:
>
>> Hi all,
>> I'm looking for a python library that lets me execute shell commands
>> on remote machines.
>>
>> I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
>> unfortunately all been unreliable, and repeated questions on their
>> respective mailing lists haven't been answered...
>>
>> It seems like the sort of commodity task that there should be a pretty
>> robust library for. Are there any suggestions for alternative
>> libraries or approaches?
>>
>
> You can find an example of running commands over SSH with Twisted online:
>
>  http://twistedmatrix.com/projects/conch/documentation/examples/
>
> Jean-Paul
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Brainwave: A Complete Web Platform With Database Out of the Box

2008-08-05 Thread Michael Mabin
Actually this is not my web site or my product. But this is the kind of
tough love I'd like the creators to read.

On Tue, Aug 5, 2008 at 10:36 AM, Avinash Vora <[EMAIL PROTECTED]> wrote:

> On Aug 5, 2008, at 8:37 PM, Michael Mabin wrote:
>
> Brainwave is a complete Web Development Platform with a DDL-free database.
>>  Its application server is built on CherryPy. It comes already bundled with
>> Cheetah and Mako templating engines.  And its database is its true gem.
>>
>
> You aren't differentiating too far from TurboGears at this point.
>
> The database is built on a "neural" model.  Each significant piece of data
>> is a meme that can be linked to other memes allowing for creation of complex
>> records that can be easily related to other records.
>>
>
> I don't quite follow this, but...
>
> It's free for single-server users and licenses can be purchased for the
>> development and deployment of fuly scalable enterprise apps on multiple
>> servers.
>>
>
> Uh oh.
>
> Noone can really be told what Brainwave is.  You have to download and try
>> the SDK for yourself at http://www.brainwavelive.com..
>>
>
> Actually, I would like to be told.  I'm pretty sure that with a decent
> explanation, I could follow.  Your self-described "gem" is--by you--so
> vaguely explained that this whole operation doesn't inspire any confidence.
>
> More problems: large form to fill out; huge license agreement; very little
> documentation outside of PDF; online demo links to a local IP address;
> NOTHING I can find on the website actually runs on Brainwave etc. etc.
>
> Maybe in a few years I'd give this a try, but for now, I'd focus on
> releasing something that you are willing to back a bit more.  Spend all your
> time making your website look good with content that is available online
> easily.  Don't make it a chore for me to get your product.  If you don't
> trust your own product enough to run your own website/blog on it, hide the
> PHP file extension, and don't put a banner on your blog proclaiming a
> competitor's product.
>
> Try not to take this too harshly--I hope it is constructive criticism.
>
> --
> Avi
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Brainwave: A Complete Web Platform With Database Out of the Box

2008-08-05 Thread Michael Mabin
What do you all think of this?



Brainwave is a complete Web Development Platform with a DDL-free database.
Its application server is built on CherryPy. It comes already bundled with
Cheetah and Mako templating engines.  And its database is its true gem.

The database is built on a "neural" model.  Each significant piece of data
is a meme that can be linked to other memes allowing for creation of complex
records that can be easily related to other records.

It's a pure Python solution.

It's free for single-server users and licenses can be purchased for the
development and deployment of fuly scalable enterprise apps on multiple
servers.
Noone can really be told what Brainwave is.  You have to download and try
the SDK for yourself at http://www.brainwavelive.com..

Free your mind and your data.

-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Protecting instance variables

2008-07-28 Thread Michael Mabin
What about __setattr__()?

On Mon, Jul 28, 2008 at 5:23 AM, Nikolaus Rath <[EMAIL PROTECTED]> wrote:

> Hi,
>
> Sorry for replying so late. Your MUA apparently messes up the
> References:, so I saw you reply only now and by coincidence.
>
> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> > Nikolaus Rath schrieb:
> >> Hello,
> >>
> >> I am really surprised that I am asking this question on the mailing
> >> list, but I really couldn't find it on python.org/doc.
> >>
> >> Why is there no proper way to protect an instance variable from access
> >> in derived classes?
> >>
> >> I can perfectly understand the philosophy behind not protecting them
> >> from access in external code ("protection by convention"), but isn't
> >> it a major design flaw that when designing a derived class I first
> >> have to study the base classes source code? Otherwise I may always
> >> accidentally overwrite an instance variable used by the base class...
> >
> > Here we go again...
> >
> >
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/188467d724b48b32/
> >
> > To directly answer your question: that's what the __ (double
> > underscore) name mangling is for.
>
>
> I understand that it is desirable not to completely hide instance
> variables. But it seems silly to me that I should generally prefix
> almost all my instance variables with two underscores.
>
> I am not so much concerned about data hiding, but about not
> accidentally overwriting a variable of the class I'm inheriting from.
> And, unless I misunderstood something, this is only possible if I'm
> prefixing them with __.
>
> How is this problem solved in practice? I probably don't have a
> representative sample, but in the libraries that I have been using so
> far, there were a lot of undocumented (in the sense of: not being part
> of the public API) instance variables not prefixed with __. I have
> therefore started to first grep the source of all base classes
> whenever I introduce a new variable in my derived class. Is that
> really the way it's supposed to be? What if one of the base classes
> introduces a new variable at a later point?
>
>
> Best,
>
>   -Nikolaus
>
> --
>  »It is not worth an intelligent man's time to be in the majority.
>  By definition, there are already enough people to do that.«
> -J.H. Hardy
>
>  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: question

2008-07-20 Thread Michael Mabin
I think the question was: why does anyone still use perl when Python is
clearly the better language?

On Sun, Jul 20, 2008 at 2:17 PM, Paddy <[EMAIL PROTECTED]> wrote:

> On Jul 20, 6:39 pm, <[EMAIL PROTECTED]> wrote:
> > Nobody any sensible answers. Too complicated I suppose!
>
> The sensible question was?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Getting a path from a file object

2008-07-04 Thread Michael Mabin
f.name will return the path.  But if you want to guarantee getting the
absolute pathname use os.path.abspath

>>> import os
>>> os.path.abspath(f.name)
'/some/path/file.ext'


On Fri, Jul 4, 2008 at 1:37 PM, Andrew Fong <[EMAIL PROTECTED]> wrote:

> Newbie question:
>
> Let's say I open a new file for writing in a certain path. How do I
> get that path back?
>
> Example:
>
> >>> f = open('/some/path/file.ext')
> >>> some_function(f)
> '/some/path/file.ext'
>
> Does some_function(f) already exist? And if not, how would I define
> it?
>
> -- Andrew
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Classes for processing/parsing Wiki Markup text

2008-07-01 Thread Michael Mabin
Thanks!  This looks like just what I need! :)

On Tue, Jul 1, 2008 at 1:25 PM, Joshua Kugler <[EMAIL PROTECTED]> wrote:

> Michael Mabin wrote:
>
> > Does anyone know if there are any generally available classes for parsing
> > various wiki markup formats?
>
> Several here:
>
> http://pypi.python.org/pypi?%3Aaction=search&term=wiki&submit=search
>
> I'm sure you could find a good one, and add your own markup if needed.
>
> j
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Classes for processing/parsing Wiki Markup text

2008-07-01 Thread Michael Mabin
Does anyone know if there are any generally available classes for parsing
various wiki markup formats?

-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Mako vs. Cheetah?

2008-06-26 Thread Michael Mabin
Cheetah also allows you to embed Python code in the HTML.

On Thu, Jun 26, 2008 at 11:10 AM, John Salerno <[EMAIL PROTECTED]>
wrote:

> "John Salerno" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >I always have the desire to learn one thing well instead of split my
> >attention between several options, so I'm trying to decide which of these
> >two to start learning. Are there any particular things I should look at
> >when deciding between them, in terms of features, for example? Do they do
> >all the same things?
>
> Is it correct to say that Mako allows you to embed Python code within HTML,
> whereas Cheetah requires a certain amount of "tweaking" of Python code so
> that it isn't really code you could just run independently in the
> interpreter?
>
> I'm getting that impression from what I see so far.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Passing arguments to subclasses

2008-06-24 Thread Michael Mabin
But if you couldn't find readily available confirmation of what you presumed
to be true, weren't the responses showing how you might come that answer
using the interpreter helpful, rather than harsh?
The Python interpreter is the shizzit.

On Mon, Jun 23, 2008 at 12:17 PM, John Dann <[EMAIL PROTECTED]> wrote:

> Thanks for the responses - they're much appreciated. And I understand
> the slight impatience with questions that could possibly be answered
> without recourse to a forum - I'm usually in the opposite position of
> fielding many newbie questions in a forum in a completely different
> field!
>
> But don't be too harsh on this category of questions for a couple of
> reasons. First, newbies don't necessarily yet have the same easy
> familiarity with the Python interpreter that's implied. - personally
> I'd be a little concerned as to whether any significant block of
> test/example code that I'd entered into the interpreter was actually
> addressing the exact question that I had in mind.
>
> And second, the answer might have been of the 'yes, but' kind. In
> other words, it might perhaps have been true in a certain sort of
> simple example, but one that failed to provide the complete picture.
> So sometimes it's reassuring to be able to get an authoritative
> answer.
>
> Thanks again for taking the time to answer.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Getting column names from a cursor using ODBC module?

2008-06-22 Thread Michael Mabin
The pyodb module doesn't implement this behavior.  You would have to create
a dictionary of column positions and column names in advance.

On Sat, Jun 21, 2008 at 3:52 PM, Chris <[EMAIL PROTECTED]> wrote:

> On Jun 21, 3:58 pm, [EMAIL PROTECTED] wrote:
> > Is there any way to retrieve column names from a cursor using the ODBC
> > module? Or must I, in advance, create a dictionary of column position
> > and column names for a particular table before I can access column
> > values by column names? I'd prefer sticking with the ODBC module for
> > now because it comes standard in Python.
> >
> > I'm using Python 2.4 at the moment.
> >
> > Thanks.
>
> You should be able to do
>
> column_names = [d[0] for d in cursor.description]
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: python/ruby question..

2008-06-19 Thread Michael Mabin
The commands module might help you out as well.
import commands as c
output = c.getoutput('testruby.rb')



On Thu, Jun 19, 2008 at 5:14 AM, Matt Nordhoff <[EMAIL PROTECTED]>
wrote:

> Mensanator wrote:
> > On Jun 18, 10:33�pm, "bruce" <[EMAIL PROTECTED]> wrote:
> >> hi...
> >>
> >> can someone point me to where/how i would go about calling a ruby app
> from a
> >> python app, and having the python app being able to get a returned value
> >> from the ruby script.
> >>
> >> something like
> >>
> >> test.py
> >> �a = os.exec(testruby.rb)
> >>
> >> testruby.py
> >> �foo = 9
> >> �return foo
> >>
> >> i know this doesn't work... but i've been searching for hours on this
> with
> >> no luck (and yeah, i'm relatively new to both ruby/python!!)
> >>
> >> thanks
> >
> > Well, I don't know anything about Ruby, but here's
> > how I do it for C programs (compiled to .exe that
> > write to stdout).
> >
> >
> > import os
> > factor_program = 'factor! -d200 ' # factor!.exe from MIRACL
> >
> > n =
> >
> '50818429800343305993022114330311033271249313957919046352679206262204589342623811236647989889145173098650749'
> >
> > # call external program and capture stdout
> > the_output = os.popen(factor_program+n).readlines()
> >
> > print 'n: %s' % n
> > for i in the_output:
> > print i,
>
> 
>
> You're supposed to use the subprocess module.
>
> In this case, something like:
>
> import subprocess
> factor_program = ['factor!', '-d200']
>
> ...
>
> p = subprocess.Popen(factor_program + [n], stdout=subprocess.PIPE)
> p.wait() # wait for it to finish; not sure how necessary it is
> the_output = p.stdout.readlines()
>
> See subprocess's documentation [1], which includes guides on replacing
> os.popen* and other functions with it.
>
> [1] 
> --
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: does paramiko support python2.5?

2008-06-13 Thread Michael Mabin
paramiko is an ssh module

On Fri, Jun 13, 2008 at 2:49 PM, Terry Reedy <[EMAIL PROTECTED]> wrote:

>
> "Praveena B" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>  when i used paramiko in python2.5 i got the error below.
> File "C:\praveena\python scripts\sshlib\ssh.py", line 5, in 
> import paramiko
> File "C:\Python25\Lib\site-packages\paramiko\__init__.py", line 69, in
> 
> from transport import randpool, SecurityOptions, Transport
> File "C:\Python25\Lib\site-packages\paramiko\transport.py", line 32, in
> 
> from paramiko import util
> File "C:\Python25\lib\site-packages\paramiko\util.py", line 31, in 
> from paramiko.common import *
> File "C:\Python25\lib\site-packages\paramiko\common.py", line 98, in
> 
> from osrandom import OSRandomPool
> File "C:\Python25\Lib\site-packages\paramiko\osrandom.py", line 129, in
> 
> raise ImportError("Cannot find OS entropy source")
> ImportError: Cannot find OS entropy source
>
> 
> I have no idea what paramiko is, but the error message suggests an OS
> rather than Python problem.  Can you run paramiko with an earlier version
> of Python on the same machine as it is currently set up?
>
> If so, check (and possibly post) the OSRandomPool class/function in
> osrandom.py for anything that might be sensitive to 2.5 changes (there were
> not very many, and just about none should have broken code).
>
> tjr
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Building 64-bit Python on AIX

2008-06-10 Thread Michael Mabin
Oops.  Forgot to mention this is AIX 5.3 and I'm trying to install Python
2.5.2. Using xlc compiler.

On Tue, Jun 10, 2008 at 10:34 AM, Michael Mabin <[EMAIL PROTECTED]> wrote:

> Hi all.  I am trying to rebuild Python on our AIX system in 64 bit so I can
> use our installed 64-bit UnixODBC library.  Has anyone successfully done
> this and can they share the configure options they used?
> Thanks.
>
> Mike
> --
>
>


-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Building 64-bit Python on AIX

2008-06-10 Thread Michael Mabin
Hi all.  I am trying to rebuild Python on our AIX system in 64 bit so I can
use our installed 64-bit UnixODBC library.  Has anyone successfully done
this and can they share the configure options they used?
Thanks.

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

Re: Python and Harry Potter?

2008-06-05 Thread Michael Mabin
Harry Potter is a Parselmouth.  He can speak to snakes.
Of course, Amazon would get this right!

Sheesh!

On Thu, Jun 5, 2008 at 6:10 AM, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>
wrote:

> On Thu, 05 Jun 2008 11:58:14 +0200, Helmut Jarausch wrote:
>
> > Today I've got an email from Amazon recommending me
> > Harry Potter and the Deathly Hallows
> >
> > and they told me why they recommended this book,
> > because I've bought
> > Core PYTHON Programming
> >
> > Didn't know, Harry Potter is a Python fan.
>
> I would've expected something with more magic, like Perl.  :-)
>
> Ciao,
> Marc 'BlackJack' Rintsch
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Squeak-like environment for Python?

2008-06-05 Thread Michael Mabin
Check out the Brainwave platform, which uses a new "neural" database model.
 It allows you to create databases to store any kind of Python object as a
"neuron" and allows objects to be connected via link to create complex
structures that don't require conventional tables and columns.
It is a development platform that has a bundled webserver based on CherryPy,
with a built-in application generator and deployer.

http://www.brainwavelive.com

On Thu, Jun 5, 2008 at 6:08 AM, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:

> Diez B. Roggisch a écrit :
>
>  Jumping Arne wrote:
>>
>>  I've been playing with Squeak a bit and I really like the persistent
>>> storage model, I also liked HyperCard and Frontier (well, the persistent
>>> storage model at least).
>>>
>>> I wonder if there is some similar environment but based on python, I
>>> would
>>> like to use this environment not as a development environment but as a
>>> platform for storing data etc - much like HyperCard.
>>>
>>> I found a few postings about such an environment:
>>>
>>> 
>>>
>>> but it looks like nothing happened.
>>>
>>> pythoncard doesn't seem to have the persistent storage model
>>>
>>
>> What about ZODB? You can use that to store (more or less) arbitrary
>> objects.
>> Maybe that can be a foundation, if you throw in
>> http://nodebox.net/code/index.php/Home
>>
>> it might be similar to squeak (I only dimly remember what squeak as a
>> whole
>> is though - smalltalk & easy multimedia I remember)
>>
>
> Mainly, Squeak is a (relatively) recent, free implementation of Smalltalk.
>
> 
> The "persistent storage model" - the 'image' storing the whole system
> (code, libs, data, whatever) - is part of the Smalltalk system since it's
> first conception IIRC  (even if some Smalltalk implementations - like GNU
> Smalltalk - are more traditionnaly file-based and have no automatic
> persistence).
> 
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Constructor re-initialization issue

2008-06-03 Thread Michael Mabin
Changing the default for data to None and creating a new dict inside your
function might handle this.  But I don't know what it is you want.  It never
even occurred to me that this behavior might be desired in the first place.

class Param(object):
   def __init__(self,data=None,condition=False):
   if data is None:
  data = {}
   if condition:
  data['class'] = 'Advanced'
   print data

Param(condition=True)
Param(condition=False)

I always thought you didn't want to have empty sequences as default values.

On Tue, Jun 3, 2008 at 5:11 PM, <[EMAIL PROTECTED]> wrote:

> Hello all,
>
> I have come across this issue in Python and I cannot quite understand
> what is going on.
>
> class Param():
>def __init__(self, data={}, condition=False):
>if condition:
>data['class']="Advanced"
>print data
>
> In the previous example, I expect the variable data to be re-
> initialized every time I construct an object type Param. However, when
> I do the following:
>
> Param(condition=True)
> Param(condition=False)
>
> The second call still prints {'class': 'Advanced'}
>
> Shouldn't data be initialized to {} since it is the default in
> __init__? Why would the state of data be preserved between two
> independent instantiations?
>
> Any help would be greatly appreciated.
>
> M.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Hungarian Notation

2008-05-30 Thread Michael Mabin
Variable names should have prefixes or suffixes (as I prefer) that represent
the "kind" of data they represent rather than the data type itself.
For example account_bal_am, order_qt, line_ct, first_nm.  Where am is
amount, qt is quantity and ct is count.  Coding standards could impose rules
on datatypes that should be used for these kinds:  am (amount) is a currency
field and should be represented by decimal values. qt (quantity) is a long,
nm a string and so on.

On Fri, May 30, 2008 at 3:31 AM, Lie <[EMAIL PROTECTED]> wrote:

> On May 27, 12:28 pm, "inhahe" <[EMAIL PROTECTED]> wrote:
> > Does anybody know of a list for canonical prefixes to use for hungarian
> > notation in Python?  Not that I plan to name all my variables with
> hungarian
> > notation, but just for when it's appropriate.
>
> If it was me, I'd use an empty-defined class:
>
> class Fake(object):
>pass
>
> data = 'headinfo=trash;headtrash=info'
> Header = Fake()
> Header.Str = data
> Header.Dict = parse(data)
>
> it saves name if it's important (alternatively, you may also use a
> dict or a tuple/list to store the string/dict pair).
> But using Fake class just like that is difficult to work with if I
> need to "write" to the data (not read only) and synchronizes the data,
> in that case, it's easy to extend the Fake Class:
>
> class Fake(object):
>def __init__(self, data):
>self.data = parse(data)
>
>def toStr(self):
>return str(self.data)
>def fromStr(self, s):
>self.data = parse(s)
>Str = property(toStr, fromStr)
>
>def toDict(self):
>return self.data
>def fromDict(self, s):
>self.data = s
>Dict = property(toDict, fromDict)
>
> you might go as far as overriding __str__ and __repr__ as appropriate.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: php vs python

2008-05-22 Thread Michael Mabin
I used python to generate php code. But that was before I knew what vast
troves of python web frameworks there were. :)

On Thu, May 22, 2008 at 11:40 PM, inhahe <[EMAIL PROTECTED]> wrote:

>
> > PHP can do that.  There are also a number of templating engines
> > available.  The nice thing about PHP is you have a choice.
>
> i just meant that php is sort of invented to combine html and code, so if
> you use python instead you should use a templating engine.  but i suppose
> it's useful for php too.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: MVC

2008-05-22 Thread Michael Mabin
In fact, the Pylons web framework is geared toward the MVC approach.
http://pylonshq.com/

On Thu, May 22, 2008 at 7:48 PM, George Maggessy <[EMAIL PROTECTED]>
wrote:

> Hi Gurus,
>
> I'm a Java developer and I'm trying to shift my mindset to start
> programming python. So, my first exercise is to build a website.
> However I'm always falling back into MVC pattern. I know it's a
> standard, but the implementation language affects the use of design
> patter. So, here goes my question. Is that OK if I follow this? Should
> I create DAOs, View Objects, Controllers and etc? Is there any sort of
> best practice / standard to Python?
>
> Cheers,
> George
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: python equivalent to perl's inplace edit mechanism

2008-05-08 Thread Michael Mabin
I miswrote my question.  But I still completely understand.  What I really
wanted to know was whether there was something equivalent to how perl can
perform inplace edits of a file with something like the magic $^I variable.


I see from Gabriel that you can use the fileinput module to  achieve this.
Very cool.

And yeah, I think ruby is very perl-like, in that like perl, which looks
like someone duct-taped shell, sed, awk and c into a scripting language,
ruby duct-taped perl, Smalltalk and Python together.

On Thu, May 8, 2008 at 7:49 AM, David <[EMAIL PROTECTED]> wrote:

> On Thu, May 8, 2008 at 2:11 PM, Michael Mabin <[EMAIL PROTECTED]> wrote:
> > Does python have an equivalent to Perl's inplace-edit variable $^I?
> >
>
> I misread your question.
>
> No, Python eschews magic characters and symbols. They make code ugly
> and harder to read and maintain.
>
> The first 3 lines of the Zen of Python:
>
> Beautiful is better than ugly.
> Explicit is better than implicit.
> Simple is better than complex.
>
> You might find a variable like that in Ruby, which has strong Perl
> influences.
>
> David.
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

python equivalent to perl's inplace edit mechanism

2008-05-08 Thread Michael Mabin
Does python have an equivalent to Perl's inplace-edit variable $^I?
For example, the following perl code below changes mike to dave in a file
that is passed as an argument.

#!/usr/bin/env perl
#chgit script
$^I = '';
while(<>) {
  s/mike/dave/g;
  print;
}

The script would be used as below:
chgit somefile

Afterward, all instances of mike are changed to dave.

Thanks.

Mike

-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-08 Thread Michael Mabin
For me, the difference is #!python doesn't work for me.  I get a bad
interpreter error.

On Thu, May 8, 2008 at 6:31 AM, Brian Vanderburg II <
[EMAIL PROTECTED]> wrote:

> This is sort of related, but I'm wondering what is different between
> "#!/usr/bin/env python" and "#!python".  Wouldn't the second do the same
> thing, since an absolute path is not specified, find 'python' from the PATH
> environment,  I don't really know.
>
> Brian Vanderburg II
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Why is None <= 0

2008-05-03 Thread Michael Mabin
New style classes are classes inherited from class object.  Therefore:
class A:
pass

is oldstyle, while

class B(object):
pass

is newstyle.

On Tue, Apr 29, 2008 at 8:29 AM, blaine <[EMAIL PROTECTED]> wrote:

> On Apr 29, 5:32 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> > =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= <[EMAIL PROTECTED]> wrote:
> > > (FWIW, in 2.x, x>=4?, it's None < numbers < anything else;
> > > numbers are ordered by value, everything else is ordered
> > > by type name, then by address, unless comparison functions
> > > are implemented).
> >
> > Quite apart from Jon pointing out that this isn't true for all cases
> when
> > copmparing against None, the other half also isn't true:
> >
> > >>> class C: pass
> > >>> C() < 5
> >
> > True
> >
> > That happens at least in Python 2.5.2 on win32. Yet another reason to
> avoid
> > old-style classes.
>
> Sorry - but what are new style classes?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-03 Thread Michael Mabin
I work on an AIX system where /usr/bin and /usr/local/bin apps can only be
installed by root. Our system doesn't have python or many other tools we
like to use installed so we have to install python in an alternate directory
location. We have a system installation of Perl installed, but it's a
release or two older than what we need, so we have done the same for perl.
Thus, #!/usr/bin/env whatever allows our developers to experiment without
always requiring the services of the admins, who are spread too thinly
amongst all the other *Nixes they have to support, and who are also
separated by many layers of red tape from us.

On Sat, May 3, 2008 at 10:24 AM, Lou Pecora <[EMAIL PROTECTED]>
wrote:

> In article <[EMAIL PROTECTED]>,
>  Grant Edwards <[EMAIL PROTECTED]> wrote:
>
> > On 2008-05-02, D'Arcy J.M. Cain <[EMAIL PROTECTED]> wrote:
> > > On Sat, 03 May 2008 00:44:00 +1000
> > > Ben Finney <[EMAIL PROTECTED]<[EMAIL PROTECTED]>>
> wrote:
> > >> "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes:
> > >> > As someone else pointed out, not all the world is Linux.
> > >>
> > >> It's a good thing I've never implied such to be the case.
> > >
> > > You haven't *said* it but you have definitely *implied* it.
> > > Installing Python in /usr/bin is not common.
> >
> > It is common.  That's where it's installed by almost all Linux
> > distributions.
>
> MacOS X system python (or links to them) is in the same place.
>
> --
> -- Lou Pecora
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is vs Equality Operator

2008-05-01 Thread Michael Mabin
'is' tests for identity (variable references the same memory location) while
'==' tests for equality.  Though it's probably best to use 'is' with more
complex classes and not the simpler built-in types like integers.
See how 'is' works for lists below:

>>> l1 = [1,2,3,4]
>>> l3 = [1,2,3,4]
>>> l1 == l3
True
>>> l1 is l3
False
>>> l2 = l1
>>> l1 is l2
True

l1 and l3 are equal because they contain the same elements. But they are not
identical because they reference different list objects in memory.  On the
other hand, l1 and l2 are identical, so using 'is' in this case tests True.

'is' will be true of the objects tested have the same address in memory.

On Thu, May 1, 2008 at 4:10 AM, Gary Herron <[EMAIL PROTECTED]>
wrote:

> Good Z wrote:
>
> > Hello,
> > I am having problem in using is. Here is what i am doing.
> >
>
> Short answer:  Use == for equality.Don't use "is".  Ever!  (Especially
> if you are a newbie.)
>
> Longer answer:  In a dozen years of programming Python, the only time I
> use "is" is when testing for something like  if x is None
> but, even then
>  if x == None
> works just as well, and in any case, there is usually a better way.  (See
> below.)
>
> Don't use "is" until you can explain the following
> >>> 11 is 10+1
> True
> >>> 11 is 10+1
> False
>
>
>
> > x=''
> > if x is None or x is '':
> >return 1
> >
>
> Both None and an empty string (and empty lists, empty dictionaries, empty
> sets, and numeric values of 0 and 0.0) all evaluate a False in an if
> statement, so the above if statement can be written as
>
>  if not x:
> return 1
>
> If you have to test for None, just do
>  if not x:
>
> If you have to differentiate between a value of None and something that
> evaluates to False (e.g., and empty list) then do
>  if x is None:
>   # handle None explicitly
>  elif not x:
>   # handle empty list
>
>
> > The above statement does not return value 1.
> >
> > If i changed the above check to
> > if x == None or x == '':
> >return 1
> > Now it works fine.
> >
> > Any idea. What is happening here. I am using python 2.4.4 on ubuntu.
> >
> > Mike
> >
> > 
> > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try
> > it now. <
> > http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20>
> >
> > 
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: Java or C++?

2008-04-15 Thread Michael Mabin
I'm shocked. I've seen no mention of Smalltalk at all.  Which should be soo
oobvious!
;)

I would take an incremental approach.  Learn Java first, since it is still
OO, offers a rich set of libraries for just about every task but requires a
bit more work.  C++ requires that you do more work still (build more of your
own classes or find more third-party frameworks to do what you need to do),
work with the Standard Template Library, distinguish between references and
pointers, choose between implementing an OO mechanism (such as IO with
iostreams) or traditional (fprintf, printf,etc.).

C requires that you shift out of the OO paradigm completely and manage your
data and operations separately without the benefit of classes.  If you read
the Extending Python documentation, you will see how much more work C has to
do to make Python possible at all.

Michael
2008/4/15 Ivan Illarionov <[EMAIL PROTECTED]>:

> On 15 апр, 07:46, Brian Vanderburg II <[EMAIL PROTECTED]>
> wrote:
> [...]
> > C has the advantage that it does not to anything behind your back.  This
> > is very useful especially for any form of system development or where
> > you must know exactly what is going on.  It is still possible to do
> > 'object oriented' development in C, it just requires some more typing to
> > set up whatever is needed. Even things like COM for windows can be done
> > in C, it just requires manually building the 'vtable' so to speak.
> > Also, C seems to avoid the use of temporaries where as C++ can use them
> > in conversions and assignments automatically if needed.
>
> Great point. It's also possible to do Python object-oriented
> programming in C. 'PyMethodDefs' are the same 'vtables'. I've found
> that Python/C API is not that hard, the problem is a lack of good
> tutorials and false assumptions that ctypes or SWIG are somehow
> better. After `#include Python.h` C becomes very Python friendly.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: finding items that occur more than once in a list

2008-03-18 Thread Michael Mabin
How about using list comprehension?

l1 = ["apples","apples","bananas","oranges","oranges","peaches"]

s1 = set([x for x in l1 if l1.count(x) > 1])


On Tue, Mar 18, 2008 at 4:56 PM, sturlamolden <[EMAIL PROTECTED]> wrote:

> On 18 Mar, 22:25, sturlamolden <[EMAIL PROTECTED]> wrote:
>
> > def nonunique(lst):
> >slst = sorted(lst)
> >return list(set([s[0] for s in
> >filter(lambda t : t[0] != t[1], zip(slst[:-1],slst[1:]))]))
>
> Obviously that should be 'lambda t : t[0] == t[1]'. Instead of using
> the set function, there is more structure to exploit when the list is
> sorted:
>
>
> def nonunique(lst):
>   slst = sorted(lst)
>dups = [s[0] for s in
> filter(lambda t : t[0] == t[1], zip(slst[:-1],slst[1:]))]
>return [dups[0]] + [s[1] for s in
>filter(lambda t : t[0] != t[1], zip(dups[:-1],dups[1:]))]
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Need Help Starting Out

2008-03-18 Thread Michael Mabin
Pylons is a Ruby on Rails-like web framework that allows you build dynamic
web applications with a database backend.  Here is a link to the Pylons web
site:

http://pylonshq.com/



On Tue, Mar 18, 2008 at 11:10 AM, jmDesktop <[EMAIL PROTECTED]> wrote:

> Hi, I would like to start using Python, but am unsure where to begin.
> I know how to look up a tutorial and learn the language, but not what
> all technologies to use.  I saw references to plain Python, Django,
> and other things.
>
> I want to use it for web building with database access.  What do I use
> for that?  Does it matter what I use on the client side (mootools, or
> whatever)?
>
> My rational for using Python is because I am hoping it will allow me
> to better understand other python programs in other areas, not just
> web.  I have used other languages for web apps for several years.
> Truth is that I always wanted to learn Python and have heard it was a
> good thing to know.
>
> Thank you.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
-- 
http://mail.python.org/mailman/listinfo/python-list