Re: Workflow engine?

2008-11-08 Thread Eric Wertman
> To be exact, I used the words "engine/library", not "a whole framework".
> Thanks for the link, I've googled for articles and recipes myself and
> as I said, I more or less know what to do - I just thought it might be
> a good idea to ask whether perhaps the wheel has already been invented.
> Apparently I was wrong.

I think that was part of the problem.. you asked if the wheel had
already been invented, rather than tell us about the stones you have
to haul up a mountain, and whether a wheel is what you need.  It's
difficult to answer your original question.. someone could have just
as easily said that you should consider Sharepoint and not bother
writing any code.

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


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-20 Thread Eric Wertman
> Do you really think there are Linux or Mac systems with a C: drive?
>
> This whole question is based on the ludicrous assumption that general
> file system paths can be platform-independent. That's a bit like trying
> to write code that is programming language-independent.


That's sort of where I was going originally... just pick a way to
store the path elements and write some simple functions (yes, many of
them will just be os.path calls) to reconstruct them based on the
actual needs of the application.  If your root element is in
ascii.letters  then it's most likely windows machine, so adding a ':'
and using os.path.join would be appropriate in the function.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python certification

2008-10-20 Thread Eric Wertman
> I would hate to live in a world where you had to have three years of
> graduate professional training to write a for-loop for pay, or where
> scientists and mathematicians were prohibited from writing code (practicing
> software) without a license.  Or where someone who just wanted to practice
> Python had to first master assembly.
>
> I would be interested to hear if you know something about medical/legal
> exams, quite aside from there use as legal cudgels, that would contribute to
> (carefully) improving voluntary computer training and exams.

I think what I'm after is something not so extreme as this.  Obviously
there are numerous folks out there that don't have a boatload of
formal education and are quite competent, while the opposite is also
almost certainly true.  Maybe I'm just reacting negatively to the
constant advertisements I hear on the radio for '6 months to your
Microsoft certification' blah blah, and the general trend I see that
says you can ignore the need for 'expensive experts' if you just use
vendor X's solution.  The truth I perceive is that IT is an unusual
field where one good employee can accomplish more than any number of
mediocre ones ever will.  I'm not sure a lot of businesses grasp this,
they still think that if there's a problem with getting something
done, they just need more people, when in reality they would
accomplish more by removing the less competent ones than adding more
of any kind.

I'm not advocating some kind of licensing for programmers.  I just
really wish there was some reasonable gauge that could be used to
evaluate information professionals.  There are many people in the
field that are not only incompetent, but they are that way on purpose,
and they use the complexity of the field to deceive whoever they can.
They may or may not be 'certified' and they may or may not have
master's degrees.

I see your points.  Again, I think mostly this is just my frustration
in general.  My perception of the world lately is that the stupid and
apathetic have really begun to take over.  Maybe it was always like
that, or maybe I'm wrong.  Or... maybe it's just Monday :).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python certification

2008-10-20 Thread Eric Wertman
> Given the way that medical/legal licensing is used to stifle competition,
> prevent innovation, and keep people from earning a living delivering simple
> services that people need at prices they can afford, 'more like' would have
> to be done very carefully.

To draw an analogy... imagine, if you will, a system where
pharmaceutical companies are the leading source of doctor
certifications.  While I'm sure there are many valid arguments that
would show today's system is far from perfect, I'm thinking that would
be a worse horror by some order of magnitude.
--
http://mail.python.org/mailman/listinfo/python-list


Re: pymssql - execute loads all results into memory!

2008-10-20 Thread Eric Wertman
> I am trying to use pymssql, and have an issue where by the execute
> (not the fetch) is appearing to load all records into memory.
>
> if I execute
>
> con = pymssql.connect(...)
> cur = con.cursor()
> cur.execute(sql)
> rec  = cur.fetchone()
>
> if I put in a query which returns a lot of records into "sql" then the
> execute never returns, pythons memory usage slowly ballons till the
> machine cant give anymore. If I put a sql query returning only few
> rows, then it works fine.
>
> So I am not sure why an execute would feel the need to load all rows,
> but its seriously crippling. Does anyone know if this is a bug or
> something I can "turn off"

I ran into this myself.  After some digging I discovered that what you
are after is a server-side cursor that isn't implemented yet in
pymssql.  There is one in MySQLdb, but it's not the default behavior.
Regardless of your usage (fetchone vs fetchmany), the result set is
held client side.  AFAIK the only workaround is to keep your result
set small (enough).  If you use fetchmany and iterate over it
directly, it may keep your memory usage down,  I can't remember if
that worked.  I definitely tried making a generator with it, that did
not help.

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


Re: Python certification

2008-10-20 Thread Eric Wertman
On Mon, Oct 20, 2008 at 3:52 AM, olive <[EMAIL PROTECTED]> wrote:
>>
>> Certification prooves you're an idiot who needs to spend money to work
>> for another idiot who doesn't know enough about programming to know if
>> they hire competent programmers and need an idiot paper to make them
>> feel better and sleep better at night.
>>
> So true !
> +1 QOTW
> --
> http://mail.python.org/mailman/listinfo/python-list
>

While in the current state of affairs I agree completely,  I do think
that IT in general would be a much better field to work in if there
were some industry standard certifications that were required.  More
like the medical and legal fields than the vendor specific ones we see
today from Microsoft, IBM, etc.

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


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-19 Thread Eric Wertman
>> I (again) wonder what's the perfect way to store, OS-independent,
>> filepaths ?

I'm in agreement that perfect probably isn't applicable.  If I were
doing this myself, I might store the information in a tuple:

base = 'some root structure ('/' or 'C')
path = ['some','set','of','path','names']
filename = 'somefile.ext'

pathdata = (root,path,filename)

and write a couple of simple functions to reconstruct them based on the os.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help with Iteration

2008-10-19 Thread Eric Wertman
>> Aaron Brady  wrote:
>>
>>> while 1:
>>>calculate_stuff( )
>>>if stuff < 0.5:
>>>break
>>
>> The thought police will come and get you.

Based on Aaron's previous posting history,  I suspect this was a joke.
--
http://mail.python.org/mailman/listinfo/python-list


Re: If an OS was to be written in Python, how'w it look?

