excel library without COM

2007-06-03 Thread james_027
Hi,

is there any library to help me write excel files without using win
com? because i'll be working on linux platform. At the same time I
could want to perform some formatting, merging of cells. adding sheets
and etc ...

Thanks
james

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


Re: excel library without COM

2007-06-04 Thread james_027
On Jun 4, 8:16 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jun 4, 3:52 pm, yuce <[EMAIL PROTECTED]> wrote:
>
> > i think this one works pretty nice:http://www.python.org/pypi/xlrd
>
> Sure does :-) However the "rd" in "xlrd" is short for "ReaD". As
> Waldemar suggested, "xlwt" ("wt" as in WriTe) is more like what the OP
> needs.
>
> Cheers,
> John


Thanks to all who have contributed. I have one concern though. Many of
the module seems to be not active anymore? or updated? It is because
it really stable and has most of the features needed?

Thanks
james

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


Re: excel library without COM

2007-06-05 Thread james_027
On Jun 5, 6:17 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jun 5, 1:04 pm, james_027 <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jun 4, 8:16 pm, John Machin <[EMAIL PROTECTED]> wrote:
>
> > > On Jun 4, 3:52 pm, yuce <[EMAIL PROTECTED]> wrote:
>
> > > > i think this one works pretty nice:http://www.python.org/pypi/xlrd
>
> > > Sure does :-) However the "rd" in "xlrd" is short for "ReaD". As
> > > Waldemar suggested, "xlwt" ("wt" as in WriTe) is more like what the OP
> > > needs.
>
> > > Cheers,
> > > John
>
> > Thanks to all who have contributed. I have one concern though. Many of
> > the module seems to be not active anymore? or updated? It is because
> > it really stable and has most of the features needed?
>
> xlwt is active, stable enough for heavy use, and will get a public
> outing Real Soon Now (after xlrd 0.6.1 final, which is expected Truly
> Rooly Real Soon Now).

Thanks a John

Now my searching is over

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


Dive into Python 5.5

2007-06-13 Thread james_027
Hi,

class UserDict:
def __init__(self, dict=None):
self.data = {}
if dict is not None: self.update(dict)

I just don't understant this code, as it is not also mention in the
book. the update is a method of a dict right? in my understanding the
last statement should be self.data.update(dict).

someone please explain to me what happen where?

Thanks
james

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


for web application development

2007-06-14 Thread james_027
hi everyone,

I am very new to python, I am almost done learning the python language
enough that I can start learning developing web app in python. I have
gone thru many research and I still say that I will want to develop
web app in python. Although some says php should be better since the
language is made for the web compare to python. In the point of view
of rails, they say that their framework is really easy and best for
web app.

My problem is looking for a web framework for python, that could
provide a natural way of developing web app. I am avoiding to learn
template language as much as possible.

Any advice will be greatly appreciated.

THanks
james

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


python website

2007-06-20 Thread james_027
hi,

what are you list of favorite python website (news, articles,
tutorials)?

cheers,
james

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


class attributes & data attributes

2007-06-20 Thread james_027
hi everyone,

I am now in chapter 5 of Dive Into Python and I have some question
about it. From what I understand in the book is you define class
attributes & data attributes like this in python

class Book:

total # is a class attribute

def __init__(self):
self.title  # is a data attributes
self.author # another data attributes

To define class attributes is like defining a function in class, to
define a data attributes is defining a variable inside the __init__
method.

what makes me confuse is this model from Django

from django.db import models

class Person(models.Model):
first_name = models.CharField(maxlength=30)
last_name = models.CharField(maxlength=30)

I believe the first_name and last_name are data attributes? but why it
is they look like a class attributes as being define.

Thanks in advance for explaining

james

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


gui application on cross platform

2007-05-27 Thread james_027
Hi,

I am using delphi to develop gui application, and wish to make a shift
to python. here are some of my question/concern...

1. is python develop gui application a cross platform? just like java
swing?
2. delphi makes things easy for me like coding for a specific event on
a specific component, could it be the same for python?
3. are there cool library of component like in delphi available for
python that will make database application more usesable?
4. where do I start the learning curve? I did some research and I
don't know which one to take among wxwdiget, pygtk, and etc.


Thanks
james

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


Re: gui application on cross platform

