List to Text back to List

2008-11-06 Thread SimonPalmer
Hi, I am looking for a way to convert a List of floating point numbers
to and from text.  I am embedding it in an XML document and am looking
for a neat way to serialise and de-serialise a list from a text node.
I can easily write something to do it manually but I wondered whether
List had native support to go to and from text.

If not List, are there any other collections/arrays that do this?

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


Re: List to Text back to List

2008-11-06 Thread SimonPalmer
On Nov 6, 8:11 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote:
> On Thu, Nov 6, 2008 at 12:04 PM, SimonPalmer <[EMAIL PROTECTED]> wrote:
> > Hi, I am looking for a way to convert a List of floating point numbers
> > to and from text.  I am embedding it in an XML document and am looking
> > for a neat way to serialise and de-serialise a list from a text node.
> > I can easily write something to do it manually but I wondered whether
> > List had native support to go to and from text.
>
> > If not List, are there any other collections/arrays that do this?
>
> It's not really a matter of the collection, but more a matter of
> serialization format/library.
>
> If you want the serialized representation to be human-readable, use
> JSON (http://docs.python.org/library/json.html#module-json).
> If that's not a requirement, use pickle
> (http://docs.python.org/library/pickle.html#module-pickle).
> Both modules can convert simple Python data, such as your list of
> floats, to a bytestream and back again.
>
> Cheers,
> Chris
> --
> Follow the path of the Iguana...http://rebertia.com
>
>
>
> > TIA
> > Simon
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>

I looked at pickle, but the problem is that I want my XML to be
readable by languages other than python, so it sort of precludes it.
JSON would be perfect, but I think the module only exists in 2.6, is
that right?  Unfortunately I am bound to 2.4.

It is looking more and more like I am going to have to roll my own.
--
http://mail.python.org/mailman/listinfo/python-list


Re: List to Text back to List

2008-11-07 Thread SimonPalmer
On Nov 6, 8:33 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote:
> On Thu, Nov 6, 2008 at 12:18 PM, SimonPalmer <[EMAIL PROTECTED]> wrote:
> > On Nov 6, 8:11 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote:
> >> On Thu, Nov 6, 2008 at 12:04 PM, SimonPalmer <[EMAIL PROTECTED]> wrote:
> >> > Hi, I am looking for a way to convert a List of floating point numbers
> >> > to and from text.  I am embedding it in an XML document and am looking
> >> > for a neat way to serialise and de-serialise a list from a text node.
> >> > I can easily write something to do it manually but I wondered whether
> >> > List had native support to go to and from text.
>
> >> > If not List, are there any other collections/arrays that do this?
>
> >> It's not really a matter of the collection, but more a matter of
> >> serialization format/library.
>
> >> If you want the serialized representation to be human-readable, use
> >> JSON (http://docs.python.org/library/json.html#module-json).
> >> If that's not a requirement, use pickle
> >> (http://docs.python.org/library/pickle.html#module-pickle).
> >> Both modules can convert simple Python data, such as your list of
> >> floats, to a bytestream and back again.
>
> >> Cheers,
> >> Chris
> >> --
> >> Follow the path of the Iguana...http://rebertia.com
>
> >> > TIA
> >> > Simon
> >> > --
> >> >http://mail.python.org/mailman/listinfo/python-list
>
> > I looked at pickle, but the problem is that I want my XML to be
> > readable by languages other than python, so it sort of precludes it.
> > JSON would be perfect, but I think the module only exists in 2.6, is
> > that right?  Unfortunately I am bound to 2.4.
>
> > It is looking more and more like I am going to have to roll my own.
>
> The module is available as a third-party library for previous Python
> versions athttp://www.undefined.org/python/
>
> Cheers,
> Chris
> --
> Follow the path of the Iguana...http://rebertia.com

simplejson did the trick.

the trouble with a couple of suggestions is that they are only really
any good for 1 dimensional lists, although I confess I didn't make
that requirement clear in my original question

sorry for capitalising list, my mistake, hope you weren't too confused.
--
http://mail.python.org/mailman/listinfo/python-list


finding out the number of rows in a CSV file

2008-08-27 Thread SimonPalmer
anyone know how I would find out how many rows are in a csv file?

I can't find a method which does this on csv.reader.

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


Re: finding out the number of rows in a CSV file [Resolved]

2008-08-27 Thread SimonPalmer
On Aug 27, 12:41 pm, Jon Clements <[EMAIL PROTECTED]> wrote:
> On Aug 27, 12:29 pm, "Simon Brunning" <[EMAIL PROTECTED]>
> wrote:
>
> > 2008/8/27 SimonPalmer <[EMAIL PROTECTED]>:
>
> > > anyone know how I would find out how many rows are in a csv file?
>
> > > I can't find a method which does this on csv.reader.
>
> > len(list(csv.reader(open('my.csv'
>
> > --
> > Cheers,
> > Simon B.
> > [EMAIL PROTECTED]://www.brunningonline.net/simon/blog/
>
> Not the best of ideas if the row size or number of rows is large!
> Manufacture a list, then discard to get its length -- ouch!

Thanks to everyone for their suggestions.

In my case the number of rows is never going to be that large (<200)
so it is a practical if slightly inelegant solution
--
http://mail.python.org/mailman/listinfo/python-list


Re: finding out the number of rows in a CSV file [Resolved]

2008-08-27 Thread SimonPalmer
On Aug 27, 12:50 pm, SimonPalmer <[EMAIL PROTECTED]> wrote:
> On Aug 27, 12:41 pm, Jon Clements <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 27, 12:29 pm, "Simon Brunning" <[EMAIL PROTECTED]>
> > wrote:
>
> > > 2008/8/27 SimonPalmer <[EMAIL PROTECTED]>:
>
> > > > anyone know how I would find out how many rows are in a csv file?
>
> > > > I can't find a method which does this on csv.reader.
>
> > > len(list(csv.reader(open('my.csv'
>
> > > --
> > > Cheers,
> > > Simon B.
> > > [EMAIL PROTECTED]://www.brunningonline.net/simon/blog/
>
> > Not the best of ideas if the row size or number of rows is large!
> > Manufacture a list, then discard to get its length -- ouch!
>
> Thanks to everyone for their suggestions.
>
> In my case the number of rows is never going to be that large (<200)
> so it is a practical if slightly inelegant solution

actually not resolved...

after reading the file throughthe csv.reader for the length I cannot
iterate over the rows.  How do I reset the row iterator?
--
http://mail.python.org/mailman/listinfo/python-list


Re: finding out the number of rows in a CSV file [Resolved]

2008-08-27 Thread SimonPalmer
On Aug 27, 1:15 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Aug 27, 9:54 pm, SimonPalmer <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 27, 12:50 pm, SimonPalmer <[EMAIL PROTECTED]> wrote:
>
> > > On Aug 27, 12:41 pm, Jon Clements <[EMAIL PROTECTED]> wrote:
>
> > > > On Aug 27, 12:29 pm, "Simon Brunning" <[EMAIL PROTECTED]>
> > > > wrote:
>
> > > > > 2008/8/27 SimonPalmer <[EMAIL PROTECTED]>:
>
> > > > > > anyone know how I would find out how many rows are in a csv file?
>
> > > > > > I can't find a method which does this on csv.reader.
>
> > > > > len(list(csv.reader(open('my.csv'
>
> > > > > --
> > > > > Cheers,
> > > > > Simon B.
> > > > > [EMAIL PROTECTED]://www.brunningonline.net/simon/blog/
>
> > > > Not the best of ideas if the row size or number of rows is large!
> > > > Manufacture a list, then discard to get its length -- ouch!
>
> > > Thanks to everyone for their suggestions.
>
> > > In my case the number of rows is never going to be that large (<200)
> > > so it is a practical if slightly inelegant solution
>
> > actually not resolved...
>
> > after reading the file throughthe csv.reader for the length I cannot
> > iterate over the rows.
>
> OK, I'll bite: Why do you think you need to know the number of rows in
> advance?
>
> > How do I reset the row iterator?
>
> You don't. You throw it away and get another one. You need to seek to
> the beginning of the file first. E.g.:
>
> C:\junk>type foo.csv
> blah,blah
> waffle
> q,w,e,r,t,y
>
> C:\junk>type csv2iters.py
> import csv
> f = open('foo.csv', 'rb')
> rdr = csv.reader(f)
> n = 0
> for row in rdr:
>n += 1
> print n, f.tell()
> f.seek(0)
> rdr = csv.reader(f)
> for row in rdr:
> print row
>
> C:\junk>csv2iters.py
> 3 32
> ['blah', 'blah']
> ['waffle']
> ['q', 'w', 'e', 'r', 't', 'y']
>
> HTH,
> John

this is all good, and thanks for your time.  I need the number of rows
because of the nature of the data and what I do with it on reading.  I
need to initialise some data structures and that is *much* more
efficient if I know in advance the number of rows of data.  The cost
of reading the file is probably less than incrementally extending my
internal structures because of their complexity.

To be honest these are all good solutions and I think I have a a view
of csv reading that comes form different technologies plus lack of
experience with python which just means that I don't know where to
look for answers.

Very happy that I can now proceed.
--
http://mail.python.org/mailman/listinfo/python-list


Python on the web - newby question

2008-09-03 Thread SimonPalmer
Apologies in advance if this is either a) the wrong board or b) been
answered a million times elsewhere, but...

I have been given an assignment to get a python module up and running
behind an existing web site.  At the moment the rest of the site is
developed in PHP but the hosts have said they will provide python
support for free, although they haven't given any more details than
that, so I'm not sure exactly what that means.  All reasonably
encouraging though.

I'm a newbie to python but quite experienced with Java/J2EE/JBoss.
What I need to know is how I get python running on the server and what
tools/middleware I would need to have installed on the host's machines
to be able to support my python modules.

Again, apologies if this is the wrong place but I'm a bit lost and
would really appreciate some pointers.

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


Re: Python on the web - newby question

2008-09-03 Thread SimonPalmer
On Sep 3, 8:41 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> SimonPalmer a écrit :
>
> > Apologies in advance if this is either a) the wrong board or b) been
> > answered a million times elsewhere, but...
>
> > I have been given an assignment to get a python module up and running
> > behind an existing web site.  At the moment the rest of the site is
> > developed in PHP but the hosts have said they will provide python
> > support for free, although they haven't given any more details than
> > that, so I'm not sure exactly what that means.
>
> Depending on the hosts, this can range from having an antiquated python
> version with only cgi enabled and no way to install anything to the very
> last stable release and (almost) whatever third-part lib / frameworks
> and correct configuration.
>
> >  All reasonably
> > encouraging though.
>
> > I'm a newbie to python but quite experienced with Java/J2EE/JBoss.
>
> Quite another world...
>
> > What I need to know is how I get python running on the server
>
> For which definition of 'server' ? The computer, or the web server process ?
>
> > and what
> > tools/middleware I would need to have installed on the host's machines
> > to be able to support my python modules.
>
> Depends on your modules dependencies !-)
>
> More seriously : Python is known has being the language with more web
> frameworks than keywords. IOW, there's no simple straightforward answer
> to your question. Fisrt choose which Python web development solution you
> intend to use, then read the FineManual's "deployment" section of the
> chosen solution.
>
> You'll find pointers to most web-related libs / frameworks 
> here:http://wiki.python.org/moin/WebFrameworkshttp://wiki.python.org/moin/WebProgramming
>
> Given your situation (Python newcomer with a real job to do), and if
> your job is anything more than a very Q&D deadsimple task, I'd
> personnaly recommand Django (http://djangiproject.com). Don't let the
> version number fools you (latest version is 1.0 release candidate),
> Django is a mature, solid and proven solution that have years of
> existance, and what they call 1.0rc would be labeled at least 3.5 for
> some other software... It's also mostly documented, and there's a strong
> community around the framework, so you should not have much problem
> getting help.
>
> For any other Python question (I mean, non django-related), you're at
> the right place.
>
> Oh, and yes, if I may suggest a 
> reading:http://dirtsimple.org/2004/12/python-is-not-java.html
>
> HTH, and welcome on board...

Hey, thanks very much this is really helpful.  What I really need is
pointers, I'm sure I can figure the rest out.  I am indeed a guy with
a real job to do.  Doesn't help that the client and host are on the
other side of the world.

I quite like python.  As a veteran coder who has tried a lot of
languages this has been a pleasant experience so far.  I *really* like
numpy and scipy.  My stock in trade is algorithms and they are quite a
revelation.  I wish I had known about them sooner and I think they
will keep me coming back to python regularly.

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


formatting a string with thousands separators

2008-09-07 Thread SimonPalmer
anyone recommend a way of formatting floats with comma separators?

e.g. 50.00 -> 500,000.00
--
http://mail.python.org/mailman/listinfo/python-list