Danny Yoo | 1 May 08:11 2006
Picon

Re: Splitting strings into blocks


On Sun, 30 Apr 2006, Daniel Watkins wrote:

> I'm currently working on a program to parse LaTeX style maths 
> expressions and provide an answer. For example, I have the expression 
> "2^\frac{1}{2}". I'm trying to work out a way to split this into it's 
> most basic blocks of LaTeX (i.e. 2^ and \frac{1}{2}) while maintaining a 
> record of the depth of the expression (i.e. (2^,0),(\frac{1}{2},1)).

Hi Daniel,

Forgive me for going off a side tangent here, but do we have to work 
directly on LaTeX?

I don't mean this to be a silly question!  What kind of problem are we 
trying to solve?  It sounds like we're trying to evaluate LaTeX equations, 
so that presents the problem of parsing LaTeX.

Diagrammically:

     LaTeX source ---- parsing --> evaluated expressions

We could talk about parsing LaTeX.  But could we have equations written in 
something easier to parse, and generate LaTeX out of that?  That is:

     some easy-to-parse equations
                |
                +-- simple parser --> LaTeX writer ---> LaTeX source
                |
                +-- simple parser --> evaluator --> evaluated expressions
(Continue reading)

Kent Johnson | 1 May 14:57 2006
Picon

Re: Splitting strings into blocks

Daniel Watkins wrote:
> Hi list,
> I'm currently working on a program to parse LaTeX style maths expressions and 
> provide an answer. For example, I have the expression "2^\frac{1}{2}". I'm 
> trying to work out a way to split this into it's most basic blocks of LaTeX 
> (i.e. 2^ and \frac{1}{2}) while maintaining a record of the depth of the 
> expression (i.e. (2^,0),(\frac{1}{2},1)). I will then process this list from 
> the highest order downwards, feeding the deeper results progressively into 
> shallower elements until all have been calculated.
> LaTeX allows me to legally express the previously stated expression as 
> "{2^{\\frac{1}{2}}}". This makes it much easier to figure out where the units 
> of LaTeX are located. The depth of any item can now be expressed as the 
> number of unpaired opening or closing braces between the element and the 
> start or end of the expression.
> I'm essentially looking for a way to split the string up along the braces, 
> while recording the number of braces between the split and either end of the 
> expression.

First, I'll echo Danny's question - why do you need to do this?

For a general parser of LaTex expressions you will want to use a parsing 
package. I have found pyparsing to be pretty easy to use but there are 
many others. Someone may have solved this problem already.

To answer your specific question, here is code that uses re.split() to 
break an expression on the braces, then a simple loop through the 
results keeps track of nesting level and prints the depth of each token 
between the braces:

import re
(Continue reading)

Kent Johnson | 1 May 15:46 2006
Picon

Re: Splitting strings into blocks

Kent Johnson wrote:
> For a general parser of LaTex expressions you will want to use a parsing 
> package. I have found pyparsing to be pretty easy to use but there are 
> many others. Someone may have solved this problem already.

Googling 'python latex parser' gives some interesting hits including
http://pylatex.sourceforge.net/
http://lists.wxwidgets.org/archive/wxPython-docs/msg00235.html

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Jon Whitehouse | 1 May 16:57 2006
Picon

Pyton and Webpages


Greetings All,

I'm a newbie to python and am curious if I can do the following in python. I'm
not asking HOW to do this, just if it is possible before I spend the time to
learn python and do it myself.

I want to write a program to go to a webpage, pull the data, and then place it
into an excel spreadsheet and then write it to an html file and allow me to
also click on the link to the excel spreadsheet.

Is this possible to do with python?

--
Jon Whitehouse
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Bob Gailer | 1 May 17:29 2006
Picon

Re: Pyton and Webpages