2007-05-28 Thread james_027
On May 28, 3:06 pm, Stefano Canepa <[EMAIL PROTECTED]> wrote:
> On 28 Mag, 08:01, james_027 <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I am using delphi to develop gui application, and wish to make a shift
> > to python. here are some of my question/concern...
>
> > 1. is python develop gui application a cross platform? just like java
> > swing?
>
> Yes. Qt, wxwidgets and pygtk run on Linux and Windows, don't know
> about Macs.
>
> > 2. delphi makes things easy for me like coding for a specific event on
> > a specific component, could it be the same for python?
>
> Not in the Delphi way but glade/gazpacho are good GUI designer for
> gtk.
> I have no experience with qtdesigner or the wx equivalent app.
>
> > 3. are there cool library of component like in delphi available for
> > python that will make database application more usesable?
>
> python has dbapi, all DBs look the same, python can also use ORM like
> SQLObjects and SQLALchemy
>
> > 4. where do I start the learning curve? I did some research and I
> > don't know which one to take among wxwdiget, pygtk, and etc.
>
> I tried wxwidgets and pygtk, then I decided to use pygtk but it
> could be I'll change my mind in the future.
>
> Bye
> sc

Thanks sc,

What do you mean when you say .."all DBs look the same"

what is the difference between pygtk and wxwidgets?

bye
james

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


decorators tutorials

2007-07-23 Thread james_027
Hi,

I am learning python by learning django, and I stumble upon decorator
which is very cool, any beginners resources for python decorators,
although I can google it, I just want to get a good tutorial for this
topic.

Thanks
james

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


Re: decorators tutorials

2007-07-23 Thread james_027
Hi all,

I am having difficulty understanding decorator. The definition was
clear for me, but the syntax is not so clear to me.

will decorators will always have to be in this way

def check_login(func):
def _check_login(*args):
print "I am decorator"
return func(*args)
return _check_login



@check_login
def method2(input):
print "I am method TWO. Input %s" % input


james

On Jul 23, 4:41 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> james_027 wrote:
> > Hi,
>
> > I am learning python by learning django, and I stumble upon decorator
> > which is very cool, any beginners resources for python decorators,
> > although I can google it, I just want to get a good tutorial for this
> > topic.
>
> Decorators are just a more concise but less obvious way of calling a
> defined function on another function.
>
> e.g.
> @my_decorator
> def foo():
>...
>
> is the essentially the same as:
>
> def foo():
>...
> foo=my_decorator(foo)


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


Re: decorators tutorials

2007-07-23 Thread james_027
hi bruno,

That seems to be hard to read at all, or I am just very new to python?

With that decorator how do I take advantage of it compare when I just
write a function that could do the same as what the decorator did? I
could translate the could from above into ...

def check_login(msg):
   #...
def my_func(toto, tata):
   #...

#call it like this
check_login('msg')
my_func('toto', 'tata')

Thanks
james
On Jul 23, 6:26 pm, Bruno Desthuilliers  wrote:
> james_027 a écrit :
>
> > Hi all,
>
> > I am having difficulty understanding decorator. The definition was
> > clear for me, but the syntax is not so clear to me.
>
> > will decorators will always have to be in this way
>
> > def check_login(func):
> > def _check_login(*args):
> > print "I am decorator"
> > return func(*args)
> > return _check_login
>
> Sort of... Well, depends...
>
> Basically, a decorator is a callable taking a callable as argument and
> returning a callable. These callable are usually *but* not necessarily
> functions. You may want to read the section about the special method
> __call__ in the  Fine Manual.
>
> Also, you may want to write a 'parameterized' decorator - a decorator
> taking arguments. In this case, you need one more wrapping level:
>
> def check_login(msg):
>def check_login_deco(func):
>  def _check_login(*args, **kw):
>print msg
>return func(*args, **kw)
>  return _check_login
>return check_login_deco
>
> @check_login("I am the decorator")
> def my_func(toto, tata):
>print toto, tata


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

Re: decorators tutorials

2007-07-23 Thread james_027
Hi,

> > def check_login(func):
> > def _check_login(*args):
> > print "I am decorator"
> > return func(*args)
> > return _check_login
>
> > @check_login
> > def method2(input):
> > print "I am method TWO. Input %s" % input
>
> That looks okay. What is unclear?
>

It just look complicated than using a simple function like this
def check_login(msg):
   #...
def my_func(toto, tata):
   #...

#call it like this
check_login('msg')
my_func('toto', 'tata')

I hope I could be able to understand clearly the decorators and use it
to it efficiently

Thanks
james

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


classmethod & staticmethod

2007-07-23 Thread james_027
hi,

python's staticmethod is the equivalent of java staticmethod right?