2008-10-06 Thread Eric Wertman
>> If an OS was to be written in Python and the hardware optimized for
>> it, what changes would be made to the hardware to accomodate Python
>> strenghs and weaknesses?


I'm no expert, but this would seem like a good example of something
that python wasn't good for.  I have always wondered, though, what a
Linux kernel module would look like that had a python (or java, or
whatever) interpreter running low-level, so the higher level
components on the operating system could be implemented in an
interpreted language.  Is there any benefit to something like that?
Or is that crap too?  Again, I'm no expert.

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


Re: Database GUI generation from schema

2008-10-02 Thread Eric Wertman
> Perhaps are you talking about dabo ?
> http://www.dabodev.com

Yes, that was it.  Thanks!  I was a little dissapointed to see that
the wikipedia entry for that software was deleted.  Is dabo not widely
used?

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


Database GUI generation from schema

2008-10-01 Thread Eric Wertman
Sorry if this is misplaced,  but I could have sworn I saw a link on
this list to a package that would auto-generate data entry type forms
from a database schema, similar to django's auto-admin interface.
Does anyone recall a package like that?  I did some searching, but
I've only found documentation describing such a system in the generic.

Thanks!

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


Re: python for *nix system admins

2008-09-27 Thread Eric Wertman
I've been growing a library of my own functions, that use the names of
unix commands.  They are just conveniences, of course, but I'd suggest
the same for sysadmins, it's handy.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Which version

2008-09-12 Thread Eric Wertman
> I'm a reasonably experienced in other languages and have just decided to
> get my feet wet with Python. But I'm using FC6 which has v2.4.4 installed,
> is this good enough to start out with or am I likely to encounter bugs that
> have been fixed in later versions.

I'm sure there will be other opinions.  I try to use the stock distro
version whenever possible, just because it makes administration easier
and you have some reasonable guess as to where your code will work if
you move it.  I use 2.4 regularly, and haven't come across many things
that the 2.5 series would make behave differently.  The subprocess
module is one though, and I recall a few datetime routines that were
2.5 only that I wished I could use.

If you aren't married to you linux distro, you might switch to
ubuntu... I believe they package the 2.5 series.  IMO it's not wrong
to compile a new one alongside the stock installation, but you could
run into potentially confusing issues later about which one exactly
you are using, installing modules for, etc.  Easy to avoid if you know
what you are doing, but a potential pitfall for a beginner.

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


Re: lacking follow-through

2008-09-08 Thread Eric Wertman
> Perhaps the wrong idea of what the group is.  I would have thought
> that
> if one had a sufficiently developed idea and wanted to have it /
> formally/
> rejected, rather than merely sniped at, then writting a PEP would be
> more
> apposite than posting to c.l.py.
>
> It's fine to post your not sufficiently developed ideas here merely
> to
> have them discussed.  But I don't know what makes you feel that you,
> or
> your ideas, are /entitled/ to any response at all, much less
> "follow-through."


To expand on this a little bit,  I've been subscribed to this group
for a couple of months, but there seems to be a bit more gray area
between what would go to a 'python-dev'  group and a 'python-user'
group.   Long debates about language features and abstract ideas would
appeal to the former, but not the latter.  Certainly I fall into the
user category..  I'm pretty happy with python, and generally just
adjust to it's design and features, rather than spend lots of time on
whether they are 'right' or could be 'better'.  /shrug
--
http://mail.python.org/mailman/listinfo/python-list


Re: lacking follow-through

2008-09-07 Thread Eric Wertman
+1 Bot
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need formatting suggestion for long strings

2008-09-05 Thread Eric Wertman
> I'm concerned about the formatting of the string in that I do not want the
> way I split the string up in source code to affect the way the string is
> displayed to the console. In other words, in source, if I break up a single
> string into multiple lines (using carriage returns), I would expect the
> string to still render as a single-line string.
>
> I'm also concerned about the source formatting, because I do not want the
> single-line string to run off the edge of my display. I want it to be in
> "Paragraph form" in the source code, but remain a single-line when printed.

I think you can also escape the line breaks:

>>> mystring = (
...   "This is a very long string that "
...   "spans multiple lines and does "
...   "not include line breaks or tabs "
...   "from the source file between "
...   "the strings partitions.")
>>> mystring2 = 'This is a very long string that spans multiple lines and does 
>>> not include line breaks or tabs from the source file between the strings 
>>> partitions.'
>>> mystring == mystring2
True
>>> mystring3 = 'This is a very long string that \
... spans multiple lines and does not include line breaks \
... or tabs from the source file between the strings \
... partitions.'
>>> mystring3 == mystring
True
--
http://mail.python.org/mailman/listinfo/python-list


Re: Coming from .NET and VB and C

2008-09-03 Thread Eric Wertman
>  Using Python.  I found "Dive Into Python" which I will be reading shortly

The title of the book is good advice all by itself.  Especially with
prior programming experience, you'll get started very quickly.  What
will take longer is the assimilation of some of python's neater and
more idiomatic features, like list comprehensions and generators.
Also, the fact that strings are immutable threw me off a little the
first day or two.

If you stick with it, I think you'll find those little things to be
your favorite parts though.  Certainly I use list comprehensions all
the time now, when I used to not use them at all.

In about 90% or more of cases, you can avoid doing things that you do
routinely in other languages..  mostly by iterating directly over
things you don't need counter variables or intermediate variable
names.  In fact, I find myself going back through old code and
removing variables pretty frequently.

I'm sure there's a lot more.  Personally I find it a lot of fun to code in.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Library/project for making an invitation-only website?

2008-09-02 Thread Eric Wertman
I think Drupy is best library for these task.

On Tue, Sep 2, 2008 at 12:27 PM, Dani <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I want to create a website where new users need to be invited by an existing 
> user in order to open an account.  Think of it the way Orkut became popular.
>
> I need a library, or code from some project, that sends the invitations, 
> keeps track of which user invited who, etc.
>
> I'm sure there's already some code out there that performs these tasks.  
> Drupy maybe?
>
> Could anybody recommend me some library/project for these tasks?
>
> Thank you in advance.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Large amount of files to parse/organize, tips on algorithm?

2008-09-02 Thread Eric Wertman
I think you really want use a relational database of some sort for this.

