parsing text from a file

2009-01-29 Thread Wes James
If I read a windows registry file with a line like this:

"{C15039B5-C47C-47BD-A698-A462F4148F52}"="v2.0|Action=Allow|Active=TRUE|Dir=In|Protocol=6|Profile=Public|App=C:\\Program
Files\\LANDesk\\LDClient\\tmcsvc.exe|Name=LANDesk Targeted
Multicast|Edge=FALSE|"

with this code:

f=open('fwrules.reg2.txt')

for s in f:
  if s.find('LANDesk') <0:
print s,


LANDesk is not found.

Also this does not work:

for s in f:
  try:
i=s.index('L')
print s[i:i+7]
 except:
   pass

all it prints is "LAND"

how do I find LANDesk in a string like this.  is the "\\" messing things up?

thx,

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


how to conditionally add a dict in-line

2009-02-23 Thread Wes James
I have this line:

navs.append(A(' '+str(i+1)+'
',_href=self.action(args=request.args,vars={'_page':i,'_query':request.vars._query
or ''})))

How do I do something like this:

vars={'_page':i, if request.vars._query not None then insert this
key/value pair ('_query':request.vars._query) else insert nothing }

thx,

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


Re: how to conditionally add a dict in-line

2009-02-23 Thread Wes James
On Mon, Feb 23, 2009 at 9:35 PM, Wes James  wrote:
> I have this line:
>
> navs.append(A(' '+str(i+1)+'
> ',_href=self.action(args=request.args,vars={'_page':i,'_query':request.vars._query
> or ''})))
>
> How do I do something like this:
>
> vars={'_page':i, if request.vars._query not None then insert this
> key/value pair ('_query':request.vars._query) else insert nothing }


Nevermind, this seems to work:

navs.append(A(' '+str(i+1)+'
',_href=self.action(args=request.args,vars={'_page':i,'_query':request.vars._query}
if request.vars._query else {'_page':i})))

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


Re: how to conditionally add a dict in-line

2009-02-23 Thread Wes James
Steven. Thx

(see my question below...)

On Mon, Feb 23, 2009 at 9:47 PM, Steven D'Aprano
 wrote:
> On Mon, 23 Feb 2009 21:35:38 -0700, Wes James wrote:
>
>> I have this line:
>>
>> navs.append(A(' '+str(i+1)+'
>> ',_href=self.action(args=request.args,vars=
> {'_page':i,'_query':request.vars._query
>> or ''})))
>
> What a mess. How can you read it?
>
>
>> How do I do something like this:
>>
>> vars={'_page':i, if request.vars._query not None then insert this
>> key/value pair ('_query':request.vars._query) else insert nothing }
>
> vars = {'_page': i}
> if request.vars._query is not None:
>    vars['_query'] = request.vars._query

Could this be:

vars = {'_page': i}
 if request.vars._query:
vars['_query'] = request.vars._query



>
> See how simple and clear things are when you give up the insistence on
> making everything a one-liner?



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


Re: Upgrade Python on a Mac

2009-03-02 Thread Wes James
On Mon, Mar 2, 2009 at 2:53 PM, Rey Bango  wrote:
> Hi,
>
> I'd like to upgrade the installed version of Python that came standard
> on OS X (Leopard) with either 2.6.1 or 3.0.1. Before I stick my foot
> in it, I just wanted to get a better understanding of the process.

I'd recommend you put your new versions in to /usr/local

Leave the OS X one alone.

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


Re: file open fails.

2009-03-24 Thread Wes James
On Tue, Mar 24, 2009 at 4:04 PM, Scott David Daniels
 wrote:
> Atul. wrote:



> In your case, '\r' is a return (a single character), not two
> characters long. I think its sad that 'C:\Thesis' doesn't cause
> an error because there is no such character as '\T', but I am
> probably excessively pedantic.

\T might mean the same thing as \t (tab), but I thought it would be different...

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


Re: file open fails.

2009-03-24 Thread Wes James
On Tue, Mar 24, 2009 at 4:32 PM, Wes James  wrote:
> On Tue, Mar 24, 2009 at 4:04 PM, Scott David Daniels
>  wrote:
>> Atul. wrote:
>
> 
>
>> In your case, '\r' is a return (a single character), not two
>> characters long. I think its sad that 'C:\Thesis' doesn't cause
>> an error because there is no such character as '\T', but I am
>> probably excessively pedantic.
>
> \T might mean the same thing as \t (tab), but I thought it would be 
> different...


I guess not:

http://docs.python.org/reference/lexical_analysis.html#string-literals

Wonder why when I do print "test\Ttest" vs print "test\ttest"  \T just
get printed?

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


python twitter

2009-04-15 Thread Wes James
Anyone know if there is a twit for python?  I did
http://twitter.com/python, but nope on that  I was looking for
twit py announcements, etc...