with classmethod, I can call the method without the need for creating
an instance right? since the difference between the two is that
classmethod receives the class itself as implicti first argument. From
my understanding classmethod are for dealing with class attributes?

Can somebody teach me the real use of classmethod & staticmethod?

Thanks
james

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


Re: classmethod & staticmethod

2007-07-24 Thread james_027
hi,

> The 'real' use is (are) the one(s) you'll find. FWIW, I use
> staticmethods for helper functions that don't need access to the class
> or instance but are too specific to a class to be of any use as plain
> functions. Which is not a very frequent case. Classmethods are more
> usefull - mostly as alternate constructors or utility methods for an
> alternate constructor, but there are other possible uses (sorry, I have
> no concrete example at hand).

You mean like the example from Marc

Thanks
james

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


cls & self

2007-07-25 Thread james_027
hi,

is cls & self the same thing?

I have seen something like

class A:
def dosomething(cls):
   #doing something

How is cls & self differ? How is it use?

Thanks
james

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


access the name of my method inside it

2007-08-01 Thread james_027
Hi,

for example I have this method

def my_method():
# do something

# how do I get the name of this method which is my_method here?

Thanks,
james

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


Re: access the name of my method inside it

2007-08-01 Thread james_027
Hi,

On Aug 1, 5:18 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote:
> > for example I have this method
>
> > def my_method():
> > # do something
>
> > # how do I get the name of this method which is my_method here?
>
> Why do you need this?  There are ways but those are not really good for
> production code.
>

I am going to use this in Django. I am trying to implement a
permission here, where in the database store the methods that the user
are allowed to execute. for example if the method is def
create_event(): the method will look for create_event in the database
to see if it allow to be execute.

Thanks.
james

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


Re: access the name of my method inside it

2007-08-01 Thread james_027
Hi all!

Thanks for all your idea, this community is truly a great one!

james

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


a dict trick

2007-08-01 Thread james_027
hi

for example I have this dictionary

dict = {'name':'james', 'language':'english'}

value = 'sex' in dict and dict['sex'] or 'unknown'

is a right pythonic of doing this one? I am trying to get a value from
the dict, but if the key doesn't exist I will provide one.

THanks
james

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


Re: a dict trick

2007-08-02 Thread james_027
Hi,

what if we're not dealing with dict? is there a pythonic way of doing
ternary? the bool ? x:y

Thanks
james

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


help with flexible decorators

2007-08-06 Thread james_027
Hi,

I want to write a flexible decorators to edit a function that may have
1 or more arguments...

def enhance(func):
def new(x):
#do something ...
return func(x)
return new

@enhance
def method_a(x):
#do something ...

While the enhance decorator work with functions of 1 argument, how do
I make it to work with more than one arguments.

Thanks
james

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


accessing static attributes

2007-08-09 Thread james_027
hi,

for example an request object ... is request.user the same as
request.__class__.user?

THanks
james

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


accessing keys in dict

2007-08-14 Thread james_027
hi,

a_dict = {'name':'apple', 'color':'red', 'texture':'smooth',
'shape':'sphere'}

is there any difference between ..

for key in a_dict:

from

for key in a_dict.keys():


which is more preferred? any difference in performance?

THanks
james

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


to property or function in class object

2007-08-16 Thread james_027
hi,

i am very new to python, not knowing much about good design. I have an
object here for example a Customer object, where I need to retrieve a
info which has a number of lines of code to get it.

my question is weather what approach should I use? to use the property
which is from the python new class style as I understand or simple use
function that will return the the info I needed.

class Customer(object):

current_balance = property(fget=_get_current_balance)

def _get_current_balance(self):
   # coding here

or

def get_current_balance(self):
   # coding here

While both approach would get the job done, I don't know much about
the performance, benefits, design philosophy between the two approach.
Any lecture will be very appreciated.

Thanks
james

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


searching dict key with reqex

2007-08-21 Thread james_027
hi,

can I use regex instead of a plain string with this kind of syntax ...

'name' in a_dictionary

something like

r'name_\D+' in a_dictionary?

Thanks
james

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


for statement on empty iterable

2007-08-21 Thread james_027
hi,

I need to do some for loop on iterables which could be empty
sometimes, for example

a_list = []

for i in a_list:
 #do something

is this safe? or should I put a if statement to test it first?

Thanks
james

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


Re: for statement on empty iterable

2007-08-21 Thread james_027
hi Paul,

>
> That doesn't crash or anything like that, but it also doesn't
> set the index variable, which can cause confusion in some situations.