On Tue, Sep 2, 2008 at 2:02 PM, cnb <[EMAIL PROTECTED]> wrote:
> over 17000 files...
>
> netflixprize.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing to ms excel

2008-08-30 Thread Eric Wertman
Yes sorry, that's a really poorly formed sentence all the way
around... not a dig on xlrd, but a warning to the OP that they may not
find what they are looking for there.


> On Aug 31, 12:57 am, "Eric Wertman" <[EMAIL PROTECTED]> wrote:
>> If you have
>> to interface with an exsisting excel file, you can try 
>> http://pypi.python.org/pypi/xlrd, but it may not support writing xls
>> files, still.
>
> That remark appears to be an inverted cousin of the old joke question
> "Have you stopped beating your wife?" :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Process "Killed"

2008-08-30 Thread Eric Wertman
> I'm doing some simple file manipulation work and the process gets
> "Killed" everytime I run it. No traceback, no segfault... just the
> word "Killed" in the bash shell and the process ends. The first few
> batch runs would only succeed with one or two files being processed
> (out of 60) before the process was "Killed". Now it makes no
> successful progress at all. Just a little processing then "Killed".

This is the behavior you'll see when your os has run out of some
memory resource.  The kernel sends a 9 signal.  I'm pretty sure that
if you exceed a soft limit your program will abort with out of memory
error.

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


Re: Writing to ms excel

2008-08-30 Thread Eric Wertman
> I'm trying to find a way to write data to excel cells (or to be more
> specific to an .xls file), let's say for the sake of argument, data
> readen from a file (although it will be calculated in the process).
> I've been searching, but couldn't find any examples which allows that.

The answer will depend on your base os.. if you are on windows there
will be some options using the COM interfaces I bet.. but I don't know
anything about them.

If you are on a unix based os, your choices are limited.  If you can,
I would just write to a csv file and open it with Excel.  If you have
to interface with an exsisting excel file, you can try
http://pypi.python.org/pypi/xlrd , but it may not support writing xls
files, still.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Advice on the style to use in imports

2008-08-30 Thread Eric Wertman
> I read the PEP8 and the "importing Python Modules" article. However,
> I'm still a little confused on what should the general rules for
> importing modules.
>
> I'm showing what I used in my current project, and will accept your
> advices on how I should change them.

> import module
>
> and then use
>
> module.MyClass
>
> ( in case of a flat module)
>
> or
>
> from package.subpackage import module
>
> and then use
>
> module.MyClass
>
> (( for a package/subpackage structure ))

My opinion is that this is the preffered way, generally speaking.  Not
only does it avoid namespace issues as effbot pointed out, but it also
makes code easier to read later.  As examples, I tend to break those
rules frequently with these :

from pprint import pprint  # Because pprint.pprint is just redundant
from lxml import etree # Actually I guess this doesn't break the rule.
from datetime import datetime  # This might be a bad idea... I haven't
had problems yet though.  datetime.datetime gets on my nerves though.

just my .02

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


Re: Newbie needs help

2008-08-26 Thread Eric Wertman
Is the loginout file named loginout.py ?  It needs to be for the
import to work.  If the import works, you have to refer to those
variables within the right namespace,  ie :   loginout.url,
loginout.adminlogin,  etc.



