RE: string to list

2012-06-14 Thread Shambhu Rajak
This will do you job:

>>> a = 'AAA,",,",EEE,FFF,GGG'
>>> b = []
>>> for x in a.split(','):
... if (x.find("\"") > -1):
... x = x.strip("\"")
... b.append(x)

If you want reduce the lines of code u can go for this option:
b = [x.strip("\"") for x in a.split(',')] 


So Just Cheerz,
-Shambhu

-Original Message-
From: bruce g [mailto:bruceg113...@gmail.com] 
Sent: 14/06/2012 8:00 AM
To: python-list@python.org
Subject: string to list

What is the best way to parse a CSV string to a list?

For example, how do I parse:
'AAA,",,",EEE,FFF,GGG'
to get:
['AAA','BBB,CCC,','EEE','FFF','GGG']

Thanks,
Bruce


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


Re: string to list

2012-06-14 Thread Peter Otten
bruce g wrote:

> What is the best way to parse a CSV string to a list?
> 
> For example, how do I parse:
> 'AAA,",,",EEE,FFF,GGG'
> to get:
> ['AAA','BBB,CCC,','EEE','FFF','GGG’]

>>> import csv
>>> next(csv.reader(['AAA,",,",EEE,FFF,GGG']))
['AAA', ',,', 'EEE', 'FFF', 'GGG']

For multiple records: 

list(csv.reader(text.splitlines(True)))

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


Re: string to list

2012-06-14 Thread Anoop Thomas Mathew
Hi,

You can use literal_eval from ast package.

>>> from ast import literal_eval
>>> list(literal_eval("'aa','bb','cc'")

this will return ['aa', 'bb', 'cc']

Thanks,
Anoop Thomas Mathew

atm
___
Life is short, Live it hard.




On 14 June 2012 12:28, Shambhu Rajak  wrote:

> This will do you job:
>
> >>> a = 'AAA,",,",EEE,FFF,GGG'
> >>> b = []
> >>> for x in a.split(','):
> ... if (x.find("\"") > -1):
> ... x = x.strip("\"")
> ... b.append(x)
>
> If you want reduce the lines of code u can go for this option:
> b = [x.strip("\"") for x in a.split(',')]
>
>
> So Just Cheerz,
> -Shambhu
>
> -Original Message-
> From: bruce g [mailto:bruceg113...@gmail.com]
> Sent: 14/06/2012 8:00 AM
> To: python-list@python.org
> Subject: string to list
>
> What is the best way to parse a CSV string to a list?
>
> For example, how do I parse:
>'AAA,",,",EEE,FFF,GGG'
> to get:
>['AAA','BBB,CCC,','EEE','FFF','GGG']
>
> Thanks,
> Bruce
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string to list

2012-06-14 Thread Hemanth H.M
@Annop Nice one, but you seem to have missed a parenthesis.

>>> list(literal_eval("'aa','bb','cc'")  should have been >>>
list(literal_eval("'aa','bb','cc'"))


On Thu, Jun 14, 2012 at 12:58 PM, Anoop Thomas Mathew wrote:

> >>> list(literal_eval("'aa','bb','cc'")




-- 
*'I am what I am because of who we all are'*
h3manth.com 
*-- Hemanth HM *
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string to list

2012-06-14 Thread Hemanth H.M
>>> list(literal_eval('"aa","bb 'b'","cc"'))
['aa', 'bb ', 'cc']

Strange?

On Thu, Jun 14, 2012 at 1:09 PM, Hemanth H.M  wrote:

> @Annop Nice one, but you seem to have missed a parenthesis.
>
> >>> list(literal_eval("'aa','bb','cc'")  should have been >>>
> list(literal_eval("'aa','bb','cc'"))
>
>
> On Thu, Jun 14, 2012 at 12:58 PM, Anoop Thomas Mathew wrote:
>
>> >>> list(literal_eval("'aa','bb','cc'")
>
>
>
>
> --
> *'I am what I am because of who we all are'*
> h3manth.com 
> *-- Hemanth HM *
>



-- 
*'I am what I am because of who we all are'*
h3manth.com 
*-- Hemanth HM *
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string to list

2012-06-14 Thread Anoop Thomas Mathew
@group: Sorry for the mistake.
@Hemanth: Thank You for pointing out.
I just realized that, we should not copy paste from the console. :)

atm
___
Life is short, Live it hard.




On 14 June 2012 13:09, Hemanth H.M  wrote:

> @Annop Nice one, but you seem to have missed a parenthesis.
>
> >>> list(literal_eval("'aa','bb','cc'")  should have been >>>
> list(literal_eval("'aa','bb','cc'"))
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string to list

2012-06-14 Thread Chris Rebert
On Thu, Jun 14, 2012 at 12:40 AM, Hemanth H.M  wrote:
 list(literal_eval('"aa","bb 'b'","cc"'))
> ['aa', 'bb ', 'cc']
>
> Strange?

Not really. You didn't properly escape the embedded quotation marks in
the string itself!
So before anything ever even gets passed to literal_eval(), that part
is parsed as two adjacent literals: '"aa","bb ' and b'","cc"'
In Python 3.x, the "b" prefix indicates a `bytes` literal rather than
a `str` literal.

Implicit adjacent string literal concatenation then occurs.
Thus:
>>> print '"aa","bb ' b'","cc"'
"aa","bb ","cc"
Compare:
>>> print '''"aa","bb 'b'","cc"'''
"aa","bb 'b'","cc"

But really, literal_eval() should not be used for CSV; it won't handle
unquoted fields at all, among other issues.

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: validating XML

2012-06-14 Thread andrea crotti
2012/6/13 Stefan Behnel 

> andrea crotti, 13.06.2012 12:06:
> > Hello Python friends, I have to validate some xml files against some xsd
> > schema files, but I can't use any cool library as libxml unfortunately.
>
> Any reason for that? Because the canonical answer to your question would be
> lxml, which uses libxml2.
>
> Stefan
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Yes sure and I would perfectly agree with you, the more I look into this
taks the less I want to do it ;)

The reason is that it has to work on many platforms and without any c
module installed, the reason of that
I'm not sure yet but I'm not going to complain again...

Anyway in a sense it's also quite interesting, and I don't need to
implement the whole XML, so it should be fine.
What I haven't found yet is an explanation of a possible algorithm to use
for the validation, that I could then implement..

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


Re: which one do you prefer? python with C# or java?

2012-06-14 Thread Albert van der Horst
In article <7xwr3fjff8@ruckus.brouhaha.com>,
Paul Rubin   wrote:
>Matej Cepl  writes:
>> The point is that you are never interested in learning *a language*,
>> everybody who has at least some touch with programming can learn most
>> languages in one session in the afternoon.
>
>Really, that's only if the new language is pretty much the same as the
>old ones, in which case you haven't really learned much of anything.
>Languages that use interesting new concepts are challenges in their own
>right.
>
>Here is an interesting exercise for statically typed languages,
>unsuitable for Python but not too hard in Haskell:
>
>http://blog.tmorris.net/understanding-practical-api-design-static-typing-and-functional-programming/

When I'm satisfied with a program, it has this ethereal property that
if the problem is slightly altered, the program is only slightly
altered. Case in point:going to incorporate the extra 8 register from
64 bit pentium into a pre-existing 32 bit Pentium assembler.
(Which is a in fact a somewhat large messy change that would
trigger a rewrite in most assemblers.)

I much doubt if e.g. the whowonordraw gives a compile time error
on a non-finished board, that the program can be robust against
a small change of the rules. Say strikes going through the lower
left square are not counted as a win.
It is sooo bloody artifical. A normal requirement would be an
API that gives on any tic-tac-toe board one of:
Iwin, youwin, draw, not-finished.

Then there are static typed languages like Forth where the programmer
is the judge whether there is a type error, and type errors are
not generated by the compiler.

A much more natural api is where a board is an object.
You can send a move message -> accepted or nor
You can send an inspect message -> won lost draw or not-finished.

I can make that totally robust without storing lost or draw
information using the type system.

He requires that on several calls, if the data is wrong, you get
a compile time error. How could that be a reasonable demand from
a language like Python where the call can be made interpretively?

Of course it is an exercise. But I think that it went this way:
1. solve it in Haskell
2. require incidental and non-useful features of the solution
to work in other languages the same way.

If he is bashing Scrum, I'm bashing staic typing.

>
>It doesn't require the use of any libraries, standards, style, or
>culture.  I can tell you as a fairly strong Python programemr who got
>interested in Haskell a few years ago, it took me much longer than an
>afternoon to get to the point of being able to solve a problem like the
>above.  It required absorbing new concepts that Python simply does not
>contain.  But it gave me the ability to do things I couldn't do before.
>That's a main reason studying new languages is challenging and
>worthwhile.

I give you that. Mastering a functional language is a real
step, but I don't think this tic-tac-toe exercise will entice me to
do that.
Maybe the solutions to http://projecteuler.net that are published
in Haskell sometimes condensing a few pages of my sequential code in
a few lines, will inspire me to take up Haskell.

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: [newbie] Equivalent to PHP?

2012-06-14 Thread Gilles
On Wed, 13 Jun 2012 19:03:29 -0500, Tim Chase
 wrote:
>That's just my off-the-top-of-my-head list of things that you'd have
>to come up with that Django happens to give you out-of-the-box.

Thanks much. So the next step will have to find a framework that's
right for a given application.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which one do you prefer? python with C# or java?

2012-06-14 Thread Paul Rubin
>>http://blog.tmorris.net/understanding-practical-api-design-static-typing-and-functional-programming/
>
> When I'm satisfied with a program, it has this ethereal property that
> if the problem is slightly altered, the program is only slightly
> altered.

One thing I find with Haskell: the type system really seems to help
guide the program towards having that property, by making sure all the
parts fit together cleanly.

> Case in point:going to incorporate the extra 8 register from
> 64 bit pentium into a pre-existing 32 bit Pentium assembler.
> (Which is a in fact a somewhat large messy change that would
> trigger a rewrite in most assemblers.)

I'd hope that such a change would be easy in a well-designed assembler.

> I much doubt if e.g. the whowonordraw gives a compile time error
> on a non-finished board, that the program can be robust against
> a small change of the rules. Say strikes going through the lower
> left square are not counted as a win.

Eh?  No, that kind of change is trivial, and wouldn't affect the types
at all.  Maybe you're imagining the rules of tic-tac-toe being encoded
in the types, which could in fact be done, especially in fancier systems
like Agda's.  But all that we're talking about here is that creation of
values describing game states is reserved to the API implementation by
the module system.  The API doesn't export the constructors for values
in the "game state" types.  It's just like an OO system that enforces
private instance variables, so that clients can only get at those
variables through accessor functions supplied by the instances.

> Then there are static typed languages like Forth where the programmer
> is the judge whether there is a type error, and type errors are not
> generated by the compiler.

That is not static typing in any normal sense of the term.  Forth is
untyped.

> A much more natural api is where a board is an object.
> You can send a move message -> accepted or nor
> You can send an inspect message -> won lost draw or not-finished.

If you attempt a move on a finished board, that is a programming
error.  By suffering some extra complexity in the types, you can catch
this particular error at compile time, decreasing your testing
and support burden at runtime.  Whether that trade-off is worth it in
practice depends on the problem.  For tic-tac-toe it's probably
not worth it except as an exercise, and this tic-tac-toe problem
was in fact presented as an exercise.  

> I can make that totally robust without storing lost or draw
> information using the type system.

I think the exercise simply wanted separate types for complete and
incomplete games, not separate types for win/lose/draw.  I could imagine
wanting separate types for wins/losses/draws if there were functions to
award prizes to the winners of games.  You'd want to make sure that lost
games didn't get awarded these prizes.

> He requires that on several calls, if the data is wrong, you get
> a compile time error. How could that be a reasonable demand from
> a language like Python where the call can be made interpretively?

You can't, that's the entire point, Python is good for many things but
not for this.  So if you want to expand your horizons as a programmer
enough to be able to do this sort of problem, you have to try out more
languages.

> Of course it is an exercise. But I think that it went this way:
> 1. solve it in Haskell
> 2. require incidental and non-useful features of the solution
> to work in other languages the same way.

Not sure what you mean there.  The exercise was to use static types to
write an API with certain characteristics.  Obviously you can't do that
without static types.  It's just like programming exercises involving
writing recursive functions can't be solved in languages like Fortran(?)
that don't support recursion, etc.  

And those characteristics (per the specification in the exercise) were
not incidental or non-useful, they were essential.

> If he is bashing Scrum, I'm bashing staic typing.

I don't remember what if anything he said about Scrum.

> I give you that. Mastering a functional language is a real
> step, but I don't think this tic-tac-toe exercise will entice me to
> do that.

Functional programming and fancy type systems are separate subjects and
Haskell implements both.  Scheme is functional without static types, and
I got interested in Scheme some time before starting to use Haskell.
When I did try out Haskell, I got more from its type system than I
expected to.  I thought the following was really cool:

https://gist.github.com/2659812   with discussion at:
http://www.reddit.com/r/haskell/comments/ti5il/redblack_trees_in_haskell_using_gadts_existential/

it implements a data structure (red-black trees) with complicated
invariants that are expressed in the type system in a natural way, so
that the compiler ensures that all manipulations on the trees don't mess
up the invariants.

> Maybe the solutions to http://projecteuler.net that are publishe

Re: Create thumbnail image (jpg/png) of PDF file using Python

2012-06-14 Thread golfshoe
On Wednesday, November 21, 2007 1:16:55 PM UTC-5, sophie_newbie wrote:
> On Nov 20, 5:36 pm, sophie_newbie 
>  wrote:
> > Is there any way to do this directly within python?
> >
> > If not is there any other good way to achieve it?
> >
> > Thanks in advance for any help!
> 
> I think I've solved this problem using a piece of software called
> imageMagick. Good stuff so it is.

Interesting. I wonder if GS can be used to convert PDF To JPG and JPG back to 
PDF?  Pillow is a better alternative to PIL if you are in need of compiling on 
a Mac.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-14 Thread Wolfgang Keller
> > None of these were such that I could propagate it as GUI development
> > tool for non-programmers / casual users.
> > Sure, some are good for designing the GUI, but at the point where
> > the user code is to be added, most people would be lost.
> 
> There was a time when that was a highly advertisable feature - "build
> XYZ applications without writing a single line of code!".

That's the typical nonsense cheaptalk of sales promotion advertising,
directed at clueless managers.

What is needed for domain specialists are frameworks and related tools
such as GUI builders that allow them to write exclusively the
domain-specific code (this is where a domain specialist will always be
better than any software developer), layout the GUI as ergonomically
convenient (same) and then have the framework do all the rest.

> I've seen it in database front-end builders as well as GUI tools,
> same thing. But those sorts of tools tend not to be what experts want
> to use.

If by "experts" you mean "domain specialists", you're wrong. If you
mean full-time software developers, I don't care for what they want,
because they already have what they want. And where they don't have it
already, they can do it themselves.

> You end up having to un-learn the "easy way" before you learn the
> "hard way" that lets you do everything.

I see no technical reason why a GUI builder would prevent anyone to
add customised code by hand.

No tool/framework can cover 100%, no doubt. My point is that there are
currently no frameworks/tools available for Python that cover the
90/95/98% of use cases where they would help a L-O-T.

Sincerely,

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


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-14 Thread Wolfgang Keller
> object mainwindow=GTK2.Window(GTK2.WindowToplevel);
> mainwindow->set_title("Timing")->set_default_size
> (400,300)->signal_connect("destroy",window_destroy); GTK2.HbuttonBox
> btns=GTK2.HbuttonBox()->set_layout(GTK2.BUTTONBOX_SPREAD); foreach
> (labels,string lbl) btns->add(buttons[lbl]=button(lbl,mode_change));
> mainwindow->add(GTK2.Vbox(0,0)
> 
> ->add(GTK2.TextView(buffer=GTK2.TextBuffer())->set_size_request(0,0))
> ->pack_start(btns,0,0,0))->show_all();
> 
> If you're a complete non-programmer, then of course that's an opaque
> block of text.

Thanks for that hideously appalling example of a ridiculously low-level
mess.

If you're an occasional Python scripting dilettant, this looks like a
heap of syntax garbage of exactly that kind that has made me avoid all
C-derived languages at university (I'm a mechanical engineer) and that
makes me avoid GUI programming with Python so far.

If a domain specialist needs an application with a GUI, (s)he
typically only wants to have to tell the framework three things:

1. What the domain model looks like (classes, attributes) and what it
does in terms of behaviour (domain logic, methods). In my use-cases this
would be typically done with SQLalchemy.

2. What the GUI shows of the domain model and how it does it - define
menus with entries, layout forms/dialog boxes with fields etc. This
should be done without having to permanently look up all the specific
details of the API of the GUI framework.

3. What attribute/method of the domain model a GUI element is
"connected to" (sorry for the quotes again). This should be possible in
an interactive way, so that you can test whether GUI and code work
together as required while defining the connections.

Anything else should be done by the framework without the necessity to
write a single line of code for the "straight forward" use cases:
- creating, retrieving, updating, deleting instances of domain model
classes
- setting values of attributes instances of domain model classes
- calling methods of instances of domain model classes

Sincerely,

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


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-14 Thread Wolfgang Keller
Danger: Flame ahead!
> I think efforts to make a better, and more definitive, "GUI builder"
> for Python should focus on makigng an easy to use "IDE" for creating
> these kinds of Python-HTMl-Javascript front ends for applications.

The idea of so-called "web applications" is a cerebral flatulance
emanating from braindead morons (typically the pointy-haired type),
sorry.

>From the perspective of the domain specialist who needs to get some work
done and who needs to get it done efficiently they are simply
unusable. The "functionality" that such "web interfaces" provide is
ridiculously poor, they are clumsy to use and even worse
hourglass-display systems than the junk that MS or SAP sell. Besides the
fact that they require obscene amounts of runtime ressources.
Besides... Sorry, this subject isn't worth wasting my brain bandwidth
on it.

I have started to use computers with GEM on Atari ST, MacOS 6.0.7 and
DOS 3.3, and if all those "web mailers" or "Google apps" had been the
only applications available back then I would have never started to use
computers at all.

In short: "web applications" are in no way a solution to the mentioned
problem, but they make this problem worse by piling up other problems
on top of it.

End of flame.

Sincerely,

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


Re: validating XML

2012-06-14 Thread Dieter Maurer
andrea crotti  writes:
> ...
> The reason is that it has to work on many platforms and without any c module
> installed, the reason of that

Searching for a pure Python solution, you might have a look at "PyXB".

It has not been designed to validate XML instances against XML-Schema
(but to map between XML instances and Python objects based on
an XML-Schema description) but it detects many problems in the
XML instances. It does not introduce its own C extensions
(but relies on an XML parser shipped with Python).

> Anyway in a sense it's also quite interesting, and I don't need to implement
> the whole XML, so it should be fine.

The XML is the lesser problem. The big problem is XML-Schema: it is
*very* complex with structure definitions (elements, attributes and
"#PCData"), inheritance, redefinition, grouping, scoping rules, inclusion,
data types with restrictions and extensions.

Thus if you want to implement a reliable algorithm which for
given XML-schema and XML-instance checks whether the instance is
valid with respect to the schema, then you have a really big task.

Maybe, you have a fixed (and quite simple) schema. Then
you may be able to implement a validator (for the fixed schema).
But I do not understand why you would want such a validation.
If you generate the XML instances, then thouroughly test your
generation process (using any available validator) and then trust it.
If the XML instances come from somewhere else and must be interpreted
by your application, then the important thing is that they are
understood by your application, not that they are valid.
If you get a complaint that your application cannot handle a specific
XML instance, then you validate it in your development environment
(again with any validator available) and if the validation fails,
you have good arguments.


> What I haven't found yet is an explanation of a possible algorithm to use for
> the validation, that I could then implement..

You parse the XML (and get a tree) and then recursively check
that the elements, attributes and text nodes in the tree
conform to the schema (in an abstract sense,
the schema is a collection of content models for the various elements;
each content model tells you how the element content and attributes
should look like).
For a simple schema, this is straight forward. If the schema starts
to include foreign schemas, uses extensions, restrictions or "redefine"s,
then it gets considerably more difficult.


--
Dieter

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


finding the byte offset of an element in an XML file (tell() and seek()?)

2012-06-14 Thread Ben Temperton
Hi there,

I am working with mass spectroscopy data in the mzXML format that looks like 
this:


  ...
  ...
  ...
  ...
 .


160409990
160442725
160474927
160497386




Where the offset element contains the byte offset of the scan element that 
shares the id. I am trying to write a python script to remove scan elements and 
their respective offset, but I can't figure out how I re-calculate the byte 
offset for each remaining element once the elements have been removed.

My plan was to write the file out, the read it back in again and search through 
the file for a particular string (e.g. '') and then use the 
tell() method to return the current byte location in the file. However, I'm not 
sure how I would implement this.

Any ideas?

Many thanks,

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


mbox parsing, specifically message body

2012-06-14 Thread Ryan Clough
Hello everyone, 

Is anyone familiar with a simple way to parse mbox emails in Python?  I use 
Mail::MBoxParser in perl and it provides a simple way to grab the bodies from 
the emails.  In my research online, people have suggested searching for lines 
starting with "From ", but this doesn't seem reliable to me.  I am using the 
built in mailbox module and am able to do something like:

import mailbox
for message in mbox:
print message['subject']

It would be great if you could do something like the following:
print messages['body']

Any thoughts are appreciated.

Thanks, Ryan 

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


[ANNOUNCE] pypiserver 0.6.0 - minimal private pypi server

2012-06-14 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 0.6.0 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just easy_install pypiserver). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver


Changes in version 0.6.0
-
- make pypiserver work with pip on windows
- add support for password protected uploads
- make pypiserver work with non-root paths
- make pypiserver 'paste compatible'
- allow to serve multiple package directories using paste


-- 
Cheers,
Ralf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-14 Thread CM
On Jun 14, 2:25 pm, Wolfgang Keller  wrote:
>
> What is needed for domain specialists are frameworks and related tools
> such as GUI builders that allow them to write exclusively the
> domain-specific code (this is where a domain specialist will always be
> better than any software developer), layout the GUI as ergonomically
> convenient (same) and then have the framework do all the rest.

Above this you also mentioned a disdain for the need for "glue code",
which in the context of your post seemed to be binding to event
handlers.
So is there a possible way for a GUI builder to *automatically* bind
widgets
to the appropriate functions in your domain-specific code?  It's hard
to
see how this would be generally possible, even with an AI (maybe a
mind-reading AI would work).

Or maybe I'm misunderstanding something.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-14 Thread Colin Higwell
On Tue, 12 Jun 2012 00:55:38 +0200, Dietmar Schwertberger wrote:

> As long as there's no GUI
> builder for Python, most people will stick to Excel / VBA / VB.

No GUI builder for Python? There are plenty.

I use wxGlade with wxPython and it works beautifully. It writes the code 
for the GUI elements, and I put in the event handlers, database access 
code and so on.

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


Re: finding the byte offset of an element in an XML file (tell() and seek()?)

2012-06-14 Thread Emile van Sebille

On 6/14/2012 12:27 PM Ben Temperton said...

Hi there,

I am working with mass spectroscopy data in the mzXML format that looks like 
this:

 
   ...
   ...
   ...
   ...
  .
 
 
 160409990
 160442725
 160474927
 160497386
 
 


Where the offset element contains the byte offset


byte offset to what in what?


of the scan element that shares the id. I am trying to write a python script to 
remove scan elements and their respective offset, but I can't figure out how I 
re-calculate the byte offset for each remaining element once the elements have 
been removed.


Removing the reference will render the location as inaccessible so you 
may not need to recalculate the remaining offsets.  I'm assuming these 
are offset in some other file and that the lengths of the data contained 
at that location is known or knowable.  But, if you don't point to that 
location you won't try to get the data at the offset.


If you're trying to minimize the size on disk you'll probably want to 
write a new file and leave the original alone.  Initialize a buffer, 
then for each valid offset id add the content and bump the offset by the 
content length (or whatever is appropriate)


Emile




My plan was to write the file out, the read it back in again and search through the file for a 
particular string (e.g. '') and then use the tell() method to 
return the current byte location in the file. However, I'm not sure how I would implement this.

Any ideas?

Many thanks,

Ben



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


Re: mbox parsing, specifically message body

2012-06-14 Thread Emile van Sebille

On 6/14/2012 12:57 PM Ryan Clough said...

Hello everyone,

Is anyone familiar with a simple way to parse mbox emails in Python?


>>> import mailbox
>>> help(mailbox)
Help on module mailbox:

NAME
mailbox - Read/write support for Maildir, mbox, MH, Babyl, and MMDF 
mailboxes.



Emile


I
use Mail::MBoxParser in perl and it provides a simple way to grab the
bodies from the emails. In my research online, people have suggested
searching for lines starting with "From ", but this doesn't seem
reliable to me. I am using the built in mailbox module and am able to do
something like:

import mailbox
for message in mbox:
print message['subject']

It would be great if you could do something like the following:
print messages['body']

Any thoughts are appreciated.

Thanks, Ryan





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


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-14 Thread Dietmar Schwertberger

Am 14.06.2012 22:06, schrieb Colin Higwell:

On Tue, 12 Jun 2012 00:55:38 +0200, Dietmar Schwertberger wrote:

As long as there's no GUI
builder for Python, most people will stick to Excel / VBA / VB.


No GUI builder for Python? There are plenty.

Yes, sorry. I posted that too late in the night.
The point was that there's no easy-to-use GUI builder which would
allow the casual user to create a GUI.



I use wxGlade with wxPython and it works beautifully. It writes the code
for the GUI elements, and I put in the event handlers, database access
code and so on.

Yes, from the ones I've tested, wxGlade came closest to what I was
looking for.
But still, it's far away from being the tool that is required IMHO.
(An it does not seem to be in active development.)

Also, with wxGlade you are forced to use sizers - even at positions
where they are not useful at all.
For simple GUIs that adds a level of complexity which is counter
productive.
(From the GUI editors that I tried, Qt Creator/Designer was the only
 one where I agree that it handles sizers/layout containers well.)


When I compare e.g. wxGlade to VB6,  whether a casual programmer can use
it to create a GUI, then still VB6 wins.
VB is crap, but at least it allows to create GUIs by using a GUI and
will help you getting started in writing GUI applications. It will
take only a few minutes to teach someone how to get started.
On the other hand, I need to know wx very well to be able to create
a GUI using wxGlade as otherwise I will never find where to add
e.g. the handlers.
But when I know wx very well, then there's no point in using wxGlade.



Regards,

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


Finding all loggers?

2012-06-14 Thread Roy Smith
Is there any way to get a list of all the loggers that have been
defined?  So if somebody has done:

from logging import getLogger
getLogger("foo")
getLogger("foo.bar")
getLogger("baz")

I want something which will give me back ["foo", "foo.bar", "baz"].
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic cross-platform GUI desingers ?? la Interface Builder (Re: what gui designer is everyone using)

2012-06-14 Thread Grant Edwards
On 2012-06-14, Dietmar Schwertberger  wrote:

> Yes, sorry. I posted that too late in the night. The point was that
> there's no easy-to-use GUI builder which would allow the casual user
> to create a GUI.

I'm not sure I'm in favor of casual users creating GUIs.

Have you ever tried to _use_ a program built by a casual user?

[OK, I'm half joking.]

If casual users want a GUI builder they can use, then let 'em write
one...:)

-- 
Grant Edwards   grant.b.edwardsYow! My nose feels like a
  at   bad Ronald Reagan movie ...
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding all loggers?

2012-06-14 Thread Michael Hrivnak
>>> import logging
>>> logging.Logger.manager.loggerDict
{}
>>> logging.getLogger('foo')

>>> logging.getLogger('bar')

>>> logging.Logger.manager.loggerDict
{'foo': , 'bar':
}

Enjoy,
Michael

On Thu, Jun 14, 2012 at 5:03 PM, Roy Smith  wrote:
> Is there any way to get a list of all the loggers that have been
> defined?  So if somebody has done:
>
> from logging import getLogger
> getLogger("foo")
> getLogger("foo.bar")
> getLogger("baz")
>
> I want something which will give me back ["foo", "foo.bar", "baz"].
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic cross-platform GUI desingers ?? la Interface Builder (Re: what gui designer is everyone using)

2012-06-14 Thread Dietmar Schwertberger

Am 14.06.2012 23:29, schrieb Grant Edwards:

On 2012-06-14, Dietmar Schwertberger  wrote:

Yes, sorry. I posted that too late in the night. The point was that
there's no easy-to-use GUI builder which would allow the casual user
to create a GUI.


I'm not sure I'm in favor of casual users creating GUIs.

Have you ever tried to _use_ a program built by a casual user?

[OK, I'm half joking.]

I understand your point.
I've used and fixed many such programs.

Plenty of those were by so-called professionals. Usually, those are the
most problematic cases as you don't have the sources available or they
are developed and deployed by a central IT department.

There's a correlation between technical knowledge of creating a GUI
and the quality of the resulting GUI, but the correlation is not too
strong.

The casual programmer that I was refering to, is also among the users
of the software that (s)he is writing and therefore the GUI tends to
be improved over time, which often is not the case with the software
developed by so-called professionals who get paid for the program and
then move on.

The point is, that if you want to promote Python as replacement
for e.g. VB, Labview etc., then an easy-to-use GUI builder is required.
The typical GUI programs will just have an input mask, a button and one
or two output fields.

Regards,

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


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-14 Thread Dietmar Schwertberger

Am 13.06.2012 14:49, schrieb Wolfgang Keller:

No matter how cool it may seem to create simple GUIs manually or to
write business letters using LaTeX: just try to persuade people to
move from Word to LaTeX for business letters...


Good example.

I have done nearly exactly this* - but it was only possible thanks to
LyX.



*I moved not from Wugh, but from other software to LyX/LaTeX for all my
document processing.

But of course, you were only doing so because you had LyX available,
which is the equivalent of an easy-to-use GUI builder.
So maybe I should be more precise: just try to persuade people to move
from Word to *pure* LaTeX for business letters...

Regards,

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


Re: Finding all loggers?

2012-06-14 Thread Roy Smith
Neat, thanks!


On Jun 14, 2012, at 5:38 PM, Michael Hrivnak wrote:

 import logging
 logging.Logger.manager.loggerDict
> {}
 logging.getLogger('foo')
> 
 logging.getLogger('bar')
> 
 logging.Logger.manager.loggerDict
> {'foo': , 'bar':
> }
> 
> Enjoy,
> Michael
> 
> On Thu, Jun 14, 2012 at 5:03 PM, Roy Smith  wrote:
>> Is there any way to get a list of all the loggers that have been
>> defined?  So if somebody has done:
>> 
>> from logging import getLogger
>> getLogger("foo")
>> getLogger("foo.bar")
>> getLogger("baz")
>> 
>> I want something which will give me back ["foo", "foo.bar", "baz"].
>> --
>> http://mail.python.org/mailman/listinfo/python-list
> 


---
Roy Smith
r...@panix.com



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