Thanks for your quick answer ... Actually I was thinking how do I
access the index inside a for statement? Can you help

Thanks
james


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


Re: for statement on empty iterable

2007-08-21 Thread james_027
hi,

> It sounds like you're just starting to learn the language... have you
> read the online tutorial yet?  That is a pretty easy introduction.
>
> See:http://python.org/doc/
>
> Anyway, you can say
>
>for i in (1,2,3):
>   print i*5
>
> to print 5, 10, and 15 on separate lines, for example.

Yes i am new to python :). I am sorry I should be clarify myself ...
for example

l = ['j', 'a', 'm', 'e', 's']

for i in l
 # i want to know the nth number of times it has loop thru or
something like counter?

Thanks
james

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


Re: for statement on empty iterable

2007-08-21 Thread james_027
hi,

> Oh I see.  You have to combine a couple of concepts but for this
> example you'd say:
>
>name = 'james' # 'l' looks too much like the digit 1
>for i,c in enumerate(name):
>   print i, c
>print i
>
> enumerate(name) generates the sequence
>
>(0,'j'), (1,'a'), (2,'m'), (3,'e'), (4,'s')
>
> and the above loop splits those tuples into two indexes i and c.
>
> You should probably read the tutorial and work through the examples.
> If you get something wrong with this basic stuff, your computer won't
> explode or anything like that, so try stuff out.  Be more careful when
> you start using library routines that can delete files ;).

Thanks, it just that I am afraid of coding that something works but
ugly or inefficient.

cheers,
james

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


creating a dictionary from a dictionary with regex

2007-08-22 Thread james_027
Hi,

I am trying to create a dictionary from a dictionary which the help of
regex to identify which keys to select. I have something like this but
I feel its long and not the fastest solution ... could someone
contribute?

import re