thx,

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


Re: Best Python Web Framework ?

2009-04-21 Thread Wes James
On Tue, Apr 21, 2009 at 12:46 PM, SKYLAB  wrote:
> Greetings..
>
> First , my english is not good .
>
> I heard that was written in python ( Youtube Programming Language :
> PYTHON :S ) Correct ?
>
> That's not correct ? Then youtube is PHP application ?
>
> That's correct ; Which python web framework in friendfeed ? Web.py ?
> Django ? web2py ?
>


You'll need to do some homework to see what fits.

Here's a starter point:

http://wiki.python.org/moin/WebFrameworks

Try some or all.

I used perl for a long time, went looking for a framework, tried
django for a few days then found web2py and web2py fits for me.

good luck

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


string to list when the contents is a list

2010-02-17 Thread Wes James
I have been trying to create a list form a string.  The string will be
a list (this is the contents will look like a list).  i.e. "[]" or
"['a','b']"

The "[]" is simple since I can just check if value == "[]" then return []

But with "['a','b']" I have tried and get:

a="['a','b']"

b=a[1:-1].split(',')

returns

[ " 'a' "," 'b' " ]

when I want it to return ['a','b'].

How can I do this?

thx,

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


error trying to join #python on irc.freenode.net

2010-02-17 Thread Wes James
When I try to join #python on irc.freenode.net it keeps saying:

You need to identify with network services to join the room "#python"
on "irc.freenode.net".

Server Details:
Cannot join channel (+r) - you need to be identified with services

What does this mean?

thx,

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


Re: error trying to join #python on irc.freenode.net

2010-02-17 Thread Wes James
On Wed, Feb 17, 2010 at 4:53 PM, Wes James  wrote:
> When I try to join #python on irc.freenode.net it keeps saying:
>
> You need to identify with network services to join the room "#python"
> on "irc.freenode.net".
>
> Server Details:
> Cannot join channel (+r) - you need to be identified with services
>
> What does this mean?


Nevermind, I think it means I need to register with the service and
supply real username/password.

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


Re: string to list when the contents is a list

2010-02-18 Thread Wes James
On Thu, Feb 18, 2010 at 8:18 AM, Tim Chase
 wrote:
> Wes James wrote:


>
> Just to add to the list of solutions I've seen, letting the built-in csv
> module do the heavy lifting:
>
>  >>> s = "['a','b']"
>  >>> import csv
>  >>> no_brackets = s[1:-1] # s.strip(' \t[]')
>  >>> c = csv.reader([no_brackets], quotechar="'")
>  >>> c.next()
>  ['a', 'b']
>
> This also gives you a bit of control regarding how escaping is done, and
> other knobs & dials to twiddle if you need. Additionally, if you have more
> than one string to process coming from an iterable source (such as a file),
> you can just pass that iterator to csv.reader() instead of concocting a
> one-element list.

Thx,  I think this will work for what I want.

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


Re: string to list when the contents is a list

2010-02-18 Thread Wes James
On Thu, Feb 18, 2010 at 12:32 PM, Wes James  wrote:
> On Thu, Feb 18, 2010 at 8:18 AM, Tim Chase
>  wrote:
>> Wes James wrote:
> 
>
>>
>> Just to add to the list of solutions I've seen, letting the built-in csv
>> module do the heavy lifting:
>>
>>  >>> s = "['a','b']"
>>  >>> import csv
>>  >>> no_brackets = s[1:-1] # s.strip(' \t[]')
>>  >>> c = csv.reader([no_brackets], quotechar="'")
>>  >>> c.next()
>>  ['a', 'b']


Hmm.  When I put csv.reader in a class:

import csv

class IS_LIST():
def __init__(self, format='', error_message='must be a list!'):
self.format = format
self.error_message = error_message
def __call__(self, value):
try:
if value=='[]' or value=='':
value=[]
else:
no_brackets = value[1:-1] # s.strip(' \t[]')
c = csv.reader([no_brackets], quotechar="'")
value=c.next()
return (value, None)
except:
return (value, self.error_message)
def formatter(self, value):
return value

I get an error (when I take the "try" out):

AttributeError: 'function' object has no attribute 'reader'

Why?

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


Re: python dowload

2010-02-23 Thread Wes James


>
>
> NEW QUESTION if y'all are still reading:
>
> Is there an integer increment operation in Python? I tried
> using i++ but had to revert to 'i = i + 1'

i+=1


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


Re: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens

2010-02-24 Thread Wes James
On Wed, Feb 24, 2010 at 5:03 AM, Jonathan Fine  wrote:
> Hi
>
> Does anyone know of a collection of regular expressions that will break a
> TeX/LaTeX document into tokens?  Assume that there is no verbatim or other
> category code changes.

I'm not sure how this does it, but it might help:

http://plastex.sourceforge.net/plastex/sect0025.html

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