On Tue, Aug 26, 2008 at 12:46 PM, frankrentef <[EMAIL PROTECTED]> wrote:
> Greetings all,
>
> I'm wanting to maintain what values in one file and call them in
> another.  The purpose being to keep a single location where url's,
> login's and passwords can be maintained, then called as needed from
> another file.
>
> In file #1 I have...
>
> import time
> import os
> import sys
>
> url = 'http://zoo/'
>
> adminlogin = 'Zebra'
> adminpassword = 'Zebra12$'
>
>
> -
>
> In file #2 I have the following...
>
> from cPAMIE import PAMIE
>
> #Imports - used to setup / control finding files
> import time
> import os
> import sys
> import loginout#name of the file retaining all url/login info
> from log import log
>
> #Create New Pamie Object
> ie=PAMIE()
> ie=Visible =1
> t=time
>
> adminlogin (ie,url)
> if ie.findText ('Site Status: Active'):
>log ('PASSED -- ADMIN Module - ADMIN Login & Admin Tab Navigation
> Successful')
> else:
>log ('WARNING -- ADMIN Module Login & Admin Tab Navigation
> FAILED')
> time.sleep(2)
>
>
>
> What am I doing incorrectly to not have file two log in when
> executed.  All files are in the same directory.   Keep it simple...
> I'm new at this.
>
> THNX
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: EOF

2008-08-22 Thread Eric Wertman
>> Im trying to download a file from a server. But how do I detect EOF ?

Shouldn't this work as well?

f1 = urllib2.urlopen('ftp://username:[EMAIL PROTECTED]/data.zip')
f2 = file("data.zip", "wb")

while f1: # When to stop ?
try :
f2.write(f1.read(1024))
except EOFError :
break

f1.close()
f2.close()

Not that it's really any better, if it works...  I'm wondering myself.

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


Storing Passwords

2008-08-19 Thread Eric Wertman
I've a number of scripts set up that require a username/password
combination to log in elsewhere.  It's gotten to the point where I
need to keep them in a more secure location, instead of just in the
scripts themselves.  I did a bit of searching, and haven't come up
with a great way to store passwords using 2-way encryption (I have to
send them as plain text).  Has anyone seen anything that fits this
need?  I whipped up something using base64 and pickle, to keep them in
a dictionary and at least prevent them from being plain text, but it
seems a bit insecure all the same.   Any ideas, much appreciated.

Thanks!

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


Re: Vmware api

2008-08-18 Thread Eric Wertman
On Mon, Aug 18, 2008 at 8:50 AM,  <[EMAIL PROTECTED]> wrote:
> do the ESX server provide any api's or an interactive session may ?

Yes, there's a seemingly very full-featured API, that's documented here:

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/index.html

They have samples for perl, java, and C#.  Now that I'm looking at it,
the wsdl files gave me namespace problems that I couldn't figure out.
I'm not exactly an expert in web services though.  I'd attach copies
of them, but I'm not sure if that's appropriate for the list.   It
seems a shame that they don't have examples and some other support for
using python. The CIM API they have does have some python examples,
but that's a different thing all together.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not get environment variable when using cron.

2008-08-17 Thread Eric Wertman
I'm not sure about the environment variable, but os.uname() should
give you what you need otherwise.
--
http://mail.python.org/mailman/listinfo/python-list


Re: like a "for loop" for a string

2008-08-17 Thread Eric Wertman
So what exactly does that do?  Returns a generator, instead of a list?


> I'm waiting for a str.xsplit still :-)
> If I write and submit a C implementation of xsplit how many chances do
> I have to see it included into Python? :-)
>
> Bye,
> bearophile
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Vmware api

2008-08-17 Thread Eric Wertman
I would also be interested in anything anyone can offer.  I spend some
time looking around, and took a fair stab at using the wsdl2py that
comes with The ZSI package.  Ultimately I couldn't get anything to
work, and reverted to using perl (yuk).

I'm interested mostly in interrogating the ESX servers to get
configuration and performance data, from external hosts.

Thanks!

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


Re: a question about mysqldb

2008-08-14 Thread Eric Wertman
Just to make sure I understand what you are showing me here:

> columns = ('tID', 'tNote')
> table_name = 'tmp'
> sql = 'select %s from %s where tID=:1' % ( ', '.join(columns), table_name)
> cursor.execute(sql, (1,))
>
> # sql is now 'select tID, tNote from tmp where tID=:1'
> # note the comma in argument tuple to execute (1,)


This means I could use this type of syntax?

sql = 'SELECT (date,time,name,size,count,stuff,flavor) FROM crazyTable
where monster=:1 and feet=:2 and price=:3'

cursor.execute(sql,('cookie','3',77.44))

?

I've not encountered that argument style before.
--
http://mail.python.org/mailman/listinfo/python-list


Re: a question about mysqldb

2008-08-14 Thread Eric Wertman
I also like to use escaped identifiers in cases like this:

sql = "select tID,tNote from %s where %s = %%s" % ("tmp","tID")
cursor.execute(sql,1)

should work fine.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fixed-length text file to database script

2008-08-14 Thread Eric Wertman
Sorry, didn't get to finish my script.  Have to figure out the deal
with gmail and the tab key someday.

myfile = '/somewhere/somefile.txt'
sizes = [16,4,8,8,8]

fd = open(myfile,r)

data = []
for line in fd.readlines() :
a = []
idx1 = 0
for l in sizes :
idx2 = idx1 + l
a.append(line[idx1:idx2])
idx1 += l
data.append(a)

fd.close()
print data

This isn't tested, and there are probably more elegant ways to do it,
but for quick and dirty I think it should work.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fixed-length text file to database script

2008-08-14 Thread Eric Wertman
I have a machine (PLC) that is dumping its test results into a fixed-
length text file.


While it has nothing to do with python,  I found that creating a MySQL
table with the proper fixed length char() fields and using 'load data
infile'  was the easiest way to deal with that sort of scenario.   The
python script is the secondary part, that handles the normalization
and proper typing of the first table to the second, permanent storage
area.  But in this case, the more advanced bits are the database and
SQL details, and python is just a very convenient way to build the SQL
statements and execute them.

I'm really not sure what the best way to deal with fixed length data
is in python.  I might define a list with the field lengths and use a
string slicing to get the items.. as a first thought:

myfile = '/somewhere/somefile.txt'
sizes = [16,4,8,8,8]

fd = open(myfile,r)

for line in fd.readlines() :

idx1 = 0
for l in sizes :
--
http://mail.python.org/mailman/listinfo/python-list


Re: Replace Several Items

2008-08-13 Thread Eric Wertman
I tend to use the re module like so :

import re
my_string = re.sub('[\-,./]','',my_string)

> I wish to replace several characters in my string to only one.
> Example, "-", "." and "/" to nothing ""
> I did like that:
> my_string = my_string.replace("-", "").replace(".", "").replace("/",
> "").replace(")", "").replace("(", "")
>
> But I think it's a ugly way.
>
> What's the better way to do it?
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.system question

2008-08-07 Thread Eric Wertman
In your case you could also use the os.environ dictionary:

import os
print os.environ['USER']
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.walk question

2008-07-26 Thread Eric Wertman
I do this, mabye a no-no?


import os

for root,dirs,files in os.walk(dir) : break
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-26 Thread Eric Wertman
> The number of nodes is very large: millions for sure, maybe tens
> of millions.  If considering (2), take note of my BOLD text above, which
> means I can't remove nodes as I iterate through them in the main loop.

Since your use of 'node' is pretty vague and I don't have a good sense
of what tests you are running and how long they would take,  I'm only
speculating, but a single loop might be the wrong way to go about
that.

If you are going to be frequently running tests and switching nodes
on/off, have you considered a separate set of processes to do both?
For example:


A set of some number of "tester" threads, that loop through and test,
recording thier results (somewhere).


You could then have a separate loop that runs every so often, checks
all the current test values, and runs through the nodes once,
switching them on or off.


I know it's not exactly what you asked, but depending on what your
nodes are exactly, you can avoid a lot of  other problems down the
road.  What if your single loop dies or gets hung on a test?  With a
separate approach, you'll have a lot more resilience too.. if there's
some problem with a single tester or node, it won't keep the rest of
the program from continuing to function.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3000 vs Perl 6

2008-06-24 Thread Eric Wertman
Flaming Thunder FTW!!!


thank you, I'm here all week.
--
http://mail.python.org/mailman/listinfo/python-list


Code execution in imported modules

2008-05-29 Thread Eric Wertman
So I'm working on some file parsing and building up a stack of regular
expressions that I need to use.  I was thinking of dropping them in an
external module.  I was wondering.. if I put them in a file called
regex.py like so :

import re

re1 = "..
re2 = "..

and then do:

rgx1 = re.compile(re1)
rgx2 = re.compile(re2)


and, in my script, parse.py py I do:

from regex import *

text = "bunch of stuff..."

m = rgx1.search(text)


Does the re get compiled when I import it, or every time I call it?
Since I'm calling it often, I'd like to compile it once.

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


Re: php vs python

2008-05-28 Thread Eric Wertman
Flaming Thunder is teh awesome! :P
--
http://mail.python.org/mailman/listinfo/python-list


Re: unittest: Calling tests in liner number order

2008-05-24 Thread Eric Wertman
>I can't relate to anyone that want to oppose a change that would give
>more freedom to a programmer.

While in general I agree with this.. I think in the case of python
part of it's base philosophy seems to be a tendency to encourage a
single way of doing things, and create a path of least resistance to
the "best" way.  "best" in this case being one or a handful of peoples
opinion.  I'm really ok with this, personally.  I think it's working
well.

So.. I'll post this because I'm sure at least one person hasn't seen it:

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python is slow

2008-05-24 Thread Eric Wertman
> if python is such a good programming/scripting language, why can't they
> build a faster interpreter/compiler engine? and beat php and zend.
> to the python team, rebuild your interpreter!

while this is just a boring troll.. it does bring me to a more
interesting point... it would be cool if the interpreter were
multi-threaded to make better use of smp systems.  While you can do
threading, if you really want to drive more than one cpu some forking
is in order.
--
http://mail.python.org/mailman/listinfo/python-list


Re: time module question - time zones

2008-05-21 Thread Eric Wertman
Sorry, my time zone is +4, not minus 4, which means that something
else is causing my source data to be in the future.  I still do need
to understand where the time routines determine the time zone offset,
so I can be sure I'm passing around the neutral value.

Thanks!


On Wed, May 21, 2008 at 12:23 PM, Eric Wertman <[EMAIL PROTECTED]> wrote:
> I tend to deal with dates a lot in different formats and places...
> typically I'll convert them to a time tuple with strptime(), and pass
> them around like that before I need to write them back out.
>
> One set of time/dates I'm getting are in UTC, but the string doesn't
> say that specifically.  So I do this..  I had expected the outcome to
> be offset properly (I'm EST5EDT).  But I'm obviously missing
> something:
>
> #!/usr/bin/env python
>
> import time
>
> utc_str = '2008-05-10 03:05:00 UTC'
>
> d = time.strptime(utc_str,'%Y-%m-%d %H:%M:%S %Z')
> t = time.mktime(d)
>
> print d
> print time.gmtime(t)
> print time.localtime(t)
>
> output :
>
> (2008, 5, 10, 3, 5, 0, 5, 131, 0)
> (2008, 5, 10, 8, 5, 0, 5, 131, 0)
> (2008, 5, 10, 4, 5, 0, 5, 131, 1)
>
>
> I believe that I should be getting (2008, 5, 9, 23, 5, 0, 5, 130, 1)
> out of one of those, since the original 3:05am time was UTC, and my TZ
> is currently -4.  Does that make sense?  I didn't even think I needed
> to do any business with time.localtime() and time.gmtime().  I
> expected  time.strftime() to return the locale appropriate time, but
> it didn't.
>
> TIA
>
> Eric
>
--
http://mail.python.org/mailman/listinfo/python-list


time module question - time zones

2008-05-21 Thread Eric Wertman
I tend to deal with dates a lot in different formats and places...
typically I'll convert them to a time tuple with strptime(), and pass
them around like that before I need to write them back out.

One set of time/dates I'm getting are in UTC, but the string doesn't
say that specifically.  So I do this..  I had expected the outcome to
be offset properly (I'm EST5EDT).  But I'm obviously missing
something:

#!/usr/bin/env python

import time

utc_str = '2008-05-10 03:05:00 UTC'

d = time.strptime(utc_str,'%Y-%m-%d %H:%M:%S %Z')
t = time.mktime(d)

print d
print time.gmtime(t)
print time.localtime(t)

output :

(2008, 5, 10, 3, 5, 0, 5, 131, 0)
(2008, 5, 10, 8, 5, 0, 5, 131, 0)
(2008, 5, 10, 4, 5, 0, 5, 131, 1)


I believe that I should be getting (2008, 5, 9, 23, 5, 0, 5, 130, 1)
out of one of those, since the original 3:05am time was UTC, and my TZ
is currently -4.  Does that make sense?  I didn't even think I needed
to do any business with time.localtime() and time.gmtime().  I
expected  time.strftime() to return the locale appropriate time, but
it didn't.

TIA

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


Re: How can I add spaces where ever I have capital letters?

2008-05-08 Thread Eric Wertman
Something like this.  I'm sure there are other ways to do it.

import re

def addspace(m) :
return ' ' + m.group(0)

strng = "ModeCommand"

newstr =  re.sub('[A-Z]',addspace,strng)

print newstr.strip()



On Thu, May 8, 2008 at 9:12 PM, John Schroeder <[EMAIL PROTECTED]> wrote:
> I have a string (which I got from the names of my classes) and I would like
> to print out my CamelCase classes as titles.
>
> I would like it to do this:
>
 my_class_name = "ModeCommand"
> ## Do some magic here
 my_class_name
> 'Mode Command'
>
> Anyone know any easy way to do this?  Thanks.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: ssh

2008-04-29 Thread Eric Wertman
I don't know about the best way.. I use this function, it works ok for
me.  I have an ssh key stashed already for my user ID, but you could
look at the ssh options and supply one on the command line if you
needed to.

from popen2 import Popen3

def ssh(host,command) :
''' Wraps ssh commands '''
ssh_exec = ['/usr/bin/ssh -qnx -F ssh_config', host, command]
cmd = ' '.join(ssh_exec)
output,errors,status = process(cmd)
return output,errors,status

def process(cmd) :
proc = Popen3(cmd,-1)
output = proc.fromchild.readlines()
errors = proc.childerr.readlines()
status = proc.poll()
return output,errors,status

I somtimes call ssh via a Thread object if I need to run a few at the same time.

In regards to your question,  fork() creates a complete copy of the
running process, and returns a 0 in the child (copy).  The parent gets
the PID of the child as a return code.  I don't think there's anything
wrong with what you are doing though.  I just found that the popen2
module was the easiest to deal with.  subprocess is nice, if you have
2.5, but I have to keep 2.3 ish most of the time.

The function above could theoretically block if the error pipe gets
full before I get to reading it.  I can't recall ever getting that
much back on stderr though.. so I'm taking the chance.

Eric


On Tue, Apr 29, 2008 at 9:29 PM, gert <[EMAIL PROTECTED]> wrote:
> Is this the best way to use ssh ?
>  How can i use ssh keys instead of passwords ?
>  I dont understand what happens when pid does not equal 0 , where does
>  the cmd get executed when pid is not 0 ?
>  How do you close the connection ?
>
>  # http://mail.python.org/pipermail/python-list/2002-July/155390.html
>  import os, time
>
>  def ssh(user, rhost, pw, cmd):
> pid, fd = os.forkpty()
> if pid == 0:
> os.execv("/bin/ssh", ["/bin/ssh", "-l", user, rhost] + cmd)
> else:
> time.sleep(0.2)
> os.read(fd, 1000)
> time.sleep(0.2)
> os.write(fd, pw + "\n")
> time.sleep(0.2)
> res = ''
> s = os.read(fd, 1)
> while s:
> res += s
> s = os.read(fd, 1)
> return res
>
>  print ssh('username', 'serverdomain.com', 'Password', ['ls -l'])
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: python script as executable

2008-04-28 Thread Eric Wertman
Try to ftp it in ascii mode, or find a dos2unix utility .. the file
has probably got \r\n (windows) line terminators in it.. causes
problems.   I guess it's also possible that /usr/bin/env doesn't
exist... not likely though.


On Tue, Apr 29, 2008 at 1:36 AM, sandipm <[EMAIL PROTECTED]> wrote:
> Hi,
>  I have written a python script to run from cron.
>  I  have put #!/usr/bin/env python at top. file executes correctly when
>  I run using python filename.py but
>  it fails to execute when try to run it like script/command.
>  it throws error:
>  :No such file or directory
>
>  I am editing file from eclipse for python from windows. and then
>  uploading on linus machine to run it.
>
>
>  any pointers?
>
>  sandip
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: File IO Issues, help :(

2008-04-28 Thread Eric Wertman
chuck in a jsfile.close().  The buffer isn't flushing with what you
are doing now.  jsfile.flush() might work... not sure.  Closing and
re-opening the file for sure will help though.

On Tue, Apr 29, 2008 at 1:26 AM, Kevin K <[EMAIL PROTECTED]> wrote:
> Hey everyone, I'm new to python and am trying to do a little project
>  with it. I'm running into problems writing over a file. I read from
>  the file and loop through for a specfic case in which I change
>  something. After I open and give it opening options (w, r, etc) one of
>  two things happens: either the file gets truncated and my writing
>  never takes place (or it seems it doesnt) or everything is appended to
>  the file and I have a double of what I started with, its never just
>  the updated file. Can someone shed some light on this for me?? Code
>  below:
>
>  jsfile = open("../timeline.js", "r+")
>  jscontent = jsfile.readlines()
>  jsfile.truncate()
>
>  for line in jscontent:
> if re.search('var d =', line):
> line = "var d = \""+mint['1'].ascdate()+"\"\n"
> print line
> jsfile.write(line)
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mapping and Filtering Help for Lists

2008-04-27 Thread Eric Wertman
You should check out the sets module:

http://docs.python.org/lib/module-sets.html



>
>  The problem asks to create a "compareandremove" so that you can use it on a
>  string, to remove the words from the string that are contained in un_words.
>
>  The remaining words then need to be compared to the alterns list and either
>  bring back the word if no matches or bring back the list.  To better explain
>  that i'll use an example.
>
>  If i do   compareandremove('notepad a pencil with desk')
>
>  I need it so it removes words contained in un_words, so "a" and "with";
>  then compares the remaining words to alterns to find a match.
>
>  This should bring back:
>
>  ['notepad', 'book', 'textbook', 'pencil', 'pen', 'pacer', 'desk']
--
http://mail.python.org/mailman/listinfo/python-list


Re: design choice: multi-threaded / asynchronous wxpython client?

2008-04-27 Thread Eric Wertman
HI, that does look like a lot of fun... You might consider breaking
that into 2 separate programs.  Write one that's threaded to keep a db
updated properly, and write a completely separate one to handle
displaying data from your db.  This would allow you to later change or
add a web interface without having to muck with the code that handles
data.
--
http://mail.python.org/mailman/listinfo/python-list


Re: learning with python question (HtTLaPP)

2008-04-26 Thread Eric Wertman
On Sat, Apr 26, 2008 at 7:50 PM,  <[EMAIL PROTECTED]> wrote:
> ok.. I finally made something that works.. Please let me know what you
>  think:
>
>  >>> def lines(letters):
> fin = open('words.txt')
> count = 0
> rescount = 0  # count the number of results
> results = ""  # there are words that contain the letters
> for line in fin:
> needs = 0
> x = str(line.strip())
> for ch in letters:
> if ch not in x:
> pass
> else:
> needs = needs + 1
> if needs == len(letters):
> rescount += 1
> results = results + '\n' + x
> count += 1
> print count, 'lines searched'
> print results, '\n'
> print 'result count is: ', rescount


That's pretty much it.. I'm guessing you are assuming your file has
one word per line?  I took a shot at it, without using the regex
module:

file = open('spyware')

my_string = 'uzi'
length = len(my_string)
words = []

for line in file :
chunks = line.strip().split()
for chunk in chunks :
x = 0
for char in my_string :
x = chunk.rfind(char,x)
if x > 0 :
words.append(chunk)

print '\n'.join(words)


or with the re module:

import re

text = open('words.txt').read()
pattern = '\S*u\S*z\S*i\S*'
stuff = re.findall(pattern,text)
count = len(stuff)

print "Found %d words :" % (count)
print "\n".join(stuff)
--
http://mail.python.org/mailman/listinfo/python-list


Re: learning with python question (HtTLaPP)

2008-04-26 Thread Eric Wertman
>  Is the way I wrote the function inherently wrong?  What I wrote

I would not say that.  I think a lot of people probably start off like
that with python.  You'll find in most cases that manually keeping
counters isn't necessary.  If you really want to learn python though,
I would suggest using built in functions and libraries as much as
possible, as that's where the real power comes from (IMO).

>  returns the sequence, however I'm trying to make the output match for
>  the letters in the string entered, not necessarily the string
>  sequence.
>  Only the sequence shows up 'uzi'.  I don't get words like 'unzip' or
>  'Zurich' .  I've only barely started on invocation and maybe writing
>  something like I'm describing is above what level I'm currently at.

This would be a more difficult approach..   Where you are doing the
comparison step:

if letters in line.strip():

It's trying to match the exact string "uzi", not any of the individual
letters.  You would need to look for each letter independently and
then make sure they were in the right order to match the other words.
--
http://mail.python.org/mailman/listinfo/python-list


Re: learning with python question (HtTLaPP)

2008-04-26 Thread Eric Wertman
>  Python Programmer" and have been trying to write a script that checks
>  'words.txt' for parameters (letters) given.  The problem that is the i
>  can only get results for the exact sequence of parameter 'letters'.

The "re" module comes to mind:

text = open('words.txt','r').read()
letters = 'sequence'
results = re.findall(letters,text)

result_count = len(results)

# one word per line:
for result in results :
print result

# one line
print ' '.join(results)

of course, you may need to invest a little time in regular expression
syntax to get exactly what you want, but I think you'll find that's
not wasted effort, as this is pretty standard and used in a lot of
other places.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Python code from inside php

2008-04-25 Thread Eric Wertman
>  > A simple yet dangerous and rather rubbish solution (possibly more of a
>  > hack than a real implementation) could be achieved by using a
>  > technique described above:
>  >
>  >   > echo exec('python foo.py');
>
>  This will spawn a Python interpreter, and not be particularly
>  efficient. You could just as well have used CGI.

I'm  in a bit of a similar situation.  I decided to use python to
solve problems where I could, in a more regimented fashion.  For
instance, I have a set of functions in a script, table.py.  After I
set up mod_python to handle requests to a single directory with
python, I can call this with:

http://localhost/py/table/nodes";); ?>

embedded in the page.  This is probably pretty hackish too, but at
least it doesn't spawn a new process, and I don't have to solve things
that aren't related to display with php.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ideas for parsing this text?

2008-04-24 Thread Eric Wertman
>  I would discourage you from using printables, since it also includes
>  '[', ']', and '"', which are significant to other elements of the
>  parser (but you could create your own variable initialized with
>  printables, and then use replace("[","") etc. to strip out the
>  offending characters).  I'm also a little concerned that you needed to
>  add \t and \n to the content word - was this really necessary?  None
>  of your examples showed such words, and I would rather have you let
>  pyparsing skip over the whitespace as is its natural behavior.
>
>  -- Paul

You are right... I have taken those out and it still works.  I was
adding everything I could think of at one point in trying to determine
what was breaking the parser.  Some of the data in there is input free
form... which means that any developer could have put just about
anything in there...  I find a lot of ^M stuff from day to day in
other places.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ideas for parsing this text?

2008-04-24 Thread Eric Wertman
Thanks to everyone for the help and feedback.  It's amazing to me that
I've been dealing with odd log files and other outputs for quite a
while, and never really stumbled onto a parser as a solution.


I got this far, with Paul's help, which manages my current set of files:

from pyparsing import nestedExpr,Word,alphanums,QuotedString
from pprint import pprint
import re
import glob

files = glob.glob('wsout/*')

for file in files :
text = open(file).read()
text = re.sub('"\[',' [',text)   # These 2 lines just drop double quotes
text = re.sub('\]"','] ',text)   # that aren't related to a string
text = re.sub('\[\]','None',text) # this drops the empty []
text = '[ ' + text + ' ]'  # Needs an outer layer

content = Word(alphanums+"-_./()*=#\\${}| :,;[EMAIL PROTECTED]&%%") |
QuotedString('"',multiline=True)
structure = nestedExpr("[", "]", content).parseString(text)

pprint(structure[0].asList())

I'm sure there are cooler ways to do some of that.  I spent most of my
time expanding the characters that constitute content.  I'm concerned
that over time I'll have things break as other characters show up.
Specifically a few of the nodes are of German locale.. so I could get
some odd international characters.

It looks like pyparser has a constant for printable characters.  I'm
not sure if I can just use that, without worrying about it?

At any rate, thumbs up on the parser!  Definitely going to add to my toolbox.


On Thu, Apr 24, 2008 at 8:19 AM, Mark Wooding <[EMAIL PROTECTED]> wrote:
>
> Eric Wertman <[EMAIL PROTECTED]> wrote:
>
> > I have a set of files with this kind of content (it's dumped from
> > WebSphere):
> >
> > [propertySet "[[resourceProperties "[[[description "This is a required
> > property. This is an actual database name, and its not the locally
> > catalogued database name. The Universal JDBC Driver does not rely on
>
> > information catalogued in the DB2 database directory."]
> > [name databaseName]
> > [required true]
> > [type java.lang.String]
> > [value DB2Foo]] ...>
>
> Looks to me like S-expressions with square brackets instead of the
> normal round ones.  I'll bet that the correct lexical analysis is
> approximately
>
>  [ open-list
>  propertySet   symbol
>  " open-string
>  [ open-list
>  [ open-list
>  resourcePropertiessymbol
>  " open-string (not close-string!)
>  ...
>
> so it also looks as if strings aren't properly escaped.
>
> This is definitely not a pretty syntax.  I'd suggest an initial
> tokenization pass for the lexical syntax
>
>  [ open-list
>  ] close-list
>  "[open-qlist
>  ]"close-qlist
>  "..." string
>  whitespaceignore
>  anything-else symbol
>
> Correct nesting should give you two kinds of lists -- which I've shown
> as `list' and `qlist' (for quoted-list), though given the nastiness of
> the dump you showed, there's no guarantee of correctness.
>
> Turn the input string (or file) into a list (generator?) of lexical
> objects above; then scan that recursively.  The lists (or qlists) seem
> to have two basic forms:
>
>  * properties, that is a list of the form [SYMBOL VALUE ...] which can
>be thought of as a declaration that some property, named by the
>SYMBOL, has a particular VALUE (or maybe VALUEs); and
>
>  * property lists, which are just lists of properties.
>
> Property lists can be usefully turned into Python dictionaries, indexed
> by their SYMBOLs, assuming that they don't try to declare the same
> property twice.
>
> There are, alas, other kinds of lists too -- one of the property lists
> contains a property `[value []]' which simply contains an empty list.
>
> The right first-cut rule for disambiguation is probably that a property
> list is a non-empty list, all of whose items look like properties, and a
> property is an entry in a property list, and (initially at least)
> restrict properties to the simple form [SYMBOL VALUE] rather than
> allowing multiple values.
>
> Does any of this help?
>
> (In fact, this syntax looks so much like a demented kind of S-expression
> that I'd probably try to parse it, initially at least, by using a Common
> Lisp system's reader and a custom readtable, but that may not be useful
> to you.)
>
> -- [mdw]
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Ideas for parsing this text?

2008-04-23 Thread Eric Wertman
I have a set of files with this kind of content (it's dumped from WebSphere):

[propertySet "[[resourceProperties "[[[description "This is a required
property. This is an actual database name, and its not the locally
catalogued database name. The Universal JDBC Driver does not rely on
information catalogued in the DB2 database directory."]
[name databaseName]
[required true]
[type java.lang.String]
[value DB2Foo]] [[description "The JDBC connectivity-type of a data
source. If you want to use a type 4 driver, set the value to 4. If you
want to use a type 2 driver, set the value to 2. Use of driverType 2
is not supported on WAS z/OS."]
[name driverType]
[required true]
[type java.lang.Integer]
[value 4]] [[description "The TCP/IP address or host name for the DRDA server."]
[name serverName]
[required false]
[type java.lang.String]
[value ServerFoo]] [[description "The TCP/IP port number where the
DRDA server resides."]
[name portNumber]
[required false]
[type java.lang.Integer]
[value 007]] [[description "The description of this datasource."]
[name description]
[required false]
[type java.lang.String]
[value []]] [[description "The DB2 trace level for logging to the
logWriter or trace file. Possible trace levels are: TRACE_NONE =
0,TRACE_CONNECTION_CALLS = 1,TRACE_STATEMENT_CALLS =
2,TRACE_RESULT_SET_CALLS = 4,TRACE_DRIVER_CONFIGURATION =
16,TRACE_CONNECTS = 32,TRACE_DRDA_FLOWS =
64,TRACE_RESULT_SET_META_DATA = 128,TRACE_PARAMETER_META_DATA =
256,TRACE_DIAGNOSTICS = 512,TRACE_SQLJ = 1024,TRACE_ALL = -1, ."]
[name traceLevel]
[required false]
[type java.lang.Integer]
[value []]] [[description "The trace file to store the trace output.
If you specify the trace file, the DB2 Jcc trace will be logged in
this trace file. If this property is not specified and the
WAS.database trace group is enabled, then both WebSphere trace and DB2
trace will be logged into the WebSphere trace file."]

I'm trying to figure out the best way to feed it all into
dictionaries, without having to know exactly what the contents of the
file are.  There are a number of things going on,  The nesting is
preserved in [] pairs, and in some cases in between double quotes.
There are also cases where double quotes are only there to preserve
spaces in a string though.  I managed to get what I needed in the
short term by just stripping the nesting all together, and flattening
out the key/value pairs, but I had to do some things that were
specific to the file contents to make it work.

Any ideas?  I was considering making a list of string combinations, like so:

junk = ['[[','"[',']]']

and just using re.sub to covert them into a single character that I
could start to do split() actions on.  There must be something else I
can do.. those brackets can't be a coincidence.  The output came from
a jython script.

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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Eric Wertman
On Apr 20, 1:29 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Sun, 20 Apr 2008 13:42:05 -0300, Matthew Woodcraft <[EMAIL PROTECTED]> 
> escribió:
>
> > An alternative scheme for describing the block structure could be
> > useful in other cases, though. For example, if you wanted to support
> > putting snippets of Python in configuration files, or spreadsheet
> > cells.
> > [...] If someone wrote a library for this and it proved popular, I expect it
> > would be considered for the standard library.
>
> There is "pindent.py" in the Tools/scripts directory:
>
> # ... When called as "pindent -r" it assumes its input is a
> # Python program with block-closing comments but with its indentation
> # messed up, and outputs a properly indented version.
>
> # A "block-closing comment" is a comment of the form '# end '
> # where  is the keyword that opened the block ...
>
> def foobar(a, b):
> if a == b:
> a = a+1
> elif a < b:
> b = b-1
> if b > a: a = a-1
> # end if
> else:
> print 'oops!'
> # end if
> # end def foobar
>
> --
> Gabriel Genellina

That's actually not a lot different than what you have to do now in a
web page.. It still seems overcomplicated though.  I'm not sure why
this is worse:

def foobar(a, b):
if a == b:
a = a+1;
elif a < b:
b = b-1;
if b > a:
a = a-1;
else:
print 'oops!';;

It's just ultimately whitespace insensitive.  Whether that's a good or
bad design is a debate that can be argued either way, but other
languages do it, and it's handy sometimes.  I agree that it makes it
much easier to produce illegible code.  Developing for a browser is
arguably annoying and hackish enough, without having to stick in
comments and such to enforce indenting.



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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Eric Wertman

> Look into any of the dozen Python-based template engines that are
> typically used for such tasks; they offer many more features than a
> way to indent blocks.
>
> George

I definitely will.. could you throw out some examples though?
Thanks!

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


Alternate indent proposal for python 3000

2008-04-20 Thread Eric Wertman
I was considering putting together a proposal for an alternate block
syntax for python, and I figured I'd post it here and see what the
general reactions are.  I did some searching, and while I found a lot
of tab vs space debates, I didn't see anything like what I'm thinking
of, so forgive me if this is a very dead horse.

Generally speaking, I like the current block scheme just fine.  I use
python on a daily basis for system administration and text parsing
tasks, and it works great for me.

>From time to time, though, I find myself needing a language for server-
side includes in web pages.  Because of the need to indent (and
terminate indents), python seems an awkward choice for this, and it's
easy for me to see why php and perl are more popular choices for this
kind of task.  Perhaps this is just my perception though.

I feel that including some optional means to block code would be a big
step in getting wider adoption of the language in web development and
in general.  I do understand though, that the current strict indenting
is part of the core of the language, so... thoughts?
-- 
http://mail.python.org/mailman/listinfo/python-list