d= {'line2.qty':2, 'line3.qty':1, 'line5.qty':12, 'line2.item':'5c-BL
Battery', 'line3.item':'N73', 'line5.item':'Screen Cover'}

collected = [k[:5] for k in d if re.match('^line\d+\.qty',k)]

for i in collected:
d2 = {}
for k in d:
if re.match('^%s\.\D+' % i, k):
d2[k] = d[k]
print d2

Thanks
james

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


setattr vs readonly property

2007-09-12 Thread james_027
hi,

My main purpose for using setattr(object, attr, value) for assign
values from a dict that has some keys that may not be present on some
object's attibute, which makes it work for me. My problem is dealing
with read only attribute like sample_attribute =
property(f_get=_get_sample_attribute). what approach should I use? Or
is my first approach In the first place right?

Thanks
james

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


mass editing for keys in a dictionary

2007-09-14 Thread james_027
hi,

How could I transform something like this

dict_1 = {'customer_id':1, 'item_id':3, amount:100}

into

dict_2 = {'customer':1, 'item':3, amount:100}

thanks
james

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


%s shortcut?

2007-09-25 Thread james_027
hi i have something like this

cursor.execute("""
select c.name,
(select from ap_invoice i where Month(i.date) = 1 and
Year(i.date) = %s and i.customer_id = c.id and i.status != 'CAN') jan,
(select from ap_invoice i where Month(i.date) = 2 and
Year(i.date) = %s and i.customer_id = c.id and i.status != 'CAN') feb,
(select from ap_invoice i where Month(i.date) = 3 and
Year(i.date) = %s and i.customer_id = c.id and i.status != 'CAN') mar
from ap_customer c
order by %s""",
[year, order_by])

what I could like to happen is ... since the first three %s points to
the same year variable, how do I let python know it without doing
[year ,year, year, order_by] ... This should be 12 I just cut it down

Thanks
james

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


Re: %s shortcut?

2007-09-25 Thread james_027
hi bjorn,
> You could do [year]*12 + [order_by] like so:
>
> >>> [1970] * 12 + ['foo']
>
> [1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970,
> 1970, 'foo']
>
>
>
> I don't know which database you're using, but the above doesn't look
> like SQL'92...
>

Thanks, it works!

I am using mysql 5, and it works (i am having a hard time with mysql's
SP, firebird is very easy and nice)


cheers,
james


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


regex with specific list of string

2007-09-26 Thread james_027
hi,

how do I regex that could check on any of the value that match any one
of these ... 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
'sep', 'oct', 'nov', 'dec'

Thanks
james

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


Re: regex with specific list of string

2007-09-26 Thread james_027
Hi all,

> This is fine IMO since the OP didn't specify the opposite.
>

Thanks for all your replies, though I don't understand quite well the
going argument? What do you mean when you say "the OP didn't specify
the opposite"?

There reason for using regex is because I am going to use it in
Django's URL pattern

Thanks
james

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


calling a function from string

2007-10-22 Thread james_027
hi,

i have a function that I could like to call, but to make it more
dynamic I am constructing a string first that could equivalent to the
name of the function I wish to call. how could I do that? the string
could might include name of the module.

for example

a_string = 'datetime.' + 'today()'

how could I call a_string as function?

Thanks
james

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


transforming list

2007-10-23 Thread james_027
hi,

i have a list from a resultset like this
1,"Chicago Bulls",,,""
2,"Cleveland Caveliers",,,""
4,"Detroit Pistons",1,"23686386.35"
4,"Detroit Pistons",2,"21773898.07"
4,"Detroit Pistons",3,"12815215.57"
4,"Detroit Pistons",4,"48522347.76"
4,"Detroit Pistons",5,"28128425.99"
4,"Detroit Pistons",6,"15681603.08"
4,"Detroit Pistons",8,"12627725.03"
4,"Detroit Pistons",9,"11417.00"
4,"Detroit Pistons",10,"945689.22"
4,"Detroit Pistons",11,"818246.57"
4,"Detroit Pistons",12,"1154292.77"
5,"Phoenix Suns",1,"23211445.97"
5,"Phoenix Suns",3,"11268469.53"
5,"Phoenix Suns",4,"49913569.61"
5,"Phoenix Suns",5,"26035236.09"
5,"Phoenix Suns",7,"113953310.50"
5,"Phoenix Suns",8,"17091769.84"
5,"Phoenix Suns",10,"818569.99"
5,"Phoenix Suns",11,"824602.19"
5,"Phoenix Suns",12,"1142018.11"

and I wish to transform it into something like this

1, "Chicago Bulls", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
2, "Cleveland Caveliers", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
4, "Detroit Pistons", 23686386.35, 21773898.07, 12815215.57,
48522347.76, 28128425.99, 15681603.08, 0, 12627725.03, 11417.00,
945689.22, 818246.57, 1154292.77
5, "Phoenix Suns", 23211445.97, 0, 11268469.53, 499113569.61,
26035236.09, 0, 113953310.50, 17091769.84, 0, 818569.99, 824602.19,
1142018.11

currently my solution is something like this the rows is the original
list which is list of list ... the report is a list of list with the
new arrangement that I want.

report = []
report_item = None
temp_c_id = 0
for row in rows:
if not row[0] == temp_c_id:
temp_c_id = row[0]
if report_item: report.append(report_item)
report_item = [row[0], row[1], 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0]
if row[2]:
report_item[row[2]+1] = row[3]

I feel this solution is not that good, can I make this more pythonic?!

Thanks
james :)

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


Re: transforming list

2007-10-23 Thread james_027
hi,

On Oct 24, 1:14 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Oct 23, 9:46?pm, james_027 <[EMAIL PROTECTED]> wrote:> hi,
>
> > i have a list from a resultset like this
> > 1,"Chicago Bulls",,,""
> > 2,"Cleveland Caveliers",,,""
>
>^ ^^^ ^
>| ||| |
>1 234 5
>
> How come these records have 5 fields...
>
> > 4,"Detroit Pistons",1,"23686386.35"
>
>^ ^ ^^
>| | ||
>1 2 34
>
> ...whereas these only have 4 fields?
>

sorry, it's a typo error... there are only 4 fields.

thanks

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


PDF library

2007-11-15 Thread james_027
hi,

I am looking for a python PDF library that starts with 'Q' ... I just
found them somewhere in the internet but I can't find them now that I
need it. Does someone knows this?

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


sorting a list of list

2007-11-20 Thread james_027
hi,

are there available library or pythonic algorithm for sorting a list
of list depending on the index of the list inside the list of my
choice?

d_list = [
['a', 1, 9],
['b', 2, 8],
['c', 3, 7],
['d', 4, 6],
['e', 5, 5],
]

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


replacing words in HTML file

2010-04-28 Thread james_027
hi,

Any idea how I can replace words in a html file? Meaning only the
content will get replace while the html tags, javascript, & css are
remain untouch.

THanks,
James
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacing words in HTML file