Jon Whitehouse wrote:
> Greetings All,
>
> I'm a newbie to python and am curious if I can do the following in python. I'm
> not asking HOW to do this, just if it is possible before I spend the time to
> learn python and do it myself.
>
> I want to write a program to go to a webpage, pull the data, 
Yes. There is a module for that. Since you want to discover it yourself 
I won't name it here. Hint: going to a web page requires a url.
> and then place it into an excel spreadsheet 
Yes. There are several ways to do that.
> and then write it to an html file 
Yes. Python provides file i/o.
> and allow me to also click on the link to the excel spreadsheet.
>   
Permission granted. You may click. (attempt at humor). Actually I don't 
know what you mean.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Kent Johnson | 1 May 17:37 2006
Picon

Re: Pyton and Webpages

Jon Whitehouse wrote:
> Greetings All,
> 
> I'm a newbie to python and am curious if I can do the following in python. I'm
> not asking HOW to do this, just if it is possible before I spend the time to
> learn python and do it myself.
> 
> I want to write a program to go to a webpage, pull the data, and then place it
> into an excel spreadsheet and then write it to an html file and allow me to
> also click on the link to the excel spreadsheet.
> 
> Is this possible to do with python?

Yes. Some of the pieces you might use are
urllib2 and BeautifulSoup to get the data from the web page
win32com or pyexcelerator to write the Excel file

http://docs.python.org/lib/module-urllib2.html
http://www.crummy.com/software/BeautifulSoup/index.html
http://starship.python.net/crew/mhammond/win32/
http://sourceforge.net/projects/pyexcelerator

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Alfonso | 1 May 18:56 2006
Picon
Picon

copying files and regular expressions

I'm totally new to python. I would like to know, how can I copy files 
using regular expressions (the equivalent in python to unix "cp 
/home/mycount/*partialname* /home/mycount/directory/").

		
______________________________________________ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y móviles desde 1 céntimo por minuto. 
http://es.voice.yahoo.com
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Danny Yoo | 1 May 21:07 2006
Picon

Re: copying files and regular expressions


On Mon, 1 May 2006, Alfonso wrote:

> I'm totally new to python. I would like to know, how can I copy files 
> using regular expressions (the equivalent in python to unix "cp 
> /home/mycount/*partialname* /home/mycount/directory/").

Hi Alfonso,

Just as a pedantic note: the above pattern you're using isn't quite a 
regular expression, but something less powerful called a "glob".

     http://en.wikipedia.org/wiki/Glob

Knowing the common names of things matters sometimes just because we 
communicate through the shared meanings of words.  In this situation, it 
does help because it turns out there's a 'glob' module in Python's 
Standard Library:

     http://www.python.org/doc/lib/module-glob.html

I'm not sure how familiar you are with using the Standard Library.  Have 
you used modules before?

The shell utilities defined in the 'shutil' module should also be helpful 
to let you copy files from one path to another:

     http://www.python.org/doc/lib/module-shutil.html

Best of wishes to you!
(Continue reading)

Nelson, Scott | 2 May 03:06 2006

Re: Pyton and Webpages

WRT creating the Excel file...

The previously mentioned techniques work great.  But, if you want to
start off even simpler, just create a .csv (comma separated value) file
with python's file i/o (there is even a python module to help you with
this if you want).  It is just a simple text file that looks something
like this:

Name, Age, Hair
Adam, 23, brown
Don, 19, gray
Biff, 42, blond
Cathy, 35, red
Gary, 99, none

Excel handles these files just fine.  You don't get all the fancy
formatting, but this is a good first step.

Good luck

-Scott
-----Original Message-----
From: tutor-bounces <at> python.org [mailto:tutor-bounces <at> python.org] On
Behalf Of Kent Johnson
Sent: Monday, May 01, 2006 10:38 AM
Cc: Tutor <at> python.org
Subject: Re: [Tutor] Pyton and Webpages

Jon Whitehouse wrote:
> Greetings All,
(Continue reading)

michel maho | 2 May 16:33 2006
Picon

decimal floating point?

To all
    I have the following calculation:

    "Je Body Mass Index is",gewicht/lengte**2

    The result is a (digital?)floating point figure with with 10 decimal numbers. For =
    example 27.2345678487
    Did I mis something? I would like to reduce it to one or two decimal =
    numbers.(27.2) but round(_,1) does not work.
    Is there any other way?
    Thank You
    Michel Maho
Sorry if this is a second mail.
Something went wrong
Michel
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Gmane