2010-04-29 Thread james_027
On Apr 29, 5:31 am, Cameron Simpson  wrote:
> On 28Apr2010 22:03, Daniel Fetchinson  wrote:
> | > Any idea how I can replace words in a html file? Meaning only the
> | > content will get replace while the html tags, javascript, & css are
> | > remain untouch.
> |
> | I'm not sure what you tried and what you haven't but as a first trial
> | you might want to
> |
> | 
> |
> | f = open( 'new.html', 'w' )
> | f.write( open( 'index.html' ).read( ).replace( 'replace-this', 'with-that' 
> ) )
> | f.close( )
> |
> | 
>
> If 'replace-this' occurs inside the javascript etc or happens to be an
> HTML tag name, it will get mangled. The OP didn't want that.
>
> The only way to get this right is to parse the file, then walk the doc
> tree enditing only the text parts.
>
> The BeautifulSoup module (3rd party, but a single .py file and trivial to
> fetch and use, though it has some dependencies) does a good job of this,
> coping even with typical not quite right HTML. It gives you a parse
> tree you can easily walk, and you can modify it in place and write it
> straight back out.
>
> Cheers,
> --
> Cameron Simpson  DoD#743http://www.cskk.ezoshosting.com/cs/
>
> The Web site you seek
> cannot be located but
> endless others exist
> - Haiku Error 
> Messageshttp://www.salonmagazine.com/21st/chal/1998/02/10chal2.html

Hi all,

Thanks for all your input. Cameron Simpson get the idea of what I am
trying to do. I've been looking at beautiful soup so far I don't know
how to perform search and replace within it.

Any suggest good read?

Thanks all,

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


fast regex

2010-05-06 Thread james_027
hi,

I was working with regex on a very large text, really large but I have
time constrained. Does python has any other regex library or string
manipulation library that works really fast?

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


Re: fast regex

2010-05-06 Thread james_027
On May 6, 11:33 pm, John Bokma  wrote:
> james_027  writes:
> > I was working with regex on a very large text, really large but I have
> > time constrained. Does python has any other regex library or string
> > manipulation library that works really fast?
>
> Hard to answer without seeing your regex and requirements first.
> Your question is like: I had a meal yesterday and it upset my
> stomach. Can you suggest a different meal for today?
>
> --
> John Bokma                                                               j3b
>
> Hacking & Hiking in Mexico -  http://johnbokma.com/http://castleamber.com/- 
> Perl & Python Development

I am doing something like this

for key, value in words_list.items():
compile = re.compile(r"""\b%s\b""" % key, re.IGNORECASE)
search = compile.sub(value, content)

where the content is a large text about 500,000 characters and the
word list is about 5,000

Any optimization for the code above?

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


Re: fast regex

2010-05-06 Thread james_027
On May 6, 11:33 pm, John Bokma  wrote:
> james_027  writes:
> > I was working with regex on a very large text, really large but I have
> > time constrained. Does python has any other regex library or string
> > manipulation library that works really fast?
>
> Hard to answer without seeing your regex and requirements first.
> Your question is like: I had a meal yesterday and it upset my
> stomach. Can you suggest a different meal for today?
>
> --
> John Bokma                                                               j3b
>
> Hacking & Hiking in Mexico -  http://johnbokma.com/http://castleamber.com/- 
> Perl & Python Development

I am doing something like this

for key, value in words_list.items():
compile = re.compile(r"""\b%s\b""" % key, re.IGNORECASE)
search = compile.sub(value, content)

where the content is a large text about 500,000 characters and the
word list is about 5,000

Any optimization for the code above?

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


Re: fast regex

2010-05-06 Thread james_027
On May 6, 11:33 pm, John Bokma  wrote:
> james_027  writes:
> > I was working with regex on a very large text, really large but I have
> > time constrained. Does python has any other regex library or string
> > manipulation library that works really fast?
>
> Hard to answer without seeing your regex and requirements first.
> Your question is like: I had a meal yesterday and it upset my
> stomach. Can you suggest a different meal for today?
>
> --
> John Bokma                                                               j3b
>
> Hacking & Hiking in Mexico -  http://johnbokma.com/http://castleamber.com/- 
> Perl & Python Development

I am doing something like this

for key, value in words_list.items():
compile = re.compile(r"""\b%s\b""" % key, re.IGNORECASE)
search = compile.sub(value, content)

where the content is a large text about 500,000 characters and the
word list is about 5,000

Any optimization for the code above?

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


using reverse in list of tuples

2010-06-09 Thread james_027
hi,

I am trying to reverse the order of my list of tuples and its is
returning a None to me. Is the reverse() function not allow on list
containing tuples?

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